@elyx-code/project-logic-tree 0.0.6147 → 0.0.6148

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
@@ -29121,7 +29121,12 @@ ${Rl}`,
29121
29121
  const a = D(
29122
29122
  this.initialData.parent
29123
29123
  ), o = this.project.get(a);
29124
- o && (this.setParent(o), e.push(o));
29124
+ if (o)
29125
+ this.setParent(o), e.push(o);
29126
+ else
29127
+ throw new Error(
29128
+ `Property with id '${this.id}' has a parent reference which is missing in the project`
29129
+ );
29125
29130
  } else
29126
29131
  throw new Error(
29127
29132
  `Property with id '${this.id}' is missing a parent reference`
@@ -42,7 +42,7 @@ Please provide a unique 'name' string.`,severity:E.Error,code:B.NameNotUniqueInS
42
42
  Please provide a unique 'name' string.`,severity:E.Error,code:B.NameNotUniqueInScope,issue:null}))}}return e}function d7(r,s){switch(r.type){case n.DefinitionEntity:return Al(r,s);case n.FunctionDeclaration:return lp(r,s);case n.VariableDeclaration:return dp(r,s);case n.Property:return up(r,s);case n.ArgumentDeclaration:return cp(r,s);case n.ReturnDeclaration:return pp(r,s);default:return[]}}function Fe(r,s,e){const i=`${bl(r)}-${s}-id`;return e.instances[i]?M.UUID.uuid():i}function hp(r,s){let e="",t=null;if(r.parent){const a=s.get(r.parent);a&&(t=a)}let i="";return t&&(i=`${bl(C(t,s))}-`),e=`${i}${bl(C(r,s))}-id`,s.instances[e]?M.UUID.uuid():e}function at(r,s,e="uuid"){return e==="semantic"?Fe(C(r,s),r.type,s):M.UUID.uuid()}function u7(r){var o;const s=wk(),e=r.toJSON();s.safeParse(e).success;const i=c7(r);(o=r.dataType)==null||o.validate();const a=[...i];if(r.id==="80c86e1b-caca-4ba5-9b1f-38f72d10e4a3"){const l=oe({id:`${r.id}--${U.PropertyImplementsNonAbstact}`,message:`Property "${C(r,r.project)}" with id "${r.id}" implements a non-abstract property "${C(r,r.project)}" with id "${r.id}".`,issue:null,severity:E.Error,code:U.PropertyImplementsNonAbstact,entity:r});a.push(l.error)}return a}function c7(r){const s=[];if(!r.implements)return s;const e=r.implements;if(!e.abstract){const i=oe({id:`${r.id}--${U.PropertyImplementsNonAbstact}`,message:`Property "${C(r,r.project)}" with id "${r.id}" implements a non-abstract property "${C(e,r.project)}" with id "${e.id}".`,issue:null,severity:E.Error,code:U.PropertyImplementsNonAbstact,entity:r});s.push(i.error)}if(r.static&&!e.static){const i=oe({id:`${r.id}--${U.NonStaticPropertyImplementsStatic}`,message:`Static property "${C(r,r.project)}" with id "${r.id}" implements a non-static property "${C(e,r.project)}" with id "${e.id}".`,issue:null,severity:E.Error,code:U.NonStaticPropertyImplementsStatic,entity:r});s.push(i.error)}if(!r.static&&e.static){const i=oe({id:`${r.id}--${U.StaticPropertyImplementsNonStatic}`,message:`Non-static property "${C(r,r.project)}" with id "${r.id}" implements a static property "${C(e,r.project)}" with id "${e.id}".`,issue:null,severity:E.Error,code:U.StaticPropertyImplementsNonStatic,entity:r});s.push(i.error)}if(!yn(r.dataType,e.dataType)){const i=oe({id:`${r.id}--${U.PropertyImplementsIncompatibleType}`,message:`Property "${C(r,r.project)}" with id "${r.id}" implements a property "${C(e,r.project)}" with id "${e.id}" that has an incompatible data type.`,issue:null,severity:E.Error,code:U.PropertyImplementsIncompatibleType,entity:r});s.push(i.error)}return je(r.errors,s)}function p7(r,s){const e=[];if(r.parent){const i=s.get(r.parent);if(!i)e.push(new g({id:`${r.id}--${r.parent}--${T.ReferencedEntityNotFound}`,code:T.ReferencedEntityNotFound,severity:E.Error,message:`Entity of type "${r.type}" with id "${r.id}", is referencing an entity with id "${r.parent}" that isn't yet found in the project. Perhaps it should be created first. Or perhaps the ID is incorrect.`,issue:null}));else{const a=Cr(i);if(a){const o=i!==a?`The entity of type '${r.type}' with id '${r.id}' have 'parent' with id '${r.parent}' because the entity belongs to a built-in '${a.type}' entity with id '${a.id}' (${C(a,i.project)}) higher up in the tree.`:`The entity of type '${r.type}' with id '${r.id}' have 'parent' with id '${r.parent}' because it is a built-in entity of type ${a.type}.`;e.push(new g({id:`${r.id}--${T.InvalidBuiltInEntityReference}`,code:T.InvalidBuiltInEntityReference,severity:E.Error,message:o,issue:null}))}else if(![n.DefinitionEntity].includes(i.type))e.push(new g({id:`${r.id}--${r.parent}--${T.InvalidParentReference}`,code:T.InvalidParentReference,severity:E.Error,message:`Entity of type "${r.type}" with id "${r.id}", has a parent reference that isn't pointing to an entity of type 'definition-entity'.`,issue:null}));else{const l=Vr(i).filter(d=>!d.interactive);if(l.length){let d=l.length>1?`The entity of type '${r.type}' with id '${r.id}' can't be added to the 'parent' entity with id '${i.id}' because it extends or implements multiple '${n.BuiltInBaseEntity}' entities that are non-interactive ("${z(l.map(h=>C(h,h.project)),'", "','" and "')}").`:`The entity of type '${r.type}' with id '${r.id}' can't be added to the 'parent' entity with id '${i.id}' because it extends or implements a '${n.BuiltInBaseEntity}' entity that is non-interactive ("${C(l[0],l[0].project)}").`;d+=`
