@elyx-code/project-logic-tree 0.0.6239 → 0.0.6240

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
@@ -49754,14 +49754,14 @@ You shouldn't have to manually update a 'parent' property. The equivalent result
49754
49754
  calledByEntry: i.calledByEntry || [],
49755
49755
  calledBySuccess: i.calledBySuccess || [],
49756
49756
  calledByError: i.calledByError || [],
49757
- declaration: this.toJSON(),
49757
+ declaration: this.toReference(),
49758
49758
  x: 0,
49759
49759
  y: 0
49760
49760
  }, l = P(
49761
49761
  s,
49762
49762
  this.project
49763
49763
  );
49764
- return l.setParent(e, null), l.initChildren(null), t == null || t.add(l, A.Added), e === this.project && this.project.addVariableInstance(l), t == null || t.attemptAutoclose("create-instance", this.id), l;
49764
+ return l.hydrateAncestors(), l.setParent(e, t), t == null || t.add(l, A.Added), l.addSelfToProject(t), l.initChildren(t), e === this.project && this.project.addVariableInstance(l), t == null || t.attemptAutoclose("create-instance", this.id), l;
49765
49765
  }
49766
49766
  // If a variable has a data type that represents an object, like KeyValue or a definition entity
49767
49767
  // Its variables can be set as inputs into the entity
@@ -106,7 +106,7 @@ Specifically for variables, their scope is also calculated from their value read
106
106
  You shouldn't have to manually update a 'parent' property. The equivalent result is to change its value readers, value writters, or callers.`,issue:null})),{errors:t,modifiedData:i}}subscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]||(this.detachedDependents[t.entity.id]=t)}),this}syncDependents(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-dependents"))){const t=[],i=[],s=[],l=[];return Object.values(this.detachedDependents).forEach(o=>{const d=o.entity.afterAllChildrenInitialized(e);t.push(...d.updated),i.push(...d.added),s.push(...d.removed),l.push(...d.affected)}),e==null||e.attemptAutoclose("sync-dependents",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];if(t==="parent"){const{updated:u,added:y,removed:c}=this.remove({ignoreUpstream:!1},i);s.push(...u),l.push(...y),o.push(...c)}if(t==="var-declaration"){const{updated:u,added:y,removed:c}=this.remove({ignoreUpstream:!1},i);s.push(...u),l.push(...y),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}onDetachedDependencyRestored(e,t,i){const s=[],l=[],o=[],d=[];if(t==="parent"){const{updated:u,added:y,removed:c}=this.restore({},i);s.push(...u),l.push(...y),o.push(...c)}if(t==="var-declaration"){const{updated:u,added:y,removed:c}=this.restore({},i);s.push(...u),l.push(...y),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}subscribeToDependencies(){var e,t,i,s;return(e=this.parent)==null||e.subscribeDependents([{entity:this,field:"parent"}]),(s=(i=(t=this.declaration.dataType)==null?void 0:t.entity)==null?void 0:i.subscribeDependents)==null||s.call(i,[{entity:this,field:"data-type-entity"}]),this.declaration.subscribeDependents([{entity:this,field:"var-declaration"}]),this}increaseVersion(e){if(e&&!T(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&T(e).isSame(T(this.createdAt))?this:(this.previousVersion=this.version,this.version=m.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new Ce(this,this.project);return e.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,e):new Map([[this.version,e]]),e.inputs=this.inputs,e.outputs=this.outputs,e.internalCalls=this.internalCalls,e.successCalls=this.successCalls,e.errorCalls=this.errorCalls,e.writesValues=this.writesValues,e.readsValue=this.readsValue,e.defaultValue=this.defaultValue,e.declaration=this.declaration,e.calledBySuccess=this.calledBySuccess,e.calledByError=this.calledByError,e.calledByEntry=this.calledByEntry,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],i=[],s=[],l=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),i.push(...o.added),s.push(...o.removed)}return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}async restoreVersion(e){var d;const t=[],i=[],s=[],l=[];if(this.version===e)return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this};if(!this.knownVersions){const u=new Map;for(const[y,c]of this.knownVersions||new Map){if(u.set(y,c),c.activeVersion=!1,c.knownVersions)for(const[E,I]of c.knownVersions)u.set(E,I);c.knownVersions=null}}let o=(d=this.knownVersions)==null?void 0:d.get(e);if(!o){const u=await this.APILoadVersion({},e);if(!u)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new Ce(u,this.project)}return this.metaSync(o.toShallowJSON(),null),this.inputs=o.inputs,this.outputs=o.outputs,this.internalCalls=o.internalCalls,this.successCalls=o.successCalls,this.errorCalls=o.errorCalls,this.writesValues=o.writesValues,this.readsValue=o.readsValue,this.defaultValue=o.defaultValue,this.declaration=o.declaration,this.calledBySuccess=o.calledBySuccess,this.calledByError=o.calledByError,this.calledByEntry=o.calledByEntry,this.parent=o.parent,{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}hydrateAncestors(){const e=[],t=[],i=[],s=[];if(this.initialData.parent){const l=_(this.initialData.parent),o=this.project.get(l);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(this.initialData.readsValue){const l=_(this.initialData.readsValue),o=this.project.get(l);o&&(this.setValueWriter(o,null),e.push(o))}if(this.initialData.declaration){const l=_(this.initialData.declaration),o=this.project.get(l);o&&(this.setDeclaration(o),e.push(o))}return this.initialData.calledByEntry.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addEntryCaller(d,null),d.addCall(this,null),e.push(d))}),this.initialData.calledBySuccess.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addSuccessCaller(d,null),d.addSuccessCall(this,null),e.push(d))}),this.initialData.calledByError.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addErrorCaller(d,null),d.addErrorCall(this,null),e.push(d))}),Rr.hydrateReadsValue(this),{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"after-all-children-initialized"))){var B;const t=[],i=[],s=[],l=[];this.initialized=!0;const{added:o,updated:d,removed:u,affected:y}=this.generateUnusedInputs(e);i.push(...o),t.push(...d),s.push(...u),l.push(...y);const{added:c,updated:E,removed:I,affected:O}=this.generateUnusedOutputs(e);i.push(...c),t.push(...E),s.push(...I),l.push(...O);const{added:P,updated:V,removed:M,affected:g}=this.generateUnusedInternalCalls(e);if(i.push(...P),t.push(...V),s.push(...M),l.push(...g),!this.declaration.dataType||(B=this.declaration.dataType)!=null&&B.inferred){const{added:G,updated:q,removed:W,affected:X}=this.declaration.inferDataTypeAndSyncInstancesInputsAndOutputs(e);i.push(...G),t.push(...q),s.push(...W),l.push(...X)}return this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addSelfToProject(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-self-to-project"))){const t=[this],i=[],s=[],l=[];return this.parent===this.project&&this.project.addVariableInstance(this),this.readsValue&&(this.readsValue.addValueReader(this,e),t.push(this.readsValue)),this.writesValues.forEach(o=>{o.setValueWriter(this,e),t.push(o)}),this.successCalls.forEach(o=>{o.addSuccessCaller(this,e),t.push(o)}),this.errorCalls.forEach(o=>{o.addErrorCaller(this,e),t.push(o)}),this.calledBySuccess.forEach(o=>{o.addSuccessCall(this,e),t.push(o)}),this.calledByError.forEach(o=>{o.addErrorCall(this,e),t.push(o)}),this.calledByEntry.forEach(o=>{o.addCall(this,e),t.push(o)}),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}get usedInputs(){return this.inputs.filter(e=>e.readsValue||e.defaultValue)}get unusedInputs(){return this.inputs.filter(e=>!e.readsValue&&!e.defaultValue)}get usedOutputs(){return this.outputs.filter(e=>e.writesValues.length)}get unusedOutputs(){return this.outputs.filter(e=>!e.writesValues.length)}get usedInternalCalls(){return this.internalCalls.filter(e=>!!e.calledBy.length)}get unusedInternalCalls(){const e=this.usedInternalCalls;return this.internalCalls.filter(i=>!(e.find(o=>o.id===i.id)||e.find(o=>o.declaration===i.declaration)))}removeInput(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-input"))){const i=this.inputs.findIndex(s=>s.id===e.id);return i>-1&&(this.inputs.splice(i,1),t&&(t==null||t.add(this,b.Affected))),t==null||t.attemptAutoclose("remove-input",this.id),this}addInput(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-input"))){return this.inputs.includes(e)?(t==null||t.attemptAutoclose("add-input",this.id),this):(this.inputs.push(e),t==null||t.add(this,b.Affected),t==null||t.attemptAutoclose("add-input",this.id),this)}addOutput(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-output"))){return this.outputs.includes(e)?(t==null||t.attemptAutoclose("add-output",this.id),this):(this.outputs.push(e),t==null||t.add(this,b.Affected),t==null||t.attemptAutoclose("add-output",this.id),this)}removeOutput(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-output"))){const i=this.outputs.findIndex(s=>s.id===e.id);return i>-1&&(this.outputs.splice(i,1),t&&(t==null||t.add(this,b.Affected))),t==null||t.attemptAutoclose("remove-output",this.id),this}addSuccessCaller(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-success-caller")),i=!1){return this.calledBySuccess.find(s=>s.id===e.id)||(this.calledBySuccess.push(e),t==null||t.add(this,b.Updated),i&&K(this,t)),t==null||t.attemptAutoclose("add-success-caller",this.id),this}addErrorCaller(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-error-caller")),i=!1){return this.calledByError.find(s=>s.id===e.id)||(this.calledByError.push(e),t==null||t.add(this,b.Updated),i&&K(this,t)),t==null||t.attemptAutoclose("add-error-caller",this.id),this}addEntryCaller(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-entry-caller")),i=!1){return this.calledByEntry.find(s=>s.id===e.id)||(this.calledByEntry.push(e),t==null||t.add(this,b.Updated),i&&K(this,t)),t==null||t.attemptAutoclose("add-entry-caller",this.id),this}addErrorCall(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-error-call")),i=!1){return this.errorCalls.find(s=>s.id===e.id)||(this.errorCalls.push(e),i&&K(this,t),t==null||t.add(this,b.Affected)),t==null||t.attemptAutoclose("add-error-call",this.id),this}addSuccessCall(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-success-call")),i=!1){return this.successCalls.find(s=>s.id===e.id)||(this.successCalls.push(e),i&&K(this,t),t==null||t.add(this,b.Affected)),t==null||t.attemptAutoclose("add-success-call",this.id),this}removeCall(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-call")),i=!1){const s=this.successCalls.findIndex(o=>o.id===e.id);s>-1&&(this.successCalls.splice(s,1),t==null||t.add(this,b.Affected));const l=this.errorCalls.findIndex(o=>o.id===e.id);return l>-1&&(this.errorCalls.splice(l,1),t==null||t.add(this,b.Affected)),i&&K(this,t),t==null||t.attemptAutoclose("remove-call",this.id),this}removeCaller(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-caller")),i=!1){return this.calledBySuccess=this.calledBySuccess.filter(s=>s.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(s,b.Affected)),!0):!1),this.calledByError=this.calledByError.filter(s=>s.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(s,b.Affected)),!0):!1),this.calledByEntry=this.calledByEntry.filter(s=>s.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(s,b.Affected)),!0):!1),i&&K(this,t),t==null||t.attemptAutoclose("remove-caller",this.id),this}addValueReader(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-value-reader"))){return this.writesValues.includes(e)?(t==null||t.attemptAutoclose("add-value-reader",this.id),this):(this.writesValues.push(e),t==null||t.add(this,b.Affected),this)}setParent(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"set-parent"))){var i;return((i=this.parent)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,b.Updated),t==null||t.attemptAutoclose("set-parent",this.id))),this}initChildren(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"init-children"))){if(this.initialized||this.startedInitialization)return this;if(this.startedInitialization=!0,this.initialData.defaultValue&&(this.defaultValue=C(this.initialData.defaultValue,this.project),this.defaultValue.setParent(this,null),this.defaultValue.initChildren(e)),this.initialData.declaration.type===n.GenericReference){const t=this.project.findSubscribedInstanceFromReference(this.initialData.declaration);if(!t)return this;this.declaration=t}else this.declaration=C(this.initialData.declaration,this.project),this.declaration.setParent(this.parent,null),this.declaration.initChildren(e);return xa.initWritesValues(this,this.parent),Rr.initReadsValue(this),this.initialData.inputs.forEach(t=>{const i=C(t,this.project);return i.setParent(this,null),i.initChildren(e),this.addInput(i,null),i}),this.initialData.outputs.forEach(t=>{const i=C(t,this.project);return i.setParent(this,null),i.initChildren(e),this.addOutput(i,e),i}),this.successCalls=this.initialData.successCalls.map(t=>{const i=C(t,this.project);if(i.addSuccessCaller(this),[n.BreakStatement,n.ContinueStatement].includes(i.type))i.setParent(this.parent.parent,null),i.initChildren(e);else if(i.type===n.ReturnStatement){const s=It(this,this.project);i.setParent(s,null),i.initChildren(e)}else i.type!==n.InternalCall&&(i.setParent(this.parent,null),i.initChildren(e));return i}),this.errorCalls=this.initialData.errorCalls.map(t=>{const i=C(t,this.project);if(i.addErrorCaller(this),[n.BreakStatement,n.ContinueStatement].includes(i.type))i.setParent(this.parent.parent,null),i.initChildren(e);else if(i.type===n.ReturnStatement){const s=It(this,this.project);i.setParent(s,null),i.initChildren(e)}else i.type!==n.InternalCall&&(i.setParent(this.parent,null),i.initChildren(e));return i}),this.internalCalls=this.initialData.internalCalls.reduce((t,i)=>{if(i.type===n.GenericReference){const s=this.project.findSubscribedInstanceFromReference(i);if(!s)return t;const l=s;return l.setParent(this,null),[...t,l]}else{const s=C(i,this.project);return s.setParent(this,null),s.initChildren(e),[...t,s]}},[]),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this}setValueWriter(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"set-value-writer"))){return this.readsValue!==e&&(this.readsValue=e,t==null||t.add(this,b.Updated)),t==null||t.attemptAutoclose("set-value-writer",this.id),this}removeValueWriter(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-value-writer"))){return this.readsValue&&(this.readsValue=null,e==null||e.add(this,b.Updated)),e==null||e.attemptAutoclose("remove-value-writer",this.id),this}removeValueReader(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-value-reader"))){return this.writesValues.includes(e)?(this.writesValues=this.writesValues.filter(i=>i.id!==e.id),t==null||t.add(this,b.Affected),this):(t==null||t.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(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"meta-sync"))){const i=ct(this,e),s=this.toMeta();return this.x=e.x||s.x,this.y=e.y||s.y,super.metaSync(e),e.deleted===!0&&!s.deleted?t==null||t.add(this,b.Removed):e.deleted===!1&&s.deleted?t==null||t.add(this,b.Added):i&&(t==null||t.add(this,b.Updated)),t==null||t.attemptAutoclose("meta-sync",this.id),this}async APILoad(e=U,...t){return await Ce.repository.APILoad(this.id,...t),this}async APICreate(e=U,...t){return await Ce.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=U,...t){return await Ce.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=U,...t){return await Ce.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=U,...t){return await Ce.repository.APIClone(this.id,...t),this}async APILoadVersion(e=U,t,...i){return await Ce.repository.APILoadVersion(this.id,t,...i)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-entity"))){const i=[],s=[],l=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(s.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(d=>{const{updated:u,removed:y,added:c}=d.entity.onDetachedDependencyRemoved(this,d.field,t);i.push(...u),s.push(...y),l.push(...c)}),this.defaultValue){const{updated:d,removed:u}=this.defaultValue.remove({ignoreUpstream:!0},t);i.push(...d),s.push(...u)}return this.readsValue&&(i.push(this.readsValue),this.readsValue.removeValueReader(this,t)),this.writesValues.forEach(d=>{i.push(d),d.setValueWriter(null,t)}),this.inputs.forEach(d=>{const{updated:u,removed:y}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...y)}),this.outputs.forEach(d=>{const{updated:u,removed:y}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...y)}),this.successCalls.forEach(d=>{i.push(d),d.removeCaller(this,t)}),this.errorCalls.forEach(d=>{i.push(d),d.removeCaller(this,t)}),this.internalCalls.forEach(d=>{const{updated:u,removed:y}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...y)}),e||this.calledBy.forEach(d=>{i.push(d),d.removeCall(this,t)}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:p(l),updated:p(i),removed:p(s),affected:p(o),self:this}}restore({}={},e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"restore-entity"))){const t=[],i=[],s=[],l=[];if(e!=null&&e.hasAdded(this.id))return e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),Object.values(this.detachedDependents).forEach(o=>{const{updated:d,removed:u,added:y}=o.entity.onDetachedDependencyRestored(this,o.field,e);i.push(...d),s.push(...u),t.push(...y)}),this.defaultValue){const{updated:o}=this.defaultValue.restore({},e);i.push(...o)}return this.readsValue&&(i.push(this.readsValue),this.readsValue.addValueReader(this,e)),this.writesValues.forEach(o=>{i.push(o),o.setValueWriter(this,e)}),this.inputs.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.outputs.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.successCalls.forEach(o=>{i.push(o),o.addSuccessCaller(this,e)}),this.errorCalls.forEach(o=>{i.push(o),o.addErrorCaller(this,e)}),this.internalCalls.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.calledBySuccess.forEach(o=>{i.push(o),o.addSuccessCall(this,e)}),this.calledByError.forEach(o=>{i.push(o),o.addErrorCall(this,e)}),this.calledByEntry.forEach(o=>{i.push(o),o.addCall(this,e)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(l),self:this}}toFlat(e=new Set){var i,s;return e.has(this.id)?[]:(e.add(this.id),[this,...((i=this.defaultValue)==null?void 0:i.toFlat(e))||[],...this.writesValues.flatMap(l=>l.toFlat(e)),...((s=this.readsValue)==null?void 0:s.toFlat(e))||[],...this.successCalls.flatMap(l=>l.toFlat(e)),...this.errorCalls.flatMap(l=>l.toFlat(e)),...this.inputs.flatMap(l=>l.toFlat(e)),...this.outputs.flatMap(l=>l.toFlat(e)),...this.internalCalls.flatMap(l=>l.toFlat(e))])}toFlatIds(e=new Set){var i;return e.has(this.id)?[]:(e.add(this.id),[this.id,...((i=this.defaultValue)==null?void 0:i.toFlatIds(e))||[],...this.writesValues.flatMap(s=>s.toFlatIds(e)),...this.successCalls.flatMap(s=>s.toFlatIds(e)),...this.errorCalls.flatMap(s=>s.toFlatIds(e)),...this.inputs.flatMap(s=>s.toFlatIds(e)),...this.outputs.flatMap(s=>s.toFlatIds(e)),...this.internalCalls.flatMap(s=>s.toFlatIds(e))])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,x:this.x,y:this.y,type:this.type}}toJSON(e=new Set){var t,i;return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,declaration:this.declaration.toJSON(e),defaultValue:((t=this.defaultValue)==null?void 0:t.toJSON(e))||null,readsValue:((i=this.readsValue)==null?void 0:i.toReference())||null,writesValues:this.writesValues.map(s=>s.toJSON(e)),inputs:this.inputs.map(s=>s.toJSON(e)),outputs:this.outputs.map(s=>s.toJSON(e)),successCalls:this.successCalls.map(s=>s.toJSON(e)),errorCalls:this.errorCalls.map(s=>s.toJSON(e)),internalCalls:this.internalCalls.map(s=>s.toJSON(e)),calledBySuccess:this.calledBySuccess.map(s=>s.toReference()),calledByError:this.calledByError.map(s=>s.toReference()),calledByEntry:this.calledByEntry.map(s=>s.toReference()),parent:this.parent.toReference(),x:this.x,y:this.y})}toJSONClone(e=J){var i,s,l,o,d,u,y;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||ht(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(s=e.seenEntities)!=null&&s.has(t)||(l=e.seenEntities)!=null&&l.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(d=e.seenEntities)==null||d.add(this.id),{id:t,version:m.UUID.uuid(),createdAt:e.timestamp||T().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,defaultValue:((u=this.defaultValue)==null?void 0:u.toJSONClone({...e,newId:null}))||null,declaration:this.declaration.toReference({seenEntityMaps:e.seenEntityMaps}),readsValue:((y=this.readsValue)==null?void 0:y.toReference({seenEntityMaps:e.seenEntityMaps}))||null,writesValues:this.writesValues.map(c=>c.toJSONClone({...e,newId:null})),inputs:this.inputs.map(c=>c.toJSONClone({...e,newId:null})),outputs:this.outputs.map(c=>c.toJSONClone({...e,newId:null})),successCalls:this.successCalls.map(c=>c.toJSONClone({...e,newId:null})),errorCalls:this.errorCalls.map(c=>c.toJSONClone({...e,newId:null})),internalCalls:this.internalCalls.map(c=>this.calledBy.length||this.readsValue?c.toJSONClone({...e,newId:null}):c.toReference({seenEntityMaps:e.seenEntityMaps})),calledBySuccess:this.calledBySuccess.map(c=>c.toReference({seenEntityMaps:e.seenEntityMaps})),calledByError:this.calledByError.map(c=>c.toReference({seenEntityMaps:e.seenEntityMaps})),calledByEntry:this.calledByEntry.map(c=>c.toReference({seenEntityMaps:e.seenEntityMaps})),parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps}),x:this.x,y:this.y})}toReference(e=J){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+m.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=J){var i,s,l,o;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,defaultValue:((s=this.defaultValue)==null?void 0:s.toReference(e))||null,declaration:((l=this.declaration)==null?void 0:l.toReference(e))||null,readsValue:((o=this.readsValue)==null?void 0:o.toReference(e))||null,writesValues:this.writesValues.map(d=>d.toReference(e)),inputs:this.inputs.map(d=>d.toReference(e)),outputs:this.outputs.map(d=>d.toReference(e)),successCalls:this.successCalls.map(d=>d.toReference(e)),errorCalls:this.errorCalls.map(d=>d.toReference(e)),calledBySuccess:this.calledBySuccess.map(d=>d.toReference(e)),calledByError:this.calledByError.map(d=>d.toReference(e)),calledByEntry:this.calledByEntry.map(d=>d.toReference(e)),internalCalls:this.internalCalls.map(d=>d.toReference(e)),parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){var i,s;return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...((i=this.defaultValue)==null?void 0:i.toFlatJSON(e))||[],...((s=this.declaration)==null?void 0:s.toFlatJSON(e))||[],...this.writesValues.flatMap(l=>l.toFlatJSON(e)),...this.successCalls.flatMap(l=>l.toFlatJSON(e)),...this.errorCalls.flatMap(l=>l.toFlatJSON(e)),...this.inputs.flatMap(l=>l.toFlatJSON(e)),...this.outputs.flatMap(l=>l.toFlatJSON(e)),...this.internalCalls.flatMap(l=>l.toFlatJSON(e)),...this.calledBy.flatMap(l=>l.toFlatJSON(e))])}toGenerationTarget(){const e=this.parent.type===n.Project?void 0:this.parent.id;return{id:this.id,type:this.type,declaration:this.declaration.id,calledByEntry:this.calledByEntry.map(t=>t.id),calledBySuccess:this.calledBySuccess.map(t=>t.id),calledByError:this.calledByError.map(t=>t.id),parent:e}}toFlatGenerationTarget(e=new Set){var i,s,l;return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...((i=this.defaultValue)==null?void 0:i.toFlatGenerationTarget(e))||[],...((s=this.declaration)==null?void 0:s.toFlatGenerationTarget(e))||[],...((l=this.readsValue)==null?void 0:l.toFlatGenerationTarget(e))||[],...this.writesValues.flatMap(o=>o.toFlatGenerationTarget(e)),...this.successCalls.flatMap(o=>o.toFlatGenerationTarget(e)),...this.errorCalls.flatMap(o=>o.toFlatGenerationTarget(e)),...this.inputs.flatMap(o=>o.toFlatGenerationTarget(e)),...this.outputs.flatMap(o=>o.toFlatGenerationTarget(e)),...this.internalCalls.flatMap(o=>o.toFlatGenerationTarget(e))])}clearErrors(){var e;return this.errors=[],(e=this.defaultValue)==null||e.clearErrors(),this.inputs.forEach(t=>t.clearErrors()),this.outputs.forEach(t=>t.clearErrors()),this.successCalls.forEach(t=>t.clearErrors()),this.errorCalls.forEach(t=>t.clearErrors()),this.internalCalls.forEach(t=>t.clearErrors()),this}validate(){const e=b1(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){var t,i;return[...this.errors,...((t=this.defaultValue)==null?void 0:t.getErrors())||[],...this.inputs.flatMap(s=>s.getErrors()),...this.internalCalls.flatMap(s=>s.getErrors()),...this.outputs.flatMap(s=>s.getErrors()),...((i=this.readsValue)==null?void 0:i.getErrors())||[]]}getShallowErrors(){return this.errors}getDefaultValue(){var e;return this.defaultValue||((e=this.declaration)==null?void 0:e.defaultValue)||null}setDefaultValue(e){return this.defaultValue=e,this}clone(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"clone-entity")),t=null,i=null,s=!0){var O,P,V,M;let l=mt(t,this);const o=this.toJSON(),d=i||m.UUID.uuid();o.inputs=[],o.id=d,o.version=m.UUID.uuid(),o.createdAt=(e==null?void 0:e.timestamp)||T().toISOString(),o.author=(e==null?void 0:e.author)||"1",o.previousVersion=null,o.deleted=!1;const u=nt(o,l);t?u.setParent(t,null):u.setParent(this.parent,null),s&&u.subscribe(),u.initChildren(e),e==null||e.add(u,b.Added);const y=(O=this.defaultValue)==null?void 0:O.clone(e,u,m.UUID.uuid(),s);u.defaultValue=y||null;const c=(P=this.inputs)==null?void 0:P.map(g=>g.clone(e,u,m.UUID.uuid(),s));u.inputs=c;const E=(V=this.outputs)==null?void 0:V.map(g=>g.clone(e,u,m.UUID.uuid(),s));u.outputs=E;const I=(M=this.internalCalls)==null?void 0:M.map(g=>g.clone(e,u,m.UUID.uuid(),s));return u.internalCalls=I,e==null||e.attemptAutoclose("clone-entity",this.id),u}addInternalCall(e){return this.internalCalls.find(t=>t===e)||this.internalCalls.push(e),this}setDeclaration(e){return this.declaration!==e&&(this.declaration=e),this}generateUnusedInputs(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"generate-unused-inputs"))){const t=[],i=[],s=[],l=[];if(this.declaration.dataType)if(this.declaration.dataType.entity){if([n.DefinitionEntity,n.PrimitiveEntity,n.BuiltInBaseEntity].includes(this.declaration.dataType.entity.type)){const o=[...this.declaration.dataType.entity.properties];o.filter(c=>!c.getDataType(e)).forEach(c=>{const E=this.inputs.find(P=>x(P,this.project)===x(c,this.project));if(!E)return;const I=this.declaration.getMasterInputWithValueWritterFromAllInstances(E);if(!I)return;const O=ji(I);c.setDataType(O),E.setDeclaration(c)}),o.filter(c=>!this.inputs.find(E=>{var I;return((I=E.declaration)==null?void 0:I.id)===c.id})).forEach(c=>{const E={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.InputMap,parent:this.toReference(),name:null,description:null,declaration:c,defaultValue:null,index:c.index,readsValue:null},I=C(E,this.project);return I.setParent(this,e),I.initChildren(e),e==null||e.add(I,b.Added),I.suggestion=!0,this.addInput(I,e),I}),this.inputs.filter(c=>!c.declaration).forEach(c=>{const E=o.find(I=>x(I,this.project)===x(c,this.project));E&&c.setDeclaration(E)})}}else return e==null||e.attemptAutoclose("generate-unused-inputs",this.id),{added:[],updated:[],removed:[],affected:[],self:this};else return e==null||e.attemptAutoclose("generate-unused-inputs",this.id),{added:[],updated:[],removed:[],affected:[],self:this};return e==null||e.attemptAutoclose("generate-unused-inputs",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(l),self:this}}generateUnusedOutputs(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"generate-unused-outputs"))){const t=[],i=[],s=[],l=[];if(this.declaration.dataType)if(this.declaration.dataType.entity)[n.DefinitionEntity,n.PrimitiveEntity,n.BuiltInBaseEntity].includes(this.declaration.dataType.entity.type)&&[...this.declaration.dataType.entity.properties].filter(u=>!this.outputs.find(y=>y.declaration===u)).map(u=>{const y={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.OutputMap,parent:this.toReference(),defaultValue:null,declaration:u,index:u.index,writesValues:[]},c=C(y,this.project);return c.setParent(this,e),c.initChildren(e),e==null||e.add(c,b.Added),c.suggestion=!0,this.addOutput(c,e),c});else return e==null||e.attemptAutoclose("generate-unused-outputs",this.id),{added:[],updated:[],removed:[],affected:[],self:this};else return e==null||e.attemptAutoclose("generate-unused-outputs",this.id),{added:[],updated:[],removed:[],affected:[],self:this};return e==null||e.attemptAutoclose("generate-unused-outputs",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(l),self:this}}generateUnusedInternalCalls(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"generate-unused-internal-calls"))){const t=[],i=[],s=[],l=[];if(this.declaration.dataType)if(this.declaration.dataType.entity)[n.DefinitionEntity,n.PrimitiveEntity,n.BuiltInBaseEntity].includes(this.declaration.dataType.entity.type)&&[...this.declaration.dataType.entity.getAllInteractiveMethods()].filter(u=>!this.internalCalls.find(c=>{var I,O,P,V,M;return(((I=c.declaration)==null?void 0:I.id)||((P=(O=c.initialData)==null?void 0:O.declaration)==null?void 0:P.entityId)||((M=(V=c.initialData)==null?void 0:V.declaration)==null?void 0:M.id))===u.id})).map(u=>{const y=u.createInternalCall(e,this);return e==null||e.add(y,b.Added),y.suggestion=!0,this.addInternalCall(y),y});else return e==null||e.attemptAutoclose("generate-unused-internal-calls",this.id),{added:[],updated:[],removed:[],affected:[],self:this};else return e==null||e.attemptAutoclose("generate-unused-internal-calls",this.id),{added:[],updated:[],removed:[],affected:[],self:this};return e==null||e.attemptAutoclose("generate-unused-internal-calls",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(l),self:this}}getDataType(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"get-data-type"))){var t;return((t=this.declaration)==null?void 0:t.getDataType(e))||null}getUnusedInputs(){return this.inputs.filter(e=>e.suggestion||!e.readsValue&&!e.defaultValue)}getUnusedOutputs(){return this.outputs.filter(e=>e.suggestion||!e.writesValues.length)}getUsedInputs(){return this.inputs.filter(e=>!e.suggestion&&(e.readsValue||e.defaultValue))}getUsedOutputs(){return this.outputs.filter(e=>!e.suggestion&&e.writesValues.length)}};f(Ce,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>e,APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...i)=>null}),f(Ce,"type",n.VariableInstance),f(Ce,"USER_MANAGED_PARENT_TYPES",[...ut,n.Project]),f(Ce,"PARENT_TYPES",[...Ce.USER_MANAGED_PARENT_TYPES]),f(Ce,"MUTABLE_BASE_PROPERTIES",[]),f(Ce,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),f(Ce,"BASE_PROPERTIES",[...Ce.MUTABLE_BASE_PROPERTIES,...Ce.INMUTABLE_BASE_PROPERTIES]),f(Ce,"MUTABLE_META_PROPERTIES",[...Ce.MUTABLE_BASE_PROPERTIES,"x","y"]),f(Ce,"INMUTABLE_META_PROPERTIES",[...Ce.INMUTABLE_BASE_PROPERTIES]),f(Ce,"META_PROPERTIES",[...Ce.MUTABLE_META_PROPERTIES,...Ce.INMUTABLE_META_PROPERTIES]),f(Ce,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry","readsValue"]),f(Ce,"INMUTABLE_UPSTREAM_PROPERTIES",["declaration","parent"]),f(Ce,"UPSTREAM_PROPERTIES",[...Ce.MUTABLE_UPSTREAM_PROPERTIES,...Ce.INMUTABLE_UPSTREAM_PROPERTIES]),f(Ce,"MUTABLE_DOWNSTREAM_PROPERTIES",["writesValues","inputs","outputs","successCalls","errorCalls","internalCalls"]),f(Ce,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),f(Ce,"DOWNSTREAM_PROPERTIES",[...Ce.MUTABLE_DOWNSTREAM_PROPERTIES,...Ce.INMUTABLE_DOWNSTREAM_PROPERTIES]),f(Ce,"PROPERTIES",[...Ce.META_PROPERTIES,...Ce.UPSTREAM_PROPERTIES,...Ce.DOWNSTREAM_PROPERTIES]);let zr=Ce;var R1=(r=>(r.Parent="parent",r.DataTypeEntity="data-type-entity",r))(R1||{});const Ve=class Ve extends lt{constructor(e,t){super(e);f(this,"initialData");f(this,"id");f(this,"name");f(this,"description",null);f(this,"required",!1);f(this,"constant",!1);f(this,"x");f(this,"y");f(this,"type",n.VariableDeclaration);f(this,"defaultValue",null);f(this,"dataType",null);f(this,"writesValues",[]);f(this,"readsValue",null);f(this,"inputs",[]);f(this,"outputs",[]);f(this,"calledBySuccess",[]);f(this,"calledByError",[]);f(this,"calledByEntry",[]);f(this,"successCalls",[]);f(this,"errorCalls",[]);f(this,"internalCalls",[]);f(this,"parent");f(this,"errors",[]);f(this,"project");f(this,"detachedDependents",{});f(this,"knownVersions",null);f(this,"activeVersion",!1);f(this,"initialized",!1);f(this,"startedInitialization",!1);f(this,"suggestion",!1);f(this,"codeNativeValueValidation",null);this.initialData=e,this.project=t,this.id=e.id,this.name=e.name,this.description=e.description,this.constant=e.constant,this.required=e.required,this.x=e.x,this.y=e.y}static new(e=null){return{id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:(e==null?void 0:e.author)||m.sessionAuthor,previousVersion:null,deleted:!1,type:n.VariableDeclaration,name:"",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(e,t){let i=t;if(e.parent){const c=_(e.parent);i=t.get(c)}const s=e.calledByEntry.map(c=>{const E=_(c);return t.get(E)}),l=e.calledBySuccess.map(c=>{const E=_(c);return t.get(E)}),o=e.calledByError.map(c=>{const E=_(c);return t.get(E)});let d=null;if(e.readsValue){const c=_(e.readsValue);d=t.get(c)}const u={id:e.id,version:m.UUID.uuid(),createdAt:T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.VariableDeclaration,name:e.name,defaultValue:null,description:e.description,constant:e.constant||!1,required:e.required||!1,calledByEntry:s,calledBySuccess:l,calledByError:o,dataType:null,errorCalls:[],successCalls:[],internalCalls:[],readsValue:d,inputs:[],outputs:[],writesValues:[],x:0,y:0,parent:i},y=C(u,t);return y.setParent(i,null),y.initChildren(null),y}static validateGenerationTarget(e,t){let i=JSON.parse(JSON.stringify(e));const s=[],l=bt(i,{parent:{list:!1,types:[...ut,n.Project],optional:!0}},t);i=l.modifiedData;const o=Rc(i,t);return s.push(...l.errors,...o,...pt(i)),{errors:s,modifiedData:i}}get variableInstances(){const e=[];return Object.values(this.detachedDependents).forEach(t=>{t.field===Nc.VarDeclaration&&!e.includes(t.entity)&&e.push(t.entity)}),e}validateGeneratedUpdate(e){const t=[];let i=JSON.parse(JSON.stringify(e));const s=_a(i,this);return i=s.modifiedData,t.push(...s.errors),e.parent&&t.push(new w({id:`${this.id}--${R.InvalidParentUpdate}`,code:R.InvalidParentUpdate,severity:D.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.
