@elyx-code/project-logic-tree 0.0.6319 → 0.0.6320

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
@@ -39231,7 +39231,7 @@ This is likely an incorrect strategy, either the '${this.type}' entity doesn't n
39231
39231
  this.implements ? s = l.filter(
39232
39232
  (t) => {
39233
39233
  var m;
39234
- return this.implements.id === ((m = t.implements) == null ? void 0 : m.id);
39234
+ return this.implements.id === ((m = t.implements) == null ? void 0 : m.id) && t.id !== this.id;
39235
39235
  }
39236
39236
  ) : s = l.filter(
39237
39237
  (t) => ce(t, this.project) === ce(this, this.project) && t.id !== this.id
@@ -76,7 +76,7 @@ ${ue}`,issue:null})):p.push(new Y({id:`${l.id}--${le.NoOverlapWithImplementedSig
76
76
  Adding a new return would make the implementation invalid. There are no returns in the descriptor with the same name.
77
77
  ${re}
78
78
  ${ue}`,issue:null}))}}}}return p.push(...t.errors,...m,...ur(l)),{errors:p,modifiedData:l}}get codeNativeValueValidation(){var s;return this._codeNativeValueValidation||((s=this.implements)==null?void 0:s.codeNativeValueValidation)||null}validateGeneratedUpdate(s){const a=[];let l=JSON.parse(JSON.stringify(s));const p=Qc(l,this);return l=p.modifiedData,a.push(...p.errors),l.parent&&a.push(new Y({id:`${this.id}--${k.InvalidParentUpdate}`,code:k.InvalidParentUpdate,severity:S.Error,message:`Entity of type '${this.type}' with id '${this.id}' cannot have the 'parent' property updated, as it would mean moving the '${this.type}' entity to another parent entity.
79
- This is likely an incorrect strategy, either the '${this.type}' entity doesn't need to be updated or it should be deleted and a new one created in the desired parent.`,issue:null})),{errors:a,modifiedData:l}}subscribeDependents(s){return s.forEach(a=>{this.detachedDependents[a.entity.id]||(this.detachedDependents[a.entity.id]=a)}),this}unsubscribeDependents(s){return s.forEach(a=>{this.detachedDependents[a.entity.id]&&delete this.detachedDependents[a.entity.id]}),this}syncDependents(s=this.project.addChangeSet(new F(this.project,P.sessionAuthor,N().toISOString(),this,!0,"sync-dependents"))){const a=[],l=[],p=[],t=[];return Object.values(this.detachedDependents).forEach(m=>{const v=m.entity.afterAllChildrenInitialized(s);a.push(...v.updated),l.push(...v.added),p.push(...v.removed),t.push(...v.affected)}),s==null||s.attemptAutoclose("sync-dependents",this.id),{updated:w(a),added:w(l),removed:w(p),affected:w(t),self:this}}onDetachedDependencyRemoved(s,a,l){const p=[],t=[],m=[],v=[];return a==="implements"&&(this.setImplements(null,l),p.push(this)),{updated:w(p),added:w(t),removed:w(m),affected:w(v),self:this}}onDetachedDependencyRestored(s,a,l){const p=[],t=[],m=[],v=[];return a==="implements"&&(this.setImplements(s,l),p.push(this)),{updated:w(p),added:w(t),removed:w(m),affected:w(v),self:this}}unsubscribeFromDependencies(){var s,a,l,p,t;return(a=(s=this.implements)==null?void 0:s.unsubscribeDependents)==null||a.call(s,[{entity:this,field:"implements"}]),(t=(p=(l=this.dataType)==null?void 0:l.entity)==null?void 0:p.unsubscribeDependents)==null||t.call(p,[{entity:this,field:"data-type-entity"}]),this}subscribeToDependencies(){var s,a,l,p,t;return(a=(s=this.implements)==null?void 0:s.subscribeDependents)==null||a.call(s,[{entity:this,field:"implements"}]),(t=(p=(l=this.dataType)==null?void 0:l.entity)==null?void 0:p.subscribeDependents)==null||t.call(p,[{entity:this,field:"data-type-entity"}]),this}increaseVersion(s){if(s&&!N(s).isValid())throw new Error(`The shared timestamp '${s}' is not a valid ISO 8601 date string.`);return s&&N(s).isSame(N(this.createdAt))?this:(this.previousVersion=this.version,this.version=P.UUID.uuid(),this.createdAt=N(s).toISOString()||N().toISOString(),this)}captureVersion(){var a;const s=((a=this.knownVersions)==null?void 0:a.get(this.version))||new yt(this,this.project);return s.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,s):new Map([[this.version,s]]),s.defaultValue=this.defaultValue,s.dataType=this.dataType,s.readsValue=this.readsValue,s.implements=this.implements,s.parent=this.parent,this}recursiveCaptureUpstreamVersions(s){const a=[],l=[],p=[],t=[];if(this.parent){this.parent.increaseVersion(s);const m=this.parent.recursiveCaptureUpstreamVersions(s);a.push(this.parent,...m.updated),l.push(...m.added),p.push(...m.removed)}return{updated:w(a),added:w(l),removed:w(p),affected:w(t),self:this}}async restoreVersion(s){var v;const a=[],l=[],p=[],t=[];if(this.version===s)return{updated:w(a),added:w(l),removed:w(p),affected:w(t),self:this};if(!this.knownVersions){const b=new Map;for(const[_,I]of this.knownVersions||new Map){if(b.set(_,I),I.activeVersion=!1,I.knownVersions)for(const[V,B]of I.knownVersions)b.set(V,B);I.knownVersions=null}}let m=(v=this.knownVersions)==null?void 0:v.get(s);if(!m){const b=await this.APILoadVersion({},s);if(!b)throw new Error(`Version with id '${s}' for entity with id '${this.id}' not found.`);m=new yt(b,this.project)}return this.metaSync(m.toShallowJSON(),null),this.previousVersion=m.previousVersion,this.version=m.version,this.createdAt=m.createdAt,this.author=m.author,this.deleted=m.deleted,this.defaultValue=m.defaultValue,this.dataType=m.dataType,this.readsValue=m.readsValue,this.implements=m.implements,this.parent=m.parent,{updated:w(a),added:w(l),removed:w(p),affected:w(t),self:this}}updateWithShallowTransfer(s,a=this.project.addChangeSet(new F(this.project,P.sessionAuthor,N().toISOString(),this,!0,"update-with-shallow-transfer"))){if(this.metaSync(s,a),this.version=s.version,this.createdAt=s.createdAt,this.author=s.author,this.deleted=s.deleted,this.previousVersion=s.previousVersion,this.unsubscribeFromDependencies(),s.parent){const l=W(s.parent),p=this.project.get(l),t=this.parent;if(t&&t.id!==(p==null?void 0:p.id)&&this.removeFromParent(a),p)this.setParent(p,a);else throw a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(s.readsValue){const l=W(s.readsValue),p=this.project.get(l),t=this.readsValue;t&&t.id!==(p==null?void 0:p.id)&&this.removeValueWriter(a),p&&this.setValueWriter(p,a)}if(s.implements){const l=W(s.implements),p=this.project.get(l);p&&this.setImplements(p,a)}return this.captureVersion(),this.subscribeToDependencies(),a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),this}hydrateAncestors(){const s=[],a=[],l=[],p=[];if(this.initialData.parent){const t=W(this.initialData.parent),m=this.project.get(t);if(m)this.setParent(m,null),s.push(m);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${t}' 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 t=W(this.initialData.readsValue),m=this.project.get(t);m&&(this.setValueWriter(m,null),s.push(m))}if(this.initialData.implements){const t=W(this.initialData.implements),m=this.project.get(t);m&&(this.setImplements(m,null),s.push(m))}return{updated:w(s),added:w(a),removed:w(l),affected:w(p),self:this}}afterAllChildrenInitialized(s=this.project.addChangeSet(new F(this.project,P.sessionAuthor,N().toISOString(),this,!0,"after-all-children-initialized"))){const a=[],l=[],p=[],t=[];return this.initialized=!0,this.captureVersion(),s==null||s.attemptAutoclose("after-all-children-initialized",this.id),{updated:w(a),added:w(l),removed:w(p),affected:w(t),self:this}}addSelfToProject(s=this.project.addChangeSet(new F(this.project,P.sessionAuthor,N().toISOString(),this,!0,"add-self-to-project"))){var m;const a=[this],l=[],p=[],t=[];return this.isError?this.parent.throws=this:this.parent.addOutputDeclaration(this,s),t.push(this.parent),(m=this.readsValue)==null||m.addValueReader(this,s),this.readsValue&&a.push(this.readsValue),this.subscribe(),this.subscribeToDependencies(),s==null||s.attemptAutoclose("add-self-to-project",this.id),{updated:w(a),added:w(l),removed:w(p),affected:w(t),self:this}}propagateChanges(){const s=[this],a=[],l=[],p=[];if(this.parent&&[f.BreakStatement,f.ContinueStatement].includes(this.parent.type)){const t=this.parent.parent,{updated:m,added:v,removed:b}=t.syncChildren();s.push(...m),a.push(...v),l.push(...b)}return{updated:w(s),added:w(a),removed:w(l),affected:w(p),self:this}}setParent(s,a=this.project.addChangeSet(new F(this.project,P.sessionAuthor,N().toISOString(),this,!0,"set-parent"))){var l;return((l=this.parent)==null?void 0:l.id)!==(s==null?void 0:s.id)&&(this.parent=s,a&&(a==null||a.add(this,G.Updated))),a==null||a.attemptAutoclose("set-parent",this.id),this}setImplements(s,a=this.project.addChangeSet(new F(this.project,P.sessionAuthor,N().toISOString(),this,!0,"set-implements"))){var l;return((l=this.implements)==null?void 0:l.id)!==(s==null?void 0:s.id)&&(this.implements=s,a&&(a==null||a.add(this,G.Updated))),a==null||a.attemptAutoclose("set-implements",this.id),this}initChildren(s=this.project.addChangeSet(new F(this.project,P.sessionAuthor,N().toISOString(),this,!0,"init-children"))){if(this.initialized||this.startedInitialization)return this;if(this.startedInitialization=!0,this.initialData.defaultValue&&(this.defaultValue=z(this.initialData.defaultValue,this.project),this.defaultValue.setParent(this,null),this.defaultValue.initChildren(s)),this.initialData.dataType){const a=z(this.initialData.dataType,this.project);a.setParent(this,null),a.initChildren(s),this.dataType=a}if(this.initialData.implements){const a=z(this.initialData.implements,this.project);this.setImplements(a,null)}return dp.initReadsValue(this),this.subscribeToDependencies(),this.afterAllChildrenInitialized(s),s==null||s.attemptAutoclose("init-children",this.id),this}setValueWriter(s,a=this.project.addChangeSet(new F(this.project,P.sessionAuthor,N().toISOString(),this,!0,"set-value-writer"))){return this.readsValue!==s&&(this.readsValue=s,a==null||a.add(this,G.Updated)),a==null||a.attemptAutoclose("set-value-writer",this.id),this}removeValueWriter(s=this.project.addChangeSet(new F(this.project,P.sessionAuthor,N().toISOString(),this,!0,"remove-value-writer"))){return this.readsValue&&(this.readsValue=null,s==null||s.add(this,G.Updated)),s==null||s.attemptAutoclose("remove-value-writer",this.id),this}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(s,a=this.project.addChangeSet(new F(this.project,P.sessionAuthor,N().toISOString(),this,!0,"meta-sync"))){const l=cr(this,s),p=this.toMeta();return this.index=s.index||(s.index!==0?p.index:0),this.name=s.name!==void 0?s.name:p.name,this.description=s.description!==void 0?s.description:p.description,this.required=s.required!==void 0?s.required:this.required,this.isError=s.isError!==void 0?s.isError:this.isError,this.constant=s.constant!==void 0?s.constant:p.constant,this.required=s.required!==void 0?s.required:p.required,super.metaSync(s),s.deleted===!0&&!p.deleted?a==null||a.add(this,G.Removed):s.deleted===!1&&p.deleted?a==null||a.add(this,G.Added):l&&(a==null||a.add(this,G.Updated)),a==null||a.attemptAutoclose("meta-sync",this.id),this}async APILoad(s=oe,...a){return await yt.repository.APILoad(this.id,...a),this}async APICreate(s=oe,...a){return await yt.repository.APICreate(this.toShallowJSON(),...a),this}async APIUpdate(s=oe,...a){return await yt.repository.APIUpdate(this.toShallowJSON(),...a),this}async APIDelete(s=oe,...a){return await yt.repository.APIDelete(this.toShallowJSON(),...a),this}async APIClone(s=oe,...a){return await yt.repository.APIClone(this.id,...a),this}async APILoadVersion(s=oe,a,...l){return await yt.repository.APILoadVersion(this.id,a,...l)}removeFromParent(s=this.project.addChangeSet(new F(this.project,P.sessionAuthor,N().toISOString(),this,!0,"remove-from-parent"))){const a=[],l=[],p=[],t=[];return this.isError?(this.parent.throws=null,s==null||s.add(this.parent,G.Updated),t.push(this.parent)):(this.parent.removeOutputDeclaration(this,s),t.push(this.parent)),s==null||s.attemptAutoclose("remove-from-parent",this.id),{added:w(p),updated:w(a),removed:w(l),affected:w(t),self:this}}remove({ignoreUpstream:s}={ignoreUpstream:!1},a=this.project.addChangeSet(new F(this.project,P.sessionAuthor,N().toISOString(),this,!0,"remove-entity"))){const l=[],p=[],t=[],m=[];if(a!=null&&a.hasRemoved(this.id))return a==null||a.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(p.push(this),this.unsubscribe(),this.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},a),Object.values(this.detachedDependents).forEach(v=>{const{updated:b,removed:_,added:I}=v.entity.onDetachedDependencyRemoved(this,v.field,a);l.push(...b),p.push(..._),t.push(...I)}),this.defaultValue){const{updated:v,removed:b}=this.defaultValue.remove({ignoreUpstream:!0},a);l.push(...v),p.push(...b)}if(this.dataType){const v=this.dataType.remove({ignoreUpstream:!0},a);l.push(...v.updated),p.push(...v.removed)}if([f.BreakStatement,f.ContinueStatement].includes(this.parent.type)){const v=this.getCounterparts();v.length&&v.forEach(b=>{if((!(a!=null&&a.hasRemoved(b.id))||!a)&&!b.deleted){const{updated:_,removed:I,added:V,affected:B}=b.remove({ignoreUpstream:s},a);l.push(..._),p.push(...I),t.push(...V),m.push(...B)}})}if(!s&&this.parent){const v=this.removeFromParent(a);t.push(...v.added),l.push(...v.updated),p.push(...v.removed),m.push(...v.affected)}if(!s&&this.parent&&[f.BreakStatement,f.ContinueStatement].includes(this.parent.type)&&this.parent.parent&&this.parent.parent.type===f.Loop&&(a==null?void 0:a.self)===this&&this.parent.parent.afterAllChildrenInitialized(a),this.isError&&this.parent.type===f.ReturnStatement){const{updated:v,added:b,removed:_,affected:I}=this.parent.syncReturnDeclarations(a);l.push(...v),t.push(...b),p.push(..._),m.push(...I)}return a==null||a.attemptAutoclose("remove-entity",this.id),{added:w(t),updated:w(l),removed:w(p),affected:w(m),self:this}}restore({}={},s=this.project.addChangeSet(new F(this.project,P.sessionAuthor,N().toISOString(),this,!0,"restore-entity"))){const a=[],l=[],p=[],t=[];if(s!=null&&s.hasAdded(this.id))return s==null||s.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},s),Object.values(this.detachedDependents).forEach(m=>{const{updated:v,removed:b,added:_}=m.entity.onDetachedDependencyRestored(this,m.field,s);l.push(...v),p.push(...b),a.push(..._)}),this.defaultValue){const{updated:m}=this.defaultValue.restore({},s);l.push(...m)}if(this.dataType){const m=this.dataType.restore({},s);l.push(...m.updated)}return this.parent&&this.parent.addOutputDeclaration(this,s),s==null||s.attemptAutoclose("restore-entity",this.id),{added:w(a),updated:w(l),removed:w(p),affected:w(t),self:this}}toFlat(s=new Set){var l,p,t;return s.has(this.id)?[]:(s.add(this.id),[this,...((l=this.defaultValue)==null?void 0:l.toFlat(s))||[],...((p=this.readsValue)==null?void 0:p.toFlat(s))||[],...((t=this.dataType)==null?void 0:t.toFlat(s))||[]])}toFlatIds(s=new Set){var l,p,t;return s.has(this.id)?[]:(s.add(this.id),[this.id,...((l=this.defaultValue)==null?void 0:l.toFlatIds(s))||[],...((p=this.readsValue)==null?void 0:p.toFlatIds(s))||[],...((t=this.dataType)==null?void 0:t.toFlatIds(s))||[]])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,description:this.description,index:this.index,required:this.required,constant:this.constant,isError:this.isError,type:this.type,name:this.name}}toJSON(s=new Set){var a,l,p,t;return s.has(this.id)?this.toReference():(s.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,name:this.name,description:this.description,type:this.type,index:this.index,required:this.required,constant:!0,isError:this.isError,defaultValue:((a=this.defaultValue)==null?void 0:a.toJSON(s))||null,dataType:((l=this.dataType)==null?void 0:l.toJSON(s))||null,implements:((p=this.implements)==null?void 0:p.toJSON(s))||null,readsValue:((t=this.readsValue)==null?void 0:t.toJSON(s))||null,parent:this.parent.toReference()})}toJSONClone(s=Ce){var l,p,t,m,v,b,_,I,V;let a;return(l=s.seenEntityMaps)!=null&&l.has(this.id)?a=s.seenEntityMaps.get(this.id):(a=s.newId||hr(this,this.project,s.uuidStrategy),s.seenEntityMaps&&s.seenEntityMaps.set(this.id,a)),(p=s.seenEntities)!=null&&p.has(a)||(t=s.seenEntities)!=null&&t.has(this.id)?this.toReference({seenEntityMaps:s.seenEntityMaps}):((m=s.seenEntities)==null||m.add(a),(v=s.seenEntities)==null||v.add(this.id),{id:a,version:P.UUID.uuid(),createdAt:s.timestamp||N().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,name:this.name,description:this.description,type:this.type,index:this.index,required:this.required,constant:!0,isError:this.isError,defaultValue:((b=this.defaultValue)==null?void 0:b.toJSONClone({...s,newId:null}))||null,dataType:((_=this.dataType)==null?void 0:_.toJSONClone({...s,newId:null}))||null,implements:((I=this.implements)==null?void 0:I.toJSONClone({...s,newId:null}))||null,readsValue:((V=this.readsValue)==null?void 0:V.toReference({seenEntityMaps:s.seenEntityMaps}))||null,parent:this.parent.toReference({seenEntityMaps:s.seenEntityMaps})})}toReference(s=Ce){var l;let a=this.id;return(l=s.seenEntityMaps)!=null&&l.has(this.id)&&(a=s.seenEntityMaps.get(this.id)),{id:a+"--"+P.UUID.uuid()+"--ref",type:f.GenericReference,entityId:a,version:this.version,entityType:this.type}}toShallowJSON(s=Ce){var l,p,t,m,v;let a=this.id;return(l=s.seenEntityMaps)!=null&&l.has(this.id)&&(a=s.seenEntityMaps.get(this.id)),{id:a,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,name:this.name,description:this.description,type:this.type,index:this.index,required:this.required,constant:!0,isError:this.isError,defaultValue:((p=this.defaultValue)==null?void 0:p.toReference(s))||null,readsValue:((t=this.readsValue)==null?void 0:t.toReference(s))||null,implements:((m=this.implements)==null?void 0:m.toReference(s))||null,dataType:((v=this.dataType)==null?void 0:v.toReference(s))||null,parent:this.parent.toReference(s)}}toFlatJSON(s=new Set){var l,p,t;return s.has(this.id)?[]:(s.add(this.id),[this.toShallowJSON(),...((l=this.defaultValue)==null?void 0:l.toFlatJSON(s))||[],...((p=this.readsValue)==null?void 0:p.toFlatJSON(s))||[],...((t=this.dataType)==null?void 0:t.toFlatJSON(s))||[]])}toGenerationTarget(){var s;return{id:this.id,name:this.name,description:this.description,type:this.type,isError:this.isError,readsValue:(s=this.readsValue)==null?void 0:s.id,required:this.required,parent:this.parent.id}}toFlatGenerationTarget(s=new Set){var l,p,t;return s.has(this.id)?[]:(s.add(this.id),[this.toGenerationTarget(),...((l=this.defaultValue)==null?void 0:l.toFlatGenerationTarget(s))||[],...((p=this.readsValue)==null?void 0:p.toFlatGenerationTarget(s))||[],...((t=this.dataType)==null?void 0:t.toFlatGenerationTarget(s))||[]])}clearErrors(){var s,a;return this.errors=[],(s=this.defaultValue)==null||s.clearErrors(),(a=this.dataType)==null||a.clearErrors(),this}validate(){const s=lM(this);return this.errors=s,{success:!0,error:null,data:this.toJSON()}}getErrors(){var a,l;return[...this.errors,...((a=this.defaultValue)==null?void 0:a.getErrors())||[],...((l=this.dataType)==null?void 0:l.getErrors())||[]]}getShallowErrors(){return this.errors}getDefaultValue(){return this.defaultValue||null}setDefaultValue(s,a=this.project.addChangeSet(new F(this.project,P.sessionAuthor,N().toISOString(),this,!0,"set-default-value"))){const l=this.defaultValue;return(l==null?void 0:l.id)!==(s==null?void 0:s.id)&&(l==null||l.remove({ignoreUpstream:!0},a),this.defaultValue=s,a==null||a.add(this,G.Affected)),a==null||a.attemptAutoclose("set-default-value",this.id),this}clone(s=this.project.addChangeSet(new F(this.project,P.sessionAuthor,N().toISOString(),this,!0,"clone-entity")),a=null,l=null,p=!0){var V,B;let t=yr(a,this);const m=this.toJSON(),v=l||P.UUID.uuid();m.dataType=null,m.id=v,m.version=P.UUID.uuid(),m.createdAt=(s==null?void 0:s.timestamp)||N().toISOString(),m.author=(s==null?void 0:s.author)||"1",m.previousVersion=null,m.deleted=!1;const b=er(m,t);a?b.setParent(a,null):b.setParent(this.parent,null),p&&b.subscribe(),b.initChildren(s),s==null||s.add(b,G.Added);const _=(V=this.dataType)==null?void 0:V.clone(s,b,P.UUID.uuid(),p);b.setDataType(_||null,s);const I=(B=this.defaultValue)==null?void 0:B.clone(s,b,P.UUID.uuid(),p);return b.defaultValue=I||null,s==null||s.attemptAutoclose("clone-entity",this.id),b}setDataType(s,a=this.project.addChangeSet(new F(this.project,P.sessionAuthor,N().toISOString(),this,!0,"set-data-type"))){const l=this.dataType;return(l==null?void 0:l.id)!==(s==null?void 0:s.id)&&(l==null||l.remove({ignoreUpstream:!0},a),this.dataType=s,this.subscribeToDependencies(),a==null||a.add(this,G.Affected)),a==null||a.attemptAutoclose("set-data-type",this.id),this}removeDataType(){return this.dataType=null,this}inferDataType(s=this.project.addChangeSet(new F(this.project,P.sessionAuthor,N().toISOString(),this,!0,"infer-data-type"))){var l;const a=$T(this,s);if(a&&a.parent===this)this.dataType&&this.dataType.merge(a,s);else if(a&&a.parent!==this)if(this.dataType)this.dataType.merge(a,s);else{const p=a.clone(s,this);s==null||s.add(p,G.Added),this.setDataType(p,s)}return(l=this.dataType)==null||l.metaSync({inferred:!0},s),s==null||s.attemptAutoclose("infer-data-type",this.id),this}getCounterparts(){let s=[];if([f.BreakStatement,f.ContinueStatement].includes(this.parent.type)){const a=this.parent.parent;s=[...a.breakStatements,...a.continueStatements].flatMap(t=>t.outputs).filter(t=>fe(t,this.project)===fe(this,this.project)&&t.id!==this.id)}else if(this.parent.type===f.ReturnStatement&&[f.FunctionDeclaration,f.GlobalEvent].includes(this.parent.parent.type)&&this.parent.parent.implements){const l=this.parent.parent.returnStatements.flatMap(p=>p.outputs);this.implements?s=l.filter(t=>{var m;return this.implements.id===((m=t.implements)==null?void 0:m.id)}):s=l.filter(t=>fe(t,this.project)===fe(this,this.project)&&t.id!==this.id)}return s}inferDataTypeFromCounterparts(s=this.project.addChangeSet(new F(this.project,P.sessionAuthor,N().toISOString(),this,!0,"infer-data-type-from-counterparts"))){var p,t,m;const a=this.getCounterparts(),l=a.find(v=>{var b;return(b=v.dataType)==null?void 0:b.isResolved});if(l)this.setDataType(l.dataType,s),s==null||s.add(this,G.Updated);else for(let v=0;v<a.length;v++){const b=a[v];if((!b.dataType||!b.dataType.isResolved||(p=b.dataType)!=null&&p.inferred)&&b.readsValue&&b.inferDataType(s),(t=b.dataType)!=null&&t.isResolved){this.setDataType(b.dataType,s),s==null||s.add(this,G.Updated);break}}return(m=this.dataType)==null||m.metaSync({inferred:!0},s),s==null||s.attemptAutoclose("infer-data-type-from-counterparts",this.id),this}getDataType(s=this.project.addChangeSet(new F(this.project,P.sessionAuthor,N().toISOString(),this,!0,"get-data-type"))){var a;return(!this.dataType||!this.dataType.isResolved||(a=this.dataType)!=null&&a.inferred)&&this.readsValue?this.inferDataType(s):this.inferDataTypeFromCounterparts(s),this.dataType}};g(yt,"repository",{APICreate:async(s,...a)=>s,APIUpdate:async(s,...a)=>s,APIDelete:async(s,...a)=>s,APIClone:async(s,...a)=>{},APILoad:async(s,...a)=>null,APILoadVersion:async(s,a,...l)=>null}),g(yt,"type",f.ReturnDeclaration),g(yt,"USER_MANAGED_PARENT_TYPES",[f.ReturnStatement,f.BreakStatement,f.ContinueStatement]),g(yt,"PARENT_TYPES",[...yt.USER_MANAGED_PARENT_TYPES]),g(yt,"MUTABLE_BASE_PROPERTIES",["name","description","required","isError"]),g(yt,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),g(yt,"BASE_PROPERTIES",[...yt.MUTABLE_BASE_PROPERTIES,...yt.INMUTABLE_BASE_PROPERTIES]),g(yt,"MUTABLE_META_PROPERTIES",[...yt.MUTABLE_BASE_PROPERTIES,"index"]),g(yt,"INMUTABLE_META_PROPERTIES",[...yt.INMUTABLE_BASE_PROPERTIES]),g(yt,"META_PROPERTIES",[...yt.MUTABLE_META_PROPERTIES,...yt.INMUTABLE_META_PROPERTIES]),g(yt,"MUTABLE_UPSTREAM_PROPERTIES",["readsValue"]),g(yt,"INMUTABLE_UPSTREAM_PROPERTIES",["parent"]),g(yt,"UPSTREAM_PROPERTIES",[...yt.MUTABLE_UPSTREAM_PROPERTIES,...yt.INMUTABLE_UPSTREAM_PROPERTIES]),g(yt,"MUTABLE_DOWNSTREAM_PROPERTIES",["dataType","defaultValue"]),g(yt,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),g(yt,"DOWNSTREAM_PROPERTIES",[...yt.MUTABLE_DOWNSTREAM_PROPERTIES,...yt.INMUTABLE_DOWNSTREAM_PROPERTIES]),g(yt,"PROPERTIES",[...yt.META_PROPERTIES,...yt.UPSTREAM_PROPERTIES,...yt.DOWNSTREAM_PROPERTIES]);let wi=yt;function uM(u){var p;const d=Woe(),s=u.toJSON();d.safeParse(s).success,u.outputs.forEach(t=>t.validate()),(p=u.throws)==null||p.validate();const l=[];return qt(u.errors,l)}const cpe=Object.freeze(Object.defineProperty({__proto__:null,validate:uM},Symbol.toStringTag,{value:"Module"}));function cM(u){var p;const d=qoe(),s=u.toJSON();d.safeParse(s).success,u.outputs.forEach(t=>t.validate()),(p=u.throws)==null||p.validate();const l=[];return qt(u.errors,l)}const ppe=Object.freeze(Object.defineProperty({__proto__:null,validate:cM},Symbol.toStringTag,{value:"Module"}));var pM=(u=>(u.Parent="parent",u))(pM||{});const $t=class $t extends nr{constructor(s,a){super(s);g(this,"initialData");g(this,"id");g(this,"x");g(this,"y");g(this,"type",f.ContinueStatement);g(this,"outputs",[]);g(this,"calledBySuccess",[]);g(this,"calledByError",[]);g(this,"calledByEntry",[]);g(this,"throws",null);g(this,"project");g(this,"errors",[]);g(this,"parent");g(this,"detachedDependents",{});g(this,"knownVersions",null);g(this,"activeVersion",!1);g(this,"initialized",!1);g(this,"startedInitialization",!1);g(this,"suggestion",!1);this.initialData=s,this.project=a,this.id=s.id,this.x=s.x,this.y=s.y}static new(s=null){return{id:P.UUID.uuid(),version:P.UUID.uuid(),createdAt:(s==null?void 0:s.timestamp)||N().toISOString(),author:(s==null?void 0:s.author)||P.sessionAuthor,previousVersion:null,deleted:!1,type:f.ContinueStatement,outputs:[],throws:null,parent:null,calledByEntry:[],calledBySuccess:[],calledByError:[],x:0,y:0}}static fromGenerationTarget(s,a){const l=W(s.parent),p=a.get(l),t=s.calledByEntry.map(I=>{const V=W(I);return a.get(V)}),m=s.calledBySuccess.map(I=>{const V=W(I);return a.get(V)}),v=s.calledByError.map(I=>{const V=W(I);return a.get(V)}),b={id:s.id,version:P.UUID.uuid(),createdAt:N().toISOString(),author:P.sessionAuthor,previousVersion:null,deleted:!1,type:f.ContinueStatement,x:0,y:0,outputs:[],calledBySuccess:m,calledByError:v,calledByEntry:t,throws:null,parent:p},_=z(b,a);return _.setParent(p,null),_.initChildren(null),_}static validateGenerationTarget(s,a){let l=JSON.parse(JSON.stringify(s));const p=[],t=Cr(l,{parent:{list:!1,types:[f.Loop]}},a);return l=t.modifiedData,p.push(...t.errors,...ur(l)),{errors:p,modifiedData:l}}validateGeneratedUpdate(s){const a=[];return s.parent&&a.push(new Y({id:`${this.id}--${k.InvalidParentUpdate}`,code:k.InvalidParentUpdate,severity:S.Error,message:`Entity of type '${this.type}' with id '${this.id}' cannot have the 'parent' property updated. The 'parent' on a callable entity, is its scope. It scope is auto-calculated implicitly by the its caller.
79
+ This is likely an incorrect strategy, either the '${this.type}' entity doesn't need to be updated or it should be deleted and a new one created in the desired parent.`,issue:null})),{errors:a,modifiedData:l}}subscribeDependents(s){return s.forEach(a=>{this.detachedDependents[a.entity.id]||(this.detachedDependents[a.entity.id]=a)}),this}unsubscribeDependents(s){return s.forEach(a=>{this.detachedDependents[a.entity.id]&&delete this.detachedDependents[a.entity.id]}),this}syncDependents(s=this.project.addChangeSet(new F(this.project,P.sessionAuthor,N().toISOString(),this,!0,"sync-dependents"))){const a=[],l=[],p=[],t=[];return Object.values(this.detachedDependents).forEach(m=>{const v=m.entity.afterAllChildrenInitialized(s);a.push(...v.updated),l.push(...v.added),p.push(...v.removed),t.push(...v.affected)}),s==null||s.attemptAutoclose("sync-dependents",this.id),{updated:w(a),added:w(l),removed:w(p),affected:w(t),self:this}}onDetachedDependencyRemoved(s,a,l){const p=[],t=[],m=[],v=[];return a==="implements"&&(this.setImplements(null,l),p.push(this)),{updated:w(p),added:w(t),removed:w(m),affected:w(v),self:this}}onDetachedDependencyRestored(s,a,l){const p=[],t=[],m=[],v=[];return a==="implements"&&(this.setImplements(s,l),p.push(this)),{updated:w(p),added:w(t),removed:w(m),affected:w(v),self:this}}unsubscribeFromDependencies(){var s,a,l,p,t;return(a=(s=this.implements)==null?void 0:s.unsubscribeDependents)==null||a.call(s,[{entity:this,field:"implements"}]),(t=(p=(l=this.dataType)==null?void 0:l.entity)==null?void 0:p.unsubscribeDependents)==null||t.call(p,[{entity:this,field:"data-type-entity"}]),this}subscribeToDependencies(){var s,a,l,p,t;return(a=(s=this.implements)==null?void 0:s.subscribeDependents)==null||a.call(s,[{entity:this,field:"implements"}]),(t=(p=(l=this.dataType)==null?void 0:l.entity)==null?void 0:p.subscribeDependents)==null||t.call(p,[{entity:this,field:"data-type-entity"}]),this}increaseVersion(s){if(s&&!N(s).isValid())throw new Error(`The shared timestamp '${s}' is not a valid ISO 8601 date string.`);return s&&N(s).isSame(N(this.createdAt))?this:(this.previousVersion=this.version,this.version=P.UUID.uuid(),this.createdAt=N(s).toISOString()||N().toISOString(),this)}captureVersion(){var a;const s=((a=this.knownVersions)==null?void 0:a.get(this.version))||new yt(this,this.project);return s.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,s):new Map([[this.version,s]]),s.defaultValue=this.defaultValue,s.dataType=this.dataType,s.readsValue=this.readsValue,s.implements=this.implements,s.parent=this.parent,this}recursiveCaptureUpstreamVersions(s){const a=[],l=[],p=[],t=[];if(this.parent){this.parent.increaseVersion(s);const m=this.parent.recursiveCaptureUpstreamVersions(s);a.push(this.parent,...m.updated),l.push(...m.added),p.push(...m.removed)}return{updated:w(a),added:w(l),removed:w(p),affected:w(t),self:this}}async restoreVersion(s){var v;const a=[],l=[],p=[],t=[];if(this.version===s)return{updated:w(a),added:w(l),removed:w(p),affected:w(t),self:this};if(!this.knownVersions){const b=new Map;for(const[_,I]of this.knownVersions||new Map){if(b.set(_,I),I.activeVersion=!1,I.knownVersions)for(const[V,B]of I.knownVersions)b.set(V,B);I.knownVersions=null}}let m=(v=this.knownVersions)==null?void 0:v.get(s);if(!m){const b=await this.APILoadVersion({},s);if(!b)throw new Error(`Version with id '${s}' for entity with id '${this.id}' not found.`);m=new yt(b,this.project)}return this.metaSync(m.toShallowJSON(),null),this.previousVersion=m.previousVersion,this.version=m.version,this.createdAt=m.createdAt,this.author=m.author,this.deleted=m.deleted,this.defaultValue=m.defaultValue,this.dataType=m.dataType,this.readsValue=m.readsValue,this.implements=m.implements,this.parent=m.parent,{updated:w(a),added:w(l),removed:w(p),affected:w(t),self:this}}updateWithShallowTransfer(s,a=this.project.addChangeSet(new F(this.project,P.sessionAuthor,N().toISOString(),this,!0,"update-with-shallow-transfer"))){if(this.metaSync(s,a),this.version=s.version,this.createdAt=s.createdAt,this.author=s.author,this.deleted=s.deleted,this.previousVersion=s.previousVersion,this.unsubscribeFromDependencies(),s.parent){const l=W(s.parent),p=this.project.get(l),t=this.parent;if(t&&t.id!==(p==null?void 0:p.id)&&this.removeFromParent(a),p)this.setParent(p,a);else throw a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(s.readsValue){const l=W(s.readsValue),p=this.project.get(l),t=this.readsValue;t&&t.id!==(p==null?void 0:p.id)&&this.removeValueWriter(a),p&&this.setValueWriter(p,a)}if(s.implements){const l=W(s.implements),p=this.project.get(l);p&&this.setImplements(p,a)}return this.captureVersion(),this.subscribeToDependencies(),a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),this}hydrateAncestors(){const s=[],a=[],l=[],p=[];if(this.initialData.parent){const t=W(this.initialData.parent),m=this.project.get(t);if(m)this.setParent(m,null),s.push(m);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${t}' 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 t=W(this.initialData.readsValue),m=this.project.get(t);m&&(this.setValueWriter(m,null),s.push(m))}if(this.initialData.implements){const t=W(this.initialData.implements),m=this.project.get(t);m&&(this.setImplements(m,null),s.push(m))}return{updated:w(s),added:w(a),removed:w(l),affected:w(p),self:this}}afterAllChildrenInitialized(s=this.project.addChangeSet(new F(this.project,P.sessionAuthor,N().toISOString(),this,!0,"after-all-children-initialized"))){const a=[],l=[],p=[],t=[];return this.initialized=!0,this.captureVersion(),s==null||s.attemptAutoclose("after-all-children-initialized",this.id),{updated:w(a),added:w(l),removed:w(p),affected:w(t),self:this}}addSelfToProject(s=this.project.addChangeSet(new F(this.project,P.sessionAuthor,N().toISOString(),this,!0,"add-self-to-project"))){var m;const a=[this],l=[],p=[],t=[];return this.isError?this.parent.throws=this:this.parent.addOutputDeclaration(this,s),t.push(this.parent),(m=this.readsValue)==null||m.addValueReader(this,s),this.readsValue&&a.push(this.readsValue),this.subscribe(),this.subscribeToDependencies(),s==null||s.attemptAutoclose("add-self-to-project",this.id),{updated:w(a),added:w(l),removed:w(p),affected:w(t),self:this}}propagateChanges(){const s=[this],a=[],l=[],p=[];if(this.parent&&[f.BreakStatement,f.ContinueStatement].includes(this.parent.type)){const t=this.parent.parent,{updated:m,added:v,removed:b}=t.syncChildren();s.push(...m),a.push(...v),l.push(...b)}return{updated:w(s),added:w(a),removed:w(l),affected:w(p),self:this}}setParent(s,a=this.project.addChangeSet(new F(this.project,P.sessionAuthor,N().toISOString(),this,!0,"set-parent"))){var l;return((l=this.parent)==null?void 0:l.id)!==(s==null?void 0:s.id)&&(this.parent=s,a&&(a==null||a.add(this,G.Updated))),a==null||a.attemptAutoclose("set-parent",this.id),this}setImplements(s,a=this.project.addChangeSet(new F(this.project,P.sessionAuthor,N().toISOString(),this,!0,"set-implements"))){var l;return((l=this.implements)==null?void 0:l.id)!==(s==null?void 0:s.id)&&(this.implements=s,a&&(a==null||a.add(this,G.Updated))),a==null||a.attemptAutoclose("set-implements",this.id),this}initChildren(s=this.project.addChangeSet(new F(this.project,P.sessionAuthor,N().toISOString(),this,!0,"init-children"))){if(this.initialized||this.startedInitialization)return this;if(this.startedInitialization=!0,this.initialData.defaultValue&&(this.defaultValue=z(this.initialData.defaultValue,this.project),this.defaultValue.setParent(this,null),this.defaultValue.initChildren(s)),this.initialData.dataType){const a=z(this.initialData.dataType,this.project);a.setParent(this,null),a.initChildren(s),this.dataType=a}if(this.initialData.implements){const a=z(this.initialData.implements,this.project);this.setImplements(a,null)}return dp.initReadsValue(this),this.subscribeToDependencies(),this.afterAllChildrenInitialized(s),s==null||s.attemptAutoclose("init-children",this.id),this}setValueWriter(s,a=this.project.addChangeSet(new F(this.project,P.sessionAuthor,N().toISOString(),this,!0,"set-value-writer"))){return this.readsValue!==s&&(this.readsValue=s,a==null||a.add(this,G.Updated)),a==null||a.attemptAutoclose("set-value-writer",this.id),this}removeValueWriter(s=this.project.addChangeSet(new F(this.project,P.sessionAuthor,N().toISOString(),this,!0,"remove-value-writer"))){return this.readsValue&&(this.readsValue=null,s==null||s.add(this,G.Updated)),s==null||s.attemptAutoclose("remove-value-writer",this.id),this}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(s,a=this.project.addChangeSet(new F(this.project,P.sessionAuthor,N().toISOString(),this,!0,"meta-sync"))){const l=cr(this,s),p=this.toMeta();return this.index=s.index||(s.index!==0?p.index:0),this.name=s.name!==void 0?s.name:p.name,this.description=s.description!==void 0?s.description:p.description,this.required=s.required!==void 0?s.required:this.required,this.isError=s.isError!==void 0?s.isError:this.isError,this.constant=s.constant!==void 0?s.constant:p.constant,this.required=s.required!==void 0?s.required:p.required,super.metaSync(s),s.deleted===!0&&!p.deleted?a==null||a.add(this,G.Removed):s.deleted===!1&&p.deleted?a==null||a.add(this,G.Added):l&&(a==null||a.add(this,G.Updated)),a==null||a.attemptAutoclose("meta-sync",this.id),this}async APILoad(s=oe,...a){return await yt.repository.APILoad(this.id,...a),this}async APICreate(s=oe,...a){return await yt.repository.APICreate(this.toShallowJSON(),...a),this}async APIUpdate(s=oe,...a){return await yt.repository.APIUpdate(this.toShallowJSON(),...a),this}async APIDelete(s=oe,...a){return await yt.repository.APIDelete(this.toShallowJSON(),...a),this}async APIClone(s=oe,...a){return await yt.repository.APIClone(this.id,...a),this}async APILoadVersion(s=oe,a,...l){return await yt.repository.APILoadVersion(this.id,a,...l)}removeFromParent(s=this.project.addChangeSet(new F(this.project,P.sessionAuthor,N().toISOString(),this,!0,"remove-from-parent"))){const a=[],l=[],p=[],t=[];return this.isError?(this.parent.throws=null,s==null||s.add(this.parent,G.Updated),t.push(this.parent)):(this.parent.removeOutputDeclaration(this,s),t.push(this.parent)),s==null||s.attemptAutoclose("remove-from-parent",this.id),{added:w(p),updated:w(a),removed:w(l),affected:w(t),self:this}}remove({ignoreUpstream:s}={ignoreUpstream:!1},a=this.project.addChangeSet(new F(this.project,P.sessionAuthor,N().toISOString(),this,!0,"remove-entity"))){const l=[],p=[],t=[],m=[];if(a!=null&&a.hasRemoved(this.id))return a==null||a.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(p.push(this),this.unsubscribe(),this.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},a),Object.values(this.detachedDependents).forEach(v=>{const{updated:b,removed:_,added:I}=v.entity.onDetachedDependencyRemoved(this,v.field,a);l.push(...b),p.push(..._),t.push(...I)}),this.defaultValue){const{updated:v,removed:b}=this.defaultValue.remove({ignoreUpstream:!0},a);l.push(...v),p.push(...b)}if(this.dataType){const v=this.dataType.remove({ignoreUpstream:!0},a);l.push(...v.updated),p.push(...v.removed)}if([f.BreakStatement,f.ContinueStatement].includes(this.parent.type)){const v=this.getCounterparts();v.length&&v.forEach(b=>{if((!(a!=null&&a.hasRemoved(b.id))||!a)&&!b.deleted){const{updated:_,removed:I,added:V,affected:B}=b.remove({ignoreUpstream:s},a);l.push(..._),p.push(...I),t.push(...V),m.push(...B)}})}if(!s&&this.parent){const v=this.removeFromParent(a);t.push(...v.added),l.push(...v.updated),p.push(...v.removed),m.push(...v.affected)}if(!s&&this.parent&&[f.BreakStatement,f.ContinueStatement].includes(this.parent.type)&&this.parent.parent&&this.parent.parent.type===f.Loop&&(a==null?void 0:a.self)===this&&this.parent.parent.afterAllChildrenInitialized(a),this.isError&&this.parent.type===f.ReturnStatement){const{updated:v,added:b,removed:_,affected:I}=this.parent.syncReturnDeclarations(a);l.push(...v),t.push(...b),p.push(..._),m.push(...I)}return a==null||a.attemptAutoclose("remove-entity",this.id),{added:w(t),updated:w(l),removed:w(p),affected:w(m),self:this}}restore({}={},s=this.project.addChangeSet(new F(this.project,P.sessionAuthor,N().toISOString(),this,!0,"restore-entity"))){const a=[],l=[],p=[],t=[];if(s!=null&&s.hasAdded(this.id))return s==null||s.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},s),Object.values(this.detachedDependents).forEach(m=>{const{updated:v,removed:b,added:_}=m.entity.onDetachedDependencyRestored(this,m.field,s);l.push(...v),p.push(...b),a.push(..._)}),this.defaultValue){const{updated:m}=this.defaultValue.restore({},s);l.push(...m)}if(this.dataType){const m=this.dataType.restore({},s);l.push(...m.updated)}return this.parent&&this.parent.addOutputDeclaration(this,s),s==null||s.attemptAutoclose("restore-entity",this.id),{added:w(a),updated:w(l),removed:w(p),affected:w(t),self:this}}toFlat(s=new Set){var l,p,t;return s.has(this.id)?[]:(s.add(this.id),[this,...((l=this.defaultValue)==null?void 0:l.toFlat(s))||[],...((p=this.readsValue)==null?void 0:p.toFlat(s))||[],...((t=this.dataType)==null?void 0:t.toFlat(s))||[]])}toFlatIds(s=new Set){var l,p,t;return s.has(this.id)?[]:(s.add(this.id),[this.id,...((l=this.defaultValue)==null?void 0:l.toFlatIds(s))||[],...((p=this.readsValue)==null?void 0:p.toFlatIds(s))||[],...((t=this.dataType)==null?void 0:t.toFlatIds(s))||[]])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,description:this.description,index:this.index,required:this.required,constant:this.constant,isError:this.isError,type:this.type,name:this.name}}toJSON(s=new Set){var a,l,p,t;return s.has(this.id)?this.toReference():(s.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,name:this.name,description:this.description,type:this.type,index:this.index,required:this.required,constant:!0,isError:this.isError,defaultValue:((a=this.defaultValue)==null?void 0:a.toJSON(s))||null,dataType:((l=this.dataType)==null?void 0:l.toJSON(s))||null,implements:((p=this.implements)==null?void 0:p.toJSON(s))||null,readsValue:((t=this.readsValue)==null?void 0:t.toJSON(s))||null,parent:this.parent.toReference()})}toJSONClone(s=Ce){var l,p,t,m,v,b,_,I,V;let a;return(l=s.seenEntityMaps)!=null&&l.has(this.id)?a=s.seenEntityMaps.get(this.id):(a=s.newId||hr(this,this.project,s.uuidStrategy),s.seenEntityMaps&&s.seenEntityMaps.set(this.id,a)),(p=s.seenEntities)!=null&&p.has(a)||(t=s.seenEntities)!=null&&t.has(this.id)?this.toReference({seenEntityMaps:s.seenEntityMaps}):((m=s.seenEntities)==null||m.add(a),(v=s.seenEntities)==null||v.add(this.id),{id:a,version:P.UUID.uuid(),createdAt:s.timestamp||N().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,name:this.name,description:this.description,type:this.type,index:this.index,required:this.required,constant:!0,isError:this.isError,defaultValue:((b=this.defaultValue)==null?void 0:b.toJSONClone({...s,newId:null}))||null,dataType:((_=this.dataType)==null?void 0:_.toJSONClone({...s,newId:null}))||null,implements:((I=this.implements)==null?void 0:I.toJSONClone({...s,newId:null}))||null,readsValue:((V=this.readsValue)==null?void 0:V.toReference({seenEntityMaps:s.seenEntityMaps}))||null,parent:this.parent.toReference({seenEntityMaps:s.seenEntityMaps})})}toReference(s=Ce){var l;let a=this.id;return(l=s.seenEntityMaps)!=null&&l.has(this.id)&&(a=s.seenEntityMaps.get(this.id)),{id:a+"--"+P.UUID.uuid()+"--ref",type:f.GenericReference,entityId:a,version:this.version,entityType:this.type}}toShallowJSON(s=Ce){var l,p,t,m,v;let a=this.id;return(l=s.seenEntityMaps)!=null&&l.has(this.id)&&(a=s.seenEntityMaps.get(this.id)),{id:a,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,name:this.name,description:this.description,type:this.type,index:this.index,required:this.required,constant:!0,isError:this.isError,defaultValue:((p=this.defaultValue)==null?void 0:p.toReference(s))||null,readsValue:((t=this.readsValue)==null?void 0:t.toReference(s))||null,implements:((m=this.implements)==null?void 0:m.toReference(s))||null,dataType:((v=this.dataType)==null?void 0:v.toReference(s))||null,parent:this.parent.toReference(s)}}toFlatJSON(s=new Set){var l,p,t;return s.has(this.id)?[]:(s.add(this.id),[this.toShallowJSON(),...((l=this.defaultValue)==null?void 0:l.toFlatJSON(s))||[],...((p=this.readsValue)==null?void 0:p.toFlatJSON(s))||[],...((t=this.dataType)==null?void 0:t.toFlatJSON(s))||[]])}toGenerationTarget(){var s;return{id:this.id,name:this.name,description:this.description,type:this.type,isError:this.isError,readsValue:(s=this.readsValue)==null?void 0:s.id,required:this.required,parent:this.parent.id}}toFlatGenerationTarget(s=new Set){var l,p,t;return s.has(this.id)?[]:(s.add(this.id),[this.toGenerationTarget(),...((l=this.defaultValue)==null?void 0:l.toFlatGenerationTarget(s))||[],...((p=this.readsValue)==null?void 0:p.toFlatGenerationTarget(s))||[],...((t=this.dataType)==null?void 0:t.toFlatGenerationTarget(s))||[]])}clearErrors(){var s,a;return this.errors=[],(s=this.defaultValue)==null||s.clearErrors(),(a=this.dataType)==null||a.clearErrors(),this}validate(){const s=lM(this);return this.errors=s,{success:!0,error:null,data:this.toJSON()}}getErrors(){var a,l;return[...this.errors,...((a=this.defaultValue)==null?void 0:a.getErrors())||[],...((l=this.dataType)==null?void 0:l.getErrors())||[]]}getShallowErrors(){return this.errors}getDefaultValue(){return this.defaultValue||null}setDefaultValue(s,a=this.project.addChangeSet(new F(this.project,P.sessionAuthor,N().toISOString(),this,!0,"set-default-value"))){const l=this.defaultValue;return(l==null?void 0:l.id)!==(s==null?void 0:s.id)&&(l==null||l.remove({ignoreUpstream:!0},a),this.defaultValue=s,a==null||a.add(this,G.Affected)),a==null||a.attemptAutoclose("set-default-value",this.id),this}clone(s=this.project.addChangeSet(new F(this.project,P.sessionAuthor,N().toISOString(),this,!0,"clone-entity")),a=null,l=null,p=!0){var V,B;let t=yr(a,this);const m=this.toJSON(),v=l||P.UUID.uuid();m.dataType=null,m.id=v,m.version=P.UUID.uuid(),m.createdAt=(s==null?void 0:s.timestamp)||N().toISOString(),m.author=(s==null?void 0:s.author)||"1",m.previousVersion=null,m.deleted=!1;const b=er(m,t);a?b.setParent(a,null):b.setParent(this.parent,null),p&&b.subscribe(),b.initChildren(s),s==null||s.add(b,G.Added);const _=(V=this.dataType)==null?void 0:V.clone(s,b,P.UUID.uuid(),p);b.setDataType(_||null,s);const I=(B=this.defaultValue)==null?void 0:B.clone(s,b,P.UUID.uuid(),p);return b.defaultValue=I||null,s==null||s.attemptAutoclose("clone-entity",this.id),b}setDataType(s,a=this.project.addChangeSet(new F(this.project,P.sessionAuthor,N().toISOString(),this,!0,"set-data-type"))){const l=this.dataType;return(l==null?void 0:l.id)!==(s==null?void 0:s.id)&&(l==null||l.remove({ignoreUpstream:!0},a),this.dataType=s,this.subscribeToDependencies(),a==null||a.add(this,G.Affected)),a==null||a.attemptAutoclose("set-data-type",this.id),this}removeDataType(){return this.dataType=null,this}inferDataType(s=this.project.addChangeSet(new F(this.project,P.sessionAuthor,N().toISOString(),this,!0,"infer-data-type"))){var l;const a=$T(this,s);if(a&&a.parent===this)this.dataType&&this.dataType.merge(a,s);else if(a&&a.parent!==this)if(this.dataType)this.dataType.merge(a,s);else{const p=a.clone(s,this);s==null||s.add(p,G.Added),this.setDataType(p,s)}return(l=this.dataType)==null||l.metaSync({inferred:!0},s),s==null||s.attemptAutoclose("infer-data-type",this.id),this}getCounterparts(){let s=[];if([f.BreakStatement,f.ContinueStatement].includes(this.parent.type)){const a=this.parent.parent;s=[...a.breakStatements,...a.continueStatements].flatMap(t=>t.outputs).filter(t=>fe(t,this.project)===fe(this,this.project)&&t.id!==this.id)}else if(this.parent.type===f.ReturnStatement&&[f.FunctionDeclaration,f.GlobalEvent].includes(this.parent.parent.type)&&this.parent.parent.implements){const l=this.parent.parent.returnStatements.flatMap(p=>p.outputs);this.implements?s=l.filter(t=>{var m;return this.implements.id===((m=t.implements)==null?void 0:m.id)&&t.id!==this.id}):s=l.filter(t=>fe(t,this.project)===fe(this,this.project)&&t.id!==this.id)}return s}inferDataTypeFromCounterparts(s=this.project.addChangeSet(new F(this.project,P.sessionAuthor,N().toISOString(),this,!0,"infer-data-type-from-counterparts"))){var p,t,m;const a=this.getCounterparts(),l=a.find(v=>{var b;return(b=v.dataType)==null?void 0:b.isResolved});if(l)this.setDataType(l.dataType,s),s==null||s.add(this,G.Updated);else for(let v=0;v<a.length;v++){const b=a[v];if((!b.dataType||!b.dataType.isResolved||(p=b.dataType)!=null&&p.inferred)&&b.readsValue&&b.inferDataType(s),(t=b.dataType)!=null&&t.isResolved){this.setDataType(b.dataType,s),s==null||s.add(this,G.Updated);break}}return(m=this.dataType)==null||m.metaSync({inferred:!0},s),s==null||s.attemptAutoclose("infer-data-type-from-counterparts",this.id),this}getDataType(s=this.project.addChangeSet(new F(this.project,P.sessionAuthor,N().toISOString(),this,!0,"get-data-type"))){var a;return(!this.dataType||!this.dataType.isResolved||(a=this.dataType)!=null&&a.inferred)&&this.readsValue?this.inferDataType(s):this.inferDataTypeFromCounterparts(s),this.dataType}};g(yt,"repository",{APICreate:async(s,...a)=>s,APIUpdate:async(s,...a)=>s,APIDelete:async(s,...a)=>s,APIClone:async(s,...a)=>{},APILoad:async(s,...a)=>null,APILoadVersion:async(s,a,...l)=>null}),g(yt,"type",f.ReturnDeclaration),g(yt,"USER_MANAGED_PARENT_TYPES",[f.ReturnStatement,f.BreakStatement,f.ContinueStatement]),g(yt,"PARENT_TYPES",[...yt.USER_MANAGED_PARENT_TYPES]),g(yt,"MUTABLE_BASE_PROPERTIES",["name","description","required","isError"]),g(yt,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),g(yt,"BASE_PROPERTIES",[...yt.MUTABLE_BASE_PROPERTIES,...yt.INMUTABLE_BASE_PROPERTIES]),g(yt,"MUTABLE_META_PROPERTIES",[...yt.MUTABLE_BASE_PROPERTIES,"index"]),g(yt,"INMUTABLE_META_PROPERTIES",[...yt.INMUTABLE_BASE_PROPERTIES]),g(yt,"META_PROPERTIES",[...yt.MUTABLE_META_PROPERTIES,...yt.INMUTABLE_META_PROPERTIES]),g(yt,"MUTABLE_UPSTREAM_PROPERTIES",["readsValue"]),g(yt,"INMUTABLE_UPSTREAM_PROPERTIES",["parent"]),g(yt,"UPSTREAM_PROPERTIES",[...yt.MUTABLE_UPSTREAM_PROPERTIES,...yt.INMUTABLE_UPSTREAM_PROPERTIES]),g(yt,"MUTABLE_DOWNSTREAM_PROPERTIES",["dataType","defaultValue"]),g(yt,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),g(yt,"DOWNSTREAM_PROPERTIES",[...yt.MUTABLE_DOWNSTREAM_PROPERTIES,...yt.INMUTABLE_DOWNSTREAM_PROPERTIES]),g(yt,"PROPERTIES",[...yt.META_PROPERTIES,...yt.UPSTREAM_PROPERTIES,...yt.DOWNSTREAM_PROPERTIES]);let wi=yt;function uM(u){var p;const d=Woe(),s=u.toJSON();d.safeParse(s).success,u.outputs.forEach(t=>t.validate()),(p=u.throws)==null||p.validate();const l=[];return qt(u.errors,l)}const cpe=Object.freeze(Object.defineProperty({__proto__:null,validate:uM},Symbol.toStringTag,{value:"Module"}));function cM(u){var p;const d=qoe(),s=u.toJSON();d.safeParse(s).success,u.outputs.forEach(t=>t.validate()),(p=u.throws)==null||p.validate();const l=[];return qt(u.errors,l)}const ppe=Object.freeze(Object.defineProperty({__proto__:null,validate:cM},Symbol.toStringTag,{value:"Module"}));var pM=(u=>(u.Parent="parent",u))(pM||{});const $t=class $t extends nr{constructor(s,a){super(s);g(this,"initialData");g(this,"id");g(this,"x");g(this,"y");g(this,"type",f.ContinueStatement);g(this,"outputs",[]);g(this,"calledBySuccess",[]);g(this,"calledByError",[]);g(this,"calledByEntry",[]);g(this,"throws",null);g(this,"project");g(this,"errors",[]);g(this,"parent");g(this,"detachedDependents",{});g(this,"knownVersions",null);g(this,"activeVersion",!1);g(this,"initialized",!1);g(this,"startedInitialization",!1);g(this,"suggestion",!1);this.initialData=s,this.project=a,this.id=s.id,this.x=s.x,this.y=s.y}static new(s=null){return{id:P.UUID.uuid(),version:P.UUID.uuid(),createdAt:(s==null?void 0:s.timestamp)||N().toISOString(),author:(s==null?void 0:s.author)||P.sessionAuthor,previousVersion:null,deleted:!1,type:f.ContinueStatement,outputs:[],throws:null,parent:null,calledByEntry:[],calledBySuccess:[],calledByError:[],x:0,y:0}}static fromGenerationTarget(s,a){const l=W(s.parent),p=a.get(l),t=s.calledByEntry.map(I=>{const V=W(I);return a.get(V)}),m=s.calledBySuccess.map(I=>{const V=W(I);return a.get(V)}),v=s.calledByError.map(I=>{const V=W(I);return a.get(V)}),b={id:s.id,version:P.UUID.uuid(),createdAt:N().toISOString(),author:P.sessionAuthor,previousVersion:null,deleted:!1,type:f.ContinueStatement,x:0,y:0,outputs:[],calledBySuccess:m,calledByError:v,calledByEntry:t,throws:null,parent:p},_=z(b,a);return _.setParent(p,null),_.initChildren(null),_}static validateGenerationTarget(s,a){let l=JSON.parse(JSON.stringify(s));const p=[],t=Cr(l,{parent:{list:!1,types:[f.Loop]}},a);return l=t.modifiedData,p.push(...t.errors,...ur(l)),{errors:p,modifiedData:l}}validateGeneratedUpdate(s){const a=[];return s.parent&&a.push(new Y({id:`${this.id}--${k.InvalidParentUpdate}`,code:k.InvalidParentUpdate,severity:S.Error,message:`Entity of type '${this.type}' with id '${this.id}' cannot have the 'parent' property updated. The 'parent' on a callable entity, is its scope. It scope is auto-calculated implicitly by the its caller.
80
80
  If an entity is called by another, they must be in the same scope, which means they have the same parent.
81
81
  You shouldn't have to manually update a 'parent' property.
82
82
  Specifically for continue statements the parent needs to always be the 'loop' entity that contains it.`,issue:null})),{errors:a,modifiedData:s}}subscribeDependents(s){return s.forEach(a=>{this.detachedDependents[a.entity.id]||(this.detachedDependents[a.entity.id]=a)}),this}unsubscribeDependents(s){return s.forEach(a=>{this.detachedDependents[a.entity.id]&&delete this.detachedDependents[a.entity.id]}),this}syncDependents(s=this.project.addChangeSet(new F(this.project,P.sessionAuthor,N().toISOString(),this,!0,"sync-dependents"))){const a=[],l=[],p=[],t=[];return Object.values(this.detachedDependents).forEach(m=>{const v=m.entity.afterAllChildrenInitialized(s);a.push(...v.updated),l.push(...v.added),p.push(...v.removed),t.push(...v.affected)}),s==null||s.attemptAutoclose("sync-dependents",this.id),{updated:w(a),added:w(l),removed:w(p),affected:w(t),self:this}}onDetachedDependencyRemoved(s,a,l){const p=[],t=[],m=[],v=[];if(a==="parent"){const{updated:b,added:_,removed:I}=this.remove({ignoreUpstream:!1},l);p.push(...b),t.push(..._),m.push(...I)}return{updated:w(p),added:w(t),removed:w(m),affected:w(v),self:this}}onDetachedDependencyRestored(s,a,l){const p=[],t=[],m=[],v=[];if(a==="parent"){const{updated:b,added:_,removed:I}=this.restore({},l);p.push(...b),t.push(..._),m.push(...I)}return{updated:w(p),added:w(t),removed:w(m),affected:w(v),self:this}}unsubscribeFromDependencies(){var s;return(s=this.parent)==null||s.unsubscribeDependents([{entity:this,field:"parent"}]),this}subscribeToDependencies(){var s;return(s=this.parent)==null||s.subscribeDependents([{entity:this,field:"parent"}]),this}increaseVersion(s){if(s&&!N(s).isValid())throw new Error(`The shared timestamp '${s}' is not a valid ISO 8601 date string.`);return s&&N(s).isSame(N(this.createdAt))?this:(this.previousVersion=this.version,this.version=P.UUID.uuid(),this.createdAt=N(s).toISOString()||N().toISOString(),this)}captureVersion(){var a;const s=((a=this.knownVersions)==null?void 0:a.get(this.version))||new $t(this,this.project);return s.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,s):new Map([[this.version,s]]),s.outputs=[...this.outputs],s.throws=this.throws,s.calledBySuccess=[...this.calledBySuccess],s.calledByError=[...this.calledByError],s.calledByEntry=[...this.calledByEntry],s.parent=this.parent,this}recursiveCaptureUpstreamVersions(s){const a=[],l=[],p=[],t=[];if(this.parent){this.parent.increaseVersion(s);const m=this.parent.recursiveCaptureUpstreamVersions(s);a.push(this.parent,...m.updated),l.push(...m.added),p.push(...m.removed)}return{updated:w(a),added:w(l),removed:w(p),affected:w(t),self:this}}async restoreVersion(s){var v;const a=[],l=[],p=[],t=[];if(this.version===s)return{updated:w(a),added:w(l),removed:w(p),affected:w(t),self:this};if(!this.knownVersions){const b=new Map;for(const[_,I]of this.knownVersions||new Map){if(b.set(_,I),I.activeVersion=!1,I.knownVersions)for(const[V,B]of I.knownVersions)b.set(V,B);I.knownVersions=null}}let m=(v=this.knownVersions)==null?void 0:v.get(s);if(!m){const b=await this.APILoadVersion({},s);if(!b)throw new Error(`Version with id '${s}' for entity with id '${this.id}' not found.`);m=new $t(b,this.project)}return this.metaSync(m.toShallowJSON(),null),this.previousVersion=m.previousVersion,this.version=m.version,this.createdAt=m.createdAt,this.author=m.author,this.deleted=m.deleted,this.outputs=m.outputs,this.throws=m.throws,this.calledBySuccess=m.calledBySuccess,this.calledByError=m.calledByError,this.calledByEntry=m.calledByEntry,this.parent=m.parent,{updated:w(a),added:w(l),removed:w(p),affected:w(t),self:this}}updateWithShallowTransfer(s,a=this.project.addChangeSet(new F(this.project,P.sessionAuthor,N().toISOString(),this,!0,"update-with-shallow-transfer"))){if(this.metaSync(s,a),this.version=s.version,this.createdAt=s.createdAt,this.author=s.author,this.deleted=s.deleted,this.previousVersion=s.previousVersion,this.unsubscribeFromDependencies(),s.parent){const l=W(s.parent),p=this.project.get(l),t=this.parent;if(t&&t.id!==(p==null?void 0:p.id)&&this.removeFromParent(a),p)this.setParent(p,a);else throw a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),new Error(`${this.type} with id '${this.id}' must have a 'parent'`);return s.calledByEntry.forEach(l=>{const p=W(l),t=this.project.get(p);t&&(this.addEntryCaller(t,a),t.addCall(this,a))}),[...this.calledByEntry].forEach(l=>{s.calledByEntry.find(t=>t.id===l.id)||(this.removeCaller(l,a),l.removeCall(this,a))}),s.calledBySuccess.forEach(l=>{const p=W(l),t=this.project.get(p);t&&(this.addSuccessCaller(t,a),t.addSuccessCall(this,a))}),[...this.calledBySuccess].forEach(l=>{s.calledBySuccess.find(t=>t.id===l.id)||(this.removeCaller(l,a),l.removeCall(this,a))}),s.calledByError.forEach(l=>{const p=W(l),t=this.project.get(p);t&&(this.addErrorCaller(t,a),t.addErrorCall(this,a))}),[...this.calledBySuccess].forEach(l=>{s.calledBySuccess.find(t=>t.id===l.id)||(this.removeCaller(l,a),l.removeCall(this,a))}),this.captureVersion(),this.subscribeToDependencies(),a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),this}hydrateAncestors(){const s=[],a=[],l=[],p=[];if(this.initialData.parent){const t=W(this.initialData.parent),m=this.project.get(t);if(m)this.setParent(m,null),s.push(m);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${t}' 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(t=>{const m=W(t),v=this.project.get(m);v&&this.addEntryCaller(v,null)}),this.initialData.calledBySuccess.forEach(t=>{const m=W(t),v=this.project.get(m);v&&this.addSuccessCaller(v,null)}),this.initialData.calledByError.forEach(t=>{const m=W(t),v=this.project.get(m);v&&this.addErrorCaller(v,null)}),{updated:w(s),added:w(a),removed:w(l),affected:w(p),self:this}}afterAllChildrenInitialized(s=this.project.addChangeSet(new F(this.project,P.sessionAuthor,N().toISOString(),this,!0,"after-all-children-initialized"))){const a=[],l=[],p=[],t=[];return this.initialized=!0,this.parent.syncTerminationStatements(s),this.captureVersion(),s==null||s.attemptAutoclose("after-all-children-initialized",this.id),{updated:w(a),added:w(l),removed:w(p),affected:w(t),self:this}}addSelfToProject(s=this.project.addChangeSet(new F(this.project,P.sessionAuthor,N().toISOString(),this,!0,"add-self-to-project"))){var m,v;const a=[this],l=[],p=[],t=[];return this.calledByEntry.forEach(b=>{b.addCall(this,s),a.push(b)}),this.calledBySuccess.forEach(b=>{b.addSuccessCall(this,s),a.push(b)}),this.calledByError.forEach(b=>{b.addErrorCall(this,s),a.push(b)}),this.parent.addContinueStatement(this),a.push(this),s==null||s.add(this.parent,G.Affected),(m=this.parent)==null||m.breakStatements.forEach(b=>{b.id!==this.id&&(t.push(b),s==null||s.add(b,G.Affected))}),(v=this.parent)==null||v.continueStatements.forEach(b=>{b.id!==this.id&&(t.push(b),s==null||s.add(b,G.Affected))}),this.subscribe(),this.subscribeToDependencies(),s==null||s.attemptAutoclose("add-self-to-project",this.id),{updated:w(a),added:w(l),removed:w(p),affected:w(t),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}addSuccessCaller(s,a=this.project.addChangeSet(new F(this.project,P.sessionAuthor,N().toISOString(),this,!0,"add-success-caller")),l=!1){return this.calledBySuccess.find(p=>p.id===s.id)||(this.calledBySuccess.push(s),a==null||a.add(this,G.Updated),l&&Me(this,a)),a==null||a.attemptAutoclose("add-success-caller",this.id),this}addErrorCaller(s,a=this.project.addChangeSet(new F(this.project,P.sessionAuthor,N().toISOString(),this,!0,"add-error-caller")),l=!1){return this.calledByError.find(p=>p.id===s.id)||(this.calledByError.push(s),a==null||a.add(this,G.Updated),l&&Me(this,a)),a==null||a.attemptAutoclose("add-error-caller",this.id),this}addEntryCaller(s,a=this.project.addChangeSet(new F(this.project,P.sessionAuthor,N().toISOString(),this,!0,"add-entry-caller")),l=!1){return this.calledByEntry.find(p=>p.id===s.id)||(this.calledByEntry.push(s),a==null||a.add(this,G.Updated),l&&Me(this,a)),a==null||a.attemptAutoclose("add-entry-caller",this.id),this}removeCaller(s,a=this.project.addChangeSet(new F(this.project,P.sessionAuthor,N().toISOString(),this,!0,"remove-caller")),l=!1){return this.calledBySuccess=this.calledBySuccess.filter(p=>p.id!==s.id?!0:(a==null||a.add(this,G.Updated),a==null||a.add(p,G.Affected),!1)),this.calledByError=this.calledByError.filter(p=>p.id!==s.id?!0:(a==null||a.add(this,G.Updated),a==null||a.add(p,G.Affected),!1)),this.calledByEntry=this.calledByEntry.filter(p=>p.id!==s.id?!0:(a==null||a.add(this,G.Updated),a==null||a.add(p,G.Affected),!1)),l&&Me(this,a),a==null||a.attemptAutoclose("remove-caller",this.id),this}addOutputDeclaration(s,a=this.project.addChangeSet(new F(this.project,P.sessionAuthor,N().toISOString(),this,!0,"add-output-declaration"))){return this.outputs.find(l=>l.id===s.id)||(this.outputs.push(s),a==null||a.add(this,G.Affected)),a==null||a.attemptAutoclose("add-output-declaration",this.id),this}removeOutputDeclaration(s,a=this.project.addChangeSet(new F(this.project,P.sessionAuthor,N().toISOString(),this,!0,"remove-output-declaration"))){return this.outputs.find(l=>l.id===s.id)&&(this.outputs=this.outputs.filter(l=>l.id!==s.id),a==null||a.add(this,G.Affected)),a==null||a.attemptAutoclose("remove-output-declaration",this.id),this}setParent(s,a=this.project.addChangeSet(new F(this.project,P.sessionAuthor,N().toISOString(),this,!0,"set-parent"))){var l;return((l=this.parent)==null?void 0:l.id)!==(s==null?void 0:s.id)&&(this.parent=s,a&&(a==null||a.add(this,G.Updated))),a==null||a.attemptAutoclose("set-parent",this.id),this}initChildren(s=this.project.addChangeSet(new F(this.project,P.sessionAuthor,N().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.outputs=this.initialData.outputs.map(a=>{const l=z(a,this.project);return l.setParent(this,null),l.initChildren(s),l}),this.initialData.throws&&(this.throws=z(this.initialData.throws,this.project),this.throws.setParent(this,null),this.throws.initChildren(s)),this.subscribeToDependencies(),this.afterAllChildrenInitialized(s),s==null||s.attemptAutoclose("init-children",this.id),this)}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(s,a=this.project.addChangeSet(new F(this.project,P.sessionAuthor,N().toISOString(),this,!0,"meta-sync"))){const l=cr(this,s),p=this.toMeta();return this.x=s.x||p.x,this.y=s.y||p.y,super.metaSync(s),s.deleted===!0&&!p.deleted?a==null||a.add(this,G.Removed):s.deleted===!1&&p.deleted?a==null||a.add(this,G.Added):l&&(a==null||a.add(this,G.Updated)),a==null||a.attemptAutoclose("meta-sync",this.id),this}async APILoad(s=oe,...a){return await $t.repository.APILoad(this.id,...a),this}async APICreate(s=oe,...a){return await $t.repository.APICreate(this.toShallowJSON(),...a),this}async APIUpdate(s=oe,...a){return await $t.repository.APIUpdate(this.toShallowJSON(),...a),this}async APIDelete(s=oe,...a){return await $t.repository.APIDelete(this.toShallowJSON(),...a),this}async APIClone(s=oe,...a){return await $t.repository.APIClone(this.id,...a),this}async APILoadVersion(s=oe,a,...l){return await $t.repository.APILoadVersion(this.id,a,...l)}removeFromParent(s=this.project.addChangeSet(new F(this.project,P.sessionAuthor,N().toISOString(),this,!0,"remove-from-parent"))){const a=[],l=[],p=[],t=[];return this.parent.removeContinueStatement(this),this.parent.detachedChildren.includes(this)&&this.parent.unsubscribeDetachedChild(this),s==null||s.attemptAutoclose("remove-from-parent",this.id),{added:w(p),updated:w(a),removed:w(l),affected:w(t),self:this}}remove({ignoreUpstream:s}={ignoreUpstream:!1},a=this.project.addChangeSet(new F(this.project,P.sessionAuthor,N().toISOString(),this,!0,"remove-entity"))){var v,b;const l=[],p=[],t=[],m=[];if(a!=null&&a.hasRemoved(this.id))return a==null||a.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(p.push(this),this.unsubscribe(),this.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},a),Object.values(this.detachedDependents).forEach(_=>{const{updated:I,removed:V,added:B}=_.entity.onDetachedDependencyRemoved(this,_.field,a);l.push(...I),p.push(...V),t.push(...B)}),this.outputs.forEach(_=>{const{updated:I,removed:V}=_.remove({ignoreUpstream:!0},a);l.push(...I),p.push(...V)}),this.throws){const{updated:_,removed:I}=this.throws.remove({ignoreUpstream:!0},a);l.push(..._),p.push(...I)}if(!s){const _=this.removeFromParent(a);t.push(..._.added),l.push(..._.updated),p.push(..._.removed),m.push(..._.affected),this.calledBy.forEach(I=>{l.push(I),I.removeCall(this,a)})}return a==null||a.add(this.parent,G.Affected),(v=this.parent)==null||v.breakStatements.forEach(_=>{_.id!==this.id&&(m.push(_),a==null||a.add(_,G.Affected))}),(b=this.parent)==null||b.continueStatements.forEach(_=>{_.id!==this.id&&(m.push(_),a==null||a.add(_,G.Affected))}),a==null||a.attemptAutoclose("remove-entity",this.id),{added:w(t),updated:w(l),removed:w(p),affected:w(m),self:this}}restore({}={},s=this.project.addChangeSet(new F(this.project,P.sessionAuthor,N().toISOString(),this,!0,"restore-entity"))){const a=[],l=[],p=[],t=[];if(s!=null&&s.hasAdded(this.id))return s==null||s.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},s),Object.values(this.detachedDependents).forEach(m=>{const{updated:v,removed:b,added:_}=m.entity.onDetachedDependencyRestored(this,m.field,s);l.push(...v),p.push(...b),a.push(..._)}),this.outputs.forEach(m=>{const{updated:v}=m.restore({},s);l.push(...v)}),this.throws){const{updated:m}=this.throws.restore({},s);l.push(...m)}return this.parent.addContinueStatement(this),this.calledBySuccess.forEach(m=>{l.push(m),m.addSuccessCall(this,s)}),this.calledByError.forEach(m=>{l.push(m),m.addErrorCall(this,s)}),this.calledByEntry.forEach(m=>{l.push(m),m.addCall(this,s)}),s==null||s.attemptAutoclose("restore-entity",this.id),{added:w(a),updated:w(l),removed:w(p),affected:w(t),self:this}}toFlat(s=new Set){return s.has(this.id)?[]:(s.add(this.id),[this,...this.outputs.flatMap(l=>l.toFlat(s)),...this.calledBy.flatMap(l=>l.toFlat(s)),...this.throws?this.throws.toFlat(s):[]])}toFlatIds(s=new Set){return s.has(this.id)?[]:(s.add(this.id),[this.id,...this.outputs.flatMap(l=>l.toFlatIds(s)),...this.calledBy.flatMap(l=>l.toFlatIds(s)),...this.throws?this.throws.toFlatIds(s):[]])}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(s=new Set){var a,l;return s.has(this.id)?this.toReference():(s.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,calledBySuccess:this.calledBySuccess.map(p=>p.toReference()),calledByError:this.calledByError.map(p=>p.toReference()),calledByEntry:this.calledByEntry.map(p=>p.toReference()),outputs:this.outputs.map(p=>p.toJSON(s)),throws:((a=this.throws)==null?void 0:a.toJSON(s))||null,parent:((l=this.parent)==null?void 0:l.toReference())||null})}toJSONClone(s=Ce){var l,p,t,m,v,b,_;let a;return(l=s.seenEntityMaps)!=null&&l.has(this.id)?a=s.seenEntityMaps.get(this.id):(a=s.newId||hr(this,this.project,s.uuidStrategy),s.seenEntityMaps&&s.seenEntityMaps.set(this.id,a)),(p=s.seenEntities)!=null&&p.has(a)||(t=s.seenEntities)!=null&&t.has(this.id)?this.toReference({seenEntityMaps:s.seenEntityMaps}):((m=s.seenEntities)==null||m.add(a),(v=s.seenEntities)==null||v.add(this.id),{id:a,version:P.UUID.uuid(),createdAt:s.timestamp||N().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,calledBySuccess:this.calledBySuccess.map(I=>I.toReference({seenEntityMaps:s.seenEntityMaps})),calledByError:this.calledByError.map(I=>I.toReference({seenEntityMaps:s.seenEntityMaps})),calledByEntry:this.calledByEntry.map(I=>I.toReference({seenEntityMaps:s.seenEntityMaps})),outputs:this.outputs.map(I=>I.toJSONClone({...s,newId:null})),throws:((b=this.throws)==null?void 0:b.toJSONClone({...s,newId:null}))||null,parent:((_=this.parent)==null?void 0:_.toReference({seenEntityMaps:s.seenEntityMaps}))||null})}toReference(s=Ce){var l;let a=this.id;return(l=s.seenEntityMaps)!=null&&l.has(this.id)&&(a=s.seenEntityMaps.get(this.id)),{id:a+"--"+P.UUID.uuid()+"--ref",type:f.GenericReference,entityId:a,version:this.version,entityType:this.type}}toShallowJSON(s=Ce){var l,p;let a=this.id;return(l=s.seenEntityMaps)!=null&&l.has(this.id)&&(a=s.seenEntityMaps.get(this.id)),{id:a,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,outputs:this.outputs.map(t=>t.toReference(s)),calledBySuccess:this.calledBySuccess.map(t=>t.toReference(s)),calledByError:this.calledByError.map(t=>t.toReference(s)),calledByEntry:this.calledByEntry.map(t=>t.toReference(s)),throws:((p=this.throws)==null?void 0:p.toReference(s))||null,parent:this.parent.toReference(s)}}toFlatJSON(s=new Set){var l;return s.has(this.id)?[]:(s.add(this.id),[this.toShallowJSON(),...this.outputs.flatMap(p=>p.toFlatJSON(s)),...this.calledBy.flatMap(p=>p.toFlatJSON(s)),...((l=this.throws)==null?void 0:l.toFlatJSON(s))||[]])}toGenerationTarget(){return{id:this.id,type:this.type,calledByEntry:this.calledByEntry.map(s=>s.id),calledByError:this.calledByError.map(s=>s.id),calledBySuccess:this.calledBySuccess.map(s=>s.id),parent:this.parent.id}}toFlatGenerationTarget(s=new Set){return s.has(this.id)?[]:(s.add(this.id),[this.toGenerationTarget(),...this.outputs.flatMap(l=>l.toFlatGenerationTarget(s)),...this.throws?this.throws.toFlatGenerationTarget(s):[]])}clearErrors(){var s;return this.errors=[],this.outputs.forEach(a=>a.clearErrors()),(s=this.throws)==null||s.clearErrors(),this}validate(){const s=cM(this);return this.errors=s,{success:!0,error:null,data:this.toJSON()}}getErrors(){return[...this.errors,...this.outputs.flatMap(a=>a.getErrors())]}getShallowErrors(){return this.errors}clone(s=this.project.addChangeSet(new F(this.project,P.sessionAuthor,N().toISOString(),this,!0,"clone-entity")),a=null,l=null,p=!0){var B;let t=yr(a,this);const m=this.toJSON(),v=l||P.UUID.uuid();m.outputs=[];const b=v.split("-id"),_=b[b.length-1||0]||v;m.id=v,m.version=P.UUID.uuid(),m.createdAt=(s==null?void 0:s.timestamp)||N().toISOString(),m.author=(s==null?void 0:s.author)||"1",m.previousVersion=null,m.deleted=!1;const I=er(m,t);a?I.setParent(a,null):I.setParent(this.parent,null),p&&I.subscribe(),I.initChildren(s),s==null||s.add(I,G.Added);const V=(B=this.outputs)==null?void 0:B.map((K,q)=>K.clone(s,I,_+"-return-declaration-"+q+"-id",p));return I.outputs=V,this.throws&&(I.throws=this.throws.clone(s,I,_+"-throws-id",p)),s==null||s.attemptAutoclose("clone-entity",this.id),I}};g($t,"repository",{APICreate:async(s,...a)=>s,APIUpdate:async(s,...a)=>s,APIDelete:async(s,...a)=>s,APIClone:async(s,...a)=>{},APILoad:async(s,...a)=>null,APILoadVersion:async(s,a,...l)=>null}),g($t,"type",f.ContinueStatement),g($t,"USER_MANAGED_PARENT_TYPES",[f.Loop]),g($t,"PARENT_TYPES",[...$t.USER_MANAGED_PARENT_TYPES]),g($t,"MUTABLE_BASE_PROPERTIES",[]),g($t,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),g($t,"BASE_PROPERTIES",[...$t.MUTABLE_BASE_PROPERTIES,...$t.INMUTABLE_BASE_PROPERTIES]),g($t,"MUTABLE_META_PROPERTIES",["x","y"]),g($t,"INMUTABLE_META_PROPERTIES",[...$t.INMUTABLE_BASE_PROPERTIES]),g($t,"META_PROPERTIES",[...$t.MUTABLE_META_PROPERTIES,...$t.INMUTABLE_META_PROPERTIES]),g($t,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry","parent"]),g($t,"INMUTABLE_UPSTREAM_PROPERTIES",[]),g($t,"UPSTREAM_PROPERTIES",[...$t.MUTABLE_UPSTREAM_PROPERTIES,...$t.INMUTABLE_UPSTREAM_PROPERTIES]),g($t,"MUTABLE_DOWNSTREAM_PROPERTIES",["outputs","throws"]),g($t,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),g($t,"DOWNSTREAM_PROPERTIES",[...$t.MUTABLE_DOWNSTREAM_PROPERTIES,...$t.INMUTABLE_DOWNSTREAM_PROPERTIES]),g($t,"PROPERTIES",[...$t.META_PROPERTIES,...$t.UPSTREAM_PROPERTIES,...$t.DOWNSTREAM_PROPERTIES]);let Qr=$t;var FT=(u=>(u.Parent="return-statement-parent",u))(FT||{});const tr=class tr extends nr{constructor(s,a){super(s);g(this,"initialData");g(this,"id");g(this,"x");g(this,"y");g(this,"type",f.ReturnStatement);g(this,"outputs",[]);g(this,"calledBySuccess",[]);g(this,"calledByError",[]);g(this,"calledByEntry",[]);g(this,"throws",null);g(this,"project");g(this,"errors",[]);g(this,"parent");g(this,"detachedDependents",{});g(this,"knownVersions",null);g(this,"activeVersion",!1);g(this,"initialized",!1);g(this,"startedInitialization",!1);g(this,"suggestion",!1);this.initialData=s,this.project=a,this.id=s.id,this.x=s.x,this.y=s.y}static new(s=null){return{id:P.UUID.uuid(),version:P.UUID.uuid(),createdAt:(s==null?void 0:s.timestamp)||N().toISOString(),author:(s==null?void 0:s.author)||P.sessionAuthor,previousVersion:null,deleted:!1,type:f.ReturnStatement,outputs:[],throws:null,parent:null,calledByEntry:[],calledBySuccess:[],calledByError:[],x:0,y:0}}static fromGenerationTarget(s,a){const l=W(s.parent),p=a.get(l),t=s.calledByEntry.map(I=>{const V=W(I);return a.get(V)}),m=s.calledBySuccess.map(I=>{const V=W(I);return a.get(V)}),v=s.calledByError.map(I=>{const V=W(I);return a.get(V)}),b={id:s.id,version:P.UUID.uuid(),createdAt:N().toISOString(),author:P.sessionAuthor,previousVersion:null,deleted:!1,type:f.ReturnStatement,x:0,y:0,outputs:[],calledBySuccess:m,calledByError:v,calledByEntry:t,throws:null,parent:p},_=z(b,a);return _.setParent(p,null),_.initChildren(null),_}static validateGenerationTarget(s,a){let l=JSON.parse(JSON.stringify(s));const p=[],t=Cr(l,{parent:{list:!1,types:br}},a);return l=t.modifiedData,p.push(...t.errors,...ur(l)),{errors:p,modifiedData:l}}validateGeneratedUpdate(s){const a=[];return s.parent&&a.push(new Y({id:`${this.id}--${k.InvalidParentUpdate}`,code:k.InvalidParentUpdate,severity:S.Error,message:`Entity of type '${this.type}' with id '${this.id}' cannot have the 'parent' property updated. The 'parent' on a callable entity, is its scope. It scope is auto-calculated implicitly by the its caller.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elyx-code/project-logic-tree",
3
- "version": "0.0.6319",
3
+ "version": "0.0.6320",
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",