@elyx-code/project-logic-tree 0.0.6530 → 0.0.6532

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
@@ -104261,7 +104261,10 @@ This is likely an incorrect strategy, either the '${this.type}' entity doesn't n
104261
104261
  )) {
104262
104262
  const a = [], o = [], f = [], e = [], y = this.declaration.inputs.filter(
104263
104263
  (I) => !this.inputs.find(
104264
- (D) => D.declaration.id === I.id
104264
+ (D) => {
104265
+ var V;
104266
+ return ((V = D.declaration) == null ? void 0 : V.id) === I.id;
104267
+ }
104265
104268
  )
104266
104269
  );
104267
104270
  this.inputs.sort((I, D) => I.index - D.index), y.forEach((I) => {
@@ -147,7 +147,7 @@ ${Ho}`);const V=o.declaration;if(!a.get(V))f.push(new le({id:`${o.id}--${K.Refer
147
147
  The declaration of the internal-call must be a 'function-declaration' entity which exists as a method in the entity of the data-type of the parent variable.${O}`})):f.push(new le({id:`${o.id}--${ae.InternalCallDeclarationNotFoundInParentDatatypeEntity}`,code:ae.InternalCallDeclarationNotFoundInParentDatatypeEntity,severity:H.Error,message:`Entity of type "${o.type}" with id "${o.id}", belongs to a variable whose data type entity doesn't contain its declaration method (function-declaration) with id "${o.declaration}".${O}`}))}}(v.inputs.length||v.outputs.length||v.internalCalls.length)&&f.push(new le({id:`${o.id}--${K.InvalidInternalCallParentRelation}`,code:K.InvalidInternalCallParentRelation,severity:H.Error,message:`Entity of type "${o.type}" with id "${o.id}", can only be added to a variable declaration or variable instance parent if the parent doesn't already have inputs, outputs or other internal calls.
148
148
  If you need a new variable-instance for this, consider using the 'implement_variable_instance' generation action to create one and give it a caller.
149
149
  The you can attach the new internal-call to it.`}))}return f.push(...e.errors,...Zi(o)),{errors:f,modifiedData:o}}validateGeneratedUpdate(i){const a=[];return i.parent&&a.push(new le({id:`${this.id}--${K.InvalidParentUpdate}`,code:K.InvalidParentUpdate,severity:H.Error,message:`Entity of type '${this.type}' with id '${this.id}' cannot have the 'parent' property updated, as it would mean moving the '${this.type}' entity to another parent entity.
150
- This is likely an incorrect strategy, either the '${this.type}' entity doesn't need to be updated or it should be deleted and a new one created in the desired parent.`})),{errors:a,modifiedData:i}}subscribeDependents(i){return i.forEach(a=>{this.detachedDependents[a.entity.id]||(this.detachedDependents[a.entity.id]=a)}),this}unsubscribeDependents(i){return i.forEach(a=>{this.detachedDependents[a.entity.id]&&delete this.detachedDependents[a.entity.id]}),this}syncDependents(i=this.project.addChangeSet(new k(this.project,N.sessionAuthor,L().toISOString(),this,!0,"sync-dependents"))){const a=[],o=[],f=[],e=[];return Object.values(this.detachedDependents).forEach(y=>{const v=y.entity.afterAllChildrenInitialized(i);a.push(...v.updated),o.push(...v.added),f.push(...v.removed),e.push(...v.affected)}),i==null||i.attemptAutoclose("sync-dependents",this.id),{updated:w(a),added:w(o),removed:w(f),affected:w(e),self:this}}onDetachedDependencyRemoved(i,a,o){const f=[],e=[],y=[],v=[];if(a==="declaration"){const{updated:T,added:b,removed:I}=this.remove({ignoreUpstream:!1},o);f.push(...T),e.push(...b),y.push(...I)}return{updated:w(f),added:w(e),removed:w(y),affected:w(v),self:this}}onDetachedDependencyRestored(i,a,o){const f=[],e=[],y=[],v=[];if(a==="declaration"){const{updated:T,added:b,removed:I}=this.restore({},o);f.push(...T),e.push(...b),y.push(...I)}return{updated:w(f),added:w(e),removed:w(y),affected:w(v),self:this}}unsubscribeFromDependencies(){return this.declaration.unsubscribeDependents([{entity:this,field:"declaration"}]),this}subscribeToDependencies(){return this.declaration.subscribeDependents([{entity:this,field:"declaration"}]),this}increaseVersion(i){if(i&&!L(i).isValid())throw new Error(`The shared timestamp '${i}' is not a valid ISO 8601 date string.`);return i&&L(i).isSame(L(this.createdAt))?this:(this.previousVersion=this.version,this.version=N.UUID.uuid(),this.createdAt=L(i).toISOString()||L().toISOString(),this)}captureVersion(){var a;const i=((a=this.knownVersions)==null?void 0:a.get(this.version))||new 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.outputs=[...this.outputs],i.error=this.error,i.process=this.process,i.successCalls=[...this.successCalls],i.errorCalls=[...this.errorCalls],i.calledBySuccess=[...this.calledBySuccess],i.calledByError=[...this.calledByError],i.calledByEntry=[...this.calledByEntry],i.declaration=this.declaration,i.parent=this.parent,this}recursiveCaptureUpstreamVersions(i){const a=[],o=[],f=[],e=[];if(this.parent){this.parent.increaseVersion(i);const y=this.parent.recursiveCaptureUpstreamVersions(i);a.push(this.parent,...y.updated),o.push(...y.added),f.push(...y.removed)}return{updated:w(a),added:w(o),removed:w(f),affected:w(e),self:this}}async restoreVersion(i){var v;const a=[],o=[],f=[],e=[];if(this.version===i)return{updated:w(a),added:w(o),removed:w(f),affected:w(e),self:this};if(!this.knownVersions){const T=new Map;for(const[b,I]of this.knownVersions||new Map){if(T.set(b,I),I.activeVersion=!1,I.knownVersions)for(const[O,V]of I.knownVersions)T.set(O,V);I.knownVersions=null}}let y=(v=this.knownVersions)==null?void 0:v.get(i);if(!y){const T=await this.APILoadVersion({},i);if(!T)throw new Error(`Version with id '${i}' for entity with id '${this.id}' not found.`);y=new zt(T,this.project)}return this.metaSync(y.toShallowJSON(),null),this.previousVersion=y.previousVersion,this.version=y.version,this.createdAt=y.createdAt,this.author=y.author,this.deleted=y.deleted,this.inputs=y.inputs,this.outputs=y.outputs,this.error=y.error,this.process=y.process,this.successCalls=y.successCalls,this.errorCalls=y.errorCalls,this.calledBySuccess=y.calledBySuccess,this.calledByError=y.calledByError,this.calledByEntry=y.calledByEntry,this.declaration=y.declaration,this.parent=y.parent,{updated:w(a),added:w(o),removed:w(f),affected:w(e),self:this}}updateWithShallowTransfer(i,a=this.project.addChangeSet(new k(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=z(i.parent),f=this.project.get(o),e=this.parent;if(e&&e.id!==(f==null?void 0:f.id)&&this.removeFromParent(a),f)this.setParent(f,a);else throw a==null||a.attemptAutoclose("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=z(i.declaration),f=this.project.get(o);f&&this.setDeclaration(f)}return i.calledByEntry.forEach(o=>{const f=z(o),e=this.project.get(f);e&&(this.addEntryCaller(e,a),e.addCall(this,a))}),[...this.calledByEntry].forEach(o=>{i.calledByEntry.find(e=>z(e)===o.id)||(this.removeCaller(o,a),o.removeCall(this,a))}),i.calledBySuccess.forEach(o=>{const f=z(o),e=this.project.get(f);e&&(this.addSuccessCaller(e,a),e.addSuccessCall(this,a))}),[...this.calledBySuccess].forEach(o=>{i.calledBySuccess.find(e=>z(e)===o.id)||(this.removeCaller(o,a),o.removeCall(this,a))}),i.calledByError.forEach(o=>{const f=z(o),e=this.project.get(f);e&&(this.addErrorCaller(e,a),e.addErrorCall(this,a))}),[...this.calledBySuccess].forEach(o=>{i.calledBySuccess.find(e=>z(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=[],f=[];if(this.initialData.parent){const e=z(this.initialData.parent),y=this.project.get(e);if(y)this.setParent(y,null),i.push(y);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${e}' that isn't found in the project`)}else throw new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(this.initialData.declaration){const e=z(this.initialData.declaration),y=this.project.get(e);y&&(this.setDeclaration(y),i.push(y))}return this.initialData.calledByEntry.forEach(e=>{const y=z(e),v=this.project.get(y);v&&this.addEntryCaller(v,null)}),this.initialData.calledBySuccess.forEach(e=>{const y=z(e),v=this.project.get(y);v&&this.addSuccessCaller(v,null)}),this.initialData.calledByError.forEach(e=>{const y=z(e),v=this.project.get(y);v&&this.addErrorCaller(v,null)}),{updated:w(i),added:w(a),removed:w(o),affected:w(f),self:this}}afterAllChildrenInitialized(i=this.project.addChangeSet(new k(this.project,N.sessionAuthor,L().toISOString(),this,!0,"after-all-children-initialized"))){const a=[],o=[],f=[],e=[];this.initialized=!0;const{updated:y,added:v,removed:T}=this.syncInputs(i),{updated:b,added:I,removed:O}=this.syncOutputs(i);return a.push(...y,...b),o.push(...v,...I),f.push(...T,...O),this.captureVersion(),i==null||i.attemptAutoclose("after-all-children-initialized",this.id),{updated:w(a),added:w(o),removed:w(f),affected:w(e),self:this}}addSelfToProject(i=this.project.addChangeSet(new k(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-self-to-project"))){var y;const a=[this],o=[],f=[],e=[];return this.parent.addInternalCall(this),e.push(this.parent),(y=this.process)==null||y.writesValues.forEach(v=>{v.setValueWriter(this.process,i),a.push(v)}),this.successCalls.forEach(v=>{v.addSuccessCaller(this,i),a.push(v)}),this.errorCalls.forEach(v=>{v.addErrorCaller(this,i),a.push(v)}),this.calledBySuccess.forEach(v=>{v.addSuccessCall(this,i),a.push(v)}),this.calledByError.forEach(v=>{v.addErrorCall(this,i),a.push(v)}),this.calledByEntry.forEach(v=>{v.addCall(this,i),a.push(v)}),this.subscribe(),this.subscribeToDependencies(),i==null||i.attemptAutoclose("add-self-to-project",this.id),{updated:w(a),added:w(o),removed:w(f),affected:w(e),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}removeInput(i,a=this.project.addChangeSet(new k(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-input"))){const o=this.inputs.findIndex(f=>f.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 k(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 k(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 k(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-output"))){const o=this.outputs.findIndex(f=>f.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}addValueReader(i,a=this.project.addChangeSet(new k(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-value-reader"))){var o;return this.process&&!this.process.writesValues.includes(i)&&((o=this.process)==null||o.addValueReader(i,a),a==null||a.add(this,F.Affected)),a==null||a.attemptAutoclose("add-value-reader",this.id),this}removeValueReader(i,a=this.project.addChangeSet(new k(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-value-reader"))){var o;return this.process&&this.process.writesValues.includes(i)&&((o=this.process)==null||o.removeValueReader(i,a),a==null||a.add(this,F.Affected)),a==null||a.attemptAutoclose("remove-value-reader",this.id),this}addSuccessCaller(i,a=this.project.addChangeSet(new k(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-success-caller")),o=!1){return this.calledBySuccess.find(f=>f.id===i.id)||(this.calledBySuccess.push(i),a==null||a.add(this,F.Updated),o&&et(this,a)),a==null||a.attemptAutoclose("add-success-caller",this.id),this}addErrorCaller(i,a=this.project.addChangeSet(new k(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-error-caller")),o=!1){return this.calledByError.find(f=>f.id===i.id)||(this.calledByError.push(i),a==null||a.add(this,F.Updated),o&&et(this,a)),a==null||a.attemptAutoclose("add-error-caller",this.id),this}addEntryCaller(i,a=this.project.addChangeSet(new k(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-entry-caller")),o=!1){return this.calledByEntry.find(f=>f.id===i.id)||(this.calledByEntry.push(i),a==null||a.add(this,F.Updated),o&&et(this,a)),a==null||a.attemptAutoclose("add-entry-caller",this.id),this}addErrorCall(i,a=this.project.addChangeSet(new k(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-error-call")),o=!1){return this.errorCalls.find(f=>f.id===i.id)||(this.errorCalls.push(i),o&&et(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 k(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-success-call")),o=!1){return this.successCalls.find(f=>f.id===i.id)||(this.successCalls.push(i),o&&et(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 k(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-call")),o=!1){const f=this.successCalls.findIndex(y=>y.id===i.id);f>-1&&(this.successCalls.splice(f,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&&et(this,a),a==null||a.attemptAutoclose("remove-call",this.id),this}removeCaller(i,a=this.project.addChangeSet(new k(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-caller")),o=!1){return this.calledBySuccess=this.calledBySuccess.filter(f=>f.id!==i.id?!0:(a==null||a.add(this,F.Updated),a==null||a.add(f,F.Affected),!1)),this.calledByError=this.calledByError.filter(f=>f.id!==i.id?!0:(a==null||a.add(this,F.Updated),a==null||a.add(f,F.Affected),!1)),this.calledByEntry=this.calledByEntry.filter(f=>f.id!==i.id?!0:(a==null||a.add(this,F.Updated),a==null||a.add(f,F.Affected),!1)),o&&et(this,a),a==null||a.attemptAutoclose("remove-caller",this.id),this}setParent(i,a=this.project.addChangeSet(new k(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}setDeclaration(i){return this.declaration=i,this}initChildren(i=this.project.addChangeSet(new k(this.project,N.sessionAuthor,L().toISOString(),this,!0,"init-children"))){if(this.initialized||this.startedInitialization)return this;if(this.startedInitialization=!0,this.initialData.parent.type!==p.GenericReference){const a=oe(this.initialData.parent,this.project);this.setParent(a,null),this.parent.initChildren(i),this.parent.addInternalCall(this);const o=this.calledBy.find(f=>!!f.parent&&Ki.includes(f.parent.type));if(o){const f=oe(o.parent,this.project);this.parent.setParent(f,null)}else if(!o&&!this.parent.calledBy.length)throw new Error("Parent of internal call parent could not be resolved")}return this.declaration=oe(this.initialData.declaration,this.project),this.successCalls=this.initialData.successCalls.map(a=>{const o=oe(a,this.project);if(o.addSuccessCaller(this),[p.BreakStatement,p.ContinueStatement].includes(o.type))o.setParent(this.parent.parent,null),o.initChildren(i);else if(o.type===p.ReturnStatement){const f=lr(this.parent,this.project);o.setParent(f,null),o.initChildren(i)}else o.type!==p.InternalCall&&(o.setParent(this.parent.parent,null),o.initChildren(i));return o}),this.errorCalls=this.initialData.errorCalls.map(a=>{const o=oe(a,this.project);if(o.addErrorCaller(this),[p.BreakStatement,p.ContinueStatement].includes(o.type))o.setParent(this.parent.parent.parent,null),o.initChildren(i);else if(o.type===p.ReturnStatement){const f=lr(this.parent,this.project);o.setParent(f,null),o.initChildren(i)}else o.type!==p.InternalCall&&(o.setParent(this.parent.parent,null),o.initChildren(i));return o}),this.inputs=this.initialData.inputs.map(a=>{const o=oe(a,this.project);return o.setParent(this,null),o.initChildren(i),o}),this.outputs=this.initialData.outputs.map(a=>{const o=oe(a,this.project);return o.setParent(this,null),o.initChildren(i),o}),this.initialData.error&&(this.error=oe(this.initialData.error,this.project),this.error.setParent(this,null),this.error.initChildren(i)),this.initialData.process&&(this.process=oe(this.initialData.process,this.project),this.process.setParent(this,null),this.process.initChildren(i)),this.subscribeToDependencies(),this.afterAllChildrenInitialized(i),i==null||i.attemptAutoclose("init-children",this.id),this}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(i,a=this.project.addChangeSet(new k(this.project,N.sessionAuthor,L().toISOString(),this,!0,"meta-sync"))){const o=Hi(this,i),f=this.toMeta();return this.index=i.index||(i.index!==0?f.index:0),this.catchesError=i.catchesError!==void 0?i.catchesError:this.catchesError,super.metaSync(i),i.deleted===!0&&!f.deleted?a==null||a.add(this,F.Removed):i.deleted===!1&&f.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=Ee,...a){return await zt.repository.APILoad(this.id,...a),this}async APICreate(i=Ee,...a){return await zt.repository.APICreate(this.toShallowJSON(),...a),this}async APIUpdate(i=Ee,...a){return await zt.repository.APIUpdate(this.toShallowJSON(),...a),this}async APIDelete(i=Ee,...a){return await zt.repository.APIDelete(this.toShallowJSON(),...a),this}async APIClone(i=Ee,...a){return await zt.repository.APIClone(this.id,...a),this}async APILoadVersion(i=Ee,a,...o){return await zt.repository.APILoadVersion(this.id,a,...o)}removeFromParent(i=this.project.addChangeSet(new k(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-from-parent"))){const a=[],o=[],f=[],e=[];return this.parent&&(this.parent.removeInternalCall(this,i),e.push(this.parent)),i==null||i.attemptAutoclose("remove-from-parent",this.id),{added:w(f),updated:w(a),removed:w(o),affected:w(e),self:this}}remove({ignoreUpstream:i}={ignoreUpstream:!1},a=this.project.addChangeSet(new k(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-entity"))){var v;const o=[],f=[],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(f.push(this),this.unsubscribe(),this.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},a),Object.values(this.detachedDependents).forEach(T=>{const{updated:b,removed:I,added:O}=T.entity.onDetachedDependencyRemoved(this,T.field,a);o.push(...b),f.push(...I),e.push(...O)}),this.process){const{updated:T,removed:b}=(v=this.process)==null?void 0:v.remove({ignoreUpstream:!0},a);o.push(...T),f.push(...b)}if(this.inputs.forEach(T=>{const{updated:b,removed:I}=T.remove({ignoreUpstream:!0},a);o.push(...b),f.push(...I)}),this.outputs.forEach(T=>{const{updated:b,removed:I}=T.remove({ignoreUpstream:!0},a);o.push(...b),f.push(...I)}),this.error){const{updated:T,removed:b}=this.error.remove({ignoreUpstream:!0},a);o.push(...T),f.push(...b)}if(this.successCalls.forEach(T=>{o.push(T),T.removeCaller(this,a)}),this.errorCalls.forEach(T=>{o.push(T),T.removeCaller(this,a)}),!i){const T=this.removeFromParent(a);e.push(...T.added),o.push(...T.updated),f.push(...T.removed),y.push(...T.affected),this.calledBy.forEach(b=>{o.push(b),b.removeCall(this,a)})}return a==null||a.attemptAutoclose("remove-entity",this.id),{added:w(e),updated:w(o),removed:w(f),affected:w(y),self:this}}restore({}={},i=this.project.addChangeSet(new k(this.project,N.sessionAuthor,L().toISOString(),this,!0,"restore-entity"))){const a=[],o=[],f=[],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:T,added:b}=y.entity.onDetachedDependencyRestored(this,y.field,i);o.push(...v),f.push(...T),a.push(...b)}),this.process){const{updated:y}=this.process.restore({},i);o.push(...y)}return 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.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:w(a),updated:w(o),removed:w(f),affected:w(e),self:this}}toFlat(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this,...this.successCalls.flatMap(o=>o.toFlat(i)),...this.errorCalls.flatMap(o=>o.toFlat(i)),...this.inputs.flatMap(o=>o.toFlat(i)),...this.outputs.flatMap(o=>o.toFlat(i)),...this.calledBy.flatMap(o=>o.toFlat(i)),...this.process?this.process.toFlat(i):[],...this.error?this.error.toFlat(i):[],...this.parent.toFlat(i)])}toFlatIds(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.id,...this.successCalls.flatMap(o=>o.toFlatIds(i)),...this.errorCalls.flatMap(o=>o.toFlatIds(i)),...this.inputs.flatMap(o=>o.toFlatIds(i)),...this.outputs.flatMap(o=>o.toFlatIds(i)),...this.calledBy.flatMap(o=>o.toFlatIds(i)),...this.process?this.process.toFlatIds(i):[],...this.error?this.error.toFlatIds(i):[],...this.parent.toFlatIds(i)])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,catchesError:this.catchesError,author:this.author,deleted:this.deleted,index:this.index,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,catchesError:this.catchesError,type:this.type,index:this.index,successCalls:this.successCalls.map(f=>f.toJSON(i)),errorCalls:this.errorCalls.map(f=>f.toJSON(i)),calledBySuccess:this.calledBySuccess.map(f=>f.toReference()),calledByError:this.calledByError.map(f=>f.toReference()),calledByEntry:this.calledByEntry.map(f=>f.toReference()),process:(a=this.process)==null?void 0:a.toJSON(i),declaration:this.declaration.toJSON(i),inputs:this.inputs.map(f=>f.toJSON(i)),outputs:this.outputs.map(f=>f.toJSON(i)),parent:this.parent.toReference(),error:(o=this.error)==null?void 0:o.toJSON(i)})}toJSONClone(i=Je){var o,f,e,y,v,T,b;let a;return(o=i.seenEntityMaps)!=null&&o.has(this.id)?a=i.seenEntityMaps.get(this.id):(a=i.newId||Xi(this,this.project,i.uuidStrategy),i.seenEntityMaps&&i.seenEntityMaps.set(this.id,a)),(f=i.seenEntities)!=null&&f.has(a)||(e=i.seenEntities)!=null&&e.has(this.id)?this.toReference({seenEntityMaps:i.seenEntityMaps}):((y=i.seenEntities)==null||y.add(a),(v=i.seenEntities)==null||v.add(this.id),{id:a,version:N.UUID.uuid(),createdAt:i.timestamp||L().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,catchesError:this.catchesError,type:this.type,index:this.index,successCalls:this.successCalls.map(I=>I.toJSONClone({...i,newId:null})),errorCalls:this.errorCalls.map(I=>I.toJSONClone({...i,newId:null})),calledBySuccess:this.calledBySuccess.map(I=>I.toReference({seenEntityMaps:i.seenEntityMaps})),calledByError:this.calledByError.map(I=>I.toReference({seenEntityMaps:i.seenEntityMaps})),calledByEntry:this.calledByEntry.map(I=>I.toReference({seenEntityMaps:i.seenEntityMaps})),process:(T=this.process)==null?void 0:T.toJSONClone({...i,newId:null}),declaration:this.project.getBuiltIn(this.declaration.id)?this.declaration.toJSON():this.declaration.toJSONClone({...i,newId:null}),inputs:this.inputs.map(I=>I.toJSONClone({...i,newId:null})),outputs:this.outputs.map(I=>I.toJSONClone({...i,newId:null})),error:(b=this.error)==null?void 0:b.toJSONClone({...i,newId:null}),parent:this.parent.calledBy.length||this.parent.readsValue?this.parent.toReference({seenEntityMaps:i.seenEntityMaps}):this.parent.toJSONClone({...i,newId:null})})}toReference(i=Je){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:p.GenericReference,entityId:a,version:this.version,entityType:this.type}}toShallowJSON(i=Je){var o;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,catchesError:this.catchesError,type:this.type,index:this.index,process:this.process?this.process.toReference(i):null,inputs:this.inputs.map(f=>f.toReference(i)),outputs:this.outputs.map(f=>f.toReference(i)),declaration:this.declaration.toReference(i),successCalls:this.successCalls.map(f=>f.toReference(i)),errorCalls:this.errorCalls.map(f=>f.toReference(i)),calledBySuccess:this.calledBySuccess.map(f=>f.toReference(i)),calledByError:this.calledByError.map(f=>f.toReference(i)),calledByEntry:this.calledByEntry.map(f=>f.toReference(i)),error:this.error?this.error.toReference(i):null,parent:this.parent.toReference(i)}}toFlatJSON(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.toShallowJSON(),...this.process?this.process.toFlatJSON(i):[],...this.successCalls.flatMap(o=>o.toFlatJSON(i)),...this.errorCalls.flatMap(o=>o.toFlatJSON(i)),...this.inputs.flatMap(o=>o.toFlatJSON(i)),...this.outputs.flatMap(o=>o.toFlatJSON(i)),...this.calledBy.flatMap(o=>o.toFlatJSON(i)),...this.error?this.error.toFlatJSON(i):[],...this.parent.toFlatJSON(i)])}toGenerationTarget(){return{id:this.id,type:this.type,calledByEntry:this.calledByEntry.map(i=>i.id),calledBySuccess:this.calledBySuccess.map(i=>i.id),calledByError:this.calledByError.map(i=>i.id),declaration:this.declaration.id,parent:this.parent.id}}toFlatGenerationTarget(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.toGenerationTarget(),...this.process?this.process.toFlatGenerationTarget(i):[],...this.successCalls.flatMap(o=>o.toFlatGenerationTarget(i)),...this.errorCalls.flatMap(o=>o.toFlatGenerationTarget(i)),...this.inputs.flatMap(o=>o.toFlatGenerationTarget(i)),...this.outputs.flatMap(o=>o.toFlatGenerationTarget(i)),...this.error?this.error.toFlatGenerationTarget(i):[],...this.parent.toFlatGenerationTarget(i)])}clearErrors(){var i,a;return this.errors=[],this.inputs.forEach(o=>o.clearErrors()),this.outputs.forEach(o=>o.clearErrors()),this.successCalls.forEach(o=>o.clearErrors()),this.errorCalls.forEach(o=>o.clearErrors()),(i=this.process)==null||i.clearErrors(),(a=this.error)==null||a.clearErrors(),this}validate(){const i=uZ(this);return this.errors=i,{success:!0}}getErrors(){return[...this.errors,...this.inputs.flatMap(a=>a.getErrors()),...this.outputs.flatMap(a=>a.getErrors()),...this.error?this.error.getErrors():[],...this.process?this.process.getErrors():[]]}getShallowErrors(){return this.errors}clone(i=this.project.addChangeSet(new k(this.project,N.sessionAuthor,L().toISOString(),this,!0,"clone-entity")),a=null,o=null,f=!0){var x,U;let e=Wi(a,this);const y=this.toJSON(),v=o||N.UUID.uuid();y.inputs=[];const T=v.split("-id"),b=T[T.length-1||0]||v;y.id=v,y.version=N.UUID.uuid();const I=Ti(y,e);a?I.setParent(a,null):I.setParent(this.parent,null),f&&I.subscribe(),I.initChildren(i),i==null||i.add(I,F.Added);const O=(x=this.inputs)==null?void 0:x.map((S,q)=>S.clone(i,I,b+"-input-map-"+q+"-id",f));I.inputs=O;const V=(U=this.outputs)==null?void 0:U.map((S,q)=>S.clone(i,I,b+"-output-map-"+q+"-id",f));return I.outputs=V,this.error&&(I.error=this.error.clone(i,I,b+"-error-map-id",f)),this.process&&(I.process=this.process.clone(i,I,b+"-process-id",f)),i==null||i.attemptAutoclose("clone-entity",this.id),I}removeUnrecognizedInputs(i=this.project.addChangeSet(new k(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-unrecognized-inputs"))){const a=[],o=[],f=[],e=[];return this.inputs.forEach(v=>{if(!this.declaration.inputs.find(b=>{var I;return b.id===((I=v.declaration)==null?void 0:I.id)})){const b=v.remove({ignoreUpstream:!1},i);f.push(...b.removed),a.push(...b.updated)}}),this.inputs.filter((v,T)=>{const b=this.inputs.findIndex(O=>O.declaration===v.declaration&&O!==v);if(b===-1)return!1;const I=this.inputs[b];return L(I==null?void 0:I.createdAt).isSame(L(v.createdAt))?T>b:!!L(I==null?void 0:I.createdAt).isAfter(v.createdAt)}).forEach(v=>{const T=v.remove({ignoreUpstream:!1},i);f.push(...T.removed),a.push(...T.updated)}),i==null||i.attemptAutoclose("remove-unrecognized-inputs",this.id),{updated:w(a),added:w(o),removed:w(f),affected:w(e),self:this}}removeUnrecognizedOutputs(i=this.project.addChangeSet(new k(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-unrecognized-outputs"))){const a=[],o=[],f=[],e=[];return this.outputs.forEach(v=>{if(!this.declaration.getUniqueReturnDeclarations().find(b=>{var I;return b.id===((I=v.declaration)==null?void 0:I.id)})){const b=v.remove({ignoreUpstream:!1},i);f.push(...b.removed),a.push(...b.updated)}}),this.outputs.filter((v,T)=>{const b=this.outputs.findIndex(O=>O.declaration===v.declaration&&O!==v);if(b===-1)return!1;const I=this.outputs[b];return L(I==null?void 0:I.createdAt).isSame(L(v.createdAt))?T>b:!!L(I==null?void 0:I.createdAt).isAfter(v.createdAt)}).forEach(v=>{const T=v.remove({ignoreUpstream:!1},i);f.push(...T.removed),a.push(...T.updated)}),i==null||i.attemptAutoclose("remove-unrecognized-outputs",this.id),{updated:w(a),added:w(o),removed:w(f),affected:w(e),self:this}}syncInputs(i=this.project.addChangeSet(new k(this.project,N.sessionAuthor,L().toISOString(),this,!0,"sync-missing-fixed-inputs"))){const a=[],o=[],f=[],e=[],y=this.declaration.inputs.filter(I=>!this.inputs.find(O=>O.declaration.id===I.id));this.inputs.sort((I,O)=>I.index-O.index),y.forEach(I=>{this.inputs.forEach(x=>{x.index>=I.index&&x.metaSync({index:x.index+1},i)});const O={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:p.InputMap,declaration:I.toJSON(),readsValue:null,defaultValue:null,index:I.index,name:null,codeName:null,description:null,parent:this.toReference()},V=oe(O,this.project);V.setParent(this,i),V.initChildren(i),i==null||i.add(V,F.Added),V.addSelfToProject(i),o.push(V)}),this.inputs.sort((I,O)=>I.index-O.index);const{updated:v,added:T,removed:b}=this.removeUnrecognizedInputs(i);return a.push(...v),o.push(...T),f.push(...b),i==null||i.attemptAutoclose("sync-missing-fixed-inputs",this.id),{updated:w(a),added:w(o),removed:w(f),affected:w(e),self:this}}syncOutputs(i=this.project.addChangeSet(new k(this.project,N.sessionAuthor,L().toISOString(),this,!0,"sync-missing-fixed-outputs"))){const a=[],o=[],f=[],e=[],y=[];this.outputs=this.initialData.outputs.map(O=>{const V=oe(O,this.project);return y.push(V.index),V.setParent(this,i),V.initChildren(i),V});const v=this.declaration.getUniqueReturnDeclarations().filter(O=>!this.outputs.find(V=>{var x;return((x=V.declaration)==null?void 0:x.id)===O.id}));this.outputs.sort((O,V)=>O.index-V.index),v.forEach((O,V)=>{this.outputs.forEach(q=>{q.index>=O.index&&q.index++});const x=y.includes(O.index)?this.outputs.length-1+V:O.index,U={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:p.OutputMap,declaration:O.toJSON(),defaultValue:null,writesValues:[],index:x,parent:this.toReference()},S=oe(U,this.project);S.setParent(this,i),S.initChildren(i),i==null||i.add(S,F.Added),S.addSelfToProject(i)}),this.outputs.sort((O,V)=>O.index-V.index);const{updated:T,added:b,removed:I}=this.removeUnrecognizedOutputs(i);return a.push(...T),o.push(...b),f.push(...I),i==null||i.attemptAutoclose("sync-missing-fixed-outputs",this.id),{updated:w(a),added:w(o),removed:w(f),affected:w(e),self:this}}getUnusedInputs(){return this.inputs.filter(i=>i.suggestion||!i.readsValue&&!i.defaultValue)}getUnusedOutputs(){return this.outputs.filter(i=>i.suggestion||!i.writesValues.length)}getUsedInputs(){return this.inputs.filter(i=>!i.suggestion&&(i.readsValue||i.defaultValue))}getUsedOutputs(){return this.outputs.filter(i=>!i.suggestion&&i.writesValues.length)}};_(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}),_(zt,"type",p.InternalCall),_(zt,"USER_MANAGED_PARENT_TYPES",[...Rt]),_(zt,"PARENT_TYPES",[...zt.USER_MANAGED_PARENT_TYPES]),_(zt,"MUTABLE_BASE_PROPERTIES",["catchesError"]),_(zt,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),_(zt,"BASE_PROPERTIES",[...zt.MUTABLE_BASE_PROPERTIES,...zt.INMUTABLE_BASE_PROPERTIES]),_(zt,"MUTABLE_META_PROPERTIES",[...zt.MUTABLE_BASE_PROPERTIES,"index"]),_(zt,"INMUTABLE_META_PROPERTIES",[...zt.INMUTABLE_BASE_PROPERTIES]),_(zt,"META_PROPERTIES",[...zt.MUTABLE_META_PROPERTIES,...zt.INMUTABLE_META_PROPERTIES]),_(zt,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry"]),_(zt,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","declaration"]),_(zt,"UPSTREAM_PROPERTIES",[...zt.MUTABLE_UPSTREAM_PROPERTIES,...zt.INMUTABLE_UPSTREAM_PROPERTIES]),_(zt,"MUTABLE_DOWNSTREAM_PROPERTIES",["inputs","outputs","writesValues","successCalls","errorCalls","error"]),_(zt,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),_(zt,"DOWNSTREAM_PROPERTIES",[...zt.MUTABLE_DOWNSTREAM_PROPERTIES,...zt.INMUTABLE_DOWNSTREAM_PROPERTIES]),_(zt,"PROPERTIES",[...zt.META_PROPERTIES,...zt.UPSTREAM_PROPERTIES,...zt.DOWNSTREAM_PROPERTIES]);let ko=zt;function gZ(d){const u=[...Jo(d)];return _i(d.errors,u)}const O_e=Object.freeze(Object.defineProperty({__proto__:null,validate:gZ},Symbol.toStringTag,{value:"Module"}));function zr(d){return d.declaration||d}function P_e(d){return d.type===p.VariableDeclaration?d.parent===d.project?"global-declaration":"local-declaration":d.declaration.parent===d.project?"global-instance":"local-instance"}function yA(d,u){const i=[];if(d.type===p.Project)i.push(...d.variableDeclarations);else{const o=Wa(ct(d)).filter(f=>f.type===p.VariableDeclaration);i.push(...o),d.parent&&(Ki.includes(d.parent.type)||d.parent.type===p.Project)&&i.push(...yA(d.parent))}return i}function $_e(d){if(d.declaration&&d.declaration.type===p.Property){if(d.declaration.interactive){if(d.declaration.implements&&!d.declaration.implements.interactive)return!1;if(d.declaration.extends&&!d.declaration.extends.interactive)return!1}else return!1;if(d.declaration.private){const u=Ai(d),i=Pu(u,d.project);if((i==null?void 0:i.type)===p.FunctionDeclaration&&(i==null?void 0:i.parent.type)===p.DefinitionEntity&&(i==null?void 0:i.parent.id)!==d.declaration.parent.id)return!1}}return!0}var IZ=(d=>(d.Declaration="declaration",d.DataTypeEntity="data-type-entity",d))(IZ||{});const Wt=class Wt extends ki{constructor(i,a){super(i);_(this,"initialData");_(this,"id");_(this,"index");_(this,"name",null);_(this,"codeName",null);_(this,"description",null);_(this,"type",p.InputMap);_(this,"defaultValue",null);_(this,"readsValue",null);_(this,"dataType",null);_(this,"declaration",null);_(this,"project");_(this,"errors",[]);_(this,"parent");_(this,"detachedDependents",{});_(this,"knownVersions",null);_(this,"activeVersion",!1);_(this,"initialized",!1);_(this,"startedInitialization",!1);_(this,"suggestion",!1);_(this,"_codeNativeValueValidation",null);this.initialData=i,this.project=a,this.id=i.id,this.index=i.index,this.name=i.name||null,this.codeName=i.codeName||null,this.description=i.description||null}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:p.InputMap,name:"",codeName:null,description:"",declaration:null,index:0,readsValue:null,defaultValue:null,parent:null}}static fromGenerationTarget(i,a){const o=z(i.parent),f=a.get(o);let e=null;if(i.declaration){const b=z(i.declaration);e=a.get(b)}let y=null;if(i.readsValue){const b=z(i.readsValue);y=a.get(b)}const v={id:i.id,version:N.UUID.uuid(),createdAt:L().toISOString(),author:N.sessionAuthor,previousVersion:null,deleted:!1,name:i.name||null,type:p.InputMap,index:(f.inputs||[]).length,codeName:i.codeName||null,description:i.description||null,declaration:e,readsValue:y,defaultValue:null,parent:f},T=oe(v,a);return T.setParent(f,null),T}static validateGenerationTarget(i,a){var b;let o=JSON.parse(JSON.stringify(i));const f=[],e=mr(o,{parent:{list:!1,types:[...ci,p.InputMap]}},a);o=e.modifiedData;const y=a.get(o.parent),v=o.declaration&&(a.get(o.declaration)||a.getBuiltIn(o.declaration)),T=((y==null?void 0:y.inputs)||[]).find(I=>{var O;return o.declaration&&((O=I.declaration)==null?void 0:O.id)===o.declaration});if(o.declaration?v?[p.Property,p.ArgumentDeclaration,p.ValueDescriptor].includes(v.type)?y&&v.type===p.ArgumentDeclaration&&![p.FunctionCall,p.Search,p.InternalCall].includes(y.type)?f.push(new le({id:`${o.id}--${K.InvalidInputMapDeclaration}`,code:K.InvalidInputMapDeclaration,severity:H.Error,message:`Entity of type '${p.InputMap}' with id '${o.id}' has a 'declaration' property pointing to an entity with type '${p.ArgumentDeclaration}' with id '${o.declaration}'.
150
+ This is likely an incorrect strategy, either the '${this.type}' entity doesn't need to be updated or it should be deleted and a new one created in the desired parent.`})),{errors:a,modifiedData:i}}subscribeDependents(i){return i.forEach(a=>{this.detachedDependents[a.entity.id]||(this.detachedDependents[a.entity.id]=a)}),this}unsubscribeDependents(i){return i.forEach(a=>{this.detachedDependents[a.entity.id]&&delete this.detachedDependents[a.entity.id]}),this}syncDependents(i=this.project.addChangeSet(new k(this.project,N.sessionAuthor,L().toISOString(),this,!0,"sync-dependents"))){const a=[],o=[],f=[],e=[];return Object.values(this.detachedDependents).forEach(y=>{const v=y.entity.afterAllChildrenInitialized(i);a.push(...v.updated),o.push(...v.added),f.push(...v.removed),e.push(...v.affected)}),i==null||i.attemptAutoclose("sync-dependents",this.id),{updated:w(a),added:w(o),removed:w(f),affected:w(e),self:this}}onDetachedDependencyRemoved(i,a,o){const f=[],e=[],y=[],v=[];if(a==="declaration"){const{updated:T,added:b,removed:I}=this.remove({ignoreUpstream:!1},o);f.push(...T),e.push(...b),y.push(...I)}return{updated:w(f),added:w(e),removed:w(y),affected:w(v),self:this}}onDetachedDependencyRestored(i,a,o){const f=[],e=[],y=[],v=[];if(a==="declaration"){const{updated:T,added:b,removed:I}=this.restore({},o);f.push(...T),e.push(...b),y.push(...I)}return{updated:w(f),added:w(e),removed:w(y),affected:w(v),self:this}}unsubscribeFromDependencies(){return this.declaration.unsubscribeDependents([{entity:this,field:"declaration"}]),this}subscribeToDependencies(){return this.declaration.subscribeDependents([{entity:this,field:"declaration"}]),this}increaseVersion(i){if(i&&!L(i).isValid())throw new Error(`The shared timestamp '${i}' is not a valid ISO 8601 date string.`);return i&&L(i).isSame(L(this.createdAt))?this:(this.previousVersion=this.version,this.version=N.UUID.uuid(),this.createdAt=L(i).toISOString()||L().toISOString(),this)}captureVersion(){var a;const i=((a=this.knownVersions)==null?void 0:a.get(this.version))||new 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.outputs=[...this.outputs],i.error=this.error,i.process=this.process,i.successCalls=[...this.successCalls],i.errorCalls=[...this.errorCalls],i.calledBySuccess=[...this.calledBySuccess],i.calledByError=[...this.calledByError],i.calledByEntry=[...this.calledByEntry],i.declaration=this.declaration,i.parent=this.parent,this}recursiveCaptureUpstreamVersions(i){const a=[],o=[],f=[],e=[];if(this.parent){this.parent.increaseVersion(i);const y=this.parent.recursiveCaptureUpstreamVersions(i);a.push(this.parent,...y.updated),o.push(...y.added),f.push(...y.removed)}return{updated:w(a),added:w(o),removed:w(f),affected:w(e),self:this}}async restoreVersion(i){var v;const a=[],o=[],f=[],e=[];if(this.version===i)return{updated:w(a),added:w(o),removed:w(f),affected:w(e),self:this};if(!this.knownVersions){const T=new Map;for(const[b,I]of this.knownVersions||new Map){if(T.set(b,I),I.activeVersion=!1,I.knownVersions)for(const[O,V]of I.knownVersions)T.set(O,V);I.knownVersions=null}}let y=(v=this.knownVersions)==null?void 0:v.get(i);if(!y){const T=await this.APILoadVersion({},i);if(!T)throw new Error(`Version with id '${i}' for entity with id '${this.id}' not found.`);y=new zt(T,this.project)}return this.metaSync(y.toShallowJSON(),null),this.previousVersion=y.previousVersion,this.version=y.version,this.createdAt=y.createdAt,this.author=y.author,this.deleted=y.deleted,this.inputs=y.inputs,this.outputs=y.outputs,this.error=y.error,this.process=y.process,this.successCalls=y.successCalls,this.errorCalls=y.errorCalls,this.calledBySuccess=y.calledBySuccess,this.calledByError=y.calledByError,this.calledByEntry=y.calledByEntry,this.declaration=y.declaration,this.parent=y.parent,{updated:w(a),added:w(o),removed:w(f),affected:w(e),self:this}}updateWithShallowTransfer(i,a=this.project.addChangeSet(new k(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=z(i.parent),f=this.project.get(o),e=this.parent;if(e&&e.id!==(f==null?void 0:f.id)&&this.removeFromParent(a),f)this.setParent(f,a);else throw a==null||a.attemptAutoclose("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=z(i.declaration),f=this.project.get(o);f&&this.setDeclaration(f)}return i.calledByEntry.forEach(o=>{const f=z(o),e=this.project.get(f);e&&(this.addEntryCaller(e,a),e.addCall(this,a))}),[...this.calledByEntry].forEach(o=>{i.calledByEntry.find(e=>z(e)===o.id)||(this.removeCaller(o,a),o.removeCall(this,a))}),i.calledBySuccess.forEach(o=>{const f=z(o),e=this.project.get(f);e&&(this.addSuccessCaller(e,a),e.addSuccessCall(this,a))}),[...this.calledBySuccess].forEach(o=>{i.calledBySuccess.find(e=>z(e)===o.id)||(this.removeCaller(o,a),o.removeCall(this,a))}),i.calledByError.forEach(o=>{const f=z(o),e=this.project.get(f);e&&(this.addErrorCaller(e,a),e.addErrorCall(this,a))}),[...this.calledBySuccess].forEach(o=>{i.calledBySuccess.find(e=>z(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=[],f=[];if(this.initialData.parent){const e=z(this.initialData.parent),y=this.project.get(e);if(y)this.setParent(y,null),i.push(y);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${e}' that isn't found in the project`)}else throw new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(this.initialData.declaration){const e=z(this.initialData.declaration),y=this.project.get(e);y&&(this.setDeclaration(y),i.push(y))}return this.initialData.calledByEntry.forEach(e=>{const y=z(e),v=this.project.get(y);v&&this.addEntryCaller(v,null)}),this.initialData.calledBySuccess.forEach(e=>{const y=z(e),v=this.project.get(y);v&&this.addSuccessCaller(v,null)}),this.initialData.calledByError.forEach(e=>{const y=z(e),v=this.project.get(y);v&&this.addErrorCaller(v,null)}),{updated:w(i),added:w(a),removed:w(o),affected:w(f),self:this}}afterAllChildrenInitialized(i=this.project.addChangeSet(new k(this.project,N.sessionAuthor,L().toISOString(),this,!0,"after-all-children-initialized"))){const a=[],o=[],f=[],e=[];this.initialized=!0;const{updated:y,added:v,removed:T}=this.syncInputs(i),{updated:b,added:I,removed:O}=this.syncOutputs(i);return a.push(...y,...b),o.push(...v,...I),f.push(...T,...O),this.captureVersion(),i==null||i.attemptAutoclose("after-all-children-initialized",this.id),{updated:w(a),added:w(o),removed:w(f),affected:w(e),self:this}}addSelfToProject(i=this.project.addChangeSet(new k(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-self-to-project"))){var y;const a=[this],o=[],f=[],e=[];return this.parent.addInternalCall(this),e.push(this.parent),(y=this.process)==null||y.writesValues.forEach(v=>{v.setValueWriter(this.process,i),a.push(v)}),this.successCalls.forEach(v=>{v.addSuccessCaller(this,i),a.push(v)}),this.errorCalls.forEach(v=>{v.addErrorCaller(this,i),a.push(v)}),this.calledBySuccess.forEach(v=>{v.addSuccessCall(this,i),a.push(v)}),this.calledByError.forEach(v=>{v.addErrorCall(this,i),a.push(v)}),this.calledByEntry.forEach(v=>{v.addCall(this,i),a.push(v)}),this.subscribe(),this.subscribeToDependencies(),i==null||i.attemptAutoclose("add-self-to-project",this.id),{updated:w(a),added:w(o),removed:w(f),affected:w(e),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}removeInput(i,a=this.project.addChangeSet(new k(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-input"))){const o=this.inputs.findIndex(f=>f.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 k(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 k(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 k(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-output"))){const o=this.outputs.findIndex(f=>f.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}addValueReader(i,a=this.project.addChangeSet(new k(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-value-reader"))){var o;return this.process&&!this.process.writesValues.includes(i)&&((o=this.process)==null||o.addValueReader(i,a),a==null||a.add(this,F.Affected)),a==null||a.attemptAutoclose("add-value-reader",this.id),this}removeValueReader(i,a=this.project.addChangeSet(new k(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-value-reader"))){var o;return this.process&&this.process.writesValues.includes(i)&&((o=this.process)==null||o.removeValueReader(i,a),a==null||a.add(this,F.Affected)),a==null||a.attemptAutoclose("remove-value-reader",this.id),this}addSuccessCaller(i,a=this.project.addChangeSet(new k(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-success-caller")),o=!1){return this.calledBySuccess.find(f=>f.id===i.id)||(this.calledBySuccess.push(i),a==null||a.add(this,F.Updated),o&&et(this,a)),a==null||a.attemptAutoclose("add-success-caller",this.id),this}addErrorCaller(i,a=this.project.addChangeSet(new k(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-error-caller")),o=!1){return this.calledByError.find(f=>f.id===i.id)||(this.calledByError.push(i),a==null||a.add(this,F.Updated),o&&et(this,a)),a==null||a.attemptAutoclose("add-error-caller",this.id),this}addEntryCaller(i,a=this.project.addChangeSet(new k(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-entry-caller")),o=!1){return this.calledByEntry.find(f=>f.id===i.id)||(this.calledByEntry.push(i),a==null||a.add(this,F.Updated),o&&et(this,a)),a==null||a.attemptAutoclose("add-entry-caller",this.id),this}addErrorCall(i,a=this.project.addChangeSet(new k(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-error-call")),o=!1){return this.errorCalls.find(f=>f.id===i.id)||(this.errorCalls.push(i),o&&et(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 k(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-success-call")),o=!1){return this.successCalls.find(f=>f.id===i.id)||(this.successCalls.push(i),o&&et(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 k(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-call")),o=!1){const f=this.successCalls.findIndex(y=>y.id===i.id);f>-1&&(this.successCalls.splice(f,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&&et(this,a),a==null||a.attemptAutoclose("remove-call",this.id),this}removeCaller(i,a=this.project.addChangeSet(new k(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-caller")),o=!1){return this.calledBySuccess=this.calledBySuccess.filter(f=>f.id!==i.id?!0:(a==null||a.add(this,F.Updated),a==null||a.add(f,F.Affected),!1)),this.calledByError=this.calledByError.filter(f=>f.id!==i.id?!0:(a==null||a.add(this,F.Updated),a==null||a.add(f,F.Affected),!1)),this.calledByEntry=this.calledByEntry.filter(f=>f.id!==i.id?!0:(a==null||a.add(this,F.Updated),a==null||a.add(f,F.Affected),!1)),o&&et(this,a),a==null||a.attemptAutoclose("remove-caller",this.id),this}setParent(i,a=this.project.addChangeSet(new k(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}setDeclaration(i){return this.declaration=i,this}initChildren(i=this.project.addChangeSet(new k(this.project,N.sessionAuthor,L().toISOString(),this,!0,"init-children"))){if(this.initialized||this.startedInitialization)return this;if(this.startedInitialization=!0,this.initialData.parent.type!==p.GenericReference){const a=oe(this.initialData.parent,this.project);this.setParent(a,null),this.parent.initChildren(i),this.parent.addInternalCall(this);const o=this.calledBy.find(f=>!!f.parent&&Ki.includes(f.parent.type));if(o){const f=oe(o.parent,this.project);this.parent.setParent(f,null)}else if(!o&&!this.parent.calledBy.length)throw new Error("Parent of internal call parent could not be resolved")}return this.declaration=oe(this.initialData.declaration,this.project),this.successCalls=this.initialData.successCalls.map(a=>{const o=oe(a,this.project);if(o.addSuccessCaller(this),[p.BreakStatement,p.ContinueStatement].includes(o.type))o.setParent(this.parent.parent,null),o.initChildren(i);else if(o.type===p.ReturnStatement){const f=lr(this.parent,this.project);o.setParent(f,null),o.initChildren(i)}else o.type!==p.InternalCall&&(o.setParent(this.parent.parent,null),o.initChildren(i));return o}),this.errorCalls=this.initialData.errorCalls.map(a=>{const o=oe(a,this.project);if(o.addErrorCaller(this),[p.BreakStatement,p.ContinueStatement].includes(o.type))o.setParent(this.parent.parent.parent,null),o.initChildren(i);else if(o.type===p.ReturnStatement){const f=lr(this.parent,this.project);o.setParent(f,null),o.initChildren(i)}else o.type!==p.InternalCall&&(o.setParent(this.parent.parent,null),o.initChildren(i));return o}),this.inputs=this.initialData.inputs.map(a=>{const o=oe(a,this.project);return o.setParent(this,null),o.initChildren(i),o}),this.outputs=this.initialData.outputs.map(a=>{const o=oe(a,this.project);return o.setParent(this,null),o.initChildren(i),o}),this.initialData.error&&(this.error=oe(this.initialData.error,this.project),this.error.setParent(this,null),this.error.initChildren(i)),this.initialData.process&&(this.process=oe(this.initialData.process,this.project),this.process.setParent(this,null),this.process.initChildren(i)),this.subscribeToDependencies(),this.afterAllChildrenInitialized(i),i==null||i.attemptAutoclose("init-children",this.id),this}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(i,a=this.project.addChangeSet(new k(this.project,N.sessionAuthor,L().toISOString(),this,!0,"meta-sync"))){const o=Hi(this,i),f=this.toMeta();return this.index=i.index||(i.index!==0?f.index:0),this.catchesError=i.catchesError!==void 0?i.catchesError:this.catchesError,super.metaSync(i),i.deleted===!0&&!f.deleted?a==null||a.add(this,F.Removed):i.deleted===!1&&f.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=Ee,...a){return await zt.repository.APILoad(this.id,...a),this}async APICreate(i=Ee,...a){return await zt.repository.APICreate(this.toShallowJSON(),...a),this}async APIUpdate(i=Ee,...a){return await zt.repository.APIUpdate(this.toShallowJSON(),...a),this}async APIDelete(i=Ee,...a){return await zt.repository.APIDelete(this.toShallowJSON(),...a),this}async APIClone(i=Ee,...a){return await zt.repository.APIClone(this.id,...a),this}async APILoadVersion(i=Ee,a,...o){return await zt.repository.APILoadVersion(this.id,a,...o)}removeFromParent(i=this.project.addChangeSet(new k(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-from-parent"))){const a=[],o=[],f=[],e=[];return this.parent&&(this.parent.removeInternalCall(this,i),e.push(this.parent)),i==null||i.attemptAutoclose("remove-from-parent",this.id),{added:w(f),updated:w(a),removed:w(o),affected:w(e),self:this}}remove({ignoreUpstream:i}={ignoreUpstream:!1},a=this.project.addChangeSet(new k(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-entity"))){var v;const o=[],f=[],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(f.push(this),this.unsubscribe(),this.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},a),Object.values(this.detachedDependents).forEach(T=>{const{updated:b,removed:I,added:O}=T.entity.onDetachedDependencyRemoved(this,T.field,a);o.push(...b),f.push(...I),e.push(...O)}),this.process){const{updated:T,removed:b}=(v=this.process)==null?void 0:v.remove({ignoreUpstream:!0},a);o.push(...T),f.push(...b)}if(this.inputs.forEach(T=>{const{updated:b,removed:I}=T.remove({ignoreUpstream:!0},a);o.push(...b),f.push(...I)}),this.outputs.forEach(T=>{const{updated:b,removed:I}=T.remove({ignoreUpstream:!0},a);o.push(...b),f.push(...I)}),this.error){const{updated:T,removed:b}=this.error.remove({ignoreUpstream:!0},a);o.push(...T),f.push(...b)}if(this.successCalls.forEach(T=>{o.push(T),T.removeCaller(this,a)}),this.errorCalls.forEach(T=>{o.push(T),T.removeCaller(this,a)}),!i){const T=this.removeFromParent(a);e.push(...T.added),o.push(...T.updated),f.push(...T.removed),y.push(...T.affected),this.calledBy.forEach(b=>{o.push(b),b.removeCall(this,a)})}return a==null||a.attemptAutoclose("remove-entity",this.id),{added:w(e),updated:w(o),removed:w(f),affected:w(y),self:this}}restore({}={},i=this.project.addChangeSet(new k(this.project,N.sessionAuthor,L().toISOString(),this,!0,"restore-entity"))){const a=[],o=[],f=[],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:T,added:b}=y.entity.onDetachedDependencyRestored(this,y.field,i);o.push(...v),f.push(...T),a.push(...b)}),this.process){const{updated:y}=this.process.restore({},i);o.push(...y)}return 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.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:w(a),updated:w(o),removed:w(f),affected:w(e),self:this}}toFlat(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this,...this.successCalls.flatMap(o=>o.toFlat(i)),...this.errorCalls.flatMap(o=>o.toFlat(i)),...this.inputs.flatMap(o=>o.toFlat(i)),...this.outputs.flatMap(o=>o.toFlat(i)),...this.calledBy.flatMap(o=>o.toFlat(i)),...this.process?this.process.toFlat(i):[],...this.error?this.error.toFlat(i):[],...this.parent.toFlat(i)])}toFlatIds(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.id,...this.successCalls.flatMap(o=>o.toFlatIds(i)),...this.errorCalls.flatMap(o=>o.toFlatIds(i)),...this.inputs.flatMap(o=>o.toFlatIds(i)),...this.outputs.flatMap(o=>o.toFlatIds(i)),...this.calledBy.flatMap(o=>o.toFlatIds(i)),...this.process?this.process.toFlatIds(i):[],...this.error?this.error.toFlatIds(i):[],...this.parent.toFlatIds(i)])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,catchesError:this.catchesError,author:this.author,deleted:this.deleted,index:this.index,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,catchesError:this.catchesError,type:this.type,index:this.index,successCalls:this.successCalls.map(f=>f.toJSON(i)),errorCalls:this.errorCalls.map(f=>f.toJSON(i)),calledBySuccess:this.calledBySuccess.map(f=>f.toReference()),calledByError:this.calledByError.map(f=>f.toReference()),calledByEntry:this.calledByEntry.map(f=>f.toReference()),process:(a=this.process)==null?void 0:a.toJSON(i),declaration:this.declaration.toJSON(i),inputs:this.inputs.map(f=>f.toJSON(i)),outputs:this.outputs.map(f=>f.toJSON(i)),parent:this.parent.toReference(),error:(o=this.error)==null?void 0:o.toJSON(i)})}toJSONClone(i=Je){var o,f,e,y,v,T,b;let a;return(o=i.seenEntityMaps)!=null&&o.has(this.id)?a=i.seenEntityMaps.get(this.id):(a=i.newId||Xi(this,this.project,i.uuidStrategy),i.seenEntityMaps&&i.seenEntityMaps.set(this.id,a)),(f=i.seenEntities)!=null&&f.has(a)||(e=i.seenEntities)!=null&&e.has(this.id)?this.toReference({seenEntityMaps:i.seenEntityMaps}):((y=i.seenEntities)==null||y.add(a),(v=i.seenEntities)==null||v.add(this.id),{id:a,version:N.UUID.uuid(),createdAt:i.timestamp||L().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,catchesError:this.catchesError,type:this.type,index:this.index,successCalls:this.successCalls.map(I=>I.toJSONClone({...i,newId:null})),errorCalls:this.errorCalls.map(I=>I.toJSONClone({...i,newId:null})),calledBySuccess:this.calledBySuccess.map(I=>I.toReference({seenEntityMaps:i.seenEntityMaps})),calledByError:this.calledByError.map(I=>I.toReference({seenEntityMaps:i.seenEntityMaps})),calledByEntry:this.calledByEntry.map(I=>I.toReference({seenEntityMaps:i.seenEntityMaps})),process:(T=this.process)==null?void 0:T.toJSONClone({...i,newId:null}),declaration:this.project.getBuiltIn(this.declaration.id)?this.declaration.toJSON():this.declaration.toJSONClone({...i,newId:null}),inputs:this.inputs.map(I=>I.toJSONClone({...i,newId:null})),outputs:this.outputs.map(I=>I.toJSONClone({...i,newId:null})),error:(b=this.error)==null?void 0:b.toJSONClone({...i,newId:null}),parent:this.parent.calledBy.length||this.parent.readsValue?this.parent.toReference({seenEntityMaps:i.seenEntityMaps}):this.parent.toJSONClone({...i,newId:null})})}toReference(i=Je){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:p.GenericReference,entityId:a,version:this.version,entityType:this.type}}toShallowJSON(i=Je){var o;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,catchesError:this.catchesError,type:this.type,index:this.index,process:this.process?this.process.toReference(i):null,inputs:this.inputs.map(f=>f.toReference(i)),outputs:this.outputs.map(f=>f.toReference(i)),declaration:this.declaration.toReference(i),successCalls:this.successCalls.map(f=>f.toReference(i)),errorCalls:this.errorCalls.map(f=>f.toReference(i)),calledBySuccess:this.calledBySuccess.map(f=>f.toReference(i)),calledByError:this.calledByError.map(f=>f.toReference(i)),calledByEntry:this.calledByEntry.map(f=>f.toReference(i)),error:this.error?this.error.toReference(i):null,parent:this.parent.toReference(i)}}toFlatJSON(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.toShallowJSON(),...this.process?this.process.toFlatJSON(i):[],...this.successCalls.flatMap(o=>o.toFlatJSON(i)),...this.errorCalls.flatMap(o=>o.toFlatJSON(i)),...this.inputs.flatMap(o=>o.toFlatJSON(i)),...this.outputs.flatMap(o=>o.toFlatJSON(i)),...this.calledBy.flatMap(o=>o.toFlatJSON(i)),...this.error?this.error.toFlatJSON(i):[],...this.parent.toFlatJSON(i)])}toGenerationTarget(){return{id:this.id,type:this.type,calledByEntry:this.calledByEntry.map(i=>i.id),calledBySuccess:this.calledBySuccess.map(i=>i.id),calledByError:this.calledByError.map(i=>i.id),declaration:this.declaration.id,parent:this.parent.id}}toFlatGenerationTarget(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.toGenerationTarget(),...this.process?this.process.toFlatGenerationTarget(i):[],...this.successCalls.flatMap(o=>o.toFlatGenerationTarget(i)),...this.errorCalls.flatMap(o=>o.toFlatGenerationTarget(i)),...this.inputs.flatMap(o=>o.toFlatGenerationTarget(i)),...this.outputs.flatMap(o=>o.toFlatGenerationTarget(i)),...this.error?this.error.toFlatGenerationTarget(i):[],...this.parent.toFlatGenerationTarget(i)])}clearErrors(){var i,a;return this.errors=[],this.inputs.forEach(o=>o.clearErrors()),this.outputs.forEach(o=>o.clearErrors()),this.successCalls.forEach(o=>o.clearErrors()),this.errorCalls.forEach(o=>o.clearErrors()),(i=this.process)==null||i.clearErrors(),(a=this.error)==null||a.clearErrors(),this}validate(){const i=uZ(this);return this.errors=i,{success:!0}}getErrors(){return[...this.errors,...this.inputs.flatMap(a=>a.getErrors()),...this.outputs.flatMap(a=>a.getErrors()),...this.error?this.error.getErrors():[],...this.process?this.process.getErrors():[]]}getShallowErrors(){return this.errors}clone(i=this.project.addChangeSet(new k(this.project,N.sessionAuthor,L().toISOString(),this,!0,"clone-entity")),a=null,o=null,f=!0){var x,U;let e=Wi(a,this);const y=this.toJSON(),v=o||N.UUID.uuid();y.inputs=[];const T=v.split("-id"),b=T[T.length-1||0]||v;y.id=v,y.version=N.UUID.uuid();const I=Ti(y,e);a?I.setParent(a,null):I.setParent(this.parent,null),f&&I.subscribe(),I.initChildren(i),i==null||i.add(I,F.Added);const O=(x=this.inputs)==null?void 0:x.map((S,q)=>S.clone(i,I,b+"-input-map-"+q+"-id",f));I.inputs=O;const V=(U=this.outputs)==null?void 0:U.map((S,q)=>S.clone(i,I,b+"-output-map-"+q+"-id",f));return I.outputs=V,this.error&&(I.error=this.error.clone(i,I,b+"-error-map-id",f)),this.process&&(I.process=this.process.clone(i,I,b+"-process-id",f)),i==null||i.attemptAutoclose("clone-entity",this.id),I}removeUnrecognizedInputs(i=this.project.addChangeSet(new k(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-unrecognized-inputs"))){const a=[],o=[],f=[],e=[];return this.inputs.forEach(v=>{if(!this.declaration.inputs.find(b=>{var I;return b.id===((I=v.declaration)==null?void 0:I.id)})){const b=v.remove({ignoreUpstream:!1},i);f.push(...b.removed),a.push(...b.updated)}}),this.inputs.filter((v,T)=>{const b=this.inputs.findIndex(O=>O.declaration===v.declaration&&O!==v);if(b===-1)return!1;const I=this.inputs[b];return L(I==null?void 0:I.createdAt).isSame(L(v.createdAt))?T>b:!!L(I==null?void 0:I.createdAt).isAfter(v.createdAt)}).forEach(v=>{const T=v.remove({ignoreUpstream:!1},i);f.push(...T.removed),a.push(...T.updated)}),i==null||i.attemptAutoclose("remove-unrecognized-inputs",this.id),{updated:w(a),added:w(o),removed:w(f),affected:w(e),self:this}}removeUnrecognizedOutputs(i=this.project.addChangeSet(new k(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-unrecognized-outputs"))){const a=[],o=[],f=[],e=[];return this.outputs.forEach(v=>{if(!this.declaration.getUniqueReturnDeclarations().find(b=>{var I;return b.id===((I=v.declaration)==null?void 0:I.id)})){const b=v.remove({ignoreUpstream:!1},i);f.push(...b.removed),a.push(...b.updated)}}),this.outputs.filter((v,T)=>{const b=this.outputs.findIndex(O=>O.declaration===v.declaration&&O!==v);if(b===-1)return!1;const I=this.outputs[b];return L(I==null?void 0:I.createdAt).isSame(L(v.createdAt))?T>b:!!L(I==null?void 0:I.createdAt).isAfter(v.createdAt)}).forEach(v=>{const T=v.remove({ignoreUpstream:!1},i);f.push(...T.removed),a.push(...T.updated)}),i==null||i.attemptAutoclose("remove-unrecognized-outputs",this.id),{updated:w(a),added:w(o),removed:w(f),affected:w(e),self:this}}syncInputs(i=this.project.addChangeSet(new k(this.project,N.sessionAuthor,L().toISOString(),this,!0,"sync-missing-fixed-inputs"))){const a=[],o=[],f=[],e=[],y=this.declaration.inputs.filter(I=>!this.inputs.find(O=>{var V;return((V=O.declaration)==null?void 0:V.id)===I.id}));this.inputs.sort((I,O)=>I.index-O.index),y.forEach(I=>{this.inputs.forEach(x=>{x.index>=I.index&&x.metaSync({index:x.index+1},i)});const O={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:p.InputMap,declaration:I.toJSON(),readsValue:null,defaultValue:null,index:I.index,name:null,codeName:null,description:null,parent:this.toReference()},V=oe(O,this.project);V.setParent(this,i),V.initChildren(i),i==null||i.add(V,F.Added),V.addSelfToProject(i),o.push(V)}),this.inputs.sort((I,O)=>I.index-O.index);const{updated:v,added:T,removed:b}=this.removeUnrecognizedInputs(i);return a.push(...v),o.push(...T),f.push(...b),i==null||i.attemptAutoclose("sync-missing-fixed-inputs",this.id),{updated:w(a),added:w(o),removed:w(f),affected:w(e),self:this}}syncOutputs(i=this.project.addChangeSet(new k(this.project,N.sessionAuthor,L().toISOString(),this,!0,"sync-missing-fixed-outputs"))){const a=[],o=[],f=[],e=[],y=[];this.outputs=this.initialData.outputs.map(O=>{const V=oe(O,this.project);return y.push(V.index),V.setParent(this,i),V.initChildren(i),V});const v=this.declaration.getUniqueReturnDeclarations().filter(O=>!this.outputs.find(V=>{var x;return((x=V.declaration)==null?void 0:x.id)===O.id}));this.outputs.sort((O,V)=>O.index-V.index),v.forEach((O,V)=>{this.outputs.forEach(q=>{q.index>=O.index&&q.index++});const x=y.includes(O.index)?this.outputs.length-1+V:O.index,U={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:p.OutputMap,declaration:O.toJSON(),defaultValue:null,writesValues:[],index:x,parent:this.toReference()},S=oe(U,this.project);S.setParent(this,i),S.initChildren(i),i==null||i.add(S,F.Added),S.addSelfToProject(i)}),this.outputs.sort((O,V)=>O.index-V.index);const{updated:T,added:b,removed:I}=this.removeUnrecognizedOutputs(i);return a.push(...T),o.push(...b),f.push(...I),i==null||i.attemptAutoclose("sync-missing-fixed-outputs",this.id),{updated:w(a),added:w(o),removed:w(f),affected:w(e),self:this}}getUnusedInputs(){return this.inputs.filter(i=>i.suggestion||!i.readsValue&&!i.defaultValue)}getUnusedOutputs(){return this.outputs.filter(i=>i.suggestion||!i.writesValues.length)}getUsedInputs(){return this.inputs.filter(i=>!i.suggestion&&(i.readsValue||i.defaultValue))}getUsedOutputs(){return this.outputs.filter(i=>!i.suggestion&&i.writesValues.length)}};_(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}),_(zt,"type",p.InternalCall),_(zt,"USER_MANAGED_PARENT_TYPES",[...Rt]),_(zt,"PARENT_TYPES",[...zt.USER_MANAGED_PARENT_TYPES]),_(zt,"MUTABLE_BASE_PROPERTIES",["catchesError"]),_(zt,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),_(zt,"BASE_PROPERTIES",[...zt.MUTABLE_BASE_PROPERTIES,...zt.INMUTABLE_BASE_PROPERTIES]),_(zt,"MUTABLE_META_PROPERTIES",[...zt.MUTABLE_BASE_PROPERTIES,"index"]),_(zt,"INMUTABLE_META_PROPERTIES",[...zt.INMUTABLE_BASE_PROPERTIES]),_(zt,"META_PROPERTIES",[...zt.MUTABLE_META_PROPERTIES,...zt.INMUTABLE_META_PROPERTIES]),_(zt,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry"]),_(zt,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","declaration"]),_(zt,"UPSTREAM_PROPERTIES",[...zt.MUTABLE_UPSTREAM_PROPERTIES,...zt.INMUTABLE_UPSTREAM_PROPERTIES]),_(zt,"MUTABLE_DOWNSTREAM_PROPERTIES",["inputs","outputs","writesValues","successCalls","errorCalls","error"]),_(zt,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),_(zt,"DOWNSTREAM_PROPERTIES",[...zt.MUTABLE_DOWNSTREAM_PROPERTIES,...zt.INMUTABLE_DOWNSTREAM_PROPERTIES]),_(zt,"PROPERTIES",[...zt.META_PROPERTIES,...zt.UPSTREAM_PROPERTIES,...zt.DOWNSTREAM_PROPERTIES]);let ko=zt;function gZ(d){const u=[...Jo(d)];return _i(d.errors,u)}const O_e=Object.freeze(Object.defineProperty({__proto__:null,validate:gZ},Symbol.toStringTag,{value:"Module"}));function zr(d){return d.declaration||d}function P_e(d){return d.type===p.VariableDeclaration?d.parent===d.project?"global-declaration":"local-declaration":d.declaration.parent===d.project?"global-instance":"local-instance"}function yA(d,u){const i=[];if(d.type===p.Project)i.push(...d.variableDeclarations);else{const o=Wa(ct(d)).filter(f=>f.type===p.VariableDeclaration);i.push(...o),d.parent&&(Ki.includes(d.parent.type)||d.parent.type===p.Project)&&i.push(...yA(d.parent))}return i}function $_e(d){if(d.declaration&&d.declaration.type===p.Property){if(d.declaration.interactive){if(d.declaration.implements&&!d.declaration.implements.interactive)return!1;if(d.declaration.extends&&!d.declaration.extends.interactive)return!1}else return!1;if(d.declaration.private){const u=Ai(d),i=Pu(u,d.project);if((i==null?void 0:i.type)===p.FunctionDeclaration&&(i==null?void 0:i.parent.type)===p.DefinitionEntity&&(i==null?void 0:i.parent.id)!==d.declaration.parent.id)return!1}}return!0}var IZ=(d=>(d.Declaration="declaration",d.DataTypeEntity="data-type-entity",d))(IZ||{});const Wt=class Wt extends ki{constructor(i,a){super(i);_(this,"initialData");_(this,"id");_(this,"index");_(this,"name",null);_(this,"codeName",null);_(this,"description",null);_(this,"type",p.InputMap);_(this,"defaultValue",null);_(this,"readsValue",null);_(this,"dataType",null);_(this,"declaration",null);_(this,"project");_(this,"errors",[]);_(this,"parent");_(this,"detachedDependents",{});_(this,"knownVersions",null);_(this,"activeVersion",!1);_(this,"initialized",!1);_(this,"startedInitialization",!1);_(this,"suggestion",!1);_(this,"_codeNativeValueValidation",null);this.initialData=i,this.project=a,this.id=i.id,this.index=i.index,this.name=i.name||null,this.codeName=i.codeName||null,this.description=i.description||null}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:p.InputMap,name:"",codeName:null,description:"",declaration:null,index:0,readsValue:null,defaultValue:null,parent:null}}static fromGenerationTarget(i,a){const o=z(i.parent),f=a.get(o);let e=null;if(i.declaration){const b=z(i.declaration);e=a.get(b)}let y=null;if(i.readsValue){const b=z(i.readsValue);y=a.get(b)}const v={id:i.id,version:N.UUID.uuid(),createdAt:L().toISOString(),author:N.sessionAuthor,previousVersion:null,deleted:!1,name:i.name||null,type:p.InputMap,index:(f.inputs||[]).length,codeName:i.codeName||null,description:i.description||null,declaration:e,readsValue:y,defaultValue:null,parent:f},T=oe(v,a);return T.setParent(f,null),T}static validateGenerationTarget(i,a){var b;let o=JSON.parse(JSON.stringify(i));const f=[],e=mr(o,{parent:{list:!1,types:[...ci,p.InputMap]}},a);o=e.modifiedData;const y=a.get(o.parent),v=o.declaration&&(a.get(o.declaration)||a.getBuiltIn(o.declaration)),T=((y==null?void 0:y.inputs)||[]).find(I=>{var O;return o.declaration&&((O=I.declaration)==null?void 0:O.id)===o.declaration});if(o.declaration?v?[p.Property,p.ArgumentDeclaration,p.ValueDescriptor].includes(v.type)?y&&v.type===p.ArgumentDeclaration&&![p.FunctionCall,p.Search,p.InternalCall].includes(y.type)?f.push(new le({id:`${o.id}--${K.InvalidInputMapDeclaration}`,code:K.InvalidInputMapDeclaration,severity:H.Error,message:`Entity of type '${p.InputMap}' with id '${o.id}' has a 'declaration' property pointing to an entity with type '${p.ArgumentDeclaration}' with id '${o.declaration}'.
151
151
  The parent entity of type '${y.type}' with id '${y.id}' is not compatible with this type of declaration.
152
152
  Only 'function-call', 'search' and 'internal-call' entities can have input-maps whose 'declaration' points to 'argument-declaration' entities.`})):y&&v.type===p.Property&&!Rt.includes(y.type)?f.push(new le({id:`${o.id}--${K.InvalidInputMapDeclaration}`,code:K.InvalidInputMapDeclaration,severity:H.Error,message:`Entity of type '${p.InputMap}' with id '${o.id}' has a 'declaration' property pointing to an entity with type '${p.Property}' with id '${o.declaration}'.
153
153
  The parent entity of type '${y.type}' with id '${y.id}' is not compatible with this type of declaration.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elyx-code/project-logic-tree",
3
- "version": "0.0.6530",
3
+ "version": "0.0.6532",
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",
@@ -27,9 +27,11 @@
27
27
  },
28
28
  "dependencies": {
29
29
  "@elyx-code/common-ts-utils": "^0.0.111",
30
- "@elyx-code/definitions": "^0.0.7983",
30
+ "@elyx-code/definitions": "^0.0.7986",
31
31
  "axios": "^1.9.0",
32
32
  "dayjs": "^1.11.13",
33
+ "i": "^0.3.7",
34
+ "npm": "^11.5.2",
33
35
  "sql-parser-cst": "^0.33.1",
34
36
  "underscore": "^1.13.7",
35
37
  "zod": "^3.22.4",
@@ -42,6 +44,7 @@
42
44
  "@nangohq/types": "^0.58.4",
43
45
  "@types/node": "^20.5.0",
44
46
  "@types/underscore": "^1.11.15",
47
+ "chalk": "4.1.2",
45
48
  "dotenv": "^16.0.3",
46
49
  "nango": "^0.58.4",
47
50
  "pg": "^8.16.3",
@@ -50,7 +53,6 @@
50
53
  "vite": "^4.5.9",
51
54
  "vite-plugin-dts": "^3.5.2",
52
55
  "vitest": "^3.2.2",
53
- "chalk": "4.1.2",
54
56
  "yaml": "^2.7.1"
55
57
  },
56
58
  "peerDependencies": {