@elyx-code/project-logic-tree 0.0.6149 → 0.0.6150

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
@@ -30692,8 +30692,12 @@ Alternatively you can update the entity with 'update' action. Or replace it by f
30692
30692
  const a = D(
30693
30693
  this.initialData.parent
30694
30694
  ), o = this.project.get(a);
30695
- o && (this.setParent(o), e.push(o));
30696
- }
30695
+ if (o)
30696
+ this.setParent(o), e.push(o);
30697
+ else
30698
+ throw new Error(`Data type with id '${this.id}' has a parent reference '${a}' that isn't found in the project`);
30699
+ } else
30700
+ throw new Error("Data type must have a parent");
30697
30701
  if (this.initialData.entity) {
30698
30702
  const a = D(
30699
30703
  this.initialData.entity
@@ -57,7 +57,7 @@ ${Sn}`,issue:null}))}}}const l=i.parent&&t.get(i.parent)||t.getBuiltIn(i.parent)
57
57
  The entitities of type '${K(f,"', '","' and '")}' can only have one 'data-type' child under the 'dataType' property so no 'parentRelationType' is needed.`,issue:null})),l.dataType)){const v=(h=l.dataType)==null?void 0:h.id;a.push(new g({id:`${e.id}--${T.NewEntityWouldOverriteExisting}`,code:T.NewEntityWouldOverriteExisting,severity:E.Error,message:`The entity with id '${e.id}' and type '${e.type}', cannot be added as a child to the entity with id '${i.parent}' and type '${y}', because it already has a 'data-type' child with id '${v}'.
58
58
  The entitities of type '${K(f,"', '","' and '")}' can only have one 'data-type' child under the 'dataType' property. You can inspect the existing data-type entity with the 'describe_entity' action. Like so:
59
59
  ${Fr({describe_entity:v})}
60
- Alternatively you can update the entity with 'update' action. Or replace it by first removing it and then creating a new one.`,issue:null}))}y===r.DataType&&(!i.parentRelationType||!(i.parentRelationType===ft.AndDataTypeGroup||i.parentRelationType===ft.OrDataTypeGroup))&&a.push(new g({id:`${e.id}--${T.InvalidParentRelationType}`,code:T.InvalidParentRelationType,severity:E.Error,message:`The entity with id '${e.id}' and type '${e.type}', must have a 'parentRelationType' property set to either 'or-data-type-group' or 'and-data-type-group' when being added as a child to an entity of type 'data-type'.`,issue:null}))}return{errors:a,modifiedData:i}}get isGroup(){const e=[...this.andChildrenGroup||[],...this.orChildrenGroup||[]];if(e.length>1){let t=0;for(const i of e)if(i.isResolved&&(t++,t>1))return!0}return!1}get isResolved(){return[r.BuiltInBaseEntity,r.ActionDescriptor].includes(this.parent.type)||Cn(this.parent)?!0:!(!this.entity&&!this.isGroup)}validateGeneratedUpdate(e){return{errors:[],modifiedData:e}}hydrateAncestors(){const e=[],t=[],i=[];if(this.initialData.parent){const a=P(this.initialData.parent),o=this.project.get(a);o&&(this.setParent(o),e.push(o))}if(this.initialData.entity){const a=P(this.initialData.entity),o=this.project.get(a);o&&(o.type===r.DefinitionEntity&&o.parent===this||(this.setEntity(o),e.push(o)))}return{updated:m(e),added:m(t),removed:m(i),self:this}}afterAllChildrenInitialized(){const e=[],t=[],i=[];return this.initialized=!0,{updated:m(e),added:m(t),removed:m(i),self:this}}addSelfToProject(){const e=[this],t=[],i=[];return this.parent.type===r.DataType?this.parentRelationType===ft.AndDataTypeGroup?this.parent.addToAndGroup(this):this.parentRelationType===ft.OrDataTypeGroup&&this.parent.addToOrGroup(this):this.parent.setDataType(this),e.push(this.parent),{updated:m(e),added:m(t),removed:m(i),self:this}}setParent(e){return this.parent=e,this}removeChildGroup(e){if(this.andChildrenGroup){const t=this.andChildrenGroup.findIndex(i=>i.id===e.id);t!==-1&&this.andChildrenGroup.splice(t,1)}if(this.orChildrenGroup){const t=this.orChildrenGroup.findIndex(i=>i.id===e.id);t!==-1&&this.orChildrenGroup.splice(t,1)}return this}initChildren(){var e,t;if(this.initialized)return this;if(this.initialized=!0,this.initialData.entity)if(this.initialData.entity.type===r.GenericReference){const i=this.project.findSubscribedInstanceFromReference(this.initialData.entity);this.entity=i}else this.entity=b(this.initialData.entity,this.project),((t=(e=this.initialData.entity)==null?void 0:e.parent)==null?void 0:t.id)===this.id&&this.entity.setParent(this),this.entity.type===r.DefinitionEntity&&this.entity.initChildren();return this.initialData.andChildrenGroup&&(this.andChildrenGroup=this.initialData.andChildrenGroup.map(i=>{const a=b(i,this.project);return a.setParent(this),a.initChildren(),a})),this.initialData.orChildrenGroup&&(this.orChildrenGroup=this.initialData.orChildrenGroup.map(i=>{const a=b(i,this.project);return a.setParent(this),a.initChildren(),a})),this.afterAllChildrenInitialized(),this}subscribe(){return this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}sync(e){return super.sync(e),this.options=e.options||this.options,this.parentRelationType=e.parentRelationType||this.parentRelationType,this.isList=e.isList!==void 0?e.isList:this.isList,this.inferred=e.inferred!==void 0?e.inferred:this.inferred,this.like=e.like!==void 0?e.like:this.like,this.asType=e.asType!==void 0?e.asType:this.asType,this.implementationChooseOne=e.implementationChooseOne!==void 0?e.implementationChooseOne:this.implementationChooseOne,this}async load(e=L,...t){return await ve.repository.load(this.id,...t),this}async create(e=L,...t){return await ve.repository.create(this.toShallowJSON(),...t),this}async update(e=L,...t){return await ve.repository.update(this.toShallowJSON(),...t),this}async delete(e=L,...t){return await ve.repository.delete(this.id,...t),this}remove({ignoreUpstream:e,seenEntities:t}={ignoreUpstream:!1,seenEntities:new Set}){const i=[],a=[];if(t.has(this.id))return{affected:[],removed:[]};if(t.add(this.id),a.push(this),this.unsubscribe(),this.entity&&this.entity.type===r.DefinitionEntity&&this.entity.parent===this){const{affected:o,removed:l}=this.entity.remove({ignoreUpstream:!0,seenEntities:t});i.push(...o),a.push(...l)}if(!e){this.parent.type===r.DataType&&this.parent.removeChildGroup(this);const o=this.parent;if(o.type===r.DataType){if(this.parentRelationType===ft.AndDataTypeGroup){if(Array.isArray(o.andChildrenGroup)){const l=o.andChildrenGroup.findIndex(d=>d.id===this.id);l!==-1&&o.andChildrenGroup.splice(l,1)}}else if(this.parentRelationType===ft.OrDataTypeGroup&&Array.isArray(o.orChildrenGroup)){const l=o.orChildrenGroup.findIndex(d=>d.id===this.id);l!==-1&&o.orChildrenGroup.splice(l,1)}}else this.parent.removeDataType();i.push(o)}return{affected:m(i),removed:m(a)}}restore({seenEntities:e}={seenEntities:new Set}){const t=[];if(e.has(this.id))return{affected:[],self:this};if(e.add(this.id),this.subscribe(),this.entity&&this.entity.type===r.DefinitionEntity&&this.entity.parent===this){const{affected:i}=this.entity.restore({seenEntities:e});t.push(...i)}if(this.parent.type===r.DataType){const i=this.parent;Array.isArray(i.andChildrenGroup)&&i.andChildrenGroup.push(this)}if(this.parent.type===r.DataType){const i=this.parent;this.parentRelationType===ft.AndDataTypeGroup?Array.isArray(i.andChildrenGroup)&&i.andChildrenGroup.push(this):this.parentRelationType===ft.OrDataTypeGroup&&Array.isArray(i.orChildrenGroup)&&i.orChildrenGroup.push(this)}else{const i=this.parent;i.setDataType(this),t.push(i)}return{affected:t,self:this}}toFlat(e=new Set){var i,a,o;return e.has(this.id)?[]:(e.add(this.id),[this,...((i=this.andChildrenGroup)==null?void 0:i.flatMap(l=>l.toFlat(e)))||[],...((a=this.orChildrenGroup)==null?void 0:a.flatMap(l=>l.toFlat(e)))||[],...((o=this.entity)==null?void 0:o.toFlat(e))||[]])}toFlatIds(e=new Set){var i,a,o;return e.has(this.id)?[]:(e.add(this.id),[this.id,...((i=this.andChildrenGroup)==null?void 0:i.flatMap(l=>l.toFlatIds(e)))||[],...((a=this.orChildrenGroup)==null?void 0:a.flatMap(l=>l.toFlatIds(e)))||[],...((o=this.entity)==null?void 0:o.toFlatIds(e))||[]])}toJSON(e=new Set){var t,i,a,o;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,options:this.options,isList:this.isList,asType:this.asType,like:this.like,inferred:this.inferred,parentRelationType:this.parentRelationType,implementationChooseOne:this.implementationChooseOne,andChildrenGroup:((t=this.andChildrenGroup)==null?void 0:t.map(l=>l.toJSON(e)))||null,orChildrenGroup:((i=this.orChildrenGroup)==null?void 0:i.map(l=>l.toJSON(e)))||null,entity:((a=this.entity)==null?void 0:a.parent)===this?this.entity.toJSON(e):((o=this.entity)==null?void 0:o.toReference())||null,parent:this.parent.toReference()})}toJSONClone(e=F){var i,a,o,l,d,h,y,f,v;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||at(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(a=e.seenEntities)!=null&&a.has(t)||(o=e.seenEntities)!=null&&o.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((l=e.seenEntities)==null||l.add(t),(d=e.seenEntities)==null||d.add(this.id),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,options:this.options,isList:this.isList,asType:this.asType,like:this.like,inferred:this.inferred,parentRelationType:this.parentRelationType,implementationChooseOne:this.implementationChooseOne,andChildrenGroup:((h=this.andChildrenGroup)==null?void 0:h.map(R=>R.toJSONClone({...e,newId:null})))||null,orChildrenGroup:((y=this.orChildrenGroup)==null?void 0:y.map(R=>R.toJSONClone({...e,newId:null})))||null,entity:((f=this.entity)==null?void 0:f.parent)===this?this.entity.toJSONClone({...e,newId:null}):((v=this.entity)==null?void 0:v.toReference({seenEntityMaps:e.seenEntityMaps}))||null,parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps})})}toReference(e=F){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+B.UUID.uuid()+"--ref",type:r.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=F){var i,a,o,l;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,isList:this.isList,options:this.options,asType:this.asType,parentRelationType:this.parentRelationType,like:this.like,inferred:this.inferred,implementationChooseOne:this.implementationChooseOne,andChildrenGroup:((a=this.andChildrenGroup)==null?void 0:a.map(d=>d.toReference(e)))||null,orChildrenGroup:((o=this.orChildrenGroup)==null?void 0:o.map(d=>d.toReference(e)))||null,entity:((l=this.entity)==null?void 0:l.toReference(e))||null,parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){var i,a,o;return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...((i=this.andChildrenGroup)==null?void 0:i.flatMap(l=>l.toFlatJSON(e)))||[],...((a=this.orChildrenGroup)==null?void 0:a.flatMap(l=>l.toFlatJSON(e)))||[],...((o=this.entity)==null?void 0:o.toFlatJSON(e))||[]])}toGenerationTarget(){var e;return{id:this.id,type:this.type,options:this.options,isList:this.isList,like:this.like,parentRelationType:this.parentRelationType,asType:this.asType,entity:((e=this.entity)==null?void 0:e.id)||null,parent:this.parent.id}}toFlatGenerationTarget(e=new Set){var i,a;return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...((i=this.andChildrenGroup)==null?void 0:i.flatMap(o=>o.toFlatGenerationTarget(e)))||[],...((a=this.orChildrenGroup)==null?void 0:a.flatMap(o=>o.toFlatGenerationTarget(e)))||[],...this.entity&&this.entity.type==r.DefinitionEntity&&this.entity.parent===this&&this.entity.toFlatGenerationTarget(e)||[]])}clearErrors(){var e,t,i;return this.errors=[],(e=this.andChildrenGroup)==null||e.forEach(a=>a.clearErrors()),(t=this.orChildrenGroup)==null||t.forEach(a=>a.clearErrors()),this.inferred&&((i=this.entity)==null||i.clearErrors()),this}validate(){const e=m7(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){return[...this.errors]}getShallowErrors(){return this.errors}clone(e=null,t=null,i=!0){var I,D,A;let a=st(e,this),o=e||this.parent;const l=t||Fe(Rs(this),r.DataType,a),d=l.split("-id"),h=d[d.length-1||0]||l,y={id:l,version:"1",createdAt:$().toDate(),author:"1",previousVersion:null,deleted:!1,type:r.DataType,isList:this.isList,asType:this.asType,options:this.options,parentRelationType:this.parentRelationType,like:this.like,inferred:this.inferred,implementationChooseOne:this.implementationChooseOne,andChildrenGroup:null,orChildrenGroup:null,entity:null,parent:o.toReference()},f=rt(y,a);e&&f.setParent(e),i&&f.subscribe(),f.initChildren();const v=(I=this.andChildrenGroup)==null?void 0:I.map((M,q)=>M.clone(f,h+"-and-group-data-type-"+q+"-id",i)),R=(D=this.orChildrenGroup)==null?void 0:D.map((M,q)=>M.clone(f,h+"-or-group-data-type-"+q+"-id",i));if(f.andChildrenGroup=v||null,f.orChildrenGroup=R||null,this.entity&&this.entity.type===r.DefinitionEntity&&((A=this.entity)==null?void 0:A.parent)===this){const M=this.entity.clone(f,B.UUID.uuid(),i);f.setEntity(M)}else this.entity&&f.setEntity(this.entity);return f}merge(e){const t=[],i=[],a=[];if(this.asType!==(e==null?void 0:e.asType)&&(this.sync({asType:e==null?void 0:e.asType}),t.push(this)),this.isList!==!(e!=null&&e.isList)&&(this.sync({isList:e==null?void 0:e.isList}),t.push(this)),this.like!==(e==null?void 0:e.like)&&(this.sync({like:e==null?void 0:e.like}),t.push(this)),e!=null&&e.inferred){if(e.entity&&e.entity.type===r.DefinitionEntity&&e.entity.parent===e){const o=e.entity.clone(this,B.UUID.uuid(),!0);this.setEntity(o),i.push(o)}else e.entity&&(this.setEntity(e.entity),t.push(this));this.inferred||(this.sync({inferred:!0}),t.push(this))}else if(this.inferred){if(this.sync({inferred:!1}),t.push(this),this.entity&&this.entity.type===r.DefinitionEntity&&this.entity.parent===this){const{affected:o,removed:l}=this.entity.remove({ignoreUpstream:!0,seenEntities:new Set});a.push(...l),o.push(...o)}e.entity!==this.entity&&(this.setEntity(e.entity),t.push(this))}else e.entity!==this.entity&&(this.setEntity(e.entity),t.push(this));return{updated:m(t),added:m(i),removed:m(a),self:this}}addToAndGroup(e){return this.andChildrenGroup||(this.andChildrenGroup=[]),this.andChildrenGroup.includes(e)||this.andChildrenGroup.push(e),this}addToOrGroup(e){return this.orChildrenGroup||(this.orChildrenGroup=[]),this.orChildrenGroup.includes(e)||this.orChildrenGroup.push(e),this}setEntity(e){return this.entity=e,this}isObject(){return!!this.entity&&(this.entity.type===r.DefinitionEntity||this.entity.name===V.KeyValue)}hasStrictObjectStructure(){var e;return this.isObject()&&((e=this.entity)==null?void 0:e.type)===r.DefinitionEntity}inferFromInputs(e){var t;if(!this.inferred)return this;if(!this.entity&&e.length){const i={id:B.UUID.uuid(),type:r.DefinitionEntity,version:"1",createdAt:$().toDate(),author:"1",previousVersion:null,deleted:!1,name:C(this.parent,this.project)+" data type definition",description:((t=this.parent)==null?void 0:t.description)||null,static:!0,abstract:!1,properties:[],methods:[],extends:[],implements:[],abstractMethods:[],x:0,y:0,parent:this.toReference()},a=b(i,this.project);a.setParent(this),a.initChildren(),a.sync(i),this.setEntity(a)}return this.entity&&this.entity.type===r.DefinitionEntity&&this.entity.parent!==this&&this.entity.setParent(this),this.entity&&this.entity.inferFromInputs(e),this.like||this.sync({like:!0}),this}};u(ve,"repository",{create:async(e,...t)=>e,update:async(e,...t)=>e,delete:async(e,...t)=>{},load:async(e,...t)=>null}),u(ve,"type",r.DataType),u(ve,"USER_MANAGED_PARENT_TYPES",[r.Property,r.ArgumentDeclaration,r.ReturnDeclaration,r.VariableDeclaration,r.ValueDescriptor,r.InputMap,r.OutputMap,r.DataType]),u(ve,"PARENT_TYPES",[...ve.USER_MANAGED_PARENT_TYPES]),u(ve,"MUTABLE_BASE_PROPERTIES",["isList","asType","options","parentRelationType","like"]),u(ve,"INMUTABLE_BASE_PROPERTIES",["id","version","type"]),u(ve,"BASE_PROPERTIES",[...ve.MUTABLE_BASE_PROPERTIES,...ve.INMUTABLE_BASE_PROPERTIES]),u(ve,"MUTABLE_META_PROPERTIES",[...ve.MUTABLE_BASE_PROPERTIES,"inferred"]),u(ve,"INMUTABLE_META_PROPERTIES",[...ve.INMUTABLE_BASE_PROPERTIES]),u(ve,"META_PROPERTIES",[...ve.MUTABLE_META_PROPERTIES,...ve.INMUTABLE_META_PROPERTIES]),u(ve,"MUTABLE_UPSTREAM_PROPERTIES",["entity","parent"]),u(ve,"INMUTABLE_UPSTREAM_PROPERTIES",[]),u(ve,"UPSTREAM_PROPERTIES",[...ve.MUTABLE_UPSTREAM_PROPERTIES,...ve.INMUTABLE_UPSTREAM_PROPERTIES]),u(ve,"MUTABLE_DOWNSTREAM_PROPERTIES",[]),u(ve,"INMUTABLE_DOWNSTREAM_PROPERTIES",["andChildrenGroup","orChildrenGroup"]),u(ve,"DOWNSTREAM_PROPERTIES",[...ve.MUTABLE_DOWNSTREAM_PROPERTIES,...ve.INMUTABLE_DOWNSTREAM_PROPERTIES]),u(ve,"PROPERTIES",[...ve.META_PROPERTIES,...ve.UPSTREAM_PROPERTIES,...ve.DOWNSTREAM_PROPERTIES]);let ca=ve;function v7(n){var l;const s=_6(),e=n.toJSON();s.safeParse(e).success;const i=E7(n),a=ln(n),o=[...i,...a];if(n.id==="exec-sequentially-operation-call-id"){const d=le({id:`${n.id}--${U.PropertyImplementsNonAbstact}`,message:`Property "${C(n,n.project)}" with id "${n.id}" implements a non-abstract property "${C(n,n.project)}" with id "${n.id}".`,issue:null,severity:E.Error,code:U.PropertyImplementsNonAbstact,entity:n});o.push(d.error)}return n.outputs.forEach(d=>d.validate()),(l=n.error)==null||l.validate(),je(n.errors,o)}function E7(n){const s=[];return n.inputs.forEach(e=>{e.validate()}),je(n.errors,s)}const Ee=class Ee extends Ke{constructor(e,t){super(e);u(this,"initialData");u(this,"id");u(this,"x");u(this,"y");u(this,"type",r.Operation);u(this,"declaration");u(this,"inputs",[]);u(this,"outputs",[]);u(this,"process",null);u(this,"successCalls",[]);u(this,"errorCalls",[]);u(this,"error",null);u(this,"calledBySuccess",[]);u(this,"calledByError",[]);u(this,"calledByEntry",[]);u(this,"parent");u(this,"errors",[]);u(this,"project");u(this,"initialized",!1);this.initialData=e,this.project=t,this.id=e.id,this.x=e.x,this.y=e.y}static fromGenerationTarget(e,t){let i=t;if(e.parent){const v=P(e.parent);i=t.get(v)}const a=P(e.declaration),o=t.get(a),l=e.calledByEntry.map(v=>{const R=P(v);return t.get(R)}),d=e.calledBySuccess.map(v=>{const R=P(v);return t.get(R)}),h=e.calledByError.map(v=>{const R=P(v);return t.get(R)}),y={id:e.id,version:"1",createdAt:$().toDate(),author:"1",previousVersion:null,deleted:!1,type:r.Operation,declaration:o,calledByEntry:l,calledBySuccess:d,calledByError:h,errorCalls:[],successCalls:[],inputs:[],outputs:[],process:null,error:null,x:0,y:0,parent:i},f=b(y,t);return f.setParent(i),f.initChildren(),f}static validateGenerationTarget(e,t){let i=JSON.parse(JSON.stringify(e));const a=[],o=mt(i,{parent:{list:!1,types:[...ut,r.Project],optional:!0}},t);i=o.modifiedData,a.push(...o.errors,...tt(i));const l=P(i.declaration);if(l){const d=Q1(l,t);a.push(...d)}else{const d=`
60
+ Alternatively you can update the entity with 'update' action. Or replace it by first removing it and then creating a new one.`,issue:null}))}y===r.DataType&&(!i.parentRelationType||!(i.parentRelationType===ft.AndDataTypeGroup||i.parentRelationType===ft.OrDataTypeGroup))&&a.push(new g({id:`${e.id}--${T.InvalidParentRelationType}`,code:T.InvalidParentRelationType,severity:E.Error,message:`The entity with id '${e.id}' and type '${e.type}', must have a 'parentRelationType' property set to either 'or-data-type-group' or 'and-data-type-group' when being added as a child to an entity of type 'data-type'.`,issue:null}))}return{errors:a,modifiedData:i}}get isGroup(){const e=[...this.andChildrenGroup||[],...this.orChildrenGroup||[]];if(e.length>1){let t=0;for(const i of e)if(i.isResolved&&(t++,t>1))return!0}return!1}get isResolved(){return[r.BuiltInBaseEntity,r.ActionDescriptor].includes(this.parent.type)||Cn(this.parent)?!0:!(!this.entity&&!this.isGroup)}validateGeneratedUpdate(e){return{errors:[],modifiedData:e}}hydrateAncestors(){const e=[],t=[],i=[];if(this.initialData.parent){const a=P(this.initialData.parent),o=this.project.get(a);if(o)this.setParent(o),e.push(o);else throw new Error(`Data type with id '${this.id}' has a parent reference '${a}' that isn't found in the project`)}else throw new Error("Data type must have a parent");if(this.initialData.entity){const a=P(this.initialData.entity),o=this.project.get(a);o&&(o.type===r.DefinitionEntity&&o.parent===this||(this.setEntity(o),e.push(o)))}return{updated:m(e),added:m(t),removed:m(i),self:this}}afterAllChildrenInitialized(){const e=[],t=[],i=[];return this.initialized=!0,{updated:m(e),added:m(t),removed:m(i),self:this}}addSelfToProject(){const e=[this],t=[],i=[];return this.parent.type===r.DataType?this.parentRelationType===ft.AndDataTypeGroup?this.parent.addToAndGroup(this):this.parentRelationType===ft.OrDataTypeGroup&&this.parent.addToOrGroup(this):this.parent.setDataType(this),e.push(this.parent),{updated:m(e),added:m(t),removed:m(i),self:this}}setParent(e){return this.parent=e,this}removeChildGroup(e){if(this.andChildrenGroup){const t=this.andChildrenGroup.findIndex(i=>i.id===e.id);t!==-1&&this.andChildrenGroup.splice(t,1)}if(this.orChildrenGroup){const t=this.orChildrenGroup.findIndex(i=>i.id===e.id);t!==-1&&this.orChildrenGroup.splice(t,1)}return this}initChildren(){var e,t;if(this.initialized)return this;if(this.initialized=!0,this.initialData.entity)if(this.initialData.entity.type===r.GenericReference){const i=this.project.findSubscribedInstanceFromReference(this.initialData.entity);this.entity=i}else this.entity=b(this.initialData.entity,this.project),((t=(e=this.initialData.entity)==null?void 0:e.parent)==null?void 0:t.id)===this.id&&this.entity.setParent(this),this.entity.type===r.DefinitionEntity&&this.entity.initChildren();return this.initialData.andChildrenGroup&&(this.andChildrenGroup=this.initialData.andChildrenGroup.map(i=>{const a=b(i,this.project);return a.setParent(this),a.initChildren(),a})),this.initialData.orChildrenGroup&&(this.orChildrenGroup=this.initialData.orChildrenGroup.map(i=>{const a=b(i,this.project);return a.setParent(this),a.initChildren(),a})),this.afterAllChildrenInitialized(),this}subscribe(){return this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}sync(e){return super.sync(e),this.options=e.options||this.options,this.parentRelationType=e.parentRelationType||this.parentRelationType,this.isList=e.isList!==void 0?e.isList:this.isList,this.inferred=e.inferred!==void 0?e.inferred:this.inferred,this.like=e.like!==void 0?e.like:this.like,this.asType=e.asType!==void 0?e.asType:this.asType,this.implementationChooseOne=e.implementationChooseOne!==void 0?e.implementationChooseOne:this.implementationChooseOne,this}async load(e=L,...t){return await ve.repository.load(this.id,...t),this}async create(e=L,...t){return await ve.repository.create(this.toShallowJSON(),...t),this}async update(e=L,...t){return await ve.repository.update(this.toShallowJSON(),...t),this}async delete(e=L,...t){return await ve.repository.delete(this.id,...t),this}remove({ignoreUpstream:e,seenEntities:t}={ignoreUpstream:!1,seenEntities:new Set}){const i=[],a=[];if(t.has(this.id))return{affected:[],removed:[]};if(t.add(this.id),a.push(this),this.unsubscribe(),this.entity&&this.entity.type===r.DefinitionEntity&&this.entity.parent===this){const{affected:o,removed:l}=this.entity.remove({ignoreUpstream:!0,seenEntities:t});i.push(...o),a.push(...l)}if(!e){this.parent.type===r.DataType&&this.parent.removeChildGroup(this);const o=this.parent;if(o.type===r.DataType){if(this.parentRelationType===ft.AndDataTypeGroup){if(Array.isArray(o.andChildrenGroup)){const l=o.andChildrenGroup.findIndex(d=>d.id===this.id);l!==-1&&o.andChildrenGroup.splice(l,1)}}else if(this.parentRelationType===ft.OrDataTypeGroup&&Array.isArray(o.orChildrenGroup)){const l=o.orChildrenGroup.findIndex(d=>d.id===this.id);l!==-1&&o.orChildrenGroup.splice(l,1)}}else this.parent.removeDataType();i.push(o)}return{affected:m(i),removed:m(a)}}restore({seenEntities:e}={seenEntities:new Set}){const t=[];if(e.has(this.id))return{affected:[],self:this};if(e.add(this.id),this.subscribe(),this.entity&&this.entity.type===r.DefinitionEntity&&this.entity.parent===this){const{affected:i}=this.entity.restore({seenEntities:e});t.push(...i)}if(this.parent.type===r.DataType){const i=this.parent;Array.isArray(i.andChildrenGroup)&&i.andChildrenGroup.push(this)}if(this.parent.type===r.DataType){const i=this.parent;this.parentRelationType===ft.AndDataTypeGroup?Array.isArray(i.andChildrenGroup)&&i.andChildrenGroup.push(this):this.parentRelationType===ft.OrDataTypeGroup&&Array.isArray(i.orChildrenGroup)&&i.orChildrenGroup.push(this)}else{const i=this.parent;i.setDataType(this),t.push(i)}return{affected:t,self:this}}toFlat(e=new Set){var i,a,o;return e.has(this.id)?[]:(e.add(this.id),[this,...((i=this.andChildrenGroup)==null?void 0:i.flatMap(l=>l.toFlat(e)))||[],...((a=this.orChildrenGroup)==null?void 0:a.flatMap(l=>l.toFlat(e)))||[],...((o=this.entity)==null?void 0:o.toFlat(e))||[]])}toFlatIds(e=new Set){var i,a,o;return e.has(this.id)?[]:(e.add(this.id),[this.id,...((i=this.andChildrenGroup)==null?void 0:i.flatMap(l=>l.toFlatIds(e)))||[],...((a=this.orChildrenGroup)==null?void 0:a.flatMap(l=>l.toFlatIds(e)))||[],...((o=this.entity)==null?void 0:o.toFlatIds(e))||[]])}toJSON(e=new Set){var t,i,a,o;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,options:this.options,isList:this.isList,asType:this.asType,like:this.like,inferred:this.inferred,parentRelationType:this.parentRelationType,implementationChooseOne:this.implementationChooseOne,andChildrenGroup:((t=this.andChildrenGroup)==null?void 0:t.map(l=>l.toJSON(e)))||null,orChildrenGroup:((i=this.orChildrenGroup)==null?void 0:i.map(l=>l.toJSON(e)))||null,entity:((a=this.entity)==null?void 0:a.parent)===this?this.entity.toJSON(e):((o=this.entity)==null?void 0:o.toReference())||null,parent:this.parent.toReference()})}toJSONClone(e=F){var i,a,o,l,d,h,y,f,v;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||at(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(a=e.seenEntities)!=null&&a.has(t)||(o=e.seenEntities)!=null&&o.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((l=e.seenEntities)==null||l.add(t),(d=e.seenEntities)==null||d.add(this.id),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,options:this.options,isList:this.isList,asType:this.asType,like:this.like,inferred:this.inferred,parentRelationType:this.parentRelationType,implementationChooseOne:this.implementationChooseOne,andChildrenGroup:((h=this.andChildrenGroup)==null?void 0:h.map(R=>R.toJSONClone({...e,newId:null})))||null,orChildrenGroup:((y=this.orChildrenGroup)==null?void 0:y.map(R=>R.toJSONClone({...e,newId:null})))||null,entity:((f=this.entity)==null?void 0:f.parent)===this?this.entity.toJSONClone({...e,newId:null}):((v=this.entity)==null?void 0:v.toReference({seenEntityMaps:e.seenEntityMaps}))||null,parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps})})}toReference(e=F){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+B.UUID.uuid()+"--ref",type:r.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=F){var i,a,o,l;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,isList:this.isList,options:this.options,asType:this.asType,parentRelationType:this.parentRelationType,like:this.like,inferred:this.inferred,implementationChooseOne:this.implementationChooseOne,andChildrenGroup:((a=this.andChildrenGroup)==null?void 0:a.map(d=>d.toReference(e)))||null,orChildrenGroup:((o=this.orChildrenGroup)==null?void 0:o.map(d=>d.toReference(e)))||null,entity:((l=this.entity)==null?void 0:l.toReference(e))||null,parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){var i,a,o;return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...((i=this.andChildrenGroup)==null?void 0:i.flatMap(l=>l.toFlatJSON(e)))||[],...((a=this.orChildrenGroup)==null?void 0:a.flatMap(l=>l.toFlatJSON(e)))||[],...((o=this.entity)==null?void 0:o.toFlatJSON(e))||[]])}toGenerationTarget(){var e;return{id:this.id,type:this.type,options:this.options,isList:this.isList,like:this.like,parentRelationType:this.parentRelationType,asType:this.asType,entity:((e=this.entity)==null?void 0:e.id)||null,parent:this.parent.id}}toFlatGenerationTarget(e=new Set){var i,a;return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...((i=this.andChildrenGroup)==null?void 0:i.flatMap(o=>o.toFlatGenerationTarget(e)))||[],...((a=this.orChildrenGroup)==null?void 0:a.flatMap(o=>o.toFlatGenerationTarget(e)))||[],...this.entity&&this.entity.type==r.DefinitionEntity&&this.entity.parent===this&&this.entity.toFlatGenerationTarget(e)||[]])}clearErrors(){var e,t,i;return this.errors=[],(e=this.andChildrenGroup)==null||e.forEach(a=>a.clearErrors()),(t=this.orChildrenGroup)==null||t.forEach(a=>a.clearErrors()),this.inferred&&((i=this.entity)==null||i.clearErrors()),this}validate(){const e=m7(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){return[...this.errors]}getShallowErrors(){return this.errors}clone(e=null,t=null,i=!0){var I,D,A;let a=st(e,this),o=e||this.parent;const l=t||Fe(Rs(this),r.DataType,a),d=l.split("-id"),h=d[d.length-1||0]||l,y={id:l,version:"1",createdAt:$().toDate(),author:"1",previousVersion:null,deleted:!1,type:r.DataType,isList:this.isList,asType:this.asType,options:this.options,parentRelationType:this.parentRelationType,like:this.like,inferred:this.inferred,implementationChooseOne:this.implementationChooseOne,andChildrenGroup:null,orChildrenGroup:null,entity:null,parent:o.toReference()},f=rt(y,a);e&&f.setParent(e),i&&f.subscribe(),f.initChildren();const v=(I=this.andChildrenGroup)==null?void 0:I.map((M,q)=>M.clone(f,h+"-and-group-data-type-"+q+"-id",i)),R=(D=this.orChildrenGroup)==null?void 0:D.map((M,q)=>M.clone(f,h+"-or-group-data-type-"+q+"-id",i));if(f.andChildrenGroup=v||null,f.orChildrenGroup=R||null,this.entity&&this.entity.type===r.DefinitionEntity&&((A=this.entity)==null?void 0:A.parent)===this){const M=this.entity.clone(f,B.UUID.uuid(),i);f.setEntity(M)}else this.entity&&f.setEntity(this.entity);return f}merge(e){const t=[],i=[],a=[];if(this.asType!==(e==null?void 0:e.asType)&&(this.sync({asType:e==null?void 0:e.asType}),t.push(this)),this.isList!==!(e!=null&&e.isList)&&(this.sync({isList:e==null?void 0:e.isList}),t.push(this)),this.like!==(e==null?void 0:e.like)&&(this.sync({like:e==null?void 0:e.like}),t.push(this)),e!=null&&e.inferred){if(e.entity&&e.entity.type===r.DefinitionEntity&&e.entity.parent===e){const o=e.entity.clone(this,B.UUID.uuid(),!0);this.setEntity(o),i.push(o)}else e.entity&&(this.setEntity(e.entity),t.push(this));this.inferred||(this.sync({inferred:!0}),t.push(this))}else if(this.inferred){if(this.sync({inferred:!1}),t.push(this),this.entity&&this.entity.type===r.DefinitionEntity&&this.entity.parent===this){const{affected:o,removed:l}=this.entity.remove({ignoreUpstream:!0,seenEntities:new Set});a.push(...l),o.push(...o)}e.entity!==this.entity&&(this.setEntity(e.entity),t.push(this))}else e.entity!==this.entity&&(this.setEntity(e.entity),t.push(this));return{updated:m(t),added:m(i),removed:m(a),self:this}}addToAndGroup(e){return this.andChildrenGroup||(this.andChildrenGroup=[]),this.andChildrenGroup.includes(e)||this.andChildrenGroup.push(e),this}addToOrGroup(e){return this.orChildrenGroup||(this.orChildrenGroup=[]),this.orChildrenGroup.includes(e)||this.orChildrenGroup.push(e),this}setEntity(e){return this.entity=e,this}isObject(){return!!this.entity&&(this.entity.type===r.DefinitionEntity||this.entity.name===V.KeyValue)}hasStrictObjectStructure(){var e;return this.isObject()&&((e=this.entity)==null?void 0:e.type)===r.DefinitionEntity}inferFromInputs(e){var t;if(!this.inferred)return this;if(!this.entity&&e.length){const i={id:B.UUID.uuid(),type:r.DefinitionEntity,version:"1",createdAt:$().toDate(),author:"1",previousVersion:null,deleted:!1,name:C(this.parent,this.project)+" data type definition",description:((t=this.parent)==null?void 0:t.description)||null,static:!0,abstract:!1,properties:[],methods:[],extends:[],implements:[],abstractMethods:[],x:0,y:0,parent:this.toReference()},a=b(i,this.project);a.setParent(this),a.initChildren(),a.sync(i),this.setEntity(a)}return this.entity&&this.entity.type===r.DefinitionEntity&&this.entity.parent!==this&&this.entity.setParent(this),this.entity&&this.entity.inferFromInputs(e),this.like||this.sync({like:!0}),this}};u(ve,"repository",{create:async(e,...t)=>e,update:async(e,...t)=>e,delete:async(e,...t)=>{},load:async(e,...t)=>null}),u(ve,"type",r.DataType),u(ve,"USER_MANAGED_PARENT_TYPES",[r.Property,r.ArgumentDeclaration,r.ReturnDeclaration,r.VariableDeclaration,r.ValueDescriptor,r.InputMap,r.OutputMap,r.DataType]),u(ve,"PARENT_TYPES",[...ve.USER_MANAGED_PARENT_TYPES]),u(ve,"MUTABLE_BASE_PROPERTIES",["isList","asType","options","parentRelationType","like"]),u(ve,"INMUTABLE_BASE_PROPERTIES",["id","version","type"]),u(ve,"BASE_PROPERTIES",[...ve.MUTABLE_BASE_PROPERTIES,...ve.INMUTABLE_BASE_PROPERTIES]),u(ve,"MUTABLE_META_PROPERTIES",[...ve.MUTABLE_BASE_PROPERTIES,"inferred"]),u(ve,"INMUTABLE_META_PROPERTIES",[...ve.INMUTABLE_BASE_PROPERTIES]),u(ve,"META_PROPERTIES",[...ve.MUTABLE_META_PROPERTIES,...ve.INMUTABLE_META_PROPERTIES]),u(ve,"MUTABLE_UPSTREAM_PROPERTIES",["entity","parent"]),u(ve,"INMUTABLE_UPSTREAM_PROPERTIES",[]),u(ve,"UPSTREAM_PROPERTIES",[...ve.MUTABLE_UPSTREAM_PROPERTIES,...ve.INMUTABLE_UPSTREAM_PROPERTIES]),u(ve,"MUTABLE_DOWNSTREAM_PROPERTIES",[]),u(ve,"INMUTABLE_DOWNSTREAM_PROPERTIES",["andChildrenGroup","orChildrenGroup"]),u(ve,"DOWNSTREAM_PROPERTIES",[...ve.MUTABLE_DOWNSTREAM_PROPERTIES,...ve.INMUTABLE_DOWNSTREAM_PROPERTIES]),u(ve,"PROPERTIES",[...ve.META_PROPERTIES,...ve.UPSTREAM_PROPERTIES,...ve.DOWNSTREAM_PROPERTIES]);let ca=ve;function v7(n){var l;const s=_6(),e=n.toJSON();s.safeParse(e).success;const i=E7(n),a=ln(n),o=[...i,...a];if(n.id==="exec-sequentially-operation-call-id"){const d=le({id:`${n.id}--${U.PropertyImplementsNonAbstact}`,message:`Property "${C(n,n.project)}" with id "${n.id}" implements a non-abstract property "${C(n,n.project)}" with id "${n.id}".`,issue:null,severity:E.Error,code:U.PropertyImplementsNonAbstact,entity:n});o.push(d.error)}return n.outputs.forEach(d=>d.validate()),(l=n.error)==null||l.validate(),je(n.errors,o)}function E7(n){const s=[];return n.inputs.forEach(e=>{e.validate()}),je(n.errors,s)}const Ee=class Ee extends Ke{constructor(e,t){super(e);u(this,"initialData");u(this,"id");u(this,"x");u(this,"y");u(this,"type",r.Operation);u(this,"declaration");u(this,"inputs",[]);u(this,"outputs",[]);u(this,"process",null);u(this,"successCalls",[]);u(this,"errorCalls",[]);u(this,"error",null);u(this,"calledBySuccess",[]);u(this,"calledByError",[]);u(this,"calledByEntry",[]);u(this,"parent");u(this,"errors",[]);u(this,"project");u(this,"initialized",!1);this.initialData=e,this.project=t,this.id=e.id,this.x=e.x,this.y=e.y}static fromGenerationTarget(e,t){let i=t;if(e.parent){const v=P(e.parent);i=t.get(v)}const a=P(e.declaration),o=t.get(a),l=e.calledByEntry.map(v=>{const R=P(v);return t.get(R)}),d=e.calledBySuccess.map(v=>{const R=P(v);return t.get(R)}),h=e.calledByError.map(v=>{const R=P(v);return t.get(R)}),y={id:e.id,version:"1",createdAt:$().toDate(),author:"1",previousVersion:null,deleted:!1,type:r.Operation,declaration:o,calledByEntry:l,calledBySuccess:d,calledByError:h,errorCalls:[],successCalls:[],inputs:[],outputs:[],process:null,error:null,x:0,y:0,parent:i},f=b(y,t);return f.setParent(i),f.initChildren(),f}static validateGenerationTarget(e,t){let i=JSON.parse(JSON.stringify(e));const a=[],o=mt(i,{parent:{list:!1,types:[...ut,r.Project],optional:!0}},t);i=o.modifiedData,a.push(...o.errors,...tt(i));const l=P(i.declaration);if(l){const d=Q1(l,t);a.push(...d)}else{const d=`
61
61
  All built-in 'action-descriptor' entity ids are:
62
62
  - ${t.operationDeclarations.map(h=>`${h.id} (${C(h,t)})`).join(`
63
63
  - `)}.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elyx-code/project-logic-tree",
3
- "version": "0.0.6149",
3
+ "version": "0.0.6150",
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",