@memberjunction/graphql-dataprovider 2.99.0 → 2.100.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 +98 -22
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +750 -1
- package/dist/index.d.mts +750 -1
- package/dist/index.mjs +124 -48
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -5
package/dist/index.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var pe=Object.defineProperty;var f=(D,e)=>pe(D,"name",{value:e,configurable:!0});var y=require("graphql-request"),u=require("@memberjunction/core"),de=require("@memberjunction/core-entities"),fe=require("@tempfix/idb"),ye=require("rxjs"),me=require("graphql-ws"),Se=require("uuid"),P=require("@memberjunction/global");const K=class K{constructor(){this._fieldMap={__mj_CreatedAt:"_mj__CreatedAt",__mj_UpdatedAt:"_mj__UpdatedAt",__mj_DeletedAt:"_mj__DeletedAt"}}MapFields(e){if(e)for(const t in e)t in this._fieldMap&&(e[this._fieldMap[t]]=e[t],delete e[t]);return e}MapFieldName(e){return this._fieldMap[e]??e}ReverseMapFieldName(e){return Object.entries(this._fieldMap).find(([t,r])=>r===e)?.[0]??e}ReverseMapFields(e){const t=Object.fromEntries(Object.entries(this._fieldMap).map(([r,s])=>[s,r]));for(const r in e)r in t&&(e[t[r]]=e[r],delete e[r]);return e}};f(K,"FieldMapper");let w=K;const J=class J extends u.TransactionGroupBase{constructor(e){super(),this._provider=e}async HandleSubmit(){const e=y.gql`
|
|
2
2
|
mutation ExecuteTransactionGroup($group: TransactionInputType!) {
|
|
3
3
|
ExecuteTransactionGroup(group: $group) {
|
|
4
4
|
Success
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
ResultsJSON
|
|
7
7
|
}
|
|
8
8
|
}
|
|
9
|
-
`,t=[];for(const a of this.PendingTransactions)t.push({EntityName:a.BaseEntity.EntityInfo.Name,EntityObjectJSON:await a.BaseEntity.GetDataObjectJSON(),OperationType:a.OperationType});const r={group:{Items:t,Variables:this.Variables.map(a=>({Name:a.Name,ItemIndex:this.MapVariableEntityObjectToPosition(a),FieldName:a.FieldName,Type:a.Type}))}},s=await this._provider.ExecuteGQL(e,r);if(s&&s.ExecuteTransactionGroup){const a=s.ExecuteTransactionGroup,n=[];for(let i=0;i<this.PendingTransactions.length;i++){const o=a.ResultsJSON[i],m=P.SafeJSONParse(o),
|
|
9
|
+
`,t=[];for(const a of this.PendingTransactions)t.push({EntityName:a.BaseEntity.EntityInfo.Name,EntityObjectJSON:await a.BaseEntity.GetDataObjectJSON(),OperationType:a.OperationType});const r={group:{Items:t,Variables:this.Variables.map(a=>({Name:a.Name,ItemIndex:this.MapVariableEntityObjectToPosition(a),FieldName:a.FieldName,Type:a.Type}))}},s=await this._provider.ExecuteGQL(e,r);if(s&&s.ExecuteTransactionGroup){const a=s.ExecuteTransactionGroup,n=[];for(let i=0;i<this.PendingTransactions.length;i++){const o=a.ResultsJSON[i],m=P.SafeJSONParse(o),p=this.PendingTransactions[i];n.push(new u.TransactionResult(p,m,m!==null))}return n}else throw new Error("Failed to execute transaction group")}};f(J,"GraphQLTransactionGroup");let $=J;const j=class j{constructor(e){this._dataProvider=e}async RunAIPrompt(e){try{const t=y.gql`
|
|
10
10
|
mutation RunAIPrompt(
|
|
11
11
|
$promptId: String!,
|
|
12
12
|
$data: String,
|
|
@@ -130,7 +130,7 @@
|
|
|
130
130
|
error
|
|
131
131
|
}
|
|
132
132
|
}
|
|
133
|
-
`,s={textToEmbed:Array.isArray(e.textToEmbed)?e.textToEmbed:[e.textToEmbed],modelSize:e.modelSize},a=await this._dataProvider.ExecuteGQL(t,s);if(!a?.EmbedText)throw new Error("Invalid response from server");const n=a.EmbedText;return{embeddings:Array.isArray(e.textToEmbed)?n.embeddings:n.embeddings[0],modelName:n.modelName,vectorDimensions:n.vectorDimensions,error:n.error}}catch(t){const r=t;return u.LogError(`Error generating embeddings: ${r}`),{embeddings:Array.isArray(e.textToEmbed)?[]:[],modelName:"Unknown",vectorDimensions:0,error:r.message||"Unknown error occurred"}}}};f(
|
|
133
|
+
`,s={textToEmbed:Array.isArray(e.textToEmbed)?e.textToEmbed:[e.textToEmbed],modelSize:e.modelSize},a=await this._dataProvider.ExecuteGQL(t,s);if(!a?.EmbedText)throw new Error("Invalid response from server");const n=a.EmbedText;return{embeddings:Array.isArray(e.textToEmbed)?n.embeddings:n.embeddings[0],modelName:n.modelName,vectorDimensions:n.vectorDimensions,error:n.error}}catch(t){const r=t;return u.LogError(`Error generating embeddings: ${r}`),{embeddings:Array.isArray(e.textToEmbed)?[]:[],modelName:"Unknown",vectorDimensions:0,error:r.message||"Unknown error occurred"}}}};f(j,"GraphQLAIClient");let N=j;const z=class z extends u.ProviderConfigDataBase{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,t,r,s,a,n,i,o){super({Token:e,URL:t,WSURL:r,MJAPIKey:o,RefreshTokenFunction:s},a,n,i)}};f(z,"GraphQLProviderConfigData");let C=z;const h=class h extends u.ProviderBase{constructor(){super(),this._innerCurrentUserQueryString=`CurrentUser {
|
|
134
134
|
${this.userInfoString()}
|
|
135
135
|
UserRoles_UserIDArray {
|
|
136
136
|
${this.userRoleInfoString()}
|
|
@@ -138,7 +138,7 @@
|
|
|
138
138
|
}
|
|
139
139
|
`,this._currentUserQuery=y.gql`query CurrentUserAndRoles {
|
|
140
140
|
${this._innerCurrentUserQueryString}
|
|
141
|
-
}`,this._wsClient=null,this._pushStatusRequests=[],
|
|
141
|
+
}`,this._wsClient=null,this._pushStatusRequests=[],h._instance||(h._instance=this)}static get Instance(){return h._instance}get ConfigData(){return this._configData}get AI(){return this._aiClient||(this._aiClient=new N(this)),this._aiClient}get DatabaseConnection(){throw new Error("DatabaseConnection not implemented for the GraphQLDataProvider")}get InstanceConnectionString(){return this._configData.URL}GenerateUUID(){return Se.v4()}get LocalStoragePrefix(){if(this._configData===void 0||this._configData.URL===void 0)throw new Error("GraphQLDataProvider: ConfigData is not set. Please call Config() first.");return this._configData.URL.replace(/[^a-zA-Z0-9]/g,"_")+"."}async GetStoredSessionID(){try{const e=this.LocalStorageProvider;if(e){const t=this.LocalStoragePrefix+"sessionId";return await e.GetItem(t)}return null}catch(e){return console.error("Error retrieving session ID from local storage:",e),null}}async SaveStoredSessionID(e){try{const t=this.LocalStorageProvider;if(t){const r=this.LocalStoragePrefix+"sessionId";await t.SetItem(r,e)}}catch{}}async GetPreferredUUID(e){const t=await this.GetStoredSessionID();return e||!t?this.GenerateUUID():t}async Config(e,t,r,s){try{return r?(this._configData=e,this._sessionId=await this.GetPreferredUUID(s),this._client=this.CreateNewGraphQLClient(e.URL,e.Token,this._sessionId,e.MJAPIKey),await this.SaveStoredSessionID(this._sessionId)):(h.Instance._configData=e,h.Instance._sessionId===void 0&&(h.Instance._sessionId=await this.GetPreferredUUID(s)),h.Instance._client||(h.Instance._client=this.CreateNewGraphQLClient(e.URL,e.Token,h.Instance._sessionId,e.MJAPIKey)),await h.Instance.SaveStoredSessionID(h.Instance._sessionId)),super.Config(e)}catch(a){throw u.LogError(a),a}}get sessionId(){return this._sessionId}get AllowRefresh(){return!0}async GetCurrentUser(){const e=await this.ExecuteGQL(this._currentUserQuery,null);if(e){const t=this.ConvertBackToMJFields(e.CurrentUser),r=t.UserRoles_UserIDArray.map(s=>this.ConvertBackToMJFields(s));return t.UserRoles_UserIDArray=r,new u.UserInfo(this,{...t,UserRoles:r})}}async RunReport(e,t){const r=y.gql`
|
|
142
142
|
query GetReportDataQuery ($ReportID: String!) {
|
|
143
143
|
GetReportData(ReportID: $ReportID) {
|
|
144
144
|
Success
|
|
@@ -153,13 +153,13 @@
|
|
|
153
153
|
${this.QueryReturnFieldList}
|
|
154
154
|
}
|
|
155
155
|
}
|
|
156
|
-
`,m={QueryID:e};t!==void 0&&(m.CategoryID=t),r!==void 0&&(m.CategoryPath=r),a!==void 0&&(m.Parameters=a),n!==void 0&&(m.MaxRows=n),i!==void 0&&(m.StartRow=i);const
|
|
156
|
+
`,m={QueryID:e};t!==void 0&&(m.CategoryID=t),r!==void 0&&(m.CategoryPath=r),a!==void 0&&(m.Parameters=a),n!==void 0&&(m.MaxRows=n),i!==void 0&&(m.StartRow=i);const p=await this.ExecuteGQL(o,m);if(p&&p.GetQueryData)return this.TransformQueryPayload(p.GetQueryData)}async RunQueryByName(e,t,r,s,a,n,i){const o=y.gql`
|
|
157
157
|
query GetQueryDataByNameQuery($QueryName: String!, $CategoryID: String, $CategoryPath: String, $Parameters: JSONObject, $MaxRows: Int, $StartRow: Int) {
|
|
158
158
|
GetQueryDataByName(QueryName: $QueryName, CategoryID: $CategoryID, CategoryPath: $CategoryPath, Parameters: $Parameters, MaxRows: $MaxRows, StartRow: $StartRow) {
|
|
159
159
|
${this.QueryReturnFieldList}
|
|
160
160
|
}
|
|
161
161
|
}
|
|
162
|
-
`,m={QueryName:e};t!==void 0&&(m.CategoryID=t),r!==void 0&&(m.CategoryPath=r),a!==void 0&&(m.Parameters=a),n!==void 0&&(m.MaxRows=n),i!==void 0&&(m.StartRow=i);const
|
|
162
|
+
`,m={QueryName:e};t!==void 0&&(m.CategoryID=t),r!==void 0&&(m.CategoryPath=r),a!==void 0&&(m.Parameters=a),n!==void 0&&(m.MaxRows=n),i!==void 0&&(m.StartRow=i);const p=await this.ExecuteGQL(o,m);if(p&&p.GetQueryDataByName)return this.TransformQueryPayload(p.GetQueryDataByName)}get QueryReturnFieldList(){return`
|
|
163
163
|
Success
|
|
164
164
|
QueryID
|
|
165
165
|
QueryName
|
|
@@ -168,11 +168,11 @@
|
|
|
168
168
|
TotalRowCount
|
|
169
169
|
ExecutionTime
|
|
170
170
|
ErrorMessage
|
|
171
|
-
AppliedParameters`}TransformQueryPayload(e){try{return{QueryID:e.QueryID,QueryName:e.QueryName,Success:e.Success,Results:JSON.parse(e.Results),RowCount:e.RowCount,TotalRowCount:e.TotalRowCount,ExecutionTime:e.ExecutionTime,ErrorMessage:e.ErrorMessage,AppliedParameters:e.AppliedParameters?JSON.parse(e.AppliedParameters):void 0}}catch(t){return u.LogError(`Error transforming query payload: ${t}`),null}}async RunView(e,t){await this.PreProcessRunView(e,t);try{let r="",s="";if(e){const a={};let n,i;if(e.ViewEntity)i=e.ViewEntity,n=i.Entity;else{const{entityName:l,v:c}=await this.getEntityNameAndUserView(e,t);i=c,n=l}const o=this.Entities.find(l=>l.Name===n);if(!o)throw new Error(`Entity ${n} not found in metadata`);let m=!1;e.ViewID?(r=`Run${o.ClassName}ViewByID`,s="RunViewByIDInput",a.ViewID=e.ViewID):e.ViewName?(r=`Run${o.ClassName}ViewByName`,s="RunViewByNameInput",a.ViewName=e.ViewName):(m=!0,r=`Run${o.ClassName}DynamicView`,s="RunDynamicViewInput",a.EntityName=e.EntityName),a.ExtraFilter=e.ExtraFilter?e.ExtraFilter:"",a.OrderBy=e.OrderBy?e.OrderBy:"",a.UserSearchString=e.UserSearchString?e.UserSearchString:"",a.Fields=e.Fields,a.IgnoreMaxRows=e.IgnoreMaxRows?e.IgnoreMaxRows:!1,e.MaxRows!==void 0&&(a.MaxRows=e.MaxRows),e.StartRow!==void 0&&(a.StartRow=e.StartRow),a.ForceAuditLog=e.ForceAuditLog?e.ForceAuditLog:!1,a.ResultType=e.ResultType?e.ResultType:"simple",e.AuditLogDescription&&e.AuditLogDescription.length>0&&(a.AuditLogDescription=e.AuditLogDescription),m||(a.ExcludeUserViewRunID=e.ExcludeUserViewRunID?e.ExcludeUserViewRunID:"",a.ExcludeDataFromAllPriorViewRuns=e.ExcludeDataFromAllPriorViewRuns?e.ExcludeDataFromAllPriorViewRuns:!1,a.OverrideExcludeFilter=e.OverrideExcludeFilter?e.OverrideExcludeFilter:"",a.SaveViewResults=e.SaveViewResults?e.SaveViewResults:!1);const
|
|
171
|
+
AppliedParameters`}TransformQueryPayload(e){try{return{QueryID:e.QueryID,QueryName:e.QueryName,Success:e.Success,Results:JSON.parse(e.Results),RowCount:e.RowCount,TotalRowCount:e.TotalRowCount,ExecutionTime:e.ExecutionTime,ErrorMessage:e.ErrorMessage,AppliedParameters:e.AppliedParameters?JSON.parse(e.AppliedParameters):void 0}}catch(t){return u.LogError(`Error transforming query payload: ${t}`),null}}async RunView(e,t){await this.PreProcessRunView(e,t);try{let r="",s="";if(e){const a={};let n,i;if(e.ViewEntity)i=e.ViewEntity,n=i.Entity;else{const{entityName:l,v:c}=await this.getEntityNameAndUserView(e,t);i=c,n=l}const o=this.Entities.find(l=>l.Name===n);if(!o)throw new Error(`Entity ${n} not found in metadata`);let m=!1;e.ViewID?(r=`Run${o.ClassName}ViewByID`,s="RunViewByIDInput",a.ViewID=e.ViewID):e.ViewName?(r=`Run${o.ClassName}ViewByName`,s="RunViewByNameInput",a.ViewName=e.ViewName):(m=!0,r=`Run${o.ClassName}DynamicView`,s="RunDynamicViewInput",a.EntityName=e.EntityName),a.ExtraFilter=e.ExtraFilter?e.ExtraFilter:"",a.OrderBy=e.OrderBy?e.OrderBy:"",a.UserSearchString=e.UserSearchString?e.UserSearchString:"",a.Fields=e.Fields,a.IgnoreMaxRows=e.IgnoreMaxRows?e.IgnoreMaxRows:!1,e.MaxRows!==void 0&&(a.MaxRows=e.MaxRows),e.StartRow!==void 0&&(a.StartRow=e.StartRow),a.ForceAuditLog=e.ForceAuditLog?e.ForceAuditLog:!1,a.ResultType=e.ResultType?e.ResultType:"simple",e.AuditLogDescription&&e.AuditLogDescription.length>0&&(a.AuditLogDescription=e.AuditLogDescription),m||(a.ExcludeUserViewRunID=e.ExcludeUserViewRunID?e.ExcludeUserViewRunID:"",a.ExcludeDataFromAllPriorViewRuns=e.ExcludeDataFromAllPriorViewRuns?e.ExcludeDataFromAllPriorViewRuns:!1,a.OverrideExcludeFilter=e.OverrideExcludeFilter?e.OverrideExcludeFilter:"",a.SaveViewResults=e.SaveViewResults?e.SaveViewResults:!1);const p=this.getViewRunTimeFieldList(o,i,e,m),g=y.gql`
|
|
172
172
|
query RunViewQuery ($input: ${s}!) {
|
|
173
173
|
${r}(input: $input) {
|
|
174
174
|
Results {
|
|
175
|
-
${
|
|
175
|
+
${p.join(`
|
|
176
176
|
`)}
|
|
177
177
|
}
|
|
178
178
|
UserViewRunID
|
|
@@ -182,7 +182,7 @@
|
|
|
182
182
|
Success
|
|
183
183
|
ErrorMessage
|
|
184
184
|
}
|
|
185
|
-
}`,d=await this.ExecuteGQL(g,{input:a});if(d&&d[r]){const l=d[r].Results;if(l&&l.length>0){const R=o.Fields.filter(
|
|
185
|
+
}`,d=await this.ExecuteGQL(g,{input:a});if(d&&d[r]){const l=d[r].Results;if(l&&l.length>0){const R=o.Fields.filter(S=>S.CodeName!==S.Name&&S.CodeName!==void 0);l.forEach(S=>{this.ConvertBackToMJFields(S),R.forEach(I=>{S[I.Name]=S[I.CodeName]})})}const c=d[r];return await this.PostProcessRunView(c,e,t),c}}else throw"No parameters passed to RunView";return null}catch(r){throw u.LogError(r),r}}async RunViews(e,t){await this.PreProcessRunViews(e,t);try{let r=[],s=[],a=[];for(const o of e){let m="",p="";const g={};let d=null,l=null;if(o.ViewEntity)l=o.ViewEntity,d=l.Get("Entity");else{const{entityName:S,v:I}=await this.getEntityNameAndUserView(o,t);l=I,d=S}const c=this.Entities.find(S=>S.Name===d);if(!c)throw new Error(`Entity ${d} not found in metadata`);s.push(c);let R=!1;o.ViewID?(m=`Run${c.ClassName}ViewByID`,p="RunViewByIDInput",g.ViewID=o.ViewID):o.ViewName?(m=`Run${c.ClassName}ViewByName`,p="RunViewByNameInput",g.ViewName=o.ViewName):(R=!0,m=`Run${c.ClassName}DynamicView`,p="RunDynamicViewInput",g.EntityName=o.EntityName),g.ExtraFilter=o.ExtraFilter||"",g.OrderBy=o.OrderBy||"",g.UserSearchString=o.UserSearchString||"",g.Fields=o.Fields,g.IgnoreMaxRows=o.IgnoreMaxRows||!1,o.MaxRows!==void 0&&(g.MaxRows=o.MaxRows),o.StartRow!==void 0&&(g.StartRow=o.StartRow),g.ForceAuditLog=o.ForceAuditLog||!1,g.ResultType=o.ResultType||"simple",o.AuditLogDescription&&o.AuditLogDescription.length>0&&(g.AuditLogDescription=o.AuditLogDescription),R||(g.ExcludeUserViewRunID=o.ExcludeUserViewRunID||"",g.ExcludeDataFromAllPriorViewRuns=o.ExcludeDataFromAllPriorViewRuns||!1,g.OverrideExcludeFilter=o.OverrideExcludeFilter||"",g.SaveViewResults=o.SaveViewResults||!1),r.push(g),a.push(...this.getViewRunTimeFieldList(c,l,o,R))}const n=y.gql`
|
|
186
186
|
query RunViewsQuery ($input: [RunViewGenericInput!]!) {
|
|
187
187
|
RunViews(input: $input) {
|
|
188
188
|
Results {
|
|
@@ -200,7 +200,7 @@
|
|
|
200
200
|
Success
|
|
201
201
|
ErrorMessage
|
|
202
202
|
}
|
|
203
|
-
}`,i=await this.ExecuteGQL(n,{input:r});if(i&&i.RunViews){const o=i.RunViews;for(const[m,
|
|
203
|
+
}`,i=await this.ExecuteGQL(n,{input:r});if(i&&i.RunViews){const o=i.RunViews;for(const[m,p]of o.entries())p.Results=p.Results.map(g=>{let d=JSON.parse(g.Data);return this.ConvertBackToMJFields(d),d});return await this.PostProcessRunViews(o,e,t),o}return null}catch(r){throw u.LogError(r),r}}async getEntityNameAndUserView(e,t){let r,s;if(e.EntityName)r=e.EntityName;else if(e.ViewID)s=await de.ViewInfo.GetViewEntity(e.ViewID,t),r=s.Entity;else if(e.ViewName)s=await de.ViewInfo.GetViewEntityByName(e.ViewName,t),r=s.Entity;else throw new Error("No EntityName, ViewID or ViewName passed to RunView");return{entityName:r,v:s}}getViewRunTimeFieldList(e,t,r,s){const a=[],n=new w;if(r.Fields){for(const i of e.PrimaryKeys)r.Fields.find(o=>o.trim().toLowerCase()===i.Name.toLowerCase())===void 0&&a.push(i.Name);r.Fields.forEach(i=>{a.push(n.MapFieldName(i))})}else if(s)e.Fields.forEach(i=>{i.IsBinaryFieldType||a.push(n.MapFieldName(i.CodeName))});else{for(const i of e.PrimaryKeys)a.find(o=>o.trim().toLowerCase()===i.Name.toLowerCase())===void 0&&a.push(i.Name);t.Columns.forEach(i=>{i.hidden===!1&&!a.find(o=>o.trim().toLowerCase()===i.EntityField?.Name.trim().toLowerCase())&&i.EntityField&&a.push(n.MapFieldName(i.EntityField.CodeName))})}return a}get ProviderType(){return u.ProviderType.Network}async GetRecordChanges(e,t){try{const r={EntityName:"Record Changes",ExtraFilter:`RecordID = '${t.Values()}' AND Entity = '${e}'`},s=await this.RunView(r);return s?s.Results.sort((a,n)=>a.ChangedAt>n.ChangedAt?-1:1):null}catch(r){throw u.LogError(r),r}}async GetRecordDependencies(e,t){try{const r=y.gql`query GetRecordDependenciesQuery ($entityName: String!, $CompositeKey: CompositeKeyInputType!) {
|
|
204
204
|
GetRecordDependencies(entityName: $entityName, CompositeKey: $CompositeKey) {
|
|
205
205
|
EntityName
|
|
206
206
|
RelatedEntityName
|
|
@@ -251,32 +251,32 @@
|
|
|
251
251
|
Message
|
|
252
252
|
}
|
|
253
253
|
}
|
|
254
|
-
}`,n={EntityName:e.EntityName,SurvivingRecordCompositeKey:{KeyValuePairs:this.ensureKeyValuePairValueIsString(e.SurvivingRecordCompositeKey.KeyValuePairs)},FieldMap:e.FieldMap?.map(o=>({FieldName:o.FieldName,Value:o.Value.toString()})),RecordsToMerge:e.RecordsToMerge.map(o=>o.Copy())};return(await this.ExecuteGQL(a,{request:n}))?.MergeRecords}catch(a){return u.LogError(a),{Success:!1,OverallStatus:a&&a.message?a.message:a,RecordStatus:[],RecordMergeLogID:"",Request:e}}}async Save(e,t,r){const s=new u.BaseEntityResult;try{e.RegisterTransactionPreprocessing();const a={input:{}},n=e.IsSaved?"Update":"Create";s.StartedAt=new Date,s.Type=e.IsSaved?"update":"create",s.OriginalValues=e.Fields.map(d=>({FieldName:d.CodeName,Value:d.Value})),e.ResultHistory.push(s);const i=`${n}${e.EntityInfo.ClassName}`,o=e.Fields.filter(d=>!d.ReadOnly||d.IsPrimaryKey&&e.IsSaved),m=new
|
|
254
|
+
}`,n={EntityName:e.EntityName,SurvivingRecordCompositeKey:{KeyValuePairs:this.ensureKeyValuePairValueIsString(e.SurvivingRecordCompositeKey.KeyValuePairs)},FieldMap:e.FieldMap?.map(o=>({FieldName:o.FieldName,Value:o.Value.toString()})),RecordsToMerge:e.RecordsToMerge.map(o=>o.Copy())};return(await this.ExecuteGQL(a,{request:n}))?.MergeRecords}catch(a){return u.LogError(a),{Success:!1,OverallStatus:a&&a.message?a.message:a,RecordStatus:[],RecordMergeLogID:"",Request:e}}}async Save(e,t,r){const s=new u.BaseEntityResult;try{e.RegisterTransactionPreprocessing();const a={input:{}},n=e.IsSaved?"Update":"Create";s.StartedAt=new Date,s.Type=e.IsSaved?"update":"create",s.OriginalValues=e.Fields.map(d=>({FieldName:d.CodeName,Value:d.Value})),e.ResultHistory.push(s);const i=`${n}${e.EntityInfo.ClassName}`,o=e.Fields.filter(d=>!d.ReadOnly||d.IsPrimaryKey&&e.IsSaved),m=new w,p=` ${i}(input: $input) {
|
|
255
255
|
${e.Fields.map(d=>m.MapFieldName(d.CodeName)).join(`
|
|
256
256
|
`)}
|
|
257
257
|
}`,g=y.gql`mutation ${n}${e.EntityInfo.ClassName} ($input: ${i}Input!) {
|
|
258
|
-
${
|
|
258
|
+
${p}
|
|
259
259
|
}
|
|
260
|
-
`;for(let d=0;d<o.length;d++){const l=o[d];let c=l.Value;if(c)switch(l.EntityFieldInfo.TSType){case u.EntityFieldTSType.Date:c=c.getTime();break;case u.EntityFieldTSType.Boolean:typeof c!="boolean"&&(c=parseInt(c)!==0);break;case u.EntityFieldTSType.Number:if(typeof c!="number"){const R=Number(c);isNaN(R)||(c=R)}break}c===null&&l.EntityFieldInfo.AllowsNull===!1&&(l.EntityFieldInfo.DefaultValue!==null?c=l.EntityFieldInfo.DefaultValue:l.FieldType===u.EntityFieldTSType.Number||l.FieldType===u.EntityFieldTSType.Boolean?c=0:c=""),a.input[l.CodeName]=c}if(n.trim().toLowerCase()==="update"&&r.SkipOldValuesCheck===!1){const d=[];e.Fields.forEach(l=>{let c=null;l.OldValue!==null&&l.OldValue!==void 0&&(l.EntityFieldInfo.TSType===u.EntityFieldTSType.Date?c=l.OldValue.getTime().toString():l.EntityFieldInfo.TSType===u.EntityFieldTSType.Boolean?c=l.OldValue===!0?"1":"0":typeof l.OldValue!="string"?c=l.OldValue.toString():c=l.OldValue),d.push({Key:l.CodeName,Value:c})}),a.input.OldValues___=d}if(e.TransactionGroup){const d=[{varName:"input",inputType:i+"Input!"}];return e.RaiseReadyForTransaction(),e.TransactionGroup.AddTransaction(new u.TransactionItem(e,s.Type==="create"?"Create":"Update",
|
|
260
|
+
`;for(let d=0;d<o.length;d++){const l=o[d];let c=l.Value;if(c)switch(l.EntityFieldInfo.TSType){case u.EntityFieldTSType.Date:c=c.getTime();break;case u.EntityFieldTSType.Boolean:typeof c!="boolean"&&(c=parseInt(c)!==0);break;case u.EntityFieldTSType.Number:if(typeof c!="number"){const R=Number(c);isNaN(R)||(c=R)}break}c===null&&l.EntityFieldInfo.AllowsNull===!1&&(l.EntityFieldInfo.DefaultValue!==null?c=l.EntityFieldInfo.DefaultValue:l.FieldType===u.EntityFieldTSType.Number||l.FieldType===u.EntityFieldTSType.Boolean?c=0:c=""),a.input[l.CodeName]=c}if(n.trim().toLowerCase()==="update"&&r.SkipOldValuesCheck===!1){const d=[];e.Fields.forEach(l=>{let c=null;l.OldValue!==null&&l.OldValue!==void 0&&(l.EntityFieldInfo.TSType===u.EntityFieldTSType.Date?c=l.OldValue.getTime().toString():l.EntityFieldInfo.TSType===u.EntityFieldTSType.Boolean?c=l.OldValue===!0?"1":"0":typeof l.OldValue!="string"?c=l.OldValue.toString():c=l.OldValue),d.push({Key:l.CodeName,Value:c})}),a.input.OldValues___=d}if(e.TransactionGroup){const d=[{varName:"input",inputType:i+"Input!"}];return e.RaiseReadyForTransaction(),e.TransactionGroup.AddTransaction(new u.TransactionItem(e,s.Type==="create"?"Create":"Update",p,a,{mutationName:i,mutationInputTypes:d},(l,c)=>{s.EndedAt=new Date,c&&l?(s.Success=!0,s.NewValues=this.ConvertBackToMJFields(l)):(s.Success=!1,s.Message="Transaction failed")})),!0}else{const d=await this.ExecuteGQL(g,a);if(d&&d[n+e.EntityInfo.ClassName])return s.Success=!0,s.EndedAt=new Date,s.NewValues=this.ConvertBackToMJFields(d[n+e.EntityInfo.ClassName]),s.NewValues;throw new Error(`Save failed for ${e.EntityInfo.ClassName}`)}}catch(a){return s.Success=!1,s.EndedAt=new Date,s.Message=a.response?.errors?.length>0?a.response.errors[0].message:a.message,u.LogError(a),null}}async Load(e,t,r=null,s){try{const a={};let n="",i="";for(let d=0;d<t.KeyValuePairs.length;d++){const l=e.Fields.find(S=>S.Name.trim().toLowerCase()===t.KeyValuePairs[d].FieldName.trim().toLowerCase()).EntityFieldInfo,c=t.GetValueByIndex(d),R=l.GraphQLType;if(i.length>0&&(i+=", "),i+=`$${l.CodeName}: ${R}!`,n.length>0&&(n+=", "),n+=`${l.CodeName}: $${l.CodeName}`,l.TSType===u.EntityFieldTSType.Number){if(isNaN(t.GetValueByIndex(d)))throw new Error(`Primary Key value ${c} (${l.Name}) is not a valid number`);a[l.CodeName]=parseInt(c)}else a[l.CodeName]=c}const o=r&&r.length>0?this.getRelatedEntityString(e.EntityInfo,r):"",m=new w,p=y.gql`query Single${e.EntityInfo.ClassName}${o.length>0?"Full":""} (${i}) {
|
|
261
261
|
${e.EntityInfo.ClassName}(${n}) {
|
|
262
262
|
${e.Fields.filter(d=>!d.EntityFieldInfo.IsBinaryFieldType).map(d=>d.EntityFieldInfo.Name.trim().toLowerCase().startsWith("__mj_")?d.CodeName.replace("__mj_","_mj__"):d.CodeName).join(`
|
|
263
263
|
`)}
|
|
264
264
|
${o}
|
|
265
265
|
}
|
|
266
266
|
}
|
|
267
|
-
`,g=await this.ExecuteGQL(
|
|
267
|
+
`,g=await this.ExecuteGQL(p,a);return g&&g[e.EntityInfo.ClassName]?this.ConvertBackToMJFields(g[e.EntityInfo.ClassName]):null}catch(a){return u.LogError(a),null}}ConvertBackToMJFields(e){return new w().ReverseMapFields(e),e}getRelatedEntityString(e,t){let r="";for(let s=0;s<e.RelatedEntities.length;s++)if(t.indexOf(e.RelatedEntities[s].RelatedEntity)>=0){const a=e.RelatedEntities[s],n=this.Entities.find(o=>o.ID===a.RelatedEntityID);let i="";a.Type.toLowerCase().trim()==="many to many"?i=`${a.RelatedEntityCodeName}_${a.JoinEntityJoinField.replace(/\s/g,"")}`:i=`${a.RelatedEntityCodeName}_${a.RelatedEntityJoinField.replace(/\s/g,"")}`,r+=`
|
|
268
268
|
${i} {
|
|
269
269
|
${n.Fields.map(o=>o.CodeName).join(`
|
|
270
270
|
`)}
|
|
271
271
|
}
|
|
272
272
|
`}return r}async Delete(e,t,r){const s=new u.BaseEntityResult;try{e.RegisterTransactionPreprocessing(),s.StartedAt=new Date,s.Type="delete",s.OriginalValues=e.Fields.map(l=>({FieldName:l.CodeName,Value:l.Value})),e.ResultHistory.push(s);const a={},n=[];let i="",o="",m="";for(let l of e.PrimaryKey.KeyValuePairs){const c=e.Fields.find(R=>R.Name.trim().toLowerCase()===l.FieldName.trim().toLowerCase());a[c.CodeName]=c.Value,n.push({varName:c.CodeName,inputType:c.EntityFieldInfo.GraphQLType+"!"}),i.length>0&&(i+=", "),i+=`${c.CodeName}: $${c.CodeName}`,o.length>0&&(o+=", "),o+=`$${c.CodeName}: ${c.EntityFieldInfo.GraphQLType}!`,m.length>0&&(m+=`
|
|
273
|
-
`),m+=`${c.CodeName}`}n.push({varName:"options___",inputType:"DeleteOptionsInput!"}),a.options___=t||{SkipEntityAIActions:!1,SkipEntityActions:!1};const
|
|
273
|
+
`),m+=`${c.CodeName}`}n.push({varName:"options___",inputType:"DeleteOptionsInput!"}),a.options___=t||{SkipEntityAIActions:!1,SkipEntityActions:!1};const p="Delete"+e.EntityInfo.ClassName,g=y.gql`${p}(${i}, options___: $options___) {
|
|
274
274
|
${m}
|
|
275
275
|
}
|
|
276
|
-
`,d=y.gql`mutation ${
|
|
276
|
+
`,d=y.gql`mutation ${p} (${o}, $options___: DeleteOptionsInput!) {
|
|
277
277
|
${g}
|
|
278
278
|
}
|
|
279
|
-
`;if(e.TransactionGroup)return e.RaiseReadyForTransaction(),e.TransactionGroup.AddTransaction(new u.TransactionItem(e,"Delete",g,a,{mutationName:
|
|
279
|
+
`;if(e.TransactionGroup)return e.RaiseReadyForTransaction(),e.TransactionGroup.AddTransaction(new u.TransactionItem(e,"Delete",g,a,{mutationName:p,mutationInputTypes:n},(l,c)=>{if(s.EndedAt=new Date,c&&l){let R=!0;for(const S of e.PrimaryKey.KeyValuePairs)S.Value!==l[S.FieldName]&&(R=!1);R?s.Success=!0:(s.Success=!1,s.Message="Transaction failed to commit")}else s.Success=!1,s.Message="Transaction failed to commit"})),!0;{const l=await this.ExecuteGQL(d,a);if(l&&l[p]){const c=l[p];for(let R of e.PrimaryKey.KeyValuePairs){let S=c[R.FieldName],I=R.Value;if(typeof I=="number"&&(I=I.toString()),typeof S=="number"&&(S=S.toString()),I!==S)throw new Error(`Primary key value mismatch in server Delete response. Field: ${R.FieldName}, Original: ${I}, Returned: ${S}`)}return s.Success=!0,s.EndedAt=new Date,!0}else throw new Error(`Delete failed for ${e.EntityInfo.Name}: ${e.PrimaryKey.ToString()} `)}}catch(a){return s.EndedAt=new Date,s.Success=!1,s.Message=a.response?.errors?.length>0?a.response.errors[0].message:a.message,u.LogError(a),!1}}async GetDatasetByName(e,t){const r=y.gql`query GetDatasetByName($DatasetName: String!, $ItemFilters: [DatasetItemFilterTypeGQL!]) {
|
|
280
280
|
GetDatasetByName(DatasetName: $DatasetName, ItemFilters: $ItemFilters) {
|
|
281
281
|
DatasetID
|
|
282
282
|
DatasetName
|
|
@@ -334,16 +334,16 @@
|
|
|
334
334
|
ErrorMessage
|
|
335
335
|
Result
|
|
336
336
|
}
|
|
337
|
-
}`,r=await this.ExecuteGQL(t,{DataContextItemID:e});if(r&&r.GetDataContextItemData){if(r.GetDataContextItemData.Success)return JSON.parse(r.GetDataContextItemData.Result);throw new Error(r.GetDataContextItemData.ErrorMessage)}else throw new Error("GraphQL query failed")}catch(t){throw u.LogError(t),t}}static async ExecuteGQL(e,t,r=!0){return
|
|
337
|
+
}`,r=await this.ExecuteGQL(t,{DataContextItemID:e});if(r&&r.GetDataContextItemData){if(r.GetDataContextItemData.Success)return JSON.parse(r.GetDataContextItemData.Result);throw new Error(r.GetDataContextItemData.ErrorMessage)}else throw new Error("GraphQL query failed")}catch(t){throw u.LogError(t),t}}static async ExecuteGQL(e,t,r=!0){return h.Instance.ExecuteGQL(e,t,r)}async ExecuteGQL(e,t,r=!0){try{return await this._client.request(e,t)}catch(s){if(s&&s.response&&s.response.errors?.length>0)if(s.response.errors[0]?.extensions?.code?.toUpperCase().trim()==="JWT_EXPIRED"){if(r)return await this.RefreshToken(),await this.ExecuteGQL(e,t,!1);throw u.LogError("JWT_EXPIRED and refreshTokenIfNeeded is false"),s}else throw s;else throw u.LogError(s),s}}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 h.Instance.RefreshToken()}CreateNewGraphQLClient(e,t,r,s){const a={"x-session-id":r};return t&&(a.authorization="Bearer "+t),s&&(a["x-mj-api-key"]=s),new y.GraphQLClient(e,{headers:a})}userInfoString(){return this.infoString(new u.UserInfo(null,null))}userRoleInfoString(){return this.infoString(new u.UserRoleInfo(null))}infoString(e){let t="";const r=Object.keys(e);for(const s of r)s.startsWith("__mj_")?t+=s.replace("__mj_","_mj__")+`
|
|
338
338
|
`:s.startsWith("_")||(t+=s+`
|
|
339
|
-
`);return t}get LocalStorageProvider(){return this._localStorageProvider||(this._localStorageProvider=new x),this._localStorageProvider}get Metadata(){return this}subscribe(e,t){return this._wsClient||(this._wsClient=
|
|
339
|
+
`);return t}get LocalStorageProvider(){return this._localStorageProvider||(this._localStorageProvider=new x),this._localStorageProvider}get Metadata(){return this}subscribe(e,t){return this._wsClient||(this._wsClient=me.createClient({url:this.ConfigData.WSURL,connectionParams:{Authorization:"Bearer "+this.ConfigData.Token}})),new ye.Observable(r=>{const s=this._wsClient.subscribe({query:e,variables:t},{next:a=>{r.next(a.data)},error:a=>{r.error(a)},complete:()=>{r.complete()}});return()=>{s()}})}PushStatusUpdates(e=null){e||(e=this.sessionId),this._wsClient||(this._wsClient=me.createClient({url:this.ConfigData.WSURL,connectionParams:{Authorization:"Bearer "+this.ConfigData.Token}}));const t=this._pushStatusRequests.find(a=>a.sessionId===e);if(t)return t.observable;const r=y.gql`subscription StatusUpdates($sessionId: String!) {
|
|
340
340
|
statusUpdates(sessionId: $sessionId) {
|
|
341
341
|
date
|
|
342
342
|
message
|
|
343
343
|
sessionId
|
|
344
344
|
}
|
|
345
345
|
}
|
|
346
|
-
`,s=new
|
|
346
|
+
`,s=new ye.Observable(a=>(this._wsClient.subscribe({query:r,variables:{sessionId:e}},{next:n=>a.next(n.data.statusUpdates),error:n=>a.error(n),complete:()=>a.complete()}),()=>{console.log("would unsub here")}));return this._pushStatusRequests.push({sessionId:e,observable:s}),s}};f(h,"GraphQLDataProvider");let v=h;const W=class W{constructor(){this._localStorage={}}async GetItem(e){return new Promise(t=>{this._localStorage.hasOwnProperty(e)?t(this._localStorage[e]):t(null)})}async SetItem(e,t){return new Promise(r=>{this._localStorage[e]=t,r()})}async Remove(e){return new Promise(t=>{this._localStorage.hasOwnProperty(e)&&delete this._localStorage[e],t()})}};f(W,"BrowserStorageProviderBase");let V=W;const Re="MJ_Metadata",E="Metadata_KVPairs",H=class H extends V{constructor(){super(),this.dbPromise=fe.openDB(Re,1,{upgrade(e){e.objectStoreNames.contains(E)||e.createObjectStore(E)}})}async setItem(e,t){const s=(await this.dbPromise).transaction(E,"readwrite");await s.objectStore(E).put(t,e),await s.done}async getItem(e){return await(await this.dbPromise).transaction(E).objectStore(E).get(e)}async remove(e){const r=(await this.dbPromise).transaction(E,"readwrite");await r.objectStore(E).delete(e),await r.done}};f(H,"BrowserIndexedDBStorageProvider");let x=H;async function he(D){const e=new v;return u.SetProvider(e),await e.Config(D),P.MJGlobal.Instance.RaiseEvent({event:P.MJEventType.LoggedIn,eventCode:null,component:this,args:null}),e}f(he,"setupGraphQLClient");const X=class X{};f(X,"SyncRolesAndUsersResult");let T=X;const Z=class Z{};f(Z,"RoleInput");let L=Z;const Y=class Y{};f(Y,"UserInput");let F=Y;const ee=class ee{};f(ee,"RolesAndUsersInput");let U=ee;var ge=(D=>(D.Create="Create",D.Update="Update",D.CreateOrUpdate="CreateOrUpdate",D.Delete="Delete",D.DeleteWithFilter="DeleteWithFilter",D))(ge||{});const te=class te{};f(te,"ActionItemInput");let G=te;const re=class re{constructor(){this.Results=[]}};f(re,"SyncDataResult");let Q=re;const se=class se{};f(se,"ActionItemOutput");let M=se;const ae=class ae{get Client(){return this._client}constructor(e,t,r,s){const a={"x-session-id":r};t&&(a.authorization="Bearer "+t),s&&(a["x-mj-api-key"]=s),this._client=new y.GraphQLClient(e,{headers:a})}async GetData(e,t){try{const s=await this.Client.request(`query GetData($input: GetDataInputType!) {
|
|
347
347
|
GetData(input: $input) {
|
|
348
348
|
Success
|
|
349
349
|
ErrorMessages
|
|
@@ -702,7 +702,7 @@
|
|
|
702
702
|
error
|
|
703
703
|
}
|
|
704
704
|
}
|
|
705
|
-
`,s={textToEmbed:Array.isArray(e.textToEmbed)?e.textToEmbed:[e.textToEmbed],modelSize:e.modelSize},a=await this.Client.request(t,s);if(!a?.EmbedTextSystemUser)return{embeddings:Array.isArray(e.textToEmbed)?[]:[],modelName:"Unknown",vectorDimensions:0,error:"Failed to generate embeddings as system user"};const n=a.EmbedTextSystemUser;return{embeddings:Array.isArray(e.textToEmbed)?n.embeddings:n.embeddings[0],modelName:n.modelName,vectorDimensions:n.vectorDimensions,error:n.error}}catch(t){return u.LogError(`GraphQLSystemUserClient::EmbedText - Error generating embeddings - ${t}`),{embeddings:Array.isArray(e.textToEmbed)?[]:[],modelName:"Unknown",vectorDimensions:0,error:t.toString()}}}};f(
|
|
705
|
+
`,s={textToEmbed:Array.isArray(e.textToEmbed)?e.textToEmbed:[e.textToEmbed],modelSize:e.modelSize},a=await this.Client.request(t,s);if(!a?.EmbedTextSystemUser)return{embeddings:Array.isArray(e.textToEmbed)?[]:[],modelName:"Unknown",vectorDimensions:0,error:"Failed to generate embeddings as system user"};const n=a.EmbedTextSystemUser;return{embeddings:Array.isArray(e.textToEmbed)?n.embeddings:n.embeddings[0],modelName:n.modelName,vectorDimensions:n.vectorDimensions,error:n.error}}catch(t){return u.LogError(`GraphQLSystemUserClient::EmbedText - Error generating embeddings - ${t}`),{embeddings:Array.isArray(e.textToEmbed)?[]:[],modelName:"Unknown",vectorDimensions:0,error:t.toString()}}}};f(ae,"GraphQLSystemUserClient");let b=ae;const ne=class ne{};f(ne,"GetDataOutput");let q=ne;const oe=class oe{};f(oe,"SimpleRemoteEntityOutput");let A=oe;const ie=class ie{};f(ie,"SimpleRemoteEntity");let O=ie;const ue=class ue{};f(ue,"SimpleRemoteEntityField");let _=ue;const le=class le{constructor(e){this._dataProvider=e}async RunAction(e,t,r=!1){try{const s=this.serializeActionParameters(t),a=this.createActionVariables(e,s,r),n=await this.executeActionMutation(a);return this.processActionResult(n,t)}catch(s){return this.handleActionError(s,t)}}serializeActionParameters(e){if(e)return e.map(t=>{let r=t.Value;return r!=null&&typeof r=="object"&&(r=JSON.stringify(r)),{...t,Value:r}})}createActionVariables(e,t,r=!1){return{input:{ActionID:e,Params:t,SkipActionLog:r}}}async executeActionMutation(e){const t=y.gql`
|
|
706
706
|
mutation RunAction($input: RunActionInput!) {
|
|
707
707
|
RunAction(input: $input) {
|
|
708
708
|
Success
|
|
@@ -719,5 +719,81 @@
|
|
|
719
719
|
ResultData
|
|
720
720
|
}
|
|
721
721
|
}
|
|
722
|
-
`;return await this._dataProvider.ExecuteGQL(t,{input:e})}processEntityActionResult(e){if(!e?.RunEntityAction)throw new Error("Invalid response from server");let t={};try{e.RunEntityAction.ResultData&&(t=JSON.parse(e.RunEntityAction.ResultData))}catch(r){u.LogError(`Failed to parse entity action result data: ${r}`)}return{Success:e.RunEntityAction.Success,Message:e.RunEntityAction.Message,RunParams:null,LogEntry:null,...t}}handleEntityActionError(e){const t=e;return u.LogError(`Error running entity action: ${t}`),{Success:!1,Message:`Error: ${t.message}`,RunParams:null,LogEntry:null}}};f(
|
|
722
|
+
`;return await this._dataProvider.ExecuteGQL(t,{input:e})}processEntityActionResult(e){if(!e?.RunEntityAction)throw new Error("Invalid response from server");let t={};try{e.RunEntityAction.ResultData&&(t=JSON.parse(e.RunEntityAction.ResultData))}catch(r){u.LogError(`Failed to parse entity action result data: ${r}`)}return{Success:e.RunEntityAction.Success,Message:e.RunEntityAction.Message,RunParams:null,LogEntry:null,...t}}handleEntityActionError(e){const t=e;return u.LogError(`Error running entity action: ${t}`),{Success:!1,Message:`Error: ${t.message}`,RunParams:null,LogEntry:null}}};f(le,"GraphQLActionClient");let B=le;const ce=class ce{constructor(e){this._dataProvider=e}async GetRegistryComponent(e){try{const t=y.gql`
|
|
723
|
+
query GetRegistryComponent(
|
|
724
|
+
$registryName: String!,
|
|
725
|
+
$namespace: String!,
|
|
726
|
+
$name: String!,
|
|
727
|
+
$version: String,
|
|
728
|
+
$hash: String
|
|
729
|
+
) {
|
|
730
|
+
GetRegistryComponent(
|
|
731
|
+
registryName: $registryName,
|
|
732
|
+
namespace: $namespace,
|
|
733
|
+
name: $name,
|
|
734
|
+
version: $version,
|
|
735
|
+
hash: $hash
|
|
736
|
+
) {
|
|
737
|
+
hash
|
|
738
|
+
notModified
|
|
739
|
+
message
|
|
740
|
+
specification
|
|
741
|
+
}
|
|
742
|
+
}
|
|
743
|
+
`,r={registryName:e.registryName,namespace:e.namespace,name:e.name};e.version!==void 0&&(r.version=e.version),e.hash!==void 0&&(r.hash=e.hash);const s=await this._dataProvider.ExecuteGQL(t,r);if(s&&s.GetRegistryComponent){const a=s.GetRegistryComponent;if(a.notModified&&!a.specification)return null;if(a.specification){if(typeof a.specification=="object")return a.specification;try{return JSON.parse(a.specification)}catch(n){return u.LogError(`Failed to parse component specification: ${n}`),null}}return null}return null}catch(t){throw u.LogError(t),new Error(`Failed to get registry component: ${t instanceof Error?t.message:"Unknown error"}`)}}async GetRegistryComponentWithHash(e){try{const t=y.gql`
|
|
744
|
+
query GetRegistryComponent(
|
|
745
|
+
$registryName: String!,
|
|
746
|
+
$namespace: String!,
|
|
747
|
+
$name: String!,
|
|
748
|
+
$version: String,
|
|
749
|
+
$hash: String
|
|
750
|
+
) {
|
|
751
|
+
GetRegistryComponent(
|
|
752
|
+
registryName: $registryName,
|
|
753
|
+
namespace: $namespace,
|
|
754
|
+
name: $name,
|
|
755
|
+
version: $version,
|
|
756
|
+
hash: $hash
|
|
757
|
+
) {
|
|
758
|
+
hash
|
|
759
|
+
notModified
|
|
760
|
+
message
|
|
761
|
+
specification
|
|
762
|
+
}
|
|
763
|
+
}
|
|
764
|
+
`,r={registryName:e.registryName,namespace:e.namespace,name:e.name};e.version!==void 0&&(r.version=e.version),e.hash!==void 0&&(r.hash=e.hash);const s=await this._dataProvider.ExecuteGQL(t,r);if(s&&s.GetRegistryComponent){const a=s.GetRegistryComponent;let n;if(a.specification)try{n=JSON.parse(a.specification)}catch(i){u.LogError(`Failed to parse component specification in GetRegistryComponentWithHash: ${i}`),n=void 0}return{specification:n,hash:a.hash,notModified:a.notModified,message:a.message}}return{specification:void 0,hash:"",notModified:!1,message:"Component not found"}}catch(t){throw u.LogError(t),new Error(`Failed to get registry component with hash: ${t instanceof Error?t.message:"Unknown error"}`)}}async SearchRegistryComponents(e){try{const t=y.gql`
|
|
765
|
+
query SearchRegistryComponents($params: SearchRegistryComponentsInput!) {
|
|
766
|
+
SearchRegistryComponents(params: $params) {
|
|
767
|
+
components
|
|
768
|
+
total
|
|
769
|
+
offset
|
|
770
|
+
limit
|
|
771
|
+
}
|
|
772
|
+
}
|
|
773
|
+
`,r=await this._dataProvider.ExecuteGQL(t,{params:e});if(r&&r.SearchRegistryComponents){const s=r.SearchRegistryComponents;return{components:s.components.map(a=>JSON.parse(a)),total:s.total,offset:s.offset,limit:s.limit}}return{components:[],total:0,offset:0,limit:e.limit||10}}catch(t){throw u.LogError(t),new Error(`Failed to search registry components: ${t instanceof Error?t.message:"Unknown error"}`)}}async ResolveComponentDependencies(e,t){try{const r=y.gql`
|
|
774
|
+
query ResolveComponentDependencies(
|
|
775
|
+
$registryId: String!,
|
|
776
|
+
$componentId: String!
|
|
777
|
+
) {
|
|
778
|
+
ResolveComponentDependencies(
|
|
779
|
+
registryId: $registryId,
|
|
780
|
+
componentId: $componentId
|
|
781
|
+
) {
|
|
782
|
+
componentId
|
|
783
|
+
name
|
|
784
|
+
namespace
|
|
785
|
+
version
|
|
786
|
+
circular
|
|
787
|
+
totalCount
|
|
788
|
+
dependencies {
|
|
789
|
+
componentId
|
|
790
|
+
name
|
|
791
|
+
namespace
|
|
792
|
+
version
|
|
793
|
+
circular
|
|
794
|
+
totalCount
|
|
795
|
+
}
|
|
796
|
+
}
|
|
797
|
+
}
|
|
798
|
+
`,s=await this._dataProvider.ExecuteGQL(r,{registryId:e,componentId:t});return s&&s.ResolveComponentDependencies?s.ResolveComponentDependencies:null}catch(r){throw u.LogError(r),new Error(`Failed to resolve component dependencies: ${r instanceof Error?r.message:"Unknown error"}`)}}async ComponentExists(e){try{return await this.GetRegistryComponent(e)!==null}catch{return!1}}async GetLatestVersion(e,t,r){try{return(await this.GetRegistryComponent({registryName:e,namespace:t,name:r,version:"latest"}))?.version||null}catch(s){return u.LogError(s),null}}};f(ce,"GraphQLComponentRegistryClient");let k=ce;Object.defineProperty(exports,"gql",{enumerable:!0,get:function(){return y.gql}}),exports.ActionItemInput=G,exports.ActionItemOutput=M,exports.FieldMapper=w,exports.GetDataOutput=q,exports.GraphQLAIClient=N,exports.GraphQLActionClient=B,exports.GraphQLComponentRegistryClient=k,exports.GraphQLDataProvider=v,exports.GraphQLProviderConfigData=C,exports.GraphQLSystemUserClient=b,exports.GraphQLTransactionGroup=$,exports.RoleInput=L,exports.RolesAndUsersInput=U,exports.SimpleRemoteEntity=O,exports.SimpleRemoteEntityField=_,exports.SimpleRemoteEntityOutput=A,exports.SyncDataAction=ge,exports.SyncDataResult=Q,exports.SyncRolesAndUsersResult=T,exports.UserInput=F,exports.setupGraphQLClient=he;
|
|
723
799
|
//# sourceMappingURL=index.cjs.map
|