43
43
  ${Sr}`,e.push(new g({id:`${r.id}--${T.NonInteractiveEntityReferenced}`,code:T.NonInteractiveEntityReferenced,severity:E.Error,message:d,issue:null}))}else if(r.implements){const d=s.get(r.implements);if(r.id===r.implements)return e.push(new g({id:`${r.id}--${r.implements}--${T.SelfReference}`,code:T.SelfReference,severity:E.Error,message:`Entity of type "${r.type}" with id "${r.id}", has a reference to itself at 'implements'. This is not allowed. Change the reference string or the 'entityId' property of the reference object.`,issue:null})),e;if(!d)e.push(new g({id:`${r.id}--${r.implements}--${T.ReferencedEntityNotFound}`,code:T.ReferencedEntityNotFound,severity:E.Error,message:`Entity of type "${r.type}" with id "${r.id}", is referencing an entity with id "${r.implements}" that isn't yet found in the project. Perhaps it should be created first. Or perhaps the ID is incorrect.`,issue:null}));else{const h=i.properties.find(y=>{var f;return((f=y.implements)==null?void 0:f.id)===r.implements});h?e.push(new g({id:`${r.id}--${B.PropertyOverwrite}`,code:B.PropertyOverwrite,severity:E.Error,message:`The property with id "${r.id}" is trying to implement the property with id "${r.implements}", but the parent entity already has a property with id '${h.id}' that implements the same base property.`,issue:null})):[n.Property].includes(d.type)?d.abstract||e.push(new g({id:`${r.id}--${r.implements}--${T.InvalidImplementsReference}`,code:T.InvalidImplementsReference,severity:E.Error,message:`Entity of type "${r.type}" with id "${r.id}", has an 'implements' reference that isn't pointing to an abstract entity.`,issue:null})):e.push(new g({id:`${r.id}--${r.implements}--${T.InvalidImplementsReference}`,code:T.InvalidImplementsReference,severity:E.Error,message:`Entity of type "${r.type}" with id "${r.id}", has an 'implements' reference that isn't pointing to an entity of type 'property'.`,issue:null}))}}}}}const t=mt(r,{},s);return e.push(...t.errors),e}class Ke{constructor(s){u(this,"version");u(this,"previousVersion",null);u(this,"createdAt");u(this,"deleted",!1);u(this,"author");this.version=s.version,this.previousVersion=s.previousVersion,this.createdAt=$(s.createdAt).toDate(),this.deleted=s.deleted,this.author=s.author}sync(s){this.version=s.version||this.version,this.previousVersion=s.previousVersion||this.previousVersion,this.createdAt=s.createdAt?$(s.createdAt).toDate():this.createdAt,this.deleted=s.deleted!==void 0?s.deleted:this.deleted,this.author=s.author||this.author}}const me=class me extends Ke{constructor(e,t){super(e);u(this,"initialData");u(this,"id");u(this,"name");u(this,"description",null);u(this,"private");u(this,"abstract");u(this,"index");u(this,"static");u(this,"required");u(this,"constant",!1);u(this,"type",n.Property);u(this,"hidden",!1);u(this,"defaultValue",null);u(this,"dataType",null);u(this,"implements",null);u(this,"project");u(this,"errors",[]);u(this,"parent");u(this,"initialized",!1);u(this,"suggestion",!1);this.initialData=e,this.project=t,this.id=e.id,this.name=e.name,this.description=e.description,this.private=e.private,this.abstract=e.abstract,this.index=e.index,this.static=e.static,this.required=e.required||!1,this.hidden=e.hidden||!1,this.constant=e.constant||!1}static fromGenerationTarget(e,t){const i=P(e.parent),a=t.get(i);let o=null;if(e.implements){const h=P(e.implements);o=t.get(h)}const l={id:e.id,version:"1",createdAt:$().toDate(),author:"1",previousVersion:null,deleted:!1,name:e.name,type:n.Property,index:a.properties.length,private:e.private||!1,abstract:e.abstract||!1,static:e.static||!1,required:e.required||!1,constant:e.constant||!1,hidden:!1,description:e.description,defaultValue:null,implements:o,dataType:null,parent:a},d=b(l,t);return d.setParent(a),d.initChildren(),d}static validateGenerationTarget(e,t){let i=JSON.parse(JSON.stringify(e));const a=[],o=p7(i,t),l=up(i,t);return a.push(...o,...l,...tt(i)),{errors:a,modifiedData:i}}get isExtendedProperty(){const e=this.parent.allBasePropertiesFromExtendedAndImplementedEntities.find(t=>t.name===this.name);return!!e&&e.id!==this.id&&!e.abstract}validateGeneratedUpdate(e){const t=[];return e.parent&&t.push(new g({id:`${this.id}--${T.InvalidParentUpdate}`,code:T.InvalidParentUpdate,severity:E.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.
