@elyx-code/project-logic-tree 0.0.6258 → 0.0.6259

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 CHANGED
@@ -44195,10 +44195,10 @@ You shouldn't have to manually update a 'parent' property. The equivalent result
44195
44195
  (h) => {
44196
44196
  const c = o.find(
44197
44197
  (T) => {
44198
- const E = F(T, this.project), R = ae.fromReturnDeclarationToLoopOutputDeclarationName(
44198
+ const E = F(h, this.project), R = ae.fromReturnDeclarationToLoopOutputDeclarationName(
44199
44199
  T
44200
44200
  );
44201
- return console.log("resolvedName", E), console.log("nameToMatch", R), F(h, this.project) === ae.fromReturnDeclarationToLoopOutputDeclarationName(T);
44201
+ return console.log("resolvedName", E), console.log("nameToMatch", R), console.log("Skip delete?", E === R), F(h, this.project) === ae.fromReturnDeclarationToLoopOutputDeclarationName(T);
44202
44202
  }
44203
44203
  );
44204
44204
  return console.log("foundMatchingReturn", c), !c;
@@ -96,7 +96,7 @@ ${Wl(t)}`,issue:null})):s.push(new w({id:`${e.id}--${R.ReferencedEntityNotFound}
96
96
  ${Wl(t)}`,issue:null})):s.push(new w({id:`${e.id}--${$.InvalidObjectStructure}`,code:$.InvalidObjectStructure,severity:O.Error,message:`Entity of type '${e.type}' with id '${e.id}' is missing the 'declaration' property. This property is required for a '${e.type}' entity and must point to one of the built-in action descriptors reserved for '${n.Condition}' entities.
97
97
  ${Wl(t)}`,issue:null})),{errors:s,modifiedData:i}}static fromReturnDeclarationToBodyArgumentDeclarationName(e){return`Previous iteration results of '${x(e,e.project)}'`}static fromBodyArgumentDeclarationToReturnDeclarationName(e){const t=e.name.replace("Previous iteration results of '","");return t.slice(0,t.length-1)}static fromReturnDeclarationToLoopOutputDeclarationName(e){return`Result list of '${x(e,e.project)}'`}static fromLoopOutputDeclarationToReturnDeclarationName(e){const t=e.name.replace("Result list of '","");return t.slice(0,t.length-1)}static fromLoopOutputDeclarationToBodyArgumentDeclarationName(e){return e.name.replace("Result list of '","Previous iteration results of '")}static fromBodyArgumentDeclarationToLoopOutputDeclarationName(e){return e.name.replace("Previous iteration results of '","Result list of '")}get continueStatements(){const e=[];return Object.values(this.detachedDependents).forEach(t=>{t.field===_c.Parent&&t.entity.type===n.ContinueStatement&&!e.includes(t.entity)&&e.push(t.entity)}),e}get breakStatements(){const e=[];return Object.values(this.detachedDependents).forEach(t=>{t.field===Nc.Parent&&t.entity.type===n.BreakStatement&&!e.includes(t.entity)&&e.push(t.entity)}),e}validateGeneratedUpdate(e){const t=[];return e.parent&&t.push(new w({id:`${this.id}--${R.InvalidParentUpdate}`,code:R.InvalidParentUpdate,severity:O.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.
98
98
  If an entity is called by another, they must be in the same scope, which means they have the same parent.
99
- You shouldn't have to manually update a 'parent' property. The equivalent result is to change its callers, the value writters of its inputs, or the value readers of its outputs.`,issue:null})),{errors:t,modifiedData:e}}subscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]||(this.detachedDependents[t.entity.id]=t)}),this}unsubscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]&&delete this.detachedDependents[t.entity.id]}),this}syncDependents(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-dependents"))){const t=[],i=[],s=[],l=[];return Object.values(this.detachedDependents).forEach(o=>{const d=o.entity.afterAllChildrenInitialized(e);t.push(...d.updated),i.push(...d.added),s.push(...d.removed),l.push(...d.affected)}),e==null||e.attemptAutoclose("sync-dependents",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];if(t==="parent"){const{updated:u,added:h,removed:c}=this.remove({ignoreUpstream:!1},i);s.push(...u),l.push(...h),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}onDetachedDependencyRestored(e,t,i){const s=[],l=[],o=[],d=[];if(t==="parent"){const{updated:u,added:h,removed:c}=this.restore({},i);s.push(...u),l.push(...h),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}unsubscribeFromDependencies(){var e;return(e=this.parent)==null||e.unsubscribeDependents([{entity:this,field:"parent"}]),this}subscribeToDependencies(){var e;return(e=this.parent)==null||e.subscribeDependents([{entity:this,field:"parent"}]),this}increaseVersion(e){if(e&&!T(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&T(e).isSame(T(this.createdAt))?this:(this.previousVersion=this.version,this.version=m.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new oe(this,this.project);return e.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,e):new Map([[this.version,e]]),e.inputs=this.inputs,e.outputs=this.outputs,e.error=this.error,e.successCalls=this.successCalls,e.errorCalls=this.errorCalls,e.declaration=this.declaration,e.outputsDeclarations=this.outputsDeclarations,e.body=this.body,e.calledByEntry=this.calledByEntry,e.calledBySuccess=this.calledBySuccess,e.calledByError=this.calledByError,e.process=this.process,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],i=[],s=[],l=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),i.push(...o.added),s.push(...o.removed)}return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}async restoreVersion(e){var d;const t=[],i=[],s=[],l=[];if(this.version===e)return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this};if(!this.knownVersions){const u=new Map;for(const[h,c]of this.knownVersions||new Map){if(u.set(h,c),c.activeVersion=!1,c.knownVersions)for(const[E,I]of c.knownVersions)u.set(E,I);c.knownVersions=null}}let o=(d=this.knownVersions)==null?void 0:d.get(e);if(!o){const u=await this.APILoadVersion({},e);if(!u)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new oe(u,this.project)}return this.metaSync(o.toShallowJSON(),null),this.inputs=o.inputs,this.outputs=o.outputs,this.error=o.error,this.successCalls=o.successCalls,this.errorCalls=o.errorCalls,this.declaration=o.declaration,this.outputsDeclarations=o.outputsDeclarations,this.body=o.body,this.calledByEntry=o.calledByEntry,this.calledBySuccess=o.calledBySuccess,this.calledByError=o.calledByError,this.process=o.process,this.parent=o.parent,{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}hydrateAncestors(){const e=[],t=[],i=[],s=[];if(this.initialData.parent){const l=_(this.initialData.parent),o=this.project.get(l);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' 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 l=_(this.initialData.declaration),o=this.project.get(l);o&&(this.setDeclaration(o),e.push(o))}return this.initialData.calledByEntry.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addEntryCaller(d,null),d.addCall(this,null),e.push(d))}),this.initialData.calledBySuccess.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addSuccessCaller(d,null),d.addSuccessCall(this,null),e.push(d))}),this.initialData.calledByError.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addErrorCaller(d,null),d.addErrorCall(this,null),e.push(d))}),{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],i=[],s=[],l=[];this.initialized=!0;const{updated:o,added:d,removed:u}=this.syncChildren(e);return t.push(...o),i.push(...d),s.push(...u),this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addSelfToProject(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-self-to-project"))){const t=[this],i=[],s=[],l=[];return this.parent===this.project&&this.project.addLoop(this),this.successCalls.forEach(o=>{o.addSuccessCaller(this,e),t.push(o)}),this.errorCalls.forEach(o=>{o.addErrorCaller(this,e),t.push(o)}),this.calledByEntry.forEach(o=>{o.addCall(this,e),t.push(o)}),this.calledBySuccess.forEach(o=>{o.addSuccessCall(this,e),t.push(o)}),this.calledByError.forEach(o=>{o.addErrorCall(this,e),t.push(o)}),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}removeInput(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-input"))){const i=this.inputs.findIndex(s=>s.id===e.id);return i>-1&&(this.inputs.splice(i,1),t&&(t==null||t.add(this,A.Affected))),t==null||t.attemptAutoclose("remove-input",this.id),this}addInput(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-input"))){return this.inputs.includes(e)?(t==null||t.attemptAutoclose("add-input",this.id),this):(this.inputs.push(e),t==null||t.add(this,A.Affected),t==null||t.attemptAutoclose("add-input",this.id),this)}addOutputDeclaration(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-output-declaration"))){return this.outputsDeclarations.includes(e)?(t==null||t.attemptAutoclose("add-output-declaration",this.id),this):(this.outputsDeclarations.push(e),t==null||t.add(this,A.Affected),t==null||t.attemptAutoclose("add-output-declaration",this.id),this)}removeOutputDeclaration(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-output-declaration"))){const i=this.outputsDeclarations.findIndex(s=>s.id===e.id);return i>-1&&(this.outputsDeclarations.splice(i,1),t==null||t.add(this,A.Affected)),t==null||t.attemptAutoclose("remove-output-declaration",this.id),this}addOutput(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-output"))){return this.outputs.includes(e)?(t==null||t.attemptAutoclose("add-output",this.id),this):(this.outputs.push(e),t==null||t.add(this,A.Affected),t==null||t.attemptAutoclose("add-output",this.id),this)}removeOutput(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-output"))){const i=this.outputs.findIndex(s=>s.id===e.id);return i>-1&&(this.outputs.splice(i,1),t&&(t==null||t.add(this,A.Affected))),t==null||t.attemptAutoclose("remove-output",this.id),this}setBody(e){return this.body=e,this}addSuccessCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-success-caller")),i=!1){return this.calledBySuccess.find(s=>s.id===e.id)||(this.calledBySuccess.push(e),t==null||t.add(this,A.Updated),i&&K(this,t)),t==null||t.attemptAutoclose("add-success-caller",this.id),this}addErrorCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-error-caller")),i=!1){return this.calledByError.find(s=>s.id===e.id)||(this.calledByError.push(e),t==null||t.add(this,A.Updated),i&&K(this,t)),t==null||t.attemptAutoclose("add-error-caller",this.id),this}addEntryCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-entry-caller")),i=!1){return this.calledByEntry.find(s=>s.id===e.id)||(this.calledByEntry.push(e),t==null||t.add(this,A.Updated),i&&K(this,t)),t==null||t.attemptAutoclose("add-entry-caller",this.id),this}addErrorCall(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-error-call")),i=!1){return this.errorCalls.find(s=>s.id===e.id)||(this.errorCalls.push(e),i&&K(this,t),t==null||t.add(this,A.Affected)),t==null||t.attemptAutoclose("add-error-call",this.id),this}addSuccessCall(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-success-call")),i=!1){return this.successCalls.find(s=>s.id===e.id)||(this.successCalls.push(e),i&&K(this,t),t==null||t.add(this,A.Affected)),t==null||t.attemptAutoclose("add-success-call",this.id),this}removeCall(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-call")),i=!1){const s=this.successCalls.findIndex(o=>o.id===e.id);s>-1&&(this.successCalls.splice(s,1),t==null||t.add(this,A.Affected));const l=this.errorCalls.findIndex(o=>o.id===e.id);return l>-1&&(this.errorCalls.splice(l,1),t==null||t.add(this,A.Affected)),i&&K(this,t),t==null||t.attemptAutoclose("remove-call",this.id),this}removeCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-caller")),i=!1){return this.calledBySuccess=this.calledBySuccess.filter(s=>s.id!==e.id?!0:(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected),!1)),this.calledByError=this.calledByError.filter(s=>s.id!==e.id?!0:(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected),!1)),this.calledByEntry=this.calledByEntry.filter(s=>s.id!==e.id?!0:(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected),!1)),i&&K(this,t),t==null||t.attemptAutoclose("remove-caller",this.id),this}replaceDetachedChild(e,t){const i=this.detachedChildren.indexOf(e);return i!==-1&&(this.detachedChildren[i]=t),this}subscribeDetachedChild(e){return this.detachedChildren.includes(e)||this.detachedChildren.push(e),this}setParent(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"set-parent"))){var i;return((i=this.parent)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,A.Updated),t==null||t.attemptAutoclose("set-parent",this.id))),this}setDeclaration(e){return this.declaration=e,this}initChildren(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.declaration=C(this.initialData.declaration,this.project),this.successCalls=this.initialData.successCalls.map(t=>{const i=C(t,this.project);if(i.addSuccessCaller(this),[n.BreakStatement,n.ContinueStatement].includes(i.type))i.setParent(this.parent.parent,null),i.initChildren(e);else if(i.type===n.ReturnStatement){const s=It(this,this.project);i.setParent(s,null),i.initChildren(e)}else i.type!==n.InternalCall&&(i.setParent(this.parent,null),i.initChildren(e));return i}),this.errorCalls=this.initialData.errorCalls.map(t=>{const i=C(t,this.project);if(i.addErrorCaller(this),[n.BreakStatement,n.ContinueStatement].includes(i.type))i.setParent(this.parent.parent,null),i.initChildren(e);else if(i.type===n.ReturnStatement){const s=It(this,this.project);i.setParent(s,null),i.initChildren(e)}else i.type!==n.InternalCall&&(i.setParent(this.parent,null),i.initChildren(e));return i}),this.inputs=this.initialData.inputs.map(t=>{const i=C(t,this.project);return i.setParent(this,null),i.initChildren(e),i}),this.outputs=this.initialData.outputs.map(t=>{const i=C(t,this.project);return i.setParent(this,null),i.initChildren(e),i}),this.initialData.process&&(this.process=C(this.initialData.process,this.project),this.process.setParent(this,null),this.process.initChildren(e)),this.initialData.body&&(this.body=C(this.initialData.body,this.project),this.body.setParent(this,null),this.body.initChildren(e)),this.initialData.error&&(this.error=C(this.initialData.error,this.project),this.error.setParent(this,null),this.error.initChildren(e)),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this)}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"meta-sync"))){const i=pt(this,e),s=this.toMeta();return this.x=e.x||s.x,this.y=e.y||s.y,super.metaSync(e),e.deleted===!0&&!s.deleted?t==null||t.add(this,A.Removed):e.deleted===!1&&s.deleted?t==null||t.add(this,A.Added):i&&(t==null||t.add(this,A.Updated)),t==null||t.attemptAutoclose("meta-sync",this.id),this}async APILoad(e=U,...t){return await oe.repository.APILoad(this.id,...t),this}async APICreate(e=U,...t){return await oe.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=U,...t){return await oe.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=U,...t){return await oe.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=U,...t){return await oe.repository.APIClone(this.id,...t),this}async APILoadVersion(e=U,t,...i){return await oe.repository.APILoadVersion(this.id,t,...i)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-entity"))){const i=[],s=[],l=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(s.push(this),this.unsubscribe(),this.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(d=>{const{updated:u,removed:h,added:c}=d.entity.onDetachedDependencyRemoved(this,d.field,t);i.push(...u),s.push(...h),l.push(...c)}),this.inputs.forEach(d=>{const{updated:u,removed:h}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...h)}),this.outputs.forEach(d=>{const{updated:u,removed:h}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...h)}),this.body.remove({ignoreUpstream:!0},t),this.error){const{updated:d,removed:u}=this.error.remove({ignoreUpstream:!0},t);i.push(...d),s.push(...u)}return this.successCalls.forEach(d=>{i.push(d),d.removeCaller(this,t)}),this.errorCalls.forEach(d=>{i.push(d),d.removeCaller(this,t)}),e||this.calledBy.forEach(d=>{i.push(d),d.removeCall(this,t)}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:p(l),updated:p(i),removed:p(s),affected:p(o),self:this}}restore({}={},e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"restore-entity"))){const t=[],i=[],s=[],l=[];return e!=null&&e.hasAdded(this.id)?(e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),this.inputs.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.outputs.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.body.restore({},e),this.successCalls.forEach(o=>{i.push(o),o.addSuccessCaller(this,e)}),this.errorCalls.forEach(o=>{i.push(o),o.addErrorCaller(this,e)}),this.calledBySuccess.forEach(o=>{i.push(o),o.addSuccessCall(this,e)}),this.calledByError.forEach(o=>{i.push(o),o.addErrorCall(this,e)}),this.calledByEntry.forEach(o=>{i.push(o),o.addCall(this,e)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(l),self:this})}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.inputs.flatMap(i=>i.toFlat(e)),...this.outputs.flatMap(i=>i.toFlat(e)),...this.outputsDeclarations.flatMap(i=>i.toFlat(e)),...this.process?this.process.toFlat(e):[],...this.successCalls.flatMap(i=>i.toFlat(e)),...this.errorCalls.flatMap(i=>i.toFlat(e)),...this.error?this.error.toFlat(e):[],...this.body?this.body.toFlat(e):[],...this.continueStatements.flatMap(i=>i.toFlat(e)),...this.breakStatements.flatMap(i=>i.toFlat(e))])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.inputs.flatMap(i=>i.toFlatIds(e)),...this.outputs.flatMap(i=>i.toFlatIds(e)),...this.process?this.process.toFlatIds(e):[],...this.successCalls.flatMap(i=>i.toFlatIds(e)),...this.errorCalls.flatMap(i=>i.toFlatIds(e)),...this.error?this.error.toFlatIds(e):[],...this.body?this.body.toFlatIds(e):[],...this.continueStatements.flatMap(i=>i.toFlatIds(e)),...this.breakStatements.flatMap(i=>i.toFlatIds(e))])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,x:this.x,y:this.y,type:this.type}}toJSON(e=new Set){var t,i;return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,calledBySuccess:this.calledBySuccess.map(s=>s.toReference()),calledByError:this.calledByError.map(s=>s.toReference()),calledByEntry:this.calledByEntry.map(s=>s.toReference()),process:((t=this.process)==null?void 0:t.toJSON(e))||null,declaration:this.declaration.toJSON(e),inputs:this.inputs.map(s=>s.toJSON(e)),outputs:this.outputs.map(s=>s.toJSON(e)),outputsDeclarations:this.outputsDeclarations.map(s=>s.toJSON(e)),successCalls:this.successCalls.map(s=>s.toJSON(e)),errorCalls:this.errorCalls.map(s=>s.toJSON(e)),error:((i=this.error)==null?void 0:i.toJSON(e))||null,body:this.body.toJSON(e),parent:this.parent.toReference()})}toJSONClone(e=J){var i,s,l,o,d,u,h;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||yt(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(s=e.seenEntities)!=null&&s.has(t)||(l=e.seenEntities)!=null&&l.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(d=e.seenEntities)==null||d.add(this.id),{id:t,version:m.UUID.uuid(),createdAt:e.timestamp||T().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,calledBySuccess:this.calledBySuccess.map(c=>c.toReference({seenEntityMaps:e.seenEntityMaps})),calledByError:this.calledByError.map(c=>c.toReference({seenEntityMaps:e.seenEntityMaps})),calledByEntry:this.calledByEntry.map(c=>c.toReference({seenEntityMaps:e.seenEntityMaps})),process:((u=this.process)==null?void 0:u.toJSONClone({...e,newId:null}))||null,declaration:this.declaration.toJSON(),inputs:this.inputs.map(c=>c.toJSONClone({...e,newId:null})),outputs:this.outputs.map(c=>c.toJSONClone({...e,newId:null})),outputsDeclarations:this.outputsDeclarations.map(c=>c.toJSONClone({...e,newId:null})),successCalls:this.successCalls.map(c=>c.toJSONClone({...e,newId:null})),errorCalls:this.errorCalls.map(c=>c.toJSONClone({...e,newId:null})),error:((h=this.error)==null?void 0:h.toJSONClone({...e,newId:null}))||null,body:this.body.toJSONClone({...e,newId:null}),parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps})})}toReference(e=J){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+m.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=J){var i,s,l,o,d;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,declaration:((s=this.declaration)==null?void 0:s.toReference(e))||null,body:((l=this.body)==null?void 0:l.toReference(e))||null,inputs:this.inputs.map(u=>u.toReference(e)),outputs:this.outputs.map(u=>u.toReference(e)),outputsDeclarations:this.outputsDeclarations.map(u=>u.toReference(e)),successCalls:this.successCalls.map(u=>u.toReference(e)),errorCalls:this.errorCalls.map(u=>u.toReference(e)),process:((o=this.process)==null?void 0:o.toReference(e))||null,calledBySuccess:this.calledBySuccess.map(u=>u.toReference(e)),calledByError:this.calledByError.map(u=>u.toReference(e)),calledByEntry:this.calledByEntry.map(u=>u.toReference(e)),error:((d=this.error)==null?void 0:d.toReference(e))||null,parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){var i;return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...((i=this.body)==null?void 0:i.toFlatJSON(e))||[],...this.successCalls.flatMap(s=>s.toFlatJSON(e)),...this.errorCalls.flatMap(s=>s.toFlatJSON(e)),...this.inputs.flatMap(s=>s.toFlatJSON(e)),...this.outputs.flatMap(s=>s.toFlatJSON(e)),...this.continueStatements.flatMap(s=>s.toFlatJSON(e)),...this.breakStatements.flatMap(s=>s.toFlatJSON(e)),...this.error?this.error.toFlatJSON(e):[],...this.process?this.process.toFlatJSON(e):[]])}toGenerationTarget(){const e=this.parent.type===n.Project?void 0:this.parent.id;return{id:this.id,type:this.type,calledByEntry:this.calledByEntry.map(t=>t.id),calledBySuccess:this.calledBySuccess.map(t=>t.id),calledByError:this.calledByError.map(t=>t.id),declaration:this.declaration.id,parent:e}}toFlatGenerationTarget(e=new Set){var i;return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...((i=this.body)==null?void 0:i.toFlatGenerationTarget(e))||[],...this.successCalls.flatMap(s=>s.toFlatGenerationTarget(e)),...this.errorCalls.flatMap(s=>s.toFlatGenerationTarget(e)),...this.inputs.flatMap(s=>s.toFlatGenerationTarget(e)),...this.outputs.flatMap(s=>s.toFlatGenerationTarget(e)),...this.continueStatements.flatMap(s=>s.toFlatGenerationTarget(e)),...this.breakStatements.flatMap(s=>s.toFlatGenerationTarget(e)),...this.error?this.error.toFlatGenerationTarget(e):[],...this.process?this.process.toFlatGenerationTarget(e):[]])}clearErrors(){var e,t;return this.errors=[],this.inputs.forEach(i=>i.clearErrors()),this.outputs.forEach(i=>i.clearErrors()),this.successCalls.forEach(i=>i.clearErrors()),this.errorCalls.forEach(i=>i.clearErrors()),this.continueStatements.forEach(i=>i.clearErrors()),this.breakStatements.forEach(i=>i.clearErrors()),(e=this.process)==null||e.clearErrors(),(t=this.error)==null||t.clearErrors(),this}validate(){const e=Lc(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){return[...this.errors,...this.inputs.flatMap(t=>t.getErrors()),...this.outputs.flatMap(t=>t.getErrors()),...this.body?this.body.getErrors():[],...this.error?this.error.getErrors():[],...this.process?this.process.getErrors():[]]}getShallowErrors(){return this.errors}clone(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"clone-entity")),t=null,i=null,s=!0){var D,P;let l=mt(t,this);const o=this.toJSON(),d=i||m.UUID.uuid();o.inputs=[];const u=d.split("-id"),h=u[u.length-1||0]||d;o.id=d,o.version=m.UUID.uuid(),o.createdAt=(e==null?void 0:e.timestamp)||T().toISOString(),o.author=(e==null?void 0:e.author)||"1",o.previousVersion=null,o.deleted=!1;const c=st(o,l);t?c.setParent(t,null):c.setParent(this.parent,null),s&&c.subscribe(),c.initChildren(e),e==null||e.add(c,A.Added);const E=(D=this.inputs)==null?void 0:D.map((V,M)=>V.clone(e,c,h+"-input-map-"+M+"-id",s));c.inputs=E;const I=(P=this.outputs)==null?void 0:P.map((V,M)=>V.clone(e,c,h+"-output-map-"+M+"-id",s));return c.outputs=I,this.body&&(c.body=this.body.clone(e,c,h+"-body-id",s,!0)),this.error&&(c.error=this.error.clone(e,c,h+"-error-map-id",s)),this.process&&(c.process=this.process.clone(e,c,h+"-process-id",s)),e==null||e.attemptAutoclose("clone-entity",this.id),c}getVariableInstances(){return this.body?He(this.body).filter(i=>i.type===n.VariableInstance):[]}addReturnStatement(e){return rt.includes(this.parent.type)&&this.parent.addReturnStatement(e),this}removeReturnStatement(e){return rt.includes(this.parent.type)&&this.parent.removeReturnStatement(e),this}addBreakStatement(e){return this.breakStatements.includes(e)||this.breakStatements.push(e),this}removeBreakStatement(e){const t=this.breakStatements.indexOf(e);return t!==-1&&this.breakStatements.splice(t,1),this}addContinueStatement(e){return this.continueStatements.includes(e)||this.continueStatements.push(e),this}removeContinueStatement(e){const t=this.continueStatements.indexOf(e);return t!==-1&&this.continueStatements.splice(t,1),this}getUniqueReturnDeclarations(){const e=[];return[...this.breakStatements,...this.continueStatements].forEach(i=>{i.outputs.forEach(l=>{e.find(d=>d===l||x(d,this.project)===x(l,this.project)&&wi(d.dataType,l.dataType))||e.push(l)})}),p(e)}syncTerminationStatements(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-termination-statements"))){const t=[],i=[],s=[],l=[],o=this.getUniqueReturnDeclarations();return[...this.breakStatements,...this.continueStatements].forEach(u=>{const h=u.outputs,c=o.filter(E=>!h.find(I=>x(E,this.project)===x(I,this.project)&&wi(E.dataType,I.dataType)));c.length&&(t.push(u),e==null||e.add(u,A.Updated)),c.forEach(E=>{const I=E.clone(e,u);e==null||e.add(I,A.Added),I.addSelfToProject(e),i.push(I)})}),e==null||e.attemptAutoclose("sync-termination-statements",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}syncBodyInputIndexes(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-body-input-indexes"))){const t=[],i=[],s=[],l=[];return this.body.inputs.sort((d,u)=>d.index-u.index),this.body.inputs.forEach((d,u)=>{d.index!==u&&(d.metaSync({index:u},e),t.push(d))}),e==null||e.attemptAutoclose("sync-body-input-indexes",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}syncBodyArgumentsDeclarations(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-body-arguments-declarations"))){const t=[],i=[],s=[],l=[],{updated:o,added:d,removed:u}=this.syncFixedBodyArgumentDeclarations(e);t.push(...o),i.push(...d),s.push(...u);const h=this.getUniqueReturnDeclarations(),c=this.body.inputs;h.sort((P,V)=>P.index-V.index),h.forEach(P=>{const V=P.getDataType(e);let g=c.find(pe=>x(pe,this.project)===oe.fromReturnDeclarationToBodyArgumentDeclarationName(P)&&wi(pe.dataType,P.dataType));if(!g){const pe=oe.fromReturnDeclarationToBodyArgumentDeclarationName(P),Ee={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.ArgumentDeclaration,name:pe,description:`Aggretated list of all previously outputted values from each iteration by the output '${x(P,this.project)}'`,defaultValue:null,constant:!0,dataType:null,implements:null,index:P.index,required:P.required,parent:this.body.toReference(),writesValues:[]},Q=C(Ee,this.project);Q.setParent(this.body,e),Q.initChildren(e),e==null||e.add(Q,A.Added),Q.addSelfToProject(e),i.push(Q),g=Q}const B=this.body.inputs.find(pe=>pe.index===g.index&&pe!==g),G=this.body.inputs.filter(pe=>pe!==g);let q=g.index;B&&(q=Math.max(...G.map(pe=>pe.index))+1),g.index!==q&&(g.metaSync({index:q},e),t.push(g));const S=g.getDataType(e);let X=S;if(V)if(!S||!wi(S,V)){if(!X){const Ee=V.clone(e,g);e==null||e.add(Ee,A.Added),Ee.addSelfToProject(e),X=Ee,i.push(Ee),t.push(g)}const pe=X.merge(V,e);pe.self===X?V.remove({ignoreUpstream:!1},e):pe.self===V&&(X.remove({ignoreUpstream:!1},e),X=V),X.metaSync({isList:!0},e)}else X.isList||(X.metaSync({isList:!0},e),t.push(X));if(!V&&!X){const pe={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.DataType,options:[],implementationChooseOne:!1,parentRelationType:null,staticEntities:null,interactiveEntities:null,actionEntities:null,isList:!0,entity:null,asType:!1,like:!1,inferred:!1,andChildrenGroup:[],orChildrenGroup:[],parent:g.toReference()},Ee=C(pe,this.project);Ee.metaSync({isList:!0},e),Ee.setParent(g,e),Ee.initChildren(e),e==null||e.add(Ee,A.Added),Ee.addSelfToProject(e),i.push(Ee)}});const{updated:E,added:I,removed:D}=this.removeExtraBodyArgumentDeclarations(e);return t.push(...E),i.push(...I),s.push(...D),e==null||e.attemptAutoclose("sync-body-arguments-declarations",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}syncOutputsDeclarations(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-outputs-declarations"))){const t=[],i=[],s=[],l=[],o=this.getUniqueReturnDeclarations(),d=this.outputsDeclarations;o.forEach((h,c)=>{h.index!==c&&(h.metaSync({index:c},e),t.push(h))}),o.forEach(h=>{const c=h.getDataType(e);let I=d.find(V=>x(V,this.project)===oe.fromReturnDeclarationToLoopOutputDeclarationName(h)&&wi(V.dataType,h.dataType));if(!I){const V=oe.fromReturnDeclarationToLoopOutputDeclarationName(h),M={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.ValueDescriptor,name:V,description:`Aggretated list of all previously outputted values from each iteration by the output '${x(h,this.project)}'`,defaultValue:null,dataType:null,index:h.index,required:h.required,parentRelationType:L.FixedReturns,parent:this.toReference()},g=C(M,this.project);g.setParent(this,e),g.initChildren(e),e==null||e.add(g,A.Added),g.addSelfToProject(e),i.push(g),I=g}I.index!==h.index&&(I.metaSync({index:h.index},e),t.push(I));let P=I.getDataType(e);if(c)if(!P||!wi(P,c)){if(!P){const M=c.clone(e,I);e==null||e.add(M,A.Added),M.addSelfToProject(e),P=M,i.push(M),t.push(I)}const V=P.merge(c,e);V.self===P?c.remove({ignoreUpstream:!1},e):V.self===c&&(P.remove({ignoreUpstream:!1},e),P=c),P.metaSync({isList:!0},e)}else P.isList||(P.metaSync({isList:!0},e),t.push(P));if(!c&&!P){const V={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.DataType,options:[],implementationChooseOne:!1,staticEntities:null,interactiveEntities:null,actionEntities:null,parentRelationType:null,isList:!0,entity:null,asType:!1,like:!1,inferred:!1,andChildrenGroup:[],orChildrenGroup:[],parent:I.toReference()},M=C(V,this.project);M.metaSync({isList:!0},e),M.setParent(I,e),M.initChildren(e),e==null||e.add(M,A.Added),M.addSelfToProject(e),i.push(M)}}),console.log("uniqueReturnDeclarations: ",o);const u=d.filter(h=>{const c=o.find(E=>{const I=x(E,this.project),D=oe.fromReturnDeclarationToLoopOutputDeclarationName(E);return console.log("resolvedName",I),console.log("nameToMatch",D),x(h,this.project)===oe.fromReturnDeclarationToLoopOutputDeclarationName(E)});return console.log("foundMatchingReturn",c),!c});return console.log("outputDeclarationsToRemove",u),u.forEach(h=>{if(!(e!=null&&e.hasRemoved(h.id))&&!h.deleted){const{updated:c,removed:E}=h.remove({ignoreUpstream:!1},e);t.push(...c),s.push(...E)}}),e==null||e.attemptAutoclose("sync-outputs-declarations",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}syncOutputMaps(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-extended-properties"))){const t=[],i=[],s=[],l=[],o=this.outputsDeclarations,d=this.outputs;return o.forEach(h=>{var I;let E=d.find(D=>{var P,V;return((P=D.declaration)==null?void 0:P.id)===h.id&&wi((V=D.declaration)==null?void 0:V.dataType,h.dataType)});if(E)((I=E.declaration)==null?void 0:I.id)!==h.id&&(E.setDeclaration(h),t.push(E));else{const D={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.OutputMap,defaultValue:null,index:h.index,declaration:h.toJSON(),writesValues:[],parent:this.toReference()},P=C(D,this.project);P.setParent(this,e),P.initChildren(e),e==null||e.add(P,A.Added),P.addSelfToProject(e),i.push(P),E=P}E.index!==h.index&&(E.metaSync({index:h.index},e),t.push(E))}),d.filter(h=>!o.find(E=>{var I;return((I=h.declaration)==null?void 0:I.id)===E.id})).forEach(h=>{const{updated:c,removed:E}=h.remove({ignoreUpstream:!1},e);t.push(...c),s.push(...E)}),e==null||e.attemptAutoclose("add-extended-properties",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}createCurrentIterationNumberArgumentDeclaration(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"create-current-iteration-number-argument-declaration"))){const t=[],i=[],s=[],l=[];let d=this.body.inputs.find(E=>{var I;return E.name===oe.CURRENT_ITERATION_NUMBER_ARG_NAME||E.id===((I=this.currentIterationNumberArgumentDeclaration)==null?void 0:I.id)});const u=this.getCurrentIterationNumberBuiltInValueDescriptor();if(!d){const E={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.ArgumentDeclaration,name:oe.CURRENT_ITERATION_NUMBER_ARG_NAME,description:"The number of the current iteration",defaultValue:null,constant:!0,dataType:null,implements:u==null?void 0:u.toJSON(),index:this.body.inputs.length,required:!0,parent:this.body.toReference(),writesValues:[]},I=C(E,this.project);I.setParent(this.body,e),I.initChildren(e),e==null||e.add(I,A.Added),I.addSelfToProject(e),i.push(I),d=I}!d.index&&d.index!==0&&(d.metaSync({index:0},e),t.push(d)),(!d.implements||d.implements.id!==u.id)&&(d.setImplements(u,e),t.push(d));let c=d.getDataType(e);if(!c){const E={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.DataType,options:[],implementationChooseOne:!1,staticEntities:null,interactiveEntities:null,actionEntities:null,parentRelationType:null,isList:!1,entity:null,asType:!1,like:!1,inferred:!1,andChildrenGroup:[],orChildrenGroup:[],parent:d.toReference()},I=C(E,this.project);I.setParent(d,e),I.initChildren(e),e==null||e.add(I,A.Added),I.addSelfToProject(e),i.push(I),c=I}if(!c.entity||c.entity.type!==n.PrimitiveEntity||c.entity.name!==N.Number||c.entity.id!==k["primitive-entity"].number.id){const E=this.project.getBuiltIn(k["primitive-entity"].number.id);c.setEntity(E),t.push(c)}return this.currentIterationNumberArgumentDeclaration=d,e==null||e.attemptAutoclose("create-current-iteration-number-argument-declaration",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}removeExtraBodyArgumentDeclarations(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-extra-body-argument-declarations"))){const t=[],i=[],s=[],l=[],o=this.body.inputs,d=this.getUniqueReturnDeclarations();return o.filter(h=>h===this.currentIterationNumberArgumentDeclaration||h===this.currentValueArgumentDeclaration?!1:!d.find(E=>x(h,this.project)===oe.fromReturnDeclarationToBodyArgumentDeclarationName(E))).forEach(h=>{const{updated:c,removed:E}=h.remove({ignoreUpstream:!1},e);t.push(...c),s.push(...E)}),e==null||e.attemptAutoclose("remove-extra-body-argument-declarations",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}createCurrentValueInputBasedOnInputMap(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"create-current-value-input-based-on-input-map"))){var h,c,E,I,D;const t=[],i=[],s=[],l=[];switch(this.declaration.id){case ee.List:{const P=this.body.inputs.find(g=>{var B;return((B=g.implements)==null?void 0:B.id)===k[n.Loop][ee.List].body.inputs.currentValue.id}),V=this.inputs.find(g=>{var B;return((B=g.declaration)==null?void 0:B.id)===k[n.Loop][ee.List].inputs.list.id});if(!V)break;const M=this.getCurrentValueBuiltInValueDescriptor();if(P){this.currentValueArgumentDeclaration=P;const g=this.project.get(k[n.Loop][ee.List].inputs.list.id);M&&(!P.implements||P.implements.id!==M.id)&&(P.setImplements(M,e),t.push(P));let G=P.getDataType(e);if(!G){const S={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.DataType,options:[],implementationChooseOne:!1,parentRelationType:null,staticEntities:null,interactiveEntities:null,actionEntities:null,isList:!1,entity:null,asType:!1,like:!1,inferred:!1,andChildrenGroup:[],orChildrenGroup:[],parent:g.toReference()},X=C(S,this.project);X.setParent(g,e),X.initChildren(e),e==null||e.add(X,A.Added),X.addSelfToProject(e),i.push(X),G=X}const q=V.getDataType(e);G.merge(q,e),G.metaSync({isList:!1},e)}else{const g={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.ArgumentDeclaration,name:oe.CURRENT_VALUE_ARG_NAME,description:null,defaultValue:null,index:this.body.inputs.length,constant:!0,required:!0,implements:M,writesValues:[],dataType:null,parent:this.body.toReference()},B=C(g,this.project);B.setParent(this.body,e),B.initChildren(e),e==null||e.add(B,A.Added),B.addSelfToProject(e),M&&(!B.implements||B.implements.id!==M.id)&&(B.setImplements(M,e),t.push(B)),i.push(B),this.currentValueArgumentDeclaration=B}break}case ee.ManualFlow:{this.currentValueArgumentDeclaration=null;break}case ee.Counted:{this.currentValueArgumentDeclaration=null;break}case ee.ObjectKeys:{const P=this.body.inputs.find(g=>{var B;return((B=g.implements)==null?void 0:B.id)===k[n.Loop][ee.ObjectKeys].body.inputs.currentValue.id});if(!this.inputs.find(g=>{var B;return((B=g.declaration)==null?void 0:B.id)===k[n.Loop][ee.ObjectKeys].inputs.object.id}))break;const M=this.getCurrentValueBuiltInValueDescriptor();if(P){this.currentValueArgumentDeclaration=P;const g=this.project.get(k[n.Loop][ee.ObjectKeys].inputs.object.id);M&&(!P.implements||P.implements.id!==M.id)&&(P.setImplements(M),t.push(P));let G=P.getDataType(e);if(G){const q=this.project.getBuiltIn(k["primitive-entity"].string.id);((h=G.entity)==null?void 0:h.id)!==q.id&&(G.setEntity(q),t.push(G))}else{const q={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.DataType,options:[],implementationChooseOne:!1,parentRelationType:null,staticEntities:null,interactiveEntities:null,actionEntities:null,isList:!1,entity:null,asType:!1,like:!1,inferred:!1,andChildrenGroup:[],orChildrenGroup:[],parent:g.toReference()},S=C(q,this.project);S.setParent(g,e),S.initChildren(e),e==null||e.add(S,A.Added),S.addSelfToProject(e),G=S}}else{const g={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.ArgumentDeclaration,name:oe.CURRENT_VALUE_ARG_NAME,description:null,defaultValue:null,index:this.body.inputs.length,constant:!0,required:!0,implements:M,writesValues:[],dataType:null,parent:this.body.toReference()},B=C(g,this.project);B.setParent(this.body,e),B.initChildren(e),e==null||e.add(B,A.Added),B.addSelfToProject(e),M&&(!B.implements||B.implements.id!==M.id)&&(B.setImplements(M,e),t.push(B)),i.push(B),this.currentValueArgumentDeclaration=B}break}case ee.ObjectValues:{const P=this.body.inputs.find(g=>{var B;return((B=g.implements)==null?void 0:B.id)===k[n.Loop][ee.ObjectValues].body.inputs.currentValue.id}),V=this.inputs.find(g=>{var B;return((B=g.declaration)==null?void 0:B.id)===k[n.Loop][ee.ObjectValues].inputs.object.id});if(!V)break;const M=this.getCurrentValueBuiltInValueDescriptor();if(P){this.currentValueArgumentDeclaration=P;const g=this.project.get(k[n.Loop][ee.ObjectValues].inputs.object.id);M&&(!P.implements||P.implements.id!==M.id)&&(P.setImplements(M,e),t.push(P));let G=P.getDataType(e);if(G){const q=V.getDataType(e),S=((E=q==null?void 0:q.entity)==null?void 0:E.properties)||[];(I=G.orChildrenGroup)==null||I.forEach(X=>{const{updated:pe,removed:Ee}=X.remove({ignoreUpstream:!1},e);t.push(...pe),s.push(...Ee)}),S.forEach(X=>{if(!X.getDataType(e)){const Ee={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.DataType,options:[],implementationChooseOne:!1,staticEntities:null,interactiveEntities:null,actionEntities:null,isList:!1,entity:null,asType:!1,like:!1,inferred:!1,andChildrenGroup:[],orChildrenGroup:[],parentRelationType:Pt.OrDataTypeGroup,parent:G.toReference()},Q=C(Ee,this.project);Q.setParent(G,e),Q.initChildren(e),e==null||e.add(Q,A.Added),Q.addSelfToProject(e),i.push(Q)}})}else{const q={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.DataType,options:[],implementationChooseOne:!1,parentRelationType:null,staticEntities:null,interactiveEntities:null,actionEntities:null,isList:!1,entity:null,asType:!1,like:!1,inferred:!1,andChildrenGroup:[],orChildrenGroup:[],parent:g.toReference()},S=C(q,this.project);S.setParent(g,e),S.initChildren(e),e==null||e.add(S,A.Added),S.addSelfToProject(e),G=S;const X=V.getDataType(e);(((c=X==null?void 0:X.entity)==null?void 0:c.properties)||[]).forEach(Ee=>{if(!Ee.getDataType(e)){const le={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.DataType,options:[],implementationChooseOne:!1,staticEntities:null,interactiveEntities:null,actionEntities:null,isList:!1,entity:null,asType:!1,like:!1,inferred:!1,andChildrenGroup:[],orChildrenGroup:[],parentRelationType:Pt.OrDataTypeGroup,parent:S.toReference()},ri=C(le,this.project);ri.setParent(S,e),ri.initChildren(e),e==null||e.add(ri,A.Added),ri.addSelfToProject(e),i.push(ri)}})}}else{const g={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.ArgumentDeclaration,name:oe.CURRENT_VALUE_ARG_NAME,description:null,constant:!0,defaultValue:null,index:this.body.inputs.length,required:!0,implements:M,writesValues:[],dataType:null,parent:this.body.toReference()},B=C(g,this.project);B.setParent(this.body,e),B.initChildren(e),e==null||e.add(B,A.Added),B.addSelfToProject(e),M&&(!B.implements||B.implements.id!==M.id)&&(B.setImplements(M,e),t.push(B)),i.push(B),this.currentValueArgumentDeclaration=B}break}case ee.String:{const P=this.body.inputs.find(g=>{var B;return((B=g.implements)==null?void 0:B.id)===k[n.Loop][ee.String].body.inputs.currentValue.id});if(!this.inputs.find(g=>{var B;return((B=g.declaration)==null?void 0:B.id)===k[n.Loop][ee.String].inputs.string.id}))break;const M=this.getCurrentValueBuiltInValueDescriptor();if(P){this.currentValueArgumentDeclaration=P;const g=this.project.get(k[n.Loop]["string-loop"].inputs.string.id);M&&(!P.implements||P.implements.id!==M.id)&&(P.setImplements(M,e),t.push(P));let G=P.getDataType(e);if(G){const q=this.project.getBuiltIn(k["primitive-entity"].string.id);((D=G.entity)==null?void 0:D.id)!==q.id&&(G.setEntity(q),t.push(G))}else{const q={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.DataType,options:[],implementationChooseOne:!1,parentRelationType:null,staticEntities:null,interactiveEntities:null,actionEntities:null,isList:!1,entity:null,asType:!1,like:!1,inferred:!1,andChildrenGroup:[],orChildrenGroup:[],parent:g.toReference()},S=C(q,this.project);S.setParent(g,e),S.initChildren(e),e==null||e.add(S,A.Added),S.addSelfToProject(e),i.push(S),G=S}}else{const g={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.ArgumentDeclaration,name:oe.CURRENT_VALUE_ARG_NAME,description:null,index:this.body.inputs.length,required:!0,constant:!0,defaultValue:null,implements:M,writesValues:[],dataType:null,parent:this.body.toReference()},B=C(g,this.project);B.setParent(this.body,e),B.initChildren(e),e==null||e.add(B,A.Added),B.addSelfToProject(e),M&&(!B.implements||B.implements.id!==M.id)&&(B.setImplements(M,e),t.push(B)),i.push(B),this.currentValueArgumentDeclaration=B}break}}const{updated:o,added:d,removed:u}=this.removeExtraBodyArgumentDeclarations(e);return t.push(...o),i.push(...d),s.push(...u),e==null||e.attemptAutoclose("create-current-value-input-based-on-input-map",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}syncFixedBodyArgumentDeclarations(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-fixed-body-argument-declarations"))){const t=[],i=[],s=[],l=[],{updated:o,added:d,removed:u}=this.createCurrentIterationNumberArgumentDeclaration(e);t.push(...o),i.push(...d),s.push(...u);const{updated:h,added:c,removed:E}=this.createCurrentValueInputBasedOnInputMap(e);return t.push(...h),i.push(...c),s.push(...E),e==null||e.attemptAutoclose("sync-fixed-body-argument-declarations",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}syncInputMaps(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-input-maps"))){const t=[],i=[],s=[],l=[];switch(this.declaration.id){case ee.List:{let o=null;if(this.inputs.forEach(d=>{var u;((u=d.declaration)==null?void 0:u.id)===k[n.Loop]["list-loop"].inputs.list.id?o=d:(d.remove({ignoreUpstream:!1},e),s.push(d))}),o){if(o.declaration.id!==k[n.Loop]["list-loop"].inputs.list.id){const d=this.project.get(k[n.Loop]["list-loop"].inputs.list.id);o.setDeclaration(d),t.push(o)}}else{const d=this.project.get(k[n.Loop]["list-loop"].inputs.list.id),u={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.InputMap,name:null,description:null,index:0,declaration:d.toJSON(),readsValue:null,defaultValue:null,parent:this.toReference()},h=C(u,this.project);h.setParent(this,e),h.initChildren(e),e==null||e.add(h,A.Added),h.addSelfToProject(e),i.push(h)}break}case ee.ManualFlow:{this.inputs.forEach(o=>{o.remove({ignoreUpstream:!1},e),s.push(o)});break}case ee.Counted:{let o=null;if(this.inputs.forEach(d=>{var u;((u=d.declaration)==null?void 0:u.id)===k[n.Loop]["counted-loop"].inputs.number.id?o=d:(d.remove({ignoreUpstream:!1},e),s.push(d))}),o){if(o.declaration.id!==k[n.Loop]["counted-loop"].inputs.number.id){const d=this.project.get(k[n.Loop]["counted-loop"].inputs.number.id);o.setDeclaration(d),t.push(o)}}else{const d=this.project.get(k[n.Loop]["counted-loop"].inputs.number.id),u={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.InputMap,name:null,description:null,index:0,declaration:d.toJSON(),readsValue:null,defaultValue:null,parent:this.toReference()},h=C(u,this.project);h.setParent(this,e),h.initChildren(e),e==null||e.add(h,A.Added),h.addSelfToProject(e),i.push(h)}break}case ee.ObjectKeys:{let o=null;if(this.inputs.forEach(d=>{var u;((u=d.declaration)==null?void 0:u.id)===k[n.Loop]["object-keys-loop"].inputs.object.id?o=d:(d.remove({ignoreUpstream:!1},e),s.push(d))}),o){if(o.declaration.id!==k[n.Loop]["object-keys-loop"].inputs.object.id){const d=this.project.get(k[n.Loop]["object-keys-loop"].inputs.object.id);o.setDeclaration(d),t.push(o)}}else{const d=this.project.get(k[n.Loop]["object-keys-loop"].inputs.object.id),u={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.InputMap,name:null,description:null,index:0,declaration:d.toJSON(),readsValue:null,defaultValue:null,parent:this.toReference()},h=C(u,this.project);h.setParent(this,e),h.initChildren(e),e==null||e.add(h,A.Added),h.addSelfToProject(e),i.push(h)}break}case ee.ObjectValues:{let o=null;if(this.inputs.forEach(d=>{var u;((u=d.declaration)==null?void 0:u.id)===k[n.Loop]["object-values-loop"].inputs.object.id?o=d:(d.remove({ignoreUpstream:!1},e),s.push(d))}),o){if(o.declaration.id!==k[n.Loop]["object-values-loop"].inputs.object.id){const d=this.project.get(k[n.Loop]["object-values-loop"].inputs.object.id);o.setDeclaration(d),t.push(o)}}else{const d=this.project.get(k[n.Loop]["object-values-loop"].inputs.object.id),u={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.InputMap,name:null,description:null,index:0,declaration:d.toJSON(),readsValue:null,defaultValue:null,parent:this.toReference()},h=C(u,this.project);h.setParent(this,e),h.initChildren(e),e==null||e.add(h,A.Added),h.addSelfToProject(e),i.push(h)}break}case ee.String:{let o=null;if(this.inputs.forEach(d=>{var u;((u=d.declaration)==null?void 0:u.id)===k[n.Loop]["string-loop"].inputs.string.id?o=d:(d.remove({ignoreUpstream:!1},e),s.push(d))}),o){if(o.declaration.id!==k[n.Loop]["string-loop"].inputs.string.id){const d=this.project.get(k[n.Loop]["string-loop"].inputs.string.id);o.setDeclaration(d),t.push(o)}}else{const d=this.project.get(k[n.Loop]["string-loop"].inputs.string.id),u={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.InputMap,name:null,description:null,index:0,declaration:d.toJSON(),readsValue:null,defaultValue:null,parent:this.toReference()},h=C(u,this.project);h.setParent(this,e),h.initChildren(e),e==null||e.add(h,A.Added),h.addSelfToProject(e),i.push(h)}break}}return e==null||e.attemptAutoclose("sync-input-maps",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}getCurrentValueBuiltInValueDescriptor(){var t;const e=(t=k[n.Loop][this.declaration.id].body.inputs.currentValue)==null?void 0:t.id;return e?this.project.get(e):null}getCurrentIterationNumberBuiltInValueDescriptor(){const e=k[n.Loop][this.declaration.id].body.inputs.iterationNumber.id;return this.project.get(e)}syncBody(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-body"))){var u;const t=[],i=[],s=[],l=[],o=k[n.Loop][this.declaration.id].body.id,d=this.project.getBuiltIn(o);if(this.body)((u=this.body.implements)==null?void 0:u.id)!==d.id&&(this.body.setImplements(d,e),this.body.setParent(this,e),t.push(this.body));else{const h={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.FunctionDeclaration,name:d.name,description:null,inputs:[],index:null,calls:[],collapsed:!1,private:!1,implements:d.toJSON(),x:0,y:0,parent:this.toReference()},c=C(h,this.project);c.setParent(this,e),c.initChildren(e),e==null||e.add(c,A.Added),c.addSelfToProject(e),i.push(c)}return e==null||e.attemptAutoclose("sync-body",this.id),{self:this,updated:p(t),added:p(i),removed:p(s),affected:p(l)}}syncChildren(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-children"))){const t=[],i=[],s=[],l=[],{updated:o,added:d,removed:u}=this.syncBody(e);t.push(...o),i.push(...d),s.push(...u);const{updated:h,added:c,removed:E}=this.syncInputMaps(e);t.push(...h),i.push(...c),s.push(...E);const{updated:I,added:D,removed:P}=this.syncTerminationStatements(e);t.push(...I),i.push(...D),s.push(...P);const{updated:V,added:M,removed:g}=this.syncBodyArgumentsDeclarations(e);t.push(...V),i.push(...M),s.push(...g);const{updated:B,added:G,removed:q}=this.syncBodyInputIndexes(e);t.push(...B),i.push(...G),s.push(...q);const{updated:S,added:X,removed:pe}=this.syncOutputsDeclarations(e);t.push(...S),i.push(...X),s.push(...pe);const{updated:Ee,added:Q,removed:le}=this.syncOutputMaps(e);return t.push(...Ee),i.push(...Q),s.push(...le),e==null||e.attemptAutoclose("sync-children",this.id),{self:this,updated:p(t),added:p(i),removed:p(s),affected:p(l)}}};f(oe,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>e,APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...i)=>null}),f(oe,"type",n.Loop),f(oe,"USER_MANAGED_PARENT_TYPES",[...ht,n.Project]),f(oe,"PARENT_TYPES",[...We.USER_MANAGED_PARENT_TYPES]),f(oe,"CURRENT_ITERATION_NUMBER_ARG_NAME","Current iteration number"),f(oe,"CURRENT_VALUE_ARG_NAME","Current value"),f(oe,"MUTABLE_BASE_PROPERTIES",[]),f(oe,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),f(oe,"BASE_PROPERTIES",[...oe.MUTABLE_BASE_PROPERTIES,...oe.INMUTABLE_BASE_PROPERTIES]),f(oe,"MUTABLE_META_PROPERTIES",[...oe.MUTABLE_BASE_PROPERTIES,"x","y"]),f(oe,"INMUTABLE_META_PROPERTIES",[...oe.INMUTABLE_BASE_PROPERTIES]),f(oe,"META_PROPERTIES",[...oe.MUTABLE_META_PROPERTIES,...oe.INMUTABLE_META_PROPERTIES]),f(oe,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry"]),f(oe,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","declaration"]),f(oe,"UPSTREAM_PROPERTIES",[...oe.MUTABLE_UPSTREAM_PROPERTIES,...oe.INMUTABLE_UPSTREAM_PROPERTIES]),f(oe,"MUTABLE_DOWNSTREAM_PROPERTIES",["body","inputs","outputs","outputsDeclarations","successCalls","errorCalls","error","breakStatements","continueStatements"]),f(oe,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),f(oe,"DOWNSTREAM_PROPERTIES",[...oe.MUTABLE_DOWNSTREAM_PROPERTIES,...oe.INMUTABLE_DOWNSTREAM_PROPERTIES]),f(oe,"PROPERTIES",[...oe.META_PROPERTIES,...oe.UPSTREAM_PROPERTIES,...oe.DOWNSTREAM_PROPERTIES]);let Wr=oe;function R1(r){const a=J5(),e=r.toJSON();a.safeParse(e).success,r.inputs.forEach(l=>l.validate());const s=[...Ar(r)];return Ke(r.errors,s)}const SJ=Object.freeze(Object.defineProperty({__proto__:null,validate:R1},Symbol.toStringTag,{value:"Module"}));var D1=(r=>(r.Parent="parent",r))(D1||{});const Ze=class Ze extends lt{constructor(e,t){super(e);f(this,"initialData");f(this,"id");f(this,"x");f(this,"y");f(this,"type",n.Condition);f(this,"successCalls",[]);f(this,"errorCalls",[]);f(this,"declaration");f(this,"inputs",[]);f(this,"calledBySuccess",[]);f(this,"calledByError",[]);f(this,"calledByEntry",[]);f(this,"project");f(this,"errors",[]);f(this,"parent");f(this,"detachedDependents",{});f(this,"knownVersions",null);f(this,"activeVersion",!1);f(this,"initialized",!1);f(this,"startedInitialization",!1);this.initialData=e,this.project=t,this.id=e.id,this.x=e.x,this.y=e.y}static new(e=null){return{id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:(e==null?void 0:e.author)||m.sessionAuthor,previousVersion:null,deleted:!1,type:n.Condition,declaration:null,inputs:[],parent:null,calledByEntry:[],calledBySuccess:[],calledByError:[],errorCalls:[],successCalls:[],x:0,y:0}}static fromGenerationTarget(e,t){let i=t;if(e.parent){const c=_(e.parent);i=t.get(c)}const s=e.calledByEntry.map(c=>{const E=_(c);return t.get(E)}),l=e.calledBySuccess.map(c=>{const E=_(c);return t.get(E)}),o=e.calledByError.map(c=>{const E=_(c);return t.get(E)});let d;if(e.declaration){const c=_(e.declaration);d=t.get(c)}const u={id:e.id,version:m.UUID.uuid(),createdAt:T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.Condition,declaration:d,calledByEntry:s,calledBySuccess:l,calledByError:o,errorCalls:[],successCalls:[],inputs:[],x:0,y:0,parent:i},h=C(u,t);return h.setParent(i,null),h.initChildren(null),h}static validateGenerationTarget(e,t){let i=JSON.parse(JSON.stringify(e));const s=[],l=bt(i,{parent:{list:!1,types:[...ht,n.Project],optional:!0}},t);return i=l.modifiedData,s.push(...l.errors,...ut(i)),e.declaration?t.get(e.declaration)?t.conditionDeclarations.find(u=>u.id===e.declaration)||s.push(new w({id:`${e.id}--${R.InvalidImplementsReference}`,code:R.InvalidImplementsReference,severity:O.Error,message:`Entity of type '${e.type}' with id '${e.id}' has an 'declaration' property that isn't pointing to an action descriptor reserved for '${n.Condition}' entities.
99
+ You shouldn't have to manually update a 'parent' property. The equivalent result is to change its callers, the value writters of its inputs, or the value readers of its outputs.`,issue:null})),{errors:t,modifiedData:e}}subscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]||(this.detachedDependents[t.entity.id]=t)}),this}unsubscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]&&delete this.detachedDependents[t.entity.id]}),this}syncDependents(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-dependents"))){const t=[],i=[],s=[],l=[];return Object.values(this.detachedDependents).forEach(o=>{const d=o.entity.afterAllChildrenInitialized(e);t.push(...d.updated),i.push(...d.added),s.push(...d.removed),l.push(...d.affected)}),e==null||e.attemptAutoclose("sync-dependents",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];if(t==="parent"){const{updated:u,added:h,removed:c}=this.remove({ignoreUpstream:!1},i);s.push(...u),l.push(...h),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}onDetachedDependencyRestored(e,t,i){const s=[],l=[],o=[],d=[];if(t==="parent"){const{updated:u,added:h,removed:c}=this.restore({},i);s.push(...u),l.push(...h),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}unsubscribeFromDependencies(){var e;return(e=this.parent)==null||e.unsubscribeDependents([{entity:this,field:"parent"}]),this}subscribeToDependencies(){var e;return(e=this.parent)==null||e.subscribeDependents([{entity:this,field:"parent"}]),this}increaseVersion(e){if(e&&!T(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&T(e).isSame(T(this.createdAt))?this:(this.previousVersion=this.version,this.version=m.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new oe(this,this.project);return e.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,e):new Map([[this.version,e]]),e.inputs=this.inputs,e.outputs=this.outputs,e.error=this.error,e.successCalls=this.successCalls,e.errorCalls=this.errorCalls,e.declaration=this.declaration,e.outputsDeclarations=this.outputsDeclarations,e.body=this.body,e.calledByEntry=this.calledByEntry,e.calledBySuccess=this.calledBySuccess,e.calledByError=this.calledByError,e.process=this.process,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],i=[],s=[],l=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),i.push(...o.added),s.push(...o.removed)}return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}async restoreVersion(e){var d;const t=[],i=[],s=[],l=[];if(this.version===e)return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this};if(!this.knownVersions){const u=new Map;for(const[h,c]of this.knownVersions||new Map){if(u.set(h,c),c.activeVersion=!1,c.knownVersions)for(const[E,I]of c.knownVersions)u.set(E,I);c.knownVersions=null}}let o=(d=this.knownVersions)==null?void 0:d.get(e);if(!o){const u=await this.APILoadVersion({},e);if(!u)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new oe(u,this.project)}return this.metaSync(o.toShallowJSON(),null),this.inputs=o.inputs,this.outputs=o.outputs,this.error=o.error,this.successCalls=o.successCalls,this.errorCalls=o.errorCalls,this.declaration=o.declaration,this.outputsDeclarations=o.outputsDeclarations,this.body=o.body,this.calledByEntry=o.calledByEntry,this.calledBySuccess=o.calledBySuccess,this.calledByError=o.calledByError,this.process=o.process,this.parent=o.parent,{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}hydrateAncestors(){const e=[],t=[],i=[],s=[];if(this.initialData.parent){const l=_(this.initialData.parent),o=this.project.get(l);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' 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 l=_(this.initialData.declaration),o=this.project.get(l);o&&(this.setDeclaration(o),e.push(o))}return this.initialData.calledByEntry.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addEntryCaller(d,null),d.addCall(this,null),e.push(d))}),this.initialData.calledBySuccess.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addSuccessCaller(d,null),d.addSuccessCall(this,null),e.push(d))}),this.initialData.calledByError.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addErrorCaller(d,null),d.addErrorCall(this,null),e.push(d))}),{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],i=[],s=[],l=[];this.initialized=!0;const{updated:o,added:d,removed:u}=this.syncChildren(e);return t.push(...o),i.push(...d),s.push(...u),this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addSelfToProject(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-self-to-project"))){const t=[this],i=[],s=[],l=[];return this.parent===this.project&&this.project.addLoop(this),this.successCalls.forEach(o=>{o.addSuccessCaller(this,e),t.push(o)}),this.errorCalls.forEach(o=>{o.addErrorCaller(this,e),t.push(o)}),this.calledByEntry.forEach(o=>{o.addCall(this,e),t.push(o)}),this.calledBySuccess.forEach(o=>{o.addSuccessCall(this,e),t.push(o)}),this.calledByError.forEach(o=>{o.addErrorCall(this,e),t.push(o)}),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}removeInput(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-input"))){const i=this.inputs.findIndex(s=>s.id===e.id);return i>-1&&(this.inputs.splice(i,1),t&&(t==null||t.add(this,A.Affected))),t==null||t.attemptAutoclose("remove-input",this.id),this}addInput(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-input"))){return this.inputs.includes(e)?(t==null||t.attemptAutoclose("add-input",this.id),this):(this.inputs.push(e),t==null||t.add(this,A.Affected),t==null||t.attemptAutoclose("add-input",this.id),this)}addOutputDeclaration(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-output-declaration"))){return this.outputsDeclarations.includes(e)?(t==null||t.attemptAutoclose("add-output-declaration",this.id),this):(this.outputsDeclarations.push(e),t==null||t.add(this,A.Affected),t==null||t.attemptAutoclose("add-output-declaration",this.id),this)}removeOutputDeclaration(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-output-declaration"))){const i=this.outputsDeclarations.findIndex(s=>s.id===e.id);return i>-1&&(this.outputsDeclarations.splice(i,1),t==null||t.add(this,A.Affected)),t==null||t.attemptAutoclose("remove-output-declaration",this.id),this}addOutput(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-output"))){return this.outputs.includes(e)?(t==null||t.attemptAutoclose("add-output",this.id),this):(this.outputs.push(e),t==null||t.add(this,A.Affected),t==null||t.attemptAutoclose("add-output",this.id),this)}removeOutput(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-output"))){const i=this.outputs.findIndex(s=>s.id===e.id);return i>-1&&(this.outputs.splice(i,1),t&&(t==null||t.add(this,A.Affected))),t==null||t.attemptAutoclose("remove-output",this.id),this}setBody(e){return this.body=e,this}addSuccessCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-success-caller")),i=!1){return this.calledBySuccess.find(s=>s.id===e.id)||(this.calledBySuccess.push(e),t==null||t.add(this,A.Updated),i&&K(this,t)),t==null||t.attemptAutoclose("add-success-caller",this.id),this}addErrorCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-error-caller")),i=!1){return this.calledByError.find(s=>s.id===e.id)||(this.calledByError.push(e),t==null||t.add(this,A.Updated),i&&K(this,t)),t==null||t.attemptAutoclose("add-error-caller",this.id),this}addEntryCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-entry-caller")),i=!1){return this.calledByEntry.find(s=>s.id===e.id)||(this.calledByEntry.push(e),t==null||t.add(this,A.Updated),i&&K(this,t)),t==null||t.attemptAutoclose("add-entry-caller",this.id),this}addErrorCall(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-error-call")),i=!1){return this.errorCalls.find(s=>s.id===e.id)||(this.errorCalls.push(e),i&&K(this,t),t==null||t.add(this,A.Affected)),t==null||t.attemptAutoclose("add-error-call",this.id),this}addSuccessCall(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-success-call")),i=!1){return this.successCalls.find(s=>s.id===e.id)||(this.successCalls.push(e),i&&K(this,t),t==null||t.add(this,A.Affected)),t==null||t.attemptAutoclose("add-success-call",this.id),this}removeCall(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-call")),i=!1){const s=this.successCalls.findIndex(o=>o.id===e.id);s>-1&&(this.successCalls.splice(s,1),t==null||t.add(this,A.Affected));const l=this.errorCalls.findIndex(o=>o.id===e.id);return l>-1&&(this.errorCalls.splice(l,1),t==null||t.add(this,A.Affected)),i&&K(this,t),t==null||t.attemptAutoclose("remove-call",this.id),this}removeCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-caller")),i=!1){return this.calledBySuccess=this.calledBySuccess.filter(s=>s.id!==e.id?!0:(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected),!1)),this.calledByError=this.calledByError.filter(s=>s.id!==e.id?!0:(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected),!1)),this.calledByEntry=this.calledByEntry.filter(s=>s.id!==e.id?!0:(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected),!1)),i&&K(this,t),t==null||t.attemptAutoclose("remove-caller",this.id),this}replaceDetachedChild(e,t){const i=this.detachedChildren.indexOf(e);return i!==-1&&(this.detachedChildren[i]=t),this}subscribeDetachedChild(e){return this.detachedChildren.includes(e)||this.detachedChildren.push(e),this}setParent(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"set-parent"))){var i;return((i=this.parent)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,A.Updated),t==null||t.attemptAutoclose("set-parent",this.id))),this}setDeclaration(e){return this.declaration=e,this}initChildren(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.declaration=C(this.initialData.declaration,this.project),this.successCalls=this.initialData.successCalls.map(t=>{const i=C(t,this.project);if(i.addSuccessCaller(this),[n.BreakStatement,n.ContinueStatement].includes(i.type))i.setParent(this.parent.parent,null),i.initChildren(e);else if(i.type===n.ReturnStatement){const s=It(this,this.project);i.setParent(s,null),i.initChildren(e)}else i.type!==n.InternalCall&&(i.setParent(this.parent,null),i.initChildren(e));return i}),this.errorCalls=this.initialData.errorCalls.map(t=>{const i=C(t,this.project);if(i.addErrorCaller(this),[n.BreakStatement,n.ContinueStatement].includes(i.type))i.setParent(this.parent.parent,null),i.initChildren(e);else if(i.type===n.ReturnStatement){const s=It(this,this.project);i.setParent(s,null),i.initChildren(e)}else i.type!==n.InternalCall&&(i.setParent(this.parent,null),i.initChildren(e));return i}),this.inputs=this.initialData.inputs.map(t=>{const i=C(t,this.project);return i.setParent(this,null),i.initChildren(e),i}),this.outputs=this.initialData.outputs.map(t=>{const i=C(t,this.project);return i.setParent(this,null),i.initChildren(e),i}),this.initialData.process&&(this.process=C(this.initialData.process,this.project),this.process.setParent(this,null),this.process.initChildren(e)),this.initialData.body&&(this.body=C(this.initialData.body,this.project),this.body.setParent(this,null),this.body.initChildren(e)),this.initialData.error&&(this.error=C(this.initialData.error,this.project),this.error.setParent(this,null),this.error.initChildren(e)),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this)}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"meta-sync"))){const i=pt(this,e),s=this.toMeta();return this.x=e.x||s.x,this.y=e.y||s.y,super.metaSync(e),e.deleted===!0&&!s.deleted?t==null||t.add(this,A.Removed):e.deleted===!1&&s.deleted?t==null||t.add(this,A.Added):i&&(t==null||t.add(this,A.Updated)),t==null||t.attemptAutoclose("meta-sync",this.id),this}async APILoad(e=U,...t){return await oe.repository.APILoad(this.id,...t),this}async APICreate(e=U,...t){return await oe.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=U,...t){return await oe.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=U,...t){return await oe.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=U,...t){return await oe.repository.APIClone(this.id,...t),this}async APILoadVersion(e=U,t,...i){return await oe.repository.APILoadVersion(this.id,t,...i)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-entity"))){const i=[],s=[],l=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(s.push(this),this.unsubscribe(),this.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(d=>{const{updated:u,removed:h,added:c}=d.entity.onDetachedDependencyRemoved(this,d.field,t);i.push(...u),s.push(...h),l.push(...c)}),this.inputs.forEach(d=>{const{updated:u,removed:h}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...h)}),this.outputs.forEach(d=>{const{updated:u,removed:h}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...h)}),this.body.remove({ignoreUpstream:!0},t),this.error){const{updated:d,removed:u}=this.error.remove({ignoreUpstream:!0},t);i.push(...d),s.push(...u)}return this.successCalls.forEach(d=>{i.push(d),d.removeCaller(this,t)}),this.errorCalls.forEach(d=>{i.push(d),d.removeCaller(this,t)}),e||this.calledBy.forEach(d=>{i.push(d),d.removeCall(this,t)}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:p(l),updated:p(i),removed:p(s),affected:p(o),self:this}}restore({}={},e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"restore-entity"))){const t=[],i=[],s=[],l=[];return e!=null&&e.hasAdded(this.id)?(e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),this.inputs.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.outputs.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.body.restore({},e),this.successCalls.forEach(o=>{i.push(o),o.addSuccessCaller(this,e)}),this.errorCalls.forEach(o=>{i.push(o),o.addErrorCaller(this,e)}),this.calledBySuccess.forEach(o=>{i.push(o),o.addSuccessCall(this,e)}),this.calledByError.forEach(o=>{i.push(o),o.addErrorCall(this,e)}),this.calledByEntry.forEach(o=>{i.push(o),o.addCall(this,e)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(l),self:this})}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.inputs.flatMap(i=>i.toFlat(e)),...this.outputs.flatMap(i=>i.toFlat(e)),...this.outputsDeclarations.flatMap(i=>i.toFlat(e)),...this.process?this.process.toFlat(e):[],...this.successCalls.flatMap(i=>i.toFlat(e)),...this.errorCalls.flatMap(i=>i.toFlat(e)),...this.error?this.error.toFlat(e):[],...this.body?this.body.toFlat(e):[],...this.continueStatements.flatMap(i=>i.toFlat(e)),...this.breakStatements.flatMap(i=>i.toFlat(e))])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.inputs.flatMap(i=>i.toFlatIds(e)),...this.outputs.flatMap(i=>i.toFlatIds(e)),...this.process?this.process.toFlatIds(e):[],...this.successCalls.flatMap(i=>i.toFlatIds(e)),...this.errorCalls.flatMap(i=>i.toFlatIds(e)),...this.error?this.error.toFlatIds(e):[],...this.body?this.body.toFlatIds(e):[],...this.continueStatements.flatMap(i=>i.toFlatIds(e)),...this.breakStatements.flatMap(i=>i.toFlatIds(e))])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,x:this.x,y:this.y,type:this.type}}toJSON(e=new Set){var t,i;return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,calledBySuccess:this.calledBySuccess.map(s=>s.toReference()),calledByError:this.calledByError.map(s=>s.toReference()),calledByEntry:this.calledByEntry.map(s=>s.toReference()),process:((t=this.process)==null?void 0:t.toJSON(e))||null,declaration:this.declaration.toJSON(e),inputs:this.inputs.map(s=>s.toJSON(e)),outputs:this.outputs.map(s=>s.toJSON(e)),outputsDeclarations:this.outputsDeclarations.map(s=>s.toJSON(e)),successCalls:this.successCalls.map(s=>s.toJSON(e)),errorCalls:this.errorCalls.map(s=>s.toJSON(e)),error:((i=this.error)==null?void 0:i.toJSON(e))||null,body:this.body.toJSON(e),parent:this.parent.toReference()})}toJSONClone(e=J){var i,s,l,o,d,u,h;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||yt(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(s=e.seenEntities)!=null&&s.has(t)||(l=e.seenEntities)!=null&&l.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(d=e.seenEntities)==null||d.add(this.id),{id:t,version:m.UUID.uuid(),createdAt:e.timestamp||T().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,calledBySuccess:this.calledBySuccess.map(c=>c.toReference({seenEntityMaps:e.seenEntityMaps})),calledByError:this.calledByError.map(c=>c.toReference({seenEntityMaps:e.seenEntityMaps})),calledByEntry:this.calledByEntry.map(c=>c.toReference({seenEntityMaps:e.seenEntityMaps})),process:((u=this.process)==null?void 0:u.toJSONClone({...e,newId:null}))||null,declaration:this.declaration.toJSON(),inputs:this.inputs.map(c=>c.toJSONClone({...e,newId:null})),outputs:this.outputs.map(c=>c.toJSONClone({...e,newId:null})),outputsDeclarations:this.outputsDeclarations.map(c=>c.toJSONClone({...e,newId:null})),successCalls:this.successCalls.map(c=>c.toJSONClone({...e,newId:null})),errorCalls:this.errorCalls.map(c=>c.toJSONClone({...e,newId:null})),error:((h=this.error)==null?void 0:h.toJSONClone({...e,newId:null}))||null,body:this.body.toJSONClone({...e,newId:null}),parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps})})}toReference(e=J){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+m.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=J){var i,s,l,o,d;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,declaration:((s=this.declaration)==null?void 0:s.toReference(e))||null,body:((l=this.body)==null?void 0:l.toReference(e))||null,inputs:this.inputs.map(u=>u.toReference(e)),outputs:this.outputs.map(u=>u.toReference(e)),outputsDeclarations:this.outputsDeclarations.map(u=>u.toReference(e)),successCalls:this.successCalls.map(u=>u.toReference(e)),errorCalls:this.errorCalls.map(u=>u.toReference(e)),process:((o=this.process)==null?void 0:o.toReference(e))||null,calledBySuccess:this.calledBySuccess.map(u=>u.toReference(e)),calledByError:this.calledByError.map(u=>u.toReference(e)),calledByEntry:this.calledByEntry.map(u=>u.toReference(e)),error:((d=this.error)==null?void 0:d.toReference(e))||null,parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){var i;return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...((i=this.body)==null?void 0:i.toFlatJSON(e))||[],...this.successCalls.flatMap(s=>s.toFlatJSON(e)),...this.errorCalls.flatMap(s=>s.toFlatJSON(e)),...this.inputs.flatMap(s=>s.toFlatJSON(e)),...this.outputs.flatMap(s=>s.toFlatJSON(e)),...this.continueStatements.flatMap(s=>s.toFlatJSON(e)),...this.breakStatements.flatMap(s=>s.toFlatJSON(e)),...this.error?this.error.toFlatJSON(e):[],...this.process?this.process.toFlatJSON(e):[]])}toGenerationTarget(){const e=this.parent.type===n.Project?void 0:this.parent.id;return{id:this.id,type:this.type,calledByEntry:this.calledByEntry.map(t=>t.id),calledBySuccess:this.calledBySuccess.map(t=>t.id),calledByError:this.calledByError.map(t=>t.id),declaration:this.declaration.id,parent:e}}toFlatGenerationTarget(e=new Set){var i;return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...((i=this.body)==null?void 0:i.toFlatGenerationTarget(e))||[],...this.successCalls.flatMap(s=>s.toFlatGenerationTarget(e)),...this.errorCalls.flatMap(s=>s.toFlatGenerationTarget(e)),...this.inputs.flatMap(s=>s.toFlatGenerationTarget(e)),...this.outputs.flatMap(s=>s.toFlatGenerationTarget(e)),...this.continueStatements.flatMap(s=>s.toFlatGenerationTarget(e)),...this.breakStatements.flatMap(s=>s.toFlatGenerationTarget(e)),...this.error?this.error.toFlatGenerationTarget(e):[],...this.process?this.process.toFlatGenerationTarget(e):[]])}clearErrors(){var e,t;return this.errors=[],this.inputs.forEach(i=>i.clearErrors()),this.outputs.forEach(i=>i.clearErrors()),this.successCalls.forEach(i=>i.clearErrors()),this.errorCalls.forEach(i=>i.clearErrors()),this.continueStatements.forEach(i=>i.clearErrors()),this.breakStatements.forEach(i=>i.clearErrors()),(e=this.process)==null||e.clearErrors(),(t=this.error)==null||t.clearErrors(),this}validate(){const e=Lc(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){return[...this.errors,...this.inputs.flatMap(t=>t.getErrors()),...this.outputs.flatMap(t=>t.getErrors()),...this.body?this.body.getErrors():[],...this.error?this.error.getErrors():[],...this.process?this.process.getErrors():[]]}getShallowErrors(){return this.errors}clone(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"clone-entity")),t=null,i=null,s=!0){var D,P;let l=mt(t,this);const o=this.toJSON(),d=i||m.UUID.uuid();o.inputs=[];const u=d.split("-id"),h=u[u.length-1||0]||d;o.id=d,o.version=m.UUID.uuid(),o.createdAt=(e==null?void 0:e.timestamp)||T().toISOString(),o.author=(e==null?void 0:e.author)||"1",o.previousVersion=null,o.deleted=!1;const c=st(o,l);t?c.setParent(t,null):c.setParent(this.parent,null),s&&c.subscribe(),c.initChildren(e),e==null||e.add(c,A.Added);const E=(D=this.inputs)==null?void 0:D.map((V,M)=>V.clone(e,c,h+"-input-map-"+M+"-id",s));c.inputs=E;const I=(P=this.outputs)==null?void 0:P.map((V,M)=>V.clone(e,c,h+"-output-map-"+M+"-id",s));return c.outputs=I,this.body&&(c.body=this.body.clone(e,c,h+"-body-id",s,!0)),this.error&&(c.error=this.error.clone(e,c,h+"-error-map-id",s)),this.process&&(c.process=this.process.clone(e,c,h+"-process-id",s)),e==null||e.attemptAutoclose("clone-entity",this.id),c}getVariableInstances(){return this.body?He(this.body).filter(i=>i.type===n.VariableInstance):[]}addReturnStatement(e){return rt.includes(this.parent.type)&&this.parent.addReturnStatement(e),this}removeReturnStatement(e){return rt.includes(this.parent.type)&&this.parent.removeReturnStatement(e),this}addBreakStatement(e){return this.breakStatements.includes(e)||this.breakStatements.push(e),this}removeBreakStatement(e){const t=this.breakStatements.indexOf(e);return t!==-1&&this.breakStatements.splice(t,1),this}addContinueStatement(e){return this.continueStatements.includes(e)||this.continueStatements.push(e),this}removeContinueStatement(e){const t=this.continueStatements.indexOf(e);return t!==-1&&this.continueStatements.splice(t,1),this}getUniqueReturnDeclarations(){const e=[];return[...this.breakStatements,...this.continueStatements].forEach(i=>{i.outputs.forEach(l=>{e.find(d=>d===l||x(d,this.project)===x(l,this.project)&&wi(d.dataType,l.dataType))||e.push(l)})}),p(e)}syncTerminationStatements(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-termination-statements"))){const t=[],i=[],s=[],l=[],o=this.getUniqueReturnDeclarations();return[...this.breakStatements,...this.continueStatements].forEach(u=>{const h=u.outputs,c=o.filter(E=>!h.find(I=>x(E,this.project)===x(I,this.project)&&wi(E.dataType,I.dataType)));c.length&&(t.push(u),e==null||e.add(u,A.Updated)),c.forEach(E=>{const I=E.clone(e,u);e==null||e.add(I,A.Added),I.addSelfToProject(e),i.push(I)})}),e==null||e.attemptAutoclose("sync-termination-statements",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}syncBodyInputIndexes(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-body-input-indexes"))){const t=[],i=[],s=[],l=[];return this.body.inputs.sort((d,u)=>d.index-u.index),this.body.inputs.forEach((d,u)=>{d.index!==u&&(d.metaSync({index:u},e),t.push(d))}),e==null||e.attemptAutoclose("sync-body-input-indexes",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}syncBodyArgumentsDeclarations(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-body-arguments-declarations"))){const t=[],i=[],s=[],l=[],{updated:o,added:d,removed:u}=this.syncFixedBodyArgumentDeclarations(e);t.push(...o),i.push(...d),s.push(...u);const h=this.getUniqueReturnDeclarations(),c=this.body.inputs;h.sort((P,V)=>P.index-V.index),h.forEach(P=>{const V=P.getDataType(e);let g=c.find(pe=>x(pe,this.project)===oe.fromReturnDeclarationToBodyArgumentDeclarationName(P)&&wi(pe.dataType,P.dataType));if(!g){const pe=oe.fromReturnDeclarationToBodyArgumentDeclarationName(P),Ee={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.ArgumentDeclaration,name:pe,description:`Aggretated list of all previously outputted values from each iteration by the output '${x(P,this.project)}'`,defaultValue:null,constant:!0,dataType:null,implements:null,index:P.index,required:P.required,parent:this.body.toReference(),writesValues:[]},Q=C(Ee,this.project);Q.setParent(this.body,e),Q.initChildren(e),e==null||e.add(Q,A.Added),Q.addSelfToProject(e),i.push(Q),g=Q}const B=this.body.inputs.find(pe=>pe.index===g.index&&pe!==g),G=this.body.inputs.filter(pe=>pe!==g);let q=g.index;B&&(q=Math.max(...G.map(pe=>pe.index))+1),g.index!==q&&(g.metaSync({index:q},e),t.push(g));const S=g.getDataType(e);let X=S;if(V)if(!S||!wi(S,V)){if(!X){const Ee=V.clone(e,g);e==null||e.add(Ee,A.Added),Ee.addSelfToProject(e),X=Ee,i.push(Ee),t.push(g)}const pe=X.merge(V,e);pe.self===X?V.remove({ignoreUpstream:!1},e):pe.self===V&&(X.remove({ignoreUpstream:!1},e),X=V),X.metaSync({isList:!0},e)}else X.isList||(X.metaSync({isList:!0},e),t.push(X));if(!V&&!X){const pe={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.DataType,options:[],implementationChooseOne:!1,parentRelationType:null,staticEntities:null,interactiveEntities:null,actionEntities:null,isList:!0,entity:null,asType:!1,like:!1,inferred:!1,andChildrenGroup:[],orChildrenGroup:[],parent:g.toReference()},Ee=C(pe,this.project);Ee.metaSync({isList:!0},e),Ee.setParent(g,e),Ee.initChildren(e),e==null||e.add(Ee,A.Added),Ee.addSelfToProject(e),i.push(Ee)}});const{updated:E,added:I,removed:D}=this.removeExtraBodyArgumentDeclarations(e);return t.push(...E),i.push(...I),s.push(...D),e==null||e.attemptAutoclose("sync-body-arguments-declarations",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}syncOutputsDeclarations(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-outputs-declarations"))){const t=[],i=[],s=[],l=[],o=this.getUniqueReturnDeclarations(),d=this.outputsDeclarations;o.forEach((h,c)=>{h.index!==c&&(h.metaSync({index:c},e),t.push(h))}),o.forEach(h=>{const c=h.getDataType(e);let I=d.find(V=>x(V,this.project)===oe.fromReturnDeclarationToLoopOutputDeclarationName(h)&&wi(V.dataType,h.dataType));if(!I){const V=oe.fromReturnDeclarationToLoopOutputDeclarationName(h),M={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.ValueDescriptor,name:V,description:`Aggretated list of all previously outputted values from each iteration by the output '${x(h,this.project)}'`,defaultValue:null,dataType:null,index:h.index,required:h.required,parentRelationType:L.FixedReturns,parent:this.toReference()},g=C(M,this.project);g.setParent(this,e),g.initChildren(e),e==null||e.add(g,A.Added),g.addSelfToProject(e),i.push(g),I=g}I.index!==h.index&&(I.metaSync({index:h.index},e),t.push(I));let P=I.getDataType(e);if(c)if(!P||!wi(P,c)){if(!P){const M=c.clone(e,I);e==null||e.add(M,A.Added),M.addSelfToProject(e),P=M,i.push(M),t.push(I)}const V=P.merge(c,e);V.self===P?c.remove({ignoreUpstream:!1},e):V.self===c&&(P.remove({ignoreUpstream:!1},e),P=c),P.metaSync({isList:!0},e)}else P.isList||(P.metaSync({isList:!0},e),t.push(P));if(!c&&!P){const V={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.DataType,options:[],implementationChooseOne:!1,staticEntities:null,interactiveEntities:null,actionEntities:null,parentRelationType:null,isList:!0,entity:null,asType:!1,like:!1,inferred:!1,andChildrenGroup:[],orChildrenGroup:[],parent:I.toReference()},M=C(V,this.project);M.metaSync({isList:!0},e),M.setParent(I,e),M.initChildren(e),e==null||e.add(M,A.Added),M.addSelfToProject(e),i.push(M)}}),console.log("uniqueReturnDeclarations: ",o);const u=d.filter(h=>{const c=o.find(E=>{const I=x(h,this.project),D=oe.fromReturnDeclarationToLoopOutputDeclarationName(E);return console.log("resolvedName",I),console.log("nameToMatch",D),console.log("Skip delete?",I===D),x(h,this.project)===oe.fromReturnDeclarationToLoopOutputDeclarationName(E)});return console.log("foundMatchingReturn",c),!c});return console.log("outputDeclarationsToRemove",u),u.forEach(h=>{if(!(e!=null&&e.hasRemoved(h.id))&&!h.deleted){const{updated:c,removed:E}=h.remove({ignoreUpstream:!1},e);t.push(...c),s.push(...E)}}),e==null||e.attemptAutoclose("sync-outputs-declarations",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}syncOutputMaps(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-extended-properties"))){const t=[],i=[],s=[],l=[],o=this.outputsDeclarations,d=this.outputs;return o.forEach(h=>{var I;let E=d.find(D=>{var P,V;return((P=D.declaration)==null?void 0:P.id)===h.id&&wi((V=D.declaration)==null?void 0:V.dataType,h.dataType)});if(E)((I=E.declaration)==null?void 0:I.id)!==h.id&&(E.setDeclaration(h),t.push(E));else{const D={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.OutputMap,defaultValue:null,index:h.index,declaration:h.toJSON(),writesValues:[],parent:this.toReference()},P=C(D,this.project);P.setParent(this,e),P.initChildren(e),e==null||e.add(P,A.Added),P.addSelfToProject(e),i.push(P),E=P}E.index!==h.index&&(E.metaSync({index:h.index},e),t.push(E))}),d.filter(h=>!o.find(E=>{var I;return((I=h.declaration)==null?void 0:I.id)===E.id})).forEach(h=>{const{updated:c,removed:E}=h.remove({ignoreUpstream:!1},e);t.push(...c),s.push(...E)}),e==null||e.attemptAutoclose("add-extended-properties",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}createCurrentIterationNumberArgumentDeclaration(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"create-current-iteration-number-argument-declaration"))){const t=[],i=[],s=[],l=[];let d=this.body.inputs.find(E=>{var I;return E.name===oe.CURRENT_ITERATION_NUMBER_ARG_NAME||E.id===((I=this.currentIterationNumberArgumentDeclaration)==null?void 0:I.id)});const u=this.getCurrentIterationNumberBuiltInValueDescriptor();if(!d){const E={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.ArgumentDeclaration,name:oe.CURRENT_ITERATION_NUMBER_ARG_NAME,description:"The number of the current iteration",defaultValue:null,constant:!0,dataType:null,implements:u==null?void 0:u.toJSON(),index:this.body.inputs.length,required:!0,parent:this.body.toReference(),writesValues:[]},I=C(E,this.project);I.setParent(this.body,e),I.initChildren(e),e==null||e.add(I,A.Added),I.addSelfToProject(e),i.push(I),d=I}!d.index&&d.index!==0&&(d.metaSync({index:0},e),t.push(d)),(!d.implements||d.implements.id!==u.id)&&(d.setImplements(u,e),t.push(d));let c=d.getDataType(e);if(!c){const E={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.DataType,options:[],implementationChooseOne:!1,staticEntities:null,interactiveEntities:null,actionEntities:null,parentRelationType:null,isList:!1,entity:null,asType:!1,like:!1,inferred:!1,andChildrenGroup:[],orChildrenGroup:[],parent:d.toReference()},I=C(E,this.project);I.setParent(d,e),I.initChildren(e),e==null||e.add(I,A.Added),I.addSelfToProject(e),i.push(I),c=I}if(!c.entity||c.entity.type!==n.PrimitiveEntity||c.entity.name!==N.Number||c.entity.id!==k["primitive-entity"].number.id){const E=this.project.getBuiltIn(k["primitive-entity"].number.id);c.setEntity(E),t.push(c)}return this.currentIterationNumberArgumentDeclaration=d,e==null||e.attemptAutoclose("create-current-iteration-number-argument-declaration",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}removeExtraBodyArgumentDeclarations(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-extra-body-argument-declarations"))){const t=[],i=[],s=[],l=[],o=this.body.inputs,d=this.getUniqueReturnDeclarations();return o.filter(h=>h===this.currentIterationNumberArgumentDeclaration||h===this.currentValueArgumentDeclaration?!1:!d.find(E=>x(h,this.project)===oe.fromReturnDeclarationToBodyArgumentDeclarationName(E))).forEach(h=>{const{updated:c,removed:E}=h.remove({ignoreUpstream:!1},e);t.push(...c),s.push(...E)}),e==null||e.attemptAutoclose("remove-extra-body-argument-declarations",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}createCurrentValueInputBasedOnInputMap(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"create-current-value-input-based-on-input-map"))){var h,c,E,I,D;const t=[],i=[],s=[],l=[];switch(this.declaration.id){case ee.List:{const P=this.body.inputs.find(g=>{var B;return((B=g.implements)==null?void 0:B.id)===k[n.Loop][ee.List].body.inputs.currentValue.id}),V=this.inputs.find(g=>{var B;return((B=g.declaration)==null?void 0:B.id)===k[n.Loop][ee.List].inputs.list.id});if(!V)break;const M=this.getCurrentValueBuiltInValueDescriptor();if(P){this.currentValueArgumentDeclaration=P;const g=this.project.get(k[n.Loop][ee.List].inputs.list.id);M&&(!P.implements||P.implements.id!==M.id)&&(P.setImplements(M,e),t.push(P));let G=P.getDataType(e);if(!G){const S={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.DataType,options:[],implementationChooseOne:!1,parentRelationType:null,staticEntities:null,interactiveEntities:null,actionEntities:null,isList:!1,entity:null,asType:!1,like:!1,inferred:!1,andChildrenGroup:[],orChildrenGroup:[],parent:g.toReference()},X=C(S,this.project);X.setParent(g,e),X.initChildren(e),e==null||e.add(X,A.Added),X.addSelfToProject(e),i.push(X),G=X}const q=V.getDataType(e);G.merge(q,e),G.metaSync({isList:!1},e)}else{const g={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.ArgumentDeclaration,name:oe.CURRENT_VALUE_ARG_NAME,description:null,defaultValue:null,index:this.body.inputs.length,constant:!0,required:!0,implements:M,writesValues:[],dataType:null,parent:this.body.toReference()},B=C(g,this.project);B.setParent(this.body,e),B.initChildren(e),e==null||e.add(B,A.Added),B.addSelfToProject(e),M&&(!B.implements||B.implements.id!==M.id)&&(B.setImplements(M,e),t.push(B)),i.push(B),this.currentValueArgumentDeclaration=B}break}case ee.ManualFlow:{this.currentValueArgumentDeclaration=null;break}case ee.Counted:{this.currentValueArgumentDeclaration=null;break}case ee.ObjectKeys:{const P=this.body.inputs.find(g=>{var B;return((B=g.implements)==null?void 0:B.id)===k[n.Loop][ee.ObjectKeys].body.inputs.currentValue.id});if(!this.inputs.find(g=>{var B;return((B=g.declaration)==null?void 0:B.id)===k[n.Loop][ee.ObjectKeys].inputs.object.id}))break;const M=this.getCurrentValueBuiltInValueDescriptor();if(P){this.currentValueArgumentDeclaration=P;const g=this.project.get(k[n.Loop][ee.ObjectKeys].inputs.object.id);M&&(!P.implements||P.implements.id!==M.id)&&(P.setImplements(M),t.push(P));let G=P.getDataType(e);if(G){const q=this.project.getBuiltIn(k["primitive-entity"].string.id);((h=G.entity)==null?void 0:h.id)!==q.id&&(G.setEntity(q),t.push(G))}else{const q={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.DataType,options:[],implementationChooseOne:!1,parentRelationType:null,staticEntities:null,interactiveEntities:null,actionEntities:null,isList:!1,entity:null,asType:!1,like:!1,inferred:!1,andChildrenGroup:[],orChildrenGroup:[],parent:g.toReference()},S=C(q,this.project);S.setParent(g,e),S.initChildren(e),e==null||e.add(S,A.Added),S.addSelfToProject(e),G=S}}else{const g={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.ArgumentDeclaration,name:oe.CURRENT_VALUE_ARG_NAME,description:null,defaultValue:null,index:this.body.inputs.length,constant:!0,required:!0,implements:M,writesValues:[],dataType:null,parent:this.body.toReference()},B=C(g,this.project);B.setParent(this.body,e),B.initChildren(e),e==null||e.add(B,A.Added),B.addSelfToProject(e),M&&(!B.implements||B.implements.id!==M.id)&&(B.setImplements(M,e),t.push(B)),i.push(B),this.currentValueArgumentDeclaration=B}break}case ee.ObjectValues:{const P=this.body.inputs.find(g=>{var B;return((B=g.implements)==null?void 0:B.id)===k[n.Loop][ee.ObjectValues].body.inputs.currentValue.id}),V=this.inputs.find(g=>{var B;return((B=g.declaration)==null?void 0:B.id)===k[n.Loop][ee.ObjectValues].inputs.object.id});if(!V)break;const M=this.getCurrentValueBuiltInValueDescriptor();if(P){this.currentValueArgumentDeclaration=P;const g=this.project.get(k[n.Loop][ee.ObjectValues].inputs.object.id);M&&(!P.implements||P.implements.id!==M.id)&&(P.setImplements(M,e),t.push(P));let G=P.getDataType(e);if(G){const q=V.getDataType(e),S=((E=q==null?void 0:q.entity)==null?void 0:E.properties)||[];(I=G.orChildrenGroup)==null||I.forEach(X=>{const{updated:pe,removed:Ee}=X.remove({ignoreUpstream:!1},e);t.push(...pe),s.push(...Ee)}),S.forEach(X=>{if(!X.getDataType(e)){const Ee={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.DataType,options:[],implementationChooseOne:!1,staticEntities:null,interactiveEntities:null,actionEntities:null,isList:!1,entity:null,asType:!1,like:!1,inferred:!1,andChildrenGroup:[],orChildrenGroup:[],parentRelationType:Pt.OrDataTypeGroup,parent:G.toReference()},Q=C(Ee,this.project);Q.setParent(G,e),Q.initChildren(e),e==null||e.add(Q,A.Added),Q.addSelfToProject(e),i.push(Q)}})}else{const q={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.DataType,options:[],implementationChooseOne:!1,parentRelationType:null,staticEntities:null,interactiveEntities:null,actionEntities:null,isList:!1,entity:null,asType:!1,like:!1,inferred:!1,andChildrenGroup:[],orChildrenGroup:[],parent:g.toReference()},S=C(q,this.project);S.setParent(g,e),S.initChildren(e),e==null||e.add(S,A.Added),S.addSelfToProject(e),G=S;const X=V.getDataType(e);(((c=X==null?void 0:X.entity)==null?void 0:c.properties)||[]).forEach(Ee=>{if(!Ee.getDataType(e)){const le={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.DataType,options:[],implementationChooseOne:!1,staticEntities:null,interactiveEntities:null,actionEntities:null,isList:!1,entity:null,asType:!1,like:!1,inferred:!1,andChildrenGroup:[],orChildrenGroup:[],parentRelationType:Pt.OrDataTypeGroup,parent:S.toReference()},ri=C(le,this.project);ri.setParent(S,e),ri.initChildren(e),e==null||e.add(ri,A.Added),ri.addSelfToProject(e),i.push(ri)}})}}else{const g={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.ArgumentDeclaration,name:oe.CURRENT_VALUE_ARG_NAME,description:null,constant:!0,defaultValue:null,index:this.body.inputs.length,required:!0,implements:M,writesValues:[],dataType:null,parent:this.body.toReference()},B=C(g,this.project);B.setParent(this.body,e),B.initChildren(e),e==null||e.add(B,A.Added),B.addSelfToProject(e),M&&(!B.implements||B.implements.id!==M.id)&&(B.setImplements(M,e),t.push(B)),i.push(B),this.currentValueArgumentDeclaration=B}break}case ee.String:{const P=this.body.inputs.find(g=>{var B;return((B=g.implements)==null?void 0:B.id)===k[n.Loop][ee.String].body.inputs.currentValue.id});if(!this.inputs.find(g=>{var B;return((B=g.declaration)==null?void 0:B.id)===k[n.Loop][ee.String].inputs.string.id}))break;const M=this.getCurrentValueBuiltInValueDescriptor();if(P){this.currentValueArgumentDeclaration=P;const g=this.project.get(k[n.Loop]["string-loop"].inputs.string.id);M&&(!P.implements||P.implements.id!==M.id)&&(P.setImplements(M,e),t.push(P));let G=P.getDataType(e);if(G){const q=this.project.getBuiltIn(k["primitive-entity"].string.id);((D=G.entity)==null?void 0:D.id)!==q.id&&(G.setEntity(q),t.push(G))}else{const q={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.DataType,options:[],implementationChooseOne:!1,parentRelationType:null,staticEntities:null,interactiveEntities:null,actionEntities:null,isList:!1,entity:null,asType:!1,like:!1,inferred:!1,andChildrenGroup:[],orChildrenGroup:[],parent:g.toReference()},S=C(q,this.project);S.setParent(g,e),S.initChildren(e),e==null||e.add(S,A.Added),S.addSelfToProject(e),i.push(S),G=S}}else{const g={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.ArgumentDeclaration,name:oe.CURRENT_VALUE_ARG_NAME,description:null,index:this.body.inputs.length,required:!0,constant:!0,defaultValue:null,implements:M,writesValues:[],dataType:null,parent:this.body.toReference()},B=C(g,this.project);B.setParent(this.body,e),B.initChildren(e),e==null||e.add(B,A.Added),B.addSelfToProject(e),M&&(!B.implements||B.implements.id!==M.id)&&(B.setImplements(M,e),t.push(B)),i.push(B),this.currentValueArgumentDeclaration=B}break}}const{updated:o,added:d,removed:u}=this.removeExtraBodyArgumentDeclarations(e);return t.push(...o),i.push(...d),s.push(...u),e==null||e.attemptAutoclose("create-current-value-input-based-on-input-map",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}syncFixedBodyArgumentDeclarations(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-fixed-body-argument-declarations"))){const t=[],i=[],s=[],l=[],{updated:o,added:d,removed:u}=this.createCurrentIterationNumberArgumentDeclaration(e);t.push(...o),i.push(...d),s.push(...u);const{updated:h,added:c,removed:E}=this.createCurrentValueInputBasedOnInputMap(e);return t.push(...h),i.push(...c),s.push(...E),e==null||e.attemptAutoclose("sync-fixed-body-argument-declarations",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}syncInputMaps(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-input-maps"))){const t=[],i=[],s=[],l=[];switch(this.declaration.id){case ee.List:{let o=null;if(this.inputs.forEach(d=>{var u;((u=d.declaration)==null?void 0:u.id)===k[n.Loop]["list-loop"].inputs.list.id?o=d:(d.remove({ignoreUpstream:!1},e),s.push(d))}),o){if(o.declaration.id!==k[n.Loop]["list-loop"].inputs.list.id){const d=this.project.get(k[n.Loop]["list-loop"].inputs.list.id);o.setDeclaration(d),t.push(o)}}else{const d=this.project.get(k[n.Loop]["list-loop"].inputs.list.id),u={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.InputMap,name:null,description:null,index:0,declaration:d.toJSON(),readsValue:null,defaultValue:null,parent:this.toReference()},h=C(u,this.project);h.setParent(this,e),h.initChildren(e),e==null||e.add(h,A.Added),h.addSelfToProject(e),i.push(h)}break}case ee.ManualFlow:{this.inputs.forEach(o=>{o.remove({ignoreUpstream:!1},e),s.push(o)});break}case ee.Counted:{let o=null;if(this.inputs.forEach(d=>{var u;((u=d.declaration)==null?void 0:u.id)===k[n.Loop]["counted-loop"].inputs.number.id?o=d:(d.remove({ignoreUpstream:!1},e),s.push(d))}),o){if(o.declaration.id!==k[n.Loop]["counted-loop"].inputs.number.id){const d=this.project.get(k[n.Loop]["counted-loop"].inputs.number.id);o.setDeclaration(d),t.push(o)}}else{const d=this.project.get(k[n.Loop]["counted-loop"].inputs.number.id),u={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.InputMap,name:null,description:null,index:0,declaration:d.toJSON(),readsValue:null,defaultValue:null,parent:this.toReference()},h=C(u,this.project);h.setParent(this,e),h.initChildren(e),e==null||e.add(h,A.Added),h.addSelfToProject(e),i.push(h)}break}case ee.ObjectKeys:{let o=null;if(this.inputs.forEach(d=>{var u;((u=d.declaration)==null?void 0:u.id)===k[n.Loop]["object-keys-loop"].inputs.object.id?o=d:(d.remove({ignoreUpstream:!1},e),s.push(d))}),o){if(o.declaration.id!==k[n.Loop]["object-keys-loop"].inputs.object.id){const d=this.project.get(k[n.Loop]["object-keys-loop"].inputs.object.id);o.setDeclaration(d),t.push(o)}}else{const d=this.project.get(k[n.Loop]["object-keys-loop"].inputs.object.id),u={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.InputMap,name:null,description:null,index:0,declaration:d.toJSON(),readsValue:null,defaultValue:null,parent:this.toReference()},h=C(u,this.project);h.setParent(this,e),h.initChildren(e),e==null||e.add(h,A.Added),h.addSelfToProject(e),i.push(h)}break}case ee.ObjectValues:{let o=null;if(this.inputs.forEach(d=>{var u;((u=d.declaration)==null?void 0:u.id)===k[n.Loop]["object-values-loop"].inputs.object.id?o=d:(d.remove({ignoreUpstream:!1},e),s.push(d))}),o){if(o.declaration.id!==k[n.Loop]["object-values-loop"].inputs.object.id){const d=this.project.get(k[n.Loop]["object-values-loop"].inputs.object.id);o.setDeclaration(d),t.push(o)}}else{const d=this.project.get(k[n.Loop]["object-values-loop"].inputs.object.id),u={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.InputMap,name:null,description:null,index:0,declaration:d.toJSON(),readsValue:null,defaultValue:null,parent:this.toReference()},h=C(u,this.project);h.setParent(this,e),h.initChildren(e),e==null||e.add(h,A.Added),h.addSelfToProject(e),i.push(h)}break}case ee.String:{let o=null;if(this.inputs.forEach(d=>{var u;((u=d.declaration)==null?void 0:u.id)===k[n.Loop]["string-loop"].inputs.string.id?o=d:(d.remove({ignoreUpstream:!1},e),s.push(d))}),o){if(o.declaration.id!==k[n.Loop]["string-loop"].inputs.string.id){const d=this.project.get(k[n.Loop]["string-loop"].inputs.string.id);o.setDeclaration(d),t.push(o)}}else{const d=this.project.get(k[n.Loop]["string-loop"].inputs.string.id),u={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.InputMap,name:null,description:null,index:0,declaration:d.toJSON(),readsValue:null,defaultValue:null,parent:this.toReference()},h=C(u,this.project);h.setParent(this,e),h.initChildren(e),e==null||e.add(h,A.Added),h.addSelfToProject(e),i.push(h)}break}}return e==null||e.attemptAutoclose("sync-input-maps",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}getCurrentValueBuiltInValueDescriptor(){var t;const e=(t=k[n.Loop][this.declaration.id].body.inputs.currentValue)==null?void 0:t.id;return e?this.project.get(e):null}getCurrentIterationNumberBuiltInValueDescriptor(){const e=k[n.Loop][this.declaration.id].body.inputs.iterationNumber.id;return this.project.get(e)}syncBody(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-body"))){var u;const t=[],i=[],s=[],l=[],o=k[n.Loop][this.declaration.id].body.id,d=this.project.getBuiltIn(o);if(this.body)((u=this.body.implements)==null?void 0:u.id)!==d.id&&(this.body.setImplements(d,e),this.body.setParent(this,e),t.push(this.body));else{const h={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.FunctionDeclaration,name:d.name,description:null,inputs:[],index:null,calls:[],collapsed:!1,private:!1,implements:d.toJSON(),x:0,y:0,parent:this.toReference()},c=C(h,this.project);c.setParent(this,e),c.initChildren(e),e==null||e.add(c,A.Added),c.addSelfToProject(e),i.push(c)}return e==null||e.attemptAutoclose("sync-body",this.id),{self:this,updated:p(t),added:p(i),removed:p(s),affected:p(l)}}syncChildren(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-children"))){const t=[],i=[],s=[],l=[],{updated:o,added:d,removed:u}=this.syncBody(e);t.push(...o),i.push(...d),s.push(...u);const{updated:h,added:c,removed:E}=this.syncInputMaps(e);t.push(...h),i.push(...c),s.push(...E);const{updated:I,added:D,removed:P}=this.syncTerminationStatements(e);t.push(...I),i.push(...D),s.push(...P);const{updated:V,added:M,removed:g}=this.syncBodyArgumentsDeclarations(e);t.push(...V),i.push(...M),s.push(...g);const{updated:B,added:G,removed:q}=this.syncBodyInputIndexes(e);t.push(...B),i.push(...G),s.push(...q);const{updated:S,added:X,removed:pe}=this.syncOutputsDeclarations(e);t.push(...S),i.push(...X),s.push(...pe);const{updated:Ee,added:Q,removed:le}=this.syncOutputMaps(e);return t.push(...Ee),i.push(...Q),s.push(...le),e==null||e.attemptAutoclose("sync-children",this.id),{self:this,updated:p(t),added:p(i),removed:p(s),affected:p(l)}}};f(oe,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>e,APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...i)=>null}),f(oe,"type",n.Loop),f(oe,"USER_MANAGED_PARENT_TYPES",[...ht,n.Project]),f(oe,"PARENT_TYPES",[...We.USER_MANAGED_PARENT_TYPES]),f(oe,"CURRENT_ITERATION_NUMBER_ARG_NAME","Current iteration number"),f(oe,"CURRENT_VALUE_ARG_NAME","Current value"),f(oe,"MUTABLE_BASE_PROPERTIES",[]),f(oe,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),f(oe,"BASE_PROPERTIES",[...oe.MUTABLE_BASE_PROPERTIES,...oe.INMUTABLE_BASE_PROPERTIES]),f(oe,"MUTABLE_META_PROPERTIES",[...oe.MUTABLE_BASE_PROPERTIES,"x","y"]),f(oe,"INMUTABLE_META_PROPERTIES",[...oe.INMUTABLE_BASE_PROPERTIES]),f(oe,"META_PROPERTIES",[...oe.MUTABLE_META_PROPERTIES,...oe.INMUTABLE_META_PROPERTIES]),f(oe,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry"]),f(oe,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","declaration"]),f(oe,"UPSTREAM_PROPERTIES",[...oe.MUTABLE_UPSTREAM_PROPERTIES,...oe.INMUTABLE_UPSTREAM_PROPERTIES]),f(oe,"MUTABLE_DOWNSTREAM_PROPERTIES",["body","inputs","outputs","outputsDeclarations","successCalls","errorCalls","error","breakStatements","continueStatements"]),f(oe,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),f(oe,"DOWNSTREAM_PROPERTIES",[...oe.MUTABLE_DOWNSTREAM_PROPERTIES,...oe.INMUTABLE_DOWNSTREAM_PROPERTIES]),f(oe,"PROPERTIES",[...oe.META_PROPERTIES,...oe.UPSTREAM_PROPERTIES,...oe.DOWNSTREAM_PROPERTIES]);let Wr=oe;function R1(r){const a=J5(),e=r.toJSON();a.safeParse(e).success,r.inputs.forEach(l=>l.validate());const s=[...Ar(r)];return Ke(r.errors,s)}const SJ=Object.freeze(Object.defineProperty({__proto__:null,validate:R1},Symbol.toStringTag,{value:"Module"}));var D1=(r=>(r.Parent="parent",r))(D1||{});const Ze=class Ze extends lt{constructor(e,t){super(e);f(this,"initialData");f(this,"id");f(this,"x");f(this,"y");f(this,"type",n.Condition);f(this,"successCalls",[]);f(this,"errorCalls",[]);f(this,"declaration");f(this,"inputs",[]);f(this,"calledBySuccess",[]);f(this,"calledByError",[]);f(this,"calledByEntry",[]);f(this,"project");f(this,"errors",[]);f(this,"parent");f(this,"detachedDependents",{});f(this,"knownVersions",null);f(this,"activeVersion",!1);f(this,"initialized",!1);f(this,"startedInitialization",!1);this.initialData=e,this.project=t,this.id=e.id,this.x=e.x,this.y=e.y}static new(e=null){return{id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:(e==null?void 0:e.author)||m.sessionAuthor,previousVersion:null,deleted:!1,type:n.Condition,declaration:null,inputs:[],parent:null,calledByEntry:[],calledBySuccess:[],calledByError:[],errorCalls:[],successCalls:[],x:0,y:0}}static fromGenerationTarget(e,t){let i=t;if(e.parent){const c=_(e.parent);i=t.get(c)}const s=e.calledByEntry.map(c=>{const E=_(c);return t.get(E)}),l=e.calledBySuccess.map(c=>{const E=_(c);return t.get(E)}),o=e.calledByError.map(c=>{const E=_(c);return t.get(E)});let d;if(e.declaration){const c=_(e.declaration);d=t.get(c)}const u={id:e.id,version:m.UUID.uuid(),createdAt:T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.Condition,declaration:d,calledByEntry:s,calledBySuccess:l,calledByError:o,errorCalls:[],successCalls:[],inputs:[],x:0,y:0,parent:i},h=C(u,t);return h.setParent(i,null),h.initChildren(null),h}static validateGenerationTarget(e,t){let i=JSON.parse(JSON.stringify(e));const s=[],l=bt(i,{parent:{list:!1,types:[...ht,n.Project],optional:!0}},t);return i=l.modifiedData,s.push(...l.errors,...ut(i)),e.declaration?t.get(e.declaration)?t.conditionDeclarations.find(u=>u.id===e.declaration)||s.push(new w({id:`${e.id}--${R.InvalidImplementsReference}`,code:R.InvalidImplementsReference,severity:O.Error,message:`Entity of type '${e.type}' with id '${e.id}' has an 'declaration' property that isn't pointing to an action descriptor reserved for '${n.Condition}' entities.
100
100
  ${Sl(t)}`,issue:null})):s.push(new w({id:`${e.id}--${R.ReferencedEntityNotFound}`,code:R.ReferencedEntityNotFound,severity:O.Error,message:`Entity of type '${e.type}' with id '${e.id}' has an 'declaration' property that isn't found in the project. The 'declaration' property must point to one of the built-in action descriptors reserved for '${n.Condition}' entities.
101
101
  ${Sl(t)}`,issue:null})):s.push(new w({id:`${e.id}--${$.InvalidObjectStructure}`,code:$.InvalidObjectStructure,severity:O.Error,message:`Entity of type '${e.type}' with id '${e.id}' is missing the 'declaration' property. This property is required for a '${e.type}' entity and must point to one of the built-in action descriptors reserved for '${n.Condition}' entities.
102
102
  ${Sl(t)}`,issue:null})),{errors:s,modifiedData:i}}validateGeneratedUpdate(e){const t=[];return e.parent&&t.push(new w({id:`${this.id}--${R.InvalidParentUpdate}`,code:R.InvalidParentUpdate,severity:O.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elyx-code/project-logic-tree",
3
- "version": "0.0.6258",
3
+ "version": "0.0.6259",
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",