107
107
  If an entity is called by another, they must be in the same scope, which means they have the same parent.
108
108
  Specifically for variables, their scope is also calculated from their value readers and value writters.
109
- You shouldn't have to manually update a 'parent' property. The equivalent result is to change its value readers, value writters, or callers.`,issue:null})),{errors:t,modifiedData:i}}subscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]||(this.detachedDependents[t.entity.id]=t)}),this}syncDependents(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-dependents"))){const t=[],i=[],s=[],l=[];return Object.values(this.detachedDependents).forEach(o=>{const d=o.entity.afterAllChildrenInitialized(e);t.push(...d.updated),i.push(...d.added),s.push(...d.removed),l.push(...d.affected)}),e==null||e.attemptAutoclose("sync-dependents",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];if(t==="parent"){const{updated:u,added:y,removed:c}=this.remove({ignoreUpstream:!1},i);s.push(...u),l.push(...y),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}onDetachedDependencyRestored(e,t,i){const s=[],l=[],o=[],d=[];if(t==="parent"){const{updated:u,added:y,removed:c}=this.restore({},i);s.push(...u),l.push(...y),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}subscribeToDependencies(){var e,t,i,s;return(e=this.parent)==null||e.subscribeDependents([{entity:this,field:"parent"}]),(s=(i=(t=this.dataType)==null?void 0:t.entity)==null?void 0:i.subscribeDependents)==null||s.call(i,[{entity:this,field:"data-type-entity"}]),this}increaseVersion(e){if(e&&!T(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&T(e).isSame(T(this.createdAt))?this:(this.previousVersion=this.version,this.version=m.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new Ve(this,this.project);return e.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,e):new Map([[this.version,e]]),e.inputs=this.inputs,e.outputs=this.outputs,e.internalCalls=this.internalCalls,e.successCalls=this.successCalls,e.errorCalls=this.errorCalls,e.writesValues=this.writesValues,e.readsValue=this.readsValue,e.defaultValue=this.defaultValue,e.dataType=this.dataType,e.calledBySuccess=this.calledBySuccess,e.calledByError=this.calledByError,e.calledByEntry=this.calledByEntry,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],i=[],s=[],l=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),i.push(...o.added),s.push(...o.removed)}return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}async restoreVersion(e){var d;const t=[],i=[],s=[],l=[];if(this.version===e)return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this};if(!this.knownVersions){const u=new Map;for(const[y,c]of this.knownVersions||new Map){if(u.set(y,c),c.activeVersion=!1,c.knownVersions)for(const[E,I]of c.knownVersions)u.set(E,I);c.knownVersions=null}}let o=(d=this.knownVersions)==null?void 0:d.get(e);if(!o){const u=await this.APILoadVersion({},e);if(!u)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new Ve(u,this.project)}return this.metaSync(o.toShallowJSON(),null),this.inputs=o.inputs,this.outputs=o.outputs,this.internalCalls=o.internalCalls,this.successCalls=o.successCalls,this.errorCalls=o.errorCalls,this.writesValues=o.writesValues,this.readsValue=o.readsValue,this.defaultValue=o.defaultValue,this.dataType=o.dataType,this.calledBySuccess=o.calledBySuccess,this.calledByError=o.calledByError,this.calledByEntry=o.calledByEntry,this.parent=o.parent,{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}hydrateAncestors(){const e=[],t=[],i=[],s=[];if(this.initialData.parent){const l=_(this.initialData.parent),o=this.project.get(l);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(this.initialData.readsValue){const l=_(this.initialData.readsValue),o=this.project.get(l);o&&(this.setValueWriter(o,null),e.push(o))}return this.initialData.calledByEntry.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addEntryCaller(d,null),d.addCall(this,null),e.push(d))}),this.initialData.calledBySuccess.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addSuccessCaller(d,null),d.addSuccessCall(this,null),e.push(d))}),this.initialData.calledByError.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addErrorCaller(d,null),d.addErrorCall(this,null),e.push(d))}),Rr.hydrateReadsValue(this),{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],i=[],s=[],l=[];this.initialized=!0;const{added:o,updated:d,removed:u,affected:y}=this.generateUnusedInputs(e);i.push(...o),t.push(...d),s.push(...u),l.push(...y);const{added:c,updated:E,removed:I,affected:O}=this.generateUnusedOutputs(e);i.push(...c),t.push(...E),s.push(...I),l.push(...O);const{added:P,updated:V,removed:M,affected:g}=this.generateUnusedInternalCalls(e);if(i.push(...P),t.push(...V),s.push(...M),l.push(...g),!this.dataType||this.dataType.inferred){const{added:B,updated:G,removed:q,affected:W}=this.inferDataTypeAndSyncInstancesInputsAndOutputs(e);i.push(...B),t.push(...G),s.push(...q),l.push(...W)}return this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addSelfToProject(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-self-to-project"))){const t=[this],i=[],s=[],l=[];return this.parent===this.project&&this.project.addVariableDeclaration(this),this.readsValue&&(this.readsValue.addValueReader(this,e),t.push(this.readsValue)),this.writesValues.forEach(o=>{o.setValueWriter(this,e),t.push(o)}),this.successCalls.forEach(o=>{o.addSuccessCaller(this,e),t.push(o)}),this.errorCalls.forEach(o=>{o.addErrorCaller(this,e),t.push(o)}),this.calledBySuccess.forEach(o=>{o.addSuccessCall(this,e),t.push(o)}),this.calledByError.forEach(o=>{o.addErrorCall(this,e),t.push(o)}),this.calledByEntry.forEach(o=>{o.addCall(this,e),t.push(o)}),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}get usedInputs(){return this.inputs.filter(e=>e.readsValue||e.defaultValue)}get unusedInputs(){return this.inputs.filter(e=>!e.readsValue&&!e.defaultValue)}get usedOutputs(){return this.outputs.filter(e=>e.writesValues.length)}get unusedOutputs(){return this.outputs.filter(e=>!e.writesValues.length)}get usedInternalCalls(){return this.internalCalls.filter(e=>!!e.calledBy.length)}get unusedInternalCalls(){return this.internalCalls.filter(e=>!e.calledBy.length)}removeInput(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-input"))){const i=this.inputs.findIndex(s=>s.id===e.id);return i>-1&&(this.inputs.splice(i,1),t&&(t==null||t.add(this,b.Affected))),t==null||t.attemptAutoclose("remove-input",this.id),this}addInput(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-input"))){return this.inputs.includes(e)?(t==null||t.attemptAutoclose("add-input",this.id),this):(this.inputs.push(e),t==null||t.add(this,b.Affected),t==null||t.attemptAutoclose("add-input",this.id),this)}addOutput(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-output"))){return this.outputs.includes(e)?(t==null||t.attemptAutoclose("add-output",this.id),this):(this.outputs.push(e),t==null||t.add(this,b.Affected),t==null||t.attemptAutoclose("add-output",this.id),this)}removeOutput(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-output"))){const i=this.outputs.findIndex(s=>s.id===e.id);return i>-1&&(this.outputs.splice(i,1),t&&(t==null||t.add(this,b.Affected))),t==null||t.attemptAutoclose("remove-output",this.id),this}addSuccessCaller(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-success-caller")),i=!1){return this.calledBySuccess.find(s=>s.id===e.id)||(this.calledBySuccess.push(e),t==null||t.add(this,b.Updated),i&&K(this,t)),t==null||t.attemptAutoclose("add-success-caller",this.id),this}addErrorCaller(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-error-caller")),i=!1){return this.calledByError.find(s=>s.id===e.id)||(this.calledByError.push(e),t==null||t.add(this,b.Updated),i&&K(this,t)),t==null||t.attemptAutoclose("add-error-caller",this.id),this}addEntryCaller(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-entry-caller")),i=!1){return this.calledByEntry.find(s=>s.id===e.id)||(this.calledByEntry.push(e),t==null||t.add(this,b.Updated),i&&K(this,t)),t==null||t.attemptAutoclose("add-entry-caller",this.id),this}addErrorCall(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-error-call")),i=!1){return this.errorCalls.find(s=>s.id===e.id)||(this.errorCalls.push(e),i&&K(this,t),t==null||t.add(this,b.Affected)),t==null||t.attemptAutoclose("add-error-call",this.id),this}addSuccessCall(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-success-call")),i=!1){return this.successCalls.find(s=>s.id===e.id)||(this.successCalls.push(e),i&&K(this,t),t==null||t.add(this,b.Affected)),t==null||t.attemptAutoclose("add-success-call",this.id),this}removeCall(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-call")),i=!1){const s=this.successCalls.findIndex(o=>o.id===e.id);s>-1&&(this.successCalls.splice(s,1),t==null||t.add(this,b.Affected));const l=this.errorCalls.findIndex(o=>o.id===e.id);return l>-1&&(this.errorCalls.splice(l,1),t==null||t.add(this,b.Affected)),i&&K(this,t),t==null||t.attemptAutoclose("remove-call",this.id),this}removeCaller(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-caller")),i=!1){return this.calledBySuccess=this.calledBySuccess.filter(s=>s.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(s,b.Affected)),!0):!1),this.calledByError=this.calledByError.filter(s=>s.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(s,b.Affected)),!0):!1),this.calledByEntry=this.calledByEntry.filter(s=>s.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(s,b.Affected)),!0):!1),i&&K(this,t),t==null||t.attemptAutoclose("remove-caller",this.id),this}addValueReader(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-value-reader"))){return this.writesValues.includes(e)?(t==null||t.attemptAutoclose("add-value-reader",this.id),this):(this.writesValues.push(e),t==null||t.add(this,b.Affected),this)}removeValueReader(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-value-reader"))){return this.writesValues.includes(e)?(this.writesValues=this.writesValues.filter(i=>i.id!==e.id),t==null||t.add(this,b.Affected),this):(t==null||t.attemptAutoclose("remove-value-reader",this.id),this)}setParent(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"set-parent"))){var i;return((i=this.parent)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,b.Updated),t==null||t.attemptAutoclose("set-parent",this.id))),this}initChildren(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.initialData.defaultValue&&(this.defaultValue=C(this.initialData.defaultValue,this.project),this.defaultValue.setParent(this,null),this.defaultValue.initChildren(e)),this.initialData.dataType&&(this.dataType=C(this.initialData.dataType,this.project),this.dataType.setParent(this,null),this.dataType.initChildren(e)),xa.initWritesValues(this,this.parent),Rr.initReadsValue(this),this.successCalls=this.initialData.successCalls.map(t=>{const i=C(t,this.project);if(i.addSuccessCaller(this),[n.BreakStatement,n.ContinueStatement].includes(i.type))i.setParent(this.parent.parent,null),i.initChildren(e);else if(i.type===n.ReturnStatement){const s=It(this,this.project);i.setParent(s,null),i.initChildren(e)}else i.type!==n.InternalCall&&(i.setParent(this.parent,null),i.initChildren(e));return i}),this.errorCalls=this.initialData.errorCalls.map(t=>{const i=C(t,this.project);if(i.addErrorCaller(this),[n.BreakStatement,n.ContinueStatement].includes(i.type))i.setParent(this.parent.parent,null),i.initChildren(e);else if(i.type===n.ReturnStatement){const s=It(this,this.project);i.setParent(s,null),i.initChildren(e)}else i.type!==n.InternalCall&&(i.setParent(this.parent,null),i.initChildren(e));return i}),this.initialData.inputs.forEach(t=>{const i=C(t,this.project);return i.setParent(this,null),i.initChildren(e),this.addInput(i,null),i}),this.initialData.outputs.forEach(t=>{const i=C(t,this.project);return i.setParent(this,null),i.initChildren(e),this.addOutput(i,null),i}),this.initialData.internalCalls.forEach(t=>{if(t.type===n.GenericReference){const s=this.project.findSubscribedInstanceFromReference(t);if(!s)return;s.setParent(this,null),s.initChildren(e),this.addInternalCall(s);return}const i=C(t,this.project);return i.setParent(this,null),i.initChildren(e),this.addInternalCall(i),i}),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this)}setValueWriter(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"set-value-writer"))){return this.readsValue!==e&&(this.readsValue=e,t==null||t.add(this,b.Updated)),t==null||t.attemptAutoclose("set-value-writer",this.id),this}removeValueWriter(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-value-writer"))){return this.readsValue&&(this.readsValue=null,e==null||e.add(this,b.Updated)),e==null||e.attemptAutoclose("remove-value-writer",this.id),this}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}getMasterInputWithValueWritterFromAllInstances(e){return p([...this.inputs,...this.variableInstances.flatMap(s=>s.inputs)]).find(s=>x(s,this.project)===x(e,this.project)&&!!s.readsValue)||e}inferDataTypeAndSyncInstancesInputsAndOutputs(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"infer-data-type-and-sync-instances-inputs-and-outputs"))){var M,g,B,G;const t=[],i=[],s=[],l=[];if(!this.dataType){const q=C({id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.DataType,parentRelationType:null,implementationChooseOne:!1,options:null,isList:!1,andChildrenGroup:null,orChildrenGroup:null,staticEntities:null,interactiveEntities:null,actionEntities:!1,asType:!1,entity:null,like:!0,inferred:!0,parent:this.toReference()},this.project);this.setDataType(q),q.setParent(this,e),q.initChildren(e),e==null||e.add(q,b.Added),q.metaSync({inferred:!0,like:!0},e)}if(this.readsValue){const q=(M=this.readsValue.getDataType(e))==null?void 0:M.clone(e);if(q){const W=(g=this.dataType)==null?void 0:g.merge(q,e);this.dataType&&(W==null?void 0:W.self.id)!==this.dataType.id&&this.dataType.remove({ignoreUpstream:!1},e),q.id!==((B=W==null?void 0:W.self)==null?void 0:B.id)&&q.remove({ignoreUpstream:!1},e),W!=null&&W.self&&(W.self.metaSync({inferred:!0,like:!0},e),e==null||e.add(W.self,b.Added),this.setDataType(W.self))}return e==null||e.attemptAutoclose("infer-data-type-and-sync-instances-inputs-and-outputs",this.id),{updated:p(i),added:p(t),removed:p(s),affected:p(l),self:this}}const o=p([...this.inputs,...this.variableInstances.flatMap(q=>q.inputs)]),d=[];if(o.forEach(q=>{d.find(X=>x(X,this.project)===x(q,this.project))||d.push(q)}),!d.length)return e==null||e.attemptAutoclose("infer-data-type-and-sync-instances-inputs-and-outputs",this.id),{updated:p(i),added:p(t),removed:p(s),affected:p(l),self:this};if((G=this.dataType)==null||G.inferFromInputs(d,e),!this.dataType)return e==null||e.attemptAutoclose("infer-data-type-and-sync-instances-inputs-and-outputs",this.id),{updated:p(i),added:p(t),removed:p(s),affected:p(l),self:this};const{updated:u,added:y,removed:c,affected:E}=this.generateUnusedInputs(e);t.push(...y),i.push(...u),s.push(...c),l.push(...E);const{updated:I,added:O,removed:P,affected:V}=this.generateUnusedOutputs(e);return t.push(...O),i.push(...I),s.push(...P),l.push(...V),this.variableInstances.forEach(q=>{const{updated:W,added:X,removed:pe,affected:Ee}=q.generateUnusedInputs(e);t.push(...X),i.push(...W),s.push(...pe),l.push(...Ee);const{updated:Q,added:le,removed:ri,affected:tr}=q.generateUnusedOutputs(e);t.push(...le),i.push(...Q),s.push(...ri),l.push(...tr)}),e==null||e.attemptAutoclose("infer-data-type-and-sync-instances-inputs-and-outputs",this.id),{updated:p(i),added:p(t),removed:p(s),affected:p(l),self:this}}metaSync(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"meta-sync"))){const i=ct(this,e),s=this.toMeta();return this.name=e.name!==void 0?e.name:s.name,this.description=e.description!==void 0?e.description:s.description,this.x=e.x||s.x,this.y=e.y||s.y,this.constant=e.constant!==void 0?e.constant:s.constant,this.required=e.required!==void 0?e.required:s.required,super.metaSync(e),e.deleted===!0&&!s.deleted?t==null||t.add(this,b.Removed):e.deleted===!1&&s.deleted?t==null||t.add(this,b.Added):i&&(t==null||t.add(this,b.Updated)),t==null||t.attemptAutoclose("meta-sync",this.id),this}async APILoad(e=U,...t){return await Ve.repository.APILoad(this.id,...t),this}async APICreate(e=U,...t){return await Ve.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=U,...t){return await Ve.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=U,...t){return await Ve.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=U,...t){return await Ve.repository.APIClone(this.id,...t),this}async APILoadVersion(e=U,t,...i){return await Ve.repository.APILoadVersion(this.id,t,...i)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-entity"))){const i=[],s=[],l=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(s.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(d=>{const{updated:u,removed:y,added:c}=d.entity.onDetachedDependencyRemoved(this,d.field,t);i.push(...u),s.push(...y),l.push(...c)}),this.defaultValue){const{updated:d,removed:u}=this.defaultValue.remove({ignoreUpstream:!0},t);i.push(...d),s.push(...u)}if(this.readsValue&&(i.push(this.readsValue),this.readsValue.removeValueReader(this,t)),this.writesValues.forEach(d=>{i.push(d),d.setValueWriter(null,t)}),this.inputs.forEach(d=>{const{updated:u,removed:y}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...y)}),this.outputs.forEach(d=>{const{updated:u,removed:y}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...y)}),this.successCalls.forEach(d=>{i.push(d),d.removeCaller(this,t)}),this.errorCalls.forEach(d=>{i.push(d),d.removeCaller(this,t)}),this.internalCalls.forEach(d=>{const{updated:u,removed:y}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...y)}),this.dataType){const{updated:d,removed:u}=this.dataType.remove({ignoreUpstream:!0},t);i.push(...d),s.push(...u)}return e||this.calledBy.forEach(d=>{i.push(d),d.removeCall(this,t)}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:p(l),updated:p(i),removed:p(s),affected:p(o),self:this}}restore({}={},e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"restore-entity"))){const t=[],i=[],s=[],l=[];if(e!=null&&e.hasAdded(this.id))return e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),Object.values(this.detachedDependents).forEach(o=>{const{updated:d,removed:u,added:y}=o.entity.onDetachedDependencyRestored(this,o.field,e);i.push(...d),s.push(...u),t.push(...y)}),this.defaultValue){const{updated:o}=this.defaultValue.restore({},e);i.push(...o)}if(this.readsValue&&(i.push(this.readsValue),this.readsValue.addValueReader(this,e)),this.writesValues.forEach(o=>{i.push(o),o.setValueWriter(this,e)}),this.inputs.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.outputs.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.successCalls.forEach(o=>{i.push(o),o.addSuccessCaller(this,e)}),this.errorCalls.forEach(o=>{i.push(o),o.addErrorCaller(this,e)}),this.internalCalls.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.dataType){const{updated:o}=this.dataType.restore({},e);i.push(...o)}return this.calledBySuccess.forEach(o=>{i.push(o),o.addSuccessCall(this,e)}),this.calledByError.forEach(o=>{i.push(o),o.addErrorCall(this,e)}),this.calledByEntry.forEach(o=>{i.push(o),o.addCall(this,e)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(l),self:this}}toFlat(e=new Set){var i,s,l;return e.has(this.id)?[]:(e.add(this.id),[this,...((i=this.defaultValue)==null?void 0:i.toFlat(e))||[],...((s=this.dataType)==null?void 0:s.toFlat(e))||[],...((l=this.readsValue)==null?void 0:l.toFlat(e))||[],...this.writesValues.flatMap(o=>o.toFlat(e)),...this.successCalls.flatMap(o=>o.toFlat(e)),...this.errorCalls.flatMap(o=>o.toFlat(e)),...this.inputs.flatMap(o=>o.toFlat(e)),...this.outputs.flatMap(o=>o.toFlat(e)),...this.internalCalls.flatMap(o=>o.toFlat(e)),...this.calledBy.flatMap(o=>o.toFlat(e))])}toFlatIds(e=new Set){var i,s;return e.has(this.id)?[]:(e.add(this.id),[this.id,...((i=this.defaultValue)==null?void 0:i.toFlatIds(e))||[],...((s=this.dataType)==null?void 0:s.toFlatIds(e))||[],...this.writesValues.flatMap(l=>l.toFlatIds(e)),...this.successCalls.flatMap(l=>l.toFlatIds(e)),...this.errorCalls.flatMap(l=>l.toFlatIds(e)),...this.inputs.flatMap(l=>l.toFlatIds(e)),...this.outputs.flatMap(l=>l.toFlatIds(e)),...this.internalCalls.flatMap(l=>l.toFlatIds(e))])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,description:this.description,required:this.required,constant:this.constant,x:this.x,y:this.y,type:this.type,name:this.name}}toJSON(e=new Set){var t,i,s;return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,constant:this.constant,required:this.required,defaultValue:((t=this.defaultValue)==null?void 0:t.toJSON(e))||null,dataType:((i=this.dataType)==null?void 0:i.toJSON(e))||null,readsValue:((s=this.readsValue)==null?void 0:s.toReference())||null,writesValues:this.writesValues.map(l=>l.toJSON(e)),inputs:this.inputs.map(l=>l.toJSON(e)),outputs:this.outputs.map(l=>l.toJSON(e)),successCalls:this.successCalls.map(l=>l.toJSON(e)),errorCalls:this.errorCalls.map(l=>l.toJSON(e)),internalCalls:this.internalCalls.map(l=>l.toJSON(e)),calledBySuccess:this.calledBySuccess.map(l=>l.toReference()),calledByError:this.calledByError.map(l=>l.toReference()),calledByEntry:this.calledByEntry.map(l=>l.toReference()),parent:this.parent.toReference(),x:this.x,y:this.y})}toJSONClone(e=J){var i,s,l,o,d,u,y,c;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||ht(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(s=e.seenEntities)!=null&&s.has(t)||(l=e.seenEntities)!=null&&l.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(d=e.seenEntities)==null||d.add(this.id),{id:t,version:m.UUID.uuid(),createdAt:e.timestamp||T().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,defaultValue:((u=this.defaultValue)==null?void 0:u.toJSONClone({...e,newId:null}))||null,dataType:((y=this.dataType)==null?void 0:y.toJSONClone({...e,newId:null}))||null,readsValue:((c=this.readsValue)==null?void 0:c.toReference({seenEntityMaps:e.seenEntityMaps}))||null,writesValues:this.writesValues.map(E=>E.toJSONClone({...e,newId:null})),inputs:this.inputs.map(E=>E.toJSONClone({...e,newId:null})),outputs:this.outputs.map(E=>E.toJSONClone({...e,newId:null})),successCalls:this.successCalls.map(E=>E.toJSONClone({...e,newId:null})),errorCalls:this.errorCalls.map(E=>E.toJSONClone({...e,newId:null})),internalCalls:this.internalCalls.map(E=>this.calledBy.length||this.readsValue?E.toJSONClone({...e,newId:null}):E.toReference({seenEntityMaps:e.seenEntityMaps})),calledBySuccess:this.calledBySuccess.map(E=>E.toReference({seenEntityMaps:e.seenEntityMaps})),calledByError:this.calledByError.map(E=>E.toReference({seenEntityMaps:e.seenEntityMaps})),calledByEntry:this.calledByEntry.map(E=>E.toReference({seenEntityMaps:e.seenEntityMaps})),parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps}),x:this.x,y:this.y})}toReference(e=J){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+m.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=J){var i,s,l,o;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,required:this.required,constant:this.constant,x:this.x,y:this.y,defaultValue:((s=this.defaultValue)==null?void 0:s.toReference(e))||null,dataType:((l=this.dataType)==null?void 0:l.toReference(e))||null,readsValue:((o=this.readsValue)==null?void 0:o.toReference(e))||null,writesValues:this.writesValues.map(d=>d.toReference(e)),inputs:this.inputs.map(d=>d.toReference(e)),outputs:this.outputs.map(d=>d.toReference(e)),successCalls:this.successCalls.map(d=>d.toReference(e)),errorCalls:this.errorCalls.map(d=>d.toReference(e)),calledBySuccess:this.calledBySuccess.map(d=>d.toReference(e)),calledByError:this.calledByError.map(d=>d.toReference(e)),calledByEntry:this.calledByEntry.map(d=>d.toReference(e)),internalCalls:this.internalCalls.map(d=>d.toReference(e)),parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){var i,s;return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...((i=this.defaultValue)==null?void 0:i.toFlatJSON(e))||[],...((s=this.dataType)==null?void 0:s.toFlatJSON(e))||[],...this.writesValues.flatMap(l=>l.toFlatJSON(e)),...this.successCalls.flatMap(l=>l.toFlatJSON(e)),...this.errorCalls.flatMap(l=>l.toFlatJSON(e)),...this.inputs.flatMap(l=>l.toFlatJSON(e)),...this.outputs.flatMap(l=>l.toFlatJSON(e)),...this.internalCalls.flatMap(l=>l.toFlatJSON(e))])}toGenerationTarget(){const e=this.parent.type===n.Project?void 0:this.parent.id;return{id:this.id,type:this.type,name:this.name,description:this.description,calledByEntry:this.calledByEntry.map(t=>t.id),calledBySuccess:this.calledBySuccess.map(t=>t.id),calledByError:this.calledByError.map(t=>t.id),parent:e}}toFlatGenerationTarget(e=new Set){var i,s;return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...((i=this.defaultValue)==null?void 0:i.toFlatGenerationTarget(e))||[],...((s=this.dataType)==null?void 0:s.toFlatGenerationTarget(e))||[],...this.writesValues.flatMap(l=>l.toFlatGenerationTarget(e)),...this.successCalls.flatMap(l=>l.toFlatGenerationTarget(e)),...this.errorCalls.flatMap(l=>l.toFlatGenerationTarget(e)),...this.inputs.flatMap(l=>l.toFlatGenerationTarget(e)),...this.outputs.flatMap(l=>l.toFlatGenerationTarget(e)),...this.internalCalls.flatMap(l=>l.toFlatGenerationTarget(e))])}clearErrors(){var e,t;return this.errors=[],this.inputs.forEach(i=>i.clearErrors()),this.outputs.forEach(i=>i.clearErrors()),this.successCalls.forEach(i=>i.clearErrors()),this.errorCalls.forEach(i=>i.clearErrors()),this.internalCalls.forEach(i=>i.clearErrors()),(e=this.dataType)==null||e.clearErrors(),(t=this.defaultValue)==null||t.clearErrors(),this}validate(){const e=A1(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){var t,i,s;return[...this.errors,...((t=this.defaultValue)==null?void 0:t.getErrors())||[],...((i=this.dataType)==null?void 0:i.getErrors())||[],...this.inputs.flatMap(l=>l.getErrors()),...this.internalCalls.flatMap(l=>l.getErrors()),...this.outputs.flatMap(l=>l.getErrors()),...((s=this.readsValue)==null?void 0:s.getErrors())||[]]}getShallowErrors(){return this.errors}getDefaultValue(){return this.defaultValue||null}setDefaultValue(e){return this.defaultValue=e,this}clone(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"clone-entity")),t=null,i=null,s=!0){var P,V,M,g,B;let l=mt(t,this);const o=this.toJSON(),d=i||m.UUID.uuid();o.inputs=[],o.id=d,o.version=m.UUID.uuid(),o.createdAt=(e==null?void 0:e.timestamp)||T().toISOString(),o.author=(e==null?void 0:e.author)||"1",o.previousVersion=null,o.deleted=!1;const u=nt(o,l);t?u.setParent(t,null):u.setParent(this.parent,null),s&&u.subscribe(),u.initChildren(e),e==null||e.add(u,b.Added);const y=(P=this.dataType)==null?void 0:P.clone(e,u,m.UUID.uuid(),s);u.dataType=y||null;const c=(V=this.defaultValue)==null?void 0:V.clone(e,u,m.UUID.uuid(),s);u.defaultValue=c||null;const E=(M=this.inputs)==null?void 0:M.map(G=>G.clone(e,u,m.UUID.uuid(),s));u.inputs=E;const I=(g=this.outputs)==null?void 0:g.map(G=>G.clone(e,u,m.UUID.uuid(),s));u.outputs=I;const O=(B=this.internalCalls)==null?void 0:B.map(G=>G.clone(e,u,m.UUID.uuid(),s));return u.internalCalls=O,e==null||e.attemptAutoclose("clone-entity",this.id),u}addInternalCall(e){return this.internalCalls.find(t=>t===e)||this.internalCalls.push(e),this}createInstance(e=this.project,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"create-instance")),i={}){const s={id:i.id||m.UUID.uuid(),version:i.version||m.UUID.uuid(),createdAt:(t==null?void 0:t.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.VariableInstance,parent:e.toReference(),defaultValue:i.defaultValue||null,successCalls:i.successCalls||[],errorCalls:i.errorCalls||[],inputs:i.inputs||[],outputs:i.outputs||[],writesValues:i.writesValues||[],internalCalls:i.internalCalls||[],readsValue:i.readsValue||null,calledByEntry:i.calledByEntry||[],calledBySuccess:i.calledBySuccess||[],calledByError:i.calledByError||[],declaration:this.toJSON(),x:0,y:0},l=C(s,this.project);return l.setParent(e,null),l.initChildren(null),t==null||t.add(l,b.Added),e===this.project&&this.project.addVariableInstance(l),t==null||t.attemptAutoclose("create-instance",this.id),l}generateUnusedInputs(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"generate-unused-inputs"))){const t=[],i=[],s=[],l=[];if(this.dataType)if(this.dataType.entity){if([n.DefinitionEntity,n.PrimitiveEntity,n.BuiltInBaseEntity].includes(this.dataType.entity.type)){const o=[...this.dataType.entity.properties];o.filter(c=>!c.getDataType(e)).forEach(c=>{const E=this.inputs.find(P=>x(P,this.project)===x(c,this.project));if(!E)return;const I=this.getMasterInputWithValueWritterFromAllInstances(E);if(!I)return;const O=ji(I);c.setDataType(O),E.setDeclaration(c)}),o.filter(c=>!this.inputs.find(E=>{var I;return((I=E.declaration)==null?void 0:I.id)===c.id})).forEach(c=>{const E={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.InputMap,parent:this.toReference(),name:null,description:null,declaration:c,defaultValue:null,index:c.index,readsValue:null},I=C(E,this.project);return I.setParent(this,e),I.initChildren(e),e==null||e.add(I,b.Added),I.suggestion=!0,this.addInput(I,e),I}),this.inputs.filter(c=>!c.declaration).forEach(c=>{const E=o.find(I=>x(I,this.project)===x(c,this.project));E&&c.setDeclaration(E)})}}else return e==null||e.attemptAutoclose("generate-unused-inputs",this.id),{added:[],updated:[],removed:[],affected:[],self:this};else return e==null||e.attemptAutoclose("generate-unused-inputs",this.id),{added:[],updated:[],removed:[],affected:[],self:this};return e==null||e.attemptAutoclose("generate-unused-inputs",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(l),self:this}}generateUnusedOutputs(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"generate-unused-outputs"))){const t=[],i=[],s=[],l=[];if(this.dataType)if(this.dataType.entity)[n.DefinitionEntity,n.PrimitiveEntity,n.BuiltInBaseEntity].includes(this.dataType.entity.type)&&[...this.dataType.entity.properties].filter(u=>!this.outputs.find(y=>y.declaration===u)).map(u=>{const y={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.OutputMap,defaultValue:null,parent:this.toReference(),declaration:u,index:u.index,writesValues:[]},c=C(y,this.project);return c.setParent(this,e),c.initChildren(e),e==null||e.add(c,b.Added),c.suggestion=!0,this.addOutput(c,e),c});else return e==null||e.attemptAutoclose("generate-unused-outputs",this.id),{added:[],updated:[],removed:[],affected:[],self:this};else return e==null||e.attemptAutoclose("generate-unused-outputs",this.id),{added:[],updated:[],removed:[],affected:[],self:this};return e==null||e.attemptAutoclose("generate-unused-outputs",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(l),self:this}}generateUnusedInternalCalls(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"generate-unused-internal-calls"))){const t=[],i=[],s=[],l=[];if(this.dataType)if(this.dataType.entity)[n.DefinitionEntity,n.PrimitiveEntity,n.BuiltInBaseEntity].includes(this.dataType.entity.type)&&[...this.dataType.entity.getAllInteractiveMethods()].filter(u=>!this.internalCalls.find(c=>{var I,O,P,V,M;return(((I=c.declaration)==null?void 0:I.id)||((P=(O=c.initialData)==null?void 0:O.declaration)==null?void 0:P.entityId)||((M=(V=c.initialData)==null?void 0:V.declaration)==null?void 0:M.id))===u.id})).map(u=>{const y=u.createInternalCall(e,this);return e==null||e.add(y,b.Added),y.suggestion=!0,this.addInternalCall(y),y});else return e==null||e.attemptAutoclose("generate-unused-internal-calls",this.id),{added:[],updated:[],removed:[],affected:[],self:this};else return e==null||e.attemptAutoclose("generate-unused-internal-calls",this.id),{added:[],updated:[],removed:[],affected:[],self:this};return e==null||e.attemptAutoclose("generate-unused-internal-calls",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(l),self:this}}setDataType(e){return this.dataType=e,this}removeDataType(){return this.dataType=null,this}getDataType(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"get-data-type"))){return(!this.dataType||this.dataType.inferred)&&this.inferDataTypeAndSyncInstancesInputsAndOutputs(e),this.dataType||null}getUnusedInputs(){return this.inputs.filter(e=>e.suggestion||!e.readsValue&&!e.defaultValue)}getUnusedOutputs(){return this.outputs.filter(e=>e.suggestion||!e.writesValues.length)}getUsedInputs(){return this.inputs.filter(e=>!e.suggestion&&(e.readsValue||e.defaultValue))}getUsedOutputs(){return this.outputs.filter(e=>!e.suggestion&&e.writesValues.length)}};f(Ve,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>e,APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...i)=>null}),f(Ve,"type",n.VariableDeclaration),f(Ve,"USER_MANAGED_PARENT_TYPES",[...ut,n.Project]),f(Ve,"PARENT_TYPES",[...Ve.USER_MANAGED_PARENT_TYPES]),f(Ve,"MUTABLE_BASE_PROPERTIES",["name","description","constant","required"]),f(Ve,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),f(Ve,"BASE_PROPERTIES",[...Ve.MUTABLE_BASE_PROPERTIES,...Ve.INMUTABLE_BASE_PROPERTIES]),f(Ve,"MUTABLE_META_PROPERTIES",[...Ve.MUTABLE_BASE_PROPERTIES,"x","y"]),f(Ve,"INMUTABLE_META_PROPERTIES",[...Ve.INMUTABLE_BASE_PROPERTIES]),f(Ve,"META_PROPERTIES",[...Ve.MUTABLE_META_PROPERTIES,...Ve.INMUTABLE_META_PROPERTIES]),f(Ve,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry","readsValue"]),f(Ve,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","dataType"]),f(Ve,"UPSTREAM_PROPERTIES",[...Ve.MUTABLE_UPSTREAM_PROPERTIES,...Ve.INMUTABLE_UPSTREAM_PROPERTIES]),f(Ve,"MUTABLE_DOWNSTREAM_PROPERTIES",["writesValues","inputs","outputs","successCalls","errorCalls","internalCalls"]),f(Ve,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),f(Ve,"DOWNSTREAM_PROPERTIES",[...Ve.MUTABLE_DOWNSTREAM_PROPERTIES,...Ve.INMUTABLE_DOWNSTREAM_PROPERTIES]),f(Ve,"PROPERTIES",[...Ve.META_PROPERTIES,...Ve.UPSTREAM_PROPERTIES,...Ve.DOWNSTREAM_PROPERTIES]);let Yr=Ve;function D1(r){var l;const a=J5(),e=r.toJSON();a.safeParse(e).success,r.inputsDeclarations.forEach(o=>o.validate()),r.inputs.forEach(o=>o.validate()),r.outputsDeclarations.forEach(o=>o.validate()),r.outputs.forEach(o=>o.validate()),(l=r.error)==null||l.validate();const s=[...Ar(r)];if(r.id==="search-person-by-id-id"){const o=de({id:`${r.id}--${F.PropertyImplementsNonAbstact}`,message:`Property "${x(r,r.project)}" with id "${r.id}" implements a non-abstract property "${x(r,r.project)}" with id "${r.id}".`,issue:null,severity:D.Error,code:F.PropertyImplementsNonAbstact,entity:r});s.push(o.error)}return Ke(r.errors,s)}const SJ=Object.freeze(Object.defineProperty({__proto__:null,validate:D1},Symbol.toStringTag,{value:"Module"}));var O1=(r=>(r.Parent="parent",r))(O1||{});const We=class We extends lt{constructor(e,t){super(e);f(this,"initialData");f(this,"id");f(this,"name");f(this,"description",null);f(this,"x");f(this,"y");f(this,"query","");f(this,"type",n.Search);f(this,"successCalls",[]);f(this,"errorCalls",[]);f(this,"inputsDeclarations",[]);f(this,"inputs",[]);f(this,"outputsDeclarations",[]);f(this,"outputs",[]);f(this,"calledBySuccess",[]);f(this,"calledByError",[]);f(this,"calledByEntry",[]);f(this,"error",null);f(this,"parent");f(this,"errors",[]);f(this,"project");f(this,"detachedDependents",{});f(this,"knownVersions",null);f(this,"activeVersion",!1);f(this,"initialized",!1);f(this,"startedInitialization",!1);this.initialData=e,this.project=t,this.id=e.id,this.x=e.x,this.y=e.y,this.name=e.name,this.query=e.query,this.description=e.description}static new(e=null){return{id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:(e==null?void 0:e.author)||m.sessionAuthor,previousVersion:null,deleted:!1,type:n.Search,name:"",description:"",inputsDeclarations:[],outputsDeclarations:[],inputs:[],outputs:[],query:"",error:null,parent:null,calledByEntry:[],calledBySuccess:[],calledByError:[],errorCalls:[],successCalls:[],x:0,y:0}}static fromGenerationTarget(e,t){let i=t;if(e.parent){const y=_(e.parent);i=t.get(y)}const s=e.calledByEntry.map(y=>{const c=_(y);return t.get(c)}),l=e.calledBySuccess.map(y=>{const c=_(y);return t.get(c)}),o=e.calledByError.map(y=>{const c=_(y);return t.get(c)}),d={id:e.id,version:m.UUID.uuid(),createdAt:T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.Search,name:e.name,description:e.description,query:e.query,calledByEntry:s,calledBySuccess:l,calledByError:o,errorCalls:[],successCalls:[],inputsDeclarations:[],inputs:[],outputsDeclarations:[],outputs:[],error:null,x:0,y:0,parent:i},u=C(d,t);return u.setParent(i,null),u.initChildren(null),u}static validateGenerationTarget(e,t){let i=JSON.parse(JSON.stringify(e));const s=[],l=bt(i,{parent:{list:!1,types:[...ut,n.Project],optional:!0}},t);return i=l.modifiedData,s.push(...l.errors,...pt(i)),{errors:s,modifiedData:i}}get resultsAsList(){const e=this.outputsDeclarations[0];if(e){const t=e.getDataType(null);return t?t.isList===!0:!0}return!0}validateGeneratedUpdate(e){const t=[];return e.parent&&t.push(new w({id:`${this.id}--${R.InvalidParentUpdate}`,code:R.InvalidParentUpdate,severity:D.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.
109
+ You shouldn't have to manually update a 'parent' property. The equivalent result is to change its value readers, value writters, or callers.`,issue:null})),{errors:t,modifiedData:i}}subscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]||(this.detachedDependents[t.entity.id]=t)}),this}syncDependents(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-dependents"))){const t=[],i=[],s=[],l=[];return Object.values(this.detachedDependents).forEach(o=>{const d=o.entity.afterAllChildrenInitialized(e);t.push(...d.updated),i.push(...d.added),s.push(...d.removed),l.push(...d.affected)}),e==null||e.attemptAutoclose("sync-dependents",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];if(t==="parent"){const{updated:u,added:y,removed:c}=this.remove({ignoreUpstream:!1},i);s.push(...u),l.push(...y),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}onDetachedDependencyRestored(e,t,i){const s=[],l=[],o=[],d=[];if(t==="parent"){const{updated:u,added:y,removed:c}=this.restore({},i);s.push(...u),l.push(...y),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}subscribeToDependencies(){var e,t,i,s;return(e=this.parent)==null||e.subscribeDependents([{entity:this,field:"parent"}]),(s=(i=(t=this.dataType)==null?void 0:t.entity)==null?void 0:i.subscribeDependents)==null||s.call(i,[{entity:this,field:"data-type-entity"}]),this}increaseVersion(e){if(e&&!T(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&T(e).isSame(T(this.createdAt))?this:(this.previousVersion=this.version,this.version=m.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new Ve(this,this.project);return e.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,e):new Map([[this.version,e]]),e.inputs=this.inputs,e.outputs=this.outputs,e.internalCalls=this.internalCalls,e.successCalls=this.successCalls,e.errorCalls=this.errorCalls,e.writesValues=this.writesValues,e.readsValue=this.readsValue,e.defaultValue=this.defaultValue,e.dataType=this.dataType,e.calledBySuccess=this.calledBySuccess,e.calledByError=this.calledByError,e.calledByEntry=this.calledByEntry,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],i=[],s=[],l=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),i.push(...o.added),s.push(...o.removed)}return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}async restoreVersion(e){var d;const t=[],i=[],s=[],l=[];if(this.version===e)return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this};if(!this.knownVersions){const u=new Map;for(const[y,c]of this.knownVersions||new Map){if(u.set(y,c),c.activeVersion=!1,c.knownVersions)for(const[E,I]of c.knownVersions)u.set(E,I);c.knownVersions=null}}let o=(d=this.knownVersions)==null?void 0:d.get(e);if(!o){const u=await this.APILoadVersion({},e);if(!u)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new Ve(u,this.project)}return this.metaSync(o.toShallowJSON(),null),this.inputs=o.inputs,this.outputs=o.outputs,this.internalCalls=o.internalCalls,this.successCalls=o.successCalls,this.errorCalls=o.errorCalls,this.writesValues=o.writesValues,this.readsValue=o.readsValue,this.defaultValue=o.defaultValue,this.dataType=o.dataType,this.calledBySuccess=o.calledBySuccess,this.calledByError=o.calledByError,this.calledByEntry=o.calledByEntry,this.parent=o.parent,{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}hydrateAncestors(){const e=[],t=[],i=[],s=[];if(this.initialData.parent){const l=_(this.initialData.parent),o=this.project.get(l);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(this.initialData.readsValue){const l=_(this.initialData.readsValue),o=this.project.get(l);o&&(this.setValueWriter(o,null),e.push(o))}return this.initialData.calledByEntry.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addEntryCaller(d,null),d.addCall(this,null),e.push(d))}),this.initialData.calledBySuccess.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addSuccessCaller(d,null),d.addSuccessCall(this,null),e.push(d))}),this.initialData.calledByError.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addErrorCaller(d,null),d.addErrorCall(this,null),e.push(d))}),Rr.hydrateReadsValue(this),{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],i=[],s=[],l=[];this.initialized=!0;const{added:o,updated:d,removed:u,affected:y}=this.generateUnusedInputs(e);i.push(...o),t.push(...d),s.push(...u),l.push(...y);const{added:c,updated:E,removed:I,affected:O}=this.generateUnusedOutputs(e);i.push(...c),t.push(...E),s.push(...I),l.push(...O);const{added:P,updated:V,removed:M,affected:g}=this.generateUnusedInternalCalls(e);if(i.push(...P),t.push(...V),s.push(...M),l.push(...g),!this.dataType||this.dataType.inferred){const{added:B,updated:G,removed:q,affected:W}=this.inferDataTypeAndSyncInstancesInputsAndOutputs(e);i.push(...B),t.push(...G),s.push(...q),l.push(...W)}return this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addSelfToProject(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-self-to-project"))){const t=[this],i=[],s=[],l=[];return this.parent===this.project&&this.project.addVariableDeclaration(this),this.readsValue&&(this.readsValue.addValueReader(this,e),t.push(this.readsValue)),this.writesValues.forEach(o=>{o.setValueWriter(this,e),t.push(o)}),this.successCalls.forEach(o=>{o.addSuccessCaller(this,e),t.push(o)}),this.errorCalls.forEach(o=>{o.addErrorCaller(this,e),t.push(o)}),this.calledBySuccess.forEach(o=>{o.addSuccessCall(this,e),t.push(o)}),this.calledByError.forEach(o=>{o.addErrorCall(this,e),t.push(o)}),this.calledByEntry.forEach(o=>{o.addCall(this,e),t.push(o)}),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}get usedInputs(){return this.inputs.filter(e=>e.readsValue||e.defaultValue)}get unusedInputs(){return this.inputs.filter(e=>!e.readsValue&&!e.defaultValue)}get usedOutputs(){return this.outputs.filter(e=>e.writesValues.length)}get unusedOutputs(){return this.outputs.filter(e=>!e.writesValues.length)}get usedInternalCalls(){return this.internalCalls.filter(e=>!!e.calledBy.length)}get unusedInternalCalls(){return this.internalCalls.filter(e=>!e.calledBy.length)}removeInput(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-input"))){const i=this.inputs.findIndex(s=>s.id===e.id);return i>-1&&(this.inputs.splice(i,1),t&&(t==null||t.add(this,b.Affected))),t==null||t.attemptAutoclose("remove-input",this.id),this}addInput(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-input"))){return this.inputs.includes(e)?(t==null||t.attemptAutoclose("add-input",this.id),this):(this.inputs.push(e),t==null||t.add(this,b.Affected),t==null||t.attemptAutoclose("add-input",this.id),this)}addOutput(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-output"))){return this.outputs.includes(e)?(t==null||t.attemptAutoclose("add-output",this.id),this):(this.outputs.push(e),t==null||t.add(this,b.Affected),t==null||t.attemptAutoclose("add-output",this.id),this)}removeOutput(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-output"))){const i=this.outputs.findIndex(s=>s.id===e.id);return i>-1&&(this.outputs.splice(i,1),t&&(t==null||t.add(this,b.Affected))),t==null||t.attemptAutoclose("remove-output",this.id),this}addSuccessCaller(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-success-caller")),i=!1){return this.calledBySuccess.find(s=>s.id===e.id)||(this.calledBySuccess.push(e),t==null||t.add(this,b.Updated),i&&K(this,t)),t==null||t.attemptAutoclose("add-success-caller",this.id),this}addErrorCaller(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-error-caller")),i=!1){return this.calledByError.find(s=>s.id===e.id)||(this.calledByError.push(e),t==null||t.add(this,b.Updated),i&&K(this,t)),t==null||t.attemptAutoclose("add-error-caller",this.id),this}addEntryCaller(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-entry-caller")),i=!1){return this.calledByEntry.find(s=>s.id===e.id)||(this.calledByEntry.push(e),t==null||t.add(this,b.Updated),i&&K(this,t)),t==null||t.attemptAutoclose("add-entry-caller",this.id),this}addErrorCall(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-error-call")),i=!1){return this.errorCalls.find(s=>s.id===e.id)||(this.errorCalls.push(e),i&&K(this,t),t==null||t.add(this,b.Affected)),t==null||t.attemptAutoclose("add-error-call",this.id),this}addSuccessCall(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-success-call")),i=!1){return this.successCalls.find(s=>s.id===e.id)||(this.successCalls.push(e),i&&K(this,t),t==null||t.add(this,b.Affected)),t==null||t.attemptAutoclose("add-success-call",this.id),this}removeCall(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-call")),i=!1){const s=this.successCalls.findIndex(o=>o.id===e.id);s>-1&&(this.successCalls.splice(s,1),t==null||t.add(this,b.Affected));const l=this.errorCalls.findIndex(o=>o.id===e.id);return l>-1&&(this.errorCalls.splice(l,1),t==null||t.add(this,b.Affected)),i&&K(this,t),t==null||t.attemptAutoclose("remove-call",this.id),this}removeCaller(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-caller")),i=!1){return this.calledBySuccess=this.calledBySuccess.filter(s=>s.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(s,b.Affected)),!0):!1),this.calledByError=this.calledByError.filter(s=>s.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(s,b.Affected)),!0):!1),this.calledByEntry=this.calledByEntry.filter(s=>s.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(s,b.Affected)),!0):!1),i&&K(this,t),t==null||t.attemptAutoclose("remove-caller",this.id),this}addValueReader(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-value-reader"))){return this.writesValues.includes(e)?(t==null||t.attemptAutoclose("add-value-reader",this.id),this):(this.writesValues.push(e),t==null||t.add(this,b.Affected),this)}removeValueReader(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-value-reader"))){return this.writesValues.includes(e)?(this.writesValues=this.writesValues.filter(i=>i.id!==e.id),t==null||t.add(this,b.Affected),this):(t==null||t.attemptAutoclose("remove-value-reader",this.id),this)}setParent(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"set-parent"))){var i;return((i=this.parent)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,b.Updated),t==null||t.attemptAutoclose("set-parent",this.id))),this}initChildren(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.initialData.defaultValue&&(this.defaultValue=C(this.initialData.defaultValue,this.project),this.defaultValue.setParent(this,null),this.defaultValue.initChildren(e)),this.initialData.dataType&&(this.dataType=C(this.initialData.dataType,this.project),this.dataType.setParent(this,null),this.dataType.initChildren(e)),xa.initWritesValues(this,this.parent),Rr.initReadsValue(this),this.successCalls=this.initialData.successCalls.map(t=>{const i=C(t,this.project);if(i.addSuccessCaller(this),[n.BreakStatement,n.ContinueStatement].includes(i.type))i.setParent(this.parent.parent,null),i.initChildren(e);else if(i.type===n.ReturnStatement){const s=It(this,this.project);i.setParent(s,null),i.initChildren(e)}else i.type!==n.InternalCall&&(i.setParent(this.parent,null),i.initChildren(e));return i}),this.errorCalls=this.initialData.errorCalls.map(t=>{const i=C(t,this.project);if(i.addErrorCaller(this),[n.BreakStatement,n.ContinueStatement].includes(i.type))i.setParent(this.parent.parent,null),i.initChildren(e);else if(i.type===n.ReturnStatement){const s=It(this,this.project);i.setParent(s,null),i.initChildren(e)}else i.type!==n.InternalCall&&(i.setParent(this.parent,null),i.initChildren(e));return i}),this.initialData.inputs.forEach(t=>{const i=C(t,this.project);return i.setParent(this,null),i.initChildren(e),this.addInput(i,null),i}),this.initialData.outputs.forEach(t=>{const i=C(t,this.project);return i.setParent(this,null),i.initChildren(e),this.addOutput(i,null),i}),this.initialData.internalCalls.forEach(t=>{if(t.type===n.GenericReference){const s=this.project.findSubscribedInstanceFromReference(t);if(!s)return;s.setParent(this,null),s.initChildren(e),this.addInternalCall(s);return}const i=C(t,this.project);return i.setParent(this,null),i.initChildren(e),this.addInternalCall(i),i}),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this)}setValueWriter(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"set-value-writer"))){return this.readsValue!==e&&(this.readsValue=e,t==null||t.add(this,b.Updated)),t==null||t.attemptAutoclose("set-value-writer",this.id),this}removeValueWriter(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-value-writer"))){return this.readsValue&&(this.readsValue=null,e==null||e.add(this,b.Updated)),e==null||e.attemptAutoclose("remove-value-writer",this.id),this}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}getMasterInputWithValueWritterFromAllInstances(e){return p([...this.inputs,...this.variableInstances.flatMap(s=>s.inputs)]).find(s=>x(s,this.project)===x(e,this.project)&&!!s.readsValue)||e}inferDataTypeAndSyncInstancesInputsAndOutputs(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"infer-data-type-and-sync-instances-inputs-and-outputs"))){var M,g,B,G;const t=[],i=[],s=[],l=[];if(!this.dataType){const q=C({id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.DataType,parentRelationType:null,implementationChooseOne:!1,options:null,isList:!1,andChildrenGroup:null,orChildrenGroup:null,staticEntities:null,interactiveEntities:null,actionEntities:!1,asType:!1,entity:null,like:!0,inferred:!0,parent:this.toReference()},this.project);this.setDataType(q),q.setParent(this,e),q.initChildren(e),e==null||e.add(q,b.Added),q.metaSync({inferred:!0,like:!0},e)}if(this.readsValue){const q=(M=this.readsValue.getDataType(e))==null?void 0:M.clone(e);if(q){const W=(g=this.dataType)==null?void 0:g.merge(q,e);this.dataType&&(W==null?void 0:W.self.id)!==this.dataType.id&&this.dataType.remove({ignoreUpstream:!1},e),q.id!==((B=W==null?void 0:W.self)==null?void 0:B.id)&&q.remove({ignoreUpstream:!1},e),W!=null&&W.self&&(W.self.metaSync({inferred:!0,like:!0},e),e==null||e.add(W.self,b.Added),this.setDataType(W.self))}return e==null||e.attemptAutoclose("infer-data-type-and-sync-instances-inputs-and-outputs",this.id),{updated:p(i),added:p(t),removed:p(s),affected:p(l),self:this}}const o=p([...this.inputs,...this.variableInstances.flatMap(q=>q.inputs)]),d=[];if(o.forEach(q=>{d.find(X=>x(X,this.project)===x(q,this.project))||d.push(q)}),!d.length)return e==null||e.attemptAutoclose("infer-data-type-and-sync-instances-inputs-and-outputs",this.id),{updated:p(i),added:p(t),removed:p(s),affected:p(l),self:this};if((G=this.dataType)==null||G.inferFromInputs(d,e),!this.dataType)return e==null||e.attemptAutoclose("infer-data-type-and-sync-instances-inputs-and-outputs",this.id),{updated:p(i),added:p(t),removed:p(s),affected:p(l),self:this};const{updated:u,added:y,removed:c,affected:E}=this.generateUnusedInputs(e);t.push(...y),i.push(...u),s.push(...c),l.push(...E);const{updated:I,added:O,removed:P,affected:V}=this.generateUnusedOutputs(e);return t.push(...O),i.push(...I),s.push(...P),l.push(...V),this.variableInstances.forEach(q=>{const{updated:W,added:X,removed:pe,affected:Ee}=q.generateUnusedInputs(e);t.push(...X),i.push(...W),s.push(...pe),l.push(...Ee);const{updated:Q,added:le,removed:ri,affected:tr}=q.generateUnusedOutputs(e);t.push(...le),i.push(...Q),s.push(...ri),l.push(...tr)}),e==null||e.attemptAutoclose("infer-data-type-and-sync-instances-inputs-and-outputs",this.id),{updated:p(i),added:p(t),removed:p(s),affected:p(l),self:this}}metaSync(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"meta-sync"))){const i=ct(this,e),s=this.toMeta();return this.name=e.name!==void 0?e.name:s.name,this.description=e.description!==void 0?e.description:s.description,this.x=e.x||s.x,this.y=e.y||s.y,this.constant=e.constant!==void 0?e.constant:s.constant,this.required=e.required!==void 0?e.required:s.required,super.metaSync(e),e.deleted===!0&&!s.deleted?t==null||t.add(this,b.Removed):e.deleted===!1&&s.deleted?t==null||t.add(this,b.Added):i&&(t==null||t.add(this,b.Updated)),t==null||t.attemptAutoclose("meta-sync",this.id),this}async APILoad(e=U,...t){return await Ve.repository.APILoad(this.id,...t),this}async APICreate(e=U,...t){return await Ve.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=U,...t){return await Ve.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=U,...t){return await Ve.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=U,...t){return await Ve.repository.APIClone(this.id,...t),this}async APILoadVersion(e=U,t,...i){return await Ve.repository.APILoadVersion(this.id,t,...i)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-entity"))){const i=[],s=[],l=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(s.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(d=>{const{updated:u,removed:y,added:c}=d.entity.onDetachedDependencyRemoved(this,d.field,t);i.push(...u),s.push(...y),l.push(...c)}),this.defaultValue){const{updated:d,removed:u}=this.defaultValue.remove({ignoreUpstream:!0},t);i.push(...d),s.push(...u)}if(this.readsValue&&(i.push(this.readsValue),this.readsValue.removeValueReader(this,t)),this.writesValues.forEach(d=>{i.push(d),d.setValueWriter(null,t)}),this.inputs.forEach(d=>{const{updated:u,removed:y}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...y)}),this.outputs.forEach(d=>{const{updated:u,removed:y}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...y)}),this.successCalls.forEach(d=>{i.push(d),d.removeCaller(this,t)}),this.errorCalls.forEach(d=>{i.push(d),d.removeCaller(this,t)}),this.internalCalls.forEach(d=>{const{updated:u,removed:y}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...y)}),this.dataType){const{updated:d,removed:u}=this.dataType.remove({ignoreUpstream:!0},t);i.push(...d),s.push(...u)}return e||this.calledBy.forEach(d=>{i.push(d),d.removeCall(this,t)}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:p(l),updated:p(i),removed:p(s),affected:p(o),self:this}}restore({}={},e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"restore-entity"))){const t=[],i=[],s=[],l=[];if(e!=null&&e.hasAdded(this.id))return e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),Object.values(this.detachedDependents).forEach(o=>{const{updated:d,removed:u,added:y}=o.entity.onDetachedDependencyRestored(this,o.field,e);i.push(...d),s.push(...u),t.push(...y)}),this.defaultValue){const{updated:o}=this.defaultValue.restore({},e);i.push(...o)}if(this.readsValue&&(i.push(this.readsValue),this.readsValue.addValueReader(this,e)),this.writesValues.forEach(o=>{i.push(o),o.setValueWriter(this,e)}),this.inputs.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.outputs.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.successCalls.forEach(o=>{i.push(o),o.addSuccessCaller(this,e)}),this.errorCalls.forEach(o=>{i.push(o),o.addErrorCaller(this,e)}),this.internalCalls.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.dataType){const{updated:o}=this.dataType.restore({},e);i.push(...o)}return this.calledBySuccess.forEach(o=>{i.push(o),o.addSuccessCall(this,e)}),this.calledByError.forEach(o=>{i.push(o),o.addErrorCall(this,e)}),this.calledByEntry.forEach(o=>{i.push(o),o.addCall(this,e)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(l),self:this}}toFlat(e=new Set){var i,s,l;return e.has(this.id)?[]:(e.add(this.id),[this,...((i=this.defaultValue)==null?void 0:i.toFlat(e))||[],...((s=this.dataType)==null?void 0:s.toFlat(e))||[],...((l=this.readsValue)==null?void 0:l.toFlat(e))||[],...this.writesValues.flatMap(o=>o.toFlat(e)),...this.successCalls.flatMap(o=>o.toFlat(e)),...this.errorCalls.flatMap(o=>o.toFlat(e)),...this.inputs.flatMap(o=>o.toFlat(e)),...this.outputs.flatMap(o=>o.toFlat(e)),...this.internalCalls.flatMap(o=>o.toFlat(e)),...this.calledBy.flatMap(o=>o.toFlat(e))])}toFlatIds(e=new Set){var i,s;return e.has(this.id)?[]:(e.add(this.id),[this.id,...((i=this.defaultValue)==null?void 0:i.toFlatIds(e))||[],...((s=this.dataType)==null?void 0:s.toFlatIds(e))||[],...this.writesValues.flatMap(l=>l.toFlatIds(e)),...this.successCalls.flatMap(l=>l.toFlatIds(e)),...this.errorCalls.flatMap(l=>l.toFlatIds(e)),...this.inputs.flatMap(l=>l.toFlatIds(e)),...this.outputs.flatMap(l=>l.toFlatIds(e)),...this.internalCalls.flatMap(l=>l.toFlatIds(e))])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,description:this.description,required:this.required,constant:this.constant,x:this.x,y:this.y,type:this.type,name:this.name}}toJSON(e=new Set){var t,i,s;return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,constant:this.constant,required:this.required,defaultValue:((t=this.defaultValue)==null?void 0:t.toJSON(e))||null,dataType:((i=this.dataType)==null?void 0:i.toJSON(e))||null,readsValue:((s=this.readsValue)==null?void 0:s.toReference())||null,writesValues:this.writesValues.map(l=>l.toJSON(e)),inputs:this.inputs.map(l=>l.toJSON(e)),outputs:this.outputs.map(l=>l.toJSON(e)),successCalls:this.successCalls.map(l=>l.toJSON(e)),errorCalls:this.errorCalls.map(l=>l.toJSON(e)),internalCalls:this.internalCalls.map(l=>l.toJSON(e)),calledBySuccess:this.calledBySuccess.map(l=>l.toReference()),calledByError:this.calledByError.map(l=>l.toReference()),calledByEntry:this.calledByEntry.map(l=>l.toReference()),parent:this.parent.toReference(),x:this.x,y:this.y})}toJSONClone(e=J){var i,s,l,o,d,u,y,c;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||ht(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(s=e.seenEntities)!=null&&s.has(t)||(l=e.seenEntities)!=null&&l.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(d=e.seenEntities)==null||d.add(this.id),{id:t,version:m.UUID.uuid(),createdAt:e.timestamp||T().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,defaultValue:((u=this.defaultValue)==null?void 0:u.toJSONClone({...e,newId:null}))||null,dataType:((y=this.dataType)==null?void 0:y.toJSONClone({...e,newId:null}))||null,readsValue:((c=this.readsValue)==null?void 0:c.toReference({seenEntityMaps:e.seenEntityMaps}))||null,writesValues:this.writesValues.map(E=>E.toJSONClone({...e,newId:null})),inputs:this.inputs.map(E=>E.toJSONClone({...e,newId:null})),outputs:this.outputs.map(E=>E.toJSONClone({...e,newId:null})),successCalls:this.successCalls.map(E=>E.toJSONClone({...e,newId:null})),errorCalls:this.errorCalls.map(E=>E.toJSONClone({...e,newId:null})),internalCalls:this.internalCalls.map(E=>this.calledBy.length||this.readsValue?E.toJSONClone({...e,newId:null}):E.toReference({seenEntityMaps:e.seenEntityMaps})),calledBySuccess:this.calledBySuccess.map(E=>E.toReference({seenEntityMaps:e.seenEntityMaps})),calledByError:this.calledByError.map(E=>E.toReference({seenEntityMaps:e.seenEntityMaps})),calledByEntry:this.calledByEntry.map(E=>E.toReference({seenEntityMaps:e.seenEntityMaps})),parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps}),x:this.x,y:this.y})}toReference(e=J){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+m.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=J){var i,s,l,o;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,required:this.required,constant:this.constant,x:this.x,y:this.y,defaultValue:((s=this.defaultValue)==null?void 0:s.toReference(e))||null,dataType:((l=this.dataType)==null?void 0:l.toReference(e))||null,readsValue:((o=this.readsValue)==null?void 0:o.toReference(e))||null,writesValues:this.writesValues.map(d=>d.toReference(e)),inputs:this.inputs.map(d=>d.toReference(e)),outputs:this.outputs.map(d=>d.toReference(e)),successCalls:this.successCalls.map(d=>d.toReference(e)),errorCalls:this.errorCalls.map(d=>d.toReference(e)),calledBySuccess:this.calledBySuccess.map(d=>d.toReference(e)),calledByError:this.calledByError.map(d=>d.toReference(e)),calledByEntry:this.calledByEntry.map(d=>d.toReference(e)),internalCalls:this.internalCalls.map(d=>d.toReference(e)),parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){var i,s;return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...((i=this.defaultValue)==null?void 0:i.toFlatJSON(e))||[],...((s=this.dataType)==null?void 0:s.toFlatJSON(e))||[],...this.writesValues.flatMap(l=>l.toFlatJSON(e)),...this.successCalls.flatMap(l=>l.toFlatJSON(e)),...this.errorCalls.flatMap(l=>l.toFlatJSON(e)),...this.inputs.flatMap(l=>l.toFlatJSON(e)),...this.outputs.flatMap(l=>l.toFlatJSON(e)),...this.internalCalls.flatMap(l=>l.toFlatJSON(e))])}toGenerationTarget(){const e=this.parent.type===n.Project?void 0:this.parent.id;return{id:this.id,type:this.type,name:this.name,description:this.description,calledByEntry:this.calledByEntry.map(t=>t.id),calledBySuccess:this.calledBySuccess.map(t=>t.id),calledByError:this.calledByError.map(t=>t.id),parent:e}}toFlatGenerationTarget(e=new Set){var i,s;return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...((i=this.defaultValue)==null?void 0:i.toFlatGenerationTarget(e))||[],...((s=this.dataType)==null?void 0:s.toFlatGenerationTarget(e))||[],...this.writesValues.flatMap(l=>l.toFlatGenerationTarget(e)),...this.successCalls.flatMap(l=>l.toFlatGenerationTarget(e)),...this.errorCalls.flatMap(l=>l.toFlatGenerationTarget(e)),...this.inputs.flatMap(l=>l.toFlatGenerationTarget(e)),...this.outputs.flatMap(l=>l.toFlatGenerationTarget(e)),...this.internalCalls.flatMap(l=>l.toFlatGenerationTarget(e))])}clearErrors(){var e,t;return this.errors=[],this.inputs.forEach(i=>i.clearErrors()),this.outputs.forEach(i=>i.clearErrors()),this.successCalls.forEach(i=>i.clearErrors()),this.errorCalls.forEach(i=>i.clearErrors()),this.internalCalls.forEach(i=>i.clearErrors()),(e=this.dataType)==null||e.clearErrors(),(t=this.defaultValue)==null||t.clearErrors(),this}validate(){const e=A1(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){var t,i,s;return[...this.errors,...((t=this.defaultValue)==null?void 0:t.getErrors())||[],...((i=this.dataType)==null?void 0:i.getErrors())||[],...this.inputs.flatMap(l=>l.getErrors()),...this.internalCalls.flatMap(l=>l.getErrors()),...this.outputs.flatMap(l=>l.getErrors()),...((s=this.readsValue)==null?void 0:s.getErrors())||[]]}getShallowErrors(){return this.errors}getDefaultValue(){return this.defaultValue||null}setDefaultValue(e){return this.defaultValue=e,this}clone(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"clone-entity")),t=null,i=null,s=!0){var P,V,M,g,B;let l=mt(t,this);const o=this.toJSON(),d=i||m.UUID.uuid();o.inputs=[],o.id=d,o.version=m.UUID.uuid(),o.createdAt=(e==null?void 0:e.timestamp)||T().toISOString(),o.author=(e==null?void 0:e.author)||"1",o.previousVersion=null,o.deleted=!1;const u=nt(o,l);t?u.setParent(t,null):u.setParent(this.parent,null),s&&u.subscribe(),u.initChildren(e),e==null||e.add(u,b.Added);const y=(P=this.dataType)==null?void 0:P.clone(e,u,m.UUID.uuid(),s);u.dataType=y||null;const c=(V=this.defaultValue)==null?void 0:V.clone(e,u,m.UUID.uuid(),s);u.defaultValue=c||null;const E=(M=this.inputs)==null?void 0:M.map(G=>G.clone(e,u,m.UUID.uuid(),s));u.inputs=E;const I=(g=this.outputs)==null?void 0:g.map(G=>G.clone(e,u,m.UUID.uuid(),s));u.outputs=I;const O=(B=this.internalCalls)==null?void 0:B.map(G=>G.clone(e,u,m.UUID.uuid(),s));return u.internalCalls=O,e==null||e.attemptAutoclose("clone-entity",this.id),u}addInternalCall(e){return this.internalCalls.find(t=>t===e)||this.internalCalls.push(e),this}createInstance(e=this.project,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"create-instance")),i={}){const s={id:i.id||m.UUID.uuid(),version:i.version||m.UUID.uuid(),createdAt:(t==null?void 0:t.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.VariableInstance,parent:e.toReference(),defaultValue:i.defaultValue||null,successCalls:i.successCalls||[],errorCalls:i.errorCalls||[],inputs:i.inputs||[],outputs:i.outputs||[],writesValues:i.writesValues||[],internalCalls:i.internalCalls||[],readsValue:i.readsValue||null,calledByEntry:i.calledByEntry||[],calledBySuccess:i.calledBySuccess||[],calledByError:i.calledByError||[],declaration:this.toReference(),x:0,y:0},l=C(s,this.project);return l.hydrateAncestors(),l.setParent(e,t),t==null||t.add(l,b.Added),l.addSelfToProject(t),l.initChildren(t),e===this.project&&this.project.addVariableInstance(l),t==null||t.attemptAutoclose("create-instance",this.id),l}generateUnusedInputs(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"generate-unused-inputs"))){const t=[],i=[],s=[],l=[];if(this.dataType)if(this.dataType.entity){if([n.DefinitionEntity,n.PrimitiveEntity,n.BuiltInBaseEntity].includes(this.dataType.entity.type)){const o=[...this.dataType.entity.properties];o.filter(c=>!c.getDataType(e)).forEach(c=>{const E=this.inputs.find(P=>x(P,this.project)===x(c,this.project));if(!E)return;const I=this.getMasterInputWithValueWritterFromAllInstances(E);if(!I)return;const O=ji(I);c.setDataType(O),E.setDeclaration(c)}),o.filter(c=>!this.inputs.find(E=>{var I;return((I=E.declaration)==null?void 0:I.id)===c.id})).forEach(c=>{const E={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.InputMap,parent:this.toReference(),name:null,description:null,declaration:c,defaultValue:null,index:c.index,readsValue:null},I=C(E,this.project);return I.setParent(this,e),I.initChildren(e),e==null||e.add(I,b.Added),I.suggestion=!0,this.addInput(I,e),I}),this.inputs.filter(c=>!c.declaration).forEach(c=>{const E=o.find(I=>x(I,this.project)===x(c,this.project));E&&c.setDeclaration(E)})}}else return e==null||e.attemptAutoclose("generate-unused-inputs",this.id),{added:[],updated:[],removed:[],affected:[],self:this};else return e==null||e.attemptAutoclose("generate-unused-inputs",this.id),{added:[],updated:[],removed:[],affected:[],self:this};return e==null||e.attemptAutoclose("generate-unused-inputs",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(l),self:this}}generateUnusedOutputs(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"generate-unused-outputs"))){const t=[],i=[],s=[],l=[];if(this.dataType)if(this.dataType.entity)[n.DefinitionEntity,n.PrimitiveEntity,n.BuiltInBaseEntity].includes(this.dataType.entity.type)&&[...this.dataType.entity.properties].filter(u=>!this.outputs.find(y=>y.declaration===u)).map(u=>{const y={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.OutputMap,defaultValue:null,parent:this.toReference(),declaration:u,index:u.index,writesValues:[]},c=C(y,this.project);return c.setParent(this,e),c.initChildren(e),e==null||e.add(c,b.Added),c.suggestion=!0,this.addOutput(c,e),c});else return e==null||e.attemptAutoclose("generate-unused-outputs",this.id),{added:[],updated:[],removed:[],affected:[],self:this};else return e==null||e.attemptAutoclose("generate-unused-outputs",this.id),{added:[],updated:[],removed:[],affected:[],self:this};return e==null||e.attemptAutoclose("generate-unused-outputs",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(l),self:this}}generateUnusedInternalCalls(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"generate-unused-internal-calls"))){const t=[],i=[],s=[],l=[];if(this.dataType)if(this.dataType.entity)[n.DefinitionEntity,n.PrimitiveEntity,n.BuiltInBaseEntity].includes(this.dataType.entity.type)&&[...this.dataType.entity.getAllInteractiveMethods()].filter(u=>!this.internalCalls.find(c=>{var I,O,P,V,M;return(((I=c.declaration)==null?void 0:I.id)||((P=(O=c.initialData)==null?void 0:O.declaration)==null?void 0:P.entityId)||((M=(V=c.initialData)==null?void 0:V.declaration)==null?void 0:M.id))===u.id})).map(u=>{const y=u.createInternalCall(e,this);return e==null||e.add(y,b.Added),y.suggestion=!0,this.addInternalCall(y),y});else return e==null||e.attemptAutoclose("generate-unused-internal-calls",this.id),{added:[],updated:[],removed:[],affected:[],self:this};else return e==null||e.attemptAutoclose("generate-unused-internal-calls",this.id),{added:[],updated:[],removed:[],affected:[],self:this};return e==null||e.attemptAutoclose("generate-unused-internal-calls",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(l),self:this}}setDataType(e){return this.dataType=e,this}removeDataType(){return this.dataType=null,this}getDataType(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"get-data-type"))){return(!this.dataType||this.dataType.inferred)&&this.inferDataTypeAndSyncInstancesInputsAndOutputs(e),this.dataType||null}getUnusedInputs(){return this.inputs.filter(e=>e.suggestion||!e.readsValue&&!e.defaultValue)}getUnusedOutputs(){return this.outputs.filter(e=>e.suggestion||!e.writesValues.length)}getUsedInputs(){return this.inputs.filter(e=>!e.suggestion&&(e.readsValue||e.defaultValue))}getUsedOutputs(){return this.outputs.filter(e=>!e.suggestion&&e.writesValues.length)}};f(Ve,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>e,APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...i)=>null}),f(Ve,"type",n.VariableDeclaration),f(Ve,"USER_MANAGED_PARENT_TYPES",[...ut,n.Project]),f(Ve,"PARENT_TYPES",[...Ve.USER_MANAGED_PARENT_TYPES]),f(Ve,"MUTABLE_BASE_PROPERTIES",["name","description","constant","required"]),f(Ve,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),f(Ve,"BASE_PROPERTIES",[...Ve.MUTABLE_BASE_PROPERTIES,...Ve.INMUTABLE_BASE_PROPERTIES]),f(Ve,"MUTABLE_META_PROPERTIES",[...Ve.MUTABLE_BASE_PROPERTIES,"x","y"]),f(Ve,"INMUTABLE_META_PROPERTIES",[...Ve.INMUTABLE_BASE_PROPERTIES]),f(Ve,"META_PROPERTIES",[...Ve.MUTABLE_META_PROPERTIES,...Ve.INMUTABLE_META_PROPERTIES]),f(Ve,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry","readsValue"]),f(Ve,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","dataType"]),f(Ve,"UPSTREAM_PROPERTIES",[...Ve.MUTABLE_UPSTREAM_PROPERTIES,...Ve.INMUTABLE_UPSTREAM_PROPERTIES]),f(Ve,"MUTABLE_DOWNSTREAM_PROPERTIES",["writesValues","inputs","outputs","successCalls","errorCalls","internalCalls"]),f(Ve,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),f(Ve,"DOWNSTREAM_PROPERTIES",[...Ve.MUTABLE_DOWNSTREAM_PROPERTIES,...Ve.INMUTABLE_DOWNSTREAM_PROPERTIES]),f(Ve,"PROPERTIES",[...Ve.META_PROPERTIES,...Ve.UPSTREAM_PROPERTIES,...Ve.DOWNSTREAM_PROPERTIES]);let Yr=Ve;function D1(r){var l;const a=J5(),e=r.toJSON();a.safeParse(e).success,r.inputsDeclarations.forEach(o=>o.validate()),r.inputs.forEach(o=>o.validate()),r.outputsDeclarations.forEach(o=>o.validate()),r.outputs.forEach(o=>o.validate()),(l=r.error)==null||l.validate();const s=[...Ar(r)];if(r.id==="search-person-by-id-id"){const o=de({id:`${r.id}--${F.PropertyImplementsNonAbstact}`,message:`Property "${x(r,r.project)}" with id "${r.id}" implements a non-abstract property "${x(r,r.project)}" with id "${r.id}".`,issue:null,severity:D.Error,code:F.PropertyImplementsNonAbstact,entity:r});s.push(o.error)}return Ke(r.errors,s)}const SJ=Object.freeze(Object.defineProperty({__proto__:null,validate:D1},Symbol.toStringTag,{value:"Module"}));var O1=(r=>(r.Parent="parent",r))(O1||{});const We=class We extends lt{constructor(e,t){super(e);f(this,"initialData");f(this,"id");f(this,"name");f(this,"description",null);f(this,"x");f(this,"y");f(this,"query","");f(this,"type",n.Search);f(this,"successCalls",[]);f(this,"errorCalls",[]);f(this,"inputsDeclarations",[]);f(this,"inputs",[]);f(this,"outputsDeclarations",[]);f(this,"outputs",[]);f(this,"calledBySuccess",[]);f(this,"calledByError",[]);f(this,"calledByEntry",[]);f(this,"error",null);f(this,"parent");f(this,"errors",[]);f(this,"project");f(this,"detachedDependents",{});f(this,"knownVersions",null);f(this,"activeVersion",!1);f(this,"initialized",!1);f(this,"startedInitialization",!1);this.initialData=e,this.project=t,this.id=e.id,this.x=e.x,this.y=e.y,this.name=e.name,this.query=e.query,this.description=e.description}static new(e=null){return{id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:(e==null?void 0:e.author)||m.sessionAuthor,previousVersion:null,deleted:!1,type:n.Search,name:"",description:"",inputsDeclarations:[],outputsDeclarations:[],inputs:[],outputs:[],query:"",error:null,parent:null,calledByEntry:[],calledBySuccess:[],calledByError:[],errorCalls:[],successCalls:[],x:0,y:0}}static fromGenerationTarget(e,t){let i=t;if(e.parent){const y=_(e.parent);i=t.get(y)}const s=e.calledByEntry.map(y=>{const c=_(y);return t.get(c)}),l=e.calledBySuccess.map(y=>{const c=_(y);return t.get(c)}),o=e.calledByError.map(y=>{const c=_(y);return t.get(c)}),d={id:e.id,version:m.UUID.uuid(),createdAt:T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.Search,name:e.name,description:e.description,query:e.query,calledByEntry:s,calledBySuccess:l,calledByError:o,errorCalls:[],successCalls:[],inputsDeclarations:[],inputs:[],outputsDeclarations:[],outputs:[],error:null,x:0,y:0,parent:i},u=C(d,t);return u.setParent(i,null),u.initChildren(null),u}static validateGenerationTarget(e,t){let i=JSON.parse(JSON.stringify(e));const s=[],l=bt(i,{parent:{list:!1,types:[...ut,n.Project],optional:!0}},t);return i=l.modifiedData,s.push(...l.errors,...pt(i)),{errors:s,modifiedData:i}}get resultsAsList(){const e=this.outputsDeclarations[0];if(e){const t=e.getDataType(null);return t?t.isList===!0:!0}return!0}validateGeneratedUpdate(e){const t=[];return e.parent&&t.push(new w({id:`${this.id}--${R.InvalidParentUpdate}`,code:R.InvalidParentUpdate,severity:D.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.
110
110
  If an entity is called by another, they must be in the same scope, which means they have the same parent.
