@elyx-code/project-logic-tree 0.0.6152 → 0.0.6153

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.
@@ -42,7 +42,7 @@ Please provide a unique 'name' string.`,severity:E.Error,code:w.NameNotUniqueInS
42
42
  Please provide a unique 'name' string.`,severity:E.Error,code:w.NameNotUniqueInScope,issue:null}))}}return e}function d7(n,s){switch(n.type){case r.DefinitionEntity:return Il(n,s);case r.FunctionDeclaration:return sp(n,s);case r.VariableDeclaration:return op(n,s);case r.Property:return lp(n,s);case r.ArgumentDeclaration:return dp(n,s);case r.ReturnDeclaration:return up(n,s);default:return[]}}function x1(n,s,e){const i=`${Rl(n)}-${s}-id`;return e.instances[i]?O.UUID.uuid():i}function cp(n,s){let e="",t=null;if(n.parent){const a=s.get(n.parent);a&&(t=a)}let i="";return t&&(i=`${Rl(B(t,s))}-`),e=`${i}${Rl(B(n,s))}-id`,s.instances[e]?O.UUID.uuid():e}function it(n,s,e="uuid"){return e==="semantic"?x1(B(n,s),n.type,s):O.UUID.uuid()}function u7(n){var o;const s=wk(),e=n.toJSON();s.safeParse(e).success;const i=c7(n);(o=n.dataType)==null||o.validate();const a=[...i];if(n.id==="80c86e1b-caca-4ba5-9b1f-38f72d10e4a3"){const l=le({id:`${n.id}--${U.PropertyImplementsNonAbstact}`,message:`Property "${B(n,n.project)}" with id "${n.id}" implements a non-abstract property "${B(n,n.project)}" with id "${n.id}".`,issue:null,severity:E.Error,code:U.PropertyImplementsNonAbstact,entity:n});a.push(l.error)}return a}function c7(n){const s=[];if(!n.implements)return s;const e=n.implements;if(!e.abstract){const i=le({id:`${n.id}--${U.PropertyImplementsNonAbstact}`,message:`Property "${B(n,n.project)}" with id "${n.id}" implements a non-abstract property "${B(e,n.project)}" with id "${e.id}".`,issue:null,severity:E.Error,code:U.PropertyImplementsNonAbstact,entity:n});s.push(i.error)}if(n.static&&!e.static){const i=le({id:`${n.id}--${U.NonStaticPropertyImplementsStatic}`,message:`Static property "${B(n,n.project)}" with id "${n.id}" implements a non-static property "${B(e,n.project)}" with id "${e.id}".`,issue:null,severity:E.Error,code:U.NonStaticPropertyImplementsStatic,entity:n});s.push(i.error)}if(!n.static&&e.static){const i=le({id:`${n.id}--${U.StaticPropertyImplementsNonStatic}`,message:`Non-static property "${B(n,n.project)}" with id "${n.id}" implements a static property "${B(e,n.project)}" with id "${e.id}".`,issue:null,severity:E.Error,code:U.StaticPropertyImplementsNonStatic,entity:n});s.push(i.error)}if(!pr(n.dataType,e.dataType)){const i=le({id:`${n.id}--${U.PropertyImplementsIncompatibleType}`,message:`Property "${B(n,n.project)}" with id "${n.id}" implements a property "${B(e,n.project)}" with id "${e.id}" that has an incompatible data type.`,issue:null,severity:E.Error,code:U.PropertyImplementsIncompatibleType,entity:n});s.push(i.error)}return xe(n.errors,s)}function p7(n,s){const e=[];if(n.parent){const i=s.get(n.parent);if(!i)e.push(new g({id:`${n.id}--${n.parent}--${T.ReferencedEntityNotFound}`,code:T.ReferencedEntityNotFound,severity:E.Error,message:`Entity of type "${n.type}" with id "${n.id}", is referencing an entity with id "${n.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=Cn(i);if(a){const o=i!==a?`The entity of type '${n.type}' with id '${n.id}' have 'parent' with id '${n.parent}' because the entity belongs to a built-in '${a.type}' entity with id '${a.id}' (${B(a,i.project)}) higher up in the tree.`:`The entity of type '${n.type}' with id '${n.id}' have 'parent' with id '${n.parent}' because it is a built-in entity of type ${a.type}.`;e.push(new g({id:`${n.id}--${T.InvalidBuiltInEntityReference}`,code:T.InvalidBuiltInEntityReference,severity:E.Error,message:o,issue:null}))}else if(![r.DefinitionEntity].includes(i.type))e.push(new g({id:`${n.id}--${n.parent}--${T.InvalidParentReference}`,code:T.InvalidParentReference,severity:E.Error,message:`Entity of type "${n.type}" with id "${n.id}", has a parent reference that isn't pointing to an entity of type 'definition-entity'.`,issue:null}));else{const l=Vn(i).filter(d=>!d.interactive);if(l.length){let d=l.length>1?`The entity of type '${n.type}' with id '${n.id}' can't be added to the 'parent' entity with id '${i.id}' because it extends or implements multiple '${r.BuiltInBaseEntity}' entities that are non-interactive ("${K(l.map(h=>B(h,h.project)),'", "','" and "')}").`:`The entity of type '${n.type}' with id '${n.id}' can't be added to the 'parent' entity with id '${i.id}' because it extends or implements a '${r.BuiltInBaseEntity}' entity that is non-interactive ("${B(l[0],l[0].project)}").`;d+=`
43
43
  ${Sn}`,e.push(new g({id:`${n.id}--${T.NonInteractiveEntityReferenced}`,code:T.NonInteractiveEntityReferenced,severity:E.Error,message:d,issue:null}))}else if(n.implements){const d=s.get(n.implements);if(n.id===n.implements)return e.push(new g({id:`${n.id}--${n.implements}--${T.SelfReference}`,code:T.SelfReference,severity:E.Error,message:`Entity of type "${n.type}" with id "${n.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:`${n.id}--${n.implements}--${T.ReferencedEntityNotFound}`,code:T.ReferencedEntityNotFound,severity:E.Error,message:`Entity of type "${n.type}" with id "${n.id}", is referencing an entity with id "${n.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)===n.implements});h?e.push(new g({id:`${n.id}--${w.PropertyOverwrite}`,code:w.PropertyOverwrite,severity:E.Error,message:`The property with id "${n.id}" is trying to implement the property with id "${n.implements}", but the parent entity already has a property with id '${h.id}' that implements the same base property.`,issue:null})):[r.Property].includes(d.type)?d.abstract||e.push(new g({id:`${n.id}--${n.implements}--${T.InvalidImplementsReference}`,code:T.InvalidImplementsReference,severity:E.Error,message:`Entity of type "${n.type}" with id "${n.id}", has an 'implements' reference that isn't pointing to an abstract entity.`,issue:null})):e.push(new g({id:`${n.id}--${n.implements}--${T.InvalidImplementsReference}`,code:T.InvalidImplementsReference,severity:E.Error,message:`Entity of type "${n.type}" with id "${n.id}", has an 'implements' reference that isn't pointing to an entity of type 'property'.`,issue:null}))}}}}}const t=ft(n,{},s);return e.push(...t.errors),e}class ze{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 ze{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",r.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:r.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=lp(i,t);return a.push(...o,...l,...et(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}--${w.InvalidObjectStructure}`,code:w.InvalidObjectStructure,severity:E.Error,message:`Entity of type '${this.type}' with id '${this.id}' is not a value reading or writing entity.
45
- ${Sl}`,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(`${An(this.type)} "${B(this,this.project)}" with id '${this.id}' has a parent reference "${a}" which is missing in the project`)}else throw new Error(`${An(this.type)} "${B(this,this.project)}" 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===r.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===r.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))||[],...this.parent.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))||[],...this.parent.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||it(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+"--"+O.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,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))||[],...this.parent.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=at(e,this);const o=t||O.UUID.uuid(),l=o.split("-id"),d=l[l.length-1||0]||o;let h=e||this.parent;const y={hidden:!1,id:o,version:O.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=tt(y,a);i&&f.subscribe(),f.setParent(h),f.initChildren();const v=((I=this.dataType)==null?void 0:I.clone(f,O.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",r.Property),u(me,"USER_MANAGED_PARENT_TYPES",[r.DefinitionEntity]),u(me,"PARENT_TYPES",[...me.USER_MANAGED_PARENT_TYPES,r.PrimitiveEntity,r.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(n){const s=Y3(),e=n.toJSON();s.safeParse(e).success;const i=y7(n),a=f7(n),o=zt(n);n.inputs.forEach(d=>d.validate()),o.forEach(d=>d.validate());const l=[...i,...a];if(n.id==="getCompanyByIdEndpointReachedEntityEvent"){const d=le({id:`${n.id}--${U.PropertyImplementsNonAbstact}`,message:`Property "${B(n,n.project)}" with id "${n.id}" implements a non-abstract property "${B(n,n.project)}" with id "${n.id}".`,issue:null,severity:E.Error,code:U.PropertyImplementsNonAbstact,entity:n});l.push(d.error)}return xe(n.errors,l)}function y7(n){const s=[];if(!n.calls.length){const e=le({id:`${n.id}--${U.ScopeWithoutLogic}`,message:`Action "${B(n,n.project)}" with id "${n.id}" does not have any logic defined. So it doesn't do anything.`,issue:null,severity:E.Warning,code:U.ScopeWithoutLogic,entity:n});s.push(e.error)}return xe(n.errors,s)}function f7(n){const s=[];return n.implements,xe(n.errors,s)}const Te=class Te extends ze{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",r.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:r.FunctionDeclaration,index:i.type===r.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=ft(i,{parent:{list:!1,types:[r.Project,r.InstalledProject,r.DefinitionEntity,r.Loop],optional:!0},implements:{list:!1,types:[r.ActionDescriptor],optional:!0}},t);i=o.modifiedData;const l=sp(i,t),d=i.parent?t.get(i.parent):null;if(d&&d.type===r.DefinitionEntity){const v=d,I=Vn(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 '${r.BuiltInBaseEntity}' entities that are non-interactive ("${K(I.map(A=>B(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 '${r.BuiltInBaseEntity}' entity that is non-interactive ("${B(I[0],I[0].project)}").`;D+=`
45
+ ${Sl}`,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(`${An(this.type)} with id '${this.id}' has a parent reference "${a}" which is missing in the project`)}else throw new Error(`${An(this.type)} 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===r.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===r.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))||[],...this.parent.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))||[],...this.parent.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||it(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+"--"+O.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,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))||[],...this.parent.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=at(e,this);const o=t||O.UUID.uuid(),l=o.split("-id"),d=l[l.length-1||0]||o;let h=e||this.parent;const y={hidden:!1,id:o,version:O.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=tt(y,a);i&&f.subscribe(),f.setParent(h),f.initChildren();const v=((I=this.dataType)==null?void 0:I.clone(f,O.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",r.Property),u(me,"USER_MANAGED_PARENT_TYPES",[r.DefinitionEntity]),u(me,"PARENT_TYPES",[...me.USER_MANAGED_PARENT_TYPES,r.PrimitiveEntity,r.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(n){const s=Y3(),e=n.toJSON();s.safeParse(e).success;const i=y7(n),a=f7(n),o=zt(n);n.inputs.forEach(d=>d.validate()),o.forEach(d=>d.validate());const l=[...i,...a];if(n.id==="getCompanyByIdEndpointReachedEntityEvent"){const d=le({id:`${n.id}--${U.PropertyImplementsNonAbstact}`,message:`Property "${B(n,n.project)}" with id "${n.id}" implements a non-abstract property "${B(n,n.project)}" with id "${n.id}".`,issue:null,severity:E.Error,code:U.PropertyImplementsNonAbstact,entity:n});l.push(d.error)}return xe(n.errors,l)}function y7(n){const s=[];if(!n.calls.length){const e=le({id:`${n.id}--${U.ScopeWithoutLogic}`,message:`Action "${B(n,n.project)}" with id "${n.id}" does not have any logic defined. So it doesn't do anything.`,issue:null,severity:E.Warning,code:U.ScopeWithoutLogic,entity:n});s.push(e.error)}return xe(n.errors,s)}function f7(n){const s=[];return n.implements,xe(n.errors,s)}const Te=class Te extends ze{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",r.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:r.FunctionDeclaration,index:i.type===r.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=ft(i,{parent:{list:!1,types:[r.Project,r.InstalledProject,r.DefinitionEntity,r.Loop],optional:!0},implements:{list:!1,types:[r.ActionDescriptor],optional:!0}},t);i=o.modifiedData;const l=sp(i,t),d=i.parent?t.get(i.parent):null;if(d&&d.type===r.DefinitionEntity){const v=d,I=Vn(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 '${r.BuiltInBaseEntity}' entities that are non-interactive ("${K(I.map(A=>B(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 '${r.BuiltInBaseEntity}' entity that is non-interactive ("${B(I[0],I[0].project)}").`;D+=`
46
46
  ${Sn}`,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(H=>{var W;return((W=H.implements)==null?void 0:W.id)===i.implements});D&&a.push(new g({id:`${i.id}--${w.MethodOverwrite}`,code:w.MethodOverwrite,severity:E.Error,message:`The '${r.FunctionDeclaration}' with id "${i.id}" is trying to implement the '${r.ActionDescriptor}' with id "${i.implements}", but the parent definition-entity already has a ${r.FunctionDeclaration} with id '${D.id}' that implements the same base method.
47
47
  A ${r.FunctionDeclaration} that has a parent of type '${r.DefinitionEntity}' is considered a method of that entity, and cannot implement the same '${r.ActionDescriptor}' more than once.
48
48
  ${r.ActionDescriptor} entities inside a ${r.DefinitionEntity} are considered abstract methods that can be implemented by ${r.FunctionDeclaration} entities inside the same parent.
@@ -82,7 +82,7 @@ You shouldn't have to manually update a 'parent' property. The equivalent result
82
82
  ${wl(t)}`,issue:null})):a.push(new g({id:`${e.id}--${T.ReferencedEntityNotFound}`,code:T.ReferencedEntityNotFound,severity:E.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 '${r.Condition}' entities.
83
83
  ${wl(t)}`,issue:null})):a.push(new g({id:`${e.id}--${w.InvalidObjectStructure}`,code:w.InvalidObjectStructure,severity:E.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 '${r.Condition}' entities.
84
84
  ${wl(t)}`,issue:null})),{errors:a,modifiedData:i}}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. The 'parent' on a callable entity, is its scope. It scope is auto-calculated implicitly by the its caller.
85
- If an entity is called by another, they must be in the same scope, which means they have the same parent.`,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(`${An(this.type)} "${B(this,this.project)}" with id '${this.id}' has a parent reference "${a}" which is missing in the project`)}else throw new Error(`${An(this.type)} "${B(this,this.project)}" with id '${this.id}' is missing a parent reference`);if(this.initialData.declaration){const a=P(this.initialData.declaration),o=this.project.get(a);o&&(this.setDeclaration(o),e.push(o))}return this.initialData.calledByEntry.forEach(a=>{const o=P(a),l=this.project.get(o);l&&(this.addEntryCaller(l),e.push(l))}),this.initialData.calledBySuccess.forEach(a=>{const o=P(a),l=this.project.get(o);l&&(this.addSuccessCaller(l),e.push(l))}),this.initialData.calledByError.forEach(a=>{const o=P(a),l=this.project.get(o);l&&(this.addErrorCaller(l),e.push(l))}),{updated:m(e),added:m(t),removed:m(i),self:this}}afterAllChildrenInitialized(){const e=[],t=[],i=[];this.initialized=!0;const{updated:a,added:o,removed:l}=this.syncMissingFixedInputs();return e.push(...a),t.push(...o),i.push(...l),{updated:m(e),added:m(t),removed:m(i),self:this}}addSelfToProject(){const e=[this],t=[],i=[];return this.parent===this.project&&this.project.addCondition(this),this.successCalls.forEach(a=>{a.addSuccessCaller(this),e.push(a)}),this.errorCalls.forEach(a=>{a.addErrorCaller(this),e.push(a)}),this.calledByEntry.forEach(a=>{a.addCall(this),e.push(a)}),this.calledBySuccess.forEach(a=>{a.addSuccessCall(this),e.push(a)}),this.calledByError.forEach(a=>{a.addErrorCall(this),e.push(a)}),{updated:m(e),added:m(t),removed:m(i),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}removeInput(e){const t=this.inputs.findIndex(i=>i.id===e.id);return t>-1&&this.inputs.splice(t,1),this}addInput(e){return this.inputs.includes(e)?this:(this.inputs.push(e),this)}addOutput(e){return this}removeOutput(e){return this}addSuccessCaller(e){return this.calledBySuccess.find(t=>t.id===e.id)||this.calledBySuccess.push(e),this}addErrorCaller(e){return this.calledByError.find(t=>t.id===e.id)||this.calledByError.push(e),this}addEntryCaller(e){return this.calledByEntry.find(t=>t.id===e.id)||this.calledByEntry.push(e),this}addErrorCall(e){return this.errorCalls.find(t=>t.id===e.id)||this.errorCalls.push(e),this}addSuccessCall(e){return this.successCalls.find(t=>t.id===e.id)||this.successCalls.push(e),this}removeCall(e){const t=this.successCalls.findIndex(a=>a.id===e.id);t>-1&&this.successCalls.splice(t,1);const i=this.errorCalls.findIndex(a=>a.id===e.id);return i>-1&&this.errorCalls.splice(i,1),this}removeCaller(e){return this.calledBySuccess=this.calledBySuccess.filter(t=>t.id!==e.id),this.calledByError=this.calledByError.filter(t=>t.id!==e.id),this.calledByEntry=this.calledByEntry.filter(t=>t.id!==e.id),this}setParent(e){return this.parent=e,this}setDeclaration(e){return this.declaration=e,this}initChildren(){return this.initialized?this:(this.initialized=!0,this.declaration=b(this.initialData.declaration,this.project),this.successCalls=this.initialData.successCalls.map(e=>{const t=b(e,this.project);return t.addSuccessCaller(this),[r.BreakStatement,r.ContinueStatement].includes(t.type)?(t.setParent(this.parent.parent),t.initChildren()):t.type!==r.InternalCall&&(t.setParent(this.parent),t.initChildren()),t}),this.errorCalls=this.initialData.errorCalls.map(e=>{const t=b(e,this.project);return t.addErrorCaller(this),[r.BreakStatement,r.ContinueStatement].includes(t.type)?(t.setParent(this.parent.parent),t.initChildren()):t.type!==r.InternalCall&&(t.setParent(this.parent),t.initChildren()),t}),this.inputs=this.initialData.inputs.map(e=>{const t=b(e,this.project);return t.setParent(this),t.initChildren(),t}),this.afterAllChildrenInitialized(),this)}subscribe(){return this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}sync(e){return super.sync(e),this.x=e.x||this.x,this.y=e.y||this.y,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=[];return t.has(this.id)?{affected:[],removed:[]}:(t.add(this.id),a.push(this),this.unsubscribe(),this.inputs.forEach(o=>{const{affected:l,removed:d}=o.remove({ignoreUpstream:!0,seenEntities:t});i.push(...l),a.push(...d)}),this.successCalls.forEach(o=>{i.push(o),o.removeCaller(this)}),this.errorCalls.forEach(o=>{i.push(o),o.removeCaller(this)}),e||this.calledBy.forEach(o=>{i.push(o),o.removeCall(this)}),{affected:m(i),removed:m(a)})}restore({seenEntities:e}={seenEntities:new Set}){const t=[];return e.has(this.id)?{affected:[],self:this}:(e.add(this.id),this.subscribe(),this.inputs.forEach(i=>{const{affected:a}=i.restore({seenEntities:e});t.push(...a)}),this.successCalls.forEach(i=>{t.push(i),i.addSuccessCaller(this)}),this.errorCalls.forEach(i=>{t.push(i),i.addErrorCaller(this)}),this.calledBySuccess.forEach(i=>{t.push(i),i.addSuccessCall(this)}),this.calledByError.forEach(i=>{t.push(i),i.addErrorCall(this)}),this.calledByEntry.forEach(i=>{t.push(i),i.addCall(this)}),{affected:t,self:this})}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.inputs.flatMap(i=>i.toFlat(e)),...this.successCalls.flatMap(i=>i.toFlat(e)),...this.errorCalls.flatMap(i=>i.toFlat(e)),...this.calledBy.flatMap(i=>i.toFlat(e))])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.inputs.flatMap(i=>i.toFlatIds(e)),...this.successCalls.flatMap(i=>i.toFlatIds(e)),...this.errorCalls.flatMap(i=>i.toFlatIds(e)),...this.calledBy.flatMap(i=>i.toFlatIds(e))])}toJSON(e=new Set){return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,declaration:this.declaration.toJSON(e),successCalls:this.successCalls.map(t=>t.toJSON(e)),errorCalls:this.errorCalls.map(t=>t.toJSON(e)),calledBySuccess:this.calledBySuccess.map(t=>t.toReference()),calledByError:this.calledByError.map(t=>t.toReference()),calledByEntry:this.calledByEntry.map(t=>t.toReference()),inputs:this.inputs.map(t=>t.toJSON(e)),parent:this.parent.toReference()})}toJSONClone(e=F){var i,a,o,l,d;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||it(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,x:this.x,y:this.y,declaration:this.declaration.toJSON(),successCalls:this.successCalls.map(h=>h.toJSONClone({...e,newId:null})),errorCalls:this.errorCalls.map(h=>h.toJSONClone({...e,newId:null})),calledBySuccess:this.calledBySuccess.map(h=>h.toReference({seenEntityMaps:e.seenEntityMaps})),calledByError:this.calledByError.map(h=>h.toReference({seenEntityMaps:e.seenEntityMaps})),calledByEntry:this.calledByEntry.map(h=>h.toReference({seenEntityMaps:e.seenEntityMaps})),inputs:this.inputs.map(h=>h.toJSONClone({...e,newId: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+"--"+O.UUID.uuid()+"--ref",type:r.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(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,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,declaration:this.declaration.toReference(e),inputs:this.inputs.map(a=>a.toReference(e)),successCalls:this.successCalls.map(a=>a.toReference(e)),errorCalls:this.errorCalls.map(a=>a.toReference(e)),calledBySuccess:this.calledBySuccess.map(a=>a.toReference(e)),calledByError:this.calledByError.map(a=>a.toReference(e)),calledByEntry:this.calledByEntry.map(a=>a.toReference(e)),parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.inputs.flatMap(i=>i.toFlatJSON(e)),...this.successCalls.flatMap(i=>i.toFlatJSON(e)),...this.errorCalls.flatMap(i=>i.toFlatJSON(e)),...this.calledBy.flatMap(i=>i.toFlatJSON(e))])}toGenerationTarget(){const e=this.parent.type===r.Project?void 0:this.parent.id;return{id:this.id,type:this.type,declaration:this.declaration.id,calledByEntry:this.calledByEntry.map(t=>t.id),calledBySuccess:this.calledBySuccess.map(t=>t.id),calledByError:this.calledByError.map(t=>t.id),parent:e}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...this.inputs.flatMap(i=>i.toFlatGenerationTarget(e)),...this.successCalls.flatMap(i=>i.toFlatGenerationTarget(e)),...this.errorCalls.flatMap(i=>i.toFlatGenerationTarget(e))])}clearErrors(){return this.errors=[],this.inputs.forEach(e=>e.clearErrors()),this.successCalls.forEach(e=>e.clearErrors()),this.errorCalls.forEach(e=>e.clearErrors()),this}validate(){const e=I7(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){return[...this.errors,...this.inputs.flatMap(t=>t.getErrors())]}getShallowErrors(){return this.errors}clone(e=null,t=null,i=!0){var v;let a=at(e,this);const o=this.toJSON(),l=t||O.UUID.uuid();o.inputs=[];const d=l.split("-id"),h=d[d.length-1||0]||l;o.id=l;const y=tt(o,a);e?y.setParent(e):y.setParent(this.parent),i&&y.subscribe(),y.initChildren();const f=(v=this.inputs)==null?void 0:v.map((R,I)=>R.clone(y,h+"-input-map-"+I+"-id",i));return y.inputs=f,y}removeUnrecognizedInputs(){const e=[],t=[],i=[];return this.inputs.forEach(a=>{if(!this.declaration.inputs.find(l=>{var d;return l.id===((d=a.declaration)==null?void 0:d.id)})){const l=a.remove();i.push(...l.removed),e.push(...l.affected)}}),{updated:m(e),added:m(t),removed:m(i),self:this}}syncMissingFixedInputs(){const e=[],t=[],i=[],a=this.declaration.inputs.filter(h=>h.parentRelationType===V.FixedArguments&&!this.inputs.find(y=>y.declaration.id===h.id));this.inputs.sort((h,y)=>h.index-y.index),a.forEach(h=>{this.inputs.forEach(v=>{v.index>=h.index&&v.sync({index:v.index+1})});const y={id:O.UUID.uuid(),version:"1",createdAt:$().toDate(),author:"1",previousVersion:null,deleted:!1,type:r.InputMap,declaration:h.toJSON(),readsValue:null,defaultValue:null,index:h.index,name:null,description:null,parent:this.toReference()},f=b(y,this.project);f.setParent(this),f.initChildren(),f.addSelfToProject()}),this.inputs.sort((h,y)=>h.index-y.index);const{updated:o,added:l,removed:d}=this.removeUnrecognizedInputs();return e.push(...o),t.push(...l),i.push(...d),{updated:m(e),added:m(t),removed:m(i),self: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",r.Condition),u(Me,"USER_MANAGED_PARENT_TYPES",[...He,r.Project]),u(Me,"PARENT_TYPES",[...Me.USER_MANAGED_PARENT_TYPES]),u(Me,"MUTABLE_BASE_PROPERTIES",["operator"]),u(Me,"INMUTABLE_BASE_PROPERTIES",["id","version","type"]),u(Me,"BASE_PROPERTIES",[...Me.MUTABLE_BASE_PROPERTIES,...Me.INMUTABLE_BASE_PROPERTIES]),u(Me,"MUTABLE_META_PROPERTIES",["x","y"]),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",["calledBySuccess","calledByError","calledByEntry","parent"]),u(Me,"INMUTABLE_UPSTREAM_PROPERTIES",[]),u(Me,"UPSTREAM_PROPERTIES",[...Me.MUTABLE_UPSTREAM_PROPERTIES,...Me.INMUTABLE_UPSTREAM_PROPERTIES]),u(Me,"MUTABLE_DOWNSTREAM_PROPERTIES",["successCalls","errorCalls","inputsDeclarations","inputs"]),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 ci=Me;function A7(n){var l;const s=i3(),e=n.toJSON();s.safeParse(e).success,(l=n.dataType)==null||l.validate(),n.inputs.forEach(d=>d.validate()),n.outputs.forEach(d=>d.validate()),n.internalCalls.forEach(d=>d.validate());const a=[...on(n)];if(n.id==="random-company-employee-test-variable-id"){const d=le({id:`${n.id}--${U.PropertyImplementsNonAbstact}`,message:`Property "${B(n,n.project)}" with id "${n.id}" implements a non-abstract property "${B(n,n.project)}" with id "${n.id}".`,issue:null,severity:E.Error,code:U.PropertyImplementsNonAbstact,entity:n});a.push(d.error)}if(n.id==="company-dto-variable-one-id"){const d=le({id:`${n.id}--${U.PropertyImplementsNonAbstact}`,message:`Property "${B(n,n.project)}" with id "${n.id}" implements a non-abstract property "${B(n,n.project)}" with id "${n.id}".`,issue:null,severity:E.Error,code:U.PropertyImplementsNonAbstact,entity:n});a.push(d.error)}const o=gp(n);return a.push(...o),xe(n.errors,a)}const be=class be extends ze{constructor(e,t){super(e);u(this,"initialData");u(this,"id");u(this,"name");u(this,"description",null);u(this,"required",!1);u(this,"constant",!1);u(this,"x");u(this,"y");u(this,"type",r.VariableDeclaration);u(this,"defaultValue",null);u(this,"dataType",null);u(this,"writesValues",[]);u(this,"readsValue",null);u(this,"inputs",[]);u(this,"outputs",[]);u(this,"calledBySuccess",[]);u(this,"calledByError",[]);u(this,"calledByEntry",[]);u(this,"successCalls",[]);u(this,"errorCalls",[]);u(this,"internalCalls",[]);u(this,"parent");u(this,"variableInstances",[]);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.constant=e.constant,this.required=e.required,this.x=e.x,this.y=e.y}static fromGenerationTarget(e,t){let i=t;if(e.parent){const f=P(e.parent);i=t.get(f)}const a=e.calledByEntry.map(f=>{const v=P(f);return t.get(v)}),o=e.calledBySuccess.map(f=>{const v=P(f);return t.get(v)}),l=e.calledByError.map(f=>{const v=P(f);return t.get(v)});let d=null;if(e.readsValue){const f=P(e.readsValue);d=t.get(f)}const h={id:e.id,version:"1",createdAt:$().toDate(),author:"1",previousVersion:null,deleted:!1,type:r.VariableDeclaration,name:e.name,defaultValue:null,description:e.description,constant:e.constant||!1,required:e.required||!1,calledByEntry:a,calledBySuccess:o,calledByError:l,dataType:null,errorCalls:[],successCalls:[],internalCalls:[],readsValue:d,inputs:[],outputs:[],writesValues:[],x:0,y:0,parent:i},y=b(h,t);return y.setParent(i),y.initChildren(),y}static validateGenerationTarget(e,t){let i=JSON.parse(JSON.stringify(e));const a=[],o=ft(i,{parent:{list:!1,types:[...dt,r.Project],optional:!0}},t);i=o.modifiedData;const l=op(i,t);return a.push(...o.errors,...l,...et(i)),{errors:a,modifiedData:i}}validateGeneratedUpdate(e){const t=[];let i=JSON.parse(JSON.stringify(e));const a=gs(i,this);return i=a.modifiedData,t.push(...a.errors),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. The 'parent' on a callable entity, is its scope. It scope is auto-calculated implicitly by the its caller.
85
+ If an entity is called by another, they must be in the same scope, which means they have the same parent.`,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(`${An(this.type)} with id '${this.id}' has a parent reference "${a}" which is missing in the project`)}else throw new Error(`${An(this.type)} with id '${this.id}' is missing a parent reference`);if(this.initialData.declaration){const a=P(this.initialData.declaration),o=this.project.get(a);o&&(this.setDeclaration(o),e.push(o))}return this.initialData.calledByEntry.forEach(a=>{const o=P(a),l=this.project.get(o);l&&(this.addEntryCaller(l),e.push(l))}),this.initialData.calledBySuccess.forEach(a=>{const o=P(a),l=this.project.get(o);l&&(this.addSuccessCaller(l),e.push(l))}),this.initialData.calledByError.forEach(a=>{const o=P(a),l=this.project.get(o);l&&(this.addErrorCaller(l),e.push(l))}),{updated:m(e),added:m(t),removed:m(i),self:this}}afterAllChildrenInitialized(){const e=[],t=[],i=[];this.initialized=!0;const{updated:a,added:o,removed:l}=this.syncMissingFixedInputs();return e.push(...a),t.push(...o),i.push(...l),{updated:m(e),added:m(t),removed:m(i),self:this}}addSelfToProject(){const e=[this],t=[],i=[];return this.parent===this.project&&this.project.addCondition(this),this.successCalls.forEach(a=>{a.addSuccessCaller(this),e.push(a)}),this.errorCalls.forEach(a=>{a.addErrorCaller(this),e.push(a)}),this.calledByEntry.forEach(a=>{a.addCall(this),e.push(a)}),this.calledBySuccess.forEach(a=>{a.addSuccessCall(this),e.push(a)}),this.calledByError.forEach(a=>{a.addErrorCall(this),e.push(a)}),{updated:m(e),added:m(t),removed:m(i),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}removeInput(e){const t=this.inputs.findIndex(i=>i.id===e.id);return t>-1&&this.inputs.splice(t,1),this}addInput(e){return this.inputs.includes(e)?this:(this.inputs.push(e),this)}addOutput(e){return this}removeOutput(e){return this}addSuccessCaller(e){return this.calledBySuccess.find(t=>t.id===e.id)||this.calledBySuccess.push(e),this}addErrorCaller(e){return this.calledByError.find(t=>t.id===e.id)||this.calledByError.push(e),this}addEntryCaller(e){return this.calledByEntry.find(t=>t.id===e.id)||this.calledByEntry.push(e),this}addErrorCall(e){return this.errorCalls.find(t=>t.id===e.id)||this.errorCalls.push(e),this}addSuccessCall(e){return this.successCalls.find(t=>t.id===e.id)||this.successCalls.push(e),this}removeCall(e){const t=this.successCalls.findIndex(a=>a.id===e.id);t>-1&&this.successCalls.splice(t,1);const i=this.errorCalls.findIndex(a=>a.id===e.id);return i>-1&&this.errorCalls.splice(i,1),this}removeCaller(e){return this.calledBySuccess=this.calledBySuccess.filter(t=>t.id!==e.id),this.calledByError=this.calledByError.filter(t=>t.id!==e.id),this.calledByEntry=this.calledByEntry.filter(t=>t.id!==e.id),this}setParent(e){return this.parent=e,this}setDeclaration(e){return this.declaration=e,this}initChildren(){return this.initialized?this:(this.initialized=!0,this.declaration=b(this.initialData.declaration,this.project),this.successCalls=this.initialData.successCalls.map(e=>{const t=b(e,this.project);return t.addSuccessCaller(this),[r.BreakStatement,r.ContinueStatement].includes(t.type)?(t.setParent(this.parent.parent),t.initChildren()):t.type!==r.InternalCall&&(t.setParent(this.parent),t.initChildren()),t}),this.errorCalls=this.initialData.errorCalls.map(e=>{const t=b(e,this.project);return t.addErrorCaller(this),[r.BreakStatement,r.ContinueStatement].includes(t.type)?(t.setParent(this.parent.parent),t.initChildren()):t.type!==r.InternalCall&&(t.setParent(this.parent),t.initChildren()),t}),this.inputs=this.initialData.inputs.map(e=>{const t=b(e,this.project);return t.setParent(this),t.initChildren(),t}),this.afterAllChildrenInitialized(),this)}subscribe(){return this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}sync(e){return super.sync(e),this.x=e.x||this.x,this.y=e.y||this.y,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=[];return t.has(this.id)?{affected:[],removed:[]}:(t.add(this.id),a.push(this),this.unsubscribe(),this.inputs.forEach(o=>{const{affected:l,removed:d}=o.remove({ignoreUpstream:!0,seenEntities:t});i.push(...l),a.push(...d)}),this.successCalls.forEach(o=>{i.push(o),o.removeCaller(this)}),this.errorCalls.forEach(o=>{i.push(o),o.removeCaller(this)}),e||this.calledBy.forEach(o=>{i.push(o),o.removeCall(this)}),{affected:m(i),removed:m(a)})}restore({seenEntities:e}={seenEntities:new Set}){const t=[];return e.has(this.id)?{affected:[],self:this}:(e.add(this.id),this.subscribe(),this.inputs.forEach(i=>{const{affected:a}=i.restore({seenEntities:e});t.push(...a)}),this.successCalls.forEach(i=>{t.push(i),i.addSuccessCaller(this)}),this.errorCalls.forEach(i=>{t.push(i),i.addErrorCaller(this)}),this.calledBySuccess.forEach(i=>{t.push(i),i.addSuccessCall(this)}),this.calledByError.forEach(i=>{t.push(i),i.addErrorCall(this)}),this.calledByEntry.forEach(i=>{t.push(i),i.addCall(this)}),{affected:t,self:this})}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.inputs.flatMap(i=>i.toFlat(e)),...this.successCalls.flatMap(i=>i.toFlat(e)),...this.errorCalls.flatMap(i=>i.toFlat(e)),...this.calledBy.flatMap(i=>i.toFlat(e))])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.inputs.flatMap(i=>i.toFlatIds(e)),...this.successCalls.flatMap(i=>i.toFlatIds(e)),...this.errorCalls.flatMap(i=>i.toFlatIds(e)),...this.calledBy.flatMap(i=>i.toFlatIds(e))])}toJSON(e=new Set){return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,declaration:this.declaration.toJSON(e),successCalls:this.successCalls.map(t=>t.toJSON(e)),errorCalls:this.errorCalls.map(t=>t.toJSON(e)),calledBySuccess:this.calledBySuccess.map(t=>t.toReference()),calledByError:this.calledByError.map(t=>t.toReference()),calledByEntry:this.calledByEntry.map(t=>t.toReference()),inputs:this.inputs.map(t=>t.toJSON(e)),parent:this.parent.toReference()})}toJSONClone(e=F){var i,a,o,l,d;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||it(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,x:this.x,y:this.y,declaration:this.declaration.toJSON(),successCalls:this.successCalls.map(h=>h.toJSONClone({...e,newId:null})),errorCalls:this.errorCalls.map(h=>h.toJSONClone({...e,newId:null})),calledBySuccess:this.calledBySuccess.map(h=>h.toReference({seenEntityMaps:e.seenEntityMaps})),calledByError:this.calledByError.map(h=>h.toReference({seenEntityMaps:e.seenEntityMaps})),calledByEntry:this.calledByEntry.map(h=>h.toReference({seenEntityMaps:e.seenEntityMaps})),inputs:this.inputs.map(h=>h.toJSONClone({...e,newId: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+"--"+O.UUID.uuid()+"--ref",type:r.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(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,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,declaration:this.declaration.toReference(e),inputs:this.inputs.map(a=>a.toReference(e)),successCalls:this.successCalls.map(a=>a.toReference(e)),errorCalls:this.errorCalls.map(a=>a.toReference(e)),calledBySuccess:this.calledBySuccess.map(a=>a.toReference(e)),calledByError:this.calledByError.map(a=>a.toReference(e)),calledByEntry:this.calledByEntry.map(a=>a.toReference(e)),parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.inputs.flatMap(i=>i.toFlatJSON(e)),...this.successCalls.flatMap(i=>i.toFlatJSON(e)),...this.errorCalls.flatMap(i=>i.toFlatJSON(e)),...this.calledBy.flatMap(i=>i.toFlatJSON(e))])}toGenerationTarget(){const e=this.parent.type===r.Project?void 0:this.parent.id;return{id:this.id,type:this.type,declaration:this.declaration.id,calledByEntry:this.calledByEntry.map(t=>t.id),calledBySuccess:this.calledBySuccess.map(t=>t.id),calledByError:this.calledByError.map(t=>t.id),parent:e}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...this.inputs.flatMap(i=>i.toFlatGenerationTarget(e)),...this.successCalls.flatMap(i=>i.toFlatGenerationTarget(e)),...this.errorCalls.flatMap(i=>i.toFlatGenerationTarget(e))])}clearErrors(){return this.errors=[],this.inputs.forEach(e=>e.clearErrors()),this.successCalls.forEach(e=>e.clearErrors()),this.errorCalls.forEach(e=>e.clearErrors()),this}validate(){const e=I7(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){return[...this.errors,...this.inputs.flatMap(t=>t.getErrors())]}getShallowErrors(){return this.errors}clone(e=null,t=null,i=!0){var v;let a=at(e,this);const o=this.toJSON(),l=t||O.UUID.uuid();o.inputs=[];const d=l.split("-id"),h=d[d.length-1||0]||l;o.id=l;const y=tt(o,a);e?y.setParent(e):y.setParent(this.parent),i&&y.subscribe(),y.initChildren();const f=(v=this.inputs)==null?void 0:v.map((R,I)=>R.clone(y,h+"-input-map-"+I+"-id",i));return y.inputs=f,y}removeUnrecognizedInputs(){const e=[],t=[],i=[];return this.inputs.forEach(a=>{if(!this.declaration.inputs.find(l=>{var d;return l.id===((d=a.declaration)==null?void 0:d.id)})){const l=a.remove();i.push(...l.removed),e.push(...l.affected)}}),{updated:m(e),added:m(t),removed:m(i),self:this}}syncMissingFixedInputs(){const e=[],t=[],i=[],a=this.declaration.inputs.filter(h=>h.parentRelationType===V.FixedArguments&&!this.inputs.find(y=>y.declaration.id===h.id));this.inputs.sort((h,y)=>h.index-y.index),a.forEach(h=>{this.inputs.forEach(v=>{v.index>=h.index&&v.sync({index:v.index+1})});const y={id:O.UUID.uuid(),version:"1",createdAt:$().toDate(),author:"1",previousVersion:null,deleted:!1,type:r.InputMap,declaration:h.toJSON(),readsValue:null,defaultValue:null,index:h.index,name:null,description:null,parent:this.toReference()},f=b(y,this.project);f.setParent(this),f.initChildren(),f.addSelfToProject()}),this.inputs.sort((h,y)=>h.index-y.index);const{updated:o,added:l,removed:d}=this.removeUnrecognizedInputs();return e.push(...o),t.push(...l),i.push(...d),{updated:m(e),added:m(t),removed:m(i),self: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",r.Condition),u(Me,"USER_MANAGED_PARENT_TYPES",[...He,r.Project]),u(Me,"PARENT_TYPES",[...Me.USER_MANAGED_PARENT_TYPES]),u(Me,"MUTABLE_BASE_PROPERTIES",["operator"]),u(Me,"INMUTABLE_BASE_PROPERTIES",["id","version","type"]),u(Me,"BASE_PROPERTIES",[...Me.MUTABLE_BASE_PROPERTIES,...Me.INMUTABLE_BASE_PROPERTIES]),u(Me,"MUTABLE_META_PROPERTIES",["x","y"]),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",["calledBySuccess","calledByError","calledByEntry","parent"]),u(Me,"INMUTABLE_UPSTREAM_PROPERTIES",[]),u(Me,"UPSTREAM_PROPERTIES",[...Me.MUTABLE_UPSTREAM_PROPERTIES,...Me.INMUTABLE_UPSTREAM_PROPERTIES]),u(Me,"MUTABLE_DOWNSTREAM_PROPERTIES",["successCalls","errorCalls","inputsDeclarations","inputs"]),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 ci=Me;function A7(n){var l;const s=i3(),e=n.toJSON();s.safeParse(e).success,(l=n.dataType)==null||l.validate(),n.inputs.forEach(d=>d.validate()),n.outputs.forEach(d=>d.validate()),n.internalCalls.forEach(d=>d.validate());const a=[...on(n)];if(n.id==="random-company-employee-test-variable-id"){const d=le({id:`${n.id}--${U.PropertyImplementsNonAbstact}`,message:`Property "${B(n,n.project)}" with id "${n.id}" implements a non-abstract property "${B(n,n.project)}" with id "${n.id}".`,issue:null,severity:E.Error,code:U.PropertyImplementsNonAbstact,entity:n});a.push(d.error)}if(n.id==="company-dto-variable-one-id"){const d=le({id:`${n.id}--${U.PropertyImplementsNonAbstact}`,message:`Property "${B(n,n.project)}" with id "${n.id}" implements a non-abstract property "${B(n,n.project)}" with id "${n.id}".`,issue:null,severity:E.Error,code:U.PropertyImplementsNonAbstact,entity:n});a.push(d.error)}const o=gp(n);return a.push(...o),xe(n.errors,a)}const be=class be extends ze{constructor(e,t){super(e);u(this,"initialData");u(this,"id");u(this,"name");u(this,"description",null);u(this,"required",!1);u(this,"constant",!1);u(this,"x");u(this,"y");u(this,"type",r.VariableDeclaration);u(this,"defaultValue",null);u(this,"dataType",null);u(this,"writesValues",[]);u(this,"readsValue",null);u(this,"inputs",[]);u(this,"outputs",[]);u(this,"calledBySuccess",[]);u(this,"calledByError",[]);u(this,"calledByEntry",[]);u(this,"successCalls",[]);u(this,"errorCalls",[]);u(this,"internalCalls",[]);u(this,"parent");u(this,"variableInstances",[]);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.constant=e.constant,this.required=e.required,this.x=e.x,this.y=e.y}static fromGenerationTarget(e,t){let i=t;if(e.parent){const f=P(e.parent);i=t.get(f)}const a=e.calledByEntry.map(f=>{const v=P(f);return t.get(v)}),o=e.calledBySuccess.map(f=>{const v=P(f);return t.get(v)}),l=e.calledByError.map(f=>{const v=P(f);return t.get(v)});let d=null;if(e.readsValue){const f=P(e.readsValue);d=t.get(f)}const h={id:e.id,version:"1",createdAt:$().toDate(),author:"1",previousVersion:null,deleted:!1,type:r.VariableDeclaration,name:e.name,defaultValue:null,description:e.description,constant:e.constant||!1,required:e.required||!1,calledByEntry:a,calledBySuccess:o,calledByError:l,dataType:null,errorCalls:[],successCalls:[],internalCalls:[],readsValue:d,inputs:[],outputs:[],writesValues:[],x:0,y:0,parent:i},y=b(h,t);return y.setParent(i),y.initChildren(),y}static validateGenerationTarget(e,t){let i=JSON.parse(JSON.stringify(e));const a=[],o=ft(i,{parent:{list:!1,types:[...dt,r.Project],optional:!0}},t);i=o.modifiedData;const l=op(i,t);return a.push(...o.errors,...l,...et(i)),{errors:a,modifiedData:i}}validateGeneratedUpdate(e){const t=[];let i=JSON.parse(JSON.stringify(e));const a=gs(i,this);return i=a.modifiedData,t.push(...a.errors),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. The 'parent' on a callable entity, is its scope. It scope is auto-calculated implicitly by the its caller.
86
86
  If an entity is called by another, they must be in the same scope, which means they have the same parent.
87
87
  Specifically for variables, their scope is also calculated from their value readers and value writters.
88
88
  You shouldn't have to manually update a 'parent' property. The equivalent result is to change its value readers, value writters, or callers.`,issue:null})),{errors:t,modifiedData:i}}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.readsValue){const a=P(this.initialData.readsValue),o=this.project.get(a);o&&(this.setValueWriter(o),e.push(o))}return this.initialData.calledByEntry.forEach(a=>{const o=P(a),l=this.project.get(o);l&&(this.addEntryCaller(l),e.push(l))}),this.initialData.calledBySuccess.forEach(a=>{const o=P(a),l=this.project.get(o);l&&(this.addSuccessCaller(l),e.push(l))}),this.initialData.calledByError.forEach(a=>{const o=P(a),l=this.project.get(o);l&&(this.addErrorCaller(l),e.push(l))}),ln.hydrateReadsValue(this),{updated:m(e),added:m(t),removed:m(i),self:this}}afterAllChildrenInitialized(){const e=[],t=[],i=[];return this.initialized=!0,this.generateUnusedInputs(),this.generateUnusedOutputs(),this.generateUnusedInternalCalls(),(!this.dataType||this.dataType.inferred)&&this.inferDataTypeAndSyncInstancesInputsAndOutputs(),{updated:m(e),added:m(t),removed:m(i),self:this}}addSelfToProject(){const e=[this],t=[],i=[];return this.parent===this.project&&this.project.addVariableDeclaration(this),this.readsValue&&(this.readsValue.addValueReader(this),e.push(this.readsValue)),this.writesValues.forEach(a=>{a.setValueWriter(this),e.push(a)}),this.successCalls.forEach(a=>{a.addSuccessCaller(this),e.push(a)}),this.errorCalls.forEach(a=>{a.addErrorCaller(this),e.push(a)}),this.calledBySuccess.forEach(a=>{a.addSuccessCall(this),e.push(a)}),this.calledByError.forEach(a=>{a.addErrorCall(this),e.push(a)}),this.calledByEntry.forEach(a=>{a.addCall(this),e.push(a)}),{updated:m(e),added:m(t),removed:m(i),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}get usedInputs(){return this.inputs.filter(e=>e.readsValue||e.defaultValue)}get unusedInputs(){return this.inputs.filter(e=>!e.readsValue&&!e.defaultValue)}get usedOutputs(){return this.outputs.filter(e=>e.writesValues.length)}get unusedOutputs(){return this.outputs.filter(e=>!e.writesValues.length)}get usedInternalCalls(){return this.internalCalls.filter(e=>!!e.calledBy.length)}get unusedInternalCalls(){return this.internalCalls.filter(e=>!e.calledBy.length)}removeInput(e){const t=this.inputs.findIndex(i=>i.id===e.id);return t>-1&&this.inputs.splice(t,1),this}addInput(e){return this.inputs.includes(e)?this:(this.inputs.push(e),this)}addOutput(e){return this.outputs.includes(e)?this:(this.outputs.push(e),this)}removeOutput(e){const t=this.outputs.findIndex(i=>i.id===e.id);return t>-1&&this.outputs.splice(t,1),this}addSuccessCaller(e){return this.calledBySuccess.find(t=>t.id===e.id)||this.calledBySuccess.push(e),this}addErrorCaller(e){return this.calledByError.find(t=>t.id===e.id)||this.calledByError.push(e),this}addEntryCaller(e){return this.calledByEntry.find(t=>t.id===e.id)||this.calledByEntry.push(e),this}addErrorCall(e){return this.errorCalls.find(t=>t.id===e.id)||this.errorCalls.push(e),this}addSuccessCall(e){return this.successCalls.find(t=>t.id===e.id)||this.successCalls.push(e),this}removeCall(e){const t=this.successCalls.findIndex(a=>a.id===e.id);t>-1&&this.successCalls.splice(t,1);const i=this.errorCalls.findIndex(a=>a.id===e.id);return i>-1&&this.errorCalls.splice(i,1),this}removeCaller(e){return this.calledBySuccess=this.calledBySuccess.filter(t=>t.id!==e.id),this.calledByError=this.calledByError.filter(t=>t.id!==e.id),this.calledByEntry=this.calledByEntry.filter(t=>t.id!==e.id),this}addValueReader(e){return this.writesValues.includes(e)?this:(this.writesValues.push(e),this)}removeValueReader(e){return this.writesValues=this.writesValues.filter(t=>t.id!==e.id),this}setParent(e){return this.parent=e,this}initChildren(){return this.initialized?this:(this.initialized=!0,this.initialData.defaultValue&&(this.defaultValue=b(this.initialData.defaultValue,this.project),this.defaultValue.setParent(this),this.defaultValue.initChildren()),this.initialData.dataType&&(this.dataType=b(this.initialData.dataType,this.project),this.dataType.setParent(this),this.dataType.initChildren()),Ps.initWritesValues(this,this.parent),ln.initReadsValue(this),this.successCalls=this.initialData.successCalls.map(e=>{const t=b(e,this.project);return t.addSuccessCaller(this),[r.BreakStatement,r.ContinueStatement].includes(t.type)?(t.setParent(this.parent.parent),t.initChildren()):t.type!==r.InternalCall&&(t.setParent(this.parent),t.initChildren()),t}),this.errorCalls=this.initialData.errorCalls.map(e=>{const t=b(e,this.project);return t.addErrorCaller(this),[r.BreakStatement,r.ContinueStatement].includes(t.type)?(t.setParent(this.parent.parent),t.initChildren()):t.type!==r.InternalCall&&(t.setParent(this.parent),t.initChildren()),t}),this.initialData.inputs.forEach(e=>{const t=b(e,this.project);return t.setParent(this),t.initChildren(),this.addInput(t),t}),this.initialData.outputs.forEach(e=>{const t=b(e,this.project);return t.setParent(this),t.initChildren(),this.addOutput(t),t}),this.initialData.internalCalls.forEach(e=>{if(e.type===r.GenericReference){const i=this.project.findSubscribedInstanceFromReference(e);if(!i)return;i.setParent(this),i.initChildren(),this.addInternalCall(i);return}const t=b(e,this.project);return t.setParent(this),t.initChildren(),this.addInternalCall(t),t}),this.afterAllChildrenInitialized(),this)}setValueWriter(e){return this.readsValue=e,this}removeValueWriter(){return this.readsValue=null,this}subscribe(){return this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}subscribeInstance(e){return this.variableInstances.includes(e)?this:(this.variableInstances.push(e),this)}removeInstance(e){return this.variableInstances=this.variableInstances.filter(t=>t.id!==e.id),this}getMasterInputWithValueWritterFromAllInstances(e){return m([...this.inputs,...this.variableInstances.flatMap(a=>a.inputs)]).find(a=>B(a,this.project)===B(e,this.project)&&!!a.readsValue)||e}inferDataTypeAndSyncInstancesInputsAndOutputs(){var i,a;if(!this.dataType){const o=b({id:O.UUID.uuid(),version:"1",createdAt:$().toDate(),author:"1",previousVersion:null,deleted:!1,type:r.DataType,isList:!1,andChildrenGroup:null,orChildrenGroup:null,asType:!1,entity:null,like:!0,inferred:!0,parent:this.toReference()},this.project);o.setParent(this),o.initChildren(),o.sync({inferred:!0,like:!0}),this.setDataType(o)}if(this.readsValue){const o=(i=this.readsValue.getDataType())==null?void 0:i.clone(this);return o&&(o.sync({inferred:!0,like:!0}),this.setDataType(o)),this}const e=m([...this.inputs,...this.variableInstances.flatMap(o=>o.inputs)]),t=[];return e.forEach(o=>{t.find(d=>B(d,this.project)===B(o,this.project))||t.push(o)}),t.length?((a=this.dataType)==null||a.inferFromInputs(t),this.dataType?(this.generateUnusedInputs(),this.generateUnusedOutputs(),this.variableInstances.forEach(o=>{o.generateUnusedInputs(),o.generateUnusedOutputs()}),this):this):this}sync(e){return super.sync(e),this.name=e.name||this.name,this.description=e.description||this.description,this.x=e.x||this.x,this.y=e.y||this.y,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 be.repository.load(this.id,...t),this}async create(e=L,...t){return await be.repository.create(this.toShallowJSON(),...t),this}async update(e=L,...t){return await be.repository.update(this.toShallowJSON(),...t),this}async delete(e=L,...t){return await be.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.readsValue&&(i.push(this.readsValue),this.readsValue.removeValueReader(this)),this.writesValues.forEach(o=>{i.push(o),o.readsValue=null}),this.inputs.forEach(o=>{const{affected:l,removed:d}=o.remove({ignoreUpstream:!0,seenEntities:t});i.push(...l),a.push(...d)}),this.outputs.forEach(o=>{const{affected:l,removed:d}=o.remove({ignoreUpstream:!0,seenEntities:t});i.push(...l),a.push(...d)}),this.successCalls.forEach(o=>{i.push(o),o.removeCaller(this)}),this.errorCalls.forEach(o=>{i.push(o),o.removeCaller(this)}),this.internalCalls.forEach(o=>{const{affected:l,removed:d}=o.remove({ignoreUpstream:!0,seenEntities:t});i.push(...l),a.push(...d)}),this.dataType){const{affected:o,removed:l}=this.dataType.remove({ignoreUpstream:!0,seenEntities:t});i.push(...o),a.push(...l)}return e||this.calledBy.forEach(o=>{i.push(o),o.removeCall(this)}),{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.readsValue&&(t.push(this.readsValue),this.readsValue.addValueReader(this)),this.writesValues.forEach(i=>{t.push(i),i.setValueWriter(this)}),this.inputs.forEach(i=>{const{affected:a}=i.restore({seenEntities:e});t.push(...a)}),this.outputs.forEach(i=>{const{affected:a}=i.restore({seenEntities:e});t.push(...a)}),this.successCalls.forEach(i=>{t.push(i),i.addSuccessCaller(this)}),this.errorCalls.forEach(i=>{t.push(i),i.addErrorCaller(this)}),this.internalCalls.forEach(i=>{const{affected:a}=i.restore({seenEntities:e});t.push(...a)}),this.dataType){const{affected:i}=this.dataType.restore({seenEntities:e});t.push(...i)}return this.calledBySuccess.forEach(i=>{t.push(i),i.addSuccessCall(this)}),this.calledByError.forEach(i=>{t.push(i),i.addErrorCall(this)}),this.calledByEntry.forEach(i=>{t.push(i),i.addCall(this)}),{affected:m(t),self:this}}toFlat(e=new Set){var i,a,o;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))||[],...((o=this.readsValue)==null?void 0:o.toFlat(e))||[],...this.writesValues.flatMap(l=>l.toFlat(e)),...this.successCalls.flatMap(l=>l.toFlat(e)),...this.errorCalls.flatMap(l=>l.toFlat(e)),...this.inputs.flatMap(l=>l.toFlat(e)),...this.outputs.flatMap(l=>l.toFlat(e)),...this.internalCalls.flatMap(l=>l.toFlat(e)),...this.calledBy.flatMap(l=>l.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))||[],...this.writesValues.flatMap(o=>o.toFlatIds(e)),...this.successCalls.flatMap(o=>o.toFlatIds(e)),...this.errorCalls.flatMap(o=>o.toFlatIds(e)),...this.inputs.flatMap(o=>o.toFlatIds(e)),...this.outputs.flatMap(o=>o.toFlatIds(e)),...this.internalCalls.flatMap(o=>o.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,constant:this.constant,required:this.required,defaultValue:((t=this.defaultValue)==null?void 0:t.toJSON(e))||null,dataType:((i=this.dataType)==null?void 0:i.toJSON(e))||null,readsValue:((a=this.readsValue)==null?void 0:a.toReference())||null,writesValues:this.writesValues.map(o=>o.toJSON(e)),inputs:this.inputs.map(o=>o.toJSON(e)),outputs:this.outputs.map(o=>o.toJSON(e)),successCalls:this.successCalls.map(o=>o.toJSON(e)),errorCalls:this.errorCalls.map(o=>o.toJSON(e)),internalCalls:this.internalCalls.map(o=>o.toJSON(e)),calledBySuccess:this.calledBySuccess.map(o=>o.toReference()),calledByError:this.calledByError.map(o=>o.toReference()),calledByEntry:this.calledByEntry.map(o=>o.toReference()),parent:this.parent.toReference(),x:this.x,y:this.y})}toJSONClone(e=F){var i,a,o,l,d,h,y,f;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||it(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,name:this.name,description:this.description,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,readsValue:((f=this.readsValue)==null?void 0:f.toReference({seenEntityMaps:e.seenEntityMaps}))||null,writesValues:this.writesValues.map(v=>v.toJSONClone({...e,newId:null})),inputs:this.inputs.map(v=>v.toJSONClone({...e,newId:null})),outputs:this.outputs.map(v=>v.toJSONClone({...e,newId:null})),successCalls:this.successCalls.map(v=>v.toJSONClone({...e,newId:null})),errorCalls:this.errorCalls.map(v=>v.toJSONClone({...e,newId:null})),internalCalls:this.internalCalls.map(v=>this.calledBy.length||this.readsValue?v.toJSONClone({...e,newId:null}):v.toReference({seenEntityMaps:e.seenEntityMaps})),calledBySuccess:this.calledBySuccess.map(v=>v.toReference({seenEntityMaps:e.seenEntityMaps})),calledByError:this.calledByError.map(v=>v.toReference({seenEntityMaps:e.seenEntityMaps})),calledByEntry:this.calledByEntry.map(v=>v.toReference({seenEntityMaps:e.seenEntityMaps})),parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps}),x:this.x,y:this.y})}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+"--"+O.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,name:this.name,description:this.description,required:this.required,constant:this.constant,x:this.x,y:this.y,defaultValue:((a=this.defaultValue)==null?void 0:a.toReference(e))||null,dataType:((o=this.dataType)==null?void 0:o.toReference(e))||null,readsValue:((l=this.readsValue)==null?void 0:l.toReference(e))||null,writesValues:this.writesValues.map(d=>d.toReference(e)),inputs:this.inputs.map(d=>d.toReference(e)),outputs:this.outputs.map(d=>d.toReference(e)),successCalls:this.successCalls.map(d=>d.toReference(e)),errorCalls:this.errorCalls.map(d=>d.toReference(e)),calledBySuccess:this.calledBySuccess.map(d=>d.toReference(e)),calledByError:this.calledByError.map(d=>d.toReference(e)),calledByEntry:this.calledByEntry.map(d=>d.toReference(e)),internalCalls:this.internalCalls.map(d=>d.toReference(e)),parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){var i,a;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))||[],...this.writesValues.flatMap(o=>o.toFlatJSON(e)),...this.successCalls.flatMap(o=>o.toFlatJSON(e)),...this.errorCalls.flatMap(o=>o.toFlatJSON(e)),...this.inputs.flatMap(o=>o.toFlatJSON(e)),...this.outputs.flatMap(o=>o.toFlatJSON(e)),...this.internalCalls.flatMap(o=>o.toFlatJSON(e))])}toGenerationTarget(){const e=this.parent.type===r.Project?void 0:this.parent.id;return{id:this.id,type:this.type,name:this.name,description:this.description,calledByEntry:this.calledByEntry.map(t=>t.id),calledBySuccess:this.calledBySuccess.map(t=>t.id),calledByError:this.calledByError.map(t=>t.id),parent:e}}toFlatGenerationTarget(e=new Set){var i,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))||[],...this.writesValues.flatMap(o=>o.toFlatGenerationTarget(e)),...this.successCalls.flatMap(o=>o.toFlatGenerationTarget(e)),...this.errorCalls.flatMap(o=>o.toFlatGenerationTarget(e)),...this.inputs.flatMap(o=>o.toFlatGenerationTarget(e)),...this.outputs.flatMap(o=>o.toFlatGenerationTarget(e)),...this.internalCalls.flatMap(o=>o.toFlatGenerationTarget(e))])}clearErrors(){var e,t;return this.errors=[],this.inputs.forEach(i=>i.clearErrors()),this.outputs.forEach(i=>i.clearErrors()),this.successCalls.forEach(i=>i.clearErrors()),this.errorCalls.forEach(i=>i.clearErrors()),this.internalCalls.forEach(i=>i.clearErrors()),(e=this.dataType)==null||e.clearErrors(),(t=this.defaultValue)==null||t.clearErrors(),this}validate(){const e=A7(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){var t,i,a;return[...this.errors,...((t=this.defaultValue)==null?void 0:t.getErrors())||[],...((i=this.dataType)==null?void 0:i.getErrors())||[],...this.inputs.flatMap(o=>o.getErrors()),...this.internalCalls.flatMap(o=>o.getErrors()),...this.outputs.flatMap(o=>o.getErrors()),...((a=this.readsValue)==null?void 0:a.getErrors())||[]]}getShallowErrors(){return this.errors}getDefaultValue(){return this.defaultValue||null}setDefaultValue(e){return this.defaultValue=e,this}clone(e=null,t=null,i=!0){var A,M,H,W,_;let a=at(e,this);const o=this.toJSON(),l=t||O.UUID.uuid();o.inputs=[];const d=l.split("-id"),h=d[d.length-1||0]||l;o.id=l;const y=tt(o,a);e?y.setParent(e):y.setParent(this.parent),i&&y.subscribe(),y.initChildren();const f=(A=this.dataType)==null?void 0:A.clone(y,O.UUID.uuid(),i);y.dataType=f||null;const v=(M=this.defaultValue)==null?void 0:M.clone(y,h+"-default-value-id",i);y.defaultValue=v||null;const R=(H=this.inputs)==null?void 0:H.map((Q,se)=>Q.clone(y,h+"-input-map-"+se+"-id",i));y.inputs=R;const I=(W=this.outputs)==null?void 0:W.map((Q,se)=>Q.clone(y,h+"-output-map-"+se+"-id",i));y.outputs=I;const D=(_=this.internalCalls)==null?void 0:_.map((Q,se)=>Q.clone(y,h+"-internal-call-"+se+"-id",i));return y.internalCalls=D,y}addInternalCall(e){return this.internalCalls.find(t=>t===e)||this.internalCalls.push(e),this}createInstance(e=this.project,t={}){const i={id:t.id||O.UUID.uuid(),version:t.version||"1",createdAt:$().toDate(),author:"1",previousVersion:null,deleted:!1,type:r.VariableInstance,parent:e.toReference(),defaultValue:t.defaultValue||null,successCalls:t.successCalls||[],errorCalls:t.errorCalls||[],inputs:t.inputs||[],outputs:t.outputs||[],writesValues:t.writesValues||[],internalCalls:t.internalCalls||[],readsValue:t.readsValue||null,calledByEntry:t.calledByEntry||[],calledBySuccess:t.calledBySuccess||[],calledByError:t.calledByError||[],declaration:this.toJSON(),x:0,y:0},a=b(i,this.project);return a.setParent(e),a.initChildren(),e===this.project&&this.project.addVariableInstance(a),a}generateUnusedInputs(){if(this.dataType)if(this.dataType.entity){if([r.DefinitionEntity,r.PrimitiveEntity,r.BuiltInBaseEntity].includes(this.dataType.entity.type)){const e=[...this.dataType.entity.properties];e.filter(o=>!o.getDataType()).forEach(o=>{const l=this.inputs.find(y=>B(y,this.project)===B(o,this.project));if(!l)return;const d=this.getMasterInputWithValueWritterFromAllInstances(l);if(!d)return;const h=Gr(d);o.setDataType(h),l.setDeclaration(o)}),e.filter(o=>!this.inputs.find(l=>{var d;return((d=l.declaration)==null?void 0:d.id)===o.id})).forEach(o=>{const l={id:O.UUID.uuid(),version:"1",createdAt:$().toDate(),author:"1",previousVersion:null,deleted:!1,type:r.InputMap,parent:this.toReference(),name:null,description:null,declaration:o,defaultValue:null,index:o.index,readsValue:null},d=b(l,this.project);return d.setParent(this),d.initChildren(),d.suggestion=!0,this.addInput(d),d}),this.inputs.filter(o=>!o.declaration).forEach(o=>{const l=e.find(d=>B(d,this.project)===B(o,this.project));l&&o.setDeclaration(l)})}}else return[];else return[];return[]}generateUnusedOutputs(){if(this.dataType)if(this.dataType.entity){if([r.DefinitionEntity,r.PrimitiveEntity,r.BuiltInBaseEntity].includes(this.dataType.entity.type))return[...this.dataType.entity.properties].filter(i=>!this.outputs.find(a=>a.declaration===i)).map(i=>{const a={id:O.UUID.uuid(),version:"1",createdAt:$().toDate(),author:"1",previousVersion:null,deleted:!1,type:r.OutputMap,defaultValue:null,parent:this.toReference(),declaration:i,index:i.index,writesValues:[]},o=b(a,this.project);return o.setParent(this),o.initChildren(),o.suggestion=!0,this.addOutput(o),o})}else return[];else return[];return[]}generateUnusedInternalCalls(){if(this.dataType)if(this.dataType.entity){if([r.DefinitionEntity,r.PrimitiveEntity,r.BuiltInBaseEntity].includes(this.dataType.entity.type))return[...this.dataType.entity.getAllInteractiveMethods()].filter(i=>!this.internalCalls.find(o=>{var d,h,y,f,v;return(((d=o.declaration)==null?void 0:d.id)||((y=(h=o.initialData)==null?void 0:h.declaration)==null?void 0:y.entityId)||((v=(f=o.initialData)==null?void 0:f.declaration)==null?void 0:v.id))===i.id})).map(i=>{const a=i.createInternalCall(this);return a.suggestion=!0,this.addInternalCall(a),a})}else return[];else return[];return[]}setDataType(e){return this.dataType=e,this}removeDataType(){return this.dataType=null,this}getDataType(){return(!this.dataType||this.dataType.inferred)&&this.inferDataTypeAndSyncInstancesInputsAndOutputs(),this.dataType||null}getUnusedInputs(){return this.inputs.filter(e=>e.suggestion||!e.readsValue&&!e.defaultValue)}getUnusedOutputs(){return this.outputs.filter(e=>e.suggestion||!e.writesValues.length)}getUsedInputs(){return this.inputs.filter(e=>!e.suggestion&&(e.readsValue||e.defaultValue))}getUsedOutputs(){return this.outputs.filter(e=>!e.suggestion&&e.writesValues.length)}};u(be,"repository",{create:async(e,...t)=>e,update:async(e,...t)=>e,delete:async(e,...t)=>{},load:async(e,...t)=>null}),u(be,"type",r.VariableDeclaration),u(be,"USER_MANAGED_PARENT_TYPES",[...dt,r.Project]),u(be,"PARENT_TYPES",[...be.USER_MANAGED_PARENT_TYPES]),u(be,"MUTABLE_BASE_PROPERTIES",["name","description"]),u(be,"INMUTABLE_BASE_PROPERTIES",["id","type","version"]),u(be,"BASE_PROPERTIES",[...be.MUTABLE_BASE_PROPERTIES,...be.INMUTABLE_BASE_PROPERTIES]),u(be,"MUTABLE_META_PROPERTIES",[...be.MUTABLE_BASE_PROPERTIES,"x","y"]),u(be,"INMUTABLE_META_PROPERTIES",[...be.INMUTABLE_BASE_PROPERTIES]),u(be,"META_PROPERTIES",[...be.MUTABLE_META_PROPERTIES,...be.INMUTABLE_META_PROPERTIES]),u(be,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry","readsValue"]),u(be,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","dataType"]),u(be,"UPSTREAM_PROPERTIES",[...be.MUTABLE_UPSTREAM_PROPERTIES,...be.INMUTABLE_UPSTREAM_PROPERTIES]),u(be,"MUTABLE_DOWNSTREAM_PROPERTIES",["writesValues","inputs","outputs","successCalls","errorCalls","internalCalls"]),u(be,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),u(be,"DOWNSTREAM_PROPERTIES",[...be.MUTABLE_DOWNSTREAM_PROPERTIES,...be.INMUTABLE_DOWNSTREAM_PROPERTIES]),u(be,"PROPERTIES",[...be.META_PROPERTIES,...be.UPSTREAM_PROPERTIES,...be.DOWNSTREAM_PROPERTIES]);let pi=be;function D7(n){const s=d3(),e=n.toJSON();s.safeParse(e).success,n.inputs.forEach(l=>l.validate()),n.outputs.forEach(l=>l.validate()),n.internalCalls.forEach(l=>l.validate());const a=[...on(n)];if(n.id==="exec-sequentially-result-variable-id"){const l=le({id:`${n.id}--${U.PropertyImplementsNonAbstact}`,message:`Property "${B(n,n.project)}" with id "${n.id}" implements a non-abstract property "${B(n,n.project)}" with id "${n.id}".`,issue:null,severity:E.Error,code:U.PropertyImplementsNonAbstact,entity:n});a.push(l.error)}const o=gp(n);return a.push(...o),xe(n.errors,a)}const Ie=class Ie extends ze{constructor(e,t){super(e);u(this,"initialData");u(this,"id");u(this,"x");u(this,"y");u(this,"type",r.VariableInstance);u(this,"defaultValue",null);u(this,"writesValues",[]);u(this,"readsValue",null);u(this,"declaration");u(this,"inputs",[]);u(this,"outputs",[]);u(this,"calledBySuccess",[]);u(this,"calledByError",[]);u(this,"calledByEntry",[]);u(this,"successCalls",[]);u(this,"errorCalls",[]);u(this,"internalCalls",[]);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.x=e.x,this.y=e.y}static fromGenerationTarget(e,t){let i=t;if(e.parent){const R=P(e.parent);i=t.get(R)}const a=P(e.declaration),o=t.get(a),l=e.calledByEntry.map(R=>{const I=P(R);return t.get(I)}),d=e.calledBySuccess.map(R=>{const I=P(R);return t.get(I)}),h=e.calledByError.map(R=>{const I=P(R);return t.get(I)});let y=null;if(e.readsValue){const R=P(e.readsValue);y=t.get(R)}const f={id:e.id,version:"1",createdAt:$().toDate(),author:"1",previousVersion:null,deleted:!1,type:r.VariableInstance,declaration:o.toReference(),calledByEntry:l,calledBySuccess:d,calledByError:h,defaultValue:null,errorCalls:[],successCalls:[],internalCalls:[],readsValue:y,inputs:[],outputs:[],writesValues:[],x:0,y:0,parent:i},v=b(f,t);return v.setParent(i),v.initChildren(),v}static validateGenerationTarget(e,t){let i=JSON.parse(JSON.stringify(e));const a=[],o=ft(i,{parent:{list:!1,types:[...dt,r.Project],optional:!0},declaration:{list:!1,types:[r.VariableDeclaration]}},t);return i=o.modifiedData,a.push(...o.errors,...et(i)),{errors:a,modifiedData:i}}validateGeneratedUpdate(e){const t=[];let i=JSON.parse(JSON.stringify(e));const a=gs(i,this);return i=a.modifiedData,t.push(...a.errors),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. 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.6152",
3
+ "version": "0.0.6153",
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",