@elyx-code/project-logic-tree 0.0.6547 → 0.0.6548
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +5 -1
- package/dist/index.umd.cjs +3 -3
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -54435,7 +54435,7 @@ Specifically for return statements the parent needs to always be the 'function-d
|
|
|
54435
54435
|
self: this
|
|
54436
54436
|
};
|
|
54437
54437
|
const a = [], l = [], f = [], e = [];
|
|
54438
|
-
this.initialized = !0, !this.dataType || this.dataType.inferred;
|
|
54438
|
+
this.initialized = !0, !this.dataType || this.dataType.inferred, this.parent.implements && !this.implements && (this.setImplements(this.parent.implements, i), a.push(this));
|
|
54439
54439
|
const {
|
|
54440
54440
|
updated: h,
|
|
54441
54441
|
added: v,
|
|
@@ -112742,6 +112742,8 @@ Specifically for break statements the parent needs to always be the 'loop' entit
|
|
|
112742
112742
|
var l;
|
|
112743
112743
|
if ((!this.dataType || this.dataType.inferred) && this.project.initialized, this.dataType)
|
|
112744
112744
|
return i == null || i.attemptAutoclose("get-data-type", this.id), this.dataType;
|
|
112745
|
+
if (this.parent.dataType)
|
|
112746
|
+
return i == null || i.attemptAutoclose("get-data-type", this.id), this.parent.dataType;
|
|
112745
112747
|
const a = (l = this.implements) == null ? void 0 : l.getDataType(i);
|
|
112746
112748
|
return i == null || i.attemptAutoclose("get-data-type", this.id), a || null;
|
|
112747
112749
|
}
|
|
@@ -114227,6 +114229,8 @@ Specifically for continue statements the parent needs to always be the 'loop' en
|
|
|
114227
114229
|
var l;
|
|
114228
114230
|
if ((!this.dataType || this.dataType.inferred) && this.project.initialized, this.dataType)
|
|
114229
114231
|
return i == null || i.attemptAutoclose("get-data-type", this.id), this.dataType;
|
|
114232
|
+
if (this.parent.dataType)
|
|
114233
|
+
return i == null || i.attemptAutoclose("get-data-type", this.id), this.parent.dataType;
|
|
114230
114234
|
const a = (l = this.implements) == null ? void 0 : l.getDataType(i);
|
|
114231
114235
|
return i == null || i.attemptAutoclose("get-data-type", this.id), a || null;
|
|
114232
114236
|
}
|
package/dist/index.umd.cjs
CHANGED
|
@@ -46,7 +46,7 @@ If an entity is called by another, they must be in the same scope, which means t
|
|
|
46
46
|
You shouldn't have to manually update a 'parent' property. The equivalent result is to change its callers, the value writters of its inputs, or the value readers of its outputs.`})),{errors:a,modifiedData:i}}subscribeDependents(i){return i.forEach(a=>{this.detachedDependents[a.entity.id]||(this.detachedDependents[a.entity.id]=a)}),this}unsubscribeDependents(i){return i.forEach(a=>{this.detachedDependents[a.entity.id]&&delete this.detachedDependents[a.entity.id]}),this}syncDependents(i=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,"sync-dependents"))){const a=[],l=[],f=[],e=[];return Object.values(this.detachedDependents).forEach(y=>{const v=y.entity.afterAllChildrenInitialized(i);a.push(...v.updated),l.push(...v.added),f.push(...v.removed),e.push(...v.affected)}),i==null||i.attemptAutoclose("sync-dependents",this.id),{updated:g(a),added:g(l),removed:g(f),affected:g(e),self:this}}onDetachedDependencyRemoved(i,a,l){const f=[],e=[],y=[],v=[];if(a==="parent"){const{updated:T,added:A,removed:I}=this.remove({ignoreUpstream:!1},l);f.push(...T),e.push(...A),y.push(...I)}return{updated:g(f),added:g(e),removed:g(y),affected:g(v),self:this}}onDetachedDependencyRestored(i,a,l){const f=[],e=[],y=[],v=[];if(a==="parent"){const{updated:T,added:A,removed:I}=this.restore({},l);f.push(...T),e.push(...A),y.push(...I)}return{updated:g(f),added:g(e),removed:g(y),affected:g(v),self:this}}unsubscribeFromDependencies(){var i;return(i=this.parent)==null||i.unsubscribeDependents([{entity:this,field:"parent"}]),this}subscribeToDependencies(){var i;return(i=this.parent)==null||i.subscribeDependents([{entity:this,field:"parent"}]),this}increaseVersion(i){if(i&&!B(i).isValid())throw new Error(`The shared timestamp '${i}' is not a valid ISO 8601 date string.`);return i&&B(i).isSame(B(this.createdAt))?this:(this.previousVersion=this.version,this.version=V.UUID.uuid(),this.createdAt=B(i).toISOString()||B().toISOString(),this)}captureVersion(){var a;const i=((a=this.knownVersions)==null?void 0:a.get(this.version))||new 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.calledBySuccess=[...this.calledBySuccess],i.calledByError=[...this.calledByError],i.calledByEntry=[...this.calledByEntry],i.declaration=this.declaration,i.parent=this.parent,this}recursiveCaptureUpstreamVersions(i){const a=[],l=[],f=[],e=[];if(this.parent){this.parent.increaseVersion(i);const y=this.parent.recursiveCaptureUpstreamVersions(i);a.push(this.parent,...y.updated),l.push(...y.added),f.push(...y.removed)}return{updated:g(a),added:g(l),removed:g(f),affected:g(e),self:this}}async restoreVersion(i){var v;const a=[],l=[],f=[],e=[];if(this.version===i)return{updated:g(a),added:g(l),removed:g(f),affected:g(e),self:this};if(!this.knownVersions){const T=new Map;for(const[A,I]of this.knownVersions||new Map){if(T.set(A,I),I.activeVersion=!1,I.knownVersions)for(const[O,L]of I.knownVersions)T.set(O,L);I.knownVersions=null}}let y=(v=this.knownVersions)==null?void 0:v.get(i);if(!y){const T=await this.APILoadVersion({},i);if(!T)throw new Error(`Version with id '${i}' for entity with id '${this.id}' not found.`);y=new qt(T,this.project)}return this.metaSync(y.toShallowJSON(),null),this.previousVersion=y.previousVersion,this.version=y.version,this.createdAt=y.createdAt,this.author=y.author,this.deleted=y.deleted,this.inputs=y.inputs,this.outputs=y.outputs,this.error=y.error,this.successCalls=y.successCalls,this.errorCalls=y.errorCalls,this.calledBySuccess=y.calledBySuccess,this.calledByError=y.calledByError,this.calledByEntry=y.calledByEntry,this.declaration=y.declaration,this.parent=y.parent,{updated:g(a),added:g(l),removed:g(f),affected:g(e),self:this}}updateWithShallowTransfer(i,a=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,P.UpdateWithShallowTransfer))){if(!this.checkCanEdit(this))return J.warn(`[updateWithShallowTransfer] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),a==null||a.attemptAutoclose(P.UpdateWithShallowTransfer,this.id),this;if(this.metaSync(i,a),this.version=i.version,this.createdAt=i.createdAt,this.author=i.author,this.deleted=i.deleted,this.previousVersion=i.previousVersion,this.unsubscribeFromDependencies(),i.parent){const l=X(i.parent),f=this.project.get(l),e=this.parent;if(e&&e.id!==(f==null?void 0:f.id)&&this.removeFromParent(a),f)this.setParent(f,a);else throw a==null||a.attemptAutoclose(P.UpdateWithShallowTransfer,this.id),new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw a==null||a.attemptAutoclose(P.UpdateWithShallowTransfer,this.id),new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(i.declaration){const l=X(i.declaration),f=this.project.get(l);f&&this.setDeclaration(f)}return i.calledByEntry.forEach(l=>{const f=X(l),e=this.project.get(f);e&&(this.addEntryCaller(e,a),e.addCall(this,a))}),[...this.calledByEntry].forEach(l=>{i.calledByEntry.find(e=>X(e)===l.id)||(this.removeCaller(l,a),l.removeCall(this,a))}),i.calledBySuccess.forEach(l=>{const f=X(l),e=this.project.get(f);e&&(this.addSuccessCaller(e,a),e.addSuccessCall(this,a))}),[...this.calledBySuccess].forEach(l=>{i.calledBySuccess.find(e=>X(e)===l.id)||(this.removeCaller(l,a),l.removeCall(this,a))}),i.calledByError.forEach(l=>{const f=X(l),e=this.project.get(f);e&&(this.addErrorCaller(e,a),e.addErrorCall(this,a))}),[...this.calledBySuccess].forEach(l=>{i.calledBySuccess.find(e=>X(e)===l.id)||(this.removeCaller(l,a),l.removeCall(this,a))}),this.captureVersion(),this.subscribeToDependencies(),a==null||a.attemptAutoclose(P.UpdateWithShallowTransfer,this.id),this}hydrateAncestors(){const i=[],a=[],l=[],f=[];if(this.initialData.parent){const e=X(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=X(this.initialData.declaration),y=this.project.get(e);y&&(this.setDeclaration(y),i.push(y))}return this.initialData.calledByEntry.forEach(e=>{const y=X(e),v=this.project.get(y);v&&this.addEntryCaller(v,null)}),this.initialData.calledBySuccess.forEach(e=>{const y=X(e),v=this.project.get(y);v&&this.addSuccessCaller(v,null)}),this.initialData.calledByError.forEach(e=>{const y=X(e),v=this.project.get(y);v&&this.addErrorCaller(v,null)}),{updated:g(i),added:g(a),removed:g(l),affected:g(f),self:this}}afterAllChildrenInitialized(i=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,P.AfterAllChildrenInitialized))){if(!this.checkCanEdit(this))return J.warn(`[afterAllChildrenInitialized] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(P.AfterAllChildrenInitialized,this.id),{updated:[],added:[],removed:[],affected:[],self:this};const a=[],l=[],f=[],e=[];this.initialized=!0;const{updated:y,added:v,removed:T}=this.syncInputs(i),{updated:A,added:I,removed:O}=this.syncOutputs(i),{updated:L,added:M,removed:j}=this.declaration.syncOperationInstance(this,i);return a.push(...y,...A,...L),l.push(...v,...I,...L),f.push(...T,...O,...L),this.captureVersion(),i==null||i.attemptAutoclose(P.AfterAllChildrenInitialized,this.id),{updated:g(a),added:g(l),removed:g(f),affected:g(e),self:this}}addSelfToProject(i=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,"add-self-to-project"))){const a=[this],l=[],f=[],e=[];return this.parent===this.project&&this.project.addOperation(this),this.successCalls.forEach(y=>{y.addSuccessCaller(this,i),a.push(y)}),this.errorCalls.forEach(y=>{y.addErrorCaller(this,i),a.push(y)}),this.calledBySuccess.forEach(y=>{y.addSuccessCall(this,i),a.push(y)}),this.calledByError.forEach(y=>{y.addErrorCall(this,i),a.push(y)}),this.calledByEntry.forEach(y=>{y.addCall(this,i),a.push(y)}),this.subscribe(),this.subscribeToDependencies(),i==null||i.attemptAutoclose("add-self-to-project",this.id),{updated:g(a),added:g(l),removed:g(f),affected:g(e),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}removeInput(i,a=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,P.RemoveInput))){if(!this.checkCanEdit(this))return J.warn(`[removeInput] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),a==null||a.attemptAutoclose(P.RemoveInput,this.id),this;const l=this.inputs.findIndex(f=>f.id===i.id);return l>-1&&(this.inputs.splice(l,1),a&&(a==null||a.add(this,K.Affected))),a==null||a.attemptAutoclose(P.RemoveInput,this.id),this}addInput(i,a=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,P.AddInput))){return this.checkCanEdit(this)?this.inputs.includes(i)?(a==null||a.attemptAutoclose(P.AddInput,this.id),this):(this.inputs.push(i),a==null||a.add(this,K.Affected),a==null||a.attemptAutoclose(P.AddInput,this.id),this):(J.warn(`[addInput] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),a==null||a.attemptAutoclose(P.AddInput,this.id),this)}addOutput(i,a=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,"add-output"))){return this.checkCanEdit(this)?this.outputs.includes(i)?(a==null||a.attemptAutoclose("add-output",this.id),this):(this.outputs.push(i),a==null||a.add(this,K.Affected),a==null||a.attemptAutoclose("add-output",this.id),this):(J.warn(`[addOutput] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),a==null||a.attemptAutoclose("add-output",this.id),this)}removeOutput(i,a=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,"remove-output"))){if(!this.checkCanEdit(this))return J.warn(`[removeOutput] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),a==null||a.attemptAutoclose("remove-output",this.id),this;const l=this.outputs.findIndex(f=>f.id===i.id);return l>-1&&(this.outputs.splice(l,1),a&&(a==null||a.add(this,K.Affected))),a==null||a.attemptAutoclose("remove-output",this.id),this}addValueReader(i,a=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,P.AddValueReader))){return this.checkCanEditWithCounterpartAndSideEffects(this,i,P.AddValueReader,a)?this.writesValues.includes(i)?(a==null||a.attemptAutoclose(P.AddValueReader,this.id),this):(this.writesValues.push(i),a==null||a.add(this,K.Affected),this):this}removeValueReader(i,a=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,P.RemoveValueReader))){return this.checkCanEditWithCounterpartAndSideEffects(this,i,P.RemoveValueReader,a)?this.writesValues.includes(i)?(this.writesValues=this.writesValues.filter(l=>l.id!==i.id),a==null||a.add(this,K.Affected),this):(a==null||a.attemptAutoclose(P.RemoveValueReader,this.id),this):this}addSuccessCaller(i,a=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,P.AddSuccessCaller)),l=!1){return this.checkCanEditWithCounterpartAndSideEffects(this,i,P.AddSuccessCaller,a)?(this.calledBySuccess.find(f=>f.id===i.id)||(this.calledBySuccess.push(i),a==null||a.add(this,K.Updated),l&&Ye(this,a)),a==null||a.attemptAutoclose(P.AddSuccessCaller,this.id),this):this}addErrorCaller(i,a=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,P.AddErrorCaller)),l=!1){return this.checkCanEditWithCounterpartAndSideEffects(this,i,P.AddErrorCaller,a)?(this.calledByError.find(f=>f.id===i.id)||(this.calledByError.push(i),a==null||a.add(this,K.Updated),l&&Ye(this,a)),a==null||a.attemptAutoclose(P.AddErrorCaller,this.id),this):this}addEntryCaller(i,a=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,P.AddEntryCaller)),l=!1){return this.checkCanEditWithCounterpartAndSideEffects(this,i,P.AddEntryCaller,a)?(this.calledByEntry.find(f=>f.id===i.id)||(this.calledByEntry.push(i),a==null||a.add(this,K.Updated),l&&Ye(this,a)),a==null||a.attemptAutoclose(P.AddEntryCaller,this.id),this):this}addErrorCall(i,a=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,P.AddErrorCall)),l=!1){return this.checkCanEditWithCounterpartAndSideEffects(this,i,P.AddErrorCall,a)?(this.errorCalls.find(f=>f.id===i.id)||(this.errorCalls.push(i),l&&Ye(this,a),a==null||a.add(this,K.Affected)),a==null||a.attemptAutoclose(P.AddErrorCall,this.id),this):this}addSuccessCall(i,a=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,P.AddSuccessCall)),l=!1){return this.checkCanEditWithCounterpartAndSideEffects(this,i,P.AddSuccessCall,a)?(this.successCalls.find(f=>f.id===i.id)||(this.successCalls.push(i),l&&Ye(this,a),a==null||a.add(this,K.Affected)),a==null||a.attemptAutoclose(P.AddSuccessCall,this.id),this):this}removeCall(i,a=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,P.RemoveCall)),l=!1){if(!this.checkCanEditWithCounterpartAndSideEffects(this,i,P.RemoveCall,a))return this;const f=this.successCalls.findIndex(y=>y.id===i.id);f>-1&&(this.successCalls.splice(f,1),a==null||a.add(this,K.Affected));const e=this.errorCalls.findIndex(y=>y.id===i.id);return e>-1&&(this.errorCalls.splice(e,1),a==null||a.add(this,K.Affected)),l&&Ye(this,a),a==null||a.attemptAutoclose(P.RemoveCall,this.id),this}removeCaller(i,a=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,"remove-caller")),l=!1){return this.checkCanEditWithCounterpartAndSideEffects(this,i,P.RemoveCaller,a)?(this.calledBySuccess=this.calledBySuccess.filter(f=>f.id!==i.id?!0:(a==null||a.add(this,K.Updated),a==null||a.add(f,K.Affected),!1)),this.calledByError=this.calledByError.filter(f=>f.id!==i.id?!0:(a==null||a.add(this,K.Updated),a==null||a.add(f,K.Affected),!1)),this.calledByEntry=this.calledByEntry.filter(f=>f.id!==i.id?!0:(a==null||a.add(this,K.Updated),a==null||a.add(f,K.Affected),!1)),l&&Ye(this,a),a==null||a.attemptAutoclose(P.RemoveCaller,this.id),this):this}setParent(i,a=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,P.SetParent))){var l;return this.checkCanEditWithCounterpartAndSideEffects(this,i,P.SetParent,a)?(((l=this.parent)==null?void 0:l.id)!==(i==null?void 0:i.id)&&(this.parent=i,a&&(a==null||a.add(this,K.Updated))),a==null||a.attemptAutoclose(P.SetParent,this.id),this):this}setDeclaration(i){return this.declaration=i,this}initChildren(i=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.declaration=se(this.initialData.declaration,this.project),this.successCalls=this.initialData.successCalls.map(a=>{const l=se(a,this.project);if(l.addSuccessCaller(this,null),[p.BreakStatement,p.ContinueStatement].includes(l.type))l.setParent(this.parent.parent,null);else if(l.type===p.ReturnStatement){const f=fr(this,this.project);l.setParent(f,null),l.initChildren(i)}else l.type!==p.InternalCall&&l.setParent(this.parent,null);return l.initChildren(i),l}),this.errorCalls=this.initialData.errorCalls.map(a=>{const l=se(a,this.project);if(l.addErrorCaller(this,null),[p.BreakStatement,p.ContinueStatement].includes(l.type))l.setParent(this.parent.parent,null),l.initChildren(i);else if(l.type===p.ReturnStatement){const f=fr(this,this.project);l.setParent(f,null),l.initChildren(i)}else l.type!==p.InternalCall&&(l.setParent(this.parent,null),l.initChildren(i));return l}),this.inputs=this.initialData.inputs.map(a=>{const l=se(a,this.project);return l.setParent(this,null),l.initChildren(i),l}),this.outputs=this.initialData.outputs.map(a=>{const l=se(a,this.project);return l.setParent(this,null),l.initChildren(i),l}),this.initialData.error&&(this.error=se(this.initialData.error,this.project),this.error.setParent(this,null),this.error.initChildren(i)),this.subscribeToDependencies(),this.afterAllChildrenInitialized(i),i==null||i.attemptAutoclose("init-children",this.id),this)}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(i,a=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,"meta-sync"))){const l=Xi(this,i),f=Yi(this,l),e=this.toMeta();return this.x=l.x||e.x,this.y=l.y||e.y,this.catchesError=l.catchesError!==void 0?l.catchesError:this.catchesError,super.baseMetaSync(l,this),l.deleted===!0&&!e.deleted?a==null||a.add(this,K.Removed):l.deleted===!1&&e.deleted?a==null||a.add(this,K.Added):f&&(a==null||a.add(this,K.Updated)),a==null||a.attemptAutoclose("meta-sync",this.id),this}async APILoad(i=Ie,...a){return await qt.repository.APILoad(this.id,...a),this}async APICreate(i=Ie,...a){return await qt.repository.APICreate(this.toShallowJSON(),...a),this}async APIUpdate(i=Ie,...a){return await qt.repository.APIUpdate(this.toShallowJSON(),...a),this}async APIDelete(i=Ie,...a){return await qt.repository.APIDelete(this.toShallowJSON(),...a),this}async APIClone(i=Ie,...a){return await qt.repository.APIClone(this.id,...a),this}async APILoadVersion(i=Ie,a,...l){return await qt.repository.APILoadVersion(this.id,a,...l)}removeFromParent(i=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,P.RemoveFromParent))){if(!this.checkCanEdit(this))return J.warn(`[removeFromParent] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(P.RemoveFromParent,this.id),{added:[],updated:[],removed:[],affected:[],self:this};const a=[],l=[],f=[],e=[];return this.parent.type===p.Project?(this.parent.removeOperation(this),e.push(this.parent)):this.parent.detachedChildren.includes(this)&&this.parent.unsubscribeDetachedChild(this),i==null||i.attemptAutoclose(P.RemoveFromParent,this.id),{added:g(f),updated:g(a),removed:g(l),affected:g(e),self:this}}remove({ignoreUpstream:i}={ignoreUpstream:!1},a=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,P.RemoveEntity))){var v;if(!this.checkCanDelete(this)||!this.checkCanEdit(this))return J.warn(`[remove] User is not allowed to delete or edit this ${this.type} entity with id: ${this.id}`),a==null||a.event({id:`${P.RemoveEntity}-${this.id}`,action:P.RemoveEntity,owner:this,errorReason:Si.ActionOwnerEntityNonDeletable,rootAction:((v=a==null?void 0:a.self)==null?void 0:v.id)===this.id&&(a==null?void 0:a.autoCloseActionName)===P.RemoveEntity}),a==null||a.attemptAutoclose(P.RemoveEntity,this.id),{added:[],updated:[],removed:[],affected:[],self:this};const l=[],f=[],e=[],y=[];if(a!=null&&a.hasRemoved(this.id))return a==null||a.attemptAutoclose(P.RemoveEntity,this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(f.push(this),this.unsubscribe(),this.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},a),Object.values(this.detachedDependents).forEach(T=>{const{updated:A,removed:I,added:O}=T.entity.onDetachedDependencyRemoved(this,T.field,a);l.push(...A),f.push(...I),e.push(...O)}),this.inputs.forEach(T=>{const{updated:A,removed:I}=T.remove({ignoreUpstream:!0},a);l.push(...A),f.push(...I)}),this.outputs.forEach(T=>{const{updated:A,removed:I}=T.remove({ignoreUpstream:!0},a);l.push(...A),f.push(...I)}),this.error){const{updated:T,removed:A}=this.error.remove({ignoreUpstream:!0},a);l.push(...T),f.push(...A)}if(this.successCalls.forEach(T=>{l.push(T),T.removeCaller(this,a)}),this.errorCalls.forEach(T=>{l.push(T),T.removeCaller(this,a)}),!i){const T=this.removeFromParent(a);e.push(...T.added),l.push(...T.updated),f.push(...T.removed),y.push(...T.affected),this.calledBy.forEach(A=>{l.push(A),A.removeCall(this,a)})}return a==null||a.attemptAutoclose(P.RemoveEntity,this.id),{added:g(e),updated:g(l),removed:g(f),affected:g(y),self:this}}restore({}={},i=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,P.RestoreEntity))){if(!this.checkCanEdit(this))return J.warn(`[restore] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(P.RestoreEntity,this.id),{added:[],updated:[],removed:[],affected:[],self:this};const a=[],l=[],f=[],e=[];return i!=null&&i.hasAdded(this.id)?(i==null||i.attemptAutoclose(P.RestoreEntity,this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},i),Object.values(this.detachedDependents).forEach(y=>{const{updated:v,removed:T,added:A}=y.entity.onDetachedDependencyRestored(this,y.field,i);l.push(...v),f.push(...T),a.push(...A)}),this.inputs.forEach(y=>{const{updated:v}=y.restore({},i);l.push(...v)}),this.outputs.forEach(y=>{const{updated:v}=y.restore({},i);l.push(...v)}),this.successCalls.forEach(y=>{l.push(y),y.addSuccessCaller(this,i)}),this.errorCalls.forEach(y=>{l.push(y),y.addErrorCaller(this,i)}),this.calledBySuccess.forEach(y=>{l.push(y),y.addSuccessCall(this,i)}),this.calledByError.forEach(y=>{l.push(y),y.addErrorCall(this,i)}),this.calledByEntry.forEach(y=>{l.push(y),y.addCall(this,i)}),i==null||i.attemptAutoclose(P.RestoreEntity,this.id),{added:g(a),updated:g(l),removed:g(f),affected:g(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.calledBy.flatMap(l=>l.toFlat(i)),...this.error?this.error.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)),...this.error?this.error.toFlatIds(i):[]])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,x:this.x,y:this.y,type:this.type,editable:this.editable,deletable:this.deletable,catchesError:this.catchesError}}toJSON(i=new Set){var a;return i.has(this.id)?this.toReference():(i.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,editable:this.editable,deletable:this.deletable,catchesError:this.catchesError,x:this.x,y:this.y,successCalls:this.successCalls.map(l=>l.toJSON(i)),errorCalls:this.errorCalls.map(l=>l.toJSON(i)),calledBySuccess:this.calledBySuccess.map(l=>l.toReference()),calledByError:this.calledByError.map(l=>l.toReference()),calledByEntry:this.calledByEntry.map(l=>l.toReference()),writesValues:this.writesValues.map(l=>l.toJSON(i)),declaration:this.declaration.toJSON(i),inputs:this.inputs.map(l=>l.toJSON(i)),outputs:this.outputs.map(l=>l.toJSON(i)),parent:this.parent.toReference(),error:(a=this.error)==null?void 0:a.toJSON(i)})}toJSONClone(i=ke){var l,f,e,y,v,T;let a;return(l=i.seenEntityMaps)!=null&&l.has(this.id)?a=i.seenEntityMaps.get(this.id):(a=i.newId||or(this,this.project,i.uuidStrategy),i.seenEntityMaps&&i.seenEntityMaps.set(this.id,a)),(f=i.seenEntities)!=null&&f.has(a)||(e=i.seenEntities)!=null&&e.has(this.id)?this.toReference({seenEntityMaps:i.seenEntityMaps}):((y=i.seenEntities)==null||y.add(a),(v=i.seenEntities)==null||v.add(this.id),{id:a,version:V.UUID.uuid(),createdAt:i.timestamp||B().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,editable:this.editable,deletable:this.deletable,catchesError:this.catchesError,x:this.x,y:this.y,successCalls:this.successCalls.map(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})),writesValues:this.writesValues.map(A=>A.toJSONClone({...i,newId:null})),declaration:this.declaration.toJSON(),inputs:this.inputs.map(A=>A.toJSONClone({...i,newId:null})),outputs:this.outputs.map(A=>A.toJSONClone({...i,newId:null})),parent:this.parent.toReference({seenEntityMaps:i.seenEntityMaps}),error:(T=this.error)==null?void 0:T.toJSONClone({...i,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+"--"+V.UUID.uuid()+"--ref",type:p.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,editable:this.editable,deletable:this.deletable,catchesError:this.catchesError,x:this.x,y:this.y,inputs:this.inputs.map(f=>f.toReference(i)),outputs:this.outputs.map(f=>f.toReference(i)),declaration:this.declaration.toReference(i),writesValues:this.writesValues.map(f=>f.toReference(i)),successCalls:this.successCalls.map(f=>f.toReference(i)),errorCalls:this.errorCalls.map(f=>f.toReference(i)),calledBySuccess:this.calledBySuccess.map(f=>f.toReference(i)),calledByError:this.calledByError.map(f=>f.toReference(i)),calledByEntry:this.calledByEntry.map(f=>f.toReference(i)),error:this.error?this.error.toReference(i):null,parent:this.parent.toReference(i)}}toFlatJSON(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.toShallowJSON(),...this.successCalls.flatMap(l=>l.toFlatJSON(i)),...this.errorCalls.flatMap(l=>l.toFlatJSON(i)),...this.inputs.flatMap(l=>l.toFlatJSON(i)),...this.outputs.flatMap(l=>l.toFlatJSON(i)),...this.calledBy.flatMap(l=>l.toFlatJSON(i)),...this.error?this.error.toFlatJSON(i):[]])}toGenerationTarget(){const i=this.parent.type===p.Project?void 0:this.parent.id;return{id:this.id,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.error?this.error.toFlatGenerationTarget(i):[]])}clearErrors(){var i;return this.errors=[],this.inputs.forEach(a=>a.clearErrors()),this.outputs.forEach(a=>a.clearErrors()),this.successCalls.forEach(a=>a.clearErrors()),this.errorCalls.forEach(a=>a.clearErrors()),(i=this.error)==null||i.clearErrors(),this}validate(){const i=pK(this);return this.errors=i,{success:!0}}getErrors(){return[...this.errors,...this.inputs.flatMap(a=>a.getErrors()),...this.outputs.flatMap(a=>a.getErrors()),...this.error?this.error.getErrors():[]]}getShallowErrors(){return this.errors}clone(i=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,P.CloneEntity)),a=null,l=null,f=!0){var M,j;let e=lr(a,this);const y=this.toJSON(),v=l||V.UUID.uuid();y.inputs=[];const T=v.split("-id"),A=T[T.length-1||0]||v;y.id=v,y.version=V.UUID.uuid(),y.createdAt=(i==null?void 0:i.timestamp)||B().toISOString(),y.author=(i==null?void 0:i.author)||"1",y.previousVersion=null,y.deleted=!1,y.deletable=!0,y.editable=!0;const I=Ei(y,e);a?I.setParent(a,null):I.setParent(this.parent,null),f&&I.subscribe(),I.initChildren(i),i==null||i.add(I,K.Added);const O=(M=this.inputs)==null?void 0:M.map((q,Z)=>q.clone(i,I,A+"-input-map-"+Z+"-id",f));I.inputs=O;const L=(j=this.outputs)==null?void 0:j.map((q,Z)=>q.clone(i,I,A+"-output-map-"+Z+"-id",f));return I.outputs=L,this.error&&(I.error=this.error.clone(i,I,A+"-error-map-id",f)),i==null||i.attemptAutoclose(P.CloneEntity,this.id),I}removeUnrecognizedInputs(i=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,P.RemoveUnrecognizedInputs))){if(!this.checkCanEdit(this))return J.warn(`[removeUnrecognizedInputs] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(P.RemoveUnrecognizedInputs,this.id),{updated:[],added:[],removed:[],affected:[],self:this};const a=[],l=[],f=[],e=[];return this.inputs.forEach(v=>{if(!this.declaration.inputs.find(A=>{var I;return A.id===((I=v.declaration)==null?void 0:I.id)})){const A=v.remove({ignoreUpstream:!1},i);f.push(...A.removed),a.push(...A.updated)}}),this.inputs.filter((v,T)=>{const A=this.inputs.findIndex(O=>O.declaration===v.declaration&&O!==v&&v.declaration.parentRelationType!==ye.DynamicArgument);if(A===-1)return!1;const I=this.inputs[A];return B(I==null?void 0:I.createdAt).isSame(B(v.createdAt))?T>A:!!B(I==null?void 0:I.createdAt).isAfter(v.createdAt)}).forEach(v=>{const T=v.remove({ignoreUpstream:!1},i);f.push(...T.removed),a.push(...T.updated)}),i==null||i.attemptAutoclose(P.RemoveUnrecognizedInputs,this.id),{updated:g(a),added:g(l),removed:g(f),affected:g(e),self:this}}removeUnrecognizedOutputs(i=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,P.RemoveUnrecognizedOutputs))){if(!this.checkCanEdit(this))return J.warn(`[removeUnrecognizedOutputs] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(P.RemoveUnrecognizedOutputs,this.id),{updated:[],added:[],removed:[],affected:[],self:this};const a=[],l=[],f=[],e=[],y=this.declaration.dataType&&this.declaration.dataType.entity&&this.declaration.dataType.entity.type===p.DefinitionEntity?this.declaration.dataType.entity.properties:[];return this.outputs.forEach(T=>{if(!y.find(I=>{var O;return I.id===((O=T.declaration)==null?void 0:O.id)})){const I=T.remove({ignoreUpstream:!1},i);f.push(...I.removed),a.push(...I.updated)}}),this.outputs.filter((T,A)=>{const I=this.outputs.findIndex(L=>L.declaration===T.declaration&&L!==T);if(I===-1)return!1;const O=this.outputs[I];return B(O==null?void 0:O.createdAt).isSame(B(T.createdAt))?A>I:!!B(O==null?void 0:O.createdAt).isAfter(T.createdAt)}).forEach(T=>{const A=T.remove({ignoreUpstream:!1},i);f.push(...A.removed),a.push(...A.updated)}),i==null||i.attemptAutoclose(P.RemoveUnrecognizedOutputs,this.id),{updated:g(a),added:g(l),removed:g(f),affected:g(e),self:this}}syncInputs(i=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,P.SyncInputs))){if(!this.checkCanEdit(this))return J.warn(`[syncInputs] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(P.SyncInputs,this.id),{updated:[],added:[],removed:[],affected:[],self:this};const a=[],l=[],f=[],e=[],y=this.declaration.inputs.filter(I=>I.parentRelationType===ye.FixedArguments&&!this.inputs.find(O=>{var L;return((L=O.declaration)==null?void 0:L.id)===I.id}));this.inputs.sort((I,O)=>I.index-O.index),y.forEach(I=>{this.inputs.forEach(M=>{M.index>=I.index&&M.metaSync({index:M.index+1},i)});const O={id:V.UUID.uuid(),version:V.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||B().toISOString(),author:V.sessionAuthor,previousVersion:null,deleted:!1,deletable:!0,editable:!0,type:p.InputMap,parentRelationType:null,declaration:I.toJSON(),readsValue:null,defaultValue:null,index:I.index,name:null,codeName:null,description:null,parent:this.toReference()},L=se(O,this.project);L.setParent(this,i),L.initChildren(i),i==null||i.add(L,K.Added),L.addSelfToProject(i)}),this.inputs.sort((I,O)=>I.index-O.index);const{updated:v,added:T,removed:A}=this.removeUnrecognizedInputs(i);return a.push(...v),l.push(...T),f.push(...A),i==null||i.attemptAutoclose(P.SyncInputs,this.id),{updated:g(a),added:g(l),removed:g(f),affected:g(e),self:this}}syncOutputs(i=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,P.SyncOutputs))){if(!this.checkCanEdit(this))return J.warn(`[syncOutputs] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(P.SyncOutputs,this.id),{updated:[],added:[],removed:[],affected:[],self:this};const a=[],l=[],f=[],e=[],v=(this.declaration.dataType&&this.declaration.dataType.entity&&this.declaration.dataType.entity.type===p.DefinitionEntity?this.declaration.dataType.entity.properties:[]).filter(O=>!this.outputs.find(L=>{var M;return((M=L.declaration)==null?void 0:M.id)===O.id}));this.outputs.sort((O,L)=>O.index-L.index),v.forEach(O=>{this.outputs.forEach(j=>{j.index>=O.index&&j.index++});const L={id:V.UUID.uuid(),version:V.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||B().toISOString(),author:V.sessionAuthor,previousVersion:null,deleted:!1,deletable:!0,editable:!0,type:p.OutputMap,declaration:O.toJSON(),writesValues:[],index:O.index,parent:this.toReference()},M=se(L,this.project);M.setParent(this,i),M.initChildren(i),i==null||i.add(M,K.Added),M.addSelfToProject(i)}),this.outputs.sort((O,L)=>O.index-L.index);const{updated:T,added:A,removed:I}=this.removeUnrecognizedOutputs(i);return a.push(...T),l.push(...A),f.push(...I),i==null||i.attemptAutoclose(P.SyncOutputs,this.id),{updated:g(a),added:g(l),removed:g(f),affected:g(e),self:this}}getUnusedInputs(){return this.inputs.filter(i=>i.suggestion||!i.readsValue&&!i.defaultValue)}getUnusedOutputs(){return this.outputs.filter(i=>i.suggestion||!i.writesValues.length)}getUsedInputs(){return this.inputs.filter(i=>!i.suggestion&&(i.readsValue||i.defaultValue))}getUsedOutputs(){return this.outputs.filter(i=>!i.suggestion&&i.writesValues.length)}getDataType(i=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,"get-data-type"))){var l;const a=((l=this.declaration)==null?void 0:l.getDataType(i))||null;return i==null||i.attemptAutoclose("get-data-type",this.id),a}};_(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}),_(qt,"type",p.Operation),_(qt,"USER_MANAGED_PARENT_TYPES",[...qi,p.Project]),_(qt,"PARENT_TYPES",[...qt.USER_MANAGED_PARENT_TYPES]),_(qt,"MUTABLE_BASE_PROPERTIES",["catchesError"]),_(qt,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),_(qt,"BASE_PROPERTIES",[...qt.MUTABLE_BASE_PROPERTIES,...qt.INMUTABLE_BASE_PROPERTIES]),_(qt,"MUTABLE_META_PROPERTIES",[...qt.MUTABLE_BASE_PROPERTIES,"x","y"]),_(qt,"INMUTABLE_META_PROPERTIES",[...qt.INMUTABLE_BASE_PROPERTIES]),_(qt,"META_PROPERTIES",[...qt.MUTABLE_META_PROPERTIES,...qt.INMUTABLE_META_PROPERTIES]),_(qt,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry"]),_(qt,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","declaration"]),_(qt,"UPSTREAM_PROPERTIES",[...qt.MUTABLE_UPSTREAM_PROPERTIES,...qt.INMUTABLE_UPSTREAM_PROPERTIES]),_(qt,"MUTABLE_DOWNSTREAM_PROPERTIES",["inputs","outputs","writesValues","successCalls","errorCalls","error"]),_(qt,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),_(qt,"DOWNSTREAM_PROPERTIES",[...qt.MUTABLE_DOWNSTREAM_PROPERTIES,...qt.INMUTABLE_DOWNSTREAM_PROPERTIES]),_(qt,"PROPERTIES",[...qt.META_PROPERTIES,...qt.UPSTREAM_PROPERTIES,...qt.DOWNSTREAM_PROPERTIES]);let Ql=qt;function fK(d){var i;d.outputs.forEach(a=>a.validate()),(i=d.throws)==null||i.validate();const u=[];return $i(d.errors,u)}const wge=Object.freeze(Object.defineProperty({__proto__:null,validate:fK},Symbol.toStringTag,{value:"Module"}));var iA=(d=>(d.Parent="return-statement-parent-field",d.ImplementsField="return-statement-implements-field",d.DataTypeEntity="return-statement-data-type-entity-field",d.DataType="return-statement-data-type-field",d))(iA||{});const ni=class ni extends nr{constructor(i,a){super(i);_(this,"initialData");_(this,"id");_(this,"x");_(this,"y");_(this,"type",p.ReturnStatement);_(this,"outputs",[]);_(this,"readsValue",null);_(this,"dataType",null);_(this,"defaultValue",null);_(this,"implements",null);_(this,"calledBySuccess",[]);_(this,"calledByError",[]);_(this,"calledByEntry",[]);_(this,"throws",null);_(this,"project");_(this,"errors",[]);_(this,"parent");_(this,"detachedDependents",{});_(this,"knownVersions",null);_(this,"activeVersion",!1);_(this,"initialized",!1);_(this,"startedInitialization",!1);_(this,"suggestion",!1);this.initialData=i,this.project=a,this.id=i.id,this.x=i.x,this.y=i.y}static new(i=null){return{id:V.UUID.uuid(),version:V.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||B().toISOString(),author:(i==null?void 0:i.author)||V.sessionAuthor,previousVersion:null,deleted:!1,deletable:!0,editable:!0,type:p.ReturnStatement,outputs:[],defaultValue:null,dataType:null,implements:null,readsValue:null,throws:null,parent:null,calledByEntry:[],calledBySuccess:[],calledByError:[],x:0,y:0}}static fromGenerationTarget(i,a){const l=X(i.parent),f=a.get(l),e=i.calledByEntry.map(L=>{const M=X(L);return a.get(M)}),y=i.calledBySuccess.map(L=>{const M=X(L);return a.get(M)}),v=i.calledByError.map(L=>{const M=X(L);return a.get(M)});let T=null;if(i.readsValue){const L=X(i.readsValue);T=a.get(L)}let A=null;if(i.implements){const L=X(i.implements);A=a.get(L)}const I={id:i.id,version:V.UUID.uuid(),createdAt:B().toISOString(),author:V.sessionAuthor,previousVersion:null,deleted:!1,deletable:!0,editable:!0,type:p.ReturnStatement,x:0,y:0,outputs:[],defaultValue:null,dataType:null,implements:A,readsValue:T,calledBySuccess:y,calledByError:v,calledByEntry:e,throws:null,parent:f},O=se(I,a);return O.setParent(f,null),O}static validateGenerationTarget(i,a){let l=JSON.parse(JSON.stringify(i));const f=[],e=Pr(l,{parent:{list:!1,types:qi}},a);return l=e.modifiedData,f.push(...e.errors,...zi(l)),{errors:f,modifiedData:l}}validateGeneratedUpdate(i){const a=[];let l=JSON.parse(JSON.stringify(i));const f=Ad(l,this);return l=f.modifiedData,a.push(...f.errors),i.parent&&a.push(new oe({id:`${this.id}--${W.InvalidParentUpdate}`,code:W.InvalidParentUpdate,severity:Y.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.
|
|
47
47
|
If an entity is called by another, they must be in the same scope, which means they have the same parent.
|
|
48
48
|
You shouldn't have to manually update a 'parent' property.
|
|
49
|
-
Specifically for return statements the parent needs to always be the 'function-declaration' or 'global-event' that contains it.`})),{errors:a,modifiedData:i}}subscribeDependents(i){return i.forEach(a=>{this.detachedDependents[a.entity.id]||(this.detachedDependents[a.entity.id]=a)}),this}unsubscribeDependents(i){return i.forEach(a=>{this.detachedDependents[a.entity.id]&&delete this.detachedDependents[a.entity.id]}),this}syncDependents(i=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,"sync-dependents"))){const a=[],l=[],f=[],e=[];return Object.values(this.detachedDependents).forEach(y=>{const v=y.entity.afterAllChildrenInitialized(i);a.push(...v.updated),l.push(...v.added),f.push(...v.removed),e.push(...v.affected)}),i==null||i.attemptAutoclose("sync-dependents",this.id),{updated:g(a),added:g(l),removed:g(f),affected:g(e),self:this}}onDetachedDependencyRemoved(i,a,l){const f=[],e=[],y=[],v=[];if(a==="return-statement-implements-field"&&(this.setImplements(null,l),f.push(this)),a==="return-statement-parent-field"){const{updated:T,added:A,removed:I}=this.remove({ignoreUpstream:!1},l);f.push(...T),e.push(...A),y.push(...I)}return{updated:g(f),added:g(e),removed:g(y),affected:g(v),self:this}}onDetachedDependencyRestored(i,a,l){const f=[],e=[],y=[],v=[];if(a==="return-statement-implements-field"&&(this.setImplements(i,l),f.push(this)),a==="return-statement-parent-field"){const{updated:T,added:A,removed:I}=this.restore({},l);f.push(...T),e.push(...A),y.push(...I)}return{updated:g(f),added:g(e),removed:g(y),affected:g(v),self:this}}unsubscribeFromDependencies(){var i,a,l,f,e,y,v,T;return(i=this.parent)==null||i.unsubscribeDependents([{entity:this,field:"return-statement-parent-field"}]),(l=(a=this.implements)==null?void 0:a.unsubscribeDependents)==null||l.call(a,[{entity:this,field:"return-statement-implements-field"}]),(y=(e=(f=this.dataType)==null?void 0:f.entity)==null?void 0:e.unsubscribeDependents)==null||y.call(e,[{entity:this,field:"return-statement-data-type-entity-field"}]),(T=(v=this.dataType)==null?void 0:v.unsubscribeDependents)==null||T.call(v,[{entity:this,field:"return-statement-data-type-field"}]),this}subscribeToDependencies(){var i,a,l,f,e,y,v,T;return(i=this.parent)==null||i.subscribeDependents([{entity:this,field:"return-statement-parent-field"}]),(l=(a=this.implements)==null?void 0:a.subscribeDependents)==null||l.call(a,[{entity:this,field:"return-statement-implements-field"}]),(y=(e=(f=this.dataType)==null?void 0:f.entity)==null?void 0:e.subscribeDependents)==null||y.call(e,[{entity:this,field:"return-statement-data-type-entity-field"}]),(T=(v=this.dataType)==null?void 0:v.subscribeDependents)==null||T.call(v,[{entity:this,field:"return-statement-data-type-field"}]),this}increaseVersion(i){if(i&&!B(i).isValid())throw new Error(`The shared timestamp '${i}' is not a valid ISO 8601 date string.`);return i&&B(i).isSame(B(this.createdAt))?this:(this.previousVersion=this.version,this.version=V.UUID.uuid(),this.createdAt=B(i).toISOString()||B().toISOString(),this)}captureVersion(){var a;const i=((a=this.knownVersions)==null?void 0:a.get(this.version))||new ni(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.outputs=[...this.outputs],i.readsValue=this.readsValue,i.defaultValue=this.defaultValue,i.dataType=this.dataType,i.implements=this.implements,i.throws=this.throws,i.calledBySuccess=[...this.calledBySuccess],i.calledByError=[...this.calledByError],i.calledByEntry=[...this.calledByEntry],i.parent=this.parent,this}recursiveCaptureUpstreamVersions(i){const a=[],l=[],f=[],e=[];if(this.parent){this.parent.increaseVersion(i);const y=this.parent.recursiveCaptureUpstreamVersions(i);a.push(this.parent,...y.updated),l.push(...y.added),f.push(...y.removed)}return{updated:g(a),added:g(l),removed:g(f),affected:g(e),self:this}}async restoreVersion(i){var v;const a=[],l=[],f=[],e=[];if(this.version===i)return{updated:g(a),added:g(l),removed:g(f),affected:g(e),self:this};if(!this.knownVersions){const T=new Map;for(const[A,I]of this.knownVersions||new Map){if(T.set(A,I),I.activeVersion=!1,I.knownVersions)for(const[O,L]of I.knownVersions)T.set(O,L);I.knownVersions=null}}let y=(v=this.knownVersions)==null?void 0:v.get(i);if(!y){const T=await this.APILoadVersion({},i);if(!T)throw new Error(`Version with id '${i}' for entity with id '${this.id}' not found.`);y=new ni(T,this.project)}return this.metaSync(y.toShallowJSON(),null),this.previousVersion=y.previousVersion,this.version=y.version,this.createdAt=y.createdAt,this.author=y.author,this.deleted=y.deleted,this.outputs=y.outputs,this.readsValue=y.readsValue,this.defaultValue=y.defaultValue,this.dataType=y.dataType,this.implements=y.implements,this.throws=y.throws,this.calledBySuccess=y.calledBySuccess,this.calledByError=y.calledByError,this.calledByEntry=y.calledByEntry,this.parent=y.parent,{updated:g(a),added:g(l),removed:g(f),affected:g(e),self:this}}updateWithShallowTransfer(i,a=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,P.UpdateWithShallowTransfer))){if(!this.checkCanEdit(this))return J.warn(`[updateWithShallowTransfer] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),a==null||a.attemptAutoclose(P.UpdateWithShallowTransfer,this.id),this;if(this.metaSync(i,a),this.version=i.version,this.createdAt=i.createdAt,this.author=i.author,this.deleted=i.deleted,this.previousVersion=i.previousVersion,this.unsubscribeFromDependencies(),i.parent){const l=X(i.parent),f=this.project.get(l),e=this.parent;if(e&&e.id!==(f==null?void 0:f.id)&&this.removeFromParent(a),f)this.setParent(f,a);else throw a==null||a.attemptAutoclose(P.UpdateWithShallowTransfer,this.id),new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw a==null||a.attemptAutoclose(P.UpdateWithShallowTransfer,this.id),new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(i.readsValue){const l=X(i.readsValue),f=this.project.get(l),e=this.readsValue;e&&e.id!==(f==null?void 0:f.id)&&this.removeValueWriter(a),f&&this.setValueWriter(f,a)}return i.calledByEntry.forEach(l=>{const f=X(l),e=this.project.get(f);e&&(this.addEntryCaller(e,a),e.addCall(this,a))}),[...this.calledByEntry].forEach(l=>{i.calledByEntry.find(e=>X(e)===l.id)||(this.removeCaller(l,a),l.removeCall(this,a))}),i.calledBySuccess.forEach(l=>{const f=X(l),e=this.project.get(f);e&&(this.addSuccessCaller(e,a),e.addSuccessCall(this,a))}),[...this.calledBySuccess].forEach(l=>{i.calledBySuccess.find(e=>X(e)===l.id)||(this.removeCaller(l,a),l.removeCall(this,a))}),i.calledByError.forEach(l=>{const f=X(l),e=this.project.get(f);e&&(this.addErrorCaller(e,a),e.addErrorCall(this,a))}),[...this.calledBySuccess].forEach(l=>{i.calledBySuccess.find(e=>X(e)===l.id)||(this.removeCaller(l,a),l.removeCall(this,a))}),this.captureVersion(),this.subscribeToDependencies(),a==null||a.attemptAutoclose(P.UpdateWithShallowTransfer,this.id),this}hydrateAncestors(){const i=[],a=[],l=[],f=[];if(this.initialData.parent){const e=X(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.implements){const e=X(this.initialData.implements),y=this.project.get(e);if(y)this.setImplements(y,null),i.push(y);else if(e)throw new Error(`${rr(this.type)} with id '${this.id}' has a 'implements' reference "${e}" which is missing in the project`)}if(this.initialData.readsValue){const e=X(this.initialData.readsValue),y=this.project.get(e);y&&(this.setValueWriter(y,null),i.push(y))}return this.initialData.calledByEntry.forEach(e=>{const y=X(e),v=this.project.get(y);v&&this.addEntryCaller(v,null)}),this.initialData.calledBySuccess.forEach(e=>{const y=X(e),v=this.project.get(y);v&&this.addSuccessCaller(v,null)}),this.initialData.calledByError.forEach(e=>{const y=X(e),v=this.project.get(y);v&&this.addErrorCaller(v,null)}),{updated:g(i),added:g(a),removed:g(l),affected:g(f),self:this}}afterAllChildrenInitialized(i=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,P.AfterAllChildrenInitialized))){if(!this.checkCanEdit(this))return J.warn(`[afterAllChildrenInitialized] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(P.AfterAllChildrenInitialized,this.id),{updated:[],added:[],removed:[],affected:[],self:this};const a=[],l=[],f=[],e=[];this.initialized=!0,!this.dataType||this.dataType.inferred;const{updated:y,added:v,removed:T,affected:A}=this.syncInputs(i);return a.push(...y),l.push(...v),f.push(...T),e.push(...A),this.captureVersion(),i==null||i.attemptAutoclose(P.AfterAllChildrenInitialized,this.id),{updated:g(a),added:g(l),removed:g(f),affected:g(e),self:this}}addSelfToProject(i=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,"add-self-to-project"))){var y;const a=[this],l=[],f=[],e=[];return this.readsValue&&(this.readsValue.addValueReader(this,i),a.push(this.readsValue)),this.calledByEntry.forEach(v=>{v.addCall(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.parent.addReturnStatement(this),e.push(this.parent),i==null||i.add(this.parent,K.Affected),(y=this.parent)==null||y.returnStatements.forEach(v=>{v.id!==this.id&&(e.push(v),i==null||i.add(v,K.Affected))}),this.subscribe(),this.subscribeToDependencies(),i==null||i.attemptAutoclose("add-self-to-project",this.id),{updated:g(a),added:g(l),removed:g(f),affected:g(e),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}addSuccessCaller(i,a=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,P.AddSuccessCaller)),l=!1){return this.checkCanEditWithCounterpartAndSideEffects(this,i,P.AddSuccessCaller,a)?(this.calledBySuccess.find(f=>f.id===i.id)||(this.calledBySuccess.push(i),a==null||a.add(this,K.Updated),l&&Ye(this,a)),a==null||a.attemptAutoclose(P.AddSuccessCaller,this.id),this):this}addErrorCaller(i,a=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,P.AddErrorCaller)),l=!1){return this.checkCanEditWithCounterpartAndSideEffects(this,i,P.AddErrorCaller,a)?(this.calledByError.find(f=>f.id===i.id)||(this.calledByError.push(i),a==null||a.add(this,K.Updated),l&&Ye(this,a)),a==null||a.attemptAutoclose(P.AddErrorCaller,this.id),this):this}addEntryCaller(i,a=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,P.AddEntryCaller)),l=!1){return this.checkCanEditWithCounterpartAndSideEffects(this,i,P.AddEntryCaller,a)?(this.calledByEntry.find(f=>f.id===i.id)||(this.calledByEntry.push(i),a==null||a.add(this,K.Updated),l&&Ye(this,a)),a==null||a.attemptAutoclose(P.AddEntryCaller,this.id),this):this}removeCaller(i,a=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,"remove-caller")),l=!1){return this.checkCanEditWithCounterpartAndSideEffects(this,i,P.RemoveCaller,a)?(this.calledBySuccess=this.calledBySuccess.filter(f=>f.id!==i.id?!0:(a==null||a.add(this,K.Updated),a==null||a.add(f,K.Affected),!1)),this.calledByError=this.calledByError.filter(f=>f.id!==i.id?!0:(a==null||a.add(this,K.Updated),a==null||a.add(f,K.Affected),!1)),this.calledByEntry=this.calledByEntry.filter(f=>f.id!==i.id?!0:(a==null||a.add(this,K.Updated),a==null||a.add(f,K.Affected),!1)),l&&Ye(this,a),a==null||a.attemptAutoclose(P.RemoveCaller,this.id),this):this}setThrows(i,a=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,"set-throws"))){var l;if(!this.checkCanEdit(this))return J.warn(`[setThrows] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),a==null||a.attemptAutoclose("set-throws",this.id),this;if(i!==null&&i.parentRelationType!==Wa.Error)throw new Error("The 'throws' InputMap must have a parentRelationType of 'Error'.");return((l=this.throws)==null?void 0:l.id)!==(i==null?void 0:i.id)&&(this.throws=i,a==null||a.add(this,K.Updated)),a==null||a.attemptAutoclose("set-throws",this.id),this}addOutput(i,a=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,"add-output"))){return this.checkCanEdit(this)?this.outputs.includes(i)?(a==null||a.attemptAutoclose("add-output",this.id),this):(this.outputs.push(i),a==null||a.add(this,K.Affected),a==null||a.attemptAutoclose("add-output",this.id),this):(J.warn(`[addOutput] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),a==null||a.attemptAutoclose("add-output",this.id),this)}removeOutput(i,a=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,"remove-output"))){if(!this.checkCanEdit(this))return J.warn(`[removeOutput] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),a==null||a.attemptAutoclose("remove-output",this.id),this;const l=this.outputs.findIndex(f=>f.id===i.id);return l>-1&&(this.outputs.splice(l,1),a&&(a==null||a.add(this,K.Affected))),a==null||a.attemptAutoclose("remove-output",this.id),this}setParent(i,a=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,P.SetParent))){var l;return this.checkCanEditWithCounterpartAndSideEffects(this,i,P.SetParent,a)?(((l=this.parent)==null?void 0:l.id)!==(i==null?void 0:i.id)&&(this.parent=i,a&&(a==null||a.add(this,K.Updated))),a==null||a.attemptAutoclose(P.SetParent,this.id),this):this}setImplements(i,a=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,P.SetImplements))){var l;return this.checkCanEdit(this)?(((l=this.implements)==null?void 0:l.id)!==(i==null?void 0:i.id)&&(this.implements=i,a&&(a==null||a.add(this,K.Updated))),a==null||a.attemptAutoclose(P.SetImplements,this.id),this):(J.warn(`[setImplements] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),a==null||a.attemptAutoclose(P.SetImplements,this.id),this)}setValueWriter(i,a=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,P.SetValueWriter))){return i&&!this.checkCanEditWithCounterpartAndSideEffects(this,i,P.SetValueWriter,a)?this:!i&&!this.checkCanEdit(this)?(J.warn(`[setValueWriter] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),a==null||a.attemptAutoclose(P.SetValueWriter,this.id),this):(this.readsValue!==i&&(this.readsValue=i,a==null||a.add(this,K.Updated)),a==null||a.attemptAutoclose(P.SetValueWriter,this.id),this)}removeValueWriter(i=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,P.RemoveValueWriter))){return this.readsValue&&!this.checkCanEditWithCounterpartAndSideEffects(this,this.readsValue,P.RemoveValueWriter,i)?this:(this.readsValue&&(this.readsValue=null,i==null||i.add(this,K.Updated)),i==null||i.attemptAutoclose(P.RemoveValueWriter,this.id),this)}initChildren(i=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,"init-children"))){if(this.initialized||this.startedInitialization)return this;if(this.startedInitialization=!0,this.initialData.defaultValue&&(this.defaultValue=se(this.initialData.defaultValue,this.project),this.defaultValue.setParent(this,null),this.defaultValue.initChildren(i)),this.initialData.dataType&&(this.setDataType(se(this.initialData.dataType,this.project),i),this.dataType.setParent(this,null),this.dataType.initChildren(i)),_d.initReadsValue(this),this.initialData.implements){const a=se(this.initialData.implements,this.project);this.setImplements(a,null)}return this.outputs=this.initialData.outputs.map(a=>{const l=se(a,this.project);return l.setParent(this,null),l.initChildren(i),l}),this.initialData.throws&&(this.throws=se(this.initialData.throws,this.project),this.throws.setParent(this,null),this.throws.initChildren(i)),this.subscribeToDependencies(),this.afterAllChildrenInitialized(i),i==null||i.attemptAutoclose("init-children",this.id),this}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(i,a=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,"meta-sync"))){const l=Xi(this,i),f=Yi(this,l),e=this.toMeta();return this.x=l.x||e.x,this.y=l.y||e.y,super.baseMetaSync(l,this),l.deleted===!0&&!e.deleted?a==null||a.add(this,K.Removed):l.deleted===!1&&e.deleted?a==null||a.add(this,K.Added):f&&(a==null||a.add(this,K.Updated)),a==null||a.attemptAutoclose("meta-sync",this.id),this}async APILoad(i=Ie,...a){return await ni.repository.APILoad(this.id,...a),this}async APICreate(i=Ie,...a){return await ni.repository.APICreate(this.toShallowJSON(),...a),this}async APIUpdate(i=Ie,...a){return await ni.repository.APIUpdate(this.toShallowJSON(),...a),this}async APIDelete(i=Ie,...a){return await ni.repository.APIDelete(this.toShallowJSON(),...a),this}async APIClone(i=Ie,...a){return await ni.repository.APIClone(this.id,...a),this}async APILoadVersion(i=Ie,a,...l){return await ni.repository.APILoadVersion(this.id,a,...l)}removeFromParent(i=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,P.RemoveFromParent))){if(!this.checkCanEdit(this))return J.warn(`[removeFromParent] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(P.RemoveFromParent,this.id),{added:[],updated:[],removed:[],affected:[],self:this};const a=[],l=[],f=[],e=[];return this.parent.removeReturnStatement(this),e.push(this.parent),i==null||i.attemptAutoclose(P.RemoveFromParent,this.id),{added:g(f),updated:g(a),removed:g(l),affected:g(e),self:this}}remove({ignoreUpstream:i}={ignoreUpstream:!1},a=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,P.RemoveEntity))){var v,T;if(!this.checkCanDelete(this)||!this.checkCanEdit(this))return J.warn(`[remove] User is not allowed to delete or edit this ${this.type} entity with id: ${this.id}`),a==null||a.event({id:`${P.RemoveEntity}-${this.id}`,action:P.RemoveEntity,owner:this,errorReason:Si.ActionOwnerEntityNonDeletable,rootAction:((v=a==null?void 0:a.self)==null?void 0:v.id)===this.id&&(a==null?void 0:a.autoCloseActionName)===P.RemoveEntity}),a==null||a.attemptAutoclose(P.RemoveEntity,this.id),{added:[],updated:[],removed:[],affected:[],self:this};const l=[],f=[],e=[],y=[];if(a!=null&&a.hasRemoved(this.id))return a==null||a.attemptAutoclose(P.RemoveEntity,this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(f.push(this),this.unsubscribe(),this.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},a),Object.values(this.detachedDependents).forEach(A=>{const{updated:I,removed:O,added:L}=A.entity.onDetachedDependencyRemoved(this,A.field,a);l.push(...I),f.push(...O),e.push(...L)}),this.readsValue&&(l.push(this.readsValue),this.readsValue.removeValueReader(this,a)),this.outputs.forEach(A=>{const{updated:I,removed:O}=A.remove({ignoreUpstream:!0},a);l.push(...I),f.push(...O)}),this.throws){const{updated:A,removed:I}=this.throws.remove({ignoreUpstream:!0},a);l.push(...A),f.push(...I)}if(this.dataType){const{updated:A,removed:I}=this.dataType.remove({ignoreUpstream:!0},a);l.push(...A),f.push(...I)}if(!i){const A=this.removeFromParent(a);e.push(...A.added),l.push(...A.updated),f.push(...A.removed),y.push(...A.affected),this.calledBy.forEach(I=>{l.push(I),I.removeCall(this,a)})}return a==null||a.add(this.parent,K.Affected),(T=this.parent)==null||T.returnStatements.forEach(A=>{A.id!==this.id&&(y.push(A),a==null||a.add(A,K.Affected))}),a==null||a.attemptAutoclose(P.RemoveEntity,this.id),{added:g(e),updated:g(l),removed:g(f),affected:g(y),self:this}}restore({}={},i=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,P.RestoreEntity))){if(!this.checkCanEdit(this))return J.warn(`[restore] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(P.RestoreEntity,this.id),{added:[],updated:[],removed:[],affected:[],self:this};const a=[],l=[],f=[],e=[];if(i!=null&&i.hasAdded(this.id))return i==null||i.attemptAutoclose(P.RestoreEntity,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:T,added:A}=y.entity.onDetachedDependencyRestored(this,y.field,i);l.push(...v),f.push(...T),a.push(...A)}),this.readsValue&&(l.push(this.readsValue),this.readsValue.addValueReader(this,i)),this.outputs.forEach(y=>{const{updated:v}=y.restore({},i);l.push(...v)}),this.throws){const{updated:y}=this.throws.restore({},i);l.push(...y)}if(this.dataType){const{updated:y}=this.dataType.restore({},i);l.push(...y)}return this.parent.addReturnStatement(this),this.calledBySuccess.forEach(y=>{l.push(y),y.addSuccessCall(this,i)}),this.calledByError.forEach(y=>{l.push(y),y.addErrorCall(this,i)}),this.calledByEntry.forEach(y=>{l.push(y),y.addCall(this,i)}),i==null||i.attemptAutoclose(P.RestoreEntity,this.id),{added:g(a),updated:g(l),removed:g(f),affected:g(e),self:this}}toFlat(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this,...this.outputs.flatMap(l=>l.toFlat(i)),...this.throws?this.throws.toFlat(i):[],...this.dataType?this.dataType.toFlat(i):[]])}toFlatIds(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.id,...this.outputs.flatMap(l=>l.toFlatIds(i)),...this.throws?this.throws.toFlatIds(i):[],...this.dataType?this.dataType.toFlatIds(i):[]])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,x:this.x,y:this.y,type:this.type,editable:this.editable,deletable:this.deletable}}toJSON(i=new Set){var a,l,f,e,y,v;return i.has(this.id)?this.toReference():(i.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,editable:this.editable,deletable:this.deletable,x:this.x,y:this.y,defaultValue:((a=this.defaultValue)==null?void 0:a.toJSON(i))||null,dataType:((l=this.dataType)==null?void 0:l.toJSON(i))||null,readsValue:((f=this.readsValue)==null?void 0:f.toReference())||null,implements:((e=this.implements)==null?void 0:e.toJSON(i))||null,calledBySuccess:this.calledBySuccess.map(T=>T.toReference()),calledByError:this.calledByError.map(T=>T.toReference()),calledByEntry:this.calledByEntry.map(T=>T.toReference()),outputs:this.outputs.map(T=>T.toJSON(i)),parent:((y=this.parent)==null?void 0:y.toReference())||null,throws:((v=this.throws)==null?void 0:v.toJSON(i))||null})}toJSONClone(i=ke){var l,f,e,y,v,T,A,I,O,L;let a;return(l=i.seenEntityMaps)!=null&&l.has(this.id)?a=i.seenEntityMaps.get(this.id):(a=i.newId||or(this,this.project,i.uuidStrategy),i.seenEntityMaps&&i.seenEntityMaps.set(this.id,a)),(f=i.seenEntities)!=null&&f.has(a)||(e=i.seenEntities)!=null&&e.has(this.id)?this.toReference({seenEntityMaps:i.seenEntityMaps}):((y=i.seenEntities)==null||y.add(a),(v=i.seenEntities)==null||v.add(this.id),{id:a,version:V.UUID.uuid(),createdAt:i.timestamp||B().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,editable:this.editable,deletable:this.deletable,x:this.x,y:this.y,defaultValue:((T=this.defaultValue)==null?void 0:T.toJSONClone({...i,newId:null}))||null,dataType:((A=this.dataType)==null?void 0:A.toJSONClone({...i,newId:null}))||null,readsValue:((I=this.readsValue)==null?void 0:I.toReference({seenEntityMaps:i.seenEntityMaps}))||null,implements:(()=>{var M;return this.implements&&this.project.getBuiltIn(this.implements.id)?this.implements.toJSON():((M=this.implements)==null?void 0:M.toJSONClone({...i,newId:null}))||null})(),calledBySuccess:this.calledBySuccess.map(M=>M.toReference({seenEntityMaps:i.seenEntityMaps})),calledByError:this.calledByError.map(M=>M.toReference({seenEntityMaps:i.seenEntityMaps})),calledByEntry:this.calledByEntry.map(M=>M.toReference({seenEntityMaps:i.seenEntityMaps})),outputs:this.outputs.map(M=>M.toJSONClone({...i,newId:null})),parent:((O=this.parent)==null?void 0:O.toReference({seenEntityMaps:i.seenEntityMaps}))||null,throws:((L=this.throws)==null?void 0:L.toJSONClone({...i,newId:null}))||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+"--"+V.UUID.uuid()+"--ref",type:p.GenericReference,entityId:a,version:this.version,entityType:this.type}}toShallowJSON(i=ke){var l,f,e,y,v,T,A;let a=this.id;return(l=i.seenEntityMaps)!=null&&l.has(this.id)&&(a=i.seenEntityMaps.get(this.id)),{id:a,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,editable:this.editable,deletable:this.deletable,x:this.x,y:this.y,defaultValue:((f=this.defaultValue)==null?void 0:f.toReference(i))||null,dataType:((e=this.dataType)==null?void 0:e.toReference(i))||null,readsValue:((y=this.readsValue)==null?void 0:y.toReference(i))||null,implements:((v=this.implements)==null?void 0:v.toReference(i))||null,outputs:this.outputs.map(I=>I.toReference(i)),calledBySuccess:this.calledBySuccess.map(I=>I.toReference(i)),calledByError:this.calledByError.map(I=>I.toReference(i)),calledByEntry:this.calledByEntry.map(I=>I.toReference(i)),throws:((T=this.throws)==null?void 0:T.toReference(i))||null,parent:((A=this.parent)==null?void 0:A.toReference(i))||null}}toFlatJSON(i=new Set){var l,f,e;return i.has(this.id)?[]:(i.add(this.id),[this.toShallowJSON(),...((l=this.defaultValue)==null?void 0:l.toFlatJSON(i))||[],...((f=this.dataType)==null?void 0:f.toFlatJSON(i))||[],...((e=this.implements)==null?void 0:e.toFlatJSON(i))||[],...this.outputs.flatMap(y=>y.toFlatJSON(i)),...this.throws?this.throws.toFlatJSON(i):[]])}toGenerationTarget(){var i;return{id:this.id,type:this.type,calledByEntry:this.calledByEntry.map(a=>a.id),calledByError:this.calledByError.map(a=>a.id),calledBySuccess:this.calledBySuccess.map(a=>a.id),implements:(i=this.implements)==null?void 0:i.id,parent:this.parent.id}}toFlatGenerationTarget(i=new Set){var l,f,e;return i.has(this.id)?[]:(i.add(this.id),[this.toGenerationTarget(),...((l=this.defaultValue)==null?void 0:l.toFlatGenerationTarget(i))||[],...((f=this.dataType)==null?void 0:f.toFlatGenerationTarget(i))||[],...((e=this.implements)==null?void 0:e.toFlatGenerationTarget(i))||[],...this.outputs.flatMap(y=>y.toFlatGenerationTarget(i)),...this.throws?this.throws.toFlatGenerationTarget(i):[]])}clearErrors(){var i,a,l;return this.errors=[],(i=this.dataType)==null||i.clearErrors(),(a=this.defaultValue)==null||a.clearErrors(),this.outputs.forEach(f=>f.clearErrors()),(l=this.throws)==null||l.clearErrors(),this}validate(){const i=fK(this);return this.errors=i,{success:!0}}getErrors(){var a,l;return[...this.errors,...((a=this.defaultValue)==null?void 0:a.getErrors())||[],...((l=this.dataType)==null?void 0:l.getErrors())||[],...this.outputs.flatMap(f=>f.getErrors())]}getShallowErrors(){return this.errors}getDefaultValue(){return this.defaultValue||null}setDefaultValue(i,a=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,"set-default-value"))){if(!this.checkCanEdit(this))return J.warn(`[setDefaultValue] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),a==null||a.attemptAutoclose("set-default-value",this.id),this;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,K.Affected)),a==null||a.attemptAutoclose("set-default-value",this.id),this}clone(i=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,P.CloneEntity)),a=null,l=null,f=!0){var j,q,Z;let e=lr(a,this);const y=this.toJSON(),v=l||V.UUID.uuid();y.outputs=[];const T=v.split("-id"),A=T[T.length-1||0]||v;y.id=v,y.version=V.UUID.uuid(),y.createdAt=(i==null?void 0:i.timestamp)||B().toISOString(),y.author=(i==null?void 0:i.author)||"1",y.previousVersion=null,y.deleted=!1,y.deletable=!0,y.editable=!0;const I=Ei(y,e);a?I.setParent(a,null):I.setParent(this.parent,null),f&&I.subscribe(),I.initChildren(i),i==null||i.add(I,K.Added);const O=(j=this.dataType)==null?void 0:j.clone(i,I,V.UUID.uuid(),f);I.setDataType(O||null,i);const L=(q=this.defaultValue)==null?void 0:q.clone(i,I,V.UUID.uuid(),f);I.setDefaultValue(L||null,i),this.implements&&I.setImplements(this.implements,i);const M=(Z=this.outputs)==null?void 0:Z.map((S,H)=>S.clone(i,I,A+"-return-declaration-"+H+"-id",f));return I.outputs=M,this.throws&&(I.throws=this.throws.clone(i,I,A+"-throws-id",f)),i==null||i.attemptAutoclose(P.CloneEntity,this.id),I}syncInputs(i=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,"sync-returned-inputs"))){var M,j;const a=[],l=[],f=[],e=[],y=fr(this,this.project);if(!y.implements)return this.throws&&this.outputs.length&&this.outputs.forEach(q=>{var Z;if(q.id!==((Z=this.throws)==null?void 0:Z.id)){const{updated:S,removed:H}=q.remove({ignoreUpstream:!0},i);a.push(...S),f.push(...H),this.removeOutput(q,i)}}),i==null||i.attemptAutoclose("sync-returned-inputs",this.id),{updated:g(a),added:g(l),removed:g(f),affected:g(e),self:this};const v=(j=(M=y.implements)==null?void 0:M.dataType)==null?void 0:j.entity,T=(v==null?void 0:v.type)===p.DefinitionEntity?v.properties:[],A=y.implements.error,I=T;if(A&&!this.throws){const q=A.implementAsInputMap(i,this);return l.push(q),this.outputs.forEach(Z=>{if(Z.id!==q.id){const{updated:S,removed:H}=Z.remove({ignoreUpstream:!0},i);a.push(...S),f.push(...H),this.removeOutput(Z,i)}}),i==null||i.attemptAutoclose("sync-returned-inputs",this.id),{updated:g(a),added:g(l),removed:g(f),affected:g(e),self:this}}if(!A&&this.throws){const{updated:q,removed:Z}=this.throws.remove({ignoreUpstream:!0},i);a.push(...q),f.push(...Z)}return I.filter(q=>!this.outputs.find(Z=>{var S;return((S=Z.declaration)==null?void 0:S.id)===q.id&&(Z.declaration.type===p.ValueDescriptor?Z.declaration.parentRelationType!==ye.ReturnedError:!0)})).forEach(q=>{const Z=q.implementAsInputMap(i,this);l.push(Z)}),i==null||i.attemptAutoclose("sync-returned-inputs",this.id),{updated:g(a),added:g(l),removed:g(f),affected:g(e),self:this}}setDataType(i,a=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,P.SetDataType))){if(!this.checkCanEdit(this))return J.warn(`[setDataType] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),a==null||a.attemptAutoclose(P.SetDataType,this.id),this;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,K.Affected)),a==null||a.attemptAutoclose(P.SetDataType,this.id),this}removeDataType(i=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,P.RemoveDataType))){return this.checkCanEdit(this)?(this.dataType&&(this.dataType.remove({ignoreUpstream:!0},i),i==null||i.add(this,K.Affected),this.dataType=null),i==null||i.attemptAutoclose(P.RemoveDataType,this.id),this):(J.warn(`[removeDataType] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(P.RemoveDataType,this.id),this)}getDataType(i=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,"get-data-type"))){var l;if((!this.dataType||this.dataType.inferred)&&this.project.initialized,this.dataType)return i==null||i.attemptAutoclose("get-data-type",this.id),this.dataType;const a=(l=this.implements)==null?void 0:l.getDataType(i);return i==null||i.attemptAutoclose("get-data-type",this.id),a||null}};_(ni,"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}),_(ni,"type",p.ReturnStatement),_(ni,"USER_MANAGED_PARENT_TYPES",[...qi]),_(ni,"PARENT_TYPES",[...ni.USER_MANAGED_PARENT_TYPES]),_(ni,"MUTABLE_BASE_PROPERTIES",[]),_(ni,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),_(ni,"BASE_PROPERTIES",[...ni.MUTABLE_BASE_PROPERTIES,...ni.INMUTABLE_BASE_PROPERTIES]),_(ni,"MUTABLE_META_PROPERTIES",["x","y"]),_(ni,"INMUTABLE_META_PROPERTIES",[...ni.INMUTABLE_BASE_PROPERTIES]),_(ni,"META_PROPERTIES",[...ni.MUTABLE_META_PROPERTIES,...ni.INMUTABLE_META_PROPERTIES]),_(ni,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry","readsValue"]),_(ni,"INMUTABLE_UPSTREAM_PROPERTIES",["parent"]),_(ni,"UPSTREAM_PROPERTIES",[...ni.MUTABLE_UPSTREAM_PROPERTIES,...ni.INMUTABLE_UPSTREAM_PROPERTIES]),_(ni,"MUTABLE_DOWNSTREAM_PROPERTIES",["outputs","throws"]),_(ni,"INMUTABLE_DOWNSTREAM_PROPERTIES",["dataType","defaultValue"]),_(ni,"DOWNSTREAM_PROPERTIES",[...ni.MUTABLE_DOWNSTREAM_PROPERTIES,...ni.INMUTABLE_DOWNSTREAM_PROPERTIES]),_(ni,"PROPERTIES",[...ni.META_PROPERTIES,...ni.UPSTREAM_PROPERTIES,...ni.DOWNSTREAM_PROPERTIES]);let eo=ni;function yK(d){const u=xn(d);d.inputs.forEach(a=>a.validate()),u.forEach(a=>a.validate());const i=[...Nw(d)];return $i(d.errors,i)}const Rge=Object.freeze(Object.defineProperty({__proto__:null,validate:yK},Symbol.toStringTag,{value:"Module"})),Zt=class Zt extends nr{constructor(i,a){super(i);_(this,"initialData");_(this,"id");_(this,"name");_(this,"description",null);_(this,"x");_(this,"y");_(this,"collapsed");_(this,"type",p.GlobalEvent);_(this,"inputs",[]);_(this,"calls",[]);_(this,"parent");_(this,"implements");_(this,"detachedChildren",[]);_(this,"errors",[]);_(this,"project");_(this,"detachedDependents",{});_(this,"knownVersions",null);_(this,"activeVersion",!1);_(this,"initialized",!1);_(this,"startedInitialization",!1);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.collapsed=i.collapsed}static new(i=null){return{id:V.UUID.uuid(),version:V.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||B().toISOString(),author:(i==null?void 0:i.author)||V.sessionAuthor,previousVersion:null,deleted:!1,deletable:!0,editable:!0,type:p.GlobalEvent,name:"",description:"",collapsed:!1,implements:null,inputs:[],parent:null,calls:[],x:0,y:0}}static fromGenerationTarget(i,a){let l=a;if(i.parent){const v=X(i.parent);l=a.get(v)}let f;i.implements&&(f=a.getBuiltIn(i.implements));const e={id:i.id,version:V.UUID.uuid(),createdAt:B().toISOString(),author:V.sessionAuthor,previousVersion:null,deleted:!1,name:i.name,description:i.description||null,deletable:!0,editable:!0,type:p.GlobalEvent,collapsed:!1,calls:[],inputs:[],implements:f,x:0,y:0,parent:l},y=se(e,a);return y.setParent(l,null),y}static validateGenerationTarget(i,a){let l=JSON.parse(JSON.stringify(i));const f=[],e=Pr(l,{},a);if(l=e.modifiedData,f.push(...e.errors,...zi(l)),!i.implements)f.push(new oe({id:`${i.id}--${le.InvalidObjectStructure}`,code:le.InvalidObjectStructure,severity:Y.Error,message:`Entity of type '${i.type}' with id '${i.id}' is missing the 'implements' property. This property is required for a '${i.type}' entity and must point to one of the built-in action descriptors reserved for 'global-event' entities.
|
|
49
|
+
Specifically for return statements the parent needs to always be the 'function-declaration' or 'global-event' that contains it.`})),{errors:a,modifiedData:i}}subscribeDependents(i){return i.forEach(a=>{this.detachedDependents[a.entity.id]||(this.detachedDependents[a.entity.id]=a)}),this}unsubscribeDependents(i){return i.forEach(a=>{this.detachedDependents[a.entity.id]&&delete this.detachedDependents[a.entity.id]}),this}syncDependents(i=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,"sync-dependents"))){const a=[],l=[],f=[],e=[];return Object.values(this.detachedDependents).forEach(y=>{const v=y.entity.afterAllChildrenInitialized(i);a.push(...v.updated),l.push(...v.added),f.push(...v.removed),e.push(...v.affected)}),i==null||i.attemptAutoclose("sync-dependents",this.id),{updated:g(a),added:g(l),removed:g(f),affected:g(e),self:this}}onDetachedDependencyRemoved(i,a,l){const f=[],e=[],y=[],v=[];if(a==="return-statement-implements-field"&&(this.setImplements(null,l),f.push(this)),a==="return-statement-parent-field"){const{updated:T,added:A,removed:I}=this.remove({ignoreUpstream:!1},l);f.push(...T),e.push(...A),y.push(...I)}return{updated:g(f),added:g(e),removed:g(y),affected:g(v),self:this}}onDetachedDependencyRestored(i,a,l){const f=[],e=[],y=[],v=[];if(a==="return-statement-implements-field"&&(this.setImplements(i,l),f.push(this)),a==="return-statement-parent-field"){const{updated:T,added:A,removed:I}=this.restore({},l);f.push(...T),e.push(...A),y.push(...I)}return{updated:g(f),added:g(e),removed:g(y),affected:g(v),self:this}}unsubscribeFromDependencies(){var i,a,l,f,e,y,v,T;return(i=this.parent)==null||i.unsubscribeDependents([{entity:this,field:"return-statement-parent-field"}]),(l=(a=this.implements)==null?void 0:a.unsubscribeDependents)==null||l.call(a,[{entity:this,field:"return-statement-implements-field"}]),(y=(e=(f=this.dataType)==null?void 0:f.entity)==null?void 0:e.unsubscribeDependents)==null||y.call(e,[{entity:this,field:"return-statement-data-type-entity-field"}]),(T=(v=this.dataType)==null?void 0:v.unsubscribeDependents)==null||T.call(v,[{entity:this,field:"return-statement-data-type-field"}]),this}subscribeToDependencies(){var i,a,l,f,e,y,v,T;return(i=this.parent)==null||i.subscribeDependents([{entity:this,field:"return-statement-parent-field"}]),(l=(a=this.implements)==null?void 0:a.subscribeDependents)==null||l.call(a,[{entity:this,field:"return-statement-implements-field"}]),(y=(e=(f=this.dataType)==null?void 0:f.entity)==null?void 0:e.subscribeDependents)==null||y.call(e,[{entity:this,field:"return-statement-data-type-entity-field"}]),(T=(v=this.dataType)==null?void 0:v.subscribeDependents)==null||T.call(v,[{entity:this,field:"return-statement-data-type-field"}]),this}increaseVersion(i){if(i&&!B(i).isValid())throw new Error(`The shared timestamp '${i}' is not a valid ISO 8601 date string.`);return i&&B(i).isSame(B(this.createdAt))?this:(this.previousVersion=this.version,this.version=V.UUID.uuid(),this.createdAt=B(i).toISOString()||B().toISOString(),this)}captureVersion(){var a;const i=((a=this.knownVersions)==null?void 0:a.get(this.version))||new ni(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.outputs=[...this.outputs],i.readsValue=this.readsValue,i.defaultValue=this.defaultValue,i.dataType=this.dataType,i.implements=this.implements,i.throws=this.throws,i.calledBySuccess=[...this.calledBySuccess],i.calledByError=[...this.calledByError],i.calledByEntry=[...this.calledByEntry],i.parent=this.parent,this}recursiveCaptureUpstreamVersions(i){const a=[],l=[],f=[],e=[];if(this.parent){this.parent.increaseVersion(i);const y=this.parent.recursiveCaptureUpstreamVersions(i);a.push(this.parent,...y.updated),l.push(...y.added),f.push(...y.removed)}return{updated:g(a),added:g(l),removed:g(f),affected:g(e),self:this}}async restoreVersion(i){var v;const a=[],l=[],f=[],e=[];if(this.version===i)return{updated:g(a),added:g(l),removed:g(f),affected:g(e),self:this};if(!this.knownVersions){const T=new Map;for(const[A,I]of this.knownVersions||new Map){if(T.set(A,I),I.activeVersion=!1,I.knownVersions)for(const[O,L]of I.knownVersions)T.set(O,L);I.knownVersions=null}}let y=(v=this.knownVersions)==null?void 0:v.get(i);if(!y){const T=await this.APILoadVersion({},i);if(!T)throw new Error(`Version with id '${i}' for entity with id '${this.id}' not found.`);y=new ni(T,this.project)}return this.metaSync(y.toShallowJSON(),null),this.previousVersion=y.previousVersion,this.version=y.version,this.createdAt=y.createdAt,this.author=y.author,this.deleted=y.deleted,this.outputs=y.outputs,this.readsValue=y.readsValue,this.defaultValue=y.defaultValue,this.dataType=y.dataType,this.implements=y.implements,this.throws=y.throws,this.calledBySuccess=y.calledBySuccess,this.calledByError=y.calledByError,this.calledByEntry=y.calledByEntry,this.parent=y.parent,{updated:g(a),added:g(l),removed:g(f),affected:g(e),self:this}}updateWithShallowTransfer(i,a=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,P.UpdateWithShallowTransfer))){if(!this.checkCanEdit(this))return J.warn(`[updateWithShallowTransfer] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),a==null||a.attemptAutoclose(P.UpdateWithShallowTransfer,this.id),this;if(this.metaSync(i,a),this.version=i.version,this.createdAt=i.createdAt,this.author=i.author,this.deleted=i.deleted,this.previousVersion=i.previousVersion,this.unsubscribeFromDependencies(),i.parent){const l=X(i.parent),f=this.project.get(l),e=this.parent;if(e&&e.id!==(f==null?void 0:f.id)&&this.removeFromParent(a),f)this.setParent(f,a);else throw a==null||a.attemptAutoclose(P.UpdateWithShallowTransfer,this.id),new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw a==null||a.attemptAutoclose(P.UpdateWithShallowTransfer,this.id),new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(i.readsValue){const l=X(i.readsValue),f=this.project.get(l),e=this.readsValue;e&&e.id!==(f==null?void 0:f.id)&&this.removeValueWriter(a),f&&this.setValueWriter(f,a)}return i.calledByEntry.forEach(l=>{const f=X(l),e=this.project.get(f);e&&(this.addEntryCaller(e,a),e.addCall(this,a))}),[...this.calledByEntry].forEach(l=>{i.calledByEntry.find(e=>X(e)===l.id)||(this.removeCaller(l,a),l.removeCall(this,a))}),i.calledBySuccess.forEach(l=>{const f=X(l),e=this.project.get(f);e&&(this.addSuccessCaller(e,a),e.addSuccessCall(this,a))}),[...this.calledBySuccess].forEach(l=>{i.calledBySuccess.find(e=>X(e)===l.id)||(this.removeCaller(l,a),l.removeCall(this,a))}),i.calledByError.forEach(l=>{const f=X(l),e=this.project.get(f);e&&(this.addErrorCaller(e,a),e.addErrorCall(this,a))}),[...this.calledBySuccess].forEach(l=>{i.calledBySuccess.find(e=>X(e)===l.id)||(this.removeCaller(l,a),l.removeCall(this,a))}),this.captureVersion(),this.subscribeToDependencies(),a==null||a.attemptAutoclose(P.UpdateWithShallowTransfer,this.id),this}hydrateAncestors(){const i=[],a=[],l=[],f=[];if(this.initialData.parent){const e=X(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.implements){const e=X(this.initialData.implements),y=this.project.get(e);if(y)this.setImplements(y,null),i.push(y);else if(e)throw new Error(`${rr(this.type)} with id '${this.id}' has a 'implements' reference "${e}" which is missing in the project`)}if(this.initialData.readsValue){const e=X(this.initialData.readsValue),y=this.project.get(e);y&&(this.setValueWriter(y,null),i.push(y))}return this.initialData.calledByEntry.forEach(e=>{const y=X(e),v=this.project.get(y);v&&this.addEntryCaller(v,null)}),this.initialData.calledBySuccess.forEach(e=>{const y=X(e),v=this.project.get(y);v&&this.addSuccessCaller(v,null)}),this.initialData.calledByError.forEach(e=>{const y=X(e),v=this.project.get(y);v&&this.addErrorCaller(v,null)}),{updated:g(i),added:g(a),removed:g(l),affected:g(f),self:this}}afterAllChildrenInitialized(i=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,P.AfterAllChildrenInitialized))){if(!this.checkCanEdit(this))return J.warn(`[afterAllChildrenInitialized] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(P.AfterAllChildrenInitialized,this.id),{updated:[],added:[],removed:[],affected:[],self:this};const a=[],l=[],f=[],e=[];this.initialized=!0,!this.dataType||this.dataType.inferred,this.parent.implements&&!this.implements&&(this.setImplements(this.parent.implements,i),a.push(this));const{updated:y,added:v,removed:T,affected:A}=this.syncInputs(i);return a.push(...y),l.push(...v),f.push(...T),e.push(...A),this.captureVersion(),i==null||i.attemptAutoclose(P.AfterAllChildrenInitialized,this.id),{updated:g(a),added:g(l),removed:g(f),affected:g(e),self:this}}addSelfToProject(i=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,"add-self-to-project"))){var y;const a=[this],l=[],f=[],e=[];return this.readsValue&&(this.readsValue.addValueReader(this,i),a.push(this.readsValue)),this.calledByEntry.forEach(v=>{v.addCall(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.parent.addReturnStatement(this),e.push(this.parent),i==null||i.add(this.parent,K.Affected),(y=this.parent)==null||y.returnStatements.forEach(v=>{v.id!==this.id&&(e.push(v),i==null||i.add(v,K.Affected))}),this.subscribe(),this.subscribeToDependencies(),i==null||i.attemptAutoclose("add-self-to-project",this.id),{updated:g(a),added:g(l),removed:g(f),affected:g(e),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}addSuccessCaller(i,a=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,P.AddSuccessCaller)),l=!1){return this.checkCanEditWithCounterpartAndSideEffects(this,i,P.AddSuccessCaller,a)?(this.calledBySuccess.find(f=>f.id===i.id)||(this.calledBySuccess.push(i),a==null||a.add(this,K.Updated),l&&Ye(this,a)),a==null||a.attemptAutoclose(P.AddSuccessCaller,this.id),this):this}addErrorCaller(i,a=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,P.AddErrorCaller)),l=!1){return this.checkCanEditWithCounterpartAndSideEffects(this,i,P.AddErrorCaller,a)?(this.calledByError.find(f=>f.id===i.id)||(this.calledByError.push(i),a==null||a.add(this,K.Updated),l&&Ye(this,a)),a==null||a.attemptAutoclose(P.AddErrorCaller,this.id),this):this}addEntryCaller(i,a=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,P.AddEntryCaller)),l=!1){return this.checkCanEditWithCounterpartAndSideEffects(this,i,P.AddEntryCaller,a)?(this.calledByEntry.find(f=>f.id===i.id)||(this.calledByEntry.push(i),a==null||a.add(this,K.Updated),l&&Ye(this,a)),a==null||a.attemptAutoclose(P.AddEntryCaller,this.id),this):this}removeCaller(i,a=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,"remove-caller")),l=!1){return this.checkCanEditWithCounterpartAndSideEffects(this,i,P.RemoveCaller,a)?(this.calledBySuccess=this.calledBySuccess.filter(f=>f.id!==i.id?!0:(a==null||a.add(this,K.Updated),a==null||a.add(f,K.Affected),!1)),this.calledByError=this.calledByError.filter(f=>f.id!==i.id?!0:(a==null||a.add(this,K.Updated),a==null||a.add(f,K.Affected),!1)),this.calledByEntry=this.calledByEntry.filter(f=>f.id!==i.id?!0:(a==null||a.add(this,K.Updated),a==null||a.add(f,K.Affected),!1)),l&&Ye(this,a),a==null||a.attemptAutoclose(P.RemoveCaller,this.id),this):this}setThrows(i,a=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,"set-throws"))){var l;if(!this.checkCanEdit(this))return J.warn(`[setThrows] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),a==null||a.attemptAutoclose("set-throws",this.id),this;if(i!==null&&i.parentRelationType!==Wa.Error)throw new Error("The 'throws' InputMap must have a parentRelationType of 'Error'.");return((l=this.throws)==null?void 0:l.id)!==(i==null?void 0:i.id)&&(this.throws=i,a==null||a.add(this,K.Updated)),a==null||a.attemptAutoclose("set-throws",this.id),this}addOutput(i,a=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,"add-output"))){return this.checkCanEdit(this)?this.outputs.includes(i)?(a==null||a.attemptAutoclose("add-output",this.id),this):(this.outputs.push(i),a==null||a.add(this,K.Affected),a==null||a.attemptAutoclose("add-output",this.id),this):(J.warn(`[addOutput] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),a==null||a.attemptAutoclose("add-output",this.id),this)}removeOutput(i,a=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,"remove-output"))){if(!this.checkCanEdit(this))return J.warn(`[removeOutput] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),a==null||a.attemptAutoclose("remove-output",this.id),this;const l=this.outputs.findIndex(f=>f.id===i.id);return l>-1&&(this.outputs.splice(l,1),a&&(a==null||a.add(this,K.Affected))),a==null||a.attemptAutoclose("remove-output",this.id),this}setParent(i,a=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,P.SetParent))){var l;return this.checkCanEditWithCounterpartAndSideEffects(this,i,P.SetParent,a)?(((l=this.parent)==null?void 0:l.id)!==(i==null?void 0:i.id)&&(this.parent=i,a&&(a==null||a.add(this,K.Updated))),a==null||a.attemptAutoclose(P.SetParent,this.id),this):this}setImplements(i,a=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,P.SetImplements))){var l;return this.checkCanEdit(this)?(((l=this.implements)==null?void 0:l.id)!==(i==null?void 0:i.id)&&(this.implements=i,a&&(a==null||a.add(this,K.Updated))),a==null||a.attemptAutoclose(P.SetImplements,this.id),this):(J.warn(`[setImplements] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),a==null||a.attemptAutoclose(P.SetImplements,this.id),this)}setValueWriter(i,a=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,P.SetValueWriter))){return i&&!this.checkCanEditWithCounterpartAndSideEffects(this,i,P.SetValueWriter,a)?this:!i&&!this.checkCanEdit(this)?(J.warn(`[setValueWriter] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),a==null||a.attemptAutoclose(P.SetValueWriter,this.id),this):(this.readsValue!==i&&(this.readsValue=i,a==null||a.add(this,K.Updated)),a==null||a.attemptAutoclose(P.SetValueWriter,this.id),this)}removeValueWriter(i=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,P.RemoveValueWriter))){return this.readsValue&&!this.checkCanEditWithCounterpartAndSideEffects(this,this.readsValue,P.RemoveValueWriter,i)?this:(this.readsValue&&(this.readsValue=null,i==null||i.add(this,K.Updated)),i==null||i.attemptAutoclose(P.RemoveValueWriter,this.id),this)}initChildren(i=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,"init-children"))){if(this.initialized||this.startedInitialization)return this;if(this.startedInitialization=!0,this.initialData.defaultValue&&(this.defaultValue=se(this.initialData.defaultValue,this.project),this.defaultValue.setParent(this,null),this.defaultValue.initChildren(i)),this.initialData.dataType&&(this.setDataType(se(this.initialData.dataType,this.project),i),this.dataType.setParent(this,null),this.dataType.initChildren(i)),_d.initReadsValue(this),this.initialData.implements){const a=se(this.initialData.implements,this.project);this.setImplements(a,null)}return this.outputs=this.initialData.outputs.map(a=>{const l=se(a,this.project);return l.setParent(this,null),l.initChildren(i),l}),this.initialData.throws&&(this.throws=se(this.initialData.throws,this.project),this.throws.setParent(this,null),this.throws.initChildren(i)),this.subscribeToDependencies(),this.afterAllChildrenInitialized(i),i==null||i.attemptAutoclose("init-children",this.id),this}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(i,a=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,"meta-sync"))){const l=Xi(this,i),f=Yi(this,l),e=this.toMeta();return this.x=l.x||e.x,this.y=l.y||e.y,super.baseMetaSync(l,this),l.deleted===!0&&!e.deleted?a==null||a.add(this,K.Removed):l.deleted===!1&&e.deleted?a==null||a.add(this,K.Added):f&&(a==null||a.add(this,K.Updated)),a==null||a.attemptAutoclose("meta-sync",this.id),this}async APILoad(i=Ie,...a){return await ni.repository.APILoad(this.id,...a),this}async APICreate(i=Ie,...a){return await ni.repository.APICreate(this.toShallowJSON(),...a),this}async APIUpdate(i=Ie,...a){return await ni.repository.APIUpdate(this.toShallowJSON(),...a),this}async APIDelete(i=Ie,...a){return await ni.repository.APIDelete(this.toShallowJSON(),...a),this}async APIClone(i=Ie,...a){return await ni.repository.APIClone(this.id,...a),this}async APILoadVersion(i=Ie,a,...l){return await ni.repository.APILoadVersion(this.id,a,...l)}removeFromParent(i=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,P.RemoveFromParent))){if(!this.checkCanEdit(this))return J.warn(`[removeFromParent] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(P.RemoveFromParent,this.id),{added:[],updated:[],removed:[],affected:[],self:this};const a=[],l=[],f=[],e=[];return this.parent.removeReturnStatement(this),e.push(this.parent),i==null||i.attemptAutoclose(P.RemoveFromParent,this.id),{added:g(f),updated:g(a),removed:g(l),affected:g(e),self:this}}remove({ignoreUpstream:i}={ignoreUpstream:!1},a=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,P.RemoveEntity))){var v,T;if(!this.checkCanDelete(this)||!this.checkCanEdit(this))return J.warn(`[remove] User is not allowed to delete or edit this ${this.type} entity with id: ${this.id}`),a==null||a.event({id:`${P.RemoveEntity}-${this.id}`,action:P.RemoveEntity,owner:this,errorReason:Si.ActionOwnerEntityNonDeletable,rootAction:((v=a==null?void 0:a.self)==null?void 0:v.id)===this.id&&(a==null?void 0:a.autoCloseActionName)===P.RemoveEntity}),a==null||a.attemptAutoclose(P.RemoveEntity,this.id),{added:[],updated:[],removed:[],affected:[],self:this};const l=[],f=[],e=[],y=[];if(a!=null&&a.hasRemoved(this.id))return a==null||a.attemptAutoclose(P.RemoveEntity,this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(f.push(this),this.unsubscribe(),this.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},a),Object.values(this.detachedDependents).forEach(A=>{const{updated:I,removed:O,added:L}=A.entity.onDetachedDependencyRemoved(this,A.field,a);l.push(...I),f.push(...O),e.push(...L)}),this.readsValue&&(l.push(this.readsValue),this.readsValue.removeValueReader(this,a)),this.outputs.forEach(A=>{const{updated:I,removed:O}=A.remove({ignoreUpstream:!0},a);l.push(...I),f.push(...O)}),this.throws){const{updated:A,removed:I}=this.throws.remove({ignoreUpstream:!0},a);l.push(...A),f.push(...I)}if(this.dataType){const{updated:A,removed:I}=this.dataType.remove({ignoreUpstream:!0},a);l.push(...A),f.push(...I)}if(!i){const A=this.removeFromParent(a);e.push(...A.added),l.push(...A.updated),f.push(...A.removed),y.push(...A.affected),this.calledBy.forEach(I=>{l.push(I),I.removeCall(this,a)})}return a==null||a.add(this.parent,K.Affected),(T=this.parent)==null||T.returnStatements.forEach(A=>{A.id!==this.id&&(y.push(A),a==null||a.add(A,K.Affected))}),a==null||a.attemptAutoclose(P.RemoveEntity,this.id),{added:g(e),updated:g(l),removed:g(f),affected:g(y),self:this}}restore({}={},i=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,P.RestoreEntity))){if(!this.checkCanEdit(this))return J.warn(`[restore] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(P.RestoreEntity,this.id),{added:[],updated:[],removed:[],affected:[],self:this};const a=[],l=[],f=[],e=[];if(i!=null&&i.hasAdded(this.id))return i==null||i.attemptAutoclose(P.RestoreEntity,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:T,added:A}=y.entity.onDetachedDependencyRestored(this,y.field,i);l.push(...v),f.push(...T),a.push(...A)}),this.readsValue&&(l.push(this.readsValue),this.readsValue.addValueReader(this,i)),this.outputs.forEach(y=>{const{updated:v}=y.restore({},i);l.push(...v)}),this.throws){const{updated:y}=this.throws.restore({},i);l.push(...y)}if(this.dataType){const{updated:y}=this.dataType.restore({},i);l.push(...y)}return this.parent.addReturnStatement(this),this.calledBySuccess.forEach(y=>{l.push(y),y.addSuccessCall(this,i)}),this.calledByError.forEach(y=>{l.push(y),y.addErrorCall(this,i)}),this.calledByEntry.forEach(y=>{l.push(y),y.addCall(this,i)}),i==null||i.attemptAutoclose(P.RestoreEntity,this.id),{added:g(a),updated:g(l),removed:g(f),affected:g(e),self:this}}toFlat(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this,...this.outputs.flatMap(l=>l.toFlat(i)),...this.throws?this.throws.toFlat(i):[],...this.dataType?this.dataType.toFlat(i):[]])}toFlatIds(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.id,...this.outputs.flatMap(l=>l.toFlatIds(i)),...this.throws?this.throws.toFlatIds(i):[],...this.dataType?this.dataType.toFlatIds(i):[]])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,x:this.x,y:this.y,type:this.type,editable:this.editable,deletable:this.deletable}}toJSON(i=new Set){var a,l,f,e,y,v;return i.has(this.id)?this.toReference():(i.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,editable:this.editable,deletable:this.deletable,x:this.x,y:this.y,defaultValue:((a=this.defaultValue)==null?void 0:a.toJSON(i))||null,dataType:((l=this.dataType)==null?void 0:l.toJSON(i))||null,readsValue:((f=this.readsValue)==null?void 0:f.toReference())||null,implements:((e=this.implements)==null?void 0:e.toJSON(i))||null,calledBySuccess:this.calledBySuccess.map(T=>T.toReference()),calledByError:this.calledByError.map(T=>T.toReference()),calledByEntry:this.calledByEntry.map(T=>T.toReference()),outputs:this.outputs.map(T=>T.toJSON(i)),parent:((y=this.parent)==null?void 0:y.toReference())||null,throws:((v=this.throws)==null?void 0:v.toJSON(i))||null})}toJSONClone(i=ke){var l,f,e,y,v,T,A,I,O,L;let a;return(l=i.seenEntityMaps)!=null&&l.has(this.id)?a=i.seenEntityMaps.get(this.id):(a=i.newId||or(this,this.project,i.uuidStrategy),i.seenEntityMaps&&i.seenEntityMaps.set(this.id,a)),(f=i.seenEntities)!=null&&f.has(a)||(e=i.seenEntities)!=null&&e.has(this.id)?this.toReference({seenEntityMaps:i.seenEntityMaps}):((y=i.seenEntities)==null||y.add(a),(v=i.seenEntities)==null||v.add(this.id),{id:a,version:V.UUID.uuid(),createdAt:i.timestamp||B().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,editable:this.editable,deletable:this.deletable,x:this.x,y:this.y,defaultValue:((T=this.defaultValue)==null?void 0:T.toJSONClone({...i,newId:null}))||null,dataType:((A=this.dataType)==null?void 0:A.toJSONClone({...i,newId:null}))||null,readsValue:((I=this.readsValue)==null?void 0:I.toReference({seenEntityMaps:i.seenEntityMaps}))||null,implements:(()=>{var M;return this.implements&&this.project.getBuiltIn(this.implements.id)?this.implements.toJSON():((M=this.implements)==null?void 0:M.toJSONClone({...i,newId:null}))||null})(),calledBySuccess:this.calledBySuccess.map(M=>M.toReference({seenEntityMaps:i.seenEntityMaps})),calledByError:this.calledByError.map(M=>M.toReference({seenEntityMaps:i.seenEntityMaps})),calledByEntry:this.calledByEntry.map(M=>M.toReference({seenEntityMaps:i.seenEntityMaps})),outputs:this.outputs.map(M=>M.toJSONClone({...i,newId:null})),parent:((O=this.parent)==null?void 0:O.toReference({seenEntityMaps:i.seenEntityMaps}))||null,throws:((L=this.throws)==null?void 0:L.toJSONClone({...i,newId:null}))||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+"--"+V.UUID.uuid()+"--ref",type:p.GenericReference,entityId:a,version:this.version,entityType:this.type}}toShallowJSON(i=ke){var l,f,e,y,v,T,A;let a=this.id;return(l=i.seenEntityMaps)!=null&&l.has(this.id)&&(a=i.seenEntityMaps.get(this.id)),{id:a,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,editable:this.editable,deletable:this.deletable,x:this.x,y:this.y,defaultValue:((f=this.defaultValue)==null?void 0:f.toReference(i))||null,dataType:((e=this.dataType)==null?void 0:e.toReference(i))||null,readsValue:((y=this.readsValue)==null?void 0:y.toReference(i))||null,implements:((v=this.implements)==null?void 0:v.toReference(i))||null,outputs:this.outputs.map(I=>I.toReference(i)),calledBySuccess:this.calledBySuccess.map(I=>I.toReference(i)),calledByError:this.calledByError.map(I=>I.toReference(i)),calledByEntry:this.calledByEntry.map(I=>I.toReference(i)),throws:((T=this.throws)==null?void 0:T.toReference(i))||null,parent:((A=this.parent)==null?void 0:A.toReference(i))||null}}toFlatJSON(i=new Set){var l,f,e;return i.has(this.id)?[]:(i.add(this.id),[this.toShallowJSON(),...((l=this.defaultValue)==null?void 0:l.toFlatJSON(i))||[],...((f=this.dataType)==null?void 0:f.toFlatJSON(i))||[],...((e=this.implements)==null?void 0:e.toFlatJSON(i))||[],...this.outputs.flatMap(y=>y.toFlatJSON(i)),...this.throws?this.throws.toFlatJSON(i):[]])}toGenerationTarget(){var i;return{id:this.id,type:this.type,calledByEntry:this.calledByEntry.map(a=>a.id),calledByError:this.calledByError.map(a=>a.id),calledBySuccess:this.calledBySuccess.map(a=>a.id),implements:(i=this.implements)==null?void 0:i.id,parent:this.parent.id}}toFlatGenerationTarget(i=new Set){var l,f,e;return i.has(this.id)?[]:(i.add(this.id),[this.toGenerationTarget(),...((l=this.defaultValue)==null?void 0:l.toFlatGenerationTarget(i))||[],...((f=this.dataType)==null?void 0:f.toFlatGenerationTarget(i))||[],...((e=this.implements)==null?void 0:e.toFlatGenerationTarget(i))||[],...this.outputs.flatMap(y=>y.toFlatGenerationTarget(i)),...this.throws?this.throws.toFlatGenerationTarget(i):[]])}clearErrors(){var i,a,l;return this.errors=[],(i=this.dataType)==null||i.clearErrors(),(a=this.defaultValue)==null||a.clearErrors(),this.outputs.forEach(f=>f.clearErrors()),(l=this.throws)==null||l.clearErrors(),this}validate(){const i=fK(this);return this.errors=i,{success:!0}}getErrors(){var a,l;return[...this.errors,...((a=this.defaultValue)==null?void 0:a.getErrors())||[],...((l=this.dataType)==null?void 0:l.getErrors())||[],...this.outputs.flatMap(f=>f.getErrors())]}getShallowErrors(){return this.errors}getDefaultValue(){return this.defaultValue||null}setDefaultValue(i,a=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,"set-default-value"))){if(!this.checkCanEdit(this))return J.warn(`[setDefaultValue] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),a==null||a.attemptAutoclose("set-default-value",this.id),this;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,K.Affected)),a==null||a.attemptAutoclose("set-default-value",this.id),this}clone(i=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,P.CloneEntity)),a=null,l=null,f=!0){var j,q,Z;let e=lr(a,this);const y=this.toJSON(),v=l||V.UUID.uuid();y.outputs=[];const T=v.split("-id"),A=T[T.length-1||0]||v;y.id=v,y.version=V.UUID.uuid(),y.createdAt=(i==null?void 0:i.timestamp)||B().toISOString(),y.author=(i==null?void 0:i.author)||"1",y.previousVersion=null,y.deleted=!1,y.deletable=!0,y.editable=!0;const I=Ei(y,e);a?I.setParent(a,null):I.setParent(this.parent,null),f&&I.subscribe(),I.initChildren(i),i==null||i.add(I,K.Added);const O=(j=this.dataType)==null?void 0:j.clone(i,I,V.UUID.uuid(),f);I.setDataType(O||null,i);const L=(q=this.defaultValue)==null?void 0:q.clone(i,I,V.UUID.uuid(),f);I.setDefaultValue(L||null,i),this.implements&&I.setImplements(this.implements,i);const M=(Z=this.outputs)==null?void 0:Z.map((S,H)=>S.clone(i,I,A+"-return-declaration-"+H+"-id",f));return I.outputs=M,this.throws&&(I.throws=this.throws.clone(i,I,A+"-throws-id",f)),i==null||i.attemptAutoclose(P.CloneEntity,this.id),I}syncInputs(i=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,"sync-returned-inputs"))){var M,j;const a=[],l=[],f=[],e=[],y=fr(this,this.project);if(!y.implements)return this.throws&&this.outputs.length&&this.outputs.forEach(q=>{var Z;if(q.id!==((Z=this.throws)==null?void 0:Z.id)){const{updated:S,removed:H}=q.remove({ignoreUpstream:!0},i);a.push(...S),f.push(...H),this.removeOutput(q,i)}}),i==null||i.attemptAutoclose("sync-returned-inputs",this.id),{updated:g(a),added:g(l),removed:g(f),affected:g(e),self:this};const v=(j=(M=y.implements)==null?void 0:M.dataType)==null?void 0:j.entity,T=(v==null?void 0:v.type)===p.DefinitionEntity?v.properties:[],A=y.implements.error,I=T;if(A&&!this.throws){const q=A.implementAsInputMap(i,this);return l.push(q),this.outputs.forEach(Z=>{if(Z.id!==q.id){const{updated:S,removed:H}=Z.remove({ignoreUpstream:!0},i);a.push(...S),f.push(...H),this.removeOutput(Z,i)}}),i==null||i.attemptAutoclose("sync-returned-inputs",this.id),{updated:g(a),added:g(l),removed:g(f),affected:g(e),self:this}}if(!A&&this.throws){const{updated:q,removed:Z}=this.throws.remove({ignoreUpstream:!0},i);a.push(...q),f.push(...Z)}return I.filter(q=>!this.outputs.find(Z=>{var S;return((S=Z.declaration)==null?void 0:S.id)===q.id&&(Z.declaration.type===p.ValueDescriptor?Z.declaration.parentRelationType!==ye.ReturnedError:!0)})).forEach(q=>{const Z=q.implementAsInputMap(i,this);l.push(Z)}),i==null||i.attemptAutoclose("sync-returned-inputs",this.id),{updated:g(a),added:g(l),removed:g(f),affected:g(e),self:this}}setDataType(i,a=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,P.SetDataType))){if(!this.checkCanEdit(this))return J.warn(`[setDataType] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),a==null||a.attemptAutoclose(P.SetDataType,this.id),this;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,K.Affected)),a==null||a.attemptAutoclose(P.SetDataType,this.id),this}removeDataType(i=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,P.RemoveDataType))){return this.checkCanEdit(this)?(this.dataType&&(this.dataType.remove({ignoreUpstream:!0},i),i==null||i.add(this,K.Affected),this.dataType=null),i==null||i.attemptAutoclose(P.RemoveDataType,this.id),this):(J.warn(`[removeDataType] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(P.RemoveDataType,this.id),this)}getDataType(i=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,"get-data-type"))){var l;if((!this.dataType||this.dataType.inferred)&&this.project.initialized,this.dataType)return i==null||i.attemptAutoclose("get-data-type",this.id),this.dataType;const a=(l=this.implements)==null?void 0:l.getDataType(i);return i==null||i.attemptAutoclose("get-data-type",this.id),a||null}};_(ni,"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}),_(ni,"type",p.ReturnStatement),_(ni,"USER_MANAGED_PARENT_TYPES",[...qi]),_(ni,"PARENT_TYPES",[...ni.USER_MANAGED_PARENT_TYPES]),_(ni,"MUTABLE_BASE_PROPERTIES",[]),_(ni,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),_(ni,"BASE_PROPERTIES",[...ni.MUTABLE_BASE_PROPERTIES,...ni.INMUTABLE_BASE_PROPERTIES]),_(ni,"MUTABLE_META_PROPERTIES",["x","y"]),_(ni,"INMUTABLE_META_PROPERTIES",[...ni.INMUTABLE_BASE_PROPERTIES]),_(ni,"META_PROPERTIES",[...ni.MUTABLE_META_PROPERTIES,...ni.INMUTABLE_META_PROPERTIES]),_(ni,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry","readsValue"]),_(ni,"INMUTABLE_UPSTREAM_PROPERTIES",["parent"]),_(ni,"UPSTREAM_PROPERTIES",[...ni.MUTABLE_UPSTREAM_PROPERTIES,...ni.INMUTABLE_UPSTREAM_PROPERTIES]),_(ni,"MUTABLE_DOWNSTREAM_PROPERTIES",["outputs","throws"]),_(ni,"INMUTABLE_DOWNSTREAM_PROPERTIES",["dataType","defaultValue"]),_(ni,"DOWNSTREAM_PROPERTIES",[...ni.MUTABLE_DOWNSTREAM_PROPERTIES,...ni.INMUTABLE_DOWNSTREAM_PROPERTIES]),_(ni,"PROPERTIES",[...ni.META_PROPERTIES,...ni.UPSTREAM_PROPERTIES,...ni.DOWNSTREAM_PROPERTIES]);let eo=ni;function yK(d){const u=xn(d);d.inputs.forEach(a=>a.validate()),u.forEach(a=>a.validate());const i=[...Nw(d)];return $i(d.errors,i)}const Rge=Object.freeze(Object.defineProperty({__proto__:null,validate:yK},Symbol.toStringTag,{value:"Module"})),Zt=class Zt extends nr{constructor(i,a){super(i);_(this,"initialData");_(this,"id");_(this,"name");_(this,"description",null);_(this,"x");_(this,"y");_(this,"collapsed");_(this,"type",p.GlobalEvent);_(this,"inputs",[]);_(this,"calls",[]);_(this,"parent");_(this,"implements");_(this,"detachedChildren",[]);_(this,"errors",[]);_(this,"project");_(this,"detachedDependents",{});_(this,"knownVersions",null);_(this,"activeVersion",!1);_(this,"initialized",!1);_(this,"startedInitialization",!1);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.collapsed=i.collapsed}static new(i=null){return{id:V.UUID.uuid(),version:V.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||B().toISOString(),author:(i==null?void 0:i.author)||V.sessionAuthor,previousVersion:null,deleted:!1,deletable:!0,editable:!0,type:p.GlobalEvent,name:"",description:"",collapsed:!1,implements:null,inputs:[],parent:null,calls:[],x:0,y:0}}static fromGenerationTarget(i,a){let l=a;if(i.parent){const v=X(i.parent);l=a.get(v)}let f;i.implements&&(f=a.getBuiltIn(i.implements));const e={id:i.id,version:V.UUID.uuid(),createdAt:B().toISOString(),author:V.sessionAuthor,previousVersion:null,deleted:!1,name:i.name,description:i.description||null,deletable:!0,editable:!0,type:p.GlobalEvent,collapsed:!1,calls:[],inputs:[],implements:f,x:0,y:0,parent:l},y=se(e,a);return y.setParent(l,null),y}static validateGenerationTarget(i,a){let l=JSON.parse(JSON.stringify(i));const f=[],e=Pr(l,{},a);if(l=e.modifiedData,f.push(...e.errors,...zi(l)),!i.implements)f.push(new oe({id:`${i.id}--${le.InvalidObjectStructure}`,code:le.InvalidObjectStructure,severity:Y.Error,message:`Entity of type '${i.type}' with id '${i.id}' is missing the 'implements' property. This property is required for a '${i.type}' entity and must point to one of the built-in action descriptors reserved for 'global-event' entities.
|
|
50
50
|
${N0(a)}`}));else if(!a.get(i.implements))f.push(new oe({id:`${i.id}--${W.ReferencedEntityNotFound}`,code:W.ReferencedEntityNotFound,severity:Y.Error,message:`Entity of type '${i.type}' with id '${i.id}' has an 'implements' property that isn't found in the project. The 'implements' property must point to one of the built-in action descriptors reserved for 'global-event' entities.
|
|
51
51
|
${N0(a)}`}));else if(!a.globalEventActionDescriptors.find(T=>T.id===i.implements))f.push(new oe({id:`${i.id}--${W.InvalidImplementsReference}`,code:W.InvalidImplementsReference,severity:Y.Error,message:`Entity of type '${i.type}' with id '${i.id}' has an 'implements' property that isn't pointing to an action descriptor reserved for 'global-event' entities.
|
|
52
52
|
${N0(a)}`}));else{const T=a.events.find(A=>A.implements.id===i.implements);T&&f.push(new oe({id:`${i.id}--${W.InvalidImplementsReference}`,code:W.InvalidImplementsReference,severity:Y.Error,message:`Entity of type '${i.type}' with id '${i.id}' has an 'implements' property that points to an action descriptor that is already implemented by another global event with id '${T.id}' in the project. Each global event must implement a unique action descriptor.
|
|
@@ -179,10 +179,10 @@ Or 'delete' and then 'post' actions to replace it.`})):i.push(new oe({id:`${d.id
|
|
|
179
179
|
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.`})),{errors:a,modifiedData:i}}subscribeDependents(i){return i.forEach(a=>{this.detachedDependents[a.entity.id]||(this.detachedDependents[a.entity.id]=a)}),this}unsubscribeDependents(i){return i.forEach(a=>{this.detachedDependents[a.entity.id]&&delete this.detachedDependents[a.entity.id]}),this}syncDependents(i=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,"sync-dependents"))){const a=[],l=[],f=[],e=[];return Object.values(this.detachedDependents).forEach(y=>{const v=y.entity.afterAllChildrenInitialized(i);a.push(...v.updated),l.push(...v.added),f.push(...v.removed),e.push(...v.affected)}),i==null||i.attemptAutoclose("sync-dependents",this.id),{updated:g(a),added:g(l),removed:g(f),affected:g(e),self:this}}onDetachedDependencyRemoved(i,a,l){const f=[],e=[],y=[],v=[];return a==="value-as-type-single"&&(this.valueAsTypeSingle=null,l==null||l.add(this,K.Updated)),a==="value-as-type-list"&&(this.valueAsTypeList=(this.valueAsTypeList||[]).filter(T=>T.id!==i.id),l==null||l.add(this,K.Updated)),{updated:g(f),added:g(e),removed:g(y),affected:g(v),self:this}}onDetachedDependencyRestored(i,a,l){const f=[],e=[],y=[],v=[];return a==="value-as-type-single"&&(this.valueAsTypeSingle=i,l==null||l.add(this,K.Updated)),a==="value-as-type-list"&&(this.valueAsTypeList=[...Array.isArray(this.valueAsTypeList||[])?this.valueAsTypeList:[],i],l==null||l.add(this,K.Updated)),{updated:g(f),added:g(e),removed:g(y),affected:g(v),self:this}}unsubscribeFromDependencies(){return this.valueAsTypeSingle&&this.valueAsTypeSingle.type!==p.BuiltInBaseEntity&&this.valueAsTypeSingle.unsubscribeDependents([{entity:this,field:"value-as-type-single"}]),this.valueAsTypeList&&Array.isArray(this.valueAsTypeList)&&this.valueAsTypeList.forEach(i=>{i.type!==p.BuiltInBaseEntity&&i.unsubscribeDependents([{entity:this,field:"value-as-type-list"}])}),this}subscribeToDependencies(){return!this.valueAsTypeSingle&&!this.valueAsTypeList?this:(this.valueAsTypeList&&Array.isArray(this.valueAsTypeList)?this.valueAsTypeList.forEach(i=>{i.type!==p.BuiltInBaseEntity&&i.subscribeDependents([{entity:this,field:"value-as-type-list"}])}):this.valueAsTypeSingle&&this.valueAsTypeSingle.type!==p.BuiltInBaseEntity&&this.valueAsTypeSingle.subscribeDependents([{entity:this,field:"value-as-type-single"}]),this)}increaseVersion(i){if(i&&!B(i).isValid())throw new Error(`The shared timestamp '${i}' is not a valid ISO 8601 date string.`);return i&&B(i).isSame(B(this.createdAt))?this:(this.previousVersion=this.version,this.version=V.UUID.uuid(),this.createdAt=B(i).toISOString()||B().toISOString(),this)}captureVersion(){var a;const i=((a=this.knownVersions)==null?void 0:a.get(this.version))||new 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.valueAsTypeSingle=this.valueAsTypeSingle,i.valueAsTypeList=this.valueAsTypeList?[...this.valueAsTypeList]:this.valueAsTypeList,i.parent=this.parent,this}recursiveCaptureUpstreamVersions(i){const a=[],l=[],f=[],e=[];if(this.parent){this.parent.increaseVersion(i);const y=this.parent.recursiveCaptureUpstreamVersions(i);a.push(this.parent,...y.updated),l.push(...y.added),f.push(...y.removed)}return{updated:g(a),added:g(l),removed:g(f),affected:g(e),self:this}}async restoreVersion(i){var v;const a=[],l=[],f=[],e=[];if(this.version===i)return{updated:g(a),added:g(l),removed:g(f),affected:g(e),self:this};if(!this.knownVersions){const T=new Map;for(const[A,I]of this.knownVersions||new Map){if(T.set(A,I),I.activeVersion=!1,I.knownVersions)for(const[O,L]of I.knownVersions)T.set(O,L);I.knownVersions=null}}let y=(v=this.knownVersions)==null?void 0:v.get(i);if(!y){const T=await this.APILoadVersion({},i);if(!T)throw new Error(`Version with id '${i}' for entity with id '${this.id}' not found.`);y=new Qt(T,this.project)}return this.metaSync(y.toShallowJSON(),null),this.previousVersion=y.previousVersion,this.version=y.version,this.createdAt=y.createdAt,this.author=y.author,this.deleted=y.deleted,this.valueAsTypeSingle=y.valueAsTypeSingle,this.parent=y.parent,{updated:g(a),added:g(l),removed:g(f),affected:g(e),self:this}}updateWithShallowTransfer(i,a=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,P.UpdateWithShallowTransfer))){if(!this.checkCanEdit(this))return J.warn(`[updateWithShallowTransfer] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),a==null||a.attemptAutoclose(P.UpdateWithShallowTransfer,this.id),this;if(this.metaSync(i,a),this.version=i.version,this.createdAt=i.createdAt,this.author=i.author,this.deleted=i.deleted,this.previousVersion=i.previousVersion,i.parent&&i.standaloneParent)throw new Error(`Entity with id '${this.id}' cannot have both 'parent' and 'standaloneParent' properties set.`);if(i.parent){const l=X(i.parent),f=this.project.get(l),e=this.parent;if(e&&e.id!==(f==null?void 0:f.id)&&this.removeFromParent(a),f)this.setParent(f,null);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else if(i.standaloneParent){const l=X(i.standaloneParent),f=this.project.get(l);if(f)this.setStandaloneParent(f);else throw new Error(`${this.type} with id '${this.id}' has a 'standaloneParent' reference '${l}' that isn't found in the project`)}else throw new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(i.valueAsTypeList&&Array.isArray(i.valueAsTypeList))this.valueAsTypeList=this.valueAsTypeList||[],i.valueAsTypeList.forEach(l=>{const f=X(l),e=this.project.get(f);e&&this.valueAsTypeList.push(e)});else if(i.valueAsTypeSingle){const l=X(i.valueAsTypeSingle),f=this.project.get(l);f&&(this.valueAsTypeSingle=f)}return this.captureVersion(),this.subscribeToDependencies(),a==null||a.attemptAutoclose(P.UpdateWithShallowTransfer,this.id),this}hydrateAncestors(){const i=[],a=[],l=[],f=[];if(this.initialData.parent&&this.initialData.standaloneParent)throw new Error(`Entity with id '${this.id}' cannot have both 'parent' and 'standaloneParent' properties set.`);if(this.initialData.parent){const e=X(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 if(this.initialData.standaloneParent){const e=X(this.initialData.standaloneParent),y=this.project.get(e);if(y)this.setStandaloneParent(y);else throw new Error(`${this.type} with id '${this.id}' has a 'standaloneParent' 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.valueAsTypeList&&Array.isArray(this.initialData.valueAsTypeList))this.valueAsTypeList=this.valueAsTypeList||[],this.initialData.valueAsTypeList.forEach(e=>{const y=X(e),v=this.project.get(y);v&&this.valueAsTypeList.push(v)});else if(this.initialData.valueAsTypeSingle){const e=X(this.initialData.valueAsTypeSingle),y=this.project.get(e);y&&(this.valueAsTypeSingle=y)}return{updated:g(i),added:g(a),removed:g(l),affected:g(f),self:this}}afterAllChildrenInitialized(i=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,P.AfterAllChildrenInitialized))){if(!this.checkCanEdit(this))return J.warn(`[afterAllChildrenInitialized] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(P.AfterAllChildrenInitialized,this.id),{updated:[],added:[],removed:[],affected:[],self:this};const a=[],l=[],f=[],e=[];return this.initialized=!0,this.captureVersion(),i==null||i.attemptAutoclose(P.AfterAllChildrenInitialized,this.id),{updated:g(a),added:g(l),removed:g(f),affected:g(e),self:this}}addSelfToProject(i=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,"add-self-to-project"))){var y,v;const a=[this],l=[],f=[],e=[];return((y=this.parent)==null?void 0:y.type)===p.DataType?this.parent.setEntity(this,i):(v=this.parent)==null||v.setDefaultValue(this,i),e.push(this.parent),this.subscribe(),this.subscribeToDependencies(),i==null||i.attemptAutoclose("add-self-to-project",this.id),{updated:g(a),added:g(l),removed:g(f),affected:g(e),self:this}}setParent(i,a=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,P.SetParent))){var l;return this.checkCanEditWithCounterpartAndSideEffects(this,i,P.SetParent,a)?(((l=this.parent)==null?void 0:l.id)!==(i==null?void 0:i.id)&&(this.parent=i,a&&(a==null||a.add(this,K.Updated))),a==null||a.attemptAutoclose(P.SetParent,this.id),this):this}setStandaloneParent(i){return this.standaloneParent=i,this}setValueAsTypeSingle(i,a=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,P.SetValueAsTypeSingle))){return this.checkCanEdit(this)?(this.valueAsTypeSingle!==i&&(this.valueAsTypeSingle=i,a==null||a.add(this,K.Updated)),a==null||a.attemptAutoclose(P.SetValueAsTypeSingle,this.id),this):(J.warn(`[setValueAsTypeSingle] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),a==null||a.attemptAutoclose(P.SetValueAsTypeSingle,this.id),this)}setValueAsTypeList(i,a=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,P.SetValueAsTypeList))){var l,f;return this.checkCanEdit(this)?(!i&&this.valueAsTypeList?(this.valueAsTypeList=null,a==null||a.add(this,K.Updated)):i&&!this.valueAsTypeList?(this.valueAsTypeList=i,a==null||a.add(this,K.Updated)):i&&this.valueAsTypeList&&((l=this.valueAsTypeList)==null?void 0:l.length)!==i.length?(this.valueAsTypeList=i,a==null||a.add(this,K.Updated)):i&&this.valueAsTypeList&&((f=this.valueAsTypeList)!=null&&f.every((e,y)=>e!==i[y]))&&(this.valueAsTypeList=i,a==null||a.add(this,K.Updated)),a==null||a.attemptAutoclose(P.SetValueAsTypeList,this.id),this):(J.warn(`[setValueAsTypeList] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),a==null||a.attemptAutoclose(P.SetValueAsTypeList,this.id),this)}setValueAsType(i,a=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,P.SetValueAsType))){return this.checkCanEdit(this)?i?(Array.isArray(i)?this.setValueAsTypeList(i,a):this.setValueAsTypeSingle(i,a),a==null||a.attemptAutoclose(P.SetValueAsType,this.id),this):(this.setValueAsTypeSingle(null,a),this.setValueAsTypeList(null,a),this):(J.warn(`[setValueAsType] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),a==null||a.attemptAutoclose(P.SetValueAsType,this.id),this)}initChildren(i=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,"init-children"))){if(this.initialized||this.startedInitialization)return this;if(this.startedInitialization=!0,this.standalone){if(this.initialData.valueAsTypeList&&Array.isArray(this.initialData.valueAsTypeList))this.valueAsTypeList=this.initialData.valueAsTypeList.map(a=>{if(a.type===p.GenericReference){const f=this.project.findSubscribedBuiltInInstanceFromReference(a);if(!f)throw new Error(`Standalone entity of type '${this.type}' with id '${this.id}' has a reference to an entity of type '${a.entityType}' with id '${a.entityId}' that is not part of the project state.`);return f}const l=this.project.get(a.id);if(!l)throw new Error(`Standalone entity of type '${this.type}' with id '${this.id}' has a reference to an entity of type '${a.type}' with id '${a.id}' that is not part of the project state.`);return l});else if(this.initialData.valueAsTypeSingle){if(this.initialData.valueAsTypeSingle.type===p.GenericReference){const l=this.project.findSubscribedBuiltInInstanceFromReference(this.initialData.valueAsTypeSingle);if(!l)throw new Error(`Standalone entity of type '${this.type}' with id '${this.id}' has a reference to an entity of type '${this.initialData.valueAsTypeSingle.entityType}' with id '${this.initialData.valueAsTypeSingle.entityId}' that is not part of the project state.`);return this.valueAsTypeSingle=l,this}const a=this.project.get(this.initialData.valueAsTypeSingle.id);if(!a)throw new Error(`Standalone entity of type '${this.type}' with id '${this.id}' has a reference to an entity of type '${this.initialData.valueAsTypeSingle.type}' with id '${this.initialData.valueAsTypeSingle.id}' that is not part of the project state.`);this.valueAsTypeSingle=a}return this}if(this.initialData.valueAsTypeList&&Array.isArray(this.initialData.valueAsTypeList))this.valueAsTypeList=this.initialData.valueAsTypeList.map(a=>{if(a.type===p.GenericReference){const f=this.project.findSubscribedBuiltInInstanceFromReference(a);if(!f)throw new Error(`Standalone entity of type '${this.type}' with id '${this.id}' has a reference to an entity of type '${a.entityType}' with id '${a.entityId}' that is not part of the project state.`);return f}const l=this.project.get(a.id);if(!l)throw new Error(`Standalone entity of type '${this.type}' with id '${this.id}' has a reference to an entity of type '${a.type}' with id '${a.id}' that is not part of the project state.`);return l});else if(this.initialData.valueAsTypeSingle){if(this.initialData.valueAsTypeSingle.type===p.GenericReference){const l=X(this.initialData.valueAsTypeSingle),f=l?this.project.get(l):null;if(!f)throw new Error(`Standalone entity of type '${this.type}' with id '${this.id}' has a reference to an entity of type '${this.initialData.valueAsTypeSingle.entityType}' with id '${this.initialData.valueAsTypeSingle.entityId}' that is not part of the project state.`);return this.valueAsTypeSingle=f,this}const a=this.project.get(this.initialData.valueAsTypeSingle.id);if(!a)throw new Error(`Standalone entity of type '${this.type}' with id '${this.id}' has a reference to an entity of type '${this.initialData.valueAsTypeSingle.type}' with id '${this.initialData.valueAsTypeSingle.id}' that is not part of the project state.`);this.valueAsTypeSingle=a}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 G(this.project,V.sessionAuthor,B().toISOString(),this,!0,"meta-sync"))){const l=Xi(this,i),f=Yi(this,l),e=this.toMeta();return this.name=l.name!==void 0?l.name:e.name,this.autogeneration=l.autogeneration!==void 0?l.autogeneration:e.autogeneration,this.value=l.value!==void 0?l.value:e.value,super.baseMetaSync(l,this),l.deleted===!0&&!e.deleted?a==null||a.add(this,K.Removed):l.deleted===!1&&e.deleted?a==null||a.add(this,K.Added):f&&(a==null||a.add(this,K.Updated)),a==null||a.attemptAutoclose("meta-sync",this.id),this}async APILoad(i=Ie,...a){return await Qt.repository.APILoad(this.id,...a),this}async APICreate(i=Ie,...a){return await Qt.repository.APICreate(this.toShallowJSON(),...a),this}async APIUpdate(i=Ie,...a){return await Qt.repository.APIUpdate(this.toShallowJSON(),...a),this}async APIDelete(i=Ie,...a){return await Qt.repository.APIDelete(this.toShallowJSON(),...a),this}async APIClone(i=Ie,...a){return await Qt.repository.APIClone(this.id,...a),this}async APILoadVersion(i=Ie,a,...l){return await Qt.repository.APILoadVersion(this.id,a,...l)}removeFromParent(i=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,P.RemoveFromParent))){if(!this.checkCanEdit(this))return J.warn(`[removeFromParent] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(P.RemoveFromParent,this.id),{added:[],updated:[],removed:[],affected:[],self:this};const a=[],l=[],f=[],e=[];return this.parent&&(this.parent.type===p.DataType?this.parent.setEntity(null,i):ph.includes(this.parent.type)&&this.parent.setDefaultValue(null,i),e.push(this.parent)),i==null||i.attemptAutoclose(P.RemoveFromParent,this.id),{added:g(f),updated:g(a),removed:g(l),affected:g(e),self:this}}remove({ignoreUpstream:i}={ignoreUpstream:!1},a=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,P.RemoveEntity))){var v;if(!this.checkCanDelete(this)||!this.checkCanEdit(this))return J.warn(`[remove] User is not allowed to delete or edit this ${this.type} entity with id: ${this.id}`),a==null||a.event({id:`${P.RemoveEntity}-${this.id}`,action:P.RemoveEntity,owner:this,errorReason:Si.ActionOwnerEntityNonDeletable,rootAction:((v=a==null?void 0:a.self)==null?void 0:v.id)===this.id&&(a==null?void 0:a.autoCloseActionName)===P.RemoveEntity}),a==null||a.attemptAutoclose(P.RemoveEntity,this.id),{added:[],updated:[],removed:[],affected:[],self:this};const l=[],f=[],e=[],y=[];if(a!=null&&a.hasRemoved(this.id))return a==null||a.attemptAutoclose(P.RemoveEntity,this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(f.push(this),this.unsubscribe(),this.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},a),Object.values(this.detachedDependents).forEach(T=>{const{updated:A,removed:I,added:O}=T.entity.onDetachedDependencyRemoved(this,T.field,a);l.push(...A),f.push(...I),e.push(...O)}),!i){const T=this.removeFromParent(a);e.push(...T.added),l.push(...T.updated),f.push(...T.removed),y.push(...T.affected)}return a==null||a.attemptAutoclose(P.RemoveEntity,this.id),{added:g(e),updated:g(l),removed:g(f),affected:g(y),self:this}}restore({}={},i=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,P.RestoreEntity))){if(!this.checkCanEdit(this))return J.warn(`[restore] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(P.RestoreEntity,this.id),{added:[],updated:[],removed:[],affected:[],self:this};const a=[],l=[],f=[],e=[];return i!=null&&i.hasAdded(this.id)?(i==null||i.attemptAutoclose(P.RestoreEntity,this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},i),Object.values(this.detachedDependents).forEach(y=>{const{updated:v,removed:T,added:A}=y.entity.onDetachedDependencyRestored(this,y.field,i);l.push(...v),f.push(...T),a.push(...A)}),i==null||i.attemptAutoclose(P.RestoreEntity,this.id),{added:g(a),updated:g(l),removed:g(f),affected:g(e),self:this})}toFlat(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this,...this.valueAsTypeSingle?this.valueAsTypeSingle.toFlat(i):[],...this.valueAsTypeList&&Array.isArray(this.valueAsTypeList)?this.valueAsTypeList.flatMap(l=>l.toFlat(i)):[]])}toFlatIds(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.id,...this.valueAsTypeSingle?this.valueAsTypeSingle.toFlatIds(i):[],...this.valueAsTypeList&&Array.isArray(this.valueAsTypeList)?this.valueAsTypeList.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,value:this.value,autogeneration:this.autogeneration,type:this.type,editable:this.editable,deletable:this.deletable,name:this.name}}toJSON(i=new Set){var a,l,f;return i.has(this.id)?this.toReference():(i.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,editable:this.editable,deletable:this.deletable,name:this.name,autogeneration:this.autogeneration,value:this.value,valueAsTypeSingle:((a=this.valueAsTypeSingle)==null?void 0:a.toJSON(i))||null,valueAsTypeList:Array.isArray(this.valueAsTypeSingle)?this.valueAsTypeSingle.map(e=>e.toJSON(i)):null,parent:(l=this.parent)==null?void 0:l.toReference(),standaloneParent:(f=this.standaloneParent)==null?void 0:f.toReference()})}toJSONClone(i=ke){var l,f,e,y,v,T,A;let a;return(l=i.seenEntityMaps)!=null&&l.has(this.id)?a=i.seenEntityMaps.get(this.id):(a=i.newId||or(this,this.project,i.uuidStrategy),i.seenEntityMaps&&i.seenEntityMaps.set(this.id,a)),(f=i.seenEntities)!=null&&f.has(a)||(e=i.seenEntities)!=null&&e.has(this.id)?this.toReference({seenEntityMaps:i.seenEntityMaps}):((y=i.seenEntities)==null||y.add(a),(v=i.seenEntities)==null||v.add(this.id),{id:a,version:V.UUID.uuid(),createdAt:i.timestamp||B().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,editable:this.editable,deletable:this.deletable,name:this.name,autogeneration:this.autogeneration,value:this.value,valueAsTypeSingle:this.valueAsTypeSingle?this.project.getBuiltIn(this.valueAsTypeSingle.id)?this.valueAsTypeSingle.toJSON():this.valueAsTypeSingle.toJSONClone({...i,newId:null}):null,valueAsTypeList:this.valueAsTypeSingle&&Array.isArray(this.valueAsTypeSingle)?this.valueAsTypeSingle.map(I=>this.project.getBuiltIn(I.id)?I.toJSON(i.seenEntities):I.toJSONClone({...i,newId:null})):null,parent:(T=this.parent)==null?void 0:T.toReference({seenEntityMaps:i.seenEntityMaps}),standaloneParent:(A=this.standaloneParent)==null?void 0:A.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+"--"+V.UUID.uuid()+"--ref",type:p.GenericReference,entityId:a,version:this.version,entityType:this.type}}toShallowJSON(i=ke){var l,f,e,y;let a=this.id;return(l=i.seenEntityMaps)!=null&&l.has(this.id)&&(a=i.seenEntityMaps.get(this.id)),{id:a,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,editable:this.editable,deletable:this.deletable,name:this.name,valueAsTypeSingle:((f=this.valueAsTypeSingle)==null?void 0:f.toReference(i))||null,valueAsTypeList:Array.isArray(this.valueAsTypeSingle)?this.valueAsTypeSingle.map(v=>v.toReference(i)):null,value:this.value,autogeneration:this.autogeneration,parent:(e=this.parent)==null?void 0:e.toReference(i),standaloneParent:(y=this.standaloneParent)==null?void 0:y.toReference(i)}}toFlatJSON(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.toShallowJSON(),...this.valueAsTypeSingle?this.valueAsTypeSingle.toFlatJSON(i):[],...this.valueAsTypeList&&Array.isArray(this.valueAsTypeList)?this.valueAsTypeList.flatMap(l=>l.toFlatJSON(i)):[]])}toGenerationTarget(){var i,a,l;return{id:this.id,type:this.type,name:this.name,valueAsTypeSingle:((i=this.valueAsTypeSingle)==null?void 0:i.id)||null,valueAsTypeList:Array.isArray(this.valueAsTypeSingle)?this.valueAsTypeSingle.map(f=>f.id):null,value:this.value,autogeneration:this.autogeneration,parent:(a=this.parent)==null?void 0:a.id,standaloneParent:(l=this.standaloneParent)==null?void 0:l.id}}toFlatGenerationTarget(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.toGenerationTarget(),...this.valueAsTypeSingle?this.valueAsTypeSingle.toFlatGenerationTarget(i):[],...this.valueAsTypeList&&Array.isArray(this.valueAsTypeList)?this.valueAsTypeList.flatMap(l=>l.toFlatGenerationTarget(i)):[]])}clearErrors(){return this.errors=[],this}validate(){const i=NZ(this);return this.errors=i,{success:!0}}getErrors(){return[...this.errors]}getShallowErrors(){return this.errors}clone(i=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,P.CloneEntity)),a=null,l=null,f=!0){let e=lr(a,this);const y=this.toJSON(),v=l||V.UUID.uuid();y.id=v,y.version=V.UUID.uuid(),y.createdAt=(i==null?void 0:i.timestamp)||B().toISOString(),y.author=(i==null?void 0:i.author)||"1",y.previousVersion=null,y.deleted=!1,y.editable=!0,y.deletable=!0;const T=Ei(y,e);return T.initChildren(i),a&&T.setParent(a,null),i==null||i.add(T,K.Added),f&&T.subscribe(),i==null||i.attemptAutoclose(P.CloneEntity,this.id),T}merge(i,a=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,"merge-literal-value"))){const l=[],f=[],e=[],y=[];return this.valueAsTypeSingle!==(i==null?void 0:i.valueAsTypeSingle)&&(this.setValueAsType(i.valueAsTypeSingle,a),l.push(this)),this.value!==i.value&&(this.metaSync({value:i.value},a),l.push(this)),this.autogeneration!==i.autogeneration&&(this.metaSync({autogeneration:i.autogeneration},a),l.push(this)),this.name!==i.name&&(this.metaSync({name:i.name},a),l.push(this)),a==null||a.attemptAutoclose("merge-literal-value",this.id),{updated:g(l),added:g(f),removed:g(e),affected:g(y),self:this}}};_(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}),_(Qt,"type",p.LiteralValue),_(Qt,"USER_MANAGED_PARENT_TYPES",[p.DataType,p.InputMap,p.Property,p.ArgumentDeclaration,p.ReturnStatement,p.BreakStatement,p.ContinueStatement,p.VariableDeclaration,p.VariableInstance,p.ValueDescriptor,p.OutputMap]),_(Qt,"PARENT_TYPES",[...Qt.USER_MANAGED_PARENT_TYPES]),_(Qt,"MUTABLE_BASE_PROPERTIES",["name","autogeneration","value"]),_(Qt,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),_(Qt,"BASE_PROPERTIES",[...Qt.MUTABLE_BASE_PROPERTIES,...Qt.INMUTABLE_BASE_PROPERTIES]),_(Qt,"MUTABLE_META_PROPERTIES",[...Qt.MUTABLE_BASE_PROPERTIES]),_(Qt,"INMUTABLE_META_PROPERTIES",[...Qt.INMUTABLE_BASE_PROPERTIES]),_(Qt,"META_PROPERTIES",[...Qt.MUTABLE_META_PROPERTIES,...Qt.INMUTABLE_META_PROPERTIES]),_(Qt,"MUTABLE_UPSTREAM_PROPERTIES",[]),_(Qt,"INMUTABLE_UPSTREAM_PROPERTIES",["parent"]),_(Qt,"UPSTREAM_PROPERTIES",[...Qt.MUTABLE_UPSTREAM_PROPERTIES,...Qt.INMUTABLE_UPSTREAM_PROPERTIES]),_(Qt,"MUTABLE_DOWNSTREAM_PROPERTIES",["valueAsTypeSingle","valueAsTypeList"]),_(Qt,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),_(Qt,"DOWNSTREAM_PROPERTIES",[...Qt.MUTABLE_DOWNSTREAM_PROPERTIES,...Qt.INMUTABLE_DOWNSTREAM_PROPERTIES]),_(Qt,"PROPERTIES",[...Qt.META_PROPERTIES,...Qt.UPSTREAM_PROPERTIES,...Qt.DOWNSTREAM_PROPERTIES]);let wr=Qt;function LZ(d){var i;d.outputs.forEach(a=>a.validate()),(i=d.throws)==null||i.validate();const u=[];return $i(d.errors,u)}const KOe=Object.freeze(Object.defineProperty({__proto__:null,validate:LZ},Symbol.toStringTag,{value:"Module"}));var BZ=(d=>(d.Parent="break-statement-parent-field",d.ImplementsField="break-statement-implements-field",d.DataTypeEntity="break-statement-data-type-entity-field",d.DataType="break-statement-data-type-field",d))(BZ||{});const li=class li extends nr{constructor(i,a){super(i);_(this,"initialData");_(this,"id");_(this,"x");_(this,"y");_(this,"type",p.BreakStatement);_(this,"outputs",[]);_(this,"readsValue",null);_(this,"dataType",null);_(this,"defaultValue",null);_(this,"implements",null);_(this,"calledBySuccess",[]);_(this,"calledByError",[]);_(this,"calledByEntry",[]);_(this,"throws",null);_(this,"project");_(this,"errors",[]);_(this,"parent");_(this,"detachedDependents",{});_(this,"knownVersions",null);_(this,"activeVersion",!1);_(this,"initialized",!1);_(this,"startedInitialization",!1);_(this,"suggestion",!1);this.initialData=i,this.project=a,this.id=i.id,this.x=i.x,this.y=i.y}static new(i=null){return{id:V.UUID.uuid(),version:V.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||B().toISOString(),author:(i==null?void 0:i.author)||V.sessionAuthor,previousVersion:null,deleted:!1,deletable:!0,editable:!0,type:p.BreakStatement,outputs:[],defaultValue:null,dataType:null,implements:null,readsValue:null,calledBySuccess:[],calledByError:[],calledByEntry:[],throws:null,parent:null,x:0,y:0}}static fromGenerationTarget(i,a){const l=X(i.parent),f=a.get(l),e=i.calledByEntry.map(L=>{const M=X(L);return a.get(M)}),y=i.calledBySuccess.map(L=>{const M=X(L);return a.get(M)}),v=i.calledByError.map(L=>{const M=X(L);return a.get(M)});let T=null;if(i.readsValue){const L=X(i.readsValue);T=a.get(L)}let A=null;if(i.implements){const L=X(i.implements);A=a.get(L)}const I={id:i.id,version:V.UUID.uuid(),createdAt:B().toISOString(),author:V.sessionAuthor,previousVersion:null,deleted:!1,deletable:!0,editable:!0,type:p.BreakStatement,x:0,y:0,outputs:[],defaultValue:null,dataType:null,implements:A,readsValue:T,calledBySuccess:y,calledByError:v,calledByEntry:e,throws:null,parent:f},O=se(I,a);return O.setParent(f,null),O}static validateGenerationTarget(i,a){let l=JSON.parse(JSON.stringify(i));const f=[],e=Pr(l,{parent:{list:!1,types:[p.Loop]}},a);return l=e.modifiedData,f.push(...e.errors,...zi(l)),{errors:f,modifiedData:l}}validateGeneratedUpdate(i){const a=[];let l=JSON.parse(JSON.stringify(i));const f=Ad(l,this);return l=f.modifiedData,a.push(...f.errors),i.parent&&a.push(new oe({id:`${this.id}--${W.InvalidParentUpdate}`,code:W.InvalidParentUpdate,severity:Y.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.
|
|
180
180
|
If an entity is called by another, they must be in the same scope, which means they have the same parent.
|
|
181
181
|
You shouldn't have to manually update a 'parent' property.
|
|
182
|
-
Specifically for break statements the parent needs to always be the 'loop' entity that contains it.`})),{errors:a,modifiedData:i}}subscribeDependents(i){return i.forEach(a=>{this.detachedDependents[a.entity.id]||(this.detachedDependents[a.entity.id]=a)}),this}unsubscribeDependents(i){return i.forEach(a=>{this.detachedDependents[a.entity.id]&&delete this.detachedDependents[a.entity.id]}),this}syncDependents(i=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,"sync-dependents"))){const a=[],l=[],f=[],e=[];return Object.values(this.detachedDependents).forEach(y=>{const v=y.entity.afterAllChildrenInitialized(i);a.push(...v.updated),l.push(...v.added),f.push(...v.removed),e.push(...v.affected)}),i==null||i.attemptAutoclose("sync-dependents",this.id),{updated:g(a),added:g(l),removed:g(f),affected:g(e),self:this}}onDetachedDependencyRemoved(i,a,l){const f=[],e=[],y=[],v=[];if(a==="break-statement-implements-field"&&(this.setImplements(null,l),f.push(this)),a==="break-statement-parent-field"){const{updated:T,added:A,removed:I}=this.remove({ignoreUpstream:!1},l);f.push(...T),e.push(...A),y.push(...I)}return{updated:g(f),added:g(e),removed:g(y),affected:g(v),self:this}}onDetachedDependencyRestored(i,a,l){const f=[],e=[],y=[],v=[];if(a==="break-statement-implements-field"&&(this.setImplements(i,l),f.push(this)),a==="break-statement-parent-field"){const{updated:T,added:A,removed:I}=this.restore({},l);f.push(...T),e.push(...A),y.push(...I)}return{updated:g(f),added:g(e),removed:g(y),affected:g(v),self:this}}unsubscribeFromDependencies(){var i,a,l,f,e,y,v;return this.parent.unsubscribeDependents([{entity:this,field:"break-statement-parent-field"}]),(a=(i=this.implements)==null?void 0:i.unsubscribeDependents)==null||a.call(i,[{entity:this,field:"break-statement-implements-field"}]),(e=(f=(l=this.dataType)==null?void 0:l.entity)==null?void 0:f.unsubscribeDependents)==null||e.call(f,[{entity:this,field:"break-statement-data-type-entity-field"}]),(v=(y=this.dataType)==null?void 0:y.unsubscribeDependents)==null||v.call(y,[{entity:this,field:"break-statement-data-type-field"}]),this}subscribeToDependencies(){var i,a,l,f,e,y,v,T;return(i=this.parent)==null||i.subscribeDependents([{entity:this,field:"break-statement-parent-field"}]),(l=(a=this.implements)==null?void 0:a.subscribeDependents)==null||l.call(a,[{entity:this,field:"break-statement-implements-field"}]),(y=(e=(f=this.dataType)==null?void 0:f.entity)==null?void 0:e.subscribeDependents)==null||y.call(e,[{entity:this,field:"break-statement-data-type-entity-field"}]),(T=(v=this.dataType)==null?void 0:v.subscribeDependents)==null||T.call(v,[{entity:this,field:"break-statement-data-type-field"}]),this}increaseVersion(i){if(i&&!B(i).isValid())throw new Error(`The shared timestamp '${i}' is not a valid ISO 8601 date string.`);return i&&B(i).isSame(B(this.createdAt))?this:(this.previousVersion=this.version,this.version=V.UUID.uuid(),this.createdAt=B(i).toISOString()||B().toISOString(),this)}captureVersion(){var a;const i=((a=this.knownVersions)==null?void 0:a.get(this.version))||new li(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.outputs=[...this.outputs],i.readsValue=this.readsValue,i.defaultValue=this.defaultValue,i.dataType=this.dataType,i.implements=this.implements,i.throws=this.throws,i.calledBySuccess=[...this.calledBySuccess],i.calledByError=[...this.calledByError],i.calledByEntry=[...this.calledByEntry],i.parent=this.parent,this}recursiveCaptureUpstreamVersions(i){const a=[],l=[],f=[],e=[];if(this.parent){this.parent.increaseVersion(i);const y=this.parent.recursiveCaptureUpstreamVersions(i);a.push(this.parent,...y.updated),l.push(...y.added),f.push(...y.removed)}return{updated:g(a),added:g(l),removed:g(f),affected:g(e),self:this}}async restoreVersion(i){var v;const a=[],l=[],f=[],e=[];if(this.version===i)return{updated:g(a),added:g(l),removed:g(f),affected:g(e),self:this};if(!this.knownVersions){const T=new Map;for(const[A,I]of this.knownVersions||new Map){if(T.set(A,I),I.activeVersion=!1,I.knownVersions)for(const[O,L]of I.knownVersions)T.set(O,L);I.knownVersions=null}}let y=(v=this.knownVersions)==null?void 0:v.get(i);if(!y){const T=await this.APILoadVersion({},i);if(!T)throw new Error(`Version with id '${i}' for entity with id '${this.id}' not found.`);y=new li(T,this.project)}return this.metaSync(y.toShallowJSON(),null),this.previousVersion=y.previousVersion,this.version=y.version,this.createdAt=y.createdAt,this.author=y.author,this.deleted=y.deleted,this.outputs=y.outputs,this.readsValue=y.readsValue,this.defaultValue=y.defaultValue,this.dataType=y.dataType,this.implements=y.implements,this.throws=y.throws,this.calledBySuccess=y.calledBySuccess,this.calledByError=y.calledByError,this.calledByEntry=y.calledByEntry,this.parent=y.parent,{updated:g(a),added:g(l),removed:g(f),affected:g(e),self:this}}updateWithShallowTransfer(i,a=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,P.UpdateWithShallowTransfer))){if(!this.checkCanEdit(this))return J.warn(`[updateWithShallowTransfer] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),a==null||a.attemptAutoclose(P.UpdateWithShallowTransfer,this.id),this;if(this.metaSync(i,a),this.version=i.version,this.createdAt=i.createdAt,this.author=i.author,this.deleted=i.deleted,this.previousVersion=i.previousVersion,this.unsubscribeFromDependencies(),i.parent){const l=X(i.parent),f=this.project.get(l),e=this.parent;if(e&&e.id!==(f==null?void 0:f.id)&&this.removeFromParent(a),f)this.setParent(f,a);else throw a==null||a.attemptAutoclose(P.UpdateWithShallowTransfer,this.id),new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw a==null||a.attemptAutoclose(P.UpdateWithShallowTransfer,this.id),new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(i.readsValue){const l=X(i.readsValue),f=this.project.get(l),e=this.readsValue;e&&e.id!==(f==null?void 0:f.id)&&this.removeValueWriter(a),f&&this.setValueWriter(f,a)}return i.calledByEntry.forEach(l=>{const f=X(l),e=this.project.get(f);e&&(this.addEntryCaller(e,a),e.addCall(this,a))}),[...this.calledByEntry].forEach(l=>{i.calledByEntry.find(e=>X(e)===l.id)||(this.removeCaller(l,a),l.removeCall(this,a))}),i.calledBySuccess.forEach(l=>{const f=X(l),e=this.project.get(f);e&&(this.addSuccessCaller(e,a),e.addSuccessCall(this,a))}),[...this.calledBySuccess].forEach(l=>{i.calledBySuccess.find(e=>X(e)===l.id)||(this.removeCaller(l,a),l.removeCall(this,a))}),i.calledByError.forEach(l=>{const f=X(l),e=this.project.get(f);e&&(this.addErrorCaller(e,a),e.addErrorCall(this,a))}),[...this.calledBySuccess].forEach(l=>{i.calledBySuccess.find(e=>X(e)===l.id)||(this.removeCaller(l,a),l.removeCall(this,a))}),this.captureVersion(),this.subscribeToDependencies(),a==null||a.attemptAutoclose(P.UpdateWithShallowTransfer,this.id),this}hydrateAncestors(){const i=[],a=[],l=[],f=[];if(this.initialData.parent){const e=X(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.implements){const e=X(this.initialData.implements),y=this.project.get(e);if(y)this.setImplements(y,null),i.push(y);else if(e)throw new Error(`${rr(this.type)} with id '${this.id}' has a 'implements' reference "${e}" which is missing in the project`)}if(this.initialData.readsValue){const e=X(this.initialData.readsValue),y=this.project.get(e);y&&(this.setValueWriter(y,null),i.push(y))}return this.initialData.calledByEntry.forEach(e=>{const y=X(e),v=this.project.get(y);v&&(this.addEntryCaller(v,null),i.push(v))}),this.initialData.calledBySuccess.forEach(e=>{const y=X(e),v=this.project.get(y);v&&(this.addSuccessCaller(v,null),i.push(v))}),this.initialData.calledByError.forEach(e=>{const y=X(e),v=this.project.get(y);v&&(this.addErrorCaller(v,null),i.push(v))}),{updated:g(i),added:g(a),removed:g(l),affected:g(f),self:this}}afterAllChildrenInitialized(i=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,P.AfterAllChildrenInitialized))){if(!this.checkCanEdit(this))return J.warn(`[afterAllChildrenInitialized] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(P.AfterAllChildrenInitialized,this.id),{updated:[],added:[],removed:[],affected:[],self:this};const a=[],l=[],f=[],e=[];return this.initialized=!0,!this.dataType||this.dataType.inferred,this.parent.syncTerminationStatements(i),this.captureVersion(),i==null||i.attemptAutoclose(P.AfterAllChildrenInitialized,this.id),{updated:g(a),added:g(l),removed:g(f),affected:g(e),self:this}}addSelfToProject(i=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,"add-self-to-project"))){var y,v;const a=[this],l=[],f=[],e=[];return this.readsValue&&(this.readsValue.addValueReader(this,i),a.push(this.readsValue)),this.calledByEntry.forEach(T=>{T.addCall(this,i),a.push(T)}),this.calledBySuccess.forEach(T=>{T.addSuccessCall(this,i),a.push(T)}),this.calledByError.forEach(T=>{T.addErrorCall(this,i),a.push(T)}),this.parent.addBreakStatement(this),e.push(this.parent),i==null||i.add(this.parent,K.Affected),(y=this.parent)==null||y.breakStatements.forEach(T=>{T.id!==this.id&&(e.push(T),i==null||i.add(T,K.Affected))}),(v=this.parent)==null||v.continueStatements.forEach(T=>{T.id!==this.id&&(e.push(T),i==null||i.add(T,K.Affected))}),this.subscribe(),this.subscribeToDependencies(),i==null||i.attemptAutoclose("add-self-to-project",this.id),{updated:g(a),added:g(l),removed:g(f),affected:g(e),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}addSuccessCaller(i,a=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,P.AddSuccessCaller)),l=!1){return this.checkCanEditWithCounterpartAndSideEffects(this,i,P.AddSuccessCaller,a)?(this.calledBySuccess.find(f=>f.id===i.id)||(this.calledBySuccess.push(i),a==null||a.add(this,K.Updated),l&&Ye(this,a)),a==null||a.attemptAutoclose(P.AddSuccessCaller,this.id),this):this}addErrorCaller(i,a=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,P.AddErrorCaller)),l=!1){return this.checkCanEditWithCounterpartAndSideEffects(this,i,P.AddErrorCaller,a)?(this.calledByError.find(f=>f.id===i.id)||(this.calledByError.push(i),a==null||a.add(this,K.Updated),l&&Ye(this,a)),a==null||a.attemptAutoclose(P.AddErrorCaller,this.id),this):this}addEntryCaller(i,a=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,P.AddEntryCaller)),l=!1){return this.checkCanEditWithCounterpartAndSideEffects(this,i,P.AddEntryCaller,a)?(this.calledByEntry.find(f=>f.id===i.id)||(this.calledByEntry.push(i),a==null||a.add(this,K.Updated),l&&Ye(this,a)),a==null||a.attemptAutoclose(P.AddEntryCaller,this.id),this):this}removeCaller(i,a=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,"remove-caller")),l=!1){return this.checkCanEditWithCounterpartAndSideEffects(this,i,P.RemoveCaller,a)?(this.calledBySuccess=this.calledBySuccess.filter(f=>f.id!==i.id?!0:(a==null||a.add(this,K.Updated),a==null||a.add(f,K.Affected),!1)),this.calledByError=this.calledByError.filter(f=>f.id!==i.id?!0:(a==null||a.add(this,K.Updated),a==null||a.add(f,K.Affected),!1)),this.calledByEntry=this.calledByEntry.filter(f=>f.id!==i.id?!0:(a==null||a.add(this,K.Updated),a==null||a.add(f,K.Affected),!1)),l&&Ye(this,a),a==null||a.attemptAutoclose(P.RemoveCaller,this.id),this):this}setThrows(i,a=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,"set-throws"))){var l;if(!this.checkCanEdit(this))return J.warn(`[setThrows] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),a==null||a.attemptAutoclose("set-throws",this.id),this;if(i!==null&&i.parentRelationType!==Wa.Error)throw new Error("The 'throws' InputMap must have a parentRelationType of 'Error'.");return((l=this.throws)==null?void 0:l.id)!==(i==null?void 0:i.id)&&(this.throws=i,a==null||a.add(this,K.Updated)),a==null||a.attemptAutoclose("set-throws",this.id),this}addOutput(i,a=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,"add-output"))){return this.checkCanEdit(this)?this.outputs.includes(i)?(a==null||a.attemptAutoclose("add-output",this.id),this):(this.outputs.push(i),a==null||a.add(this,K.Affected),a==null||a.attemptAutoclose("add-output",this.id),this):(J.warn(`[addOutput] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),a==null||a.attemptAutoclose("add-output",this.id),this)}removeOutput(i,a=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,"remove-output"))){if(!this.checkCanEdit(this))return J.warn(`[removeOutput] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),a==null||a.attemptAutoclose("remove-output",this.id),this;const l=this.outputs.findIndex(f=>f.id===i.id);return l>-1&&(this.outputs.splice(l,1),a&&(a==null||a.add(this,K.Affected))),a==null||a.attemptAutoclose("remove-output",this.id),this}setParent(i,a=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,P.SetParent))){var l;return this.checkCanEditWithCounterpartAndSideEffects(this,i,P.SetParent,a)?(((l=this.parent)==null?void 0:l.id)!==(i==null?void 0:i.id)&&(this.parent=i,a&&(a==null||a.add(this,K.Updated))),a==null||a.attemptAutoclose(P.SetParent,this.id),this):this}setImplements(i,a=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,P.SetImplements))){var l;return this.checkCanEdit(this)?(((l=this.implements)==null?void 0:l.id)!==(i==null?void 0:i.id)&&(this.implements=i,a&&(a==null||a.add(this,K.Updated))),a==null||a.attemptAutoclose(P.SetImplements,this.id),this):(J.warn(`[setImplements] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),a==null||a.attemptAutoclose(P.SetImplements,this.id),this)}setValueWriter(i,a=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,P.SetValueWriter))){return i&&!this.checkCanEditWithCounterpartAndSideEffects(this,i,P.SetValueWriter,a)?this:!i&&!this.checkCanEdit(this)?(J.warn(`[setValueWriter] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),a==null||a.attemptAutoclose(P.SetValueWriter,this.id),this):(this.readsValue!==i&&(this.readsValue=i,a==null||a.add(this,K.Updated)),a==null||a.attemptAutoclose(P.SetValueWriter,this.id),this)}removeValueWriter(i=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,P.RemoveValueWriter))){return this.readsValue&&!this.checkCanEditWithCounterpartAndSideEffects(this,this.readsValue,P.RemoveValueWriter,i)?this:(this.readsValue&&(this.readsValue=null,i==null||i.add(this,K.Updated)),i==null||i.attemptAutoclose(P.RemoveValueWriter,this.id),this)}initChildren(i=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,"init-children"))){if(this.initialized||this.startedInitialization)return this;if(this.startedInitialization=!0,this.initialData.defaultValue&&(this.defaultValue=se(this.initialData.defaultValue,this.project),this.defaultValue.setParent(this,null),this.defaultValue.initChildren(i)),this.initialData.dataType&&(this.dataType=se(this.initialData.dataType,this.project),this.dataType.setParent(this,null),this.dataType.initChildren(i)),_d.initReadsValue(this),this.initialData.implements){const a=se(this.initialData.implements,this.project);this.setImplements(a,null)}return this.outputs=this.initialData.outputs.map(a=>{const l=se(a,this.project);return l.setParent(this,null),l.initChildren(i),l}),this.initialData.throws&&(this.throws=se(this.initialData.throws,this.project),this.throws.setParent(this,null),this.throws.initChildren(i)),this.subscribeToDependencies(),this.afterAllChildrenInitialized(i),i==null||i.attemptAutoclose("init-children",this.id),this}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(i,a=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,"meta-sync"))){const l=Xi(this,i),f=Yi(this,l),e=this.toMeta();return this.x=l.x||e.x,this.y=l.y||e.y,super.baseMetaSync(l,this),l.deleted===!0&&!e.deleted?a==null||a.add(this,K.Removed):l.deleted===!1&&e.deleted?a==null||a.add(this,K.Added):f&&(a==null||a.add(this,K.Updated)),a==null||a.attemptAutoclose("meta-sync",this.id),this}async APILoad(i=Ie,...a){return await li.repository.APILoad(this.id,...a),this}async APICreate(i=Ie,...a){return await li.repository.APICreate(this.toShallowJSON(),...a),this}async APIUpdate(i=Ie,...a){return await li.repository.APIUpdate(this.toShallowJSON(),...a),this}async APIDelete(i=Ie,...a){return await li.repository.APIDelete(this.toShallowJSON(),...a),this}async APIClone(i=Ie,...a){return await li.repository.APIClone(this.id,...a),this}async APILoadVersion(i=Ie,a,...l){return await li.repository.APILoadVersion(this.id,a,...l)}removeFromParent(i=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,P.RemoveFromParent))){if(!this.checkCanEdit(this))return J.warn(`[removeFromParent] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(P.RemoveFromParent,this.id),{added:[],updated:[],removed:[],affected:[],self:this};const a=[],l=[],f=[],e=[];return this.parent.removeBreakStatement(this),e.push(this.parent),i==null||i.attemptAutoclose(P.RemoveFromParent,this.id),{added:g(f),updated:g(a),removed:g(l),affected:g(e),self:this}}remove({ignoreUpstream:i}={ignoreUpstream:!1},a=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,P.RemoveEntity))){var v,T,A;if(!this.checkCanDelete(this)||!this.checkCanEdit(this))return J.warn(`[remove] User is not allowed to delete or edit this ${this.type} entity with id: ${this.id}`),a==null||a.event({id:`${P.RemoveEntity}-${this.id}`,action:P.RemoveEntity,owner:this,errorReason:Si.ActionOwnerEntityNonDeletable,rootAction:((v=a==null?void 0:a.self)==null?void 0:v.id)===this.id&&(a==null?void 0:a.autoCloseActionName)===P.RemoveEntity}),a==null||a.attemptAutoclose(P.RemoveEntity,this.id),{added:[],updated:[],removed:[],affected:[],self:this};const l=[],f=[],e=[],y=[];if(a!=null&&a.hasRemoved(this.id))return a==null||a.attemptAutoclose(P.RemoveEntity,this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(f.push(this),this.unsubscribe(),this.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},a),Object.values(this.detachedDependents).forEach(I=>{const{updated:O,removed:L,added:M}=I.entity.onDetachedDependencyRemoved(this,I.field,a);l.push(...O),f.push(...L),e.push(...M)}),this.readsValue&&(l.push(this.readsValue),this.readsValue.removeValueReader(this,a)),this.outputs.forEach(I=>{const{updated:O,removed:L}=I.remove({ignoreUpstream:!0},a);l.push(...O),f.push(...L)}),this.throws){const{updated:I,removed:O}=this.throws.remove({ignoreUpstream:!0},a);l.push(...I),f.push(...O)}if(this.dataType){const{updated:I,removed:O}=this.dataType.remove({ignoreUpstream:!0},a);l.push(...I),f.push(...O)}if(!i){const I=this.removeFromParent(a);e.push(...I.added),l.push(...I.updated),f.push(...I.removed),y.push(...I.affected),this.calledBy.forEach(O=>{l.push(O),O.removeCall(this,a)})}return a==null||a.add(this.parent,K.Affected),(T=this.parent)==null||T.breakStatements.forEach(I=>{I.id!==this.id&&(y.push(I),a==null||a.add(I,K.Affected))}),(A=this.parent)==null||A.continueStatements.forEach(I=>{I.id!==this.id&&(y.push(I),a==null||a.add(I,K.Affected))}),a==null||a.attemptAutoclose(P.RemoveEntity,this.id),{added:g(e),updated:g(l),removed:g(f),affected:g(y),self:this}}restore({}={},i=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,P.RestoreEntity))){if(!this.checkCanEdit(this))return J.warn(`[restore] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(P.RestoreEntity,this.id),{added:[],updated:[],removed:[],affected:[],self:this};const a=[],l=[],f=[],e=[];if(i!=null&&i.hasAdded(this.id))return i==null||i.attemptAutoclose(P.RestoreEntity,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:T,added:A}=y.entity.onDetachedDependencyRestored(this,y.field,i);l.push(...v),f.push(...T),a.push(...A)}),this.readsValue&&(l.push(this.readsValue),this.readsValue.addValueReader(this,i)),this.outputs.forEach(y=>{const{updated:v}=y.restore({},i);l.push(...v)}),this.throws){const{updated:y}=this.throws.restore({},i);l.push(...y)}if(this.dataType){const{updated:y}=this.dataType.restore({},i);l.push(...y)}return this.parent.addBreakStatement(this),this.calledBySuccess.forEach(y=>{l.push(y),y.addSuccessCall(this,i)}),this.calledByError.forEach(y=>{l.push(y),y.addErrorCall(this,i)}),this.calledByEntry.forEach(y=>{l.push(y),y.addCall(this,i)}),i==null||i.attemptAutoclose(P.RestoreEntity,this.id),{added:g(a),updated:g(l),removed:g(f),affected:g(e),self:this}}toFlat(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this,...this.outputs.flatMap(l=>l.toFlat(i)),...this.throws?this.throws.toFlat(i):[],...this.dataType?this.dataType.toFlat(i):[]])}toFlatIds(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.id,...this.outputs.flatMap(l=>l.toFlatIds(i)),...this.throws?this.throws.toFlatIds(i):[],...this.dataType?this.dataType.toFlatIds(i):[]])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,x:this.x,y:this.y,type:this.type,editable:this.editable,deletable:this.deletable}}toJSON(i=new Set){var a,l,f,e,y,v;return i.has(this.id)?this.toReference():(i.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,editable:this.editable,deletable:this.deletable,x:this.x,y:this.y,defaultValue:((a=this.defaultValue)==null?void 0:a.toJSON(i))||null,dataType:((l=this.dataType)==null?void 0:l.toJSON(i))||null,readsValue:((f=this.readsValue)==null?void 0:f.toReference())||null,implements:((e=this.implements)==null?void 0:e.toJSON(i))||null,outputs:this.outputs.map(T=>T.toJSON(i)),calledBySuccess:this.calledBySuccess.map(T=>T.toReference()),calledByError:this.calledByError.map(T=>T.toReference()),calledByEntry:this.calledByEntry.map(T=>T.toReference()),parent:((y=this.parent)==null?void 0:y.toReference())||null,throws:((v=this.throws)==null?void 0:v.toJSON(i))||null})}toJSONClone(i=ke){var l,f,e,y,v,T,A,I,O,L;let a;return(l=i.seenEntityMaps)!=null&&l.has(this.id)?a=i.seenEntityMaps.get(this.id):(a=i.newId||or(this,this.project,i.uuidStrategy),i.seenEntityMaps&&i.seenEntityMaps.set(this.id,a)),(f=i.seenEntities)!=null&&f.has(a)||(e=i.seenEntities)!=null&&e.has(this.id)?this.toReference({seenEntityMaps:i.seenEntityMaps}):((y=i.seenEntities)==null||y.add(a),(v=i.seenEntities)==null||v.add(this.id),{id:a,version:V.UUID.uuid(),createdAt:i.timestamp||B().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,editable:this.editable,deletable:this.deletable,x:this.x,y:this.y,defaultValue:((T=this.defaultValue)==null?void 0:T.toJSONClone({...i,newId:null}))||null,dataType:((A=this.dataType)==null?void 0:A.toJSONClone({...i,newId:null}))||null,readsValue:((I=this.readsValue)==null?void 0:I.toReference({seenEntityMaps:i.seenEntityMaps}))||null,implements:(()=>{var M;return this.implements&&this.project.getBuiltIn(this.implements.id)?this.implements.toJSON():((M=this.implements)==null?void 0:M.toJSONClone({...i,newId:null}))||null})(),outputs:this.outputs.map(M=>M.toJSONClone({...i,newId:null})),calledBySuccess:this.calledBySuccess.map(M=>M.toReference({seenEntityMaps:i.seenEntityMaps})),calledByError:this.calledByError.map(M=>M.toReference({seenEntityMaps:i.seenEntityMaps})),calledByEntry:this.calledByEntry.map(M=>M.toReference({seenEntityMaps:i.seenEntityMaps})),parent:((O=this.parent)==null?void 0:O.toReference({seenEntityMaps:i.seenEntityMaps}))||null,throws:((L=this.throws)==null?void 0:L.toJSONClone({...i,newId:null}))||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+"--"+V.UUID.uuid()+"--ref",type:p.GenericReference,entityId:a,version:this.version,entityType:this.type}}toShallowJSON(i=ke){var l,f,e,y,v,T,A;let a=this.id;return(l=i.seenEntityMaps)!=null&&l.has(this.id)&&(a=i.seenEntityMaps.get(this.id)),{id:a,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,editable:this.editable,deletable:this.deletable,x:this.x,y:this.y,defaultValue:((f=this.defaultValue)==null?void 0:f.toReference(i))||null,dataType:((e=this.dataType)==null?void 0:e.toReference(i))||null,readsValue:((y=this.readsValue)==null?void 0:y.toReference(i))||null,implements:((v=this.implements)==null?void 0:v.toReference(i))||null,outputs:this.outputs.map(I=>I.toReference(i)),calledBySuccess:this.calledBySuccess.map(I=>I.toReference(i)),calledByError:this.calledByError.map(I=>I.toReference(i)),calledByEntry:this.calledByEntry.map(I=>I.toReference(i)),throws:((T=this.throws)==null?void 0:T.toReference(i))||null,parent:((A=this.parent)==null?void 0:A.toReference(i))||null}}toFlatJSON(i=new Set){var l,f,e;return i.has(this.id)?[]:(i.add(this.id),[this.toShallowJSON(),...((l=this.defaultValue)==null?void 0:l.toFlatJSON(i))||[],...((f=this.dataType)==null?void 0:f.toFlatJSON(i))||[],...((e=this.implements)==null?void 0:e.toFlatJSON(i))||[],...this.outputs.flatMap(y=>y.toFlatJSON(i)),...this.throws?this.throws.toFlatJSON(i):[]])}toGenerationTarget(){var i;return{id:this.id,type:this.type,calledByEntry:this.calledByEntry.map(a=>a.id),calledByError:this.calledByError.map(a=>a.id),calledBySuccess:this.calledBySuccess.map(a=>a.id),implements:(i=this.implements)==null?void 0:i.id,parent:this.parent.id}}toFlatGenerationTarget(i=new Set){var l,f,e;return i.has(this.id)?[]:(i.add(this.id),[this.toGenerationTarget(),...((l=this.defaultValue)==null?void 0:l.toFlatGenerationTarget(i))||[],...((f=this.dataType)==null?void 0:f.toFlatGenerationTarget(i))||[],...((e=this.implements)==null?void 0:e.toFlatGenerationTarget(i))||[],...this.outputs.flatMap(y=>y.toFlatGenerationTarget(i)),...this.throws?this.throws.toFlatGenerationTarget(i):[]])}clearErrors(){var i,a,l;return this.errors=[],(i=this.dataType)==null||i.clearErrors(),(a=this.defaultValue)==null||a.clearErrors(),this.outputs.forEach(f=>f.clearErrors()),(l=this.throws)==null||l.clearErrors(),this}validate(){const i=LZ(this);return this.errors=i,{success:!0}}getErrors(){var a,l;return[...this.errors,...((a=this.defaultValue)==null?void 0:a.getErrors())||[],...((l=this.dataType)==null?void 0:l.getErrors())||[],...this.outputs.flatMap(f=>f.getErrors()),...this.throws?this.throws.getErrors():[]]}getShallowErrors(){return this.errors}getDefaultValue(){return this.defaultValue||null}setDefaultValue(i,a=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,"set-default-value"))){if(!this.checkCanEdit(this))return J.warn(`[setDefaultValue] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),a==null||a.attemptAutoclose("set-default-value",this.id),this;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,K.Affected)),a==null||a.attemptAutoclose("set-default-value",this.id),this}clone(i=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,P.CloneEntity)),a=null,l=null,f=!0){var j,q,Z;let e=lr(a,this);const y=this.toJSON(),v=l||V.UUID.uuid();y.outputs=[];const T=v.split("-id"),A=T[T.length-1||0]||v;y.id=v,y.version=V.UUID.uuid(),y.createdAt=(i==null?void 0:i.timestamp)||B().toISOString(),y.author=(i==null?void 0:i.author)||"1",y.previousVersion=null,y.deleted=!1,y.deletable=!0,y.editable=!0;const I=Ei(y,e);a?I.setParent(a,null):I.setParent(this.parent,null),f&&I.subscribe(),I.initChildren(i),i==null||i.add(I,K.Added);const O=(j=this.dataType)==null?void 0:j.clone(i,I,V.UUID.uuid(),f);I.setDataType(O||null,i);const L=(q=this.defaultValue)==null?void 0:q.clone(i,I,V.UUID.uuid(),f);I.setDefaultValue(L||null,i),this.implements&&I.setImplements(this.implements,i);const M=(Z=this.outputs)==null?void 0:Z.map((S,H)=>S.clone(i,I,A+"-return-declaration-"+H+"-id",f));return I.outputs=M,this.throws&&(I.throws=this.throws.clone(i,I,A+"-throws-id",f)),i==null||i.attemptAutoclose(P.CloneEntity,this.id),I}setDataType(i,a=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,P.SetDataType))){if(!this.checkCanEdit(this))return J.warn(`[setDataType] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),a==null||a.attemptAutoclose(P.SetDataType,this.id),this;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,K.Affected)),a==null||a.attemptAutoclose(P.SetDataType,this.id),this}removeDataType(i=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,P.RemoveDataType))){return this.checkCanEdit(this)?(this.dataType&&(this.dataType.remove({ignoreUpstream:!0},i),i==null||i.add(this,K.Affected),this.dataType=null),i==null||i.attemptAutoclose(P.RemoveDataType,this.id),this):(J.warn(`[removeDataType] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(P.RemoveDataType,this.id),this)}getDataType(i=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,"get-data-type"))){var l;if((!this.dataType||this.dataType.inferred)&&this.project.initialized,this.dataType)return i==null||i.attemptAutoclose("get-data-type",this.id),this.dataType;const a=(l=this.implements)==null?void 0:l.getDataType(i);return i==null||i.attemptAutoclose("get-data-type",this.id),a||null}};_(li,"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}),_(li,"type",p.BreakStatement),_(li,"USER_MANAGED_PARENT_TYPES",[p.Loop]),_(li,"PARENT_TYPES",[...li.USER_MANAGED_PARENT_TYPES]),_(li,"MUTABLE_BASE_PROPERTIES",[]),_(li,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),_(li,"BASE_PROPERTIES",[...li.MUTABLE_BASE_PROPERTIES,...li.INMUTABLE_BASE_PROPERTIES]),_(li,"MUTABLE_META_PROPERTIES",["x","y"]),_(li,"INMUTABLE_META_PROPERTIES",[...li.INMUTABLE_BASE_PROPERTIES]),_(li,"META_PROPERTIES",[...li.MUTABLE_META_PROPERTIES,...li.INMUTABLE_META_PROPERTIES]),_(li,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry","readsValue"]),_(li,"INMUTABLE_UPSTREAM_PROPERTIES",["parent"]),_(li,"UPSTREAM_PROPERTIES",[...li.MUTABLE_UPSTREAM_PROPERTIES,...li.INMUTABLE_UPSTREAM_PROPERTIES]),_(li,"MUTABLE_DOWNSTREAM_PROPERTIES",["outputs","throws"]),_(li,"INMUTABLE_DOWNSTREAM_PROPERTIES",["dataType","defaultValue"]),_(li,"DOWNSTREAM_PROPERTIES",[...li.MUTABLE_DOWNSTREAM_PROPERTIES,...li.INMUTABLE_DOWNSTREAM_PROPERTIES]),_(li,"PROPERTIES",[...li.META_PROPERTIES,...li.UPSTREAM_PROPERTIES,...li.DOWNSTREAM_PROPERTIES]);let po=li;function MZ(d){var i;d.outputs.forEach(a=>a.validate()),(i=d.throws)==null||i.validate();const u=[];return $i(d.errors,u)}const qOe=Object.freeze(Object.defineProperty({__proto__:null,validate:MZ},Symbol.toStringTag,{value:"Module"}));var xZ=(d=>(d.Parent="continue-statement-parent-field",d.ImplementsField="continue-statement-implements-field",d.DataTypeEntity="continue-statement-data-type-entity-field",d.DataType="continue-statement-data-type-field",d))(xZ||{});const oi=class oi extends nr{constructor(i,a){super(i);_(this,"initialData");_(this,"id");_(this,"x");_(this,"y");_(this,"type",p.ContinueStatement);_(this,"outputs",[]);_(this,"readsValue",null);_(this,"dataType",null);_(this,"defaultValue",null);_(this,"implements",null);_(this,"calledBySuccess",[]);_(this,"calledByError",[]);_(this,"calledByEntry",[]);_(this,"throws",null);_(this,"project");_(this,"errors",[]);_(this,"parent");_(this,"detachedDependents",{});_(this,"knownVersions",null);_(this,"activeVersion",!1);_(this,"initialized",!1);_(this,"startedInitialization",!1);_(this,"suggestion",!1);this.initialData=i,this.project=a,this.id=i.id,this.x=i.x,this.y=i.y}static new(i=null){return{id:V.UUID.uuid(),version:V.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||B().toISOString(),author:(i==null?void 0:i.author)||V.sessionAuthor,previousVersion:null,deleted:!1,deletable:!0,editable:!0,type:p.ContinueStatement,outputs:[],defaultValue:null,dataType:null,implements:null,readsValue:null,throws:null,parent:null,calledByEntry:[],calledBySuccess:[],calledByError:[],x:0,y:0}}static fromGenerationTarget(i,a){const l=X(i.parent),f=a.get(l),e=i.calledByEntry.map(L=>{const M=X(L);return a.get(M)}),y=i.calledBySuccess.map(L=>{const M=X(L);return a.get(M)}),v=i.calledByError.map(L=>{const M=X(L);return a.get(M)});let T=null;if(i.readsValue){const L=X(i.readsValue);T=a.get(L)}let A=null;if(i.implements){const L=X(i.implements);A=a.get(L)}const I={id:i.id,version:V.UUID.uuid(),createdAt:B().toISOString(),author:V.sessionAuthor,previousVersion:null,deleted:!1,deletable:!0,editable:!0,type:p.ContinueStatement,x:0,y:0,outputs:[],defaultValue:null,dataType:null,implements:A,readsValue:T,calledBySuccess:y,calledByError:v,calledByEntry:e,throws:null,parent:f},O=se(I,a);return O.setParent(f,null),O}static validateGenerationTarget(i,a){let l=JSON.parse(JSON.stringify(i));const f=[],e=Pr(l,{parent:{list:!1,types:[p.Loop]}},a);return l=e.modifiedData,f.push(...e.errors,...zi(l)),{errors:f,modifiedData:l}}validateGeneratedUpdate(i){const a=[];let l=JSON.parse(JSON.stringify(i));const f=Ad(l,this);return l=f.modifiedData,a.push(...f.errors),i.parent&&a.push(new oe({id:`${this.id}--${W.InvalidParentUpdate}`,code:W.InvalidParentUpdate,severity:Y.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.
|
|
182
|
+
Specifically for break statements the parent needs to always be the 'loop' entity that contains it.`})),{errors:a,modifiedData:i}}subscribeDependents(i){return i.forEach(a=>{this.detachedDependents[a.entity.id]||(this.detachedDependents[a.entity.id]=a)}),this}unsubscribeDependents(i){return i.forEach(a=>{this.detachedDependents[a.entity.id]&&delete this.detachedDependents[a.entity.id]}),this}syncDependents(i=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,"sync-dependents"))){const a=[],l=[],f=[],e=[];return Object.values(this.detachedDependents).forEach(y=>{const v=y.entity.afterAllChildrenInitialized(i);a.push(...v.updated),l.push(...v.added),f.push(...v.removed),e.push(...v.affected)}),i==null||i.attemptAutoclose("sync-dependents",this.id),{updated:g(a),added:g(l),removed:g(f),affected:g(e),self:this}}onDetachedDependencyRemoved(i,a,l){const f=[],e=[],y=[],v=[];if(a==="break-statement-implements-field"&&(this.setImplements(null,l),f.push(this)),a==="break-statement-parent-field"){const{updated:T,added:A,removed:I}=this.remove({ignoreUpstream:!1},l);f.push(...T),e.push(...A),y.push(...I)}return{updated:g(f),added:g(e),removed:g(y),affected:g(v),self:this}}onDetachedDependencyRestored(i,a,l){const f=[],e=[],y=[],v=[];if(a==="break-statement-implements-field"&&(this.setImplements(i,l),f.push(this)),a==="break-statement-parent-field"){const{updated:T,added:A,removed:I}=this.restore({},l);f.push(...T),e.push(...A),y.push(...I)}return{updated:g(f),added:g(e),removed:g(y),affected:g(v),self:this}}unsubscribeFromDependencies(){var i,a,l,f,e,y,v;return this.parent.unsubscribeDependents([{entity:this,field:"break-statement-parent-field"}]),(a=(i=this.implements)==null?void 0:i.unsubscribeDependents)==null||a.call(i,[{entity:this,field:"break-statement-implements-field"}]),(e=(f=(l=this.dataType)==null?void 0:l.entity)==null?void 0:f.unsubscribeDependents)==null||e.call(f,[{entity:this,field:"break-statement-data-type-entity-field"}]),(v=(y=this.dataType)==null?void 0:y.unsubscribeDependents)==null||v.call(y,[{entity:this,field:"break-statement-data-type-field"}]),this}subscribeToDependencies(){var i,a,l,f,e,y,v,T;return(i=this.parent)==null||i.subscribeDependents([{entity:this,field:"break-statement-parent-field"}]),(l=(a=this.implements)==null?void 0:a.subscribeDependents)==null||l.call(a,[{entity:this,field:"break-statement-implements-field"}]),(y=(e=(f=this.dataType)==null?void 0:f.entity)==null?void 0:e.subscribeDependents)==null||y.call(e,[{entity:this,field:"break-statement-data-type-entity-field"}]),(T=(v=this.dataType)==null?void 0:v.subscribeDependents)==null||T.call(v,[{entity:this,field:"break-statement-data-type-field"}]),this}increaseVersion(i){if(i&&!B(i).isValid())throw new Error(`The shared timestamp '${i}' is not a valid ISO 8601 date string.`);return i&&B(i).isSame(B(this.createdAt))?this:(this.previousVersion=this.version,this.version=V.UUID.uuid(),this.createdAt=B(i).toISOString()||B().toISOString(),this)}captureVersion(){var a;const i=((a=this.knownVersions)==null?void 0:a.get(this.version))||new li(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.outputs=[...this.outputs],i.readsValue=this.readsValue,i.defaultValue=this.defaultValue,i.dataType=this.dataType,i.implements=this.implements,i.throws=this.throws,i.calledBySuccess=[...this.calledBySuccess],i.calledByError=[...this.calledByError],i.calledByEntry=[...this.calledByEntry],i.parent=this.parent,this}recursiveCaptureUpstreamVersions(i){const a=[],l=[],f=[],e=[];if(this.parent){this.parent.increaseVersion(i);const y=this.parent.recursiveCaptureUpstreamVersions(i);a.push(this.parent,...y.updated),l.push(...y.added),f.push(...y.removed)}return{updated:g(a),added:g(l),removed:g(f),affected:g(e),self:this}}async restoreVersion(i){var v;const a=[],l=[],f=[],e=[];if(this.version===i)return{updated:g(a),added:g(l),removed:g(f),affected:g(e),self:this};if(!this.knownVersions){const T=new Map;for(const[A,I]of this.knownVersions||new Map){if(T.set(A,I),I.activeVersion=!1,I.knownVersions)for(const[O,L]of I.knownVersions)T.set(O,L);I.knownVersions=null}}let y=(v=this.knownVersions)==null?void 0:v.get(i);if(!y){const T=await this.APILoadVersion({},i);if(!T)throw new Error(`Version with id '${i}' for entity with id '${this.id}' not found.`);y=new li(T,this.project)}return this.metaSync(y.toShallowJSON(),null),this.previousVersion=y.previousVersion,this.version=y.version,this.createdAt=y.createdAt,this.author=y.author,this.deleted=y.deleted,this.outputs=y.outputs,this.readsValue=y.readsValue,this.defaultValue=y.defaultValue,this.dataType=y.dataType,this.implements=y.implements,this.throws=y.throws,this.calledBySuccess=y.calledBySuccess,this.calledByError=y.calledByError,this.calledByEntry=y.calledByEntry,this.parent=y.parent,{updated:g(a),added:g(l),removed:g(f),affected:g(e),self:this}}updateWithShallowTransfer(i,a=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,P.UpdateWithShallowTransfer))){if(!this.checkCanEdit(this))return J.warn(`[updateWithShallowTransfer] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),a==null||a.attemptAutoclose(P.UpdateWithShallowTransfer,this.id),this;if(this.metaSync(i,a),this.version=i.version,this.createdAt=i.createdAt,this.author=i.author,this.deleted=i.deleted,this.previousVersion=i.previousVersion,this.unsubscribeFromDependencies(),i.parent){const l=X(i.parent),f=this.project.get(l),e=this.parent;if(e&&e.id!==(f==null?void 0:f.id)&&this.removeFromParent(a),f)this.setParent(f,a);else throw a==null||a.attemptAutoclose(P.UpdateWithShallowTransfer,this.id),new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw a==null||a.attemptAutoclose(P.UpdateWithShallowTransfer,this.id),new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(i.readsValue){const l=X(i.readsValue),f=this.project.get(l),e=this.readsValue;e&&e.id!==(f==null?void 0:f.id)&&this.removeValueWriter(a),f&&this.setValueWriter(f,a)}return i.calledByEntry.forEach(l=>{const f=X(l),e=this.project.get(f);e&&(this.addEntryCaller(e,a),e.addCall(this,a))}),[...this.calledByEntry].forEach(l=>{i.calledByEntry.find(e=>X(e)===l.id)||(this.removeCaller(l,a),l.removeCall(this,a))}),i.calledBySuccess.forEach(l=>{const f=X(l),e=this.project.get(f);e&&(this.addSuccessCaller(e,a),e.addSuccessCall(this,a))}),[...this.calledBySuccess].forEach(l=>{i.calledBySuccess.find(e=>X(e)===l.id)||(this.removeCaller(l,a),l.removeCall(this,a))}),i.calledByError.forEach(l=>{const f=X(l),e=this.project.get(f);e&&(this.addErrorCaller(e,a),e.addErrorCall(this,a))}),[...this.calledBySuccess].forEach(l=>{i.calledBySuccess.find(e=>X(e)===l.id)||(this.removeCaller(l,a),l.removeCall(this,a))}),this.captureVersion(),this.subscribeToDependencies(),a==null||a.attemptAutoclose(P.UpdateWithShallowTransfer,this.id),this}hydrateAncestors(){const i=[],a=[],l=[],f=[];if(this.initialData.parent){const e=X(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.implements){const e=X(this.initialData.implements),y=this.project.get(e);if(y)this.setImplements(y,null),i.push(y);else if(e)throw new Error(`${rr(this.type)} with id '${this.id}' has a 'implements' reference "${e}" which is missing in the project`)}if(this.initialData.readsValue){const e=X(this.initialData.readsValue),y=this.project.get(e);y&&(this.setValueWriter(y,null),i.push(y))}return this.initialData.calledByEntry.forEach(e=>{const y=X(e),v=this.project.get(y);v&&(this.addEntryCaller(v,null),i.push(v))}),this.initialData.calledBySuccess.forEach(e=>{const y=X(e),v=this.project.get(y);v&&(this.addSuccessCaller(v,null),i.push(v))}),this.initialData.calledByError.forEach(e=>{const y=X(e),v=this.project.get(y);v&&(this.addErrorCaller(v,null),i.push(v))}),{updated:g(i),added:g(a),removed:g(l),affected:g(f),self:this}}afterAllChildrenInitialized(i=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,P.AfterAllChildrenInitialized))){if(!this.checkCanEdit(this))return J.warn(`[afterAllChildrenInitialized] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(P.AfterAllChildrenInitialized,this.id),{updated:[],added:[],removed:[],affected:[],self:this};const a=[],l=[],f=[],e=[];return this.initialized=!0,!this.dataType||this.dataType.inferred,this.parent.syncTerminationStatements(i),this.captureVersion(),i==null||i.attemptAutoclose(P.AfterAllChildrenInitialized,this.id),{updated:g(a),added:g(l),removed:g(f),affected:g(e),self:this}}addSelfToProject(i=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,"add-self-to-project"))){var y,v;const a=[this],l=[],f=[],e=[];return this.readsValue&&(this.readsValue.addValueReader(this,i),a.push(this.readsValue)),this.calledByEntry.forEach(T=>{T.addCall(this,i),a.push(T)}),this.calledBySuccess.forEach(T=>{T.addSuccessCall(this,i),a.push(T)}),this.calledByError.forEach(T=>{T.addErrorCall(this,i),a.push(T)}),this.parent.addBreakStatement(this),e.push(this.parent),i==null||i.add(this.parent,K.Affected),(y=this.parent)==null||y.breakStatements.forEach(T=>{T.id!==this.id&&(e.push(T),i==null||i.add(T,K.Affected))}),(v=this.parent)==null||v.continueStatements.forEach(T=>{T.id!==this.id&&(e.push(T),i==null||i.add(T,K.Affected))}),this.subscribe(),this.subscribeToDependencies(),i==null||i.attemptAutoclose("add-self-to-project",this.id),{updated:g(a),added:g(l),removed:g(f),affected:g(e),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}addSuccessCaller(i,a=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,P.AddSuccessCaller)),l=!1){return this.checkCanEditWithCounterpartAndSideEffects(this,i,P.AddSuccessCaller,a)?(this.calledBySuccess.find(f=>f.id===i.id)||(this.calledBySuccess.push(i),a==null||a.add(this,K.Updated),l&&Ye(this,a)),a==null||a.attemptAutoclose(P.AddSuccessCaller,this.id),this):this}addErrorCaller(i,a=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,P.AddErrorCaller)),l=!1){return this.checkCanEditWithCounterpartAndSideEffects(this,i,P.AddErrorCaller,a)?(this.calledByError.find(f=>f.id===i.id)||(this.calledByError.push(i),a==null||a.add(this,K.Updated),l&&Ye(this,a)),a==null||a.attemptAutoclose(P.AddErrorCaller,this.id),this):this}addEntryCaller(i,a=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,P.AddEntryCaller)),l=!1){return this.checkCanEditWithCounterpartAndSideEffects(this,i,P.AddEntryCaller,a)?(this.calledByEntry.find(f=>f.id===i.id)||(this.calledByEntry.push(i),a==null||a.add(this,K.Updated),l&&Ye(this,a)),a==null||a.attemptAutoclose(P.AddEntryCaller,this.id),this):this}removeCaller(i,a=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,"remove-caller")),l=!1){return this.checkCanEditWithCounterpartAndSideEffects(this,i,P.RemoveCaller,a)?(this.calledBySuccess=this.calledBySuccess.filter(f=>f.id!==i.id?!0:(a==null||a.add(this,K.Updated),a==null||a.add(f,K.Affected),!1)),this.calledByError=this.calledByError.filter(f=>f.id!==i.id?!0:(a==null||a.add(this,K.Updated),a==null||a.add(f,K.Affected),!1)),this.calledByEntry=this.calledByEntry.filter(f=>f.id!==i.id?!0:(a==null||a.add(this,K.Updated),a==null||a.add(f,K.Affected),!1)),l&&Ye(this,a),a==null||a.attemptAutoclose(P.RemoveCaller,this.id),this):this}setThrows(i,a=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,"set-throws"))){var l;if(!this.checkCanEdit(this))return J.warn(`[setThrows] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),a==null||a.attemptAutoclose("set-throws",this.id),this;if(i!==null&&i.parentRelationType!==Wa.Error)throw new Error("The 'throws' InputMap must have a parentRelationType of 'Error'.");return((l=this.throws)==null?void 0:l.id)!==(i==null?void 0:i.id)&&(this.throws=i,a==null||a.add(this,K.Updated)),a==null||a.attemptAutoclose("set-throws",this.id),this}addOutput(i,a=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,"add-output"))){return this.checkCanEdit(this)?this.outputs.includes(i)?(a==null||a.attemptAutoclose("add-output",this.id),this):(this.outputs.push(i),a==null||a.add(this,K.Affected),a==null||a.attemptAutoclose("add-output",this.id),this):(J.warn(`[addOutput] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),a==null||a.attemptAutoclose("add-output",this.id),this)}removeOutput(i,a=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,"remove-output"))){if(!this.checkCanEdit(this))return J.warn(`[removeOutput] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),a==null||a.attemptAutoclose("remove-output",this.id),this;const l=this.outputs.findIndex(f=>f.id===i.id);return l>-1&&(this.outputs.splice(l,1),a&&(a==null||a.add(this,K.Affected))),a==null||a.attemptAutoclose("remove-output",this.id),this}setParent(i,a=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,P.SetParent))){var l;return this.checkCanEditWithCounterpartAndSideEffects(this,i,P.SetParent,a)?(((l=this.parent)==null?void 0:l.id)!==(i==null?void 0:i.id)&&(this.parent=i,a&&(a==null||a.add(this,K.Updated))),a==null||a.attemptAutoclose(P.SetParent,this.id),this):this}setImplements(i,a=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,P.SetImplements))){var l;return this.checkCanEdit(this)?(((l=this.implements)==null?void 0:l.id)!==(i==null?void 0:i.id)&&(this.implements=i,a&&(a==null||a.add(this,K.Updated))),a==null||a.attemptAutoclose(P.SetImplements,this.id),this):(J.warn(`[setImplements] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),a==null||a.attemptAutoclose(P.SetImplements,this.id),this)}setValueWriter(i,a=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,P.SetValueWriter))){return i&&!this.checkCanEditWithCounterpartAndSideEffects(this,i,P.SetValueWriter,a)?this:!i&&!this.checkCanEdit(this)?(J.warn(`[setValueWriter] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),a==null||a.attemptAutoclose(P.SetValueWriter,this.id),this):(this.readsValue!==i&&(this.readsValue=i,a==null||a.add(this,K.Updated)),a==null||a.attemptAutoclose(P.SetValueWriter,this.id),this)}removeValueWriter(i=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,P.RemoveValueWriter))){return this.readsValue&&!this.checkCanEditWithCounterpartAndSideEffects(this,this.readsValue,P.RemoveValueWriter,i)?this:(this.readsValue&&(this.readsValue=null,i==null||i.add(this,K.Updated)),i==null||i.attemptAutoclose(P.RemoveValueWriter,this.id),this)}initChildren(i=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,"init-children"))){if(this.initialized||this.startedInitialization)return this;if(this.startedInitialization=!0,this.initialData.defaultValue&&(this.defaultValue=se(this.initialData.defaultValue,this.project),this.defaultValue.setParent(this,null),this.defaultValue.initChildren(i)),this.initialData.dataType&&(this.dataType=se(this.initialData.dataType,this.project),this.dataType.setParent(this,null),this.dataType.initChildren(i)),_d.initReadsValue(this),this.initialData.implements){const a=se(this.initialData.implements,this.project);this.setImplements(a,null)}return this.outputs=this.initialData.outputs.map(a=>{const l=se(a,this.project);return l.setParent(this,null),l.initChildren(i),l}),this.initialData.throws&&(this.throws=se(this.initialData.throws,this.project),this.throws.setParent(this,null),this.throws.initChildren(i)),this.subscribeToDependencies(),this.afterAllChildrenInitialized(i),i==null||i.attemptAutoclose("init-children",this.id),this}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(i,a=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,"meta-sync"))){const l=Xi(this,i),f=Yi(this,l),e=this.toMeta();return this.x=l.x||e.x,this.y=l.y||e.y,super.baseMetaSync(l,this),l.deleted===!0&&!e.deleted?a==null||a.add(this,K.Removed):l.deleted===!1&&e.deleted?a==null||a.add(this,K.Added):f&&(a==null||a.add(this,K.Updated)),a==null||a.attemptAutoclose("meta-sync",this.id),this}async APILoad(i=Ie,...a){return await li.repository.APILoad(this.id,...a),this}async APICreate(i=Ie,...a){return await li.repository.APICreate(this.toShallowJSON(),...a),this}async APIUpdate(i=Ie,...a){return await li.repository.APIUpdate(this.toShallowJSON(),...a),this}async APIDelete(i=Ie,...a){return await li.repository.APIDelete(this.toShallowJSON(),...a),this}async APIClone(i=Ie,...a){return await li.repository.APIClone(this.id,...a),this}async APILoadVersion(i=Ie,a,...l){return await li.repository.APILoadVersion(this.id,a,...l)}removeFromParent(i=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,P.RemoveFromParent))){if(!this.checkCanEdit(this))return J.warn(`[removeFromParent] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(P.RemoveFromParent,this.id),{added:[],updated:[],removed:[],affected:[],self:this};const a=[],l=[],f=[],e=[];return this.parent.removeBreakStatement(this),e.push(this.parent),i==null||i.attemptAutoclose(P.RemoveFromParent,this.id),{added:g(f),updated:g(a),removed:g(l),affected:g(e),self:this}}remove({ignoreUpstream:i}={ignoreUpstream:!1},a=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,P.RemoveEntity))){var v,T,A;if(!this.checkCanDelete(this)||!this.checkCanEdit(this))return J.warn(`[remove] User is not allowed to delete or edit this ${this.type} entity with id: ${this.id}`),a==null||a.event({id:`${P.RemoveEntity}-${this.id}`,action:P.RemoveEntity,owner:this,errorReason:Si.ActionOwnerEntityNonDeletable,rootAction:((v=a==null?void 0:a.self)==null?void 0:v.id)===this.id&&(a==null?void 0:a.autoCloseActionName)===P.RemoveEntity}),a==null||a.attemptAutoclose(P.RemoveEntity,this.id),{added:[],updated:[],removed:[],affected:[],self:this};const l=[],f=[],e=[],y=[];if(a!=null&&a.hasRemoved(this.id))return a==null||a.attemptAutoclose(P.RemoveEntity,this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(f.push(this),this.unsubscribe(),this.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},a),Object.values(this.detachedDependents).forEach(I=>{const{updated:O,removed:L,added:M}=I.entity.onDetachedDependencyRemoved(this,I.field,a);l.push(...O),f.push(...L),e.push(...M)}),this.readsValue&&(l.push(this.readsValue),this.readsValue.removeValueReader(this,a)),this.outputs.forEach(I=>{const{updated:O,removed:L}=I.remove({ignoreUpstream:!0},a);l.push(...O),f.push(...L)}),this.throws){const{updated:I,removed:O}=this.throws.remove({ignoreUpstream:!0},a);l.push(...I),f.push(...O)}if(this.dataType){const{updated:I,removed:O}=this.dataType.remove({ignoreUpstream:!0},a);l.push(...I),f.push(...O)}if(!i){const I=this.removeFromParent(a);e.push(...I.added),l.push(...I.updated),f.push(...I.removed),y.push(...I.affected),this.calledBy.forEach(O=>{l.push(O),O.removeCall(this,a)})}return a==null||a.add(this.parent,K.Affected),(T=this.parent)==null||T.breakStatements.forEach(I=>{I.id!==this.id&&(y.push(I),a==null||a.add(I,K.Affected))}),(A=this.parent)==null||A.continueStatements.forEach(I=>{I.id!==this.id&&(y.push(I),a==null||a.add(I,K.Affected))}),a==null||a.attemptAutoclose(P.RemoveEntity,this.id),{added:g(e),updated:g(l),removed:g(f),affected:g(y),self:this}}restore({}={},i=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,P.RestoreEntity))){if(!this.checkCanEdit(this))return J.warn(`[restore] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(P.RestoreEntity,this.id),{added:[],updated:[],removed:[],affected:[],self:this};const a=[],l=[],f=[],e=[];if(i!=null&&i.hasAdded(this.id))return i==null||i.attemptAutoclose(P.RestoreEntity,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:T,added:A}=y.entity.onDetachedDependencyRestored(this,y.field,i);l.push(...v),f.push(...T),a.push(...A)}),this.readsValue&&(l.push(this.readsValue),this.readsValue.addValueReader(this,i)),this.outputs.forEach(y=>{const{updated:v}=y.restore({},i);l.push(...v)}),this.throws){const{updated:y}=this.throws.restore({},i);l.push(...y)}if(this.dataType){const{updated:y}=this.dataType.restore({},i);l.push(...y)}return this.parent.addBreakStatement(this),this.calledBySuccess.forEach(y=>{l.push(y),y.addSuccessCall(this,i)}),this.calledByError.forEach(y=>{l.push(y),y.addErrorCall(this,i)}),this.calledByEntry.forEach(y=>{l.push(y),y.addCall(this,i)}),i==null||i.attemptAutoclose(P.RestoreEntity,this.id),{added:g(a),updated:g(l),removed:g(f),affected:g(e),self:this}}toFlat(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this,...this.outputs.flatMap(l=>l.toFlat(i)),...this.throws?this.throws.toFlat(i):[],...this.dataType?this.dataType.toFlat(i):[]])}toFlatIds(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.id,...this.outputs.flatMap(l=>l.toFlatIds(i)),...this.throws?this.throws.toFlatIds(i):[],...this.dataType?this.dataType.toFlatIds(i):[]])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,x:this.x,y:this.y,type:this.type,editable:this.editable,deletable:this.deletable}}toJSON(i=new Set){var a,l,f,e,y,v;return i.has(this.id)?this.toReference():(i.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,editable:this.editable,deletable:this.deletable,x:this.x,y:this.y,defaultValue:((a=this.defaultValue)==null?void 0:a.toJSON(i))||null,dataType:((l=this.dataType)==null?void 0:l.toJSON(i))||null,readsValue:((f=this.readsValue)==null?void 0:f.toReference())||null,implements:((e=this.implements)==null?void 0:e.toJSON(i))||null,outputs:this.outputs.map(T=>T.toJSON(i)),calledBySuccess:this.calledBySuccess.map(T=>T.toReference()),calledByError:this.calledByError.map(T=>T.toReference()),calledByEntry:this.calledByEntry.map(T=>T.toReference()),parent:((y=this.parent)==null?void 0:y.toReference())||null,throws:((v=this.throws)==null?void 0:v.toJSON(i))||null})}toJSONClone(i=ke){var l,f,e,y,v,T,A,I,O,L;let a;return(l=i.seenEntityMaps)!=null&&l.has(this.id)?a=i.seenEntityMaps.get(this.id):(a=i.newId||or(this,this.project,i.uuidStrategy),i.seenEntityMaps&&i.seenEntityMaps.set(this.id,a)),(f=i.seenEntities)!=null&&f.has(a)||(e=i.seenEntities)!=null&&e.has(this.id)?this.toReference({seenEntityMaps:i.seenEntityMaps}):((y=i.seenEntities)==null||y.add(a),(v=i.seenEntities)==null||v.add(this.id),{id:a,version:V.UUID.uuid(),createdAt:i.timestamp||B().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,editable:this.editable,deletable:this.deletable,x:this.x,y:this.y,defaultValue:((T=this.defaultValue)==null?void 0:T.toJSONClone({...i,newId:null}))||null,dataType:((A=this.dataType)==null?void 0:A.toJSONClone({...i,newId:null}))||null,readsValue:((I=this.readsValue)==null?void 0:I.toReference({seenEntityMaps:i.seenEntityMaps}))||null,implements:(()=>{var M;return this.implements&&this.project.getBuiltIn(this.implements.id)?this.implements.toJSON():((M=this.implements)==null?void 0:M.toJSONClone({...i,newId:null}))||null})(),outputs:this.outputs.map(M=>M.toJSONClone({...i,newId:null})),calledBySuccess:this.calledBySuccess.map(M=>M.toReference({seenEntityMaps:i.seenEntityMaps})),calledByError:this.calledByError.map(M=>M.toReference({seenEntityMaps:i.seenEntityMaps})),calledByEntry:this.calledByEntry.map(M=>M.toReference({seenEntityMaps:i.seenEntityMaps})),parent:((O=this.parent)==null?void 0:O.toReference({seenEntityMaps:i.seenEntityMaps}))||null,throws:((L=this.throws)==null?void 0:L.toJSONClone({...i,newId:null}))||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+"--"+V.UUID.uuid()+"--ref",type:p.GenericReference,entityId:a,version:this.version,entityType:this.type}}toShallowJSON(i=ke){var l,f,e,y,v,T,A;let a=this.id;return(l=i.seenEntityMaps)!=null&&l.has(this.id)&&(a=i.seenEntityMaps.get(this.id)),{id:a,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,editable:this.editable,deletable:this.deletable,x:this.x,y:this.y,defaultValue:((f=this.defaultValue)==null?void 0:f.toReference(i))||null,dataType:((e=this.dataType)==null?void 0:e.toReference(i))||null,readsValue:((y=this.readsValue)==null?void 0:y.toReference(i))||null,implements:((v=this.implements)==null?void 0:v.toReference(i))||null,outputs:this.outputs.map(I=>I.toReference(i)),calledBySuccess:this.calledBySuccess.map(I=>I.toReference(i)),calledByError:this.calledByError.map(I=>I.toReference(i)),calledByEntry:this.calledByEntry.map(I=>I.toReference(i)),throws:((T=this.throws)==null?void 0:T.toReference(i))||null,parent:((A=this.parent)==null?void 0:A.toReference(i))||null}}toFlatJSON(i=new Set){var l,f,e;return i.has(this.id)?[]:(i.add(this.id),[this.toShallowJSON(),...((l=this.defaultValue)==null?void 0:l.toFlatJSON(i))||[],...((f=this.dataType)==null?void 0:f.toFlatJSON(i))||[],...((e=this.implements)==null?void 0:e.toFlatJSON(i))||[],...this.outputs.flatMap(y=>y.toFlatJSON(i)),...this.throws?this.throws.toFlatJSON(i):[]])}toGenerationTarget(){var i;return{id:this.id,type:this.type,calledByEntry:this.calledByEntry.map(a=>a.id),calledByError:this.calledByError.map(a=>a.id),calledBySuccess:this.calledBySuccess.map(a=>a.id),implements:(i=this.implements)==null?void 0:i.id,parent:this.parent.id}}toFlatGenerationTarget(i=new Set){var l,f,e;return i.has(this.id)?[]:(i.add(this.id),[this.toGenerationTarget(),...((l=this.defaultValue)==null?void 0:l.toFlatGenerationTarget(i))||[],...((f=this.dataType)==null?void 0:f.toFlatGenerationTarget(i))||[],...((e=this.implements)==null?void 0:e.toFlatGenerationTarget(i))||[],...this.outputs.flatMap(y=>y.toFlatGenerationTarget(i)),...this.throws?this.throws.toFlatGenerationTarget(i):[]])}clearErrors(){var i,a,l;return this.errors=[],(i=this.dataType)==null||i.clearErrors(),(a=this.defaultValue)==null||a.clearErrors(),this.outputs.forEach(f=>f.clearErrors()),(l=this.throws)==null||l.clearErrors(),this}validate(){const i=LZ(this);return this.errors=i,{success:!0}}getErrors(){var a,l;return[...this.errors,...((a=this.defaultValue)==null?void 0:a.getErrors())||[],...((l=this.dataType)==null?void 0:l.getErrors())||[],...this.outputs.flatMap(f=>f.getErrors()),...this.throws?this.throws.getErrors():[]]}getShallowErrors(){return this.errors}getDefaultValue(){return this.defaultValue||null}setDefaultValue(i,a=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,"set-default-value"))){if(!this.checkCanEdit(this))return J.warn(`[setDefaultValue] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),a==null||a.attemptAutoclose("set-default-value",this.id),this;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,K.Affected)),a==null||a.attemptAutoclose("set-default-value",this.id),this}clone(i=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,P.CloneEntity)),a=null,l=null,f=!0){var j,q,Z;let e=lr(a,this);const y=this.toJSON(),v=l||V.UUID.uuid();y.outputs=[];const T=v.split("-id"),A=T[T.length-1||0]||v;y.id=v,y.version=V.UUID.uuid(),y.createdAt=(i==null?void 0:i.timestamp)||B().toISOString(),y.author=(i==null?void 0:i.author)||"1",y.previousVersion=null,y.deleted=!1,y.deletable=!0,y.editable=!0;const I=Ei(y,e);a?I.setParent(a,null):I.setParent(this.parent,null),f&&I.subscribe(),I.initChildren(i),i==null||i.add(I,K.Added);const O=(j=this.dataType)==null?void 0:j.clone(i,I,V.UUID.uuid(),f);I.setDataType(O||null,i);const L=(q=this.defaultValue)==null?void 0:q.clone(i,I,V.UUID.uuid(),f);I.setDefaultValue(L||null,i),this.implements&&I.setImplements(this.implements,i);const M=(Z=this.outputs)==null?void 0:Z.map((S,H)=>S.clone(i,I,A+"-return-declaration-"+H+"-id",f));return I.outputs=M,this.throws&&(I.throws=this.throws.clone(i,I,A+"-throws-id",f)),i==null||i.attemptAutoclose(P.CloneEntity,this.id),I}setDataType(i,a=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,P.SetDataType))){if(!this.checkCanEdit(this))return J.warn(`[setDataType] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),a==null||a.attemptAutoclose(P.SetDataType,this.id),this;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,K.Affected)),a==null||a.attemptAutoclose(P.SetDataType,this.id),this}removeDataType(i=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,P.RemoveDataType))){return this.checkCanEdit(this)?(this.dataType&&(this.dataType.remove({ignoreUpstream:!0},i),i==null||i.add(this,K.Affected),this.dataType=null),i==null||i.attemptAutoclose(P.RemoveDataType,this.id),this):(J.warn(`[removeDataType] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(P.RemoveDataType,this.id),this)}getDataType(i=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,"get-data-type"))){var l;if((!this.dataType||this.dataType.inferred)&&this.project.initialized,this.dataType)return i==null||i.attemptAutoclose("get-data-type",this.id),this.dataType;if(this.parent.dataType)return i==null||i.attemptAutoclose("get-data-type",this.id),this.parent.dataType;const a=(l=this.implements)==null?void 0:l.getDataType(i);return i==null||i.attemptAutoclose("get-data-type",this.id),a||null}};_(li,"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}),_(li,"type",p.BreakStatement),_(li,"USER_MANAGED_PARENT_TYPES",[p.Loop]),_(li,"PARENT_TYPES",[...li.USER_MANAGED_PARENT_TYPES]),_(li,"MUTABLE_BASE_PROPERTIES",[]),_(li,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),_(li,"BASE_PROPERTIES",[...li.MUTABLE_BASE_PROPERTIES,...li.INMUTABLE_BASE_PROPERTIES]),_(li,"MUTABLE_META_PROPERTIES",["x","y"]),_(li,"INMUTABLE_META_PROPERTIES",[...li.INMUTABLE_BASE_PROPERTIES]),_(li,"META_PROPERTIES",[...li.MUTABLE_META_PROPERTIES,...li.INMUTABLE_META_PROPERTIES]),_(li,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry","readsValue"]),_(li,"INMUTABLE_UPSTREAM_PROPERTIES",["parent"]),_(li,"UPSTREAM_PROPERTIES",[...li.MUTABLE_UPSTREAM_PROPERTIES,...li.INMUTABLE_UPSTREAM_PROPERTIES]),_(li,"MUTABLE_DOWNSTREAM_PROPERTIES",["outputs","throws"]),_(li,"INMUTABLE_DOWNSTREAM_PROPERTIES",["dataType","defaultValue"]),_(li,"DOWNSTREAM_PROPERTIES",[...li.MUTABLE_DOWNSTREAM_PROPERTIES,...li.INMUTABLE_DOWNSTREAM_PROPERTIES]),_(li,"PROPERTIES",[...li.META_PROPERTIES,...li.UPSTREAM_PROPERTIES,...li.DOWNSTREAM_PROPERTIES]);let po=li;function MZ(d){var i;d.outputs.forEach(a=>a.validate()),(i=d.throws)==null||i.validate();const u=[];return $i(d.errors,u)}const qOe=Object.freeze(Object.defineProperty({__proto__:null,validate:MZ},Symbol.toStringTag,{value:"Module"}));var xZ=(d=>(d.Parent="continue-statement-parent-field",d.ImplementsField="continue-statement-implements-field",d.DataTypeEntity="continue-statement-data-type-entity-field",d.DataType="continue-statement-data-type-field",d))(xZ||{});const oi=class oi extends nr{constructor(i,a){super(i);_(this,"initialData");_(this,"id");_(this,"x");_(this,"y");_(this,"type",p.ContinueStatement);_(this,"outputs",[]);_(this,"readsValue",null);_(this,"dataType",null);_(this,"defaultValue",null);_(this,"implements",null);_(this,"calledBySuccess",[]);_(this,"calledByError",[]);_(this,"calledByEntry",[]);_(this,"throws",null);_(this,"project");_(this,"errors",[]);_(this,"parent");_(this,"detachedDependents",{});_(this,"knownVersions",null);_(this,"activeVersion",!1);_(this,"initialized",!1);_(this,"startedInitialization",!1);_(this,"suggestion",!1);this.initialData=i,this.project=a,this.id=i.id,this.x=i.x,this.y=i.y}static new(i=null){return{id:V.UUID.uuid(),version:V.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||B().toISOString(),author:(i==null?void 0:i.author)||V.sessionAuthor,previousVersion:null,deleted:!1,deletable:!0,editable:!0,type:p.ContinueStatement,outputs:[],defaultValue:null,dataType:null,implements:null,readsValue:null,throws:null,parent:null,calledByEntry:[],calledBySuccess:[],calledByError:[],x:0,y:0}}static fromGenerationTarget(i,a){const l=X(i.parent),f=a.get(l),e=i.calledByEntry.map(L=>{const M=X(L);return a.get(M)}),y=i.calledBySuccess.map(L=>{const M=X(L);return a.get(M)}),v=i.calledByError.map(L=>{const M=X(L);return a.get(M)});let T=null;if(i.readsValue){const L=X(i.readsValue);T=a.get(L)}let A=null;if(i.implements){const L=X(i.implements);A=a.get(L)}const I={id:i.id,version:V.UUID.uuid(),createdAt:B().toISOString(),author:V.sessionAuthor,previousVersion:null,deleted:!1,deletable:!0,editable:!0,type:p.ContinueStatement,x:0,y:0,outputs:[],defaultValue:null,dataType:null,implements:A,readsValue:T,calledBySuccess:y,calledByError:v,calledByEntry:e,throws:null,parent:f},O=se(I,a);return O.setParent(f,null),O}static validateGenerationTarget(i,a){let l=JSON.parse(JSON.stringify(i));const f=[],e=Pr(l,{parent:{list:!1,types:[p.Loop]}},a);return l=e.modifiedData,f.push(...e.errors,...zi(l)),{errors:f,modifiedData:l}}validateGeneratedUpdate(i){const a=[];let l=JSON.parse(JSON.stringify(i));const f=Ad(l,this);return l=f.modifiedData,a.push(...f.errors),i.parent&&a.push(new oe({id:`${this.id}--${W.InvalidParentUpdate}`,code:W.InvalidParentUpdate,severity:Y.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.
|
|
183
183
|
If an entity is called by another, they must be in the same scope, which means they have the same parent.
|
|
184
184
|
You shouldn't have to manually update a 'parent' property.
|
|
185
|
-
Specifically for continue statements the parent needs to always be the 'loop' entity that contains it.`})),{errors:a,modifiedData:i}}subscribeDependents(i){return i.forEach(a=>{this.detachedDependents[a.entity.id]||(this.detachedDependents[a.entity.id]=a)}),this}unsubscribeDependents(i){return i.forEach(a=>{this.detachedDependents[a.entity.id]&&delete this.detachedDependents[a.entity.id]}),this}syncDependents(i=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,"sync-dependents"))){const a=[],l=[],f=[],e=[];return Object.values(this.detachedDependents).forEach(y=>{const v=y.entity.afterAllChildrenInitialized(i);a.push(...v.updated),l.push(...v.added),f.push(...v.removed),e.push(...v.affected)}),i==null||i.attemptAutoclose("sync-dependents",this.id),{updated:g(a),added:g(l),removed:g(f),affected:g(e),self:this}}onDetachedDependencyRemoved(i,a,l){const f=[],e=[],y=[],v=[];if(a==="continue-statement-implements-field"&&(this.setImplements(null,l),f.push(this)),a==="continue-statement-parent-field"){const{updated:T,added:A,removed:I}=this.remove({ignoreUpstream:!1},l);f.push(...T),e.push(...A),y.push(...I)}return{updated:g(f),added:g(e),removed:g(y),affected:g(v),self:this}}onDetachedDependencyRestored(i,a,l){const f=[],e=[],y=[],v=[];if(a==="continue-statement-implements-field"&&(this.setImplements(i,l),f.push(this)),a==="continue-statement-parent-field"){const{updated:T,added:A,removed:I}=this.restore({},l);f.push(...T),e.push(...A),y.push(...I)}return{updated:g(f),added:g(e),removed:g(y),affected:g(v),self:this}}unsubscribeFromDependencies(){var i,a,l,f,e,y,v,T;return(i=this.parent)==null||i.unsubscribeDependents([{entity:this,field:"continue-statement-parent-field"}]),(l=(a=this.implements)==null?void 0:a.unsubscribeDependents)==null||l.call(a,[{entity:this,field:"continue-statement-implements-field"}]),(y=(e=(f=this.dataType)==null?void 0:f.entity)==null?void 0:e.unsubscribeDependents)==null||y.call(e,[{entity:this,field:"continue-statement-data-type-entity-field"}]),(T=(v=this.dataType)==null?void 0:v.unsubscribeDependents)==null||T.call(v,[{entity:this,field:"continue-statement-data-type-field"}]),this}subscribeToDependencies(){var i,a,l,f,e,y,v,T;return(i=this.parent)==null||i.subscribeDependents([{entity:this,field:"continue-statement-parent-field"}]),(l=(a=this.implements)==null?void 0:a.subscribeDependents)==null||l.call(a,[{entity:this,field:"continue-statement-implements-field"}]),(y=(e=(f=this.dataType)==null?void 0:f.entity)==null?void 0:e.subscribeDependents)==null||y.call(e,[{entity:this,field:"continue-statement-data-type-entity-field"}]),(T=(v=this.dataType)==null?void 0:v.subscribeDependents)==null||T.call(v,[{entity:this,field:"continue-statement-data-type-field"}]),this}increaseVersion(i){if(i&&!B(i).isValid())throw new Error(`The shared timestamp '${i}' is not a valid ISO 8601 date string.`);return i&&B(i).isSame(B(this.createdAt))?this:(this.previousVersion=this.version,this.version=V.UUID.uuid(),this.createdAt=B(i).toISOString()||B().toISOString(),this)}captureVersion(){var a;const i=((a=this.knownVersions)==null?void 0:a.get(this.version))||new oi(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.outputs=[...this.outputs],i.readsValue=this.readsValue,i.defaultValue=this.defaultValue,i.dataType=this.dataType,i.implements=this.implements,i.throws=this.throws,i.calledBySuccess=[...this.calledBySuccess],i.calledByError=[...this.calledByError],i.calledByEntry=[...this.calledByEntry],i.parent=this.parent,this}recursiveCaptureUpstreamVersions(i){const a=[],l=[],f=[],e=[];if(this.parent){this.parent.increaseVersion(i);const y=this.parent.recursiveCaptureUpstreamVersions(i);a.push(this.parent,...y.updated),l.push(...y.added),f.push(...y.removed)}return{updated:g(a),added:g(l),removed:g(f),affected:g(e),self:this}}async restoreVersion(i){var v;const a=[],l=[],f=[],e=[];if(this.version===i)return{updated:g(a),added:g(l),removed:g(f),affected:g(e),self:this};if(!this.knownVersions){const T=new Map;for(const[A,I]of this.knownVersions||new Map){if(T.set(A,I),I.activeVersion=!1,I.knownVersions)for(const[O,L]of I.knownVersions)T.set(O,L);I.knownVersions=null}}let y=(v=this.knownVersions)==null?void 0:v.get(i);if(!y){const T=await this.APILoadVersion({},i);if(!T)throw new Error(`Version with id '${i}' for entity with id '${this.id}' not found.`);y=new oi(T,this.project)}return this.metaSync(y.toShallowJSON(),null),this.previousVersion=y.previousVersion,this.version=y.version,this.createdAt=y.createdAt,this.author=y.author,this.deleted=y.deleted,this.outputs=y.outputs,this.readsValue=y.readsValue,this.defaultValue=y.defaultValue,this.dataType=y.dataType,this.implements=y.implements,this.throws=y.throws,this.calledBySuccess=y.calledBySuccess,this.calledByError=y.calledByError,this.calledByEntry=y.calledByEntry,this.parent=y.parent,{updated:g(a),added:g(l),removed:g(f),affected:g(e),self:this}}updateWithShallowTransfer(i,a=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,P.UpdateWithShallowTransfer))){if(!this.checkCanEdit(this))return J.warn(`[updateWithShallowTransfer] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),a==null||a.attemptAutoclose(P.UpdateWithShallowTransfer,this.id),this;if(this.metaSync(i,a),this.version=i.version,this.createdAt=i.createdAt,this.author=i.author,this.deleted=i.deleted,this.previousVersion=i.previousVersion,this.unsubscribeFromDependencies(),i.parent){const l=X(i.parent),f=this.project.get(l),e=this.parent;if(e&&e.id!==(f==null?void 0:f.id)&&this.removeFromParent(a),f)this.setParent(f,a);else throw a==null||a.attemptAutoclose(P.UpdateWithShallowTransfer,this.id),new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw a==null||a.attemptAutoclose(P.UpdateWithShallowTransfer,this.id),new Error(`${this.type} with id '${this.id}' must have a 'parent'`);return i.calledByEntry.forEach(l=>{const f=X(l),e=this.project.get(f);e&&(this.addEntryCaller(e,a),e.addCall(this,a))}),[...this.calledByEntry].forEach(l=>{i.calledByEntry.find(e=>X(e)===l.id)||(this.removeCaller(l,a),l.removeCall(this,a))}),i.calledBySuccess.forEach(l=>{const f=X(l),e=this.project.get(f);e&&(this.addSuccessCaller(e,a),e.addSuccessCall(this,a))}),[...this.calledBySuccess].forEach(l=>{i.calledBySuccess.find(e=>X(e)===l.id)||(this.removeCaller(l,a),l.removeCall(this,a))}),i.calledByError.forEach(l=>{const f=X(l),e=this.project.get(f);e&&(this.addErrorCaller(e,a),e.addErrorCall(this,a))}),[...this.calledBySuccess].forEach(l=>{i.calledBySuccess.find(e=>X(e)===l.id)||(this.removeCaller(l,a),l.removeCall(this,a))}),this.captureVersion(),this.subscribeToDependencies(),a==null||a.attemptAutoclose(P.UpdateWithShallowTransfer,this.id),this}hydrateAncestors(){const i=[],a=[],l=[],f=[];if(this.initialData.parent){const e=X(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.implements){const e=X(this.initialData.implements),y=this.project.get(e);if(y)this.setImplements(y,null),i.push(y);else if(e)throw new Error(`${rr(this.type)} with id '${this.id}' has a 'implements' reference "${e}" which is missing in the project`)}if(this.initialData.readsValue){const e=X(this.initialData.readsValue),y=this.project.get(e);y&&(this.setValueWriter(y,null),i.push(y))}return this.initialData.calledByEntry.forEach(e=>{const y=X(e),v=this.project.get(y);v&&this.addEntryCaller(v,null)}),this.initialData.calledBySuccess.forEach(e=>{const y=X(e),v=this.project.get(y);v&&this.addSuccessCaller(v,null)}),this.initialData.calledByError.forEach(e=>{const y=X(e),v=this.project.get(y);v&&this.addErrorCaller(v,null)}),{updated:g(i),added:g(a),removed:g(l),affected:g(f),self:this}}afterAllChildrenInitialized(i=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,P.AfterAllChildrenInitialized))){if(!this.checkCanEdit(this))return J.warn(`[afterAllChildrenInitialized] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(P.AfterAllChildrenInitialized,this.id),{updated:[],added:[],removed:[],affected:[],self:this};const a=[],l=[],f=[],e=[];return this.initialized=!0,!this.dataType||this.dataType.inferred,this.parent.syncTerminationStatements(i),this.captureVersion(),i==null||i.attemptAutoclose(P.AfterAllChildrenInitialized,this.id),{updated:g(a),added:g(l),removed:g(f),affected:g(e),self:this}}addSelfToProject(i=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,"add-self-to-project"))){var y,v;const a=[this],l=[],f=[],e=[];return this.readsValue&&(this.readsValue.addValueReader(this,i),a.push(this.readsValue)),this.calledByEntry.forEach(T=>{T.addCall(this,i),a.push(T)}),this.calledBySuccess.forEach(T=>{T.addSuccessCall(this,i),a.push(T)}),this.calledByError.forEach(T=>{T.addErrorCall(this,i),a.push(T)}),this.parent.addContinueStatement(this),a.push(this),i==null||i.add(this.parent,K.Affected),(y=this.parent)==null||y.breakStatements.forEach(T=>{T.id!==this.id&&(e.push(T),i==null||i.add(T,K.Affected))}),(v=this.parent)==null||v.continueStatements.forEach(T=>{T.id!==this.id&&(e.push(T),i==null||i.add(T,K.Affected))}),this.subscribe(),this.subscribeToDependencies(),i==null||i.attemptAutoclose("add-self-to-project",this.id),{updated:g(a),added:g(l),removed:g(f),affected:g(e),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}addSuccessCaller(i,a=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,P.AddSuccessCaller)),l=!1){return this.checkCanEditWithCounterpartAndSideEffects(this,i,P.AddSuccessCaller,a)?(this.calledBySuccess.find(f=>f.id===i.id)||(this.calledBySuccess.push(i),a==null||a.add(this,K.Updated),l&&Ye(this,a)),a==null||a.attemptAutoclose(P.AddSuccessCaller,this.id),this):this}addErrorCaller(i,a=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,P.AddErrorCaller)),l=!1){return this.checkCanEditWithCounterpartAndSideEffects(this,i,P.AddErrorCaller,a)?(this.calledByError.find(f=>f.id===i.id)||(this.calledByError.push(i),a==null||a.add(this,K.Updated),l&&Ye(this,a)),a==null||a.attemptAutoclose(P.AddErrorCaller,this.id),this):this}addEntryCaller(i,a=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,P.AddEntryCaller)),l=!1){return this.checkCanEditWithCounterpartAndSideEffects(this,i,P.AddEntryCaller,a)?(this.calledByEntry.find(f=>f.id===i.id)||(this.calledByEntry.push(i),a==null||a.add(this,K.Updated),l&&Ye(this,a)),a==null||a.attemptAutoclose(P.AddEntryCaller,this.id),this):this}removeCaller(i,a=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,"remove-caller")),l=!1){return this.checkCanEditWithCounterpartAndSideEffects(this,i,P.RemoveCaller,a)?(this.calledBySuccess=this.calledBySuccess.filter(f=>f.id!==i.id?!0:(a==null||a.add(this,K.Updated),a==null||a.add(f,K.Affected),!1)),this.calledByError=this.calledByError.filter(f=>f.id!==i.id?!0:(a==null||a.add(this,K.Updated),a==null||a.add(f,K.Affected),!1)),this.calledByEntry=this.calledByEntry.filter(f=>f.id!==i.id?!0:(a==null||a.add(this,K.Updated),a==null||a.add(f,K.Affected),!1)),l&&Ye(this,a),a==null||a.attemptAutoclose(P.RemoveCaller,this.id),this):this}setThrows(i,a=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,"set-throws"))){var l;if(!this.checkCanEdit(this))return J.warn(`[setThrows] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),a==null||a.attemptAutoclose("set-throws",this.id),this;if(i!==null&&i.parentRelationType!==Wa.Error)throw new Error("The 'throws' InputMap must have a parentRelationType of 'Error'.");return((l=this.throws)==null?void 0:l.id)!==(i==null?void 0:i.id)&&(this.throws=i,a==null||a.add(this,K.Updated)),a==null||a.attemptAutoclose("set-throws",this.id),this}addOutput(i,a=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,"add-output"))){return this.checkCanEdit(this)?this.outputs.includes(i)?(a==null||a.attemptAutoclose("add-output",this.id),this):(this.outputs.push(i),a==null||a.add(this,K.Affected),a==null||a.attemptAutoclose("add-output",this.id),this):(J.warn(`[addOutput] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),a==null||a.attemptAutoclose("add-output",this.id),this)}removeOutput(i,a=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,"remove-output"))){if(!this.checkCanEdit(this))return J.warn(`[removeOutput] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),a==null||a.attemptAutoclose("remove-output",this.id),this;const l=this.outputs.findIndex(f=>f.id===i.id);return l>-1&&(this.outputs.splice(l,1),a&&(a==null||a.add(this,K.Affected))),a==null||a.attemptAutoclose("remove-output",this.id),this}setParent(i,a=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,P.SetParent))){var l;return this.checkCanEditWithCounterpartAndSideEffects(this,i,P.SetParent,a)?(((l=this.parent)==null?void 0:l.id)!==(i==null?void 0:i.id)&&(this.parent=i,a&&(a==null||a.add(this,K.Updated))),a==null||a.attemptAutoclose(P.SetParent,this.id),this):this}setImplements(i,a=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,P.SetImplements))){var l;return this.checkCanEdit(this)?(((l=this.implements)==null?void 0:l.id)!==(i==null?void 0:i.id)&&(this.implements=i,a&&(a==null||a.add(this,K.Updated))),a==null||a.attemptAutoclose(P.SetImplements,this.id),this):(J.warn(`[setImplements] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),a==null||a.attemptAutoclose(P.SetImplements,this.id),this)}setValueWriter(i,a=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,P.SetValueWriter))){return i&&!this.checkCanEditWithCounterpartAndSideEffects(this,i,P.SetValueWriter,a)?this:!i&&!this.checkCanEdit(this)?(J.warn(`[setValueWriter] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),a==null||a.attemptAutoclose(P.SetValueWriter,this.id),this):(this.readsValue!==i&&(this.readsValue=i,a==null||a.add(this,K.Updated)),a==null||a.attemptAutoclose(P.SetValueWriter,this.id),this)}removeValueWriter(i=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,P.RemoveValueWriter))){return this.readsValue&&!this.checkCanEditWithCounterpartAndSideEffects(this,this.readsValue,P.RemoveValueWriter,i)?this:(this.readsValue&&(this.readsValue=null,i==null||i.add(this,K.Updated)),i==null||i.attemptAutoclose(P.RemoveValueWriter,this.id),this)}initChildren(i=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,"init-children"))){if(this.initialized||this.startedInitialization)return this;if(this.startedInitialization=!0,this.initialData.defaultValue&&(this.defaultValue=se(this.initialData.defaultValue,this.project),this.defaultValue.setParent(this,null),this.defaultValue.initChildren(i)),this.initialData.dataType&&(this.dataType=se(this.initialData.dataType,this.project),this.dataType.setParent(this,null),this.dataType.initChildren(i)),_d.initReadsValue(this),this.initialData.implements){const a=se(this.initialData.implements,this.project);this.setImplements(a,null)}return this.outputs=this.initialData.outputs.map(a=>{const l=se(a,this.project);return l.setParent(this,null),l.initChildren(i),l}),this.initialData.throws&&(this.throws=se(this.initialData.throws,this.project),this.throws.setParent(this,null),this.throws.initChildren(i)),this.subscribeToDependencies(),this.afterAllChildrenInitialized(i),i==null||i.attemptAutoclose("init-children",this.id),this}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(i,a=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,"meta-sync"))){const l=Xi(this,i),f=Yi(this,l),e=this.toMeta();return this.x=l.x||e.x,this.y=l.y||e.y,super.baseMetaSync(l,this),l.deleted===!0&&!e.deleted?a==null||a.add(this,K.Removed):l.deleted===!1&&e.deleted?a==null||a.add(this,K.Added):f&&(a==null||a.add(this,K.Updated)),a==null||a.attemptAutoclose("meta-sync",this.id),this}async APILoad(i=Ie,...a){return await oi.repository.APILoad(this.id,...a),this}async APICreate(i=Ie,...a){return await oi.repository.APICreate(this.toShallowJSON(),...a),this}async APIUpdate(i=Ie,...a){return await oi.repository.APIUpdate(this.toShallowJSON(),...a),this}async APIDelete(i=Ie,...a){return await oi.repository.APIDelete(this.toShallowJSON(),...a),this}async APIClone(i=Ie,...a){return await oi.repository.APIClone(this.id,...a),this}async APILoadVersion(i=Ie,a,...l){return await oi.repository.APILoadVersion(this.id,a,...l)}removeFromParent(i=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,P.RemoveFromParent))){if(!this.checkCanEdit(this))return J.warn(`[removeFromParent] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(P.RemoveFromParent,this.id),{added:[],updated:[],removed:[],affected:[],self:this};const a=[],l=[],f=[],e=[];return this.parent.removeContinueStatement(this),this.parent.detachedChildren.includes(this)&&this.parent.unsubscribeDetachedChild(this),i==null||i.attemptAutoclose(P.RemoveFromParent,this.id),{added:g(f),updated:g(a),removed:g(l),affected:g(e),self:this}}remove({ignoreUpstream:i}={ignoreUpstream:!1},a=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,P.RemoveEntity))){var v,T,A;if(!this.checkCanDelete(this)||!this.checkCanEdit(this))return J.warn(`[remove] User is not allowed to delete or edit this ${this.type} entity with id: ${this.id}`),a==null||a.event({id:`${P.RemoveEntity}-${this.id}`,action:P.RemoveEntity,owner:this,errorReason:Si.ActionOwnerEntityNonDeletable,rootAction:((v=a==null?void 0:a.self)==null?void 0:v.id)===this.id&&(a==null?void 0:a.autoCloseActionName)===P.RemoveEntity}),a==null||a.attemptAutoclose(P.RemoveEntity,this.id),{added:[],updated:[],removed:[],affected:[],self:this};const l=[],f=[],e=[],y=[];if(a!=null&&a.hasRemoved(this.id))return a==null||a.attemptAutoclose(P.RemoveEntity,this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(f.push(this),this.unsubscribe(),this.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},a),Object.values(this.detachedDependents).forEach(I=>{const{updated:O,removed:L,added:M}=I.entity.onDetachedDependencyRemoved(this,I.field,a);l.push(...O),f.push(...L),e.push(...M)}),this.readsValue&&(l.push(this.readsValue),this.readsValue.removeValueReader(this,a)),this.outputs.forEach(I=>{const{updated:O,removed:L}=I.remove({ignoreUpstream:!0},a);l.push(...O),f.push(...L)}),this.throws){const{updated:I,removed:O}=this.throws.remove({ignoreUpstream:!0},a);l.push(...I),f.push(...O)}if(this.dataType){const{updated:I,removed:O}=this.dataType.remove({ignoreUpstream:!0},a);l.push(...I),f.push(...O)}if(!i){const I=this.removeFromParent(a);e.push(...I.added),l.push(...I.updated),f.push(...I.removed),y.push(...I.affected),this.calledBy.forEach(O=>{l.push(O),O.removeCall(this,a)})}return a==null||a.add(this.parent,K.Affected),(T=this.parent)==null||T.breakStatements.forEach(I=>{I.id!==this.id&&(y.push(I),a==null||a.add(I,K.Affected))}),(A=this.parent)==null||A.continueStatements.forEach(I=>{I.id!==this.id&&(y.push(I),a==null||a.add(I,K.Affected))}),a==null||a.attemptAutoclose(P.RemoveEntity,this.id),{added:g(e),updated:g(l),removed:g(f),affected:g(y),self:this}}restore({}={},i=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,P.RestoreEntity))){if(!this.checkCanEdit(this))return J.warn(`[restore] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(P.RestoreEntity,this.id),{added:[],updated:[],removed:[],affected:[],self:this};const a=[],l=[],f=[],e=[];if(i!=null&&i.hasAdded(this.id))return i==null||i.attemptAutoclose(P.RestoreEntity,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:T,added:A}=y.entity.onDetachedDependencyRestored(this,y.field,i);l.push(...v),f.push(...T),a.push(...A)}),this.readsValue&&(l.push(this.readsValue),this.readsValue.addValueReader(this,i)),this.outputs.forEach(y=>{const{updated:v}=y.restore({},i);l.push(...v)}),this.throws){const{updated:y}=this.throws.restore({},i);l.push(...y)}if(this.dataType){const{updated:y}=this.dataType.restore({},i);l.push(...y)}return this.parent.addContinueStatement(this),this.calledBySuccess.forEach(y=>{l.push(y),y.addSuccessCall(this,i)}),this.calledByError.forEach(y=>{l.push(y),y.addErrorCall(this,i)}),this.calledByEntry.forEach(y=>{l.push(y),y.addCall(this,i)}),i==null||i.attemptAutoclose(P.RestoreEntity,this.id),{added:g(a),updated:g(l),removed:g(f),affected:g(e),self:this}}toFlat(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this,...this.outputs.flatMap(l=>l.toFlat(i)),...this.calledBy.flatMap(l=>l.toFlat(i)),...this.throws?this.throws.toFlat(i):[],...this.dataType?this.dataType.toFlat(i):[]])}toFlatIds(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.id,...this.outputs.flatMap(l=>l.toFlatIds(i)),...this.calledBy.flatMap(l=>l.toFlatIds(i)),...this.throws?this.throws.toFlatIds(i):[],...this.dataType?this.dataType.toFlatIds(i):[]])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,x:this.x,y:this.y,type:this.type,editable:this.editable,deletable:this.deletable}}toJSON(i=new Set){var a,l,f,e,y,v;return i.has(this.id)?this.toReference():(i.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,editable:this.editable,deletable:this.deletable,x:this.x,y:this.y,defaultValue:((a=this.defaultValue)==null?void 0:a.toJSON(i))||null,dataType:((l=this.dataType)==null?void 0:l.toJSON(i))||null,readsValue:((f=this.readsValue)==null?void 0:f.toReference())||null,implements:((e=this.implements)==null?void 0:e.toJSON(i))||null,calledBySuccess:this.calledBySuccess.map(T=>T.toReference()),calledByError:this.calledByError.map(T=>T.toReference()),calledByEntry:this.calledByEntry.map(T=>T.toReference()),outputs:this.outputs.map(T=>T.toJSON(i)),throws:((y=this.throws)==null?void 0:y.toJSON(i))||null,parent:((v=this.parent)==null?void 0:v.toReference())||null})}toJSONClone(i=ke){var l,f,e,y,v,T,A,I,O,L;let a;return(l=i.seenEntityMaps)!=null&&l.has(this.id)?a=i.seenEntityMaps.get(this.id):(a=i.newId||or(this,this.project,i.uuidStrategy),i.seenEntityMaps&&i.seenEntityMaps.set(this.id,a)),(f=i.seenEntities)!=null&&f.has(a)||(e=i.seenEntities)!=null&&e.has(this.id)?this.toReference({seenEntityMaps:i.seenEntityMaps}):((y=i.seenEntities)==null||y.add(a),(v=i.seenEntities)==null||v.add(this.id),{id:a,version:V.UUID.uuid(),createdAt:i.timestamp||B().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,editable:this.editable,deletable:this.deletable,x:this.x,y:this.y,defaultValue:((T=this.defaultValue)==null?void 0:T.toJSONClone({...i,newId:null}))||null,dataType:((A=this.dataType)==null?void 0:A.toJSONClone({...i,newId:null}))||null,readsValue:((I=this.readsValue)==null?void 0:I.toReference({seenEntityMaps:i.seenEntityMaps}))||null,implements:(()=>{var M;return this.implements&&this.project.getBuiltIn(this.implements.id)?this.implements.toJSON():((M=this.implements)==null?void 0:M.toJSONClone({...i,newId:null}))||null})(),calledBySuccess:this.calledBySuccess.map(M=>M.toReference({seenEntityMaps:i.seenEntityMaps})),calledByError:this.calledByError.map(M=>M.toReference({seenEntityMaps:i.seenEntityMaps})),calledByEntry:this.calledByEntry.map(M=>M.toReference({seenEntityMaps:i.seenEntityMaps})),outputs:this.outputs.map(M=>M.toJSONClone({...i,newId:null})),throws:((O=this.throws)==null?void 0:O.toJSONClone({...i,newId:null}))||null,parent:((L=this.parent)==null?void 0:L.toReference({seenEntityMaps:i.seenEntityMaps}))||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+"--"+V.UUID.uuid()+"--ref",type:p.GenericReference,entityId:a,version:this.version,entityType:this.type}}toShallowJSON(i=ke){var l,f,e,y,v,T;let a=this.id;return(l=i.seenEntityMaps)!=null&&l.has(this.id)&&(a=i.seenEntityMaps.get(this.id)),{id:a,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,editable:this.editable,deletable:this.deletable,x:this.x,y:this.y,defaultValue:((f=this.defaultValue)==null?void 0:f.toReference(i))||null,dataType:((e=this.dataType)==null?void 0:e.toReference(i))||null,readsValue:((y=this.readsValue)==null?void 0:y.toReference(i))||null,implements:((v=this.implements)==null?void 0:v.toReference(i))||null,outputs:this.outputs.map(A=>A.toReference(i)),calledBySuccess:this.calledBySuccess.map(A=>A.toReference(i)),calledByError:this.calledByError.map(A=>A.toReference(i)),calledByEntry:this.calledByEntry.map(A=>A.toReference(i)),throws:((T=this.throws)==null?void 0:T.toReference(i))||null,parent:this.parent.toReference(i)}}toFlatJSON(i=new Set){var l,f,e,y;return i.has(this.id)?[]:(i.add(this.id),[this.toShallowJSON(),...((l=this.defaultValue)==null?void 0:l.toFlatJSON(i))||[],...((f=this.dataType)==null?void 0:f.toFlatJSON(i))||[],...((e=this.implements)==null?void 0:e.toFlatJSON(i))||[],...this.outputs.flatMap(v=>v.toFlatJSON(i)),...this.calledBy.flatMap(v=>v.toFlatJSON(i)),...((y=this.throws)==null?void 0:y.toFlatJSON(i))||[]])}toGenerationTarget(){var i;return{id:this.id,type:this.type,calledByEntry:this.calledByEntry.map(a=>a.id),calledByError:this.calledByError.map(a=>a.id),calledBySuccess:this.calledBySuccess.map(a=>a.id),implements:(i=this.implements)==null?void 0:i.id,parent:this.parent.id}}toFlatGenerationTarget(i=new Set){var l,f,e;return i.has(this.id)?[]:(i.add(this.id),[this.toGenerationTarget(),...((l=this.defaultValue)==null?void 0:l.toFlatGenerationTarget(i))||[],...((f=this.dataType)==null?void 0:f.toFlatGenerationTarget(i))||[],...((e=this.implements)==null?void 0:e.toFlatGenerationTarget(i))||[],...this.outputs.flatMap(y=>y.toFlatGenerationTarget(i)),...this.throws?this.throws.toFlatGenerationTarget(i):[]])}clearErrors(){var i,a,l;return this.errors=[],(i=this.dataType)==null||i.clearErrors(),(a=this.defaultValue)==null||a.clearErrors(),this.outputs.forEach(f=>f.clearErrors()),(l=this.throws)==null||l.clearErrors(),this}validate(){const i=MZ(this);return this.errors=i,{success:!0}}getErrors(){var a,l;return[...this.errors,...((a=this.defaultValue)==null?void 0:a.getErrors())||[],...((l=this.dataType)==null?void 0:l.getErrors())||[],...this.outputs.flatMap(f=>f.getErrors()),...this.throws?this.throws.getErrors():[]]}getShallowErrors(){return this.errors}getDefaultValue(){return this.defaultValue||null}setDefaultValue(i,a=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,"set-default-value"))){if(!this.checkCanEdit(this))return J.warn(`[setDefaultValue] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),a==null||a.attemptAutoclose("set-default-value",this.id),this;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,K.Affected)),a==null||a.attemptAutoclose("set-default-value",this.id),this}clone(i=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,P.CloneEntity)),a=null,l=null,f=!0){var j,q,Z;let e=lr(a,this);const y=this.toJSON(),v=l||V.UUID.uuid();y.outputs=[];const T=v.split("-id"),A=T[T.length-1||0]||v;y.id=v,y.version=V.UUID.uuid(),y.createdAt=(i==null?void 0:i.timestamp)||B().toISOString(),y.author=(i==null?void 0:i.author)||"1",y.previousVersion=null,y.deleted=!1,y.deletable=!0,y.editable=!0;const I=Ei(y,e);a?I.setParent(a,null):I.setParent(this.parent,null),f&&I.subscribe(),I.initChildren(i),i==null||i.add(I,K.Added);const O=(j=this.dataType)==null?void 0:j.clone(i,I,V.UUID.uuid(),f);I.setDataType(O||null,i);const L=(q=this.defaultValue)==null?void 0:q.clone(i,I,V.UUID.uuid(),f);I.setDefaultValue(L||null,i),this.implements&&I.setImplements(this.implements,i);const M=(Z=this.outputs)==null?void 0:Z.map((S,H)=>S.clone(i,I,A+"-return-declaration-"+H+"-id",f));return I.outputs=M,this.throws&&(I.throws=this.throws.clone(i,I,A+"-throws-id",f)),i==null||i.attemptAutoclose(P.CloneEntity,this.id),I}setDataType(i,a=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,P.SetDataType))){if(!this.checkCanEdit(this))return J.warn(`[setDataType] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),a==null||a.attemptAutoclose(P.SetDataType,this.id),this;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,K.Affected)),a==null||a.attemptAutoclose(P.SetDataType,this.id),this}removeDataType(i=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,P.RemoveDataType))){return this.checkCanEdit(this)?(this.dataType&&(this.dataType.remove({ignoreUpstream:!0},i),i==null||i.add(this,K.Affected),this.dataType=null),i==null||i.attemptAutoclose(P.RemoveDataType,this.id),this):(J.warn(`[removeDataType] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(P.RemoveDataType,this.id),this)}getDataType(i=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,"get-data-type"))){var l;if((!this.dataType||this.dataType.inferred)&&this.project.initialized,this.dataType)return i==null||i.attemptAutoclose("get-data-type",this.id),this.dataType;const a=(l=this.implements)==null?void 0:l.getDataType(i);return i==null||i.attemptAutoclose("get-data-type",this.id),a||null}};_(oi,"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}),_(oi,"type",p.ContinueStatement),_(oi,"USER_MANAGED_PARENT_TYPES",[p.Loop]),_(oi,"PARENT_TYPES",[...oi.USER_MANAGED_PARENT_TYPES]),_(oi,"MUTABLE_BASE_PROPERTIES",[]),_(oi,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),_(oi,"BASE_PROPERTIES",[...oi.MUTABLE_BASE_PROPERTIES,...oi.INMUTABLE_BASE_PROPERTIES]),_(oi,"MUTABLE_META_PROPERTIES",["x","y"]),_(oi,"INMUTABLE_META_PROPERTIES",[...oi.INMUTABLE_BASE_PROPERTIES]),_(oi,"META_PROPERTIES",[...oi.MUTABLE_META_PROPERTIES,...oi.INMUTABLE_META_PROPERTIES]),_(oi,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry","readsValue"]),_(oi,"INMUTABLE_UPSTREAM_PROPERTIES",["parent"]),_(oi,"UPSTREAM_PROPERTIES",[...oi.MUTABLE_UPSTREAM_PROPERTIES,...oi.INMUTABLE_UPSTREAM_PROPERTIES]),_(oi,"MUTABLE_DOWNSTREAM_PROPERTIES",["outputs","throws"]),_(oi,"INMUTABLE_DOWNSTREAM_PROPERTIES",["dataType","defaultValue"]),_(oi,"DOWNSTREAM_PROPERTIES",[...oi.MUTABLE_DOWNSTREAM_PROPERTIES,...oi.INMUTABLE_DOWNSTREAM_PROPERTIES]),_(oi,"PROPERTIES",[...oi.META_PROPERTIES,...oi.UPSTREAM_PROPERTIES,...oi.DOWNSTREAM_PROPERTIES]);let co=oi;function UZ(d){var i;(i=d.dataType)==null||i.validate();const u=[];return $i(d.errors,u)}const ZOe=Object.freeze(Object.defineProperty({__proto__:null,validate:UZ},Symbol.toStringTag,{value:"Module"}));var jZ=(d=>(d.DataTypeEntity="data-type-entity",d))(jZ||{});const ei=class ei extends nr{constructor(i,a){super(i);_(this,"initialData");_(this,"id");_(this,"name");_(this,"codeName",null);_(this,"description",null);_(this,"index");_(this,"required");_(this,"parentRelationType");_(this,"type",p.ValueDescriptor);_(this,"defaultValue",null);_(this,"dataType",null);_(this,"project");_(this,"errors",[]);_(this,"parent");_(this,"detachedDependents",{});_(this,"knownVersions",null);_(this,"activeVersion",!1);_(this,"initialized",!1);_(this,"startedInitialization",!1);_(this,"codeNativeValueValidation",null);this.initialData=i,this.project=a,this.id=i.id,this.name=i.name,this.description=i.description,this.index=i.index,this.codeName=i.codeName,this.required=i.required,this.parentRelationType=i.parentRelationType}static new(i=null){return{id:V.UUID.uuid(),version:V.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||B().toISOString(),author:(i==null?void 0:i.author)||V.sessionAuthor,previousVersion:null,deleted:!1,deletable:!0,editable:!0,type:p.ValueDescriptor,name:"",codeName:null,description:"",dataType:null,index:0,required:!1,parentRelationType:ye.FixedArguments,defaultValue:null,parent:null}}static fromGenerationTarget(i,a){const l=i.parent?X(i.parent):null,f=l?a.get(l):null,e=i.parentRelationType===ye.FixedArguments?f==null?void 0:f.inputs.length:null,y={id:i.id,version:V.UUID.uuid(),createdAt:B().toISOString(),author:V.sessionAuthor,previousVersion:null,deleted:!1,name:i.name,deletable:!0,editable:!0,type:p.ValueDescriptor,index:e||0,codeName:i.codeName,description:i.description,required:i.required,defaultValue:null,parentRelationType:i.parentRelationType,dataType:null,parent:f},v=se(y,a);return f&&v.setParent(f,null),v}static validateGenerationTarget(i,a){let l=JSON.parse(JSON.stringify(i));const f=[],e=Pr(l,{parent:{list:!1,types:[p.ActionDescriptor]}},a);l=e.modifiedData,f.push(...e.errors,...zi(l));const y=l.parent&&a.get(l.parent),v=y&&Ao(y);return v&&v.type===p.ActionDescriptor&&f.push(new oe({id:`${i.id}--${W.BuiltInEntityParent}`,code:W.BuiltInEntityParent,severity:Y.Error,message:`Entity of type "${i.type}" with id "${i.id}", has a parent that is a built-in entity "${v.name}" of type '${v.type}' with id '${v.id}'.
|
|
185
|
+
Specifically for continue statements the parent needs to always be the 'loop' entity that contains it.`})),{errors:a,modifiedData:i}}subscribeDependents(i){return i.forEach(a=>{this.detachedDependents[a.entity.id]||(this.detachedDependents[a.entity.id]=a)}),this}unsubscribeDependents(i){return i.forEach(a=>{this.detachedDependents[a.entity.id]&&delete this.detachedDependents[a.entity.id]}),this}syncDependents(i=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,"sync-dependents"))){const a=[],l=[],f=[],e=[];return Object.values(this.detachedDependents).forEach(y=>{const v=y.entity.afterAllChildrenInitialized(i);a.push(...v.updated),l.push(...v.added),f.push(...v.removed),e.push(...v.affected)}),i==null||i.attemptAutoclose("sync-dependents",this.id),{updated:g(a),added:g(l),removed:g(f),affected:g(e),self:this}}onDetachedDependencyRemoved(i,a,l){const f=[],e=[],y=[],v=[];if(a==="continue-statement-implements-field"&&(this.setImplements(null,l),f.push(this)),a==="continue-statement-parent-field"){const{updated:T,added:A,removed:I}=this.remove({ignoreUpstream:!1},l);f.push(...T),e.push(...A),y.push(...I)}return{updated:g(f),added:g(e),removed:g(y),affected:g(v),self:this}}onDetachedDependencyRestored(i,a,l){const f=[],e=[],y=[],v=[];if(a==="continue-statement-implements-field"&&(this.setImplements(i,l),f.push(this)),a==="continue-statement-parent-field"){const{updated:T,added:A,removed:I}=this.restore({},l);f.push(...T),e.push(...A),y.push(...I)}return{updated:g(f),added:g(e),removed:g(y),affected:g(v),self:this}}unsubscribeFromDependencies(){var i,a,l,f,e,y,v,T;return(i=this.parent)==null||i.unsubscribeDependents([{entity:this,field:"continue-statement-parent-field"}]),(l=(a=this.implements)==null?void 0:a.unsubscribeDependents)==null||l.call(a,[{entity:this,field:"continue-statement-implements-field"}]),(y=(e=(f=this.dataType)==null?void 0:f.entity)==null?void 0:e.unsubscribeDependents)==null||y.call(e,[{entity:this,field:"continue-statement-data-type-entity-field"}]),(T=(v=this.dataType)==null?void 0:v.unsubscribeDependents)==null||T.call(v,[{entity:this,field:"continue-statement-data-type-field"}]),this}subscribeToDependencies(){var i,a,l,f,e,y,v,T;return(i=this.parent)==null||i.subscribeDependents([{entity:this,field:"continue-statement-parent-field"}]),(l=(a=this.implements)==null?void 0:a.subscribeDependents)==null||l.call(a,[{entity:this,field:"continue-statement-implements-field"}]),(y=(e=(f=this.dataType)==null?void 0:f.entity)==null?void 0:e.subscribeDependents)==null||y.call(e,[{entity:this,field:"continue-statement-data-type-entity-field"}]),(T=(v=this.dataType)==null?void 0:v.subscribeDependents)==null||T.call(v,[{entity:this,field:"continue-statement-data-type-field"}]),this}increaseVersion(i){if(i&&!B(i).isValid())throw new Error(`The shared timestamp '${i}' is not a valid ISO 8601 date string.`);return i&&B(i).isSame(B(this.createdAt))?this:(this.previousVersion=this.version,this.version=V.UUID.uuid(),this.createdAt=B(i).toISOString()||B().toISOString(),this)}captureVersion(){var a;const i=((a=this.knownVersions)==null?void 0:a.get(this.version))||new oi(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.outputs=[...this.outputs],i.readsValue=this.readsValue,i.defaultValue=this.defaultValue,i.dataType=this.dataType,i.implements=this.implements,i.throws=this.throws,i.calledBySuccess=[...this.calledBySuccess],i.calledByError=[...this.calledByError],i.calledByEntry=[...this.calledByEntry],i.parent=this.parent,this}recursiveCaptureUpstreamVersions(i){const a=[],l=[],f=[],e=[];if(this.parent){this.parent.increaseVersion(i);const y=this.parent.recursiveCaptureUpstreamVersions(i);a.push(this.parent,...y.updated),l.push(...y.added),f.push(...y.removed)}return{updated:g(a),added:g(l),removed:g(f),affected:g(e),self:this}}async restoreVersion(i){var v;const a=[],l=[],f=[],e=[];if(this.version===i)return{updated:g(a),added:g(l),removed:g(f),affected:g(e),self:this};if(!this.knownVersions){const T=new Map;for(const[A,I]of this.knownVersions||new Map){if(T.set(A,I),I.activeVersion=!1,I.knownVersions)for(const[O,L]of I.knownVersions)T.set(O,L);I.knownVersions=null}}let y=(v=this.knownVersions)==null?void 0:v.get(i);if(!y){const T=await this.APILoadVersion({},i);if(!T)throw new Error(`Version with id '${i}' for entity with id '${this.id}' not found.`);y=new oi(T,this.project)}return this.metaSync(y.toShallowJSON(),null),this.previousVersion=y.previousVersion,this.version=y.version,this.createdAt=y.createdAt,this.author=y.author,this.deleted=y.deleted,this.outputs=y.outputs,this.readsValue=y.readsValue,this.defaultValue=y.defaultValue,this.dataType=y.dataType,this.implements=y.implements,this.throws=y.throws,this.calledBySuccess=y.calledBySuccess,this.calledByError=y.calledByError,this.calledByEntry=y.calledByEntry,this.parent=y.parent,{updated:g(a),added:g(l),removed:g(f),affected:g(e),self:this}}updateWithShallowTransfer(i,a=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,P.UpdateWithShallowTransfer))){if(!this.checkCanEdit(this))return J.warn(`[updateWithShallowTransfer] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),a==null||a.attemptAutoclose(P.UpdateWithShallowTransfer,this.id),this;if(this.metaSync(i,a),this.version=i.version,this.createdAt=i.createdAt,this.author=i.author,this.deleted=i.deleted,this.previousVersion=i.previousVersion,this.unsubscribeFromDependencies(),i.parent){const l=X(i.parent),f=this.project.get(l),e=this.parent;if(e&&e.id!==(f==null?void 0:f.id)&&this.removeFromParent(a),f)this.setParent(f,a);else throw a==null||a.attemptAutoclose(P.UpdateWithShallowTransfer,this.id),new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw a==null||a.attemptAutoclose(P.UpdateWithShallowTransfer,this.id),new Error(`${this.type} with id '${this.id}' must have a 'parent'`);return i.calledByEntry.forEach(l=>{const f=X(l),e=this.project.get(f);e&&(this.addEntryCaller(e,a),e.addCall(this,a))}),[...this.calledByEntry].forEach(l=>{i.calledByEntry.find(e=>X(e)===l.id)||(this.removeCaller(l,a),l.removeCall(this,a))}),i.calledBySuccess.forEach(l=>{const f=X(l),e=this.project.get(f);e&&(this.addSuccessCaller(e,a),e.addSuccessCall(this,a))}),[...this.calledBySuccess].forEach(l=>{i.calledBySuccess.find(e=>X(e)===l.id)||(this.removeCaller(l,a),l.removeCall(this,a))}),i.calledByError.forEach(l=>{const f=X(l),e=this.project.get(f);e&&(this.addErrorCaller(e,a),e.addErrorCall(this,a))}),[...this.calledBySuccess].forEach(l=>{i.calledBySuccess.find(e=>X(e)===l.id)||(this.removeCaller(l,a),l.removeCall(this,a))}),this.captureVersion(),this.subscribeToDependencies(),a==null||a.attemptAutoclose(P.UpdateWithShallowTransfer,this.id),this}hydrateAncestors(){const i=[],a=[],l=[],f=[];if(this.initialData.parent){const e=X(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.implements){const e=X(this.initialData.implements),y=this.project.get(e);if(y)this.setImplements(y,null),i.push(y);else if(e)throw new Error(`${rr(this.type)} with id '${this.id}' has a 'implements' reference "${e}" which is missing in the project`)}if(this.initialData.readsValue){const e=X(this.initialData.readsValue),y=this.project.get(e);y&&(this.setValueWriter(y,null),i.push(y))}return this.initialData.calledByEntry.forEach(e=>{const y=X(e),v=this.project.get(y);v&&this.addEntryCaller(v,null)}),this.initialData.calledBySuccess.forEach(e=>{const y=X(e),v=this.project.get(y);v&&this.addSuccessCaller(v,null)}),this.initialData.calledByError.forEach(e=>{const y=X(e),v=this.project.get(y);v&&this.addErrorCaller(v,null)}),{updated:g(i),added:g(a),removed:g(l),affected:g(f),self:this}}afterAllChildrenInitialized(i=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,P.AfterAllChildrenInitialized))){if(!this.checkCanEdit(this))return J.warn(`[afterAllChildrenInitialized] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(P.AfterAllChildrenInitialized,this.id),{updated:[],added:[],removed:[],affected:[],self:this};const a=[],l=[],f=[],e=[];return this.initialized=!0,!this.dataType||this.dataType.inferred,this.parent.syncTerminationStatements(i),this.captureVersion(),i==null||i.attemptAutoclose(P.AfterAllChildrenInitialized,this.id),{updated:g(a),added:g(l),removed:g(f),affected:g(e),self:this}}addSelfToProject(i=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,"add-self-to-project"))){var y,v;const a=[this],l=[],f=[],e=[];return this.readsValue&&(this.readsValue.addValueReader(this,i),a.push(this.readsValue)),this.calledByEntry.forEach(T=>{T.addCall(this,i),a.push(T)}),this.calledBySuccess.forEach(T=>{T.addSuccessCall(this,i),a.push(T)}),this.calledByError.forEach(T=>{T.addErrorCall(this,i),a.push(T)}),this.parent.addContinueStatement(this),a.push(this),i==null||i.add(this.parent,K.Affected),(y=this.parent)==null||y.breakStatements.forEach(T=>{T.id!==this.id&&(e.push(T),i==null||i.add(T,K.Affected))}),(v=this.parent)==null||v.continueStatements.forEach(T=>{T.id!==this.id&&(e.push(T),i==null||i.add(T,K.Affected))}),this.subscribe(),this.subscribeToDependencies(),i==null||i.attemptAutoclose("add-self-to-project",this.id),{updated:g(a),added:g(l),removed:g(f),affected:g(e),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}addSuccessCaller(i,a=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,P.AddSuccessCaller)),l=!1){return this.checkCanEditWithCounterpartAndSideEffects(this,i,P.AddSuccessCaller,a)?(this.calledBySuccess.find(f=>f.id===i.id)||(this.calledBySuccess.push(i),a==null||a.add(this,K.Updated),l&&Ye(this,a)),a==null||a.attemptAutoclose(P.AddSuccessCaller,this.id),this):this}addErrorCaller(i,a=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,P.AddErrorCaller)),l=!1){return this.checkCanEditWithCounterpartAndSideEffects(this,i,P.AddErrorCaller,a)?(this.calledByError.find(f=>f.id===i.id)||(this.calledByError.push(i),a==null||a.add(this,K.Updated),l&&Ye(this,a)),a==null||a.attemptAutoclose(P.AddErrorCaller,this.id),this):this}addEntryCaller(i,a=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,P.AddEntryCaller)),l=!1){return this.checkCanEditWithCounterpartAndSideEffects(this,i,P.AddEntryCaller,a)?(this.calledByEntry.find(f=>f.id===i.id)||(this.calledByEntry.push(i),a==null||a.add(this,K.Updated),l&&Ye(this,a)),a==null||a.attemptAutoclose(P.AddEntryCaller,this.id),this):this}removeCaller(i,a=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,"remove-caller")),l=!1){return this.checkCanEditWithCounterpartAndSideEffects(this,i,P.RemoveCaller,a)?(this.calledBySuccess=this.calledBySuccess.filter(f=>f.id!==i.id?!0:(a==null||a.add(this,K.Updated),a==null||a.add(f,K.Affected),!1)),this.calledByError=this.calledByError.filter(f=>f.id!==i.id?!0:(a==null||a.add(this,K.Updated),a==null||a.add(f,K.Affected),!1)),this.calledByEntry=this.calledByEntry.filter(f=>f.id!==i.id?!0:(a==null||a.add(this,K.Updated),a==null||a.add(f,K.Affected),!1)),l&&Ye(this,a),a==null||a.attemptAutoclose(P.RemoveCaller,this.id),this):this}setThrows(i,a=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,"set-throws"))){var l;if(!this.checkCanEdit(this))return J.warn(`[setThrows] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),a==null||a.attemptAutoclose("set-throws",this.id),this;if(i!==null&&i.parentRelationType!==Wa.Error)throw new Error("The 'throws' InputMap must have a parentRelationType of 'Error'.");return((l=this.throws)==null?void 0:l.id)!==(i==null?void 0:i.id)&&(this.throws=i,a==null||a.add(this,K.Updated)),a==null||a.attemptAutoclose("set-throws",this.id),this}addOutput(i,a=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,"add-output"))){return this.checkCanEdit(this)?this.outputs.includes(i)?(a==null||a.attemptAutoclose("add-output",this.id),this):(this.outputs.push(i),a==null||a.add(this,K.Affected),a==null||a.attemptAutoclose("add-output",this.id),this):(J.warn(`[addOutput] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),a==null||a.attemptAutoclose("add-output",this.id),this)}removeOutput(i,a=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,"remove-output"))){if(!this.checkCanEdit(this))return J.warn(`[removeOutput] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),a==null||a.attemptAutoclose("remove-output",this.id),this;const l=this.outputs.findIndex(f=>f.id===i.id);return l>-1&&(this.outputs.splice(l,1),a&&(a==null||a.add(this,K.Affected))),a==null||a.attemptAutoclose("remove-output",this.id),this}setParent(i,a=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,P.SetParent))){var l;return this.checkCanEditWithCounterpartAndSideEffects(this,i,P.SetParent,a)?(((l=this.parent)==null?void 0:l.id)!==(i==null?void 0:i.id)&&(this.parent=i,a&&(a==null||a.add(this,K.Updated))),a==null||a.attemptAutoclose(P.SetParent,this.id),this):this}setImplements(i,a=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,P.SetImplements))){var l;return this.checkCanEdit(this)?(((l=this.implements)==null?void 0:l.id)!==(i==null?void 0:i.id)&&(this.implements=i,a&&(a==null||a.add(this,K.Updated))),a==null||a.attemptAutoclose(P.SetImplements,this.id),this):(J.warn(`[setImplements] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),a==null||a.attemptAutoclose(P.SetImplements,this.id),this)}setValueWriter(i,a=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,P.SetValueWriter))){return i&&!this.checkCanEditWithCounterpartAndSideEffects(this,i,P.SetValueWriter,a)?this:!i&&!this.checkCanEdit(this)?(J.warn(`[setValueWriter] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),a==null||a.attemptAutoclose(P.SetValueWriter,this.id),this):(this.readsValue!==i&&(this.readsValue=i,a==null||a.add(this,K.Updated)),a==null||a.attemptAutoclose(P.SetValueWriter,this.id),this)}removeValueWriter(i=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,P.RemoveValueWriter))){return this.readsValue&&!this.checkCanEditWithCounterpartAndSideEffects(this,this.readsValue,P.RemoveValueWriter,i)?this:(this.readsValue&&(this.readsValue=null,i==null||i.add(this,K.Updated)),i==null||i.attemptAutoclose(P.RemoveValueWriter,this.id),this)}initChildren(i=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,"init-children"))){if(this.initialized||this.startedInitialization)return this;if(this.startedInitialization=!0,this.initialData.defaultValue&&(this.defaultValue=se(this.initialData.defaultValue,this.project),this.defaultValue.setParent(this,null),this.defaultValue.initChildren(i)),this.initialData.dataType&&(this.dataType=se(this.initialData.dataType,this.project),this.dataType.setParent(this,null),this.dataType.initChildren(i)),_d.initReadsValue(this),this.initialData.implements){const a=se(this.initialData.implements,this.project);this.setImplements(a,null)}return this.outputs=this.initialData.outputs.map(a=>{const l=se(a,this.project);return l.setParent(this,null),l.initChildren(i),l}),this.initialData.throws&&(this.throws=se(this.initialData.throws,this.project),this.throws.setParent(this,null),this.throws.initChildren(i)),this.subscribeToDependencies(),this.afterAllChildrenInitialized(i),i==null||i.attemptAutoclose("init-children",this.id),this}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(i,a=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,"meta-sync"))){const l=Xi(this,i),f=Yi(this,l),e=this.toMeta();return this.x=l.x||e.x,this.y=l.y||e.y,super.baseMetaSync(l,this),l.deleted===!0&&!e.deleted?a==null||a.add(this,K.Removed):l.deleted===!1&&e.deleted?a==null||a.add(this,K.Added):f&&(a==null||a.add(this,K.Updated)),a==null||a.attemptAutoclose("meta-sync",this.id),this}async APILoad(i=Ie,...a){return await oi.repository.APILoad(this.id,...a),this}async APICreate(i=Ie,...a){return await oi.repository.APICreate(this.toShallowJSON(),...a),this}async APIUpdate(i=Ie,...a){return await oi.repository.APIUpdate(this.toShallowJSON(),...a),this}async APIDelete(i=Ie,...a){return await oi.repository.APIDelete(this.toShallowJSON(),...a),this}async APIClone(i=Ie,...a){return await oi.repository.APIClone(this.id,...a),this}async APILoadVersion(i=Ie,a,...l){return await oi.repository.APILoadVersion(this.id,a,...l)}removeFromParent(i=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,P.RemoveFromParent))){if(!this.checkCanEdit(this))return J.warn(`[removeFromParent] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(P.RemoveFromParent,this.id),{added:[],updated:[],removed:[],affected:[],self:this};const a=[],l=[],f=[],e=[];return this.parent.removeContinueStatement(this),this.parent.detachedChildren.includes(this)&&this.parent.unsubscribeDetachedChild(this),i==null||i.attemptAutoclose(P.RemoveFromParent,this.id),{added:g(f),updated:g(a),removed:g(l),affected:g(e),self:this}}remove({ignoreUpstream:i}={ignoreUpstream:!1},a=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,P.RemoveEntity))){var v,T,A;if(!this.checkCanDelete(this)||!this.checkCanEdit(this))return J.warn(`[remove] User is not allowed to delete or edit this ${this.type} entity with id: ${this.id}`),a==null||a.event({id:`${P.RemoveEntity}-${this.id}`,action:P.RemoveEntity,owner:this,errorReason:Si.ActionOwnerEntityNonDeletable,rootAction:((v=a==null?void 0:a.self)==null?void 0:v.id)===this.id&&(a==null?void 0:a.autoCloseActionName)===P.RemoveEntity}),a==null||a.attemptAutoclose(P.RemoveEntity,this.id),{added:[],updated:[],removed:[],affected:[],self:this};const l=[],f=[],e=[],y=[];if(a!=null&&a.hasRemoved(this.id))return a==null||a.attemptAutoclose(P.RemoveEntity,this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(f.push(this),this.unsubscribe(),this.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},a),Object.values(this.detachedDependents).forEach(I=>{const{updated:O,removed:L,added:M}=I.entity.onDetachedDependencyRemoved(this,I.field,a);l.push(...O),f.push(...L),e.push(...M)}),this.readsValue&&(l.push(this.readsValue),this.readsValue.removeValueReader(this,a)),this.outputs.forEach(I=>{const{updated:O,removed:L}=I.remove({ignoreUpstream:!0},a);l.push(...O),f.push(...L)}),this.throws){const{updated:I,removed:O}=this.throws.remove({ignoreUpstream:!0},a);l.push(...I),f.push(...O)}if(this.dataType){const{updated:I,removed:O}=this.dataType.remove({ignoreUpstream:!0},a);l.push(...I),f.push(...O)}if(!i){const I=this.removeFromParent(a);e.push(...I.added),l.push(...I.updated),f.push(...I.removed),y.push(...I.affected),this.calledBy.forEach(O=>{l.push(O),O.removeCall(this,a)})}return a==null||a.add(this.parent,K.Affected),(T=this.parent)==null||T.breakStatements.forEach(I=>{I.id!==this.id&&(y.push(I),a==null||a.add(I,K.Affected))}),(A=this.parent)==null||A.continueStatements.forEach(I=>{I.id!==this.id&&(y.push(I),a==null||a.add(I,K.Affected))}),a==null||a.attemptAutoclose(P.RemoveEntity,this.id),{added:g(e),updated:g(l),removed:g(f),affected:g(y),self:this}}restore({}={},i=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,P.RestoreEntity))){if(!this.checkCanEdit(this))return J.warn(`[restore] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(P.RestoreEntity,this.id),{added:[],updated:[],removed:[],affected:[],self:this};const a=[],l=[],f=[],e=[];if(i!=null&&i.hasAdded(this.id))return i==null||i.attemptAutoclose(P.RestoreEntity,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:T,added:A}=y.entity.onDetachedDependencyRestored(this,y.field,i);l.push(...v),f.push(...T),a.push(...A)}),this.readsValue&&(l.push(this.readsValue),this.readsValue.addValueReader(this,i)),this.outputs.forEach(y=>{const{updated:v}=y.restore({},i);l.push(...v)}),this.throws){const{updated:y}=this.throws.restore({},i);l.push(...y)}if(this.dataType){const{updated:y}=this.dataType.restore({},i);l.push(...y)}return this.parent.addContinueStatement(this),this.calledBySuccess.forEach(y=>{l.push(y),y.addSuccessCall(this,i)}),this.calledByError.forEach(y=>{l.push(y),y.addErrorCall(this,i)}),this.calledByEntry.forEach(y=>{l.push(y),y.addCall(this,i)}),i==null||i.attemptAutoclose(P.RestoreEntity,this.id),{added:g(a),updated:g(l),removed:g(f),affected:g(e),self:this}}toFlat(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this,...this.outputs.flatMap(l=>l.toFlat(i)),...this.calledBy.flatMap(l=>l.toFlat(i)),...this.throws?this.throws.toFlat(i):[],...this.dataType?this.dataType.toFlat(i):[]])}toFlatIds(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.id,...this.outputs.flatMap(l=>l.toFlatIds(i)),...this.calledBy.flatMap(l=>l.toFlatIds(i)),...this.throws?this.throws.toFlatIds(i):[],...this.dataType?this.dataType.toFlatIds(i):[]])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,x:this.x,y:this.y,type:this.type,editable:this.editable,deletable:this.deletable}}toJSON(i=new Set){var a,l,f,e,y,v;return i.has(this.id)?this.toReference():(i.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,editable:this.editable,deletable:this.deletable,x:this.x,y:this.y,defaultValue:((a=this.defaultValue)==null?void 0:a.toJSON(i))||null,dataType:((l=this.dataType)==null?void 0:l.toJSON(i))||null,readsValue:((f=this.readsValue)==null?void 0:f.toReference())||null,implements:((e=this.implements)==null?void 0:e.toJSON(i))||null,calledBySuccess:this.calledBySuccess.map(T=>T.toReference()),calledByError:this.calledByError.map(T=>T.toReference()),calledByEntry:this.calledByEntry.map(T=>T.toReference()),outputs:this.outputs.map(T=>T.toJSON(i)),throws:((y=this.throws)==null?void 0:y.toJSON(i))||null,parent:((v=this.parent)==null?void 0:v.toReference())||null})}toJSONClone(i=ke){var l,f,e,y,v,T,A,I,O,L;let a;return(l=i.seenEntityMaps)!=null&&l.has(this.id)?a=i.seenEntityMaps.get(this.id):(a=i.newId||or(this,this.project,i.uuidStrategy),i.seenEntityMaps&&i.seenEntityMaps.set(this.id,a)),(f=i.seenEntities)!=null&&f.has(a)||(e=i.seenEntities)!=null&&e.has(this.id)?this.toReference({seenEntityMaps:i.seenEntityMaps}):((y=i.seenEntities)==null||y.add(a),(v=i.seenEntities)==null||v.add(this.id),{id:a,version:V.UUID.uuid(),createdAt:i.timestamp||B().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,editable:this.editable,deletable:this.deletable,x:this.x,y:this.y,defaultValue:((T=this.defaultValue)==null?void 0:T.toJSONClone({...i,newId:null}))||null,dataType:((A=this.dataType)==null?void 0:A.toJSONClone({...i,newId:null}))||null,readsValue:((I=this.readsValue)==null?void 0:I.toReference({seenEntityMaps:i.seenEntityMaps}))||null,implements:(()=>{var M;return this.implements&&this.project.getBuiltIn(this.implements.id)?this.implements.toJSON():((M=this.implements)==null?void 0:M.toJSONClone({...i,newId:null}))||null})(),calledBySuccess:this.calledBySuccess.map(M=>M.toReference({seenEntityMaps:i.seenEntityMaps})),calledByError:this.calledByError.map(M=>M.toReference({seenEntityMaps:i.seenEntityMaps})),calledByEntry:this.calledByEntry.map(M=>M.toReference({seenEntityMaps:i.seenEntityMaps})),outputs:this.outputs.map(M=>M.toJSONClone({...i,newId:null})),throws:((O=this.throws)==null?void 0:O.toJSONClone({...i,newId:null}))||null,parent:((L=this.parent)==null?void 0:L.toReference({seenEntityMaps:i.seenEntityMaps}))||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+"--"+V.UUID.uuid()+"--ref",type:p.GenericReference,entityId:a,version:this.version,entityType:this.type}}toShallowJSON(i=ke){var l,f,e,y,v,T;let a=this.id;return(l=i.seenEntityMaps)!=null&&l.has(this.id)&&(a=i.seenEntityMaps.get(this.id)),{id:a,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,editable:this.editable,deletable:this.deletable,x:this.x,y:this.y,defaultValue:((f=this.defaultValue)==null?void 0:f.toReference(i))||null,dataType:((e=this.dataType)==null?void 0:e.toReference(i))||null,readsValue:((y=this.readsValue)==null?void 0:y.toReference(i))||null,implements:((v=this.implements)==null?void 0:v.toReference(i))||null,outputs:this.outputs.map(A=>A.toReference(i)),calledBySuccess:this.calledBySuccess.map(A=>A.toReference(i)),calledByError:this.calledByError.map(A=>A.toReference(i)),calledByEntry:this.calledByEntry.map(A=>A.toReference(i)),throws:((T=this.throws)==null?void 0:T.toReference(i))||null,parent:this.parent.toReference(i)}}toFlatJSON(i=new Set){var l,f,e,y;return i.has(this.id)?[]:(i.add(this.id),[this.toShallowJSON(),...((l=this.defaultValue)==null?void 0:l.toFlatJSON(i))||[],...((f=this.dataType)==null?void 0:f.toFlatJSON(i))||[],...((e=this.implements)==null?void 0:e.toFlatJSON(i))||[],...this.outputs.flatMap(v=>v.toFlatJSON(i)),...this.calledBy.flatMap(v=>v.toFlatJSON(i)),...((y=this.throws)==null?void 0:y.toFlatJSON(i))||[]])}toGenerationTarget(){var i;return{id:this.id,type:this.type,calledByEntry:this.calledByEntry.map(a=>a.id),calledByError:this.calledByError.map(a=>a.id),calledBySuccess:this.calledBySuccess.map(a=>a.id),implements:(i=this.implements)==null?void 0:i.id,parent:this.parent.id}}toFlatGenerationTarget(i=new Set){var l,f,e;return i.has(this.id)?[]:(i.add(this.id),[this.toGenerationTarget(),...((l=this.defaultValue)==null?void 0:l.toFlatGenerationTarget(i))||[],...((f=this.dataType)==null?void 0:f.toFlatGenerationTarget(i))||[],...((e=this.implements)==null?void 0:e.toFlatGenerationTarget(i))||[],...this.outputs.flatMap(y=>y.toFlatGenerationTarget(i)),...this.throws?this.throws.toFlatGenerationTarget(i):[]])}clearErrors(){var i,a,l;return this.errors=[],(i=this.dataType)==null||i.clearErrors(),(a=this.defaultValue)==null||a.clearErrors(),this.outputs.forEach(f=>f.clearErrors()),(l=this.throws)==null||l.clearErrors(),this}validate(){const i=MZ(this);return this.errors=i,{success:!0}}getErrors(){var a,l;return[...this.errors,...((a=this.defaultValue)==null?void 0:a.getErrors())||[],...((l=this.dataType)==null?void 0:l.getErrors())||[],...this.outputs.flatMap(f=>f.getErrors()),...this.throws?this.throws.getErrors():[]]}getShallowErrors(){return this.errors}getDefaultValue(){return this.defaultValue||null}setDefaultValue(i,a=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,"set-default-value"))){if(!this.checkCanEdit(this))return J.warn(`[setDefaultValue] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),a==null||a.attemptAutoclose("set-default-value",this.id),this;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,K.Affected)),a==null||a.attemptAutoclose("set-default-value",this.id),this}clone(i=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,P.CloneEntity)),a=null,l=null,f=!0){var j,q,Z;let e=lr(a,this);const y=this.toJSON(),v=l||V.UUID.uuid();y.outputs=[];const T=v.split("-id"),A=T[T.length-1||0]||v;y.id=v,y.version=V.UUID.uuid(),y.createdAt=(i==null?void 0:i.timestamp)||B().toISOString(),y.author=(i==null?void 0:i.author)||"1",y.previousVersion=null,y.deleted=!1,y.deletable=!0,y.editable=!0;const I=Ei(y,e);a?I.setParent(a,null):I.setParent(this.parent,null),f&&I.subscribe(),I.initChildren(i),i==null||i.add(I,K.Added);const O=(j=this.dataType)==null?void 0:j.clone(i,I,V.UUID.uuid(),f);I.setDataType(O||null,i);const L=(q=this.defaultValue)==null?void 0:q.clone(i,I,V.UUID.uuid(),f);I.setDefaultValue(L||null,i),this.implements&&I.setImplements(this.implements,i);const M=(Z=this.outputs)==null?void 0:Z.map((S,H)=>S.clone(i,I,A+"-return-declaration-"+H+"-id",f));return I.outputs=M,this.throws&&(I.throws=this.throws.clone(i,I,A+"-throws-id",f)),i==null||i.attemptAutoclose(P.CloneEntity,this.id),I}setDataType(i,a=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,P.SetDataType))){if(!this.checkCanEdit(this))return J.warn(`[setDataType] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),a==null||a.attemptAutoclose(P.SetDataType,this.id),this;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,K.Affected)),a==null||a.attemptAutoclose(P.SetDataType,this.id),this}removeDataType(i=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,P.RemoveDataType))){return this.checkCanEdit(this)?(this.dataType&&(this.dataType.remove({ignoreUpstream:!0},i),i==null||i.add(this,K.Affected),this.dataType=null),i==null||i.attemptAutoclose(P.RemoveDataType,this.id),this):(J.warn(`[removeDataType] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(P.RemoveDataType,this.id),this)}getDataType(i=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,"get-data-type"))){var l;if((!this.dataType||this.dataType.inferred)&&this.project.initialized,this.dataType)return i==null||i.attemptAutoclose("get-data-type",this.id),this.dataType;if(this.parent.dataType)return i==null||i.attemptAutoclose("get-data-type",this.id),this.parent.dataType;const a=(l=this.implements)==null?void 0:l.getDataType(i);return i==null||i.attemptAutoclose("get-data-type",this.id),a||null}};_(oi,"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}),_(oi,"type",p.ContinueStatement),_(oi,"USER_MANAGED_PARENT_TYPES",[p.Loop]),_(oi,"PARENT_TYPES",[...oi.USER_MANAGED_PARENT_TYPES]),_(oi,"MUTABLE_BASE_PROPERTIES",[]),_(oi,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),_(oi,"BASE_PROPERTIES",[...oi.MUTABLE_BASE_PROPERTIES,...oi.INMUTABLE_BASE_PROPERTIES]),_(oi,"MUTABLE_META_PROPERTIES",["x","y"]),_(oi,"INMUTABLE_META_PROPERTIES",[...oi.INMUTABLE_BASE_PROPERTIES]),_(oi,"META_PROPERTIES",[...oi.MUTABLE_META_PROPERTIES,...oi.INMUTABLE_META_PROPERTIES]),_(oi,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry","readsValue"]),_(oi,"INMUTABLE_UPSTREAM_PROPERTIES",["parent"]),_(oi,"UPSTREAM_PROPERTIES",[...oi.MUTABLE_UPSTREAM_PROPERTIES,...oi.INMUTABLE_UPSTREAM_PROPERTIES]),_(oi,"MUTABLE_DOWNSTREAM_PROPERTIES",["outputs","throws"]),_(oi,"INMUTABLE_DOWNSTREAM_PROPERTIES",["dataType","defaultValue"]),_(oi,"DOWNSTREAM_PROPERTIES",[...oi.MUTABLE_DOWNSTREAM_PROPERTIES,...oi.INMUTABLE_DOWNSTREAM_PROPERTIES]),_(oi,"PROPERTIES",[...oi.META_PROPERTIES,...oi.UPSTREAM_PROPERTIES,...oi.DOWNSTREAM_PROPERTIES]);let co=oi;function UZ(d){var i;(i=d.dataType)==null||i.validate();const u=[];return $i(d.errors,u)}const ZOe=Object.freeze(Object.defineProperty({__proto__:null,validate:UZ},Symbol.toStringTag,{value:"Module"}));var jZ=(d=>(d.DataTypeEntity="data-type-entity",d))(jZ||{});const ei=class ei extends nr{constructor(i,a){super(i);_(this,"initialData");_(this,"id");_(this,"name");_(this,"codeName",null);_(this,"description",null);_(this,"index");_(this,"required");_(this,"parentRelationType");_(this,"type",p.ValueDescriptor);_(this,"defaultValue",null);_(this,"dataType",null);_(this,"project");_(this,"errors",[]);_(this,"parent");_(this,"detachedDependents",{});_(this,"knownVersions",null);_(this,"activeVersion",!1);_(this,"initialized",!1);_(this,"startedInitialization",!1);_(this,"codeNativeValueValidation",null);this.initialData=i,this.project=a,this.id=i.id,this.name=i.name,this.description=i.description,this.index=i.index,this.codeName=i.codeName,this.required=i.required,this.parentRelationType=i.parentRelationType}static new(i=null){return{id:V.UUID.uuid(),version:V.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||B().toISOString(),author:(i==null?void 0:i.author)||V.sessionAuthor,previousVersion:null,deleted:!1,deletable:!0,editable:!0,type:p.ValueDescriptor,name:"",codeName:null,description:"",dataType:null,index:0,required:!1,parentRelationType:ye.FixedArguments,defaultValue:null,parent:null}}static fromGenerationTarget(i,a){const l=i.parent?X(i.parent):null,f=l?a.get(l):null,e=i.parentRelationType===ye.FixedArguments?f==null?void 0:f.inputs.length:null,y={id:i.id,version:V.UUID.uuid(),createdAt:B().toISOString(),author:V.sessionAuthor,previousVersion:null,deleted:!1,name:i.name,deletable:!0,editable:!0,type:p.ValueDescriptor,index:e||0,codeName:i.codeName,description:i.description,required:i.required,defaultValue:null,parentRelationType:i.parentRelationType,dataType:null,parent:f},v=se(y,a);return f&&v.setParent(f,null),v}static validateGenerationTarget(i,a){let l=JSON.parse(JSON.stringify(i));const f=[],e=Pr(l,{parent:{list:!1,types:[p.ActionDescriptor]}},a);l=e.modifiedData,f.push(...e.errors,...zi(l));const y=l.parent&&a.get(l.parent),v=y&&Ao(y);return v&&v.type===p.ActionDescriptor&&f.push(new oe({id:`${i.id}--${W.BuiltInEntityParent}`,code:W.BuiltInEntityParent,severity:Y.Error,message:`Entity of type "${i.type}" with id "${i.id}", has a parent that is a built-in entity "${v.name}" of type '${v.type}' with id '${v.id}'.
|
|
186
186
|
You can't modify system entities that are built-in.`})),y&&y.type===p.ActionDescriptor&&(!l.parentRelationType||!(l.parentRelationType===ye.FixedArguments||l.parentRelationType===ye.ReturnedError||l.parentRelationType===ye.DynamicArgument)?f.push(new oe({id:`${i.id}--${W.InvalidParentRelationType}`,code:W.InvalidParentRelationType,severity:Y.Error,message:`The entity with id '${i.id}' and type '${i.type}', must have a 'parentRelationType' property set to either '${ye.FixedArguments}' or '${ye.ReturnedError}' when being added as a child to an entity of type 'action-descriptor'.`})):l.parentRelationType===ye.ReturnedError&&y.error&&f.push(new oe({id:`${i.id}--${W.NewEntityWouldOverriteExisting}`,code:W.NewEntityWouldOverriteExisting,severity:Y.Error,message:`The entity with id '${i.id}' and type '${i.type}', is being added as an error value-descriptor to an entity of type 'action-descriptor' with id '${y.id}', which already has an error value descriptor with id '${y.error.id}'.
|
|
187
187
|
An action descriptor can only have one error value descriptor child.
|
|
188
188
|
Either remove the existing error value descriptor or update it with the 'update' action.
|
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.6548",
|
|
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",
|