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

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.
@@ -40,7 +40,7 @@ Please provide a unique 'name' string.`,severity:D.Error,code:j.NameNotUniqueInS
40
40
  Please provide a unique 'name' string.`,severity:D.Error,code:j.NameNotUniqueInScope,issue:null}))}}return e}function Ec(i,s){const e=[];i.name||e.push(new P({id:`${i.id}--${j.EmptyName}`,message:`Entity with id "${i.id}" and type "${i.type}" has an empty name. Please provide a 'name' string.`,severity:D.Error,code:j.EmptyName,issue:null}));const t=B(i.parent);if(!t)e.push(new P({id:`${i.id}--parent-reference--${R.InvalidReferenceObjectStructure}`,message:`Reference object at 'parent' property for entity with id "${i.id}" and type "${i.type}" is not a valid reference. A reference needs to be a 'id' string of an existing entity in the project.`,severity:D.Error,code:R.InvalidReferenceObjectStructure,issue:null}));else{const r=s.get(t);if(!r)e.push(new P({id:`${i.id}--parent-reference--${R.ReferencedEntityNotFound}`,message:`The entity with id '${t}' that isn't yet found in the project. Perhaps it should be created first. Or perhaps the ID is incorrect.`,severity:D.Error,code:R.ReferencedEntityNotFound,issue:null}));else{const l=Sc(r).filter(o=>o.name===i.name);l.length&&e.push(new P({id:`${i.id}--${j.NameNotUniqueInScope}`,message:`Entity with id "${i.id}" and type "${i.type}" has a name "${i.name}" that is not unique among all inputs declared in the parent entity. Entity with id "${l[0].id}" has the same name.
41
41
  Please provide a unique 'name' string.`,severity:D.Error,code:j.NameNotUniqueInScope,issue:null}))}}return e}function Ic(i,s){const e=[];i.name||e.push(new P({id:`${i.id}--${j.EmptyName}`,message:`Entity with id "${i.id}" and type "${i.type}" has an empty name. Please provide a 'name' string.`,severity:D.Error,code:j.EmptyName,issue:null}));const t=B(i.parent);if(!t)e.push(new P({id:`${i.id}--parent-reference--${R.InvalidReferenceObjectStructure}`,message:`Reference object at 'parent' property for entity with id "${i.id}" and type "${i.type}" is not a valid reference. A reference needs to be a 'id' string of an existing entity in the project.`,severity:D.Error,code:R.InvalidReferenceObjectStructure,issue:null}));else{const r=s.get(t);if(!r)e.push(new P({id:`${i.id}--parent-reference--${R.ReferencedEntityNotFound}`,message:`The entity with id '${t}' that isn't yet found in the project. Perhaps it should be created first. Or perhaps the ID is incorrect.`,severity:D.Error,code:R.ReferencedEntityNotFound,issue:null}));else{const l=yP(r).filter(o=>o.name===i.name);l.length&&e.push(new P({id:`${i.id}--${j.NameNotUniqueInScope}`,message:`Entity with id "${i.id}" and type "${i.type}" has a name "${i.name}" that is not unique among all outputs declared in the parent entity. Entity with id "${l[0].id}" has the same name.
42
42
  Please provide a unique 'name' string.`,severity:D.Error,code:j.NameNotUniqueInScope,issue:null}))}}return e}function x7(i,s){switch(i.type){case n.DefinitionEntity:return hc(i,s);case n.FunctionDeclaration:return mc(i,s);case n.VariableDeclaration:return vc(i,s);case n.Property:return Tc(i,s);case n.ArgumentDeclaration:return Ec(i,s);case n.ReturnDeclaration:return Ic(i,s);default:return[]}}function J1(i,s,e){const r=`${Vl(i)}-${s}-id`;return e.instances[r]?I.UUID.uuid():r}function Rc(i,s){let e="",t=null;if(i.parent){const a=s.get(i.parent);a&&(t=a)}let r="";return t&&(r=`${Vl(F(t,s))}-`),e=`${r}${Vl(F(i,s))}-id`,s.instances[e]?I.UUID.uuid():e}function ct(i,s,e="uuid"){return e==="semantic"?J1(F(i,s),i.type,s):I.UUID.uuid()}function S7(i){var l;const s=u6(),e=i.toJSON();s.safeParse(e).success;const r=k7(i);(l=i.dataType)==null||l.validate();const a=[...r];if(i.id==="80c86e1b-caca-4ba5-9b1f-38f72d10e4a3"){const o=ye({id:`${i.id}--${q.PropertyImplementsNonAbstact}`,message:`Property "${F(i,i.project)}" with id "${i.id}" implements a non-abstract property "${F(i,i.project)}" with id "${i.id}".`,issue:null,severity:D.Error,code:q.PropertyImplementsNonAbstact,entity:i});a.push(o.error)}return a}function k7(i){const s=[];if(!i.implements)return s;const e=i.implements;if(!e.abstract){const r=ye({id:`${i.id}--${q.PropertyImplementsNonAbstact}`,message:`Property "${F(i,i.project)}" with id "${i.id}" implements a non-abstract property "${F(e,i.project)}" with id "${e.id}".`,issue:null,severity:D.Error,code:q.PropertyImplementsNonAbstact,entity:i});s.push(r.error)}if(i.static&&!e.static){const r=ye({id:`${i.id}--${q.NonStaticPropertyImplementsStatic}`,message:`Static property "${F(i,i.project)}" with id "${i.id}" implements a non-static property "${F(e,i.project)}" with id "${e.id}".`,issue:null,severity:D.Error,code:q.NonStaticPropertyImplementsStatic,entity:i});s.push(r.error)}if(!i.static&&e.static){const r=ye({id:`${i.id}--${q.StaticPropertyImplementsNonStatic}`,message:`Non-static property "${F(i,i.project)}" with id "${i.id}" implements a static property "${F(e,i.project)}" with id "${e.id}".`,issue:null,severity:D.Error,code:q.StaticPropertyImplementsNonStatic,entity:i});s.push(r.error)}if(!Ir(i.dataType,e.dataType)){const r=ye({id:`${i.id}--${q.PropertyImplementsIncompatibleType}`,message:`Property "${F(i,i.project)}" with id "${i.id}" implements a property "${F(e,i.project)}" with id "${e.id}" that has an incompatible data type.`,issue:null,severity:D.Error,code:q.PropertyImplementsIncompatibleType,entity:i});s.push(r.error)}return ze(i.errors,s)}function Z7(i,s){const e=[];if(i.parent){const r=s.get(i.parent);if(!r)e.push(new P({id:`${i.id}--${i.parent}--${R.ReferencedEntityNotFound}`,code:R.ReferencedEntityNotFound,severity:D.Error,message:`Entity of type "${i.type}" with id "${i.id}", is referencing an entity with id "${i.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=zi(r);if(a){const l=r!==a?`The entity of type '${i.type}' with id '${i.id}' have 'parent' with id '${i.parent}' because the entity belongs to a built-in '${a.type}' entity with id '${a.id}' (${F(a,r.project)}) higher up in the tree.`:`The entity of type '${i.type}' with id '${i.id}' have 'parent' with id '${i.parent}' because it is a built-in entity of type ${a.type}.`;e.push(new P({id:`${i.id}--${R.InvalidBuiltInEntityReference}`,code:R.InvalidBuiltInEntityReference,severity:D.Error,message:l,issue:null}))}else if(![n.DefinitionEntity].includes(r.type))e.push(new P({id:`${i.id}--${i.parent}--${R.InvalidParentReference}`,code:R.InvalidParentReference,severity:D.Error,message:`Entity of type "${i.type}" with id "${i.id}", has a parent reference that isn't pointing to an entity of type 'definition-entity'.`,issue:null}));else{const o=Wi(r).filter(d=>!d.interactive);if(o.length){let d=o.length>1?`The entity of type '${i.type}' with id '${i.id}' can't be added to the 'parent' entity with id '${r.id}' because it extends or implements multiple '${n.BuiltInBaseEntity}' entities that are non-interactive ("${ie(o.map(u=>F(u,u.project)),'", "','" and "')}").`:`The entity of type '${i.type}' with id '${i.id}' can't be added to the 'parent' entity with id '${r.id}' because it extends or implements a '${n.BuiltInBaseEntity}' entity that is non-interactive ("${F(o[0],o[0].project)}").`;d+=`
43
- ${Zi}`,e.push(new P({id:`${i.id}--${R.NonInteractiveEntityReferenced}`,code:R.NonInteractiveEntityReferenced,severity:D.Error,message:d,issue:null}))}else if(i.implements){const d=s.get(i.implements);if(i.id===i.implements)return e.push(new P({id:`${i.id}--${i.implements}--${R.SelfReference}`,code:R.SelfReference,severity:D.Error,message:`Entity of type "${i.type}" with id "${i.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 P({id:`${i.id}--${i.implements}--${R.ReferencedEntityNotFound}`,code:R.ReferencedEntityNotFound,severity:D.Error,message:`Entity of type "${i.type}" with id "${i.id}", is referencing an entity with id "${i.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 u=r.properties.find(h=>{var c;return((c=h.implements)==null?void 0:c.id)===i.implements});u?e.push(new P({id:`${i.id}--${j.PropertyOverwrite}`,code:j.PropertyOverwrite,severity:D.Error,message:`The property with id "${i.id}" is trying to implement the property with id "${i.implements}", but the parent entity already has a property with id '${u.id}' that implements the same base property.`,issue:null})):[n.Property].includes(d.type)?d.abstract||e.push(new P({id:`${i.id}--${i.implements}--${R.InvalidImplementsReference}`,code:R.InvalidImplementsReference,severity:D.Error,message:`Entity of type "${i.type}" with id "${i.id}", has an 'implements' reference that isn't pointing to an abstract entity.`,issue:null})):e.push(new P({id:`${i.id}--${i.implements}--${R.InvalidImplementsReference}`,code:R.InvalidImplementsReference,severity:D.Error,message:`Entity of type "${i.type}" with id "${i.id}", has an 'implements' reference that isn't pointing to an entity of type 'property'.`,issue:null}))}}}}}const t=Et(i,{},s);return e.push(...t.errors),e}class rt{constructor(s){f(this,"version");f(this,"previousVersion",null);f(this,"createdAt");f(this,"deleted",!1);f(this,"author");this.version=s.version,this.previousVersion=s.previousVersion,this.createdAt=T(s.createdAt).toISOString(),this.deleted=s.deleted,this.author=s.author}metaSync(s){this.deleted=s.deleted!==void 0?s.deleted:this.deleted}}var Ac=(i=>(i.Manual="manual",i.Automatic="automatic",i))(Ac||{}),A=(i=>(i.Added="added",i.Updated="updated",i.Removed="removed",i.Affected="affected",i))(A||{});class b{constructor(s,e,t,r,a=!1,l=""){f(this,"id",I.UUID.uuid());f(this,"seenEntities",[]);f(this,"added",{});f(this,"updated",{});f(this,"removed",{});f(this,"affected",{});f(this,"self",null);f(this,"author");f(this,"timestamp");f(this,"open",!0);f(this,"dirty",!0);f(this,"type","manual");f(this,"autoclose",!1);f(this,"autoCloseActionName","");f(this,"project");if(this.project=s,this.author=e||I.sessionAuthor||"",this.timestamp=t,this.self=r,this.autoclose=a,this.autoCloseActionName=l,this.autoclose&&!this.autoCloseActionName)throw new Error("Auto-close change-set must have an auto-close action name.")}get isEmpty(){return Object.keys(this.added).length===0&&Object.keys(this.updated).length===0&&Object.keys(this.removed).length===0}get isValid(){var s;return!(this.isEmpty&&this.self&&!this.affected[(s=this.self)==null?void 0:s.id])}get list(){return[...Object.values(this.added),...Object.values(this.updated),...Object.values(this.removed)]}get listAdded(){return Object.values(this.added)}get listUpdated(){return Object.values(this.updated)}get listRemoved(){return Object.values(this.removed)}get listAffected(){return Object.values(this.affected)}get addedIds(){return Object.keys(this.added)}get updatedIds(){return Object.keys(this.updated)}get removedIds(){return Object.keys(this.removed)}get affectedIds(){return Object.keys(this.affected)}discardOrphans(){const s=[...this.addedIds,...this.updatedIds],e=this.project.toFlatIds(),t=Cr(),r=e.filter(l=>!t.includes(l));s.filter(l=>!r.includes(l)).forEach(l=>{this.remove(l)})}captureAllChangesInVersionInstances(){[...this.addedIds,...this.updatedIds].forEach(e=>{const t=this.project.get(e);if(!t)throw new Error(`Entity with id "${e}" not found in the project state when capturing version for change-set.`);const r=this.get(e);t.version===r.version&&t.captureVersion()}),this.removedIds.forEach(e=>{const t=this.project.getDeleted(e);if(!t)throw new Error(`Entity with id "${e}" not found in the project state when capturing version for change-set.`);const r=this.get(e);t.version===r.version&&t.captureVersion()})}async attemptAutocloseAsync(s,e){var t;return this.autoclose&&this.autoCloseActionName&&this.autoCloseActionName===s&&(this.self&&e===((t=this.self)==null?void 0:t.id)||!this.self)&&await this.closeAsync(),this}async closeAsync(){return this.open=!1,!this.isValid&&this.self&&!this.added[this.self.id]&&!this.updated[this.self.id]&&this.removed[this.self.id],this.discardOrphans(),this.recursiveCaptureUpstreamVersions(),this.captureAllChangesInVersionInstances(),this.isEmpty?(console.warn(`Empty change-set (${this.id}) discarded upon closing.`),this.project.discardChangeSet(this),this):(await this.project.closeChangeSet(this),this)}attemptAutoclose(s,e){var t;return this.autoclose&&this.autoCloseActionName&&this.autoCloseActionName===s&&(this.self&&e===((t=this.self)==null?void 0:t.id)||!this.self)&&this.close(),this}recursiveCaptureUpstreamVersions(){[...this.addedIds,...this.updatedIds,...this.removedIds].forEach(e=>{const t=this.get(e),{added:r,updated:a,removed:l,affected:o}=t.recursiveCaptureUpstreamVersions(this.timestamp);for(const d of r)this.add(d,"added");for(const d of a)this.add(d,"updated");for(const d of l)this.add(d,"removed");for(const d of o)this.add(d,"affected")})}close(){if(!this.isValid&&this.self&&!this.added[this.self.id]&&!this.updated[this.self.id]&&this.removed[this.self.id],this.discardOrphans(),this.captureAllChangesInVersionInstances(),this.recursiveCaptureUpstreamVersions(),this.captureAllChangesInVersionInstances(),this.open=!1,this.isEmpty)return console.warn(`Empty change-set (${this.id}) discarded upon closing.`),this.project.discardChangeSet(this),this;if(this.added[this.project.id]&&this.updatedIds.length)throw new Error("No 'updated' entities should be present in the change-set when the project entity is in the 'added' list. New projects can only have newly added entities");if(this.added[this.project.id]&&this.removedIds.length)throw new Error("No 'removed' entities should be present in the change-set when the project entity is in the 'added' list. New projects can only have newly added entities");if(!this.updated[this.project.id]&&!this.added[this.project.id])throw new Error("Change-set must also have the project entity as 'updated' or 'added'. All changes must propagate upstream until the root project entity.");return this.project.closeChangeSet(this),this}get(s){return this.added[s]?this.added[s]:this.updated[s]?this.updated[s]:this.removed[s]?this.removed[s]:null}remove(s){return this.has(s)&&(delete this.added[s],delete this.updated[s],delete this.removed[s],delete this.affected[s],this.seenEntities=this.seenEntities.filter(e=>e!==s)),this}add(s,e){var l,o,d;if(!this.open||!this.dirty)return this;const t=Array.from(new Set([...this.project.getAllBuiltInIds(),...Cr()]));if(t.includes(s.id))return this;if(!Ql(s,{...this.project.instances,...this.project.builtInInstances}).every(u=>!t.includes(u)))return this;if(this.seenEntities.indexOf(s.id)===-1&&this.seenEntities.push(s.id),(e==="updated"||e==="removed")&&!this.has(s.id)){s.increaseVersion(this.timestamp);const{added:u,updated:h,removed:c,affected:v}=s.recursiveCaptureUpstreamVersions(this.timestamp);for(const E of u)this.add(E,"added");for(const E of h)this.add(E,"updated");for(const E of c)this.add(E,"removed");for(const E of v)this.add(E,"affected")}if(e==="added"&&!this.has(s.id)){const{added:u,updated:h,removed:c,affected:v}=s.recursiveCaptureUpstreamVersions(this.timestamp);for(const E of u)this.add(E,"added");for(const E of h)this.add(E,"updated");for(const E of c)this.add(E,"removed");for(const E of v)this.add(E,"affected")}if(e==="removed"){if(this.added[s.id])return delete this.added[s.id],this.seenEntities=this.seenEntities.filter(h=>h!==s.id),delete this.project.deletedInstances[s.id],this;this.updated[s.id]&&delete this.updated[s.id],this.affected[s.id]&&delete this.affected[s.id],s.captureVersion();const u=(l=s.knownVersions)==null?void 0:l.get(s.version);if(!u)throw Error(`Version ${s.version} should have a cached version instance but it wasn't found when adding entity to change-set`);this.removed[s.id]=u}if(e==="added"){if(this.removed[s.id])return this;this.updated[s.id]&&delete this.updated[s.id],this.affected[s.id]&&delete this.affected[s.id],s.captureVersion();const u=(o=s.knownVersions)==null?void 0:o.get(s.version);if(!u)throw Error(`Version ${s.version} should have a cached version instance but it wasn't found when adding entity to change-set`);this.added[s.id]=u}if(e==="updated"){if(this.removed[s.id])return this;if(this.added[s.id])return this;this.affected[s.id]&&delete this.affected[s.id],s.captureVersion();const u=(d=s.knownVersions)==null?void 0:d.get(s.version);if(!u)throw Error(`Version ${s.version} should have a cached version instance but it wasn't found when adding entity to change-set`);this.updated[s.id]=u}if(e==="affected"){if(this.removed[s.id])return this;if(this.added[s.id])return this;if(this.updated[s.id])return this;this.affected[s.id]=s}return this}toJSON(){const s={},e={},t={},r=new Set;for(const a of Object.values(this.added))s[a.id]=a.toShallowJSON();for(const a of Object.values(this.updated))e[a.id]=a.toShallowJSON();for(const a of Object.values(this.removed))t[a.id]=a.toShallowJSON();for(const a of Object.values(this.affected))r.add(a.id);return{added:s,updated:e,removed:t,affected:Array.from(r),self:this.self?this.self.toShallowJSON():null,seenEntities:this.seenEntities}}has(s){return!!this.added[s]||!!this.removed[s]||!!this.updated[s]||!!this.affected[s]}hasAdded(s){return!!this.added[s]}hasUpdated(s){return!!this.updated[s]}hasRemoved(s){return!!this.removed[s]}hasAffected(s){return!!this.affected[s]}}function q7(i){return new Set([...Object.keys(i.added),...Object.keys(i.updated),...Object.keys(i.removed),...Array.from(i.affected)])}var W1=(i=>(i.Implements="implements",i.DataTypeEntity="data-type-entity",i))(W1||{});const Ie=class Ie extends rt{constructor(e,t){super(e);f(this,"initialData");f(this,"id");f(this,"name");f(this,"description",null);f(this,"private");f(this,"abstract");f(this,"index");f(this,"static");f(this,"required");f(this,"constant",!1);f(this,"type",n.Property);f(this,"hidden",!1);f(this,"defaultValue",null);f(this,"dataType",null);f(this,"implements",null);f(this,"project");f(this,"errors",[]);f(this,"parent");f(this,"detachedDependents",{});f(this,"knownVersions",null);f(this,"activeVersion",!1);f(this,"initialized",!1);f(this,"startedInitialization",!1);f(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 r=B(e.parent),a=t.get(r);let l=null;if(e.implements){const u=B(e.implements);l=t.get(u)}const o={id:e.id,version:I.UUID.uuid(),createdAt:T().toISOString(),author:I.sessionAuthor,previousVersion:null,deleted:!1,name:e.name,type:n.Property,index:a.properties.length,private:e.private||!1,abstract:e.abstract||!1,static:e.static||!1,required:e.required||!1,constant:e.constant||!1,hidden:!1,description:e.description,defaultValue:null,implements:l,dataType:null,parent:a},d=C(o,t);return d.setParent(a,null),d.initChildren(null),d}static validateGenerationTarget(e,t){let r=JSON.parse(JSON.stringify(e));const a=[],l=Z7(r,t),o=Tc(r,t);return a.push(...l,...o,...ot(r)),{errors:a,modifiedData:r}}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 P({id:`${this.id}--${R.InvalidParentUpdate}`,code:R.InvalidParentUpdate,severity:D.Error,message:`Entity of type '${this.type}' with id '${this.id}' cannot have the 'parent' property updated, as it would mean moving the '${this.type}' entity to another parent entity.
43
+ ${Zi}`,e.push(new P({id:`${i.id}--${R.NonInteractiveEntityReferenced}`,code:R.NonInteractiveEntityReferenced,severity:D.Error,message:d,issue:null}))}else if(i.implements){const d=s.get(i.implements);if(i.id===i.implements)return e.push(new P({id:`${i.id}--${i.implements}--${R.SelfReference}`,code:R.SelfReference,severity:D.Error,message:`Entity of type "${i.type}" with id "${i.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 P({id:`${i.id}--${i.implements}--${R.ReferencedEntityNotFound}`,code:R.ReferencedEntityNotFound,severity:D.Error,message:`Entity of type "${i.type}" with id "${i.id}", is referencing an entity with id "${i.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 u=r.properties.find(h=>{var c;return((c=h.implements)==null?void 0:c.id)===i.implements});u?e.push(new P({id:`${i.id}--${j.PropertyOverwrite}`,code:j.PropertyOverwrite,severity:D.Error,message:`The property with id "${i.id}" is trying to implement the property with id "${i.implements}", but the parent entity already has a property with id '${u.id}' that implements the same base property.`,issue:null})):[n.Property].includes(d.type)?d.abstract||e.push(new P({id:`${i.id}--${i.implements}--${R.InvalidImplementsReference}`,code:R.InvalidImplementsReference,severity:D.Error,message:`Entity of type "${i.type}" with id "${i.id}", has an 'implements' reference that isn't pointing to an abstract entity.`,issue:null})):e.push(new P({id:`${i.id}--${i.implements}--${R.InvalidImplementsReference}`,code:R.InvalidImplementsReference,severity:D.Error,message:`Entity of type "${i.type}" with id "${i.id}", has an 'implements' reference that isn't pointing to an entity of type 'property'.`,issue:null}))}}}}}const t=Et(i,{},s);return e.push(...t.errors),e}class rt{constructor(s){f(this,"version");f(this,"previousVersion",null);f(this,"createdAt");f(this,"deleted",!1);f(this,"author");this.version=s.version,this.previousVersion=s.previousVersion,this.createdAt=T(s.createdAt).toISOString(),this.deleted=s.deleted,this.author=s.author}metaSync(s){this.deleted=s.deleted!==void 0?s.deleted:this.deleted}}var Ac=(i=>(i.Manual="manual",i.Automatic="automatic",i))(Ac||{}),A=(i=>(i.Added="added",i.Updated="updated",i.Removed="removed",i.Affected="affected",i))(A||{});class b{constructor(s,e,t,r,a=!1,l=""){f(this,"id",I.UUID.uuid());f(this,"seenEntities",[]);f(this,"added",{});f(this,"updated",{});f(this,"removed",{});f(this,"affected",{});f(this,"self",null);f(this,"author");f(this,"timestamp");f(this,"open",!0);f(this,"dirty",!0);f(this,"type","manual");f(this,"autoclose",!1);f(this,"autoCloseActionName","");f(this,"project");if(this.project=s,this.author=e||I.sessionAuthor||"",this.timestamp=t,this.self=r,this.autoclose=a,this.autoCloseActionName=l,this.autoclose&&!this.autoCloseActionName)throw new Error("Auto-close change-set must have an auto-close action name.")}get isEmpty(){return Object.keys(this.added).length===0&&Object.keys(this.updated).length===0&&Object.keys(this.removed).length===0}get isValid(){var s;return!(this.isEmpty&&this.self&&!this.affected[(s=this.self)==null?void 0:s.id])}get list(){return[...Object.values(this.added),...Object.values(this.updated),...Object.values(this.removed)]}get listAdded(){return Object.values(this.added)}get listUpdated(){return Object.values(this.updated)}get listRemoved(){return Object.values(this.removed)}get listAffected(){return Object.values(this.affected)}get addedIds(){return Object.keys(this.added)}get updatedIds(){return Object.keys(this.updated)}get removedIds(){return Object.keys(this.removed)}get affectedIds(){return Object.keys(this.affected)}discardOrphans(){const s=[...this.addedIds,...this.updatedIds],e=this.project.toFlatIds(),t=Cr(),r=e.filter(l=>!t.includes(l)),a=s.filter(l=>!r.includes(l));a.forEach(l=>{console.log("Discarding orphan entity from change-set",l),console.log("allIdsInProject",e),console.log("allUserManagedIdsInProject",r),console.log("shouldBePresentInProject",s),console.log("missingIdsInProject",a),this.remove(l)})}captureAllChangesInVersionInstances(){[...this.addedIds,...this.updatedIds].forEach(e=>{const t=this.project.get(e);if(!t)throw new Error(`Entity with id "${e}" not found in the project state when capturing version for change-set.`);const r=this.get(e);t.version===r.version&&t.captureVersion()}),this.removedIds.forEach(e=>{const t=this.project.getDeleted(e);if(!t)throw new Error(`Entity with id "${e}" not found in the project state when capturing version for change-set.`);const r=this.get(e);t.version===r.version&&t.captureVersion()})}async attemptAutocloseAsync(s,e){var t;return this.autoclose&&this.autoCloseActionName&&this.autoCloseActionName===s&&(this.self&&e===((t=this.self)==null?void 0:t.id)||!this.self)&&await this.closeAsync(),this}async closeAsync(){return!this.isValid&&this.self&&!this.added[this.self.id]&&!this.updated[this.self.id]&&this.removed[this.self.id],this.discardOrphans(),this.recursiveCaptureUpstreamVersions(),this.captureAllChangesInVersionInstances(),this.recursiveCaptureUpstreamVersions(),this.open=!1,this.isEmpty?(console.warn(`Empty change-set (${this.id}) discarded upon closing.`),this.project.discardChangeSet(this),this):(await this.project.closeChangeSet(this),this)}attemptAutoclose(s,e){var t;return this.autoclose&&this.autoCloseActionName&&this.autoCloseActionName===s&&(this.self&&e===((t=this.self)==null?void 0:t.id)||!this.self)&&this.close(),this}recursiveCaptureUpstreamVersions(){[...this.addedIds,...this.updatedIds,...this.removedIds].forEach(e=>{const t=this.get(e),{added:r,updated:a,removed:l,affected:o}=t.recursiveCaptureUpstreamVersions(this.timestamp);for(const d of r)this.add(d,"added");for(const d of a)this.add(d,"updated");for(const d of l)this.add(d,"removed");for(const d of o)this.add(d,"affected")})}close(){if(!this.isValid&&this.self&&!this.added[this.self.id]&&!this.updated[this.self.id]&&this.removed[this.self.id],this.discardOrphans(),this.captureAllChangesInVersionInstances(),this.recursiveCaptureUpstreamVersions(),this.captureAllChangesInVersionInstances(),this.open=!1,this.isEmpty)return console.warn(`Empty change-set (${this.id}) discarded upon closing.`),this.project.discardChangeSet(this),this;if(this.added[this.project.id]&&this.updatedIds.length)throw new Error("No 'updated' entities should be present in the change-set when the project entity is in the 'added' list. New projects can only have newly added entities");if(this.added[this.project.id]&&this.removedIds.length)throw new Error("No 'removed' entities should be present in the change-set when the project entity is in the 'added' list. New projects can only have newly added entities");if(!this.updated[this.project.id]&&!this.added[this.project.id])throw new Error("Change-set must also have the project entity as 'updated' or 'added'. All changes must propagate upstream until the root project entity.");return this.project.closeChangeSet(this),this}get(s){return this.added[s]?this.added[s]:this.updated[s]?this.updated[s]:this.removed[s]?this.removed[s]:null}remove(s){return this.has(s)&&(delete this.added[s],delete this.updated[s],delete this.removed[s],delete this.affected[s],this.seenEntities=this.seenEntities.filter(e=>e!==s)),this}add(s,e){var l,o,d;if(!this.open||!this.dirty)return this;const t=Array.from(new Set([...this.project.getAllBuiltInIds(),...Cr()]));if(t.includes(s.id))return this;if(!Ql(s,{...this.project.instances,...this.project.builtInInstances}).every(u=>!t.includes(u)))return this;if(this.seenEntities.indexOf(s.id)===-1&&this.seenEntities.push(s.id),(e==="updated"||e==="removed")&&!this.has(s.id)){s.increaseVersion(this.timestamp);const{added:u,updated:h,removed:c,affected:v}=s.recursiveCaptureUpstreamVersions(this.timestamp);for(const E of u)this.add(E,"added");for(const E of h)this.add(E,"updated");for(const E of c)this.add(E,"removed");for(const E of v)this.add(E,"affected")}if(e==="added"&&!this.has(s.id)){const{added:u,updated:h,removed:c,affected:v}=s.recursiveCaptureUpstreamVersions(this.timestamp);for(const E of u)this.add(E,"added");for(const E of h)this.add(E,"updated");for(const E of c)this.add(E,"removed");for(const E of v)this.add(E,"affected")}if(e==="removed"){if(this.added[s.id])return delete this.added[s.id],this.seenEntities=this.seenEntities.filter(h=>h!==s.id),delete this.project.deletedInstances[s.id],this;this.updated[s.id]&&delete this.updated[s.id],this.affected[s.id]&&delete this.affected[s.id],s.captureVersion();const u=(l=s.knownVersions)==null?void 0:l.get(s.version);if(!u)throw Error(`Version ${s.version} should have a cached version instance but it wasn't found when adding entity to change-set`);this.removed[s.id]=u}if(e==="added"){if(this.removed[s.id])return this;this.updated[s.id]&&delete this.updated[s.id],this.affected[s.id]&&delete this.affected[s.id],s.captureVersion();const u=(o=s.knownVersions)==null?void 0:o.get(s.version);if(!u)throw Error(`Version ${s.version} should have a cached version instance but it wasn't found when adding entity to change-set`);this.added[s.id]=u}if(e==="updated"){if(this.removed[s.id])return this;if(this.added[s.id])return this;this.affected[s.id]&&delete this.affected[s.id],s.captureVersion();const u=(d=s.knownVersions)==null?void 0:d.get(s.version);if(!u)throw Error(`Version ${s.version} should have a cached version instance but it wasn't found when adding entity to change-set`);this.updated[s.id]=u}if(e==="affected"){if(this.removed[s.id])return this;if(this.added[s.id])return this;if(this.updated[s.id])return this;this.affected[s.id]=s}return this}toJSON(){const s={},e={},t={},r=new Set;for(const a of Object.values(this.added))s[a.id]=a.toShallowJSON();for(const a of Object.values(this.updated))e[a.id]=a.toShallowJSON();for(const a of Object.values(this.removed))t[a.id]=a.toShallowJSON();for(const a of Object.values(this.affected))r.add(a.id);return{added:s,updated:e,removed:t,affected:Array.from(r),self:this.self?this.self.toShallowJSON():null,seenEntities:this.seenEntities}}has(s){return!!this.added[s]||!!this.removed[s]||!!this.updated[s]||!!this.affected[s]}hasAdded(s){return!!this.added[s]}hasUpdated(s){return!!this.updated[s]}hasRemoved(s){return!!this.removed[s]}hasAffected(s){return!!this.affected[s]}}function q7(i){return new Set([...Object.keys(i.added),...Object.keys(i.updated),...Object.keys(i.removed),...Array.from(i.affected)])}var W1=(i=>(i.Implements="implements",i.DataTypeEntity="data-type-entity",i))(W1||{});const Ie=class Ie extends rt{constructor(e,t){super(e);f(this,"initialData");f(this,"id");f(this,"name");f(this,"description",null);f(this,"private");f(this,"abstract");f(this,"index");f(this,"static");f(this,"required");f(this,"constant",!1);f(this,"type",n.Property);f(this,"hidden",!1);f(this,"defaultValue",null);f(this,"dataType",null);f(this,"implements",null);f(this,"project");f(this,"errors",[]);f(this,"parent");f(this,"detachedDependents",{});f(this,"knownVersions",null);f(this,"activeVersion",!1);f(this,"initialized",!1);f(this,"startedInitialization",!1);f(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 r=B(e.parent),a=t.get(r);let l=null;if(e.implements){const u=B(e.implements);l=t.get(u)}const o={id:e.id,version:I.UUID.uuid(),createdAt:T().toISOString(),author:I.sessionAuthor,previousVersion:null,deleted:!1,name:e.name,type:n.Property,index:a.properties.length,private:e.private||!1,abstract:e.abstract||!1,static:e.static||!1,required:e.required||!1,constant:e.constant||!1,hidden:!1,description:e.description,defaultValue:null,implements:l,dataType:null,parent:a},d=C(o,t);return d.setParent(a,null),d.initChildren(null),d}static validateGenerationTarget(e,t){let r=JSON.parse(JSON.stringify(e));const a=[],l=Z7(r,t),o=Tc(r,t);return a.push(...l,...o,...ot(r)),{errors:a,modifiedData:r}}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 P({id:`${this.id}--${R.InvalidParentUpdate}`,code:R.InvalidParentUpdate,severity:D.Error,message:`Entity of type '${this.type}' with id '${this.id}' cannot have the 'parent' property updated, as it would mean moving the '${this.type}' entity to another parent entity.
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 P({id:`${this.id}--${j.InvalidObjectStructure}`,code:j.InvalidObjectStructure,severity:D.Error,message:`Entity of type '${this.type}' with id '${this.id}' is not a value reading or writing entity.
45
45
  ${Ul}`,issue:null})),{errors:t,modifiedData:e}}subscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]||(this.detachedDependents[t.entity.id]=t)}),this}syncDependents(){const e=[],t=[],r=[],a=[];return Object.values(this.detachedDependents).forEach(l=>{const o=l.entity.afterAllChildrenInitialized();e.push(...o.updated),t.push(...o.added),r.push(...o.removed),a.push(...o.affected)}),{updated:p(e),added:p(t),removed:p(r),affected:p(a),self:this}}onDetachedDependencyRemoved(e,t,r){const a=[],l=[],o=[],d=[];return t==="implements"&&(this.setImplements(null,r),a.push(this)),{updated:p(a),added:p(l),removed:p(o),affected:p(d),self:this}}onDetachedDependencyRestored(e,t,r){const a=[],l=[],o=[],d=[];return t==="implements"&&(this.setImplements(e,r),a.push(this)),{updated:p(a),added:p(l),removed:p(o),affected:p(d),self:this}}subscribeToDependencies(){var e,t,r,a,l;return(t=(e=this.implements)==null?void 0:e.subscribeDependents)==null||t.call(e,[{entity:this,field:"implements"}]),(l=(a=(r=this.dataType)==null?void 0:r.entity)==null?void 0:a.subscribeDependents)==null||l.call(a,[{entity:this,field:"data-type-entity"}]),this}increaseVersion(e){if(e&&!T(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&T(e).isSame(T(this.createdAt))?this:(this.previousVersion=this.version,this.version=I.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new Ie(this,this.project);return e.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,e):new Map([[this.version,e]]),e.defaultValue=this.defaultValue,e.dataType=this.dataType,e.implements=this.implements,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],r=[],a=[],l=[];if(this.parent&&this.parent.type!==n.PrimitiveEntity&&this.parent.type!==n.BuiltInBaseEntity){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),r.push(...o.added),a.push(...o.removed)}return{updated:p(t),added:p(r),removed:p(a),affected:p(l),self:this}}async restoreVersion(e){var d;const t=[],r=[],a=[],l=[];if(this.version===e)return{updated:p(t),added:p(r),removed:p(a),affected:p(l),self:this};if(!this.knownVersions){const u=new Map;for(const[h,c]of this.knownVersions||new Map){if(u.set(h,c),c.activeVersion=!1,c.knownVersions)for(const[v,E]of c.knownVersions)u.set(v,E);c.knownVersions=null}}let o=(d=this.knownVersions)==null?void 0:d.get(e);if(!o){const u=await this.APILoadVersion({},e);if(!u)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new Ie(u,this.project)}return this.metaSync(o.toShallowJSON(),null),this.defaultValue=o.defaultValue,this.dataType=o.dataType,this.implements=o.implements,this.parent=o.parent,{updated:p(t),added:p(r),removed:p(a),affected:p(l),self:this}}hydrateAncestors(){const e=[],t=[],r=[],a=[];if(this.initialData.parent){const l=B(this.initialData.parent),o=this.project.get(l);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${Wt(this.type)} with id '${this.id}' has a parent reference "${l}" which is missing in the project`)}else throw new Error(`${Wt(this.type)} with id '${this.id}' is missing a parent reference`);if(this.initialData.implements){const l=B(this.initialData.implements),o=this.project.get(l);o&&(this.setImplements(o,null),e.push(o))}return{updated:p(e),added:p(t),removed:p(r),affected:p(a),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new b(this.project,"",T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],r=[],a=[],l=[];return this.initialized=!0,this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:p(t),added:p(r),removed:p(a),affected:p(l),self:this}}addSelfToProject(e=this.project.addChangeSet(new b(this.project,"",T().toISOString(),this,!0,"add-self-to-project"))){const t=[this],r=[],a=[],l=[];return this.parent.addProperty(this),t.push(this.parent),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:p(t),added:p(r),removed:p(a),affected:p(l),self:this}}setParent(e,t=this.project.addChangeSet(new b(this.project,"",T().toISOString(),this,!0,"set-parent"))){var r;return((r=this.parent)==null?void 0:r.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,A.Updated),t==null||t.attemptAutoclose("set-parent",this.id))),this}setImplements(e,t=this.project.addChangeSet(new b(this.project,"",T().toISOString(),this,!0,"set-implements"))){var r;return((r=this.implements)==null?void 0:r.id)!==(e==null?void 0:e.id)&&(this.implements=e,t&&(t==null||t.add(this,A.Updated),t==null||t.attemptAutoclose("set-implements",this.id))),this}initChildren(e=this.project.addChangeSet(new b(this.project,"",T().toISOString(),this,!0,"init-children"))){if(this.initialized||this.startedInitialization)return this;if(this.startedInitialization=!0,this.initialData.defaultValue&&(this.defaultValue=C(this.initialData.defaultValue,this.project),this.defaultValue.setParent(this,null),this.defaultValue.initChildren(e)),this.initialData.dataType){const t=C(this.initialData.dataType,this.project);t.setParent(this,null),t.initChildren(e),this.dataType=t}if(this.initialData.implements){const t=C(this.initialData.implements,this.project);this.setImplements(t,null)}return this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new b(this.project,"",T().toISOString(),this,!0,"meta-sync"))){const r=lt(this,e),a=this.toMeta();return this.name=e.name||a.name,this.description=e.description||a.description,this.abstract=e.abstract!==void 0?e.abstract:a.abstract,this.private=e.private!==void 0?e.private:a.private,this.index=e.index||(e.index!==0?a.index:0),this.static=e.static!==void 0?e.static:a.static,this.hidden=e.hidden!==void 0?e.hidden:a.hidden,this.constant=e.constant!==void 0?e.constant:a.constant,this.required=e.required!==void 0?e.required:a.required,super.metaSync(e),e.deleted===!0&&!a.deleted?t==null||t.add(this,A.Removed):e.deleted===!1&&a.deleted?t==null||t.add(this,A.Added):r&&(t==null||t.add(this,A.Updated)),t==null||t.attemptAutoclose("meta-sync",this.id),this}async APILoad(e=L,...t){return await Ie.repository.APILoad(this.id,...t),this}async APICreate(e=L,...t){return await Ie.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=L,...t){return await Ie.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=L,...t){return await Ie.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=L,...t){return await Ie.repository.APIClone(this.id,...t),this}async APILoadVersion(e=L,t,...r){return await Ie.repository.APILoadVersion(this.id,t,...r)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new b(this.project,"",T().toISOString(),this,!0,"remove-entity"))){const r=[],a=[],l=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(a.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(d=>{const{updated:u,removed:h,added:c}=d.entity.onDetachedDependencyRemoved(this,d.field,t);r.push(...u),a.push(...h),l.push(...c)}),this.defaultValue){const{updated:d,removed:u}=this.defaultValue.remove({ignoreUpstream:!0},t);r.push(...d),a.push(...u)}if(this.dataType){const{updated:d,removed:u}=this.dataType.remove({ignoreUpstream:!0},t);r.push(...d),a.push(...u)}return e||this.parent.type===n.DefinitionEntity&&(this.parent.removeProperty(this),r.push(this.parent)),t==null||t.attemptAutoclose("remove-entity",this.id),{added:p(l),updated:p(r),removed:p(a),affected:p(o),self:this}}restore({}={},e=this.project.addChangeSet(new b(this.project,"",T().toISOString(),this,!0,"restore-entity"))){const t=[],r=[],a=[],l=[];if(e!=null&&e.hasAdded(this.id))return e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),this.defaultValue){const{updated:o}=this.defaultValue.restore({},e);r.push(...o)}if(this.dataType){const{updated:o}=this.dataType.restore({},e);r.push(...o)}return this.parent.type===n.DefinitionEntity&&(this.parent.addProperty(this),r.push(this.parent)),e==null||e.attemptAutoclose("restore-entity",this.id),{added:p(t),updated:p(r),removed:p(a),affected:p(l),self:this}}toFlat(e=new Set){var r,a;return e.has(this.id)?[]:(e.add(this.id),[this,...((r=this.defaultValue)==null?void 0:r.toFlat(e))||[],...((a=this.dataType)==null?void 0:a.toFlat(e))||[],...this.parent.toFlat(e)])}toFlatIds(e=new Set){var r,a;return e.has(this.id)?[]:(e.add(this.id),[this.id,...((r=this.defaultValue)==null?void 0:r.toFlatIds(e))||[],...((a=this.dataType)==null?void 0:a.toFlatIds(e))||[],...this.parent.toFlatIds(e)])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,description:this.description,index:this.index,hidden:this.hidden,private:this.private,abstract:this.abstract,required:this.required,constant:this.constant,static:this.static,type:this.type,name:this.name}}toJSON(e=new Set){var t,r,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:((r=this.dataType)==null?void 0:r.toJSON(e))||null,implements:((a=this.implements)==null?void 0:a.toJSON(e))||null,parent:this.parent.toReference()})}toJSONClone(e=Z){var r,a,l,o,d,u,h;let t;return(r=e.seenEntityMaps)!=null&&r.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||ct(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(a=e.seenEntities)!=null&&a.has(t)||(l=e.seenEntities)!=null&&l.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(d=e.seenEntities)==null||d.add(this.id),{id:t,version:I.UUID.uuid(),createdAt:e.timestamp||T().toISOString(),author:I.sessionAuthor,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:((u=this.defaultValue)==null?void 0:u.toJSONClone({...e,newId:null}))||null,dataType:((h=this.dataType)==null?void 0:h.toJSONClone({...e,newId:null}))||null,implements:(()=>{var c;return this.implements&&this.project.getBuiltIn(this.implements.id)?this.implements.toJSON():((c=this.implements)==null?void 0:c.toJSONClone({...e,newId:null}))||null})(),parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps})})}toReference(e=Z){var r;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+I.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=Z){var r,a,l,o;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,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:((l=this.dataType)==null?void 0:l.toReference(e))||null,implements:((o=this.implements)==null?void 0:o.toReference(e))||null,parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){var r,a,l;return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...((r=this.defaultValue)==null?void 0:r.toFlatJSON(e))||[],...((a=this.dataType)==null?void 0:a.toFlatJSON(e))||[],...((l=this.implements)==null?void 0:l.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 r,a;return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...((r=this.defaultValue)==null?void 0:r.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=S7(this),this.errors.length,{success:!0,error:null,data:null}}getErrors(){var t,r;return[...this.errors,...((t=this.defaultValue)==null?void 0:t.getErrors())||[],...((r=this.dataType)==null?void 0:r.getErrors())||[]]}getShallowErrors(){return this.errors}clone(e=this.project.addChangeSet(new b(this.project,"",T().toISOString(),this,!0,"clone-entity")),t=null,r=null,a=!0){var E,O;let l=ft(t,this);const o=r||I.UUID.uuid();let d=t||this.parent;const u={hidden:!1,id:o,version:I.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:(e==null?void 0:e.author)||"1",previousVersion:null,deleted:!1,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:d},h=dt(u,l);a&&h.subscribe(),h.setParent(d,null),h.initChildren(e),e==null||e.add(h,A.Added);const c=((E=this.dataType)==null?void 0:E.clone(e,h,I.UUID.uuid(),a))||null;c&&h.setDataType(c);const v=(O=this.defaultValue)==null?void 0:O.clone(e,h,I.UUID.uuid(),a);return h.defaultValue=v||null,this.implements&&(h.implements=this.implements),h.addSelfToProject(null),e==null||e.attemptAutoclose("clone-entity",this.id),h}setDataType(e){return this.dataType=e,this}removeDataType(){return this.dataType=null,this}getDataType(e=this.project.addChangeSet(new b(this.project,"",T().toISOString(),this,!0,"get-data-type"))){return this.dataType}getDefaultValue(){return this.defaultValue}setDefaultValue(e){return this.defaultValue=e,this}};f(Ie,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>e,APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...r)=>null}),f(Ie,"type",n.Property),f(Ie,"USER_MANAGED_PARENT_TYPES",[n.DefinitionEntity]),f(Ie,"PARENT_TYPES",[...Ie.USER_MANAGED_PARENT_TYPES,n.PrimitiveEntity,n.BuiltInBaseEntity]),f(Ie,"MUTABLE_BASE_PROPERTIES",["name","description","private","abstract","static","required","constant"]),f(Ie,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),f(Ie,"BASE_PROPERTIES",[...Ie.MUTABLE_BASE_PROPERTIES,...Ie.INMUTABLE_BASE_PROPERTIES]),f(Ie,"MUTABLE_META_PROPERTIES",[...Ie.MUTABLE_BASE_PROPERTIES,"index"]),f(Ie,"INMUTABLE_META_PROPERTIES",[...Ie.INMUTABLE_BASE_PROPERTIES]),f(Ie,"META_PROPERTIES",[...Ie.MUTABLE_META_PROPERTIES,...Ie.INMUTABLE_META_PROPERTIES]),f(Ie,"MUTABLE_UPSTREAM_PROPERTIES",[]),f(Ie,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","implements"]),f(Ie,"UPSTREAM_PROPERTIES",[...Ie.MUTABLE_UPSTREAM_PROPERTIES,...Ie.INMUTABLE_UPSTREAM_PROPERTIES]),f(Ie,"MUTABLE_DOWNSTREAM_PROPERTIES",["dataType"]),f(Ie,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),f(Ie,"DOWNSTREAM_PROPERTIES",[...Ie.MUTABLE_DOWNSTREAM_PROPERTIES,...Ie.INMUTABLE_DOWNSTREAM_PROPERTIES]),f(Ie,"PROPERTIES",[...Ie.META_PROPERTIES,...Ie.UPSTREAM_PROPERTIES,...Ie.DOWNSTREAM_PROPERTIES]);let Bi=Ie;function J7(i){var a;const s=N6(),e=i.toJSON();s.safeParse(e).success,(a=i.dataType)==null||a.validate();const r=[];if(i.id==="iterate-over-employee-list-continue-statement-employee-dto-output-decl-id"){const l=ye({id:`${i.id}--${q.PropertyImplementsNonAbstact}`,message:`Property "${F(i,i.project)}" with id "${i.id}" implements a non-abstract property "${F(i,i.project)}" with id "${i.id}".`,issue:null,severity:D.Error,code:q.PropertyImplementsNonAbstact,entity:i});r.push(l.error)}return ze(i.errors,r)}var z1=(i=>(i.Implements="implements",i.DataTypeEntity="data-type-entity",i))(z1||{});const Re=class Re extends rt{constructor(e,t){super(e);f(this,"initialData");f(this,"id");f(this,"name");f(this,"description",null);f(this,"index");f(this,"required");f(this,"constant",!0);f(this,"isError");f(this,"type",n.ReturnDeclaration);f(this,"defaultValue",null);f(this,"dataType",null);f(this,"readsValue",null);f(this,"implements",null);f(this,"project");f(this,"errors",[]);f(this,"parent");f(this,"detachedDependents",{});f(this,"knownVersions",null);f(this,"activeVersion",!1);f(this,"initialized",!1);f(this,"startedInitialization",!1);f(this,"suggestion",!1);this.initialData=e,this.project=t,this.id=e.id,this.index=e.index,this.name=e.name,this.description=e.description,this.required=e.required,this.constant=!0,this.isError=e.isError}static fromGenerationTarget(e,t){const r=B(e.parent),a=t.get(r);let l=null;if(e.readsValue){const u=B(e.readsValue);l=t.get(u)}const o={id:e.id,version:I.UUID.uuid(),createdAt:T().toISOString(),author:I.sessionAuthor,previousVersion:null,deleted:!1,name:e.name,type:n.ReturnDeclaration,index:a.outputs.length,isError:!1,description:e.description,defaultValue:null,implements:null,required:e.required,constant:!0,readsValue:l,dataType:null,parent:a},d=C(o,t);return d.setParent(a,null),d.initChildren(null),d}static validateGenerationTarget(e,t){var d,u;let r=JSON.parse(JSON.stringify(e));const a=[],l=Et(r,{parent:{list:!1,types:[n.ReturnStatement,n.Search,n.BreakStatement,n.ContinueStatement]}},t),o=Ic(r,t);if(r=l.modifiedData,r.parent){const h=t.get(B(r.parent));if(h&&[n.BreakStatement,n.ContinueStatement].includes(h.type)){const c=h,v=c.parent,E=[...v.breakStatements.filter(w=>w.id!==h.id),...v.continueStatements.filter(w=>w.id!==h.id)];if(c.outputs.length)a.push(new P({id:`${r.id}--${j.NoOverlapWithImplementedSignature}`,code:j.NoOverlapWithImplementedSignature,severity:D.Error,message:`Entity of type '${n.ReturnDeclaration}' with id '${r.id}' cannot be added to the parent entity of type '${c.type}' with id '${c.id}'. This '${c.type}' already has return declarations.
46
46
  ${Vc}`,issue:null}));else{const w=(u=(d=E[0])==null?void 0:d.outputs[0])==null?void 0:u.name;w!==r.name&&a.push(new P({id:`${r.id}--${j.NoOverlapWithImplementedSignature}`,code:j.NoOverlapWithImplementedSignature,severity:D.Error,message:`Entity of type '${n.ReturnDeclaration}' with id '${r.id}' cannot be added to the parent entity of type '${c.type}' with id '${c.id}'. This new 'return-declaration' doesn't have the same name "${w}" as the return declarations on the other statements in the same scope.
@@ -91,7 +91,7 @@ ${Zi}`,a.push(new P({id:`${e.id}--${R.NonInteractiveEntityReferenced}`,code:R.No
91
91
  You can inspect the existing 'entity' field with the 'describe_entity' action. Like so:
92
92
  ${Jr({describe_entity:d.entity.id})}
93
93
  Alternatively you can update the parent data-type entity with 'update' action to remove the existing value of the field.`,issue:null}))}return a.push(...l.errors,...ot(r)),{errors:a,modifiedData:r}}syncOperationInstance(e,t){return{updated:[],added:[],removed:[],affected:[],self:e}}inferInputMapDataType(e,t=this.project.addChangeSet(new b(this.project,"",T().toISOString(),this,!0,"infer-input-map-data-type"))){const r=pc(e);return t==null||t.attemptAutoclose("infer-input-map-data-type",this.id),{updated:[],added:[],removed:[],affected:[],self:r}}inferOutputMapDataType(e,t=this.project.addChangeSet(new b(this.project,"",T().toISOString(),this,!0,"infer-output-map-data-type"))){const r=fc(e);return t==null||t.attemptAutoclose("infer-output-map-data-type",this.id),{updated:[],added:[],removed:[],affected:[],self:r}}validateGeneratedUpdate(e){const t=[];return e.parent&&t.push(new P({id:`${this.id}--${R.InvalidParentUpdate}`,code:R.InvalidParentUpdate,severity:D.Error,message:`Entity of type '${this.type}' with id '${this.id}' cannot have the 'parent' property updated, as it would mean moving the '${this.type}' entity to another parent entity.
94
- This is likely an incorrect strategy, either the '${this.type}' entity doesn't need to be updated or it should be deleted and a new one created in the desired parent.`,issue:null})),{errors:t,modifiedData:e}}subscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]||(this.detachedDependents[t.entity.id]=t)}),this}syncDependents(){const e=[],t=[],r=[],a=[];return Object.values(this.detachedDependents).forEach(l=>{const o=l.entity.afterAllChildrenInitialized();e.push(...o.updated),t.push(...o.added),r.push(...o.removed),a.push(...o.affected)}),{updated:p(e),added:p(t),removed:p(r),affected:p(a),self:this}}onDetachedDependencyRemoved(e,t,r){const a=[],l=[],o=[],d=[];return{updated:p(a),added:p(l),removed:p(o),affected:p(d),self:this}}onDetachedDependencyRestored(e,t,r){const a=[],l=[],o=[],d=[];return{updated:p(a),added:p(l),removed:p(o),affected:p(d),self:this}}subscribeToDependencies(){return this}increaseVersion(e){if(e&&!T(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&T(e).isSame(T(this.createdAt))?this:(this.previousVersion=this.version,this.version=I.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new Pe(this,this.project);return e.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,e):new Map([[this.version,e]]),e.inputs=this.inputs,e.outputs=this.outputs,e.error=this.error,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],r=[],a=[],l=[];if(this.parent&&this.parent.type!==n.BuiltInBaseEntity&&this.parent.type!==n.PrimitiveEntity){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),r.push(...o.added),a.push(...o.removed)}return{updated:p(t),added:p(r),removed:p(a),affected:p(l),self:this}}async restoreVersion(e){var d;const t=[],r=[],a=[],l=[];if(this.version===e)return{updated:p(t),added:p(r),removed:p(a),affected:p(l),self:this};if(!this.knownVersions){const u=new Map;for(const[h,c]of this.knownVersions||new Map){if(u.set(h,c),c.activeVersion=!1,c.knownVersions)for(const[v,E]of c.knownVersions)u.set(v,E);c.knownVersions=null}}let o=(d=this.knownVersions)==null?void 0:d.get(e);if(!o){const u=await this.APILoadVersion({},e);if(!u)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new Pe(u,this.project)}return this.metaSync(o.toShallowJSON(),null),this.inputs=o.inputs,this.outputs=o.outputs,this.error=o.error,this.parent=o.parent,{updated:p(t),added:p(r),removed:p(a),affected:p(l),self:this}}hydrateAncestors(){const e=[],t=[],r=[],a=[];if(this.initialData.parent){const l=B(this.initialData.parent),o=this.project.get(l);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw new Error(`${this.type} with id '${this.id}' must have a 'parent'`);return{updated:p(e),added:p(t),removed:p(r),affected:p(a),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new b(this.project,"",T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],r=[],a=[],l=[];return this.initialized=!0,this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:p(t),added:p(r),removed:p(a),affected:p(l),self:this}}addSelfToProject(e=this.project.addChangeSet(new b(this.project,"",T().toISOString(),this,!0,"add-self-to-project"))){const t=[this],r=[],a=[],l=[];return this.parent?(this.parent.type===n.DefinitionEntity?(this.parent.addAbstractMethod(this),t.push(this.parent)):this.parent.type===n.DataType&&(this.parent.setEntity(this),t.push(this.parent)),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:p(t),added:p(r),removed:p(a),affected:p(l),self:this}):(this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:p(t),added:p(r),removed:p(a),affected:p(l),self:this})}setParent(e,t=this.project.addChangeSet(new b(this.project,"",T().toISOString(),this,!0,"set-parent"))){var r;return((r=this.parent)==null?void 0:r.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,A.Updated),t==null||t.attemptAutoclose("set-parent",this.id))),this}initChildren(e=this.project.addChangeSet(new b(this.project,"",T().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.inputs=this.initialData.inputs.map(t=>{const r=C(t,this.project);return r.setParent(this,null),r.initChildren(e),r}),this.outputs=this.initialData.outputs.map(t=>{const r=C(t,this.project);return r.setParent(this,null),r.initChildren(e),r}),this.initialData.error&&(this.error=C(this.initialData.error,this.project),this.error.setParent(this,null),this.error.initChildren(e)),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this)}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new b(this.project,"",T().toISOString(),this,!0,"meta-sync"))){const r=lt(this,e),a=this.toMeta();return this.name=e.name||a.name,this.description=e.description||a.description,super.metaSync(e),e.deleted===!0&&!a.deleted?t==null||t.add(this,A.Removed):e.deleted===!1&&a.deleted?t==null||t.add(this,A.Added):r&&(t==null||t.add(this,A.Updated)),t==null||t.attemptAutoclose("meta-sync",this.id),this}async APILoad(e=L,...t){return await Pe.repository.APILoad(this.id,...t),this}async APICreate(e=L,...t){return await Pe.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=L,...t){return await Pe.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=L,...t){return await Pe.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=L,...t){return await Pe.repository.APIClone(this.id,...t),this}async APILoadVersion(e=L,t,...r){return await Pe.repository.APILoadVersion(this.id,t,...r)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new b(this.project,"",T().toISOString(),this,!0,"remove-entity"))){const r=[],a=[],l=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(a.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(d=>{const{updated:u,removed:h,added:c}=d.entity.onDetachedDependencyRemoved(this,d.field,t);r.push(...u),a.push(...h),l.push(...c)}),this.inputs.forEach(d=>{const u=d.remove({ignoreUpstream:!0},t);r.push(...u.updated),a.push(...u.removed)}),this.outputs.forEach(d=>{const u=d.remove({ignoreUpstream:!0},t);r.push(...u.updated),a.push(...u.removed)}),this.error){const d=this.error.remove({ignoreUpstream:!0},t);r.push(...d.updated),a.push(...d.removed)}return t==null||t.attemptAutoclose("remove-entity",this.id),{added:p(l),updated:p(r),removed:p(a),affected:p(o),self:this}}restore({}={},e=this.project.addChangeSet(new b(this.project,"",T().toISOString(),this,!0,"restore-entity"))){const t=[],r=[],a=[],l=[];if(e!=null&&e.hasAdded(this.id))return e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),this.inputs.forEach(o=>{const d=o.restore({},e);r.push(...d.updated)}),this.outputs.forEach(o=>{const d=o.restore({},e);r.push(...d.updated)}),this.error){const o=this.error.restore({},e);r.push(...o.updated)}return e==null||e.attemptAutoclose("restore-entity",this.id),{added:p(t),updated:p(r),removed:p(a),affected:p(l),self:this}}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.inputs.flatMap(r=>r.toFlat(e)),...this.outputs.flatMap(r=>r.toFlat(e))])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.inputs.flatMap(r=>r.toFlatIds(e)),...this.outputs.flatMap(r=>r.toFlatIds(e))])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,description:this.description,type:this.type,name:this.name}}toJSON(e=new Set){var t,r;return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,error:((t=this.error)==null?void 0:t.toJSON())||null,inputs:this.inputs.map(a=>a.toJSON()),outputs:this.outputs.map(a=>a.toJSON()),parent:((r=this.parent)==null?void 0:r.toReference())||null})}toJSONClone(e=Z){var r,a,l,o,d,u,h;let t;return(r=e.seenEntityMaps)!=null&&r.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||ct(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(a=e.seenEntities)!=null&&a.has(t)||(l=e.seenEntities)!=null&&l.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(d=e.seenEntities)==null||d.add(this.id),{id:t,version:I.UUID.uuid(),createdAt:e.timestamp||T().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,error:((u=this.error)==null?void 0:u.toJSONClone({...e,newId:null}))||null,inputs:this.inputs.map(c=>c.toJSONClone({...e,newId:null})),outputs:this.outputs.map(c=>c.toJSONClone({...e,newId:null})),parent:((h=this.parent)==null?void 0:h.toReference({seenEntityMaps:e.seenEntityMaps}))||null})}toReference(e=Z){var r;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+I.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=Z){var r,a,l;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,error:((a=this.error)==null?void 0:a.toReference(e))||null,inputs:this.inputs.map(o=>o.toReference(e)),outputs:this.outputs.map(o=>o.toReference(e)),parent:((l=this.parent)==null?void 0:l.toReference(e))||null}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.inputs.flatMap(r=>r.toFlatJSON(e)),...this.outputs.flatMap(r=>r.toFlatJSON(e))])}toGenerationTarget(){var e;return{id:this.id,name:this.name,description:this.description,type:this.type,parent:((e=this.parent)==null?void 0:e.id)||void 0}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...this.inputs.flatMap(r=>r.toFlatGenerationTarget(e)),...this.outputs.flatMap(r=>r.toFlatGenerationTarget(e))])}asFunctionDeclarationTransfer(e,t=this.project.addChangeSet(new b(this.project,"",T().toISOString(),this,!0,"implement-as-function-declaration"))){var d;const r=e||I.UUID.uuid(),a=I.UUID.uuid(),l=this.inputs.map((u,h)=>{var v;const c={id:I.UUID.uuid(),type:n.GenericReference,version:a,entityType:n.FunctionDeclaration,entityId:r};return{id:I.UUID.uuid(),version:I.UUID.uuid(),createdAt:(t==null?void 0:t.timestamp)||T().toISOString(),author:I.sessionAuthor,previousVersion:null,deleted:!1,type:n.ArgumentDeclaration,name:u.name,required:u.required,implements:u.toJSON(),constant:!0,writesValues:[],defaultValue:null,description:u.description,index:h,dataType:((v=u.dataType)==null?void 0:v.toJSONClone({timestamp:(t==null?void 0:t.timestamp)||T().toISOString()}))||null,parent:c}}),o=[];if(this.outputs.length){const u=this.outputs.map((E,O)=>{var V;const w={id:I.UUID.uuid(),type:n.GenericReference,entityId:r,version:a,entityType:n.ReturnStatement};return{id:I.UUID.uuid(),version:I.UUID.uuid(),createdAt:(t==null?void 0:t.timestamp)||T().toISOString(),author:I.sessionAuthor,previousVersion:null,deleted:!1,type:n.ReturnDeclaration,name:E.name,description:E.description,readsValue:null,constant:!0,required:E.required,defaultValue:null,implements:E.toJSON(),isError:!1,index:O,dataType:((V=E.dataType)==null?void 0:V.toJSONClone())||null,parent:w}}),h={id:I.UUID.uuid(),type:n.GenericReference,version:a,entityType:n.FunctionDeclaration,entityId:r},c={id:I.UUID.uuid(),type:n.GenericReference,version:a,entityType:n.FunctionDeclaration,entityId:r},v={id:I.UUID.uuid(),version:I.UUID.uuid(),createdAt:(t==null?void 0:t.timestamp)||T().toISOString(),author:I.sessionAuthor,previousVersion:null,deleted:!1,type:n.ReturnStatement,outputs:u,throws:null,calledBySuccess:[],calledByError:[],calledByEntry:[c],parent:h,x:0,y:0};o.push(v)}return t==null||t.attemptAutoclose("implement-as-function-declaration",this.id),{id:r,version:a,createdAt:(t==null?void 0:t.timestamp)||T().toISOString(),author:I.sessionAuthor,previousVersion:null,deleted:!1,type:n.FunctionDeclaration,name:this.name,description:this.description,inputs:l,calls:o,collapsed:!1,private:!1,implements:this.toJSON(),index:0,parent:((d=this.parent)==null?void 0:d.toReference())||null,x:0,y:0}}implementAsGlobalEvent(e=this.project.addChangeSet(new b(this.project,"",T().toISOString(),this,!0,"implement-as-global-event")),t,r){const a=t||this.project,l=r||I.UUID.uuid(),o=I.UUID.uuid(),d={id:l,version:o,createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:I.sessionAuthor,previousVersion:null,deleted:!1,type:n.GlobalEvent,name:this.name,description:this.description,inputs:[],calls:[],collapsed:!1,implements:this.toJSON(),parent:(a==null?void 0:a.toReference())||null,x:0,y:0},u=C(d,this.project);if(u.setParent(a,e),u.initChildren(e),e==null||e.add(u,A.Added),u.hydrateAncestors(),u.addSelfToProject(e),this.inputs.map((h,c)=>{var V;const v={id:I.UUID.uuid(),type:n.GenericReference,version:o,entityType:n.GlobalEvent,entityId:l},E={id:I.UUID.uuid(),version:I.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:I.sessionAuthor,previousVersion:null,deleted:!1,type:n.ArgumentDeclaration,name:h.name,required:h.required,implements:h.toJSON(),constant:!0,writesValues:[],defaultValue:null,description:h.description,index:c,dataType:null,parent:v},O=C(E,this.project);O.setParent(u,e),O.initChildren(e),e==null||e.add(O,A.Added),O.hydrateAncestors(),O.addSelfToProject(e);const w=((V=h.dataType)==null?void 0:V.clone(e,O))||null;w&&(e==null||e.add(w,A.Added)),O.setDataType(w)}),this.outputs.length){const h=I.UUID.uuid(),c=I.UUID.uuid(),v={id:I.UUID.uuid(),type:n.GenericReference,version:o,entityType:n.GlobalEvent,entityId:l},E={id:I.UUID.uuid(),type:n.GenericReference,version:o,entityType:n.GlobalEvent,entityId:l},O={id:h,version:c,createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:I.sessionAuthor,previousVersion:null,deleted:!1,type:n.ReturnStatement,outputs:[],throws:null,calledBySuccess:[],calledByError:[],calledByEntry:[E],parent:v,x:0,y:0},w=C(O,this.project);w.setParent(u,e),w.initChildren(e),e==null||e.add(w,A.Added),w.hydrateAncestors(),w.addSelfToProject(e),this.outputs.map((V,U)=>{var J;const G={id:I.UUID.uuid(),type:n.GenericReference,entityId:h,version:c,entityType:n.ReturnStatement},_={id:I.UUID.uuid(),version:I.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:I.sessionAuthor,previousVersion:null,deleted:!1,type:n.ReturnDeclaration,name:V.name,description:V.description,readsValue:null,constant:!0,required:V.required,defaultValue:null,implements:V.toJSON(),isError:!1,index:U,dataType:null,parent:G},$=C(_,this.project);$.setParent(w,e),$.initChildren(e),e==null||e.add($,A.Added),$.hydrateAncestors(),$.addSelfToProject(e);const k=((J=V.dataType)==null?void 0:J.clone(e,$))||null;k&&(e==null||e.add(k,A.Added)),$.setDataType(k)})}return e==null||e.attemptAutoclose("implement-as-function-declaration",this.id),u}implementAsFunctionDeclaration(e=this.project.addChangeSet(new b(this.project,"",T().toISOString(),this,!0,"implement-as-function-declaration")),t,r){const a=t||this.project,l=r||I.UUID.uuid(),o=I.UUID.uuid(),d={id:l,version:o,createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:I.sessionAuthor,previousVersion:null,deleted:!1,type:n.FunctionDeclaration,name:this.name,description:this.description,inputs:[],calls:[],collapsed:!1,private:!1,implements:this.toJSON(),index:0,parent:(a==null?void 0:a.toReference())||null,x:0,y:0},u=C(d,this.project);if(u.setParent(a,e),u.initChildren(e),e==null||e.add(u,A.Added),u.hydrateAncestors(),u.addSelfToProject(e),this.inputs.map((h,c)=>{var V;const v={id:I.UUID.uuid(),type:n.GenericReference,version:o,entityType:n.FunctionDeclaration,entityId:l},E={id:I.UUID.uuid(),version:I.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:I.sessionAuthor,previousVersion:null,deleted:!1,type:n.ArgumentDeclaration,name:h.name,required:h.required,implements:h.toJSON(),constant:!0,writesValues:[],defaultValue:null,description:h.description,index:c,dataType:null,parent:v},O=C(E,this.project);O.setParent(u,e),O.initChildren(e),e==null||e.add(O,A.Added),O.hydrateAncestors(),O.addSelfToProject(e);const w=((V=h.dataType)==null?void 0:V.clone(e,O))||null;w&&(e==null||e.add(w,A.Added)),O.setDataType(w)}),this.outputs.length){const h=I.UUID.uuid(),c=I.UUID.uuid(),v={id:I.UUID.uuid(),type:n.GenericReference,version:o,entityType:n.FunctionDeclaration,entityId:l},E={id:I.UUID.uuid(),type:n.GenericReference,version:o,entityType:n.FunctionDeclaration,entityId:l},O={id:h,version:c,createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:I.sessionAuthor,previousVersion:null,deleted:!1,type:n.ReturnStatement,outputs:[],throws:null,calledBySuccess:[],calledByError:[],calledByEntry:[E],parent:v,x:0,y:0},w=C(O,this.project);w.setParent(u,e),w.initChildren(e),e==null||e.add(w,A.Added),w.hydrateAncestors(),w.addSelfToProject(e),this.outputs.map((V,U)=>{var J;const G={id:I.UUID.uuid(),type:n.GenericReference,entityId:h,version:c,entityType:n.ReturnStatement},_={id:I.UUID.uuid(),version:I.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:I.sessionAuthor,previousVersion:null,deleted:!1,type:n.ReturnDeclaration,name:V.name,description:V.description,readsValue:null,constant:!0,required:V.required,defaultValue:null,implements:V.toJSON(),isError:!1,index:U,dataType:null,parent:G},$=C(_,this.project);$.setParent(w,e),$.initChildren(e),e==null||e.add($,A.Added),$.hydrateAncestors(),$.addSelfToProject(e);const k=((J=V.dataType)==null?void 0:J.clone(e,$))||null;k&&(e==null||e.add(k,A.Added)),$.setDataType(k)})}return e==null||e.attemptAutoclose("implement-as-function-declaration",this.id),u}implementAsLoop(e=this.project.addChangeSet(new b(this.project,"",T().toISOString(),this,!0,"implement-as-loop")),t,r){const a=t||this.project,l=r||I.UUID.uuid(),o=I.UUID.uuid(),d={id:l,version:o,createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:I.sessionAuthor,previousVersion:null,deleted:!1,type:n.Loop,declaration:this.toJSON(),inputs:[],outputs:[],error:null,process:null,successCalls:[],errorCalls:[],calledByEntry:[],calledByError:[],calledBySuccess:[],outputsDeclarations:[],body:null,x:0,y:0,parent:a.toReference()},u=C(d,this.project);return u.setParent(a,e),u.initChildren(e),e==null||e.add(u,A.Added),u.hydrateAncestors(),u.addSelfToProject(e),u.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("implement-as-loop",this.id),u}implementAsOperation(e=this.project.addChangeSet(new b(this.project,"",T().toISOString(),this,!0,"implement-as-operation")),t,r){const a=t||this.project,l=r||I.UUID.uuid(),o=I.UUID.uuid(),d={id:l,version:o,createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:I.sessionAuthor,previousVersion:null,deleted:!1,type:n.Operation,declaration:this.toJSON(),inputs:[],outputs:[],error:null,process:null,successCalls:[],errorCalls:[],calledByEntry:[],calledByError:[],calledBySuccess:[],x:0,y:0,parent:a.toReference()},u=C(d,this.project);return u.setParent(a,e),u.initChildren(e),e==null||e.add(u,A.Added),u.hydrateAncestors(),u.addSelfToProject(e),this.inputs.forEach((h,c)=>{const v={id:I.UUID.uuid(),version:I.UUID.uuid(),type:n.InputMap,createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:I.sessionAuthor,previousVersion:null,deleted:!1,name:null,description:null,declaration:h,defaultValue:null,readsValue:null,index:c,parent:{id:I.UUID.uuid(),type:n.GenericReference,entityId:l,version:o,entityType:n.Operation}},E=C(v,this.project);E.setParent(u,e),E.initChildren(e),e==null||e.add(E,A.Added),E.hydrateAncestors(),E.addSelfToProject(e)}),this.outputs.forEach((h,c)=>{const v={id:I.UUID.uuid(),version:I.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:I.sessionAuthor,previousVersion:null,deleted:!1,type:n.OutputMap,declaration:h,defaultValue:null,writesValues:[],index:c,parent:{id:I.UUID.uuid(),type:n.GenericReference,entityId:l,version:o,entityType:n.Operation}},E=C(v,this.project);E.setParent(u,e),E.initChildren(e),e==null||e.add(E,A.Added),E.hydrateAncestors(),E.addSelfToProject(e)}),u.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("implement-as-operation",this.id),u}implementAsCondition(e=this.project.addChangeSet(new b(this.project,"",T().toISOString(),this,!0,"implement-as-condition")),t,r){const a=t||this.project,l=r||I.UUID.uuid(),o=I.UUID.uuid(),d={id:l,version:o,createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:I.sessionAuthor,previousVersion:null,deleted:!1,type:n.Condition,declaration:this.toJSON(),inputs:[],successCalls:[],errorCalls:[],calledByEntry:[],calledByError:[],calledBySuccess:[],x:0,y:0,parent:a.toReference()},u=C(d,this.project);return u.setParent(a,e),u.initChildren(e),e==null||e.add(u,A.Added),u.hydrateAncestors(),u.addSelfToProject(e),this.inputs.forEach((h,c)=>{const v={id:I.UUID.uuid(),version:I.UUID.uuid(),type:n.InputMap,createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:I.sessionAuthor,previousVersion:null,deleted:!1,name:null,description:null,declaration:h,defaultValue:null,readsValue:null,index:c,parent:{id:I.UUID.uuid(),type:n.GenericReference,entityId:l,version:o,entityType:n.Condition}},E=C(v,this.project);E.setParent(u,e),E.initChildren(e),e==null||e.add(E,A.Added),E.hydrateAncestors(),E.addSelfToProject(e)}),u.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("implement-as-condition",this.id),u}clearErrors(){var e;return this.errors=[],this.inputs.forEach(t=>t.clearErrors()),this.outputs.forEach(t=>t.clearErrors()),(e=this.error)==null||e.clearErrors(),this}validate(){const e=aq(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){return[...this.errors,...this.inputs.flatMap(t=>t.getErrors()),...this.outputs.flatMap(t=>t.getErrors())]}getShallowErrors(){return this.errors}clone(e=this.project.addChangeSet(new b(this.project,"",T().toISOString(),this,!0,"clone-entity")),t=null,r=null,a=!0){var w,V;if(Array.from(new Set([...Cr(),...this.project.getAllBuiltInIds()])).includes(this.id))return this;let o=ft(t,this);const d=this.toJSON(),u=r||I.UUID.uuid();d.inputs=[],d.outputs=[],d.error=null;const h=u.split("-id"),c=h[h.length-1||0]||u;d.id=u,d.version=I.UUID.uuid(),d.createdAt=(e==null?void 0:e.timestamp)||T().toISOString(),d.author=(e==null?void 0:e.author)||"1",d.previousVersion=null,d.deleted=!1;const v=dt(d,o);e==null||e.add(v,A.Added),t?v.setParent(t,null):this.parent&&v.setParent(this.parent,null),a&&v.subscribe(),v.initChildren(e);const E=(w=this.inputs)==null?void 0:w.map((U,G)=>U.clone(e,v,c+"-argument-value-descriptor-"+G+"-id",a));v.inputs=E;const O=(V=this.outputs)==null?void 0:V.map((U,G)=>U.clone(e,v,c+"-return-value-descriptor-"+G+"-id",a));return v.outputs=O,this.error&&(v.error=this.error.clone(e,v,c+"-error-action-descriptor-id",a)),e==null||e.attemptAutoclose("clone-entity",this.id),v}addInput(e){return this.inputs.find(t=>t.id===e.id)||this.inputs.push(e),this}removeInput(e){return this.inputs=this.inputs.filter(t=>t.id!==e.id),this}addOutput(e){return this.outputs.find(t=>t.id===e.id)||this.outputs.push(e),this}removeOutput(e){return this.outputs=this.outputs.filter(t=>t.id!==e.id),this}};f(Pe,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>e,APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...r)=>null}),f(Pe,"type",n.ActionDescriptor),f(Pe,"USER_MANAGED_PARENT_TYPES",[n.DefinitionEntity,n.DataType]),f(Pe,"PARENT_TYPES",[...Pe.USER_MANAGED_PARENT_TYPES,n.PrimitiveEntity,n.BuiltInBaseEntity]),f(Pe,"MUTABLE_BASE_PROPERTIES",["name","description"]),f(Pe,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),f(Pe,"BASE_PROPERTIES",[...Pe.MUTABLE_BASE_PROPERTIES,...Pe.INMUTABLE_BASE_PROPERTIES]),f(Pe,"MUTABLE_META_PROPERTIES",[...Pe.MUTABLE_BASE_PROPERTIES]),f(Pe,"INMUTABLE_META_PROPERTIES",[...Pe.INMUTABLE_BASE_PROPERTIES]),f(Pe,"META_PROPERTIES",[...Pe.MUTABLE_META_PROPERTIES,...Pe.INMUTABLE_META_PROPERTIES]),f(Pe,"MUTABLE_UPSTREAM_PROPERTIES",[]),f(Pe,"INMUTABLE_UPSTREAM_PROPERTIES",["parent"]),f(Pe,"UPSTREAM_PROPERTIES",[...Pe.MUTABLE_UPSTREAM_PROPERTIES,...Pe.INMUTABLE_UPSTREAM_PROPERTIES]),f(Pe,"MUTABLE_DOWNSTREAM_PROPERTIES",["inputs","outputs"]),f(Pe,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),f(Pe,"DOWNSTREAM_PROPERTIES",[...Pe.MUTABLE_DOWNSTREAM_PROPERTIES,...Pe.INMUTABLE_DOWNSTREAM_PROPERTIES]),f(Pe,"PROPERTIES",[...Pe.META_PROPERTIES,...Pe.UPSTREAM_PROPERTIES,...Pe.DOWNSTREAM_PROPERTIES]);let qe=Pe;var Q1=(i=>(i.Parent="parent",i))(Q1||{});const ae=class ae extends rt{constructor(e,t){super(e);f(this,"initialData");f(this,"id");f(this,"x");f(this,"y");f(this,"type",n.Loop);f(this,"declaration");f(this,"inputs",[]);f(this,"outputs",[]);f(this,"process",null);f(this,"successCalls",[]);f(this,"errorCalls",[]);f(this,"error",null);f(this,"outputsDeclarations",[]);f(this,"body");f(this,"calledBySuccess",[]);f(this,"calledByError",[]);f(this,"calledByEntry",[]);f(this,"parent");f(this,"detachedChildren",[]);f(this,"currentIterationNumberArgumentDeclaration");f(this,"currentValueArgumentDeclaration",null);f(this,"errors",[]);f(this,"project");f(this,"detachedDependents",{});f(this,"knownVersions",null);f(this,"activeVersion",!1);f(this,"initialized",!1);f(this,"startedInitialization",!1);this.initialData=e,this.project=t,this.id=e.id,this.x=e.x,this.y=e.y}static fromGenerationTarget(e,t){let r=t;if(e.parent){const v=B(e.parent);r=t.get(v)}const a=B(e.declaration),l=t.get(a),o=e.calledByEntry.map(v=>{const E=B(v);return t.get(E)}),d=e.calledBySuccess.map(v=>{const E=B(v);return t.get(E)}),u=e.calledByError.map(v=>{const E=B(v);return t.get(E)}),h={id:e.id,version:I.UUID.uuid(),createdAt:T().toISOString(),author:I.sessionAuthor,previousVersion:null,deleted:!1,type:n.Loop,declaration:l,calledByEntry:o,calledBySuccess:d,calledByError:u,process:null,errorCalls:[],successCalls:[],inputs:[],outputs:[],body:null,outputsDeclarations:[],error:null,x:0,y:0,parent:r},c=C(h,t);return c.setParent(r,null),c.initChildren(null),c}static validateGenerationTarget(e,t){let r=JSON.parse(JSON.stringify(e));const a=[],l=Et(r,{parent:{list:!1,types:[...mt,n.Project],optional:!0},declaration:{list:!1,types:[n.ActionDescriptor]}},t);return r=l.modifiedData,a.push(...l.errors,...ot(r)),e.declaration?t.get(e.declaration)?t.conditionDeclarations.find(u=>u.id===e.declaration)||a.push(new P({id:`${e.id}--${R.InvalidImplementsReference}`,code:R.InvalidImplementsReference,severity:D.Error,message:`Entity of type '${e.type}' with id '${e.id}' has an 'declaration' property that isn't pointing to an action descriptor reserved for '${n.Condition}' entities.
94
+ This is likely an incorrect strategy, either the '${this.type}' entity doesn't need to be updated or it should be deleted and a new one created in the desired parent.`,issue:null})),{errors:t,modifiedData:e}}subscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]||(this.detachedDependents[t.entity.id]=t)}),this}syncDependents(){const e=[],t=[],r=[],a=[];return Object.values(this.detachedDependents).forEach(l=>{const o=l.entity.afterAllChildrenInitialized();e.push(...o.updated),t.push(...o.added),r.push(...o.removed),a.push(...o.affected)}),{updated:p(e),added:p(t),removed:p(r),affected:p(a),self:this}}onDetachedDependencyRemoved(e,t,r){const a=[],l=[],o=[],d=[];return{updated:p(a),added:p(l),removed:p(o),affected:p(d),self:this}}onDetachedDependencyRestored(e,t,r){const a=[],l=[],o=[],d=[];return{updated:p(a),added:p(l),removed:p(o),affected:p(d),self:this}}subscribeToDependencies(){return this}increaseVersion(e){if(e&&!T(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&T(e).isSame(T(this.createdAt))?this:(this.previousVersion=this.version,this.version=I.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new Pe(this,this.project);return e.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,e):new Map([[this.version,e]]),e.inputs=this.inputs,e.outputs=this.outputs,e.error=this.error,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],r=[],a=[],l=[];if(this.parent&&this.parent.type!==n.BuiltInBaseEntity&&this.parent.type!==n.PrimitiveEntity){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),r.push(...o.added),a.push(...o.removed)}return{updated:p(t),added:p(r),removed:p(a),affected:p(l),self:this}}async restoreVersion(e){var d;const t=[],r=[],a=[],l=[];if(this.version===e)return{updated:p(t),added:p(r),removed:p(a),affected:p(l),self:this};if(!this.knownVersions){const u=new Map;for(const[h,c]of this.knownVersions||new Map){if(u.set(h,c),c.activeVersion=!1,c.knownVersions)for(const[v,E]of c.knownVersions)u.set(v,E);c.knownVersions=null}}let o=(d=this.knownVersions)==null?void 0:d.get(e);if(!o){const u=await this.APILoadVersion({},e);if(!u)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new Pe(u,this.project)}return this.metaSync(o.toShallowJSON(),null),this.inputs=o.inputs,this.outputs=o.outputs,this.error=o.error,this.parent=o.parent,{updated:p(t),added:p(r),removed:p(a),affected:p(l),self:this}}hydrateAncestors(){const e=[],t=[],r=[],a=[];if(this.initialData.parent){const l=B(this.initialData.parent),o=this.project.get(l);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw new Error(`${this.type} with id '${this.id}' must have a 'parent'`);return{updated:p(e),added:p(t),removed:p(r),affected:p(a),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new b(this.project,"",T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],r=[],a=[],l=[];return this.initialized=!0,this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:p(t),added:p(r),removed:p(a),affected:p(l),self:this}}addSelfToProject(e=this.project.addChangeSet(new b(this.project,"",T().toISOString(),this,!0,"add-self-to-project"))){const t=[this],r=[],a=[],l=[];return this.parent?(this.parent.type===n.DefinitionEntity?(this.parent.addAbstractMethod(this),t.push(this.parent)):this.parent.type===n.DataType&&(this.parent.setEntity(this),t.push(this.parent)),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:p(t),added:p(r),removed:p(a),affected:p(l),self:this}):(this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:p(t),added:p(r),removed:p(a),affected:p(l),self:this})}setParent(e,t=this.project.addChangeSet(new b(this.project,"",T().toISOString(),this,!0,"set-parent"))){var r;return((r=this.parent)==null?void 0:r.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,A.Updated),t==null||t.attemptAutoclose("set-parent",this.id))),this}initChildren(e=this.project.addChangeSet(new b(this.project,"",T().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.inputs=this.initialData.inputs.map(t=>{const r=C(t,this.project);return r.setParent(this,null),r.initChildren(e),r}),this.outputs=this.initialData.outputs.map(t=>{const r=C(t,this.project);return r.setParent(this,null),r.initChildren(e),r}),this.initialData.error&&(this.error=C(this.initialData.error,this.project),this.error.setParent(this,null),this.error.initChildren(e)),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this)}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new b(this.project,"",T().toISOString(),this,!0,"meta-sync"))){const r=lt(this,e),a=this.toMeta();return this.name=e.name||a.name,this.description=e.description||a.description,super.metaSync(e),e.deleted===!0&&!a.deleted?t==null||t.add(this,A.Removed):e.deleted===!1&&a.deleted?t==null||t.add(this,A.Added):r&&(t==null||t.add(this,A.Updated)),t==null||t.attemptAutoclose("meta-sync",this.id),this}async APILoad(e=L,...t){return await Pe.repository.APILoad(this.id,...t),this}async APICreate(e=L,...t){return await Pe.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=L,...t){return await Pe.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=L,...t){return await Pe.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=L,...t){return await Pe.repository.APIClone(this.id,...t),this}async APILoadVersion(e=L,t,...r){return await Pe.repository.APILoadVersion(this.id,t,...r)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new b(this.project,"",T().toISOString(),this,!0,"remove-entity"))){const r=[],a=[],l=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(a.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(d=>{const{updated:u,removed:h,added:c}=d.entity.onDetachedDependencyRemoved(this,d.field,t);r.push(...u),a.push(...h),l.push(...c)}),this.inputs.forEach(d=>{const u=d.remove({ignoreUpstream:!0},t);r.push(...u.updated),a.push(...u.removed)}),this.outputs.forEach(d=>{const u=d.remove({ignoreUpstream:!0},t);r.push(...u.updated),a.push(...u.removed)}),this.error){const d=this.error.remove({ignoreUpstream:!0},t);r.push(...d.updated),a.push(...d.removed)}return t==null||t.attemptAutoclose("remove-entity",this.id),{added:p(l),updated:p(r),removed:p(a),affected:p(o),self:this}}restore({}={},e=this.project.addChangeSet(new b(this.project,"",T().toISOString(),this,!0,"restore-entity"))){const t=[],r=[],a=[],l=[];if(e!=null&&e.hasAdded(this.id))return e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),this.inputs.forEach(o=>{const d=o.restore({},e);r.push(...d.updated)}),this.outputs.forEach(o=>{const d=o.restore({},e);r.push(...d.updated)}),this.error){const o=this.error.restore({},e);r.push(...o.updated)}return e==null||e.attemptAutoclose("restore-entity",this.id),{added:p(t),updated:p(r),removed:p(a),affected:p(l),self:this}}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.inputs.flatMap(r=>r.toFlat(e)),...this.outputs.flatMap(r=>r.toFlat(e))])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.inputs.flatMap(r=>r.toFlatIds(e)),...this.outputs.flatMap(r=>r.toFlatIds(e))])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,description:this.description,type:this.type,name:this.name}}toJSON(e=new Set){var t,r;return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,error:((t=this.error)==null?void 0:t.toJSON())||null,inputs:this.inputs.map(a=>a.toJSON()),outputs:this.outputs.map(a=>a.toJSON()),parent:((r=this.parent)==null?void 0:r.toReference())||null})}toJSONClone(e=Z){var r,a,l,o,d,u,h;let t;return(r=e.seenEntityMaps)!=null&&r.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||ct(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(a=e.seenEntities)!=null&&a.has(t)||(l=e.seenEntities)!=null&&l.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(d=e.seenEntities)==null||d.add(this.id),{id:t,version:I.UUID.uuid(),createdAt:e.timestamp||T().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,error:((u=this.error)==null?void 0:u.toJSONClone({...e,newId:null}))||null,inputs:this.inputs.map(c=>c.toJSONClone({...e,newId:null})),outputs:this.outputs.map(c=>c.toJSONClone({...e,newId:null})),parent:((h=this.parent)==null?void 0:h.toReference({seenEntityMaps:e.seenEntityMaps}))||null})}toReference(e=Z){var r;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+I.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=Z){var r,a,l;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,error:((a=this.error)==null?void 0:a.toReference(e))||null,inputs:this.inputs.map(o=>o.toReference(e)),outputs:this.outputs.map(o=>o.toReference(e)),parent:((l=this.parent)==null?void 0:l.toReference(e))||null}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.inputs.flatMap(r=>r.toFlatJSON(e)),...this.outputs.flatMap(r=>r.toFlatJSON(e))])}toGenerationTarget(){var e;return{id:this.id,name:this.name,description:this.description,type:this.type,parent:((e=this.parent)==null?void 0:e.id)||void 0}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...this.inputs.flatMap(r=>r.toFlatGenerationTarget(e)),...this.outputs.flatMap(r=>r.toFlatGenerationTarget(e))])}asFunctionDeclarationTransfer(e,t=this.project.addChangeSet(new b(this.project,"",T().toISOString(),this,!0,"implement-as-function-declaration"))){var d;const r=e||I.UUID.uuid(),a=I.UUID.uuid(),l=this.inputs.map((u,h)=>{var v;const c={id:I.UUID.uuid(),type:n.GenericReference,version:a,entityType:n.FunctionDeclaration,entityId:r};return{id:I.UUID.uuid(),version:I.UUID.uuid(),createdAt:(t==null?void 0:t.timestamp)||T().toISOString(),author:I.sessionAuthor,previousVersion:null,deleted:!1,type:n.ArgumentDeclaration,name:u.name,required:u.required,implements:u.toJSON(),constant:!0,writesValues:[],defaultValue:null,description:u.description,index:h,dataType:((v=u.dataType)==null?void 0:v.toJSONClone({timestamp:(t==null?void 0:t.timestamp)||T().toISOString()}))||null,parent:c}}),o=[];if(this.outputs.length){const u=this.outputs.map((E,O)=>{var V;const w={id:I.UUID.uuid(),type:n.GenericReference,entityId:r,version:a,entityType:n.ReturnStatement};return{id:I.UUID.uuid(),version:I.UUID.uuid(),createdAt:(t==null?void 0:t.timestamp)||T().toISOString(),author:I.sessionAuthor,previousVersion:null,deleted:!1,type:n.ReturnDeclaration,name:E.name,description:E.description,readsValue:null,constant:!0,required:E.required,defaultValue:null,implements:E.toJSON(),isError:!1,index:O,dataType:((V=E.dataType)==null?void 0:V.toJSONClone())||null,parent:w}}),h={id:I.UUID.uuid(),type:n.GenericReference,version:a,entityType:n.FunctionDeclaration,entityId:r},c={id:I.UUID.uuid(),type:n.GenericReference,version:a,entityType:n.FunctionDeclaration,entityId:r},v={id:I.UUID.uuid(),version:I.UUID.uuid(),createdAt:(t==null?void 0:t.timestamp)||T().toISOString(),author:I.sessionAuthor,previousVersion:null,deleted:!1,type:n.ReturnStatement,outputs:u,throws:null,calledBySuccess:[],calledByError:[],calledByEntry:[c],parent:h,x:0,y:0};o.push(v)}return t==null||t.attemptAutoclose("implement-as-function-declaration",this.id),{id:r,version:a,createdAt:(t==null?void 0:t.timestamp)||T().toISOString(),author:I.sessionAuthor,previousVersion:null,deleted:!1,type:n.FunctionDeclaration,name:this.name,description:this.description,inputs:l,calls:o,collapsed:!1,private:!1,implements:this.toJSON(),index:0,parent:((d=this.parent)==null?void 0:d.toReference())||null,x:0,y:0}}implementAsGlobalEvent(e=this.project.addChangeSet(new b(this.project,"",T().toISOString(),this,!0,"implement-as-global-event")),t,r){const a=t||this.project,l=r||I.UUID.uuid(),o=I.UUID.uuid(),d={id:l,version:o,createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:I.sessionAuthor,previousVersion:null,deleted:!1,type:n.GlobalEvent,name:this.name,description:this.description,inputs:[],calls:[],collapsed:!1,implements:this.toJSON(),parent:(a==null?void 0:a.toReference())||null,x:0,y:0},u=C(d,this.project);if(u.setParent(a,e),u.initChildren(e),e==null||e.add(u,A.Added),u.hydrateAncestors(),u.addSelfToProject(e),this.inputs.map((h,c)=>{var V;const v={id:I.UUID.uuid(),type:n.GenericReference,version:o,entityType:n.GlobalEvent,entityId:l},E={id:I.UUID.uuid(),version:I.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:I.sessionAuthor,previousVersion:null,deleted:!1,type:n.ArgumentDeclaration,name:h.name,required:h.required,implements:h.toJSON(),constant:!0,writesValues:[],defaultValue:null,description:h.description,index:c,dataType:null,parent:v},O=C(E,this.project);O.setParent(u,e),O.initChildren(e),e==null||e.add(O,A.Added),O.hydrateAncestors(),O.addSelfToProject(e);const w=((V=h.dataType)==null?void 0:V.clone(e,O))||null;w&&(e==null||e.add(w,A.Added)),O.setDataType(w)}),this.outputs.length){const h=I.UUID.uuid(),c=I.UUID.uuid(),v={id:I.UUID.uuid(),type:n.GenericReference,version:o,entityType:n.GlobalEvent,entityId:l},E={id:I.UUID.uuid(),type:n.GenericReference,version:o,entityType:n.GlobalEvent,entityId:l},O={id:h,version:c,createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:I.sessionAuthor,previousVersion:null,deleted:!1,type:n.ReturnStatement,outputs:[],throws:null,calledBySuccess:[],calledByError:[],calledByEntry:[E],parent:v,x:0,y:0},w=C(O,this.project);w.setParent(u,e),w.initChildren(e),e==null||e.add(w,A.Added),w.hydrateAncestors(),w.addSelfToProject(e),this.outputs.map((V,U)=>{var J;const G={id:I.UUID.uuid(),type:n.GenericReference,entityId:h,version:c,entityType:n.ReturnStatement},_={id:I.UUID.uuid(),version:I.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:I.sessionAuthor,previousVersion:null,deleted:!1,type:n.ReturnDeclaration,name:V.name,description:V.description,readsValue:null,constant:!0,required:V.required,defaultValue:null,implements:V.toJSON(),isError:!1,index:U,dataType:null,parent:G},$=C(_,this.project);$.setParent(w,e),$.initChildren(e),e==null||e.add($,A.Added),$.hydrateAncestors(),$.addSelfToProject(e);const k=((J=V.dataType)==null?void 0:J.clone(e,$))||null;k&&(e==null||e.add(k,A.Added)),$.setDataType(k)})}return e==null||e.attemptAutoclose("implement-as-function-declaration",this.id),u}implementAsFunctionDeclaration(e=this.project.addChangeSet(new b(this.project,"",T().toISOString(),this,!0,"implement-as-function-declaration")),t,r){const a=t||this.project,l=r||I.UUID.uuid(),o=I.UUID.uuid(),d={id:l,version:o,createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:I.sessionAuthor,previousVersion:null,deleted:!1,type:n.FunctionDeclaration,name:this.name,description:this.description,inputs:[],calls:[],collapsed:!1,private:!1,implements:this.toJSON(),index:0,parent:(a==null?void 0:a.toReference())||null,x:0,y:0},u=C(d,this.project);if(u.setParent(a,e),u.initChildren(e),e==null||e.add(u,A.Added),u.hydrateAncestors(),u.addSelfToProject(e),this.inputs.map((h,c)=>{var V;const v={id:I.UUID.uuid(),type:n.GenericReference,version:o,entityType:n.FunctionDeclaration,entityId:l},E={id:I.UUID.uuid(),version:I.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:I.sessionAuthor,previousVersion:null,deleted:!1,type:n.ArgumentDeclaration,name:h.name,required:h.required,implements:h.toJSON(),constant:!0,writesValues:[],defaultValue:null,description:h.description,index:c,dataType:null,parent:v},O=C(E,this.project);O.setParent(u,e),O.initChildren(e),e==null||e.add(O,A.Added),O.hydrateAncestors(),O.addSelfToProject(e);const w=((V=h.dataType)==null?void 0:V.clone(e,O))||null;w&&(e==null||e.add(w,A.Added)),O.setDataType(w)}),this.outputs.length){const h=I.UUID.uuid(),c=I.UUID.uuid(),v={id:I.UUID.uuid(),type:n.GenericReference,version:o,entityType:n.FunctionDeclaration,entityId:l},E={id:I.UUID.uuid(),type:n.GenericReference,version:o,entityType:n.FunctionDeclaration,entityId:l},O={id:h,version:c,createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:I.sessionAuthor,previousVersion:null,deleted:!1,type:n.ReturnStatement,outputs:[],throws:null,calledBySuccess:[],calledByError:[],calledByEntry:[E],parent:v,x:0,y:0},w=C(O,this.project);w.setParent(u,e),w.initChildren(e),e==null||e.add(w,A.Added),w.hydrateAncestors(),w.addSelfToProject(e),this.outputs.map((V,U)=>{var J;const G={id:I.UUID.uuid(),type:n.GenericReference,entityId:h,version:c,entityType:n.ReturnStatement},_={id:I.UUID.uuid(),version:I.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:I.sessionAuthor,previousVersion:null,deleted:!1,type:n.ReturnDeclaration,name:V.name,description:V.description,readsValue:null,constant:!0,required:V.required,defaultValue:null,implements:V.toJSON(),isError:!1,index:U,dataType:null,parent:G},$=C(_,this.project);$.setParent(w,e),$.initChildren(e),e==null||e.add($,A.Added),$.hydrateAncestors(),$.addSelfToProject(e);const k=((J=V.dataType)==null?void 0:J.clone(e,$))||null;k&&(e==null||e.add(k,A.Added)),$.setDataType(k)})}return e==null||e.attemptAutoclose("implement-as-function-declaration",this.id),u}implementAsLoop(e=this.project.addChangeSet(new b(this.project,"",T().toISOString(),this,!0,"implement-as-loop")),t,r){const a=t||this.project,l=r||I.UUID.uuid(),o=I.UUID.uuid(),d={id:l,version:o,createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:I.sessionAuthor,previousVersion:null,deleted:!1,type:n.Loop,declaration:this.toJSON(),inputs:[],outputs:[],error:null,process:null,successCalls:[],errorCalls:[],calledByEntry:[],calledByError:[],calledBySuccess:[],outputsDeclarations:[],body:null,x:0,y:0,parent:a.toReference()},u=C(d,this.project);return u.setParent(a,e),u.initChildren(e),e==null||e.add(u,A.Added),u.hydrateAncestors(),u.addSelfToProject(e),u.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("implement-as-loop",this.id),u}implementAsOperation(e=this.project.addChangeSet(new b(this.project,"",T().toISOString(),this,!0,"implement-as-operation")),t,r){const a=t||this.project,l=r||I.UUID.uuid(),o=I.UUID.uuid(),d={id:l,version:o,createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:I.sessionAuthor,previousVersion:null,deleted:!1,type:n.Operation,declaration:this.toJSON(),inputs:[],outputs:[],error:null,process:null,successCalls:[],errorCalls:[],calledByEntry:[],calledByError:[],calledBySuccess:[],x:0,y:0,parent:a.toReference()},u=C(d,this.project);return u.setParent(a,e),u.initChildren(e),e==null||e.add(u,A.Added),u.hydrateAncestors(),u.addSelfToProject(e),u.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("implement-as-operation",this.id),u}implementAsCondition(e=this.project.addChangeSet(new b(this.project,"",T().toISOString(),this,!0,"implement-as-condition")),t,r){const a=t||this.project,l=r||I.UUID.uuid(),o=I.UUID.uuid(),d={id:l,version:o,createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:I.sessionAuthor,previousVersion:null,deleted:!1,type:n.Condition,declaration:this.toJSON(),inputs:[],successCalls:[],errorCalls:[],calledByEntry:[],calledByError:[],calledBySuccess:[],x:0,y:0,parent:a.toReference()},u=C(d,this.project);return u.setParent(a,e),u.initChildren(e),e==null||e.add(u,A.Added),u.hydrateAncestors(),u.addSelfToProject(e),u.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("implement-as-condition",this.id),u}clearErrors(){var e;return this.errors=[],this.inputs.forEach(t=>t.clearErrors()),this.outputs.forEach(t=>t.clearErrors()),(e=this.error)==null||e.clearErrors(),this}validate(){const e=aq(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){return[...this.errors,...this.inputs.flatMap(t=>t.getErrors()),...this.outputs.flatMap(t=>t.getErrors())]}getShallowErrors(){return this.errors}clone(e=this.project.addChangeSet(new b(this.project,"",T().toISOString(),this,!0,"clone-entity")),t=null,r=null,a=!0){var w,V;if(Array.from(new Set([...Cr(),...this.project.getAllBuiltInIds()])).includes(this.id))return this;let o=ft(t,this);const d=this.toJSON(),u=r||I.UUID.uuid();d.inputs=[],d.outputs=[],d.error=null;const h=u.split("-id"),c=h[h.length-1||0]||u;d.id=u,d.version=I.UUID.uuid(),d.createdAt=(e==null?void 0:e.timestamp)||T().toISOString(),d.author=(e==null?void 0:e.author)||"1",d.previousVersion=null,d.deleted=!1;const v=dt(d,o);e==null||e.add(v,A.Added),t?v.setParent(t,null):this.parent&&v.setParent(this.parent,null),a&&v.subscribe(),v.initChildren(e);const E=(w=this.inputs)==null?void 0:w.map((U,G)=>U.clone(e,v,c+"-argument-value-descriptor-"+G+"-id",a));v.inputs=E;const O=(V=this.outputs)==null?void 0:V.map((U,G)=>U.clone(e,v,c+"-return-value-descriptor-"+G+"-id",a));return v.outputs=O,this.error&&(v.error=this.error.clone(e,v,c+"-error-action-descriptor-id",a)),e==null||e.attemptAutoclose("clone-entity",this.id),v}addInput(e){return this.inputs.find(t=>t.id===e.id)||this.inputs.push(e),this}removeInput(e){return this.inputs=this.inputs.filter(t=>t.id!==e.id),this}addOutput(e){return this.outputs.find(t=>t.id===e.id)||this.outputs.push(e),this}removeOutput(e){return this.outputs=this.outputs.filter(t=>t.id!==e.id),this}};f(Pe,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>e,APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...r)=>null}),f(Pe,"type",n.ActionDescriptor),f(Pe,"USER_MANAGED_PARENT_TYPES",[n.DefinitionEntity,n.DataType]),f(Pe,"PARENT_TYPES",[...Pe.USER_MANAGED_PARENT_TYPES,n.PrimitiveEntity,n.BuiltInBaseEntity]),f(Pe,"MUTABLE_BASE_PROPERTIES",["name","description"]),f(Pe,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),f(Pe,"BASE_PROPERTIES",[...Pe.MUTABLE_BASE_PROPERTIES,...Pe.INMUTABLE_BASE_PROPERTIES]),f(Pe,"MUTABLE_META_PROPERTIES",[...Pe.MUTABLE_BASE_PROPERTIES]),f(Pe,"INMUTABLE_META_PROPERTIES",[...Pe.INMUTABLE_BASE_PROPERTIES]),f(Pe,"META_PROPERTIES",[...Pe.MUTABLE_META_PROPERTIES,...Pe.INMUTABLE_META_PROPERTIES]),f(Pe,"MUTABLE_UPSTREAM_PROPERTIES",[]),f(Pe,"INMUTABLE_UPSTREAM_PROPERTIES",["parent"]),f(Pe,"UPSTREAM_PROPERTIES",[...Pe.MUTABLE_UPSTREAM_PROPERTIES,...Pe.INMUTABLE_UPSTREAM_PROPERTIES]),f(Pe,"MUTABLE_DOWNSTREAM_PROPERTIES",["inputs","outputs"]),f(Pe,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),f(Pe,"DOWNSTREAM_PROPERTIES",[...Pe.MUTABLE_DOWNSTREAM_PROPERTIES,...Pe.INMUTABLE_DOWNSTREAM_PROPERTIES]),f(Pe,"PROPERTIES",[...Pe.META_PROPERTIES,...Pe.UPSTREAM_PROPERTIES,...Pe.DOWNSTREAM_PROPERTIES]);let qe=Pe;var Q1=(i=>(i.Parent="parent",i))(Q1||{});const ae=class ae extends rt{constructor(e,t){super(e);f(this,"initialData");f(this,"id");f(this,"x");f(this,"y");f(this,"type",n.Loop);f(this,"declaration");f(this,"inputs",[]);f(this,"outputs",[]);f(this,"process",null);f(this,"successCalls",[]);f(this,"errorCalls",[]);f(this,"error",null);f(this,"outputsDeclarations",[]);f(this,"body");f(this,"calledBySuccess",[]);f(this,"calledByError",[]);f(this,"calledByEntry",[]);f(this,"parent");f(this,"detachedChildren",[]);f(this,"currentIterationNumberArgumentDeclaration");f(this,"currentValueArgumentDeclaration",null);f(this,"errors",[]);f(this,"project");f(this,"detachedDependents",{});f(this,"knownVersions",null);f(this,"activeVersion",!1);f(this,"initialized",!1);f(this,"startedInitialization",!1);this.initialData=e,this.project=t,this.id=e.id,this.x=e.x,this.y=e.y}static fromGenerationTarget(e,t){let r=t;if(e.parent){const v=B(e.parent);r=t.get(v)}const a=B(e.declaration),l=t.get(a),o=e.calledByEntry.map(v=>{const E=B(v);return t.get(E)}),d=e.calledBySuccess.map(v=>{const E=B(v);return t.get(E)}),u=e.calledByError.map(v=>{const E=B(v);return t.get(E)}),h={id:e.id,version:I.UUID.uuid(),createdAt:T().toISOString(),author:I.sessionAuthor,previousVersion:null,deleted:!1,type:n.Loop,declaration:l,calledByEntry:o,calledBySuccess:d,calledByError:u,process:null,errorCalls:[],successCalls:[],inputs:[],outputs:[],body:null,outputsDeclarations:[],error:null,x:0,y:0,parent:r},c=C(h,t);return c.setParent(r,null),c.initChildren(null),c}static validateGenerationTarget(e,t){let r=JSON.parse(JSON.stringify(e));const a=[],l=Et(r,{parent:{list:!1,types:[...mt,n.Project],optional:!0},declaration:{list:!1,types:[n.ActionDescriptor]}},t);return r=l.modifiedData,a.push(...l.errors,...ot(r)),e.declaration?t.get(e.declaration)?t.conditionDeclarations.find(u=>u.id===e.declaration)||a.push(new P({id:`${e.id}--${R.InvalidImplementsReference}`,code:R.InvalidImplementsReference,severity:D.Error,message:`Entity of type '${e.type}' with id '${e.id}' has an 'declaration' property that isn't pointing to an action descriptor reserved for '${n.Condition}' entities.
95
95
  ${Gl(t)}`,issue:null})):a.push(new P({id:`${e.id}--${R.ReferencedEntityNotFound}`,code:R.ReferencedEntityNotFound,severity:D.Error,message:`Entity of type '${e.type}' with id '${e.id}' has an 'declaration' property that isn't found in the project. The 'declaration' property must point to one of the built-in action descriptors reserved for '${n.Condition}' entities.
96
96
  ${Gl(t)}`,issue:null})):a.push(new P({id:`${e.id}--${j.InvalidObjectStructure}`,code:j.InvalidObjectStructure,severity:D.Error,message:`Entity of type '${e.type}' with id '${e.id}' is missing the 'declaration' property. This property is required for a '${e.type}' entity and must point to one of the built-in action descriptors reserved for '${n.Condition}' entities.
97
97
  ${Gl(t)}`,issue:null})),{errors:a,modifiedData:r}}static fromReturnDeclarationToBodyArgumentDeclarationName(e){return`Previous iteration results of '${F(e,e.project)}'`}static fromBodyArgumentDeclarationToReturnDeclarationName(e){const t=e.name.replace("Previous iteration results of '","");return t.slice(0,t.length-1)}static fromReturnDeclarationToLoopOutputDeclarationName(e){return`Result list of '${F(e,e.project)}'`}static fromLoopOutputDeclarationToReturnDeclarationName(e){const t=e.name.replace("Result list of '","");return t.slice(0,t.length-1)}static fromLoopOutputDeclarationToBodyArgumentDeclarationName(e){return e.name.replace("Result list of '","Previous iteration results of '")}static fromBodyArgumentDeclarationToLoopOutputDeclarationName(e){return e.name.replace("Previous iteration results of '","Result list of '")}get continueStatements(){const e=[];return Object.values(this.detachedDependents).forEach(t=>{t.field===bc.Parent&&t.entity.type===n.ContinueStatement&&!e.includes(t.entity)&&e.push(t.entity)}),e}get breakStatements(){const e=[];return Object.values(this.detachedDependents).forEach(t=>{t.field===Dc.Parent&&t.entity.type===n.BreakStatement&&!e.includes(t.entity)&&e.push(t.entity)}),e}validateGeneratedUpdate(e){const t=[];return e.parent&&t.push(new P({id:`${this.id}--${R.InvalidParentUpdate}`,code:R.InvalidParentUpdate,severity:D.Error,message:`Entity of type '${this.type}' with id '${this.id}' cannot have the 'parent' property updated. The 'parent' on a callable entity, is its scope. It scope is auto-calculated implicitly by the its caller.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elyx-code/project-logic-tree",
3
- "version": "0.0.6194",
3
+ "version": "0.0.6196",
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",