@elyx-code/project-logic-tree 0.0.6565 → 0.0.6566
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 +4 -3
- package/dist/index.umd.cjs +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -124093,7 +124093,7 @@ function jxt(d, u) {
|
|
|
124093
124093
|
let K = M.defaultValue || null;
|
|
124094
124094
|
if (!K) {
|
|
124095
124095
|
const q = Mr.new(u);
|
|
124096
|
-
q.parent = M.toReference(), q.id = V.UUID.uuid(), K = se(
|
|
124096
|
+
q.name = ie.EntityTemplate, q.parent = M.toReference(), q.id = V.UUID.uuid(), K = se(
|
|
124097
124097
|
q,
|
|
124098
124098
|
d.project
|
|
124099
124099
|
), K.hydrateAncestors(), K.setParent(
|
|
@@ -128049,13 +128049,14 @@ function cUt(d) {
|
|
|
128049
128049
|
...d.listUpdated,
|
|
128050
128050
|
...d.listAffected
|
|
128051
128051
|
].forEach((a) => {
|
|
128052
|
+
var e;
|
|
128052
128053
|
const l = Oi(a);
|
|
128053
128054
|
if (!l || i.has(l.id))
|
|
128054
128055
|
return;
|
|
128055
|
-
const c = d.project.get(a.id);
|
|
128056
|
+
const c = d.project.get(a.id) || d.project.getDeleted(a.id);
|
|
128056
128057
|
if (!c)
|
|
128057
128058
|
throw new Error(
|
|
128058
|
-
`Could not find active version of
|
|
128059
|
+
`[getTouchedCanvasEntitiesFromChangeSet] Could not find active version of ${a.type} ${a.id} in project, which is present in the change set.${a.parent ? ` With parent ${(e = a.parent) == null ? void 0 : e.type} ${ee(a.parent)}` : ""}`
|
|
128059
128060
|
);
|
|
128060
128061
|
i.add(l.id), u.push(c);
|
|
128061
128062
|
}), R(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 ue({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 ue({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,V.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:A,removed:b}=this.remove({ignoreUpstream:!1},l);c.push(...T),e.push(...A),y.push(...b)}if(a==="function-call-parent-field"){const{updated:T,added:A,removed:b}=this.remove({ignoreUpstream:!1},l);c.push(...T),e.push(...A),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:A,removed:b}=this.restore({},l);c.push(...T),e.push(...A),y.push(...b)}if(a==="function-call-parent-field"){const{updated:T,added:A,removed:b}=this.restore({},l);c.push(...T),e.push(...A),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=V.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[A,b]of this.knownVersions||new Map){if(T.set(A,b),b.activeVersion=!1,b.knownVersions)for(const[O,L]of b.knownVersions)T.set(O,L);b.knownVersions=null}}let y=(v=this.knownVersions)==null?void 0:v.get(i);if(!y){const T=await this.APILoadVersion({},i);if(!T)throw new Error(`Version with id '${i}' for entity with id '${this.id}' not found.`);y=new yi(T,this.project)}return this.metaSync(y.toShallowJSON(),null),this.previousVersion=y.previousVersion,this.version=y.version,this.createdAt=y.createdAt,this.author=y.author,this.deleted=y.deleted,this.inputs=y.inputs,this.outputs=y.outputs,this.error=y.error,this.successCalls=y.successCalls,this.errorCalls=y.errorCalls,this.declaration=y.declaration,this.calledBySuccess=y.calledBySuccess,this.calledByError=y.calledByError,this.calledByEntry=y.calledByEntry,this.parent=y.parent,{updated:C(a),added:C(l),removed:C(c),affected:C(e),self:this}}updateWithShallowTransfer(i,a=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,P.UpdateWithShallowTransfer))){if(!this.checkCanEdit(this,a))return Y.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,V.sessionAuthor,B().toISOString(),this,!0,P.AfterAllChildrenInitialized))){if(!this.checkCanEdit(this,i))return Y.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:A,added:b,removed:O}=this.syncOutputs(i);return a.push(...y,...A),l.push(...v,...b),c.push(...T,...O),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,V.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,V.sessionAuthor,B().toISOString(),this,!0,P.RemoveInput))){if(!this.checkCanEdit(this,a))return Y.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,V.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):(Y.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,V.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):(Y.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,V.sessionAuthor,B().toISOString(),this,!0,"remove-output"))){if(!this.checkCanEdit(this,a))return Y.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,V.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,V.sessionAuthor,B().toISOString(),this,!0,P.RemoveValueReader))){return this.checkCanEditWithCounterpartAndSideEffects(this,i,P.RemoveValueReader,a)?this.writesValues.includes(i)?(this.writesValues=this.writesValues.filter(l=>l.id!==i.id),a==null||a.add(this,k.Affected),this):(a==null||a.attemptAutoclose(P.RemoveValueReader,this.id),this):this}addSuccessCaller(i,a=this.project.addChangeSet(new G(this.project,V.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,V.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,V.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,V.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,V.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,V.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,V.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,V.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,V.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=ne(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=ne(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=ne(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=ne(a,this.project);return l.setParent(this,null),l.initChildren(i),l}),this.initialData.error&&(this.error=ne(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,V.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=Ce,...a){return await yi.repository.APILoad(this.id,...a),this}async APICreate(i=Ce,...a){return await yi.repository.APICreate(this.toShallowJSON(),...a),this}async APIUpdate(i=Ce,...a){return await yi.repository.APIUpdate(this.toShallowJSON(),...a),this}async APIDelete(i=Ce,...a){return await yi.repository.APIDelete(this.toShallowJSON(),...a),this}async APIClone(i=Ce,...a){return await yi.repository.APIClone(this.id,...a),this}async APILoadVersion(i=Ce,a,...l){return await yi.repository.APILoadVersion(this.id,a,...l)}removeFromParent(i=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,P.RemoveFromParent))){if(!this.checkCanEdit(this,i))return Y.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,V.sessionAuthor,B().toISOString(),this,!0,P.RemoveEntity))){var v;if(!this.checkCanDelete(this,a))return Y.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:A,removed:b,added:O}=T.entity.onDetachedDependencyRemoved(this,T.field,a);l.push(...A),c.push(...b),e.push(...O)}),this.inputs.forEach(T=>{const{updated:A,removed:b}=T.remove({ignoreUpstream:!0},a);l.push(...A),c.push(...b)}),this.outputs.forEach(T=>{const{updated:A,removed:b}=T.remove({ignoreUpstream:!0},a);l.push(...A),c.push(...b)}),this.error){const{updated:T,removed:A}=this.error.remove({ignoreUpstream:!0},a);l.push(...T),c.push(...A)}if(this.successCalls.forEach(T=>{l.push(T),T.removeCaller(this,a)}),this.errorCalls.forEach(T=>{l.push(T),T.removeCaller(this,a)}),!i){const T=this.removeFromParent(a);e.push(...T.added),l.push(...T.updated),c.push(...T.removed),y.push(...T.affected),this.calledBy.forEach(A=>{l.push(A),A.removeCall(this,a)})}return a==null||a.attemptAutoclose(P.RemoveEntity,this.id),{added:C(e),updated:C(l),removed:C(c),affected:C(y),self:this}}restore({}={},i=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,P.RestoreEntity))){if(!this.checkCanEdit(this,i))return Y.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:A}=y.entity.onDetachedDependencyRestored(this,y.field,i);l.push(...v),c.push(...T),a.push(...A)}),this.inputs.forEach(y=>{const{updated:v}=y.restore({},i);l.push(...v)}),this.outputs.forEach(y=>{const{updated:v}=y.restore({},i);l.push(...v)}),this.successCalls.forEach(y=>{l.push(y),y.addSuccessCaller(this,i)}),this.errorCalls.forEach(y=>{l.push(y),y.addErrorCaller(this,i)}),this.calledBySuccess.forEach(y=>{l.push(y),y.addSuccessCall(this,i)}),this.calledByError.forEach(y=>{l.push(y),y.addErrorCall(this,i)}),this.calledByEntry.forEach(y=>{l.push(y),y.addCall(this,i)}),i==null||i.attemptAutoclose(P.RestoreEntity,this.id),{added:C(a),updated:C(l),removed:C(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:V.UUID.uuid(),createdAt:i.timestamp||B().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,catchesError:this.catchesError,type:this.type,editable:this.editable,deletable:this.deletable,x:this.x,y:this.y,writesValues:this.writesValues.map(A=>A.toJSONClone({...i,newId:null})),successCalls:this.successCalls.map(A=>A.toJSONClone({...i,newId:null})),errorCalls:this.errorCalls.map(A=>A.toJSONClone({...i,newId:null})),calledBySuccess:this.calledBySuccess.map(A=>A.toReference({seenEntityMaps:i.seenEntityMaps})),calledByError:this.calledByError.map(A=>A.toReference({seenEntityMaps:i.seenEntityMaps})),calledByEntry:this.calledByEntry.map(A=>A.toReference({seenEntityMaps:i.seenEntityMaps})),declaration:this.declaration.toJSONClone({...i,newId:null}),inputs:this.inputs.map(A=>A.toJSONClone({...i,newId:null})),outputs:this.outputs.map(A=>A.toJSONClone({...i,newId:null})),error:(T=this.error)==null?void 0:T.toJSONClone({...i,newId:null}),parent:this.parent.toReference({seenEntityMaps:i.seenEntityMaps})})}toReference(i=He){var l;let a=this.id;return(l=i.seenEntityMaps)!=null&&l.has(this.id)&&(a=i.seenEntityMaps.get(this.id)),{id:a+"--"+V.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=dH(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,V.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||V.UUID.uuid();y.inputs=[];const T=v.split("-id"),A=T[T.length-1||0]||v;y.id=v,y.version=V.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 O=(M=this.inputs)==null?void 0:M.map((q,Z)=>q.clone(i,b,A+"-input-map-"+Z+"-id",c));b.inputs=O;const L=(x=this.outputs)==null?void 0:x.map((q,Z)=>q.clone(i,b,A+"-output-map-"+Z+"-id",c));return b.outputs=L,this.error&&(b.error=this.error.clone(i,b,A+"-error-map-id",c)),i==null||i.attemptAutoclose(P.CloneEntity,this.id),b}removeUnrecognizedInputs(i=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,P.RemoveUnrecognizedInputs))){if(!this.checkCanEdit(this,i))return Y.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(A=>{var b;return A.id===((b=v.declaration)==null?void 0:b.id)})){const A=v.remove({ignoreUpstream:!1},i);c.push(...A.removed),a.push(...A.updated)}}),this.inputs.filter((v,T)=>{const A=this.inputs.findIndex(O=>O.declaration===v.declaration&&O!==v);if(A===-1)return!1;const b=this.inputs[A];return B(b==null?void 0:b.createdAt).isSame(B(v.createdAt))?T>A:!!B(b==null?void 0:b.createdAt).isAfter(v.createdAt)}).forEach(v=>{const T=v.remove({ignoreUpstream:!1},i);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,V.sessionAuthor,B().toISOString(),this,!0,P.RemoveUnrecognizedOutputs))){var T,A;if(!this.checkCanEdit(this,i))return Y.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=((A=(T=this.declaration.dataType)==null?void 0:T.entity)==null?void 0:A.properties)||[];return this.outputs.forEach(b=>{if(!y.find(L=>{var M;return L.id===((M=b.declaration)==null?void 0:M.id)})){const L=b.remove({ignoreUpstream:!1},i);c.push(...L.removed),a.push(...L.updated)}}),this.outputs.filter((b,O)=>{const L=this.outputs.findIndex(x=>x.declaration===b.declaration&&x!==b);if(L===-1)return!1;const M=this.outputs[L];return B(M==null?void 0:M.createdAt).isSame(B(b.createdAt))?O>L:!!B(M==null?void 0:M.createdAt).isAfter(b.createdAt)}).forEach(b=>{const O=b.remove({ignoreUpstream:!1},i);c.push(...O.removed),a.push(...O.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,V.sessionAuthor,B().toISOString(),this,!0,P.SyncInputs))){if(!this.checkCanEdit(this,i))return Y.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(O=>O.declaration.id===b.id));this.inputs.sort((b,O)=>b.index-O.index),y.forEach(b=>{this.inputs.forEach(M=>{M.index>=b.index&&M.metaSync({index:M.index+1},i)});const O={id:V.UUID.uuid(),version:V.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||B().toISOString(),author:V.sessionAuthor,previousVersion:null,deleted:!1,deletable:!0,editable:!0,type:p.InputMap,parentRelationType:null,declaration:b.toJSON(),readsValue:null,defaultValue:null,index:b.index,name:null,codeName:null,description:null,parent:this.toReference()},L=ne(O,this.project);L.setParent(this,i),L.initChildren(i),i==null||i.add(L,k.Added),L.addSelfToProject(i),l.push(L)}),this.inputs.sort((b,O)=>b.index-O.index);const{updated:v,added:T,removed:A}=this.removeUnrecognizedInputs(i);return a.push(...v),l.push(...T),c.push(...A),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,V.sessionAuthor,B().toISOString(),this,!0,P.SyncOutputs))){var O,L;if(!this.checkCanEdit(this,i))return Y.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=mn(x,this.project);return Z?[...M,Z]:M}const q=ne(x,this.project);return y.push(q.index),q.setParent(this,null),q.initChildren(i),[...M,q]},[]);const v=(((L=(O=this.declaration.dataType)==null?void 0:O.entity)==null?void 0:L.properties)||[]).filter(M=>!this.outputs.find(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(J=>{J.index>=M.index&&J.index++});const q=y.includes(M.index)?this.outputs.length-1+x:M.index,Z={id:V.UUID.uuid(),version:V.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||B().toISOString(),author:V.sessionAuthor,previousVersion:null,deleted:!1,deletable:!0,editable:!0,type:p.OutputMap,declaration:M.toJSON(),writesValues:[],index:q,parent:this.toReference()},W=ne(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:A,removed:b}=this.removeUnrecognizedOutputs(i);return a.push(...T),l.push(...A),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,V.sessionAuthor,B().toISOString(),this,!0,"get-data-type"))){var l;const a=((l=this.declaration)==null?void 0:l.getDataType(i))||null;return i==null||i.attemptAutoclose("get-data-type",this.id),a}};_(yi,"repository",{APICreate:async(i,...a)=>i,APIUpdate:async(i,...a)=>i,APIDelete:async(i,...a)=>i,APIClone:async(i,...a)=>{},APILoad:async(i,...a)=>null,APILoadVersion:async(i,a,...l)=>null}),_(yi,"type",p.FunctionCall),_(yi,"USER_MANAGED_PARENT_TYPES",[...Xi,p.Project]),_(yi,"PARENT_TYPES",[...yi.USER_MANAGED_PARENT_TYPES]),_(yi,"MUTABLE_BASE_PROPERTIES",["catchesError"]),_(yi,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),_(yi,"BASE_PROPERTIES",[...yi.MUTABLE_BASE_PROPERTIES,...yi.INMUTABLE_BASE_PROPERTIES]),_(yi,"MUTABLE_META_PROPERTIES",["x","y"]),_(yi,"INMUTABLE_META_PROPERTIES",[...yi.INMUTABLE_BASE_PROPERTIES]),_(yi,"META_PROPERTIES",[...yi.MUTABLE_META_PROPERTIES,...yi.INMUTABLE_META_PROPERTIES]),_(yi,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry"]),_(yi,"INMUTABLE_UPSTREAM_PROPERTIES",["declaration","parent"]),_(yi,"UPSTREAM_PROPERTIES",[...yi.MUTABLE_UPSTREAM_PROPERTIES,...yi.INMUTABLE_UPSTREAM_PROPERTIES]),_(yi,"MUTABLE_DOWNSTREAM_PROPERTIES",["successCalls","errorCalls","writesValues","inputs","outputs","error"]),_(yi,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),_(yi,"DOWNSTREAM_PROPERTIES",[...yi.MUTABLE_DOWNSTREAM_PROPERTIES,...yi.INMUTABLE_DOWNSTREAM_PROPERTIES]),_(yi,"PROPERTIES",[...yi.META_PROPERTIES,...yi.UPSTREAM_PROPERTIES,...yi.DOWNSTREAM_PROPERTIES]);let Eo=yi;function Uw(d){return d&&typeof d.then=="function"}function S$e(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 X$e(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(Te(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}=op(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||Y.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}=op(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(op(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);Uw(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);Uw(e)&&(this.onGoingVisits[a][l]=e)}return await this.settlePromises(this.onGoingVisits[a],a),this.onGoingVisits[a]={},this}}const Q$e=63,eNe=/^[a-z][a-z0-9-]*[a-z0-9]$/;function tNe(d){return d.length>=1&&d.length<=Q$e&&eNe.test(d)&&!d.includes("--")}function*iNe(){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 rNe(d,u){const i=new Set(d.map(l=>l.toLowerCase())),a=u>0?"secondary-db":"main";for(const l of iNe()){const c=l?`${a}-${l}`:a;if(tNe(c)&&!i.has(c))return c}throw new Error("Unable to generate identifier")}function uH(d,u){switch(d.id){case pe["built-in-base-entity"].BUILT_IN_PERSISTED_ENTITY_ENTITY.id:{const i=d.project.entities.filter(v=>!!v.implements.find(T=>T.id===pe["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.id)),a=i.find(v=>{const T=v.properties.find(O=>O.implements.find(L=>L.id===pe["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.default.id)),A=T==null?void 0:T.getDefaultValue();return(A==null?void 0:A.value)===!0});if(!a&&i.length){const T=i[0].properties.find(b=>b.implements.find(O=>O.id===pe["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.default.id)),A=T==null?void 0:T.defaultValue;if(A)A.metaSync({value:!0},u);else if(T!=null&&T.dataType){const b={id:V.UUID.uuid(),version:V.UUID.uuid(),createdAt:(u==null?void 0:u.timestamp)||new Date().toISOString(),author:V.sessionAuthor,previousVersion:null,deleted:!1,deletable:!0,editable:!0,type:p.LiteralValue,standaloneParent:null,name:re.EntityTemplate,autogeneration:null,value:!0,valueAsTypeSingle:null,valueAsTypeList:null,parent:T==null?void 0:T.toReference()},O=ne(b,d.project);return O.setParent(T,u),O.initChildren(u),u==null||u.add(O,k.Added),O.addSelfToProject(u),{newEntities:[O]}}return{newEntities:[]}}else if(a)return{newEntities:[]};const l=d.project.get(pe["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.id),c=j0(l,"Main database",u);if(c.errors.length>0)return{newEntities:[]};const e=c.properties.find(v=>v.implements.find(T=>T.id===pe["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:V.UUID.uuid(),version:V.UUID.uuid(),createdAt:(u==null?void 0:u.timestamp)||new Date().toISOString(),author:V.sessionAuthor,previousVersion:null,deleted:!1,deletable:!0,editable:!0,type:p.LiteralValue,standaloneParent:null,name:re.EntityTemplate,autogeneration:null,value:!0,valueAsTypeSingle:null,valueAsTypeList:null,parent:e==null?void 0:e.toReference()},T=ne(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 pH(d,u){const i=[],a=[],l=[],c=[];return d.implements.filter(y=>y.type===p.BuiltInBaseEntity).forEach(y=>{var v,T,A,b,O;switch(y.id){case pe["built-in-base-entity"].BUILT_IN_PERSISTED_ENTITY_ENTITY.id:{const L=d.project.entities.filter(W=>W.implements.find(J=>J.id===pe["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.id));let M=L.find(W=>!!W.properties.find(J=>{var le;return J.implements.find(z=>z.id===pe["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.default.id)&&((le=J.getDefaultValue())==null?void 0:le.value)===!0}));if(!M&&L.length)M=L[0];else if(!M&&!L.length){M=d.project.getBuiltIn(pe["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.id).implement("Relational database",u);const J=M.properties.find(le=>le.implements.find(z=>z.id===pe["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.default.id));(v=J==null?void 0:J.defaultValue)==null||v.metaSync({value:!0},u),a.push(M)}const x=d.properties.find(W=>W.implements.find(J=>J.id===pe["built-in-base-entity"].BUILT_IN_PERSISTED_ENTITY_ENTITY.properties.database.id));if(x&&!(x!=null&&x.defaultValue)){const W={id:V.UUID.uuid(),version:V.UUID.uuid(),createdAt:(u==null?void 0:u.timestamp)||new Date().toISOString(),author:V.sessionAuthor,previousVersion:null,deleted:!1,deletable:!0,editable:!0,type:p.LiteralValue,standaloneParent:null,name:re.EntityTemplate,autogeneration:null,value:null,valueAsTypeSingle:(M==null?void 0:M.toJSON())||null,valueAsTypeList:null,parent:x==null?void 0:x.toReference()},J=ne(W,d.project);J.hydrateAncestors(),J.setParent(x,u),J.addSelfToProject(u),u==null||u.add(J,k.Added),J.initChildren(u),(x==null?void 0:x.defaultValue).setValueAsTypeSingle(M||null,u),a.push(J);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(J=>J.id===pe["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 ${pe["built-in-base-entity"]}`);if(!q.dataType){const W=Zr.new(u);W.parent=q.toReference();const J=ne(W,d.project);J.hydrateAncestors(),J.setParent(q,u),J.addSelfToProject(u),u==null||u.add(J,k.Added),J.initChildren(u)}const Z=d.project.getBuiltIn(pe["primitive-entity"].number.id);(T=q.dataType)==null||T.setEntity(Z,u);return}case pe["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.id:{const L=d.project.entities.filter(le=>le.implements.find(z=>z.id===pe["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.id)&&le.id!==d.id),M=L.map(le=>{var ie;const z=le.properties.find(de=>de.implements.find(me=>me.id===pe["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.identifier.id));return(ie=z==null?void 0:z.getDefaultValue())==null?void 0:ie.value}).filter(le=>!!le),x=d.properties.find(le=>le.implements.find(z=>z.id===pe["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.identifier.id));if(!L.find(le=>!!le.properties.find(z=>{var ce;return z.implements.find(ie=>ie.id===pe["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.default.id)&&((ce=z.getDefaultValue())==null?void 0:ce.value)===!0}))){const le=d.properties.find(z=>z.implements.find(ce=>ce.id===pe["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.default.id));if(!le)throw new Error("Default boolean property not found for relational database entity with id: "+d.id);if(!(le!=null&&le.defaultValue)){const z=Pr.new(u);z.parent=le.toReference();const ce=ne(z,d.project);ce.hydrateAncestors(),ce.setParent(le,u),ce.addSelfToProject(u),u==null||u.add(ce,k.Added),ce.initChildren(u)}(A=le==null?void 0:le.defaultValue)==null||A.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 le=Pr.new(u);le.parent=x.toReference();const z=ne(le,d.project);z.hydrateAncestors(),z.setParent(x,u),z.addSelfToProject(u),z.initChildren(u),u==null||u.add(z,k.Added)}const Z=rNe(M,L.length);(b=x.defaultValue)==null||b.metaSync({value:Z},u);const W=d.properties.find(le=>le.implements.find(z=>z.id===pe["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 ${pe["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.id} with id ${d.id}`);if(!W.defaultValue){const le=Pr.new(u);le.parent=W.toReference();const z=ne(le,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 J=t7(24);(O=W.defaultValue)==null||O.metaSync({value:J},u);return}case pe["built-in-base-entity"].BUILT_IN_SQL_ROW_TRANSFORMER_ENTITY.id:{const L=d.properties.find(Z=>Z.implements.find(W=>W.id===pe["built-in-base-entity"].BUILT_IN_SQL_ROW_TRANSFORMER_ENTITY.properties.time.id));if(!L)throw new Error(`[handleAfterEntityImplementationSideEffects] Time property not found for implemented base entity ${pe["built-in-base-entity"].BUILT_IN_SQL_ROW_TRANSFORMER_ENTITY.id} with id ${d.id}`);let M=L.defaultValue||null;if(!M){const Z=Pr.new(u);Z.parent=L.toReference(),Z.name=re.Date,Z.id=V.UUID.uuid(),M=ne(Z,d.project),M.hydrateAncestors(),M.setParent(L,u),M.addSelfToProject(u),M.initChildren(u),u==null||u.add(M,k.Added)}M.metaSync({value:new Date().toISOString()},u),M.metaSync({editable:!1,deletable:!1},u),L.metaSync({editable:!1,deletable:!1},u);const x=d.properties.find(Z=>Z.implements.find(W=>W.id===pe["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 ${pe["built-in-base-entity"].BUILT_IN_SQL_ROW_TRANSFORMER_ENTITY.id} with id ${d.id}`);let q=x.defaultValue||null;if(!q){const Z=Pr.new(u);Z.parent=x.toReference(),Z.id=V.UUID.uuid(),q=ne(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 j0(d,u,i,a){const l=a||V.UUID.uuid(),c=V.UUID.uuid(),e={id:l,version:c,createdAt:(i==null?void 0:i.timestamp)||new Date().toISOString(),author:V.sessionAuthor,previousVersion:null,deleted:!1,name:u,deletable:!0,editable:!0,type:p.DefinitionEntity,allPropertiesImplement:null,additionalProperties:!1,additionalPropertiesDataType:null,codeName:null,description:null,static:d.static,abstract:!1,properties:[],methods:[],abstractMethods:[],extends:null,implements:[d.toJSON()],x:0,y:0,parent:d.project.toReference()};uH(d,i);const y=ne(e,d.project);return y.hydrateAncestors(),i==null||i.add(y,k.Added),y.addSelfToProject(i),y.addImplementation(d,i),y.setParent(d.project,i),y.initChildren(i),pH(y,i),y}function jw(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 cH(d,u,i,a=vr.OrDataTypeGroup){const l=[],c=[],e=[],y=[],T={id:V.UUID.uuid(),version:V.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||new Date().toISOString(),author:V.sessionAuthor,previousVersion:null,deleted:!1,deletable:!0,editable:!0,type:p.DataType,options:null,implementationChooseOne:!1,entity:d.toJSON(),isList:!1,asType:!1,andChildrenGroup:null,index:null,orChildrenGroup:null,staticEntities:null,interactiveEntities:null,actionEntities:null,like:!0,inferred:!1,parentRelationType:a,parent:u.toReference()},A=ne(T,d.project);return c.push(A),A.setParent(u,i),A.initChildren(i),i==null||i.add(A,k.Added),A.setEntity(d,i),A.addSelfToProject(i),{updated:C(l),added:C(c),removed:C(e),affected:C(y),self:A}}function Gw(d,u,i,a,l){var T,A,b,O,L,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 J=u.project.getBuiltIn(pe[p.PrimitiveEntity][re.Date].id);u.setEntity(J,a);break}else{const J=u.project.getBuiltIn(pe[p.PrimitiveEntity][re.String].id);u.setEntity(J,a);break}case"number":u.setEntity(u.project.getBuiltIn(pe[p.PrimitiveEntity][re.Number].id),a);break;case"boolean":u.setEntity(u.project.getBuiltIn(pe[p.PrimitiveEntity][re.Boolean].id),a);break;case"object":if(d===null){u.setEntity(u.project.getBuiltIn(pe[p.PrimitiveEntity][re.Null].id),a);break}else if(Array.isArray(d))if(u.metaSync({isList:!0},a),d.length>0){const J=d.slice(0,5).filter(z=>z!==void 0);if(J.every(z=>typeof z==typeof J[0])&&(typeof J[0]!="object"||J[0]===null))switch(typeof J[0]){case"string":u.setEntity(u.project.getBuiltIn(pe[p.PrimitiveEntity][re.String].id),a);break;case"number":u.setEntity(u.project.getBuiltIn(pe[p.PrimitiveEntity][re.Number].id),a);break;case"boolean":u.setEntity(u.project.getBuiltIn(pe[p.PrimitiveEntity][re.Boolean].id),a);break;case"object":u.setEntity(u.project.getBuiltIn(pe[p.PrimitiveEntity][re.Null].id),a);break}else{const z=[];let ce=!1;J.forEach(de=>{var me,Q,ye,Ie;if(Array.isArray(de)&&(ce=!0),typeof de=="object"&&!Array.isArray(de)&&de!==null){const Ee=G0(de,u.project,{...i,id:V.UUID.uuid()},a,l);Ee.hasCreated&&z.push((me=Ee.changeSet)==null?void 0:me.self),c.push(...(Q=Ee.changeSet)==null?void 0:Q.updated),e.push(...(ye=Ee.changeSet)==null?void 0:ye.added),y.push(...(Ie=Ee.changeSet)==null?void 0:Ie.removed)}});const ie=C(z);if(!ie.length&&!ce){J.forEach(de=>{const me={id:V.UUID.uuid(),version:V.UUID.uuid(),createdAt:(a==null?void 0:a.timestamp)||new Date().toISOString(),author:V.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=ne(me,u.project);switch(Q.setParent(u,a),Q.initChildren(a),a==null||a.add(Q,k.Added),Q.addSelfToProject(a),typeof de){case"string":Q.setEntity(Q.project.getBuiltIn(pe[p.PrimitiveEntity][re.String].id),a);break;case"number":Q.setEntity(Q.project.getBuiltIn(pe[p.PrimitiveEntity][re.Number].id),a);break;case"boolean":Q.setEntity(Q.project.getBuiltIn(pe[p.PrimitiveEntity][re.Boolean].id),a);break;case"object":Q.setEntity(Q.project.getBuiltIn(pe[p.PrimitiveEntity][re.Null].id),a);break}});break}else ie.length===1&&!ce?u.setEntity(ie[0],a):J.forEach(de=>{if(typeof de=="object"&&!Array.isArray(de)&&de!==null){const me=jw(Object.keys(de),u.project);if(me){const Q=cH(me||ie[0],u,a,vr.OrDataTypeGroup);c.push(...Q.updated),e.push(...Q.added),y.push(...Q.removed)}}else{const me={id:V.UUID.uuid(),version:V.UUID.uuid(),createdAt:(a==null?void 0:a.timestamp)||new Date().toISOString(),author:V.sessionAuthor,previousVersion:null,deleted:!1,deletable:!0,editable:!0,type:p.DataType,options:null,implementationChooseOne:!1,entity:null,isList:Array.isArray(de),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=ne(me,u.project);Q.setParent(u,a),Q.initChildren(a),a==null||a.add(Q,k.Added),Q.addSelfToProject(a);const ye=Gw(de,Q,{...i,id:V.UUID.uuid()},a,l);c.push(...ye.updated),e.push(...ye.added),y.push(...ye.removed)}})}}else{const J=G0(d[0],u.project,{...i},a,l);u.setEntity((T=J.changeSet)==null?void 0:T.self,a),c.push(...(A=J.changeSet)==null?void 0:A.updated),e.push(...(b=J.changeSet)==null?void 0:b.added),y.push(...(O=J.changeSet)==null?void 0:O.removed);break}else{const J=G0(d,u.project,{...i},a,l);u.setEntity((L=J.changeSet)==null?void 0:L.self,a),c.push(...(M=J.changeSet)==null?void 0:M.updated),e.push(...(x=J.changeSet)==null?void 0:x.added),y.push(...(q=J.changeSet)==null?void 0:q.removed);break}}return{updated:C(c),added:C(e),removed:C(y),affected:C(v),self:u}}function G0(d,u,i,a,l){const c=[],e=[],y=[],v=[],T=Object.keys(d),A=jw(T,u);if(A)return{hasCreated:!1,changeSet:{updated:[],added:[],removed:[],affected:[],self:A}};const b=l?i.name+" of "+l.name:i.name,L={id:i.id||V.UUID.uuid(),version:V.UUID.uuid(),createdAt:(a==null?void 0:a.timestamp)||new Date().toISOString(),author:V.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=ne(L,u);return M.setParent(u,a),M.initChildren(a),a==null||a.add(M,k.Added),M.addSelfToProject(a),e.push(M),T.forEach((x,q)=>{const W={id:V.UUID.uuid(),version:V.UUID.uuid(),createdAt:(a==null?void 0:a.timestamp)||new Date().toISOString(),author:V.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()},J=ne(W,u);J.setParent(M,a),J.initChildren(a),a==null||a.add(J,k.Added),J.addSelfToProject(a),e.push(J);const le=d[x],ce={id:V.UUID.uuid(),version:V.UUID.uuid(),createdAt:(a==null?void 0:a.timestamp)||new Date().toISOString(),author:V.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:J.toReference()},ie=ne(ce,u);ie.setParent(J,a),ie.initChildren(a),a==null||a.add(ie,k.Added),ie.addSelfToProject(a),e.push(ie);const de=Gw(le,ie,{...i,name:x,id:V.UUID.uuid()},a,l||M);c.push(...de.updated),e.push(...de.added),y.push(...de.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,A;return Array.isArray(v.implements)?v.implements.some(b=>!!c.implements.find(O=>O.id===b.id)):((T=v.implements)==null?void 0:T.id)===((A=c.implements)==null?void 0:A.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 A,b;return T.implements&&Array.isArray(T.implements)?T.implements.some(O=>!!c.implements.find(L=>L.id===O.id)):((A=T.implements)==null?void 0:A.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(A=>A.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 nNe(d,u){return d.abstract||(d.properties.forEach(a=>{a.abstract||a.metaSync({abstract:!0},u)}),Object.values(d.detachedDependents).forEach(a=>{a.field===sA.Entity&&a.entity.remove({ignoreUpstream:!1},u)}),d.metaSync({abstract:!0},u)),d}function sNe(d,u){return d.abstract&&(d.properties.forEach(a=>{a.abstract&&a.metaSync({abstract:!1},u)}),Object.values(d.detachedDependents).forEach(a=>{(a.field===nv.Implements||a.field===nv.Extends)&&a.entity.onDetachedDependencyRemoved(d,a.field,u)}),d.metaSync({abstract:!1},u)),d}function aNe(d,u){return d.static||(d.properties.forEach(a=>{a.static||a.metaSync({static:!0},u)}),d.metaSync({static:!0},u)),d}function lNe(d,u){return d.static&&d.metaSync({static:!1},u),d}var hn=(d=>(d.StringValueMustNotHaveSpaces="string-value-must-not-have-spaces",d.StringValueMustNotHaveDashes="string-value-must-not-have-dashes",d.MustBeUniqueAmongSameEntities="must-be-unique-among-same-entities",d))(hn||{});function kw(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 fH(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 Fw(d,u){var i;if(d.type===p.LiteralValue){let a=(i=d.value)==null?void 0:i.toString();try{a=JSON.stringify(d.value,null,2)}catch{}return`${d.type}: ${d.id} (${S(d,u)}) = ${a}`}if(d.type===p.DataType){if(d instanceof Zr||d.increaseVersion)return`${d.type}: ${d.id} (${yp(d)})`;try{const a=yp(d);return`${d.type}: ${d.id} (${a})`}catch{}}return`${d.type}: ${d.id} (${S(d,u)})`}function sp(d,u){const i=Io(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=sp(c,u);return e.last&&(a=e.last),[c,...e.list]}),last:a}}function bo(d,u){const i=d.calledBy;if(i.length===0)return{list:[],last:null,callType:null};let a=null,l=null;return{list:i.flatMap(e=>{if(e===u)return a=e,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(!en.includes(e.type))return[e];const y=bo(e,u);return y.last&&(a=y.last,l=y.callType),[e,...y.list]}),last:a,callType:l}}function oNe(d,u){if(d===u)return"same-entity";if(!Gr.includes(d.type)||!py(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 dy(d){const u=Hr(d,d.project);return u?Gt.includes(u.type)?u:u.type===p.Loop?u.body:null:null}function Kw(d,u){const i=d.calledBy;return!i||!i.length?!1:i.every(a=>a===u?!0:en.includes(a.type)?!!bo(a,u).last:!1)}function yH(d){return d.filter(u=>{const i=dy(u);return!d.filter(c=>c!==u).some(c=>c===i?!1:K0(c,u))})}function qw(d){if(!d.calledBy||!d.calledBy.length)return[];const u=d.calledBy.reduce((i,a)=>{if(en.includes(a.type)){const l=qw(a);return[...i,a,...l]}return i},[]);return C(u)}function hH(d){const u=qw(d);if(!u.length)return{ancestor:null,callType:null};const a=u.filter(c=>!(c===d||!Gr.includes(c.type)||!ht(c).find(v=>v===d))).filter((c,e,y)=>y.findIndex(v=>v===c)===e).filter(c=>Kw(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 mH(d,u){if(!d)throw new Error("findNextSingleCallerAncestor: Target is not defined, cannot find ancestor.");let i=d;(d.type===p.VariableDeclaration||d.type===p.VariableInstance)&&!d.calledBy.length&&!d.successCalls.length&&!d.errorCalls.length&&d.internalCalls.some(O=>!!O.calledBy.length)&&(i=d.internalCalls.find(L=>!!L.calledBy.length));let a=u||Hr(i,d.project);if(!a)return{ancestor:null,callType:null};if(a.type===p.Project&&(a=hH(i).ancestor,!a))return{ancestor:null,callType:null};const l=py(a);if(!l.find(O=>O.callee===i))return{ancestor:null,callType:null};if(a.type===p.Loop){if(a.body.calls.includes(i))return{ancestor:a,callType:"loop-body"}}else if(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(O=>!(O.callee===i||!Gr.includes(O.callee.type)||!ht(O.callee).find(x=>x===i))).filter((O,L,M)=>M.findIndex(x=>x.callee===O.callee)===L);if(e.length===0)return{ancestor:null,callType:null};if(e.length===1){const O=e[0];if(O.callee.type===p.Loop){if(O.callee.body.calls.includes(i))return{ancestor:O.callee,callType:"loop-body"}}else{if(Gt.includes(O.callee.type))return O.callee.type===p.FunctionDeclaration&&O.callee.parent.type===p.Loop?{ancestor:O.callee,callType:"loop-body"}:{ancestor:O.callee,callType:"entry"};if(mi.includes(O.callee.type)){if(O.callType==="success"&&O.callee.type===p.InternalCall)return{ancestor:O.callee,callType:"success"};if(O.callType==="error"&&O.callee.type===p.InternalCall)return{ancestor:O.callee,callType:"error"}}}}const y=e.filter(O=>Kw(i,O.callee)),v=y.filter(O=>{const L=ht(O.callee),M=y.filter(q=>q.callee!==O.callee).map(q=>q.callee);return!L.some(q=>!!M.find(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(Er(a.successCalls).find(W=>W===i))return{ancestor:a,callType:"success"};if(Er(a.errorCalls).find(W=>W===i))return{ancestor:a,callType:"error"}}else if(mi.includes(a.type)){if(Er(a.successCalls).find(q=>q===i))return{ancestor:a,callType:"success"};if(Er(a.errorCalls).find(q=>q===i))return{ancestor:a,callType:"error"}}return a.parent.type===p.Loop?{ancestor:a,callType:"loop-body"}:{ancestor:a,callType:"entry"}}if(v.length>1)throw new Error(`findNextSingleCallerAncestor: Could not be resolved, multiple candidates found: ${v.map(O=>S(O.callee,i.project)).join(", ")}`);const T=v[0].callee,b=py(T).find(O=>O.callee===i);return{ancestor:T,callType:b.callType}}function dNe(d){if(![p.VariableDeclaration,p.OutputMap].includes(d.type))throw new Error("getEarliestSingleCallerAncestorOfValueWriterAndItsValueReaders can only be used with a value writer entity");let u;if(d.type===p.VariableDeclaration?u=d:d.type===p.OutputMap&&(u=d.parent),!u)throw new Error("getEarliestSingleCallerAncestorOfValueWriterAndItsValueReaders can only be used with a value writer entity that has a caller");const i=C([d,...k0(d),...$t.includes(d.type)?d.outputs.flatMap(y=>k0(y)):[]]),a=C(i.map(y=>Zw(y)).flatMap(y=>xt.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 A=Er(y.successCalls),b=Er(y.errorCalls);if(A.includes(u))return{ancestor:y,callType:"success"};if(b.includes(u))return{ancestor:y,callType:"error"}}const v=mH(y);if(!v.ancestor)throw new Error(`getEarliestSingleCallerAncestorOfValueWriterAndItsValueReaders: Could not be resolved, no ancestor found for ${S(y,u.project)}`);return v}).filter((y,v,T)=>v===T.findIndex(A=>{var b,O;return((b=A.ancestor)==null?void 0:b.id)===((O=y.ancestor)==null?void 0:O.id)})),c=dy(u),e=l.filter(y=>y!=null&&y.ancestor?c===y.ancestor?!0:!l.filter(A=>A.ancestor!==y.ancestor).map(A=>A.ancestor).some(A=>{const b=bo(y.ancestor,A);return!!(b!=null&&b.last)}):!1);if(e.length===0)return{ancestor: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 vH(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:yH(l).length>1&&l.includes(u)?!1:l.every(e=>d===u?!0:Gt.includes(e.type)?!1:vH(e,u))}function TH(d){const u=[];let i=d.calledBySuccess;i=i.filter(l=>!i.filter(y=>y!==l).some(y=>K0(y,l)));let a=d.calledByError;a=a.filter(l=>!a.filter(y=>y!==l).some(y=>K0(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 EH(d){const u=[];return TH(d).forEach(a=>{a.ancestor.type===p.Condition&&u.push({condition:a.ancestor,call:d,callType:a.callType});const c=EH(a.ancestor).filter(e=>!u.some(y=>y.condition.id===e.condition.id));u.push(...c)}),u}function Zw(d){if(!d)return null;if(d.type===p.Condition&&d.parent.type===p.Condition)return q0(d.parent);if(QT.includes(d.type))return d;const u=d.parent;return u?Zw(u):null}function k0(d,u=new Set){return d.writesValues.reduce((i,a)=>u.has(a.id)?i:(u.add(a.id),Xn.includes(a.type)?[...i,a]:Qi.includes(a.type)?[...i,a,...k0(a,u)]:i),[])}function uy(d){const u=d.calledBy;if(u.length===0)return d.project;const i=u.reduce((a,l)=>{const c=Hr(l,d.project);return!c||c.type===p.Project?a:a.type===p.Project||sp(c,a).last?c:(sp(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=uy(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&&!Xi.includes(i.type)){d.remove({ignoreUpstream:!1},u);return}else if($t.includes(d.type)){const l=d.usedInternalCalls[0];if(l)if(i=uy(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(xt.includes(d.type))return;ht(d).forEach(l=>{let c=uy(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&&!Xi.includes(c.type)){l.remove({ignoreUpstream:!1},u);return}else if($t.includes(l.type)){const e=l.usedInternalCalls[0];if(e)if(c=uy(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 F0(d,u,i=new Set){const a=ia(d),l=ia(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,...F0(T,u,i)])),[]);return C([...e,...y])}function gd(d,u){const i=sp(d,u);return i.last===u&&i.list.length>0&&i.list[0]!==u}function Ww(d,u){return!!sp(d,u).last}function K0(d,u){return!!bo(d,u).last}function Hw(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 Hw(i,a)}function uNe(d,u,i=!0){if(!d||!u)throw new Error("Both entities must be defined to find a common ancestor");if(d===u)return{ancestor:d,callType:"same-entity"};if(en.includes(d.type)&&Gr.includes(u.type)){const y=bo(d,u),v=y.last;if(v){if(v===u)return{ancestor:u,callType:y.callType}}else return{ancestor:null,callType:null}}if(en.includes(u.type)&&Gr.includes(d.type)){const y=bo(u,d),v=y.last;if(v){if(v===d)return{ancestor:d,callType:y.callType}}else return{ancestor:null,callType:null}}const a=dy(d),l=dy(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(!Gr.includes(v.type))return y;const T=py(v),A=T.find(O=>O.callee===d),b=T.find(O=>O.callee===u);return A&&b&&(!i||A.callType===b.callType)?[...y,{ancestor:v,callType:A.callType}]:y},[]);if(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&&bo(y.ancestor,v.ancestor).last===v.ancestor));return e.length===1?{ancestor:e[0].ancestor,callType:e[0].callType}:{ancestor:a,callType:"entry"}}function Pi(d){if(sc.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 ap(d,u){const i=lp(d,u);if(!i)return null;if(sc.includes(i.type)){if(i.type===p.FunctionDeclaration){const a=lp(i.parent,u);if(a){if(a.type===p.DefinitionEntity)return a;if(a.type===p.Loop)return a}}if(i.parent){const a=lp(i.parent,u);if(a&&(i.type===p.DefinitionEntity&&a.type===p.DataType||i.type===p.Condition&&a.type===p.Condition))return ap(a,u)}return i}else{const a=i.parent?lp(i.parent,u):null;return a?ap(a,u):null}}function py(d){if(d.type===p.Loop){const u=[...Er(d.successCalls).map(l=>({callee:l,callType:"success"})),...Er(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=[...Er(d.successCalls).map(l=>({callee:l,callType:"success"})),...Er(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=[...Er(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 q0(d){if(!d)return null;if(d.type===p.Condition&&d.parent.type===p.Condition)return q0(d.parent);if(en.includes(d.type))return d;const u=d.parent;return u?q0(u):null}function bH(d){if(!d)return null;if(mi.includes(d.type))return d;const u=d.parent;return u?bH(u):null}function IH(d){if(!d)return null;if(Gr.includes(d.type))return d;const u=d.parent;return u?IH(u):null}function pNe(d){return d.type===p.VariableDeclaration?[d]:mi.includes(d.type)?[...d.inputs,...d.outputs||[]]:xt.includes(d.type)?d.outputs:Fo.includes(d.type)||d.type===p.FunctionDeclaration?d.inputs:[]}function cNe(d){const u=ia(d),i=[],a=[];Pg.includes(d.type)&&i.push(...Z0(d));const l=u.filter(c=>{const e=i.includes(c);return e?!1:en.includes(c.type)&&!e?(a.push(c),!1):!0});return i.sort((c,e)=>gd(e,c)?-1:0),a.sort((c,e)=>gd(e,c)?-1:0),[...i,...a,...l]}function AH(d){return[...d].sort((u,i)=>gd(i,u)?-1:0)}function fNe(d){const u=AH(d),i=[];return u.forEach(a=>{const l=i[i.length-1];if(l){const c=l[l.length-1];gd(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 Z0(d){return mi.includes(d.type)?[...El(d.successCalls),...El(d.errorCalls)]:Gt.includes(d.type)?El(d.calls):[]}function yNe(d,u){return Z0(d).includes(u)}function W0(d){return d.writesValues||[]}function hNe(d,u){return W0(d).includes(u)}function wH(d){var u;return $t.includes((u=d==null?void 0:d.readsValue)==null?void 0:u.type)?d.readsValue:null}function mNe(d){return d.writesValues}function RH(d=[]){return d.map(wH).filter(u=>!!u)}function H0(d=[]){return d.map(u=>u.writesValues).flat().filter(u=>$t.includes(u.type))}function CH(d=[]){return d.map(u=>u.readsValue).filter(u=>!!u&&$t.includes(u.type))}function gH(d){return $t.includes(d.type)?d:null}function _H(d){return d.writesValues.map(gH).filter(u=>!!u)}function DH(d=[]){return d.reduce((u,i)=>i.type===p.OutputMap?[...u,..._H(i)]:u,[])}function ht(d){return d.type===p.Loop?C([...Er(d.successCalls),...Er(d.errorCalls),...d.body?ht(d.body):[]]):mi.includes(d.type)?C([...Er(d.successCalls),...Er(d.errorCalls)]):Gt.includes(d.type)?C(Er(d.calls)):[]}function vNe(d){return mi.includes(d.type)?[...Er(d.successCalls),...Er(d.errorCalls)]:Gt.includes(d.type)?Er(d.calls):[]}function OH(d,u=new Set){return d.writesValues.filter(a=>$t.includes(a.type)&&!u.has(a.id)).reduce((a,l)=>u.has(l.id)?a:[...a,...Li(l,u)],[])}function PH(d,u=new Set){var a;return(((a=d.readsValue)==null?void 0:a.writesValues)||[]).filter(l=>$t.includes(l.type)&&!u.has(l.id)).reduce((l,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 CH(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)]},[]),...RH(d.inputs),...DH(d.outputs)].reduce((c,e)=>[...c,...Li(e,u)],[]);if(Fo.includes(d.type)){const i=H0(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=[...H0(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($t.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,...PH(d,u),...OH(d,u)]}return[]}function Fn(d,u=new Set){if(u.has(d.id))return[];u.add(d.id),Y.log("[flattenDerivedCanvasEntities]",d.type,S(d,d.project),d.id);const i=ia(d);return i.forEach(l=>{u.add(l.id)}),[...i.reduce((l,c)=>(Y.log("[Recursive -- flattenDerivedCanvasEntities]",c.type,S(c,c.project),c.id),[...l,c,...Fn(c,u)]),[])]}function Er(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 $H(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,...H0(T.inputs),...Er(El(T.calls)),...T.returnStatements],[]),e=d.functions.reduce((v,T)=>[...v,...Er(El(T.calls)),...T.returnStatements],[]),y=d.events.reduce((v,T)=>[...v,...Er(El(T.calls)),...T.returnStatements],[]);return[...i,...a,...l,...c,...e,...y]}function NH(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)?aJ(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 TNe(d){const u=$H(d.project);return NH(d,u)}function lp(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 VH(d={},u){const i={};return Object.keys(d).forEach(a=>{const l=u.get(a)||a,c=d[a];i[l]=c}),i}function op(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,A=d,b=d,O=d,L=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),...L.parent?[L.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)):O.extends&&Z.push(O.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 ce=te(z);if(ce&&u[ce]){const ie=u[ce];[...ie.calledByEntry||[],...ie.calledBySuccess||[],...ie.calledByError||[]].forEach(de=>{const me=te(de);me&&u[me]&&Z.push(u[me])})}});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),...A.error?[A.error]:[],...L.throws?[L.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 ce=te(z);if(ce&&u[ce]){const ie=u[ce];[...ie.successCalls||[],...ie.errorCalls||[]].forEach(de=>{const me=te(de);me&&u[me]&&W.push(u[me])})}});const J={},le={};return Z.forEach(z=>{var de;const ce=te(z);if(ce&&a.ignoreBuiltInBaseEntities&&(vn.includes(z.type)||(a.allBuiltInEntityIds||[]).includes(ce)))return;const ie=z.version;if(ce){const me=((de=a.entityMaps)==null?void 0:de.get(ce))||ce;J[me]=ie}}),W.forEach(z=>{var de;const ce=te(z);if(ce&&a.ignoreBuiltInBaseEntities&&(vn.includes(z.type)||(a.allBuiltInEntityIds||[]).includes(ce)))return;const ie=z.version;if(ce){const me=((de=a.entityMaps)==null?void 0:de.get(ce))||ce;le[me]=ie}}),{upstream:J,downstream:le}}function ENe(d,u){const i=[];if(en.includes(d.type)){os(d).forEach(c=>{const e=ap(c,u);e&&i.push(e)});const l=[...d.inputs||[],...d.outputs||[]].map(c=>{const e=lp(c,u);return e?lJ(e,u):null}).filter(c=>c!==null);i.push(...C(l))}if($t.includes(d.type)){const a=J0(d);a&&i.push(a)}return C(i)}function Io(d){const u=[];if(en.includes(d.type)){d.calledBy.forEach(l=>{const c=Pi(l);c&&u.push(c)});const a=[...d.inputs||[],...d.outputs||[]].map(l=>J0(l)).filter(l=>l!==null);u.push(...C(a))}if(Xn.includes(d.type)){const i=J0(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 LH(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==p.ActionDescriptor)throw new Error("Entity must be an action descriptor to be flattened");return[d,...d.inputs.flatMap(a=>Te(a,u,i)),...d.dataType?Te(d.dataType,u,i):[],...d.error?Te(d.error,u,i):[],...d.parent?Te(d.parent,u,i):[]]}function BH(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==p.ArgumentDeclaration)throw new Error("Entity must be an argument declaration to be flattened");return[d,...d.defaultValue?Te(d.defaultValue,u):[],...d.writesValues.flatMap(a=>Te(a,u,i)),...d.dataType?Te(d.dataType,u,i):[],...d.parent?Te(d.parent,u,i):[]]}function MH(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==p.BreakStatement)throw new Error("Entity must be a break statement to be flattened");return[d,...d.outputs.flatMap(a=>Te(a,u,i)),...d.throws?Te(d.throws,u,i):[],...d.implements?Te(d.implements,u,i):[],...d.dataType?Te(d.dataType,u,i):[],...d.readsValue?Te(d.readsValue,u,i):[],...(os(d)||[]).flatMap(a=>Te(a,u,i)),...d.parent?Te(d.parent,u,i):[]]}function xH(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==p.BuiltInBaseEntity)throw new Error("Entity must be a built-in base entity to be flattened");return[d,...(d.properties||[]).flatMap(a=>Te(a,u,i)),...(d.methods||[]).flatMap(a=>Te(a,u,i)),...(d.abstractMethods||[]).flatMap(a=>Te(a,u,i)),...d.allPropertiesImplement?Te(d.allPropertiesImplement,u,i):[],...d.additionalPropertiesDataType?Te(d.additionalPropertiesDataType,u,i):[],...d.extends?Te(d.extends,u,i):[]]}function UH(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==p.Condition)throw new Error("Entity must be a condition to be flattened");return[d,...(d.andChildrenGroup||[]).flatMap(a=>Te(a,u,i)),...(d.orChildrenGroup||[]).flatMap(a=>Te(a,u,i)),...(d.inputs||[]).flatMap(a=>Te(a,u,i)),...(d.successCalls||[]).flatMap(a=>Te(a,u,i)),...(d.errorCalls||[]).flatMap(a=>Te(a,u,i)),...(os(d)||[]).flatMap(a=>Te(a,u,i)),...d.parent?Te(d.parent,u,i):[]]}function jH(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==p.ContinueStatement)throw new Error("Entity must be a continue statement to be flattened");return[d,...d.outputs.flatMap(a=>Te(a,u,i)),...d.readsValue?Te(d.readsValue,u,i):[],...d.implements?Te(d.implements,u,i):[],...d.throws?Te(d.throws,u,i):[],...d.dataType?Te(d.dataType,u,i):[],...(os(d)||[]).flatMap(a=>Te(a,u,i)),...d.parent?Te(d.parent,u,i):[]]}function GH(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==p.DefinitionEntity)throw new Error("Entity must be a definition entity to be flattened");return[d,...d.extends?Te(d.extends,u,i):[],...(d.implements||[]).flatMap(a=>Te(a,u,i)),...(d.properties||[]).flatMap(a=>Te(a,u,i)),...(d.methods||[]).flatMap(a=>Te(a,u,i)),...(d.abstractMethods||[]).flatMap(a=>Te(a,u,i)),...d.allPropertiesImplement?Te(d.allPropertiesImplement,u,i):[],...d.additionalPropertiesDataType?Te(d.additionalPropertiesDataType,u,i):[],...d.parent?Te(d.parent,u,i):[]]}function kH(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==p.DataType)throw new Error("Entity must be a data type to be flattened");return[d,...(d.andChildrenGroup||[]).flatMap(a=>Te(a,u,i)),...(d.orChildrenGroup||[]).flatMap(a=>Te(a,u,i)),...d.entity?Te(d.entity,u,i):[],...d.parent?Te(d.parent,u,i):[]]}function FH(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==p.FunctionCall)throw new Error("Entity must be a function call to be flattened");return[d,...(d.inputs||[]).flatMap(a=>Te(a,u,i)),...(d.outputs||[]).flatMap(a=>Te(a,u,i)),...d.error?Te(d.error,u,i):[],...(os(d)||[]).flatMap(a=>Te(a,u,i)),...(d.successCalls||[]).flatMap(a=>Te(a,u,i)),...(d.errorCalls||[]).flatMap(a=>Te(a,u,i)),...(d.writesValues||[]).flatMap(a=>Te(a,u,i)),...d.parent?Te(d.parent,u,i):[]]}function KH(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==p.FunctionDeclaration)throw new Error("Entity must be a function declaration to be flattened");return[d,...(d.inputs||[]).flatMap(a=>Te(a,u,i)),...(d.calls||[]).flatMap(a=>Te(a,u,i)),...d.implements?Te(d.implements,u,i):[],...d.parent?Te(d.parent,u,i):[]]}function qH(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==p.GlobalEvent)throw new Error("Entity must be a global event to be flattened");return[d,...(d.inputs||[]).flatMap(a=>Te(a,u,i)),...(d.calls||[]).flatMap(a=>Te(a,u,i)),...d.implements?Te(d.implements,u,i):[],...d.parent?Te(d.parent,u,i):[]]}function ZH(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==p.InputMap)throw new Error("Entity must be an input map to be flattened");return[d,...d.readsValue?Te(d.readsValue,u,i):[],...d.declaration?Te(d.declaration,u,i):[],...d.defaultValue?Te(d.defaultValue,u,i):[],...d.parent?Te(d.parent,u,i):[]]}function WH(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==p.InstalledProject)throw new Error("Entity must be an installed project to be flattened");return[d,...(d.functions||[]).flatMap(a=>Te(a,u,i)),...(d.events||[]).flatMap(a=>Te(a,u,i)),...d.parent?Te(d.parent,u,i):[]]}function HH(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==p.InternalCall)throw new Error("Entity must be an internal call to be flattened");return[d,...(d.successCalls||[]).flatMap(a=>Te(a,u,i)),...(d.errorCalls||[]).flatMap(a=>Te(a,u,i)),...(d.inputs||[]).flatMap(a=>Te(a,u,i)),...(d.outputs||[]).flatMap(a=>Te(a,u,i)),...(os(d)||[]).flatMap(a=>Te(a,u,i)),...d.error?Te(d.error,u,i):[],...(d.writesValues||[]).flatMap(a=>Te(a,u,i)),...d.parent?Te(d.parent,u,i):[]]}function JH(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==p.LiteralValue)throw new Error("Entity must be a literal value to be flattened");return[d,...d.valueAsTypeSingle?Te(d.valueAsTypeSingle,u,i):[],...d.valueAsTypeList&&Array.isArray(d.valueAsTypeList)?d.valueAsTypeList.flatMap(a=>Te(a,u,i)):[],...d.parent?Te(d.parent,u,i):[]]}function zH(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==p.Loop)throw new Error("Entity must be a loop to be flattened");return[d,...(d.inputs||[]).flatMap(a=>Te(a,u,i)),...(d.outputs||[]).flatMap(a=>Te(a,u,i)),...(d.successCalls||[]).flatMap(a=>Te(a,u,i)),...(d.errorCalls||[]).flatMap(a=>Te(a,u,i)),...d.error?Te(d.error,u,i):[],...d.dataType?Te(d.dataType,u,i):[],...d.body?Te(d.body,u,i):[],...(os(d)||[]).flatMap(a=>Te(a,u,i)),...(d.writesValues||[]).flatMap(a=>Te(a,u,i)),...d.parent?Te(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.Operation)throw new Error("Entity must be an operation to be flattened");return[d,...(d.successCalls||[]).flatMap(a=>Te(a,u,i)),...(d.errorCalls||[]).flatMap(a=>Te(a,u,i)),...(d.inputs||[]).flatMap(a=>Te(a,u,i)),...(d.outputs||[]).flatMap(a=>Te(a,u,i)),...(d.writesValues||[]).flatMap(a=>Te(a,u,i)),...d.error?Te(d.error,u,i):[],...(os(d)||[]).flatMap(a=>Te(a,u,i)),...d.parent?Te(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.OutputMap)throw new Error("Entity must be an output map to be flattened");return[d,...(d.writesValues||[]).flatMap(a=>Te(a,u,i)),...d.declaration?Te(d.declaration,u,i):[],...d.parent?Te(d.parent,u,i):[]]}function XH(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==p.PrimitiveEntity)throw new Error("Entity must be a primitive entity to be flattened");return[d,...(d.properties||[]).flatMap(a=>Te(a,u,i)),...(d.methods||[]).flatMap(a=>Te(a,u,i)),...(d.abstractMethods||[]).flatMap(a=>Te(a,u,i))]}function QH(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==p.Project)throw new Error("Entity must be a project to be flattened");return[d,...(d.entities||[]).flatMap(a=>Te(a,u,i)),...(d.functions||[]).flatMap(a=>Te(a,u,i)),...(d.events||[]).flatMap(a=>Te(a,u,i)),...(d.projects||[]).flatMap(a=>Te(a,u,i)),...(d.variableDeclarations||[]).flatMap(a=>Te(a,u,i)),...(d.variableInstances||[]).flatMap(a=>Te(a,u,i)),...(d.operations||[]).flatMap(a=>Te(a,u,i)),...(d.conditions||[]).flatMap(a=>Te(a,u,i)),...(d.functionCalls||[]).flatMap(a=>Te(a,u,i)),...(d.projects||[]).flatMap(a=>Te(a,u,i)),...(d.loops||[]).flatMap(a=>Te(a,u,i)),...(d.searches||[]).flatMap(a=>Te(a,u,i))]}function eJ(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==p.Property)throw new Error("Entity must be a property to be flattened");return[d,...d.defaultValue?Te(d.defaultValue,u,i):[],...d.dataType?Te(d.dataType,u,i):[],...d.parent?Te(d.parent,u,i):[]]}function tJ(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==p.ReturnStatement)throw new Error("Entity must be a return statement to be flattened");return[d,...(d.outputs||[]).flatMap(a=>Te(a,u,i)),...d.throws?Te(d.throws,u,i):[],...d.implements?Te(d.implements,u,i):[],...d.readsValue?Te(d.readsValue,u,i):[],...d.dataType?Te(d.dataType,u,i):[],...(os(d)||[]).flatMap(a=>Te(a,u,i)),...d.parent?Te(d.parent,u,i):[]]}function iJ(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==p.Search)throw new Error("Entity must be a search to be flattened");return[d,...(d.successCalls||[]).flatMap(a=>Te(a,u,i)),...(d.errorCalls||[]).flatMap(a=>Te(a,u,i)),...(d.inputsDeclarations||[]).flatMap(a=>Te(a,u,i)),...(d.inputs||[]).flatMap(a=>Te(a,u,i)),...(d.writesValues||[]).flatMap(a=>Te(a,u,i)),...(d.outputs||[]).flatMap(a=>Te(a,u,i)),...d.error?Te(d.error,u,i):[],...d.dataType?Te(d.dataType,u,i):[],...(os(d)||[]).flatMap(a=>Te(a,u,i)),...d.parent?Te(d.parent,u,i):[]]}function rJ(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==p.ValueDescriptor)throw new Error("Entity must be a value descriptor to be flattened");return[d,...d.defaultValue?Te(d.defaultValue,u,i):[],...d.dataType?Te(d.dataType,u,i):[],...d.parent?Te(d.parent,u,i):[]]}function nJ(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==p.VariableDeclaration)throw new Error("Entity must be a variable declaration to be flattened");return[d,...(d.successCalls||[]).flatMap(a=>Te(a,u,i)),...(d.errorCalls||[]).flatMap(a=>Te(a,u,i)),...(d.inputs||[]).flatMap(a=>Te(a,u,i)),...(d.outputs||[]).flatMap(a=>Te(a,u,i)),...(d.internalCalls||[]).flatMap(a=>Te(a,u,i)),...(d.writesValues||[]).flatMap(a=>Te(a,u,i)),...d.readsValue?Te(d.readsValue,u,i):[],...d.defaultValue?Te(d.defaultValue,u,i):[],...(os(d)||[]).flatMap(a=>Te(a,u,i)),...d.dataType?Te(d.dataType,u,i):[],...d.parent?Te(d.parent,u,i):[]]}function sJ(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==p.VariableInstance)throw new Error("Entity must be a variable instance to be flattened");return[d,...(d.successCalls||[]).flatMap(a=>Te(a,u,i)),...(d.errorCalls||[]).flatMap(a=>Te(a,u,i)),...(d.inputs||[]).flatMap(a=>Te(a,u,i)),...(d.outputs||[]).flatMap(a=>Te(a,u,i)),...(d.internalCalls||[]).flatMap(a=>Te(a,u,i)),...(d.writesValues||[]).flatMap(a=>Te(a,u,i)),...d.readsValue?Te(d.readsValue,u,i):[],...d.defaultValue?Te(d.defaultValue,u,i):[],...(os(d)||[]).flatMap(a=>Te(a,u,i)),...d.declaration?Te(d.declaration,u,i):[],...d.parent?Te(d.parent,u,i):[]]}function Kn(){const d=new Set;return dk.flatMap(i=>Te(i,d)).map(i=>i.id)}function Te(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(!d)throw new Error("Entity must be defined to be flattened");if(d.type===p.GenericReference)return[];if(i.ignoreBuiltInBaseEntities&&(vn.includes(d.type)||Kn().includes(d.id)))return[];if(u.has(d.id))return[];switch(d.type){case p.FunctionCall:return FH(d,u,i);case p.Operation:return YH(d,u,i);case p.Condition:return UH(d,u,i);case p.Loop:return zH(d,u,i);case p.Search:return iJ(d,u,i);case p.GlobalEvent:return qH(d,u,i);case p.ReturnStatement:return tJ(d,u,i);case p.ContinueStatement:return jH(d,u,i);case p.BreakStatement:return MH(d,u,i);case p.VariableDeclaration:return nJ(d,u,i);case p.DefinitionEntity:return GH(d,u,i);case p.FunctionDeclaration:return KH(d,u,i);case p.Project:return QH(d,u,i);case p.ActionDescriptor:return LH(d,u,i);case p.ArgumentDeclaration:return BH(d,u,i);case p.ValueDescriptor:return rJ(d,u,i);case p.InputMap:return ZH(d,u,i);case p.OutputMap:return SH(d,u,i);case p.DataType:return kH(d,u,i);case p.InstalledProject:return WH(d,u,i);case p.InternalCall:return HH(d,u,i);case p.LiteralValue:return JH(d,u,i);case p.Property:return eJ(d,u,i);case p.VariableInstance:return sJ(d,u,i);case p.BuiltInBaseEntity:return i.ignoreBuiltInBaseEntities?[]:xH(d,u,i);case p.PrimitiveEntity:return i.ignoreBuiltInBaseEntities?[]:XH(d,u,i)}return[]}function Jw(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||Fo.includes(d.type)?d.inputs:d.type===p.Search?d.inputsDeclarations:[]}function bNe(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 aJ(d){return mi.includes(d.type)?d.inputs:[]}function INe(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 xt.includes(d.type)?d.outputs.map(i=>i.declaration).filter(i=>!!i)||[]:[]}function ANe(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 wNe(d){return d.type===p.Condition?[]:mi.includes(d.type)?d.outputs:[]}function J0(d){const u=d.readsValue;return u?Pi(u):null}function lJ(d,u){const i=d.readsValue;return i?ap(i,u):null}function oJ(d){const u=d.internalCalls||[];return C(El(C(u.flatMap(i=>[...i.successCalls,...i.errorCalls]))))}function dJ(d){const u=d.internalCalls||[];return C(C(u.flatMap(i=>[...i.successCalls,...i.errorCalls])))}function dp(d){const u=W0(d),i=[];return u.forEach(a=>{if(sc.includes(a.type))i.push(a);else if(Xn.includes(a.type)){const l=Pi(a.parent);i.push(l)}}),i}function up(d){const u=W0(d),i=[];return u.forEach(a=>{if($t.includes(a.type))i.push(a);else if(Xn.includes(a.type)){const l=a.parent;i.push(l)}}),i}function C(d){const u=new Set;return d.filter(i=>!i||u.has(i.id)?!1:(u.add(i.id),!0))}function uJ(d){return d.type===p.Project?null:QT.includes(d.type)?d:vn.includes(d.type)?null:d.parent?uJ(d.parent):null}function ia(d,u=!1){Y.log("[getRelatedCanvasElementsOnTheRight]",d.type,S(d,d.project),d.id);const i=[];if(d.type===p.Project&&i.push(...(d==null?void 0:d.entities)||[],...(d==null?void 0:d.functions)||[],...(d==null?void 0:d.variableDeclarations)||[],...(d==null?void 0:d.variableInstances)||[],...(d==null?void 0:d.searches)||[],...(d==null?void 0:d.loops)||[],...(d==null?void 0:d.operations)||[],...(d==null?void 0:d.conditions)||[],...(d==null?void 0:d.functionCalls)||[],...(d==null?void 0:d.events)||[],...(d==null?void 0:d.projects)||[]),Xi.includes(d.type)&&i.push(...(d==null?void 0:d.detachedChildren)||[]),d.type===p.DefinitionEntity){const a=[...d.suggestedMethods,...d.methods].flatMap(l=>l.collapsed&&u?[]:(Y.log("[Recursive -- getRelatedCanvasElementsOnTheRight]",l.type,S(l,l.project),l.id),ia(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(Fo.includes(d.type)){if(d.collapsed&&u)return[];const a=d.inputs.map(c=>dp(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=>dp(e)).flat(),l=d.successCalls.map(e=>Pi(e)),c=d.errorCalls.map(e=>Pi(e));i.push(...C(a),...l,...c)}if($t.includes(d.type)){const a=dp(d),l=oJ(d);i.push(...a,...l)}if(Qi.includes(d.type)){const a=dp(d);i.push(...a)}if(d.type===p.Loop){if(d.body){const c=ia(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=>dp(c)).flat(),l=d.calls.map(c=>Pi(c));i.push(...C(a),...l)}return C(i)}function z0(d,u=!1){const i=[];if(d.type===p.Project&&i.push(...(d==null?void 0:d.variableDeclarations)||[],...(d==null?void 0:d.variableInstances)||[],...(d==null?void 0:d.searches)||[],...(d==null?void 0:d.loops)||[],...(d==null?void 0:d.operations)||[],...(d==null?void 0:d.conditions)||[],...(d==null?void 0:d.functionCalls)||[]),Xi.includes(d.type)&&i.push(...(d==null?void 0:d.detachedChildren)||[]),d.type===p.DefinitionEntity){const a=[...d.suggestedMethods,...d.methods].flatMap(l=>l.collapsed&&u?[]:z0(l));i.push(...a)}if(d.type===p.Condition){const a=d.successCalls,l=d.errorCalls;i.push(...a,...l)}if(Fo.includes(d.type)){if(d.collapsed&&u)return[];const a=d.inputs.map(c=>up(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=>up(e)).flat(),l=d.successCalls,c=d.errorCalls;i.push(...C(a),...l,...c)}if($t.includes(d.type)){const a=up(d),l=dJ(d);i.push(...a,...l)}if(d.type===p.Loop){const a=d.outputs.map(e=>up(e)).flat();if(d.body){const e=z0(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=>up(c)).flat(),l=d.calls;i.push(...C(a),...l)}return C(i)}function Y0(d,u=!1){const i=ia(d,u),a=[...i,...i.reduce((l,c)=>[...l,...Y0(c,u)],[])];return C(a)}function pJ(d,u=!1){const i=z0(d,u),a=[...i,...i.reduce((l,c)=>[...l,...pJ(c,u)],[])];return C(a)}function cy(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,...cy(i),...Ao(i)]:(i==null?void 0:i.type)===p.BuiltInBaseEntity?[i==null?void 0:i.name,...Ao(i)]:[...u],[])}function Ao(d){var u;if(!d)throw new Error("[flattenDefinitionEntityExtensionTypes] Entity must be defined to flatten extension types");if(d.extends){if(((u=d.extends)==null?void 0:u.type)===p.DefinitionEntity)return[p.DefinitionEntity,...Ao(d.extends),...cy(d.extends)];if(d.extends.type===p.BuiltInBaseEntity)return[d.extends.name,...Ao(d.extends)]}return[]}function fy(d){var u,i;return d.extends?((u=d.extends)==null?void 0:u.type)===p.DefinitionEntity?[d.extends,...fy(d.extends),...zw(d.extends)]:((i=d.extends)==null?void 0:i.type)===p.BuiltInBaseEntity?[d.extends,...fy(d.extends)]:[]:[]}function zw(d){return d.implements.reduce((u,i)=>i.type===p.DefinitionEntity?[...u,i,...zw(i),...fy(i)]:(i==null?void 0:i.type)===p.BuiltInBaseEntity?[i,...fy(i)]:[...u,i],[])}function pp(d){return[...Ao(d),...cy(d)].filter((i,a,l)=>l.indexOf(i)===a)}function cr(d,u){if(!d)throw new Error("checkHasBaseEntity: entity is null or undefined");if(d.type!==p.DefinitionEntity&&d.type!==p.BuiltInBaseEntity)throw new Error(`checkHasBaseEntity: entity is not a '${p.DefinitionEntity}' or '${p.BuiltInBaseEntity}', got ${d.type}`);return d.type===p.BuiltInBaseEntity?!!(d.name===u||[...Ao(d)].includes(u)):!!pp(d).includes(u)}function cJ(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 fJ(d){const u=Io(d),i=[...u,...u.reduce((a,l)=>[...a,...fJ(l)],[])];return C(i)}function Yw(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=Yw(l);if(c)return c}return a},null)}function RNe(d){return d.extends&&d.extends.type===p.BuiltInBaseEntity?d.extends:null}function CNe(d){const u=d.implements.find(i=>i.type===p.BuiltInBaseEntity);return u&&u.type===p.BuiltInBaseEntity?u:null}function S0(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 yy(d){return d.type===p.PrimitiveEntity?!0:d.type===p.BuiltInBaseEntity?d.interactive:!sn(d).find(a=>!a.interactive)}function gNe(d){return d.parent===d.project&&d.project.variableDeclarations.includes(d)}function Sw(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 yJ(d){if([...Gt,p.DefinitionEntity,p.InstalledProject,p.Project].includes(d.type)||Sw(d))return!1;const u=Io(d);return u.length===0?!0:u.some(i=>yJ(i))}function Xw(d){return[...Gt,p.DefinitionEntity,p.InstalledProject,p.Project].includes(d.type)||Sw(d)?!1:Io(d).length===0}function hJ(d,u=0){if(Xw(d)){const i=Io(d);return i.length===0?d:i.map(l=>hJ(l,u+1)).reduce((l,c)=>l?c&&c.x<l.x?c:l:c,null)}return null}function mJ(d){const u=[];if(Xw(d))u.push(d);else return[];return Io(d).forEach(a=>{u.push(...mJ(a))}),u}function Qw(d){return d.type===p.FunctionDeclaration&&d.parent!==d.project&&!![p.DefinitionEntity,p.Loop,p.InstalledProject].includes(d.parent.type)}function _Ne(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 cp(d){switch(d){case p.DefinitionEntity:return Os;case p.FunctionDeclaration:return Ia;case p.VariableDeclaration:return lo;case p.VariableInstance:return ao;case p.FunctionCall:return Eo;case p.Operation:return eo;case p.Condition:return ro;case p.ReturnStatement:return cl;case p.Loop:return io;case p.Search:return oo;case p.InputMap:return ls;case p.OutputMap:return ta;case p.ArgumentDeclaration:return ns;case p.Property:return us;case p.InstalledProject:return uo;case p.Project:return V;case p.DataType:return Zr;case p.GlobalEvent:return to;case p.InternalCall:return po;case p.ValueDescriptor:return hl;case p.BuiltInBaseEntity:return Oa;case p.PrimitiveEntity:return Rn;case p.ActionDescriptor:return Ut;case p.LiteralValue:return Pr;case p.ContinueStatement:return fo;case p.BreakStatement:return co;default:return null}}function Hr(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?Hr(v,u,c):null}else return e===u?u:Hr(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 _d(d,u){if(vn.includes(d.type))return Y.warn(`getRootEntryPointScopeOwner is \`null\` because it was called with a built-in entity type: ${d.type}`),null;if(u.getBuiltIn(d.id))return Y.warn(`getRootEntryPointScopeOwner is \`null\` because it was called with a built-in entity: ${d.id}`),null;const i=mn(d.parent,u);return i?i===u?Xi.includes(d.type)?d:(Y.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:_d(i,u):(Y.warn(`getRootEntryPointScopeOwner is \`null\` because it was called with an entity that has no parent: ${d.id}`),null)}function X0(d,u,i){if(d===u||u===i||d===i||!d||!u)return!1;const a=Hr(u.parent,i);return a===i?!1:a===d?!0:X0(a,u,i)}var Q0=(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))(Q0||{});function Ds(d,u,i){const a=Hr(d,i),l=Hr(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(X0(a,l,i))return{compatible:!0,type:"b-in-a",commonAncestorScope:a};if(X0(l,a,i))return{compatible:!0,type:"a-in-b",commonAncestorScope:l};const y=Hw(a,l);return y===i?{compatible:!1,type:"parallel-in-project",commonAncestorScope:y}:y?{compatible:!1,type:"parallel-in-common-parent",commonAncestorScope:Hr(y,i)}:{compatible:!1,type:"parallel-in-project",commonAncestorScope:i}}function vJ(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=Hr(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=Hr(l.parent,i)}let c=Hr(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=Hr(c.parent,i)}return null}function TJ(d){return d.length===0?null:d.length===1?d[0]:d.reduce((i,a)=>{const l=vJ(i,a,a.project);return!l||l===a?i:a},d[0])}function mn(d,u){if(!d)return null;let i;return typeof d=="string"?i=d:d.type===p.GenericReference?i=te(d):i=d.id,i===u.id?u:u.get(i)}function wo(d){if(!d)return null;if(vn.includes(d.type))return d;if(d.type===p.Project)return null;if(d.project.getBuiltIn(d.id))return d;const u=d.parent;return!u||u.type===p.Project?null:wo(u)}function hy(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=_d(d,d.project);return l?(d.calledBySuccess.forEach(c=>{[...c.successCalls||[]].forEach(v=>{xt.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=hy(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=>{xt.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=hy(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=>{xt.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=hy(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 DNe(d){return sc.includes(d.type)?d.type===p.FunctionDeclaration?!Qw(d):!0:!1}function ONe(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 ev(d,u){return d.type===p.BuiltInBaseEntity?d.name===u:!!Ao(d).includes(u)}function PNe(d,u){return d.type===p.BuiltInBaseEntity?d.name===u:!!cy(d).includes(u)}function $Ne(d){const u=[];return d.entities.forEach(i=>{if(ev(i,fe.PERSISTED_ENTITY)){u.push(i);return}}),C(u)}function NNe(d){const u=[];return d.entities.forEach(i=>{if(ev(i,fe.RELATIONAL_DATABASE)){u.push(i);return}}),C(u)}function VNe(d){return d.type!==p.DefinitionEntity||d.abstract||!ev(d,fe.PERSISTED_ENTITY)?null:(d==null?void 0:d.properties.find(i=>i.implements.find(a=>a.id===pe[p.BuiltInBaseEntity][fe.PERSISTED_ENTITY].properties.primaryKey.id)&&!i.abstract))||null}function EJ(d){var a;const u=Yw(d);if(!u)return null;const i=u.properties.find(l=>l.implements.find(c=>c.id===pe[p.BuiltInBaseEntity][fe.PERSISTED_ENTITY].properties.database.id));return i?(a=i.getDefaultValue())==null?void 0:a.valueAsType:null}function fp(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===pe[p.BuiltInBaseEntity][fe.PERSISTED_ENTITY].properties.database.id)&&!a.abstract);return u.push(...i),u}function LNe(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===pe[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(!Bg.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 BNe(d){switch(d){case p.Project:return V;case p.InstalledProject:return uo;case p.DefinitionEntity:return Os;case p.FunctionDeclaration:return Ia;case p.GlobalEvent:return to;case p.VariableInstance:return ao;case p.VariableDeclaration:return lo;case p.InputMap:return ls;case p.OutputMap:return ta;case p.Condition:return ro;case p.Operation:return eo;case p.FunctionCall:return Eo;case p.ArgumentDeclaration:return ns;case p.PrimitiveEntity:return Rn;case p.DataType:return Zr;case p.Property:return us;case p.ActionDescriptor:return Ut;case p.ReturnStatement:return cl;case p.ContinueStatement:return fo;case p.BreakStatement:return co;case p.Loop:return io;case p.Search:return oo;case p.ValueDescriptor:return hl;case p.InternalCall:return po;case p.LiteralValue:return Pr}return null}function MNe(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=cp(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=cp(d.type);if(!l)return a;l.MUTABLE_META_PROPERTIES.forEach(c=>{["x","y","collapsed"].includes(c)||delete a[c]})}return a}function tv(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,...tv(a,u)]:[]}function xNe(d){const u=[],i=new Set;return[...d.listAdded,...d.listUpdated,...d.listAffected].forEach(a=>{const l=Pi(a);if(!l||i.has(l.id))return;const c=d.project.get(a.id);if(!c)throw new Error(`Could not find active version of entity ${a.id} in project, which is present in the change set.`);i.add(l.id),u.push(c)}),C(u)}function UNe(d){if(d.type===p.Condition)return null;if(d.type===p.Search)return d.project.getBuiltIn(pe["value-descriptor"][hh.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 bJ(d){const u=d.entities.filter(l=>!!l.implements.find(c=>c.id===pe["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===pe["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 eR(d,u){const i=Array.from(new Set([...u.getAllBuiltInIds(),...Kn()]));return!!(i.includes(d.id)||!tv(d,{...u.instances,...u.builtInInstances}).every(c=>!i.includes(c)))}function IJ(d){if(!d)return null;if(d.type===p.Project)return d.id;const u=d.parent;return u?IJ(u):d.id}function my(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=_d(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 tR(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=_d(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 jNe(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 iR(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=iR(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=iR(u.extends,d);if(e)return e}}return null}function Dd(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 Dd(d.implements);if(d.extends)return Dd(d.extends)}return d}function Il(d){var u;return!!(d.required||(u=d.declaration)!=null&&u.required)}function Ro(d){return f6(d)||d===void 0||d===""}function ds(d){return d?d.valueAsType?!1:Ro(d.value):!0}function vy(d){return d.replace(/["'`]/g,"")}function Bi(d){const i=vy(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 Od(d){return vy(d).split(/[\s-]+/).filter(a=>a.length>0).map(a=>a[0].toUpperCase()+a.slice(1)).join("")}function AJ(d){const u=vy(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 GNe(d){const u=vy(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 iv(d){return AJ(d).toLowerCase()}function rR(d){const u=vy(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 yp(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(A=>{const b=yp(A),O=Mu(b);v&&(y+=" and "),A.isGroup?y+="("+O+")":v?y+=O:y+=b,v=!0,T=!0}),(d.orChildrenGroup||[]).forEach(A=>{const b=yp(A),O=Mu(b);v&&(T&&(y+=","),y+=" or "),A.isGroup?y+="("+O+")":v?y+=O:y+=b,v=!0}),e?`List of ${Mu(y)}`:y}if(d.entity.type===p.PrimitiveEntity){let e=d.entity.name;switch(d.entity.name){case re.String:e="Text";break;case re.KeyValue:e="Data structure";break}return d.isList?`List of ${e}s${u}`:`${e.slice(0,1).toUpperCase()}${e.slice(1)}${u}`}else if(d.entity.type===p.DefinitionEntity){const e=S(d.entity,d.project);return d.isList?`List of ${e} values${u}`:e.slice(0,1).toUpperCase()+e.slice(1)+u}else if(d.entity.type===p.BuiltInBaseEntity){const e=RJ(d.entity);return d.isList?`List of ${e} values${u}`:e.slice(0,1).toUpperCase()+e.slice(1)+u}else if(d.entity.type===p.LiteralValue){if(d.entity.name===re.Null)return"Empty value";if(d.entity.name===re.Untyped)return"Untyped value";if(d.entity.name===re.File)return"File";if(d.entity.name===re.String)return`"${d.entity.value}" text`;if(d.entity.name===re.Number)return`Number '${d.entity.value}'`;if(d.entity.name===re.Boolean)return`${d.entity.value} value`;if(d.entity.name===re.UUID)return`"${d.entity.value}" unique identifier`;if(d.entity.name===re.Date)return`"${d.entity.value}" date`}return d.isList?`List of ${S(d.entity,d.project)} values${u}`:`${S(d.entity,d.project).slice(0,1).toUpperCase()+S(d.entity,d.project).slice(1)} value${u}`}function kNe(d){if(!d)return"Any data type";const u=d.getDataType(null);return yp(u)}function rv(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 Ir.Empty:return"is empty";case Ir.NotEmpty:return"is present"}}function wJ(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 rR(d[0])}catch(u){return console.error("Error resolving base entity name for base entities:",d,u),"Built-in base entity"}}function RJ(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 rR(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 FNe(d){const u=S0(d);if(!u){const i=pp(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 CJ(d){let u="Find ";return d.outputs.forEach((i,a)=>{const l=f0(i,null),c=Mu(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 gJ(d){switch(d.name){case re.String:return"Text";case re.Number:return"Number";case re.Boolean:return"Boolean";case re.KeyValue:return"Data structure";case re.UUID:return"Unique identifier";case re.Date:return"Date";case re.EntityTemplate:return"Entity as template";case re.Enum:return"Enumeration";case re.File:return"File";case re.Null:return"Empty";case re.ActionDescriptor:return"Action descriptor";case re.Untyped:return"Untyped";default:return d.name}}function _J(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 ze.AddIndex:return"Add at index position";case ze.DeleteFirst:return"Delete first character";case ze.DeleteLast:return"Delete last character";case ze.DeleteIndex:return"Delete at index position";case ze.Join:return"Join texts";case ze.ReplaceAllMatches:return"Replace all matches";case ze.ReplaceFirst:return"Replace first match";case ze.ReplaceLast:return"Replace last match";case ze.Split:return"Split text";case ze.ReplaceIndex:return"Replace at index position";case ze.ReplaceSingleMatch:return"Replace single match";case ze.GetFirst:return"Get first character";case ze.GetLast:return"Get last character";case ze.GetIndexItem:return"Get at index position";case ze.GetIndexOf:return"Get the index number of the character";case ze.Append:return"Add at the end";case ze.Prepend:return"Add at the start";case Ei.Wait:return"Wait";case Ei.Parallel:return"Run in parallel";case Ei.Sequential:return"Run in sequence";case pn.HttpRequest:return"HTTP request";case 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 Gs.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(Ar).includes(a))switch(a){case Ar.AbortExecution:return"Abort ongoing execution";case Ar.DeletePersistedEntity:return"Delete entry from database";case Ar.CreatePersistedEntity:return"Save new data entry in database";case Ar.UpdatePersistedEntity:return"Update entity data to database";default:return ir(d.type).replaceAll("-"," ")}return a}if(p.BuiltInBaseEntity===d.type)return wJ([d.name]);if(Vg.includes(d.type)&&d.type!==p.ActionDescriptor)return d.name;switch(d.type){case p.Search:return CJ(d);case p.GlobalEvent:return d.implements?S(d.implements,u):ir(d.type).replaceAll("-"," ");case p.Operation:case p.InternalCall:case p.Loop:const a=mn(d.declaration,u);return S(a,u);case p.ActionDescriptor:return _J(d);case p.BreakStatement:const l=mn(d.parent,u);return`Stop loop ${S(l,u)}`;case p.ContinueStatement:const c=mn(d.parent,u);return`Execute next iteration of ${S(c,u)}`;case p.FunctionCall:return mn(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} ${rv(y)} ${T}`}return`If ${v} ${rv(y)}`}else return`If ${rv(y)}`}case p.ReturnStatement:{const y=mn(d.parent,u);return y?`Output of ${S(y,u)}`:"Return statement"}case p.InputMap:if(d.declaration){const y=mn(d.declaration,u);return S(y,u)||""}else{if(!d.name)throw new Error(`Input map entity with id "${d.id}" has no name and no declaration.`);return d.name||""}case p.VariableInstance:{const y=mn(d.declaration,u);return S(y,u)||""}case p.OutputMap:if(d.declaration){const y=mn(d.declaration,u);return(y==null?void 0:y.name)||""}else return d.parentRelationType===Dl.Error?"Undeclared error":"";case p.PrimitiveEntity:case p.LiteralValue:return gJ(d);default:return ir(d.type).replaceAll("-"," ")}}function nR(d,u){const i=[];d.name||i.push(new ue({id:`${d.id}--${oe.EmptyName}`,message:`Entity with id "${d.id}" and type "${d.type}" has an empty name. Please provide a 'name' string.`,severity:ee.Error,code:oe.EmptyName}));const a=u.entities.filter(l=>l.name===d.name);return a.length&&i.push(new ue({id:`${d.id}--${oe.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,V.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:A,removed:b}=this.remove({ignoreUpstream:!1},l);c.push(...T),e.push(...A),y.push(...b)}if(a==="function-call-parent-field"){const{updated:T,added:A,removed:b}=this.remove({ignoreUpstream:!1},l);c.push(...T),e.push(...A),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:A,removed:b}=this.restore({},l);c.push(...T),e.push(...A),y.push(...b)}if(a==="function-call-parent-field"){const{updated:T,added:A,removed:b}=this.restore({},l);c.push(...T),e.push(...A),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=V.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[A,b]of this.knownVersions||new Map){if(T.set(A,b),b.activeVersion=!1,b.knownVersions)for(const[O,L]of b.knownVersions)T.set(O,L);b.knownVersions=null}}let y=(v=this.knownVersions)==null?void 0:v.get(i);if(!y){const T=await this.APILoadVersion({},i);if(!T)throw new Error(`Version with id '${i}' for entity with id '${this.id}' not found.`);y=new yi(T,this.project)}return this.metaSync(y.toShallowJSON(),null),this.previousVersion=y.previousVersion,this.version=y.version,this.createdAt=y.createdAt,this.author=y.author,this.deleted=y.deleted,this.inputs=y.inputs,this.outputs=y.outputs,this.error=y.error,this.successCalls=y.successCalls,this.errorCalls=y.errorCalls,this.declaration=y.declaration,this.calledBySuccess=y.calledBySuccess,this.calledByError=y.calledByError,this.calledByEntry=y.calledByEntry,this.parent=y.parent,{updated:C(a),added:C(l),removed:C(c),affected:C(e),self:this}}updateWithShallowTransfer(i,a=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,P.UpdateWithShallowTransfer))){if(!this.checkCanEdit(this,a))return Y.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,V.sessionAuthor,B().toISOString(),this,!0,P.AfterAllChildrenInitialized))){if(!this.checkCanEdit(this,i))return Y.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:A,added:b,removed:O}=this.syncOutputs(i);return a.push(...y,...A),l.push(...v,...b),c.push(...T,...O),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,V.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,V.sessionAuthor,B().toISOString(),this,!0,P.RemoveInput))){if(!this.checkCanEdit(this,a))return Y.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,V.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):(Y.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,V.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):(Y.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,V.sessionAuthor,B().toISOString(),this,!0,"remove-output"))){if(!this.checkCanEdit(this,a))return Y.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,V.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,V.sessionAuthor,B().toISOString(),this,!0,P.RemoveValueReader))){return this.checkCanEditWithCounterpartAndSideEffects(this,i,P.RemoveValueReader,a)?this.writesValues.includes(i)?(this.writesValues=this.writesValues.filter(l=>l.id!==i.id),a==null||a.add(this,k.Affected),this):(a==null||a.attemptAutoclose(P.RemoveValueReader,this.id),this):this}addSuccessCaller(i,a=this.project.addChangeSet(new G(this.project,V.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,V.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,V.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,V.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,V.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,V.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,V.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,V.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,V.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=ne(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=ne(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=ne(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=ne(a,this.project);return l.setParent(this,null),l.initChildren(i),l}),this.initialData.error&&(this.error=ne(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,V.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=Ce,...a){return await yi.repository.APILoad(this.id,...a),this}async APICreate(i=Ce,...a){return await yi.repository.APICreate(this.toShallowJSON(),...a),this}async APIUpdate(i=Ce,...a){return await yi.repository.APIUpdate(this.toShallowJSON(),...a),this}async APIDelete(i=Ce,...a){return await yi.repository.APIDelete(this.toShallowJSON(),...a),this}async APIClone(i=Ce,...a){return await yi.repository.APIClone(this.id,...a),this}async APILoadVersion(i=Ce,a,...l){return await yi.repository.APILoadVersion(this.id,a,...l)}removeFromParent(i=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,P.RemoveFromParent))){if(!this.checkCanEdit(this,i))return Y.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,V.sessionAuthor,B().toISOString(),this,!0,P.RemoveEntity))){var v;if(!this.checkCanDelete(this,a))return Y.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:A,removed:b,added:O}=T.entity.onDetachedDependencyRemoved(this,T.field,a);l.push(...A),c.push(...b),e.push(...O)}),this.inputs.forEach(T=>{const{updated:A,removed:b}=T.remove({ignoreUpstream:!0},a);l.push(...A),c.push(...b)}),this.outputs.forEach(T=>{const{updated:A,removed:b}=T.remove({ignoreUpstream:!0},a);l.push(...A),c.push(...b)}),this.error){const{updated:T,removed:A}=this.error.remove({ignoreUpstream:!0},a);l.push(...T),c.push(...A)}if(this.successCalls.forEach(T=>{l.push(T),T.removeCaller(this,a)}),this.errorCalls.forEach(T=>{l.push(T),T.removeCaller(this,a)}),!i){const T=this.removeFromParent(a);e.push(...T.added),l.push(...T.updated),c.push(...T.removed),y.push(...T.affected),this.calledBy.forEach(A=>{l.push(A),A.removeCall(this,a)})}return a==null||a.attemptAutoclose(P.RemoveEntity,this.id),{added:C(e),updated:C(l),removed:C(c),affected:C(y),self:this}}restore({}={},i=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,P.RestoreEntity))){if(!this.checkCanEdit(this,i))return Y.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:A}=y.entity.onDetachedDependencyRestored(this,y.field,i);l.push(...v),c.push(...T),a.push(...A)}),this.inputs.forEach(y=>{const{updated:v}=y.restore({},i);l.push(...v)}),this.outputs.forEach(y=>{const{updated:v}=y.restore({},i);l.push(...v)}),this.successCalls.forEach(y=>{l.push(y),y.addSuccessCaller(this,i)}),this.errorCalls.forEach(y=>{l.push(y),y.addErrorCaller(this,i)}),this.calledBySuccess.forEach(y=>{l.push(y),y.addSuccessCall(this,i)}),this.calledByError.forEach(y=>{l.push(y),y.addErrorCall(this,i)}),this.calledByEntry.forEach(y=>{l.push(y),y.addCall(this,i)}),i==null||i.attemptAutoclose(P.RestoreEntity,this.id),{added:C(a),updated:C(l),removed:C(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:V.UUID.uuid(),createdAt:i.timestamp||B().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,catchesError:this.catchesError,type:this.type,editable:this.editable,deletable:this.deletable,x:this.x,y:this.y,writesValues:this.writesValues.map(A=>A.toJSONClone({...i,newId:null})),successCalls:this.successCalls.map(A=>A.toJSONClone({...i,newId:null})),errorCalls:this.errorCalls.map(A=>A.toJSONClone({...i,newId:null})),calledBySuccess:this.calledBySuccess.map(A=>A.toReference({seenEntityMaps:i.seenEntityMaps})),calledByError:this.calledByError.map(A=>A.toReference({seenEntityMaps:i.seenEntityMaps})),calledByEntry:this.calledByEntry.map(A=>A.toReference({seenEntityMaps:i.seenEntityMaps})),declaration:this.declaration.toJSONClone({...i,newId:null}),inputs:this.inputs.map(A=>A.toJSONClone({...i,newId:null})),outputs:this.outputs.map(A=>A.toJSONClone({...i,newId:null})),error:(T=this.error)==null?void 0:T.toJSONClone({...i,newId:null}),parent:this.parent.toReference({seenEntityMaps:i.seenEntityMaps})})}toReference(i=He){var l;let a=this.id;return(l=i.seenEntityMaps)!=null&&l.has(this.id)&&(a=i.seenEntityMaps.get(this.id)),{id:a+"--"+V.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=dH(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,V.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||V.UUID.uuid();y.inputs=[];const T=v.split("-id"),A=T[T.length-1||0]||v;y.id=v,y.version=V.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 O=(M=this.inputs)==null?void 0:M.map((q,Z)=>q.clone(i,b,A+"-input-map-"+Z+"-id",c));b.inputs=O;const L=(x=this.outputs)==null?void 0:x.map((q,Z)=>q.clone(i,b,A+"-output-map-"+Z+"-id",c));return b.outputs=L,this.error&&(b.error=this.error.clone(i,b,A+"-error-map-id",c)),i==null||i.attemptAutoclose(P.CloneEntity,this.id),b}removeUnrecognizedInputs(i=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,P.RemoveUnrecognizedInputs))){if(!this.checkCanEdit(this,i))return Y.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(A=>{var b;return A.id===((b=v.declaration)==null?void 0:b.id)})){const A=v.remove({ignoreUpstream:!1},i);c.push(...A.removed),a.push(...A.updated)}}),this.inputs.filter((v,T)=>{const A=this.inputs.findIndex(O=>O.declaration===v.declaration&&O!==v);if(A===-1)return!1;const b=this.inputs[A];return B(b==null?void 0:b.createdAt).isSame(B(v.createdAt))?T>A:!!B(b==null?void 0:b.createdAt).isAfter(v.createdAt)}).forEach(v=>{const T=v.remove({ignoreUpstream:!1},i);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,V.sessionAuthor,B().toISOString(),this,!0,P.RemoveUnrecognizedOutputs))){var T,A;if(!this.checkCanEdit(this,i))return Y.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=((A=(T=this.declaration.dataType)==null?void 0:T.entity)==null?void 0:A.properties)||[];return this.outputs.forEach(b=>{if(!y.find(L=>{var M;return L.id===((M=b.declaration)==null?void 0:M.id)})){const L=b.remove({ignoreUpstream:!1},i);c.push(...L.removed),a.push(...L.updated)}}),this.outputs.filter((b,O)=>{const L=this.outputs.findIndex(x=>x.declaration===b.declaration&&x!==b);if(L===-1)return!1;const M=this.outputs[L];return B(M==null?void 0:M.createdAt).isSame(B(b.createdAt))?O>L:!!B(M==null?void 0:M.createdAt).isAfter(b.createdAt)}).forEach(b=>{const O=b.remove({ignoreUpstream:!1},i);c.push(...O.removed),a.push(...O.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,V.sessionAuthor,B().toISOString(),this,!0,P.SyncInputs))){if(!this.checkCanEdit(this,i))return Y.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(O=>O.declaration.id===b.id));this.inputs.sort((b,O)=>b.index-O.index),y.forEach(b=>{this.inputs.forEach(M=>{M.index>=b.index&&M.metaSync({index:M.index+1},i)});const O={id:V.UUID.uuid(),version:V.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||B().toISOString(),author:V.sessionAuthor,previousVersion:null,deleted:!1,deletable:!0,editable:!0,type:p.InputMap,parentRelationType:null,declaration:b.toJSON(),readsValue:null,defaultValue:null,index:b.index,name:null,codeName:null,description:null,parent:this.toReference()},L=ne(O,this.project);L.setParent(this,i),L.initChildren(i),i==null||i.add(L,k.Added),L.addSelfToProject(i),l.push(L)}),this.inputs.sort((b,O)=>b.index-O.index);const{updated:v,added:T,removed:A}=this.removeUnrecognizedInputs(i);return a.push(...v),l.push(...T),c.push(...A),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,V.sessionAuthor,B().toISOString(),this,!0,P.SyncOutputs))){var O,L;if(!this.checkCanEdit(this,i))return Y.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=mn(x,this.project);return Z?[...M,Z]:M}const q=ne(x,this.project);return y.push(q.index),q.setParent(this,null),q.initChildren(i),[...M,q]},[]);const v=(((L=(O=this.declaration.dataType)==null?void 0:O.entity)==null?void 0:L.properties)||[]).filter(M=>!this.outputs.find(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(J=>{J.index>=M.index&&J.index++});const q=y.includes(M.index)?this.outputs.length-1+x:M.index,Z={id:V.UUID.uuid(),version:V.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||B().toISOString(),author:V.sessionAuthor,previousVersion:null,deleted:!1,deletable:!0,editable:!0,type:p.OutputMap,declaration:M.toJSON(),writesValues:[],index:q,parent:this.toReference()},W=ne(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:A,removed:b}=this.removeUnrecognizedOutputs(i);return a.push(...T),l.push(...A),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,V.sessionAuthor,B().toISOString(),this,!0,"get-data-type"))){var l;const a=((l=this.declaration)==null?void 0:l.getDataType(i))||null;return i==null||i.attemptAutoclose("get-data-type",this.id),a}};_(yi,"repository",{APICreate:async(i,...a)=>i,APIUpdate:async(i,...a)=>i,APIDelete:async(i,...a)=>i,APIClone:async(i,...a)=>{},APILoad:async(i,...a)=>null,APILoadVersion:async(i,a,...l)=>null}),_(yi,"type",p.FunctionCall),_(yi,"USER_MANAGED_PARENT_TYPES",[...Xi,p.Project]),_(yi,"PARENT_TYPES",[...yi.USER_MANAGED_PARENT_TYPES]),_(yi,"MUTABLE_BASE_PROPERTIES",["catchesError"]),_(yi,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),_(yi,"BASE_PROPERTIES",[...yi.MUTABLE_BASE_PROPERTIES,...yi.INMUTABLE_BASE_PROPERTIES]),_(yi,"MUTABLE_META_PROPERTIES",["x","y"]),_(yi,"INMUTABLE_META_PROPERTIES",[...yi.INMUTABLE_BASE_PROPERTIES]),_(yi,"META_PROPERTIES",[...yi.MUTABLE_META_PROPERTIES,...yi.INMUTABLE_META_PROPERTIES]),_(yi,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry"]),_(yi,"INMUTABLE_UPSTREAM_PROPERTIES",["declaration","parent"]),_(yi,"UPSTREAM_PROPERTIES",[...yi.MUTABLE_UPSTREAM_PROPERTIES,...yi.INMUTABLE_UPSTREAM_PROPERTIES]),_(yi,"MUTABLE_DOWNSTREAM_PROPERTIES",["successCalls","errorCalls","writesValues","inputs","outputs","error"]),_(yi,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),_(yi,"DOWNSTREAM_PROPERTIES",[...yi.MUTABLE_DOWNSTREAM_PROPERTIES,...yi.INMUTABLE_DOWNSTREAM_PROPERTIES]),_(yi,"PROPERTIES",[...yi.META_PROPERTIES,...yi.UPSTREAM_PROPERTIES,...yi.DOWNSTREAM_PROPERTIES]);let Eo=yi;function Uw(d){return d&&typeof d.then=="function"}function S$e(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 X$e(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(Te(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}=op(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||Y.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}=op(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(op(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);Uw(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);Uw(e)&&(this.onGoingVisits[a][l]=e)}return await this.settlePromises(this.onGoingVisits[a],a),this.onGoingVisits[a]={},this}}const Q$e=63,eNe=/^[a-z][a-z0-9-]*[a-z0-9]$/;function tNe(d){return d.length>=1&&d.length<=Q$e&&eNe.test(d)&&!d.includes("--")}function*iNe(){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 rNe(d,u){const i=new Set(d.map(l=>l.toLowerCase())),a=u>0?"secondary-db":"main";for(const l of iNe()){const c=l?`${a}-${l}`:a;if(tNe(c)&&!i.has(c))return c}throw new Error("Unable to generate identifier")}function uH(d,u){switch(d.id){case pe["built-in-base-entity"].BUILT_IN_PERSISTED_ENTITY_ENTITY.id:{const i=d.project.entities.filter(v=>!!v.implements.find(T=>T.id===pe["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.id)),a=i.find(v=>{const T=v.properties.find(O=>O.implements.find(L=>L.id===pe["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.default.id)),A=T==null?void 0:T.getDefaultValue();return(A==null?void 0:A.value)===!0});if(!a&&i.length){const T=i[0].properties.find(b=>b.implements.find(O=>O.id===pe["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.default.id)),A=T==null?void 0:T.defaultValue;if(A)A.metaSync({value:!0},u);else if(T!=null&&T.dataType){const b={id:V.UUID.uuid(),version:V.UUID.uuid(),createdAt:(u==null?void 0:u.timestamp)||new Date().toISOString(),author:V.sessionAuthor,previousVersion:null,deleted:!1,deletable:!0,editable:!0,type:p.LiteralValue,standaloneParent:null,name:re.EntityTemplate,autogeneration:null,value:!0,valueAsTypeSingle:null,valueAsTypeList:null,parent:T==null?void 0:T.toReference()},O=ne(b,d.project);return O.setParent(T,u),O.initChildren(u),u==null||u.add(O,k.Added),O.addSelfToProject(u),{newEntities:[O]}}return{newEntities:[]}}else if(a)return{newEntities:[]};const l=d.project.get(pe["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.id),c=j0(l,"Main database",u);if(c.errors.length>0)return{newEntities:[]};const e=c.properties.find(v=>v.implements.find(T=>T.id===pe["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:V.UUID.uuid(),version:V.UUID.uuid(),createdAt:(u==null?void 0:u.timestamp)||new Date().toISOString(),author:V.sessionAuthor,previousVersion:null,deleted:!1,deletable:!0,editable:!0,type:p.LiteralValue,standaloneParent:null,name:re.EntityTemplate,autogeneration:null,value:!0,valueAsTypeSingle:null,valueAsTypeList:null,parent:e==null?void 0:e.toReference()},T=ne(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 pH(d,u){const i=[],a=[],l=[],c=[];return d.implements.filter(y=>y.type===p.BuiltInBaseEntity).forEach(y=>{var v,T,A,b,O;switch(y.id){case pe["built-in-base-entity"].BUILT_IN_PERSISTED_ENTITY_ENTITY.id:{const L=d.project.entities.filter(W=>W.implements.find(J=>J.id===pe["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.id));let M=L.find(W=>!!W.properties.find(J=>{var le;return J.implements.find(z=>z.id===pe["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.default.id)&&((le=J.getDefaultValue())==null?void 0:le.value)===!0}));if(!M&&L.length)M=L[0];else if(!M&&!L.length){M=d.project.getBuiltIn(pe["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.id).implement("Relational database",u);const J=M.properties.find(le=>le.implements.find(z=>z.id===pe["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.default.id));(v=J==null?void 0:J.defaultValue)==null||v.metaSync({value:!0},u),a.push(M)}const x=d.properties.find(W=>W.implements.find(J=>J.id===pe["built-in-base-entity"].BUILT_IN_PERSISTED_ENTITY_ENTITY.properties.database.id));if(x&&!(x!=null&&x.defaultValue)){const W={id:V.UUID.uuid(),version:V.UUID.uuid(),createdAt:(u==null?void 0:u.timestamp)||new Date().toISOString(),author:V.sessionAuthor,previousVersion:null,deleted:!1,deletable:!0,editable:!0,type:p.LiteralValue,standaloneParent:null,name:re.EntityTemplate,autogeneration:null,value:null,valueAsTypeSingle:(M==null?void 0:M.toJSON())||null,valueAsTypeList:null,parent:x==null?void 0:x.toReference()},J=ne(W,d.project);J.hydrateAncestors(),J.setParent(x,u),J.addSelfToProject(u),u==null||u.add(J,k.Added),J.initChildren(u),(x==null?void 0:x.defaultValue).setValueAsTypeSingle(M||null,u),a.push(J);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(J=>J.id===pe["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 ${pe["built-in-base-entity"]}`);if(!q.dataType){const W=Zr.new(u);W.parent=q.toReference();const J=ne(W,d.project);J.hydrateAncestors(),J.setParent(q,u),J.addSelfToProject(u),u==null||u.add(J,k.Added),J.initChildren(u)}const Z=d.project.getBuiltIn(pe["primitive-entity"].number.id);(T=q.dataType)==null||T.setEntity(Z,u);return}case pe["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.id:{const L=d.project.entities.filter(le=>le.implements.find(z=>z.id===pe["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.id)&&le.id!==d.id),M=L.map(le=>{var ie;const z=le.properties.find(de=>de.implements.find(me=>me.id===pe["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.identifier.id));return(ie=z==null?void 0:z.getDefaultValue())==null?void 0:ie.value}).filter(le=>!!le),x=d.properties.find(le=>le.implements.find(z=>z.id===pe["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.identifier.id));if(!L.find(le=>!!le.properties.find(z=>{var ce;return z.implements.find(ie=>ie.id===pe["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.default.id)&&((ce=z.getDefaultValue())==null?void 0:ce.value)===!0}))){const le=d.properties.find(z=>z.implements.find(ce=>ce.id===pe["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.default.id));if(!le)throw new Error("Default boolean property not found for relational database entity with id: "+d.id);if(!(le!=null&&le.defaultValue)){const z=Pr.new(u);z.parent=le.toReference();const ce=ne(z,d.project);ce.hydrateAncestors(),ce.setParent(le,u),ce.addSelfToProject(u),u==null||u.add(ce,k.Added),ce.initChildren(u)}(A=le==null?void 0:le.defaultValue)==null||A.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 le=Pr.new(u);le.parent=x.toReference();const z=ne(le,d.project);z.hydrateAncestors(),z.setParent(x,u),z.addSelfToProject(u),z.initChildren(u),u==null||u.add(z,k.Added)}const Z=rNe(M,L.length);(b=x.defaultValue)==null||b.metaSync({value:Z},u);const W=d.properties.find(le=>le.implements.find(z=>z.id===pe["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 ${pe["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.id} with id ${d.id}`);if(!W.defaultValue){const le=Pr.new(u);le.parent=W.toReference();const z=ne(le,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 J=t7(24);(O=W.defaultValue)==null||O.metaSync({value:J},u);return}case pe["built-in-base-entity"].BUILT_IN_SQL_ROW_TRANSFORMER_ENTITY.id:{const L=d.properties.find(Z=>Z.implements.find(W=>W.id===pe["built-in-base-entity"].BUILT_IN_SQL_ROW_TRANSFORMER_ENTITY.properties.time.id));if(!L)throw new Error(`[handleAfterEntityImplementationSideEffects] Time property not found for implemented base entity ${pe["built-in-base-entity"].BUILT_IN_SQL_ROW_TRANSFORMER_ENTITY.id} with id ${d.id}`);let M=L.defaultValue||null;if(!M){const Z=Pr.new(u);Z.parent=L.toReference(),Z.name=re.Date,Z.id=V.UUID.uuid(),M=ne(Z,d.project),M.hydrateAncestors(),M.setParent(L,u),M.addSelfToProject(u),M.initChildren(u),u==null||u.add(M,k.Added)}M.metaSync({value:new Date().toISOString()},u),M.metaSync({editable:!1,deletable:!1},u),L.metaSync({editable:!1,deletable:!1},u);const x=d.properties.find(Z=>Z.implements.find(W=>W.id===pe["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 ${pe["built-in-base-entity"].BUILT_IN_SQL_ROW_TRANSFORMER_ENTITY.id} with id ${d.id}`);let q=x.defaultValue||null;if(!q){const Z=Pr.new(u);Z.name=re.EntityTemplate,Z.parent=x.toReference(),Z.id=V.UUID.uuid(),q=ne(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 j0(d,u,i,a){const l=a||V.UUID.uuid(),c=V.UUID.uuid(),e={id:l,version:c,createdAt:(i==null?void 0:i.timestamp)||new Date().toISOString(),author:V.sessionAuthor,previousVersion:null,deleted:!1,name:u,deletable:!0,editable:!0,type:p.DefinitionEntity,allPropertiesImplement:null,additionalProperties:!1,additionalPropertiesDataType:null,codeName:null,description:null,static:d.static,abstract:!1,properties:[],methods:[],abstractMethods:[],extends:null,implements:[d.toJSON()],x:0,y:0,parent:d.project.toReference()};uH(d,i);const y=ne(e,d.project);return y.hydrateAncestors(),i==null||i.add(y,k.Added),y.addSelfToProject(i),y.addImplementation(d,i),y.setParent(d.project,i),y.initChildren(i),pH(y,i),y}function jw(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 cH(d,u,i,a=vr.OrDataTypeGroup){const l=[],c=[],e=[],y=[],T={id:V.UUID.uuid(),version:V.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||new Date().toISOString(),author:V.sessionAuthor,previousVersion:null,deleted:!1,deletable:!0,editable:!0,type:p.DataType,options:null,implementationChooseOne:!1,entity:d.toJSON(),isList:!1,asType:!1,andChildrenGroup:null,index:null,orChildrenGroup:null,staticEntities:null,interactiveEntities:null,actionEntities:null,like:!0,inferred:!1,parentRelationType:a,parent:u.toReference()},A=ne(T,d.project);return c.push(A),A.setParent(u,i),A.initChildren(i),i==null||i.add(A,k.Added),A.setEntity(d,i),A.addSelfToProject(i),{updated:C(l),added:C(c),removed:C(e),affected:C(y),self:A}}function Gw(d,u,i,a,l){var T,A,b,O,L,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 J=u.project.getBuiltIn(pe[p.PrimitiveEntity][re.Date].id);u.setEntity(J,a);break}else{const J=u.project.getBuiltIn(pe[p.PrimitiveEntity][re.String].id);u.setEntity(J,a);break}case"number":u.setEntity(u.project.getBuiltIn(pe[p.PrimitiveEntity][re.Number].id),a);break;case"boolean":u.setEntity(u.project.getBuiltIn(pe[p.PrimitiveEntity][re.Boolean].id),a);break;case"object":if(d===null){u.setEntity(u.project.getBuiltIn(pe[p.PrimitiveEntity][re.Null].id),a);break}else if(Array.isArray(d))if(u.metaSync({isList:!0},a),d.length>0){const J=d.slice(0,5).filter(z=>z!==void 0);if(J.every(z=>typeof z==typeof J[0])&&(typeof J[0]!="object"||J[0]===null))switch(typeof J[0]){case"string":u.setEntity(u.project.getBuiltIn(pe[p.PrimitiveEntity][re.String].id),a);break;case"number":u.setEntity(u.project.getBuiltIn(pe[p.PrimitiveEntity][re.Number].id),a);break;case"boolean":u.setEntity(u.project.getBuiltIn(pe[p.PrimitiveEntity][re.Boolean].id),a);break;case"object":u.setEntity(u.project.getBuiltIn(pe[p.PrimitiveEntity][re.Null].id),a);break}else{const z=[];let ce=!1;J.forEach(de=>{var me,Q,ye,Ie;if(Array.isArray(de)&&(ce=!0),typeof de=="object"&&!Array.isArray(de)&&de!==null){const Ee=G0(de,u.project,{...i,id:V.UUID.uuid()},a,l);Ee.hasCreated&&z.push((me=Ee.changeSet)==null?void 0:me.self),c.push(...(Q=Ee.changeSet)==null?void 0:Q.updated),e.push(...(ye=Ee.changeSet)==null?void 0:ye.added),y.push(...(Ie=Ee.changeSet)==null?void 0:Ie.removed)}});const ie=C(z);if(!ie.length&&!ce){J.forEach(de=>{const me={id:V.UUID.uuid(),version:V.UUID.uuid(),createdAt:(a==null?void 0:a.timestamp)||new Date().toISOString(),author:V.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=ne(me,u.project);switch(Q.setParent(u,a),Q.initChildren(a),a==null||a.add(Q,k.Added),Q.addSelfToProject(a),typeof de){case"string":Q.setEntity(Q.project.getBuiltIn(pe[p.PrimitiveEntity][re.String].id),a);break;case"number":Q.setEntity(Q.project.getBuiltIn(pe[p.PrimitiveEntity][re.Number].id),a);break;case"boolean":Q.setEntity(Q.project.getBuiltIn(pe[p.PrimitiveEntity][re.Boolean].id),a);break;case"object":Q.setEntity(Q.project.getBuiltIn(pe[p.PrimitiveEntity][re.Null].id),a);break}});break}else ie.length===1&&!ce?u.setEntity(ie[0],a):J.forEach(de=>{if(typeof de=="object"&&!Array.isArray(de)&&de!==null){const me=jw(Object.keys(de),u.project);if(me){const Q=cH(me||ie[0],u,a,vr.OrDataTypeGroup);c.push(...Q.updated),e.push(...Q.added),y.push(...Q.removed)}}else{const me={id:V.UUID.uuid(),version:V.UUID.uuid(),createdAt:(a==null?void 0:a.timestamp)||new Date().toISOString(),author:V.sessionAuthor,previousVersion:null,deleted:!1,deletable:!0,editable:!0,type:p.DataType,options:null,implementationChooseOne:!1,entity:null,isList:Array.isArray(de),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=ne(me,u.project);Q.setParent(u,a),Q.initChildren(a),a==null||a.add(Q,k.Added),Q.addSelfToProject(a);const ye=Gw(de,Q,{...i,id:V.UUID.uuid()},a,l);c.push(...ye.updated),e.push(...ye.added),y.push(...ye.removed)}})}}else{const J=G0(d[0],u.project,{...i},a,l);u.setEntity((T=J.changeSet)==null?void 0:T.self,a),c.push(...(A=J.changeSet)==null?void 0:A.updated),e.push(...(b=J.changeSet)==null?void 0:b.added),y.push(...(O=J.changeSet)==null?void 0:O.removed);break}else{const J=G0(d,u.project,{...i},a,l);u.setEntity((L=J.changeSet)==null?void 0:L.self,a),c.push(...(M=J.changeSet)==null?void 0:M.updated),e.push(...(x=J.changeSet)==null?void 0:x.added),y.push(...(q=J.changeSet)==null?void 0:q.removed);break}}return{updated:C(c),added:C(e),removed:C(y),affected:C(v),self:u}}function G0(d,u,i,a,l){const c=[],e=[],y=[],v=[],T=Object.keys(d),A=jw(T,u);if(A)return{hasCreated:!1,changeSet:{updated:[],added:[],removed:[],affected:[],self:A}};const b=l?i.name+" of "+l.name:i.name,L={id:i.id||V.UUID.uuid(),version:V.UUID.uuid(),createdAt:(a==null?void 0:a.timestamp)||new Date().toISOString(),author:V.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=ne(L,u);return M.setParent(u,a),M.initChildren(a),a==null||a.add(M,k.Added),M.addSelfToProject(a),e.push(M),T.forEach((x,q)=>{const W={id:V.UUID.uuid(),version:V.UUID.uuid(),createdAt:(a==null?void 0:a.timestamp)||new Date().toISOString(),author:V.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()},J=ne(W,u);J.setParent(M,a),J.initChildren(a),a==null||a.add(J,k.Added),J.addSelfToProject(a),e.push(J);const le=d[x],ce={id:V.UUID.uuid(),version:V.UUID.uuid(),createdAt:(a==null?void 0:a.timestamp)||new Date().toISOString(),author:V.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:J.toReference()},ie=ne(ce,u);ie.setParent(J,a),ie.initChildren(a),a==null||a.add(ie,k.Added),ie.addSelfToProject(a),e.push(ie);const de=Gw(le,ie,{...i,name:x,id:V.UUID.uuid()},a,l||M);c.push(...de.updated),e.push(...de.added),y.push(...de.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,A;return Array.isArray(v.implements)?v.implements.some(b=>!!c.implements.find(O=>O.id===b.id)):((T=v.implements)==null?void 0:T.id)===((A=c.implements)==null?void 0:A.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 A,b;return T.implements&&Array.isArray(T.implements)?T.implements.some(O=>!!c.implements.find(L=>L.id===O.id)):((A=T.implements)==null?void 0:A.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(A=>A.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 nNe(d,u){return d.abstract||(d.properties.forEach(a=>{a.abstract||a.metaSync({abstract:!0},u)}),Object.values(d.detachedDependents).forEach(a=>{a.field===sA.Entity&&a.entity.remove({ignoreUpstream:!1},u)}),d.metaSync({abstract:!0},u)),d}function sNe(d,u){return d.abstract&&(d.properties.forEach(a=>{a.abstract&&a.metaSync({abstract:!1},u)}),Object.values(d.detachedDependents).forEach(a=>{(a.field===nv.Implements||a.field===nv.Extends)&&a.entity.onDetachedDependencyRemoved(d,a.field,u)}),d.metaSync({abstract:!1},u)),d}function aNe(d,u){return d.static||(d.properties.forEach(a=>{a.static||a.metaSync({static:!0},u)}),d.metaSync({static:!0},u)),d}function lNe(d,u){return d.static&&d.metaSync({static:!1},u),d}var hn=(d=>(d.StringValueMustNotHaveSpaces="string-value-must-not-have-spaces",d.StringValueMustNotHaveDashes="string-value-must-not-have-dashes",d.MustBeUniqueAmongSameEntities="must-be-unique-among-same-entities",d))(hn||{});function kw(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 fH(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 Fw(d,u){var i;if(d.type===p.LiteralValue){let a=(i=d.value)==null?void 0:i.toString();try{a=JSON.stringify(d.value,null,2)}catch{}return`${d.type}: ${d.id} (${S(d,u)}) = ${a}`}if(d.type===p.DataType){if(d instanceof Zr||d.increaseVersion)return`${d.type}: ${d.id} (${yp(d)})`;try{const a=yp(d);return`${d.type}: ${d.id} (${a})`}catch{}}return`${d.type}: ${d.id} (${S(d,u)})`}function sp(d,u){const i=Io(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=sp(c,u);return e.last&&(a=e.last),[c,...e.list]}),last:a}}function bo(d,u){const i=d.calledBy;if(i.length===0)return{list:[],last:null,callType:null};let a=null,l=null;return{list:i.flatMap(e=>{if(e===u)return a=e,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(!en.includes(e.type))return[e];const y=bo(e,u);return y.last&&(a=y.last,l=y.callType),[e,...y.list]}),last:a,callType:l}}function oNe(d,u){if(d===u)return"same-entity";if(!Gr.includes(d.type)||!py(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 dy(d){const u=Hr(d,d.project);return u?Gt.includes(u.type)?u:u.type===p.Loop?u.body:null:null}function Kw(d,u){const i=d.calledBy;return!i||!i.length?!1:i.every(a=>a===u?!0:en.includes(a.type)?!!bo(a,u).last:!1)}function yH(d){return d.filter(u=>{const i=dy(u);return!d.filter(c=>c!==u).some(c=>c===i?!1:K0(c,u))})}function qw(d){if(!d.calledBy||!d.calledBy.length)return[];const u=d.calledBy.reduce((i,a)=>{if(en.includes(a.type)){const l=qw(a);return[...i,a,...l]}return i},[]);return C(u)}function hH(d){const u=qw(d);if(!u.length)return{ancestor:null,callType:null};const a=u.filter(c=>!(c===d||!Gr.includes(c.type)||!ht(c).find(v=>v===d))).filter((c,e,y)=>y.findIndex(v=>v===c)===e).filter(c=>Kw(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 mH(d,u){if(!d)throw new Error("findNextSingleCallerAncestor: Target is not defined, cannot find ancestor.");let i=d;(d.type===p.VariableDeclaration||d.type===p.VariableInstance)&&!d.calledBy.length&&!d.successCalls.length&&!d.errorCalls.length&&d.internalCalls.some(O=>!!O.calledBy.length)&&(i=d.internalCalls.find(L=>!!L.calledBy.length));let a=u||Hr(i,d.project);if(!a)return{ancestor:null,callType:null};if(a.type===p.Project&&(a=hH(i).ancestor,!a))return{ancestor:null,callType:null};const l=py(a);if(!l.find(O=>O.callee===i))return{ancestor:null,callType:null};if(a.type===p.Loop){if(a.body.calls.includes(i))return{ancestor:a,callType:"loop-body"}}else if(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(O=>!(O.callee===i||!Gr.includes(O.callee.type)||!ht(O.callee).find(x=>x===i))).filter((O,L,M)=>M.findIndex(x=>x.callee===O.callee)===L);if(e.length===0)return{ancestor:null,callType:null};if(e.length===1){const O=e[0];if(O.callee.type===p.Loop){if(O.callee.body.calls.includes(i))return{ancestor:O.callee,callType:"loop-body"}}else{if(Gt.includes(O.callee.type))return O.callee.type===p.FunctionDeclaration&&O.callee.parent.type===p.Loop?{ancestor:O.callee,callType:"loop-body"}:{ancestor:O.callee,callType:"entry"};if(mi.includes(O.callee.type)){if(O.callType==="success"&&O.callee.type===p.InternalCall)return{ancestor:O.callee,callType:"success"};if(O.callType==="error"&&O.callee.type===p.InternalCall)return{ancestor:O.callee,callType:"error"}}}}const y=e.filter(O=>Kw(i,O.callee)),v=y.filter(O=>{const L=ht(O.callee),M=y.filter(q=>q.callee!==O.callee).map(q=>q.callee);return!L.some(q=>!!M.find(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(Er(a.successCalls).find(W=>W===i))return{ancestor:a,callType:"success"};if(Er(a.errorCalls).find(W=>W===i))return{ancestor:a,callType:"error"}}else if(mi.includes(a.type)){if(Er(a.successCalls).find(q=>q===i))return{ancestor:a,callType:"success"};if(Er(a.errorCalls).find(q=>q===i))return{ancestor:a,callType:"error"}}return a.parent.type===p.Loop?{ancestor:a,callType:"loop-body"}:{ancestor:a,callType:"entry"}}if(v.length>1)throw new Error(`findNextSingleCallerAncestor: Could not be resolved, multiple candidates found: ${v.map(O=>S(O.callee,i.project)).join(", ")}`);const T=v[0].callee,b=py(T).find(O=>O.callee===i);return{ancestor:T,callType:b.callType}}function dNe(d){if(![p.VariableDeclaration,p.OutputMap].includes(d.type))throw new Error("getEarliestSingleCallerAncestorOfValueWriterAndItsValueReaders can only be used with a value writer entity");let u;if(d.type===p.VariableDeclaration?u=d:d.type===p.OutputMap&&(u=d.parent),!u)throw new Error("getEarliestSingleCallerAncestorOfValueWriterAndItsValueReaders can only be used with a value writer entity that has a caller");const i=C([d,...k0(d),...$t.includes(d.type)?d.outputs.flatMap(y=>k0(y)):[]]),a=C(i.map(y=>Zw(y)).flatMap(y=>xt.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 A=Er(y.successCalls),b=Er(y.errorCalls);if(A.includes(u))return{ancestor:y,callType:"success"};if(b.includes(u))return{ancestor:y,callType:"error"}}const v=mH(y);if(!v.ancestor)throw new Error(`getEarliestSingleCallerAncestorOfValueWriterAndItsValueReaders: Could not be resolved, no ancestor found for ${S(y,u.project)}`);return v}).filter((y,v,T)=>v===T.findIndex(A=>{var b,O;return((b=A.ancestor)==null?void 0:b.id)===((O=y.ancestor)==null?void 0:O.id)})),c=dy(u),e=l.filter(y=>y!=null&&y.ancestor?c===y.ancestor?!0:!l.filter(A=>A.ancestor!==y.ancestor).map(A=>A.ancestor).some(A=>{const b=bo(y.ancestor,A);return!!(b!=null&&b.last)}):!1);if(e.length===0)return{ancestor: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 vH(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:yH(l).length>1&&l.includes(u)?!1:l.every(e=>d===u?!0:Gt.includes(e.type)?!1:vH(e,u))}function TH(d){const u=[];let i=d.calledBySuccess;i=i.filter(l=>!i.filter(y=>y!==l).some(y=>K0(y,l)));let a=d.calledByError;a=a.filter(l=>!a.filter(y=>y!==l).some(y=>K0(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 EH(d){const u=[];return TH(d).forEach(a=>{a.ancestor.type===p.Condition&&u.push({condition:a.ancestor,call:d,callType:a.callType});const c=EH(a.ancestor).filter(e=>!u.some(y=>y.condition.id===e.condition.id));u.push(...c)}),u}function Zw(d){if(!d)return null;if(d.type===p.Condition&&d.parent.type===p.Condition)return q0(d.parent);if(QT.includes(d.type))return d;const u=d.parent;return u?Zw(u):null}function k0(d,u=new Set){return d.writesValues.reduce((i,a)=>u.has(a.id)?i:(u.add(a.id),Xn.includes(a.type)?[...i,a]:Qi.includes(a.type)?[...i,a,...k0(a,u)]:i),[])}function uy(d){const u=d.calledBy;if(u.length===0)return d.project;const i=u.reduce((a,l)=>{const c=Hr(l,d.project);return!c||c.type===p.Project?a:a.type===p.Project||sp(c,a).last?c:(sp(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=uy(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&&!Xi.includes(i.type)){d.remove({ignoreUpstream:!1},u);return}else if($t.includes(d.type)){const l=d.usedInternalCalls[0];if(l)if(i=uy(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(xt.includes(d.type))return;ht(d).forEach(l=>{let c=uy(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&&!Xi.includes(c.type)){l.remove({ignoreUpstream:!1},u);return}else if($t.includes(l.type)){const e=l.usedInternalCalls[0];if(e)if(c=uy(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 F0(d,u,i=new Set){const a=ia(d),l=ia(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,...F0(T,u,i)])),[]);return C([...e,...y])}function gd(d,u){const i=sp(d,u);return i.last===u&&i.list.length>0&&i.list[0]!==u}function Ww(d,u){return!!sp(d,u).last}function K0(d,u){return!!bo(d,u).last}function Hw(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 Hw(i,a)}function uNe(d,u,i=!0){if(!d||!u)throw new Error("Both entities must be defined to find a common ancestor");if(d===u)return{ancestor:d,callType:"same-entity"};if(en.includes(d.type)&&Gr.includes(u.type)){const y=bo(d,u),v=y.last;if(v){if(v===u)return{ancestor:u,callType:y.callType}}else return{ancestor:null,callType:null}}if(en.includes(u.type)&&Gr.includes(d.type)){const y=bo(u,d),v=y.last;if(v){if(v===d)return{ancestor:d,callType:y.callType}}else return{ancestor:null,callType:null}}const a=dy(d),l=dy(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(!Gr.includes(v.type))return y;const T=py(v),A=T.find(O=>O.callee===d),b=T.find(O=>O.callee===u);return A&&b&&(!i||A.callType===b.callType)?[...y,{ancestor:v,callType:A.callType}]:y},[]);if(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&&bo(y.ancestor,v.ancestor).last===v.ancestor));return e.length===1?{ancestor:e[0].ancestor,callType:e[0].callType}:{ancestor:a,callType:"entry"}}function Pi(d){if(sc.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 ap(d,u){const i=lp(d,u);if(!i)return null;if(sc.includes(i.type)){if(i.type===p.FunctionDeclaration){const a=lp(i.parent,u);if(a){if(a.type===p.DefinitionEntity)return a;if(a.type===p.Loop)return a}}if(i.parent){const a=lp(i.parent,u);if(a&&(i.type===p.DefinitionEntity&&a.type===p.DataType||i.type===p.Condition&&a.type===p.Condition))return ap(a,u)}return i}else{const a=i.parent?lp(i.parent,u):null;return a?ap(a,u):null}}function py(d){if(d.type===p.Loop){const u=[...Er(d.successCalls).map(l=>({callee:l,callType:"success"})),...Er(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=[...Er(d.successCalls).map(l=>({callee:l,callType:"success"})),...Er(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=[...Er(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 q0(d){if(!d)return null;if(d.type===p.Condition&&d.parent.type===p.Condition)return q0(d.parent);if(en.includes(d.type))return d;const u=d.parent;return u?q0(u):null}function bH(d){if(!d)return null;if(mi.includes(d.type))return d;const u=d.parent;return u?bH(u):null}function IH(d){if(!d)return null;if(Gr.includes(d.type))return d;const u=d.parent;return u?IH(u):null}function pNe(d){return d.type===p.VariableDeclaration?[d]:mi.includes(d.type)?[...d.inputs,...d.outputs||[]]:xt.includes(d.type)?d.outputs:Fo.includes(d.type)||d.type===p.FunctionDeclaration?d.inputs:[]}function cNe(d){const u=ia(d),i=[],a=[];Pg.includes(d.type)&&i.push(...Z0(d));const l=u.filter(c=>{const e=i.includes(c);return e?!1:en.includes(c.type)&&!e?(a.push(c),!1):!0});return i.sort((c,e)=>gd(e,c)?-1:0),a.sort((c,e)=>gd(e,c)?-1:0),[...i,...a,...l]}function AH(d){return[...d].sort((u,i)=>gd(i,u)?-1:0)}function fNe(d){const u=AH(d),i=[];return u.forEach(a=>{const l=i[i.length-1];if(l){const c=l[l.length-1];gd(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 Z0(d){return mi.includes(d.type)?[...El(d.successCalls),...El(d.errorCalls)]:Gt.includes(d.type)?El(d.calls):[]}function yNe(d,u){return Z0(d).includes(u)}function W0(d){return d.writesValues||[]}function hNe(d,u){return W0(d).includes(u)}function wH(d){var u;return $t.includes((u=d==null?void 0:d.readsValue)==null?void 0:u.type)?d.readsValue:null}function mNe(d){return d.writesValues}function RH(d=[]){return d.map(wH).filter(u=>!!u)}function H0(d=[]){return d.map(u=>u.writesValues).flat().filter(u=>$t.includes(u.type))}function CH(d=[]){return d.map(u=>u.readsValue).filter(u=>!!u&&$t.includes(u.type))}function gH(d){return $t.includes(d.type)?d:null}function _H(d){return d.writesValues.map(gH).filter(u=>!!u)}function DH(d=[]){return d.reduce((u,i)=>i.type===p.OutputMap?[...u,..._H(i)]:u,[])}function ht(d){return d.type===p.Loop?C([...Er(d.successCalls),...Er(d.errorCalls),...d.body?ht(d.body):[]]):mi.includes(d.type)?C([...Er(d.successCalls),...Er(d.errorCalls)]):Gt.includes(d.type)?C(Er(d.calls)):[]}function vNe(d){return mi.includes(d.type)?[...Er(d.successCalls),...Er(d.errorCalls)]:Gt.includes(d.type)?Er(d.calls):[]}function OH(d,u=new Set){return d.writesValues.filter(a=>$t.includes(a.type)&&!u.has(a.id)).reduce((a,l)=>u.has(l.id)?a:[...a,...Li(l,u)],[])}function PH(d,u=new Set){var a;return(((a=d.readsValue)==null?void 0:a.writesValues)||[]).filter(l=>$t.includes(l.type)&&!u.has(l.id)).reduce((l,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 CH(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)]},[]),...RH(d.inputs),...DH(d.outputs)].reduce((c,e)=>[...c,...Li(e,u)],[]);if(Fo.includes(d.type)){const i=H0(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=[...H0(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($t.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,...PH(d,u),...OH(d,u)]}return[]}function Fn(d,u=new Set){if(u.has(d.id))return[];u.add(d.id),Y.log("[flattenDerivedCanvasEntities]",d.type,S(d,d.project),d.id);const i=ia(d);return i.forEach(l=>{u.add(l.id)}),[...i.reduce((l,c)=>(Y.log("[Recursive -- flattenDerivedCanvasEntities]",c.type,S(c,c.project),c.id),[...l,c,...Fn(c,u)]),[])]}function Er(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 $H(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,...H0(T.inputs),...Er(El(T.calls)),...T.returnStatements],[]),e=d.functions.reduce((v,T)=>[...v,...Er(El(T.calls)),...T.returnStatements],[]),y=d.events.reduce((v,T)=>[...v,...Er(El(T.calls)),...T.returnStatements],[]);return[...i,...a,...l,...c,...e,...y]}function NH(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)?aJ(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 TNe(d){const u=$H(d.project);return NH(d,u)}function lp(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 VH(d={},u){const i={};return Object.keys(d).forEach(a=>{const l=u.get(a)||a,c=d[a];i[l]=c}),i}function op(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,A=d,b=d,O=d,L=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),...L.parent?[L.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)):O.extends&&Z.push(O.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 ce=te(z);if(ce&&u[ce]){const ie=u[ce];[...ie.calledByEntry||[],...ie.calledBySuccess||[],...ie.calledByError||[]].forEach(de=>{const me=te(de);me&&u[me]&&Z.push(u[me])})}});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),...A.error?[A.error]:[],...L.throws?[L.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 ce=te(z);if(ce&&u[ce]){const ie=u[ce];[...ie.successCalls||[],...ie.errorCalls||[]].forEach(de=>{const me=te(de);me&&u[me]&&W.push(u[me])})}});const J={},le={};return Z.forEach(z=>{var de;const ce=te(z);if(ce&&a.ignoreBuiltInBaseEntities&&(vn.includes(z.type)||(a.allBuiltInEntityIds||[]).includes(ce)))return;const ie=z.version;if(ce){const me=((de=a.entityMaps)==null?void 0:de.get(ce))||ce;J[me]=ie}}),W.forEach(z=>{var de;const ce=te(z);if(ce&&a.ignoreBuiltInBaseEntities&&(vn.includes(z.type)||(a.allBuiltInEntityIds||[]).includes(ce)))return;const ie=z.version;if(ce){const me=((de=a.entityMaps)==null?void 0:de.get(ce))||ce;le[me]=ie}}),{upstream:J,downstream:le}}function ENe(d,u){const i=[];if(en.includes(d.type)){os(d).forEach(c=>{const e=ap(c,u);e&&i.push(e)});const l=[...d.inputs||[],...d.outputs||[]].map(c=>{const e=lp(c,u);return e?lJ(e,u):null}).filter(c=>c!==null);i.push(...C(l))}if($t.includes(d.type)){const a=J0(d);a&&i.push(a)}return C(i)}function Io(d){const u=[];if(en.includes(d.type)){d.calledBy.forEach(l=>{const c=Pi(l);c&&u.push(c)});const a=[...d.inputs||[],...d.outputs||[]].map(l=>J0(l)).filter(l=>l!==null);u.push(...C(a))}if(Xn.includes(d.type)){const i=J0(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 LH(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==p.ActionDescriptor)throw new Error("Entity must be an action descriptor to be flattened");return[d,...d.inputs.flatMap(a=>Te(a,u,i)),...d.dataType?Te(d.dataType,u,i):[],...d.error?Te(d.error,u,i):[],...d.parent?Te(d.parent,u,i):[]]}function BH(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==p.ArgumentDeclaration)throw new Error("Entity must be an argument declaration to be flattened");return[d,...d.defaultValue?Te(d.defaultValue,u):[],...d.writesValues.flatMap(a=>Te(a,u,i)),...d.dataType?Te(d.dataType,u,i):[],...d.parent?Te(d.parent,u,i):[]]}function MH(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==p.BreakStatement)throw new Error("Entity must be a break statement to be flattened");return[d,...d.outputs.flatMap(a=>Te(a,u,i)),...d.throws?Te(d.throws,u,i):[],...d.implements?Te(d.implements,u,i):[],...d.dataType?Te(d.dataType,u,i):[],...d.readsValue?Te(d.readsValue,u,i):[],...(os(d)||[]).flatMap(a=>Te(a,u,i)),...d.parent?Te(d.parent,u,i):[]]}function xH(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==p.BuiltInBaseEntity)throw new Error("Entity must be a built-in base entity to be flattened");return[d,...(d.properties||[]).flatMap(a=>Te(a,u,i)),...(d.methods||[]).flatMap(a=>Te(a,u,i)),...(d.abstractMethods||[]).flatMap(a=>Te(a,u,i)),...d.allPropertiesImplement?Te(d.allPropertiesImplement,u,i):[],...d.additionalPropertiesDataType?Te(d.additionalPropertiesDataType,u,i):[],...d.extends?Te(d.extends,u,i):[]]}function UH(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==p.Condition)throw new Error("Entity must be a condition to be flattened");return[d,...(d.andChildrenGroup||[]).flatMap(a=>Te(a,u,i)),...(d.orChildrenGroup||[]).flatMap(a=>Te(a,u,i)),...(d.inputs||[]).flatMap(a=>Te(a,u,i)),...(d.successCalls||[]).flatMap(a=>Te(a,u,i)),...(d.errorCalls||[]).flatMap(a=>Te(a,u,i)),...(os(d)||[]).flatMap(a=>Te(a,u,i)),...d.parent?Te(d.parent,u,i):[]]}function jH(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==p.ContinueStatement)throw new Error("Entity must be a continue statement to be flattened");return[d,...d.outputs.flatMap(a=>Te(a,u,i)),...d.readsValue?Te(d.readsValue,u,i):[],...d.implements?Te(d.implements,u,i):[],...d.throws?Te(d.throws,u,i):[],...d.dataType?Te(d.dataType,u,i):[],...(os(d)||[]).flatMap(a=>Te(a,u,i)),...d.parent?Te(d.parent,u,i):[]]}function GH(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==p.DefinitionEntity)throw new Error("Entity must be a definition entity to be flattened");return[d,...d.extends?Te(d.extends,u,i):[],...(d.implements||[]).flatMap(a=>Te(a,u,i)),...(d.properties||[]).flatMap(a=>Te(a,u,i)),...(d.methods||[]).flatMap(a=>Te(a,u,i)),...(d.abstractMethods||[]).flatMap(a=>Te(a,u,i)),...d.allPropertiesImplement?Te(d.allPropertiesImplement,u,i):[],...d.additionalPropertiesDataType?Te(d.additionalPropertiesDataType,u,i):[],...d.parent?Te(d.parent,u,i):[]]}function kH(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==p.DataType)throw new Error("Entity must be a data type to be flattened");return[d,...(d.andChildrenGroup||[]).flatMap(a=>Te(a,u,i)),...(d.orChildrenGroup||[]).flatMap(a=>Te(a,u,i)),...d.entity?Te(d.entity,u,i):[],...d.parent?Te(d.parent,u,i):[]]}function FH(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==p.FunctionCall)throw new Error("Entity must be a function call to be flattened");return[d,...(d.inputs||[]).flatMap(a=>Te(a,u,i)),...(d.outputs||[]).flatMap(a=>Te(a,u,i)),...d.error?Te(d.error,u,i):[],...(os(d)||[]).flatMap(a=>Te(a,u,i)),...(d.successCalls||[]).flatMap(a=>Te(a,u,i)),...(d.errorCalls||[]).flatMap(a=>Te(a,u,i)),...(d.writesValues||[]).flatMap(a=>Te(a,u,i)),...d.parent?Te(d.parent,u,i):[]]}function KH(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==p.FunctionDeclaration)throw new Error("Entity must be a function declaration to be flattened");return[d,...(d.inputs||[]).flatMap(a=>Te(a,u,i)),...(d.calls||[]).flatMap(a=>Te(a,u,i)),...d.implements?Te(d.implements,u,i):[],...d.parent?Te(d.parent,u,i):[]]}function qH(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==p.GlobalEvent)throw new Error("Entity must be a global event to be flattened");return[d,...(d.inputs||[]).flatMap(a=>Te(a,u,i)),...(d.calls||[]).flatMap(a=>Te(a,u,i)),...d.implements?Te(d.implements,u,i):[],...d.parent?Te(d.parent,u,i):[]]}function ZH(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==p.InputMap)throw new Error("Entity must be an input map to be flattened");return[d,...d.readsValue?Te(d.readsValue,u,i):[],...d.declaration?Te(d.declaration,u,i):[],...d.defaultValue?Te(d.defaultValue,u,i):[],...d.parent?Te(d.parent,u,i):[]]}function WH(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==p.InstalledProject)throw new Error("Entity must be an installed project to be flattened");return[d,...(d.functions||[]).flatMap(a=>Te(a,u,i)),...(d.events||[]).flatMap(a=>Te(a,u,i)),...d.parent?Te(d.parent,u,i):[]]}function HH(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==p.InternalCall)throw new Error("Entity must be an internal call to be flattened");return[d,...(d.successCalls||[]).flatMap(a=>Te(a,u,i)),...(d.errorCalls||[]).flatMap(a=>Te(a,u,i)),...(d.inputs||[]).flatMap(a=>Te(a,u,i)),...(d.outputs||[]).flatMap(a=>Te(a,u,i)),...(os(d)||[]).flatMap(a=>Te(a,u,i)),...d.error?Te(d.error,u,i):[],...(d.writesValues||[]).flatMap(a=>Te(a,u,i)),...d.parent?Te(d.parent,u,i):[]]}function JH(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==p.LiteralValue)throw new Error("Entity must be a literal value to be flattened");return[d,...d.valueAsTypeSingle?Te(d.valueAsTypeSingle,u,i):[],...d.valueAsTypeList&&Array.isArray(d.valueAsTypeList)?d.valueAsTypeList.flatMap(a=>Te(a,u,i)):[],...d.parent?Te(d.parent,u,i):[]]}function zH(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==p.Loop)throw new Error("Entity must be a loop to be flattened");return[d,...(d.inputs||[]).flatMap(a=>Te(a,u,i)),...(d.outputs||[]).flatMap(a=>Te(a,u,i)),...(d.successCalls||[]).flatMap(a=>Te(a,u,i)),...(d.errorCalls||[]).flatMap(a=>Te(a,u,i)),...d.error?Te(d.error,u,i):[],...d.dataType?Te(d.dataType,u,i):[],...d.body?Te(d.body,u,i):[],...(os(d)||[]).flatMap(a=>Te(a,u,i)),...(d.writesValues||[]).flatMap(a=>Te(a,u,i)),...d.parent?Te(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.Operation)throw new Error("Entity must be an operation to be flattened");return[d,...(d.successCalls||[]).flatMap(a=>Te(a,u,i)),...(d.errorCalls||[]).flatMap(a=>Te(a,u,i)),...(d.inputs||[]).flatMap(a=>Te(a,u,i)),...(d.outputs||[]).flatMap(a=>Te(a,u,i)),...(d.writesValues||[]).flatMap(a=>Te(a,u,i)),...d.error?Te(d.error,u,i):[],...(os(d)||[]).flatMap(a=>Te(a,u,i)),...d.parent?Te(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.OutputMap)throw new Error("Entity must be an output map to be flattened");return[d,...(d.writesValues||[]).flatMap(a=>Te(a,u,i)),...d.declaration?Te(d.declaration,u,i):[],...d.parent?Te(d.parent,u,i):[]]}function XH(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==p.PrimitiveEntity)throw new Error("Entity must be a primitive entity to be flattened");return[d,...(d.properties||[]).flatMap(a=>Te(a,u,i)),...(d.methods||[]).flatMap(a=>Te(a,u,i)),...(d.abstractMethods||[]).flatMap(a=>Te(a,u,i))]}function QH(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==p.Project)throw new Error("Entity must be a project to be flattened");return[d,...(d.entities||[]).flatMap(a=>Te(a,u,i)),...(d.functions||[]).flatMap(a=>Te(a,u,i)),...(d.events||[]).flatMap(a=>Te(a,u,i)),...(d.projects||[]).flatMap(a=>Te(a,u,i)),...(d.variableDeclarations||[]).flatMap(a=>Te(a,u,i)),...(d.variableInstances||[]).flatMap(a=>Te(a,u,i)),...(d.operations||[]).flatMap(a=>Te(a,u,i)),...(d.conditions||[]).flatMap(a=>Te(a,u,i)),...(d.functionCalls||[]).flatMap(a=>Te(a,u,i)),...(d.projects||[]).flatMap(a=>Te(a,u,i)),...(d.loops||[]).flatMap(a=>Te(a,u,i)),...(d.searches||[]).flatMap(a=>Te(a,u,i))]}function eJ(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==p.Property)throw new Error("Entity must be a property to be flattened");return[d,...d.defaultValue?Te(d.defaultValue,u,i):[],...d.dataType?Te(d.dataType,u,i):[],...d.parent?Te(d.parent,u,i):[]]}function tJ(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==p.ReturnStatement)throw new Error("Entity must be a return statement to be flattened");return[d,...(d.outputs||[]).flatMap(a=>Te(a,u,i)),...d.throws?Te(d.throws,u,i):[],...d.implements?Te(d.implements,u,i):[],...d.readsValue?Te(d.readsValue,u,i):[],...d.dataType?Te(d.dataType,u,i):[],...(os(d)||[]).flatMap(a=>Te(a,u,i)),...d.parent?Te(d.parent,u,i):[]]}function iJ(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==p.Search)throw new Error("Entity must be a search to be flattened");return[d,...(d.successCalls||[]).flatMap(a=>Te(a,u,i)),...(d.errorCalls||[]).flatMap(a=>Te(a,u,i)),...(d.inputsDeclarations||[]).flatMap(a=>Te(a,u,i)),...(d.inputs||[]).flatMap(a=>Te(a,u,i)),...(d.writesValues||[]).flatMap(a=>Te(a,u,i)),...(d.outputs||[]).flatMap(a=>Te(a,u,i)),...d.error?Te(d.error,u,i):[],...d.dataType?Te(d.dataType,u,i):[],...(os(d)||[]).flatMap(a=>Te(a,u,i)),...d.parent?Te(d.parent,u,i):[]]}function rJ(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==p.ValueDescriptor)throw new Error("Entity must be a value descriptor to be flattened");return[d,...d.defaultValue?Te(d.defaultValue,u,i):[],...d.dataType?Te(d.dataType,u,i):[],...d.parent?Te(d.parent,u,i):[]]}function nJ(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==p.VariableDeclaration)throw new Error("Entity must be a variable declaration to be flattened");return[d,...(d.successCalls||[]).flatMap(a=>Te(a,u,i)),...(d.errorCalls||[]).flatMap(a=>Te(a,u,i)),...(d.inputs||[]).flatMap(a=>Te(a,u,i)),...(d.outputs||[]).flatMap(a=>Te(a,u,i)),...(d.internalCalls||[]).flatMap(a=>Te(a,u,i)),...(d.writesValues||[]).flatMap(a=>Te(a,u,i)),...d.readsValue?Te(d.readsValue,u,i):[],...d.defaultValue?Te(d.defaultValue,u,i):[],...(os(d)||[]).flatMap(a=>Te(a,u,i)),...d.dataType?Te(d.dataType,u,i):[],...d.parent?Te(d.parent,u,i):[]]}function sJ(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==p.VariableInstance)throw new Error("Entity must be a variable instance to be flattened");return[d,...(d.successCalls||[]).flatMap(a=>Te(a,u,i)),...(d.errorCalls||[]).flatMap(a=>Te(a,u,i)),...(d.inputs||[]).flatMap(a=>Te(a,u,i)),...(d.outputs||[]).flatMap(a=>Te(a,u,i)),...(d.internalCalls||[]).flatMap(a=>Te(a,u,i)),...(d.writesValues||[]).flatMap(a=>Te(a,u,i)),...d.readsValue?Te(d.readsValue,u,i):[],...d.defaultValue?Te(d.defaultValue,u,i):[],...(os(d)||[]).flatMap(a=>Te(a,u,i)),...d.declaration?Te(d.declaration,u,i):[],...d.parent?Te(d.parent,u,i):[]]}function Kn(){const d=new Set;return dk.flatMap(i=>Te(i,d)).map(i=>i.id)}function Te(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(!d)throw new Error("Entity must be defined to be flattened");if(d.type===p.GenericReference)return[];if(i.ignoreBuiltInBaseEntities&&(vn.includes(d.type)||Kn().includes(d.id)))return[];if(u.has(d.id))return[];switch(d.type){case p.FunctionCall:return FH(d,u,i);case p.Operation:return YH(d,u,i);case p.Condition:return UH(d,u,i);case p.Loop:return zH(d,u,i);case p.Search:return iJ(d,u,i);case p.GlobalEvent:return qH(d,u,i);case p.ReturnStatement:return tJ(d,u,i);case p.ContinueStatement:return jH(d,u,i);case p.BreakStatement:return MH(d,u,i);case p.VariableDeclaration:return nJ(d,u,i);case p.DefinitionEntity:return GH(d,u,i);case p.FunctionDeclaration:return KH(d,u,i);case p.Project:return QH(d,u,i);case p.ActionDescriptor:return LH(d,u,i);case p.ArgumentDeclaration:return BH(d,u,i);case p.ValueDescriptor:return rJ(d,u,i);case p.InputMap:return ZH(d,u,i);case p.OutputMap:return SH(d,u,i);case p.DataType:return kH(d,u,i);case p.InstalledProject:return WH(d,u,i);case p.InternalCall:return HH(d,u,i);case p.LiteralValue:return JH(d,u,i);case p.Property:return eJ(d,u,i);case p.VariableInstance:return sJ(d,u,i);case p.BuiltInBaseEntity:return i.ignoreBuiltInBaseEntities?[]:xH(d,u,i);case p.PrimitiveEntity:return i.ignoreBuiltInBaseEntities?[]:XH(d,u,i)}return[]}function Jw(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||Fo.includes(d.type)?d.inputs:d.type===p.Search?d.inputsDeclarations:[]}function bNe(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 aJ(d){return mi.includes(d.type)?d.inputs:[]}function INe(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 xt.includes(d.type)?d.outputs.map(i=>i.declaration).filter(i=>!!i)||[]:[]}function ANe(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 wNe(d){return d.type===p.Condition?[]:mi.includes(d.type)?d.outputs:[]}function J0(d){const u=d.readsValue;return u?Pi(u):null}function lJ(d,u){const i=d.readsValue;return i?ap(i,u):null}function oJ(d){const u=d.internalCalls||[];return C(El(C(u.flatMap(i=>[...i.successCalls,...i.errorCalls]))))}function dJ(d){const u=d.internalCalls||[];return C(C(u.flatMap(i=>[...i.successCalls,...i.errorCalls])))}function dp(d){const u=W0(d),i=[];return u.forEach(a=>{if(sc.includes(a.type))i.push(a);else if(Xn.includes(a.type)){const l=Pi(a.parent);i.push(l)}}),i}function up(d){const u=W0(d),i=[];return u.forEach(a=>{if($t.includes(a.type))i.push(a);else if(Xn.includes(a.type)){const l=a.parent;i.push(l)}}),i}function C(d){const u=new Set;return d.filter(i=>!i||u.has(i.id)?!1:(u.add(i.id),!0))}function uJ(d){return d.type===p.Project?null:QT.includes(d.type)?d:vn.includes(d.type)?null:d.parent?uJ(d.parent):null}function ia(d,u=!1){Y.log("[getRelatedCanvasElementsOnTheRight]",d.type,S(d,d.project),d.id);const i=[];if(d.type===p.Project&&i.push(...(d==null?void 0:d.entities)||[],...(d==null?void 0:d.functions)||[],...(d==null?void 0:d.variableDeclarations)||[],...(d==null?void 0:d.variableInstances)||[],...(d==null?void 0:d.searches)||[],...(d==null?void 0:d.loops)||[],...(d==null?void 0:d.operations)||[],...(d==null?void 0:d.conditions)||[],...(d==null?void 0:d.functionCalls)||[],...(d==null?void 0:d.events)||[],...(d==null?void 0:d.projects)||[]),Xi.includes(d.type)&&i.push(...(d==null?void 0:d.detachedChildren)||[]),d.type===p.DefinitionEntity){const a=[...d.suggestedMethods,...d.methods].flatMap(l=>l.collapsed&&u?[]:(Y.log("[Recursive -- getRelatedCanvasElementsOnTheRight]",l.type,S(l,l.project),l.id),ia(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(Fo.includes(d.type)){if(d.collapsed&&u)return[];const a=d.inputs.map(c=>dp(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=>dp(e)).flat(),l=d.successCalls.map(e=>Pi(e)),c=d.errorCalls.map(e=>Pi(e));i.push(...C(a),...l,...c)}if($t.includes(d.type)){const a=dp(d),l=oJ(d);i.push(...a,...l)}if(Qi.includes(d.type)){const a=dp(d);i.push(...a)}if(d.type===p.Loop){if(d.body){const c=ia(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=>dp(c)).flat(),l=d.calls.map(c=>Pi(c));i.push(...C(a),...l)}return C(i)}function z0(d,u=!1){const i=[];if(d.type===p.Project&&i.push(...(d==null?void 0:d.variableDeclarations)||[],...(d==null?void 0:d.variableInstances)||[],...(d==null?void 0:d.searches)||[],...(d==null?void 0:d.loops)||[],...(d==null?void 0:d.operations)||[],...(d==null?void 0:d.conditions)||[],...(d==null?void 0:d.functionCalls)||[]),Xi.includes(d.type)&&i.push(...(d==null?void 0:d.detachedChildren)||[]),d.type===p.DefinitionEntity){const a=[...d.suggestedMethods,...d.methods].flatMap(l=>l.collapsed&&u?[]:z0(l));i.push(...a)}if(d.type===p.Condition){const a=d.successCalls,l=d.errorCalls;i.push(...a,...l)}if(Fo.includes(d.type)){if(d.collapsed&&u)return[];const a=d.inputs.map(c=>up(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=>up(e)).flat(),l=d.successCalls,c=d.errorCalls;i.push(...C(a),...l,...c)}if($t.includes(d.type)){const a=up(d),l=dJ(d);i.push(...a,...l)}if(d.type===p.Loop){const a=d.outputs.map(e=>up(e)).flat();if(d.body){const e=z0(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=>up(c)).flat(),l=d.calls;i.push(...C(a),...l)}return C(i)}function Y0(d,u=!1){const i=ia(d,u),a=[...i,...i.reduce((l,c)=>[...l,...Y0(c,u)],[])];return C(a)}function pJ(d,u=!1){const i=z0(d,u),a=[...i,...i.reduce((l,c)=>[...l,...pJ(c,u)],[])];return C(a)}function cy(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,...cy(i),...Ao(i)]:(i==null?void 0:i.type)===p.BuiltInBaseEntity?[i==null?void 0:i.name,...Ao(i)]:[...u],[])}function Ao(d){var u;if(!d)throw new Error("[flattenDefinitionEntityExtensionTypes] Entity must be defined to flatten extension types");if(d.extends){if(((u=d.extends)==null?void 0:u.type)===p.DefinitionEntity)return[p.DefinitionEntity,...Ao(d.extends),...cy(d.extends)];if(d.extends.type===p.BuiltInBaseEntity)return[d.extends.name,...Ao(d.extends)]}return[]}function fy(d){var u,i;return d.extends?((u=d.extends)==null?void 0:u.type)===p.DefinitionEntity?[d.extends,...fy(d.extends),...zw(d.extends)]:((i=d.extends)==null?void 0:i.type)===p.BuiltInBaseEntity?[d.extends,...fy(d.extends)]:[]:[]}function zw(d){return d.implements.reduce((u,i)=>i.type===p.DefinitionEntity?[...u,i,...zw(i),...fy(i)]:(i==null?void 0:i.type)===p.BuiltInBaseEntity?[i,...fy(i)]:[...u,i],[])}function pp(d){return[...Ao(d),...cy(d)].filter((i,a,l)=>l.indexOf(i)===a)}function cr(d,u){if(!d)throw new Error("checkHasBaseEntity: entity is null or undefined");if(d.type!==p.DefinitionEntity&&d.type!==p.BuiltInBaseEntity)throw new Error(`checkHasBaseEntity: entity is not a '${p.DefinitionEntity}' or '${p.BuiltInBaseEntity}', got ${d.type}`);return d.type===p.BuiltInBaseEntity?!!(d.name===u||[...Ao(d)].includes(u)):!!pp(d).includes(u)}function cJ(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 fJ(d){const u=Io(d),i=[...u,...u.reduce((a,l)=>[...a,...fJ(l)],[])];return C(i)}function Yw(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=Yw(l);if(c)return c}return a},null)}function RNe(d){return d.extends&&d.extends.type===p.BuiltInBaseEntity?d.extends:null}function CNe(d){const u=d.implements.find(i=>i.type===p.BuiltInBaseEntity);return u&&u.type===p.BuiltInBaseEntity?u:null}function S0(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 yy(d){return d.type===p.PrimitiveEntity?!0:d.type===p.BuiltInBaseEntity?d.interactive:!sn(d).find(a=>!a.interactive)}function gNe(d){return d.parent===d.project&&d.project.variableDeclarations.includes(d)}function Sw(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 yJ(d){if([...Gt,p.DefinitionEntity,p.InstalledProject,p.Project].includes(d.type)||Sw(d))return!1;const u=Io(d);return u.length===0?!0:u.some(i=>yJ(i))}function Xw(d){return[...Gt,p.DefinitionEntity,p.InstalledProject,p.Project].includes(d.type)||Sw(d)?!1:Io(d).length===0}function hJ(d,u=0){if(Xw(d)){const i=Io(d);return i.length===0?d:i.map(l=>hJ(l,u+1)).reduce((l,c)=>l?c&&c.x<l.x?c:l:c,null)}return null}function mJ(d){const u=[];if(Xw(d))u.push(d);else return[];return Io(d).forEach(a=>{u.push(...mJ(a))}),u}function Qw(d){return d.type===p.FunctionDeclaration&&d.parent!==d.project&&!![p.DefinitionEntity,p.Loop,p.InstalledProject].includes(d.parent.type)}function _Ne(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 cp(d){switch(d){case p.DefinitionEntity:return Os;case p.FunctionDeclaration:return Ia;case p.VariableDeclaration:return lo;case p.VariableInstance:return ao;case p.FunctionCall:return Eo;case p.Operation:return eo;case p.Condition:return ro;case p.ReturnStatement:return cl;case p.Loop:return io;case p.Search:return oo;case p.InputMap:return ls;case p.OutputMap:return ta;case p.ArgumentDeclaration:return ns;case p.Property:return us;case p.InstalledProject:return uo;case p.Project:return V;case p.DataType:return Zr;case p.GlobalEvent:return to;case p.InternalCall:return po;case p.ValueDescriptor:return hl;case p.BuiltInBaseEntity:return Oa;case p.PrimitiveEntity:return Rn;case p.ActionDescriptor:return Ut;case p.LiteralValue:return Pr;case p.ContinueStatement:return fo;case p.BreakStatement:return co;default:return null}}function Hr(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?Hr(v,u,c):null}else return e===u?u:Hr(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 _d(d,u){if(vn.includes(d.type))return Y.warn(`getRootEntryPointScopeOwner is \`null\` because it was called with a built-in entity type: ${d.type}`),null;if(u.getBuiltIn(d.id))return Y.warn(`getRootEntryPointScopeOwner is \`null\` because it was called with a built-in entity: ${d.id}`),null;const i=mn(d.parent,u);return i?i===u?Xi.includes(d.type)?d:(Y.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:_d(i,u):(Y.warn(`getRootEntryPointScopeOwner is \`null\` because it was called with an entity that has no parent: ${d.id}`),null)}function X0(d,u,i){if(d===u||u===i||d===i||!d||!u)return!1;const a=Hr(u.parent,i);return a===i?!1:a===d?!0:X0(a,u,i)}var Q0=(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))(Q0||{});function Ds(d,u,i){const a=Hr(d,i),l=Hr(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(X0(a,l,i))return{compatible:!0,type:"b-in-a",commonAncestorScope:a};if(X0(l,a,i))return{compatible:!0,type:"a-in-b",commonAncestorScope:l};const y=Hw(a,l);return y===i?{compatible:!1,type:"parallel-in-project",commonAncestorScope:y}:y?{compatible:!1,type:"parallel-in-common-parent",commonAncestorScope:Hr(y,i)}:{compatible:!1,type:"parallel-in-project",commonAncestorScope:i}}function vJ(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=Hr(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=Hr(l.parent,i)}let c=Hr(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=Hr(c.parent,i)}return null}function TJ(d){return d.length===0?null:d.length===1?d[0]:d.reduce((i,a)=>{const l=vJ(i,a,a.project);return!l||l===a?i:a},d[0])}function mn(d,u){if(!d)return null;let i;return typeof d=="string"?i=d:d.type===p.GenericReference?i=te(d):i=d.id,i===u.id?u:u.get(i)}function wo(d){if(!d)return null;if(vn.includes(d.type))return d;if(d.type===p.Project)return null;if(d.project.getBuiltIn(d.id))return d;const u=d.parent;return!u||u.type===p.Project?null:wo(u)}function hy(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=_d(d,d.project);return l?(d.calledBySuccess.forEach(c=>{[...c.successCalls||[]].forEach(v=>{xt.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=hy(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=>{xt.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=hy(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=>{xt.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=hy(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 DNe(d){return sc.includes(d.type)?d.type===p.FunctionDeclaration?!Qw(d):!0:!1}function ONe(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 ev(d,u){return d.type===p.BuiltInBaseEntity?d.name===u:!!Ao(d).includes(u)}function PNe(d,u){return d.type===p.BuiltInBaseEntity?d.name===u:!!cy(d).includes(u)}function $Ne(d){const u=[];return d.entities.forEach(i=>{if(ev(i,fe.PERSISTED_ENTITY)){u.push(i);return}}),C(u)}function NNe(d){const u=[];return d.entities.forEach(i=>{if(ev(i,fe.RELATIONAL_DATABASE)){u.push(i);return}}),C(u)}function VNe(d){return d.type!==p.DefinitionEntity||d.abstract||!ev(d,fe.PERSISTED_ENTITY)?null:(d==null?void 0:d.properties.find(i=>i.implements.find(a=>a.id===pe[p.BuiltInBaseEntity][fe.PERSISTED_ENTITY].properties.primaryKey.id)&&!i.abstract))||null}function EJ(d){var a;const u=Yw(d);if(!u)return null;const i=u.properties.find(l=>l.implements.find(c=>c.id===pe[p.BuiltInBaseEntity][fe.PERSISTED_ENTITY].properties.database.id));return i?(a=i.getDefaultValue())==null?void 0:a.valueAsType:null}function fp(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===pe[p.BuiltInBaseEntity][fe.PERSISTED_ENTITY].properties.database.id)&&!a.abstract);return u.push(...i),u}function LNe(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===pe[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(!Bg.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 BNe(d){switch(d){case p.Project:return V;case p.InstalledProject:return uo;case p.DefinitionEntity:return Os;case p.FunctionDeclaration:return Ia;case p.GlobalEvent:return to;case p.VariableInstance:return ao;case p.VariableDeclaration:return lo;case p.InputMap:return ls;case p.OutputMap:return ta;case p.Condition:return ro;case p.Operation:return eo;case p.FunctionCall:return Eo;case p.ArgumentDeclaration:return ns;case p.PrimitiveEntity:return Rn;case p.DataType:return Zr;case p.Property:return us;case p.ActionDescriptor:return Ut;case p.ReturnStatement:return cl;case p.ContinueStatement:return fo;case p.BreakStatement:return co;case p.Loop:return io;case p.Search:return oo;case p.ValueDescriptor:return hl;case p.InternalCall:return po;case p.LiteralValue:return Pr}return null}function MNe(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=cp(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=cp(d.type);if(!l)return a;l.MUTABLE_META_PROPERTIES.forEach(c=>{["x","y","collapsed"].includes(c)||delete a[c]})}return a}function tv(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,...tv(a,u)]:[]}function xNe(d){const u=[],i=new Set;return[...d.listAdded,...d.listUpdated,...d.listAffected].forEach(a=>{var e;const l=Pi(a);if(!l||i.has(l.id))return;const c=d.project.get(a.id)||d.project.getDeleted(a.id);if(!c)throw new Error(`[getTouchedCanvasEntitiesFromChangeSet] Could not find active version of ${a.type} ${a.id} in project, which is present in the change set.${a.parent?` With parent ${(e=a.parent)==null?void 0:e.type} ${te(a.parent)}`:""}`);i.add(l.id),u.push(c)}),C(u)}function UNe(d){if(d.type===p.Condition)return null;if(d.type===p.Search)return d.project.getBuiltIn(pe["value-descriptor"][hh.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 bJ(d){const u=d.entities.filter(l=>!!l.implements.find(c=>c.id===pe["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===pe["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 eR(d,u){const i=Array.from(new Set([...u.getAllBuiltInIds(),...Kn()]));return!!(i.includes(d.id)||!tv(d,{...u.instances,...u.builtInInstances}).every(c=>!i.includes(c)))}function IJ(d){if(!d)return null;if(d.type===p.Project)return d.id;const u=d.parent;return u?IJ(u):d.id}function my(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=_d(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 tR(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=_d(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 jNe(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 iR(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=iR(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=iR(u.extends,d);if(e)return e}}return null}function Dd(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 Dd(d.implements);if(d.extends)return Dd(d.extends)}return d}function Il(d){var u;return!!(d.required||(u=d.declaration)!=null&&u.required)}function Ro(d){return f6(d)||d===void 0||d===""}function ds(d){return d?d.valueAsType?!1:Ro(d.value):!0}function vy(d){return d.replace(/["'`]/g,"")}function Bi(d){const i=vy(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 Od(d){return vy(d).split(/[\s-]+/).filter(a=>a.length>0).map(a=>a[0].toUpperCase()+a.slice(1)).join("")}function AJ(d){const u=vy(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 GNe(d){const u=vy(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 iv(d){return AJ(d).toLowerCase()}function rR(d){const u=vy(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 yp(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(A=>{const b=yp(A),O=Mu(b);v&&(y+=" and "),A.isGroup?y+="("+O+")":v?y+=O:y+=b,v=!0,T=!0}),(d.orChildrenGroup||[]).forEach(A=>{const b=yp(A),O=Mu(b);v&&(T&&(y+=","),y+=" or "),A.isGroup?y+="("+O+")":v?y+=O:y+=b,v=!0}),e?`List of ${Mu(y)}`:y}if(d.entity.type===p.PrimitiveEntity){let e=d.entity.name;switch(d.entity.name){case re.String:e="Text";break;case re.KeyValue:e="Data structure";break}return d.isList?`List of ${e}s${u}`:`${e.slice(0,1).toUpperCase()}${e.slice(1)}${u}`}else if(d.entity.type===p.DefinitionEntity){const e=S(d.entity,d.project);return d.isList?`List of ${e} values${u}`:e.slice(0,1).toUpperCase()+e.slice(1)+u}else if(d.entity.type===p.BuiltInBaseEntity){const e=RJ(d.entity);return d.isList?`List of ${e} values${u}`:e.slice(0,1).toUpperCase()+e.slice(1)+u}else if(d.entity.type===p.LiteralValue){if(d.entity.name===re.Null)return"Empty value";if(d.entity.name===re.Untyped)return"Untyped value";if(d.entity.name===re.File)return"File";if(d.entity.name===re.String)return`"${d.entity.value}" text`;if(d.entity.name===re.Number)return`Number '${d.entity.value}'`;if(d.entity.name===re.Boolean)return`${d.entity.value} value`;if(d.entity.name===re.UUID)return`"${d.entity.value}" unique identifier`;if(d.entity.name===re.Date)return`"${d.entity.value}" date`}return d.isList?`List of ${S(d.entity,d.project)} values${u}`:`${S(d.entity,d.project).slice(0,1).toUpperCase()+S(d.entity,d.project).slice(1)} value${u}`}function kNe(d){if(!d)return"Any data type";const u=d.getDataType(null);return yp(u)}function rv(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 Ir.Empty:return"is empty";case Ir.NotEmpty:return"is present"}}function wJ(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 rR(d[0])}catch(u){return console.error("Error resolving base entity name for base entities:",d,u),"Built-in base entity"}}function RJ(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 rR(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 FNe(d){const u=S0(d);if(!u){const i=pp(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 CJ(d){let u="Find ";return d.outputs.forEach((i,a)=>{const l=f0(i,null),c=Mu(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 gJ(d){switch(d.name){case re.String:return"Text";case re.Number:return"Number";case re.Boolean:return"Boolean";case re.KeyValue:return"Data structure";case re.UUID:return"Unique identifier";case re.Date:return"Date";case re.EntityTemplate:return"Entity as template";case re.Enum:return"Enumeration";case re.File:return"File";case re.Null:return"Empty";case re.ActionDescriptor:return"Action descriptor";case re.Untyped:return"Untyped";default:return d.name}}function _J(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 ze.AddIndex:return"Add at index position";case ze.DeleteFirst:return"Delete first character";case ze.DeleteLast:return"Delete last character";case ze.DeleteIndex:return"Delete at index position";case ze.Join:return"Join texts";case ze.ReplaceAllMatches:return"Replace all matches";case ze.ReplaceFirst:return"Replace first match";case ze.ReplaceLast:return"Replace last match";case ze.Split:return"Split text";case ze.ReplaceIndex:return"Replace at index position";case ze.ReplaceSingleMatch:return"Replace single match";case ze.GetFirst:return"Get first character";case ze.GetLast:return"Get last character";case ze.GetIndexItem:return"Get at index position";case ze.GetIndexOf:return"Get the index number of the character";case ze.Append:return"Add at the end";case ze.Prepend:return"Add at the start";case Ei.Wait:return"Wait";case Ei.Parallel:return"Run in parallel";case Ei.Sequential:return"Run in sequence";case pn.HttpRequest:return"HTTP request";case 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 Gs.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(Ar).includes(a))switch(a){case Ar.AbortExecution:return"Abort ongoing execution";case Ar.DeletePersistedEntity:return"Delete entry from database";case Ar.CreatePersistedEntity:return"Save new data entry in database";case Ar.UpdatePersistedEntity:return"Update entity data to database";default:return ir(d.type).replaceAll("-"," ")}return a}if(p.BuiltInBaseEntity===d.type)return wJ([d.name]);if(Vg.includes(d.type)&&d.type!==p.ActionDescriptor)return d.name;switch(d.type){case p.Search:return CJ(d);case p.GlobalEvent:return d.implements?S(d.implements,u):ir(d.type).replaceAll("-"," ");case p.Operation:case p.InternalCall:case p.Loop:const a=mn(d.declaration,u);return S(a,u);case p.ActionDescriptor:return _J(d);case p.BreakStatement:const l=mn(d.parent,u);return`Stop loop ${S(l,u)}`;case p.ContinueStatement:const c=mn(d.parent,u);return`Execute next iteration of ${S(c,u)}`;case p.FunctionCall:return mn(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} ${rv(y)} ${T}`}return`If ${v} ${rv(y)}`}else return`If ${rv(y)}`}case p.ReturnStatement:{const y=mn(d.parent,u);return y?`Output of ${S(y,u)}`:"Return statement"}case p.InputMap:if(d.declaration){const y=mn(d.declaration,u);return S(y,u)||""}else{if(!d.name)throw new Error(`Input map entity with id "${d.id}" has no name and no declaration.`);return d.name||""}case p.VariableInstance:{const y=mn(d.declaration,u);return S(y,u)||""}case p.OutputMap:if(d.declaration){const y=mn(d.declaration,u);return(y==null?void 0:y.name)||""}else return d.parentRelationType===Dl.Error?"Undeclared error":"";case p.PrimitiveEntity:case p.LiteralValue:return gJ(d);default:return ir(d.type).replaceAll("-"," ")}}function nR(d,u){const i=[];d.name||i.push(new ue({id:`${d.id}--${oe.EmptyName}`,message:`Entity with id "${d.id}" and type "${d.type}" has an empty name. Please provide a 'name' string.`,severity:ee.Error,code:oe.EmptyName}));const a=u.entities.filter(l=>l.name===d.name);return a.length&&i.push(new ue({id:`${d.id}--${oe.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:oe.NameNotUniqueInScope})),i}function sR(d,u){const i=[];d.name||i.push(new ue({id:`${d.id}--${oe.EmptyName}`,message:`Entity with id "${d.id}" and type "${d.type}" has an empty name. Please provide a 'name' string.`,severity:ee.Error,code:oe.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 ue({id:`${d.id}--${oe.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:oe.NameNotUniqueInScope})),i}function aR(d,u){const i=[];d.name||i.push(new ue({id:`${d.id}--${oe.EmptyName}`,message:`Entity with id "${d.id}" and type "${d.type}" has an empty name. Please provide a 'name' string.`,severity:ee.Error,code:oe.EmptyName}));const a=d.parent&&mn(d.parent,u)||u;if(!a)i.push(new ue({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=yw(a).filter(e=>e.name===d.name);c.length&&i.push(new ue({id:`${d.id}--${oe.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:oe.NameNotUniqueInScope}))}return i}function lR(d,u){const i=[];d.name||i.push(new ue({id:`${d.id}--${oe.EmptyName}`,message:`Entity with id "${d.id}" and type "${d.type}" has an empty name. Please provide a 'name' string.`,severity:ee.Error,code:oe.EmptyName}));const a=te(d.parent);if(!a)i.push(new ue({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 ue({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 ue({id:`${d.id}--${oe.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.6566",
|
|
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",
|