@memberjunction/graphql-dataprovider 2.2.0 → 2.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +25 -25
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +26 -26
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var
|
|
1
|
+
var K=Object.defineProperty;var N=(V,e)=>K(V,"name",{value:e,configurable:!0});import{gql as R,GraphQLClient as Q}from"graphql-request";import{gql as we}from"graphql-request";import{ProviderConfigDataBase as A,ProviderBase as O,LogError as D,UserInfo as M,ProviderType as q,BaseEntityResult as _,EntityFieldTSType as S,TransactionItem as B,UserRoleInfo as b,TransactionGroupBase as J,TransactionResult as j,BaseEntity as W,Metadata as z,RunView as H,RunReport as X,RunQuery as Y}from"@memberjunction/core";import{ViewInfo as k}from"@memberjunction/core-entities";import{openDB as Z}from"@tempfix/idb";import{Observable as ee}from"rxjs";import{createClient as te}from"graphql-ws";import{MJGlobal as ae,MJEventType as se}from"@memberjunction/global";const G=class G{constructor(){this._fieldMap={__mj_CreatedAt:"_mj__CreatedAt",__mj_UpdatedAt:"_mj__UpdatedAt",__mj_DeletedAt:"_mj__DeletedAt"}}MapFields(e){if(e)for(const s in e)s in this._fieldMap&&(e[this._fieldMap[s]]=e[s],delete e[s]);return e}MapFieldName(e){return this._fieldMap[e]??e}ReverseMapFieldName(e){return Object.entries(this._fieldMap).find(([s,a])=>a===e)?.[0]??e}ReverseMapFields(e){const s=Object.fromEntries(Object.entries(this._fieldMap).map(([a,t])=>[t,a]));for(const a in e)a in s&&(e[s[a]]=e[a],delete e[a]);return e}};N(G,"FieldMapper");let h=G;const T=class T extends A{get Token(){return this.Data.Token}set Token(e){this.Data.Token=e}get URL(){return this.Data.URL}get WSURL(){return this.Data.WSURL}get RefreshTokenFunction(){return this.Data.RefreshFunction}constructor(e,s,a,t,r,l,i){super({Token:e,URL:s,WSURL:a,RefreshTokenFunction:t},r,l,i)}};N(T,"GraphQLProviderConfigData");let C=T;const d=class d extends O{constructor(){super(...arguments),this._innerCurrentUserQueryString=`CurrentUser {
|
|
2
2
|
${this.userInfoString()}
|
|
3
3
|
UserRolesArray {
|
|
4
4
|
${this.userRoleInfoString()}
|
|
@@ -24,7 +24,7 @@ var Q=Object.defineProperty;var E=(V,e)=>Q(V,"name",{value:e,configurable:!0});i
|
|
|
24
24
|
ExecutionTime
|
|
25
25
|
ErrorMessage
|
|
26
26
|
}
|
|
27
|
-
}`,t=await d.ExecuteGQL(a,{QueryID:e.QueryID});if(t&&t.GetQueryData)return{QueryID:e.QueryID,Success:t.GetQueryData.Success,Results:JSON.parse(t.GetQueryData.Results),RowCount:t.GetQueryData.RowCount,ExecutionTime:t.GetQueryData.ExecutionTime,ErrorMessage:t.GetQueryData.ErrorMessage}}async RunView(e,s){try{let a="",t="";if(e){const r={};let
|
|
27
|
+
}`,t=await d.ExecuteGQL(a,{QueryID:e.QueryID});if(t&&t.GetQueryData)return{QueryID:e.QueryID,Success:t.GetQueryData.Success,Results:JSON.parse(t.GetQueryData.Results),RowCount:t.GetQueryData.RowCount,ExecutionTime:t.GetQueryData.ExecutionTime,ErrorMessage:t.GetQueryData.ErrorMessage}}async RunView(e,s){try{let a="",t="";if(e){const r={};let l,i;if(e.ViewEntity)i=e.ViewEntity,l=i.Entity;else{const{entityName:o,v:c}=await this.getEntityNameAndUserView(e,s);i=c,l=o}const n=this.Entities.find(o=>o.Name===l);if(!n)throw new Error(`Entity ${l} not found in metadata`);let p=!1;e.ViewID?(a=`Run${n.ClassName}ViewByID`,t="RunViewByIDInput",r.ViewID=e.ViewID):e.ViewName?(a=`Run${n.ClassName}ViewByName`,t="RunViewByNameInput",r.ViewName=e.ViewName):(p=!0,a=`Run${n.ClassName}DynamicView`,t="RunDynamicViewInput",r.EntityName=e.EntityName),r.ExtraFilter=e.ExtraFilter?e.ExtraFilter:"",r.OrderBy=e.OrderBy?e.OrderBy:"",r.UserSearchString=e.UserSearchString?e.UserSearchString:"",r.Fields=e.Fields,r.IgnoreMaxRows=e.IgnoreMaxRows?e.IgnoreMaxRows:!1,r.MaxRows=e.MaxRows?e.MaxRows:0,r.ForceAuditLog=e.ForceAuditLog?e.ForceAuditLog:!1,r.ResultType=e.ResultType?e.ResultType:"simple",e.AuditLogDescription&&e.AuditLogDescription.length>0&&(r.AuditLogDescription=e.AuditLogDescription),p||(r.ExcludeUserViewRunID=e.ExcludeUserViewRunID?e.ExcludeUserViewRunID:"",r.ExcludeDataFromAllPriorViewRuns=e.ExcludeDataFromAllPriorViewRuns?e.ExcludeDataFromAllPriorViewRuns:!1,r.OverrideExcludeFilter=e.OverrideExcludeFilter?e.OverrideExcludeFilter:"",r.SaveViewResults=e.SaveViewResults?e.SaveViewResults:!1);const f=this.getViewRunTimeFieldList(n,i,e,p),y=R`
|
|
28
28
|
query RunViewQuery ($input: ${t}!) {
|
|
29
29
|
${a}(input: $input) {
|
|
30
30
|
Results {
|
|
@@ -38,7 +38,7 @@ var Q=Object.defineProperty;var E=(V,e)=>Q(V,"name",{value:e,configurable:!0});i
|
|
|
38
38
|
Success
|
|
39
39
|
ErrorMessage
|
|
40
40
|
}
|
|
41
|
-
}`,
|
|
41
|
+
}`,u=await d.ExecuteGQL(y,{input:r});if(u&&u[a]){const o=u[a].Results;if(o&&o.length>0){const c=n.Fields.filter(m=>m.CodeName!==m.Name&&m.CodeName!==void 0);o.forEach(m=>{this.ConvertBackToMJFields(m),c.forEach(w=>{m[w.Name]=m[w.CodeName]})})}return u[a]}}else throw"No parameters passed to RunView";return null}catch(a){throw D(a),a}}async RunViews(e,s){try{let a=[],t=[],r=[];for(const n of e){let p="",f="";const y={};let u=null,o=null;if(n.ViewEntity)o=n.ViewEntity,u=o.Get("Entity");else{const{entityName:w,v:E}=await this.getEntityNameAndUserView(n,s);o=E,u=w}const c=this.Entities.find(w=>w.Name===u);if(!c)throw new Error(`Entity ${u} not found in metadata`);t.push(c);let m=!1;n.ViewID?(p=`Run${c.ClassName}ViewByID`,f="RunViewByIDInput",y.ViewID=n.ViewID):n.ViewName?(p=`Run${c.ClassName}ViewByName`,f="RunViewByNameInput",y.ViewName=n.ViewName):(m=!0,p=`Run${c.ClassName}DynamicView`,f="RunDynamicViewInput",y.EntityName=n.EntityName),y.ExtraFilter=n.ExtraFilter||"",y.OrderBy=n.OrderBy||"",y.UserSearchString=n.UserSearchString||"",y.Fields=n.Fields,y.IgnoreMaxRows=n.IgnoreMaxRows||!1,y.MaxRows=n.MaxRows||0,y.ForceAuditLog=n.ForceAuditLog||!1,y.ResultType=n.ResultType||"simple",n.AuditLogDescription&&n.AuditLogDescription.length>0&&(y.AuditLogDescription=n.AuditLogDescription),m||(y.ExcludeUserViewRunID=n.ExcludeUserViewRunID||"",y.ExcludeDataFromAllPriorViewRuns=n.ExcludeDataFromAllPriorViewRuns||!1,y.OverrideExcludeFilter=n.OverrideExcludeFilter||"",y.SaveViewResults=n.SaveViewResults||!1),a.push(y),r.push(...this.getViewRunTimeFieldList(c,o,n,m))}const l=R`
|
|
42
42
|
query RunViewsQuery ($input: [RunViewGenericInput!]!) {
|
|
43
43
|
RunViews(input: $input) {
|
|
44
44
|
Results {
|
|
@@ -53,7 +53,7 @@ var Q=Object.defineProperty;var E=(V,e)=>Q(V,"name",{value:e,configurable:!0});i
|
|
|
53
53
|
Success
|
|
54
54
|
ErrorMessage
|
|
55
55
|
}
|
|
56
|
-
}`,i=await d.ExecuteGQL(
|
|
56
|
+
}`,i=await d.ExecuteGQL(l,{input:a});if(i&&i.RunViews){const n=i.RunViews;for(const[p,f]of n.entries())f.Results=f.Results.map(y=>{let u=JSON.parse(y.Data);return this.ConvertBackToMJFields(u),u});return n}return null}catch(a){throw D(a),a}}async getEntityNameAndUserView(e,s){let a,t;if(e.EntityName)a=e.EntityName;else if(e.ViewID)t=await k.GetViewEntity(e.ViewID,s),a=t.Entity;else if(e.ViewName)t=await k.GetViewEntityByName(e.ViewName,s),a=t.Entity;else throw new Error("No EntityName, ViewID or ViewName passed to RunView");return{entityName:a,v:t}}getViewRunTimeFieldList(e,s,a,t){const r=[],l=new h;if(a.Fields){for(const i of e.PrimaryKeys)a.Fields.find(n=>n.trim().toLowerCase()===i.Name.toLowerCase())===void 0&&r.push(i.Name);a.Fields.forEach(i=>{r.push(l.MapFieldName(i))})}else if(t)e.Fields.forEach(i=>{i.IsBinaryFieldType||r.push(l.MapFieldName(i.CodeName))});else{for(const i of e.PrimaryKeys)r.find(n=>n.trim().toLowerCase()===i.Name.toLowerCase())===void 0&&r.push(i.Name);s.Columns.forEach(i=>{i.hidden===!1&&!r.find(n=>n.trim().toLowerCase()===i.EntityField?.Name.trim().toLowerCase())&&i.EntityField&&r.push(l.MapFieldName(i.EntityField.CodeName))})}return r}get ProviderType(){return q.Network}async GetRecordChanges(e,s){try{const a={EntityName:"Record Changes",ExtraFilter:`RecordID = '${s.Values()}' AND Entity = '${e}'`},t=await this.RunView(a);return t?t.Results.sort((r,l)=>r.ChangedAt>l.ChangedAt?-1:1):null}catch(a){throw D(a),a}}async GetRecordDependencies(e,s){try{const a=R`query GetRecordDependenciesQuery ($entityName: String!, $CompositeKey: CompositeKeyInputType!) {
|
|
57
57
|
GetRecordDependencies(entityName: $entityName, CompositeKey: $CompositeKey) {
|
|
58
58
|
EntityName
|
|
59
59
|
RelatedEntityName
|
|
@@ -87,7 +87,7 @@ var Q=Object.defineProperty;var E=(V,e)=>Q(V,"name",{value:e,configurable:!0});i
|
|
|
87
87
|
}
|
|
88
88
|
}
|
|
89
89
|
}
|
|
90
|
-
}`;let t={EntityID:e.EntityID,EntityDocumentID:e.EntityDocumentID,ListID:e.ListID,ProbabilityScore:e.ProbabilityScore,Options:e.Options,RecordIDs:e.RecordIDs.map(
|
|
90
|
+
}`;let t={EntityID:e.EntityID,EntityDocumentID:e.EntityDocumentID,ListID:e.ListID,ProbabilityScore:e.ProbabilityScore,Options:e.Options,RecordIDs:e.RecordIDs.map(l=>l.Copy())};const r=await d.ExecuteGQL(a,{params:t});if(r&&r.GetRecordDuplicates)return r.GetRecordDuplicates}async MergeRecords(e){const s=this.Entities.find(a=>a.Name.trim().toLowerCase()===e.EntityName.trim().toLowerCase());if(!s||!s.AllowRecordMerge)throw new Error(`Entity ${e.EntityName} does not allow record merging, check the AllowRecordMerge property in the entity metadata`);try{const a=R`mutation MergeRecordsMutation ($request: RecordMergeRequest!) {
|
|
91
91
|
MergeRecords(request: $request) {
|
|
92
92
|
Success
|
|
93
93
|
OverallStatus
|
|
@@ -104,32 +104,32 @@ var Q=Object.defineProperty;var E=(V,e)=>Q(V,"name",{value:e,configurable:!0});i
|
|
|
104
104
|
Message
|
|
105
105
|
}
|
|
106
106
|
}
|
|
107
|
-
}`,t={EntityName:e.EntityName,SurvivingRecordCompositeKey:{KeyValuePairs:this.ensureKeyValuePairValueIsString(e.SurvivingRecordCompositeKey.KeyValuePairs)},FieldMap:e.FieldMap?.map(
|
|
108
|
-
${e.Fields.map(
|
|
107
|
+
}`,t={EntityName:e.EntityName,SurvivingRecordCompositeKey:{KeyValuePairs:this.ensureKeyValuePairValueIsString(e.SurvivingRecordCompositeKey.KeyValuePairs)},FieldMap:e.FieldMap?.map(l=>({FieldName:l.FieldName,Value:l.Value.toString()})),RecordsToMerge:e.RecordsToMerge.map(l=>l.Copy())};return(await d.ExecuteGQL(a,{request:t}))?.MergeRecords}catch(a){return D(a),{Success:!1,OverallStatus:a&&a.message?a.message:a,RecordStatus:[],RecordMergeLogID:"",Request:e}}}async Save(e,s,a){const t=new _;try{e.RegisterTransactionPreprocessing();const r={input:{}},l=e.IsSaved?"Update":"Create";t.StartedAt=new Date,t.Type=e.IsSaved?"update":"create",t.OriginalValues=e.Fields.map(u=>({FieldName:u.CodeName,Value:u.Value})),e.ResultHistory.push(t);const i=`${l}${e.EntityInfo.ClassName}`,n=e.Fields.filter(u=>!u.ReadOnly||u.IsPrimaryKey&&e.IsSaved),p=new h,f=` ${i}(input: $input) {
|
|
108
|
+
${e.Fields.map(u=>p.MapFieldName(u.CodeName)).join(`
|
|
109
109
|
`)}
|
|
110
|
-
}`,
|
|
110
|
+
}`,y=R`mutation ${l}${e.EntityInfo.ClassName} ($input: ${i}Input!) {
|
|
111
111
|
${f}
|
|
112
112
|
}
|
|
113
|
-
`;for(let
|
|
114
|
-
${e.EntityInfo.ClassName}(${
|
|
115
|
-
${e.Fields.filter(
|
|
113
|
+
`;for(let u=0;u<n.length;u++){const o=n[u];let c=o.Value;c&&o.EntityFieldInfo.TSType===S.Date&&(c=c.getTime()),c&&o.EntityFieldInfo.TSType===S.Boolean&&typeof c!="boolean"&&(c=parseInt(c)!==0),c===null&&o.EntityFieldInfo.AllowsNull===!1&&(o.EntityFieldInfo.DefaultValue!==null?c=o.EntityFieldInfo.DefaultValue:o.FieldType===S.Number||o.FieldType===S.Boolean?c=0:c=""),r.input[o.CodeName]=c}if(l.trim().toLowerCase()==="update"&&a.SkipOldValuesCheck===!1){const u=[];e.Fields.forEach(o=>{let c=null;o.OldValue!==null&&o.OldValue!==void 0&&(typeof o.OldValue!="string"?c=o.OldValue.toString():c=o.OldValue),u.push({Key:o.CodeName,Value:c})}),r.input.OldValues___=u}if(e.TransactionGroup)return new Promise((u,o)=>{const c=[{varName:"input",inputType:i+"Input!"}];e.RaiseReadyForTransaction(),e.TransactionGroup.AddTransaction(new B(e,f,r,{mutationName:i,mutationInputTypes:c},(m,w)=>{t.EndedAt=new Date,w&&m?(t.Success=!0,u(this.ConvertBackToMJFields(m))):(t.Success=!1,t.Message="Transaction failed",o())}))});{const u=await d.ExecuteGQL(y,r);if(u&&u[l+e.EntityInfo.ClassName])return t.Success=!0,t.EndedAt=new Date,this.ConvertBackToMJFields(u[l+e.EntityInfo.ClassName]);throw new Error(`Save failed for ${e.EntityInfo.ClassName}`)}}catch(r){return t.Success=!1,t.EndedAt=new Date,t.Message=r.response?.errors?.length>0?r.response.errors[0].message:r.message,D(r),null}}async Load(e,s,a=null,t){try{const r={};let l="",i="";for(let u=0;u<s.KeyValuePairs.length;u++){const o=e.Fields.find(w=>w.Name.trim().toLowerCase()===s.KeyValuePairs[u].FieldName.trim().toLowerCase()).EntityFieldInfo,c=s.GetValueByIndex(u),m=o.GraphQLType;if(i.length>0&&(i+=", "),i+=`$${o.CodeName}: ${m}!`,l.length>0&&(l+=", "),l+=`${o.CodeName}: $${o.CodeName}`,o.TSType===S.Number){if(isNaN(s.GetValueByIndex(u)))throw new Error(`Primary Key value ${c} (${o.Name}) is not a valid number`);r[o.CodeName]=parseInt(c)}else r[o.CodeName]=c}const n=a&&a.length>0?this.getRelatedEntityString(e.EntityInfo,a):"",p=new h,f=R`query Single${e.EntityInfo.ClassName}${n.length>0?"Full":""} (${i}) {
|
|
114
|
+
${e.EntityInfo.ClassName}(${l}) {
|
|
115
|
+
${e.Fields.filter(u=>!u.EntityFieldInfo.IsBinaryFieldType).map(u=>u.EntityFieldInfo.Name.trim().toLowerCase().startsWith("__mj_")?u.CodeName.replace("__mj_","_mj__"):u.CodeName).join(`
|
|
116
116
|
`)}
|
|
117
117
|
${n}
|
|
118
118
|
}
|
|
119
119
|
}
|
|
120
|
-
`,
|
|
121
|
-
${
|
|
122
|
-
${
|
|
120
|
+
`,y=await d.ExecuteGQL(f,r);return y&&y[e.EntityInfo.ClassName]?this.ConvertBackToMJFields(y[e.EntityInfo.ClassName]):null}catch(r){return D(r),null}}ConvertBackToMJFields(e){return new h().ReverseMapFields(e),e}getRelatedEntityString(e,s){let a="";for(let t=0;t<e.RelatedEntities.length;t++)if(s.indexOf(e.RelatedEntities[t].RelatedEntity)>=0){const r=e.RelatedEntities[t],l=this.Entities.find(n=>n.ID===r.RelatedEntityID);let i="";r.Type.toLowerCase().trim()==="many to many"?i=`${r.RelatedEntityCodeName}_${r.JoinEntityJoinField.replace(/\s/g,"")}`:i=`${r.RelatedEntityCodeName}_${r.RelatedEntityJoinField.replace(/\s/g,"")}`,a+=`
|
|
121
|
+
${i} {
|
|
122
|
+
${l.Fields.map(n=>n.CodeName).join(`
|
|
123
123
|
`)}
|
|
124
124
|
}
|
|
125
|
-
`}return a}async Delete(e,s,a){const t=new _;try{e.RegisterTransactionPreprocessing(),t.StartedAt=new Date,t.Type="delete",t.OriginalValues=e.Fields.map(o=>({FieldName:o.CodeName,Value:o.Value})),e.ResultHistory.push(t);const r={},
|
|
126
|
-
`),p+=`${c.CodeName}`}
|
|
125
|
+
`}return a}async Delete(e,s,a){const t=new _;try{e.RegisterTransactionPreprocessing(),t.StartedAt=new Date,t.Type="delete",t.OriginalValues=e.Fields.map(o=>({FieldName:o.CodeName,Value:o.Value})),e.ResultHistory.push(t);const r={},l=[];let i="",n="",p="";for(let o of e.PrimaryKey.KeyValuePairs){const c=e.Fields.find(m=>m.Name.trim().toLowerCase()===o.FieldName.trim().toLowerCase());r[c.CodeName]=c.Value,l.push({varName:c.CodeName,inputType:c.EntityFieldInfo.GraphQLType+"!"}),i.length>0&&(i+=", "),i+=`${c.CodeName}: $${c.CodeName}`,n.length>0&&(n+=", "),n+=`$${c.CodeName}: ${c.EntityFieldInfo.GraphQLType}!`,p.length>0&&(p+=`
|
|
126
|
+
`),p+=`${c.CodeName}`}l.push({varName:"options___",inputType:"DeleteOptionsInput!"}),r.options___=s||{SkipEntityAIActions:!1,SkipEntityActions:!1};const f="Delete"+e.EntityInfo.ClassName,y=R`${f}(${i}, options___: $options___) {
|
|
127
127
|
${p}
|
|
128
128
|
}
|
|
129
|
-
`,
|
|
130
|
-
${
|
|
129
|
+
`,u=R`mutation ${f} (${n}, $options___: DeleteOptionsInput!) {
|
|
130
|
+
${y}
|
|
131
131
|
}
|
|
132
|
-
`;if(e.TransactionGroup)return e.RaiseReadyForTransaction(),new Promise((o,c)=>{e.TransactionGroup.AddTransaction(new B(e,
|
|
132
|
+
`;if(e.TransactionGroup)return e.RaiseReadyForTransaction(),new Promise((o,c)=>{e.TransactionGroup.AddTransaction(new B(e,y,r,{mutationName:f,mutationInputTypes:l},(m,w)=>{if(t.EndedAt=new Date,w&&m){let E=!0;for(const U of e.PrimaryKey.KeyValuePairs)U.Value!==m[U.FieldName]&&(E=!1);E?(t.Success=!0,o(!0)):(t.Success=!1,t.Message="Transaction failed to commit",c())}else t.Success=!1,t.Message="Transaction failed to commit",c()}))});{const o=await d.ExecuteGQL(u,r);if(o&&o[f]){const c=o[f];for(let m of e.PrimaryKey.KeyValuePairs){let w=c[m.FieldName],E=m.Value;if(typeof E=="number"&&(E=E.toString()),typeof w=="number"&&(w=w.toString()),E!==w)throw new Error(`Primary key value mismatch in server Delete response. Field: ${m.FieldName}, Original: ${E}, Returned: ${w}`)}return t.Success=!0,t.EndedAt=new Date,!0}else throw new Error(`Delete failed for ${e.EntityInfo.Name}: ${e.PrimaryKey.ToString()} `)}}catch(r){return t.EndedAt=new Date,t.Success=!1,t.Message=r.response?.errors?.length>0?r.response.errors[0].message:r.message,D(r),!1}}async GetDatasetByName(e,s){const a=R`query GetDatasetByName($DatasetName: String!, $ItemFilters: [DatasetItemFilterTypeGQL!]) {
|
|
133
133
|
GetDatasetByName(DatasetName: $DatasetName, ItemFilters: $ItemFilters) {
|
|
134
134
|
DatasetID
|
|
135
135
|
DatasetName
|
|
@@ -147,16 +147,16 @@ var Q=Object.defineProperty;var E=(V,e)=>Q(V,"name",{value:e,configurable:!0});i
|
|
|
147
147
|
LatestUpdateDate
|
|
148
148
|
EntityUpdateDates
|
|
149
149
|
}
|
|
150
|
-
}`,t=await d.ExecuteGQL(a,{DatasetName:e,ItemFilters:s});return t&&t.GetDatasetStatusByName&&t.GetDatasetStatusByName.Success?{DatasetID:t.GetDatasetStatusByName.DatasetID,DatasetName:t.GetDatasetStatusByName.DatasetName,Success:t.GetDatasetStatusByName.Success,Status:t.GetDatasetStatusByName.Status,LatestUpdateDate:new Date(t.GetDatasetStatusByName.LatestUpdateDate),EntityUpdateDates:JSON.parse(t.GetDatasetStatusByName.EntityUpdateDates)}:{DatasetID:"",DatasetName:e,Success:!1,Status:"Unknown",LatestUpdateDate:null,EntityUpdateDates:null}}async CreateTransactionGroup(){return new
|
|
150
|
+
}`,t=await d.ExecuteGQL(a,{DatasetName:e,ItemFilters:s});return t&&t.GetDatasetStatusByName&&t.GetDatasetStatusByName.Success?{DatasetID:t.GetDatasetStatusByName.DatasetID,DatasetName:t.GetDatasetStatusByName.DatasetName,Success:t.GetDatasetStatusByName.Success,Status:t.GetDatasetStatusByName.Status,LatestUpdateDate:new Date(t.GetDatasetStatusByName.LatestUpdateDate),EntityUpdateDates:JSON.parse(t.GetDatasetStatusByName.EntityUpdateDates)}:{DatasetID:"",DatasetName:e,Success:!1,Status:"Unknown",LatestUpdateDate:null,EntityUpdateDates:null}}async CreateTransactionGroup(){return new x}async GetRecordFavoriteStatus(e,s,a){if(!a.Validate().IsValid)return!1;const r=this.Entities.find(n=>n.Name===s);if(!r)throw new Error(`Entity ${s} not found in metadata`);const l=R`query GetRecordFavoriteStatus($params: UserFavoriteSearchParams!) {
|
|
151
151
|
GetRecordFavoriteStatus(params: $params) {
|
|
152
152
|
Success
|
|
153
153
|
IsFavorite
|
|
154
154
|
}
|
|
155
|
-
}`,i=await d.ExecuteGQL(
|
|
155
|
+
}`,i=await d.ExecuteGQL(l,{params:{UserID:e,EntityID:r.ID,CompositeKey:{KeyValuePairs:this.ensureKeyValuePairValueIsString(a.KeyValuePairs)}}});if(i&&i.GetRecordFavoriteStatus&&i.GetRecordFavoriteStatus.Success)return i.GetRecordFavoriteStatus.IsFavorite}async SetRecordFavoriteStatus(e,s,a,t,r){const l=this.Entities.find(p=>p.Name===s);if(!l)throw new Error(`Entity ${s} not found in metadata`);const i=R`mutation SetRecordFavoriteStatus($params: UserFavoriteSetParams!) {
|
|
156
156
|
SetRecordFavoriteStatus(params: $params){
|
|
157
157
|
Success
|
|
158
158
|
}
|
|
159
|
-
}`,n=await d.ExecuteGQL(i,{params:{UserID:e,EntityID:
|
|
159
|
+
}`,n=await d.ExecuteGQL(i,{params:{UserID:e,EntityID:l.ID,CompositeKey:{KeyValuePairs:this.ensureKeyValuePairValueIsString(a.KeyValuePairs)},IsFavorite:t}});if(n&&n.SetRecordFavoriteStatus!==null)return n.SetRecordFavoriteStatus.Success}async GetEntityRecordName(e,s){if(!e||!s||s.KeyValuePairs?.length===0)return null;const a=R`query GetEntityRecordNameQuery ($EntityName: String!, $CompositeKey: CompositeKeyInputType!) {
|
|
160
160
|
GetEntityRecordName(EntityName: $EntityName, CompositeKey: $CompositeKey) {
|
|
161
161
|
Success
|
|
162
162
|
Status
|
|
@@ -175,18 +175,18 @@ var Q=Object.defineProperty;var E=(V,e)=>Q(V,"name",{value:e,configurable:!0});i
|
|
|
175
175
|
EntityName
|
|
176
176
|
RecordName
|
|
177
177
|
}
|
|
178
|
-
}`,a=await d.ExecuteGQL(s,{info:e.map(t=>({EntityName:t.EntityName,CompositeKey:{KeyValuePairs:this.ensureKeyValuePairValueIsString(t.CompositeKey.KeyValuePairs)}}))});if(a&&a.GetEntityRecordNames)return a.GetEntityRecordNames}static async ExecuteGQL(e,s,a=!0){try{return await d._client.request(e,s)}catch(t){if(t&&t.response&&t.response.errors?.length>0)if(t.response.errors[0]?.extensions?.code?.toUpperCase().trim()==="JWT_EXPIRED"){if(a)return await d.RefreshToken(),await d.ExecuteGQL(e,s,!1);throw D("JWT_EXPIRED and refreshTokenIfNeeded is false"),t}else throw t;else throw D(t),t}}static async RefreshToken(){if(d._configData.Data.RefreshTokenFunction){const e=await d._configData.Data.RefreshTokenFunction();if(e)d._configData.Token=e,d._client=this.CreateNewGraphQLClient(d._configData.URL,d._configData.Token,d._sessionId);else throw new Error("Refresh token function returned null or undefined token")}else throw new Error("No refresh token function provided")}static CreateNewGraphQLClient(e,s,a){return new
|
|
178
|
+
}`,a=await d.ExecuteGQL(s,{info:e.map(t=>({EntityName:t.EntityName,CompositeKey:{KeyValuePairs:this.ensureKeyValuePairValueIsString(t.CompositeKey.KeyValuePairs)}}))});if(a&&a.GetEntityRecordNames)return a.GetEntityRecordNames}static async ExecuteGQL(e,s,a=!0){try{return await d._client.request(e,s)}catch(t){if(t&&t.response&&t.response.errors?.length>0)if(t.response.errors[0]?.extensions?.code?.toUpperCase().trim()==="JWT_EXPIRED"){if(a)return await d.RefreshToken(),await d.ExecuteGQL(e,s,!1);throw D("JWT_EXPIRED and refreshTokenIfNeeded is false"),t}else throw t;else throw D(t),t}}static async RefreshToken(){if(d._configData.Data.RefreshTokenFunction){const e=await d._configData.Data.RefreshTokenFunction();if(e)d._configData.Token=e,d._client=this.CreateNewGraphQLClient(d._configData.URL,d._configData.Token,d._sessionId);else throw new Error("Refresh token function returned null or undefined token")}else throw new Error("No refresh token function provided")}static CreateNewGraphQLClient(e,s,a){return new Q(e,{headers:{authorization:"Bearer "+s,"x-session-id":a}})}userInfoString(){return this.infoString(new M(null,null))}userRoleInfoString(){return this.infoString(new b(null))}infoString(e){let s="";const a=Object.keys(e);for(const t of a)t.startsWith("__mj_")?s+=t.replace("__mj_","_mj__")+`
|
|
179
179
|
`:t.startsWith("_")||(s+=t+`
|
|
180
|
-
`);return s}get LocalStorageProvider(){return this._localStorageProvider||(this._localStorageProvider=new
|
|
180
|
+
`);return s}get LocalStorageProvider(){return this._localStorageProvider||(this._localStorageProvider=new $),this._localStorageProvider}get Metadata(){return this}PushStatusUpdates(e=null){e||(e=this.sessionId),this._wsClient||(this._wsClient=te({url:this.ConfigData.WSURL,connectionParams:{Authorization:"Bearer "+this.ConfigData.Token}}));const s=this._pushStatusRequests.find(r=>r.sessionId===e);if(s)return s.observable;const a=R`subscription StatusUpdates($sessionId: String!) {
|
|
181
181
|
statusUpdates(sessionId: $sessionId) {
|
|
182
182
|
date
|
|
183
183
|
message
|
|
184
184
|
sessionId
|
|
185
185
|
}
|
|
186
186
|
}
|
|
187
|
-
`,t=new ee(r=>(this._wsClient.subscribe({query:a,variables:{sessionId:e}},{next:
|
|
187
|
+
`,t=new ee(r=>(this._wsClient.subscribe({query:a,variables:{sessionId:e}},{next:l=>r.next(l.data.statusUpdates),error:l=>r.error(l),complete:()=>r.complete()}),()=>{console.log("would unsub here")}));return this._pushStatusRequests.push({sessionId:e,observable:t}),t}};N(d,"GraphQLDataProvider");let I=d;const v=class v{constructor(){this._localStorage={}}async getItem(e){return new Promise(s=>{this._localStorage.hasOwnProperty(e)?s(this._localStorage[e]):s(null)})}async setItem(e,s){return new Promise(a=>{this._localStorage[e]=s,a()})}async remove(e){return new Promise(s=>{this._localStorage.hasOwnProperty(e)&&delete this._localStorage[e],s()})}};N(v,"BrowserStorageProviderBase");let F=v;const re="MJ_Metadata",g="Metadata_KVPairs",L=class L extends F{constructor(){super(),this.dbPromise=Z(re,1,{upgrade(e){e.objectStoreNames.contains(g)||e.createObjectStore(g)}})}async setItem(e,s){const t=(await this.dbPromise).transaction(g,"readwrite");await t.objectStore(g).put(s,e),await t.done}async getItem(e){return await(await this.dbPromise).transaction(g).objectStore(g).get(e)}async remove(e){const a=(await this.dbPromise).transaction(g,"readwrite");await a.objectStore(g).delete(e),await a.done}};N(L,"BrowserIndexedDBStorageProvider");let $=L;const P=class P extends J{async HandleSubmit(e){let s="",a="";const t={};for(let i=0;i<e.length;i++){const n=e[i];let p=n.Instruction;if(n.Vars){const f=Object.keys(n.Vars);for(let y=0;y<f.length;y++){const u=f[y],o=`${u}_${i}`;t[o]=n.Vars[u];const c=new RegExp("\\$"+u,"g");p=p.replace(c,"$"+o);const m=n.ExtraData.mutationInputTypes.find(w=>w.varName===u)?.inputType;a+=`$${o}: ${m}
|
|
188
188
|
`}}s+=`mutation_${i}: `+p+`
|
|
189
189
|
`}s=`mutation TransactionGroup(${a}){
|
|
190
190
|
`+s+`
|
|
191
|
-
}`;const r=await I.ExecuteGQL(s,t),
|
|
191
|
+
}`;const r=await I.ExecuteGQL(s,t),l=[];for(let i=0;i<e.length;i++){const n=r[`mutation_${i}`],p=e[i];l.push(new j(p,n,n!==null))}return l}};N(P,"GraphQLTransactionGroup");let x=P;async function ne(V){const e=new I;return W.Provider=e,z.Provider=e,H.Provider=e,X.Provider=e,Y.Provider=e,await e.Config(V),ae.Instance.RaiseEvent({event:se.LoggedIn,eventCode:null,component:this,args:null}),e}N(ne,"setupGraphQLClient");export{h as FieldMapper,I as GraphQLDataProvider,C as GraphQLProviderConfigData,we as gql,ne as setupGraphQLClient};
|
|
192
192
|
//# sourceMappingURL=index.mjs.map
|