@elyx-code/project-logic-tree 0.0.6409 → 0.0.6411
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.d.ts +1 -1
- package/dist/index.js +2 -2
- package/dist/index.umd.cjs +2 -2
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -14234,7 +14234,7 @@ export declare function resolveCardSubheader(entity: CanvasEntityState): string;
|
|
|
14234
14234
|
|
|
14235
14235
|
export declare function resolveClonedEntityProject(newParent: EntityState | null, self: EntityState): ProjectState;
|
|
14236
14236
|
|
|
14237
|
-
export declare function resolveConditionOperatorLabel(condition: ConditionState): "and" | "or" | "is equal to" | "is not equal to" | "is greater than" | "is greater than or equal to" | "is less than" | "is less than or equal to" | "is empty" | "is
|
|
14237
|
+
export declare function resolveConditionOperatorLabel(condition: ConditionState): "and" | "or" | "is equal to" | "is not equal to" | "is greater than" | "is greater than or equal to" | "is less than" | "is less than or equal to" | "is empty" | "is present" | undefined;
|
|
14238
14238
|
|
|
14239
14239
|
export declare function resolveDataType(entity: EntityWithValueState | PropertyState | ValueDescriptorState, changeSet?: ChangeSet | null): DataTypeState | null;
|
|
14240
14240
|
|
package/dist/index.js
CHANGED
|
@@ -103223,7 +103223,7 @@ function ZT(d) {
|
|
|
103223
103223
|
case ai.Empty:
|
|
103224
103224
|
return "is empty";
|
|
103225
103225
|
case ai.NotEmpty:
|
|
103226
|
-
return "is
|
|
103226
|
+
return "is present";
|
|
103227
103227
|
}
|
|
103228
103228
|
}
|
|
103229
103229
|
function a_t(d) {
|
|
@@ -105165,7 +105165,7 @@ ${PI}`,
|
|
|
105165
105165
|
)
|
|
105166
105166
|
), l = null) {
|
|
105167
105167
|
const p = l || P.UUID.uuid(), e = Ot.new(a);
|
|
105168
|
-
e.id = p, e.name = this.name, e.description = this.description, e.index = this.index, e.private = this.private, e.required = this.required, e.static = this.static, e.constant = this.constant, e.hidden = this.hidden, e.parent = i.toReference(), e.implements = this.toJSON();
|
|
105168
|
+
e.id = p, e.name = this.name, e.description = this.description, e.index = this.index, e.private = this.private, e.required = this.required, e.static = this.static, e.constant = this.constant, e.hidden = this.hidden, e.interactive = this.interactive, e.parent = i.toReference(), e.implements = this.toJSON();
|
|
105169
105169
|
const y = ee(
|
|
105170
105170
|
e,
|
|
105171
105171
|
this.project
|
package/dist/index.umd.cjs
CHANGED
|
@@ -393,7 +393,7 @@ All global 'function-declaration' entity ids are:
|
|
|
393
393
|
The project currently has no global 'function-declaration' entities that can be called as 'function-call' entities.`;p.push(new ee({id:`${l.id}--${k.InvalidReference}`,code:k.InvalidReference,severity:q.Error,message:`Entity of type "${f.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.
|
|
394
394
|
References can either be an ID string or an object with exacly four properties: 'id', 'entityId', 'entityType', 'type'.${v}`,issue:null}))}return{errors:p,modifiedData:l}}validateGeneratedUpdate(i){const a=[];return i.parent&&a.push(new ee({id:`${this.id}--${k.InvalidParentUpdate}`,code:k.InvalidParentUpdate,severity:q.Error,message:`Entity of type '${this.type}' with id '${this.id}' cannot have the 'parent' property updated. The 'parent' on a callable entity, is its scope. It scope is auto-calculated implicitly by the its caller.
|
|
395
395
|
If an entity is called by another, they must be in the same scope, which means they have the same parent.
|
|
396
|
-
You shouldn't have to manually update a 'parent' property. The equivalent result is to change its callers, the value writters of its inputs, or the value readers of its outputs.`,issue:null})),{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 F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"sync-dependents"))){const a=[],l=[],p=[],e=[];return Object.values(this.detachedDependents).forEach(y=>{const v=y.entity.afterAllChildrenInitialized(i);a.push(...v.updated),l.push(...v.added),p.push(...v.removed),e.push(...v.affected)}),i==null||i.attemptAutoclose("sync-dependents",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(e),self:this}}onDetachedDependencyRemoved(i,a,l){const p=[],e=[],y=[],v=[];if(a==="declaration"){const{updated:E,added:w,removed:A}=this.remove({ignoreUpstream:!1},l);p.push(...E),e.push(...w),y.push(...A)}if(a==="parent"){const{updated:E,added:w,removed:A}=this.remove({ignoreUpstream:!1},l);p.push(...E),e.push(...w),y.push(...A)}return{updated:R(p),added:R(e),removed:R(y),affected:R(v),self:this}}onDetachedDependencyRestored(i,a,l){const p=[],e=[],y=[],v=[];if(a==="declaration"){const{updated:E,added:w,removed:A}=this.restore({},l);p.push(...E),e.push(...w),y.push(...A)}if(a==="parent"){const{updated:E,added:w,removed:A}=this.restore({},l);p.push(...E),e.push(...w),y.push(...A)}return{updated:R(p),added:R(e),removed:R(y),affected:R(v),self:this}}unsubscribeFromDependencies(){var i;return(i=this.parent)==null||i.unsubscribeDependents([{entity:this,field:"parent"}]),this.declaration.unsubscribeDependents([{entity:this,field:"declaration"}]),this}subscribeToDependencies(){var i;return(i=this.parent)==null||i.subscribeDependents([{entity:this,field:"parent"}]),this.declaration.subscribeDependents([{entity:this,field:"declaration"}]),this}increaseVersion(i){if(i&&!L(i).isValid())throw new Error(`The shared timestamp '${i}' is not a valid ISO 8601 date string.`);return i&&L(i).isSame(L(this.createdAt))?this:(this.previousVersion=this.version,this.version=N.UUID.uuid(),this.createdAt=L(i).toISOString()||L().toISOString(),this)}captureVersion(){var a;const i=((a=this.knownVersions)==null?void 0:a.get(this.version))||new Qt(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.process=this.process,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=[],p=[],e=[];if(this.parent){this.parent.increaseVersion(i);const y=this.parent.recursiveCaptureUpstreamVersions(i);a.push(this.parent,...y.updated),l.push(...y.added),p.push(...y.removed)}return{updated:R(a),added:R(l),removed:R(p),affected:R(e),self:this}}async restoreVersion(i){var v;const a=[],l=[],p=[],e=[];if(this.version===i)return{updated:R(a),added:R(l),removed:R(p),affected:R(e),self:this};if(!this.knownVersions){const E=new Map;for(const[w,A]of this.knownVersions||new Map){if(E.set(w,A),A.activeVersion=!1,A.knownVersions)for(const[$,V]of A.knownVersions)E.set($,V);A.knownVersions=null}}let y=(v=this.knownVersions)==null?void 0:v.get(i);if(!y){const E=await this.APILoadVersion({},i);if(!E)throw new Error(`Version with id '${i}' for entity with id '${this.id}' not found.`);y=new Qt(E,this.project)}return this.metaSync(y.toShallowJSON(),null),this.previousVersion=y.previousVersion,this.version=y.version,this.createdAt=y.createdAt,this.author=y.author,this.deleted=y.deleted,this.inputs=y.inputs,this.outputs=y.outputs,this.error=y.error,this.successCalls=y.successCalls,this.errorCalls=y.errorCalls,this.process=y.process,this.declaration=y.declaration,this.calledBySuccess=y.calledBySuccess,this.calledByError=y.calledByError,this.calledByEntry=y.calledByEntry,this.parent=y.parent,{updated:R(a),added:R(l),removed:R(p),affected:R(e),self:this}}updateWithShallowTransfer(i,a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"update-with-shallow-transfer"))){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=Z(i.parent),p=this.project.get(l),e=this.parent;if(e&&e.id!==(p==null?void 0:p.id)&&this.removeFromParent(a),p)this.setParent(p,a);else throw a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(i.declaration){const l=Z(i.declaration),p=this.project.get(l);p&&this.setDeclaration(p)}return i.calledByEntry.forEach(l=>{const p=Z(l),e=this.project.get(p);e&&(this.addEntryCaller(e,a),e.addCall(this,a))}),[...this.calledByEntry].forEach(l=>{i.calledByEntry.find(e=>Z(e)===l.id)||(this.removeCaller(l,a),l.removeCall(this,a))}),i.calledBySuccess.forEach(l=>{const p=Z(l),e=this.project.get(p);e&&(this.addSuccessCaller(e,a),e.addSuccessCall(this,a))}),[...this.calledBySuccess].forEach(l=>{i.calledBySuccess.find(e=>Z(e)===l.id)||(this.removeCaller(l,a),l.removeCall(this,a))}),i.calledByError.forEach(l=>{const p=Z(l),e=this.project.get(p);e&&(this.addErrorCaller(e,a),e.addErrorCall(this,a))}),[...this.calledBySuccess].forEach(l=>{i.calledBySuccess.find(e=>Z(e)===l.id)||(this.removeCaller(l,a),l.removeCall(this,a))}),this.captureVersion(),this.subscribeToDependencies(),a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),this}hydrateAncestors(){const i=[],a=[],l=[],p=[];if(this.initialData.parent){const e=Z(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=Z(this.initialData.declaration),y=this.project.get(e);y&&(this.setDeclaration(y),i.push(y))}return this.initialData.calledByEntry.forEach(e=>{const y=Z(e),v=this.project.get(y);v&&this.addEntryCaller(v,null)}),this.initialData.calledBySuccess.forEach(e=>{const y=Z(e),v=this.project.get(y);v&&this.addSuccessCaller(v,null)}),this.initialData.calledByError.forEach(e=>{const y=Z(e),v=this.project.get(y);v&&this.addErrorCaller(v,null)}),{updated:R(i),added:R(a),removed:R(l),affected:R(p),self:this}}afterAllChildrenInitialized(i=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"after-all-children-initialized"))){const a=[],l=[],p=[],e=[];this.initialized=!0;const{updated:y,added:v,removed:E}=this.syncInputs(i),{updated:w,added:A,removed:$}=this.syncOutputs(i);return a.push(...y,...w),l.push(...v,...A),p.push(...E,...$),this.captureVersion(),i==null||i.attemptAutoclose("after-all-children-initialized",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(e),self:this}}addSelfToProject(i=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-self-to-project"))){var y;const a=[this],l=[],p=[],e=[];return this.parent===this.project&&this.project.addFunctionCall(this),(y=this.process)==null||y.writesValues.forEach(v=>{v.setValueWriter(this.process,i),a.push(v)}),this.successCalls.forEach(v=>{v.addSuccessCaller(this,i),a.push(v)}),this.errorCalls.forEach(v=>{v.addErrorCaller(this,i),a.push(v)}),this.calledBySuccess.forEach(v=>{v.addSuccessCall(this,i),a.push(v)}),this.calledByError.forEach(v=>{v.addErrorCall(this,i),a.push(v)}),this.calledByEntry.forEach(v=>{v.addCall(this,i),a.push(v)}),this.subscribe(),this.subscribeToDependencies(),i==null||i.attemptAutoclose("add-self-to-project",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(e),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}removeInput(i,a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-input"))){const l=this.inputs.findIndex(p=>p.id===i.id);return l>-1&&(this.inputs.splice(l,1),a&&(a==null||a.add(this,S.Affected))),a==null||a.attemptAutoclose("remove-input",this.id),this}addInput(i,a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-input"))){return this.inputs.includes(i)?(a==null||a.attemptAutoclose("add-input",this.id),this):(this.inputs.push(i),a==null||a.add(this,S.Affected),a==null||a.attemptAutoclose("add-input",this.id),this)}addOutput(i,a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-output"))){return this.outputs.includes(i)?(a==null||a.attemptAutoclose("add-output",this.id),this):(this.outputs.push(i),a==null||a.add(this,S.Affected),a==null||a.attemptAutoclose("add-output",this.id),this)}removeOutput(i,a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-output"))){const l=this.outputs.findIndex(p=>p.id===i.id);return l>-1&&(this.outputs.splice(l,1),a&&(a==null||a.add(this,S.Affected))),a==null||a.attemptAutoclose("remove-output",this.id),this}addValueReader(i,a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-value-reader"))){var l;return this.process&&!this.process.writesValues.includes(i)&&((l=this.process)==null||l.addValueReader(i,a),a==null||a.add(this,S.Affected)),a==null||a.attemptAutoclose("add-value-reader",this.id),this}removeValueReader(i,a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-value-reader"))){var l;return this.process&&this.process.writesValues.includes(i)&&((l=this.process)==null||l.removeValueReader(i,a),a==null||a.add(this,S.Affected)),a==null||a.attemptAutoclose("remove-value-reader",this.id),this}addSuccessCaller(i,a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-success-caller")),l=!1){return this.calledBySuccess.find(p=>p.id===i.id)||(this.calledBySuccess.push(i),a==null||a.add(this,S.Updated),l&&We(this,a)),a==null||a.attemptAutoclose("add-success-caller",this.id),this}addErrorCaller(i,a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-error-caller")),l=!1){return this.calledByError.find(p=>p.id===i.id)||(this.calledByError.push(i),a==null||a.add(this,S.Updated),l&&We(this,a)),a==null||a.attemptAutoclose("add-error-caller",this.id),this}addEntryCaller(i,a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-entry-caller")),l=!1){return this.calledByEntry.find(p=>p.id===i.id)||(this.calledByEntry.push(i),a==null||a.add(this,S.Updated),l&&We(this,a)),a==null||a.attemptAutoclose("add-entry-caller",this.id),this}addErrorCall(i,a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-error-call")),l=!1){return this.errorCalls.find(p=>p.id===i.id)||(this.errorCalls.push(i),l&&We(this,a),a==null||a.add(this,S.Affected)),a==null||a.attemptAutoclose("add-error-call",this.id),this}addSuccessCall(i,a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-success-call")),l=!1){return this.successCalls.find(p=>p.id===i.id)||(this.successCalls.push(i),l&&We(this,a),a==null||a.add(this,S.Affected)),a==null||a.attemptAutoclose("add-success-call",this.id),this}removeCall(i,a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-call")),l=!1){const p=this.successCalls.findIndex(y=>y.id===i.id);p>-1&&(this.successCalls.splice(p,1),a==null||a.add(this,S.Affected));const e=this.errorCalls.findIndex(y=>y.id===i.id);return e>-1&&(this.errorCalls.splice(e,1),a==null||a.add(this,S.Affected)),l&&We(this,a),a==null||a.attemptAutoclose("remove-call",this.id),this}removeCaller(i,a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-caller")),l=!1){return this.calledBySuccess=this.calledBySuccess.filter(p=>p.id!==i.id?!0:(a==null||a.add(this,S.Updated),a==null||a.add(p,S.Affected),!1)),this.calledByError=this.calledByError.filter(p=>p.id!==i.id?!0:(a==null||a.add(this,S.Updated),a==null||a.add(p,S.Affected),!1)),this.calledByEntry=this.calledByEntry.filter(p=>p.id!==i.id?!0:(a==null||a.add(this,S.Updated),a==null||a.add(p,S.Affected),!1)),l&&We(this,a),a==null||a.attemptAutoclose("remove-caller",this.id),this}setParent(i,a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"set-parent"))){var l;return((l=this.parent)==null?void 0:l.id)!==(i==null?void 0:i.id)&&(this.parent=i,a&&(a==null||a.add(this,S.Updated))),a==null||a.attemptAutoclose("set-parent",this.id),this}setDeclaration(i){return this.declaration=i,this}initChildren(i=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"init-children"))){if(this.initialized||this.startedInitialization)return this;if(this.startedInitialization=!0,this.initialData.declaration.type===f.FunctionDeclaration){const a=te(this.initialData.declaration,this.project);this.declaration=a}else{const a=Z(this.initialData.declaration),l=this.project.get(a);this.declaration=l}return this.successCalls=this.initialData.successCalls.map(a=>{const l=te(a,this.project);if(l.addSuccessCaller(this),[f.BreakStatement,f.ContinueStatement].includes(l.type))l.setParent(this.parent.parent,null),l.initChildren(i);else if(l.type===f.ReturnStatement){const p=Wr(this,this.project);l.setParent(p,null),l.initChildren(i)}else l.type!==f.InternalCall&&(l.setParent(this.parent,null),l.initChildren(i));return l}),this.errorCalls=this.initialData.errorCalls.map(a=>{const l=te(a,this.project);if(l.addErrorCaller(this),[f.BreakStatement,f.ContinueStatement].includes(l.type))l.setParent(this.parent.parent,null),l.initChildren(i);else if(l.type===f.ReturnStatement){const p=Wr(this,this.project);l.setParent(p,null),l.initChildren(i)}else l.type!==f.InternalCall&&(l.setParent(this.parent,null),l.initChildren(i));return l}),this.inputs=this.initialData.inputs.map(a=>{const l=te(a,this.project);return l.setParent(this,null),l.initChildren(i),l}),this.initialData.process&&(this.process=te(this.initialData.process,this.project),this.process.setParent(this,null),this.process.initChildren(i)),this.initialData.error&&(this.error=te(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 F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"meta-sync"))){const l=Ur(this,i),p=this.toMeta();return this.x=i.x||p.x,this.y=i.y||p.y,super.metaSync(i),i.deleted===!0&&!p.deleted?a==null||a.add(this,S.Removed):i.deleted===!1&&p.deleted?a==null||a.add(this,S.Added):l&&(a==null||a.add(this,S.Updated)),a==null||a.attemptAutoclose("meta-sync",this.id),this}async APILoad(i=ve,...a){return await Qt.repository.APILoad(this.id,...a),this}async APICreate(i=ve,...a){return await Qt.repository.APICreate(this.toShallowJSON(),...a),this}async APIUpdate(i=ve,...a){return await Qt.repository.APIUpdate(this.toShallowJSON(),...a),this}async APIDelete(i=ve,...a){return await Qt.repository.APIDelete(this.toShallowJSON(),...a),this}async APIClone(i=ve,...a){return await Qt.repository.APIClone(this.id,...a),this}async APILoadVersion(i=ve,a,...l){return await Qt.repository.APILoadVersion(this.id,a,...l)}removeFromParent(i=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-from-parent"))){const a=[],l=[],p=[],e=[];return this.parent.type===f.Project?(this.parent.removeFunctionCall(this),e.push(this.parent)):this.parent.detachedChildren.includes(this)&&this.parent.unsubscribeDetachedChild(this),i==null||i.attemptAutoclose("remove-from-parent",this.id),{added:R(p),updated:R(a),removed:R(l),affected:R(e),self:this}}remove({ignoreUpstream:i}={ignoreUpstream:!1},a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-entity"))){var v;const l=[],p=[],e=[],y=[];if(a!=null&&a.hasRemoved(this.id))return a==null||a.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(p.push(this),this.unsubscribe(),this.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},a),Object.values(this.detachedDependents).forEach(E=>{const{updated:w,removed:A,added:$}=E.entity.onDetachedDependencyRemoved(this,E.field,a);l.push(...w),p.push(...A),e.push(...$)}),this.process){const{updated:E,removed:w}=(v=this.process)==null?void 0:v.remove({ignoreUpstream:!0},a);l.push(...E),p.push(...w)}if(this.inputs.forEach(E=>{const{updated:w,removed:A}=E.remove({ignoreUpstream:!0},a);l.push(...w),p.push(...A)}),this.outputs.forEach(E=>{const{updated:w,removed:A}=E.remove({ignoreUpstream:!0},a);l.push(...w),p.push(...A)}),this.error){const{updated:E,removed:w}=this.error.remove({ignoreUpstream:!0},a);l.push(...E),p.push(...w)}if(this.successCalls.forEach(E=>{l.push(E),E.removeCaller(this,a)}),this.errorCalls.forEach(E=>{l.push(E),E.removeCaller(this,a)}),!i){const E=this.removeFromParent(a);e.push(...E.added),l.push(...E.updated),p.push(...E.removed),y.push(...E.affected),this.calledBy.forEach(w=>{l.push(w),w.removeCall(this,a)})}return a==null||a.attemptAutoclose("remove-entity",this.id),{added:R(e),updated:R(l),removed:R(p),affected:R(y),self:this}}restore({}={},i=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"restore-entity"))){const a=[],l=[],p=[],e=[];if(i!=null&&i.hasAdded(this.id))return i==null||i.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},i),Object.values(this.detachedDependents).forEach(y=>{const{updated:v,removed:E,added:w}=y.entity.onDetachedDependencyRestored(this,y.field,i);l.push(...v),p.push(...E),a.push(...w)}),this.process){const{updated:y}=this.process.restore({},i);l.push(...y)}return 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("restore-entity",this.id),{added:R(a),updated:R(l),removed:R(p),affected:R(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.process?this.process.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}}toJSON(i=new Set){var a,l;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,x:this.x,y:this.y,successCalls:this.successCalls.map(p=>p.toJSON(i)),errorCalls:this.errorCalls.map(p=>p.toJSON(i)),calledBySuccess:this.calledBySuccess.map(p=>p.toReference()),calledByError:this.calledByError.map(p=>p.toReference()),calledByEntry:this.calledByEntry.map(p=>p.toReference()),process:(a=this.process)==null?void 0:a.toJSON(i),declaration:this.declaration.toJSON(i),inputs:this.inputs.map(p=>p.toJSON(i)),outputs:this.outputs.map(p=>p.toJSON(i)),parent:this.parent.toReference(),error:(l=this.error)==null?void 0:l.toJSON(i)})}toJSONClone(i=ke){var l,p,e,y,v,E,w;let a;return(l=i.seenEntityMaps)!=null&&l.has(this.id)?a=i.seenEntityMaps.get(this.id):(a=i.newId||Gr(this,this.project,i.uuidStrategy),i.seenEntityMaps&&i.seenEntityMaps.set(this.id,a)),(p=i.seenEntities)!=null&&p.has(a)||(e=i.seenEntities)!=null&&e.has(this.id)?this.toReference({seenEntityMaps:i.seenEntityMaps}):((y=i.seenEntities)==null||y.add(a),(v=i.seenEntities)==null||v.add(this.id),{id:a,version:N.UUID.uuid(),createdAt:i.timestamp||L().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,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})),process:(E=this.process)==null?void 0:E.toJSONClone({...i,newId:null}),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:(w=this.error)==null?void 0:w.toJSONClone({...i,newId:null}),parent:this.parent.toReference({seenEntityMaps:i.seenEntityMaps})})}toReference(i=ke){var l;let a=this.id;return(l=i.seenEntityMaps)!=null&&l.has(this.id)&&(a=i.seenEntityMaps.get(this.id)),{id:a+"--"+N.UUID.uuid()+"--ref",type:f.GenericReference,entityId:a,version:this.version,entityType:this.type}}toShallowJSON(i=ke){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,x:this.x,y:this.y,process:this.process?this.process.toReference(i):null,inputs:this.inputs.map(p=>p.toReference(i)),outputs:this.outputs.map(p=>p.toReference(i)),declaration:this.declaration.toReference(i),successCalls:this.successCalls.map(p=>p.toReference(i)),errorCalls:this.errorCalls.map(p=>p.toReference(i)),calledBySuccess:this.calledBySuccess.map(p=>p.toReference(i)),calledByError:this.calledByError.map(p=>p.toReference(i)),calledByEntry:this.calledByEntry.map(p=>p.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.process?this.process.toFlatJSON(i):[],...this.error?this.error.toFlatJSON(i):[]])}toGenerationTarget(){const i=this.parent.type===f.Project?void 0:this.parent.id;return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,calledByEntry:this.calledByEntry.map(a=>a.id),calledBySuccess:this.calledBySuccess.map(a=>a.id),calledByError:this.calledByError.map(a=>a.id),declaration:this.declaration.id,parent: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.process?this.process.toFlatGenerationTarget(i):[],...this.error?this.error.toFlatGenerationTarget(i):[]])}clearErrors(){var i,a;return this.errors=[],this.inputs.forEach(l=>l.clearErrors()),this.outputs.forEach(l=>l.clearErrors()),this.successCalls.forEach(l=>l.clearErrors()),this.errorCalls.forEach(l=>l.clearErrors()),(i=this.process)==null||i.clearErrors(),(a=this.error)==null||a.clearErrors(),this}validate(){const i=u5(this);return this.errors=i,{success:!0,error:null,data:this.toJSON()}}getErrors(){return[...this.errors,...this.inputs.flatMap(a=>a.getErrors()),...this.outputs.flatMap(a=>a.getErrors()),...this.error?this.error.getErrors():[],...this.process?this.process.getErrors():[]]}getShallowErrors(){return this.errors}clone(i=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"clone-entity")),a=null,l=null,p=!0){var U,G;let e=Fr(a,this);const y=this.toJSON(),v=l||N.UUID.uuid();y.inputs=[];const E=v.split("-id"),w=E[E.length-1||0]||v;y.id=v,y.version=N.UUID.uuid(),y.createdAt=(i==null?void 0:i.timestamp)||L().toISOString(),y.author=(i==null?void 0:i.author)||"1",y.previousVersion=null,y.deleted=!1;const A=or(y,e);a?A.setParent(a,null):A.setParent(this.parent,null),p&&A.subscribe(),A.initChildren(i),i==null||i.add(A,S.Added);const $=(U=this.inputs)==null?void 0:U.map((K,J)=>K.clone(i,A,w+"-input-map-"+J+"-id",p));A.inputs=$;const V=(G=this.outputs)==null?void 0:G.map((K,J)=>K.clone(i,A,w+"-output-map-"+J+"-id",p));return A.outputs=V,this.error&&(A.error=this.error.clone(i,A,w+"-error-map-id",p)),this.process&&(A.process=this.process.clone(i,A,w+"-process-id",p)),i==null||i.attemptAutoclose("clone-entity",this.id),A}removeUnrecognizedInputs(i=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-unrecognized-inputs"))){const a=[],l=[],p=[],e=[];return this.inputs.forEach(v=>{if(!this.declaration.inputs.find(w=>{var A;return w.id===((A=v.declaration)==null?void 0:A.id)})){const w=v.remove({ignoreUpstream:!1},i);p.push(...w.removed),a.push(...w.updated)}}),this.inputs.filter((v,E)=>{const w=this.inputs.findIndex($=>$.declaration===v.declaration&&$!==v);if(w===-1)return!1;const A=this.inputs[w];return L(A==null?void 0:A.createdAt).isSame(L(v.createdAt))?E>w:!!L(A==null?void 0:A.createdAt).isAfter(v.createdAt)}).forEach(v=>{const E=v.remove({ignoreUpstream:!1},i);p.push(...E.removed),a.push(...E.updated)}),i==null||i.attemptAutoclose("remove-unrecognized-inputs",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(e),self:this}}removeUnrecognizedOutputs(i=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-unrecognized-outputs"))){const a=[],l=[],p=[],e=[];return this.outputs.forEach(v=>{if(!this.declaration.getUniqueReturnDeclarations().find(w=>{var A;return w.id===((A=v.declaration)==null?void 0:A.id)})){const w=v.remove({ignoreUpstream:!1},i);p.push(...w.removed),a.push(...w.updated)}}),this.outputs.filter((v,E)=>{const w=this.outputs.findIndex($=>$.declaration===v.declaration&&$!==v);if(w===-1)return!1;const A=this.outputs[w];return L(A==null?void 0:A.createdAt).isSame(L(v.createdAt))?E>w:!!L(A==null?void 0:A.createdAt).isAfter(v.createdAt)}).forEach(v=>{const E=v.remove({ignoreUpstream:!1},i);p.push(...E.removed),a.push(...E.updated)}),i==null||i.attemptAutoclose("remove-unrecognized-outputs",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(e),self:this}}syncInputs(i=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"sync-missing-fixed-inputs"))){const a=[],l=[],p=[],e=[],y=this.declaration.inputs.filter(A=>!this.inputs.find($=>$.declaration.id===A.id));this.inputs.sort((A,$)=>A.index-$.index),y.forEach(A=>{this.inputs.forEach(U=>{U.index>=A.index&&U.metaSync({index:U.index+1},i)});const $={id:N.UUID.uuid(),version:N.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||L().toISOString(),author:N.sessionAuthor,previousVersion:null,deleted:!1,type:f.InputMap,declaration:A.toJSON(),readsValue:null,defaultValue:null,index:A.index,name:null,codeName:null,description:null,parent:this.toReference()},V=te($,this.project);V.setParent(this,i),V.initChildren(i),i==null||i.add(V,S.Added),V.addSelfToProject(i),l.push(V)}),this.inputs.sort((A,$)=>A.index-$.index);const{updated:v,added:E,removed:w}=this.removeUnrecognizedInputs(i);return a.push(...v),l.push(...E),p.push(...w),i==null||i.attemptAutoclose("sync-missing-fixed-inputs",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(e),self:this}}syncOutputs(i=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"sync-missing-fixed-outputs"))){const a=[],l=[],p=[],e=[],y=[];this.outputs=this.initialData.outputs.reduce(($,V)=>{if(V.type===f.GenericReference){const G=ki(V,this.project);return G?[...$,G]:$}const U=te(V,this.project);return y.push(U.index),U.setParent(this,null),U.initChildren(i),[...$,U]},[]);const v=this.declaration.getUniqueReturnDeclarations().filter($=>!this.outputs.find(V=>V.declaration.id===$.id));this.outputs.sort(($,V)=>$.index-V.index),v.forEach(($,V)=>{this.outputs.forEach(J=>{J.index>=$.index&&J.index++});const U=y.includes($.index)?this.outputs.length-1+V:$.index,G={id:N.UUID.uuid(),version:N.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||L().toISOString(),author:N.sessionAuthor,previousVersion:null,deleted:!1,type:f.OutputMap,declaration:$.toJSON(),defaultValue:null,writesValues:[],index:U,parent:this.toReference()},K=te(G,this.project);K.setParent(this,i),K.initChildren(i),i==null||i.add(K,S.Added),K.addSelfToProject(i)}),this.outputs.sort(($,V)=>$.index-V.index);const{updated:E,added:w,removed:A}=this.removeUnrecognizedOutputs(i);return a.push(...E),l.push(...w),p.push(...A),i==null||i.attemptAutoclose("sync-missing-fixed-outputs",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(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)}};g(Qt,"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}),g(Qt,"type",f.FunctionCall),g(Qt,"USER_MANAGED_PARENT_TYPES",[...Mr,f.Project]),g(Qt,"PARENT_TYPES",[...Qt.USER_MANAGED_PARENT_TYPES]),g(Qt,"MUTABLE_BASE_PROPERTIES",[]),g(Qt,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),g(Qt,"BASE_PROPERTIES",[...Qt.MUTABLE_BASE_PROPERTIES,...Qt.INMUTABLE_BASE_PROPERTIES]),g(Qt,"MUTABLE_META_PROPERTIES",["x","y"]),g(Qt,"INMUTABLE_META_PROPERTIES",[...Qt.INMUTABLE_BASE_PROPERTIES]),g(Qt,"META_PROPERTIES",[...Qt.MUTABLE_META_PROPERTIES,...Qt.INMUTABLE_META_PROPERTIES]),g(Qt,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry"]),g(Qt,"INMUTABLE_UPSTREAM_PROPERTIES",["declaration","parent"]),g(Qt,"UPSTREAM_PROPERTIES",[...Qt.MUTABLE_UPSTREAM_PROPERTIES,...Qt.INMUTABLE_UPSTREAM_PROPERTIES]),g(Qt,"MUTABLE_DOWNSTREAM_PROPERTIES",["successCalls","errorCalls","writesValues","inputs","outputs","error"]),g(Qt,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),g(Qt,"DOWNSTREAM_PROPERTIES",[...Qt.MUTABLE_DOWNSTREAM_PROPERTIES,...Qt.INMUTABLE_DOWNSTREAM_PROPERTIES]),g(Qt,"PROPERTIES",[...Qt.META_PROPERTIES,...Qt.UPSTREAM_PROPERTIES,...Qt.DOWNSTREAM_PROPERTIES]);let Ao=Qt;function Ob(d){return d&&typeof d.then=="function"}function CIe(d){const u=new Qn(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 $Ie(d){const u=new Qn(Object.values(d)[0]),i=Object.keys(d);return u.order=i,u.flatRecord=d,u.orderEntities(),u.order}class Qn{constructor(u){g(this,"order",[]);g(this,"flatRecord",{});g(this,"allBuiltInEntityIds",Xs());g(this,"onGoingVisits",{});u&&(this.flatten(u),this.orderEntities())}flatten(u){const i=new Set(Xs()),a=R(me(u,i,{ignoreBuiltInBaseEntities:!0})),l=new Set;for(const p of a)this.flatRecord[p.id]=p,l.add(p.id);this.order=Array.from(l)}moveEntityAfterDependencies(u){const{upstream:i}=Qd(u,this.flatRecord,{ignoreBuiltInBaseEntities:!0,allBuiltInEntityIds:this.allBuiltInEntityIds});for(const a of Object.keys(i)){const l=this.order.indexOf(a),p=this.order.indexOf(u.id);if(l>p)return this.order.splice(p,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||Me.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}=Qd(this.flatRecord[u],this.flatRecord,{ignoreBuiltInBaseEntities:!0,allBuiltInEntityIds:this.allBuiltInEntityIds}),l={};return Object.entries(this.onGoingVisits[i]||{}).forEach(([p,e])=>{Object.keys(a).includes(p)&&(l[p]=e)}),l}getDownstreamOngoingDependenciesVisits(u,i){const a=Object.keys(this.onGoingVisits[i]||{}),l=new Set(a.flatMap(e=>Object.keys(Qd(this.flatRecord[e],this.flatRecord,{ignoreBuiltInBaseEntities:!0,allBuiltInEntityIds:this.allBuiltInEntityIds}).downstream))),p={};return Array.from(l).forEach(e=>{e===u&&(p[e]=this.onGoingVisits[i][e])}),p}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 p=this.getUpstreamOngoingDependenciesVisits(l,a);Object.keys(p).length&&await this.settlePromises(p,a);const e=u(this.flatRecord[l],this.flatRecord);Ob(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 p=this.getDownstreamOngoingDependenciesVisits(l,a);Object.keys(p).length&&await this.settlePromises(p,a);const e=u(this.flatRecord[l],this.flatRecord);Ob(e)&&(this.onGoingVisits[a][l]=e)}return await this.settlePromises(this.onGoingVisits[a],a),this.onGoingVisits[a]={},this}}function p5(d,u){switch(d.id){case Ee["built-in-base-entity"].BUILT_IN_PERSISTED_ENTITY_ENTITY.id:{const i=d.project.entities.filter(v=>!!v.implements.find(E=>E.id===Ee["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.id)),a=i.find(v=>{const E=v.properties.find($=>$.implements&&$.implements.id===Ee["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.default.id),w=E==null?void 0:E.getDefaultValue();return(w==null?void 0:w.value)===!0});if(!a&&i.length){const E=i[0].properties.find(A=>A.implements&&A.implements.id===Ee["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.default.id),w=E==null?void 0:E.defaultValue;if(w)w.metaSync({value:!0},u);else if(E!=null&&E.dataType){const A={id:N.UUID.uuid(),version:N.UUID.uuid(),createdAt:(u==null?void 0:u.timestamp)||new Date().toISOString(),author:N.sessionAuthor,previousVersion:null,deleted:!1,type:f.LiteralValue,standaloneParent:null,name:Q.EntityTemplate,autogeneration:null,value:!0,valueAsTypeSingle:null,valueAsTypeList:null,parent:E==null?void 0:E.toReference()},$=te(A,d.project);return $.setParent(E,u),$.initChildren(u),u==null||u.add($,S.Added),$.addSelfToProject(u),{newEntities:[$]}}return{newEntities:[]}}else if(a)return{newEntities:[]};const l=d.project.get(Ee["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.id),p=Im(l,"Main database",u);if(p.errors.length>0)return{newEntities:[]};const e=p.properties.find(v=>v.implements&&v.implements.id===Ee["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.default.id),y=e==null?void 0:e.defaultValue;if(y)y.metaSync({value:!0},u);else if(e!=null&&e.dataType){const v={id:N.UUID.uuid(),version:N.UUID.uuid(),createdAt:(u==null?void 0:u.timestamp)||new Date().toISOString(),author:N.sessionAuthor,previousVersion:null,deleted:!1,type:f.LiteralValue,standaloneParent:null,name:Q.EntityTemplate,autogeneration:null,value:!0,valueAsTypeSingle:null,valueAsTypeList:null,parent:e==null?void 0:e.toReference()},E=te(v,d.project);E.setParent(e,u),E.initChildren(u),u==null||u.add(E,S.Added),E.addSelfToProject(u)}return{newEntities:[p]}}}return{newEntities:[]}}function f5(d,u){const i=[],a=[],l=[],p=[];return d.implements.filter(y=>y.type===f.BuiltInBaseEntity).forEach(y=>{var v;switch(y.id){case Ee["built-in-base-entity"].BUILT_IN_PERSISTED_ENTITY_ENTITY.id:{const E=d.project.entities.filter(V=>V.implements.find(U=>U.id===Ee["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.id));let w=E.find(V=>!!V.properties.find(U=>{var G;return U.implements&&U.implements.id===Ee["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.default.id&&((G=U.getDefaultValue())==null?void 0:G.value)===!0}));if(!w&&E.length)w=E[0];else if(!w&&!E.length){w=d.project.getBuiltIn(Ee["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.id).implement("Relational database",u);const U=w.properties.find(G=>{var K;return((K=G.implements)==null?void 0:K.id)===Ee["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.default.id});(v=U==null?void 0:U.defaultValue)==null||v.metaSync({value:!0},u),a.push(w)}const A=d.properties.find(V=>V.implements&&V.implements.id===Ee["built-in-base-entity"].BUILT_IN_PERSISTED_ENTITY_ENTITY.properties.database.id),$=A==null?void 0:A.defaultValue;if(A&&!$){const V={id:N.UUID.uuid(),version:N.UUID.uuid(),createdAt:(u==null?void 0:u.timestamp)||new Date().toISOString(),author:N.sessionAuthor,previousVersion:null,deleted:!1,type:f.LiteralValue,standaloneParent:null,name:Q.EntityTemplate,autogeneration:null,value:null,valueAsTypeSingle:(w==null?void 0:w.toJSON())||null,valueAsTypeList:null,parent:A==null?void 0:A.toReference()},U=te(V,d.project);U.hydrateAncestors(),U.setParent(A,u),U.addSelfToProject(u),U.initChildren(u),u==null||u.add(U,S.Added),a.push(U);return}else $&&!$.valueAsTypeSingle&&$.setValueAsTypeSingle(w||null,u);return}}}),{self:d,updated:R(i),added:R(a),removed:R(l),affected:R(p)}}function Im(d,u,i,a){const l=a||N.UUID.uuid(),p=N.UUID.uuid(),e={id:l,version:p,createdAt:(i==null?void 0:i.timestamp)||new Date().toISOString(),author:N.sessionAuthor,previousVersion:null,deleted:!1,name:u,type:f.DefinitionEntity,codeName:null,description:null,static:d.static,abstract:!1,properties:[],methods:[],abstractMethods:[],extends:[],implements:[d.toJSON()],x:0,y:0,parent:d.project.toReference()};p5(d,i);const y=te(e,d.project);return y.hydrateAncestors(),i==null||i.add(y,S.Added),y.addSelfToProject(i),y.addImplementation(d),y.setParent(d.project,i),y.initChildren(i),f5(y,i),y}function Cb(d,u){return u.entities.find(l=>{const p=l.properties,e=p.map(A=>A.name),y=d.every(A=>e.includes(A)),v=e.filter(A=>!d.includes(A)),E=p.every(A=>!v.includes(A.name)||!A.required);return y&&E})||null}function h5(d,u,i,a=mi.OrDataTypeGroup){const l=[],p=[],e=[],y=[],E={id:N.UUID.uuid(),version:N.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||new Date().toISOString(),author:N.sessionAuthor,previousVersion:null,deleted:!1,type:f.DataType,options:null,implementationChooseOne:!1,entity:d.toJSON(),isList:!1,asType:!1,andChildrenGroup:null,orChildrenGroup:null,staticEntities:null,interactiveEntities:null,actionEntities:null,like:!0,inferred:!1,parentRelationType:a,parent:u.toReference()},w=te(E,d.project);return p.push(w),w.setParent(u,i),w.initChildren(i),i==null||i.add(w,S.Added),w.setEntity(d,i),w.addSelfToProject(i),{updated:R(l),added:R(p),removed:R(e),affected:R(y),self:w}}function $b(d,u,i,a,l){var E,w,A,$,V,U,G,K;const p=[],e=[],y=[],v=[];switch(typeof d){case"string":let J=!1;const ie=new Date(d);if(ie instanceof Date&&!isNaN(ie.valueOf())&&(J=!0),J){const X=u.project.getBuiltIn(Ee[f.PrimitiveEntity][Q.Date].id);u.setEntity(X,a);break}else{const X=u.project.getBuiltIn(Ee[f.PrimitiveEntity][Q.String].id);u.setEntity(X,a);break}case"number":u.setEntity(u.project.getBuiltIn(Ee[f.PrimitiveEntity][Q.Number].id),a);break;case"boolean":u.setEntity(u.project.getBuiltIn(Ee[f.PrimitiveEntity][Q.Boolean].id),a);break;case"object":if(d===null){u.setEntity(u.project.getBuiltIn(Ee[f.PrimitiveEntity][Q.Null].id),a);break}else if(Array.isArray(d))if(u.metaSync({isList:!0},a),d.length>0){const X=d.slice(0,5).filter(re=>re!==void 0);if(X.every(re=>typeof re==typeof X[0])&&(typeof X[0]!="object"||X[0]===null))switch(typeof X[0]){case"string":u.setEntity(u.project.getBuiltIn(Ee[f.PrimitiveEntity][Q.String].id),a);break;case"number":u.setEntity(u.project.getBuiltIn(Ee[f.PrimitiveEntity][Q.Number].id),a);break;case"boolean":u.setEntity(u.project.getBuiltIn(Ee[f.PrimitiveEntity][Q.Boolean].id),a);break;case"object":u.setEntity(u.project.getBuiltIn(Ee[f.PrimitiveEntity][Q.Null].id),a);break}else{const re=[];let fe=!1;X.forEach(H=>{var ce,z,oe,we;if(Array.isArray(H)&&(fe=!0),typeof H=="object"&&!Array.isArray(H)&&H!==null){const xe=Am(H,u.project,{...i,id:N.UUID.uuid()},a,l);xe.hasCreated&&re.push((ce=xe.changeSet)==null?void 0:ce.self),p.push(...(z=xe.changeSet)==null?void 0:z.updated),e.push(...(oe=xe.changeSet)==null?void 0:oe.added),y.push(...(we=xe.changeSet)==null?void 0:we.removed)}});const Y=R(re);if(!Y.length&&!fe){X.forEach(H=>{const ce={id:N.UUID.uuid(),version:N.UUID.uuid(),createdAt:(a==null?void 0:a.timestamp)||new Date().toISOString(),author:N.sessionAuthor,previousVersion:null,deleted:!1,type:f.DataType,options:null,implementationChooseOne:!1,entity:null,isList:!1,asType:!1,andChildrenGroup:null,orChildrenGroup:null,staticEntities:!1,interactiveEntities:!0,actionEntities:!1,like:!0,inferred:!1,parentRelationType:mi.OrDataTypeGroup,parent:u.toReference()},z=te(ce,u.project);switch(z.setParent(u,a),z.initChildren(a),a==null||a.add(z,S.Added),z.addSelfToProject(a),typeof H){case"string":z.setEntity(z.project.getBuiltIn(Ee[f.PrimitiveEntity][Q.String].id),a);break;case"number":z.setEntity(z.project.getBuiltIn(Ee[f.PrimitiveEntity][Q.Number].id),a);break;case"boolean":z.setEntity(z.project.getBuiltIn(Ee[f.PrimitiveEntity][Q.Boolean].id),a);break;case"object":z.setEntity(z.project.getBuiltIn(Ee[f.PrimitiveEntity][Q.Null].id),a);break}});break}else Y.length===1&&!fe?u.setEntity(Y[0],a):X.forEach(H=>{if(typeof H=="object"&&!Array.isArray(H)&&H!==null){const ce=Cb(Object.keys(H),u.project);if(ce){const z=h5(ce||Y[0],u,a,mi.OrDataTypeGroup);p.push(...z.updated),e.push(...z.added),y.push(...z.removed)}}else{const ce={id:N.UUID.uuid(),version:N.UUID.uuid(),createdAt:(a==null?void 0:a.timestamp)||new Date().toISOString(),author:N.sessionAuthor,previousVersion:null,deleted:!1,type:f.DataType,options:null,implementationChooseOne:!1,entity:null,isList:Array.isArray(H),asType:!1,andChildrenGroup:null,orChildrenGroup:null,staticEntities:!1,interactiveEntities:!0,actionEntities:!1,like:!0,inferred:!1,parentRelationType:mi.OrDataTypeGroup,parent:u.toReference()},z=te(ce,u.project);z.setParent(u,a),z.initChildren(a),a==null||a.add(z,S.Added),z.addSelfToProject(a);const oe=$b(H,z,{...i,id:N.UUID.uuid()},a,l);p.push(...oe.updated),e.push(...oe.added),y.push(...oe.removed)}})}}else{const X=Am(d[0],u.project,{...i},a,l);u.setEntity((E=X.changeSet)==null?void 0:E.self,a),p.push(...(w=X.changeSet)==null?void 0:w.updated),e.push(...(A=X.changeSet)==null?void 0:A.added),y.push(...($=X.changeSet)==null?void 0:$.removed);break}else{const X=Am(d,u.project,{...i},a,l);u.setEntity((V=X.changeSet)==null?void 0:V.self,a),p.push(...(U=X.changeSet)==null?void 0:U.updated),e.push(...(G=X.changeSet)==null?void 0:G.added),y.push(...(K=X.changeSet)==null?void 0:K.removed);break}}return{updated:R(p),added:R(e),removed:R(y),affected:R(v),self:u}}function Am(d,u,i,a,l){const p=[],e=[],y=[],v=[],E=Object.keys(d),w=Cb(E,u);if(w)return{hasCreated:!1,changeSet:{updated:[],added:[],removed:[],affected:[],self:w}};const A=l?i.name+" of "+l.name:i.name,V={id:i.id||N.UUID.uuid(),version:N.UUID.uuid(),createdAt:(a==null?void 0:a.timestamp)||new Date().toISOString(),author:N.sessionAuthor,previousVersion:null,deleted:!1,name:A,codeName:null,type:f.DefinitionEntity,description:i.description||null,static:i.static||!1,abstract:i.abstract||!1,properties:[],methods:[],abstractMethods:[],extends:[],implements:[],x:0,y:0,parent:u.toReference()},U=te(V,u);return U.setParent(u,a),U.initChildren(a),a==null||a.add(U,S.Added),U.addSelfToProject(a),e.push(U),E.forEach((G,K)=>{const ie={id:N.UUID.uuid(),version:N.UUID.uuid(),createdAt:(a==null?void 0:a.timestamp)||new Date().toISOString(),author:N.sessionAuthor,previousVersion:null,deleted:!1,name:G,type:f.Property,codeName:G,description:null,static:!1,abstract:!1,defaultValue:null,constant:!1,interactive:!0,dataType:null,implements:null,extends:null,index:K,hidden:!1,private:!1,required:!0,parent:U.toReference()},X=te(ie,u);X.setParent(U,a),X.initChildren(a),a==null||a.add(X,S.Added),X.addSelfToProject(a),e.push(X);const ue=d[G],fe={id:N.UUID.uuid(),version:N.UUID.uuid(),createdAt:(a==null?void 0:a.timestamp)||new Date().toISOString(),author:N.sessionAuthor,previousVersion:null,deleted:!1,type:f.DataType,parentRelationType:null,options:null,implementationChooseOne:!1,entity:null,isList:!1,asType:!1,andChildrenGroup:null,orChildrenGroup:null,staticEntities:!1,interactiveEntities:!0,actionEntities:!1,like:!0,inferred:!1,parent:X.toReference()},Y=te(fe,u);Y.setParent(X,a),Y.initChildren(a),a==null||a.add(Y,S.Added),Y.addSelfToProject(a),e.push(Y);const H=$b(ue,Y,{...i,name:G,id:N.UUID.uuid()},a,l||U);p.push(...H.updated),e.push(...H.added),y.push(...H.removed)}),{hasCreated:!0,changeSet:{updated:R(p),added:R(e),removed:R(y),affected:R(v),self:U}}}function ja(d,u,i,a){const l=[];return!d.length||!u.length?{errors:l,overlap:!1}:(d.length>u.length?d.forEach(p=>{const e=u.find(v=>v.name===p.name),y=u.find(v=>{var E,w;return!!p.implements&&((E=v.implements)==null?void 0:E.id)===((w=p.implements)==null?void 0:w.id)});if(e){const v=new lr({id:p.id+"--"+e.id+"--"+a,message:`Entity of type ${p.type} named "${p.name}" with id "${p.id}" overrides a base ${e.type} ${e.name} with id "${e.id}" that has the same name`,issue:null,severity:q.Error,code:a,entity:p,firstRelationship:e});l.push(v)}if(y){const v=new lr({id:p.id+"--"+y.id+"--"+i,message:`Entity of type ${p.type} named "${p.name}" with id "${p.id}" overrides a base ${y.type} ${y.name} with id "${y.id}" that implements the same base descriptor`,issue:null,severity:q.Error,code:i,entity:p,firstRelationship:y});l.push(v)}}):u.forEach(p=>{var v;const e=d.find(E=>E.name===p.name),y=d.find(E=>{var w,A;return!!E.implements&&((w=E.implements)==null?void 0:w.id)===((A=p.implements)==null?void 0:A.id)});if(e){const E=new lr({id:e.id+"--"+p.id+"--"+a,message:`Entity of type ${e.type} named "${e.name}" with id "${e.id}" overrides a base entity ${p.name} with id "${p.id}" that has the same name`,issue:null,severity:q.Error,code:a,entity:e,firstRelationship:p});l.push(E)}if(y){const E=new lr({id:y.id+"--"+p.id+"--"+i,message:`Entity of type ${y.type} named "${y.name}" with id "${y.id}" overrides a base entity ${p.name} with id "${p.id}" that implements the same base ${(v=y==null?void 0:y.implements)==null?void 0:v.type}`,issue:null,severity:q.Error,code:i,entity:y,firstRelationship:p});l.push(E)}}),{errors:l,overlap:!!l.length})}function PIe(d,u){return d.abstract||(d.properties.forEach(a=>{a.abstract||a.metaSync({abstract:!0},u)}),Object.values(d.detachedDependents).forEach(a=>{a.field===nA.Entity&&a.entity.remove({ignoreUpstream:!1},u)}),d.metaSync({abstract:!0},u)),d}function NIe(d,u){return d.abstract&&(d.properties.forEach(a=>{a.abstract&&a.metaSync({abstract:!1},u)}),Object.values(d.detachedDependents).forEach(a=>{(a.field===Um.Implements||a.field===Um.Extends)&&a.entity.onDetachedDependencyRemoved(d,a.field,u)}),d.metaSync({abstract:!1},u)),d}function VIe(d,u){return d.static||(d.properties.forEach(a=>{a.static||a.metaSync({static:!0},u)}),d.metaSync({static:!0},u)),d}function LIe(d,u){return d.static&&d.metaSync({static:!1},u),d}var y5=(d=>(d.StringValueMustNotHaveSpaces="string-value-must-not-have-spaces",d.StringValueMustNotHaveDashes="string-value-must-not-have-dashes",d))(y5||{});function m5(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 lr({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.`,issue:null,severity:q.Error,code:"string-value-must-not-have-spaces",entity:d});i.push(l)}return{errors:i,override:a.replace(/\s/g,"-")}}function v5(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 lr({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.`,issue:null,severity:q.Error,code:"string-value-must-not-have-spaces",entity:d});i.push(l)}if(a.includes("-")){const l=new lr({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.`,issue:null,severity:q.Error,code:"string-value-must-not-have-dashes",entity:d});i.push(l)}return{errors:i,override:a.replace(/\s|-/g,"_")}}function Pb(d,u){var i;if(d.type===f.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} (${ne(d,u)}) = ${a}`}if(d.type===f.DataType){if(d instanceof hs||d.increaseVersion)return`${d.type}: ${d.id} (${nu(d)})`;try{const a=nu(d);return`${d.type}: ${d.id} (${a})`}catch{}}return`${d.type}: ${d.id} (${ne(d,u)})`}function Xd(d,u){const i=bo(d);if(i.length===0)return{list:[],last:null};let a=null;return{list:i.flatMap(p=>{if(p===u)return a=p,[p];const e=Xd(p,u);return e.last&&(a=e.last),[p,...e.list]}),last:a}}function Xp(d){const u=d.calledBy;if(u.length===0)return d.project;const i=u.reduce((a,l)=>{const p=Ki(l,d.project);return!p||p.type===f.Project?a:a.type===f.Project||Xd(p,a).last?p:(Xd(a,p).last,a)},d.project);return i.type===f.FunctionDeclaration&&i.parent.type===f.Loop?i.parent:i}function We(d,u){let i=Xp(d);if(d.type===f.InternalCall)if(d.parent.type===f.VariableInstance){const l=Qs(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===f.ContinueStatement||d.type===f.BreakStatement)&&i.type!==f.Loop){d.remove({ignoreUpstream:!1},u);return}else if(d.type===f.ReturnStatement&&!Mr.includes(i.type)){d.remove({ignoreUpstream:!1},u);return}else if(mt.includes(d.type)){const l=d.usedInternalCalls[0];if(l)if(i=Xp(l),d.type===f.VariableInstance){const p=Qs(i,d.declaration,d.project);!p.compatible&&p.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===f.VariableInstance){const p=Qs(i,d.declaration,d.project);!p.compatible&&p.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(Ar.includes(d.type))return;_t(d).forEach(l=>{let p=Xp(l);if(l.type===f.InternalCall)if(l.parent.type===f.VariableInstance){const e=Qs(p,l.parent.declaration,d.project);!e.compatible&&e.type!=="b-is-global-a-is-not"?l.parent.remove({ignoreUpstream:!1},u):(l.parent.setParent(p,u),l.parent.addSelfToProject(u))}else l.parent.setParent(p,u),l.parent.addSelfToProject(u);else if((l.type===f.ContinueStatement||l.type===f.BreakStatement)&&p.type!==f.Loop){l.remove({ignoreUpstream:!1},u);return}else if(l.type===f.ReturnStatement&&!Mr.includes(p.type)){l.remove({ignoreUpstream:!1},u);return}else if(mt.includes(l.type)){const e=l.usedInternalCalls[0];if(e)if(p=Xp(e),l.type===f.VariableInstance){const y=Qs(p,l.declaration,d.project);!y.compatible&&y.type!=="b-is-global-a-is-not"?l.remove({ignoreUpstream:!1},u):(l.setParent(p,u),l.addSelfToProject(u))}else l.setParent(p,u),l.addSelfToProject(u);else if(l.type===f.VariableInstance){const y=Qs(p,l.declaration,d.project);!y.compatible&&y.type!=="b-is-global-a-is-not"?l.remove({ignoreUpstream:!1},u):(l.setParent(p,u),l.addSelfToProject(u))}else l.setParent(p,u),l.addSelfToProject(u)}else l.setParent(p,u),l.addSelfToProject(u)})}function bm(d,u,i=new Set){const a=wn(d),l=wn(u),p=a.filter(v=>!l.includes(v)),e=a.filter(v=>l.includes(v)),y=p.reduce((v,E)=>i.has(E.id)?v:(i.add(E.id),R([...v,...bm(E,u,i)])),[]);return R([...e,...y])}function _l(d,u){const i=Xd(d,u);return i.last===u&&i.list.length>0&&i.list[0]!==u}function Nb(d,u){return!!Xd(d,u).last}function MIe(d){if(pr.includes(d.type))return d;if([...Ss,f.VariableDeclaration].includes(d.type)){const u=d.parent;return pr.includes(u.type)?u:null}return null}function Vb(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===f.Project)return null}else return null;const a=u.parent;if(a){if(a===d)return d;if(a.type===f.Project)return null}else return null;return Vb(i,a)}function Er(d){if(rh.includes(d.type)){if(d.type===f.FunctionDeclaration){const u=d.parent;if(u.type===f.DefinitionEntity)return Er(u);if(u.type===f.Loop)return u}return d.type===f.DefinitionEntity&&d.parent.type===f.DataType?Er(d.parent):d}else{const u=d.parent;return u?Er(u):null}}function wm(d,u){const i=Qp(d,u);if(!i)return null;if(rh.includes(i.type)){if(i.type===f.FunctionDeclaration){const a=Qp(i.parent,u);if(a){if(a.type===f.DefinitionEntity)return a;if(a.type===f.Loop)return a}}return i}else{const a=i.parent?Qp(i.parent,u):null;return a?wm(a,u):null}}function E5(d){if(!d)return null;if(Ss.includes(d.type))return d;const u=d.parent;return u?E5(u):null}function T5(d){if(!d)return null;if(mr.includes(d.type))return d;const u=d.parent;return u?T5(u):null}function I5(d){if(!d)return null;if(Ks.includes(d.type))return d;const u=d.parent;return u?I5(u):null}function BIe(d){return d.type===f.VariableDeclaration?[d]:mr.includes(d.type)?[...d.inputs,...d.outputs||[]]:Ar.includes(d.type)?d.outputs:So.includes(d.type)||d.type===f.FunctionDeclaration?d.inputs:[]}function UIe(d){const u=wn(d),i=[],a=[];Eg.includes(d.type)&&i.push(...Rm(d));const l=u.filter(p=>{const e=i.includes(p);return e?!1:Ss.includes(p.type)&&!e?(a.push(p),!1):!0});return i.sort((p,e)=>_l(e,p)?-1:0),a.sort((p,e)=>_l(e,p)?-1:0),[...i,...a,...l]}function A5(d){return[...d].sort((u,i)=>_l(i,u)?-1:0)}function jIe(d){const u=A5(d),i=[];return u.forEach(a=>{const l=i[i.length-1];if(l){const p=l[l.length-1];_l(a,p)?i.push([a]):l.push(a)}else i.push([a])}),i}function Pi(d){const u=d.map(i=>Er(i));return R(u)}function Rm(d){return mr.includes(d.type)?[...Pi(d.successCalls),...Pi(d.errorCalls)]:pr.includes(d.type)?Pi(d.calls):[]}function xIe(d,u){return Rm(d).includes(u)}function _m(d){return d.writesValues||[]}function FIe(d,u){return _m(d).includes(u)}function b5(d){var u;return mt.includes((u=d==null?void 0:d.readsValue)==null?void 0:u.type)?d.readsValue:null}function GIe(d){return d.writesValues}function w5(d=[]){return d.map(b5).filter(u=>!!u)}function gm(d=[]){return d.map(u=>u.writesValues).flat().filter(u=>mt.includes(u.type))}function R5(d=[]){return d.map(u=>u.readsValue).filter(u=>!!u&&mt.includes(u.type))}function _5(d){return mt.includes(d.type)?d:null}function g5(d){return d.writesValues.map(_5).filter(u=>!!u)}function D5(d=[]){return d.reduce((u,i)=>i.type===f.OutputMap?[...u,...g5(i)]:u,[])}function _t(d){return d.type===f.Loop?R([...zs(Pi(d.successCalls)),...zs(Pi(d.errorCalls)),...d.body?_t(d.body):[]]):mr.includes(d.type)?R([...zs(Pi(d.successCalls)),...zs(Pi(d.errorCalls))]):pr.includes(d.type)?R(zs(Pi(d.calls))):[]}function SIe(d){return mr.includes(d.type)?[...zs(Pi(d.successCalls)),...zs(Pi(d.errorCalls))]:pr.includes(d.type)?zs(Pi(d.calls)):[]}function O5(d,u=new Set){return d.writesValues.filter(a=>mt.includes(a.type)&&!u.has(a.id)).reduce((a,l)=>u.has(l.id)?a:[...a,...yr(l,u)],[])}function C5(d,u=new Set){var a;return(((a=d.readsValue)==null?void 0:a.writesValues)||[]).filter(l=>mt.includes(l.type)&&!u.has(l.id)).reduce((l,p)=>u.has(p.id)?l:[...l,...yr(p,u)],[])}function yr(d,u=new Set){if(u.has(d.id))return[];if(d.type===f.ReturnStatement)return R5(d.outputs).reduce((a,l)=>[...a,...yr(l,u)],[]);if(d.type===f.FunctionCall||d.type===f.Operation||d.type===f.Condition)return[..._t(d).reduce((p,e)=>{const y=Er(e);return[...p,...yr(y||e,u)]},[]),...w5(d.inputs),...D5(d.outputs)].reduce((p,e)=>[...p,...yr(e,u)],[]);if(So.includes(d.type)){const i=gm(d.inputs),l=_t(d).reduce((p,e)=>{const y=Er(e);return[...p,...yr(y||e,u)]},[]);return i.push(...l),i.reduce((p,e)=>[...p,...yr(e,u)],[])}if(d.type===f.FunctionDeclaration){const i=[...gm(d.inputs)],l=_t(d).reduce((p,e)=>{const y=Er(e);return[...p,...yr(y||e,u)]},[]);return i.push(...l),i.reduce((p,e)=>[...p,...yr(e)],[])}if(mt.includes(d.type)){u.add(d.id);const a=_t(d).reduce((l,p)=>{const e=Er(p);return[...l,...yr(e||p,u)]},[]);return[d,...a,...C5(d,u),...O5(d,u)]}return[]}function vs(d,u=new Set){return u.has(d.id)?[]:(u.add(d.id),[...wn(d).reduce((l,p)=>[...l,p,...vs(p,u)],[])])}function zs(d){return d.reduce((u,i)=>i.type===f.ReturnStatement||i.type===f.ContinueStatement||i.type===f.BreakStatement?[...u,i]:[...u,i,..._t(i)],[])}function $5(d){const u=d.entities||[],i=[...u,...d.functions||[],...d.events||[],...d.projects||[]],a=u.reduce((v,E)=>[...v,...E.properties],[]),l=u.reduce((v,E)=>[...v,...E.methods],[]),p=l.reduce((v,E)=>[...v,...gm(E.inputs),...zs(Pi(E.calls)),...E.returnStatements],[]),e=d.functions.reduce((v,E)=>[...v,...zs(Pi(E.calls)),...E.returnStatements],[]),y=d.events.reduce((v,E)=>[...v,...zs(Pi(E.calls)),...E.returnStatements],[]);return[...i,...a,...l,...p,...e,...y]}function P5(d,u){return u.filter(a=>{if(!a)return!1;switch(a.type){case f.FunctionCall:return a.inputs.find(l=>l.id===d.id)!==void 0||a.outputs.find(l=>l.id===d.id)!==void 0;case f.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 f.Operation:return a.outputs.find(l=>l.id===d.id)!==void 0;case f.VariableDeclaration:return mr.includes(d.type)?aS(d).find(p=>{var e;return((e=p.readsValue)==null?void 0:e.id)===a.id})!==void 0:!1;case f.DefinitionEntity:return a.properties.find(l=>l.id===d.id)!==void 0||a.methods.find(l=>l.id===d.id)!==void 0;case f.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 KIe(d){const u=$5(d.project);return P5(d,u)}function Qp(d,u){return d?typeof d=="string"?u[d]:d.type===f.GenericReference?u[d.entityId]:u[d.id]?u[d.id]:null:null}function N5(d={},u){const i={};return Object.keys(d).forEach(a=>{const l=u.get(a)||a,p=d[a];i[l]=p}),i}function Qd(d,u={},i={}){const a={ignoreBuiltInBaseEntities:!1,allBuiltInEntityIds:[],entityMaps:new Map,...i};if(a.ignoreBuiltInBaseEntities&&(ls.includes(d.type)||(a.allBuiltInEntityIds||[]).includes(d.id)))return{upstream:{},downstream:{}};const l=d,p=d,e=d,y=d,v=d,E=d,w=d,A=d,$=d,V=d,U=d,G=d,K=d,J=[...K.readsValue?[K.readsValue]:[],...K.declaration?[K.declaration]:[],...(G.calledByEntry||[]).flatMap(re=>re),...(G.calledBySuccess||[]).flatMap(re=>re),...(G.calledByError||[]).flatMap(re=>re),...V.parent?[V.parent]:[]];Array.isArray(e.implements)?J.push(...e.implements.flatMap(re=>re)):$.implements&&J.push($.implements),Array.isArray(e.extends)?J.push(...e.extends.flatMap(re=>re)):$.extends&&J.push($.extends),v.valueAsTypeList&&Array.isArray(v.valueAsTypeList)&&J.push(...v.valueAsTypeList.flatMap(re=>re)),v.valueAsTypeSingle&&J.push(v.valueAsTypeSingle),(K.internalCalls||[]).forEach(re=>{const fe=Z(re);if(fe&&u[fe]){const Y=u[fe];[...Y.calledByEntry||[],...Y.calledBySuccess||[],...Y.calledByError||[]].forEach(H=>{const ce=Z(H);ce&&u[ce]&&J.push(u[ce])})}});const ie=[...(l.inputs||[]).flatMap(re=>re),...(U.inputsDeclarations||[]).flatMap(re=>re),...(l.outputs||[]).flatMap(re=>re),...(U.outputsDeclarations||[]).flatMap(re=>re),...(K.internalCalls||[]).flatMap(re=>re),...K.writesValues||[],...G.dataType?[G.dataType]:[],...E.body?[E.body]:[],...G.defaultValue?[G.defaultValue]:[],...(G.successCalls||[]).flatMap(re=>re),...(G.errorCalls||[]).flatMap(re=>re),...(e.properties||[]).flatMap(re=>re),...(e.methods||[]).flatMap(re=>re),...(e.abstractMethods||[]).flatMap(re=>re),...w.error?[w.error]:[],...w.process?[w.process]:[],...V.throws?[V.throws]:[],...(p.andChildrenGroup||[]).flatMap(re=>re),...(p.orChildrenGroup||[]).flatMap(re=>re),...(A.entities||[]).flatMap(re=>re),...(A.functions||[]).flatMap(re=>re),...(A.functionCalls||[]).flatMap(re=>re),...(A.events||[]).flatMap(re=>re),...(A.conditions||[]).flatMap(re=>re),...(A.operations||[]).flatMap(re=>re),...(A.loops||[]).flatMap(re=>re),...(A.variableDeclarations||[]).flatMap(re=>re),...(A.variableInstances||[]).flatMap(re=>re),...(A.searches||[]).flatMap(re=>re),...(A.projects||[]).flatMap(re=>re),...(y.calls||[]).flatMap(re=>re)];d.type===f.DataType&&(p.entity&&u[Z(p.entity)]&&u[Z(p.entity)].parent&&Z(u[Z(p.entity)].parent)===d.id?ie.push(p.entity):p.entity&&J.push(p.entity)),(K.internalCalls||[]).forEach(re=>{const fe=Z(re);if(fe&&u[fe]){const Y=u[fe];[...Y.successCalls||[],...Y.errorCalls||[]].forEach(H=>{const ce=Z(H);ce&&u[ce]&&ie.push(u[ce])})}});const X={},ue={};return J.forEach(re=>{var H;const fe=Z(re);if(fe&&a.ignoreBuiltInBaseEntities&&(ls.includes(re.type)||(a.allBuiltInEntityIds||[]).includes(fe)))return;const Y=re.version;if(fe){const ce=((H=a.entityMaps)==null?void 0:H.get(fe))||fe;X[ce]=Y}}),ie.forEach(re=>{var H;const fe=Z(re);if(fe&&a.ignoreBuiltInBaseEntities&&(ls.includes(re.type)||(a.allBuiltInEntityIds||[]).includes(fe)))return;const Y=re.version;if(fe){const ce=((H=a.entityMaps)==null?void 0:H.get(fe))||fe;ue[ce]=Y}}),{upstream:X,downstream:ue}}function kIe(d,u){const i=[];if(Ss.includes(d.type)){Ls(d).forEach(p=>{const e=wm(p,u);e&&i.push(e)});const l=[...d.inputs||[],...d.outputs||[]].map(p=>{const e=Qp(p,u);return e?lS(e,u):null}).filter(p=>p!==null);i.push(...R(l))}if(mt.includes(d.type)){const a=Dm(d);a&&i.push(a)}return R(i)}function bo(d){const u=[];if(Ss.includes(d.type)){d.calledBy.forEach(l=>{const p=Er(l);p&&u.push(p)});const a=[...d.inputs||[],...d.outputs||[]].map(l=>Dm(l)).filter(l=>l!==null);u.push(...R(a))}if(mt.includes(d.type)){const i=Dm(d);i&&u.push(i)}return R(u)}function Ls(d){return[...d.calledByEntry||[],...d.calledByError||[],...d.calledBySuccess||[]].filter(u=>u.type!==f.GenericReference)}function V5(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.ActionDescriptor)throw new Error("Entity must be an action descriptor to be flattened");return[d,...d.inputs.flatMap(a=>me(a,u,i)),...d.outputs.flatMap(a=>me(a,u,i)),...d.error?me(d.error,u,i):[],...d.parent?me(d.parent,u,i):[]]}function L5(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.ArgumentDeclaration)throw new Error("Entity must be an argument declaration to be flattened");return[d,...d.defaultValue?me(d.defaultValue,u):[],...d.writesValues.flatMap(a=>me(a,u,i)),...d.dataType?me(d.dataType,u,i):[],...d.parent?me(d.parent,u,i):[]]}function M5(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.BreakStatement)throw new Error("Entity must be a break statement to be flattened");return[d,...d.outputs.flatMap(a=>me(a,u,i)),...d.throws?me(d.throws,u,i):[],...(Ls(d)||[]).flatMap(a=>me(a,u,i)),...d.parent?me(d.parent,u,i):[]]}function B5(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.BuiltInBaseEntity)throw new Error("Entity must be a built-in base entity to be flattened");return[d,...(d.properties||[]).flatMap(a=>me(a,u,i)),...(d.methods||[]).flatMap(a=>me(a,u,i)),...(d.abstractMethods||[]).flatMap(a=>me(a,u,i)),...(d.extends||[]).flatMap(a=>me(a,u,i))]}function U5(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.Condition)throw new Error("Entity must be a condition to be flattened");return[d,...(d.inputs||[]).flatMap(a=>me(a,u,i)),...(d.successCalls||[]).flatMap(a=>me(a,u,i)),...(d.errorCalls||[]).flatMap(a=>me(a,u,i)),...(Ls(d)||[]).flatMap(a=>me(a,u,i)),...d.parent?me(d.parent,u,i):[]]}function j5(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.ContinueStatement)throw new Error("Entity must be a continue statement to be flattened");return[d,...d.outputs.flatMap(a=>me(a,u,i)),...d.throws?me(d.throws,u,i):[],...(Ls(d)||[]).flatMap(a=>me(a,u,i)),...d.parent?me(d.parent,u,i):[]]}function x5(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.DefinitionEntity)throw new Error("Entity must be a definition entity to be flattened");return[d,...(d.extends||[]).flatMap(a=>me(a,u,i)),...(d.implements||[]).flatMap(a=>me(a,u,i)),...(d.properties||[]).flatMap(a=>me(a,u,i)),...(d.methods||[]).flatMap(a=>me(a,u,i)),...(d.abstractMethods||[]).flatMap(a=>me(a,u,i)),...d.parent?me(d.parent,u,i):[]]}function F5(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.DataType)throw new Error("Entity must be a data type to be flattened");return[d,...(d.andChildrenGroup||[]).flatMap(a=>me(a,u,i)),...(d.orChildrenGroup||[]).flatMap(a=>me(a,u,i)),...d.entity?me(d.entity,u,i):[],...d.parent?me(d.parent,u,i):[]]}function G5(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.FunctionCall)throw new Error("Entity must be a function call to be flattened");return[d,...(d.inputs||[]).flatMap(a=>me(a,u,i)),...(d.outputs||[]).flatMap(a=>me(a,u,i)),...d.error?me(d.error,u,i):[],...d.process?me(d.process,u,i):[],...(Ls(d)||[]).flatMap(a=>me(a,u,i)),...(d.successCalls||[]).flatMap(a=>me(a,u,i)),...(d.errorCalls||[]).flatMap(a=>me(a,u,i)),...d.parent?me(d.parent,u,i):[]]}function S5(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.FunctionDeclaration)throw new Error("Entity must be a function declaration to be flattened");return[d,...(d.inputs||[]).flatMap(a=>me(a,u,i)),...(d.calls||[]).flatMap(a=>me(a,u,i)),...d.implements?me(d.implements,u,i):[],...d.parent?me(d.parent,u,i):[]]}function K5(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.GlobalEvent)throw new Error("Entity must be a global event to be flattened");return[d,...(d.inputs||[]).flatMap(a=>me(a,u,i)),...(d.calls||[]).flatMap(a=>me(a,u,i)),...d.implements?me(d.implements,u,i):[],...d.parent?me(d.parent,u,i):[]]}function k5(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.InputMap)throw new Error("Entity must be an input map to be flattened");return[d,...d.readsValue?me(d.readsValue,u,i):[],...d.declaration?me(d.declaration,u,i):[],...d.defaultValue?me(d.defaultValue,u,i):[],...d.parent?me(d.parent,u,i):[]]}function q5(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.InstalledProject)throw new Error("Entity must be an installed project to be flattened");return[d,...(d.functions||[]).flatMap(a=>me(a,u,i)),...(d.events||[]).flatMap(a=>me(a,u,i)),...d.parent?me(d.parent,u,i):[]]}function J5(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.InternalCall)throw new Error("Entity must be an internal call to be flattened");return[d,...(d.successCalls||[]).flatMap(a=>me(a,u,i)),...(d.errorCalls||[]).flatMap(a=>me(a,u,i)),...(d.inputs||[]).flatMap(a=>me(a,u,i)),...(d.outputs||[]).flatMap(a=>me(a,u,i)),...(Ls(d)||[]).flatMap(a=>me(a,u,i)),...d.error?me(d.error,u,i):[],...d.process?me(d.process,u,i):[],...d.parent?me(d.parent,u,i):[]]}function Z5(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.LiteralValue)throw new Error("Entity must be a literal value to be flattened");return[d,...d.valueAsTypeSingle?me(d.valueAsTypeSingle,u,i):[],...d.valueAsTypeList&&Array.isArray(d.valueAsTypeList)?d.valueAsTypeList.flatMap(a=>me(a,u,i)):[],...d.parent?me(d.parent,u,i):[]]}function H5(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.Loop)throw new Error("Entity must be a loop to be flattened");return[d,...(d.inputs||[]).flatMap(a=>me(a,u,i)),...(d.outputs||[]).flatMap(a=>me(a,u,i)),...(d.successCalls||[]).flatMap(a=>me(a,u,i)),...(d.errorCalls||[]).flatMap(a=>me(a,u,i)),...d.error?me(d.error,u,i):[],...d.process?me(d.process,u,i):[],...d.body?me(d.body,u,i):[],...(Ls(d)||[]).flatMap(a=>me(a,u,i)),...d.parent?me(d.parent,u,i):[]]}function W5(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.Operation)throw new Error("Entity must be an operation to be flattened");return[d,...(d.successCalls||[]).flatMap(a=>me(a,u,i)),...(d.errorCalls||[]).flatMap(a=>me(a,u,i)),...(d.inputs||[]).flatMap(a=>me(a,u,i)),...(d.outputs||[]).flatMap(a=>me(a,u,i)),...d.error?me(d.error,u,i):[],...d.process?me(d.process,u,i):[],...(Ls(d)||[]).flatMap(a=>me(a,u,i)),...d.parent?me(d.parent,u,i):[]]}function Y5(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.OutputMap)throw new Error("Entity must be an output map to be flattened");return[d,...(d.writesValues||[]).flatMap(a=>me(a,u,i)),...d.declaration?me(d.declaration,u,i):[],...d.defaultValue?me(d.defaultValue,u,i):[],...d.parent?me(d.parent,u,i):[]]}function z5(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.PrimitiveEntity)throw new Error("Entity must be a primitive entity to be flattened");return[d,...(d.properties||[]).flatMap(a=>me(a,u,i)),...(d.methods||[]).flatMap(a=>me(a,u,i)),...(d.abstractMethods||[]).flatMap(a=>me(a,u,i))]}function X5(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.Project)throw new Error("Entity must be a project to be flattened");return[d,...(d.entities||[]).flatMap(a=>me(a,u,i)),...(d.functions||[]).flatMap(a=>me(a,u,i)),...(d.events||[]).flatMap(a=>me(a,u,i)),...(d.projects||[]).flatMap(a=>me(a,u,i)),...(d.variableDeclarations||[]).flatMap(a=>me(a,u,i)),...(d.variableInstances||[]).flatMap(a=>me(a,u,i)),...(d.operations||[]).flatMap(a=>me(a,u,i)),...(d.conditions||[]).flatMap(a=>me(a,u,i)),...(d.functionCalls||[]).flatMap(a=>me(a,u,i)),...(d.projects||[]).flatMap(a=>me(a,u,i)),...(d.loops||[]).flatMap(a=>me(a,u,i)),...(d.searches||[]).flatMap(a=>me(a,u,i))]}function Q5(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.Property)throw new Error("Entity must be a property to be flattened");return[d,...d.defaultValue?me(d.defaultValue,u,i):[],...d.dataType?me(d.dataType,u,i):[],...d.parent?me(d.parent,u,i):[]]}function eS(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.ReturnDeclaration)throw new Error("Entity must be a return declaration to be flattened");return[d,...d.readsValue?me(d.readsValue,u,i):[],...d.defaultValue?me(d.defaultValue,u,i):[],...d.dataType?me(d.dataType,u,i):[],...d.parent?me(d.parent,u,i):[]]}function tS(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.ReturnStatement)throw new Error("Entity must be a return statement to be flattened");return[d,...(d.outputs||[]).flatMap(a=>me(a,u,i)),...d.throws?me(d.throws,u,i):[],...(Ls(d)||[]).flatMap(a=>me(a,u,i)),...d.parent?me(d.parent,u,i):[]]}function rS(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.Search)throw new Error("Entity must be a search to be flattened");return[d,...(d.successCalls||[]).flatMap(a=>me(a,u,i)),...(d.errorCalls||[]).flatMap(a=>me(a,u,i)),...(d.inputsDeclarations||[]).flatMap(a=>me(a,u,i)),...(d.inputs||[]).flatMap(a=>me(a,u,i)),...(d.outputsDeclarations||[]).flatMap(a=>me(a,u,i)),...(d.outputs||[]).flatMap(a=>me(a,u,i)),...d.error?me(d.error,u,i):[],...(Ls(d)||[]).flatMap(a=>me(a,u,i)),...d.parent?me(d.parent,u,i):[]]}function iS(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.ValueDescriptor)throw new Error("Entity must be a value descriptor to be flattened");return[d,...d.defaultValue?me(d.defaultValue,u,i):[],...d.dataType?me(d.dataType,u,i):[],...d.parent?me(d.parent,u,i):[]]}function sS(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.VariableDeclaration)throw new Error("Entity must be a variable declaration to be flattened");return[d,...(d.successCalls||[]).flatMap(a=>me(a,u,i)),...(d.errorCalls||[]).flatMap(a=>me(a,u,i)),...(d.inputs||[]).flatMap(a=>me(a,u,i)),...(d.outputs||[]).flatMap(a=>me(a,u,i)),...(d.internalCalls||[]).flatMap(a=>me(a,u,i)),...(d.writesValues||[]).flatMap(a=>me(a,u,i)),...d.readsValue?me(d.readsValue,u,i):[],...d.defaultValue?me(d.defaultValue,u,i):[],...(Ls(d)||[]).flatMap(a=>me(a,u,i)),...d.dataType?me(d.dataType,u,i):[],...d.parent?me(d.parent,u,i):[]]}function nS(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.VariableInstance)throw new Error("Entity must be a variable instance to be flattened");return[d,...(d.successCalls||[]).flatMap(a=>me(a,u,i)),...(d.errorCalls||[]).flatMap(a=>me(a,u,i)),...(d.inputs||[]).flatMap(a=>me(a,u,i)),...(d.outputs||[]).flatMap(a=>me(a,u,i)),...(d.internalCalls||[]).flatMap(a=>me(a,u,i)),...(d.writesValues||[]).flatMap(a=>me(a,u,i)),...d.readsValue?me(d.readsValue,u,i):[],...d.defaultValue?me(d.defaultValue,u,i):[],...(Ls(d)||[]).flatMap(a=>me(a,u,i)),...d.declaration?me(d.declaration,u,i):[],...d.parent?me(d.parent,u,i):[]]}function Xs(){const d=new Set,u=u2.flatMap(i=>me(i,d)).map(i=>i.id);if(!u.includes("http-request-error-return-delaration-id"))throw new Error("Built-in base entities must be included in the list");return u}function me(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(!d)throw new Error("Entity must be defined to be flattened");if(d.type===f.GenericReference)return[];if(i.ignoreBuiltInBaseEntities&&(ls.includes(d.type)||Xs().includes(d.id)))return[];if(u.has(d.id))return[];switch(d.type){case f.FunctionCall:return G5(d,u,i);case f.Operation:return W5(d,u,i);case f.Condition:return U5(d,u,i);case f.Loop:return H5(d,u,i);case f.Search:return rS(d,u,i);case f.GlobalEvent:return K5(d,u,i);case f.ReturnStatement:return tS(d,u,i);case f.ContinueStatement:return j5(d,u,i);case f.BreakStatement:return M5(d,u,i);case f.VariableDeclaration:return sS(d,u,i);case f.DefinitionEntity:return x5(d,u,i);case f.FunctionDeclaration:return S5(d,u,i);case f.Project:return X5(d,u,i);case f.ActionDescriptor:return V5(d,u,i);case f.ArgumentDeclaration:return L5(d,u,i);case f.ReturnDeclaration:return eS(d,u,i);case f.ValueDescriptor:return iS(d,u,i);case f.InputMap:return k5(d,u,i);case f.OutputMap:return Y5(d,u,i);case f.DataType:return F5(d,u,i);case f.InstalledProject:return q5(d,u,i);case f.InternalCall:return J5(d,u,i);case f.LiteralValue:return Z5(d,u,i);case f.Property:return Q5(d,u,i);case f.VariableInstance:return nS(d,u,i);case f.BuiltInBaseEntity:return i.ignoreBuiltInBaseEntities?[]:B5(d,u,i);case f.PrimitiveEntity:return i.ignoreBuiltInBaseEntities?[]:z5(d,u,i)}return[]}function Lb(d){return d.type===f.FunctionCall||d.type===f.InternalCall||[f.Operation,f.Condition,f.Loop].includes(d.type)?d.declaration.inputs:d.type===f.FunctionDeclaration||So.includes(d.type)?d.inputs:d.type===f.Search?d.inputsDeclarations:[]}function qIe(d,u){return u.type===f.Condition?u.inputs.find(i=>i.declaration.id===d.id):u.type===f.FunctionCall||u.type===f.Operation?u.inputs.find(i=>i.declaration.id===d.id):null}function aS(d){return mr.includes(d.type)?d.inputs:[]}function oS(d){var u;return d.type===f.FunctionCall?((u=d.declaration.returnStatements[0])==null?void 0:u.outputs)||[]:[f.Operation,f.Condition,f.Loop].includes(d.type)?d.declaration.outputs:d.type===f.Search?d.outputsDeclarations:Ar.includes(d.type)?d.outputs:[]}function JIe(d,u){return u.type===f.Condition?null:u.type===f.FunctionCall||u.type===f.Operation?u.outputs.find(i=>i.declaration.id===d.id):null}function ZIe(d){return d.type===f.Condition?[]:mr.includes(d.type)?d.outputs:[]}function Dm(d){const u=d.readsValue;return u?Er(u):null}function lS(d,u){const i=d.readsValue;return i?wm(i,u):null}function dS(d){const u=d.internalCalls||[];return R(Pi(R(u.flatMap(i=>[...i.successCalls,...i.errorCalls]))))}function uS(d){const u=d.internalCalls||[];return R(R(u.flatMap(i=>[...i.successCalls,...i.errorCalls])))}function eu(d){const u=_m(d),i=[];return u.forEach(a=>{if(mt.includes(a.type))i.push(a);else if(Ln.includes(a.type)){const l=Er(a.parent);i.push(l)}}),i}function tu(d){const u=_m(d),i=[];return u.forEach(a=>{if(mt.includes(a.type))i.push(a);else if(Ln.includes(a.type)){const l=a.parent;i.push(l)}}),i}function R(d){const u=new Set;return d.filter(i=>!i||u.has(i.id)?!1:(u.add(i.id),!0))}function wn(d,u=!1){const i=[];if(d.type===f.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)||[]),Mr.includes(d.type)&&i.push(...(d==null?void 0:d.detachedChildren)||[]),d.type===f.DefinitionEntity){const a=[...d.suggestedMethods,...d.methods].flatMap(l=>l.collapsed&&u?[]:wn(l));i.push(...a)}if(d.type===f.Condition){const a=d.successCalls.map(p=>Er(p)),l=d.errorCalls.map(p=>Er(p));i.push(...a,...l)}if(So.includes(d.type)){if(d.collapsed&&u)return[];const a=d.inputs.map(p=>eu(p)).flat(),l=d.calls.map(p=>Er(p));i.push(...R(a),...l)}if(mr.includes(d.type)&&d.type!==f.Condition&&d.type!==f.Loop){const a=d==null?void 0:d.outputs.map(e=>eu(e)).flat(),l=d.successCalls.map(e=>Er(e)),p=d.errorCalls.map(e=>Er(e));i.push(...R(a),...l,...p)}if(mt.includes(d.type)){const a=eu(d),l=dS(d);i.push(...a,...l)}if(d.type===f.Loop){const a=d.outputs.map(e=>eu(e)).flat();if(d.body){const e=wn(d.body,u);i.push(...e)}const l=d.errorCalls.map(e=>Er(e)),p=d.successCalls.map(e=>Er(e));i.push(...R(a),...p,...l)}if(d.type===f.FunctionDeclaration){if(d.collapsed&&u)return[];const a=d.inputs.map(p=>eu(p)).flat(),l=d.calls.map(p=>Er(p));i.push(...R(a),...l)}return R(i)}function Om(d,u=!1){const i=[];if(d.type===f.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)||[]),Mr.includes(d.type)&&i.push(...(d==null?void 0:d.detachedChildren)||[]),d.type===f.DefinitionEntity){const a=[...d.suggestedMethods,...d.methods].flatMap(l=>l.collapsed&&u?[]:Om(l));i.push(...a)}if(d.type===f.Condition){const a=d.successCalls,l=d.errorCalls;i.push(...a,...l)}if(So.includes(d.type)){if(d.collapsed&&u)return[];const a=d.inputs.map(p=>tu(p)).flat(),l=d.calls;i.push(...R(a),...l)}if(mr.includes(d.type)&&d.type!==f.Condition&&d.type!==f.Loop){const a=d==null?void 0:d.outputs.map(e=>tu(e)).flat(),l=d.successCalls,p=d.errorCalls;i.push(...R(a),...l,...p)}if(mt.includes(d.type)){const a=tu(d),l=uS(d);i.push(...a,...l)}if(d.type===f.Loop){const a=d.outputs.map(e=>tu(e)).flat();if(d.body){const e=Om(d.body,u);i.push(...e)}const l=d.errorCalls,p=d.successCalls;i.push(...R(a),...p,...l)}if(d.type===f.FunctionDeclaration){if(d.collapsed&&u)return[];const a=d.inputs.map(p=>tu(p)).flat(),l=d.calls;i.push(...R(a),...l)}return R(i)}function Cm(d,u=!1){const i=wn(d,u),a=[...i,...i.reduce((l,p)=>[...l,...Cm(p,u)],[])];return R(a)}function cS(d,u=!1){const i=Om(d,u),a=[...i,...i.reduce((l,p)=>[...l,...cS(p,u)],[])];return R(a)}function pS(d){const u=bo(d),i=[...u,...u.reduce((a,l)=>[...a,...pS(l)],[])];return R(i)}function ef(d){return d.implements.reduce((u,i)=>i.type===f.DefinitionEntity?[...u,f.DefinitionEntity,...ef(i),...tf(i)]:[...u,i.name],[])}function tf(d){return d.extends.reduce((u,i)=>i.type===f.DefinitionEntity?[...u,f.DefinitionEntity,...tf(i),...ef(i)]:[...u,i.name],[])}function Mb(d){return d.extends.reduce((u,i)=>i.type===f.DefinitionEntity?[...u,i,...Mb(i),...Bb(i)]:[...u,i],[])}function Bb(d){return d.implements.reduce((u,i)=>i.type===f.DefinitionEntity?[...u,i,...Bb(i),...Mb(i)]:[...u,i],[])}function ru(d){return[...tf(d),...ef(d)].filter((i,a,l)=>l.indexOf(i)===a)}function Ub(d){return d.implements.length===0&&d.extends.length===0?null:d.implements.find(a=>a.type===f.BuiltInBaseEntity&&a.name===Ue.PERSISTED_ENTITY)?d:[...d.implements,...d.extends].reduce((a,l)=>{if(l.type===f.DefinitionEntity){const p=Ub(l);if(p)return p}return a},null)}function HIe(d){const u=d.extends.find(i=>i.type===f.BuiltInBaseEntity);return u&&u.type===f.BuiltInBaseEntity?u:null}function WIe(d){const u=d.implements.find(i=>i.type===f.BuiltInBaseEntity);return u&&u.type===f.BuiltInBaseEntity?u:null}function $m(d){const u=d.extends.find(i=>i.type===f.DefinitionEntity);return u&&u.type===f.DefinitionEntity?u:null}function Ni(d){if(d.type===f.BuiltInBaseEntity)return[d];const u=[...d.implements,...d.extends].reduce((i,a)=>a.type===f.BuiltInBaseEntity?[...i,a]:a.type===f.DefinitionEntity?[...i,...Ni(a)]:i,[]);return R(u)}function rf(d){return d.type===f.PrimitiveEntity?!0:d.type===f.BuiltInBaseEntity?d.interactive:!Ni(d).find(a=>!a.interactive)}function YIe(d){return d.parent===d.project&&d.project.variableDeclarations.includes(d)}function jb(d){return d.parent!==d.project?!1:f.VariableDeclaration===d.type?d.project.variableDeclarations.includes(d):f.VariableInstance===d.type?d.project.variableInstances.includes(d):f.FunctionCall===d.type?d.project.functionCalls.includes(d):f.Condition===d.type?d.project.conditions.includes(d):f.Operation===d.type?d.project.operations.includes(d):f.Loop===d.type?d.project.loops.includes(d):f.Search===d.type?d.project.searches.includes(d):!1}function fS(d){if([...pr,f.DefinitionEntity,f.InstalledProject,f.Project].includes(d.type)||jb(d))return!1;const u=bo(d);return u.length===0?!0:u.some(i=>fS(i))}function xb(d){return[...pr,f.DefinitionEntity,f.InstalledProject,f.Project].includes(d.type)||jb(d)?!1:bo(d).length===0}function hS(d,u=0){if(xb(d)){const i=bo(d);return i.length===0?d:i.map(l=>hS(l,u+1)).reduce((l,p)=>l?p&&p.x<l.x?p:l:p,null)}return null}function yS(d){const u=[];if(xb(d))u.push(d);else return[];return bo(d).forEach(a=>{u.push(...yS(a))}),u}function Fb(d){return d.type===f.FunctionDeclaration&&d.parent!==d.project&&!![f.DefinitionEntity,f.Loop,f.InstalledProject].includes(d.parent.type)}function zIe(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 sf(d){switch(d){case f.DefinitionEntity:return ta;case f.FunctionDeclaration:return io;case f.VariableDeclaration:return uo;case f.VariableInstance:return lo;case f.FunctionCall:return Ao;case f.Operation:return so;case f.Condition:return oo;case f.ReturnStatement:return no;case f.Loop:return xi;case f.Search:return co;case f.InputMap:return Yn;case f.OutputMap:return mn;case f.ArgumentDeclaration:return Zn;case f.ReturnDeclaration:return Qi;case f.Property:return ea;case f.InstalledProject:return po;case f.Project:return N;case f.DataType:return hs;case f.GlobalEvent:return ao;case f.InternalCall:return fo;case f.ValueDescriptor:return vn;case f.BuiltInBaseEntity:return ra;case f.PrimitiveEntity:return es;case f.ActionDescriptor:return wt;case f.LiteralValue:return Gi;case f.ContinueStatement:return Ci;case f.BreakStatement:return ho;default:return null}}function Ki(d,u,i=null){const a=d!=null&&d.parent?Z(d==null?void 0:d.parent):null;let l=a?u.get(a):null,p=i||d;if((d==null?void 0:d.id)===(u==null?void 0:u.id))return u;if(d.type===f.ReturnStatement)return Wr(d,u,p);if(d.type===f.FunctionDeclaration&&(l==null?void 0:l.type)===f.Loop)return l;if(pr.includes(d.type))return d;if(d.type===f.Loop)return p.id===d.id?l:d;if(ls.includes(d.type))return null;const e=d.parent;if(!e)return null;if(e.type===f.GenericReference){const y=Z(e);if(!y)return null;const v=u.get(y);return v?Ki(v,u,p):null}else return e===u?u:Ki(e,u,p)}function Wr(d,u,i=null){const a=d!=null&&d.parent?Z(d==null?void 0:d.parent):null;let l=a?u.get(a):null,p=i||d;if(d.type===f.FunctionDeclaration&&(l==null?void 0:l.type)===f.Loop)return Wr(l.parent,u,p);if(pr.includes(d.type))return d;if(ls.includes(d.type))return null;const e=d.parent;if(!e)return null;if(e.type===f.GenericReference){const y=Z(e);if(!y)return null;const v=u.get(y);return v?Wr(v,u,p):null}else return e===u?u:Wr(e,u,p)}function nf(d,u){if(ls.includes(d.type)||u.getBuiltIn(d.id))return null;const i=ki(d.parent,u);return i?i===u?Mr.includes(d.type)?d:null:i.type===f.DefinitionEntity?d:nf(i,u):null}function Pm(d,u,i){if(d===u||u===i||d===i||!d||!u)return!1;const a=Ki(u.parent,i);return a===i?!1:a===d?!0:Pm(a,u,i)}var Nm=(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))(Nm||{});function Qs(d,u,i){const a=Ki(d,i),l=Ki(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!==f.Project)return{compatible:!0,type:"same-both-local",commonAncestorScope:a};if(a===l&&a.type===f.Project)return{compatible:!0,type:"same-both-global",commonAncestorScope:a};if(a.type===f.Project&&l.type!==f.Project)return{compatible:!1,type:"a-is-global-b-is-not",commonAncestorScope:a};if(a.type!==f.Project&&l.type===f.Project)return{compatible:!1,type:"b-is-global-a-is-not",commonAncestorScope:l};if(Pm(a,l,i))return{compatible:!0,type:"b-in-a",commonAncestorScope:a};if(Pm(l,a,i))return{compatible:!0,type:"a-in-b",commonAncestorScope:l};const y=Vb(a,l);return y===i?{compatible:!1,type:"parallel-in-project",commonAncestorScope:y}:y?{compatible:!1,type:"parallel-in-common-parent",commonAncestorScope:Ki(y,i)}:{compatible:!1,type:"parallel-in-project",commonAncestorScope:i}}function mS(d,u,i){const a=Qs(d,u,i);if(!a.compatible||a.type!=="same-both-local")return null;if(d===u)return d;let l=Ki(d.parent,i);if(l){if(l===u)return u;if(l.type===f.Project)return d}else return d;for(;l;){if(l){if(l===u)return u;if(l.type===f.Project)return d}else return d;l=Ki(l.parent,i)}let p=Ki(u.parent,i);if(p){if(p===d)return d;if(p.type===f.Project)return u}else return u;for(;p;){if(p){if(p===d)return d;if(p.type===f.Project)return u}else return u;p=Ki(p.parent,i)}return null}function vS(d){return d.length===0?null:d.length===1?d[0]:d.reduce((i,a)=>{const l=mS(i,a,a.project);return!l||l===a?i:a},d[0])}function ki(d,u){if(!d)return null;let i;return typeof d=="string"?i=d:d.type===f.GenericReference?i=Z(d):i=d.id,i===u.id?u:u.get(i)}function wo(d){if(!d)return null;if(ls.includes(d.type))return d;if(d.type===f.Project)return null;if(d.project.getBuiltIn(d.id))return d;const u=d.parent;return!u||u.type===f.Project?null:wo(u)}function af(d){const u=[];function i(p,e){return u.some(y=>y.blockedByCaller===p&&y.blockedByCalling===e)}function a(p,e){i(p,e)||u.push({blockedByCaller:p,blockedByCalling:e})}const l=nf(d,d.project);return d.calledBySuccess.forEach(p=>{[...p.successCalls||[]].forEach(v=>{Ar.includes(v.type)&&v!==d&&(_t(d).find(A=>A===v)||a(p,v))});let y;if(mr.includes(p.type)&&(y=p),y){const v=af(y);v.reachable||_t(d).find(A=>A===p)||v.blocks.forEach(A=>{a(p,A.blockedByCalling)})}}),d.calledByError.forEach(p=>{[...p.errorCalls||[]].forEach(v=>{Ar.includes(v.type)&&v!==d&&(_t(d).find(A=>A===v)||a(p,v))});let y;if(mr.includes(p.type)&&(y=p),y){const v=af(y);v.reachable||_t(d).find(A=>A===p)||v.blocks.forEach(A=>{a(p,A.blockedByCalling)})}}),d.calledByEntry.forEach(p=>{if([...p.calls||[]].forEach(v=>{Ar.includes(v.type)&&v!==d&&(_t(d).find(A=>A===v)||a(p,v))}),p===l)return;let y;if(p.type===f.FunctionDeclaration){const v=Er(p);if(v.type===f.DefinitionEntity)return;v.type===f.Loop&&(y=v)}if(y){const v=af(y);v.reachable||v.blocks.forEach(E=>{a(p,E.blockedByCalling)})}}),{reachable:u.length===0,entryPoint:l,blocks:u}}function XIe(d){return rh.includes(d.type)?d.type===f.FunctionDeclaration?!Fb(d):!0:!1}function QIe(d){if(f.ActionDescriptor===d.type){if(d.project.operationDeclarations.find(p=>p.id===d.id))return f.Operation;if(d.project.globalEventActionDescriptors.find(p=>p.id===d.id))return f.GlobalEvent;if(d.project.loopDeclarations.find(p=>p.id===d.id))return f.Loop;if(d.project.conditionDeclarations.find(p=>p.id===d.id))return f.Condition}return d.type}function Vm(d,u){return d.type===f.BuiltInBaseEntity?d.name===u:!!tf(d).includes(u)}function eAe(d,u){return d.type===f.BuiltInBaseEntity?d.name===u:!!ef(d).includes(u)}function Es(d,u){return d.type===f.BuiltInBaseEntity?d.name===u:!!ru(d).includes(u)}function tAe(d){const u=[];return d.entities.forEach(i=>{if(Vm(i,Ue.PERSISTED_ENTITY)){u.push(i);return}}),R(u)}function rAe(d){const u=[];return d.entities.forEach(i=>{if(Vm(i,Ue.RELATIONAL_DATABASE)){u.push(i);return}}),R(u)}function iAe(d){return d.type!==f.DefinitionEntity||d.abstract||!Vm(d,Ue.PERSISTED_ENTITY)?null:(d==null?void 0:d.properties.find(i=>{var a;return((a=i.implements)==null?void 0:a.id)===Ee[f.BuiltInBaseEntity][Ue.PERSISTED_ENTITY].properties.primaryKey.id&&!i.abstract}))||null}function ES(d){var a;const u=Ub(d);if(!u)return null;const i=u.properties.find(l=>{var p;return((p=l.implements)==null?void 0:p.id)===Ee[f.BuiltInBaseEntity][Ue.PERSISTED_ENTITY].properties.database.id});return i?(a=i.getDefaultValue())==null?void 0:a.valueAsType:null}function iu(d){if(d.type!==f.DefinitionEntity)return[];if(d.abstract)return[];if(!Es(d,Ue.PERSISTED_ENTITY))return[];const u=[],i=d.properties.filter(a=>{var l;return((l=a.implements)==null?void 0:l.id)!==Ee[f.BuiltInBaseEntity][Ue.PERSISTED_ENTITY].properties.database.id&&!a.abstract});return u.push(...i),u}function sAe(d){var i;if(!d||d.type!==f.DefinitionEntity||!Es(d,Ue.PERSISTED_ENTITY))return null;const u=d.properties.find(a=>{var l;return((l=a.implements)==null?void 0:l.id)===Ee[f.BuiltInBaseEntity][Ue.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(!Ag.includes(u.type)||!d)return u.project||null;let i=u.project;return d.type===f.Project?i=d:((a=u.project)==null?void 0:a.id)!==d.project.id&&(i=d.project),i}function nAe(d){switch(d){case f.Project:return N;case f.InstalledProject:return po;case f.DefinitionEntity:return ta;case f.FunctionDeclaration:return io;case f.GlobalEvent:return ao;case f.VariableInstance:return lo;case f.VariableDeclaration:return uo;case f.InputMap:return Yn;case f.OutputMap:return mn;case f.Condition:return oo;case f.Operation:return so;case f.FunctionCall:return Ao;case f.ReturnDeclaration:return Qi;case f.ArgumentDeclaration:return Zn;case f.PrimitiveEntity:return es;case f.DataType:return hs;case f.Property:return ea;case f.ActionDescriptor:return wt;case f.ReturnStatement:return no;case f.ContinueStatement:return Ci;case f.BreakStatement:return ho;case f.Loop:return xi;case f.Search:return co;case f.ValueDescriptor:return vn;case f.InternalCall:return fo;case f.LiteralValue:return Gi}return null}function aAe(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 Ur(d,u){const i=sf(d.type);return i?!i.MUTABLE_META_PROPERTIES.every(l=>{const p=d[l],e=u[l];return e===void 0||p===e?!0:Array.isArray(p)&&Array.isArray(e)?p.length!==e.length?!1:p.every((y,v)=>y===e[v]):!1}):!1}function Lm(d,u={}){if(d.type===f.Project)return[];if(!d.parent)return[];const i=Z(d.parent);if(!i)return[];const a=u[i];return a?[a.id,...Lm(a,u)]:[]}function oAe(d){const u=[],i=new Set;return[...d.listAdded,...d.listUpdated,...d.listAffected].forEach(a=>{const l=Er(a);!l||i.has(l.id)||(i.add(l.id),u.push(l))}),R(u)}function lAe(d){if(d.type===f.Condition)return null;if(d.type===f.Search)return d.project.getBuiltIn(Ee["value-descriptor"][Ql.SearchErrorOutputDescriptor].id)||null;if(d.type===f.Operation)return d.declaration.error;if(d.type===f.FunctionCall){const i=d.declaration.returnStatements.find(a=>!!a.throws);return(i==null?void 0:i.throws)||null}return null}function TS(d){const u=d.entities.filter(l=>!!l.implements.find(p=>p.id===Ee["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.id)),i=u.find(l=>{const p=l.properties.find(v=>v.implements&&v.implements.id===Ee["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.default.id),e=p==null?void 0:p.getDefaultValue();return(e==null?void 0:e.value)===!0});return i||u[0]||null}function Gb(d,u){const i=Array.from(new Set([...u.getAllBuiltInIds(),...Xs()]));return!!(i.includes(d.id)||!Lm(d,{...u.instances,...u.builtInInstances}).every(p=>!i.includes(p)))}function IS(d){if(!d)return null;if(d.type===f.Project)return d.id;const u=d.parent;return u?IS(u):d.id}function of(d){if(d.declaration&&d.declaration.type===f.Property){if(d.declaration.interactive){if(d.declaration.implements&&!d.declaration.implements.interactive)return!1;if(d.declaration.extends&&!d.declaration.extends.interactive)return!1}else return!1;if(d.declaration.private){const u=Er(d),i=nf(u,d.project);if((i==null?void 0:i.type)===f.FunctionDeclaration&&(i==null?void 0:i.parent.type)===f.DefinitionEntity&&(i==null?void 0:i.parent.id)!==d.declaration.parent.id)return!1}}return!0}function Sb(d){if(d.interactive){if(d.implements&&!d.implements.interactive)return!1;if(d.extends&&!d.extends.interactive)return!1}else return!1;if(d.private){const u=Er(d),i=nf(u,d.project);if((i==null?void 0:i.type)===f.FunctionDeclaration&&(i==null?void 0:i.parent.type)===f.DefinitionEntity&&(i==null?void 0:i.parent.id)!==d.parent.id)return!1}return!0}function dAe(d,u,i){const a=u,l=i,p=!!i,e=[];return a.forEach(y=>{var v;if(p){const E=Qs(l,y,d);if(!E.compatible&&E.type!=="b-is-global-a-is-not")return;e.push(y)}else{if(((v=y.parent)==null?void 0:v.type)!==f.Project)return;e.push(y)}}),R(e)}function jr(d){const u=d.split(/[\s-]+/).filter(p=>p.length>0);if(u.length===0)return"";const i=u[0],a=i[0].toLowerCase()+i.slice(1),l=u.slice(1).map(p=>p[0].toUpperCase()+p.slice(1));return[a,...l].join("")}function su(d){return d.split(/[\s-]+/).filter(i=>i.length>0).map(i=>i[0].toUpperCase()+i.slice(1)).join("")}function AS(d){return(d.match(/[A-Z]{2,}(?=[A-Z][a-z]+[0-9]*|\b)|[A-Z]?[a-z]+[0-9]*|[A-Z]|[0-9]+/g)||[]).join("-")}function Mm(d){return AS(d).toLowerCase()}function nu(d){var i,a,l,p;if(!d)return"Any data type";let u="";if(d.interactiveEntities===!1?u+=` but only definition nodes ${d.asType?"as template ":""}that don't include non-interactive built-in functionality`:d.interactiveEntities===!0&&(u+=` but only definition nodes ${d.asType?"as template ":""}that extend or implement interactive built-in functionality`),d.staticEntities===!1?u?u+=" and that aren't a single global copy instance":u+=` but only definition nodes ${d.asType?"as template ":""}that aren't a single global copy instance`:d.staticEntities===!0&&(u?u+=" and that are a single global copy instance":u+=` but only definition nodes ${d.asType?"as template ":""}that are a single global copy instance`),d.actionEntities===!1?u?u+=" excluding executable/action nodes":u+=` excluding executable/action nodes ${d.asType?"templates ":""}`:d.actionEntities===!0&&(u?u+=" and not executable/action nodes":u+=" but not executable/action nodes"),d.entity&&(u=""),d.asType&&!u&&!((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)&&!((p=d.orChildrenGroup)!=null&&p.length))return e?`List of an any data type${u}`:`Any data type${u}`;let y="",v=!1,E=!1;return(d.andChildrenGroup||[]).forEach(w=>{const A=nu(w),$=gd(A);v&&(y+=" and "),w.isGroup?y+="("+$+")":v?y+=$:y+=A,v=!0,E=!0}),(d.orChildrenGroup||[]).forEach(w=>{const A=nu(w),$=gd(A);v&&(E&&(y+=","),y+=" or "),w.isGroup?y+="("+$+")":v?y+=$:y+=A,v=!0}),e?`List of ${gd(y)}`:y}if(d.entity.type===f.PrimitiveEntity){let e=d.entity.name;switch(d.entity.name){case Q.String:e="Text";break;case Q.KeyValue:e="Data structure";break}return d.isList?`List of ${e}s${u}`:`${e.slice(0,1).toUpperCase()}${e.slice(1)}${u}`}else if(d.entity.type===f.DefinitionEntity){const e=ne(d.entity,d.project);return d.isList?`List of ${e} values${u}`:e.slice(0,1).toUpperCase()+e.slice(1)+u}else if(d.entity.type===f.BuiltInBaseEntity){const e=wS(d.entity);return d.isList?`List of ${e} values${u}`:e.slice(0,1).toUpperCase()+e.slice(1)+u}else if(d.entity.type===f.LiteralValue){if(d.entity.name===Q.Null)return"Empty value";if(d.entity.name===Q.Untyped)return"Untyped value";if(d.entity.name===Q.File)return"File";if(d.entity.name===Q.String)return`"${d.entity.value}" text`;if(d.entity.name===Q.Number)return`Number '${d.entity.value}'`;if(d.entity.name===Q.Boolean)return`${d.entity.value} value`;if(d.entity.name===Q.UUID)return`"${d.entity.value}" unique identifier`;if(d.entity.name===Q.Date)return`"${d.entity.value}" date`}return d.isList?`List of ${ne(d.entity,d.project)} values${u}`:`${ne(d.entity,d.project).slice(0,1).toUpperCase()+ne(d.entity,d.project).slice(1)} value${u}`}function uAe(d){if(!d)return"Any data type";const u=d.getDataType(null);return nu(u)}function Bm(d){switch(d.declaration.id){case _r.Equal:return"is equal to";case _r.NotEqual:return"is not equal to";case _r.MoreThan:return"is greater than";case _r.MoreThanOrEqual:return"is greater than or equal to";case _r.LessThan:return"is less than";case _r.LessThanOrEqual:return"is less than or equal to";case _r.And:return"and";case _r.Or:return"or";case zr.Empty:return"is empty";case zr.NotEmpty:return"is not empty"}}function bS(d){return d.includes(Ue.HTTP_ENDPOINT)?"HTTP endpoint":d.includes(Ue.PERSISTED_ENTITY)?"Persisted entity":d.includes(Ue.CRON_JOB)?"Scheduled execution":d.includes(Ue.RELATIONAL_DATABASE)?"Relational database":"Entity"}function wS(d){switch(d.name){case Ue.HTTP_ENDPOINT:return"HTTP endpoint";case Ue.PERSISTED_ENTITY:return"Persisted entity";case Ue.CRON_JOB:return"Scheduled execution";case Ue.RELATIONAL_DATABASE:return"Relational database"}return"Entity"}function cAe(d){const u=$m(d);if(!u){const i=ru(d);return i.includes(Ue.HTTP_ENDPOINT)?"HTTP endpoint":i.includes(Ue.PERSISTED_ENTITY)?"Persisted entity":i.includes(Ue.CRON_JOB)?"Scheduled execution":i.includes(Ue.RELATIONAL_DATABASE)?"Relational database":ne(d,d.project)+" entity"}return ne(u,d.project)+" entity"}function RS(d){let u="Find ";return d.outputsDeclarations.forEach((i,a)=>{const l=xy(i,null),p=gd(l&&l.entity?ne(l.entity,d.project):"unstructured data");a===0?u+=`${p} `:a===d.outputsDeclarations.length-1?u+=`and ${p} `:u+=`, ${p} `}),u}function _S(d){switch(d.name){case Q.String:return"Text";case Q.Number:return"Number";case Q.Boolean:return"Boolean";case Q.KeyValue:return"Data structure";case Q.UUID:return"Unique identifier";case Q.Date:return"Date";case Q.EntityTemplate:return"Entity as template";case Q.Enum:return"Enumeration";case Q.File:return"File";case Q.Null:return"Empty";case Q.ActionDescriptor:return"Action descriptor";case Q.Untyped:return"Untyped";default:return d.name}}function gS(d){switch(d.id){case ze.List:return"Loop over list items";case ze.ManualFlow:return"Manual flow control loop";case ze.ObjectKeys:return"Loop over object keys";case ze.ObjectValues:return"Loop over object values";case ze.Counted:return"Loop given number of times";case ze.String:return"Loop over text characters";case Jt.Addition:return"Sum numbers";case Jt.Subtraction:return"Subtract numbers";case Jt.Multiplication:return"Multiply numbers";case Jt.Division:return"Divide numbers";case Jt.Remainder:return"Get remainder of numbers";case Jt.Exponentiation:return"Get exponent of numbers";case Se.AddIndex:return"Add at index position";case Se.DeleteFirst:return"Delete first character";case Se.DeleteLast:return"Delete last character";case Se.DeleteIndex:return"Delete at index position";case Se.Join:return"Join texts";case Se.ReplaceAllMatches:return"Replace all matches";case Se.ReplaceFirst:return"Replace first match";case Se.ReplaceLast:return"Replace last match";case Se.Split:return"Split text";case Se.ReplaceIndex:return"Replace at index position";case Se.ReplaceSingleMatch:return"Replace single match";case Se.GetFirst:return"Get first character";case Se.GetLast:return"Get last character";case Se.GetIndexItem:return"Get at index position";case Se.GetIndexOf:return"Get the index number of the character";case Se.Append:return"Add at the end";case Se.Prepend:return"Add at the start";case sr.Wait:return"Wait";case sr.Parallel:return"Run in parallel";case sr.Sequential:return"Run in sequence";case yi.HttpRequest:return"HTTP request";case cr.CreateNewInstance:return"Create new copy of entity";case Ze.AddIndex:return"Add item at index position";case Ze.DeleteFirst:return"Delete first item";case Ze.DeleteLast:return"Delete last item";case Ze.DeleteIndex:return"Delete item at index position";case Ze.Join:return"Join lists";case Ze.ReplaceFirst:return"Replace first match";case Ze.ReplaceLast:return"Replace last match";case Ze.Split:return"Split list";case Ze.ReplaceIndex:return"Replace at index position";case Ze.GetFirst:return"Get first item";case Ze.GetLast:return"Get last item";case Ze.GetIndexItem:return"Get item at index position";case Ze.Append:return"Add item at the end";case Ze.Prepend:return"Add item at the start";case Ta.PROJECT_PUBLICATION_COMPLETED:return"Project publication completed";default:return(d.name.slice(0,1).toUpperCase()+d.name.slice(1)).replaceAll("-"," ")}}function ne(d,u){var i;if(f.FunctionDeclaration===d.type){const a=d.name;if(Object.values(qi).includes(a))switch(a){case qi.AbortExecution:return"Abort ongoing execution";case qi.DeletePersistedEntity:return"Delete entry from database";case qi.SavePersistedEntity:return"Save entity data to database";default:return Ti(d.type).replaceAll("-"," ")}return a}if(f.BuiltInBaseEntity===d.type)return bS([d.name]);if(Tg.includes(d.type)&&d.type!==f.ActionDescriptor)return d.name;switch(d.type){case f.Search:return RS(d);case f.GlobalEvent:return d.implements?ne(d.implements,u):Ti(d.type).replaceAll("-"," ");case f.Operation:case f.InternalCall:case f.Loop:const a=ki(d.declaration,u);return a||Me.log("Loop without declaration: ",d),ne(a,u);case f.ActionDescriptor:return gS(d);case f.BreakStatement:const l=ki(d.parent,u);return l||Me.log("Break without parent: ",d),`Stop loop ${ne(l,u)}`;case f.ContinueStatement:const p=ki(d.parent,u);return p||Me.log("continue without parent: ",d),`Execute next iteration of ${ne(p,u)}`;case f.FunctionCall:return ki(d.declaration,u).name;case f.Condition:{const y=d;if((i=d.inputs)!=null&&i.length){y.inputs[0]||Me.log("condition without input: ",d);const v=ne(y.inputs[0],y.project);if(y.inputs[1]){const E=y.inputs[1].declaration.name;return`If ${v} ${Bm(y)} ${E}`}return`If ${v} ${Bm(y)}`}else return`If ${Bm(y)}`}case f.ReturnStatement:{const y=ki(d.parent,u);return y?`Output of ${ne(y,u)}`:"Return statement"}case f.InputMap:if(d.declaration){const y=ki(d.declaration,u);return y||(Me.log("Input without declaration: ",d),Me.log("Og declaration: ",d.declaration)),ne(y,u)||""}else return d.name||"";case f.VariableInstance:{const y=ki(d.declaration,u);return y||Me.log("Var without declaration: ",d),ne(y,u)||""}case f.OutputMap:if(d.declaration){const y=ki(d.declaration,u);return(y==null?void 0:y.name)||""}else return"";case f.PrimitiveEntity:case f.LiteralValue:return _S(d);default:return Ti(d.type).replaceAll("-"," ")}}function Kb(d,u){const i=[];d.name||i.push(new ee({id:`${d.id}--${ae.EmptyName}`,message:`Entity with id "${d.id}" and type "${d.type}" has an empty name. Please provide a 'name' string.`,severity:q.Error,code:ae.EmptyName,issue:null}));const a=u.entities.filter(l=>l.name===d.name);return a.length&&i.push(new ee({id:`${d.id}--${ae.NameNotUniqueInScope}`,message:`Entity with id "${d.id}" and type "${d.type}" has a name "${d.name}" that is not unique in the project. Entity with id "${a[0].id}" has the same name.
|
|
396
|
+
You shouldn't have to manually update a 'parent' property. The equivalent result is to change its callers, the value writters of its inputs, or the value readers of its outputs.`,issue:null})),{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 F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"sync-dependents"))){const a=[],l=[],p=[],e=[];return Object.values(this.detachedDependents).forEach(y=>{const v=y.entity.afterAllChildrenInitialized(i);a.push(...v.updated),l.push(...v.added),p.push(...v.removed),e.push(...v.affected)}),i==null||i.attemptAutoclose("sync-dependents",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(e),self:this}}onDetachedDependencyRemoved(i,a,l){const p=[],e=[],y=[],v=[];if(a==="declaration"){const{updated:E,added:w,removed:A}=this.remove({ignoreUpstream:!1},l);p.push(...E),e.push(...w),y.push(...A)}if(a==="parent"){const{updated:E,added:w,removed:A}=this.remove({ignoreUpstream:!1},l);p.push(...E),e.push(...w),y.push(...A)}return{updated:R(p),added:R(e),removed:R(y),affected:R(v),self:this}}onDetachedDependencyRestored(i,a,l){const p=[],e=[],y=[],v=[];if(a==="declaration"){const{updated:E,added:w,removed:A}=this.restore({},l);p.push(...E),e.push(...w),y.push(...A)}if(a==="parent"){const{updated:E,added:w,removed:A}=this.restore({},l);p.push(...E),e.push(...w),y.push(...A)}return{updated:R(p),added:R(e),removed:R(y),affected:R(v),self:this}}unsubscribeFromDependencies(){var i;return(i=this.parent)==null||i.unsubscribeDependents([{entity:this,field:"parent"}]),this.declaration.unsubscribeDependents([{entity:this,field:"declaration"}]),this}subscribeToDependencies(){var i;return(i=this.parent)==null||i.subscribeDependents([{entity:this,field:"parent"}]),this.declaration.subscribeDependents([{entity:this,field:"declaration"}]),this}increaseVersion(i){if(i&&!L(i).isValid())throw new Error(`The shared timestamp '${i}' is not a valid ISO 8601 date string.`);return i&&L(i).isSame(L(this.createdAt))?this:(this.previousVersion=this.version,this.version=N.UUID.uuid(),this.createdAt=L(i).toISOString()||L().toISOString(),this)}captureVersion(){var a;const i=((a=this.knownVersions)==null?void 0:a.get(this.version))||new Qt(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.process=this.process,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=[],p=[],e=[];if(this.parent){this.parent.increaseVersion(i);const y=this.parent.recursiveCaptureUpstreamVersions(i);a.push(this.parent,...y.updated),l.push(...y.added),p.push(...y.removed)}return{updated:R(a),added:R(l),removed:R(p),affected:R(e),self:this}}async restoreVersion(i){var v;const a=[],l=[],p=[],e=[];if(this.version===i)return{updated:R(a),added:R(l),removed:R(p),affected:R(e),self:this};if(!this.knownVersions){const E=new Map;for(const[w,A]of this.knownVersions||new Map){if(E.set(w,A),A.activeVersion=!1,A.knownVersions)for(const[$,V]of A.knownVersions)E.set($,V);A.knownVersions=null}}let y=(v=this.knownVersions)==null?void 0:v.get(i);if(!y){const E=await this.APILoadVersion({},i);if(!E)throw new Error(`Version with id '${i}' for entity with id '${this.id}' not found.`);y=new Qt(E,this.project)}return this.metaSync(y.toShallowJSON(),null),this.previousVersion=y.previousVersion,this.version=y.version,this.createdAt=y.createdAt,this.author=y.author,this.deleted=y.deleted,this.inputs=y.inputs,this.outputs=y.outputs,this.error=y.error,this.successCalls=y.successCalls,this.errorCalls=y.errorCalls,this.process=y.process,this.declaration=y.declaration,this.calledBySuccess=y.calledBySuccess,this.calledByError=y.calledByError,this.calledByEntry=y.calledByEntry,this.parent=y.parent,{updated:R(a),added:R(l),removed:R(p),affected:R(e),self:this}}updateWithShallowTransfer(i,a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"update-with-shallow-transfer"))){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=Z(i.parent),p=this.project.get(l),e=this.parent;if(e&&e.id!==(p==null?void 0:p.id)&&this.removeFromParent(a),p)this.setParent(p,a);else throw a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(i.declaration){const l=Z(i.declaration),p=this.project.get(l);p&&this.setDeclaration(p)}return i.calledByEntry.forEach(l=>{const p=Z(l),e=this.project.get(p);e&&(this.addEntryCaller(e,a),e.addCall(this,a))}),[...this.calledByEntry].forEach(l=>{i.calledByEntry.find(e=>Z(e)===l.id)||(this.removeCaller(l,a),l.removeCall(this,a))}),i.calledBySuccess.forEach(l=>{const p=Z(l),e=this.project.get(p);e&&(this.addSuccessCaller(e,a),e.addSuccessCall(this,a))}),[...this.calledBySuccess].forEach(l=>{i.calledBySuccess.find(e=>Z(e)===l.id)||(this.removeCaller(l,a),l.removeCall(this,a))}),i.calledByError.forEach(l=>{const p=Z(l),e=this.project.get(p);e&&(this.addErrorCaller(e,a),e.addErrorCall(this,a))}),[...this.calledBySuccess].forEach(l=>{i.calledBySuccess.find(e=>Z(e)===l.id)||(this.removeCaller(l,a),l.removeCall(this,a))}),this.captureVersion(),this.subscribeToDependencies(),a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),this}hydrateAncestors(){const i=[],a=[],l=[],p=[];if(this.initialData.parent){const e=Z(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=Z(this.initialData.declaration),y=this.project.get(e);y&&(this.setDeclaration(y),i.push(y))}return this.initialData.calledByEntry.forEach(e=>{const y=Z(e),v=this.project.get(y);v&&this.addEntryCaller(v,null)}),this.initialData.calledBySuccess.forEach(e=>{const y=Z(e),v=this.project.get(y);v&&this.addSuccessCaller(v,null)}),this.initialData.calledByError.forEach(e=>{const y=Z(e),v=this.project.get(y);v&&this.addErrorCaller(v,null)}),{updated:R(i),added:R(a),removed:R(l),affected:R(p),self:this}}afterAllChildrenInitialized(i=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"after-all-children-initialized"))){const a=[],l=[],p=[],e=[];this.initialized=!0;const{updated:y,added:v,removed:E}=this.syncInputs(i),{updated:w,added:A,removed:$}=this.syncOutputs(i);return a.push(...y,...w),l.push(...v,...A),p.push(...E,...$),this.captureVersion(),i==null||i.attemptAutoclose("after-all-children-initialized",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(e),self:this}}addSelfToProject(i=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-self-to-project"))){var y;const a=[this],l=[],p=[],e=[];return this.parent===this.project&&this.project.addFunctionCall(this),(y=this.process)==null||y.writesValues.forEach(v=>{v.setValueWriter(this.process,i),a.push(v)}),this.successCalls.forEach(v=>{v.addSuccessCaller(this,i),a.push(v)}),this.errorCalls.forEach(v=>{v.addErrorCaller(this,i),a.push(v)}),this.calledBySuccess.forEach(v=>{v.addSuccessCall(this,i),a.push(v)}),this.calledByError.forEach(v=>{v.addErrorCall(this,i),a.push(v)}),this.calledByEntry.forEach(v=>{v.addCall(this,i),a.push(v)}),this.subscribe(),this.subscribeToDependencies(),i==null||i.attemptAutoclose("add-self-to-project",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(e),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}removeInput(i,a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-input"))){const l=this.inputs.findIndex(p=>p.id===i.id);return l>-1&&(this.inputs.splice(l,1),a&&(a==null||a.add(this,S.Affected))),a==null||a.attemptAutoclose("remove-input",this.id),this}addInput(i,a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-input"))){return this.inputs.includes(i)?(a==null||a.attemptAutoclose("add-input",this.id),this):(this.inputs.push(i),a==null||a.add(this,S.Affected),a==null||a.attemptAutoclose("add-input",this.id),this)}addOutput(i,a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-output"))){return this.outputs.includes(i)?(a==null||a.attemptAutoclose("add-output",this.id),this):(this.outputs.push(i),a==null||a.add(this,S.Affected),a==null||a.attemptAutoclose("add-output",this.id),this)}removeOutput(i,a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-output"))){const l=this.outputs.findIndex(p=>p.id===i.id);return l>-1&&(this.outputs.splice(l,1),a&&(a==null||a.add(this,S.Affected))),a==null||a.attemptAutoclose("remove-output",this.id),this}addValueReader(i,a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-value-reader"))){var l;return this.process&&!this.process.writesValues.includes(i)&&((l=this.process)==null||l.addValueReader(i,a),a==null||a.add(this,S.Affected)),a==null||a.attemptAutoclose("add-value-reader",this.id),this}removeValueReader(i,a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-value-reader"))){var l;return this.process&&this.process.writesValues.includes(i)&&((l=this.process)==null||l.removeValueReader(i,a),a==null||a.add(this,S.Affected)),a==null||a.attemptAutoclose("remove-value-reader",this.id),this}addSuccessCaller(i,a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-success-caller")),l=!1){return this.calledBySuccess.find(p=>p.id===i.id)||(this.calledBySuccess.push(i),a==null||a.add(this,S.Updated),l&&We(this,a)),a==null||a.attemptAutoclose("add-success-caller",this.id),this}addErrorCaller(i,a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-error-caller")),l=!1){return this.calledByError.find(p=>p.id===i.id)||(this.calledByError.push(i),a==null||a.add(this,S.Updated),l&&We(this,a)),a==null||a.attemptAutoclose("add-error-caller",this.id),this}addEntryCaller(i,a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-entry-caller")),l=!1){return this.calledByEntry.find(p=>p.id===i.id)||(this.calledByEntry.push(i),a==null||a.add(this,S.Updated),l&&We(this,a)),a==null||a.attemptAutoclose("add-entry-caller",this.id),this}addErrorCall(i,a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-error-call")),l=!1){return this.errorCalls.find(p=>p.id===i.id)||(this.errorCalls.push(i),l&&We(this,a),a==null||a.add(this,S.Affected)),a==null||a.attemptAutoclose("add-error-call",this.id),this}addSuccessCall(i,a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-success-call")),l=!1){return this.successCalls.find(p=>p.id===i.id)||(this.successCalls.push(i),l&&We(this,a),a==null||a.add(this,S.Affected)),a==null||a.attemptAutoclose("add-success-call",this.id),this}removeCall(i,a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-call")),l=!1){const p=this.successCalls.findIndex(y=>y.id===i.id);p>-1&&(this.successCalls.splice(p,1),a==null||a.add(this,S.Affected));const e=this.errorCalls.findIndex(y=>y.id===i.id);return e>-1&&(this.errorCalls.splice(e,1),a==null||a.add(this,S.Affected)),l&&We(this,a),a==null||a.attemptAutoclose("remove-call",this.id),this}removeCaller(i,a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-caller")),l=!1){return this.calledBySuccess=this.calledBySuccess.filter(p=>p.id!==i.id?!0:(a==null||a.add(this,S.Updated),a==null||a.add(p,S.Affected),!1)),this.calledByError=this.calledByError.filter(p=>p.id!==i.id?!0:(a==null||a.add(this,S.Updated),a==null||a.add(p,S.Affected),!1)),this.calledByEntry=this.calledByEntry.filter(p=>p.id!==i.id?!0:(a==null||a.add(this,S.Updated),a==null||a.add(p,S.Affected),!1)),l&&We(this,a),a==null||a.attemptAutoclose("remove-caller",this.id),this}setParent(i,a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"set-parent"))){var l;return((l=this.parent)==null?void 0:l.id)!==(i==null?void 0:i.id)&&(this.parent=i,a&&(a==null||a.add(this,S.Updated))),a==null||a.attemptAutoclose("set-parent",this.id),this}setDeclaration(i){return this.declaration=i,this}initChildren(i=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"init-children"))){if(this.initialized||this.startedInitialization)return this;if(this.startedInitialization=!0,this.initialData.declaration.type===f.FunctionDeclaration){const a=te(this.initialData.declaration,this.project);this.declaration=a}else{const a=Z(this.initialData.declaration),l=this.project.get(a);this.declaration=l}return this.successCalls=this.initialData.successCalls.map(a=>{const l=te(a,this.project);if(l.addSuccessCaller(this),[f.BreakStatement,f.ContinueStatement].includes(l.type))l.setParent(this.parent.parent,null),l.initChildren(i);else if(l.type===f.ReturnStatement){const p=Wr(this,this.project);l.setParent(p,null),l.initChildren(i)}else l.type!==f.InternalCall&&(l.setParent(this.parent,null),l.initChildren(i));return l}),this.errorCalls=this.initialData.errorCalls.map(a=>{const l=te(a,this.project);if(l.addErrorCaller(this),[f.BreakStatement,f.ContinueStatement].includes(l.type))l.setParent(this.parent.parent,null),l.initChildren(i);else if(l.type===f.ReturnStatement){const p=Wr(this,this.project);l.setParent(p,null),l.initChildren(i)}else l.type!==f.InternalCall&&(l.setParent(this.parent,null),l.initChildren(i));return l}),this.inputs=this.initialData.inputs.map(a=>{const l=te(a,this.project);return l.setParent(this,null),l.initChildren(i),l}),this.initialData.process&&(this.process=te(this.initialData.process,this.project),this.process.setParent(this,null),this.process.initChildren(i)),this.initialData.error&&(this.error=te(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 F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"meta-sync"))){const l=Ur(this,i),p=this.toMeta();return this.x=i.x||p.x,this.y=i.y||p.y,super.metaSync(i),i.deleted===!0&&!p.deleted?a==null||a.add(this,S.Removed):i.deleted===!1&&p.deleted?a==null||a.add(this,S.Added):l&&(a==null||a.add(this,S.Updated)),a==null||a.attemptAutoclose("meta-sync",this.id),this}async APILoad(i=ve,...a){return await Qt.repository.APILoad(this.id,...a),this}async APICreate(i=ve,...a){return await Qt.repository.APICreate(this.toShallowJSON(),...a),this}async APIUpdate(i=ve,...a){return await Qt.repository.APIUpdate(this.toShallowJSON(),...a),this}async APIDelete(i=ve,...a){return await Qt.repository.APIDelete(this.toShallowJSON(),...a),this}async APIClone(i=ve,...a){return await Qt.repository.APIClone(this.id,...a),this}async APILoadVersion(i=ve,a,...l){return await Qt.repository.APILoadVersion(this.id,a,...l)}removeFromParent(i=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-from-parent"))){const a=[],l=[],p=[],e=[];return this.parent.type===f.Project?(this.parent.removeFunctionCall(this),e.push(this.parent)):this.parent.detachedChildren.includes(this)&&this.parent.unsubscribeDetachedChild(this),i==null||i.attemptAutoclose("remove-from-parent",this.id),{added:R(p),updated:R(a),removed:R(l),affected:R(e),self:this}}remove({ignoreUpstream:i}={ignoreUpstream:!1},a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-entity"))){var v;const l=[],p=[],e=[],y=[];if(a!=null&&a.hasRemoved(this.id))return a==null||a.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(p.push(this),this.unsubscribe(),this.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},a),Object.values(this.detachedDependents).forEach(E=>{const{updated:w,removed:A,added:$}=E.entity.onDetachedDependencyRemoved(this,E.field,a);l.push(...w),p.push(...A),e.push(...$)}),this.process){const{updated:E,removed:w}=(v=this.process)==null?void 0:v.remove({ignoreUpstream:!0},a);l.push(...E),p.push(...w)}if(this.inputs.forEach(E=>{const{updated:w,removed:A}=E.remove({ignoreUpstream:!0},a);l.push(...w),p.push(...A)}),this.outputs.forEach(E=>{const{updated:w,removed:A}=E.remove({ignoreUpstream:!0},a);l.push(...w),p.push(...A)}),this.error){const{updated:E,removed:w}=this.error.remove({ignoreUpstream:!0},a);l.push(...E),p.push(...w)}if(this.successCalls.forEach(E=>{l.push(E),E.removeCaller(this,a)}),this.errorCalls.forEach(E=>{l.push(E),E.removeCaller(this,a)}),!i){const E=this.removeFromParent(a);e.push(...E.added),l.push(...E.updated),p.push(...E.removed),y.push(...E.affected),this.calledBy.forEach(w=>{l.push(w),w.removeCall(this,a)})}return a==null||a.attemptAutoclose("remove-entity",this.id),{added:R(e),updated:R(l),removed:R(p),affected:R(y),self:this}}restore({}={},i=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"restore-entity"))){const a=[],l=[],p=[],e=[];if(i!=null&&i.hasAdded(this.id))return i==null||i.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},i),Object.values(this.detachedDependents).forEach(y=>{const{updated:v,removed:E,added:w}=y.entity.onDetachedDependencyRestored(this,y.field,i);l.push(...v),p.push(...E),a.push(...w)}),this.process){const{updated:y}=this.process.restore({},i);l.push(...y)}return 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("restore-entity",this.id),{added:R(a),updated:R(l),removed:R(p),affected:R(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.process?this.process.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}}toJSON(i=new Set){var a,l;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,x:this.x,y:this.y,successCalls:this.successCalls.map(p=>p.toJSON(i)),errorCalls:this.errorCalls.map(p=>p.toJSON(i)),calledBySuccess:this.calledBySuccess.map(p=>p.toReference()),calledByError:this.calledByError.map(p=>p.toReference()),calledByEntry:this.calledByEntry.map(p=>p.toReference()),process:(a=this.process)==null?void 0:a.toJSON(i),declaration:this.declaration.toJSON(i),inputs:this.inputs.map(p=>p.toJSON(i)),outputs:this.outputs.map(p=>p.toJSON(i)),parent:this.parent.toReference(),error:(l=this.error)==null?void 0:l.toJSON(i)})}toJSONClone(i=ke){var l,p,e,y,v,E,w;let a;return(l=i.seenEntityMaps)!=null&&l.has(this.id)?a=i.seenEntityMaps.get(this.id):(a=i.newId||Gr(this,this.project,i.uuidStrategy),i.seenEntityMaps&&i.seenEntityMaps.set(this.id,a)),(p=i.seenEntities)!=null&&p.has(a)||(e=i.seenEntities)!=null&&e.has(this.id)?this.toReference({seenEntityMaps:i.seenEntityMaps}):((y=i.seenEntities)==null||y.add(a),(v=i.seenEntities)==null||v.add(this.id),{id:a,version:N.UUID.uuid(),createdAt:i.timestamp||L().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,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})),process:(E=this.process)==null?void 0:E.toJSONClone({...i,newId:null}),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:(w=this.error)==null?void 0:w.toJSONClone({...i,newId:null}),parent:this.parent.toReference({seenEntityMaps:i.seenEntityMaps})})}toReference(i=ke){var l;let a=this.id;return(l=i.seenEntityMaps)!=null&&l.has(this.id)&&(a=i.seenEntityMaps.get(this.id)),{id:a+"--"+N.UUID.uuid()+"--ref",type:f.GenericReference,entityId:a,version:this.version,entityType:this.type}}toShallowJSON(i=ke){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,x:this.x,y:this.y,process:this.process?this.process.toReference(i):null,inputs:this.inputs.map(p=>p.toReference(i)),outputs:this.outputs.map(p=>p.toReference(i)),declaration:this.declaration.toReference(i),successCalls:this.successCalls.map(p=>p.toReference(i)),errorCalls:this.errorCalls.map(p=>p.toReference(i)),calledBySuccess:this.calledBySuccess.map(p=>p.toReference(i)),calledByError:this.calledByError.map(p=>p.toReference(i)),calledByEntry:this.calledByEntry.map(p=>p.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.process?this.process.toFlatJSON(i):[],...this.error?this.error.toFlatJSON(i):[]])}toGenerationTarget(){const i=this.parent.type===f.Project?void 0:this.parent.id;return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,calledByEntry:this.calledByEntry.map(a=>a.id),calledBySuccess:this.calledBySuccess.map(a=>a.id),calledByError:this.calledByError.map(a=>a.id),declaration:this.declaration.id,parent: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.process?this.process.toFlatGenerationTarget(i):[],...this.error?this.error.toFlatGenerationTarget(i):[]])}clearErrors(){var i,a;return this.errors=[],this.inputs.forEach(l=>l.clearErrors()),this.outputs.forEach(l=>l.clearErrors()),this.successCalls.forEach(l=>l.clearErrors()),this.errorCalls.forEach(l=>l.clearErrors()),(i=this.process)==null||i.clearErrors(),(a=this.error)==null||a.clearErrors(),this}validate(){const i=u5(this);return this.errors=i,{success:!0,error:null,data:this.toJSON()}}getErrors(){return[...this.errors,...this.inputs.flatMap(a=>a.getErrors()),...this.outputs.flatMap(a=>a.getErrors()),...this.error?this.error.getErrors():[],...this.process?this.process.getErrors():[]]}getShallowErrors(){return this.errors}clone(i=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"clone-entity")),a=null,l=null,p=!0){var U,G;let e=Fr(a,this);const y=this.toJSON(),v=l||N.UUID.uuid();y.inputs=[];const E=v.split("-id"),w=E[E.length-1||0]||v;y.id=v,y.version=N.UUID.uuid(),y.createdAt=(i==null?void 0:i.timestamp)||L().toISOString(),y.author=(i==null?void 0:i.author)||"1",y.previousVersion=null,y.deleted=!1;const A=or(y,e);a?A.setParent(a,null):A.setParent(this.parent,null),p&&A.subscribe(),A.initChildren(i),i==null||i.add(A,S.Added);const $=(U=this.inputs)==null?void 0:U.map((K,J)=>K.clone(i,A,w+"-input-map-"+J+"-id",p));A.inputs=$;const V=(G=this.outputs)==null?void 0:G.map((K,J)=>K.clone(i,A,w+"-output-map-"+J+"-id",p));return A.outputs=V,this.error&&(A.error=this.error.clone(i,A,w+"-error-map-id",p)),this.process&&(A.process=this.process.clone(i,A,w+"-process-id",p)),i==null||i.attemptAutoclose("clone-entity",this.id),A}removeUnrecognizedInputs(i=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-unrecognized-inputs"))){const a=[],l=[],p=[],e=[];return this.inputs.forEach(v=>{if(!this.declaration.inputs.find(w=>{var A;return w.id===((A=v.declaration)==null?void 0:A.id)})){const w=v.remove({ignoreUpstream:!1},i);p.push(...w.removed),a.push(...w.updated)}}),this.inputs.filter((v,E)=>{const w=this.inputs.findIndex($=>$.declaration===v.declaration&&$!==v);if(w===-1)return!1;const A=this.inputs[w];return L(A==null?void 0:A.createdAt).isSame(L(v.createdAt))?E>w:!!L(A==null?void 0:A.createdAt).isAfter(v.createdAt)}).forEach(v=>{const E=v.remove({ignoreUpstream:!1},i);p.push(...E.removed),a.push(...E.updated)}),i==null||i.attemptAutoclose("remove-unrecognized-inputs",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(e),self:this}}removeUnrecognizedOutputs(i=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-unrecognized-outputs"))){const a=[],l=[],p=[],e=[];return this.outputs.forEach(v=>{if(!this.declaration.getUniqueReturnDeclarations().find(w=>{var A;return w.id===((A=v.declaration)==null?void 0:A.id)})){const w=v.remove({ignoreUpstream:!1},i);p.push(...w.removed),a.push(...w.updated)}}),this.outputs.filter((v,E)=>{const w=this.outputs.findIndex($=>$.declaration===v.declaration&&$!==v);if(w===-1)return!1;const A=this.outputs[w];return L(A==null?void 0:A.createdAt).isSame(L(v.createdAt))?E>w:!!L(A==null?void 0:A.createdAt).isAfter(v.createdAt)}).forEach(v=>{const E=v.remove({ignoreUpstream:!1},i);p.push(...E.removed),a.push(...E.updated)}),i==null||i.attemptAutoclose("remove-unrecognized-outputs",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(e),self:this}}syncInputs(i=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"sync-missing-fixed-inputs"))){const a=[],l=[],p=[],e=[],y=this.declaration.inputs.filter(A=>!this.inputs.find($=>$.declaration.id===A.id));this.inputs.sort((A,$)=>A.index-$.index),y.forEach(A=>{this.inputs.forEach(U=>{U.index>=A.index&&U.metaSync({index:U.index+1},i)});const $={id:N.UUID.uuid(),version:N.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||L().toISOString(),author:N.sessionAuthor,previousVersion:null,deleted:!1,type:f.InputMap,declaration:A.toJSON(),readsValue:null,defaultValue:null,index:A.index,name:null,codeName:null,description:null,parent:this.toReference()},V=te($,this.project);V.setParent(this,i),V.initChildren(i),i==null||i.add(V,S.Added),V.addSelfToProject(i),l.push(V)}),this.inputs.sort((A,$)=>A.index-$.index);const{updated:v,added:E,removed:w}=this.removeUnrecognizedInputs(i);return a.push(...v),l.push(...E),p.push(...w),i==null||i.attemptAutoclose("sync-missing-fixed-inputs",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(e),self:this}}syncOutputs(i=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"sync-missing-fixed-outputs"))){const a=[],l=[],p=[],e=[],y=[];this.outputs=this.initialData.outputs.reduce(($,V)=>{if(V.type===f.GenericReference){const G=ki(V,this.project);return G?[...$,G]:$}const U=te(V,this.project);return y.push(U.index),U.setParent(this,null),U.initChildren(i),[...$,U]},[]);const v=this.declaration.getUniqueReturnDeclarations().filter($=>!this.outputs.find(V=>V.declaration.id===$.id));this.outputs.sort(($,V)=>$.index-V.index),v.forEach(($,V)=>{this.outputs.forEach(J=>{J.index>=$.index&&J.index++});const U=y.includes($.index)?this.outputs.length-1+V:$.index,G={id:N.UUID.uuid(),version:N.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||L().toISOString(),author:N.sessionAuthor,previousVersion:null,deleted:!1,type:f.OutputMap,declaration:$.toJSON(),defaultValue:null,writesValues:[],index:U,parent:this.toReference()},K=te(G,this.project);K.setParent(this,i),K.initChildren(i),i==null||i.add(K,S.Added),K.addSelfToProject(i)}),this.outputs.sort(($,V)=>$.index-V.index);const{updated:E,added:w,removed:A}=this.removeUnrecognizedOutputs(i);return a.push(...E),l.push(...w),p.push(...A),i==null||i.attemptAutoclose("sync-missing-fixed-outputs",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(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)}};g(Qt,"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}),g(Qt,"type",f.FunctionCall),g(Qt,"USER_MANAGED_PARENT_TYPES",[...Mr,f.Project]),g(Qt,"PARENT_TYPES",[...Qt.USER_MANAGED_PARENT_TYPES]),g(Qt,"MUTABLE_BASE_PROPERTIES",[]),g(Qt,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),g(Qt,"BASE_PROPERTIES",[...Qt.MUTABLE_BASE_PROPERTIES,...Qt.INMUTABLE_BASE_PROPERTIES]),g(Qt,"MUTABLE_META_PROPERTIES",["x","y"]),g(Qt,"INMUTABLE_META_PROPERTIES",[...Qt.INMUTABLE_BASE_PROPERTIES]),g(Qt,"META_PROPERTIES",[...Qt.MUTABLE_META_PROPERTIES,...Qt.INMUTABLE_META_PROPERTIES]),g(Qt,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry"]),g(Qt,"INMUTABLE_UPSTREAM_PROPERTIES",["declaration","parent"]),g(Qt,"UPSTREAM_PROPERTIES",[...Qt.MUTABLE_UPSTREAM_PROPERTIES,...Qt.INMUTABLE_UPSTREAM_PROPERTIES]),g(Qt,"MUTABLE_DOWNSTREAM_PROPERTIES",["successCalls","errorCalls","writesValues","inputs","outputs","error"]),g(Qt,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),g(Qt,"DOWNSTREAM_PROPERTIES",[...Qt.MUTABLE_DOWNSTREAM_PROPERTIES,...Qt.INMUTABLE_DOWNSTREAM_PROPERTIES]),g(Qt,"PROPERTIES",[...Qt.META_PROPERTIES,...Qt.UPSTREAM_PROPERTIES,...Qt.DOWNSTREAM_PROPERTIES]);let Ao=Qt;function Ob(d){return d&&typeof d.then=="function"}function CIe(d){const u=new Qn(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 $Ie(d){const u=new Qn(Object.values(d)[0]),i=Object.keys(d);return u.order=i,u.flatRecord=d,u.orderEntities(),u.order}class Qn{constructor(u){g(this,"order",[]);g(this,"flatRecord",{});g(this,"allBuiltInEntityIds",Xs());g(this,"onGoingVisits",{});u&&(this.flatten(u),this.orderEntities())}flatten(u){const i=new Set(Xs()),a=R(me(u,i,{ignoreBuiltInBaseEntities:!0})),l=new Set;for(const p of a)this.flatRecord[p.id]=p,l.add(p.id);this.order=Array.from(l)}moveEntityAfterDependencies(u){const{upstream:i}=Qd(u,this.flatRecord,{ignoreBuiltInBaseEntities:!0,allBuiltInEntityIds:this.allBuiltInEntityIds});for(const a of Object.keys(i)){const l=this.order.indexOf(a),p=this.order.indexOf(u.id);if(l>p)return this.order.splice(p,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||Me.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}=Qd(this.flatRecord[u],this.flatRecord,{ignoreBuiltInBaseEntities:!0,allBuiltInEntityIds:this.allBuiltInEntityIds}),l={};return Object.entries(this.onGoingVisits[i]||{}).forEach(([p,e])=>{Object.keys(a).includes(p)&&(l[p]=e)}),l}getDownstreamOngoingDependenciesVisits(u,i){const a=Object.keys(this.onGoingVisits[i]||{}),l=new Set(a.flatMap(e=>Object.keys(Qd(this.flatRecord[e],this.flatRecord,{ignoreBuiltInBaseEntities:!0,allBuiltInEntityIds:this.allBuiltInEntityIds}).downstream))),p={};return Array.from(l).forEach(e=>{e===u&&(p[e]=this.onGoingVisits[i][e])}),p}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 p=this.getUpstreamOngoingDependenciesVisits(l,a);Object.keys(p).length&&await this.settlePromises(p,a);const e=u(this.flatRecord[l],this.flatRecord);Ob(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 p=this.getDownstreamOngoingDependenciesVisits(l,a);Object.keys(p).length&&await this.settlePromises(p,a);const e=u(this.flatRecord[l],this.flatRecord);Ob(e)&&(this.onGoingVisits[a][l]=e)}return await this.settlePromises(this.onGoingVisits[a],a),this.onGoingVisits[a]={},this}}function p5(d,u){switch(d.id){case Ee["built-in-base-entity"].BUILT_IN_PERSISTED_ENTITY_ENTITY.id:{const i=d.project.entities.filter(v=>!!v.implements.find(E=>E.id===Ee["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.id)),a=i.find(v=>{const E=v.properties.find($=>$.implements&&$.implements.id===Ee["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.default.id),w=E==null?void 0:E.getDefaultValue();return(w==null?void 0:w.value)===!0});if(!a&&i.length){const E=i[0].properties.find(A=>A.implements&&A.implements.id===Ee["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.default.id),w=E==null?void 0:E.defaultValue;if(w)w.metaSync({value:!0},u);else if(E!=null&&E.dataType){const A={id:N.UUID.uuid(),version:N.UUID.uuid(),createdAt:(u==null?void 0:u.timestamp)||new Date().toISOString(),author:N.sessionAuthor,previousVersion:null,deleted:!1,type:f.LiteralValue,standaloneParent:null,name:Q.EntityTemplate,autogeneration:null,value:!0,valueAsTypeSingle:null,valueAsTypeList:null,parent:E==null?void 0:E.toReference()},$=te(A,d.project);return $.setParent(E,u),$.initChildren(u),u==null||u.add($,S.Added),$.addSelfToProject(u),{newEntities:[$]}}return{newEntities:[]}}else if(a)return{newEntities:[]};const l=d.project.get(Ee["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.id),p=Im(l,"Main database",u);if(p.errors.length>0)return{newEntities:[]};const e=p.properties.find(v=>v.implements&&v.implements.id===Ee["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.default.id),y=e==null?void 0:e.defaultValue;if(y)y.metaSync({value:!0},u);else if(e!=null&&e.dataType){const v={id:N.UUID.uuid(),version:N.UUID.uuid(),createdAt:(u==null?void 0:u.timestamp)||new Date().toISOString(),author:N.sessionAuthor,previousVersion:null,deleted:!1,type:f.LiteralValue,standaloneParent:null,name:Q.EntityTemplate,autogeneration:null,value:!0,valueAsTypeSingle:null,valueAsTypeList:null,parent:e==null?void 0:e.toReference()},E=te(v,d.project);E.setParent(e,u),E.initChildren(u),u==null||u.add(E,S.Added),E.addSelfToProject(u)}return{newEntities:[p]}}}return{newEntities:[]}}function f5(d,u){const i=[],a=[],l=[],p=[];return d.implements.filter(y=>y.type===f.BuiltInBaseEntity).forEach(y=>{var v;switch(y.id){case Ee["built-in-base-entity"].BUILT_IN_PERSISTED_ENTITY_ENTITY.id:{const E=d.project.entities.filter(V=>V.implements.find(U=>U.id===Ee["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.id));let w=E.find(V=>!!V.properties.find(U=>{var G;return U.implements&&U.implements.id===Ee["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.default.id&&((G=U.getDefaultValue())==null?void 0:G.value)===!0}));if(!w&&E.length)w=E[0];else if(!w&&!E.length){w=d.project.getBuiltIn(Ee["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.id).implement("Relational database",u);const U=w.properties.find(G=>{var K;return((K=G.implements)==null?void 0:K.id)===Ee["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.default.id});(v=U==null?void 0:U.defaultValue)==null||v.metaSync({value:!0},u),a.push(w)}const A=d.properties.find(V=>V.implements&&V.implements.id===Ee["built-in-base-entity"].BUILT_IN_PERSISTED_ENTITY_ENTITY.properties.database.id),$=A==null?void 0:A.defaultValue;if(A&&!$){const V={id:N.UUID.uuid(),version:N.UUID.uuid(),createdAt:(u==null?void 0:u.timestamp)||new Date().toISOString(),author:N.sessionAuthor,previousVersion:null,deleted:!1,type:f.LiteralValue,standaloneParent:null,name:Q.EntityTemplate,autogeneration:null,value:null,valueAsTypeSingle:(w==null?void 0:w.toJSON())||null,valueAsTypeList:null,parent:A==null?void 0:A.toReference()},U=te(V,d.project);U.hydrateAncestors(),U.setParent(A,u),U.addSelfToProject(u),U.initChildren(u),u==null||u.add(U,S.Added),a.push(U);return}else $&&!$.valueAsTypeSingle&&$.setValueAsTypeSingle(w||null,u);return}}}),{self:d,updated:R(i),added:R(a),removed:R(l),affected:R(p)}}function Im(d,u,i,a){const l=a||N.UUID.uuid(),p=N.UUID.uuid(),e={id:l,version:p,createdAt:(i==null?void 0:i.timestamp)||new Date().toISOString(),author:N.sessionAuthor,previousVersion:null,deleted:!1,name:u,type:f.DefinitionEntity,codeName:null,description:null,static:d.static,abstract:!1,properties:[],methods:[],abstractMethods:[],extends:[],implements:[d.toJSON()],x:0,y:0,parent:d.project.toReference()};p5(d,i);const y=te(e,d.project);return y.hydrateAncestors(),i==null||i.add(y,S.Added),y.addSelfToProject(i),y.addImplementation(d),y.setParent(d.project,i),y.initChildren(i),f5(y,i),y}function Cb(d,u){return u.entities.find(l=>{const p=l.properties,e=p.map(A=>A.name),y=d.every(A=>e.includes(A)),v=e.filter(A=>!d.includes(A)),E=p.every(A=>!v.includes(A.name)||!A.required);return y&&E})||null}function h5(d,u,i,a=mi.OrDataTypeGroup){const l=[],p=[],e=[],y=[],E={id:N.UUID.uuid(),version:N.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||new Date().toISOString(),author:N.sessionAuthor,previousVersion:null,deleted:!1,type:f.DataType,options:null,implementationChooseOne:!1,entity:d.toJSON(),isList:!1,asType:!1,andChildrenGroup:null,orChildrenGroup:null,staticEntities:null,interactiveEntities:null,actionEntities:null,like:!0,inferred:!1,parentRelationType:a,parent:u.toReference()},w=te(E,d.project);return p.push(w),w.setParent(u,i),w.initChildren(i),i==null||i.add(w,S.Added),w.setEntity(d,i),w.addSelfToProject(i),{updated:R(l),added:R(p),removed:R(e),affected:R(y),self:w}}function $b(d,u,i,a,l){var E,w,A,$,V,U,G,K;const p=[],e=[],y=[],v=[];switch(typeof d){case"string":let J=!1;const ie=new Date(d);if(ie instanceof Date&&!isNaN(ie.valueOf())&&(J=!0),J){const X=u.project.getBuiltIn(Ee[f.PrimitiveEntity][Q.Date].id);u.setEntity(X,a);break}else{const X=u.project.getBuiltIn(Ee[f.PrimitiveEntity][Q.String].id);u.setEntity(X,a);break}case"number":u.setEntity(u.project.getBuiltIn(Ee[f.PrimitiveEntity][Q.Number].id),a);break;case"boolean":u.setEntity(u.project.getBuiltIn(Ee[f.PrimitiveEntity][Q.Boolean].id),a);break;case"object":if(d===null){u.setEntity(u.project.getBuiltIn(Ee[f.PrimitiveEntity][Q.Null].id),a);break}else if(Array.isArray(d))if(u.metaSync({isList:!0},a),d.length>0){const X=d.slice(0,5).filter(re=>re!==void 0);if(X.every(re=>typeof re==typeof X[0])&&(typeof X[0]!="object"||X[0]===null))switch(typeof X[0]){case"string":u.setEntity(u.project.getBuiltIn(Ee[f.PrimitiveEntity][Q.String].id),a);break;case"number":u.setEntity(u.project.getBuiltIn(Ee[f.PrimitiveEntity][Q.Number].id),a);break;case"boolean":u.setEntity(u.project.getBuiltIn(Ee[f.PrimitiveEntity][Q.Boolean].id),a);break;case"object":u.setEntity(u.project.getBuiltIn(Ee[f.PrimitiveEntity][Q.Null].id),a);break}else{const re=[];let fe=!1;X.forEach(H=>{var ce,z,oe,we;if(Array.isArray(H)&&(fe=!0),typeof H=="object"&&!Array.isArray(H)&&H!==null){const xe=Am(H,u.project,{...i,id:N.UUID.uuid()},a,l);xe.hasCreated&&re.push((ce=xe.changeSet)==null?void 0:ce.self),p.push(...(z=xe.changeSet)==null?void 0:z.updated),e.push(...(oe=xe.changeSet)==null?void 0:oe.added),y.push(...(we=xe.changeSet)==null?void 0:we.removed)}});const Y=R(re);if(!Y.length&&!fe){X.forEach(H=>{const ce={id:N.UUID.uuid(),version:N.UUID.uuid(),createdAt:(a==null?void 0:a.timestamp)||new Date().toISOString(),author:N.sessionAuthor,previousVersion:null,deleted:!1,type:f.DataType,options:null,implementationChooseOne:!1,entity:null,isList:!1,asType:!1,andChildrenGroup:null,orChildrenGroup:null,staticEntities:!1,interactiveEntities:!0,actionEntities:!1,like:!0,inferred:!1,parentRelationType:mi.OrDataTypeGroup,parent:u.toReference()},z=te(ce,u.project);switch(z.setParent(u,a),z.initChildren(a),a==null||a.add(z,S.Added),z.addSelfToProject(a),typeof H){case"string":z.setEntity(z.project.getBuiltIn(Ee[f.PrimitiveEntity][Q.String].id),a);break;case"number":z.setEntity(z.project.getBuiltIn(Ee[f.PrimitiveEntity][Q.Number].id),a);break;case"boolean":z.setEntity(z.project.getBuiltIn(Ee[f.PrimitiveEntity][Q.Boolean].id),a);break;case"object":z.setEntity(z.project.getBuiltIn(Ee[f.PrimitiveEntity][Q.Null].id),a);break}});break}else Y.length===1&&!fe?u.setEntity(Y[0],a):X.forEach(H=>{if(typeof H=="object"&&!Array.isArray(H)&&H!==null){const ce=Cb(Object.keys(H),u.project);if(ce){const z=h5(ce||Y[0],u,a,mi.OrDataTypeGroup);p.push(...z.updated),e.push(...z.added),y.push(...z.removed)}}else{const ce={id:N.UUID.uuid(),version:N.UUID.uuid(),createdAt:(a==null?void 0:a.timestamp)||new Date().toISOString(),author:N.sessionAuthor,previousVersion:null,deleted:!1,type:f.DataType,options:null,implementationChooseOne:!1,entity:null,isList:Array.isArray(H),asType:!1,andChildrenGroup:null,orChildrenGroup:null,staticEntities:!1,interactiveEntities:!0,actionEntities:!1,like:!0,inferred:!1,parentRelationType:mi.OrDataTypeGroup,parent:u.toReference()},z=te(ce,u.project);z.setParent(u,a),z.initChildren(a),a==null||a.add(z,S.Added),z.addSelfToProject(a);const oe=$b(H,z,{...i,id:N.UUID.uuid()},a,l);p.push(...oe.updated),e.push(...oe.added),y.push(...oe.removed)}})}}else{const X=Am(d[0],u.project,{...i},a,l);u.setEntity((E=X.changeSet)==null?void 0:E.self,a),p.push(...(w=X.changeSet)==null?void 0:w.updated),e.push(...(A=X.changeSet)==null?void 0:A.added),y.push(...($=X.changeSet)==null?void 0:$.removed);break}else{const X=Am(d,u.project,{...i},a,l);u.setEntity((V=X.changeSet)==null?void 0:V.self,a),p.push(...(U=X.changeSet)==null?void 0:U.updated),e.push(...(G=X.changeSet)==null?void 0:G.added),y.push(...(K=X.changeSet)==null?void 0:K.removed);break}}return{updated:R(p),added:R(e),removed:R(y),affected:R(v),self:u}}function Am(d,u,i,a,l){const p=[],e=[],y=[],v=[],E=Object.keys(d),w=Cb(E,u);if(w)return{hasCreated:!1,changeSet:{updated:[],added:[],removed:[],affected:[],self:w}};const A=l?i.name+" of "+l.name:i.name,V={id:i.id||N.UUID.uuid(),version:N.UUID.uuid(),createdAt:(a==null?void 0:a.timestamp)||new Date().toISOString(),author:N.sessionAuthor,previousVersion:null,deleted:!1,name:A,codeName:null,type:f.DefinitionEntity,description:i.description||null,static:i.static||!1,abstract:i.abstract||!1,properties:[],methods:[],abstractMethods:[],extends:[],implements:[],x:0,y:0,parent:u.toReference()},U=te(V,u);return U.setParent(u,a),U.initChildren(a),a==null||a.add(U,S.Added),U.addSelfToProject(a),e.push(U),E.forEach((G,K)=>{const ie={id:N.UUID.uuid(),version:N.UUID.uuid(),createdAt:(a==null?void 0:a.timestamp)||new Date().toISOString(),author:N.sessionAuthor,previousVersion:null,deleted:!1,name:G,type:f.Property,codeName:G,description:null,static:!1,abstract:!1,defaultValue:null,constant:!1,interactive:!0,dataType:null,implements:null,extends:null,index:K,hidden:!1,private:!1,required:!0,parent:U.toReference()},X=te(ie,u);X.setParent(U,a),X.initChildren(a),a==null||a.add(X,S.Added),X.addSelfToProject(a),e.push(X);const ue=d[G],fe={id:N.UUID.uuid(),version:N.UUID.uuid(),createdAt:(a==null?void 0:a.timestamp)||new Date().toISOString(),author:N.sessionAuthor,previousVersion:null,deleted:!1,type:f.DataType,parentRelationType:null,options:null,implementationChooseOne:!1,entity:null,isList:!1,asType:!1,andChildrenGroup:null,orChildrenGroup:null,staticEntities:!1,interactiveEntities:!0,actionEntities:!1,like:!0,inferred:!1,parent:X.toReference()},Y=te(fe,u);Y.setParent(X,a),Y.initChildren(a),a==null||a.add(Y,S.Added),Y.addSelfToProject(a),e.push(Y);const H=$b(ue,Y,{...i,name:G,id:N.UUID.uuid()},a,l||U);p.push(...H.updated),e.push(...H.added),y.push(...H.removed)}),{hasCreated:!0,changeSet:{updated:R(p),added:R(e),removed:R(y),affected:R(v),self:U}}}function ja(d,u,i,a){const l=[];return!d.length||!u.length?{errors:l,overlap:!1}:(d.length>u.length?d.forEach(p=>{const e=u.find(v=>v.name===p.name),y=u.find(v=>{var E,w;return!!p.implements&&((E=v.implements)==null?void 0:E.id)===((w=p.implements)==null?void 0:w.id)});if(e){const v=new lr({id:p.id+"--"+e.id+"--"+a,message:`Entity of type ${p.type} named "${p.name}" with id "${p.id}" overrides a base ${e.type} ${e.name} with id "${e.id}" that has the same name`,issue:null,severity:q.Error,code:a,entity:p,firstRelationship:e});l.push(v)}if(y){const v=new lr({id:p.id+"--"+y.id+"--"+i,message:`Entity of type ${p.type} named "${p.name}" with id "${p.id}" overrides a base ${y.type} ${y.name} with id "${y.id}" that implements the same base descriptor`,issue:null,severity:q.Error,code:i,entity:p,firstRelationship:y});l.push(v)}}):u.forEach(p=>{var v;const e=d.find(E=>E.name===p.name),y=d.find(E=>{var w,A;return!!E.implements&&((w=E.implements)==null?void 0:w.id)===((A=p.implements)==null?void 0:A.id)});if(e){const E=new lr({id:e.id+"--"+p.id+"--"+a,message:`Entity of type ${e.type} named "${e.name}" with id "${e.id}" overrides a base entity ${p.name} with id "${p.id}" that has the same name`,issue:null,severity:q.Error,code:a,entity:e,firstRelationship:p});l.push(E)}if(y){const E=new lr({id:y.id+"--"+p.id+"--"+i,message:`Entity of type ${y.type} named "${y.name}" with id "${y.id}" overrides a base entity ${p.name} with id "${p.id}" that implements the same base ${(v=y==null?void 0:y.implements)==null?void 0:v.type}`,issue:null,severity:q.Error,code:i,entity:y,firstRelationship:p});l.push(E)}}),{errors:l,overlap:!!l.length})}function PIe(d,u){return d.abstract||(d.properties.forEach(a=>{a.abstract||a.metaSync({abstract:!0},u)}),Object.values(d.detachedDependents).forEach(a=>{a.field===nA.Entity&&a.entity.remove({ignoreUpstream:!1},u)}),d.metaSync({abstract:!0},u)),d}function NIe(d,u){return d.abstract&&(d.properties.forEach(a=>{a.abstract&&a.metaSync({abstract:!1},u)}),Object.values(d.detachedDependents).forEach(a=>{(a.field===Um.Implements||a.field===Um.Extends)&&a.entity.onDetachedDependencyRemoved(d,a.field,u)}),d.metaSync({abstract:!1},u)),d}function VIe(d,u){return d.static||(d.properties.forEach(a=>{a.static||a.metaSync({static:!0},u)}),d.metaSync({static:!0},u)),d}function LIe(d,u){return d.static&&d.metaSync({static:!1},u),d}var y5=(d=>(d.StringValueMustNotHaveSpaces="string-value-must-not-have-spaces",d.StringValueMustNotHaveDashes="string-value-must-not-have-dashes",d))(y5||{});function m5(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 lr({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.`,issue:null,severity:q.Error,code:"string-value-must-not-have-spaces",entity:d});i.push(l)}return{errors:i,override:a.replace(/\s/g,"-")}}function v5(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 lr({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.`,issue:null,severity:q.Error,code:"string-value-must-not-have-spaces",entity:d});i.push(l)}if(a.includes("-")){const l=new lr({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.`,issue:null,severity:q.Error,code:"string-value-must-not-have-dashes",entity:d});i.push(l)}return{errors:i,override:a.replace(/\s|-/g,"_")}}function Pb(d,u){var i;if(d.type===f.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} (${ne(d,u)}) = ${a}`}if(d.type===f.DataType){if(d instanceof hs||d.increaseVersion)return`${d.type}: ${d.id} (${nu(d)})`;try{const a=nu(d);return`${d.type}: ${d.id} (${a})`}catch{}}return`${d.type}: ${d.id} (${ne(d,u)})`}function Xd(d,u){const i=bo(d);if(i.length===0)return{list:[],last:null};let a=null;return{list:i.flatMap(p=>{if(p===u)return a=p,[p];const e=Xd(p,u);return e.last&&(a=e.last),[p,...e.list]}),last:a}}function Xp(d){const u=d.calledBy;if(u.length===0)return d.project;const i=u.reduce((a,l)=>{const p=Ki(l,d.project);return!p||p.type===f.Project?a:a.type===f.Project||Xd(p,a).last?p:(Xd(a,p).last,a)},d.project);return i.type===f.FunctionDeclaration&&i.parent.type===f.Loop?i.parent:i}function We(d,u){let i=Xp(d);if(d.type===f.InternalCall)if(d.parent.type===f.VariableInstance){const l=Qs(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===f.ContinueStatement||d.type===f.BreakStatement)&&i.type!==f.Loop){d.remove({ignoreUpstream:!1},u);return}else if(d.type===f.ReturnStatement&&!Mr.includes(i.type)){d.remove({ignoreUpstream:!1},u);return}else if(mt.includes(d.type)){const l=d.usedInternalCalls[0];if(l)if(i=Xp(l),d.type===f.VariableInstance){const p=Qs(i,d.declaration,d.project);!p.compatible&&p.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===f.VariableInstance){const p=Qs(i,d.declaration,d.project);!p.compatible&&p.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(Ar.includes(d.type))return;_t(d).forEach(l=>{let p=Xp(l);if(l.type===f.InternalCall)if(l.parent.type===f.VariableInstance){const e=Qs(p,l.parent.declaration,d.project);!e.compatible&&e.type!=="b-is-global-a-is-not"?l.parent.remove({ignoreUpstream:!1},u):(l.parent.setParent(p,u),l.parent.addSelfToProject(u))}else l.parent.setParent(p,u),l.parent.addSelfToProject(u);else if((l.type===f.ContinueStatement||l.type===f.BreakStatement)&&p.type!==f.Loop){l.remove({ignoreUpstream:!1},u);return}else if(l.type===f.ReturnStatement&&!Mr.includes(p.type)){l.remove({ignoreUpstream:!1},u);return}else if(mt.includes(l.type)){const e=l.usedInternalCalls[0];if(e)if(p=Xp(e),l.type===f.VariableInstance){const y=Qs(p,l.declaration,d.project);!y.compatible&&y.type!=="b-is-global-a-is-not"?l.remove({ignoreUpstream:!1},u):(l.setParent(p,u),l.addSelfToProject(u))}else l.setParent(p,u),l.addSelfToProject(u);else if(l.type===f.VariableInstance){const y=Qs(p,l.declaration,d.project);!y.compatible&&y.type!=="b-is-global-a-is-not"?l.remove({ignoreUpstream:!1},u):(l.setParent(p,u),l.addSelfToProject(u))}else l.setParent(p,u),l.addSelfToProject(u)}else l.setParent(p,u),l.addSelfToProject(u)})}function bm(d,u,i=new Set){const a=wn(d),l=wn(u),p=a.filter(v=>!l.includes(v)),e=a.filter(v=>l.includes(v)),y=p.reduce((v,E)=>i.has(E.id)?v:(i.add(E.id),R([...v,...bm(E,u,i)])),[]);return R([...e,...y])}function _l(d,u){const i=Xd(d,u);return i.last===u&&i.list.length>0&&i.list[0]!==u}function Nb(d,u){return!!Xd(d,u).last}function MIe(d){if(pr.includes(d.type))return d;if([...Ss,f.VariableDeclaration].includes(d.type)){const u=d.parent;return pr.includes(u.type)?u:null}return null}function Vb(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===f.Project)return null}else return null;const a=u.parent;if(a){if(a===d)return d;if(a.type===f.Project)return null}else return null;return Vb(i,a)}function Er(d){if(rh.includes(d.type)){if(d.type===f.FunctionDeclaration){const u=d.parent;if(u.type===f.DefinitionEntity)return Er(u);if(u.type===f.Loop)return u}return d.type===f.DefinitionEntity&&d.parent.type===f.DataType?Er(d.parent):d}else{const u=d.parent;return u?Er(u):null}}function wm(d,u){const i=Qp(d,u);if(!i)return null;if(rh.includes(i.type)){if(i.type===f.FunctionDeclaration){const a=Qp(i.parent,u);if(a){if(a.type===f.DefinitionEntity)return a;if(a.type===f.Loop)return a}}return i}else{const a=i.parent?Qp(i.parent,u):null;return a?wm(a,u):null}}function E5(d){if(!d)return null;if(Ss.includes(d.type))return d;const u=d.parent;return u?E5(u):null}function T5(d){if(!d)return null;if(mr.includes(d.type))return d;const u=d.parent;return u?T5(u):null}function I5(d){if(!d)return null;if(Ks.includes(d.type))return d;const u=d.parent;return u?I5(u):null}function BIe(d){return d.type===f.VariableDeclaration?[d]:mr.includes(d.type)?[...d.inputs,...d.outputs||[]]:Ar.includes(d.type)?d.outputs:So.includes(d.type)||d.type===f.FunctionDeclaration?d.inputs:[]}function UIe(d){const u=wn(d),i=[],a=[];Eg.includes(d.type)&&i.push(...Rm(d));const l=u.filter(p=>{const e=i.includes(p);return e?!1:Ss.includes(p.type)&&!e?(a.push(p),!1):!0});return i.sort((p,e)=>_l(e,p)?-1:0),a.sort((p,e)=>_l(e,p)?-1:0),[...i,...a,...l]}function A5(d){return[...d].sort((u,i)=>_l(i,u)?-1:0)}function jIe(d){const u=A5(d),i=[];return u.forEach(a=>{const l=i[i.length-1];if(l){const p=l[l.length-1];_l(a,p)?i.push([a]):l.push(a)}else i.push([a])}),i}function Pi(d){const u=d.map(i=>Er(i));return R(u)}function Rm(d){return mr.includes(d.type)?[...Pi(d.successCalls),...Pi(d.errorCalls)]:pr.includes(d.type)?Pi(d.calls):[]}function xIe(d,u){return Rm(d).includes(u)}function _m(d){return d.writesValues||[]}function FIe(d,u){return _m(d).includes(u)}function b5(d){var u;return mt.includes((u=d==null?void 0:d.readsValue)==null?void 0:u.type)?d.readsValue:null}function GIe(d){return d.writesValues}function w5(d=[]){return d.map(b5).filter(u=>!!u)}function gm(d=[]){return d.map(u=>u.writesValues).flat().filter(u=>mt.includes(u.type))}function R5(d=[]){return d.map(u=>u.readsValue).filter(u=>!!u&&mt.includes(u.type))}function _5(d){return mt.includes(d.type)?d:null}function g5(d){return d.writesValues.map(_5).filter(u=>!!u)}function D5(d=[]){return d.reduce((u,i)=>i.type===f.OutputMap?[...u,...g5(i)]:u,[])}function _t(d){return d.type===f.Loop?R([...zs(Pi(d.successCalls)),...zs(Pi(d.errorCalls)),...d.body?_t(d.body):[]]):mr.includes(d.type)?R([...zs(Pi(d.successCalls)),...zs(Pi(d.errorCalls))]):pr.includes(d.type)?R(zs(Pi(d.calls))):[]}function SIe(d){return mr.includes(d.type)?[...zs(Pi(d.successCalls)),...zs(Pi(d.errorCalls))]:pr.includes(d.type)?zs(Pi(d.calls)):[]}function O5(d,u=new Set){return d.writesValues.filter(a=>mt.includes(a.type)&&!u.has(a.id)).reduce((a,l)=>u.has(l.id)?a:[...a,...yr(l,u)],[])}function C5(d,u=new Set){var a;return(((a=d.readsValue)==null?void 0:a.writesValues)||[]).filter(l=>mt.includes(l.type)&&!u.has(l.id)).reduce((l,p)=>u.has(p.id)?l:[...l,...yr(p,u)],[])}function yr(d,u=new Set){if(u.has(d.id))return[];if(d.type===f.ReturnStatement)return R5(d.outputs).reduce((a,l)=>[...a,...yr(l,u)],[]);if(d.type===f.FunctionCall||d.type===f.Operation||d.type===f.Condition)return[..._t(d).reduce((p,e)=>{const y=Er(e);return[...p,...yr(y||e,u)]},[]),...w5(d.inputs),...D5(d.outputs)].reduce((p,e)=>[...p,...yr(e,u)],[]);if(So.includes(d.type)){const i=gm(d.inputs),l=_t(d).reduce((p,e)=>{const y=Er(e);return[...p,...yr(y||e,u)]},[]);return i.push(...l),i.reduce((p,e)=>[...p,...yr(e,u)],[])}if(d.type===f.FunctionDeclaration){const i=[...gm(d.inputs)],l=_t(d).reduce((p,e)=>{const y=Er(e);return[...p,...yr(y||e,u)]},[]);return i.push(...l),i.reduce((p,e)=>[...p,...yr(e)],[])}if(mt.includes(d.type)){u.add(d.id);const a=_t(d).reduce((l,p)=>{const e=Er(p);return[...l,...yr(e||p,u)]},[]);return[d,...a,...C5(d,u),...O5(d,u)]}return[]}function vs(d,u=new Set){return u.has(d.id)?[]:(u.add(d.id),[...wn(d).reduce((l,p)=>[...l,p,...vs(p,u)],[])])}function zs(d){return d.reduce((u,i)=>i.type===f.ReturnStatement||i.type===f.ContinueStatement||i.type===f.BreakStatement?[...u,i]:[...u,i,..._t(i)],[])}function $5(d){const u=d.entities||[],i=[...u,...d.functions||[],...d.events||[],...d.projects||[]],a=u.reduce((v,E)=>[...v,...E.properties],[]),l=u.reduce((v,E)=>[...v,...E.methods],[]),p=l.reduce((v,E)=>[...v,...gm(E.inputs),...zs(Pi(E.calls)),...E.returnStatements],[]),e=d.functions.reduce((v,E)=>[...v,...zs(Pi(E.calls)),...E.returnStatements],[]),y=d.events.reduce((v,E)=>[...v,...zs(Pi(E.calls)),...E.returnStatements],[]);return[...i,...a,...l,...p,...e,...y]}function P5(d,u){return u.filter(a=>{if(!a)return!1;switch(a.type){case f.FunctionCall:return a.inputs.find(l=>l.id===d.id)!==void 0||a.outputs.find(l=>l.id===d.id)!==void 0;case f.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 f.Operation:return a.outputs.find(l=>l.id===d.id)!==void 0;case f.VariableDeclaration:return mr.includes(d.type)?aS(d).find(p=>{var e;return((e=p.readsValue)==null?void 0:e.id)===a.id})!==void 0:!1;case f.DefinitionEntity:return a.properties.find(l=>l.id===d.id)!==void 0||a.methods.find(l=>l.id===d.id)!==void 0;case f.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 KIe(d){const u=$5(d.project);return P5(d,u)}function Qp(d,u){return d?typeof d=="string"?u[d]:d.type===f.GenericReference?u[d.entityId]:u[d.id]?u[d.id]:null:null}function N5(d={},u){const i={};return Object.keys(d).forEach(a=>{const l=u.get(a)||a,p=d[a];i[l]=p}),i}function Qd(d,u={},i={}){const a={ignoreBuiltInBaseEntities:!1,allBuiltInEntityIds:[],entityMaps:new Map,...i};if(a.ignoreBuiltInBaseEntities&&(ls.includes(d.type)||(a.allBuiltInEntityIds||[]).includes(d.id)))return{upstream:{},downstream:{}};const l=d,p=d,e=d,y=d,v=d,E=d,w=d,A=d,$=d,V=d,U=d,G=d,K=d,J=[...K.readsValue?[K.readsValue]:[],...K.declaration?[K.declaration]:[],...(G.calledByEntry||[]).flatMap(re=>re),...(G.calledBySuccess||[]).flatMap(re=>re),...(G.calledByError||[]).flatMap(re=>re),...V.parent?[V.parent]:[]];Array.isArray(e.implements)?J.push(...e.implements.flatMap(re=>re)):$.implements&&J.push($.implements),Array.isArray(e.extends)?J.push(...e.extends.flatMap(re=>re)):$.extends&&J.push($.extends),v.valueAsTypeList&&Array.isArray(v.valueAsTypeList)&&J.push(...v.valueAsTypeList.flatMap(re=>re)),v.valueAsTypeSingle&&J.push(v.valueAsTypeSingle),(K.internalCalls||[]).forEach(re=>{const fe=Z(re);if(fe&&u[fe]){const Y=u[fe];[...Y.calledByEntry||[],...Y.calledBySuccess||[],...Y.calledByError||[]].forEach(H=>{const ce=Z(H);ce&&u[ce]&&J.push(u[ce])})}});const ie=[...(l.inputs||[]).flatMap(re=>re),...(U.inputsDeclarations||[]).flatMap(re=>re),...(l.outputs||[]).flatMap(re=>re),...(U.outputsDeclarations||[]).flatMap(re=>re),...(K.internalCalls||[]).flatMap(re=>re),...K.writesValues||[],...G.dataType?[G.dataType]:[],...E.body?[E.body]:[],...G.defaultValue?[G.defaultValue]:[],...(G.successCalls||[]).flatMap(re=>re),...(G.errorCalls||[]).flatMap(re=>re),...(e.properties||[]).flatMap(re=>re),...(e.methods||[]).flatMap(re=>re),...(e.abstractMethods||[]).flatMap(re=>re),...w.error?[w.error]:[],...w.process?[w.process]:[],...V.throws?[V.throws]:[],...(p.andChildrenGroup||[]).flatMap(re=>re),...(p.orChildrenGroup||[]).flatMap(re=>re),...(A.entities||[]).flatMap(re=>re),...(A.functions||[]).flatMap(re=>re),...(A.functionCalls||[]).flatMap(re=>re),...(A.events||[]).flatMap(re=>re),...(A.conditions||[]).flatMap(re=>re),...(A.operations||[]).flatMap(re=>re),...(A.loops||[]).flatMap(re=>re),...(A.variableDeclarations||[]).flatMap(re=>re),...(A.variableInstances||[]).flatMap(re=>re),...(A.searches||[]).flatMap(re=>re),...(A.projects||[]).flatMap(re=>re),...(y.calls||[]).flatMap(re=>re)];d.type===f.DataType&&(p.entity&&u[Z(p.entity)]&&u[Z(p.entity)].parent&&Z(u[Z(p.entity)].parent)===d.id?ie.push(p.entity):p.entity&&J.push(p.entity)),(K.internalCalls||[]).forEach(re=>{const fe=Z(re);if(fe&&u[fe]){const Y=u[fe];[...Y.successCalls||[],...Y.errorCalls||[]].forEach(H=>{const ce=Z(H);ce&&u[ce]&&ie.push(u[ce])})}});const X={},ue={};return J.forEach(re=>{var H;const fe=Z(re);if(fe&&a.ignoreBuiltInBaseEntities&&(ls.includes(re.type)||(a.allBuiltInEntityIds||[]).includes(fe)))return;const Y=re.version;if(fe){const ce=((H=a.entityMaps)==null?void 0:H.get(fe))||fe;X[ce]=Y}}),ie.forEach(re=>{var H;const fe=Z(re);if(fe&&a.ignoreBuiltInBaseEntities&&(ls.includes(re.type)||(a.allBuiltInEntityIds||[]).includes(fe)))return;const Y=re.version;if(fe){const ce=((H=a.entityMaps)==null?void 0:H.get(fe))||fe;ue[ce]=Y}}),{upstream:X,downstream:ue}}function kIe(d,u){const i=[];if(Ss.includes(d.type)){Ls(d).forEach(p=>{const e=wm(p,u);e&&i.push(e)});const l=[...d.inputs||[],...d.outputs||[]].map(p=>{const e=Qp(p,u);return e?lS(e,u):null}).filter(p=>p!==null);i.push(...R(l))}if(mt.includes(d.type)){const a=Dm(d);a&&i.push(a)}return R(i)}function bo(d){const u=[];if(Ss.includes(d.type)){d.calledBy.forEach(l=>{const p=Er(l);p&&u.push(p)});const a=[...d.inputs||[],...d.outputs||[]].map(l=>Dm(l)).filter(l=>l!==null);u.push(...R(a))}if(mt.includes(d.type)){const i=Dm(d);i&&u.push(i)}return R(u)}function Ls(d){return[...d.calledByEntry||[],...d.calledByError||[],...d.calledBySuccess||[]].filter(u=>u.type!==f.GenericReference)}function V5(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.ActionDescriptor)throw new Error("Entity must be an action descriptor to be flattened");return[d,...d.inputs.flatMap(a=>me(a,u,i)),...d.outputs.flatMap(a=>me(a,u,i)),...d.error?me(d.error,u,i):[],...d.parent?me(d.parent,u,i):[]]}function L5(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.ArgumentDeclaration)throw new Error("Entity must be an argument declaration to be flattened");return[d,...d.defaultValue?me(d.defaultValue,u):[],...d.writesValues.flatMap(a=>me(a,u,i)),...d.dataType?me(d.dataType,u,i):[],...d.parent?me(d.parent,u,i):[]]}function M5(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.BreakStatement)throw new Error("Entity must be a break statement to be flattened");return[d,...d.outputs.flatMap(a=>me(a,u,i)),...d.throws?me(d.throws,u,i):[],...(Ls(d)||[]).flatMap(a=>me(a,u,i)),...d.parent?me(d.parent,u,i):[]]}function B5(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.BuiltInBaseEntity)throw new Error("Entity must be a built-in base entity to be flattened");return[d,...(d.properties||[]).flatMap(a=>me(a,u,i)),...(d.methods||[]).flatMap(a=>me(a,u,i)),...(d.abstractMethods||[]).flatMap(a=>me(a,u,i)),...(d.extends||[]).flatMap(a=>me(a,u,i))]}function U5(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.Condition)throw new Error("Entity must be a condition to be flattened");return[d,...(d.inputs||[]).flatMap(a=>me(a,u,i)),...(d.successCalls||[]).flatMap(a=>me(a,u,i)),...(d.errorCalls||[]).flatMap(a=>me(a,u,i)),...(Ls(d)||[]).flatMap(a=>me(a,u,i)),...d.parent?me(d.parent,u,i):[]]}function j5(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.ContinueStatement)throw new Error("Entity must be a continue statement to be flattened");return[d,...d.outputs.flatMap(a=>me(a,u,i)),...d.throws?me(d.throws,u,i):[],...(Ls(d)||[]).flatMap(a=>me(a,u,i)),...d.parent?me(d.parent,u,i):[]]}function x5(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.DefinitionEntity)throw new Error("Entity must be a definition entity to be flattened");return[d,...(d.extends||[]).flatMap(a=>me(a,u,i)),...(d.implements||[]).flatMap(a=>me(a,u,i)),...(d.properties||[]).flatMap(a=>me(a,u,i)),...(d.methods||[]).flatMap(a=>me(a,u,i)),...(d.abstractMethods||[]).flatMap(a=>me(a,u,i)),...d.parent?me(d.parent,u,i):[]]}function F5(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.DataType)throw new Error("Entity must be a data type to be flattened");return[d,...(d.andChildrenGroup||[]).flatMap(a=>me(a,u,i)),...(d.orChildrenGroup||[]).flatMap(a=>me(a,u,i)),...d.entity?me(d.entity,u,i):[],...d.parent?me(d.parent,u,i):[]]}function G5(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.FunctionCall)throw new Error("Entity must be a function call to be flattened");return[d,...(d.inputs||[]).flatMap(a=>me(a,u,i)),...(d.outputs||[]).flatMap(a=>me(a,u,i)),...d.error?me(d.error,u,i):[],...d.process?me(d.process,u,i):[],...(Ls(d)||[]).flatMap(a=>me(a,u,i)),...(d.successCalls||[]).flatMap(a=>me(a,u,i)),...(d.errorCalls||[]).flatMap(a=>me(a,u,i)),...d.parent?me(d.parent,u,i):[]]}function S5(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.FunctionDeclaration)throw new Error("Entity must be a function declaration to be flattened");return[d,...(d.inputs||[]).flatMap(a=>me(a,u,i)),...(d.calls||[]).flatMap(a=>me(a,u,i)),...d.implements?me(d.implements,u,i):[],...d.parent?me(d.parent,u,i):[]]}function K5(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.GlobalEvent)throw new Error("Entity must be a global event to be flattened");return[d,...(d.inputs||[]).flatMap(a=>me(a,u,i)),...(d.calls||[]).flatMap(a=>me(a,u,i)),...d.implements?me(d.implements,u,i):[],...d.parent?me(d.parent,u,i):[]]}function k5(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.InputMap)throw new Error("Entity must be an input map to be flattened");return[d,...d.readsValue?me(d.readsValue,u,i):[],...d.declaration?me(d.declaration,u,i):[],...d.defaultValue?me(d.defaultValue,u,i):[],...d.parent?me(d.parent,u,i):[]]}function q5(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.InstalledProject)throw new Error("Entity must be an installed project to be flattened");return[d,...(d.functions||[]).flatMap(a=>me(a,u,i)),...(d.events||[]).flatMap(a=>me(a,u,i)),...d.parent?me(d.parent,u,i):[]]}function J5(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.InternalCall)throw new Error("Entity must be an internal call to be flattened");return[d,...(d.successCalls||[]).flatMap(a=>me(a,u,i)),...(d.errorCalls||[]).flatMap(a=>me(a,u,i)),...(d.inputs||[]).flatMap(a=>me(a,u,i)),...(d.outputs||[]).flatMap(a=>me(a,u,i)),...(Ls(d)||[]).flatMap(a=>me(a,u,i)),...d.error?me(d.error,u,i):[],...d.process?me(d.process,u,i):[],...d.parent?me(d.parent,u,i):[]]}function Z5(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.LiteralValue)throw new Error("Entity must be a literal value to be flattened");return[d,...d.valueAsTypeSingle?me(d.valueAsTypeSingle,u,i):[],...d.valueAsTypeList&&Array.isArray(d.valueAsTypeList)?d.valueAsTypeList.flatMap(a=>me(a,u,i)):[],...d.parent?me(d.parent,u,i):[]]}function H5(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.Loop)throw new Error("Entity must be a loop to be flattened");return[d,...(d.inputs||[]).flatMap(a=>me(a,u,i)),...(d.outputs||[]).flatMap(a=>me(a,u,i)),...(d.successCalls||[]).flatMap(a=>me(a,u,i)),...(d.errorCalls||[]).flatMap(a=>me(a,u,i)),...d.error?me(d.error,u,i):[],...d.process?me(d.process,u,i):[],...d.body?me(d.body,u,i):[],...(Ls(d)||[]).flatMap(a=>me(a,u,i)),...d.parent?me(d.parent,u,i):[]]}function W5(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.Operation)throw new Error("Entity must be an operation to be flattened");return[d,...(d.successCalls||[]).flatMap(a=>me(a,u,i)),...(d.errorCalls||[]).flatMap(a=>me(a,u,i)),...(d.inputs||[]).flatMap(a=>me(a,u,i)),...(d.outputs||[]).flatMap(a=>me(a,u,i)),...d.error?me(d.error,u,i):[],...d.process?me(d.process,u,i):[],...(Ls(d)||[]).flatMap(a=>me(a,u,i)),...d.parent?me(d.parent,u,i):[]]}function Y5(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.OutputMap)throw new Error("Entity must be an output map to be flattened");return[d,...(d.writesValues||[]).flatMap(a=>me(a,u,i)),...d.declaration?me(d.declaration,u,i):[],...d.defaultValue?me(d.defaultValue,u,i):[],...d.parent?me(d.parent,u,i):[]]}function z5(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.PrimitiveEntity)throw new Error("Entity must be a primitive entity to be flattened");return[d,...(d.properties||[]).flatMap(a=>me(a,u,i)),...(d.methods||[]).flatMap(a=>me(a,u,i)),...(d.abstractMethods||[]).flatMap(a=>me(a,u,i))]}function X5(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.Project)throw new Error("Entity must be a project to be flattened");return[d,...(d.entities||[]).flatMap(a=>me(a,u,i)),...(d.functions||[]).flatMap(a=>me(a,u,i)),...(d.events||[]).flatMap(a=>me(a,u,i)),...(d.projects||[]).flatMap(a=>me(a,u,i)),...(d.variableDeclarations||[]).flatMap(a=>me(a,u,i)),...(d.variableInstances||[]).flatMap(a=>me(a,u,i)),...(d.operations||[]).flatMap(a=>me(a,u,i)),...(d.conditions||[]).flatMap(a=>me(a,u,i)),...(d.functionCalls||[]).flatMap(a=>me(a,u,i)),...(d.projects||[]).flatMap(a=>me(a,u,i)),...(d.loops||[]).flatMap(a=>me(a,u,i)),...(d.searches||[]).flatMap(a=>me(a,u,i))]}function Q5(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.Property)throw new Error("Entity must be a property to be flattened");return[d,...d.defaultValue?me(d.defaultValue,u,i):[],...d.dataType?me(d.dataType,u,i):[],...d.parent?me(d.parent,u,i):[]]}function eS(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.ReturnDeclaration)throw new Error("Entity must be a return declaration to be flattened");return[d,...d.readsValue?me(d.readsValue,u,i):[],...d.defaultValue?me(d.defaultValue,u,i):[],...d.dataType?me(d.dataType,u,i):[],...d.parent?me(d.parent,u,i):[]]}function tS(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.ReturnStatement)throw new Error("Entity must be a return statement to be flattened");return[d,...(d.outputs||[]).flatMap(a=>me(a,u,i)),...d.throws?me(d.throws,u,i):[],...(Ls(d)||[]).flatMap(a=>me(a,u,i)),...d.parent?me(d.parent,u,i):[]]}function rS(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.Search)throw new Error("Entity must be a search to be flattened");return[d,...(d.successCalls||[]).flatMap(a=>me(a,u,i)),...(d.errorCalls||[]).flatMap(a=>me(a,u,i)),...(d.inputsDeclarations||[]).flatMap(a=>me(a,u,i)),...(d.inputs||[]).flatMap(a=>me(a,u,i)),...(d.outputsDeclarations||[]).flatMap(a=>me(a,u,i)),...(d.outputs||[]).flatMap(a=>me(a,u,i)),...d.error?me(d.error,u,i):[],...(Ls(d)||[]).flatMap(a=>me(a,u,i)),...d.parent?me(d.parent,u,i):[]]}function iS(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.ValueDescriptor)throw new Error("Entity must be a value descriptor to be flattened");return[d,...d.defaultValue?me(d.defaultValue,u,i):[],...d.dataType?me(d.dataType,u,i):[],...d.parent?me(d.parent,u,i):[]]}function sS(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.VariableDeclaration)throw new Error("Entity must be a variable declaration to be flattened");return[d,...(d.successCalls||[]).flatMap(a=>me(a,u,i)),...(d.errorCalls||[]).flatMap(a=>me(a,u,i)),...(d.inputs||[]).flatMap(a=>me(a,u,i)),...(d.outputs||[]).flatMap(a=>me(a,u,i)),...(d.internalCalls||[]).flatMap(a=>me(a,u,i)),...(d.writesValues||[]).flatMap(a=>me(a,u,i)),...d.readsValue?me(d.readsValue,u,i):[],...d.defaultValue?me(d.defaultValue,u,i):[],...(Ls(d)||[]).flatMap(a=>me(a,u,i)),...d.dataType?me(d.dataType,u,i):[],...d.parent?me(d.parent,u,i):[]]}function nS(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.VariableInstance)throw new Error("Entity must be a variable instance to be flattened");return[d,...(d.successCalls||[]).flatMap(a=>me(a,u,i)),...(d.errorCalls||[]).flatMap(a=>me(a,u,i)),...(d.inputs||[]).flatMap(a=>me(a,u,i)),...(d.outputs||[]).flatMap(a=>me(a,u,i)),...(d.internalCalls||[]).flatMap(a=>me(a,u,i)),...(d.writesValues||[]).flatMap(a=>me(a,u,i)),...d.readsValue?me(d.readsValue,u,i):[],...d.defaultValue?me(d.defaultValue,u,i):[],...(Ls(d)||[]).flatMap(a=>me(a,u,i)),...d.declaration?me(d.declaration,u,i):[],...d.parent?me(d.parent,u,i):[]]}function Xs(){const d=new Set,u=u2.flatMap(i=>me(i,d)).map(i=>i.id);if(!u.includes("http-request-error-return-delaration-id"))throw new Error("Built-in base entities must be included in the list");return u}function me(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(!d)throw new Error("Entity must be defined to be flattened");if(d.type===f.GenericReference)return[];if(i.ignoreBuiltInBaseEntities&&(ls.includes(d.type)||Xs().includes(d.id)))return[];if(u.has(d.id))return[];switch(d.type){case f.FunctionCall:return G5(d,u,i);case f.Operation:return W5(d,u,i);case f.Condition:return U5(d,u,i);case f.Loop:return H5(d,u,i);case f.Search:return rS(d,u,i);case f.GlobalEvent:return K5(d,u,i);case f.ReturnStatement:return tS(d,u,i);case f.ContinueStatement:return j5(d,u,i);case f.BreakStatement:return M5(d,u,i);case f.VariableDeclaration:return sS(d,u,i);case f.DefinitionEntity:return x5(d,u,i);case f.FunctionDeclaration:return S5(d,u,i);case f.Project:return X5(d,u,i);case f.ActionDescriptor:return V5(d,u,i);case f.ArgumentDeclaration:return L5(d,u,i);case f.ReturnDeclaration:return eS(d,u,i);case f.ValueDescriptor:return iS(d,u,i);case f.InputMap:return k5(d,u,i);case f.OutputMap:return Y5(d,u,i);case f.DataType:return F5(d,u,i);case f.InstalledProject:return q5(d,u,i);case f.InternalCall:return J5(d,u,i);case f.LiteralValue:return Z5(d,u,i);case f.Property:return Q5(d,u,i);case f.VariableInstance:return nS(d,u,i);case f.BuiltInBaseEntity:return i.ignoreBuiltInBaseEntities?[]:B5(d,u,i);case f.PrimitiveEntity:return i.ignoreBuiltInBaseEntities?[]:z5(d,u,i)}return[]}function Lb(d){return d.type===f.FunctionCall||d.type===f.InternalCall||[f.Operation,f.Condition,f.Loop].includes(d.type)?d.declaration.inputs:d.type===f.FunctionDeclaration||So.includes(d.type)?d.inputs:d.type===f.Search?d.inputsDeclarations:[]}function qIe(d,u){return u.type===f.Condition?u.inputs.find(i=>i.declaration.id===d.id):u.type===f.FunctionCall||u.type===f.Operation?u.inputs.find(i=>i.declaration.id===d.id):null}function aS(d){return mr.includes(d.type)?d.inputs:[]}function oS(d){var u;return d.type===f.FunctionCall?((u=d.declaration.returnStatements[0])==null?void 0:u.outputs)||[]:[f.Operation,f.Condition,f.Loop].includes(d.type)?d.declaration.outputs:d.type===f.Search?d.outputsDeclarations:Ar.includes(d.type)?d.outputs:[]}function JIe(d,u){return u.type===f.Condition?null:u.type===f.FunctionCall||u.type===f.Operation?u.outputs.find(i=>i.declaration.id===d.id):null}function ZIe(d){return d.type===f.Condition?[]:mr.includes(d.type)?d.outputs:[]}function Dm(d){const u=d.readsValue;return u?Er(u):null}function lS(d,u){const i=d.readsValue;return i?wm(i,u):null}function dS(d){const u=d.internalCalls||[];return R(Pi(R(u.flatMap(i=>[...i.successCalls,...i.errorCalls]))))}function uS(d){const u=d.internalCalls||[];return R(R(u.flatMap(i=>[...i.successCalls,...i.errorCalls])))}function eu(d){const u=_m(d),i=[];return u.forEach(a=>{if(mt.includes(a.type))i.push(a);else if(Ln.includes(a.type)){const l=Er(a.parent);i.push(l)}}),i}function tu(d){const u=_m(d),i=[];return u.forEach(a=>{if(mt.includes(a.type))i.push(a);else if(Ln.includes(a.type)){const l=a.parent;i.push(l)}}),i}function R(d){const u=new Set;return d.filter(i=>!i||u.has(i.id)?!1:(u.add(i.id),!0))}function wn(d,u=!1){const i=[];if(d.type===f.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)||[]),Mr.includes(d.type)&&i.push(...(d==null?void 0:d.detachedChildren)||[]),d.type===f.DefinitionEntity){const a=[...d.suggestedMethods,...d.methods].flatMap(l=>l.collapsed&&u?[]:wn(l));i.push(...a)}if(d.type===f.Condition){const a=d.successCalls.map(p=>Er(p)),l=d.errorCalls.map(p=>Er(p));i.push(...a,...l)}if(So.includes(d.type)){if(d.collapsed&&u)return[];const a=d.inputs.map(p=>eu(p)).flat(),l=d.calls.map(p=>Er(p));i.push(...R(a),...l)}if(mr.includes(d.type)&&d.type!==f.Condition&&d.type!==f.Loop){const a=d==null?void 0:d.outputs.map(e=>eu(e)).flat(),l=d.successCalls.map(e=>Er(e)),p=d.errorCalls.map(e=>Er(e));i.push(...R(a),...l,...p)}if(mt.includes(d.type)){const a=eu(d),l=dS(d);i.push(...a,...l)}if(d.type===f.Loop){const a=d.outputs.map(e=>eu(e)).flat();if(d.body){const e=wn(d.body,u);i.push(...e)}const l=d.errorCalls.map(e=>Er(e)),p=d.successCalls.map(e=>Er(e));i.push(...R(a),...p,...l)}if(d.type===f.FunctionDeclaration){if(d.collapsed&&u)return[];const a=d.inputs.map(p=>eu(p)).flat(),l=d.calls.map(p=>Er(p));i.push(...R(a),...l)}return R(i)}function Om(d,u=!1){const i=[];if(d.type===f.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)||[]),Mr.includes(d.type)&&i.push(...(d==null?void 0:d.detachedChildren)||[]),d.type===f.DefinitionEntity){const a=[...d.suggestedMethods,...d.methods].flatMap(l=>l.collapsed&&u?[]:Om(l));i.push(...a)}if(d.type===f.Condition){const a=d.successCalls,l=d.errorCalls;i.push(...a,...l)}if(So.includes(d.type)){if(d.collapsed&&u)return[];const a=d.inputs.map(p=>tu(p)).flat(),l=d.calls;i.push(...R(a),...l)}if(mr.includes(d.type)&&d.type!==f.Condition&&d.type!==f.Loop){const a=d==null?void 0:d.outputs.map(e=>tu(e)).flat(),l=d.successCalls,p=d.errorCalls;i.push(...R(a),...l,...p)}if(mt.includes(d.type)){const a=tu(d),l=uS(d);i.push(...a,...l)}if(d.type===f.Loop){const a=d.outputs.map(e=>tu(e)).flat();if(d.body){const e=Om(d.body,u);i.push(...e)}const l=d.errorCalls,p=d.successCalls;i.push(...R(a),...p,...l)}if(d.type===f.FunctionDeclaration){if(d.collapsed&&u)return[];const a=d.inputs.map(p=>tu(p)).flat(),l=d.calls;i.push(...R(a),...l)}return R(i)}function Cm(d,u=!1){const i=wn(d,u),a=[...i,...i.reduce((l,p)=>[...l,...Cm(p,u)],[])];return R(a)}function cS(d,u=!1){const i=Om(d,u),a=[...i,...i.reduce((l,p)=>[...l,...cS(p,u)],[])];return R(a)}function pS(d){const u=bo(d),i=[...u,...u.reduce((a,l)=>[...a,...pS(l)],[])];return R(i)}function ef(d){return d.implements.reduce((u,i)=>i.type===f.DefinitionEntity?[...u,f.DefinitionEntity,...ef(i),...tf(i)]:[...u,i.name],[])}function tf(d){return d.extends.reduce((u,i)=>i.type===f.DefinitionEntity?[...u,f.DefinitionEntity,...tf(i),...ef(i)]:[...u,i.name],[])}function Mb(d){return d.extends.reduce((u,i)=>i.type===f.DefinitionEntity?[...u,i,...Mb(i),...Bb(i)]:[...u,i],[])}function Bb(d){return d.implements.reduce((u,i)=>i.type===f.DefinitionEntity?[...u,i,...Bb(i),...Mb(i)]:[...u,i],[])}function ru(d){return[...tf(d),...ef(d)].filter((i,a,l)=>l.indexOf(i)===a)}function Ub(d){return d.implements.length===0&&d.extends.length===0?null:d.implements.find(a=>a.type===f.BuiltInBaseEntity&&a.name===Ue.PERSISTED_ENTITY)?d:[...d.implements,...d.extends].reduce((a,l)=>{if(l.type===f.DefinitionEntity){const p=Ub(l);if(p)return p}return a},null)}function HIe(d){const u=d.extends.find(i=>i.type===f.BuiltInBaseEntity);return u&&u.type===f.BuiltInBaseEntity?u:null}function WIe(d){const u=d.implements.find(i=>i.type===f.BuiltInBaseEntity);return u&&u.type===f.BuiltInBaseEntity?u:null}function $m(d){const u=d.extends.find(i=>i.type===f.DefinitionEntity);return u&&u.type===f.DefinitionEntity?u:null}function Ni(d){if(d.type===f.BuiltInBaseEntity)return[d];const u=[...d.implements,...d.extends].reduce((i,a)=>a.type===f.BuiltInBaseEntity?[...i,a]:a.type===f.DefinitionEntity?[...i,...Ni(a)]:i,[]);return R(u)}function rf(d){return d.type===f.PrimitiveEntity?!0:d.type===f.BuiltInBaseEntity?d.interactive:!Ni(d).find(a=>!a.interactive)}function YIe(d){return d.parent===d.project&&d.project.variableDeclarations.includes(d)}function jb(d){return d.parent!==d.project?!1:f.VariableDeclaration===d.type?d.project.variableDeclarations.includes(d):f.VariableInstance===d.type?d.project.variableInstances.includes(d):f.FunctionCall===d.type?d.project.functionCalls.includes(d):f.Condition===d.type?d.project.conditions.includes(d):f.Operation===d.type?d.project.operations.includes(d):f.Loop===d.type?d.project.loops.includes(d):f.Search===d.type?d.project.searches.includes(d):!1}function fS(d){if([...pr,f.DefinitionEntity,f.InstalledProject,f.Project].includes(d.type)||jb(d))return!1;const u=bo(d);return u.length===0?!0:u.some(i=>fS(i))}function xb(d){return[...pr,f.DefinitionEntity,f.InstalledProject,f.Project].includes(d.type)||jb(d)?!1:bo(d).length===0}function hS(d,u=0){if(xb(d)){const i=bo(d);return i.length===0?d:i.map(l=>hS(l,u+1)).reduce((l,p)=>l?p&&p.x<l.x?p:l:p,null)}return null}function yS(d){const u=[];if(xb(d))u.push(d);else return[];return bo(d).forEach(a=>{u.push(...yS(a))}),u}function Fb(d){return d.type===f.FunctionDeclaration&&d.parent!==d.project&&!![f.DefinitionEntity,f.Loop,f.InstalledProject].includes(d.parent.type)}function zIe(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 sf(d){switch(d){case f.DefinitionEntity:return ta;case f.FunctionDeclaration:return io;case f.VariableDeclaration:return uo;case f.VariableInstance:return lo;case f.FunctionCall:return Ao;case f.Operation:return so;case f.Condition:return oo;case f.ReturnStatement:return no;case f.Loop:return xi;case f.Search:return co;case f.InputMap:return Yn;case f.OutputMap:return mn;case f.ArgumentDeclaration:return Zn;case f.ReturnDeclaration:return Qi;case f.Property:return ea;case f.InstalledProject:return po;case f.Project:return N;case f.DataType:return hs;case f.GlobalEvent:return ao;case f.InternalCall:return fo;case f.ValueDescriptor:return vn;case f.BuiltInBaseEntity:return ra;case f.PrimitiveEntity:return es;case f.ActionDescriptor:return wt;case f.LiteralValue:return Gi;case f.ContinueStatement:return Ci;case f.BreakStatement:return ho;default:return null}}function Ki(d,u,i=null){const a=d!=null&&d.parent?Z(d==null?void 0:d.parent):null;let l=a?u.get(a):null,p=i||d;if((d==null?void 0:d.id)===(u==null?void 0:u.id))return u;if(d.type===f.ReturnStatement)return Wr(d,u,p);if(d.type===f.FunctionDeclaration&&(l==null?void 0:l.type)===f.Loop)return l;if(pr.includes(d.type))return d;if(d.type===f.Loop)return p.id===d.id?l:d;if(ls.includes(d.type))return null;const e=d.parent;if(!e)return null;if(e.type===f.GenericReference){const y=Z(e);if(!y)return null;const v=u.get(y);return v?Ki(v,u,p):null}else return e===u?u:Ki(e,u,p)}function Wr(d,u,i=null){const a=d!=null&&d.parent?Z(d==null?void 0:d.parent):null;let l=a?u.get(a):null,p=i||d;if(d.type===f.FunctionDeclaration&&(l==null?void 0:l.type)===f.Loop)return Wr(l.parent,u,p);if(pr.includes(d.type))return d;if(ls.includes(d.type))return null;const e=d.parent;if(!e)return null;if(e.type===f.GenericReference){const y=Z(e);if(!y)return null;const v=u.get(y);return v?Wr(v,u,p):null}else return e===u?u:Wr(e,u,p)}function nf(d,u){if(ls.includes(d.type)||u.getBuiltIn(d.id))return null;const i=ki(d.parent,u);return i?i===u?Mr.includes(d.type)?d:null:i.type===f.DefinitionEntity?d:nf(i,u):null}function Pm(d,u,i){if(d===u||u===i||d===i||!d||!u)return!1;const a=Ki(u.parent,i);return a===i?!1:a===d?!0:Pm(a,u,i)}var Nm=(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))(Nm||{});function Qs(d,u,i){const a=Ki(d,i),l=Ki(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!==f.Project)return{compatible:!0,type:"same-both-local",commonAncestorScope:a};if(a===l&&a.type===f.Project)return{compatible:!0,type:"same-both-global",commonAncestorScope:a};if(a.type===f.Project&&l.type!==f.Project)return{compatible:!1,type:"a-is-global-b-is-not",commonAncestorScope:a};if(a.type!==f.Project&&l.type===f.Project)return{compatible:!1,type:"b-is-global-a-is-not",commonAncestorScope:l};if(Pm(a,l,i))return{compatible:!0,type:"b-in-a",commonAncestorScope:a};if(Pm(l,a,i))return{compatible:!0,type:"a-in-b",commonAncestorScope:l};const y=Vb(a,l);return y===i?{compatible:!1,type:"parallel-in-project",commonAncestorScope:y}:y?{compatible:!1,type:"parallel-in-common-parent",commonAncestorScope:Ki(y,i)}:{compatible:!1,type:"parallel-in-project",commonAncestorScope:i}}function mS(d,u,i){const a=Qs(d,u,i);if(!a.compatible||a.type!=="same-both-local")return null;if(d===u)return d;let l=Ki(d.parent,i);if(l){if(l===u)return u;if(l.type===f.Project)return d}else return d;for(;l;){if(l){if(l===u)return u;if(l.type===f.Project)return d}else return d;l=Ki(l.parent,i)}let p=Ki(u.parent,i);if(p){if(p===d)return d;if(p.type===f.Project)return u}else return u;for(;p;){if(p){if(p===d)return d;if(p.type===f.Project)return u}else return u;p=Ki(p.parent,i)}return null}function vS(d){return d.length===0?null:d.length===1?d[0]:d.reduce((i,a)=>{const l=mS(i,a,a.project);return!l||l===a?i:a},d[0])}function ki(d,u){if(!d)return null;let i;return typeof d=="string"?i=d:d.type===f.GenericReference?i=Z(d):i=d.id,i===u.id?u:u.get(i)}function wo(d){if(!d)return null;if(ls.includes(d.type))return d;if(d.type===f.Project)return null;if(d.project.getBuiltIn(d.id))return d;const u=d.parent;return!u||u.type===f.Project?null:wo(u)}function af(d){const u=[];function i(p,e){return u.some(y=>y.blockedByCaller===p&&y.blockedByCalling===e)}function a(p,e){i(p,e)||u.push({blockedByCaller:p,blockedByCalling:e})}const l=nf(d,d.project);return d.calledBySuccess.forEach(p=>{[...p.successCalls||[]].forEach(v=>{Ar.includes(v.type)&&v!==d&&(_t(d).find(A=>A===v)||a(p,v))});let y;if(mr.includes(p.type)&&(y=p),y){const v=af(y);v.reachable||_t(d).find(A=>A===p)||v.blocks.forEach(A=>{a(p,A.blockedByCalling)})}}),d.calledByError.forEach(p=>{[...p.errorCalls||[]].forEach(v=>{Ar.includes(v.type)&&v!==d&&(_t(d).find(A=>A===v)||a(p,v))});let y;if(mr.includes(p.type)&&(y=p),y){const v=af(y);v.reachable||_t(d).find(A=>A===p)||v.blocks.forEach(A=>{a(p,A.blockedByCalling)})}}),d.calledByEntry.forEach(p=>{if([...p.calls||[]].forEach(v=>{Ar.includes(v.type)&&v!==d&&(_t(d).find(A=>A===v)||a(p,v))}),p===l)return;let y;if(p.type===f.FunctionDeclaration){const v=Er(p);if(v.type===f.DefinitionEntity)return;v.type===f.Loop&&(y=v)}if(y){const v=af(y);v.reachable||v.blocks.forEach(E=>{a(p,E.blockedByCalling)})}}),{reachable:u.length===0,entryPoint:l,blocks:u}}function XIe(d){return rh.includes(d.type)?d.type===f.FunctionDeclaration?!Fb(d):!0:!1}function QIe(d){if(f.ActionDescriptor===d.type){if(d.project.operationDeclarations.find(p=>p.id===d.id))return f.Operation;if(d.project.globalEventActionDescriptors.find(p=>p.id===d.id))return f.GlobalEvent;if(d.project.loopDeclarations.find(p=>p.id===d.id))return f.Loop;if(d.project.conditionDeclarations.find(p=>p.id===d.id))return f.Condition}return d.type}function Vm(d,u){return d.type===f.BuiltInBaseEntity?d.name===u:!!tf(d).includes(u)}function eAe(d,u){return d.type===f.BuiltInBaseEntity?d.name===u:!!ef(d).includes(u)}function Es(d,u){return d.type===f.BuiltInBaseEntity?d.name===u:!!ru(d).includes(u)}function tAe(d){const u=[];return d.entities.forEach(i=>{if(Vm(i,Ue.PERSISTED_ENTITY)){u.push(i);return}}),R(u)}function rAe(d){const u=[];return d.entities.forEach(i=>{if(Vm(i,Ue.RELATIONAL_DATABASE)){u.push(i);return}}),R(u)}function iAe(d){return d.type!==f.DefinitionEntity||d.abstract||!Vm(d,Ue.PERSISTED_ENTITY)?null:(d==null?void 0:d.properties.find(i=>{var a;return((a=i.implements)==null?void 0:a.id)===Ee[f.BuiltInBaseEntity][Ue.PERSISTED_ENTITY].properties.primaryKey.id&&!i.abstract}))||null}function ES(d){var a;const u=Ub(d);if(!u)return null;const i=u.properties.find(l=>{var p;return((p=l.implements)==null?void 0:p.id)===Ee[f.BuiltInBaseEntity][Ue.PERSISTED_ENTITY].properties.database.id});return i?(a=i.getDefaultValue())==null?void 0:a.valueAsType:null}function iu(d){if(d.type!==f.DefinitionEntity)return[];if(d.abstract)return[];if(!Es(d,Ue.PERSISTED_ENTITY))return[];const u=[],i=d.properties.filter(a=>{var l;return((l=a.implements)==null?void 0:l.id)!==Ee[f.BuiltInBaseEntity][Ue.PERSISTED_ENTITY].properties.database.id&&!a.abstract});return u.push(...i),u}function sAe(d){var i;if(!d||d.type!==f.DefinitionEntity||!Es(d,Ue.PERSISTED_ENTITY))return null;const u=d.properties.find(a=>{var l;return((l=a.implements)==null?void 0:l.id)===Ee[f.BuiltInBaseEntity][Ue.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(!Ag.includes(u.type)||!d)return u.project||null;let i=u.project;return d.type===f.Project?i=d:((a=u.project)==null?void 0:a.id)!==d.project.id&&(i=d.project),i}function nAe(d){switch(d){case f.Project:return N;case f.InstalledProject:return po;case f.DefinitionEntity:return ta;case f.FunctionDeclaration:return io;case f.GlobalEvent:return ao;case f.VariableInstance:return lo;case f.VariableDeclaration:return uo;case f.InputMap:return Yn;case f.OutputMap:return mn;case f.Condition:return oo;case f.Operation:return so;case f.FunctionCall:return Ao;case f.ReturnDeclaration:return Qi;case f.ArgumentDeclaration:return Zn;case f.PrimitiveEntity:return es;case f.DataType:return hs;case f.Property:return ea;case f.ActionDescriptor:return wt;case f.ReturnStatement:return no;case f.ContinueStatement:return Ci;case f.BreakStatement:return ho;case f.Loop:return xi;case f.Search:return co;case f.ValueDescriptor:return vn;case f.InternalCall:return fo;case f.LiteralValue:return Gi}return null}function aAe(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 Ur(d,u){const i=sf(d.type);return i?!i.MUTABLE_META_PROPERTIES.every(l=>{const p=d[l],e=u[l];return e===void 0||p===e?!0:Array.isArray(p)&&Array.isArray(e)?p.length!==e.length?!1:p.every((y,v)=>y===e[v]):!1}):!1}function Lm(d,u={}){if(d.type===f.Project)return[];if(!d.parent)return[];const i=Z(d.parent);if(!i)return[];const a=u[i];return a?[a.id,...Lm(a,u)]:[]}function oAe(d){const u=[],i=new Set;return[...d.listAdded,...d.listUpdated,...d.listAffected].forEach(a=>{const l=Er(a);!l||i.has(l.id)||(i.add(l.id),u.push(l))}),R(u)}function lAe(d){if(d.type===f.Condition)return null;if(d.type===f.Search)return d.project.getBuiltIn(Ee["value-descriptor"][Ql.SearchErrorOutputDescriptor].id)||null;if(d.type===f.Operation)return d.declaration.error;if(d.type===f.FunctionCall){const i=d.declaration.returnStatements.find(a=>!!a.throws);return(i==null?void 0:i.throws)||null}return null}function TS(d){const u=d.entities.filter(l=>!!l.implements.find(p=>p.id===Ee["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.id)),i=u.find(l=>{const p=l.properties.find(v=>v.implements&&v.implements.id===Ee["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.default.id),e=p==null?void 0:p.getDefaultValue();return(e==null?void 0:e.value)===!0});return i||u[0]||null}function Gb(d,u){const i=Array.from(new Set([...u.getAllBuiltInIds(),...Xs()]));return!!(i.includes(d.id)||!Lm(d,{...u.instances,...u.builtInInstances}).every(p=>!i.includes(p)))}function IS(d){if(!d)return null;if(d.type===f.Project)return d.id;const u=d.parent;return u?IS(u):d.id}function of(d){if(d.declaration&&d.declaration.type===f.Property){if(d.declaration.interactive){if(d.declaration.implements&&!d.declaration.implements.interactive)return!1;if(d.declaration.extends&&!d.declaration.extends.interactive)return!1}else return!1;if(d.declaration.private){const u=Er(d),i=nf(u,d.project);if((i==null?void 0:i.type)===f.FunctionDeclaration&&(i==null?void 0:i.parent.type)===f.DefinitionEntity&&(i==null?void 0:i.parent.id)!==d.declaration.parent.id)return!1}}return!0}function Sb(d){if(d.interactive){if(d.implements&&!d.implements.interactive)return!1;if(d.extends&&!d.extends.interactive)return!1}else return!1;if(d.private){const u=Er(d),i=nf(u,d.project);if((i==null?void 0:i.type)===f.FunctionDeclaration&&(i==null?void 0:i.parent.type)===f.DefinitionEntity&&(i==null?void 0:i.parent.id)!==d.parent.id)return!1}return!0}function dAe(d,u,i){const a=u,l=i,p=!!i,e=[];return a.forEach(y=>{var v;if(p){const E=Qs(l,y,d);if(!E.compatible&&E.type!=="b-is-global-a-is-not")return;e.push(y)}else{if(((v=y.parent)==null?void 0:v.type)!==f.Project)return;e.push(y)}}),R(e)}function jr(d){const u=d.split(/[\s-]+/).filter(p=>p.length>0);if(u.length===0)return"";const i=u[0],a=i[0].toLowerCase()+i.slice(1),l=u.slice(1).map(p=>p[0].toUpperCase()+p.slice(1));return[a,...l].join("")}function su(d){return d.split(/[\s-]+/).filter(i=>i.length>0).map(i=>i[0].toUpperCase()+i.slice(1)).join("")}function AS(d){return(d.match(/[A-Z]{2,}(?=[A-Z][a-z]+[0-9]*|\b)|[A-Z]?[a-z]+[0-9]*|[A-Z]|[0-9]+/g)||[]).join("-")}function Mm(d){return AS(d).toLowerCase()}function nu(d){var i,a,l,p;if(!d)return"Any data type";let u="";if(d.interactiveEntities===!1?u+=` but only definition nodes ${d.asType?"as template ":""}that don't include non-interactive built-in functionality`:d.interactiveEntities===!0&&(u+=` but only definition nodes ${d.asType?"as template ":""}that extend or implement interactive built-in functionality`),d.staticEntities===!1?u?u+=" and that aren't a single global copy instance":u+=` but only definition nodes ${d.asType?"as template ":""}that aren't a single global copy instance`:d.staticEntities===!0&&(u?u+=" and that are a single global copy instance":u+=` but only definition nodes ${d.asType?"as template ":""}that are a single global copy instance`),d.actionEntities===!1?u?u+=" excluding executable/action nodes":u+=` excluding executable/action nodes ${d.asType?"templates ":""}`:d.actionEntities===!0&&(u?u+=" and not executable/action nodes":u+=" but not executable/action nodes"),d.entity&&(u=""),d.asType&&!u&&!((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)&&!((p=d.orChildrenGroup)!=null&&p.length))return e?`List of an any data type${u}`:`Any data type${u}`;let y="",v=!1,E=!1;return(d.andChildrenGroup||[]).forEach(w=>{const A=nu(w),$=gd(A);v&&(y+=" and "),w.isGroup?y+="("+$+")":v?y+=$:y+=A,v=!0,E=!0}),(d.orChildrenGroup||[]).forEach(w=>{const A=nu(w),$=gd(A);v&&(E&&(y+=","),y+=" or "),w.isGroup?y+="("+$+")":v?y+=$:y+=A,v=!0}),e?`List of ${gd(y)}`:y}if(d.entity.type===f.PrimitiveEntity){let e=d.entity.name;switch(d.entity.name){case Q.String:e="Text";break;case Q.KeyValue:e="Data structure";break}return d.isList?`List of ${e}s${u}`:`${e.slice(0,1).toUpperCase()}${e.slice(1)}${u}`}else if(d.entity.type===f.DefinitionEntity){const e=ne(d.entity,d.project);return d.isList?`List of ${e} values${u}`:e.slice(0,1).toUpperCase()+e.slice(1)+u}else if(d.entity.type===f.BuiltInBaseEntity){const e=wS(d.entity);return d.isList?`List of ${e} values${u}`:e.slice(0,1).toUpperCase()+e.slice(1)+u}else if(d.entity.type===f.LiteralValue){if(d.entity.name===Q.Null)return"Empty value";if(d.entity.name===Q.Untyped)return"Untyped value";if(d.entity.name===Q.File)return"File";if(d.entity.name===Q.String)return`"${d.entity.value}" text`;if(d.entity.name===Q.Number)return`Number '${d.entity.value}'`;if(d.entity.name===Q.Boolean)return`${d.entity.value} value`;if(d.entity.name===Q.UUID)return`"${d.entity.value}" unique identifier`;if(d.entity.name===Q.Date)return`"${d.entity.value}" date`}return d.isList?`List of ${ne(d.entity,d.project)} values${u}`:`${ne(d.entity,d.project).slice(0,1).toUpperCase()+ne(d.entity,d.project).slice(1)} value${u}`}function uAe(d){if(!d)return"Any data type";const u=d.getDataType(null);return nu(u)}function Bm(d){switch(d.declaration.id){case _r.Equal:return"is equal to";case _r.NotEqual:return"is not equal to";case _r.MoreThan:return"is greater than";case _r.MoreThanOrEqual:return"is greater than or equal to";case _r.LessThan:return"is less than";case _r.LessThanOrEqual:return"is less than or equal to";case _r.And:return"and";case _r.Or:return"or";case zr.Empty:return"is empty";case zr.NotEmpty:return"is present"}}function bS(d){return d.includes(Ue.HTTP_ENDPOINT)?"HTTP endpoint":d.includes(Ue.PERSISTED_ENTITY)?"Persisted entity":d.includes(Ue.CRON_JOB)?"Scheduled execution":d.includes(Ue.RELATIONAL_DATABASE)?"Relational database":"Entity"}function wS(d){switch(d.name){case Ue.HTTP_ENDPOINT:return"HTTP endpoint";case Ue.PERSISTED_ENTITY:return"Persisted entity";case Ue.CRON_JOB:return"Scheduled execution";case Ue.RELATIONAL_DATABASE:return"Relational database"}return"Entity"}function cAe(d){const u=$m(d);if(!u){const i=ru(d);return i.includes(Ue.HTTP_ENDPOINT)?"HTTP endpoint":i.includes(Ue.PERSISTED_ENTITY)?"Persisted entity":i.includes(Ue.CRON_JOB)?"Scheduled execution":i.includes(Ue.RELATIONAL_DATABASE)?"Relational database":ne(d,d.project)+" entity"}return ne(u,d.project)+" entity"}function RS(d){let u="Find ";return d.outputsDeclarations.forEach((i,a)=>{const l=xy(i,null),p=gd(l&&l.entity?ne(l.entity,d.project):"unstructured data");a===0?u+=`${p} `:a===d.outputsDeclarations.length-1?u+=`and ${p} `:u+=`, ${p} `}),u}function _S(d){switch(d.name){case Q.String:return"Text";case Q.Number:return"Number";case Q.Boolean:return"Boolean";case Q.KeyValue:return"Data structure";case Q.UUID:return"Unique identifier";case Q.Date:return"Date";case Q.EntityTemplate:return"Entity as template";case Q.Enum:return"Enumeration";case Q.File:return"File";case Q.Null:return"Empty";case Q.ActionDescriptor:return"Action descriptor";case Q.Untyped:return"Untyped";default:return d.name}}function gS(d){switch(d.id){case ze.List:return"Loop over list items";case ze.ManualFlow:return"Manual flow control loop";case ze.ObjectKeys:return"Loop over object keys";case ze.ObjectValues:return"Loop over object values";case ze.Counted:return"Loop given number of times";case ze.String:return"Loop over text characters";case Jt.Addition:return"Sum numbers";case Jt.Subtraction:return"Subtract numbers";case Jt.Multiplication:return"Multiply numbers";case Jt.Division:return"Divide numbers";case Jt.Remainder:return"Get remainder of numbers";case Jt.Exponentiation:return"Get exponent of numbers";case Se.AddIndex:return"Add at index position";case Se.DeleteFirst:return"Delete first character";case Se.DeleteLast:return"Delete last character";case Se.DeleteIndex:return"Delete at index position";case Se.Join:return"Join texts";case Se.ReplaceAllMatches:return"Replace all matches";case Se.ReplaceFirst:return"Replace first match";case Se.ReplaceLast:return"Replace last match";case Se.Split:return"Split text";case Se.ReplaceIndex:return"Replace at index position";case Se.ReplaceSingleMatch:return"Replace single match";case Se.GetFirst:return"Get first character";case Se.GetLast:return"Get last character";case Se.GetIndexItem:return"Get at index position";case Se.GetIndexOf:return"Get the index number of the character";case Se.Append:return"Add at the end";case Se.Prepend:return"Add at the start";case sr.Wait:return"Wait";case sr.Parallel:return"Run in parallel";case sr.Sequential:return"Run in sequence";case yi.HttpRequest:return"HTTP request";case cr.CreateNewInstance:return"Create new copy of entity";case Ze.AddIndex:return"Add item at index position";case Ze.DeleteFirst:return"Delete first item";case Ze.DeleteLast:return"Delete last item";case Ze.DeleteIndex:return"Delete item at index position";case Ze.Join:return"Join lists";case Ze.ReplaceFirst:return"Replace first match";case Ze.ReplaceLast:return"Replace last match";case Ze.Split:return"Split list";case Ze.ReplaceIndex:return"Replace at index position";case Ze.GetFirst:return"Get first item";case Ze.GetLast:return"Get last item";case Ze.GetIndexItem:return"Get item at index position";case Ze.Append:return"Add item at the end";case Ze.Prepend:return"Add item at the start";case Ta.PROJECT_PUBLICATION_COMPLETED:return"Project publication completed";default:return(d.name.slice(0,1).toUpperCase()+d.name.slice(1)).replaceAll("-"," ")}}function ne(d,u){var i;if(f.FunctionDeclaration===d.type){const a=d.name;if(Object.values(qi).includes(a))switch(a){case qi.AbortExecution:return"Abort ongoing execution";case qi.DeletePersistedEntity:return"Delete entry from database";case qi.SavePersistedEntity:return"Save entity data to database";default:return Ti(d.type).replaceAll("-"," ")}return a}if(f.BuiltInBaseEntity===d.type)return bS([d.name]);if(Tg.includes(d.type)&&d.type!==f.ActionDescriptor)return d.name;switch(d.type){case f.Search:return RS(d);case f.GlobalEvent:return d.implements?ne(d.implements,u):Ti(d.type).replaceAll("-"," ");case f.Operation:case f.InternalCall:case f.Loop:const a=ki(d.declaration,u);return a||Me.log("Loop without declaration: ",d),ne(a,u);case f.ActionDescriptor:return gS(d);case f.BreakStatement:const l=ki(d.parent,u);return l||Me.log("Break without parent: ",d),`Stop loop ${ne(l,u)}`;case f.ContinueStatement:const p=ki(d.parent,u);return p||Me.log("continue without parent: ",d),`Execute next iteration of ${ne(p,u)}`;case f.FunctionCall:return ki(d.declaration,u).name;case f.Condition:{const y=d;if((i=d.inputs)!=null&&i.length){y.inputs[0]||Me.log("condition without input: ",d);const v=ne(y.inputs[0],y.project);if(y.inputs[1]){const E=y.inputs[1].declaration.name;return`If ${v} ${Bm(y)} ${E}`}return`If ${v} ${Bm(y)}`}else return`If ${Bm(y)}`}case f.ReturnStatement:{const y=ki(d.parent,u);return y?`Output of ${ne(y,u)}`:"Return statement"}case f.InputMap:if(d.declaration){const y=ki(d.declaration,u);return y||(Me.log("Input without declaration: ",d),Me.log("Og declaration: ",d.declaration)),ne(y,u)||""}else return d.name||"";case f.VariableInstance:{const y=ki(d.declaration,u);return y||Me.log("Var without declaration: ",d),ne(y,u)||""}case f.OutputMap:if(d.declaration){const y=ki(d.declaration,u);return(y==null?void 0:y.name)||""}else return"";case f.PrimitiveEntity:case f.LiteralValue:return _S(d);default:return Ti(d.type).replaceAll("-"," ")}}function Kb(d,u){const i=[];d.name||i.push(new ee({id:`${d.id}--${ae.EmptyName}`,message:`Entity with id "${d.id}" and type "${d.type}" has an empty name. Please provide a 'name' string.`,severity:q.Error,code:ae.EmptyName,issue:null}));const a=u.entities.filter(l=>l.name===d.name);return a.length&&i.push(new ee({id:`${d.id}--${ae.NameNotUniqueInScope}`,message:`Entity with id "${d.id}" and type "${d.type}" has a name "${d.name}" that is not unique in the project. Entity with id "${a[0].id}" has the same name.
|
|
397
397
|
Please provide a unique 'name' string.`,severity:q.Error,code:ae.NameNotUniqueInScope,issue:null})),i}function kb(d,u){const i=[];d.name||i.push(new ee({id:`${d.id}--${ae.EmptyName}`,message:`Entity with id "${d.id}" and type "${d.type}" has an empty name. Please provide a 'name' string.`,severity:q.Error,code:ae.EmptyName,issue:null}));const a=d.parent?Z(d.parent):null;let l=u;a&&(l=u.get(a));const p=[];l.type===f.DefinitionEntity?p.push(...l.methods.map(y=>y)):l.type===f.Project?p.push(...l.functions.map(y=>y)):l.type===f.Loop?l.body&&p.push(l.body):l.type===f.InstalledProject&&p.push(...l.functions.map(y=>y));const e=p.filter(y=>y.name===d.name);return e.length&&i.push(new ee({id:`${d.id}--${ae.NameNotUniqueInScope}`,message:`Entity with id "${d.id}" and type "${d.type}" has a name "${d.name}" that is not unique in ${l.type===f.Project?"the globally declared project scope":"its parent entity"}. Entity with id "${e[0].id}" has the same name.
|
|
398
398
|
Please provide a unique 'name' string.`,severity:q.Error,code:ae.NameNotUniqueInScope,issue:null})),i}function qb(d,u){const i=[];d.name||i.push(new ee({id:`${d.id}--${ae.EmptyName}`,message:`Entity with id "${d.id}" and type "${d.type}" has an empty name. Please provide a 'name' string.`,severity:q.Error,code:ae.EmptyName,issue:null}));const a=d.parent&&ki(d.parent,u)||u;if(!a)i.push(new ee({id:`${d.id}--parent-reference--${k.ReferencedEntityNotFound}`,message:`The entity with id '${d.parent}' that isn't yet found in the project. Perhaps it should be created first. Or perhaps the ID is incorrect.`,severity:q.Error,code:k.ReferencedEntityNotFound,issue:null}));else{const p=$A(a).filter(e=>e.name===d.name);p.length&&i.push(new ee({id:`${d.id}--${ae.NameNotUniqueInScope}`,message:`Entity with id "${d.id}" and type "${d.type}" has a name "${d.name}" that is not unique in its scope or higher scopes. Entity with id "${p[0].id}" has the same name.
|
|
399
399
|
Please provide a unique 'name' string.`,severity:q.Error,code:ae.NameNotUniqueInScope,issue:null}))}return i}function Jb(d,u){const i=[];d.name||i.push(new ee({id:`${d.id}--${ae.EmptyName}`,message:`Entity with id "${d.id}" and type "${d.type}" has an empty name. Please provide a 'name' string.`,severity:q.Error,code:ae.EmptyName,issue:null}));const a=Z(d.parent);if(!a)i.push(new ee({id:`${d.id}--parent-reference--${k.InvalidReferenceObjectStructure}`,message:`Reference object at 'parent' property for entity with id "${d.id}" and type "${d.type}" is not a valid reference. A reference needs to be a 'id' string of an existing entity in the project.`,severity:q.Error,code:k.InvalidReferenceObjectStructure,issue:null}));else{const l=u.get(a);if(!l)i.push(new ee({id:`${d.id}--parent-reference--${k.ReferencedEntityNotFound}`,message:`The entity with id '${a}' that isn't yet found in the project. Perhaps it should be created first. Or perhaps the ID is incorrect.`,severity:q.Error,code:k.ReferencedEntityNotFound,issue:null}));else{const e=l.properties.filter(y=>y.name===d.name);e.length&&i.push(new ee({id:`${d.id}--${ae.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.
|
|
@@ -402,7 +402,7 @@ Please provide a unique 'name' string.`,severity:q.Error,code:ae.NameNotUniqueIn
|
|
|
402
402
|
Please provide a unique 'name' string.`,severity:q.Error,code:ae.NameNotUniqueInScope,issue:null}))}}return i}function pAe(d,u){switch(d.type){case f.DefinitionEntity:return Kb(d,u);case f.FunctionDeclaration:return kb(d,u);case f.VariableDeclaration:return qb(d,u);case f.Property:return Jb(d,u);case f.ArgumentDeclaration:return Zb(d,u);case f.ReturnDeclaration:return Hb(d,u);default:return[]}}function Wb(d,u){switch(d.type){case f.FunctionCall:case f.InternalCall:return ki(d.declaration,u).codeName}if(!Ig.includes(d.type))return null;const i=d;switch(d.type){case f.ActionDescriptor:case f.DefinitionEntity:case f.VariableDeclaration:case f.ValueDescriptor:case f.FunctionDeclaration:return d.codeName||null;case f.ArgumentDeclaration:case f.ReturnDeclaration:{if(d.implements){const a=ki(d.implements,u);return Wb(a,u)||null}return d.codeName||null}case f.InputMap:case f.OutputMap:case f.VariableInstance:{if(d.declaration){const a=ki(d.declaration,u);return Wb(a,u)||""}break}}return i.codeName||null}function DS(d,u,i){const l=`${Mm(d)}-${u}-id`;return i.instances[l]?N.UUID.uuid():l}function Yb(d,u){let i="",a=null;if(d.parent){const p=u.get(d.parent);p&&(a=p)}let l="";return a&&(l=`${Mm(ne(a,u))}-`),i=`${l}${Mm(ne(d,u))}-id`,u.instances[i]?N.UUID.uuid():i}function Gr(d,u,i="uuid"){return i==="semantic"?DS(ne(d,u),d.type,u):N.UUID.uuid()}const fAe=/^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;function OS(d){return typeof d=="string"&&fAe.test(d)}function CS(d){var e;const u=ohe(),i=d.toJSON();u.safeParse(i).success;const l=$S(d);return(e=d.dataType)==null||e.validate(),[...l,...Io(d)]}function $S(d){const u=[];if(!d.implements)return u;const i=d.implements;if(!i.abstract){const l=ft({id:`${d.id}--${le.PropertyImplementsNonAbstact}`,message:`Property "${ne(d,d.project)}" with id "${d.id}" implements a non-abstract property "${ne(i,d.project)}" with id "${i.id}".`,issue:null,severity:q.Error,code:le.PropertyImplementsNonAbstact,entity:d});u.push(l.error)}if(d.static&&!i.static){const l=ft({id:`${d.id}--${le.NonStaticPropertyImplementsStatic}`,message:`Static property "${ne(d,d.project)}" with id "${d.id}" implements a non-static property "${ne(i,d.project)}" with id "${i.id}".`,issue:null,severity:q.Error,code:le.NonStaticPropertyImplementsStatic,entity:d});u.push(l.error)}if(!d.static&&i.static){const l=ft({id:`${d.id}--${le.StaticPropertyImplementsNonStatic}`,message:`Non-static property "${ne(d,d.project)}" with id "${d.id}" implements a static property "${ne(i,d.project)}" with id "${i.id}".`,issue:null,severity:q.Error,code:le.StaticPropertyImplementsNonStatic,entity:d});u.push(l.error)}if(!Ws(d.dataType,i.dataType)){const l=ft({id:`${d.id}--${le.PropertyImplementsIncompatibleType}`,message:`Property "${ne(d,d.project)}" with id "${d.id}" implements a property "${ne(i,d.project)}" with id "${i.id}" that has an incompatible data type.`,issue:null,severity:q.Error,code:le.PropertyImplementsIncompatibleType,entity:d});u.push(l.error)}return vr(d.errors,u)}const hAe=Object.freeze(Object.defineProperty({__proto__:null,validate:CS,validateImplementation:$S},Symbol.toStringTag,{value:"Module"}));function yAe(d,u){const i=[];if(d.parent){const l=u.get(d.parent);if(!l)i.push(new ee({id:`${d.id}--${d.parent}--${k.ReferencedEntityNotFound}`,code:k.ReferencedEntityNotFound,severity:q.Error,message:`Entity of type "${d.type}" with id "${d.id}", is referencing an 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.`,issue:null}));else{const p=wo(l);if(p){const e=l!==p?`The entity of type '${d.type}' with id '${d.id}' have 'parent' with id '${d.parent}' because the entity belongs to a built-in '${p.type}' entity with id '${p.id}' (${ne(p,l.project)}) higher up in the tree.`:`The entity of type '${d.type}' with id '${d.id}' have 'parent' with id '${d.parent}' because it is a built-in entity of type ${p.type}.`;i.push(new ee({id:`${d.id}--${k.InvalidBuiltInEntityReference}`,code:k.InvalidBuiltInEntityReference,severity:q.Error,message:e,issue:null}))}else if(![f.DefinitionEntity].includes(l.type))i.push(new ee({id:`${d.id}--${d.parent}--${k.InvalidParentReference}`,code:k.InvalidParentReference,severity:q.Error,message:`Entity of type "${d.type}" with id "${d.id}", has a parent reference that isn't pointing to an entity of type 'definition-entity'.`,issue:null}));else{const y=Ni(l).filter(v=>!v.interactive);if(y.length){let v=y.length>1?`The entity of type '${d.type}' with id '${d.id}' can't be added to the 'parent' entity with id '${l.id}' because it extends or implements multiple '${f.BuiltInBaseEntity}' entities that are non-interactive ("${at(y.map(E=>ne(E,E.project)),'", "','" and "')}").`:`The entity of type '${d.type}' with id '${d.id}' can't be added to the 'parent' entity with id '${l.id}' because it extends or implements a '${f.BuiltInBaseEntity}' entity that is non-interactive ("${ne(y[0],y[0].project)}").`;v+=`
|
|
403
403
|
${To}`,i.push(new ee({id:`${d.id}--${k.NonInteractiveEntityReferenced}`,code:k.NonInteractiveEntityReferenced,severity:q.Error,message:v,issue:null}))}else if(d.implements){const v=u.get(d.implements);if(d.id===d.implements)return i.push(new ee({id:`${d.id}--${d.implements}--${k.SelfReference}`,code:k.SelfReference,severity:q.Error,message:`Entity of type "${d.type}" with id "${d.id}", has a reference to itself at 'implements'. This is not allowed. Change the reference string or the 'entityId' property of the reference object.`,issue:null})),i;if(!v)i.push(new ee({id:`${d.id}--${d.implements}--${k.ReferencedEntityNotFound}`,code:k.ReferencedEntityNotFound,severity:q.Error,message:`Entity of type "${d.type}" with id "${d.id}", is referencing an entity with id "${d.implements}" that isn't yet found in the project. Perhaps it should be created first. Or perhaps the ID is incorrect.`,issue:null}));else{const E=l.properties.find(w=>{var A;return((A=w.implements)==null?void 0:A.id)===d.implements});E?i.push(new ee({id:`${d.id}--${ae.PropertyOverwritesOtherSiblingWithSameImplementation}`,code:ae.PropertyOverwritesOtherSiblingWithSameImplementation,severity:q.Error,message:`The property with id "${d.id}" is trying to implement the property with id "${d.implements}", but the parent entity already has a property with id '${E.id}' that implements the same base property.`,issue:null})):[f.Property].includes(v.type)?v.abstract||i.push(new ee({id:`${d.id}--${d.implements}--${k.InvalidImplementsReference}`,code:k.InvalidImplementsReference,severity:q.Error,message:`Entity of type "${d.type}" with id "${d.id}", has an 'implements' reference that isn't pointing to an abstract entity.`,issue:null})):i.push(new ee({id:`${d.id}--${d.implements}--${k.InvalidImplementsReference}`,code:k.InvalidImplementsReference,severity:q.Error,message:`Entity of type "${d.type}" with id "${d.id}", has an 'implements' reference that isn't pointing to an entity of type 'property'.`,issue:null}))}}}}}const a=ni(d,{},u);return i.push(...a.errors),i}function PS(d,u){var e;const i=[],a=[],l=[],p=[];if(((e=d.implements)==null?void 0:e.id)===Ee["built-in-base-entity"].BUILT_IN_PERSISTED_ENTITY_ENTITY.properties.database.id){let y=d.defaultValue;if(!d.defaultValue){const v=Gi.new(u);v.name=Q.EntityTemplate,v.parent=d.toReference();const E=te(v,d.project);E.hydrateAncestors(),E.addSelfToProject(u),u==null||u.add(E,S.Added),a.push(E),E.initChildren(u),y=E}if(!y.valueAsTypeSingle){const v=TS(d.project);v&&y.setValueAsTypeSingle(v,u)}}return{updated:R(i),added:R(a),removed:R(l),affected:R(p),self:d}}var NS=(d=>(d.PropertyImplements="property-implements",d.PropertyExtends="property-extends",d.DataTypeEntity="data-type-entity",d))(NS||{});const Ct=class Ct extends Nr{constructor(i,a){super(i);g(this,"initialData");g(this,"id");g(this,"name");g(this,"codeName",null);g(this,"description",null);g(this,"private");g(this,"abstract");g(this,"index");g(this,"static");g(this,"required");g(this,"constant",!1);g(this,"interactive",!1);g(this,"type",f.Property);g(this,"hidden",!1);g(this,"defaultValue",null);g(this,"dataType",null);g(this,"implements",null);g(this,"extends",null);g(this,"project");g(this,"errors",[]);g(this,"parent");g(this,"detachedDependents",{});g(this,"knownVersions",null);g(this,"activeVersion",!1);g(this,"initialized",!1);g(this,"startedInitialization",!1);g(this,"suggestion",!1);g(this,"_codeNativeValueValidation",null);this.initialData=i,this.project=a,this.id=i.id,this.name=i.name,this.description=i.description,this.private=i.private,this.abstract=i.abstract,this.index=i.index,this.static=i.static,this.required=i.required||!1,this.codeName=i.codeName,this.hidden=i.hidden||!1,this.constant=i.constant||!1,this.interactive=i.interactive||!1,this.onProjectInitialized=this.onProjectInitialized.bind(this)}static new(i=null){return{id:N.UUID.uuid(),version:N.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||L().toISOString(),author:(i==null?void 0:i.author)||N.sessionAuthor,previousVersion:null,deleted:!1,type:f.Property,name:"",codeName:null,description:"",dataType:null,implements:null,extends:null,private:!1,abstract:!1,static:!1,constant:!1,interactive:!0,hidden:!1,index:0,required:!1,defaultValue:null,parent:null}}static fromGenerationTarget(i,a){const l=Z(i.parent),p=a.get(l);let e=null;if(i.implements){const w=Z(i.implements);e=a.get(w)}let y=null;if(i.extends){const w=Z(i.extends);y=a.get(w)}const v={id:i.id,version:N.UUID.uuid(),createdAt:L().toISOString(),author:N.sessionAuthor,previousVersion:null,deleted:!1,name:i.name,type:f.Property,index:p.properties.length,private:i.private||!1,abstract:i.abstract||!1,static:i.static||!1,required:i.required||!1,constant:i.constant||!1,interactive:i.interactive||!1,hidden:!1,codeName:i.codeName||null,description:i.description||null,defaultValue:null,implements:e,extends:y,dataType:null,parent:p},E=te(v,a);return E.setParent(p,null),E}static validateGenerationTarget(i,a){let l=JSON.parse(JSON.stringify(i));const p=[],e=yAe(l,a),y=Jb(l,a);return p.push(...e,...y,...Br(l)),{errors:p,modifiedData:l}}get isExtendedProperty(){const i=this.parent.allBasePropertiesFromExtendedAndImplementedEntities.find(a=>{var l;return a.id===((l=this.extends)==null?void 0:l.id)});return!!i&&i.id!==this.id&&!i.abstract}get codeNativeValueValidation(){var i;return this._codeNativeValueValidation||((i=this.implements)==null?void 0:i.codeNativeValueValidation)||null}validateGeneratedUpdate(i){const a=[];return i.parent&&a.push(new ee({id:`${this.id}--${k.InvalidParentUpdate}`,code:k.InvalidParentUpdate,severity:q.Error,message:`Entity of type '${this.type}' with id '${this.id}' cannot have the 'parent' property updated, as it would mean moving the '${this.type}' entity to another parent entity.
|
|
404
404
|
This is likely an incorrect strategy, either the '${this.type}' entity doesn't need to be updated or it should be deleted and a new one created in the desired parent.`,issue:null})),(i.readsValue||i.writesValue)&&a.push(new ee({id:`${this.id}--${ae.InvalidObjectStructure}`,code:ae.InvalidObjectStructure,severity:q.Error,message:`Entity of type '${this.type}' with id '${this.id}' is not a value reading or writing entity.
|
|
405
|
-
${ym}`,issue:null})),{errors:a,modifiedData:i}}onProjectInitialized(i,a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,new Date().toISOString(),this,!0,"on-property-received-project-initialized"))){return PS(this,a),a==null||a.attemptAutoclose("on-property-received-project-initialized",this.id),this}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 F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"sync-dependents"))){const a=[],l=[],p=[],e=[];return Object.values(this.detachedDependents).forEach(y=>{const v=y.entity.afterAllChildrenInitialized(i);a.push(...v.updated),l.push(...v.added),p.push(...v.removed),e.push(...v.affected)}),i==null||i.attemptAutoclose("sync-dependents",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(e),self:this}}onDetachedDependencyRemoved(i,a,l){const p=[],e=[],y=[],v=[];if(a==="property-implements"&&(this.setImplements(null,l),p.push(this)),a==="property-extends"){const{updated:E,added:w,removed:A,affected:$}=this.remove({ignoreUpstream:!1},l);p.push(...E),e.push(...w),y.push(...A),v.push(...$)}return{updated:R(p),added:R(e),removed:R(y),affected:R(v),self:this}}onDetachedDependencyRestored(i,a,l){const p=[],e=[],y=[],v=[];if(a==="property-implements"&&(this.setImplements(i,l),p.push(this)),a==="property-extends"){const{updated:E,added:w,removed:A,affected:$}=this.restore({},l);p.push(...E),e.push(...w),y.push(...A),v.push(...$)}return{updated:R(p),added:R(e),removed:R(y),affected:R(v),self:this}}unsubscribeFromDependencies(){var i,a,l,p,e,y,v;return(a=(i=this.implements)==null?void 0:i.unsubscribeDependents)==null||a.call(i,[{entity:this,field:"property-implements"}]),(p=(l=this.extends)==null?void 0:l.unsubscribeDependents)==null||p.call(l,[{entity:this,field:"property-extends"}]),(v=(y=(e=this.dataType)==null?void 0:e.entity)==null?void 0:y.unsubscribeDependents)==null||v.call(y,[{entity:this,field:"data-type-entity"}]),this.project.off(Vr.PROJECT_INITIALIZED,this.onProjectInitialized),this}subscribeToDependencies(){var i,a,l,p,e,y,v;return(a=(i=this.implements)==null?void 0:i.subscribeDependents)==null||a.call(i,[{entity:this,field:"property-implements"}]),(p=(l=this.extends)==null?void 0:l.subscribeDependents)==null||p.call(l,[{entity:this,field:"property-extends"}]),(v=(y=(e=this.dataType)==null?void 0:e.entity)==null?void 0:y.subscribeDependents)==null||v.call(y,[{entity:this,field:"data-type-entity"}]),this.project.on(Vr.PROJECT_INITIALIZED,this.onProjectInitialized),this}increaseVersion(i){if(i&&!L(i).isValid())throw new Error(`The shared timestamp '${i}' is not a valid ISO 8601 date string.`);return i&&L(i).isSame(L(this.createdAt))?this:(this.previousVersion=this.version,this.version=N.UUID.uuid(),this.createdAt=L(i).toISOString()||L().toISOString(),this)}captureVersion(){var a;const i=((a=this.knownVersions)==null?void 0:a.get(this.version))||new Ct(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.defaultValue=this.defaultValue,i.dataType=this.dataType,i.implements=this.implements,i.extends=this.extends,i.parent=this.parent,this}recursiveCaptureUpstreamVersions(i){const a=[],l=[],p=[],e=[];if(this.parent&&this.parent.type!==f.PrimitiveEntity&&this.parent.type!==f.BuiltInBaseEntity){this.parent.increaseVersion(i);const y=this.parent.recursiveCaptureUpstreamVersions(i);a.push(this.parent,...y.updated),l.push(...y.added),p.push(...y.removed)}return{updated:R(a),added:R(l),removed:R(p),affected:R(e),self:this}}async restoreVersion(i){var v;const a=[],l=[],p=[],e=[];if(this.version===i)return{updated:R(a),added:R(l),removed:R(p),affected:R(e),self:this};if(!this.knownVersions){const E=new Map;for(const[w,A]of this.knownVersions||new Map){if(E.set(w,A),A.activeVersion=!1,A.knownVersions)for(const[$,V]of A.knownVersions)E.set($,V);A.knownVersions=null}}let y=(v=this.knownVersions)==null?void 0:v.get(i);if(!y){const E=await this.APILoadVersion({},i);if(!E)throw new Error(`Version with id '${i}' for entity with id '${this.id}' not found.`);y=new Ct(E,this.project)}return this.metaSync(y.toShallowJSON(),null),this.previousVersion=y.previousVersion,this.version=y.version,this.createdAt=y.createdAt,this.author=y.author,this.deleted=y.deleted,this.defaultValue=y.defaultValue,this.dataType=y.dataType,this.implements=y.implements,this.parent=y.parent,{updated:R(a),added:R(l),removed:R(p),affected:R(e),self:this}}updateWithShallowTransfer(i,a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"update-with-shallow-transfer"))){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=Z(i.parent),p=this.project.get(l),e=this.parent;if(e&&e.id!==(p==null?void 0:p.id)&&this.removeFromParent(a),p)this.setParent(p,null);else throw a==null||a.attemptAutoclose("update-with-shallow-transfer",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("update-with-shallow-transfer",this.id),new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(i.implements){const l=Z(i.implements),p=this.project.get(l);if(p)this.setImplements(p,a);else if(l)throw new Error(`${Ti(this.type)} with id '${this.id}' has a 'implements' reference "${l}" which is missing in the project`)}if(i.extends){const l=Z(i.extends),p=this.project.get(l);if(p)this.setExtends(p,a);else if(l)throw new Error(`${Ti(this.type)} with id '${this.id}' has a 'extends' reference "${l}" which is missing in the project`)}return this.captureVersion(),this.subscribeToDependencies(),a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),this}hydrateAncestors(){const i=[],a=[],l=[],p=[];if(this.initialData.parent){const e=Z(this.initialData.parent),y=this.project.get(e);if(y)this.setParent(y,null);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.implements){const e=Z(this.initialData.implements),y=this.project.get(e);if(y)this.setImplements(y,null),i.push(y);else if(e)throw new Error(`${Ti(this.type)} with id '${this.id}' has a 'implements' reference "${e}" which is missing in the project`)}if(this.initialData.extends){const e=Z(this.initialData.extends),y=this.project.get(e);if(y)this.setExtends(y,null),i.push(y);else if(e)throw new Error(`${Ti(this.type)} with id '${this.id}' has a 'extends' reference "${e}" which is missing in the project`)}return{updated:R(i),added:R(a),removed:R(l),affected:R(p),self:this}}afterAllChildrenInitialized(i=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"after-all-children-initialized"))){const a=[],l=[],p=[],e=[];this.initialized=!0;const{updated:y,added:v,removed:E,affected:w}=this.syncWithImplementation(i);a.push(...y),l.push(...v),p.push(...E),e.push(...w);const{updated:A,added:$,removed:V,affected:U}=PS(this,i);return a.push(...A),l.push(...$),p.push(...V),e.push(...U),this.captureVersion(),i==null||i.attemptAutoclose("after-all-children-initialized",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(e),self:this}}addSelfToProject(i=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-self-to-project"))){const a=[this],l=[],p=[],e=[];return this.parent.addProperty(this),a.push(this.parent),this.subscribe(),this.subscribeToDependencies(),i==null||i.attemptAutoclose("add-self-to-project",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(e),self:this}}setParent(i,a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"set-parent"))){var l;return((l=this.parent)==null?void 0:l.id)!==(i==null?void 0:i.id)&&(this.parent=i,a&&(a==null||a.add(this,S.Updated))),a==null||a.attemptAutoclose("set-parent",this.id),this}setImplements(i,a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"set-implements"))){var l;return((l=this.implements)==null?void 0:l.id)!==(i==null?void 0:i.id)&&(this.implements=i,a&&(a==null||a.add(this,S.Updated))),a==null||a.attemptAutoclose("set-implements",this.id),this}setExtends(i,a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"set-extends"))){var l;return((l=this.extends)==null?void 0:l.id)!==(i==null?void 0:i.id)&&(this.extends=i,a&&(a==null||a.add(this,S.Updated))),a==null||a.attemptAutoclose("set-extends",this.id),this}initChildren(i=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"init-children"))){if(this.initialized||this.startedInitialization)return this;if(this.startedInitialization=!0,this.initialData.defaultValue&&(this.defaultValue=te(this.initialData.defaultValue,this.project),this.defaultValue.setParent(this,null),this.defaultValue.initChildren(i)),this.initialData.dataType){const a=te(this.initialData.dataType,this.project);a.setParent(this,null),a.initChildren(i),this.dataType=a}if(this.initialData.implements){const a=te(this.initialData.implements,this.project);this.setImplements(a,null)}if(this.initialData.extends){const a=te(this.initialData.extends,this.project);this.setExtends(a,null)}return 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 F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"meta-sync"))){const l=Ur(this,i),p=this.toMeta();return this.name=i.name!==void 0?i.name:p.name,this.codeName=i.codeName!==void 0?i.codeName:p.codeName,this.description=i.description!==void 0?i.description:p.description,this.abstract=i.abstract!==void 0?i.abstract:p.abstract,this.private=i.private!==void 0?i.private:p.private,this.index=i.index||(i.index!==0?p.index:0),this.static=i.static!==void 0?i.static:p.static,this.hidden=i.hidden!==void 0?i.hidden:p.hidden,this.constant=i.constant!==void 0?i.constant:p.constant,this.interactive=i.interactive!==void 0?i.interactive:p.interactive,this.required=i.required!==void 0?i.required:p.required,super.metaSync(i),i.deleted===!0&&!p.deleted?a==null||a.add(this,S.Removed):i.deleted===!1&&p.deleted?a==null||a.add(this,S.Added):l&&(a==null||a.add(this,S.Updated)),a==null||a.attemptAutoclose("meta-sync",this.id),this}async APILoad(i=ve,...a){return await Ct.repository.APILoad(this.id,...a),this}async APICreate(i=ve,...a){return await Ct.repository.APICreate(this.toShallowJSON(),...a),this}async APIUpdate(i=ve,...a){return await Ct.repository.APIUpdate(this.toShallowJSON(),...a),this}async APIDelete(i=ve,...a){return await Ct.repository.APIDelete(this.toShallowJSON(),...a),this}async APIClone(i=ve,...a){return await Ct.repository.APIClone(this.id,...a),this}async APILoadVersion(i=ve,a,...l){return await Ct.repository.APILoadVersion(this.id,a,...l)}removeFromParent(i=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-from-parent"))){const a=[],l=[],p=[],e=[];return this.parent.type===f.DefinitionEntity&&(this.parent.removeProperty(this),e.push(this.parent)),i==null||i.attemptAutoclose("remove-from-parent",this.id),{added:R(p),updated:R(a),removed:R(l),affected:R(e),self:this}}remove({ignoreUpstream:i}={ignoreUpstream:!1},a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-entity"))){const l=[],p=[],e=[],y=[];if(a!=null&&a.hasRemoved(this.id))return a==null||a.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(p.push(this),this.unsubscribe(),this.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},a),Object.values(this.detachedDependents).forEach(v=>{const{updated:E,removed:w,added:A}=v.entity.onDetachedDependencyRemoved(this,v.field,a);l.push(...E),p.push(...w),e.push(...A)}),this.defaultValue){const{updated:v,removed:E}=this.defaultValue.remove({ignoreUpstream:!0},a);l.push(...v),p.push(...E)}if(this.dataType){const{updated:v,removed:E}=this.dataType.remove({ignoreUpstream:!0},a);l.push(...v),p.push(...E)}if(!i){const v=this.removeFromParent(a);e.push(...v.added),l.push(...v.updated),p.push(...v.removed),y.push(...v.affected)}return a==null||a.attemptAutoclose("remove-entity",this.id),{added:R(e),updated:R(l),removed:R(p),affected:R(y),self:this}}restore({}={},i=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"restore-entity"))){const a=[],l=[],p=[],e=[];if(i!=null&&i.hasAdded(this.id))return i==null||i.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},i),Object.values(this.detachedDependents).forEach(y=>{const{updated:v,removed:E,added:w}=y.entity.onDetachedDependencyRestored(this,y.field,i);l.push(...v),p.push(...E),a.push(...w)}),this.defaultValue){const{updated:y}=this.defaultValue.restore({},i);l.push(...y)}if(this.dataType){const{updated:y}=this.dataType.restore({},i);l.push(...y)}return this.parent.type===f.DefinitionEntity&&(this.parent.addProperty(this),e.push(this.parent)),i==null||i.attemptAutoclose("restore-entity",this.id),{added:R(a),updated:R(l),removed:R(p),affected:R(e),self:this}}toFlat(i=new Set){var l,p;return i.has(this.id)?[]:(i.add(this.id),[this,...((l=this.defaultValue)==null?void 0:l.toFlat(i))||[],...((p=this.dataType)==null?void 0:p.toFlat(i))||[],...this.parent.toFlat(i)])}toFlatIds(i=new Set){var l,p;return i.has(this.id)?[]:(i.add(this.id),[this.id,...((l=this.defaultValue)==null?void 0:l.toFlatIds(i))||[],...((p=this.dataType)==null?void 0:p.toFlatIds(i))||[],...this.parent.toFlatIds(i)])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,codeName:this.codeName,description:this.description,index:this.index,hidden:this.hidden,private:this.private,abstract:this.abstract,required:this.required,constant:this.constant,interactive:this.interactive,static:this.static,type:this.type,name:this.name}}toJSON(i=new Set){var a,l,p,e;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,name:this.name,codeName:this.codeName,description:this.description,index:this.index,private:this.private,required:this.required,static:this.static,constant:this.constant,interactive:this.interactive,abstract:this.abstract,hidden:this.hidden,defaultValue:((a=this.defaultValue)==null?void 0:a.toJSON(i))||null,dataType:((l=this.dataType)==null?void 0:l.toJSON(i))||null,implements:((p=this.implements)==null?void 0:p.toJSON(i))||null,extends:((e=this.extends)==null?void 0:e.toJSON(i))||null,parent:this.parent.toReference()})}toJSONClone(i=ke){var l,p,e,y,v,E,w;let a;return(l=i.seenEntityMaps)!=null&&l.has(this.id)?a=i.seenEntityMaps.get(this.id):(a=i.newId||Gr(this,this.project,i.uuidStrategy),i.seenEntityMaps&&i.seenEntityMaps.set(this.id,a)),(p=i.seenEntities)!=null&&p.has(a)||(e=i.seenEntities)!=null&&e.has(this.id)?this.toReference({seenEntityMaps:i.seenEntityMaps}):((y=i.seenEntities)==null||y.add(a),(v=i.seenEntities)==null||v.add(this.id),{id:a,version:N.UUID.uuid(),createdAt:i.timestamp||L().toISOString(),author:N.sessionAuthor,previousVersion:null,deleted:!1,type:this.type,name:this.name,codeName:this.codeName,description:this.description,index:this.index,private:this.private,required:this.required,static:this.static,constant:this.constant,interactive:this.interactive,abstract:this.abstract,hidden:this.hidden,defaultValue:((E=this.defaultValue)==null?void 0:E.toJSONClone({...i,newId:null}))||null,dataType:((w=this.dataType)==null?void 0:w.toJSONClone({...i,newId:null}))||null,implements:(()=>{var A;return this.implements&&this.project.getBuiltIn(this.implements.id)?this.implements.toJSON():((A=this.implements)==null?void 0:A.toJSONClone({...i,newId:null}))||null})(),extends:(()=>{var A;return this.extends&&this.project.getBuiltIn(this.extends.id)?this.extends.toJSON():((A=this.extends)==null?void 0:A.toJSONClone({...i,newId:null}))||null})(),parent:this.parent.toReference({seenEntityMaps:i.seenEntityMaps})})}toReference(i=ke){var l;let a=this.id;return(l=i.seenEntityMaps)!=null&&l.has(this.id)&&(a=i.seenEntityMaps.get(this.id)),{id:a+"--"+N.UUID.uuid()+"--ref",type:f.GenericReference,entityId:a,version:this.version,entityType:this.type}}toShallowJSON(i=ke){var l,p,e,y,v;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,name:this.name,codeName:this.codeName,description:this.description,type:this.type,index:this.index,private:this.private,required:this.required,abstract:this.abstract,static:this.static,constant:this.constant,interactive:this.interactive,hidden:this.hidden,defaultValue:((p=this.defaultValue)==null?void 0:p.toReference(i))||null,dataType:((e=this.dataType)==null?void 0:e.toReference(i))||null,implements:((y=this.implements)==null?void 0:y.toReference(i))||null,extends:((v=this.extends)==null?void 0:v.toReference(i))||null,parent:this.parent.toReference(i)}}toFlatJSON(i=new Set){var l,p,e;return i.has(this.id)?[]:(i.add(this.id),[this.toShallowJSON(),...((l=this.defaultValue)==null?void 0:l.toFlatJSON(i))||[],...((p=this.dataType)==null?void 0:p.toFlatJSON(i))||[],...((e=this.implements)==null?void 0:e.toFlatJSON(i))||[],...this.parent.toFlatJSON(i)])}toGenerationTarget(){var i,a;return{id:this.id,name:this.name,description:this.description,type:this.type,private:this.private,required:this.required,abstract:this.abstract,static:this.static,implements:(i=this.implements)==null?void 0:i.id,extends:(a=this.extends)==null?void 0:a.id,parent:this.parent.id}}toFlatGenerationTarget(i=new Set){var l,p;return i.has(this.id)?[]:(i.add(this.id),[this.toGenerationTarget(),...((l=this.defaultValue)==null?void 0:l.toFlatGenerationTarget(i))||[],...((p=this.dataType)==null?void 0:p.toFlatGenerationTarget(i))||[]])}clearErrors(){var i,a;return this.errors=[],(i=this.defaultValue)==null||i.clearErrors(),(a=this.dataType)==null||a.clearErrors(),this}validate(){return this.errors=CS(this),this.errors.length,{success:!0,error:null,data:null}}getErrors(){var a,l;return[...this.errors,...((a=this.defaultValue)==null?void 0:a.getErrors())||[],...((l=this.dataType)==null?void 0:l.getErrors())||[]]}getShallowErrors(){return this.errors}implement(i,a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"implement-self-as-property")),l=null){const p=l||N.UUID.uuid(),e=Ct.new(a);e.id=p,e.name=this.name,e.description=this.description,e.index=this.index,e.private=this.private,e.required=this.required,e.static=this.static,e.constant=this.constant,e.hidden=this.hidden,e.parent=i.toReference(),e.implements=this.toJSON();const y=te(e,this.project);return y.hydrateAncestors(),y.addSelfToProject(a),y.initChildren(a),y}clone(i=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"clone-entity")),a=null,l=null,p=!0){var V,U;let e=Fr(a,this);const y=l||N.UUID.uuid();let v=a||this.parent;const E={hidden:!1,id:y,version:N.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||L().toISOString(),author:(i==null?void 0:i.author)||"1",previousVersion:null,deleted:!1,type:this.type,name:this.name,codeName:this.codeName,description:this.description,index:this.index,private:this.private,constant:this.constant,interactive:this.interactive,required:this.required,abstract:this.abstract,static:this.static,defaultValue:null,dataType:null,implements:this.implements,extends:this.extends,parent:v},w=or(E,e);p&&w.subscribe(),w.hydrateAncestors(),p&&w.addSelfToProject(i),w.setParent(v,null),w.initChildren(i),i==null||i.add(w,S.Added);const A=((V=this.dataType)==null?void 0:V.clone(i,w,N.UUID.uuid(),p))||null;A&&w.setDataType(A,i);const $=(U=this.defaultValue)==null?void 0:U.clone(i,w,N.UUID.uuid(),p);return w.setDefaultValue($||null,i),this.implements&&w.setImplements(this.implements,i),w.addSelfToProject(null),i==null||i.attemptAutoclose("clone-entity",this.id),w}setDataType(i,a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"set-data-type"))){const l=this.dataType;return(l==null?void 0:l.id)!==(i==null?void 0:i.id)&&(l==null||l.remove({ignoreUpstream:!0},a),this.dataType=i,this.subscribeToDependencies(),a==null||a.add(this,S.Affected)),a==null||a.attemptAutoclose("set-data-type",this.id),this}removeDataType(){return this.dataType=null,this}getDataType(i=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"get-data-type"))){return i==null||i.attemptAutoclose("get-data-type",this.id),this.dataType}getDefaultValue(){return this.defaultValue}setDefaultValue(i,a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"set-default-value"))){const l=this.defaultValue;return(l==null?void 0:l.id)!==(i==null?void 0:i.id)&&(l==null||l.remove({ignoreUpstream:!0},a),this.defaultValue=i,a==null||a.add(this,S.Affected)),a==null||a.attemptAutoclose("set-default-value",this.id),this}syncWithImplementation(i=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"sync-with-implementation"))){var y;const a=[],l=[],p=[],e=[];if(this.implements){const v=this.implements;if(!this.dataType&&v.dataType){const E=v.dataType.clone(i,this,N.UUID.uuid(),!0);this.setDataType(E,i),l.push(E)}if(this.implements.defaultValue&&!this.defaultValue){const E=(y=this.implements.defaultValue)==null?void 0:y.clone(i,this,N.UUID.uuid(),!0);this.setDefaultValue(E||null,i),l.push(E)}}return i==null||i.attemptAutoclose("sync-with-implementation",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(e),self:this}}};g(Ct,"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}),g(Ct,"type",f.Property),g(Ct,"USER_MANAGED_PARENT_TYPES",[f.DefinitionEntity]),g(Ct,"PARENT_TYPES",[...Ct.USER_MANAGED_PARENT_TYPES,f.PrimitiveEntity,f.BuiltInBaseEntity]),g(Ct,"MUTABLE_BASE_PROPERTIES",["name","codeName","description","private","abstract","static","required","constant","interactive"]),g(Ct,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),g(Ct,"BASE_PROPERTIES",[...Ct.MUTABLE_BASE_PROPERTIES,...Ct.INMUTABLE_BASE_PROPERTIES]),g(Ct,"MUTABLE_META_PROPERTIES",[...Ct.MUTABLE_BASE_PROPERTIES,"index"]),g(Ct,"INMUTABLE_META_PROPERTIES",[...Ct.INMUTABLE_BASE_PROPERTIES]),g(Ct,"META_PROPERTIES",[...Ct.MUTABLE_META_PROPERTIES,...Ct.INMUTABLE_META_PROPERTIES]),g(Ct,"MUTABLE_UPSTREAM_PROPERTIES",[]),g(Ct,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","implements","extends"]),g(Ct,"UPSTREAM_PROPERTIES",[...Ct.MUTABLE_UPSTREAM_PROPERTIES,...Ct.INMUTABLE_UPSTREAM_PROPERTIES]),g(Ct,"MUTABLE_DOWNSTREAM_PROPERTIES",["dataType"]),g(Ct,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),g(Ct,"DOWNSTREAM_PROPERTIES",[...Ct.MUTABLE_DOWNSTREAM_PROPERTIES,...Ct.INMUTABLE_DOWNSTREAM_PROPERTIES]),g(Ct,"PROPERTIES",[...Ct.META_PROPERTIES,...Ct.UPSTREAM_PROPERTIES,...Ct.DOWNSTREAM_PROPERTIES]);let ea=Ct;function VS(d){const u=xye(),i=d.toJSON();u.safeParse(i).success;const l=d.implements.flatMap(w=>mAe(d,w)),p=d.extends.flatMap(w=>vAe(d,w)),e=TAe(d),y=EAe(d);d.methods.flatMap(w=>w.validate());const v=[...l,...p,...e,...y,...BS(d)];return vr(d.errors,v)}function LS(d,u){const i=u.properties.filter(p=>p.abstract),a=[];let l=[...d.properties];return i.forEach(p=>{const e=l.find(y=>{var v;return((v=y.implements)==null?void 0:v.id)===p.id});e?l=l.filter(y=>y.id!==e.id):a.push(p)}),a}function MS(d,u){const i=u.abstractMethods,a=[];let l=[...d.methods];return i.forEach(p=>{const e=l.find(y=>{var v;return((v=y.implements)==null?void 0:v.id)===p.id});e?l=l.filter(y=>y.id!==e.id):a.push(p)}),a}function mAe(d,u){const i=[];if(!u.abstract){const w=ft({id:d.id+"--"+le.ImplementingNonAbstractEntity,message:`Entity "${d.name}" with id "${d.id}" is implementing a non-abstract entity "${u.name}" with id "${u.id}"`,issue:null,severity:q.Error,code:le.ImplementingNonAbstractEntity,entity:d});return i.push(w.error),i}const a=u.properties.filter(w=>w.abstract),l=[];let p=[...d.properties];a.forEach(w=>{const A=p.find($=>{var V;return((V=$.implements)==null?void 0:V.id)===w.id});A?p=p.filter($=>$.id!==A.id):l.push(w)}),l.length&&l.forEach(w=>{const A=ft({id:d.id+"--"+le.MissingPropertyImplementation+"--"+w.id,message:`Property "${w.name}" with id "${w.id}" of entity "${u.name}" with id "${u.id}" is not implemented when entity "${d.name}" with id "${d.id}" implements it`,issue:null,severity:q.Error,code:le.MissingPropertyImplementation,entity:d});i.push(A.error)});const e=[];let y=[...d.methods];u.abstractMethods.forEach(w=>{const A=y.find($=>{var V;return((V=$.implements)==null?void 0:V.id)===w.id});A?y=y.filter($=>$.id!==A.id):e.push(w)}),e.length&&e.forEach(w=>{const A=ft({id:d.id+"--"+le.MissingMethodImplementation+"--"+w.id,message:`Method "${w.name}" with id "${w.id}" of entity "${u.name}" with id "${u.id}" is not implemented when entity "${d.name}" with id "${d.id}" implements it`,issue:null,severity:q.Error,code:le.MissingMethodImplementation,entity:d});i.push(A.error)});const v=[];u.properties.forEach(w=>{const A=p.find($=>$.name===w.name);A&&v.push([A,w])}),v.length&&v.forEach(([w])=>{const A=ft({id:d.id+"--"+ae.PropertyOverwritesOtherSiblingWithSameName+"--"+w.id,message:`Property "${w.name}" with id "${w.id}" of entity "${d.name}" with id "${d.id}" overwrites the property with the same name from the base entity "${u.name}" with id "${u.id}"`,issue:null,severity:q.Error,code:ae.PropertyOverwritesOtherSiblingWithSameName,entity:d});i.push(A.error)});const E=[];return u.methods.forEach(w=>{const A=y.find($=>$.name===w.name);A&&E.push([A,w])}),E.length&&E.forEach(([w])=>{const A=ft({id:d.id+"--"+ae.MethodOverwritesOtherSiblingWithSameName+"--"+w.id,message:`Method "${w.name}" with id "${w.id}" of entity "${d.name}" with id "${d.id}" overwrites the method with the same name from the base entity "${u.name}" with id "${u.id}"`,issue:null,severity:q.Error,code:ae.MethodOverwritesOtherSiblingWithSameName,entity:d});i.push(A.error)}),i}function vAe(d,u){const i=[],a=[];if(!d.abstract&&u.abstract){const p=ft({id:d.id+"--"+u.id+"--"+le.NonAbstractExtendingAbstractEntity,message:`Entity "${d.name}" with id "${d.id}" is not-abstract but is extending an abstract entity "${u.name}" with id "${u.id}"`,issue:null,severity:q.Error,code:le.NonAbstractExtendingAbstractEntity,entity:d,firstRelationship:u});return i.push(p.error),i}if(d.abstract&&!u.abstract){const p=ft({id:d.id+"--"+u.id+"--"+le.AbstractExtendingNonAbstractEntity,message:`Entity "${d.name}" with id "${d.id}" is abstract but is extending an non-abstract entity "${u.name}" with id "${u.id}"`,issue:null,severity:q.Error,code:le.AbstractExtendingNonAbstractEntity,entity:d,firstRelationship:u});return i.push(p.error),i}d.properties.forEach(p=>{var y;const e=u.properties.find(v=>{var E;return v.name===p.name&&((E=p.extends)==null?void 0:E.id)!==v.id});((y=p.implements)==null?void 0:y.id)!==(e==null?void 0:e.id)&&e&&a.push(p)}),a.length&&a.forEach(p=>{const e=ft({id:d.id+"--"+ae.PropertyOverwritesOtherSiblingWithSameName,message:`Property "${p.name}" with id "${p.id}" of entity "${d.name}" with id "${d.id}" overwrites the property with the same name from the extended entity "${u.name}" with id "${u.id}"`,issue:null,severity:q.Error,code:ae.PropertyOverwritesOtherSiblingWithSameName,entity:d});i.push(e.error)});const l=[];return d.methods.forEach(p=>{var y;const e=u.methods.find(v=>{var E;return v.name===p.name&&((E=p.extends)==null?void 0:E.id)!==v.id});((y=p.implements)==null?void 0:y.id)!==(e==null?void 0:e.id)&&e&&l.push(p)}),l.length&&l.forEach(p=>{const e=ft({id:d.id+"--"+ae.MethodOverwritesOtherSiblingWithSameName,message:`Method "${p.name}" with id "${p.id}" of entity "${d.name}" with id "${d.id}" overwrites the method with the same name from the extended entity "${u.name}" with id "${u.id}"`,issue:null,severity:q.Error,code:ae.MethodOverwritesOtherSiblingWithSameName,entity:d});i.push(e.error)}),i}function EAe(d){const u=[];if(!d.properties.length){const i=ft({id:d.id+"--"+le.NoProperties,message:"No properties implemented",issue:null,severity:q.Warning,code:le.NoProperties,entity:d});u.push(i.error)}return d.properties.forEach(i=>{i.validate()}),u}function TAe(d){const u=[];if(d.abstract){if(d.methods.length){const i=ft({id:d.id+"--"+le.AbstractEntityWithNonAbstractMethods,message:`Entity "${d.name}" with id "${d.id}" is marked as abstract but has non-abstract methods`,issue:null,severity:q.Error,code:le.AbstractEntityWithNonAbstractMethods,entity:d});u.push(i.error)}if(d.properties.some(i=>!i.abstract)){const i=ft({id:d.id+"--"+le.AbstractEntityWithNonAbstractProperties,message:`Entity "${d.name}" with id "${d.id}" is marked as abstract but has non-abstract properties`,issue:null,severity:q.Error,code:le.AbstractEntityWithNonAbstractProperties,entity:d});u.push(i.error),d.properties.forEach(a=>{if(!a.abstract){const l=ft({id:d.id+"--"+le.StaticEntityWithNonStaticProperties+"--"+a.id,message:`Property "${a.name}" with id "${a.id}" of entity "${d.name}" with id "${d.id}" is not marked as abstract but the entity is marked as abstract`,issue:null,severity:q.Error,code:le.StaticEntityWithNonStaticProperties,entity:d});u.push(l.error)}})}}else{if(d.abstractMethods.length){const i=ft({id:d.id+"--"+le.AbstractPropertyInNonAbstractEntity,message:`Entity "${d.name}" with id "${d.id}" is not marked as abstract but has abstract methods`,issue:null,severity:q.Error,code:le.AbstractPropertyInNonAbstractEntity,entity:d});u.push(i.error)}d.properties.some(i=>i.abstract)&&d.properties.forEach(i=>{if(i.abstract){const a=ft({id:d.id+"--"+le.AbstractPropertyInNonAbstractEntity+"--"+i.id,message:`Property "${i.name}" with id "${i.id}" of entity "${d.name}" with id "${d.id}" is marked as abstract but the entity is not marked as abstract`,issue:null,severity:q.Error,code:le.AbstractPropertyInNonAbstractEntity,entity:d,firstRelationship:i});u.push(a.error)}})}return d.static&&d.properties.some(i=>!i.static)&&d.properties.forEach(i=>{if(!i.static){const a=ft({id:d.id+"--"+le.NonStaticPropertyInStaticEntity+"--"+i.id,message:`Property "${i.name}" with id "${i.id}" of entity "${d.name}" with id "${d.id}" is not marked as static but the entity is marked as static`,issue:null,severity:q.Error,code:le.NonStaticPropertyInStaticEntity,entity:d,firstRelationship:i});u.push(a.error)}}),u}function IAe(d,u){const i=[],a=Ni(u);if(!u.abstract){const e=new lr({id:d.id+"--"+u.id+"--"+le.ImplementingNonAbstractEntity,message:`Entity "${d.name}" with id "${d.id}" is implementing a non-abstract built-in entity "${u.name}" with id "${u.id}"`,issue:null,severity:q.Error,code:le.ImplementingNonAbstractEntity,entity:d,firstRelationship:u});i.push(e)}const l=d.implements.filter(e=>e.id!==u.id);if(d.abstract){const e=new lr({id:d.id+"--"+u.id+"--"+le.AbstractEntityImplements,message:`Entity "${d.name}" with id "${d.id}" is marked as abstract and cannot implement built-in entity "${u.name}" with id "${u.id}"`,issue:null,severity:q.Error,code:le.AbstractEntityImplements,entity:d,firstRelationship:u});i.push(e)}if(d.static&&!u.static){const e=new lr({id:d.id+"--"+u.id+"--"+le.StaticImplementingNonStaticEntity,message:`Entity "${d.name}" with id "${d.id}" is marked as static and cannot implement non-static built-in entity "${u.name}" with id "${u.id}"`,issue:null,severity:q.Error,code:le.StaticImplementingNonStaticEntity,entity:d,firstRelationship:u});i.push(e)}if(!d.static&&u.static){const e=new lr({id:d.id+"--"+u.id+"--"+le.NonStaticImplementingStaticEntity,message:`Entity "${d.name}" with id "${d.id}" is not marked as static and cannot implement static built-in entity "${u.name}" with id "${u.id}"`,issue:null,severity:q.Error,code:le.NonStaticImplementingStaticEntity,entity:d,firstRelationship:u});i.push(e)}return l.length&&l.forEach(e=>{if(e.type===f.BuiltInBaseEntity){const y=a.filter(v=>v.id!==e.id);y.length&&y.forEach(v=>{if(v.id!==e.id){const E=new lr({id:d.id+"--"+v.id+"--"+e.id+"--"+le.ImplementsIncompatibleEntities,message:`Entity "${d.name}" with id "${d.id}" is implementing built-in entity "${v.name}" with id "${v.id}" but also implements entity "${e.name}" with id "${e.id}" which is incompatible`,issue:null,severity:q.Error,code:le.ImplementsIncompatibleEntities,entity:d,firstRelationship:v,secondRelationship:e});i.push(E)}})}else{Ni(e).forEach(w=>{const A=a.filter($=>$.id!==w.id);A.length&&A.forEach($=>{if($.id!==w.id){const V=new lr({id:d.id+"--"+$.id+"--"+w.id+"--"+le.ImplementsIncompatibleEntities,message:`Entity "${d.name}" with id "${d.id}" is implementing built-in entity "${$.name}" with id "${$.id}" but also implements entity "${w.name}" with id "${w.id}" which is incompatible`,issue:null,severity:q.Error,code:le.ImplementsIncompatibleEntities,entity:d,firstRelationship:$,secondRelationship:w});i.push(V)}})});const v=ja(u.ownDeclaredProperties,e.ownDeclaredProperties,ae.PropertyOverwritesOtherImplementedEntitysPropertyWithSameImplementation,ae.PropertyOverwritesOtherImplementedEntitysPropertyWithSameName);i.push(...v.errors);const E=ja(u.abstractMethods,[...e.abstractMethods,...e.methods],ae.MethodOverwritesOtherImplementedEntitysMethodWithSameImplementation,ae.MethodOverwritesOtherImplementedEntitysMethodWithSameName);i.push(...E.errors)}}),R(d.extends.flatMap(e=>Ni(e))).forEach(e=>{if(!a.find(y=>y.id===e.id)){const y=new lr({id:d.id+"--"+u.id+"--"+e.id+"--"+le.ExtendsIncompatibleEntities,message:`Entity "${d.name}" with id "${d.id}" is implementing built-in entity "${u.name}" with id "${u.id}" but also extends entity "${e.name}" with id "${e.id}" which is incompatible`,issue:null,severity:q.Error,code:le.ExtendsIncompatibleEntities,entity:d,firstRelationship:u,secondRelationship:e});i.push(y)}}),i}function AAe(d,u,i=!1){const a=[],l=Ni(u);if(!d.abstract&&u.abstract){const w=ft({id:d.id+"--"+u.id+"--"+le.NonAbstractExtendingAbstractEntity,message:`Entity "${d.name}" with id "${d.id}" is not-abstract but is extending an abstract entity "${u.name}" with id "${u.id}"`,issue:null,severity:q.Error,code:le.NonAbstractExtendingAbstractEntity,entity:d,firstRelationship:u});a.push(w.error)}if(d.abstract&&!u.abstract){const w=ft({id:d.id+"--"+u.id+"--"+le.AbstractExtendingNonAbstractEntity,message:`Entity "${d.name}" with id "${d.id}" is abstract but is extending an non-abstract entity "${u.name}" with id "${u.id}"`,issue:null,severity:q.Error,code:le.AbstractExtendingNonAbstractEntity,entity:d,firstRelationship:u});a.push(w.error)}if(!d.static&&u.static){const w=ft({id:d.id+"--"+u.id+"--"+le.NonStaticExtendingStaticEntity,message:`Entity "${d.name}" with id "${d.id}" is not static but is extending a static entity "${u.name}" with id "${u.id}"`,issue:null,severity:q.Error,code:le.NonStaticExtendingStaticEntity,entity:d,firstRelationship:u});a.push(w.error)}if(d.static&&!u.static){const w=ft({id:d.id+"--"+u.id+"--"+le.StaticExtendingNonStaticEntity,message:`Entity "${d.name}" with id "${d.id}" is static but is extending an non-static entity "${u.name}" with id "${u.id}"`,issue:null,severity:q.Error,code:le.StaticExtendingNonStaticEntity,entity:d,firstRelationship:u});a.push(w.error)}if(!rf(u)){const w=ft({id:d.id+"--"+u.id+"--"+le.ExtendingNonInteractiveEntity,message:`Entity "${d.name}" with id "${d.id}" is extending an non-interactive entity "${u.name}" with id "${u.id}"`,issue:null,severity:q.Error,code:le.ExtendingNonInteractiveEntity,entity:d,firstRelationship:u});a.push(w.error)}const e=d.extends.filter(w=>w.id!==u.id);e.length&&e.forEach(w=>{if(w.type===f.BuiltInBaseEntity){const A=l.filter($=>$.id!==w.id);A.length&&A.forEach($=>{if($.id!==w.id){const V=ft({id:d.id+"--"+$.id+"--"+w.id+"--"+le.ExtendsIncompatibleEntities,message:`Entity "${d.name}" with id "${d.id}" is extending built-in entity "${$.name}" with id "${$.id}" but also extends entity "${w.name}" with id "${w.id}" which is incompatible`,issue:null,severity:q.Error,code:le.ExtendsIncompatibleEntities,entity:d,firstRelationship:$,secondRelationship:w});a.push(V.error)}})}else{Ni(w).forEach(J=>{const ie=l.filter(X=>X.id!==J.id);ie.length&&ie.forEach(X=>{if(X.id!==J.id){const ue=new lr({id:d.id+"--"+X.id+"--"+J.id+"--"+le.ImplementsIncompatibleEntities,message:`Entity "${d.name}" with id "${d.id}" is extending built-in entity "${X.name}" with id "${X.id}" but also extends or implements entity "${J.name}" with id "${J.id}" which is incompatible`,issue:null,severity:q.Error,code:le.ImplementsIncompatibleEntities,entity:d,firstRelationship:X,secondRelationship:J});a.push(ue)}})});const $=!!Ni(w).find(J=>J.id===u.id);let V=[...w.properties];$&&(V=V.filter(J=>!u.properties.find(ie=>{var X;return ie.id===J.id||ie.name===J.name||ie.id===((X=J.implements)==null?void 0:X.id)})));let U=[...w.methods];$&&(U=U.filter(J=>!u.methods.find(ie=>{var X;return ie.id===J.id||ie.name===J.name||ie.id===((X=J.implements)==null?void 0:X.id)})));const G=ja(u.ownDeclaredProperties,V,ae.PropertyOverwritesOtherExtendedEntitysPropertyWithSameImplementation,ae.PropertyOverwritesOtherExtendedEntitysPropertyWithSameName);a.push(...G.errors);const K=ja(u.abstractMethods,U,ae.MethodOverwritesOtherExtendedEntitysMethodWithSameImplementation,ae.MethodOverwritesOtherExtendedEntitysMethodWithSameName);a.push(...K.errors)}}),i&&Me.log("self.implements.length",d.implements.length),d.implements.length&&d.implements.forEach(w=>{if(w.type===f.BuiltInBaseEntity){const A=l.filter($=>$.id!==w.id);A.length&&A.forEach($=>{if($.id!==w.id){const V=new lr({id:d.id+"--"+$.id+"--"+w.id+"--"+le.ImplementsIncompatibleEntities,message:`Entity "${d.name}" with id "${d.id}" is implementing built-in entity "${$.name}" with id "${$.id}" but also implements entity "${w.name}" with id "${w.id}" which is incompatible`,issue:null,severity:q.Error,code:le.ImplementsIncompatibleEntities,entity:d,firstRelationship:$,secondRelationship:w});a.push(V)}})}else{Ni(w).forEach(U=>{const G=l.filter(K=>K.id!==U.id);G.length&&G.forEach(K=>{if(K.id!==U.id){const J=new lr({id:d.id+"--"+K.id+"--"+U.id+"--"+le.ImplementsIncompatibleEntities,message:`Entity "${d.name}" with id "${d.id}" is implementing built-in entity "${K.name}" with id "${K.id}" but also implements entity "${U.name}" with id "${U.id}" which is incompatible`,issue:null,severity:q.Error,code:le.ImplementsIncompatibleEntities,entity:d,firstRelationship:K,secondRelationship:U});a.push(J)}})});const $=ja(u.ownDeclaredProperties,w.ownDeclaredProperties,ae.PropertyOverwritesOtherImplementedEntitysPropertyWithSameImplementation,ae.PropertyOverwritesOtherImplementedEntitysPropertyWithSameName);a.push(...$.errors);const V=ja(u.abstractMethods,[...w.abstractMethods,...w.methods],ae.MethodOverwritesOtherImplementedEntitysMethodWithSameImplementation,ae.MethodOverwritesOtherImplementedEntitysMethodWithSameName);a.push(...V.errors)}});const y=ja(d.ownDeclaredProperties,u.ownDeclaredProperties,ae.PropertyOverwritesOtherSiblingWithSameImplementation,ae.PropertyOverwritesOtherSiblingWithSameName);a.push(...y.errors);const v=ja(u.methods,u.abstractMethods,ae.MethodOverwritesOtherSiblingWithSameImplementation,ae.MethodOverwritesOtherSiblingWithSameName);return a.push(...v.errors),R(d.extends.flatMap(w=>Ni(w))).forEach(w=>{if(!l.find(A=>A.id===w.id)){const A=new lr({id:d.id+"--"+u.id+"--"+w.id+"--"+le.ImplementsIncompatibleEntities,message:`Entity "${d.name}" with id "${d.id}" is extending built-in entity "${u.name}" with id "${u.id}" but also extends entity "${w.name}" with id "${w.id}" which is incompatible`,issue:null,severity:q.Error,code:le.ImplementsIncompatibleEntities,entity:d,firstRelationship:u,secondRelationship:w});a.push(A)}}),a}function bAe(d){const u=[];return d.implements.forEach(i=>{if(!i.static){const a=new lr({id:d.id+"--"+i.id+"--"+le.StaticImplementingNonStaticEntity,message:`Entity "${d.name}" with id "${d.id}" is static but implements entity "${i.name}" with id "${i.id}" which is non-static`,issue:null,severity:q.Error,code:le.StaticImplementingNonStaticEntity,entity:d,firstRelationship:i});u.push(a)}}),d.extends.forEach(i=>{if(!i.static){const a=new lr({id:d.id+"--"+i.id+"--"+le.StaticExtendingNonStaticEntity,message:`Entity "${d.name}" with id "${d.id}" is static but extends entity "${i.name}" with id "${i.id}" which is non-static`,issue:null,severity:q.Error,code:le.StaticExtendingNonStaticEntity,entity:d,firstRelationship:i});u.push(a)}}),u}function wAe(d){const u=[];if(d.implements.length){const i=new lr({id:d.id+"--"+le.AbstractEntityImplements,message:`Entity "${d.name}" with id "${d.id}" cannot be marked as abstract because it implements other entities`,issue:null,severity:q.Error,code:le.AbstractEntityImplements,entity:d});u.push(i)}return d.extends.forEach(i=>{if(!i.abstract){const a=new lr({id:d.id+"--"+i.id+"--"+le.AbstractExtendingNonAbstractEntity,message:`Entity "${d.name}" with id "${d.id}" is abstract but extends entity "${i.name}" with id "${i.id}" which is non-abstract`,issue:null,severity:q.Error,code:le.AbstractExtendingNonAbstractEntity,entity:d,firstRelationship:i});u.push(a)}}),u}function RAe(d){const u=[];return d.extends.forEach(i=>{if(i.static){const a=new lr({id:d.id+"--"+i.id+"--"+le.NonStaticExtendingStaticEntity,message:`Entity "${d.name}" with id "${d.id}" is non-static but extends entity "${i.name}" with id "${i.id}" which is static`,issue:null,severity:q.Error,code:le.NonStaticExtendingStaticEntity,entity:d,firstRelationship:i});u.push(a)}}),u}function _Ae(d){const u=[];return d.extends.forEach(i=>{if(i.abstract){const a=new lr({id:d.id+"--"+i.id+"--"+le.NonAbstractExtendingAbstractEntity,message:`Entity "${d.name}" with id "${d.id}" is non-abstract but extends entity "${i.name}" with id "${i.id}" which is abstract`,issue:null,severity:q.Error,code:le.NonAbstractExtendingAbstractEntity,entity:d,firstRelationship:i});u.push(a)}}),u}function BS(d){const u=[],i=d.name;if(!i){const $=ft({id:`${d.id}--${ae.EmptyName}`,message:`Definition entity "${ne(d,d.project)}" with id "${d.id}" does not have a name. Entities of type ${d.type} must have valid names.`,issue:null,severity:q.Error,code:ae.EmptyName,entity:d});return u.push($.error),u}const l=[...d.project.functions,...d.project.entities.flatMap($=>$.methods)].filter($=>$.id!==d.id),p=i.trim(),e=!l.some($=>$.name===i||$.name===p);if(!e){const $=ft({id:`${d.id}--${ae.NameNotUniqueInScope}`,message:`Definition entity "${ne(d,d.project)}" with id "${d.id}" does not have a unique name. Entities of type ${d.type} must have valid names among all other entities of its type.`,issue:null,severity:q.Error,code:ae.NameNotUniqueInScope,entity:d});u.push($.error)}const y=jr(i);if(!!l.some($=>jr($.name)===y)&&e){const $=ft({id:`${d.id}--${ae.NameAsResolvedCodeNameNotUniqueInScope}`,message:`Definition entity "${ne(d,d.project)}" with id "${d.id}" does not have a unique name once it is resolved as it will appear in code: "${y}". Entities of type ${d.type} must have valid names including their code name form.`,issue:null,severity:q.Error,code:ae.NameAsResolvedCodeNameNotUniqueInScope,entity:d});u.push($.error)}if(!/^[a-zA-Z_]/.test(i)){const $=ft({id:`${d.id}--${ae.NameMustStartWithLetterOrUnderscore}`,message:`Definition entity "${ne(d,d.project)}" with id "${d.id}" has a name that does not start with a letter or underscore.`,issue:null,severity:q.Error,code:ae.NameMustStartWithLetterOrUnderscore,entity:d});u.push($.error)}const w=i.substring(1);if(!/^[a-zA-Z0-9_ ]*$/.test(w)){const $=ft({id:`${d.id}--${ae.NameCanOnlyContainLettersNumbersUnderscoreAndSpaces}`,message:`Definition entity "${ne(d,d.project)}" with id "${d.id}" has a name that contains invalid characters. It can only contain letters, numbers, underscores and spaces.`,issue:null,severity:q.Error,code:ae.NameCanOnlyContainLettersNumbersUnderscoreAndSpaces,entity:d});u.push($.error)}return u}const gAe=Object.freeze(Object.defineProperty({__proto__:null,getBaseMethodsNotImplemented:MS,getBasePropertiesNotImplemented:LS,validate:VS,validateCanBecomeAbstract:wAe,validateCanBecomeNonAbstract:_Ae,validateCanBecomeNonStatic:RAe,validateCanBecomeStatic:bAe,validateCanExtendEntity:AAe,validateCanImplementEntity:IAe,validateDefinitionEntityName:BS},Symbol.toStringTag,{value:"Module"}));function DAe(d,u){const i=[];if(d.parent)if(d.id===d.parent)i.push(new ee({id:`${d.id}--${d.parent}--${k.SelfReference}`,code:k.SelfReference,severity:q.Error,message:`Entity of type "${d.type}" with id "${d.id}", has a reference to itself at 'parent'. This is not allowed. Change the reference string or the 'entityId' property of the reference object.`,issue:null}));else{const a=u.get(d.parent);a?[f.Project,f.DataType].includes(a.type)||i.push(new ee({id:`${d.id}--${d.parent}--${k.InvalidParentReference}`,code:k.InvalidParentReference,severity:q.Error,message:`Entity of type "${d.type}" with id "${d.id}", has a parent reference that isn't pointing to an entity of type 'project' or 'data-type'.`,issue:null})):i.push(new ee({id:`${d.id}--${d.parent}--${k.ReferencedEntityNotFound}`,code:k.ReferencedEntityNotFound,severity:q.Error,message:`Entity of type "${d.type}" with id "${d.id}", is referencing an 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.`,issue:null}))}return d.implements&&Array.isArray(d.implements)?d.implements.forEach(a=>{if(d.id===a){i.push(new ee({id:`${d.id}--${a}--${k.SelfReference}`,code:k.SelfReference,severity:q.Error,message:`Entity of type "${d.type}" with id "${d.id}", has a reference to itself at one of the 'implements' references. This is not allowed. Change the reference string or the 'entityId' property of the reference object.`,issue:null}));return}const l=u.get(a);l?[f.DefinitionEntity,f.BuiltInBaseEntity].includes(l.type)?l.abstract||i.push(new ee({id:`${d.id}--${a}--${k.InvalidImplementsReference}`,code:k.InvalidImplementsReference,severity:q.Error,message:`Entity of type "${d.type}" with id "${d.id}", has an 'implements' reference that isn't pointing to an abstract entity.`,issue:null})):i.push(new ee({id:`${d.id}--${a}--${k.InvalidImplementsReference}`,code:k.InvalidImplementsReference,severity:q.Error,message:`Entity of type "${d.type}" with id "${d.id}", has an 'implements' reference that isn't pointing to an entity of type 'definition-entity' or 'built-in-base-entity'.`,issue:null})):i.push(new ee({id:`${d.id}--${a}--${k.ReferencedEntityNotFound}`,code:k.ReferencedEntityNotFound,severity:q.Error,message:`Entity of type "${d.type}" with id "${d.id}", is referencing an entity with id "${a}" that isn't yet found in the project. Perhaps it should be created first. Or perhaps the ID is incorrect.`,issue:null}))}):i.push(new ee({id:`${d.id}--${ae.InvalidObjectStructure}`,code:ae.InvalidObjectStructure,severity:q.Error,message:`Entity of type "${d.type}" with id "${d.id}", has an 'implements' property that isn't an array.`,issue:null})),d.extends&&Array.isArray(d.extends)&&d.extends.forEach(a=>{const l=u.get(a);l?[f.DefinitionEntity,f.BuiltInBaseEntity].includes(l.type)?l.abstract&&i.push(new ee({id:`${d.id}--${a}--${k.InvalidExtendsReference}`,code:k.InvalidExtendsReference,severity:q.Error,message:`Entity of type "${d.type}" with id "${d.id}", has an 'extends' reference that isn't pointing to a non-abstract entity. Did you want to use the property 'implements', which holds a list of references to absract entities, instead?`,issue:null})):i.push(new ee({id:`${d.id}--${a}--${k.InvalidExtendsReference}`,code:k.InvalidExtendsReference,severity:q.Error,message:`Entity of type "${d.type}" with id "${d.id}", has an 'extends' reference that isn't pointing to an entity of type 'definition-entity' or 'built-in-base-entity'.`,issue:null})):i.push(new ee({id:`${d.id}--${a}--${k.ReferencedEntityNotFound}`,code:k.ReferencedEntityNotFound,severity:q.Error,message:`Entity of type "${d.type}" with id "${d.id}", is referencing an entity with id "${a}" that isn't yet found in the project. Perhaps it should be created first. Or perhaps the ID is incorrect.`,issue:null}))}),i}var Um=(d=>(d.Extends="extends",d.Implements="implements",d))(Um||{});const qt=class qt extends Nr{constructor(i,a){super(i);g(this,"initialData");g(this,"id");g(this,"name");g(this,"codeName",null);g(this,"description",null);g(this,"x");g(this,"y");g(this,"static");g(this,"abstract");g(this,"type",f.DefinitionEntity);g(this,"properties",[]);g(this,"methods",[]);g(this,"abstractMethods",[]);g(this,"extends",[]);g(this,"implements",[]);g(this,"project");g(this,"errors",[]);g(this,"parent");g(this,"detachedDependents",{});g(this,"knownVersions",null);g(this,"activeVersion",!1);g(this,"initialized",!1);g(this,"startedInitialization",!1);g(this,"suggestedProperties",[]);g(this,"suggestedMethods",[]);this.initialData=i,this.project=a,this.id=i.id,this.name=i.name,this.description=i.description,this.x=i.x,this.y=i.y,this.codeName=i.codeName,this.static=i.static,this.abstract=i.abstract}static new(i=null){return{id:N.UUID.uuid(),version:N.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||L().toISOString(),author:(i==null?void 0:i.author)||N.sessionAuthor,previousVersion:null,deleted:!1,type:f.DefinitionEntity,name:"",codeName:null,description:"",static:!1,abstract:!1,properties:[],methods:[],abstractMethods:[],extends:[],implements:[],x:0,y:0,parent:null}}static fromGenerationTarget(i,a){let l=a;if(i.parent){const E=Z(i.parent);l=a.get(E)}const p=[];i.implements&&i.implements.forEach(E=>{p.push(a.get(E)||a.getBuiltIn(E))});const e=[];i.extends&&i.extends.forEach(E=>{e.push(a.get(E)||a.getBuiltIn(E))});const y={id:i.id,version:N.UUID.uuid(),createdAt:L().toISOString(),author:N.sessionAuthor,previousVersion:null,deleted:!1,name:i.name,type:f.DefinitionEntity,codeName:i.codeName||null,description:i.description,static:i.static,abstract:i.abstract,properties:[],methods:[],abstractMethods:[],extends:e,implements:p,x:0,y:0,parent:l},v=te(y,a);return v.setParent(l,null),v}static validateGenerationTarget(i,a){let l=JSON.parse(JSON.stringify(i));const p=[],e=DAe(l,a),y=Kb(l,a);p.push(...e,...y,...Br(l));const v=l.parent?a.get(l.parent):null;if(v&&v.type===f.DataType){const E=v;E.entity&&p.push(new ee({id:`${i.id}--${k.NewEntityWouldOverriteExisting}`,code:k.NewEntityWouldOverriteExisting,severity:q.Error,message:`The entity of type '${i.type}' with id '${i.id}' can't be added to the 'parent' entity with id '${E.id}' because it already has an 'entity' child. Data type entities can only have one 'entity' as children.
|
|
405
|
+
${ym}`,issue:null})),{errors:a,modifiedData:i}}onProjectInitialized(i,a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,new Date().toISOString(),this,!0,"on-property-received-project-initialized"))){return PS(this,a),a==null||a.attemptAutoclose("on-property-received-project-initialized",this.id),this}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 F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"sync-dependents"))){const a=[],l=[],p=[],e=[];return Object.values(this.detachedDependents).forEach(y=>{const v=y.entity.afterAllChildrenInitialized(i);a.push(...v.updated),l.push(...v.added),p.push(...v.removed),e.push(...v.affected)}),i==null||i.attemptAutoclose("sync-dependents",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(e),self:this}}onDetachedDependencyRemoved(i,a,l){const p=[],e=[],y=[],v=[];if(a==="property-implements"&&(this.setImplements(null,l),p.push(this)),a==="property-extends"){const{updated:E,added:w,removed:A,affected:$}=this.remove({ignoreUpstream:!1},l);p.push(...E),e.push(...w),y.push(...A),v.push(...$)}return{updated:R(p),added:R(e),removed:R(y),affected:R(v),self:this}}onDetachedDependencyRestored(i,a,l){const p=[],e=[],y=[],v=[];if(a==="property-implements"&&(this.setImplements(i,l),p.push(this)),a==="property-extends"){const{updated:E,added:w,removed:A,affected:$}=this.restore({},l);p.push(...E),e.push(...w),y.push(...A),v.push(...$)}return{updated:R(p),added:R(e),removed:R(y),affected:R(v),self:this}}unsubscribeFromDependencies(){var i,a,l,p,e,y,v;return(a=(i=this.implements)==null?void 0:i.unsubscribeDependents)==null||a.call(i,[{entity:this,field:"property-implements"}]),(p=(l=this.extends)==null?void 0:l.unsubscribeDependents)==null||p.call(l,[{entity:this,field:"property-extends"}]),(v=(y=(e=this.dataType)==null?void 0:e.entity)==null?void 0:y.unsubscribeDependents)==null||v.call(y,[{entity:this,field:"data-type-entity"}]),this.project.off(Vr.PROJECT_INITIALIZED,this.onProjectInitialized),this}subscribeToDependencies(){var i,a,l,p,e,y,v;return(a=(i=this.implements)==null?void 0:i.subscribeDependents)==null||a.call(i,[{entity:this,field:"property-implements"}]),(p=(l=this.extends)==null?void 0:l.subscribeDependents)==null||p.call(l,[{entity:this,field:"property-extends"}]),(v=(y=(e=this.dataType)==null?void 0:e.entity)==null?void 0:y.subscribeDependents)==null||v.call(y,[{entity:this,field:"data-type-entity"}]),this.project.on(Vr.PROJECT_INITIALIZED,this.onProjectInitialized),this}increaseVersion(i){if(i&&!L(i).isValid())throw new Error(`The shared timestamp '${i}' is not a valid ISO 8601 date string.`);return i&&L(i).isSame(L(this.createdAt))?this:(this.previousVersion=this.version,this.version=N.UUID.uuid(),this.createdAt=L(i).toISOString()||L().toISOString(),this)}captureVersion(){var a;const i=((a=this.knownVersions)==null?void 0:a.get(this.version))||new Ct(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.defaultValue=this.defaultValue,i.dataType=this.dataType,i.implements=this.implements,i.extends=this.extends,i.parent=this.parent,this}recursiveCaptureUpstreamVersions(i){const a=[],l=[],p=[],e=[];if(this.parent&&this.parent.type!==f.PrimitiveEntity&&this.parent.type!==f.BuiltInBaseEntity){this.parent.increaseVersion(i);const y=this.parent.recursiveCaptureUpstreamVersions(i);a.push(this.parent,...y.updated),l.push(...y.added),p.push(...y.removed)}return{updated:R(a),added:R(l),removed:R(p),affected:R(e),self:this}}async restoreVersion(i){var v;const a=[],l=[],p=[],e=[];if(this.version===i)return{updated:R(a),added:R(l),removed:R(p),affected:R(e),self:this};if(!this.knownVersions){const E=new Map;for(const[w,A]of this.knownVersions||new Map){if(E.set(w,A),A.activeVersion=!1,A.knownVersions)for(const[$,V]of A.knownVersions)E.set($,V);A.knownVersions=null}}let y=(v=this.knownVersions)==null?void 0:v.get(i);if(!y){const E=await this.APILoadVersion({},i);if(!E)throw new Error(`Version with id '${i}' for entity with id '${this.id}' not found.`);y=new Ct(E,this.project)}return this.metaSync(y.toShallowJSON(),null),this.previousVersion=y.previousVersion,this.version=y.version,this.createdAt=y.createdAt,this.author=y.author,this.deleted=y.deleted,this.defaultValue=y.defaultValue,this.dataType=y.dataType,this.implements=y.implements,this.parent=y.parent,{updated:R(a),added:R(l),removed:R(p),affected:R(e),self:this}}updateWithShallowTransfer(i,a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"update-with-shallow-transfer"))){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=Z(i.parent),p=this.project.get(l),e=this.parent;if(e&&e.id!==(p==null?void 0:p.id)&&this.removeFromParent(a),p)this.setParent(p,null);else throw a==null||a.attemptAutoclose("update-with-shallow-transfer",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("update-with-shallow-transfer",this.id),new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(i.implements){const l=Z(i.implements),p=this.project.get(l);if(p)this.setImplements(p,a);else if(l)throw new Error(`${Ti(this.type)} with id '${this.id}' has a 'implements' reference "${l}" which is missing in the project`)}if(i.extends){const l=Z(i.extends),p=this.project.get(l);if(p)this.setExtends(p,a);else if(l)throw new Error(`${Ti(this.type)} with id '${this.id}' has a 'extends' reference "${l}" which is missing in the project`)}return this.captureVersion(),this.subscribeToDependencies(),a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),this}hydrateAncestors(){const i=[],a=[],l=[],p=[];if(this.initialData.parent){const e=Z(this.initialData.parent),y=this.project.get(e);if(y)this.setParent(y,null);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.implements){const e=Z(this.initialData.implements),y=this.project.get(e);if(y)this.setImplements(y,null),i.push(y);else if(e)throw new Error(`${Ti(this.type)} with id '${this.id}' has a 'implements' reference "${e}" which is missing in the project`)}if(this.initialData.extends){const e=Z(this.initialData.extends),y=this.project.get(e);if(y)this.setExtends(y,null),i.push(y);else if(e)throw new Error(`${Ti(this.type)} with id '${this.id}' has a 'extends' reference "${e}" which is missing in the project`)}return{updated:R(i),added:R(a),removed:R(l),affected:R(p),self:this}}afterAllChildrenInitialized(i=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"after-all-children-initialized"))){const a=[],l=[],p=[],e=[];this.initialized=!0;const{updated:y,added:v,removed:E,affected:w}=this.syncWithImplementation(i);a.push(...y),l.push(...v),p.push(...E),e.push(...w);const{updated:A,added:$,removed:V,affected:U}=PS(this,i);return a.push(...A),l.push(...$),p.push(...V),e.push(...U),this.captureVersion(),i==null||i.attemptAutoclose("after-all-children-initialized",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(e),self:this}}addSelfToProject(i=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-self-to-project"))){const a=[this],l=[],p=[],e=[];return this.parent.addProperty(this),a.push(this.parent),this.subscribe(),this.subscribeToDependencies(),i==null||i.attemptAutoclose("add-self-to-project",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(e),self:this}}setParent(i,a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"set-parent"))){var l;return((l=this.parent)==null?void 0:l.id)!==(i==null?void 0:i.id)&&(this.parent=i,a&&(a==null||a.add(this,S.Updated))),a==null||a.attemptAutoclose("set-parent",this.id),this}setImplements(i,a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"set-implements"))){var l;return((l=this.implements)==null?void 0:l.id)!==(i==null?void 0:i.id)&&(this.implements=i,a&&(a==null||a.add(this,S.Updated))),a==null||a.attemptAutoclose("set-implements",this.id),this}setExtends(i,a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"set-extends"))){var l;return((l=this.extends)==null?void 0:l.id)!==(i==null?void 0:i.id)&&(this.extends=i,a&&(a==null||a.add(this,S.Updated))),a==null||a.attemptAutoclose("set-extends",this.id),this}initChildren(i=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"init-children"))){if(this.initialized||this.startedInitialization)return this;if(this.startedInitialization=!0,this.initialData.defaultValue&&(this.defaultValue=te(this.initialData.defaultValue,this.project),this.defaultValue.setParent(this,null),this.defaultValue.initChildren(i)),this.initialData.dataType){const a=te(this.initialData.dataType,this.project);a.setParent(this,null),a.initChildren(i),this.dataType=a}if(this.initialData.implements){const a=te(this.initialData.implements,this.project);this.setImplements(a,null)}if(this.initialData.extends){const a=te(this.initialData.extends,this.project);this.setExtends(a,null)}return 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 F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"meta-sync"))){const l=Ur(this,i),p=this.toMeta();return this.name=i.name!==void 0?i.name:p.name,this.codeName=i.codeName!==void 0?i.codeName:p.codeName,this.description=i.description!==void 0?i.description:p.description,this.abstract=i.abstract!==void 0?i.abstract:p.abstract,this.private=i.private!==void 0?i.private:p.private,this.index=i.index||(i.index!==0?p.index:0),this.static=i.static!==void 0?i.static:p.static,this.hidden=i.hidden!==void 0?i.hidden:p.hidden,this.constant=i.constant!==void 0?i.constant:p.constant,this.interactive=i.interactive!==void 0?i.interactive:p.interactive,this.required=i.required!==void 0?i.required:p.required,super.metaSync(i),i.deleted===!0&&!p.deleted?a==null||a.add(this,S.Removed):i.deleted===!1&&p.deleted?a==null||a.add(this,S.Added):l&&(a==null||a.add(this,S.Updated)),a==null||a.attemptAutoclose("meta-sync",this.id),this}async APILoad(i=ve,...a){return await Ct.repository.APILoad(this.id,...a),this}async APICreate(i=ve,...a){return await Ct.repository.APICreate(this.toShallowJSON(),...a),this}async APIUpdate(i=ve,...a){return await Ct.repository.APIUpdate(this.toShallowJSON(),...a),this}async APIDelete(i=ve,...a){return await Ct.repository.APIDelete(this.toShallowJSON(),...a),this}async APIClone(i=ve,...a){return await Ct.repository.APIClone(this.id,...a),this}async APILoadVersion(i=ve,a,...l){return await Ct.repository.APILoadVersion(this.id,a,...l)}removeFromParent(i=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-from-parent"))){const a=[],l=[],p=[],e=[];return this.parent.type===f.DefinitionEntity&&(this.parent.removeProperty(this),e.push(this.parent)),i==null||i.attemptAutoclose("remove-from-parent",this.id),{added:R(p),updated:R(a),removed:R(l),affected:R(e),self:this}}remove({ignoreUpstream:i}={ignoreUpstream:!1},a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-entity"))){const l=[],p=[],e=[],y=[];if(a!=null&&a.hasRemoved(this.id))return a==null||a.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(p.push(this),this.unsubscribe(),this.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},a),Object.values(this.detachedDependents).forEach(v=>{const{updated:E,removed:w,added:A}=v.entity.onDetachedDependencyRemoved(this,v.field,a);l.push(...E),p.push(...w),e.push(...A)}),this.defaultValue){const{updated:v,removed:E}=this.defaultValue.remove({ignoreUpstream:!0},a);l.push(...v),p.push(...E)}if(this.dataType){const{updated:v,removed:E}=this.dataType.remove({ignoreUpstream:!0},a);l.push(...v),p.push(...E)}if(!i){const v=this.removeFromParent(a);e.push(...v.added),l.push(...v.updated),p.push(...v.removed),y.push(...v.affected)}return a==null||a.attemptAutoclose("remove-entity",this.id),{added:R(e),updated:R(l),removed:R(p),affected:R(y),self:this}}restore({}={},i=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"restore-entity"))){const a=[],l=[],p=[],e=[];if(i!=null&&i.hasAdded(this.id))return i==null||i.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},i),Object.values(this.detachedDependents).forEach(y=>{const{updated:v,removed:E,added:w}=y.entity.onDetachedDependencyRestored(this,y.field,i);l.push(...v),p.push(...E),a.push(...w)}),this.defaultValue){const{updated:y}=this.defaultValue.restore({},i);l.push(...y)}if(this.dataType){const{updated:y}=this.dataType.restore({},i);l.push(...y)}return this.parent.type===f.DefinitionEntity&&(this.parent.addProperty(this),e.push(this.parent)),i==null||i.attemptAutoclose("restore-entity",this.id),{added:R(a),updated:R(l),removed:R(p),affected:R(e),self:this}}toFlat(i=new Set){var l,p;return i.has(this.id)?[]:(i.add(this.id),[this,...((l=this.defaultValue)==null?void 0:l.toFlat(i))||[],...((p=this.dataType)==null?void 0:p.toFlat(i))||[],...this.parent.toFlat(i)])}toFlatIds(i=new Set){var l,p;return i.has(this.id)?[]:(i.add(this.id),[this.id,...((l=this.defaultValue)==null?void 0:l.toFlatIds(i))||[],...((p=this.dataType)==null?void 0:p.toFlatIds(i))||[],...this.parent.toFlatIds(i)])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,codeName:this.codeName,description:this.description,index:this.index,hidden:this.hidden,private:this.private,abstract:this.abstract,required:this.required,constant:this.constant,interactive:this.interactive,static:this.static,type:this.type,name:this.name}}toJSON(i=new Set){var a,l,p,e;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,name:this.name,codeName:this.codeName,description:this.description,index:this.index,private:this.private,required:this.required,static:this.static,constant:this.constant,interactive:this.interactive,abstract:this.abstract,hidden:this.hidden,defaultValue:((a=this.defaultValue)==null?void 0:a.toJSON(i))||null,dataType:((l=this.dataType)==null?void 0:l.toJSON(i))||null,implements:((p=this.implements)==null?void 0:p.toJSON(i))||null,extends:((e=this.extends)==null?void 0:e.toJSON(i))||null,parent:this.parent.toReference()})}toJSONClone(i=ke){var l,p,e,y,v,E,w;let a;return(l=i.seenEntityMaps)!=null&&l.has(this.id)?a=i.seenEntityMaps.get(this.id):(a=i.newId||Gr(this,this.project,i.uuidStrategy),i.seenEntityMaps&&i.seenEntityMaps.set(this.id,a)),(p=i.seenEntities)!=null&&p.has(a)||(e=i.seenEntities)!=null&&e.has(this.id)?this.toReference({seenEntityMaps:i.seenEntityMaps}):((y=i.seenEntities)==null||y.add(a),(v=i.seenEntities)==null||v.add(this.id),{id:a,version:N.UUID.uuid(),createdAt:i.timestamp||L().toISOString(),author:N.sessionAuthor,previousVersion:null,deleted:!1,type:this.type,name:this.name,codeName:this.codeName,description:this.description,index:this.index,private:this.private,required:this.required,static:this.static,constant:this.constant,interactive:this.interactive,abstract:this.abstract,hidden:this.hidden,defaultValue:((E=this.defaultValue)==null?void 0:E.toJSONClone({...i,newId:null}))||null,dataType:((w=this.dataType)==null?void 0:w.toJSONClone({...i,newId:null}))||null,implements:(()=>{var A;return this.implements&&this.project.getBuiltIn(this.implements.id)?this.implements.toJSON():((A=this.implements)==null?void 0:A.toJSONClone({...i,newId:null}))||null})(),extends:(()=>{var A;return this.extends&&this.project.getBuiltIn(this.extends.id)?this.extends.toJSON():((A=this.extends)==null?void 0:A.toJSONClone({...i,newId:null}))||null})(),parent:this.parent.toReference({seenEntityMaps:i.seenEntityMaps})})}toReference(i=ke){var l;let a=this.id;return(l=i.seenEntityMaps)!=null&&l.has(this.id)&&(a=i.seenEntityMaps.get(this.id)),{id:a+"--"+N.UUID.uuid()+"--ref",type:f.GenericReference,entityId:a,version:this.version,entityType:this.type}}toShallowJSON(i=ke){var l,p,e,y,v;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,name:this.name,codeName:this.codeName,description:this.description,type:this.type,index:this.index,private:this.private,required:this.required,abstract:this.abstract,static:this.static,constant:this.constant,interactive:this.interactive,hidden:this.hidden,defaultValue:((p=this.defaultValue)==null?void 0:p.toReference(i))||null,dataType:((e=this.dataType)==null?void 0:e.toReference(i))||null,implements:((y=this.implements)==null?void 0:y.toReference(i))||null,extends:((v=this.extends)==null?void 0:v.toReference(i))||null,parent:this.parent.toReference(i)}}toFlatJSON(i=new Set){var l,p,e;return i.has(this.id)?[]:(i.add(this.id),[this.toShallowJSON(),...((l=this.defaultValue)==null?void 0:l.toFlatJSON(i))||[],...((p=this.dataType)==null?void 0:p.toFlatJSON(i))||[],...((e=this.implements)==null?void 0:e.toFlatJSON(i))||[],...this.parent.toFlatJSON(i)])}toGenerationTarget(){var i,a;return{id:this.id,name:this.name,description:this.description,type:this.type,private:this.private,required:this.required,abstract:this.abstract,static:this.static,implements:(i=this.implements)==null?void 0:i.id,extends:(a=this.extends)==null?void 0:a.id,parent:this.parent.id}}toFlatGenerationTarget(i=new Set){var l,p;return i.has(this.id)?[]:(i.add(this.id),[this.toGenerationTarget(),...((l=this.defaultValue)==null?void 0:l.toFlatGenerationTarget(i))||[],...((p=this.dataType)==null?void 0:p.toFlatGenerationTarget(i))||[]])}clearErrors(){var i,a;return this.errors=[],(i=this.defaultValue)==null||i.clearErrors(),(a=this.dataType)==null||a.clearErrors(),this}validate(){return this.errors=CS(this),this.errors.length,{success:!0,error:null,data:null}}getErrors(){var a,l;return[...this.errors,...((a=this.defaultValue)==null?void 0:a.getErrors())||[],...((l=this.dataType)==null?void 0:l.getErrors())||[]]}getShallowErrors(){return this.errors}implement(i,a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"implement-self-as-property")),l=null){const p=l||N.UUID.uuid(),e=Ct.new(a);e.id=p,e.name=this.name,e.description=this.description,e.index=this.index,e.private=this.private,e.required=this.required,e.static=this.static,e.constant=this.constant,e.hidden=this.hidden,e.interactive=this.interactive,e.parent=i.toReference(),e.implements=this.toJSON();const y=te(e,this.project);return y.hydrateAncestors(),y.addSelfToProject(a),y.initChildren(a),y}clone(i=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"clone-entity")),a=null,l=null,p=!0){var V,U;let e=Fr(a,this);const y=l||N.UUID.uuid();let v=a||this.parent;const E={hidden:!1,id:y,version:N.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||L().toISOString(),author:(i==null?void 0:i.author)||"1",previousVersion:null,deleted:!1,type:this.type,name:this.name,codeName:this.codeName,description:this.description,index:this.index,private:this.private,constant:this.constant,interactive:this.interactive,required:this.required,abstract:this.abstract,static:this.static,defaultValue:null,dataType:null,implements:this.implements,extends:this.extends,parent:v},w=or(E,e);p&&w.subscribe(),w.hydrateAncestors(),p&&w.addSelfToProject(i),w.setParent(v,null),w.initChildren(i),i==null||i.add(w,S.Added);const A=((V=this.dataType)==null?void 0:V.clone(i,w,N.UUID.uuid(),p))||null;A&&w.setDataType(A,i);const $=(U=this.defaultValue)==null?void 0:U.clone(i,w,N.UUID.uuid(),p);return w.setDefaultValue($||null,i),this.implements&&w.setImplements(this.implements,i),w.addSelfToProject(null),i==null||i.attemptAutoclose("clone-entity",this.id),w}setDataType(i,a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"set-data-type"))){const l=this.dataType;return(l==null?void 0:l.id)!==(i==null?void 0:i.id)&&(l==null||l.remove({ignoreUpstream:!0},a),this.dataType=i,this.subscribeToDependencies(),a==null||a.add(this,S.Affected)),a==null||a.attemptAutoclose("set-data-type",this.id),this}removeDataType(){return this.dataType=null,this}getDataType(i=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"get-data-type"))){return i==null||i.attemptAutoclose("get-data-type",this.id),this.dataType}getDefaultValue(){return this.defaultValue}setDefaultValue(i,a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"set-default-value"))){const l=this.defaultValue;return(l==null?void 0:l.id)!==(i==null?void 0:i.id)&&(l==null||l.remove({ignoreUpstream:!0},a),this.defaultValue=i,a==null||a.add(this,S.Affected)),a==null||a.attemptAutoclose("set-default-value",this.id),this}syncWithImplementation(i=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"sync-with-implementation"))){var y;const a=[],l=[],p=[],e=[];if(this.implements){const v=this.implements;if(!this.dataType&&v.dataType){const E=v.dataType.clone(i,this,N.UUID.uuid(),!0);this.setDataType(E,i),l.push(E)}if(this.implements.defaultValue&&!this.defaultValue){const E=(y=this.implements.defaultValue)==null?void 0:y.clone(i,this,N.UUID.uuid(),!0);this.setDefaultValue(E||null,i),l.push(E)}}return i==null||i.attemptAutoclose("sync-with-implementation",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(e),self:this}}};g(Ct,"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}),g(Ct,"type",f.Property),g(Ct,"USER_MANAGED_PARENT_TYPES",[f.DefinitionEntity]),g(Ct,"PARENT_TYPES",[...Ct.USER_MANAGED_PARENT_TYPES,f.PrimitiveEntity,f.BuiltInBaseEntity]),g(Ct,"MUTABLE_BASE_PROPERTIES",["name","codeName","description","private","abstract","static","required","constant","interactive"]),g(Ct,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),g(Ct,"BASE_PROPERTIES",[...Ct.MUTABLE_BASE_PROPERTIES,...Ct.INMUTABLE_BASE_PROPERTIES]),g(Ct,"MUTABLE_META_PROPERTIES",[...Ct.MUTABLE_BASE_PROPERTIES,"index"]),g(Ct,"INMUTABLE_META_PROPERTIES",[...Ct.INMUTABLE_BASE_PROPERTIES]),g(Ct,"META_PROPERTIES",[...Ct.MUTABLE_META_PROPERTIES,...Ct.INMUTABLE_META_PROPERTIES]),g(Ct,"MUTABLE_UPSTREAM_PROPERTIES",[]),g(Ct,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","implements","extends"]),g(Ct,"UPSTREAM_PROPERTIES",[...Ct.MUTABLE_UPSTREAM_PROPERTIES,...Ct.INMUTABLE_UPSTREAM_PROPERTIES]),g(Ct,"MUTABLE_DOWNSTREAM_PROPERTIES",["dataType"]),g(Ct,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),g(Ct,"DOWNSTREAM_PROPERTIES",[...Ct.MUTABLE_DOWNSTREAM_PROPERTIES,...Ct.INMUTABLE_DOWNSTREAM_PROPERTIES]),g(Ct,"PROPERTIES",[...Ct.META_PROPERTIES,...Ct.UPSTREAM_PROPERTIES,...Ct.DOWNSTREAM_PROPERTIES]);let ea=Ct;function VS(d){const u=xye(),i=d.toJSON();u.safeParse(i).success;const l=d.implements.flatMap(w=>mAe(d,w)),p=d.extends.flatMap(w=>vAe(d,w)),e=TAe(d),y=EAe(d);d.methods.flatMap(w=>w.validate());const v=[...l,...p,...e,...y,...BS(d)];return vr(d.errors,v)}function LS(d,u){const i=u.properties.filter(p=>p.abstract),a=[];let l=[...d.properties];return i.forEach(p=>{const e=l.find(y=>{var v;return((v=y.implements)==null?void 0:v.id)===p.id});e?l=l.filter(y=>y.id!==e.id):a.push(p)}),a}function MS(d,u){const i=u.abstractMethods,a=[];let l=[...d.methods];return i.forEach(p=>{const e=l.find(y=>{var v;return((v=y.implements)==null?void 0:v.id)===p.id});e?l=l.filter(y=>y.id!==e.id):a.push(p)}),a}function mAe(d,u){const i=[];if(!u.abstract){const w=ft({id:d.id+"--"+le.ImplementingNonAbstractEntity,message:`Entity "${d.name}" with id "${d.id}" is implementing a non-abstract entity "${u.name}" with id "${u.id}"`,issue:null,severity:q.Error,code:le.ImplementingNonAbstractEntity,entity:d});return i.push(w.error),i}const a=u.properties.filter(w=>w.abstract),l=[];let p=[...d.properties];a.forEach(w=>{const A=p.find($=>{var V;return((V=$.implements)==null?void 0:V.id)===w.id});A?p=p.filter($=>$.id!==A.id):l.push(w)}),l.length&&l.forEach(w=>{const A=ft({id:d.id+"--"+le.MissingPropertyImplementation+"--"+w.id,message:`Property "${w.name}" with id "${w.id}" of entity "${u.name}" with id "${u.id}" is not implemented when entity "${d.name}" with id "${d.id}" implements it`,issue:null,severity:q.Error,code:le.MissingPropertyImplementation,entity:d});i.push(A.error)});const e=[];let y=[...d.methods];u.abstractMethods.forEach(w=>{const A=y.find($=>{var V;return((V=$.implements)==null?void 0:V.id)===w.id});A?y=y.filter($=>$.id!==A.id):e.push(w)}),e.length&&e.forEach(w=>{const A=ft({id:d.id+"--"+le.MissingMethodImplementation+"--"+w.id,message:`Method "${w.name}" with id "${w.id}" of entity "${u.name}" with id "${u.id}" is not implemented when entity "${d.name}" with id "${d.id}" implements it`,issue:null,severity:q.Error,code:le.MissingMethodImplementation,entity:d});i.push(A.error)});const v=[];u.properties.forEach(w=>{const A=p.find($=>$.name===w.name);A&&v.push([A,w])}),v.length&&v.forEach(([w])=>{const A=ft({id:d.id+"--"+ae.PropertyOverwritesOtherSiblingWithSameName+"--"+w.id,message:`Property "${w.name}" with id "${w.id}" of entity "${d.name}" with id "${d.id}" overwrites the property with the same name from the base entity "${u.name}" with id "${u.id}"`,issue:null,severity:q.Error,code:ae.PropertyOverwritesOtherSiblingWithSameName,entity:d});i.push(A.error)});const E=[];return u.methods.forEach(w=>{const A=y.find($=>$.name===w.name);A&&E.push([A,w])}),E.length&&E.forEach(([w])=>{const A=ft({id:d.id+"--"+ae.MethodOverwritesOtherSiblingWithSameName+"--"+w.id,message:`Method "${w.name}" with id "${w.id}" of entity "${d.name}" with id "${d.id}" overwrites the method with the same name from the base entity "${u.name}" with id "${u.id}"`,issue:null,severity:q.Error,code:ae.MethodOverwritesOtherSiblingWithSameName,entity:d});i.push(A.error)}),i}function vAe(d,u){const i=[],a=[];if(!d.abstract&&u.abstract){const p=ft({id:d.id+"--"+u.id+"--"+le.NonAbstractExtendingAbstractEntity,message:`Entity "${d.name}" with id "${d.id}" is not-abstract but is extending an abstract entity "${u.name}" with id "${u.id}"`,issue:null,severity:q.Error,code:le.NonAbstractExtendingAbstractEntity,entity:d,firstRelationship:u});return i.push(p.error),i}if(d.abstract&&!u.abstract){const p=ft({id:d.id+"--"+u.id+"--"+le.AbstractExtendingNonAbstractEntity,message:`Entity "${d.name}" with id "${d.id}" is abstract but is extending an non-abstract entity "${u.name}" with id "${u.id}"`,issue:null,severity:q.Error,code:le.AbstractExtendingNonAbstractEntity,entity:d,firstRelationship:u});return i.push(p.error),i}d.properties.forEach(p=>{var y;const e=u.properties.find(v=>{var E;return v.name===p.name&&((E=p.extends)==null?void 0:E.id)!==v.id});((y=p.implements)==null?void 0:y.id)!==(e==null?void 0:e.id)&&e&&a.push(p)}),a.length&&a.forEach(p=>{const e=ft({id:d.id+"--"+ae.PropertyOverwritesOtherSiblingWithSameName,message:`Property "${p.name}" with id "${p.id}" of entity "${d.name}" with id "${d.id}" overwrites the property with the same name from the extended entity "${u.name}" with id "${u.id}"`,issue:null,severity:q.Error,code:ae.PropertyOverwritesOtherSiblingWithSameName,entity:d});i.push(e.error)});const l=[];return d.methods.forEach(p=>{var y;const e=u.methods.find(v=>{var E;return v.name===p.name&&((E=p.extends)==null?void 0:E.id)!==v.id});((y=p.implements)==null?void 0:y.id)!==(e==null?void 0:e.id)&&e&&l.push(p)}),l.length&&l.forEach(p=>{const e=ft({id:d.id+"--"+ae.MethodOverwritesOtherSiblingWithSameName,message:`Method "${p.name}" with id "${p.id}" of entity "${d.name}" with id "${d.id}" overwrites the method with the same name from the extended entity "${u.name}" with id "${u.id}"`,issue:null,severity:q.Error,code:ae.MethodOverwritesOtherSiblingWithSameName,entity:d});i.push(e.error)}),i}function EAe(d){const u=[];if(!d.properties.length){const i=ft({id:d.id+"--"+le.NoProperties,message:"No properties implemented",issue:null,severity:q.Warning,code:le.NoProperties,entity:d});u.push(i.error)}return d.properties.forEach(i=>{i.validate()}),u}function TAe(d){const u=[];if(d.abstract){if(d.methods.length){const i=ft({id:d.id+"--"+le.AbstractEntityWithNonAbstractMethods,message:`Entity "${d.name}" with id "${d.id}" is marked as abstract but has non-abstract methods`,issue:null,severity:q.Error,code:le.AbstractEntityWithNonAbstractMethods,entity:d});u.push(i.error)}if(d.properties.some(i=>!i.abstract)){const i=ft({id:d.id+"--"+le.AbstractEntityWithNonAbstractProperties,message:`Entity "${d.name}" with id "${d.id}" is marked as abstract but has non-abstract properties`,issue:null,severity:q.Error,code:le.AbstractEntityWithNonAbstractProperties,entity:d});u.push(i.error),d.properties.forEach(a=>{if(!a.abstract){const l=ft({id:d.id+"--"+le.StaticEntityWithNonStaticProperties+"--"+a.id,message:`Property "${a.name}" with id "${a.id}" of entity "${d.name}" with id "${d.id}" is not marked as abstract but the entity is marked as abstract`,issue:null,severity:q.Error,code:le.StaticEntityWithNonStaticProperties,entity:d});u.push(l.error)}})}}else{if(d.abstractMethods.length){const i=ft({id:d.id+"--"+le.AbstractPropertyInNonAbstractEntity,message:`Entity "${d.name}" with id "${d.id}" is not marked as abstract but has abstract methods`,issue:null,severity:q.Error,code:le.AbstractPropertyInNonAbstractEntity,entity:d});u.push(i.error)}d.properties.some(i=>i.abstract)&&d.properties.forEach(i=>{if(i.abstract){const a=ft({id:d.id+"--"+le.AbstractPropertyInNonAbstractEntity+"--"+i.id,message:`Property "${i.name}" with id "${i.id}" of entity "${d.name}" with id "${d.id}" is marked as abstract but the entity is not marked as abstract`,issue:null,severity:q.Error,code:le.AbstractPropertyInNonAbstractEntity,entity:d,firstRelationship:i});u.push(a.error)}})}return d.static&&d.properties.some(i=>!i.static)&&d.properties.forEach(i=>{if(!i.static){const a=ft({id:d.id+"--"+le.NonStaticPropertyInStaticEntity+"--"+i.id,message:`Property "${i.name}" with id "${i.id}" of entity "${d.name}" with id "${d.id}" is not marked as static but the entity is marked as static`,issue:null,severity:q.Error,code:le.NonStaticPropertyInStaticEntity,entity:d,firstRelationship:i});u.push(a.error)}}),u}function IAe(d,u){const i=[],a=Ni(u);if(!u.abstract){const e=new lr({id:d.id+"--"+u.id+"--"+le.ImplementingNonAbstractEntity,message:`Entity "${d.name}" with id "${d.id}" is implementing a non-abstract built-in entity "${u.name}" with id "${u.id}"`,issue:null,severity:q.Error,code:le.ImplementingNonAbstractEntity,entity:d,firstRelationship:u});i.push(e)}const l=d.implements.filter(e=>e.id!==u.id);if(d.abstract){const e=new lr({id:d.id+"--"+u.id+"--"+le.AbstractEntityImplements,message:`Entity "${d.name}" with id "${d.id}" is marked as abstract and cannot implement built-in entity "${u.name}" with id "${u.id}"`,issue:null,severity:q.Error,code:le.AbstractEntityImplements,entity:d,firstRelationship:u});i.push(e)}if(d.static&&!u.static){const e=new lr({id:d.id+"--"+u.id+"--"+le.StaticImplementingNonStaticEntity,message:`Entity "${d.name}" with id "${d.id}" is marked as static and cannot implement non-static built-in entity "${u.name}" with id "${u.id}"`,issue:null,severity:q.Error,code:le.StaticImplementingNonStaticEntity,entity:d,firstRelationship:u});i.push(e)}if(!d.static&&u.static){const e=new lr({id:d.id+"--"+u.id+"--"+le.NonStaticImplementingStaticEntity,message:`Entity "${d.name}" with id "${d.id}" is not marked as static and cannot implement static built-in entity "${u.name}" with id "${u.id}"`,issue:null,severity:q.Error,code:le.NonStaticImplementingStaticEntity,entity:d,firstRelationship:u});i.push(e)}return l.length&&l.forEach(e=>{if(e.type===f.BuiltInBaseEntity){const y=a.filter(v=>v.id!==e.id);y.length&&y.forEach(v=>{if(v.id!==e.id){const E=new lr({id:d.id+"--"+v.id+"--"+e.id+"--"+le.ImplementsIncompatibleEntities,message:`Entity "${d.name}" with id "${d.id}" is implementing built-in entity "${v.name}" with id "${v.id}" but also implements entity "${e.name}" with id "${e.id}" which is incompatible`,issue:null,severity:q.Error,code:le.ImplementsIncompatibleEntities,entity:d,firstRelationship:v,secondRelationship:e});i.push(E)}})}else{Ni(e).forEach(w=>{const A=a.filter($=>$.id!==w.id);A.length&&A.forEach($=>{if($.id!==w.id){const V=new lr({id:d.id+"--"+$.id+"--"+w.id+"--"+le.ImplementsIncompatibleEntities,message:`Entity "${d.name}" with id "${d.id}" is implementing built-in entity "${$.name}" with id "${$.id}" but also implements entity "${w.name}" with id "${w.id}" which is incompatible`,issue:null,severity:q.Error,code:le.ImplementsIncompatibleEntities,entity:d,firstRelationship:$,secondRelationship:w});i.push(V)}})});const v=ja(u.ownDeclaredProperties,e.ownDeclaredProperties,ae.PropertyOverwritesOtherImplementedEntitysPropertyWithSameImplementation,ae.PropertyOverwritesOtherImplementedEntitysPropertyWithSameName);i.push(...v.errors);const E=ja(u.abstractMethods,[...e.abstractMethods,...e.methods],ae.MethodOverwritesOtherImplementedEntitysMethodWithSameImplementation,ae.MethodOverwritesOtherImplementedEntitysMethodWithSameName);i.push(...E.errors)}}),R(d.extends.flatMap(e=>Ni(e))).forEach(e=>{if(!a.find(y=>y.id===e.id)){const y=new lr({id:d.id+"--"+u.id+"--"+e.id+"--"+le.ExtendsIncompatibleEntities,message:`Entity "${d.name}" with id "${d.id}" is implementing built-in entity "${u.name}" with id "${u.id}" but also extends entity "${e.name}" with id "${e.id}" which is incompatible`,issue:null,severity:q.Error,code:le.ExtendsIncompatibleEntities,entity:d,firstRelationship:u,secondRelationship:e});i.push(y)}}),i}function AAe(d,u,i=!1){const a=[],l=Ni(u);if(!d.abstract&&u.abstract){const w=ft({id:d.id+"--"+u.id+"--"+le.NonAbstractExtendingAbstractEntity,message:`Entity "${d.name}" with id "${d.id}" is not-abstract but is extending an abstract entity "${u.name}" with id "${u.id}"`,issue:null,severity:q.Error,code:le.NonAbstractExtendingAbstractEntity,entity:d,firstRelationship:u});a.push(w.error)}if(d.abstract&&!u.abstract){const w=ft({id:d.id+"--"+u.id+"--"+le.AbstractExtendingNonAbstractEntity,message:`Entity "${d.name}" with id "${d.id}" is abstract but is extending an non-abstract entity "${u.name}" with id "${u.id}"`,issue:null,severity:q.Error,code:le.AbstractExtendingNonAbstractEntity,entity:d,firstRelationship:u});a.push(w.error)}if(!d.static&&u.static){const w=ft({id:d.id+"--"+u.id+"--"+le.NonStaticExtendingStaticEntity,message:`Entity "${d.name}" with id "${d.id}" is not static but is extending a static entity "${u.name}" with id "${u.id}"`,issue:null,severity:q.Error,code:le.NonStaticExtendingStaticEntity,entity:d,firstRelationship:u});a.push(w.error)}if(d.static&&!u.static){const w=ft({id:d.id+"--"+u.id+"--"+le.StaticExtendingNonStaticEntity,message:`Entity "${d.name}" with id "${d.id}" is static but is extending an non-static entity "${u.name}" with id "${u.id}"`,issue:null,severity:q.Error,code:le.StaticExtendingNonStaticEntity,entity:d,firstRelationship:u});a.push(w.error)}if(!rf(u)){const w=ft({id:d.id+"--"+u.id+"--"+le.ExtendingNonInteractiveEntity,message:`Entity "${d.name}" with id "${d.id}" is extending an non-interactive entity "${u.name}" with id "${u.id}"`,issue:null,severity:q.Error,code:le.ExtendingNonInteractiveEntity,entity:d,firstRelationship:u});a.push(w.error)}const e=d.extends.filter(w=>w.id!==u.id);e.length&&e.forEach(w=>{if(w.type===f.BuiltInBaseEntity){const A=l.filter($=>$.id!==w.id);A.length&&A.forEach($=>{if($.id!==w.id){const V=ft({id:d.id+"--"+$.id+"--"+w.id+"--"+le.ExtendsIncompatibleEntities,message:`Entity "${d.name}" with id "${d.id}" is extending built-in entity "${$.name}" with id "${$.id}" but also extends entity "${w.name}" with id "${w.id}" which is incompatible`,issue:null,severity:q.Error,code:le.ExtendsIncompatibleEntities,entity:d,firstRelationship:$,secondRelationship:w});a.push(V.error)}})}else{Ni(w).forEach(J=>{const ie=l.filter(X=>X.id!==J.id);ie.length&&ie.forEach(X=>{if(X.id!==J.id){const ue=new lr({id:d.id+"--"+X.id+"--"+J.id+"--"+le.ImplementsIncompatibleEntities,message:`Entity "${d.name}" with id "${d.id}" is extending built-in entity "${X.name}" with id "${X.id}" but also extends or implements entity "${J.name}" with id "${J.id}" which is incompatible`,issue:null,severity:q.Error,code:le.ImplementsIncompatibleEntities,entity:d,firstRelationship:X,secondRelationship:J});a.push(ue)}})});const $=!!Ni(w).find(J=>J.id===u.id);let V=[...w.properties];$&&(V=V.filter(J=>!u.properties.find(ie=>{var X;return ie.id===J.id||ie.name===J.name||ie.id===((X=J.implements)==null?void 0:X.id)})));let U=[...w.methods];$&&(U=U.filter(J=>!u.methods.find(ie=>{var X;return ie.id===J.id||ie.name===J.name||ie.id===((X=J.implements)==null?void 0:X.id)})));const G=ja(u.ownDeclaredProperties,V,ae.PropertyOverwritesOtherExtendedEntitysPropertyWithSameImplementation,ae.PropertyOverwritesOtherExtendedEntitysPropertyWithSameName);a.push(...G.errors);const K=ja(u.abstractMethods,U,ae.MethodOverwritesOtherExtendedEntitysMethodWithSameImplementation,ae.MethodOverwritesOtherExtendedEntitysMethodWithSameName);a.push(...K.errors)}}),i&&Me.log("self.implements.length",d.implements.length),d.implements.length&&d.implements.forEach(w=>{if(w.type===f.BuiltInBaseEntity){const A=l.filter($=>$.id!==w.id);A.length&&A.forEach($=>{if($.id!==w.id){const V=new lr({id:d.id+"--"+$.id+"--"+w.id+"--"+le.ImplementsIncompatibleEntities,message:`Entity "${d.name}" with id "${d.id}" is implementing built-in entity "${$.name}" with id "${$.id}" but also implements entity "${w.name}" with id "${w.id}" which is incompatible`,issue:null,severity:q.Error,code:le.ImplementsIncompatibleEntities,entity:d,firstRelationship:$,secondRelationship:w});a.push(V)}})}else{Ni(w).forEach(U=>{const G=l.filter(K=>K.id!==U.id);G.length&&G.forEach(K=>{if(K.id!==U.id){const J=new lr({id:d.id+"--"+K.id+"--"+U.id+"--"+le.ImplementsIncompatibleEntities,message:`Entity "${d.name}" with id "${d.id}" is implementing built-in entity "${K.name}" with id "${K.id}" but also implements entity "${U.name}" with id "${U.id}" which is incompatible`,issue:null,severity:q.Error,code:le.ImplementsIncompatibleEntities,entity:d,firstRelationship:K,secondRelationship:U});a.push(J)}})});const $=ja(u.ownDeclaredProperties,w.ownDeclaredProperties,ae.PropertyOverwritesOtherImplementedEntitysPropertyWithSameImplementation,ae.PropertyOverwritesOtherImplementedEntitysPropertyWithSameName);a.push(...$.errors);const V=ja(u.abstractMethods,[...w.abstractMethods,...w.methods],ae.MethodOverwritesOtherImplementedEntitysMethodWithSameImplementation,ae.MethodOverwritesOtherImplementedEntitysMethodWithSameName);a.push(...V.errors)}});const y=ja(d.ownDeclaredProperties,u.ownDeclaredProperties,ae.PropertyOverwritesOtherSiblingWithSameImplementation,ae.PropertyOverwritesOtherSiblingWithSameName);a.push(...y.errors);const v=ja(u.methods,u.abstractMethods,ae.MethodOverwritesOtherSiblingWithSameImplementation,ae.MethodOverwritesOtherSiblingWithSameName);return a.push(...v.errors),R(d.extends.flatMap(w=>Ni(w))).forEach(w=>{if(!l.find(A=>A.id===w.id)){const A=new lr({id:d.id+"--"+u.id+"--"+w.id+"--"+le.ImplementsIncompatibleEntities,message:`Entity "${d.name}" with id "${d.id}" is extending built-in entity "${u.name}" with id "${u.id}" but also extends entity "${w.name}" with id "${w.id}" which is incompatible`,issue:null,severity:q.Error,code:le.ImplementsIncompatibleEntities,entity:d,firstRelationship:u,secondRelationship:w});a.push(A)}}),a}function bAe(d){const u=[];return d.implements.forEach(i=>{if(!i.static){const a=new lr({id:d.id+"--"+i.id+"--"+le.StaticImplementingNonStaticEntity,message:`Entity "${d.name}" with id "${d.id}" is static but implements entity "${i.name}" with id "${i.id}" which is non-static`,issue:null,severity:q.Error,code:le.StaticImplementingNonStaticEntity,entity:d,firstRelationship:i});u.push(a)}}),d.extends.forEach(i=>{if(!i.static){const a=new lr({id:d.id+"--"+i.id+"--"+le.StaticExtendingNonStaticEntity,message:`Entity "${d.name}" with id "${d.id}" is static but extends entity "${i.name}" with id "${i.id}" which is non-static`,issue:null,severity:q.Error,code:le.StaticExtendingNonStaticEntity,entity:d,firstRelationship:i});u.push(a)}}),u}function wAe(d){const u=[];if(d.implements.length){const i=new lr({id:d.id+"--"+le.AbstractEntityImplements,message:`Entity "${d.name}" with id "${d.id}" cannot be marked as abstract because it implements other entities`,issue:null,severity:q.Error,code:le.AbstractEntityImplements,entity:d});u.push(i)}return d.extends.forEach(i=>{if(!i.abstract){const a=new lr({id:d.id+"--"+i.id+"--"+le.AbstractExtendingNonAbstractEntity,message:`Entity "${d.name}" with id "${d.id}" is abstract but extends entity "${i.name}" with id "${i.id}" which is non-abstract`,issue:null,severity:q.Error,code:le.AbstractExtendingNonAbstractEntity,entity:d,firstRelationship:i});u.push(a)}}),u}function RAe(d){const u=[];return d.extends.forEach(i=>{if(i.static){const a=new lr({id:d.id+"--"+i.id+"--"+le.NonStaticExtendingStaticEntity,message:`Entity "${d.name}" with id "${d.id}" is non-static but extends entity "${i.name}" with id "${i.id}" which is static`,issue:null,severity:q.Error,code:le.NonStaticExtendingStaticEntity,entity:d,firstRelationship:i});u.push(a)}}),u}function _Ae(d){const u=[];return d.extends.forEach(i=>{if(i.abstract){const a=new lr({id:d.id+"--"+i.id+"--"+le.NonAbstractExtendingAbstractEntity,message:`Entity "${d.name}" with id "${d.id}" is non-abstract but extends entity "${i.name}" with id "${i.id}" which is abstract`,issue:null,severity:q.Error,code:le.NonAbstractExtendingAbstractEntity,entity:d,firstRelationship:i});u.push(a)}}),u}function BS(d){const u=[],i=d.name;if(!i){const $=ft({id:`${d.id}--${ae.EmptyName}`,message:`Definition entity "${ne(d,d.project)}" with id "${d.id}" does not have a name. Entities of type ${d.type} must have valid names.`,issue:null,severity:q.Error,code:ae.EmptyName,entity:d});return u.push($.error),u}const l=[...d.project.functions,...d.project.entities.flatMap($=>$.methods)].filter($=>$.id!==d.id),p=i.trim(),e=!l.some($=>$.name===i||$.name===p);if(!e){const $=ft({id:`${d.id}--${ae.NameNotUniqueInScope}`,message:`Definition entity "${ne(d,d.project)}" with id "${d.id}" does not have a unique name. Entities of type ${d.type} must have valid names among all other entities of its type.`,issue:null,severity:q.Error,code:ae.NameNotUniqueInScope,entity:d});u.push($.error)}const y=jr(i);if(!!l.some($=>jr($.name)===y)&&e){const $=ft({id:`${d.id}--${ae.NameAsResolvedCodeNameNotUniqueInScope}`,message:`Definition entity "${ne(d,d.project)}" with id "${d.id}" does not have a unique name once it is resolved as it will appear in code: "${y}". Entities of type ${d.type} must have valid names including their code name form.`,issue:null,severity:q.Error,code:ae.NameAsResolvedCodeNameNotUniqueInScope,entity:d});u.push($.error)}if(!/^[a-zA-Z_]/.test(i)){const $=ft({id:`${d.id}--${ae.NameMustStartWithLetterOrUnderscore}`,message:`Definition entity "${ne(d,d.project)}" with id "${d.id}" has a name that does not start with a letter or underscore.`,issue:null,severity:q.Error,code:ae.NameMustStartWithLetterOrUnderscore,entity:d});u.push($.error)}const w=i.substring(1);if(!/^[a-zA-Z0-9_ ]*$/.test(w)){const $=ft({id:`${d.id}--${ae.NameCanOnlyContainLettersNumbersUnderscoreAndSpaces}`,message:`Definition entity "${ne(d,d.project)}" with id "${d.id}" has a name that contains invalid characters. It can only contain letters, numbers, underscores and spaces.`,issue:null,severity:q.Error,code:ae.NameCanOnlyContainLettersNumbersUnderscoreAndSpaces,entity:d});u.push($.error)}return u}const gAe=Object.freeze(Object.defineProperty({__proto__:null,getBaseMethodsNotImplemented:MS,getBasePropertiesNotImplemented:LS,validate:VS,validateCanBecomeAbstract:wAe,validateCanBecomeNonAbstract:_Ae,validateCanBecomeNonStatic:RAe,validateCanBecomeStatic:bAe,validateCanExtendEntity:AAe,validateCanImplementEntity:IAe,validateDefinitionEntityName:BS},Symbol.toStringTag,{value:"Module"}));function DAe(d,u){const i=[];if(d.parent)if(d.id===d.parent)i.push(new ee({id:`${d.id}--${d.parent}--${k.SelfReference}`,code:k.SelfReference,severity:q.Error,message:`Entity of type "${d.type}" with id "${d.id}", has a reference to itself at 'parent'. This is not allowed. Change the reference string or the 'entityId' property of the reference object.`,issue:null}));else{const a=u.get(d.parent);a?[f.Project,f.DataType].includes(a.type)||i.push(new ee({id:`${d.id}--${d.parent}--${k.InvalidParentReference}`,code:k.InvalidParentReference,severity:q.Error,message:`Entity of type "${d.type}" with id "${d.id}", has a parent reference that isn't pointing to an entity of type 'project' or 'data-type'.`,issue:null})):i.push(new ee({id:`${d.id}--${d.parent}--${k.ReferencedEntityNotFound}`,code:k.ReferencedEntityNotFound,severity:q.Error,message:`Entity of type "${d.type}" with id "${d.id}", is referencing an 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.`,issue:null}))}return d.implements&&Array.isArray(d.implements)?d.implements.forEach(a=>{if(d.id===a){i.push(new ee({id:`${d.id}--${a}--${k.SelfReference}`,code:k.SelfReference,severity:q.Error,message:`Entity of type "${d.type}" with id "${d.id}", has a reference to itself at one of the 'implements' references. This is not allowed. Change the reference string or the 'entityId' property of the reference object.`,issue:null}));return}const l=u.get(a);l?[f.DefinitionEntity,f.BuiltInBaseEntity].includes(l.type)?l.abstract||i.push(new ee({id:`${d.id}--${a}--${k.InvalidImplementsReference}`,code:k.InvalidImplementsReference,severity:q.Error,message:`Entity of type "${d.type}" with id "${d.id}", has an 'implements' reference that isn't pointing to an abstract entity.`,issue:null})):i.push(new ee({id:`${d.id}--${a}--${k.InvalidImplementsReference}`,code:k.InvalidImplementsReference,severity:q.Error,message:`Entity of type "${d.type}" with id "${d.id}", has an 'implements' reference that isn't pointing to an entity of type 'definition-entity' or 'built-in-base-entity'.`,issue:null})):i.push(new ee({id:`${d.id}--${a}--${k.ReferencedEntityNotFound}`,code:k.ReferencedEntityNotFound,severity:q.Error,message:`Entity of type "${d.type}" with id "${d.id}", is referencing an entity with id "${a}" that isn't yet found in the project. Perhaps it should be created first. Or perhaps the ID is incorrect.`,issue:null}))}):i.push(new ee({id:`${d.id}--${ae.InvalidObjectStructure}`,code:ae.InvalidObjectStructure,severity:q.Error,message:`Entity of type "${d.type}" with id "${d.id}", has an 'implements' property that isn't an array.`,issue:null})),d.extends&&Array.isArray(d.extends)&&d.extends.forEach(a=>{const l=u.get(a);l?[f.DefinitionEntity,f.BuiltInBaseEntity].includes(l.type)?l.abstract&&i.push(new ee({id:`${d.id}--${a}--${k.InvalidExtendsReference}`,code:k.InvalidExtendsReference,severity:q.Error,message:`Entity of type "${d.type}" with id "${d.id}", has an 'extends' reference that isn't pointing to a non-abstract entity. Did you want to use the property 'implements', which holds a list of references to absract entities, instead?`,issue:null})):i.push(new ee({id:`${d.id}--${a}--${k.InvalidExtendsReference}`,code:k.InvalidExtendsReference,severity:q.Error,message:`Entity of type "${d.type}" with id "${d.id}", has an 'extends' reference that isn't pointing to an entity of type 'definition-entity' or 'built-in-base-entity'.`,issue:null})):i.push(new ee({id:`${d.id}--${a}--${k.ReferencedEntityNotFound}`,code:k.ReferencedEntityNotFound,severity:q.Error,message:`Entity of type "${d.type}" with id "${d.id}", is referencing an entity with id "${a}" that isn't yet found in the project. Perhaps it should be created first. Or perhaps the ID is incorrect.`,issue:null}))}),i}var Um=(d=>(d.Extends="extends",d.Implements="implements",d))(Um||{});const qt=class qt extends Nr{constructor(i,a){super(i);g(this,"initialData");g(this,"id");g(this,"name");g(this,"codeName",null);g(this,"description",null);g(this,"x");g(this,"y");g(this,"static");g(this,"abstract");g(this,"type",f.DefinitionEntity);g(this,"properties",[]);g(this,"methods",[]);g(this,"abstractMethods",[]);g(this,"extends",[]);g(this,"implements",[]);g(this,"project");g(this,"errors",[]);g(this,"parent");g(this,"detachedDependents",{});g(this,"knownVersions",null);g(this,"activeVersion",!1);g(this,"initialized",!1);g(this,"startedInitialization",!1);g(this,"suggestedProperties",[]);g(this,"suggestedMethods",[]);this.initialData=i,this.project=a,this.id=i.id,this.name=i.name,this.description=i.description,this.x=i.x,this.y=i.y,this.codeName=i.codeName,this.static=i.static,this.abstract=i.abstract}static new(i=null){return{id:N.UUID.uuid(),version:N.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||L().toISOString(),author:(i==null?void 0:i.author)||N.sessionAuthor,previousVersion:null,deleted:!1,type:f.DefinitionEntity,name:"",codeName:null,description:"",static:!1,abstract:!1,properties:[],methods:[],abstractMethods:[],extends:[],implements:[],x:0,y:0,parent:null}}static fromGenerationTarget(i,a){let l=a;if(i.parent){const E=Z(i.parent);l=a.get(E)}const p=[];i.implements&&i.implements.forEach(E=>{p.push(a.get(E)||a.getBuiltIn(E))});const e=[];i.extends&&i.extends.forEach(E=>{e.push(a.get(E)||a.getBuiltIn(E))});const y={id:i.id,version:N.UUID.uuid(),createdAt:L().toISOString(),author:N.sessionAuthor,previousVersion:null,deleted:!1,name:i.name,type:f.DefinitionEntity,codeName:i.codeName||null,description:i.description,static:i.static,abstract:i.abstract,properties:[],methods:[],abstractMethods:[],extends:e,implements:p,x:0,y:0,parent:l},v=te(y,a);return v.setParent(l,null),v}static validateGenerationTarget(i,a){let l=JSON.parse(JSON.stringify(i));const p=[],e=DAe(l,a),y=Kb(l,a);p.push(...e,...y,...Br(l));const v=l.parent?a.get(l.parent):null;if(v&&v.type===f.DataType){const E=v;E.entity&&p.push(new ee({id:`${i.id}--${k.NewEntityWouldOverriteExisting}`,code:k.NewEntityWouldOverriteExisting,severity:q.Error,message:`The entity of type '${i.type}' with id '${i.id}' can't be added to the 'parent' entity with id '${E.id}' because it already has an 'entity' child. Data type entities can only have one 'entity' as children.
|
|
406
406
|
You can inspect the existing 'entity' field with the 'describe_entity' action. Like so:
|
|
407
407
|
${Xn({describe_entity:E.entity.id})}
|
|
408
408
|
Alternatively you can update the parent data-type entity with 'update' action to remove the existing value of the field.`,issue:null}))}return{errors:p,modifiedData:l}}get interactive(){return this.implements.length?this.implements.every(i=>i.interactive):!0}get allMethods(){return R([...this.ownDeclaredMethods,...this.allBaseMethodsFromOriginalParents])}get allProperties(){return R([...this.ownDeclaredProperties,...this.allBasePropertiesFromOriginalParents])}get allBaseMethodsFromOriginalParents(){return R([...this.extends.flatMap(i=>i.allMethods,[]),...this.implements.flatMap(i=>i.allMethods,[])])}get allBasePropertiesFromOriginalParents(){return R([...this.extends.flatMap(i=>i.allProperties,[]),...this.implements.flatMap(i=>i.allProperties,[])])}get allBasePropertiesFromExtendedAndImplementedEntities(){return R([...this.extends.reduce((i,a)=>[...[...a.ownDeclaredProperties,...a.allBasePropertiesFromExtendedAndImplementedEntities].filter(p=>!p.abstract),...i],[]),...this.implements.reduce((i,a)=>[...[...a.ownDeclaredProperties,...a.allBasePropertiesFromExtendedAndImplementedEntities].filter(p=>!p.abstract),...i],[])])}get allBaseMethodsFromExtendedAndImplementedEntities(){return R([...this.extends.reduce((i,a)=>a.type!==f.DefinitionEntity?[]:[...[...a.ownDeclaredMethods,...a.allBaseMethodsFromExtendedAndImplementedEntities].filter(p=>p.type!==f.ActionDescriptor),...i],[]),...this.implements.reduce((i,a)=>a.type!==f.DefinitionEntity?a.abstractMethods:[...[...a.ownDeclaredMethods,...a.allBaseMethodsFromExtendedAndImplementedEntities].filter(p=>p.type!==f.ActionDescriptor),...i],[])])}get extendedPropertiesFromOriginalParents(){return R(this.extends.reduce((i,a)=>{const l=[...a.ownDeclaredProperties,...a.extendedPropertiesFromOriginalParents].filter(p=>!p.abstract);return[...i,...l]},[]))}get implementedPropertiesFromOriginalParents(){return R([...this.extends.reduce((i,a)=>{const l=a.implementedPropertiesFromOriginalParents,p=[...a.ownDeclaredProperties].filter(e=>!!e.abstract&&!l.find(y=>y.name===e.name));return[...l,...p,...i]},[]),...this.implements.reduce((i,a)=>{const l=a.implementedPropertiesFromOriginalParents,p=[...a.ownDeclaredProperties].filter(e=>!!e.abstract&&!l.find(y=>y.name===e.name));return[...l,...p,...i]},[])].filter(i=>!!i.abstract))}get extendedMethodsFromOriginalParents(){return R(this.extends.reduce((i,a)=>{if(a.type!==f.DefinitionEntity)return[];const l=[...a.ownDeclaredMethods,...a.extendedMethodsFromOriginalParents].filter(p=>p.type!==f.ActionDescriptor);return[...i,...l]},[]))}get implementedMethodsFromOriginalParents(){return R([...this.extends.reduce((i,a)=>{const l=a.type===f.DefinitionEntity?a.methods:[],p=[...a.abstractMethods].filter(e=>!l.find(y=>y.name===e.name));return[...l,...p,...i]},[]),...this.implements.reduce((i,a)=>[...a.abstractMethods,...i],[])].filter(i=>i.type===f.ActionDescriptor))}get extendedProperties(){return this.properties.filter(i=>i.isExtendedProperty)}get ownDeclaredProperties(){return this.properties.filter(i=>!i.isExtendedProperty)}get extendedMethods(){return this.methods.filter(i=>i.isExtendedMethod)}get ownDeclaredMethods(){return this.methods.filter(i=>!i.isExtendedMethod)}validateGeneratedUpdate(i){const a=[];return i.parent&&a.push(new ee({id:`${this.id}--${k.InvalidParentUpdate}`,code:k.InvalidParentUpdate,severity:q.Error,message:`Entity of type '${this.type}' with id '${this.id}' cannot have the 'parent' property updated. The 'parent' on an '${this.type}', must be the root project as it is a globally declared entity.`,issue:null})),{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 F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"sync-dependents"))){const a=[],l=[],p=[],e=[];return Object.values(this.detachedDependents).forEach(y=>{const v=y.entity.afterAllChildrenInitialized(i);a.push(...v.updated),l.push(...v.added),p.push(...v.removed),e.push(...v.affected)}),i==null||i.attemptAutoclose("sync-dependents",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(e),self:this}}onDetachedDependencyRemoved(i,a,l){const p=[],e=[],y=[],v=[];return a==="implements"&&this.removeImplementation(i),a==="extends"&&this.removeExtension(i),{updated:R(p),added:R(e),removed:R(y),affected:R(v),self:this}}onDetachedDependencyRestored(i,a,l){const p=[],e=[],y=[],v=[];return a==="implements"&&this.addImplementation(i),a==="extends"&&this.addExtension(i),{updated:R(p),added:R(e),removed:R(y),affected:R(v),self:this}}unsubscribeFromDependencies(){return this.implements.forEach(i=>{ls.includes(i.type)||i.unsubscribeDependents([{entity:this,field:"implements"}])}),this}subscribeToDependencies(){return this.implements.forEach(i=>{ls.includes(i.type)||i.subscribeDependents([{entity:this,field:"implements"}])}),this.extends.forEach(i=>{ls.includes(i.type)||i.subscribeDependents([{entity:this,field:"extends"}])}),this}increaseVersion(i){if(i&&!L(i).isValid())throw new Error(`The shared timestamp '${i}' is not a valid ISO 8601 date string.`);return i&&L(i).isSame(L(this.createdAt))?this:(this.previousVersion=this.version,this.version=N.UUID.uuid(),this.createdAt=L(i).toISOString()||L().toISOString(),this)}captureVersion(){var a;const i=((a=this.knownVersions)==null?void 0:a.get(this.version))||new qt(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.properties=[...this.properties],i.methods=[...this.methods],i.abstractMethods=[...this.abstractMethods],i.extends=[...this.extends],i.implements=[...this.implements],i.parent=this.parent,this}recursiveCaptureUpstreamVersions(i){const a=[],l=[],p=[],e=[];if(this.parent){this.parent.increaseVersion(i);const y=this.parent.recursiveCaptureUpstreamVersions(i);a.push(this.parent,...y.updated),l.push(...y.added),p.push(...y.removed)}return{updated:R(a),added:R(l),removed:R(p),affected:R(e),self:this}}async restoreVersion(i){var v;const a=[],l=[],p=[],e=[];if(this.version===i)return{updated:R(a),added:R(l),removed:R(p),affected:R(e),self:this};if(!this.knownVersions){const E=new Map;for(const[w,A]of this.knownVersions||new Map){if(E.set(w,A),A.activeVersion=!1,A.knownVersions)for(const[$,V]of A.knownVersions)E.set($,V);A.knownVersions=null}}let y=(v=this.knownVersions)==null?void 0:v.get(i);if(!y){const E=await this.APILoadVersion({},i);if(!E)throw new Error(`Version with id '${i}' for entity with id '${this.id}' not found.`);y=new qt(E,this.project)}return this.metaSync(y.toShallowJSON(),null),this.previousVersion=y.previousVersion,this.version=y.version,this.createdAt=y.createdAt,this.author=y.author,this.deleted=y.deleted,this.properties=y.properties,this.methods=y.methods,this.abstractMethods=y.abstractMethods,this.extends=y.extends,this.implements=y.implements,this.parent=y.parent,{updated:R(a),added:R(l),removed:R(p),affected:R(e),self:this}}updateWithShallowTransfer(i,a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"update-with-shallow-transfer"))){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=Z(i.parent),p=this.project.get(l),e=this.parent;if(e&&e.id!==(p==null?void 0:p.id)&&this.removeFromParent(a),p)this.setParent(p,a);else throw a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),new Error(`${this.type} with id '${this.id}' must have a 'parent'`);return i.extends.forEach(l=>{const p=Z(l),e=this.project.get(p);e&&this.addExtension(e)}),i.implements.forEach(l=>{const p=Z(l),e=this.project.get(p);e&&this.addImplementation(e)}),this.captureVersion(),this.subscribeToDependencies(),a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),this}hydrateAncestors(){const i=[],a=[],l=[],p=[];if(this.initialData.parent){const e=Z(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'`);return this.initialData.extends.forEach(e=>{const y=Z(e),v=this.project.get(y);v&&(this.addExtension(v),v.type!==f.BuiltInBaseEntity&&i.push(v))}),this.initialData.implements.forEach(e=>{const y=Z(e),v=this.project.get(y);v&&(this.addImplementation(v),v.type!==f.BuiltInBaseEntity&&i.push(v))}),{updated:R(i),added:R(a),removed:R(l),affected:R(p),self:this}}afterAllChildrenInitialized(i=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"after-all-children-initialized"))){const a=[],l=[],p=[],e=[];this.initialized=!0;const{updated:y,added:v,removed:E,affected:w}=this.syncImplementationProperties(i);a.push(...y),l.push(...v),p.push(...E),e.push(...w);const{updated:A,added:$,removed:V,affected:U}=this.addExtendedProperties(i);a.push(...A),l.push(...$),p.push(...V),e.push(...U);const{updated:G,added:K,removed:J}=this.removeUnrecognizedProperties(i);a.push(...G),l.push(...K),p.push(...J);const{updated:ie,added:X,removed:ue,affected:re}=this.syncImplementationMethods(i);a.push(...ie),l.push(...X),p.push(...ue),e.push(...re);const{updated:fe,added:Y,removed:H,affected:ce}=this.addExtendedMethods(i);a.push(...fe),l.push(...Y),p.push(...H),e.push(...ce);const{updated:z,added:oe,removed:we}=this.removeUnrecognizedMethods(i);return a.push(...z),l.push(...oe),p.push(...we),this.addSuggestions(),this.captureVersion(),i==null||i.attemptAutoclose("after-all-children-initialized",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(e),self:this}}addSelfToProject(i=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-self-to-project"))){const a=[this],l=[],p=[],e=[];if(this.parent.type===f.DataType){const y=this.parent;y.entity=this,a.push(y)}else this.project.addDefinitionEntity(this);return this.subscribe(),this.subscribeToDependencies(),i==null||i.attemptAutoclose("add-self-to-project",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(e),self:this}}setParent(i,a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"set-parent"))){var l;return((l=this.parent)==null?void 0:l.id)!==(i==null?void 0:i.id)&&(this.parent=i,a&&(a==null||a.add(this,S.Updated))),a==null||a.attemptAutoclose("set-parent",this.id),this}addExtension(i){return this.extends.includes(i)||this.extends.push(i),this}removeExtension(i){return this.extends=this.extends.filter(a=>a.id!==i.id),this}addImplementation(i){return this.implements.includes(i)||this.implements.push(i),this}removeImplementation(i){return this.implements=this.implements.filter(a=>a.id!==i.id),this}removeProperty(i){return this.properties=this.properties.filter(a=>a.id!==i.id),this}addMethod(i){return this.methods.includes(i)||(this.methods.push(i),this.suggestedMethods=this.suggestedMethods.filter(a=>a.name!==i.name)),this}removeMethod(i){return this.methods=this.methods.filter(a=>a.id!==i.id),this}addProperty(i){return this.properties.includes(i)||(this.properties.push(i),this.suggestedProperties=this.suggestedProperties.filter(a=>a.name!==i.name)),this}addSuggestedProperty(i){return this.suggestedProperties.includes(i)||this.suggestedProperties.push(i),this}addSuggestedMethod(i){return this.suggestedMethods.includes(i)||this.suggestedMethods.push(i),this}removeSuggestedProperty(i){return this.suggestedProperties=this.suggestedProperties.filter(a=>a.id!==i.id),this}removeSuggestedMethod(i){return this.suggestedMethods=this.suggestedMethods.filter(a=>a.id!==i.id),this}addAbstractMethod(i){return this.abstractMethods.includes(i)||this.abstractMethods.push(i),this}removeAbstractMethod(i){return this.abstractMethods=this.abstractMethods.filter(a=>a.id!==i.id),this}initChildren(i=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.properties=this.initialData.properties.map(a=>{const l=te(a,this.project);return l.setParent(this,null),l.initChildren(i),l}),this.methods=this.initialData.methods.map(a=>{const l=te(a,this.project);return l.setParent(this,null),l.initChildren(i),l}),this.abstractMethods=this.initialData.abstractMethods.map(a=>{const l=te(a,this.project);return l.setParent(this,null),l.initChildren(i),l}),this.extends=this.initialData.extends.map(a=>te(a,this.project)),this.implements=this.initialData.implements.map(a=>te(a,this.project)),this.subscribeToDependencies(),this.afterAllChildrenInitialized(i),i==null||i.attemptAutoclose("init-children",this.id),this)}removeUnrecognizedProperties(i=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-unrecognized-properties"))){const a=[],l=[],p=[],e=[];let y=[...this.properties];y=y.filter(E=>E.parent.id===this.id),y=y.filter(E=>!E.isExtendedProperty);const v=this.implementedPropertiesFromOriginalParents;return y=y.filter(E=>this.interactive&&!E.implements?!1:!v.find(w=>{var A;return w.id===((A=E.implements)==null?void 0:A.id)})),y.forEach(E=>{const w=E.remove({ignoreUpstream:!1},i);p.push(...w.removed),a.push(...w.updated)}),i==null||i.attemptAutoclose("remove-unrecognized-properties",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(e),self:this}}removeUnrecognizedMethods(i=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-unrecognized-methods"))){const a=[],l=[],p=[],e=[];let y=[...this.methods];y=y.filter(E=>E.parent.id===this.id),y=y.filter(E=>!E.isExtendedMethod);const v=this.implementedMethodsFromOriginalParents;return y=y.filter(E=>this.interactive&&!E.implements?!1:!v.find(w=>{var A;return w.id===((A=E.implements)==null?void 0:A.id)})),y.forEach(E=>{const w=E.remove({ignoreUpstream:!1},i);p.push(...w.removed),a.push(...w.updated)}),i==null||i.attemptAutoclose("remove-unrecognized-methods",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(e),self:this}}syncImplementationMethods(i=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"sync-implementation-methods"))){const a=[],l=[],p=[],e=[],y=this.methods,v=this.implementedMethodsFromOriginalParents,E=[...this.allBaseMethodsFromExtendedAndImplementedEntities,...y];return v.filter(A=>!E.find(V=>{var U;return((U=V.implements)==null?void 0:U.id)===A.id})).forEach(A=>{if(this.methods.find(G=>{var K;return((K=G.implements)==null?void 0:K.id)===A.id}))return;const V=this.methods.find(G=>{var ue,re;if(G.name===A.name&&!G.implements)return!0;const K=Es(this,Ue.CRON_JOB),J=Es(this,Ue.HTTP_ENDPOINT),ie=((ue=G.implements)==null?void 0:ue.id)===Ee["built-in-base-entity"].BUILT_IN_HTTP_ENDPOINT_ENTITY.methods.handler.id,X=((re=G.implements)==null?void 0:re.id)===Ee["built-in-base-entity"].BUILT_IN_CRON_JOB_ENTITY.methods.handler.id;return!!(K&&!X&&!J&&ie||J&&!ie&&!K&&X)});if(V&&V.type===f.FunctionDeclaration){V.setImplements(A,i),V.metaSync({name:A.name},i),i==null||i.add(V,S.Updated),i==null||i.add(this,S.Updated);return}this.id==="new-endpoint-test-id-1234"&&console.log("Creating new method for",A.name);const U=A.implementAsFunctionDeclaration(i,this);l.push(U),i==null||i.add(U,S.Added),this.addMethod(U)}),i==null||i.attemptAutoclose("sync-implementation-methods",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(e),self:this}}syncImplementationProperties(i=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"sync-implementation-properties"))){const a=[],l=[],p=[],e=[],y=this.properties,v=this.implementedPropertiesFromOriginalParents,E=[...this.allBasePropertiesFromExtendedAndImplementedEntities,...y];return v.filter(A=>!E.find(V=>{var U;return((U=V.implements)==null?void 0:U.id)===A.id})).forEach(A=>{if(this.properties.find(G=>{var K;return((K=G.implements)==null?void 0:K.id)===A.id}))return;const V=this.properties.find(G=>G.name===A.name&&!!G.abstract&&!G.implements);if(V){V.setImplements(A,i),V.metaSync({abstract:!1},i),V.afterAllChildrenInitialized(i);return}const U=A.implement(this,i,N.UUID.uuid());l.push(U),i==null||i.add(U,S.Added)}),i==null||i.attemptAutoclose("sync-implementation-properties",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(e),self:this}}addExtendedMethods(i=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-extended-methods"))){const a=[],l=[],p=[],e=[],y=this.methods,E=this.extendedMethodsFromOriginalParents.filter(A=>A.type===f.FunctionDeclaration),w=new Set(y.filter(A=>{var $;return!!(($=A.extends)!=null&&$.id)}).map(A=>A.extends.id));return E.forEach(A=>{if(w.has(A.id))return;w.add(A.id);const $=A.clone(i,this,N.UUID.uuid());$.setExtends(A,i),$.initChildren(i),l.push($),i==null||i.add($,S.Added),this.addMethod($)}),i==null||i.attemptAutoclose("add-extended-methods",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(e),self:this}}addExtendedProperties(i=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-extended-properties"))){const a=[],l=[],p=[],e=[],y=this.properties,v=this.extendedPropertiesFromOriginalParents,E=v.filter(A=>v.find(V=>{var U;return((U=V.implements)==null?void 0:U.id)===A.id})?!1:!A.abstract),w=new Set(y.filter(A=>{var $;return!!(($=A.extends)!=null&&$.id)}).map(A=>A.extends.id));return E.forEach(A=>{if(w.has(A.id))return;w.add(A.id);const $=A.clone(i,this,N.UUID.uuid());$.setExtends(A,i),$.initChildren(i),l.push($),i==null||i.add($,S.Added),this.addProperty($)}),i==null||i.attemptAutoclose("add-extended-properties",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(e),self:this}}addSuggestions(){return this.implements.forEach(i=>{LS(this,i).forEach(p=>{const e=p.toJSON();e.id=`_suggestion--parent--${this.id}--${p.id}`;const y=te(e,this.project);y.suggestion=!0,y.setParent(this,null),y.initChildren(null),this.addSuggestedProperty(y)}),MS(this,i).forEach(p=>{const e=`_suggestion--parent--${this.id}--${p.id}`,y=p.implementAsFunctionDeclaration(null,this,e),v=te(y,this.project);if(v.suggestion=!0,v.setParent(this,null),v.initChildren(null),this.methods=this.methods.filter(E=>E.id!==e),v.inputs.forEach(E=>{E.suggestion=!0}),v.returnStatements.length){const E=v.returnStatements[0];E.suggestion=!0,E.outputs.forEach(w=>{w.suggestion=!0})}this.addSuggestedMethod(v)})}),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 F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"meta-sync"))){const l=Ur(this,i),p=this.toMeta();return this.name=i.name!==void 0?i.name:p.name,this.codeName=i.codeName!==void 0?i.codeName:p.codeName,this.description=i.description!==void 0?i.description:p.description,this.x=i.x||p.x,this.y=i.y||p.y,this.static=i.static!==void 0?i.static:this.static,this.abstract=i.abstract!==void 0?i.abstract:this.abstract,super.metaSync(i),i.deleted===!0&&!p.deleted?a==null||a.add(this,S.Removed):i.deleted===!1&&p.deleted?a==null||a.add(this,S.Added):l&&(a==null||a.add(this,S.Updated)),a==null||a.attemptAutoclose("meta-sync",this.id),this}async APILoad(i=ve,...a){return await qt.repository.APILoad(this.id,...a),this}async APICreate(i=ve,...a){return await qt.repository.APICreate(this.toShallowJSON(),...a),this}async APIUpdate(i=ve,...a){return await qt.repository.APIUpdate(this.toShallowJSON(),...a),this}async APIDelete(i=ve,...a){return await qt.repository.APIDelete(this.toShallowJSON(),...a),this}async APIClone(i=ve,...a){return await qt.repository.APIClone(this.id,...a),this}async APILoadVersion(i=ve,a,...l){return await qt.repository.APILoadVersion(this.id,a,...l)}removeFromParent(i=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-from-parent"))){const a=[],l=[],p=[],e=[];if(this.parent.type===f.Project)this.parent.removeDefinitionEntity(this);else if(this.parent.type===f.DataType&&this.parent.entity&&this.parent.entity.id===this.id){const y=this.parent.setEntity(null,i);a.push(y)}return i==null||i.attemptAutoclose("remove-from-parent",this.id),{added:R(p),updated:R(a),removed:R(l),affected:R(e),self:this}}remove({ignoreUpstream:i}={ignoreUpstream:!1},a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-entity"))){const l=[],p=[],e=[],y=[];if(a!=null&&a.hasRemoved(this.id))return a==null||a.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(p.push(this),this.unsubscribe(),this.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},a),Object.values(this.detachedDependents).forEach(v=>{const{updated:E,removed:w,added:A}=v.entity.onDetachedDependencyRemoved(this,v.field,a);l.push(...E),p.push(...w),e.push(...A)}),this.properties.forEach(v=>{const{updated:E,removed:w}=v.remove({ignoreUpstream:!0},a);l.push(...E),p.push(...w)}),this.methods.forEach(v=>{const{updated:E,removed:w}=v.remove({ignoreUpstream:!0},a);l.push(...E),p.push(...w)}),this.abstractMethods.forEach(v=>{const{updated:E,removed:w}=v.remove({ignoreUpstream:!0},a);l.push(...E),p.push(...w)}),this.suggestedProperties.forEach(v=>{const{updated:E,removed:w}=v.remove({ignoreUpstream:!0},a);l.push(...E),p.push(...w)}),this.suggestedMethods.forEach(v=>{const{updated:E,removed:w}=v.remove({ignoreUpstream:!0},a);l.push(...E),p.push(...w)}),!i){const v=this.removeFromParent(a);e.push(...v.added),l.push(...v.updated),p.push(...v.removed),y.push(...v.affected)}return a==null||a.attemptAutoclose("remove-entity",this.id),{added:R(e),updated:R(l),removed:R(p),affected:R(y),self:this}}restore({}={},i=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"restore-entity"))){const a=[],l=[],p=[],e=[];return i!=null&&i.hasAdded(this.id)?(i==null||i.attemptAutoclose("restore-entity",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:E,added:w}=y.entity.onDetachedDependencyRestored(this,y.field,i);l.push(...v),p.push(...E),a.push(...w)}),this.properties.forEach(y=>{const{updated:v}=y.restore({},i);l.push(...v)}),this.methods.forEach(y=>{const{updated:v}=y.restore({},i);l.push(...v)}),this.abstractMethods.forEach(y=>{const{updated:v}=y.restore({},i);l.push(...v)}),this.suggestedProperties.forEach(y=>{const{updated:v}=y.restore({},i);l.push(...v)}),this.suggestedMethods.forEach(y=>{const{updated:v}=y.restore({},i);l.push(...v)}),i==null||i.attemptAutoclose("restore-entity",this.id),{added:R(a),updated:R(l),removed:R(p),affected:R(e),self:this})}toFlat(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this,...this.extends.flatMap(l=>l.toFlat(i)),...this.implements.flatMap(l=>l.toFlat(i)),...this.properties.flatMap(l=>l.toFlat(i)),...this.methods.flatMap(l=>l.toFlat(i)),...this.abstractMethods.flatMap(l=>l.toFlat(i)),...this.parent.toFlat(i)])}toFlatIds(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.id,...this.extends.flatMap(l=>l.toFlatIds(i)),...this.implements.flatMap(l=>l.toFlatIds(i)),...this.properties.flatMap(l=>l.toFlatIds(i)),...this.methods.flatMap(l=>l.toFlatIds(i)),...this.abstractMethods.flatMap(l=>l.toFlatIds(i)),...this.parent.toFlatIds(i)])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,codeName:this.codeName,description:this.description,static:this.static,abstract:this.abstract,x:this.x,y:this.y,type:this.type,name:this.name}}toJSON(i=new Set){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,name:this.name,codeName:this.codeName,description:this.description,x:this.x,y:this.y,static:this.static,abstract:this.abstract,properties:this.properties.map(a=>a.toJSON(i)),methods:this.methods.map(a=>a.toJSON(i)),abstractMethods:this.abstractMethods.map(a=>a.toJSON(i)),implements:this.implements.map(a=>a.toJSON(i)),extends:this.extends.map(a=>a.toJSON(i)),parent:this.parent.toReference()})}toJSONClone(i=ke){var l,p,e,y,v;let a;return(l=i.seenEntityMaps)!=null&&l.has(this.id)?a=i.seenEntityMaps.get(this.id):(a=i.newId||Gr(this,this.project,i.uuidStrategy),i.seenEntityMaps&&i.seenEntityMaps.set(this.id,a)),(p=i.seenEntities)!=null&&p.has(a)||(e=i.seenEntities)!=null&&e.has(this.id)?this.toReference({seenEntityMaps:i.seenEntityMaps}):((y=i.seenEntities)==null||y.add(a),(v=i.seenEntities)==null||v.add(this.id),{id:a,version:N.UUID.uuid(),createdAt:i.timestamp||L().toISOString(),author:N.sessionAuthor,previousVersion:null,deleted:!1,type:this.type,name:this.name,codeName:this.codeName,description:this.description,x:this.x,y:this.y,static:this.static,abstract:this.abstract,properties:this.properties.map(E=>E.toJSONClone({...i,newId:null})),methods:this.methods.map(E=>E.toJSONClone({...i,newId:null})),abstractMethods:this.abstractMethods.map(E=>E.toJSONClone({...i,newId:null})),implements:this.implements.map(E=>E.type===f.BuiltInBaseEntity?E.toJSON():E.toJSONClone({...i,newId:null})),extends:this.extends.map(E=>E.type===f.BuiltInBaseEntity?E.toJSON():E.toJSONClone({...i,newId:null})),parent:this.parent.toReference({seenEntityMaps:i.seenEntityMaps})})}toReference(i=ke){var l;let a=this.id;return(l=i.seenEntityMaps)!=null&&l.has(this.id)&&(a=i.seenEntityMaps.get(this.id)),{id:a+"--"+N.UUID.uuid()+"--ref",type:f.GenericReference,entityId:a,version:this.version,entityType:this.type}}toShallowJSON(i=ke){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,name:this.name,codeName:this.codeName,description:this.description,type:this.type,x:this.x,y:this.y,static:this.static,abstract:this.abstract,properties:this.properties.map(p=>p.toReference(i)),methods:this.methods.map(p=>p.toReference(i)),abstractMethods:this.abstractMethods.map(p=>p.toReference(i)),implements:this.implements.map(p=>p.toReference(i)),extends:this.extends.map(p=>p.toReference(i)),parent:this.parent.toReference(i)}}toFlatJSON(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.toShallowJSON(),...this.properties.flatMap(l=>l.toFlatJSON(i)),...this.methods.flatMap(l=>l.toFlatJSON(i)),...this.abstractMethods.flatMap(l=>l.toFlatJSON(i)),...this.implements.flatMap(l=>l.toFlatJSON(i)),...this.extends.flatMap(l=>l.toFlatJSON(i)),...this.parent.toFlatJSON(i)])}toGenerationTarget(){const i=this.parent.type===f.Project?void 0:this.parent.id;return{id:this.id,name:this.name,description:this.description,type:this.type,static:this.static,abstract:this.abstract,extends:this.extends.map(a=>a.id),implements:this.implements.map(a=>a.id),parent:i}}toFlatGenerationTarget(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.toGenerationTarget(),...this.properties.flatMap(l=>l.toFlatGenerationTarget(i)),...this.methods.flatMap(l=>l.toFlatGenerationTarget(i)),...this.abstractMethods.flatMap(l=>l.toFlatGenerationTarget(i)),...this.implements.filter(l=>l.type===f.DefinitionEntity).flatMap(l=>l.toFlatGenerationTarget(i)),...this.implements.filter(l=>l.type===f.DefinitionEntity).flatMap(l=>l.toFlatGenerationTarget(i)),...this.parent.toFlatGenerationTarget(i)])}clearErrors(){return this.errors=[],this.properties.forEach(i=>i.clearErrors()),this.methods.forEach(i=>i.clearErrors()),this.abstractMethods.forEach(i=>i.clearErrors()),this}validate(){return this.errors=VS(this),{success:!0,error:null,data:null}}getErrors(){return[...this.errors,...this.properties.flatMap(a=>a.getErrors()),...this.methods.flatMap(a=>a.getErrors()),...this.abstractMethods.flatMap(a=>a.getErrors())]}getShallowErrors(){return this.errors}clone(i=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"clone-entity")),a=null,l=null,p=!0){var G,K,J;let e=Fr(a,this);const y=this.toJSON(),v=l||N.UUID.uuid();y.properties=[],y.methods=[],y.abstractMethods=[];const E=v.split("-id"),w=E[E.length-1||0]||v;y.id=v,y.version=N.UUID.uuid(),y.createdAt=(i==null?void 0:i.timestamp)||L().toISOString(),y.author=(i==null?void 0:i.author)||"1",y.previousVersion=null,y.deleted=!1;const A=or(y,e);a&&A.setParent(a,null),p&&A.subscribe(),A.initChildren(i),i==null||i.add(A,S.Added);const $=(G=this.properties)==null?void 0:G.map(ie=>ie.clone(i,A,N.UUID.uuid(),p));A.properties=$;const V=(K=this.methods)==null?void 0:K.map((ie,X)=>ie.clone(i,A,w+"-method-"+X+"-id",p));A.methods=V;const U=(J=this.abstractMethods)==null?void 0:J.map((ie,X)=>ie.clone(i,A,w+"-abstract-method-"+X+"-id",p));return A.abstractMethods=U,i==null||i.attemptAutoclose("clone-entity",this.id),A}getFunctionDeclaration(i){return this.methods.find(a=>a.id===i)}implement(i,a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"implement-definition-entity")),l){const p=Im(this,i,a,l);return a==null||a.attemptAutoclose("implement-definition-entity",this.id),p}getAllInteractiveMethods(){const i=this.implements.filter(l=>l.type===f.DefinitionEntity||l.type===f.BuiltInBaseEntity&&l.interactive);return R([...this.methods,...this.extends.flatMap(l=>l.getAllInteractiveMethods()),...i.flatMap(l=>l.getAllInteractiveMethods())])}inferFromInputs(i,a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"infer-definition-entity-from-inputs"))){const l=[],p=[],e=[],y=[];if(this.parent.type!==f.DataType||!this.parent.inferred)return a==null||a.attemptAutoclose("infer-definition-entity-from-inputs",this.id),{added:[],updated:[],removed:[],affected:[],self:this};const v=[];i.forEach(A=>{v.find(V=>ne(V,this.project)===ne(A,this.project))||v.push(A)});const E=this.properties.filter(A=>!A.dataType);v.forEach(A=>{var ie,X,ue;const $=E.find(re=>ne(re,this.project)===ne(A,this.project));if(!$)return;const U=$i(A.parent).getMasterInputWithValueWritterFromAllInstances(A),G=yn(U,a),K=G==null?void 0:G.clone(a,$,N.UUID.uuid(),!0);K&&((ie=$.dataType)==null||ie.merge(K,a),K.id!==((X=$.dataType)==null?void 0:X.id)&&K.remove({ignoreUpstream:!1},a),$.dataType&&($.dataType.metaSync({inferred:!0,like:!0},a),$.setDataType($.dataType,a),a==null||a.add($,S.Affected)));let J=null;if(A.declaration&&$.id!==((ue=A.declaration)==null?void 0:ue.id)&&(J=A.declaration),A.setDeclaration($,a),a==null||a.add(A,S.Updated),J){const{updated:re,removed:fe}=J.remove({ignoreUpstream:!1},a);p.push(...re),e.push(...fe)}});const w=[];return v.forEach(A=>{if(!A.declaration){w.push(A);return}}),w.length===0?(a==null||a.attemptAutoclose("infer-definition-entity-from-inputs",this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(w.forEach(A=>{var X,ue,re,fe;const $=this.properties.find(Y=>ne(Y,this.project)===ne(A,this.project));if($){if(A.setDeclaration($,a),!$.getDataType(a)){const H=$i(A.parent).getMasterInputWithValueWritterFromAllInstances(A),ce=yn(H),z=ce==null?void 0:ce.clone(a,$,N.UUID.uuid(),!0);z&&((X=$.dataType)==null||X.merge(z,a),z.id!==((ue=$.dataType)==null?void 0:ue.id)&&z.remove({ignoreUpstream:!1},a),$.dataType&&($.dataType.metaSync({inferred:!0,like:!0},a),$.setDataType($.dataType,a),a==null||a.add($,S.Affected)))}return}const V=ea.new(a);V.parent=this.toReference(),V.index=A.index,V.name=ne(A,this.project),V.codeName=A.codeName,V.description=A.description;const U=te(V,this.project);U.hydrateAncestors(),a==null||a.add(U,S.Added),U.setParent(this,a),U.initChildren(a);const K=$i(A.parent).getMasterInputWithValueWritterFromAllInstances(A),J=yn(K),ie=J==null?void 0:J.clone(a,U,N.UUID.uuid(),!0);return ie&&((re=U.dataType)==null||re.merge(ie,a),ie.id!==((fe=U.dataType)==null?void 0:fe.id)&&ie.remove({ignoreUpstream:!1},a),U.dataType&&(U.dataType.metaSync({inferred:!0,like:!0},a),U.setDataType(U.dataType,a),a==null||a.add(U,S.Affected))),this.addProperty(U),A.setDeclaration(U,a),a==null||a.add(A,S.Updated),U}),a==null||a.attemptAutoclose("infer-definition-entity-from-inputs",this.id),{added:R(l),updated:R(p),removed:R(e),affected:R(y),self:this})}getRawDefaultValue(){const i={};return this.properties.forEach(a=>{var p;if(!Sb(a))return;const l=jr(a.name);i[l]=((p=a.getDefaultValue())==null?void 0:p.value)||null}),i}getActiveRawDefaultValue(){const i={};return this.properties.forEach(a=>{var e;if(!Sb(a))return;const l=jr(a.name),p=(e=this.project.requestActiveDynamicValue(a))==null?void 0:e.value;i[l]=(p==null?void 0:p.value)||null}),i}};g(qt,"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}),g(qt,"type",f.DefinitionEntity),g(qt,"USER_MANAGED_PARENT_TYPES",[f.Project,f.DataType]),g(qt,"PARENT_TYPES",[...qt.USER_MANAGED_PARENT_TYPES]),g(qt,"MUTABLE_BASE_PROPERTIES",["name","codeName","description","static","abstract"]),g(qt,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),g(qt,"BASE_PROPERTIES",[...qt.MUTABLE_BASE_PROPERTIES,...qt.INMUTABLE_BASE_PROPERTIES]),g(qt,"MUTABLE_META_PROPERTIES",[...qt.MUTABLE_BASE_PROPERTIES,"x","y"]),g(qt,"INMUTABLE_META_PROPERTIES",[...qt.INMUTABLE_BASE_PROPERTIES]),g(qt,"META_PROPERTIES",[...qt.MUTABLE_META_PROPERTIES,...qt.INMUTABLE_META_PROPERTIES]),g(qt,"MUTABLE_UPSTREAM_PROPERTIES",["extends","implements"]),g(qt,"INMUTABLE_UPSTREAM_PROPERTIES",["parent"]),g(qt,"UPSTREAM_PROPERTIES",[...qt.MUTABLE_UPSTREAM_PROPERTIES,...qt.INMUTABLE_UPSTREAM_PROPERTIES]),g(qt,"MUTABLE_DOWNSTREAM_PROPERTIES",["properties","methods","abstractMethods"]),g(qt,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),g(qt,"DOWNSTREAM_PROPERTIES",[...qt.MUTABLE_DOWNSTREAM_PROPERTIES,...qt.INMUTABLE_DOWNSTREAM_PROPERTIES]),g(qt,"PROPERTIES",[...qt.META_PROPERTIES,...qt.UPSTREAM_PROPERTIES,...qt.DOWNSTREAM_PROPERTIES]);let ta=qt;function OAe(d){const u=phe(),i=d.toJSON();u.safeParse(i).success;const l=[];return vr(d.errors,l)}const cf=class cf extends Nr{constructor(i,a){super(i);g(this,"initialData");g(this,"id");g(this,"version");g(this,"name");g(this,"description",null);g(this,"type",f.BuiltInBaseEntity);g(this,"abstract",!1);g(this,"static");g(this,"properties",[]);g(this,"methods",[]);g(this,"abstractMethods",[]);g(this,"extends",[]);g(this,"interactive",!1);g(this,"errors",[]);g(this,"project");this.initialData=this.initialData||i,this.project=this.project||a,this.id=this.id||i.id,this.version=this.version||i.version,this.name=this.name||i.name,this.static=this.static||i.static,this.interactive=this.interactive||i.interactive,this.abstract=i.abstract,this.properties=this.initialData.properties.map(l=>{const p=te(l,this.project);return p.setParent(this,null),p.initChildren(null),p}),this.methods=this.initialData.methods.map(l=>{const p=te(l,this.project);return p.setParent(this,null),p.initChildren(null),p}),this.abstractMethods=this.initialData.abstractMethods.map(l=>{const p=te(l,this.project);return p.setParent(this,null),p.initChildren(null),p}),this.extends=this.initialData.extends.map(l=>te(l,this.project))}get allMethods(){return R([...this.ownDeclaredMethods,...this.allBaseMethodsFromOriginalParents])}get allProperties(){return R([...this.ownDeclaredProperties,...this.allBasePropertiesFromOriginalParents])}get allBaseMethodsFromOriginalParents(){return R([...this.extends.flatMap(i=>i.allMethods,[])])}get allBasePropertiesFromOriginalParents(){return R([...this.extends.flatMap(i=>i.allProperties,[])])}get allBasePropertiesFromExtendedAndImplementedEntities(){return R(this.extends.reduce((i,a)=>{const l=[...a.ownDeclaredProperties,...a.allBasePropertiesFromExtendedAndImplementedEntities].filter(p=>!p.abstract);return[...i,...l]},[]))}get extendedPropertiesFromOriginalParents(){return R(this.extends.reduce((i,a)=>{const l=[...a.ownDeclaredProperties,...a.extendedPropertiesFromOriginalParents].filter(p=>!p.abstract);return[...i,...l]},[]))}get implementedPropertiesFromOriginalParents(){return R([...this.extends.reduce((i,a)=>{const l=a.implementedPropertiesFromOriginalParents,p=[...a.ownDeclaredProperties].filter(e=>!!e.abstract&&!l.find(y=>y.name===e.name));return[...l,...p,...i]},[])])}get extendedProperties(){return this.properties.filter(i=>i.isExtendedProperty)}get ownDeclaredMethods(){return this.methods.filter(i=>!i.isExtendedMethod)}get ownDeclaredProperties(){return this.properties.filter(i=>!i.isExtendedProperty)}subscribe(){return this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}async APILoad(i=ve,...a){return await cf.repository.APILoad(this.id,...a),this}toFlat(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this,...this.properties.flatMap(l=>l.toFlat(i)),...this.methods.flatMap(l=>l.toFlat(i)),...this.abstractMethods.flatMap(l=>l.toFlat(i)),...this.extends.flatMap(l=>l.toFlat(i))])}toFlatIds(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.id,...this.properties.flatMap(l=>l.toFlatIds(i)),...this.methods.flatMap(l=>l.toFlatIds(i)),...this.abstractMethods.flatMap(l=>l.toFlatIds(i)),...this.extends.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,description:this.description,interactive:this.interactive,abstract:this.abstract,static:this.static,type:this.type,name:this.name}}toJSON(i=new Set){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,name:this.name,description:this.description,abstract:this.abstract,static:this.static,interactive:this.interactive,properties:this.properties.map(a=>a.toJSON(i)),methods:this.methods.map(a=>a.toJSON(i)),abstractMethods:this.abstractMethods.map(a=>a.toJSON(i)),extends:this.extends.map(a=>a.toJSON(i))})}toReference(i=ke){return{id:this.id+"--"+N.UUID.uuid()+"--ref",type:f.GenericReference,entityId:this.id,version:this.version,entityType:this.type}}toShallowJSON(i=ke){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,abstract:this.abstract,static:this.static,interactive:this.interactive,properties:this.properties.map(a=>a.toReference()),methods:this.methods.map(a=>a.toReference()),abstractMethods:this.abstractMethods.map(a=>a.toReference()),extends:this.extends.map(a=>a.toReference())}}toFlatJSON(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.toShallowJSON(),...this.properties.flatMap(l=>l.toFlatJSON(i)),...this.methods.flatMap(l=>l.toFlatJSON(i)),...this.abstractMethods.flatMap(l=>l.toFlatJSON(i))])}toGenerationTarget(){return{id:this.id,type:this.type,name:this.name,description:this.description,static:this.static,abstract:this.abstract,interactive:this.interactive,extends:this.extends.map(i=>i.id)}}toFlatGenerationTarget(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.toGenerationTarget(),...this.properties.flatMap(l=>l.toFlatGenerationTarget(i)),...this.methods.flatMap(l=>l.toFlatGenerationTarget(i)),...this.abstractMethods.flatMap(l=>l.toFlatGenerationTarget(i))])}clearErrors(){return this.errors=[],this.properties.forEach(i=>i.clearErrors()),this.methods.forEach(i=>i.clearErrors()),this.abstractMethods.forEach(i=>i.clearErrors()),this}validate(){const i=OAe(this);return this.errors=i,{success:!0,error:null,data:this.toJSON()}}getErrors(){return[...this.errors,...this.properties.flatMap(a=>a.getErrors()),...this.methods.flatMap(a=>a.getErrors()),...this.abstractMethods.flatMap(a=>a.getErrors())]}getShallowErrors(){return this.errors}implement(i,a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),null,!0,"implement-built-in-base-entity")),l){const p=Im(this,i,a,l);return a==null||a.attemptAutoclose("implement-built-in-base-entity",this.id),p}getAllInteractiveMethods(){const i=[];return this.interactive&&(i.push(...this.methods),this.extends.filter(l=>l.type===f.BuiltInBaseEntity&&l.interactive||l.type===f.PrimitiveEntity).forEach(l=>{l instanceof cf&&i.push(...l.getAllInteractiveMethods())})),R(i)}};g(cf,"repository",{APILoad:async(i,...a)=>null});let ra=cf;function CAe(d){const u=ihe(),i=d.toJSON();u.safeParse(i).success;const l=[];return vr(d.errors,l)}const Gm=class Gm extends Nr{constructor(i,a){super(i);g(this,"initialData");g(this,"id");g(this,"name");g(this,"description",null);g(this,"type",f.PrimitiveEntity);g(this,"static");g(this,"abstract");g(this,"properties",[]);g(this,"methods",[]);g(this,"abstractMethods",[]);g(this,"extends",[]);g(this,"errors",[]);g(this,"project");this.initialData=i,this.project=a,this.id=i.id,this.name=i.name,this.static=i.static,this.abstract=i.abstract,this.properties=this.initialData.properties.map(l=>{const p=te(l,this.project);return p.setParent(this,null),p.initChildren(null),p}),this.methods=this.initialData.methods.map(l=>{const p=te(l,this.project);return p.parent=this,p}),this.abstractMethods=this.initialData.abstractMethods.map(l=>{const p=te(l,this.project);return p.parent=this,p})}get allMethods(){return R([...this.ownDeclaredMethods,...this.allBaseMethodsFromOriginalParents])}get allProperties(){return R([...this.ownDeclaredProperties,...this.allBasePropertiesFromOriginalParents])}get allBaseMethodsFromOriginalParents(){return R([...this.extends.flatMap(i=>i.allMethods,[])])}get allBasePropertiesFromOriginalParents(){return R([...this.extends.flatMap(i=>i.allProperties,[])])}get allBasePropertiesFromExtendedAndImplementedEntities(){return R(this.extends.reduce((i,a)=>{const l=[...a.ownDeclaredProperties,...a.allBasePropertiesFromExtendedAndImplementedEntities].filter(p=>!p.abstract);return[...i,...l]},[]))}get extendedPropertiesFromOriginalParents(){return R(this.extends.reduce((i,a)=>{const l=[...a.ownDeclaredProperties,...a.extendedPropertiesFromOriginalParents].filter(p=>!p.abstract);return[...i,...l]},[]))}get implementedPropertiesFromOriginalParents(){return R([...this.extends.reduce((i,a)=>{const l=a.implementedPropertiesFromOriginalParents,p=[...a.ownDeclaredProperties].filter(e=>!!e.abstract&&!l.find(y=>y.name===e.name));return[...l,...p,...i]},[])])}get extendedProperties(){return this.properties.filter(i=>i.isExtendedProperty)}get ownDeclaredMethods(){return this.methods.filter(i=>!i.isExtendedMethod)}get ownDeclaredProperties(){return this.properties.filter(i=>!i.isExtendedProperty)}subscribe(){return this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}async APILoad(i=ve,...a){return await Gm.repository.APILoad(this.id,...a),this}toFlat(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this,...this.properties.flatMap(l=>l.toFlat(i)),...this.methods.flatMap(l=>l.toFlat(i)),...this.abstractMethods.flatMap(l=>l.toFlat(i))])}toFlatIds(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.id,...this.properties.flatMap(l=>l.toFlatIds(i)),...this.methods.flatMap(l=>l.toFlatIds(i)),...this.abstractMethods.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,description:this.description,static:this.static,abstract:this.abstract,type:this.type,name:this.name}}toJSON(i=new Set){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,name:this.name,description:this.description,static:this.static,abstract:this.abstract,properties:this.properties.map(a=>a.toJSON(i)),methods:this.methods.map(a=>a.toJSON(i)),abstractMethods:this.abstractMethods.map(a=>a.toJSON(i)),extends:this.extends.map(a=>a.toJSON(i))})}toReference(i=ke){return{id:this.id+"--"+N.UUID.uuid()+"--ref",type:f.GenericReference,entityId:this.id,version:this.version,entityType:this.type}}toShallowJSON(i=ke){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,abstract:this.abstract,static:this.static,properties:this.properties.map(a=>a.toReference()),methods:this.methods.map(a=>a.toReference()),abstractMethods:this.abstractMethods.map(a=>a.toReference()),extends:this.extends.map(a=>a.toReference())}}toFlatJSON(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.toShallowJSON(),...this.properties.flatMap(l=>l.toFlatJSON(i)),...this.methods.flatMap(l=>l.toFlatJSON(i)),...this.abstractMethods.flatMap(l=>l.toFlatJSON(i))])}toGenerationTarget(){return{id:this.id,type:this.type,name:this.name,description:this.description,static:this.static,abstract:this.abstract,extends:this.extends.map(i=>i.id)}}toFlatGenerationTarget(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.toGenerationTarget(),...this.properties.flatMap(l=>l.toFlatGenerationTarget(i)),...this.methods.flatMap(l=>l.toFlatGenerationTarget(i)),...this.abstractMethods.flatMap(l=>l.toFlatGenerationTarget(i))])}clearErrors(){return this.errors=[],this.properties.forEach(i=>i.clearErrors()),this.methods.forEach(i=>i.clearErrors()),this.abstractMethods.forEach(i=>i.clearErrors()),this}validate(){const i=CAe(this);return this.errors=i,{success:!0,error:null,data:this.toJSON()}}getErrors(){return[...this.errors,...this.properties.flatMap(a=>a.getErrors()),...this.methods.flatMap(a=>a.getErrors()),...this.abstractMethods.flatMap(a=>a.getErrors())]}getShallowErrors(){return this.errors}getAllInteractiveMethods(){const i=[];return i.push(...this.methods),this.extends.filter(l=>l.type===f.BuiltInBaseEntity&&l.interactive||l.type===f.PrimitiveEntity).forEach(l=>{l instanceof ra&&i.push(...l.getAllInteractiveMethods())}),R(i)}};g(Gm,"repository",{APILoad:async(i,...a)=>null});let es=Gm;function or(d,u){if(!d)throw new Error("Entity is null");const i=u.get(d.id);switch(d.type){case f.LiteralValue:return i||new Gi(d,u);case f.DefinitionEntity:return i||new ta(d,u);case f.PrimitiveEntity:return i||new es(d,u);case f.FunctionDeclaration:return i||new io(d,u);case f.GlobalEvent:return i||new ao(d,u);case f.DataType:return i||new hs(d,u);case f.Property:return i||new ea(d,u);case f.FunctionCall:return i||new Ao(d,u);case f.Condition:return i||new oo(d,u);case f.Operation:return i||new so(d,u);case f.VariableDeclaration:return i||new uo(d,u);case f.VariableInstance:return i||new lo(d,u);case f.OutputMap:return i||new mn(d,u);case f.ReturnDeclaration:return i||new Qi(d,u);case f.ArgumentDeclaration:return i||new Zn(d,u);case f.InputMap:return i||new Yn(d,u);case f.Project:return i||new N(d);case f.InstalledProject:return i||new po(d,u);case f.ActionDescriptor:return i||new wt(d,u);case f.ReturnStatement:return i||new no(d,u);case f.Loop:return i||new xi(d,u);case f.Search:return i||new co(d,u);case f.ValueDescriptor:return i||new vn(d,u);case f.BuiltInBaseEntity:return i||new ra(d,u);case f.InternalCall:return i||new fo(d,u);case f.ContinueStatement:return i||new Ci(d,u);case f.BreakStatement:return i||new ho(d,u);case f.GenericReference:return u.get(d.entityId);default:throw new Error("Invalid entity type: "+d.type)}}function te(d,u){if(!d)throw new Error("Entity is null");const i=or(d,u);return i.subscribe(),i}function $Ae(d,u){if(!d)throw new Error("Entity is null");switch(d.type){case f.LiteralValue:return Gi.fromGenerationTarget(d,u);case f.DefinitionEntity:return ta.fromGenerationTarget(d,u);case f.FunctionDeclaration:return io.fromGenerationTarget(d,u);case f.GlobalEvent:return ao.fromGenerationTarget(d,u);case f.DataType:return hs.fromGenerationTarget(d,u);case f.Property:return ea.fromGenerationTarget(d,u);case f.FunctionCall:return Ao.fromGenerationTarget(d,u);case f.Condition:return oo.fromGenerationTarget(d,u);case f.Operation:return so.fromGenerationTarget(d,u);case f.VariableDeclaration:return uo.fromGenerationTarget(d,u);case f.VariableInstance:return lo.fromGenerationTarget(d,u);case f.OutputMap:return mn.fromGenerationTarget(d,u);case f.ReturnDeclaration:return Qi.fromGenerationTarget(d,u);case f.ArgumentDeclaration:return Zn.fromGenerationTarget(d,u);case f.InputMap:return Yn.fromGenerationTarget(d,u);case f.InstalledProject:return po.fromGenerationTarget(d,u);case f.ReturnStatement:return no.fromGenerationTarget(d,u);case f.Loop:return xi.fromGenerationTarget(d,u);case f.Search:return co.fromGenerationTarget(d,u);case f.ActionDescriptor:return wt.fromGenerationTarget(d,u);case f.ValueDescriptor:return vn.fromGenerationTarget(d,u);case f.InternalCall:return fo.fromGenerationTarget(d,u);case f.ContinueStatement:return Ci.fromGenerationTarget(d,u);case f.BreakStatement:return ho.fromGenerationTarget(d,u);default:throw new Error("Invalid entity type: "+d.type)}}const ke={seenEntityMaps:new Map,seenEntities:new Set,timestamp:L().toISOString()};class US{constructor(){g(this,"initialData")}}const ve={cascade:!1},jS={APILoad:async(d,...u)=>null},PAe={APICreate:async(d,...u)=>d,APIUpdate:async(d,...u)=>d,APIDelete:async(d,...u)=>d,APIClone:async(d,...u)=>{},APILoadVersion:async(d,u,...i)=>null,...jS};class NAe{}class VAe extends US{}class LAe{}class MAe{}class BAe{}class zb{}class UAe extends zb{}class jAe extends zb{}class xAe{}class lf{static initReadsValue(u){if(u.initialData.readsValue&&u.initialData.readsValue.type!==f.GenericReference)u.readsValue=te(u.initialData.readsValue,u.project);else if(u.initialData.readsValue&&u.initialData.readsValue.type===f.GenericReference){const i=ki(u.initialData.readsValue,u.project);i&&(u.readsValue=i)}if(u.readsValue){if(mt.includes(u.readsValue.type)){let i=u.parent;Mr.includes(i.type)||(i=i.parent);const a=u.type===f.InputMap&&u.parent.type===f.Loop;a&&(i=u.parent.parent),u.readsValue.setParent(i,null),u.readsValue.initChildren(null),i&&i.type!==f.Project&&!a&&i.detachedChildren.includes(u)?i.replaceDetachedChild(u,u.readsValue):i&&i.type!==f.Project&&!a&&i.subscribeDetachedChild(u.readsValue)}u.readsValue.addValueReader(u,null)}return u.readsValue}}class df{static initWritesValues(u,i){const a=u.initialData.writesValues.reduce((p,e)=>{if(e.type===f.GenericReference||u.writesValues.some(v=>v.id===e.id))return p;const y=te(e,u.project);return y.setValueWriter(u,null),mt.includes(y.type)&&(y.setParent(i,null),y.initChildren(null)),[...p,y]},[]),l=[...u.writesValues];return u.writesValues=R([...l,...a]),u.writesValues}}class FAe{}var Vr=(d=>(d.PROJECT_INITIALIZED="project-initialized",d.CHANGE_SET_CLOSED="change-set-closed",d.EXPLICIT_DEFINITION_ENTITY_ADDED="explicit-definition-entity-added",d.EXPLICIT_DEFINITION_ENTITY_REMOVED="explicit-definition-entity-removed",d.EXPLICIT_DEFINITION_ENTITY_UPDATED="explicit-definition-entity-updated",d.PERSISTED_DEFINITION_ENTITY_ADDED="persisted-definition-entity-added",d.PERSISTED_DEFINITION_ENTITY_REMOVED="persisted-definition-entity-removed",d.PERSISTED_DEFINITION_ENTITY_UPDATED="persisted-definition-entity-updated",d.RELATIONAL_DATABASE_DEFINITION_ENTITY_ADDED="relational-database-definition-entity-added",d.RELATIONAL_DATABASE_DEFINITION_ENTITY_REMOVED="relational-database-definition-entity-removed",d.RELATIONAL_DATABASE_DEFINITION_ENTITY_UPDATED="relational-database-definition-entity-updated",d))(Vr||{});const Xb={...tb,events:new Kp},xS={requestActiveDynamicValue:d=>null,...Xb},pt=class pt extends Nr{constructor(i,a={...xS,events:new Kp}){super(i);g(this,"initialData");g(this,"id");g(this,"type",f.Project);g(this,"name",null);g(this,"description",null);g(this,"x");g(this,"y");g(this,"entities",[]);g(this,"projects",[]);g(this,"functions",[]);g(this,"events",[]);g(this,"variableDeclarations",[]);g(this,"variableInstances",[]);g(this,"conditions",[]);g(this,"operations",[]);g(this,"functionCalls",[]);g(this,"loops",[]);g(this,"searches",[]);g(this,"primitives",[]);g(this,"builtInBaseEntities",[]);g(this,"operationDeclarations",[]);g(this,"globalEventActionDescriptors",[]);g(this,"loopDeclarations",[]);g(this,"loopDeclarationsBodies",[]);g(this,"conditionDeclarations",[]);g(this,"valueDescriptors",[]);g(this,"dataTypes",[]);g(this,"project");g(this,"instances",{});g(this,"builtInInstances",{});g(this,"deletedInstances",{});g(this,"errors",[]);g(this,"references",[]);g(this,"history",[]);g(this,"undoableStackValueIndex",-1);g(this,"detachedDependents",{});g(this,"knownVersions",null);g(this,"activeVersion",!1);g(this,"initialized",!1);g(this,"startedInitialization",!1);g(this,"onCloseChangeSetCallback",null);g(this,"onAddChangeSetCallback",null);g(this,"onDiscardChangeSetCallback",null);if(this.parentContext=a,this.initialData=i,this.id=i.id,this.name=i.name,this.description=i.description,this.x=0,this.y=0,this.instances[this.id]=this,!pt.UUID)throw new Error("UUID module is already initialized. Please inject a valid UUID module.")}static get UUID(){return this.parentContext.requestModule("uuid")}static new(i=null){return{id:pt.UUID.uuid(),version:pt.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||L().toISOString(),author:(i==null?void 0:i.author)||pt.sessionAuthor,previousVersion:null,deleted:!1,type:f.Project,name:"",description:"",entities:[],functions:[],events:[],projects:[],variableDeclarations:[],variableInstances:[],conditions:[],operations:[],functionCalls:[],loops:[],searches:[]}}static validateGenerationTarget(i,a){let l=JSON.parse(JSON.stringify(i));const p=[];return p.push(...Br(l)),{errors:p,modifiedData:l}}get off(){return this.parentContext.events.off}get on(){return this.parentContext.events.on}get emit(){return this.parentContext.events.emit}async closePendingChangeSets(){const i=this.history.find(a=>a.dirty&&!a.open);i&&await this.closeChangeSet(i)}async onCloseChangeSet(i){this.onCloseChangeSetCallback=i,await this.closePendingChangeSets()}onAddChangeSet(i){this.onAddChangeSetCallback=i}onDiscardChangeSet(i){this.onDiscardChangeSetCallback=i}async closeChangeSet(i){const a=this.history.findIndex(e=>e.id===i.id),l=this.history.slice(0,a),p=l[l.length-1];if(!(p!=null&&p.dirty)&&this.onCloseChangeSetCallback){(await this.onCloseChangeSetCallback(i)).success&&(i.dirty=!1,this.emit("change-set-closed",i),this.closePendingChangeSets());return}}toLatestChangeSet(i,a,l,p=!1,e="here-this"){if(!this.history.length)return new F(this,i,a,l,p,e);const y=this.history[this.history.length-1];return y.open?y:this.addChangeSet(new F(this,i,a,l,p,e))}addChangeSet(i){var p,e;if(!this.history.length)return this.undoableStackValueIndex=sA(this.undoableStackValueIndex,this.history,i),(p=this.onAddChangeSetCallback)==null||p.call(this,i,this.undoableStackValueIndex),i;const a=this.history.find(y=>y.id===(i==null?void 0:i.id));if(a)return a;const l=this.history.find(y=>y.open);if(l)throw Me.warn("Previous still open: ",l),Me.warn("New change set: ",i),new Error(`There is already an open change-set with id '${l.id}'.`);return this.undoableStackValueIndex=sA(this.undoableStackValueIndex,this.history,i),(e=this.onAddChangeSetCallback)==null||e.call(this,i,this.undoableStackValueIndex),i}discardChangeSet(i){var l;const a=this.history.findIndex(p=>p.id===(i==null?void 0:i.id));return a!==-1&&(this.history.splice(a,1),this.undoableStackValueIndex=this.undoableStackValueIndex-1,(l=this.onDiscardChangeSetCallback)==null||l.call(this,i)),this}validateGeneratedUpdate(i){return{errors:[],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 F(this.project,pt.sessionAuthor,L().toISOString(),this,!0,"sync-dependents"))){const a=[],l=[],p=[],e=[];return Object.values(this.detachedDependents).forEach(y=>{const v=y.entity.afterAllChildrenInitialized(i);a.push(...v.updated),l.push(...v.added),p.push(...v.removed),e.push(...v.affected)}),i==null||i.attemptAutoclose("sync-dependents",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(e),self:this}}onDetachedDependencyRemoved(i,a,l){const p=[],e=[],y=[],v=[];return{updated:R(p),added:R(e),removed:R(y),affected:R(v),self:this}}onDetachedDependencyRestored(i,a,l){const p=[],e=[],y=[],v=[];return{updated:R(p),added:R(e),removed:R(y),affected:R(v),self:this}}unsubscribeFromDependencies(){return this}subscribeToDependencies(){return this}increaseVersion(i){if(i&&!L(i).isValid())throw new Error(`The shared timestamp '${i}' is not a valid ISO 8601 date string.`);return i&&L(i).isSame(L(this.createdAt))?this:(this.previousVersion=this.version,this.version=pt.UUID.uuid(),this.createdAt=L(i).toISOString()||L().toISOString(),this)}captureVersion(){var a;const i=((a=this.knownVersions)==null?void 0:a.get(this.version))||new pt(this);return i.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,i):new Map([[this.version,i]]),i.entities=[...this.entities],i.projects=[...this.projects],i.functions=[...this.functions],i.events=[...this.events],i.variableDeclarations=[...this.variableDeclarations],i.variableInstances=[...this.variableInstances],i.conditions=[...this.conditions],i.operations=[...this.operations],i.functionCalls=[...this.functionCalls],i.loops=[...this.loops],i.searches=[...this.searches],this}recursiveCaptureUpstreamVersions(i){const a=[],l=[],p=[],e=[];return{updated:R(a),added:R(l),removed:R(p),affected:R(e),self:this}}async restoreVersion(i){var v;const a=[],l=[],p=[],e=[];if(this.version===i)return{updated:R(a),added:R(l),removed:R(p),affected:R(e),self:this};if(!this.knownVersions){const E=new Map;for(const[w,A]of this.knownVersions||new Map){if(E.set(w,A),A.activeVersion=!1,A.knownVersions)for(const[$,V]of A.knownVersions)E.set($,V);A.knownVersions=null}}let y=(v=this.knownVersions)==null?void 0:v.get(i);if(!y){const E=await this.APILoadVersion({},i);if(!E)throw new Error(`Version with id '${i}' for entity with id '${this.id}' not found.`);y=new pt(E)}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.entities=y.entities,this.projects=y.projects,this.functions=y.functions,this.events=y.events,this.variableDeclarations=y.variableDeclarations,this.variableInstances=y.variableInstances,this.conditions=y.conditions,this.operations=y.operations,this.functionCalls=y.functionCalls,this.loops=y.loops,this.searches=y.searches,{updated:R(a),added:R(l),removed:R(p),affected:R(e),self:this}}updateWithShallowTransfer(i,a=this.project.addChangeSet(new F(this.project,pt.sessionAuthor,L().toISOString(),this,!0,"update-with-shallow-transfer"))){return 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.captureVersion(),this.subscribeToDependencies(),a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),this}hydrateAncestors(){const i=[],a=[],l=[],p=[];return{updated:R(i),added:R(a),removed:R(l),affected:R(p),self:this}}afterAllChildrenInitialized(i=null){const a=[],l=[],p=[],e=[];return this.initialized||(this.initialized=!0,this.emit("project-initialized",this,i)),this.validate(),this.captureVersion(),{updated:R(a),added:R(l),removed:R(p),affected:R(e),self:this}}addSelfToProject(i){const a=[],l=[],p=[],e=[];return this.subscribe(),this.subscribeToDependencies(),{updated:R(a),added:R(l),removed:R(p),affected:R(e),self:this}}get instancesList(){return Object.values(this.instances)}isOperationDeclaration(i){return this.operationDeclarations.includes(i)}isGlobalEventActionDescriptor(i){return this.globalEventActionDescriptors.includes(i)}isLoopDeclaration(i){return this.loopDeclarations.includes(i)}isConditionDeclaration(i){return this.conditionDeclarations.includes(i)}initChildren(i=this.project.addChangeSet(new F(this.project,pt.sessionAuthor,L().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.entities=this.initialData.entities.map(a=>{const l=te(a,this);return l.setParent(this,null),l.initChildren(i),l}),this.projects=this.initialData.projects.map(a=>{const l=te(a,this);return l.setParent(this,null),l.initChildren(i),l}),this.variableDeclarations=this.initialData.variableDeclarations.map(a=>{const l=te(a,this);return l.setParent(this,null),l.initChildren(i),l}),this.variableInstances=this.initialData.variableInstances.map(a=>{const l=te(a,this);return l.setParent(this,null),l.initChildren(i),l}),this.conditions=this.initialData.conditions.map(a=>{const l=te(a,this);return l.setParent(this,null),l.initChildren(i),l}),this.operations=this.initialData.operations.map(a=>{const l=te(a,this);return l.setParent(this,null),l.initChildren(i),l}),this.functions=this.initialData.functions.map(a=>{const l=te(a,this);return l.setParent(this,null),l.initChildren(i),l}),this.events=this.initialData.events.map(a=>{const l=te(a,this);return l.setParent(this,null),l.initChildren(i),l}),this.functionCalls=this.initialData.functionCalls.map(a=>{const l=te(a,this);return l.setParent(this,null),l.initChildren(i),l}),this.loops=this.initialData.loops.map(a=>{const l=te(a,this);return l.setParent(this,null),l.initChildren(i),l}),this.searches=this.initialData.searches.map(a=>{const l=te(a,this);return l.setParent(this,null),l.initChildren(i),l}),this.attachOrphanReferences(),this.subscribeToDependencies(),this.afterAllChildrenInitialized(i),i==null||i.attemptAutoclose("init-children",this.id),this)}subscribeInstance(i){return(!this.instances[i.id]||this.instances[i.id]!==i)&&(this.instances[i.id]=i),this}subscribeDeletedInstance(i){return(!this.deletedInstances[i.id]||this.deletedInstances[i.id]!==i)&&(this.deletedInstances[i.id]=i),this}subscribeBuiltInInstance(i){return(!this.builtInInstances[i.id]||this.builtInInstances[i.id]!==i)&&(this.builtInInstances[i.id]=i),this}subscribe(){return this}unsubscribe(){return this}unsubscribeInstance(i){return delete this.instances[i.id],this}unsubscribeDeletedInstance(i){return delete this.deletedInstances[i.id],this}findSubscribedBuiltInInstance(i){return this.builtInInstances[i.id]||null}get(i){return this.instances[i]||this.builtInInstances[i]||null}getDeleted(i){return this.deletedInstances[i]||null}getManaged(i){return this.getBuiltIn(i)?null:this.instances[i]||null}getBuiltIn(i){return this.builtInInstances[i]||null}findSubscribedInstanceFromReference(i){return this.instances[i.entityId]||null}findSubscribedBuiltInInstanceFromReference(i){return this.builtInInstances[i.entityId]||null}metaSync(i,a=this.project.addChangeSet(new F(this.project,pt.sessionAuthor,L().toISOString(),this,!0,"meta-sync"))){const l=Ur(this,i),p=this.toMeta();return this.name=i.name!==void 0?i.name:p.name,this.description=i.description!==void 0?i.description:p.description,this.x=i.x||p.x,this.y=i.y||p.y,super.metaSync(i),i.deleted===!0&&!p.deleted?a==null||a.add(this,S.Removed):i.deleted===!1&&p.deleted?a==null||a.add(this,S.Added):l&&(a==null||a.add(this,S.Updated)),a==null||a.attemptAutoclose("meta-sync",this.id),this}async APILoad(i=ve,...a){return await pt.repository.APILoad(this.id,...a),this}async APICreate(i=ve,...a){return await pt.repository.APICreate(this.toShallowJSON(),...a),this}async APIUpdate(i=ve,...a){return await pt.repository.APIUpdate(this.toShallowJSON(),...a),this}async APIDelete(i=ve,...a){return await pt.repository.APIDelete(this.toShallowJSON(),...a),this}async APIClone(i=ve,...a){return await pt.repository.APIClone(this.id,...a),this}async APILoadVersion(i=ve,a,...l){return await pt.repository.APILoadVersion(this.id,a,...l)}remove({ignoreUpstream:i}={ignoreUpstream:!1},a=this.project.addChangeSet(new F(this.project,pt.sessionAuthor,L().toISOString(),this,!0,"remove-entity"))){return{added:[],updated:[],removed:[],affected:[],self:this}}restore({}={},i=this.project.addChangeSet(new F(this.project,pt.sessionAuthor,L().toISOString(),this,!0,"restore-entity"))){return{added:[],updated:[],removed:[],affected:[],self:this}}getAllBuiltInIds(){const i=new Set;return[...this.primitives.flatMap(a=>a.toFlatIds(i)),...this.builtInBaseEntities.flatMap(a=>a.toFlatIds(i)),...this.operationDeclarations.flatMap(a=>a.toFlatIds(i)),...this.globalEventActionDescriptors.flatMap(a=>a.toFlatIds(i)),...this.loopDeclarations.flatMap(a=>a.toFlatIds(i)),...this.conditionDeclarations.flatMap(a=>a.toFlatIds(i)),...this.valueDescriptors.flatMap(a=>a.toFlatIds(i)),...this.dataTypes.flatMap(a=>a.toFlatIds(i))]}getAllBuiltIn(){const i=new Set;return[...this.primitives.flatMap(a=>a.toFlat(i)),...this.builtInBaseEntities.flatMap(a=>a.toFlat(i)),...this.operationDeclarations.flatMap(a=>a.toFlat(i)),...this.globalEventActionDescriptors.flatMap(a=>a.toFlat(i)),...this.loopDeclarations.flatMap(a=>a.toFlat(i)),...this.conditionDeclarations.flatMap(a=>a.toFlat(i)),...this.valueDescriptors.flatMap(a=>a.toFlat(i)),...this.dataTypes.flatMap(a=>a.toFlat(i))]}toFlat(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this,...this.entities.flatMap(l=>l.toFlat(i)),...this.functions.flatMap(l=>l.toFlat(i)),...this.events.flatMap(l=>l.toFlat(i)),...this.projects.flatMap(l=>l.toFlat(i)),...this.variableDeclarations.flatMap(l=>l.toFlat(i)),...this.variableInstances.flatMap(l=>l.toFlat(i)),...this.conditions.flatMap(l=>l.toFlat(i)),...this.operations.flatMap(l=>l.toFlat(i)),...this.functionCalls.flatMap(l=>l.toFlat(i)),...this.loops.flatMap(l=>l.toFlat(i)),...this.searches.flatMap(l=>l.toFlat(i))])}toFlatIds(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.id,...this.entities.flatMap(l=>l.toFlatIds(i)),...this.functions.flatMap(l=>l.toFlatIds(i)),...this.events.flatMap(l=>l.toFlatIds(i)),...this.projects.flatMap(l=>l.toFlatIds(i)),...this.variableDeclarations.flatMap(l=>l.toFlatIds(i)),...this.variableInstances.flatMap(l=>l.toFlatIds(i)),...this.conditions.flatMap(l=>l.toFlatIds(i)),...this.operations.flatMap(l=>l.toFlatIds(i)),...this.functionCalls.flatMap(l=>l.toFlatIds(i)),...this.loops.flatMap(l=>l.toFlatIds(i)),...this.searches.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,description:this.description,type:this.type,name:this.name}}toJSON(i=new Set){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,name:this.name,description:this.description,entities:this.entities.map(a=>a.toJSON(i)),variableDeclarations:this.variableDeclarations.map(a=>a.toJSON(i)),variableInstances:this.variableInstances.map(a=>a.toJSON(i)),conditions:this.conditions.map(a=>a.toJSON(i)),operations:this.operations.map(a=>a.toJSON(i)),loops:this.loops.map(a=>a.toJSON(i)),searches:this.searches.map(a=>a.toJSON(i)),functions:this.functions.map(a=>a.toJSON(i)),events:this.events.map(a=>a.toJSON(i)),projects:this.projects.map(a=>a.toJSON(i)),functionCalls:this.functionCalls.map(a=>a.toJSON(i))})}toJSONClone(i={uuidStrategy:"uuid"}){const a=new Map,l=new Set,p=this.getAllBuiltInIds();return Object.keys(this.instances).forEach(e=>{if(p.includes(e)){a.set(e,e);return}a.set(e,pt.UUID.uuid())}),l.add(this.id),{id:a.get(this.id),version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,entities:this.entities.map(e=>e.toJSONClone({...i,seenEntityMaps:a,seenEntities:l,newId:null})),projects:this.projects.map(e=>e.toJSONClone({...i,seenEntityMaps:a,seenEntities:l,newId:null})),variableDeclarations:this.variableDeclarations.map(e=>e.toJSONClone({...i,seenEntityMaps:a,seenEntities:l,newId:null})),variableInstances:this.variableInstances.map(e=>e.toJSONClone({...i,seenEntityMaps:a,seenEntities:l,newId:null})),conditions:this.conditions.map(e=>e.toJSONClone({...i,seenEntityMaps:a,seenEntities:l,newId:null})),operations:this.operations.map(e=>e.toJSONClone({...i,seenEntityMaps:a,seenEntities:l,newId:null})),functions:this.functions.map(e=>e.toJSONClone({...i,seenEntityMaps:a,seenEntities:l,newId:null})),events:this.events.map(e=>e.toJSONClone({...i,seenEntityMaps:a,seenEntities:l,newId:null})),functionCalls:this.functionCalls.map(e=>e.toJSONClone({...i,seenEntityMaps:a,seenEntities:l,newId:null})),loops:this.loops.map(e=>e.toJSONClone({...i,seenEntityMaps:a,seenEntities:l,newId:null})),searches:this.searches.map(e=>e.toJSONClone({...i,seenEntityMaps:a,seenEntities:l,newId:null}))}}toReference(i=ke){var l;let a=this.id;return(l=i.seenEntityMaps)!=null&&l.has(this.id)&&(a=i.seenEntityMaps.get(this.id)),{id:a+"--"+pt.UUID.uuid()+"--ref",type:f.GenericReference,entityId:a,version:this.version,entityType:this.type}}toShallowJSON(i=ke){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,name:this.name,description:this.description,entities:this.entities.map(p=>p.toReference(i)),functions:this.functions.map(p=>p.toReference(i)),events:this.events.map(p=>p.toReference(i)),projects:this.projects.map(p=>p.toReference(i)),variableDeclarations:this.variableDeclarations.map(p=>p.toReference(i)),variableInstances:this.variableInstances.map(p=>p.toReference(i)),conditions:this.conditions.map(p=>p.toReference(i)),operations:this.operations.map(p=>p.toReference(i)),functionCalls:this.functionCalls.map(p=>p.toReference(i)),loops:this.loops.map(p=>p.toReference(i)),searches:this.searches.map(p=>p.toReference(i))}}toFlatJSON(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.toShallowJSON(),...this.entities.flatMap(l=>l.toFlatJSON(i)),...this.functions.flatMap(l=>l.toFlatJSON(i)),...this.events.flatMap(l=>l.toFlatJSON(i)),...this.projects.flatMap(l=>l.toFlatJSON(i)),...this.variableDeclarations.flatMap(l=>l.toFlatJSON(i)),...this.variableInstances.flatMap(l=>l.toFlatJSON(i)),...this.conditions.flatMap(l=>l.toFlatJSON(i)),...this.operations.flatMap(l=>l.toFlatJSON(i)),...this.functionCalls.flatMap(l=>l.toFlatJSON(i)),...this.loops.flatMap(l=>l.toFlatJSON(i)),...this.searches.flatMap(l=>l.toFlatJSON(i))])}toGenerationTarget(){return{id:this.id,type:this.type,name:this.name,description:this.description}}toFlatGenerationTarget(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[...this.entities.flatMap(l=>l.toFlatGenerationTarget(i)),...this.functions.flatMap(l=>l.toFlatGenerationTarget(i)),...this.events.flatMap(l=>l.toFlatGenerationTarget(i)),...this.projects.flatMap(l=>l.toFlatGenerationTarget(i)),...this.variableDeclarations.flatMap(l=>l.toFlatGenerationTarget(i)),...this.variableInstances.flatMap(l=>l.toFlatGenerationTarget(i)),...this.conditions.flatMap(l=>l.toFlatGenerationTarget(i)),...this.operations.flatMap(l=>l.toFlatGenerationTarget(i)),...this.functionCalls.flatMap(l=>l.toFlatGenerationTarget(i)),...this.loops.flatMap(l=>l.toFlatGenerationTarget(i)),...this.searches.flatMap(l=>l.toFlatGenerationTarget(i))])}clearErrors(){return this.errors=[],this.entities.forEach(i=>i.clearErrors()),this.projects.forEach(i=>i.clearErrors()),this.functions.forEach(i=>i.clearErrors()),this.events.forEach(i=>i.clearErrors()),this.variableDeclarations.forEach(i=>i.clearErrors()),this.variableInstances.forEach(i=>i.clearErrors()),this.conditions.forEach(i=>i.clearErrors()),this.operations.forEach(i=>i.clearErrors()),this.functionCalls.forEach(i=>i.clearErrors()),this.loops.forEach(i=>i.clearErrors()),this.searches.forEach(i=>i.clearErrors()),this}validate(){const i=Lye(),a=this.toJSON();return i.safeParse(a),this.validateChildren(),{success:!0,error:null,data:a}}validateChildren(){this.entities.forEach(i=>i.validate()),this.projects.forEach(i=>i.validate()),this.functions.forEach(i=>i.validate()),this.events.forEach(i=>i.validate()),this.variableDeclarations.forEach(i=>i.validate()),this.variableInstances.forEach(i=>i.validate()),this.conditions.forEach(i=>i.validate()),this.operations.forEach(i=>i.validate()),this.functionCalls.forEach(i=>i.validate()),this.loops.forEach(i=>i.validate()),this.searches.forEach(i=>i.validate())}getErrors(){return[...this.errors,...this.entities.flatMap(a=>a.getErrors()),...this.projects.flatMap(a=>a.getErrors()),...this.functions.flatMap(a=>a.getErrors()),...this.events.flatMap(a=>a.getErrors()),...this.variableDeclarations.flatMap(a=>a.getErrors()),...this.variableInstances.flatMap(a=>a.getErrors()),...this.conditions.flatMap(a=>a.getErrors()),...this.operations.flatMap(a=>a.getErrors()),...this.functionCalls.flatMap(a=>a.getErrors()),...this.loops.flatMap(a=>a.getErrors()),...this.searches.flatMap(a=>a.getErrors())]}getShallowErrors(){return this.errors}clone(){return this}getDefinitionEntity(i){return this.entities.find(a=>a.id===i)||null}addDefinitionEntity(i){return this.entities.includes(i)||this.entities.push(i),i}addFunctionDeclaration(i){return this.functions.includes(i)||this.functions.push(i),i}addFunctionCall(i){return this.functionCalls.includes(i)||this.functionCalls.push(i),i}addVariableDeclaration(i){return this.variableDeclarations.includes(i)||this.variableDeclarations.push(i),i}addVariableInstance(i){return this.variableInstances.includes(i)||this.variableInstances.push(i),i}addInstalledProject(i){return this.projects.includes(i)||this.projects.push(i),this}addGlobalEvent(i){return this.events.includes(i)||this.events.push(i),this}addCondition(i){return this.conditions.includes(i)||this.conditions.push(i),this}addOperation(i){return this.operations.includes(i)||this.operations.push(i),this}addLoop(i){return this.loops.includes(i)||this.loops.push(i),this}addSearch(i){return this.searches.includes(i)||this.searches.push(i),this}removeDefinitionEntity(i){const a=this.entities.findIndex(l=>l.id===i.id);if(a>-1){const l=this.entities[a];return this.entities.splice(a,1),l}return null}removeCondition(i){const a=this.conditions.findIndex(l=>l.id===i.id);if(a>-1){const l=this.conditions[a];return this.conditions.splice(a,1),l}return null}removeOperation(i){const a=this.operations.findIndex(l=>l.id===i.id);if(a>-1){const l=this.operations[a];return this.operations.splice(a,1),l}return null}removeLoop(i){const a=this.loops.findIndex(l=>l.id===i.id);if(a>-1){const l=this.loops[a];return this.loops.splice(a,1),l}return null}removeSearch(i){const a=this.searches.findIndex(l=>l.id===i.id);if(a>-1){const l=this.searches[a];return this.searches.splice(a,1),l}return null}removeFunctionCall(i){const a=this.functionCalls.findIndex(l=>l.id===i.id);if(a>-1){const l=this.functionCalls[a];return this.functionCalls.splice(a,1),l}return null}removeVariableInstance(i){const a=this.variableInstances.findIndex(l=>l.id===i.id);if(a>-1){const l=this.variableInstances[a];return this.variableInstances.splice(a,1),l}return null}removeVariableDeclaration(i){const a=this.variableDeclarations.findIndex(l=>l.id===i.id);if(a>-1){const l=this.variableDeclarations[a];return this.variableDeclarations.splice(a,1),l}return null}removeFunctionDeclaration(i){const a=this.functions.findIndex(l=>l.id===i.id);if(a>-1){const l=this.functions[a];return this.functions.splice(a,1),l}return null}removeInstalledProject(i){const a=this.projects.findIndex(l=>l.id===i.id);if(a>-1){const l=this.projects[a];return this.projects.splice(a,1),l}return null}removeGlobalEvent(i){const a=this.events.findIndex(l=>l.id===i.id);if(a>-1){const l=this.events[a];return this.events.splice(a,1),l}return null}removeTopLevelVariableDeclaration(i){if(i.type!==f.VariableDeclaration)return null;const a=this.variableDeclarations.findIndex(l=>l.id===i.id);if(a>-1){const l=this.variableDeclarations[a];return this.variableDeclarations.splice(a,1),l}return null}getEntryPoints(){return[...this.functions,...this.events,...this.entities.flatMap(a=>a.methods)]}getTerminationStatements(){return[...this.getEntryPoints().reduce((a,l)=>{const p=_t(l);return[...a,...p.filter(e=>e.type===f.ReturnStatement||e.type===f.ContinueStatement||e.type===f.BreakStatement)]},[])]}getFunctionDeclaration(i){return this.functions.find(a=>a.id===i)||null}getConditions(){return[...this.conditions,...this.getEntryPoints().reduce((a,l)=>{const p=_t(l);return[...a,...p.filter(e=>e.type===f.Condition)]},[]),...this.functionCalls.reduce((a,l)=>{const p=_t(l);return[...a,...p.filter(e=>e.type===f.Condition)]},[]),...this.operations.reduce((a,l)=>{const p=_t(l);return[...a,...p.filter(e=>e.type===f.Condition)]},[]),...this.loops.reduce((a,l)=>{const p=_t(l);return[...a,...p.filter(e=>e.type===f.Condition)]},[]),...this.searches.reduce((a,l)=>{const p=_t(l);return[...a,...p.filter(e=>e.type===f.Condition)]},[])]}getOperations(){return[...this.operations,...this.getEntryPoints().reduce((a,l)=>{const p=_t(l);return[...a,...p.filter(e=>e.type===f.Operation)]},[]),...this.functionCalls.reduce((a,l)=>{const p=_t(l);return[...a,...p.filter(e=>e.type===f.Operation)]},[]),...this.conditions.reduce((a,l)=>{const p=_t(l);return[...a,...p.filter(e=>e.type===f.Operation)]},[]),...this.loops.reduce((a,l)=>{const p=_t(l);return[...a,...p.filter(e=>e.type===f.Operation)]},[]),...this.searches.reduce((a,l)=>{const p=_t(l);return[...a,...p.filter(e=>e.type===f.Operation)]},[])]}getFunctionCalls(){return[...this.functionCalls,...this.getEntryPoints().reduce((a,l)=>{const p=_t(l);return[...a,...p.filter(e=>e.type===f.FunctionCall)]},[]),...this.conditions.reduce((a,l)=>{const p=_t(l);return[...a,...p.filter(e=>e.type===f.FunctionCall)]},[]),...this.operations.reduce((a,l)=>{const p=_t(l);return[...a,...p.filter(e=>e.type===f.FunctionCall)]},[]),...this.loops.reduce((a,l)=>{const p=_t(l);return[...a,...p.filter(e=>e.type===f.FunctionCall)]},[]),...this.searches.reduce((a,l)=>{const p=_t(l);return[...a,...p.filter(e=>e.type===f.FunctionCall)]},[])]}getVariables(){return[...this.variableDeclarations,...this.getEntryPoints().reduce((a,l)=>{const p=yr(l);return[...a,...p]},[]),...this.functionCalls.reduce((a,l)=>{const p=yr(l);return[...a,...p]},[]),...this.conditions.reduce((a,l)=>{const p=yr(l);return[...a,...p]},[]),...this.operations.reduce((a,l)=>{const p=yr(l);return[...a,...p]},[]),...this.loops.reduce((a,l)=>{const p=yr(l);return[...a,...p]},[]),...this.searches.reduce((a,l)=>{const p=yr(l);return[...a,...p]},[])]}getVariableInstances(){return[...this.variableInstances,...this.entities.reduce((a,l)=>[...a,...l.methods.flatMap(p=>{const y=_t(p).filter(v=>v.type===f.VariableInstance);return[...a,...y]})],[]),...this.getEntryPoints().reduce((a,l)=>{const e=yr(l).filter(y=>y.type===f.VariableInstance);return[...a,...e]},[]),...this.functionCalls.reduce((a,l)=>{const e=yr(l).filter(y=>y.type===f.VariableInstance);return[...a,...e]},[]),...this.conditions.reduce((a,l)=>{const e=yr(l).filter(y=>y.type===f.VariableInstance);return[...a,...e]},[]),...this.operations.reduce((a,l)=>{const e=yr(l).filter(y=>y.type===f.VariableInstance);return[...a,...e]},[]),...this.loops.reduce((a,l)=>{const e=yr(l).filter(y=>y.type===f.VariableInstance);return[...a,...e]},[]),...this.searches.reduce((a,l)=>{const e=yr(l).filter(y=>y.type===f.VariableInstance);return[...a,...e]},[])]}getVariableDeclarations(){return R([...this.variableDeclarations,...this.entities.reduce((a,l)=>[...a,...l.methods.flatMap(p=>{const y=_t(p).filter(v=>v.type===f.VariableDeclaration);return[...a,...y]})],[]),...this.getEntryPoints().reduce((a,l)=>{const e=yr(l).filter(y=>y.type===f.VariableDeclaration);return[...a,...e]},[]),...this.functionCalls.reduce((a,l)=>{const e=yr(l).filter(y=>y.type===f.VariableDeclaration);return[...a,...e]},[]),...this.conditions.reduce((a,l)=>{const e=yr(l).filter(y=>y.type===f.VariableDeclaration);return[...a,...e]},[]),...this.operations.reduce((a,l)=>{const e=yr(l).filter(y=>y.type===f.VariableDeclaration);return[...a,...e]},[]),...this.loops.reduce((a,l)=>{const e=yr(l).filter(y=>y.type===f.VariableDeclaration);return[...a,...e]},[]),...this.searches.reduce((a,l)=>{const e=yr(l).filter(y=>y.type===f.VariableDeclaration);return[...a,...e]},[])])}getLoops(){return[...this.loops,...this.getEntryPoints().reduce((a,l)=>{const p=_t(l);return[...a,...p.filter(e=>e.type===f.Loop)]},[]),...this.functionCalls.reduce((a,l)=>{const p=_t(l);return[...a,...p.filter(e=>e.type===f.Loop)]},[]),...this.conditions.reduce((a,l)=>{const p=_t(l);return[...a,...p.filter(e=>e.type===f.Loop)]},[]),...this.operations.reduce((a,l)=>{const p=_t(l);return[...a,...p.filter(e=>e.type===f.Loop)]},[]),...this.searches.reduce((a,l)=>{const p=_t(l);return[...a,...p.filter(e=>e.type===f.Loop)]},[])]}getSearches(){return[...this.searches,...this.getEntryPoints().reduce((a,l)=>{const p=_t(l);return[...a,...p.filter(e=>e.type===f.Search)]},[]),...this.functionCalls.reduce((a,l)=>{const p=_t(l);return[...a,...p.filter(e=>e.type===f.Search)]},[]),...this.conditions.reduce((a,l)=>{const p=_t(l);return[...a,...p.filter(e=>e.type===f.Search)]},[]),...this.operations.reduce((a,l)=>{const p=_t(l);return[...a,...p.filter(e=>e.type===f.Search)]},[]),...this.loops.reduce((a,l)=>{const p=_t(l);return[...a,...p.filter(e=>e.type===f.Search)]},[])]}attachOrphanReferences(){const i=this.getVariableInstances(),a=this.getVariableDeclarations();return i.forEach(l=>{if(!l.declaration){const p=l.initialData,e=p.declaration.entityId||p.declaration.id,y=a.find(v=>v.id===e);y&&l.setDeclaration(y)}}),this}getBuiltInPersistedEntity(){return this.builtInBaseEntities.find(i=>i.name===Ue.PERSISTED_ENTITY)||null}requestActiveDynamicValue(i){var l,p;const a=(p=(l=this.parentContext).requestActiveDynamicValue)==null?void 0:p.call(l,i);if(!a){const e=i.getDefaultValue();return e?{value:e,type:Ae.DefaultValue,inheritanceLink:null,valueOwner:i}:null}return a||null}requestModule(i){if(this.parentContext.requestModule){const a=this.parentContext.requestModule(i);return!a&&i==="uuid"?Yu:a||null}return i==="uuid"?Yu:null}undo(){Me.log("Undoing, from: ",this.undoableStackValueIndex),this.undoableStackValueIndex=this.undoableStackValueIndex-1,Me.log("To: ",this.undoableStackValueIndex);const i=this.history[this.undoableStackValueIndex+1],a=this.history[this.undoableStackValueIndex];return Me.log("Current change set: ",i==null?void 0:i.toJSON()),Me.log("Change set to restore: ",a==null?void 0:a.toJSON()),rA(i||"initial",a||"initial",this)}redo(){Me.log("Undoing, from: ",this.undoableStackValueIndex),this.undoableStackValueIndex=this.undoableStackValueIndex+1,Me.log("To: ",this.undoableStackValueIndex);const i=this.history[this.undoableStackValueIndex-1],a=this.history[this.undoableStackValueIndex];return Me.log("Current change set: ",i==null?void 0:i.toJSON()),Me.log("Change set to restore: ",a.toJSON()),rA(i||"initial",a||"initial",this)}applyExternalChangeSet(i){const a=i.payload,l=this.addChangeSet(new F(this,i.userAuthor,i.emittedAt,this)),p=a.updated[this.id];if(!p)throw new Error("Project root not found in change set transfer. Cannot apply changes.");const e={...a.added,...a.updated,...a.removed},y=[...Object.keys(a.added),...Object.keys(a.updated),...Object.keys(a.removed)];y.forEach(E=>{var w;if(!e[E]){Me.warn(`Entity '${E}' not found in change set transfer. Cannot apply changes.`);const A=(w=this.get(E))==null?void 0:w.toShallowJSON();throw A?Me.warn("Entity in project: ",A):Me.warn("Entity not in project"),new Error(`Entity '${E}' not found in change set transfer. Cannot apply changes.`)}});const v=new Qn(p);return v.flatRecord=e,v.order=y,v.orderEntities(),Me.log("All entities: ",v.order.map((E,w)=>`${w+1}: ${e[E].type} - ${E}`).join(`,
|
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.6411",
|
|
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",
|