@elyx-code/project-logic-tree 0.0.6669 → 0.0.6670

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.cjs CHANGED
@@ -43,7 +43,7 @@ ${Sb(n)}`})):c.push(new De({id:`${i.id}--${re.ReferencedEntityNotFound}`,code:re
43
43
  ${Sb(n)}`})):c.push(new De({id:`${i.id}--${Ie.InvalidObjectStructure}`,code:Ie.InvalidObjectStructure,severity:ue.Error,message:`Entity of type '${i.type}' with id '${i.id}' is missing the 'declaration' property. This property is required for a '${i.type}' entity and must point to one of the built-in action descriptors reserved for '${o.Condition}' entities.
44
44
  ${Sb(n)}`})),{errors:c,modifiedData:l}}get currentIterationNumberArgumentDeclaration(){var l;const i=(l=Y[o.Loop][this.declaration.id].body.inputs.iterationNumber)==null?void 0:l.id;return this.body.inputs.find(c=>!!c.implements.find(e=>e.id===i)||c.name===Kt.CURRENT_ITERATION_NUMBER_ARG_NAME)}get currentValueArgumentDeclaration(){var l;if(this.declaration.id===st.ManualFlow||this.declaration.id===st.Counted)return null;const i=(l=Y[o.Loop][this.declaration.id].body.inputs.currentValue)==null?void 0:l.id;return this.body.inputs.find(c=>!!c.implements.find(e=>e.id===i)||c.name===Kt.CURRENT_VALUE_ARG_NAME)||null}get continueStatements(){return Rt(this.body).filter(l=>l.type===o.ContinueStatement&&l.parent.id===this.id)}get breakStatements(){return Rt(this.body).filter(l=>l.type===o.BreakStatement&&l.parent.id===this.id)}validateGeneratedUpdate(i){const n=[];return i.parent&&n.push(new De({id:`${this.id}--${re.InvalidParentUpdate}`,code:re.InvalidParentUpdate,severity:ue.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.
45
45
  If an entity is called by another, they must be in the same scope, which means they have the same parent.
46
- You shouldn't have to manually update a 'parent' property. The equivalent result is to change its callers, the value writters of its inputs, or the value readers of its outputs.`})),{errors:n,modifiedData:i}}subscribeDependents(i){return i.forEach(n=>{this.detachedDependents[n.entity.id]||(this.detachedDependents[n.entity.id]=n)}),this}unsubscribeDependents(i){return i.forEach(n=>{this.detachedDependents[n.entity.id]&&delete this.detachedDependents[n.entity.id]}),this}syncDependents(i=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,"sync-dependents"))){const n=[],l=[],c=[],e=[];return Object.values(this.detachedDependents).forEach(y=>{const T=y.entity.afterAllChildrenInitialized(i);n.push(...T.updated),l.push(...T.added),c.push(...T.removed),e.push(...T.affected)}),i==null||i.attemptAutoclose("sync-dependents",this.id),{updated:D(n),added:D(l),removed:D(c),affected:D(e),self:this}}onDetachedDependencyRemoved(i,n,l){const c=[],e=[],y=[],T=[];if(n==="loop-parent-field"){const{updated:v,added:E,removed:b}=this.remove({ignoreUpstream:!1},l);c.push(...v),e.push(...E),y.push(...b)}return{updated:D(c),added:D(e),removed:D(y),affected:D(T),self:this}}onDetachedDependencyRestored(i,n,l){const c=[],e=[],y=[],T=[];if(n==="loop-parent-field"){const{updated:v,added:E,removed:b}=this.restore({},l);c.push(...v),e.push(...E),y.push(...b)}return{updated:D(c),added:D(e),removed:D(y),affected:D(T),self:this}}unsubscribeFromDependencies(){var i,n,l,c,e,y,T,v,E,b,O,_,$;return(i=this.parent)==null||i.unsubscribeDependents([{entity:this,field:"loop-parent-field"}]),(c=(l=(n=this.dataType)==null?void 0:n.entity)==null?void 0:l.unsubscribeDependents)==null||c.call(l,[{entity:this,field:"loop-data-type-entity-field"}]),(y=(e=this.dataType)==null?void 0:e.unsubscribeDependents)==null||y.call(e,[{entity:this,field:"loop-data-type-field"}]),(b=(E=(v=(T=this.body)==null?void 0:T.dataType)==null?void 0:v.entity)==null?void 0:E.unsubscribeDependents)==null||b.call(E,[{entity:this,field:"loop-body-data-type-entity-field"}]),($=(_=(O=this.body)==null?void 0:O.dataType)==null?void 0:_.unsubscribeDependents)==null||$.call(_,[{entity:this,field:"loop-body-data-type-field"}]),this}subscribeToDependencies(){var i,n,l,c,e,y,T,v,E,b,O,_,$;return(i=this.parent)==null||i.subscribeDependents([{entity:this,field:"loop-parent-field"}]),(c=(l=(n=this.dataType)==null?void 0:n.entity)==null?void 0:l.subscribeDependents)==null||c.call(l,[{entity:this,field:"loop-data-type-entity-field"}]),(y=(e=this.dataType)==null?void 0:e.subscribeDependents)==null||y.call(e,[{entity:this,field:"loop-data-type-field"}]),(b=(E=(v=(T=this.body)==null?void 0:T.dataType)==null?void 0:v.entity)==null?void 0:E.subscribeDependents)==null||b.call(E,[{entity:this,field:"loop-body-data-type-entity-field"}]),($=(_=(O=this.body)==null?void 0:O.dataType)==null?void 0:_.subscribeDependents)==null||$.call(_,[{entity:this,field:"loop-body-data-type-field"}]),this}increaseVersion(i){if(i&&!M(i).isValid())throw new Error(`The shared timestamp '${i}' is not a valid ISO 8601 date string.`);return i&&M(i).isSame(M(this.createdAt))?this:(this.previousVersion=this.version,this.version=x.UUID.uuid(),this.createdAt=M(i).toISOString()||M().toISOString(),this)}captureVersion(){var n;const i=((n=this.knownVersions)==null?void 0:n.get(this.version))||new Kt(this,this.project);return i.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,i):new Map([[this.version,i]]),i.inputs=[...this.inputs],i.outputs=[...this.outputs],i.error=this.error,i.successCalls=[...this.successCalls],i.errorCalls=[...this.errorCalls],i.declaration=this.declaration,i.body=this.body,i.calledByEntry=[...this.calledByEntry],i.calledBySuccess=[...this.calledBySuccess],i.calledByError=[...this.calledByError],i.dataType=this.dataType,i.parent=this.parent,this}recursiveCaptureUpstreamVersions(i){const n=[],l=[],c=[],e=[];if(this.parent){this.parent.increaseVersion(i);const y=this.parent.recursiveCaptureUpstreamVersions(i);n.push(this.parent,...y.updated),l.push(...y.added),c.push(...y.removed)}return{updated:D(n),added:D(l),removed:D(c),affected:D(e),self:this}}async restoreVersion(i){var T;const n=[],l=[],c=[],e=[];if(this.version===i)return{updated:D(n),added:D(l),removed:D(c),affected:D(e),self:this};if(!this.knownVersions){const v=new Map;for(const[E,b]of this.knownVersions||new Map){if(v.set(E,b),b.activeVersion=!1,b.knownVersions)for(const[O,_]of b.knownVersions)v.set(O,_);b.knownVersions=null}}let y=(T=this.knownVersions)==null?void 0:T.get(i);if(!y){const v=await this.APILoadVersion({},i);if(!v)throw new Error(`Version with id '${i}' for entity with id '${this.id}' not found.`);y=new Kt(v,this.project)}return this.metaSync(y.toShallowJSON(),null),this.previousVersion=y.previousVersion,this.version=y.version,this.createdAt=y.createdAt,this.author=y.author,this.deleted=y.deleted,this.inputs=y.inputs,this.outputs=y.outputs,this.error=y.error,this.successCalls=y.successCalls,this.errorCalls=y.errorCalls,this.declaration=y.declaration,this.body=y.body,this.calledByEntry=y.calledByEntry,this.calledBySuccess=y.calledBySuccess,this.calledByError=y.calledByError,this.dataType=y.dataType,this.parent=y.parent,{updated:D(n),added:D(l),removed:D(c),affected:D(e),self:this}}updateWithShallowTransfer(i,n=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,P.UpdateWithShallowTransfer))){if(!this.checkCanEdit(this,n))return ie.Logger.warn(`[updateWithShallowTransfer] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),n==null||n.attemptAutoclose(P.UpdateWithShallowTransfer,this.id),this;if(this.metaSync(i,n),this.version=i.version,this.createdAt=i.createdAt,this.author=i.author,this.deleted=i.deleted,this.previousVersion=i.previousVersion,this.unsubscribeFromDependencies(),i.parent){const l=pe(i.parent),c=this.project.get(l),e=this.parent;if(e&&e.id!==(c==null?void 0:c.id)&&this.removeFromParent(n),c)this.setParent(c,n);else throw n==null||n.attemptAutoclose(P.UpdateWithShallowTransfer,this.id),new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw n==null||n.attemptAutoclose(P.UpdateWithShallowTransfer,this.id),new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(i.declaration){const l=pe(i.declaration),c=this.project.get(l);c&&this.setDeclaration(c)}return i.calledByEntry.forEach(l=>{const c=pe(l),e=this.project.get(c);e&&(this.addEntryCaller(e,n),e.addCall(this,n))}),[...this.calledByEntry].forEach(l=>{i.calledByEntry.find(e=>pe(e)===l.id)||(this.removeCaller(l,n),l.removeCall(this,n))}),i.calledBySuccess.forEach(l=>{const c=pe(l),e=this.project.get(c);e&&(this.addSuccessCaller(e,n),e.addSuccessCall(this,n))}),[...this.calledBySuccess].forEach(l=>{i.calledBySuccess.find(e=>pe(e)===l.id)||(this.removeCaller(l,n),l.removeCall(this,n))}),i.calledByError.forEach(l=>{const c=pe(l),e=this.project.get(c);e&&(this.addErrorCaller(e,n),e.addErrorCall(this,n))}),[...this.calledBySuccess].forEach(l=>{i.calledBySuccess.find(e=>pe(e)===l.id)||(this.removeCaller(l,n),l.removeCall(this,n))}),this.captureVersion(),this.subscribeToDependencies(),n==null||n.attemptAutoclose(P.UpdateWithShallowTransfer,this.id),this}hydrateAncestors(){const i=[],n=[],l=[],c=[];if(this.initialData.parent){const e=pe(this.initialData.parent),y=this.project.get(e);if(y)this.setParent(y,null),i.push(y);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${e}' that isn't found in the project`)}else throw new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(this.initialData.declaration){const e=pe(this.initialData.declaration),y=this.project.get(e);y&&(this.setDeclaration(y),i.push(y))}return this.initialData.calledByEntry.forEach(e=>{const y=pe(e),T=this.project.get(y);T&&this.addEntryCaller(T,null)}),this.initialData.calledBySuccess.forEach(e=>{const y=pe(e),T=this.project.get(y);T&&this.addSuccessCaller(T,null)}),this.initialData.calledByError.forEach(e=>{const y=pe(e),T=this.project.get(y);T&&this.addErrorCaller(T,null)}),{updated:D(i),added:D(n),removed:D(l),affected:D(c),self:this}}afterAllChildrenInitialized(i=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,P.AfterAllChildrenInitialized))){if(!this.checkCanEdit(this,i))return ie.Logger.warn(`[afterAllChildrenInitialized] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(P.AfterAllChildrenInitialized,this.id),{updated:[],added:[],removed:[],affected:[],self:this};const n=[],l=[],c=[],e=[];if(this.initialized=!0,this.checkIsSynced())return i==null||i.attemptAutoclose(P.AfterAllChildrenInitialized,this.id),{updated:D(n),added:D(l),removed:D(c),affected:D(e),self:this};const{updated:y,added:T,removed:v}=this.syncChildren(i);return n.push(...y),l.push(...T),c.push(...v),this.inputs.sort((E,b)=>{var O,_;return(E.index??((O=E.declaration)==null?void 0:O.index))-(b.index??((_=b.declaration)==null?void 0:_.index))}),this.outputs.sort((E,b)=>{var O,_;return(E.index??((O=E.declaration)==null?void 0:O.index))-(b.index??((_=b.declaration)==null?void 0:_.index))}),this.captureVersion(),i==null||i.attemptAutoclose(P.AfterAllChildrenInitialized,this.id),{updated:D(n),added:D(l),removed:D(c),affected:D(e),self:this}}addSelfToProject(i=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,"add-self-to-project"))){const n=[this],l=[],c=[],e=[];return this.parent===this.project&&this.project.addLoop(this),this.successCalls.forEach(y=>{y.addSuccessCaller(this,i),n.push(y)}),this.errorCalls.forEach(y=>{y.addErrorCaller(this,i),n.push(y)}),this.calledByEntry.forEach(y=>{y.addCall(this,i),n.push(y)}),this.calledBySuccess.forEach(y=>{y.addSuccessCall(this,i),n.push(y)}),this.calledByError.forEach(y=>{y.addErrorCall(this,i),n.push(y)}),this.subscribe(),this.subscribeToDependencies(),i==null||i.attemptAutoclose("add-self-to-project",this.id),{updated:D(n),added:D(l),removed:D(c),affected:D(e),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}removeInput(i,n=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,P.RemoveInput))){if(!this.checkCanEdit(this,n))return ie.Logger.warn(`[removeInput] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),n==null||n.attemptAutoclose(P.RemoveInput,this.id),this;const l=this.inputs.findIndex(c=>c.id===i.id);return l>-1&&(this.inputs.splice(l,1),n&&(n==null||n.add(this,H.Affected))),n==null||n.attemptAutoclose(P.RemoveInput,this.id),this}addInput(i,n=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,P.AddInput))){return this.checkCanEdit(this,n)?this.inputs.includes(i)?(n==null||n.attemptAutoclose(P.AddInput,this.id),this):(this.inputs.push(i),n==null||n.add(this,H.Affected),n==null||n.attemptAutoclose(P.AddInput,this.id),this):(ie.Logger.warn(`[addInput] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),n==null||n.attemptAutoclose(P.AddInput,this.id),this)}addOutput(i,n=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,"add-output"))){return this.checkCanEdit(this,n)?this.outputs.includes(i)?(n==null||n.attemptAutoclose("add-output",this.id),this):(this.outputs.push(i),n==null||n.add(this,H.Affected),n==null||n.attemptAutoclose("add-output",this.id),this):(ie.Logger.warn(`[addOutput] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),n==null||n.attemptAutoclose("add-output",this.id),this)}removeOutput(i,n=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,"remove-output"))){if(!this.checkCanEdit(this,n))return ie.Logger.warn(`[removeOutput] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),n==null||n.attemptAutoclose("remove-output",this.id),this;const l=this.outputs.findIndex(c=>c.id===i.id);return l>-1&&(this.outputs.splice(l,1),n&&(n==null||n.add(this,H.Affected))),n==null||n.attemptAutoclose("remove-output",this.id),this}setBody(i){return this.body=i,this}detachBody(){return this.body=null,this}addSuccessCaller(i,n=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,P.AddSuccessCaller)),l=!1){return this.checkCanEditWithCounterpartAndSideEffects(this,i,P.AddSuccessCaller,n)?(this.calledBySuccess.find(c=>c.id===i.id)||(this.calledBySuccess.push(i),n==null||n.add(this,H.Updated),l&&ht(this,n)),n==null||n.attemptAutoclose(P.AddSuccessCaller,this.id),this):this}addErrorCaller(i,n=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,P.AddErrorCaller)),l=!1){return this.checkCanEditWithCounterpartAndSideEffects(this,i,P.AddErrorCaller,n)?(this.calledByError.find(c=>c.id===i.id)||(this.calledByError.push(i),n==null||n.add(this,H.Updated),l&&ht(this,n)),n==null||n.attemptAutoclose(P.AddErrorCaller,this.id),this):this}addEntryCaller(i,n=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,P.AddEntryCaller)),l=!1){return this.checkCanEditWithCounterpartAndSideEffects(this,i,P.AddEntryCaller,n)?(this.calledByEntry.find(c=>c.id===i.id)||(this.calledByEntry.push(i),n==null||n.add(this,H.Updated),l&&ht(this,n)),n==null||n.attemptAutoclose(P.AddEntryCaller,this.id),this):this}addErrorCall(i,n=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,P.AddErrorCall)),l=!1){return this.checkCanEditWithCounterpartAndSideEffects(this,i,P.AddErrorCall,n)?(this.errorCalls.find(c=>c.id===i.id)||(this.errorCalls.push(i),l&&ht(this,n),n==null||n.add(this,H.Affected)),n==null||n.attemptAutoclose(P.AddErrorCall,this.id),this):this}addSuccessCall(i,n=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,P.AddSuccessCall)),l=!1){return this.checkCanEditWithCounterpartAndSideEffects(this,i,P.AddSuccessCall,n)?(this.successCalls.find(c=>c.id===i.id)||(this.successCalls.push(i),l&&ht(this,n),n==null||n.add(this,H.Affected)),n==null||n.attemptAutoclose(P.AddSuccessCall,this.id),this):this}removeCall(i,n=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,P.RemoveCall)),l=!1){if(!this.checkCanEditWithCounterpartAndSideEffects(this,i,P.RemoveCall,n))return this;const c=this.successCalls.findIndex(y=>y.id===i.id);c>-1&&(this.successCalls.splice(c,1),n==null||n.add(this,H.Affected));const e=this.errorCalls.findIndex(y=>y.id===i.id);return e>-1&&(this.errorCalls.splice(e,1),n==null||n.add(this,H.Affected)),l&&ht(this,n),n==null||n.attemptAutoclose(P.RemoveCall,this.id),this}removeCaller(i,n=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,"remove-caller")),l=!1){return this.checkCanEditWithCounterpartAndSideEffects(this,i,P.RemoveCaller,n)?(this.calledBySuccess=this.calledBySuccess.filter(c=>c.id!==i.id?!0:(n==null||n.add(this,H.Updated),n==null||n.add(c,H.Affected),!1)),this.calledByError=this.calledByError.filter(c=>c.id!==i.id?!0:(n==null||n.add(this,H.Updated),n==null||n.add(c,H.Affected),!1)),this.calledByEntry=this.calledByEntry.filter(c=>c.id!==i.id?!0:(n==null||n.add(this,H.Updated),n==null||n.add(c,H.Affected),!1)),l&&ht(this,n),n==null||n.attemptAutoclose(P.RemoveCaller,this.id),this):this}replaceDetachedChild(i,n){const l=this.detachedChildren.indexOf(i);return l!==-1&&(this.detachedChildren[l]=n),this}subscribeDetachedChild(i){return this.detachedChildren.includes(i)||this.detachedChildren.push(i),this}unsubscribeDetachedChild(i){const n=this.detachedChildren.indexOf(i);return n!==-1&&this.detachedChildren.splice(n,1),this}setParent(i,n=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,P.SetParent))){var l;return this.checkCanEditWithCounterpartAndSideEffects(this,i,P.SetParent,n)?(((l=this.parent)==null?void 0:l.id)!==(i==null?void 0:i.id)&&(this.parent=i,n&&(n==null||n.add(this,H.Updated))),n==null||n.attemptAutoclose(P.SetParent,this.id),this):this}setDeclaration(i){return this.declaration=i,this}initChildren(i=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,"init-children"))){if(this.initialized||this.startedInitialization)return this;if(this.startedInitialization=!0,this.declaration=he(this.initialData.declaration,this.project),this.initialData.dataType){const n=he(this.initialData.dataType,this.project);this.setDataType(n,null),this.dataType.setParent(this,null),this.dataType.initChildren(i)}return this.successCalls=this.initialData.successCalls.map(n=>{const l=he(n,this.project);if(l.addSuccessCaller(this,null),[o.BreakStatement,o.ContinueStatement].includes(l.type))l.setParent(this.parent.parent,null),l.initChildren(i);else if(l.type===o.ReturnStatement){const c=en(this,this.project);l.setParent(c,null),l.initChildren(i)}else l.type!==o.InternalCall&&(l.setParent(this.parent,null),l.initChildren(i));return l}),this.errorCalls=this.initialData.errorCalls.map(n=>{const l=he(n,this.project);if(l.addErrorCaller(this,null),[o.BreakStatement,o.ContinueStatement].includes(l.type))l.setParent(this.parent.parent,null),l.initChildren(i);else if(l.type===o.ReturnStatement){const c=en(this,this.project);l.setParent(c,null),l.initChildren(i)}else l.type!==o.InternalCall&&(l.setParent(this.parent,null),l.initChildren(i));return l}),this.inputs=this.initialData.inputs.map(n=>{const l=he(n,this.project);return l.setParent(this,null),l.initChildren(i),l}),this.outputs=this.initialData.outputs.map(n=>{const l=he(n,this.project);return l.setParent(this,null),l.initChildren(i),l}),this.initialData.body&&(this.body=he(this.initialData.body,this.project),this.body.setParent(this,null),this.body.initChildren(i)),this.initialData.error&&(this.error=he(this.initialData.error,this.project),this.error.setParent(this,null),this.error.initChildren(i)),this.subscribeToDependencies(),this.afterAllChildrenInitialized(i),i==null||i.attemptAutoclose("init-children",this.id),this}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(i,n=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,"meta-sync"))){const l=$r(this,i,n),c=xr(this,l),e=this.toMeta();return this.x=l.x||e.x,this.y=l.y||e.y,this.catchesError=l.catchesError!==void 0?l.catchesError:this.catchesError,super.baseMetaSync(l,this,n),l.deleted===!0&&!e.deleted?n==null||n.add(this,H.Removed):l.deleted===!1&&e.deleted?n==null||n.add(this,H.Added):c&&(n==null||n.add(this,H.Updated)),n==null||n.attemptAutoclose("meta-sync",this.id),this}async APILoad(i=Ge,...n){return await Kt.repository.APILoad(this.id,...n),this}async APICreate(i=Ge,...n){return await Kt.repository.APICreate(this.toShallowJSON(),...n),this}async APIUpdate(i=Ge,...n){return await Kt.repository.APIUpdate(this.toShallowJSON(),...n),this}async APIDelete(i=Ge,...n){return await Kt.repository.APIDelete(this.toShallowJSON(),...n),this}async APIClone(i=Ge,...n){return await Kt.repository.APIClone(this.id,...n),this}async APILoadVersion(i=Ge,n,...l){return await Kt.repository.APILoadVersion(this.id,n,...l)}removeFromParent(i=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,P.RemoveFromParent))){if(!this.checkCanEdit(this,i))return ie.Logger.warn(`[removeFromParent] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(P.RemoveFromParent,this.id),{added:[],updated:[],removed:[],affected:[],self:this};const n=[],l=[],c=[],e=[];return this.parent.type===o.Project?(this.parent.removeLoop(this),e.push(this.parent)):this.parent.detachedChildren.includes(this)&&this.parent.unsubscribeDetachedChild(this),i==null||i.attemptAutoclose(P.RemoveFromParent,this.id),{added:D(c),updated:D(n),removed:D(l),affected:D(e),self:this}}remove({ignoreUpstream:i}={ignoreUpstream:!1},n=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,P.RemoveEntity))){var T;if(!this.checkCanDelete(this,n))return ie.Logger.warn(`[remove] User is not allowed to delete or edit this ${this.type} entity with id: ${this.id}`),n==null||n.event({id:`${P.RemoveEntity}-${this.id}`,action:P.RemoveEntity,owner:this,errorReason:tr.ActionOwnerEntityNonDeletable,rootAction:((T=n==null?void 0:n.self)==null?void 0:T.id)===this.id&&(n==null?void 0:n.autoCloseActionName)===P.RemoveEntity}),n==null||n.attemptAutoclose(P.RemoveEntity,this.id),{added:[],updated:[],removed:[],affected:[],self:this};const l=[],c=[],e=[],y=[];if(n!=null&&n.hasRemoved(this.id))return n==null||n.attemptAutoclose(P.RemoveEntity,this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(c.push(this),this.unsubscribe(),this.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},n),Object.values(this.detachedDependents).forEach(v=>{const{updated:E,removed:b,added:O}=v.entity.onDetachedDependencyRemoved(this,v.field,n);l.push(...E),c.push(...b),e.push(...O)}),this.inputs.forEach(v=>{const{updated:E,removed:b}=v.remove({ignoreUpstream:!0},n);l.push(...E),c.push(...b)}),this.outputs.forEach(v=>{const{updated:E,removed:b}=v.remove({ignoreUpstream:!0},n);l.push(...E),c.push(...b)}),this.body.remove({ignoreUpstream:!0},n),this.error){const{updated:v,removed:E}=this.error.remove({ignoreUpstream:!0},n);l.push(...v),c.push(...E)}if(this.dataType){const{updated:v,removed:E}=this.dataType.remove({ignoreUpstream:!0},n);l.push(...v),c.push(...E)}if(this.successCalls.forEach(v=>{l.push(v),v.removeCaller(this,n)}),this.errorCalls.forEach(v=>{l.push(v),v.removeCaller(this,n)}),!i){const v=this.removeFromParent(n);e.push(...v.added),l.push(...v.updated),c.push(...v.removed),y.push(...v.affected),this.calledBy.forEach(E=>{l.push(E),E.removeCall(this,n)})}return n==null||n.attemptAutoclose(P.RemoveEntity,this.id),{added:D(e),updated:D(l),removed:D(c),affected:D(y),self:this}}restore({}={},i=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,P.RestoreEntity))){if(!this.checkCanEdit(this,i))return ie.Logger.warn(`[restore] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(P.RestoreEntity,this.id),{added:[],updated:[],removed:[],affected:[],self:this};const n=[],l=[],c=[],e=[];if(i!=null&&i.hasAdded(this.id))return i==null||i.attemptAutoclose(P.RestoreEntity,this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},i),this.inputs.forEach(y=>{const{updated:T}=y.restore({},i);l.push(...T)}),this.outputs.forEach(y=>{const{updated:T}=y.restore({},i);l.push(...T)}),this.body.restore({},i),this.successCalls.forEach(y=>{l.push(y),y.addSuccessCaller(this,i)}),this.errorCalls.forEach(y=>{l.push(y),y.addErrorCaller(this,i)}),this.error){const{updated:y}=this.error.restore({},i);l.push(...y)}if(this.dataType){const{updated:y}=this.dataType.restore({},i);l.push(...y)}return this.calledBySuccess.forEach(y=>{l.push(y),y.addSuccessCall(this,i)}),this.calledByError.forEach(y=>{l.push(y),y.addErrorCall(this,i)}),this.calledByEntry.forEach(y=>{l.push(y),y.addCall(this,i)}),i==null||i.attemptAutoclose(P.RestoreEntity,this.id),{added:D(n),updated:D(l),removed:D(c),affected:D(e),self:this}}toFlat(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this,...this.inputs.flatMap(l=>l.toFlat(i)),...this.outputs.flatMap(l=>l.toFlat(i)),...this.successCalls.flatMap(l=>l.toFlat(i)),...this.errorCalls.flatMap(l=>l.toFlat(i)),...this.error?this.error.toFlat(i):[],...this.body?this.body.toFlat(i):[],...this.dataType?this.dataType.toFlat(i):[],...this.continueStatements.flatMap(l=>l.toFlat(i)),...this.breakStatements.flatMap(l=>l.toFlat(i))])}toFlatIds(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.id,...this.inputs.flatMap(l=>l.toFlatIds(i)),...this.outputs.flatMap(l=>l.toFlatIds(i)),...this.successCalls.flatMap(l=>l.toFlatIds(i)),...this.errorCalls.flatMap(l=>l.toFlatIds(i)),...this.error?this.error.toFlatIds(i):[],...this.body?this.body.toFlatIds(i):[],...this.dataType?this.dataType.toFlatIds(i):[],...this.continueStatements.flatMap(l=>l.toFlatIds(i)),...this.breakStatements.flatMap(l=>l.toFlatIds(i))])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,x:this.x,y:this.y,type:this.type,editable:this.editable,deletable:this.deletable,catchesError:this.catchesError}}toJSON(i=new Set){var n,l;return i.has(this.id)?this.toReference():(i.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,editable:this.editable,deletable:this.deletable,catchesError:this.catchesError,x:this.x,y:this.y,dataType:((n=this.dataType)==null?void 0:n.toJSON(i))||null,calledBySuccess:this.calledBySuccess.map(c=>c.toReference()),calledByError:this.calledByError.map(c=>c.toReference()),calledByEntry:this.calledByEntry.map(c=>c.toReference()),writesValues:this.writesValues.map(c=>c.toJSON(i)),declaration:this.declaration.toJSON(i),inputs:this.inputs.map(c=>c.toJSON(i)),outputs:this.outputs.map(c=>c.toJSON(i)),successCalls:this.successCalls.map(c=>c.toJSON(i)),errorCalls:this.errorCalls.map(c=>c.toJSON(i)),error:((l=this.error)==null?void 0:l.toJSON(i))||null,body:this.body.toJSON(i),parent:this.parent.toReference()})}toJSONClone(i=pt){var l,c,e,y,T,v,E;let n;return(l=i.seenEntityMaps)!=null&&l.has(this.id)?n=i.seenEntityMaps.get(this.id):(n=i.newId||jr(this,this.project,i.uuidStrategy),i.seenEntityMaps&&i.seenEntityMaps.set(this.id,n)),(c=i.seenEntities)!=null&&c.has(n)||(e=i.seenEntities)!=null&&e.has(this.id)?this.toReference({seenEntityMaps:i.seenEntityMaps}):((y=i.seenEntities)==null||y.add(n),(T=i.seenEntities)==null||T.add(this.id),{id:n,version:x.UUID.uuid(),createdAt:i.timestamp||M().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,editable:this.editable,deletable:this.deletable,x:this.x,y:this.y,catchesError:this.catchesError,dataType:((v=this.dataType)==null?void 0:v.toJSONClone({...i,newId:null}))||null,calledBySuccess:this.calledBySuccess.map(b=>b.toReference({seenEntityMaps:i.seenEntityMaps})),calledByError:this.calledByError.map(b=>b.toReference({seenEntityMaps:i.seenEntityMaps})),calledByEntry:this.calledByEntry.map(b=>b.toReference({seenEntityMaps:i.seenEntityMaps})),declaration:this.declaration.toJSON(),inputs:this.inputs.map(b=>b.toJSONClone({...i,newId:null})),outputs:this.outputs.map(b=>b.toJSONClone({...i,newId:null})),writesValues:this.writesValues.map(b=>b.toJSONClone({...i,newId:null})),successCalls:this.successCalls.map(b=>b.toJSONClone({...i,newId:null})),errorCalls:this.errorCalls.map(b=>b.toJSONClone({...i,newId:null})),error:((E=this.error)==null?void 0:E.toJSONClone({...i,newId:null}))||null,body:this.body.toJSONClone({...i,newId:null}),parent:this.parent.toReference({seenEntityMaps:i.seenEntityMaps})})}toReference(i=pt){var l;let n=this.id;return(l=i.seenEntityMaps)!=null&&l.has(this.id)&&(n=i.seenEntityMaps.get(this.id)),{id:n+"--"+x.UUID.uuid()+"--ref",type:o.GenericReference,entityId:n,version:this.version,entityType:this.type}}toShallowJSON(i=pt){var l,c,e,y,T;let n=this.id;return(l=i.seenEntityMaps)!=null&&l.has(this.id)&&(n=i.seenEntityMaps.get(this.id)),{id:n,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,editable:this.editable,deletable:this.deletable,catchesError:this.catchesError,x:this.x,y:this.y,dataType:((c=this.dataType)==null?void 0:c.toReference(i))||null,declaration:((e=this.declaration)==null?void 0:e.toReference(i))||null,body:((y=this.body)==null?void 0:y.toReference(i))||null,inputs:this.inputs.map(v=>v.toReference(i)),outputs:this.outputs.map(v=>v.toReference(i)),writesValues:this.writesValues.map(v=>v.toReference(i)),successCalls:this.successCalls.map(v=>v.toReference(i)),errorCalls:this.errorCalls.map(v=>v.toReference(i)),calledBySuccess:this.calledBySuccess.map(v=>v.toReference(i)),calledByError:this.calledByError.map(v=>v.toReference(i)),calledByEntry:this.calledByEntry.map(v=>v.toReference(i)),error:((T=this.error)==null?void 0:T.toReference(i))||null,parent:this.parent.toReference(i)}}toFlatJSON(i=new Set){var l;return i.has(this.id)?[]:(i.add(this.id),[this.toShallowJSON(),...((l=this.body)==null?void 0:l.toFlatJSON(i))||[],...this.successCalls.flatMap(c=>c.toFlatJSON(i)),...this.errorCalls.flatMap(c=>c.toFlatJSON(i)),...this.inputs.flatMap(c=>c.toFlatJSON(i)),...this.outputs.flatMap(c=>c.toFlatJSON(i)),...this.continueStatements.flatMap(c=>c.toFlatJSON(i)),...this.breakStatements.flatMap(c=>c.toFlatJSON(i)),...this.error?this.error.toFlatJSON(i):[],...this.dataType?this.dataType.toFlatJSON(i):[]])}toGenerationTarget(){const i=this.parent.type===o.Project?void 0:this.parent.id;return{id:this.id,type:this.type,calledByEntry:this.calledByEntry.map(n=>n.id),calledBySuccess:this.calledBySuccess.map(n=>n.id),calledByError:this.calledByError.map(n=>n.id),declaration:this.declaration.id,parent:i}}toFlatGenerationTarget(i=new Set){var l;return i.has(this.id)?[]:(i.add(this.id),[this.toGenerationTarget(),...((l=this.body)==null?void 0:l.toFlatGenerationTarget(i))||[],...this.successCalls.flatMap(c=>c.toFlatGenerationTarget(i)),...this.errorCalls.flatMap(c=>c.toFlatGenerationTarget(i)),...this.inputs.flatMap(c=>c.toFlatGenerationTarget(i)),...this.outputs.flatMap(c=>c.toFlatGenerationTarget(i)),...this.continueStatements.flatMap(c=>c.toFlatGenerationTarget(i)),...this.breakStatements.flatMap(c=>c.toFlatGenerationTarget(i)),...this.error?this.error.toFlatGenerationTarget(i):[],...this.dataType?this.dataType.toFlatGenerationTarget(i):[]])}clearErrors(){var i,n;return this.errors=[],this.inputs.forEach(l=>l.clearErrors()),this.outputs.forEach(l=>l.clearErrors()),this.successCalls.forEach(l=>l.clearErrors()),this.errorCalls.forEach(l=>l.clearErrors()),this.continueStatements.forEach(l=>l.clearErrors()),this.breakStatements.forEach(l=>l.clearErrors()),(i=this.error)==null||i.clearErrors(),(n=this.dataType)==null||n.clearErrors(),this}validate(){const i=HV(this);return this.errors=i,{success:!0}}getErrors(){return[...this.errors,...this.inputs.flatMap(n=>n.getErrors()),...this.outputs.flatMap(n=>n.getErrors()),...this.body?this.body.getErrors():[],...this.error?this.error.getErrors():[],...this.dataType?this.dataType.getErrors():[]]}getShallowErrors(){return this.errors}clone(i=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,P.CloneEntity)),n=null,l=null,c=!0){var $,L;const e=Pr(n,this),y=this.toJSON(),T=l||x.UUID.uuid();y.inputs=[];const v=T.split("-id"),E=v[v.length-1||0]||T;y.id=T,y.version=x.UUID.uuid(),y.createdAt=(i==null?void 0:i.timestamp)||M().toISOString(),y.author=(i==null?void 0:i.author)||"1",y.previousVersion=null,y.deleted=!1,y.deletable=!0,y.editable=!0;const b=Gi(y,e);n?b.setParent(n,i):b.setParent(this.parent,null),c&&b.subscribe(),b.initChildren(i),i==null||i.add(b,H.Added);const O=($=this.inputs)==null?void 0:$.map((U,S)=>U.clone(i,b,E+"-input-map-"+S+"-id",c));b.inputs=O;const _=(L=this.outputs)==null?void 0:L.map((U,S)=>U.clone(i,b,E+"-output-map-"+S+"-id",c));return b.outputs=_,this.body&&(b.body=this.body.clone(i,b,E+"-body-id",c,!0)),this.error&&(b.error=this.error.clone(i,b,E+"-error-map-id",c)),this.dataType&&(b.dataType=this.dataType.clone(i,b,E+"-data-type-id",c)),i==null||i.attemptAutoclose(P.CloneEntity,this.id),b}getVariableInstances(){return this.body?Zi(this.body).filter(l=>l.type===o.VariableInstance):[]}addReturnStatement(i){return zt.includes(this.parent.type)&&this.parent.addReturnStatement(i),this}removeReturnStatement(i){return zt.includes(this.parent.type)&&this.parent.removeReturnStatement(i),this}addBreakStatement(i){return this.breakStatements.includes(i)||this.breakStatements.push(i),this}removeBreakStatement(i){const n=this.breakStatements.indexOf(i);return n!==-1&&this.breakStatements.splice(n,1),this}addContinueStatement(i){return this.continueStatements.includes(i)||this.continueStatements.push(i),this}removeContinueStatement(i){const n=this.continueStatements.indexOf(i);return n!==-1&&this.continueStatements.splice(n,1),this}getUniqueInputMaps(){const i=[];return[...this.breakStatements,...this.continueStatements].forEach(l=>{l.outputs.filter(e=>{var y;return!e.deleted&&!((y=e.declaration)!=null&&y.deleted)}).forEach(e=>{i.find(T=>T===e||se(T,this.project)===se(e,this.project)&&on(T.dataType,e.dataType))||i.push(e)})}),D(i)}syncTerminationStatements(i=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,"sync-termination-statements"))){const n=[],l=[],c=[],e=[],y=this.getUniqueInputMaps();return[...this.breakStatements,...this.continueStatements].forEach(v=>{const E=v.outputs.filter(O=>{var _;return!O.deleted&&!((_=O.declaration)!=null&&_.deleted)}),b=y.filter(O=>!E.find(_=>se(O,this.project)===se(_,this.project)&&on(O.dataType,_.dataType)));b.length&&(n.push(v),i==null||i.add(v,H.Updated)),b.forEach(O=>{const _=O.clone(i,v);i==null||i.add(_,H.Added),_.addSelfToProject(i),l.push(_)})}),i==null||i.attemptAutoclose("sync-termination-statements",this.id),{updated:D(n),added:D(l),removed:D(c),affected:D(e),self:this}}syncBodyInputIndexes(i=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,"sync-body-input-indexes"))){const n=[],l=[],c=[],e=[];return this.body.inputs.sort((y,T)=>y.index-T.index),i==null||i.attemptAutoclose("sync-body-input-indexes",this.id),{updated:D(n),added:D(l),removed:D(c),affected:D(e),self:this}}syncBodyArgumentsDeclarations(i=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,"sync-body-arguments-declarations"))){var L,U,S,Z,X,ae;const n=[],l=[],c=[],e=[],{updated:y,added:T,removed:v}=this.syncFixedBodyArgumentDeclarations(i);n.push(...y),l.push(...T),c.push(...v);const E=this.getUniqueInputMaps(),b=this.body.inputs;if(E.sort((Q,fe)=>Q.index-fe.index),((S=(U=(L=this.body)==null?void 0:L.dataType)==null?void 0:U.entity)==null?void 0:S.id)!==Y["primitive-entity"].void.id&&!b.find(fe=>{var oe,ce,me,ne,ye,_e,Ve;return fe.id!==((oe=this.currentIterationNumberArgumentDeclaration)==null?void 0:oe.id)&&fe.id!==((ce=this.currentValueArgumentDeclaration)==null?void 0:ce.id)&&((ne=(me=fe.dataType)==null?void 0:me.entity)==null?void 0:ne.id)===((Ve=(_e=(ye=this.body)==null?void 0:ye.dataType)==null?void 0:_e.entity)==null?void 0:Ve.id)})){let fe=0;this.currentIterationNumberArgumentDeclaration&&fe++,this.currentValueArgumentDeclaration&&fe++;const oe=ya.new(i);oe.name="Aggregate result",oe.description="Aggretated list of all previously outputted values from each iteration",oe.constant=!0,oe.index=fe,oe.required=!1,oe.parent=this.body.toReference();const ce=he(oe,this.project);if(ce.hydrateAncestors(),ce.addSelfToProject(i),i==null||i.add(ce,H.Added),l.push(ce),ce.setParent(this.body,i),ce.initChildren(i),!ce.dataType&&((Z=this.body)!=null&&Z.dataType)){const me=lr.new(i);me.parent=ce.toReference();const ne=he(me,this.project);ne.hydrateAncestors(),ne.addSelfToProject(i),l.push(ne),ne.setParent(ce,i),ne.initChildren(i),ne.merge((X=this.body)==null?void 0:X.dataType,i),ne.setEntity((ae=this.body)==null?void 0:ae.dataType.entity,i),i==null||i.add(ne,H.Added)}}const{updated:O,added:_,removed:$}=this.removeExtraBodyArgumentDeclarations(i);return n.push(...O),l.push(..._),c.push(...$),i==null||i.attemptAutoclose("sync-body-arguments-declarations",this.id),{updated:D(n),added:D(l),removed:D(c),affected:D(e),self:this}}reAttachAllTerminationInputMapsToDeclarations(i=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,"reattach-termination-input-maps-to-declarations"))){var T,v,E;const n=[],l=[],c=[],e=[];return!((T=this.body)!=null&&T.dataType)||!((v=this.body)!=null&&v.dataType.entity)||((E=this.body)==null?void 0:E.dataType.entity.type)!==o.DefinitionEntity?(i==null||i.attemptAutoclose("reattach-termination-input-maps-to-declarations",this.id),{updated:D(n),added:D(l),removed:D(c),affected:D(e),self:this}):([...this.breakStatements,...this.continueStatements].forEach(b=>{var U,S,Z;const O=b.outputs.filter(X=>{var ae;return!X.deleted&&!((ae=X.declaration)!=null&&ae.deleted)}),_=O.filter(X=>!X.declaration&&!!X.readsValue),$=O.filter(X=>!X.declaration&&!X.readsValue);let L=(((Z=(S=(U=this.body)==null?void 0:U.dataType)==null?void 0:S.entity)==null?void 0:Z.properties)||[]).filter(X=>!O.find(ae=>{var Q,fe;return!ae.deleted&&!((Q=ae.declaration)!=null&&Q.deleted)&&((fe=ae.declaration)==null?void 0:fe.id)===X.id}));_.forEach(X=>{const ae=X.getDataType(i);if(X.readsValue){const Q=se(X.readsValue,this.project),fe=L.find(oe=>se(oe,this.project)===Q&&on(oe.dataType,ae));if(fe){X.setDeclaration(fe,i),n.push(X),L=L.filter(oe=>oe!==fe);return}}}),$.forEach(X=>{const ae=X.getDataType(i),Q=L.find(fe=>on(fe.dataType,ae));if(Q){X.setDeclaration(Q,i),n.push(X),L=L.filter(fe=>fe!==Q);return}}),O.forEach(X=>{const ae=L.find(Q=>se(Q,this.project)===se(X,this.project));X.declaration&&!L.includes(X.declaration)&&ae&&(X.setDeclaration(ae,i),n.push(X),L=L.filter(Q=>Q!==ae))})}),i==null||i.attemptAutoclose("reattach-termination-input-maps-to-declarations",this.id),{updated:D(n),added:D(l),removed:D(c),affected:D(e),self:this})}syncOutputDataType(i=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,"sync-outputs-properties"))){var $,L,U,S,Z,X,ae,Q,fe,oe,ce,me,ne,ye,_e,Ve,Be,xe,Me,We,Se;const n=[],l=[],c=[],e=[],y=[...this.breakStatements,...this.continueStatements];if(!y.every(qe=>qe.initialized))return i==null||i.attemptAutoclose("sync-outputs-properties",this.id),{updated:D(n),added:D(l),removed:D(c),affected:D(e),self:this};if(!(($=this.body)!=null&&$.dataType)){const qe=lr.new(i);qe.parent=this.body.toReference(),qe.inferred=!0;const et=he(qe,this.project);et.hydrateAncestors(),et.addSelfToProject(i),i==null||i.add(et,H.Added),et.initChildren(i),l.push(et)}const T=y.find(qe=>!!qe.readsValue);if(T){const qe=(L=T.readsValue)==null?void 0:L.getDataType(i);qe&&((S=(U=this.body)==null?void 0:U.dataType)==null||S.merge(qe,i))}const v=this.getUniqueInputMaps();let E=(X=(Z=this.body)==null?void 0:Z.dataType)==null?void 0:X.entity;if(v.length&&(!E||E.id===Y["primitive-entity"].void.id)){const qe=ls.new(i);qe.parent=((ae=this.body)==null?void 0:ae.dataType).toReference(),qe.name=`${se(this,this.project)} output definition`,qe.description=`The definition of the output data type of the loop '${se(this,this.project)}'`;const et=he(qe,this.project);et.setParent((Q=this.body)==null?void 0:Q.dataType,i),et.hydrateAncestors(),i==null||i.add(et,H.Added),et.addSelfToProject(i),et.initChildren(i),l.push(et),E=et,(oe=(fe=this.body)==null?void 0:fe.dataType)==null||oe.metaSync({inferred:!0},i)}const b=(E==null?void 0:E.properties)||[];(me=(ce=this.body)==null?void 0:ce.dataType)!=null&&me.inferred&&((ye=(ne=this.body)==null?void 0:ne.dataType.entity)==null?void 0:ye.type)===o.DefinitionEntity&&(v.forEach(qe=>{var Ei,er,br,Aa,vn;const et=qe.getDataType(i);let dt=b.find(Ci=>se(Ci,this.project)===se(qe,this.project)&&on(Ci.dataType,qe.dataType));if(!dt){const Ci=Ma.new(i);Ci.name=se(qe,this.project),Ci.description=`Aggretated list of all previously outputted values from each iteration by the output '${se(qe,this.project)}'`,Ci.index=qe.index,Ci.required=((Ei=qe.declaration)==null?void 0:Ei.required)||!1,Ci.parent=((br=(er=this.body)==null?void 0:er.dataType)==null?void 0:br.entity).toReference();const qi=he(Ci,this.project);qi.hydrateAncestors(),qi.setParent((vn=(Aa=this.body)==null?void 0:Aa.dataType)==null?void 0:vn.entity,i),qi.addSelfToProject(i),i==null||i.add(qi,H.Added),qi.initChildren(i),l.push(qi),dt=qi}dt.index!==qe.index&&(dt.metaSync({index:qe.index},i),n.push(dt));let wt=dt.getDataType(i);if(et)if(!wt||!on(wt,et)){if(!wt){const Ci=et.clone(i,dt);i==null||i.add(Ci,H.Added),Ci.addSelfToProject(i),wt=Ci,l.push(Ci),n.push(dt)}wt.merge(et,i),wt.metaSync({isList:!0},i)}else wt.isList||(wt.metaSync({isList:!0},i),n.push(wt));if(!et&&!wt){const Ci={id:x.UUID.uuid(),version:x.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||M().toISOString(),author:x.sessionAuthor,previousVersion:null,deleted:!1,deletable:!0,editable:!0,type:o.DataType,foreignKeyRef:null,foreignKeyAllowed:null,options:[],implementationChooseOne:!1,staticEntities:null,interactiveEntities:null,index:null,actionEntities:null,parentRelationType:null,isList:!0,entity:null,asType:!1,like:!1,inferred:!1,andChildrenGroup:null,orChildrenGroup:null,parent:dt.toReference()},qi=he(Ci,this.project);qi.metaSync({isList:!0},i),qi.setParent(dt,i),qi.initChildren(i),i==null||i.add(qi,H.Added),qi.addSelfToProject(i),l.push(qi)}}),this.reAttachAllTerminationInputMapsToDeclarations(i)),(Ve=(_e=this.body)==null?void 0:_e.dataType)!=null&&Ve.inferred&&((xe=(Be=this.body)==null?void 0:Be.dataType.entity)==null?void 0:xe.type)===o.DefinitionEntity&&b.filter(et=>!v.find(dt=>se(et,this.project)===se(dt,this.project))).forEach(et=>{if(!(i!=null&&i.hasRemoved(et.id))&&!et.deleted){const{updated:ot,removed:dt}=et.remove({ignoreUpstream:!1},i);n.push(...ot),c.push(...dt)}}),y.forEach(qe=>{qe.outputs.filter(ot=>{var dt;return!ot.deleted&&!((dt=ot.declaration)!=null&&dt.deleted)}).forEach(ot=>{var St,wt,Ei;if(!(((Ei=(wt=(St=this.body)==null?void 0:St.dataType)==null?void 0:wt.entity)==null?void 0:Ei.properties)||[]).find(er=>{var br;return((br=ot.declaration)==null?void 0:br.id)===er.id})&&!(i!=null&&i.hasRemoved(ot.id))&&!ot.deleted){const{updated:er,removed:br}=ot.remove({ignoreUpstream:!1},i);n.push(...er),c.push(...br)}})});const O=this.getUniqueInputMaps();if(y.every(qe=>!qe.readsValue)&&!O.length){const qe=this.project.getBuiltIn(Y["primitive-entity"].void.id);(We=(Me=this.body)==null?void 0:Me.dataType)==null||We.setEntity(qe,i),n.push((Se=this.body)==null?void 0:Se.dataType)}return i==null||i.attemptAutoclose("sync-outputs-properties",this.id),{updated:D(n),added:D(l),removed:D(c),affected:D(e),self:this}}syncOutputMaps(i=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,P.SyncOutputs))){var E,b,O;const n=[],l=[],c=[],e=[],y=((O=(b=(E=this.body)==null?void 0:E.dataType)==null?void 0:b.entity)==null?void 0:O.properties)||[],T=this.outputs;return y.forEach(_=>{var U;let L=T.find(S=>{var Z,X;return((Z=S.declaration)==null?void 0:Z.id)===_.id&&on((X=S.declaration)==null?void 0:X.dataType,_.dataType)});if(L)((U=L.declaration)==null?void 0:U.id)!==_.id&&(L.setDeclaration(_,i),n.push(L));else{const S={id:x.UUID.uuid(),version:x.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||M().toISOString(),author:x.sessionAuthor,previousVersion:null,deleted:!1,deletable:!0,editable:!0,type:o.OutputMap,index:_.index,declaration:_.toJSON(),writesValues:[],parent:this.toReference()},Z=he(S,this.project);Z.setParent(this,i),Z.initChildren(i),i==null||i.add(Z,H.Added),Z.addSelfToProject(i),l.push(Z),L=Z}L.index!==_.index&&(L.metaSync({index:_.index},i),n.push(L))}),T.filter(_=>!y.find(L=>{var U;return((U=_.declaration)==null?void 0:U.id)===L.id})).forEach(_=>{const{updated:$,removed:L}=_.remove({ignoreUpstream:!1},i);n.push(...$),c.push(...L)}),i==null||i.attemptAutoclose(P.SyncOutputs,this.id),{updated:D(n),added:D(l),removed:D(c),affected:D(e),self:this}}createCurrentIterationNumberArgumentDeclaration(i=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,"create-current-iteration-number-argument-declaration"))){const n=[],l=[],c=[],e=[];let T=this.body.inputs.find(O=>{var _;return O.name===Kt.CURRENT_ITERATION_NUMBER_ARG_NAME||O.id===((_=this.currentIterationNumberArgumentDeclaration)==null?void 0:_.id)});const v=this.getCurrentIterationNumberBuiltInValueDescriptor();if(!T){const O={id:x.UUID.uuid(),version:x.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||M().toISOString(),author:x.sessionAuthor,previousVersion:null,deleted:!1,deletable:!0,editable:!0,type:o.ArgumentDeclaration,name:Kt.CURRENT_ITERATION_NUMBER_ARG_NAME,codeName:null,description:"The number of the current iteration",defaultValue:null,constant:!0,dataType:null,implements:[v==null?void 0:v.toJSON()],index:this.body.inputs.length,required:!0,parent:this.body.toReference(),writesValues:[]},_=he(O,this.project);_.setParent(this.body,i),_.initChildren(i),i==null||i.add(_,H.Added),_.addSelfToProject(i),l.push(_),T=_}!T.index&&T.index!==0&&(T.metaSync({index:0},i),n.push(T)),(!T.implements||!T.implements.find(O=>O.id===v.id))&&(T.addImplementation(v,i),n.push(T));let b=T.getDataType(i);if(!b){const O={id:x.UUID.uuid(),version:x.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||M().toISOString(),author:x.sessionAuthor,previousVersion:null,deleted:!1,deletable:!0,editable:!0,type:o.DataType,foreignKeyRef:null,foreignKeyAllowed:null,options:[],implementationChooseOne:!1,staticEntities:null,interactiveEntities:null,actionEntities:null,parentRelationType:null,isList:!1,index:null,entity:null,asType:!1,like:!1,inferred:!1,andChildrenGroup:null,orChildrenGroup:null,parent:T.toReference()},_=he(O,this.project);_.setParent(T,i),_.initChildren(i),i==null||i.add(_,H.Added),_.addSelfToProject(i),l.push(_),b=_}if(!b.entity||b.entity.type!==o.PrimitiveEntity||b.entity.name!==le.Number||b.entity.id!==Y["primitive-entity"].number.id){const O=this.project.getBuiltIn(Y["primitive-entity"].number.id);b.setEntity(O,i),n.push(b)}return i==null||i.attemptAutoclose("create-current-iteration-number-argument-declaration",this.id),{updated:D(n),added:D(l),removed:D(c),affected:D(e),self:this}}removeExtraBodyArgumentDeclarations(i=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,"remove-extra-body-argument-declarations"))){const n=[],l=[],c=[],e=[];return this.body.inputs.filter(v=>{var E,b,O,_,$,L,U,S;return v===this.currentIterationNumberArgumentDeclaration||v===this.currentValueArgumentDeclaration?!1:((O=(b=(E=this.body)==null?void 0:E.dataType)==null?void 0:b.entity)==null?void 0:O.id)===Y["primitive-entity"].void.id?!0:(($=(_=v.dataType)==null?void 0:_.entity)==null?void 0:$.id)!==((S=(U=(L=this.body)==null?void 0:L.dataType)==null?void 0:U.entity)==null?void 0:S.id)}).forEach(v=>{const{updated:E,removed:b}=v.remove({ignoreUpstream:!1},i);n.push(...E),c.push(...b)}),i==null||i.attemptAutoclose("remove-extra-body-argument-declarations",this.id),{updated:D(n),added:D(l),removed:D(c),affected:D(e),self:this}}createCurrentValueInputBasedOnInputMap(i=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,"create-current-value-input-based-on-input-map"))){var E,b,O,_,$,L,U,S,Z;const n=[],l=[],c=[],e=[];switch(this.declaration.id){case st.List:{const X=this.body.inputs.find(fe=>!!fe.implements.find(oe=>oe.id===Y[o.Loop][st.List].body.inputs.currentValue.id)),ae=this.inputs.find(fe=>{var oe;return((oe=fe.declaration)==null?void 0:oe.id)===Y[o.Loop][st.List].inputs.list.id});if(!ae)break;const Q=this.getCurrentValueBuiltInValueDescriptor();if(X){Q&&!X.implements.find(me=>me.id===Q.id)&&(X.addImplementation(Q,i),n.push(X));let oe=X.getDataType(i);if(!oe){const me={id:x.UUID.uuid(),version:x.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||M().toISOString(),author:x.sessionAuthor,previousVersion:null,deleted:!1,deletable:!0,editable:!0,type:o.DataType,foreignKeyRef:null,foreignKeyAllowed:null,options:[],implementationChooseOne:!1,parentRelationType:null,staticEntities:null,interactiveEntities:null,index:null,actionEntities:null,isList:!1,entity:null,asType:!1,like:!1,inferred:!1,andChildrenGroup:null,orChildrenGroup:null,parent:(E=this.currentValueArgumentDeclaration)==null?void 0:E.toReference()},ne=he(me,this.project);ne.setParent(this.currentValueArgumentDeclaration,i),ne.initChildren(i),i==null||i.add(ne,H.Added),ne.addSelfToProject(i),l.push(ne),oe=ne}const ce=ae.getDataType(i);oe.merge(ce,i),oe.metaSync({isList:!1},i)}else{const fe={id:x.UUID.uuid(),version:x.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||M().toISOString(),author:x.sessionAuthor,previousVersion:null,deleted:!1,deletable:!0,editable:!0,type:o.ArgumentDeclaration,name:Kt.CURRENT_VALUE_ARG_NAME,codeName:null,description:null,defaultValue:null,index:this.body.inputs.length,constant:!0,required:!0,implements:[Q],writesValues:[],dataType:null,parent:this.body.toReference()},oe=he(fe,this.project);oe.setParent(this.body,i),oe.initChildren(i),i==null||i.add(oe,H.Added),oe.addSelfToProject(i),Q&&!oe.implements.find(ce=>ce.id===Q.id)&&(oe.addImplementation(Q,i),n.push(oe)),l.push(oe)}break}case st.ManualFlow:break;case st.Counted:break;case st.ObjectKeys:{const X=this.body.inputs.find(fe=>!!fe.implements.find(oe=>oe.id===Y[o.Loop][st.ObjectKeys].body.inputs.currentValue.id));if(!this.inputs.find(fe=>{var oe;return((oe=fe.declaration)==null?void 0:oe.id)===Y[o.Loop][st.ObjectKeys].inputs.object.id}))break;const Q=this.getCurrentValueBuiltInValueDescriptor();if(X){Q&&!X.implements.find(ce=>ce.id===Q.id)&&(X.addImplementation(Q),n.push(X));let oe=X.getDataType(i);if(oe){const ce=this.project.getBuiltIn(Y["primitive-entity"].string.id);((O=oe.entity)==null?void 0:O.id)!==ce.id&&(oe.setEntity(ce,i),n.push(oe))}else{const ce={id:x.UUID.uuid(),version:x.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||M().toISOString(),author:x.sessionAuthor,previousVersion:null,deleted:!1,deletable:!0,editable:!0,type:o.DataType,foreignKeyRef:null,foreignKeyAllowed:null,options:[],implementationChooseOne:!1,parentRelationType:null,staticEntities:null,interactiveEntities:null,index:null,actionEntities:null,isList:!1,entity:null,asType:!1,like:!1,inferred:!1,andChildrenGroup:null,orChildrenGroup:null,parent:(b=this.currentValueArgumentDeclaration)==null?void 0:b.toReference()},me=he(ce,this.project);me.setParent(this.currentValueArgumentDeclaration,i),me.initChildren(i),i==null||i.add(me,H.Added),me.addSelfToProject(i),oe=me}}else{const fe={id:x.UUID.uuid(),version:x.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||M().toISOString(),author:x.sessionAuthor,previousVersion:null,deleted:!1,deletable:!0,editable:!0,type:o.ArgumentDeclaration,name:Kt.CURRENT_VALUE_ARG_NAME,codeName:null,description:null,defaultValue:null,index:this.body.inputs.length,constant:!0,required:!0,implements:[Q],writesValues:[],dataType:null,parent:this.body.toReference()},oe=he(fe,this.project);oe.setParent(this.body,i),oe.initChildren(i),i==null||i.add(oe,H.Added),oe.addSelfToProject(i),Q&&!oe.implements.find(ce=>ce.id===Q.id)&&(oe.addImplementation(Q,i),n.push(oe)),l.push(oe)}break}case st.ObjectValues:{const X=this.body.inputs.find(fe=>!!fe.implements.find(oe=>oe.id===Y[o.Loop][st.ObjectValues].body.inputs.currentValue.id)),ae=this.inputs.find(fe=>{var oe;return((oe=fe.declaration)==null?void 0:oe.id)===Y[o.Loop][st.ObjectValues].inputs.object.id});if(!ae)break;const Q=this.getCurrentValueBuiltInValueDescriptor();if(X){Q&&!X.implements.find(ce=>ce.id===Q.id)&&(X.addImplementation(Q,i),n.push(X));let oe=X.getDataType(i);if(oe){const ce=ae.getDataType(i),me=((L=ce==null?void 0:ce.entity)==null?void 0:L.properties)||[];(U=oe.orChildrenGroup)==null||U.forEach(ne=>{const{updated:ye,removed:_e}=ne.remove({ignoreUpstream:!1},i);n.push(...ye),c.push(..._e)}),me.forEach(ne=>{if(!ne.getDataType(i)){const _e={id:x.UUID.uuid(),version:x.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||M().toISOString(),author:x.sessionAuthor,previousVersion:null,deleted:!1,deletable:!0,editable:!0,type:o.DataType,foreignKeyRef:null,foreignKeyAllowed:null,options:[],implementationChooseOne:!1,staticEntities:null,interactiveEntities:null,actionEntities:null,index:null,isList:!1,entity:null,asType:!1,like:!1,inferred:!1,andChildrenGroup:null,orChildrenGroup:null,parentRelationType:Fe.OrDataTypeGroup,parent:oe.toReference()},Ve=he(_e,this.project);Ve.setParent(oe,i),Ve.initChildren(i),i==null||i.add(Ve,H.Added),Ve.addSelfToProject(i),l.push(Ve)}})}else{const ce={id:x.UUID.uuid(),version:x.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||M().toISOString(),author:x.sessionAuthor,previousVersion:null,deleted:!1,deletable:!0,editable:!0,type:o.DataType,foreignKeyRef:null,foreignKeyAllowed:null,options:[],implementationChooseOne:!1,parentRelationType:null,staticEntities:null,interactiveEntities:null,index:null,actionEntities:null,isList:!1,entity:null,asType:!1,like:!1,inferred:!1,andChildrenGroup:null,orChildrenGroup:null,parent:(_=this.currentValueArgumentDeclaration)==null?void 0:_.toReference()},me=he(ce,this.project);me.setParent(this.currentValueArgumentDeclaration,i),me.initChildren(i),i==null||i.add(me,H.Added),me.addSelfToProject(i),oe=me;const ne=ae.getDataType(i);((($=ne==null?void 0:ne.entity)==null?void 0:$.properties)||[]).forEach(_e=>{if(!_e.getDataType(i)){const Be={id:x.UUID.uuid(),version:x.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||M().toISOString(),author:x.sessionAuthor,previousVersion:null,deleted:!1,deletable:!0,editable:!0,type:o.DataType,foreignKeyRef:null,foreignKeyAllowed:null,options:[],implementationChooseOne:!1,staticEntities:null,interactiveEntities:null,actionEntities:null,index:null,isList:!1,entity:null,asType:!1,like:!1,inferred:!1,andChildrenGroup:null,orChildrenGroup:null,parentRelationType:Fe.OrDataTypeGroup,parent:me.toReference()},xe=he(Be,this.project);xe.setParent(me,i),xe.initChildren(i),i==null||i.add(xe,H.Added),xe.addSelfToProject(i),l.push(xe)}})}}else{const fe={id:x.UUID.uuid(),version:x.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||M().toISOString(),author:x.sessionAuthor,previousVersion:null,deleted:!1,deletable:!0,editable:!0,type:o.ArgumentDeclaration,name:Kt.CURRENT_VALUE_ARG_NAME,codeName:null,description:null,constant:!0,defaultValue:null,index:this.body.inputs.length,required:!0,implements:[Q],writesValues:[],dataType:null,parent:this.body.toReference()},oe=he(fe,this.project);oe.setParent(this.body,i),oe.initChildren(i),i==null||i.add(oe,H.Added),oe.addSelfToProject(i),Q&&!oe.implements.find(ce=>ce.id===Q.id)&&(oe.addImplementation(Q,i),n.push(oe)),l.push(oe)}break}case st.String:{const X=this.body.inputs.find(fe=>!!fe.implements.find(oe=>oe.id===Y[o.Loop][st.String].body.inputs.currentValue.id));if(!this.inputs.find(fe=>{var oe;return((oe=fe.declaration)==null?void 0:oe.id)===Y[o.Loop][st.String].inputs.string.id}))break;const Q=this.getCurrentValueBuiltInValueDescriptor();if(X){Q&&!X.implements.find(ce=>ce.id===Q.id)&&(X.addImplementation(Q,i),n.push(X));let oe=X.getDataType(i);if(oe){const ce=this.project.getBuiltIn(Y["primitive-entity"].string.id);((Z=oe.entity)==null?void 0:Z.id)!==ce.id&&(oe.setEntity(ce,i),n.push(oe))}else{const ce={id:x.UUID.uuid(),version:x.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||M().toISOString(),author:x.sessionAuthor,previousVersion:null,deleted:!1,deletable:!0,editable:!0,type:o.DataType,foreignKeyRef:null,foreignKeyAllowed:null,options:[],implementationChooseOne:!1,parentRelationType:null,staticEntities:null,interactiveEntities:null,index:null,actionEntities:null,isList:!1,entity:null,asType:!1,like:!1,inferred:!1,andChildrenGroup:null,orChildrenGroup:null,parent:(S=this.currentValueArgumentDeclaration)==null?void 0:S.toReference()},me=he(ce,this.project);me.setParent(this.currentValueArgumentDeclaration,i),me.initChildren(i),i==null||i.add(me,H.Added),me.addSelfToProject(i),l.push(me),oe=me}}else{const fe={id:x.UUID.uuid(),version:x.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||M().toISOString(),author:x.sessionAuthor,previousVersion:null,deleted:!1,deletable:!0,editable:!0,type:o.ArgumentDeclaration,name:Kt.CURRENT_VALUE_ARG_NAME,codeName:null,description:null,index:this.body.inputs.length,required:!0,constant:!0,defaultValue:null,implements:[Q],writesValues:[],dataType:null,parent:this.body.toReference()},oe=he(fe,this.project);oe.setParent(this.body,i),oe.initChildren(i),i==null||i.add(oe,H.Added),oe.addSelfToProject(i),Q&&!oe.implements.find(ce=>ce.id===Q.id)&&(oe.addImplementation(Q,i),n.push(oe)),l.push(oe)}break}}const{updated:y,added:T,removed:v}=this.removeExtraBodyArgumentDeclarations(i);return n.push(...y),l.push(...T),c.push(...v),i==null||i.attemptAutoclose("create-current-value-input-based-on-input-map",this.id),{updated:D(n),added:D(l),removed:D(c),affected:D(e),self:this}}syncFixedBodyArgumentDeclarations(i=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,"sync-fixed-body-argument-declarations"))){const n=[],l=[],c=[],e=[],{updated:y,added:T,removed:v}=this.createCurrentIterationNumberArgumentDeclaration(i);n.push(...y),l.push(...T),c.push(...v);const{updated:E,added:b,removed:O}=this.createCurrentValueInputBasedOnInputMap(i);return n.push(...E),l.push(...b),c.push(...O),i==null||i.attemptAutoclose("sync-fixed-body-argument-declarations",this.id),{updated:D(n),added:D(l),removed:D(c),affected:D(e),self:this}}syncInputMaps(i=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,"sync-input-maps"))){const n=[],l=[],c=[],e=[];switch(this.declaration.id){case st.List:{let y=null;if(this.inputs.forEach(T=>{var v;((v=T.declaration)==null?void 0:v.id)===Y[o.Loop]["list-loop"].inputs.list.id?y=T:(T.remove({ignoreUpstream:!1},i),c.push(T))}),y){if(y.declaration.id!==Y[o.Loop]["list-loop"].inputs.list.id){const T=this.project.get(Y[o.Loop]["list-loop"].inputs.list.id);y.setDeclaration(T,i),n.push(y)}}else{const T=this.project.get(Y[o.Loop]["list-loop"].inputs.list.id),v={id:x.UUID.uuid(),version:x.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||M().toISOString(),author:x.sessionAuthor,previousVersion:null,deleted:!1,deletable:!0,editable:!0,type:o.InputMap,parentRelationType:null,name:null,codeName:null,description:null,index:0,declaration:T.toJSON(),readsValue:null,defaultValue:null,parent:this.toReference()},E=he(v,this.project);E.setParent(this,i),E.initChildren(i),i==null||i.add(E,H.Added),E.addSelfToProject(i),l.push(E)}break}case st.ManualFlow:{this.inputs.forEach(y=>{y.remove({ignoreUpstream:!1},i),c.push(y)});break}case st.Counted:{let y=null;if(this.inputs.forEach(T=>{var v;((v=T.declaration)==null?void 0:v.id)===Y[o.Loop]["counted-loop"].inputs.number.id?y=T:(T.remove({ignoreUpstream:!1},i),c.push(T))}),y){if(y.declaration.id!==Y[o.Loop]["counted-loop"].inputs.number.id){const T=this.project.get(Y[o.Loop]["counted-loop"].inputs.number.id);y.setDeclaration(T,i),n.push(y)}}else{const T=this.project.get(Y[o.Loop]["counted-loop"].inputs.number.id),v={id:x.UUID.uuid(),version:x.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||M().toISOString(),author:x.sessionAuthor,previousVersion:null,deleted:!1,deletable:!0,editable:!0,type:o.InputMap,parentRelationType:null,name:null,codeName:null,description:null,index:0,declaration:T.toJSON(),readsValue:null,defaultValue:null,parent:this.toReference()},E=he(v,this.project);E.setParent(this,i),E.initChildren(i),i==null||i.add(E,H.Added),E.addSelfToProject(i),l.push(E)}break}case st.ObjectKeys:{let y=null;if(this.inputs.forEach(T=>{var v;((v=T.declaration)==null?void 0:v.id)===Y[o.Loop]["object-keys-loop"].inputs.object.id?y=T:(T.remove({ignoreUpstream:!1},i),c.push(T))}),y){if(y.declaration.id!==Y[o.Loop]["object-keys-loop"].inputs.object.id){const T=this.project.get(Y[o.Loop]["object-keys-loop"].inputs.object.id);y.setDeclaration(T,i),n.push(y)}}else{const T=this.project.get(Y[o.Loop]["object-keys-loop"].inputs.object.id),v={id:x.UUID.uuid(),version:x.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||M().toISOString(),author:x.sessionAuthor,previousVersion:null,deleted:!1,deletable:!0,editable:!0,type:o.InputMap,parentRelationType:null,name:null,codeName:null,description:null,index:0,declaration:T.toJSON(),readsValue:null,defaultValue:null,parent:this.toReference()},E=he(v,this.project);E.setParent(this,i),E.initChildren(i),i==null||i.add(E,H.Added),E.addSelfToProject(i),l.push(E)}break}case st.ObjectValues:{let y=null;if(this.inputs.forEach(T=>{var v;((v=T.declaration)==null?void 0:v.id)===Y[o.Loop]["object-values-loop"].inputs.object.id?y=T:(T.remove({ignoreUpstream:!1},i),c.push(T))}),y){if(y.declaration.id!==Y[o.Loop]["object-values-loop"].inputs.object.id){const T=this.project.get(Y[o.Loop]["object-values-loop"].inputs.object.id);y.setDeclaration(T,i),n.push(y)}}else{const T=this.project.get(Y[o.Loop]["object-values-loop"].inputs.object.id),v={id:x.UUID.uuid(),version:x.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||M().toISOString(),author:x.sessionAuthor,previousVersion:null,deleted:!1,deletable:!0,editable:!0,type:o.InputMap,parentRelationType:null,name:null,codeName:null,description:null,index:0,declaration:T.toJSON(),readsValue:null,defaultValue:null,parent:this.toReference()},E=he(v,this.project);E.setParent(this,i),E.initChildren(i),i==null||i.add(E,H.Added),E.addSelfToProject(i),l.push(E)}break}case st.String:{let y=null;if(this.inputs.forEach(T=>{var v;((v=T.declaration)==null?void 0:v.id)===Y[o.Loop]["string-loop"].inputs.string.id?y=T:(T.remove({ignoreUpstream:!1},i),c.push(T))}),y){if(y.declaration.id!==Y[o.Loop]["string-loop"].inputs.string.id){const T=this.project.get(Y[o.Loop]["string-loop"].inputs.string.id);y.setDeclaration(T,i),n.push(y)}}else{const T=this.project.get(Y[o.Loop]["string-loop"].inputs.string.id),v={id:x.UUID.uuid(),version:x.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||M().toISOString(),author:x.sessionAuthor,previousVersion:null,deleted:!1,deletable:!0,editable:!0,type:o.InputMap,parentRelationType:null,name:null,codeName:null,description:null,index:0,declaration:T.toJSON(),readsValue:null,defaultValue:null,parent:this.toReference()},E=he(v,this.project);E.setParent(this,i),E.initChildren(i),i==null||i.add(E,H.Added),E.addSelfToProject(i),l.push(E)}break}}return i==null||i.attemptAutoclose("sync-input-maps",this.id),{updated:D(n),added:D(l),removed:D(c),affected:D(e),self:this}}getValueInputMapDeclarationId(){switch(this.declaration.id){case st.List:return Y[o.Loop]["list-loop"].inputs.list.id;case st.ObjectKeys:return Y[o.Loop]["object-keys-loop"].inputs.object.id;case st.ObjectValues:return Y[o.Loop]["object-values-loop"].inputs.object.id;case st.String:return Y[o.Loop]["string-loop"].inputs.string.id;case st.Counted:return Y[o.Loop]["counted-loop"].inputs.number.id;default:return null}}getCurrentValueBuiltInValueDescriptor(){var n;if(this.declaration.id===st.ManualFlow||this.declaration.id===st.Counted)return null;const i=(n=Y[o.Loop][this.declaration.id].body.inputs.currentValue)==null?void 0:n.id;return i?this.project.get(i):null}getCurrentIterationNumberBuiltInValueDescriptor(){const i=Y[o.Loop][this.declaration.id].body.inputs.iterationNumber.id;return this.project.get(i)}syncBody(i=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,"sync-body"))){var v;const n=[],l=[],c=[],e=[],y=Y[o.Loop][this.declaration.id].body.id,T=this.project.getBuiltIn(y);if(this.body)((v=this.body.implements)==null?void 0:v.id)!==T.id&&(this.body.setImplements(T,i),this.body.setParent(this,i),n.push(this.body));else{const E=Ro.new(i);E.implements=T.toJSON(),E.name=T.name,E.parent=this.toReference();const b=he(E,this.project);b.setParent(this,i),b.initChildren(i),i==null||i.add(b,H.Added),b.addSelfToProject(i),l.push(b)}return i==null||i.attemptAutoclose("sync-body",this.id),{self:this,updated:D(n),added:D(l),removed:D(c),affected:D(e)}}checkIsSynced(){var b,O,_,$,L,U,S,Z,X,ae,Q,fe,oe,ce,me,ne,ye,_e,Ve,Be,xe,Me,We,Se,qe;if((!this.body||!((b=this.body)!=null&&b.dataType)||!((O=this.body)!=null&&O.dataType.entity))&&this.id)return!1;const i=[st.List,st.ObjectKeys,st.ObjectValues,st.String],n=this.body.inputs.find(et=>et.implements.find(ot=>ot.id===Y[o.Loop][this.declaration.id].body.inputs.iterationNumber.id))||null,l=this.body.inputs.find(et=>et.implements.find(ot=>{var dt;return ot.id===((dt=Y[o.Loop][this.declaration.id].body.inputs.currentValue)==null?void 0:dt.id)}))||null;if(!n||i.includes(this.declaration.id)&&!l)return!1;const c=[...this.breakStatements,...this.continueStatements];if(((L=($=(_=this.body)==null?void 0:_.dataType)==null?void 0:$.entity)==null?void 0:L.id)!==Y["primitive-entity"].void.id){if(!this.body.inputs.find(ot=>{var dt,St,wt,Ei,er;return((St=(dt=ot.dataType)==null?void 0:dt.entity)==null?void 0:St.id)===((er=(Ei=(wt=this.body)==null?void 0:wt.dataType)==null?void 0:Ei.entity)==null?void 0:er.id)})||((Z=(S=(U=this.body)==null?void 0:U.dataType)==null?void 0:S.entity)==null?void 0:Z.type)===o.DefinitionEntity&&(!((ae=(X=this.body)==null?void 0:X.dataType)==null?void 0:ae.entity).properties.every(St=>this.outputs.find(wt=>{var Ei;return((Ei=wt.declaration)==null?void 0:Ei.id)===St.id}))||!c.every(St=>{var br,Aa;const wt=St.outputs.filter(vn=>!vn.deleted),Ei=((Aa=(br=this.body)==null?void 0:br.dataType)==null?void 0:Aa.entity).properties.every(vn=>wt.find(Ci=>{var qi;return((qi=Ci.declaration)==null?void 0:qi.id)===vn.id})),er=wt.every(vn=>{var Ci,qi;return((qi=(Ci=this.body)==null?void 0:Ci.dataType)==null?void 0:qi.entity).properties.find(Jl=>{var Yl;return Jl.id===((Yl=vn.declaration)==null?void 0:Yl.id)})});return Ei&&er})))return!1}else if(this.body.inputs.find(dt=>{var St,wt,Ei,er,br;return((wt=(St=dt.dataType)==null?void 0:St.entity)==null?void 0:wt.id)===((br=(er=(Ei=this.body)==null?void 0:Ei.dataType)==null?void 0:er.entity)==null?void 0:br.id)})||this.outputs.length>0||![...this.breakStatements,...this.continueStatements].every(dt=>dt.outputs.filter(St=>!St.deleted).length===0))return!1;if([st.List,st.Counted,st.ObjectKeys,st.ObjectValues,st.String].includes(this.declaration.id)){if(this.inputs.length!==1)return!1;const et=this.inputs[0],ot=this.getValueInputMapDeclarationId();if(((Q=et.declaration)==null?void 0:Q.id)!==ot)return!1}else if(this.inputs.length>0)return!1;if((oe=(fe=this.body)==null?void 0:fe.dataType)!=null&&oe.inferred){const et=this.getUniqueInputMaps();if(c.every(wt=>!wt.readsValue)&&!et.length&&((ne=(me=(ce=this.body)==null?void 0:ce.dataType)==null?void 0:me.entity)==null?void 0:ne.id)!==Y["primitive-entity"].void.id)return!1;const dt=c.find(wt=>wt.readsValue),St=(Ve=(_e=(ye=dt==null?void 0:dt.readsValue)==null?void 0:ye.getDataType(null))==null?void 0:_e.entity)==null?void 0:Ve.id;if(St&&St!==((Me=(xe=(Be=this.body)==null?void 0:Be.dataType)==null?void 0:xe.entity)==null?void 0:Me.id))return!1}const y=((qe=(Se=(We=this.body)==null?void 0:We.dataType)==null?void 0:Se.entity)==null?void 0:qe.properties)||[],T=this.outputs,v=y.every(et=>T.find(ot=>{var dt;return((dt=ot.declaration)==null?void 0:dt.id)===et.id})),E=T.every(et=>y.find(ot=>{var dt;return ot.id===((dt=et.declaration)==null?void 0:dt.id)}));return!(!v||!E)}syncFromDataType(i=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,"sync-from-data-type"))){const n=[],l=[],c=[],e=[],{updated:y,added:T,removed:v}=this.syncOutputDataType(i);n.push(...y),l.push(...T),c.push(...v);const{updated:E,added:b,removed:O}=this.syncBodyArgumentsDeclarations(i);n.push(...E),l.push(...b),c.push(...O);const{updated:_,added:$,removed:L}=this.syncBodyInputIndexes(i);n.push(..._),l.push(...$),c.push(...L);const{updated:U,added:S,removed:Z}=this.syncOutputMaps(i);return n.push(...U),l.push(...S),c.push(...Z),i==null||i.attemptAutoclose("sync-from-data-type",this.id),{self:this,updated:D(n),added:D(l),removed:D(c),affected:D(e)}}syncChildren(i=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,"sync-children"))){const n=[],l=[],c=[],e=[],{updated:y,added:T,removed:v}=this.syncBody(i);n.push(...y),l.push(...T),c.push(...v);const{updated:E,added:b,removed:O}=this.syncInputMaps(i);n.push(...E),l.push(...b),c.push(...O);const{updated:_,added:$,removed:L}=this.syncTerminationStatements(i);n.push(..._),l.push(...$),c.push(...L);const{updated:U,added:S,removed:Z}=this.syncFromDataType(i);return n.push(...U),l.push(...S),c.push(...Z),i==null||i.attemptAutoclose("sync-children",this.id),{self:this,updated:D(n),added:D(l),removed:D(c),affected:D(e)}}getUnusedInputs(){return this.inputs.filter(i=>i.suggestion||!i.readsValue&&!i.defaultValue)}getUnusedOutputs(){return this.outputs.filter(i=>i.suggestion||!i.writesValues.length)}getUsedInputs(){return this.inputs.filter(i=>!i.suggestion&&(i.readsValue||i.defaultValue))}getUsedOutputs(){return this.outputs.filter(i=>!i.suggestion&&i.writesValues.length)}addValueReader(i,n=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,P.AddValueReader))){return this.checkCanEditFromScopeOwnerWithSideEffects(this,P.AddValueReader,n)?this.writesValues.includes(i)?(n==null||n.attemptAutoclose(P.AddValueReader,this.id),this):(this.writesValues.push(i),n==null||n.add(this,H.Affected),this):this}setDataType(i,n=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,P.SetDataType))){if(!this.checkCanEdit(this,n))return ie.Logger.warn(`[setDataType] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),n==null||n.attemptAutoclose(P.SetDataType,this.id),this;const l=this.dataType;return(l==null?void 0:l.id)!==(i==null?void 0:i.id)&&(l==null||l.remove({ignoreUpstream:!0},n),this.dataType=i,this.subscribeToDependencies(),n==null||n.add(this,H.Affected)),n==null||n.attemptAutoclose(P.SetDataType,this.id),this}removeValueReader(i,n=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,P.RemoveValueReader))){return this.checkCanEditFromScopeOwnerWithSideEffects(this,P.RemoveValueReader,n)?this.writesValues.includes(i)?(this.writesValues=this.writesValues.filter(l=>l.id!==i.id),n==null||n.add(this,H.Affected),this):(n==null||n.attemptAutoclose(P.RemoveValueReader,this.id),this):this}removeDataType(i=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,P.RemoveDataType))){return this.checkCanEdit(this,i)?(this.dataType&&(this.dataType.remove({ignoreUpstream:!0},i),i==null||i.add(this,H.Affected),this.dataType=null),i==null||i.attemptAutoclose(P.RemoveDataType,this.id),this):(ie.Logger.warn(`[removeDataType] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(P.RemoveDataType,this.id),this)}getDataType(i=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,"get-data-type"))){var n;return i==null||i.attemptAutoclose("get-data-type",this.id),this.dataType||((n=this.body)==null?void 0:n.dataType)||null}};I(Kt,"repository",{APICreate:async(i,...n)=>i,APIUpdate:async(i,...n)=>i,APIDelete:async(i,...n)=>i,APIClone:async(i,...n)=>{},APILoad:async(i,...n)=>null,APILoadVersion:async(i,n,...l)=>null}),I(Kt,"type",o.Loop),I(Kt,"USER_MANAGED_PARENT_TYPES",[...yr,o.Project]),I(Kt,"PARENT_TYPES",[...Pi.USER_MANAGED_PARENT_TYPES]),I(Kt,"CURRENT_ITERATION_NUMBER_ARG_NAME","Current iteration number"),I(Kt,"CURRENT_VALUE_ARG_NAME","Current value"),I(Kt,"MUTABLE_BASE_PROPERTIES",["catchesError"]),I(Kt,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),I(Kt,"BASE_PROPERTIES",[...Kt.MUTABLE_BASE_PROPERTIES,...Kt.INMUTABLE_BASE_PROPERTIES]),I(Kt,"MUTABLE_META_PROPERTIES",[...Kt.MUTABLE_BASE_PROPERTIES,"x","y"]),I(Kt,"INMUTABLE_META_PROPERTIES",[...Kt.INMUTABLE_BASE_PROPERTIES]),I(Kt,"META_PROPERTIES",[...Kt.MUTABLE_META_PROPERTIES,...Kt.INMUTABLE_META_PROPERTIES]),I(Kt,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry"]),I(Kt,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","declaration","dataType"]),I(Kt,"UPSTREAM_PROPERTIES",[...Kt.MUTABLE_UPSTREAM_PROPERTIES,...Kt.INMUTABLE_UPSTREAM_PROPERTIES]),I(Kt,"MUTABLE_DOWNSTREAM_PROPERTIES",["body","inputs","outputs","successCalls","errorCalls","error","breakStatements","continueStatements"]),I(Kt,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),I(Kt,"DOWNSTREAM_PROPERTIES",[...Kt.MUTABLE_DOWNSTREAM_PROPERTIES,...Kt.INMUTABLE_DOWNSTREAM_PROPERTIES]),I(Kt,"PROPERTIES",[...Kt.META_PROPERTIES,...Kt.UPSTREAM_PROPERTIES,...Kt.DOWNSTREAM_PROPERTIES]);let Iu=Kt;function oPe(d){d.inputs.forEach(n=>n.validate());const i=[...qd(d),...Zd(d)];return rr(d.errors,i)}const s$i=Object.freeze(Object.defineProperty({__proto__:null,validate:oPe},Symbol.toStringTag,{value:"Module"}));var dPe=(d=>(d.Parent="parent",d))(dPe||{});const Ai=class Ai extends Ur{constructor(i,n){super(i);I(this,"initialData");I(this,"id");I(this,"x");I(this,"y");I(this,"type",o.Condition);I(this,"index",null);I(this,"successCalls",[]);I(this,"errorCalls",[]);I(this,"declaration");I(this,"inputs",[]);I(this,"calledBySuccess",[]);I(this,"calledByError",[]);I(this,"calledByEntry",[]);I(this,"andChildrenGroup",null);I(this,"orChildrenGroup",null);I(this,"project");I(this,"errors",[]);I(this,"parent");I(this,"detachedDependents",{});I(this,"knownVersions",null);I(this,"activeVersion",!1);I(this,"initialized",!1);I(this,"startedInitialization",!1);this.initialData=i,this.project=n,this.id=i.id,this.x=i.x,this.y=i.y,this.index=i.index??null}static new(i=null){return{id:x.UUID.uuid(),version:x.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||M().toISOString(),author:(i==null?void 0:i.author)||x.sessionAuthor,previousVersion:null,deleted:!1,deletable:!0,editable:!0,type:o.Condition,declaration:null,index:null,inputs:[],parent:null,andChildrenGroup:null,orChildrenGroup:null,calledByEntry:[],calledBySuccess:[],calledByError:[],errorCalls:[],successCalls:[],x:0,y:0}}static fromGenerationTarget(i,n){var O,_;let l=n;if(i.parent){const $=pe(i.parent);l=n.get($)}const c=i.calledByEntry.map($=>{const L=pe($);return n.get(L)}),e=i.calledBySuccess.map($=>{const L=pe($);return n.get(L)}),y=i.calledByError.map($=>{const L=pe($);return n.get(L)});let T;if(i.declaration){const $=pe(i.declaration);T=n.get($)}let v=null;l&&l.type===o.Condition&&(((O=l.declaration)==null?void 0:O.id)===sr.Or?v=(l.orChildrenGroup||[]).length:((_=l.declaration)==null?void 0:_.id)===sr.And&&(v=(l.andChildrenGroup||[]).length));const E={id:i.id,version:x.UUID.uuid(),createdAt:M().toISOString(),author:x.sessionAuthor,previousVersion:null,deleted:!1,deletable:!0,editable:!0,type:o.Condition,index:v,declaration:T,andChildrenGroup:i.andChildrenGroup?i.andChildrenGroup.map($=>{const L=pe($);return n.get(L)}).filter($=>!!$):null,orChildrenGroup:i.orChildrenGroup?i.orChildrenGroup.map($=>{const L=pe($);return n.get(L)}).filter($=>!!$):null,calledByEntry:c,calledBySuccess:e,calledByError:y,errorCalls:[],successCalls:[],inputs:[],x:0,y:0,parent:l},b=he(E,n);return b.setParent(l,null),b}static validateGenerationTarget(i,n){let l=JSON.parse(JSON.stringify(i));const c=[],e=Tn(l,{parent:{list:!1,types:[...yr,o.Project],optional:!0}},n);return l=e.modifiedData,c.push(...e.errors,...Nr(l)),i.declaration?n.get(i.declaration)?n.conditionDeclarations.find(v=>v.id===i.declaration)||c.push(new De({id:`${i.id}--${re.InvalidImplementsReference}`,code:re.InvalidImplementsReference,severity:ue.Error,message:`Entity of type '${i.type}' with id '${i.id}' has an 'declaration' property that isn't pointing to an action descriptor reserved for '${o.Condition}' entities.
46
+ You shouldn't have to manually update a 'parent' property. The equivalent result is to change its callers, the value writters of its inputs, or the value readers of its outputs.`})),{errors:n,modifiedData:i}}subscribeDependents(i){return i.forEach(n=>{this.detachedDependents[n.entity.id]||(this.detachedDependents[n.entity.id]=n)}),this}unsubscribeDependents(i){return i.forEach(n=>{this.detachedDependents[n.entity.id]&&delete this.detachedDependents[n.entity.id]}),this}syncDependents(i=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,"sync-dependents"))){const n=[],l=[],c=[],e=[];return Object.values(this.detachedDependents).forEach(y=>{const T=y.entity.afterAllChildrenInitialized(i);n.push(...T.updated),l.push(...T.added),c.push(...T.removed),e.push(...T.affected)}),i==null||i.attemptAutoclose("sync-dependents",this.id),{updated:D(n),added:D(l),removed:D(c),affected:D(e),self:this}}onDetachedDependencyRemoved(i,n,l){const c=[],e=[],y=[],T=[];if(n==="loop-parent-field"){const{updated:v,added:E,removed:b}=this.remove({ignoreUpstream:!1},l);c.push(...v),e.push(...E),y.push(...b)}return{updated:D(c),added:D(e),removed:D(y),affected:D(T),self:this}}onDetachedDependencyRestored(i,n,l){const c=[],e=[],y=[],T=[];if(n==="loop-parent-field"){const{updated:v,added:E,removed:b}=this.restore({},l);c.push(...v),e.push(...E),y.push(...b)}return{updated:D(c),added:D(e),removed:D(y),affected:D(T),self:this}}unsubscribeFromDependencies(){var i,n,l,c,e,y,T,v,E,b,O,_,$;return(i=this.parent)==null||i.unsubscribeDependents([{entity:this,field:"loop-parent-field"}]),(c=(l=(n=this.dataType)==null?void 0:n.entity)==null?void 0:l.unsubscribeDependents)==null||c.call(l,[{entity:this,field:"loop-data-type-entity-field"}]),(y=(e=this.dataType)==null?void 0:e.unsubscribeDependents)==null||y.call(e,[{entity:this,field:"loop-data-type-field"}]),(b=(E=(v=(T=this.body)==null?void 0:T.dataType)==null?void 0:v.entity)==null?void 0:E.unsubscribeDependents)==null||b.call(E,[{entity:this,field:"loop-body-data-type-entity-field"}]),($=(_=(O=this.body)==null?void 0:O.dataType)==null?void 0:_.unsubscribeDependents)==null||$.call(_,[{entity:this,field:"loop-body-data-type-field"}]),this}subscribeToDependencies(){var i,n,l,c,e,y,T,v,E,b,O,_,$;return(i=this.parent)==null||i.subscribeDependents([{entity:this,field:"loop-parent-field"}]),(c=(l=(n=this.dataType)==null?void 0:n.entity)==null?void 0:l.subscribeDependents)==null||c.call(l,[{entity:this,field:"loop-data-type-entity-field"}]),(y=(e=this.dataType)==null?void 0:e.subscribeDependents)==null||y.call(e,[{entity:this,field:"loop-data-type-field"}]),(b=(E=(v=(T=this.body)==null?void 0:T.dataType)==null?void 0:v.entity)==null?void 0:E.subscribeDependents)==null||b.call(E,[{entity:this,field:"loop-body-data-type-entity-field"}]),($=(_=(O=this.body)==null?void 0:O.dataType)==null?void 0:_.subscribeDependents)==null||$.call(_,[{entity:this,field:"loop-body-data-type-field"}]),this}increaseVersion(i){if(i&&!M(i).isValid())throw new Error(`The shared timestamp '${i}' is not a valid ISO 8601 date string.`);return i&&M(i).isSame(M(this.createdAt))?this:(this.previousVersion=this.version,this.version=x.UUID.uuid(),this.createdAt=M(i).toISOString()||M().toISOString(),this)}captureVersion(){var n;const i=((n=this.knownVersions)==null?void 0:n.get(this.version))||new Kt(this,this.project);return i.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,i):new Map([[this.version,i]]),i.inputs=[...this.inputs],i.outputs=[...this.outputs],i.error=this.error,i.successCalls=[...this.successCalls],i.errorCalls=[...this.errorCalls],i.declaration=this.declaration,i.body=this.body,i.calledByEntry=[...this.calledByEntry],i.calledBySuccess=[...this.calledBySuccess],i.calledByError=[...this.calledByError],i.dataType=this.dataType,i.parent=this.parent,this}recursiveCaptureUpstreamVersions(i){const n=[],l=[],c=[],e=[];if(this.parent){this.parent.increaseVersion(i);const y=this.parent.recursiveCaptureUpstreamVersions(i);n.push(this.parent,...y.updated),l.push(...y.added),c.push(...y.removed)}return{updated:D(n),added:D(l),removed:D(c),affected:D(e),self:this}}async restoreVersion(i){var T;const n=[],l=[],c=[],e=[];if(this.version===i)return{updated:D(n),added:D(l),removed:D(c),affected:D(e),self:this};if(!this.knownVersions){const v=new Map;for(const[E,b]of this.knownVersions||new Map){if(v.set(E,b),b.activeVersion=!1,b.knownVersions)for(const[O,_]of b.knownVersions)v.set(O,_);b.knownVersions=null}}let y=(T=this.knownVersions)==null?void 0:T.get(i);if(!y){const v=await this.APILoadVersion({},i);if(!v)throw new Error(`Version with id '${i}' for entity with id '${this.id}' not found.`);y=new Kt(v,this.project)}return this.metaSync(y.toShallowJSON(),null),this.previousVersion=y.previousVersion,this.version=y.version,this.createdAt=y.createdAt,this.author=y.author,this.deleted=y.deleted,this.inputs=y.inputs,this.outputs=y.outputs,this.error=y.error,this.successCalls=y.successCalls,this.errorCalls=y.errorCalls,this.declaration=y.declaration,this.body=y.body,this.calledByEntry=y.calledByEntry,this.calledBySuccess=y.calledBySuccess,this.calledByError=y.calledByError,this.dataType=y.dataType,this.parent=y.parent,{updated:D(n),added:D(l),removed:D(c),affected:D(e),self:this}}updateWithShallowTransfer(i,n=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,P.UpdateWithShallowTransfer))){if(!this.checkCanEdit(this,n))return ie.Logger.warn(`[updateWithShallowTransfer] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),n==null||n.attemptAutoclose(P.UpdateWithShallowTransfer,this.id),this;if(this.metaSync(i,n),this.version=i.version,this.createdAt=i.createdAt,this.author=i.author,this.deleted=i.deleted,this.previousVersion=i.previousVersion,this.unsubscribeFromDependencies(),i.parent){const l=pe(i.parent),c=this.project.get(l),e=this.parent;if(e&&e.id!==(c==null?void 0:c.id)&&this.removeFromParent(n),c)this.setParent(c,n);else throw n==null||n.attemptAutoclose(P.UpdateWithShallowTransfer,this.id),new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw n==null||n.attemptAutoclose(P.UpdateWithShallowTransfer,this.id),new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(i.declaration){const l=pe(i.declaration),c=this.project.get(l);c&&this.setDeclaration(c)}return i.calledByEntry.forEach(l=>{const c=pe(l),e=this.project.get(c);e&&(this.addEntryCaller(e,n),e.addCall(this,n))}),[...this.calledByEntry].forEach(l=>{i.calledByEntry.find(e=>pe(e)===l.id)||(this.removeCaller(l,n),l.removeCall(this,n))}),i.calledBySuccess.forEach(l=>{const c=pe(l),e=this.project.get(c);e&&(this.addSuccessCaller(e,n),e.addSuccessCall(this,n))}),[...this.calledBySuccess].forEach(l=>{i.calledBySuccess.find(e=>pe(e)===l.id)||(this.removeCaller(l,n),l.removeCall(this,n))}),i.calledByError.forEach(l=>{const c=pe(l),e=this.project.get(c);e&&(this.addErrorCaller(e,n),e.addErrorCall(this,n))}),[...this.calledBySuccess].forEach(l=>{i.calledBySuccess.find(e=>pe(e)===l.id)||(this.removeCaller(l,n),l.removeCall(this,n))}),this.captureVersion(),this.subscribeToDependencies(),n==null||n.attemptAutoclose(P.UpdateWithShallowTransfer,this.id),this}hydrateAncestors(){const i=[],n=[],l=[],c=[];if(this.initialData.parent){const e=pe(this.initialData.parent),y=this.project.get(e);if(y)this.setParent(y,null),i.push(y);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${e}' that isn't found in the project`)}else throw new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(this.initialData.declaration){const e=pe(this.initialData.declaration),y=this.project.get(e);y&&(this.setDeclaration(y),i.push(y))}return this.initialData.calledByEntry.forEach(e=>{const y=pe(e),T=this.project.get(y);T&&this.addEntryCaller(T,null)}),this.initialData.calledBySuccess.forEach(e=>{const y=pe(e),T=this.project.get(y);T&&this.addSuccessCaller(T,null)}),this.initialData.calledByError.forEach(e=>{const y=pe(e),T=this.project.get(y);T&&this.addErrorCaller(T,null)}),{updated:D(i),added:D(n),removed:D(l),affected:D(c),self:this}}afterAllChildrenInitialized(i=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,P.AfterAllChildrenInitialized))){if(!this.checkCanEdit(this,i))return ie.Logger.warn(`[afterAllChildrenInitialized] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(P.AfterAllChildrenInitialized,this.id),{updated:[],added:[],removed:[],affected:[],self:this};const n=[],l=[],c=[],e=[];if(this.initialized=!0,this.checkIsSynced())return i==null||i.attemptAutoclose(P.AfterAllChildrenInitialized,this.id),{updated:D(n),added:D(l),removed:D(c),affected:D(e),self:this};const{updated:y,added:T,removed:v}=this.syncChildren(i);return n.push(...y),l.push(...T),c.push(...v),this.inputs.sort((E,b)=>{var O,_;return(E.index??((O=E.declaration)==null?void 0:O.index))-(b.index??((_=b.declaration)==null?void 0:_.index))}),this.outputs.sort((E,b)=>{var O,_;return(E.index??((O=E.declaration)==null?void 0:O.index))-(b.index??((_=b.declaration)==null?void 0:_.index))}),this.captureVersion(),i==null||i.attemptAutoclose(P.AfterAllChildrenInitialized,this.id),{updated:D(n),added:D(l),removed:D(c),affected:D(e),self:this}}addSelfToProject(i=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,"add-self-to-project"))){const n=[this],l=[],c=[],e=[];return this.parent===this.project&&this.project.addLoop(this),this.successCalls.forEach(y=>{y.addSuccessCaller(this,i),n.push(y)}),this.errorCalls.forEach(y=>{y.addErrorCaller(this,i),n.push(y)}),this.calledByEntry.forEach(y=>{y.addCall(this,i),n.push(y)}),this.calledBySuccess.forEach(y=>{y.addSuccessCall(this,i),n.push(y)}),this.calledByError.forEach(y=>{y.addErrorCall(this,i),n.push(y)}),this.subscribe(),this.subscribeToDependencies(),i==null||i.attemptAutoclose("add-self-to-project",this.id),{updated:D(n),added:D(l),removed:D(c),affected:D(e),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}removeInput(i,n=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,P.RemoveInput))){if(!this.checkCanEdit(this,n))return ie.Logger.warn(`[removeInput] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),n==null||n.attemptAutoclose(P.RemoveInput,this.id),this;const l=this.inputs.findIndex(c=>c.id===i.id);return l>-1&&(this.inputs.splice(l,1),n&&(n==null||n.add(this,H.Affected))),n==null||n.attemptAutoclose(P.RemoveInput,this.id),this}addInput(i,n=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,P.AddInput))){return this.checkCanEdit(this,n)?this.inputs.includes(i)?(n==null||n.attemptAutoclose(P.AddInput,this.id),this):(this.inputs.push(i),n==null||n.add(this,H.Affected),n==null||n.attemptAutoclose(P.AddInput,this.id),this):(ie.Logger.warn(`[addInput] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),n==null||n.attemptAutoclose(P.AddInput,this.id),this)}addOutput(i,n=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,"add-output"))){return this.checkCanEdit(this,n)?this.outputs.includes(i)?(n==null||n.attemptAutoclose("add-output",this.id),this):(this.outputs.push(i),n==null||n.add(this,H.Affected),n==null||n.attemptAutoclose("add-output",this.id),this):(ie.Logger.warn(`[addOutput] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),n==null||n.attemptAutoclose("add-output",this.id),this)}removeOutput(i,n=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,"remove-output"))){if(!this.checkCanEdit(this,n))return ie.Logger.warn(`[removeOutput] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),n==null||n.attemptAutoclose("remove-output",this.id),this;const l=this.outputs.findIndex(c=>c.id===i.id);return l>-1&&(this.outputs.splice(l,1),n&&(n==null||n.add(this,H.Affected))),n==null||n.attemptAutoclose("remove-output",this.id),this}setBody(i){return this.body=i,this}detachBody(){return this.body=null,this}addSuccessCaller(i,n=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,P.AddSuccessCaller)),l=!1){return this.checkCanEditWithCounterpartAndSideEffects(this,i,P.AddSuccessCaller,n)?(this.calledBySuccess.find(c=>c.id===i.id)||(this.calledBySuccess.push(i),n==null||n.add(this,H.Updated),l&&ht(this,n)),n==null||n.attemptAutoclose(P.AddSuccessCaller,this.id),this):this}addErrorCaller(i,n=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,P.AddErrorCaller)),l=!1){return this.checkCanEditWithCounterpartAndSideEffects(this,i,P.AddErrorCaller,n)?(this.calledByError.find(c=>c.id===i.id)||(this.calledByError.push(i),n==null||n.add(this,H.Updated),l&&ht(this,n)),n==null||n.attemptAutoclose(P.AddErrorCaller,this.id),this):this}addEntryCaller(i,n=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,P.AddEntryCaller)),l=!1){return this.checkCanEditWithCounterpartAndSideEffects(this,i,P.AddEntryCaller,n)?(this.calledByEntry.find(c=>c.id===i.id)||(this.calledByEntry.push(i),n==null||n.add(this,H.Updated),l&&ht(this,n)),n==null||n.attemptAutoclose(P.AddEntryCaller,this.id),this):this}addErrorCall(i,n=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,P.AddErrorCall)),l=!1){return this.checkCanEditWithCounterpartAndSideEffects(this,i,P.AddErrorCall,n)?(this.errorCalls.find(c=>c.id===i.id)||(this.errorCalls.push(i),l&&ht(this,n),n==null||n.add(this,H.Affected)),n==null||n.attemptAutoclose(P.AddErrorCall,this.id),this):this}addSuccessCall(i,n=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,P.AddSuccessCall)),l=!1){return this.checkCanEditWithCounterpartAndSideEffects(this,i,P.AddSuccessCall,n)?(this.successCalls.find(c=>c.id===i.id)||(this.successCalls.push(i),l&&ht(this,n),n==null||n.add(this,H.Affected)),n==null||n.attemptAutoclose(P.AddSuccessCall,this.id),this):this}removeCall(i,n=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,P.RemoveCall)),l=!1){if(!this.checkCanEditWithCounterpartAndSideEffects(this,i,P.RemoveCall,n))return this;const c=this.successCalls.findIndex(y=>y.id===i.id);c>-1&&(this.successCalls.splice(c,1),n==null||n.add(this,H.Affected));const e=this.errorCalls.findIndex(y=>y.id===i.id);return e>-1&&(this.errorCalls.splice(e,1),n==null||n.add(this,H.Affected)),l&&ht(this,n),n==null||n.attemptAutoclose(P.RemoveCall,this.id),this}removeCaller(i,n=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,"remove-caller")),l=!1){return this.checkCanEditWithCounterpartAndSideEffects(this,i,P.RemoveCaller,n)?(this.calledBySuccess=this.calledBySuccess.filter(c=>c.id!==i.id?!0:(n==null||n.add(this,H.Updated),n==null||n.add(c,H.Affected),!1)),this.calledByError=this.calledByError.filter(c=>c.id!==i.id?!0:(n==null||n.add(this,H.Updated),n==null||n.add(c,H.Affected),!1)),this.calledByEntry=this.calledByEntry.filter(c=>c.id!==i.id?!0:(n==null||n.add(this,H.Updated),n==null||n.add(c,H.Affected),!1)),l&&ht(this,n),n==null||n.attemptAutoclose(P.RemoveCaller,this.id),this):this}replaceDetachedChild(i,n){const l=this.detachedChildren.indexOf(i);return l!==-1&&(this.detachedChildren[l]=n),this}subscribeDetachedChild(i){return this.detachedChildren.includes(i)||this.detachedChildren.push(i),this}unsubscribeDetachedChild(i){const n=this.detachedChildren.indexOf(i);return n!==-1&&this.detachedChildren.splice(n,1),this}setParent(i,n=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,P.SetParent))){var l;return this.checkCanEditWithCounterpartAndSideEffects(this,i,P.SetParent,n)?(((l=this.parent)==null?void 0:l.id)!==(i==null?void 0:i.id)&&(this.parent=i,n&&(n==null||n.add(this,H.Updated))),n==null||n.attemptAutoclose(P.SetParent,this.id),this):this}setDeclaration(i){return this.declaration=i,this}initChildren(i=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,"init-children"))){if(this.initialized||this.startedInitialization)return this;if(this.startedInitialization=!0,this.declaration=he(this.initialData.declaration,this.project),this.initialData.dataType){const n=he(this.initialData.dataType,this.project);this.setDataType(n,null),this.dataType.setParent(this,null),this.dataType.initChildren(i)}return this.successCalls=this.initialData.successCalls.map(n=>{const l=he(n,this.project);if(l.addSuccessCaller(this,null),[o.BreakStatement,o.ContinueStatement].includes(l.type))l.setParent(this.parent.parent,null),l.initChildren(i);else if(l.type===o.ReturnStatement){const c=en(this,this.project);l.setParent(c,null),l.initChildren(i)}else l.type!==o.InternalCall&&(l.setParent(this.parent,null),l.initChildren(i));return l}),this.errorCalls=this.initialData.errorCalls.map(n=>{const l=he(n,this.project);if(l.addErrorCaller(this,null),[o.BreakStatement,o.ContinueStatement].includes(l.type))l.setParent(this.parent.parent,null),l.initChildren(i);else if(l.type===o.ReturnStatement){const c=en(this,this.project);l.setParent(c,null),l.initChildren(i)}else l.type!==o.InternalCall&&(l.setParent(this.parent,null),l.initChildren(i));return l}),this.inputs=this.initialData.inputs.map(n=>{const l=he(n,this.project);return l.setParent(this,null),l.initChildren(i),l}),this.outputs=this.initialData.outputs.map(n=>{const l=he(n,this.project);return l.setParent(this,null),l.initChildren(i),l}),this.initialData.body&&(this.body=he(this.initialData.body,this.project),this.body.setParent(this,null),this.body.initChildren(i)),this.initialData.error&&(this.error=he(this.initialData.error,this.project),this.error.setParent(this,null),this.error.initChildren(i)),this.subscribeToDependencies(),this.afterAllChildrenInitialized(i),i==null||i.attemptAutoclose("init-children",this.id),this}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(i,n=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,"meta-sync"))){const l=$r(this,i,n),c=xr(this,l),e=this.toMeta();return this.x=l.x||e.x,this.y=l.y||e.y,this.catchesError=l.catchesError!==void 0?l.catchesError:this.catchesError,super.baseMetaSync(l,this,n),l.deleted===!0&&!e.deleted?n==null||n.add(this,H.Removed):l.deleted===!1&&e.deleted?n==null||n.add(this,H.Added):c&&(n==null||n.add(this,H.Updated)),n==null||n.attemptAutoclose("meta-sync",this.id),this}async APILoad(i=Ge,...n){return await Kt.repository.APILoad(this.id,...n),this}async APICreate(i=Ge,...n){return await Kt.repository.APICreate(this.toShallowJSON(),...n),this}async APIUpdate(i=Ge,...n){return await Kt.repository.APIUpdate(this.toShallowJSON(),...n),this}async APIDelete(i=Ge,...n){return await Kt.repository.APIDelete(this.toShallowJSON(),...n),this}async APIClone(i=Ge,...n){return await Kt.repository.APIClone(this.id,...n),this}async APILoadVersion(i=Ge,n,...l){return await Kt.repository.APILoadVersion(this.id,n,...l)}removeFromParent(i=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,P.RemoveFromParent))){if(!this.checkCanEdit(this,i))return ie.Logger.warn(`[removeFromParent] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(P.RemoveFromParent,this.id),{added:[],updated:[],removed:[],affected:[],self:this};const n=[],l=[],c=[],e=[];return this.parent.type===o.Project?(this.parent.removeLoop(this),e.push(this.parent)):this.parent.detachedChildren.includes(this)&&this.parent.unsubscribeDetachedChild(this),i==null||i.attemptAutoclose(P.RemoveFromParent,this.id),{added:D(c),updated:D(n),removed:D(l),affected:D(e),self:this}}remove({ignoreUpstream:i}={ignoreUpstream:!1},n=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,P.RemoveEntity))){var T;if(!this.checkCanDelete(this,n))return ie.Logger.warn(`[remove] User is not allowed to delete or edit this ${this.type} entity with id: ${this.id}`),n==null||n.event({id:`${P.RemoveEntity}-${this.id}`,action:P.RemoveEntity,owner:this,errorReason:tr.ActionOwnerEntityNonDeletable,rootAction:((T=n==null?void 0:n.self)==null?void 0:T.id)===this.id&&(n==null?void 0:n.autoCloseActionName)===P.RemoveEntity}),n==null||n.attemptAutoclose(P.RemoveEntity,this.id),{added:[],updated:[],removed:[],affected:[],self:this};const l=[],c=[],e=[],y=[];if(n!=null&&n.hasRemoved(this.id))return n==null||n.attemptAutoclose(P.RemoveEntity,this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(c.push(this),this.unsubscribe(),this.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},n),Object.values(this.detachedDependents).forEach(v=>{const{updated:E,removed:b,added:O}=v.entity.onDetachedDependencyRemoved(this,v.field,n);l.push(...E),c.push(...b),e.push(...O)}),this.inputs.forEach(v=>{const{updated:E,removed:b}=v.remove({ignoreUpstream:!0},n);l.push(...E),c.push(...b)}),this.outputs.forEach(v=>{const{updated:E,removed:b}=v.remove({ignoreUpstream:!0},n);l.push(...E),c.push(...b)}),this.body.remove({ignoreUpstream:!0},n),this.error){const{updated:v,removed:E}=this.error.remove({ignoreUpstream:!0},n);l.push(...v),c.push(...E)}if(this.dataType){const{updated:v,removed:E}=this.dataType.remove({ignoreUpstream:!0},n);l.push(...v),c.push(...E)}if(this.successCalls.forEach(v=>{l.push(v),v.removeCaller(this,n)}),this.errorCalls.forEach(v=>{l.push(v),v.removeCaller(this,n)}),!i){const v=this.removeFromParent(n);e.push(...v.added),l.push(...v.updated),c.push(...v.removed),y.push(...v.affected),this.calledBy.forEach(E=>{l.push(E),E.removeCall(this,n)})}return n==null||n.attemptAutoclose(P.RemoveEntity,this.id),{added:D(e),updated:D(l),removed:D(c),affected:D(y),self:this}}restore({}={},i=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,P.RestoreEntity))){if(!this.checkCanEdit(this,i))return ie.Logger.warn(`[restore] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(P.RestoreEntity,this.id),{added:[],updated:[],removed:[],affected:[],self:this};const n=[],l=[],c=[],e=[];if(i!=null&&i.hasAdded(this.id))return i==null||i.attemptAutoclose(P.RestoreEntity,this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},i),this.inputs.forEach(y=>{const{updated:T}=y.restore({},i);l.push(...T)}),this.outputs.forEach(y=>{const{updated:T}=y.restore({},i);l.push(...T)}),this.body.restore({},i),this.successCalls.forEach(y=>{l.push(y),y.addSuccessCaller(this,i)}),this.errorCalls.forEach(y=>{l.push(y),y.addErrorCaller(this,i)}),this.error){const{updated:y}=this.error.restore({},i);l.push(...y)}if(this.dataType){const{updated:y}=this.dataType.restore({},i);l.push(...y)}return this.calledBySuccess.forEach(y=>{l.push(y),y.addSuccessCall(this,i)}),this.calledByError.forEach(y=>{l.push(y),y.addErrorCall(this,i)}),this.calledByEntry.forEach(y=>{l.push(y),y.addCall(this,i)}),i==null||i.attemptAutoclose(P.RestoreEntity,this.id),{added:D(n),updated:D(l),removed:D(c),affected:D(e),self:this}}toFlat(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this,...this.inputs.flatMap(l=>l.toFlat(i)),...this.outputs.flatMap(l=>l.toFlat(i)),...this.successCalls.flatMap(l=>l.toFlat(i)),...this.errorCalls.flatMap(l=>l.toFlat(i)),...this.error?this.error.toFlat(i):[],...this.body?this.body.toFlat(i):[],...this.dataType?this.dataType.toFlat(i):[],...this.continueStatements.flatMap(l=>l.toFlat(i)),...this.breakStatements.flatMap(l=>l.toFlat(i))])}toFlatIds(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.id,...this.inputs.flatMap(l=>l.toFlatIds(i)),...this.outputs.flatMap(l=>l.toFlatIds(i)),...this.successCalls.flatMap(l=>l.toFlatIds(i)),...this.errorCalls.flatMap(l=>l.toFlatIds(i)),...this.error?this.error.toFlatIds(i):[],...this.body?this.body.toFlatIds(i):[],...this.dataType?this.dataType.toFlatIds(i):[],...this.continueStatements.flatMap(l=>l.toFlatIds(i)),...this.breakStatements.flatMap(l=>l.toFlatIds(i))])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,x:this.x,y:this.y,type:this.type,editable:this.editable,deletable:this.deletable,catchesError:this.catchesError}}toJSON(i=new Set){var n,l;return i.has(this.id)?this.toReference():(i.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,editable:this.editable,deletable:this.deletable,catchesError:this.catchesError,x:this.x,y:this.y,dataType:((n=this.dataType)==null?void 0:n.toJSON(i))||null,calledBySuccess:this.calledBySuccess.map(c=>c.toReference()),calledByError:this.calledByError.map(c=>c.toReference()),calledByEntry:this.calledByEntry.map(c=>c.toReference()),writesValues:this.writesValues.map(c=>c.toJSON(i)),declaration:this.declaration.toJSON(i),inputs:this.inputs.map(c=>c.toJSON(i)),outputs:this.outputs.map(c=>c.toJSON(i)),successCalls:this.successCalls.map(c=>c.toJSON(i)),errorCalls:this.errorCalls.map(c=>c.toJSON(i)),error:((l=this.error)==null?void 0:l.toJSON(i))||null,body:this.body.toJSON(i),parent:this.parent.toReference()})}toJSONClone(i=pt){var l,c,e,y,T,v,E;let n;return(l=i.seenEntityMaps)!=null&&l.has(this.id)?n=i.seenEntityMaps.get(this.id):(n=i.newId||jr(this,this.project,i.uuidStrategy),i.seenEntityMaps&&i.seenEntityMaps.set(this.id,n)),(c=i.seenEntities)!=null&&c.has(n)||(e=i.seenEntities)!=null&&e.has(this.id)?this.toReference({seenEntityMaps:i.seenEntityMaps}):((y=i.seenEntities)==null||y.add(n),(T=i.seenEntities)==null||T.add(this.id),{id:n,version:x.UUID.uuid(),createdAt:i.timestamp||M().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,editable:this.editable,deletable:this.deletable,x:this.x,y:this.y,catchesError:this.catchesError,dataType:((v=this.dataType)==null?void 0:v.toJSONClone({...i,newId:null}))||null,calledBySuccess:this.calledBySuccess.map(b=>b.toReference({seenEntityMaps:i.seenEntityMaps})),calledByError:this.calledByError.map(b=>b.toReference({seenEntityMaps:i.seenEntityMaps})),calledByEntry:this.calledByEntry.map(b=>b.toReference({seenEntityMaps:i.seenEntityMaps})),declaration:this.declaration.toJSON(),inputs:this.inputs.map(b=>b.toJSONClone({...i,newId:null})),outputs:this.outputs.map(b=>b.toJSONClone({...i,newId:null})),writesValues:this.writesValues.map(b=>b.toJSONClone({...i,newId:null})),successCalls:this.successCalls.map(b=>b.toJSONClone({...i,newId:null})),errorCalls:this.errorCalls.map(b=>b.toJSONClone({...i,newId:null})),error:((E=this.error)==null?void 0:E.toJSONClone({...i,newId:null}))||null,body:this.body.toJSONClone({...i,newId:null}),parent:this.parent.toReference({seenEntityMaps:i.seenEntityMaps})})}toReference(i=pt){var l;let n=this.id;return(l=i.seenEntityMaps)!=null&&l.has(this.id)&&(n=i.seenEntityMaps.get(this.id)),{id:n+"--"+x.UUID.uuid()+"--ref",type:o.GenericReference,entityId:n,version:this.version,entityType:this.type}}toShallowJSON(i=pt){var l,c,e,y,T;let n=this.id;return(l=i.seenEntityMaps)!=null&&l.has(this.id)&&(n=i.seenEntityMaps.get(this.id)),{id:n,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,editable:this.editable,deletable:this.deletable,catchesError:this.catchesError,x:this.x,y:this.y,dataType:((c=this.dataType)==null?void 0:c.toReference(i))||null,declaration:((e=this.declaration)==null?void 0:e.toReference(i))||null,body:((y=this.body)==null?void 0:y.toReference(i))||null,inputs:this.inputs.map(v=>v.toReference(i)),outputs:this.outputs.map(v=>v.toReference(i)),writesValues:this.writesValues.map(v=>v.toReference(i)),successCalls:this.successCalls.map(v=>v.toReference(i)),errorCalls:this.errorCalls.map(v=>v.toReference(i)),calledBySuccess:this.calledBySuccess.map(v=>v.toReference(i)),calledByError:this.calledByError.map(v=>v.toReference(i)),calledByEntry:this.calledByEntry.map(v=>v.toReference(i)),error:((T=this.error)==null?void 0:T.toReference(i))||null,parent:this.parent.toReference(i)}}toFlatJSON(i=new Set){var l;return i.has(this.id)?[]:(i.add(this.id),[this.toShallowJSON(),...((l=this.body)==null?void 0:l.toFlatJSON(i))||[],...this.successCalls.flatMap(c=>c.toFlatJSON(i)),...this.errorCalls.flatMap(c=>c.toFlatJSON(i)),...this.inputs.flatMap(c=>c.toFlatJSON(i)),...this.outputs.flatMap(c=>c.toFlatJSON(i)),...this.continueStatements.flatMap(c=>c.toFlatJSON(i)),...this.breakStatements.flatMap(c=>c.toFlatJSON(i)),...this.error?this.error.toFlatJSON(i):[],...this.dataType?this.dataType.toFlatJSON(i):[]])}toGenerationTarget(){const i=this.parent.type===o.Project?void 0:this.parent.id;return{id:this.id,type:this.type,calledByEntry:this.calledByEntry.map(n=>n.id),calledBySuccess:this.calledBySuccess.map(n=>n.id),calledByError:this.calledByError.map(n=>n.id),declaration:this.declaration.id,parent:i}}toFlatGenerationTarget(i=new Set){var l;return i.has(this.id)?[]:(i.add(this.id),[this.toGenerationTarget(),...((l=this.body)==null?void 0:l.toFlatGenerationTarget(i))||[],...this.successCalls.flatMap(c=>c.toFlatGenerationTarget(i)),...this.errorCalls.flatMap(c=>c.toFlatGenerationTarget(i)),...this.inputs.flatMap(c=>c.toFlatGenerationTarget(i)),...this.outputs.flatMap(c=>c.toFlatGenerationTarget(i)),...this.continueStatements.flatMap(c=>c.toFlatGenerationTarget(i)),...this.breakStatements.flatMap(c=>c.toFlatGenerationTarget(i)),...this.error?this.error.toFlatGenerationTarget(i):[],...this.dataType?this.dataType.toFlatGenerationTarget(i):[]])}clearErrors(){var i,n;return this.errors=[],this.inputs.forEach(l=>l.clearErrors()),this.outputs.forEach(l=>l.clearErrors()),this.successCalls.forEach(l=>l.clearErrors()),this.errorCalls.forEach(l=>l.clearErrors()),this.continueStatements.forEach(l=>l.clearErrors()),this.breakStatements.forEach(l=>l.clearErrors()),(i=this.error)==null||i.clearErrors(),(n=this.dataType)==null||n.clearErrors(),this}validate(){const i=HV(this);return this.errors=i,{success:!0}}getErrors(){return[...this.errors,...this.inputs.flatMap(n=>n.getErrors()),...this.outputs.flatMap(n=>n.getErrors()),...this.body?this.body.getErrors():[],...this.error?this.error.getErrors():[],...this.dataType?this.dataType.getErrors():[]]}getShallowErrors(){return this.errors}clone(i=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,P.CloneEntity)),n=null,l=null,c=!0){var $,L;const e=Pr(n,this),y=this.toJSON(),T=l||x.UUID.uuid();y.inputs=[];const v=T.split("-id"),E=v[v.length-1||0]||T;y.id=T,y.version=x.UUID.uuid(),y.createdAt=(i==null?void 0:i.timestamp)||M().toISOString(),y.author=(i==null?void 0:i.author)||"1",y.previousVersion=null,y.deleted=!1,y.deletable=!0,y.editable=!0;const b=Gi(y,e);n?b.setParent(n,i):b.setParent(this.parent,null),c&&b.subscribe(),b.initChildren(i),i==null||i.add(b,H.Added);const O=($=this.inputs)==null?void 0:$.map((U,S)=>U.clone(i,b,E+"-input-map-"+S+"-id",c));b.inputs=O;const _=(L=this.outputs)==null?void 0:L.map((U,S)=>U.clone(i,b,E+"-output-map-"+S+"-id",c));return b.outputs=_,this.body&&(b.body=this.body.clone(i,b,E+"-body-id",c,!0)),this.error&&(b.error=this.error.clone(i,b,E+"-error-map-id",c)),this.dataType&&(b.dataType=this.dataType.clone(i,b,E+"-data-type-id",c)),i==null||i.attemptAutoclose(P.CloneEntity,this.id),b}getVariableInstances(){return this.body?Zi(this.body).filter(l=>l.type===o.VariableInstance):[]}addReturnStatement(i){return zt.includes(this.parent.type)&&this.parent.addReturnStatement(i),this}removeReturnStatement(i){return zt.includes(this.parent.type)&&this.parent.removeReturnStatement(i),this}addBreakStatement(i){return this.breakStatements.includes(i)||this.breakStatements.push(i),this}removeBreakStatement(i){const n=this.breakStatements.indexOf(i);return n!==-1&&this.breakStatements.splice(n,1),this}addContinueStatement(i){return this.continueStatements.includes(i)||this.continueStatements.push(i),this}removeContinueStatement(i){const n=this.continueStatements.indexOf(i);return n!==-1&&this.continueStatements.splice(n,1),this}getUniqueInputMaps(){const i=[];return[...this.breakStatements,...this.continueStatements].forEach(l=>{l.outputs.filter(e=>{var y;return!e.deleted&&!((y=e.declaration)!=null&&y.deleted)}).forEach(e=>{i.find(T=>T===e||se(T,this.project)===se(e,this.project)&&on(T.dataType,e.dataType))||i.push(e)})}),D(i)}syncTerminationStatements(i=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,"sync-termination-statements"))){const n=[],l=[],c=[],e=[],y=this.getUniqueInputMaps();return[...this.breakStatements,...this.continueStatements].forEach(v=>{const E=v.outputs.filter(O=>{var _;return!O.deleted&&!((_=O.declaration)!=null&&_.deleted)}),b=y.filter(O=>!E.find(_=>se(O,this.project)===se(_,this.project)&&on(O.dataType,_.dataType)));b.length&&(n.push(v),i==null||i.add(v,H.Updated)),b.forEach(O=>{const _=O.clone(i,v);i==null||i.add(_,H.Added),_.addSelfToProject(i),l.push(_)})}),i==null||i.attemptAutoclose("sync-termination-statements",this.id),{updated:D(n),added:D(l),removed:D(c),affected:D(e),self:this}}syncBodyInputIndexes(i=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,"sync-body-input-indexes"))){const n=[],l=[],c=[],e=[];return this.body.inputs.sort((y,T)=>y.index-T.index),i==null||i.attemptAutoclose("sync-body-input-indexes",this.id),{updated:D(n),added:D(l),removed:D(c),affected:D(e),self:this}}syncBodyArgumentsDeclarations(i=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,"sync-body-arguments-declarations"))){var L,U,S,Z,X,ae;const n=[],l=[],c=[],e=[],{updated:y,added:T,removed:v}=this.syncFixedBodyArgumentDeclarations(i);n.push(...y),l.push(...T),c.push(...v);const E=this.getUniqueInputMaps(),b=this.body.inputs;if(E.sort((Q,fe)=>Q.index-fe.index),((S=(U=(L=this.body)==null?void 0:L.dataType)==null?void 0:U.entity)==null?void 0:S.id)!==Y["primitive-entity"].void.id&&!b.find(fe=>{var oe,ce,me,ne,ye,_e,Ve;return fe.id!==((oe=this.currentIterationNumberArgumentDeclaration)==null?void 0:oe.id)&&fe.id!==((ce=this.currentValueArgumentDeclaration)==null?void 0:ce.id)&&((ne=(me=fe.dataType)==null?void 0:me.entity)==null?void 0:ne.id)===((Ve=(_e=(ye=this.body)==null?void 0:ye.dataType)==null?void 0:_e.entity)==null?void 0:Ve.id)})){let fe=0;this.currentIterationNumberArgumentDeclaration&&fe++,this.currentValueArgumentDeclaration&&fe++;const oe=ya.new(i);oe.name="Aggregate result",oe.description="Aggretated list of all previously outputted values from each iteration",oe.constant=!0,oe.index=fe,oe.required=!1,oe.parent=this.body.toReference();const ce=he(oe,this.project);if(ce.hydrateAncestors(),ce.addSelfToProject(i),i==null||i.add(ce,H.Added),l.push(ce),ce.setParent(this.body,i),ce.initChildren(i),!ce.dataType&&((Z=this.body)!=null&&Z.dataType)){const me=lr.new(i);me.parent=ce.toReference();const ne=he(me,this.project);ne.hydrateAncestors(),ne.addSelfToProject(i),l.push(ne),ne.setParent(ce,i),ne.initChildren(i),ne.merge((X=this.body)==null?void 0:X.dataType,i),ne.setEntity((ae=this.body)==null?void 0:ae.dataType.entity,i),i==null||i.add(ne,H.Added)}}const{updated:O,added:_,removed:$}=this.removeExtraBodyArgumentDeclarations(i);return n.push(...O),l.push(..._),c.push(...$),i==null||i.attemptAutoclose("sync-body-arguments-declarations",this.id),{updated:D(n),added:D(l),removed:D(c),affected:D(e),self:this}}reAttachAllTerminationInputMapsToDeclarations(i=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,"reattach-termination-input-maps-to-declarations"))){var T,v,E;const n=[],l=[],c=[],e=[];return!((T=this.body)!=null&&T.dataType)||!((v=this.body)!=null&&v.dataType.entity)||((E=this.body)==null?void 0:E.dataType.entity.type)!==o.DefinitionEntity?(i==null||i.attemptAutoclose("reattach-termination-input-maps-to-declarations",this.id),{updated:D(n),added:D(l),removed:D(c),affected:D(e),self:this}):([...this.breakStatements,...this.continueStatements].forEach(b=>{var U,S,Z;const O=b.outputs.filter(X=>{var ae;return!X.deleted&&!((ae=X.declaration)!=null&&ae.deleted)}),_=O.filter(X=>!X.declaration&&!!X.readsValue),$=O.filter(X=>!X.declaration&&!X.readsValue);let L=(((Z=(S=(U=this.body)==null?void 0:U.dataType)==null?void 0:S.entity)==null?void 0:Z.properties)||[]).filter(X=>!O.find(ae=>{var Q,fe;return!ae.deleted&&!((Q=ae.declaration)!=null&&Q.deleted)&&((fe=ae.declaration)==null?void 0:fe.id)===X.id}));_.forEach(X=>{const ae=X.getDataType(i);if(X.readsValue){const Q=se(X.readsValue,this.project),fe=L.find(oe=>se(oe,this.project)===Q&&on(oe.dataType,ae));if(fe){X.setDeclaration(fe,i),n.push(X),L=L.filter(oe=>oe!==fe);return}}}),$.forEach(X=>{const ae=X.getDataType(i),Q=L.find(fe=>on(fe.dataType,ae));if(Q){X.setDeclaration(Q,i),n.push(X),L=L.filter(fe=>fe!==Q);return}}),O.forEach(X=>{const ae=L.find(Q=>se(Q,this.project)===se(X,this.project));X.declaration&&!L.includes(X.declaration)&&ae&&(X.setDeclaration(ae,i),n.push(X),L=L.filter(Q=>Q!==ae))})}),i==null||i.attemptAutoclose("reattach-termination-input-maps-to-declarations",this.id),{updated:D(n),added:D(l),removed:D(c),affected:D(e),self:this})}syncOutputDataType(i=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,"sync-outputs-properties"))){var $,L,U,S,Z,X,ae,Q,fe,oe,ce,me,ne,ye,_e,Ve,Be,xe,Me,We,Se;const n=[],l=[],c=[],e=[],y=[...this.breakStatements,...this.continueStatements];if(!y.every(qe=>qe.initialized))return i==null||i.attemptAutoclose("sync-outputs-properties",this.id),{updated:D(n),added:D(l),removed:D(c),affected:D(e),self:this};if(!(($=this.body)!=null&&$.dataType)){const qe=lr.new(i);qe.parent=this.body.toReference(),qe.inferred=!0;const et=he(qe,this.project);et.hydrateAncestors(),et.addSelfToProject(i),i==null||i.add(et,H.Added),et.initChildren(i),l.push(et)}const T=y.find(qe=>!!qe.readsValue);if(T){const qe=(L=T.readsValue)==null?void 0:L.getDataType(i);qe&&((S=(U=this.body)==null?void 0:U.dataType)==null||S.merge(qe,i))}const v=this.getUniqueInputMaps();let E=(X=(Z=this.body)==null?void 0:Z.dataType)==null?void 0:X.entity;if(v.length&&(!E||E.id===Y["primitive-entity"].void.id)){const qe=ls.new(i);qe.parent=((ae=this.body)==null?void 0:ae.dataType).toReference(),qe.name=`${se(this,this.project)} output definition`,qe.description=`The definition of the output data type of the loop '${se(this,this.project)}'`;const et=he(qe,this.project);et.setParent((Q=this.body)==null?void 0:Q.dataType,i),et.hydrateAncestors(),i==null||i.add(et,H.Added),et.addSelfToProject(i),et.initChildren(i),l.push(et),E=et,(oe=(fe=this.body)==null?void 0:fe.dataType)==null||oe.metaSync({inferred:!0},i)}const b=(E==null?void 0:E.properties)||[];(me=(ce=this.body)==null?void 0:ce.dataType)!=null&&me.inferred&&((ye=(ne=this.body)==null?void 0:ne.dataType.entity)==null?void 0:ye.type)===o.DefinitionEntity&&(v.forEach(qe=>{var Ei,er,br,Aa,vn;const et=qe.getDataType(i);let dt=b.find(Ci=>se(Ci,this.project)===se(qe,this.project)&&on(Ci.dataType,qe.dataType));if(!dt){const Ci=Ma.new(i);Ci.name=se(qe,this.project),Ci.description=`Aggretated list of all previously outputted values from each iteration by the output '${se(qe,this.project)}'`,Ci.index=qe.index,Ci.required=((Ei=qe.declaration)==null?void 0:Ei.required)||!1,Ci.parent=((br=(er=this.body)==null?void 0:er.dataType)==null?void 0:br.entity).toReference();const qi=he(Ci,this.project);qi.hydrateAncestors(),qi.setParent((vn=(Aa=this.body)==null?void 0:Aa.dataType)==null?void 0:vn.entity,i),qi.addSelfToProject(i),i==null||i.add(qi,H.Added),qi.initChildren(i),l.push(qi),dt=qi}dt.index!==qe.index&&(dt.metaSync({index:qe.index},i),n.push(dt));let wt=dt.getDataType(i);if(et)if(!wt||!on(wt,et)){if(!wt){const Ci=et.clone(i,dt);i==null||i.add(Ci,H.Added),Ci.addSelfToProject(i),wt=Ci,l.push(Ci),n.push(dt)}wt.merge(et,i),wt.metaSync({isList:!0},i)}else wt.isList||(wt.metaSync({isList:!0},i),n.push(wt));if(!et&&!wt){const Ci={id:x.UUID.uuid(),version:x.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||M().toISOString(),author:x.sessionAuthor,previousVersion:null,deleted:!1,deletable:!0,editable:!0,type:o.DataType,foreignKeyRef:null,foreignKeyAllowed:null,options:[],implementationChooseOne:!1,staticEntities:null,interactiveEntities:null,index:null,actionEntities:null,parentRelationType:null,isList:!0,entity:null,asType:!1,like:!1,inferred:!1,andChildrenGroup:null,orChildrenGroup:null,parent:dt.toReference()},qi=he(Ci,this.project);qi.metaSync({isList:!0},i),qi.setParent(dt,i),qi.initChildren(i),i==null||i.add(qi,H.Added),qi.addSelfToProject(i),l.push(qi)}}),this.reAttachAllTerminationInputMapsToDeclarations(i)),(Ve=(_e=this.body)==null?void 0:_e.dataType)!=null&&Ve.inferred&&((xe=(Be=this.body)==null?void 0:Be.dataType.entity)==null?void 0:xe.type)===o.DefinitionEntity&&b.filter(et=>!v.find(dt=>se(et,this.project)===se(dt,this.project))).forEach(et=>{if(!(i!=null&&i.hasRemoved(et.id))&&!et.deleted){const{updated:ot,removed:dt}=et.remove({ignoreUpstream:!1},i);n.push(...ot),c.push(...dt)}}),y.forEach(qe=>{qe.outputs.filter(ot=>{var dt;return!ot.deleted&&!((dt=ot.declaration)!=null&&dt.deleted)}).forEach(ot=>{var St,wt,Ei;if(!(((Ei=(wt=(St=this.body)==null?void 0:St.dataType)==null?void 0:wt.entity)==null?void 0:Ei.properties)||[]).find(er=>{var br;return((br=ot.declaration)==null?void 0:br.id)===er.id})&&!(i!=null&&i.hasRemoved(ot.id))&&!ot.deleted){const{updated:er,removed:br}=ot.remove({ignoreUpstream:!1},i);n.push(...er),c.push(...br)}})});const O=this.getUniqueInputMaps();if(y.every(qe=>!qe.readsValue)&&!O.length){const qe=this.project.getBuiltIn(Y["primitive-entity"].void.id);(We=(Me=this.body)==null?void 0:Me.dataType)==null||We.setEntity(qe,i),n.push((Se=this.body)==null?void 0:Se.dataType)}return i==null||i.attemptAutoclose("sync-outputs-properties",this.id),{updated:D(n),added:D(l),removed:D(c),affected:D(e),self:this}}syncOutputMaps(i=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,P.SyncOutputs))){var E,b,O;const n=[],l=[],c=[],e=[],y=((O=(b=(E=this.body)==null?void 0:E.dataType)==null?void 0:b.entity)==null?void 0:O.properties)||[],T=this.outputs;return y.forEach(_=>{var U;let L=T.find(S=>{var Z,X;return((Z=S.declaration)==null?void 0:Z.id)===_.id&&on((X=S.declaration)==null?void 0:X.dataType,_.dataType)});if(L)((U=L.declaration)==null?void 0:U.id)!==_.id&&(L.setDeclaration(_,i),n.push(L));else{const S={id:x.UUID.uuid(),version:x.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||M().toISOString(),author:x.sessionAuthor,previousVersion:null,deleted:!1,deletable:!0,editable:!0,type:o.OutputMap,index:_.index,declaration:_.toJSON(),writesValues:[],parent:this.toReference()},Z=he(S,this.project);Z.setParent(this,i),Z.initChildren(i),i==null||i.add(Z,H.Added),Z.addSelfToProject(i),l.push(Z),L=Z}L.index!==_.index&&(L.metaSync({index:_.index},i),n.push(L))}),T.filter(_=>!y.find(L=>{var U;return((U=_.declaration)==null?void 0:U.id)===L.id})).forEach(_=>{const{updated:$,removed:L}=_.remove({ignoreUpstream:!1},i);n.push(...$),c.push(...L)}),i==null||i.attemptAutoclose(P.SyncOutputs,this.id),{updated:D(n),added:D(l),removed:D(c),affected:D(e),self:this}}createCurrentIterationNumberArgumentDeclaration(i=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,"create-current-iteration-number-argument-declaration"))){const n=[],l=[],c=[],e=[];let T=this.body.inputs.find(O=>{var _;return O.name===Kt.CURRENT_ITERATION_NUMBER_ARG_NAME||O.id===((_=this.currentIterationNumberArgumentDeclaration)==null?void 0:_.id)});const v=this.getCurrentIterationNumberBuiltInValueDescriptor();if(!T){const O={id:x.UUID.uuid(),version:x.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||M().toISOString(),author:x.sessionAuthor,previousVersion:null,deleted:!1,deletable:!0,editable:!0,type:o.ArgumentDeclaration,name:Kt.CURRENT_ITERATION_NUMBER_ARG_NAME,codeName:null,description:"The number of the current iteration",defaultValue:null,constant:!0,dataType:null,implements:[v==null?void 0:v.toJSON()],index:this.body.inputs.length,required:!0,parent:this.body.toReference(),writesValues:[]},_=he(O,this.project);_.setParent(this.body,i),_.initChildren(i),i==null||i.add(_,H.Added),_.addSelfToProject(i),l.push(_),T=_}!T.index&&T.index!==0&&(T.metaSync({index:0},i),n.push(T)),(!T.implements||!T.implements.find(O=>O.id===v.id))&&(T.addImplementation(v,i),n.push(T));let b=T.getDataType(i);if(!b){const O={id:x.UUID.uuid(),version:x.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||M().toISOString(),author:x.sessionAuthor,previousVersion:null,deleted:!1,deletable:!0,editable:!0,type:o.DataType,foreignKeyRef:null,foreignKeyAllowed:null,options:[],implementationChooseOne:!1,staticEntities:null,interactiveEntities:null,actionEntities:null,parentRelationType:null,isList:!1,index:null,entity:null,asType:!1,like:!1,inferred:!1,andChildrenGroup:null,orChildrenGroup:null,parent:T.toReference()},_=he(O,this.project);_.setParent(T,i),_.initChildren(i),i==null||i.add(_,H.Added),_.addSelfToProject(i),l.push(_),b=_}if(!b.entity||b.entity.type!==o.PrimitiveEntity||b.entity.name!==le.Number||b.entity.id!==Y["primitive-entity"].number.id){const O=this.project.getBuiltIn(Y["primitive-entity"].number.id);b.setEntity(O,i),n.push(b)}return i==null||i.attemptAutoclose("create-current-iteration-number-argument-declaration",this.id),{updated:D(n),added:D(l),removed:D(c),affected:D(e),self:this}}removeExtraBodyArgumentDeclarations(i=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,"remove-extra-body-argument-declarations"))){const n=[],l=[],c=[],e=[];return this.body.inputs.filter(v=>{var E,b,O,_,$,L,U,S;return v===this.currentIterationNumberArgumentDeclaration||v===this.currentValueArgumentDeclaration?!1:((O=(b=(E=this.body)==null?void 0:E.dataType)==null?void 0:b.entity)==null?void 0:O.id)===Y["primitive-entity"].void.id?!0:(($=(_=v.dataType)==null?void 0:_.entity)==null?void 0:$.id)!==((S=(U=(L=this.body)==null?void 0:L.dataType)==null?void 0:U.entity)==null?void 0:S.id)}).forEach(v=>{const{updated:E,removed:b}=v.remove({ignoreUpstream:!1},i);n.push(...E),c.push(...b)}),i==null||i.attemptAutoclose("remove-extra-body-argument-declarations",this.id),{updated:D(n),added:D(l),removed:D(c),affected:D(e),self:this}}createCurrentValueInputBasedOnInputMap(i=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,"create-current-value-input-based-on-input-map"))){var E,b,O,_,$,L,U,S,Z;const n=[],l=[],c=[],e=[];switch(this.declaration.id){case st.List:{const X=this.body.inputs.find(fe=>!!fe.implements.find(oe=>oe.id===Y[o.Loop][st.List].body.inputs.currentValue.id)),ae=this.inputs.find(fe=>{var oe;return((oe=fe.declaration)==null?void 0:oe.id)===Y[o.Loop][st.List].inputs.list.id});if(!ae)break;const Q=this.getCurrentValueBuiltInValueDescriptor();if(X){Q&&!X.implements.find(me=>me.id===Q.id)&&(X.addImplementation(Q,i),n.push(X));let oe=X.getDataType(i);if(!oe){const me={id:x.UUID.uuid(),version:x.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||M().toISOString(),author:x.sessionAuthor,previousVersion:null,deleted:!1,deletable:!0,editable:!0,type:o.DataType,foreignKeyRef:null,foreignKeyAllowed:null,options:[],implementationChooseOne:!1,parentRelationType:null,staticEntities:null,interactiveEntities:null,index:null,actionEntities:null,isList:!1,entity:null,asType:!1,like:!1,inferred:!1,andChildrenGroup:null,orChildrenGroup:null,parent:(E=this.currentValueArgumentDeclaration)==null?void 0:E.toReference()},ne=he(me,this.project);ne.setParent(this.currentValueArgumentDeclaration,i),ne.initChildren(i),i==null||i.add(ne,H.Added),ne.addSelfToProject(i),l.push(ne),oe=ne}const ce=ae.getDataType(i);oe.merge(ce,i),oe.metaSync({isList:!1},i)}else{const fe={id:x.UUID.uuid(),version:x.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||M().toISOString(),author:x.sessionAuthor,previousVersion:null,deleted:!1,deletable:!0,editable:!0,type:o.ArgumentDeclaration,name:Kt.CURRENT_VALUE_ARG_NAME,codeName:null,description:null,defaultValue:null,index:this.body.inputs.length,constant:!0,required:!0,implements:[Q],writesValues:[],dataType:null,parent:this.body.toReference()},oe=he(fe,this.project);oe.setParent(this.body,i),oe.initChildren(i),i==null||i.add(oe,H.Added),oe.addSelfToProject(i),Q&&!oe.implements.find(ce=>ce.id===Q.id)&&(oe.addImplementation(Q,i),n.push(oe)),l.push(oe)}break}case st.ManualFlow:break;case st.Counted:break;case st.ObjectKeys:{const X=this.body.inputs.find(fe=>!!fe.implements.find(oe=>oe.id===Y[o.Loop][st.ObjectKeys].body.inputs.currentValue.id));if(!this.inputs.find(fe=>{var oe;return((oe=fe.declaration)==null?void 0:oe.id)===Y[o.Loop][st.ObjectKeys].inputs.object.id}))break;const Q=this.getCurrentValueBuiltInValueDescriptor();if(X){Q&&!X.implements.find(ce=>ce.id===Q.id)&&(X.addImplementation(Q),n.push(X));let oe=X.getDataType(i);if(oe){const ce=this.project.getBuiltIn(Y["primitive-entity"].string.id);((O=oe.entity)==null?void 0:O.id)!==ce.id&&(oe.setEntity(ce,i),n.push(oe))}else{const ce={id:x.UUID.uuid(),version:x.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||M().toISOString(),author:x.sessionAuthor,previousVersion:null,deleted:!1,deletable:!0,editable:!0,type:o.DataType,foreignKeyRef:null,foreignKeyAllowed:null,options:[],implementationChooseOne:!1,parentRelationType:null,staticEntities:null,interactiveEntities:null,index:null,actionEntities:null,isList:!1,entity:null,asType:!1,like:!1,inferred:!1,andChildrenGroup:null,orChildrenGroup:null,parent:(b=this.currentValueArgumentDeclaration)==null?void 0:b.toReference()},me=he(ce,this.project);me.setParent(this.currentValueArgumentDeclaration,i),me.initChildren(i),i==null||i.add(me,H.Added),me.addSelfToProject(i),oe=me}}else{const fe={id:x.UUID.uuid(),version:x.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||M().toISOString(),author:x.sessionAuthor,previousVersion:null,deleted:!1,deletable:!0,editable:!0,type:o.ArgumentDeclaration,name:Kt.CURRENT_VALUE_ARG_NAME,codeName:null,description:null,defaultValue:null,index:this.body.inputs.length,constant:!0,required:!0,implements:[Q],writesValues:[],dataType:null,parent:this.body.toReference()},oe=he(fe,this.project);oe.setParent(this.body,i),oe.initChildren(i),i==null||i.add(oe,H.Added),oe.addSelfToProject(i),Q&&!oe.implements.find(ce=>ce.id===Q.id)&&(oe.addImplementation(Q,i),n.push(oe)),l.push(oe)}break}case st.ObjectValues:{const X=this.body.inputs.find(fe=>!!fe.implements.find(oe=>oe.id===Y[o.Loop][st.ObjectValues].body.inputs.currentValue.id)),ae=this.inputs.find(fe=>{var oe;return((oe=fe.declaration)==null?void 0:oe.id)===Y[o.Loop][st.ObjectValues].inputs.object.id});if(!ae)break;const Q=this.getCurrentValueBuiltInValueDescriptor();if(X){Q&&!X.implements.find(ce=>ce.id===Q.id)&&(X.addImplementation(Q,i),n.push(X));let oe=X.getDataType(i);if(oe){const ce=ae.getDataType(i),me=((L=ce==null?void 0:ce.entity)==null?void 0:L.properties)||[];(U=oe.orChildrenGroup)==null||U.forEach(ne=>{const{updated:ye,removed:_e}=ne.remove({ignoreUpstream:!1},i);n.push(...ye),c.push(..._e)}),me.forEach(ne=>{if(!ne.getDataType(i)){const _e={id:x.UUID.uuid(),version:x.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||M().toISOString(),author:x.sessionAuthor,previousVersion:null,deleted:!1,deletable:!0,editable:!0,type:o.DataType,foreignKeyRef:null,foreignKeyAllowed:null,options:[],implementationChooseOne:!1,staticEntities:null,interactiveEntities:null,actionEntities:null,index:null,isList:!1,entity:null,asType:!1,like:!1,inferred:!1,andChildrenGroup:null,orChildrenGroup:null,parentRelationType:Fe.OrDataTypeGroup,parent:oe.toReference()},Ve=he(_e,this.project);Ve.setParent(oe,i),Ve.initChildren(i),i==null||i.add(Ve,H.Added),Ve.addSelfToProject(i),l.push(Ve)}})}else{const ce={id:x.UUID.uuid(),version:x.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||M().toISOString(),author:x.sessionAuthor,previousVersion:null,deleted:!1,deletable:!0,editable:!0,type:o.DataType,foreignKeyRef:null,foreignKeyAllowed:null,options:[],implementationChooseOne:!1,parentRelationType:null,staticEntities:null,interactiveEntities:null,index:null,actionEntities:null,isList:!1,entity:null,asType:!1,like:!1,inferred:!1,andChildrenGroup:null,orChildrenGroup:null,parent:(_=this.currentValueArgumentDeclaration)==null?void 0:_.toReference()},me=he(ce,this.project);me.setParent(this.currentValueArgumentDeclaration,i),me.initChildren(i),i==null||i.add(me,H.Added),me.addSelfToProject(i),oe=me;const ne=ae.getDataType(i);((($=ne==null?void 0:ne.entity)==null?void 0:$.properties)||[]).forEach(_e=>{if(!_e.getDataType(i)){const Be={id:x.UUID.uuid(),version:x.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||M().toISOString(),author:x.sessionAuthor,previousVersion:null,deleted:!1,deletable:!0,editable:!0,type:o.DataType,foreignKeyRef:null,foreignKeyAllowed:null,options:[],implementationChooseOne:!1,staticEntities:null,interactiveEntities:null,actionEntities:null,index:null,isList:!1,entity:null,asType:!1,like:!1,inferred:!1,andChildrenGroup:null,orChildrenGroup:null,parentRelationType:Fe.OrDataTypeGroup,parent:me.toReference()},xe=he(Be,this.project);xe.setParent(me,i),xe.initChildren(i),i==null||i.add(xe,H.Added),xe.addSelfToProject(i),l.push(xe)}})}}else{const fe={id:x.UUID.uuid(),version:x.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||M().toISOString(),author:x.sessionAuthor,previousVersion:null,deleted:!1,deletable:!0,editable:!0,type:o.ArgumentDeclaration,name:Kt.CURRENT_VALUE_ARG_NAME,codeName:null,description:null,constant:!0,defaultValue:null,index:this.body.inputs.length,required:!0,implements:[Q],writesValues:[],dataType:null,parent:this.body.toReference()},oe=he(fe,this.project);oe.setParent(this.body,i),oe.initChildren(i),i==null||i.add(oe,H.Added),oe.addSelfToProject(i),Q&&!oe.implements.find(ce=>ce.id===Q.id)&&(oe.addImplementation(Q,i),n.push(oe)),l.push(oe)}break}case st.String:{const X=this.body.inputs.find(fe=>!!fe.implements.find(oe=>oe.id===Y[o.Loop][st.String].body.inputs.currentValue.id));if(!this.inputs.find(fe=>{var oe;return((oe=fe.declaration)==null?void 0:oe.id)===Y[o.Loop][st.String].inputs.string.id}))break;const Q=this.getCurrentValueBuiltInValueDescriptor();if(X){Q&&!X.implements.find(ce=>ce.id===Q.id)&&(X.addImplementation(Q,i),n.push(X));let oe=X.getDataType(i);if(oe){const ce=this.project.getBuiltIn(Y["primitive-entity"].string.id);((Z=oe.entity)==null?void 0:Z.id)!==ce.id&&(oe.setEntity(ce,i),n.push(oe))}else{const ce={id:x.UUID.uuid(),version:x.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||M().toISOString(),author:x.sessionAuthor,previousVersion:null,deleted:!1,deletable:!0,editable:!0,type:o.DataType,foreignKeyRef:null,foreignKeyAllowed:null,options:[],implementationChooseOne:!1,parentRelationType:null,staticEntities:null,interactiveEntities:null,index:null,actionEntities:null,isList:!1,entity:null,asType:!1,like:!1,inferred:!1,andChildrenGroup:null,orChildrenGroup:null,parent:(S=this.currentValueArgumentDeclaration)==null?void 0:S.toReference()},me=he(ce,this.project);me.setParent(this.currentValueArgumentDeclaration,i),me.initChildren(i),i==null||i.add(me,H.Added),me.addSelfToProject(i),l.push(me),oe=me}}else{const fe={id:x.UUID.uuid(),version:x.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||M().toISOString(),author:x.sessionAuthor,previousVersion:null,deleted:!1,deletable:!0,editable:!0,type:o.ArgumentDeclaration,name:Kt.CURRENT_VALUE_ARG_NAME,codeName:null,description:null,index:this.body.inputs.length,required:!0,constant:!0,defaultValue:null,implements:[Q],writesValues:[],dataType:null,parent:this.body.toReference()},oe=he(fe,this.project);oe.setParent(this.body,i),oe.initChildren(i),i==null||i.add(oe,H.Added),oe.addSelfToProject(i),Q&&!oe.implements.find(ce=>ce.id===Q.id)&&(oe.addImplementation(Q,i),n.push(oe)),l.push(oe)}break}}const{updated:y,added:T,removed:v}=this.removeExtraBodyArgumentDeclarations(i);return n.push(...y),l.push(...T),c.push(...v),i==null||i.attemptAutoclose("create-current-value-input-based-on-input-map",this.id),{updated:D(n),added:D(l),removed:D(c),affected:D(e),self:this}}syncFixedBodyArgumentDeclarations(i=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,"sync-fixed-body-argument-declarations"))){const n=[],l=[],c=[],e=[],{updated:y,added:T,removed:v}=this.createCurrentIterationNumberArgumentDeclaration(i);n.push(...y),l.push(...T),c.push(...v);const{updated:E,added:b,removed:O}=this.createCurrentValueInputBasedOnInputMap(i);return n.push(...E),l.push(...b),c.push(...O),i==null||i.attemptAutoclose("sync-fixed-body-argument-declarations",this.id),{updated:D(n),added:D(l),removed:D(c),affected:D(e),self:this}}syncInputMaps(i=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,"sync-input-maps"))){const n=[],l=[],c=[],e=[];switch(this.declaration.id){case st.List:{let y=null;if(this.inputs.forEach(v=>{var E;((E=v.declaration)==null?void 0:E.id)===Y[o.Loop]["list-loop"].inputs.list.id?y=v:(v.remove({ignoreUpstream:!1},i),c.push(v))}),y){if(y.declaration.id!==Y[o.Loop]["list-loop"].inputs.list.id){const v=this.project.get(Y[o.Loop]["list-loop"].inputs.list.id);y.setDeclaration(v,i),n.push(y)}}else{const v=this.project.get(Y[o.Loop]["list-loop"].inputs.list.id),E={id:x.UUID.uuid(),version:x.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||M().toISOString(),author:x.sessionAuthor,previousVersion:null,deleted:!1,deletable:!0,editable:!0,type:o.InputMap,parentRelationType:null,name:null,codeName:null,description:null,index:0,declaration:v.toJSON(),readsValue:null,defaultValue:null,parent:this.toReference()},b=he(E,this.project);b.setParent(this,i),b.initChildren(i),i==null||i.add(b,H.Added),b.addSelfToProject(i),l.push(b)}[...this.inputs].forEach(v=>{var E;((E=v.declaration)==null?void 0:E.id)!==Y[o.Loop]["list-loop"].inputs.list.id&&(v.remove({ignoreUpstream:!1},i),c.push(v))}),this.inputs.sort((v,E)=>M(v.createdAt).isBefore(M(E.createdAt))?-1:1).forEach((v,E)=>{E!==0&&(v.remove({ignoreUpstream:!1},i),c.push(v))});break}case st.ManualFlow:{this.inputs.forEach(y=>{y.remove({ignoreUpstream:!1},i),c.push(y)});break}case st.Counted:{let y=null;if(this.inputs.forEach(v=>{var E;((E=v.declaration)==null?void 0:E.id)===Y[o.Loop]["counted-loop"].inputs.number.id?y=v:(v.remove({ignoreUpstream:!1},i),c.push(v))}),y){if(y.declaration.id!==Y[o.Loop]["counted-loop"].inputs.number.id){const v=this.project.get(Y[o.Loop]["counted-loop"].inputs.number.id);y.setDeclaration(v,i),n.push(y)}}else{const v=this.project.get(Y[o.Loop]["counted-loop"].inputs.number.id),E={id:x.UUID.uuid(),version:x.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||M().toISOString(),author:x.sessionAuthor,previousVersion:null,deleted:!1,deletable:!0,editable:!0,type:o.InputMap,parentRelationType:null,name:null,codeName:null,description:null,index:0,declaration:v.toJSON(),readsValue:null,defaultValue:null,parent:this.toReference()},b=he(E,this.project);b.setParent(this,i),b.initChildren(i),i==null||i.add(b,H.Added),b.addSelfToProject(i),l.push(b)}[...this.inputs].forEach(v=>{var E;((E=v.declaration)==null?void 0:E.id)!==Y[o.Loop]["counted-loop"].inputs.number.id&&(v.remove({ignoreUpstream:!1},i),c.push(v))}),this.inputs.sort((v,E)=>M(v.createdAt).isBefore(M(E.createdAt))?-1:1).forEach((v,E)=>{E!==0&&(v.remove({ignoreUpstream:!1},i),c.push(v))});break}case st.ObjectKeys:{let y=null;if(this.inputs.forEach(v=>{var E;((E=v.declaration)==null?void 0:E.id)===Y[o.Loop]["object-keys-loop"].inputs.object.id?y=v:(v.remove({ignoreUpstream:!1},i),c.push(v))}),y){if(y.declaration.id!==Y[o.Loop]["object-keys-loop"].inputs.object.id){const v=this.project.get(Y[o.Loop]["object-keys-loop"].inputs.object.id);y.setDeclaration(v,i),n.push(y)}}else{const v=this.project.get(Y[o.Loop]["object-keys-loop"].inputs.object.id),E={id:x.UUID.uuid(),version:x.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||M().toISOString(),author:x.sessionAuthor,previousVersion:null,deleted:!1,deletable:!0,editable:!0,type:o.InputMap,parentRelationType:null,name:null,codeName:null,description:null,index:0,declaration:v.toJSON(),readsValue:null,defaultValue:null,parent:this.toReference()},b=he(E,this.project);b.setParent(this,i),b.initChildren(i),i==null||i.add(b,H.Added),b.addSelfToProject(i),l.push(b)}[...this.inputs].forEach(v=>{var E;((E=v.declaration)==null?void 0:E.id)!==Y[o.Loop]["object-keys-loop"].inputs.object.id&&(v.remove({ignoreUpstream:!1},i),c.push(v))}),this.inputs.sort((v,E)=>M(v.createdAt).isBefore(M(E.createdAt))?-1:1).forEach((v,E)=>{E!==0&&(v.remove({ignoreUpstream:!1},i),c.push(v))});break}case st.ObjectValues:{let y=null;if(this.inputs.forEach(v=>{var E;((E=v.declaration)==null?void 0:E.id)===Y[o.Loop]["object-values-loop"].inputs.object.id?y=v:(v.remove({ignoreUpstream:!1},i),c.push(v))}),y){if(y.declaration.id!==Y[o.Loop]["object-values-loop"].inputs.object.id){const v=this.project.get(Y[o.Loop]["object-values-loop"].inputs.object.id);y.setDeclaration(v,i),n.push(y)}}else{const v=this.project.get(Y[o.Loop]["object-values-loop"].inputs.object.id),E={id:x.UUID.uuid(),version:x.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||M().toISOString(),author:x.sessionAuthor,previousVersion:null,deleted:!1,deletable:!0,editable:!0,type:o.InputMap,parentRelationType:null,name:null,codeName:null,description:null,index:0,declaration:v.toJSON(),readsValue:null,defaultValue:null,parent:this.toReference()},b=he(E,this.project);b.setParent(this,i),b.initChildren(i),i==null||i.add(b,H.Added),b.addSelfToProject(i),l.push(b)}[...this.inputs].forEach(v=>{var E;((E=v.declaration)==null?void 0:E.id)!==Y[o.Loop]["object-values-loop"].inputs.object.id&&(v.remove({ignoreUpstream:!1},i),c.push(v))}),this.inputs.sort((v,E)=>M(v.createdAt).isBefore(M(E.createdAt))?-1:1).forEach((v,E)=>{E!==0&&(v.remove({ignoreUpstream:!1},i),c.push(v))});break}case st.String:{let y=null;if(this.inputs.forEach(v=>{var E;((E=v.declaration)==null?void 0:E.id)===Y[o.Loop]["string-loop"].inputs.string.id?y=v:(v.remove({ignoreUpstream:!1},i),c.push(v))}),y){if(y.declaration.id!==Y[o.Loop]["string-loop"].inputs.string.id){const v=this.project.get(Y[o.Loop]["string-loop"].inputs.string.id);y.setDeclaration(v,i),n.push(y)}}else{const v=this.project.get(Y[o.Loop]["string-loop"].inputs.string.id),E={id:x.UUID.uuid(),version:x.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||M().toISOString(),author:x.sessionAuthor,previousVersion:null,deleted:!1,deletable:!0,editable:!0,type:o.InputMap,parentRelationType:null,name:null,codeName:null,description:null,index:0,declaration:v.toJSON(),readsValue:null,defaultValue:null,parent:this.toReference()},b=he(E,this.project);b.setParent(this,i),b.initChildren(i),i==null||i.add(b,H.Added),b.addSelfToProject(i),l.push(b)}[...this.inputs].forEach(v=>{var E;((E=v.declaration)==null?void 0:E.id)!==Y[o.Loop]["string-loop"].inputs.string.id&&(v.remove({ignoreUpstream:!1},i),c.push(v))}),this.inputs.sort((v,E)=>M(v.createdAt).isBefore(M(E.createdAt))?-1:1).forEach((v,E)=>{E!==0&&(v.remove({ignoreUpstream:!1},i),c.push(v))});break}}return i==null||i.attemptAutoclose("sync-input-maps",this.id),{updated:D(n),added:D(l),removed:D(c),affected:D(e),self:this}}getValueInputMapDeclarationId(){switch(this.declaration.id){case st.List:return Y[o.Loop]["list-loop"].inputs.list.id;case st.ObjectKeys:return Y[o.Loop]["object-keys-loop"].inputs.object.id;case st.ObjectValues:return Y[o.Loop]["object-values-loop"].inputs.object.id;case st.String:return Y[o.Loop]["string-loop"].inputs.string.id;case st.Counted:return Y[o.Loop]["counted-loop"].inputs.number.id;default:return null}}getCurrentValueBuiltInValueDescriptor(){var n;if(this.declaration.id===st.ManualFlow||this.declaration.id===st.Counted)return null;const i=(n=Y[o.Loop][this.declaration.id].body.inputs.currentValue)==null?void 0:n.id;return i?this.project.get(i):null}getCurrentIterationNumberBuiltInValueDescriptor(){const i=Y[o.Loop][this.declaration.id].body.inputs.iterationNumber.id;return this.project.get(i)}syncBody(i=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,"sync-body"))){var v;const n=[],l=[],c=[],e=[],y=Y[o.Loop][this.declaration.id].body.id,T=this.project.getBuiltIn(y);if(this.body)((v=this.body.implements)==null?void 0:v.id)!==T.id&&(this.body.setImplements(T,i),this.body.setParent(this,i),n.push(this.body));else{const E=Ro.new(i);E.implements=T.toJSON(),E.name=T.name,E.parent=this.toReference();const b=he(E,this.project);b.setParent(this,i),b.initChildren(i),i==null||i.add(b,H.Added),b.addSelfToProject(i),l.push(b)}return i==null||i.attemptAutoclose("sync-body",this.id),{self:this,updated:D(n),added:D(l),removed:D(c),affected:D(e)}}checkIsSynced(){var b,O,_,$,L,U,S,Z,X,ae,Q,fe,oe,ce,me,ne,ye,_e,Ve,Be,xe,Me,We,Se,qe;if((!this.body||!((b=this.body)!=null&&b.dataType)||!((O=this.body)!=null&&O.dataType.entity))&&this.id)return!1;const i=[st.List,st.ObjectKeys,st.ObjectValues,st.String],n=this.body.inputs.find(et=>et.implements.find(ot=>ot.id===Y[o.Loop][this.declaration.id].body.inputs.iterationNumber.id))||null,l=this.body.inputs.find(et=>et.implements.find(ot=>{var dt;return ot.id===((dt=Y[o.Loop][this.declaration.id].body.inputs.currentValue)==null?void 0:dt.id)}))||null;if(!n||i.includes(this.declaration.id)&&!l)return!1;const c=[...this.breakStatements,...this.continueStatements];if(((L=($=(_=this.body)==null?void 0:_.dataType)==null?void 0:$.entity)==null?void 0:L.id)!==Y["primitive-entity"].void.id){if(!this.body.inputs.find(ot=>{var dt,St,wt,Ei,er;return((St=(dt=ot.dataType)==null?void 0:dt.entity)==null?void 0:St.id)===((er=(Ei=(wt=this.body)==null?void 0:wt.dataType)==null?void 0:Ei.entity)==null?void 0:er.id)})||((Z=(S=(U=this.body)==null?void 0:U.dataType)==null?void 0:S.entity)==null?void 0:Z.type)===o.DefinitionEntity&&(!((ae=(X=this.body)==null?void 0:X.dataType)==null?void 0:ae.entity).properties.every(St=>this.outputs.find(wt=>{var Ei;return((Ei=wt.declaration)==null?void 0:Ei.id)===St.id}))||!c.every(St=>{var br,Aa;const wt=St.outputs.filter(vn=>!vn.deleted),Ei=((Aa=(br=this.body)==null?void 0:br.dataType)==null?void 0:Aa.entity).properties.every(vn=>wt.find(Ci=>{var qi;return((qi=Ci.declaration)==null?void 0:qi.id)===vn.id})),er=wt.every(vn=>{var Ci,qi;return((qi=(Ci=this.body)==null?void 0:Ci.dataType)==null?void 0:qi.entity).properties.find(Jl=>{var Yl;return Jl.id===((Yl=vn.declaration)==null?void 0:Yl.id)})});return Ei&&er})))return!1}else if(this.body.inputs.find(dt=>{var St,wt,Ei,er,br;return((wt=(St=dt.dataType)==null?void 0:St.entity)==null?void 0:wt.id)===((br=(er=(Ei=this.body)==null?void 0:Ei.dataType)==null?void 0:er.entity)==null?void 0:br.id)})||this.outputs.length>0||![...this.breakStatements,...this.continueStatements].every(dt=>dt.outputs.filter(St=>!St.deleted).length===0))return!1;if([st.List,st.Counted,st.ObjectKeys,st.ObjectValues,st.String].includes(this.declaration.id)){if(this.inputs.length!==1)return!1;const et=this.inputs[0],ot=this.getValueInputMapDeclarationId();if(((Q=et.declaration)==null?void 0:Q.id)!==ot)return!1}else if(this.inputs.length>0)return!1;if((oe=(fe=this.body)==null?void 0:fe.dataType)!=null&&oe.inferred){const et=this.getUniqueInputMaps();if(c.every(wt=>!wt.readsValue)&&!et.length&&((ne=(me=(ce=this.body)==null?void 0:ce.dataType)==null?void 0:me.entity)==null?void 0:ne.id)!==Y["primitive-entity"].void.id)return!1;const dt=c.find(wt=>wt.readsValue),St=(Ve=(_e=(ye=dt==null?void 0:dt.readsValue)==null?void 0:ye.getDataType(null))==null?void 0:_e.entity)==null?void 0:Ve.id;if(St&&St!==((Me=(xe=(Be=this.body)==null?void 0:Be.dataType)==null?void 0:xe.entity)==null?void 0:Me.id))return!1}const y=((qe=(Se=(We=this.body)==null?void 0:We.dataType)==null?void 0:Se.entity)==null?void 0:qe.properties)||[],T=this.outputs,v=y.every(et=>T.find(ot=>{var dt;return((dt=ot.declaration)==null?void 0:dt.id)===et.id})),E=T.every(et=>y.find(ot=>{var dt;return ot.id===((dt=et.declaration)==null?void 0:dt.id)}));return!(!v||!E)}syncFromDataType(i=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,"sync-from-data-type"))){const n=[],l=[],c=[],e=[],{updated:y,added:T,removed:v}=this.syncOutputDataType(i);n.push(...y),l.push(...T),c.push(...v);const{updated:E,added:b,removed:O}=this.syncBodyArgumentsDeclarations(i);n.push(...E),l.push(...b),c.push(...O);const{updated:_,added:$,removed:L}=this.syncBodyInputIndexes(i);n.push(..._),l.push(...$),c.push(...L);const{updated:U,added:S,removed:Z}=this.syncOutputMaps(i);return n.push(...U),l.push(...S),c.push(...Z),i==null||i.attemptAutoclose("sync-from-data-type",this.id),{self:this,updated:D(n),added:D(l),removed:D(c),affected:D(e)}}syncChildren(i=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,"sync-children"))){const n=[],l=[],c=[],e=[],{updated:y,added:T,removed:v}=this.syncBody(i);n.push(...y),l.push(...T),c.push(...v);const{updated:E,added:b,removed:O}=this.syncInputMaps(i);n.push(...E),l.push(...b),c.push(...O);const{updated:_,added:$,removed:L}=this.syncTerminationStatements(i);n.push(..._),l.push(...$),c.push(...L);const{updated:U,added:S,removed:Z}=this.syncFromDataType(i);return n.push(...U),l.push(...S),c.push(...Z),i==null||i.attemptAutoclose("sync-children",this.id),{self:this,updated:D(n),added:D(l),removed:D(c),affected:D(e)}}getUnusedInputs(){return this.inputs.filter(i=>i.suggestion||!i.readsValue&&!i.defaultValue)}getUnusedOutputs(){return this.outputs.filter(i=>i.suggestion||!i.writesValues.length)}getUsedInputs(){return this.inputs.filter(i=>!i.suggestion&&(i.readsValue||i.defaultValue))}getUsedOutputs(){return this.outputs.filter(i=>!i.suggestion&&i.writesValues.length)}addValueReader(i,n=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,P.AddValueReader))){return this.checkCanEditFromScopeOwnerWithSideEffects(this,P.AddValueReader,n)?this.writesValues.includes(i)?(n==null||n.attemptAutoclose(P.AddValueReader,this.id),this):(this.writesValues.push(i),n==null||n.add(this,H.Affected),this):this}setDataType(i,n=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,P.SetDataType))){if(!this.checkCanEdit(this,n))return ie.Logger.warn(`[setDataType] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),n==null||n.attemptAutoclose(P.SetDataType,this.id),this;const l=this.dataType;return(l==null?void 0:l.id)!==(i==null?void 0:i.id)&&(l==null||l.remove({ignoreUpstream:!0},n),this.dataType=i,this.subscribeToDependencies(),n==null||n.add(this,H.Affected)),n==null||n.attemptAutoclose(P.SetDataType,this.id),this}removeValueReader(i,n=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,P.RemoveValueReader))){return this.checkCanEditFromScopeOwnerWithSideEffects(this,P.RemoveValueReader,n)?this.writesValues.includes(i)?(this.writesValues=this.writesValues.filter(l=>l.id!==i.id),n==null||n.add(this,H.Affected),this):(n==null||n.attemptAutoclose(P.RemoveValueReader,this.id),this):this}removeDataType(i=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,P.RemoveDataType))){return this.checkCanEdit(this,i)?(this.dataType&&(this.dataType.remove({ignoreUpstream:!0},i),i==null||i.add(this,H.Affected),this.dataType=null),i==null||i.attemptAutoclose(P.RemoveDataType,this.id),this):(ie.Logger.warn(`[removeDataType] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(P.RemoveDataType,this.id),this)}getDataType(i=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,"get-data-type"))){var n;return i==null||i.attemptAutoclose("get-data-type",this.id),this.dataType||((n=this.body)==null?void 0:n.dataType)||null}};I(Kt,"repository",{APICreate:async(i,...n)=>i,APIUpdate:async(i,...n)=>i,APIDelete:async(i,...n)=>i,APIClone:async(i,...n)=>{},APILoad:async(i,...n)=>null,APILoadVersion:async(i,n,...l)=>null}),I(Kt,"type",o.Loop),I(Kt,"USER_MANAGED_PARENT_TYPES",[...yr,o.Project]),I(Kt,"PARENT_TYPES",[...Pi.USER_MANAGED_PARENT_TYPES]),I(Kt,"CURRENT_ITERATION_NUMBER_ARG_NAME","Current iteration number"),I(Kt,"CURRENT_VALUE_ARG_NAME","Current value"),I(Kt,"MUTABLE_BASE_PROPERTIES",["catchesError"]),I(Kt,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),I(Kt,"BASE_PROPERTIES",[...Kt.MUTABLE_BASE_PROPERTIES,...Kt.INMUTABLE_BASE_PROPERTIES]),I(Kt,"MUTABLE_META_PROPERTIES",[...Kt.MUTABLE_BASE_PROPERTIES,"x","y"]),I(Kt,"INMUTABLE_META_PROPERTIES",[...Kt.INMUTABLE_BASE_PROPERTIES]),I(Kt,"META_PROPERTIES",[...Kt.MUTABLE_META_PROPERTIES,...Kt.INMUTABLE_META_PROPERTIES]),I(Kt,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry"]),I(Kt,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","declaration","dataType"]),I(Kt,"UPSTREAM_PROPERTIES",[...Kt.MUTABLE_UPSTREAM_PROPERTIES,...Kt.INMUTABLE_UPSTREAM_PROPERTIES]),I(Kt,"MUTABLE_DOWNSTREAM_PROPERTIES",["body","inputs","outputs","successCalls","errorCalls","error","breakStatements","continueStatements"]),I(Kt,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),I(Kt,"DOWNSTREAM_PROPERTIES",[...Kt.MUTABLE_DOWNSTREAM_PROPERTIES,...Kt.INMUTABLE_DOWNSTREAM_PROPERTIES]),I(Kt,"PROPERTIES",[...Kt.META_PROPERTIES,...Kt.UPSTREAM_PROPERTIES,...Kt.DOWNSTREAM_PROPERTIES]);let Iu=Kt;function oPe(d){d.inputs.forEach(n=>n.validate());const i=[...qd(d),...Zd(d)];return rr(d.errors,i)}const s$i=Object.freeze(Object.defineProperty({__proto__:null,validate:oPe},Symbol.toStringTag,{value:"Module"}));var dPe=(d=>(d.Parent="parent",d))(dPe||{});const Ai=class Ai extends Ur{constructor(i,n){super(i);I(this,"initialData");I(this,"id");I(this,"x");I(this,"y");I(this,"type",o.Condition);I(this,"index",null);I(this,"successCalls",[]);I(this,"errorCalls",[]);I(this,"declaration");I(this,"inputs",[]);I(this,"calledBySuccess",[]);I(this,"calledByError",[]);I(this,"calledByEntry",[]);I(this,"andChildrenGroup",null);I(this,"orChildrenGroup",null);I(this,"project");I(this,"errors",[]);I(this,"parent");I(this,"detachedDependents",{});I(this,"knownVersions",null);I(this,"activeVersion",!1);I(this,"initialized",!1);I(this,"startedInitialization",!1);this.initialData=i,this.project=n,this.id=i.id,this.x=i.x,this.y=i.y,this.index=i.index??null}static new(i=null){return{id:x.UUID.uuid(),version:x.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||M().toISOString(),author:(i==null?void 0:i.author)||x.sessionAuthor,previousVersion:null,deleted:!1,deletable:!0,editable:!0,type:o.Condition,declaration:null,index:null,inputs:[],parent:null,andChildrenGroup:null,orChildrenGroup:null,calledByEntry:[],calledBySuccess:[],calledByError:[],errorCalls:[],successCalls:[],x:0,y:0}}static fromGenerationTarget(i,n){var O,_;let l=n;if(i.parent){const $=pe(i.parent);l=n.get($)}const c=i.calledByEntry.map($=>{const L=pe($);return n.get(L)}),e=i.calledBySuccess.map($=>{const L=pe($);return n.get(L)}),y=i.calledByError.map($=>{const L=pe($);return n.get(L)});let T;if(i.declaration){const $=pe(i.declaration);T=n.get($)}let v=null;l&&l.type===o.Condition&&(((O=l.declaration)==null?void 0:O.id)===sr.Or?v=(l.orChildrenGroup||[]).length:((_=l.declaration)==null?void 0:_.id)===sr.And&&(v=(l.andChildrenGroup||[]).length));const E={id:i.id,version:x.UUID.uuid(),createdAt:M().toISOString(),author:x.sessionAuthor,previousVersion:null,deleted:!1,deletable:!0,editable:!0,type:o.Condition,index:v,declaration:T,andChildrenGroup:i.andChildrenGroup?i.andChildrenGroup.map($=>{const L=pe($);return n.get(L)}).filter($=>!!$):null,orChildrenGroup:i.orChildrenGroup?i.orChildrenGroup.map($=>{const L=pe($);return n.get(L)}).filter($=>!!$):null,calledByEntry:c,calledBySuccess:e,calledByError:y,errorCalls:[],successCalls:[],inputs:[],x:0,y:0,parent:l},b=he(E,n);return b.setParent(l,null),b}static validateGenerationTarget(i,n){let l=JSON.parse(JSON.stringify(i));const c=[],e=Tn(l,{parent:{list:!1,types:[...yr,o.Project],optional:!0}},n);return l=e.modifiedData,c.push(...e.errors,...Nr(l)),i.declaration?n.get(i.declaration)?n.conditionDeclarations.find(v=>v.id===i.declaration)||c.push(new De({id:`${i.id}--${re.InvalidImplementsReference}`,code:re.InvalidImplementsReference,severity:ue.Error,message:`Entity of type '${i.type}' with id '${i.id}' has an 'declaration' property that isn't pointing to an action descriptor reserved for '${o.Condition}' entities.
47
47
  ${Fb(n)}`})):c.push(new De({id:`${i.id}--${re.ReferencedEntityNotFound}`,code:re.ReferencedEntityNotFound,severity:ue.Error,message:`Entity of type '${i.type}' with id '${i.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 '${o.Condition}' entities.
48
48
  ${Fb(n)}`})):c.push(new De({id:`${i.id}--${Ie.InvalidObjectStructure}`,code:Ie.InvalidObjectStructure,severity:ue.Error,message:`Entity of type '${i.type}' with id '${i.id}' is missing the 'declaration' property. This property is required for a '${i.type}' entity and must point to one of the built-in action descriptors reserved for '${o.Condition}' entities.
49
49
  ${Fb(n)}`})),{errors:c,modifiedData:l}}validateGeneratedUpdate(i){const n=[];return i.parent&&n.push(new De({id:`${this.id}--${re.InvalidParentUpdate}`,code:re.InvalidParentUpdate,severity:ue.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/dist/index.js CHANGED
@@ -109305,23 +109305,23 @@ You shouldn't have to manually update a 'parent' property. The equivalent result
109305
109305
  switch (this.declaration.id) {
109306
109306
  case st.List: {
109307
109307
  let y = null;
109308
- if (this.inputs.forEach((T) => {
109309
- var v;
109310
- ((v = T.declaration) == null ? void 0 : v.id) === Y[o.Loop]["list-loop"].inputs.list.id ? y = T : (T.remove({ ignoreUpstream: !1 }, i), c.push(T));
109308
+ if (this.inputs.forEach((v) => {
109309
+ var b;
109310
+ ((b = v.declaration) == null ? void 0 : b.id) === Y[o.Loop]["list-loop"].inputs.list.id ? y = v : (v.remove({ ignoreUpstream: !1 }, i), c.push(v));
109311
109311
  }), y) {
109312
109312
  if (y.declaration.id !== Y[o.Loop]["list-loop"].inputs.list.id) {
109313
- const T = this.project.get(
109313
+ const v = this.project.get(
109314
109314
  Y[o.Loop]["list-loop"].inputs.list.id
109315
109315
  );
109316
109316
  y.setDeclaration(
109317
- T,
109317
+ v,
109318
109318
  i
109319
109319
  ), n.push(y);
109320
109320
  }
109321
109321
  } else {
109322
- const T = this.project.get(
109322
+ const v = this.project.get(
109323
109323
  Y[o.Loop]["list-loop"].inputs.list.id
109324
- ), v = {
109324
+ ), b = {
109325
109325
  id: x.UUID.uuid(),
109326
109326
  version: x.UUID.uuid(),
109327
109327
  createdAt: (i == null ? void 0 : i.timestamp) || G().toISOString(),
@@ -109336,16 +109336,27 @@ You shouldn't have to manually update a 'parent' property. The equivalent result
109336
109336
  codeName: null,
109337
109337
  description: null,
109338
109338
  index: 0,
109339
- declaration: T.toJSON(),
109339
+ declaration: v.toJSON(),
109340
109340
  readsValue: null,
109341
109341
  defaultValue: null,
109342
109342
  parent: this.toReference()
109343
- }, b = he(
109344
- v,
109343
+ }, E = he(
109344
+ b,
109345
109345
  this.project
109346
109346
  );
109347
- b.setParent(this, i), b.initChildren(i), i == null || i.add(b, H.Added), b.addSelfToProject(i), l.push(b);
109347
+ E.setParent(this, i), E.initChildren(i), i == null || i.add(E, H.Added), E.addSelfToProject(i), l.push(E);
109348
109348
  }
109349
+ [...this.inputs].forEach((v) => {
109350
+ var b;
109351
+ ((b = v.declaration) == null ? void 0 : b.id) !== Y[o.Loop]["list-loop"].inputs.list.id && (v.remove({ ignoreUpstream: !1 }, i), c.push(v));
109352
+ }), this.inputs.sort(
109353
+ (v, b) => (
109354
+ // Order, place the oldest first, if they don't implement the right declaration last
109355
+ G(v.createdAt).isBefore(G(b.createdAt)) ? -1 : 1
109356
+ )
109357
+ ).forEach((v, b) => {
109358
+ b !== 0 && (v.remove({ ignoreUpstream: !1 }, i), c.push(v));
109359
+ });
109349
109360
  break;
109350
109361
  }
109351
109362
  case st.ManualFlow: {
@@ -109356,23 +109367,23 @@ You shouldn't have to manually update a 'parent' property. The equivalent result
109356
109367
  }
109357
109368
  case st.Counted: {
109358
109369
  let y = null;
109359
- if (this.inputs.forEach((T) => {
109360
- var v;
109361
- ((v = T.declaration) == null ? void 0 : v.id) === Y[o.Loop]["counted-loop"].inputs.number.id ? y = T : (T.remove({ ignoreUpstream: !1 }, i), c.push(T));
109370
+ if (this.inputs.forEach((v) => {
109371
+ var b;
109372
+ ((b = v.declaration) == null ? void 0 : b.id) === Y[o.Loop]["counted-loop"].inputs.number.id ? y = v : (v.remove({ ignoreUpstream: !1 }, i), c.push(v));
109362
109373
  }), y) {
109363
109374
  if (y.declaration.id !== Y[o.Loop]["counted-loop"].inputs.number.id) {
109364
- const T = this.project.get(
109375
+ const v = this.project.get(
109365
109376
  Y[o.Loop]["counted-loop"].inputs.number.id
109366
109377
  );
109367
109378
  y.setDeclaration(
109368
- T,
109379
+ v,
109369
109380
  i
109370
109381
  ), n.push(y);
109371
109382
  }
109372
109383
  } else {
109373
- const T = this.project.get(
109384
+ const v = this.project.get(
109374
109385
  Y[o.Loop]["counted-loop"].inputs.number.id
109375
- ), v = {
109386
+ ), b = {
109376
109387
  id: x.UUID.uuid(),
109377
109388
  version: x.UUID.uuid(),
109378
109389
  createdAt: (i == null ? void 0 : i.timestamp) || G().toISOString(),
@@ -109387,37 +109398,48 @@ You shouldn't have to manually update a 'parent' property. The equivalent result
109387
109398
  codeName: null,
109388
109399
  description: null,
109389
109400
  index: 0,
109390
- declaration: T.toJSON(),
109401
+ declaration: v.toJSON(),
109391
109402
  readsValue: null,
109392
109403
  defaultValue: null,
109393
109404
  parent: this.toReference()
109394
- }, b = he(
109395
- v,
109405
+ }, E = he(
109406
+ b,
109396
109407
  this.project
109397
109408
  );
109398
- b.setParent(this, i), b.initChildren(i), i == null || i.add(b, H.Added), b.addSelfToProject(i), l.push(b);
109409
+ E.setParent(this, i), E.initChildren(i), i == null || i.add(E, H.Added), E.addSelfToProject(i), l.push(E);
109399
109410
  }
109411
+ [...this.inputs].forEach((v) => {
109412
+ var b;
109413
+ ((b = v.declaration) == null ? void 0 : b.id) !== Y[o.Loop]["counted-loop"].inputs.number.id && (v.remove({ ignoreUpstream: !1 }, i), c.push(v));
109414
+ }), this.inputs.sort(
109415
+ (v, b) => (
109416
+ // Order, place the oldest first, if they don't implement the right declaration last
109417
+ G(v.createdAt).isBefore(G(b.createdAt)) ? -1 : 1
109418
+ )
109419
+ ).forEach((v, b) => {
109420
+ b !== 0 && (v.remove({ ignoreUpstream: !1 }, i), c.push(v));
109421
+ });
109400
109422
  break;
109401
109423
  }
109402
109424
  case st.ObjectKeys: {
109403
109425
  let y = null;
109404
- if (this.inputs.forEach((T) => {
109405
- var v;
109406
- ((v = T.declaration) == null ? void 0 : v.id) === Y[o.Loop]["object-keys-loop"].inputs.object.id ? y = T : (T.remove({ ignoreUpstream: !1 }, i), c.push(T));
109426
+ if (this.inputs.forEach((v) => {
109427
+ var b;
109428
+ ((b = v.declaration) == null ? void 0 : b.id) === Y[o.Loop]["object-keys-loop"].inputs.object.id ? y = v : (v.remove({ ignoreUpstream: !1 }, i), c.push(v));
109407
109429
  }), y) {
109408
109430
  if (y.declaration.id !== Y[o.Loop]["object-keys-loop"].inputs.object.id) {
109409
- const T = this.project.get(
109431
+ const v = this.project.get(
109410
109432
  Y[o.Loop]["object-keys-loop"].inputs.object.id
109411
109433
  );
109412
109434
  y.setDeclaration(
109413
- T,
109435
+ v,
109414
109436
  i
109415
109437
  ), n.push(y);
109416
109438
  }
109417
109439
  } else {
109418
- const T = this.project.get(
109440
+ const v = this.project.get(
109419
109441
  Y[o.Loop]["object-keys-loop"].inputs.object.id
109420
- ), v = {
109442
+ ), b = {
109421
109443
  id: x.UUID.uuid(),
109422
109444
  version: x.UUID.uuid(),
109423
109445
  createdAt: (i == null ? void 0 : i.timestamp) || G().toISOString(),
@@ -109432,37 +109454,48 @@ You shouldn't have to manually update a 'parent' property. The equivalent result
109432
109454
  codeName: null,
109433
109455
  description: null,
109434
109456
  index: 0,
109435
- declaration: T.toJSON(),
109457
+ declaration: v.toJSON(),
109436
109458
  readsValue: null,
109437
109459
  defaultValue: null,
109438
109460
  parent: this.toReference()
109439
- }, b = he(
109440
- v,
109461
+ }, E = he(
109462
+ b,
109441
109463
  this.project
109442
109464
  );
109443
- b.setParent(this, i), b.initChildren(i), i == null || i.add(b, H.Added), b.addSelfToProject(i), l.push(b);
109465
+ E.setParent(this, i), E.initChildren(i), i == null || i.add(E, H.Added), E.addSelfToProject(i), l.push(E);
109444
109466
  }
109467
+ [...this.inputs].forEach((v) => {
109468
+ var b;
109469
+ ((b = v.declaration) == null ? void 0 : b.id) !== Y[o.Loop]["object-keys-loop"].inputs.object.id && (v.remove({ ignoreUpstream: !1 }, i), c.push(v));
109470
+ }), this.inputs.sort(
109471
+ (v, b) => (
109472
+ // Order, place the oldest first, if they don't implement the right declaration last
109473
+ G(v.createdAt).isBefore(G(b.createdAt)) ? -1 : 1
109474
+ )
109475
+ ).forEach((v, b) => {
109476
+ b !== 0 && (v.remove({ ignoreUpstream: !1 }, i), c.push(v));
109477
+ });
109445
109478
  break;
109446
109479
  }
109447
109480
  case st.ObjectValues: {
109448
109481
  let y = null;
109449
- if (this.inputs.forEach((T) => {
109450
- var v;
109451
- ((v = T.declaration) == null ? void 0 : v.id) === Y[o.Loop]["object-values-loop"].inputs.object.id ? y = T : (T.remove({ ignoreUpstream: !1 }, i), c.push(T));
109482
+ if (this.inputs.forEach((v) => {
109483
+ var b;
109484
+ ((b = v.declaration) == null ? void 0 : b.id) === Y[o.Loop]["object-values-loop"].inputs.object.id ? y = v : (v.remove({ ignoreUpstream: !1 }, i), c.push(v));
109452
109485
  }), y) {
109453
109486
  if (y.declaration.id !== Y[o.Loop]["object-values-loop"].inputs.object.id) {
109454
- const T = this.project.get(
109487
+ const v = this.project.get(
109455
109488
  Y[o.Loop]["object-values-loop"].inputs.object.id
109456
109489
  );
109457
109490
  y.setDeclaration(
109458
- T,
109491
+ v,
109459
109492
  i
109460
109493
  ), n.push(y);
109461
109494
  }
109462
109495
  } else {
109463
- const T = this.project.get(
109496
+ const v = this.project.get(
109464
109497
  Y[o.Loop]["object-values-loop"].inputs.object.id
109465
- ), v = {
109498
+ ), b = {
109466
109499
  id: x.UUID.uuid(),
109467
109500
  version: x.UUID.uuid(),
109468
109501
  createdAt: (i == null ? void 0 : i.timestamp) || G().toISOString(),
@@ -109477,37 +109510,48 @@ You shouldn't have to manually update a 'parent' property. The equivalent result
109477
109510
  codeName: null,
109478
109511
  description: null,
109479
109512
  index: 0,
109480
- declaration: T.toJSON(),
109513
+ declaration: v.toJSON(),
109481
109514
  readsValue: null,
109482
109515
  defaultValue: null,
109483
109516
  parent: this.toReference()
109484
- }, b = he(
109485
- v,
109517
+ }, E = he(
109518
+ b,
109486
109519
  this.project
109487
109520
  );
109488
- b.setParent(this, i), b.initChildren(i), i == null || i.add(b, H.Added), b.addSelfToProject(i), l.push(b);
109521
+ E.setParent(this, i), E.initChildren(i), i == null || i.add(E, H.Added), E.addSelfToProject(i), l.push(E);
109489
109522
  }
109523
+ [...this.inputs].forEach((v) => {
109524
+ var b;
109525
+ ((b = v.declaration) == null ? void 0 : b.id) !== Y[o.Loop]["object-values-loop"].inputs.object.id && (v.remove({ ignoreUpstream: !1 }, i), c.push(v));
109526
+ }), this.inputs.sort(
109527
+ (v, b) => (
109528
+ // Order, place the oldest first, if they don't implement the right declaration last
109529
+ G(v.createdAt).isBefore(G(b.createdAt)) ? -1 : 1
109530
+ )
109531
+ ).forEach((v, b) => {
109532
+ b !== 0 && (v.remove({ ignoreUpstream: !1 }, i), c.push(v));
109533
+ });
109490
109534
  break;
109491
109535
  }
109492
109536
  case st.String: {
109493
109537
  let y = null;
109494
- if (this.inputs.forEach((T) => {
109495
- var v;
109496
- ((v = T.declaration) == null ? void 0 : v.id) === Y[o.Loop]["string-loop"].inputs.string.id ? y = T : (T.remove({ ignoreUpstream: !1 }, i), c.push(T));
109538
+ if (this.inputs.forEach((v) => {
109539
+ var b;
109540
+ ((b = v.declaration) == null ? void 0 : b.id) === Y[o.Loop]["string-loop"].inputs.string.id ? y = v : (v.remove({ ignoreUpstream: !1 }, i), c.push(v));
109497
109541
  }), y) {
109498
109542
  if (y.declaration.id !== Y[o.Loop]["string-loop"].inputs.string.id) {
109499
- const T = this.project.get(
109543
+ const v = this.project.get(
109500
109544
  Y[o.Loop]["string-loop"].inputs.string.id
109501
109545
  );
109502
109546
  y.setDeclaration(
109503
- T,
109547
+ v,
109504
109548
  i
109505
109549
  ), n.push(y);
109506
109550
  }
109507
109551
  } else {
109508
- const T = this.project.get(
109552
+ const v = this.project.get(
109509
109553
  Y[o.Loop]["string-loop"].inputs.string.id
109510
- ), v = {
109554
+ ), b = {
109511
109555
  id: x.UUID.uuid(),
109512
109556
  version: x.UUID.uuid(),
109513
109557
  createdAt: (i == null ? void 0 : i.timestamp) || G().toISOString(),
@@ -109522,16 +109566,27 @@ You shouldn't have to manually update a 'parent' property. The equivalent result
109522
109566
  codeName: null,
109523
109567
  description: null,
109524
109568
  index: 0,
109525
- declaration: T.toJSON(),
109569
+ declaration: v.toJSON(),
109526
109570
  readsValue: null,
109527
109571
  defaultValue: null,
109528
109572
  parent: this.toReference()
109529
- }, b = he(
109530
- v,
109573
+ }, E = he(
109574
+ b,
109531
109575
  this.project
109532
109576
  );
109533
- b.setParent(this, i), b.initChildren(i), i == null || i.add(b, H.Added), b.addSelfToProject(i), l.push(b);
109577
+ E.setParent(this, i), E.initChildren(i), i == null || i.add(E, H.Added), E.addSelfToProject(i), l.push(E);
109534
109578
  }
109579
+ [...this.inputs].forEach((v) => {
109580
+ var b;
109581
+ ((b = v.declaration) == null ? void 0 : b.id) !== Y[o.Loop]["string-loop"].inputs.string.id && (v.remove({ ignoreUpstream: !1 }, i), c.push(v));
109582
+ }), this.inputs.sort(
109583
+ (v, b) => (
109584
+ // Order, place the oldest first, if they don't implement the right declaration last
109585
+ G(v.createdAt).isBefore(G(b.createdAt)) ? -1 : 1
109586
+ )
109587
+ ).forEach((v, b) => {
109588
+ b !== 0 && (v.remove({ ignoreUpstream: !1 }, i), c.push(v));
109589
+ });
109535
109590
  break;
109536
109591
  }
109537
109592
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elyx-code/project-logic-tree",
3
- "version": "0.0.6669",
3
+ "version": "0.0.6670",
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",