@elyx-code/project-logic-tree 0.0.6590 → 0.0.6592
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +7 -0
- package/dist/index.umd.cjs +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -125333,6 +125333,13 @@ function iUt(d, u, i) {
|
|
|
125333
125333
|
);
|
|
125334
125334
|
((y = g.ancestor) == null ? void 0 : y.id) === ((v = E.ancestor) == null ? void 0 : v.id) || ((T = g.ancestor) == null ? void 0 : T.id) === d.id ? (a.ancestor = g.ancestor, a.callType = g.callType) : ((A = E.ancestor) == null ? void 0 : A.id) === u.id ? (a.ancestor = E.ancestor, a.callType = E.callType) : (V.some((M) => M.callee.id === (u == null ? void 0 : u.id)) || L.some((M) => M.callee.id === (d == null ? void 0 : d.id)), a.ancestor = l, a.callType = "entry");
|
|
125335
125335
|
}
|
|
125336
|
+
if (!a.ancestor) {
|
|
125337
|
+
let E = null;
|
|
125338
|
+
return (e == null ? void 0 : e.type) === p.Loop || (e == null ? void 0 : e.type) === p.FunctionDeclaration && (e == null ? void 0 : e.parent.type) === p.Loop ? E = "loop-body" : (e == null ? void 0 : e.type) === p.FunctionDeclaration && (E = "entry"), {
|
|
125339
|
+
ancestor: e,
|
|
125340
|
+
callType: E
|
|
125341
|
+
};
|
|
125342
|
+
}
|
|
125336
125343
|
return a;
|
|
125337
125344
|
}
|
|
125338
125345
|
function Mm(d, u) {
|
package/dist/index.umd.cjs
CHANGED
|
@@ -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.`;c.push(new pe({id:`${l.id}--${H.InvalidReference}`,code:H.InvalidReference,severity:ee.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:c,modifiedData:l}}validateGeneratedUpdate(i){const a=[];return i.parent&&a.push(new pe({id:`${this.id}--${H.InvalidParentUpdate}`,code:H.InvalidParentUpdate,severity:ee.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,L.sessionAuthor,B().toISOString(),this,!0,"sync-dependents"))){const a=[],l=[],c=[],e=[];return Object.values(this.detachedDependents).forEach(y=>{const v=y.entity.afterAllChildrenInitialized(i);a.push(...v.updated),l.push(...v.added),c.push(...v.removed),e.push(...v.affected)}),i==null||i.attemptAutoclose("sync-dependents",this.id),{updated:C(a),added:C(l),removed:C(c),affected:C(e),self:this}}onDetachedDependencyRemoved(i,a,l){const c=[],e=[],y=[],v=[];if(a==="function-call-declaration-field"){const{updated:T,added:I,removed:b}=this.remove({ignoreUpstream:!1},l);c.push(...T),e.push(...I),y.push(...b)}if(a==="function-call-parent-field"){const{updated:T,added:I,removed:b}=this.remove({ignoreUpstream:!1},l);c.push(...T),e.push(...I),y.push(...b)}return{updated:C(c),added:C(e),removed:C(y),affected:C(v),self:this}}onDetachedDependencyRestored(i,a,l){const c=[],e=[],y=[],v=[];if(a==="function-call-declaration-field"){const{updated:T,added:I,removed:b}=this.restore({},l);c.push(...T),e.push(...I),y.push(...b)}if(a==="function-call-parent-field"){const{updated:T,added:I,removed:b}=this.restore({},l);c.push(...T),e.push(...I),y.push(...b)}return{updated:C(c),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=L.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=[],c=[],e=[];if(this.parent){this.parent.increaseVersion(i);const y=this.parent.recursiveCaptureUpstreamVersions(i);a.push(this.parent,...y.updated),l.push(...y.added),c.push(...y.removed)}return{updated:C(a),added:C(l),removed:C(c),affected:C(e),self:this}}async restoreVersion(i){var v;const a=[],l=[],c=[],e=[];if(this.version===i)return{updated:C(a),added:C(l),removed:C(c),affected:C(e),self:this};if(!this.knownVersions){const T=new Map;for(const[I,b]of this.knownVersions||new Map){if(T.set(I,b),b.activeVersion=!1,b.knownVersions)for(const[D,V]of b.knownVersions)T.set(D,V);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(c),affected:C(e),self:this}}updateWithShallowTransfer(i,a=this.project.addChangeSet(new G(this.project,L.sessionAuthor,B().toISOString(),this,!0,P.UpdateWithShallowTransfer))){if(!this.checkCanEdit(this,a))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=te(i.parent),c=this.project.get(l),e=this.parent;if(e&&e.id!==(c==null?void 0:c.id)&&this.removeFromParent(a),c)this.setParent(c,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=te(i.declaration),c=this.project.get(l);c&&this.setDeclaration(c)}return i.calledByEntry.forEach(l=>{const c=te(l),e=this.project.get(c);e&&(this.addEntryCaller(e,a),e.addCall(this,a))}),[...this.calledByEntry].forEach(l=>{i.calledByEntry.find(e=>te(e)===l.id)||(this.removeCaller(l,a),l.removeCall(this,a))}),i.calledBySuccess.forEach(l=>{const c=te(l),e=this.project.get(c);e&&(this.addSuccessCaller(e,a),e.addSuccessCall(this,a))}),[...this.calledBySuccess].forEach(l=>{i.calledBySuccess.find(e=>te(e)===l.id)||(this.removeCaller(l,a),l.removeCall(this,a))}),i.calledByError.forEach(l=>{const c=te(l),e=this.project.get(c);e&&(this.addErrorCaller(e,a),e.addErrorCall(this,a))}),[...this.calledBySuccess].forEach(l=>{i.calledBySuccess.find(e=>te(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=[],c=[];if(this.initialData.parent){const e=te(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=te(this.initialData.declaration),y=this.project.get(e);y&&(this.setDeclaration(y),i.push(y))}return this.initialData.calledByEntry.forEach(e=>{const y=te(e),v=this.project.get(y);v&&this.addEntryCaller(v,null)}),this.initialData.calledBySuccess.forEach(e=>{const y=te(e),v=this.project.get(y);v&&this.addSuccessCaller(v,null)}),this.initialData.calledByError.forEach(e=>{const y=te(e),v=this.project.get(y);v&&this.addErrorCaller(v,null)}),{updated:C(i),added:C(a),removed:C(l),affected:C(c),self:this}}afterAllChildrenInitialized(i=this.project.addChangeSet(new G(this.project,L.sessionAuthor,B().toISOString(),this,!0,P.AfterAllChildrenInitialized))){if(!this.checkCanEdit(this,i))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=[],c=[],e=[];this.initialized=!0;const{updated:y,added:v,removed:T}=this.syncInputs(i),{updated:I,added:b,removed:D}=this.syncOutputs(i);return a.push(...y,...I),l.push(...v,...b),c.push(...T,...D),this.captureVersion(),i==null||i.attemptAutoclose(P.AfterAllChildrenInitialized,this.id),{updated:C(a),added:C(l),removed:C(c),affected:C(e),self:this}}addSelfToProject(i=this.project.addChangeSet(new G(this.project,L.sessionAuthor,B().toISOString(),this,!0,"add-self-to-project"))){const a=[this],l=[],c=[],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(c),affected:C(e),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}removeInput(i,a=this.project.addChangeSet(new G(this.project,L.sessionAuthor,B().toISOString(),this,!0,P.RemoveInput))){if(!this.checkCanEdit(this,a))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(c=>c.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,L.sessionAuthor,B().toISOString(),this,!0,P.AddInput))){return this.checkCanEdit(this,a)?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,L.sessionAuthor,B().toISOString(),this,!0,"add-output"))){return this.checkCanEdit(this,a)?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,L.sessionAuthor,B().toISOString(),this,!0,"remove-output"))){if(!this.checkCanEdit(this,a))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(c=>c.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,L.sessionAuthor,B().toISOString(),this,!0,P.AddValueReader))){return this.checkCanEditFromScopeOwnerWithSideEffects(this,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,L.sessionAuthor,B().toISOString(),this,!0,P.RemoveValueReader))){return this.checkCanEditFromScopeOwnerWithSideEffects(this,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,L.sessionAuthor,B().toISOString(),this,!0,P.AddSuccessCaller)),l=!1){return this.checkCanEditWithCounterpartAndSideEffects(this,i,P.AddSuccessCaller,a)?(this.calledBySuccess.find(c=>c.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,L.sessionAuthor,B().toISOString(),this,!0,P.AddErrorCaller)),l=!1){return this.checkCanEditWithCounterpartAndSideEffects(this,i,P.AddErrorCaller,a)?(this.calledByError.find(c=>c.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,L.sessionAuthor,B().toISOString(),this,!0,P.AddEntryCaller)),l=!1){return this.checkCanEditWithCounterpartAndSideEffects(this,i,P.AddEntryCaller,a)?(this.calledByEntry.find(c=>c.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,L.sessionAuthor,B().toISOString(),this,!0,P.AddErrorCall)),l=!1){return this.checkCanEditWithCounterpartAndSideEffects(this,i,P.AddErrorCall,a)?(this.errorCalls.find(c=>c.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,L.sessionAuthor,B().toISOString(),this,!0,P.AddSuccessCall)),l=!1){return this.checkCanEditWithCounterpartAndSideEffects(this,i,P.AddSuccessCall,a)?(this.successCalls.find(c=>c.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,L.sessionAuthor,B().toISOString(),this,!0,P.RemoveCall)),l=!1){if(!this.checkCanEditWithCounterpartAndSideEffects(this,i,P.RemoveCall,a))return this;const c=this.successCalls.findIndex(y=>y.id===i.id);c>-1&&(this.successCalls.splice(c,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,L.sessionAuthor,B().toISOString(),this,!0,"remove-caller")),l=!1){return this.checkCanEditWithCounterpartAndSideEffects(this,i,P.RemoveCaller,a)?(this.calledBySuccess=this.calledBySuccess.filter(c=>c.id!==i.id?!0:(a==null||a.add(this,k.Updated),a==null||a.add(c,k.Affected),!1)),this.calledByError=this.calledByError.filter(c=>c.id!==i.id?!0:(a==null||a.add(this,k.Updated),a==null||a.add(c,k.Affected),!1)),this.calledByEntry=this.calledByEntry.filter(c=>c.id!==i.id?!0:(a==null||a.add(this,k.Updated),a==null||a.add(c,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,L.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,L.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=se(this.initialData.declaration,this.project);this.declaration=a}else{const a=te(this.initialData.declaration),l=this.project.get(a);this.declaration=l}return this.successCalls=this.initialData.successCalls.map(a=>{const l=se(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 c=Rr(this,this.project);l.setParent(c,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=se(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 c=Rr(this,this.project);l.setParent(c,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=se(a,this.project);return l.setParent(this,null),l.initChildren(i),l}),this.initialData.error&&(this.error=se(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,L.sessionAuthor,B().toISOString(),this,!0,"meta-sync"))){const l=sr(this,i,a),c=nr(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,a),l.deleted===!0&&!e.deleted?a==null||a.add(this,k.Removed):l.deleted===!1&&e.deleted?a==null||a.add(this,k.Added):c&&(a==null||a.add(this,k.Updated)),a==null||a.attemptAutoclose("meta-sync",this.id),this}async APILoad(i=we,...a){return await yi.repository.APILoad(this.id,...a),this}async APICreate(i=we,...a){return await yi.repository.APICreate(this.toShallowJSON(),...a),this}async APIUpdate(i=we,...a){return await yi.repository.APIUpdate(this.toShallowJSON(),...a),this}async APIDelete(i=we,...a){return await yi.repository.APIDelete(this.toShallowJSON(),...a),this}async APIClone(i=we,...a){return await yi.repository.APIClone(this.id,...a),this}async APILoadVersion(i=we,a,...l){return await yi.repository.APILoadVersion(this.id,a,...l)}removeFromParent(i=this.project.addChangeSet(new G(this.project,L.sessionAuthor,B().toISOString(),this,!0,P.RemoveFromParent))){if(!this.checkCanEdit(this,i))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=[],c=[],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(c),updated:C(a),removed:C(l),affected:C(e),self:this}}remove({ignoreUpstream:i}={ignoreUpstream:!1},a=this.project.addChangeSet(new G(this.project,L.sessionAuthor,B().toISOString(),this,!0,P.RemoveEntity))){var v;if(!this.checkCanDelete(this,a))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:ji.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=[],c=[],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(c.push(this),this.unsubscribe(),this.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},a),Object.values(this.detachedDependents).forEach(T=>{const{updated:I,removed:b,added:D}=T.entity.onDetachedDependencyRemoved(this,T.field,a);l.push(...I),c.push(...b),e.push(...D)}),this.inputs.forEach(T=>{const{updated:I,removed:b}=T.remove({ignoreUpstream:!0},a);l.push(...I),c.push(...b)}),this.outputs.forEach(T=>{const{updated:I,removed:b}=T.remove({ignoreUpstream:!0},a);l.push(...I),c.push(...b)}),this.error){const{updated:T,removed:I}=this.error.remove({ignoreUpstream:!0},a);l.push(...T),c.push(...I)}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),c.push(...T.removed),y.push(...T.affected),this.calledBy.forEach(I=>{l.push(I),I.removeCall(this,a)})}return a==null||a.attemptAutoclose(P.RemoveEntity,this.id),{added:C(e),updated:C(l),removed:C(c),affected:C(y),self:this}}restore({}={},i=this.project.addChangeSet(new G(this.project,L.sessionAuthor,B().toISOString(),this,!0,P.RestoreEntity))){if(!this.checkCanEdit(this,i))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=[],c=[],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:I}=y.entity.onDetachedDependencyRestored(this,y.field,i);l.push(...v),c.push(...T),a.push(...I)}),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(c),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,c,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)),(c=i.seenEntities)!=null&&c.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:L.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(I=>I.toJSONClone({...i,newId:null})),successCalls:this.successCalls.map(I=>I.toJSONClone({...i,newId:null})),errorCalls:this.errorCalls.map(I=>I.toJSONClone({...i,newId:null})),calledBySuccess:this.calledBySuccess.map(I=>I.toReference({seenEntityMaps:i.seenEntityMaps})),calledByError:this.calledByError.map(I=>I.toReference({seenEntityMaps:i.seenEntityMaps})),calledByEntry:this.calledByEntry.map(I=>I.toReference({seenEntityMaps:i.seenEntityMaps})),declaration:this.declaration.toJSONClone({...i,newId:null}),inputs:this.inputs.map(I=>I.toJSONClone({...i,newId:null})),outputs:this.outputs.map(I=>I.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+"--"+L.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(c=>c.toReference(i)),inputs:this.inputs.map(c=>c.toReference(i)),outputs:this.outputs.map(c=>c.toReference(i)),declaration:this.declaration.toReference(i),successCalls:this.successCalls.map(c=>c.toReference(i)),errorCalls:this.errorCalls.map(c=>c.toReference(i)),calledBySuccess:this.calledBySuccess.map(c=>c.toReference(i)),calledByError:this.calledByError.map(c=>c.toReference(i)),calledByEntry:this.calledByEntry.map(c=>c.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=mH(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,L.sessionAuthor,B().toISOString(),this,!0,P.CloneEntity)),a=null,l=null,c=!0){var M,x;let e=fr(a,this);const y=this.toJSON(),v=l||L.UUID.uuid();y.inputs=[];const T=v.split("-id"),I=T[T.length-1||0]||v;y.id=v,y.version=L.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),c&&b.subscribe(),b.initChildren(i),i==null||i.add(b,k.Added);const D=(M=this.inputs)==null?void 0:M.map((q,Z)=>q.clone(i,b,I+"-input-map-"+Z+"-id",c));b.inputs=D;const V=(x=this.outputs)==null?void 0:x.map((q,Z)=>q.clone(i,b,I+"-output-map-"+Z+"-id",c));return b.outputs=V,this.error&&(b.error=this.error.clone(i,b,I+"-error-map-id",c)),i==null||i.attemptAutoclose(P.CloneEntity,this.id),b}removeUnrecognizedInputs(i=this.project.addChangeSet(new G(this.project,L.sessionAuthor,B().toISOString(),this,!0,P.RemoveUnrecognizedInputs))){if(!this.checkCanEdit(this,i))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=[],c=[],e=[];return this.inputs.forEach(v=>{if(!this.declaration.inputs.find(I=>{var b;return I.id===((b=v.declaration)==null?void 0:b.id)})){const I=v.remove({ignoreUpstream:!1},i);c.push(...I.removed),a.push(...I.updated)}}),this.inputs.filter((v,T)=>{const I=this.inputs.findIndex(D=>D.declaration===v.declaration&&D!==v);if(I===-1)return!1;const b=this.inputs[I];return B(b==null?void 0:b.createdAt).isSame(B(v.createdAt))?T>I:!!B(b==null?void 0:b.createdAt).isAfter(v.createdAt)}).forEach(v=>{const T=v.remove({ignoreUpstream:!1},i);c.push(...T.removed),a.push(...T.updated)}),i==null||i.attemptAutoclose(P.RemoveUnrecognizedInputs,this.id),{updated:C(a),added:C(l),removed:C(c),affected:C(e),self:this}}removeUnrecognizedOutputs(i=this.project.addChangeSet(new G(this.project,L.sessionAuthor,B().toISOString(),this,!0,P.RemoveUnrecognizedOutputs))){var T,I;if(!this.checkCanEdit(this,i))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=[],c=[],e=[],y=((I=(T=this.declaration.dataType)==null?void 0:T.entity)==null?void 0:I.properties)||[];return this.outputs.forEach(b=>{if(!y.find(V=>{var M;return V.id===((M=b.declaration)==null?void 0:M.id)})){const V=b.remove({ignoreUpstream:!1},i);c.push(...V.removed),a.push(...V.updated)}}),this.outputs.filter((b,D)=>{const V=this.outputs.findIndex(x=>x.declaration===b.declaration&&x!==b);if(V===-1)return!1;const M=this.outputs[V];return B(M==null?void 0:M.createdAt).isSame(B(b.createdAt))?D>V:!!B(M==null?void 0:M.createdAt).isAfter(b.createdAt)}).forEach(b=>{const D=b.remove({ignoreUpstream:!1},i);c.push(...D.removed),a.push(...D.updated)}),i==null||i.attemptAutoclose(P.RemoveUnrecognizedOutputs,this.id),{updated:C(a),added:C(l),removed:C(c),affected:C(e),self:this}}syncInputs(i=this.project.addChangeSet(new G(this.project,L.sessionAuthor,B().toISOString(),this,!0,P.SyncInputs))){if(!this.checkCanEdit(this,i))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=[],c=[],e=[],y=this.declaration.inputs.filter(b=>!this.inputs.find(D=>D.declaration.id===b.id));this.inputs.sort((b,D)=>b.index-D.index),y.forEach(b=>{this.inputs.forEach(M=>{M.index>=b.index&&M.metaSync({index:M.index+1},i)});const D={id:L.UUID.uuid(),version:L.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||B().toISOString(),author:L.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()},V=se(D,this.project);V.setParent(this,i),V.initChildren(i),i==null||i.add(V,k.Added),V.addSelfToProject(i),l.push(V)}),this.inputs.sort((b,D)=>b.index-D.index);const{updated:v,added:T,removed:I}=this.removeUnrecognizedInputs(i);return a.push(...v),l.push(...T),c.push(...I),i==null||i.attemptAutoclose(P.SyncInputs,this.id),{updated:C(a),added:C(l),removed:C(c),affected:C(e),self:this}}syncOutputs(i=this.project.addChangeSet(new G(this.project,L.sessionAuthor,B().toISOString(),this,!0,P.SyncOutputs))){var D,V;if(!this.checkCanEdit(this,i))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=[],c=[],e=[],y=[];this.outputs=this.initialData.outputs.reduce((M,x)=>{if(x.type===p.GenericReference){const Z=an(x,this.project);return Z?[...M,Z]:M}const q=se(x,this.project);return y.push(q.index),q.setParent(this,null),q.initChildren(i),[...M,q]},[]);const v=(((V=(D=this.declaration.dataType)==null?void 0:D.entity)==null?void 0:V.properties)||[]).filter(M=>!this.outputs.find(x=>{var q;return((q=x.declaration)==null?void 0:q.id)===M.id}));this.outputs.sort((M,x)=>M.index-x.index),v.forEach((M,x)=>{this.outputs.forEach(Y=>{Y.index>=M.index&&Y.index++});const q=y.includes(M.index)?this.outputs.length-1+x:M.index,Z={id:L.UUID.uuid(),version:L.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||B().toISOString(),author:L.sessionAuthor,previousVersion:null,deleted:!1,deletable:!0,editable:!0,type:p.OutputMap,declaration:M.toJSON(),writesValues:[],index:q,parent:this.toReference()},W=se(Z,this.project);W.setParent(this,i),W.initChildren(i),i==null||i.add(W,k.Added),W.addSelfToProject(i)}),this.outputs.sort((M,x)=>M.index-x.index);const{updated:T,added:I,removed:b}=this.removeUnrecognizedOutputs(i);return a.push(...T),l.push(...I),c.push(...b),i==null||i.attemptAutoclose(P.SyncOutputs,this.id),{updated:C(a),added:C(l),removed:C(c),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,L.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",[...Qi,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 Io=yi;function Zw(d){return d&&typeof d.then=="function"}function hNe(d){const u=new Da(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 mNe(d){const u=new Da(Object.values(d)[0]),i=Object.keys(d);return u.order=i,u.flatRecord=d,u.orderEntities(),u.order}class Da{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(Ee(u,i,{ignoreBuiltInBaseEntities:!0})),l=new Set;for(const c of a)this.flatRecord[c.id]=c,l.add(c.id);this.order=Array.from(l)}moveEntityAfterDependencies(u){const{upstream:i}=pp(u,this.flatRecord,{ignoreBuiltInBaseEntities:!0,allBuiltInEntityIds:this.allBuiltInEntityIds});for(const a of Object.keys(i)){const l=this.order.indexOf(a),c=this.order.indexOf(u.id);if(l>c)return this.order.splice(c,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}=pp(this.flatRecord[u],this.flatRecord,{ignoreBuiltInBaseEntities:!0,allBuiltInEntityIds:this.allBuiltInEntityIds}),l={};return Object.entries(this.onGoingVisits[i]||{}).forEach(([c,e])=>{Object.keys(a).includes(c)&&(l[c]=e)}),l}getDownstreamOngoingDependenciesVisits(u,i){const a=Object.keys(this.onGoingVisits[i]||{}),l=new Set(a.flatMap(e=>Object.keys(pp(this.flatRecord[e],this.flatRecord,{ignoreBuiltInBaseEntities:!0,allBuiltInEntityIds:this.allBuiltInEntityIds}).downstream))),c={};return Array.from(l).forEach(e=>{e===u&&(c[e]=this.onGoingVisits[i][e])}),c}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 c=this.getUpstreamOngoingDependenciesVisits(l,a);Object.keys(c).length&&await this.settlePromises(c,a);const e=u(this.flatRecord[l],this.flatRecord);Zw(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 c=this.getDownstreamOngoingDependenciesVisits(l,a);Object.keys(c).length&&await this.settlePromises(c,a);const e=u(this.flatRecord[l],this.flatRecord);Zw(e)&&(this.onGoingVisits[a][l]=e)}return await this.settlePromises(this.onGoingVisits[a],a),this.onGoingVisits[a]={},this}}const vNe=63,TNe=/^[a-z][a-z0-9-]*[a-z0-9]$/;function ENe(d){return d.length>=1&&d.length<=vNe&&TNe.test(d)&&!d.includes("--")}function*bNe(){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 INe(d,u){const i=new Set(d.map(l=>l.toLowerCase())),a=u>0?"secondary-db":"main";for(const l of bNe()){const c=l?`${a}-${l}`:a;if(ENe(c)&&!i.has(c))return c}throw new Error("Unable to generate identifier")}function vH(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(D=>D.implements.find(V=>V.id===ce["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.default.id)),I=T==null?void 0:T.getDefaultValue();return(I==null?void 0:I.value)===!0});if(!a&&i.length){const T=i[0].properties.find(b=>b.implements.find(D=>D.id===ce["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.default.id)),I=T==null?void 0:T.defaultValue;if(I)I.metaSync({value:!0},u);else if(T!=null&&T.dataType){const b={id:L.UUID.uuid(),version:L.UUID.uuid(),createdAt:(u==null?void 0:u.timestamp)||new Date().toISOString(),author:L.sessionAuthor,previousVersion:null,deleted:!1,deletable:!0,editable:!0,type:p.LiteralValue,standaloneParent:null,name:ie.EntityTemplate,autogeneration:null,value:!0,valueAsTypeSingle:null,valueAsTypeList:null,parent:T==null?void 0:T.toReference()},D=se(b,d.project);return D.setParent(T,u),D.initChildren(u),u==null||u.add(D,k.Added),D.addSelfToProject(u),{newEntities:[D]}}return{newEntities:[]}}else if(a)return{newEntities:[]};const l=d.project.get(ce["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.id),c=q0(l,"Main database",u);if(c.errors.length>0)return{newEntities:[]};const e=c.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:L.UUID.uuid(),version:L.UUID.uuid(),createdAt:(u==null?void 0:u.timestamp)||new Date().toISOString(),author:L.sessionAuthor,previousVersion:null,deleted:!1,deletable:!0,editable:!0,type:p.LiteralValue,standaloneParent:null,name:ie.EntityTemplate,autogeneration:null,value:!0,valueAsTypeSingle:null,valueAsTypeList:null,parent:e==null?void 0:e.toReference()},T=se(v,d.project);T.setParent(e,u),T.initChildren(u),u==null||u.add(T,k.Added),T.addSelfToProject(u)}return{newEntities:[c]}}}return{newEntities:[]}}function TH(d,u){const i=[],a=[],l=[],c=[];return d.implements.filter(y=>y.type===p.BuiltInBaseEntity).forEach(y=>{var v,T,I,b,D;switch(y.id){case ce["built-in-base-entity"].BUILT_IN_PERSISTED_ENTITY_ENTITY.id:{const V=d.project.entities.filter(W=>W.implements.find(Y=>Y.id===ce["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.id));let M=V.find(W=>!!W.properties.find(Y=>{var re;return Y.implements.find(z=>z.id===ce["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.default.id)&&((re=Y.getDefaultValue())==null?void 0:re.value)===!0}));if(!M&&V.length)M=V[0];else if(!M&&!V.length){M=d.project.getBuiltIn(ce["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.id).implement("Relational database",u);const Y=M.properties.find(re=>re.implements.find(z=>z.id===ce["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.default.id));(v=Y==null?void 0:Y.defaultValue)==null||v.metaSync({value:!0},u),a.push(M)}const x=d.properties.find(W=>W.implements.find(Y=>Y.id===ce["built-in-base-entity"].BUILT_IN_PERSISTED_ENTITY_ENTITY.properties.database.id));if(x&&!(x!=null&&x.defaultValue)){const W={id:L.UUID.uuid(),version:L.UUID.uuid(),createdAt:(u==null?void 0:u.timestamp)||new Date().toISOString(),author:L.sessionAuthor,previousVersion:null,deleted:!1,deletable:!0,editable:!0,type:p.LiteralValue,standaloneParent:null,name:ie.EntityTemplate,autogeneration:null,value:null,valueAsTypeSingle:(M==null?void 0:M.toJSON())||null,valueAsTypeList:null,parent:x==null?void 0:x.toReference()},Y=se(W,d.project);Y.hydrateAncestors(),Y.setParent(x,u),Y.addSelfToProject(u),u==null||u.add(Y,k.Added),Y.initChildren(u),(x==null?void 0:x.defaultValue).setValueAsTypeSingle(M||null,u),a.push(Y);return}else x!=null&&x.defaultValue&&!(x!=null&&x.defaultValue.valueAsTypeSingle)&&(x==null||x.defaultValue.setValueAsTypeSingle(M||null,u));const q=d.properties.find(W=>W.implements.find(Y=>Y.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 W=Wr.new(u);W.parent=q.toReference();const Y=se(W,d.project);Y.hydrateAncestors(),Y.setParent(q,u),Y.addSelfToProject(u),u==null||u.add(Y,k.Added),Y.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 V=d.project.entities.filter(re=>re.implements.find(z=>z.id===ce["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.id)&&re.id!==d.id),M=V.map(re=>{var le;const z=re.properties.find(ye=>ye.implements.find(he=>he.id===ce["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.identifier.id));return(le=z==null?void 0:z.getDefaultValue())==null?void 0:le.value}).filter(re=>!!re),x=d.properties.find(re=>re.implements.find(z=>z.id===ce["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.identifier.id));if(!V.find(re=>!!re.properties.find(z=>{var oe;return z.implements.find(le=>le.id===ce["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.default.id)&&((oe=z.getDefaultValue())==null?void 0:oe.value)===!0}))){const re=d.properties.find(z=>z.implements.find(oe=>oe.id===ce["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.default.id));if(!re)throw new Error("Default boolean property not found for relational database entity with id: "+d.id);if(!(re!=null&&re.defaultValue)){const z=$r.new(u);z.parent=re.toReference();const oe=se(z,d.project);oe.hydrateAncestors(),oe.setParent(re,u),oe.addSelfToProject(u),u==null||u.add(oe,k.Added),oe.initChildren(u)}(I=re==null?void 0:re.defaultValue)==null||I.metaSync({value:!0},u)}if(!x)throw new Error("Identifier property not found for relational database entity with id: "+d.id);if(!(x!=null&&x.defaultValue)){const re=$r.new(u);re.parent=x.toReference();const z=se(re,d.project);z.hydrateAncestors(),z.setParent(x,u),z.addSelfToProject(u),z.initChildren(u),u==null||u.add(z,k.Added)}const Z=INe(M,V.length);(b=x.defaultValue)==null||b.metaSync({value:Z},u);const W=d.properties.find(re=>re.implements.find(z=>z.id===ce["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.password.id));if(!W)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(!W.defaultValue){const re=$r.new(u);re.parent=W.toReference();const z=se(re,d.project);z.hydrateAncestors(),z.setParent(W,u),z.addSelfToProject(u),z.initChildren(u),u==null||u.add(z,k.Added),a.push(z)}const Y=lq(24);(D=W.defaultValue)==null||D.metaSync({value:Y},u);return}case ce["built-in-base-entity"].BUILT_IN_SQL_ROW_TRANSFORMER_ENTITY.id:{const V=d.properties.find(Z=>Z.implements.find(W=>W.id===ce["built-in-base-entity"].BUILT_IN_SQL_ROW_TRANSFORMER_ENTITY.properties.time.id));if(!V)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=V.defaultValue||null;if(!M){const Z=$r.new(u);Z.parent=V.toReference(),Z.name=ie.Date,Z.id=L.UUID.uuid(),M=se(Z,d.project),M.hydrateAncestors(),M.setParent(V,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),V.metaSync({editable:!1,deletable:!1},u);const x=d.properties.find(Z=>Z.implements.find(W=>W.id===ce["built-in-base-entity"].BUILT_IN_SQL_ROW_TRANSFORMER_ENTITY.properties.definition.id));if(!x)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=x.defaultValue||null;if(!q){const Z=$r.new(u);Z.name=ie.EntityTemplate,Z.parent=x.toReference(),Z.id=L.UUID.uuid(),q=se(Z,d.project),q.hydrateAncestors(),q.setParent(x,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(c)}}function q0(d,u,i,a){const l=a||L.UUID.uuid(),c=us.new(i);c.id=l,c.name=u,c.static=d.static,c.implements=[d.toJSON()],c.parent=d.project.toReference(),c.static=d.static,vH(d,i);const e=se(c,d.project);return e.hydrateAncestors(),i==null||i.add(e,k.Added),e.addSelfToProject(i),e.initChildren(i),TH(e,i),e.afterAllChildrenInitialized(i),e}function Ww(d,u){return u.entities.find(l=>{const c=l.properties,e=c.map(b=>b.name),y=d.every(b=>e.includes(b)),v=e.filter(b=>!d.includes(b)),T=c.every(b=>!v.includes(b.name)||!b.required);return y&&T})||null}function EH(d,u,i,a=vr.OrDataTypeGroup){const l=[],c=[],e=[],y=[],T={id:L.UUID.uuid(),version:L.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||new Date().toISOString(),author:L.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()},I=se(T,d.project);return c.push(I),I.setParent(u,i),I.initChildren(i),i==null||i.add(I,k.Added),I.setEntity(d,i),I.addSelfToProject(i),{updated:C(l),added:C(c),removed:C(e),affected:C(y),self:I}}function Hw(d,u,i,a,l){var T,I,b,D,V,M,x,q;const c=[],e=[],y=[],v=[];switch(typeof d){case"string":let Z=!1;const W=new Date(d);if(W instanceof Date&&!isNaN(W.valueOf())&&(Z=!0),Z){const Y=u.project.getBuiltIn(ce[p.PrimitiveEntity][ie.Date].id);u.setEntity(Y,a);break}else{const Y=u.project.getBuiltIn(ce[p.PrimitiveEntity][ie.String].id);u.setEntity(Y,a);break}case"number":u.setEntity(u.project.getBuiltIn(ce[p.PrimitiveEntity][ie.Number].id),a);break;case"boolean":u.setEntity(u.project.getBuiltIn(ce[p.PrimitiveEntity][ie.Boolean].id),a);break;case"object":if(d===null){u.setEntity(u.project.getBuiltIn(ce[p.PrimitiveEntity][ie.Null].id),a);break}else if(Array.isArray(d))if(u.metaSync({isList:!0},a),d.length>0){const Y=d.slice(0,5).filter(z=>z!==void 0);if(Y.every(z=>typeof z==typeof Y[0])&&(typeof Y[0]!="object"||Y[0]===null))switch(typeof Y[0]){case"string":u.setEntity(u.project.getBuiltIn(ce[p.PrimitiveEntity][ie.String].id),a);break;case"number":u.setEntity(u.project.getBuiltIn(ce[p.PrimitiveEntity][ie.Number].id),a);break;case"boolean":u.setEntity(u.project.getBuiltIn(ce[p.PrimitiveEntity][ie.Boolean].id),a);break;case"object":u.setEntity(u.project.getBuiltIn(ce[p.PrimitiveEntity][ie.Null].id),a);break}else{const z=[];let oe=!1;Y.forEach(ye=>{var he,Q,ue,Te;if(Array.isArray(ye)&&(oe=!0),typeof ye=="object"&&!Array.isArray(ye)&&ye!==null){const _e=Z0(ye,u.project,{...i,id:L.UUID.uuid()},a,l);_e.hasCreated&&z.push((he=_e.changeSet)==null?void 0:he.self),c.push(...(Q=_e.changeSet)==null?void 0:Q.updated),e.push(...(ue=_e.changeSet)==null?void 0:ue.added),y.push(...(Te=_e.changeSet)==null?void 0:Te.removed)}});const le=C(z);if(!le.length&&!oe){Y.forEach(ye=>{const he={id:L.UUID.uuid(),version:L.UUID.uuid(),createdAt:(a==null?void 0:a.timestamp)||new Date().toISOString(),author:L.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:vr.OrDataTypeGroup,parent:u.toReference()},Q=se(he,u.project);switch(Q.setParent(u,a),Q.initChildren(a),a==null||a.add(Q,k.Added),Q.addSelfToProject(a),typeof ye){case"string":Q.setEntity(Q.project.getBuiltIn(ce[p.PrimitiveEntity][ie.String].id),a);break;case"number":Q.setEntity(Q.project.getBuiltIn(ce[p.PrimitiveEntity][ie.Number].id),a);break;case"boolean":Q.setEntity(Q.project.getBuiltIn(ce[p.PrimitiveEntity][ie.Boolean].id),a);break;case"object":Q.setEntity(Q.project.getBuiltIn(ce[p.PrimitiveEntity][ie.Null].id),a);break}});break}else le.length===1&&!oe?u.setEntity(le[0],a):Y.forEach(ye=>{if(typeof ye=="object"&&!Array.isArray(ye)&&ye!==null){const he=Ww(Object.keys(ye),u.project);if(he){const Q=EH(he||le[0],u,a,vr.OrDataTypeGroup);c.push(...Q.updated),e.push(...Q.added),y.push(...Q.removed)}}else{const he={id:L.UUID.uuid(),version:L.UUID.uuid(),createdAt:(a==null?void 0:a.timestamp)||new Date().toISOString(),author:L.sessionAuthor,previousVersion:null,deleted:!1,deletable:!0,editable:!0,type:p.DataType,options:null,implementationChooseOne:!1,entity:null,isList:Array.isArray(ye),asType:!1,andChildrenGroup:null,index:null,orChildrenGroup:null,staticEntities:!1,interactiveEntities:!0,actionEntities:!1,like:!0,inferred:!1,parentRelationType:vr.OrDataTypeGroup,parent:u.toReference()},Q=se(he,u.project);Q.setParent(u,a),Q.initChildren(a),a==null||a.add(Q,k.Added),Q.addSelfToProject(a);const ue=Hw(ye,Q,{...i,id:L.UUID.uuid()},a,l);c.push(...ue.updated),e.push(...ue.added),y.push(...ue.removed)}})}}else{const Y=Z0(d[0],u.project,{...i},a,l);u.setEntity((T=Y.changeSet)==null?void 0:T.self,a),c.push(...(I=Y.changeSet)==null?void 0:I.updated),e.push(...(b=Y.changeSet)==null?void 0:b.added),y.push(...(D=Y.changeSet)==null?void 0:D.removed);break}else{const Y=Z0(d,u.project,{...i},a,l);u.setEntity((V=Y.changeSet)==null?void 0:V.self,a),c.push(...(M=Y.changeSet)==null?void 0:M.updated),e.push(...(x=Y.changeSet)==null?void 0:x.added),y.push(...(q=Y.changeSet)==null?void 0:q.removed);break}}return{updated:C(c),added:C(e),removed:C(y),affected:C(v),self:u}}function Z0(d,u,i,a,l){const c=[],e=[],y=[],v=[],T=Object.keys(d),I=Ww(T,u);if(I)return{hasCreated:!1,changeSet:{updated:[],added:[],removed:[],affected:[],self:I}};const b=l?i.name+" of "+l.name:i.name,V={id:i.id||L.UUID.uuid(),version:L.UUID.uuid(),createdAt:(a==null?void 0:a.timestamp)||new Date().toISOString(),author:L.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=se(V,u);return M.setParent(u,a),M.initChildren(a),a==null||a.add(M,k.Added),M.addSelfToProject(a),e.push(M),T.forEach((x,q)=>{const W={id:L.UUID.uuid(),version:L.UUID.uuid(),createdAt:(a==null?void 0:a.timestamp)||new Date().toISOString(),author:L.sessionAuthor,previousVersion:null,deleted:!1,name:x,deletable:!0,editable:!0,type:p.Property,parentRelationType:null,codeName:x,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()},Y=se(W,u);Y.setParent(M,a),Y.initChildren(a),a==null||a.add(Y,k.Added),Y.addSelfToProject(a),e.push(Y);const re=d[x],oe={id:L.UUID.uuid(),version:L.UUID.uuid(),createdAt:(a==null?void 0:a.timestamp)||new Date().toISOString(),author:L.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:Y.toReference()},le=se(oe,u);le.setParent(Y,a),le.initChildren(a),a==null||a.add(le,k.Added),le.addSelfToProject(a),e.push(le);const ye=Hw(re,le,{...i,name:x,id:L.UUID.uuid()},a,l||M);c.push(...ye.updated),e.push(...ye.added),y.push(...ye.removed)}),{hasCreated:!0,changeSet:{updated:C(c),added:C(e),removed:C(y),affected:C(v),self:M}}}function Tl(d,u,i,a){const l=[];return!d.length||!u.length?{errors:l,overlap:!1}:(d.length>u.length?d.forEach(c=>{const e=u.find(v=>v.name===c.name),y=u.find(v=>{var T,I;return Array.isArray(v.implements)?v.implements.some(b=>!!c.implements.find(D=>D.id===b.id)):((T=v.implements)==null?void 0:T.id)===((I=c.implements)==null?void 0:I.id)});if(e){const v=new vi({id:c.id+"--"+e.id+"--"+a,message:`Entity of type ${c.type} named "${c.name}" with id "${c.id}" overrides a base ${e.type} ${e.name} with id "${e.id}" that has the same name`,severity:ee.Error,code:a,entity:c,firstRelationship:e});l.push(v)}if(y){const v=new vi({id:c.id+"--"+y.id+"--"+i,message:`Entity of type ${c.type} named "${c.name}" with id "${c.id}" overrides a base ${y.type} ${y.name} with id "${y.id}" that implements the same base descriptor`,severity:ee.Error,code:i,entity:c,firstRelationship:y});l.push(v)}}):u.forEach(c=>{var v;const e=d.find(T=>T.name===c.name),y=d.find(T=>{var I,b;return T.implements&&Array.isArray(T.implements)?T.implements.some(D=>!!c.implements.find(V=>V.id===D.id)):((I=T.implements)==null?void 0:I.id)===((b=c.implements)==null?void 0:b.id)});if(e){const T=new vi({id:e.id+"--"+c.id+"--"+a,message:`Entity of type ${e.type} named "${e.name}" with id "${e.id}" overrides a base entity ${c.name} with id "${c.id}" that has the same name`,severity:ee.Error,code:a,entity:e,firstRelationship:c});l.push(T)}if(y){const T=new vi({id:y.id+"--"+c.id+"--"+i,message:`Entity of type ${y.type} named "${y.name}" with id "${y.id}" overrides a base entity ${c.name} with id "${c.id}" that implements the same base ${Array.isArray(y==null?void 0:y.implements)?yt(y==null?void 0:y.implements.map(I=>I.type),"', '","' and '"):(v=y.implements)==null?void 0:v.id}`,severity:ee.Error,code:i,entity:y,firstRelationship:c});l.push(T)}}),{errors:l,overlap:!!l.length})}function ANe(d,u){return d.abstract||(d.properties.forEach(a=>{a.abstract||a.metaSync({abstract:!0},u)}),Object.values(d.detachedDependents).forEach(a=>{a.field===uA.Entity&&a.entity.remove({ignoreUpstream:!1},u)}),d.metaSync({abstract:!0},u)),d}function wNe(d,u){return d.abstract&&(d.properties.forEach(a=>{a.abstract&&a.metaSync({abstract:!1},u)}),Object.values(d.detachedDependents).forEach(a=>{(a.field===dv.Implements||a.field===dv.Extends)&&a.entity.onDetachedDependencyRemoved(d,a.field,u)}),d.metaSync({abstract:!1},u)),d}function RNe(d,u){return d.static||(d.properties.forEach(a=>{a.static||a.metaSync({static:!0},u)}),d.metaSync({static:!0},u)),d}function CNe(d,u){return d.static&&d.metaSync({static:!1},u),d}var mn=(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))(mn||{});function zw(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:ee.Error,code:"string-value-must-not-have-spaces",entity:d});i.push(l)}return{errors:i,override:a.replace(/\s/g,"-")}}function bH(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:ee.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:ee.Error,code:"string-value-must-not-have-dashes",entity:d});i.push(l)}return{errors:i,override:a.replace(/\s|-/g,"_")}}function Jw(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 Wr||d.increaseVersion)return`${d.type}: ${d.id} (${Tp(d)})`;try{const a=Tp(d);return`${d.type}: ${d.id} (${a})`}catch{}}return`${d.type}: ${d.id} (${S(d,u)})`}function op(d,u){const i=Ro(d);if(i.length===0)return{list:[],last:null};let a=null;return{list:i.flatMap(c=>{if(c===u)return a=c,[c];const e=op(c,u);return e.last&&(a=e.last),[c,...e.list]}),last:a}}function Ao(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,Gt.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(!Mr.includes(e.type))return[e];const y=Ao(e,u);return y.last&&(a=y.last,l=y.callType),[e,...y.list]}),last:a,callType:l}}function gNe(d,u){if(d===u)return"same-entity";if(!Dr.includes(d.type)||!wo(d).find(l=>l.callee===u))return null;if(Gt.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 yy(d){const u=zr(d,d.project);return u?Gt.includes(u.type)?u:u.type===p.Loop?u.body:null:null}function Yw(d,u){const i=d.calledBy;return!i||!i.length?!1:i.every(a=>a===u?!0:Mr.includes(a.type)?!!Ao(a,u).last:!1)}function IH(d){return d.filter(u=>{const i=yy(u);return!d.filter(c=>c!==u).some(c=>c===i?!1:z0(c,u))})}function Sw(d){if(!d.calledBy||!d.calledBy.length)return[];const u=d.calledBy.reduce((i,a)=>{if(Mr.includes(a.type)){const l=Sw(a);return[...i,a,...l]}return i},[]);return C(u)}function AH(d){const u=Sw(d);if(!u.length)return{ancestor:null,callType:null};const a=u.filter(c=>!(c===d||!Dr.includes(c.type)||!ht(c).find(v=>v===d))).filter((c,e,y)=>y.findIndex(v=>v===c)===e).filter(c=>Yw(d,c)),l=a.filter(c=>{const e=ht(c),y=a.filter(T=>T!==c).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 c=l[0];if(c.type===p.Loop){if(c.body.calls.includes(d))return{ancestor:c,callType:"loop-body"}}else if(Gt.includes(c.type)){if(c.calls.includes(d))return c.type===p.FunctionDeclaration&&c.parent.type===p.Loop?{ancestor:c,callType:"loop-body"}:{ancestor:c,callType:"entry"}}else if(mi.includes(c.type)){if(c.successCalls.includes(d))return{ancestor:c,callType:"success"};if(c.errorCalls.includes(d))return{ancestor:c,callType:"error"}}}if(l.length>1)throw new Error(`resolveEarliestSingleCallerAncestor: Multiple callers found for entity ${d.id}.`);return{ancestor:l[0],callType:null}}function _Ne(d,u,i){var y,v,T,I;const a={ancestor:null,callType:null};if(!d)throw new Error("[findNextCombinedSingleCallerAncestor] No 'targetA' given");if(!u)throw new Error("[findNextCombinedSingleCallerAncestor] No 'targetB' given");if((d==null?void 0:d.id)===(u==null?void 0:u.id))if(Dr.includes(d.type)){let b=null;return d.type===p.Loop||d.type===p.FunctionDeclaration&&d.parent.type===p.Loop?b="loop-body":d.type===p.FunctionDeclaration&&(b="entry"),{ancestor:d,callType:b}}else{if(Mr.includes(d.type))return hy(d,i);throw new Error(`[findNextCombinedSingleCallerAncestor] Invalid 'targetA' and 'targetB' arguments, neither is a callable or caller entity: ${d.type} -- ${d.id}`)}if(i){const b=wo(i),D=b.find(M=>M.callee===d),V=b.find(M=>M.callee===u);if(!D)throw new Error(`[findNextCombinedSingleCallerAncestor] Invalid 'from' argument, doesn't contain 'targetA' entity ${d.type} -- ${d.id}`);if(!V)throw new Error(`[findNextCombinedSingleCallerAncestor] Invalid 'from' argument, doesn't contain 'targetB' entity ${u.type} -- ${u.id}`)}const l=Il(d,d.project),c=Il(u,u.project);if((l==null?void 0:l.id)!==(c==null?void 0:c.id))return a;let e=i||l;if(!e)return{ancestor:null,callType:null};if(!Dr.includes(e.type))throw new Error(`[findNextCombinedSingleCallerAncestor] Invalid 'from' argument, is not a caller entity: ${e.type} -- ${e.id}`);if(Mr.includes(d.type)&&Mr.includes(u.type)){const b=hy(d,e),D=hy(u,e),V=wo(b.ancestor),M=wo(D.ancestor);((y=D.ancestor)==null?void 0:y.id)===((v=b.ancestor)==null?void 0:v.id)||((T=D.ancestor)==null?void 0:T.id)===d.id?(a.ancestor=D.ancestor,a.callType=D.callType):((I=b.ancestor)==null?void 0:I.id)===u.id?(a.ancestor=b.ancestor,a.callType=b.callType):(V.some(x=>x.callee.id===(u==null?void 0:u.id))||M.some(x=>x.callee.id===(d==null?void 0:d.id)),a.ancestor=l,a.callType="entry")}return a}function hy(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(D=>!!D.calledBy.length)&&(i=d.internalCalls.find(V=>!!V.calledBy.length));let a=u||zr(i,d.project);if(!a)return{ancestor:null,callType:null};if(a.type===p.Project&&(a=AH(i).ancestor,!a))return{ancestor:null,callType:null};const l=wo(a);if(!l.find(D=>D.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(Gt.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(D=>!(D.callee===i||!Dr.includes(D.callee.type)||!ht(D.callee).find(x=>x===i))).filter((D,V,M)=>M.findIndex(x=>x.callee===D.callee)===V);if(e.length===0)return{ancestor:null,callType:null};if(e.length===1){const D=e[0];if(D.callee.type===p.Loop){if(D.callee.body.calls.includes(i))return{ancestor:D.callee,callType:"loop-body"}}else{if(Gt.includes(D.callee.type))return D.callee.type===p.FunctionDeclaration&&D.callee.parent.type===p.Loop?{ancestor:D.callee,callType:"loop-body"}:{ancestor:D.callee,callType:"entry"};if(mi.includes(D.callee.type)){if(D.callType==="success"&&D.callee.type===p.InternalCall)return{ancestor:D.callee,callType:"success"};if(D.callType==="error"&&D.callee.type===p.InternalCall)return{ancestor:D.callee,callType:"error"}}}}const y=e.filter(D=>Yw(i,D.callee)),v=y.filter(D=>{const V=ht(D.callee),M=y.filter(q=>q.callee!==D.callee).map(q=>q.callee);return!V.some(q=>!!M.find(W=>W===q))});if(v.length===0){if(a.type===p.Loop){if(ht(a.body).find(W=>W===i))return{ancestor:a,callType:"loop-body"};if(br(a.successCalls).find(W=>W===i))return{ancestor:a,callType:"success"};if(br(a.errorCalls).find(W=>W===i))return{ancestor:a,callType:"error"}}else if(mi.includes(a.type)){if(br(a.successCalls).find(q=>q===i))return{ancestor:a,callType:"success"};if(br(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(D=>S(D.callee,i.project)).join(", ")}`);const T=v[0].callee,b=wo(T).find(D=>D.callee===i);return{ancestor:T,callType:b.callType}}function DNe(d){if(![...au,p.OutputMap].includes(d.type))throw new Error("getEarliestSingleCallerAncestorOfValueWriterAndItsValueReaders can only be used with a value writer entity");let u;if(au.includes(d.type)?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,...W0(d),...Vt.includes(d.type)?d.outputs.flatMap(y=>W0(y)):[]]),a=C(i.map(y=>Xw(y)).flatMap(y=>Nt.includes(y==null?void 0:y.type)?y.calledBy:[y]));if(a.length===1){const y=a[0];if(Gt.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(Gt.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 I=br(y.successCalls),b=br(y.errorCalls);if(I.includes(u))return{ancestor:y,callType:"success"};if(b.includes(u))return{ancestor:y,callType:"error"}}const v=hy(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(I=>{var b,D;return((b=I.ancestor)==null?void 0:b.id)===((D=y.ancestor)==null?void 0:D.id)})),c=yy(u),e=l.filter(y=>y!=null&&y.ancestor?c===y.ancestor?!0:!l.filter(I=>I.ancestor!==y.ancestor).map(I=>I.ancestor).some(I=>{const b=Ao(y.ancestor,I);return!!(b!=null&&b.last)}):!1);if(e.length===0)return{ancestor:c,callType:(c==null?void 0:c.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 wH(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:IH(l).length>1&&l.includes(u)?!1:l.every(e=>d===u?!0:Gt.includes(e.type)?!1:wH(e,u))}function RH(d){const u=[];let i=d.calledBySuccess;i=i.filter(l=>!i.filter(y=>y!==l).some(y=>z0(y,l)));let a=d.calledByError;a=a.filter(l=>!a.filter(y=>y!==l).some(y=>z0(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 CH(d){const u=[];return RH(d).forEach(a=>{a.ancestor.type===p.Condition&&u.push({condition:a.ancestor,call:d,callType:a.callType});const c=CH(a.ancestor).filter(e=>!u.some(y=>y.condition.id===e.condition.id));u.push(...c)}),u}function Xw(d){if(!d)return null;if(d.type===p.Condition&&d.parent.type===p.Condition)return vy(d.parent);if(rE.includes(d.type))return d;const u=d.parent;return u?Xw(u):null}function W0(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]:er.includes(a.type)?[...i,a,...W0(a,u)]:i),[])}function my(d){const u=d.calledBy;if(u.length===0)return d.project;const i=u.reduce((a,l)=>{const c=zr(l,d.project);return!c||c.type===p.Project?a:a.type===p.Project||op(c,a).last?c:(op(a,c).last,a)},d.project);return i.type===p.FunctionDeclaration&&i.parent.type===p.Loop?i.parent:i}function et(d,u){let i=my(d);if(d.type===p.InternalCall)if(d.parent.type===p.VariableInstance){const l=Ds(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&&!Qi.includes(i.type)){d.remove({ignoreUpstream:!1},u);return}else if(Vt.includes(d.type)){const l=d.usedInternalCalls[0];if(l)if(i=my(l),d.type===p.VariableInstance){const c=Ds(i,d.declaration,d.project);!c.compatible&&c.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 c=Ds(i,d.declaration,d.project);!c.compatible&&c.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(Nt.includes(d.type))return;ht(d).forEach(l=>{let c=my(l);if(l.type===p.InternalCall)if(l.parent.type===p.VariableInstance){const e=Ds(c,l.parent.declaration,d.project);!e.compatible&&e.type!=="b-is-global-a-is-not"?l.parent.remove({ignoreUpstream:!1},u):(l.parent.setParent(c,u),l.parent.addSelfToProject(u))}else l.parent.setParent(c,u),l.parent.addSelfToProject(u);else if((l.type===p.ContinueStatement||l.type===p.BreakStatement)&&c.type!==p.Loop){l.remove({ignoreUpstream:!1},u);return}else if(l.type===p.ReturnStatement&&!Qi.includes(c.type)){l.remove({ignoreUpstream:!1},u);return}else if(Vt.includes(l.type)){const e=l.usedInternalCalls[0];if(e)if(c=my(e),l.type===p.VariableInstance){const y=Ds(c,l.declaration,d.project);!y.compatible&&y.type!=="b-is-global-a-is-not"?l.remove({ignoreUpstream:!1},u):(l.setParent(c,u),l.addSelfToProject(u))}else l.setParent(c,u),l.addSelfToProject(u);else if(l.type===p.VariableInstance){const y=Ds(c,l.declaration,d.project);!y.compatible&&y.type!=="b-is-global-a-is-not"?l.remove({ignoreUpstream:!1},u):(l.setParent(c,u),l.addSelfToProject(u))}else l.setParent(c,u),l.addSelfToProject(u)}else l.setParent(c,u),l.addSelfToProject(u)})}function H0(d,u,i=new Set){const a=ta(d),l=ta(u),c=a.filter(v=>!l.includes(v)),e=a.filter(v=>l.includes(v)),y=c.reduce((v,T)=>i.has(T.id)?v:(i.add(T.id),C([...v,...H0(T,u,i)])),[]);return C([...e,...y])}function Pd(d,u){const i=op(d,u);return i.last===u&&i.list.length>0&&i.list[0]!==u}function Qw(d,u){return!!op(d,u).last}function z0(d,u){return!!Ao(d,u).last}function eR(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 eR(i,a)}function ONe(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(Mr.includes(d.type)&&Dr.includes(u.type)){const y=Ao(d,u),v=y.last;if(v){if(v===u)return{ancestor:u,callType:y.callType}}else return{ancestor:null,callType:null}}if(Mr.includes(u.type)&&Dr.includes(d.type)){const y=Ao(u,d),v=y.last;if(v){if(v===d)return{ancestor:d,callType:y.callType}}else return{ancestor:null,callType:null}}const a=yy(d),l=yy(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 c=a.calls.reduce((y,v)=>{if(!Dr.includes(v.type))return y;const T=wo(v),I=T.find(D=>D.callee===d),b=T.find(D=>D.callee===u);return I&&b&&(!i||I.callType===b.callType)?[...y,{ancestor:v,callType:I.callType}]:y},[]);if(c.length===0)return{ancestor:null,callType:null};if(c.length===1)return{ancestor:c[0].ancestor,callType:c[0].callType};const e=c.filter(y=>!c.some(v=>v.ancestor!==y.ancestor&&Ao(y.ancestor,v.ancestor).last===v.ancestor));return e.length===1?{ancestor:e[0].ancestor,callType:e[0].callType}:{ancestor:a,callType:"entry"}}function Pi(d){if(dc.includes(d.type)){if(d.type===p.FunctionDeclaration){const u=d.parent;if(u.type===p.DefinitionEntity)return Pi(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?Pi(d.parent):d}else{const u=d.parent;return u?Pi(u):null}}function dp(d,u){const i=up(d,u);if(!i)return null;if(dc.includes(i.type)){if(i.type===p.FunctionDeclaration){const a=up(i.parent,u);if(a){if(a.type===p.DefinitionEntity)return a;if(a.type===p.Loop)return a}}if(i.parent){const a=up(i.parent,u);if(a&&(i.type===p.DefinitionEntity&&a.type===p.DataType||i.type===p.Condition&&a.type===p.Condition))return dp(a,u)}return i}else{const a=i.parent?up(i.parent,u):null;return a?dp(a,u):null}}function wo(d){if(d.type===p.Loop){const u=[...br(d.successCalls).map(l=>({callee:l,callType:"success"})),...br(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 c=(e=u.find(y=>y.callee===l))==null?void 0:e.callType;return{callee:l,callType:c}})}if(mi.includes(d.type)){const u=[...br(d.successCalls).map(l=>({callee:l,callType:"success"})),...br(d.errorCalls).map(l=>({callee:l,callType:"error"}))];return C(u.map(l=>l.callee)).map(l=>{var e;const c=(e=u.find(y=>y.callee===l))==null?void 0:e.callType;return{callee:l,callType:c}})}if(Gt.includes(d.type)){const u=[...br(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 c=(e=u.find(y=>y.callee===l))==null?void 0:e.callType;return{callee:l,callType:c}})}return[]}function vy(d){if(!d)return null;if(d.type===p.Condition&&d.parent.type===p.Condition)return vy(d.parent);if(Mr.includes(d.type))return d;const u=d.parent;return u?vy(u):null}function gH(d){if(!d)return null;if(mi.includes(d.type))return d;const u=d.parent;return u?gH(u):null}function _H(d){if(!d)return null;if(Dr.includes(d.type))return d;const u=d.parent;return u?_H(u):null}function PNe(d){return d.type===p.VariableDeclaration?[d]:mi.includes(d.type)?[...d.inputs,...d.outputs||[]]:Nt.includes(d.type)?d.outputs:Zo.includes(d.type)||d.type===p.FunctionDeclaration?d.inputs:[]}function $Ne(d){const u=ta(d),i=[],a=[];Mg.includes(d.type)&&i.push(...J0(d));const l=u.filter(c=>{const e=i.includes(c);return e?!1:Mr.includes(c.type)&&!e?(a.push(c),!1):!0});return i.sort((c,e)=>Pd(e,c)?-1:0),a.sort((c,e)=>Pd(e,c)?-1:0),[...i,...a,...l]}function DH(d){return[...d].sort((u,i)=>Pd(i,u)?-1:0)}function NNe(d){const u=DH(d),i=[];return u.forEach(a=>{const l=i[i.length-1];if(l){const c=l[l.length-1];Pd(a,c)?i.push([a]):l.push(a)}else i.push([a])}),i}function El(d){const u=d.map(i=>Pi(i));return C(u)}function J0(d){return mi.includes(d.type)?[...El(d.successCalls),...El(d.errorCalls)]:Gt.includes(d.type)?El(d.calls):[]}function VNe(d,u){return J0(d).includes(u)}function Y0(d){return d.writesValues||[]}function LNe(d,u){return Y0(d).includes(u)}function OH(d){var u;return Vt.includes((u=d==null?void 0:d.readsValue)==null?void 0:u.type)?d.readsValue:null}function BNe(d){return d.writesValues}function PH(d=[]){return d.map(OH).filter(u=>!!u)}function S0(d=[]){return d.map(u=>u.writesValues).flat().filter(u=>Vt.includes(u.type))}function $H(d=[]){return d.map(u=>u.readsValue).filter(u=>!!u&&Vt.includes(u.type))}function NH(d){return Vt.includes(d.type)?d:null}function VH(d){return d.writesValues.map(NH).filter(u=>!!u)}function LH(d=[]){return d.reduce((u,i)=>i.type===p.OutputMap?[...u,...VH(i)]:u,[])}function ht(d){return d.type===p.Loop?C([...br(d.successCalls),...br(d.errorCalls),...d.body?ht(d.body):[]]):mi.includes(d.type)?C([...br(d.successCalls),...br(d.errorCalls)]):Gt.includes(d.type)?C(br(d.calls)):[]}function MNe(d){return mi.includes(d.type)?[...br(d.successCalls),...br(d.errorCalls)]:Gt.includes(d.type)?br(d.calls):[]}function BH(d,u=new Set){return d.writesValues.filter(a=>Vt.includes(a.type)&&!u.has(a.id)).reduce((a,l)=>u.has(l.id)?a:[...a,...Li(l,u)],[])}function MH(d,u=new Set){var a;return(((a=d.readsValue)==null?void 0:a.writesValues)||[]).filter(l=>Vt.includes(l.type)&&!u.has(l.id)).reduce((l,c)=>u.has(c.id)?l:[...l,...Li(c,u)],[])}function Li(d,u=new Set){if(u.has(d.id))return[];if(d.type===p.ReturnStatement)return $H(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((c,e)=>{const y=Pi(e);return[...c,...Li(y||e,u)]},[]),...PH(d.inputs),...LH(d.outputs)].reduce((c,e)=>[...c,...Li(e,u)],[]);if(Zo.includes(d.type)){const i=S0(d.inputs),l=ht(d).reduce((c,e)=>{const y=Pi(e);return[...c,...Li(y||e,u)]},[]);return i.push(...l),i.reduce((c,e)=>[...c,...Li(e,u)],[])}if(d.type===p.FunctionDeclaration){const i=[...S0(d.inputs)],l=ht(d).reduce((c,e)=>{const y=Pi(e);return[...c,...Li(y||e,u)]},[]);return i.push(...l),i.reduce((c,e)=>[...c,...Li(e)],[])}if(Vt.includes(d.type)){u.add(d.id);const a=ht(d).reduce((l,c)=>{const e=Pi(c);return[...l,...Li(e||c,u)]},[]);return[d,...a,...MH(d,u),...BH(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,c)=>(J.log("[Recursive -- flattenDerivedCanvasEntities]",c.type,S(c,c.project),c.id),[...l,c,...Fn(c,u)]),[])]}function br(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 xH(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],[]),c=l.reduce((v,T)=>[...v,...S0(T.inputs),...br(El(T.calls)),...T.returnStatements],[]),e=d.functions.reduce((v,T)=>[...v,...br(El(T.calls)),...T.returnStatements],[]),y=d.events.reduce((v,T)=>[...v,...br(El(T.calls)),...T.returnStatements],[]);return[...i,...a,...l,...c,...e,...y]}function UH(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)?cz(d).find(c=>{var e;return((e=c.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 xNe(d){const u=xH(d.project);return UH(d,u)}function up(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 jH(d={},u){const i={};return Object.keys(d).forEach(a=>{const l=u.get(a)||a,c=d[a];i[l]=c}),i}function pp(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,c=d,e=d,y=d,v=d,T=d,I=d,b=d,D=d,V=d,M=d,x=d,q=d,Z=[...q.readsValue?[q.readsValue]:[],...q.declaration?[q.declaration]:[],...(x.calledByEntry||[]).flatMap(z=>z),...(x.calledBySuccess||[]).flatMap(z=>z),...(x.calledByError||[]).flatMap(z=>z),...V.parent?[V.parent]:[]];Array.isArray(e.implements)?Z.push(...e.implements.flatMap(z=>z)):y.implements&&Z.push(y.implements),Array.isArray(e.extends)?Z.push(...e.extends.flatMap(z=>z)):D.extends&&Z.push(D.extends),v.valueAsTypeList&&Array.isArray(v.valueAsTypeList)&&Z.push(...v.valueAsTypeList.flatMap(z=>z)),v.valueAsTypeSingle&&Z.push(v.valueAsTypeSingle),(q.internalCalls||[]).forEach(z=>{const oe=te(z);if(oe&&u[oe]){const le=u[oe];[...le.calledByEntry||[],...le.calledBySuccess||[],...le.calledByError||[]].forEach(ye=>{const he=te(ye);he&&u[he]&&Z.push(u[he])})}});const W=[...(l.inputs||[]).flatMap(z=>z),...(M.inputsDeclarations||[]).flatMap(z=>z),...(M.outputs||[]).flatMap(z=>z),...(q.internalCalls||[]).flatMap(z=>z),...q.writesValues||[],...x.dataType?[x.dataType]:[],...T.body?[T.body]:[],...x.defaultValue?[x.defaultValue]:[],...(x.successCalls||[]).flatMap(z=>z),...(x.errorCalls||[]).flatMap(z=>z),...(e.properties||[]).flatMap(z=>z),...(e.methods||[]).flatMap(z=>z),...(e.abstractMethods||[]).flatMap(z=>z),...I.error?[I.error]:[],...V.throws?[V.throws]:[],...(c.andChildrenGroup||[]).flatMap(z=>z),...(c.orChildrenGroup||[]).flatMap(z=>z),...(b.entities||[]).flatMap(z=>z),...(b.functions||[]).flatMap(z=>z),...(b.functionCalls||[]).flatMap(z=>z),...(b.events||[]).flatMap(z=>z),...(b.conditions||[]).flatMap(z=>z),...(b.operations||[]).flatMap(z=>z),...(b.loops||[]).flatMap(z=>z),...(b.variableDeclarations||[]).flatMap(z=>z),...(b.variableInstances||[]).flatMap(z=>z),...(b.searches||[]).flatMap(z=>z),...(b.projects||[]).flatMap(z=>z),...(y.calls||[]).flatMap(z=>z)];d.type===p.DataType&&(c.entity&&u[te(c.entity)]&&u[te(c.entity)].parent&&te(u[te(c.entity)].parent)===d.id?W.push(c.entity):c.entity&&Z.push(c.entity)),(q.internalCalls||[]).forEach(z=>{const oe=te(z);if(oe&&u[oe]){const le=u[oe];[...le.successCalls||[],...le.errorCalls||[]].forEach(ye=>{const he=te(ye);he&&u[he]&&W.push(u[he])})}});const Y={},re={};return Z.forEach(z=>{var ye;const oe=te(z);if(oe&&a.ignoreBuiltInBaseEntities&&(vn.includes(z.type)||(a.allBuiltInEntityIds||[]).includes(oe)))return;const le=z.version;if(oe){const he=((ye=a.entityMaps)==null?void 0:ye.get(oe))||oe;Y[he]=le}}),W.forEach(z=>{var ye;const oe=te(z);if(oe&&a.ignoreBuiltInBaseEntities&&(vn.includes(z.type)||(a.allBuiltInEntityIds||[]).includes(oe)))return;const le=z.version;if(oe){const he=((ye=a.entityMaps)==null?void 0:ye.get(oe))||oe;re[he]=le}}),{upstream:Y,downstream:re}}function UNe(d,u){const i=[];if(Mr.includes(d.type)){os(d).forEach(c=>{const e=dp(c,u);e&&i.push(e)});const l=[...d.inputs||[],...d.outputs||[]].map(c=>{const e=up(c,u);return e?fz(e,u):null}).filter(c=>c!==null);i.push(...C(l))}if(Vt.includes(d.type)){const a=X0(d);a&&i.push(a)}return C(i)}function Ro(d){const u=[];if(Mr.includes(d.type)){d.calledBy.forEach(l=>{const c=Pi(l);c&&u.push(c)});const a=[...d.inputs||[],...d.outputs||[]].map(l=>X0(l)).filter(l=>l!==null);u.push(...C(a))}if(Xn.includes(d.type)){const i=X0(d);i&&u.push(i)}return C(u)}function os(d){return[...d.calledByEntry||[],...d.calledByError||[],...d.calledBySuccess||[]].filter(u=>u.type!==p.GenericReference)}function GH(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=>Ee(a,u,i)),...d.dataType?Ee(d.dataType,u,i):[],...d.error?Ee(d.error,u,i):[],...d.parent?Ee(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.ArgumentDeclaration)throw new Error("Entity must be an argument declaration to be flattened");return[d,...d.defaultValue?Ee(d.defaultValue,u):[],...d.writesValues.flatMap(a=>Ee(a,u,i)),...d.dataType?Ee(d.dataType,u,i):[],...d.parent?Ee(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.BreakStatement)throw new Error("Entity must be a break statement to be flattened");return[d,...d.outputs.flatMap(a=>Ee(a,u,i)),...d.throws?Ee(d.throws,u,i):[],...d.dataType?Ee(d.dataType,u,i):[],...d.readsValue?Ee(d.readsValue,u,i):[],...(os(d)||[]).flatMap(a=>Ee(a,u,i)),...d.parent?Ee(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.BuiltInBaseEntity)throw new Error("Entity must be a built-in base entity to be flattened");return[d,...(d.properties||[]).flatMap(a=>Ee(a,u,i)),...(d.methods||[]).flatMap(a=>Ee(a,u,i)),...(d.abstractMethods||[]).flatMap(a=>Ee(a,u,i)),...d.allPropertiesImplement?Ee(d.allPropertiesImplement,u,i):[],...d.additionalPropertiesDataType?Ee(d.additionalPropertiesDataType,u,i):[],...d.extends?Ee(d.extends,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.Condition)throw new Error("Entity must be a condition to be flattened");return[d,...(d.andChildrenGroup||[]).flatMap(a=>Ee(a,u,i)),...(d.orChildrenGroup||[]).flatMap(a=>Ee(a,u,i)),...(d.inputs||[]).flatMap(a=>Ee(a,u,i)),...(d.successCalls||[]).flatMap(a=>Ee(a,u,i)),...(d.errorCalls||[]).flatMap(a=>Ee(a,u,i)),...(os(d)||[]).flatMap(a=>Ee(a,u,i)),...d.parent?Ee(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.ContinueStatement)throw new Error("Entity must be a continue statement to be flattened");return[d,...d.outputs.flatMap(a=>Ee(a,u,i)),...d.readsValue?Ee(d.readsValue,u,i):[],...d.throws?Ee(d.throws,u,i):[],...d.dataType?Ee(d.dataType,u,i):[],...(os(d)||[]).flatMap(a=>Ee(a,u,i)),...d.parent?Ee(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.DefinitionEntity)throw new Error("Entity must be a definition entity to be flattened");return[d,...d.extends?Ee(d.extends,u,i):[],...(d.implements||[]).flatMap(a=>Ee(a,u,i)),...(d.properties||[]).flatMap(a=>Ee(a,u,i)),...(d.methods||[]).flatMap(a=>Ee(a,u,i)),...(d.abstractMethods||[]).flatMap(a=>Ee(a,u,i)),...d.allPropertiesImplement?Ee(d.allPropertiesImplement,u,i):[],...d.additionalPropertiesDataType?Ee(d.additionalPropertiesDataType,u,i):[],...d.parent?Ee(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.DataType)throw new Error("Entity must be a data type to be flattened");return[d,...(d.andChildrenGroup||[]).flatMap(a=>Ee(a,u,i)),...(d.orChildrenGroup||[]).flatMap(a=>Ee(a,u,i)),...d.entity?Ee(d.entity,u,i):[],...d.parent?Ee(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.FunctionCall)throw new Error("Entity must be a function call to be flattened");return[d,...(d.inputs||[]).flatMap(a=>Ee(a,u,i)),...(d.outputs||[]).flatMap(a=>Ee(a,u,i)),...d.error?Ee(d.error,u,i):[],...(os(d)||[]).flatMap(a=>Ee(a,u,i)),...(d.successCalls||[]).flatMap(a=>Ee(a,u,i)),...(d.errorCalls||[]).flatMap(a=>Ee(a,u,i)),...(d.writesValues||[]).flatMap(a=>Ee(a,u,i)),...d.parent?Ee(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.FunctionDeclaration)throw new Error("Entity must be a function declaration to be flattened");return[d,...(d.inputs||[]).flatMap(a=>Ee(a,u,i)),...(d.calls||[]).flatMap(a=>Ee(a,u,i)),...d.dataType?Ee(d.dataType,u,i):[],...d.implements?Ee(d.implements,u,i):[],...d.parent?Ee(d.parent,u,i):[]]}function YH(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=>Ee(a,u,i)),...(d.calls||[]).flatMap(a=>Ee(a,u,i)),...d.implements?Ee(d.implements,u,i):[],...d.parent?Ee(d.parent,u,i):[]]}function SH(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?Ee(d.readsValue,u,i):[],...d.declaration?Ee(d.declaration,u,i):[],...d.defaultValue?Ee(d.defaultValue,u,i):[],...d.parent?Ee(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.InstalledProject)throw new Error("Entity must be an installed project to be flattened");return[d,...(d.functions||[]).flatMap(a=>Ee(a,u,i)),...(d.events||[]).flatMap(a=>Ee(a,u,i)),...d.parent?Ee(d.parent,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.InternalCall)throw new Error("Entity must be an internal call to be flattened");return[d,...(d.successCalls||[]).flatMap(a=>Ee(a,u,i)),...(d.errorCalls||[]).flatMap(a=>Ee(a,u,i)),...(d.inputs||[]).flatMap(a=>Ee(a,u,i)),...(d.outputs||[]).flatMap(a=>Ee(a,u,i)),...(os(d)||[]).flatMap(a=>Ee(a,u,i)),...d.error?Ee(d.error,u,i):[],...(d.writesValues||[]).flatMap(a=>Ee(a,u,i)),...d.parent?Ee(d.parent,u,i):[]]}function ez(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?Ee(d.valueAsTypeSingle,u,i):[],...d.valueAsTypeList&&Array.isArray(d.valueAsTypeList)?d.valueAsTypeList.flatMap(a=>Ee(a,u,i)):[],...d.parent?Ee(d.parent,u,i):[]]}function tz(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=>Ee(a,u,i)),...(d.outputs||[]).flatMap(a=>Ee(a,u,i)),...(d.successCalls||[]).flatMap(a=>Ee(a,u,i)),...(d.errorCalls||[]).flatMap(a=>Ee(a,u,i)),...d.error?Ee(d.error,u,i):[],...d.dataType?Ee(d.dataType,u,i):[],...d.body?Ee(d.body,u,i):[],...(os(d)||[]).flatMap(a=>Ee(a,u,i)),...(d.writesValues||[]).flatMap(a=>Ee(a,u,i)),...d.parent?Ee(d.parent,u,i):[]]}function iz(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=>Ee(a,u,i)),...(d.errorCalls||[]).flatMap(a=>Ee(a,u,i)),...(d.inputs||[]).flatMap(a=>Ee(a,u,i)),...(d.outputs||[]).flatMap(a=>Ee(a,u,i)),...(d.writesValues||[]).flatMap(a=>Ee(a,u,i)),...d.error?Ee(d.error,u,i):[],...(os(d)||[]).flatMap(a=>Ee(a,u,i)),...d.parent?Ee(d.parent,u,i):[]]}function rz(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=>Ee(a,u,i)),...d.declaration?Ee(d.declaration,u,i):[],...d.parent?Ee(d.parent,u,i):[]]}function nz(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=>Ee(a,u,i)),...(d.methods||[]).flatMap(a=>Ee(a,u,i)),...(d.abstractMethods||[]).flatMap(a=>Ee(a,u,i))]}function sz(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=>Ee(a,u,i)),...(d.functions||[]).flatMap(a=>Ee(a,u,i)),...(d.events||[]).flatMap(a=>Ee(a,u,i)),...(d.projects||[]).flatMap(a=>Ee(a,u,i)),...(d.variableDeclarations||[]).flatMap(a=>Ee(a,u,i)),...(d.variableInstances||[]).flatMap(a=>Ee(a,u,i)),...(d.operations||[]).flatMap(a=>Ee(a,u,i)),...(d.conditions||[]).flatMap(a=>Ee(a,u,i)),...(d.functionCalls||[]).flatMap(a=>Ee(a,u,i)),...(d.projects||[]).flatMap(a=>Ee(a,u,i)),...(d.loops||[]).flatMap(a=>Ee(a,u,i)),...(d.searches||[]).flatMap(a=>Ee(a,u,i))]}function az(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?Ee(d.defaultValue,u,i):[],...d.dataType?Ee(d.dataType,u,i):[],...d.parent?Ee(d.parent,u,i):[]]}function lz(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=>Ee(a,u,i)),...d.throws?Ee(d.throws,u,i):[],...d.readsValue?Ee(d.readsValue,u,i):[],...d.dataType?Ee(d.dataType,u,i):[],...(os(d)||[]).flatMap(a=>Ee(a,u,i)),...d.parent?Ee(d.parent,u,i):[]]}function oz(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=>Ee(a,u,i)),...(d.errorCalls||[]).flatMap(a=>Ee(a,u,i)),...(d.inputsDeclarations||[]).flatMap(a=>Ee(a,u,i)),...(d.inputs||[]).flatMap(a=>Ee(a,u,i)),...(d.writesValues||[]).flatMap(a=>Ee(a,u,i)),...(d.outputs||[]).flatMap(a=>Ee(a,u,i)),...d.error?Ee(d.error,u,i):[],...d.dataType?Ee(d.dataType,u,i):[],...(os(d)||[]).flatMap(a=>Ee(a,u,i)),...d.parent?Ee(d.parent,u,i):[]]}function dz(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?Ee(d.defaultValue,u,i):[],...d.dataType?Ee(d.dataType,u,i):[],...d.parent?Ee(d.parent,u,i):[]]}function uz(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=>Ee(a,u,i)),...(d.errorCalls||[]).flatMap(a=>Ee(a,u,i)),...(d.inputs||[]).flatMap(a=>Ee(a,u,i)),...(d.outputs||[]).flatMap(a=>Ee(a,u,i)),...(d.internalCalls||[]).flatMap(a=>Ee(a,u,i)),...(d.writesValues||[]).flatMap(a=>Ee(a,u,i)),...d.readsValue?Ee(d.readsValue,u,i):[],...d.defaultValue?Ee(d.defaultValue,u,i):[],...(os(d)||[]).flatMap(a=>Ee(a,u,i)),...d.dataType?Ee(d.dataType,u,i):[],...d.parent?Ee(d.parent,u,i):[]]}function pz(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=>Ee(a,u,i)),...(d.errorCalls||[]).flatMap(a=>Ee(a,u,i)),...(d.inputs||[]).flatMap(a=>Ee(a,u,i)),...(d.outputs||[]).flatMap(a=>Ee(a,u,i)),...(d.internalCalls||[]).flatMap(a=>Ee(a,u,i)),...(d.writesValues||[]).flatMap(a=>Ee(a,u,i)),...d.readsValue?Ee(d.readsValue,u,i):[],...d.defaultValue?Ee(d.defaultValue,u,i):[],...(os(d)||[]).flatMap(a=>Ee(a,u,i)),...d.declaration?Ee(d.declaration,u,i):[],...d.parent?Ee(d.parent,u,i):[]]}function Kn(){const d=new Set;return yk.flatMap(i=>Ee(i,d)).map(i=>i.id)}function Ee(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 zH(d,u,i);case p.Operation:return iz(d,u,i);case p.Condition:return qH(d,u,i);case p.Loop:return tz(d,u,i);case p.Search:return oz(d,u,i);case p.GlobalEvent:return YH(d,u,i);case p.ReturnStatement:return lz(d,u,i);case p.ContinueStatement:return ZH(d,u,i);case p.BreakStatement:return FH(d,u,i);case p.VariableDeclaration:return uz(d,u,i);case p.DefinitionEntity:return WH(d,u,i);case p.FunctionDeclaration:return JH(d,u,i);case p.Project:return sz(d,u,i);case p.ActionDescriptor:return GH(d,u,i);case p.ArgumentDeclaration:return kH(d,u,i);case p.ValueDescriptor:return dz(d,u,i);case p.InputMap:return SH(d,u,i);case p.OutputMap:return rz(d,u,i);case p.DataType:return HH(d,u,i);case p.InstalledProject:return XH(d,u,i);case p.InternalCall:return QH(d,u,i);case p.LiteralValue:return ez(d,u,i);case p.Property:return az(d,u,i);case p.VariableInstance:return pz(d,u,i);case p.BuiltInBaseEntity:return i.ignoreBuiltInBaseEntities?[]:KH(d,u,i);case p.PrimitiveEntity:return i.ignoreBuiltInBaseEntities?[]:nz(d,u,i)}return[]}function tR(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||Zo.includes(d.type)?d.inputs:d.type===p.Search?d.inputsDeclarations:[]}function jNe(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 cz(d){return mi.includes(d.type)?d.inputs:[]}function GNe(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 Nt.includes(d.type)?d.outputs.map(i=>i.declaration).filter(i=>!!i)||[]:[]}function kNe(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 FNe(d){return d.type===p.Condition?[]:mi.includes(d.type)?d.outputs:[]}function X0(d){const u=d.readsValue;return u?Pi(u):null}function fz(d,u){const i=d.readsValue;return i?dp(i,u):null}function yz(d){const u=d.internalCalls||[];return C(El(C(u.flatMap(i=>[...i.successCalls,...i.errorCalls]))))}function hz(d){const u=d.internalCalls||[];return C(C(u.flatMap(i=>[...i.successCalls,...i.errorCalls])))}function cp(d){const u=Y0(d),i=[];return u.forEach(a=>{if(dc.includes(a.type))i.push(a);else if(Xn.includes(a.type)){const l=Pi(a.parent);i.push(l)}}),i}function fp(d){const u=Y0(d),i=[];return u.forEach(a=>{if([...Vt,...Nt].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 mz(d){return d.type===p.Project?null:rE.includes(d.type)?d:vn.includes(d.type)?null:d.parent?mz(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)||[]),Qi.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(c=>Pi(c)),l=d.errorCalls.map(c=>Pi(c));i.push(...a,...l)}if(Zo.includes(d.type)){if(d.collapsed&&u)return[];const a=d.inputs.map(c=>cp(c)).flat(),l=d.calls.map(c=>Pi(c));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=>cp(e)).flat(),l=d.successCalls.map(e=>Pi(e)),c=d.errorCalls.map(e=>Pi(e));i.push(...C(a),...l,...c)}if(Vt.includes(d.type)){const a=cp(d),l=yz(d);i.push(...a,...l)}if(er.includes(d.type)){const a=cp(d);i.push(...a)}if(d.type===p.Loop){if(d.body){const c=ta(d.body,u);i.push(...c)}const a=d.errorCalls.map(c=>Pi(c)),l=d.successCalls.map(c=>Pi(c));i.push(...l,...a)}if(d.type===p.FunctionDeclaration){if(d.collapsed&&u)return[];const a=d.inputs.map(c=>cp(c)).flat(),l=d.calls.map(c=>Pi(c));i.push(...C(a),...l)}return C(i)}function Q0(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)||[]),Qi.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?[]:Q0(l));i.push(...a)}if(d.type===p.Condition){const a=d.successCalls,l=d.errorCalls;i.push(...a,...l)}if(Zo.includes(d.type)){if(d.collapsed&&u)return[];const a=d.inputs.map(c=>fp(c)).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=>fp(e)).flat(),l=d.successCalls,c=d.errorCalls;i.push(...C(a),...l,...c)}if(Vt.includes(d.type)){const a=fp(d),l=hz(d);i.push(...a,...l)}if(d.type===p.Loop){const a=d.outputs.map(e=>fp(e)).flat();if(d.body){const e=Q0(d.body,u);i.push(...e)}const l=d.errorCalls,c=d.successCalls;i.push(...C(a),...c,...l)}if(d.type===p.FunctionDeclaration){if(d.collapsed&&u)return[];const a=d.inputs.map(c=>fp(c)).flat(),l=d.calls;i.push(...C(a),...l)}return C(i)}function ev(d,u=!1){const i=ta(d,u),a=[...i,...i.reduce((l,c)=>[...l,...ev(c,u)],[])];return C(a)}function vz(d,u=!1){const i=Q0(d,u),a=[...i,...i.reduce((l,c)=>[...l,...vz(c,u)],[])];return C(a)}function Ty(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,...Ty(i),...Co(i)]:(i==null?void 0:i.type)===p.BuiltInBaseEntity?[i==null?void 0:i.name,...Co(i)]:[...u],[])}function Co(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,...Co(d.extends),...Ty(d.extends)];if(d.extends.type===p.BuiltInBaseEntity)return[d.extends.name,...Co(d.extends)]}return[]}function Ey(d){var u,i;return d.extends?((u=d.extends)==null?void 0:u.type)===p.DefinitionEntity?[d.extends,...Ey(d.extends),...iR(d.extends)]:((i=d.extends)==null?void 0:i.type)===p.BuiltInBaseEntity?[d.extends,...Ey(d.extends)]:[]:[]}function iR(d){return d.implements.reduce((u,i)=>i.type===p.DefinitionEntity?[...u,i,...iR(i),...Ey(i)]:(i==null?void 0:i.type)===p.BuiltInBaseEntity?[i,...Ey(i)]:[...u,i],[])}function yp(d){return[...Co(d),...Ty(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||[...Co(d)].includes(u)):!!yp(d).includes(u)}function Tz(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 bl(d.extends,u)}return null}if(d.extends)return cr(d.extends,u)?d.extends:bl(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=bl(i,u);if(a)return a}else if(i.type===p.DefinitionEntity){const a=bl(i,u);if(a)return a}}return null}function bl(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 bl(d.extends,u)}return null}if(d.extends)return d.extends.name===u?d.extends:bl(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=bl(i,u);if(a)return a}else if(i.type===p.DefinitionEntity){const a=bl(i,u);if(a)return a}}return null}function Ez(d){const u=Ro(d),i=[...u,...u.reduce((a,l)=>[...a,...Ez(l)],[])];return C(i)}function rR(d){return d.implements.length===0&&!d.extends?null:d.implements.find(a=>a.type===p.BuiltInBaseEntity&&a.name===fe.PERSISTED_ENTITY)?d:[...d.implements,...d.extends?[d.extends]:[]].reduce((a,l)=>{if(l.type===p.DefinitionEntity){const c=rR(l);if(c)return c}return a},null)}function KNe(d){return d.extends&&d.extends.type===p.BuiltInBaseEntity?d.extends:null}function qNe(d){const u=d.implements.find(i=>i.type===p.BuiltInBaseEntity);return u&&u.type===p.BuiltInBaseEntity?u:null}function tv(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 hp(d){return d.type===p.PrimitiveEntity?!0:d.type===p.BuiltInBaseEntity?d.interactive:!sn(d).find(a=>!a.interactive)}function ZNe(d){return d.parent===d.project&&d.project.variableDeclarations.includes(d)}function nR(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 bz(d){if([...Gt,p.DefinitionEntity,p.InstalledProject,p.Project].includes(d.type)||nR(d))return!1;const u=Ro(d);return u.length===0?!0:u.some(i=>bz(i))}function sR(d){return[...Gt,p.DefinitionEntity,p.InstalledProject,p.Project].includes(d.type)||nR(d)?!1:Ro(d).length===0}function Iz(d,u=0){if(sR(d)){const i=Ro(d);return i.length===0?d:i.map(l=>Iz(l,u+1)).reduce((l,c)=>l?c&&c.x<l.x?c:l:c,null)}return null}function Az(d){const u=[];if(sR(d))u.push(d);else return[];return Ro(d).forEach(a=>{u.push(...Az(a))}),u}function aR(d){return d.type===p.FunctionDeclaration&&d.parent!==d.project&&!![p.DefinitionEntity,p.Loop,p.InstalledProject].includes(d.parent.type)}function WNe(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 mp(d){switch(d){case p.DefinitionEntity:return us;case p.FunctionDeclaration:return Ia;case p.VariableDeclaration:return uo;case p.VariableInstance:return oo;case p.FunctionCall:return Io;case p.Operation:return to;case p.Condition:return no;case p.ReturnStatement:return cl;case p.Loop:return ro;case p.Search:return po;case p.InputMap:return ls;case p.OutputMap:return ea;case p.ArgumentDeclaration:return ns;case p.Property:return ds;case p.InstalledProject:return co;case p.Project:return L;case p.DataType:return Wr;case p.GlobalEvent:return io;case p.InternalCall:return fo;case p.ValueDescriptor:return hl;case p.BuiltInBaseEntity:return Oa;case p.PrimitiveEntity:return Rn;case p.ActionDescriptor:return Ut;case p.LiteralValue:return $r;case p.ContinueStatement:return ho;case p.BreakStatement:return yo;default:return null}}function zr(d,u,i=null){const a=d!=null&&d.parent?te(d==null?void 0:d.parent):null;let l=a?u.get(a):null,c=i||d;if((d==null?void 0:d.id)===(u==null?void 0:u.id))return u;if(d.type===p.ReturnStatement)return Rr(d,u,c);if(d.type===p.FunctionDeclaration&&(l==null?void 0:l.type)===p.Loop)return l;if(Gt.includes(d.type))return d;if(d.type===p.Loop)return c.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=te(e);if(!y)return null;const v=u.get(y);return v?zr(v,u,c):null}else return e===u?u:zr(e,u,c)}function Rr(d,u,i=null){const a=d!=null&&d.parent?te(d==null?void 0:d.parent):null;let l=a?u.get(a):null,c=i||d;if(d.type===p.FunctionDeclaration&&(l==null?void 0:l.type)===p.Loop)return Rr(l.parent,u,c);if(Gt.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=te(e);if(!y)return null;const v=u.get(y);return v?Rr(v,u,c):null}else return e===u?u:Rr(e,u,c)}function Il(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=an(d.parent,u);return i?i===u?Qi.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:Il(i,u):(J.warn(`getRootEntryPointScopeOwner is \`null\` because it was called with an entity that has no parent: ${d.id}`),null)}function iv(d,u,i){if(d===u||u===i||d===i||!d||!u)return!1;const a=zr(u.parent,i);return a===i?!1:a===d?!0:iv(a,u,i)}var rv=(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))(rv||{});function Ds(d,u,i){const a=zr(d,i),l=zr(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(iv(a,l,i))return{compatible:!0,type:"b-in-a",commonAncestorScope:a};if(iv(l,a,i))return{compatible:!0,type:"a-in-b",commonAncestorScope:l};const y=eR(a,l);return y===i?{compatible:!1,type:"parallel-in-project",commonAncestorScope:y}:y?{compatible:!1,type:"parallel-in-common-parent",commonAncestorScope:zr(y,i)}:{compatible:!1,type:"parallel-in-project",commonAncestorScope:i}}function wz(d,u,i){const a=Ds(d,u,i);if(!a.compatible||a.type!=="same-both-local")return null;if(d===u)return d;let l=zr(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=zr(l.parent,i)}let c=zr(u.parent,i);if(c){if(c===d)return d;if(c.type===p.Project)return u}else return u;for(;c;){if(c){if(c===d)return d;if(c.type===p.Project)return u}else return u;c=zr(c.parent,i)}return null}function Rz(d){return d.length===0?null:d.length===1?d[0]:d.reduce((i,a)=>{const l=wz(i,a,a.project);return!l||l===a?i:a},d[0])}function an(d,u){if(!d)return null;let i;return typeof d=="string"?i=d:d.type===p.GenericReference?i=te(d):i=d.id,i===u.id?u:u.get(i)}function go(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:go(u)}function by(d){const u=[];function i(c,e){return u.some(y=>y.blockedByCaller===c&&y.blockedByCalling===e)}function a(c,e){i(c,e)||u.push({blockedByCaller:c,blockedByCalling:e})}const l=Il(d,d.project);return l?(d.calledBySuccess.forEach(c=>{[...c.successCalls||[]].forEach(v=>{Nt.includes(v.type)&&v.id!==d.id&&(ht(d).find(b=>b===v)||a(c,v))});let y;if(mi.includes(c.type)&&(y=c),y){const v=by(y);v.reachable||ht(d).find(b=>b===c)||v.blocks.forEach(b=>{a(c,b.blockedByCalling)})}}),d.calledByError.forEach(c=>{[...c.errorCalls||[]].forEach(v=>{Nt.includes(v.type)&&v!==d&&(ht(d).find(b=>b===v)||a(c,v))});let y;if(mi.includes(c.type)&&(y=c),y){const v=by(y);v.reachable||ht(d).find(b=>b===c)||v.blocks.forEach(b=>{a(c,b.blockedByCalling)})}}),d.calledByEntry.forEach(c=>{if([...c.calls||[]].forEach(v=>{Nt.includes(v.type)&&v!==d&&(ht(d).find(b=>b===v)||a(c,v))}),c===l)return;let y;if(c.type===p.FunctionDeclaration){const v=Pi(c);if(v.type===p.DefinitionEntity)return;v.type===p.Loop&&(y=v)}if(y){const v=by(y);v.reachable||v.blocks.forEach(T=>{a(c,T.blockedByCalling)})}}),{reachable:u.length===0,entryPoint:l,blocks:u}):{reachable:!0,entryPoint:null,blocks:[]}}function HNe(d){return dc.includes(d.type)?d.type===p.FunctionDeclaration?!aR(d):!0:!1}function zNe(d){if(p.ActionDescriptor===d.type){if(d.project.operationDeclarations.find(c=>c.id===d.id))return p.Operation;if(d.project.globalEventActionDescriptors.find(c=>c.id===d.id))return p.GlobalEvent;if(d.project.loopDeclarations.find(c=>c.id===d.id))return p.Loop;if(d.project.conditionDeclarations.find(c=>c.id===d.id))return p.Condition}return d.type}function nv(d,u){return d.type===p.BuiltInBaseEntity?d.name===u:!!Co(d).includes(u)}function JNe(d,u){return d.type===p.BuiltInBaseEntity?d.name===u:!!Ty(d).includes(u)}function YNe(d){const u=[];return d.entities.forEach(i=>{if(nv(i,fe.PERSISTED_ENTITY)){u.push(i);return}}),C(u)}function SNe(d){const u=[];return d.entities.forEach(i=>{if(nv(i,fe.RELATIONAL_DATABASE)){u.push(i);return}}),C(u)}function XNe(d){return d.type!==p.DefinitionEntity||d.abstract||!nv(d,fe.PERSISTED_ENTITY)?null:(d==null?void 0:d.properties.find(i=>i.implements.find(a=>a.id===ce[p.BuiltInBaseEntity][fe.PERSISTED_ENTITY].properties.primaryKey.id)&&!i.abstract))||null}function Cz(d){var a;const u=rR(d);if(!u)return null;const i=u.properties.find(l=>l.implements.find(c=>c.id===ce[p.BuiltInBaseEntity][fe.PERSISTED_ENTITY].properties.database.id));return i?(a=i.getDefaultValue())==null?void 0:a.valueAsType:null}function vp(d){if(d.type!==p.DefinitionEntity)return[];if(d.abstract)return[];if(!cr(d,fe.PERSISTED_ENTITY))return[];const u=[],i=d.properties.filter(a=>!a.implements.find(l=>l.id===ce[p.BuiltInBaseEntity][fe.PERSISTED_ENTITY].properties.database.id)&&!a.abstract);return u.push(...i),u}function QNe(d){var i;if(!d||d.type!==p.DefinitionEntity||!cr(d,fe.PERSISTED_ENTITY))return null;const u=d.properties.find(a=>!!a.implements.find(l=>l.id===ce[p.BuiltInBaseEntity][fe.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(!Gg.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 eVe(d){switch(d){case p.Project:return L;case p.InstalledProject:return co;case p.DefinitionEntity:return us;case p.FunctionDeclaration:return Ia;case p.GlobalEvent:return io;case p.VariableInstance:return oo;case p.VariableDeclaration:return uo;case p.InputMap:return ls;case p.OutputMap:return ea;case p.Condition:return no;case p.Operation:return to;case p.FunctionCall:return Io;case p.ArgumentDeclaration:return ns;case p.PrimitiveEntity:return Rn;case p.DataType:return Wr;case p.Property:return ds;case p.ActionDescriptor:return Ut;case p.ReturnStatement:return cl;case p.ContinueStatement:return ho;case p.BreakStatement:return yo;case p.Loop:return ro;case p.Search:return po;case p.ValueDescriptor:return hl;case p.InternalCall:return fo;case p.LiteralValue:return $r}return null}function tVe(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 nr(d,u){const i=mp(d.type);return i?!i.MUTABLE_META_PROPERTIES.every(l=>{const c=d[l],e=u[l];return e===void 0||c===e?!0:Array.isArray(c)&&Array.isArray(e)?c.length!==e.length?!1:c.every((y,v)=>y===e[v]):!1}):!1}function sr(d,u,i){let a={...u};if(!d.checkCanEdit(d,i)){const l=mp(d.type);if(!l)return a;l.MUTABLE_META_PROPERTIES.forEach(c=>{["x","y","collapsed"].includes(c)||delete a[c]})}return a}function sv(d,u={}){if(d.type===p.Project)return[];if(!d.parent)return[];const i=te(d.parent);if(!i)return[];const a=u[i];return a?[a.id,...sv(a,u)]:[]}function iVe(d){const u=[],i=new Set;return[...d.listAdded,...d.listUpdated,...d.listAffected].forEach(l=>{var y;const c=Pi(l);if(!c||i.has(c.id))return;const e=d.project.get(c.id)||d.project.getDeleted(c.id);if(!e)throw new Error(`[getTouchedCanvasEntitiesFromChangeSet] Could not find active version of ${c.type} ${c.id} in project, which is present in the change set.${c.parent?` With parent ${(y=c.parent)==null?void 0:y.type} ${te(c.parent)}`:""}`);i.add(c.id),i.add(l.id),u.push(e)}),C(u)}function rVe(d){if(d.type===p.Condition)return null;if(d.type===p.Search)return d.project.getBuiltIn(ce["value-descriptor"][bh.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 gz(d){const u=d.entities.filter(l=>!!l.implements.find(c=>c.id===ce["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.id)),i=u.find(l=>{const c=l.properties.find(v=>v.implements.find(T=>T.id===ce["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.default.id)),e=c==null?void 0:c.getDefaultValue();return(e==null?void 0:e.value)===!0});return i||u[0]||null}function lR(d,u){const i=Array.from(new Set([...u.getAllBuiltInIds(),...Kn()]));return!!(i.includes(d.id)||!sv(d,{...u.instances,...u.builtInInstances}).every(c=>!i.includes(c)))}function _z(d){if(!d)return null;if(d.type===p.Project)return d.id;const u=d.parent;return u?_z(u):d.id}function Iy(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=Pi(d),i=Il(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 oR(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=Pi(d),i=Il(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 nVe(d,u,i){const a=u,l=i,c=!!i,e=[];return a.forEach(y=>{var v;if(c){const T=Ds(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 dR(d,u){var i,a,l,c;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=dR(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(((c=u.extends)==null?void 0:c.id)===d.id)return u;if(u.extends){const e=dR(u.extends,d);if(e)return e}}return null}function $d(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 $d(d.implements);if(d.extends)return $d(d.extends)}return d}function Al(d){var u;return!!(d.required||(u=d.declaration)!=null&&u.required)}function _o(d){return T6(d)||d===void 0||d===""}function ia(d){return d?d.valueAsType?!1:_o(d.value):!0}function Ay(d){return d.replace(/["'`]/g,"")}function Bi(d){const i=Ay(d).split(/[\s-]+/).filter(e=>e.length>0);if(i.length===0)return"";const a=i[0],l=a[0].toLowerCase()+a.slice(1),c=i.slice(1).map(e=>e[0].toUpperCase()+e.slice(1));return[l,...c].join("")}function Nd(d){return Ay(d).split(/[\s-]+/).filter(a=>a.length>0).map(a=>a[0].toUpperCase()+a.slice(1)).join("")}function Dz(d){const u=Ay(d).trim();if(!u)return"";const i=u.replace(/[\s_-]+/g," ").split(" ").filter(Boolean),a=[];for(const l of i){let c=l;c=c.replace(/([A-Z]+)([A-Z][a-z]+)/g,"$1-$2"),c=c.replace(/([a-z0-9])([A-Z][a-z0-9]*)/g,"$1-$2"),c=c.replace(/([0-9])([a-zA-Z]+)/g,"$1-$2"),c=c.replace(/([a-zA-Z])([0-9])/g,"$1-$2");for(const e of c.split("-"))e&&a.push(e)}return a.join("-")}function sVe(d){const u=Ay(d).trim();if(!u)return"";const i=u.replace(/[\s_-]+/g," ").split(" ").filter(Boolean),a=[];for(const l of i){let c=l;c=c.replace(/([A-Z]+)([A-Z][a-z]+)/g,"$1_$2"),c=c.replace(/([a-z0-9])([A-Z][a-z0-9]*)/g,"$1_$2"),c=c.replace(/([0-9])([a-zA-Z]+)/g,"$1_$2"),c=c.replace(/([a-zA-Z])([0-9])/g,"$1_$2");for(const e of c.split("_"))e&&a.push(e)}return a.join("_")}function av(d){return Dz(d).toLowerCase()}function uR(d){const u=Ay(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 Tp(d){var i,a,l,c;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)&&!((c=d.orChildrenGroup)!=null&&c.length))return e?`List of an any data type${u}`:`Any data type${u}`;let y="",v=!1,T=!1;return(d.andChildrenGroup||[]).forEach(I=>{const b=Tp(I),D=cd(b);v&&(y+=" and "),I.isGroup?y+="("+D+")":v?y+=D:y+=b,v=!0,T=!0}),(d.orChildrenGroup||[]).forEach(I=>{const b=Tp(I),D=cd(b);v&&(T&&(y+=","),y+=" or "),I.isGroup?y+="("+D+")":v?y+=D:y+=b,v=!0}),e?`List of ${cd(y)}`:y}if(d.entity.type===p.PrimitiveEntity){let e=d.entity.name;switch(d.entity.name){case ie.String:e="Text";break;case ie.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=Pz(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===ie.Null)return"Empty value";if(d.entity.name===ie.Untyped)return"Untyped value";if(d.entity.name===ie.File)return"File";if(d.entity.name===ie.String)return`"${d.entity.value}" text`;if(d.entity.name===ie.Number)return`Number '${d.entity.value}'`;if(d.entity.name===ie.Boolean)return`${d.entity.value} value`;if(d.entity.name===ie.UUID)return`"${d.entity.value}" unique identifier`;if(d.entity.name===ie.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 aVe(d){if(!d)return"Any data type";const u=d.getDataType(null);return Tp(u)}function lv(d){switch(d.declaration.id){case ut.Equal:return"is equal to";case ut.NotEqual:return"is not equal to";case ut.MoreThan:return"is greater than";case ut.MoreThanOrEqual:return"is greater than or equal to";case ut.LessThan:return"is less than";case ut.LessThanOrEqual:return"is less than or equal to";case Gi.And:return"and";case Gi.Or:return"or";case Ar.Empty:return"is empty";case Ar.NotEmpty:return"is present"}}function Oz(d){if(d.includes(fe.HTTP_ENDPOINT))return"HTTP endpoint";if(d.includes(fe.PERSISTED_ENTITY))return"Persisted entity";if(d.includes(fe.CRON_JOB))return"Scheduled execution";if(d.includes(fe.RELATIONAL_DATABASE))return"Relational database";if(d.includes(fe.SQL_ROW_TRANSFORMER))return"Row transformer";if(d.includes(fe.GOOGLE_AUTH_CONNECTION))return"Google account connection";if(d.includes(fe.SLACK_AUTH_CONNECTION))return"Slack account connection";if(d.includes(fe.AIRTABLE_AUTH_CONNECTION))return"Airtable account connection";if(d.includes(fe.MICROSOFT_AUTH_CONNECTION))return"Microsoft account connection";if(d.includes(fe.OPENAI_AUTH_CONNECTION))return"OpenAI account connection";if(d.includes(fe.ATLASSIAN_AUTH_CONNECTION))return"Atlassian account connection";if(d.includes(fe.JIRA_AUTH_CONNECTION))return"Jira account connection";if(d.includes(fe.GOOGLE_DRIVE_AUTH_CONNECTION))return"Google Drive account connection";if(d.includes(fe.GOOGLE_MAIL_AUTH_CONNECTION))return"Gmail account connection";if(d.includes(fe.GOOGLE_SHEET_AUTH_CONNECTION))return"Google Sheet account connection";if(d.includes(fe.GOOGLE_SLIDES_AUTH_CONNECTION))return"Google Slides account connection";if(d.includes(fe.GOOGLE_GEMINI_AUTH_CONNECTION))return"Google Gemini account connection";if(d.includes(fe.EXTERNAL_INTEGRATION_CONNECTION))return"External integration connection";try{return uR(d[0])}catch(u){return console.error("Error resolving base entity name for base entities:",d,u),"Built-in base entity"}}function Pz(d){switch(d.name){case fe.HTTP_ENDPOINT:return"HTTP endpoint";case fe.PERSISTED_ENTITY:return"Persisted entity";case fe.CRON_JOB:return"Scheduled execution";case fe.RELATIONAL_DATABASE:return"Relational database";case fe.SQL_ROW_TRANSFORMER:return"Row transformer";case fe.GOOGLE_AUTH_CONNECTION:return"Google account connection";case fe.SLACK_AUTH_CONNECTION:return"Slack account connection";case fe.AIRTABLE_AUTH_CONNECTION:return"Airtable account connection";case fe.MICROSOFT_AUTH_CONNECTION:return"Microsoft account connection";case fe.OPENAI_AUTH_CONNECTION:return"OpenAI account connection";case fe.ATLASSIAN_AUTH_CONNECTION:return"Atlassian account connection";case fe.JIRA_AUTH_CONNECTION:return"Jira account connection";case fe.GOOGLE_DRIVE_AUTH_CONNECTION:return"Google Drive account connection";case fe.GOOGLE_MAIL_AUTH_CONNECTION:return"Gmail account connection";case fe.GOOGLE_SHEET_AUTH_CONNECTION:return"Google Sheet account connection";case fe.GOOGLE_SLIDES_AUTH_CONNECTION:return"Google Slides account connection";case fe.GOOGLE_GEMINI_AUTH_CONNECTION:return"Google Gemini account connection";case fe.EXTERNAL_INTEGRATION_CONNECTION:return"External integration connection";case fe.EXTERNAL_INTEGRATION_CONNECTION:return"External integration connection"}try{return uR(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 lVe(d){const u=tv(d);if(!u){const i=yp(d);return i.includes(fe.HTTP_ENDPOINT)?"HTTP endpoint":i.includes(fe.PERSISTED_ENTITY)?"Persisted entity":i.includes(fe.CRON_JOB)?"Scheduled execution":i.includes(fe.RELATIONAL_DATABASE)?"Relational database":i.includes(fe.SQL_ROW_TRANSFORMER)?"Row transformer":i.includes(fe.GOOGLE_AUTH_CONNECTION)?"Google account connection":i.includes(fe.SLACK_AUTH_CONNECTION)?"Slack account connection":i.includes(fe.AIRTABLE_AUTH_CONNECTION)?"Airtable account connection":i.includes(fe.MICROSOFT_AUTH_CONNECTION)?"Microsoft account connection":i.includes(fe.OPENAI_AUTH_CONNECTION)?"OpenAI account connection":i.includes(fe.ATLASSIAN_AUTH_CONNECTION)?"Atlassian account connection":i.includes(fe.JIRA_AUTH_CONNECTION)?"Jira account connection":i.includes(fe.EXTERNAL_INTEGRATION_CONNECTION)?"External integration connection":S(d,d.project)+" entity"}return S(u,d.project)+" entity"}function $z(d){let u="Find ";return d.outputs.forEach((i,a)=>{const l=E0(i,null),c=cd(l&&l.entity?S(l.entity,d.project):"unstructured data");a===0?u+=`${c} `:a===d.outputs.length-1?u+=`and ${c} `:u+=`, ${c} `}),u}function Nz(d){switch(d.name){case ie.String:return"Text";case ie.Number:return"Number";case ie.Boolean:return"Boolean";case ie.KeyValue:return"Data structure";case ie.UUID:return"Unique identifier";case ie.Date:return"Date";case ie.EntityTemplate:return"Entity as template";case ie.Enum:return"Enumeration";case ie.File:return"File";case ie.Null:return"Empty";case ie.ActionDescriptor:return"Action descriptor";case ie.Untyped:return"Untyped";default:return d.name}}function Vz(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 $i.Addition:return"Sum numbers";case $i.Subtraction:return"Subtract numbers";case $i.Multiplication:return"Multiply numbers";case $i.Division:return"Divide numbers";case $i.Remainder:return"Get remainder of numbers";case $i.Exponentiation:return"Get exponent of numbers";case Je.AddIndex:return"Add at index position";case Je.DeleteFirst:return"Delete first character";case Je.DeleteLast:return"Delete last character";case Je.DeleteIndex:return"Delete at index position";case Je.Join:return"Join texts";case Je.ReplaceAllMatches:return"Replace all matches";case Je.ReplaceFirst:return"Replace first match";case Je.ReplaceLast:return"Replace last match";case Je.Split:return"Split text";case Je.ReplaceIndex:return"Replace at index position";case Je.ReplaceSingleMatch:return"Replace single match";case Je.GetFirst:return"Get first character";case Je.GetLast:return"Get last character";case Je.GetIndexItem:return"Get at index position";case Je.GetIndexOf:return"Get the index number of the character";case Je.Append:return"Add at the end";case Je.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 cn.HttpRequest:return"HTTP request";case dt.AddIndex:return"Add item at index position";case dt.DeleteFirst:return"Delete first item";case dt.DeleteLast:return"Delete last item";case dt.DeleteIndex:return"Delete item at index position";case dt.Join:return"Join lists";case dt.ReplaceFirst:return"Replace first match";case dt.ReplaceLast:return"Replace last match";case dt.Split:return"Split list";case dt.ReplaceIndex:return"Replace at index position";case dt.GetFirst:return"Get first item";case dt.GetLast:return"Get last item";case dt.GetIndexItem:return"Get item at index position";case dt.Append:return"Add item at the end";case dt.Prepend:return"Add item at the start";case js.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(dr).includes(a))switch(a){case dr.AbortExecution:return"Abort ongoing execution";case dr.DeletePersistedEntity:return"Delete entry from database";case dr.CreatePersistedEntity:return"Save new data entry in database";case dr.UpdatePersistedEntity:return"Update entity data to database";case dr.DownSQLRowTransformer:return"Reverse row";case dr.UpSQLRowTransformer:return"Transform row";default:return Tr(d.type).replaceAll("-"," ")}return a}if(p.BuiltInBaseEntity===d.type)return Oz([d.name]);if(jg.includes(d.type)&&d.type!==p.ActionDescriptor)return d.name;switch(d.type){case p.Search:return $z(d);case p.GlobalEvent:return d.implements?S(d.implements,u):Tr(d.type).replaceAll("-"," ");case p.Operation:case p.InternalCall:case p.Loop:const a=an(d.declaration,u);return S(a,u);case p.ActionDescriptor:return Vz(d);case p.BreakStatement:const l=an(d.parent,u);return`Stop loop ${S(l,u)}`;case p.ContinueStatement:const c=an(d.parent,u);return`Execute next iteration of ${S(c,u)}`;case p.FunctionCall:return an(d.declaration,u).name;case p.Condition:{const y=d;if(y.declaration.id===Gi.And)return"If all conditions are met";if(y.declaration.id===Gi.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} ${lv(y)} ${T}`}return`If ${v} ${lv(y)}`}else return`If ${lv(y)}`}case p.ReturnStatement:{const y=an(d.parent,u);return y?`Output of ${S(y,u)}`:"Return statement"}case p.InputMap:if(d.declaration){const y=an(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=an(d.declaration,u);return S(y,u)||""}case p.OutputMap:if(d.declaration){const y=an(d.declaration,u);return(y==null?void 0:y.name)||""}else return d.parentRelationType===Ol.Error?"Undeclared error":"";case p.PrimitiveEntity:case p.LiteralValue:return Nz(d);default:return Tr(d.type).replaceAll("-"," ")}}function pR(d,u){const i=[];d.name||i.push(new pe({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:ee.Error,code:de.EmptyName}));const a=u.entities.filter(l=>l.name===d.name);return a.length&&i.push(new pe({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,L.sessionAuthor,B().toISOString(),this,!0,"sync-dependents"))){const a=[],l=[],c=[],e=[];return Object.values(this.detachedDependents).forEach(y=>{const v=y.entity.afterAllChildrenInitialized(i);a.push(...v.updated),l.push(...v.added),c.push(...v.removed),e.push(...v.affected)}),i==null||i.attemptAutoclose("sync-dependents",this.id),{updated:C(a),added:C(l),removed:C(c),affected:C(e),self:this}}onDetachedDependencyRemoved(i,a,l){const c=[],e=[],y=[],v=[];if(a==="function-call-declaration-field"){const{updated:T,added:I,removed:b}=this.remove({ignoreUpstream:!1},l);c.push(...T),e.push(...I),y.push(...b)}if(a==="function-call-parent-field"){const{updated:T,added:I,removed:b}=this.remove({ignoreUpstream:!1},l);c.push(...T),e.push(...I),y.push(...b)}return{updated:C(c),added:C(e),removed:C(y),affected:C(v),self:this}}onDetachedDependencyRestored(i,a,l){const c=[],e=[],y=[],v=[];if(a==="function-call-declaration-field"){const{updated:T,added:I,removed:b}=this.restore({},l);c.push(...T),e.push(...I),y.push(...b)}if(a==="function-call-parent-field"){const{updated:T,added:I,removed:b}=this.restore({},l);c.push(...T),e.push(...I),y.push(...b)}return{updated:C(c),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=L.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=[],c=[],e=[];if(this.parent){this.parent.increaseVersion(i);const y=this.parent.recursiveCaptureUpstreamVersions(i);a.push(this.parent,...y.updated),l.push(...y.added),c.push(...y.removed)}return{updated:C(a),added:C(l),removed:C(c),affected:C(e),self:this}}async restoreVersion(i){var v;const a=[],l=[],c=[],e=[];if(this.version===i)return{updated:C(a),added:C(l),removed:C(c),affected:C(e),self:this};if(!this.knownVersions){const T=new Map;for(const[I,b]of this.knownVersions||new Map){if(T.set(I,b),b.activeVersion=!1,b.knownVersions)for(const[D,V]of b.knownVersions)T.set(D,V);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(c),affected:C(e),self:this}}updateWithShallowTransfer(i,a=this.project.addChangeSet(new G(this.project,L.sessionAuthor,B().toISOString(),this,!0,P.UpdateWithShallowTransfer))){if(!this.checkCanEdit(this,a))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=te(i.parent),c=this.project.get(l),e=this.parent;if(e&&e.id!==(c==null?void 0:c.id)&&this.removeFromParent(a),c)this.setParent(c,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=te(i.declaration),c=this.project.get(l);c&&this.setDeclaration(c)}return i.calledByEntry.forEach(l=>{const c=te(l),e=this.project.get(c);e&&(this.addEntryCaller(e,a),e.addCall(this,a))}),[...this.calledByEntry].forEach(l=>{i.calledByEntry.find(e=>te(e)===l.id)||(this.removeCaller(l,a),l.removeCall(this,a))}),i.calledBySuccess.forEach(l=>{const c=te(l),e=this.project.get(c);e&&(this.addSuccessCaller(e,a),e.addSuccessCall(this,a))}),[...this.calledBySuccess].forEach(l=>{i.calledBySuccess.find(e=>te(e)===l.id)||(this.removeCaller(l,a),l.removeCall(this,a))}),i.calledByError.forEach(l=>{const c=te(l),e=this.project.get(c);e&&(this.addErrorCaller(e,a),e.addErrorCall(this,a))}),[...this.calledBySuccess].forEach(l=>{i.calledBySuccess.find(e=>te(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=[],c=[];if(this.initialData.parent){const e=te(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=te(this.initialData.declaration),y=this.project.get(e);y&&(this.setDeclaration(y),i.push(y))}return this.initialData.calledByEntry.forEach(e=>{const y=te(e),v=this.project.get(y);v&&this.addEntryCaller(v,null)}),this.initialData.calledBySuccess.forEach(e=>{const y=te(e),v=this.project.get(y);v&&this.addSuccessCaller(v,null)}),this.initialData.calledByError.forEach(e=>{const y=te(e),v=this.project.get(y);v&&this.addErrorCaller(v,null)}),{updated:C(i),added:C(a),removed:C(l),affected:C(c),self:this}}afterAllChildrenInitialized(i=this.project.addChangeSet(new G(this.project,L.sessionAuthor,B().toISOString(),this,!0,P.AfterAllChildrenInitialized))){if(!this.checkCanEdit(this,i))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=[],c=[],e=[];this.initialized=!0;const{updated:y,added:v,removed:T}=this.syncInputs(i),{updated:I,added:b,removed:D}=this.syncOutputs(i);return a.push(...y,...I),l.push(...v,...b),c.push(...T,...D),this.captureVersion(),i==null||i.attemptAutoclose(P.AfterAllChildrenInitialized,this.id),{updated:C(a),added:C(l),removed:C(c),affected:C(e),self:this}}addSelfToProject(i=this.project.addChangeSet(new G(this.project,L.sessionAuthor,B().toISOString(),this,!0,"add-self-to-project"))){const a=[this],l=[],c=[],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(c),affected:C(e),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}removeInput(i,a=this.project.addChangeSet(new G(this.project,L.sessionAuthor,B().toISOString(),this,!0,P.RemoveInput))){if(!this.checkCanEdit(this,a))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(c=>c.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,L.sessionAuthor,B().toISOString(),this,!0,P.AddInput))){return this.checkCanEdit(this,a)?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,L.sessionAuthor,B().toISOString(),this,!0,"add-output"))){return this.checkCanEdit(this,a)?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,L.sessionAuthor,B().toISOString(),this,!0,"remove-output"))){if(!this.checkCanEdit(this,a))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(c=>c.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,L.sessionAuthor,B().toISOString(),this,!0,P.AddValueReader))){return this.checkCanEditFromScopeOwnerWithSideEffects(this,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,L.sessionAuthor,B().toISOString(),this,!0,P.RemoveValueReader))){return this.checkCanEditFromScopeOwnerWithSideEffects(this,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,L.sessionAuthor,B().toISOString(),this,!0,P.AddSuccessCaller)),l=!1){return this.checkCanEditWithCounterpartAndSideEffects(this,i,P.AddSuccessCaller,a)?(this.calledBySuccess.find(c=>c.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,L.sessionAuthor,B().toISOString(),this,!0,P.AddErrorCaller)),l=!1){return this.checkCanEditWithCounterpartAndSideEffects(this,i,P.AddErrorCaller,a)?(this.calledByError.find(c=>c.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,L.sessionAuthor,B().toISOString(),this,!0,P.AddEntryCaller)),l=!1){return this.checkCanEditWithCounterpartAndSideEffects(this,i,P.AddEntryCaller,a)?(this.calledByEntry.find(c=>c.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,L.sessionAuthor,B().toISOString(),this,!0,P.AddErrorCall)),l=!1){return this.checkCanEditWithCounterpartAndSideEffects(this,i,P.AddErrorCall,a)?(this.errorCalls.find(c=>c.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,L.sessionAuthor,B().toISOString(),this,!0,P.AddSuccessCall)),l=!1){return this.checkCanEditWithCounterpartAndSideEffects(this,i,P.AddSuccessCall,a)?(this.successCalls.find(c=>c.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,L.sessionAuthor,B().toISOString(),this,!0,P.RemoveCall)),l=!1){if(!this.checkCanEditWithCounterpartAndSideEffects(this,i,P.RemoveCall,a))return this;const c=this.successCalls.findIndex(y=>y.id===i.id);c>-1&&(this.successCalls.splice(c,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,L.sessionAuthor,B().toISOString(),this,!0,"remove-caller")),l=!1){return this.checkCanEditWithCounterpartAndSideEffects(this,i,P.RemoveCaller,a)?(this.calledBySuccess=this.calledBySuccess.filter(c=>c.id!==i.id?!0:(a==null||a.add(this,k.Updated),a==null||a.add(c,k.Affected),!1)),this.calledByError=this.calledByError.filter(c=>c.id!==i.id?!0:(a==null||a.add(this,k.Updated),a==null||a.add(c,k.Affected),!1)),this.calledByEntry=this.calledByEntry.filter(c=>c.id!==i.id?!0:(a==null||a.add(this,k.Updated),a==null||a.add(c,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,L.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,L.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=se(this.initialData.declaration,this.project);this.declaration=a}else{const a=te(this.initialData.declaration),l=this.project.get(a);this.declaration=l}return this.successCalls=this.initialData.successCalls.map(a=>{const l=se(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 c=Rr(this,this.project);l.setParent(c,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=se(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 c=Rr(this,this.project);l.setParent(c,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=se(a,this.project);return l.setParent(this,null),l.initChildren(i),l}),this.initialData.error&&(this.error=se(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,L.sessionAuthor,B().toISOString(),this,!0,"meta-sync"))){const l=sr(this,i,a),c=nr(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,a),l.deleted===!0&&!e.deleted?a==null||a.add(this,k.Removed):l.deleted===!1&&e.deleted?a==null||a.add(this,k.Added):c&&(a==null||a.add(this,k.Updated)),a==null||a.attemptAutoclose("meta-sync",this.id),this}async APILoad(i=we,...a){return await yi.repository.APILoad(this.id,...a),this}async APICreate(i=we,...a){return await yi.repository.APICreate(this.toShallowJSON(),...a),this}async APIUpdate(i=we,...a){return await yi.repository.APIUpdate(this.toShallowJSON(),...a),this}async APIDelete(i=we,...a){return await yi.repository.APIDelete(this.toShallowJSON(),...a),this}async APIClone(i=we,...a){return await yi.repository.APIClone(this.id,...a),this}async APILoadVersion(i=we,a,...l){return await yi.repository.APILoadVersion(this.id,a,...l)}removeFromParent(i=this.project.addChangeSet(new G(this.project,L.sessionAuthor,B().toISOString(),this,!0,P.RemoveFromParent))){if(!this.checkCanEdit(this,i))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=[],c=[],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(c),updated:C(a),removed:C(l),affected:C(e),self:this}}remove({ignoreUpstream:i}={ignoreUpstream:!1},a=this.project.addChangeSet(new G(this.project,L.sessionAuthor,B().toISOString(),this,!0,P.RemoveEntity))){var v;if(!this.checkCanDelete(this,a))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:ji.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=[],c=[],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(c.push(this),this.unsubscribe(),this.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},a),Object.values(this.detachedDependents).forEach(T=>{const{updated:I,removed:b,added:D}=T.entity.onDetachedDependencyRemoved(this,T.field,a);l.push(...I),c.push(...b),e.push(...D)}),this.inputs.forEach(T=>{const{updated:I,removed:b}=T.remove({ignoreUpstream:!0},a);l.push(...I),c.push(...b)}),this.outputs.forEach(T=>{const{updated:I,removed:b}=T.remove({ignoreUpstream:!0},a);l.push(...I),c.push(...b)}),this.error){const{updated:T,removed:I}=this.error.remove({ignoreUpstream:!0},a);l.push(...T),c.push(...I)}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),c.push(...T.removed),y.push(...T.affected),this.calledBy.forEach(I=>{l.push(I),I.removeCall(this,a)})}return a==null||a.attemptAutoclose(P.RemoveEntity,this.id),{added:C(e),updated:C(l),removed:C(c),affected:C(y),self:this}}restore({}={},i=this.project.addChangeSet(new G(this.project,L.sessionAuthor,B().toISOString(),this,!0,P.RestoreEntity))){if(!this.checkCanEdit(this,i))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=[],c=[],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:I}=y.entity.onDetachedDependencyRestored(this,y.field,i);l.push(...v),c.push(...T),a.push(...I)}),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(c),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,c,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)),(c=i.seenEntities)!=null&&c.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:L.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(I=>I.toJSONClone({...i,newId:null})),successCalls:this.successCalls.map(I=>I.toJSONClone({...i,newId:null})),errorCalls:this.errorCalls.map(I=>I.toJSONClone({...i,newId:null})),calledBySuccess:this.calledBySuccess.map(I=>I.toReference({seenEntityMaps:i.seenEntityMaps})),calledByError:this.calledByError.map(I=>I.toReference({seenEntityMaps:i.seenEntityMaps})),calledByEntry:this.calledByEntry.map(I=>I.toReference({seenEntityMaps:i.seenEntityMaps})),declaration:this.declaration.toJSONClone({...i,newId:null}),inputs:this.inputs.map(I=>I.toJSONClone({...i,newId:null})),outputs:this.outputs.map(I=>I.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+"--"+L.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(c=>c.toReference(i)),inputs:this.inputs.map(c=>c.toReference(i)),outputs:this.outputs.map(c=>c.toReference(i)),declaration:this.declaration.toReference(i),successCalls:this.successCalls.map(c=>c.toReference(i)),errorCalls:this.errorCalls.map(c=>c.toReference(i)),calledBySuccess:this.calledBySuccess.map(c=>c.toReference(i)),calledByError:this.calledByError.map(c=>c.toReference(i)),calledByEntry:this.calledByEntry.map(c=>c.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=mH(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,L.sessionAuthor,B().toISOString(),this,!0,P.CloneEntity)),a=null,l=null,c=!0){var M,x;let e=fr(a,this);const y=this.toJSON(),v=l||L.UUID.uuid();y.inputs=[];const T=v.split("-id"),I=T[T.length-1||0]||v;y.id=v,y.version=L.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),c&&b.subscribe(),b.initChildren(i),i==null||i.add(b,k.Added);const D=(M=this.inputs)==null?void 0:M.map((q,Z)=>q.clone(i,b,I+"-input-map-"+Z+"-id",c));b.inputs=D;const V=(x=this.outputs)==null?void 0:x.map((q,Z)=>q.clone(i,b,I+"-output-map-"+Z+"-id",c));return b.outputs=V,this.error&&(b.error=this.error.clone(i,b,I+"-error-map-id",c)),i==null||i.attemptAutoclose(P.CloneEntity,this.id),b}removeUnrecognizedInputs(i=this.project.addChangeSet(new G(this.project,L.sessionAuthor,B().toISOString(),this,!0,P.RemoveUnrecognizedInputs))){if(!this.checkCanEdit(this,i))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=[],c=[],e=[];return this.inputs.forEach(v=>{if(!this.declaration.inputs.find(I=>{var b;return I.id===((b=v.declaration)==null?void 0:b.id)})){const I=v.remove({ignoreUpstream:!1},i);c.push(...I.removed),a.push(...I.updated)}}),this.inputs.filter((v,T)=>{const I=this.inputs.findIndex(D=>D.declaration===v.declaration&&D!==v);if(I===-1)return!1;const b=this.inputs[I];return B(b==null?void 0:b.createdAt).isSame(B(v.createdAt))?T>I:!!B(b==null?void 0:b.createdAt).isAfter(v.createdAt)}).forEach(v=>{const T=v.remove({ignoreUpstream:!1},i);c.push(...T.removed),a.push(...T.updated)}),i==null||i.attemptAutoclose(P.RemoveUnrecognizedInputs,this.id),{updated:C(a),added:C(l),removed:C(c),affected:C(e),self:this}}removeUnrecognizedOutputs(i=this.project.addChangeSet(new G(this.project,L.sessionAuthor,B().toISOString(),this,!0,P.RemoveUnrecognizedOutputs))){var T,I;if(!this.checkCanEdit(this,i))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=[],c=[],e=[],y=((I=(T=this.declaration.dataType)==null?void 0:T.entity)==null?void 0:I.properties)||[];return this.outputs.forEach(b=>{if(!y.find(V=>{var M;return V.id===((M=b.declaration)==null?void 0:M.id)})){const V=b.remove({ignoreUpstream:!1},i);c.push(...V.removed),a.push(...V.updated)}}),this.outputs.filter((b,D)=>{const V=this.outputs.findIndex(x=>x.declaration===b.declaration&&x!==b);if(V===-1)return!1;const M=this.outputs[V];return B(M==null?void 0:M.createdAt).isSame(B(b.createdAt))?D>V:!!B(M==null?void 0:M.createdAt).isAfter(b.createdAt)}).forEach(b=>{const D=b.remove({ignoreUpstream:!1},i);c.push(...D.removed),a.push(...D.updated)}),i==null||i.attemptAutoclose(P.RemoveUnrecognizedOutputs,this.id),{updated:C(a),added:C(l),removed:C(c),affected:C(e),self:this}}syncInputs(i=this.project.addChangeSet(new G(this.project,L.sessionAuthor,B().toISOString(),this,!0,P.SyncInputs))){if(!this.checkCanEdit(this,i))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=[],c=[],e=[],y=this.declaration.inputs.filter(b=>!this.inputs.find(D=>D.declaration.id===b.id));this.inputs.sort((b,D)=>b.index-D.index),y.forEach(b=>{this.inputs.forEach(M=>{M.index>=b.index&&M.metaSync({index:M.index+1},i)});const D={id:L.UUID.uuid(),version:L.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||B().toISOString(),author:L.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()},V=se(D,this.project);V.setParent(this,i),V.initChildren(i),i==null||i.add(V,k.Added),V.addSelfToProject(i),l.push(V)}),this.inputs.sort((b,D)=>b.index-D.index);const{updated:v,added:T,removed:I}=this.removeUnrecognizedInputs(i);return a.push(...v),l.push(...T),c.push(...I),i==null||i.attemptAutoclose(P.SyncInputs,this.id),{updated:C(a),added:C(l),removed:C(c),affected:C(e),self:this}}syncOutputs(i=this.project.addChangeSet(new G(this.project,L.sessionAuthor,B().toISOString(),this,!0,P.SyncOutputs))){var D,V;if(!this.checkCanEdit(this,i))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=[],c=[],e=[],y=[];this.outputs=this.initialData.outputs.reduce((M,x)=>{if(x.type===p.GenericReference){const Z=an(x,this.project);return Z?[...M,Z]:M}const q=se(x,this.project);return y.push(q.index),q.setParent(this,null),q.initChildren(i),[...M,q]},[]);const v=(((V=(D=this.declaration.dataType)==null?void 0:D.entity)==null?void 0:V.properties)||[]).filter(M=>!this.outputs.find(x=>{var q;return((q=x.declaration)==null?void 0:q.id)===M.id}));this.outputs.sort((M,x)=>M.index-x.index),v.forEach((M,x)=>{this.outputs.forEach(Y=>{Y.index>=M.index&&Y.index++});const q=y.includes(M.index)?this.outputs.length-1+x:M.index,Z={id:L.UUID.uuid(),version:L.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||B().toISOString(),author:L.sessionAuthor,previousVersion:null,deleted:!1,deletable:!0,editable:!0,type:p.OutputMap,declaration:M.toJSON(),writesValues:[],index:q,parent:this.toReference()},W=se(Z,this.project);W.setParent(this,i),W.initChildren(i),i==null||i.add(W,k.Added),W.addSelfToProject(i)}),this.outputs.sort((M,x)=>M.index-x.index);const{updated:T,added:I,removed:b}=this.removeUnrecognizedOutputs(i);return a.push(...T),l.push(...I),c.push(...b),i==null||i.attemptAutoclose(P.SyncOutputs,this.id),{updated:C(a),added:C(l),removed:C(c),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,L.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",[...Qi,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 Io=yi;function Zw(d){return d&&typeof d.then=="function"}function hNe(d){const u=new Da(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 mNe(d){const u=new Da(Object.values(d)[0]),i=Object.keys(d);return u.order=i,u.flatRecord=d,u.orderEntities(),u.order}class Da{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(Ee(u,i,{ignoreBuiltInBaseEntities:!0})),l=new Set;for(const c of a)this.flatRecord[c.id]=c,l.add(c.id);this.order=Array.from(l)}moveEntityAfterDependencies(u){const{upstream:i}=pp(u,this.flatRecord,{ignoreBuiltInBaseEntities:!0,allBuiltInEntityIds:this.allBuiltInEntityIds});for(const a of Object.keys(i)){const l=this.order.indexOf(a),c=this.order.indexOf(u.id);if(l>c)return this.order.splice(c,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}=pp(this.flatRecord[u],this.flatRecord,{ignoreBuiltInBaseEntities:!0,allBuiltInEntityIds:this.allBuiltInEntityIds}),l={};return Object.entries(this.onGoingVisits[i]||{}).forEach(([c,e])=>{Object.keys(a).includes(c)&&(l[c]=e)}),l}getDownstreamOngoingDependenciesVisits(u,i){const a=Object.keys(this.onGoingVisits[i]||{}),l=new Set(a.flatMap(e=>Object.keys(pp(this.flatRecord[e],this.flatRecord,{ignoreBuiltInBaseEntities:!0,allBuiltInEntityIds:this.allBuiltInEntityIds}).downstream))),c={};return Array.from(l).forEach(e=>{e===u&&(c[e]=this.onGoingVisits[i][e])}),c}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 c=this.getUpstreamOngoingDependenciesVisits(l,a);Object.keys(c).length&&await this.settlePromises(c,a);const e=u(this.flatRecord[l],this.flatRecord);Zw(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 c=this.getDownstreamOngoingDependenciesVisits(l,a);Object.keys(c).length&&await this.settlePromises(c,a);const e=u(this.flatRecord[l],this.flatRecord);Zw(e)&&(this.onGoingVisits[a][l]=e)}return await this.settlePromises(this.onGoingVisits[a],a),this.onGoingVisits[a]={},this}}const vNe=63,TNe=/^[a-z][a-z0-9-]*[a-z0-9]$/;function ENe(d){return d.length>=1&&d.length<=vNe&&TNe.test(d)&&!d.includes("--")}function*bNe(){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 INe(d,u){const i=new Set(d.map(l=>l.toLowerCase())),a=u>0?"secondary-db":"main";for(const l of bNe()){const c=l?`${a}-${l}`:a;if(ENe(c)&&!i.has(c))return c}throw new Error("Unable to generate identifier")}function vH(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(D=>D.implements.find(V=>V.id===ce["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.default.id)),I=T==null?void 0:T.getDefaultValue();return(I==null?void 0:I.value)===!0});if(!a&&i.length){const T=i[0].properties.find(b=>b.implements.find(D=>D.id===ce["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.default.id)),I=T==null?void 0:T.defaultValue;if(I)I.metaSync({value:!0},u);else if(T!=null&&T.dataType){const b={id:L.UUID.uuid(),version:L.UUID.uuid(),createdAt:(u==null?void 0:u.timestamp)||new Date().toISOString(),author:L.sessionAuthor,previousVersion:null,deleted:!1,deletable:!0,editable:!0,type:p.LiteralValue,standaloneParent:null,name:ie.EntityTemplate,autogeneration:null,value:!0,valueAsTypeSingle:null,valueAsTypeList:null,parent:T==null?void 0:T.toReference()},D=se(b,d.project);return D.setParent(T,u),D.initChildren(u),u==null||u.add(D,k.Added),D.addSelfToProject(u),{newEntities:[D]}}return{newEntities:[]}}else if(a)return{newEntities:[]};const l=d.project.get(ce["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.id),c=q0(l,"Main database",u);if(c.errors.length>0)return{newEntities:[]};const e=c.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:L.UUID.uuid(),version:L.UUID.uuid(),createdAt:(u==null?void 0:u.timestamp)||new Date().toISOString(),author:L.sessionAuthor,previousVersion:null,deleted:!1,deletable:!0,editable:!0,type:p.LiteralValue,standaloneParent:null,name:ie.EntityTemplate,autogeneration:null,value:!0,valueAsTypeSingle:null,valueAsTypeList:null,parent:e==null?void 0:e.toReference()},T=se(v,d.project);T.setParent(e,u),T.initChildren(u),u==null||u.add(T,k.Added),T.addSelfToProject(u)}return{newEntities:[c]}}}return{newEntities:[]}}function TH(d,u){const i=[],a=[],l=[],c=[];return d.implements.filter(y=>y.type===p.BuiltInBaseEntity).forEach(y=>{var v,T,I,b,D;switch(y.id){case ce["built-in-base-entity"].BUILT_IN_PERSISTED_ENTITY_ENTITY.id:{const V=d.project.entities.filter(W=>W.implements.find(Y=>Y.id===ce["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.id));let M=V.find(W=>!!W.properties.find(Y=>{var re;return Y.implements.find(z=>z.id===ce["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.default.id)&&((re=Y.getDefaultValue())==null?void 0:re.value)===!0}));if(!M&&V.length)M=V[0];else if(!M&&!V.length){M=d.project.getBuiltIn(ce["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.id).implement("Relational database",u);const Y=M.properties.find(re=>re.implements.find(z=>z.id===ce["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.default.id));(v=Y==null?void 0:Y.defaultValue)==null||v.metaSync({value:!0},u),a.push(M)}const x=d.properties.find(W=>W.implements.find(Y=>Y.id===ce["built-in-base-entity"].BUILT_IN_PERSISTED_ENTITY_ENTITY.properties.database.id));if(x&&!(x!=null&&x.defaultValue)){const W={id:L.UUID.uuid(),version:L.UUID.uuid(),createdAt:(u==null?void 0:u.timestamp)||new Date().toISOString(),author:L.sessionAuthor,previousVersion:null,deleted:!1,deletable:!0,editable:!0,type:p.LiteralValue,standaloneParent:null,name:ie.EntityTemplate,autogeneration:null,value:null,valueAsTypeSingle:(M==null?void 0:M.toJSON())||null,valueAsTypeList:null,parent:x==null?void 0:x.toReference()},Y=se(W,d.project);Y.hydrateAncestors(),Y.setParent(x,u),Y.addSelfToProject(u),u==null||u.add(Y,k.Added),Y.initChildren(u),(x==null?void 0:x.defaultValue).setValueAsTypeSingle(M||null,u),a.push(Y);return}else x!=null&&x.defaultValue&&!(x!=null&&x.defaultValue.valueAsTypeSingle)&&(x==null||x.defaultValue.setValueAsTypeSingle(M||null,u));const q=d.properties.find(W=>W.implements.find(Y=>Y.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 W=Wr.new(u);W.parent=q.toReference();const Y=se(W,d.project);Y.hydrateAncestors(),Y.setParent(q,u),Y.addSelfToProject(u),u==null||u.add(Y,k.Added),Y.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 V=d.project.entities.filter(re=>re.implements.find(z=>z.id===ce["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.id)&&re.id!==d.id),M=V.map(re=>{var le;const z=re.properties.find(ye=>ye.implements.find(he=>he.id===ce["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.identifier.id));return(le=z==null?void 0:z.getDefaultValue())==null?void 0:le.value}).filter(re=>!!re),x=d.properties.find(re=>re.implements.find(z=>z.id===ce["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.identifier.id));if(!V.find(re=>!!re.properties.find(z=>{var oe;return z.implements.find(le=>le.id===ce["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.default.id)&&((oe=z.getDefaultValue())==null?void 0:oe.value)===!0}))){const re=d.properties.find(z=>z.implements.find(oe=>oe.id===ce["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.default.id));if(!re)throw new Error("Default boolean property not found for relational database entity with id: "+d.id);if(!(re!=null&&re.defaultValue)){const z=$r.new(u);z.parent=re.toReference();const oe=se(z,d.project);oe.hydrateAncestors(),oe.setParent(re,u),oe.addSelfToProject(u),u==null||u.add(oe,k.Added),oe.initChildren(u)}(I=re==null?void 0:re.defaultValue)==null||I.metaSync({value:!0},u)}if(!x)throw new Error("Identifier property not found for relational database entity with id: "+d.id);if(!(x!=null&&x.defaultValue)){const re=$r.new(u);re.parent=x.toReference();const z=se(re,d.project);z.hydrateAncestors(),z.setParent(x,u),z.addSelfToProject(u),z.initChildren(u),u==null||u.add(z,k.Added)}const Z=INe(M,V.length);(b=x.defaultValue)==null||b.metaSync({value:Z},u);const W=d.properties.find(re=>re.implements.find(z=>z.id===ce["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.password.id));if(!W)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(!W.defaultValue){const re=$r.new(u);re.parent=W.toReference();const z=se(re,d.project);z.hydrateAncestors(),z.setParent(W,u),z.addSelfToProject(u),z.initChildren(u),u==null||u.add(z,k.Added),a.push(z)}const Y=lq(24);(D=W.defaultValue)==null||D.metaSync({value:Y},u);return}case ce["built-in-base-entity"].BUILT_IN_SQL_ROW_TRANSFORMER_ENTITY.id:{const V=d.properties.find(Z=>Z.implements.find(W=>W.id===ce["built-in-base-entity"].BUILT_IN_SQL_ROW_TRANSFORMER_ENTITY.properties.time.id));if(!V)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=V.defaultValue||null;if(!M){const Z=$r.new(u);Z.parent=V.toReference(),Z.name=ie.Date,Z.id=L.UUID.uuid(),M=se(Z,d.project),M.hydrateAncestors(),M.setParent(V,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),V.metaSync({editable:!1,deletable:!1},u);const x=d.properties.find(Z=>Z.implements.find(W=>W.id===ce["built-in-base-entity"].BUILT_IN_SQL_ROW_TRANSFORMER_ENTITY.properties.definition.id));if(!x)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=x.defaultValue||null;if(!q){const Z=$r.new(u);Z.name=ie.EntityTemplate,Z.parent=x.toReference(),Z.id=L.UUID.uuid(),q=se(Z,d.project),q.hydrateAncestors(),q.setParent(x,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(c)}}function q0(d,u,i,a){const l=a||L.UUID.uuid(),c=us.new(i);c.id=l,c.name=u,c.static=d.static,c.implements=[d.toJSON()],c.parent=d.project.toReference(),c.static=d.static,vH(d,i);const e=se(c,d.project);return e.hydrateAncestors(),i==null||i.add(e,k.Added),e.addSelfToProject(i),e.initChildren(i),TH(e,i),e.afterAllChildrenInitialized(i),e}function Ww(d,u){return u.entities.find(l=>{const c=l.properties,e=c.map(b=>b.name),y=d.every(b=>e.includes(b)),v=e.filter(b=>!d.includes(b)),T=c.every(b=>!v.includes(b.name)||!b.required);return y&&T})||null}function EH(d,u,i,a=vr.OrDataTypeGroup){const l=[],c=[],e=[],y=[],T={id:L.UUID.uuid(),version:L.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||new Date().toISOString(),author:L.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()},I=se(T,d.project);return c.push(I),I.setParent(u,i),I.initChildren(i),i==null||i.add(I,k.Added),I.setEntity(d,i),I.addSelfToProject(i),{updated:C(l),added:C(c),removed:C(e),affected:C(y),self:I}}function Hw(d,u,i,a,l){var T,I,b,D,V,M,x,q;const c=[],e=[],y=[],v=[];switch(typeof d){case"string":let Z=!1;const W=new Date(d);if(W instanceof Date&&!isNaN(W.valueOf())&&(Z=!0),Z){const Y=u.project.getBuiltIn(ce[p.PrimitiveEntity][ie.Date].id);u.setEntity(Y,a);break}else{const Y=u.project.getBuiltIn(ce[p.PrimitiveEntity][ie.String].id);u.setEntity(Y,a);break}case"number":u.setEntity(u.project.getBuiltIn(ce[p.PrimitiveEntity][ie.Number].id),a);break;case"boolean":u.setEntity(u.project.getBuiltIn(ce[p.PrimitiveEntity][ie.Boolean].id),a);break;case"object":if(d===null){u.setEntity(u.project.getBuiltIn(ce[p.PrimitiveEntity][ie.Null].id),a);break}else if(Array.isArray(d))if(u.metaSync({isList:!0},a),d.length>0){const Y=d.slice(0,5).filter(z=>z!==void 0);if(Y.every(z=>typeof z==typeof Y[0])&&(typeof Y[0]!="object"||Y[0]===null))switch(typeof Y[0]){case"string":u.setEntity(u.project.getBuiltIn(ce[p.PrimitiveEntity][ie.String].id),a);break;case"number":u.setEntity(u.project.getBuiltIn(ce[p.PrimitiveEntity][ie.Number].id),a);break;case"boolean":u.setEntity(u.project.getBuiltIn(ce[p.PrimitiveEntity][ie.Boolean].id),a);break;case"object":u.setEntity(u.project.getBuiltIn(ce[p.PrimitiveEntity][ie.Null].id),a);break}else{const z=[];let oe=!1;Y.forEach(ye=>{var he,Q,ue,Te;if(Array.isArray(ye)&&(oe=!0),typeof ye=="object"&&!Array.isArray(ye)&&ye!==null){const _e=Z0(ye,u.project,{...i,id:L.UUID.uuid()},a,l);_e.hasCreated&&z.push((he=_e.changeSet)==null?void 0:he.self),c.push(...(Q=_e.changeSet)==null?void 0:Q.updated),e.push(...(ue=_e.changeSet)==null?void 0:ue.added),y.push(...(Te=_e.changeSet)==null?void 0:Te.removed)}});const le=C(z);if(!le.length&&!oe){Y.forEach(ye=>{const he={id:L.UUID.uuid(),version:L.UUID.uuid(),createdAt:(a==null?void 0:a.timestamp)||new Date().toISOString(),author:L.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:vr.OrDataTypeGroup,parent:u.toReference()},Q=se(he,u.project);switch(Q.setParent(u,a),Q.initChildren(a),a==null||a.add(Q,k.Added),Q.addSelfToProject(a),typeof ye){case"string":Q.setEntity(Q.project.getBuiltIn(ce[p.PrimitiveEntity][ie.String].id),a);break;case"number":Q.setEntity(Q.project.getBuiltIn(ce[p.PrimitiveEntity][ie.Number].id),a);break;case"boolean":Q.setEntity(Q.project.getBuiltIn(ce[p.PrimitiveEntity][ie.Boolean].id),a);break;case"object":Q.setEntity(Q.project.getBuiltIn(ce[p.PrimitiveEntity][ie.Null].id),a);break}});break}else le.length===1&&!oe?u.setEntity(le[0],a):Y.forEach(ye=>{if(typeof ye=="object"&&!Array.isArray(ye)&&ye!==null){const he=Ww(Object.keys(ye),u.project);if(he){const Q=EH(he||le[0],u,a,vr.OrDataTypeGroup);c.push(...Q.updated),e.push(...Q.added),y.push(...Q.removed)}}else{const he={id:L.UUID.uuid(),version:L.UUID.uuid(),createdAt:(a==null?void 0:a.timestamp)||new Date().toISOString(),author:L.sessionAuthor,previousVersion:null,deleted:!1,deletable:!0,editable:!0,type:p.DataType,options:null,implementationChooseOne:!1,entity:null,isList:Array.isArray(ye),asType:!1,andChildrenGroup:null,index:null,orChildrenGroup:null,staticEntities:!1,interactiveEntities:!0,actionEntities:!1,like:!0,inferred:!1,parentRelationType:vr.OrDataTypeGroup,parent:u.toReference()},Q=se(he,u.project);Q.setParent(u,a),Q.initChildren(a),a==null||a.add(Q,k.Added),Q.addSelfToProject(a);const ue=Hw(ye,Q,{...i,id:L.UUID.uuid()},a,l);c.push(...ue.updated),e.push(...ue.added),y.push(...ue.removed)}})}}else{const Y=Z0(d[0],u.project,{...i},a,l);u.setEntity((T=Y.changeSet)==null?void 0:T.self,a),c.push(...(I=Y.changeSet)==null?void 0:I.updated),e.push(...(b=Y.changeSet)==null?void 0:b.added),y.push(...(D=Y.changeSet)==null?void 0:D.removed);break}else{const Y=Z0(d,u.project,{...i},a,l);u.setEntity((V=Y.changeSet)==null?void 0:V.self,a),c.push(...(M=Y.changeSet)==null?void 0:M.updated),e.push(...(x=Y.changeSet)==null?void 0:x.added),y.push(...(q=Y.changeSet)==null?void 0:q.removed);break}}return{updated:C(c),added:C(e),removed:C(y),affected:C(v),self:u}}function Z0(d,u,i,a,l){const c=[],e=[],y=[],v=[],T=Object.keys(d),I=Ww(T,u);if(I)return{hasCreated:!1,changeSet:{updated:[],added:[],removed:[],affected:[],self:I}};const b=l?i.name+" of "+l.name:i.name,V={id:i.id||L.UUID.uuid(),version:L.UUID.uuid(),createdAt:(a==null?void 0:a.timestamp)||new Date().toISOString(),author:L.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=se(V,u);return M.setParent(u,a),M.initChildren(a),a==null||a.add(M,k.Added),M.addSelfToProject(a),e.push(M),T.forEach((x,q)=>{const W={id:L.UUID.uuid(),version:L.UUID.uuid(),createdAt:(a==null?void 0:a.timestamp)||new Date().toISOString(),author:L.sessionAuthor,previousVersion:null,deleted:!1,name:x,deletable:!0,editable:!0,type:p.Property,parentRelationType:null,codeName:x,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()},Y=se(W,u);Y.setParent(M,a),Y.initChildren(a),a==null||a.add(Y,k.Added),Y.addSelfToProject(a),e.push(Y);const re=d[x],oe={id:L.UUID.uuid(),version:L.UUID.uuid(),createdAt:(a==null?void 0:a.timestamp)||new Date().toISOString(),author:L.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:Y.toReference()},le=se(oe,u);le.setParent(Y,a),le.initChildren(a),a==null||a.add(le,k.Added),le.addSelfToProject(a),e.push(le);const ye=Hw(re,le,{...i,name:x,id:L.UUID.uuid()},a,l||M);c.push(...ye.updated),e.push(...ye.added),y.push(...ye.removed)}),{hasCreated:!0,changeSet:{updated:C(c),added:C(e),removed:C(y),affected:C(v),self:M}}}function Tl(d,u,i,a){const l=[];return!d.length||!u.length?{errors:l,overlap:!1}:(d.length>u.length?d.forEach(c=>{const e=u.find(v=>v.name===c.name),y=u.find(v=>{var T,I;return Array.isArray(v.implements)?v.implements.some(b=>!!c.implements.find(D=>D.id===b.id)):((T=v.implements)==null?void 0:T.id)===((I=c.implements)==null?void 0:I.id)});if(e){const v=new vi({id:c.id+"--"+e.id+"--"+a,message:`Entity of type ${c.type} named "${c.name}" with id "${c.id}" overrides a base ${e.type} ${e.name} with id "${e.id}" that has the same name`,severity:ee.Error,code:a,entity:c,firstRelationship:e});l.push(v)}if(y){const v=new vi({id:c.id+"--"+y.id+"--"+i,message:`Entity of type ${c.type} named "${c.name}" with id "${c.id}" overrides a base ${y.type} ${y.name} with id "${y.id}" that implements the same base descriptor`,severity:ee.Error,code:i,entity:c,firstRelationship:y});l.push(v)}}):u.forEach(c=>{var v;const e=d.find(T=>T.name===c.name),y=d.find(T=>{var I,b;return T.implements&&Array.isArray(T.implements)?T.implements.some(D=>!!c.implements.find(V=>V.id===D.id)):((I=T.implements)==null?void 0:I.id)===((b=c.implements)==null?void 0:b.id)});if(e){const T=new vi({id:e.id+"--"+c.id+"--"+a,message:`Entity of type ${e.type} named "${e.name}" with id "${e.id}" overrides a base entity ${c.name} with id "${c.id}" that has the same name`,severity:ee.Error,code:a,entity:e,firstRelationship:c});l.push(T)}if(y){const T=new vi({id:y.id+"--"+c.id+"--"+i,message:`Entity of type ${y.type} named "${y.name}" with id "${y.id}" overrides a base entity ${c.name} with id "${c.id}" that implements the same base ${Array.isArray(y==null?void 0:y.implements)?yt(y==null?void 0:y.implements.map(I=>I.type),"', '","' and '"):(v=y.implements)==null?void 0:v.id}`,severity:ee.Error,code:i,entity:y,firstRelationship:c});l.push(T)}}),{errors:l,overlap:!!l.length})}function ANe(d,u){return d.abstract||(d.properties.forEach(a=>{a.abstract||a.metaSync({abstract:!0},u)}),Object.values(d.detachedDependents).forEach(a=>{a.field===uA.Entity&&a.entity.remove({ignoreUpstream:!1},u)}),d.metaSync({abstract:!0},u)),d}function wNe(d,u){return d.abstract&&(d.properties.forEach(a=>{a.abstract&&a.metaSync({abstract:!1},u)}),Object.values(d.detachedDependents).forEach(a=>{(a.field===dv.Implements||a.field===dv.Extends)&&a.entity.onDetachedDependencyRemoved(d,a.field,u)}),d.metaSync({abstract:!1},u)),d}function RNe(d,u){return d.static||(d.properties.forEach(a=>{a.static||a.metaSync({static:!0},u)}),d.metaSync({static:!0},u)),d}function CNe(d,u){return d.static&&d.metaSync({static:!1},u),d}var mn=(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))(mn||{});function zw(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:ee.Error,code:"string-value-must-not-have-spaces",entity:d});i.push(l)}return{errors:i,override:a.replace(/\s/g,"-")}}function bH(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:ee.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:ee.Error,code:"string-value-must-not-have-dashes",entity:d});i.push(l)}return{errors:i,override:a.replace(/\s|-/g,"_")}}function Jw(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 Wr||d.increaseVersion)return`${d.type}: ${d.id} (${Tp(d)})`;try{const a=Tp(d);return`${d.type}: ${d.id} (${a})`}catch{}}return`${d.type}: ${d.id} (${S(d,u)})`}function op(d,u){const i=Ro(d);if(i.length===0)return{list:[],last:null};let a=null;return{list:i.flatMap(c=>{if(c===u)return a=c,[c];const e=op(c,u);return e.last&&(a=e.last),[c,...e.list]}),last:a}}function Ao(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,Gt.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(!Mr.includes(e.type))return[e];const y=Ao(e,u);return y.last&&(a=y.last,l=y.callType),[e,...y.list]}),last:a,callType:l}}function gNe(d,u){if(d===u)return"same-entity";if(!Dr.includes(d.type)||!wo(d).find(l=>l.callee===u))return null;if(Gt.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 yy(d){const u=zr(d,d.project);return u?Gt.includes(u.type)?u:u.type===p.Loop?u.body:null:null}function Yw(d,u){const i=d.calledBy;return!i||!i.length?!1:i.every(a=>a===u?!0:Mr.includes(a.type)?!!Ao(a,u).last:!1)}function IH(d){return d.filter(u=>{const i=yy(u);return!d.filter(c=>c!==u).some(c=>c===i?!1:z0(c,u))})}function Sw(d){if(!d.calledBy||!d.calledBy.length)return[];const u=d.calledBy.reduce((i,a)=>{if(Mr.includes(a.type)){const l=Sw(a);return[...i,a,...l]}return i},[]);return C(u)}function AH(d){const u=Sw(d);if(!u.length)return{ancestor:null,callType:null};const a=u.filter(c=>!(c===d||!Dr.includes(c.type)||!ht(c).find(v=>v===d))).filter((c,e,y)=>y.findIndex(v=>v===c)===e).filter(c=>Yw(d,c)),l=a.filter(c=>{const e=ht(c),y=a.filter(T=>T!==c).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 c=l[0];if(c.type===p.Loop){if(c.body.calls.includes(d))return{ancestor:c,callType:"loop-body"}}else if(Gt.includes(c.type)){if(c.calls.includes(d))return c.type===p.FunctionDeclaration&&c.parent.type===p.Loop?{ancestor:c,callType:"loop-body"}:{ancestor:c,callType:"entry"}}else if(mi.includes(c.type)){if(c.successCalls.includes(d))return{ancestor:c,callType:"success"};if(c.errorCalls.includes(d))return{ancestor:c,callType:"error"}}}if(l.length>1)throw new Error(`resolveEarliestSingleCallerAncestor: Multiple callers found for entity ${d.id}.`);return{ancestor:l[0],callType:null}}function _Ne(d,u,i){var y,v,T,I;const a={ancestor:null,callType:null};if(!d)throw new Error("[findNextCombinedSingleCallerAncestor] No 'targetA' given");if(!u)throw new Error("[findNextCombinedSingleCallerAncestor] No 'targetB' given");if((d==null?void 0:d.id)===(u==null?void 0:u.id))if(Dr.includes(d.type)){let b=null;return d.type===p.Loop||d.type===p.FunctionDeclaration&&d.parent.type===p.Loop?b="loop-body":d.type===p.FunctionDeclaration&&(b="entry"),{ancestor:d,callType:b}}else{if(Mr.includes(d.type))return hy(d,i);throw new Error(`[findNextCombinedSingleCallerAncestor] Invalid 'targetA' and 'targetB' arguments, neither is a callable or caller entity: ${d.type} -- ${d.id}`)}if(i){const b=wo(i),D=b.find(M=>M.callee===d),V=b.find(M=>M.callee===u);if(!D)throw new Error(`[findNextCombinedSingleCallerAncestor] Invalid 'from' argument, doesn't contain 'targetA' entity ${d.type} -- ${d.id}`);if(!V)throw new Error(`[findNextCombinedSingleCallerAncestor] Invalid 'from' argument, doesn't contain 'targetB' entity ${u.type} -- ${u.id}`)}const l=Il(d,d.project),c=Il(u,u.project);if((l==null?void 0:l.id)!==(c==null?void 0:c.id))return a;let e=i||l;if(!e)return{ancestor:null,callType:null};if(!Dr.includes(e.type))throw new Error(`[findNextCombinedSingleCallerAncestor] Invalid 'from' argument, is not a caller entity: ${e.type} -- ${e.id}`);if(Mr.includes(d.type)&&Mr.includes(u.type)){const b=hy(d,e),D=hy(u,e),V=wo(b.ancestor),M=wo(D.ancestor);((y=D.ancestor)==null?void 0:y.id)===((v=b.ancestor)==null?void 0:v.id)||((T=D.ancestor)==null?void 0:T.id)===d.id?(a.ancestor=D.ancestor,a.callType=D.callType):((I=b.ancestor)==null?void 0:I.id)===u.id?(a.ancestor=b.ancestor,a.callType=b.callType):(V.some(x=>x.callee.id===(u==null?void 0:u.id))||M.some(x=>x.callee.id===(d==null?void 0:d.id)),a.ancestor=l,a.callType="entry")}if(!a.ancestor){let b=null;return(e==null?void 0:e.type)===p.Loop||(e==null?void 0:e.type)===p.FunctionDeclaration&&(e==null?void 0:e.parent.type)===p.Loop?b="loop-body":(e==null?void 0:e.type)===p.FunctionDeclaration&&(b="entry"),{ancestor:e,callType:b}}return a}function hy(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(D=>!!D.calledBy.length)&&(i=d.internalCalls.find(V=>!!V.calledBy.length));let a=u||zr(i,d.project);if(!a)return{ancestor:null,callType:null};if(a.type===p.Project&&(a=AH(i).ancestor,!a))return{ancestor:null,callType:null};const l=wo(a);if(!l.find(D=>D.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(Gt.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(D=>!(D.callee===i||!Dr.includes(D.callee.type)||!ht(D.callee).find(x=>x===i))).filter((D,V,M)=>M.findIndex(x=>x.callee===D.callee)===V);if(e.length===0)return{ancestor:null,callType:null};if(e.length===1){const D=e[0];if(D.callee.type===p.Loop){if(D.callee.body.calls.includes(i))return{ancestor:D.callee,callType:"loop-body"}}else{if(Gt.includes(D.callee.type))return D.callee.type===p.FunctionDeclaration&&D.callee.parent.type===p.Loop?{ancestor:D.callee,callType:"loop-body"}:{ancestor:D.callee,callType:"entry"};if(mi.includes(D.callee.type)){if(D.callType==="success"&&D.callee.type===p.InternalCall)return{ancestor:D.callee,callType:"success"};if(D.callType==="error"&&D.callee.type===p.InternalCall)return{ancestor:D.callee,callType:"error"}}}}const y=e.filter(D=>Yw(i,D.callee)),v=y.filter(D=>{const V=ht(D.callee),M=y.filter(q=>q.callee!==D.callee).map(q=>q.callee);return!V.some(q=>!!M.find(W=>W===q))});if(v.length===0){if(a.type===p.Loop){if(ht(a.body).find(W=>W===i))return{ancestor:a,callType:"loop-body"};if(br(a.successCalls).find(W=>W===i))return{ancestor:a,callType:"success"};if(br(a.errorCalls).find(W=>W===i))return{ancestor:a,callType:"error"}}else if(mi.includes(a.type)){if(br(a.successCalls).find(q=>q===i))return{ancestor:a,callType:"success"};if(br(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(D=>S(D.callee,i.project)).join(", ")}`);const T=v[0].callee,b=wo(T).find(D=>D.callee===i);return{ancestor:T,callType:b.callType}}function DNe(d){if(![...au,p.OutputMap].includes(d.type))throw new Error("getEarliestSingleCallerAncestorOfValueWriterAndItsValueReaders can only be used with a value writer entity");let u;if(au.includes(d.type)?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,...W0(d),...Vt.includes(d.type)?d.outputs.flatMap(y=>W0(y)):[]]),a=C(i.map(y=>Xw(y)).flatMap(y=>Nt.includes(y==null?void 0:y.type)?y.calledBy:[y]));if(a.length===1){const y=a[0];if(Gt.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(Gt.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 I=br(y.successCalls),b=br(y.errorCalls);if(I.includes(u))return{ancestor:y,callType:"success"};if(b.includes(u))return{ancestor:y,callType:"error"}}const v=hy(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(I=>{var b,D;return((b=I.ancestor)==null?void 0:b.id)===((D=y.ancestor)==null?void 0:D.id)})),c=yy(u),e=l.filter(y=>y!=null&&y.ancestor?c===y.ancestor?!0:!l.filter(I=>I.ancestor!==y.ancestor).map(I=>I.ancestor).some(I=>{const b=Ao(y.ancestor,I);return!!(b!=null&&b.last)}):!1);if(e.length===0)return{ancestor:c,callType:(c==null?void 0:c.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 wH(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:IH(l).length>1&&l.includes(u)?!1:l.every(e=>d===u?!0:Gt.includes(e.type)?!1:wH(e,u))}function RH(d){const u=[];let i=d.calledBySuccess;i=i.filter(l=>!i.filter(y=>y!==l).some(y=>z0(y,l)));let a=d.calledByError;a=a.filter(l=>!a.filter(y=>y!==l).some(y=>z0(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 CH(d){const u=[];return RH(d).forEach(a=>{a.ancestor.type===p.Condition&&u.push({condition:a.ancestor,call:d,callType:a.callType});const c=CH(a.ancestor).filter(e=>!u.some(y=>y.condition.id===e.condition.id));u.push(...c)}),u}function Xw(d){if(!d)return null;if(d.type===p.Condition&&d.parent.type===p.Condition)return vy(d.parent);if(rE.includes(d.type))return d;const u=d.parent;return u?Xw(u):null}function W0(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]:er.includes(a.type)?[...i,a,...W0(a,u)]:i),[])}function my(d){const u=d.calledBy;if(u.length===0)return d.project;const i=u.reduce((a,l)=>{const c=zr(l,d.project);return!c||c.type===p.Project?a:a.type===p.Project||op(c,a).last?c:(op(a,c).last,a)},d.project);return i.type===p.FunctionDeclaration&&i.parent.type===p.Loop?i.parent:i}function et(d,u){let i=my(d);if(d.type===p.InternalCall)if(d.parent.type===p.VariableInstance){const l=Ds(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&&!Qi.includes(i.type)){d.remove({ignoreUpstream:!1},u);return}else if(Vt.includes(d.type)){const l=d.usedInternalCalls[0];if(l)if(i=my(l),d.type===p.VariableInstance){const c=Ds(i,d.declaration,d.project);!c.compatible&&c.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 c=Ds(i,d.declaration,d.project);!c.compatible&&c.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(Nt.includes(d.type))return;ht(d).forEach(l=>{let c=my(l);if(l.type===p.InternalCall)if(l.parent.type===p.VariableInstance){const e=Ds(c,l.parent.declaration,d.project);!e.compatible&&e.type!=="b-is-global-a-is-not"?l.parent.remove({ignoreUpstream:!1},u):(l.parent.setParent(c,u),l.parent.addSelfToProject(u))}else l.parent.setParent(c,u),l.parent.addSelfToProject(u);else if((l.type===p.ContinueStatement||l.type===p.BreakStatement)&&c.type!==p.Loop){l.remove({ignoreUpstream:!1},u);return}else if(l.type===p.ReturnStatement&&!Qi.includes(c.type)){l.remove({ignoreUpstream:!1},u);return}else if(Vt.includes(l.type)){const e=l.usedInternalCalls[0];if(e)if(c=my(e),l.type===p.VariableInstance){const y=Ds(c,l.declaration,d.project);!y.compatible&&y.type!=="b-is-global-a-is-not"?l.remove({ignoreUpstream:!1},u):(l.setParent(c,u),l.addSelfToProject(u))}else l.setParent(c,u),l.addSelfToProject(u);else if(l.type===p.VariableInstance){const y=Ds(c,l.declaration,d.project);!y.compatible&&y.type!=="b-is-global-a-is-not"?l.remove({ignoreUpstream:!1},u):(l.setParent(c,u),l.addSelfToProject(u))}else l.setParent(c,u),l.addSelfToProject(u)}else l.setParent(c,u),l.addSelfToProject(u)})}function H0(d,u,i=new Set){const a=ta(d),l=ta(u),c=a.filter(v=>!l.includes(v)),e=a.filter(v=>l.includes(v)),y=c.reduce((v,T)=>i.has(T.id)?v:(i.add(T.id),C([...v,...H0(T,u,i)])),[]);return C([...e,...y])}function Pd(d,u){const i=op(d,u);return i.last===u&&i.list.length>0&&i.list[0]!==u}function Qw(d,u){return!!op(d,u).last}function z0(d,u){return!!Ao(d,u).last}function eR(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 eR(i,a)}function ONe(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(Mr.includes(d.type)&&Dr.includes(u.type)){const y=Ao(d,u),v=y.last;if(v){if(v===u)return{ancestor:u,callType:y.callType}}else return{ancestor:null,callType:null}}if(Mr.includes(u.type)&&Dr.includes(d.type)){const y=Ao(u,d),v=y.last;if(v){if(v===d)return{ancestor:d,callType:y.callType}}else return{ancestor:null,callType:null}}const a=yy(d),l=yy(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 c=a.calls.reduce((y,v)=>{if(!Dr.includes(v.type))return y;const T=wo(v),I=T.find(D=>D.callee===d),b=T.find(D=>D.callee===u);return I&&b&&(!i||I.callType===b.callType)?[...y,{ancestor:v,callType:I.callType}]:y},[]);if(c.length===0)return{ancestor:null,callType:null};if(c.length===1)return{ancestor:c[0].ancestor,callType:c[0].callType};const e=c.filter(y=>!c.some(v=>v.ancestor!==y.ancestor&&Ao(y.ancestor,v.ancestor).last===v.ancestor));return e.length===1?{ancestor:e[0].ancestor,callType:e[0].callType}:{ancestor:a,callType:"entry"}}function Pi(d){if(dc.includes(d.type)){if(d.type===p.FunctionDeclaration){const u=d.parent;if(u.type===p.DefinitionEntity)return Pi(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?Pi(d.parent):d}else{const u=d.parent;return u?Pi(u):null}}function dp(d,u){const i=up(d,u);if(!i)return null;if(dc.includes(i.type)){if(i.type===p.FunctionDeclaration){const a=up(i.parent,u);if(a){if(a.type===p.DefinitionEntity)return a;if(a.type===p.Loop)return a}}if(i.parent){const a=up(i.parent,u);if(a&&(i.type===p.DefinitionEntity&&a.type===p.DataType||i.type===p.Condition&&a.type===p.Condition))return dp(a,u)}return i}else{const a=i.parent?up(i.parent,u):null;return a?dp(a,u):null}}function wo(d){if(d.type===p.Loop){const u=[...br(d.successCalls).map(l=>({callee:l,callType:"success"})),...br(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 c=(e=u.find(y=>y.callee===l))==null?void 0:e.callType;return{callee:l,callType:c}})}if(mi.includes(d.type)){const u=[...br(d.successCalls).map(l=>({callee:l,callType:"success"})),...br(d.errorCalls).map(l=>({callee:l,callType:"error"}))];return C(u.map(l=>l.callee)).map(l=>{var e;const c=(e=u.find(y=>y.callee===l))==null?void 0:e.callType;return{callee:l,callType:c}})}if(Gt.includes(d.type)){const u=[...br(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 c=(e=u.find(y=>y.callee===l))==null?void 0:e.callType;return{callee:l,callType:c}})}return[]}function vy(d){if(!d)return null;if(d.type===p.Condition&&d.parent.type===p.Condition)return vy(d.parent);if(Mr.includes(d.type))return d;const u=d.parent;return u?vy(u):null}function gH(d){if(!d)return null;if(mi.includes(d.type))return d;const u=d.parent;return u?gH(u):null}function _H(d){if(!d)return null;if(Dr.includes(d.type))return d;const u=d.parent;return u?_H(u):null}function PNe(d){return d.type===p.VariableDeclaration?[d]:mi.includes(d.type)?[...d.inputs,...d.outputs||[]]:Nt.includes(d.type)?d.outputs:Zo.includes(d.type)||d.type===p.FunctionDeclaration?d.inputs:[]}function $Ne(d){const u=ta(d),i=[],a=[];Mg.includes(d.type)&&i.push(...J0(d));const l=u.filter(c=>{const e=i.includes(c);return e?!1:Mr.includes(c.type)&&!e?(a.push(c),!1):!0});return i.sort((c,e)=>Pd(e,c)?-1:0),a.sort((c,e)=>Pd(e,c)?-1:0),[...i,...a,...l]}function DH(d){return[...d].sort((u,i)=>Pd(i,u)?-1:0)}function NNe(d){const u=DH(d),i=[];return u.forEach(a=>{const l=i[i.length-1];if(l){const c=l[l.length-1];Pd(a,c)?i.push([a]):l.push(a)}else i.push([a])}),i}function El(d){const u=d.map(i=>Pi(i));return C(u)}function J0(d){return mi.includes(d.type)?[...El(d.successCalls),...El(d.errorCalls)]:Gt.includes(d.type)?El(d.calls):[]}function VNe(d,u){return J0(d).includes(u)}function Y0(d){return d.writesValues||[]}function LNe(d,u){return Y0(d).includes(u)}function OH(d){var u;return Vt.includes((u=d==null?void 0:d.readsValue)==null?void 0:u.type)?d.readsValue:null}function BNe(d){return d.writesValues}function PH(d=[]){return d.map(OH).filter(u=>!!u)}function S0(d=[]){return d.map(u=>u.writesValues).flat().filter(u=>Vt.includes(u.type))}function $H(d=[]){return d.map(u=>u.readsValue).filter(u=>!!u&&Vt.includes(u.type))}function NH(d){return Vt.includes(d.type)?d:null}function VH(d){return d.writesValues.map(NH).filter(u=>!!u)}function LH(d=[]){return d.reduce((u,i)=>i.type===p.OutputMap?[...u,...VH(i)]:u,[])}function ht(d){return d.type===p.Loop?C([...br(d.successCalls),...br(d.errorCalls),...d.body?ht(d.body):[]]):mi.includes(d.type)?C([...br(d.successCalls),...br(d.errorCalls)]):Gt.includes(d.type)?C(br(d.calls)):[]}function MNe(d){return mi.includes(d.type)?[...br(d.successCalls),...br(d.errorCalls)]:Gt.includes(d.type)?br(d.calls):[]}function BH(d,u=new Set){return d.writesValues.filter(a=>Vt.includes(a.type)&&!u.has(a.id)).reduce((a,l)=>u.has(l.id)?a:[...a,...Li(l,u)],[])}function MH(d,u=new Set){var a;return(((a=d.readsValue)==null?void 0:a.writesValues)||[]).filter(l=>Vt.includes(l.type)&&!u.has(l.id)).reduce((l,c)=>u.has(c.id)?l:[...l,...Li(c,u)],[])}function Li(d,u=new Set){if(u.has(d.id))return[];if(d.type===p.ReturnStatement)return $H(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((c,e)=>{const y=Pi(e);return[...c,...Li(y||e,u)]},[]),...PH(d.inputs),...LH(d.outputs)].reduce((c,e)=>[...c,...Li(e,u)],[]);if(Zo.includes(d.type)){const i=S0(d.inputs),l=ht(d).reduce((c,e)=>{const y=Pi(e);return[...c,...Li(y||e,u)]},[]);return i.push(...l),i.reduce((c,e)=>[...c,...Li(e,u)],[])}if(d.type===p.FunctionDeclaration){const i=[...S0(d.inputs)],l=ht(d).reduce((c,e)=>{const y=Pi(e);return[...c,...Li(y||e,u)]},[]);return i.push(...l),i.reduce((c,e)=>[...c,...Li(e)],[])}if(Vt.includes(d.type)){u.add(d.id);const a=ht(d).reduce((l,c)=>{const e=Pi(c);return[...l,...Li(e||c,u)]},[]);return[d,...a,...MH(d,u),...BH(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,c)=>(J.log("[Recursive -- flattenDerivedCanvasEntities]",c.type,S(c,c.project),c.id),[...l,c,...Fn(c,u)]),[])]}function br(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 xH(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],[]),c=l.reduce((v,T)=>[...v,...S0(T.inputs),...br(El(T.calls)),...T.returnStatements],[]),e=d.functions.reduce((v,T)=>[...v,...br(El(T.calls)),...T.returnStatements],[]),y=d.events.reduce((v,T)=>[...v,...br(El(T.calls)),...T.returnStatements],[]);return[...i,...a,...l,...c,...e,...y]}function UH(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)?cz(d).find(c=>{var e;return((e=c.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 xNe(d){const u=xH(d.project);return UH(d,u)}function up(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 jH(d={},u){const i={};return Object.keys(d).forEach(a=>{const l=u.get(a)||a,c=d[a];i[l]=c}),i}function pp(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,c=d,e=d,y=d,v=d,T=d,I=d,b=d,D=d,V=d,M=d,x=d,q=d,Z=[...q.readsValue?[q.readsValue]:[],...q.declaration?[q.declaration]:[],...(x.calledByEntry||[]).flatMap(z=>z),...(x.calledBySuccess||[]).flatMap(z=>z),...(x.calledByError||[]).flatMap(z=>z),...V.parent?[V.parent]:[]];Array.isArray(e.implements)?Z.push(...e.implements.flatMap(z=>z)):y.implements&&Z.push(y.implements),Array.isArray(e.extends)?Z.push(...e.extends.flatMap(z=>z)):D.extends&&Z.push(D.extends),v.valueAsTypeList&&Array.isArray(v.valueAsTypeList)&&Z.push(...v.valueAsTypeList.flatMap(z=>z)),v.valueAsTypeSingle&&Z.push(v.valueAsTypeSingle),(q.internalCalls||[]).forEach(z=>{const oe=te(z);if(oe&&u[oe]){const le=u[oe];[...le.calledByEntry||[],...le.calledBySuccess||[],...le.calledByError||[]].forEach(ye=>{const he=te(ye);he&&u[he]&&Z.push(u[he])})}});const W=[...(l.inputs||[]).flatMap(z=>z),...(M.inputsDeclarations||[]).flatMap(z=>z),...(M.outputs||[]).flatMap(z=>z),...(q.internalCalls||[]).flatMap(z=>z),...q.writesValues||[],...x.dataType?[x.dataType]:[],...T.body?[T.body]:[],...x.defaultValue?[x.defaultValue]:[],...(x.successCalls||[]).flatMap(z=>z),...(x.errorCalls||[]).flatMap(z=>z),...(e.properties||[]).flatMap(z=>z),...(e.methods||[]).flatMap(z=>z),...(e.abstractMethods||[]).flatMap(z=>z),...I.error?[I.error]:[],...V.throws?[V.throws]:[],...(c.andChildrenGroup||[]).flatMap(z=>z),...(c.orChildrenGroup||[]).flatMap(z=>z),...(b.entities||[]).flatMap(z=>z),...(b.functions||[]).flatMap(z=>z),...(b.functionCalls||[]).flatMap(z=>z),...(b.events||[]).flatMap(z=>z),...(b.conditions||[]).flatMap(z=>z),...(b.operations||[]).flatMap(z=>z),...(b.loops||[]).flatMap(z=>z),...(b.variableDeclarations||[]).flatMap(z=>z),...(b.variableInstances||[]).flatMap(z=>z),...(b.searches||[]).flatMap(z=>z),...(b.projects||[]).flatMap(z=>z),...(y.calls||[]).flatMap(z=>z)];d.type===p.DataType&&(c.entity&&u[te(c.entity)]&&u[te(c.entity)].parent&&te(u[te(c.entity)].parent)===d.id?W.push(c.entity):c.entity&&Z.push(c.entity)),(q.internalCalls||[]).forEach(z=>{const oe=te(z);if(oe&&u[oe]){const le=u[oe];[...le.successCalls||[],...le.errorCalls||[]].forEach(ye=>{const he=te(ye);he&&u[he]&&W.push(u[he])})}});const Y={},re={};return Z.forEach(z=>{var ye;const oe=te(z);if(oe&&a.ignoreBuiltInBaseEntities&&(vn.includes(z.type)||(a.allBuiltInEntityIds||[]).includes(oe)))return;const le=z.version;if(oe){const he=((ye=a.entityMaps)==null?void 0:ye.get(oe))||oe;Y[he]=le}}),W.forEach(z=>{var ye;const oe=te(z);if(oe&&a.ignoreBuiltInBaseEntities&&(vn.includes(z.type)||(a.allBuiltInEntityIds||[]).includes(oe)))return;const le=z.version;if(oe){const he=((ye=a.entityMaps)==null?void 0:ye.get(oe))||oe;re[he]=le}}),{upstream:Y,downstream:re}}function UNe(d,u){const i=[];if(Mr.includes(d.type)){os(d).forEach(c=>{const e=dp(c,u);e&&i.push(e)});const l=[...d.inputs||[],...d.outputs||[]].map(c=>{const e=up(c,u);return e?fz(e,u):null}).filter(c=>c!==null);i.push(...C(l))}if(Vt.includes(d.type)){const a=X0(d);a&&i.push(a)}return C(i)}function Ro(d){const u=[];if(Mr.includes(d.type)){d.calledBy.forEach(l=>{const c=Pi(l);c&&u.push(c)});const a=[...d.inputs||[],...d.outputs||[]].map(l=>X0(l)).filter(l=>l!==null);u.push(...C(a))}if(Xn.includes(d.type)){const i=X0(d);i&&u.push(i)}return C(u)}function os(d){return[...d.calledByEntry||[],...d.calledByError||[],...d.calledBySuccess||[]].filter(u=>u.type!==p.GenericReference)}function GH(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=>Ee(a,u,i)),...d.dataType?Ee(d.dataType,u,i):[],...d.error?Ee(d.error,u,i):[],...d.parent?Ee(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.ArgumentDeclaration)throw new Error("Entity must be an argument declaration to be flattened");return[d,...d.defaultValue?Ee(d.defaultValue,u):[],...d.writesValues.flatMap(a=>Ee(a,u,i)),...d.dataType?Ee(d.dataType,u,i):[],...d.parent?Ee(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.BreakStatement)throw new Error("Entity must be a break statement to be flattened");return[d,...d.outputs.flatMap(a=>Ee(a,u,i)),...d.throws?Ee(d.throws,u,i):[],...d.dataType?Ee(d.dataType,u,i):[],...d.readsValue?Ee(d.readsValue,u,i):[],...(os(d)||[]).flatMap(a=>Ee(a,u,i)),...d.parent?Ee(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.BuiltInBaseEntity)throw new Error("Entity must be a built-in base entity to be flattened");return[d,...(d.properties||[]).flatMap(a=>Ee(a,u,i)),...(d.methods||[]).flatMap(a=>Ee(a,u,i)),...(d.abstractMethods||[]).flatMap(a=>Ee(a,u,i)),...d.allPropertiesImplement?Ee(d.allPropertiesImplement,u,i):[],...d.additionalPropertiesDataType?Ee(d.additionalPropertiesDataType,u,i):[],...d.extends?Ee(d.extends,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.Condition)throw new Error("Entity must be a condition to be flattened");return[d,...(d.andChildrenGroup||[]).flatMap(a=>Ee(a,u,i)),...(d.orChildrenGroup||[]).flatMap(a=>Ee(a,u,i)),...(d.inputs||[]).flatMap(a=>Ee(a,u,i)),...(d.successCalls||[]).flatMap(a=>Ee(a,u,i)),...(d.errorCalls||[]).flatMap(a=>Ee(a,u,i)),...(os(d)||[]).flatMap(a=>Ee(a,u,i)),...d.parent?Ee(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.ContinueStatement)throw new Error("Entity must be a continue statement to be flattened");return[d,...d.outputs.flatMap(a=>Ee(a,u,i)),...d.readsValue?Ee(d.readsValue,u,i):[],...d.throws?Ee(d.throws,u,i):[],...d.dataType?Ee(d.dataType,u,i):[],...(os(d)||[]).flatMap(a=>Ee(a,u,i)),...d.parent?Ee(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.DefinitionEntity)throw new Error("Entity must be a definition entity to be flattened");return[d,...d.extends?Ee(d.extends,u,i):[],...(d.implements||[]).flatMap(a=>Ee(a,u,i)),...(d.properties||[]).flatMap(a=>Ee(a,u,i)),...(d.methods||[]).flatMap(a=>Ee(a,u,i)),...(d.abstractMethods||[]).flatMap(a=>Ee(a,u,i)),...d.allPropertiesImplement?Ee(d.allPropertiesImplement,u,i):[],...d.additionalPropertiesDataType?Ee(d.additionalPropertiesDataType,u,i):[],...d.parent?Ee(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.DataType)throw new Error("Entity must be a data type to be flattened");return[d,...(d.andChildrenGroup||[]).flatMap(a=>Ee(a,u,i)),...(d.orChildrenGroup||[]).flatMap(a=>Ee(a,u,i)),...d.entity?Ee(d.entity,u,i):[],...d.parent?Ee(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.FunctionCall)throw new Error("Entity must be a function call to be flattened");return[d,...(d.inputs||[]).flatMap(a=>Ee(a,u,i)),...(d.outputs||[]).flatMap(a=>Ee(a,u,i)),...d.error?Ee(d.error,u,i):[],...(os(d)||[]).flatMap(a=>Ee(a,u,i)),...(d.successCalls||[]).flatMap(a=>Ee(a,u,i)),...(d.errorCalls||[]).flatMap(a=>Ee(a,u,i)),...(d.writesValues||[]).flatMap(a=>Ee(a,u,i)),...d.parent?Ee(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.FunctionDeclaration)throw new Error("Entity must be a function declaration to be flattened");return[d,...(d.inputs||[]).flatMap(a=>Ee(a,u,i)),...(d.calls||[]).flatMap(a=>Ee(a,u,i)),...d.dataType?Ee(d.dataType,u,i):[],...d.implements?Ee(d.implements,u,i):[],...d.parent?Ee(d.parent,u,i):[]]}function YH(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=>Ee(a,u,i)),...(d.calls||[]).flatMap(a=>Ee(a,u,i)),...d.implements?Ee(d.implements,u,i):[],...d.parent?Ee(d.parent,u,i):[]]}function SH(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?Ee(d.readsValue,u,i):[],...d.declaration?Ee(d.declaration,u,i):[],...d.defaultValue?Ee(d.defaultValue,u,i):[],...d.parent?Ee(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.InstalledProject)throw new Error("Entity must be an installed project to be flattened");return[d,...(d.functions||[]).flatMap(a=>Ee(a,u,i)),...(d.events||[]).flatMap(a=>Ee(a,u,i)),...d.parent?Ee(d.parent,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.InternalCall)throw new Error("Entity must be an internal call to be flattened");return[d,...(d.successCalls||[]).flatMap(a=>Ee(a,u,i)),...(d.errorCalls||[]).flatMap(a=>Ee(a,u,i)),...(d.inputs||[]).flatMap(a=>Ee(a,u,i)),...(d.outputs||[]).flatMap(a=>Ee(a,u,i)),...(os(d)||[]).flatMap(a=>Ee(a,u,i)),...d.error?Ee(d.error,u,i):[],...(d.writesValues||[]).flatMap(a=>Ee(a,u,i)),...d.parent?Ee(d.parent,u,i):[]]}function ez(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?Ee(d.valueAsTypeSingle,u,i):[],...d.valueAsTypeList&&Array.isArray(d.valueAsTypeList)?d.valueAsTypeList.flatMap(a=>Ee(a,u,i)):[],...d.parent?Ee(d.parent,u,i):[]]}function tz(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=>Ee(a,u,i)),...(d.outputs||[]).flatMap(a=>Ee(a,u,i)),...(d.successCalls||[]).flatMap(a=>Ee(a,u,i)),...(d.errorCalls||[]).flatMap(a=>Ee(a,u,i)),...d.error?Ee(d.error,u,i):[],...d.dataType?Ee(d.dataType,u,i):[],...d.body?Ee(d.body,u,i):[],...(os(d)||[]).flatMap(a=>Ee(a,u,i)),...(d.writesValues||[]).flatMap(a=>Ee(a,u,i)),...d.parent?Ee(d.parent,u,i):[]]}function iz(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=>Ee(a,u,i)),...(d.errorCalls||[]).flatMap(a=>Ee(a,u,i)),...(d.inputs||[]).flatMap(a=>Ee(a,u,i)),...(d.outputs||[]).flatMap(a=>Ee(a,u,i)),...(d.writesValues||[]).flatMap(a=>Ee(a,u,i)),...d.error?Ee(d.error,u,i):[],...(os(d)||[]).flatMap(a=>Ee(a,u,i)),...d.parent?Ee(d.parent,u,i):[]]}function rz(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=>Ee(a,u,i)),...d.declaration?Ee(d.declaration,u,i):[],...d.parent?Ee(d.parent,u,i):[]]}function nz(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=>Ee(a,u,i)),...(d.methods||[]).flatMap(a=>Ee(a,u,i)),...(d.abstractMethods||[]).flatMap(a=>Ee(a,u,i))]}function sz(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=>Ee(a,u,i)),...(d.functions||[]).flatMap(a=>Ee(a,u,i)),...(d.events||[]).flatMap(a=>Ee(a,u,i)),...(d.projects||[]).flatMap(a=>Ee(a,u,i)),...(d.variableDeclarations||[]).flatMap(a=>Ee(a,u,i)),...(d.variableInstances||[]).flatMap(a=>Ee(a,u,i)),...(d.operations||[]).flatMap(a=>Ee(a,u,i)),...(d.conditions||[]).flatMap(a=>Ee(a,u,i)),...(d.functionCalls||[]).flatMap(a=>Ee(a,u,i)),...(d.projects||[]).flatMap(a=>Ee(a,u,i)),...(d.loops||[]).flatMap(a=>Ee(a,u,i)),...(d.searches||[]).flatMap(a=>Ee(a,u,i))]}function az(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?Ee(d.defaultValue,u,i):[],...d.dataType?Ee(d.dataType,u,i):[],...d.parent?Ee(d.parent,u,i):[]]}function lz(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=>Ee(a,u,i)),...d.throws?Ee(d.throws,u,i):[],...d.readsValue?Ee(d.readsValue,u,i):[],...d.dataType?Ee(d.dataType,u,i):[],...(os(d)||[]).flatMap(a=>Ee(a,u,i)),...d.parent?Ee(d.parent,u,i):[]]}function oz(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=>Ee(a,u,i)),...(d.errorCalls||[]).flatMap(a=>Ee(a,u,i)),...(d.inputsDeclarations||[]).flatMap(a=>Ee(a,u,i)),...(d.inputs||[]).flatMap(a=>Ee(a,u,i)),...(d.writesValues||[]).flatMap(a=>Ee(a,u,i)),...(d.outputs||[]).flatMap(a=>Ee(a,u,i)),...d.error?Ee(d.error,u,i):[],...d.dataType?Ee(d.dataType,u,i):[],...(os(d)||[]).flatMap(a=>Ee(a,u,i)),...d.parent?Ee(d.parent,u,i):[]]}function dz(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?Ee(d.defaultValue,u,i):[],...d.dataType?Ee(d.dataType,u,i):[],...d.parent?Ee(d.parent,u,i):[]]}function uz(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=>Ee(a,u,i)),...(d.errorCalls||[]).flatMap(a=>Ee(a,u,i)),...(d.inputs||[]).flatMap(a=>Ee(a,u,i)),...(d.outputs||[]).flatMap(a=>Ee(a,u,i)),...(d.internalCalls||[]).flatMap(a=>Ee(a,u,i)),...(d.writesValues||[]).flatMap(a=>Ee(a,u,i)),...d.readsValue?Ee(d.readsValue,u,i):[],...d.defaultValue?Ee(d.defaultValue,u,i):[],...(os(d)||[]).flatMap(a=>Ee(a,u,i)),...d.dataType?Ee(d.dataType,u,i):[],...d.parent?Ee(d.parent,u,i):[]]}function pz(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=>Ee(a,u,i)),...(d.errorCalls||[]).flatMap(a=>Ee(a,u,i)),...(d.inputs||[]).flatMap(a=>Ee(a,u,i)),...(d.outputs||[]).flatMap(a=>Ee(a,u,i)),...(d.internalCalls||[]).flatMap(a=>Ee(a,u,i)),...(d.writesValues||[]).flatMap(a=>Ee(a,u,i)),...d.readsValue?Ee(d.readsValue,u,i):[],...d.defaultValue?Ee(d.defaultValue,u,i):[],...(os(d)||[]).flatMap(a=>Ee(a,u,i)),...d.declaration?Ee(d.declaration,u,i):[],...d.parent?Ee(d.parent,u,i):[]]}function Kn(){const d=new Set;return yk.flatMap(i=>Ee(i,d)).map(i=>i.id)}function Ee(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 zH(d,u,i);case p.Operation:return iz(d,u,i);case p.Condition:return qH(d,u,i);case p.Loop:return tz(d,u,i);case p.Search:return oz(d,u,i);case p.GlobalEvent:return YH(d,u,i);case p.ReturnStatement:return lz(d,u,i);case p.ContinueStatement:return ZH(d,u,i);case p.BreakStatement:return FH(d,u,i);case p.VariableDeclaration:return uz(d,u,i);case p.DefinitionEntity:return WH(d,u,i);case p.FunctionDeclaration:return JH(d,u,i);case p.Project:return sz(d,u,i);case p.ActionDescriptor:return GH(d,u,i);case p.ArgumentDeclaration:return kH(d,u,i);case p.ValueDescriptor:return dz(d,u,i);case p.InputMap:return SH(d,u,i);case p.OutputMap:return rz(d,u,i);case p.DataType:return HH(d,u,i);case p.InstalledProject:return XH(d,u,i);case p.InternalCall:return QH(d,u,i);case p.LiteralValue:return ez(d,u,i);case p.Property:return az(d,u,i);case p.VariableInstance:return pz(d,u,i);case p.BuiltInBaseEntity:return i.ignoreBuiltInBaseEntities?[]:KH(d,u,i);case p.PrimitiveEntity:return i.ignoreBuiltInBaseEntities?[]:nz(d,u,i)}return[]}function tR(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||Zo.includes(d.type)?d.inputs:d.type===p.Search?d.inputsDeclarations:[]}function jNe(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 cz(d){return mi.includes(d.type)?d.inputs:[]}function GNe(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 Nt.includes(d.type)?d.outputs.map(i=>i.declaration).filter(i=>!!i)||[]:[]}function kNe(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 FNe(d){return d.type===p.Condition?[]:mi.includes(d.type)?d.outputs:[]}function X0(d){const u=d.readsValue;return u?Pi(u):null}function fz(d,u){const i=d.readsValue;return i?dp(i,u):null}function yz(d){const u=d.internalCalls||[];return C(El(C(u.flatMap(i=>[...i.successCalls,...i.errorCalls]))))}function hz(d){const u=d.internalCalls||[];return C(C(u.flatMap(i=>[...i.successCalls,...i.errorCalls])))}function cp(d){const u=Y0(d),i=[];return u.forEach(a=>{if(dc.includes(a.type))i.push(a);else if(Xn.includes(a.type)){const l=Pi(a.parent);i.push(l)}}),i}function fp(d){const u=Y0(d),i=[];return u.forEach(a=>{if([...Vt,...Nt].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 mz(d){return d.type===p.Project?null:rE.includes(d.type)?d:vn.includes(d.type)?null:d.parent?mz(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)||[]),Qi.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(c=>Pi(c)),l=d.errorCalls.map(c=>Pi(c));i.push(...a,...l)}if(Zo.includes(d.type)){if(d.collapsed&&u)return[];const a=d.inputs.map(c=>cp(c)).flat(),l=d.calls.map(c=>Pi(c));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=>cp(e)).flat(),l=d.successCalls.map(e=>Pi(e)),c=d.errorCalls.map(e=>Pi(e));i.push(...C(a),...l,...c)}if(Vt.includes(d.type)){const a=cp(d),l=yz(d);i.push(...a,...l)}if(er.includes(d.type)){const a=cp(d);i.push(...a)}if(d.type===p.Loop){if(d.body){const c=ta(d.body,u);i.push(...c)}const a=d.errorCalls.map(c=>Pi(c)),l=d.successCalls.map(c=>Pi(c));i.push(...l,...a)}if(d.type===p.FunctionDeclaration){if(d.collapsed&&u)return[];const a=d.inputs.map(c=>cp(c)).flat(),l=d.calls.map(c=>Pi(c));i.push(...C(a),...l)}return C(i)}function Q0(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)||[]),Qi.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?[]:Q0(l));i.push(...a)}if(d.type===p.Condition){const a=d.successCalls,l=d.errorCalls;i.push(...a,...l)}if(Zo.includes(d.type)){if(d.collapsed&&u)return[];const a=d.inputs.map(c=>fp(c)).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=>fp(e)).flat(),l=d.successCalls,c=d.errorCalls;i.push(...C(a),...l,...c)}if(Vt.includes(d.type)){const a=fp(d),l=hz(d);i.push(...a,...l)}if(d.type===p.Loop){const a=d.outputs.map(e=>fp(e)).flat();if(d.body){const e=Q0(d.body,u);i.push(...e)}const l=d.errorCalls,c=d.successCalls;i.push(...C(a),...c,...l)}if(d.type===p.FunctionDeclaration){if(d.collapsed&&u)return[];const a=d.inputs.map(c=>fp(c)).flat(),l=d.calls;i.push(...C(a),...l)}return C(i)}function ev(d,u=!1){const i=ta(d,u),a=[...i,...i.reduce((l,c)=>[...l,...ev(c,u)],[])];return C(a)}function vz(d,u=!1){const i=Q0(d,u),a=[...i,...i.reduce((l,c)=>[...l,...vz(c,u)],[])];return C(a)}function Ty(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,...Ty(i),...Co(i)]:(i==null?void 0:i.type)===p.BuiltInBaseEntity?[i==null?void 0:i.name,...Co(i)]:[...u],[])}function Co(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,...Co(d.extends),...Ty(d.extends)];if(d.extends.type===p.BuiltInBaseEntity)return[d.extends.name,...Co(d.extends)]}return[]}function Ey(d){var u,i;return d.extends?((u=d.extends)==null?void 0:u.type)===p.DefinitionEntity?[d.extends,...Ey(d.extends),...iR(d.extends)]:((i=d.extends)==null?void 0:i.type)===p.BuiltInBaseEntity?[d.extends,...Ey(d.extends)]:[]:[]}function iR(d){return d.implements.reduce((u,i)=>i.type===p.DefinitionEntity?[...u,i,...iR(i),...Ey(i)]:(i==null?void 0:i.type)===p.BuiltInBaseEntity?[i,...Ey(i)]:[...u,i],[])}function yp(d){return[...Co(d),...Ty(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||[...Co(d)].includes(u)):!!yp(d).includes(u)}function Tz(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 bl(d.extends,u)}return null}if(d.extends)return cr(d.extends,u)?d.extends:bl(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=bl(i,u);if(a)return a}else if(i.type===p.DefinitionEntity){const a=bl(i,u);if(a)return a}}return null}function bl(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 bl(d.extends,u)}return null}if(d.extends)return d.extends.name===u?d.extends:bl(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=bl(i,u);if(a)return a}else if(i.type===p.DefinitionEntity){const a=bl(i,u);if(a)return a}}return null}function Ez(d){const u=Ro(d),i=[...u,...u.reduce((a,l)=>[...a,...Ez(l)],[])];return C(i)}function rR(d){return d.implements.length===0&&!d.extends?null:d.implements.find(a=>a.type===p.BuiltInBaseEntity&&a.name===fe.PERSISTED_ENTITY)?d:[...d.implements,...d.extends?[d.extends]:[]].reduce((a,l)=>{if(l.type===p.DefinitionEntity){const c=rR(l);if(c)return c}return a},null)}function KNe(d){return d.extends&&d.extends.type===p.BuiltInBaseEntity?d.extends:null}function qNe(d){const u=d.implements.find(i=>i.type===p.BuiltInBaseEntity);return u&&u.type===p.BuiltInBaseEntity?u:null}function tv(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 hp(d){return d.type===p.PrimitiveEntity?!0:d.type===p.BuiltInBaseEntity?d.interactive:!sn(d).find(a=>!a.interactive)}function ZNe(d){return d.parent===d.project&&d.project.variableDeclarations.includes(d)}function nR(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 bz(d){if([...Gt,p.DefinitionEntity,p.InstalledProject,p.Project].includes(d.type)||nR(d))return!1;const u=Ro(d);return u.length===0?!0:u.some(i=>bz(i))}function sR(d){return[...Gt,p.DefinitionEntity,p.InstalledProject,p.Project].includes(d.type)||nR(d)?!1:Ro(d).length===0}function Iz(d,u=0){if(sR(d)){const i=Ro(d);return i.length===0?d:i.map(l=>Iz(l,u+1)).reduce((l,c)=>l?c&&c.x<l.x?c:l:c,null)}return null}function Az(d){const u=[];if(sR(d))u.push(d);else return[];return Ro(d).forEach(a=>{u.push(...Az(a))}),u}function aR(d){return d.type===p.FunctionDeclaration&&d.parent!==d.project&&!![p.DefinitionEntity,p.Loop,p.InstalledProject].includes(d.parent.type)}function WNe(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 mp(d){switch(d){case p.DefinitionEntity:return us;case p.FunctionDeclaration:return Ia;case p.VariableDeclaration:return uo;case p.VariableInstance:return oo;case p.FunctionCall:return Io;case p.Operation:return to;case p.Condition:return no;case p.ReturnStatement:return cl;case p.Loop:return ro;case p.Search:return po;case p.InputMap:return ls;case p.OutputMap:return ea;case p.ArgumentDeclaration:return ns;case p.Property:return ds;case p.InstalledProject:return co;case p.Project:return L;case p.DataType:return Wr;case p.GlobalEvent:return io;case p.InternalCall:return fo;case p.ValueDescriptor:return hl;case p.BuiltInBaseEntity:return Oa;case p.PrimitiveEntity:return Rn;case p.ActionDescriptor:return Ut;case p.LiteralValue:return $r;case p.ContinueStatement:return ho;case p.BreakStatement:return yo;default:return null}}function zr(d,u,i=null){const a=d!=null&&d.parent?te(d==null?void 0:d.parent):null;let l=a?u.get(a):null,c=i||d;if((d==null?void 0:d.id)===(u==null?void 0:u.id))return u;if(d.type===p.ReturnStatement)return Rr(d,u,c);if(d.type===p.FunctionDeclaration&&(l==null?void 0:l.type)===p.Loop)return l;if(Gt.includes(d.type))return d;if(d.type===p.Loop)return c.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=te(e);if(!y)return null;const v=u.get(y);return v?zr(v,u,c):null}else return e===u?u:zr(e,u,c)}function Rr(d,u,i=null){const a=d!=null&&d.parent?te(d==null?void 0:d.parent):null;let l=a?u.get(a):null,c=i||d;if(d.type===p.FunctionDeclaration&&(l==null?void 0:l.type)===p.Loop)return Rr(l.parent,u,c);if(Gt.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=te(e);if(!y)return null;const v=u.get(y);return v?Rr(v,u,c):null}else return e===u?u:Rr(e,u,c)}function Il(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=an(d.parent,u);return i?i===u?Qi.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:Il(i,u):(J.warn(`getRootEntryPointScopeOwner is \`null\` because it was called with an entity that has no parent: ${d.id}`),null)}function iv(d,u,i){if(d===u||u===i||d===i||!d||!u)return!1;const a=zr(u.parent,i);return a===i?!1:a===d?!0:iv(a,u,i)}var rv=(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))(rv||{});function Ds(d,u,i){const a=zr(d,i),l=zr(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(iv(a,l,i))return{compatible:!0,type:"b-in-a",commonAncestorScope:a};if(iv(l,a,i))return{compatible:!0,type:"a-in-b",commonAncestorScope:l};const y=eR(a,l);return y===i?{compatible:!1,type:"parallel-in-project",commonAncestorScope:y}:y?{compatible:!1,type:"parallel-in-common-parent",commonAncestorScope:zr(y,i)}:{compatible:!1,type:"parallel-in-project",commonAncestorScope:i}}function wz(d,u,i){const a=Ds(d,u,i);if(!a.compatible||a.type!=="same-both-local")return null;if(d===u)return d;let l=zr(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=zr(l.parent,i)}let c=zr(u.parent,i);if(c){if(c===d)return d;if(c.type===p.Project)return u}else return u;for(;c;){if(c){if(c===d)return d;if(c.type===p.Project)return u}else return u;c=zr(c.parent,i)}return null}function Rz(d){return d.length===0?null:d.length===1?d[0]:d.reduce((i,a)=>{const l=wz(i,a,a.project);return!l||l===a?i:a},d[0])}function an(d,u){if(!d)return null;let i;return typeof d=="string"?i=d:d.type===p.GenericReference?i=te(d):i=d.id,i===u.id?u:u.get(i)}function go(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:go(u)}function by(d){const u=[];function i(c,e){return u.some(y=>y.blockedByCaller===c&&y.blockedByCalling===e)}function a(c,e){i(c,e)||u.push({blockedByCaller:c,blockedByCalling:e})}const l=Il(d,d.project);return l?(d.calledBySuccess.forEach(c=>{[...c.successCalls||[]].forEach(v=>{Nt.includes(v.type)&&v.id!==d.id&&(ht(d).find(b=>b===v)||a(c,v))});let y;if(mi.includes(c.type)&&(y=c),y){const v=by(y);v.reachable||ht(d).find(b=>b===c)||v.blocks.forEach(b=>{a(c,b.blockedByCalling)})}}),d.calledByError.forEach(c=>{[...c.errorCalls||[]].forEach(v=>{Nt.includes(v.type)&&v!==d&&(ht(d).find(b=>b===v)||a(c,v))});let y;if(mi.includes(c.type)&&(y=c),y){const v=by(y);v.reachable||ht(d).find(b=>b===c)||v.blocks.forEach(b=>{a(c,b.blockedByCalling)})}}),d.calledByEntry.forEach(c=>{if([...c.calls||[]].forEach(v=>{Nt.includes(v.type)&&v!==d&&(ht(d).find(b=>b===v)||a(c,v))}),c===l)return;let y;if(c.type===p.FunctionDeclaration){const v=Pi(c);if(v.type===p.DefinitionEntity)return;v.type===p.Loop&&(y=v)}if(y){const v=by(y);v.reachable||v.blocks.forEach(T=>{a(c,T.blockedByCalling)})}}),{reachable:u.length===0,entryPoint:l,blocks:u}):{reachable:!0,entryPoint:null,blocks:[]}}function HNe(d){return dc.includes(d.type)?d.type===p.FunctionDeclaration?!aR(d):!0:!1}function zNe(d){if(p.ActionDescriptor===d.type){if(d.project.operationDeclarations.find(c=>c.id===d.id))return p.Operation;if(d.project.globalEventActionDescriptors.find(c=>c.id===d.id))return p.GlobalEvent;if(d.project.loopDeclarations.find(c=>c.id===d.id))return p.Loop;if(d.project.conditionDeclarations.find(c=>c.id===d.id))return p.Condition}return d.type}function nv(d,u){return d.type===p.BuiltInBaseEntity?d.name===u:!!Co(d).includes(u)}function JNe(d,u){return d.type===p.BuiltInBaseEntity?d.name===u:!!Ty(d).includes(u)}function YNe(d){const u=[];return d.entities.forEach(i=>{if(nv(i,fe.PERSISTED_ENTITY)){u.push(i);return}}),C(u)}function SNe(d){const u=[];return d.entities.forEach(i=>{if(nv(i,fe.RELATIONAL_DATABASE)){u.push(i);return}}),C(u)}function XNe(d){return d.type!==p.DefinitionEntity||d.abstract||!nv(d,fe.PERSISTED_ENTITY)?null:(d==null?void 0:d.properties.find(i=>i.implements.find(a=>a.id===ce[p.BuiltInBaseEntity][fe.PERSISTED_ENTITY].properties.primaryKey.id)&&!i.abstract))||null}function Cz(d){var a;const u=rR(d);if(!u)return null;const i=u.properties.find(l=>l.implements.find(c=>c.id===ce[p.BuiltInBaseEntity][fe.PERSISTED_ENTITY].properties.database.id));return i?(a=i.getDefaultValue())==null?void 0:a.valueAsType:null}function vp(d){if(d.type!==p.DefinitionEntity)return[];if(d.abstract)return[];if(!cr(d,fe.PERSISTED_ENTITY))return[];const u=[],i=d.properties.filter(a=>!a.implements.find(l=>l.id===ce[p.BuiltInBaseEntity][fe.PERSISTED_ENTITY].properties.database.id)&&!a.abstract);return u.push(...i),u}function QNe(d){var i;if(!d||d.type!==p.DefinitionEntity||!cr(d,fe.PERSISTED_ENTITY))return null;const u=d.properties.find(a=>!!a.implements.find(l=>l.id===ce[p.BuiltInBaseEntity][fe.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(!Gg.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 eVe(d){switch(d){case p.Project:return L;case p.InstalledProject:return co;case p.DefinitionEntity:return us;case p.FunctionDeclaration:return Ia;case p.GlobalEvent:return io;case p.VariableInstance:return oo;case p.VariableDeclaration:return uo;case p.InputMap:return ls;case p.OutputMap:return ea;case p.Condition:return no;case p.Operation:return to;case p.FunctionCall:return Io;case p.ArgumentDeclaration:return ns;case p.PrimitiveEntity:return Rn;case p.DataType:return Wr;case p.Property:return ds;case p.ActionDescriptor:return Ut;case p.ReturnStatement:return cl;case p.ContinueStatement:return ho;case p.BreakStatement:return yo;case p.Loop:return ro;case p.Search:return po;case p.ValueDescriptor:return hl;case p.InternalCall:return fo;case p.LiteralValue:return $r}return null}function tVe(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 nr(d,u){const i=mp(d.type);return i?!i.MUTABLE_META_PROPERTIES.every(l=>{const c=d[l],e=u[l];return e===void 0||c===e?!0:Array.isArray(c)&&Array.isArray(e)?c.length!==e.length?!1:c.every((y,v)=>y===e[v]):!1}):!1}function sr(d,u,i){let a={...u};if(!d.checkCanEdit(d,i)){const l=mp(d.type);if(!l)return a;l.MUTABLE_META_PROPERTIES.forEach(c=>{["x","y","collapsed"].includes(c)||delete a[c]})}return a}function sv(d,u={}){if(d.type===p.Project)return[];if(!d.parent)return[];const i=te(d.parent);if(!i)return[];const a=u[i];return a?[a.id,...sv(a,u)]:[]}function iVe(d){const u=[],i=new Set;return[...d.listAdded,...d.listUpdated,...d.listAffected].forEach(l=>{var y;const c=Pi(l);if(!c||i.has(c.id))return;const e=d.project.get(c.id)||d.project.getDeleted(c.id);if(!e)throw new Error(`[getTouchedCanvasEntitiesFromChangeSet] Could not find active version of ${c.type} ${c.id} in project, which is present in the change set.${c.parent?` With parent ${(y=c.parent)==null?void 0:y.type} ${te(c.parent)}`:""}`);i.add(c.id),i.add(l.id),u.push(e)}),C(u)}function rVe(d){if(d.type===p.Condition)return null;if(d.type===p.Search)return d.project.getBuiltIn(ce["value-descriptor"][bh.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 gz(d){const u=d.entities.filter(l=>!!l.implements.find(c=>c.id===ce["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.id)),i=u.find(l=>{const c=l.properties.find(v=>v.implements.find(T=>T.id===ce["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.default.id)),e=c==null?void 0:c.getDefaultValue();return(e==null?void 0:e.value)===!0});return i||u[0]||null}function lR(d,u){const i=Array.from(new Set([...u.getAllBuiltInIds(),...Kn()]));return!!(i.includes(d.id)||!sv(d,{...u.instances,...u.builtInInstances}).every(c=>!i.includes(c)))}function _z(d){if(!d)return null;if(d.type===p.Project)return d.id;const u=d.parent;return u?_z(u):d.id}function Iy(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=Pi(d),i=Il(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 oR(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=Pi(d),i=Il(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 nVe(d,u,i){const a=u,l=i,c=!!i,e=[];return a.forEach(y=>{var v;if(c){const T=Ds(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 dR(d,u){var i,a,l,c;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=dR(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(((c=u.extends)==null?void 0:c.id)===d.id)return u;if(u.extends){const e=dR(u.extends,d);if(e)return e}}return null}function $d(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 $d(d.implements);if(d.extends)return $d(d.extends)}return d}function Al(d){var u;return!!(d.required||(u=d.declaration)!=null&&u.required)}function _o(d){return T6(d)||d===void 0||d===""}function ia(d){return d?d.valueAsType?!1:_o(d.value):!0}function Ay(d){return d.replace(/["'`]/g,"")}function Bi(d){const i=Ay(d).split(/[\s-]+/).filter(e=>e.length>0);if(i.length===0)return"";const a=i[0],l=a[0].toLowerCase()+a.slice(1),c=i.slice(1).map(e=>e[0].toUpperCase()+e.slice(1));return[l,...c].join("")}function Nd(d){return Ay(d).split(/[\s-]+/).filter(a=>a.length>0).map(a=>a[0].toUpperCase()+a.slice(1)).join("")}function Dz(d){const u=Ay(d).trim();if(!u)return"";const i=u.replace(/[\s_-]+/g," ").split(" ").filter(Boolean),a=[];for(const l of i){let c=l;c=c.replace(/([A-Z]+)([A-Z][a-z]+)/g,"$1-$2"),c=c.replace(/([a-z0-9])([A-Z][a-z0-9]*)/g,"$1-$2"),c=c.replace(/([0-9])([a-zA-Z]+)/g,"$1-$2"),c=c.replace(/([a-zA-Z])([0-9])/g,"$1-$2");for(const e of c.split("-"))e&&a.push(e)}return a.join("-")}function sVe(d){const u=Ay(d).trim();if(!u)return"";const i=u.replace(/[\s_-]+/g," ").split(" ").filter(Boolean),a=[];for(const l of i){let c=l;c=c.replace(/([A-Z]+)([A-Z][a-z]+)/g,"$1_$2"),c=c.replace(/([a-z0-9])([A-Z][a-z0-9]*)/g,"$1_$2"),c=c.replace(/([0-9])([a-zA-Z]+)/g,"$1_$2"),c=c.replace(/([a-zA-Z])([0-9])/g,"$1_$2");for(const e of c.split("_"))e&&a.push(e)}return a.join("_")}function av(d){return Dz(d).toLowerCase()}function uR(d){const u=Ay(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 Tp(d){var i,a,l,c;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)&&!((c=d.orChildrenGroup)!=null&&c.length))return e?`List of an any data type${u}`:`Any data type${u}`;let y="",v=!1,T=!1;return(d.andChildrenGroup||[]).forEach(I=>{const b=Tp(I),D=cd(b);v&&(y+=" and "),I.isGroup?y+="("+D+")":v?y+=D:y+=b,v=!0,T=!0}),(d.orChildrenGroup||[]).forEach(I=>{const b=Tp(I),D=cd(b);v&&(T&&(y+=","),y+=" or "),I.isGroup?y+="("+D+")":v?y+=D:y+=b,v=!0}),e?`List of ${cd(y)}`:y}if(d.entity.type===p.PrimitiveEntity){let e=d.entity.name;switch(d.entity.name){case ie.String:e="Text";break;case ie.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=Pz(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===ie.Null)return"Empty value";if(d.entity.name===ie.Untyped)return"Untyped value";if(d.entity.name===ie.File)return"File";if(d.entity.name===ie.String)return`"${d.entity.value}" text`;if(d.entity.name===ie.Number)return`Number '${d.entity.value}'`;if(d.entity.name===ie.Boolean)return`${d.entity.value} value`;if(d.entity.name===ie.UUID)return`"${d.entity.value}" unique identifier`;if(d.entity.name===ie.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 aVe(d){if(!d)return"Any data type";const u=d.getDataType(null);return Tp(u)}function lv(d){switch(d.declaration.id){case ut.Equal:return"is equal to";case ut.NotEqual:return"is not equal to";case ut.MoreThan:return"is greater than";case ut.MoreThanOrEqual:return"is greater than or equal to";case ut.LessThan:return"is less than";case ut.LessThanOrEqual:return"is less than or equal to";case Gi.And:return"and";case Gi.Or:return"or";case Ar.Empty:return"is empty";case Ar.NotEmpty:return"is present"}}function Oz(d){if(d.includes(fe.HTTP_ENDPOINT))return"HTTP endpoint";if(d.includes(fe.PERSISTED_ENTITY))return"Persisted entity";if(d.includes(fe.CRON_JOB))return"Scheduled execution";if(d.includes(fe.RELATIONAL_DATABASE))return"Relational database";if(d.includes(fe.SQL_ROW_TRANSFORMER))return"Row transformer";if(d.includes(fe.GOOGLE_AUTH_CONNECTION))return"Google account connection";if(d.includes(fe.SLACK_AUTH_CONNECTION))return"Slack account connection";if(d.includes(fe.AIRTABLE_AUTH_CONNECTION))return"Airtable account connection";if(d.includes(fe.MICROSOFT_AUTH_CONNECTION))return"Microsoft account connection";if(d.includes(fe.OPENAI_AUTH_CONNECTION))return"OpenAI account connection";if(d.includes(fe.ATLASSIAN_AUTH_CONNECTION))return"Atlassian account connection";if(d.includes(fe.JIRA_AUTH_CONNECTION))return"Jira account connection";if(d.includes(fe.GOOGLE_DRIVE_AUTH_CONNECTION))return"Google Drive account connection";if(d.includes(fe.GOOGLE_MAIL_AUTH_CONNECTION))return"Gmail account connection";if(d.includes(fe.GOOGLE_SHEET_AUTH_CONNECTION))return"Google Sheet account connection";if(d.includes(fe.GOOGLE_SLIDES_AUTH_CONNECTION))return"Google Slides account connection";if(d.includes(fe.GOOGLE_GEMINI_AUTH_CONNECTION))return"Google Gemini account connection";if(d.includes(fe.EXTERNAL_INTEGRATION_CONNECTION))return"External integration connection";try{return uR(d[0])}catch(u){return console.error("Error resolving base entity name for base entities:",d,u),"Built-in base entity"}}function Pz(d){switch(d.name){case fe.HTTP_ENDPOINT:return"HTTP endpoint";case fe.PERSISTED_ENTITY:return"Persisted entity";case fe.CRON_JOB:return"Scheduled execution";case fe.RELATIONAL_DATABASE:return"Relational database";case fe.SQL_ROW_TRANSFORMER:return"Row transformer";case fe.GOOGLE_AUTH_CONNECTION:return"Google account connection";case fe.SLACK_AUTH_CONNECTION:return"Slack account connection";case fe.AIRTABLE_AUTH_CONNECTION:return"Airtable account connection";case fe.MICROSOFT_AUTH_CONNECTION:return"Microsoft account connection";case fe.OPENAI_AUTH_CONNECTION:return"OpenAI account connection";case fe.ATLASSIAN_AUTH_CONNECTION:return"Atlassian account connection";case fe.JIRA_AUTH_CONNECTION:return"Jira account connection";case fe.GOOGLE_DRIVE_AUTH_CONNECTION:return"Google Drive account connection";case fe.GOOGLE_MAIL_AUTH_CONNECTION:return"Gmail account connection";case fe.GOOGLE_SHEET_AUTH_CONNECTION:return"Google Sheet account connection";case fe.GOOGLE_SLIDES_AUTH_CONNECTION:return"Google Slides account connection";case fe.GOOGLE_GEMINI_AUTH_CONNECTION:return"Google Gemini account connection";case fe.EXTERNAL_INTEGRATION_CONNECTION:return"External integration connection";case fe.EXTERNAL_INTEGRATION_CONNECTION:return"External integration connection"}try{return uR(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 lVe(d){const u=tv(d);if(!u){const i=yp(d);return i.includes(fe.HTTP_ENDPOINT)?"HTTP endpoint":i.includes(fe.PERSISTED_ENTITY)?"Persisted entity":i.includes(fe.CRON_JOB)?"Scheduled execution":i.includes(fe.RELATIONAL_DATABASE)?"Relational database":i.includes(fe.SQL_ROW_TRANSFORMER)?"Row transformer":i.includes(fe.GOOGLE_AUTH_CONNECTION)?"Google account connection":i.includes(fe.SLACK_AUTH_CONNECTION)?"Slack account connection":i.includes(fe.AIRTABLE_AUTH_CONNECTION)?"Airtable account connection":i.includes(fe.MICROSOFT_AUTH_CONNECTION)?"Microsoft account connection":i.includes(fe.OPENAI_AUTH_CONNECTION)?"OpenAI account connection":i.includes(fe.ATLASSIAN_AUTH_CONNECTION)?"Atlassian account connection":i.includes(fe.JIRA_AUTH_CONNECTION)?"Jira account connection":i.includes(fe.EXTERNAL_INTEGRATION_CONNECTION)?"External integration connection":S(d,d.project)+" entity"}return S(u,d.project)+" entity"}function $z(d){let u="Find ";return d.outputs.forEach((i,a)=>{const l=E0(i,null),c=cd(l&&l.entity?S(l.entity,d.project):"unstructured data");a===0?u+=`${c} `:a===d.outputs.length-1?u+=`and ${c} `:u+=`, ${c} `}),u}function Nz(d){switch(d.name){case ie.String:return"Text";case ie.Number:return"Number";case ie.Boolean:return"Boolean";case ie.KeyValue:return"Data structure";case ie.UUID:return"Unique identifier";case ie.Date:return"Date";case ie.EntityTemplate:return"Entity as template";case ie.Enum:return"Enumeration";case ie.File:return"File";case ie.Null:return"Empty";case ie.ActionDescriptor:return"Action descriptor";case ie.Untyped:return"Untyped";default:return d.name}}function Vz(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 $i.Addition:return"Sum numbers";case $i.Subtraction:return"Subtract numbers";case $i.Multiplication:return"Multiply numbers";case $i.Division:return"Divide numbers";case $i.Remainder:return"Get remainder of numbers";case $i.Exponentiation:return"Get exponent of numbers";case Je.AddIndex:return"Add at index position";case Je.DeleteFirst:return"Delete first character";case Je.DeleteLast:return"Delete last character";case Je.DeleteIndex:return"Delete at index position";case Je.Join:return"Join texts";case Je.ReplaceAllMatches:return"Replace all matches";case Je.ReplaceFirst:return"Replace first match";case Je.ReplaceLast:return"Replace last match";case Je.Split:return"Split text";case Je.ReplaceIndex:return"Replace at index position";case Je.ReplaceSingleMatch:return"Replace single match";case Je.GetFirst:return"Get first character";case Je.GetLast:return"Get last character";case Je.GetIndexItem:return"Get at index position";case Je.GetIndexOf:return"Get the index number of the character";case Je.Append:return"Add at the end";case Je.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 cn.HttpRequest:return"HTTP request";case dt.AddIndex:return"Add item at index position";case dt.DeleteFirst:return"Delete first item";case dt.DeleteLast:return"Delete last item";case dt.DeleteIndex:return"Delete item at index position";case dt.Join:return"Join lists";case dt.ReplaceFirst:return"Replace first match";case dt.ReplaceLast:return"Replace last match";case dt.Split:return"Split list";case dt.ReplaceIndex:return"Replace at index position";case dt.GetFirst:return"Get first item";case dt.GetLast:return"Get last item";case dt.GetIndexItem:return"Get item at index position";case dt.Append:return"Add item at the end";case dt.Prepend:return"Add item at the start";case js.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(dr).includes(a))switch(a){case dr.AbortExecution:return"Abort ongoing execution";case dr.DeletePersistedEntity:return"Delete entry from database";case dr.CreatePersistedEntity:return"Save new data entry in database";case dr.UpdatePersistedEntity:return"Update entity data to database";case dr.DownSQLRowTransformer:return"Reverse row";case dr.UpSQLRowTransformer:return"Transform row";default:return Tr(d.type).replaceAll("-"," ")}return a}if(p.BuiltInBaseEntity===d.type)return Oz([d.name]);if(jg.includes(d.type)&&d.type!==p.ActionDescriptor)return d.name;switch(d.type){case p.Search:return $z(d);case p.GlobalEvent:return d.implements?S(d.implements,u):Tr(d.type).replaceAll("-"," ");case p.Operation:case p.InternalCall:case p.Loop:const a=an(d.declaration,u);return S(a,u);case p.ActionDescriptor:return Vz(d);case p.BreakStatement:const l=an(d.parent,u);return`Stop loop ${S(l,u)}`;case p.ContinueStatement:const c=an(d.parent,u);return`Execute next iteration of ${S(c,u)}`;case p.FunctionCall:return an(d.declaration,u).name;case p.Condition:{const y=d;if(y.declaration.id===Gi.And)return"If all conditions are met";if(y.declaration.id===Gi.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} ${lv(y)} ${T}`}return`If ${v} ${lv(y)}`}else return`If ${lv(y)}`}case p.ReturnStatement:{const y=an(d.parent,u);return y?`Output of ${S(y,u)}`:"Return statement"}case p.InputMap:if(d.declaration){const y=an(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=an(d.declaration,u);return S(y,u)||""}case p.OutputMap:if(d.declaration){const y=an(d.declaration,u);return(y==null?void 0:y.name)||""}else return d.parentRelationType===Ol.Error?"Undeclared error":"";case p.PrimitiveEntity:case p.LiteralValue:return Nz(d);default:return Tr(d.type).replaceAll("-"," ")}}function pR(d,u){const i=[];d.name||i.push(new pe({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:ee.Error,code:de.EmptyName}));const a=u.entities.filter(l=>l.name===d.name);return a.length&&i.push(new pe({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:ee.Error,code:de.NameNotUniqueInScope})),i}function cR(d,u){const i=[];d.name||i.push(new pe({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:ee.Error,code:de.EmptyName}));const a=d.parent?te(d.parent):null;let l=u;a&&(l=u.get(a));const c=[];l.type===p.DefinitionEntity?c.push(...l.methods.map(y=>y)):l.type===p.Project?c.push(...l.functions.map(y=>y)):l.type===p.Loop?l.body&&c.push(l.body):l.type===p.InstalledProject&&c.push(...l.functions.map(y=>y));const e=c.filter(y=>y.name===d.name);return e.length&&i.push(new pe({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:ee.Error,code:de.NameNotUniqueInScope})),i}function fR(d,u){const i=[];d.name||i.push(new pe({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:ee.Error,code:de.EmptyName}));const a=d.parent&&an(d.parent,u)||u;if(!a)i.push(new pe({id:`${d.id}--parent-reference--${H.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:ee.Error,code:H.ReferencedEntityNotFound}));else{const c=bw(a).filter(e=>e.name===d.name);c.length&&i.push(new pe({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 "${c[0].id}" has the same name.
|
|
390
390
|
Please provide a unique 'name' string.`,severity:ee.Error,code:de.NameNotUniqueInScope}))}return i}function yR(d,u){const i=[];d.name||i.push(new pe({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:ee.Error,code:de.EmptyName}));const a=te(d.parent);if(!a)i.push(new pe({id:`${d.id}--parent-reference--${H.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:ee.Error,code:H.InvalidReferenceObjectStructure}));else{const l=u.get(a);if(!l)i.push(new pe({id:`${d.id}--parent-reference--${H.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:ee.Error,code:H.ReferencedEntityNotFound}));else{const e=l.properties.filter(y=>y.name===d.name);e.length&&i.push(new pe({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.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@elyx-code/project-logic-tree",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.6592",
|
|
4
4
|
"author": "Sergio Herrero",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"description": "An installable module which contains the type definitions and ephemeral state management for a projects' logic tree data structure",
|