@elyx-code/project-logic-tree 0.0.6427 → 0.0.6428

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -47613,7 +47613,8 @@ g(Zt, "repository", {
47613
47613
  APILoadVersion: async (i, a, ...o) => null
47614
47614
  }), g(Zt, "type", f.Condition), g(Zt, "USER_MANAGED_PARENT_TYPES", [
47615
47615
  ...Br,
47616
- f.Project
47616
+ f.Project,
47617
+ f.Condition
47617
47618
  ]), g(Zt, "PARENT_TYPES", [
47618
47619
  ...Zt.USER_MANAGED_PARENT_TYPES
47619
47620
  ]), g(Zt, "MUTABLE_BASE_PROPERTIES", ["operator"]), g(Zt, "INMUTABLE_BASE_PROPERTIES", [
@@ -76,7 +76,7 @@ You shouldn't have to manually update a 'parent' property. The equivalent result
76
76
  ${bm(a)}`})):p.push(new ee({id:`${i.id}--${k.ReferencedEntityNotFound}`,code:k.ReferencedEntityNotFound,severity:q.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 '${f.Condition}' entities.
77
77
  ${bm(a)}`})):p.push(new ee({id:`${i.id}--${ae.InvalidObjectStructure}`,code:ae.InvalidObjectStructure,severity:q.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 '${f.Condition}' entities.
78
78
  ${bm(a)}`})),{errors:p,modifiedData:o}}validateGeneratedUpdate(i){const a=[];return i.parent&&a.push(new ee({id:`${this.id}--${k.InvalidParentUpdate}`,code:k.InvalidParentUpdate,severity:q.Error,message:`Entity of type '${this.type}' with id '${this.id}' cannot have the 'parent' property updated. The 'parent' on a callable entity, is its scope. It scope is auto-calculated implicitly by the its caller.
79
- If an entity is called by another, they must be in the same scope, which means they have the same parent.`})),{errors:a,modifiedData:i}}subscribeDependents(i){return i.forEach(a=>{this.detachedDependents[a.entity.id]||(this.detachedDependents[a.entity.id]=a)}),this}unsubscribeDependents(i){return i.forEach(a=>{this.detachedDependents[a.entity.id]&&delete this.detachedDependents[a.entity.id]}),this}syncDependents(i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"sync-dependents"))){const a=[],o=[],p=[],e=[];return Object.values(this.detachedDependents).forEach(y=>{const v=y.entity.afterAllChildrenInitialized(i);a.push(...v.updated),o.push(...v.added),p.push(...v.removed),e.push(...v.affected)}),i==null||i.attemptAutoclose("sync-dependents",this.id),{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}onDetachedDependencyRemoved(i,a,o){const p=[],e=[],y=[],v=[];if(a==="parent"){const{updated:E,added:b,removed:A}=this.remove({ignoreUpstream:!1},o);p.push(...E),e.push(...b),y.push(...A)}return{updated:R(p),added:R(e),removed:R(y),affected:R(v),self:this}}onDetachedDependencyRestored(i,a,o){const p=[],e=[],y=[],v=[];if(a==="parent"){const{updated:E,added:b,removed:A}=this.restore({},o);p.push(...E),e.push(...b),y.push(...A)}return{updated:R(p),added:R(e),removed:R(y),affected:R(v),self:this}}unsubscribeFromDependencies(){return this.parent.unsubscribeDependents([{entity:this,field:"parent"}]),this}subscribeToDependencies(){var i;return(i=this.parent)==null||i.subscribeDependents([{entity:this,field:"parent"}]),this}increaseVersion(i){if(i&&!L(i).isValid())throw new Error(`The shared timestamp '${i}' is not a valid ISO 8601 date string.`);return i&&L(i).isSame(L(this.createdAt))?this:(this.previousVersion=this.version,this.version=N.UUID.uuid(),this.createdAt=L(i).toISOString()||L().toISOString(),this)}captureVersion(){var a;const i=((a=this.knownVersions)==null?void 0:a.get(this.version))||new zt(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.declaration=this.declaration,i.andChildrenGroup=this.andChildrenGroup?[...this.andChildrenGroup]:this.andChildrenGroup,i.orChildrenGroup=this.orChildrenGroup?[...this.orChildrenGroup]:this.orChildrenGroup,i.successCalls=[...this.successCalls],i.errorCalls=[...this.errorCalls],i.calledBySuccess=[...this.calledBySuccess],i.calledByError=[...this.calledByError],i.calledByEntry=[...this.calledByEntry],i.parent=this.parent,this}recursiveCaptureUpstreamVersions(i){const a=[],o=[],p=[],e=[];if(this.parent){this.parent.increaseVersion(i);const y=this.parent.recursiveCaptureUpstreamVersions(i);a.push(this.parent,...y.updated),o.push(...y.added),p.push(...y.removed)}return{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}async restoreVersion(i){var v;const a=[],o=[],p=[],e=[];if(this.version===i)return{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this};if(!this.knownVersions){const E=new Map;for(const[b,A]of this.knownVersions||new Map){if(E.set(b,A),A.activeVersion=!1,A.knownVersions)for(const[$,V]of A.knownVersions)E.set($,V);A.knownVersions=null}}let y=(v=this.knownVersions)==null?void 0:v.get(i);if(!y){const E=await this.APILoadVersion({},i);if(!E)throw new Error(`Version with id '${i}' for entity with id '${this.id}' not found.`);y=new zt(E,this.project)}return this.metaSync(y.toShallowJSON(),null),this.previousVersion=y.previousVersion,this.version=y.version,this.createdAt=y.createdAt,this.author=y.author,this.deleted=y.deleted,this.inputs=y.inputs,this.declaration=y.declaration,this.andChildrenGroup=y.andChildrenGroup,this.orChildrenGroup=y.orChildrenGroup,this.successCalls=y.successCalls,this.errorCalls=y.errorCalls,this.calledBySuccess=y.calledBySuccess,this.calledByError=y.calledByError,this.calledByEntry=y.calledByEntry,this.parent=y.parent,{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}updateWithShallowTransfer(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"update-with-shallow-transfer"))){if(this.metaSync(i,a),this.version=i.version,this.createdAt=i.createdAt,this.author=i.author,this.deleted=i.deleted,this.previousVersion=i.previousVersion,i.parent){const o=J(i.parent),p=this.project.get(o),e=this.parent;if(e&&e.id!==(p==null?void 0:p.id)&&this.removeFromParent(a),p)this.setParent(p,a);else throw a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${o}' that isn't found in the project`)}else throw a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(i.declaration){const o=J(i.declaration),p=this.project.get(o);p&&this.setDeclaration(p)}return i.calledByEntry.forEach(o=>{const p=J(o),e=this.project.get(p);e&&(this.addEntryCaller(e,a),e.addCall(this,a))}),[...this.calledByEntry].forEach(o=>{i.calledByEntry.find(e=>J(e)===o.id)||(this.removeCaller(o,a),o.removeCall(this,a))}),i.calledBySuccess.forEach(o=>{const p=J(o),e=this.project.get(p);e&&(this.addSuccessCaller(e,a),e.addSuccessCall(this,a))}),[...this.calledBySuccess].forEach(o=>{i.calledBySuccess.find(e=>J(e)===o.id)||(this.removeCaller(o,a),o.removeCall(this,a))}),i.calledByError.forEach(o=>{const p=J(o),e=this.project.get(p);e&&(this.addErrorCaller(e,a),e.addErrorCall(this,a))}),[...this.calledBySuccess].forEach(o=>{i.calledBySuccess.find(e=>J(e)===o.id)||(this.removeCaller(o,a),o.removeCall(this,a))}),this.captureVersion(),this.subscribeToDependencies(),a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),this}hydrateAncestors(){const i=[],a=[],o=[],p=[];if(this.initialData.parent){const e=J(this.initialData.parent),y=this.project.get(e);if(y)this.setParent(y,null);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${e}' that isn't found in the project`)}else throw new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(this.initialData.declaration){const e=J(this.initialData.declaration),y=this.project.get(e);y&&(this.setDeclaration(y),i.push(y))}return this.initialData.calledByEntry.forEach(e=>{const y=J(e),v=this.project.get(y);v&&this.addEntryCaller(v,null)}),this.initialData.calledBySuccess.forEach(e=>{const y=J(e),v=this.project.get(y);v&&this.addSuccessCaller(v,null)}),this.initialData.calledByError.forEach(e=>{const y=J(e),v=this.project.get(y);v&&this.addErrorCaller(v,null)}),{updated:R(i),added:R(a),removed:R(o),affected:R(p),self:this}}afterAllChildrenInitialized(i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"after-all-children-initialized"))){const a=[],o=[],p=[],e=[];this.initialized=!0;const{updated:y,added:v,removed:E}=this.syncInputs(i);return a.push(...y),o.push(...v),p.push(...E),this.captureVersion(),i==null||i.attemptAutoclose("after-all-children-initialized",this.id),{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}addSelfToProject(i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-self-to-project"))){const a=[this],o=[],p=[],e=[];return this.parent===this.project&&this.project.addCondition(this),this.successCalls.forEach(y=>{y.addSuccessCaller(this,i),a.push(y)}),this.errorCalls.forEach(y=>{y.addErrorCaller(this,i),a.push(y)}),this.calledByEntry.forEach(y=>{y.addCall(this,i),a.push(y)}),this.calledBySuccess.forEach(y=>{y.addSuccessCall(this,i),a.push(y)}),this.calledByError.forEach(y=>{y.addErrorCall(this,i),a.push(y)}),this.subscribe(),this.subscribeToDependencies(),i==null||i.attemptAutoclose("add-self-to-project",this.id),{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}removeInput(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-input"))){const o=this.inputs.findIndex(p=>p.id===i.id);return o>-1&&(this.inputs.splice(o,1),a&&(a==null||a.add(this,F.Affected))),a==null||a.attemptAutoclose("remove-input",this.id),this}addInput(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-input"))){return this.inputs.includes(i)?(a==null||a.attemptAutoclose("add-input",this.id),this):(this.inputs.push(i),a==null||a.add(this,F.Affected),a==null||a.attemptAutoclose("add-input",this.id),this)}addOutput(i){return this}removeOutput(i){return this}addSuccessCaller(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-success-caller")),o=!1){return this.calledBySuccess.find(p=>p.id===i.id)||(this.calledBySuccess.push(i),a==null||a.add(this,F.Updated),o&&We(this,a)),a==null||a.attemptAutoclose("add-success-caller",this.id),this}addErrorCaller(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-error-caller")),o=!1){return this.calledByError.find(p=>p.id===i.id)||(this.calledByError.push(i),a==null||a.add(this,F.Updated),o&&We(this,a)),a==null||a.attemptAutoclose("add-error-caller",this.id),this}addEntryCaller(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-entry-caller")),o=!1){return this.calledByEntry.find(p=>p.id===i.id)||(this.calledByEntry.push(i),a==null||a.add(this,F.Updated),o&&We(this,a)),a==null||a.attemptAutoclose("add-entry-caller",this.id),this}addErrorCall(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-error-call")),o=!1){return this.errorCalls.find(p=>p.id===i.id)||(this.errorCalls.push(i),o&&We(this,a),a==null||a.add(this,F.Affected)),a==null||a.attemptAutoclose("add-error-call",this.id),this}addSuccessCall(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-success-call")),o=!1){return this.successCalls.find(p=>p.id===i.id)||(this.successCalls.push(i),o&&We(this,a),a==null||a.add(this,F.Affected)),a==null||a.attemptAutoclose("add-success-call",this.id),this}removeCall(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-call")),o=!1){const p=this.successCalls.findIndex(y=>y.id===i.id);p>-1&&(this.successCalls.splice(p,1),a==null||a.add(this,F.Affected));const e=this.errorCalls.findIndex(y=>y.id===i.id);return e>-1&&(this.errorCalls.splice(e,1),a==null||a.add(this,F.Affected)),o&&We(this,a),a==null||a.attemptAutoclose("remove-call",this.id),this}removeCaller(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-caller")),o=!1){return this.calledBySuccess=this.calledBySuccess.filter(p=>p.id!==i.id?!0:(a==null||a.add(this,F.Updated),a==null||a.add(p,F.Affected),!1)),this.calledByError=this.calledByError.filter(p=>p.id!==i.id?!0:(a==null||a.add(this,F.Updated),a==null||a.add(p,F.Affected),!1)),this.calledByEntry=this.calledByEntry.filter(p=>p.id!==i.id?!0:(a==null||a.add(this,F.Updated),a==null||a.add(p,F.Affected),!1)),o&&We(this,a),a==null||a.attemptAutoclose("remove-caller",this.id),this}setParent(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"set-parent"))){var o;return((o=this.parent)==null?void 0:o.id)!==(i==null?void 0:i.id)&&(this.parent=i,a&&(a==null||a.add(this,F.Updated))),a==null||a.attemptAutoclose("set-parent",this.id),this}removeChildGroup(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-child-group"))){if(this.andChildrenGroup){const o=this.andChildrenGroup.findIndex(p=>p.id===i.id);o!==-1&&(this.andChildrenGroup.splice(o,1),a==null||a.add(this,F.Updated))}if(this.orChildrenGroup){const o=this.orChildrenGroup.findIndex(p=>p.id===i.id);o!==-1&&(this.orChildrenGroup.splice(o,1),a==null||a.add(this,F.Updated))}return a==null||a.attemptAutoclose("remove-child-group",this.id),this}setDeclaration(i){return this.declaration=i,this}initChildren(i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.declaration=te(this.initialData.declaration,this.project),this.initialData.andChildrenGroup&&(this.andChildrenGroup=this.initialData.andChildrenGroup.map(a=>{const o=te(a,this.project);return o.setParent(this,null),o.initChildren(i),o})),this.initialData.orChildrenGroup&&(this.orChildrenGroup=this.initialData.orChildrenGroup.map(a=>{const o=te(a,this.project);return o.setParent(this,null),o.initChildren(i),o})),this.successCalls=this.initialData.successCalls.map(a=>{const o=te(a,this.project);if(o.addSuccessCaller(this),[f.BreakStatement,f.ContinueStatement].includes(o.type))o.setParent(this.parent.parent,null),o.initChildren(i);else if(o.type===f.ReturnStatement){const p=Wr(this,this.project);o.setParent(p,null),o.initChildren(i)}else o.type!==f.InternalCall&&(o.setParent(this.parent,null),o.initChildren(i));return o}),this.errorCalls=this.initialData.errorCalls.map(a=>{const o=te(a,this.project);if(o.addErrorCaller(this),[f.BreakStatement,f.ContinueStatement].includes(o.type))o.setParent(this.parent.parent,null),o.initChildren(i);else if(o.type===f.ReturnStatement){const p=Wr(this,this.project);o.setParent(p,null),o.initChildren(i)}else o.type!==f.InternalCall&&(o.setParent(this.parent,null),o.initChildren(i));return o}),this.inputs=this.initialData.inputs.map(a=>{const o=te(a,this.project);return o.setParent(this,null),o.initChildren(i),o}),this.subscribeToDependencies(),this.afterAllChildrenInitialized(i),i==null||i.attemptAutoclose("init-children",this.id),this)}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"meta-sync"))){const o=Ur(this,i),p=this.toMeta();return this.x=i.x||p.x,this.y=i.y||p.y,super.metaSync(i),i.deleted===!0&&!p.deleted?a==null||a.add(this,F.Removed):i.deleted===!1&&p.deleted?a==null||a.add(this,F.Added):o&&(a==null||a.add(this,F.Updated)),a==null||a.attemptAutoclose("meta-sync",this.id),this}async APILoad(i=ve,...a){return await zt.repository.APILoad(this.id,...a),this}async APICreate(i=ve,...a){return await zt.repository.APICreate(this.toShallowJSON(),...a),this}async APIUpdate(i=ve,...a){return await zt.repository.APIUpdate(this.toShallowJSON(),...a),this}async APIDelete(i=ve,...a){return await zt.repository.APIDelete(this.toShallowJSON(),...a),this}async APIClone(i=ve,...a){return await zt.repository.APIClone(this.id,...a),this}async APILoadVersion(i=ve,a,...o){return await zt.repository.APILoadVersion(this.id,a,...o)}removeFromParent(i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-from-parent"))){var y;const a=[],o=[],p=[],e=[];return this.parent.type===f.Project?(this.parent.removeCondition(this),e.push(this.parent)):((y=this.parent)==null?void 0:y.type)===f.Condition?this.parent.removeChildGroup(this):this.parent.detachedChildren.includes(this)&&this.parent.unsubscribeDetachedChild(this),i==null||i.attemptAutoclose("remove-from-parent",this.id),{added:R(p),updated:R(a),removed:R(o),affected:R(e),self:this}}remove({ignoreUpstream:i}={ignoreUpstream:!1},a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-entity"))){const o=[],p=[],e=[],y=[];if(a!=null&&a.hasRemoved(this.id))return a==null||a.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(p.push(this),this.unsubscribe(),this.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},a),Object.values(this.detachedDependents).forEach(v=>{const{updated:E,removed:b,added:A}=v.entity.onDetachedDependencyRemoved(this,v.field,a);o.push(...E),p.push(...b),e.push(...A)}),this.andChildrenGroup&&this.andChildrenGroup.forEach(v=>{const{removed:E,updated:b}=v.remove({ignoreUpstream:!0},a);p.push(...E),o.push(...b)}),this.orChildrenGroup&&this.orChildrenGroup.forEach(v=>{const{removed:E,updated:b}=v.remove({ignoreUpstream:!0},a);p.push(...E),o.push(...b)}),this.inputs.forEach(v=>{const{updated:E,removed:b}=v.remove({ignoreUpstream:!0},a);o.push(...E),p.push(...b)}),this.successCalls.forEach(v=>{o.push(v),v.removeCaller(this,a)}),this.errorCalls.forEach(v=>{o.push(v),v.removeCaller(this,a)}),!i){const v=this.removeFromParent(a);e.push(...v.added),o.push(...v.updated),p.push(...v.removed),y.push(...v.affected),this.calledBy.forEach(E=>{o.push(E),E.removeCall(this,a)})}return a==null||a.attemptAutoclose("remove-entity",this.id),{added:R(e),updated:R(o),removed:R(p),affected:R(y),self:this}}restore({}={},i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"restore-entity"))){const a=[],o=[],p=[],e=[];return i!=null&&i.hasAdded(this.id)?(i==null||i.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},i),Object.values(this.detachedDependents).forEach(y=>{const{updated:v,removed:E,added:b}=y.entity.onDetachedDependencyRestored(this,y.field,i);o.push(...v),p.push(...E),a.push(...b)}),this.andChildrenGroup&&this.andChildrenGroup.forEach(y=>{const{updated:v,added:E}=y.restore({},i);o.push(...v),a.push(...E)}),this.orChildrenGroup&&this.orChildrenGroup.forEach(y=>{const{updated:v,added:E}=y.restore({},i);o.push(...v),a.push(...E)}),this.inputs.forEach(y=>{const{updated:v}=y.restore({},i);o.push(...v)}),this.successCalls.forEach(y=>{o.push(y),y.addSuccessCaller(this,i)}),this.errorCalls.forEach(y=>{o.push(y),y.addErrorCaller(this,i)}),this.calledBySuccess.forEach(y=>{o.push(y),y.addSuccessCall(this,i)}),this.calledByError.forEach(y=>{o.push(y),y.addErrorCall(this,i)}),this.calledByEntry.forEach(y=>{o.push(y),y.addCall(this,i)}),this.parent.type===f.Project&&this.project.addCondition(this),i==null||i.attemptAutoclose("restore-entity",this.id),{added:R(a),updated:R(o),removed:R(p),affected:R(e),self:this})}toFlat(i=new Set){var o,p;return i.has(this.id)?[]:(i.add(this.id),[this,...((o=this.andChildrenGroup)==null?void 0:o.flatMap(e=>e.toFlat(i)))||[],...((p=this.orChildrenGroup)==null?void 0:p.flatMap(e=>e.toFlat(i)))||[],...this.inputs.flatMap(e=>e.toFlat(i)),...this.successCalls.flatMap(e=>e.toFlat(i)),...this.errorCalls.flatMap(e=>e.toFlat(i)),...this.calledBy.flatMap(e=>e.toFlat(i))])}toFlatIds(i=new Set){var o,p;return i.has(this.id)?[]:(i.add(this.id),[this.id,...((o=this.andChildrenGroup)==null?void 0:o.flatMap(e=>e.toFlatIds(i)))||[],...((p=this.orChildrenGroup)==null?void 0:p.flatMap(e=>e.toFlatIds(i)))||[],...this.inputs.flatMap(e=>e.toFlatIds(i)),...this.successCalls.flatMap(e=>e.toFlatIds(i)),...this.errorCalls.flatMap(e=>e.toFlatIds(i)),...this.calledBy.flatMap(e=>e.toFlatIds(i))])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,x:this.x,y:this.y,type:this.type}}toJSON(i=new Set){var a,o;return i.has(this.id)?this.toReference():(i.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,declaration:this.declaration.toJSON(i),andChildrenGroup:((a=this.andChildrenGroup)==null?void 0:a.map(p=>p.toJSON(i)))||null,orChildrenGroup:((o=this.orChildrenGroup)==null?void 0:o.map(p=>p.toJSON(i)))||null,successCalls:this.successCalls.map(p=>p.toJSON(i)),errorCalls:this.errorCalls.map(p=>p.toJSON(i)),calledBySuccess:this.calledBySuccess.map(p=>p.toReference()),calledByError:this.calledByError.map(p=>p.toReference()),calledByEntry:this.calledByEntry.map(p=>p.toReference()),inputs:this.inputs.map(p=>p.toJSON(i)),parent:this.parent.toReference()})}toJSONClone(i=ke){var o,p,e,y,v,E,b;let a;return(o=i.seenEntityMaps)!=null&&o.has(this.id)?a=i.seenEntityMaps.get(this.id):(a=i.newId||Sr(this,this.project,i.uuidStrategy),i.seenEntityMaps&&i.seenEntityMaps.set(this.id,a)),(p=i.seenEntities)!=null&&p.has(a)||(e=i.seenEntities)!=null&&e.has(this.id)?this.toReference({seenEntityMaps:i.seenEntityMaps}):((y=i.seenEntities)==null||y.add(a),(v=i.seenEntities)==null||v.add(this.id),{id:a,version:N.UUID.uuid(),createdAt:i.timestamp||L().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,declaration:this.declaration.toJSON(),andChildrenGroup:((E=this.andChildrenGroup)==null?void 0:E.map(A=>A.toJSONClone({...i,newId:null})))||null,orChildrenGroup:((b=this.orChildrenGroup)==null?void 0:b.map(A=>A.toJSONClone({...i,newId:null})))||null,successCalls:this.successCalls.map(A=>A.toJSONClone({...i,newId:null})),errorCalls:this.errorCalls.map(A=>A.toJSONClone({...i,newId:null})),calledBySuccess:this.calledBySuccess.map(A=>A.toReference({seenEntityMaps:i.seenEntityMaps})),calledByError:this.calledByError.map(A=>A.toReference({seenEntityMaps:i.seenEntityMaps})),calledByEntry:this.calledByEntry.map(A=>A.toReference({seenEntityMaps:i.seenEntityMaps})),inputs:this.inputs.map(A=>A.toJSONClone({...i,newId:null})),parent:this.parent.toReference({seenEntityMaps:i.seenEntityMaps})})}toReference(i=ke){var o;let a=this.id;return(o=i.seenEntityMaps)!=null&&o.has(this.id)&&(a=i.seenEntityMaps.get(this.id)),{id:a+"--"+N.UUID.uuid()+"--ref",type:f.GenericReference,entityId:a,version:this.version,entityType:this.type}}toShallowJSON(i=ke){var o,p,e;let a=this.id;return(o=i.seenEntityMaps)!=null&&o.has(this.id)&&(a=i.seenEntityMaps.get(this.id)),{id:a,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,declaration:this.declaration.toReference(i),andChildrenGroup:((p=this.andChildrenGroup)==null?void 0:p.map(y=>y.toReference(i)))||null,orChildrenGroup:((e=this.orChildrenGroup)==null?void 0:e.map(y=>y.toReference(i)))||null,inputs:this.inputs.map(y=>y.toReference(i)),successCalls:this.successCalls.map(y=>y.toReference(i)),errorCalls:this.errorCalls.map(y=>y.toReference(i)),calledBySuccess:this.calledBySuccess.map(y=>y.toReference(i)),calledByError:this.calledByError.map(y=>y.toReference(i)),calledByEntry:this.calledByEntry.map(y=>y.toReference(i)),parent:this.parent.toReference(i)}}toFlatJSON(i=new Set){var o,p;return i.has(this.id)?[]:(i.add(this.id),[this.toShallowJSON(),...((o=this.andChildrenGroup)==null?void 0:o.flatMap(e=>e.toFlatJSON(i)))||[],...((p=this.orChildrenGroup)==null?void 0:p.flatMap(e=>e.toFlatJSON(i)))||[],...this.inputs.flatMap(e=>e.toFlatJSON(i)),...this.successCalls.flatMap(e=>e.toFlatJSON(i)),...this.errorCalls.flatMap(e=>e.toFlatJSON(i)),...this.calledBy.flatMap(e=>e.toFlatJSON(i))])}toGenerationTarget(){const i=this.parent.type===f.Project?void 0:this.parent.id;return{id:this.id,type:this.type,declaration:this.declaration.id,calledByEntry:this.calledByEntry.map(a=>a.id),calledBySuccess:this.calledBySuccess.map(a=>a.id),calledByError:this.calledByError.map(a=>a.id),parent:i}}toFlatGenerationTarget(i=new Set){var o,p;return i.has(this.id)?[]:(i.add(this.id),[this.toGenerationTarget(),...((o=this.andChildrenGroup)==null?void 0:o.flatMap(e=>e.toFlatGenerationTarget(i)))||[],...((p=this.orChildrenGroup)==null?void 0:p.flatMap(e=>e.toFlatGenerationTarget(i)))||[],...this.inputs.flatMap(e=>e.toFlatGenerationTarget(i)),...this.successCalls.flatMap(e=>e.toFlatGenerationTarget(i)),...this.errorCalls.flatMap(e=>e.toFlatGenerationTarget(i))])}clearErrors(){var i,a;return this.errors=[],(i=this.andChildrenGroup)==null||i.forEach(o=>o.clearErrors()),(a=this.orChildrenGroup)==null||a.forEach(o=>o.clearErrors()),this.inputs.forEach(o=>o.clearErrors()),this.successCalls.forEach(o=>o.clearErrors()),this.errorCalls.forEach(o=>o.clearErrors()),this}validate(){const i=zj(this);return this.errors=i,{success:!0}}getErrors(){return[...this.errors,...this.inputs.flatMap(a=>a.getErrors())]}getShallowErrors(){return this.errors}clone(i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"clone-entity")),a=null,o=null,p=!0){var S,K,Z;let e=Fr(a,this);const y=this.toJSON(),v=o||N.UUID.uuid();y.inputs=[];const E=v.split("-id"),b=E[E.length-1||0]||v;y.id=v,y.version=N.UUID.uuid(),y.createdAt=(i==null?void 0:i.timestamp)||L().toISOString(),y.author=(i==null?void 0:i.author)||"1",y.previousVersion=null,y.deleted=!1;const A=lr(y,e);a?A.setParent(a,null):A.setParent(this.parent,null),p&&A.subscribe(),A.initChildren(i),i==null||i.add(A,F.Added);const $=(S=this.andChildrenGroup)==null?void 0:S.map(ie=>ie.clone(i,A,N.UUID.uuid(),p)),V=(K=this.orChildrenGroup)==null?void 0:K.map(ie=>ie.clone(i,A,N.UUID.uuid(),p));A.andChildrenGroup=$||null,A.orChildrenGroup=V||null;const U=(Z=this.inputs)==null?void 0:Z.map((ie,X)=>ie.clone(i,A,b+"-input-map-"+X+"-id",p));return A.inputs=U,i==null||i.attemptAutoclose("clone-entity",this.id),A}addToAndGroup(i){return this.andChildrenGroup||(this.andChildrenGroup=[]),this.andChildrenGroup.includes(i)||this.andChildrenGroup.push(i),this}addToOrGroup(i){return this.orChildrenGroup||(this.orChildrenGroup=[]),this.orChildrenGroup.includes(i)||this.orChildrenGroup.push(i),this}removeUnrecognizedInputs(i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-unrecognized-inputs"))){const a=[],o=[],p=[],e=[];return this.inputs.forEach(v=>{if(!this.declaration.inputs.find(b=>{var A;return b.id===((A=v.declaration)==null?void 0:A.id)})){const b=v.remove({ignoreUpstream:!1},i);p.push(...b.removed),a.push(...b.updated)}}),this.inputs.filter((v,E)=>{const b=this.inputs.findIndex($=>$.declaration===v.declaration&&$!==v);if(b===-1)return!1;const A=this.inputs[b];return L(A==null?void 0:A.createdAt).isSame(L(v.createdAt))?E>b:!!L(A==null?void 0:A.createdAt).isAfter(v.createdAt)}).forEach(v=>{const E=v.remove({ignoreUpstream:!1},i);p.push(...E.removed),a.push(...E.updated)}),i==null||i.attemptAutoclose("remove-unrecognized-inputs",this.id),{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}syncInputs(i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"sync-missing-fixed-inputs"))){const a=[],o=[],p=[],e=[],y=this.declaration.inputs.filter(A=>A.parentRelationType===de.FixedArguments&&!this.inputs.find($=>$.declaration.id===A.id));this.inputs.sort((A,$)=>A.index-$.index),y.forEach(A=>{this.inputs.forEach(U=>{U.index>=A.index&&U.metaSync({index:U.index+1},i)});const $={id:N.UUID.uuid(),version:N.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||L().toISOString(),author:N.sessionAuthor,previousVersion:null,deleted:!1,type:f.InputMap,declaration:A.toJSON(),readsValue:null,defaultValue:null,index:A.index,name:null,codeName:null,description:null,parent:this.toReference()},V=te($,this.project);V.setParent(this,i),V.initChildren(i),i==null||i.add(V,F.Added),V.addSelfToProject(i)}),this.inputs.sort((A,$)=>A.index-$.index);const{updated:v,added:E,removed:b}=this.removeUnrecognizedInputs(i);return a.push(...v),o.push(...E),p.push(...b),i==null||i.attemptAutoclose("sync-missing-fixed-inputs",this.id),{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}getUnusedInputs(){return this.inputs.filter(i=>i.suggestion||!i.readsValue&&!i.defaultValue)}getUnusedOutputs(){return[]}getUsedInputs(){return this.inputs.filter(i=>!i.suggestion&&(i.readsValue||i.defaultValue))}getUsedOutputs(){return[]}};g(zt,"repository",{APICreate:async(i,...a)=>i,APIUpdate:async(i,...a)=>i,APIDelete:async(i,...a)=>i,APIClone:async(i,...a)=>{},APILoad:async(i,...a)=>null,APILoadVersion:async(i,a,...o)=>null}),g(zt,"type",f.Condition),g(zt,"USER_MANAGED_PARENT_TYPES",[...Mr,f.Project]),g(zt,"PARENT_TYPES",[...zt.USER_MANAGED_PARENT_TYPES]),g(zt,"MUTABLE_BASE_PROPERTIES",["operator"]),g(zt,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),g(zt,"BASE_PROPERTIES",[...zt.MUTABLE_BASE_PROPERTIES,...zt.INMUTABLE_BASE_PROPERTIES]),g(zt,"MUTABLE_META_PROPERTIES",["x","y"]),g(zt,"INMUTABLE_META_PROPERTIES",[...zt.INMUTABLE_BASE_PROPERTIES]),g(zt,"META_PROPERTIES",[...zt.MUTABLE_META_PROPERTIES,...zt.INMUTABLE_META_PROPERTIES]),g(zt,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry","parent"]),g(zt,"INMUTABLE_UPSTREAM_PROPERTIES",[]),g(zt,"UPSTREAM_PROPERTIES",[...zt.MUTABLE_UPSTREAM_PROPERTIES,...zt.INMUTABLE_UPSTREAM_PROPERTIES]),g(zt,"MUTABLE_DOWNSTREAM_PROPERTIES",["andChildrenGroup","orChildrenGroup","successCalls","errorCalls","inputsDeclarations","inputs"]),g(zt,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),g(zt,"DOWNSTREAM_PROPERTIES",[...zt.MUTABLE_DOWNSTREAM_PROPERTIES,...zt.INMUTABLE_DOWNSTREAM_PROPERTIES]),g(zt,"PROPERTIES",[...zt.META_PROPERTIES,...zt.UPSTREAM_PROPERTIES,...zt.DOWNSTREAM_PROPERTIES]);let oo=zt;function Qj(d){var y;const u=Eme(),i=d.toJSON();u.safeParse(i).success,(y=d.dataType)==null||y.validate(),d.inputs.forEach(v=>v.validate()),d.outputs.forEach(v=>v.validate()),d.internalCalls.forEach(v=>v.validate());const p=[...Ua(d),...Io(d),...e3(d)],e=$b(d);return p.push(...e),vr(d.errors,p)}function e3(d){const u=[],i=d.name;if(!i){const $=ft({id:`${d.id}--${ae.EmptyName}`,message:`Variable declaration "${ne(d,d.project)}" with id "${d.id}" does not have a name. Entities of type ${d.type} must have valid names.`,severity:q.Error,code:ae.EmptyName,entity:d});return u.push($.error),u}const o=[...d.project.functions,...d.project.entities.flatMap($=>$.methods)].filter($=>$.id!==d.id),p=i.trim(),e=!o.some($=>$.name===i||$.name===p);if(!e){const $=ft({id:`${d.id}--${ae.NameNotUniqueInScope}`,message:`Variable declaration "${ne(d,d.project)}" with id "${d.id}" does not have a unique name. Entities of type ${d.type} must have valid names among all other entities of its type.`,severity:q.Error,code:ae.NameNotUniqueInScope,entity:d});u.push($.error)}const y=jr(i);if(!!o.some($=>jr($.name)===y)&&e){const $=ft({id:`${d.id}--${ae.NameAsResolvedCodeNameNotUniqueInScope}`,message:`Variable declaration "${ne(d,d.project)}" with id "${d.id}" does not have a unique name once it is resolved as it will appear in code: "${y}". Entities of type ${d.type} must have valid names including their code name form.`,severity:q.Error,code:ae.NameAsResolvedCodeNameNotUniqueInScope,entity:d});u.push($.error)}if(!/^[a-zA-Z_]/.test(i)){const $=ft({id:`${d.id}--${ae.NameMustStartWithLetterOrUnderscore}`,message:`Variable declaration "${ne(d,d.project)}" with id "${d.id}" has a name that does not start with a letter or underscore.`,severity:q.Error,code:ae.NameMustStartWithLetterOrUnderscore,entity:d});u.push($.error)}const b=i.substring(1);if(!/^[a-zA-Z0-9_ ]*$/.test(b)){const $=ft({id:`${d.id}--${ae.NameCanOnlyContainLettersNumbersUnderscoreAndSpaces}`,message:`Variable declaration "${ne(d,d.project)}" with id "${d.id}" has a name that contains invalid characters. It can only contain letters, numbers, underscores and spaces.`,severity:q.Error,code:ae.NameCanOnlyContainLettersNumbersUnderscoreAndSpaces,entity:d});u.push($.error)}return u}const o0e=Object.freeze(Object.defineProperty({__proto__:null,validate:Qj,validateVariableDeclarationName:e3},Symbol.toStringTag,{value:"Module"}));function t3(d){const u=Sye(),i=d.toJSON();u.safeParse(i).success,d.inputs.forEach(y=>y.validate()),d.outputs.forEach(y=>y.validate()),d.internalCalls.forEach(y=>y.validate());const p=[...Ua(d),...Io(d)],e=$b(d);return p.push(...e),vr(d.errors,p)}const l0e=Object.freeze(Object.defineProperty({__proto__:null,validate:t3},Symbol.toStringTag,{value:"Module"}));var pA=(d=>(d.Parent="parent",d.DataTypeEntity="data-type-entity",d.VarDeclaration="var-declaration",d))(pA||{});const xt=class xt extends Nr{constructor(i,a){super(i);g(this,"initialData");g(this,"id");g(this,"x");g(this,"y");g(this,"type",f.VariableInstance);g(this,"defaultValue",null);g(this,"writesValues",[]);g(this,"readsValue",null);g(this,"declaration");g(this,"inputs",[]);g(this,"outputs",[]);g(this,"calledBySuccess",[]);g(this,"calledByError",[]);g(this,"calledByEntry",[]);g(this,"successCalls",[]);g(this,"errorCalls",[]);g(this,"internalCalls",[]);g(this,"project");g(this,"errors",[]);g(this,"parent");g(this,"detachedDependents",{});g(this,"knownVersions",null);g(this,"activeVersion",!1);g(this,"initialized",!1);g(this,"startedInitialization",!1);g(this,"suggestion",!1);g(this,"_codeNativeValueValidation",null);this.initialData=i,this.project=a,this.id=i.id,this.x=i.x,this.y=i.y}static new(i=null){return{id:N.UUID.uuid(),version:N.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||L().toISOString(),author:(i==null?void 0:i.author)||N.sessionAuthor,previousVersion:null,deleted:!1,type:f.VariableInstance,declaration:null,internalCalls:[],successCalls:[],errorCalls:[],readsValue:null,writesValues:[],defaultValue:null,inputs:[],outputs:[],parent:null,calledByEntry:[],calledBySuccess:[],calledByError:[],x:0,y:0}}static fromGenerationTarget(i,a){let o=a;if(i.parent){const V=J(i.parent);o=a.get(V)}const p=J(i.declaration),e=a.get(p),y=i.calledByEntry.map(V=>{const U=J(V);return a.get(U)}),v=i.calledBySuccess.map(V=>{const U=J(V);return a.get(U)}),E=i.calledByError.map(V=>{const U=J(V);return a.get(U)});let b=null;if(i.readsValue){const V=J(i.readsValue);b=a.get(V)}const A={id:i.id,version:N.UUID.uuid(),createdAt:L().toISOString(),author:N.sessionAuthor,previousVersion:null,deleted:!1,type:f.VariableInstance,declaration:e.toReference(),calledByEntry:y,calledBySuccess:v,calledByError:E,defaultValue:null,errorCalls:[],successCalls:[],internalCalls:[],readsValue:b,inputs:[],outputs:[],writesValues:[],x:0,y:0,parent:o},$=te(A,a);return $.setParent(o,null),$}static validateGenerationTarget(i,a){let o=JSON.parse(JSON.stringify(i));const p=[],e=oi(o,{parent:{list:!1,types:[...Mr,f.Project],optional:!0},declaration:{list:!1,types:[f.VariableDeclaration]}},a);return o=e.modifiedData,p.push(...e.errors,...Br(o)),{errors:p,modifiedData:o}}get codeName(){var i;return(i=this.declaration)==null?void 0:i.codeName}get codeNativeValueValidation(){var i;return this._codeNativeValueValidation||((i=this.declaration)==null?void 0:i.codeNativeValueValidation)||null}validateGeneratedUpdate(i){const a=[];let o=JSON.parse(JSON.stringify(i));const p=zp(o,this);return o=p.modifiedData,a.push(...p.errors),i.parent&&a.push(new ee({id:`${this.id}--${k.InvalidParentUpdate}`,code:k.InvalidParentUpdate,severity:q.Error,message:`Entity of type '${this.type}' with id '${this.id}' cannot have the 'parent' property updated. The 'parent' on a callable entity, is its scope. It scope is auto-calculated implicitly by the its caller.
79
+ If an entity is called by another, they must be in the same scope, which means they have the same parent.`})),{errors:a,modifiedData:i}}subscribeDependents(i){return i.forEach(a=>{this.detachedDependents[a.entity.id]||(this.detachedDependents[a.entity.id]=a)}),this}unsubscribeDependents(i){return i.forEach(a=>{this.detachedDependents[a.entity.id]&&delete this.detachedDependents[a.entity.id]}),this}syncDependents(i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"sync-dependents"))){const a=[],o=[],p=[],e=[];return Object.values(this.detachedDependents).forEach(y=>{const v=y.entity.afterAllChildrenInitialized(i);a.push(...v.updated),o.push(...v.added),p.push(...v.removed),e.push(...v.affected)}),i==null||i.attemptAutoclose("sync-dependents",this.id),{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}onDetachedDependencyRemoved(i,a,o){const p=[],e=[],y=[],v=[];if(a==="parent"){const{updated:E,added:b,removed:A}=this.remove({ignoreUpstream:!1},o);p.push(...E),e.push(...b),y.push(...A)}return{updated:R(p),added:R(e),removed:R(y),affected:R(v),self:this}}onDetachedDependencyRestored(i,a,o){const p=[],e=[],y=[],v=[];if(a==="parent"){const{updated:E,added:b,removed:A}=this.restore({},o);p.push(...E),e.push(...b),y.push(...A)}return{updated:R(p),added:R(e),removed:R(y),affected:R(v),self:this}}unsubscribeFromDependencies(){return this.parent.unsubscribeDependents([{entity:this,field:"parent"}]),this}subscribeToDependencies(){var i;return(i=this.parent)==null||i.subscribeDependents([{entity:this,field:"parent"}]),this}increaseVersion(i){if(i&&!L(i).isValid())throw new Error(`The shared timestamp '${i}' is not a valid ISO 8601 date string.`);return i&&L(i).isSame(L(this.createdAt))?this:(this.previousVersion=this.version,this.version=N.UUID.uuid(),this.createdAt=L(i).toISOString()||L().toISOString(),this)}captureVersion(){var a;const i=((a=this.knownVersions)==null?void 0:a.get(this.version))||new zt(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.declaration=this.declaration,i.andChildrenGroup=this.andChildrenGroup?[...this.andChildrenGroup]:this.andChildrenGroup,i.orChildrenGroup=this.orChildrenGroup?[...this.orChildrenGroup]:this.orChildrenGroup,i.successCalls=[...this.successCalls],i.errorCalls=[...this.errorCalls],i.calledBySuccess=[...this.calledBySuccess],i.calledByError=[...this.calledByError],i.calledByEntry=[...this.calledByEntry],i.parent=this.parent,this}recursiveCaptureUpstreamVersions(i){const a=[],o=[],p=[],e=[];if(this.parent){this.parent.increaseVersion(i);const y=this.parent.recursiveCaptureUpstreamVersions(i);a.push(this.parent,...y.updated),o.push(...y.added),p.push(...y.removed)}return{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}async restoreVersion(i){var v;const a=[],o=[],p=[],e=[];if(this.version===i)return{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this};if(!this.knownVersions){const E=new Map;for(const[b,A]of this.knownVersions||new Map){if(E.set(b,A),A.activeVersion=!1,A.knownVersions)for(const[$,V]of A.knownVersions)E.set($,V);A.knownVersions=null}}let y=(v=this.knownVersions)==null?void 0:v.get(i);if(!y){const E=await this.APILoadVersion({},i);if(!E)throw new Error(`Version with id '${i}' for entity with id '${this.id}' not found.`);y=new zt(E,this.project)}return this.metaSync(y.toShallowJSON(),null),this.previousVersion=y.previousVersion,this.version=y.version,this.createdAt=y.createdAt,this.author=y.author,this.deleted=y.deleted,this.inputs=y.inputs,this.declaration=y.declaration,this.andChildrenGroup=y.andChildrenGroup,this.orChildrenGroup=y.orChildrenGroup,this.successCalls=y.successCalls,this.errorCalls=y.errorCalls,this.calledBySuccess=y.calledBySuccess,this.calledByError=y.calledByError,this.calledByEntry=y.calledByEntry,this.parent=y.parent,{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}updateWithShallowTransfer(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"update-with-shallow-transfer"))){if(this.metaSync(i,a),this.version=i.version,this.createdAt=i.createdAt,this.author=i.author,this.deleted=i.deleted,this.previousVersion=i.previousVersion,i.parent){const o=J(i.parent),p=this.project.get(o),e=this.parent;if(e&&e.id!==(p==null?void 0:p.id)&&this.removeFromParent(a),p)this.setParent(p,a);else throw a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${o}' that isn't found in the project`)}else throw a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(i.declaration){const o=J(i.declaration),p=this.project.get(o);p&&this.setDeclaration(p)}return i.calledByEntry.forEach(o=>{const p=J(o),e=this.project.get(p);e&&(this.addEntryCaller(e,a),e.addCall(this,a))}),[...this.calledByEntry].forEach(o=>{i.calledByEntry.find(e=>J(e)===o.id)||(this.removeCaller(o,a),o.removeCall(this,a))}),i.calledBySuccess.forEach(o=>{const p=J(o),e=this.project.get(p);e&&(this.addSuccessCaller(e,a),e.addSuccessCall(this,a))}),[...this.calledBySuccess].forEach(o=>{i.calledBySuccess.find(e=>J(e)===o.id)||(this.removeCaller(o,a),o.removeCall(this,a))}),i.calledByError.forEach(o=>{const p=J(o),e=this.project.get(p);e&&(this.addErrorCaller(e,a),e.addErrorCall(this,a))}),[...this.calledBySuccess].forEach(o=>{i.calledBySuccess.find(e=>J(e)===o.id)||(this.removeCaller(o,a),o.removeCall(this,a))}),this.captureVersion(),this.subscribeToDependencies(),a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),this}hydrateAncestors(){const i=[],a=[],o=[],p=[];if(this.initialData.parent){const e=J(this.initialData.parent),y=this.project.get(e);if(y)this.setParent(y,null);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${e}' that isn't found in the project`)}else throw new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(this.initialData.declaration){const e=J(this.initialData.declaration),y=this.project.get(e);y&&(this.setDeclaration(y),i.push(y))}return this.initialData.calledByEntry.forEach(e=>{const y=J(e),v=this.project.get(y);v&&this.addEntryCaller(v,null)}),this.initialData.calledBySuccess.forEach(e=>{const y=J(e),v=this.project.get(y);v&&this.addSuccessCaller(v,null)}),this.initialData.calledByError.forEach(e=>{const y=J(e),v=this.project.get(y);v&&this.addErrorCaller(v,null)}),{updated:R(i),added:R(a),removed:R(o),affected:R(p),self:this}}afterAllChildrenInitialized(i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"after-all-children-initialized"))){const a=[],o=[],p=[],e=[];this.initialized=!0;const{updated:y,added:v,removed:E}=this.syncInputs(i);return a.push(...y),o.push(...v),p.push(...E),this.captureVersion(),i==null||i.attemptAutoclose("after-all-children-initialized",this.id),{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}addSelfToProject(i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-self-to-project"))){const a=[this],o=[],p=[],e=[];return this.parent===this.project&&this.project.addCondition(this),this.successCalls.forEach(y=>{y.addSuccessCaller(this,i),a.push(y)}),this.errorCalls.forEach(y=>{y.addErrorCaller(this,i),a.push(y)}),this.calledByEntry.forEach(y=>{y.addCall(this,i),a.push(y)}),this.calledBySuccess.forEach(y=>{y.addSuccessCall(this,i),a.push(y)}),this.calledByError.forEach(y=>{y.addErrorCall(this,i),a.push(y)}),this.subscribe(),this.subscribeToDependencies(),i==null||i.attemptAutoclose("add-self-to-project",this.id),{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}removeInput(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-input"))){const o=this.inputs.findIndex(p=>p.id===i.id);return o>-1&&(this.inputs.splice(o,1),a&&(a==null||a.add(this,F.Affected))),a==null||a.attemptAutoclose("remove-input",this.id),this}addInput(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-input"))){return this.inputs.includes(i)?(a==null||a.attemptAutoclose("add-input",this.id),this):(this.inputs.push(i),a==null||a.add(this,F.Affected),a==null||a.attemptAutoclose("add-input",this.id),this)}addOutput(i){return this}removeOutput(i){return this}addSuccessCaller(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-success-caller")),o=!1){return this.calledBySuccess.find(p=>p.id===i.id)||(this.calledBySuccess.push(i),a==null||a.add(this,F.Updated),o&&We(this,a)),a==null||a.attemptAutoclose("add-success-caller",this.id),this}addErrorCaller(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-error-caller")),o=!1){return this.calledByError.find(p=>p.id===i.id)||(this.calledByError.push(i),a==null||a.add(this,F.Updated),o&&We(this,a)),a==null||a.attemptAutoclose("add-error-caller",this.id),this}addEntryCaller(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-entry-caller")),o=!1){return this.calledByEntry.find(p=>p.id===i.id)||(this.calledByEntry.push(i),a==null||a.add(this,F.Updated),o&&We(this,a)),a==null||a.attemptAutoclose("add-entry-caller",this.id),this}addErrorCall(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-error-call")),o=!1){return this.errorCalls.find(p=>p.id===i.id)||(this.errorCalls.push(i),o&&We(this,a),a==null||a.add(this,F.Affected)),a==null||a.attemptAutoclose("add-error-call",this.id),this}addSuccessCall(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-success-call")),o=!1){return this.successCalls.find(p=>p.id===i.id)||(this.successCalls.push(i),o&&We(this,a),a==null||a.add(this,F.Affected)),a==null||a.attemptAutoclose("add-success-call",this.id),this}removeCall(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-call")),o=!1){const p=this.successCalls.findIndex(y=>y.id===i.id);p>-1&&(this.successCalls.splice(p,1),a==null||a.add(this,F.Affected));const e=this.errorCalls.findIndex(y=>y.id===i.id);return e>-1&&(this.errorCalls.splice(e,1),a==null||a.add(this,F.Affected)),o&&We(this,a),a==null||a.attemptAutoclose("remove-call",this.id),this}removeCaller(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-caller")),o=!1){return this.calledBySuccess=this.calledBySuccess.filter(p=>p.id!==i.id?!0:(a==null||a.add(this,F.Updated),a==null||a.add(p,F.Affected),!1)),this.calledByError=this.calledByError.filter(p=>p.id!==i.id?!0:(a==null||a.add(this,F.Updated),a==null||a.add(p,F.Affected),!1)),this.calledByEntry=this.calledByEntry.filter(p=>p.id!==i.id?!0:(a==null||a.add(this,F.Updated),a==null||a.add(p,F.Affected),!1)),o&&We(this,a),a==null||a.attemptAutoclose("remove-caller",this.id),this}setParent(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"set-parent"))){var o;return((o=this.parent)==null?void 0:o.id)!==(i==null?void 0:i.id)&&(this.parent=i,a&&(a==null||a.add(this,F.Updated))),a==null||a.attemptAutoclose("set-parent",this.id),this}removeChildGroup(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-child-group"))){if(this.andChildrenGroup){const o=this.andChildrenGroup.findIndex(p=>p.id===i.id);o!==-1&&(this.andChildrenGroup.splice(o,1),a==null||a.add(this,F.Updated))}if(this.orChildrenGroup){const o=this.orChildrenGroup.findIndex(p=>p.id===i.id);o!==-1&&(this.orChildrenGroup.splice(o,1),a==null||a.add(this,F.Updated))}return a==null||a.attemptAutoclose("remove-child-group",this.id),this}setDeclaration(i){return this.declaration=i,this}initChildren(i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.declaration=te(this.initialData.declaration,this.project),this.initialData.andChildrenGroup&&(this.andChildrenGroup=this.initialData.andChildrenGroup.map(a=>{const o=te(a,this.project);return o.setParent(this,null),o.initChildren(i),o})),this.initialData.orChildrenGroup&&(this.orChildrenGroup=this.initialData.orChildrenGroup.map(a=>{const o=te(a,this.project);return o.setParent(this,null),o.initChildren(i),o})),this.successCalls=this.initialData.successCalls.map(a=>{const o=te(a,this.project);if(o.addSuccessCaller(this),[f.BreakStatement,f.ContinueStatement].includes(o.type))o.setParent(this.parent.parent,null),o.initChildren(i);else if(o.type===f.ReturnStatement){const p=Wr(this,this.project);o.setParent(p,null),o.initChildren(i)}else o.type!==f.InternalCall&&(o.setParent(this.parent,null),o.initChildren(i));return o}),this.errorCalls=this.initialData.errorCalls.map(a=>{const o=te(a,this.project);if(o.addErrorCaller(this),[f.BreakStatement,f.ContinueStatement].includes(o.type))o.setParent(this.parent.parent,null),o.initChildren(i);else if(o.type===f.ReturnStatement){const p=Wr(this,this.project);o.setParent(p,null),o.initChildren(i)}else o.type!==f.InternalCall&&(o.setParent(this.parent,null),o.initChildren(i));return o}),this.inputs=this.initialData.inputs.map(a=>{const o=te(a,this.project);return o.setParent(this,null),o.initChildren(i),o}),this.subscribeToDependencies(),this.afterAllChildrenInitialized(i),i==null||i.attemptAutoclose("init-children",this.id),this)}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"meta-sync"))){const o=Ur(this,i),p=this.toMeta();return this.x=i.x||p.x,this.y=i.y||p.y,super.metaSync(i),i.deleted===!0&&!p.deleted?a==null||a.add(this,F.Removed):i.deleted===!1&&p.deleted?a==null||a.add(this,F.Added):o&&(a==null||a.add(this,F.Updated)),a==null||a.attemptAutoclose("meta-sync",this.id),this}async APILoad(i=ve,...a){return await zt.repository.APILoad(this.id,...a),this}async APICreate(i=ve,...a){return await zt.repository.APICreate(this.toShallowJSON(),...a),this}async APIUpdate(i=ve,...a){return await zt.repository.APIUpdate(this.toShallowJSON(),...a),this}async APIDelete(i=ve,...a){return await zt.repository.APIDelete(this.toShallowJSON(),...a),this}async APIClone(i=ve,...a){return await zt.repository.APIClone(this.id,...a),this}async APILoadVersion(i=ve,a,...o){return await zt.repository.APILoadVersion(this.id,a,...o)}removeFromParent(i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-from-parent"))){var y;const a=[],o=[],p=[],e=[];return this.parent.type===f.Project?(this.parent.removeCondition(this),e.push(this.parent)):((y=this.parent)==null?void 0:y.type)===f.Condition?this.parent.removeChildGroup(this):this.parent.detachedChildren.includes(this)&&this.parent.unsubscribeDetachedChild(this),i==null||i.attemptAutoclose("remove-from-parent",this.id),{added:R(p),updated:R(a),removed:R(o),affected:R(e),self:this}}remove({ignoreUpstream:i}={ignoreUpstream:!1},a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-entity"))){const o=[],p=[],e=[],y=[];if(a!=null&&a.hasRemoved(this.id))return a==null||a.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(p.push(this),this.unsubscribe(),this.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},a),Object.values(this.detachedDependents).forEach(v=>{const{updated:E,removed:b,added:A}=v.entity.onDetachedDependencyRemoved(this,v.field,a);o.push(...E),p.push(...b),e.push(...A)}),this.andChildrenGroup&&this.andChildrenGroup.forEach(v=>{const{removed:E,updated:b}=v.remove({ignoreUpstream:!0},a);p.push(...E),o.push(...b)}),this.orChildrenGroup&&this.orChildrenGroup.forEach(v=>{const{removed:E,updated:b}=v.remove({ignoreUpstream:!0},a);p.push(...E),o.push(...b)}),this.inputs.forEach(v=>{const{updated:E,removed:b}=v.remove({ignoreUpstream:!0},a);o.push(...E),p.push(...b)}),this.successCalls.forEach(v=>{o.push(v),v.removeCaller(this,a)}),this.errorCalls.forEach(v=>{o.push(v),v.removeCaller(this,a)}),!i){const v=this.removeFromParent(a);e.push(...v.added),o.push(...v.updated),p.push(...v.removed),y.push(...v.affected),this.calledBy.forEach(E=>{o.push(E),E.removeCall(this,a)})}return a==null||a.attemptAutoclose("remove-entity",this.id),{added:R(e),updated:R(o),removed:R(p),affected:R(y),self:this}}restore({}={},i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"restore-entity"))){const a=[],o=[],p=[],e=[];return i!=null&&i.hasAdded(this.id)?(i==null||i.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},i),Object.values(this.detachedDependents).forEach(y=>{const{updated:v,removed:E,added:b}=y.entity.onDetachedDependencyRestored(this,y.field,i);o.push(...v),p.push(...E),a.push(...b)}),this.andChildrenGroup&&this.andChildrenGroup.forEach(y=>{const{updated:v,added:E}=y.restore({},i);o.push(...v),a.push(...E)}),this.orChildrenGroup&&this.orChildrenGroup.forEach(y=>{const{updated:v,added:E}=y.restore({},i);o.push(...v),a.push(...E)}),this.inputs.forEach(y=>{const{updated:v}=y.restore({},i);o.push(...v)}),this.successCalls.forEach(y=>{o.push(y),y.addSuccessCaller(this,i)}),this.errorCalls.forEach(y=>{o.push(y),y.addErrorCaller(this,i)}),this.calledBySuccess.forEach(y=>{o.push(y),y.addSuccessCall(this,i)}),this.calledByError.forEach(y=>{o.push(y),y.addErrorCall(this,i)}),this.calledByEntry.forEach(y=>{o.push(y),y.addCall(this,i)}),this.parent.type===f.Project&&this.project.addCondition(this),i==null||i.attemptAutoclose("restore-entity",this.id),{added:R(a),updated:R(o),removed:R(p),affected:R(e),self:this})}toFlat(i=new Set){var o,p;return i.has(this.id)?[]:(i.add(this.id),[this,...((o=this.andChildrenGroup)==null?void 0:o.flatMap(e=>e.toFlat(i)))||[],...((p=this.orChildrenGroup)==null?void 0:p.flatMap(e=>e.toFlat(i)))||[],...this.inputs.flatMap(e=>e.toFlat(i)),...this.successCalls.flatMap(e=>e.toFlat(i)),...this.errorCalls.flatMap(e=>e.toFlat(i)),...this.calledBy.flatMap(e=>e.toFlat(i))])}toFlatIds(i=new Set){var o,p;return i.has(this.id)?[]:(i.add(this.id),[this.id,...((o=this.andChildrenGroup)==null?void 0:o.flatMap(e=>e.toFlatIds(i)))||[],...((p=this.orChildrenGroup)==null?void 0:p.flatMap(e=>e.toFlatIds(i)))||[],...this.inputs.flatMap(e=>e.toFlatIds(i)),...this.successCalls.flatMap(e=>e.toFlatIds(i)),...this.errorCalls.flatMap(e=>e.toFlatIds(i)),...this.calledBy.flatMap(e=>e.toFlatIds(i))])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,x:this.x,y:this.y,type:this.type}}toJSON(i=new Set){var a,o;return i.has(this.id)?this.toReference():(i.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,declaration:this.declaration.toJSON(i),andChildrenGroup:((a=this.andChildrenGroup)==null?void 0:a.map(p=>p.toJSON(i)))||null,orChildrenGroup:((o=this.orChildrenGroup)==null?void 0:o.map(p=>p.toJSON(i)))||null,successCalls:this.successCalls.map(p=>p.toJSON(i)),errorCalls:this.errorCalls.map(p=>p.toJSON(i)),calledBySuccess:this.calledBySuccess.map(p=>p.toReference()),calledByError:this.calledByError.map(p=>p.toReference()),calledByEntry:this.calledByEntry.map(p=>p.toReference()),inputs:this.inputs.map(p=>p.toJSON(i)),parent:this.parent.toReference()})}toJSONClone(i=ke){var o,p,e,y,v,E,b;let a;return(o=i.seenEntityMaps)!=null&&o.has(this.id)?a=i.seenEntityMaps.get(this.id):(a=i.newId||Sr(this,this.project,i.uuidStrategy),i.seenEntityMaps&&i.seenEntityMaps.set(this.id,a)),(p=i.seenEntities)!=null&&p.has(a)||(e=i.seenEntities)!=null&&e.has(this.id)?this.toReference({seenEntityMaps:i.seenEntityMaps}):((y=i.seenEntities)==null||y.add(a),(v=i.seenEntities)==null||v.add(this.id),{id:a,version:N.UUID.uuid(),createdAt:i.timestamp||L().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,declaration:this.declaration.toJSON(),andChildrenGroup:((E=this.andChildrenGroup)==null?void 0:E.map(A=>A.toJSONClone({...i,newId:null})))||null,orChildrenGroup:((b=this.orChildrenGroup)==null?void 0:b.map(A=>A.toJSONClone({...i,newId:null})))||null,successCalls:this.successCalls.map(A=>A.toJSONClone({...i,newId:null})),errorCalls:this.errorCalls.map(A=>A.toJSONClone({...i,newId:null})),calledBySuccess:this.calledBySuccess.map(A=>A.toReference({seenEntityMaps:i.seenEntityMaps})),calledByError:this.calledByError.map(A=>A.toReference({seenEntityMaps:i.seenEntityMaps})),calledByEntry:this.calledByEntry.map(A=>A.toReference({seenEntityMaps:i.seenEntityMaps})),inputs:this.inputs.map(A=>A.toJSONClone({...i,newId:null})),parent:this.parent.toReference({seenEntityMaps:i.seenEntityMaps})})}toReference(i=ke){var o;let a=this.id;return(o=i.seenEntityMaps)!=null&&o.has(this.id)&&(a=i.seenEntityMaps.get(this.id)),{id:a+"--"+N.UUID.uuid()+"--ref",type:f.GenericReference,entityId:a,version:this.version,entityType:this.type}}toShallowJSON(i=ke){var o,p,e;let a=this.id;return(o=i.seenEntityMaps)!=null&&o.has(this.id)&&(a=i.seenEntityMaps.get(this.id)),{id:a,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,declaration:this.declaration.toReference(i),andChildrenGroup:((p=this.andChildrenGroup)==null?void 0:p.map(y=>y.toReference(i)))||null,orChildrenGroup:((e=this.orChildrenGroup)==null?void 0:e.map(y=>y.toReference(i)))||null,inputs:this.inputs.map(y=>y.toReference(i)),successCalls:this.successCalls.map(y=>y.toReference(i)),errorCalls:this.errorCalls.map(y=>y.toReference(i)),calledBySuccess:this.calledBySuccess.map(y=>y.toReference(i)),calledByError:this.calledByError.map(y=>y.toReference(i)),calledByEntry:this.calledByEntry.map(y=>y.toReference(i)),parent:this.parent.toReference(i)}}toFlatJSON(i=new Set){var o,p;return i.has(this.id)?[]:(i.add(this.id),[this.toShallowJSON(),...((o=this.andChildrenGroup)==null?void 0:o.flatMap(e=>e.toFlatJSON(i)))||[],...((p=this.orChildrenGroup)==null?void 0:p.flatMap(e=>e.toFlatJSON(i)))||[],...this.inputs.flatMap(e=>e.toFlatJSON(i)),...this.successCalls.flatMap(e=>e.toFlatJSON(i)),...this.errorCalls.flatMap(e=>e.toFlatJSON(i)),...this.calledBy.flatMap(e=>e.toFlatJSON(i))])}toGenerationTarget(){const i=this.parent.type===f.Project?void 0:this.parent.id;return{id:this.id,type:this.type,declaration:this.declaration.id,calledByEntry:this.calledByEntry.map(a=>a.id),calledBySuccess:this.calledBySuccess.map(a=>a.id),calledByError:this.calledByError.map(a=>a.id),parent:i}}toFlatGenerationTarget(i=new Set){var o,p;return i.has(this.id)?[]:(i.add(this.id),[this.toGenerationTarget(),...((o=this.andChildrenGroup)==null?void 0:o.flatMap(e=>e.toFlatGenerationTarget(i)))||[],...((p=this.orChildrenGroup)==null?void 0:p.flatMap(e=>e.toFlatGenerationTarget(i)))||[],...this.inputs.flatMap(e=>e.toFlatGenerationTarget(i)),...this.successCalls.flatMap(e=>e.toFlatGenerationTarget(i)),...this.errorCalls.flatMap(e=>e.toFlatGenerationTarget(i))])}clearErrors(){var i,a;return this.errors=[],(i=this.andChildrenGroup)==null||i.forEach(o=>o.clearErrors()),(a=this.orChildrenGroup)==null||a.forEach(o=>o.clearErrors()),this.inputs.forEach(o=>o.clearErrors()),this.successCalls.forEach(o=>o.clearErrors()),this.errorCalls.forEach(o=>o.clearErrors()),this}validate(){const i=zj(this);return this.errors=i,{success:!0}}getErrors(){return[...this.errors,...this.inputs.flatMap(a=>a.getErrors())]}getShallowErrors(){return this.errors}clone(i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"clone-entity")),a=null,o=null,p=!0){var S,K,Z;let e=Fr(a,this);const y=this.toJSON(),v=o||N.UUID.uuid();y.inputs=[];const E=v.split("-id"),b=E[E.length-1||0]||v;y.id=v,y.version=N.UUID.uuid(),y.createdAt=(i==null?void 0:i.timestamp)||L().toISOString(),y.author=(i==null?void 0:i.author)||"1",y.previousVersion=null,y.deleted=!1;const A=lr(y,e);a?A.setParent(a,null):A.setParent(this.parent,null),p&&A.subscribe(),A.initChildren(i),i==null||i.add(A,F.Added);const $=(S=this.andChildrenGroup)==null?void 0:S.map(ie=>ie.clone(i,A,N.UUID.uuid(),p)),V=(K=this.orChildrenGroup)==null?void 0:K.map(ie=>ie.clone(i,A,N.UUID.uuid(),p));A.andChildrenGroup=$||null,A.orChildrenGroup=V||null;const U=(Z=this.inputs)==null?void 0:Z.map((ie,X)=>ie.clone(i,A,b+"-input-map-"+X+"-id",p));return A.inputs=U,i==null||i.attemptAutoclose("clone-entity",this.id),A}addToAndGroup(i){return this.andChildrenGroup||(this.andChildrenGroup=[]),this.andChildrenGroup.includes(i)||this.andChildrenGroup.push(i),this}addToOrGroup(i){return this.orChildrenGroup||(this.orChildrenGroup=[]),this.orChildrenGroup.includes(i)||this.orChildrenGroup.push(i),this}removeUnrecognizedInputs(i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-unrecognized-inputs"))){const a=[],o=[],p=[],e=[];return this.inputs.forEach(v=>{if(!this.declaration.inputs.find(b=>{var A;return b.id===((A=v.declaration)==null?void 0:A.id)})){const b=v.remove({ignoreUpstream:!1},i);p.push(...b.removed),a.push(...b.updated)}}),this.inputs.filter((v,E)=>{const b=this.inputs.findIndex($=>$.declaration===v.declaration&&$!==v);if(b===-1)return!1;const A=this.inputs[b];return L(A==null?void 0:A.createdAt).isSame(L(v.createdAt))?E>b:!!L(A==null?void 0:A.createdAt).isAfter(v.createdAt)}).forEach(v=>{const E=v.remove({ignoreUpstream:!1},i);p.push(...E.removed),a.push(...E.updated)}),i==null||i.attemptAutoclose("remove-unrecognized-inputs",this.id),{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}syncInputs(i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"sync-missing-fixed-inputs"))){const a=[],o=[],p=[],e=[],y=this.declaration.inputs.filter(A=>A.parentRelationType===de.FixedArguments&&!this.inputs.find($=>$.declaration.id===A.id));this.inputs.sort((A,$)=>A.index-$.index),y.forEach(A=>{this.inputs.forEach(U=>{U.index>=A.index&&U.metaSync({index:U.index+1},i)});const $={id:N.UUID.uuid(),version:N.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||L().toISOString(),author:N.sessionAuthor,previousVersion:null,deleted:!1,type:f.InputMap,declaration:A.toJSON(),readsValue:null,defaultValue:null,index:A.index,name:null,codeName:null,description:null,parent:this.toReference()},V=te($,this.project);V.setParent(this,i),V.initChildren(i),i==null||i.add(V,F.Added),V.addSelfToProject(i)}),this.inputs.sort((A,$)=>A.index-$.index);const{updated:v,added:E,removed:b}=this.removeUnrecognizedInputs(i);return a.push(...v),o.push(...E),p.push(...b),i==null||i.attemptAutoclose("sync-missing-fixed-inputs",this.id),{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}getUnusedInputs(){return this.inputs.filter(i=>i.suggestion||!i.readsValue&&!i.defaultValue)}getUnusedOutputs(){return[]}getUsedInputs(){return this.inputs.filter(i=>!i.suggestion&&(i.readsValue||i.defaultValue))}getUsedOutputs(){return[]}};g(zt,"repository",{APICreate:async(i,...a)=>i,APIUpdate:async(i,...a)=>i,APIDelete:async(i,...a)=>i,APIClone:async(i,...a)=>{},APILoad:async(i,...a)=>null,APILoadVersion:async(i,a,...o)=>null}),g(zt,"type",f.Condition),g(zt,"USER_MANAGED_PARENT_TYPES",[...Mr,f.Project,f.Condition]),g(zt,"PARENT_TYPES",[...zt.USER_MANAGED_PARENT_TYPES]),g(zt,"MUTABLE_BASE_PROPERTIES",["operator"]),g(zt,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),g(zt,"BASE_PROPERTIES",[...zt.MUTABLE_BASE_PROPERTIES,...zt.INMUTABLE_BASE_PROPERTIES]),g(zt,"MUTABLE_META_PROPERTIES",["x","y"]),g(zt,"INMUTABLE_META_PROPERTIES",[...zt.INMUTABLE_BASE_PROPERTIES]),g(zt,"META_PROPERTIES",[...zt.MUTABLE_META_PROPERTIES,...zt.INMUTABLE_META_PROPERTIES]),g(zt,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry","parent"]),g(zt,"INMUTABLE_UPSTREAM_PROPERTIES",[]),g(zt,"UPSTREAM_PROPERTIES",[...zt.MUTABLE_UPSTREAM_PROPERTIES,...zt.INMUTABLE_UPSTREAM_PROPERTIES]),g(zt,"MUTABLE_DOWNSTREAM_PROPERTIES",["andChildrenGroup","orChildrenGroup","successCalls","errorCalls","inputsDeclarations","inputs"]),g(zt,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),g(zt,"DOWNSTREAM_PROPERTIES",[...zt.MUTABLE_DOWNSTREAM_PROPERTIES,...zt.INMUTABLE_DOWNSTREAM_PROPERTIES]),g(zt,"PROPERTIES",[...zt.META_PROPERTIES,...zt.UPSTREAM_PROPERTIES,...zt.DOWNSTREAM_PROPERTIES]);let oo=zt;function Qj(d){var y;const u=Eme(),i=d.toJSON();u.safeParse(i).success,(y=d.dataType)==null||y.validate(),d.inputs.forEach(v=>v.validate()),d.outputs.forEach(v=>v.validate()),d.internalCalls.forEach(v=>v.validate());const p=[...Ua(d),...Io(d),...e3(d)],e=$b(d);return p.push(...e),vr(d.errors,p)}function e3(d){const u=[],i=d.name;if(!i){const $=ft({id:`${d.id}--${ae.EmptyName}`,message:`Variable declaration "${ne(d,d.project)}" with id "${d.id}" does not have a name. Entities of type ${d.type} must have valid names.`,severity:q.Error,code:ae.EmptyName,entity:d});return u.push($.error),u}const o=[...d.project.functions,...d.project.entities.flatMap($=>$.methods)].filter($=>$.id!==d.id),p=i.trim(),e=!o.some($=>$.name===i||$.name===p);if(!e){const $=ft({id:`${d.id}--${ae.NameNotUniqueInScope}`,message:`Variable declaration "${ne(d,d.project)}" with id "${d.id}" does not have a unique name. Entities of type ${d.type} must have valid names among all other entities of its type.`,severity:q.Error,code:ae.NameNotUniqueInScope,entity:d});u.push($.error)}const y=jr(i);if(!!o.some($=>jr($.name)===y)&&e){const $=ft({id:`${d.id}--${ae.NameAsResolvedCodeNameNotUniqueInScope}`,message:`Variable declaration "${ne(d,d.project)}" with id "${d.id}" does not have a unique name once it is resolved as it will appear in code: "${y}". Entities of type ${d.type} must have valid names including their code name form.`,severity:q.Error,code:ae.NameAsResolvedCodeNameNotUniqueInScope,entity:d});u.push($.error)}if(!/^[a-zA-Z_]/.test(i)){const $=ft({id:`${d.id}--${ae.NameMustStartWithLetterOrUnderscore}`,message:`Variable declaration "${ne(d,d.project)}" with id "${d.id}" has a name that does not start with a letter or underscore.`,severity:q.Error,code:ae.NameMustStartWithLetterOrUnderscore,entity:d});u.push($.error)}const b=i.substring(1);if(!/^[a-zA-Z0-9_ ]*$/.test(b)){const $=ft({id:`${d.id}--${ae.NameCanOnlyContainLettersNumbersUnderscoreAndSpaces}`,message:`Variable declaration "${ne(d,d.project)}" with id "${d.id}" has a name that contains invalid characters. It can only contain letters, numbers, underscores and spaces.`,severity:q.Error,code:ae.NameCanOnlyContainLettersNumbersUnderscoreAndSpaces,entity:d});u.push($.error)}return u}const o0e=Object.freeze(Object.defineProperty({__proto__:null,validate:Qj,validateVariableDeclarationName:e3},Symbol.toStringTag,{value:"Module"}));function t3(d){const u=Sye(),i=d.toJSON();u.safeParse(i).success,d.inputs.forEach(y=>y.validate()),d.outputs.forEach(y=>y.validate()),d.internalCalls.forEach(y=>y.validate());const p=[...Ua(d),...Io(d)],e=$b(d);return p.push(...e),vr(d.errors,p)}const l0e=Object.freeze(Object.defineProperty({__proto__:null,validate:t3},Symbol.toStringTag,{value:"Module"}));var pA=(d=>(d.Parent="parent",d.DataTypeEntity="data-type-entity",d.VarDeclaration="var-declaration",d))(pA||{});const xt=class xt extends Nr{constructor(i,a){super(i);g(this,"initialData");g(this,"id");g(this,"x");g(this,"y");g(this,"type",f.VariableInstance);g(this,"defaultValue",null);g(this,"writesValues",[]);g(this,"readsValue",null);g(this,"declaration");g(this,"inputs",[]);g(this,"outputs",[]);g(this,"calledBySuccess",[]);g(this,"calledByError",[]);g(this,"calledByEntry",[]);g(this,"successCalls",[]);g(this,"errorCalls",[]);g(this,"internalCalls",[]);g(this,"project");g(this,"errors",[]);g(this,"parent");g(this,"detachedDependents",{});g(this,"knownVersions",null);g(this,"activeVersion",!1);g(this,"initialized",!1);g(this,"startedInitialization",!1);g(this,"suggestion",!1);g(this,"_codeNativeValueValidation",null);this.initialData=i,this.project=a,this.id=i.id,this.x=i.x,this.y=i.y}static new(i=null){return{id:N.UUID.uuid(),version:N.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||L().toISOString(),author:(i==null?void 0:i.author)||N.sessionAuthor,previousVersion:null,deleted:!1,type:f.VariableInstance,declaration:null,internalCalls:[],successCalls:[],errorCalls:[],readsValue:null,writesValues:[],defaultValue:null,inputs:[],outputs:[],parent:null,calledByEntry:[],calledBySuccess:[],calledByError:[],x:0,y:0}}static fromGenerationTarget(i,a){let o=a;if(i.parent){const V=J(i.parent);o=a.get(V)}const p=J(i.declaration),e=a.get(p),y=i.calledByEntry.map(V=>{const U=J(V);return a.get(U)}),v=i.calledBySuccess.map(V=>{const U=J(V);return a.get(U)}),E=i.calledByError.map(V=>{const U=J(V);return a.get(U)});let b=null;if(i.readsValue){const V=J(i.readsValue);b=a.get(V)}const A={id:i.id,version:N.UUID.uuid(),createdAt:L().toISOString(),author:N.sessionAuthor,previousVersion:null,deleted:!1,type:f.VariableInstance,declaration:e.toReference(),calledByEntry:y,calledBySuccess:v,calledByError:E,defaultValue:null,errorCalls:[],successCalls:[],internalCalls:[],readsValue:b,inputs:[],outputs:[],writesValues:[],x:0,y:0,parent:o},$=te(A,a);return $.setParent(o,null),$}static validateGenerationTarget(i,a){let o=JSON.parse(JSON.stringify(i));const p=[],e=oi(o,{parent:{list:!1,types:[...Mr,f.Project],optional:!0},declaration:{list:!1,types:[f.VariableDeclaration]}},a);return o=e.modifiedData,p.push(...e.errors,...Br(o)),{errors:p,modifiedData:o}}get codeName(){var i;return(i=this.declaration)==null?void 0:i.codeName}get codeNativeValueValidation(){var i;return this._codeNativeValueValidation||((i=this.declaration)==null?void 0:i.codeNativeValueValidation)||null}validateGeneratedUpdate(i){const a=[];let o=JSON.parse(JSON.stringify(i));const p=zp(o,this);return o=p.modifiedData,a.push(...p.errors),i.parent&&a.push(new ee({id:`${this.id}--${k.InvalidParentUpdate}`,code:k.InvalidParentUpdate,severity:q.Error,message:`Entity of type '${this.type}' with id '${this.id}' cannot have the 'parent' property updated. The 'parent' on a callable entity, is its scope. It scope is auto-calculated implicitly by the its caller.
80
80
  If an entity is called by another, they must be in the same scope, which means they have the same parent.
81
81
  Specifically for variables, their scope is also calculated from their value readers and value writters.
82
82
  You shouldn't have to manually update a 'parent' property. The equivalent result is to change its value readers, value writters, or callers.`})),{errors:a,modifiedData:o}}subscribeDependents(i){return i.forEach(a=>{this.detachedDependents[a.entity.id]||(this.detachedDependents[a.entity.id]=a)}),this}unsubscribeDependents(i){return i.forEach(a=>{this.detachedDependents[a.entity.id]&&delete this.detachedDependents[a.entity.id]}),this}syncDependents(i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"sync-dependents"))){const a=[],o=[],p=[],e=[];return Object.values(this.detachedDependents).forEach(y=>{const v=y.entity.afterAllChildrenInitialized(i);a.push(...v.updated),o.push(...v.added),p.push(...v.removed),e.push(...v.affected)}),i==null||i.attemptAutoclose("sync-dependents",this.id),{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}onDetachedDependencyRemoved(i,a,o){const p=[],e=[],y=[],v=[];if(a==="parent"){const{updated:E,added:b,removed:A}=this.remove({ignoreUpstream:!1},o);p.push(...E),e.push(...b),y.push(...A)}if(a==="var-declaration"){const{updated:E,added:b,removed:A}=this.remove({ignoreUpstream:!1},o);p.push(...E),e.push(...b),y.push(...A)}return{updated:R(p),added:R(e),removed:R(y),affected:R(v),self:this}}onDetachedDependencyRestored(i,a,o){const p=[],e=[],y=[],v=[];if(a==="parent"){const{updated:E,added:b,removed:A}=this.restore({},o);p.push(...E),e.push(...b),y.push(...A)}if(a==="var-declaration"){const{updated:E,added:b,removed:A}=this.restore({},o);p.push(...E),e.push(...b),y.push(...A)}return{updated:R(p),added:R(e),removed:R(y),affected:R(v),self:this}}unsubscribeFromDependencies(){var i,a,o,p,e,y,v;return(a=(i=this.parent)==null?void 0:i.unsubscribeDependents)==null||a.call(i,[{entity:this,field:"parent"}]),(e=(p=(o=this.declaration.dataType)==null?void 0:o.entity)==null?void 0:p.unsubscribeDependents)==null||e.call(p,[{entity:this,field:"data-type-entity"}]),(v=(y=this.declaration)==null?void 0:y.unsubscribeDependents)==null||v.call(y,[{entity:this,field:"var-declaration"}]),this}subscribeToDependencies(){var i,a,o,p;return(i=this.parent)==null||i.subscribeDependents([{entity:this,field:"parent"}]),(p=(o=(a=this.declaration.dataType)==null?void 0:a.entity)==null?void 0:o.subscribeDependents)==null||p.call(o,[{entity:this,field:"data-type-entity"}]),this.declaration.subscribeDependents([{entity:this,field:"var-declaration"}]),this}increaseVersion(i){if(i&&!L(i).isValid())throw new Error(`The shared timestamp '${i}' is not a valid ISO 8601 date string.`);return i&&L(i).isSame(L(this.createdAt))?this:(this.previousVersion=this.version,this.version=N.UUID.uuid(),this.createdAt=L(i).toISOString()||L().toISOString(),this)}captureVersion(){var a;const i=((a=this.knownVersions)==null?void 0:a.get(this.version))||new xt(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.internalCalls=[...this.internalCalls],i.successCalls=[...this.successCalls],i.errorCalls=[...this.errorCalls],i.writesValues=[...this.writesValues],i.readsValue=this.readsValue,i.defaultValue=this.defaultValue,i.declaration=this.declaration,i.calledBySuccess=[...this.calledBySuccess],i.calledByError=[...this.calledByError],i.calledByEntry=[...this.calledByEntry],i.parent=this.parent,this}recursiveCaptureUpstreamVersions(i){const a=[],o=[],p=[],e=[];if(this.parent){this.parent.increaseVersion(i);const y=this.parent.recursiveCaptureUpstreamVersions(i);a.push(this.parent,...y.updated),o.push(...y.added),p.push(...y.removed)}return{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}async restoreVersion(i){var v;const a=[],o=[],p=[],e=[];if(this.version===i)return{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this};if(!this.knownVersions){const E=new Map;for(const[b,A]of this.knownVersions||new Map){if(E.set(b,A),A.activeVersion=!1,A.knownVersions)for(const[$,V]of A.knownVersions)E.set($,V);A.knownVersions=null}}let y=(v=this.knownVersions)==null?void 0:v.get(i);if(!y){const E=await this.APILoadVersion({},i);if(!E)throw new Error(`Version with id '${i}' for entity with id '${this.id}' not found.`);y=new xt(E,this.project)}return this.metaSync(y.toShallowJSON(),null),this.previousVersion=y.previousVersion,this.version=y.version,this.createdAt=y.createdAt,this.author=y.author,this.deleted=y.deleted,this.inputs=y.inputs,this.outputs=y.outputs,this.internalCalls=y.internalCalls,this.successCalls=y.successCalls,this.errorCalls=y.errorCalls,this.writesValues=y.writesValues,this.readsValue=y.readsValue,this.defaultValue=y.defaultValue,this.declaration=y.declaration,this.calledBySuccess=y.calledBySuccess,this.calledByError=y.calledByError,this.calledByEntry=y.calledByEntry,this.parent=y.parent,{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}updateWithShallowTransfer(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"update-with-shallow-transfer"))){if(this.metaSync(i,a),this.version=i.version,this.createdAt=i.createdAt,this.author=i.author,this.deleted=i.deleted,this.previousVersion=i.previousVersion,this.unsubscribeFromDependencies(),i.parent){const o=J(i.parent),p=this.project.get(o),e=this.parent;if(e&&e.id!==(p==null?void 0:p.id)&&this.removeFromParent(a),p)this.setParent(p,a);else throw a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${o}' that isn't found in the project`)}else throw a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(i.readsValue){const o=J(i.readsValue),p=this.project.get(o),e=this.readsValue;e&&e.id!==(p==null?void 0:p.id)&&this.removeValueWriter(a),p&&this.setValueWriter(p,a)}if(i.declaration){const o=J(i.declaration),p=this.project.get(o);p&&this.setDeclaration(p)}return i.calledByEntry.forEach(o=>{const p=J(o),e=this.project.get(p);e&&(this.addEntryCaller(e,a),e.addCall(this,a))}),[...this.calledByEntry].forEach(o=>{i.calledByEntry.find(e=>J(e)===o.id)||(this.removeCaller(o,a),o.removeCall(this,a))}),i.calledBySuccess.forEach(o=>{const p=J(o),e=this.project.get(p);e&&(this.addSuccessCaller(e,a),e.addSuccessCall(this,a))}),[...this.calledBySuccess].forEach(o=>{i.calledBySuccess.find(e=>J(e)===o.id)||(this.removeCaller(o,a),o.removeCall(this,a))}),i.calledByError.forEach(o=>{const p=J(o),e=this.project.get(p);e&&(this.addErrorCaller(e,a),e.addErrorCall(this,a))}),[...this.calledBySuccess].forEach(o=>{i.calledBySuccess.find(e=>J(e)===o.id)||(this.removeCaller(o,a),o.removeCall(this,a))}),this.captureVersion(),this.subscribeToDependencies(),a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),this}hydrateAncestors(){const i=[],a=[],o=[],p=[];if(this.initialData.parent){const e=J(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.readsValue){const e=J(this.initialData.readsValue),y=this.project.get(e);y&&(this.setValueWriter(y,null),i.push(y))}if(this.initialData.declaration){const e=J(this.initialData.declaration),y=this.project.get(e);y&&(this.setDeclaration(y),i.push(y))}return this.initialData.calledByEntry.forEach(e=>{const y=J(e),v=this.project.get(y);v&&this.addEntryCaller(v,null)}),this.initialData.calledBySuccess.forEach(e=>{const y=J(e),v=this.project.get(y);v&&this.addSuccessCaller(v,null)}),this.initialData.calledByError.forEach(e=>{const y=J(e),v=this.project.get(y);v&&this.addErrorCaller(v,null)}),{updated:R(i),added:R(a),removed:R(o),affected:R(p),self:this}}afterAllChildrenInitialized(i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"after-all-children-initialized"))){var $e;const a=[],o=[],p=[],e=[];if(this.initialized=!0,!this.declaration.dataType||($e=this.declaration.dataType)!=null&&$e.inferred){const{added:Pe,updated:Ze,removed:Ge,affected:lt}=this.declaration.inferDataTypeAndSyncInstancesInputsAndOutputs(i);o.push(...Pe),a.push(...Ze),p.push(...Ge),e.push(...lt)}const{added:y,updated:v,removed:E,affected:b}=this.syncInputs(i);o.push(...y),a.push(...v),p.push(...E),e.push(...b);const{added:A,updated:$,removed:V,affected:U}=this.syncOutputs(i);o.push(...A),a.push(...$),p.push(...V),e.push(...U);const{added:S,updated:K,removed:Z,affected:ie}=this.generateUnusedInternalCalls(i);o.push(...S),a.push(...K),p.push(...Z),e.push(...ie);const{added:X,updated:ue,removed:re,affected:fe}=this.removeUnrecognizedInputs(i);o.push(...X),a.push(...ue),p.push(...re),e.push(...fe);const{added:Y,updated:H,removed:ce,affected:z}=this.removeUnrecognizedOutputs(i);o.push(...Y),a.push(...H),p.push(...ce),e.push(...z);const{added:oe,updated:we,removed:xe,affected:Ne}=this.removeUnrecognizedInternalCalls(i);return o.push(...oe),a.push(...we),p.push(...xe),e.push(...Ne),this.captureVersion(),i==null||i.attemptAutoclose("after-all-children-initialized",this.id),{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}addSelfToProject(i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-self-to-project"))){const a=[this],o=[],p=[],e=[];return this.parent===this.project&&this.project.addVariableInstance(this),this.readsValue&&(this.readsValue.addValueReader(this,i),a.push(this.readsValue)),this.writesValues.forEach(y=>{y.setValueWriter(this,i),a.push(y)}),this.successCalls.forEach(y=>{y.addSuccessCaller(this,i),a.push(y)}),this.errorCalls.forEach(y=>{y.addErrorCaller(this,i),a.push(y)}),this.calledBySuccess.forEach(y=>{y.addSuccessCall(this,i),a.push(y)}),this.calledByError.forEach(y=>{y.addErrorCall(this,i),a.push(y)}),this.calledByEntry.forEach(y=>{y.addCall(this,i),a.push(y)}),this.subscribe(),this.subscribeToDependencies(),i==null||i.attemptAutoclose("add-self-to-project",this.id),{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}get usedInputs(){return this.inputs.filter(i=>i.readsValue||i.defaultValue)}get unusedInputs(){return this.inputs.filter(i=>!i.readsValue&&!i.defaultValue)}get usedOutputs(){return this.outputs.filter(i=>i.writesValues.length)}get unusedOutputs(){return this.outputs.filter(i=>!i.writesValues.length)}get usedInternalCalls(){return this.internalCalls.filter(i=>!!i.calledBy.length)}get unusedInternalCalls(){const i=this.usedInternalCalls;return this.internalCalls.filter(o=>!(i.find(y=>y.id===o.id)||i.find(y=>y.declaration===o.declaration)))}removeInternalCall(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-variable-instance-internal-call"))){const o=this.internalCalls.findIndex(p=>p.id===i.id);return o>-1&&(this.internalCalls.splice(o,1),a&&(a==null||a.add(this,F.Affected))),a==null||a.attemptAutoclose("remove-variable-instance-internal-call",this.id),this}removeInput(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-input"))){const o=this.inputs.findIndex(p=>p.id===i.id);return o>-1&&(this.inputs.splice(o,1),a&&(a==null||a.add(this,F.Affected))),a==null||a.attemptAutoclose("remove-input",this.id),this}addInput(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-input"))){return this.inputs.includes(i)?(a==null||a.attemptAutoclose("add-input",this.id),this):(this.inputs.push(i),a==null||a.add(this,F.Affected),a==null||a.attemptAutoclose("add-input",this.id),this)}addOutput(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-output"))){return this.outputs.includes(i)?(a==null||a.attemptAutoclose("add-output",this.id),this):(this.outputs.push(i),a==null||a.add(this,F.Affected),a==null||a.attemptAutoclose("add-output",this.id),this)}removeOutput(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-output"))){const o=this.outputs.findIndex(p=>p.id===i.id);return o>-1&&(this.outputs.splice(o,1),a&&(a==null||a.add(this,F.Affected))),a==null||a.attemptAutoclose("remove-output",this.id),this}addSuccessCaller(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-success-caller")),o=!1){return this.calledBySuccess.find(p=>p.id===i.id)||(this.calledBySuccess.push(i),a==null||a.add(this,F.Updated),o&&We(this,a)),a==null||a.attemptAutoclose("add-success-caller",this.id),this}addErrorCaller(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-error-caller")),o=!1){return this.calledByError.find(p=>p.id===i.id)||(this.calledByError.push(i),a==null||a.add(this,F.Updated),o&&We(this,a)),a==null||a.attemptAutoclose("add-error-caller",this.id),this}addEntryCaller(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-entry-caller")),o=!1){return this.calledByEntry.find(p=>p.id===i.id)||(this.calledByEntry.push(i),a==null||a.add(this,F.Updated),o&&We(this,a)),a==null||a.attemptAutoclose("add-entry-caller",this.id),this}addErrorCall(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-error-call")),o=!1){return this.errorCalls.find(p=>p.id===i.id)||(this.errorCalls.push(i),o&&We(this,a),a==null||a.add(this,F.Affected)),a==null||a.attemptAutoclose("add-error-call",this.id),this}addSuccessCall(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-success-call")),o=!1){return this.successCalls.find(p=>p.id===i.id)||(this.successCalls.push(i),o&&We(this,a),a==null||a.add(this,F.Affected)),a==null||a.attemptAutoclose("add-success-call",this.id),this}removeCall(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-call")),o=!1){const p=this.successCalls.findIndex(y=>y.id===i.id);p>-1&&(this.successCalls.splice(p,1),a==null||a.add(this,F.Affected));const e=this.errorCalls.findIndex(y=>y.id===i.id);return e>-1&&(this.errorCalls.splice(e,1),a==null||a.add(this,F.Affected)),o&&We(this,a),a==null||a.attemptAutoclose("remove-call",this.id),this}removeCaller(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-caller")),o=!1){return this.calledBySuccess=this.calledBySuccess.filter(p=>p.id!==i.id?!0:(a==null||a.add(this,F.Updated),a==null||a.add(p,F.Affected),!1)),this.calledByError=this.calledByError.filter(p=>p.id!==i.id?!0:(a==null||a.add(this,F.Updated),a==null||a.add(p,F.Affected),!1)),this.calledByEntry=this.calledByEntry.filter(p=>p.id!==i.id?!0:(a==null||a.add(this,F.Updated),a==null||a.add(p,F.Affected),!1)),o&&We(this,a),a==null||a.attemptAutoclose("remove-caller",this.id),this}addValueReader(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-value-reader"))){return this.writesValues.includes(i)?(a==null||a.attemptAutoclose("add-value-reader",this.id),this):(this.writesValues.push(i),a==null||a.add(this,F.Affected),this)}setParent(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"set-parent"))){var o;return((o=this.parent)==null?void 0:o.id)!==(i==null?void 0:i.id)&&(this.parent=i,a&&(a==null||a.add(this,F.Updated))),a==null||a.attemptAutoclose("set-parent",this.id),this}initChildren(i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"init-children"))){if(this.initialized||this.startedInitialization)return this;if(this.startedInitialization=!0,this.initialData.defaultValue&&(this.defaultValue=te(this.initialData.defaultValue,this.project),this.defaultValue.setParent(this,null),this.defaultValue.initChildren(i)),this.initialData.declaration.type===f.GenericReference){const a=this.project.findSubscribedInstanceFromReference(this.initialData.declaration);if(!a)return this;this.declaration=a}else this.declaration=te(this.initialData.declaration,this.project),this.declaration.initChildren(i);return uf.initWritesValues(this,this.parent),df.initReadsValue(this),this.initialData.inputs.forEach(a=>{const o=te(a,this.project);return o.setParent(this,null),o.initChildren(i),this.addInput(o,null),o}),this.initialData.outputs.forEach(a=>{const o=te(a,this.project);return o.setParent(this,null),o.initChildren(i),this.addOutput(o,i),o}),this.successCalls=this.initialData.successCalls.map(a=>{const o=te(a,this.project);if(o.addSuccessCaller(this),[f.BreakStatement,f.ContinueStatement].includes(o.type))o.setParent(this.parent.parent,null),o.initChildren(i);else if(o.type===f.ReturnStatement){const p=Wr(this,this.project);o.setParent(p,null),o.initChildren(i)}else o.type!==f.InternalCall&&(o.setParent(this.parent,null),o.initChildren(i));return o}),this.errorCalls=this.initialData.errorCalls.map(a=>{const o=te(a,this.project);if(o.addErrorCaller(this),[f.BreakStatement,f.ContinueStatement].includes(o.type))o.setParent(this.parent.parent,null),o.initChildren(i);else if(o.type===f.ReturnStatement){const p=Wr(this,this.project);o.setParent(p,null),o.initChildren(i)}else o.type!==f.InternalCall&&(o.setParent(this.parent,null),o.initChildren(i));return o}),this.internalCalls=this.initialData.internalCalls.reduce((a,o)=>{if(o.type===f.GenericReference){const p=this.project.findSubscribedInstanceFromReference(o);if(!p)return a;const e=p;return e.setParent(this,null),[...a,e]}else{const p=te(o,this.project);return p.setParent(this,null),p.initChildren(i),[...a,p]}},[]),this.subscribeToDependencies(),this.afterAllChildrenInitialized(i),i==null||i.attemptAutoclose("init-children",this.id),this}setValueWriter(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"set-value-writer"))){return this.readsValue!==i&&(this.readsValue=i,a==null||a.add(this,F.Updated)),a==null||a.attemptAutoclose("set-value-writer",this.id),this}removeValueWriter(i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-value-writer"))){return this.readsValue&&(this.readsValue=null,i==null||i.add(this,F.Updated)),i==null||i.attemptAutoclose("remove-value-writer",this.id),this}removeValueReader(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-value-reader"))){return this.writesValues.includes(i)?(this.writesValues=this.writesValues.filter(o=>o.id!==i.id),a==null||a.add(this,F.Affected),this):(a==null||a.attemptAutoclose("remove-value-reader",this.id),this)}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"meta-sync"))){const o=Ur(this,i),p=this.toMeta();return this.x=i.x||p.x,this.y=i.y||p.y,super.metaSync(i),i.deleted===!0&&!p.deleted?a==null||a.add(this,F.Removed):i.deleted===!1&&p.deleted?a==null||a.add(this,F.Added):o&&(a==null||a.add(this,F.Updated)),a==null||a.attemptAutoclose("meta-sync",this.id),this}async APILoad(i=ve,...a){return await xt.repository.APILoad(this.id,...a),this}async APICreate(i=ve,...a){return await xt.repository.APICreate(this.toShallowJSON(),...a),this}async APIUpdate(i=ve,...a){return await xt.repository.APIUpdate(this.toShallowJSON(),...a),this}async APIDelete(i=ve,...a){return await xt.repository.APIDelete(this.toShallowJSON(),...a),this}async APIClone(i=ve,...a){return await xt.repository.APIClone(this.id,...a),this}async APILoadVersion(i=ve,a,...o){return await xt.repository.APILoadVersion(this.id,a,...o)}removeFromParent(i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-from-parent"))){const a=[],o=[],p=[],e=[];return this.parent.type===f.Project?(this.parent.removeVariableInstance(this),e.push(this.parent)):this.parent.detachedChildren.includes(this)&&this.parent.unsubscribeDetachedChild(this),i==null||i.attemptAutoclose("remove-from-parent",this.id),{added:R(p),updated:R(a),removed:R(o),affected:R(e),self:this}}remove({ignoreUpstream:i}={ignoreUpstream:!1},a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-entity"))){const o=[],p=[],e=[],y=[];if(a!=null&&a.hasRemoved(this.id))return a==null||a.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(p.push(this),this.unsubscribe(),this.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},a),Object.values(this.detachedDependents).forEach(v=>{const{updated:E,removed:b,added:A}=v.entity.onDetachedDependencyRemoved(this,v.field,a);o.push(...E),p.push(...b),e.push(...A)}),this.defaultValue){const{updated:v,removed:E}=this.defaultValue.remove({ignoreUpstream:!0},a);o.push(...v),p.push(...E)}if(this.readsValue&&(o.push(this.readsValue),this.readsValue.removeValueReader(this,a)),this.writesValues.forEach(v=>{o.push(v),v.setValueWriter(null,a)}),this.inputs.forEach(v=>{const{updated:E,removed:b}=v.remove({ignoreUpstream:!0},a);o.push(...E),p.push(...b)}),this.outputs.forEach(v=>{const{updated:E,removed:b}=v.remove({ignoreUpstream:!0},a);o.push(...E),p.push(...b)}),this.successCalls.forEach(v=>{o.push(v),v.removeCaller(this,a)}),this.errorCalls.forEach(v=>{o.push(v),v.removeCaller(this,a)}),this.internalCalls.forEach(v=>{const{updated:E,removed:b}=v.remove({ignoreUpstream:!0},a);o.push(...E),p.push(...b)}),!i){const v=this.removeFromParent(a);e.push(...v.added),o.push(...v.updated),p.push(...v.removed),y.push(...v.affected),this.calledBy.forEach(E=>{o.push(E),E.removeCall(this,a)})}return a==null||a.attemptAutoclose("remove-entity",this.id),{added:R(e),updated:R(o),removed:R(p),affected:R(y),self:this}}restore({}={},i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"restore-entity"))){const a=[],o=[],p=[],e=[];if(i!=null&&i.hasAdded(this.id))return i==null||i.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},i),Object.values(this.detachedDependents).forEach(y=>{const{updated:v,removed:E,added:b}=y.entity.onDetachedDependencyRestored(this,y.field,i);o.push(...v),p.push(...E),a.push(...b)}),this.defaultValue){const{updated:y}=this.defaultValue.restore({},i);o.push(...y)}return this.readsValue&&(o.push(this.readsValue),this.readsValue.addValueReader(this,i)),this.writesValues.forEach(y=>{o.push(y),y.setValueWriter(this,i)}),this.inputs.forEach(y=>{const{updated:v}=y.restore({},i);o.push(...v)}),this.outputs.forEach(y=>{const{updated:v}=y.restore({},i);o.push(...v)}),this.successCalls.forEach(y=>{o.push(y),y.addSuccessCaller(this,i)}),this.errorCalls.forEach(y=>{o.push(y),y.addErrorCaller(this,i)}),this.internalCalls.forEach(y=>{const{updated:v}=y.restore({},i);o.push(...v)}),this.calledBySuccess.forEach(y=>{o.push(y),y.addSuccessCall(this,i)}),this.calledByError.forEach(y=>{o.push(y),y.addErrorCall(this,i)}),this.calledByEntry.forEach(y=>{o.push(y),y.addCall(this,i)}),i==null||i.attemptAutoclose("restore-entity",this.id),{added:R(a),updated:R(o),removed:R(p),affected:R(e),self:this}}toFlat(i=new Set){var o,p;return i.has(this.id)?[]:(i.add(this.id),[this,...((o=this.defaultValue)==null?void 0:o.toFlat(i))||[],...this.writesValues.flatMap(e=>e.toFlat(i)),...((p=this.readsValue)==null?void 0:p.toFlat(i))||[],...this.successCalls.flatMap(e=>e.toFlat(i)),...this.errorCalls.flatMap(e=>e.toFlat(i)),...this.inputs.flatMap(e=>e.toFlat(i)),...this.outputs.flatMap(e=>e.toFlat(i)),...this.internalCalls.flatMap(e=>e.toFlat(i))])}toFlatIds(i=new Set){var o;return i.has(this.id)?[]:(i.add(this.id),[this.id,...((o=this.defaultValue)==null?void 0:o.toFlatIds(i))||[],...this.writesValues.flatMap(p=>p.toFlatIds(i)),...this.successCalls.flatMap(p=>p.toFlatIds(i)),...this.errorCalls.flatMap(p=>p.toFlatIds(i)),...this.inputs.flatMap(p=>p.toFlatIds(i)),...this.outputs.flatMap(p=>p.toFlatIds(i)),...this.internalCalls.flatMap(p=>p.toFlatIds(i))])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,x:this.x,y:this.y,type:this.type}}toJSON(i=new Set){var a,o;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,declaration:this.declaration.toJSON(i),defaultValue:((a=this.defaultValue)==null?void 0:a.toJSON(i))||null,readsValue:((o=this.readsValue)==null?void 0:o.toReference())||null,writesValues:this.writesValues.map(p=>p.toJSON(i)),inputs:this.inputs.map(p=>p.toJSON(i)),outputs:this.outputs.map(p=>p.toJSON(i)),successCalls:this.successCalls.map(p=>p.toJSON(i)),errorCalls:this.errorCalls.map(p=>p.toJSON(i)),internalCalls:this.internalCalls.map(p=>p.toJSON(i)),calledBySuccess:this.calledBySuccess.map(p=>p.toReference()),calledByError:this.calledByError.map(p=>p.toReference()),calledByEntry:this.calledByEntry.map(p=>p.toReference()),parent:this.parent.toReference(),x:this.x,y:this.y})}toJSONClone(i=ke){var o,p,e,y,v,E,b;let a;return(o=i.seenEntityMaps)!=null&&o.has(this.id)?a=i.seenEntityMaps.get(this.id):(a=i.newId||Sr(this,this.project,i.uuidStrategy),i.seenEntityMaps&&i.seenEntityMaps.set(this.id,a)),(p=i.seenEntities)!=null&&p.has(a)||(e=i.seenEntities)!=null&&e.has(this.id)?this.toReference({seenEntityMaps:i.seenEntityMaps}):((y=i.seenEntities)==null||y.add(a),(v=i.seenEntities)==null||v.add(this.id),{id:a,version:N.UUID.uuid(),createdAt:i.timestamp||L().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,defaultValue:((E=this.defaultValue)==null?void 0:E.toJSONClone({...i,newId:null}))||null,declaration:this.declaration.toReference({seenEntityMaps:i.seenEntityMaps}),readsValue:((b=this.readsValue)==null?void 0:b.toReference({seenEntityMaps:i.seenEntityMaps}))||null,writesValues:this.writesValues.map(A=>A.toJSONClone({...i,newId:null})),inputs:this.inputs.map(A=>A.toJSONClone({...i,newId:null})),outputs:this.outputs.map(A=>A.toJSONClone({...i,newId:null})),successCalls:this.successCalls.map(A=>A.toJSONClone({...i,newId:null})),errorCalls:this.errorCalls.map(A=>A.toJSONClone({...i,newId:null})),internalCalls:this.internalCalls.map(A=>this.calledBy.length||this.readsValue?A.toJSONClone({...i,newId:null}):A.toReference({seenEntityMaps:i.seenEntityMaps})),calledBySuccess:this.calledBySuccess.map(A=>A.toReference({seenEntityMaps:i.seenEntityMaps})),calledByError:this.calledByError.map(A=>A.toReference({seenEntityMaps:i.seenEntityMaps})),calledByEntry:this.calledByEntry.map(A=>A.toReference({seenEntityMaps:i.seenEntityMaps})),parent:this.parent.toReference({seenEntityMaps:i.seenEntityMaps}),x:this.x,y:this.y})}toReference(i=ke){var o;let a=this.id;return(o=i.seenEntityMaps)!=null&&o.has(this.id)&&(a=i.seenEntityMaps.get(this.id)),{id:a+"--"+N.UUID.uuid()+"--ref",type:f.GenericReference,entityId:a,version:this.version,entityType:this.type}}toShallowJSON(i=ke){var o,p,e,y;let a=this.id;return(o=i.seenEntityMaps)!=null&&o.has(this.id)&&(a=i.seenEntityMaps.get(this.id)),{id:a,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,defaultValue:((p=this.defaultValue)==null?void 0:p.toReference(i))||null,declaration:((e=this.declaration)==null?void 0:e.toReference(i))||null,readsValue:((y=this.readsValue)==null?void 0:y.toReference(i))||null,writesValues:this.writesValues.map(v=>v.toReference(i)),inputs:this.inputs.map(v=>v.toReference(i)),outputs:this.outputs.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)),internalCalls:this.internalCalls.map(v=>v.toReference(i)),parent:this.parent.toReference(i)}}toFlatJSON(i=new Set){var o,p;return i.has(this.id)?[]:(i.add(this.id),[this.toShallowJSON(),...((o=this.defaultValue)==null?void 0:o.toFlatJSON(i))||[],...((p=this.declaration)==null?void 0:p.toFlatJSON(i))||[],...this.writesValues.flatMap(e=>e.toFlatJSON(i)),...this.successCalls.flatMap(e=>e.toFlatJSON(i)),...this.errorCalls.flatMap(e=>e.toFlatJSON(i)),...this.inputs.flatMap(e=>e.toFlatJSON(i)),...this.outputs.flatMap(e=>e.toFlatJSON(i)),...this.internalCalls.flatMap(e=>e.toFlatJSON(i)),...this.calledBy.flatMap(e=>e.toFlatJSON(i))])}toGenerationTarget(){const i=this.parent.type===f.Project?void 0:this.parent.id;return{id:this.id,type:this.type,declaration:this.declaration.id,calledByEntry:this.calledByEntry.map(a=>a.id),calledBySuccess:this.calledBySuccess.map(a=>a.id),calledByError:this.calledByError.map(a=>a.id),parent:i}}toFlatGenerationTarget(i=new Set){var o,p,e;return i.has(this.id)?[]:(i.add(this.id),[this.toGenerationTarget(),...((o=this.defaultValue)==null?void 0:o.toFlatGenerationTarget(i))||[],...((p=this.declaration)==null?void 0:p.toFlatGenerationTarget(i))||[],...((e=this.readsValue)==null?void 0:e.toFlatGenerationTarget(i))||[],...this.writesValues.flatMap(y=>y.toFlatGenerationTarget(i)),...this.successCalls.flatMap(y=>y.toFlatGenerationTarget(i)),...this.errorCalls.flatMap(y=>y.toFlatGenerationTarget(i)),...this.inputs.flatMap(y=>y.toFlatGenerationTarget(i)),...this.outputs.flatMap(y=>y.toFlatGenerationTarget(i)),...this.internalCalls.flatMap(y=>y.toFlatGenerationTarget(i))])}clearErrors(){var i;return this.errors=[],(i=this.defaultValue)==null||i.clearErrors(),this.inputs.forEach(a=>a.clearErrors()),this.outputs.forEach(a=>a.clearErrors()),this.successCalls.forEach(a=>a.clearErrors()),this.errorCalls.forEach(a=>a.clearErrors()),this.internalCalls.forEach(a=>a.clearErrors()),this}validate(){const i=t3(this);return this.errors=i,{success:!0}}getErrors(){var a,o;return[...this.errors,...((a=this.defaultValue)==null?void 0:a.getErrors())||[],...this.inputs.flatMap(p=>p.getErrors()),...this.internalCalls.flatMap(p=>p.getErrors()),...this.outputs.flatMap(p=>p.getErrors()),...((o=this.readsValue)==null?void 0:o.getErrors())||[]]}getShallowErrors(){return this.errors}getDefaultValue(){var i;return this.defaultValue||((i=this.declaration)==null?void 0:i.defaultValue)||null}setDefaultValue(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"set-default-value"))){const o=this.defaultValue;return(o==null?void 0:o.id)!==(i==null?void 0:i.id)&&(o==null||o.remove({ignoreUpstream:!0},a),this.defaultValue=i,a==null||a.add(this,F.Affected)),a==null||a.attemptAutoclose("set-default-value",this.id),this}clone(i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"clone-entity")),a=null,o=null,p=!0){var U,S,K,Z;let e=Fr(a,this);const y=this.toJSON(),v=o||N.UUID.uuid();y.inputs=[],y.id=v,y.version=N.UUID.uuid(),y.createdAt=(i==null?void 0:i.timestamp)||L().toISOString(),y.author=(i==null?void 0:i.author)||"1",y.previousVersion=null,y.deleted=!1;const E=lr(y,e);a?E.setParent(a,null):E.setParent(this.parent,null),p&&E.subscribe(),E.initChildren(i),i==null||i.add(E,F.Added);const b=(U=this.defaultValue)==null?void 0:U.clone(i,E,N.UUID.uuid(),p);E.defaultValue=b||null;const A=(S=this.inputs)==null?void 0:S.map(ie=>ie.clone(i,E,N.UUID.uuid(),p));E.inputs=A;const $=(K=this.outputs)==null?void 0:K.map(ie=>ie.clone(i,E,N.UUID.uuid(),p));E.outputs=$;const V=(Z=this.internalCalls)==null?void 0:Z.map(ie=>ie.clone(i,E,N.UUID.uuid(),p));return E.internalCalls=V,i==null||i.attemptAutoclose("clone-entity",this.id),E}addInternalCall(i){return this.internalCalls.find(a=>a===i)||this.internalCalls.push(i),this}setDeclaration(i){return this.declaration!==i&&(this.declaration=i),this}removeUnrecognizedInputs(i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-unrecognized-variable-instance-inputs"))){const a=[],o=[],p=[],e=[];return this.declaration.dataType&&!this.declaration.dataType.isObject()?[...this.inputs].forEach(y=>{const v=y.remove({ignoreUpstream:!1},i);p.push(...v.removed),a.push(...v.updated)}):this.declaration.dataType&&this.declaration.dataType.hasStrictObjectStructure()&&[...this.inputs].forEach(y=>{var E;if(!y.declaration){const b=y.remove({ignoreUpstream:!1},i);p.push(...b.removed),a.push(...b.updated);return}if(![...((E=this.declaration.dataType)==null?void 0:E.entity).allProperties].find(b=>y.declaration===b)){const b=y.remove({ignoreUpstream:!1},i);p.push(...b.removed),a.push(...b.updated)}}),i==null||i.attemptAutoclose("remove-unrecognized-variable-instance-inputs",this.id),{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}removeUnrecognizedOutputs(i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-unrecognized-variable-instance-outputs"))){const a=[],o=[],p=[],e=[];return this.declaration.dataType&&!this.declaration.dataType.isObject()?[...this.outputs].forEach(y=>{const v=y.remove({ignoreUpstream:!1},i);p.push(...v.removed),a.push(...v.updated)}):this.declaration.dataType&&this.declaration.dataType.hasStrictObjectStructure()&&[...this.outputs].forEach(y=>{var E;if(!y.declaration){const b=y.remove({ignoreUpstream:!1},i);p.push(...b.removed),a.push(...b.updated);return}if(![...((E=this.declaration.dataType)==null?void 0:E.entity).allProperties].find(b=>y.declaration===b)){const b=y.remove({ignoreUpstream:!1},i);p.push(...b.removed),a.push(...b.updated)}}),i==null||i.attemptAutoclose("remove-unrecognized-variable-instance-outputs",this.id),{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}removeUnrecognizedInternalCalls(i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-unrecognized-variable-declaration-internal-calls"))){var v;const a=[],o=[],p=[],e=[];if(!this.declaration.dataType||!this.declaration.dataType.entity||![f.DefinitionEntity,f.PrimitiveEntity,f.BuiltInBaseEntity].includes(this.declaration.dataType.entity.type))[...this.internalCalls].forEach(E=>{const b=E.remove({ignoreUpstream:!1},i);p.push(...b.removed),a.push(...b.updated)});else if(this.declaration.dataType&&this.declaration.dataType.entity&&[f.DefinitionEntity,f.PrimitiveEntity,f.BuiltInBaseEntity].includes(this.declaration.dataType.entity.type)){const E=[...((v=this.declaration.dataType)==null?void 0:v.entity).allMethods];[...this.internalCalls].forEach(b=>{if(!b.declaration){const $=b.remove({ignoreUpstream:!1},i);p.push(...$.removed),a.push(...$.updated);return}if(!E.find($=>b.declaration===$)){const $=b.remove({ignoreUpstream:!1},i);p.push(...$.removed),a.push(...$.updated);return}})}return this.internalCalls.filter((E,b)=>{const A=this.internalCalls.findIndex(V=>V.declaration===E.declaration&&V!==E);if(A===-1)return!1;const $=this.internalCalls[A];return L($==null?void 0:$.createdAt).isSame(L(E.createdAt))?b>A:!!L($==null?void 0:$.createdAt).isAfter(E.createdAt)}).forEach(E=>{const b=E.remove({ignoreUpstream:!1},i);p.push(...b.removed),a.push(...b.updated)}),i==null||i.attemptAutoclose("remove-unrecognized-variable-declaration-internal-calls",this.id),{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}syncInputs(i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"sync-variable-instance-inputs"))){const a=[],o=[],p=[],e=[];if(this.declaration.dataType)if(this.declaration.dataType.entity){if([f.DefinitionEntity,f.PrimitiveEntity,f.BuiltInBaseEntity].includes(this.declaration.dataType.entity.type)&&!this.declaration.dataType.isList){const y=[...this.declaration.dataType.entity.properties];y.filter(A=>!A.getDataType(i)).forEach(A=>{const $=this.inputs.find(S=>ne(S,this.project)===ne(A,this.project));if(!$)return;const V=this.declaration.getMasterInputWithValueWritterFromAllInstances($);if(!V)return;const U=mn(V);A.setDataType(U,i),$.setDeclaration(A,i)}),y.filter(A=>!this.inputs.find($=>{var V;return((V=$.declaration)==null?void 0:V.id)===A.id})).forEach(A=>{const $={id:N.UUID.uuid(),version:N.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||L().toISOString(),author:N.sessionAuthor,previousVersion:null,deleted:!1,type:f.InputMap,parent:this.toReference(),name:null,description:null,codeName:null,declaration:A,defaultValue:null,index:A.index,readsValue:null},V=te($,this.project);return V.setParent(this,i),V.initChildren(i),i==null||i.add(V,F.Added),this.addInput(V,i),V}),this.inputs.filter(A=>!A.declaration).forEach(A=>{const $=y.find(V=>ne(V,this.project)===ne(A,this.project));$&&A.setDeclaration($,i)})}}else return i==null||i.attemptAutoclose("sync-variable-instance-inputs",this.id),{added:[],updated:[],removed:[],affected:[],self:this};else return i==null||i.attemptAutoclose("sync-variable-instance-inputs",this.id),{added:[],updated:[],removed:[],affected:[],self:this};return i==null||i.attemptAutoclose("sync-variable-instance-inputs",this.id),{added:R(a),updated:R(o),removed:R(p),affected:R(e),self:this}}syncOutputs(i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"sync-variable-instance-outputs"))){const a=[],o=[],p=[],e=[];if(this.declaration.dataType)if(this.declaration.dataType.entity)[f.DefinitionEntity,f.PrimitiveEntity,f.BuiltInBaseEntity].includes(this.declaration.dataType.entity.type)&&!this.declaration.dataType.isList&&[...this.declaration.dataType.entity.properties].filter(E=>!this.outputs.find(b=>b.declaration===E)).map(E=>{const b={id:N.UUID.uuid(),version:N.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||L().toISOString(),author:N.sessionAuthor,previousVersion:null,deleted:!1,type:f.OutputMap,parent:this.toReference(),defaultValue:null,declaration:E,index:E.index,writesValues:[]},A=te(b,this.project);return A.setParent(this,i),A.initChildren(i),i==null||i.add(A,F.Added),this.addOutput(A,i),A});else return i==null||i.attemptAutoclose("sync-variable-instance-outputs",this.id),{added:[],updated:[],removed:[],affected:[],self:this};else return i==null||i.attemptAutoclose("sync-variable-instance-outputs",this.id),{added:[],updated:[],removed:[],affected:[],self:this};return i==null||i.attemptAutoclose("sync-variable-instance-outputs",this.id),{added:R(a),updated:R(o),removed:R(p),affected:R(e),self:this}}generateUnusedInternalCalls(i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"generate-unused-internal-calls"))){const a=[],o=[],p=[],e=[];if(this.declaration.dataType)if(this.declaration.dataType.entity)[f.DefinitionEntity,f.PrimitiveEntity,f.BuiltInBaseEntity].includes(this.declaration.dataType.entity.type)&&!this.declaration.dataType.isList&&[...this.declaration.dataType.entity.getAllInteractiveMethods()].filter(E=>!this.internalCalls.find(A=>{var V,U,S,K,Z;return(((V=A.declaration)==null?void 0:V.id)||((S=(U=A.initialData)==null?void 0:U.declaration)==null?void 0:S.entityId)||((Z=(K=A.initialData)==null?void 0:K.declaration)==null?void 0:Z.id))===E.id})).map(E=>{const b=E.createInternalCall(i,this);return i==null||i.add(b,F.Added),this.addInternalCall(b),b});else return i==null||i.attemptAutoclose("generate-unused-internal-calls",this.id),{added:[],updated:[],removed:[],affected:[],self:this};else return i==null||i.attemptAutoclose("generate-unused-internal-calls",this.id),{added:[],updated:[],removed:[],affected:[],self:this};return i==null||i.attemptAutoclose("generate-unused-internal-calls",this.id),{added:R(a),updated:R(o),removed:R(p),affected:R(e),self:this}}getDataType(i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"get-data-type"))){var a;return((a=this.declaration)==null?void 0:a.getDataType(i))||null}getUnusedInputs(){return this.inputs.filter(i=>i.suggestion||!i.readsValue&&!i.defaultValue)}getUnusedOutputs(){return this.outputs.filter(i=>i.suggestion||!i.writesValues.length)}getUsedInputs(){return this.inputs.filter(i=>!i.suggestion&&(i.readsValue||i.defaultValue))}getUsedOutputs(){return this.outputs.filter(i=>!i.suggestion&&i.writesValues.length)}};g(xt,"repository",{APICreate:async(i,...a)=>i,APIUpdate:async(i,...a)=>i,APIDelete:async(i,...a)=>i,APIClone:async(i,...a)=>{},APILoad:async(i,...a)=>null,APILoadVersion:async(i,a,...o)=>null}),g(xt,"type",f.VariableInstance),g(xt,"USER_MANAGED_PARENT_TYPES",[...Mr,f.Project]),g(xt,"PARENT_TYPES",[...xt.USER_MANAGED_PARENT_TYPES]),g(xt,"MUTABLE_BASE_PROPERTIES",[]),g(xt,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),g(xt,"BASE_PROPERTIES",[...xt.MUTABLE_BASE_PROPERTIES,...xt.INMUTABLE_BASE_PROPERTIES]),g(xt,"MUTABLE_META_PROPERTIES",[...xt.MUTABLE_BASE_PROPERTIES,"x","y"]),g(xt,"INMUTABLE_META_PROPERTIES",[...xt.INMUTABLE_BASE_PROPERTIES]),g(xt,"META_PROPERTIES",[...xt.MUTABLE_META_PROPERTIES,...xt.INMUTABLE_META_PROPERTIES]),g(xt,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry","readsValue"]),g(xt,"INMUTABLE_UPSTREAM_PROPERTIES",["declaration","parent"]),g(xt,"UPSTREAM_PROPERTIES",[...xt.MUTABLE_UPSTREAM_PROPERTIES,...xt.INMUTABLE_UPSTREAM_PROPERTIES]),g(xt,"MUTABLE_DOWNSTREAM_PROPERTIES",["writesValues","inputs","outputs","successCalls","errorCalls","internalCalls"]),g(xt,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),g(xt,"DOWNSTREAM_PROPERTIES",[...xt.MUTABLE_DOWNSTREAM_PROPERTIES,...xt.INMUTABLE_DOWNSTREAM_PROPERTIES]),g(xt,"PROPERTIES",[...xt.META_PROPERTIES,...xt.UPSTREAM_PROPERTIES,...xt.DOWNSTREAM_PROPERTIES]);let lo=xt;var r3=(d=>(d.Parent="parent",d.DataTypeEntity="variable-data-type-entity",d.DataType="variable-data-type",d))(r3||{});const Gt=class Gt extends Nr{constructor(i,a){super(i);g(this,"initialData");g(this,"id");g(this,"name");g(this,"codeName",null);g(this,"description",null);g(this,"required",!1);g(this,"constant",!1);g(this,"x");g(this,"y");g(this,"type",f.VariableDeclaration);g(this,"defaultValue",null);g(this,"dataType",null);g(this,"writesValues",[]);g(this,"readsValue",null);g(this,"inputs",[]);g(this,"outputs",[]);g(this,"calledBySuccess",[]);g(this,"calledByError",[]);g(this,"calledByEntry",[]);g(this,"successCalls",[]);g(this,"errorCalls",[]);g(this,"internalCalls",[]);g(this,"parent");g(this,"errors",[]);g(this,"project");g(this,"detachedDependents",{});g(this,"knownVersions",null);g(this,"activeVersion",!1);g(this,"initialized",!1);g(this,"startedInitialization",!1);g(this,"suggestion",!1);g(this,"codeNativeValueValidation",null);this.initialData=i,this.project=a,this.id=i.id,this.name=i.name,this.description=i.description,this.constant=i.constant,this.codeName=i.codeName,this.required=i.required,this.x=i.x,this.y=i.y}static new(i=null){return{id:N.UUID.uuid(),version:N.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||L().toISOString(),author:(i==null?void 0:i.author)||N.sessionAuthor,previousVersion:null,deleted:!1,type:f.VariableDeclaration,name:"",codeName:null,description:"",dataType:null,internalCalls:[],successCalls:[],errorCalls:[],readsValue:null,writesValues:[],defaultValue:null,constant:!1,required:!1,inputs:[],outputs:[],parent:null,calledByEntry:[],calledBySuccess:[],calledByError:[],x:0,y:0}}static fromGenerationTarget(i,a){let o=a;if(i.parent){const A=J(i.parent);o=a.get(A)}const p=i.calledByEntry.map(A=>{const $=J(A);return a.get($)}),e=i.calledBySuccess.map(A=>{const $=J(A);return a.get($)}),y=i.calledByError.map(A=>{const $=J(A);return a.get($)});let v=null;if(i.readsValue){const A=J(i.readsValue);v=a.get(A)}const E={id:i.id,version:N.UUID.uuid(),createdAt:L().toISOString(),author:N.sessionAuthor,previousVersion:null,deleted:!1,type:f.VariableDeclaration,name:i.name,defaultValue:null,codeName:i.codeName||null,description:i.description||null,constant:i.constant||!1,required:i.required||!1,calledByEntry:p,calledBySuccess:e,calledByError:y,dataType:null,errorCalls:[],successCalls:[],internalCalls:[],readsValue:v,inputs:[],outputs:[],writesValues:[],x:0,y:0,parent:o},b=te(E,a);return b.setParent(o,null),b}static validateGenerationTarget(i,a){let o=JSON.parse(JSON.stringify(i));const p=[],e=oi(o,{parent:{list:!1,types:[...Mr,f.Project],optional:!0}},a);o=e.modifiedData;const y=Qb(o,a);return p.push(...e.errors,...y,...Br(o)),{errors:p,modifiedData:o}}get variableInstances(){const i=[];return Object.values(this.detachedDependents).forEach(a=>{a.field===pA.VarDeclaration&&!i.includes(a.entity)&&i.push(a.entity)}),i}validateGeneratedUpdate(i){const a=[];let o=JSON.parse(JSON.stringify(i));const p=zp(o,this);return o=p.modifiedData,a.push(...p.errors),i.parent&&a.push(new ee({id:`${this.id}--${k.InvalidParentUpdate}`,code:k.InvalidParentUpdate,severity:q.Error,message:`Entity of type '${this.type}' with id '${this.id}' cannot have the 'parent' property updated. The 'parent' on a callable entity, is its scope. It scope is auto-calculated implicitly by the its caller.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elyx-code/project-logic-tree",
3
- "version": "0.0.6427",
3
+ "version": "0.0.6428",
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",