@elyx-code/project-logic-tree 0.0.6484 → 0.0.6485

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.js CHANGED
@@ -102270,28 +102270,38 @@ function Bgt(d) {
102270
102270
  r.map((y) => $B(y)).flatMap((y) => mr.includes(y == null ? void 0 : y.type) ? y.calledBy : [y])
102271
102271
  );
102272
102272
  if (a.length === 1) {
102273
- if (Ot.includes(a[0].type))
102274
- return a[0].parent.type === f.Loop ? {
102275
- ancestor: a[0],
102273
+ const y = a[0];
102274
+ if (Ot.includes(y.type))
102275
+ return y.parent.type === f.Loop ? {
102276
+ ancestor: y,
102276
102277
  callType: "loop-body"
102277
102278
  } : {
102278
- ancestor: a[0],
102279
+ ancestor: y,
102279
102280
  callType: "entry"
102280
102281
  };
102281
- if (a[0].successCalls.includes(
102282
- u
102283
- ))
102282
+ if (u === y)
102284
102283
  return {
102285
- ancestor: a[0],
102284
+ ancestor: y,
102286
102285
  callType: "success"
102287
102286
  };
102288
- if (a[0].errorCalls.includes(
102287
+ if (y.successCalls.includes(
102289
102288
  u
102290
102289
  ))
102291
102290
  return {
102292
- ancestor: a[0],
102291
+ ancestor: y,
102292
+ callType: "success"
102293
+ };
102294
+ if (y.errorCalls.includes(u))
102295
+ return {
102296
+ ancestor: y,
102293
102297
  callType: "error"
102294
102298
  };
102299
+ throw new Error(
102300
+ `getEarliestSingleCallerAncestorOfValueWriterAndItsValueReaders: Could not be resolved, single caller found, but it is not a valid caller: ${W(
102301
+ y,
102302
+ u.project
102303
+ )}`
102304
+ );
102295
102305
  }
102296
102306
  const o = a.map((y) => {
102297
102307
  if (Ot.includes(y.type))
@@ -393,7 +393,7 @@ All global 'function-declaration' entity ids are:
393
393
  The project currently has no global 'function-declaration' entities that can be called as 'function-call' entities.`;p.push(new ae({id:`${o.id}--${k.InvalidReference}`,code:k.InvalidReference,severity:H.Error,message:`Entity of type "${f.FunctionCall}" with id "${o.id}", has an invalid reference at the 'declaration' property. The 'declaration' property must be a valid reference to an 'function-declaration' entity.
394
394
  References can either be an ID string or an object with exacly four properties: 'id', 'entityId', 'entityType', 'type'.${v}`}))}return{errors:p,modifiedData:o}}validateGeneratedUpdate(r){const a=[];return r.parent&&a.push(new ae({id:`${this.id}--${k.InvalidParentUpdate}`,code:k.InvalidParentUpdate,severity:H.Error,message:`Entity of type '${this.type}' with id '${this.id}' cannot have the 'parent' property updated. The 'parent' on a callable entity, is its scope. It scope is auto-calculated implicitly by the its caller.
395
395
  If an entity is called by another, they must be in the same scope, which means they have the same parent.
396
- You shouldn't have to manually update a 'parent' property. The equivalent result is to change its callers, the value writters of its inputs, or the value readers of its outputs.`})),{errors:a,modifiedData:r}}subscribeDependents(r){return r.forEach(a=>{this.detachedDependents[a.entity.id]||(this.detachedDependents[a.entity.id]=a)}),this}unsubscribeDependents(r){return r.forEach(a=>{this.detachedDependents[a.entity.id]&&delete this.detachedDependents[a.entity.id]}),this}syncDependents(r=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"sync-dependents"))){const a=[],o=[],p=[],e=[];return Object.values(this.detachedDependents).forEach(y=>{const v=y.entity.afterAllChildrenInitialized(r);a.push(...v.updated),o.push(...v.added),p.push(...v.removed),e.push(...v.affected)}),r==null||r.attemptAutoclose("sync-dependents",this.id),{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}onDetachedDependencyRemoved(r,a,o){const p=[],e=[],y=[],v=[];if(a==="declaration"){const{updated:E,added:w,removed:A}=this.remove({ignoreUpstream:!1},o);p.push(...E),e.push(...w),y.push(...A)}if(a==="parent"){const{updated:E,added:w,removed:A}=this.remove({ignoreUpstream:!1},o);p.push(...E),e.push(...w),y.push(...A)}return{updated:R(p),added:R(e),removed:R(y),affected:R(v),self:this}}onDetachedDependencyRestored(r,a,o){const p=[],e=[],y=[],v=[];if(a==="declaration"){const{updated:E,added:w,removed:A}=this.restore({},o);p.push(...E),e.push(...w),y.push(...A)}if(a==="parent"){const{updated:E,added:w,removed:A}=this.restore({},o);p.push(...E),e.push(...w),y.push(...A)}return{updated:R(p),added:R(e),removed:R(y),affected:R(v),self:this}}unsubscribeFromDependencies(){var r;return(r=this.parent)==null||r.unsubscribeDependents([{entity:this,field:"parent"}]),this.declaration.unsubscribeDependents([{entity:this,field:"declaration"}]),this}subscribeToDependencies(){var r;return(r=this.parent)==null||r.subscribeDependents([{entity:this,field:"parent"}]),this.declaration.subscribeDependents([{entity:this,field:"declaration"}]),this}increaseVersion(r){if(r&&!L(r).isValid())throw new Error(`The shared timestamp '${r}' is not a valid ISO 8601 date string.`);return r&&L(r).isSame(L(this.createdAt))?this:(this.previousVersion=this.version,this.version=N.UUID.uuid(),this.createdAt=L(r).toISOString()||L().toISOString(),this)}captureVersion(){var a;const r=((a=this.knownVersions)==null?void 0:a.get(this.version))||new Qt(this,this.project);return r.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,r):new Map([[this.version,r]]),r.inputs=[...this.inputs],r.outputs=[...this.outputs],r.error=this.error,r.successCalls=[...this.successCalls],r.errorCalls=[...this.errorCalls],r.process=this.process,r.declaration=this.declaration,r.calledBySuccess=[...this.calledBySuccess],r.calledByError=[...this.calledByError],r.calledByEntry=[...this.calledByEntry],r.parent=this.parent,this}recursiveCaptureUpstreamVersions(r){const a=[],o=[],p=[],e=[];if(this.parent){this.parent.increaseVersion(r);const y=this.parent.recursiveCaptureUpstreamVersions(r);a.push(this.parent,...y.updated),o.push(...y.added),p.push(...y.removed)}return{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}async restoreVersion(r){var v;const a=[],o=[],p=[],e=[];if(this.version===r)return{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this};if(!this.knownVersions){const E=new Map;for(const[w,A]of this.knownVersions||new Map){if(E.set(w,A),A.activeVersion=!1,A.knownVersions)for(const[$,V]of A.knownVersions)E.set($,V);A.knownVersions=null}}let y=(v=this.knownVersions)==null?void 0:v.get(r);if(!y){const E=await this.APILoadVersion({},r);if(!E)throw new Error(`Version with id '${r}' for entity with id '${this.id}' not found.`);y=new Qt(E,this.project)}return this.metaSync(y.toShallowJSON(),null),this.previousVersion=y.previousVersion,this.version=y.version,this.createdAt=y.createdAt,this.author=y.author,this.deleted=y.deleted,this.inputs=y.inputs,this.outputs=y.outputs,this.error=y.error,this.successCalls=y.successCalls,this.errorCalls=y.errorCalls,this.process=y.process,this.declaration=y.declaration,this.calledBySuccess=y.calledBySuccess,this.calledByError=y.calledByError,this.calledByEntry=y.calledByEntry,this.parent=y.parent,{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}updateWithShallowTransfer(r,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"update-with-shallow-transfer"))){if(this.metaSync(r,a),this.version=r.version,this.createdAt=r.createdAt,this.author=r.author,this.deleted=r.deleted,this.previousVersion=r.previousVersion,this.unsubscribeFromDependencies(),r.parent){const o=J(r.parent),p=this.project.get(o),e=this.parent;if(e&&e.id!==(p==null?void 0:p.id)&&this.removeFromParent(a),p)this.setParent(p,a);else throw a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${o}' that isn't found in the project`)}else throw a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(r.declaration){const o=J(r.declaration),p=this.project.get(o);p&&this.setDeclaration(p)}return r.calledByEntry.forEach(o=>{const p=J(o),e=this.project.get(p);e&&(this.addEntryCaller(e,a),e.addCall(this,a))}),[...this.calledByEntry].forEach(o=>{r.calledByEntry.find(e=>J(e)===o.id)||(this.removeCaller(o,a),o.removeCall(this,a))}),r.calledBySuccess.forEach(o=>{const p=J(o),e=this.project.get(p);e&&(this.addSuccessCaller(e,a),e.addSuccessCall(this,a))}),[...this.calledBySuccess].forEach(o=>{r.calledBySuccess.find(e=>J(e)===o.id)||(this.removeCaller(o,a),o.removeCall(this,a))}),r.calledByError.forEach(o=>{const p=J(o),e=this.project.get(p);e&&(this.addErrorCaller(e,a),e.addErrorCall(this,a))}),[...this.calledBySuccess].forEach(o=>{r.calledBySuccess.find(e=>J(e)===o.id)||(this.removeCaller(o,a),o.removeCall(this,a))}),this.captureVersion(),this.subscribeToDependencies(),a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),this}hydrateAncestors(){const r=[],a=[],o=[],p=[];if(this.initialData.parent){const e=J(this.initialData.parent),y=this.project.get(e);if(y)this.setParent(y,null),r.push(y);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${e}' that isn't found in the project`)}else throw new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(this.initialData.declaration){const e=J(this.initialData.declaration),y=this.project.get(e);y&&(this.setDeclaration(y),r.push(y))}return this.initialData.calledByEntry.forEach(e=>{const y=J(e),v=this.project.get(y);v&&this.addEntryCaller(v,null)}),this.initialData.calledBySuccess.forEach(e=>{const y=J(e),v=this.project.get(y);v&&this.addSuccessCaller(v,null)}),this.initialData.calledByError.forEach(e=>{const y=J(e),v=this.project.get(y);v&&this.addErrorCaller(v,null)}),{updated:R(r),added:R(a),removed:R(o),affected:R(p),self:this}}afterAllChildrenInitialized(r=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"after-all-children-initialized"))){const a=[],o=[],p=[],e=[];this.initialized=!0;const{updated:y,added:v,removed:E}=this.syncInputs(r),{updated:w,added:A,removed:$}=this.syncOutputs(r);return a.push(...y,...w),o.push(...v,...A),p.push(...E,...$),this.captureVersion(),r==null||r.attemptAutoclose("after-all-children-initialized",this.id),{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}addSelfToProject(r=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-self-to-project"))){var y;const a=[this],o=[],p=[],e=[];return this.parent===this.project&&this.project.addFunctionCall(this),(y=this.process)==null||y.writesValues.forEach(v=>{v.setValueWriter(this.process,r),a.push(v)}),this.successCalls.forEach(v=>{v.addSuccessCaller(this,r),a.push(v)}),this.errorCalls.forEach(v=>{v.addErrorCaller(this,r),a.push(v)}),this.calledBySuccess.forEach(v=>{v.addSuccessCall(this,r),a.push(v)}),this.calledByError.forEach(v=>{v.addErrorCall(this,r),a.push(v)}),this.calledByEntry.forEach(v=>{v.addCall(this,r),a.push(v)}),this.subscribe(),this.subscribeToDependencies(),r==null||r.attemptAutoclose("add-self-to-project",this.id),{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}removeInput(r,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-input"))){const o=this.inputs.findIndex(p=>p.id===r.id);return o>-1&&(this.inputs.splice(o,1),a&&(a==null||a.add(this,S.Affected))),a==null||a.attemptAutoclose("remove-input",this.id),this}addInput(r,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-input"))){return this.inputs.includes(r)?(a==null||a.attemptAutoclose("add-input",this.id),this):(this.inputs.push(r),a==null||a.add(this,S.Affected),a==null||a.attemptAutoclose("add-input",this.id),this)}addOutput(r,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-output"))){return this.outputs.includes(r)?(a==null||a.attemptAutoclose("add-output",this.id),this):(this.outputs.push(r),a==null||a.add(this,S.Affected),a==null||a.attemptAutoclose("add-output",this.id),this)}removeOutput(r,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-output"))){const o=this.outputs.findIndex(p=>p.id===r.id);return o>-1&&(this.outputs.splice(o,1),a&&(a==null||a.add(this,S.Affected))),a==null||a.attemptAutoclose("remove-output",this.id),this}addValueReader(r,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-value-reader"))){var o;return this.process&&!this.process.writesValues.includes(r)&&((o=this.process)==null||o.addValueReader(r,a),a==null||a.add(this,S.Affected)),a==null||a.attemptAutoclose("add-value-reader",this.id),this}removeValueReader(r,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-value-reader"))){var o;return this.process&&this.process.writesValues.includes(r)&&((o=this.process)==null||o.removeValueReader(r,a),a==null||a.add(this,S.Affected)),a==null||a.attemptAutoclose("remove-value-reader",this.id),this}addSuccessCaller(r,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-success-caller")),o=!1){return this.calledBySuccess.find(p=>p.id===r.id)||(this.calledBySuccess.push(r),a==null||a.add(this,S.Updated),o&&He(this,a)),a==null||a.attemptAutoclose("add-success-caller",this.id),this}addErrorCaller(r,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-error-caller")),o=!1){return this.calledByError.find(p=>p.id===r.id)||(this.calledByError.push(r),a==null||a.add(this,S.Updated),o&&He(this,a)),a==null||a.attemptAutoclose("add-error-caller",this.id),this}addEntryCaller(r,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-entry-caller")),o=!1){return this.calledByEntry.find(p=>p.id===r.id)||(this.calledByEntry.push(r),a==null||a.add(this,S.Updated),o&&He(this,a)),a==null||a.attemptAutoclose("add-entry-caller",this.id),this}addErrorCall(r,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-error-call")),o=!1){return this.errorCalls.find(p=>p.id===r.id)||(this.errorCalls.push(r),o&&He(this,a),a==null||a.add(this,S.Affected)),a==null||a.attemptAutoclose("add-error-call",this.id),this}addSuccessCall(r,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-success-call")),o=!1){return this.successCalls.find(p=>p.id===r.id)||(this.successCalls.push(r),o&&He(this,a),a==null||a.add(this,S.Affected)),a==null||a.attemptAutoclose("add-success-call",this.id),this}removeCall(r,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-call")),o=!1){const p=this.successCalls.findIndex(y=>y.id===r.id);p>-1&&(this.successCalls.splice(p,1),a==null||a.add(this,S.Affected));const e=this.errorCalls.findIndex(y=>y.id===r.id);return e>-1&&(this.errorCalls.splice(e,1),a==null||a.add(this,S.Affected)),o&&He(this,a),a==null||a.attemptAutoclose("remove-call",this.id),this}removeCaller(r,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-caller")),o=!1){return this.calledBySuccess=this.calledBySuccess.filter(p=>p.id!==r.id?!0:(a==null||a.add(this,S.Updated),a==null||a.add(p,S.Affected),!1)),this.calledByError=this.calledByError.filter(p=>p.id!==r.id?!0:(a==null||a.add(this,S.Updated),a==null||a.add(p,S.Affected),!1)),this.calledByEntry=this.calledByEntry.filter(p=>p.id!==r.id?!0:(a==null||a.add(this,S.Updated),a==null||a.add(p,S.Affected),!1)),o&&He(this,a),a==null||a.attemptAutoclose("remove-caller",this.id),this}setParent(r,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"set-parent"))){var o;return((o=this.parent)==null?void 0:o.id)!==(r==null?void 0:r.id)&&(this.parent=r,a&&(a==null||a.add(this,S.Updated))),a==null||a.attemptAutoclose("set-parent",this.id),this}setDeclaration(r){return this.declaration=r,this}initChildren(r=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"init-children"))){if(this.initialized||this.startedInitialization)return this;if(this.startedInitialization=!0,this.initialData.declaration.type===f.FunctionDeclaration){const a=ne(this.initialData.declaration,this.project);this.declaration=a}else{const a=J(this.initialData.declaration),o=this.project.get(a);this.declaration=o}return this.successCalls=this.initialData.successCalls.map(a=>{const o=ne(a,this.project);if(o.addSuccessCaller(this),[f.BreakStatement,f.ContinueStatement].includes(o.type))o.setParent(this.parent.parent,null),o.initChildren(r);else if(o.type===f.ReturnStatement){const p=Hr(this,this.project);o.setParent(p,null),o.initChildren(r)}else o.type!==f.InternalCall&&(o.setParent(this.parent,null),o.initChildren(r));return o}),this.errorCalls=this.initialData.errorCalls.map(a=>{const o=ne(a,this.project);if(o.addErrorCaller(this),[f.BreakStatement,f.ContinueStatement].includes(o.type))o.setParent(this.parent.parent,null),o.initChildren(r);else if(o.type===f.ReturnStatement){const p=Hr(this,this.project);o.setParent(p,null),o.initChildren(r)}else o.type!==f.InternalCall&&(o.setParent(this.parent,null),o.initChildren(r));return o}),this.inputs=this.initialData.inputs.map(a=>{const o=ne(a,this.project);return o.setParent(this,null),o.initChildren(r),o}),this.initialData.process&&(this.process=ne(this.initialData.process,this.project),this.process.setParent(this,null),this.process.initChildren(r)),this.initialData.error&&(this.error=ne(this.initialData.error,this.project),this.error.setParent(this,null),this.error.initChildren(r)),this.subscribeToDependencies(),this.afterAllChildrenInitialized(r),r==null||r.attemptAutoclose("init-children",this.id),this}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(r,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"meta-sync"))){const o=Lr(this,r),p=this.toMeta();return this.x=r.x||p.x,this.y=r.y||p.y,this.catchesError=r.catchesError!==void 0?r.catchesError:this.catchesError,super.metaSync(r),r.deleted===!0&&!p.deleted?a==null||a.add(this,S.Removed):r.deleted===!1&&p.deleted?a==null||a.add(this,S.Added):o&&(a==null||a.add(this,S.Updated)),a==null||a.attemptAutoclose("meta-sync",this.id),this}async APILoad(r=ve,...a){return await Qt.repository.APILoad(this.id,...a),this}async APICreate(r=ve,...a){return await Qt.repository.APICreate(this.toShallowJSON(),...a),this}async APIUpdate(r=ve,...a){return await Qt.repository.APIUpdate(this.toShallowJSON(),...a),this}async APIDelete(r=ve,...a){return await Qt.repository.APIDelete(this.toShallowJSON(),...a),this}async APIClone(r=ve,...a){return await Qt.repository.APIClone(this.id,...a),this}async APILoadVersion(r=ve,a,...o){return await Qt.repository.APILoadVersion(this.id,a,...o)}removeFromParent(r=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-from-parent"))){const a=[],o=[],p=[],e=[];return this.parent.type===f.Project?(this.parent.removeFunctionCall(this),e.push(this.parent)):this.parent.detachedChildren.includes(this)&&this.parent.unsubscribeDetachedChild(this),r==null||r.attemptAutoclose("remove-from-parent",this.id),{added:R(p),updated:R(a),removed:R(o),affected:R(e),self:this}}remove({ignoreUpstream:r}={ignoreUpstream:!1},a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-entity"))){var v;const o=[],p=[],e=[],y=[];if(a!=null&&a.hasRemoved(this.id))return a==null||a.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(p.push(this),this.unsubscribe(),this.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},a),Object.values(this.detachedDependents).forEach(E=>{const{updated:w,removed:A,added:$}=E.entity.onDetachedDependencyRemoved(this,E.field,a);o.push(...w),p.push(...A),e.push(...$)}),this.process){const{updated:E,removed:w}=(v=this.process)==null?void 0:v.remove({ignoreUpstream:!0},a);o.push(...E),p.push(...w)}if(this.inputs.forEach(E=>{const{updated:w,removed:A}=E.remove({ignoreUpstream:!0},a);o.push(...w),p.push(...A)}),this.outputs.forEach(E=>{const{updated:w,removed:A}=E.remove({ignoreUpstream:!0},a);o.push(...w),p.push(...A)}),this.error){const{updated:E,removed:w}=this.error.remove({ignoreUpstream:!0},a);o.push(...E),p.push(...w)}if(this.successCalls.forEach(E=>{o.push(E),E.removeCaller(this,a)}),this.errorCalls.forEach(E=>{o.push(E),E.removeCaller(this,a)}),!r){const E=this.removeFromParent(a);e.push(...E.added),o.push(...E.updated),p.push(...E.removed),y.push(...E.affected),this.calledBy.forEach(w=>{o.push(w),w.removeCall(this,a)})}return a==null||a.attemptAutoclose("remove-entity",this.id),{added:R(e),updated:R(o),removed:R(p),affected:R(y),self:this}}restore({}={},r=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"restore-entity"))){const a=[],o=[],p=[],e=[];if(r!=null&&r.hasAdded(this.id))return r==null||r.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},r),Object.values(this.detachedDependents).forEach(y=>{const{updated:v,removed:E,added:w}=y.entity.onDetachedDependencyRestored(this,y.field,r);o.push(...v),p.push(...E),a.push(...w)}),this.process){const{updated:y}=this.process.restore({},r);o.push(...y)}return this.inputs.forEach(y=>{const{updated:v}=y.restore({},r);o.push(...v)}),this.outputs.forEach(y=>{const{updated:v}=y.restore({},r);o.push(...v)}),this.successCalls.forEach(y=>{o.push(y),y.addSuccessCaller(this,r)}),this.errorCalls.forEach(y=>{o.push(y),y.addErrorCaller(this,r)}),this.calledBySuccess.forEach(y=>{o.push(y),y.addSuccessCall(this,r)}),this.calledByError.forEach(y=>{o.push(y),y.addErrorCall(this,r)}),this.calledByEntry.forEach(y=>{o.push(y),y.addCall(this,r)}),r==null||r.attemptAutoclose("restore-entity",this.id),{added:R(a),updated:R(o),removed:R(p),affected:R(e),self:this}}toFlat(r=new Set){return r.has(this.id)?[]:(r.add(this.id),[this,...this.successCalls.flatMap(o=>o.toFlat(r)),...this.errorCalls.flatMap(o=>o.toFlat(r)),...this.inputs.flatMap(o=>o.toFlat(r)),...this.outputs.flatMap(o=>o.toFlat(r)),...this.process?this.process.toFlat(r):[],...this.error?this.error.toFlat(r):[],...this.calledBy.flatMap(o=>o.toFlat(r))])}toFlatIds(r=new Set){return r.has(this.id)?[]:(r.add(this.id),[this.id,...this.successCalls.flatMap(o=>o.toFlatIds(r)),...this.errorCalls.flatMap(o=>o.toFlatIds(r)),...this.inputs.flatMap(o=>o.toFlatIds(r)),...this.outputs.flatMap(o=>o.toFlatIds(r))])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,x:this.x,y:this.y,type:this.type,catchesError:this.catchesError}}toJSON(r=new Set){var a,o;return r.has(this.id)?this.toReference():(r.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,catchesError:this.catchesError,x:this.x,y:this.y,successCalls:this.successCalls.map(p=>p.toJSON(r)),errorCalls:this.errorCalls.map(p=>p.toJSON(r)),calledBySuccess:this.calledBySuccess.map(p=>p.toReference()),calledByError:this.calledByError.map(p=>p.toReference()),calledByEntry:this.calledByEntry.map(p=>p.toReference()),process:(a=this.process)==null?void 0:a.toJSON(r),declaration:this.declaration.toJSON(r),inputs:this.inputs.map(p=>p.toJSON(r)),outputs:this.outputs.map(p=>p.toJSON(r)),parent:this.parent.toReference(),error:(o=this.error)==null?void 0:o.toJSON(r)})}toJSONClone(r=Se){var o,p,e,y,v,E,w;let a;return(o=r.seenEntityMaps)!=null&&o.has(this.id)?a=r.seenEntityMaps.get(this.id):(a=r.newId||jr(this,this.project,r.uuidStrategy),r.seenEntityMaps&&r.seenEntityMaps.set(this.id,a)),(p=r.seenEntities)!=null&&p.has(a)||(e=r.seenEntities)!=null&&e.has(this.id)?this.toReference({seenEntityMaps:r.seenEntityMaps}):((y=r.seenEntities)==null||y.add(a),(v=r.seenEntities)==null||v.add(this.id),{id:a,version:N.UUID.uuid(),createdAt:r.timestamp||L().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,catchesError:this.catchesError,type:this.type,x:this.x,y:this.y,successCalls:this.successCalls.map(A=>A.toJSONClone({...r,newId:null})),errorCalls:this.errorCalls.map(A=>A.toJSONClone({...r,newId:null})),calledBySuccess:this.calledBySuccess.map(A=>A.toReference({seenEntityMaps:r.seenEntityMaps})),calledByError:this.calledByError.map(A=>A.toReference({seenEntityMaps:r.seenEntityMaps})),calledByEntry:this.calledByEntry.map(A=>A.toReference({seenEntityMaps:r.seenEntityMaps})),process:(E=this.process)==null?void 0:E.toJSONClone({...r,newId:null}),declaration:this.declaration.toJSONClone({...r,newId:null}),inputs:this.inputs.map(A=>A.toJSONClone({...r,newId:null})),outputs:this.outputs.map(A=>A.toJSONClone({...r,newId:null})),error:(w=this.error)==null?void 0:w.toJSONClone({...r,newId:null}),parent:this.parent.toReference({seenEntityMaps:r.seenEntityMaps})})}toReference(r=Se){var o;let a=this.id;return(o=r.seenEntityMaps)!=null&&o.has(this.id)&&(a=r.seenEntityMaps.get(this.id)),{id:a+"--"+N.UUID.uuid()+"--ref",type:f.GenericReference,entityId:a,version:this.version,entityType:this.type}}toShallowJSON(r=Se){var o;let a=this.id;return(o=r.seenEntityMaps)!=null&&o.has(this.id)&&(a=r.seenEntityMaps.get(this.id)),{id:a,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,catchesError:this.catchesError,x:this.x,y:this.y,process:this.process?this.process.toReference(r):null,inputs:this.inputs.map(p=>p.toReference(r)),outputs:this.outputs.map(p=>p.toReference(r)),declaration:this.declaration.toReference(r),successCalls:this.successCalls.map(p=>p.toReference(r)),errorCalls:this.errorCalls.map(p=>p.toReference(r)),calledBySuccess:this.calledBySuccess.map(p=>p.toReference(r)),calledByError:this.calledByError.map(p=>p.toReference(r)),calledByEntry:this.calledByEntry.map(p=>p.toReference(r)),error:this.error?this.error.toReference(r):null,parent:this.parent.toReference(r)}}toFlatJSON(r=new Set){return r.has(this.id)?[]:(r.add(this.id),[this.toShallowJSON(),...this.successCalls.flatMap(o=>o.toFlatJSON(r)),...this.errorCalls.flatMap(o=>o.toFlatJSON(r)),...this.inputs.flatMap(o=>o.toFlatJSON(r)),...this.outputs.flatMap(o=>o.toFlatJSON(r)),...this.process?this.process.toFlatJSON(r):[],...this.error?this.error.toFlatJSON(r):[]])}toGenerationTarget(){const r=this.parent.type===f.Project?void 0:this.parent.id;return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,calledByEntry:this.calledByEntry.map(a=>a.id),calledBySuccess:this.calledBySuccess.map(a=>a.id),calledByError:this.calledByError.map(a=>a.id),declaration:this.declaration.id,parent:r}}toFlatGenerationTarget(r=new Set){return r.has(this.id)?[]:(r.add(this.id),[this.toGenerationTarget(),...this.successCalls.flatMap(o=>o.toFlatGenerationTarget(r)),...this.errorCalls.flatMap(o=>o.toFlatGenerationTarget(r)),...this.inputs.flatMap(o=>o.toFlatGenerationTarget(r)),...this.outputs.flatMap(o=>o.toFlatGenerationTarget(r)),...this.process?this.process.toFlatGenerationTarget(r):[],...this.error?this.error.toFlatGenerationTarget(r):[]])}clearErrors(){var r,a;return this.errors=[],this.inputs.forEach(o=>o.clearErrors()),this.outputs.forEach(o=>o.clearErrors()),this.successCalls.forEach(o=>o.clearErrors()),this.errorCalls.forEach(o=>o.clearErrors()),(r=this.process)==null||r.clearErrors(),(a=this.error)==null||a.clearErrors(),this}validate(){const r=T5(this);return this.errors=r,{success:!0}}getErrors(){return[...this.errors,...this.inputs.flatMap(a=>a.getErrors()),...this.outputs.flatMap(a=>a.getErrors()),...this.error?this.error.getErrors():[],...this.process?this.process.getErrors():[]]}getShallowErrors(){return this.errors}clone(r=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"clone-entity")),a=null,o=null,p=!0){var B,F;let e=Ur(a,this);const y=this.toJSON(),v=o||N.UUID.uuid();y.inputs=[];const E=v.split("-id"),w=E[E.length-1||0]||v;y.id=v,y.version=N.UUID.uuid(),y.createdAt=(r==null?void 0:r.timestamp)||L().toISOString(),y.author=(r==null?void 0:r.author)||"1",y.previousVersion=null,y.deleted=!1;const A=dr(y,e);a?A.setParent(a,null):A.setParent(this.parent,null),p&&A.subscribe(),A.initChildren(r),r==null||r.add(A,S.Added);const $=(B=this.inputs)==null?void 0:B.map((K,q)=>K.clone(r,A,w+"-input-map-"+q+"-id",p));A.inputs=$;const V=(F=this.outputs)==null?void 0:F.map((K,q)=>K.clone(r,A,w+"-output-map-"+q+"-id",p));return A.outputs=V,this.error&&(A.error=this.error.clone(r,A,w+"-error-map-id",p)),this.process&&(A.process=this.process.clone(r,A,w+"-process-id",p)),r==null||r.attemptAutoclose("clone-entity",this.id),A}removeUnrecognizedInputs(r=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-unrecognized-inputs"))){const a=[],o=[],p=[],e=[];return this.inputs.forEach(v=>{if(!this.declaration.inputs.find(w=>{var A;return w.id===((A=v.declaration)==null?void 0:A.id)})){const w=v.remove({ignoreUpstream:!1},r);p.push(...w.removed),a.push(...w.updated)}}),this.inputs.filter((v,E)=>{const w=this.inputs.findIndex($=>$.declaration===v.declaration&&$!==v);if(w===-1)return!1;const A=this.inputs[w];return L(A==null?void 0:A.createdAt).isSame(L(v.createdAt))?E>w:!!L(A==null?void 0:A.createdAt).isAfter(v.createdAt)}).forEach(v=>{const E=v.remove({ignoreUpstream:!1},r);p.push(...E.removed),a.push(...E.updated)}),r==null||r.attemptAutoclose("remove-unrecognized-inputs",this.id),{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}removeUnrecognizedOutputs(r=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-unrecognized-outputs"))){const a=[],o=[],p=[],e=[];return this.outputs.forEach(v=>{if(!this.declaration.getUniqueReturnDeclarations().find(w=>{var A;return w.id===((A=v.declaration)==null?void 0:A.id)})){const w=v.remove({ignoreUpstream:!1},r);p.push(...w.removed),a.push(...w.updated)}}),this.outputs.filter((v,E)=>{const w=this.outputs.findIndex($=>$.declaration===v.declaration&&$!==v);if(w===-1)return!1;const A=this.outputs[w];return L(A==null?void 0:A.createdAt).isSame(L(v.createdAt))?E>w:!!L(A==null?void 0:A.createdAt).isAfter(v.createdAt)}).forEach(v=>{const E=v.remove({ignoreUpstream:!1},r);p.push(...E.removed),a.push(...E.updated)}),r==null||r.attemptAutoclose("remove-unrecognized-outputs",this.id),{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}syncInputs(r=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"sync-missing-fixed-inputs"))){const a=[],o=[],p=[],e=[],y=this.declaration.inputs.filter(A=>!this.inputs.find($=>$.declaration.id===A.id));this.inputs.sort((A,$)=>A.index-$.index),y.forEach(A=>{this.inputs.forEach(B=>{B.index>=A.index&&B.metaSync({index:B.index+1},r)});const $={id:N.UUID.uuid(),version:N.UUID.uuid(),createdAt:(r==null?void 0:r.timestamp)||L().toISOString(),author:N.sessionAuthor,previousVersion:null,deleted:!1,type:f.InputMap,declaration:A.toJSON(),readsValue:null,defaultValue:null,index:A.index,name:null,codeName:null,description:null,parent:this.toReference()},V=ne($,this.project);V.setParent(this,r),V.initChildren(r),r==null||r.add(V,S.Added),V.addSelfToProject(r),o.push(V)}),this.inputs.sort((A,$)=>A.index-$.index);const{updated:v,added:E,removed:w}=this.removeUnrecognizedInputs(r);return a.push(...v),o.push(...E),p.push(...w),r==null||r.attemptAutoclose("sync-missing-fixed-inputs",this.id),{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}syncOutputs(r=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"sync-missing-fixed-outputs"))){const a=[],o=[],p=[],e=[],y=[];this.outputs=this.initialData.outputs.reduce(($,V)=>{if(V.type===f.GenericReference){const F=qi(V,this.project);return F?[...$,F]:$}const B=ne(V,this.project);return y.push(B.index),B.setParent(this,null),B.initChildren(r),[...$,B]},[]);const v=this.declaration.getUniqueReturnDeclarations().filter($=>!this.outputs.find(V=>{var B;return((B=V.declaration)==null?void 0:B.id)===$.id}));this.outputs.sort(($,V)=>$.index-V.index),v.forEach(($,V)=>{this.outputs.forEach(q=>{q.index>=$.index&&q.index++});const B=y.includes($.index)?this.outputs.length-1+V:$.index,F={id:N.UUID.uuid(),version:N.UUID.uuid(),createdAt:(r==null?void 0:r.timestamp)||L().toISOString(),author:N.sessionAuthor,previousVersion:null,deleted:!1,type:f.OutputMap,declaration:$.toJSON(),defaultValue:null,writesValues:[],index:B,parent:this.toReference()},K=ne(F,this.project);K.setParent(this,r),K.initChildren(r),r==null||r.add(K,S.Added),K.addSelfToProject(r)}),this.outputs.sort(($,V)=>$.index-V.index);const{updated:E,added:w,removed:A}=this.removeUnrecognizedOutputs(r);return a.push(...E),o.push(...w),p.push(...A),r==null||r.attemptAutoclose("sync-missing-fixed-outputs",this.id),{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}getUnusedInputs(){return this.inputs.filter(r=>r.suggestion||!r.readsValue&&!r.defaultValue)}getUnusedOutputs(){return this.outputs.filter(r=>r.suggestion||!r.writesValues.length)}getUsedInputs(){return this.inputs.filter(r=>!r.suggestion&&(r.readsValue||r.defaultValue))}getUsedOutputs(){return this.outputs.filter(r=>!r.suggestion&&r.writesValues.length)}};_(Qt,"repository",{APICreate:async(r,...a)=>r,APIUpdate:async(r,...a)=>r,APIDelete:async(r,...a)=>r,APIClone:async(r,...a)=>{},APILoad:async(r,...a)=>null,APILoadVersion:async(r,a,...o)=>null}),_(Qt,"type",f.FunctionCall),_(Qt,"USER_MANAGED_PARENT_TYPES",[...Nr,f.Project]),_(Qt,"PARENT_TYPES",[...Qt.USER_MANAGED_PARENT_TYPES]),_(Qt,"MUTABLE_BASE_PROPERTIES",["catchesError"]),_(Qt,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),_(Qt,"BASE_PROPERTIES",[...Qt.MUTABLE_BASE_PROPERTIES,...Qt.INMUTABLE_BASE_PROPERTIES]),_(Qt,"MUTABLE_META_PROPERTIES",["x","y"]),_(Qt,"INMUTABLE_META_PROPERTIES",[...Qt.INMUTABLE_BASE_PROPERTIES]),_(Qt,"META_PROPERTIES",[...Qt.MUTABLE_META_PROPERTIES,...Qt.INMUTABLE_META_PROPERTIES]),_(Qt,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry"]),_(Qt,"INMUTABLE_UPSTREAM_PROPERTIES",["declaration","parent"]),_(Qt,"UPSTREAM_PROPERTIES",[...Qt.MUTABLE_UPSTREAM_PROPERTIES,...Qt.INMUTABLE_UPSTREAM_PROPERTIES]),_(Qt,"MUTABLE_DOWNSTREAM_PROPERTIES",["successCalls","errorCalls","writesValues","inputs","outputs","error"]),_(Qt,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),_(Qt,"DOWNSTREAM_PROPERTIES",[...Qt.MUTABLE_DOWNSTREAM_PROPERTIES,...Qt.INMUTABLE_DOWNSTREAM_PROPERTIES]),_(Qt,"PROPERTIES",[...Qt.META_PROPERTIES,...Qt.UPSTREAM_PROPERTIES,...Qt.DOWNSTREAM_PROPERTIES]);let To=Qt;function nb(d){return d&&typeof d.then=="function"}function tIe(d){const u=new zn(d[0]),r=d.map(o=>o.id),a={};return d.forEach(o=>{a[o.id]=o}),u.order=r,u.flatRecord=a,u.orderEntities(),u.order.map(o=>u.flatRecord[o])}function rIe(d){const u=new zn(Object.values(d)[0]),r=Object.keys(d);return u.order=r,u.flatRecord=d,u.orderEntities(),u.order}class zn{constructor(u){_(this,"order",[]);_(this,"flatRecord",{});_(this,"allBuiltInEntityIds",zs());_(this,"onGoingVisits",{});u&&(this.flatten(u),this.orderEntities())}flatten(u){const r=new Set(zs()),a=R(me(u,r,{ignoreBuiltInBaseEntities:!0})),o=new Set;for(const p of a)this.flatRecord[p.id]=p,o.add(p.id);this.order=Array.from(o)}moveEntityAfterDependencies(u){const{upstream:r}=kd(u,this.flatRecord,{ignoreBuiltInBaseEntities:!0,allBuiltInEntityIds:this.allBuiltInEntityIds});for(const a of Object.keys(r)){const o=this.order.indexOf(a),p=this.order.indexOf(u.id);if(o>p)return this.order.splice(p,1),this.order.splice(o,0,u.id),!0}return!1}orderEntities(){let u=!1;for(let r=0;r<this.order.length;r++){const a=this.order[r],o=this.flatRecord[a];if(o||Me.warn(`Entity with id ${a} not found in flatRecord. Skipping...`),this.moveEntityAfterDependencies(o)){u=!0;break}}u&&this.orderEntities()}getUpstreamOngoingDependenciesVisits(u,r){const{upstream:a}=kd(this.flatRecord[u],this.flatRecord,{ignoreBuiltInBaseEntities:!0,allBuiltInEntityIds:this.allBuiltInEntityIds}),o={};return Object.entries(this.onGoingVisits[r]||{}).forEach(([p,e])=>{Object.keys(a).includes(p)&&(o[p]=e)}),o}getDownstreamOngoingDependenciesVisits(u,r){const a=Object.keys(this.onGoingVisits[r]||{}),o=new Set(a.flatMap(e=>Object.keys(kd(this.flatRecord[e],this.flatRecord,{ignoreBuiltInBaseEntities:!0,allBuiltInEntityIds:this.allBuiltInEntityIds}).downstream))),p={};return Array.from(o).forEach(e=>{e===u&&(p[e]=this.onGoingVisits[r][e])}),p}async settlePromises(u,r){const a=Object.values(u);a.length&&await Promise.all(a),Object.keys(u).forEach(o=>{delete this.onGoingVisits[r][o]})}visit(u){const r=this.order;for(const a of r)u(this.flatRecord[a],this.flatRecord);return this}reverseVisit(u){const r=this.order.slice().reverse();for(const a of r)u(this.flatRecord[a],this.flatRecord);return this}async visitAsync(u){const r=this.order,a=Math.random().toString(36).substring(7);this.onGoingVisits[a]={};for(const o of r){const p=this.getUpstreamOngoingDependenciesVisits(o,a);Object.keys(p).length&&await this.settlePromises(p,a);const e=u(this.flatRecord[o],this.flatRecord);nb(e)&&(this.onGoingVisits[a][o]=e)}return await this.settlePromises(this.onGoingVisits[a],a),this.onGoingVisits[a]={},this}async reverseVisitAsync(u){const r=this.order.slice().reverse(),a=Math.random().toString(36).substring(7);this.onGoingVisits[a]={};for(const o of r){const p=this.getDownstreamOngoingDependenciesVisits(o,a);Object.keys(p).length&&await this.settlePromises(p,a);const e=u(this.flatRecord[o],this.flatRecord);nb(e)&&(this.onGoingVisits[a][o]=e)}return await this.settlePromises(this.onGoingVisits[a],a),this.onGoingVisits[a]={},this}}function A5(d,u){switch(d.id){case he["built-in-base-entity"].BUILT_IN_PERSISTED_ENTITY_ENTITY.id:{const r=d.project.entities.filter(v=>!!v.implements.find(E=>E.id===he["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.id)),a=r.find(v=>{const E=v.properties.find($=>$.implements&&$.implements.id===he["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.default.id),w=E==null?void 0:E.getDefaultValue();return(w==null?void 0:w.value)===!0});if(!a&&r.length){const E=r[0].properties.find(A=>A.implements&&A.implements.id===he["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.default.id),w=E==null?void 0:E.defaultValue;if(w)w.metaSync({value:!0},u);else if(E!=null&&E.dataType){const A={id:N.UUID.uuid(),version:N.UUID.uuid(),createdAt:(u==null?void 0:u.timestamp)||new Date().toISOString(),author:N.sessionAuthor,previousVersion:null,deleted:!1,type:f.LiteralValue,standaloneParent:null,name:oe.EntityTemplate,autogeneration:null,value:!0,valueAsTypeSingle:null,valueAsTypeList:null,parent:E==null?void 0:E.toReference()},$=ne(A,d.project);return $.setParent(E,u),$.initChildren(u),u==null||u.add($,S.Added),$.addSelfToProject(u),{newEntities:[$]}}return{newEntities:[]}}else if(a)return{newEntities:[]};const o=d.project.get(he["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.id),p=vm(o,"Main database",u);if(p.errors.length>0)return{newEntities:[]};const e=p.properties.find(v=>v.implements&&v.implements.id===he["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.default.id),y=e==null?void 0:e.defaultValue;if(y)y.metaSync({value:!0},u);else if(e!=null&&e.dataType){const v={id:N.UUID.uuid(),version:N.UUID.uuid(),createdAt:(u==null?void 0:u.timestamp)||new Date().toISOString(),author:N.sessionAuthor,previousVersion:null,deleted:!1,type:f.LiteralValue,standaloneParent:null,name:oe.EntityTemplate,autogeneration:null,value:!0,valueAsTypeSingle:null,valueAsTypeList:null,parent:e==null?void 0:e.toReference()},E=ne(v,d.project);E.setParent(e,u),E.initChildren(u),u==null||u.add(E,S.Added),E.addSelfToProject(u)}return{newEntities:[p]}}}return{newEntities:[]}}function b5(d,u){const r=[],a=[],o=[],p=[];return d.implements.filter(y=>y.type===f.BuiltInBaseEntity).forEach(y=>{var v;switch(y.id){case he["built-in-base-entity"].BUILT_IN_PERSISTED_ENTITY_ENTITY.id:{const E=d.project.entities.filter(V=>V.implements.find(B=>B.id===he["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.id));let w=E.find(V=>!!V.properties.find(B=>{var F;return B.implements&&B.implements.id===he["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.default.id&&((F=B.getDefaultValue())==null?void 0:F.value)===!0}));if(!w&&E.length)w=E[0];else if(!w&&!E.length){w=d.project.getBuiltIn(he["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.id).implement("Relational database",u);const B=w.properties.find(F=>{var K;return((K=F.implements)==null?void 0:K.id)===he["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.default.id});(v=B==null?void 0:B.defaultValue)==null||v.metaSync({value:!0},u),a.push(w)}const A=d.properties.find(V=>V.implements&&V.implements.id===he["built-in-base-entity"].BUILT_IN_PERSISTED_ENTITY_ENTITY.properties.database.id),$=A==null?void 0:A.defaultValue;if(A&&!$){const V={id:N.UUID.uuid(),version:N.UUID.uuid(),createdAt:(u==null?void 0:u.timestamp)||new Date().toISOString(),author:N.sessionAuthor,previousVersion:null,deleted:!1,type:f.LiteralValue,standaloneParent:null,name:oe.EntityTemplate,autogeneration:null,value:null,valueAsTypeSingle:(w==null?void 0:w.toJSON())||null,valueAsTypeList:null,parent:A==null?void 0:A.toReference()},B=ne(V,d.project);B.hydrateAncestors(),B.setParent(A,u),B.addSelfToProject(u),B.initChildren(u),u==null||u.add(B,S.Added),a.push(B);return}else $&&!$.valueAsTypeSingle&&$.setValueAsTypeSingle(w||null,u);return}}}),{self:d,updated:R(r),added:R(a),removed:R(o),affected:R(p)}}function vm(d,u,r,a){const o=a||N.UUID.uuid(),p=N.UUID.uuid(),e={id:o,version:p,createdAt:(r==null?void 0:r.timestamp)||new Date().toISOString(),author:N.sessionAuthor,previousVersion:null,deleted:!1,name:u,type:f.DefinitionEntity,codeName:null,description:null,static:d.static,abstract:!1,properties:[],methods:[],abstractMethods:[],extends:null,implements:[d.toJSON()],x:0,y:0,parent:d.project.toReference()};A5(d,r);const y=ne(e,d.project);return y.hydrateAncestors(),r==null||r.add(y,S.Added),y.addSelfToProject(r),y.addImplementation(d),y.setParent(d.project,r),y.initChildren(r),b5(y,r),y}function ab(d,u){return u.entities.find(o=>{const p=o.properties,e=p.map(A=>A.name),y=d.every(A=>e.includes(A)),v=e.filter(A=>!d.includes(A)),E=p.every(A=>!v.includes(A.name)||!A.required);return y&&E})||null}function w5(d,u,r,a=mi.OrDataTypeGroup){const o=[],p=[],e=[],y=[],E={id:N.UUID.uuid(),version:N.UUID.uuid(),createdAt:(r==null?void 0:r.timestamp)||new Date().toISOString(),author:N.sessionAuthor,previousVersion:null,deleted:!1,type:f.DataType,options:null,implementationChooseOne:!1,entity:d.toJSON(),isList:!1,asType:!1,andChildrenGroup:null,index:null,orChildrenGroup:null,staticEntities:null,interactiveEntities:null,actionEntities:null,like:!0,inferred:!1,parentRelationType:a,parent:u.toReference()},w=ne(E,d.project);return p.push(w),w.setParent(u,r),w.initChildren(r),r==null||r.add(w,S.Added),w.setEntity(d,r),w.addSelfToProject(r),{updated:R(o),added:R(p),removed:R(e),affected:R(y),self:w}}function ob(d,u,r,a,o){var E,w,A,$,V,B,F,K;const p=[],e=[],y=[],v=[];switch(typeof d){case"string":let q=!1;const ie=new Date(d);if(ie instanceof Date&&!isNaN(ie.valueOf())&&(q=!0),q){const W=u.project.getBuiltIn(he[f.PrimitiveEntity][oe.Date].id);u.setEntity(W,a);break}else{const W=u.project.getBuiltIn(he[f.PrimitiveEntity][oe.String].id);u.setEntity(W,a);break}case"number":u.setEntity(u.project.getBuiltIn(he[f.PrimitiveEntity][oe.Number].id),a);break;case"boolean":u.setEntity(u.project.getBuiltIn(he[f.PrimitiveEntity][oe.Boolean].id),a);break;case"object":if(d===null){u.setEntity(u.project.getBuiltIn(he[f.PrimitiveEntity][oe.Null].id),a);break}else if(Array.isArray(d))if(u.metaSync({isList:!0},a),d.length>0){const W=d.slice(0,5).filter(Q=>Q!==void 0);if(W.every(Q=>typeof Q==typeof W[0])&&(typeof W[0]!="object"||W[0]===null))switch(typeof W[0]){case"string":u.setEntity(u.project.getBuiltIn(he[f.PrimitiveEntity][oe.String].id),a);break;case"number":u.setEntity(u.project.getBuiltIn(he[f.PrimitiveEntity][oe.Number].id),a);break;case"boolean":u.setEntity(u.project.getBuiltIn(he[f.PrimitiveEntity][oe.Boolean].id),a);break;case"object":u.setEntity(u.project.getBuiltIn(he[f.PrimitiveEntity][oe.Null].id),a);break}else{const Q=[];let ce=!1;W.forEach(z=>{var pe,te,ue,Ie;if(Array.isArray(z)&&(ce=!0),typeof z=="object"&&!Array.isArray(z)&&z!==null){const Ue=Em(z,u.project,{...r,id:N.UUID.uuid()},a,o);Ue.hasCreated&&Q.push((pe=Ue.changeSet)==null?void 0:pe.self),p.push(...(te=Ue.changeSet)==null?void 0:te.updated),e.push(...(ue=Ue.changeSet)==null?void 0:ue.added),y.push(...(Ie=Ue.changeSet)==null?void 0:Ie.removed)}});const X=R(Q);if(!X.length&&!ce){W.forEach(z=>{const pe={id:N.UUID.uuid(),version:N.UUID.uuid(),createdAt:(a==null?void 0:a.timestamp)||new Date().toISOString(),author:N.sessionAuthor,previousVersion:null,deleted:!1,type:f.DataType,options:null,implementationChooseOne:!1,entity:null,isList:!1,asType:!1,andChildrenGroup:null,index:null,orChildrenGroup:null,staticEntities:!1,interactiveEntities:!0,actionEntities:!1,like:!0,inferred:!1,parentRelationType:mi.OrDataTypeGroup,parent:u.toReference()},te=ne(pe,u.project);switch(te.setParent(u,a),te.initChildren(a),a==null||a.add(te,S.Added),te.addSelfToProject(a),typeof z){case"string":te.setEntity(te.project.getBuiltIn(he[f.PrimitiveEntity][oe.String].id),a);break;case"number":te.setEntity(te.project.getBuiltIn(he[f.PrimitiveEntity][oe.Number].id),a);break;case"boolean":te.setEntity(te.project.getBuiltIn(he[f.PrimitiveEntity][oe.Boolean].id),a);break;case"object":te.setEntity(te.project.getBuiltIn(he[f.PrimitiveEntity][oe.Null].id),a);break}});break}else X.length===1&&!ce?u.setEntity(X[0],a):W.forEach(z=>{if(typeof z=="object"&&!Array.isArray(z)&&z!==null){const pe=ab(Object.keys(z),u.project);if(pe){const te=w5(pe||X[0],u,a,mi.OrDataTypeGroup);p.push(...te.updated),e.push(...te.added),y.push(...te.removed)}}else{const pe={id:N.UUID.uuid(),version:N.UUID.uuid(),createdAt:(a==null?void 0:a.timestamp)||new Date().toISOString(),author:N.sessionAuthor,previousVersion:null,deleted:!1,type:f.DataType,options:null,implementationChooseOne:!1,entity:null,isList:Array.isArray(z),asType:!1,andChildrenGroup:null,index:null,orChildrenGroup:null,staticEntities:!1,interactiveEntities:!0,actionEntities:!1,like:!0,inferred:!1,parentRelationType:mi.OrDataTypeGroup,parent:u.toReference()},te=ne(pe,u.project);te.setParent(u,a),te.initChildren(a),a==null||a.add(te,S.Added),te.addSelfToProject(a);const ue=ob(z,te,{...r,id:N.UUID.uuid()},a,o);p.push(...ue.updated),e.push(...ue.added),y.push(...ue.removed)}})}}else{const W=Em(d[0],u.project,{...r},a,o);u.setEntity((E=W.changeSet)==null?void 0:E.self,a),p.push(...(w=W.changeSet)==null?void 0:w.updated),e.push(...(A=W.changeSet)==null?void 0:A.added),y.push(...($=W.changeSet)==null?void 0:$.removed);break}else{const W=Em(d,u.project,{...r},a,o);u.setEntity((V=W.changeSet)==null?void 0:V.self,a),p.push(...(B=W.changeSet)==null?void 0:B.updated),e.push(...(F=W.changeSet)==null?void 0:F.added),y.push(...(K=W.changeSet)==null?void 0:K.removed);break}}return{updated:R(p),added:R(e),removed:R(y),affected:R(v),self:u}}function Em(d,u,r,a,o){const p=[],e=[],y=[],v=[],E=Object.keys(d),w=ab(E,u);if(w)return{hasCreated:!1,changeSet:{updated:[],added:[],removed:[],affected:[],self:w}};const A=o?r.name+" of "+o.name:r.name,V={id:r.id||N.UUID.uuid(),version:N.UUID.uuid(),createdAt:(a==null?void 0:a.timestamp)||new Date().toISOString(),author:N.sessionAuthor,previousVersion:null,deleted:!1,name:A,codeName:null,type:f.DefinitionEntity,description:r.description||null,static:r.static||!1,abstract:r.abstract||!1,properties:[],methods:[],abstractMethods:[],extends:null,implements:[],x:0,y:0,parent:u.toReference()},B=ne(V,u);return B.setParent(u,a),B.initChildren(a),a==null||a.add(B,S.Added),B.addSelfToProject(a),e.push(B),E.forEach((F,K)=>{const ie={id:N.UUID.uuid(),version:N.UUID.uuid(),createdAt:(a==null?void 0:a.timestamp)||new Date().toISOString(),author:N.sessionAuthor,previousVersion:null,deleted:!1,name:F,type:f.Property,codeName:F,description:null,static:!1,abstract:!1,defaultValue:null,constant:!1,interactive:!0,dataType:null,implements:null,extends:null,index:K,hidden:!1,private:!1,required:!0,parent:B.toReference()},W=ne(ie,u);W.setParent(B,a),W.initChildren(a),a==null||a.add(W,S.Added),W.addSelfToProject(a),e.push(W);const de=d[F],ce={id:N.UUID.uuid(),version:N.UUID.uuid(),createdAt:(a==null?void 0:a.timestamp)||new Date().toISOString(),author:N.sessionAuthor,previousVersion:null,deleted:!1,type:f.DataType,parentRelationType:null,options:null,implementationChooseOne:!1,entity:null,isList:!1,asType:!1,andChildrenGroup:null,index:null,orChildrenGroup:null,staticEntities:!1,interactiveEntities:!0,actionEntities:!1,like:!0,inferred:!1,parent:W.toReference()},X=ne(ce,u);X.setParent(W,a),X.initChildren(a),a==null||a.add(X,S.Added),X.addSelfToProject(a),e.push(X);const z=ob(de,X,{...r,name:F,id:N.UUID.uuid()},a,o||B);p.push(...z.updated),e.push(...z.added),y.push(...z.removed)}),{hasCreated:!0,changeSet:{updated:R(p),added:R(e),removed:R(y),affected:R(v),self:B}}}function Va(d,u,r,a){const o=[];return!d.length||!u.length?{errors:o,overlap:!1}:(d.length>u.length?d.forEach(p=>{const e=u.find(v=>v.name===p.name),y=u.find(v=>{var E,w;return!!p.implements&&((E=v.implements)==null?void 0:E.id)===((w=p.implements)==null?void 0:w.id)});if(e){const v=new ir({id:p.id+"--"+e.id+"--"+a,message:`Entity of type ${p.type} named "${p.name}" with id "${p.id}" overrides a base ${e.type} ${e.name} with id "${e.id}" that has the same name`,severity:H.Error,code:a,entity:p,firstRelationship:e});o.push(v)}if(y){const v=new ir({id:p.id+"--"+y.id+"--"+r,message:`Entity of type ${p.type} named "${p.name}" with id "${p.id}" overrides a base ${y.type} ${y.name} with id "${y.id}" that implements the same base descriptor`,severity:H.Error,code:r,entity:p,firstRelationship:y});o.push(v)}}):u.forEach(p=>{var v;const e=d.find(E=>E.name===p.name),y=d.find(E=>{var w,A;return!!E.implements&&((w=E.implements)==null?void 0:w.id)===((A=p.implements)==null?void 0:A.id)});if(e){const E=new ir({id:e.id+"--"+p.id+"--"+a,message:`Entity of type ${e.type} named "${e.name}" with id "${e.id}" overrides a base entity ${p.name} with id "${p.id}" that has the same name`,severity:H.Error,code:a,entity:e,firstRelationship:p});o.push(E)}if(y){const E=new ir({id:y.id+"--"+p.id+"--"+r,message:`Entity of type ${y.type} named "${y.name}" with id "${y.id}" overrides a base entity ${p.name} with id "${p.id}" that implements the same base ${(v=y==null?void 0:y.implements)==null?void 0:v.type}`,severity:H.Error,code:r,entity:y,firstRelationship:p});o.push(E)}}),{errors:o,overlap:!!o.length})}function iIe(d,u){return d.abstract||(d.properties.forEach(a=>{a.abstract||a.metaSync({abstract:!0},u)}),Object.values(d.detachedDependents).forEach(a=>{a.field===gI.Entity&&a.entity.remove({ignoreUpstream:!1},u)}),d.metaSync({abstract:!0},u)),d}function sIe(d,u){return d.abstract&&(d.properties.forEach(a=>{a.abstract&&a.metaSync({abstract:!1},u)}),Object.values(d.detachedDependents).forEach(a=>{(a.field===Bm.Implements||a.field===Bm.Extends)&&a.entity.onDetachedDependencyRemoved(d,a.field,u)}),d.metaSync({abstract:!1},u)),d}function nIe(d,u){return d.static||(d.properties.forEach(a=>{a.static||a.metaSync({static:!0},u)}),d.metaSync({static:!0},u)),d}function aIe(d,u){return d.static&&d.metaSync({static:!1},u),d}var ki=(d=>(d.StringValueMustNotHaveSpaces="string-value-must-not-have-spaces",d.StringValueMustNotHaveDashes="string-value-must-not-have-dashes",d.MustBeUniqueAmongSameEntities="must-be-unique-among-same-entities",d))(ki||{});function lb(d,u){const r=[],a=u;if(!a)return{errors:r,override:u};if(typeof a!="string")return{errors:[],override:u};if(a.includes(" ")){const o=new ir({id:d.id+"--string-value-must-not-have-spaces",message:`Entity of type ${d.type} with id "${d.id}" has an invalid value "${u}". The value cannot contain spaces.`,severity:H.Error,code:"string-value-must-not-have-spaces",entity:d});r.push(o)}return{errors:r,override:a.replace(/\s/g,"-")}}function R5(d,u){const r=[],a=u;if(!a)return{errors:r,override:u};if(typeof a!="string")return{errors:[],override:u};if(a.includes(" ")){const o=new ir({id:d.id+"--string-value-must-not-have-spaces",message:`Entity of type ${d.type} with id "${d.id}" has an invalid value "${u}". The value cannot contain spaces or dashes.`,severity:H.Error,code:"string-value-must-not-have-spaces",entity:d});r.push(o)}if(a.includes("-")){const o=new ir({id:d.id+"--string-value-must-not-have-dashes",message:`Entity of type ${d.type} with id "${d.id}" has an invalid value "${u}". The value cannot contain spaces or dashes.`,severity:H.Error,code:"string-value-must-not-have-dashes",entity:d});r.push(o)}return{errors:r,override:a.replace(/\s|-/g,"_")}}function db(d,u){var r;if(d.type===f.LiteralValue){let a=(r=d.value)==null?void 0:r.toString();try{a=JSON.stringify(d.value,null,2)}catch{}return`${d.type}: ${d.id} (${Y(d,u)}) = ${a}`}if(d.type===f.DataType){if(d instanceof fs||d.increaseVersion)return`${d.type}: ${d.id} (${Yd(d)})`;try{const a=Yd(d);return`${d.type}: ${d.id} (${a})`}catch{}}return`${d.type}: ${d.id} (${Y(d,u)})`}function Fd(d,u){const r=Ao(d);if(r.length===0)return{list:[],last:null};let a=null;return{list:r.flatMap(p=>{if(p===u)return a=p,[p];const e=Fd(p,u);return e.last&&(a=e.last),[p,...e.list]}),last:a}}function Io(d,u){const r=d.calledBy;if(r.length===0)return{list:[],last:null,callType:null};let a=null,o=null;return{list:r.flatMap(e=>{if(e===u)return a=e,Dt.includes(e.type)?e.parent.type===f.Loop?o="loop-body":o="entry":e.successCalls.includes(d)?o="success":e.errorCalls.includes(d)&&(o="error"),[e];if(e.type===f.FunctionDeclaration&&e.parent.type===f.Loop&&e.parent===u)return a=e.parent,o="loop-body",[e];if(!xi.includes(e.type))return[e];const y=Io(e,u);return y.last&&(a=y.last,o=y.callType),[e,...y.list]}),last:a,callType:o}}function oIe(d,u){if(d===u)return"same-entity";if(!wi.includes(d.type)||!Yp(d).find(o=>o.callee===u))return null;if(Dt.includes(d.type)){if(d.calls.includes(u))return d.type===f.Loop?"loop-body":"entry"}else if(sr.includes(d.type)&&d.type!==f.InternalCall){if(d.successCalls.includes(u))return"success";if(d.errorCalls.includes(u))return"error"}return null}function Jp(d){const u=Di(d,d.project);return u?Dt.includes(u.type)?u:u.type===f.Loop?u.body:null:null}function g5(d,u){const r=d.calledBy;return!r||!r.length?!1:r.every(a=>a===u?!0:xi.includes(a.type)?!!Io(a,u).last:!1)}function _5(d){return d.filter(u=>{const r=Jp(u);return!d.filter(p=>p!==u).some(p=>p===r?!1:Im(p,u))})}function D5(d,u){if(!d)throw new Error("findNextSingleCallerAncestor: Target is not defined, cannot find ancestor.");let r=d;(d.type===f.VariableDeclaration||d.type===f.VariableInstance)&&!d.calledBy.length&&!d.successCalls.length&&!d.errorCalls.length&&d.internalCalls.some($=>!!$.calledBy.length)&&(r=d.internalCalls.find(V=>!!V.calledBy.length));const a=u||Di(r,d.project);if(!a)return{ancestor:null,callType:null};if(a.type===f.Project)return{ancestor:null,callType:null};const o=Yp(a);if(!o.find($=>$.callee===r))return{ancestor:null,callType:null};if(a.type===f.Loop){if(a.body.calls.includes(r))return{ancestor:a,callType:"loop-body"}}else if(Dt.includes(a.type)){if(a.calls.includes(r))return a.type===f.FunctionDeclaration&&a.parent.type===f.Loop?{ancestor:a,callType:"loop-body"}:{ancestor:a,callType:"entry"}}else if(sr.includes(a.type)){if(a.successCalls.includes(r))return{ancestor:a,callType:"success"};if(a.errorCalls.includes(r))return{ancestor:a,callType:"error"}}const e=o.filter($=>!($.callee===r||!wi.includes($.callee.type)||!dt($.callee).find(F=>F===r))).filter(($,V,B)=>B.findIndex(F=>F.callee===$.callee)===V);if(e.length===0)return{ancestor:null,callType:null};if(e.length===1){const $=e[0];if($.callee.type===f.Loop){if($.callee.body.calls.includes(r))return{ancestor:$.callee,callType:"loop-body"}}else{if(Dt.includes($.callee.type))return $.callee.type===f.FunctionDeclaration&&$.callee.parent.type===f.Loop?{ancestor:$.callee,callType:"loop-body"}:{ancestor:$.callee,callType:"entry"};if(sr.includes($.callee.type)){if($.callType==="success"&&$.callee.type===f.InternalCall)return{ancestor:$.callee,callType:"success"};if($.callType==="error"&&$.callee.type===f.InternalCall)return{ancestor:$.callee,callType:"error"}}}}const y=e.filter($=>g5(r,$.callee)),v=y.filter($=>{const V=dt($.callee),B=y.filter(K=>K.callee!==$.callee).map(K=>K.callee);return!V.some(K=>!!B.find(ie=>ie===K))});if(v.length===0){if(a.type===f.Loop){if(dt(a.body).find(ie=>ie===r))return{ancestor:a,callType:"loop-body"};if(ri(a.successCalls).find(ie=>ie===r))return{ancestor:a,callType:"success"};if(ri(a.errorCalls).find(ie=>ie===r))return{ancestor:a,callType:"error"}}else if(sr.includes(a.type)){if(ri(a.successCalls).find(K=>K===r))return{ancestor:a,callType:"success"};if(ri(a.errorCalls).find(K=>K===r))return{ancestor:a,callType:"error"}}return a.parent.type===f.Loop?{ancestor:a,callType:"loop-body"}:{ancestor:a,callType:"entry"}}if(v.length>1)throw new Error(`findNextSingleCallerAncestor: Could not be resolved, multiple candidates found: ${v.map($=>Y($.callee,r.project)).join(", ")}`);const E=v[0].callee,A=Yp(E).find($=>$.callee===r);return{ancestor:E,callType:A.callType}}function lIe(d){if(![f.VariableDeclaration,f.OutputMap].includes(d.type))throw new Error("getEarliestSingleCallerAncestorOfValueWriterAndItsValueReaders can only be used with a value writer entity");let u;if(d.type===f.VariableDeclaration?u=d:d.type===f.OutputMap&&(u=d.parent),!u)throw new Error("getEarliestSingleCallerAncestorOfValueWriterAndItsValueReaders can only be used with a value writer entity that has a caller");const r=R([d,...cb(d)]),a=R(r.map(y=>ub(y)).flatMap(y=>hr.includes(y==null?void 0:y.type)?y.calledBy:[y]));if(a.length===1){if(Dt.includes(a[0].type))return a[0].parent.type===f.Loop?{ancestor:a[0],callType:"loop-body"}:{ancestor:a[0],callType:"entry"};if(a[0].successCalls.includes(u))return{ancestor:a[0],callType:"success"};if(a[0].errorCalls.includes(u))return{ancestor:a[0],callType:"error"}}const o=a.map(y=>{if(Dt.includes(y.type))return y.parent.type===f.Loop?{ancestor:y,callType:"loop-body"}:{ancestor:y,callType:"entry"};const v=D5(y);if(!v.ancestor)throw new Error(`getEarliestSingleCallerAncestorOfValueWriterAndItsValueReaders: Could not be resolved, no ancestor found for ${Y(y,u.project)}`);return v}).filter((y,v,E)=>v===E.findIndex(w=>{var A,$;return((A=w.ancestor)==null?void 0:A.id)===(($=y.ancestor)==null?void 0:$.id)})),p=Jp(u),e=o.filter(y=>y!=null&&y.ancestor?p===y.ancestor?!0:!o.filter(w=>w.ancestor!==y.ancestor).map(w=>w.ancestor).some(w=>{const A=Io(y.ancestor,w);return!!(A!=null&&A.last)}):!1);if(e.length===0)return{ancestor:p,callType:(p==null?void 0:p.parent.type)===f.Loop?"loop-body":"entry"};if(e.length>1)throw new Error(`getEarliestSingleCallerAncestorOfValueWriterAndItsValueReaders: Could not be resolved, multiple candidates found: ${e.map(y=>Y(y.ancestor,u.project)).join(", ")}`);return{ancestor:e[0].ancestor,callType:e[0].callType}}function O5(d,u){if(d===u)return!0;if(dt(d).includes(u)||!dt(u).includes(d))return!1;const o=d.calledBy;return o.length===0?!1:o.length===1?o[0]===u:_5(o).length>1&&o.includes(u)?!1:o.every(e=>d===u?!0:Dt.includes(e.type)?!1:O5(e,u))}function C5(d){const u=[];let r=d.calledBySuccess;r=r.filter(o=>!r.filter(y=>y!==o).some(y=>Im(y,o)));let a=d.calledByError;a=a.filter(o=>!a.filter(y=>y!==o).some(y=>Im(y,o)));for(const o of r)u.push({ancestor:o,callType:"success"});for(const o of a)u.push({ancestor:o,callType:"error"});return u}function $5(d){const u=[];return C5(d).forEach(a=>{a.ancestor.type===f.Condition&&u.push({condition:a.ancestor,call:d,callType:a.callType});const p=$5(a.ancestor).filter(e=>!u.some(y=>y.condition.id===e.condition.id));u.push(...p)}),u}function ub(d){if(!d)return null;if(d.type===f.Condition&&d.parent.type===f.Condition)return Am(d.parent);if($v.includes(d.type))return d;const u=d.parent;return u?ub(u):null}function cb(d,u=new Set){return d.writesValues.reduce((r,a)=>u.has(a.id)?r:(u.add(a.id),un.includes(a.type)?[...r,a]:Br.includes(a.type)?[...r,a,...cb(a,u)]:r),[])}function Wp(d){const u=d.calledBy;if(u.length===0)return d.project;const r=u.reduce((a,o)=>{const p=Di(o,d.project);return!p||p.type===f.Project?a:a.type===f.Project||Fd(p,a).last?p:(Fd(a,p).last,a)},d.project);return r.type===f.FunctionDeclaration&&r.parent.type===f.Loop?r.parent:r}function He(d,u){let r=Wp(d);if(d.type===f.InternalCall)if(d.parent.type===f.VariableInstance){const o=Xs(r,d.parent.declaration,d.project);!o.compatible&&o.type!=="b-is-global-a-is-not"?d.parent.remove({ignoreUpstream:!1},u):(d.parent.setParent(r,u),d.parent.addSelfToProject(u))}else d.parent.setParent(r,u),d.parent.addSelfToProject(u);else if((d.type===f.ContinueStatement||d.type===f.BreakStatement)&&r.type!==f.Loop){d.remove({ignoreUpstream:!1},u);return}else if(d.type===f.ReturnStatement&&!Nr.includes(r.type)){d.remove({ignoreUpstream:!1},u);return}else if(Tt.includes(d.type)){const o=d.usedInternalCalls[0];if(o)if(r=Wp(o),d.type===f.VariableInstance){const p=Xs(r,d.declaration,d.project);!p.compatible&&p.type!=="b-is-global-a-is-not"?d.remove({ignoreUpstream:!1},u):(d.setParent(r,u),d.addSelfToProject(u))}else d.setParent(r,u),d.addSelfToProject(u);else if(d.type===f.VariableInstance){const p=Xs(r,d.declaration,d.project);!p.compatible&&p.type!=="b-is-global-a-is-not"?d.remove({ignoreUpstream:!1},u):(d.setParent(r,u),d.addSelfToProject(u))}else d.setParent(r,u),d.addSelfToProject(u)}else d.setParent(r,u),d.addSelfToProject(u);if(hr.includes(d.type))return;dt(d).forEach(o=>{let p=Wp(o);if(o.type===f.InternalCall)if(o.parent.type===f.VariableInstance){const e=Xs(p,o.parent.declaration,d.project);!e.compatible&&e.type!=="b-is-global-a-is-not"?o.parent.remove({ignoreUpstream:!1},u):(o.parent.setParent(p,u),o.parent.addSelfToProject(u))}else o.parent.setParent(p,u),o.parent.addSelfToProject(u);else if((o.type===f.ContinueStatement||o.type===f.BreakStatement)&&p.type!==f.Loop){o.remove({ignoreUpstream:!1},u);return}else if(o.type===f.ReturnStatement&&!Nr.includes(p.type)){o.remove({ignoreUpstream:!1},u);return}else if(Tt.includes(o.type)){const e=o.usedInternalCalls[0];if(e)if(p=Wp(e),o.type===f.VariableInstance){const y=Xs(p,o.declaration,d.project);!y.compatible&&y.type!=="b-is-global-a-is-not"?o.remove({ignoreUpstream:!1},u):(o.setParent(p,u),o.addSelfToProject(u))}else o.setParent(p,u),o.addSelfToProject(u);else if(o.type===f.VariableInstance){const y=Xs(p,o.declaration,d.project);!y.compatible&&y.type!=="b-is-global-a-is-not"?o.remove({ignoreUpstream:!1},u):(o.setParent(p,u),o.addSelfToProject(u))}else o.setParent(p,u),o.addSelfToProject(u)}else o.setParent(p,u),o.addSelfToProject(u)})}function Tm(d,u,r=new Set){const a=bn(d),o=bn(u),p=a.filter(v=>!o.includes(v)),e=a.filter(v=>o.includes(v)),y=p.reduce((v,E)=>r.has(E.id)?v:(r.add(E.id),R([...v,...Tm(E,u,r)])),[]);return R([...e,...y])}function Il(d,u){const r=Fd(d,u);return r.last===u&&r.list.length>0&&r.list[0]!==u}function pb(d,u){return!!Fd(d,u).last}function Im(d,u){return!!Io(d,u).last}function fb(d,u){if(!d||!u)throw new Error("Both entities must be defined to find a common ancestor");if(d===u)return d;const r=d.parent;if(r){if(r===u)return u;if(r.type===f.Project)return null}else return null;const a=u.parent;if(a){if(a===d)return d;if(a.type===f.Project)return null}else return null;return fb(r,a)}function dIe(d,u,r=!0){if(!d||!u)throw new Error("Both entities must be defined to find a common ancestor");if(d===u)return{ancestor:d,callType:"same-entity"};if(xi.includes(d.type)&&wi.includes(u.type)){const y=Io(d,u),v=y.last;if(v){if(v===u)return{ancestor:u,callType:y.callType}}else return{ancestor:null,callType:null}}if(xi.includes(u.type)&&wi.includes(d.type)){const y=Io(u,d),v=y.last;if(v){if(v===d)return{ancestor:d,callType:y.callType}}else return{ancestor:null,callType:null}}const a=Jp(d),o=Jp(u);if(!a||!o)return{ancestor:null,callType:null};if(a!==o)return{ancestor:null,callType:null};if(a.calls.includes(d)||a.calls.includes(u))return{ancestor:a,callType:"entry"};const p=a.calls.reduce((y,v)=>{if(!wi.includes(v.type))return y;const E=Yp(v),w=E.find($=>$.callee===d),A=E.find($=>$.callee===u);return w&&A&&(!r||w.callType===A.callType)?[...y,{ancestor:v,callType:w.callType}]:y},[]);if(p.length===0)return{ancestor:null,callType:null};if(p.length===1)return{ancestor:p[0].ancestor,callType:p[0].callType};const e=p.filter(y=>!p.some(v=>v.ancestor!==y.ancestor&&Io(y.ancestor,v.ancestor).last===v.ancestor));return e.length===1?{ancestor:e[0].ancestor,callType:e[0].callType}:{ancestor:a,callType:"entry"}}function fr(d){if(th.includes(d.type)){if(d.type===f.FunctionDeclaration){const u=d.parent;if(u.type===f.DefinitionEntity)return fr(u);if(u.type===f.Loop)return u}return d.type===f.DefinitionEntity&&d.parent.type===f.DataType||d.type===f.Condition&&d.parent.type===f.Condition?fr(d.parent):d}else{const u=d.parent;return u?fr(u):null}}function Sd(d,u){const r=Kd(d,u);if(!r)return null;if(th.includes(r.type)){if(r.type===f.FunctionDeclaration){const a=Kd(r.parent,u);if(a){if(a.type===f.DefinitionEntity)return a;if(a.type===f.Loop)return a}}if(r.parent){const a=Kd(r.parent,u);if(a&&(r.type===f.DefinitionEntity&&a.type===f.DataType||r.type===f.Condition&&a.type===f.Condition))return Sd(a,u)}return r}else{const a=r.parent?Kd(r.parent,u):null;return a?Sd(a,u):null}}function Yp(d){if(d.type===f.Loop){const u=[...ri(d.successCalls).map(o=>({callee:o,callType:"success"})),...ri(d.errorCalls).map(o=>({callee:o,callType:"error"})),...(d.body?dt(d.body):[]).map(o=>({callee:o,callType:"loop-body"}))];return R(u.map(o=>o.callee)).map(o=>{var e;const p=(e=u.find(y=>y.callee===o))==null?void 0:e.callType;return{callee:o,callType:p}})}if(sr.includes(d.type)){const u=[...ri(d.successCalls).map(o=>({callee:o,callType:"success"})),...ri(d.errorCalls).map(o=>({callee:o,callType:"error"}))];return R(u.map(o=>o.callee)).map(o=>{var e;const p=(e=u.find(y=>y.callee===o))==null?void 0:e.callType;return{callee:o,callType:p}})}if(Dt.includes(d.type)){const u=[...ri(d.calls).map(o=>d.parent.type===f.Loop?{callee:o,callType:"loop-body"}:{callee:o,callType:"entry"})];return R(u.map(o=>o.callee)).map(o=>{var e;const p=(e=u.find(y=>y.callee===o))==null?void 0:e.callType;return{callee:o,callType:p}})}return[]}function Am(d){if(!d)return null;if(d.type===f.Condition&&d.parent.type===f.Condition)return Am(d.parent);if(xi.includes(d.type))return d;const u=d.parent;return u?Am(u):null}function P5(d){if(!d)return null;if(sr.includes(d.type))return d;const u=d.parent;return u?P5(u):null}function N5(d){if(!d)return null;if(wi.includes(d.type))return d;const u=d.parent;return u?N5(u):null}function uIe(d){return d.type===f.VariableDeclaration?[d]:sr.includes(d.type)?[...d.inputs,...d.outputs||[]]:hr.includes(d.type)?d.outputs:jo.includes(d.type)||d.type===f.FunctionDeclaration?d.inputs:[]}function cIe(d){const u=bn(d),r=[],a=[];Xg.includes(d.type)&&r.push(...bm(d));const o=u.filter(p=>{const e=r.includes(p);return e?!1:xi.includes(p.type)&&!e?(a.push(p),!1):!0});return r.sort((p,e)=>Il(e,p)?-1:0),a.sort((p,e)=>Il(e,p)?-1:0),[...r,...a,...o]}function V5(d){return[...d].sort((u,r)=>Il(r,u)?-1:0)}function pIe(d){const u=V5(d),r=[];return u.forEach(a=>{const o=r[r.length-1];if(o){const p=o[o.length-1];Il(a,p)?r.push([a]):o.push(a)}else r.push([a])}),r}function La(d){const u=d.map(r=>fr(r));return R(u)}function bm(d){return sr.includes(d.type)?[...La(d.successCalls),...La(d.errorCalls)]:Dt.includes(d.type)?La(d.calls):[]}function fIe(d,u){return bm(d).includes(u)}function wm(d){return d.writesValues||[]}function hIe(d,u){return wm(d).includes(u)}function L5(d){var u;return Tt.includes((u=d==null?void 0:d.readsValue)==null?void 0:u.type)?d.readsValue:null}function yIe(d){return d.writesValues}function M5(d=[]){return d.map(L5).filter(u=>!!u)}function Rm(d=[]){return d.map(u=>u.writesValues).flat().filter(u=>Tt.includes(u.type))}function B5(d=[]){return d.map(u=>u.readsValue).filter(u=>!!u&&Tt.includes(u.type))}function U5(d){return Tt.includes(d.type)?d:null}function x5(d){return d.writesValues.map(U5).filter(u=>!!u)}function j5(d=[]){return d.reduce((u,r)=>r.type===f.OutputMap?[...u,...x5(r)]:u,[])}function dt(d){return d.type===f.Loop?R([...ri(d.successCalls),...ri(d.errorCalls),...d.body?dt(d.body):[]]):sr.includes(d.type)?R([...ri(d.successCalls),...ri(d.errorCalls)]):Dt.includes(d.type)?R(ri(d.calls)):[]}function mIe(d){return sr.includes(d.type)?[...ri(d.successCalls),...ri(d.errorCalls)]:Dt.includes(d.type)?ri(d.calls):[]}function G5(d,u=new Set){return d.writesValues.filter(a=>Tt.includes(a.type)&&!u.has(a.id)).reduce((a,o)=>u.has(o.id)?a:[...a,...vr(o,u)],[])}function F5(d,u=new Set){var a;return(((a=d.readsValue)==null?void 0:a.writesValues)||[]).filter(o=>Tt.includes(o.type)&&!u.has(o.id)).reduce((o,p)=>u.has(p.id)?o:[...o,...vr(p,u)],[])}function vr(d,u=new Set){if(u.has(d.id))return[];if(d.type===f.ReturnStatement)return B5(d.outputs).reduce((a,o)=>[...a,...vr(o,u)],[]);if(d.type===f.FunctionCall||d.type===f.Operation||d.type===f.Condition)return[...dt(d).reduce((p,e)=>{const y=fr(e);return[...p,...vr(y||e,u)]},[]),...M5(d.inputs),...j5(d.outputs)].reduce((p,e)=>[...p,...vr(e,u)],[]);if(jo.includes(d.type)){const r=Rm(d.inputs),o=dt(d).reduce((p,e)=>{const y=fr(e);return[...p,...vr(y||e,u)]},[]);return r.push(...o),r.reduce((p,e)=>[...p,...vr(e,u)],[])}if(d.type===f.FunctionDeclaration){const r=[...Rm(d.inputs)],o=dt(d).reduce((p,e)=>{const y=fr(e);return[...p,...vr(y||e,u)]},[]);return r.push(...o),r.reduce((p,e)=>[...p,...vr(e)],[])}if(Tt.includes(d.type)){u.add(d.id);const a=dt(d).reduce((o,p)=>{const e=fr(p);return[...o,...vr(e||p,u)]},[]);return[d,...a,...F5(d,u),...G5(d,u)]}return[]}function ms(d,u=new Set){return u.has(d.id)?[]:(u.add(d.id),[...bn(d).reduce((o,p)=>[...o,p,...ms(p,u)],[])])}function ri(d){return d.reduce((u,r)=>r.type===f.ReturnStatement||r.type===f.ContinueStatement||r.type===f.BreakStatement?[...u,r]:[...u,r,...dt(r)],[])}function S5(d){const u=d.entities||[],r=[...u,...d.functions||[],...d.events||[],...d.projects||[]],a=u.reduce((v,E)=>[...v,...E.properties],[]),o=u.reduce((v,E)=>[...v,...E.methods],[]),p=o.reduce((v,E)=>[...v,...Rm(E.inputs),...ri(La(E.calls)),...E.returnStatements],[]),e=d.functions.reduce((v,E)=>[...v,...ri(La(E.calls)),...E.returnStatements],[]),y=d.events.reduce((v,E)=>[...v,...ri(La(E.calls)),...E.returnStatements],[]);return[...r,...a,...o,...p,...e,...y]}function K5(d,u){return u.filter(a=>{if(!a)return!1;switch(a.type){case f.FunctionCall:return a.inputs.find(o=>o.id===d.id)!==void 0||a.outputs.find(o=>o.id===d.id)!==void 0;case f.Condition:return a.successCalls.find(o=>o.id===d.id)!==void 0||a.errorCalls.find(o=>o.id===d.id)!==void 0||a.inputs.find(o=>o.id===d.id)!==void 0;case f.Operation:return a.outputs.find(o=>o.id===d.id)!==void 0;case f.VariableDeclaration:return sr.includes(d.type)?ES(d).find(p=>{var e;return((e=p.readsValue)==null?void 0:e.id)===a.id})!==void 0:!1;case f.DefinitionEntity:return a.properties.find(o=>o.id===d.id)!==void 0||a.methods.find(o=>o.id===d.id)!==void 0;case f.FunctionDeclaration:return a.inputs.find(o=>o.id===d.id)!==void 0||(a.returnStatements.map(o=>o.outputs).flat()||[]).find(o=>o.id===d.id)!==void 0;default:return!1}})}function vIe(d){const u=S5(d.project);return K5(d,u)}function Kd(d,u){return d?typeof d=="string"?u[d]:d.type===f.GenericReference?u[d.entityId]:u[d.id]?u[d.id]:null:null}function k5(d={},u){const r={};return Object.keys(d).forEach(a=>{const o=u.get(a)||a,p=d[a];r[o]=p}),r}function kd(d,u={},r={}){const a={ignoreBuiltInBaseEntities:!1,allBuiltInEntityIds:[],entityMaps:new Map,...r};if(a.ignoreBuiltInBaseEntities&&(Zi.includes(d.type)||(a.allBuiltInEntityIds||[]).includes(d.id)))return{upstream:{},downstream:{}};const o=d,p=d,e=d,y=d,v=d,E=d,w=d,A=d,$=d,V=d,B=d,F=d,K=d,q=[...K.readsValue?[K.readsValue]:[],...K.declaration?[K.declaration]:[],...(F.calledByEntry||[]).flatMap(Q=>Q),...(F.calledBySuccess||[]).flatMap(Q=>Q),...(F.calledByError||[]).flatMap(Q=>Q),...V.parent?[V.parent]:[]];Array.isArray(e.implements)?q.push(...e.implements.flatMap(Q=>Q)):$.implements&&q.push($.implements),Array.isArray(e.extends)?q.push(...e.extends.flatMap(Q=>Q)):$.extends&&q.push($.extends),v.valueAsTypeList&&Array.isArray(v.valueAsTypeList)&&q.push(...v.valueAsTypeList.flatMap(Q=>Q)),v.valueAsTypeSingle&&q.push(v.valueAsTypeSingle),(K.internalCalls||[]).forEach(Q=>{const ce=J(Q);if(ce&&u[ce]){const X=u[ce];[...X.calledByEntry||[],...X.calledBySuccess||[],...X.calledByError||[]].forEach(z=>{const pe=J(z);pe&&u[pe]&&q.push(u[pe])})}});const ie=[...(o.inputs||[]).flatMap(Q=>Q),...(B.inputsDeclarations||[]).flatMap(Q=>Q),...(o.outputs||[]).flatMap(Q=>Q),...(B.outputsDeclarations||[]).flatMap(Q=>Q),...(K.internalCalls||[]).flatMap(Q=>Q),...K.writesValues||[],...F.dataType?[F.dataType]:[],...E.body?[E.body]:[],...F.defaultValue?[F.defaultValue]:[],...(F.successCalls||[]).flatMap(Q=>Q),...(F.errorCalls||[]).flatMap(Q=>Q),...(e.properties||[]).flatMap(Q=>Q),...(e.methods||[]).flatMap(Q=>Q),...(e.abstractMethods||[]).flatMap(Q=>Q),...w.error?[w.error]:[],...w.process?[w.process]:[],...V.throws?[V.throws]:[],...(p.andChildrenGroup||[]).flatMap(Q=>Q),...(p.orChildrenGroup||[]).flatMap(Q=>Q),...(A.entities||[]).flatMap(Q=>Q),...(A.functions||[]).flatMap(Q=>Q),...(A.functionCalls||[]).flatMap(Q=>Q),...(A.events||[]).flatMap(Q=>Q),...(A.conditions||[]).flatMap(Q=>Q),...(A.operations||[]).flatMap(Q=>Q),...(A.loops||[]).flatMap(Q=>Q),...(A.variableDeclarations||[]).flatMap(Q=>Q),...(A.variableInstances||[]).flatMap(Q=>Q),...(A.searches||[]).flatMap(Q=>Q),...(A.projects||[]).flatMap(Q=>Q),...(y.calls||[]).flatMap(Q=>Q)];d.type===f.DataType&&(p.entity&&u[J(p.entity)]&&u[J(p.entity)].parent&&J(u[J(p.entity)].parent)===d.id?ie.push(p.entity):p.entity&&q.push(p.entity)),(K.internalCalls||[]).forEach(Q=>{const ce=J(Q);if(ce&&u[ce]){const X=u[ce];[...X.successCalls||[],...X.errorCalls||[]].forEach(z=>{const pe=J(z);pe&&u[pe]&&ie.push(u[pe])})}});const W={},de={};return q.forEach(Q=>{var z;const ce=J(Q);if(ce&&a.ignoreBuiltInBaseEntities&&(Zi.includes(Q.type)||(a.allBuiltInEntityIds||[]).includes(ce)))return;const X=Q.version;if(ce){const pe=((z=a.entityMaps)==null?void 0:z.get(ce))||ce;W[pe]=X}}),ie.forEach(Q=>{var z;const ce=J(Q);if(ce&&a.ignoreBuiltInBaseEntities&&(Zi.includes(Q.type)||(a.allBuiltInEntityIds||[]).includes(ce)))return;const X=Q.version;if(ce){const pe=((z=a.entityMaps)==null?void 0:z.get(ce))||ce;de[pe]=X}}),{upstream:W,downstream:de}}function EIe(d,u){const r=[];if(xi.includes(d.type)){Ms(d).forEach(p=>{const e=Sd(p,u);e&&r.push(e)});const o=[...d.inputs||[],...d.outputs||[]].map(p=>{const e=Kd(p,u);return e?IS(e,u):null}).filter(p=>p!==null);r.push(...R(o))}if(Tt.includes(d.type)){const a=gm(d);a&&r.push(a)}return R(r)}function Ao(d){const u=[];if(xi.includes(d.type)){d.calledBy.forEach(o=>{const p=fr(o);p&&u.push(p)});const a=[...d.inputs||[],...d.outputs||[]].map(o=>gm(o)).filter(o=>o!==null);u.push(...R(a))}if(Tt.includes(d.type)){const r=gm(d);r&&u.push(r)}return R(u)}function Ms(d){return[...d.calledByEntry||[],...d.calledByError||[],...d.calledBySuccess||[]].filter(u=>u.type!==f.GenericReference)}function q5(d,u=new Set,r={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.ActionDescriptor)throw new Error("Entity must be an action descriptor to be flattened");return[d,...d.inputs.flatMap(a=>me(a,u,r)),...d.outputs.flatMap(a=>me(a,u,r)),...d.error?me(d.error,u,r):[],...d.parent?me(d.parent,u,r):[]]}function Z5(d,u=new Set,r={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.ArgumentDeclaration)throw new Error("Entity must be an argument declaration to be flattened");return[d,...d.defaultValue?me(d.defaultValue,u):[],...d.writesValues.flatMap(a=>me(a,u,r)),...d.dataType?me(d.dataType,u,r):[],...d.parent?me(d.parent,u,r):[]]}function H5(d,u=new Set,r={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.BreakStatement)throw new Error("Entity must be a break statement to be flattened");return[d,...d.outputs.flatMap(a=>me(a,u,r)),...d.throws?me(d.throws,u,r):[],...(Ms(d)||[]).flatMap(a=>me(a,u,r)),...d.parent?me(d.parent,u,r):[]]}function J5(d,u=new Set,r={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.BuiltInBaseEntity)throw new Error("Entity must be a built-in base entity to be flattened");return[d,...(d.properties||[]).flatMap(a=>me(a,u,r)),...(d.methods||[]).flatMap(a=>me(a,u,r)),...(d.abstractMethods||[]).flatMap(a=>me(a,u,r)),...d.extends?me(d.extends,u,r):[]]}function W5(d,u=new Set,r={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.Condition)throw new Error("Entity must be a condition to be flattened");return[d,...(d.andChildrenGroup||[]).flatMap(a=>me(a,u,r)),...(d.orChildrenGroup||[]).flatMap(a=>me(a,u,r)),...(d.inputs||[]).flatMap(a=>me(a,u,r)),...(d.successCalls||[]).flatMap(a=>me(a,u,r)),...(d.errorCalls||[]).flatMap(a=>me(a,u,r)),...(Ms(d)||[]).flatMap(a=>me(a,u,r)),...d.parent?me(d.parent,u,r):[]]}function Y5(d,u=new Set,r={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.ContinueStatement)throw new Error("Entity must be a continue statement to be flattened");return[d,...d.outputs.flatMap(a=>me(a,u,r)),...d.throws?me(d.throws,u,r):[],...(Ms(d)||[]).flatMap(a=>me(a,u,r)),...d.parent?me(d.parent,u,r):[]]}function z5(d,u=new Set,r={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.DefinitionEntity)throw new Error("Entity must be a definition entity to be flattened");return[d,...d.extends?me(d.extends,u,r):[],...(d.implements||[]).flatMap(a=>me(a,u,r)),...(d.properties||[]).flatMap(a=>me(a,u,r)),...(d.methods||[]).flatMap(a=>me(a,u,r)),...(d.abstractMethods||[]).flatMap(a=>me(a,u,r)),...d.parent?me(d.parent,u,r):[]]}function X5(d,u=new Set,r={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.DataType)throw new Error("Entity must be a data type to be flattened");return[d,...(d.andChildrenGroup||[]).flatMap(a=>me(a,u,r)),...(d.orChildrenGroup||[]).flatMap(a=>me(a,u,r)),...d.entity?me(d.entity,u,r):[],...d.parent?me(d.parent,u,r):[]]}function Q5(d,u=new Set,r={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.FunctionCall)throw new Error("Entity must be a function call to be flattened");return[d,...(d.inputs||[]).flatMap(a=>me(a,u,r)),...(d.outputs||[]).flatMap(a=>me(a,u,r)),...d.error?me(d.error,u,r):[],...d.process?me(d.process,u,r):[],...(Ms(d)||[]).flatMap(a=>me(a,u,r)),...(d.successCalls||[]).flatMap(a=>me(a,u,r)),...(d.errorCalls||[]).flatMap(a=>me(a,u,r)),...d.parent?me(d.parent,u,r):[]]}function eS(d,u=new Set,r={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.FunctionDeclaration)throw new Error("Entity must be a function declaration to be flattened");return[d,...(d.inputs||[]).flatMap(a=>me(a,u,r)),...(d.calls||[]).flatMap(a=>me(a,u,r)),...d.implements?me(d.implements,u,r):[],...d.parent?me(d.parent,u,r):[]]}function tS(d,u=new Set,r={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.GlobalEvent)throw new Error("Entity must be a global event to be flattened");return[d,...(d.inputs||[]).flatMap(a=>me(a,u,r)),...(d.calls||[]).flatMap(a=>me(a,u,r)),...d.implements?me(d.implements,u,r):[],...d.parent?me(d.parent,u,r):[]]}function rS(d,u=new Set,r={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.InputMap)throw new Error("Entity must be an input map to be flattened");return[d,...d.readsValue?me(d.readsValue,u,r):[],...d.declaration?me(d.declaration,u,r):[],...d.defaultValue?me(d.defaultValue,u,r):[],...d.parent?me(d.parent,u,r):[]]}function iS(d,u=new Set,r={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.InstalledProject)throw new Error("Entity must be an installed project to be flattened");return[d,...(d.functions||[]).flatMap(a=>me(a,u,r)),...(d.events||[]).flatMap(a=>me(a,u,r)),...d.parent?me(d.parent,u,r):[]]}function sS(d,u=new Set,r={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.InternalCall)throw new Error("Entity must be an internal call to be flattened");return[d,...(d.successCalls||[]).flatMap(a=>me(a,u,r)),...(d.errorCalls||[]).flatMap(a=>me(a,u,r)),...(d.inputs||[]).flatMap(a=>me(a,u,r)),...(d.outputs||[]).flatMap(a=>me(a,u,r)),...(Ms(d)||[]).flatMap(a=>me(a,u,r)),...d.error?me(d.error,u,r):[],...d.process?me(d.process,u,r):[],...d.parent?me(d.parent,u,r):[]]}function nS(d,u=new Set,r={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.LiteralValue)throw new Error("Entity must be a literal value to be flattened");return[d,...d.valueAsTypeSingle?me(d.valueAsTypeSingle,u,r):[],...d.valueAsTypeList&&Array.isArray(d.valueAsTypeList)?d.valueAsTypeList.flatMap(a=>me(a,u,r)):[],...d.parent?me(d.parent,u,r):[]]}function aS(d,u=new Set,r={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.Loop)throw new Error("Entity must be a loop to be flattened");return[d,...(d.inputs||[]).flatMap(a=>me(a,u,r)),...(d.outputs||[]).flatMap(a=>me(a,u,r)),...(d.successCalls||[]).flatMap(a=>me(a,u,r)),...(d.errorCalls||[]).flatMap(a=>me(a,u,r)),...d.error?me(d.error,u,r):[],...d.process?me(d.process,u,r):[],...d.body?me(d.body,u,r):[],...(Ms(d)||[]).flatMap(a=>me(a,u,r)),...d.parent?me(d.parent,u,r):[]]}function oS(d,u=new Set,r={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.Operation)throw new Error("Entity must be an operation to be flattened");return[d,...(d.successCalls||[]).flatMap(a=>me(a,u,r)),...(d.errorCalls||[]).flatMap(a=>me(a,u,r)),...(d.inputs||[]).flatMap(a=>me(a,u,r)),...(d.outputs||[]).flatMap(a=>me(a,u,r)),...d.error?me(d.error,u,r):[],...d.process?me(d.process,u,r):[],...(Ms(d)||[]).flatMap(a=>me(a,u,r)),...d.parent?me(d.parent,u,r):[]]}function lS(d,u=new Set,r={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.OutputMap)throw new Error("Entity must be an output map to be flattened");return[d,...(d.writesValues||[]).flatMap(a=>me(a,u,r)),...d.declaration?me(d.declaration,u,r):[],...d.defaultValue?me(d.defaultValue,u,r):[],...d.parent?me(d.parent,u,r):[]]}function dS(d,u=new Set,r={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.PrimitiveEntity)throw new Error("Entity must be a primitive entity to be flattened");return[d,...(d.properties||[]).flatMap(a=>me(a,u,r)),...(d.methods||[]).flatMap(a=>me(a,u,r)),...(d.abstractMethods||[]).flatMap(a=>me(a,u,r))]}function uS(d,u=new Set,r={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.Project)throw new Error("Entity must be a project to be flattened");return[d,...(d.entities||[]).flatMap(a=>me(a,u,r)),...(d.functions||[]).flatMap(a=>me(a,u,r)),...(d.events||[]).flatMap(a=>me(a,u,r)),...(d.projects||[]).flatMap(a=>me(a,u,r)),...(d.variableDeclarations||[]).flatMap(a=>me(a,u,r)),...(d.variableInstances||[]).flatMap(a=>me(a,u,r)),...(d.operations||[]).flatMap(a=>me(a,u,r)),...(d.conditions||[]).flatMap(a=>me(a,u,r)),...(d.functionCalls||[]).flatMap(a=>me(a,u,r)),...(d.projects||[]).flatMap(a=>me(a,u,r)),...(d.loops||[]).flatMap(a=>me(a,u,r)),...(d.searches||[]).flatMap(a=>me(a,u,r))]}function cS(d,u=new Set,r={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.Property)throw new Error("Entity must be a property to be flattened");return[d,...d.defaultValue?me(d.defaultValue,u,r):[],...d.dataType?me(d.dataType,u,r):[],...d.parent?me(d.parent,u,r):[]]}function pS(d,u=new Set,r={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.ReturnDeclaration)throw new Error("Entity must be a return declaration to be flattened");return[d,...d.readsValue?me(d.readsValue,u,r):[],...d.defaultValue?me(d.defaultValue,u,r):[],...d.dataType?me(d.dataType,u,r):[],...d.parent?me(d.parent,u,r):[]]}function fS(d,u=new Set,r={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.ReturnStatement)throw new Error("Entity must be a return statement to be flattened");return[d,...(d.outputs||[]).flatMap(a=>me(a,u,r)),...d.throws?me(d.throws,u,r):[],...(Ms(d)||[]).flatMap(a=>me(a,u,r)),...d.parent?me(d.parent,u,r):[]]}function hS(d,u=new Set,r={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.Search)throw new Error("Entity must be a search to be flattened");return[d,...(d.successCalls||[]).flatMap(a=>me(a,u,r)),...(d.errorCalls||[]).flatMap(a=>me(a,u,r)),...(d.inputsDeclarations||[]).flatMap(a=>me(a,u,r)),...(d.inputs||[]).flatMap(a=>me(a,u,r)),...(d.outputsDeclarations||[]).flatMap(a=>me(a,u,r)),...(d.outputs||[]).flatMap(a=>me(a,u,r)),...d.error?me(d.error,u,r):[],...(Ms(d)||[]).flatMap(a=>me(a,u,r)),...d.parent?me(d.parent,u,r):[]]}function yS(d,u=new Set,r={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.ValueDescriptor)throw new Error("Entity must be a value descriptor to be flattened");return[d,...d.defaultValue?me(d.defaultValue,u,r):[],...d.dataType?me(d.dataType,u,r):[],...d.parent?me(d.parent,u,r):[]]}function mS(d,u=new Set,r={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.VariableDeclaration)throw new Error("Entity must be a variable declaration to be flattened");return[d,...(d.successCalls||[]).flatMap(a=>me(a,u,r)),...(d.errorCalls||[]).flatMap(a=>me(a,u,r)),...(d.inputs||[]).flatMap(a=>me(a,u,r)),...(d.outputs||[]).flatMap(a=>me(a,u,r)),...(d.internalCalls||[]).flatMap(a=>me(a,u,r)),...(d.writesValues||[]).flatMap(a=>me(a,u,r)),...d.readsValue?me(d.readsValue,u,r):[],...d.defaultValue?me(d.defaultValue,u,r):[],...(Ms(d)||[]).flatMap(a=>me(a,u,r)),...d.dataType?me(d.dataType,u,r):[],...d.parent?me(d.parent,u,r):[]]}function vS(d,u=new Set,r={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.VariableInstance)throw new Error("Entity must be a variable instance to be flattened");return[d,...(d.successCalls||[]).flatMap(a=>me(a,u,r)),...(d.errorCalls||[]).flatMap(a=>me(a,u,r)),...(d.inputs||[]).flatMap(a=>me(a,u,r)),...(d.outputs||[]).flatMap(a=>me(a,u,r)),...(d.internalCalls||[]).flatMap(a=>me(a,u,r)),...(d.writesValues||[]).flatMap(a=>me(a,u,r)),...d.readsValue?me(d.readsValue,u,r):[],...d.defaultValue?me(d.defaultValue,u,r):[],...(Ms(d)||[]).flatMap(a=>me(a,u,r)),...d.declaration?me(d.declaration,u,r):[],...d.parent?me(d.parent,u,r):[]]}function zs(){const d=new Set,u=KL.flatMap(r=>me(r,d)).map(r=>r.id);if(!u.includes("http-request-error-return-delaration-id"))throw new Error("Built-in base entities must be included in the list");return u}function me(d,u=new Set,r={ignoreBuiltInBaseEntities:!1}){if(!d)throw new Error("Entity must be defined to be flattened");if(d.type===f.GenericReference)return[];if(r.ignoreBuiltInBaseEntities&&(Zi.includes(d.type)||zs().includes(d.id)))return[];if(u.has(d.id))return[];switch(d.type){case f.FunctionCall:return Q5(d,u,r);case f.Operation:return oS(d,u,r);case f.Condition:return W5(d,u,r);case f.Loop:return aS(d,u,r);case f.Search:return hS(d,u,r);case f.GlobalEvent:return tS(d,u,r);case f.ReturnStatement:return fS(d,u,r);case f.ContinueStatement:return Y5(d,u,r);case f.BreakStatement:return H5(d,u,r);case f.VariableDeclaration:return mS(d,u,r);case f.DefinitionEntity:return z5(d,u,r);case f.FunctionDeclaration:return eS(d,u,r);case f.Project:return uS(d,u,r);case f.ActionDescriptor:return q5(d,u,r);case f.ArgumentDeclaration:return Z5(d,u,r);case f.ReturnDeclaration:return pS(d,u,r);case f.ValueDescriptor:return yS(d,u,r);case f.InputMap:return rS(d,u,r);case f.OutputMap:return lS(d,u,r);case f.DataType:return X5(d,u,r);case f.InstalledProject:return iS(d,u,r);case f.InternalCall:return sS(d,u,r);case f.LiteralValue:return nS(d,u,r);case f.Property:return cS(d,u,r);case f.VariableInstance:return vS(d,u,r);case f.BuiltInBaseEntity:return r.ignoreBuiltInBaseEntities?[]:J5(d,u,r);case f.PrimitiveEntity:return r.ignoreBuiltInBaseEntities?[]:dS(d,u,r)}return[]}function hb(d){return d.type===f.FunctionCall||d.type===f.InternalCall||[f.Operation,f.Condition,f.Loop].includes(d.type)?d.declaration.inputs:d.type===f.FunctionDeclaration||jo.includes(d.type)?d.inputs:d.type===f.Search?d.inputsDeclarations:[]}function TIe(d,u){return u.type===f.Condition?u.inputs.find(r=>r.declaration.id===d.id):u.type===f.FunctionCall||u.type===f.Operation?u.inputs.find(r=>r.declaration.id===d.id):null}function ES(d){return sr.includes(d.type)?d.inputs:[]}function TS(d){var u;return d.type===f.FunctionCall?((u=d.declaration.returnStatements[0])==null?void 0:u.outputs)||[]:[f.Operation,f.Condition,f.Loop].includes(d.type)?d.declaration.outputs:d.type===f.Search?d.outputsDeclarations:hr.includes(d.type)?d.outputs:[]}function IIe(d,u){return u.type===f.Condition?null:(u.type===f.FunctionCall||u.type===f.Operation)&&u.outputs.find(r=>{var a;return((a=r.declaration)==null?void 0:a.id)===d.id})||null}function AIe(d){return d.type===f.Condition?[]:sr.includes(d.type)?d.outputs:[]}function gm(d){const u=d.readsValue;return u?fr(u):null}function IS(d,u){const r=d.readsValue;return r?Sd(r,u):null}function AS(d){const u=d.internalCalls||[];return R(La(R(u.flatMap(r=>[...r.successCalls,...r.errorCalls]))))}function bS(d){const u=d.internalCalls||[];return R(R(u.flatMap(r=>[...r.successCalls,...r.errorCalls])))}function qd(d){const u=wm(d),r=[];return u.forEach(a=>{if(Tt.includes(a.type))r.push(a);else if(un.includes(a.type)){const o=fr(a.parent);r.push(o)}}),r}function Zd(d){const u=wm(d),r=[];return u.forEach(a=>{if(Tt.includes(a.type))r.push(a);else if(un.includes(a.type)){const o=a.parent;r.push(o)}}),r}function R(d){const u=new Set;return d.filter(r=>!r||u.has(r.id)?!1:(u.add(r.id),!0))}function wS(d){return d.type===f.Project?null:$v.includes(d.type)?d:Zi.includes(d.type)?null:d.parent?wS(d.parent):null}function bn(d,u=!1){const r=[];if(d.type===f.Project&&r.push(...(d==null?void 0:d.entities)||[],...(d==null?void 0:d.functions)||[],...(d==null?void 0:d.variableDeclarations)||[],...(d==null?void 0:d.variableInstances)||[],...(d==null?void 0:d.searches)||[],...(d==null?void 0:d.loops)||[],...(d==null?void 0:d.operations)||[],...(d==null?void 0:d.conditions)||[],...(d==null?void 0:d.functionCalls)||[],...(d==null?void 0:d.events)||[],...(d==null?void 0:d.projects)||[]),Nr.includes(d.type)&&r.push(...(d==null?void 0:d.detachedChildren)||[]),d.type===f.DefinitionEntity){const a=[...d.suggestedMethods,...d.methods].flatMap(o=>o.collapsed&&u?[]:bn(o));r.push(...a)}if(d.type===f.Condition){const a=d.successCalls.map(p=>fr(p)),o=d.errorCalls.map(p=>fr(p));r.push(...a,...o)}if(jo.includes(d.type)){if(d.collapsed&&u)return[];const a=d.inputs.map(p=>qd(p)).flat(),o=d.calls.map(p=>fr(p));r.push(...R(a),...o)}if(sr.includes(d.type)&&d.type!==f.Condition&&d.type!==f.Loop){const a=d==null?void 0:d.outputs.map(e=>qd(e)).flat(),o=d.successCalls.map(e=>fr(e)),p=d.errorCalls.map(e=>fr(e));r.push(...R(a),...o,...p)}if(Tt.includes(d.type)){const a=qd(d),o=AS(d);r.push(...a,...o)}if(d.type===f.Loop){const a=d.outputs.map(e=>qd(e)).flat();if(d.body){const e=bn(d.body,u);r.push(...e)}const o=d.errorCalls.map(e=>fr(e)),p=d.successCalls.map(e=>fr(e));r.push(...R(a),...p,...o)}if(d.type===f.FunctionDeclaration){if(d.collapsed&&u)return[];const a=d.inputs.map(p=>qd(p)).flat(),o=d.calls.map(p=>fr(p));r.push(...R(a),...o)}return R(r)}function _m(d,u=!1){const r=[];if(d.type===f.Project&&r.push(...(d==null?void 0:d.variableDeclarations)||[],...(d==null?void 0:d.variableInstances)||[],...(d==null?void 0:d.searches)||[],...(d==null?void 0:d.loops)||[],...(d==null?void 0:d.operations)||[],...(d==null?void 0:d.conditions)||[],...(d==null?void 0:d.functionCalls)||[]),Nr.includes(d.type)&&r.push(...(d==null?void 0:d.detachedChildren)||[]),d.type===f.DefinitionEntity){const a=[...d.suggestedMethods,...d.methods].flatMap(o=>o.collapsed&&u?[]:_m(o));r.push(...a)}if(d.type===f.Condition){const a=d.successCalls,o=d.errorCalls;r.push(...a,...o)}if(jo.includes(d.type)){if(d.collapsed&&u)return[];const a=d.inputs.map(p=>Zd(p)).flat(),o=d.calls;r.push(...R(a),...o)}if(sr.includes(d.type)&&d.type!==f.Condition&&d.type!==f.Loop){const a=d==null?void 0:d.outputs.map(e=>Zd(e)).flat(),o=d.successCalls,p=d.errorCalls;r.push(...R(a),...o,...p)}if(Tt.includes(d.type)){const a=Zd(d),o=bS(d);r.push(...a,...o)}if(d.type===f.Loop){const a=d.outputs.map(e=>Zd(e)).flat();if(d.body){const e=_m(d.body,u);r.push(...e)}const o=d.errorCalls,p=d.successCalls;r.push(...R(a),...p,...o)}if(d.type===f.FunctionDeclaration){if(d.collapsed&&u)return[];const a=d.inputs.map(p=>Zd(p)).flat(),o=d.calls;r.push(...R(a),...o)}return R(r)}function Dm(d,u=!1){const r=bn(d,u),a=[...r,...r.reduce((o,p)=>[...o,...Dm(p,u)],[])];return R(a)}function RS(d,u=!1){const r=_m(d,u),a=[...r,...r.reduce((o,p)=>[...o,...RS(p,u)],[])];return R(a)}function gS(d){const u=Ao(d),r=[...u,...u.reduce((a,o)=>[...a,...gS(o)],[])];return R(r)}function zp(d){return d.implements.reduce((u,r)=>r.type===f.DefinitionEntity?[...u,f.DefinitionEntity,...zp(r),...Xp(r)]:[...u,r.name],[])}function Xp(d){return d.extends?d.extends.type===f.DefinitionEntity?[f.DefinitionEntity,...Xp(d.extends),...zp(d.extends)]:[d.extends.name]:[]}function yb(d){return d.extends?d.extends.type===f.DefinitionEntity?[d.extends,...yb(d.extends),...mb(d.extends)]:[d.extends]:[]}function mb(d){return d.implements.reduce((u,r)=>r.type===f.DefinitionEntity?[...u,r,...mb(r),...yb(r)]:[...u,r],[])}function Hd(d){return[...Xp(d),...zp(d)].filter((r,a,o)=>o.indexOf(r)===a)}function vb(d){return d.implements.length===0&&!d.extends?null:d.implements.find(a=>a.type===f.BuiltInBaseEntity&&a.name===Le.PERSISTED_ENTITY)?d:[...d.implements,...d.extends?[d.extends]:[]].reduce((a,o)=>{if(o.type===f.DefinitionEntity){const p=vb(o);if(p)return p}return a},null)}function bIe(d){return d.extends&&d.extends.type===f.BuiltInBaseEntity?d.extends:null}function wIe(d){const u=d.implements.find(r=>r.type===f.BuiltInBaseEntity);return u&&u.type===f.BuiltInBaseEntity?u:null}function Om(d){return d.extends&&d.extends.type===f.DefinitionEntity?d.extends:null}function Vi(d){if(d.type===f.BuiltInBaseEntity)return[d];const u=[...d.implements,...d.extends?[d.extends]:[]].reduce((r,a)=>a.type===f.BuiltInBaseEntity?[...r,a]:a.type===f.DefinitionEntity?[...r,...Vi(a)]:r,[]);return R(u)}function Qp(d){return d.type===f.PrimitiveEntity?!0:d.type===f.BuiltInBaseEntity?d.interactive:!Vi(d).find(a=>!a.interactive)}function RIe(d){return d.parent===d.project&&d.project.variableDeclarations.includes(d)}function Eb(d){return d.parent!==d.project?!1:f.VariableDeclaration===d.type?d.project.variableDeclarations.includes(d):f.VariableInstance===d.type?d.project.variableInstances.includes(d):f.FunctionCall===d.type?d.project.functionCalls.includes(d):f.Condition===d.type?d.project.conditions.includes(d):f.Operation===d.type?d.project.operations.includes(d):f.Loop===d.type?d.project.loops.includes(d):f.Search===d.type?d.project.searches.includes(d):!1}function _S(d){if([...Dt,f.DefinitionEntity,f.InstalledProject,f.Project].includes(d.type)||Eb(d))return!1;const u=Ao(d);return u.length===0?!0:u.some(r=>_S(r))}function Tb(d){return[...Dt,f.DefinitionEntity,f.InstalledProject,f.Project].includes(d.type)||Eb(d)?!1:Ao(d).length===0}function DS(d,u=0){if(Tb(d)){const r=Ao(d);return r.length===0?d:r.map(o=>DS(o,u+1)).reduce((o,p)=>o?p&&p.x<o.x?p:o:p,null)}return null}function OS(d){const u=[];if(Tb(d))u.push(d);else return[];return Ao(d).forEach(a=>{u.push(...OS(a))}),u}function Ib(d){return d.type===f.FunctionDeclaration&&d.parent!==d.project&&!![f.DefinitionEntity,f.Loop,f.InstalledProject].includes(d.parent.type)}function gIe(d,u){const r=new Map;return d.forEach(a=>{r.set(a.id,a)}),u.forEach(a=>{r.set(a.id,a)}),Array.from(r.values())}function ef(d){switch(d){case f.DefinitionEntity:return Qn;case f.FunctionDeclaration:return Qa;case f.VariableDeclaration:return oo;case f.VariableInstance:return ao;case f.FunctionCall:return To;case f.Operation:return eo;case f.Condition:return io;case f.ReturnStatement:return to;case f.Loop:return Gi;case f.Search:return lo;case f.InputMap:return Wn;case f.OutputMap:return In;case f.ArgumentDeclaration:return kn;case f.ReturnDeclaration:return Qi;case f.Property:return Xn;case f.InstalledProject:return uo;case f.Project:return N;case f.DataType:return fs;case f.GlobalEvent:return ro;case f.InternalCall:return co;case f.ValueDescriptor:return An;case f.BuiltInBaseEntity:return ea;case f.PrimitiveEntity:return ts;case f.ActionDescriptor:return ct;case f.LiteralValue:return Ki;case f.ContinueStatement:return Pi;case f.BreakStatement:return po;default:return null}}function Di(d,u,r=null){const a=d!=null&&d.parent?J(d==null?void 0:d.parent):null;let o=a?u.get(a):null,p=r||d;if((d==null?void 0:d.id)===(u==null?void 0:u.id))return u;if(d.type===f.ReturnStatement)return Hr(d,u,p);if(d.type===f.FunctionDeclaration&&(o==null?void 0:o.type)===f.Loop)return o;if(Dt.includes(d.type))return d;if(d.type===f.Loop)return p.id===d.id?o:d;if(Zi.includes(d.type))return null;const e=d.parent;if(!e)return null;if(e.type===f.GenericReference){const y=J(e);if(!y)return null;const v=u.get(y);return v?Di(v,u,p):null}else return e===u?u:Di(e,u,p)}function Hr(d,u,r=null){const a=d!=null&&d.parent?J(d==null?void 0:d.parent):null;let o=a?u.get(a):null,p=r||d;if(d.type===f.FunctionDeclaration&&(o==null?void 0:o.type)===f.Loop)return Hr(o.parent,u,p);if(Dt.includes(d.type))return d;if(Zi.includes(d.type))return null;const e=d.parent;if(!e)return null;if(e.type===f.GenericReference){const y=J(e);if(!y)return null;const v=u.get(y);return v?Hr(v,u,p):null}else return e===u?u:Hr(e,u,p)}function Jd(d,u){if(Zi.includes(d.type))return Me.warn(`getRootEntryPointScopeOwner is \`null\` because it was called with a built-in entity type: ${d.type}`),null;if(u.getBuiltIn(d.id))return Me.warn(`getRootEntryPointScopeOwner is \`null\` because it was called with a built-in entity: ${d.id}`),null;const r=qi(d.parent,u);return r?r===u?Nr.includes(d.type)?d:(Me.warn(`getRootEntryPointScopeOwner is \`null\` because it was called with an entity that has the project as parent: ${d.id}`),null):r.type===f.DefinitionEntity?d:Jd(r,u):(Me.warn(`getRootEntryPointScopeOwner is \`null\` because it was called with an entity that has no parent: ${d.id}`),null)}function Cm(d,u,r){if(d===u||u===r||d===r||!d||!u)return!1;const a=Di(u.parent,r);return a===r?!1:a===d?!0:Cm(a,u,r)}var $m=(d=>(d.SameBothLocal="same-both-local",d.AInB="a-in-b",d.BInA="b-in-a",d.ParallelInCommonParent="parallel-in-common-parent",d.ParallelInProject="parallel-in-project",d.AIsGlobalBIsNot="a-is-global-b-is-not",d.BIsGlobalAIsNot="b-is-global-a-is-not",d.SameBothGlobal="same-both-global",d))($m||{});function Xs(d,u,r){const a=Di(d,r),o=Di(u,r);if(!a)throw new Error("Could not find scope owner for the entity: "+d.id);if(!o)throw new Error("Could not find scope owner for the entity: "+u.id);if(a===o&&a.type!==f.Project)return{compatible:!0,type:"same-both-local",commonAncestorScope:a};if(a===o&&a.type===f.Project)return{compatible:!0,type:"same-both-global",commonAncestorScope:a};if(a.type===f.Project&&o.type!==f.Project)return{compatible:!1,type:"a-is-global-b-is-not",commonAncestorScope:a};if(a.type!==f.Project&&o.type===f.Project)return{compatible:!1,type:"b-is-global-a-is-not",commonAncestorScope:o};if(Cm(a,o,r))return{compatible:!0,type:"b-in-a",commonAncestorScope:a};if(Cm(o,a,r))return{compatible:!0,type:"a-in-b",commonAncestorScope:o};const y=fb(a,o);return y===r?{compatible:!1,type:"parallel-in-project",commonAncestorScope:y}:y?{compatible:!1,type:"parallel-in-common-parent",commonAncestorScope:Di(y,r)}:{compatible:!1,type:"parallel-in-project",commonAncestorScope:r}}function CS(d,u,r){const a=Xs(d,u,r);if(!a.compatible||a.type!=="same-both-local")return null;if(d===u)return d;let o=Di(d.parent,r);if(o){if(o===u)return u;if(o.type===f.Project)return d}else return d;for(;o;){if(o){if(o===u)return u;if(o.type===f.Project)return d}else return d;o=Di(o.parent,r)}let p=Di(u.parent,r);if(p){if(p===d)return d;if(p.type===f.Project)return u}else return u;for(;p;){if(p){if(p===d)return d;if(p.type===f.Project)return u}else return u;p=Di(p.parent,r)}return null}function $S(d){return d.length===0?null:d.length===1?d[0]:d.reduce((r,a)=>{const o=CS(r,a,a.project);return!o||o===a?r:a},d[0])}function qi(d,u){if(!d)return null;let r;return typeof d=="string"?r=d:d.type===f.GenericReference?r=J(d):r=d.id,r===u.id?u:u.get(r)}function bo(d){if(!d)return null;if(Zi.includes(d.type))return d;if(d.type===f.Project)return null;if(d.project.getBuiltIn(d.id))return d;const u=d.parent;return!u||u.type===f.Project?null:bo(u)}function tf(d){const u=[];function r(p,e){return u.some(y=>y.blockedByCaller===p&&y.blockedByCalling===e)}function a(p,e){r(p,e)||u.push({blockedByCaller:p,blockedByCalling:e})}const o=Jd(d,d.project);return o?(d.calledBySuccess.forEach(p=>{[...p.successCalls||[]].forEach(v=>{hr.includes(v.type)&&v!==d&&(dt(d).find(A=>A===v)||a(p,v))});let y;if(sr.includes(p.type)&&(y=p),y){const v=tf(y);v.reachable||dt(d).find(A=>A===p)||v.blocks.forEach(A=>{a(p,A.blockedByCalling)})}}),d.calledByError.forEach(p=>{[...p.errorCalls||[]].forEach(v=>{hr.includes(v.type)&&v!==d&&(dt(d).find(A=>A===v)||a(p,v))});let y;if(sr.includes(p.type)&&(y=p),y){const v=tf(y);v.reachable||dt(d).find(A=>A===p)||v.blocks.forEach(A=>{a(p,A.blockedByCalling)})}}),d.calledByEntry.forEach(p=>{if([...p.calls||[]].forEach(v=>{hr.includes(v.type)&&v!==d&&(dt(d).find(A=>A===v)||a(p,v))}),p===o)return;let y;if(p.type===f.FunctionDeclaration){const v=fr(p);if(v.type===f.DefinitionEntity)return;v.type===f.Loop&&(y=v)}if(y){const v=tf(y);v.reachable||v.blocks.forEach(E=>{a(p,E.blockedByCalling)})}}),{reachable:u.length===0,entryPoint:o,blocks:u}):{reachable:!0,entryPoint:null,blocks:[]}}function _Ie(d){return th.includes(d.type)?d.type===f.FunctionDeclaration?!Ib(d):!0:!1}function DIe(d){if(f.ActionDescriptor===d.type){if(d.project.operationDeclarations.find(p=>p.id===d.id))return f.Operation;if(d.project.globalEventActionDescriptors.find(p=>p.id===d.id))return f.GlobalEvent;if(d.project.loopDeclarations.find(p=>p.id===d.id))return f.Loop;if(d.project.conditionDeclarations.find(p=>p.id===d.id))return f.Condition}return d.type}function Pm(d,u){return d.type===f.BuiltInBaseEntity?d.name===u:!!Xp(d).includes(u)}function OIe(d,u){return d.type===f.BuiltInBaseEntity?d.name===u:!!zp(d).includes(u)}function es(d,u){return d.type===f.BuiltInBaseEntity?d.name===u:!!Hd(d).includes(u)}function CIe(d){const u=[];return d.entities.forEach(r=>{if(Pm(r,Le.PERSISTED_ENTITY)){u.push(r);return}}),R(u)}function $Ie(d){const u=[];return d.entities.forEach(r=>{if(Pm(r,Le.RELATIONAL_DATABASE)){u.push(r);return}}),R(u)}function PIe(d){return d.type!==f.DefinitionEntity||d.abstract||!Pm(d,Le.PERSISTED_ENTITY)?null:(d==null?void 0:d.properties.find(r=>{var a;return((a=r.implements)==null?void 0:a.id)===he[f.BuiltInBaseEntity][Le.PERSISTED_ENTITY].properties.primaryKey.id&&!r.abstract}))||null}function PS(d){var a;const u=vb(d);if(!u)return null;const r=u.properties.find(o=>{var p;return((p=o.implements)==null?void 0:p.id)===he[f.BuiltInBaseEntity][Le.PERSISTED_ENTITY].properties.database.id});return r?(a=r.getDefaultValue())==null?void 0:a.valueAsType:null}function Wd(d){if(d.type!==f.DefinitionEntity)return[];if(d.abstract)return[];if(!es(d,Le.PERSISTED_ENTITY))return[];const u=[],r=d.properties.filter(a=>{var o;return((o=a.implements)==null?void 0:o.id)!==he[f.BuiltInBaseEntity][Le.PERSISTED_ENTITY].properties.database.id&&!a.abstract});return u.push(...r),u}function NIe(d){var r;if(!d||d.type!==f.DefinitionEntity||!es(d,Le.PERSISTED_ENTITY))return null;const u=d.properties.find(a=>{var o;return((o=a.implements)==null?void 0:o.id)===he[f.BuiltInBaseEntity][Le.PERSISTED_ENTITY].properties.database.id});return(r=u==null?void 0:u.getDefaultValue())==null?void 0:r.valueAsTypeSingle}function Ur(d,u){var a;if(!t_.includes(u.type)||!d)return u.project||null;let r=u.project;return d.type===f.Project?r=d:((a=u.project)==null?void 0:a.id)!==d.project.id&&(r=d.project),r}function VIe(d){switch(d){case f.Project:return N;case f.InstalledProject:return uo;case f.DefinitionEntity:return Qn;case f.FunctionDeclaration:return Qa;case f.GlobalEvent:return ro;case f.VariableInstance:return ao;case f.VariableDeclaration:return oo;case f.InputMap:return Wn;case f.OutputMap:return In;case f.Condition:return io;case f.Operation:return eo;case f.FunctionCall:return To;case f.ReturnDeclaration:return Qi;case f.ArgumentDeclaration:return kn;case f.PrimitiveEntity:return ts;case f.DataType:return fs;case f.Property:return Xn;case f.ActionDescriptor:return ct;case f.ReturnStatement:return to;case f.ContinueStatement:return Pi;case f.BreakStatement:return po;case f.Loop:return Gi;case f.Search:return lo;case f.ValueDescriptor:return An;case f.InternalCall:return co;case f.LiteralValue:return Ki}return null}function LIe(d){const u={added:{},updated:{},removed:{},affected:[],seenEntities:[],self:d==null?void 0:d.self};return d==null||d.added.forEach(r=>{u.added[r.id]=r}),d==null||d.updated.forEach(r=>{u.updated[r.id]=r}),d==null||d.removed.forEach(r=>{u.removed[r.id]=r}),u.affected=Array.from(new Set(d==null?void 0:d.affected.map(r=>r.id))),u}function Lr(d,u){const r=ef(d.type);return r?!r.MUTABLE_META_PROPERTIES.every(o=>{const p=d[o],e=u[o];return e===void 0||p===e?!0:Array.isArray(p)&&Array.isArray(e)?p.length!==e.length?!1:p.every((y,v)=>y===e[v]):!1}):!1}function Nm(d,u={}){if(d.type===f.Project)return[];if(!d.parent)return[];const r=J(d.parent);if(!r)return[];const a=u[r];return a?[a.id,...Nm(a,u)]:[]}function MIe(d){const u=[],r=new Set;return[...d.listAdded,...d.listUpdated,...d.listAffected].forEach(a=>{const o=fr(a);!o||r.has(o.id)||(r.add(o.id),u.push(o))}),R(u)}function BIe(d){if(d.type===f.Condition)return null;if(d.type===f.Search)return d.project.getBuiltIn(he["value-descriptor"][Jl.SearchErrorOutputDescriptor].id)||null;if(d.type===f.Operation)return d.declaration.error;if(d.type===f.FunctionCall){const r=d.declaration.returnStatements.find(a=>!!a.throws);return(r==null?void 0:r.throws)||null}return null}function NS(d){const u=d.entities.filter(o=>!!o.implements.find(p=>p.id===he["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.id)),r=u.find(o=>{const p=o.properties.find(v=>v.implements&&v.implements.id===he["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.default.id),e=p==null?void 0:p.getDefaultValue();return(e==null?void 0:e.value)===!0});return r||u[0]||null}function Ab(d,u){const r=Array.from(new Set([...u.getAllBuiltInIds(),...zs()]));return!!(r.includes(d.id)||!Nm(d,{...u.instances,...u.builtInInstances}).every(p=>!r.includes(p)))}function VS(d){if(!d)return null;if(d.type===f.Project)return d.id;const u=d.parent;return u?VS(u):d.id}function rf(d){if(d.declaration&&d.declaration.type===f.Property){if(d.declaration.interactive){if(d.declaration.implements&&!d.declaration.implements.interactive)return!1;if(d.declaration.extends&&!d.declaration.extends.interactive)return!1}else return!1;if(d.declaration.private){const u=fr(d),r=Jd(u,d.project);if((r==null?void 0:r.type)===f.FunctionDeclaration&&(r==null?void 0:r.parent.type)===f.DefinitionEntity&&(r==null?void 0:r.parent.id)!==d.declaration.parent.id)return!1}}return!0}function bb(d){if(d.interactive){if(d.implements&&!d.implements.interactive)return!1;if(d.extends&&!d.extends.interactive)return!1}else return!1;if(d.private){const u=fr(d),r=Jd(u,d.project);if((r==null?void 0:r.type)===f.FunctionDeclaration&&(r==null?void 0:r.parent.type)===f.DefinitionEntity&&(r==null?void 0:r.parent.id)!==d.parent.id)return!1}return!0}function UIe(d,u,r){const a=u,o=r,p=!!r,e=[];return a.forEach(y=>{var v;if(p){const E=Xs(o,y,d);if(!E.compatible&&E.type!=="b-is-global-a-is-not")return;e.push(y)}else{if(((v=y.parent)==null?void 0:v.type)!==f.Project)return;e.push(y)}}),R(e)}function Vm(d){return d.replace(/["'`]/g,"")}function xr(d){const r=Vm(d).split(/[\s-]+/).filter(e=>e.length>0);if(r.length===0)return"";const a=r[0],o=a[0].toLowerCase()+a.slice(1),p=r.slice(1).map(e=>e[0].toUpperCase()+e.slice(1));return[o,...p].join("")}function Al(d){return Vm(d).split(/[\s-]+/).filter(a=>a.length>0).map(a=>a[0].toUpperCase()+a.slice(1)).join("")}function LS(d){const u=Vm(d).trim();if(!u)return"";const r=u.replace(/[\s_-]+/g," ").split(" ").filter(Boolean),a=[];for(const o of r){let p=o;p=p.replace(/([A-Z]+)([A-Z][a-z]+)/g,"$1-$2"),p=p.replace(/([a-z0-9])([A-Z][a-z0-9]*)/g,"$1-$2"),p=p.replace(/([0-9])([a-zA-Z]+)/g,"$1-$2"),p=p.replace(/([a-zA-Z])([0-9])/g,"$1-$2");for(const e of p.split("-"))e&&a.push(e)}return a.join("-")}function xIe(d){const u=Vm(d).trim();if(!u)return"";const r=u.replace(/[\s_-]+/g," ").split(" ").filter(Boolean),a=[];for(const o of r){let p=o;p=p.replace(/([A-Z]+)([A-Z][a-z]+)/g,"$1_$2"),p=p.replace(/([a-z0-9])([A-Z][a-z0-9]*)/g,"$1_$2"),p=p.replace(/([0-9])([a-zA-Z]+)/g,"$1_$2"),p=p.replace(/([a-zA-Z])([0-9])/g,"$1_$2");for(const e of p.split("_"))e&&a.push(e)}return a.join("_")}function Lm(d){return LS(d).toLowerCase()}function Yd(d){var r,a,o,p;if(!d)return"Any data type";let u="";if(d.interactiveEntities===!1?u+=` but only definition nodes ${d.asType?"as template ":""}that don't include non-interactive built-in functionality`:d.interactiveEntities===!0&&(u+=` but only definition nodes ${d.asType?"as template ":""}that extend or implement interactive built-in functionality`),d.staticEntities===!1?u?u+=" and that aren't a single global copy instance":u+=` but only definition nodes ${d.asType?"as template ":""}that aren't a single global copy instance`:d.staticEntities===!0&&(u?u+=" and that are a single global copy instance":u+=` but only definition nodes ${d.asType?"as template ":""}that are a single global copy instance`),d.actionEntities===!1?u?u+=" excluding executable/action nodes":u+=` excluding executable/action nodes ${d.asType?"templates ":""}`:d.actionEntities===!0&&(u?u+=" and not executable/action nodes":u+=" but not executable/action nodes"),d.entity&&(u=""),d.asType&&!u&&!((r=d.andChildrenGroup)!=null&&r.length)&&!((a=d.orChildrenGroup)!=null&&a.length)&&(u=" as template"),!d.entity){const e=d.isList;if(!((o=d.andChildrenGroup)!=null&&o.length)&&!((p=d.orChildrenGroup)!=null&&p.length))return e?`List of an any data type${u}`:`Any data type${u}`;let y="",v=!1,E=!1;return(d.andChildrenGroup||[]).forEach(w=>{const A=Yd(w),$=Rd(A);v&&(y+=" and "),w.isGroup?y+="("+$+")":v?y+=$:y+=A,v=!0,E=!0}),(d.orChildrenGroup||[]).forEach(w=>{const A=Yd(w),$=Rd(A);v&&(E&&(y+=","),y+=" or "),w.isGroup?y+="("+$+")":v?y+=$:y+=A,v=!0}),e?`List of ${Rd(y)}`:y}if(d.entity.type===f.PrimitiveEntity){let e=d.entity.name;switch(d.entity.name){case oe.String:e="Text";break;case oe.KeyValue:e="Data structure";break}return d.isList?`List of ${e}s${u}`:`${e.slice(0,1).toUpperCase()}${e.slice(1)}${u}`}else if(d.entity.type===f.DefinitionEntity){const e=Y(d.entity,d.project);return d.isList?`List of ${e} values${u}`:e.slice(0,1).toUpperCase()+e.slice(1)+u}else if(d.entity.type===f.BuiltInBaseEntity){const e=BS(d.entity);return d.isList?`List of ${e} values${u}`:e.slice(0,1).toUpperCase()+e.slice(1)+u}else if(d.entity.type===f.LiteralValue){if(d.entity.name===oe.Null)return"Empty value";if(d.entity.name===oe.Untyped)return"Untyped value";if(d.entity.name===oe.File)return"File";if(d.entity.name===oe.String)return`"${d.entity.value}" text`;if(d.entity.name===oe.Number)return`Number '${d.entity.value}'`;if(d.entity.name===oe.Boolean)return`${d.entity.value} value`;if(d.entity.name===oe.UUID)return`"${d.entity.value}" unique identifier`;if(d.entity.name===oe.Date)return`"${d.entity.value}" date`}return d.isList?`List of ${Y(d.entity,d.project)} values${u}`:`${Y(d.entity,d.project).slice(0,1).toUpperCase()+Y(d.entity,d.project).slice(1)} value${u}`}function jIe(d){if(!d)return"Any data type";const u=d.getDataType(null);return Yd(u)}function Mm(d){switch(d.declaration.id){case ut.Equal:return"is equal to";case ut.NotEqual:return"is not equal to";case ut.MoreThan:return"is greater than";case ut.MoreThanOrEqual:return"is greater than or equal to";case ut.LessThan:return"is less than";case ut.LessThanOrEqual:return"is less than or equal to";case Kr.And:return"and";case Kr.Or:return"or";case oi.Empty:return"is empty";case oi.NotEmpty:return"is present"}}function MS(d){return d.includes(Le.HTTP_ENDPOINT)?"HTTP endpoint":d.includes(Le.PERSISTED_ENTITY)?"Persisted entity":d.includes(Le.CRON_JOB)?"Scheduled execution":d.includes(Le.RELATIONAL_DATABASE)?"Relational database":"Entity"}function BS(d){switch(d.name){case Le.HTTP_ENDPOINT:return"HTTP endpoint";case Le.PERSISTED_ENTITY:return"Persisted entity";case Le.CRON_JOB:return"Scheduled execution";case Le.RELATIONAL_DATABASE:return"Relational database"}return"Entity"}function GIe(d){const u=Om(d);if(!u){const r=Hd(d);return r.includes(Le.HTTP_ENDPOINT)?"HTTP endpoint":r.includes(Le.PERSISTED_ENTITY)?"Persisted entity":r.includes(Le.CRON_JOB)?"Scheduled execution":r.includes(Le.RELATIONAL_DATABASE)?"Relational database":Y(d,d.project)+" entity"}return Y(u,d.project)+" entity"}function US(d){let u="Find ";return d.outputsDeclarations.forEach((r,a)=>{const o=Hy(r,null),p=Rd(o&&o.entity?Y(o.entity,d.project):"unstructured data");a===0?u+=`${p} `:a===d.outputsDeclarations.length-1?u+=`and ${p} `:u+=`, ${p} `}),u}function xS(d){switch(d.name){case oe.String:return"Text";case oe.Number:return"Number";case oe.Boolean:return"Boolean";case oe.KeyValue:return"Data structure";case oe.UUID:return"Unique identifier";case oe.Date:return"Date";case oe.EntityTemplate:return"Entity as template";case oe.Enum:return"Enumeration";case oe.File:return"File";case oe.Null:return"Empty";case oe.ActionDescriptor:return"Action descriptor";case oe.Untyped:return"Untyped";default:return d.name}}function jS(d){switch(d.id){case Je.List:return"Loop over list items";case Je.ManualFlow:return"Manual flow control loop";case Je.ObjectKeys:return"Loop over object keys";case Je.ObjectValues:return"Loop over object values";case Je.Counted:return"Loop given number of times";case Je.String:return"Loop over text characters";case Zt.Addition:return"Sum numbers";case Zt.Subtraction:return"Subtract numbers";case Zt.Multiplication:return"Multiply numbers";case Zt.Division:return"Divide numbers";case Zt.Remainder:return"Get remainder of numbers";case Zt.Exponentiation:return"Get exponent of numbers";case Ge.AddIndex:return"Add at index position";case Ge.DeleteFirst:return"Delete first character";case Ge.DeleteLast:return"Delete last character";case Ge.DeleteIndex:return"Delete at index position";case Ge.Join:return"Join texts";case Ge.ReplaceAllMatches:return"Replace all matches";case Ge.ReplaceFirst:return"Replace first match";case Ge.ReplaceLast:return"Replace last match";case Ge.Split:return"Split text";case Ge.ReplaceIndex:return"Replace at index position";case Ge.ReplaceSingleMatch:return"Replace single match";case Ge.GetFirst:return"Get first character";case Ge.GetLast:return"Get last character";case Ge.GetIndexItem:return"Get at index position";case Ge.GetIndexOf:return"Get the index number of the character";case Ge.Append:return"Add at the end";case Ge.Prepend:return"Add at the start";case tr.Wait:return"Wait";case tr.Parallel:return"Run in parallel";case tr.Sequential:return"Run in sequence";case yi.HttpRequest:return"HTTP request";case pr.CreateNewInstance:return"Create new copy of entity";case Fe.AddIndex:return"Add item at index position";case Fe.DeleteFirst:return"Delete first item";case Fe.DeleteLast:return"Delete last item";case Fe.DeleteIndex:return"Delete item at index position";case Fe.Join:return"Join lists";case Fe.ReplaceFirst:return"Replace first match";case Fe.ReplaceLast:return"Replace last match";case Fe.Split:return"Split list";case Fe.ReplaceIndex:return"Replace at index position";case Fe.GetFirst:return"Get first item";case Fe.GetLast:return"Get last item";case Fe.GetIndexItem:return"Get item at index position";case Fe.Append:return"Add item at the end";case Fe.Prepend:return"Add item at the start";case Ea.PROJECT_PUBLICATION_COMPLETED:return"Project publication completed";default:return(d.name.slice(0,1).toUpperCase()+d.name.slice(1)).replaceAll("-"," ")}}function Y(d,u){var r;if(f.FunctionDeclaration===d.type){const a=d.name;if(Object.values(Wr).includes(a))switch(a){case Wr.AbortExecution:return"Abort ongoing execution";case Wr.DeletePersistedEntity:return"Delete entry from database";case Wr.CreatePersistedEntity:return"Save new data entry in database";case Wr.UpdatePersistedEntity:return"Update entity data to database";default:return Ii(d.type).replaceAll("-"," ")}return a}if(f.BuiltInBaseEntity===d.type)return MS([d.name]);if(Qg.includes(d.type)&&d.type!==f.ActionDescriptor)return d.name;switch(d.type){case f.Search:return US(d);case f.GlobalEvent:return d.implements?Y(d.implements,u):Ii(d.type).replaceAll("-"," ");case f.Operation:case f.InternalCall:case f.Loop:const a=qi(d.declaration,u);return Y(a,u);case f.ActionDescriptor:return jS(d);case f.BreakStatement:const o=qi(d.parent,u);return`Stop loop ${Y(o,u)}`;case f.ContinueStatement:const p=qi(d.parent,u);return`Execute next iteration of ${Y(p,u)}`;case f.FunctionCall:return qi(d.declaration,u).name;case f.Condition:{const y=d;if(y.declaration.id===Kr.And)return"If all conditions are met";if(y.declaration.id===Kr.Or)return"If any condition is met";if((r=d.inputs)!=null&&r.length){const v=Y(y.inputs[0],y.project);if(y.inputs[1]){const E=y.inputs[1].declaration.name;return`If ${v} ${Mm(y)} ${E}`}return`If ${v} ${Mm(y)}`}else return`If ${Mm(y)}`}case f.ReturnStatement:{const y=qi(d.parent,u);return y?`Output of ${Y(y,u)}`:"Return statement"}case f.InputMap:if(d.declaration){const y=qi(d.declaration,u);return Y(y,u)||""}else{if(!d.name)throw new Error(`Input map entity with id "${d.id}" has no name and no declaration.`);return d.name||""}case f.VariableInstance:{const y=qi(d.declaration,u);return Y(y,u)||""}case f.OutputMap:if(d.declaration){const y=qi(d.declaration,u);return(y==null?void 0:y.name)||""}else return d.parentRelationType===Fa.Error?"Undeclared error":"";case f.PrimitiveEntity:case f.LiteralValue:return xS(d);default:return Ii(d.type).replaceAll("-"," ")}}function wb(d,u){const r=[];d.name||r.push(new ae({id:`${d.id}--${se.EmptyName}`,message:`Entity with id "${d.id}" and type "${d.type}" has an empty name. Please provide a 'name' string.`,severity:H.Error,code:se.EmptyName}));const a=u.entities.filter(o=>o.name===d.name);return a.length&&r.push(new ae({id:`${d.id}--${se.NameNotUniqueInScope}`,message:`Entity with id "${d.id}" and type "${d.type}" has a name "${d.name}" that is not unique in the project. Entity with id "${a[0].id}" has the same name.
396
+ You shouldn't have to manually update a 'parent' property. The equivalent result is to change its callers, the value writters of its inputs, or the value readers of its outputs.`})),{errors:a,modifiedData:r}}subscribeDependents(r){return r.forEach(a=>{this.detachedDependents[a.entity.id]||(this.detachedDependents[a.entity.id]=a)}),this}unsubscribeDependents(r){return r.forEach(a=>{this.detachedDependents[a.entity.id]&&delete this.detachedDependents[a.entity.id]}),this}syncDependents(r=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"sync-dependents"))){const a=[],o=[],p=[],e=[];return Object.values(this.detachedDependents).forEach(y=>{const v=y.entity.afterAllChildrenInitialized(r);a.push(...v.updated),o.push(...v.added),p.push(...v.removed),e.push(...v.affected)}),r==null||r.attemptAutoclose("sync-dependents",this.id),{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}onDetachedDependencyRemoved(r,a,o){const p=[],e=[],y=[],v=[];if(a==="declaration"){const{updated:E,added:w,removed:A}=this.remove({ignoreUpstream:!1},o);p.push(...E),e.push(...w),y.push(...A)}if(a==="parent"){const{updated:E,added:w,removed:A}=this.remove({ignoreUpstream:!1},o);p.push(...E),e.push(...w),y.push(...A)}return{updated:R(p),added:R(e),removed:R(y),affected:R(v),self:this}}onDetachedDependencyRestored(r,a,o){const p=[],e=[],y=[],v=[];if(a==="declaration"){const{updated:E,added:w,removed:A}=this.restore({},o);p.push(...E),e.push(...w),y.push(...A)}if(a==="parent"){const{updated:E,added:w,removed:A}=this.restore({},o);p.push(...E),e.push(...w),y.push(...A)}return{updated:R(p),added:R(e),removed:R(y),affected:R(v),self:this}}unsubscribeFromDependencies(){var r;return(r=this.parent)==null||r.unsubscribeDependents([{entity:this,field:"parent"}]),this.declaration.unsubscribeDependents([{entity:this,field:"declaration"}]),this}subscribeToDependencies(){var r;return(r=this.parent)==null||r.subscribeDependents([{entity:this,field:"parent"}]),this.declaration.subscribeDependents([{entity:this,field:"declaration"}]),this}increaseVersion(r){if(r&&!L(r).isValid())throw new Error(`The shared timestamp '${r}' is not a valid ISO 8601 date string.`);return r&&L(r).isSame(L(this.createdAt))?this:(this.previousVersion=this.version,this.version=N.UUID.uuid(),this.createdAt=L(r).toISOString()||L().toISOString(),this)}captureVersion(){var a;const r=((a=this.knownVersions)==null?void 0:a.get(this.version))||new Qt(this,this.project);return r.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,r):new Map([[this.version,r]]),r.inputs=[...this.inputs],r.outputs=[...this.outputs],r.error=this.error,r.successCalls=[...this.successCalls],r.errorCalls=[...this.errorCalls],r.process=this.process,r.declaration=this.declaration,r.calledBySuccess=[...this.calledBySuccess],r.calledByError=[...this.calledByError],r.calledByEntry=[...this.calledByEntry],r.parent=this.parent,this}recursiveCaptureUpstreamVersions(r){const a=[],o=[],p=[],e=[];if(this.parent){this.parent.increaseVersion(r);const y=this.parent.recursiveCaptureUpstreamVersions(r);a.push(this.parent,...y.updated),o.push(...y.added),p.push(...y.removed)}return{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}async restoreVersion(r){var v;const a=[],o=[],p=[],e=[];if(this.version===r)return{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this};if(!this.knownVersions){const E=new Map;for(const[w,A]of this.knownVersions||new Map){if(E.set(w,A),A.activeVersion=!1,A.knownVersions)for(const[$,V]of A.knownVersions)E.set($,V);A.knownVersions=null}}let y=(v=this.knownVersions)==null?void 0:v.get(r);if(!y){const E=await this.APILoadVersion({},r);if(!E)throw new Error(`Version with id '${r}' for entity with id '${this.id}' not found.`);y=new Qt(E,this.project)}return this.metaSync(y.toShallowJSON(),null),this.previousVersion=y.previousVersion,this.version=y.version,this.createdAt=y.createdAt,this.author=y.author,this.deleted=y.deleted,this.inputs=y.inputs,this.outputs=y.outputs,this.error=y.error,this.successCalls=y.successCalls,this.errorCalls=y.errorCalls,this.process=y.process,this.declaration=y.declaration,this.calledBySuccess=y.calledBySuccess,this.calledByError=y.calledByError,this.calledByEntry=y.calledByEntry,this.parent=y.parent,{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}updateWithShallowTransfer(r,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"update-with-shallow-transfer"))){if(this.metaSync(r,a),this.version=r.version,this.createdAt=r.createdAt,this.author=r.author,this.deleted=r.deleted,this.previousVersion=r.previousVersion,this.unsubscribeFromDependencies(),r.parent){const o=J(r.parent),p=this.project.get(o),e=this.parent;if(e&&e.id!==(p==null?void 0:p.id)&&this.removeFromParent(a),p)this.setParent(p,a);else throw a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${o}' that isn't found in the project`)}else throw a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(r.declaration){const o=J(r.declaration),p=this.project.get(o);p&&this.setDeclaration(p)}return r.calledByEntry.forEach(o=>{const p=J(o),e=this.project.get(p);e&&(this.addEntryCaller(e,a),e.addCall(this,a))}),[...this.calledByEntry].forEach(o=>{r.calledByEntry.find(e=>J(e)===o.id)||(this.removeCaller(o,a),o.removeCall(this,a))}),r.calledBySuccess.forEach(o=>{const p=J(o),e=this.project.get(p);e&&(this.addSuccessCaller(e,a),e.addSuccessCall(this,a))}),[...this.calledBySuccess].forEach(o=>{r.calledBySuccess.find(e=>J(e)===o.id)||(this.removeCaller(o,a),o.removeCall(this,a))}),r.calledByError.forEach(o=>{const p=J(o),e=this.project.get(p);e&&(this.addErrorCaller(e,a),e.addErrorCall(this,a))}),[...this.calledBySuccess].forEach(o=>{r.calledBySuccess.find(e=>J(e)===o.id)||(this.removeCaller(o,a),o.removeCall(this,a))}),this.captureVersion(),this.subscribeToDependencies(),a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),this}hydrateAncestors(){const r=[],a=[],o=[],p=[];if(this.initialData.parent){const e=J(this.initialData.parent),y=this.project.get(e);if(y)this.setParent(y,null),r.push(y);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${e}' that isn't found in the project`)}else throw new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(this.initialData.declaration){const e=J(this.initialData.declaration),y=this.project.get(e);y&&(this.setDeclaration(y),r.push(y))}return this.initialData.calledByEntry.forEach(e=>{const y=J(e),v=this.project.get(y);v&&this.addEntryCaller(v,null)}),this.initialData.calledBySuccess.forEach(e=>{const y=J(e),v=this.project.get(y);v&&this.addSuccessCaller(v,null)}),this.initialData.calledByError.forEach(e=>{const y=J(e),v=this.project.get(y);v&&this.addErrorCaller(v,null)}),{updated:R(r),added:R(a),removed:R(o),affected:R(p),self:this}}afterAllChildrenInitialized(r=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"after-all-children-initialized"))){const a=[],o=[],p=[],e=[];this.initialized=!0;const{updated:y,added:v,removed:E}=this.syncInputs(r),{updated:w,added:A,removed:$}=this.syncOutputs(r);return a.push(...y,...w),o.push(...v,...A),p.push(...E,...$),this.captureVersion(),r==null||r.attemptAutoclose("after-all-children-initialized",this.id),{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}addSelfToProject(r=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-self-to-project"))){var y;const a=[this],o=[],p=[],e=[];return this.parent===this.project&&this.project.addFunctionCall(this),(y=this.process)==null||y.writesValues.forEach(v=>{v.setValueWriter(this.process,r),a.push(v)}),this.successCalls.forEach(v=>{v.addSuccessCaller(this,r),a.push(v)}),this.errorCalls.forEach(v=>{v.addErrorCaller(this,r),a.push(v)}),this.calledBySuccess.forEach(v=>{v.addSuccessCall(this,r),a.push(v)}),this.calledByError.forEach(v=>{v.addErrorCall(this,r),a.push(v)}),this.calledByEntry.forEach(v=>{v.addCall(this,r),a.push(v)}),this.subscribe(),this.subscribeToDependencies(),r==null||r.attemptAutoclose("add-self-to-project",this.id),{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}removeInput(r,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-input"))){const o=this.inputs.findIndex(p=>p.id===r.id);return o>-1&&(this.inputs.splice(o,1),a&&(a==null||a.add(this,S.Affected))),a==null||a.attemptAutoclose("remove-input",this.id),this}addInput(r,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-input"))){return this.inputs.includes(r)?(a==null||a.attemptAutoclose("add-input",this.id),this):(this.inputs.push(r),a==null||a.add(this,S.Affected),a==null||a.attemptAutoclose("add-input",this.id),this)}addOutput(r,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-output"))){return this.outputs.includes(r)?(a==null||a.attemptAutoclose("add-output",this.id),this):(this.outputs.push(r),a==null||a.add(this,S.Affected),a==null||a.attemptAutoclose("add-output",this.id),this)}removeOutput(r,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-output"))){const o=this.outputs.findIndex(p=>p.id===r.id);return o>-1&&(this.outputs.splice(o,1),a&&(a==null||a.add(this,S.Affected))),a==null||a.attemptAutoclose("remove-output",this.id),this}addValueReader(r,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-value-reader"))){var o;return this.process&&!this.process.writesValues.includes(r)&&((o=this.process)==null||o.addValueReader(r,a),a==null||a.add(this,S.Affected)),a==null||a.attemptAutoclose("add-value-reader",this.id),this}removeValueReader(r,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-value-reader"))){var o;return this.process&&this.process.writesValues.includes(r)&&((o=this.process)==null||o.removeValueReader(r,a),a==null||a.add(this,S.Affected)),a==null||a.attemptAutoclose("remove-value-reader",this.id),this}addSuccessCaller(r,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-success-caller")),o=!1){return this.calledBySuccess.find(p=>p.id===r.id)||(this.calledBySuccess.push(r),a==null||a.add(this,S.Updated),o&&He(this,a)),a==null||a.attemptAutoclose("add-success-caller",this.id),this}addErrorCaller(r,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-error-caller")),o=!1){return this.calledByError.find(p=>p.id===r.id)||(this.calledByError.push(r),a==null||a.add(this,S.Updated),o&&He(this,a)),a==null||a.attemptAutoclose("add-error-caller",this.id),this}addEntryCaller(r,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-entry-caller")),o=!1){return this.calledByEntry.find(p=>p.id===r.id)||(this.calledByEntry.push(r),a==null||a.add(this,S.Updated),o&&He(this,a)),a==null||a.attemptAutoclose("add-entry-caller",this.id),this}addErrorCall(r,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-error-call")),o=!1){return this.errorCalls.find(p=>p.id===r.id)||(this.errorCalls.push(r),o&&He(this,a),a==null||a.add(this,S.Affected)),a==null||a.attemptAutoclose("add-error-call",this.id),this}addSuccessCall(r,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-success-call")),o=!1){return this.successCalls.find(p=>p.id===r.id)||(this.successCalls.push(r),o&&He(this,a),a==null||a.add(this,S.Affected)),a==null||a.attemptAutoclose("add-success-call",this.id),this}removeCall(r,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-call")),o=!1){const p=this.successCalls.findIndex(y=>y.id===r.id);p>-1&&(this.successCalls.splice(p,1),a==null||a.add(this,S.Affected));const e=this.errorCalls.findIndex(y=>y.id===r.id);return e>-1&&(this.errorCalls.splice(e,1),a==null||a.add(this,S.Affected)),o&&He(this,a),a==null||a.attemptAutoclose("remove-call",this.id),this}removeCaller(r,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-caller")),o=!1){return this.calledBySuccess=this.calledBySuccess.filter(p=>p.id!==r.id?!0:(a==null||a.add(this,S.Updated),a==null||a.add(p,S.Affected),!1)),this.calledByError=this.calledByError.filter(p=>p.id!==r.id?!0:(a==null||a.add(this,S.Updated),a==null||a.add(p,S.Affected),!1)),this.calledByEntry=this.calledByEntry.filter(p=>p.id!==r.id?!0:(a==null||a.add(this,S.Updated),a==null||a.add(p,S.Affected),!1)),o&&He(this,a),a==null||a.attemptAutoclose("remove-caller",this.id),this}setParent(r,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"set-parent"))){var o;return((o=this.parent)==null?void 0:o.id)!==(r==null?void 0:r.id)&&(this.parent=r,a&&(a==null||a.add(this,S.Updated))),a==null||a.attemptAutoclose("set-parent",this.id),this}setDeclaration(r){return this.declaration=r,this}initChildren(r=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"init-children"))){if(this.initialized||this.startedInitialization)return this;if(this.startedInitialization=!0,this.initialData.declaration.type===f.FunctionDeclaration){const a=ne(this.initialData.declaration,this.project);this.declaration=a}else{const a=J(this.initialData.declaration),o=this.project.get(a);this.declaration=o}return this.successCalls=this.initialData.successCalls.map(a=>{const o=ne(a,this.project);if(o.addSuccessCaller(this),[f.BreakStatement,f.ContinueStatement].includes(o.type))o.setParent(this.parent.parent,null),o.initChildren(r);else if(o.type===f.ReturnStatement){const p=Hr(this,this.project);o.setParent(p,null),o.initChildren(r)}else o.type!==f.InternalCall&&(o.setParent(this.parent,null),o.initChildren(r));return o}),this.errorCalls=this.initialData.errorCalls.map(a=>{const o=ne(a,this.project);if(o.addErrorCaller(this),[f.BreakStatement,f.ContinueStatement].includes(o.type))o.setParent(this.parent.parent,null),o.initChildren(r);else if(o.type===f.ReturnStatement){const p=Hr(this,this.project);o.setParent(p,null),o.initChildren(r)}else o.type!==f.InternalCall&&(o.setParent(this.parent,null),o.initChildren(r));return o}),this.inputs=this.initialData.inputs.map(a=>{const o=ne(a,this.project);return o.setParent(this,null),o.initChildren(r),o}),this.initialData.process&&(this.process=ne(this.initialData.process,this.project),this.process.setParent(this,null),this.process.initChildren(r)),this.initialData.error&&(this.error=ne(this.initialData.error,this.project),this.error.setParent(this,null),this.error.initChildren(r)),this.subscribeToDependencies(),this.afterAllChildrenInitialized(r),r==null||r.attemptAutoclose("init-children",this.id),this}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(r,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"meta-sync"))){const o=Lr(this,r),p=this.toMeta();return this.x=r.x||p.x,this.y=r.y||p.y,this.catchesError=r.catchesError!==void 0?r.catchesError:this.catchesError,super.metaSync(r),r.deleted===!0&&!p.deleted?a==null||a.add(this,S.Removed):r.deleted===!1&&p.deleted?a==null||a.add(this,S.Added):o&&(a==null||a.add(this,S.Updated)),a==null||a.attemptAutoclose("meta-sync",this.id),this}async APILoad(r=ve,...a){return await Qt.repository.APILoad(this.id,...a),this}async APICreate(r=ve,...a){return await Qt.repository.APICreate(this.toShallowJSON(),...a),this}async APIUpdate(r=ve,...a){return await Qt.repository.APIUpdate(this.toShallowJSON(),...a),this}async APIDelete(r=ve,...a){return await Qt.repository.APIDelete(this.toShallowJSON(),...a),this}async APIClone(r=ve,...a){return await Qt.repository.APIClone(this.id,...a),this}async APILoadVersion(r=ve,a,...o){return await Qt.repository.APILoadVersion(this.id,a,...o)}removeFromParent(r=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-from-parent"))){const a=[],o=[],p=[],e=[];return this.parent.type===f.Project?(this.parent.removeFunctionCall(this),e.push(this.parent)):this.parent.detachedChildren.includes(this)&&this.parent.unsubscribeDetachedChild(this),r==null||r.attemptAutoclose("remove-from-parent",this.id),{added:R(p),updated:R(a),removed:R(o),affected:R(e),self:this}}remove({ignoreUpstream:r}={ignoreUpstream:!1},a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-entity"))){var v;const o=[],p=[],e=[],y=[];if(a!=null&&a.hasRemoved(this.id))return a==null||a.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(p.push(this),this.unsubscribe(),this.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},a),Object.values(this.detachedDependents).forEach(E=>{const{updated:w,removed:A,added:$}=E.entity.onDetachedDependencyRemoved(this,E.field,a);o.push(...w),p.push(...A),e.push(...$)}),this.process){const{updated:E,removed:w}=(v=this.process)==null?void 0:v.remove({ignoreUpstream:!0},a);o.push(...E),p.push(...w)}if(this.inputs.forEach(E=>{const{updated:w,removed:A}=E.remove({ignoreUpstream:!0},a);o.push(...w),p.push(...A)}),this.outputs.forEach(E=>{const{updated:w,removed:A}=E.remove({ignoreUpstream:!0},a);o.push(...w),p.push(...A)}),this.error){const{updated:E,removed:w}=this.error.remove({ignoreUpstream:!0},a);o.push(...E),p.push(...w)}if(this.successCalls.forEach(E=>{o.push(E),E.removeCaller(this,a)}),this.errorCalls.forEach(E=>{o.push(E),E.removeCaller(this,a)}),!r){const E=this.removeFromParent(a);e.push(...E.added),o.push(...E.updated),p.push(...E.removed),y.push(...E.affected),this.calledBy.forEach(w=>{o.push(w),w.removeCall(this,a)})}return a==null||a.attemptAutoclose("remove-entity",this.id),{added:R(e),updated:R(o),removed:R(p),affected:R(y),self:this}}restore({}={},r=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"restore-entity"))){const a=[],o=[],p=[],e=[];if(r!=null&&r.hasAdded(this.id))return r==null||r.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},r),Object.values(this.detachedDependents).forEach(y=>{const{updated:v,removed:E,added:w}=y.entity.onDetachedDependencyRestored(this,y.field,r);o.push(...v),p.push(...E),a.push(...w)}),this.process){const{updated:y}=this.process.restore({},r);o.push(...y)}return this.inputs.forEach(y=>{const{updated:v}=y.restore({},r);o.push(...v)}),this.outputs.forEach(y=>{const{updated:v}=y.restore({},r);o.push(...v)}),this.successCalls.forEach(y=>{o.push(y),y.addSuccessCaller(this,r)}),this.errorCalls.forEach(y=>{o.push(y),y.addErrorCaller(this,r)}),this.calledBySuccess.forEach(y=>{o.push(y),y.addSuccessCall(this,r)}),this.calledByError.forEach(y=>{o.push(y),y.addErrorCall(this,r)}),this.calledByEntry.forEach(y=>{o.push(y),y.addCall(this,r)}),r==null||r.attemptAutoclose("restore-entity",this.id),{added:R(a),updated:R(o),removed:R(p),affected:R(e),self:this}}toFlat(r=new Set){return r.has(this.id)?[]:(r.add(this.id),[this,...this.successCalls.flatMap(o=>o.toFlat(r)),...this.errorCalls.flatMap(o=>o.toFlat(r)),...this.inputs.flatMap(o=>o.toFlat(r)),...this.outputs.flatMap(o=>o.toFlat(r)),...this.process?this.process.toFlat(r):[],...this.error?this.error.toFlat(r):[],...this.calledBy.flatMap(o=>o.toFlat(r))])}toFlatIds(r=new Set){return r.has(this.id)?[]:(r.add(this.id),[this.id,...this.successCalls.flatMap(o=>o.toFlatIds(r)),...this.errorCalls.flatMap(o=>o.toFlatIds(r)),...this.inputs.flatMap(o=>o.toFlatIds(r)),...this.outputs.flatMap(o=>o.toFlatIds(r))])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,x:this.x,y:this.y,type:this.type,catchesError:this.catchesError}}toJSON(r=new Set){var a,o;return r.has(this.id)?this.toReference():(r.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,catchesError:this.catchesError,x:this.x,y:this.y,successCalls:this.successCalls.map(p=>p.toJSON(r)),errorCalls:this.errorCalls.map(p=>p.toJSON(r)),calledBySuccess:this.calledBySuccess.map(p=>p.toReference()),calledByError:this.calledByError.map(p=>p.toReference()),calledByEntry:this.calledByEntry.map(p=>p.toReference()),process:(a=this.process)==null?void 0:a.toJSON(r),declaration:this.declaration.toJSON(r),inputs:this.inputs.map(p=>p.toJSON(r)),outputs:this.outputs.map(p=>p.toJSON(r)),parent:this.parent.toReference(),error:(o=this.error)==null?void 0:o.toJSON(r)})}toJSONClone(r=Se){var o,p,e,y,v,E,w;let a;return(o=r.seenEntityMaps)!=null&&o.has(this.id)?a=r.seenEntityMaps.get(this.id):(a=r.newId||jr(this,this.project,r.uuidStrategy),r.seenEntityMaps&&r.seenEntityMaps.set(this.id,a)),(p=r.seenEntities)!=null&&p.has(a)||(e=r.seenEntities)!=null&&e.has(this.id)?this.toReference({seenEntityMaps:r.seenEntityMaps}):((y=r.seenEntities)==null||y.add(a),(v=r.seenEntities)==null||v.add(this.id),{id:a,version:N.UUID.uuid(),createdAt:r.timestamp||L().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,catchesError:this.catchesError,type:this.type,x:this.x,y:this.y,successCalls:this.successCalls.map(A=>A.toJSONClone({...r,newId:null})),errorCalls:this.errorCalls.map(A=>A.toJSONClone({...r,newId:null})),calledBySuccess:this.calledBySuccess.map(A=>A.toReference({seenEntityMaps:r.seenEntityMaps})),calledByError:this.calledByError.map(A=>A.toReference({seenEntityMaps:r.seenEntityMaps})),calledByEntry:this.calledByEntry.map(A=>A.toReference({seenEntityMaps:r.seenEntityMaps})),process:(E=this.process)==null?void 0:E.toJSONClone({...r,newId:null}),declaration:this.declaration.toJSONClone({...r,newId:null}),inputs:this.inputs.map(A=>A.toJSONClone({...r,newId:null})),outputs:this.outputs.map(A=>A.toJSONClone({...r,newId:null})),error:(w=this.error)==null?void 0:w.toJSONClone({...r,newId:null}),parent:this.parent.toReference({seenEntityMaps:r.seenEntityMaps})})}toReference(r=Se){var o;let a=this.id;return(o=r.seenEntityMaps)!=null&&o.has(this.id)&&(a=r.seenEntityMaps.get(this.id)),{id:a+"--"+N.UUID.uuid()+"--ref",type:f.GenericReference,entityId:a,version:this.version,entityType:this.type}}toShallowJSON(r=Se){var o;let a=this.id;return(o=r.seenEntityMaps)!=null&&o.has(this.id)&&(a=r.seenEntityMaps.get(this.id)),{id:a,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,catchesError:this.catchesError,x:this.x,y:this.y,process:this.process?this.process.toReference(r):null,inputs:this.inputs.map(p=>p.toReference(r)),outputs:this.outputs.map(p=>p.toReference(r)),declaration:this.declaration.toReference(r),successCalls:this.successCalls.map(p=>p.toReference(r)),errorCalls:this.errorCalls.map(p=>p.toReference(r)),calledBySuccess:this.calledBySuccess.map(p=>p.toReference(r)),calledByError:this.calledByError.map(p=>p.toReference(r)),calledByEntry:this.calledByEntry.map(p=>p.toReference(r)),error:this.error?this.error.toReference(r):null,parent:this.parent.toReference(r)}}toFlatJSON(r=new Set){return r.has(this.id)?[]:(r.add(this.id),[this.toShallowJSON(),...this.successCalls.flatMap(o=>o.toFlatJSON(r)),...this.errorCalls.flatMap(o=>o.toFlatJSON(r)),...this.inputs.flatMap(o=>o.toFlatJSON(r)),...this.outputs.flatMap(o=>o.toFlatJSON(r)),...this.process?this.process.toFlatJSON(r):[],...this.error?this.error.toFlatJSON(r):[]])}toGenerationTarget(){const r=this.parent.type===f.Project?void 0:this.parent.id;return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,calledByEntry:this.calledByEntry.map(a=>a.id),calledBySuccess:this.calledBySuccess.map(a=>a.id),calledByError:this.calledByError.map(a=>a.id),declaration:this.declaration.id,parent:r}}toFlatGenerationTarget(r=new Set){return r.has(this.id)?[]:(r.add(this.id),[this.toGenerationTarget(),...this.successCalls.flatMap(o=>o.toFlatGenerationTarget(r)),...this.errorCalls.flatMap(o=>o.toFlatGenerationTarget(r)),...this.inputs.flatMap(o=>o.toFlatGenerationTarget(r)),...this.outputs.flatMap(o=>o.toFlatGenerationTarget(r)),...this.process?this.process.toFlatGenerationTarget(r):[],...this.error?this.error.toFlatGenerationTarget(r):[]])}clearErrors(){var r,a;return this.errors=[],this.inputs.forEach(o=>o.clearErrors()),this.outputs.forEach(o=>o.clearErrors()),this.successCalls.forEach(o=>o.clearErrors()),this.errorCalls.forEach(o=>o.clearErrors()),(r=this.process)==null||r.clearErrors(),(a=this.error)==null||a.clearErrors(),this}validate(){const r=T5(this);return this.errors=r,{success:!0}}getErrors(){return[...this.errors,...this.inputs.flatMap(a=>a.getErrors()),...this.outputs.flatMap(a=>a.getErrors()),...this.error?this.error.getErrors():[],...this.process?this.process.getErrors():[]]}getShallowErrors(){return this.errors}clone(r=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"clone-entity")),a=null,o=null,p=!0){var B,F;let e=Ur(a,this);const y=this.toJSON(),v=o||N.UUID.uuid();y.inputs=[];const E=v.split("-id"),w=E[E.length-1||0]||v;y.id=v,y.version=N.UUID.uuid(),y.createdAt=(r==null?void 0:r.timestamp)||L().toISOString(),y.author=(r==null?void 0:r.author)||"1",y.previousVersion=null,y.deleted=!1;const A=dr(y,e);a?A.setParent(a,null):A.setParent(this.parent,null),p&&A.subscribe(),A.initChildren(r),r==null||r.add(A,S.Added);const $=(B=this.inputs)==null?void 0:B.map((K,q)=>K.clone(r,A,w+"-input-map-"+q+"-id",p));A.inputs=$;const V=(F=this.outputs)==null?void 0:F.map((K,q)=>K.clone(r,A,w+"-output-map-"+q+"-id",p));return A.outputs=V,this.error&&(A.error=this.error.clone(r,A,w+"-error-map-id",p)),this.process&&(A.process=this.process.clone(r,A,w+"-process-id",p)),r==null||r.attemptAutoclose("clone-entity",this.id),A}removeUnrecognizedInputs(r=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-unrecognized-inputs"))){const a=[],o=[],p=[],e=[];return this.inputs.forEach(v=>{if(!this.declaration.inputs.find(w=>{var A;return w.id===((A=v.declaration)==null?void 0:A.id)})){const w=v.remove({ignoreUpstream:!1},r);p.push(...w.removed),a.push(...w.updated)}}),this.inputs.filter((v,E)=>{const w=this.inputs.findIndex($=>$.declaration===v.declaration&&$!==v);if(w===-1)return!1;const A=this.inputs[w];return L(A==null?void 0:A.createdAt).isSame(L(v.createdAt))?E>w:!!L(A==null?void 0:A.createdAt).isAfter(v.createdAt)}).forEach(v=>{const E=v.remove({ignoreUpstream:!1},r);p.push(...E.removed),a.push(...E.updated)}),r==null||r.attemptAutoclose("remove-unrecognized-inputs",this.id),{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}removeUnrecognizedOutputs(r=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-unrecognized-outputs"))){const a=[],o=[],p=[],e=[];return this.outputs.forEach(v=>{if(!this.declaration.getUniqueReturnDeclarations().find(w=>{var A;return w.id===((A=v.declaration)==null?void 0:A.id)})){const w=v.remove({ignoreUpstream:!1},r);p.push(...w.removed),a.push(...w.updated)}}),this.outputs.filter((v,E)=>{const w=this.outputs.findIndex($=>$.declaration===v.declaration&&$!==v);if(w===-1)return!1;const A=this.outputs[w];return L(A==null?void 0:A.createdAt).isSame(L(v.createdAt))?E>w:!!L(A==null?void 0:A.createdAt).isAfter(v.createdAt)}).forEach(v=>{const E=v.remove({ignoreUpstream:!1},r);p.push(...E.removed),a.push(...E.updated)}),r==null||r.attemptAutoclose("remove-unrecognized-outputs",this.id),{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}syncInputs(r=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"sync-missing-fixed-inputs"))){const a=[],o=[],p=[],e=[],y=this.declaration.inputs.filter(A=>!this.inputs.find($=>$.declaration.id===A.id));this.inputs.sort((A,$)=>A.index-$.index),y.forEach(A=>{this.inputs.forEach(B=>{B.index>=A.index&&B.metaSync({index:B.index+1},r)});const $={id:N.UUID.uuid(),version:N.UUID.uuid(),createdAt:(r==null?void 0:r.timestamp)||L().toISOString(),author:N.sessionAuthor,previousVersion:null,deleted:!1,type:f.InputMap,declaration:A.toJSON(),readsValue:null,defaultValue:null,index:A.index,name:null,codeName:null,description:null,parent:this.toReference()},V=ne($,this.project);V.setParent(this,r),V.initChildren(r),r==null||r.add(V,S.Added),V.addSelfToProject(r),o.push(V)}),this.inputs.sort((A,$)=>A.index-$.index);const{updated:v,added:E,removed:w}=this.removeUnrecognizedInputs(r);return a.push(...v),o.push(...E),p.push(...w),r==null||r.attemptAutoclose("sync-missing-fixed-inputs",this.id),{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}syncOutputs(r=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"sync-missing-fixed-outputs"))){const a=[],o=[],p=[],e=[],y=[];this.outputs=this.initialData.outputs.reduce(($,V)=>{if(V.type===f.GenericReference){const F=qi(V,this.project);return F?[...$,F]:$}const B=ne(V,this.project);return y.push(B.index),B.setParent(this,null),B.initChildren(r),[...$,B]},[]);const v=this.declaration.getUniqueReturnDeclarations().filter($=>!this.outputs.find(V=>{var B;return((B=V.declaration)==null?void 0:B.id)===$.id}));this.outputs.sort(($,V)=>$.index-V.index),v.forEach(($,V)=>{this.outputs.forEach(q=>{q.index>=$.index&&q.index++});const B=y.includes($.index)?this.outputs.length-1+V:$.index,F={id:N.UUID.uuid(),version:N.UUID.uuid(),createdAt:(r==null?void 0:r.timestamp)||L().toISOString(),author:N.sessionAuthor,previousVersion:null,deleted:!1,type:f.OutputMap,declaration:$.toJSON(),defaultValue:null,writesValues:[],index:B,parent:this.toReference()},K=ne(F,this.project);K.setParent(this,r),K.initChildren(r),r==null||r.add(K,S.Added),K.addSelfToProject(r)}),this.outputs.sort(($,V)=>$.index-V.index);const{updated:E,added:w,removed:A}=this.removeUnrecognizedOutputs(r);return a.push(...E),o.push(...w),p.push(...A),r==null||r.attemptAutoclose("sync-missing-fixed-outputs",this.id),{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}getUnusedInputs(){return this.inputs.filter(r=>r.suggestion||!r.readsValue&&!r.defaultValue)}getUnusedOutputs(){return this.outputs.filter(r=>r.suggestion||!r.writesValues.length)}getUsedInputs(){return this.inputs.filter(r=>!r.suggestion&&(r.readsValue||r.defaultValue))}getUsedOutputs(){return this.outputs.filter(r=>!r.suggestion&&r.writesValues.length)}};_(Qt,"repository",{APICreate:async(r,...a)=>r,APIUpdate:async(r,...a)=>r,APIDelete:async(r,...a)=>r,APIClone:async(r,...a)=>{},APILoad:async(r,...a)=>null,APILoadVersion:async(r,a,...o)=>null}),_(Qt,"type",f.FunctionCall),_(Qt,"USER_MANAGED_PARENT_TYPES",[...Nr,f.Project]),_(Qt,"PARENT_TYPES",[...Qt.USER_MANAGED_PARENT_TYPES]),_(Qt,"MUTABLE_BASE_PROPERTIES",["catchesError"]),_(Qt,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),_(Qt,"BASE_PROPERTIES",[...Qt.MUTABLE_BASE_PROPERTIES,...Qt.INMUTABLE_BASE_PROPERTIES]),_(Qt,"MUTABLE_META_PROPERTIES",["x","y"]),_(Qt,"INMUTABLE_META_PROPERTIES",[...Qt.INMUTABLE_BASE_PROPERTIES]),_(Qt,"META_PROPERTIES",[...Qt.MUTABLE_META_PROPERTIES,...Qt.INMUTABLE_META_PROPERTIES]),_(Qt,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry"]),_(Qt,"INMUTABLE_UPSTREAM_PROPERTIES",["declaration","parent"]),_(Qt,"UPSTREAM_PROPERTIES",[...Qt.MUTABLE_UPSTREAM_PROPERTIES,...Qt.INMUTABLE_UPSTREAM_PROPERTIES]),_(Qt,"MUTABLE_DOWNSTREAM_PROPERTIES",["successCalls","errorCalls","writesValues","inputs","outputs","error"]),_(Qt,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),_(Qt,"DOWNSTREAM_PROPERTIES",[...Qt.MUTABLE_DOWNSTREAM_PROPERTIES,...Qt.INMUTABLE_DOWNSTREAM_PROPERTIES]),_(Qt,"PROPERTIES",[...Qt.META_PROPERTIES,...Qt.UPSTREAM_PROPERTIES,...Qt.DOWNSTREAM_PROPERTIES]);let To=Qt;function nb(d){return d&&typeof d.then=="function"}function tIe(d){const u=new zn(d[0]),r=d.map(o=>o.id),a={};return d.forEach(o=>{a[o.id]=o}),u.order=r,u.flatRecord=a,u.orderEntities(),u.order.map(o=>u.flatRecord[o])}function rIe(d){const u=new zn(Object.values(d)[0]),r=Object.keys(d);return u.order=r,u.flatRecord=d,u.orderEntities(),u.order}class zn{constructor(u){_(this,"order",[]);_(this,"flatRecord",{});_(this,"allBuiltInEntityIds",zs());_(this,"onGoingVisits",{});u&&(this.flatten(u),this.orderEntities())}flatten(u){const r=new Set(zs()),a=R(me(u,r,{ignoreBuiltInBaseEntities:!0})),o=new Set;for(const p of a)this.flatRecord[p.id]=p,o.add(p.id);this.order=Array.from(o)}moveEntityAfterDependencies(u){const{upstream:r}=kd(u,this.flatRecord,{ignoreBuiltInBaseEntities:!0,allBuiltInEntityIds:this.allBuiltInEntityIds});for(const a of Object.keys(r)){const o=this.order.indexOf(a),p=this.order.indexOf(u.id);if(o>p)return this.order.splice(p,1),this.order.splice(o,0,u.id),!0}return!1}orderEntities(){let u=!1;for(let r=0;r<this.order.length;r++){const a=this.order[r],o=this.flatRecord[a];if(o||Me.warn(`Entity with id ${a} not found in flatRecord. Skipping...`),this.moveEntityAfterDependencies(o)){u=!0;break}}u&&this.orderEntities()}getUpstreamOngoingDependenciesVisits(u,r){const{upstream:a}=kd(this.flatRecord[u],this.flatRecord,{ignoreBuiltInBaseEntities:!0,allBuiltInEntityIds:this.allBuiltInEntityIds}),o={};return Object.entries(this.onGoingVisits[r]||{}).forEach(([p,e])=>{Object.keys(a).includes(p)&&(o[p]=e)}),o}getDownstreamOngoingDependenciesVisits(u,r){const a=Object.keys(this.onGoingVisits[r]||{}),o=new Set(a.flatMap(e=>Object.keys(kd(this.flatRecord[e],this.flatRecord,{ignoreBuiltInBaseEntities:!0,allBuiltInEntityIds:this.allBuiltInEntityIds}).downstream))),p={};return Array.from(o).forEach(e=>{e===u&&(p[e]=this.onGoingVisits[r][e])}),p}async settlePromises(u,r){const a=Object.values(u);a.length&&await Promise.all(a),Object.keys(u).forEach(o=>{delete this.onGoingVisits[r][o]})}visit(u){const r=this.order;for(const a of r)u(this.flatRecord[a],this.flatRecord);return this}reverseVisit(u){const r=this.order.slice().reverse();for(const a of r)u(this.flatRecord[a],this.flatRecord);return this}async visitAsync(u){const r=this.order,a=Math.random().toString(36).substring(7);this.onGoingVisits[a]={};for(const o of r){const p=this.getUpstreamOngoingDependenciesVisits(o,a);Object.keys(p).length&&await this.settlePromises(p,a);const e=u(this.flatRecord[o],this.flatRecord);nb(e)&&(this.onGoingVisits[a][o]=e)}return await this.settlePromises(this.onGoingVisits[a],a),this.onGoingVisits[a]={},this}async reverseVisitAsync(u){const r=this.order.slice().reverse(),a=Math.random().toString(36).substring(7);this.onGoingVisits[a]={};for(const o of r){const p=this.getDownstreamOngoingDependenciesVisits(o,a);Object.keys(p).length&&await this.settlePromises(p,a);const e=u(this.flatRecord[o],this.flatRecord);nb(e)&&(this.onGoingVisits[a][o]=e)}return await this.settlePromises(this.onGoingVisits[a],a),this.onGoingVisits[a]={},this}}function A5(d,u){switch(d.id){case he["built-in-base-entity"].BUILT_IN_PERSISTED_ENTITY_ENTITY.id:{const r=d.project.entities.filter(v=>!!v.implements.find(E=>E.id===he["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.id)),a=r.find(v=>{const E=v.properties.find($=>$.implements&&$.implements.id===he["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.default.id),w=E==null?void 0:E.getDefaultValue();return(w==null?void 0:w.value)===!0});if(!a&&r.length){const E=r[0].properties.find(A=>A.implements&&A.implements.id===he["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.default.id),w=E==null?void 0:E.defaultValue;if(w)w.metaSync({value:!0},u);else if(E!=null&&E.dataType){const A={id:N.UUID.uuid(),version:N.UUID.uuid(),createdAt:(u==null?void 0:u.timestamp)||new Date().toISOString(),author:N.sessionAuthor,previousVersion:null,deleted:!1,type:f.LiteralValue,standaloneParent:null,name:oe.EntityTemplate,autogeneration:null,value:!0,valueAsTypeSingle:null,valueAsTypeList:null,parent:E==null?void 0:E.toReference()},$=ne(A,d.project);return $.setParent(E,u),$.initChildren(u),u==null||u.add($,S.Added),$.addSelfToProject(u),{newEntities:[$]}}return{newEntities:[]}}else if(a)return{newEntities:[]};const o=d.project.get(he["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.id),p=vm(o,"Main database",u);if(p.errors.length>0)return{newEntities:[]};const e=p.properties.find(v=>v.implements&&v.implements.id===he["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.default.id),y=e==null?void 0:e.defaultValue;if(y)y.metaSync({value:!0},u);else if(e!=null&&e.dataType){const v={id:N.UUID.uuid(),version:N.UUID.uuid(),createdAt:(u==null?void 0:u.timestamp)||new Date().toISOString(),author:N.sessionAuthor,previousVersion:null,deleted:!1,type:f.LiteralValue,standaloneParent:null,name:oe.EntityTemplate,autogeneration:null,value:!0,valueAsTypeSingle:null,valueAsTypeList:null,parent:e==null?void 0:e.toReference()},E=ne(v,d.project);E.setParent(e,u),E.initChildren(u),u==null||u.add(E,S.Added),E.addSelfToProject(u)}return{newEntities:[p]}}}return{newEntities:[]}}function b5(d,u){const r=[],a=[],o=[],p=[];return d.implements.filter(y=>y.type===f.BuiltInBaseEntity).forEach(y=>{var v;switch(y.id){case he["built-in-base-entity"].BUILT_IN_PERSISTED_ENTITY_ENTITY.id:{const E=d.project.entities.filter(V=>V.implements.find(B=>B.id===he["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.id));let w=E.find(V=>!!V.properties.find(B=>{var F;return B.implements&&B.implements.id===he["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.default.id&&((F=B.getDefaultValue())==null?void 0:F.value)===!0}));if(!w&&E.length)w=E[0];else if(!w&&!E.length){w=d.project.getBuiltIn(he["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.id).implement("Relational database",u);const B=w.properties.find(F=>{var K;return((K=F.implements)==null?void 0:K.id)===he["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.default.id});(v=B==null?void 0:B.defaultValue)==null||v.metaSync({value:!0},u),a.push(w)}const A=d.properties.find(V=>V.implements&&V.implements.id===he["built-in-base-entity"].BUILT_IN_PERSISTED_ENTITY_ENTITY.properties.database.id),$=A==null?void 0:A.defaultValue;if(A&&!$){const V={id:N.UUID.uuid(),version:N.UUID.uuid(),createdAt:(u==null?void 0:u.timestamp)||new Date().toISOString(),author:N.sessionAuthor,previousVersion:null,deleted:!1,type:f.LiteralValue,standaloneParent:null,name:oe.EntityTemplate,autogeneration:null,value:null,valueAsTypeSingle:(w==null?void 0:w.toJSON())||null,valueAsTypeList:null,parent:A==null?void 0:A.toReference()},B=ne(V,d.project);B.hydrateAncestors(),B.setParent(A,u),B.addSelfToProject(u),B.initChildren(u),u==null||u.add(B,S.Added),a.push(B);return}else $&&!$.valueAsTypeSingle&&$.setValueAsTypeSingle(w||null,u);return}}}),{self:d,updated:R(r),added:R(a),removed:R(o),affected:R(p)}}function vm(d,u,r,a){const o=a||N.UUID.uuid(),p=N.UUID.uuid(),e={id:o,version:p,createdAt:(r==null?void 0:r.timestamp)||new Date().toISOString(),author:N.sessionAuthor,previousVersion:null,deleted:!1,name:u,type:f.DefinitionEntity,codeName:null,description:null,static:d.static,abstract:!1,properties:[],methods:[],abstractMethods:[],extends:null,implements:[d.toJSON()],x:0,y:0,parent:d.project.toReference()};A5(d,r);const y=ne(e,d.project);return y.hydrateAncestors(),r==null||r.add(y,S.Added),y.addSelfToProject(r),y.addImplementation(d),y.setParent(d.project,r),y.initChildren(r),b5(y,r),y}function ab(d,u){return u.entities.find(o=>{const p=o.properties,e=p.map(A=>A.name),y=d.every(A=>e.includes(A)),v=e.filter(A=>!d.includes(A)),E=p.every(A=>!v.includes(A.name)||!A.required);return y&&E})||null}function w5(d,u,r,a=mi.OrDataTypeGroup){const o=[],p=[],e=[],y=[],E={id:N.UUID.uuid(),version:N.UUID.uuid(),createdAt:(r==null?void 0:r.timestamp)||new Date().toISOString(),author:N.sessionAuthor,previousVersion:null,deleted:!1,type:f.DataType,options:null,implementationChooseOne:!1,entity:d.toJSON(),isList:!1,asType:!1,andChildrenGroup:null,index:null,orChildrenGroup:null,staticEntities:null,interactiveEntities:null,actionEntities:null,like:!0,inferred:!1,parentRelationType:a,parent:u.toReference()},w=ne(E,d.project);return p.push(w),w.setParent(u,r),w.initChildren(r),r==null||r.add(w,S.Added),w.setEntity(d,r),w.addSelfToProject(r),{updated:R(o),added:R(p),removed:R(e),affected:R(y),self:w}}function ob(d,u,r,a,o){var E,w,A,$,V,B,F,K;const p=[],e=[],y=[],v=[];switch(typeof d){case"string":let q=!1;const ie=new Date(d);if(ie instanceof Date&&!isNaN(ie.valueOf())&&(q=!0),q){const W=u.project.getBuiltIn(he[f.PrimitiveEntity][oe.Date].id);u.setEntity(W,a);break}else{const W=u.project.getBuiltIn(he[f.PrimitiveEntity][oe.String].id);u.setEntity(W,a);break}case"number":u.setEntity(u.project.getBuiltIn(he[f.PrimitiveEntity][oe.Number].id),a);break;case"boolean":u.setEntity(u.project.getBuiltIn(he[f.PrimitiveEntity][oe.Boolean].id),a);break;case"object":if(d===null){u.setEntity(u.project.getBuiltIn(he[f.PrimitiveEntity][oe.Null].id),a);break}else if(Array.isArray(d))if(u.metaSync({isList:!0},a),d.length>0){const W=d.slice(0,5).filter(Q=>Q!==void 0);if(W.every(Q=>typeof Q==typeof W[0])&&(typeof W[0]!="object"||W[0]===null))switch(typeof W[0]){case"string":u.setEntity(u.project.getBuiltIn(he[f.PrimitiveEntity][oe.String].id),a);break;case"number":u.setEntity(u.project.getBuiltIn(he[f.PrimitiveEntity][oe.Number].id),a);break;case"boolean":u.setEntity(u.project.getBuiltIn(he[f.PrimitiveEntity][oe.Boolean].id),a);break;case"object":u.setEntity(u.project.getBuiltIn(he[f.PrimitiveEntity][oe.Null].id),a);break}else{const Q=[];let ce=!1;W.forEach(z=>{var pe,te,ue,Ie;if(Array.isArray(z)&&(ce=!0),typeof z=="object"&&!Array.isArray(z)&&z!==null){const Ue=Em(z,u.project,{...r,id:N.UUID.uuid()},a,o);Ue.hasCreated&&Q.push((pe=Ue.changeSet)==null?void 0:pe.self),p.push(...(te=Ue.changeSet)==null?void 0:te.updated),e.push(...(ue=Ue.changeSet)==null?void 0:ue.added),y.push(...(Ie=Ue.changeSet)==null?void 0:Ie.removed)}});const X=R(Q);if(!X.length&&!ce){W.forEach(z=>{const pe={id:N.UUID.uuid(),version:N.UUID.uuid(),createdAt:(a==null?void 0:a.timestamp)||new Date().toISOString(),author:N.sessionAuthor,previousVersion:null,deleted:!1,type:f.DataType,options:null,implementationChooseOne:!1,entity:null,isList:!1,asType:!1,andChildrenGroup:null,index:null,orChildrenGroup:null,staticEntities:!1,interactiveEntities:!0,actionEntities:!1,like:!0,inferred:!1,parentRelationType:mi.OrDataTypeGroup,parent:u.toReference()},te=ne(pe,u.project);switch(te.setParent(u,a),te.initChildren(a),a==null||a.add(te,S.Added),te.addSelfToProject(a),typeof z){case"string":te.setEntity(te.project.getBuiltIn(he[f.PrimitiveEntity][oe.String].id),a);break;case"number":te.setEntity(te.project.getBuiltIn(he[f.PrimitiveEntity][oe.Number].id),a);break;case"boolean":te.setEntity(te.project.getBuiltIn(he[f.PrimitiveEntity][oe.Boolean].id),a);break;case"object":te.setEntity(te.project.getBuiltIn(he[f.PrimitiveEntity][oe.Null].id),a);break}});break}else X.length===1&&!ce?u.setEntity(X[0],a):W.forEach(z=>{if(typeof z=="object"&&!Array.isArray(z)&&z!==null){const pe=ab(Object.keys(z),u.project);if(pe){const te=w5(pe||X[0],u,a,mi.OrDataTypeGroup);p.push(...te.updated),e.push(...te.added),y.push(...te.removed)}}else{const pe={id:N.UUID.uuid(),version:N.UUID.uuid(),createdAt:(a==null?void 0:a.timestamp)||new Date().toISOString(),author:N.sessionAuthor,previousVersion:null,deleted:!1,type:f.DataType,options:null,implementationChooseOne:!1,entity:null,isList:Array.isArray(z),asType:!1,andChildrenGroup:null,index:null,orChildrenGroup:null,staticEntities:!1,interactiveEntities:!0,actionEntities:!1,like:!0,inferred:!1,parentRelationType:mi.OrDataTypeGroup,parent:u.toReference()},te=ne(pe,u.project);te.setParent(u,a),te.initChildren(a),a==null||a.add(te,S.Added),te.addSelfToProject(a);const ue=ob(z,te,{...r,id:N.UUID.uuid()},a,o);p.push(...ue.updated),e.push(...ue.added),y.push(...ue.removed)}})}}else{const W=Em(d[0],u.project,{...r},a,o);u.setEntity((E=W.changeSet)==null?void 0:E.self,a),p.push(...(w=W.changeSet)==null?void 0:w.updated),e.push(...(A=W.changeSet)==null?void 0:A.added),y.push(...($=W.changeSet)==null?void 0:$.removed);break}else{const W=Em(d,u.project,{...r},a,o);u.setEntity((V=W.changeSet)==null?void 0:V.self,a),p.push(...(B=W.changeSet)==null?void 0:B.updated),e.push(...(F=W.changeSet)==null?void 0:F.added),y.push(...(K=W.changeSet)==null?void 0:K.removed);break}}return{updated:R(p),added:R(e),removed:R(y),affected:R(v),self:u}}function Em(d,u,r,a,o){const p=[],e=[],y=[],v=[],E=Object.keys(d),w=ab(E,u);if(w)return{hasCreated:!1,changeSet:{updated:[],added:[],removed:[],affected:[],self:w}};const A=o?r.name+" of "+o.name:r.name,V={id:r.id||N.UUID.uuid(),version:N.UUID.uuid(),createdAt:(a==null?void 0:a.timestamp)||new Date().toISOString(),author:N.sessionAuthor,previousVersion:null,deleted:!1,name:A,codeName:null,type:f.DefinitionEntity,description:r.description||null,static:r.static||!1,abstract:r.abstract||!1,properties:[],methods:[],abstractMethods:[],extends:null,implements:[],x:0,y:0,parent:u.toReference()},B=ne(V,u);return B.setParent(u,a),B.initChildren(a),a==null||a.add(B,S.Added),B.addSelfToProject(a),e.push(B),E.forEach((F,K)=>{const ie={id:N.UUID.uuid(),version:N.UUID.uuid(),createdAt:(a==null?void 0:a.timestamp)||new Date().toISOString(),author:N.sessionAuthor,previousVersion:null,deleted:!1,name:F,type:f.Property,codeName:F,description:null,static:!1,abstract:!1,defaultValue:null,constant:!1,interactive:!0,dataType:null,implements:null,extends:null,index:K,hidden:!1,private:!1,required:!0,parent:B.toReference()},W=ne(ie,u);W.setParent(B,a),W.initChildren(a),a==null||a.add(W,S.Added),W.addSelfToProject(a),e.push(W);const de=d[F],ce={id:N.UUID.uuid(),version:N.UUID.uuid(),createdAt:(a==null?void 0:a.timestamp)||new Date().toISOString(),author:N.sessionAuthor,previousVersion:null,deleted:!1,type:f.DataType,parentRelationType:null,options:null,implementationChooseOne:!1,entity:null,isList:!1,asType:!1,andChildrenGroup:null,index:null,orChildrenGroup:null,staticEntities:!1,interactiveEntities:!0,actionEntities:!1,like:!0,inferred:!1,parent:W.toReference()},X=ne(ce,u);X.setParent(W,a),X.initChildren(a),a==null||a.add(X,S.Added),X.addSelfToProject(a),e.push(X);const z=ob(de,X,{...r,name:F,id:N.UUID.uuid()},a,o||B);p.push(...z.updated),e.push(...z.added),y.push(...z.removed)}),{hasCreated:!0,changeSet:{updated:R(p),added:R(e),removed:R(y),affected:R(v),self:B}}}function Va(d,u,r,a){const o=[];return!d.length||!u.length?{errors:o,overlap:!1}:(d.length>u.length?d.forEach(p=>{const e=u.find(v=>v.name===p.name),y=u.find(v=>{var E,w;return!!p.implements&&((E=v.implements)==null?void 0:E.id)===((w=p.implements)==null?void 0:w.id)});if(e){const v=new ir({id:p.id+"--"+e.id+"--"+a,message:`Entity of type ${p.type} named "${p.name}" with id "${p.id}" overrides a base ${e.type} ${e.name} with id "${e.id}" that has the same name`,severity:H.Error,code:a,entity:p,firstRelationship:e});o.push(v)}if(y){const v=new ir({id:p.id+"--"+y.id+"--"+r,message:`Entity of type ${p.type} named "${p.name}" with id "${p.id}" overrides a base ${y.type} ${y.name} with id "${y.id}" that implements the same base descriptor`,severity:H.Error,code:r,entity:p,firstRelationship:y});o.push(v)}}):u.forEach(p=>{var v;const e=d.find(E=>E.name===p.name),y=d.find(E=>{var w,A;return!!E.implements&&((w=E.implements)==null?void 0:w.id)===((A=p.implements)==null?void 0:A.id)});if(e){const E=new ir({id:e.id+"--"+p.id+"--"+a,message:`Entity of type ${e.type} named "${e.name}" with id "${e.id}" overrides a base entity ${p.name} with id "${p.id}" that has the same name`,severity:H.Error,code:a,entity:e,firstRelationship:p});o.push(E)}if(y){const E=new ir({id:y.id+"--"+p.id+"--"+r,message:`Entity of type ${y.type} named "${y.name}" with id "${y.id}" overrides a base entity ${p.name} with id "${p.id}" that implements the same base ${(v=y==null?void 0:y.implements)==null?void 0:v.type}`,severity:H.Error,code:r,entity:y,firstRelationship:p});o.push(E)}}),{errors:o,overlap:!!o.length})}function iIe(d,u){return d.abstract||(d.properties.forEach(a=>{a.abstract||a.metaSync({abstract:!0},u)}),Object.values(d.detachedDependents).forEach(a=>{a.field===gI.Entity&&a.entity.remove({ignoreUpstream:!1},u)}),d.metaSync({abstract:!0},u)),d}function sIe(d,u){return d.abstract&&(d.properties.forEach(a=>{a.abstract&&a.metaSync({abstract:!1},u)}),Object.values(d.detachedDependents).forEach(a=>{(a.field===Bm.Implements||a.field===Bm.Extends)&&a.entity.onDetachedDependencyRemoved(d,a.field,u)}),d.metaSync({abstract:!1},u)),d}function nIe(d,u){return d.static||(d.properties.forEach(a=>{a.static||a.metaSync({static:!0},u)}),d.metaSync({static:!0},u)),d}function aIe(d,u){return d.static&&d.metaSync({static:!1},u),d}var ki=(d=>(d.StringValueMustNotHaveSpaces="string-value-must-not-have-spaces",d.StringValueMustNotHaveDashes="string-value-must-not-have-dashes",d.MustBeUniqueAmongSameEntities="must-be-unique-among-same-entities",d))(ki||{});function lb(d,u){const r=[],a=u;if(!a)return{errors:r,override:u};if(typeof a!="string")return{errors:[],override:u};if(a.includes(" ")){const o=new ir({id:d.id+"--string-value-must-not-have-spaces",message:`Entity of type ${d.type} with id "${d.id}" has an invalid value "${u}". The value cannot contain spaces.`,severity:H.Error,code:"string-value-must-not-have-spaces",entity:d});r.push(o)}return{errors:r,override:a.replace(/\s/g,"-")}}function R5(d,u){const r=[],a=u;if(!a)return{errors:r,override:u};if(typeof a!="string")return{errors:[],override:u};if(a.includes(" ")){const o=new ir({id:d.id+"--string-value-must-not-have-spaces",message:`Entity of type ${d.type} with id "${d.id}" has an invalid value "${u}". The value cannot contain spaces or dashes.`,severity:H.Error,code:"string-value-must-not-have-spaces",entity:d});r.push(o)}if(a.includes("-")){const o=new ir({id:d.id+"--string-value-must-not-have-dashes",message:`Entity of type ${d.type} with id "${d.id}" has an invalid value "${u}". The value cannot contain spaces or dashes.`,severity:H.Error,code:"string-value-must-not-have-dashes",entity:d});r.push(o)}return{errors:r,override:a.replace(/\s|-/g,"_")}}function db(d,u){var r;if(d.type===f.LiteralValue){let a=(r=d.value)==null?void 0:r.toString();try{a=JSON.stringify(d.value,null,2)}catch{}return`${d.type}: ${d.id} (${Y(d,u)}) = ${a}`}if(d.type===f.DataType){if(d instanceof fs||d.increaseVersion)return`${d.type}: ${d.id} (${Yd(d)})`;try{const a=Yd(d);return`${d.type}: ${d.id} (${a})`}catch{}}return`${d.type}: ${d.id} (${Y(d,u)})`}function Fd(d,u){const r=Ao(d);if(r.length===0)return{list:[],last:null};let a=null;return{list:r.flatMap(p=>{if(p===u)return a=p,[p];const e=Fd(p,u);return e.last&&(a=e.last),[p,...e.list]}),last:a}}function Io(d,u){const r=d.calledBy;if(r.length===0)return{list:[],last:null,callType:null};let a=null,o=null;return{list:r.flatMap(e=>{if(e===u)return a=e,Dt.includes(e.type)?e.parent.type===f.Loop?o="loop-body":o="entry":e.successCalls.includes(d)?o="success":e.errorCalls.includes(d)&&(o="error"),[e];if(e.type===f.FunctionDeclaration&&e.parent.type===f.Loop&&e.parent===u)return a=e.parent,o="loop-body",[e];if(!xi.includes(e.type))return[e];const y=Io(e,u);return y.last&&(a=y.last,o=y.callType),[e,...y.list]}),last:a,callType:o}}function oIe(d,u){if(d===u)return"same-entity";if(!wi.includes(d.type)||!Yp(d).find(o=>o.callee===u))return null;if(Dt.includes(d.type)){if(d.calls.includes(u))return d.type===f.Loop?"loop-body":"entry"}else if(sr.includes(d.type)&&d.type!==f.InternalCall){if(d.successCalls.includes(u))return"success";if(d.errorCalls.includes(u))return"error"}return null}function Jp(d){const u=Di(d,d.project);return u?Dt.includes(u.type)?u:u.type===f.Loop?u.body:null:null}function g5(d,u){const r=d.calledBy;return!r||!r.length?!1:r.every(a=>a===u?!0:xi.includes(a.type)?!!Io(a,u).last:!1)}function _5(d){return d.filter(u=>{const r=Jp(u);return!d.filter(p=>p!==u).some(p=>p===r?!1:Im(p,u))})}function D5(d,u){if(!d)throw new Error("findNextSingleCallerAncestor: Target is not defined, cannot find ancestor.");let r=d;(d.type===f.VariableDeclaration||d.type===f.VariableInstance)&&!d.calledBy.length&&!d.successCalls.length&&!d.errorCalls.length&&d.internalCalls.some($=>!!$.calledBy.length)&&(r=d.internalCalls.find(V=>!!V.calledBy.length));const a=u||Di(r,d.project);if(!a)return{ancestor:null,callType:null};if(a.type===f.Project)return{ancestor:null,callType:null};const o=Yp(a);if(!o.find($=>$.callee===r))return{ancestor:null,callType:null};if(a.type===f.Loop){if(a.body.calls.includes(r))return{ancestor:a,callType:"loop-body"}}else if(Dt.includes(a.type)){if(a.calls.includes(r))return a.type===f.FunctionDeclaration&&a.parent.type===f.Loop?{ancestor:a,callType:"loop-body"}:{ancestor:a,callType:"entry"}}else if(sr.includes(a.type)){if(a.successCalls.includes(r))return{ancestor:a,callType:"success"};if(a.errorCalls.includes(r))return{ancestor:a,callType:"error"}}const e=o.filter($=>!($.callee===r||!wi.includes($.callee.type)||!dt($.callee).find(F=>F===r))).filter(($,V,B)=>B.findIndex(F=>F.callee===$.callee)===V);if(e.length===0)return{ancestor:null,callType:null};if(e.length===1){const $=e[0];if($.callee.type===f.Loop){if($.callee.body.calls.includes(r))return{ancestor:$.callee,callType:"loop-body"}}else{if(Dt.includes($.callee.type))return $.callee.type===f.FunctionDeclaration&&$.callee.parent.type===f.Loop?{ancestor:$.callee,callType:"loop-body"}:{ancestor:$.callee,callType:"entry"};if(sr.includes($.callee.type)){if($.callType==="success"&&$.callee.type===f.InternalCall)return{ancestor:$.callee,callType:"success"};if($.callType==="error"&&$.callee.type===f.InternalCall)return{ancestor:$.callee,callType:"error"}}}}const y=e.filter($=>g5(r,$.callee)),v=y.filter($=>{const V=dt($.callee),B=y.filter(K=>K.callee!==$.callee).map(K=>K.callee);return!V.some(K=>!!B.find(ie=>ie===K))});if(v.length===0){if(a.type===f.Loop){if(dt(a.body).find(ie=>ie===r))return{ancestor:a,callType:"loop-body"};if(ri(a.successCalls).find(ie=>ie===r))return{ancestor:a,callType:"success"};if(ri(a.errorCalls).find(ie=>ie===r))return{ancestor:a,callType:"error"}}else if(sr.includes(a.type)){if(ri(a.successCalls).find(K=>K===r))return{ancestor:a,callType:"success"};if(ri(a.errorCalls).find(K=>K===r))return{ancestor:a,callType:"error"}}return a.parent.type===f.Loop?{ancestor:a,callType:"loop-body"}:{ancestor:a,callType:"entry"}}if(v.length>1)throw new Error(`findNextSingleCallerAncestor: Could not be resolved, multiple candidates found: ${v.map($=>Y($.callee,r.project)).join(", ")}`);const E=v[0].callee,A=Yp(E).find($=>$.callee===r);return{ancestor:E,callType:A.callType}}function lIe(d){if(![f.VariableDeclaration,f.OutputMap].includes(d.type))throw new Error("getEarliestSingleCallerAncestorOfValueWriterAndItsValueReaders can only be used with a value writer entity");let u;if(d.type===f.VariableDeclaration?u=d:d.type===f.OutputMap&&(u=d.parent),!u)throw new Error("getEarliestSingleCallerAncestorOfValueWriterAndItsValueReaders can only be used with a value writer entity that has a caller");const r=R([d,...cb(d)]),a=R(r.map(y=>ub(y)).flatMap(y=>hr.includes(y==null?void 0:y.type)?y.calledBy:[y]));if(a.length===1){const y=a[0];if(Dt.includes(y.type))return y.parent.type===f.Loop?{ancestor:y,callType:"loop-body"}:{ancestor:y,callType:"entry"};if(u===y)return{ancestor:y,callType:"success"};if(y.successCalls.includes(u))return{ancestor:y,callType:"success"};if(y.errorCalls.includes(u))return{ancestor:y,callType:"error"};throw new Error(`getEarliestSingleCallerAncestorOfValueWriterAndItsValueReaders: Could not be resolved, single caller found, but it is not a valid caller: ${Y(y,u.project)}`)}const o=a.map(y=>{if(Dt.includes(y.type))return y.parent.type===f.Loop?{ancestor:y,callType:"loop-body"}:{ancestor:y,callType:"entry"};const v=D5(y);if(!v.ancestor)throw new Error(`getEarliestSingleCallerAncestorOfValueWriterAndItsValueReaders: Could not be resolved, no ancestor found for ${Y(y,u.project)}`);return v}).filter((y,v,E)=>v===E.findIndex(w=>{var A,$;return((A=w.ancestor)==null?void 0:A.id)===(($=y.ancestor)==null?void 0:$.id)})),p=Jp(u),e=o.filter(y=>y!=null&&y.ancestor?p===y.ancestor?!0:!o.filter(w=>w.ancestor!==y.ancestor).map(w=>w.ancestor).some(w=>{const A=Io(y.ancestor,w);return!!(A!=null&&A.last)}):!1);if(e.length===0)return{ancestor:p,callType:(p==null?void 0:p.parent.type)===f.Loop?"loop-body":"entry"};if(e.length>1)throw new Error(`getEarliestSingleCallerAncestorOfValueWriterAndItsValueReaders: Could not be resolved, multiple candidates found: ${e.map(y=>Y(y.ancestor,u.project)).join(", ")}`);return{ancestor:e[0].ancestor,callType:e[0].callType}}function O5(d,u){if(d===u)return!0;if(dt(d).includes(u)||!dt(u).includes(d))return!1;const o=d.calledBy;return o.length===0?!1:o.length===1?o[0]===u:_5(o).length>1&&o.includes(u)?!1:o.every(e=>d===u?!0:Dt.includes(e.type)?!1:O5(e,u))}function C5(d){const u=[];let r=d.calledBySuccess;r=r.filter(o=>!r.filter(y=>y!==o).some(y=>Im(y,o)));let a=d.calledByError;a=a.filter(o=>!a.filter(y=>y!==o).some(y=>Im(y,o)));for(const o of r)u.push({ancestor:o,callType:"success"});for(const o of a)u.push({ancestor:o,callType:"error"});return u}function $5(d){const u=[];return C5(d).forEach(a=>{a.ancestor.type===f.Condition&&u.push({condition:a.ancestor,call:d,callType:a.callType});const p=$5(a.ancestor).filter(e=>!u.some(y=>y.condition.id===e.condition.id));u.push(...p)}),u}function ub(d){if(!d)return null;if(d.type===f.Condition&&d.parent.type===f.Condition)return Am(d.parent);if($v.includes(d.type))return d;const u=d.parent;return u?ub(u):null}function cb(d,u=new Set){return d.writesValues.reduce((r,a)=>u.has(a.id)?r:(u.add(a.id),un.includes(a.type)?[...r,a]:Br.includes(a.type)?[...r,a,...cb(a,u)]:r),[])}function Wp(d){const u=d.calledBy;if(u.length===0)return d.project;const r=u.reduce((a,o)=>{const p=Di(o,d.project);return!p||p.type===f.Project?a:a.type===f.Project||Fd(p,a).last?p:(Fd(a,p).last,a)},d.project);return r.type===f.FunctionDeclaration&&r.parent.type===f.Loop?r.parent:r}function He(d,u){let r=Wp(d);if(d.type===f.InternalCall)if(d.parent.type===f.VariableInstance){const o=Xs(r,d.parent.declaration,d.project);!o.compatible&&o.type!=="b-is-global-a-is-not"?d.parent.remove({ignoreUpstream:!1},u):(d.parent.setParent(r,u),d.parent.addSelfToProject(u))}else d.parent.setParent(r,u),d.parent.addSelfToProject(u);else if((d.type===f.ContinueStatement||d.type===f.BreakStatement)&&r.type!==f.Loop){d.remove({ignoreUpstream:!1},u);return}else if(d.type===f.ReturnStatement&&!Nr.includes(r.type)){d.remove({ignoreUpstream:!1},u);return}else if(Tt.includes(d.type)){const o=d.usedInternalCalls[0];if(o)if(r=Wp(o),d.type===f.VariableInstance){const p=Xs(r,d.declaration,d.project);!p.compatible&&p.type!=="b-is-global-a-is-not"?d.remove({ignoreUpstream:!1},u):(d.setParent(r,u),d.addSelfToProject(u))}else d.setParent(r,u),d.addSelfToProject(u);else if(d.type===f.VariableInstance){const p=Xs(r,d.declaration,d.project);!p.compatible&&p.type!=="b-is-global-a-is-not"?d.remove({ignoreUpstream:!1},u):(d.setParent(r,u),d.addSelfToProject(u))}else d.setParent(r,u),d.addSelfToProject(u)}else d.setParent(r,u),d.addSelfToProject(u);if(hr.includes(d.type))return;dt(d).forEach(o=>{let p=Wp(o);if(o.type===f.InternalCall)if(o.parent.type===f.VariableInstance){const e=Xs(p,o.parent.declaration,d.project);!e.compatible&&e.type!=="b-is-global-a-is-not"?o.parent.remove({ignoreUpstream:!1},u):(o.parent.setParent(p,u),o.parent.addSelfToProject(u))}else o.parent.setParent(p,u),o.parent.addSelfToProject(u);else if((o.type===f.ContinueStatement||o.type===f.BreakStatement)&&p.type!==f.Loop){o.remove({ignoreUpstream:!1},u);return}else if(o.type===f.ReturnStatement&&!Nr.includes(p.type)){o.remove({ignoreUpstream:!1},u);return}else if(Tt.includes(o.type)){const e=o.usedInternalCalls[0];if(e)if(p=Wp(e),o.type===f.VariableInstance){const y=Xs(p,o.declaration,d.project);!y.compatible&&y.type!=="b-is-global-a-is-not"?o.remove({ignoreUpstream:!1},u):(o.setParent(p,u),o.addSelfToProject(u))}else o.setParent(p,u),o.addSelfToProject(u);else if(o.type===f.VariableInstance){const y=Xs(p,o.declaration,d.project);!y.compatible&&y.type!=="b-is-global-a-is-not"?o.remove({ignoreUpstream:!1},u):(o.setParent(p,u),o.addSelfToProject(u))}else o.setParent(p,u),o.addSelfToProject(u)}else o.setParent(p,u),o.addSelfToProject(u)})}function Tm(d,u,r=new Set){const a=bn(d),o=bn(u),p=a.filter(v=>!o.includes(v)),e=a.filter(v=>o.includes(v)),y=p.reduce((v,E)=>r.has(E.id)?v:(r.add(E.id),R([...v,...Tm(E,u,r)])),[]);return R([...e,...y])}function Il(d,u){const r=Fd(d,u);return r.last===u&&r.list.length>0&&r.list[0]!==u}function pb(d,u){return!!Fd(d,u).last}function Im(d,u){return!!Io(d,u).last}function fb(d,u){if(!d||!u)throw new Error("Both entities must be defined to find a common ancestor");if(d===u)return d;const r=d.parent;if(r){if(r===u)return u;if(r.type===f.Project)return null}else return null;const a=u.parent;if(a){if(a===d)return d;if(a.type===f.Project)return null}else return null;return fb(r,a)}function dIe(d,u,r=!0){if(!d||!u)throw new Error("Both entities must be defined to find a common ancestor");if(d===u)return{ancestor:d,callType:"same-entity"};if(xi.includes(d.type)&&wi.includes(u.type)){const y=Io(d,u),v=y.last;if(v){if(v===u)return{ancestor:u,callType:y.callType}}else return{ancestor:null,callType:null}}if(xi.includes(u.type)&&wi.includes(d.type)){const y=Io(u,d),v=y.last;if(v){if(v===d)return{ancestor:d,callType:y.callType}}else return{ancestor:null,callType:null}}const a=Jp(d),o=Jp(u);if(!a||!o)return{ancestor:null,callType:null};if(a!==o)return{ancestor:null,callType:null};if(a.calls.includes(d)||a.calls.includes(u))return{ancestor:a,callType:"entry"};const p=a.calls.reduce((y,v)=>{if(!wi.includes(v.type))return y;const E=Yp(v),w=E.find($=>$.callee===d),A=E.find($=>$.callee===u);return w&&A&&(!r||w.callType===A.callType)?[...y,{ancestor:v,callType:w.callType}]:y},[]);if(p.length===0)return{ancestor:null,callType:null};if(p.length===1)return{ancestor:p[0].ancestor,callType:p[0].callType};const e=p.filter(y=>!p.some(v=>v.ancestor!==y.ancestor&&Io(y.ancestor,v.ancestor).last===v.ancestor));return e.length===1?{ancestor:e[0].ancestor,callType:e[0].callType}:{ancestor:a,callType:"entry"}}function fr(d){if(th.includes(d.type)){if(d.type===f.FunctionDeclaration){const u=d.parent;if(u.type===f.DefinitionEntity)return fr(u);if(u.type===f.Loop)return u}return d.type===f.DefinitionEntity&&d.parent.type===f.DataType||d.type===f.Condition&&d.parent.type===f.Condition?fr(d.parent):d}else{const u=d.parent;return u?fr(u):null}}function Sd(d,u){const r=Kd(d,u);if(!r)return null;if(th.includes(r.type)){if(r.type===f.FunctionDeclaration){const a=Kd(r.parent,u);if(a){if(a.type===f.DefinitionEntity)return a;if(a.type===f.Loop)return a}}if(r.parent){const a=Kd(r.parent,u);if(a&&(r.type===f.DefinitionEntity&&a.type===f.DataType||r.type===f.Condition&&a.type===f.Condition))return Sd(a,u)}return r}else{const a=r.parent?Kd(r.parent,u):null;return a?Sd(a,u):null}}function Yp(d){if(d.type===f.Loop){const u=[...ri(d.successCalls).map(o=>({callee:o,callType:"success"})),...ri(d.errorCalls).map(o=>({callee:o,callType:"error"})),...(d.body?dt(d.body):[]).map(o=>({callee:o,callType:"loop-body"}))];return R(u.map(o=>o.callee)).map(o=>{var e;const p=(e=u.find(y=>y.callee===o))==null?void 0:e.callType;return{callee:o,callType:p}})}if(sr.includes(d.type)){const u=[...ri(d.successCalls).map(o=>({callee:o,callType:"success"})),...ri(d.errorCalls).map(o=>({callee:o,callType:"error"}))];return R(u.map(o=>o.callee)).map(o=>{var e;const p=(e=u.find(y=>y.callee===o))==null?void 0:e.callType;return{callee:o,callType:p}})}if(Dt.includes(d.type)){const u=[...ri(d.calls).map(o=>d.parent.type===f.Loop?{callee:o,callType:"loop-body"}:{callee:o,callType:"entry"})];return R(u.map(o=>o.callee)).map(o=>{var e;const p=(e=u.find(y=>y.callee===o))==null?void 0:e.callType;return{callee:o,callType:p}})}return[]}function Am(d){if(!d)return null;if(d.type===f.Condition&&d.parent.type===f.Condition)return Am(d.parent);if(xi.includes(d.type))return d;const u=d.parent;return u?Am(u):null}function P5(d){if(!d)return null;if(sr.includes(d.type))return d;const u=d.parent;return u?P5(u):null}function N5(d){if(!d)return null;if(wi.includes(d.type))return d;const u=d.parent;return u?N5(u):null}function uIe(d){return d.type===f.VariableDeclaration?[d]:sr.includes(d.type)?[...d.inputs,...d.outputs||[]]:hr.includes(d.type)?d.outputs:jo.includes(d.type)||d.type===f.FunctionDeclaration?d.inputs:[]}function cIe(d){const u=bn(d),r=[],a=[];Xg.includes(d.type)&&r.push(...bm(d));const o=u.filter(p=>{const e=r.includes(p);return e?!1:xi.includes(p.type)&&!e?(a.push(p),!1):!0});return r.sort((p,e)=>Il(e,p)?-1:0),a.sort((p,e)=>Il(e,p)?-1:0),[...r,...a,...o]}function V5(d){return[...d].sort((u,r)=>Il(r,u)?-1:0)}function pIe(d){const u=V5(d),r=[];return u.forEach(a=>{const o=r[r.length-1];if(o){const p=o[o.length-1];Il(a,p)?r.push([a]):o.push(a)}else r.push([a])}),r}function La(d){const u=d.map(r=>fr(r));return R(u)}function bm(d){return sr.includes(d.type)?[...La(d.successCalls),...La(d.errorCalls)]:Dt.includes(d.type)?La(d.calls):[]}function fIe(d,u){return bm(d).includes(u)}function wm(d){return d.writesValues||[]}function hIe(d,u){return wm(d).includes(u)}function L5(d){var u;return Tt.includes((u=d==null?void 0:d.readsValue)==null?void 0:u.type)?d.readsValue:null}function yIe(d){return d.writesValues}function M5(d=[]){return d.map(L5).filter(u=>!!u)}function Rm(d=[]){return d.map(u=>u.writesValues).flat().filter(u=>Tt.includes(u.type))}function B5(d=[]){return d.map(u=>u.readsValue).filter(u=>!!u&&Tt.includes(u.type))}function U5(d){return Tt.includes(d.type)?d:null}function x5(d){return d.writesValues.map(U5).filter(u=>!!u)}function j5(d=[]){return d.reduce((u,r)=>r.type===f.OutputMap?[...u,...x5(r)]:u,[])}function dt(d){return d.type===f.Loop?R([...ri(d.successCalls),...ri(d.errorCalls),...d.body?dt(d.body):[]]):sr.includes(d.type)?R([...ri(d.successCalls),...ri(d.errorCalls)]):Dt.includes(d.type)?R(ri(d.calls)):[]}function mIe(d){return sr.includes(d.type)?[...ri(d.successCalls),...ri(d.errorCalls)]:Dt.includes(d.type)?ri(d.calls):[]}function G5(d,u=new Set){return d.writesValues.filter(a=>Tt.includes(a.type)&&!u.has(a.id)).reduce((a,o)=>u.has(o.id)?a:[...a,...vr(o,u)],[])}function F5(d,u=new Set){var a;return(((a=d.readsValue)==null?void 0:a.writesValues)||[]).filter(o=>Tt.includes(o.type)&&!u.has(o.id)).reduce((o,p)=>u.has(p.id)?o:[...o,...vr(p,u)],[])}function vr(d,u=new Set){if(u.has(d.id))return[];if(d.type===f.ReturnStatement)return B5(d.outputs).reduce((a,o)=>[...a,...vr(o,u)],[]);if(d.type===f.FunctionCall||d.type===f.Operation||d.type===f.Condition)return[...dt(d).reduce((p,e)=>{const y=fr(e);return[...p,...vr(y||e,u)]},[]),...M5(d.inputs),...j5(d.outputs)].reduce((p,e)=>[...p,...vr(e,u)],[]);if(jo.includes(d.type)){const r=Rm(d.inputs),o=dt(d).reduce((p,e)=>{const y=fr(e);return[...p,...vr(y||e,u)]},[]);return r.push(...o),r.reduce((p,e)=>[...p,...vr(e,u)],[])}if(d.type===f.FunctionDeclaration){const r=[...Rm(d.inputs)],o=dt(d).reduce((p,e)=>{const y=fr(e);return[...p,...vr(y||e,u)]},[]);return r.push(...o),r.reduce((p,e)=>[...p,...vr(e)],[])}if(Tt.includes(d.type)){u.add(d.id);const a=dt(d).reduce((o,p)=>{const e=fr(p);return[...o,...vr(e||p,u)]},[]);return[d,...a,...F5(d,u),...G5(d,u)]}return[]}function ms(d,u=new Set){return u.has(d.id)?[]:(u.add(d.id),[...bn(d).reduce((o,p)=>[...o,p,...ms(p,u)],[])])}function ri(d){return d.reduce((u,r)=>r.type===f.ReturnStatement||r.type===f.ContinueStatement||r.type===f.BreakStatement?[...u,r]:[...u,r,...dt(r)],[])}function S5(d){const u=d.entities||[],r=[...u,...d.functions||[],...d.events||[],...d.projects||[]],a=u.reduce((v,E)=>[...v,...E.properties],[]),o=u.reduce((v,E)=>[...v,...E.methods],[]),p=o.reduce((v,E)=>[...v,...Rm(E.inputs),...ri(La(E.calls)),...E.returnStatements],[]),e=d.functions.reduce((v,E)=>[...v,...ri(La(E.calls)),...E.returnStatements],[]),y=d.events.reduce((v,E)=>[...v,...ri(La(E.calls)),...E.returnStatements],[]);return[...r,...a,...o,...p,...e,...y]}function K5(d,u){return u.filter(a=>{if(!a)return!1;switch(a.type){case f.FunctionCall:return a.inputs.find(o=>o.id===d.id)!==void 0||a.outputs.find(o=>o.id===d.id)!==void 0;case f.Condition:return a.successCalls.find(o=>o.id===d.id)!==void 0||a.errorCalls.find(o=>o.id===d.id)!==void 0||a.inputs.find(o=>o.id===d.id)!==void 0;case f.Operation:return a.outputs.find(o=>o.id===d.id)!==void 0;case f.VariableDeclaration:return sr.includes(d.type)?ES(d).find(p=>{var e;return((e=p.readsValue)==null?void 0:e.id)===a.id})!==void 0:!1;case f.DefinitionEntity:return a.properties.find(o=>o.id===d.id)!==void 0||a.methods.find(o=>o.id===d.id)!==void 0;case f.FunctionDeclaration:return a.inputs.find(o=>o.id===d.id)!==void 0||(a.returnStatements.map(o=>o.outputs).flat()||[]).find(o=>o.id===d.id)!==void 0;default:return!1}})}function vIe(d){const u=S5(d.project);return K5(d,u)}function Kd(d,u){return d?typeof d=="string"?u[d]:d.type===f.GenericReference?u[d.entityId]:u[d.id]?u[d.id]:null:null}function k5(d={},u){const r={};return Object.keys(d).forEach(a=>{const o=u.get(a)||a,p=d[a];r[o]=p}),r}function kd(d,u={},r={}){const a={ignoreBuiltInBaseEntities:!1,allBuiltInEntityIds:[],entityMaps:new Map,...r};if(a.ignoreBuiltInBaseEntities&&(Zi.includes(d.type)||(a.allBuiltInEntityIds||[]).includes(d.id)))return{upstream:{},downstream:{}};const o=d,p=d,e=d,y=d,v=d,E=d,w=d,A=d,$=d,V=d,B=d,F=d,K=d,q=[...K.readsValue?[K.readsValue]:[],...K.declaration?[K.declaration]:[],...(F.calledByEntry||[]).flatMap(Q=>Q),...(F.calledBySuccess||[]).flatMap(Q=>Q),...(F.calledByError||[]).flatMap(Q=>Q),...V.parent?[V.parent]:[]];Array.isArray(e.implements)?q.push(...e.implements.flatMap(Q=>Q)):$.implements&&q.push($.implements),Array.isArray(e.extends)?q.push(...e.extends.flatMap(Q=>Q)):$.extends&&q.push($.extends),v.valueAsTypeList&&Array.isArray(v.valueAsTypeList)&&q.push(...v.valueAsTypeList.flatMap(Q=>Q)),v.valueAsTypeSingle&&q.push(v.valueAsTypeSingle),(K.internalCalls||[]).forEach(Q=>{const ce=J(Q);if(ce&&u[ce]){const X=u[ce];[...X.calledByEntry||[],...X.calledBySuccess||[],...X.calledByError||[]].forEach(z=>{const pe=J(z);pe&&u[pe]&&q.push(u[pe])})}});const ie=[...(o.inputs||[]).flatMap(Q=>Q),...(B.inputsDeclarations||[]).flatMap(Q=>Q),...(o.outputs||[]).flatMap(Q=>Q),...(B.outputsDeclarations||[]).flatMap(Q=>Q),...(K.internalCalls||[]).flatMap(Q=>Q),...K.writesValues||[],...F.dataType?[F.dataType]:[],...E.body?[E.body]:[],...F.defaultValue?[F.defaultValue]:[],...(F.successCalls||[]).flatMap(Q=>Q),...(F.errorCalls||[]).flatMap(Q=>Q),...(e.properties||[]).flatMap(Q=>Q),...(e.methods||[]).flatMap(Q=>Q),...(e.abstractMethods||[]).flatMap(Q=>Q),...w.error?[w.error]:[],...w.process?[w.process]:[],...V.throws?[V.throws]:[],...(p.andChildrenGroup||[]).flatMap(Q=>Q),...(p.orChildrenGroup||[]).flatMap(Q=>Q),...(A.entities||[]).flatMap(Q=>Q),...(A.functions||[]).flatMap(Q=>Q),...(A.functionCalls||[]).flatMap(Q=>Q),...(A.events||[]).flatMap(Q=>Q),...(A.conditions||[]).flatMap(Q=>Q),...(A.operations||[]).flatMap(Q=>Q),...(A.loops||[]).flatMap(Q=>Q),...(A.variableDeclarations||[]).flatMap(Q=>Q),...(A.variableInstances||[]).flatMap(Q=>Q),...(A.searches||[]).flatMap(Q=>Q),...(A.projects||[]).flatMap(Q=>Q),...(y.calls||[]).flatMap(Q=>Q)];d.type===f.DataType&&(p.entity&&u[J(p.entity)]&&u[J(p.entity)].parent&&J(u[J(p.entity)].parent)===d.id?ie.push(p.entity):p.entity&&q.push(p.entity)),(K.internalCalls||[]).forEach(Q=>{const ce=J(Q);if(ce&&u[ce]){const X=u[ce];[...X.successCalls||[],...X.errorCalls||[]].forEach(z=>{const pe=J(z);pe&&u[pe]&&ie.push(u[pe])})}});const W={},de={};return q.forEach(Q=>{var z;const ce=J(Q);if(ce&&a.ignoreBuiltInBaseEntities&&(Zi.includes(Q.type)||(a.allBuiltInEntityIds||[]).includes(ce)))return;const X=Q.version;if(ce){const pe=((z=a.entityMaps)==null?void 0:z.get(ce))||ce;W[pe]=X}}),ie.forEach(Q=>{var z;const ce=J(Q);if(ce&&a.ignoreBuiltInBaseEntities&&(Zi.includes(Q.type)||(a.allBuiltInEntityIds||[]).includes(ce)))return;const X=Q.version;if(ce){const pe=((z=a.entityMaps)==null?void 0:z.get(ce))||ce;de[pe]=X}}),{upstream:W,downstream:de}}function EIe(d,u){const r=[];if(xi.includes(d.type)){Ms(d).forEach(p=>{const e=Sd(p,u);e&&r.push(e)});const o=[...d.inputs||[],...d.outputs||[]].map(p=>{const e=Kd(p,u);return e?IS(e,u):null}).filter(p=>p!==null);r.push(...R(o))}if(Tt.includes(d.type)){const a=gm(d);a&&r.push(a)}return R(r)}function Ao(d){const u=[];if(xi.includes(d.type)){d.calledBy.forEach(o=>{const p=fr(o);p&&u.push(p)});const a=[...d.inputs||[],...d.outputs||[]].map(o=>gm(o)).filter(o=>o!==null);u.push(...R(a))}if(Tt.includes(d.type)){const r=gm(d);r&&u.push(r)}return R(u)}function Ms(d){return[...d.calledByEntry||[],...d.calledByError||[],...d.calledBySuccess||[]].filter(u=>u.type!==f.GenericReference)}function q5(d,u=new Set,r={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.ActionDescriptor)throw new Error("Entity must be an action descriptor to be flattened");return[d,...d.inputs.flatMap(a=>me(a,u,r)),...d.outputs.flatMap(a=>me(a,u,r)),...d.error?me(d.error,u,r):[],...d.parent?me(d.parent,u,r):[]]}function Z5(d,u=new Set,r={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.ArgumentDeclaration)throw new Error("Entity must be an argument declaration to be flattened");return[d,...d.defaultValue?me(d.defaultValue,u):[],...d.writesValues.flatMap(a=>me(a,u,r)),...d.dataType?me(d.dataType,u,r):[],...d.parent?me(d.parent,u,r):[]]}function H5(d,u=new Set,r={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.BreakStatement)throw new Error("Entity must be a break statement to be flattened");return[d,...d.outputs.flatMap(a=>me(a,u,r)),...d.throws?me(d.throws,u,r):[],...(Ms(d)||[]).flatMap(a=>me(a,u,r)),...d.parent?me(d.parent,u,r):[]]}function J5(d,u=new Set,r={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.BuiltInBaseEntity)throw new Error("Entity must be a built-in base entity to be flattened");return[d,...(d.properties||[]).flatMap(a=>me(a,u,r)),...(d.methods||[]).flatMap(a=>me(a,u,r)),...(d.abstractMethods||[]).flatMap(a=>me(a,u,r)),...d.extends?me(d.extends,u,r):[]]}function W5(d,u=new Set,r={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.Condition)throw new Error("Entity must be a condition to be flattened");return[d,...(d.andChildrenGroup||[]).flatMap(a=>me(a,u,r)),...(d.orChildrenGroup||[]).flatMap(a=>me(a,u,r)),...(d.inputs||[]).flatMap(a=>me(a,u,r)),...(d.successCalls||[]).flatMap(a=>me(a,u,r)),...(d.errorCalls||[]).flatMap(a=>me(a,u,r)),...(Ms(d)||[]).flatMap(a=>me(a,u,r)),...d.parent?me(d.parent,u,r):[]]}function Y5(d,u=new Set,r={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.ContinueStatement)throw new Error("Entity must be a continue statement to be flattened");return[d,...d.outputs.flatMap(a=>me(a,u,r)),...d.throws?me(d.throws,u,r):[],...(Ms(d)||[]).flatMap(a=>me(a,u,r)),...d.parent?me(d.parent,u,r):[]]}function z5(d,u=new Set,r={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.DefinitionEntity)throw new Error("Entity must be a definition entity to be flattened");return[d,...d.extends?me(d.extends,u,r):[],...(d.implements||[]).flatMap(a=>me(a,u,r)),...(d.properties||[]).flatMap(a=>me(a,u,r)),...(d.methods||[]).flatMap(a=>me(a,u,r)),...(d.abstractMethods||[]).flatMap(a=>me(a,u,r)),...d.parent?me(d.parent,u,r):[]]}function X5(d,u=new Set,r={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.DataType)throw new Error("Entity must be a data type to be flattened");return[d,...(d.andChildrenGroup||[]).flatMap(a=>me(a,u,r)),...(d.orChildrenGroup||[]).flatMap(a=>me(a,u,r)),...d.entity?me(d.entity,u,r):[],...d.parent?me(d.parent,u,r):[]]}function Q5(d,u=new Set,r={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.FunctionCall)throw new Error("Entity must be a function call to be flattened");return[d,...(d.inputs||[]).flatMap(a=>me(a,u,r)),...(d.outputs||[]).flatMap(a=>me(a,u,r)),...d.error?me(d.error,u,r):[],...d.process?me(d.process,u,r):[],...(Ms(d)||[]).flatMap(a=>me(a,u,r)),...(d.successCalls||[]).flatMap(a=>me(a,u,r)),...(d.errorCalls||[]).flatMap(a=>me(a,u,r)),...d.parent?me(d.parent,u,r):[]]}function eS(d,u=new Set,r={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.FunctionDeclaration)throw new Error("Entity must be a function declaration to be flattened");return[d,...(d.inputs||[]).flatMap(a=>me(a,u,r)),...(d.calls||[]).flatMap(a=>me(a,u,r)),...d.implements?me(d.implements,u,r):[],...d.parent?me(d.parent,u,r):[]]}function tS(d,u=new Set,r={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.GlobalEvent)throw new Error("Entity must be a global event to be flattened");return[d,...(d.inputs||[]).flatMap(a=>me(a,u,r)),...(d.calls||[]).flatMap(a=>me(a,u,r)),...d.implements?me(d.implements,u,r):[],...d.parent?me(d.parent,u,r):[]]}function rS(d,u=new Set,r={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.InputMap)throw new Error("Entity must be an input map to be flattened");return[d,...d.readsValue?me(d.readsValue,u,r):[],...d.declaration?me(d.declaration,u,r):[],...d.defaultValue?me(d.defaultValue,u,r):[],...d.parent?me(d.parent,u,r):[]]}function iS(d,u=new Set,r={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.InstalledProject)throw new Error("Entity must be an installed project to be flattened");return[d,...(d.functions||[]).flatMap(a=>me(a,u,r)),...(d.events||[]).flatMap(a=>me(a,u,r)),...d.parent?me(d.parent,u,r):[]]}function sS(d,u=new Set,r={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.InternalCall)throw new Error("Entity must be an internal call to be flattened");return[d,...(d.successCalls||[]).flatMap(a=>me(a,u,r)),...(d.errorCalls||[]).flatMap(a=>me(a,u,r)),...(d.inputs||[]).flatMap(a=>me(a,u,r)),...(d.outputs||[]).flatMap(a=>me(a,u,r)),...(Ms(d)||[]).flatMap(a=>me(a,u,r)),...d.error?me(d.error,u,r):[],...d.process?me(d.process,u,r):[],...d.parent?me(d.parent,u,r):[]]}function nS(d,u=new Set,r={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.LiteralValue)throw new Error("Entity must be a literal value to be flattened");return[d,...d.valueAsTypeSingle?me(d.valueAsTypeSingle,u,r):[],...d.valueAsTypeList&&Array.isArray(d.valueAsTypeList)?d.valueAsTypeList.flatMap(a=>me(a,u,r)):[],...d.parent?me(d.parent,u,r):[]]}function aS(d,u=new Set,r={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.Loop)throw new Error("Entity must be a loop to be flattened");return[d,...(d.inputs||[]).flatMap(a=>me(a,u,r)),...(d.outputs||[]).flatMap(a=>me(a,u,r)),...(d.successCalls||[]).flatMap(a=>me(a,u,r)),...(d.errorCalls||[]).flatMap(a=>me(a,u,r)),...d.error?me(d.error,u,r):[],...d.process?me(d.process,u,r):[],...d.body?me(d.body,u,r):[],...(Ms(d)||[]).flatMap(a=>me(a,u,r)),...d.parent?me(d.parent,u,r):[]]}function oS(d,u=new Set,r={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.Operation)throw new Error("Entity must be an operation to be flattened");return[d,...(d.successCalls||[]).flatMap(a=>me(a,u,r)),...(d.errorCalls||[]).flatMap(a=>me(a,u,r)),...(d.inputs||[]).flatMap(a=>me(a,u,r)),...(d.outputs||[]).flatMap(a=>me(a,u,r)),...d.error?me(d.error,u,r):[],...d.process?me(d.process,u,r):[],...(Ms(d)||[]).flatMap(a=>me(a,u,r)),...d.parent?me(d.parent,u,r):[]]}function lS(d,u=new Set,r={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.OutputMap)throw new Error("Entity must be an output map to be flattened");return[d,...(d.writesValues||[]).flatMap(a=>me(a,u,r)),...d.declaration?me(d.declaration,u,r):[],...d.defaultValue?me(d.defaultValue,u,r):[],...d.parent?me(d.parent,u,r):[]]}function dS(d,u=new Set,r={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.PrimitiveEntity)throw new Error("Entity must be a primitive entity to be flattened");return[d,...(d.properties||[]).flatMap(a=>me(a,u,r)),...(d.methods||[]).flatMap(a=>me(a,u,r)),...(d.abstractMethods||[]).flatMap(a=>me(a,u,r))]}function uS(d,u=new Set,r={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.Project)throw new Error("Entity must be a project to be flattened");return[d,...(d.entities||[]).flatMap(a=>me(a,u,r)),...(d.functions||[]).flatMap(a=>me(a,u,r)),...(d.events||[]).flatMap(a=>me(a,u,r)),...(d.projects||[]).flatMap(a=>me(a,u,r)),...(d.variableDeclarations||[]).flatMap(a=>me(a,u,r)),...(d.variableInstances||[]).flatMap(a=>me(a,u,r)),...(d.operations||[]).flatMap(a=>me(a,u,r)),...(d.conditions||[]).flatMap(a=>me(a,u,r)),...(d.functionCalls||[]).flatMap(a=>me(a,u,r)),...(d.projects||[]).flatMap(a=>me(a,u,r)),...(d.loops||[]).flatMap(a=>me(a,u,r)),...(d.searches||[]).flatMap(a=>me(a,u,r))]}function cS(d,u=new Set,r={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.Property)throw new Error("Entity must be a property to be flattened");return[d,...d.defaultValue?me(d.defaultValue,u,r):[],...d.dataType?me(d.dataType,u,r):[],...d.parent?me(d.parent,u,r):[]]}function pS(d,u=new Set,r={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.ReturnDeclaration)throw new Error("Entity must be a return declaration to be flattened");return[d,...d.readsValue?me(d.readsValue,u,r):[],...d.defaultValue?me(d.defaultValue,u,r):[],...d.dataType?me(d.dataType,u,r):[],...d.parent?me(d.parent,u,r):[]]}function fS(d,u=new Set,r={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.ReturnStatement)throw new Error("Entity must be a return statement to be flattened");return[d,...(d.outputs||[]).flatMap(a=>me(a,u,r)),...d.throws?me(d.throws,u,r):[],...(Ms(d)||[]).flatMap(a=>me(a,u,r)),...d.parent?me(d.parent,u,r):[]]}function hS(d,u=new Set,r={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.Search)throw new Error("Entity must be a search to be flattened");return[d,...(d.successCalls||[]).flatMap(a=>me(a,u,r)),...(d.errorCalls||[]).flatMap(a=>me(a,u,r)),...(d.inputsDeclarations||[]).flatMap(a=>me(a,u,r)),...(d.inputs||[]).flatMap(a=>me(a,u,r)),...(d.outputsDeclarations||[]).flatMap(a=>me(a,u,r)),...(d.outputs||[]).flatMap(a=>me(a,u,r)),...d.error?me(d.error,u,r):[],...(Ms(d)||[]).flatMap(a=>me(a,u,r)),...d.parent?me(d.parent,u,r):[]]}function yS(d,u=new Set,r={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.ValueDescriptor)throw new Error("Entity must be a value descriptor to be flattened");return[d,...d.defaultValue?me(d.defaultValue,u,r):[],...d.dataType?me(d.dataType,u,r):[],...d.parent?me(d.parent,u,r):[]]}function mS(d,u=new Set,r={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.VariableDeclaration)throw new Error("Entity must be a variable declaration to be flattened");return[d,...(d.successCalls||[]).flatMap(a=>me(a,u,r)),...(d.errorCalls||[]).flatMap(a=>me(a,u,r)),...(d.inputs||[]).flatMap(a=>me(a,u,r)),...(d.outputs||[]).flatMap(a=>me(a,u,r)),...(d.internalCalls||[]).flatMap(a=>me(a,u,r)),...(d.writesValues||[]).flatMap(a=>me(a,u,r)),...d.readsValue?me(d.readsValue,u,r):[],...d.defaultValue?me(d.defaultValue,u,r):[],...(Ms(d)||[]).flatMap(a=>me(a,u,r)),...d.dataType?me(d.dataType,u,r):[],...d.parent?me(d.parent,u,r):[]]}function vS(d,u=new Set,r={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.VariableInstance)throw new Error("Entity must be a variable instance to be flattened");return[d,...(d.successCalls||[]).flatMap(a=>me(a,u,r)),...(d.errorCalls||[]).flatMap(a=>me(a,u,r)),...(d.inputs||[]).flatMap(a=>me(a,u,r)),...(d.outputs||[]).flatMap(a=>me(a,u,r)),...(d.internalCalls||[]).flatMap(a=>me(a,u,r)),...(d.writesValues||[]).flatMap(a=>me(a,u,r)),...d.readsValue?me(d.readsValue,u,r):[],...d.defaultValue?me(d.defaultValue,u,r):[],...(Ms(d)||[]).flatMap(a=>me(a,u,r)),...d.declaration?me(d.declaration,u,r):[],...d.parent?me(d.parent,u,r):[]]}function zs(){const d=new Set,u=KL.flatMap(r=>me(r,d)).map(r=>r.id);if(!u.includes("http-request-error-return-delaration-id"))throw new Error("Built-in base entities must be included in the list");return u}function me(d,u=new Set,r={ignoreBuiltInBaseEntities:!1}){if(!d)throw new Error("Entity must be defined to be flattened");if(d.type===f.GenericReference)return[];if(r.ignoreBuiltInBaseEntities&&(Zi.includes(d.type)||zs().includes(d.id)))return[];if(u.has(d.id))return[];switch(d.type){case f.FunctionCall:return Q5(d,u,r);case f.Operation:return oS(d,u,r);case f.Condition:return W5(d,u,r);case f.Loop:return aS(d,u,r);case f.Search:return hS(d,u,r);case f.GlobalEvent:return tS(d,u,r);case f.ReturnStatement:return fS(d,u,r);case f.ContinueStatement:return Y5(d,u,r);case f.BreakStatement:return H5(d,u,r);case f.VariableDeclaration:return mS(d,u,r);case f.DefinitionEntity:return z5(d,u,r);case f.FunctionDeclaration:return eS(d,u,r);case f.Project:return uS(d,u,r);case f.ActionDescriptor:return q5(d,u,r);case f.ArgumentDeclaration:return Z5(d,u,r);case f.ReturnDeclaration:return pS(d,u,r);case f.ValueDescriptor:return yS(d,u,r);case f.InputMap:return rS(d,u,r);case f.OutputMap:return lS(d,u,r);case f.DataType:return X5(d,u,r);case f.InstalledProject:return iS(d,u,r);case f.InternalCall:return sS(d,u,r);case f.LiteralValue:return nS(d,u,r);case f.Property:return cS(d,u,r);case f.VariableInstance:return vS(d,u,r);case f.BuiltInBaseEntity:return r.ignoreBuiltInBaseEntities?[]:J5(d,u,r);case f.PrimitiveEntity:return r.ignoreBuiltInBaseEntities?[]:dS(d,u,r)}return[]}function hb(d){return d.type===f.FunctionCall||d.type===f.InternalCall||[f.Operation,f.Condition,f.Loop].includes(d.type)?d.declaration.inputs:d.type===f.FunctionDeclaration||jo.includes(d.type)?d.inputs:d.type===f.Search?d.inputsDeclarations:[]}function TIe(d,u){return u.type===f.Condition?u.inputs.find(r=>r.declaration.id===d.id):u.type===f.FunctionCall||u.type===f.Operation?u.inputs.find(r=>r.declaration.id===d.id):null}function ES(d){return sr.includes(d.type)?d.inputs:[]}function TS(d){var u;return d.type===f.FunctionCall?((u=d.declaration.returnStatements[0])==null?void 0:u.outputs)||[]:[f.Operation,f.Condition,f.Loop].includes(d.type)?d.declaration.outputs:d.type===f.Search?d.outputsDeclarations:hr.includes(d.type)?d.outputs:[]}function IIe(d,u){return u.type===f.Condition?null:(u.type===f.FunctionCall||u.type===f.Operation)&&u.outputs.find(r=>{var a;return((a=r.declaration)==null?void 0:a.id)===d.id})||null}function AIe(d){return d.type===f.Condition?[]:sr.includes(d.type)?d.outputs:[]}function gm(d){const u=d.readsValue;return u?fr(u):null}function IS(d,u){const r=d.readsValue;return r?Sd(r,u):null}function AS(d){const u=d.internalCalls||[];return R(La(R(u.flatMap(r=>[...r.successCalls,...r.errorCalls]))))}function bS(d){const u=d.internalCalls||[];return R(R(u.flatMap(r=>[...r.successCalls,...r.errorCalls])))}function qd(d){const u=wm(d),r=[];return u.forEach(a=>{if(Tt.includes(a.type))r.push(a);else if(un.includes(a.type)){const o=fr(a.parent);r.push(o)}}),r}function Zd(d){const u=wm(d),r=[];return u.forEach(a=>{if(Tt.includes(a.type))r.push(a);else if(un.includes(a.type)){const o=a.parent;r.push(o)}}),r}function R(d){const u=new Set;return d.filter(r=>!r||u.has(r.id)?!1:(u.add(r.id),!0))}function wS(d){return d.type===f.Project?null:$v.includes(d.type)?d:Zi.includes(d.type)?null:d.parent?wS(d.parent):null}function bn(d,u=!1){const r=[];if(d.type===f.Project&&r.push(...(d==null?void 0:d.entities)||[],...(d==null?void 0:d.functions)||[],...(d==null?void 0:d.variableDeclarations)||[],...(d==null?void 0:d.variableInstances)||[],...(d==null?void 0:d.searches)||[],...(d==null?void 0:d.loops)||[],...(d==null?void 0:d.operations)||[],...(d==null?void 0:d.conditions)||[],...(d==null?void 0:d.functionCalls)||[],...(d==null?void 0:d.events)||[],...(d==null?void 0:d.projects)||[]),Nr.includes(d.type)&&r.push(...(d==null?void 0:d.detachedChildren)||[]),d.type===f.DefinitionEntity){const a=[...d.suggestedMethods,...d.methods].flatMap(o=>o.collapsed&&u?[]:bn(o));r.push(...a)}if(d.type===f.Condition){const a=d.successCalls.map(p=>fr(p)),o=d.errorCalls.map(p=>fr(p));r.push(...a,...o)}if(jo.includes(d.type)){if(d.collapsed&&u)return[];const a=d.inputs.map(p=>qd(p)).flat(),o=d.calls.map(p=>fr(p));r.push(...R(a),...o)}if(sr.includes(d.type)&&d.type!==f.Condition&&d.type!==f.Loop){const a=d==null?void 0:d.outputs.map(e=>qd(e)).flat(),o=d.successCalls.map(e=>fr(e)),p=d.errorCalls.map(e=>fr(e));r.push(...R(a),...o,...p)}if(Tt.includes(d.type)){const a=qd(d),o=AS(d);r.push(...a,...o)}if(d.type===f.Loop){const a=d.outputs.map(e=>qd(e)).flat();if(d.body){const e=bn(d.body,u);r.push(...e)}const o=d.errorCalls.map(e=>fr(e)),p=d.successCalls.map(e=>fr(e));r.push(...R(a),...p,...o)}if(d.type===f.FunctionDeclaration){if(d.collapsed&&u)return[];const a=d.inputs.map(p=>qd(p)).flat(),o=d.calls.map(p=>fr(p));r.push(...R(a),...o)}return R(r)}function _m(d,u=!1){const r=[];if(d.type===f.Project&&r.push(...(d==null?void 0:d.variableDeclarations)||[],...(d==null?void 0:d.variableInstances)||[],...(d==null?void 0:d.searches)||[],...(d==null?void 0:d.loops)||[],...(d==null?void 0:d.operations)||[],...(d==null?void 0:d.conditions)||[],...(d==null?void 0:d.functionCalls)||[]),Nr.includes(d.type)&&r.push(...(d==null?void 0:d.detachedChildren)||[]),d.type===f.DefinitionEntity){const a=[...d.suggestedMethods,...d.methods].flatMap(o=>o.collapsed&&u?[]:_m(o));r.push(...a)}if(d.type===f.Condition){const a=d.successCalls,o=d.errorCalls;r.push(...a,...o)}if(jo.includes(d.type)){if(d.collapsed&&u)return[];const a=d.inputs.map(p=>Zd(p)).flat(),o=d.calls;r.push(...R(a),...o)}if(sr.includes(d.type)&&d.type!==f.Condition&&d.type!==f.Loop){const a=d==null?void 0:d.outputs.map(e=>Zd(e)).flat(),o=d.successCalls,p=d.errorCalls;r.push(...R(a),...o,...p)}if(Tt.includes(d.type)){const a=Zd(d),o=bS(d);r.push(...a,...o)}if(d.type===f.Loop){const a=d.outputs.map(e=>Zd(e)).flat();if(d.body){const e=_m(d.body,u);r.push(...e)}const o=d.errorCalls,p=d.successCalls;r.push(...R(a),...p,...o)}if(d.type===f.FunctionDeclaration){if(d.collapsed&&u)return[];const a=d.inputs.map(p=>Zd(p)).flat(),o=d.calls;r.push(...R(a),...o)}return R(r)}function Dm(d,u=!1){const r=bn(d,u),a=[...r,...r.reduce((o,p)=>[...o,...Dm(p,u)],[])];return R(a)}function RS(d,u=!1){const r=_m(d,u),a=[...r,...r.reduce((o,p)=>[...o,...RS(p,u)],[])];return R(a)}function gS(d){const u=Ao(d),r=[...u,...u.reduce((a,o)=>[...a,...gS(o)],[])];return R(r)}function zp(d){return d.implements.reduce((u,r)=>r.type===f.DefinitionEntity?[...u,f.DefinitionEntity,...zp(r),...Xp(r)]:[...u,r.name],[])}function Xp(d){return d.extends?d.extends.type===f.DefinitionEntity?[f.DefinitionEntity,...Xp(d.extends),...zp(d.extends)]:[d.extends.name]:[]}function yb(d){return d.extends?d.extends.type===f.DefinitionEntity?[d.extends,...yb(d.extends),...mb(d.extends)]:[d.extends]:[]}function mb(d){return d.implements.reduce((u,r)=>r.type===f.DefinitionEntity?[...u,r,...mb(r),...yb(r)]:[...u,r],[])}function Hd(d){return[...Xp(d),...zp(d)].filter((r,a,o)=>o.indexOf(r)===a)}function vb(d){return d.implements.length===0&&!d.extends?null:d.implements.find(a=>a.type===f.BuiltInBaseEntity&&a.name===Le.PERSISTED_ENTITY)?d:[...d.implements,...d.extends?[d.extends]:[]].reduce((a,o)=>{if(o.type===f.DefinitionEntity){const p=vb(o);if(p)return p}return a},null)}function bIe(d){return d.extends&&d.extends.type===f.BuiltInBaseEntity?d.extends:null}function wIe(d){const u=d.implements.find(r=>r.type===f.BuiltInBaseEntity);return u&&u.type===f.BuiltInBaseEntity?u:null}function Om(d){return d.extends&&d.extends.type===f.DefinitionEntity?d.extends:null}function Vi(d){if(d.type===f.BuiltInBaseEntity)return[d];const u=[...d.implements,...d.extends?[d.extends]:[]].reduce((r,a)=>a.type===f.BuiltInBaseEntity?[...r,a]:a.type===f.DefinitionEntity?[...r,...Vi(a)]:r,[]);return R(u)}function Qp(d){return d.type===f.PrimitiveEntity?!0:d.type===f.BuiltInBaseEntity?d.interactive:!Vi(d).find(a=>!a.interactive)}function RIe(d){return d.parent===d.project&&d.project.variableDeclarations.includes(d)}function Eb(d){return d.parent!==d.project?!1:f.VariableDeclaration===d.type?d.project.variableDeclarations.includes(d):f.VariableInstance===d.type?d.project.variableInstances.includes(d):f.FunctionCall===d.type?d.project.functionCalls.includes(d):f.Condition===d.type?d.project.conditions.includes(d):f.Operation===d.type?d.project.operations.includes(d):f.Loop===d.type?d.project.loops.includes(d):f.Search===d.type?d.project.searches.includes(d):!1}function _S(d){if([...Dt,f.DefinitionEntity,f.InstalledProject,f.Project].includes(d.type)||Eb(d))return!1;const u=Ao(d);return u.length===0?!0:u.some(r=>_S(r))}function Tb(d){return[...Dt,f.DefinitionEntity,f.InstalledProject,f.Project].includes(d.type)||Eb(d)?!1:Ao(d).length===0}function DS(d,u=0){if(Tb(d)){const r=Ao(d);return r.length===0?d:r.map(o=>DS(o,u+1)).reduce((o,p)=>o?p&&p.x<o.x?p:o:p,null)}return null}function OS(d){const u=[];if(Tb(d))u.push(d);else return[];return Ao(d).forEach(a=>{u.push(...OS(a))}),u}function Ib(d){return d.type===f.FunctionDeclaration&&d.parent!==d.project&&!![f.DefinitionEntity,f.Loop,f.InstalledProject].includes(d.parent.type)}function gIe(d,u){const r=new Map;return d.forEach(a=>{r.set(a.id,a)}),u.forEach(a=>{r.set(a.id,a)}),Array.from(r.values())}function ef(d){switch(d){case f.DefinitionEntity:return Qn;case f.FunctionDeclaration:return Qa;case f.VariableDeclaration:return oo;case f.VariableInstance:return ao;case f.FunctionCall:return To;case f.Operation:return eo;case f.Condition:return io;case f.ReturnStatement:return to;case f.Loop:return Gi;case f.Search:return lo;case f.InputMap:return Wn;case f.OutputMap:return In;case f.ArgumentDeclaration:return kn;case f.ReturnDeclaration:return Qi;case f.Property:return Xn;case f.InstalledProject:return uo;case f.Project:return N;case f.DataType:return fs;case f.GlobalEvent:return ro;case f.InternalCall:return co;case f.ValueDescriptor:return An;case f.BuiltInBaseEntity:return ea;case f.PrimitiveEntity:return ts;case f.ActionDescriptor:return ct;case f.LiteralValue:return Ki;case f.ContinueStatement:return Pi;case f.BreakStatement:return po;default:return null}}function Di(d,u,r=null){const a=d!=null&&d.parent?J(d==null?void 0:d.parent):null;let o=a?u.get(a):null,p=r||d;if((d==null?void 0:d.id)===(u==null?void 0:u.id))return u;if(d.type===f.ReturnStatement)return Hr(d,u,p);if(d.type===f.FunctionDeclaration&&(o==null?void 0:o.type)===f.Loop)return o;if(Dt.includes(d.type))return d;if(d.type===f.Loop)return p.id===d.id?o:d;if(Zi.includes(d.type))return null;const e=d.parent;if(!e)return null;if(e.type===f.GenericReference){const y=J(e);if(!y)return null;const v=u.get(y);return v?Di(v,u,p):null}else return e===u?u:Di(e,u,p)}function Hr(d,u,r=null){const a=d!=null&&d.parent?J(d==null?void 0:d.parent):null;let o=a?u.get(a):null,p=r||d;if(d.type===f.FunctionDeclaration&&(o==null?void 0:o.type)===f.Loop)return Hr(o.parent,u,p);if(Dt.includes(d.type))return d;if(Zi.includes(d.type))return null;const e=d.parent;if(!e)return null;if(e.type===f.GenericReference){const y=J(e);if(!y)return null;const v=u.get(y);return v?Hr(v,u,p):null}else return e===u?u:Hr(e,u,p)}function Jd(d,u){if(Zi.includes(d.type))return Me.warn(`getRootEntryPointScopeOwner is \`null\` because it was called with a built-in entity type: ${d.type}`),null;if(u.getBuiltIn(d.id))return Me.warn(`getRootEntryPointScopeOwner is \`null\` because it was called with a built-in entity: ${d.id}`),null;const r=qi(d.parent,u);return r?r===u?Nr.includes(d.type)?d:(Me.warn(`getRootEntryPointScopeOwner is \`null\` because it was called with an entity that has the project as parent: ${d.id}`),null):r.type===f.DefinitionEntity?d:Jd(r,u):(Me.warn(`getRootEntryPointScopeOwner is \`null\` because it was called with an entity that has no parent: ${d.id}`),null)}function Cm(d,u,r){if(d===u||u===r||d===r||!d||!u)return!1;const a=Di(u.parent,r);return a===r?!1:a===d?!0:Cm(a,u,r)}var $m=(d=>(d.SameBothLocal="same-both-local",d.AInB="a-in-b",d.BInA="b-in-a",d.ParallelInCommonParent="parallel-in-common-parent",d.ParallelInProject="parallel-in-project",d.AIsGlobalBIsNot="a-is-global-b-is-not",d.BIsGlobalAIsNot="b-is-global-a-is-not",d.SameBothGlobal="same-both-global",d))($m||{});function Xs(d,u,r){const a=Di(d,r),o=Di(u,r);if(!a)throw new Error("Could not find scope owner for the entity: "+d.id);if(!o)throw new Error("Could not find scope owner for the entity: "+u.id);if(a===o&&a.type!==f.Project)return{compatible:!0,type:"same-both-local",commonAncestorScope:a};if(a===o&&a.type===f.Project)return{compatible:!0,type:"same-both-global",commonAncestorScope:a};if(a.type===f.Project&&o.type!==f.Project)return{compatible:!1,type:"a-is-global-b-is-not",commonAncestorScope:a};if(a.type!==f.Project&&o.type===f.Project)return{compatible:!1,type:"b-is-global-a-is-not",commonAncestorScope:o};if(Cm(a,o,r))return{compatible:!0,type:"b-in-a",commonAncestorScope:a};if(Cm(o,a,r))return{compatible:!0,type:"a-in-b",commonAncestorScope:o};const y=fb(a,o);return y===r?{compatible:!1,type:"parallel-in-project",commonAncestorScope:y}:y?{compatible:!1,type:"parallel-in-common-parent",commonAncestorScope:Di(y,r)}:{compatible:!1,type:"parallel-in-project",commonAncestorScope:r}}function CS(d,u,r){const a=Xs(d,u,r);if(!a.compatible||a.type!=="same-both-local")return null;if(d===u)return d;let o=Di(d.parent,r);if(o){if(o===u)return u;if(o.type===f.Project)return d}else return d;for(;o;){if(o){if(o===u)return u;if(o.type===f.Project)return d}else return d;o=Di(o.parent,r)}let p=Di(u.parent,r);if(p){if(p===d)return d;if(p.type===f.Project)return u}else return u;for(;p;){if(p){if(p===d)return d;if(p.type===f.Project)return u}else return u;p=Di(p.parent,r)}return null}function $S(d){return d.length===0?null:d.length===1?d[0]:d.reduce((r,a)=>{const o=CS(r,a,a.project);return!o||o===a?r:a},d[0])}function qi(d,u){if(!d)return null;let r;return typeof d=="string"?r=d:d.type===f.GenericReference?r=J(d):r=d.id,r===u.id?u:u.get(r)}function bo(d){if(!d)return null;if(Zi.includes(d.type))return d;if(d.type===f.Project)return null;if(d.project.getBuiltIn(d.id))return d;const u=d.parent;return!u||u.type===f.Project?null:bo(u)}function tf(d){const u=[];function r(p,e){return u.some(y=>y.blockedByCaller===p&&y.blockedByCalling===e)}function a(p,e){r(p,e)||u.push({blockedByCaller:p,blockedByCalling:e})}const o=Jd(d,d.project);return o?(d.calledBySuccess.forEach(p=>{[...p.successCalls||[]].forEach(v=>{hr.includes(v.type)&&v!==d&&(dt(d).find(A=>A===v)||a(p,v))});let y;if(sr.includes(p.type)&&(y=p),y){const v=tf(y);v.reachable||dt(d).find(A=>A===p)||v.blocks.forEach(A=>{a(p,A.blockedByCalling)})}}),d.calledByError.forEach(p=>{[...p.errorCalls||[]].forEach(v=>{hr.includes(v.type)&&v!==d&&(dt(d).find(A=>A===v)||a(p,v))});let y;if(sr.includes(p.type)&&(y=p),y){const v=tf(y);v.reachable||dt(d).find(A=>A===p)||v.blocks.forEach(A=>{a(p,A.blockedByCalling)})}}),d.calledByEntry.forEach(p=>{if([...p.calls||[]].forEach(v=>{hr.includes(v.type)&&v!==d&&(dt(d).find(A=>A===v)||a(p,v))}),p===o)return;let y;if(p.type===f.FunctionDeclaration){const v=fr(p);if(v.type===f.DefinitionEntity)return;v.type===f.Loop&&(y=v)}if(y){const v=tf(y);v.reachable||v.blocks.forEach(E=>{a(p,E.blockedByCalling)})}}),{reachable:u.length===0,entryPoint:o,blocks:u}):{reachable:!0,entryPoint:null,blocks:[]}}function _Ie(d){return th.includes(d.type)?d.type===f.FunctionDeclaration?!Ib(d):!0:!1}function DIe(d){if(f.ActionDescriptor===d.type){if(d.project.operationDeclarations.find(p=>p.id===d.id))return f.Operation;if(d.project.globalEventActionDescriptors.find(p=>p.id===d.id))return f.GlobalEvent;if(d.project.loopDeclarations.find(p=>p.id===d.id))return f.Loop;if(d.project.conditionDeclarations.find(p=>p.id===d.id))return f.Condition}return d.type}function Pm(d,u){return d.type===f.BuiltInBaseEntity?d.name===u:!!Xp(d).includes(u)}function OIe(d,u){return d.type===f.BuiltInBaseEntity?d.name===u:!!zp(d).includes(u)}function es(d,u){return d.type===f.BuiltInBaseEntity?d.name===u:!!Hd(d).includes(u)}function CIe(d){const u=[];return d.entities.forEach(r=>{if(Pm(r,Le.PERSISTED_ENTITY)){u.push(r);return}}),R(u)}function $Ie(d){const u=[];return d.entities.forEach(r=>{if(Pm(r,Le.RELATIONAL_DATABASE)){u.push(r);return}}),R(u)}function PIe(d){return d.type!==f.DefinitionEntity||d.abstract||!Pm(d,Le.PERSISTED_ENTITY)?null:(d==null?void 0:d.properties.find(r=>{var a;return((a=r.implements)==null?void 0:a.id)===he[f.BuiltInBaseEntity][Le.PERSISTED_ENTITY].properties.primaryKey.id&&!r.abstract}))||null}function PS(d){var a;const u=vb(d);if(!u)return null;const r=u.properties.find(o=>{var p;return((p=o.implements)==null?void 0:p.id)===he[f.BuiltInBaseEntity][Le.PERSISTED_ENTITY].properties.database.id});return r?(a=r.getDefaultValue())==null?void 0:a.valueAsType:null}function Wd(d){if(d.type!==f.DefinitionEntity)return[];if(d.abstract)return[];if(!es(d,Le.PERSISTED_ENTITY))return[];const u=[],r=d.properties.filter(a=>{var o;return((o=a.implements)==null?void 0:o.id)!==he[f.BuiltInBaseEntity][Le.PERSISTED_ENTITY].properties.database.id&&!a.abstract});return u.push(...r),u}function NIe(d){var r;if(!d||d.type!==f.DefinitionEntity||!es(d,Le.PERSISTED_ENTITY))return null;const u=d.properties.find(a=>{var o;return((o=a.implements)==null?void 0:o.id)===he[f.BuiltInBaseEntity][Le.PERSISTED_ENTITY].properties.database.id});return(r=u==null?void 0:u.getDefaultValue())==null?void 0:r.valueAsTypeSingle}function Ur(d,u){var a;if(!t_.includes(u.type)||!d)return u.project||null;let r=u.project;return d.type===f.Project?r=d:((a=u.project)==null?void 0:a.id)!==d.project.id&&(r=d.project),r}function VIe(d){switch(d){case f.Project:return N;case f.InstalledProject:return uo;case f.DefinitionEntity:return Qn;case f.FunctionDeclaration:return Qa;case f.GlobalEvent:return ro;case f.VariableInstance:return ao;case f.VariableDeclaration:return oo;case f.InputMap:return Wn;case f.OutputMap:return In;case f.Condition:return io;case f.Operation:return eo;case f.FunctionCall:return To;case f.ReturnDeclaration:return Qi;case f.ArgumentDeclaration:return kn;case f.PrimitiveEntity:return ts;case f.DataType:return fs;case f.Property:return Xn;case f.ActionDescriptor:return ct;case f.ReturnStatement:return to;case f.ContinueStatement:return Pi;case f.BreakStatement:return po;case f.Loop:return Gi;case f.Search:return lo;case f.ValueDescriptor:return An;case f.InternalCall:return co;case f.LiteralValue:return Ki}return null}function LIe(d){const u={added:{},updated:{},removed:{},affected:[],seenEntities:[],self:d==null?void 0:d.self};return d==null||d.added.forEach(r=>{u.added[r.id]=r}),d==null||d.updated.forEach(r=>{u.updated[r.id]=r}),d==null||d.removed.forEach(r=>{u.removed[r.id]=r}),u.affected=Array.from(new Set(d==null?void 0:d.affected.map(r=>r.id))),u}function Lr(d,u){const r=ef(d.type);return r?!r.MUTABLE_META_PROPERTIES.every(o=>{const p=d[o],e=u[o];return e===void 0||p===e?!0:Array.isArray(p)&&Array.isArray(e)?p.length!==e.length?!1:p.every((y,v)=>y===e[v]):!1}):!1}function Nm(d,u={}){if(d.type===f.Project)return[];if(!d.parent)return[];const r=J(d.parent);if(!r)return[];const a=u[r];return a?[a.id,...Nm(a,u)]:[]}function MIe(d){const u=[],r=new Set;return[...d.listAdded,...d.listUpdated,...d.listAffected].forEach(a=>{const o=fr(a);!o||r.has(o.id)||(r.add(o.id),u.push(o))}),R(u)}function BIe(d){if(d.type===f.Condition)return null;if(d.type===f.Search)return d.project.getBuiltIn(he["value-descriptor"][Jl.SearchErrorOutputDescriptor].id)||null;if(d.type===f.Operation)return d.declaration.error;if(d.type===f.FunctionCall){const r=d.declaration.returnStatements.find(a=>!!a.throws);return(r==null?void 0:r.throws)||null}return null}function NS(d){const u=d.entities.filter(o=>!!o.implements.find(p=>p.id===he["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.id)),r=u.find(o=>{const p=o.properties.find(v=>v.implements&&v.implements.id===he["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.default.id),e=p==null?void 0:p.getDefaultValue();return(e==null?void 0:e.value)===!0});return r||u[0]||null}function Ab(d,u){const r=Array.from(new Set([...u.getAllBuiltInIds(),...zs()]));return!!(r.includes(d.id)||!Nm(d,{...u.instances,...u.builtInInstances}).every(p=>!r.includes(p)))}function VS(d){if(!d)return null;if(d.type===f.Project)return d.id;const u=d.parent;return u?VS(u):d.id}function rf(d){if(d.declaration&&d.declaration.type===f.Property){if(d.declaration.interactive){if(d.declaration.implements&&!d.declaration.implements.interactive)return!1;if(d.declaration.extends&&!d.declaration.extends.interactive)return!1}else return!1;if(d.declaration.private){const u=fr(d),r=Jd(u,d.project);if((r==null?void 0:r.type)===f.FunctionDeclaration&&(r==null?void 0:r.parent.type)===f.DefinitionEntity&&(r==null?void 0:r.parent.id)!==d.declaration.parent.id)return!1}}return!0}function bb(d){if(d.interactive){if(d.implements&&!d.implements.interactive)return!1;if(d.extends&&!d.extends.interactive)return!1}else return!1;if(d.private){const u=fr(d),r=Jd(u,d.project);if((r==null?void 0:r.type)===f.FunctionDeclaration&&(r==null?void 0:r.parent.type)===f.DefinitionEntity&&(r==null?void 0:r.parent.id)!==d.parent.id)return!1}return!0}function UIe(d,u,r){const a=u,o=r,p=!!r,e=[];return a.forEach(y=>{var v;if(p){const E=Xs(o,y,d);if(!E.compatible&&E.type!=="b-is-global-a-is-not")return;e.push(y)}else{if(((v=y.parent)==null?void 0:v.type)!==f.Project)return;e.push(y)}}),R(e)}function Vm(d){return d.replace(/["'`]/g,"")}function xr(d){const r=Vm(d).split(/[\s-]+/).filter(e=>e.length>0);if(r.length===0)return"";const a=r[0],o=a[0].toLowerCase()+a.slice(1),p=r.slice(1).map(e=>e[0].toUpperCase()+e.slice(1));return[o,...p].join("")}function Al(d){return Vm(d).split(/[\s-]+/).filter(a=>a.length>0).map(a=>a[0].toUpperCase()+a.slice(1)).join("")}function LS(d){const u=Vm(d).trim();if(!u)return"";const r=u.replace(/[\s_-]+/g," ").split(" ").filter(Boolean),a=[];for(const o of r){let p=o;p=p.replace(/([A-Z]+)([A-Z][a-z]+)/g,"$1-$2"),p=p.replace(/([a-z0-9])([A-Z][a-z0-9]*)/g,"$1-$2"),p=p.replace(/([0-9])([a-zA-Z]+)/g,"$1-$2"),p=p.replace(/([a-zA-Z])([0-9])/g,"$1-$2");for(const e of p.split("-"))e&&a.push(e)}return a.join("-")}function xIe(d){const u=Vm(d).trim();if(!u)return"";const r=u.replace(/[\s_-]+/g," ").split(" ").filter(Boolean),a=[];for(const o of r){let p=o;p=p.replace(/([A-Z]+)([A-Z][a-z]+)/g,"$1_$2"),p=p.replace(/([a-z0-9])([A-Z][a-z0-9]*)/g,"$1_$2"),p=p.replace(/([0-9])([a-zA-Z]+)/g,"$1_$2"),p=p.replace(/([a-zA-Z])([0-9])/g,"$1_$2");for(const e of p.split("_"))e&&a.push(e)}return a.join("_")}function Lm(d){return LS(d).toLowerCase()}function Yd(d){var r,a,o,p;if(!d)return"Any data type";let u="";if(d.interactiveEntities===!1?u+=` but only definition nodes ${d.asType?"as template ":""}that don't include non-interactive built-in functionality`:d.interactiveEntities===!0&&(u+=` but only definition nodes ${d.asType?"as template ":""}that extend or implement interactive built-in functionality`),d.staticEntities===!1?u?u+=" and that aren't a single global copy instance":u+=` but only definition nodes ${d.asType?"as template ":""}that aren't a single global copy instance`:d.staticEntities===!0&&(u?u+=" and that are a single global copy instance":u+=` but only definition nodes ${d.asType?"as template ":""}that are a single global copy instance`),d.actionEntities===!1?u?u+=" excluding executable/action nodes":u+=` excluding executable/action nodes ${d.asType?"templates ":""}`:d.actionEntities===!0&&(u?u+=" and not executable/action nodes":u+=" but not executable/action nodes"),d.entity&&(u=""),d.asType&&!u&&!((r=d.andChildrenGroup)!=null&&r.length)&&!((a=d.orChildrenGroup)!=null&&a.length)&&(u=" as template"),!d.entity){const e=d.isList;if(!((o=d.andChildrenGroup)!=null&&o.length)&&!((p=d.orChildrenGroup)!=null&&p.length))return e?`List of an any data type${u}`:`Any data type${u}`;let y="",v=!1,E=!1;return(d.andChildrenGroup||[]).forEach(w=>{const A=Yd(w),$=Rd(A);v&&(y+=" and "),w.isGroup?y+="("+$+")":v?y+=$:y+=A,v=!0,E=!0}),(d.orChildrenGroup||[]).forEach(w=>{const A=Yd(w),$=Rd(A);v&&(E&&(y+=","),y+=" or "),w.isGroup?y+="("+$+")":v?y+=$:y+=A,v=!0}),e?`List of ${Rd(y)}`:y}if(d.entity.type===f.PrimitiveEntity){let e=d.entity.name;switch(d.entity.name){case oe.String:e="Text";break;case oe.KeyValue:e="Data structure";break}return d.isList?`List of ${e}s${u}`:`${e.slice(0,1).toUpperCase()}${e.slice(1)}${u}`}else if(d.entity.type===f.DefinitionEntity){const e=Y(d.entity,d.project);return d.isList?`List of ${e} values${u}`:e.slice(0,1).toUpperCase()+e.slice(1)+u}else if(d.entity.type===f.BuiltInBaseEntity){const e=BS(d.entity);return d.isList?`List of ${e} values${u}`:e.slice(0,1).toUpperCase()+e.slice(1)+u}else if(d.entity.type===f.LiteralValue){if(d.entity.name===oe.Null)return"Empty value";if(d.entity.name===oe.Untyped)return"Untyped value";if(d.entity.name===oe.File)return"File";if(d.entity.name===oe.String)return`"${d.entity.value}" text`;if(d.entity.name===oe.Number)return`Number '${d.entity.value}'`;if(d.entity.name===oe.Boolean)return`${d.entity.value} value`;if(d.entity.name===oe.UUID)return`"${d.entity.value}" unique identifier`;if(d.entity.name===oe.Date)return`"${d.entity.value}" date`}return d.isList?`List of ${Y(d.entity,d.project)} values${u}`:`${Y(d.entity,d.project).slice(0,1).toUpperCase()+Y(d.entity,d.project).slice(1)} value${u}`}function jIe(d){if(!d)return"Any data type";const u=d.getDataType(null);return Yd(u)}function Mm(d){switch(d.declaration.id){case ut.Equal:return"is equal to";case ut.NotEqual:return"is not equal to";case ut.MoreThan:return"is greater than";case ut.MoreThanOrEqual:return"is greater than or equal to";case ut.LessThan:return"is less than";case ut.LessThanOrEqual:return"is less than or equal to";case Kr.And:return"and";case Kr.Or:return"or";case oi.Empty:return"is empty";case oi.NotEmpty:return"is present"}}function MS(d){return d.includes(Le.HTTP_ENDPOINT)?"HTTP endpoint":d.includes(Le.PERSISTED_ENTITY)?"Persisted entity":d.includes(Le.CRON_JOB)?"Scheduled execution":d.includes(Le.RELATIONAL_DATABASE)?"Relational database":"Entity"}function BS(d){switch(d.name){case Le.HTTP_ENDPOINT:return"HTTP endpoint";case Le.PERSISTED_ENTITY:return"Persisted entity";case Le.CRON_JOB:return"Scheduled execution";case Le.RELATIONAL_DATABASE:return"Relational database"}return"Entity"}function GIe(d){const u=Om(d);if(!u){const r=Hd(d);return r.includes(Le.HTTP_ENDPOINT)?"HTTP endpoint":r.includes(Le.PERSISTED_ENTITY)?"Persisted entity":r.includes(Le.CRON_JOB)?"Scheduled execution":r.includes(Le.RELATIONAL_DATABASE)?"Relational database":Y(d,d.project)+" entity"}return Y(u,d.project)+" entity"}function US(d){let u="Find ";return d.outputsDeclarations.forEach((r,a)=>{const o=Hy(r,null),p=Rd(o&&o.entity?Y(o.entity,d.project):"unstructured data");a===0?u+=`${p} `:a===d.outputsDeclarations.length-1?u+=`and ${p} `:u+=`, ${p} `}),u}function xS(d){switch(d.name){case oe.String:return"Text";case oe.Number:return"Number";case oe.Boolean:return"Boolean";case oe.KeyValue:return"Data structure";case oe.UUID:return"Unique identifier";case oe.Date:return"Date";case oe.EntityTemplate:return"Entity as template";case oe.Enum:return"Enumeration";case oe.File:return"File";case oe.Null:return"Empty";case oe.ActionDescriptor:return"Action descriptor";case oe.Untyped:return"Untyped";default:return d.name}}function jS(d){switch(d.id){case Je.List:return"Loop over list items";case Je.ManualFlow:return"Manual flow control loop";case Je.ObjectKeys:return"Loop over object keys";case Je.ObjectValues:return"Loop over object values";case Je.Counted:return"Loop given number of times";case Je.String:return"Loop over text characters";case Zt.Addition:return"Sum numbers";case Zt.Subtraction:return"Subtract numbers";case Zt.Multiplication:return"Multiply numbers";case Zt.Division:return"Divide numbers";case Zt.Remainder:return"Get remainder of numbers";case Zt.Exponentiation:return"Get exponent of numbers";case Ge.AddIndex:return"Add at index position";case Ge.DeleteFirst:return"Delete first character";case Ge.DeleteLast:return"Delete last character";case Ge.DeleteIndex:return"Delete at index position";case Ge.Join:return"Join texts";case Ge.ReplaceAllMatches:return"Replace all matches";case Ge.ReplaceFirst:return"Replace first match";case Ge.ReplaceLast:return"Replace last match";case Ge.Split:return"Split text";case Ge.ReplaceIndex:return"Replace at index position";case Ge.ReplaceSingleMatch:return"Replace single match";case Ge.GetFirst:return"Get first character";case Ge.GetLast:return"Get last character";case Ge.GetIndexItem:return"Get at index position";case Ge.GetIndexOf:return"Get the index number of the character";case Ge.Append:return"Add at the end";case Ge.Prepend:return"Add at the start";case tr.Wait:return"Wait";case tr.Parallel:return"Run in parallel";case tr.Sequential:return"Run in sequence";case yi.HttpRequest:return"HTTP request";case pr.CreateNewInstance:return"Create new copy of entity";case Fe.AddIndex:return"Add item at index position";case Fe.DeleteFirst:return"Delete first item";case Fe.DeleteLast:return"Delete last item";case Fe.DeleteIndex:return"Delete item at index position";case Fe.Join:return"Join lists";case Fe.ReplaceFirst:return"Replace first match";case Fe.ReplaceLast:return"Replace last match";case Fe.Split:return"Split list";case Fe.ReplaceIndex:return"Replace at index position";case Fe.GetFirst:return"Get first item";case Fe.GetLast:return"Get last item";case Fe.GetIndexItem:return"Get item at index position";case Fe.Append:return"Add item at the end";case Fe.Prepend:return"Add item at the start";case Ea.PROJECT_PUBLICATION_COMPLETED:return"Project publication completed";default:return(d.name.slice(0,1).toUpperCase()+d.name.slice(1)).replaceAll("-"," ")}}function Y(d,u){var r;if(f.FunctionDeclaration===d.type){const a=d.name;if(Object.values(Wr).includes(a))switch(a){case Wr.AbortExecution:return"Abort ongoing execution";case Wr.DeletePersistedEntity:return"Delete entry from database";case Wr.CreatePersistedEntity:return"Save new data entry in database";case Wr.UpdatePersistedEntity:return"Update entity data to database";default:return Ii(d.type).replaceAll("-"," ")}return a}if(f.BuiltInBaseEntity===d.type)return MS([d.name]);if(Qg.includes(d.type)&&d.type!==f.ActionDescriptor)return d.name;switch(d.type){case f.Search:return US(d);case f.GlobalEvent:return d.implements?Y(d.implements,u):Ii(d.type).replaceAll("-"," ");case f.Operation:case f.InternalCall:case f.Loop:const a=qi(d.declaration,u);return Y(a,u);case f.ActionDescriptor:return jS(d);case f.BreakStatement:const o=qi(d.parent,u);return`Stop loop ${Y(o,u)}`;case f.ContinueStatement:const p=qi(d.parent,u);return`Execute next iteration of ${Y(p,u)}`;case f.FunctionCall:return qi(d.declaration,u).name;case f.Condition:{const y=d;if(y.declaration.id===Kr.And)return"If all conditions are met";if(y.declaration.id===Kr.Or)return"If any condition is met";if((r=d.inputs)!=null&&r.length){const v=Y(y.inputs[0],y.project);if(y.inputs[1]){const E=y.inputs[1].declaration.name;return`If ${v} ${Mm(y)} ${E}`}return`If ${v} ${Mm(y)}`}else return`If ${Mm(y)}`}case f.ReturnStatement:{const y=qi(d.parent,u);return y?`Output of ${Y(y,u)}`:"Return statement"}case f.InputMap:if(d.declaration){const y=qi(d.declaration,u);return Y(y,u)||""}else{if(!d.name)throw new Error(`Input map entity with id "${d.id}" has no name and no declaration.`);return d.name||""}case f.VariableInstance:{const y=qi(d.declaration,u);return Y(y,u)||""}case f.OutputMap:if(d.declaration){const y=qi(d.declaration,u);return(y==null?void 0:y.name)||""}else return d.parentRelationType===Fa.Error?"Undeclared error":"";case f.PrimitiveEntity:case f.LiteralValue:return xS(d);default:return Ii(d.type).replaceAll("-"," ")}}function wb(d,u){const r=[];d.name||r.push(new ae({id:`${d.id}--${se.EmptyName}`,message:`Entity with id "${d.id}" and type "${d.type}" has an empty name. Please provide a 'name' string.`,severity:H.Error,code:se.EmptyName}));const a=u.entities.filter(o=>o.name===d.name);return a.length&&r.push(new ae({id:`${d.id}--${se.NameNotUniqueInScope}`,message:`Entity with id "${d.id}" and type "${d.type}" has a name "${d.name}" that is not unique in the project. Entity with id "${a[0].id}" has the same name.
397
397
  Please provide a unique 'name' string.`,severity:H.Error,code:se.NameNotUniqueInScope})),r}function Rb(d,u){const r=[];d.name||r.push(new ae({id:`${d.id}--${se.EmptyName}`,message:`Entity with id "${d.id}" and type "${d.type}" has an empty name. Please provide a 'name' string.`,severity:H.Error,code:se.EmptyName}));const a=d.parent?J(d.parent):null;let o=u;a&&(o=u.get(a));const p=[];o.type===f.DefinitionEntity?p.push(...o.methods.map(y=>y)):o.type===f.Project?p.push(...o.functions.map(y=>y)):o.type===f.Loop?o.body&&p.push(o.body):o.type===f.InstalledProject&&p.push(...o.functions.map(y=>y));const e=p.filter(y=>y.name===d.name);return e.length&&r.push(new ae({id:`${d.id}--${se.NameNotUniqueInScope}`,message:`Entity with id "${d.id}" and type "${d.type}" has a name "${d.name}" that is not unique in ${o.type===f.Project?"the globally declared project scope":"its parent entity"}. Entity with id "${e[0].id}" has the same name.
398
398
  Please provide a unique 'name' string.`,severity:H.Error,code:se.NameNotUniqueInScope})),r}function gb(d,u){const r=[];d.name||r.push(new ae({id:`${d.id}--${se.EmptyName}`,message:`Entity with id "${d.id}" and type "${d.type}" has an empty name. Please provide a 'name' string.`,severity:H.Error,code:se.EmptyName}));const a=d.parent&&qi(d.parent,u)||u;if(!a)r.push(new ae({id:`${d.id}--parent-reference--${k.ReferencedEntityNotFound}`,message:`The entity with id '${d.parent}' that isn't yet found in the project. Perhaps it should be created first. Or perhaps the ID is incorrect.`,severity:H.Error,code:k.ReferencedEntityNotFound}));else{const p=MA(a).filter(e=>e.name===d.name);p.length&&r.push(new ae({id:`${d.id}--${se.NameNotUniqueInScope}`,message:`Entity with id "${d.id}" and type "${d.type}" has a name "${d.name}" that is not unique in its scope or higher scopes. Entity with id "${p[0].id}" has the same name.
399
399
  Please provide a unique 'name' string.`,severity:H.Error,code:se.NameNotUniqueInScope}))}return r}function _b(d,u){const r=[];d.name||r.push(new ae({id:`${d.id}--${se.EmptyName}`,message:`Entity with id "${d.id}" and type "${d.type}" has an empty name. Please provide a 'name' string.`,severity:H.Error,code:se.EmptyName}));const a=J(d.parent);if(!a)r.push(new ae({id:`${d.id}--parent-reference--${k.InvalidReferenceObjectStructure}`,message:`Reference object at 'parent' property for entity with id "${d.id}" and type "${d.type}" is not a valid reference. A reference needs to be a 'id' string of an existing entity in the project.`,severity:H.Error,code:k.InvalidReferenceObjectStructure}));else{const o=u.get(a);if(!o)r.push(new ae({id:`${d.id}--parent-reference--${k.ReferencedEntityNotFound}`,message:`The entity with id '${a}' that isn't yet found in the project. Perhaps it should be created first. Or perhaps the ID is incorrect.`,severity:H.Error,code:k.ReferencedEntityNotFound}));else{const e=o.properties.filter(y=>y.name===d.name);e.length&&r.push(new ae({id:`${d.id}--${se.NameNotUniqueInScope}`,message:`Entity with id "${d.id}" and type "${d.type}" has a name "${d.name}" that is not unique among all properties in the parent entity. Entity with id "${e[0].id}" has the same name.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elyx-code/project-logic-tree",
3
- "version": "0.0.6484",
3
+ "version": "0.0.6485",
4
4
  "author": "Sergio Herrero",
5
5
  "license": "UNLICENSED",
6
6
  "description": "An installable module which contains the type definitions and ephemeral state management for a projects' logic tree data structure",