@memberjunction/graphql-dataprovider 2.20.2 → 2.20.3
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 +33 -28
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +49 -2
- package/dist/index.d.mts +49 -2
- package/dist/index.mjs +32 -27
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
package/dist/index.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { GraphQLClient } from 'graphql-request';
|
|
2
2
|
export { gql } from 'graphql-request';
|
|
3
|
-
import { ProviderConfigDataBase, ProviderBase, IEntityDataProvider, IMetadataProvider, IRunViewProvider, IRunReportProvider, IRunQueryProvider, UserInfo, RunReportParams, RunReportResult, RunQueryParams, RunQueryResult, RunViewParams, RunViewResult, EntityInfo, ProviderType,
|
|
3
|
+
import { CompositeKey, ProviderConfigDataBase, ProviderBase, IEntityDataProvider, IMetadataProvider, IRunViewProvider, IRunReportProvider, IRunQueryProvider, UserInfo, RunReportParams, RunReportResult, RunQueryParams, RunQueryResult, RunViewParams, RunViewResult, EntityInfo, ProviderType, RecordChange, RecordDependency, KeyValuePair, PotentialDuplicateRequest, PotentialDuplicateResponse, RecordMergeRequest, RecordMergeResult, BaseEntity, EntitySaveOptions, EntityDeleteOptions, DatasetItemFilterType, DatasetResultType, DatasetStatusResultType, TransactionGroupBase, EntityRecordNameInput, EntityRecordNameResult, ILocalStorageProvider } from '@memberjunction/core';
|
|
4
4
|
import { UserViewEntityExtended } from '@memberjunction/core-entities';
|
|
5
5
|
import { Observable } from 'rxjs';
|
|
6
6
|
|
|
@@ -23,6 +23,48 @@ declare class RolesAndUsersInput {
|
|
|
23
23
|
Users: UserInput[];
|
|
24
24
|
Roles: RoleInput[];
|
|
25
25
|
}
|
|
26
|
+
declare enum SyncDataActionType {
|
|
27
|
+
Create = "Create",
|
|
28
|
+
Update = "Update",
|
|
29
|
+
CreateOrUpdate = "CreateOrUpdate",
|
|
30
|
+
Delete = "Delete",
|
|
31
|
+
DeleteWithFilter = "DeleteWithFilter"
|
|
32
|
+
}
|
|
33
|
+
declare class ActionItemInput {
|
|
34
|
+
/**
|
|
35
|
+
* The name of the entity where action is to be taken
|
|
36
|
+
*/
|
|
37
|
+
EntityName: string;
|
|
38
|
+
/**
|
|
39
|
+
* For Update, CreateOrUpdate and Delete operations either a PrimaryKey or an AlternateKey must be provided. For Create and DeleteWithFilter operations, neither is used.
|
|
40
|
+
*/
|
|
41
|
+
PrimaryKey?: CompositeKey;
|
|
42
|
+
/**
|
|
43
|
+
* For Update, CreateOrUpdate and Delete operations either a PrimaryKey or an AlternateKey must be provided. For Create and DeleteWithFilter operations, neither is used.
|
|
44
|
+
*/
|
|
45
|
+
AlternateKey?: CompositeKey;
|
|
46
|
+
/**
|
|
47
|
+
* The type of action requested. The possible values are Create, Update, CreateOrUpdate, Delete, DeleteWithFilter
|
|
48
|
+
*/
|
|
49
|
+
Type: SyncDataActionType;
|
|
50
|
+
/**
|
|
51
|
+
* This field is a JSON representation of the field values of the entity to be created or updated. It is used for all ActionTypes except for
|
|
52
|
+
*/
|
|
53
|
+
RecordJSON?: string;
|
|
54
|
+
/**
|
|
55
|
+
* This field is only provided when the Action Type is DeleteWithFilter. It is a valid SQL expression that can be used in a where clause to get a list of records in a given entity to delete
|
|
56
|
+
*/
|
|
57
|
+
DeleteFilter?: string;
|
|
58
|
+
}
|
|
59
|
+
declare class SyncDataResult {
|
|
60
|
+
Success: boolean;
|
|
61
|
+
Results: ActionItemOutput[];
|
|
62
|
+
}
|
|
63
|
+
declare class ActionItemOutput {
|
|
64
|
+
input: ActionItemInput;
|
|
65
|
+
success: boolean;
|
|
66
|
+
errorMessage: string;
|
|
67
|
+
}
|
|
26
68
|
|
|
27
69
|
/**************************************************************************************************************
|
|
28
70
|
* The graphQLDataProvider provides a data provider for the entities framework that uses GraphQL to communicate
|
|
@@ -222,6 +264,11 @@ declare class GraphQLDataProvider extends ProviderBase implements IEntityDataPro
|
|
|
222
264
|
* @param data
|
|
223
265
|
*/
|
|
224
266
|
SyncRolesAndUsers(data: RolesAndUsersInput): Promise<boolean>;
|
|
267
|
+
/**
|
|
268
|
+
* Utility method to call the Sync Roles and Users mutation on the MJ API server, this can only be invoked by the system user
|
|
269
|
+
* @param data
|
|
270
|
+
*/
|
|
271
|
+
SyncData(items: ActionItemInput[]): Promise<SyncDataResult>;
|
|
225
272
|
}
|
|
226
273
|
|
|
227
274
|
/**
|
|
@@ -265,4 +312,4 @@ declare class FieldMapper {
|
|
|
265
312
|
ReverseMapFields(obj: Record<string, unknown>): Record<string, unknown>;
|
|
266
313
|
}
|
|
267
314
|
|
|
268
|
-
export { FieldMapper, GraphQLDataProvider, GraphQLProviderConfigData, RoleInput, RolesAndUsersInput, UserInput, setupGraphQLClient };
|
|
315
|
+
export { ActionItemInput, ActionItemOutput, FieldMapper, GraphQLDataProvider, GraphQLProviderConfigData, RoleInput, RolesAndUsersInput, SyncDataActionType, SyncDataResult, UserInput, setupGraphQLClient };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { GraphQLClient } from 'graphql-request';
|
|
2
2
|
export { gql } from 'graphql-request';
|
|
3
|
-
import { ProviderConfigDataBase, ProviderBase, IEntityDataProvider, IMetadataProvider, IRunViewProvider, IRunReportProvider, IRunQueryProvider, UserInfo, RunReportParams, RunReportResult, RunQueryParams, RunQueryResult, RunViewParams, RunViewResult, EntityInfo, ProviderType,
|
|
3
|
+
import { CompositeKey, ProviderConfigDataBase, ProviderBase, IEntityDataProvider, IMetadataProvider, IRunViewProvider, IRunReportProvider, IRunQueryProvider, UserInfo, RunReportParams, RunReportResult, RunQueryParams, RunQueryResult, RunViewParams, RunViewResult, EntityInfo, ProviderType, RecordChange, RecordDependency, KeyValuePair, PotentialDuplicateRequest, PotentialDuplicateResponse, RecordMergeRequest, RecordMergeResult, BaseEntity, EntitySaveOptions, EntityDeleteOptions, DatasetItemFilterType, DatasetResultType, DatasetStatusResultType, TransactionGroupBase, EntityRecordNameInput, EntityRecordNameResult, ILocalStorageProvider } from '@memberjunction/core';
|
|
4
4
|
import { UserViewEntityExtended } from '@memberjunction/core-entities';
|
|
5
5
|
import { Observable } from 'rxjs';
|
|
6
6
|
|
|
@@ -23,6 +23,48 @@ declare class RolesAndUsersInput {
|
|
|
23
23
|
Users: UserInput[];
|
|
24
24
|
Roles: RoleInput[];
|
|
25
25
|
}
|
|
26
|
+
declare enum SyncDataActionType {
|
|
27
|
+
Create = "Create",
|
|
28
|
+
Update = "Update",
|
|
29
|
+
CreateOrUpdate = "CreateOrUpdate",
|
|
30
|
+
Delete = "Delete",
|
|
31
|
+
DeleteWithFilter = "DeleteWithFilter"
|
|
32
|
+
}
|
|
33
|
+
declare class ActionItemInput {
|
|
34
|
+
/**
|
|
35
|
+
* The name of the entity where action is to be taken
|
|
36
|
+
*/
|
|
37
|
+
EntityName: string;
|
|
38
|
+
/**
|
|
39
|
+
* For Update, CreateOrUpdate and Delete operations either a PrimaryKey or an AlternateKey must be provided. For Create and DeleteWithFilter operations, neither is used.
|
|
40
|
+
*/
|
|
41
|
+
PrimaryKey?: CompositeKey;
|
|
42
|
+
/**
|
|
43
|
+
* For Update, CreateOrUpdate and Delete operations either a PrimaryKey or an AlternateKey must be provided. For Create and DeleteWithFilter operations, neither is used.
|
|
44
|
+
*/
|
|
45
|
+
AlternateKey?: CompositeKey;
|
|
46
|
+
/**
|
|
47
|
+
* The type of action requested. The possible values are Create, Update, CreateOrUpdate, Delete, DeleteWithFilter
|
|
48
|
+
*/
|
|
49
|
+
Type: SyncDataActionType;
|
|
50
|
+
/**
|
|
51
|
+
* This field is a JSON representation of the field values of the entity to be created or updated. It is used for all ActionTypes except for
|
|
52
|
+
*/
|
|
53
|
+
RecordJSON?: string;
|
|
54
|
+
/**
|
|
55
|
+
* This field is only provided when the Action Type is DeleteWithFilter. It is a valid SQL expression that can be used in a where clause to get a list of records in a given entity to delete
|
|
56
|
+
*/
|
|
57
|
+
DeleteFilter?: string;
|
|
58
|
+
}
|
|
59
|
+
declare class SyncDataResult {
|
|
60
|
+
Success: boolean;
|
|
61
|
+
Results: ActionItemOutput[];
|
|
62
|
+
}
|
|
63
|
+
declare class ActionItemOutput {
|
|
64
|
+
input: ActionItemInput;
|
|
65
|
+
success: boolean;
|
|
66
|
+
errorMessage: string;
|
|
67
|
+
}
|
|
26
68
|
|
|
27
69
|
/**************************************************************************************************************
|
|
28
70
|
* The graphQLDataProvider provides a data provider for the entities framework that uses GraphQL to communicate
|
|
@@ -222,6 +264,11 @@ declare class GraphQLDataProvider extends ProviderBase implements IEntityDataPro
|
|
|
222
264
|
* @param data
|
|
223
265
|
*/
|
|
224
266
|
SyncRolesAndUsers(data: RolesAndUsersInput): Promise<boolean>;
|
|
267
|
+
/**
|
|
268
|
+
* Utility method to call the Sync Roles and Users mutation on the MJ API server, this can only be invoked by the system user
|
|
269
|
+
* @param data
|
|
270
|
+
*/
|
|
271
|
+
SyncData(items: ActionItemInput[]): Promise<SyncDataResult>;
|
|
225
272
|
}
|
|
226
273
|
|
|
227
274
|
/**
|
|
@@ -265,4 +312,4 @@ declare class FieldMapper {
|
|
|
265
312
|
ReverseMapFields(obj: Record<string, unknown>): Record<string, unknown>;
|
|
266
313
|
}
|
|
267
314
|
|
|
268
|
-
export { FieldMapper, GraphQLDataProvider, GraphQLProviderConfigData, RoleInput, RolesAndUsersInput, UserInput, setupGraphQLClient };
|
|
315
|
+
export { ActionItemInput, ActionItemOutput, FieldMapper, GraphQLDataProvider, GraphQLProviderConfigData, RoleInput, RolesAndUsersInput, SyncDataActionType, SyncDataResult, UserInput, setupGraphQLClient };
|
package/dist/index.mjs
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
var
|
|
1
|
+
var Y=Object.defineProperty;var w=(E,e)=>Y(E,"name",{value:e,configurable:!0});import{gql as f,GraphQLClient as ee}from"graphql-request";import{gql as Fe}from"graphql-request";import{ProviderConfigDataBase as te,ProviderBase as se,LogError as D,UserInfo as W,ProviderType as ae,BaseEntityResult as z,EntityFieldTSType as g,TransactionItem as H,UserRoleInfo as re,TransactionGroupBase as ie,TransactionResult as ne,SetProvider as oe}from"@memberjunction/core";import{ViewInfo as X}from"@memberjunction/core-entities";import{openDB as ue}from"@tempfix/idb";import{Observable as le}from"rxjs";import{createClient as ce}from"graphql-ws";import{v4 as de}from"uuid";import{MJGlobal as ye,MJEventType as me}from"@memberjunction/global";const U=class U{constructor(){this._fieldMap={__mj_CreatedAt:"_mj__CreatedAt",__mj_UpdatedAt:"_mj__UpdatedAt",__mj_DeletedAt:"_mj__DeletedAt"}}MapFields(e){if(e)for(const a in e)a in this._fieldMap&&(e[this._fieldMap[a]]=e[a],delete e[a]);return e}MapFieldName(e){return this._fieldMap[e]??e}ReverseMapFieldName(e){return Object.entries(this._fieldMap).find(([a,s])=>s===e)?.[0]??e}ReverseMapFields(e){const a=Object.fromEntries(Object.entries(this._fieldMap).map(([s,t])=>[t,s]));for(const s in e)s in a&&(e[a[s]]=e[s],delete e[s]);return e}};w(U,"FieldMapper");let I=U;const M=class M extends te{get Token(){return this.Data.Token}set Token(e){this.Data.Token=e}get MJAPIKey(){return this.Data.MJAPIKey}set MJAPIKey(e){this.Data.MJAPIKey=e}get URL(){return this.Data.URL}get WSURL(){return this.Data.WSURL}get RefreshTokenFunction(){return this.Data.RefreshFunction}constructor(e,a,s,t,r,c,n,i){super({Token:e,URL:a,WSURL:s,MJAPIKey:i,RefreshTokenFunction:t},r,c,n)}};w(M,"GraphQLProviderConfigData");let C=M;const R=class R extends se{constructor(){super(),this._innerCurrentUserQueryString=`CurrentUser {
|
|
2
2
|
${this.userInfoString()}
|
|
3
3
|
UserRoles_UserIDArray {
|
|
4
4
|
${this.userRoleInfoString()}
|
|
5
5
|
}
|
|
6
6
|
}
|
|
7
|
-
`,this._currentUserQuery=
|
|
7
|
+
`,this._currentUserQuery=f`query CurrentUserAndRoles {
|
|
8
8
|
${this._innerCurrentUserQueryString}
|
|
9
|
-
}`,this._wsClient=null,this._pushStatusRequests=[],
|
|
9
|
+
}`,this._wsClient=null,this._pushStatusRequests=[],R._instance||(R._instance=this)}static get Instance(){return R._instance}get ConfigData(){return this._configData}get DatabaseConnection(){throw new Error("DatabaseConnection not implemented for the GraphQLDataProvider")}get InstanceConnectionString(){return this._configData.URL}GenerateUUID(){return de()}get LocalStoragePrefix(){return this._configData.URL.replace(/[^a-zA-Z0-9]/g,"_")+"."}async Config(e,a){try{const s=this.GenerateUUID();return a?(this._sessionId=s,this._configData=e,this._client=this.CreateNewGraphQLClient(e.URL,e.Token,this._sessionId,e.MJAPIKey)):(R.Instance._sessionId===void 0&&(R.Instance._sessionId=s),R.Instance._configData=e,R.Instance._client||(R.Instance._client=this.CreateNewGraphQLClient(e.URL,e.Token,R.Instance._sessionId,e.MJAPIKey))),super.Config(e)}catch(s){throw D(s),s}}get sessionId(){return this._sessionId}get AllowRefresh(){return!0}async GetCurrentUser(){const e=await this.ExecuteGQL(this._currentUserQuery,null);if(e){const a=this.ConvertBackToMJFields(e.CurrentUser),s=a.UserRoles_UserIDArray.map(t=>this.ConvertBackToMJFields(t));return a.UserRoles_UserIDArray=s,new W(this,{...a,UserRoles:s})}}async RunReport(e,a){const s=f`
|
|
10
10
|
query GetReportDataQuery ($ReportID: String!) {
|
|
11
11
|
GetReportData(ReportID: $ReportID) {
|
|
12
12
|
Success
|
|
@@ -15,7 +15,7 @@ var J=Object.defineProperty;var R=(V,e)=>J(V,"name",{value:e,configurable:!0});i
|
|
|
15
15
|
ExecutionTime
|
|
16
16
|
ErrorMessage
|
|
17
17
|
}
|
|
18
|
-
}`,t=await this.ExecuteGQL(s,{ReportID:e.ReportID});if(t&&t.GetReportData)return{ReportID:e.ReportID,Success:t.GetReportData.Success,Results:JSON.parse(t.GetReportData.Results),RowCount:t.GetReportData.RowCount,ExecutionTime:t.GetReportData.ExecutionTime,ErrorMessage:t.GetReportData.ErrorMessage}}async RunQuery(e,a){const s=
|
|
18
|
+
}`,t=await this.ExecuteGQL(s,{ReportID:e.ReportID});if(t&&t.GetReportData)return{ReportID:e.ReportID,Success:t.GetReportData.Success,Results:JSON.parse(t.GetReportData.Results),RowCount:t.GetReportData.RowCount,ExecutionTime:t.GetReportData.ExecutionTime,ErrorMessage:t.GetReportData.ErrorMessage}}async RunQuery(e,a){const s=f`
|
|
19
19
|
query GetQueryDataQuery ($QueryID: String!) {
|
|
20
20
|
GetQueryData(QueryID: $QueryID) {
|
|
21
21
|
Success
|
|
@@ -24,7 +24,7 @@ var J=Object.defineProperty;var R=(V,e)=>J(V,"name",{value:e,configurable:!0});i
|
|
|
24
24
|
ExecutionTime
|
|
25
25
|
ErrorMessage
|
|
26
26
|
}
|
|
27
|
-
}`,t=await this.ExecuteGQL(s,{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,a){try{let s="",t="";if(e){const r={};let c,n;if(e.ViewEntity)n=e.ViewEntity,c=n.Entity;else{const{entityName:o,v:l}=await this.getEntityNameAndUserView(e,a);n=l,c=o}const i=this.Entities.find(o=>o.Name===c);if(!i)throw new Error(`Entity ${c} not found in metadata`);let m=!1;e.ViewID?(s=`Run${i.ClassName}ViewByID`,t="RunViewByIDInput",r.ViewID=e.ViewID):e.ViewName?(s=`Run${i.ClassName}ViewByName`,t="RunViewByNameInput",r.ViewName=e.ViewName):(m=!0,s=`Run${i.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),m||(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 p=this.getViewRunTimeFieldList(i,n,e,m),d=
|
|
27
|
+
}`,t=await this.ExecuteGQL(s,{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,a){try{let s="",t="";if(e){const r={};let c,n;if(e.ViewEntity)n=e.ViewEntity,c=n.Entity;else{const{entityName:o,v:l}=await this.getEntityNameAndUserView(e,a);n=l,c=o}const i=this.Entities.find(o=>o.Name===c);if(!i)throw new Error(`Entity ${c} not found in metadata`);let m=!1;e.ViewID?(s=`Run${i.ClassName}ViewByID`,t="RunViewByIDInput",r.ViewID=e.ViewID):e.ViewName?(s=`Run${i.ClassName}ViewByName`,t="RunViewByNameInput",r.ViewName=e.ViewName):(m=!0,s=`Run${i.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),m||(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 p=this.getViewRunTimeFieldList(i,n,e,m),d=f`
|
|
28
28
|
query RunViewQuery ($input: ${t}!) {
|
|
29
29
|
${s}(input: $input) {
|
|
30
30
|
Results {
|
|
@@ -38,7 +38,7 @@ var J=Object.defineProperty;var R=(V,e)=>J(V,"name",{value:e,configurable:!0});i
|
|
|
38
38
|
Success
|
|
39
39
|
ErrorMessage
|
|
40
40
|
}
|
|
41
|
-
}`,u=await this.ExecuteGQL(d,{input:r});if(u&&u[s]){const o=u[s].Results;if(o&&o.length>0){const l=i.Fields.filter(y=>y.CodeName!==y.Name&&y.CodeName!==void 0);o.forEach(y=>{this.ConvertBackToMJFields(y),l.forEach(
|
|
41
|
+
}`,u=await this.ExecuteGQL(d,{input:r});if(u&&u[s]){const o=u[s].Results;if(o&&o.length>0){const l=i.Fields.filter(y=>y.CodeName!==y.Name&&y.CodeName!==void 0);o.forEach(y=>{this.ConvertBackToMJFields(y),l.forEach(h=>{y[h.Name]=y[h.CodeName]})})}return u[s]}}else throw"No parameters passed to RunView";return null}catch(s){throw D(s),s}}async RunViews(e,a){try{let s=[],t=[],r=[];for(const i of e){let m="",p="";const d={};let u=null,o=null;if(i.ViewEntity)o=i.ViewEntity,u=o.Get("Entity");else{const{entityName:h,v:N}=await this.getEntityNameAndUserView(i,a);o=N,u=h}const l=this.Entities.find(h=>h.Name===u);if(!l)throw new Error(`Entity ${u} not found in metadata`);t.push(l);let y=!1;i.ViewID?(m=`Run${l.ClassName}ViewByID`,p="RunViewByIDInput",d.ViewID=i.ViewID):i.ViewName?(m=`Run${l.ClassName}ViewByName`,p="RunViewByNameInput",d.ViewName=i.ViewName):(y=!0,m=`Run${l.ClassName}DynamicView`,p="RunDynamicViewInput",d.EntityName=i.EntityName),d.ExtraFilter=i.ExtraFilter||"",d.OrderBy=i.OrderBy||"",d.UserSearchString=i.UserSearchString||"",d.Fields=i.Fields,d.IgnoreMaxRows=i.IgnoreMaxRows||!1,d.MaxRows=i.MaxRows||0,d.ForceAuditLog=i.ForceAuditLog||!1,d.ResultType=i.ResultType||"simple",i.AuditLogDescription&&i.AuditLogDescription.length>0&&(d.AuditLogDescription=i.AuditLogDescription),y||(d.ExcludeUserViewRunID=i.ExcludeUserViewRunID||"",d.ExcludeDataFromAllPriorViewRuns=i.ExcludeDataFromAllPriorViewRuns||!1,d.OverrideExcludeFilter=i.OverrideExcludeFilter||"",d.SaveViewResults=i.SaveViewResults||!1),s.push(d),r.push(...this.getViewRunTimeFieldList(l,o,i,y))}const c=f`
|
|
42
42
|
query RunViewsQuery ($input: [RunViewGenericInput!]!) {
|
|
43
43
|
RunViews(input: $input) {
|
|
44
44
|
Results {
|
|
@@ -53,7 +53,7 @@ var J=Object.defineProperty;var R=(V,e)=>J(V,"name",{value:e,configurable:!0});i
|
|
|
53
53
|
Success
|
|
54
54
|
ErrorMessage
|
|
55
55
|
}
|
|
56
|
-
}`,n=await this.ExecuteGQL(c,{input:s});if(n&&n.RunViews){const i=n.RunViews;for(const[m,p]of i.entries())p.Results=p.Results.map(d=>{let u=JSON.parse(d.Data);return this.ConvertBackToMJFields(u),u});return i}return null}catch(s){throw D(s),s}}async getEntityNameAndUserView(e,a){let s,t;if(e.EntityName)s=e.EntityName;else if(e.ViewID)t=await
|
|
56
|
+
}`,n=await this.ExecuteGQL(c,{input:s});if(n&&n.RunViews){const i=n.RunViews;for(const[m,p]of i.entries())p.Results=p.Results.map(d=>{let u=JSON.parse(d.Data);return this.ConvertBackToMJFields(u),u});return i}return null}catch(s){throw D(s),s}}async getEntityNameAndUserView(e,a){let s,t;if(e.EntityName)s=e.EntityName;else if(e.ViewID)t=await X.GetViewEntity(e.ViewID,a),s=t.Entity;else if(e.ViewName)t=await X.GetViewEntityByName(e.ViewName,a),s=t.Entity;else throw new Error("No EntityName, ViewID or ViewName passed to RunView");return{entityName:s,v:t}}getViewRunTimeFieldList(e,a,s,t){const r=[],c=new I;if(s.Fields){for(const n of e.PrimaryKeys)s.Fields.find(i=>i.trim().toLowerCase()===n.Name.toLowerCase())===void 0&&r.push(n.Name);s.Fields.forEach(n=>{r.push(c.MapFieldName(n))})}else if(t)e.Fields.forEach(n=>{n.IsBinaryFieldType||r.push(c.MapFieldName(n.CodeName))});else{for(const n of e.PrimaryKeys)r.find(i=>i.trim().toLowerCase()===n.Name.toLowerCase())===void 0&&r.push(n.Name);a.Columns.forEach(n=>{n.hidden===!1&&!r.find(i=>i.trim().toLowerCase()===n.EntityField?.Name.trim().toLowerCase())&&n.EntityField&&r.push(c.MapFieldName(n.EntityField.CodeName))})}return r}get ProviderType(){return ae.Network}async GetRecordChanges(e,a){try{const s={EntityName:"Record Changes",ExtraFilter:`RecordID = '${a.Values()}' AND Entity = '${e}'`},t=await this.RunView(s);return t?t.Results.sort((r,c)=>r.ChangedAt>c.ChangedAt?-1:1):null}catch(s){throw D(s),s}}async GetRecordDependencies(e,a){try{const s=f`query GetRecordDependenciesQuery ($entityName: String!, $CompositeKey: CompositeKeyInputType!) {
|
|
57
57
|
GetRecordDependencies(entityName: $entityName, CompositeKey: $CompositeKey) {
|
|
58
58
|
EntityName
|
|
59
59
|
RelatedEntityName
|
|
@@ -65,7 +65,7 @@ var J=Object.defineProperty;var R=(V,e)=>J(V,"name",{value:e,configurable:!0});i
|
|
|
65
65
|
}
|
|
66
66
|
}
|
|
67
67
|
}
|
|
68
|
-
}`,t={entityName:e,CompositeKey:{KeyValuePairs:this.ensureKeyValuePairValueIsString(a.KeyValuePairs)}};return(await this.ExecuteGQL(s,t))?.GetRecordDependencies}catch(s){throw D(s),s}}ensureKeyValuePairValueIsString(e){return e.map(a=>({FieldName:a.FieldName,Value:a.Value.toString()}))}async GetRecordDuplicates(e,a){if(!e)return null;const s=
|
|
68
|
+
}`,t={entityName:e,CompositeKey:{KeyValuePairs:this.ensureKeyValuePairValueIsString(a.KeyValuePairs)}};return(await this.ExecuteGQL(s,t))?.GetRecordDependencies}catch(s){throw D(s),s}}ensureKeyValuePairValueIsString(e){return e.map(a=>({FieldName:a.FieldName,Value:a.Value.toString()}))}async GetRecordDuplicates(e,a){if(!e)return null;const s=f`query GetRecordDuplicatesQuery ($params: PotentialDuplicateRequestType!) {
|
|
69
69
|
GetRecordDuplicates(params: $params) {
|
|
70
70
|
Status
|
|
71
71
|
ErrorMessage
|
|
@@ -87,7 +87,7 @@ var J=Object.defineProperty;var R=(V,e)=>J(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(c=>c.Copy())};const r=await this.ExecuteGQL(s,{params:t});if(r&&r.GetRecordDuplicates)return r.GetRecordDuplicates}async MergeRecords(e){const a=this.Entities.find(s=>s.Name.trim().toLowerCase()===e.EntityName.trim().toLowerCase());if(!a||!a.AllowRecordMerge)throw new Error(`Entity ${e.EntityName} does not allow record merging, check the AllowRecordMerge property in the entity metadata`);try{const s=
|
|
90
|
+
}`;let t={EntityID:e.EntityID,EntityDocumentID:e.EntityDocumentID,ListID:e.ListID,ProbabilityScore:e.ProbabilityScore,Options:e.Options,RecordIDs:e.RecordIDs.map(c=>c.Copy())};const r=await this.ExecuteGQL(s,{params:t});if(r&&r.GetRecordDuplicates)return r.GetRecordDuplicates}async MergeRecords(e){const a=this.Entities.find(s=>s.Name.trim().toLowerCase()===e.EntityName.trim().toLowerCase());if(!a||!a.AllowRecordMerge)throw new Error(`Entity ${e.EntityName} does not allow record merging, check the AllowRecordMerge property in the entity metadata`);try{const s=f`mutation MergeRecordsMutation ($request: RecordMergeRequest!) {
|
|
91
91
|
MergeRecords(request: $request) {
|
|
92
92
|
Success
|
|
93
93
|
OverallStatus
|
|
@@ -104,32 +104,32 @@ var J=Object.defineProperty;var R=(V,e)=>J(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(c=>({FieldName:c.FieldName,Value:c.Value.toString()})),RecordsToMerge:e.RecordsToMerge.map(c=>c.Copy())};return(await this.ExecuteGQL(s,{request:t}))?.MergeRecords}catch(s){return D(s),{Success:!1,OverallStatus:s&&s.message?s.message:s,RecordStatus:[],RecordMergeLogID:"",Request:e}}}async Save(e,a,s){const t=new
|
|
107
|
+
}`,t={EntityName:e.EntityName,SurvivingRecordCompositeKey:{KeyValuePairs:this.ensureKeyValuePairValueIsString(e.SurvivingRecordCompositeKey.KeyValuePairs)},FieldMap:e.FieldMap?.map(c=>({FieldName:c.FieldName,Value:c.Value.toString()})),RecordsToMerge:e.RecordsToMerge.map(c=>c.Copy())};return(await this.ExecuteGQL(s,{request:t}))?.MergeRecords}catch(s){return D(s),{Success:!1,OverallStatus:s&&s.message?s.message:s,RecordStatus:[],RecordMergeLogID:"",Request:e}}}async Save(e,a,s){const t=new z;try{e.RegisterTransactionPreprocessing();const r={input:{}},c=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 n=`${c}${e.EntityInfo.ClassName}`,i=e.Fields.filter(u=>!u.ReadOnly||u.IsPrimaryKey&&e.IsSaved),m=new I,p=` ${n}(input: $input) {
|
|
108
108
|
${e.Fields.map(u=>m.MapFieldName(u.CodeName)).join(`
|
|
109
109
|
`)}
|
|
110
|
-
}`,d=
|
|
110
|
+
}`,d=f`mutation ${c}${e.EntityInfo.ClassName} ($input: ${n}Input!) {
|
|
111
111
|
${p}
|
|
112
112
|
}
|
|
113
|
-
`;for(let u=0;u<i.length;u++){const o=i[u];let l=o.Value;l&&o.EntityFieldInfo.TSType===
|
|
113
|
+
`;for(let u=0;u<i.length;u++){const o=i[u];let l=o.Value;l&&o.EntityFieldInfo.TSType===g.Date&&(l=l.getTime()),l&&o.EntityFieldInfo.TSType===g.Boolean&&typeof l!="boolean"&&(l=parseInt(l)!==0),l===null&&o.EntityFieldInfo.AllowsNull===!1&&(o.EntityFieldInfo.DefaultValue!==null?l=o.EntityFieldInfo.DefaultValue:o.FieldType===g.Number||o.FieldType===g.Boolean?l=0:l=""),r.input[o.CodeName]=l}if(c.trim().toLowerCase()==="update"&&s.SkipOldValuesCheck===!1){const u=[];e.Fields.forEach(o=>{let l=null;o.OldValue!==null&&o.OldValue!==void 0&&(o.EntityFieldInfo.TSType===g.Date?l=o.OldValue.getTime().toString():o.EntityFieldInfo.TSType===g.Boolean?l=o.OldValue===!0?"1":"0":typeof o.OldValue!="string"?l=o.OldValue.toString():l=o.OldValue),u.push({Key:o.CodeName,Value:l})}),r.input.OldValues___=u}if(e.TransactionGroup)return new Promise((u,o)=>{const l=[{varName:"input",inputType:n+"Input!"}];e.RaiseReadyForTransaction(),e.TransactionGroup.AddTransaction(new H(e,p,r,{mutationName:n,mutationInputTypes:l},(y,h)=>{t.EndedAt=new Date,h&&y?(t.Success=!0,u(this.ConvertBackToMJFields(y))):(t.Success=!1,t.Message="Transaction failed",o())}))});{const u=await this.ExecuteGQL(d,r);if(u&&u[c+e.EntityInfo.ClassName])return t.Success=!0,t.EndedAt=new Date,this.ConvertBackToMJFields(u[c+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,a,s=null,t){try{const r={};let c="",n="";for(let u=0;u<a.KeyValuePairs.length;u++){const o=e.Fields.find(h=>h.Name.trim().toLowerCase()===a.KeyValuePairs[u].FieldName.trim().toLowerCase()).EntityFieldInfo,l=a.GetValueByIndex(u),y=o.GraphQLType;if(n.length>0&&(n+=", "),n+=`$${o.CodeName}: ${y}!`,c.length>0&&(c+=", "),c+=`${o.CodeName}: $${o.CodeName}`,o.TSType===g.Number){if(isNaN(a.GetValueByIndex(u)))throw new Error(`Primary Key value ${l} (${o.Name}) is not a valid number`);r[o.CodeName]=parseInt(l)}else r[o.CodeName]=l}const i=s&&s.length>0?this.getRelatedEntityString(e.EntityInfo,s):"",m=new I,p=f`query Single${e.EntityInfo.ClassName}${i.length>0?"Full":""} (${n}) {
|
|
114
114
|
${e.EntityInfo.ClassName}(${c}) {
|
|
115
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
|
${i}
|
|
118
118
|
}
|
|
119
119
|
}
|
|
120
|
-
`,d=await this.ExecuteGQL(p,r);return d&&d[e.EntityInfo.ClassName]?this.ConvertBackToMJFields(d[e.EntityInfo.ClassName]):null}catch(r){return D(r),null}}ConvertBackToMJFields(e){return new
|
|
120
|
+
`,d=await this.ExecuteGQL(p,r);return d&&d[e.EntityInfo.ClassName]?this.ConvertBackToMJFields(d[e.EntityInfo.ClassName]):null}catch(r){return D(r),null}}ConvertBackToMJFields(e){return new I().ReverseMapFields(e),e}getRelatedEntityString(e,a){let s="";for(let t=0;t<e.RelatedEntities.length;t++)if(a.indexOf(e.RelatedEntities[t].RelatedEntity)>=0){const r=e.RelatedEntities[t],c=this.Entities.find(i=>i.ID===r.RelatedEntityID);let n="";r.Type.toLowerCase().trim()==="many to many"?n=`${r.RelatedEntityCodeName}_${r.JoinEntityJoinField.replace(/\s/g,"")}`:n=`${r.RelatedEntityCodeName}_${r.RelatedEntityJoinField.replace(/\s/g,"")}`,s+=`
|
|
121
121
|
${n} {
|
|
122
122
|
${c.Fields.map(i=>i.CodeName).join(`
|
|
123
123
|
`)}
|
|
124
124
|
}
|
|
125
|
-
`}return s}async Delete(e,a,s){const t=new
|
|
126
|
-
`),m+=`${l.CodeName}`}c.push({varName:"options___",inputType:"DeleteOptionsInput!"}),r.options___=a||{SkipEntityAIActions:!1,SkipEntityActions:!1};const p="Delete"+e.EntityInfo.ClassName,d=
|
|
125
|
+
`}return s}async Delete(e,a,s){const t=new z;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={},c=[];let n="",i="",m="";for(let o of e.PrimaryKey.KeyValuePairs){const l=e.Fields.find(y=>y.Name.trim().toLowerCase()===o.FieldName.trim().toLowerCase());r[l.CodeName]=l.Value,c.push({varName:l.CodeName,inputType:l.EntityFieldInfo.GraphQLType+"!"}),n.length>0&&(n+=", "),n+=`${l.CodeName}: $${l.CodeName}`,i.length>0&&(i+=", "),i+=`$${l.CodeName}: ${l.EntityFieldInfo.GraphQLType}!`,m.length>0&&(m+=`
|
|
126
|
+
`),m+=`${l.CodeName}`}c.push({varName:"options___",inputType:"DeleteOptionsInput!"}),r.options___=a||{SkipEntityAIActions:!1,SkipEntityActions:!1};const p="Delete"+e.EntityInfo.ClassName,d=f`${p}(${n}, options___: $options___) {
|
|
127
127
|
${m}
|
|
128
128
|
}
|
|
129
|
-
`,u=
|
|
129
|
+
`,u=f`mutation ${p} (${i}, $options___: DeleteOptionsInput!) {
|
|
130
130
|
${d}
|
|
131
131
|
}
|
|
132
|
-
`;if(e.TransactionGroup)return e.RaiseReadyForTransaction(),new Promise((o,l)=>{e.TransactionGroup.AddTransaction(new
|
|
132
|
+
`;if(e.TransactionGroup)return e.RaiseReadyForTransaction(),new Promise((o,l)=>{e.TransactionGroup.AddTransaction(new H(e,d,r,{mutationName:p,mutationInputTypes:c},(y,h)=>{if(t.EndedAt=new Date,h&&y){let N=!0;for(const j of e.PrimaryKey.KeyValuePairs)j.Value!==y[j.FieldName]&&(N=!1);N?(t.Success=!0,o(!0)):(t.Success=!1,t.Message="Transaction failed to commit",l())}else t.Success=!1,t.Message="Transaction failed to commit",l()}))});{const o=await this.ExecuteGQL(u,r);if(o&&o[p]){const l=o[p];for(let y of e.PrimaryKey.KeyValuePairs){let h=l[y.FieldName],N=y.Value;if(typeof N=="number"&&(N=N.toString()),typeof h=="number"&&(h=h.toString()),N!==h)throw new Error(`Primary key value mismatch in server Delete response. Field: ${y.FieldName}, Original: ${N}, Returned: ${h}`)}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,a){const s=f`query GetDatasetByName($DatasetName: String!, $ItemFilters: [DatasetItemFilterTypeGQL!]) {
|
|
133
133
|
GetDatasetByName(DatasetName: $DatasetName, ItemFilters: $ItemFilters) {
|
|
134
134
|
DatasetID
|
|
135
135
|
DatasetName
|
|
@@ -138,7 +138,7 @@ var J=Object.defineProperty;var R=(V,e)=>J(V,"name",{value:e,configurable:!0});i
|
|
|
138
138
|
LatestUpdateDate
|
|
139
139
|
Results
|
|
140
140
|
}
|
|
141
|
-
}`,t=await this.ExecuteGQL(s,{DatasetName:e,ItemFilters:a});return t&&t.GetDatasetByName&&t.GetDatasetByName.Success?{DatasetID:t.GetDatasetByName.DatasetID,DatasetName:t.GetDatasetByName.DatasetName,Success:t.GetDatasetByName.Success,Status:t.GetDatasetByName.Status,LatestUpdateDate:new Date(t.GetDatasetByName.LatestUpdateDate),Results:JSON.parse(t.GetDatasetByName.Results)}:{DatasetID:"",DatasetName:e,Success:!1,Status:"Unknown",LatestUpdateDate:null,Results:null}}async GetDatasetStatusByName(e,a){const s=
|
|
141
|
+
}`,t=await this.ExecuteGQL(s,{DatasetName:e,ItemFilters:a});return t&&t.GetDatasetByName&&t.GetDatasetByName.Success?{DatasetID:t.GetDatasetByName.DatasetID,DatasetName:t.GetDatasetByName.DatasetName,Success:t.GetDatasetByName.Success,Status:t.GetDatasetByName.Status,LatestUpdateDate:new Date(t.GetDatasetByName.LatestUpdateDate),Results:JSON.parse(t.GetDatasetByName.Results)}:{DatasetID:"",DatasetName:e,Success:!1,Status:"Unknown",LatestUpdateDate:null,Results:null}}async GetDatasetStatusByName(e,a){const s=f`query GetDatasetStatusByName($DatasetName: String!, $ItemFilters: [DatasetItemFilterTypeGQL!]) {
|
|
142
142
|
GetDatasetStatusByName(DatasetName: $DatasetName, ItemFilters: $ItemFilters) {
|
|
143
143
|
DatasetID
|
|
144
144
|
DatasetName
|
|
@@ -147,22 +147,22 @@ var J=Object.defineProperty;var R=(V,e)=>J(V,"name",{value:e,configurable:!0});i
|
|
|
147
147
|
LatestUpdateDate
|
|
148
148
|
EntityUpdateDates
|
|
149
149
|
}
|
|
150
|
-
}`,t=await this.ExecuteGQL(s,{DatasetName:e,ItemFilters:a});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 this.ExecuteGQL(s,{DatasetName:e,ItemFilters:a});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 G(this)}async GetRecordFavoriteStatus(e,a,s){if(!s.Validate().IsValid)return!1;const r=this.Entities.find(i=>i.Name===a);if(!r)throw new Error(`Entity ${a} not found in metadata`);const c=f`query GetRecordFavoriteStatus($params: UserFavoriteSearchParams!) {
|
|
151
151
|
GetRecordFavoriteStatus(params: $params) {
|
|
152
152
|
Success
|
|
153
153
|
IsFavorite
|
|
154
154
|
}
|
|
155
|
-
}`,n=await this.ExecuteGQL(c,{params:{UserID:e,EntityID:r.ID,CompositeKey:{KeyValuePairs:this.ensureKeyValuePairValueIsString(s.KeyValuePairs)}}});if(n&&n.GetRecordFavoriteStatus&&n.GetRecordFavoriteStatus.Success)return n.GetRecordFavoriteStatus.IsFavorite}async SetRecordFavoriteStatus(e,a,s,t,r){const c=this.Entities.find(m=>m.Name===a);if(!c)throw new Error(`Entity ${a} not found in metadata`);const n=
|
|
155
|
+
}`,n=await this.ExecuteGQL(c,{params:{UserID:e,EntityID:r.ID,CompositeKey:{KeyValuePairs:this.ensureKeyValuePairValueIsString(s.KeyValuePairs)}}});if(n&&n.GetRecordFavoriteStatus&&n.GetRecordFavoriteStatus.Success)return n.GetRecordFavoriteStatus.IsFavorite}async SetRecordFavoriteStatus(e,a,s,t,r){const c=this.Entities.find(m=>m.Name===a);if(!c)throw new Error(`Entity ${a} not found in metadata`);const n=f`mutation SetRecordFavoriteStatus($params: UserFavoriteSetParams!) {
|
|
156
156
|
SetRecordFavoriteStatus(params: $params){
|
|
157
157
|
Success
|
|
158
158
|
}
|
|
159
|
-
}`,i=await this.ExecuteGQL(n,{params:{UserID:e,EntityID:c.ID,CompositeKey:{KeyValuePairs:this.ensureKeyValuePairValueIsString(s.KeyValuePairs)},IsFavorite:t}});if(i&&i.SetRecordFavoriteStatus!==null)return i.SetRecordFavoriteStatus.Success}async GetEntityRecordName(e,a){if(!e||!a||a.KeyValuePairs?.length===0)return null;const s=
|
|
159
|
+
}`,i=await this.ExecuteGQL(n,{params:{UserID:e,EntityID:c.ID,CompositeKey:{KeyValuePairs:this.ensureKeyValuePairValueIsString(s.KeyValuePairs)},IsFavorite:t}});if(i&&i.SetRecordFavoriteStatus!==null)return i.SetRecordFavoriteStatus.Success}async GetEntityRecordName(e,a){if(!e||!a||a.KeyValuePairs?.length===0)return null;const s=f`query GetEntityRecordNameQuery ($EntityName: String!, $CompositeKey: CompositeKeyInputType!) {
|
|
160
160
|
GetEntityRecordName(EntityName: $EntityName, CompositeKey: $CompositeKey) {
|
|
161
161
|
Success
|
|
162
162
|
Status
|
|
163
163
|
RecordName
|
|
164
164
|
}
|
|
165
|
-
}`,t=await this.ExecuteGQL(s,{EntityName:e,CompositeKey:{KeyValuePairs:this.ensureKeyValuePairValueIsString(a.KeyValuePairs)}});if(t&&t.GetEntityRecordName&&t.GetEntityRecordName.Success)return t.GetEntityRecordName.RecordName}async GetEntityRecordNames(e){if(!e)return null;const a=
|
|
165
|
+
}`,t=await this.ExecuteGQL(s,{EntityName:e,CompositeKey:{KeyValuePairs:this.ensureKeyValuePairValueIsString(a.KeyValuePairs)}});if(t&&t.GetEntityRecordName&&t.GetEntityRecordName.Success)return t.GetEntityRecordName.RecordName}async GetEntityRecordNames(e){if(!e)return null;const a=f`query GetEntityRecordNamesQuery ($info: [EntityRecordNameInput!]!) {
|
|
166
166
|
GetEntityRecordNames(info: $info) {
|
|
167
167
|
Success
|
|
168
168
|
Status
|
|
@@ -175,22 +175,27 @@ var J=Object.defineProperty;var R=(V,e)=>J(V,"name",{value:e,configurable:!0});i
|
|
|
175
175
|
EntityName
|
|
176
176
|
RecordName
|
|
177
177
|
}
|
|
178
|
-
}`,s=await this.ExecuteGQL(a,{info:e.map(t=>({EntityName:t.EntityName,CompositeKey:{KeyValuePairs:this.ensureKeyValuePairValueIsString(t.CompositeKey.KeyValuePairs)}}))});if(s&&s.GetEntityRecordNames)return s.GetEntityRecordNames}static async ExecuteGQL(e,a,s=!0){return
|
|
178
|
+
}`,s=await this.ExecuteGQL(a,{info:e.map(t=>({EntityName:t.EntityName,CompositeKey:{KeyValuePairs:this.ensureKeyValuePairValueIsString(t.CompositeKey.KeyValuePairs)}}))});if(s&&s.GetEntityRecordNames)return s.GetEntityRecordNames}static async ExecuteGQL(e,a,s=!0){return R.Instance.ExecuteGQL(e,a,s)}async ExecuteGQL(e,a,s=!0){try{return await this._client.request(e,a)}catch(t){if(t&&t.response&&t.response.errors?.length>0)if(t.response.errors[0]?.extensions?.code?.toUpperCase().trim()==="JWT_EXPIRED"){if(s)return await this.RefreshToken(),await this.ExecuteGQL(e,a,!1);throw D("JWT_EXPIRED and refreshTokenIfNeeded is false"),t}else throw t;else throw D(t),t}}async RefreshToken(){if(this._configData.Data.RefreshTokenFunction){const e=await this._configData.Data.RefreshTokenFunction();if(e)this._configData.Token=e,this._client=this.CreateNewGraphQLClient(this._configData.URL,this._configData.Token,this._sessionId,this._configData.MJAPIKey);else throw new Error("Refresh token function returned null or undefined token")}else throw new Error("No refresh token function provided")}static async RefreshToken(){return R.Instance.RefreshToken()}CreateNewGraphQLClient(e,a,s,t){const r={"x-session-id":s};return a&&(r.authorization="Bearer "+a),t&&(r["x-mj-api-key"]=t),new ee(e,{headers:r})}userInfoString(){return this.infoString(new W(null,null))}userRoleInfoString(){return this.infoString(new re(null))}infoString(e){let a="";const s=Object.keys(e);for(const t of s)t.startsWith("__mj_")?a+=t.replace("__mj_","_mj__")+`
|
|
179
179
|
`:t.startsWith("_")||(a+=t+`
|
|
180
|
-
`);return a}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=
|
|
180
|
+
`);return a}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=ce({url:this.ConfigData.WSURL,connectionParams:{Authorization:"Bearer "+this.ConfigData.Token}}));const a=this._pushStatusRequests.find(r=>r.sessionId===e);if(a)return a.observable;const s=f`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
|
|
187
|
+
`,t=new le(r=>(this._wsClient.subscribe({query:s,variables:{sessionId:e}},{next:c=>r.next(c.data.statusUpdates),error:c=>r.error(c),complete:()=>r.complete()}),()=>{console.log("would unsub here")}));return this._pushStatusRequests.push({sessionId:e,observable:t}),t}async SyncRolesAndUsers(e){const a=f`mutation SyncRolesAndUsers($data: RolesAndUsersInputType!) {
|
|
188
188
|
SyncRolesAndUsers(data: $data) {
|
|
189
189
|
Success
|
|
190
190
|
}
|
|
191
|
-
}`;return(await this.ExecuteGQL(a,{data:e})).SyncRolesAndUsers.Success}
|
|
191
|
+
}`;return(await this.ExecuteGQL(a,{data:e})).SyncRolesAndUsers.Success}async SyncData(e){const a=f`mutation SyncData($items: [ActionItemInputType!]!) {
|
|
192
|
+
SyncData(items: $items) {
|
|
193
|
+
Success
|
|
194
|
+
Results
|
|
195
|
+
}
|
|
196
|
+
}`;return(await this.ExecuteGQL(a,{items:e})).SyncRolesAndUsers.Success}};w(R,"GraphQLDataProvider");let V=R;const K=class K{constructor(){this._localStorage={}}async getItem(e){return new Promise(a=>{this._localStorage.hasOwnProperty(e)?a(this._localStorage[e]):a(null)})}async setItem(e,a){return new Promise(s=>{this._localStorage[e]=a,s()})}async remove(e){return new Promise(a=>{this._localStorage.hasOwnProperty(e)&&delete this._localStorage[e],a()})}};w(K,"BrowserStorageProviderBase");let F=K;const pe="MJ_Metadata",S="Metadata_KVPairs",Q=class Q extends F{constructor(){super(),this.dbPromise=ue(pe,1,{upgrade(e){e.objectStoreNames.contains(S)||e.createObjectStore(S)}})}async setItem(e,a){const t=(await this.dbPromise).transaction(S,"readwrite");await t.objectStore(S).put(a,e),await t.done}async getItem(e){return await(await this.dbPromise).transaction(S).objectStore(S).get(e)}async remove(e){const s=(await this.dbPromise).transaction(S,"readwrite");await s.objectStore(S).delete(e),await s.done}};w(Q,"BrowserIndexedDBStorageProvider");let $=Q;const A=class A extends ie{constructor(e){super(),this._provider=e}async HandleSubmit(e){let a="",s="";const t={};for(let n=0;n<e.length;n++){const i=e[n];let m=i.Instruction;if(i.Vars){const p=Object.keys(i.Vars);for(let d=0;d<p.length;d++){const u=p[d],o=`${u}_${n}`;t[o]=i.Vars[u];const l=new RegExp("\\$"+u,"g");m=m.replace(l,"$"+o);const y=i.ExtraData.mutationInputTypes.find(h=>h.varName===u)?.inputType;s+=`$${o}: ${y}
|
|
192
197
|
`}}a+=`mutation_${n}: `+m+`
|
|
193
198
|
`}a=`mutation TransactionGroup(${s}){
|
|
194
199
|
`+a+`
|
|
195
|
-
}`;const r=await this._provider.ExecuteGQL(a,t),c=[];for(let n=0;n<e.length;n++){const i=r[`mutation_${n}`],m=e[n];c.push(new
|
|
200
|
+
}`;const r=await this._provider.ExecuteGQL(a,t),c=[];for(let n=0;n<e.length;n++){const i=r[`mutation_${n}`],m=e[n];c.push(new ne(m,i,i!==null))}return c}};w(A,"GraphQLTransactionGroup");let G=A;async function fe(E){const e=new V;return oe(e),await e.Config(E),ye.Instance.RaiseEvent({event:me.LoggedIn,eventCode:null,component:this,args:null}),e}w(fe,"setupGraphQLClient");const k=class k{};w(k,"RoleInput");let T=k;const B=class B{};w(B,"UserInput");let _=B;const O=class O{};w(O,"RolesAndUsersInput");let v=O;var Z=(E=>(E.Create="Create",E.Update="Update",E.CreateOrUpdate="CreateOrUpdate",E.Delete="Delete",E.DeleteWithFilter="DeleteWithFilter",E))(Z||{});const q=class q{};w(q,"ActionItemInput");let L=q;const b=class b{constructor(){this.Results=[]}};w(b,"SyncDataResult");let P=b;const J=class J{};w(J,"ActionItemOutput");let x=J;export{L as ActionItemInput,x as ActionItemOutput,I as FieldMapper,V as GraphQLDataProvider,C as GraphQLProviderConfigData,T as RoleInput,v as RolesAndUsersInput,Z as SyncDataActionType,P as SyncDataResult,_ as UserInput,Fe as gql,fe as setupGraphQLClient};
|
|
196
201
|
//# sourceMappingURL=index.mjs.map
|