@elyx-code/project-logic-tree 0.0.6556 → 0.0.6557

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.
@@ -384,7 +384,7 @@ All global 'function-declaration' entity ids are:
384
384
  The project currently has no global 'function-declaration' entities that can be called as 'function-call' entities.`;f.push(new ue({id:`${l.id}--${W.InvalidReference}`,code:W.InvalidReference,severity:Q.Error,message:`Entity of type "${p.FunctionCall}" with id "${l.id}", has an invalid reference at the 'declaration' property. The 'declaration' property must be a valid reference to an 'function-declaration' entity.
385
385
  References can either be an ID string or an object with exacly four properties: 'id', 'entityId', 'entityType', 'type'.${v}`}))}return{errors:f,modifiedData:l}}validateGeneratedUpdate(i){const a=[];return i.parent&&a.push(new ue({id:`${this.id}--${W.InvalidParentUpdate}`,code:W.InvalidParentUpdate,severity:Q.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.
386
386
  If an entity is called by another, they must be in the same scope, which means they have the same parent.
387
- 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:i}}subscribeDependents(i){return i.forEach(a=>{this.detachedDependents[a.entity.id]||(this.detachedDependents[a.entity.id]=a)}),this}unsubscribeDependents(i){return i.forEach(a=>{this.detachedDependents[a.entity.id]&&delete this.detachedDependents[a.entity.id]}),this}syncDependents(i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,B().toISOString(),this,!0,"sync-dependents"))){const a=[],l=[],f=[],e=[];return Object.values(this.detachedDependents).forEach(y=>{const v=y.entity.afterAllChildrenInitialized(i);a.push(...v.updated),l.push(...v.added),f.push(...v.removed),e.push(...v.affected)}),i==null||i.attemptAutoclose("sync-dependents",this.id),{updated:C(a),added:C(l),removed:C(f),affected:C(e),self:this}}onDetachedDependencyRemoved(i,a,l){const f=[],e=[],y=[],v=[];if(a==="function-call-declaration-field"){const{updated:T,added:A,removed:b}=this.remove({ignoreUpstream:!1},l);f.push(...T),e.push(...A),y.push(...b)}if(a==="function-call-parent-field"){const{updated:T,added:A,removed:b}=this.remove({ignoreUpstream:!1},l);f.push(...T),e.push(...A),y.push(...b)}return{updated:C(f),added:C(e),removed:C(y),affected:C(v),self:this}}onDetachedDependencyRestored(i,a,l){const f=[],e=[],y=[],v=[];if(a==="function-call-declaration-field"){const{updated:T,added:A,removed:b}=this.restore({},l);f.push(...T),e.push(...A),y.push(...b)}if(a==="function-call-parent-field"){const{updated:T,added:A,removed:b}=this.restore({},l);f.push(...T),e.push(...A),y.push(...b)}return{updated:C(f),added:C(e),removed:C(y),affected:C(v),self:this}}unsubscribeFromDependencies(){var i;return(i=this.parent)==null||i.unsubscribeDependents([{entity:this,field:"function-call-parent-field"}]),this.declaration.unsubscribeDependents([{entity:this,field:"function-call-declaration-field"}]),this}subscribeToDependencies(){var i;return(i=this.parent)==null||i.subscribeDependents([{entity:this,field:"function-call-parent-field"}]),this.declaration.subscribeDependents([{entity:this,field:"function-call-declaration-field"}]),this}increaseVersion(i){if(i&&!B(i).isValid())throw new Error(`The shared timestamp '${i}' is not a valid ISO 8601 date string.`);return i&&B(i).isSame(B(this.createdAt))?this:(this.previousVersion=this.version,this.version=N.UUID.uuid(),this.createdAt=B(i).toISOString()||B().toISOString(),this)}captureVersion(){var a;const i=((a=this.knownVersions)==null?void 0:a.get(this.version))||new yi(this,this.project);return i.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,i):new Map([[this.version,i]]),i.inputs=[...this.inputs],i.outputs=[...this.outputs],i.error=this.error,i.successCalls=[...this.successCalls],i.errorCalls=[...this.errorCalls],i.declaration=this.declaration,i.calledBySuccess=[...this.calledBySuccess],i.calledByError=[...this.calledByError],i.calledByEntry=[...this.calledByEntry],i.parent=this.parent,this}recursiveCaptureUpstreamVersions(i){const a=[],l=[],f=[],e=[];if(this.parent){this.parent.increaseVersion(i);const y=this.parent.recursiveCaptureUpstreamVersions(i);a.push(this.parent,...y.updated),l.push(...y.added),f.push(...y.removed)}return{updated:C(a),added:C(l),removed:C(f),affected:C(e),self:this}}async restoreVersion(i){var v;const a=[],l=[],f=[],e=[];if(this.version===i)return{updated:C(a),added:C(l),removed:C(f),affected:C(e),self:this};if(!this.knownVersions){const T=new Map;for(const[A,b]of this.knownVersions||new Map){if(T.set(A,b),b.activeVersion=!1,b.knownVersions)for(const[O,L]of b.knownVersions)T.set(O,L);b.knownVersions=null}}let y=(v=this.knownVersions)==null?void 0:v.get(i);if(!y){const T=await this.APILoadVersion({},i);if(!T)throw new Error(`Version with id '${i}' for entity with id '${this.id}' not found.`);y=new yi(T,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.declaration=y.declaration,this.calledBySuccess=y.calledBySuccess,this.calledByError=y.calledByError,this.calledByEntry=y.calledByEntry,this.parent=y.parent,{updated:C(a),added:C(l),removed:C(f),affected:C(e),self:this}}updateWithShallowTransfer(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,B().toISOString(),this,!0,P.UpdateWithShallowTransfer))){if(!this.checkCanEdit(this))return J.warn(`[updateWithShallowTransfer] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),a==null||a.attemptAutoclose(P.UpdateWithShallowTransfer,this.id),this;if(this.metaSync(i,a),this.version=i.version,this.createdAt=i.createdAt,this.author=i.author,this.deleted=i.deleted,this.previousVersion=i.previousVersion,this.unsubscribeFromDependencies(),i.parent){const l=ee(i.parent),f=this.project.get(l),e=this.parent;if(e&&e.id!==(f==null?void 0:f.id)&&this.removeFromParent(a),f)this.setParent(f,a);else throw a==null||a.attemptAutoclose(P.UpdateWithShallowTransfer,this.id),new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw a==null||a.attemptAutoclose(P.UpdateWithShallowTransfer,this.id),new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(i.declaration){const l=ee(i.declaration),f=this.project.get(l);f&&this.setDeclaration(f)}return i.calledByEntry.forEach(l=>{const f=ee(l),e=this.project.get(f);e&&(this.addEntryCaller(e,a),e.addCall(this,a))}),[...this.calledByEntry].forEach(l=>{i.calledByEntry.find(e=>ee(e)===l.id)||(this.removeCaller(l,a),l.removeCall(this,a))}),i.calledBySuccess.forEach(l=>{const f=ee(l),e=this.project.get(f);e&&(this.addSuccessCaller(e,a),e.addSuccessCall(this,a))}),[...this.calledBySuccess].forEach(l=>{i.calledBySuccess.find(e=>ee(e)===l.id)||(this.removeCaller(l,a),l.removeCall(this,a))}),i.calledByError.forEach(l=>{const f=ee(l),e=this.project.get(f);e&&(this.addErrorCaller(e,a),e.addErrorCall(this,a))}),[...this.calledBySuccess].forEach(l=>{i.calledBySuccess.find(e=>ee(e)===l.id)||(this.removeCaller(l,a),l.removeCall(this,a))}),this.captureVersion(),this.subscribeToDependencies(),a==null||a.attemptAutoclose(P.UpdateWithShallowTransfer,this.id),this}hydrateAncestors(){const i=[],a=[],l=[],f=[];if(this.initialData.parent){const e=ee(this.initialData.parent),y=this.project.get(e);if(y)this.setParent(y,null),i.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=ee(this.initialData.declaration),y=this.project.get(e);y&&(this.setDeclaration(y),i.push(y))}return this.initialData.calledByEntry.forEach(e=>{const y=ee(e),v=this.project.get(y);v&&this.addEntryCaller(v,null)}),this.initialData.calledBySuccess.forEach(e=>{const y=ee(e),v=this.project.get(y);v&&this.addSuccessCaller(v,null)}),this.initialData.calledByError.forEach(e=>{const y=ee(e),v=this.project.get(y);v&&this.addErrorCaller(v,null)}),{updated:C(i),added:C(a),removed:C(l),affected:C(f),self:this}}afterAllChildrenInitialized(i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,B().toISOString(),this,!0,P.AfterAllChildrenInitialized))){if(!this.checkCanEdit(this))return J.warn(`[afterAllChildrenInitialized] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(P.AfterAllChildrenInitialized,this.id),{updated:[],added:[],removed:[],affected:[],self:this};const a=[],l=[],f=[],e=[];this.initialized=!0;const{updated:y,added:v,removed:T}=this.syncInputs(i),{updated:A,added:b,removed:O}=this.syncOutputs(i);return a.push(...y,...A),l.push(...v,...b),f.push(...T,...O),this.captureVersion(),i==null||i.attemptAutoclose(P.AfterAllChildrenInitialized,this.id),{updated:C(a),added:C(l),removed:C(f),affected:C(e),self:this}}addSelfToProject(i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,B().toISOString(),this,!0,"add-self-to-project"))){const a=[this],l=[],f=[],e=[];return this.parent===this.project&&this.project.addFunctionCall(this),this.successCalls.forEach(y=>{y.addSuccessCaller(this,i),a.push(y)}),this.errorCalls.forEach(y=>{y.addErrorCaller(this,i),a.push(y)}),this.calledBySuccess.forEach(y=>{y.addSuccessCall(this,i),a.push(y)}),this.calledByError.forEach(y=>{y.addErrorCall(this,i),a.push(y)}),this.calledByEntry.forEach(y=>{y.addCall(this,i),a.push(y)}),this.subscribe(),this.subscribeToDependencies(),i==null||i.attemptAutoclose("add-self-to-project",this.id),{updated:C(a),added:C(l),removed:C(f),affected:C(e),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}removeInput(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,B().toISOString(),this,!0,P.RemoveInput))){if(!this.checkCanEdit(this))return J.warn(`[removeInput] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),a==null||a.attemptAutoclose(P.RemoveInput,this.id),this;const l=this.inputs.findIndex(f=>f.id===i.id);return l>-1&&(this.inputs.splice(l,1),a&&(a==null||a.add(this,k.Affected))),a==null||a.attemptAutoclose(P.RemoveInput,this.id),this}addInput(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,B().toISOString(),this,!0,P.AddInput))){return this.checkCanEdit(this)?this.inputs.includes(i)?(a==null||a.attemptAutoclose(P.AddInput,this.id),this):(this.inputs.push(i),a==null||a.add(this,k.Affected),a==null||a.attemptAutoclose(P.AddInput,this.id),this):(J.warn(`[addInput] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),a==null||a.attemptAutoclose(P.AddInput,this.id),this)}addOutput(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,B().toISOString(),this,!0,"add-output"))){return this.checkCanEdit(this)?this.outputs.includes(i)?(a==null||a.attemptAutoclose("add-output",this.id),this):(this.outputs.push(i),a==null||a.add(this,k.Affected),a==null||a.attemptAutoclose("add-output",this.id),this):(J.warn(`[addOutput] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),a==null||a.attemptAutoclose("add-output",this.id),this)}removeOutput(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,B().toISOString(),this,!0,"remove-output"))){if(!this.checkCanEdit(this))return J.warn(`[removeOutput] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),a==null||a.attemptAutoclose("remove-output",this.id),this;const l=this.outputs.findIndex(f=>f.id===i.id);return l>-1&&(this.outputs.splice(l,1),a&&(a==null||a.add(this,k.Affected))),a==null||a.attemptAutoclose("remove-output",this.id),this}addValueReader(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,B().toISOString(),this,!0,P.AddValueReader))){return this.checkCanEditWithCounterpartAndSideEffects(this,i,P.AddValueReader,a)?this.writesValues.includes(i)?(a==null||a.attemptAutoclose(P.AddValueReader,this.id),this):(this.writesValues.push(i),a==null||a.add(this,k.Affected),this):this}removeValueReader(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,B().toISOString(),this,!0,P.RemoveValueReader))){return this.checkCanEditWithCounterpartAndSideEffects(this,i,P.RemoveValueReader,a)?this.writesValues.includes(i)?(this.writesValues=this.writesValues.filter(l=>l.id!==i.id),a==null||a.add(this,k.Affected),this):(a==null||a.attemptAutoclose(P.RemoveValueReader,this.id),this):this}addSuccessCaller(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,B().toISOString(),this,!0,P.AddSuccessCaller)),l=!1){return this.checkCanEditWithCounterpartAndSideEffects(this,i,P.AddSuccessCaller,a)?(this.calledBySuccess.find(f=>f.id===i.id)||(this.calledBySuccess.push(i),a==null||a.add(this,k.Updated),l&&et(this,a)),a==null||a.attemptAutoclose(P.AddSuccessCaller,this.id),this):this}addErrorCaller(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,B().toISOString(),this,!0,P.AddErrorCaller)),l=!1){return this.checkCanEditWithCounterpartAndSideEffects(this,i,P.AddErrorCaller,a)?(this.calledByError.find(f=>f.id===i.id)||(this.calledByError.push(i),a==null||a.add(this,k.Updated),l&&et(this,a)),a==null||a.attemptAutoclose(P.AddErrorCaller,this.id),this):this}addEntryCaller(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,B().toISOString(),this,!0,P.AddEntryCaller)),l=!1){return this.checkCanEditWithCounterpartAndSideEffects(this,i,P.AddEntryCaller,a)?(this.calledByEntry.find(f=>f.id===i.id)||(this.calledByEntry.push(i),a==null||a.add(this,k.Updated),l&&et(this,a)),a==null||a.attemptAutoclose(P.AddEntryCaller,this.id),this):this}addErrorCall(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,B().toISOString(),this,!0,P.AddErrorCall)),l=!1){return this.checkCanEditWithCounterpartAndSideEffects(this,i,P.AddErrorCall,a)?(this.errorCalls.find(f=>f.id===i.id)||(this.errorCalls.push(i),l&&et(this,a),a==null||a.add(this,k.Affected)),a==null||a.attemptAutoclose(P.AddErrorCall,this.id),this):this}addSuccessCall(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,B().toISOString(),this,!0,P.AddSuccessCall)),l=!1){return this.checkCanEditWithCounterpartAndSideEffects(this,i,P.AddSuccessCall,a)?(this.successCalls.find(f=>f.id===i.id)||(this.successCalls.push(i),l&&et(this,a),a==null||a.add(this,k.Affected)),a==null||a.attemptAutoclose(P.AddSuccessCall,this.id),this):this}removeCall(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,B().toISOString(),this,!0,P.RemoveCall)),l=!1){if(!this.checkCanEditWithCounterpartAndSideEffects(this,i,P.RemoveCall,a))return this;const f=this.successCalls.findIndex(y=>y.id===i.id);f>-1&&(this.successCalls.splice(f,1),a==null||a.add(this,k.Affected));const e=this.errorCalls.findIndex(y=>y.id===i.id);return e>-1&&(this.errorCalls.splice(e,1),a==null||a.add(this,k.Affected)),l&&et(this,a),a==null||a.attemptAutoclose(P.RemoveCall,this.id),this}removeCaller(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,B().toISOString(),this,!0,"remove-caller")),l=!1){return this.checkCanEditWithCounterpartAndSideEffects(this,i,P.RemoveCaller,a)?(this.calledBySuccess=this.calledBySuccess.filter(f=>f.id!==i.id?!0:(a==null||a.add(this,k.Updated),a==null||a.add(f,k.Affected),!1)),this.calledByError=this.calledByError.filter(f=>f.id!==i.id?!0:(a==null||a.add(this,k.Updated),a==null||a.add(f,k.Affected),!1)),this.calledByEntry=this.calledByEntry.filter(f=>f.id!==i.id?!0:(a==null||a.add(this,k.Updated),a==null||a.add(f,k.Affected),!1)),l&&et(this,a),a==null||a.attemptAutoclose(P.RemoveCaller,this.id),this):this}setParent(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,B().toISOString(),this,!0,P.SetParent))){var l;return this.checkCanEditWithCounterpartAndSideEffects(this,i,P.SetParent,a)?(((l=this.parent)==null?void 0:l.id)!==(i==null?void 0:i.id)&&(this.parent=i,a&&(a==null||a.add(this,k.Updated))),a==null||a.attemptAutoclose(P.SetParent,this.id),this):this}setDeclaration(i){return this.declaration=i,this}initChildren(i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,B().toISOString(),this,!0,"init-children"))){if(this.initialized||this.startedInitialization)return this;if(this.startedInitialization=!0,this.initialData.declaration.type===p.FunctionDeclaration){const a=ae(this.initialData.declaration,this.project);this.declaration=a}else{const a=ee(this.initialData.declaration),l=this.project.get(a);this.declaration=l}return this.successCalls=this.initialData.successCalls.map(a=>{const l=ae(a,this.project);if(l.addSuccessCaller(this,null),[p.BreakStatement,p.ContinueStatement].includes(l.type))l.setParent(this.parent.parent,null),l.initChildren(i);else if(l.type===p.ReturnStatement){const f=Er(this,this.project);l.setParent(f,null),l.initChildren(i)}else l.type!==p.InternalCall&&(l.setParent(this.parent,null),l.initChildren(i));return l}),this.errorCalls=this.initialData.errorCalls.map(a=>{const l=ae(a,this.project);if(l.addErrorCaller(this,null),[p.BreakStatement,p.ContinueStatement].includes(l.type))l.setParent(this.parent.parent,null),l.initChildren(i);else if(l.type===p.ReturnStatement){const f=Er(this,this.project);l.setParent(f,null),l.initChildren(i)}else l.type!==p.InternalCall&&(l.setParent(this.parent,null),l.initChildren(i));return l}),this.inputs=this.initialData.inputs.map(a=>{const l=ae(a,this.project);return l.setParent(this,null),l.initChildren(i),l}),this.initialData.error&&(this.error=ae(this.initialData.error,this.project),this.error.setParent(this,null),this.error.initChildren(i)),this.subscribeToDependencies(),this.afterAllChildrenInitialized(i),i==null||i.attemptAutoclose("init-children",this.id),this}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,B().toISOString(),this,!0,"meta-sync"))){const l=nr(this,i),f=rr(this,l),e=this.toMeta();return this.x=l.x||e.x,this.y=l.y||e.y,this.catchesError=l.catchesError!==void 0?l.catchesError:this.catchesError,super.baseMetaSync(l,this),l.deleted===!0&&!e.deleted?a==null||a.add(this,k.Removed):l.deleted===!1&&e.deleted?a==null||a.add(this,k.Added):f&&(a==null||a.add(this,k.Updated)),a==null||a.attemptAutoclose("meta-sync",this.id),this}async APILoad(i=Ae,...a){return await yi.repository.APILoad(this.id,...a),this}async APICreate(i=Ae,...a){return await yi.repository.APICreate(this.toShallowJSON(),...a),this}async APIUpdate(i=Ae,...a){return await yi.repository.APIUpdate(this.toShallowJSON(),...a),this}async APIDelete(i=Ae,...a){return await yi.repository.APIDelete(this.toShallowJSON(),...a),this}async APIClone(i=Ae,...a){return await yi.repository.APIClone(this.id,...a),this}async APILoadVersion(i=Ae,a,...l){return await yi.repository.APILoadVersion(this.id,a,...l)}removeFromParent(i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,B().toISOString(),this,!0,P.RemoveFromParent))){if(!this.checkCanEdit(this))return J.warn(`[removeFromParent] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(P.RemoveFromParent,this.id),{added:[],updated:[],removed:[],affected:[],self:this};const a=[],l=[],f=[],e=[];return this.parent.type===p.Project?(this.parent.removeFunctionCall(this),e.push(this.parent)):this.parent.detachedChildren.includes(this)&&this.parent.unsubscribeDetachedChild(this),i==null||i.attemptAutoclose(P.RemoveFromParent,this.id),{added:C(f),updated:C(a),removed:C(l),affected:C(e),self:this}}remove({ignoreUpstream:i}={ignoreUpstream:!1},a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,B().toISOString(),this,!0,P.RemoveEntity))){var v;if(!this.checkCanDelete(this)||!this.checkCanEdit(this))return J.warn(`[remove] User is not allowed to delete or edit this ${this.type} entity with id: ${this.id}`),a==null||a.event({id:`${P.RemoveEntity}-${this.id}`,action:P.RemoveEntity,owner:this,errorReason:ki.ActionOwnerEntityNonDeletable,rootAction:((v=a==null?void 0:a.self)==null?void 0:v.id)===this.id&&(a==null?void 0:a.autoCloseActionName)===P.RemoveEntity}),a==null||a.attemptAutoclose(P.RemoveEntity,this.id),{added:[],updated:[],removed:[],affected:[],self:this};const l=[],f=[],e=[],y=[];if(a!=null&&a.hasRemoved(this.id))return a==null||a.attemptAutoclose(P.RemoveEntity,this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(f.push(this),this.unsubscribe(),this.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},a),Object.values(this.detachedDependents).forEach(T=>{const{updated:A,removed:b,added:O}=T.entity.onDetachedDependencyRemoved(this,T.field,a);l.push(...A),f.push(...b),e.push(...O)}),this.inputs.forEach(T=>{const{updated:A,removed:b}=T.remove({ignoreUpstream:!0},a);l.push(...A),f.push(...b)}),this.outputs.forEach(T=>{const{updated:A,removed:b}=T.remove({ignoreUpstream:!0},a);l.push(...A),f.push(...b)}),this.error){const{updated:T,removed:A}=this.error.remove({ignoreUpstream:!0},a);l.push(...T),f.push(...A)}if(this.successCalls.forEach(T=>{l.push(T),T.removeCaller(this,a)}),this.errorCalls.forEach(T=>{l.push(T),T.removeCaller(this,a)}),!i){const T=this.removeFromParent(a);e.push(...T.added),l.push(...T.updated),f.push(...T.removed),y.push(...T.affected),this.calledBy.forEach(A=>{l.push(A),A.removeCall(this,a)})}return a==null||a.attemptAutoclose(P.RemoveEntity,this.id),{added:C(e),updated:C(l),removed:C(f),affected:C(y),self:this}}restore({}={},i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,B().toISOString(),this,!0,P.RestoreEntity))){if(!this.checkCanEdit(this))return J.warn(`[restore] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(P.RestoreEntity,this.id),{added:[],updated:[],removed:[],affected:[],self:this};const a=[],l=[],f=[],e=[];return i!=null&&i.hasAdded(this.id)?(i==null||i.attemptAutoclose(P.RestoreEntity,this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},i),Object.values(this.detachedDependents).forEach(y=>{const{updated:v,removed:T,added:A}=y.entity.onDetachedDependencyRestored(this,y.field,i);l.push(...v),f.push(...T),a.push(...A)}),this.inputs.forEach(y=>{const{updated:v}=y.restore({},i);l.push(...v)}),this.outputs.forEach(y=>{const{updated:v}=y.restore({},i);l.push(...v)}),this.successCalls.forEach(y=>{l.push(y),y.addSuccessCaller(this,i)}),this.errorCalls.forEach(y=>{l.push(y),y.addErrorCaller(this,i)}),this.calledBySuccess.forEach(y=>{l.push(y),y.addSuccessCall(this,i)}),this.calledByError.forEach(y=>{l.push(y),y.addErrorCall(this,i)}),this.calledByEntry.forEach(y=>{l.push(y),y.addCall(this,i)}),i==null||i.attemptAutoclose(P.RestoreEntity,this.id),{added:C(a),updated:C(l),removed:C(f),affected:C(e),self:this})}toFlat(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this,...this.successCalls.flatMap(l=>l.toFlat(i)),...this.errorCalls.flatMap(l=>l.toFlat(i)),...this.inputs.flatMap(l=>l.toFlat(i)),...this.outputs.flatMap(l=>l.toFlat(i)),...this.error?this.error.toFlat(i):[],...this.calledBy.flatMap(l=>l.toFlat(i))])}toFlatIds(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.id,...this.successCalls.flatMap(l=>l.toFlatIds(i)),...this.errorCalls.flatMap(l=>l.toFlatIds(i)),...this.inputs.flatMap(l=>l.toFlatIds(i)),...this.outputs.flatMap(l=>l.toFlatIds(i))])}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,editable:this.editable,deletable:this.deletable,catchesError:this.catchesError}}toJSON(i=new Set){var a;return i.has(this.id)?this.toReference():(i.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,editable:this.editable,deletable:this.deletable,catchesError:this.catchesError,x:this.x,y:this.y,successCalls:this.successCalls.map(l=>l.toJSON(i)),errorCalls:this.errorCalls.map(l=>l.toJSON(i)),calledBySuccess:this.calledBySuccess.map(l=>l.toReference()),calledByError:this.calledByError.map(l=>l.toReference()),calledByEntry:this.calledByEntry.map(l=>l.toReference()),writesValues:this.writesValues.map(l=>l.toJSON(i)),declaration:this.declaration.toJSON(i),inputs:this.inputs.map(l=>l.toJSON(i)),outputs:this.outputs.map(l=>l.toJSON(i)),parent:this.parent.toReference(),error:(a=this.error)==null?void 0:a.toJSON(i)})}toJSONClone(i=He){var l,f,e,y,v,T;let a;return(l=i.seenEntityMaps)!=null&&l.has(this.id)?a=i.seenEntityMaps.get(this.id):(a=i.newId||yr(this,this.project,i.uuidStrategy),i.seenEntityMaps&&i.seenEntityMaps.set(this.id,a)),(f=i.seenEntities)!=null&&f.has(a)||(e=i.seenEntities)!=null&&e.has(this.id)?this.toReference({seenEntityMaps:i.seenEntityMaps}):((y=i.seenEntities)==null||y.add(a),(v=i.seenEntities)==null||v.add(this.id),{id:a,version:N.UUID.uuid(),createdAt:i.timestamp||B().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,catchesError:this.catchesError,type:this.type,editable:this.editable,deletable:this.deletable,x:this.x,y:this.y,writesValues:this.writesValues.map(A=>A.toJSONClone({...i,newId:null})),successCalls:this.successCalls.map(A=>A.toJSONClone({...i,newId:null})),errorCalls:this.errorCalls.map(A=>A.toJSONClone({...i,newId:null})),calledBySuccess:this.calledBySuccess.map(A=>A.toReference({seenEntityMaps:i.seenEntityMaps})),calledByError:this.calledByError.map(A=>A.toReference({seenEntityMaps:i.seenEntityMaps})),calledByEntry:this.calledByEntry.map(A=>A.toReference({seenEntityMaps:i.seenEntityMaps})),declaration:this.declaration.toJSONClone({...i,newId:null}),inputs:this.inputs.map(A=>A.toJSONClone({...i,newId:null})),outputs:this.outputs.map(A=>A.toJSONClone({...i,newId:null})),error:(T=this.error)==null?void 0:T.toJSONClone({...i,newId:null}),parent:this.parent.toReference({seenEntityMaps:i.seenEntityMaps})})}toReference(i=He){var l;let a=this.id;return(l=i.seenEntityMaps)!=null&&l.has(this.id)&&(a=i.seenEntityMaps.get(this.id)),{id:a+"--"+N.UUID.uuid()+"--ref",type:p.GenericReference,entityId:a,version:this.version,entityType:this.type}}toShallowJSON(i=He){var l;let a=this.id;return(l=i.seenEntityMaps)!=null&&l.has(this.id)&&(a=i.seenEntityMaps.get(this.id)),{id:a,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,editable:this.editable,deletable:this.deletable,catchesError:this.catchesError,x:this.x,y:this.y,writesValues:this.writesValues.map(f=>f.toReference(i)),inputs:this.inputs.map(f=>f.toReference(i)),outputs:this.outputs.map(f=>f.toReference(i)),declaration:this.declaration.toReference(i),successCalls:this.successCalls.map(f=>f.toReference(i)),errorCalls:this.errorCalls.map(f=>f.toReference(i)),calledBySuccess:this.calledBySuccess.map(f=>f.toReference(i)),calledByError:this.calledByError.map(f=>f.toReference(i)),calledByEntry:this.calledByEntry.map(f=>f.toReference(i)),error:this.error?this.error.toReference(i):null,parent:this.parent.toReference(i)}}toFlatJSON(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.toShallowJSON(),...this.successCalls.flatMap(l=>l.toFlatJSON(i)),...this.errorCalls.flatMap(l=>l.toFlatJSON(i)),...this.inputs.flatMap(l=>l.toFlatJSON(i)),...this.outputs.flatMap(l=>l.toFlatJSON(i)),...this.error?this.error.toFlatJSON(i):[]])}toGenerationTarget(){const i=this.parent.type===p.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,editable:this.editable,deletable:this.deletable,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:i}}toFlatGenerationTarget(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.toGenerationTarget(),...this.successCalls.flatMap(l=>l.toFlatGenerationTarget(i)),...this.errorCalls.flatMap(l=>l.toFlatGenerationTarget(i)),...this.inputs.flatMap(l=>l.toFlatGenerationTarget(i)),...this.outputs.flatMap(l=>l.toFlatGenerationTarget(i)),...this.error?this.error.toFlatGenerationTarget(i):[]])}clearErrors(){var i;return this.errors=[],this.inputs.forEach(a=>a.clearErrors()),this.outputs.forEach(a=>a.clearErrors()),this.successCalls.forEach(a=>a.clearErrors()),this.errorCalls.forEach(a=>a.clearErrors()),(i=this.error)==null||i.clearErrors(),this}validate(){const i=QW(this);return this.errors=i,{success:!0}}getErrors(){return[...this.errors,...this.inputs.flatMap(a=>a.getErrors()),...this.outputs.flatMap(a=>a.getErrors()),...this.error?this.error.getErrors():[]]}getShallowErrors(){return this.errors}clone(i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,B().toISOString(),this,!0,P.CloneEntity)),a=null,l=null,f=!0){var M,U;let e=fr(a,this);const y=this.toJSON(),v=l||N.UUID.uuid();y.inputs=[];const T=v.split("-id"),A=T[T.length-1||0]||v;y.id=v,y.version=N.UUID.uuid(),y.createdAt=(i==null?void 0:i.timestamp)||B().toISOString(),y.author=(i==null?void 0:i.author)||"1",y.previousVersion=null,y.deleted=!1,y.deletable=!0,y.editable=!0;const b=Ci(y,e);a?b.setParent(a,null):b.setParent(this.parent,null),f&&b.subscribe(),b.initChildren(i),i==null||i.add(b,k.Added);const O=(M=this.inputs)==null?void 0:M.map((q,Z)=>q.clone(i,b,A+"-input-map-"+Z+"-id",f));b.inputs=O;const L=(U=this.outputs)==null?void 0:U.map((q,Z)=>q.clone(i,b,A+"-output-map-"+Z+"-id",f));return b.outputs=L,this.error&&(b.error=this.error.clone(i,b,A+"-error-map-id",f)),i==null||i.attemptAutoclose(P.CloneEntity,this.id),b}removeUnrecognizedInputs(i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,B().toISOString(),this,!0,P.RemoveUnrecognizedInputs))){if(!this.checkCanEdit(this))return J.warn(`[removeUnrecognizedInputs] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(P.RemoveUnrecognizedInputs,this.id),{updated:[],added:[],removed:[],affected:[],self:this};const a=[],l=[],f=[],e=[];return this.inputs.forEach(v=>{if(!this.declaration.inputs.find(A=>{var b;return A.id===((b=v.declaration)==null?void 0:b.id)})){const A=v.remove({ignoreUpstream:!1},i);f.push(...A.removed),a.push(...A.updated)}}),this.inputs.filter((v,T)=>{const A=this.inputs.findIndex(O=>O.declaration===v.declaration&&O!==v);if(A===-1)return!1;const b=this.inputs[A];return B(b==null?void 0:b.createdAt).isSame(B(v.createdAt))?T>A:!!B(b==null?void 0:b.createdAt).isAfter(v.createdAt)}).forEach(v=>{const T=v.remove({ignoreUpstream:!1},i);f.push(...T.removed),a.push(...T.updated)}),i==null||i.attemptAutoclose(P.RemoveUnrecognizedInputs,this.id),{updated:C(a),added:C(l),removed:C(f),affected:C(e),self:this}}removeUnrecognizedOutputs(i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,B().toISOString(),this,!0,P.RemoveUnrecognizedOutputs))){var T,A;if(!this.checkCanEdit(this))return J.warn(`[removeUnrecognizedOutputs] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(P.RemoveUnrecognizedOutputs,this.id),{updated:[],added:[],removed:[],affected:[],self:this};const a=[],l=[],f=[],e=[],y=((A=(T=this.declaration.dataType)==null?void 0:T.entity)==null?void 0:A.properties)||[];return this.outputs.forEach(b=>{if(!y.find(L=>{var M;return L.id===((M=b.declaration)==null?void 0:M.id)})){const L=b.remove({ignoreUpstream:!1},i);f.push(...L.removed),a.push(...L.updated)}}),this.outputs.filter((b,O)=>{const L=this.outputs.findIndex(U=>U.declaration===b.declaration&&U!==b);if(L===-1)return!1;const M=this.outputs[L];return B(M==null?void 0:M.createdAt).isSame(B(b.createdAt))?O>L:!!B(M==null?void 0:M.createdAt).isAfter(b.createdAt)}).forEach(b=>{const O=b.remove({ignoreUpstream:!1},i);f.push(...O.removed),a.push(...O.updated)}),i==null||i.attemptAutoclose(P.RemoveUnrecognizedOutputs,this.id),{updated:C(a),added:C(l),removed:C(f),affected:C(e),self:this}}syncInputs(i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,B().toISOString(),this,!0,P.SyncInputs))){if(!this.checkCanEdit(this))return J.warn(`[syncInputs] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(P.SyncInputs,this.id),{updated:[],added:[],removed:[],affected:[],self:this};const a=[],l=[],f=[],e=[],y=this.declaration.inputs.filter(b=>!this.inputs.find(O=>O.declaration.id===b.id));this.inputs.sort((b,O)=>b.index-O.index),y.forEach(b=>{this.inputs.forEach(M=>{M.index>=b.index&&M.metaSync({index:M.index+1},i)});const O={id:N.UUID.uuid(),version:N.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||B().toISOString(),author:N.sessionAuthor,previousVersion:null,deleted:!1,deletable:!0,editable:!0,type:p.InputMap,parentRelationType:null,declaration:b.toJSON(),readsValue:null,defaultValue:null,index:b.index,name:null,codeName:null,description:null,parent:this.toReference()},L=ae(O,this.project);L.setParent(this,i),L.initChildren(i),i==null||i.add(L,k.Added),L.addSelfToProject(i),l.push(L)}),this.inputs.sort((b,O)=>b.index-O.index);const{updated:v,added:T,removed:A}=this.removeUnrecognizedInputs(i);return a.push(...v),l.push(...T),f.push(...A),i==null||i.attemptAutoclose(P.SyncInputs,this.id),{updated:C(a),added:C(l),removed:C(f),affected:C(e),self:this}}syncOutputs(i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,B().toISOString(),this,!0,P.SyncOutputs))){var O,L;if(!this.checkCanEdit(this))return J.warn(`[syncOutputs] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(P.SyncOutputs,this.id),{updated:[],added:[],removed:[],affected:[],self:this};const a=[],l=[],f=[],e=[],y=[];this.outputs=this.initialData.outputs.reduce((M,U)=>{if(U.type===p.GenericReference){const Z=mn(U,this.project);return Z?[...M,Z]:M}const q=ae(U,this.project);return y.push(q.index),q.setParent(this,null),q.initChildren(i),[...M,q]},[]);const v=(((L=(O=this.declaration.dataType)==null?void 0:O.entity)==null?void 0:L.properties)||[]).filter(M=>!this.outputs.find(U=>{var q;return((q=U.declaration)==null?void 0:q.id)===M.id}));this.outputs.sort((M,U)=>M.index-U.index),v.forEach((M,U)=>{this.outputs.forEach(z=>{z.index>=M.index&&z.index++});const q=y.includes(M.index)?this.outputs.length-1+U:M.index,Z={id:N.UUID.uuid(),version:N.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||B().toISOString(),author:N.sessionAuthor,previousVersion:null,deleted:!1,deletable:!0,editable:!0,type:p.OutputMap,declaration:M.toJSON(),writesValues:[],index:q,parent:this.toReference()},H=ae(Z,this.project);H.setParent(this,i),H.initChildren(i),i==null||i.add(H,k.Added),H.addSelfToProject(i)}),this.outputs.sort((M,U)=>M.index-U.index);const{updated:T,added:A,removed:b}=this.removeUnrecognizedOutputs(i);return a.push(...T),l.push(...A),f.push(...b),i==null||i.attemptAutoclose(P.SyncOutputs,this.id),{updated:C(a),added:C(l),removed:C(f),affected:C(e),self:this}}getUnusedInputs(){return this.inputs.filter(i=>i.suggestion||!i.readsValue&&!i.defaultValue)}getUnusedOutputs(){return this.outputs.filter(i=>i.suggestion||!i.writesValues.length)}getUsedInputs(){return this.inputs.filter(i=>!i.suggestion&&(i.readsValue||i.defaultValue))}getUsedOutputs(){return this.outputs.filter(i=>!i.suggestion&&i.writesValues.length)}getDataType(i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,B().toISOString(),this,!0,"get-data-type"))){var l;const a=((l=this.declaration)==null?void 0:l.getDataType(i))||null;return i==null||i.attemptAutoclose("get-data-type",this.id),a}};_(yi,"repository",{APICreate:async(i,...a)=>i,APIUpdate:async(i,...a)=>i,APIDelete:async(i,...a)=>i,APIClone:async(i,...a)=>{},APILoad:async(i,...a)=>null,APILoadVersion:async(i,a,...l)=>null}),_(yi,"type",p.FunctionCall),_(yi,"USER_MANAGED_PARENT_TYPES",[...Xi,p.Project]),_(yi,"PARENT_TYPES",[...yi.USER_MANAGED_PARENT_TYPES]),_(yi,"MUTABLE_BASE_PROPERTIES",["catchesError"]),_(yi,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),_(yi,"BASE_PROPERTIES",[...yi.MUTABLE_BASE_PROPERTIES,...yi.INMUTABLE_BASE_PROPERTIES]),_(yi,"MUTABLE_META_PROPERTIES",["x","y"]),_(yi,"INMUTABLE_META_PROPERTIES",[...yi.INMUTABLE_BASE_PROPERTIES]),_(yi,"META_PROPERTIES",[...yi.MUTABLE_META_PROPERTIES,...yi.INMUTABLE_META_PROPERTIES]),_(yi,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry"]),_(yi,"INMUTABLE_UPSTREAM_PROPERTIES",["declaration","parent"]),_(yi,"UPSTREAM_PROPERTIES",[...yi.MUTABLE_UPSTREAM_PROPERTIES,...yi.INMUTABLE_UPSTREAM_PROPERTIES]),_(yi,"MUTABLE_DOWNSTREAM_PROPERTIES",["successCalls","errorCalls","writesValues","inputs","outputs","error"]),_(yi,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),_(yi,"DOWNSTREAM_PROPERTIES",[...yi.MUTABLE_DOWNSTREAM_PROPERTIES,...yi.INMUTABLE_DOWNSTREAM_PROPERTIES]),_(yi,"PROPERTIES",[...yi.META_PROPERTIES,...yi.UPSTREAM_PROPERTIES,...yi.DOWNSTREAM_PROPERTIES]);let Eo=yi;function Lw(d){return d&&typeof d.then=="function"}function L$e(d){const u=new ga(d[0]),i=d.map(l=>l.id),a={};return d.forEach(l=>{a[l.id]=l}),u.order=i,u.flatRecord=a,u.orderEntities(),u.order.map(l=>u.flatRecord[l])}function B$e(d){const u=new ga(Object.values(d)[0]),i=Object.keys(d);return u.order=i,u.flatRecord=d,u.orderEntities(),u.order}class ga{constructor(u){_(this,"order",[]);_(this,"flatRecord",{});_(this,"allBuiltInEntityIds",Kn());_(this,"onGoingVisits",{});u&&(this.flatten(u),this.orderEntities())}flatten(u){const i=new Set(Kn()),a=C(Te(u,i,{ignoreBuiltInBaseEntities:!0})),l=new Set;for(const f of a)this.flatRecord[f.id]=f,l.add(f.id);this.order=Array.from(l)}moveEntityAfterDependencies(u){const{upstream:i}=sp(u,this.flatRecord,{ignoreBuiltInBaseEntities:!0,allBuiltInEntityIds:this.allBuiltInEntityIds});for(const a of Object.keys(i)){const l=this.order.indexOf(a),f=this.order.indexOf(u.id);if(l>f)return this.order.splice(f,1),this.order.splice(l,0,u.id),!0}return!1}orderEntities(){let u=!1;for(let i=0;i<this.order.length;i++){const a=this.order[i],l=this.flatRecord[a];if(l||J.warn(`Entity with id ${a} not found in flatRecord. Skipping...`),this.moveEntityAfterDependencies(l)){u=!0;break}}u&&this.orderEntities()}getUpstreamOngoingDependenciesVisits(u,i){const{upstream:a}=sp(this.flatRecord[u],this.flatRecord,{ignoreBuiltInBaseEntities:!0,allBuiltInEntityIds:this.allBuiltInEntityIds}),l={};return Object.entries(this.onGoingVisits[i]||{}).forEach(([f,e])=>{Object.keys(a).includes(f)&&(l[f]=e)}),l}getDownstreamOngoingDependenciesVisits(u,i){const a=Object.keys(this.onGoingVisits[i]||{}),l=new Set(a.flatMap(e=>Object.keys(sp(this.flatRecord[e],this.flatRecord,{ignoreBuiltInBaseEntities:!0,allBuiltInEntityIds:this.allBuiltInEntityIds}).downstream))),f={};return Array.from(l).forEach(e=>{e===u&&(f[e]=this.onGoingVisits[i][e])}),f}async settlePromises(u,i){const a=Object.values(u);a.length&&await Promise.all(a),Object.keys(u).forEach(l=>{delete this.onGoingVisits[i][l]})}visit(u){const i=this.order;for(const a of i)u(this.flatRecord[a],this.flatRecord);return this}reverseVisit(u){const i=this.order.slice().reverse();for(const a of i)u(this.flatRecord[a],this.flatRecord);return this}async visitAsync(u){const i=this.order,a=Math.random().toString(36).substring(7);this.onGoingVisits[a]={};for(const l of i){const f=this.getUpstreamOngoingDependenciesVisits(l,a);Object.keys(f).length&&await this.settlePromises(f,a);const e=u(this.flatRecord[l],this.flatRecord);Lw(e)&&(this.onGoingVisits[a][l]=e)}return await this.settlePromises(this.onGoingVisits[a],a),this.onGoingVisits[a]={},this}async reverseVisitAsync(u){const i=this.order.slice().reverse(),a=Math.random().toString(36).substring(7);this.onGoingVisits[a]={};for(const l of i){const f=this.getDownstreamOngoingDependenciesVisits(l,a);Object.keys(f).length&&await this.settlePromises(f,a);const e=u(this.flatRecord[l],this.flatRecord);Lw(e)&&(this.onGoingVisits[a][l]=e)}return await this.settlePromises(this.onGoingVisits[a],a),this.onGoingVisits[a]={},this}}const M$e=63,x$e=/^[a-z][a-z0-9-]*[a-z0-9]$/;function U$e(d){return d.length>=1&&d.length<=M$e&&x$e.test(d)&&!d.includes("--")}function*j$e(){yield"";const d="abcdefghijklmnopqrstuvwxyz";for(let u=1;;u++){const i=new Array(u).fill(0);let a=!1;for(;!a;){yield i.map(l=>d[l]).join("");for(let l=u-1;l>=0&&(i[l]++,!(i[l]<d.length));l--)i[l]=0,l===0&&(a=!0)}}}function G$e(d,u){const i=new Set(d.map(l=>l.toLowerCase())),a=u>0?"secondary-db":"main";for(const l of j$e()){const f=l?`${a}-${l}`:a;if(U$e(f)&&!i.has(f))return f}throw new Error("Unable to generate identifier")}function eH(d,u){switch(d.id){case ce["built-in-base-entity"].BUILT_IN_PERSISTED_ENTITY_ENTITY.id:{const i=d.project.entities.filter(v=>!!v.implements.find(T=>T.id===ce["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.id)),a=i.find(v=>{const T=v.properties.find(O=>O.implements.find(L=>L.id===ce["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.default.id)),A=T==null?void 0:T.getDefaultValue();return(A==null?void 0:A.value)===!0});if(!a&&i.length){const T=i[0].properties.find(b=>b.implements.find(O=>O.id===ce["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.default.id)),A=T==null?void 0:T.defaultValue;if(A)A.metaSync({value:!0},u);else if(T!=null&&T.dataType){const b={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,deletable:!0,editable:!0,type:p.LiteralValue,standaloneParent:null,name:re.EntityTemplate,autogeneration:null,value:!0,valueAsTypeSingle:null,valueAsTypeList:null,parent:T==null?void 0:T.toReference()},O=ae(b,d.project);return O.setParent(T,u),O.initChildren(u),u==null||u.add(O,k.Added),O.addSelfToProject(u),{newEntities:[O]}}return{newEntities:[]}}else if(a)return{newEntities:[]};const l=d.project.get(ce["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.id),f=B0(l,"Main database",u);if(f.errors.length>0)return{newEntities:[]};const e=f.properties.find(v=>v.implements.find(T=>T.id===ce["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,deletable:!0,editable:!0,type:p.LiteralValue,standaloneParent:null,name:re.EntityTemplate,autogeneration:null,value:!0,valueAsTypeSingle:null,valueAsTypeList:null,parent:e==null?void 0:e.toReference()},T=ae(v,d.project);T.setParent(e,u),T.initChildren(u),u==null||u.add(T,k.Added),T.addSelfToProject(u)}return{newEntities:[f]}}}return{newEntities:[]}}function tH(d,u){const i=[],a=[],l=[],f=[];return d.implements.filter(y=>y.type===p.BuiltInBaseEntity).forEach(y=>{var v,T,A,b,O;switch(y.id){case ce["built-in-base-entity"].BUILT_IN_PERSISTED_ENTITY_ENTITY.id:{const L=d.project.entities.filter(H=>H.implements.find(z=>z.id===ce["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.id));let M=L.find(H=>!!H.properties.find(z=>{var oe;return z.implements.find(ie=>ie.id===ce["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.default.id)&&((oe=z.getDefaultValue())==null?void 0:oe.value)===!0}));if(!M&&L.length)M=L[0];else if(!M&&!L.length){M=d.project.getBuiltIn(ce["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.id).implement("Relational database",u);const z=M.properties.find(oe=>oe.implements.find(ie=>ie.id===ce["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.default.id));(v=z==null?void 0:z.defaultValue)==null||v.metaSync({value:!0},u),a.push(M)}const U=d.properties.find(H=>H.implements.find(z=>z.id===ce["built-in-base-entity"].BUILT_IN_PERSISTED_ENTITY_ENTITY.properties.database.id));if(U&&!(U!=null&&U.defaultValue)){const H={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,deletable:!0,editable:!0,type:p.LiteralValue,standaloneParent:null,name:re.EntityTemplate,autogeneration:null,value:null,valueAsTypeSingle:(M==null?void 0:M.toJSON())||null,valueAsTypeList:null,parent:U==null?void 0:U.toReference()},z=ae(H,d.project);z.hydrateAncestors(),z.setParent(U,u),z.addSelfToProject(u),u==null||u.add(z,k.Added),z.initChildren(u),(U==null?void 0:U.defaultValue).setValueAsTypeSingle(M||null,u),a.push(z);return}else U!=null&&U.defaultValue&&!(U!=null&&U.defaultValue.valueAsTypeSingle)&&(U==null||U.defaultValue.setValueAsTypeSingle(M||null,u));const q=d.properties.find(H=>H.implements.find(z=>z.id===ce["built-in-base-entity"].BUILT_IN_PERSISTED_ENTITY_ENTITY.properties.primaryKey.id));if(!q)throw new Error(`[handleAfterEntityImplementationSideEffects] Primary key property not found for implemented base entity ${ce["built-in-base-entity"]}`);if(!q.dataType){const H=Zr.new(u);H.parent=q.toReference();const z=ae(H,d.project);z.hydrateAncestors(),z.setParent(q,u),z.addSelfToProject(u),u==null||u.add(z,k.Added),z.initChildren(u)}const Z=d.project.getBuiltIn(ce["primitive-entity"].number.id);(T=q.dataType)==null||T.setEntity(Z,u);return}case ce["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.id:{const L=d.project.entities.filter(oe=>oe.implements.find(ie=>ie.id===ce["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.id)&&oe.id!==d.id),M=L.map(oe=>{var te;const ie=oe.properties.find(fe=>fe.implements.find(me=>me.id===ce["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.identifier.id));return(te=ie==null?void 0:ie.getDefaultValue())==null?void 0:te.value}).filter(oe=>!!oe),U=d.properties.find(oe=>oe.implements.find(ie=>ie.id===ce["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.identifier.id));if(!L.find(oe=>!!oe.properties.find(ie=>{var ne;return ie.implements.find(te=>te.id===ce["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.default.id)&&((ne=ie.getDefaultValue())==null?void 0:ne.value)===!0}))){const oe=d.properties.find(ie=>ie.implements.find(ne=>ne.id===ce["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.default.id));if(!oe)throw new Error("Default boolean property not found for relational database entity with id: "+d.id);if(!(oe!=null&&oe.defaultValue)){const ie=Or.new(u);ie.parent=oe.toReference();const ne=ae(ie,d.project);ne.hydrateAncestors(),ne.setParent(oe,u),ne.addSelfToProject(u),u==null||u.add(ne,k.Added),ne.initChildren(u)}(A=oe==null?void 0:oe.defaultValue)==null||A.metaSync({value:!0},u)}if(!U)throw new Error("Identifier property not found for relational database entity with id: "+d.id);if(!(U!=null&&U.defaultValue)){const oe=Or.new(u);oe.parent=U.toReference();const ie=ae(oe,d.project);ie.hydrateAncestors(),ie.setParent(U,u),ie.addSelfToProject(u),ie.initChildren(u),u==null||u.add(ie,k.Added)}const Z=G$e(M,L.length);(b=U.defaultValue)==null||b.metaSync({value:Z},u);const H=d.properties.find(oe=>oe.implements.find(ie=>ie.id===ce["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.password.id));if(!H)throw new Error(`[handleAfterEntityImplementationSideEffects] Password property not found for implemented base entity ${ce["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.id} with id ${d.id}`);if(!H.defaultValue){const oe=Or.new(u);oe.parent=H.toReference();const ie=ae(oe,d.project);ie.hydrateAncestors(),ie.setParent(H,u),ie.addSelfToProject(u),ie.initChildren(u),u==null||u.add(ie,k.Added),a.push(ie)}const z=ZK(24);(O=H.defaultValue)==null||O.metaSync({value:z},u);return}case ce["built-in-base-entity"].BUILT_IN_SQL_ROW_TRANSFORMER_ENTITY.id:{const L=d.properties.find(Z=>Z.implements.find(H=>H.id===ce["built-in-base-entity"].BUILT_IN_SQL_ROW_TRANSFORMER_ENTITY.properties.time.id));if(!L)throw new Error(`[handleAfterEntityImplementationSideEffects] Time property not found for implemented base entity ${ce["built-in-base-entity"].BUILT_IN_SQL_ROW_TRANSFORMER_ENTITY.id} with id ${d.id}`);let M=L.defaultValue||null;if(!M){const Z=Or.new(u);Z.parent=L.toReference(),Z.id=N.UUID.uuid(),M=ae(Z,d.project),M.hydrateAncestors(),M.setParent(L,u),M.addSelfToProject(u),M.initChildren(u),u==null||u.add(M,k.Added)}M.metaSync({value:new Date().toISOString()},u),M.metaSync({editable:!1,deletable:!1},u),L.metaSync({editable:!1,deletable:!1},u);const U=d.properties.find(Z=>Z.implements.find(H=>H.id===ce["built-in-base-entity"].BUILT_IN_SQL_ROW_TRANSFORMER_ENTITY.properties.definition.id));if(!U)throw new Error(`[handleAfterEntityImplementationSideEffects] Definition property not found for implemented base entity ${ce["built-in-base-entity"].BUILT_IN_SQL_ROW_TRANSFORMER_ENTITY.id} with id ${d.id}`);let q=U.defaultValue||null;if(!q){const Z=Or.new(u);Z.parent=U.toReference(),Z.id=N.UUID.uuid(),q=ae(Z,d.project),q.hydrateAncestors(),q.setParent(U,u),q.addSelfToProject(u),q.initChildren(u),u==null||u.add(q,k.Added)}}}}),{self:d,updated:C(i),added:C(a),removed:C(l),affected:C(f)}}function B0(d,u,i,a){const l=a||N.UUID.uuid(),f=N.UUID.uuid(),e={id:l,version:f,createdAt:(i==null?void 0:i.timestamp)||new Date().toISOString(),author:N.sessionAuthor,previousVersion:null,deleted:!1,name:u,deletable:!0,editable:!0,type:p.DefinitionEntity,allPropertiesImplement:null,additionalProperties:!1,additionalPropertiesDataType:null,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()};eH(d,i);const y=ae(e,d.project);return y.hydrateAncestors(),i==null||i.add(y,k.Added),y.addSelfToProject(i),y.addImplementation(d,i),y.setParent(d.project,i),y.initChildren(i),tH(y,i),y}function Bw(d,u){return u.entities.find(l=>{const f=l.properties,e=f.map(b=>b.name),y=d.every(b=>e.includes(b)),v=e.filter(b=>!d.includes(b)),T=f.every(b=>!v.includes(b.name)||!b.required);return y&&T})||null}function iH(d,u,i,a=Ar.OrDataTypeGroup){const l=[],f=[],e=[],y=[],T={id:N.UUID.uuid(),version:N.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||new Date().toISOString(),author:N.sessionAuthor,previousVersion:null,deleted:!1,deletable:!0,editable:!0,type:p.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()},A=ae(T,d.project);return f.push(A),A.setParent(u,i),A.initChildren(i),i==null||i.add(A,k.Added),A.setEntity(d,i),A.addSelfToProject(i),{updated:C(l),added:C(f),removed:C(e),affected:C(y),self:A}}function Mw(d,u,i,a,l){var T,A,b,O,L,M,U,q;const f=[],e=[],y=[],v=[];switch(typeof d){case"string":let Z=!1;const H=new Date(d);if(H instanceof Date&&!isNaN(H.valueOf())&&(Z=!0),Z){const z=u.project.getBuiltIn(ce[p.PrimitiveEntity][re.Date].id);u.setEntity(z,a);break}else{const z=u.project.getBuiltIn(ce[p.PrimitiveEntity][re.String].id);u.setEntity(z,a);break}case"number":u.setEntity(u.project.getBuiltIn(ce[p.PrimitiveEntity][re.Number].id),a);break;case"boolean":u.setEntity(u.project.getBuiltIn(ce[p.PrimitiveEntity][re.Boolean].id),a);break;case"object":if(d===null){u.setEntity(u.project.getBuiltIn(ce[p.PrimitiveEntity][re.Null].id),a);break}else if(Array.isArray(d))if(u.metaSync({isList:!0},a),d.length>0){const z=d.slice(0,5).filter(ie=>ie!==void 0);if(z.every(ie=>typeof ie==typeof z[0])&&(typeof z[0]!="object"||z[0]===null))switch(typeof z[0]){case"string":u.setEntity(u.project.getBuiltIn(ce[p.PrimitiveEntity][re.String].id),a);break;case"number":u.setEntity(u.project.getBuiltIn(ce[p.PrimitiveEntity][re.Number].id),a);break;case"boolean":u.setEntity(u.project.getBuiltIn(ce[p.PrimitiveEntity][re.Boolean].id),a);break;case"object":u.setEntity(u.project.getBuiltIn(ce[p.PrimitiveEntity][re.Null].id),a);break}else{const ie=[];let ne=!1;z.forEach(fe=>{var me,Y,ye,Ee;if(Array.isArray(fe)&&(ne=!0),typeof fe=="object"&&!Array.isArray(fe)&&fe!==null){const ge=M0(fe,u.project,{...i,id:N.UUID.uuid()},a,l);ge.hasCreated&&ie.push((me=ge.changeSet)==null?void 0:me.self),f.push(...(Y=ge.changeSet)==null?void 0:Y.updated),e.push(...(ye=ge.changeSet)==null?void 0:ye.added),y.push(...(Ee=ge.changeSet)==null?void 0:Ee.removed)}});const te=C(ie);if(!te.length&&!ne){z.forEach(fe=>{const me={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,deletable:!0,editable:!0,type:p.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:Ar.OrDataTypeGroup,parent:u.toReference()},Y=ae(me,u.project);switch(Y.setParent(u,a),Y.initChildren(a),a==null||a.add(Y,k.Added),Y.addSelfToProject(a),typeof fe){case"string":Y.setEntity(Y.project.getBuiltIn(ce[p.PrimitiveEntity][re.String].id),a);break;case"number":Y.setEntity(Y.project.getBuiltIn(ce[p.PrimitiveEntity][re.Number].id),a);break;case"boolean":Y.setEntity(Y.project.getBuiltIn(ce[p.PrimitiveEntity][re.Boolean].id),a);break;case"object":Y.setEntity(Y.project.getBuiltIn(ce[p.PrimitiveEntity][re.Null].id),a);break}});break}else te.length===1&&!ne?u.setEntity(te[0],a):z.forEach(fe=>{if(typeof fe=="object"&&!Array.isArray(fe)&&fe!==null){const me=Bw(Object.keys(fe),u.project);if(me){const Y=iH(me||te[0],u,a,Ar.OrDataTypeGroup);f.push(...Y.updated),e.push(...Y.added),y.push(...Y.removed)}}else{const me={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,deletable:!0,editable:!0,type:p.DataType,options:null,implementationChooseOne:!1,entity:null,isList:Array.isArray(fe),asType:!1,andChildrenGroup:null,index:null,orChildrenGroup:null,staticEntities:!1,interactiveEntities:!0,actionEntities:!1,like:!0,inferred:!1,parentRelationType:Ar.OrDataTypeGroup,parent:u.toReference()},Y=ae(me,u.project);Y.setParent(u,a),Y.initChildren(a),a==null||a.add(Y,k.Added),Y.addSelfToProject(a);const ye=Mw(fe,Y,{...i,id:N.UUID.uuid()},a,l);f.push(...ye.updated),e.push(...ye.added),y.push(...ye.removed)}})}}else{const z=M0(d[0],u.project,{...i},a,l);u.setEntity((T=z.changeSet)==null?void 0:T.self,a),f.push(...(A=z.changeSet)==null?void 0:A.updated),e.push(...(b=z.changeSet)==null?void 0:b.added),y.push(...(O=z.changeSet)==null?void 0:O.removed);break}else{const z=M0(d,u.project,{...i},a,l);u.setEntity((L=z.changeSet)==null?void 0:L.self,a),f.push(...(M=z.changeSet)==null?void 0:M.updated),e.push(...(U=z.changeSet)==null?void 0:U.added),y.push(...(q=z.changeSet)==null?void 0:q.removed);break}}return{updated:C(f),added:C(e),removed:C(y),affected:C(v),self:u}}function M0(d,u,i,a,l){const f=[],e=[],y=[],v=[],T=Object.keys(d),A=Bw(T,u);if(A)return{hasCreated:!1,changeSet:{updated:[],added:[],removed:[],affected:[],self:A}};const b=l?i.name+" of "+l.name:i.name,L={id:i.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:b,codeName:null,deletable:!0,editable:!0,type:p.DefinitionEntity,additionalProperties:!1,additionalPropertiesDataType:null,allPropertiesImplement:null,description:i.description||null,static:i.static||!1,abstract:i.abstract||!1,properties:[],methods:[],abstractMethods:[],extends:null,implements:[],x:0,y:0,parent:u.toReference()},M=ae(L,u);return M.setParent(u,a),M.initChildren(a),a==null||a.add(M,k.Added),M.addSelfToProject(a),e.push(M),T.forEach((U,q)=>{const H={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:U,deletable:!0,editable:!0,type:p.Property,parentRelationType:null,codeName:U,description:null,static:!1,abstract:!1,defaultValue:null,constant:!1,interactive:!0,dataType:null,implements:[],extends:null,index:q,hidden:!1,private:!1,required:!0,parent:M.toReference()},z=ae(H,u);z.setParent(M,a),z.initChildren(a),a==null||a.add(z,k.Added),z.addSelfToProject(a),e.push(z);const oe=d[U],ne={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,deletable:!0,editable:!0,type:p.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:z.toReference()},te=ae(ne,u);te.setParent(z,a),te.initChildren(a),a==null||a.add(te,k.Added),te.addSelfToProject(a),e.push(te);const fe=Mw(oe,te,{...i,name:U,id:N.UUID.uuid()},a,l||M);f.push(...fe.updated),e.push(...fe.added),y.push(...fe.removed)}),{hasCreated:!0,changeSet:{updated:C(f),added:C(e),removed:C(y),affected:C(v),self:M}}}function vl(d,u,i,a){const l=[];return!d.length||!u.length?{errors:l,overlap:!1}:(d.length>u.length?d.forEach(f=>{const e=u.find(v=>v.name===f.name),y=u.find(v=>{var T,A;return Array.isArray(v.implements)?v.implements.some(b=>!!f.implements.find(O=>O.id===b.id)):((T=v.implements)==null?void 0:T.id)===((A=f.implements)==null?void 0:A.id)});if(e){const v=new vi({id:f.id+"--"+e.id+"--"+a,message:`Entity of type ${f.type} named "${f.name}" with id "${f.id}" overrides a base ${e.type} ${e.name} with id "${e.id}" that has the same name`,severity:Q.Error,code:a,entity:f,firstRelationship:e});l.push(v)}if(y){const v=new vi({id:f.id+"--"+y.id+"--"+i,message:`Entity of type ${f.type} named "${f.name}" with id "${f.id}" overrides a base ${y.type} ${y.name} with id "${y.id}" that implements the same base descriptor`,severity:Q.Error,code:i,entity:f,firstRelationship:y});l.push(v)}}):u.forEach(f=>{var v;const e=d.find(T=>T.name===f.name),y=d.find(T=>{var A,b;return T.implements&&Array.isArray(T.implements)?T.implements.some(O=>!!f.implements.find(L=>L.id===O.id)):((A=T.implements)==null?void 0:A.id)===((b=f.implements)==null?void 0:b.id)});if(e){const T=new vi({id:e.id+"--"+f.id+"--"+a,message:`Entity of type ${e.type} named "${e.name}" with id "${e.id}" overrides a base entity ${f.name} with id "${f.id}" that has the same name`,severity:Q.Error,code:a,entity:e,firstRelationship:f});l.push(T)}if(y){const T=new vi({id:y.id+"--"+f.id+"--"+i,message:`Entity of type ${y.type} named "${y.name}" with id "${y.id}" overrides a base entity ${f.name} with id "${f.id}" that implements the same base ${Array.isArray(y==null?void 0:y.implements)?yt(y==null?void 0:y.implements.map(A=>A.type),"', '","' and '"):(v=y.implements)==null?void 0:v.id}`,severity:Q.Error,code:i,entity:y,firstRelationship:f});l.push(T)}}),{errors:l,overlap:!!l.length})}function k$e(d,u){return d.abstract||(d.properties.forEach(a=>{a.abstract||a.metaSync({abstract:!0},u)}),Object.values(d.detachedDependents).forEach(a=>{a.field===tA.Entity&&a.entity.remove({ignoreUpstream:!1},u)}),d.metaSync({abstract:!0},u)),d}function F$e(d,u){return d.abstract&&(d.properties.forEach(a=>{a.abstract&&a.metaSync({abstract:!1},u)}),Object.values(d.detachedDependents).forEach(a=>{(a.field===ev.Implements||a.field===ev.Extends)&&a.entity.onDetachedDependencyRemoved(d,a.field,u)}),d.metaSync({abstract:!1},u)),d}function K$e(d,u){return d.static||(d.properties.forEach(a=>{a.static||a.metaSync({static:!0},u)}),d.metaSync({static:!0},u)),d}function q$e(d,u){return d.static&&d.metaSync({static:!1},u),d}var hn=(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))(hn||{});function xw(d,u){const i=[],a=u;if(!a)return{errors:i,override:u};if(typeof a!="string")return{errors:[],override:u};if(a.includes(" ")){const l=new vi({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:Q.Error,code:"string-value-must-not-have-spaces",entity:d});i.push(l)}return{errors:i,override:a.replace(/\s/g,"-")}}function rH(d,u){const i=[],a=u;if(!a)return{errors:i,override:u};if(typeof a!="string")return{errors:[],override:u};if(a.includes(" ")){const l=new vi({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:Q.Error,code:"string-value-must-not-have-spaces",entity:d});i.push(l)}if(a.includes("-")){const l=new vi({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:Q.Error,code:"string-value-must-not-have-dashes",entity:d});i.push(l)}return{errors:i,override:a.replace(/\s|-/g,"_")}}function Uw(d,u){var i;if(d.type===p.LiteralValue){let a=(i=d.value)==null?void 0:i.toString();try{a=JSON.stringify(d.value,null,2)}catch{}return`${d.type}: ${d.id} (${S(d,u)}) = ${a}`}if(d.type===p.DataType){if(d instanceof Zr||d.increaseVersion)return`${d.type}: ${d.id} (${cp(d)})`;try{const a=cp(d);return`${d.type}: ${d.id} (${a})`}catch{}}return`${d.type}: ${d.id} (${S(d,u)})`}function ip(d,u){const i=Io(d);if(i.length===0)return{list:[],last:null};let a=null;return{list:i.flatMap(f=>{if(f===u)return a=f,[f];const e=ip(f,u);return e.last&&(a=e.last),[f,...e.list]}),last:a}}function bo(d,u){const i=d.calledBy;if(i.length===0)return{list:[],last:null,callType:null};let a=null,l=null;return{list:i.flatMap(e=>{if(e===u)return a=e,jt.includes(e.type)?e.parent.type===p.Loop?l="loop-body":l="entry":e.successCalls.includes(d)?l="success":e.errorCalls.includes(d)&&(l="error"),[e];if(e.type===p.FunctionDeclaration&&e.parent.type===p.Loop&&e.parent===u)return a=e.parent,l="loop-body",[e];if(!en.includes(e.type))return[e];const y=bo(e,u);return y.last&&(a=y.last,l=y.callType),[e,...y.list]}),last:a,callType:l}}function Z$e(d,u){if(d===u)return"same-entity";if(!jr.includes(d.type)||!oy(d).find(l=>l.callee===u))return null;if(jt.includes(d.type)){if(d.calls.includes(u))return d.type===p.Loop?"loop-body":"entry"}else if(mi.includes(d.type)&&d.type!==p.InternalCall){if(d.successCalls.includes(u))return"success";if(d.errorCalls.includes(u))return"error"}return null}function ay(d){const u=Yr(d,d.project);return u?jt.includes(u.type)?u:u.type===p.Loop?u.body:null:null}function jw(d,u){const i=d.calledBy;return!i||!i.length?!1:i.every(a=>a===u?!0:en.includes(a.type)?!!bo(a,u).last:!1)}function nH(d){return d.filter(u=>{const i=ay(u);return!d.filter(f=>f!==u).some(f=>f===i?!1:j0(f,u))})}function Gw(d){if(!d.calledBy||!d.calledBy.length)return[];const u=d.calledBy.reduce((i,a)=>{if(en.includes(a.type)){const l=Gw(a);return[...i,a,...l]}return i},[]);return C(u)}function sH(d){const u=Gw(d);if(!u.length)return{ancestor:null,callType:null};const a=u.filter(f=>!(f===d||!jr.includes(f.type)||!ht(f).find(v=>v===d))).filter((f,e,y)=>y.findIndex(v=>v===f)===e).filter(f=>jw(d,f)),l=a.filter(f=>{const e=ht(f),y=a.filter(T=>T!==f).map(T=>T);return!e.some(T=>!!y.find(b=>b===T))});if(l.length===0)return{ancestor:null,callType:null};if(l.length===1){const f=l[0];if(f.type===p.Loop){if(f.body.calls.includes(d))return{ancestor:f,callType:"loop-body"}}else if(jt.includes(f.type)){if(f.calls.includes(d))return f.type===p.FunctionDeclaration&&f.parent.type===p.Loop?{ancestor:f,callType:"loop-body"}:{ancestor:f,callType:"entry"}}else if(mi.includes(f.type)){if(f.successCalls.includes(d))return{ancestor:f,callType:"success"};if(f.errorCalls.includes(d))return{ancestor:f,callType:"error"}}}if(l.length>1)throw new Error(`resolveEarliestSingleCallerAncestor: Multiple callers found for entity ${d.id}.`);return{ancestor:l[0],callType:null}}function aH(d,u){if(!d)throw new Error("findNextSingleCallerAncestor: Target is not defined, cannot find ancestor.");let i=d;(d.type===p.VariableDeclaration||d.type===p.VariableInstance)&&!d.calledBy.length&&!d.successCalls.length&&!d.errorCalls.length&&d.internalCalls.some(O=>!!O.calledBy.length)&&(i=d.internalCalls.find(L=>!!L.calledBy.length));let a=u||Yr(i,d.project);if(!a)return{ancestor:null,callType:null};if(a.type===p.Project&&(a=sH(i).ancestor,!a))return{ancestor:null,callType:null};const l=oy(a);if(!l.find(O=>O.callee===i))return{ancestor:null,callType:null};if(a.type===p.Loop){if(a.body.calls.includes(i))return{ancestor:a,callType:"loop-body"}}else if(jt.includes(a.type)){if(a.calls.includes(i))return a.type===p.FunctionDeclaration&&a.parent.type===p.Loop?{ancestor:a,callType:"loop-body"}:{ancestor:a,callType:"entry"}}else if(mi.includes(a.type)){if(a.successCalls.includes(i))return{ancestor:a,callType:"success"};if(a.errorCalls.includes(i))return{ancestor:a,callType:"error"}}const e=l.filter(O=>!(O.callee===i||!jr.includes(O.callee.type)||!ht(O.callee).find(U=>U===i))).filter((O,L,M)=>M.findIndex(U=>U.callee===O.callee)===L);if(e.length===0)return{ancestor:null,callType:null};if(e.length===1){const O=e[0];if(O.callee.type===p.Loop){if(O.callee.body.calls.includes(i))return{ancestor:O.callee,callType:"loop-body"}}else{if(jt.includes(O.callee.type))return O.callee.type===p.FunctionDeclaration&&O.callee.parent.type===p.Loop?{ancestor:O.callee,callType:"loop-body"}:{ancestor:O.callee,callType:"entry"};if(mi.includes(O.callee.type)){if(O.callType==="success"&&O.callee.type===p.InternalCall)return{ancestor:O.callee,callType:"success"};if(O.callType==="error"&&O.callee.type===p.InternalCall)return{ancestor:O.callee,callType:"error"}}}}const y=e.filter(O=>jw(i,O.callee)),v=y.filter(O=>{const L=ht(O.callee),M=y.filter(q=>q.callee!==O.callee).map(q=>q.callee);return!L.some(q=>!!M.find(H=>H===q))});if(v.length===0){if(a.type===p.Loop){if(ht(a.body).find(H=>H===i))return{ancestor:a,callType:"loop-body"};if(Tr(a.successCalls).find(H=>H===i))return{ancestor:a,callType:"success"};if(Tr(a.errorCalls).find(H=>H===i))return{ancestor:a,callType:"error"}}else if(mi.includes(a.type)){if(Tr(a.successCalls).find(q=>q===i))return{ancestor:a,callType:"success"};if(Tr(a.errorCalls).find(q=>q===i))return{ancestor:a,callType:"error"}}return a.parent.type===p.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(O=>S(O.callee,i.project)).join(", ")}`);const T=v[0].callee,b=oy(T).find(O=>O.callee===i);return{ancestor:T,callType:b.callType}}function W$e(d){if(![p.VariableDeclaration,p.OutputMap].includes(d.type))throw new Error("getEarliestSingleCallerAncestorOfValueWriterAndItsValueReaders can only be used with a value writer entity");let u;if(d.type===p.VariableDeclaration?u=d:d.type===p.OutputMap&&(u=d.parent),!u)throw new Error("getEarliestSingleCallerAncestorOfValueWriterAndItsValueReaders can only be used with a value writer entity that has a caller");const i=C([d,...x0(d),...$t.includes(d.type)?d.outputs.flatMap(y=>x0(y)):[]]),a=C(i.map(y=>kw(y)).flatMap(y=>Gt.includes(y==null?void 0:y.type)?y.calledBy:[y]));if(a.length===1){const y=a[0];if(jt.includes(y.type))return y.parent.type===p.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: ${S(y,u.project)}`)}const l=a.map(y=>{var T;if(jt.includes(y.type))return y.parent.type===p.Loop?{ancestor:y,callType:"loop-body"}:{ancestor:y,callType:"entry"};if(y.parent===d.project&&!((T=u.calledBy)!=null&&T.length)){if(y===u)return{ancestor:y,callType:"success"};const A=Tr(y.successCalls),b=Tr(y.errorCalls);if(A.includes(u))return{ancestor:y,callType:"success"};if(b.includes(u))return{ancestor:y,callType:"error"}}const v=aH(y);if(!v.ancestor)throw new Error(`getEarliestSingleCallerAncestorOfValueWriterAndItsValueReaders: Could not be resolved, no ancestor found for ${S(y,u.project)}`);return v}).filter((y,v,T)=>v===T.findIndex(A=>{var b,O;return((b=A.ancestor)==null?void 0:b.id)===((O=y.ancestor)==null?void 0:O.id)})),f=ay(u),e=l.filter(y=>y!=null&&y.ancestor?f===y.ancestor?!0:!l.filter(A=>A.ancestor!==y.ancestor).map(A=>A.ancestor).some(A=>{const b=bo(y.ancestor,A);return!!(b!=null&&b.last)}):!1);if(e.length===0)return{ancestor:f,callType:(f==null?void 0:f.parent.type)===p.Loop?"loop-body":"entry"};if(e.length>1)throw new Error(`getEarliestSingleCallerAncestorOfValueWriterAndItsValueReaders: Could not be resolved, multiple candidates found: ${e.map(y=>S(y.ancestor,u.project)).join(", ")}`);return{ancestor:e[0].ancestor,callType:e[0].callType}}function lH(d,u){if(d===u)return!0;if(ht(d).includes(u)||!ht(u).includes(d))return!1;const l=d.calledBy;return l.length===0?!1:l.length===1?l[0]===u:nH(l).length>1&&l.includes(u)?!1:l.every(e=>d===u?!0:jt.includes(e.type)?!1:lH(e,u))}function oH(d){const u=[];let i=d.calledBySuccess;i=i.filter(l=>!i.filter(y=>y!==l).some(y=>j0(y,l)));let a=d.calledByError;a=a.filter(l=>!a.filter(y=>y!==l).some(y=>j0(y,l)));for(const l of i)u.push({ancestor:l,callType:"success"});for(const l of a)u.push({ancestor:l,callType:"error"});return u}function dH(d){const u=[];return oH(d).forEach(a=>{a.ancestor.type===p.Condition&&u.push({condition:a.ancestor,call:d,callType:a.callType});const f=dH(a.ancestor).filter(e=>!u.some(y=>y.condition.id===e.condition.id));u.push(...f)}),u}function kw(d){if(!d)return null;if(d.type===p.Condition&&d.parent.type===p.Condition)return G0(d.parent);if(zT.includes(d.type))return d;const u=d.parent;return u?kw(u):null}function x0(d,u=new Set){return d.writesValues.reduce((i,a)=>u.has(a.id)?i:(u.add(a.id),Xn.includes(a.type)?[...i,a]:Qi.includes(a.type)?[...i,a,...x0(a,u)]:i),[])}function ly(d){const u=d.calledBy;if(u.length===0)return d.project;const i=u.reduce((a,l)=>{const f=Yr(l,d.project);return!f||f.type===p.Project?a:a.type===p.Project||ip(f,a).last?f:(ip(a,f).last,a)},d.project);return i.type===p.FunctionDeclaration&&i.parent.type===p.Loop?i.parent:i}function et(d,u){let i=ly(d);if(d.type===p.InternalCall)if(d.parent.type===p.VariableInstance){const l=gs(i,d.parent.declaration,d.project);!l.compatible&&l.type!=="b-is-global-a-is-not"?d.parent.remove({ignoreUpstream:!1},u):(d.parent.setParent(i,u),d.parent.addSelfToProject(u))}else d.parent.setParent(i,u),d.parent.addSelfToProject(u);else if((d.type===p.ContinueStatement||d.type===p.BreakStatement)&&i.type!==p.Loop){d.remove({ignoreUpstream:!1},u);return}else if(d.type===p.ReturnStatement&&!Xi.includes(i.type)){d.remove({ignoreUpstream:!1},u);return}else if($t.includes(d.type)){const l=d.usedInternalCalls[0];if(l)if(i=ly(l),d.type===p.VariableInstance){const f=gs(i,d.declaration,d.project);!f.compatible&&f.type!=="b-is-global-a-is-not"?d.remove({ignoreUpstream:!1},u):(d.setParent(i,u),d.addSelfToProject(u))}else d.setParent(i,u),d.addSelfToProject(u);else if(d.type===p.VariableInstance){const f=gs(i,d.declaration,d.project);!f.compatible&&f.type!=="b-is-global-a-is-not"?d.remove({ignoreUpstream:!1},u):(d.setParent(i,u),d.addSelfToProject(u))}else d.setParent(i,u),d.addSelfToProject(u)}else d.setParent(i,u),d.addSelfToProject(u);if(Gt.includes(d.type))return;ht(d).forEach(l=>{let f=ly(l);if(l.type===p.InternalCall)if(l.parent.type===p.VariableInstance){const e=gs(f,l.parent.declaration,d.project);!e.compatible&&e.type!=="b-is-global-a-is-not"?l.parent.remove({ignoreUpstream:!1},u):(l.parent.setParent(f,u),l.parent.addSelfToProject(u))}else l.parent.setParent(f,u),l.parent.addSelfToProject(u);else if((l.type===p.ContinueStatement||l.type===p.BreakStatement)&&f.type!==p.Loop){l.remove({ignoreUpstream:!1},u);return}else if(l.type===p.ReturnStatement&&!Xi.includes(f.type)){l.remove({ignoreUpstream:!1},u);return}else if($t.includes(l.type)){const e=l.usedInternalCalls[0];if(e)if(f=ly(e),l.type===p.VariableInstance){const y=gs(f,l.declaration,d.project);!y.compatible&&y.type!=="b-is-global-a-is-not"?l.remove({ignoreUpstream:!1},u):(l.setParent(f,u),l.addSelfToProject(u))}else l.setParent(f,u),l.addSelfToProject(u);else if(l.type===p.VariableInstance){const y=gs(f,l.declaration,d.project);!y.compatible&&y.type!=="b-is-global-a-is-not"?l.remove({ignoreUpstream:!1},u):(l.setParent(f,u),l.addSelfToProject(u))}else l.setParent(f,u),l.addSelfToProject(u)}else l.setParent(f,u),l.addSelfToProject(u)})}function U0(d,u,i=new Set){const a=ta(d),l=ta(u),f=a.filter(v=>!l.includes(v)),e=a.filter(v=>l.includes(v)),y=f.reduce((v,T)=>i.has(T.id)?v:(i.add(T.id),C([...v,...U0(T,u,i)])),[]);return C([...e,...y])}function Cd(d,u){const i=ip(d,u);return i.last===u&&i.list.length>0&&i.list[0]!==u}function Fw(d,u){return!!ip(d,u).last}function j0(d,u){return!!bo(d,u).last}function Kw(d,u){if(!d||!u)throw new Error("Both entities must be defined to find a common ancestor");if(d===u)return d;const i=d.parent;if(i){if(i===u)return u;if(i.type===p.Project)return null}else return null;const a=u.parent;if(a){if(a===d)return d;if(a.type===p.Project)return null}else return null;return Kw(i,a)}function H$e(d,u,i=!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(en.includes(d.type)&&jr.includes(u.type)){const y=bo(d,u),v=y.last;if(v){if(v===u)return{ancestor:u,callType:y.callType}}else return{ancestor:null,callType:null}}if(en.includes(u.type)&&jr.includes(d.type)){const y=bo(u,d),v=y.last;if(v){if(v===d)return{ancestor:d,callType:y.callType}}else return{ancestor:null,callType:null}}const a=ay(d),l=ay(u);if(!a||!l)return{ancestor:null,callType:null};if(a!==l)return{ancestor:null,callType:null};if(a.calls.includes(d)||a.calls.includes(u))return{ancestor:a,callType:"entry"};const f=a.calls.reduce((y,v)=>{if(!jr.includes(v.type))return y;const T=oy(v),A=T.find(O=>O.callee===d),b=T.find(O=>O.callee===u);return A&&b&&(!i||A.callType===b.callType)?[...y,{ancestor:v,callType:A.callType}]:y},[]);if(f.length===0)return{ancestor:null,callType:null};if(f.length===1)return{ancestor:f[0].ancestor,callType:f[0].callType};const e=f.filter(y=>!f.some(v=>v.ancestor!==y.ancestor&&bo(y.ancestor,v.ancestor).last===v.ancestor));return e.length===1?{ancestor:e[0].ancestor,callType:e[0].callType}:{ancestor:a,callType:"entry"}}function Ni(d){if(rc.includes(d.type)){if(d.type===p.FunctionDeclaration){const u=d.parent;if(u.type===p.DefinitionEntity)return Ni(u);if(u.type===p.Loop)return u}return d.type===p.DefinitionEntity&&d.parent.type===p.DataType||d.type===p.Condition&&d.parent.type===p.Condition?Ni(d.parent):d}else{const u=d.parent;return u?Ni(u):null}}function rp(d,u){const i=np(d,u);if(!i)return null;if(rc.includes(i.type)){if(i.type===p.FunctionDeclaration){const a=np(i.parent,u);if(a){if(a.type===p.DefinitionEntity)return a;if(a.type===p.Loop)return a}}if(i.parent){const a=np(i.parent,u);if(a&&(i.type===p.DefinitionEntity&&a.type===p.DataType||i.type===p.Condition&&a.type===p.Condition))return rp(a,u)}return i}else{const a=i.parent?np(i.parent,u):null;return a?rp(a,u):null}}function oy(d){if(d.type===p.Loop){const u=[...Tr(d.successCalls).map(l=>({callee:l,callType:"success"})),...Tr(d.errorCalls).map(l=>({callee:l,callType:"error"})),...(d.body?ht(d.body):[]).map(l=>({callee:l,callType:"loop-body"}))];return C(u.map(l=>l.callee)).map(l=>{var e;const f=(e=u.find(y=>y.callee===l))==null?void 0:e.callType;return{callee:l,callType:f}})}if(mi.includes(d.type)){const u=[...Tr(d.successCalls).map(l=>({callee:l,callType:"success"})),...Tr(d.errorCalls).map(l=>({callee:l,callType:"error"}))];return C(u.map(l=>l.callee)).map(l=>{var e;const f=(e=u.find(y=>y.callee===l))==null?void 0:e.callType;return{callee:l,callType:f}})}if(jt.includes(d.type)){const u=[...Tr(d.calls).map(l=>d.parent.type===p.Loop?{callee:l,callType:"loop-body"}:{callee:l,callType:"entry"})];return C(u.map(l=>l.callee)).map(l=>{var e;const f=(e=u.find(y=>y.callee===l))==null?void 0:e.callType;return{callee:l,callType:f}})}return[]}function G0(d){if(!d)return null;if(d.type===p.Condition&&d.parent.type===p.Condition)return G0(d.parent);if(en.includes(d.type))return d;const u=d.parent;return u?G0(u):null}function uH(d){if(!d)return null;if(mi.includes(d.type))return d;const u=d.parent;return u?uH(u):null}function pH(d){if(!d)return null;if(jr.includes(d.type))return d;const u=d.parent;return u?pH(u):null}function J$e(d){return d.type===p.VariableDeclaration?[d]:mi.includes(d.type)?[...d.inputs,...d.outputs||[]]:Gt.includes(d.type)?d.outputs:ko.includes(d.type)||d.type===p.FunctionDeclaration?d.inputs:[]}function z$e(d){const u=ta(d),i=[],a=[];gg.includes(d.type)&&i.push(...k0(d));const l=u.filter(f=>{const e=i.includes(f);return e?!1:en.includes(f.type)&&!e?(a.push(f),!1):!0});return i.sort((f,e)=>Cd(e,f)?-1:0),a.sort((f,e)=>Cd(e,f)?-1:0),[...i,...a,...l]}function cH(d){return[...d].sort((u,i)=>Cd(i,u)?-1:0)}function S$e(d){const u=cH(d),i=[];return u.forEach(a=>{const l=i[i.length-1];if(l){const f=l[l.length-1];Cd(a,f)?i.push([a]):l.push(a)}else i.push([a])}),i}function Tl(d){const u=d.map(i=>Ni(i));return C(u)}function k0(d){return mi.includes(d.type)?[...Tl(d.successCalls),...Tl(d.errorCalls)]:jt.includes(d.type)?Tl(d.calls):[]}function Y$e(d,u){return k0(d).includes(u)}function F0(d){return d.writesValues||[]}function X$e(d,u){return F0(d).includes(u)}function fH(d){var u;return $t.includes((u=d==null?void 0:d.readsValue)==null?void 0:u.type)?d.readsValue:null}function Q$e(d){return d.writesValues}function yH(d=[]){return d.map(fH).filter(u=>!!u)}function K0(d=[]){return d.map(u=>u.writesValues).flat().filter(u=>$t.includes(u.type))}function hH(d=[]){return d.map(u=>u.readsValue).filter(u=>!!u&&$t.includes(u.type))}function mH(d){return $t.includes(d.type)?d:null}function vH(d){return d.writesValues.map(mH).filter(u=>!!u)}function TH(d=[]){return d.reduce((u,i)=>i.type===p.OutputMap?[...u,...vH(i)]:u,[])}function ht(d){return d.type===p.Loop?C([...Tr(d.successCalls),...Tr(d.errorCalls),...d.body?ht(d.body):[]]):mi.includes(d.type)?C([...Tr(d.successCalls),...Tr(d.errorCalls)]):jt.includes(d.type)?C(Tr(d.calls)):[]}function eVe(d){return mi.includes(d.type)?[...Tr(d.successCalls),...Tr(d.errorCalls)]:jt.includes(d.type)?Tr(d.calls):[]}function EH(d,u=new Set){return d.writesValues.filter(a=>$t.includes(a.type)&&!u.has(a.id)).reduce((a,l)=>u.has(l.id)?a:[...a,...Li(l,u)],[])}function bH(d,u=new Set){var a;return(((a=d.readsValue)==null?void 0:a.writesValues)||[]).filter(l=>$t.includes(l.type)&&!u.has(l.id)).reduce((l,f)=>u.has(f.id)?l:[...l,...Li(f,u)],[])}function Li(d,u=new Set){if(u.has(d.id))return[];if(d.type===p.ReturnStatement)return hH(d.outputs).reduce((a,l)=>[...a,...Li(l,u)],[]);if(d.type===p.FunctionCall||d.type===p.Operation||d.type===p.Condition)return[...ht(d).reduce((f,e)=>{const y=Ni(e);return[...f,...Li(y||e,u)]},[]),...yH(d.inputs),...TH(d.outputs)].reduce((f,e)=>[...f,...Li(e,u)],[]);if(ko.includes(d.type)){const i=K0(d.inputs),l=ht(d).reduce((f,e)=>{const y=Ni(e);return[...f,...Li(y||e,u)]},[]);return i.push(...l),i.reduce((f,e)=>[...f,...Li(e,u)],[])}if(d.type===p.FunctionDeclaration){const i=[...K0(d.inputs)],l=ht(d).reduce((f,e)=>{const y=Ni(e);return[...f,...Li(y||e,u)]},[]);return i.push(...l),i.reduce((f,e)=>[...f,...Li(e)],[])}if($t.includes(d.type)){u.add(d.id);const a=ht(d).reduce((l,f)=>{const e=Ni(f);return[...l,...Li(e||f,u)]},[]);return[d,...a,...bH(d,u),...EH(d,u)]}return[]}function Fn(d,u=new Set){if(u.has(d.id))return[];u.add(d.id),J.log("[flattenDerivedCanvasEntities]",d.type,S(d,d.project),d.id);const i=ta(d);return i.forEach(l=>{u.add(l.id)}),[...i.reduce((l,f)=>(J.log("[Recursive -- flattenDerivedCanvasEntities]",f.type,S(f,f.project),f.id),[...l,f,...Fn(f,u)]),[])]}function Tr(d){return d.reduce((u,i)=>i.type===p.ReturnStatement||i.type===p.ContinueStatement||i.type===p.BreakStatement?[...u,i]:[...u,i,...ht(i)],[])}function IH(d){const u=d.entities||[],i=[...u,...d.functions||[],...d.events||[],...d.projects||[]],a=u.reduce((v,T)=>[...v,...T.properties],[]),l=u.reduce((v,T)=>[...v,...T.methods],[]),f=l.reduce((v,T)=>[...v,...K0(T.inputs),...Tr(Tl(T.calls)),...T.returnStatements],[]),e=d.functions.reduce((v,T)=>[...v,...Tr(Tl(T.calls)),...T.returnStatements],[]),y=d.events.reduce((v,T)=>[...v,...Tr(Tl(T.calls)),...T.returnStatements],[]);return[...i,...a,...l,...f,...e,...y]}function AH(d,u){return u.filter(a=>{if(!a)return!1;switch(a.type){case p.FunctionCall:return a.inputs.find(l=>l.id===d.id)!==void 0||a.outputs.find(l=>l.id===d.id)!==void 0;case p.Condition:return a.successCalls.find(l=>l.id===d.id)!==void 0||a.errorCalls.find(l=>l.id===d.id)!==void 0||a.inputs.find(l=>l.id===d.id)!==void 0;case p.Operation:return a.outputs.find(l=>l.id===d.id)!==void 0;case p.VariableDeclaration:return mi.includes(d.type)?SH(d).find(f=>{var e;return((e=f.readsValue)==null?void 0:e.id)===a.id})!==void 0:!1;case p.DefinitionEntity:return a.properties.find(l=>l.id===d.id)!==void 0||a.methods.find(l=>l.id===d.id)!==void 0;case p.FunctionDeclaration:return a.inputs.find(l=>l.id===d.id)!==void 0||(a.returnStatements.map(l=>l.outputs).flat()||[]).find(l=>l.id===d.id)!==void 0;default:return!1}})}function tVe(d){const u=IH(d.project);return AH(d,u)}function np(d,u){return d?typeof d=="string"?u[d]:d.type===p.GenericReference?u[d.entityId]:u[d.id]?u[d.id]:null:null}function wH(d={},u){const i={};return Object.keys(d).forEach(a=>{const l=u.get(a)||a,f=d[a];i[l]=f}),i}function sp(d,u={},i={}){const a={ignoreBuiltInBaseEntities:!1,allBuiltInEntityIds:[],entityMaps:new Map,...i};if(a.ignoreBuiltInBaseEntities&&(vn.includes(d.type)||(a.allBuiltInEntityIds||[]).includes(d.id)))return{upstream:{},downstream:{}};const l=d,f=d,e=d,y=d,v=d,T=d,A=d,b=d,O=d,L=d,M=d,U=d,q=d,Z=d,H=[...Z.readsValue?[Z.readsValue]:[],...Z.declaration?[Z.declaration]:[],...(q.calledByEntry||[]).flatMap(ne=>ne),...(q.calledBySuccess||[]).flatMap(ne=>ne),...(q.calledByError||[]).flatMap(ne=>ne),...M.parent?[M.parent]:[]];Array.isArray(e.implements)?H.push(...e.implements.flatMap(ne=>ne)):L.implements&&H.push(L.implements),Array.isArray(e.extends)?H.push(...e.extends.flatMap(ne=>ne)):O.extends&&H.push(O.extends),v.valueAsTypeList&&Array.isArray(v.valueAsTypeList)&&H.push(...v.valueAsTypeList.flatMap(ne=>ne)),v.valueAsTypeSingle&&H.push(v.valueAsTypeSingle),(Z.internalCalls||[]).forEach(ne=>{const te=ee(ne);if(te&&u[te]){const fe=u[te];[...fe.calledByEntry||[],...fe.calledBySuccess||[],...fe.calledByError||[]].forEach(me=>{const Y=ee(me);Y&&u[Y]&&H.push(u[Y])})}});const z=[...(l.inputs||[]).flatMap(ne=>ne),...(U.inputsDeclarations||[]).flatMap(ne=>ne),...(U.outputs||[]).flatMap(ne=>ne),...(Z.internalCalls||[]).flatMap(ne=>ne),...Z.writesValues||[],...q.dataType?[q.dataType]:[],...T.body?[T.body]:[],...q.defaultValue?[q.defaultValue]:[],...(q.successCalls||[]).flatMap(ne=>ne),...(q.errorCalls||[]).flatMap(ne=>ne),...(e.properties||[]).flatMap(ne=>ne),...(e.methods||[]).flatMap(ne=>ne),...(e.abstractMethods||[]).flatMap(ne=>ne),...A.error?[A.error]:[],...M.throws?[M.throws]:[],...(f.andChildrenGroup||[]).flatMap(ne=>ne),...(f.orChildrenGroup||[]).flatMap(ne=>ne),...(b.entities||[]).flatMap(ne=>ne),...(b.functions||[]).flatMap(ne=>ne),...(b.functionCalls||[]).flatMap(ne=>ne),...(b.events||[]).flatMap(ne=>ne),...(b.conditions||[]).flatMap(ne=>ne),...(b.operations||[]).flatMap(ne=>ne),...(b.loops||[]).flatMap(ne=>ne),...(b.variableDeclarations||[]).flatMap(ne=>ne),...(b.variableInstances||[]).flatMap(ne=>ne),...(b.searches||[]).flatMap(ne=>ne),...(b.projects||[]).flatMap(ne=>ne),...(y.calls||[]).flatMap(ne=>ne)];d.type===p.DataType&&(f.entity&&u[ee(f.entity)]&&u[ee(f.entity)].parent&&ee(u[ee(f.entity)].parent)===d.id?z.push(f.entity):f.entity&&H.push(f.entity)),(Z.internalCalls||[]).forEach(ne=>{const te=ee(ne);if(te&&u[te]){const fe=u[te];[...fe.successCalls||[],...fe.errorCalls||[]].forEach(me=>{const Y=ee(me);Y&&u[Y]&&z.push(u[Y])})}});const oe={},ie={};return H.forEach(ne=>{var me;const te=ee(ne);if(te&&a.ignoreBuiltInBaseEntities&&(vn.includes(ne.type)||(a.allBuiltInEntityIds||[]).includes(te)))return;const fe=ne.version;if(te){const Y=((me=a.entityMaps)==null?void 0:me.get(te))||te;oe[Y]=fe}}),z.forEach(ne=>{var me;const te=ee(ne);if(te&&a.ignoreBuiltInBaseEntities&&(vn.includes(ne.type)||(a.allBuiltInEntityIds||[]).includes(te)))return;const fe=ne.version;if(te){const Y=((me=a.entityMaps)==null?void 0:me.get(te))||te;ie[Y]=fe}}),{upstream:oe,downstream:ie}}function iVe(d,u){const i=[];if(en.includes(d.type)){ls(d).forEach(f=>{const e=rp(f,u);e&&i.push(e)});const l=[...d.inputs||[],...d.outputs||[]].map(f=>{const e=np(f,u);return e?YH(e,u):null}).filter(f=>f!==null);i.push(...C(l))}if($t.includes(d.type)){const a=q0(d);a&&i.push(a)}return C(i)}function Io(d){const u=[];if(en.includes(d.type)){d.calledBy.forEach(l=>{const f=Ni(l);f&&u.push(f)});const a=[...d.inputs||[],...d.outputs||[]].map(l=>q0(l)).filter(l=>l!==null);u.push(...C(a))}if(Xn.includes(d.type)){const i=q0(d);i&&u.push(i)}return C(u)}function ls(d){return[...d.calledByEntry||[],...d.calledByError||[],...d.calledBySuccess||[]].filter(u=>u.type!==p.GenericReference)}function RH(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==p.ActionDescriptor)throw new Error("Entity must be an action descriptor to be flattened");return[d,...d.inputs.flatMap(a=>Te(a,u,i)),...d.dataType?Te(d.dataType,u,i):[],...d.error?Te(d.error,u,i):[],...d.parent?Te(d.parent,u,i):[]]}function CH(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==p.ArgumentDeclaration)throw new Error("Entity must be an argument declaration to be flattened");return[d,...d.defaultValue?Te(d.defaultValue,u):[],...d.writesValues.flatMap(a=>Te(a,u,i)),...d.dataType?Te(d.dataType,u,i):[],...d.parent?Te(d.parent,u,i):[]]}function gH(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==p.BreakStatement)throw new Error("Entity must be a break statement to be flattened");return[d,...d.outputs.flatMap(a=>Te(a,u,i)),...d.throws?Te(d.throws,u,i):[],...d.implements?Te(d.implements,u,i):[],...d.dataType?Te(d.dataType,u,i):[],...d.readsValue?Te(d.readsValue,u,i):[],...(ls(d)||[]).flatMap(a=>Te(a,u,i)),...d.parent?Te(d.parent,u,i):[]]}function _H(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==p.BuiltInBaseEntity)throw new Error("Entity must be a built-in base entity to be flattened");return[d,...(d.properties||[]).flatMap(a=>Te(a,u,i)),...(d.methods||[]).flatMap(a=>Te(a,u,i)),...(d.abstractMethods||[]).flatMap(a=>Te(a,u,i)),...d.allPropertiesImplement?Te(d.allPropertiesImplement,u,i):[],...d.additionalPropertiesDataType?Te(d.additionalPropertiesDataType,u,i):[],...d.extends?Te(d.extends,u,i):[]]}function DH(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==p.Condition)throw new Error("Entity must be a condition to be flattened");return[d,...(d.andChildrenGroup||[]).flatMap(a=>Te(a,u,i)),...(d.orChildrenGroup||[]).flatMap(a=>Te(a,u,i)),...(d.inputs||[]).flatMap(a=>Te(a,u,i)),...(d.successCalls||[]).flatMap(a=>Te(a,u,i)),...(d.errorCalls||[]).flatMap(a=>Te(a,u,i)),...(ls(d)||[]).flatMap(a=>Te(a,u,i)),...d.parent?Te(d.parent,u,i):[]]}function OH(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==p.ContinueStatement)throw new Error("Entity must be a continue statement to be flattened");return[d,...d.outputs.flatMap(a=>Te(a,u,i)),...d.readsValue?Te(d.readsValue,u,i):[],...d.implements?Te(d.implements,u,i):[],...d.throws?Te(d.throws,u,i):[],...d.dataType?Te(d.dataType,u,i):[],...(ls(d)||[]).flatMap(a=>Te(a,u,i)),...d.parent?Te(d.parent,u,i):[]]}function PH(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==p.DefinitionEntity)throw new Error("Entity must be a definition entity to be flattened");return[d,...d.extends?Te(d.extends,u,i):[],...(d.implements||[]).flatMap(a=>Te(a,u,i)),...(d.properties||[]).flatMap(a=>Te(a,u,i)),...(d.methods||[]).flatMap(a=>Te(a,u,i)),...(d.abstractMethods||[]).flatMap(a=>Te(a,u,i)),...d.allPropertiesImplement?Te(d.allPropertiesImplement,u,i):[],...d.additionalPropertiesDataType?Te(d.additionalPropertiesDataType,u,i):[],...d.parent?Te(d.parent,u,i):[]]}function $H(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==p.DataType)throw new Error("Entity must be a data type to be flattened");return[d,...(d.andChildrenGroup||[]).flatMap(a=>Te(a,u,i)),...(d.orChildrenGroup||[]).flatMap(a=>Te(a,u,i)),...d.entity?Te(d.entity,u,i):[],...d.parent?Te(d.parent,u,i):[]]}function VH(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==p.FunctionCall)throw new Error("Entity must be a function call to be flattened");return[d,...(d.inputs||[]).flatMap(a=>Te(a,u,i)),...(d.outputs||[]).flatMap(a=>Te(a,u,i)),...d.error?Te(d.error,u,i):[],...(ls(d)||[]).flatMap(a=>Te(a,u,i)),...(d.successCalls||[]).flatMap(a=>Te(a,u,i)),...(d.errorCalls||[]).flatMap(a=>Te(a,u,i)),...(d.writesValues||[]).flatMap(a=>Te(a,u,i)),...d.parent?Te(d.parent,u,i):[]]}function NH(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==p.FunctionDeclaration)throw new Error("Entity must be a function declaration to be flattened");return[d,...(d.inputs||[]).flatMap(a=>Te(a,u,i)),...(d.calls||[]).flatMap(a=>Te(a,u,i)),...d.implements?Te(d.implements,u,i):[],...d.parent?Te(d.parent,u,i):[]]}function LH(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==p.GlobalEvent)throw new Error("Entity must be a global event to be flattened");return[d,...(d.inputs||[]).flatMap(a=>Te(a,u,i)),...(d.calls||[]).flatMap(a=>Te(a,u,i)),...d.implements?Te(d.implements,u,i):[],...d.parent?Te(d.parent,u,i):[]]}function BH(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==p.InputMap)throw new Error("Entity must be an input map to be flattened");return[d,...d.readsValue?Te(d.readsValue,u,i):[],...d.declaration?Te(d.declaration,u,i):[],...d.defaultValue?Te(d.defaultValue,u,i):[],...d.parent?Te(d.parent,u,i):[]]}function MH(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==p.InstalledProject)throw new Error("Entity must be an installed project to be flattened");return[d,...(d.functions||[]).flatMap(a=>Te(a,u,i)),...(d.events||[]).flatMap(a=>Te(a,u,i)),...d.parent?Te(d.parent,u,i):[]]}function xH(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==p.InternalCall)throw new Error("Entity must be an internal call to be flattened");return[d,...(d.successCalls||[]).flatMap(a=>Te(a,u,i)),...(d.errorCalls||[]).flatMap(a=>Te(a,u,i)),...(d.inputs||[]).flatMap(a=>Te(a,u,i)),...(d.outputs||[]).flatMap(a=>Te(a,u,i)),...(ls(d)||[]).flatMap(a=>Te(a,u,i)),...d.error?Te(d.error,u,i):[],...(d.writesValues||[]).flatMap(a=>Te(a,u,i)),...d.parent?Te(d.parent,u,i):[]]}function UH(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==p.LiteralValue)throw new Error("Entity must be a literal value to be flattened");return[d,...d.valueAsTypeSingle?Te(d.valueAsTypeSingle,u,i):[],...d.valueAsTypeList&&Array.isArray(d.valueAsTypeList)?d.valueAsTypeList.flatMap(a=>Te(a,u,i)):[],...d.parent?Te(d.parent,u,i):[]]}function jH(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==p.Loop)throw new Error("Entity must be a loop to be flattened");return[d,...(d.inputs||[]).flatMap(a=>Te(a,u,i)),...(d.outputs||[]).flatMap(a=>Te(a,u,i)),...(d.successCalls||[]).flatMap(a=>Te(a,u,i)),...(d.errorCalls||[]).flatMap(a=>Te(a,u,i)),...d.error?Te(d.error,u,i):[],...d.dataType?Te(d.dataType,u,i):[],...d.body?Te(d.body,u,i):[],...(ls(d)||[]).flatMap(a=>Te(a,u,i)),...(d.writesValues||[]).flatMap(a=>Te(a,u,i)),...d.parent?Te(d.parent,u,i):[]]}function GH(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==p.Operation)throw new Error("Entity must be an operation to be flattened");return[d,...(d.successCalls||[]).flatMap(a=>Te(a,u,i)),...(d.errorCalls||[]).flatMap(a=>Te(a,u,i)),...(d.inputs||[]).flatMap(a=>Te(a,u,i)),...(d.outputs||[]).flatMap(a=>Te(a,u,i)),...(d.writesValues||[]).flatMap(a=>Te(a,u,i)),...d.error?Te(d.error,u,i):[],...(ls(d)||[]).flatMap(a=>Te(a,u,i)),...d.parent?Te(d.parent,u,i):[]]}function kH(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==p.OutputMap)throw new Error("Entity must be an output map to be flattened");return[d,...(d.writesValues||[]).flatMap(a=>Te(a,u,i)),...d.declaration?Te(d.declaration,u,i):[],...d.parent?Te(d.parent,u,i):[]]}function FH(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==p.PrimitiveEntity)throw new Error("Entity must be a primitive entity to be flattened");return[d,...(d.properties||[]).flatMap(a=>Te(a,u,i)),...(d.methods||[]).flatMap(a=>Te(a,u,i)),...(d.abstractMethods||[]).flatMap(a=>Te(a,u,i))]}function KH(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==p.Project)throw new Error("Entity must be a project to be flattened");return[d,...(d.entities||[]).flatMap(a=>Te(a,u,i)),...(d.functions||[]).flatMap(a=>Te(a,u,i)),...(d.events||[]).flatMap(a=>Te(a,u,i)),...(d.projects||[]).flatMap(a=>Te(a,u,i)),...(d.variableDeclarations||[]).flatMap(a=>Te(a,u,i)),...(d.variableInstances||[]).flatMap(a=>Te(a,u,i)),...(d.operations||[]).flatMap(a=>Te(a,u,i)),...(d.conditions||[]).flatMap(a=>Te(a,u,i)),...(d.functionCalls||[]).flatMap(a=>Te(a,u,i)),...(d.projects||[]).flatMap(a=>Te(a,u,i)),...(d.loops||[]).flatMap(a=>Te(a,u,i)),...(d.searches||[]).flatMap(a=>Te(a,u,i))]}function qH(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==p.Property)throw new Error("Entity must be a property to be flattened");return[d,...d.defaultValue?Te(d.defaultValue,u,i):[],...d.dataType?Te(d.dataType,u,i):[],...d.parent?Te(d.parent,u,i):[]]}function ZH(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==p.ReturnStatement)throw new Error("Entity must be a return statement to be flattened");return[d,...(d.outputs||[]).flatMap(a=>Te(a,u,i)),...d.throws?Te(d.throws,u,i):[],...d.implements?Te(d.implements,u,i):[],...d.readsValue?Te(d.readsValue,u,i):[],...d.dataType?Te(d.dataType,u,i):[],...(ls(d)||[]).flatMap(a=>Te(a,u,i)),...d.parent?Te(d.parent,u,i):[]]}function WH(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==p.Search)throw new Error("Entity must be a search to be flattened");return[d,...(d.successCalls||[]).flatMap(a=>Te(a,u,i)),...(d.errorCalls||[]).flatMap(a=>Te(a,u,i)),...(d.inputsDeclarations||[]).flatMap(a=>Te(a,u,i)),...(d.inputs||[]).flatMap(a=>Te(a,u,i)),...(d.writesValues||[]).flatMap(a=>Te(a,u,i)),...(d.outputs||[]).flatMap(a=>Te(a,u,i)),...d.error?Te(d.error,u,i):[],...d.dataType?Te(d.dataType,u,i):[],...(ls(d)||[]).flatMap(a=>Te(a,u,i)),...d.parent?Te(d.parent,u,i):[]]}function HH(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==p.ValueDescriptor)throw new Error("Entity must be a value descriptor to be flattened");return[d,...d.defaultValue?Te(d.defaultValue,u,i):[],...d.dataType?Te(d.dataType,u,i):[],...d.parent?Te(d.parent,u,i):[]]}function JH(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==p.VariableDeclaration)throw new Error("Entity must be a variable declaration to be flattened");return[d,...(d.successCalls||[]).flatMap(a=>Te(a,u,i)),...(d.errorCalls||[]).flatMap(a=>Te(a,u,i)),...(d.inputs||[]).flatMap(a=>Te(a,u,i)),...(d.outputs||[]).flatMap(a=>Te(a,u,i)),...(d.internalCalls||[]).flatMap(a=>Te(a,u,i)),...(d.writesValues||[]).flatMap(a=>Te(a,u,i)),...d.readsValue?Te(d.readsValue,u,i):[],...d.defaultValue?Te(d.defaultValue,u,i):[],...(ls(d)||[]).flatMap(a=>Te(a,u,i)),...d.dataType?Te(d.dataType,u,i):[],...d.parent?Te(d.parent,u,i):[]]}function zH(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==p.VariableInstance)throw new Error("Entity must be a variable instance to be flattened");return[d,...(d.successCalls||[]).flatMap(a=>Te(a,u,i)),...(d.errorCalls||[]).flatMap(a=>Te(a,u,i)),...(d.inputs||[]).flatMap(a=>Te(a,u,i)),...(d.outputs||[]).flatMap(a=>Te(a,u,i)),...(d.internalCalls||[]).flatMap(a=>Te(a,u,i)),...(d.writesValues||[]).flatMap(a=>Te(a,u,i)),...d.readsValue?Te(d.readsValue,u,i):[],...d.defaultValue?Te(d.defaultValue,u,i):[],...(ls(d)||[]).flatMap(a=>Te(a,u,i)),...d.declaration?Te(d.declaration,u,i):[],...d.parent?Te(d.parent,u,i):[]]}function Kn(){const d=new Set;return QG.flatMap(i=>Te(i,d)).map(i=>i.id)}function Te(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(!d)throw new Error("Entity must be defined to be flattened");if(d.type===p.GenericReference)return[];if(i.ignoreBuiltInBaseEntities&&(vn.includes(d.type)||Kn().includes(d.id)))return[];if(u.has(d.id))return[];switch(d.type){case p.FunctionCall:return VH(d,u,i);case p.Operation:return GH(d,u,i);case p.Condition:return DH(d,u,i);case p.Loop:return jH(d,u,i);case p.Search:return WH(d,u,i);case p.GlobalEvent:return LH(d,u,i);case p.ReturnStatement:return ZH(d,u,i);case p.ContinueStatement:return OH(d,u,i);case p.BreakStatement:return gH(d,u,i);case p.VariableDeclaration:return JH(d,u,i);case p.DefinitionEntity:return PH(d,u,i);case p.FunctionDeclaration:return NH(d,u,i);case p.Project:return KH(d,u,i);case p.ActionDescriptor:return RH(d,u,i);case p.ArgumentDeclaration:return CH(d,u,i);case p.ValueDescriptor:return HH(d,u,i);case p.InputMap:return BH(d,u,i);case p.OutputMap:return kH(d,u,i);case p.DataType:return $H(d,u,i);case p.InstalledProject:return MH(d,u,i);case p.InternalCall:return xH(d,u,i);case p.LiteralValue:return UH(d,u,i);case p.Property:return qH(d,u,i);case p.VariableInstance:return zH(d,u,i);case p.BuiltInBaseEntity:return i.ignoreBuiltInBaseEntities?[]:_H(d,u,i);case p.PrimitiveEntity:return i.ignoreBuiltInBaseEntities?[]:FH(d,u,i)}return[]}function qw(d){return d.type===p.FunctionCall||d.type===p.InternalCall||[p.Operation,p.Condition,p.Loop].includes(d.type)?d.declaration.inputs:d.type===p.FunctionDeclaration||ko.includes(d.type)?d.inputs:d.type===p.Search?d.inputsDeclarations:[]}function rVe(d,u){return u.type===p.Condition?u.inputs.find(i=>i.declaration.id===d.id):u.type===p.FunctionCall||u.type===p.Operation?u.inputs.find(i=>i.declaration.id===d.id):null}function SH(d){return mi.includes(d.type)?d.inputs:[]}function nVe(d){var u;if(d.type===p.FunctionCall)return d.declaration.implements&&d.declaration.implements.dataType&&d.declaration.implements.dataType.entity&&d.declaration.implements.dataType.entity.type===p.DefinitionEntity&&d.declaration.implements.dataType.entity.properties.length?d.declaration.implements.dataType.entity.properties:((u=d.declaration.returnStatements[0])==null?void 0:u.outputs.map(i=>i.declaration).filter(i=>!!i))||[];if([p.Operation,p.Condition,p.Loop].includes(d.type)){const i=d.declaration;return i.dataType&&i.dataType.entity&&i.dataType.entity.type===p.DefinitionEntity&&i.dataType.entity.properties.length?i.dataType.entity.properties:[]}return Gt.includes(d.type)?d.outputs.map(i=>i.declaration).filter(i=>!!i)||[]:[]}function sVe(d,u){return u.type===p.Condition?null:(u.type===p.FunctionCall||u.type===p.Operation)&&u.outputs.find(i=>{var a;return((a=i.declaration)==null?void 0:a.id)===d.id})||null}function aVe(d){return d.type===p.Condition?[]:mi.includes(d.type)?d.outputs:[]}function q0(d){const u=d.readsValue;return u?Ni(u):null}function YH(d,u){const i=d.readsValue;return i?rp(i,u):null}function XH(d){const u=d.internalCalls||[];return C(Tl(C(u.flatMap(i=>[...i.successCalls,...i.errorCalls]))))}function QH(d){const u=d.internalCalls||[];return C(C(u.flatMap(i=>[...i.successCalls,...i.errorCalls])))}function ap(d){const u=F0(d),i=[];return u.forEach(a=>{if(rc.includes(a.type))i.push(a);else if(Xn.includes(a.type)){const l=Ni(a.parent);i.push(l)}}),i}function lp(d){const u=F0(d),i=[];return u.forEach(a=>{if($t.includes(a.type))i.push(a);else if(Xn.includes(a.type)){const l=a.parent;i.push(l)}}),i}function C(d){const u=new Set;return d.filter(i=>!i||u.has(i.id)?!1:(u.add(i.id),!0))}function eJ(d){return d.type===p.Project?null:zT.includes(d.type)?d:vn.includes(d.type)?null:d.parent?eJ(d.parent):null}function ta(d,u=!1){J.log("[getRelatedCanvasElementsOnTheRight]",d.type,S(d,d.project),d.id);const i=[];if(d.type===p.Project&&i.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)||[]),Xi.includes(d.type)&&i.push(...(d==null?void 0:d.detachedChildren)||[]),d.type===p.DefinitionEntity){const a=[...d.suggestedMethods,...d.methods].flatMap(l=>l.collapsed&&u?[]:(J.log("[Recursive -- getRelatedCanvasElementsOnTheRight]",l.type,S(l,l.project),l.id),ta(l,u)));i.push(...a)}if(d.type===p.Condition){const a=d.successCalls.map(f=>Ni(f)),l=d.errorCalls.map(f=>Ni(f));i.push(...a,...l)}if(ko.includes(d.type)){if(d.collapsed&&u)return[];const a=d.inputs.map(f=>ap(f)).flat(),l=d.calls.map(f=>Ni(f));i.push(...C(a),...l)}if(mi.includes(d.type)&&d.type!==p.Condition&&d.type!==p.Loop){const a=d==null?void 0:d.outputs.map(e=>ap(e)).flat(),l=d.successCalls.map(e=>Ni(e)),f=d.errorCalls.map(e=>Ni(e));i.push(...C(a),...l,...f)}if($t.includes(d.type)){const a=ap(d),l=XH(d);i.push(...a,...l)}if(Qi.includes(d.type)){const a=ap(d);i.push(...a)}if(d.type===p.Loop){if(d.body){const f=ta(d.body,u);i.push(...f)}const a=d.errorCalls.map(f=>Ni(f)),l=d.successCalls.map(f=>Ni(f));i.push(...l,...a)}if(d.type===p.FunctionDeclaration){if(d.collapsed&&u)return[];const a=d.inputs.map(f=>ap(f)).flat(),l=d.calls.map(f=>Ni(f));i.push(...C(a),...l)}return C(i)}function Z0(d,u=!1){const i=[];if(d.type===p.Project&&i.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)||[]),Xi.includes(d.type)&&i.push(...(d==null?void 0:d.detachedChildren)||[]),d.type===p.DefinitionEntity){const a=[...d.suggestedMethods,...d.methods].flatMap(l=>l.collapsed&&u?[]:Z0(l));i.push(...a)}if(d.type===p.Condition){const a=d.successCalls,l=d.errorCalls;i.push(...a,...l)}if(ko.includes(d.type)){if(d.collapsed&&u)return[];const a=d.inputs.map(f=>lp(f)).flat(),l=d.calls;i.push(...C(a),...l)}if(mi.includes(d.type)&&d.type!==p.Condition&&d.type!==p.Loop){const a=d==null?void 0:d.outputs.map(e=>lp(e)).flat(),l=d.successCalls,f=d.errorCalls;i.push(...C(a),...l,...f)}if($t.includes(d.type)){const a=lp(d),l=QH(d);i.push(...a,...l)}if(d.type===p.Loop){const a=d.outputs.map(e=>lp(e)).flat();if(d.body){const e=Z0(d.body,u);i.push(...e)}const l=d.errorCalls,f=d.successCalls;i.push(...C(a),...f,...l)}if(d.type===p.FunctionDeclaration){if(d.collapsed&&u)return[];const a=d.inputs.map(f=>lp(f)).flat(),l=d.calls;i.push(...C(a),...l)}return C(i)}function W0(d,u=!1){const i=ta(d,u),a=[...i,...i.reduce((l,f)=>[...l,...W0(f,u)],[])];return C(a)}function tJ(d,u=!1){const i=Z0(d,u),a=[...i,...i.reduce((l,f)=>[...l,...tJ(f,u)],[])];return C(a)}function dy(d){if(!d)throw new Error("[flattenDefinitionEntityImplementionTypes] Entity must be defined to flatten implementation types");return d.implements.reduce((u,i)=>i.type===p.DefinitionEntity?[...u,p.DefinitionEntity,...dy(i),...Ao(i)]:(i==null?void 0:i.type)===p.BuiltInBaseEntity?[i==null?void 0:i.name,...Ao(i)]:[...u],[])}function Ao(d){var u;if(!d)throw new Error("[flattenDefinitionEntityExtensionTypes] Entity must be defined to flatten extension types");if(d.extends){if(((u=d.extends)==null?void 0:u.type)===p.DefinitionEntity)return[p.DefinitionEntity,...Ao(d.extends),...dy(d.extends)];if(d.extends.type===p.BuiltInBaseEntity)return[d.extends.name,...Ao(d.extends)]}return[]}function uy(d){var u,i;return d.extends?((u=d.extends)==null?void 0:u.type)===p.DefinitionEntity?[d.extends,...uy(d.extends),...Zw(d.extends)]:((i=d.extends)==null?void 0:i.type)===p.BuiltInBaseEntity?[d.extends,...uy(d.extends)]:[]:[]}function Zw(d){return d.implements.reduce((u,i)=>i.type===p.DefinitionEntity?[...u,i,...Zw(i),...uy(i)]:(i==null?void 0:i.type)===p.BuiltInBaseEntity?[i,...uy(i)]:[...u,i],[])}function op(d){return[...Ao(d),...dy(d)].filter((i,a,l)=>l.indexOf(i)===a)}function cr(d,u){if(!d)throw new Error("checkHasBaseEntity: entity is null or undefined");if(d.type!==p.DefinitionEntity&&d.type!==p.BuiltInBaseEntity)throw new Error(`checkHasBaseEntity: entity is not a '${p.DefinitionEntity}' or '${p.BuiltInBaseEntity}', got ${d.type}`);return d.type===p.BuiltInBaseEntity?!!(d.name===u||[...Ao(d)].includes(u)):!!op(d).includes(u)}function iJ(d,u){if(!d)throw new Error("getFirstBaseEntityWithOwnBase: entity is null or undefined");if(d.type!==p.DefinitionEntity&&d.type!==p.BuiltInBaseEntity)throw new Error(`getBaseEntity: entity is not a '${p.DefinitionEntity}' or '${p.BuiltInBaseEntity}', got ${d.type}`);if(d.type===p.BuiltInBaseEntity){if(cr(d,u))return d;if(d.extends&&d.extends.type!==p.PrimitiveEntity){if(cr(d.extends,u))return d.extends;if(d.extends.type===p.BuiltInBaseEntity)return El(d.extends,u)}return null}if(d.extends)return cr(d.extends,u)?d.extends:El(d.extends,u);if(d.implements.length>0){for(const i of d.implements)if(i.type===p.BuiltInBaseEntity){if(cr(i,u))return i;const a=El(i,u);if(a)return a}else if(i.type===p.DefinitionEntity){const a=El(i,u);if(a)return a}}return null}function El(d,u){if(!d)throw new Error("getBaseEntity: entity is null or undefined");if(d.type!==p.DefinitionEntity&&d.type!==p.BuiltInBaseEntity)throw new Error(`getBaseEntity: entity is not a '${p.DefinitionEntity}' or '${p.BuiltInBaseEntity}', got ${d.type}`);if(d.type===p.BuiltInBaseEntity){if(d.name===u)return d;if(d.extends){if(d.extends.name===u)return d.extends;if(d.extends.type===p.BuiltInBaseEntity)return El(d.extends,u)}return null}if(d.extends)return d.extends.name===u?d.extends:El(d.extends,u);if(d.implements.length>0){for(const i of d.implements)if(i.type===p.BuiltInBaseEntity){if(i.name===u)return i;const a=El(i,u);if(a)return a}else if(i.type===p.DefinitionEntity){const a=El(i,u);if(a)return a}}return null}function rJ(d){const u=Io(d),i=[...u,...u.reduce((a,l)=>[...a,...rJ(l)],[])];return C(i)}function Ww(d){return d.implements.length===0&&!d.extends?null:d.implements.find(a=>a.type===p.BuiltInBaseEntity&&a.name===pe.PERSISTED_ENTITY)?d:[...d.implements,...d.extends?[d.extends]:[]].reduce((a,l)=>{if(l.type===p.DefinitionEntity){const f=Ww(l);if(f)return f}return a},null)}function lVe(d){return d.extends&&d.extends.type===p.BuiltInBaseEntity?d.extends:null}function oVe(d){const u=d.implements.find(i=>i.type===p.BuiltInBaseEntity);return u&&u.type===p.BuiltInBaseEntity?u:null}function H0(d){return d.extends&&d.extends.type===p.DefinitionEntity?d.extends:null}function sn(d){const u=[...d.implements||[],...d.extends?[d.extends]:[]].reduce((i,a)=>a.type===p.BuiltInBaseEntity?[...i,a,...sn(a)]:a.type===p.DefinitionEntity?[...i,...sn(a)]:i,[]);return C(u)}function py(d){return d.type===p.PrimitiveEntity?!0:d.type===p.BuiltInBaseEntity?d.interactive:!sn(d).find(a=>!a.interactive)}function dVe(d){return d.parent===d.project&&d.project.variableDeclarations.includes(d)}function Hw(d){return d.parent!==d.project?!1:p.VariableDeclaration===d.type?d.project.variableDeclarations.includes(d):p.VariableInstance===d.type?d.project.variableInstances.includes(d):p.FunctionCall===d.type?d.project.functionCalls.includes(d):p.Condition===d.type?d.project.conditions.includes(d):p.Operation===d.type?d.project.operations.includes(d):p.Loop===d.type?d.project.loops.includes(d):p.Search===d.type?d.project.searches.includes(d):!1}function nJ(d){if([...jt,p.DefinitionEntity,p.InstalledProject,p.Project].includes(d.type)||Hw(d))return!1;const u=Io(d);return u.length===0?!0:u.some(i=>nJ(i))}function Jw(d){return[...jt,p.DefinitionEntity,p.InstalledProject,p.Project].includes(d.type)||Hw(d)?!1:Io(d).length===0}function sJ(d,u=0){if(Jw(d)){const i=Io(d);return i.length===0?d:i.map(l=>sJ(l,u+1)).reduce((l,f)=>l?f&&f.x<l.x?f:l:f,null)}return null}function aJ(d){const u=[];if(Jw(d))u.push(d);else return[];return Io(d).forEach(a=>{u.push(...aJ(a))}),u}function zw(d){return d.type===p.FunctionDeclaration&&d.parent!==d.project&&!![p.DefinitionEntity,p.Loop,p.InstalledProject].includes(d.parent.type)}function uVe(d,u){const i=new Map;return d.forEach(a=>{i.set(a.id,a)}),u.forEach(a=>{i.set(a.id,a)}),Array.from(i.values())}function dp(d){switch(d){case p.DefinitionEntity:return _s;case p.FunctionDeclaration:return pl;case p.VariableDeclaration:return lo;case p.VariableInstance:return ao;case p.FunctionCall:return Eo;case p.Operation:return Ql;case p.Condition:return ro;case p.ReturnStatement:return eo;case p.Loop:return io;case p.Search:return oo;case p.InputMap:return as;case p.OutputMap:return ea;case p.ArgumentDeclaration:return Hs;case p.Property:return os;case p.InstalledProject:return uo;case p.Project:return N;case p.DataType:return Zr;case p.GlobalEvent:return to;case p.InternalCall:return po;case p.ValueDescriptor:return yl;case p.BuiltInBaseEntity:return Da;case p.PrimitiveEntity:return Rn;case p.ActionDescriptor:return xt;case p.LiteralValue:return Or;case p.ContinueStatement:return fo;case p.BreakStatement:return co;default:return null}}function Yr(d,u,i=null){const a=d!=null&&d.parent?ee(d==null?void 0:d.parent):null;let l=a?u.get(a):null,f=i||d;if((d==null?void 0:d.id)===(u==null?void 0:u.id))return u;if(d.type===p.ReturnStatement)return Er(d,u,f);if(d.type===p.FunctionDeclaration&&(l==null?void 0:l.type)===p.Loop)return l;if(jt.includes(d.type))return d;if(d.type===p.Loop)return f.id===d.id?l:d;if(vn.includes(d.type))return null;const e=d.parent;if(!e)return null;if(e.type===p.GenericReference){const y=ee(e);if(!y)return null;const v=u.get(y);return v?Yr(v,u,f):null}else return e===u?u:Yr(e,u,f)}function Er(d,u,i=null){const a=d!=null&&d.parent?ee(d==null?void 0:d.parent):null;let l=a?u.get(a):null,f=i||d;if(d.type===p.FunctionDeclaration&&(l==null?void 0:l.type)===p.Loop)return Er(l.parent,u,f);if(jt.includes(d.type))return d;if(vn.includes(d.type))return null;const e=d.parent;if(!e)return null;if(e.type===p.GenericReference){const y=ee(e);if(!y)return null;const v=u.get(y);return v?Er(v,u,f):null}else return e===u?u:Er(e,u,f)}function up(d,u){if(vn.includes(d.type))return J.warn(`getRootEntryPointScopeOwner is \`null\` because it was called with a built-in entity type: ${d.type}`),null;if(u.getBuiltIn(d.id))return J.warn(`getRootEntryPointScopeOwner is \`null\` because it was called with a built-in entity: ${d.id}`),null;const i=mn(d.parent,u);return i?i===u?Xi.includes(d.type)?d:(J.warn(`getRootEntryPointScopeOwner is \`null\` because it was called with an entity that has the project as parent: ${d.id}`),null):i.type===p.DefinitionEntity?d:up(i,u):(J.warn(`getRootEntryPointScopeOwner is \`null\` because it was called with an entity that has no parent: ${d.id}`),null)}function J0(d,u,i){if(d===u||u===i||d===i||!d||!u)return!1;const a=Yr(u.parent,i);return a===i?!1:a===d?!0:J0(a,u,i)}var z0=(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))(z0||{});function gs(d,u,i){const a=Yr(d,i),l=Yr(u,i);if(!a)throw new Error("Could not find scope owner for the entity: "+d.id);if(!l)throw new Error("Could not find scope owner for the entity: "+u.id);if(a===l&&a.type!==p.Project)return{compatible:!0,type:"same-both-local",commonAncestorScope:a};if(a===l&&a.type===p.Project)return{compatible:!0,type:"same-both-global",commonAncestorScope:a};if(a.type===p.Project&&l.type!==p.Project)return{compatible:!1,type:"a-is-global-b-is-not",commonAncestorScope:a};if(a.type!==p.Project&&l.type===p.Project)return{compatible:!1,type:"b-is-global-a-is-not",commonAncestorScope:l};if(J0(a,l,i))return{compatible:!0,type:"b-in-a",commonAncestorScope:a};if(J0(l,a,i))return{compatible:!0,type:"a-in-b",commonAncestorScope:l};const y=Kw(a,l);return y===i?{compatible:!1,type:"parallel-in-project",commonAncestorScope:y}:y?{compatible:!1,type:"parallel-in-common-parent",commonAncestorScope:Yr(y,i)}:{compatible:!1,type:"parallel-in-project",commonAncestorScope:i}}function lJ(d,u,i){const a=gs(d,u,i);if(!a.compatible||a.type!=="same-both-local")return null;if(d===u)return d;let l=Yr(d.parent,i);if(l){if(l===u)return u;if(l.type===p.Project)return d}else return d;for(;l;){if(l){if(l===u)return u;if(l.type===p.Project)return d}else return d;l=Yr(l.parent,i)}let f=Yr(u.parent,i);if(f){if(f===d)return d;if(f.type===p.Project)return u}else return u;for(;f;){if(f){if(f===d)return d;if(f.type===p.Project)return u}else return u;f=Yr(f.parent,i)}return null}function oJ(d){return d.length===0?null:d.length===1?d[0]:d.reduce((i,a)=>{const l=lJ(i,a,a.project);return!l||l===a?i:a},d[0])}function mn(d,u){if(!d)return null;let i;return typeof d=="string"?i=d:d.type===p.GenericReference?i=ee(d):i=d.id,i===u.id?u:u.get(i)}function wo(d){if(!d)return null;if(vn.includes(d.type))return d;if(d.type===p.Project)return null;if(d.project.getBuiltIn(d.id))return d;const u=d.parent;return!u||u.type===p.Project?null:wo(u)}function cy(d){const u=[];function i(f,e){return u.some(y=>y.blockedByCaller===f&&y.blockedByCalling===e)}function a(f,e){i(f,e)||u.push({blockedByCaller:f,blockedByCalling:e})}const l=up(d,d.project);return l?(d.calledBySuccess.forEach(f=>{[...f.successCalls||[]].forEach(v=>{Gt.includes(v.type)&&v.id!==d.id&&(ht(d).find(b=>b===v)||a(f,v))});let y;if(mi.includes(f.type)&&(y=f),y){const v=cy(y);v.reachable||ht(d).find(b=>b===f)||v.blocks.forEach(b=>{a(f,b.blockedByCalling)})}}),d.calledByError.forEach(f=>{[...f.errorCalls||[]].forEach(v=>{Gt.includes(v.type)&&v!==d&&(ht(d).find(b=>b===v)||a(f,v))});let y;if(mi.includes(f.type)&&(y=f),y){const v=cy(y);v.reachable||ht(d).find(b=>b===f)||v.blocks.forEach(b=>{a(f,b.blockedByCalling)})}}),d.calledByEntry.forEach(f=>{if([...f.calls||[]].forEach(v=>{Gt.includes(v.type)&&v!==d&&(ht(d).find(b=>b===v)||a(f,v))}),f===l)return;let y;if(f.type===p.FunctionDeclaration){const v=Ni(f);if(v.type===p.DefinitionEntity)return;v.type===p.Loop&&(y=v)}if(y){const v=cy(y);v.reachable||v.blocks.forEach(T=>{a(f,T.blockedByCalling)})}}),{reachable:u.length===0,entryPoint:l,blocks:u}):{reachable:!0,entryPoint:null,blocks:[]}}function pVe(d){return rc.includes(d.type)?d.type===p.FunctionDeclaration?!zw(d):!0:!1}function cVe(d){if(p.ActionDescriptor===d.type){if(d.project.operationDeclarations.find(f=>f.id===d.id))return p.Operation;if(d.project.globalEventActionDescriptors.find(f=>f.id===d.id))return p.GlobalEvent;if(d.project.loopDeclarations.find(f=>f.id===d.id))return p.Loop;if(d.project.conditionDeclarations.find(f=>f.id===d.id))return p.Condition}return d.type}function S0(d,u){return d.type===p.BuiltInBaseEntity?d.name===u:!!Ao(d).includes(u)}function fVe(d,u){return d.type===p.BuiltInBaseEntity?d.name===u:!!dy(d).includes(u)}function yVe(d){const u=[];return d.entities.forEach(i=>{if(S0(i,pe.PERSISTED_ENTITY)){u.push(i);return}}),C(u)}function hVe(d){const u=[];return d.entities.forEach(i=>{if(S0(i,pe.RELATIONAL_DATABASE)){u.push(i);return}}),C(u)}function mVe(d){return d.type!==p.DefinitionEntity||d.abstract||!S0(d,pe.PERSISTED_ENTITY)?null:(d==null?void 0:d.properties.find(i=>i.implements.find(a=>a.id===ce[p.BuiltInBaseEntity][pe.PERSISTED_ENTITY].properties.primaryKey.id)&&!i.abstract))||null}function dJ(d){var a;const u=Ww(d);if(!u)return null;const i=u.properties.find(l=>l.implements.find(f=>f.id===ce[p.BuiltInBaseEntity][pe.PERSISTED_ENTITY].properties.database.id));return i?(a=i.getDefaultValue())==null?void 0:a.valueAsType:null}function pp(d){if(d.type!==p.DefinitionEntity)return[];if(d.abstract)return[];if(!cr(d,pe.PERSISTED_ENTITY))return[];const u=[],i=d.properties.filter(a=>!a.implements.find(l=>l.id===ce[p.BuiltInBaseEntity][pe.PERSISTED_ENTITY].properties.database.id)&&!a.abstract);return u.push(...i),u}function vVe(d){var i;if(!d||d.type!==p.DefinitionEntity||!cr(d,pe.PERSISTED_ENTITY))return null;const u=d.properties.find(a=>!!a.implements.find(l=>l.id===ce[p.BuiltInBaseEntity][pe.PERSISTED_ENTITY].properties.database.id));return(i=u==null?void 0:u.getDefaultValue())==null?void 0:i.valueAsTypeSingle}function fr(d,u){var a;if(!$g.includes(u.type)||!d)return u.project||null;let i=u.project;return d.type===p.Project?i=d:((a=u.project)==null?void 0:a.id)!==d.project.id&&(i=d.project),i}function TVe(d){switch(d){case p.Project:return N;case p.InstalledProject:return uo;case p.DefinitionEntity:return _s;case p.FunctionDeclaration:return pl;case p.GlobalEvent:return to;case p.VariableInstance:return ao;case p.VariableDeclaration:return lo;case p.InputMap:return as;case p.OutputMap:return ea;case p.Condition:return ro;case p.Operation:return Ql;case p.FunctionCall:return Eo;case p.ArgumentDeclaration:return Hs;case p.PrimitiveEntity:return Rn;case p.DataType:return Zr;case p.Property:return os;case p.ActionDescriptor:return xt;case p.ReturnStatement:return eo;case p.ContinueStatement:return fo;case p.BreakStatement:return co;case p.Loop:return io;case p.Search:return oo;case p.ValueDescriptor:return yl;case p.InternalCall:return po;case p.LiteralValue:return Or}return null}function EVe(d){const u={added:{},updated:{},removed:{},affected:[],seenEntities:[],self:d==null?void 0:d.self};return d==null||d.added.forEach(i=>{u.added[i.id]=i}),d==null||d.updated.forEach(i=>{u.updated[i.id]=i}),d==null||d.removed.forEach(i=>{u.removed[i.id]=i}),u.affected=Array.from(new Set(d==null?void 0:d.affected.map(i=>i.id))),u}function rr(d,u){const i=dp(d.type);return i?!i.MUTABLE_META_PROPERTIES.every(l=>{const f=d[l],e=u[l];return e===void 0||f===e?!0:Array.isArray(f)&&Array.isArray(e)?f.length!==e.length?!1:f.every((y,v)=>y===e[v]):!1}):!1}function nr(d,u){let i={...u};if(!d.checkCanEdit(d)){const a=dp(d.type);if(!a)return i;a.MUTABLE_META_PROPERTIES.forEach(l=>{["x","y","collapsed"].includes(l)||delete i[l]})}return i}function Y0(d,u={}){if(d.type===p.Project)return[];if(!d.parent)return[];const i=ee(d.parent);if(!i)return[];const a=u[i];return a?[a.id,...Y0(a,u)]:[]}function bVe(d){const u=[],i=new Set;return[...d.listAdded,...d.listUpdated,...d.listAffected].forEach(a=>{const l=Ni(a);if(!l||i.has(l.id))return;const f=d.project.get(a.id);if(!f)throw new Error(`Could not find active version of entity ${a.id} in project, which is present in the change set.`);i.add(l.id),u.push(f)}),C(u)}function IVe(d){if(d.type===p.Condition)return null;if(d.type===p.Search)return d.project.getBuiltIn(ce["value-descriptor"][ch.SearchErrorOutputDescriptor].id)||null;if(d.type===p.Operation)return d.declaration.error;if(d.type===p.FunctionCall){const i=d.declaration.returnStatements.find(a=>!!a.throws);return(i==null?void 0:i.throws)||null}return null}function uJ(d){const u=d.entities.filter(l=>!!l.implements.find(f=>f.id===ce["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.id)),i=u.find(l=>{const f=l.properties.find(v=>v.implements.find(T=>T.id===ce["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.default.id)),e=f==null?void 0:f.getDefaultValue();return(e==null?void 0:e.value)===!0});return i||u[0]||null}function Sw(d,u){const i=Array.from(new Set([...u.getAllBuiltInIds(),...Kn()]));return!!(i.includes(d.id)||!Y0(d,{...u.instances,...u.builtInInstances}).every(f=>!i.includes(f)))}function pJ(d){if(!d)return null;if(d.type===p.Project)return d.id;const u=d.parent;return u?pJ(u):d.id}function fy(d){if(d.declaration&&d.declaration.type===p.Property){if(d.declaration.interactive)if(d.declaration.implements.every(u=>u.interactive)){if(d.declaration.extends&&!d.declaration.extends.interactive)return!1}else return!1;else return!1;if(d.declaration.private){const u=Ni(d),i=up(u,d.project);if((i==null?void 0:i.type)===p.FunctionDeclaration&&(i==null?void 0:i.parent.type)===p.DefinitionEntity&&(i==null?void 0:i.parent.id)!==d.declaration.parent.id)return!1}}return!0}function Yw(d){if(d.interactive)if(d.implements.every(u=>u.interactive)){if(d.extends&&!d.extends.interactive)return!1}else return!1;else return!1;if(d.private){const u=Ni(d),i=up(u,d.project);if((i==null?void 0:i.type)===p.FunctionDeclaration&&(i==null?void 0:i.parent.type)===p.DefinitionEntity&&(i==null?void 0:i.parent.id)!==d.parent.id)return!1}return!0}function AVe(d,u,i){const a=u,l=i,f=!!i,e=[];return a.forEach(y=>{var v;if(f){const T=gs(l,y,d);if(!T.compatible&&T.type!=="b-is-global-a-is-not")return;e.push(y)}else{if(((v=y.parent)==null?void 0:v.type)!==p.Project)return;e.push(y)}}),C(e)}function Xw(d,u){var i,a,l,f;if(!d||!u)return null;if(d.id===u.id)return d;if(d.type===p.FunctionDeclaration){if(((i=d.implements)==null?void 0:i.id)===u.id)return d;if(((a=d.extends)==null?void 0:a.id)===u.id)return d;if(d.extends){const e=Xw(d.extends,u);if(e)return e}}if(u.type===p.FunctionDeclaration){if(((l=u.implements)==null?void 0:l.id)===d.id)return u;if(((f=u.extends)==null?void 0:f.id)===d.id)return u;if(u.extends){const e=Xw(u.extends,d);if(e)return e}}return null}function gd(d){if(d.type!==p.FunctionDeclaration&&d.type!==p.ActionDescriptor)throw new Error(`Entity is not a FunctionDeclaration or ActionDescriptor: ${d.type}`);if(d.type===p.FunctionDeclaration){if(d.implements)return gd(d.implements);if(d.extends)return gd(d.extends)}return d}function bl(d){var u;return!!(d.required||(u=d.declaration)!=null&&u.required)}function Ro(d){return r6(d)||d===void 0||d===""}function _a(d){return d?d.valueAsType?!1:Ro(d.value):!0}function yy(d){return d.replace(/["'`]/g,"")}function Bi(d){const i=yy(d).split(/[\s-]+/).filter(e=>e.length>0);if(i.length===0)return"";const a=i[0],l=a[0].toLowerCase()+a.slice(1),f=i.slice(1).map(e=>e[0].toUpperCase()+e.slice(1));return[l,...f].join("")}function _d(d){return yy(d).split(/[\s-]+/).filter(a=>a.length>0).map(a=>a[0].toUpperCase()+a.slice(1)).join("")}function cJ(d){const u=yy(d).trim();if(!u)return"";const i=u.replace(/[\s_-]+/g," ").split(" ").filter(Boolean),a=[];for(const l of i){let f=l;f=f.replace(/([A-Z]+)([A-Z][a-z]+)/g,"$1-$2"),f=f.replace(/([a-z0-9])([A-Z][a-z0-9]*)/g,"$1-$2"),f=f.replace(/([0-9])([a-zA-Z]+)/g,"$1-$2"),f=f.replace(/([a-zA-Z])([0-9])/g,"$1-$2");for(const e of f.split("-"))e&&a.push(e)}return a.join("-")}function wVe(d){const u=yy(d).trim();if(!u)return"";const i=u.replace(/[\s_-]+/g," ").split(" ").filter(Boolean),a=[];for(const l of i){let f=l;f=f.replace(/([A-Z]+)([A-Z][a-z]+)/g,"$1_$2"),f=f.replace(/([a-z0-9])([A-Z][a-z0-9]*)/g,"$1_$2"),f=f.replace(/([0-9])([a-zA-Z]+)/g,"$1_$2"),f=f.replace(/([a-zA-Z])([0-9])/g,"$1_$2");for(const e of f.split("_"))e&&a.push(e)}return a.join("_")}function X0(d){return cJ(d).toLowerCase()}function Qw(d){const u=yy(d).trim();if(!u)return"";let i=u.replace(/([A-Z]+)([A-Z][a-z]+)/g,"$1 $2").replace(/([a-z0-9])([A-Z][a-z0-9]*)/g,"$1 $2").replace(/[_-]+/g," ").replace(/\s+/g," ").trim();return i.charAt(0).toUpperCase()+i.slice(1)}function cp(d){var i,a,l,f;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&&!((i=d.andChildrenGroup)!=null&&i.length)&&!((a=d.orChildrenGroup)!=null&&a.length)&&(u=" as template"),!d.entity){const e=d.isList;if(!((l=d.andChildrenGroup)!=null&&l.length)&&!((f=d.orChildrenGroup)!=null&&f.length))return e?`List of an any data type${u}`:`Any data type${u}`;let y="",v=!1,T=!1;return(d.andChildrenGroup||[]).forEach(A=>{const b=cp(A),O=Nu(b);v&&(y+=" and "),A.isGroup?y+="("+O+")":v?y+=O:y+=b,v=!0,T=!0}),(d.orChildrenGroup||[]).forEach(A=>{const b=cp(A),O=Nu(b);v&&(T&&(y+=","),y+=" or "),A.isGroup?y+="("+O+")":v?y+=O:y+=b,v=!0}),e?`List of ${Nu(y)}`:y}if(d.entity.type===p.PrimitiveEntity){let e=d.entity.name;switch(d.entity.name){case re.String:e="Text";break;case re.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===p.DefinitionEntity){const e=S(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===p.BuiltInBaseEntity){const e=yJ(d.entity);return d.isList?`List of ${e} values${u}`:e.slice(0,1).toUpperCase()+e.slice(1)+u}else if(d.entity.type===p.LiteralValue){if(d.entity.name===re.Null)return"Empty value";if(d.entity.name===re.Untyped)return"Untyped value";if(d.entity.name===re.File)return"File";if(d.entity.name===re.String)return`"${d.entity.value}" text`;if(d.entity.name===re.Number)return`Number '${d.entity.value}'`;if(d.entity.name===re.Boolean)return`${d.entity.value} value`;if(d.entity.name===re.UUID)return`"${d.entity.value}" unique identifier`;if(d.entity.name===re.Date)return`"${d.entity.value}" date`}return d.isList?`List of ${S(d.entity,d.project)} values${u}`:`${S(d.entity,d.project).slice(0,1).toUpperCase()+S(d.entity,d.project).slice(1)} value${u}`}function RVe(d){if(!d)return"Any data type";const u=d.getDataType(null);return cp(u)}function Q0(d){switch(d.declaration.id){case pt.Equal:return"is equal to";case pt.NotEqual:return"is not equal to";case pt.MoreThan:return"is greater than";case pt.MoreThanOrEqual:return"is greater than or equal to";case pt.LessThan:return"is less than";case pt.LessThanOrEqual:return"is less than or equal to";case Zi.And:return"and";case Zi.Or:return"or";case Ir.Empty:return"is empty";case Ir.NotEmpty:return"is present"}}function fJ(d){if(d.includes(pe.HTTP_ENDPOINT))return"HTTP endpoint";if(d.includes(pe.PERSISTED_ENTITY))return"Persisted entity";if(d.includes(pe.CRON_JOB))return"Scheduled execution";if(d.includes(pe.RELATIONAL_DATABASE))return"Relational database";if(d.includes(pe.GOOGLE_AUTH_CONNECTION))return"Google account connection";if(d.includes(pe.SLACK_AUTH_CONNECTION))return"Slack account connection";if(d.includes(pe.AIRTABLE_AUTH_CONNECTION))return"Airtable account connection";if(d.includes(pe.MICROSOFT_AUTH_CONNECTION))return"Microsoft account connection";if(d.includes(pe.OPENAI_AUTH_CONNECTION))return"OpenAI account connection";if(d.includes(pe.ATLASSIAN_AUTH_CONNECTION))return"Atlassian account connection";if(d.includes(pe.JIRA_AUTH_CONNECTION))return"Jira account connection";if(d.includes(pe.GOOGLE_DRIVE_AUTH_CONNECTION))return"Google Drive account connection";if(d.includes(pe.GOOGLE_MAIL_AUTH_CONNECTION))return"Gmail account connection";if(d.includes(pe.GOOGLE_SHEET_AUTH_CONNECTION))return"Google Sheet account connection";if(d.includes(pe.GOOGLE_SLIDES_AUTH_CONNECTION))return"Google Slides account connection";if(d.includes(pe.GOOGLE_GEMINI_AUTH_CONNECTION))return"Google Gemini account connection";if(d.includes(pe.EXTERNAL_INTEGRATION_CONNECTION))return"External integration connection";try{return Qw(d[0])}catch(u){return console.error("Error resolving base entity name for base entities:",d,u),"Built-in base entity"}}function yJ(d){switch(d.name){case pe.HTTP_ENDPOINT:return"HTTP endpoint";case pe.PERSISTED_ENTITY:return"Persisted entity";case pe.CRON_JOB:return"Scheduled execution";case pe.RELATIONAL_DATABASE:return"Relational database";case pe.GOOGLE_AUTH_CONNECTION:return"Google account connection";case pe.SLACK_AUTH_CONNECTION:return"Slack account connection";case pe.AIRTABLE_AUTH_CONNECTION:return"Airtable account connection";case pe.MICROSOFT_AUTH_CONNECTION:return"Microsoft account connection";case pe.OPENAI_AUTH_CONNECTION:return"OpenAI account connection";case pe.ATLASSIAN_AUTH_CONNECTION:return"Atlassian account connection";case pe.JIRA_AUTH_CONNECTION:return"Jira account connection";case pe.GOOGLE_DRIVE_AUTH_CONNECTION:return"Google Drive account connection";case pe.GOOGLE_MAIL_AUTH_CONNECTION:return"Gmail account connection";case pe.GOOGLE_SHEET_AUTH_CONNECTION:return"Google Sheet account connection";case pe.GOOGLE_SLIDES_AUTH_CONNECTION:return"Google Slides account connection";case pe.GOOGLE_GEMINI_AUTH_CONNECTION:return"Google Gemini account connection";case pe.EXTERNAL_INTEGRATION_CONNECTION:return"External integration connection";case pe.EXTERNAL_INTEGRATION_CONNECTION:return"External integration connection"}try{return Qw(d.name)}catch(u){return console.error("Error resolving built-in base entity data type label for entity:",d,u),"Built-in base entity"}}function CVe(d){const u=H0(d);if(!u){const i=op(d);return i.includes(pe.HTTP_ENDPOINT)?"HTTP endpoint":i.includes(pe.PERSISTED_ENTITY)?"Persisted entity":i.includes(pe.CRON_JOB)?"Scheduled execution":i.includes(pe.RELATIONAL_DATABASE)?"Relational database":i.includes(pe.GOOGLE_AUTH_CONNECTION)?"Google account connection":i.includes(pe.SLACK_AUTH_CONNECTION)?"Slack account connection":i.includes(pe.AIRTABLE_AUTH_CONNECTION)?"Airtable account connection":i.includes(pe.MICROSOFT_AUTH_CONNECTION)?"Microsoft account connection":i.includes(pe.OPENAI_AUTH_CONNECTION)?"OpenAI account connection":i.includes(pe.ATLASSIAN_AUTH_CONNECTION)?"Atlassian account connection":i.includes(pe.JIRA_AUTH_CONNECTION)?"Jira account connection":i.includes(pe.EXTERNAL_INTEGRATION_CONNECTION)?"External integration connection":S(d,d.project)+" entity"}return S(u,d.project)+" entity"}function hJ(d){let u="Find ";return d.outputs.forEach((i,a)=>{const l=p0(i,null),f=Nu(l&&l.entity?S(l.entity,d.project):"unstructured data");a===0?u+=`${f} `:a===d.outputs.length-1?u+=`and ${f} `:u+=`, ${f} `}),u}function mJ(d){switch(d.name){case re.String:return"Text";case re.Number:return"Number";case re.Boolean:return"Boolean";case re.KeyValue:return"Data structure";case re.UUID:return"Unique identifier";case re.Date:return"Date";case re.EntityTemplate:return"Entity as template";case re.Enum:return"Enumeration";case re.File:return"File";case re.Null:return"Empty";case re.ActionDescriptor:return"Action descriptor";case re.Untyped:return"Untyped";default:return d.name}}function vJ(d){switch(d.id){case We.List:return"Loop over list items";case We.ManualFlow:return"Manual flow control loop";case We.ObjectKeys:return"Loop over object keys";case We.ObjectValues:return"Loop over object values";case We.Counted:return"Loop given number of times";case We.String:return"Loop over text characters";case Pi.Addition:return"Sum numbers";case Pi.Subtraction:return"Subtract numbers";case Pi.Multiplication:return"Multiply numbers";case Pi.Division:return"Divide numbers";case Pi.Remainder:return"Get remainder of numbers";case Pi.Exponentiation:return"Get exponent of numbers";case ze.AddIndex:return"Add at index position";case ze.DeleteFirst:return"Delete first character";case ze.DeleteLast:return"Delete last character";case ze.DeleteIndex:return"Delete at index position";case ze.Join:return"Join texts";case ze.ReplaceAllMatches:return"Replace all matches";case ze.ReplaceFirst:return"Replace first match";case ze.ReplaceLast:return"Replace last match";case ze.Split:return"Split text";case ze.ReplaceIndex:return"Replace at index position";case ze.ReplaceSingleMatch:return"Replace single match";case ze.GetFirst:return"Get first character";case ze.GetLast:return"Get last character";case ze.GetIndexItem:return"Get at index position";case ze.GetIndexOf:return"Get the index number of the character";case ze.Append:return"Add at the end";case ze.Prepend:return"Add at the start";case Ei.Wait:return"Wait";case Ei.Parallel:return"Run in parallel";case Ei.Sequential:return"Run in sequence";case pn.HttpRequest:return"HTTP request";case ut.AddIndex:return"Add item at index position";case ut.DeleteFirst:return"Delete first item";case ut.DeleteLast:return"Delete last item";case ut.DeleteIndex:return"Delete item at index position";case ut.Join:return"Join lists";case ut.ReplaceFirst:return"Replace first match";case ut.ReplaceLast:return"Replace last match";case ut.Split:return"Split list";case ut.ReplaceIndex:return"Replace at index position";case ut.GetFirst:return"Get first item";case ut.GetLast:return"Get last item";case ut.GetIndexItem:return"Get item at index position";case ut.Append:return"Add item at the end";case ut.Prepend:return"Add item at the start";case Us.PROJECT_PUBLICATION_COMPLETED:return"Project publication completed";default:return(d.name.slice(0,1).toUpperCase()+d.name.slice(1)).replaceAll("-"," ")}}function S(d,u){var i;if(p.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 dr(d.type).replaceAll("-"," ")}return a}if(p.BuiltInBaseEntity===d.type)return fJ([d.name]);if(Og.includes(d.type)&&d.type!==p.ActionDescriptor)return d.name;switch(d.type){case p.Search:return hJ(d);case p.GlobalEvent:return d.implements?S(d.implements,u):dr(d.type).replaceAll("-"," ");case p.Operation:case p.InternalCall:case p.Loop:const a=mn(d.declaration,u);return S(a,u);case p.ActionDescriptor:return vJ(d);case p.BreakStatement:const l=mn(d.parent,u);return`Stop loop ${S(l,u)}`;case p.ContinueStatement:const f=mn(d.parent,u);return`Execute next iteration of ${S(f,u)}`;case p.FunctionCall:return mn(d.declaration,u).name;case p.Condition:{const y=d;if(y.declaration.id===Zi.And)return"If all conditions are met";if(y.declaration.id===Zi.Or)return"If any condition is met";if((i=d.inputs)!=null&&i.length){const v=S(y.inputs[0],y.project);if(y.inputs[1]){const T=y.inputs[1].declaration.name;return`If ${v} ${Q0(y)} ${T}`}return`If ${v} ${Q0(y)}`}else return`If ${Q0(y)}`}case p.ReturnStatement:{const y=mn(d.parent,u);return y?`Output of ${S(y,u)}`:"Return statement"}case p.InputMap:if(d.declaration){const y=mn(d.declaration,u);return S(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 p.VariableInstance:{const y=mn(d.declaration,u);return S(y,u)||""}case p.OutputMap:if(d.declaration){const y=mn(d.declaration,u);return(y==null?void 0:y.name)||""}else return d.parentRelationType===_l.Error?"Undeclared error":"";case p.PrimitiveEntity:case p.LiteralValue:return mJ(d);default:return dr(d.type).replaceAll("-"," ")}}function eR(d,u){const i=[];d.name||i.push(new ue({id:`${d.id}--${de.EmptyName}`,message:`Entity with id "${d.id}" and type "${d.type}" has an empty name. Please provide a 'name' string.`,severity:Q.Error,code:de.EmptyName}));const a=u.entities.filter(l=>l.name===d.name);return a.length&&i.push(new ue({id:`${d.id}--${de.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.
387
+ 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:i}}subscribeDependents(i){return i.forEach(a=>{this.detachedDependents[a.entity.id]||(this.detachedDependents[a.entity.id]=a)}),this}unsubscribeDependents(i){return i.forEach(a=>{this.detachedDependents[a.entity.id]&&delete this.detachedDependents[a.entity.id]}),this}syncDependents(i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,B().toISOString(),this,!0,"sync-dependents"))){const a=[],l=[],f=[],e=[];return Object.values(this.detachedDependents).forEach(y=>{const v=y.entity.afterAllChildrenInitialized(i);a.push(...v.updated),l.push(...v.added),f.push(...v.removed),e.push(...v.affected)}),i==null||i.attemptAutoclose("sync-dependents",this.id),{updated:C(a),added:C(l),removed:C(f),affected:C(e),self:this}}onDetachedDependencyRemoved(i,a,l){const f=[],e=[],y=[],v=[];if(a==="function-call-declaration-field"){const{updated:T,added:A,removed:b}=this.remove({ignoreUpstream:!1},l);f.push(...T),e.push(...A),y.push(...b)}if(a==="function-call-parent-field"){const{updated:T,added:A,removed:b}=this.remove({ignoreUpstream:!1},l);f.push(...T),e.push(...A),y.push(...b)}return{updated:C(f),added:C(e),removed:C(y),affected:C(v),self:this}}onDetachedDependencyRestored(i,a,l){const f=[],e=[],y=[],v=[];if(a==="function-call-declaration-field"){const{updated:T,added:A,removed:b}=this.restore({},l);f.push(...T),e.push(...A),y.push(...b)}if(a==="function-call-parent-field"){const{updated:T,added:A,removed:b}=this.restore({},l);f.push(...T),e.push(...A),y.push(...b)}return{updated:C(f),added:C(e),removed:C(y),affected:C(v),self:this}}unsubscribeFromDependencies(){var i;return(i=this.parent)==null||i.unsubscribeDependents([{entity:this,field:"function-call-parent-field"}]),this.declaration.unsubscribeDependents([{entity:this,field:"function-call-declaration-field"}]),this}subscribeToDependencies(){var i;return(i=this.parent)==null||i.subscribeDependents([{entity:this,field:"function-call-parent-field"}]),this.declaration.subscribeDependents([{entity:this,field:"function-call-declaration-field"}]),this}increaseVersion(i){if(i&&!B(i).isValid())throw new Error(`The shared timestamp '${i}' is not a valid ISO 8601 date string.`);return i&&B(i).isSame(B(this.createdAt))?this:(this.previousVersion=this.version,this.version=N.UUID.uuid(),this.createdAt=B(i).toISOString()||B().toISOString(),this)}captureVersion(){var a;const i=((a=this.knownVersions)==null?void 0:a.get(this.version))||new yi(this,this.project);return i.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,i):new Map([[this.version,i]]),i.inputs=[...this.inputs],i.outputs=[...this.outputs],i.error=this.error,i.successCalls=[...this.successCalls],i.errorCalls=[...this.errorCalls],i.declaration=this.declaration,i.calledBySuccess=[...this.calledBySuccess],i.calledByError=[...this.calledByError],i.calledByEntry=[...this.calledByEntry],i.parent=this.parent,this}recursiveCaptureUpstreamVersions(i){const a=[],l=[],f=[],e=[];if(this.parent){this.parent.increaseVersion(i);const y=this.parent.recursiveCaptureUpstreamVersions(i);a.push(this.parent,...y.updated),l.push(...y.added),f.push(...y.removed)}return{updated:C(a),added:C(l),removed:C(f),affected:C(e),self:this}}async restoreVersion(i){var v;const a=[],l=[],f=[],e=[];if(this.version===i)return{updated:C(a),added:C(l),removed:C(f),affected:C(e),self:this};if(!this.knownVersions){const T=new Map;for(const[A,b]of this.knownVersions||new Map){if(T.set(A,b),b.activeVersion=!1,b.knownVersions)for(const[O,L]of b.knownVersions)T.set(O,L);b.knownVersions=null}}let y=(v=this.knownVersions)==null?void 0:v.get(i);if(!y){const T=await this.APILoadVersion({},i);if(!T)throw new Error(`Version with id '${i}' for entity with id '${this.id}' not found.`);y=new yi(T,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.declaration=y.declaration,this.calledBySuccess=y.calledBySuccess,this.calledByError=y.calledByError,this.calledByEntry=y.calledByEntry,this.parent=y.parent,{updated:C(a),added:C(l),removed:C(f),affected:C(e),self:this}}updateWithShallowTransfer(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,B().toISOString(),this,!0,P.UpdateWithShallowTransfer))){if(!this.checkCanEdit(this))return J.warn(`[updateWithShallowTransfer] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),a==null||a.attemptAutoclose(P.UpdateWithShallowTransfer,this.id),this;if(this.metaSync(i,a),this.version=i.version,this.createdAt=i.createdAt,this.author=i.author,this.deleted=i.deleted,this.previousVersion=i.previousVersion,this.unsubscribeFromDependencies(),i.parent){const l=ee(i.parent),f=this.project.get(l),e=this.parent;if(e&&e.id!==(f==null?void 0:f.id)&&this.removeFromParent(a),f)this.setParent(f,a);else throw a==null||a.attemptAutoclose(P.UpdateWithShallowTransfer,this.id),new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw a==null||a.attemptAutoclose(P.UpdateWithShallowTransfer,this.id),new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(i.declaration){const l=ee(i.declaration),f=this.project.get(l);f&&this.setDeclaration(f)}return i.calledByEntry.forEach(l=>{const f=ee(l),e=this.project.get(f);e&&(this.addEntryCaller(e,a),e.addCall(this,a))}),[...this.calledByEntry].forEach(l=>{i.calledByEntry.find(e=>ee(e)===l.id)||(this.removeCaller(l,a),l.removeCall(this,a))}),i.calledBySuccess.forEach(l=>{const f=ee(l),e=this.project.get(f);e&&(this.addSuccessCaller(e,a),e.addSuccessCall(this,a))}),[...this.calledBySuccess].forEach(l=>{i.calledBySuccess.find(e=>ee(e)===l.id)||(this.removeCaller(l,a),l.removeCall(this,a))}),i.calledByError.forEach(l=>{const f=ee(l),e=this.project.get(f);e&&(this.addErrorCaller(e,a),e.addErrorCall(this,a))}),[...this.calledBySuccess].forEach(l=>{i.calledBySuccess.find(e=>ee(e)===l.id)||(this.removeCaller(l,a),l.removeCall(this,a))}),this.captureVersion(),this.subscribeToDependencies(),a==null||a.attemptAutoclose(P.UpdateWithShallowTransfer,this.id),this}hydrateAncestors(){const i=[],a=[],l=[],f=[];if(this.initialData.parent){const e=ee(this.initialData.parent),y=this.project.get(e);if(y)this.setParent(y,null),i.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=ee(this.initialData.declaration),y=this.project.get(e);y&&(this.setDeclaration(y),i.push(y))}return this.initialData.calledByEntry.forEach(e=>{const y=ee(e),v=this.project.get(y);v&&this.addEntryCaller(v,null)}),this.initialData.calledBySuccess.forEach(e=>{const y=ee(e),v=this.project.get(y);v&&this.addSuccessCaller(v,null)}),this.initialData.calledByError.forEach(e=>{const y=ee(e),v=this.project.get(y);v&&this.addErrorCaller(v,null)}),{updated:C(i),added:C(a),removed:C(l),affected:C(f),self:this}}afterAllChildrenInitialized(i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,B().toISOString(),this,!0,P.AfterAllChildrenInitialized))){if(!this.checkCanEdit(this))return J.warn(`[afterAllChildrenInitialized] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(P.AfterAllChildrenInitialized,this.id),{updated:[],added:[],removed:[],affected:[],self:this};const a=[],l=[],f=[],e=[];this.initialized=!0;const{updated:y,added:v,removed:T}=this.syncInputs(i),{updated:A,added:b,removed:O}=this.syncOutputs(i);return a.push(...y,...A),l.push(...v,...b),f.push(...T,...O),this.captureVersion(),i==null||i.attemptAutoclose(P.AfterAllChildrenInitialized,this.id),{updated:C(a),added:C(l),removed:C(f),affected:C(e),self:this}}addSelfToProject(i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,B().toISOString(),this,!0,"add-self-to-project"))){const a=[this],l=[],f=[],e=[];return this.parent===this.project&&this.project.addFunctionCall(this),this.successCalls.forEach(y=>{y.addSuccessCaller(this,i),a.push(y)}),this.errorCalls.forEach(y=>{y.addErrorCaller(this,i),a.push(y)}),this.calledBySuccess.forEach(y=>{y.addSuccessCall(this,i),a.push(y)}),this.calledByError.forEach(y=>{y.addErrorCall(this,i),a.push(y)}),this.calledByEntry.forEach(y=>{y.addCall(this,i),a.push(y)}),this.subscribe(),this.subscribeToDependencies(),i==null||i.attemptAutoclose("add-self-to-project",this.id),{updated:C(a),added:C(l),removed:C(f),affected:C(e),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}removeInput(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,B().toISOString(),this,!0,P.RemoveInput))){if(!this.checkCanEdit(this))return J.warn(`[removeInput] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),a==null||a.attemptAutoclose(P.RemoveInput,this.id),this;const l=this.inputs.findIndex(f=>f.id===i.id);return l>-1&&(this.inputs.splice(l,1),a&&(a==null||a.add(this,k.Affected))),a==null||a.attemptAutoclose(P.RemoveInput,this.id),this}addInput(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,B().toISOString(),this,!0,P.AddInput))){return this.checkCanEdit(this)?this.inputs.includes(i)?(a==null||a.attemptAutoclose(P.AddInput,this.id),this):(this.inputs.push(i),a==null||a.add(this,k.Affected),a==null||a.attemptAutoclose(P.AddInput,this.id),this):(J.warn(`[addInput] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),a==null||a.attemptAutoclose(P.AddInput,this.id),this)}addOutput(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,B().toISOString(),this,!0,"add-output"))){return this.checkCanEdit(this)?this.outputs.includes(i)?(a==null||a.attemptAutoclose("add-output",this.id),this):(this.outputs.push(i),a==null||a.add(this,k.Affected),a==null||a.attemptAutoclose("add-output",this.id),this):(J.warn(`[addOutput] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),a==null||a.attemptAutoclose("add-output",this.id),this)}removeOutput(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,B().toISOString(),this,!0,"remove-output"))){if(!this.checkCanEdit(this))return J.warn(`[removeOutput] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),a==null||a.attemptAutoclose("remove-output",this.id),this;const l=this.outputs.findIndex(f=>f.id===i.id);return l>-1&&(this.outputs.splice(l,1),a&&(a==null||a.add(this,k.Affected))),a==null||a.attemptAutoclose("remove-output",this.id),this}addValueReader(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,B().toISOString(),this,!0,P.AddValueReader))){return this.checkCanEditWithCounterpartAndSideEffects(this,i,P.AddValueReader,a)?this.writesValues.includes(i)?(a==null||a.attemptAutoclose(P.AddValueReader,this.id),this):(this.writesValues.push(i),a==null||a.add(this,k.Affected),this):this}removeValueReader(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,B().toISOString(),this,!0,P.RemoveValueReader))){return this.checkCanEditWithCounterpartAndSideEffects(this,i,P.RemoveValueReader,a)?this.writesValues.includes(i)?(this.writesValues=this.writesValues.filter(l=>l.id!==i.id),a==null||a.add(this,k.Affected),this):(a==null||a.attemptAutoclose(P.RemoveValueReader,this.id),this):this}addSuccessCaller(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,B().toISOString(),this,!0,P.AddSuccessCaller)),l=!1){return this.checkCanEditWithCounterpartAndSideEffects(this,i,P.AddSuccessCaller,a)?(this.calledBySuccess.find(f=>f.id===i.id)||(this.calledBySuccess.push(i),a==null||a.add(this,k.Updated),l&&et(this,a)),a==null||a.attemptAutoclose(P.AddSuccessCaller,this.id),this):this}addErrorCaller(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,B().toISOString(),this,!0,P.AddErrorCaller)),l=!1){return this.checkCanEditWithCounterpartAndSideEffects(this,i,P.AddErrorCaller,a)?(this.calledByError.find(f=>f.id===i.id)||(this.calledByError.push(i),a==null||a.add(this,k.Updated),l&&et(this,a)),a==null||a.attemptAutoclose(P.AddErrorCaller,this.id),this):this}addEntryCaller(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,B().toISOString(),this,!0,P.AddEntryCaller)),l=!1){return this.checkCanEditWithCounterpartAndSideEffects(this,i,P.AddEntryCaller,a)?(this.calledByEntry.find(f=>f.id===i.id)||(this.calledByEntry.push(i),a==null||a.add(this,k.Updated),l&&et(this,a)),a==null||a.attemptAutoclose(P.AddEntryCaller,this.id),this):this}addErrorCall(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,B().toISOString(),this,!0,P.AddErrorCall)),l=!1){return this.checkCanEditWithCounterpartAndSideEffects(this,i,P.AddErrorCall,a)?(this.errorCalls.find(f=>f.id===i.id)||(this.errorCalls.push(i),l&&et(this,a),a==null||a.add(this,k.Affected)),a==null||a.attemptAutoclose(P.AddErrorCall,this.id),this):this}addSuccessCall(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,B().toISOString(),this,!0,P.AddSuccessCall)),l=!1){return this.checkCanEditWithCounterpartAndSideEffects(this,i,P.AddSuccessCall,a)?(this.successCalls.find(f=>f.id===i.id)||(this.successCalls.push(i),l&&et(this,a),a==null||a.add(this,k.Affected)),a==null||a.attemptAutoclose(P.AddSuccessCall,this.id),this):this}removeCall(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,B().toISOString(),this,!0,P.RemoveCall)),l=!1){if(!this.checkCanEditWithCounterpartAndSideEffects(this,i,P.RemoveCall,a))return this;const f=this.successCalls.findIndex(y=>y.id===i.id);f>-1&&(this.successCalls.splice(f,1),a==null||a.add(this,k.Affected));const e=this.errorCalls.findIndex(y=>y.id===i.id);return e>-1&&(this.errorCalls.splice(e,1),a==null||a.add(this,k.Affected)),l&&et(this,a),a==null||a.attemptAutoclose(P.RemoveCall,this.id),this}removeCaller(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,B().toISOString(),this,!0,"remove-caller")),l=!1){return this.checkCanEditWithCounterpartAndSideEffects(this,i,P.RemoveCaller,a)?(this.calledBySuccess=this.calledBySuccess.filter(f=>f.id!==i.id?!0:(a==null||a.add(this,k.Updated),a==null||a.add(f,k.Affected),!1)),this.calledByError=this.calledByError.filter(f=>f.id!==i.id?!0:(a==null||a.add(this,k.Updated),a==null||a.add(f,k.Affected),!1)),this.calledByEntry=this.calledByEntry.filter(f=>f.id!==i.id?!0:(a==null||a.add(this,k.Updated),a==null||a.add(f,k.Affected),!1)),l&&et(this,a),a==null||a.attemptAutoclose(P.RemoveCaller,this.id),this):this}setParent(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,B().toISOString(),this,!0,P.SetParent))){var l;return this.checkCanEditWithCounterpartAndSideEffects(this,i,P.SetParent,a)?(((l=this.parent)==null?void 0:l.id)!==(i==null?void 0:i.id)&&(this.parent=i,a&&(a==null||a.add(this,k.Updated))),a==null||a.attemptAutoclose(P.SetParent,this.id),this):this}setDeclaration(i){return this.declaration=i,this}initChildren(i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,B().toISOString(),this,!0,"init-children"))){if(this.initialized||this.startedInitialization)return this;if(this.startedInitialization=!0,this.initialData.declaration.type===p.FunctionDeclaration){const a=ae(this.initialData.declaration,this.project);this.declaration=a}else{const a=ee(this.initialData.declaration),l=this.project.get(a);this.declaration=l}return this.successCalls=this.initialData.successCalls.map(a=>{const l=ae(a,this.project);if(l.addSuccessCaller(this,null),[p.BreakStatement,p.ContinueStatement].includes(l.type))l.setParent(this.parent.parent,null),l.initChildren(i);else if(l.type===p.ReturnStatement){const f=Er(this,this.project);l.setParent(f,null),l.initChildren(i)}else l.type!==p.InternalCall&&(l.setParent(this.parent,null),l.initChildren(i));return l}),this.errorCalls=this.initialData.errorCalls.map(a=>{const l=ae(a,this.project);if(l.addErrorCaller(this,null),[p.BreakStatement,p.ContinueStatement].includes(l.type))l.setParent(this.parent.parent,null),l.initChildren(i);else if(l.type===p.ReturnStatement){const f=Er(this,this.project);l.setParent(f,null),l.initChildren(i)}else l.type!==p.InternalCall&&(l.setParent(this.parent,null),l.initChildren(i));return l}),this.inputs=this.initialData.inputs.map(a=>{const l=ae(a,this.project);return l.setParent(this,null),l.initChildren(i),l}),this.initialData.error&&(this.error=ae(this.initialData.error,this.project),this.error.setParent(this,null),this.error.initChildren(i)),this.subscribeToDependencies(),this.afterAllChildrenInitialized(i),i==null||i.attemptAutoclose("init-children",this.id),this}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,B().toISOString(),this,!0,"meta-sync"))){const l=nr(this,i),f=rr(this,l),e=this.toMeta();return this.x=l.x||e.x,this.y=l.y||e.y,this.catchesError=l.catchesError!==void 0?l.catchesError:this.catchesError,super.baseMetaSync(l,this),l.deleted===!0&&!e.deleted?a==null||a.add(this,k.Removed):l.deleted===!1&&e.deleted?a==null||a.add(this,k.Added):f&&(a==null||a.add(this,k.Updated)),a==null||a.attemptAutoclose("meta-sync",this.id),this}async APILoad(i=Ae,...a){return await yi.repository.APILoad(this.id,...a),this}async APICreate(i=Ae,...a){return await yi.repository.APICreate(this.toShallowJSON(),...a),this}async APIUpdate(i=Ae,...a){return await yi.repository.APIUpdate(this.toShallowJSON(),...a),this}async APIDelete(i=Ae,...a){return await yi.repository.APIDelete(this.toShallowJSON(),...a),this}async APIClone(i=Ae,...a){return await yi.repository.APIClone(this.id,...a),this}async APILoadVersion(i=Ae,a,...l){return await yi.repository.APILoadVersion(this.id,a,...l)}removeFromParent(i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,B().toISOString(),this,!0,P.RemoveFromParent))){if(!this.checkCanEdit(this))return J.warn(`[removeFromParent] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(P.RemoveFromParent,this.id),{added:[],updated:[],removed:[],affected:[],self:this};const a=[],l=[],f=[],e=[];return this.parent.type===p.Project?(this.parent.removeFunctionCall(this),e.push(this.parent)):this.parent.detachedChildren.includes(this)&&this.parent.unsubscribeDetachedChild(this),i==null||i.attemptAutoclose(P.RemoveFromParent,this.id),{added:C(f),updated:C(a),removed:C(l),affected:C(e),self:this}}remove({ignoreUpstream:i}={ignoreUpstream:!1},a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,B().toISOString(),this,!0,P.RemoveEntity))){var v;if(!this.checkCanDelete(this)||!this.checkCanEdit(this))return J.warn(`[remove] User is not allowed to delete or edit this ${this.type} entity with id: ${this.id}`),a==null||a.event({id:`${P.RemoveEntity}-${this.id}`,action:P.RemoveEntity,owner:this,errorReason:ki.ActionOwnerEntityNonDeletable,rootAction:((v=a==null?void 0:a.self)==null?void 0:v.id)===this.id&&(a==null?void 0:a.autoCloseActionName)===P.RemoveEntity}),a==null||a.attemptAutoclose(P.RemoveEntity,this.id),{added:[],updated:[],removed:[],affected:[],self:this};const l=[],f=[],e=[],y=[];if(a!=null&&a.hasRemoved(this.id))return a==null||a.attemptAutoclose(P.RemoveEntity,this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(f.push(this),this.unsubscribe(),this.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},a),Object.values(this.detachedDependents).forEach(T=>{const{updated:A,removed:b,added:O}=T.entity.onDetachedDependencyRemoved(this,T.field,a);l.push(...A),f.push(...b),e.push(...O)}),this.inputs.forEach(T=>{const{updated:A,removed:b}=T.remove({ignoreUpstream:!0},a);l.push(...A),f.push(...b)}),this.outputs.forEach(T=>{const{updated:A,removed:b}=T.remove({ignoreUpstream:!0},a);l.push(...A),f.push(...b)}),this.error){const{updated:T,removed:A}=this.error.remove({ignoreUpstream:!0},a);l.push(...T),f.push(...A)}if(this.successCalls.forEach(T=>{l.push(T),T.removeCaller(this,a)}),this.errorCalls.forEach(T=>{l.push(T),T.removeCaller(this,a)}),!i){const T=this.removeFromParent(a);e.push(...T.added),l.push(...T.updated),f.push(...T.removed),y.push(...T.affected),this.calledBy.forEach(A=>{l.push(A),A.removeCall(this,a)})}return a==null||a.attemptAutoclose(P.RemoveEntity,this.id),{added:C(e),updated:C(l),removed:C(f),affected:C(y),self:this}}restore({}={},i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,B().toISOString(),this,!0,P.RestoreEntity))){if(!this.checkCanEdit(this))return J.warn(`[restore] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(P.RestoreEntity,this.id),{added:[],updated:[],removed:[],affected:[],self:this};const a=[],l=[],f=[],e=[];return i!=null&&i.hasAdded(this.id)?(i==null||i.attemptAutoclose(P.RestoreEntity,this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},i),Object.values(this.detachedDependents).forEach(y=>{const{updated:v,removed:T,added:A}=y.entity.onDetachedDependencyRestored(this,y.field,i);l.push(...v),f.push(...T),a.push(...A)}),this.inputs.forEach(y=>{const{updated:v}=y.restore({},i);l.push(...v)}),this.outputs.forEach(y=>{const{updated:v}=y.restore({},i);l.push(...v)}),this.successCalls.forEach(y=>{l.push(y),y.addSuccessCaller(this,i)}),this.errorCalls.forEach(y=>{l.push(y),y.addErrorCaller(this,i)}),this.calledBySuccess.forEach(y=>{l.push(y),y.addSuccessCall(this,i)}),this.calledByError.forEach(y=>{l.push(y),y.addErrorCall(this,i)}),this.calledByEntry.forEach(y=>{l.push(y),y.addCall(this,i)}),i==null||i.attemptAutoclose(P.RestoreEntity,this.id),{added:C(a),updated:C(l),removed:C(f),affected:C(e),self:this})}toFlat(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this,...this.successCalls.flatMap(l=>l.toFlat(i)),...this.errorCalls.flatMap(l=>l.toFlat(i)),...this.inputs.flatMap(l=>l.toFlat(i)),...this.outputs.flatMap(l=>l.toFlat(i)),...this.error?this.error.toFlat(i):[],...this.calledBy.flatMap(l=>l.toFlat(i))])}toFlatIds(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.id,...this.successCalls.flatMap(l=>l.toFlatIds(i)),...this.errorCalls.flatMap(l=>l.toFlatIds(i)),...this.inputs.flatMap(l=>l.toFlatIds(i)),...this.outputs.flatMap(l=>l.toFlatIds(i))])}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,editable:this.editable,deletable:this.deletable,catchesError:this.catchesError}}toJSON(i=new Set){var a;return i.has(this.id)?this.toReference():(i.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,editable:this.editable,deletable:this.deletable,catchesError:this.catchesError,x:this.x,y:this.y,successCalls:this.successCalls.map(l=>l.toJSON(i)),errorCalls:this.errorCalls.map(l=>l.toJSON(i)),calledBySuccess:this.calledBySuccess.map(l=>l.toReference()),calledByError:this.calledByError.map(l=>l.toReference()),calledByEntry:this.calledByEntry.map(l=>l.toReference()),writesValues:this.writesValues.map(l=>l.toJSON(i)),declaration:this.declaration.toJSON(i),inputs:this.inputs.map(l=>l.toJSON(i)),outputs:this.outputs.map(l=>l.toJSON(i)),parent:this.parent.toReference(),error:(a=this.error)==null?void 0:a.toJSON(i)})}toJSONClone(i=He){var l,f,e,y,v,T;let a;return(l=i.seenEntityMaps)!=null&&l.has(this.id)?a=i.seenEntityMaps.get(this.id):(a=i.newId||yr(this,this.project,i.uuidStrategy),i.seenEntityMaps&&i.seenEntityMaps.set(this.id,a)),(f=i.seenEntities)!=null&&f.has(a)||(e=i.seenEntities)!=null&&e.has(this.id)?this.toReference({seenEntityMaps:i.seenEntityMaps}):((y=i.seenEntities)==null||y.add(a),(v=i.seenEntities)==null||v.add(this.id),{id:a,version:N.UUID.uuid(),createdAt:i.timestamp||B().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,catchesError:this.catchesError,type:this.type,editable:this.editable,deletable:this.deletable,x:this.x,y:this.y,writesValues:this.writesValues.map(A=>A.toJSONClone({...i,newId:null})),successCalls:this.successCalls.map(A=>A.toJSONClone({...i,newId:null})),errorCalls:this.errorCalls.map(A=>A.toJSONClone({...i,newId:null})),calledBySuccess:this.calledBySuccess.map(A=>A.toReference({seenEntityMaps:i.seenEntityMaps})),calledByError:this.calledByError.map(A=>A.toReference({seenEntityMaps:i.seenEntityMaps})),calledByEntry:this.calledByEntry.map(A=>A.toReference({seenEntityMaps:i.seenEntityMaps})),declaration:this.declaration.toJSONClone({...i,newId:null}),inputs:this.inputs.map(A=>A.toJSONClone({...i,newId:null})),outputs:this.outputs.map(A=>A.toJSONClone({...i,newId:null})),error:(T=this.error)==null?void 0:T.toJSONClone({...i,newId:null}),parent:this.parent.toReference({seenEntityMaps:i.seenEntityMaps})})}toReference(i=He){var l;let a=this.id;return(l=i.seenEntityMaps)!=null&&l.has(this.id)&&(a=i.seenEntityMaps.get(this.id)),{id:a+"--"+N.UUID.uuid()+"--ref",type:p.GenericReference,entityId:a,version:this.version,entityType:this.type}}toShallowJSON(i=He){var l;let a=this.id;return(l=i.seenEntityMaps)!=null&&l.has(this.id)&&(a=i.seenEntityMaps.get(this.id)),{id:a,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,editable:this.editable,deletable:this.deletable,catchesError:this.catchesError,x:this.x,y:this.y,writesValues:this.writesValues.map(f=>f.toReference(i)),inputs:this.inputs.map(f=>f.toReference(i)),outputs:this.outputs.map(f=>f.toReference(i)),declaration:this.declaration.toReference(i),successCalls:this.successCalls.map(f=>f.toReference(i)),errorCalls:this.errorCalls.map(f=>f.toReference(i)),calledBySuccess:this.calledBySuccess.map(f=>f.toReference(i)),calledByError:this.calledByError.map(f=>f.toReference(i)),calledByEntry:this.calledByEntry.map(f=>f.toReference(i)),error:this.error?this.error.toReference(i):null,parent:this.parent.toReference(i)}}toFlatJSON(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.toShallowJSON(),...this.successCalls.flatMap(l=>l.toFlatJSON(i)),...this.errorCalls.flatMap(l=>l.toFlatJSON(i)),...this.inputs.flatMap(l=>l.toFlatJSON(i)),...this.outputs.flatMap(l=>l.toFlatJSON(i)),...this.error?this.error.toFlatJSON(i):[]])}toGenerationTarget(){const i=this.parent.type===p.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,editable:this.editable,deletable:this.deletable,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:i}}toFlatGenerationTarget(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.toGenerationTarget(),...this.successCalls.flatMap(l=>l.toFlatGenerationTarget(i)),...this.errorCalls.flatMap(l=>l.toFlatGenerationTarget(i)),...this.inputs.flatMap(l=>l.toFlatGenerationTarget(i)),...this.outputs.flatMap(l=>l.toFlatGenerationTarget(i)),...this.error?this.error.toFlatGenerationTarget(i):[]])}clearErrors(){var i;return this.errors=[],this.inputs.forEach(a=>a.clearErrors()),this.outputs.forEach(a=>a.clearErrors()),this.successCalls.forEach(a=>a.clearErrors()),this.errorCalls.forEach(a=>a.clearErrors()),(i=this.error)==null||i.clearErrors(),this}validate(){const i=QW(this);return this.errors=i,{success:!0}}getErrors(){return[...this.errors,...this.inputs.flatMap(a=>a.getErrors()),...this.outputs.flatMap(a=>a.getErrors()),...this.error?this.error.getErrors():[]]}getShallowErrors(){return this.errors}clone(i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,B().toISOString(),this,!0,P.CloneEntity)),a=null,l=null,f=!0){var M,U;let e=fr(a,this);const y=this.toJSON(),v=l||N.UUID.uuid();y.inputs=[];const T=v.split("-id"),A=T[T.length-1||0]||v;y.id=v,y.version=N.UUID.uuid(),y.createdAt=(i==null?void 0:i.timestamp)||B().toISOString(),y.author=(i==null?void 0:i.author)||"1",y.previousVersion=null,y.deleted=!1,y.deletable=!0,y.editable=!0;const b=Ci(y,e);a?b.setParent(a,null):b.setParent(this.parent,null),f&&b.subscribe(),b.initChildren(i),i==null||i.add(b,k.Added);const O=(M=this.inputs)==null?void 0:M.map((q,Z)=>q.clone(i,b,A+"-input-map-"+Z+"-id",f));b.inputs=O;const L=(U=this.outputs)==null?void 0:U.map((q,Z)=>q.clone(i,b,A+"-output-map-"+Z+"-id",f));return b.outputs=L,this.error&&(b.error=this.error.clone(i,b,A+"-error-map-id",f)),i==null||i.attemptAutoclose(P.CloneEntity,this.id),b}removeUnrecognizedInputs(i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,B().toISOString(),this,!0,P.RemoveUnrecognizedInputs))){if(!this.checkCanEdit(this))return J.warn(`[removeUnrecognizedInputs] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(P.RemoveUnrecognizedInputs,this.id),{updated:[],added:[],removed:[],affected:[],self:this};const a=[],l=[],f=[],e=[];return this.inputs.forEach(v=>{if(!this.declaration.inputs.find(A=>{var b;return A.id===((b=v.declaration)==null?void 0:b.id)})){const A=v.remove({ignoreUpstream:!1},i);f.push(...A.removed),a.push(...A.updated)}}),this.inputs.filter((v,T)=>{const A=this.inputs.findIndex(O=>O.declaration===v.declaration&&O!==v);if(A===-1)return!1;const b=this.inputs[A];return B(b==null?void 0:b.createdAt).isSame(B(v.createdAt))?T>A:!!B(b==null?void 0:b.createdAt).isAfter(v.createdAt)}).forEach(v=>{const T=v.remove({ignoreUpstream:!1},i);f.push(...T.removed),a.push(...T.updated)}),i==null||i.attemptAutoclose(P.RemoveUnrecognizedInputs,this.id),{updated:C(a),added:C(l),removed:C(f),affected:C(e),self:this}}removeUnrecognizedOutputs(i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,B().toISOString(),this,!0,P.RemoveUnrecognizedOutputs))){var T,A;if(!this.checkCanEdit(this))return J.warn(`[removeUnrecognizedOutputs] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(P.RemoveUnrecognizedOutputs,this.id),{updated:[],added:[],removed:[],affected:[],self:this};const a=[],l=[],f=[],e=[],y=((A=(T=this.declaration.dataType)==null?void 0:T.entity)==null?void 0:A.properties)||[];return this.outputs.forEach(b=>{if(!y.find(L=>{var M;return L.id===((M=b.declaration)==null?void 0:M.id)})){const L=b.remove({ignoreUpstream:!1},i);f.push(...L.removed),a.push(...L.updated)}}),this.outputs.filter((b,O)=>{const L=this.outputs.findIndex(U=>U.declaration===b.declaration&&U!==b);if(L===-1)return!1;const M=this.outputs[L];return B(M==null?void 0:M.createdAt).isSame(B(b.createdAt))?O>L:!!B(M==null?void 0:M.createdAt).isAfter(b.createdAt)}).forEach(b=>{const O=b.remove({ignoreUpstream:!1},i);f.push(...O.removed),a.push(...O.updated)}),i==null||i.attemptAutoclose(P.RemoveUnrecognizedOutputs,this.id),{updated:C(a),added:C(l),removed:C(f),affected:C(e),self:this}}syncInputs(i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,B().toISOString(),this,!0,P.SyncInputs))){if(!this.checkCanEdit(this))return J.warn(`[syncInputs] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(P.SyncInputs,this.id),{updated:[],added:[],removed:[],affected:[],self:this};const a=[],l=[],f=[],e=[],y=this.declaration.inputs.filter(b=>!this.inputs.find(O=>O.declaration.id===b.id));this.inputs.sort((b,O)=>b.index-O.index),y.forEach(b=>{this.inputs.forEach(M=>{M.index>=b.index&&M.metaSync({index:M.index+1},i)});const O={id:N.UUID.uuid(),version:N.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||B().toISOString(),author:N.sessionAuthor,previousVersion:null,deleted:!1,deletable:!0,editable:!0,type:p.InputMap,parentRelationType:null,declaration:b.toJSON(),readsValue:null,defaultValue:null,index:b.index,name:null,codeName:null,description:null,parent:this.toReference()},L=ae(O,this.project);L.setParent(this,i),L.initChildren(i),i==null||i.add(L,k.Added),L.addSelfToProject(i),l.push(L)}),this.inputs.sort((b,O)=>b.index-O.index);const{updated:v,added:T,removed:A}=this.removeUnrecognizedInputs(i);return a.push(...v),l.push(...T),f.push(...A),i==null||i.attemptAutoclose(P.SyncInputs,this.id),{updated:C(a),added:C(l),removed:C(f),affected:C(e),self:this}}syncOutputs(i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,B().toISOString(),this,!0,P.SyncOutputs))){var O,L;if(!this.checkCanEdit(this))return J.warn(`[syncOutputs] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(P.SyncOutputs,this.id),{updated:[],added:[],removed:[],affected:[],self:this};const a=[],l=[],f=[],e=[],y=[];this.outputs=this.initialData.outputs.reduce((M,U)=>{if(U.type===p.GenericReference){const Z=mn(U,this.project);return Z?[...M,Z]:M}const q=ae(U,this.project);return y.push(q.index),q.setParent(this,null),q.initChildren(i),[...M,q]},[]);const v=(((L=(O=this.declaration.dataType)==null?void 0:O.entity)==null?void 0:L.properties)||[]).filter(M=>!this.outputs.find(U=>{var q;return((q=U.declaration)==null?void 0:q.id)===M.id}));this.outputs.sort((M,U)=>M.index-U.index),v.forEach((M,U)=>{this.outputs.forEach(z=>{z.index>=M.index&&z.index++});const q=y.includes(M.index)?this.outputs.length-1+U:M.index,Z={id:N.UUID.uuid(),version:N.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||B().toISOString(),author:N.sessionAuthor,previousVersion:null,deleted:!1,deletable:!0,editable:!0,type:p.OutputMap,declaration:M.toJSON(),writesValues:[],index:q,parent:this.toReference()},H=ae(Z,this.project);H.setParent(this,i),H.initChildren(i),i==null||i.add(H,k.Added),H.addSelfToProject(i)}),this.outputs.sort((M,U)=>M.index-U.index);const{updated:T,added:A,removed:b}=this.removeUnrecognizedOutputs(i);return a.push(...T),l.push(...A),f.push(...b),i==null||i.attemptAutoclose(P.SyncOutputs,this.id),{updated:C(a),added:C(l),removed:C(f),affected:C(e),self:this}}getUnusedInputs(){return this.inputs.filter(i=>i.suggestion||!i.readsValue&&!i.defaultValue)}getUnusedOutputs(){return this.outputs.filter(i=>i.suggestion||!i.writesValues.length)}getUsedInputs(){return this.inputs.filter(i=>!i.suggestion&&(i.readsValue||i.defaultValue))}getUsedOutputs(){return this.outputs.filter(i=>!i.suggestion&&i.writesValues.length)}getDataType(i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,B().toISOString(),this,!0,"get-data-type"))){var l;const a=((l=this.declaration)==null?void 0:l.getDataType(i))||null;return i==null||i.attemptAutoclose("get-data-type",this.id),a}};_(yi,"repository",{APICreate:async(i,...a)=>i,APIUpdate:async(i,...a)=>i,APIDelete:async(i,...a)=>i,APIClone:async(i,...a)=>{},APILoad:async(i,...a)=>null,APILoadVersion:async(i,a,...l)=>null}),_(yi,"type",p.FunctionCall),_(yi,"USER_MANAGED_PARENT_TYPES",[...Xi,p.Project]),_(yi,"PARENT_TYPES",[...yi.USER_MANAGED_PARENT_TYPES]),_(yi,"MUTABLE_BASE_PROPERTIES",["catchesError"]),_(yi,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),_(yi,"BASE_PROPERTIES",[...yi.MUTABLE_BASE_PROPERTIES,...yi.INMUTABLE_BASE_PROPERTIES]),_(yi,"MUTABLE_META_PROPERTIES",["x","y"]),_(yi,"INMUTABLE_META_PROPERTIES",[...yi.INMUTABLE_BASE_PROPERTIES]),_(yi,"META_PROPERTIES",[...yi.MUTABLE_META_PROPERTIES,...yi.INMUTABLE_META_PROPERTIES]),_(yi,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry"]),_(yi,"INMUTABLE_UPSTREAM_PROPERTIES",["declaration","parent"]),_(yi,"UPSTREAM_PROPERTIES",[...yi.MUTABLE_UPSTREAM_PROPERTIES,...yi.INMUTABLE_UPSTREAM_PROPERTIES]),_(yi,"MUTABLE_DOWNSTREAM_PROPERTIES",["successCalls","errorCalls","writesValues","inputs","outputs","error"]),_(yi,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),_(yi,"DOWNSTREAM_PROPERTIES",[...yi.MUTABLE_DOWNSTREAM_PROPERTIES,...yi.INMUTABLE_DOWNSTREAM_PROPERTIES]),_(yi,"PROPERTIES",[...yi.META_PROPERTIES,...yi.UPSTREAM_PROPERTIES,...yi.DOWNSTREAM_PROPERTIES]);let Eo=yi;function Lw(d){return d&&typeof d.then=="function"}function L$e(d){const u=new ga(d[0]),i=d.map(l=>l.id),a={};return d.forEach(l=>{a[l.id]=l}),u.order=i,u.flatRecord=a,u.orderEntities(),u.order.map(l=>u.flatRecord[l])}function B$e(d){const u=new ga(Object.values(d)[0]),i=Object.keys(d);return u.order=i,u.flatRecord=d,u.orderEntities(),u.order}class ga{constructor(u){_(this,"order",[]);_(this,"flatRecord",{});_(this,"allBuiltInEntityIds",Kn());_(this,"onGoingVisits",{});u&&(this.flatten(u),this.orderEntities())}flatten(u){const i=new Set(Kn()),a=C(Te(u,i,{ignoreBuiltInBaseEntities:!0})),l=new Set;for(const f of a)this.flatRecord[f.id]=f,l.add(f.id);this.order=Array.from(l)}moveEntityAfterDependencies(u){const{upstream:i}=sp(u,this.flatRecord,{ignoreBuiltInBaseEntities:!0,allBuiltInEntityIds:this.allBuiltInEntityIds});for(const a of Object.keys(i)){const l=this.order.indexOf(a),f=this.order.indexOf(u.id);if(l>f)return this.order.splice(f,1),this.order.splice(l,0,u.id),!0}return!1}orderEntities(){let u=!1;for(let i=0;i<this.order.length;i++){const a=this.order[i],l=this.flatRecord[a];if(l||J.warn(`Entity with id ${a} not found in flatRecord. Skipping...`),this.moveEntityAfterDependencies(l)){u=!0;break}}u&&this.orderEntities()}getUpstreamOngoingDependenciesVisits(u,i){const{upstream:a}=sp(this.flatRecord[u],this.flatRecord,{ignoreBuiltInBaseEntities:!0,allBuiltInEntityIds:this.allBuiltInEntityIds}),l={};return Object.entries(this.onGoingVisits[i]||{}).forEach(([f,e])=>{Object.keys(a).includes(f)&&(l[f]=e)}),l}getDownstreamOngoingDependenciesVisits(u,i){const a=Object.keys(this.onGoingVisits[i]||{}),l=new Set(a.flatMap(e=>Object.keys(sp(this.flatRecord[e],this.flatRecord,{ignoreBuiltInBaseEntities:!0,allBuiltInEntityIds:this.allBuiltInEntityIds}).downstream))),f={};return Array.from(l).forEach(e=>{e===u&&(f[e]=this.onGoingVisits[i][e])}),f}async settlePromises(u,i){const a=Object.values(u);a.length&&await Promise.all(a),Object.keys(u).forEach(l=>{delete this.onGoingVisits[i][l]})}visit(u){const i=this.order;for(const a of i)u(this.flatRecord[a],this.flatRecord);return this}reverseVisit(u){const i=this.order.slice().reverse();for(const a of i)u(this.flatRecord[a],this.flatRecord);return this}async visitAsync(u){const i=this.order,a=Math.random().toString(36).substring(7);this.onGoingVisits[a]={};for(const l of i){const f=this.getUpstreamOngoingDependenciesVisits(l,a);Object.keys(f).length&&await this.settlePromises(f,a);const e=u(this.flatRecord[l],this.flatRecord);Lw(e)&&(this.onGoingVisits[a][l]=e)}return await this.settlePromises(this.onGoingVisits[a],a),this.onGoingVisits[a]={},this}async reverseVisitAsync(u){const i=this.order.slice().reverse(),a=Math.random().toString(36).substring(7);this.onGoingVisits[a]={};for(const l of i){const f=this.getDownstreamOngoingDependenciesVisits(l,a);Object.keys(f).length&&await this.settlePromises(f,a);const e=u(this.flatRecord[l],this.flatRecord);Lw(e)&&(this.onGoingVisits[a][l]=e)}return await this.settlePromises(this.onGoingVisits[a],a),this.onGoingVisits[a]={},this}}const M$e=63,x$e=/^[a-z][a-z0-9-]*[a-z0-9]$/;function U$e(d){return d.length>=1&&d.length<=M$e&&x$e.test(d)&&!d.includes("--")}function*j$e(){yield"";const d="abcdefghijklmnopqrstuvwxyz";for(let u=1;;u++){const i=new Array(u).fill(0);let a=!1;for(;!a;){yield i.map(l=>d[l]).join("");for(let l=u-1;l>=0&&(i[l]++,!(i[l]<d.length));l--)i[l]=0,l===0&&(a=!0)}}}function G$e(d,u){const i=new Set(d.map(l=>l.toLowerCase())),a=u>0?"secondary-db":"main";for(const l of j$e()){const f=l?`${a}-${l}`:a;if(U$e(f)&&!i.has(f))return f}throw new Error("Unable to generate identifier")}function eH(d,u){switch(d.id){case ce["built-in-base-entity"].BUILT_IN_PERSISTED_ENTITY_ENTITY.id:{const i=d.project.entities.filter(v=>!!v.implements.find(T=>T.id===ce["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.id)),a=i.find(v=>{const T=v.properties.find(O=>O.implements.find(L=>L.id===ce["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.default.id)),A=T==null?void 0:T.getDefaultValue();return(A==null?void 0:A.value)===!0});if(!a&&i.length){const T=i[0].properties.find(b=>b.implements.find(O=>O.id===ce["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.default.id)),A=T==null?void 0:T.defaultValue;if(A)A.metaSync({value:!0},u);else if(T!=null&&T.dataType){const b={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,deletable:!0,editable:!0,type:p.LiteralValue,standaloneParent:null,name:re.EntityTemplate,autogeneration:null,value:!0,valueAsTypeSingle:null,valueAsTypeList:null,parent:T==null?void 0:T.toReference()},O=ae(b,d.project);return O.setParent(T,u),O.initChildren(u),u==null||u.add(O,k.Added),O.addSelfToProject(u),{newEntities:[O]}}return{newEntities:[]}}else if(a)return{newEntities:[]};const l=d.project.get(ce["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.id),f=B0(l,"Main database",u);if(f.errors.length>0)return{newEntities:[]};const e=f.properties.find(v=>v.implements.find(T=>T.id===ce["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,deletable:!0,editable:!0,type:p.LiteralValue,standaloneParent:null,name:re.EntityTemplate,autogeneration:null,value:!0,valueAsTypeSingle:null,valueAsTypeList:null,parent:e==null?void 0:e.toReference()},T=ae(v,d.project);T.setParent(e,u),T.initChildren(u),u==null||u.add(T,k.Added),T.addSelfToProject(u)}return{newEntities:[f]}}}return{newEntities:[]}}function tH(d,u){const i=[],a=[],l=[],f=[];return d.implements.filter(y=>y.type===p.BuiltInBaseEntity).forEach(y=>{var v,T,A,b,O;switch(y.id){case ce["built-in-base-entity"].BUILT_IN_PERSISTED_ENTITY_ENTITY.id:{const L=d.project.entities.filter(H=>H.implements.find(z=>z.id===ce["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.id));let M=L.find(H=>!!H.properties.find(z=>{var oe;return z.implements.find(ie=>ie.id===ce["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.default.id)&&((oe=z.getDefaultValue())==null?void 0:oe.value)===!0}));if(!M&&L.length)M=L[0];else if(!M&&!L.length){M=d.project.getBuiltIn(ce["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.id).implement("Relational database",u);const z=M.properties.find(oe=>oe.implements.find(ie=>ie.id===ce["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.default.id));(v=z==null?void 0:z.defaultValue)==null||v.metaSync({value:!0},u),a.push(M)}const U=d.properties.find(H=>H.implements.find(z=>z.id===ce["built-in-base-entity"].BUILT_IN_PERSISTED_ENTITY_ENTITY.properties.database.id));if(U&&!(U!=null&&U.defaultValue)){const H={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,deletable:!0,editable:!0,type:p.LiteralValue,standaloneParent:null,name:re.EntityTemplate,autogeneration:null,value:null,valueAsTypeSingle:(M==null?void 0:M.toJSON())||null,valueAsTypeList:null,parent:U==null?void 0:U.toReference()},z=ae(H,d.project);z.hydrateAncestors(),z.setParent(U,u),z.addSelfToProject(u),u==null||u.add(z,k.Added),z.initChildren(u),(U==null?void 0:U.defaultValue).setValueAsTypeSingle(M||null,u),a.push(z);return}else U!=null&&U.defaultValue&&!(U!=null&&U.defaultValue.valueAsTypeSingle)&&(U==null||U.defaultValue.setValueAsTypeSingle(M||null,u));const q=d.properties.find(H=>H.implements.find(z=>z.id===ce["built-in-base-entity"].BUILT_IN_PERSISTED_ENTITY_ENTITY.properties.primaryKey.id));if(!q)throw new Error(`[handleAfterEntityImplementationSideEffects] Primary key property not found for implemented base entity ${ce["built-in-base-entity"]}`);if(!q.dataType){const H=Zr.new(u);H.parent=q.toReference();const z=ae(H,d.project);z.hydrateAncestors(),z.setParent(q,u),z.addSelfToProject(u),u==null||u.add(z,k.Added),z.initChildren(u)}const Z=d.project.getBuiltIn(ce["primitive-entity"].number.id);(T=q.dataType)==null||T.setEntity(Z,u);return}case ce["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.id:{const L=d.project.entities.filter(oe=>oe.implements.find(ie=>ie.id===ce["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.id)&&oe.id!==d.id),M=L.map(oe=>{var te;const ie=oe.properties.find(fe=>fe.implements.find(me=>me.id===ce["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.identifier.id));return(te=ie==null?void 0:ie.getDefaultValue())==null?void 0:te.value}).filter(oe=>!!oe),U=d.properties.find(oe=>oe.implements.find(ie=>ie.id===ce["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.identifier.id));if(!L.find(oe=>!!oe.properties.find(ie=>{var ne;return ie.implements.find(te=>te.id===ce["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.default.id)&&((ne=ie.getDefaultValue())==null?void 0:ne.value)===!0}))){const oe=d.properties.find(ie=>ie.implements.find(ne=>ne.id===ce["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.default.id));if(!oe)throw new Error("Default boolean property not found for relational database entity with id: "+d.id);if(!(oe!=null&&oe.defaultValue)){const ie=Or.new(u);ie.parent=oe.toReference();const ne=ae(ie,d.project);ne.hydrateAncestors(),ne.setParent(oe,u),ne.addSelfToProject(u),u==null||u.add(ne,k.Added),ne.initChildren(u)}(A=oe==null?void 0:oe.defaultValue)==null||A.metaSync({value:!0},u)}if(!U)throw new Error("Identifier property not found for relational database entity with id: "+d.id);if(!(U!=null&&U.defaultValue)){const oe=Or.new(u);oe.parent=U.toReference();const ie=ae(oe,d.project);ie.hydrateAncestors(),ie.setParent(U,u),ie.addSelfToProject(u),ie.initChildren(u),u==null||u.add(ie,k.Added)}const Z=G$e(M,L.length);(b=U.defaultValue)==null||b.metaSync({value:Z},u);const H=d.properties.find(oe=>oe.implements.find(ie=>ie.id===ce["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.password.id));if(!H)throw new Error(`[handleAfterEntityImplementationSideEffects] Password property not found for implemented base entity ${ce["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.id} with id ${d.id}`);if(!H.defaultValue){const oe=Or.new(u);oe.parent=H.toReference();const ie=ae(oe,d.project);ie.hydrateAncestors(),ie.setParent(H,u),ie.addSelfToProject(u),ie.initChildren(u),u==null||u.add(ie,k.Added),a.push(ie)}const z=ZK(24);(O=H.defaultValue)==null||O.metaSync({value:z},u);return}case ce["built-in-base-entity"].BUILT_IN_SQL_ROW_TRANSFORMER_ENTITY.id:{const L=d.properties.find(Z=>Z.implements.find(H=>H.id===ce["built-in-base-entity"].BUILT_IN_SQL_ROW_TRANSFORMER_ENTITY.properties.time.id));if(!L)throw new Error(`[handleAfterEntityImplementationSideEffects] Time property not found for implemented base entity ${ce["built-in-base-entity"].BUILT_IN_SQL_ROW_TRANSFORMER_ENTITY.id} with id ${d.id}`);let M=L.defaultValue||null;if(!M){const Z=Or.new(u);Z.parent=L.toReference(),Z.id=N.UUID.uuid(),M=ae(Z,d.project),M.hydrateAncestors(),M.setParent(L,u),M.addSelfToProject(u),M.initChildren(u),u==null||u.add(M,k.Added)}M.metaSync({value:new Date().toISOString()},u),M.metaSync({editable:!1,deletable:!1},u),L.metaSync({editable:!1,deletable:!1},u);const U=d.properties.find(Z=>Z.implements.find(H=>H.id===ce["built-in-base-entity"].BUILT_IN_SQL_ROW_TRANSFORMER_ENTITY.properties.definition.id));if(!U)throw new Error(`[handleAfterEntityImplementationSideEffects] Definition property not found for implemented base entity ${ce["built-in-base-entity"].BUILT_IN_SQL_ROW_TRANSFORMER_ENTITY.id} with id ${d.id}`);let q=U.defaultValue||null;if(!q){const Z=Or.new(u);Z.parent=U.toReference(),Z.id=N.UUID.uuid(),q=ae(Z,d.project),q.hydrateAncestors(),q.setParent(U,u),q.addSelfToProject(u),q.initChildren(u),u==null||u.add(q,k.Added)}}}}),{self:d,updated:C(i),added:C(a),removed:C(l),affected:C(f)}}function B0(d,u,i,a){const l=a||N.UUID.uuid(),f=N.UUID.uuid(),e={id:l,version:f,createdAt:(i==null?void 0:i.timestamp)||new Date().toISOString(),author:N.sessionAuthor,previousVersion:null,deleted:!1,name:u,deletable:!0,editable:!0,type:p.DefinitionEntity,allPropertiesImplement:null,additionalProperties:!1,additionalPropertiesDataType:null,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()};eH(d,i);const y=ae(e,d.project);return y.hydrateAncestors(),i==null||i.add(y,k.Added),y.addSelfToProject(i),y.addImplementation(d,i),y.setParent(d.project,i),y.initChildren(i),tH(y,i),y}function Bw(d,u){return u.entities.find(l=>{const f=l.properties,e=f.map(b=>b.name),y=d.every(b=>e.includes(b)),v=e.filter(b=>!d.includes(b)),T=f.every(b=>!v.includes(b.name)||!b.required);return y&&T})||null}function iH(d,u,i,a=Ar.OrDataTypeGroup){const l=[],f=[],e=[],y=[],T={id:N.UUID.uuid(),version:N.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||new Date().toISOString(),author:N.sessionAuthor,previousVersion:null,deleted:!1,deletable:!0,editable:!0,type:p.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()},A=ae(T,d.project);return f.push(A),A.setParent(u,i),A.initChildren(i),i==null||i.add(A,k.Added),A.setEntity(d,i),A.addSelfToProject(i),{updated:C(l),added:C(f),removed:C(e),affected:C(y),self:A}}function Mw(d,u,i,a,l){var T,A,b,O,L,M,U,q;const f=[],e=[],y=[],v=[];switch(typeof d){case"string":let Z=!1;const H=new Date(d);if(H instanceof Date&&!isNaN(H.valueOf())&&(Z=!0),Z){const z=u.project.getBuiltIn(ce[p.PrimitiveEntity][re.Date].id);u.setEntity(z,a);break}else{const z=u.project.getBuiltIn(ce[p.PrimitiveEntity][re.String].id);u.setEntity(z,a);break}case"number":u.setEntity(u.project.getBuiltIn(ce[p.PrimitiveEntity][re.Number].id),a);break;case"boolean":u.setEntity(u.project.getBuiltIn(ce[p.PrimitiveEntity][re.Boolean].id),a);break;case"object":if(d===null){u.setEntity(u.project.getBuiltIn(ce[p.PrimitiveEntity][re.Null].id),a);break}else if(Array.isArray(d))if(u.metaSync({isList:!0},a),d.length>0){const z=d.slice(0,5).filter(ie=>ie!==void 0);if(z.every(ie=>typeof ie==typeof z[0])&&(typeof z[0]!="object"||z[0]===null))switch(typeof z[0]){case"string":u.setEntity(u.project.getBuiltIn(ce[p.PrimitiveEntity][re.String].id),a);break;case"number":u.setEntity(u.project.getBuiltIn(ce[p.PrimitiveEntity][re.Number].id),a);break;case"boolean":u.setEntity(u.project.getBuiltIn(ce[p.PrimitiveEntity][re.Boolean].id),a);break;case"object":u.setEntity(u.project.getBuiltIn(ce[p.PrimitiveEntity][re.Null].id),a);break}else{const ie=[];let ne=!1;z.forEach(fe=>{var me,Y,ye,Ee;if(Array.isArray(fe)&&(ne=!0),typeof fe=="object"&&!Array.isArray(fe)&&fe!==null){const ge=M0(fe,u.project,{...i,id:N.UUID.uuid()},a,l);ge.hasCreated&&ie.push((me=ge.changeSet)==null?void 0:me.self),f.push(...(Y=ge.changeSet)==null?void 0:Y.updated),e.push(...(ye=ge.changeSet)==null?void 0:ye.added),y.push(...(Ee=ge.changeSet)==null?void 0:Ee.removed)}});const te=C(ie);if(!te.length&&!ne){z.forEach(fe=>{const me={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,deletable:!0,editable:!0,type:p.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:Ar.OrDataTypeGroup,parent:u.toReference()},Y=ae(me,u.project);switch(Y.setParent(u,a),Y.initChildren(a),a==null||a.add(Y,k.Added),Y.addSelfToProject(a),typeof fe){case"string":Y.setEntity(Y.project.getBuiltIn(ce[p.PrimitiveEntity][re.String].id),a);break;case"number":Y.setEntity(Y.project.getBuiltIn(ce[p.PrimitiveEntity][re.Number].id),a);break;case"boolean":Y.setEntity(Y.project.getBuiltIn(ce[p.PrimitiveEntity][re.Boolean].id),a);break;case"object":Y.setEntity(Y.project.getBuiltIn(ce[p.PrimitiveEntity][re.Null].id),a);break}});break}else te.length===1&&!ne?u.setEntity(te[0],a):z.forEach(fe=>{if(typeof fe=="object"&&!Array.isArray(fe)&&fe!==null){const me=Bw(Object.keys(fe),u.project);if(me){const Y=iH(me||te[0],u,a,Ar.OrDataTypeGroup);f.push(...Y.updated),e.push(...Y.added),y.push(...Y.removed)}}else{const me={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,deletable:!0,editable:!0,type:p.DataType,options:null,implementationChooseOne:!1,entity:null,isList:Array.isArray(fe),asType:!1,andChildrenGroup:null,index:null,orChildrenGroup:null,staticEntities:!1,interactiveEntities:!0,actionEntities:!1,like:!0,inferred:!1,parentRelationType:Ar.OrDataTypeGroup,parent:u.toReference()},Y=ae(me,u.project);Y.setParent(u,a),Y.initChildren(a),a==null||a.add(Y,k.Added),Y.addSelfToProject(a);const ye=Mw(fe,Y,{...i,id:N.UUID.uuid()},a,l);f.push(...ye.updated),e.push(...ye.added),y.push(...ye.removed)}})}}else{const z=M0(d[0],u.project,{...i},a,l);u.setEntity((T=z.changeSet)==null?void 0:T.self,a),f.push(...(A=z.changeSet)==null?void 0:A.updated),e.push(...(b=z.changeSet)==null?void 0:b.added),y.push(...(O=z.changeSet)==null?void 0:O.removed);break}else{const z=M0(d,u.project,{...i},a,l);u.setEntity((L=z.changeSet)==null?void 0:L.self,a),f.push(...(M=z.changeSet)==null?void 0:M.updated),e.push(...(U=z.changeSet)==null?void 0:U.added),y.push(...(q=z.changeSet)==null?void 0:q.removed);break}}return{updated:C(f),added:C(e),removed:C(y),affected:C(v),self:u}}function M0(d,u,i,a,l){const f=[],e=[],y=[],v=[],T=Object.keys(d),A=Bw(T,u);if(A)return{hasCreated:!1,changeSet:{updated:[],added:[],removed:[],affected:[],self:A}};const b=l?i.name+" of "+l.name:i.name,L={id:i.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:b,codeName:null,deletable:!0,editable:!0,type:p.DefinitionEntity,additionalProperties:!1,additionalPropertiesDataType:null,allPropertiesImplement:null,description:i.description||null,static:i.static||!1,abstract:i.abstract||!1,properties:[],methods:[],abstractMethods:[],extends:null,implements:[],x:0,y:0,parent:u.toReference()},M=ae(L,u);return M.setParent(u,a),M.initChildren(a),a==null||a.add(M,k.Added),M.addSelfToProject(a),e.push(M),T.forEach((U,q)=>{const H={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:U,deletable:!0,editable:!0,type:p.Property,parentRelationType:null,codeName:U,description:null,static:!1,abstract:!1,defaultValue:null,constant:!1,interactive:!0,dataType:null,implements:[],extends:null,index:q,hidden:!1,private:!1,required:!0,parent:M.toReference()},z=ae(H,u);z.setParent(M,a),z.initChildren(a),a==null||a.add(z,k.Added),z.addSelfToProject(a),e.push(z);const oe=d[U],ne={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,deletable:!0,editable:!0,type:p.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:z.toReference()},te=ae(ne,u);te.setParent(z,a),te.initChildren(a),a==null||a.add(te,k.Added),te.addSelfToProject(a),e.push(te);const fe=Mw(oe,te,{...i,name:U,id:N.UUID.uuid()},a,l||M);f.push(...fe.updated),e.push(...fe.added),y.push(...fe.removed)}),{hasCreated:!0,changeSet:{updated:C(f),added:C(e),removed:C(y),affected:C(v),self:M}}}function vl(d,u,i,a){const l=[];return!d.length||!u.length?{errors:l,overlap:!1}:(d.length>u.length?d.forEach(f=>{const e=u.find(v=>v.name===f.name),y=u.find(v=>{var T,A;return Array.isArray(v.implements)?v.implements.some(b=>!!f.implements.find(O=>O.id===b.id)):((T=v.implements)==null?void 0:T.id)===((A=f.implements)==null?void 0:A.id)});if(e){const v=new vi({id:f.id+"--"+e.id+"--"+a,message:`Entity of type ${f.type} named "${f.name}" with id "${f.id}" overrides a base ${e.type} ${e.name} with id "${e.id}" that has the same name`,severity:Q.Error,code:a,entity:f,firstRelationship:e});l.push(v)}if(y){const v=new vi({id:f.id+"--"+y.id+"--"+i,message:`Entity of type ${f.type} named "${f.name}" with id "${f.id}" overrides a base ${y.type} ${y.name} with id "${y.id}" that implements the same base descriptor`,severity:Q.Error,code:i,entity:f,firstRelationship:y});l.push(v)}}):u.forEach(f=>{var v;const e=d.find(T=>T.name===f.name),y=d.find(T=>{var A,b;return T.implements&&Array.isArray(T.implements)?T.implements.some(O=>!!f.implements.find(L=>L.id===O.id)):((A=T.implements)==null?void 0:A.id)===((b=f.implements)==null?void 0:b.id)});if(e){const T=new vi({id:e.id+"--"+f.id+"--"+a,message:`Entity of type ${e.type} named "${e.name}" with id "${e.id}" overrides a base entity ${f.name} with id "${f.id}" that has the same name`,severity:Q.Error,code:a,entity:e,firstRelationship:f});l.push(T)}if(y){const T=new vi({id:y.id+"--"+f.id+"--"+i,message:`Entity of type ${y.type} named "${y.name}" with id "${y.id}" overrides a base entity ${f.name} with id "${f.id}" that implements the same base ${Array.isArray(y==null?void 0:y.implements)?yt(y==null?void 0:y.implements.map(A=>A.type),"', '","' and '"):(v=y.implements)==null?void 0:v.id}`,severity:Q.Error,code:i,entity:y,firstRelationship:f});l.push(T)}}),{errors:l,overlap:!!l.length})}function k$e(d,u){return d.abstract||(d.properties.forEach(a=>{a.abstract||a.metaSync({abstract:!0},u)}),Object.values(d.detachedDependents).forEach(a=>{a.field===tA.Entity&&a.entity.remove({ignoreUpstream:!1},u)}),d.metaSync({abstract:!0},u)),d}function F$e(d,u){return d.abstract&&(d.properties.forEach(a=>{a.abstract&&a.metaSync({abstract:!1},u)}),Object.values(d.detachedDependents).forEach(a=>{(a.field===ev.Implements||a.field===ev.Extends)&&a.entity.onDetachedDependencyRemoved(d,a.field,u)}),d.metaSync({abstract:!1},u)),d}function K$e(d,u){return d.static||(d.properties.forEach(a=>{a.static||a.metaSync({static:!0},u)}),d.metaSync({static:!0},u)),d}function q$e(d,u){return d.static&&d.metaSync({static:!1},u),d}var hn=(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))(hn||{});function xw(d,u){const i=[],a=u;if(!a)return{errors:i,override:u};if(typeof a!="string")return{errors:[],override:u};if(a.includes(" ")){const l=new vi({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:Q.Error,code:"string-value-must-not-have-spaces",entity:d});i.push(l)}return{errors:i,override:a.replace(/\s/g,"-")}}function rH(d,u){const i=[],a=u;if(!a)return{errors:i,override:u};if(typeof a!="string")return{errors:[],override:u};if(a.includes(" ")){const l=new vi({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:Q.Error,code:"string-value-must-not-have-spaces",entity:d});i.push(l)}if(a.includes("-")){const l=new vi({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:Q.Error,code:"string-value-must-not-have-dashes",entity:d});i.push(l)}return{errors:i,override:a.replace(/\s|-/g,"_")}}function Uw(d,u){var i;if(d.type===p.LiteralValue){let a=(i=d.value)==null?void 0:i.toString();try{a=JSON.stringify(d.value,null,2)}catch{}return`${d.type}: ${d.id} (${S(d,u)}) = ${a}`}if(d.type===p.DataType){if(d instanceof Zr||d.increaseVersion)return`${d.type}: ${d.id} (${cp(d)})`;try{const a=cp(d);return`${d.type}: ${d.id} (${a})`}catch{}}return`${d.type}: ${d.id} (${S(d,u)})`}function ip(d,u){const i=Io(d);if(i.length===0)return{list:[],last:null};let a=null;return{list:i.flatMap(f=>{if(f===u)return a=f,[f];const e=ip(f,u);return e.last&&(a=e.last),[f,...e.list]}),last:a}}function bo(d,u){const i=d.calledBy;if(i.length===0)return{list:[],last:null,callType:null};let a=null,l=null;return{list:i.flatMap(e=>{if(e===u)return a=e,jt.includes(e.type)?e.parent.type===p.Loop?l="loop-body":l="entry":e.successCalls.includes(d)?l="success":e.errorCalls.includes(d)&&(l="error"),[e];if(e.type===p.FunctionDeclaration&&e.parent.type===p.Loop&&e.parent===u)return a=e.parent,l="loop-body",[e];if(!en.includes(e.type))return[e];const y=bo(e,u);return y.last&&(a=y.last,l=y.callType),[e,...y.list]}),last:a,callType:l}}function Z$e(d,u){if(d===u)return"same-entity";if(!jr.includes(d.type)||!oy(d).find(l=>l.callee===u))return null;if(jt.includes(d.type)){if(d.calls.includes(u))return d.type===p.Loop?"loop-body":"entry"}else if(mi.includes(d.type)&&d.type!==p.InternalCall){if(d.successCalls.includes(u))return"success";if(d.errorCalls.includes(u))return"error"}return null}function ay(d){const u=Yr(d,d.project);return u?jt.includes(u.type)?u:u.type===p.Loop?u.body:null:null}function jw(d,u){const i=d.calledBy;return!i||!i.length?!1:i.every(a=>a===u?!0:en.includes(a.type)?!!bo(a,u).last:!1)}function nH(d){return d.filter(u=>{const i=ay(u);return!d.filter(f=>f!==u).some(f=>f===i?!1:j0(f,u))})}function Gw(d){if(!d.calledBy||!d.calledBy.length)return[];const u=d.calledBy.reduce((i,a)=>{if(en.includes(a.type)){const l=Gw(a);return[...i,a,...l]}return i},[]);return C(u)}function sH(d){const u=Gw(d);if(!u.length)return{ancestor:null,callType:null};const a=u.filter(f=>!(f===d||!jr.includes(f.type)||!ht(f).find(v=>v===d))).filter((f,e,y)=>y.findIndex(v=>v===f)===e).filter(f=>jw(d,f)),l=a.filter(f=>{const e=ht(f),y=a.filter(T=>T!==f).map(T=>T);return!e.some(T=>!!y.find(b=>b===T))});if(l.length===0)return{ancestor:null,callType:null};if(l.length===1){const f=l[0];if(f.type===p.Loop){if(f.body.calls.includes(d))return{ancestor:f,callType:"loop-body"}}else if(jt.includes(f.type)){if(f.calls.includes(d))return f.type===p.FunctionDeclaration&&f.parent.type===p.Loop?{ancestor:f,callType:"loop-body"}:{ancestor:f,callType:"entry"}}else if(mi.includes(f.type)){if(f.successCalls.includes(d))return{ancestor:f,callType:"success"};if(f.errorCalls.includes(d))return{ancestor:f,callType:"error"}}}if(l.length>1)throw new Error(`resolveEarliestSingleCallerAncestor: Multiple callers found for entity ${d.id}.`);return{ancestor:l[0],callType:null}}function aH(d,u){if(!d)throw new Error("findNextSingleCallerAncestor: Target is not defined, cannot find ancestor.");let i=d;(d.type===p.VariableDeclaration||d.type===p.VariableInstance)&&!d.calledBy.length&&!d.successCalls.length&&!d.errorCalls.length&&d.internalCalls.some(O=>!!O.calledBy.length)&&(i=d.internalCalls.find(L=>!!L.calledBy.length));let a=u||Yr(i,d.project);if(!a)return{ancestor:null,callType:null};if(a.type===p.Project&&(a=sH(i).ancestor,!a))return{ancestor:null,callType:null};const l=oy(a);if(!l.find(O=>O.callee===i))return{ancestor:null,callType:null};if(a.type===p.Loop){if(a.body.calls.includes(i))return{ancestor:a,callType:"loop-body"}}else if(jt.includes(a.type)){if(a.calls.includes(i))return a.type===p.FunctionDeclaration&&a.parent.type===p.Loop?{ancestor:a,callType:"loop-body"}:{ancestor:a,callType:"entry"}}else if(mi.includes(a.type)){if(a.successCalls.includes(i))return{ancestor:a,callType:"success"};if(a.errorCalls.includes(i))return{ancestor:a,callType:"error"}}const e=l.filter(O=>!(O.callee===i||!jr.includes(O.callee.type)||!ht(O.callee).find(U=>U===i))).filter((O,L,M)=>M.findIndex(U=>U.callee===O.callee)===L);if(e.length===0)return{ancestor:null,callType:null};if(e.length===1){const O=e[0];if(O.callee.type===p.Loop){if(O.callee.body.calls.includes(i))return{ancestor:O.callee,callType:"loop-body"}}else{if(jt.includes(O.callee.type))return O.callee.type===p.FunctionDeclaration&&O.callee.parent.type===p.Loop?{ancestor:O.callee,callType:"loop-body"}:{ancestor:O.callee,callType:"entry"};if(mi.includes(O.callee.type)){if(O.callType==="success"&&O.callee.type===p.InternalCall)return{ancestor:O.callee,callType:"success"};if(O.callType==="error"&&O.callee.type===p.InternalCall)return{ancestor:O.callee,callType:"error"}}}}const y=e.filter(O=>jw(i,O.callee)),v=y.filter(O=>{const L=ht(O.callee),M=y.filter(q=>q.callee!==O.callee).map(q=>q.callee);return!L.some(q=>!!M.find(H=>H===q))});if(v.length===0){if(a.type===p.Loop){if(ht(a.body).find(H=>H===i))return{ancestor:a,callType:"loop-body"};if(Tr(a.successCalls).find(H=>H===i))return{ancestor:a,callType:"success"};if(Tr(a.errorCalls).find(H=>H===i))return{ancestor:a,callType:"error"}}else if(mi.includes(a.type)){if(Tr(a.successCalls).find(q=>q===i))return{ancestor:a,callType:"success"};if(Tr(a.errorCalls).find(q=>q===i))return{ancestor:a,callType:"error"}}return a.parent.type===p.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(O=>S(O.callee,i.project)).join(", ")}`);const T=v[0].callee,b=oy(T).find(O=>O.callee===i);return{ancestor:T,callType:b.callType}}function W$e(d){if(![p.VariableDeclaration,p.OutputMap].includes(d.type))throw new Error("getEarliestSingleCallerAncestorOfValueWriterAndItsValueReaders can only be used with a value writer entity");let u;if(d.type===p.VariableDeclaration?u=d:d.type===p.OutputMap&&(u=d.parent),!u)throw new Error("getEarliestSingleCallerAncestorOfValueWriterAndItsValueReaders can only be used with a value writer entity that has a caller");const i=C([d,...x0(d),...$t.includes(d.type)?d.outputs.flatMap(y=>x0(y)):[]]),a=C(i.map(y=>kw(y)).flatMap(y=>Gt.includes(y==null?void 0:y.type)?y.calledBy:[y]));if(a.length===1){const y=a[0];if(jt.includes(y.type))return y.parent.type===p.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: ${S(y,u.project)}`)}const l=a.map(y=>{var T;if(jt.includes(y.type))return y.parent.type===p.Loop?{ancestor:y,callType:"loop-body"}:{ancestor:y,callType:"entry"};if(y.parent===d.project&&!((T=u.calledBy)!=null&&T.length)){if(y===u)return{ancestor:y,callType:"success"};const A=Tr(y.successCalls),b=Tr(y.errorCalls);if(A.includes(u))return{ancestor:y,callType:"success"};if(b.includes(u))return{ancestor:y,callType:"error"}}const v=aH(y);if(!v.ancestor)throw new Error(`getEarliestSingleCallerAncestorOfValueWriterAndItsValueReaders: Could not be resolved, no ancestor found for ${S(y,u.project)}`);return v}).filter((y,v,T)=>v===T.findIndex(A=>{var b,O;return((b=A.ancestor)==null?void 0:b.id)===((O=y.ancestor)==null?void 0:O.id)})),f=ay(u),e=l.filter(y=>y!=null&&y.ancestor?f===y.ancestor?!0:!l.filter(A=>A.ancestor!==y.ancestor).map(A=>A.ancestor).some(A=>{const b=bo(y.ancestor,A);return!!(b!=null&&b.last)}):!1);if(e.length===0)return{ancestor:f,callType:(f==null?void 0:f.parent.type)===p.Loop?"loop-body":"entry"};if(e.length>1)throw new Error(`getEarliestSingleCallerAncestorOfValueWriterAndItsValueReaders: Could not be resolved, multiple candidates found: ${e.map(y=>S(y.ancestor,u.project)).join(", ")}`);return{ancestor:e[0].ancestor,callType:e[0].callType}}function lH(d,u){if(d===u)return!0;if(ht(d).includes(u)||!ht(u).includes(d))return!1;const l=d.calledBy;return l.length===0?!1:l.length===1?l[0]===u:nH(l).length>1&&l.includes(u)?!1:l.every(e=>d===u?!0:jt.includes(e.type)?!1:lH(e,u))}function oH(d){const u=[];let i=d.calledBySuccess;i=i.filter(l=>!i.filter(y=>y!==l).some(y=>j0(y,l)));let a=d.calledByError;a=a.filter(l=>!a.filter(y=>y!==l).some(y=>j0(y,l)));for(const l of i)u.push({ancestor:l,callType:"success"});for(const l of a)u.push({ancestor:l,callType:"error"});return u}function dH(d){const u=[];return oH(d).forEach(a=>{a.ancestor.type===p.Condition&&u.push({condition:a.ancestor,call:d,callType:a.callType});const f=dH(a.ancestor).filter(e=>!u.some(y=>y.condition.id===e.condition.id));u.push(...f)}),u}function kw(d){if(!d)return null;if(d.type===p.Condition&&d.parent.type===p.Condition)return G0(d.parent);if(zT.includes(d.type))return d;const u=d.parent;return u?kw(u):null}function x0(d,u=new Set){return d.writesValues.reduce((i,a)=>u.has(a.id)?i:(u.add(a.id),Xn.includes(a.type)?[...i,a]:Qi.includes(a.type)?[...i,a,...x0(a,u)]:i),[])}function ly(d){const u=d.calledBy;if(u.length===0)return d.project;const i=u.reduce((a,l)=>{const f=Yr(l,d.project);return!f||f.type===p.Project?a:a.type===p.Project||ip(f,a).last?f:(ip(a,f).last,a)},d.project);return i.type===p.FunctionDeclaration&&i.parent.type===p.Loop?i.parent:i}function et(d,u){let i=ly(d);if(d.type===p.InternalCall)if(d.parent.type===p.VariableInstance){const l=gs(i,d.parent.declaration,d.project);!l.compatible&&l.type!=="b-is-global-a-is-not"?d.parent.remove({ignoreUpstream:!1},u):(d.parent.setParent(i,u),d.parent.addSelfToProject(u))}else d.parent.setParent(i,u),d.parent.addSelfToProject(u);else if((d.type===p.ContinueStatement||d.type===p.BreakStatement)&&i.type!==p.Loop){d.remove({ignoreUpstream:!1},u);return}else if(d.type===p.ReturnStatement&&!Xi.includes(i.type)){d.remove({ignoreUpstream:!1},u);return}else if($t.includes(d.type)){const l=d.usedInternalCalls[0];if(l)if(i=ly(l),d.type===p.VariableInstance){const f=gs(i,d.declaration,d.project);!f.compatible&&f.type!=="b-is-global-a-is-not"?d.remove({ignoreUpstream:!1},u):(d.setParent(i,u),d.addSelfToProject(u))}else d.setParent(i,u),d.addSelfToProject(u);else if(d.type===p.VariableInstance){const f=gs(i,d.declaration,d.project);!f.compatible&&f.type!=="b-is-global-a-is-not"?d.remove({ignoreUpstream:!1},u):(d.setParent(i,u),d.addSelfToProject(u))}else d.setParent(i,u),d.addSelfToProject(u)}else d.setParent(i,u),d.addSelfToProject(u);if(Gt.includes(d.type))return;ht(d).forEach(l=>{let f=ly(l);if(l.type===p.InternalCall)if(l.parent.type===p.VariableInstance){const e=gs(f,l.parent.declaration,d.project);!e.compatible&&e.type!=="b-is-global-a-is-not"?l.parent.remove({ignoreUpstream:!1},u):(l.parent.setParent(f,u),l.parent.addSelfToProject(u))}else l.parent.setParent(f,u),l.parent.addSelfToProject(u);else if((l.type===p.ContinueStatement||l.type===p.BreakStatement)&&f.type!==p.Loop){l.remove({ignoreUpstream:!1},u);return}else if(l.type===p.ReturnStatement&&!Xi.includes(f.type)){l.remove({ignoreUpstream:!1},u);return}else if($t.includes(l.type)){const e=l.usedInternalCalls[0];if(e)if(f=ly(e),l.type===p.VariableInstance){const y=gs(f,l.declaration,d.project);!y.compatible&&y.type!=="b-is-global-a-is-not"?l.remove({ignoreUpstream:!1},u):(l.setParent(f,u),l.addSelfToProject(u))}else l.setParent(f,u),l.addSelfToProject(u);else if(l.type===p.VariableInstance){const y=gs(f,l.declaration,d.project);!y.compatible&&y.type!=="b-is-global-a-is-not"?l.remove({ignoreUpstream:!1},u):(l.setParent(f,u),l.addSelfToProject(u))}else l.setParent(f,u),l.addSelfToProject(u)}else l.setParent(f,u),l.addSelfToProject(u)})}function U0(d,u,i=new Set){const a=ta(d),l=ta(u),f=a.filter(v=>!l.includes(v)),e=a.filter(v=>l.includes(v)),y=f.reduce((v,T)=>i.has(T.id)?v:(i.add(T.id),C([...v,...U0(T,u,i)])),[]);return C([...e,...y])}function Cd(d,u){const i=ip(d,u);return i.last===u&&i.list.length>0&&i.list[0]!==u}function Fw(d,u){return!!ip(d,u).last}function j0(d,u){return!!bo(d,u).last}function Kw(d,u){if(!d||!u)throw new Error("Both entities must be defined to find a common ancestor");if(d===u)return d;const i=d.parent;if(i){if(i===u)return u;if(i.type===p.Project)return null}else return null;const a=u.parent;if(a){if(a===d)return d;if(a.type===p.Project)return null}else return null;return Kw(i,a)}function H$e(d,u,i=!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(en.includes(d.type)&&jr.includes(u.type)){const y=bo(d,u),v=y.last;if(v){if(v===u)return{ancestor:u,callType:y.callType}}else return{ancestor:null,callType:null}}if(en.includes(u.type)&&jr.includes(d.type)){const y=bo(u,d),v=y.last;if(v){if(v===d)return{ancestor:d,callType:y.callType}}else return{ancestor:null,callType:null}}const a=ay(d),l=ay(u);if(!a||!l)return{ancestor:null,callType:null};if(a!==l)return{ancestor:null,callType:null};if(a.calls.includes(d)||a.calls.includes(u))return{ancestor:a,callType:"entry"};const f=a.calls.reduce((y,v)=>{if(!jr.includes(v.type))return y;const T=oy(v),A=T.find(O=>O.callee===d),b=T.find(O=>O.callee===u);return A&&b&&(!i||A.callType===b.callType)?[...y,{ancestor:v,callType:A.callType}]:y},[]);if(f.length===0)return{ancestor:null,callType:null};if(f.length===1)return{ancestor:f[0].ancestor,callType:f[0].callType};const e=f.filter(y=>!f.some(v=>v.ancestor!==y.ancestor&&bo(y.ancestor,v.ancestor).last===v.ancestor));return e.length===1?{ancestor:e[0].ancestor,callType:e[0].callType}:{ancestor:a,callType:"entry"}}function Ni(d){if(rc.includes(d.type)){if(d.type===p.FunctionDeclaration){const u=d.parent;if(u.type===p.DefinitionEntity)return Ni(u);if(u.type===p.Loop)return u}return d.type===p.DefinitionEntity&&d.parent.type===p.DataType||d.type===p.Condition&&d.parent.type===p.Condition?Ni(d.parent):d}else{const u=d.parent;return u?Ni(u):null}}function rp(d,u){const i=np(d,u);if(!i)return null;if(rc.includes(i.type)){if(i.type===p.FunctionDeclaration){const a=np(i.parent,u);if(a){if(a.type===p.DefinitionEntity)return a;if(a.type===p.Loop)return a}}if(i.parent){const a=np(i.parent,u);if(a&&(i.type===p.DefinitionEntity&&a.type===p.DataType||i.type===p.Condition&&a.type===p.Condition))return rp(a,u)}return i}else{const a=i.parent?np(i.parent,u):null;return a?rp(a,u):null}}function oy(d){if(d.type===p.Loop){const u=[...Tr(d.successCalls).map(l=>({callee:l,callType:"success"})),...Tr(d.errorCalls).map(l=>({callee:l,callType:"error"})),...(d.body?ht(d.body):[]).map(l=>({callee:l,callType:"loop-body"}))];return C(u.map(l=>l.callee)).map(l=>{var e;const f=(e=u.find(y=>y.callee===l))==null?void 0:e.callType;return{callee:l,callType:f}})}if(mi.includes(d.type)){const u=[...Tr(d.successCalls).map(l=>({callee:l,callType:"success"})),...Tr(d.errorCalls).map(l=>({callee:l,callType:"error"}))];return C(u.map(l=>l.callee)).map(l=>{var e;const f=(e=u.find(y=>y.callee===l))==null?void 0:e.callType;return{callee:l,callType:f}})}if(jt.includes(d.type)){const u=[...Tr(d.calls).map(l=>d.parent.type===p.Loop?{callee:l,callType:"loop-body"}:{callee:l,callType:"entry"})];return C(u.map(l=>l.callee)).map(l=>{var e;const f=(e=u.find(y=>y.callee===l))==null?void 0:e.callType;return{callee:l,callType:f}})}return[]}function G0(d){if(!d)return null;if(d.type===p.Condition&&d.parent.type===p.Condition)return G0(d.parent);if(en.includes(d.type))return d;const u=d.parent;return u?G0(u):null}function uH(d){if(!d)return null;if(mi.includes(d.type))return d;const u=d.parent;return u?uH(u):null}function pH(d){if(!d)return null;if(jr.includes(d.type))return d;const u=d.parent;return u?pH(u):null}function J$e(d){return d.type===p.VariableDeclaration?[d]:mi.includes(d.type)?[...d.inputs,...d.outputs||[]]:Gt.includes(d.type)?d.outputs:ko.includes(d.type)||d.type===p.FunctionDeclaration?d.inputs:[]}function z$e(d){const u=ta(d),i=[],a=[];gg.includes(d.type)&&i.push(...k0(d));const l=u.filter(f=>{const e=i.includes(f);return e?!1:en.includes(f.type)&&!e?(a.push(f),!1):!0});return i.sort((f,e)=>Cd(e,f)?-1:0),a.sort((f,e)=>Cd(e,f)?-1:0),[...i,...a,...l]}function cH(d){return[...d].sort((u,i)=>Cd(i,u)?-1:0)}function S$e(d){const u=cH(d),i=[];return u.forEach(a=>{const l=i[i.length-1];if(l){const f=l[l.length-1];Cd(a,f)?i.push([a]):l.push(a)}else i.push([a])}),i}function Tl(d){const u=d.map(i=>Ni(i));return C(u)}function k0(d){return mi.includes(d.type)?[...Tl(d.successCalls),...Tl(d.errorCalls)]:jt.includes(d.type)?Tl(d.calls):[]}function Y$e(d,u){return k0(d).includes(u)}function F0(d){return d.writesValues||[]}function X$e(d,u){return F0(d).includes(u)}function fH(d){var u;return $t.includes((u=d==null?void 0:d.readsValue)==null?void 0:u.type)?d.readsValue:null}function Q$e(d){return d.writesValues}function yH(d=[]){return d.map(fH).filter(u=>!!u)}function K0(d=[]){return d.map(u=>u.writesValues).flat().filter(u=>$t.includes(u.type))}function hH(d=[]){return d.map(u=>u.readsValue).filter(u=>!!u&&$t.includes(u.type))}function mH(d){return $t.includes(d.type)?d:null}function vH(d){return d.writesValues.map(mH).filter(u=>!!u)}function TH(d=[]){return d.reduce((u,i)=>i.type===p.OutputMap?[...u,...vH(i)]:u,[])}function ht(d){return d.type===p.Loop?C([...Tr(d.successCalls),...Tr(d.errorCalls),...d.body?ht(d.body):[]]):mi.includes(d.type)?C([...Tr(d.successCalls),...Tr(d.errorCalls)]):jt.includes(d.type)?C(Tr(d.calls)):[]}function eVe(d){return mi.includes(d.type)?[...Tr(d.successCalls),...Tr(d.errorCalls)]:jt.includes(d.type)?Tr(d.calls):[]}function EH(d,u=new Set){return d.writesValues.filter(a=>$t.includes(a.type)&&!u.has(a.id)).reduce((a,l)=>u.has(l.id)?a:[...a,...Li(l,u)],[])}function bH(d,u=new Set){var a;return(((a=d.readsValue)==null?void 0:a.writesValues)||[]).filter(l=>$t.includes(l.type)&&!u.has(l.id)).reduce((l,f)=>u.has(f.id)?l:[...l,...Li(f,u)],[])}function Li(d,u=new Set){if(u.has(d.id))return[];if(d.type===p.ReturnStatement)return hH(d.outputs).reduce((a,l)=>[...a,...Li(l,u)],[]);if(d.type===p.FunctionCall||d.type===p.Operation||d.type===p.Condition)return[...ht(d).reduce((f,e)=>{const y=Ni(e);return[...f,...Li(y||e,u)]},[]),...yH(d.inputs),...TH(d.outputs)].reduce((f,e)=>[...f,...Li(e,u)],[]);if(ko.includes(d.type)){const i=K0(d.inputs),l=ht(d).reduce((f,e)=>{const y=Ni(e);return[...f,...Li(y||e,u)]},[]);return i.push(...l),i.reduce((f,e)=>[...f,...Li(e,u)],[])}if(d.type===p.FunctionDeclaration){const i=[...K0(d.inputs)],l=ht(d).reduce((f,e)=>{const y=Ni(e);return[...f,...Li(y||e,u)]},[]);return i.push(...l),i.reduce((f,e)=>[...f,...Li(e)],[])}if($t.includes(d.type)){u.add(d.id);const a=ht(d).reduce((l,f)=>{const e=Ni(f);return[...l,...Li(e||f,u)]},[]);return[d,...a,...bH(d,u),...EH(d,u)]}return[]}function Fn(d,u=new Set){if(u.has(d.id))return[];u.add(d.id),J.log("[flattenDerivedCanvasEntities]",d.type,S(d,d.project),d.id);const i=ta(d);return i.forEach(l=>{u.add(l.id)}),[...i.reduce((l,f)=>(J.log("[Recursive -- flattenDerivedCanvasEntities]",f.type,S(f,f.project),f.id),[...l,f,...Fn(f,u)]),[])]}function Tr(d){return d.reduce((u,i)=>i.type===p.ReturnStatement||i.type===p.ContinueStatement||i.type===p.BreakStatement?[...u,i]:[...u,i,...ht(i)],[])}function IH(d){const u=d.entities||[],i=[...u,...d.functions||[],...d.events||[],...d.projects||[]],a=u.reduce((v,T)=>[...v,...T.properties],[]),l=u.reduce((v,T)=>[...v,...T.methods],[]),f=l.reduce((v,T)=>[...v,...K0(T.inputs),...Tr(Tl(T.calls)),...T.returnStatements],[]),e=d.functions.reduce((v,T)=>[...v,...Tr(Tl(T.calls)),...T.returnStatements],[]),y=d.events.reduce((v,T)=>[...v,...Tr(Tl(T.calls)),...T.returnStatements],[]);return[...i,...a,...l,...f,...e,...y]}function AH(d,u){return u.filter(a=>{if(!a)return!1;switch(a.type){case p.FunctionCall:return a.inputs.find(l=>l.id===d.id)!==void 0||a.outputs.find(l=>l.id===d.id)!==void 0;case p.Condition:return a.successCalls.find(l=>l.id===d.id)!==void 0||a.errorCalls.find(l=>l.id===d.id)!==void 0||a.inputs.find(l=>l.id===d.id)!==void 0;case p.Operation:return a.outputs.find(l=>l.id===d.id)!==void 0;case p.VariableDeclaration:return mi.includes(d.type)?SH(d).find(f=>{var e;return((e=f.readsValue)==null?void 0:e.id)===a.id})!==void 0:!1;case p.DefinitionEntity:return a.properties.find(l=>l.id===d.id)!==void 0||a.methods.find(l=>l.id===d.id)!==void 0;case p.FunctionDeclaration:return a.inputs.find(l=>l.id===d.id)!==void 0||(a.returnStatements.map(l=>l.outputs).flat()||[]).find(l=>l.id===d.id)!==void 0;default:return!1}})}function tVe(d){const u=IH(d.project);return AH(d,u)}function np(d,u){return d?typeof d=="string"?u[d]:d.type===p.GenericReference?u[d.entityId]:u[d.id]?u[d.id]:null:null}function wH(d={},u){const i={};return Object.keys(d).forEach(a=>{const l=u.get(a)||a,f=d[a];i[l]=f}),i}function sp(d,u={},i={}){const a={ignoreBuiltInBaseEntities:!1,allBuiltInEntityIds:[],entityMaps:new Map,...i};if(a.ignoreBuiltInBaseEntities&&(vn.includes(d.type)||(a.allBuiltInEntityIds||[]).includes(d.id)))return{upstream:{},downstream:{}};const l=d,f=d,e=d,y=d,v=d,T=d,A=d,b=d,O=d,L=d,M=d,U=d,q=d,Z=d,H=[...Z.readsValue?[Z.readsValue]:[],...Z.declaration?[Z.declaration]:[],...(q.calledByEntry||[]).flatMap(ne=>ne),...(q.calledBySuccess||[]).flatMap(ne=>ne),...(q.calledByError||[]).flatMap(ne=>ne),...M.parent?[M.parent]:[]];Array.isArray(e.implements)?H.push(...e.implements.flatMap(ne=>ne)):L.implements&&H.push(L.implements),Array.isArray(e.extends)?H.push(...e.extends.flatMap(ne=>ne)):O.extends&&H.push(O.extends),v.valueAsTypeList&&Array.isArray(v.valueAsTypeList)&&H.push(...v.valueAsTypeList.flatMap(ne=>ne)),v.valueAsTypeSingle&&H.push(v.valueAsTypeSingle),(Z.internalCalls||[]).forEach(ne=>{const te=ee(ne);if(te&&u[te]){const fe=u[te];[...fe.calledByEntry||[],...fe.calledBySuccess||[],...fe.calledByError||[]].forEach(me=>{const Y=ee(me);Y&&u[Y]&&H.push(u[Y])})}});const z=[...(l.inputs||[]).flatMap(ne=>ne),...(U.inputsDeclarations||[]).flatMap(ne=>ne),...(U.outputs||[]).flatMap(ne=>ne),...(Z.internalCalls||[]).flatMap(ne=>ne),...Z.writesValues||[],...q.dataType?[q.dataType]:[],...T.body?[T.body]:[],...q.defaultValue?[q.defaultValue]:[],...(q.successCalls||[]).flatMap(ne=>ne),...(q.errorCalls||[]).flatMap(ne=>ne),...(e.properties||[]).flatMap(ne=>ne),...(e.methods||[]).flatMap(ne=>ne),...(e.abstractMethods||[]).flatMap(ne=>ne),...A.error?[A.error]:[],...M.throws?[M.throws]:[],...(f.andChildrenGroup||[]).flatMap(ne=>ne),...(f.orChildrenGroup||[]).flatMap(ne=>ne),...(b.entities||[]).flatMap(ne=>ne),...(b.functions||[]).flatMap(ne=>ne),...(b.functionCalls||[]).flatMap(ne=>ne),...(b.events||[]).flatMap(ne=>ne),...(b.conditions||[]).flatMap(ne=>ne),...(b.operations||[]).flatMap(ne=>ne),...(b.loops||[]).flatMap(ne=>ne),...(b.variableDeclarations||[]).flatMap(ne=>ne),...(b.variableInstances||[]).flatMap(ne=>ne),...(b.searches||[]).flatMap(ne=>ne),...(b.projects||[]).flatMap(ne=>ne),...(y.calls||[]).flatMap(ne=>ne)];d.type===p.DataType&&(f.entity&&u[ee(f.entity)]&&u[ee(f.entity)].parent&&ee(u[ee(f.entity)].parent)===d.id?z.push(f.entity):f.entity&&H.push(f.entity)),(Z.internalCalls||[]).forEach(ne=>{const te=ee(ne);if(te&&u[te]){const fe=u[te];[...fe.successCalls||[],...fe.errorCalls||[]].forEach(me=>{const Y=ee(me);Y&&u[Y]&&z.push(u[Y])})}});const oe={},ie={};return H.forEach(ne=>{var me;const te=ee(ne);if(te&&a.ignoreBuiltInBaseEntities&&(vn.includes(ne.type)||(a.allBuiltInEntityIds||[]).includes(te)))return;const fe=ne.version;if(te){const Y=((me=a.entityMaps)==null?void 0:me.get(te))||te;oe[Y]=fe}}),z.forEach(ne=>{var me;const te=ee(ne);if(te&&a.ignoreBuiltInBaseEntities&&(vn.includes(ne.type)||(a.allBuiltInEntityIds||[]).includes(te)))return;const fe=ne.version;if(te){const Y=((me=a.entityMaps)==null?void 0:me.get(te))||te;ie[Y]=fe}}),{upstream:oe,downstream:ie}}function iVe(d,u){const i=[];if(en.includes(d.type)){ls(d).forEach(f=>{const e=rp(f,u);e&&i.push(e)});const l=[...d.inputs||[],...d.outputs||[]].map(f=>{const e=np(f,u);return e?YH(e,u):null}).filter(f=>f!==null);i.push(...C(l))}if($t.includes(d.type)){const a=q0(d);a&&i.push(a)}return C(i)}function Io(d){const u=[];if(en.includes(d.type)){d.calledBy.forEach(l=>{const f=Ni(l);f&&u.push(f)});const a=[...d.inputs||[],...d.outputs||[]].map(l=>q0(l)).filter(l=>l!==null);u.push(...C(a))}if(Xn.includes(d.type)){const i=q0(d);i&&u.push(i)}return C(u)}function ls(d){return[...d.calledByEntry||[],...d.calledByError||[],...d.calledBySuccess||[]].filter(u=>u.type!==p.GenericReference)}function RH(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==p.ActionDescriptor)throw new Error("Entity must be an action descriptor to be flattened");return[d,...d.inputs.flatMap(a=>Te(a,u,i)),...d.dataType?Te(d.dataType,u,i):[],...d.error?Te(d.error,u,i):[],...d.parent?Te(d.parent,u,i):[]]}function CH(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==p.ArgumentDeclaration)throw new Error("Entity must be an argument declaration to be flattened");return[d,...d.defaultValue?Te(d.defaultValue,u):[],...d.writesValues.flatMap(a=>Te(a,u,i)),...d.dataType?Te(d.dataType,u,i):[],...d.parent?Te(d.parent,u,i):[]]}function gH(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==p.BreakStatement)throw new Error("Entity must be a break statement to be flattened");return[d,...d.outputs.flatMap(a=>Te(a,u,i)),...d.throws?Te(d.throws,u,i):[],...d.implements?Te(d.implements,u,i):[],...d.dataType?Te(d.dataType,u,i):[],...d.readsValue?Te(d.readsValue,u,i):[],...(ls(d)||[]).flatMap(a=>Te(a,u,i)),...d.parent?Te(d.parent,u,i):[]]}function _H(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==p.BuiltInBaseEntity)throw new Error("Entity must be a built-in base entity to be flattened");return[d,...(d.properties||[]).flatMap(a=>Te(a,u,i)),...(d.methods||[]).flatMap(a=>Te(a,u,i)),...(d.abstractMethods||[]).flatMap(a=>Te(a,u,i)),...d.allPropertiesImplement?Te(d.allPropertiesImplement,u,i):[],...d.additionalPropertiesDataType?Te(d.additionalPropertiesDataType,u,i):[],...d.extends?Te(d.extends,u,i):[]]}function DH(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==p.Condition)throw new Error("Entity must be a condition to be flattened");return[d,...(d.andChildrenGroup||[]).flatMap(a=>Te(a,u,i)),...(d.orChildrenGroup||[]).flatMap(a=>Te(a,u,i)),...(d.inputs||[]).flatMap(a=>Te(a,u,i)),...(d.successCalls||[]).flatMap(a=>Te(a,u,i)),...(d.errorCalls||[]).flatMap(a=>Te(a,u,i)),...(ls(d)||[]).flatMap(a=>Te(a,u,i)),...d.parent?Te(d.parent,u,i):[]]}function OH(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==p.ContinueStatement)throw new Error("Entity must be a continue statement to be flattened");return[d,...d.outputs.flatMap(a=>Te(a,u,i)),...d.readsValue?Te(d.readsValue,u,i):[],...d.implements?Te(d.implements,u,i):[],...d.throws?Te(d.throws,u,i):[],...d.dataType?Te(d.dataType,u,i):[],...(ls(d)||[]).flatMap(a=>Te(a,u,i)),...d.parent?Te(d.parent,u,i):[]]}function PH(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==p.DefinitionEntity)throw new Error("Entity must be a definition entity to be flattened");return[d,...d.extends?Te(d.extends,u,i):[],...(d.implements||[]).flatMap(a=>Te(a,u,i)),...(d.properties||[]).flatMap(a=>Te(a,u,i)),...(d.methods||[]).flatMap(a=>Te(a,u,i)),...(d.abstractMethods||[]).flatMap(a=>Te(a,u,i)),...d.allPropertiesImplement?Te(d.allPropertiesImplement,u,i):[],...d.additionalPropertiesDataType?Te(d.additionalPropertiesDataType,u,i):[],...d.parent?Te(d.parent,u,i):[]]}function $H(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==p.DataType)throw new Error("Entity must be a data type to be flattened");return[d,...(d.andChildrenGroup||[]).flatMap(a=>Te(a,u,i)),...(d.orChildrenGroup||[]).flatMap(a=>Te(a,u,i)),...d.entity?Te(d.entity,u,i):[],...d.parent?Te(d.parent,u,i):[]]}function VH(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==p.FunctionCall)throw new Error("Entity must be a function call to be flattened");return[d,...(d.inputs||[]).flatMap(a=>Te(a,u,i)),...(d.outputs||[]).flatMap(a=>Te(a,u,i)),...d.error?Te(d.error,u,i):[],...(ls(d)||[]).flatMap(a=>Te(a,u,i)),...(d.successCalls||[]).flatMap(a=>Te(a,u,i)),...(d.errorCalls||[]).flatMap(a=>Te(a,u,i)),...(d.writesValues||[]).flatMap(a=>Te(a,u,i)),...d.parent?Te(d.parent,u,i):[]]}function NH(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==p.FunctionDeclaration)throw new Error("Entity must be a function declaration to be flattened");return[d,...(d.inputs||[]).flatMap(a=>Te(a,u,i)),...(d.calls||[]).flatMap(a=>Te(a,u,i)),...d.implements?Te(d.implements,u,i):[],...d.parent?Te(d.parent,u,i):[]]}function LH(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==p.GlobalEvent)throw new Error("Entity must be a global event to be flattened");return[d,...(d.inputs||[]).flatMap(a=>Te(a,u,i)),...(d.calls||[]).flatMap(a=>Te(a,u,i)),...d.implements?Te(d.implements,u,i):[],...d.parent?Te(d.parent,u,i):[]]}function BH(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==p.InputMap)throw new Error("Entity must be an input map to be flattened");return[d,...d.readsValue?Te(d.readsValue,u,i):[],...d.declaration?Te(d.declaration,u,i):[],...d.defaultValue?Te(d.defaultValue,u,i):[],...d.parent?Te(d.parent,u,i):[]]}function MH(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==p.InstalledProject)throw new Error("Entity must be an installed project to be flattened");return[d,...(d.functions||[]).flatMap(a=>Te(a,u,i)),...(d.events||[]).flatMap(a=>Te(a,u,i)),...d.parent?Te(d.parent,u,i):[]]}function xH(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==p.InternalCall)throw new Error("Entity must be an internal call to be flattened");return[d,...(d.successCalls||[]).flatMap(a=>Te(a,u,i)),...(d.errorCalls||[]).flatMap(a=>Te(a,u,i)),...(d.inputs||[]).flatMap(a=>Te(a,u,i)),...(d.outputs||[]).flatMap(a=>Te(a,u,i)),...(ls(d)||[]).flatMap(a=>Te(a,u,i)),...d.error?Te(d.error,u,i):[],...(d.writesValues||[]).flatMap(a=>Te(a,u,i)),...d.parent?Te(d.parent,u,i):[]]}function UH(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==p.LiteralValue)throw new Error("Entity must be a literal value to be flattened");return[d,...d.valueAsTypeSingle?Te(d.valueAsTypeSingle,u,i):[],...d.valueAsTypeList&&Array.isArray(d.valueAsTypeList)?d.valueAsTypeList.flatMap(a=>Te(a,u,i)):[],...d.parent?Te(d.parent,u,i):[]]}function jH(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==p.Loop)throw new Error("Entity must be a loop to be flattened");return[d,...(d.inputs||[]).flatMap(a=>Te(a,u,i)),...(d.outputs||[]).flatMap(a=>Te(a,u,i)),...(d.successCalls||[]).flatMap(a=>Te(a,u,i)),...(d.errorCalls||[]).flatMap(a=>Te(a,u,i)),...d.error?Te(d.error,u,i):[],...d.dataType?Te(d.dataType,u,i):[],...d.body?Te(d.body,u,i):[],...(ls(d)||[]).flatMap(a=>Te(a,u,i)),...(d.writesValues||[]).flatMap(a=>Te(a,u,i)),...d.parent?Te(d.parent,u,i):[]]}function GH(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==p.Operation)throw new Error("Entity must be an operation to be flattened");return[d,...(d.successCalls||[]).flatMap(a=>Te(a,u,i)),...(d.errorCalls||[]).flatMap(a=>Te(a,u,i)),...(d.inputs||[]).flatMap(a=>Te(a,u,i)),...(d.outputs||[]).flatMap(a=>Te(a,u,i)),...(d.writesValues||[]).flatMap(a=>Te(a,u,i)),...d.error?Te(d.error,u,i):[],...(ls(d)||[]).flatMap(a=>Te(a,u,i)),...d.parent?Te(d.parent,u,i):[]]}function kH(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==p.OutputMap)throw new Error("Entity must be an output map to be flattened");return[d,...(d.writesValues||[]).flatMap(a=>Te(a,u,i)),...d.declaration?Te(d.declaration,u,i):[],...d.parent?Te(d.parent,u,i):[]]}function FH(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==p.PrimitiveEntity)throw new Error("Entity must be a primitive entity to be flattened");return[d,...(d.properties||[]).flatMap(a=>Te(a,u,i)),...(d.methods||[]).flatMap(a=>Te(a,u,i)),...(d.abstractMethods||[]).flatMap(a=>Te(a,u,i))]}function KH(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==p.Project)throw new Error("Entity must be a project to be flattened");return[d,...(d.entities||[]).flatMap(a=>Te(a,u,i)),...(d.functions||[]).flatMap(a=>Te(a,u,i)),...(d.events||[]).flatMap(a=>Te(a,u,i)),...(d.projects||[]).flatMap(a=>Te(a,u,i)),...(d.variableDeclarations||[]).flatMap(a=>Te(a,u,i)),...(d.variableInstances||[]).flatMap(a=>Te(a,u,i)),...(d.operations||[]).flatMap(a=>Te(a,u,i)),...(d.conditions||[]).flatMap(a=>Te(a,u,i)),...(d.functionCalls||[]).flatMap(a=>Te(a,u,i)),...(d.projects||[]).flatMap(a=>Te(a,u,i)),...(d.loops||[]).flatMap(a=>Te(a,u,i)),...(d.searches||[]).flatMap(a=>Te(a,u,i))]}function qH(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==p.Property)throw new Error("Entity must be a property to be flattened");return[d,...d.defaultValue?Te(d.defaultValue,u,i):[],...d.dataType?Te(d.dataType,u,i):[],...d.parent?Te(d.parent,u,i):[]]}function ZH(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==p.ReturnStatement)throw new Error("Entity must be a return statement to be flattened");return[d,...(d.outputs||[]).flatMap(a=>Te(a,u,i)),...d.throws?Te(d.throws,u,i):[],...d.implements?Te(d.implements,u,i):[],...d.readsValue?Te(d.readsValue,u,i):[],...d.dataType?Te(d.dataType,u,i):[],...(ls(d)||[]).flatMap(a=>Te(a,u,i)),...d.parent?Te(d.parent,u,i):[]]}function WH(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==p.Search)throw new Error("Entity must be a search to be flattened");return[d,...(d.successCalls||[]).flatMap(a=>Te(a,u,i)),...(d.errorCalls||[]).flatMap(a=>Te(a,u,i)),...(d.inputsDeclarations||[]).flatMap(a=>Te(a,u,i)),...(d.inputs||[]).flatMap(a=>Te(a,u,i)),...(d.writesValues||[]).flatMap(a=>Te(a,u,i)),...(d.outputs||[]).flatMap(a=>Te(a,u,i)),...d.error?Te(d.error,u,i):[],...d.dataType?Te(d.dataType,u,i):[],...(ls(d)||[]).flatMap(a=>Te(a,u,i)),...d.parent?Te(d.parent,u,i):[]]}function HH(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==p.ValueDescriptor)throw new Error("Entity must be a value descriptor to be flattened");return[d,...d.defaultValue?Te(d.defaultValue,u,i):[],...d.dataType?Te(d.dataType,u,i):[],...d.parent?Te(d.parent,u,i):[]]}function JH(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==p.VariableDeclaration)throw new Error("Entity must be a variable declaration to be flattened");return[d,...(d.successCalls||[]).flatMap(a=>Te(a,u,i)),...(d.errorCalls||[]).flatMap(a=>Te(a,u,i)),...(d.inputs||[]).flatMap(a=>Te(a,u,i)),...(d.outputs||[]).flatMap(a=>Te(a,u,i)),...(d.internalCalls||[]).flatMap(a=>Te(a,u,i)),...(d.writesValues||[]).flatMap(a=>Te(a,u,i)),...d.readsValue?Te(d.readsValue,u,i):[],...d.defaultValue?Te(d.defaultValue,u,i):[],...(ls(d)||[]).flatMap(a=>Te(a,u,i)),...d.dataType?Te(d.dataType,u,i):[],...d.parent?Te(d.parent,u,i):[]]}function zH(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==p.VariableInstance)throw new Error("Entity must be a variable instance to be flattened");return[d,...(d.successCalls||[]).flatMap(a=>Te(a,u,i)),...(d.errorCalls||[]).flatMap(a=>Te(a,u,i)),...(d.inputs||[]).flatMap(a=>Te(a,u,i)),...(d.outputs||[]).flatMap(a=>Te(a,u,i)),...(d.internalCalls||[]).flatMap(a=>Te(a,u,i)),...(d.writesValues||[]).flatMap(a=>Te(a,u,i)),...d.readsValue?Te(d.readsValue,u,i):[],...d.defaultValue?Te(d.defaultValue,u,i):[],...(ls(d)||[]).flatMap(a=>Te(a,u,i)),...d.declaration?Te(d.declaration,u,i):[],...d.parent?Te(d.parent,u,i):[]]}function Kn(){const d=new Set;return QG.flatMap(i=>Te(i,d)).map(i=>i.id)}function Te(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(!d)throw new Error("Entity must be defined to be flattened");if(d.type===p.GenericReference)return[];if(i.ignoreBuiltInBaseEntities&&(vn.includes(d.type)||Kn().includes(d.id)))return[];if(u.has(d.id))return[];switch(d.type){case p.FunctionCall:return VH(d,u,i);case p.Operation:return GH(d,u,i);case p.Condition:return DH(d,u,i);case p.Loop:return jH(d,u,i);case p.Search:return WH(d,u,i);case p.GlobalEvent:return LH(d,u,i);case p.ReturnStatement:return ZH(d,u,i);case p.ContinueStatement:return OH(d,u,i);case p.BreakStatement:return gH(d,u,i);case p.VariableDeclaration:return JH(d,u,i);case p.DefinitionEntity:return PH(d,u,i);case p.FunctionDeclaration:return NH(d,u,i);case p.Project:return KH(d,u,i);case p.ActionDescriptor:return RH(d,u,i);case p.ArgumentDeclaration:return CH(d,u,i);case p.ValueDescriptor:return HH(d,u,i);case p.InputMap:return BH(d,u,i);case p.OutputMap:return kH(d,u,i);case p.DataType:return $H(d,u,i);case p.InstalledProject:return MH(d,u,i);case p.InternalCall:return xH(d,u,i);case p.LiteralValue:return UH(d,u,i);case p.Property:return qH(d,u,i);case p.VariableInstance:return zH(d,u,i);case p.BuiltInBaseEntity:return i.ignoreBuiltInBaseEntities?[]:_H(d,u,i);case p.PrimitiveEntity:return i.ignoreBuiltInBaseEntities?[]:FH(d,u,i)}return[]}function qw(d){return d.type===p.FunctionCall||d.type===p.InternalCall||[p.Operation,p.Condition,p.Loop].includes(d.type)?d.declaration.inputs:d.type===p.FunctionDeclaration||ko.includes(d.type)?d.inputs:d.type===p.Search?d.inputsDeclarations:[]}function rVe(d,u){return u.type===p.Condition?u.inputs.find(i=>i.declaration.id===d.id):u.type===p.FunctionCall||u.type===p.Operation?u.inputs.find(i=>i.declaration.id===d.id):null}function SH(d){return mi.includes(d.type)?d.inputs:[]}function nVe(d){var u;if(d.type===p.FunctionCall)return d.declaration.implements&&d.declaration.implements.dataType&&d.declaration.implements.dataType.entity&&d.declaration.implements.dataType.entity.type===p.DefinitionEntity&&d.declaration.implements.dataType.entity.properties.length?d.declaration.implements.dataType.entity.properties:((u=d.declaration.returnStatements[0])==null?void 0:u.outputs.map(i=>i.declaration).filter(i=>!!i))||[];if([p.Operation,p.Condition,p.Loop].includes(d.type)){const i=d.declaration;return i.dataType&&i.dataType.entity&&i.dataType.entity.type===p.DefinitionEntity&&i.dataType.entity.properties.length?i.dataType.entity.properties:[]}return Gt.includes(d.type)?d.outputs.map(i=>i.declaration).filter(i=>!!i)||[]:[]}function sVe(d,u){return u.type===p.Condition?null:(u.type===p.FunctionCall||u.type===p.Operation)&&u.outputs.find(i=>{var a;return((a=i.declaration)==null?void 0:a.id)===d.id})||null}function aVe(d){return d.type===p.Condition?[]:mi.includes(d.type)?d.outputs:[]}function q0(d){const u=d.readsValue;return u?Ni(u):null}function YH(d,u){const i=d.readsValue;return i?rp(i,u):null}function XH(d){const u=d.internalCalls||[];return C(Tl(C(u.flatMap(i=>[...i.successCalls,...i.errorCalls]))))}function QH(d){const u=d.internalCalls||[];return C(C(u.flatMap(i=>[...i.successCalls,...i.errorCalls])))}function ap(d){const u=F0(d),i=[];return u.forEach(a=>{if(rc.includes(a.type))i.push(a);else if(Xn.includes(a.type)){const l=Ni(a.parent);i.push(l)}}),i}function lp(d){const u=F0(d),i=[];return u.forEach(a=>{if($t.includes(a.type))i.push(a);else if(Xn.includes(a.type)){const l=a.parent;i.push(l)}}),i}function C(d){const u=new Set;return d.filter(i=>!i||u.has(i.id)?!1:(u.add(i.id),!0))}function eJ(d){return d.type===p.Project?null:zT.includes(d.type)?d:vn.includes(d.type)?null:d.parent?eJ(d.parent):null}function ta(d,u=!1){J.log("[getRelatedCanvasElementsOnTheRight]",d.type,S(d,d.project),d.id);const i=[];if(d.type===p.Project&&i.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)||[]),Xi.includes(d.type)&&i.push(...(d==null?void 0:d.detachedChildren)||[]),d.type===p.DefinitionEntity){const a=[...d.suggestedMethods,...d.methods].flatMap(l=>l.collapsed&&u?[]:(J.log("[Recursive -- getRelatedCanvasElementsOnTheRight]",l.type,S(l,l.project),l.id),ta(l,u)));i.push(...a)}if(d.type===p.Condition){const a=d.successCalls.map(f=>Ni(f)),l=d.errorCalls.map(f=>Ni(f));i.push(...a,...l)}if(ko.includes(d.type)){if(d.collapsed&&u)return[];const a=d.inputs.map(f=>ap(f)).flat(),l=d.calls.map(f=>Ni(f));i.push(...C(a),...l)}if(mi.includes(d.type)&&d.type!==p.Condition&&d.type!==p.Loop){const a=d==null?void 0:d.outputs.map(e=>ap(e)).flat(),l=d.successCalls.map(e=>Ni(e)),f=d.errorCalls.map(e=>Ni(e));i.push(...C(a),...l,...f)}if($t.includes(d.type)){const a=ap(d),l=XH(d);i.push(...a,...l)}if(Qi.includes(d.type)){const a=ap(d);i.push(...a)}if(d.type===p.Loop){if(d.body){const f=ta(d.body,u);i.push(...f)}const a=d.errorCalls.map(f=>Ni(f)),l=d.successCalls.map(f=>Ni(f));i.push(...l,...a)}if(d.type===p.FunctionDeclaration){if(d.collapsed&&u)return[];const a=d.inputs.map(f=>ap(f)).flat(),l=d.calls.map(f=>Ni(f));i.push(...C(a),...l)}return C(i)}function Z0(d,u=!1){const i=[];if(d.type===p.Project&&i.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)||[]),Xi.includes(d.type)&&i.push(...(d==null?void 0:d.detachedChildren)||[]),d.type===p.DefinitionEntity){const a=[...d.suggestedMethods,...d.methods].flatMap(l=>l.collapsed&&u?[]:Z0(l));i.push(...a)}if(d.type===p.Condition){const a=d.successCalls,l=d.errorCalls;i.push(...a,...l)}if(ko.includes(d.type)){if(d.collapsed&&u)return[];const a=d.inputs.map(f=>lp(f)).flat(),l=d.calls;i.push(...C(a),...l)}if(mi.includes(d.type)&&d.type!==p.Condition&&d.type!==p.Loop){const a=d==null?void 0:d.outputs.map(e=>lp(e)).flat(),l=d.successCalls,f=d.errorCalls;i.push(...C(a),...l,...f)}if($t.includes(d.type)){const a=lp(d),l=QH(d);i.push(...a,...l)}if(d.type===p.Loop){const a=d.outputs.map(e=>lp(e)).flat();if(d.body){const e=Z0(d.body,u);i.push(...e)}const l=d.errorCalls,f=d.successCalls;i.push(...C(a),...f,...l)}if(d.type===p.FunctionDeclaration){if(d.collapsed&&u)return[];const a=d.inputs.map(f=>lp(f)).flat(),l=d.calls;i.push(...C(a),...l)}return C(i)}function W0(d,u=!1){const i=ta(d,u),a=[...i,...i.reduce((l,f)=>[...l,...W0(f,u)],[])];return C(a)}function tJ(d,u=!1){const i=Z0(d,u),a=[...i,...i.reduce((l,f)=>[...l,...tJ(f,u)],[])];return C(a)}function dy(d){if(!d)throw new Error("[flattenDefinitionEntityImplementionTypes] Entity must be defined to flatten implementation types");return d.implements.reduce((u,i)=>i.type===p.DefinitionEntity?[...u,p.DefinitionEntity,...dy(i),...Ao(i)]:(i==null?void 0:i.type)===p.BuiltInBaseEntity?[i==null?void 0:i.name,...Ao(i)]:[...u],[])}function Ao(d){var u;if(!d)throw new Error("[flattenDefinitionEntityExtensionTypes] Entity must be defined to flatten extension types");if(d.extends){if(((u=d.extends)==null?void 0:u.type)===p.DefinitionEntity)return[p.DefinitionEntity,...Ao(d.extends),...dy(d.extends)];if(d.extends.type===p.BuiltInBaseEntity)return[d.extends.name,...Ao(d.extends)]}return[]}function uy(d){var u,i;return d.extends?((u=d.extends)==null?void 0:u.type)===p.DefinitionEntity?[d.extends,...uy(d.extends),...Zw(d.extends)]:((i=d.extends)==null?void 0:i.type)===p.BuiltInBaseEntity?[d.extends,...uy(d.extends)]:[]:[]}function Zw(d){return d.implements.reduce((u,i)=>i.type===p.DefinitionEntity?[...u,i,...Zw(i),...uy(i)]:(i==null?void 0:i.type)===p.BuiltInBaseEntity?[i,...uy(i)]:[...u,i],[])}function op(d){return[...Ao(d),...dy(d)].filter((i,a,l)=>l.indexOf(i)===a)}function cr(d,u){if(!d)throw new Error("checkHasBaseEntity: entity is null or undefined");if(d.type!==p.DefinitionEntity&&d.type!==p.BuiltInBaseEntity)throw new Error(`checkHasBaseEntity: entity is not a '${p.DefinitionEntity}' or '${p.BuiltInBaseEntity}', got ${d.type}`);return d.type===p.BuiltInBaseEntity?!!(d.name===u||[...Ao(d)].includes(u)):!!op(d).includes(u)}function iJ(d,u){if(!d)throw new Error("getFirstBaseEntityWithOwnBase: entity is null or undefined");if(d.type!==p.DefinitionEntity&&d.type!==p.BuiltInBaseEntity)throw new Error(`getBaseEntity: entity is not a '${p.DefinitionEntity}' or '${p.BuiltInBaseEntity}', got ${d.type}`);if(d.type===p.BuiltInBaseEntity){if(cr(d,u))return d;if(d.extends&&d.extends.type!==p.PrimitiveEntity){if(cr(d.extends,u))return d.extends;if(d.extends.type===p.BuiltInBaseEntity)return El(d.extends,u)}return null}if(d.extends)return cr(d.extends,u)?d.extends:El(d.extends,u);if(d.implements.length>0){for(const i of d.implements)if(i.type===p.BuiltInBaseEntity){if(cr(i,u))return i;const a=El(i,u);if(a)return a}else if(i.type===p.DefinitionEntity){const a=El(i,u);if(a)return a}}return null}function El(d,u){if(!d)throw new Error("getBaseEntity: entity is null or undefined");if(d.type!==p.DefinitionEntity&&d.type!==p.BuiltInBaseEntity)throw new Error(`getBaseEntity: entity is not a '${p.DefinitionEntity}' or '${p.BuiltInBaseEntity}', got ${d.type}`);if(d.type===p.BuiltInBaseEntity){if(d.name===u)return d;if(d.extends){if(d.extends.name===u)return d.extends;if(d.extends.type===p.BuiltInBaseEntity)return El(d.extends,u)}return null}if(d.extends)return d.extends.name===u?d.extends:El(d.extends,u);if(d.implements.length>0){for(const i of d.implements)if(i.type===p.BuiltInBaseEntity){if(i.name===u)return i;const a=El(i,u);if(a)return a}else if(i.type===p.DefinitionEntity){const a=El(i,u);if(a)return a}}return null}function rJ(d){const u=Io(d),i=[...u,...u.reduce((a,l)=>[...a,...rJ(l)],[])];return C(i)}function Ww(d){return d.implements.length===0&&!d.extends?null:d.implements.find(a=>a.type===p.BuiltInBaseEntity&&a.name===pe.PERSISTED_ENTITY)?d:[...d.implements,...d.extends?[d.extends]:[]].reduce((a,l)=>{if(l.type===p.DefinitionEntity){const f=Ww(l);if(f)return f}return a},null)}function lVe(d){return d.extends&&d.extends.type===p.BuiltInBaseEntity?d.extends:null}function oVe(d){const u=d.implements.find(i=>i.type===p.BuiltInBaseEntity);return u&&u.type===p.BuiltInBaseEntity?u:null}function H0(d){return d.extends&&d.extends.type===p.DefinitionEntity?d.extends:null}function sn(d){const u=[...d.implements||[],...d.extends?[d.extends]:[]].reduce((i,a)=>a.type===p.BuiltInBaseEntity?[...i,a,...sn(a)]:a.type===p.DefinitionEntity?[...i,...sn(a)]:i,[]);return C(u)}function py(d){return d.type===p.PrimitiveEntity?!0:d.type===p.BuiltInBaseEntity?d.interactive:!sn(d).find(a=>!a.interactive)}function dVe(d){return d.parent===d.project&&d.project.variableDeclarations.includes(d)}function Hw(d){return d.parent!==d.project?!1:p.VariableDeclaration===d.type?d.project.variableDeclarations.includes(d):p.VariableInstance===d.type?d.project.variableInstances.includes(d):p.FunctionCall===d.type?d.project.functionCalls.includes(d):p.Condition===d.type?d.project.conditions.includes(d):p.Operation===d.type?d.project.operations.includes(d):p.Loop===d.type?d.project.loops.includes(d):p.Search===d.type?d.project.searches.includes(d):!1}function nJ(d){if([...jt,p.DefinitionEntity,p.InstalledProject,p.Project].includes(d.type)||Hw(d))return!1;const u=Io(d);return u.length===0?!0:u.some(i=>nJ(i))}function Jw(d){return[...jt,p.DefinitionEntity,p.InstalledProject,p.Project].includes(d.type)||Hw(d)?!1:Io(d).length===0}function sJ(d,u=0){if(Jw(d)){const i=Io(d);return i.length===0?d:i.map(l=>sJ(l,u+1)).reduce((l,f)=>l?f&&f.x<l.x?f:l:f,null)}return null}function aJ(d){const u=[];if(Jw(d))u.push(d);else return[];return Io(d).forEach(a=>{u.push(...aJ(a))}),u}function zw(d){return d.type===p.FunctionDeclaration&&d.parent!==d.project&&!![p.DefinitionEntity,p.Loop,p.InstalledProject].includes(d.parent.type)}function uVe(d,u){const i=new Map;return d.forEach(a=>{i.set(a.id,a)}),u.forEach(a=>{i.set(a.id,a)}),Array.from(i.values())}function dp(d){switch(d){case p.DefinitionEntity:return _s;case p.FunctionDeclaration:return pl;case p.VariableDeclaration:return lo;case p.VariableInstance:return ao;case p.FunctionCall:return Eo;case p.Operation:return Ql;case p.Condition:return ro;case p.ReturnStatement:return eo;case p.Loop:return io;case p.Search:return oo;case p.InputMap:return as;case p.OutputMap:return ea;case p.ArgumentDeclaration:return Hs;case p.Property:return os;case p.InstalledProject:return uo;case p.Project:return N;case p.DataType:return Zr;case p.GlobalEvent:return to;case p.InternalCall:return po;case p.ValueDescriptor:return yl;case p.BuiltInBaseEntity:return Da;case p.PrimitiveEntity:return Rn;case p.ActionDescriptor:return xt;case p.LiteralValue:return Or;case p.ContinueStatement:return fo;case p.BreakStatement:return co;default:return null}}function Yr(d,u,i=null){const a=d!=null&&d.parent?ee(d==null?void 0:d.parent):null;let l=a?u.get(a):null,f=i||d;if((d==null?void 0:d.id)===(u==null?void 0:u.id))return u;if(d.type===p.ReturnStatement)return Er(d,u,f);if(d.type===p.FunctionDeclaration&&(l==null?void 0:l.type)===p.Loop)return l;if(jt.includes(d.type))return d;if(d.type===p.Loop)return f.id===d.id?l:d;if(vn.includes(d.type))return null;const e=d.parent;if(!e)return null;if(e.type===p.GenericReference){const y=ee(e);if(!y)return null;const v=u.get(y);return v?Yr(v,u,f):null}else return e===u?u:Yr(e,u,f)}function Er(d,u,i=null){const a=d!=null&&d.parent?ee(d==null?void 0:d.parent):null;let l=a?u.get(a):null,f=i||d;if(d.type===p.FunctionDeclaration&&(l==null?void 0:l.type)===p.Loop)return Er(l.parent,u,f);if(jt.includes(d.type))return d;if(vn.includes(d.type))return null;const e=d.parent;if(!e)return null;if(e.type===p.GenericReference){const y=ee(e);if(!y)return null;const v=u.get(y);return v?Er(v,u,f):null}else return e===u?u:Er(e,u,f)}function up(d,u){if(vn.includes(d.type))return J.warn(`getRootEntryPointScopeOwner is \`null\` because it was called with a built-in entity type: ${d.type}`),null;if(u.getBuiltIn(d.id))return J.warn(`getRootEntryPointScopeOwner is \`null\` because it was called with a built-in entity: ${d.id}`),null;const i=mn(d.parent,u);return i?i===u?Xi.includes(d.type)?d:(J.warn(`getRootEntryPointScopeOwner is \`null\` because it was called with an entity that has the project as parent: ${d.id}`),null):i.type===p.DefinitionEntity?d:up(i,u):(J.warn(`getRootEntryPointScopeOwner is \`null\` because it was called with an entity that has no parent: ${d.id}`),null)}function J0(d,u,i){if(d===u||u===i||d===i||!d||!u)return!1;const a=Yr(u.parent,i);return a===i?!1:a===d?!0:J0(a,u,i)}var z0=(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))(z0||{});function gs(d,u,i){const a=Yr(d,i),l=Yr(u,i);if(!a)throw new Error("Could not find scope owner for the entity: "+d.id);if(!l)throw new Error("Could not find scope owner for the entity: "+u.id);if(a===l&&a.type!==p.Project)return{compatible:!0,type:"same-both-local",commonAncestorScope:a};if(a===l&&a.type===p.Project)return{compatible:!0,type:"same-both-global",commonAncestorScope:a};if(a.type===p.Project&&l.type!==p.Project)return{compatible:!1,type:"a-is-global-b-is-not",commonAncestorScope:a};if(a.type!==p.Project&&l.type===p.Project)return{compatible:!1,type:"b-is-global-a-is-not",commonAncestorScope:l};if(J0(a,l,i))return{compatible:!0,type:"b-in-a",commonAncestorScope:a};if(J0(l,a,i))return{compatible:!0,type:"a-in-b",commonAncestorScope:l};const y=Kw(a,l);return y===i?{compatible:!1,type:"parallel-in-project",commonAncestorScope:y}:y?{compatible:!1,type:"parallel-in-common-parent",commonAncestorScope:Yr(y,i)}:{compatible:!1,type:"parallel-in-project",commonAncestorScope:i}}function lJ(d,u,i){const a=gs(d,u,i);if(!a.compatible||a.type!=="same-both-local")return null;if(d===u)return d;let l=Yr(d.parent,i);if(l){if(l===u)return u;if(l.type===p.Project)return d}else return d;for(;l;){if(l){if(l===u)return u;if(l.type===p.Project)return d}else return d;l=Yr(l.parent,i)}let f=Yr(u.parent,i);if(f){if(f===d)return d;if(f.type===p.Project)return u}else return u;for(;f;){if(f){if(f===d)return d;if(f.type===p.Project)return u}else return u;f=Yr(f.parent,i)}return null}function oJ(d){return d.length===0?null:d.length===1?d[0]:d.reduce((i,a)=>{const l=lJ(i,a,a.project);return!l||l===a?i:a},d[0])}function mn(d,u){if(!d)return null;let i;return typeof d=="string"?i=d:d.type===p.GenericReference?i=ee(d):i=d.id,i===u.id?u:u.get(i)}function wo(d){if(!d)return null;if(vn.includes(d.type))return d;if(d.type===p.Project)return null;if(d.project.getBuiltIn(d.id))return d;const u=d.parent;return!u||u.type===p.Project?null:wo(u)}function cy(d){const u=[];function i(f,e){return u.some(y=>y.blockedByCaller===f&&y.blockedByCalling===e)}function a(f,e){i(f,e)||u.push({blockedByCaller:f,blockedByCalling:e})}const l=up(d,d.project);return l?(d.calledBySuccess.forEach(f=>{[...f.successCalls||[]].forEach(v=>{Gt.includes(v.type)&&v.id!==d.id&&(ht(d).find(b=>b===v)||a(f,v))});let y;if(mi.includes(f.type)&&(y=f),y){const v=cy(y);v.reachable||ht(d).find(b=>b===f)||v.blocks.forEach(b=>{a(f,b.blockedByCalling)})}}),d.calledByError.forEach(f=>{[...f.errorCalls||[]].forEach(v=>{Gt.includes(v.type)&&v!==d&&(ht(d).find(b=>b===v)||a(f,v))});let y;if(mi.includes(f.type)&&(y=f),y){const v=cy(y);v.reachable||ht(d).find(b=>b===f)||v.blocks.forEach(b=>{a(f,b.blockedByCalling)})}}),d.calledByEntry.forEach(f=>{if([...f.calls||[]].forEach(v=>{Gt.includes(v.type)&&v!==d&&(ht(d).find(b=>b===v)||a(f,v))}),f===l)return;let y;if(f.type===p.FunctionDeclaration){const v=Ni(f);if(v.type===p.DefinitionEntity)return;v.type===p.Loop&&(y=v)}if(y){const v=cy(y);v.reachable||v.blocks.forEach(T=>{a(f,T.blockedByCalling)})}}),{reachable:u.length===0,entryPoint:l,blocks:u}):{reachable:!0,entryPoint:null,blocks:[]}}function pVe(d){return rc.includes(d.type)?d.type===p.FunctionDeclaration?!zw(d):!0:!1}function cVe(d){if(p.ActionDescriptor===d.type){if(d.project.operationDeclarations.find(f=>f.id===d.id))return p.Operation;if(d.project.globalEventActionDescriptors.find(f=>f.id===d.id))return p.GlobalEvent;if(d.project.loopDeclarations.find(f=>f.id===d.id))return p.Loop;if(d.project.conditionDeclarations.find(f=>f.id===d.id))return p.Condition}return d.type}function S0(d,u){return d.type===p.BuiltInBaseEntity?d.name===u:!!Ao(d).includes(u)}function fVe(d,u){return d.type===p.BuiltInBaseEntity?d.name===u:!!dy(d).includes(u)}function yVe(d){const u=[];return d.entities.forEach(i=>{if(S0(i,pe.PERSISTED_ENTITY)){u.push(i);return}}),C(u)}function hVe(d){const u=[];return d.entities.forEach(i=>{if(S0(i,pe.RELATIONAL_DATABASE)){u.push(i);return}}),C(u)}function mVe(d){return d.type!==p.DefinitionEntity||d.abstract||!S0(d,pe.PERSISTED_ENTITY)?null:(d==null?void 0:d.properties.find(i=>i.implements.find(a=>a.id===ce[p.BuiltInBaseEntity][pe.PERSISTED_ENTITY].properties.primaryKey.id)&&!i.abstract))||null}function dJ(d){var a;const u=Ww(d);if(!u)return null;const i=u.properties.find(l=>l.implements.find(f=>f.id===ce[p.BuiltInBaseEntity][pe.PERSISTED_ENTITY].properties.database.id));return i?(a=i.getDefaultValue())==null?void 0:a.valueAsType:null}function pp(d){if(d.type!==p.DefinitionEntity)return[];if(d.abstract)return[];if(!cr(d,pe.PERSISTED_ENTITY))return[];const u=[],i=d.properties.filter(a=>!a.implements.find(l=>l.id===ce[p.BuiltInBaseEntity][pe.PERSISTED_ENTITY].properties.database.id)&&!a.abstract);return u.push(...i),u}function vVe(d){var i;if(!d||d.type!==p.DefinitionEntity||!cr(d,pe.PERSISTED_ENTITY))return null;const u=d.properties.find(a=>!!a.implements.find(l=>l.id===ce[p.BuiltInBaseEntity][pe.PERSISTED_ENTITY].properties.database.id));return(i=u==null?void 0:u.getDefaultValue())==null?void 0:i.valueAsTypeSingle}function fr(d,u){var a;if(!$g.includes(u.type)||!d)return u.project||null;let i=u.project;return d.type===p.Project?i=d:((a=u.project)==null?void 0:a.id)!==d.project.id&&(i=d.project),i}function TVe(d){switch(d){case p.Project:return N;case p.InstalledProject:return uo;case p.DefinitionEntity:return _s;case p.FunctionDeclaration:return pl;case p.GlobalEvent:return to;case p.VariableInstance:return ao;case p.VariableDeclaration:return lo;case p.InputMap:return as;case p.OutputMap:return ea;case p.Condition:return ro;case p.Operation:return Ql;case p.FunctionCall:return Eo;case p.ArgumentDeclaration:return Hs;case p.PrimitiveEntity:return Rn;case p.DataType:return Zr;case p.Property:return os;case p.ActionDescriptor:return xt;case p.ReturnStatement:return eo;case p.ContinueStatement:return fo;case p.BreakStatement:return co;case p.Loop:return io;case p.Search:return oo;case p.ValueDescriptor:return yl;case p.InternalCall:return po;case p.LiteralValue:return Or}return null}function EVe(d){const u={added:{},updated:{},removed:{},affected:[],seenEntities:[],self:d==null?void 0:d.self};return d==null||d.added.forEach(i=>{u.added[i.id]=i}),d==null||d.updated.forEach(i=>{u.updated[i.id]=i}),d==null||d.removed.forEach(i=>{u.removed[i.id]=i}),u.affected=Array.from(new Set(d==null?void 0:d.affected.map(i=>i.id))),u}function rr(d,u){const i=dp(d.type);return i?!i.MUTABLE_META_PROPERTIES.every(l=>{const f=d[l],e=u[l];return e===void 0||f===e?!0:Array.isArray(f)&&Array.isArray(e)?f.length!==e.length?!1:f.every((y,v)=>y===e[v]):!1}):!1}function nr(d,u){let i={...u};if(!d.checkCanEdit(d)){const a=dp(d.type);if(!a)return i;a.MUTABLE_META_PROPERTIES.forEach(l=>{["x","y","collapsed"].includes(l)||delete i[l]})}return i}function Y0(d,u={}){if(d.type===p.Project)return[];if(!d.parent)return[];const i=ee(d.parent);if(!i)return[];const a=u[i];return a?[a.id,...Y0(a,u)]:[]}function bVe(d){const u=[],i=new Set;return[...d.listAdded,...d.listUpdated,...d.listAffected].forEach(a=>{const l=Ni(a);if(!l||i.has(l.id))return;const f=d.project.get(a.id);if(!f)throw new Error(`Could not find active version of entity ${a.id} in project, which is present in the change set.`);i.add(l.id),u.push(f)}),C(u)}function IVe(d){if(d.type===p.Condition)return null;if(d.type===p.Search)return d.project.getBuiltIn(ce["value-descriptor"][ch.SearchErrorOutputDescriptor].id)||null;if(d.type===p.Operation)return d.declaration.error;if(d.type===p.FunctionCall){const i=d.declaration.returnStatements.find(a=>!!a.throws);return(i==null?void 0:i.throws)||null}return null}function uJ(d){const u=d.entities.filter(l=>!!l.implements.find(f=>f.id===ce["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.id)),i=u.find(l=>{const f=l.properties.find(v=>v.implements.find(T=>T.id===ce["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.default.id)),e=f==null?void 0:f.getDefaultValue();return(e==null?void 0:e.value)===!0});return i||u[0]||null}function Sw(d,u){const i=Array.from(new Set([...u.getAllBuiltInIds(),...Kn()]));return!!(i.includes(d.id)||!Y0(d,{...u.instances,...u.builtInInstances}).every(f=>!i.includes(f)))}function pJ(d){if(!d)return null;if(d.type===p.Project)return d.id;const u=d.parent;return u?pJ(u):d.id}function fy(d){if(d.declaration&&d.declaration.type===p.Property){if(d.declaration.interactive)if(d.declaration.implements.every(u=>u.interactive)){if(d.declaration.extends&&!d.declaration.extends.interactive)return!1}else return!1;else return!1;if(d.declaration.private){const u=Ni(d),i=up(u,d.project);if((i==null?void 0:i.type)===p.FunctionDeclaration&&(i==null?void 0:i.parent.type)===p.DefinitionEntity&&(i==null?void 0:i.parent.id)!==d.declaration.parent.id)return!1}}return!0}function Yw(d){if(d.interactive)if(d.implements.every(u=>u.interactive)){if(d.extends&&!d.extends.interactive)return!1}else return!1;else return!1;if(d.private){const u=Ni(d),i=up(u,d.project);if((i==null?void 0:i.type)===p.FunctionDeclaration&&(i==null?void 0:i.parent.type)===p.DefinitionEntity&&(i==null?void 0:i.parent.id)!==d.parent.id)return!1}return!0}function AVe(d,u,i){const a=u,l=i,f=!!i,e=[];return a.forEach(y=>{var v;if(f){const T=gs(l,y,d);if(!T.compatible&&T.type!=="b-is-global-a-is-not")return;e.push(y)}else{if(((v=y.parent)==null?void 0:v.type)!==p.Project)return;e.push(y)}}),C(e)}function Xw(d,u){var i,a,l,f;if(!d||!u)return null;if(d.id===u.id)return d;if(d.type===p.FunctionDeclaration){if(((i=d.implements)==null?void 0:i.id)===u.id)return d;if(((a=d.extends)==null?void 0:a.id)===u.id)return d;if(d.extends){const e=Xw(d.extends,u);if(e)return e}}if(u.type===p.FunctionDeclaration){if(((l=u.implements)==null?void 0:l.id)===d.id)return u;if(((f=u.extends)==null?void 0:f.id)===d.id)return u;if(u.extends){const e=Xw(u.extends,d);if(e)return e}}return null}function gd(d){if(d.type!==p.FunctionDeclaration&&d.type!==p.ActionDescriptor)throw new Error(`Entity is not a FunctionDeclaration or ActionDescriptor: ${d.type}`);if(d.type===p.FunctionDeclaration){if(d.implements)return gd(d.implements);if(d.extends)return gd(d.extends)}return d}function bl(d){var u;return!!(d.required||(u=d.declaration)!=null&&u.required)}function Ro(d){return r6(d)||d===void 0||d===""}function _a(d){return d?d.valueAsType?!1:Ro(d.value):!0}function yy(d){return d.replace(/["'`]/g,"")}function Bi(d){const i=yy(d).split(/[\s-]+/).filter(e=>e.length>0);if(i.length===0)return"";const a=i[0],l=a[0].toLowerCase()+a.slice(1),f=i.slice(1).map(e=>e[0].toUpperCase()+e.slice(1));return[l,...f].join("")}function _d(d){return yy(d).split(/[\s-]+/).filter(a=>a.length>0).map(a=>a[0].toUpperCase()+a.slice(1)).join("")}function cJ(d){const u=yy(d).trim();if(!u)return"";const i=u.replace(/[\s_-]+/g," ").split(" ").filter(Boolean),a=[];for(const l of i){let f=l;f=f.replace(/([A-Z]+)([A-Z][a-z]+)/g,"$1-$2"),f=f.replace(/([a-z0-9])([A-Z][a-z0-9]*)/g,"$1-$2"),f=f.replace(/([0-9])([a-zA-Z]+)/g,"$1-$2"),f=f.replace(/([a-zA-Z])([0-9])/g,"$1-$2");for(const e of f.split("-"))e&&a.push(e)}return a.join("-")}function wVe(d){const u=yy(d).trim();if(!u)return"";const i=u.replace(/[\s_-]+/g," ").split(" ").filter(Boolean),a=[];for(const l of i){let f=l;f=f.replace(/([A-Z]+)([A-Z][a-z]+)/g,"$1_$2"),f=f.replace(/([a-z0-9])([A-Z][a-z0-9]*)/g,"$1_$2"),f=f.replace(/([0-9])([a-zA-Z]+)/g,"$1_$2"),f=f.replace(/([a-zA-Z])([0-9])/g,"$1_$2");for(const e of f.split("_"))e&&a.push(e)}return a.join("_")}function X0(d){return cJ(d).toLowerCase()}function Qw(d){const u=yy(d).trim();if(!u)return"";let i=u.replace(/([A-Z]+)([A-Z][a-z]+)/g,"$1 $2").replace(/([a-z0-9])([A-Z][a-z0-9]*)/g,"$1 $2").replace(/[_-]+/g," ").replace(/\s+/g," ").trim();return i.charAt(0).toUpperCase()+i.slice(1)}function cp(d){var i,a,l,f;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&&!((i=d.andChildrenGroup)!=null&&i.length)&&!((a=d.orChildrenGroup)!=null&&a.length)&&(u=" as template"),!d.entity){const e=d.isList;if(!((l=d.andChildrenGroup)!=null&&l.length)&&!((f=d.orChildrenGroup)!=null&&f.length))return e?`List of an any data type${u}`:`Any data type${u}`;let y="",v=!1,T=!1;return(d.andChildrenGroup||[]).forEach(A=>{const b=cp(A),O=Nu(b);v&&(y+=" and "),A.isGroup?y+="("+O+")":v?y+=O:y+=b,v=!0,T=!0}),(d.orChildrenGroup||[]).forEach(A=>{const b=cp(A),O=Nu(b);v&&(T&&(y+=","),y+=" or "),A.isGroup?y+="("+O+")":v?y+=O:y+=b,v=!0}),e?`List of ${Nu(y)}`:y}if(d.entity.type===p.PrimitiveEntity){let e=d.entity.name;switch(d.entity.name){case re.String:e="Text";break;case re.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===p.DefinitionEntity){const e=S(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===p.BuiltInBaseEntity){const e=yJ(d.entity);return d.isList?`List of ${e} values${u}`:e.slice(0,1).toUpperCase()+e.slice(1)+u}else if(d.entity.type===p.LiteralValue){if(d.entity.name===re.Null)return"Empty value";if(d.entity.name===re.Untyped)return"Untyped value";if(d.entity.name===re.File)return"File";if(d.entity.name===re.String)return`"${d.entity.value}" text`;if(d.entity.name===re.Number)return`Number '${d.entity.value}'`;if(d.entity.name===re.Boolean)return`${d.entity.value} value`;if(d.entity.name===re.UUID)return`"${d.entity.value}" unique identifier`;if(d.entity.name===re.Date)return`"${d.entity.value}" date`}return d.isList?`List of ${S(d.entity,d.project)} values${u}`:`${S(d.entity,d.project).slice(0,1).toUpperCase()+S(d.entity,d.project).slice(1)} value${u}`}function RVe(d){if(!d)return"Any data type";const u=d.getDataType(null);return cp(u)}function Q0(d){switch(d.declaration.id){case pt.Equal:return"is equal to";case pt.NotEqual:return"is not equal to";case pt.MoreThan:return"is greater than";case pt.MoreThanOrEqual:return"is greater than or equal to";case pt.LessThan:return"is less than";case pt.LessThanOrEqual:return"is less than or equal to";case Zi.And:return"and";case Zi.Or:return"or";case Ir.Empty:return"is empty";case Ir.NotEmpty:return"is present"}}function fJ(d){if(d.includes(pe.HTTP_ENDPOINT))return"HTTP endpoint";if(d.includes(pe.PERSISTED_ENTITY))return"Persisted entity";if(d.includes(pe.CRON_JOB))return"Scheduled execution";if(d.includes(pe.RELATIONAL_DATABASE))return"Relational database";if(d.includes(pe.SQL_ROW_TRANSFORMER))return"Row transformer";if(d.includes(pe.GOOGLE_AUTH_CONNECTION))return"Google account connection";if(d.includes(pe.SLACK_AUTH_CONNECTION))return"Slack account connection";if(d.includes(pe.AIRTABLE_AUTH_CONNECTION))return"Airtable account connection";if(d.includes(pe.MICROSOFT_AUTH_CONNECTION))return"Microsoft account connection";if(d.includes(pe.OPENAI_AUTH_CONNECTION))return"OpenAI account connection";if(d.includes(pe.ATLASSIAN_AUTH_CONNECTION))return"Atlassian account connection";if(d.includes(pe.JIRA_AUTH_CONNECTION))return"Jira account connection";if(d.includes(pe.GOOGLE_DRIVE_AUTH_CONNECTION))return"Google Drive account connection";if(d.includes(pe.GOOGLE_MAIL_AUTH_CONNECTION))return"Gmail account connection";if(d.includes(pe.GOOGLE_SHEET_AUTH_CONNECTION))return"Google Sheet account connection";if(d.includes(pe.GOOGLE_SLIDES_AUTH_CONNECTION))return"Google Slides account connection";if(d.includes(pe.GOOGLE_GEMINI_AUTH_CONNECTION))return"Google Gemini account connection";if(d.includes(pe.EXTERNAL_INTEGRATION_CONNECTION))return"External integration connection";try{return Qw(d[0])}catch(u){return console.error("Error resolving base entity name for base entities:",d,u),"Built-in base entity"}}function yJ(d){switch(d.name){case pe.HTTP_ENDPOINT:return"HTTP endpoint";case pe.PERSISTED_ENTITY:return"Persisted entity";case pe.CRON_JOB:return"Scheduled execution";case pe.RELATIONAL_DATABASE:return"Relational database";case pe.SQL_ROW_TRANSFORMER:return"Row transformer";case pe.GOOGLE_AUTH_CONNECTION:return"Google account connection";case pe.SLACK_AUTH_CONNECTION:return"Slack account connection";case pe.AIRTABLE_AUTH_CONNECTION:return"Airtable account connection";case pe.MICROSOFT_AUTH_CONNECTION:return"Microsoft account connection";case pe.OPENAI_AUTH_CONNECTION:return"OpenAI account connection";case pe.ATLASSIAN_AUTH_CONNECTION:return"Atlassian account connection";case pe.JIRA_AUTH_CONNECTION:return"Jira account connection";case pe.GOOGLE_DRIVE_AUTH_CONNECTION:return"Google Drive account connection";case pe.GOOGLE_MAIL_AUTH_CONNECTION:return"Gmail account connection";case pe.GOOGLE_SHEET_AUTH_CONNECTION:return"Google Sheet account connection";case pe.GOOGLE_SLIDES_AUTH_CONNECTION:return"Google Slides account connection";case pe.GOOGLE_GEMINI_AUTH_CONNECTION:return"Google Gemini account connection";case pe.EXTERNAL_INTEGRATION_CONNECTION:return"External integration connection";case pe.EXTERNAL_INTEGRATION_CONNECTION:return"External integration connection"}try{return Qw(d.name)}catch(u){return console.error("Error resolving built-in base entity data type label for entity:",d,u),"Built-in base entity"}}function CVe(d){const u=H0(d);if(!u){const i=op(d);return i.includes(pe.HTTP_ENDPOINT)?"HTTP endpoint":i.includes(pe.PERSISTED_ENTITY)?"Persisted entity":i.includes(pe.CRON_JOB)?"Scheduled execution":i.includes(pe.RELATIONAL_DATABASE)?"Relational database":i.includes(pe.SQL_ROW_TRANSFORMER)?"Row transformer":i.includes(pe.GOOGLE_AUTH_CONNECTION)?"Google account connection":i.includes(pe.SLACK_AUTH_CONNECTION)?"Slack account connection":i.includes(pe.AIRTABLE_AUTH_CONNECTION)?"Airtable account connection":i.includes(pe.MICROSOFT_AUTH_CONNECTION)?"Microsoft account connection":i.includes(pe.OPENAI_AUTH_CONNECTION)?"OpenAI account connection":i.includes(pe.ATLASSIAN_AUTH_CONNECTION)?"Atlassian account connection":i.includes(pe.JIRA_AUTH_CONNECTION)?"Jira account connection":i.includes(pe.EXTERNAL_INTEGRATION_CONNECTION)?"External integration connection":S(d,d.project)+" entity"}return S(u,d.project)+" entity"}function hJ(d){let u="Find ";return d.outputs.forEach((i,a)=>{const l=p0(i,null),f=Nu(l&&l.entity?S(l.entity,d.project):"unstructured data");a===0?u+=`${f} `:a===d.outputs.length-1?u+=`and ${f} `:u+=`, ${f} `}),u}function mJ(d){switch(d.name){case re.String:return"Text";case re.Number:return"Number";case re.Boolean:return"Boolean";case re.KeyValue:return"Data structure";case re.UUID:return"Unique identifier";case re.Date:return"Date";case re.EntityTemplate:return"Entity as template";case re.Enum:return"Enumeration";case re.File:return"File";case re.Null:return"Empty";case re.ActionDescriptor:return"Action descriptor";case re.Untyped:return"Untyped";default:return d.name}}function vJ(d){switch(d.id){case We.List:return"Loop over list items";case We.ManualFlow:return"Manual flow control loop";case We.ObjectKeys:return"Loop over object keys";case We.ObjectValues:return"Loop over object values";case We.Counted:return"Loop given number of times";case We.String:return"Loop over text characters";case Pi.Addition:return"Sum numbers";case Pi.Subtraction:return"Subtract numbers";case Pi.Multiplication:return"Multiply numbers";case Pi.Division:return"Divide numbers";case Pi.Remainder:return"Get remainder of numbers";case Pi.Exponentiation:return"Get exponent of numbers";case ze.AddIndex:return"Add at index position";case ze.DeleteFirst:return"Delete first character";case ze.DeleteLast:return"Delete last character";case ze.DeleteIndex:return"Delete at index position";case ze.Join:return"Join texts";case ze.ReplaceAllMatches:return"Replace all matches";case ze.ReplaceFirst:return"Replace first match";case ze.ReplaceLast:return"Replace last match";case ze.Split:return"Split text";case ze.ReplaceIndex:return"Replace at index position";case ze.ReplaceSingleMatch:return"Replace single match";case ze.GetFirst:return"Get first character";case ze.GetLast:return"Get last character";case ze.GetIndexItem:return"Get at index position";case ze.GetIndexOf:return"Get the index number of the character";case ze.Append:return"Add at the end";case ze.Prepend:return"Add at the start";case Ei.Wait:return"Wait";case Ei.Parallel:return"Run in parallel";case Ei.Sequential:return"Run in sequence";case pn.HttpRequest:return"HTTP request";case ut.AddIndex:return"Add item at index position";case ut.DeleteFirst:return"Delete first item";case ut.DeleteLast:return"Delete last item";case ut.DeleteIndex:return"Delete item at index position";case ut.Join:return"Join lists";case ut.ReplaceFirst:return"Replace first match";case ut.ReplaceLast:return"Replace last match";case ut.Split:return"Split list";case ut.ReplaceIndex:return"Replace at index position";case ut.GetFirst:return"Get first item";case ut.GetLast:return"Get last item";case ut.GetIndexItem:return"Get item at index position";case ut.Append:return"Add item at the end";case ut.Prepend:return"Add item at the start";case Us.PROJECT_PUBLICATION_COMPLETED:return"Project publication completed";default:return(d.name.slice(0,1).toUpperCase()+d.name.slice(1)).replaceAll("-"," ")}}function S(d,u){var i;if(p.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 dr(d.type).replaceAll("-"," ")}return a}if(p.BuiltInBaseEntity===d.type)return fJ([d.name]);if(Og.includes(d.type)&&d.type!==p.ActionDescriptor)return d.name;switch(d.type){case p.Search:return hJ(d);case p.GlobalEvent:return d.implements?S(d.implements,u):dr(d.type).replaceAll("-"," ");case p.Operation:case p.InternalCall:case p.Loop:const a=mn(d.declaration,u);return S(a,u);case p.ActionDescriptor:return vJ(d);case p.BreakStatement:const l=mn(d.parent,u);return`Stop loop ${S(l,u)}`;case p.ContinueStatement:const f=mn(d.parent,u);return`Execute next iteration of ${S(f,u)}`;case p.FunctionCall:return mn(d.declaration,u).name;case p.Condition:{const y=d;if(y.declaration.id===Zi.And)return"If all conditions are met";if(y.declaration.id===Zi.Or)return"If any condition is met";if((i=d.inputs)!=null&&i.length){const v=S(y.inputs[0],y.project);if(y.inputs[1]){const T=y.inputs[1].declaration.name;return`If ${v} ${Q0(y)} ${T}`}return`If ${v} ${Q0(y)}`}else return`If ${Q0(y)}`}case p.ReturnStatement:{const y=mn(d.parent,u);return y?`Output of ${S(y,u)}`:"Return statement"}case p.InputMap:if(d.declaration){const y=mn(d.declaration,u);return S(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 p.VariableInstance:{const y=mn(d.declaration,u);return S(y,u)||""}case p.OutputMap:if(d.declaration){const y=mn(d.declaration,u);return(y==null?void 0:y.name)||""}else return d.parentRelationType===_l.Error?"Undeclared error":"";case p.PrimitiveEntity:case p.LiteralValue:return mJ(d);default:return dr(d.type).replaceAll("-"," ")}}function eR(d,u){const i=[];d.name||i.push(new ue({id:`${d.id}--${de.EmptyName}`,message:`Entity with id "${d.id}" and type "${d.type}" has an empty name. Please provide a 'name' string.`,severity:Q.Error,code:de.EmptyName}));const a=u.entities.filter(l=>l.name===d.name);return a.length&&i.push(new ue({id:`${d.id}--${de.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.
388
388
  Please provide a unique 'name' string.`,severity:Q.Error,code:de.NameNotUniqueInScope})),i}function tR(d,u){const i=[];d.name||i.push(new ue({id:`${d.id}--${de.EmptyName}`,message:`Entity with id "${d.id}" and type "${d.type}" has an empty name. Please provide a 'name' string.`,severity:Q.Error,code:de.EmptyName}));const a=d.parent?ee(d.parent):null;let l=u;a&&(l=u.get(a));const f=[];l.type===p.DefinitionEntity?f.push(...l.methods.map(y=>y)):l.type===p.Project?f.push(...l.functions.map(y=>y)):l.type===p.Loop?l.body&&f.push(l.body):l.type===p.InstalledProject&&f.push(...l.functions.map(y=>y));const e=f.filter(y=>y.name===d.name);return e.length&&i.push(new ue({id:`${d.id}--${de.NameNotUniqueInScope}`,message:`Entity with id "${d.id}" and type "${d.type}" has a name "${d.name}" that is not unique in ${l.type===p.Project?"the globally declared project scope":"its parent entity"}. Entity with id "${e[0].id}" has the same name.
389
389
  Please provide a unique 'name' string.`,severity:Q.Error,code:de.NameNotUniqueInScope})),i}function iR(d,u){const i=[];d.name||i.push(new ue({id:`${d.id}--${de.EmptyName}`,message:`Entity with id "${d.id}" and type "${d.type}" has an empty name. Please provide a 'name' string.`,severity:Q.Error,code:de.EmptyName}));const a=d.parent&&mn(d.parent,u)||u;if(!a)i.push(new ue({id:`${d.id}--parent-reference--${W.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:Q.Error,code:W.ReferencedEntityNotFound}));else{const f=uw(a).filter(e=>e.name===d.name);f.length&&i.push(new ue({id:`${d.id}--${de.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 "${f[0].id}" has the same name.
390
390
  Please provide a unique 'name' string.`,severity:Q.Error,code:de.NameNotUniqueInScope}))}return i}function rR(d,u){const i=[];d.name||i.push(new ue({id:`${d.id}--${de.EmptyName}`,message:`Entity with id "${d.id}" and type "${d.type}" has an empty name. Please provide a 'name' string.`,severity:Q.Error,code:de.EmptyName}));const a=ee(d.parent);if(!a)i.push(new ue({id:`${d.id}--parent-reference--${W.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:Q.Error,code:W.InvalidReferenceObjectStructure}));else{const l=u.get(a);if(!l)i.push(new ue({id:`${d.id}--parent-reference--${W.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:Q.Error,code:W.ReferencedEntityNotFound}));else{const e=l.properties.filter(y=>y.name===d.name);e.length&&i.push(new ue({id:`${d.id}--${de.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.