@elyx-code/project-logic-tree 0.0.6194 → 0.0.6195

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.
@@ -91,7 +91,7 @@ ${Zi}`,a.push(new P({id:`${e.id}--${R.NonInteractiveEntityReferenced}`,code:R.No
91
91
  You can inspect the existing 'entity' field with the 'describe_entity' action. Like so:
92
92
  ${Jr({describe_entity:d.entity.id})}
93
93
  Alternatively you can update the parent data-type entity with 'update' action to remove the existing value of the field.`,issue:null}))}return a.push(...l.errors,...ot(r)),{errors:a,modifiedData:r}}syncOperationInstance(e,t){return{updated:[],added:[],removed:[],affected:[],self:e}}inferInputMapDataType(e,t=this.project.addChangeSet(new b(this.project,"",T().toISOString(),this,!0,"infer-input-map-data-type"))){const r=pc(e);return t==null||t.attemptAutoclose("infer-input-map-data-type",this.id),{updated:[],added:[],removed:[],affected:[],self:r}}inferOutputMapDataType(e,t=this.project.addChangeSet(new b(this.project,"",T().toISOString(),this,!0,"infer-output-map-data-type"))){const r=fc(e);return t==null||t.attemptAutoclose("infer-output-map-data-type",this.id),{updated:[],added:[],removed:[],affected:[],self:r}}validateGeneratedUpdate(e){const t=[];return e.parent&&t.push(new P({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, as it would mean moving the '${this.type}' entity to another parent entity.
94
- 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:t,modifiedData:e}}subscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]||(this.detachedDependents[t.entity.id]=t)}),this}syncDependents(){const e=[],t=[],r=[],a=[];return Object.values(this.detachedDependents).forEach(l=>{const o=l.entity.afterAllChildrenInitialized();e.push(...o.updated),t.push(...o.added),r.push(...o.removed),a.push(...o.affected)}),{updated:p(e),added:p(t),removed:p(r),affected:p(a),self:this}}onDetachedDependencyRemoved(e,t,r){const a=[],l=[],o=[],d=[];return{updated:p(a),added:p(l),removed:p(o),affected:p(d),self:this}}onDetachedDependencyRestored(e,t,r){const a=[],l=[],o=[],d=[];return{updated:p(a),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=I.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 Pe(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.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],r=[],a=[],l=[];if(this.parent&&this.parent.type!==n.BuiltInBaseEntity&&this.parent.type!==n.PrimitiveEntity){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),r.push(...o.added),a.push(...o.removed)}return{updated:p(t),added:p(r),removed:p(a),affected:p(l),self:this}}async restoreVersion(e){var d;const t=[],r=[],a=[],l=[];if(this.version===e)return{updated:p(t),added:p(r),removed:p(a),affected:p(l),self:this};if(!this.knownVersions){const u=new Map;for(const[h,c]of this.knownVersions||new Map){if(u.set(h,c),c.activeVersion=!1,c.knownVersions)for(const[v,E]of c.knownVersions)u.set(v,E);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 Pe(u,this.project)}return this.metaSync(o.toShallowJSON(),null),this.inputs=o.inputs,this.outputs=o.outputs,this.error=o.error,this.parent=o.parent,{updated:p(t),added:p(r),removed:p(a),affected:p(l),self:this}}hydrateAncestors(){const e=[],t=[],r=[],a=[];if(this.initialData.parent){const l=B(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(r),affected:p(a),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new b(this.project,"",T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],r=[],a=[],l=[];return this.initialized=!0,this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:p(t),added:p(r),removed:p(a),affected:p(l),self:this}}addSelfToProject(e=this.project.addChangeSet(new b(this.project,"",T().toISOString(),this,!0,"add-self-to-project"))){const t=[this],r=[],a=[],l=[];return this.parent?(this.parent.type===n.DefinitionEntity?(this.parent.addAbstractMethod(this),t.push(this.parent)):this.parent.type===n.DataType&&(this.parent.setEntity(this),t.push(this.parent)),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:p(t),added:p(r),removed:p(a),affected:p(l),self:this}):(this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:p(t),added:p(r),removed:p(a),affected:p(l),self:this})}setParent(e,t=this.project.addChangeSet(new b(this.project,"",T().toISOString(),this,!0,"set-parent"))){var r;return((r=this.parent)==null?void 0:r.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,A.Updated),t==null||t.attemptAutoclose("set-parent",this.id))),this}initChildren(e=this.project.addChangeSet(new b(this.project,"",T().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.inputs=this.initialData.inputs.map(t=>{const r=C(t,this.project);return r.setParent(this,null),r.initChildren(e),r}),this.outputs=this.initialData.outputs.map(t=>{const r=C(t,this.project);return r.setParent(this,null),r.initChildren(e),r}),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 b(this.project,"",T().toISOString(),this,!0,"meta-sync"))){const r=lt(this,e),a=this.toMeta();return this.name=e.name||a.name,this.description=e.description||a.description,super.metaSync(e),e.deleted===!0&&!a.deleted?t==null||t.add(this,A.Removed):e.deleted===!1&&a.deleted?t==null||t.add(this,A.Added):r&&(t==null||t.add(this,A.Updated)),t==null||t.attemptAutoclose("meta-sync",this.id),this}async APILoad(e=L,...t){return await Pe.repository.APILoad(this.id,...t),this}async APICreate(e=L,...t){return await Pe.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=L,...t){return await Pe.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=L,...t){return await Pe.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=L,...t){return await Pe.repository.APIClone(this.id,...t),this}async APILoadVersion(e=L,t,...r){return await Pe.repository.APILoadVersion(this.id,t,...r)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new b(this.project,"",T().toISOString(),this,!0,"remove-entity"))){const r=[],a=[],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(a.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(d=>{const{updated:u,removed:h,added:c}=d.entity.onDetachedDependencyRemoved(this,d.field,t);r.push(...u),a.push(...h),l.push(...c)}),this.inputs.forEach(d=>{const u=d.remove({ignoreUpstream:!0},t);r.push(...u.updated),a.push(...u.removed)}),this.outputs.forEach(d=>{const u=d.remove({ignoreUpstream:!0},t);r.push(...u.updated),a.push(...u.removed)}),this.error){const d=this.error.remove({ignoreUpstream:!0},t);r.push(...d.updated),a.push(...d.removed)}return t==null||t.attemptAutoclose("remove-entity",this.id),{added:p(l),updated:p(r),removed:p(a),affected:p(o),self:this}}restore({}={},e=this.project.addChangeSet(new b(this.project,"",T().toISOString(),this,!0,"restore-entity"))){const t=[],r=[],a=[],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),this.inputs.forEach(o=>{const d=o.restore({},e);r.push(...d.updated)}),this.outputs.forEach(o=>{const d=o.restore({},e);r.push(...d.updated)}),this.error){const o=this.error.restore({},e);r.push(...o.updated)}return e==null||e.attemptAutoclose("restore-entity",this.id),{added:p(t),updated:p(r),removed:p(a),affected:p(l),self:this}}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.inputs.flatMap(r=>r.toFlat(e)),...this.outputs.flatMap(r=>r.toFlat(e))])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.inputs.flatMap(r=>r.toFlatIds(e)),...this.outputs.flatMap(r=>r.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,type:this.type,name:this.name}}toJSON(e=new Set){var t,r;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,error:((t=this.error)==null?void 0:t.toJSON())||null,inputs:this.inputs.map(a=>a.toJSON()),outputs:this.outputs.map(a=>a.toJSON()),parent:((r=this.parent)==null?void 0:r.toReference())||null})}toJSONClone(e=Z){var r,a,l,o,d,u,h;let t;return(r=e.seenEntityMaps)!=null&&r.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||ct(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(a=e.seenEntities)!=null&&a.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:I.UUID.uuid(),createdAt:e.timestamp||T().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,error:((u=this.error)==null?void 0:u.toJSONClone({...e,newId:null}))||null,inputs:this.inputs.map(c=>c.toJSONClone({...e,newId:null})),outputs:this.outputs.map(c=>c.toJSONClone({...e,newId:null})),parent:((h=this.parent)==null?void 0:h.toReference({seenEntityMaps:e.seenEntityMaps}))||null})}toReference(e=Z){var r;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+I.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=Z){var r,a,l;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.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,error:((a=this.error)==null?void 0:a.toReference(e))||null,inputs:this.inputs.map(o=>o.toReference(e)),outputs:this.outputs.map(o=>o.toReference(e)),parent:((l=this.parent)==null?void 0:l.toReference(e))||null}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.inputs.flatMap(r=>r.toFlatJSON(e)),...this.outputs.flatMap(r=>r.toFlatJSON(e))])}toGenerationTarget(){var e;return{id:this.id,name:this.name,description:this.description,type:this.type,parent:((e=this.parent)==null?void 0:e.id)||void 0}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...this.inputs.flatMap(r=>r.toFlatGenerationTarget(e)),...this.outputs.flatMap(r=>r.toFlatGenerationTarget(e))])}asFunctionDeclarationTransfer(e,t=this.project.addChangeSet(new b(this.project,"",T().toISOString(),this,!0,"implement-as-function-declaration"))){var d;const r=e||I.UUID.uuid(),a=I.UUID.uuid(),l=this.inputs.map((u,h)=>{var v;const c={id:I.UUID.uuid(),type:n.GenericReference,version:a,entityType:n.FunctionDeclaration,entityId:r};return{id:I.UUID.uuid(),version:I.UUID.uuid(),createdAt:(t==null?void 0:t.timestamp)||T().toISOString(),author:I.sessionAuthor,previousVersion:null,deleted:!1,type:n.ArgumentDeclaration,name:u.name,required:u.required,implements:u.toJSON(),constant:!0,writesValues:[],defaultValue:null,description:u.description,index:h,dataType:((v=u.dataType)==null?void 0:v.toJSONClone({timestamp:(t==null?void 0:t.timestamp)||T().toISOString()}))||null,parent:c}}),o=[];if(this.outputs.length){const u=this.outputs.map((E,O)=>{var V;const w={id:I.UUID.uuid(),type:n.GenericReference,entityId:r,version:a,entityType:n.ReturnStatement};return{id:I.UUID.uuid(),version:I.UUID.uuid(),createdAt:(t==null?void 0:t.timestamp)||T().toISOString(),author:I.sessionAuthor,previousVersion:null,deleted:!1,type:n.ReturnDeclaration,name:E.name,description:E.description,readsValue:null,constant:!0,required:E.required,defaultValue:null,implements:E.toJSON(),isError:!1,index:O,dataType:((V=E.dataType)==null?void 0:V.toJSONClone())||null,parent:w}}),h={id:I.UUID.uuid(),type:n.GenericReference,version:a,entityType:n.FunctionDeclaration,entityId:r},c={id:I.UUID.uuid(),type:n.GenericReference,version:a,entityType:n.FunctionDeclaration,entityId:r},v={id:I.UUID.uuid(),version:I.UUID.uuid(),createdAt:(t==null?void 0:t.timestamp)||T().toISOString(),author:I.sessionAuthor,previousVersion:null,deleted:!1,type:n.ReturnStatement,outputs:u,throws:null,calledBySuccess:[],calledByError:[],calledByEntry:[c],parent:h,x:0,y:0};o.push(v)}return t==null||t.attemptAutoclose("implement-as-function-declaration",this.id),{id:r,version:a,createdAt:(t==null?void 0:t.timestamp)||T().toISOString(),author:I.sessionAuthor,previousVersion:null,deleted:!1,type:n.FunctionDeclaration,name:this.name,description:this.description,inputs:l,calls:o,collapsed:!1,private:!1,implements:this.toJSON(),index:0,parent:((d=this.parent)==null?void 0:d.toReference())||null,x:0,y:0}}implementAsGlobalEvent(e=this.project.addChangeSet(new b(this.project,"",T().toISOString(),this,!0,"implement-as-global-event")),t,r){const a=t||this.project,l=r||I.UUID.uuid(),o=I.UUID.uuid(),d={id:l,version:o,createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:I.sessionAuthor,previousVersion:null,deleted:!1,type:n.GlobalEvent,name:this.name,description:this.description,inputs:[],calls:[],collapsed:!1,implements:this.toJSON(),parent:(a==null?void 0:a.toReference())||null,x:0,y:0},u=C(d,this.project);if(u.setParent(a,e),u.initChildren(e),e==null||e.add(u,A.Added),u.hydrateAncestors(),u.addSelfToProject(e),this.inputs.map((h,c)=>{var V;const v={id:I.UUID.uuid(),type:n.GenericReference,version:o,entityType:n.GlobalEvent,entityId:l},E={id:I.UUID.uuid(),version:I.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:I.sessionAuthor,previousVersion:null,deleted:!1,type:n.ArgumentDeclaration,name:h.name,required:h.required,implements:h.toJSON(),constant:!0,writesValues:[],defaultValue:null,description:h.description,index:c,dataType:null,parent:v},O=C(E,this.project);O.setParent(u,e),O.initChildren(e),e==null||e.add(O,A.Added),O.hydrateAncestors(),O.addSelfToProject(e);const w=((V=h.dataType)==null?void 0:V.clone(e,O))||null;w&&(e==null||e.add(w,A.Added)),O.setDataType(w)}),this.outputs.length){const h=I.UUID.uuid(),c=I.UUID.uuid(),v={id:I.UUID.uuid(),type:n.GenericReference,version:o,entityType:n.GlobalEvent,entityId:l},E={id:I.UUID.uuid(),type:n.GenericReference,version:o,entityType:n.GlobalEvent,entityId:l},O={id:h,version:c,createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:I.sessionAuthor,previousVersion:null,deleted:!1,type:n.ReturnStatement,outputs:[],throws:null,calledBySuccess:[],calledByError:[],calledByEntry:[E],parent:v,x:0,y:0},w=C(O,this.project);w.setParent(u,e),w.initChildren(e),e==null||e.add(w,A.Added),w.hydrateAncestors(),w.addSelfToProject(e),this.outputs.map((V,U)=>{var J;const G={id:I.UUID.uuid(),type:n.GenericReference,entityId:h,version:c,entityType:n.ReturnStatement},_={id:I.UUID.uuid(),version:I.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:I.sessionAuthor,previousVersion:null,deleted:!1,type:n.ReturnDeclaration,name:V.name,description:V.description,readsValue:null,constant:!0,required:V.required,defaultValue:null,implements:V.toJSON(),isError:!1,index:U,dataType:null,parent:G},$=C(_,this.project);$.setParent(w,e),$.initChildren(e),e==null||e.add($,A.Added),$.hydrateAncestors(),$.addSelfToProject(e);const k=((J=V.dataType)==null?void 0:J.clone(e,$))||null;k&&(e==null||e.add(k,A.Added)),$.setDataType(k)})}return e==null||e.attemptAutoclose("implement-as-function-declaration",this.id),u}implementAsFunctionDeclaration(e=this.project.addChangeSet(new b(this.project,"",T().toISOString(),this,!0,"implement-as-function-declaration")),t,r){const a=t||this.project,l=r||I.UUID.uuid(),o=I.UUID.uuid(),d={id:l,version:o,createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:I.sessionAuthor,previousVersion:null,deleted:!1,type:n.FunctionDeclaration,name:this.name,description:this.description,inputs:[],calls:[],collapsed:!1,private:!1,implements:this.toJSON(),index:0,parent:(a==null?void 0:a.toReference())||null,x:0,y:0},u=C(d,this.project);if(u.setParent(a,e),u.initChildren(e),e==null||e.add(u,A.Added),u.hydrateAncestors(),u.addSelfToProject(e),this.inputs.map((h,c)=>{var V;const v={id:I.UUID.uuid(),type:n.GenericReference,version:o,entityType:n.FunctionDeclaration,entityId:l},E={id:I.UUID.uuid(),version:I.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:I.sessionAuthor,previousVersion:null,deleted:!1,type:n.ArgumentDeclaration,name:h.name,required:h.required,implements:h.toJSON(),constant:!0,writesValues:[],defaultValue:null,description:h.description,index:c,dataType:null,parent:v},O=C(E,this.project);O.setParent(u,e),O.initChildren(e),e==null||e.add(O,A.Added),O.hydrateAncestors(),O.addSelfToProject(e);const w=((V=h.dataType)==null?void 0:V.clone(e,O))||null;w&&(e==null||e.add(w,A.Added)),O.setDataType(w)}),this.outputs.length){const h=I.UUID.uuid(),c=I.UUID.uuid(),v={id:I.UUID.uuid(),type:n.GenericReference,version:o,entityType:n.FunctionDeclaration,entityId:l},E={id:I.UUID.uuid(),type:n.GenericReference,version:o,entityType:n.FunctionDeclaration,entityId:l},O={id:h,version:c,createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:I.sessionAuthor,previousVersion:null,deleted:!1,type:n.ReturnStatement,outputs:[],throws:null,calledBySuccess:[],calledByError:[],calledByEntry:[E],parent:v,x:0,y:0},w=C(O,this.project);w.setParent(u,e),w.initChildren(e),e==null||e.add(w,A.Added),w.hydrateAncestors(),w.addSelfToProject(e),this.outputs.map((V,U)=>{var J;const G={id:I.UUID.uuid(),type:n.GenericReference,entityId:h,version:c,entityType:n.ReturnStatement},_={id:I.UUID.uuid(),version:I.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:I.sessionAuthor,previousVersion:null,deleted:!1,type:n.ReturnDeclaration,name:V.name,description:V.description,readsValue:null,constant:!0,required:V.required,defaultValue:null,implements:V.toJSON(),isError:!1,index:U,dataType:null,parent:G},$=C(_,this.project);$.setParent(w,e),$.initChildren(e),e==null||e.add($,A.Added),$.hydrateAncestors(),$.addSelfToProject(e);const k=((J=V.dataType)==null?void 0:J.clone(e,$))||null;k&&(e==null||e.add(k,A.Added)),$.setDataType(k)})}return e==null||e.attemptAutoclose("implement-as-function-declaration",this.id),u}implementAsLoop(e=this.project.addChangeSet(new b(this.project,"",T().toISOString(),this,!0,"implement-as-loop")),t,r){const a=t||this.project,l=r||I.UUID.uuid(),o=I.UUID.uuid(),d={id:l,version:o,createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:I.sessionAuthor,previousVersion:null,deleted:!1,type:n.Loop,declaration:this.toJSON(),inputs:[],outputs:[],error:null,process:null,successCalls:[],errorCalls:[],calledByEntry:[],calledByError:[],calledBySuccess:[],outputsDeclarations:[],body:null,x:0,y:0,parent:a.toReference()},u=C(d,this.project);return u.setParent(a,e),u.initChildren(e),e==null||e.add(u,A.Added),u.hydrateAncestors(),u.addSelfToProject(e),u.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("implement-as-loop",this.id),u}implementAsOperation(e=this.project.addChangeSet(new b(this.project,"",T().toISOString(),this,!0,"implement-as-operation")),t,r){const a=t||this.project,l=r||I.UUID.uuid(),o=I.UUID.uuid(),d={id:l,version:o,createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:I.sessionAuthor,previousVersion:null,deleted:!1,type:n.Operation,declaration:this.toJSON(),inputs:[],outputs:[],error:null,process:null,successCalls:[],errorCalls:[],calledByEntry:[],calledByError:[],calledBySuccess:[],x:0,y:0,parent:a.toReference()},u=C(d,this.project);return u.setParent(a,e),u.initChildren(e),e==null||e.add(u,A.Added),u.hydrateAncestors(),u.addSelfToProject(e),this.inputs.forEach((h,c)=>{const v={id:I.UUID.uuid(),version:I.UUID.uuid(),type:n.InputMap,createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:I.sessionAuthor,previousVersion:null,deleted:!1,name:null,description:null,declaration:h,defaultValue:null,readsValue:null,index:c,parent:{id:I.UUID.uuid(),type:n.GenericReference,entityId:l,version:o,entityType:n.Operation}},E=C(v,this.project);E.setParent(u,e),E.initChildren(e),e==null||e.add(E,A.Added),E.hydrateAncestors(),E.addSelfToProject(e)}),this.outputs.forEach((h,c)=>{const v={id:I.UUID.uuid(),version:I.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:I.sessionAuthor,previousVersion:null,deleted:!1,type:n.OutputMap,declaration:h,defaultValue:null,writesValues:[],index:c,parent:{id:I.UUID.uuid(),type:n.GenericReference,entityId:l,version:o,entityType:n.Operation}},E=C(v,this.project);E.setParent(u,e),E.initChildren(e),e==null||e.add(E,A.Added),E.hydrateAncestors(),E.addSelfToProject(e)}),u.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("implement-as-operation",this.id),u}implementAsCondition(e=this.project.addChangeSet(new b(this.project,"",T().toISOString(),this,!0,"implement-as-condition")),t,r){const a=t||this.project,l=r||I.UUID.uuid(),o=I.UUID.uuid(),d={id:l,version:o,createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:I.sessionAuthor,previousVersion:null,deleted:!1,type:n.Condition,declaration:this.toJSON(),inputs:[],successCalls:[],errorCalls:[],calledByEntry:[],calledByError:[],calledBySuccess:[],x:0,y:0,parent:a.toReference()},u=C(d,this.project);return u.setParent(a,e),u.initChildren(e),e==null||e.add(u,A.Added),u.hydrateAncestors(),u.addSelfToProject(e),this.inputs.forEach((h,c)=>{const v={id:I.UUID.uuid(),version:I.UUID.uuid(),type:n.InputMap,createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:I.sessionAuthor,previousVersion:null,deleted:!1,name:null,description:null,declaration:h,defaultValue:null,readsValue:null,index:c,parent:{id:I.UUID.uuid(),type:n.GenericReference,entityId:l,version:o,entityType:n.Condition}},E=C(v,this.project);E.setParent(u,e),E.initChildren(e),e==null||e.add(E,A.Added),E.hydrateAncestors(),E.addSelfToProject(e)}),u.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("implement-as-condition",this.id),u}clearErrors(){var e;return this.errors=[],this.inputs.forEach(t=>t.clearErrors()),this.outputs.forEach(t=>t.clearErrors()),(e=this.error)==null||e.clearErrors(),this}validate(){const e=aq(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){return[...this.errors,...this.inputs.flatMap(t=>t.getErrors()),...this.outputs.flatMap(t=>t.getErrors())]}getShallowErrors(){return this.errors}clone(e=this.project.addChangeSet(new b(this.project,"",T().toISOString(),this,!0,"clone-entity")),t=null,r=null,a=!0){var w,V;if(Array.from(new Set([...Cr(),...this.project.getAllBuiltInIds()])).includes(this.id))return this;let o=ft(t,this);const d=this.toJSON(),u=r||I.UUID.uuid();d.inputs=[],d.outputs=[],d.error=null;const h=u.split("-id"),c=h[h.length-1||0]||u;d.id=u,d.version=I.UUID.uuid(),d.createdAt=(e==null?void 0:e.timestamp)||T().toISOString(),d.author=(e==null?void 0:e.author)||"1",d.previousVersion=null,d.deleted=!1;const v=dt(d,o);e==null||e.add(v,A.Added),t?v.setParent(t,null):this.parent&&v.setParent(this.parent,null),a&&v.subscribe(),v.initChildren(e);const E=(w=this.inputs)==null?void 0:w.map((U,G)=>U.clone(e,v,c+"-argument-value-descriptor-"+G+"-id",a));v.inputs=E;const O=(V=this.outputs)==null?void 0:V.map((U,G)=>U.clone(e,v,c+"-return-value-descriptor-"+G+"-id",a));return v.outputs=O,this.error&&(v.error=this.error.clone(e,v,c+"-error-action-descriptor-id",a)),e==null||e.attemptAutoclose("clone-entity",this.id),v}addInput(e){return this.inputs.find(t=>t.id===e.id)||this.inputs.push(e),this}removeInput(e){return this.inputs=this.inputs.filter(t=>t.id!==e.id),this}addOutput(e){return this.outputs.find(t=>t.id===e.id)||this.outputs.push(e),this}removeOutput(e){return this.outputs=this.outputs.filter(t=>t.id!==e.id),this}};f(Pe,"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,...r)=>null}),f(Pe,"type",n.ActionDescriptor),f(Pe,"USER_MANAGED_PARENT_TYPES",[n.DefinitionEntity,n.DataType]),f(Pe,"PARENT_TYPES",[...Pe.USER_MANAGED_PARENT_TYPES,n.PrimitiveEntity,n.BuiltInBaseEntity]),f(Pe,"MUTABLE_BASE_PROPERTIES",["name","description"]),f(Pe,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),f(Pe,"BASE_PROPERTIES",[...Pe.MUTABLE_BASE_PROPERTIES,...Pe.INMUTABLE_BASE_PROPERTIES]),f(Pe,"MUTABLE_META_PROPERTIES",[...Pe.MUTABLE_BASE_PROPERTIES]),f(Pe,"INMUTABLE_META_PROPERTIES",[...Pe.INMUTABLE_BASE_PROPERTIES]),f(Pe,"META_PROPERTIES",[...Pe.MUTABLE_META_PROPERTIES,...Pe.INMUTABLE_META_PROPERTIES]),f(Pe,"MUTABLE_UPSTREAM_PROPERTIES",[]),f(Pe,"INMUTABLE_UPSTREAM_PROPERTIES",["parent"]),f(Pe,"UPSTREAM_PROPERTIES",[...Pe.MUTABLE_UPSTREAM_PROPERTIES,...Pe.INMUTABLE_UPSTREAM_PROPERTIES]),f(Pe,"MUTABLE_DOWNSTREAM_PROPERTIES",["inputs","outputs"]),f(Pe,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),f(Pe,"DOWNSTREAM_PROPERTIES",[...Pe.MUTABLE_DOWNSTREAM_PROPERTIES,...Pe.INMUTABLE_DOWNSTREAM_PROPERTIES]),f(Pe,"PROPERTIES",[...Pe.META_PROPERTIES,...Pe.UPSTREAM_PROPERTIES,...Pe.DOWNSTREAM_PROPERTIES]);let qe=Pe;var Q1=(i=>(i.Parent="parent",i))(Q1||{});const ae=class ae extends rt{constructor(e,t){super(e);f(this,"initialData");f(this,"id");f(this,"x");f(this,"y");f(this,"type",n.Loop);f(this,"declaration");f(this,"inputs",[]);f(this,"outputs",[]);f(this,"process",null);f(this,"successCalls",[]);f(this,"errorCalls",[]);f(this,"error",null);f(this,"outputsDeclarations",[]);f(this,"body");f(this,"calledBySuccess",[]);f(this,"calledByError",[]);f(this,"calledByEntry",[]);f(this,"parent");f(this,"detachedChildren",[]);f(this,"currentIterationNumberArgumentDeclaration");f(this,"currentValueArgumentDeclaration",null);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}static fromGenerationTarget(e,t){let r=t;if(e.parent){const v=B(e.parent);r=t.get(v)}const a=B(e.declaration),l=t.get(a),o=e.calledByEntry.map(v=>{const E=B(v);return t.get(E)}),d=e.calledBySuccess.map(v=>{const E=B(v);return t.get(E)}),u=e.calledByError.map(v=>{const E=B(v);return t.get(E)}),h={id:e.id,version:I.UUID.uuid(),createdAt:T().toISOString(),author:I.sessionAuthor,previousVersion:null,deleted:!1,type:n.Loop,declaration:l,calledByEntry:o,calledBySuccess:d,calledByError:u,process:null,errorCalls:[],successCalls:[],inputs:[],outputs:[],body:null,outputsDeclarations:[],error:null,x:0,y:0,parent:r},c=C(h,t);return c.setParent(r,null),c.initChildren(null),c}static validateGenerationTarget(e,t){let r=JSON.parse(JSON.stringify(e));const a=[],l=Et(r,{parent:{list:!1,types:[...mt,n.Project],optional:!0},declaration:{list:!1,types:[n.ActionDescriptor]}},t);return r=l.modifiedData,a.push(...l.errors,...ot(r)),e.declaration?t.get(e.declaration)?t.conditionDeclarations.find(u=>u.id===e.declaration)||a.push(new P({id:`${e.id}--${R.InvalidImplementsReference}`,code:R.InvalidImplementsReference,severity:D.Error,message:`Entity of type '${e.type}' with id '${e.id}' has an 'declaration' property that isn't pointing to an action descriptor reserved for '${n.Condition}' entities.
94
+ 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:t,modifiedData:e}}subscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]||(this.detachedDependents[t.entity.id]=t)}),this}syncDependents(){const e=[],t=[],r=[],a=[];return Object.values(this.detachedDependents).forEach(l=>{const o=l.entity.afterAllChildrenInitialized();e.push(...o.updated),t.push(...o.added),r.push(...o.removed),a.push(...o.affected)}),{updated:p(e),added:p(t),removed:p(r),affected:p(a),self:this}}onDetachedDependencyRemoved(e,t,r){const a=[],l=[],o=[],d=[];return{updated:p(a),added:p(l),removed:p(o),affected:p(d),self:this}}onDetachedDependencyRestored(e,t,r){const a=[],l=[],o=[],d=[];return{updated:p(a),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=I.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 Pe(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.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],r=[],a=[],l=[];if(this.parent&&this.parent.type!==n.BuiltInBaseEntity&&this.parent.type!==n.PrimitiveEntity){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),r.push(...o.added),a.push(...o.removed)}return{updated:p(t),added:p(r),removed:p(a),affected:p(l),self:this}}async restoreVersion(e){var d;const t=[],r=[],a=[],l=[];if(this.version===e)return{updated:p(t),added:p(r),removed:p(a),affected:p(l),self:this};if(!this.knownVersions){const u=new Map;for(const[h,c]of this.knownVersions||new Map){if(u.set(h,c),c.activeVersion=!1,c.knownVersions)for(const[v,E]of c.knownVersions)u.set(v,E);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 Pe(u,this.project)}return this.metaSync(o.toShallowJSON(),null),this.inputs=o.inputs,this.outputs=o.outputs,this.error=o.error,this.parent=o.parent,{updated:p(t),added:p(r),removed:p(a),affected:p(l),self:this}}hydrateAncestors(){const e=[],t=[],r=[],a=[];if(this.initialData.parent){const l=B(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(r),affected:p(a),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new b(this.project,"",T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],r=[],a=[],l=[];return this.initialized=!0,this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:p(t),added:p(r),removed:p(a),affected:p(l),self:this}}addSelfToProject(e=this.project.addChangeSet(new b(this.project,"",T().toISOString(),this,!0,"add-self-to-project"))){const t=[this],r=[],a=[],l=[];return this.parent?(this.parent.type===n.DefinitionEntity?(this.parent.addAbstractMethod(this),t.push(this.parent)):this.parent.type===n.DataType&&(this.parent.setEntity(this),t.push(this.parent)),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:p(t),added:p(r),removed:p(a),affected:p(l),self:this}):(this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:p(t),added:p(r),removed:p(a),affected:p(l),self:this})}setParent(e,t=this.project.addChangeSet(new b(this.project,"",T().toISOString(),this,!0,"set-parent"))){var r;return((r=this.parent)==null?void 0:r.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,A.Updated),t==null||t.attemptAutoclose("set-parent",this.id))),this}initChildren(e=this.project.addChangeSet(new b(this.project,"",T().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.inputs=this.initialData.inputs.map(t=>{const r=C(t,this.project);return r.setParent(this,null),r.initChildren(e),r}),this.outputs=this.initialData.outputs.map(t=>{const r=C(t,this.project);return r.setParent(this,null),r.initChildren(e),r}),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 b(this.project,"",T().toISOString(),this,!0,"meta-sync"))){const r=lt(this,e),a=this.toMeta();return this.name=e.name||a.name,this.description=e.description||a.description,super.metaSync(e),e.deleted===!0&&!a.deleted?t==null||t.add(this,A.Removed):e.deleted===!1&&a.deleted?t==null||t.add(this,A.Added):r&&(t==null||t.add(this,A.Updated)),t==null||t.attemptAutoclose("meta-sync",this.id),this}async APILoad(e=L,...t){return await Pe.repository.APILoad(this.id,...t),this}async APICreate(e=L,...t){return await Pe.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=L,...t){return await Pe.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=L,...t){return await Pe.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=L,...t){return await Pe.repository.APIClone(this.id,...t),this}async APILoadVersion(e=L,t,...r){return await Pe.repository.APILoadVersion(this.id,t,...r)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new b(this.project,"",T().toISOString(),this,!0,"remove-entity"))){const r=[],a=[],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(a.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(d=>{const{updated:u,removed:h,added:c}=d.entity.onDetachedDependencyRemoved(this,d.field,t);r.push(...u),a.push(...h),l.push(...c)}),this.inputs.forEach(d=>{const u=d.remove({ignoreUpstream:!0},t);r.push(...u.updated),a.push(...u.removed)}),this.outputs.forEach(d=>{const u=d.remove({ignoreUpstream:!0},t);r.push(...u.updated),a.push(...u.removed)}),this.error){const d=this.error.remove({ignoreUpstream:!0},t);r.push(...d.updated),a.push(...d.removed)}return t==null||t.attemptAutoclose("remove-entity",this.id),{added:p(l),updated:p(r),removed:p(a),affected:p(o),self:this}}restore({}={},e=this.project.addChangeSet(new b(this.project,"",T().toISOString(),this,!0,"restore-entity"))){const t=[],r=[],a=[],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),this.inputs.forEach(o=>{const d=o.restore({},e);r.push(...d.updated)}),this.outputs.forEach(o=>{const d=o.restore({},e);r.push(...d.updated)}),this.error){const o=this.error.restore({},e);r.push(...o.updated)}return e==null||e.attemptAutoclose("restore-entity",this.id),{added:p(t),updated:p(r),removed:p(a),affected:p(l),self:this}}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.inputs.flatMap(r=>r.toFlat(e)),...this.outputs.flatMap(r=>r.toFlat(e))])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.inputs.flatMap(r=>r.toFlatIds(e)),...this.outputs.flatMap(r=>r.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,type:this.type,name:this.name}}toJSON(e=new Set){var t,r;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,error:((t=this.error)==null?void 0:t.toJSON())||null,inputs:this.inputs.map(a=>a.toJSON()),outputs:this.outputs.map(a=>a.toJSON()),parent:((r=this.parent)==null?void 0:r.toReference())||null})}toJSONClone(e=Z){var r,a,l,o,d,u,h;let t;return(r=e.seenEntityMaps)!=null&&r.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||ct(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(a=e.seenEntities)!=null&&a.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:I.UUID.uuid(),createdAt:e.timestamp||T().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,error:((u=this.error)==null?void 0:u.toJSONClone({...e,newId:null}))||null,inputs:this.inputs.map(c=>c.toJSONClone({...e,newId:null})),outputs:this.outputs.map(c=>c.toJSONClone({...e,newId:null})),parent:((h=this.parent)==null?void 0:h.toReference({seenEntityMaps:e.seenEntityMaps}))||null})}toReference(e=Z){var r;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+I.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=Z){var r,a,l;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.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,error:((a=this.error)==null?void 0:a.toReference(e))||null,inputs:this.inputs.map(o=>o.toReference(e)),outputs:this.outputs.map(o=>o.toReference(e)),parent:((l=this.parent)==null?void 0:l.toReference(e))||null}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.inputs.flatMap(r=>r.toFlatJSON(e)),...this.outputs.flatMap(r=>r.toFlatJSON(e))])}toGenerationTarget(){var e;return{id:this.id,name:this.name,description:this.description,type:this.type,parent:((e=this.parent)==null?void 0:e.id)||void 0}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...this.inputs.flatMap(r=>r.toFlatGenerationTarget(e)),...this.outputs.flatMap(r=>r.toFlatGenerationTarget(e))])}asFunctionDeclarationTransfer(e,t=this.project.addChangeSet(new b(this.project,"",T().toISOString(),this,!0,"implement-as-function-declaration"))){var d;const r=e||I.UUID.uuid(),a=I.UUID.uuid(),l=this.inputs.map((u,h)=>{var v;const c={id:I.UUID.uuid(),type:n.GenericReference,version:a,entityType:n.FunctionDeclaration,entityId:r};return{id:I.UUID.uuid(),version:I.UUID.uuid(),createdAt:(t==null?void 0:t.timestamp)||T().toISOString(),author:I.sessionAuthor,previousVersion:null,deleted:!1,type:n.ArgumentDeclaration,name:u.name,required:u.required,implements:u.toJSON(),constant:!0,writesValues:[],defaultValue:null,description:u.description,index:h,dataType:((v=u.dataType)==null?void 0:v.toJSONClone({timestamp:(t==null?void 0:t.timestamp)||T().toISOString()}))||null,parent:c}}),o=[];if(this.outputs.length){const u=this.outputs.map((E,O)=>{var V;const w={id:I.UUID.uuid(),type:n.GenericReference,entityId:r,version:a,entityType:n.ReturnStatement};return{id:I.UUID.uuid(),version:I.UUID.uuid(),createdAt:(t==null?void 0:t.timestamp)||T().toISOString(),author:I.sessionAuthor,previousVersion:null,deleted:!1,type:n.ReturnDeclaration,name:E.name,description:E.description,readsValue:null,constant:!0,required:E.required,defaultValue:null,implements:E.toJSON(),isError:!1,index:O,dataType:((V=E.dataType)==null?void 0:V.toJSONClone())||null,parent:w}}),h={id:I.UUID.uuid(),type:n.GenericReference,version:a,entityType:n.FunctionDeclaration,entityId:r},c={id:I.UUID.uuid(),type:n.GenericReference,version:a,entityType:n.FunctionDeclaration,entityId:r},v={id:I.UUID.uuid(),version:I.UUID.uuid(),createdAt:(t==null?void 0:t.timestamp)||T().toISOString(),author:I.sessionAuthor,previousVersion:null,deleted:!1,type:n.ReturnStatement,outputs:u,throws:null,calledBySuccess:[],calledByError:[],calledByEntry:[c],parent:h,x:0,y:0};o.push(v)}return t==null||t.attemptAutoclose("implement-as-function-declaration",this.id),{id:r,version:a,createdAt:(t==null?void 0:t.timestamp)||T().toISOString(),author:I.sessionAuthor,previousVersion:null,deleted:!1,type:n.FunctionDeclaration,name:this.name,description:this.description,inputs:l,calls:o,collapsed:!1,private:!1,implements:this.toJSON(),index:0,parent:((d=this.parent)==null?void 0:d.toReference())||null,x:0,y:0}}implementAsGlobalEvent(e=this.project.addChangeSet(new b(this.project,"",T().toISOString(),this,!0,"implement-as-global-event")),t,r){const a=t||this.project,l=r||I.UUID.uuid(),o=I.UUID.uuid(),d={id:l,version:o,createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:I.sessionAuthor,previousVersion:null,deleted:!1,type:n.GlobalEvent,name:this.name,description:this.description,inputs:[],calls:[],collapsed:!1,implements:this.toJSON(),parent:(a==null?void 0:a.toReference())||null,x:0,y:0},u=C(d,this.project);if(u.setParent(a,e),u.initChildren(e),e==null||e.add(u,A.Added),u.hydrateAncestors(),u.addSelfToProject(e),this.inputs.map((h,c)=>{var V;const v={id:I.UUID.uuid(),type:n.GenericReference,version:o,entityType:n.GlobalEvent,entityId:l},E={id:I.UUID.uuid(),version:I.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:I.sessionAuthor,previousVersion:null,deleted:!1,type:n.ArgumentDeclaration,name:h.name,required:h.required,implements:h.toJSON(),constant:!0,writesValues:[],defaultValue:null,description:h.description,index:c,dataType:null,parent:v},O=C(E,this.project);O.setParent(u,e),O.initChildren(e),e==null||e.add(O,A.Added),O.hydrateAncestors(),O.addSelfToProject(e);const w=((V=h.dataType)==null?void 0:V.clone(e,O))||null;w&&(e==null||e.add(w,A.Added)),O.setDataType(w)}),this.outputs.length){const h=I.UUID.uuid(),c=I.UUID.uuid(),v={id:I.UUID.uuid(),type:n.GenericReference,version:o,entityType:n.GlobalEvent,entityId:l},E={id:I.UUID.uuid(),type:n.GenericReference,version:o,entityType:n.GlobalEvent,entityId:l},O={id:h,version:c,createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:I.sessionAuthor,previousVersion:null,deleted:!1,type:n.ReturnStatement,outputs:[],throws:null,calledBySuccess:[],calledByError:[],calledByEntry:[E],parent:v,x:0,y:0},w=C(O,this.project);w.setParent(u,e),w.initChildren(e),e==null||e.add(w,A.Added),w.hydrateAncestors(),w.addSelfToProject(e),this.outputs.map((V,U)=>{var J;const G={id:I.UUID.uuid(),type:n.GenericReference,entityId:h,version:c,entityType:n.ReturnStatement},_={id:I.UUID.uuid(),version:I.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:I.sessionAuthor,previousVersion:null,deleted:!1,type:n.ReturnDeclaration,name:V.name,description:V.description,readsValue:null,constant:!0,required:V.required,defaultValue:null,implements:V.toJSON(),isError:!1,index:U,dataType:null,parent:G},$=C(_,this.project);$.setParent(w,e),$.initChildren(e),e==null||e.add($,A.Added),$.hydrateAncestors(),$.addSelfToProject(e);const k=((J=V.dataType)==null?void 0:J.clone(e,$))||null;k&&(e==null||e.add(k,A.Added)),$.setDataType(k)})}return e==null||e.attemptAutoclose("implement-as-function-declaration",this.id),u}implementAsFunctionDeclaration(e=this.project.addChangeSet(new b(this.project,"",T().toISOString(),this,!0,"implement-as-function-declaration")),t,r){const a=t||this.project,l=r||I.UUID.uuid(),o=I.UUID.uuid(),d={id:l,version:o,createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:I.sessionAuthor,previousVersion:null,deleted:!1,type:n.FunctionDeclaration,name:this.name,description:this.description,inputs:[],calls:[],collapsed:!1,private:!1,implements:this.toJSON(),index:0,parent:(a==null?void 0:a.toReference())||null,x:0,y:0},u=C(d,this.project);if(u.setParent(a,e),u.initChildren(e),e==null||e.add(u,A.Added),u.hydrateAncestors(),u.addSelfToProject(e),this.inputs.map((h,c)=>{var V;const v={id:I.UUID.uuid(),type:n.GenericReference,version:o,entityType:n.FunctionDeclaration,entityId:l},E={id:I.UUID.uuid(),version:I.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:I.sessionAuthor,previousVersion:null,deleted:!1,type:n.ArgumentDeclaration,name:h.name,required:h.required,implements:h.toJSON(),constant:!0,writesValues:[],defaultValue:null,description:h.description,index:c,dataType:null,parent:v},O=C(E,this.project);O.setParent(u,e),O.initChildren(e),e==null||e.add(O,A.Added),O.hydrateAncestors(),O.addSelfToProject(e);const w=((V=h.dataType)==null?void 0:V.clone(e,O))||null;w&&(e==null||e.add(w,A.Added)),O.setDataType(w)}),this.outputs.length){const h=I.UUID.uuid(),c=I.UUID.uuid(),v={id:I.UUID.uuid(),type:n.GenericReference,version:o,entityType:n.FunctionDeclaration,entityId:l},E={id:I.UUID.uuid(),type:n.GenericReference,version:o,entityType:n.FunctionDeclaration,entityId:l},O={id:h,version:c,createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:I.sessionAuthor,previousVersion:null,deleted:!1,type:n.ReturnStatement,outputs:[],throws:null,calledBySuccess:[],calledByError:[],calledByEntry:[E],parent:v,x:0,y:0},w=C(O,this.project);w.setParent(u,e),w.initChildren(e),e==null||e.add(w,A.Added),w.hydrateAncestors(),w.addSelfToProject(e),this.outputs.map((V,U)=>{var J;const G={id:I.UUID.uuid(),type:n.GenericReference,entityId:h,version:c,entityType:n.ReturnStatement},_={id:I.UUID.uuid(),version:I.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:I.sessionAuthor,previousVersion:null,deleted:!1,type:n.ReturnDeclaration,name:V.name,description:V.description,readsValue:null,constant:!0,required:V.required,defaultValue:null,implements:V.toJSON(),isError:!1,index:U,dataType:null,parent:G},$=C(_,this.project);$.setParent(w,e),$.initChildren(e),e==null||e.add($,A.Added),$.hydrateAncestors(),$.addSelfToProject(e);const k=((J=V.dataType)==null?void 0:J.clone(e,$))||null;k&&(e==null||e.add(k,A.Added)),$.setDataType(k)})}return e==null||e.attemptAutoclose("implement-as-function-declaration",this.id),u}implementAsLoop(e=this.project.addChangeSet(new b(this.project,"",T().toISOString(),this,!0,"implement-as-loop")),t,r){const a=t||this.project,l=r||I.UUID.uuid(),o=I.UUID.uuid(),d={id:l,version:o,createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:I.sessionAuthor,previousVersion:null,deleted:!1,type:n.Loop,declaration:this.toJSON(),inputs:[],outputs:[],error:null,process:null,successCalls:[],errorCalls:[],calledByEntry:[],calledByError:[],calledBySuccess:[],outputsDeclarations:[],body:null,x:0,y:0,parent:a.toReference()},u=C(d,this.project);return u.setParent(a,e),u.initChildren(e),e==null||e.add(u,A.Added),u.hydrateAncestors(),u.addSelfToProject(e),u.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("implement-as-loop",this.id),u}implementAsOperation(e=this.project.addChangeSet(new b(this.project,"",T().toISOString(),this,!0,"implement-as-operation")),t,r){const a=t||this.project,l=r||I.UUID.uuid(),o=I.UUID.uuid(),d={id:l,version:o,createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:I.sessionAuthor,previousVersion:null,deleted:!1,type:n.Operation,declaration:this.toJSON(),inputs:[],outputs:[],error:null,process:null,successCalls:[],errorCalls:[],calledByEntry:[],calledByError:[],calledBySuccess:[],x:0,y:0,parent:a.toReference()},u=C(d,this.project);return u.setParent(a,e),u.initChildren(e),e==null||e.add(u,A.Added),u.hydrateAncestors(),u.addSelfToProject(e),u.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("implement-as-operation",this.id),u}implementAsCondition(e=this.project.addChangeSet(new b(this.project,"",T().toISOString(),this,!0,"implement-as-condition")),t,r){const a=t||this.project,l=r||I.UUID.uuid(),o=I.UUID.uuid(),d={id:l,version:o,createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:I.sessionAuthor,previousVersion:null,deleted:!1,type:n.Condition,declaration:this.toJSON(),inputs:[],successCalls:[],errorCalls:[],calledByEntry:[],calledByError:[],calledBySuccess:[],x:0,y:0,parent:a.toReference()},u=C(d,this.project);return u.setParent(a,e),u.initChildren(e),e==null||e.add(u,A.Added),u.hydrateAncestors(),u.addSelfToProject(e),u.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("implement-as-condition",this.id),u}clearErrors(){var e;return this.errors=[],this.inputs.forEach(t=>t.clearErrors()),this.outputs.forEach(t=>t.clearErrors()),(e=this.error)==null||e.clearErrors(),this}validate(){const e=aq(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){return[...this.errors,...this.inputs.flatMap(t=>t.getErrors()),...this.outputs.flatMap(t=>t.getErrors())]}getShallowErrors(){return this.errors}clone(e=this.project.addChangeSet(new b(this.project,"",T().toISOString(),this,!0,"clone-entity")),t=null,r=null,a=!0){var w,V;if(Array.from(new Set([...Cr(),...this.project.getAllBuiltInIds()])).includes(this.id))return this;let o=ft(t,this);const d=this.toJSON(),u=r||I.UUID.uuid();d.inputs=[],d.outputs=[],d.error=null;const h=u.split("-id"),c=h[h.length-1||0]||u;d.id=u,d.version=I.UUID.uuid(),d.createdAt=(e==null?void 0:e.timestamp)||T().toISOString(),d.author=(e==null?void 0:e.author)||"1",d.previousVersion=null,d.deleted=!1;const v=dt(d,o);e==null||e.add(v,A.Added),t?v.setParent(t,null):this.parent&&v.setParent(this.parent,null),a&&v.subscribe(),v.initChildren(e);const E=(w=this.inputs)==null?void 0:w.map((U,G)=>U.clone(e,v,c+"-argument-value-descriptor-"+G+"-id",a));v.inputs=E;const O=(V=this.outputs)==null?void 0:V.map((U,G)=>U.clone(e,v,c+"-return-value-descriptor-"+G+"-id",a));return v.outputs=O,this.error&&(v.error=this.error.clone(e,v,c+"-error-action-descriptor-id",a)),e==null||e.attemptAutoclose("clone-entity",this.id),v}addInput(e){return this.inputs.find(t=>t.id===e.id)||this.inputs.push(e),this}removeInput(e){return this.inputs=this.inputs.filter(t=>t.id!==e.id),this}addOutput(e){return this.outputs.find(t=>t.id===e.id)||this.outputs.push(e),this}removeOutput(e){return this.outputs=this.outputs.filter(t=>t.id!==e.id),this}};f(Pe,"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,...r)=>null}),f(Pe,"type",n.ActionDescriptor),f(Pe,"USER_MANAGED_PARENT_TYPES",[n.DefinitionEntity,n.DataType]),f(Pe,"PARENT_TYPES",[...Pe.USER_MANAGED_PARENT_TYPES,n.PrimitiveEntity,n.BuiltInBaseEntity]),f(Pe,"MUTABLE_BASE_PROPERTIES",["name","description"]),f(Pe,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),f(Pe,"BASE_PROPERTIES",[...Pe.MUTABLE_BASE_PROPERTIES,...Pe.INMUTABLE_BASE_PROPERTIES]),f(Pe,"MUTABLE_META_PROPERTIES",[...Pe.MUTABLE_BASE_PROPERTIES]),f(Pe,"INMUTABLE_META_PROPERTIES",[...Pe.INMUTABLE_BASE_PROPERTIES]),f(Pe,"META_PROPERTIES",[...Pe.MUTABLE_META_PROPERTIES,...Pe.INMUTABLE_META_PROPERTIES]),f(Pe,"MUTABLE_UPSTREAM_PROPERTIES",[]),f(Pe,"INMUTABLE_UPSTREAM_PROPERTIES",["parent"]),f(Pe,"UPSTREAM_PROPERTIES",[...Pe.MUTABLE_UPSTREAM_PROPERTIES,...Pe.INMUTABLE_UPSTREAM_PROPERTIES]),f(Pe,"MUTABLE_DOWNSTREAM_PROPERTIES",["inputs","outputs"]),f(Pe,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),f(Pe,"DOWNSTREAM_PROPERTIES",[...Pe.MUTABLE_DOWNSTREAM_PROPERTIES,...Pe.INMUTABLE_DOWNSTREAM_PROPERTIES]),f(Pe,"PROPERTIES",[...Pe.META_PROPERTIES,...Pe.UPSTREAM_PROPERTIES,...Pe.DOWNSTREAM_PROPERTIES]);let qe=Pe;var Q1=(i=>(i.Parent="parent",i))(Q1||{});const ae=class ae extends rt{constructor(e,t){super(e);f(this,"initialData");f(this,"id");f(this,"x");f(this,"y");f(this,"type",n.Loop);f(this,"declaration");f(this,"inputs",[]);f(this,"outputs",[]);f(this,"process",null);f(this,"successCalls",[]);f(this,"errorCalls",[]);f(this,"error",null);f(this,"outputsDeclarations",[]);f(this,"body");f(this,"calledBySuccess",[]);f(this,"calledByError",[]);f(this,"calledByEntry",[]);f(this,"parent");f(this,"detachedChildren",[]);f(this,"currentIterationNumberArgumentDeclaration");f(this,"currentValueArgumentDeclaration",null);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}static fromGenerationTarget(e,t){let r=t;if(e.parent){const v=B(e.parent);r=t.get(v)}const a=B(e.declaration),l=t.get(a),o=e.calledByEntry.map(v=>{const E=B(v);return t.get(E)}),d=e.calledBySuccess.map(v=>{const E=B(v);return t.get(E)}),u=e.calledByError.map(v=>{const E=B(v);return t.get(E)}),h={id:e.id,version:I.UUID.uuid(),createdAt:T().toISOString(),author:I.sessionAuthor,previousVersion:null,deleted:!1,type:n.Loop,declaration:l,calledByEntry:o,calledBySuccess:d,calledByError:u,process:null,errorCalls:[],successCalls:[],inputs:[],outputs:[],body:null,outputsDeclarations:[],error:null,x:0,y:0,parent:r},c=C(h,t);return c.setParent(r,null),c.initChildren(null),c}static validateGenerationTarget(e,t){let r=JSON.parse(JSON.stringify(e));const a=[],l=Et(r,{parent:{list:!1,types:[...mt,n.Project],optional:!0},declaration:{list:!1,types:[n.ActionDescriptor]}},t);return r=l.modifiedData,a.push(...l.errors,...ot(r)),e.declaration?t.get(e.declaration)?t.conditionDeclarations.find(u=>u.id===e.declaration)||a.push(new P({id:`${e.id}--${R.InvalidImplementsReference}`,code:R.InvalidImplementsReference,severity:D.Error,message:`Entity of type '${e.type}' with id '${e.id}' has an 'declaration' property that isn't pointing to an action descriptor reserved for '${n.Condition}' entities.
95
95
  ${Gl(t)}`,issue:null})):a.push(new P({id:`${e.id}--${R.ReferencedEntityNotFound}`,code:R.ReferencedEntityNotFound,severity:D.Error,message:`Entity of type '${e.type}' with id '${e.id}' has an 'declaration' property that isn't found in the project. The 'declaration' property must point to one of the built-in action descriptors reserved for '${n.Condition}' entities.
96
96
  ${Gl(t)}`,issue:null})):a.push(new P({id:`${e.id}--${j.InvalidObjectStructure}`,code:j.InvalidObjectStructure,severity:D.Error,message:`Entity of type '${e.type}' with id '${e.id}' is missing the 'declaration' property. This property is required for a '${e.type}' entity and must point to one of the built-in action descriptors reserved for '${n.Condition}' entities.
97
97
  ${Gl(t)}`,issue:null})),{errors:a,modifiedData:r}}static fromReturnDeclarationToBodyArgumentDeclarationName(e){return`Previous iteration results of '${F(e,e.project)}'`}static fromBodyArgumentDeclarationToReturnDeclarationName(e){const t=e.name.replace("Previous iteration results of '","");return t.slice(0,t.length-1)}static fromReturnDeclarationToLoopOutputDeclarationName(e){return`Result list of '${F(e,e.project)}'`}static fromLoopOutputDeclarationToReturnDeclarationName(e){const t=e.name.replace("Result list of '","");return t.slice(0,t.length-1)}static fromLoopOutputDeclarationToBodyArgumentDeclarationName(e){return e.name.replace("Result list of '","Previous iteration results of '")}static fromBodyArgumentDeclarationToLoopOutputDeclarationName(e){return e.name.replace("Previous iteration results of '","Result list of '")}get continueStatements(){const e=[];return Object.values(this.detachedDependents).forEach(t=>{t.field===bc.Parent&&t.entity.type===n.ContinueStatement&&!e.includes(t.entity)&&e.push(t.entity)}),e}get breakStatements(){const e=[];return Object.values(this.detachedDependents).forEach(t=>{t.field===Dc.Parent&&t.entity.type===n.BreakStatement&&!e.includes(t.entity)&&e.push(t.entity)}),e}validateGeneratedUpdate(e){const t=[];return e.parent&&t.push(new P({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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elyx-code/project-logic-tree",
3
- "version": "0.0.6194",
3
+ "version": "0.0.6195",
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",