@memberjunction/react-runtime 4.0.0 → 4.1.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.
@@ -339,7 +339,7 @@
339
339
  Message
340
340
  }
341
341
  }
342
- }`,r={EntityName:e.EntityName,SurvivingRecordCompositeKey:{KeyValuePairs:this.ensureKeyValuePairValueIsString(e.SurvivingRecordCompositeKey.KeyValuePairs)},FieldMap:e.FieldMap?.map(e=>({FieldName:e.FieldName,Value:e.Value.toString()})),RecordsToMerge:e.RecordsToMerge.map(e=>e.Copy())};return(await this.ExecuteGQL(t,{request:r}))?.MergeRecords}catch(t){return(0,a.ZI)(t),{Success:!1,OverallStatus:t&&t.message?t.message:t,RecordStatus:[],RecordMergeLogID:"",Request:e}}}async Save(e,t,r){const n=new a.KV;try{e.RegisterTransactionPreprocessing();const t={input:{}},o=e.IsSaved?"Update":"Create";n.StartedAt=new Date,n.Type=e.IsSaved?"update":"create",n.OriginalValues=e.Fields.map(e=>({FieldName:e.CodeName,Value:e.Value})),e.ResultHistory.push(n);const i=(0,a.I)(e.EntityInfo),u=`${o}${i}`,c=e.Fields.filter(t=>!t.ReadOnly||t.IsPrimaryKey&&e.IsSaved),l=new g,d=` ${u}(input: $input) {\n ${e.Fields.map(e=>l.MapFieldName(e.CodeName)).join("\n ")}\n }`,m=s.J1`mutation ${o}${i} ($input: ${u}Input!) {
342
+ }`,r={EntityName:e.EntityName,SurvivingRecordCompositeKey:{KeyValuePairs:this.ensureKeyValuePairValueIsString(e.SurvivingRecordCompositeKey.KeyValuePairs)},FieldMap:e.FieldMap?.map(e=>({FieldName:e.FieldName,Value:e.Value.toString()})),RecordsToMerge:e.RecordsToMerge.map(e=>e.Copy())};return(await this.ExecuteGQL(t,{request:r}))?.MergeRecords}catch(t){return(0,a.ZI)(t),{Success:!1,OverallStatus:t&&t.message?t.message:t,RecordStatus:[],RecordMergeLogID:"",Request:e}}}async Save(e,t,r){if(r?.IsParentEntitySave){const t=new a.KV;return t.StartedAt=new Date,t.EndedAt=new Date,t.Type=e.IsSaved?"update":"create",t.Success=!0,t.NewValues=e.GetAll(),e.ResultHistory.push(t),t.NewValues}const n=new a.KV;try{e.RegisterTransactionPreprocessing();const t={input:{}},o=e.IsSaved?"Update":"Create";n.StartedAt=new Date,n.Type=e.IsSaved?"update":"create",n.OriginalValues=e.Fields.map(e=>({FieldName:e.CodeName,Value:e.Value})),e.ResultHistory.push(n);const i=(0,a.I)(e.EntityInfo),u=`${o}${i}`,c=e.Fields.filter(t=>!t.ReadOnly||t.IsPrimaryKey&&e.IsSaved),l=new g,d=` ${u}(input: $input) {\n ${e.Fields.map(e=>l.MapFieldName(e.CodeName)).join("\n ")}\n }`,m=s.J1`mutation ${o}${i} ($input: ${u}Input!) {
343
343
  ${d}
344
344
  }