44
44
  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})),(e.readsValue||e.writesValue)&&t.push(new g({id:`${this.id}--${B.InvalidObjectStructure}`,code:B.InvalidObjectStructure,severity:E.Error,message:`Entity of type '${this.type}' with id '${this.id}' is not a value reading or writing entity.
45
- ${Ol}`,issue:null})),{errors:t,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))}else throw new Error(`Property with id '${this.id}' is missing a parent reference`);if(this.initialData.implements){const a=P(this.initialData.implements),o=this.project.get(a);o&&(this.setImplements(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.addProperty(this),e.push(this.parent),{updated:m(e),added:m(t),removed:m(i),self:this}}setParent(e){return this.parent=e,this}setImplements(e){return this.implements=e,this}initChildren(){if(this.initialized)return this;if(this.initialized=!0,this.initialData.defaultValue&&(this.defaultValue=b(this.initialData.defaultValue,this.project),this.defaultValue.setParent(this),this.defaultValue.initChildren()),this.initialData.dataType){const e=b(this.initialData.dataType,this.project);e.setParent(this),e.initChildren(),this.dataType=e}if(this.initialData.implements){const e=b(this.initialData.implements,this.project);this.implements=e}return this.afterAllChildrenInitialized(),this}subscribe(){return this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}sync(e){return super.sync(e),this.name=e.name||this.name,this.description=e.description||this.description,this.abstract=e.abstract!==void 0?e.abstract:this.abstract,this.private=e.private!==void 0?e.private:this.private,this.index=e.index||(e.index!==0?this.index:0),this.static=e.static!==void 0?e.static:this.static,this.hidden=e.hidden!==void 0?e.hidden:this.hidden,this.constant=e.constant!==void 0?e.constant:this.constant,this.required=e.required!==void 0?e.required:this.required,this}async load(e=L,...t){return await me.repository.load(this.id,...t),this}async create(e=L,...t){return await me.repository.create(this.toShallowJSON(),...t),this}async update(e=L,...t){return await me.repository.update(this.toShallowJSON(),...t),this}async delete(e=L,...t){return await me.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.defaultValue){const{affected:o,removed:l}=this.defaultValue.remove({ignoreUpstream:!0,seenEntities:t});i.push(...o),a.push(...l)}if(this.dataType){const{affected:o,removed:l}=this.dataType.remove({ignoreUpstream:!0,seenEntities:t});i.push(...o),a.push(...l)}return e||this.parent.type===n.DefinitionEntity&&(this.parent.removeProperty(this),i.push(this.parent)),{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.defaultValue){const{affected:i}=this.defaultValue.restore({seenEntities:e});t.push(...i)}if(this.dataType){const{affected:i}=this.dataType.restore({seenEntities:e});t.push(...i)}return this.parent.type===n.DefinitionEntity&&(this.parent.addProperty(this),t.push(this.parent)),{affected:t,self:this}}toFlat(e=new Set){var i,a;return e.has(this.id)?[]:(e.add(this.id),[this,...((i=this.defaultValue)==null?void 0:i.toFlat(e))||[],...((a=this.dataType)==null?void 0:a.toFlat(e))||[]])}toFlatIds(e=new Set){var i,a;return e.has(this.id)?[]:(e.add(this.id),[this.id,...((i=this.defaultValue)==null?void 0:i.toFlatIds(e))||[],...((a=this.dataType)==null?void 0:a.toFlatIds(e))||[]])}toJSON(e=new Set){var t,i,a;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,index:this.index,private:this.private,required:this.required,static:this.static,constant:this.constant,abstract:this.abstract,hidden:this.hidden,defaultValue:((t=this.defaultValue)==null?void 0:t.toJSON(e))||null,dataType:((i=this.dataType)==null?void 0:i.toJSON(e))||null,implements:((a=this.implements)==null?void 0:a.toJSON(e))||null,parent:this.parent.toReference()})}toJSONClone(e=F){var i,a,o,l,d,h,y;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:"1",createdAt:$().toDate(),author:"1",previousVersion:null,deleted:!1,type:this.type,name:this.name,description:this.description,index:this.index,private:this.private,required:this.required,static:this.static,constant:this.constant,abstract:this.abstract,hidden:this.hidden,defaultValue:((h=this.defaultValue)==null?void 0:h.toJSONClone({...e,newId:null}))||null,dataType:((y=this.dataType)==null?void 0:y.toJSONClone({...e,newId:null}))||null,implements:(()=>{var f;return this.implements&&this.project.getBuiltIn(this.implements.id)?this.implements.toJSON():((f=this.implements)==null?void 0:f.toJSONClone({...e,newId:null}))||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+"--"+M.UUID.uuid()+"--ref",type:n.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,name:this.name,description:this.description,type:this.type,index:this.index,private:this.private,required:this.required,abstract:this.abstract,static:this.static,constant:this.constant,hidden:this.hidden,defaultValue:((a=this.defaultValue)==null?void 0:a.toReference(e))||null,dataType:((o=this.dataType)==null?void 0:o.toReference(e))||null,implements:((l=this.implements)==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.defaultValue)==null?void 0:i.toFlatJSON(e))||[],...((a=this.dataType)==null?void 0:a.toFlatJSON(e))||[],...((o=this.implements)==null?void 0:o.toFlatJSON(e))||[]])}toGenerationTarget(){var e;return{id:this.id,name:this.name,description:this.description,type:this.type,private:this.private,required:this.required,abstract:this.abstract,static:this.static,implements:((e=this.implements)==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.defaultValue)==null?void 0:i.toFlatGenerationTarget(e))||[],...((a=this.dataType)==null?void 0:a.toFlatGenerationTarget(e))||[]])}clearErrors(){var e,t;return this.errors=[],(e=this.defaultValue)==null||e.clearErrors(),(t=this.dataType)==null||t.clearErrors(),this}validate(){return this.errors=u7(this),this.errors.length,{success:!0,error:null,data:null}}getErrors(){var t,i;return[...this.errors,...((t=this.defaultValue)==null?void 0:t.getErrors())||[],...((i=this.dataType)==null?void 0:i.getErrors())||[]]}getShallowErrors(){return this.errors}clone(e=null,t=null,i=!0){var I,D;let a=st(e,this);const o=t||Fe(C(this,this.project),n.Property,a),l=o.split("-id"),d=l[l.length-1||0]||o;let h=e||this.parent;const y={hidden:!1,id:o,version:M.UUID.uuid(),createdAt:this.createdAt,author:this.author,previousVersion:this.version,deleted:this.deleted,type:this.type,name:this.name,description:this.description,index:this.index,private:this.private,constant:this.constant,required:this.required,abstract:this.abstract,static:this.static,defaultValue:null,dataType:null,implements:this.implements,parent:h},f=nt(y,a);i&&f.subscribe(),f.setParent(h),f.initChildren();const v=((I=this.dataType)==null?void 0:I.clone(f,M.UUID.uuid(),i))||null;v&&f.setDataType(v);const R=(D=this.defaultValue)==null?void 0:D.clone(f,d+"-default-value-id",i);return f.defaultValue=R||null,this.implements&&(f.implements=this.implements),f.addSelfToProject(),f}setDataType(e){return this.dataType=e,this}removeDataType(){return this.dataType=null,this}getDataType(){return this.dataType}getDefaultValue(){return this.defaultValue}setDefaultValue(e){return this.defaultValue=e,this}};u(me,"repository",{create:async(e,...t)=>e,update:async(e,...t)=>e,delete:async(e,...t)=>{},load:async(e,...t)=>null}),u(me,"type",n.Property),u(me,"USER_MANAGED_PARENT_TYPES",[n.DefinitionEntity]),u(me,"PARENT_TYPES",[...me.USER_MANAGED_PARENT_TYPES,n.PrimitiveEntity,n.BuiltInBaseEntity]),u(me,"MUTABLE_BASE_PROPERTIES",["name","description","private","abstract","static","required","constant"]),u(me,"INMUTABLE_BASE_PROPERTIES",["id","type","version"]),u(me,"BASE_PROPERTIES",[...me.MUTABLE_BASE_PROPERTIES,...me.INMUTABLE_BASE_PROPERTIES]),u(me,"MUTABLE_META_PROPERTIES",[...me.MUTABLE_BASE_PROPERTIES,"index"]),u(me,"INMUTABLE_META_PROPERTIES",[...me.INMUTABLE_BASE_PROPERTIES]),u(me,"META_PROPERTIES",[...me.MUTABLE_META_PROPERTIES,...me.INMUTABLE_META_PROPERTIES]),u(me,"MUTABLE_UPSTREAM_PROPERTIES",[]),u(me,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","implements"]),u(me,"UPSTREAM_PROPERTIES",[...me.MUTABLE_UPSTREAM_PROPERTIES,...me.INMUTABLE_UPSTREAM_PROPERTIES]),u(me,"MUTABLE_DOWNSTREAM_PROPERTIES",["dataType"]),u(me,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),u(me,"DOWNSTREAM_PROPERTIES",[...me.MUTABLE_DOWNSTREAM_PROPERTIES,...me.INMUTABLE_DOWNSTREAM_PROPERTIES]),u(me,"PROPERTIES",[...me.META_PROPERTIES,...me.UPSTREAM_PROPERTIES,...me.DOWNSTREAM_PROPERTIES]);let oi=me;function h7(r){const s=Y3(),e=r.toJSON();s.safeParse(e).success;const i=y7(r),a=f7(r),o=Kt(r);r.inputs.forEach(d=>d.validate()),o.forEach(d=>d.validate());const l=[...i,...a];if(r.id==="getCompanyByIdEndpointReachedEntityEvent"){const d=oe({id:`${r.id}--${U.PropertyImplementsNonAbstact}`,message:`Property "${C(r,r.project)}" with id "${r.id}" implements a non-abstract property "${C(r,r.project)}" with id "${r.id}".`,issue:null,severity:E.Error,code:U.PropertyImplementsNonAbstact,entity:r});l.push(d.error)}return je(r.errors,l)}function y7(r){const s=[];if(!r.calls.length){const e=oe({id:`${r.id}--${U.ScopeWithoutLogic}`,message:`Action "${C(r,r.project)}" with id "${r.id}" does not have any logic defined. So it doesn't do anything.`,issue:null,severity:E.Warning,code:U.ScopeWithoutLogic,entity:r});s.push(e.error)}return je(r.errors,s)}function f7(r){const s=[];return r.implements,je(r.errors,s)}const Te=class Te extends Ke{constructor(e,t){super(e);u(this,"initialData");u(this,"id");u(this,"name");u(this,"description",null);u(this,"x");u(this,"y");u(this,"collapsed");u(this,"private");u(this,"index",null);u(this,"type",n.FunctionDeclaration);u(this,"implements",null);u(this,"inputs",[]);u(this,"returnStatements",[]);u(this,"calls",[]);u(this,"parent");u(this,"detachedChildren",[]);u(this,"errors",[]);u(this,"project");u(this,"initialized",!1);u(this,"suggestion",!1);this.initialData=e,this.project=t,this.id=e.id,this.name=e.name,this.description=e.description,this.private=e.private,this.collapsed=e.collapsed,this.x=e.x,this.y=e.y,this.index=e.index}static fromGenerationTarget(e,t){let i=t;if(e.parent){const d=P(e.parent);i=t.get(d)}let a=null;if(e.implements){const d=P(e.implements);a=t.get(d)}const o={id:e.id,version:"1",createdAt:$().toDate(),author:"1",previousVersion:null,deleted:!1,name:e.name,type:n.FunctionDeclaration,index:i.type===n.DefinitionEntity?i.methods.length:null,description:e.description,collapsed:!1,private:!1,returnStatements:[],calls:[],inputs:[],implements:a,x:0,y:0,parent:i},l=b(o,t);return l.setParent(i),l.initChildren(),l}static validateGenerationTarget(e,t){var f;let i=JSON.parse(JSON.stringify(e));const a=[],o=mt(i,{parent:{list:!1,types:[n.Project,n.InstalledProject,n.DefinitionEntity,n.Loop],optional:!0},implements:{list:!1,types:[n.ActionDescriptor],optional:!0}},t);i=o.modifiedData;const l=lp(i,t),d=i.parent?t.get(i.parent):null;if(d&&d.type===n.DefinitionEntity){const v=d,I=Vr(v).filter(D=>!D.interactive);if(I.length){let D=I.length>1?`The entity of type '${e.type}' with id '${e.id}' can't be added to the 'parent' entity with id '${v.id}' because it extends or implements multiple '${n.BuiltInBaseEntity}' entities that are non-interactive ("${z(I.map(A=>C(A,A.project)),'", "','" and "')}").`:`The entity of type '${e.type}' with id '${e.id}' can't be added to the 'parent' entity with id '${v.id}' because it extends or implements a '${n.BuiltInBaseEntity}' entity that is non-interactive ("${C(I[0],I[0].project)}").`;D+=`
45
+ ${Ol}`,issue:null})),{errors:t,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(`Property with id '${this.id}' has a parent reference which is missing in the project`)}else throw new Error(`Property with id '${this.id}' is missing a parent reference`);if(this.initialData.implements){const a=P(this.initialData.implements),o=this.project.get(a);o&&(this.setImplements(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.addProperty(this),e.push(this.parent),{updated:m(e),added:m(t),removed:m(i),self:this}}setParent(e){return this.parent=e,this}setImplements(e){return this.implements=e,this}initChildren(){if(this.initialized)return this;if(this.initialized=!0,this.initialData.defaultValue&&(this.defaultValue=b(this.initialData.defaultValue,this.project),this.defaultValue.setParent(this),this.defaultValue.initChildren()),this.initialData.dataType){const e=b(this.initialData.dataType,this.project);e.setParent(this),e.initChildren(),this.dataType=e}if(this.initialData.implements){const e=b(this.initialData.implements,this.project);this.implements=e}return this.afterAllChildrenInitialized(),this}subscribe(){return this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}sync(e){return super.sync(e),this.name=e.name||this.name,this.description=e.description||this.description,this.abstract=e.abstract!==void 0?e.abstract:this.abstract,this.private=e.private!==void 0?e.private:this.private,this.index=e.index||(e.index!==0?this.index:0),this.static=e.static!==void 0?e.static:this.static,this.hidden=e.hidden!==void 0?e.hidden:this.hidden,this.constant=e.constant!==void 0?e.constant:this.constant,this.required=e.required!==void 0?e.required:this.required,this}async load(e=L,...t){return await me.repository.load(this.id,...t),this}async create(e=L,...t){return await me.repository.create(this.toShallowJSON(),...t),this}async update(e=L,...t){return await me.repository.update(this.toShallowJSON(),...t),this}async delete(e=L,...t){return await me.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.defaultValue){const{affected:o,removed:l}=this.defaultValue.remove({ignoreUpstream:!0,seenEntities:t});i.push(...o),a.push(...l)}if(this.dataType){const{affected:o,removed:l}=this.dataType.remove({ignoreUpstream:!0,seenEntities:t});i.push(...o),a.push(...l)}return e||this.parent.type===n.DefinitionEntity&&(this.parent.removeProperty(this),i.push(this.parent)),{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.defaultValue){const{affected:i}=this.defaultValue.restore({seenEntities:e});t.push(...i)}if(this.dataType){const{affected:i}=this.dataType.restore({seenEntities:e});t.push(...i)}return this.parent.type===n.DefinitionEntity&&(this.parent.addProperty(this),t.push(this.parent)),{affected:t,self:this}}toFlat(e=new Set){var i,a;return e.has(this.id)?[]:(e.add(this.id),[this,...((i=this.defaultValue)==null?void 0:i.toFlat(e))||[],...((a=this.dataType)==null?void 0:a.toFlat(e))||[]])}toFlatIds(e=new Set){var i,a;return e.has(this.id)?[]:(e.add(this.id),[this.id,...((i=this.defaultValue)==null?void 0:i.toFlatIds(e))||[],...((a=this.dataType)==null?void 0:a.toFlatIds(e))||[]])}toJSON(e=new Set){var t,i,a;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,index:this.index,private:this.private,required:this.required,static:this.static,constant:this.constant,abstract:this.abstract,hidden:this.hidden,defaultValue:((t=this.defaultValue)==null?void 0:t.toJSON(e))||null,dataType:((i=this.dataType)==null?void 0:i.toJSON(e))||null,implements:((a=this.implements)==null?void 0:a.toJSON(e))||null,parent:this.parent.toReference()})}toJSONClone(e=F){var i,a,o,l,d,h,y;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:"1",createdAt:$().toDate(),author:"1",previousVersion:null,deleted:!1,type:this.type,name:this.name,description:this.description,index:this.index,private:this.private,required:this.required,static:this.static,constant:this.constant,abstract:this.abstract,hidden:this.hidden,defaultValue:((h=this.defaultValue)==null?void 0:h.toJSONClone({...e,newId:null}))||null,dataType:((y=this.dataType)==null?void 0:y.toJSONClone({...e,newId:null}))||null,implements:(()=>{var f;return this.implements&&this.project.getBuiltIn(this.implements.id)?this.implements.toJSON():((f=this.implements)==null?void 0:f.toJSONClone({...e,newId:null}))||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+"--"+M.UUID.uuid()+"--ref",type:n.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,name:this.name,description:this.description,type:this.type,index:this.index,private:this.private,required:this.required,abstract:this.abstract,static:this.static,constant:this.constant,hidden:this.hidden,defaultValue:((a=this.defaultValue)==null?void 0:a.toReference(e))||null,dataType:((o=this.dataType)==null?void 0:o.toReference(e))||null,implements:((l=this.implements)==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.defaultValue)==null?void 0:i.toFlatJSON(e))||[],...((a=this.dataType)==null?void 0:a.toFlatJSON(e))||[],...((o=this.implements)==null?void 0:o.toFlatJSON(e))||[]])}toGenerationTarget(){var e;return{id:this.id,name:this.name,description:this.description,type:this.type,private:this.private,required:this.required,abstract:this.abstract,static:this.static,implements:((e=this.implements)==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.defaultValue)==null?void 0:i.toFlatGenerationTarget(e))||[],...((a=this.dataType)==null?void 0:a.toFlatGenerationTarget(e))||[]])}clearErrors(){var e,t;return this.errors=[],(e=this.defaultValue)==null||e.clearErrors(),(t=this.dataType)==null||t.clearErrors(),this}validate(){return this.errors=u7(this),this.errors.length,{success:!0,error:null,data:null}}getErrors(){var t,i;return[...this.errors,...((t=this.defaultValue)==null?void 0:t.getErrors())||[],...((i=this.dataType)==null?void 0:i.getErrors())||[]]}getShallowErrors(){return this.errors}clone(e=null,t=null,i=!0){var I,D;let a=st(e,this);const o=t||Fe(C(this,this.project),n.Property,a),l=o.split("-id"),d=l[l.length-1||0]||o;let h=e||this.parent;const y={hidden:!1,id:o,version:M.UUID.uuid(),createdAt:this.createdAt,author:this.author,previousVersion:this.version,deleted:this.deleted,type:this.type,name:this.name,description:this.description,index:this.index,private:this.private,constant:this.constant,required:this.required,abstract:this.abstract,static:this.static,defaultValue:null,dataType:null,implements:this.implements,parent:h},f=nt(y,a);i&&f.subscribe(),f.setParent(h),f.initChildren();const v=((I=this.dataType)==null?void 0:I.clone(f,M.UUID.uuid(),i))||null;v&&f.setDataType(v);const R=(D=this.defaultValue)==null?void 0:D.clone(f,d+"-default-value-id",i);return f.defaultValue=R||null,this.implements&&(f.implements=this.implements),f.addSelfToProject(),f}setDataType(e){return this.dataType=e,this}removeDataType(){return this.dataType=null,this}getDataType(){return this.dataType}getDefaultValue(){return this.defaultValue}setDefaultValue(e){return this.defaultValue=e,this}};u(me,"repository",{create:async(e,...t)=>e,update:async(e,...t)=>e,delete:async(e,...t)=>{},load:async(e,...t)=>null}),u(me,"type",n.Property),u(me,"USER_MANAGED_PARENT_TYPES",[n.DefinitionEntity]),u(me,"PARENT_TYPES",[...me.USER_MANAGED_PARENT_TYPES,n.PrimitiveEntity,n.BuiltInBaseEntity]),u(me,"MUTABLE_BASE_PROPERTIES",["name","description","private","abstract","static","required","constant"]),u(me,"INMUTABLE_BASE_PROPERTIES",["id","type","version"]),u(me,"BASE_PROPERTIES",[...me.MUTABLE_BASE_PROPERTIES,...me.INMUTABLE_BASE_PROPERTIES]),u(me,"MUTABLE_META_PROPERTIES",[...me.MUTABLE_BASE_PROPERTIES,"index"]),u(me,"INMUTABLE_META_PROPERTIES",[...me.INMUTABLE_BASE_PROPERTIES]),u(me,"META_PROPERTIES",[...me.MUTABLE_META_PROPERTIES,...me.INMUTABLE_META_PROPERTIES]),u(me,"MUTABLE_UPSTREAM_PROPERTIES",[]),u(me,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","implements"]),u(me,"UPSTREAM_PROPERTIES",[...me.MUTABLE_UPSTREAM_PROPERTIES,...me.INMUTABLE_UPSTREAM_PROPERTIES]),u(me,"MUTABLE_DOWNSTREAM_PROPERTIES",["dataType"]),u(me,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),u(me,"DOWNSTREAM_PROPERTIES",[...me.MUTABLE_DOWNSTREAM_PROPERTIES,...me.INMUTABLE_DOWNSTREAM_PROPERTIES]),u(me,"PROPERTIES",[...me.META_PROPERTIES,...me.UPSTREAM_PROPERTIES,...me.DOWNSTREAM_PROPERTIES]);let oi=me;function h7(r){const s=Y3(),e=r.toJSON();s.safeParse(e).success;const i=y7(r),a=f7(r),o=Kt(r);r.inputs.forEach(d=>d.validate()),o.forEach(d=>d.validate());const l=[...i,...a];if(r.id==="getCompanyByIdEndpointReachedEntityEvent"){const d=oe({id:`${r.id}--${U.PropertyImplementsNonAbstact}`,message:`Property "${C(r,r.project)}" with id "${r.id}" implements a non-abstract property "${C(r,r.project)}" with id "${r.id}".`,issue:null,severity:E.Error,code:U.PropertyImplementsNonAbstact,entity:r});l.push(d.error)}return je(r.errors,l)}function y7(r){const s=[];if(!r.calls.length){const e=oe({id:`${r.id}--${U.ScopeWithoutLogic}`,message:`Action "${C(r,r.project)}" with id "${r.id}" does not have any logic defined. So it doesn't do anything.`,issue:null,severity:E.Warning,code:U.ScopeWithoutLogic,entity:r});s.push(e.error)}return je(r.errors,s)}function f7(r){const s=[];return r.implements,je(r.errors,s)}const Te=class Te extends Ke{constructor(e,t){super(e);u(this,"initialData");u(this,"id");u(this,"name");u(this,"description",null);u(this,"x");u(this,"y");u(this,"collapsed");u(this,"private");u(this,"index",null);u(this,"type",n.FunctionDeclaration);u(this,"implements",null);u(this,"inputs",[]);u(this,"returnStatements",[]);u(this,"calls",[]);u(this,"parent");u(this,"detachedChildren",[]);u(this,"errors",[]);u(this,"project");u(this,"initialized",!1);u(this,"suggestion",!1);this.initialData=e,this.project=t,this.id=e.id,this.name=e.name,this.description=e.description,this.private=e.private,this.collapsed=e.collapsed,this.x=e.x,this.y=e.y,this.index=e.index}static fromGenerationTarget(e,t){let i=t;if(e.parent){const d=P(e.parent);i=t.get(d)}let a=null;if(e.implements){const d=P(e.implements);a=t.get(d)}const o={id:e.id,version:"1",createdAt:$().toDate(),author:"1",previousVersion:null,deleted:!1,name:e.name,type:n.FunctionDeclaration,index:i.type===n.DefinitionEntity?i.methods.length:null,description:e.description,collapsed:!1,private:!1,returnStatements:[],calls:[],inputs:[],implements:a,x:0,y:0,parent:i},l=b(o,t);return l.setParent(i),l.initChildren(),l}static validateGenerationTarget(e,t){var f;let i=JSON.parse(JSON.stringify(e));const a=[],o=mt(i,{parent:{list:!1,types:[n.Project,n.InstalledProject,n.DefinitionEntity,n.Loop],optional:!0},implements:{list:!1,types:[n.ActionDescriptor],optional:!0}},t);i=o.modifiedData;const l=lp(i,t),d=i.parent?t.get(i.parent):null;if(d&&d.type===n.DefinitionEntity){const v=d,I=Vr(v).filter(D=>!D.interactive);if(I.length){let D=I.length>1?`The entity of type '${e.type}' with id '${e.id}' can't be added to the 'parent' entity with id '${v.id}' because it extends or implements multiple '${n.BuiltInBaseEntity}' entities that are non-interactive ("${z(I.map(A=>C(A,A.project)),'", "','" and "')}").`:`The entity of type '${e.type}' with id '${e.id}' can't be added to the 'parent' entity with id '${v.id}' because it extends or implements a '${n.BuiltInBaseEntity}' entity that is non-interactive ("${C(I[0],I[0].project)}").`;D+=`
46
46
  ${Sr}`,a.push(new g({id:`${e.id}--${T.NonInteractiveEntityReferenced}`,code:T.NonInteractiveEntityReferenced,severity:E.Error,message:D,issue:null}))}else{const D=v.methods.find(q=>{var w;return((w=q.implements)==null?void 0:w.id)===i.implements});D&&a.push(new g({id:`${i.id}--${B.MethodOverwrite}`,code:B.MethodOverwrite,severity:E.Error,message:`The '${n.FunctionDeclaration}' with id "${i.id}" is trying to implement the '${n.ActionDescriptor}' with id "${i.implements}", but the parent definition-entity already has a ${n.FunctionDeclaration} with id '${D.id}' that implements the same base method.
47
47
  A ${n.FunctionDeclaration} that has a parent of type '${n.DefinitionEntity}' is considered a method of that entity, and cannot implement the same '${n.ActionDescriptor}' more than once.
48
48
  ${n.ActionDescriptor} entities inside a ${n.DefinitionEntity} are considered abstract methods that can be implemented by ${n.FunctionDeclaration} entities inside the same parent.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elyx-code/project-logic-tree",
3
- "version": "0.0.6147",
3
+ "version": "0.0.6148",
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",