111
111
  You shouldn't have to manually update a 'parent' property. The equivalent result is to change its callers, the value writters of its inputs, or the value readers of its outputs.`,issue:null})),{errors:t,modifiedData:e}}subscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]||(this.detachedDependents[t.entity.id]=t)}),this}syncDependents(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-dependents"))){const t=[],i=[],s=[],l=[];return Object.values(this.detachedDependents).forEach(o=>{const d=o.entity.afterAllChildrenInitialized(e);t.push(...d.updated),i.push(...d.added),s.push(...d.removed),l.push(...d.affected)}),e==null||e.attemptAutoclose("sync-dependents",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];if(t==="parent"){const{updated:u,added:y,removed:c}=this.remove({ignoreUpstream:!1},i);s.push(...u),l.push(...y),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}onDetachedDependencyRestored(e,t,i){const s=[],l=[],o=[],d=[];if(t==="parent"){const{updated:u,added:y,removed:c}=this.restore({},i);s.push(...u),l.push(...y),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}subscribeToDependencies(){var e;return(e=this.parent)==null||e.subscribeDependents([{entity:this,field:"parent"}]),this}increaseVersion(e){if(e&&!T(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&T(e).isSame(T(this.createdAt))?this:(this.previousVersion=this.version,this.version=m.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new We(this,this.project);return e.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,e):new Map([[this.version,e]]),e.inputs=this.inputs,e.outputs=this.outputs,e.error=this.error,e.inputsDeclarations=this.inputsDeclarations,e.outputsDeclarations=this.outputsDeclarations,e.successCalls=this.successCalls,e.errorCalls=this.errorCalls,e.calledByEntry=this.calledByEntry,e.calledBySuccess=this.calledBySuccess,e.calledByError=this.calledByError,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],i=[],s=[],l=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),i.push(...o.added),s.push(...o.removed)}return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}async restoreVersion(e){var d;const t=[],i=[],s=[],l=[];if(this.version===e)return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this};if(!this.knownVersions){const u=new Map;for(const[y,c]of this.knownVersions||new Map){if(u.set(y,c),c.activeVersion=!1,c.knownVersions)for(const[E,I]of c.knownVersions)u.set(E,I);c.knownVersions=null}}let o=(d=this.knownVersions)==null?void 0:d.get(e);if(!o){const u=await this.APILoadVersion({},e);if(!u)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new We(u,this.project)}return this.metaSync(o.toShallowJSON(),null),this.inputs=o.inputs,this.outputs=o.outputs,this.error=o.error,this.inputsDeclarations=o.inputsDeclarations,this.outputsDeclarations=o.outputsDeclarations,this.successCalls=o.successCalls,this.errorCalls=o.errorCalls,this.calledByEntry=o.calledByEntry,this.calledBySuccess=o.calledBySuccess,this.calledByError=o.calledByError,this.parent=o.parent,{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}hydrateAncestors(){const e=[],t=[],i=[],s=[];if(this.initialData.parent){const l=_(this.initialData.parent),o=this.project.get(l);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw new Error(`${this.type} with id '${this.id}' must have a 'parent'`);return this.initialData.calledByEntry.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addEntryCaller(d,null),d.addCall(this,null),e.push(d))}),this.initialData.calledBySuccess.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addSuccessCaller(d,null),d.addSuccessCall(this,null),e.push(d))}),this.initialData.calledByError.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addErrorCaller(d,null),d.addErrorCall(this,null),e.push(d))}),{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],i=[],s=[],l=[];this.initialized=!0;const{updated:o,added:d,removed:u}=this.syncInputMaps(e);return t.push(...o),i.push(...d),s.push(...u),this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addSelfToProject(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-self-to-project"))){const t=[this],i=[],s=[],l=[];return this.parent===this.project&&this.project.addSearch(this),this.successCalls.forEach(o=>{o.addSuccessCaller(this,e),t.push(o)}),this.errorCalls.forEach(o=>{o.addErrorCaller(this,e),t.push(o)}),this.calledByEntry.forEach(o=>{o.addCall(this,e),t.push(o)}),this.calledBySuccess.forEach(o=>{o.addSuccessCall(this,e),t.push(o)}),this.calledByError.forEach(o=>{o.addErrorCall(this,e),t.push(o)}),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}removeInput(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-input"))){const i=this.inputs.findIndex(l=>l.id===e.id);i>-1&&(this.inputs.splice(i,1),t==null||t.add(this,b.Affected));const s=this.inputsDeclarations.findIndex(l=>{var o;return l.id===((o=e.declaration)==null?void 0:o.id)});return s>-1&&(this.inputsDeclarations.splice(s,1),t==null||t.add(this,b.Affected)),t==null||t.attemptAutoclose("remove-input",this.id),this}addInput(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-input"))){return this.inputs.includes(e)?(t==null||t.attemptAutoclose("add-input",this.id),this):(this.inputs.push(e),t==null||t.add(this,b.Affected),t==null||t.attemptAutoclose("add-input",this.id),this)}addInputDeclaration(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-input-declaration"))){return this.inputsDeclarations.includes(e)?(t==null||t.attemptAutoclose("add-input-declaration",this.id),this):(this.inputsDeclarations.push(e),t==null||t.attemptAutoclose("add-input-declaration",this.id),this)}removeInputDeclaration(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-input-declaration"))){const i=this.inputsDeclarations.findIndex(s=>s.id===e.id);return i>-1&&(this.inputsDeclarations.splice(i,1),t==null||t.add(this,b.Affected)),t==null||t.attemptAutoclose("remove-input-declaration",this.id),this}addOutputDeclaration(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-output-declaration"))){return this.outputsDeclarations.includes(e)?(t==null||t.attemptAutoclose("add-output-declaration",this.id),this):(this.outputsDeclarations.push(e),t==null||t.add(this,b.Affected),t==null||t.attemptAutoclose("add-output-declaration",this.id),this)}removeOutputDeclaration(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-output-declaration"))){const i=this.outputsDeclarations.findIndex(s=>s.id===e.id);return i>-1&&(this.outputsDeclarations.splice(i,1),t==null||t.add(this,b.Affected)),t==null||t.attemptAutoclose("remove-output-declaration",this.id),this}addOutput(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-output"))){return this.outputs.includes(e)?(t==null||t.attemptAutoclose("add-output",this.id),this):(this.outputs.push(e),t==null||t.add(this,b.Affected),t==null||t.attemptAutoclose("add-output",this.id),this)}removeOutput(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-output"))){const i=this.outputs.findIndex(s=>s.id===e.id);return i>-1&&(this.outputs.splice(i,1),t&&(t==null||t.add(this,b.Affected))),t==null||t.attemptAutoclose("remove-output",this.id),this}addSuccessCaller(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-success-caller")),i=!1){return this.calledBySuccess.find(s=>s.id===e.id)||(this.calledBySuccess.push(e),t==null||t.add(this,b.Updated),i&&K(this,t)),t==null||t.attemptAutoclose("add-success-caller",this.id),this}addErrorCaller(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-error-caller")),i=!1){return this.calledByError.find(s=>s.id===e.id)||(this.calledByError.push(e),t==null||t.add(this,b.Updated),i&&K(this,t)),t==null||t.attemptAutoclose("add-error-caller",this.id),this}addEntryCaller(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-entry-caller")),i=!1){return this.calledByEntry.find(s=>s.id===e.id)||(this.calledByEntry.push(e),t==null||t.add(this,b.Updated),i&&K(this,t)),t==null||t.attemptAutoclose("add-entry-caller",this.id),this}addErrorCall(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-error-call")),i=!1){return this.errorCalls.find(s=>s.id===e.id)||(this.errorCalls.push(e),i&&K(this,t),t==null||t.add(this,b.Affected)),t==null||t.attemptAutoclose("add-error-call",this.id),this}addSuccessCall(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-success-call")),i=!1){return this.successCalls.find(s=>s.id===e.id)||(this.successCalls.push(e),i&&K(this,t),t==null||t.add(this,b.Affected)),t==null||t.attemptAutoclose("add-success-call",this.id),this}removeCall(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-call")),i=!1){const s=this.successCalls.findIndex(o=>o.id===e.id);s>-1&&(this.successCalls.splice(s,1),t==null||t.add(this,b.Affected));const l=this.errorCalls.findIndex(o=>o.id===e.id);return l>-1&&(this.errorCalls.splice(l,1),t==null||t.add(this,b.Affected)),i&&K(this,t),t==null||t.attemptAutoclose("remove-call",this.id),this}removeCaller(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-caller")),i=!1){return this.calledBySuccess=this.calledBySuccess.filter(s=>s.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(s,b.Affected)),!0):!1),this.calledByError=this.calledByError.filter(s=>s.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(s,b.Affected)),!0):!1),this.calledByEntry=this.calledByEntry.filter(s=>s.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(s,b.Affected)),!0):!1),i&&K(this,t),t==null||t.attemptAutoclose("remove-caller",this.id),this}setParent(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"set-parent"))){var i;return((i=this.parent)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,b.Updated),t==null||t.attemptAutoclose("set-parent",this.id))),this}initChildren(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.successCalls=this.initialData.successCalls.map(t=>{const i=C(t,this.project);if([n.BreakStatement,n.ContinueStatement].includes(i.type))i.setParent(this.parent.parent,null),i.initChildren(e);else if(i.type===n.ReturnStatement){const s=It(this,this.project);i.setParent(s,null),i.initChildren(e)}else i.type!==n.InternalCall&&(i.setParent(this.parent,null),i.initChildren(e));return i}),this.errorCalls=this.initialData.errorCalls.map(t=>{const i=C(t,this.project);if(i.addErrorCaller(this),[n.BreakStatement,n.ContinueStatement].includes(i.type))i.setParent(this.parent.parent,null),i.initChildren(e);else if(i.type===n.ReturnStatement){const s=It(this,this.project);i.setParent(s,null),i.initChildren(e)}else i.type!==n.InternalCall&&(i.setParent(this.parent,null),i.initChildren(e));return i}),this.inputsDeclarations=this.initialData.inputsDeclarations.map(t=>{const i=C(t,this.project);return i.setParent(this,null),i.initChildren(e),i}),this.inputs=this.initialData.inputs.map(t=>{const i=C(t,this.project);return i.setParent(this,null),i.initChildren(e),i}),this.outputsDeclarations=this.initialData.outputsDeclarations.map(t=>{const i=C(t,this.project);return i.setParent(this,null),i.initChildren(e),i}),this.outputs=this.initialData.outputs.map(t=>{const i=C(t,this.project);return i.setParent(this,null),i.initChildren(e),i}),this.initialData.error&&(this.error=C(this.initialData.error,this.project),this.error.setParent(this,null),this.error.initChildren(e)),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this)}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"meta-sync"))){const i=ct(this,e),s=this.toMeta();return this.x=e.x||s.x,this.y=e.y||s.y,this.name=e.name!==void 0?e.name:s.name,this.description=e.description!==void 0?e.description:s.description,e.query!==void 0&&(this.query=e.query),super.metaSync(e),e.deleted===!0&&!s.deleted?t==null||t.add(this,b.Removed):e.deleted===!1&&s.deleted?t==null||t.add(this,b.Added):i&&(t==null||t.add(this,b.Updated)),t==null||t.attemptAutoclose("meta-sync",this.id),this}async APILoad(e=U,...t){return await We.repository.APILoad(this.id,...t),this}async APICreate(e=U,...t){return await We.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=U,...t){return await We.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=U,...t){return await We.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=U,...t){return await We.repository.APIClone(this.id,...t),this}async APILoadVersion(e=U,t,...i){return await We.repository.APILoadVersion(this.id,t,...i)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-entity"))){const i=[],s=[],l=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(s.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(d=>{const{updated:u,removed:y,added:c}=d.entity.onDetachedDependencyRemoved(this,d.field,t);i.push(...u),s.push(...y),l.push(...c)}),this.inputs.forEach(d=>{const{updated:u,removed:y}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...y)}),this.inputsDeclarations.forEach(d=>{const{updated:u,removed:y}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...y)}),this.outputs.forEach(d=>{const{updated:u,removed:y}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...y)}),this.outputsDeclarations.forEach(d=>{const{updated:u,removed:y}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...y)}),this.error){const{updated:d,removed:u}=this.error.remove({ignoreUpstream:!0},t);i.push(...d),s.push(...u)}return this.successCalls.forEach(d=>{i.push(d),d.removeCaller(this,t)}),this.errorCalls.forEach(d=>{i.push(d),d.removeCaller(this,t)}),e||this.calledBy.forEach(d=>{i.push(d),d.removeCall(this,t)}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:p(l),updated:p(i),removed:p(s),affected:p(o),self:this}}restore({}={},e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"restore-entity"))){const t=[],i=[],s=[],l=[];return e!=null&&e.hasAdded(this.id)?(e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),Object.values(this.detachedDependents).forEach(o=>{const{updated:d,removed:u,added:y}=o.entity.onDetachedDependencyRestored(this,o.field,e);i.push(...d),s.push(...u),t.push(...y)}),this.inputsDeclarations.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.inputs.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.outputsDeclarations.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.outputs.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.successCalls.forEach(o=>{i.push(o),o.addSuccessCaller(this,e)}),this.errorCalls.forEach(o=>{i.push(o),o.addErrorCaller(this,e)}),this.calledBySuccess.forEach(o=>{i.push(o),o.addSuccessCall(this,e)}),this.calledByError.forEach(o=>{i.push(o),o.addErrorCall(this,e)}),this.calledByEntry.forEach(o=>{i.push(o),o.addCall(this,e)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(l),self:this})}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.successCalls.flatMap(i=>i.toFlat(e)),...this.errorCalls.flatMap(i=>i.toFlat(e)),...this.inputs.flatMap(i=>i.toFlat(e)),...this.inputsDeclarations.flatMap(i=>i.toFlat(e)),...this.outputs.flatMap(i=>i.toFlat(e)),...this.outputsDeclarations.flatMap(i=>i.toFlat(e)),...this.calledBy.flatMap(i=>i.toFlat(e)),...this.error?this.error.toFlat(e):[]])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.successCalls.flatMap(i=>i.toFlatIds(e)),...this.errorCalls.flatMap(i=>i.toFlatIds(e)),...this.inputs.flatMap(i=>i.toFlatIds(e)),...this.inputsDeclarations.flatMap(i=>i.toFlatIds(e)),...this.outputs.flatMap(i=>i.toFlatIds(e)),...this.outputsDeclarations.flatMap(i=>i.toFlatIds(e)),...this.calledBy.flatMap(i=>i.toFlatIds(e)),...this.error?this.error.toFlatIds(e):[]])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,description:this.description,query:this.query,x:this.x,y:this.y,type:this.type,name:this.name}}toJSON(e=new Set){var t;return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,query:this.query,description:this.description,x:this.x,y:this.y,successCalls:this.successCalls.map(i=>i.toJSON()),errorCalls:this.errorCalls.map(i=>i.toJSON()),calledBySuccess:this.calledBySuccess.map(i=>i.toReference()),calledByError:this.calledByError.map(i=>i.toReference()),calledByEntry:this.calledByEntry.map(i=>i.toReference()),inputsDeclarations:this.inputsDeclarations.map(i=>i.toJSON()),inputs:this.inputs.map(i=>i.toJSON()),outputsDeclarations:this.outputsDeclarations.map(i=>i.toJSON()),outputs:this.outputs.map(i=>i.toJSON()),error:((t=this.error)==null?void 0:t.toJSON())||null,parent:this.parent.toReference()})}toJSONClone(e=J){var i,s,l,o,d,u;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||ht(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(s=e.seenEntities)!=null&&s.has(t)||(l=e.seenEntities)!=null&&l.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(d=e.seenEntities)==null||d.add(this.id),{id:t,version:m.UUID.uuid(),createdAt:e.timestamp||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.Search,name:this.name,query:this.query,description:this.description,x:this.x,y:this.y,successCalls:this.successCalls.map(y=>y.toJSONClone({...e,newId:null})),errorCalls:this.errorCalls.map(y=>y.toJSONClone({...e,newId:null})),calledBySuccess:this.calledBySuccess.map(y=>y.toReference({seenEntityMaps:e.seenEntityMaps})),calledByError:this.calledByError.map(y=>y.toReference({seenEntityMaps:e.seenEntityMaps})),calledByEntry:this.calledByEntry.map(y=>y.toReference({seenEntityMaps:e.seenEntityMaps})),inputsDeclarations:this.inputsDeclarations.map(y=>y.toJSONClone({...e,newId:null})),inputs:this.inputs.map(y=>y.toJSONClone({...e,newId:null})),outputsDeclarations:this.outputsDeclarations.map(y=>y.toJSONClone({...e,newId:null})),outputs:this.outputs.map(y=>y.toJSONClone({...e,newId:null})),error:((u=this.error)==null?void 0:u.toJSONClone({...e,newId:null}))||null,parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps})})}toReference(e=J){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+m.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=J){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,query:this.query,x:this.x,y:this.y,inputs:this.inputs.map(s=>s.toReference(e)),inputsDeclarations:this.inputsDeclarations.map(s=>s.toReference(e)),outputs:this.outputs.map(s=>s.toReference(e)),outputsDeclarations:this.outputsDeclarations.map(s=>s.toReference(e)),successCalls:this.successCalls.map(s=>s.toReference(e)),errorCalls:this.errorCalls.map(s=>s.toReference(e)),calledBySuccess:this.calledBySuccess.map(s=>s.toReference(e)),calledByError:this.calledByError.map(s=>s.toReference(e)),calledByEntry:this.calledByEntry.map(s=>s.toReference(e)),error:this.error?this.error.toReference(e):null,parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.successCalls.flatMap(i=>i.toFlatJSON(e)),...this.errorCalls.flatMap(i=>i.toFlatJSON(e)),...this.inputs.flatMap(i=>i.toFlatJSON(e)),...this.inputsDeclarations.flatMap(i=>i.toFlatJSON(e)),...this.outputs.flatMap(i=>i.toFlatJSON(e)),...this.outputsDeclarations.flatMap(i=>i.toFlatJSON(e)),...this.calledBy.flatMap(i=>i.toFlatJSON(e)),...this.error?this.error.toFlatJSON(e):[]])}toGenerationTarget(){const e=this.parent.type===n.Project?void 0:this.parent.id;return{id:this.id,name:this.name,description:this.description,type:this.type,query:this.query,calledByEntry:this.calledByEntry.map(t=>t.id),calledBySuccess:this.calledBySuccess.map(t=>t.id),calledByError:this.calledByError.map(t=>t.id),parent:e}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...this.successCalls.flatMap(i=>i.toFlatGenerationTarget(e)),...this.errorCalls.flatMap(i=>i.toFlatGenerationTarget(e)),...this.inputs.flatMap(i=>i.toFlatGenerationTarget(e)),...this.inputsDeclarations.flatMap(i=>i.toFlatGenerationTarget(e)),...this.outputs.flatMap(i=>i.toFlatGenerationTarget(e)),...this.outputsDeclarations.flatMap(i=>i.toFlatGenerationTarget(e)),...this.error?this.error.toFlatGenerationTarget(e):[]])}clearErrors(){var e;return this.errors=[],this.inputsDeclarations.forEach(t=>t.clearErrors()),this.inputs.forEach(t=>t.clearErrors()),this.outputs.forEach(t=>t.clearErrors()),this.successCalls.forEach(t=>t.clearErrors()),this.errorCalls.forEach(t=>t.clearErrors()),(e=this.error)==null||e.clearErrors(),this}validate(){const e=D1(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){return[...this.errors,...this.inputsDeclarations.flatMap(t=>t.getErrors()),...this.inputs.flatMap(t=>t.getErrors()),...this.outputsDeclarations.flatMap(t=>t.getErrors()),...this.outputs.flatMap(t=>t.getErrors()),...this.error?this.error.getErrors():[]]}getShallowErrors(){return this.errors}clone(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"clone-entity")),t=null,i=null,s=!0){var V,M,g,B;let l=mt(t,this);const o=this.toJSON(),d=i||m.UUID.uuid();o.inputs=[];const u=d.split("-id"),y=u[u.length-1||0]||d;o.id=d,o.version=m.UUID.uuid(),o.createdAt=(e==null?void 0:e.timestamp)||T().toISOString(),o.author=(e==null?void 0:e.author)||"1",o.previousVersion=null,o.deleted=!1;const c=nt(o,l);t?c.setParent(t,null):c.setParent(this.parent,null),s&&c.subscribe(),c.initChildren(e),e==null||e.add(c,b.Added);const E=(V=this.inputsDeclarations)==null?void 0:V.map((G,q)=>G.clone(e,this,y+"-input-declaration-"+q+"-id",s));c.inputsDeclarations=E;const I=(M=this.outputsDeclarations)==null?void 0:M.map((G,q)=>G.clone(e,this,y+"-output-declaration-"+q+"-id",s));c.outputsDeclarations=I;const O=(g=this.inputs)==null?void 0:g.map((G,q)=>G.clone(e,c,y+"-input-map-"+q+"-id",s));c.inputs=O;const P=(B=this.outputs)==null?void 0:B.map((G,q)=>G.clone(e,c,y+"-output-map-"+q+"-id",s));return c.outputs=P,this.error&&(c.error=this.error.clone(e,c,y+"-error-map-id",s)),e==null||e.attemptAutoclose("clone-entity",this.id),c}syncInputMaps(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-input-maps"))){const t=[],i=[],s=[],l=[];return this.inputsDeclarations.forEach(o=>{if(!this.inputs.find(u=>{var y;return((y=u.declaration)==null?void 0:y.id)===o.id})){const u={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.InputMap,declaration:o.toJSON(),readsValue:null,defaultValue:null,index:this.inputs.length,name:null,description:null,parent:this.toReference()},y=C(u,this.project);y.setParent(this,e),y.initChildren(e),e==null||e.add(y,b.Added),y.addSelfToProject(e),t.push(this),i.push(y)}}),this.inputs.forEach(o=>{if(o.declaration){if(!this.inputsDeclarations.find(u=>{var y;return u.id===((y=o.declaration)==null?void 0:y.id)})){const{updated:u,removed:y}=o.remove({ignoreUpstream:!1},e);u.push(...u),s.push(...y)}}else{const{updated:d,removed:u}=o.remove({ignoreUpstream:!1},e);t.push(...d),s.push(...u)}}),e==null||e.attemptAutoclose("sync-input-maps",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}};f(We,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>e,APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...i)=>null}),f(We,"type",n.Search),f(We,"USER_MANAGED_PARENT_TYPES",[...ut,n.Project]),f(We,"PARENT_TYPES",[...We.USER_MANAGED_PARENT_TYPES]),f(We,"MUTABLE_BASE_PROPERTIES",["name","description","query"]),f(We,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),f(We,"BASE_PROPERTIES",[...We.MUTABLE_BASE_PROPERTIES,...We.INMUTABLE_BASE_PROPERTIES]),f(We,"MUTABLE_META_PROPERTIES",[...We.MUTABLE_BASE_PROPERTIES,"x","y"]),f(We,"INMUTABLE_META_PROPERTIES",[...We.INMUTABLE_BASE_PROPERTIES]),f(We,"META_PROPERTIES",[...We.MUTABLE_META_PROPERTIES,...We.INMUTABLE_META_PROPERTIES]),f(We,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry"]),f(We,"INMUTABLE_UPSTREAM_PROPERTIES",["parent"]),f(We,"UPSTREAM_PROPERTIES",[...We.MUTABLE_UPSTREAM_PROPERTIES,...We.INMUTABLE_UPSTREAM_PROPERTIES]),f(We,"MUTABLE_DOWNSTREAM_PROPERTIES",["successCalls","errorCalls","inputsDeclarations","inputs","outputsDeclarations","outputs","error"]),f(We,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),f(We,"DOWNSTREAM_PROPERTIES",[...We.MUTABLE_DOWNSTREAM_PROPERTIES,...We.INMUTABLE_DOWNSTREAM_PROPERTIES]),f(We,"PROPERTIES",[...ei.META_PROPERTIES,...ei.UPSTREAM_PROPERTIES,...ei.DOWNSTREAM_PROPERTIES]);let Hr=We;function P1(r){const a=UZ(),e=r.toJSON();a.safeParse(e).success,r.functions.forEach(s=>s.validate()),r.events.forEach(s=>s.validate());const i=[];return Ke(r.errors,i)}const WJ=Object.freeze(Object.defineProperty({__proto__:null,validate:P1},Symbol.toStringTag,{value:"Module"})),Ze=class Ze extends lt{constructor(e,t){super(e);f(this,"initialData");f(this,"id");f(this,"name");f(this,"description",null);f(this,"x");f(this,"y");f(this,"type",n.InstalledProject);f(this,"implements");f(this,"functions",[]);f(this,"events",[]);f(this,"parent");f(this,"errors",[]);f(this,"project");f(this,"detachedDependents",{});f(this,"knownVersions",null);f(this,"activeVersion",!1);f(this,"initialized",!1);f(this,"startedInitialization",!1);this.initialData=e,this.project=t,this.id=e.id,this.name=e.name,this.description=e.description,this.x=e.x,this.y=e.y,this.implements=e.implements}static new(e=null){return{id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:(e==null?void 0:e.author)||m.sessionAuthor,previousVersion:null,deleted:!1,type:n.InstalledProject,name:"",description:"",implements:null,functions:[],events:[],x:0,y:0,parent:null}}static fromGenerationTarget(e,t){const i=t,s={id:e.id,version:m.UUID.uuid(),createdAt:T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,name:e.name,type:n.InstalledProject,description:e.description,functions:[],events:[],implements:{entityId:e.implements,version:m.UUID.uuid(),entityType:n.Project,type:n.GenericReference,id:m.UUID.uuid()},x:0,y:0,parent:i},l=C(s,t);return l.setParent(i,null),l.initChildren(null),l}static validateGenerationTarget(e,t){let i=JSON.parse(JSON.stringify(e));const s=[];return s.push(...pt(i)),{errors:s,modifiedData:i}}validateGeneratedUpdate(e){const t=[];return e.parent&&t.push(new w({id:`${this.id}--${R.InvalidParentUpdate}`,code:R.InvalidParentUpdate,severity:D.Error,message:`Entity of type '${this.type}' with id '${this.id}' cannot have the 'parent' property updated. The 'parent' on an installed project, must be the root project as it is a globally declared entity.`,issue:null})),{errors:t,modifiedData:e}}subscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]||(this.detachedDependents[t.entity.id]=t)}),this}syncDependents(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-dependents"))){const t=[],i=[],s=[],l=[];return Object.values(this.detachedDependents).forEach(o=>{const d=o.entity.afterAllChildrenInitialized(e);t.push(...d.updated),i.push(...d.added),s.push(...d.removed),l.push(...d.affected)}),e==null||e.attemptAutoclose("sync-dependents",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}onDetachedDependencyRestored(e,t,i){const s=[],l=[],o=[],d=[];return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}subscribeToDependencies(){return this}increaseVersion(e){if(e&&!T(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&T(e).isSame(T(this.createdAt))?this:(this.previousVersion=this.version,this.version=m.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new Ze(this,this.project);return e.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,e):new Map([[this.version,e]]),e.functions=this.functions,e.events=this.events,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],i=[],s=[],l=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),i.push(...o.added),s.push(...o.removed)}return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}async restoreVersion(e){var d;const t=[],i=[],s=[],l=[];if(this.version===e)return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this};if(!this.knownVersions){const u=new Map;for(const[y,c]of this.knownVersions||new Map){if(u.set(y,c),c.activeVersion=!1,c.knownVersions)for(const[E,I]of c.knownVersions)u.set(E,I);c.knownVersions=null}}let o=(d=this.knownVersions)==null?void 0:d.get(e);if(!o){const u=await this.APILoadVersion({},e);if(!u)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new Ze(u,this.project)}return this.metaSync(o.toShallowJSON(),null),this.functions=o.functions,this.events=o.events,this.parent=o.parent,{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}hydrateAncestors(){const e=[],t=[],i=[],s=[];if(this.initialData.parent){const l=_(this.initialData.parent),o=this.project.get(l);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw new Error(`${this.type} with id '${this.id}' must have a 'parent'`);return{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],i=[],s=[],l=[];return this.initialized=!0,this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addSelfToProject(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-self-to-project"))){const t=[this],i=[],s=[],l=[];return this.project.addInstalledProject(this),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}setParent(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"set-parent"))){var i;return((i=this.parent)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,b.Updated),t==null||t.attemptAutoclose("set-parent",this.id))),this}initChildren(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.functions=this.initialData.functions.map(t=>{const i=C(t,this.project);return i.setParent(this,null),i.initChildren(e),i}),this.events=this.initialData.events.map(t=>{const i=C(t,this.project);return i.setParent(this,null),i.initChildren(e),i}),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this)}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"meta-sync"))){const i=ct(this,e),s=this.toMeta();return this.x=e.x||s.x,this.y=e.y||s.y,super.metaSync(e),e.deleted===!0&&!s.deleted?t==null||t.add(this,b.Removed):e.deleted===!1&&s.deleted?t==null||t.add(this,b.Added):i&&(t==null||t.add(this,b.Updated)),t==null||t.attemptAutoclose("meta-sync",this.id),this}async APILoad(e=U,...t){return await Ze.repository.APILoad(this.id,...t),this}async APICreate(e=U,...t){return await Ze.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=U,...t){return await Ze.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=U,...t){return await Ze.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=U,...t){return await Ze.repository.APIClone(this.id,...t),this}async APILoadVersion(e=U,t,...i){return await Ze.repository.APILoadVersion(this.id,t,...i)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-entity"))){const i=[],s=[],l=[],o=[];return t!=null&&t.hasRemoved(this.id)?(t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(s.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(d=>{const{updated:u,removed:y,added:c}=d.entity.onDetachedDependencyRemoved(this,d.field,t);i.push(...u),s.push(...y),l.push(...c)}),this.functions.forEach(d=>{const{updated:u,removed:y}=d.remove({ignoreUpstream:!1},t);i.push(...u),s.push(...y)}),this.events.forEach(d=>{const{updated:u,removed:y}=d.remove({ignoreUpstream:!1},t);i.push(...u),s.push(...y)}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:p(o),self:this})}restore({}={},e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"restore-entity"))){const t=[],i=[],s=[],l=[];return e!=null&&e.hasAdded(this.id)?(e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),Object.values(this.detachedDependents).forEach(o=>{const{updated:d,removed:u,added:y,affected:c}=o.entity.onDetachedDependencyRestored(this,o.field,e);t.push(...d),i.push(...u),s.push(...y),l.push(...c)}),this.functions.forEach(o=>{const{updated:d,removed:u,added:y,affected:c}=o.restore({},e);t.push(...d),i.push(...u),s.push(...y),l.push(...c)}),this.events.forEach(o=>{const{updated:d,removed:u,added:y,affected:c}=o.restore({},e);t.push(...d),i.push(...u),s.push(...y),l.push(...c)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this})}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.functions.flatMap(i=>i.toFlat(e)),...this.events.flatMap(i=>i.toFlat(e))])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.functions.flatMap(i=>i.toFlatIds(e)),...this.events.flatMap(i=>i.toFlatIds(e))])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,description:this.description,x:this.x,y:this.y,type:this.type,name:this.name}}toJSON(e=new Set){return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,implements:this.implements,functions:this.functions.map(t=>t.toJSON(e)),events:this.events.map(t=>t.toJSON(e)),parent:this.parent.toReference(),x:this.x,y:this.y})}toJSONClone(e=J){var i,s,l,o,d;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||ht(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(s=e.seenEntities)!=null&&s.has(t)||(l=e.seenEntities)!=null&&l.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(d=e.seenEntities)==null||d.add(this.id),{id:t,version:m.UUID.uuid(),createdAt:e.timestamp||T().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,implements:this.implements,functions:this.functions.map(u=>u.toJSONClone({...e,newId:null})),events:this.events.map(u=>u.toJSONClone({...e,newId:null})),parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps}),x:this.x,y:this.y})}toReference(e=J){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+m.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=J){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,x:this.x,y:this.y,implements:this.implements,functions:this.functions.map(s=>s.toReference(e)),events:this.events.map(s=>s.toReference(e)),parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.functions.flatMap(i=>i.toFlatJSON(e)),...this.events.flatMap(i=>i.toFlatJSON(e))])}toGenerationTarget(){return{id:this.id,name:this.name,description:this.description,type:this.type,implements:this.implements.id}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...this.functions.flatMap(i=>i.toFlatGenerationTarget(e)),...this.events.flatMap(i=>i.toFlatGenerationTarget(e))])}clearErrors(){return this.errors=[],this.functions.forEach(e=>e.clearErrors()),this.events.forEach(e=>e.clearErrors()),this}validate(){const e=P1(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){return[...this.errors,...this.functions.flatMap(t=>t.getErrors()),...this.events.flatMap(t=>t.getErrors())]}getShallowErrors(){return this.errors}clone(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"clone-entity")),t=null,i=null,s=!0){var O,P;let l=mt(t,this);const o=this.toJSON(),d=i||m.UUID.uuid();o.functions=[],o.events=[];const u=d.split("-id"),y=u[u.length-1||0]||d;o.id=d,o.version=m.UUID.uuid(),o.createdAt=(e==null?void 0:e.timestamp)||T().toISOString(),o.author=(e==null?void 0:e.author)||"1",o.previousVersion=null,o.deleted=!1;const c=nt(o,l);t&&c.setParent(t,null),s&&c.subscribe(),c.initChildren(e),e==null||e.add(c,b.Added);const E=(O=this.functions)==null?void 0:O.map((V,M)=>V.clone(e,c,y+"-exported-function-declaration-"+M+"-id",s));c.functions=E;const I=(P=this.events)==null?void 0:P.map((V,M)=>V.clone(e,c,y+"-exported-event-"+M+"-id",s));return c.events=I,e==null||e.attemptAutoclose("clone-entity",this.id),c}};f(Ze,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>e,APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...i)=>null}),f(Ze,"type",n.InstalledProject),f(Ze,"USER_MANAGED_PARENT_TYPES",[n.Project]),f(Ze,"PARENT_TYPES",[...Ze.USER_MANAGED_PARENT_TYPES]),f(Ze,"MUTABLE_BASE_PROPERTIES",[]),f(Ze,"INMUTABLE_BASE_PROPERTIES",["id","version","name","description","type","createdAt","author","previousVersion"]),f(Ze,"BASE_PROPERTIES",[...Ze.MUTABLE_BASE_PROPERTIES,...Ze.INMUTABLE_BASE_PROPERTIES]),f(Ze,"MUTABLE_META_PROPERTIES",["x","y"]),f(Ze,"INMUTABLE_META_PROPERTIES",[...Ze.INMUTABLE_BASE_PROPERTIES]),f(Ze,"META_PROPERTIES",[...Ze.MUTABLE_META_PROPERTIES,...Ze.INMUTABLE_META_PROPERTIES]),f(Ze,"MUTABLE_UPSTREAM_PROPERTIES",[]),f(Ze,"INMUTABLE_UPSTREAM_PROPERTIES",["implements","parent"]),f(Ze,"UPSTREAM_PROPERTIES",[...Ze.MUTABLE_UPSTREAM_PROPERTIES,...Ze.INMUTABLE_UPSTREAM_PROPERTIES]),f(Ze,"MUTABLE_DOWNSTREAM_PROPERTIES",["functions","events"]),f(Ze,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),f(Ze,"DOWNSTREAM_PROPERTIES",[...Ze.MUTABLE_DOWNSTREAM_PROPERTIES,...Ze.INMUTABLE_DOWNSTREAM_PROPERTIES]),f(Ze,"PROPERTIES",[...Ze.META_PROPERTIES,...Ze.UPSTREAM_PROPERTIES,...Ze.DOWNSTREAM_PROPERTIES]);let Kr=Ze;function w1(r){var o;const a=Y5(),e=r.toJSON();a.safeParse(e).success,r.inputs.forEach(d=>d.validate()),r.outputs.forEach(d=>d.validate()),(o=r.error)==null||o.validate();const i=Ar(r),s=C1(r),l=[...i,...s];return Ke(r.errors,l)}function C1(r){const a=[],e=jl(r.parent,null),t=e==null?void 0:e.entity;if(!t)a.push(de({id:`${r.id}--${$.InternalCallParentMissingDataType}`,code:$.InternalCallParentMissingDataType,severity:D.Error,message:`Entity of type "${r.type}" with id "${r.id}", belongs to a variable whose data type entity doesn't contain its declaration method (function-declaration) its id "${r.declaration}".`,issue:null,entity:r}).error);else if(![n.DefinitionEntity,n.BuiltInBaseEntity,n.PrimitiveEntity].includes(t.type))a.push(de({id:`${r.id}--${$.InternalCallParentDeclarationEntityInvalidType}`,code:$.InternalCallParentDeclarationEntityInvalidType,severity:D.Error,message:`Entity of type "${r.type}" with id "${r.id}", belongs to a variable whose data type 'entity' is not a definition entity, built-in base entity or primitive entity.
112
112
  This variable's data-type has an 'entity' field that references an entity with id '${t.id}' and of type '${t.type}'.`,issue:null,entity:r}).error);else{const i=Ua(t),s=[];[n.DefinitionEntity,n.BuiltInBaseEntity,n.PrimitiveEntity].includes(t.type)&&s.push(...t.getAllInteractiveMethods());let l="";i?t.methods.length?l=`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elyx-code/project-logic-tree",
3
- "version": "0.0.6239",
3
+ "version": "0.0.6240",
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",