345
345
  `;for(let e=0;e<c.length;e++){const r=c[e];let s=r.Value;if(s)switch(r.EntityFieldInfo.TSType){case a.$S.Date:s=s.getTime();break;case a.$S.Boolean:"boolean"!=typeof s&&(s=0!==parseInt(s));break;case a.$S.Number:if("number"!=typeof s){const e=Number(s);isNaN(e)||(s=e)}}null===s&&!1===r.EntityFieldInfo.AllowsNull&&(s=null!==r.EntityFieldInfo.DefaultValue?r.EntityFieldInfo.DefaultValue:r.FieldType===a.$S.Number||r.FieldType===a.$S.Boolean?0:""),t.input[r.CodeName]=s}if("update"===o.trim().toLowerCase()&&!1===r.SkipOldValuesCheck){const r=[];e.Fields.forEach(e=>{let t=null;null!==e.OldValue&&void 0!==e.OldValue&&(t=e.EntityFieldInfo.TSType===a.$S.Date?e.OldValue.getTime().toString():e.EntityFieldInfo.TSType===a.$S.Boolean?!0===e.OldValue?"1":"0":"string"!=typeof e.OldValue?e.OldValue.toString():e.OldValue),r.push({Key:e.CodeName,Value:t})}),t.input.OldValues___=r}if(e.TransactionGroup){const r=[{varName:"input",inputType:u+"Input!"}];return e.RaiseReadyForTransaction(),e.TransactionGroup.AddTransaction(new a.U1(e,"create"===n.Type?"Create":"Update",d,t,{mutationName:u,mutationInputTypes:r},(e,t)=>{n.EndedAt=new Date,t&&e?(n.Success=!0,n.NewValues=this.ConvertBackToMJFields(e)):(n.Success=!1,n.Message="Transaction failed")})),!0}{const r=await this.ExecuteGQL(m,t);if(r&&r[u])return n.Success=!0,n.EndedAt=new Date,n.NewValues=this.ConvertBackToMJFields(r[u]),n.NewValues;throw new Error(`Save failed for ${e.EntityInfo.ClassName}`)}}catch(e){return n.Success=!1,n.EndedAt=new Date,n.Message=e.response?.errors?.length>0?e.response.errors[0].message:e.message,(0,a.ZI)(e),null}}async Load(e,t,r=null,n){try{const n={};let o="",i="";for(let r=0;r<t.KeyValuePairs.length;r++){const s=e.Fields.find(e=>e.Name.trim().toLowerCase()===t.KeyValuePairs[r].FieldName.trim().toLowerCase()).EntityFieldInfo,u=t.GetValueByIndex(r),c=s.GraphQLType;if(i.length>0&&(i+=", "),i+=`$${s.CodeName}: ${c}!`,o.length>0&&(o+=", "),o+=`${s.CodeName}: $${s.CodeName}`,s.TSType===a.$S.Number){if(isNaN(t.GetValueByIndex(r)))throw new Error(`Primary Key value ${u} (${s.Name}) is not a valid number`);n[s.CodeName]=parseInt(u)}else n[s.CodeName]=u}const u=r&&r.length>0?this.getRelatedEntityString(e.EntityInfo,r):"",c=(0,a.I)(e.EntityInfo),l=(new g,s.J1`query Single${c}${u.length>0?"Full":""} (${i}) {
@@ -381,13 +381,13 @@
381
381
  SetRecordFavoriteStatus(params: $params){
382
382
  Success
383
383
  }
384
- }`,u=await this.ExecuteGQL(i,{params:{UserID:e,EntityID:o.ID,CompositeKey:{KeyValuePairs:this.ensureKeyValuePairValueIsString(r.KeyValuePairs)},IsFavorite:a}});if(u&&null!==u.SetRecordFavoriteStatus)return u.SetRecordFavoriteStatus.Success}async GetEntityRecordName(e,t){if(!e||!t||0===t.KeyValuePairs?.length)return null;const r=s.J1`query GetEntityRecordNameQuery ($EntityName: String!, $CompositeKey: CompositeKeyInputType!) {
384
+ }`,u=await this.ExecuteGQL(i,{params:{UserID:e,EntityID:o.ID,CompositeKey:{KeyValuePairs:this.ensureKeyValuePairValueIsString(r.KeyValuePairs)},IsFavorite:a}});if(u&&null!==u.SetRecordFavoriteStatus)return u.SetRecordFavoriteStatus.Success}async InternalGetEntityRecordName(e,t){if(!e||!t||0===t.KeyValuePairs?.length)return null;const r=s.J1`query GetEntityRecordNameQuery ($EntityName: String!, $CompositeKey: CompositeKeyInputType!) {
385
385
  GetEntityRecordName(EntityName: $EntityName, CompositeKey: $CompositeKey) {
386
386
  Success
387
387
  Status
388
388
  RecordName
389
389
  }
390
- }`,a=await this.ExecuteGQL(r,{EntityName:e,CompositeKey:{KeyValuePairs:this.ensureKeyValuePairValueIsString(t.KeyValuePairs)}});return a&&a.GetEntityRecordName&&a.GetEntityRecordName.Success?a.GetEntityRecordName.RecordName:void 0}async GetEntityRecordNames(e){if(!e)return null;const t=s.J1`query GetEntityRecordNamesQuery ($info: [EntityRecordNameInput!]!) {
390
+ }`,a=await this.ExecuteGQL(r,{EntityName:e,CompositeKey:{KeyValuePairs:this.ensureKeyValuePairValueIsString(t.KeyValuePairs)}});return a&&a.GetEntityRecordName&&a.GetEntityRecordName.Success?a.GetEntityRecordName.RecordName:void 0}async InternalGetEntityRecordNames(e){if(!e)return null;const t=s.J1`query GetEntityRecordNamesQuery ($info: [EntityRecordNameInput!]!) {
391
391
  GetEntityRecordNames(info: $info) {
392
392
  Success
393
393
  Status