@elyx-code/project-logic-tree 0.0.6266 → 0.0.6267

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -30916,7 +30916,7 @@ ${Ul}`,
30916
30916
  captureVersion() {
30917
30917
  var t;
30918
30918
  const e = ((t = this.knownVersions) == null ? void 0 : t.get(this.version)) || new be(this, this.project);
30919
- return e.metaSync(this.toMeta(), null), this.knownVersions = this.knownVersions ? this.knownVersions.set(this.version, e) : /* @__PURE__ */ new Map([[this.version, e]]), e.defaultValue = this.defaultValue, e.dataType = this.dataType, e.implements = this.implements, e.parent = this.parent, this;
30919
+ return e.metaSync(this.toMeta(), null), this.knownVersions = this.knownVersions ? this.knownVersions.set(this.version, e) : /* @__PURE__ */ new Map([[this.version, e]]), e.defaultValue = this.defaultValue, e.dataType = this.dataType, e.implements = this.implements, e.extends = this.extends, e.parent = this.parent, this;
30920
30920
  }
30921
30921
  // Traverses upstream entities and captures their versions as well
30922
30922
  recursiveCaptureUpstreamVersions(e) {
@@ -32127,7 +32127,7 @@ Please consider than any updates might affect the overlap with the signature of
32127
32127
  captureVersion() {
32128
32128
  var t;
32129
32129
  const e = ((t = this.knownVersions) == null ? void 0 : t.get(this.version)) || new Re(this, this.project);
32130
- return e.metaSync(this.toMeta(), null), this.knownVersions = this.knownVersions ? this.knownVersions.set(this.version, e) : /* @__PURE__ */ new Map([[this.version, e]]), e.inputs = this.inputs, e.calls = this.calls, e.implements = this.implements, e.detachedChildren = this.detachedChildren, e.parent = this.parent, this;
32130
+ return e.metaSync(this.toMeta(), null), this.knownVersions = this.knownVersions ? this.knownVersions.set(this.version, e) : /* @__PURE__ */ new Map([[this.version, e]]), e.inputs = this.inputs, e.calls = this.calls, e.implements = this.implements, e.extends = this.extends, e.detachedChildren = this.detachedChildren, e.parent = this.parent, this;
32131
32131
  }
32132
32132
  // Traverses upstream entities and captures their versions as well
32133
32133
  recursiveCaptureUpstreamVersions(e) {
@@ -32822,32 +32822,33 @@ Please consider than any updates might affect the overlap with the signature of
32822
32822
  "clone-entity"
32823
32823
  )
32824
32824
  ), t = null, i = null, s = !0, l = !1) {
32825
- var O;
32825
+ var E;
32826
32826
  let o = yt(t, this);
32827
32827
  const d = this.toJSON(), u = i || y.UUID.uuid();
32828
- d.inputs = [], d.calls = [];
32829
- const f = u.split("-id"), c = f[f.length - 1 || 0] || u;
32830
- d.id = u, d.version = y.UUID.uuid(), d.createdAt = (e == null ? void 0 : e.timestamp) || v().toISOString(), d.author = (e == null ? void 0 : e.author) || "1", d.previousVersion = null, d.deleted = !1;
32831
- const T = rt(
32828
+ d.inputs = [], d.calls = [], d.id = u, d.version = y.UUID.uuid(), d.createdAt = (e == null ? void 0 : e.timestamp) || v().toISOString(), d.author = (e == null ? void 0 : e.author) || "1", d.previousVersion = null, d.deleted = !1;
32829
+ const f = rt(
32832
32830
  d,
32833
32831
  o
32834
32832
  );
32835
- t ? T.setParent(t, null) : T.setParent(this.parent, null), s && T.subscribe(), T.initChildren(e), e == null || e.add(T, I.Added);
32836
- const E = (O = this.inputs) == null ? void 0 : O.map(
32837
- (V, M) => V.clone(
32833
+ t ? f.setParent(t, null) : f.setParent(this.parent, null), s && f.subscribe(), f.initChildren(e), e == null || e.add(f, I.Added);
32834
+ const c = (E = this.inputs) == null ? void 0 : E.map(
32835
+ (R) => R.clone(
32838
32836
  e,
32839
- T,
32840
- c + "-argument-declaration-" + M + "-id",
32837
+ f,
32838
+ y.UUID.uuid(),
32839
+ // parentIdPrefix + '-argument-declaration-' + index + '-id',
32841
32840
  s
32842
32841
  )
32843
32842
  );
32844
- return T.inputs = E, l ? (ui(this).map(
32845
- (V, M) => V.clone(
32843
+ return f.inputs = c, l ? (ui(this).map(
32844
+ (R) => R.clone(
32846
32845
  e,
32847
- T,
32848
- c + "-body-entity-" + M + "-id"
32846
+ f,
32847
+ y.UUID.uuid(),
32848
+ // parentIdPrefix + '-body-entity-' + index + '-id'
32849
+ s
32849
32850
  )
32850
- ), e == null || e.attemptAutoclose("clone-entity", this.id), T) : (e == null || e.attemptAutoclose("clone-entity", this.id), T);
32851
+ ), e == null || e.attemptAutoclose("clone-entity", this.id), f) : (e == null || e.attemptAutoclose("clone-entity", this.id), f);
32851
32852
  }
32852
32853
  getVariableInstances() {
32853
32854
  return He(this).filter(
@@ -42,7 +42,7 @@ Please provide a unique 'name' string.`,severity:O.Error,code:$.NameNotUniqueInS
42
42
  Please provide a unique 'name' string.`,severity:O.Error,code:$.NameNotUniqueInScope,issue:null}))}}return e}function CJ(r,a){switch(r.type){case n.DefinitionEntity:return bc(r,a);case n.FunctionDeclaration:return Rc(r,a);case n.VariableDeclaration:return Dc(r,a);case n.Property:return Oc(r,a);case n.ArgumentDeclaration:return Pc(r,a);case n.ReturnDeclaration:return wc(r,a);default:return[]}}function r1(r,a,e){const i=`${Ul(r)}-${a}-id`;return e.instances[i]?m.UUID.uuid():i}function Cc(r,a){let e="",t=null;if(r.parent){const s=a.get(r.parent);s&&(t=s)}let i="";return t&&(i=`${Ul(x(t,a))}-`),e=`${i}${Ul(x(r,a))}-id`,a.instances[e]?m.UUID.uuid():e}function yt(r,a,e="uuid"){return e==="semantic"?r1(x(r,a),r.type,a):m.UUID.uuid()}function n1(r){var l;const a=n5(),e=r.toJSON();a.safeParse(e).success;const i=s1(r);(l=r.dataType)==null||l.validate();const s=[...i];if(r.id==="80c86e1b-caca-4ba5-9b1f-38f72d10e4a3"){const o=de({id:`${r.id}--${F.PropertyImplementsNonAbstact}`,message:`Property "${x(r,r.project)}" with id "${r.id}" implements a non-abstract property "${x(r,r.project)}" with id "${r.id}".`,issue:null,severity:O.Error,code:F.PropertyImplementsNonAbstact,entity:r});s.push(o.error)}return s}function s1(r){const a=[];if(!r.implements)return a;const e=r.implements;if(!e.abstract){const i=de({id:`${r.id}--${F.PropertyImplementsNonAbstact}`,message:`Property "${x(r,r.project)}" with id "${r.id}" implements a non-abstract property "${x(e,r.project)}" with id "${e.id}".`,issue:null,severity:O.Error,code:F.PropertyImplementsNonAbstact,entity:r});a.push(i.error)}if(r.static&&!e.static){const i=de({id:`${r.id}--${F.NonStaticPropertyImplementsStatic}`,message:`Static property "${x(r,r.project)}" with id "${r.id}" implements a non-static property "${x(e,r.project)}" with id "${e.id}".`,issue:null,severity:O.Error,code:F.NonStaticPropertyImplementsStatic,entity:r});a.push(i.error)}if(!r.static&&e.static){const i=de({id:`${r.id}--${F.StaticPropertyImplementsNonStatic}`,message:`Non-static property "${x(r,r.project)}" with id "${r.id}" implements a static property "${x(e,r.project)}" with id "${e.id}".`,issue:null,severity:O.Error,code:F.StaticPropertyImplementsNonStatic,entity:r});a.push(i.error)}if(!wi(r.dataType,e.dataType)){const i=de({id:`${r.id}--${F.PropertyImplementsIncompatibleType}`,message:`Property "${x(r,r.project)}" with id "${r.id}" implements a property "${x(e,r.project)}" with id "${e.id}" that has an incompatible data type.`,issue:null,severity:O.Error,code:F.PropertyImplementsIncompatibleType,entity:r});a.push(i.error)}return Ke(r.errors,a)}const VJ=Object.freeze(Object.defineProperty({__proto__:null,validate:n1,validateImplementation:s1},Symbol.toStringTag,{value:"Module"}));function BJ(r,a){const e=[];if(r.parent){const i=a.get(r.parent);if(!i)e.push(new w({id:`${r.id}--${r.parent}--${R.ReferencedEntityNotFound}`,code:R.ReferencedEntityNotFound,severity:O.Error,message:`Entity of type "${r.type}" with id "${r.id}", is referencing an entity with id "${r.parent}" that isn't yet found in the project. Perhaps it should be created first. Or perhaps the ID is incorrect.`,issue:null}));else{const s=an(i);if(s){const l=i!==s?`The entity of type '${r.type}' with id '${r.id}' have 'parent' with id '${r.parent}' because the entity belongs to a built-in '${s.type}' entity with id '${s.id}' (${x(s,i.project)}) higher up in the tree.`:`The entity of type '${r.type}' with id '${r.id}' have 'parent' with id '${r.parent}' because it is a built-in entity of type ${s.type}.`;e.push(new w({id:`${r.id}--${R.InvalidBuiltInEntityReference}`,code:R.InvalidBuiltInEntityReference,severity:O.Error,message:l,issue:null}))}else if(![n.DefinitionEntity].includes(i.type))e.push(new w({id:`${r.id}--${r.parent}--${R.InvalidParentReference}`,code:R.InvalidParentReference,severity:O.Error,message:`Entity of type "${r.type}" with id "${r.id}", has a parent reference that isn't pointing to an entity of type 'definition-entity'.`,issue:null}));else{const o=Wt(i).filter(d=>!d.interactive);if(o.length){let d=o.length>1?`The entity of type '${r.type}' with id '${r.id}' can't be added to the 'parent' entity with id '${i.id}' because it extends or implements multiple '${n.BuiltInBaseEntity}' entities that are non-interactive ("${se(o.map(u=>x(u,u.project)),'", "','" and "')}").`:`The entity of type '${r.type}' with id '${r.id}' can't be added to the 'parent' entity with id '${i.id}' because it extends or implements a '${n.BuiltInBaseEntity}' entity that is non-interactive ("${x(o[0],o[0].project)}").`;d+=`
43
43
  ${rn}`,e.push(new w({id:`${r.id}--${R.NonInteractiveEntityReferenced}`,code:R.NonInteractiveEntityReferenced,severity:O.Error,message:d,issue:null}))}else if(r.implements){const d=a.get(r.implements);if(r.id===r.implements)return e.push(new w({id:`${r.id}--${r.implements}--${R.SelfReference}`,code:R.SelfReference,severity:O.Error,message:`Entity of type "${r.type}" with id "${r.id}", has a reference to itself at 'implements'. This is not allowed. Change the reference string or the 'entityId' property of the reference object.`,issue:null})),e;if(!d)e.push(new w({id:`${r.id}--${r.implements}--${R.ReferencedEntityNotFound}`,code:R.ReferencedEntityNotFound,severity:O.Error,message:`Entity of type "${r.type}" with id "${r.id}", is referencing an entity with id "${r.implements}" that isn't yet found in the project. Perhaps it should be created first. Or perhaps the ID is incorrect.`,issue:null}));else{const u=i.properties.find(f=>{var c;return((c=f.implements)==null?void 0:c.id)===r.implements});u?e.push(new w({id:`${r.id}--${$.PropertyOverwritesOtherSiblingWithSameImplementation}`,code:$.PropertyOverwritesOtherSiblingWithSameImplementation,severity:O.Error,message:`The property with id "${r.id}" is trying to implement the property with id "${r.implements}", but the parent entity already has a property with id '${u.id}' that implements the same base property.`,issue:null})):[n.Property].includes(d.type)?d.abstract||e.push(new w({id:`${r.id}--${r.implements}--${R.InvalidImplementsReference}`,code:R.InvalidImplementsReference,severity:O.Error,message:`Entity of type "${r.type}" with id "${r.id}", has an 'implements' reference that isn't pointing to an abstract entity.`,issue:null})):e.push(new w({id:`${r.id}--${r.implements}--${R.InvalidImplementsReference}`,code:R.InvalidImplementsReference,severity:O.Error,message:`Entity of type "${r.type}" with id "${r.id}", has an 'implements' reference that isn't pointing to an entity of type 'property'.`,issue:null}))}}}}}const t=bt(r,{},a);return e.push(...t.errors),e}class lt{constructor(a){h(this,"version");h(this,"previousVersion",null);h(this,"createdAt");h(this,"deleted",!1);h(this,"author");this.version=a.version,this.previousVersion=a.previousVersion,this.createdAt=T(a.createdAt).toISOString(),this.deleted=a.deleted,this.author=a.author}metaSync(a){this.deleted=a.deleted!==void 0?a.deleted:this.deleted}}var Vc=(r=>(r.Manual="manual",r.Automatic="automatic",r))(Vc||{}),A=(r=>(r.Added="added",r.Updated="updated",r.Removed="removed",r.Affected="affected",r))(A||{});class b{constructor(a,e,t,i,s=!1,l=""){h(this,"id",m.UUID.uuid());h(this,"seenEntities",[]);h(this,"added",{});h(this,"updated",{});h(this,"removed",{});h(this,"affected",{});h(this,"self",null);h(this,"author");h(this,"timestamp");h(this,"open",!0);h(this,"dirty",!0);h(this,"type","manual");h(this,"autoclose",!1);h(this,"autoCloseActionName","");h(this,"project");if(this.project=a,this.author=e||m.sessionAuthor||"",this.timestamp=t,this.self=i,this.autoclose=s,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 a;return!(this.isEmpty&&this.self&&!this.affected[(a=this.self)==null?void 0:a.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 a=[...this.addedIds,...this.updatedIds],e=this.project.toFlatIds(),t=$i(),i=e.filter(l=>!t.includes(l));a.filter(l=>!i.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 i=this.get(e);t.version===i.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 i=this.get(e);t.version===i.version&&t.captureVersion()})}async attemptAutocloseAsync(a,e){var t;return this.autoclose&&this.autoCloseActionName&&this.autoCloseActionName===a&&(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.sanitize(),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.project.closePendingChangeSets(),this):(await this.project.closeChangeSet(this),this)}attemptAutoclose(a,e){var t;return this.autoclose&&this.autoCloseActionName&&this.autoCloseActionName===a&&(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:i,updated:s,removed:l,affected:o}=t.recursiveCaptureUpstreamVersions(this.timestamp);for(const d of i)this.add(d,"added");for(const d of s)this.add(d,"updated");for(const d of l)this.add(d,"removed");for(const d of o)this.add(d,"affected")})}sanitize(){this.listAdded.forEach(a=>{a.previousVersion=null})}close(){if(!this.isValid&&this.self&&!this.added[this.self.id]&&!this.updated[this.self.id]&&this.removed[this.self.id],this.discardOrphans(),this.sanitize(),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.project.closePendingChangeSets(),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}addDependentsToAffected(a){Object.values(a.detachedDependents).forEach(e=>{const{entity:t,field:i}=e;this.has(t.id)||this.add(t,"affected")})}get(a){return this.added[a]?this.added[a]:this.updated[a]?this.updated[a]:this.removed[a]?this.removed[a]:null}remove(a){return this.has(a)&&(delete this.added[a],delete this.updated[a],delete this.removed[a],delete this.affected[a],this.seenEntities=this.seenEntities.filter(e=>e!==a)),this}add(a,e){var l,o,d;if(!this.open||!this.dirty)return this;const t=Array.from(new Set([...this.project.getAllBuiltInIds(),...$i()]));if(t.includes(a.id))return this;if(!rd(a,{...this.project.instances,...this.project.builtInInstances}).every(u=>!t.includes(u)))return this;if(this.seenEntities.indexOf(a.id)===-1&&this.seenEntities.push(a.id),e==="removed"){if(this.added[a.id])return delete this.added[a.id],this.seenEntities=this.seenEntities.filter(f=>f!==a.id),delete this.project.deletedInstances[a.id],this;if(this.updated[a.id]&&delete this.updated[a.id],this.affected[a.id]&&delete this.affected[a.id],!this.hasRemoved(a.id)){a.increaseVersion(this.timestamp);const{added:f,updated:c,removed:E,affected:I}=a.recursiveCaptureUpstreamVersions(this.timestamp);for(const D of f)this.add(D,"added");for(const D of c)this.add(D,"updated");for(const D of E)this.add(D,"removed");for(const D of I)this.add(D,"affected")}a.captureVersion();const u=(l=a.knownVersions)==null?void 0:l.get(a.version);if(!u)throw Error(`Version ${a.version} should have a cached version instance but it wasn't found when adding entity to change-set`);return this.removed[a.id]=u,this}if(e==="added"){if(this.removed[a.id])return this;if(this.updated[a.id]&&delete this.updated[a.id],this.affected[a.id]&&delete this.affected[a.id],!this.hasAdded(a.id)){const{added:f,updated:c,removed:E,affected:I}=a.recursiveCaptureUpstreamVersions(this.timestamp);for(const D of f)this.add(D,"added");for(const D of c)this.add(D,"updated");for(const D of E)this.add(D,"removed");for(const D of I)this.add(D,"affected")}a.previousVersion=null,a.captureVersion();const u=(o=a.knownVersions)==null?void 0:o.get(a.version);if(!u)throw Error(`Version ${a.version} should have a cached version instance but it wasn't found when adding entity to change-set`);return this.added[a.id]=u,delete this.affected[a.id],this.addDependentsToAffected(a),this}if(e==="updated"){if(this.removed[a.id])return this;if(this.added[a.id])return a.captureVersion(),this.addDependentsToAffected(a),this;if(this.affected[a.id]&&delete this.affected[a.id],!this.hasUpdated(a.id)){a.increaseVersion(this.timestamp);const{added:f,updated:c,removed:E,affected:I}=a.recursiveCaptureUpstreamVersions(this.timestamp);for(const D of f)this.add(D,"added");for(const D of c)this.add(D,"updated");for(const D of E)this.add(D,"removed");for(const D of I)this.add(D,"affected")}a.captureVersion();const u=(d=a.knownVersions)==null?void 0:d.get(a.version);if(!u)throw Error(`Version ${a.version} should have a cached version instance but it wasn't found when adding entity to change-set`);return this.updated[a.id]=u,this.addDependentsToAffected(a),this}if(e==="affected"){if(this.removed[a.id])return this;if(this.added[a.id])return this;if(this.updated[a.id])return this;this.affected[a.id]=a}return this}toJSON(){const a={},e={},t={},i=new Set;for(const s of Object.values(this.added))a[s.id]=s.toShallowJSON();for(const s of Object.values(this.updated))e[s.id]=s.toShallowJSON();for(const s of Object.values(this.removed))t[s.id]=s.toShallowJSON();for(const s of Object.values(this.affected))i.add(s.id);return{added:a,updated:e,removed:t,affected:Array.from(i),self:this.self?this.self.toShallowJSON():null,seenEntities:this.seenEntities}}has(a){return!!this.added[a]||!!this.removed[a]||!!this.updated[a]||!!this.affected[a]}hasAdded(a){return!!this.added[a]}hasUpdated(a){return!!this.updated[a]}hasRemoved(a){return!!this.removed[a]}hasAffected(a){return!!this.affected[a]}}function _J(r){return new Set([...Object.keys(r.added),...Object.keys(r.updated),...Object.keys(r.removed),...Array.from(r.affected)])}var a1=(r=>(r.PropertyImplements="property-implements",r.PropertyExtends="property-extends",r.DataTypeEntity="data-type-entity",r))(a1||{});const be=class be extends lt{constructor(e,t){super(e);h(this,"initialData");h(this,"id");h(this,"name");h(this,"description",null);h(this,"private");h(this,"abstract");h(this,"index");h(this,"static");h(this,"required");h(this,"constant",!1);h(this,"type",n.Property);h(this,"hidden",!1);h(this,"defaultValue",null);h(this,"dataType",null);h(this,"implements",null);h(this,"extends",null);h(this,"project");h(this,"errors",[]);h(this,"parent");h(this,"detachedDependents",{});h(this,"knownVersions",null);h(this,"activeVersion",!1);h(this,"initialized",!1);h(this,"startedInitialization",!1);h(this,"suggestion",!1);h(this,"_codeNativeValueValidation",null);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 new(e=null){return{id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:(e==null?void 0:e.author)||m.sessionAuthor,previousVersion:null,deleted:!1,type:n.Property,name:"",description:"",dataType:null,implements:null,extends:null,private:!1,abstract:!1,static:!1,constant:!1,hidden:!1,index:0,required:!1,defaultValue:null,parent:null}}static fromGenerationTarget(e,t){const i=_(e.parent),s=t.get(i);let l=null;if(e.implements){const f=_(e.implements);l=t.get(f)}let o=null;if(e.extends){const f=_(e.extends);o=t.get(f)}const d={id:e.id,version:m.UUID.uuid(),createdAt:T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,name:e.name,type:n.Property,index:s.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,extends:o,dataType:null,parent:s},u=C(d,t);return u.setParent(s,null),u.initChildren(null),u}static validateGenerationTarget(e,t){let i=JSON.parse(JSON.stringify(e));const s=[],l=BJ(i,t),o=Oc(i,t);return s.push(...l,...o,...ut(i)),{errors:s,modifiedData:i}}get isExtendedProperty(){const e=this.parent.allBasePropertiesFromExtendedAndImplementedEntities.find(t=>{var i;return t.id===((i=this.extends)==null?void 0:i.id)});return!!e&&e.id!==this.id&&!e.abstract}get codeNativeValueValidation(){var e;return this._codeNativeValueValidation||((e=this.implements)==null?void 0:e.codeNativeValueValidation)||null}validateGeneratedUpdate(e){const t=[];return e.parent&&t.push(new w({id:`${this.id}--${R.InvalidParentUpdate}`,code:R.InvalidParentUpdate,severity:O.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 w({id:`${this.id}--${$.InvalidObjectStructure}`,code:$.InvalidObjectStructure,severity:O.Error,message:`Entity of type '${this.type}' with id '${this.id}' is not a value reading or writing entity.
45
- ${kl}`,issue:null})),{errors:t,modifiedData:e}}subscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]||(this.detachedDependents[t.entity.id]=t)}),this}unsubscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]&&delete this.detachedDependents[t.entity.id]}),this}syncDependents(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-dependents"))){const t=[],i=[],s=[],l=[];return Object.values(this.detachedDependents).forEach(o=>{const d=o.entity.afterAllChildrenInitialized(e);t.push(...d.updated),i.push(...d.added),s.push(...d.removed),l.push(...d.affected)}),e==null||e.attemptAutoclose("sync-dependents",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];if(t==="property-implements"&&(this.setImplements(null,i),s.push(this)),t==="property-extends"){const{updated:u,added:f,removed:c,affected:E}=this.remove({ignoreUpstream:!1},i);s.push(...u),l.push(...f),o.push(...c),d.push(...E)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}onDetachedDependencyRestored(e,t,i){const s=[],l=[],o=[],d=[];if(t==="property-implements"&&(this.setImplements(e,i),s.push(this)),t==="property-extends"){const{updated:u,added:f,removed:c,affected:E}=this.restore({},i);s.push(...u),l.push(...f),o.push(...c),d.push(...E)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}unsubscribeFromDependencies(){var e,t,i,s,l,o,d;return(t=(e=this.implements)==null?void 0:e.unsubscribeDependents)==null||t.call(e,[{entity:this,field:"property-implements"}]),(s=(i=this.extends)==null?void 0:i.unsubscribeDependents)==null||s.call(i,[{entity:this,field:"property-extends"}]),(d=(o=(l=this.dataType)==null?void 0:l.entity)==null?void 0:o.unsubscribeDependents)==null||d.call(o,[{entity:this,field:"data-type-entity"}]),this}subscribeToDependencies(){var e,t,i,s,l,o,d;return(t=(e=this.implements)==null?void 0:e.subscribeDependents)==null||t.call(e,[{entity:this,field:"property-implements"}]),(s=(i=this.extends)==null?void 0:i.subscribeDependents)==null||s.call(i,[{entity:this,field:"property-extends"}]),(d=(o=(l=this.dataType)==null?void 0:l.entity)==null?void 0:o.subscribeDependents)==null||d.call(o,[{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=m.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 be(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=[],i=[],s=[],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),i.push(...o.added),s.push(...o.removed)}return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}async restoreVersion(e){var d;const t=[],i=[],s=[],l=[];if(this.version===e)return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this};if(!this.knownVersions){const u=new Map;for(const[f,c]of this.knownVersions||new Map){if(u.set(f,c),c.activeVersion=!1,c.knownVersions)for(const[E,I]of c.knownVersions)u.set(E,I);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 be(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(i),removed:p(s),affected:p(l),self:this}}hydrateAncestors(){const e=[],t=[],i=[],s=[];if(this.initialData.parent){const l=_(this.initialData.parent),o=this.project.get(l);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${Vt(this.type)} with id '${this.id}' has a parent reference "${l}" which is missing in the project`)}else throw new Error(`${Vt(this.type)} with id '${this.id}' is missing a parent reference`);if(this.initialData.implements){const l=_(this.initialData.implements),o=this.project.get(l);if(o)this.setImplements(o,null),e.push(o);else if(l)throw new Error(`${Vt(this.type)} with id '${this.id}' has a 'implements' reference "${l}" which is missing in the project`)}if(this.initialData.extends){const l=_(this.initialData.extends),o=this.project.get(l);if(o)this.setExtends(o,null),e.push(o);else if(l)throw new Error(`${Vt(this.type)} with id '${this.id}' has a 'extends' reference "${l}" which is missing in the project`)}return{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],i=[],s=[],l=[];return this.initialized=!0,this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addSelfToProject(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-self-to-project"))){const t=[this],i=[],s=[],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(i),removed:p(s),affected:p(l),self:this}}setParent(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"set-parent"))){var i;return((i=this.parent)==null?void 0:i.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,m.sessionAuthor,T().toISOString(),this,!0,"set-implements"))){var i;return((i=this.implements)==null?void 0:i.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}setExtends(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"set-extends"))){var i;return((i=this.extends)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.extends=e,t&&(t==null||t.add(this,A.Updated))),t==null||t.attemptAutoclose("set-extends",this.id),this}initChildren(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,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)}if(this.initialData.extends){const t=C(this.initialData.extends,this.project);this.setExtends(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,m.sessionAuthor,T().toISOString(),this,!0,"meta-sync"))){const i=pt(this,e),s=this.toMeta();return this.name=e.name!==void 0?e.name:s.name,this.description=e.description!==void 0?e.description:s.description,this.abstract=e.abstract!==void 0?e.abstract:s.abstract,this.private=e.private!==void 0?e.private:s.private,this.index=e.index||(e.index!==0?s.index:0),this.static=e.static!==void 0?e.static:s.static,this.hidden=e.hidden!==void 0?e.hidden:s.hidden,this.constant=e.constant!==void 0?e.constant:s.constant,this.required=e.required!==void 0?e.required:s.required,super.metaSync(e),e.deleted===!0&&!s.deleted?t==null||t.add(this,A.Removed):e.deleted===!1&&s.deleted?t==null||t.add(this,A.Added):i&&(t==null||t.add(this,A.Updated)),t==null||t.attemptAutoclose("meta-sync",this.id),this}async APILoad(e=U,...t){return await be.repository.APILoad(this.id,...t),this}async APICreate(e=U,...t){return await be.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=U,...t){return await be.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=U,...t){return await be.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=U,...t){return await be.repository.APIClone(this.id,...t),this}async APILoadVersion(e=U,t,...i){return await be.repository.APILoadVersion(this.id,t,...i)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-entity"))){const i=[],s=[],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(s.push(this),this.unsubscribe(),this.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(d=>{const{updated:u,removed:f,added:c}=d.entity.onDetachedDependencyRemoved(this,d.field,t);i.push(...u),s.push(...f),l.push(...c)}),this.defaultValue){const{updated:d,removed:u}=this.defaultValue.remove({ignoreUpstream:!0},t);i.push(...d),s.push(...u)}if(this.dataType){const{updated:d,removed:u}=this.dataType.remove({ignoreUpstream:!0},t);i.push(...d),s.push(...u)}return e||this.parent.type===n.DefinitionEntity&&(this.parent.removeProperty(this),i.push(this.parent)),t==null||t.attemptAutoclose("remove-entity",this.id),{added:p(l),updated:p(i),removed:p(s),affected:p(o),self:this}}restore({}={},e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"restore-entity"))){const t=[],i=[],s=[],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),Object.values(this.detachedDependents).forEach(o=>{const{updated:d,removed:u,added:f}=o.entity.onDetachedDependencyRestored(this,o.field,e);i.push(...d),s.push(...u),t.push(...f)}),this.defaultValue){const{updated:o}=this.defaultValue.restore({},e);i.push(...o)}if(this.dataType){const{updated:o}=this.dataType.restore({},e);i.push(...o)}return this.parent.type===n.DefinitionEntity&&(this.parent.addProperty(this),i.push(this.parent)),e==null||e.attemptAutoclose("restore-entity",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(l),self:this}}toFlat(e=new Set){var i,s;return e.has(this.id)?[]:(e.add(this.id),[this,...((i=this.defaultValue)==null?void 0:i.toFlat(e))||[],...((s=this.dataType)==null?void 0:s.toFlat(e))||[],...this.parent.toFlat(e)])}toFlatIds(e=new Set){var i,s;return e.has(this.id)?[]:(e.add(this.id),[this.id,...((i=this.defaultValue)==null?void 0:i.toFlatIds(e))||[],...((s=this.dataType)==null?void 0:s.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,i,s,l;return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,index:this.index,private:this.private,required:this.required,static:this.static,constant:this.constant,abstract:this.abstract,hidden:this.hidden,defaultValue:((t=this.defaultValue)==null?void 0:t.toJSON(e))||null,dataType:((i=this.dataType)==null?void 0:i.toJSON(e))||null,implements:((s=this.implements)==null?void 0:s.toJSON(e))||null,extends:((l=this.extends)==null?void 0:l.toJSON(e))||null,parent:this.parent.toReference()})}toJSONClone(e=J){var i,s,l,o,d,u,f;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||yt(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(s=e.seenEntities)!=null&&s.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:m.UUID.uuid(),createdAt:e.timestamp||T().toISOString(),author:m.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:((f=this.dataType)==null?void 0:f.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})(),extends:(()=>{var c;return this.extends&&this.project.getBuiltIn(this.extends.id)?this.extends.toJSON():((c=this.extends)==null?void 0:c.toJSONClone({...e,newId:null}))||null})(),parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps})})}toReference(e=J){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+m.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=J){var i,s,l,o,d;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,name:this.name,description:this.description,type:this.type,index:this.index,private:this.private,required:this.required,abstract:this.abstract,static:this.static,constant:this.constant,hidden:this.hidden,defaultValue:((s=this.defaultValue)==null?void 0:s.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,extends:((d=this.extends)==null?void 0:d.toReference(e))||null,parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){var i,s,l;return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...((i=this.defaultValue)==null?void 0:i.toFlatJSON(e))||[],...((s=this.dataType)==null?void 0:s.toFlatJSON(e))||[],...((l=this.implements)==null?void 0:l.toFlatJSON(e))||[],...this.parent.toFlatJSON(e)])}toGenerationTarget(){var e,t;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,extends:(t=this.extends)==null?void 0:t.id,parent:this.parent.id}}toFlatGenerationTarget(e=new Set){var i,s;return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...((i=this.defaultValue)==null?void 0:i.toFlatGenerationTarget(e))||[],...((s=this.dataType)==null?void 0:s.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=n1(this),this.errors.length,{success:!0,error:null,data:null}}getErrors(){var t,i;return[...this.errors,...((t=this.defaultValue)==null?void 0:t.getErrors())||[],...((i=this.dataType)==null?void 0:i.getErrors())||[]]}getShallowErrors(){return this.errors}clone(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"clone-entity")),t=null,i=null,s=!0){var I,D;let l=mt(t,this);const o=i||m.UUID.uuid();let d=t||this.parent;const u={hidden:!1,id:o,version:m.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,extends:this.extends,parent:d},f=st(u,l);s&&f.subscribe(),f.setParent(d,null),f.initChildren(e),e==null||e.add(f,A.Added);const c=((I=this.dataType)==null?void 0:I.clone(e,f,m.UUID.uuid(),s))||null;c&&f.setDataType(c);const E=(D=this.defaultValue)==null?void 0:D.clone(e,f,m.UUID.uuid(),s);return f.defaultValue=E||null,this.implements&&(f.implements=this.implements),f.addSelfToProject(null),e==null||e.attemptAutoclose("clone-entity",this.id),f}setDataType(e){return this.dataType=e,this}removeDataType(){return this.dataType=null,this}getDataType(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"get-data-type"))){return e==null||e.attemptAutoclose("get-data-type",this.id),this.dataType}getDefaultValue(){return this.defaultValue}setDefaultValue(e){return this.defaultValue=e,this}};h(be,"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,...i)=>null}),h(be,"type",n.Property),h(be,"USER_MANAGED_PARENT_TYPES",[n.DefinitionEntity]),h(be,"PARENT_TYPES",[...be.USER_MANAGED_PARENT_TYPES,n.PrimitiveEntity,n.BuiltInBaseEntity]),h(be,"MUTABLE_BASE_PROPERTIES",["name","description","private","abstract","static","required","constant"]),h(be,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),h(be,"BASE_PROPERTIES",[...be.MUTABLE_BASE_PROPERTIES,...be.INMUTABLE_BASE_PROPERTIES]),h(be,"MUTABLE_META_PROPERTIES",[...be.MUTABLE_BASE_PROPERTIES,"index"]),h(be,"INMUTABLE_META_PROPERTIES",[...be.INMUTABLE_BASE_PROPERTIES]),h(be,"META_PROPERTIES",[...be.MUTABLE_META_PROPERTIES,...be.INMUTABLE_META_PROPERTIES]),h(be,"MUTABLE_UPSTREAM_PROPERTIES",[]),h(be,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","implements","extends"]),h(be,"UPSTREAM_PROPERTIES",[...be.MUTABLE_UPSTREAM_PROPERTIES,...be.INMUTABLE_UPSTREAM_PROPERTIES]),h(be,"MUTABLE_DOWNSTREAM_PROPERTIES",["dataType"]),h(be,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),h(be,"DOWNSTREAM_PROPERTIES",[...be.MUTABLE_DOWNSTREAM_PROPERTIES,...be.INMUTABLE_DOWNSTREAM_PROPERTIES]),h(be,"PROPERTIES",[...be.META_PROPERTIES,...be.UPSTREAM_PROPERTIES,...be.DOWNSTREAM_PROPERTIES]);let gr=be;function o1(r){const a=I7(),e=r.toJSON();a.safeParse(e).success;const i=MJ(r),s=NJ(r),l=pi(r);r.inputs.forEach(d=>d.validate()),l.forEach(d=>d.validate());const o=[...i,...s];if(r.id==="getCompanyByIdEndpointReachedEntityEvent"){const d=de({id:`${r.id}--${F.PropertyImplementsNonAbstact}`,message:`Property "${x(r,r.project)}" with id "${r.id}" implements a non-abstract property "${x(r,r.project)}" with id "${r.id}".`,issue:null,severity:O.Error,code:F.PropertyImplementsNonAbstact,entity:r});o.push(d.error)}return Ke(r.errors,o)}function MJ(r){const a=[];if(!r.calls.length){const e=de({id:`${r.id}--${F.ScopeWithoutLogic}`,message:`Action "${x(r,r.project)}" with id "${r.id}" does not have any logic defined. So it doesn't do anything.`,issue:null,severity:O.Warning,code:F.ScopeWithoutLogic,entity:r});a.push(e.error)}return Ke(r.errors,a)}function NJ(r){const a=[];return r.implements,Ke(r.errors,a)}const LJ=Object.freeze(Object.defineProperty({__proto__:null,validate:o1},Symbol.toStringTag,{value:"Module"}));var l1=(r=>(r.FunctionDeclarationImplements="function-declaration-implements",r.FunctionDeclarationExtends="function-declaration-extends",r))(l1||{});const Re=class Re extends lt{constructor(e,t){super(e);h(this,"initialData");h(this,"id");h(this,"name");h(this,"description",null);h(this,"x");h(this,"y");h(this,"collapsed");h(this,"private");h(this,"index",null);h(this,"type",n.FunctionDeclaration);h(this,"implements",null);h(this,"extends",null);h(this,"inputs",[]);h(this,"calls",[]);h(this,"parent");h(this,"detachedChildren",[]);h(this,"errors",[]);h(this,"project");h(this,"detachedDependents",{});h(this,"knownVersions",null);h(this,"activeVersion",!1);h(this,"initialized",!1);h(this,"startedInitialization",!1);h(this,"suggestion",!1);this.initialData=e,this.project=t,this.id=e.id,this.name=e.name,this.description=e.description,this.private=e.private,this.collapsed=e.collapsed,this.x=e.x,this.y=e.y,this.index=e.index}static new(e=null){return{id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:(e==null?void 0:e.author)||m.sessionAuthor,previousVersion:null,deleted:!1,type:n.FunctionDeclaration,name:"",description:"",collapsed:!1,private:!1,index:null,implements:null,extends:null,inputs:[],parent:null,calls:[],x:0,y:0}}static fromGenerationTarget(e,t){let i=t;if(e.parent){const u=_(e.parent);i=t.get(u)}let s=null;if(e.implements){const u=_(e.implements);s=t.get(u)}let l=null;if(e.extends){const u=_(e.extends);l=t.get(u)}const o={id:e.id,version:m.UUID.uuid(),createdAt:T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,name:e.name,type:n.FunctionDeclaration,index:i.type===n.DefinitionEntity?i.methods.length:null,description:e.description||null,collapsed:!1,private:!1,calls:[],inputs:[],implements:s,extends:l,x:0,y:0,parent:i},d=C(o,t);return d.setParent(i,null),d.initChildren(null),d}static validateGenerationTarget(e,t){var c;let i=JSON.parse(JSON.stringify(e));const s=[],l=bt(i,{parent:{list:!1,types:[n.Project,n.InstalledProject,n.DefinitionEntity,n.Loop],optional:!0},implements:{list:!1,types:[n.ActionDescriptor],optional:!0}},t);i=l.modifiedData;const o=Rc(i,t),d=i.parent?t.get(i.parent):null;if(d&&d.type===n.DefinitionEntity){const E=d,D=Wt(E).filter(P=>!P.interactive);if(D.length){let P=D.length>1?`The entity of type '${e.type}' with id '${e.id}' can't be added to the 'parent' entity with id '${E.id}' because it extends or implements multiple '${n.BuiltInBaseEntity}' entities that are non-interactive ("${se(D.map(V=>x(V,V.project)),'", "','" and "')}").`:`The entity of type '${e.type}' with id '${e.id}' can't be added to the 'parent' entity with id '${E.id}' because it extends or implements a '${n.BuiltInBaseEntity}' entity that is non-interactive ("${x(D[0],D[0].project)}").`;P+=`
45
+ ${kl}`,issue:null})),{errors:t,modifiedData:e}}subscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]||(this.detachedDependents[t.entity.id]=t)}),this}unsubscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]&&delete this.detachedDependents[t.entity.id]}),this}syncDependents(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-dependents"))){const t=[],i=[],s=[],l=[];return Object.values(this.detachedDependents).forEach(o=>{const d=o.entity.afterAllChildrenInitialized(e);t.push(...d.updated),i.push(...d.added),s.push(...d.removed),l.push(...d.affected)}),e==null||e.attemptAutoclose("sync-dependents",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];if(t==="property-implements"&&(this.setImplements(null,i),s.push(this)),t==="property-extends"){const{updated:u,added:f,removed:c,affected:E}=this.remove({ignoreUpstream:!1},i);s.push(...u),l.push(...f),o.push(...c),d.push(...E)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}onDetachedDependencyRestored(e,t,i){const s=[],l=[],o=[],d=[];if(t==="property-implements"&&(this.setImplements(e,i),s.push(this)),t==="property-extends"){const{updated:u,added:f,removed:c,affected:E}=this.restore({},i);s.push(...u),l.push(...f),o.push(...c),d.push(...E)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}unsubscribeFromDependencies(){var e,t,i,s,l,o,d;return(t=(e=this.implements)==null?void 0:e.unsubscribeDependents)==null||t.call(e,[{entity:this,field:"property-implements"}]),(s=(i=this.extends)==null?void 0:i.unsubscribeDependents)==null||s.call(i,[{entity:this,field:"property-extends"}]),(d=(o=(l=this.dataType)==null?void 0:l.entity)==null?void 0:o.unsubscribeDependents)==null||d.call(o,[{entity:this,field:"data-type-entity"}]),this}subscribeToDependencies(){var e,t,i,s,l,o,d;return(t=(e=this.implements)==null?void 0:e.subscribeDependents)==null||t.call(e,[{entity:this,field:"property-implements"}]),(s=(i=this.extends)==null?void 0:i.subscribeDependents)==null||s.call(i,[{entity:this,field:"property-extends"}]),(d=(o=(l=this.dataType)==null?void 0:l.entity)==null?void 0:o.subscribeDependents)==null||d.call(o,[{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=m.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 be(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.extends=this.extends,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],i=[],s=[],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),i.push(...o.added),s.push(...o.removed)}return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}async restoreVersion(e){var d;const t=[],i=[],s=[],l=[];if(this.version===e)return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this};if(!this.knownVersions){const u=new Map;for(const[f,c]of this.knownVersions||new Map){if(u.set(f,c),c.activeVersion=!1,c.knownVersions)for(const[E,I]of c.knownVersions)u.set(E,I);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 be(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(i),removed:p(s),affected:p(l),self:this}}hydrateAncestors(){const e=[],t=[],i=[],s=[];if(this.initialData.parent){const l=_(this.initialData.parent),o=this.project.get(l);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${Vt(this.type)} with id '${this.id}' has a parent reference "${l}" which is missing in the project`)}else throw new Error(`${Vt(this.type)} with id '${this.id}' is missing a parent reference`);if(this.initialData.implements){const l=_(this.initialData.implements),o=this.project.get(l);if(o)this.setImplements(o,null),e.push(o);else if(l)throw new Error(`${Vt(this.type)} with id '${this.id}' has a 'implements' reference "${l}" which is missing in the project`)}if(this.initialData.extends){const l=_(this.initialData.extends),o=this.project.get(l);if(o)this.setExtends(o,null),e.push(o);else if(l)throw new Error(`${Vt(this.type)} with id '${this.id}' has a 'extends' reference "${l}" which is missing in the project`)}return{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],i=[],s=[],l=[];return this.initialized=!0,this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addSelfToProject(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-self-to-project"))){const t=[this],i=[],s=[],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(i),removed:p(s),affected:p(l),self:this}}setParent(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"set-parent"))){var i;return((i=this.parent)==null?void 0:i.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,m.sessionAuthor,T().toISOString(),this,!0,"set-implements"))){var i;return((i=this.implements)==null?void 0:i.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}setExtends(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"set-extends"))){var i;return((i=this.extends)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.extends=e,t&&(t==null||t.add(this,A.Updated))),t==null||t.attemptAutoclose("set-extends",this.id),this}initChildren(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,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)}if(this.initialData.extends){const t=C(this.initialData.extends,this.project);this.setExtends(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,m.sessionAuthor,T().toISOString(),this,!0,"meta-sync"))){const i=pt(this,e),s=this.toMeta();return this.name=e.name!==void 0?e.name:s.name,this.description=e.description!==void 0?e.description:s.description,this.abstract=e.abstract!==void 0?e.abstract:s.abstract,this.private=e.private!==void 0?e.private:s.private,this.index=e.index||(e.index!==0?s.index:0),this.static=e.static!==void 0?e.static:s.static,this.hidden=e.hidden!==void 0?e.hidden:s.hidden,this.constant=e.constant!==void 0?e.constant:s.constant,this.required=e.required!==void 0?e.required:s.required,super.metaSync(e),e.deleted===!0&&!s.deleted?t==null||t.add(this,A.Removed):e.deleted===!1&&s.deleted?t==null||t.add(this,A.Added):i&&(t==null||t.add(this,A.Updated)),t==null||t.attemptAutoclose("meta-sync",this.id),this}async APILoad(e=U,...t){return await be.repository.APILoad(this.id,...t),this}async APICreate(e=U,...t){return await be.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=U,...t){return await be.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=U,...t){return await be.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=U,...t){return await be.repository.APIClone(this.id,...t),this}async APILoadVersion(e=U,t,...i){return await be.repository.APILoadVersion(this.id,t,...i)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-entity"))){const i=[],s=[],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(s.push(this),this.unsubscribe(),this.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(d=>{const{updated:u,removed:f,added:c}=d.entity.onDetachedDependencyRemoved(this,d.field,t);i.push(...u),s.push(...f),l.push(...c)}),this.defaultValue){const{updated:d,removed:u}=this.defaultValue.remove({ignoreUpstream:!0},t);i.push(...d),s.push(...u)}if(this.dataType){const{updated:d,removed:u}=this.dataType.remove({ignoreUpstream:!0},t);i.push(...d),s.push(...u)}return e||this.parent.type===n.DefinitionEntity&&(this.parent.removeProperty(this),i.push(this.parent)),t==null||t.attemptAutoclose("remove-entity",this.id),{added:p(l),updated:p(i),removed:p(s),affected:p(o),self:this}}restore({}={},e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"restore-entity"))){const t=[],i=[],s=[],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),Object.values(this.detachedDependents).forEach(o=>{const{updated:d,removed:u,added:f}=o.entity.onDetachedDependencyRestored(this,o.field,e);i.push(...d),s.push(...u),t.push(...f)}),this.defaultValue){const{updated:o}=this.defaultValue.restore({},e);i.push(...o)}if(this.dataType){const{updated:o}=this.dataType.restore({},e);i.push(...o)}return this.parent.type===n.DefinitionEntity&&(this.parent.addProperty(this),i.push(this.parent)),e==null||e.attemptAutoclose("restore-entity",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(l),self:this}}toFlat(e=new Set){var i,s;return e.has(this.id)?[]:(e.add(this.id),[this,...((i=this.defaultValue)==null?void 0:i.toFlat(e))||[],...((s=this.dataType)==null?void 0:s.toFlat(e))||[],...this.parent.toFlat(e)])}toFlatIds(e=new Set){var i,s;return e.has(this.id)?[]:(e.add(this.id),[this.id,...((i=this.defaultValue)==null?void 0:i.toFlatIds(e))||[],...((s=this.dataType)==null?void 0:s.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,i,s,l;return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,index:this.index,private:this.private,required:this.required,static:this.static,constant:this.constant,abstract:this.abstract,hidden:this.hidden,defaultValue:((t=this.defaultValue)==null?void 0:t.toJSON(e))||null,dataType:((i=this.dataType)==null?void 0:i.toJSON(e))||null,implements:((s=this.implements)==null?void 0:s.toJSON(e))||null,extends:((l=this.extends)==null?void 0:l.toJSON(e))||null,parent:this.parent.toReference()})}toJSONClone(e=J){var i,s,l,o,d,u,f;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||yt(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(s=e.seenEntities)!=null&&s.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:m.UUID.uuid(),createdAt:e.timestamp||T().toISOString(),author:m.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:((f=this.dataType)==null?void 0:f.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})(),extends:(()=>{var c;return this.extends&&this.project.getBuiltIn(this.extends.id)?this.extends.toJSON():((c=this.extends)==null?void 0:c.toJSONClone({...e,newId:null}))||null})(),parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps})})}toReference(e=J){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+m.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=J){var i,s,l,o,d;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,name:this.name,description:this.description,type:this.type,index:this.index,private:this.private,required:this.required,abstract:this.abstract,static:this.static,constant:this.constant,hidden:this.hidden,defaultValue:((s=this.defaultValue)==null?void 0:s.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,extends:((d=this.extends)==null?void 0:d.toReference(e))||null,parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){var i,s,l;return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...((i=this.defaultValue)==null?void 0:i.toFlatJSON(e))||[],...((s=this.dataType)==null?void 0:s.toFlatJSON(e))||[],...((l=this.implements)==null?void 0:l.toFlatJSON(e))||[],...this.parent.toFlatJSON(e)])}toGenerationTarget(){var e,t;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,extends:(t=this.extends)==null?void 0:t.id,parent:this.parent.id}}toFlatGenerationTarget(e=new Set){var i,s;return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...((i=this.defaultValue)==null?void 0:i.toFlatGenerationTarget(e))||[],...((s=this.dataType)==null?void 0:s.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=n1(this),this.errors.length,{success:!0,error:null,data:null}}getErrors(){var t,i;return[...this.errors,...((t=this.defaultValue)==null?void 0:t.getErrors())||[],...((i=this.dataType)==null?void 0:i.getErrors())||[]]}getShallowErrors(){return this.errors}clone(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"clone-entity")),t=null,i=null,s=!0){var I,D;let l=mt(t,this);const o=i||m.UUID.uuid();let d=t||this.parent;const u={hidden:!1,id:o,version:m.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,extends:this.extends,parent:d},f=st(u,l);s&&f.subscribe(),f.setParent(d,null),f.initChildren(e),e==null||e.add(f,A.Added);const c=((I=this.dataType)==null?void 0:I.clone(e,f,m.UUID.uuid(),s))||null;c&&f.setDataType(c);const E=(D=this.defaultValue)==null?void 0:D.clone(e,f,m.UUID.uuid(),s);return f.defaultValue=E||null,this.implements&&(f.implements=this.implements),f.addSelfToProject(null),e==null||e.attemptAutoclose("clone-entity",this.id),f}setDataType(e){return this.dataType=e,this}removeDataType(){return this.dataType=null,this}getDataType(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"get-data-type"))){return e==null||e.attemptAutoclose("get-data-type",this.id),this.dataType}getDefaultValue(){return this.defaultValue}setDefaultValue(e){return this.defaultValue=e,this}};h(be,"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,...i)=>null}),h(be,"type",n.Property),h(be,"USER_MANAGED_PARENT_TYPES",[n.DefinitionEntity]),h(be,"PARENT_TYPES",[...be.USER_MANAGED_PARENT_TYPES,n.PrimitiveEntity,n.BuiltInBaseEntity]),h(be,"MUTABLE_BASE_PROPERTIES",["name","description","private","abstract","static","required","constant"]),h(be,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),h(be,"BASE_PROPERTIES",[...be.MUTABLE_BASE_PROPERTIES,...be.INMUTABLE_BASE_PROPERTIES]),h(be,"MUTABLE_META_PROPERTIES",[...be.MUTABLE_BASE_PROPERTIES,"index"]),h(be,"INMUTABLE_META_PROPERTIES",[...be.INMUTABLE_BASE_PROPERTIES]),h(be,"META_PROPERTIES",[...be.MUTABLE_META_PROPERTIES,...be.INMUTABLE_META_PROPERTIES]),h(be,"MUTABLE_UPSTREAM_PROPERTIES",[]),h(be,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","implements","extends"]),h(be,"UPSTREAM_PROPERTIES",[...be.MUTABLE_UPSTREAM_PROPERTIES,...be.INMUTABLE_UPSTREAM_PROPERTIES]),h(be,"MUTABLE_DOWNSTREAM_PROPERTIES",["dataType"]),h(be,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),h(be,"DOWNSTREAM_PROPERTIES",[...be.MUTABLE_DOWNSTREAM_PROPERTIES,...be.INMUTABLE_DOWNSTREAM_PROPERTIES]),h(be,"PROPERTIES",[...be.META_PROPERTIES,...be.UPSTREAM_PROPERTIES,...be.DOWNSTREAM_PROPERTIES]);let gr=be;function o1(r){const a=I7(),e=r.toJSON();a.safeParse(e).success;const i=MJ(r),s=NJ(r),l=pi(r);r.inputs.forEach(d=>d.validate()),l.forEach(d=>d.validate());const o=[...i,...s];if(r.id==="getCompanyByIdEndpointReachedEntityEvent"){const d=de({id:`${r.id}--${F.PropertyImplementsNonAbstact}`,message:`Property "${x(r,r.project)}" with id "${r.id}" implements a non-abstract property "${x(r,r.project)}" with id "${r.id}".`,issue:null,severity:O.Error,code:F.PropertyImplementsNonAbstact,entity:r});o.push(d.error)}return Ke(r.errors,o)}function MJ(r){const a=[];if(!r.calls.length){const e=de({id:`${r.id}--${F.ScopeWithoutLogic}`,message:`Action "${x(r,r.project)}" with id "${r.id}" does not have any logic defined. So it doesn't do anything.`,issue:null,severity:O.Warning,code:F.ScopeWithoutLogic,entity:r});a.push(e.error)}return Ke(r.errors,a)}function NJ(r){const a=[];return r.implements,Ke(r.errors,a)}const LJ=Object.freeze(Object.defineProperty({__proto__:null,validate:o1},Symbol.toStringTag,{value:"Module"}));var l1=(r=>(r.FunctionDeclarationImplements="function-declaration-implements",r.FunctionDeclarationExtends="function-declaration-extends",r))(l1||{});const Re=class Re extends lt{constructor(e,t){super(e);h(this,"initialData");h(this,"id");h(this,"name");h(this,"description",null);h(this,"x");h(this,"y");h(this,"collapsed");h(this,"private");h(this,"index",null);h(this,"type",n.FunctionDeclaration);h(this,"implements",null);h(this,"extends",null);h(this,"inputs",[]);h(this,"calls",[]);h(this,"parent");h(this,"detachedChildren",[]);h(this,"errors",[]);h(this,"project");h(this,"detachedDependents",{});h(this,"knownVersions",null);h(this,"activeVersion",!1);h(this,"initialized",!1);h(this,"startedInitialization",!1);h(this,"suggestion",!1);this.initialData=e,this.project=t,this.id=e.id,this.name=e.name,this.description=e.description,this.private=e.private,this.collapsed=e.collapsed,this.x=e.x,this.y=e.y,this.index=e.index}static new(e=null){return{id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:(e==null?void 0:e.author)||m.sessionAuthor,previousVersion:null,deleted:!1,type:n.FunctionDeclaration,name:"",description:"",collapsed:!1,private:!1,index:null,implements:null,extends:null,inputs:[],parent:null,calls:[],x:0,y:0}}static fromGenerationTarget(e,t){let i=t;if(e.parent){const u=_(e.parent);i=t.get(u)}let s=null;if(e.implements){const u=_(e.implements);s=t.get(u)}let l=null;if(e.extends){const u=_(e.extends);l=t.get(u)}const o={id:e.id,version:m.UUID.uuid(),createdAt:T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,name:e.name,type:n.FunctionDeclaration,index:i.type===n.DefinitionEntity?i.methods.length:null,description:e.description||null,collapsed:!1,private:!1,calls:[],inputs:[],implements:s,extends:l,x:0,y:0,parent:i},d=C(o,t);return d.setParent(i,null),d.initChildren(null),d}static validateGenerationTarget(e,t){var c;let i=JSON.parse(JSON.stringify(e));const s=[],l=bt(i,{parent:{list:!1,types:[n.Project,n.InstalledProject,n.DefinitionEntity,n.Loop],optional:!0},implements:{list:!1,types:[n.ActionDescriptor],optional:!0}},t);i=l.modifiedData;const o=Rc(i,t),d=i.parent?t.get(i.parent):null;if(d&&d.type===n.DefinitionEntity){const E=d,D=Wt(E).filter(P=>!P.interactive);if(D.length){let P=D.length>1?`The entity of type '${e.type}' with id '${e.id}' can't be added to the 'parent' entity with id '${E.id}' because it extends or implements multiple '${n.BuiltInBaseEntity}' entities that are non-interactive ("${se(D.map(V=>x(V,V.project)),'", "','" and "')}").`:`The entity of type '${e.type}' with id '${e.id}' can't be added to the 'parent' entity with id '${E.id}' because it extends or implements a '${n.BuiltInBaseEntity}' entity that is non-interactive ("${x(D[0],D[0].project)}").`;P+=`
46
46
  ${rn}`,s.push(new w({id:`${e.id}--${R.NonInteractiveEntityReferenced}`,code:R.NonInteractiveEntityReferenced,severity:O.Error,message:P,issue:null}))}else{const P=E.methods.find(G=>{var B;return((B=G.implements)==null?void 0:B.id)===i.implements});P&&s.push(new w({id:`${i.id}--${$.MethodOverwritesOtherSiblingWithSameImplementation}`,code:$.MethodOverwritesOtherSiblingWithSameImplementation,severity:O.Error,message:`The '${n.FunctionDeclaration}' with id "${i.id}" is trying to implement the '${n.ActionDescriptor}' with id "${i.implements}", but the parent definition-entity already has a ${n.FunctionDeclaration} with id '${P.id}' that implements the same base method.
47
47
  A ${n.FunctionDeclaration} that has a parent of type '${n.DefinitionEntity}' is considered a method of that entity, and cannot implement the same '${n.ActionDescriptor}' more than once.
48
48
  ${n.ActionDescriptor} entities inside a ${n.DefinitionEntity} are considered abstract methods that can be implemented by ${n.FunctionDeclaration} entities inside the same parent.
@@ -52,7 +52,7 @@ If you want to implement a new method, you can create a new 'function-declaratio
52
52
  If you want to modify the existing implementation, you can update the existing method instead, but it will have to match the same base ${n.ActionDescriptor} signature, otherwise the implementation will have a validation error.`,issue:null}))}}else if(d&&d.type===n.Loop){const E=d.body;E&&((c=E.implements)==null?void 0:c.id)===i.implements&&s.push(new w({id:`${i.id}--${$.LoopBodyFunctionOverwrite}`,code:$.LoopBodyFunctionOverwrite,severity:O.Error,message:`The '${n.FunctionDeclaration}' with id "${i.id}" is being added as the 'body' of the ${n.Loop} with id "${d.id}", but the loop already has a function-declaration body. A loop can only have one function-declaration body at a time. You can edit the existing body instead, but it will have to match the same base signature, otherwise the implementation will have a validation error.`,issue:null}))}const u=i.parent&&t.get(i.parent)||t.getBuiltIn(i.parent),f=u?an(u):null;return f&&s.push(new w({id:`${e.id}--${R.BuiltInEntityParent}`,code:R.BuiltInEntityParent,severity:O.Error,message:`The entity with id '${e.id}' and type '${e.type}', belongs to a built-in system entity "${x(f,t)}" with id '${f.id}', and therefore it cannot be created as it would affect a built in entity, which are inmutable.`,issue:null})),s.push(...l.errors,...o,...ut(i)),{errors:s,modifiedData:i}}get isExtendedMethod(){if(this.parent.type!==n.DefinitionEntity)return!1;const e=this.parent.allBaseMethodsFromExtendedAndImplementedEntities.find(t=>{var i;return t.id===((i=this.extends)==null?void 0:i.id)});return!!e&&e.id!==this.id&&e.type!==n.ActionDescriptor}get returnStatements(){return Ee(this).filter(i=>i.type===n.ReturnStatement&&i.parent.id===this.id)}validateGeneratedUpdate(e){const t=[];return e.parent&&(this.parent.type===n.Project?t.push(new w({id:`${this.id}--${R.InvalidParentUpdate}`,code:R.InvalidParentUpdate,severity:O.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.
53
53
  This is likely an incorrect strategy because this is a globally declared '${this.type}' entity which can only have the root project as its parent.`,issue:null})):t.push(new w({id:`${this.id}--${R.InvalidParentUpdate}`,code:R.InvalidParentUpdate,severity:O.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.
54
54
  This is likely an incorrect strategy because this function declaration is a method, since it belongs to a '${this.parent.type}' entity, 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.
55
- Please consider than any updates might affect the overlap with the signature of the parent entity's action descriptors.`,issue:null}))),{errors:t,modifiedData:e}}subscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]||(this.detachedDependents[t.entity.id]=t)}),this}unsubscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]&&delete this.detachedDependents[t.entity.id]}),this}syncDependents(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-dependents"))){const t=[],i=[],s=[],l=[];return Object.values(this.detachedDependents).forEach(o=>{const d=o.entity.afterAllChildrenInitialized(e);t.push(...d.updated),i.push(...d.added),s.push(...d.removed),l.push(...d.affected)}),e==null||e.attemptAutoclose("sync-dependents",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];if(t==="function-declaration-implements"&&this.setImplements(null,i),t==="function-declaration-extends"){const{updated:u,added:f,removed:c,affected:E}=this.remove({ignoreUpstream:!1},i);s.push(...u),l.push(...f),o.push(...c),d.push(...E)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}onDetachedDependencyRestored(e,t,i){const s=[],l=[],o=[],d=[];if(t==="function-declaration-implements"&&(this.setImplements(e,i),s.push(e)),t==="function-declaration-extends"){const{updated:u,added:f,removed:c,affected:E}=this.restore({},i);s.push(...u),l.push(...f),o.push(...c),d.push(...E)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}unsubscribeFromDependencies(){var e,t;return(e=this.implements)==null||e.unsubscribeDependents([{entity:this,field:"function-declaration-implements"}]),(t=this.extends)==null||t.unsubscribeDependents([{entity:this,field:"function-declaration-extends"}]),this}subscribeToDependencies(){var e,t;return(e=this.implements)==null||e.subscribeDependents([{entity:this,field:"function-declaration-implements"}]),(t=this.extends)==null||t.subscribeDependents([{entity:this,field:"function-declaration-extends"}]),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=m.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 Re(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.calls=this.calls,e.implements=this.implements,e.detachedChildren=this.detachedChildren,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],i=[],s=[],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),i.push(...o.added),s.push(...o.removed)}return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}async restoreVersion(e){var d;const t=[],i=[],s=[],l=[];if(this.version===e)return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this};if(!this.knownVersions){const u=new Map;for(const[f,c]of this.knownVersions||new Map){if(u.set(f,c),c.activeVersion=!1,c.knownVersions)for(const[E,I]of c.knownVersions)u.set(E,I);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 Re(u,this.project)}return this.metaSync(o.toShallowJSON(),null),this.inputs=o.inputs,this.calls=o.calls,this.implements=o.implements,this.detachedChildren=o.detachedChildren,this.parent=o.parent,{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}hydrateAncestors(){const e=[],t=[],i=[],s=[];if(this.initialData.parent){const l=_(this.initialData.parent),o=this.project.get(l);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${Vt(this.type)} with id '${this.id}' has a 'parent' reference "${l}" which is missing in the project`)}else throw new Error(`${Vt(this.type)} with id '${this.id}' is missing a 'parent' reference`);if(this.initialData.implements){const l=_(this.initialData.implements),o=this.project.get(l);if(o)this.setImplements(o,null),e.push(o);else if(l)throw new Error(`${Vt(this.type)} with id '${this.id}' has a 'implements' reference "${l}" which is missing in the project`)}if(this.initialData.extends){const l=_(this.initialData.extends),o=this.project.get(l);if(o)this.setExtends(o,null),e.push(o);else if(l)throw new Error(`${Vt(this.type)} with id '${this.id}' has a 'extends' reference "${l}" which is missing in the project`)}return{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],i=[],s=[],l=[];return this.initialized=!0,this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addSelfToProject(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-self-to-project"))){const t=[this],i=[],s=[],l=[];return this.parent===this.project?this.project.addFunctionDeclaration(this):this.parent.type===n.DefinitionEntity?(this.parent.addMethod(this),t.push(this.parent)):this.parent.type===n.Loop&&(this.parent.setBody(this),t.push(this.parent)),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}replaceDetachedChild(e,t){const i=this.detachedChildren.indexOf(e);return i!==-1&&(this.detachedChildren[i]=t),this}subscribeDetachedChild(e){return this.detachedChildren.includes(e)||this.detachedChildren.push(e),this}addInputDeclaration(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-input-declaration"))){return this.inputs.includes(e)?(t==null||t.attemptAutoclose("add-input-declaration",this.id),this):(this.inputs.push(e),t==null||t.attemptAutoclose("add-input-declaration",this.id),this)}removeInputDeclaration(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-input-declaration"))){const i=this.inputs.findIndex(s=>s.id===e.id);return i>-1&&(this.inputs.splice(i,1),t&&(t==null||t.add(this,A.Affected))),t==null||t.attemptAutoclose("remove-input-declaration",this.id),this}setParent(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"set-parent"))){var i;return((i=this.parent)==null?void 0:i.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,m.sessionAuthor,T().toISOString(),this,!0,"set-implements"))){var i;return((i=this.implements)==null?void 0:i.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}setExtends(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"set-extends"))){var i;return((i=this.extends)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.extends=e,t&&(t==null||t.add(this,A.Updated))),t==null||t.attemptAutoclose("set-extends",this.id),this}addCall(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-call"))){return this.calls.includes(e)||(this.calls.push(e),t==null||t.add(e,A.Affected)),t==null||t.attemptAutoclose("add-call",this.id),this}removeCall(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-call"))){const i=this.calls.indexOf(e);return i!==-1&&(this.calls.splice(i,1),t==null||t.add(e,A.Affected)),t==null||t.attemptAutoclose("remove-call",this.id),this}initChildren(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.inputs=this.initialData.inputs.map(t=>{const i=C(t,this.project);return i.setParent(this,null),i.initChildren(e),i}),this.calls=this.initialData.calls.map(t=>{const i=C(t,this.project);return i.addEntryCaller(this,null),[n.BreakStatement,n.ContinueStatement].includes(i.type)?(i.setParent(this.parent,null),i.initChildren(e)):i.type!==n.InternalCall&&(i.setParent(this,null),i.initChildren(e)),i}),this.initialData.implements&&(this.implements=C(this.initialData.implements,this.project)),this.initialData.extends&&(this.extends=C(this.initialData.extends,this.project)),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,m.sessionAuthor,T().toISOString(),this,!0,"meta-sync"))){const i=pt(this,e),s=this.toMeta();return this.name=e.name!==void 0?e.name:s.name,this.description=e.description!==void 0?e.description:s.description,this.private=e.private!==void 0?e.private:this.private,this.index=e.index||(e.index!==0?s.index:0),this.collapsed=e.collapsed!==void 0?e.collapsed:s.collapsed,this.x=e.x||s.x,this.y=e.y||s.y,super.metaSync(e),e.deleted===!0&&!s.deleted?t==null||t.add(this,A.Removed):e.deleted===!1&&s.deleted?t==null||t.add(this,A.Added):i&&(t==null||t.add(this,A.Updated)),t==null||t.attemptAutoclose("meta-sync",this.id),this}async APILoad(e=U,...t){return await Re.repository.APILoad(this.id,...t),this}async APICreate(e=U,...t){return await Re.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=U,...t){return await Re.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=U,...t){return await Re.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=U,...t){return await Re.repository.APIClone(this.id,...t),this}async APILoadVersion(e=U,t,...i){return await Re.repository.APILoadVersion(this.id,t,...i)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-entity"))){const i=[],s=[],l=[],o=[];return t!=null&&t.hasRemoved(this.id)?(t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(s.push(this),this.unsubscribe(),this.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(u=>{const{updated:f,removed:c,added:E}=u.entity.onDetachedDependencyRemoved(this,u.field,t);i.push(...f),s.push(...c),l.push(...E)}),this.inputs.forEach(u=>{const{updated:f,removed:c}=u.remove({ignoreUpstream:!0},t);i.push(...f),s.push(...c)}),pi(this).forEach(u=>{const{updated:f,removed:c}=u.remove({ignoreUpstream:!0},t);i.push(...f),s.push(...c)}),this.parent.type===n.DefinitionEntity&&!e&&(this.parent.removeMethod(this),t==null||t.add(this.parent,A.Affected),i.push(this.parent)),t==null||t.attemptAutoclose("remove-entity",this.id),{added:p(l),updated:p(i),removed:p(s),affected:p(o),self:this})}restore({}={},e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"restore-entity"))){const t=[],i=[],s=[],l=[];return e!=null&&e.hasAdded(this.id)?(e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),Object.values(this.detachedDependents).forEach(d=>{const{updated:u,removed:f,added:c}=d.entity.onDetachedDependencyRestored(this,d.field,e);i.push(...u),s.push(...f),t.push(...c)}),this.inputs.forEach(d=>{const{updated:u}=d.restore({},e);i.push(...u)}),pi(this).forEach(d=>{const{updated:u}=d.restore({},e);i.push(...u)}),this.parent.type===n.DefinitionEntity&&(this.parent.addMethod(this),e==null||e.add(this.parent,A.Affected),i.push(this.parent)),e==null||e.attemptAutoclose("restore-entity",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(l),self:this})}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.inputs.flatMap(i=>i.toFlat(e)),...this.calls.flatMap(i=>i.toFlat(e)),...this.returnStatements.flatMap(i=>i.toFlat(e)),...this.implements?this.implements.toFlat(e):[]])}toFlatIds(e=new Set){if(e.has(this.id))return[];e.add(this.id);const t=pi(this);return[this.id,...this.inputs.flatMap(s=>s.toFlatIds(e)),...this.calls.flatMap(s=>s.toFlatIds(e)),...this.returnStatements.flatMap(s=>s.toFlatIds(e)),...this.implements?this.implements.toFlatIds(e):[],...t.flatMap(s=>s.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,collapsed:this.collapsed,private:this.private,index:this.index,x:this.x,y:this.y,type:this.type,name:this.name}}toJSON(e=new Set){var t,i;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,x:this.x,y:this.y,collapsed:this.collapsed,private:this.private,calls:this.calls.map(s=>s.toJSON(e)),inputs:this.inputs.map(s=>s.toJSON(e)),implements:((t=this.implements)==null?void 0:t.toJSON(e))||null,extends:((i=this.extends)==null?void 0:i.toJSON(e))||null,parent:this.parent.toReference()})}toJSONClone(e=J){var i,s,l,o,d;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||yt(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(s=e.seenEntities)!=null&&s.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:m.UUID.uuid(),createdAt:e.timestamp||T().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,index:this.index,x:this.x,y:this.y,collapsed:this.collapsed,private:this.private,calls:this.calls.map(u=>u.toJSONClone({...e,newId:null})),inputs:this.inputs.map(u=>u.toJSONClone({...e,newId:null})),implements:(()=>{var u;return this.implements&&this.project.getBuiltIn(this.implements.id)?this.implements.toJSON():(u=this.implements)==null?void 0:u.toJSONClone({...e,newId:null})})(),extends:(()=>{var u;return this.extends&&this.project.getBuiltIn(this.extends.id)?this.extends.toJSON():(u=this.extends)==null?void 0:u.toJSONClone({...e,newId:null})})(),parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps})})}toReference(e=J){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+m.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=J){var i,s,l;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,index:this.index,collapsed:this.collapsed,private:this.private,x:this.x,y:this.y,inputs:this.inputs.map(o=>o.toReference(e)),calls:this.calls.map(o=>o.toReference(e)),implements:((s=this.implements)==null?void 0:s.toReference(e))||null,extends:((l=this.extends)==null?void 0:l.toReference(e))||null,parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.inputs.flatMap(i=>i.toFlatJSON(e)),...this.calls.flatMap(i=>i.toFlatJSON(e)),...this.returnStatements.flatMap(i=>i.toFlatJSON(e)),...this.implements?this.implements.toFlatJSON(e):[]])}toGenerationTarget(){var t,i;const e=this.parent.type===n.Project?void 0:this.parent.id;return{id:this.id,name:this.name,description:this.description||void 0,type:this.type,private:this.private,implements:((t=this.implements)==null?void 0:t.id)||void 0,extends:((i=this.extends)==null?void 0:i.id)||void 0,parent:e}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...this.inputs.flatMap(i=>i.toFlatGenerationTarget(e)),...this.calls.flatMap(i=>i.toFlatGenerationTarget(e)),...this.returnStatements.flatMap(i=>i.toFlatGenerationTarget(e))])}clearErrors(){return this.errors=[],this.inputs.forEach(e=>e.clearErrors()),this.calls.forEach(e=>e.clearErrors()),this.returnStatements.forEach(e=>e.clearErrors()),this}validate(){const e=o1(this);return this.errors=[...e],{success:!0,error:null,data:this.toJSON()}}getErrors(){const e=pi(this);return[...this.errors,...this.inputs.flatMap(i=>i.getErrors()),...e.flatMap(i=>i.getErrors())]}getShallowErrors(){return this.errors}clone(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"clone-entity")),t=null,i=null,s=!0,l=!1){var P;let o=mt(t,this);const d=this.toJSON(),u=i||m.UUID.uuid();d.inputs=[],d.calls=[];const f=u.split("-id"),c=f[f.length-1||0]||u;d.id=u,d.version=m.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 E=st(d,o);t?E.setParent(t,null):E.setParent(this.parent,null),s&&E.subscribe(),E.initChildren(e),e==null||e.add(E,A.Added);const I=(P=this.inputs)==null?void 0:P.map((V,M)=>V.clone(e,E,c+"-argument-declaration-"+M+"-id",s));return E.inputs=I,l?(pi(this).map((V,M)=>V.clone(e,E,c+"-body-entity-"+M+"-id")),e==null||e.attemptAutoclose("clone-entity",this.id),E):(e==null||e.attemptAutoclose("clone-entity",this.id),E)}getVariableInstances(){return He(this).filter(i=>i.type===n.VariableInstance)}getArgument(e){return this.inputs.find(t=>t.id===e)||null}createCall(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"create-call")),t=this.project,i={}){const s={id:i.id||m.UUID.uuid(),version:i.version||m.UUID.uuid(),createdAt:i.createdAt||(e==null?void 0:e.timestamp)||T().toISOString(),author:i.author||m.sessionAuthor||"1",previousVersion:i.previousVersion||null,deleted:i.deleted||!1,type:n.FunctionCall,parent:t.toReference(),successCalls:i.successCalls||[],errorCalls:i.errorCalls||[],inputs:i.inputs||[],outputs:i.outputs||[],error:i.error||null,process:i.process||null,calledBySuccess:i.calledBySuccess||[],calledByError:i.calledByError||[],calledByEntry:i.calledByEntry||[],declaration:this.toJSON(),x:0,y:0},l=C(s,this.project);return l.hydrateAncestors(),e==null||e.add(l,A.Added),l.addSelfToProject(e),l.setParent(t,e),l.initChildren(e),l.afterAllChildrenInitialized(e),e==null||e.add(l,A.Added),e==null||e.attemptAutoclose("create-call",this.id),l}createInternalCall(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"create-internal")),t,i={}){const s={id:i.id||m.UUID.uuid(),version:i.version||m.UUID.uuid(),createdAt:i.createdAt||(e==null?void 0:e.timestamp)||T().toISOString(),author:i.author||m.sessionAuthor||"1",previousVersion:i.previousVersion||null,deleted:i.deleted||!1,type:n.InternalCall,parent:t.toReference(),successCalls:i.successCalls||[],errorCalls:i.errorCalls||[],inputs:i.inputs||[],outputs:i.outputs||[],error:i.error||null,process:i.process||null,calledBySuccess:i.calledBySuccess||[],calledByError:i.calledByError||[],calledByEntry:i.calledByEntry||[],declaration:this.toShallowJSON(),index:t.internalCalls.length},l=C(s,this.project);return l.hydrateAncestors(),e==null||e.add(l,A.Added),l.addSelfToProject(e),l.setParent(t,e),l.initChildren(e),l.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("create-internal",this.id),l}addReturnStatement(e){return this.returnStatements.includes(e)||this.returnStatements.push(e),this}removeReturnStatement(e){const t=this.returnStatements.indexOf(e);return t!==-1&&this.returnStatements.splice(t,1),this}getUniqueReturnDeclarations(){const e=[],i=[...this.returnStatements].flatMap(s=>s.outputs);if(this.implements){const s=this.implements.outputs;return i.forEach(l=>{const o=s.find(u=>u===l.implements),d=e.find(u=>u.implements===l.implements);o&&!d&&e.push(l)}),p(e)}else return i.forEach(s=>{e.find(o=>o===s||x(o,this.project)===x(s,this.project)&&wi(o.dataType,s.dataType))||e.push(s)}),p(e)}};h(Re,"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,...i)=>null}),h(Re,"type",n.FunctionDeclaration),h(Re,"USER_MANAGED_PARENT_TYPES",[n.Project,n.InstalledProject,n.DefinitionEntity,n.Loop]),h(Re,"PARENT_TYPES",[...Re.USER_MANAGED_PARENT_TYPES,n.BuiltInBaseEntity,n.PrimitiveEntity]),h(Re,"MUTABLE_BASE_PROPERTIES",["name","description","private"]),h(Re,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),h(Re,"BASE_PROPERTIES",[...Re.MUTABLE_BASE_PROPERTIES,...Re.INMUTABLE_BASE_PROPERTIES]),h(Re,"MUTABLE_META_PROPERTIES",[...Re.MUTABLE_BASE_PROPERTIES,"x","y","index","collapsed"]),h(Re,"INMUTABLE_META_PROPERTIES",[...Re.INMUTABLE_BASE_PROPERTIES]),h(Re,"META_PROPERTIES",[...Re.MUTABLE_META_PROPERTIES,...Re.INMUTABLE_META_PROPERTIES]),h(Re,"MUTABLE_UPSTREAM_PROPERTIES",[]),h(Re,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","implements","extends"]),h(Re,"UPSTREAM_PROPERTIES",[...Re.MUTABLE_UPSTREAM_PROPERTIES,...Re.INMUTABLE_UPSTREAM_PROPERTIES]),h(Re,"MUTABLE_DOWNSTREAM_PROPERTIES",["inputs","calls"]),h(Re,"INMUATABLE_DOWNSTREAM_PROPERTIES",[]),h(Re,"DOWNSTREAM_PROPERTIES",[...Re.MUTABLE_DOWNSTREAM_PROPERTIES,...Re.INMUATABLE_DOWNSTREAM_PROPERTIES]),h(Re,"PROPERTIES",[...Re.META_PROPERTIES,...Re.UPSTREAM_PROPERTIES,...Re.DOWNSTREAM_PROPERTIES]);let Fr=Re;function d1(r){const a=OZ(),e=r.toJSON();a.safeParse(e).success;const i=[];if(r.entity&&r.andChildrenGroup||r.entity&&r.orChildrenGroup||r.andChildrenGroup&&r.orChildrenGroup){const s=de({id:r.id+"--"+F.InvalidPropertiesCombination,message:`Data type with id "${r.id}" has invalid properties combination. Only one of the following properties can be present at the time: 'entity', 'andChildrenGroup' or 'orChildrenGroup'`,issue:null,severity:O.Error,code:F.InvalidPropertiesCombination,entity:r});i.push(s.error)}return Ke(r.errors,i)}const jJ=Object.freeze(Object.defineProperty({__proto__:null,validate:d1},Symbol.toStringTag,{value:"Module"}));function UJ(r,a){const e=[],t=[n.DefinitionEntity,n.ActionDescriptor,n.Property,n.ArgumentDeclaration,n.ReturnDeclaration,n.VariableDeclaration,n.ValueDescriptor,n.DataType],i=`'${se(t,"', '","' or '")}'`;if(r.parent)if(r.id===r.parent)e.push(new w({id:`${r.id}--${r.parent}--${R.SelfReference}`,code:R.SelfReference,severity:O.Error,message:`Entity of type "${r.type}" with id "${r.id}", has a reference to itself at 'parent'. This is not allowed. Change the reference string or the 'entityId' property of the reference object.`,issue:null}));else{const s=a.get(r.parent);s?t.includes(s.type)||e.push(new w({id:`${r.id}--${r.parent}--${R.InvalidParentReference}`,code:R.InvalidParentReference,severity:O.Error,message:`Entity of type "${r.type}" with id "${r.id}", has a parent reference that isn't pointing to an entity of type ${i}.`,issue:null})):e.push(new w({id:`${r.id}--${r.parent}--${R.ReferencedEntityNotFound}`,code:R.ReferencedEntityNotFound,severity:O.Error,message:`Entity of type "${r.type}" with id "${r.id}", is referencing an entity with id "${r.parent}" that isn't yet found in the project. Perhaps it should be created first. Or perhaps the ID is incorrect.`,issue:null}))}else e.push(new w({id:`${r.id}--${$.InvalidObjectStructure}`,code:$.InvalidObjectStructure,severity:O.Error,message:`Entity of type "${r.type}" with id "${r.id}" is missing a 'parent' reference. The 'parent' of a 'data-type' entity must be a reference to an entity of type ${i}.`,issue:null}));if(r.entity){if(r.id===r.entity)return e.push(new w({id:`${r.id}--${r.entity}--${R.SelfReference}`,code:R.SelfReference,severity:O.Error,message:`Entity of type "${r.type}" with id "${r.id}", has a reference to itself at 'entity'. This is not allowed. Change the reference string or the 'entityId' property of the reference object.`,issue:null})),e;const s=a.get(r.entity);s?[n.DefinitionEntity,n.PrimitiveEntity,n.ActionDescriptor,n.BuiltInBaseEntity].includes(s.type)||e.push(new w({id:`${r.id}--${r.entity}--${R.InvalidImplementsReference}`,code:R.InvalidImplementsReference,severity:O.Error,message:`Entity of type "${r.type}" with id "${r.id}", has an 'entity' reference that isn't pointing to an entity of type 'definition-entity', 'primitive-entity', 'action-descriptor' or 'built-in-base-entity'.`,issue:null})):e.push(new w({id:`${r.id}--${r.entity}--${R.ReferencedEntityNotFound}`,code:R.ReferencedEntityNotFound,severity:O.Error,message:`Entity of type "${r.type}" with id "${r.id}", is referencing an entity with id "${r.entity}" that isn't yet found in the project. Perhaps it should be created first. Or perhaps the ID is incorrect.`,issue:null}))}return e}var Bc=(r=>(r.Entity="entity",r))(Bc||{});const De=class De extends lt{constructor(e,t){super(e);h(this,"initialData");h(this,"id");h(this,"isList",null);h(this,"asType",null);h(this,"type",n.DataType);h(this,"options",null);h(this,"parentRelationType",null);h(this,"like");h(this,"implementationChooseOne",!1);h(this,"inferred",!1);h(this,"staticEntities",null);h(this,"interactiveEntities",null);h(this,"actionEntities",null);h(this,"entity",null);h(this,"andChildrenGroup",null);h(this,"orChildrenGroup",null);h(this,"project");h(this,"errors",[]);h(this,"parent");h(this,"detachedDependents",{});h(this,"knownVersions",null);h(this,"activeVersion",!1);h(this,"initialized",!1);h(this,"startedInitialization",!1);this.initialData=e,this.project=t,this.id=e.id,this.isList=e.isList,this.asType=e.asType,this.options=e.options,this.parentRelationType=e.parentRelationType,this.inferred=e.inferred||!1,this.like=e.like||!1,this.implementationChooseOne=e.implementationChooseOne||!1,this.staticEntities=e.staticEntities,this.interactiveEntities=e.interactiveEntities,this.actionEntities=e.actionEntities}static new(e=null){return{id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:(e==null?void 0:e.author)||m.sessionAuthor,previousVersion:null,deleted:!1,type:n.DataType,entity:null,isList:!1,like:!1,inferred:!1,implementationChooseOne:!1,parentRelationType:null,options:null,asType:null,staticEntities:null,interactiveEntities:null,actionEntities:null,andChildrenGroup:null,orChildrenGroup:null,parent:null}}static fromGenerationTarget(e,t){const i=_(e.parent),s=t.get(i);let l=null;e.entity&&(l=t.get(e.entity));const o={id:e.id,version:m.UUID.uuid(),createdAt:T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.DataType,andChildrenGroup:null,orChildrenGroup:null,parentRelationType:e.parentRelationType||null,options:e.options||null,isList:e.isList,like:e.like||!1,inferred:!1,implementationChooseOne:e.implementationChooseOne||!1,staticEntities:e.staticEntities??null,interactiveEntities:e.interactiveEntities??null,actionEntities:e.actionEntities??null,entity:l,asType:e.asType,parent:s},d=C(o,t);return d.setParent(s,null),d.initChildren(null),d}static validateGenerationTarget(e,t){var u;let i=JSON.parse(JSON.stringify(e));const s=[],l=UJ(i,t);if(s.push(...l,...ut(i)),i.entity){const f=t.get(i.entity);if(f.type===n.DefinitionEntity){const E=Wt(f).filter(I=>!I.interactive);if(E.length){const I=E.length>1?`entities with ids '${se(E.map(D=>D.id),"', '","' and '")}'`:`entity with id '${E[0].id}'`;s.push(new w({id:`${e.id}--${R.NonInteractiveEntityReferenced}`,code:R.NonInteractiveEntityReferenced,severity:O.Error,message:`The entity with id '${e.id}' and type '${e.type}', cannot reference 'definition-entity' with id '${i.entity}' at 'entity'. The entity extends or implements non-interactive built-in-base-entity ${I}.
55
+ Please consider than any updates might affect the overlap with the signature of the parent entity's action descriptors.`,issue:null}))),{errors:t,modifiedData:e}}subscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]||(this.detachedDependents[t.entity.id]=t)}),this}unsubscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]&&delete this.detachedDependents[t.entity.id]}),this}syncDependents(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-dependents"))){const t=[],i=[],s=[],l=[];return Object.values(this.detachedDependents).forEach(o=>{const d=o.entity.afterAllChildrenInitialized(e);t.push(...d.updated),i.push(...d.added),s.push(...d.removed),l.push(...d.affected)}),e==null||e.attemptAutoclose("sync-dependents",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];if(t==="function-declaration-implements"&&this.setImplements(null,i),t==="function-declaration-extends"){const{updated:u,added:f,removed:c,affected:E}=this.remove({ignoreUpstream:!1},i);s.push(...u),l.push(...f),o.push(...c),d.push(...E)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}onDetachedDependencyRestored(e,t,i){const s=[],l=[],o=[],d=[];if(t==="function-declaration-implements"&&(this.setImplements(e,i),s.push(e)),t==="function-declaration-extends"){const{updated:u,added:f,removed:c,affected:E}=this.restore({},i);s.push(...u),l.push(...f),o.push(...c),d.push(...E)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}unsubscribeFromDependencies(){var e,t;return(e=this.implements)==null||e.unsubscribeDependents([{entity:this,field:"function-declaration-implements"}]),(t=this.extends)==null||t.unsubscribeDependents([{entity:this,field:"function-declaration-extends"}]),this}subscribeToDependencies(){var e,t;return(e=this.implements)==null||e.subscribeDependents([{entity:this,field:"function-declaration-implements"}]),(t=this.extends)==null||t.subscribeDependents([{entity:this,field:"function-declaration-extends"}]),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=m.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 Re(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.calls=this.calls,e.implements=this.implements,e.extends=this.extends,e.detachedChildren=this.detachedChildren,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],i=[],s=[],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),i.push(...o.added),s.push(...o.removed)}return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}async restoreVersion(e){var d;const t=[],i=[],s=[],l=[];if(this.version===e)return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this};if(!this.knownVersions){const u=new Map;for(const[f,c]of this.knownVersions||new Map){if(u.set(f,c),c.activeVersion=!1,c.knownVersions)for(const[E,I]of c.knownVersions)u.set(E,I);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 Re(u,this.project)}return this.metaSync(o.toShallowJSON(),null),this.inputs=o.inputs,this.calls=o.calls,this.implements=o.implements,this.detachedChildren=o.detachedChildren,this.parent=o.parent,{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}hydrateAncestors(){const e=[],t=[],i=[],s=[];if(this.initialData.parent){const l=_(this.initialData.parent),o=this.project.get(l);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${Vt(this.type)} with id '${this.id}' has a 'parent' reference "${l}" which is missing in the project`)}else throw new Error(`${Vt(this.type)} with id '${this.id}' is missing a 'parent' reference`);if(this.initialData.implements){const l=_(this.initialData.implements),o=this.project.get(l);if(o)this.setImplements(o,null),e.push(o);else if(l)throw new Error(`${Vt(this.type)} with id '${this.id}' has a 'implements' reference "${l}" which is missing in the project`)}if(this.initialData.extends){const l=_(this.initialData.extends),o=this.project.get(l);if(o)this.setExtends(o,null),e.push(o);else if(l)throw new Error(`${Vt(this.type)} with id '${this.id}' has a 'extends' reference "${l}" which is missing in the project`)}return{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],i=[],s=[],l=[];return this.initialized=!0,this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addSelfToProject(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-self-to-project"))){const t=[this],i=[],s=[],l=[];return this.parent===this.project?this.project.addFunctionDeclaration(this):this.parent.type===n.DefinitionEntity?(this.parent.addMethod(this),t.push(this.parent)):this.parent.type===n.Loop&&(this.parent.setBody(this),t.push(this.parent)),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}replaceDetachedChild(e,t){const i=this.detachedChildren.indexOf(e);return i!==-1&&(this.detachedChildren[i]=t),this}subscribeDetachedChild(e){return this.detachedChildren.includes(e)||this.detachedChildren.push(e),this}addInputDeclaration(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-input-declaration"))){return this.inputs.includes(e)?(t==null||t.attemptAutoclose("add-input-declaration",this.id),this):(this.inputs.push(e),t==null||t.attemptAutoclose("add-input-declaration",this.id),this)}removeInputDeclaration(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-input-declaration"))){const i=this.inputs.findIndex(s=>s.id===e.id);return i>-1&&(this.inputs.splice(i,1),t&&(t==null||t.add(this,A.Affected))),t==null||t.attemptAutoclose("remove-input-declaration",this.id),this}setParent(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"set-parent"))){var i;return((i=this.parent)==null?void 0:i.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,m.sessionAuthor,T().toISOString(),this,!0,"set-implements"))){var i;return((i=this.implements)==null?void 0:i.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}setExtends(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"set-extends"))){var i;return((i=this.extends)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.extends=e,t&&(t==null||t.add(this,A.Updated))),t==null||t.attemptAutoclose("set-extends",this.id),this}addCall(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-call"))){return this.calls.includes(e)||(this.calls.push(e),t==null||t.add(e,A.Affected)),t==null||t.attemptAutoclose("add-call",this.id),this}removeCall(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-call"))){const i=this.calls.indexOf(e);return i!==-1&&(this.calls.splice(i,1),t==null||t.add(e,A.Affected)),t==null||t.attemptAutoclose("remove-call",this.id),this}initChildren(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.inputs=this.initialData.inputs.map(t=>{const i=C(t,this.project);return i.setParent(this,null),i.initChildren(e),i}),this.calls=this.initialData.calls.map(t=>{const i=C(t,this.project);return i.addEntryCaller(this,null),[n.BreakStatement,n.ContinueStatement].includes(i.type)?(i.setParent(this.parent,null),i.initChildren(e)):i.type!==n.InternalCall&&(i.setParent(this,null),i.initChildren(e)),i}),this.initialData.implements&&(this.implements=C(this.initialData.implements,this.project)),this.initialData.extends&&(this.extends=C(this.initialData.extends,this.project)),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,m.sessionAuthor,T().toISOString(),this,!0,"meta-sync"))){const i=pt(this,e),s=this.toMeta();return this.name=e.name!==void 0?e.name:s.name,this.description=e.description!==void 0?e.description:s.description,this.private=e.private!==void 0?e.private:this.private,this.index=e.index||(e.index!==0?s.index:0),this.collapsed=e.collapsed!==void 0?e.collapsed:s.collapsed,this.x=e.x||s.x,this.y=e.y||s.y,super.metaSync(e),e.deleted===!0&&!s.deleted?t==null||t.add(this,A.Removed):e.deleted===!1&&s.deleted?t==null||t.add(this,A.Added):i&&(t==null||t.add(this,A.Updated)),t==null||t.attemptAutoclose("meta-sync",this.id),this}async APILoad(e=U,...t){return await Re.repository.APILoad(this.id,...t),this}async APICreate(e=U,...t){return await Re.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=U,...t){return await Re.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=U,...t){return await Re.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=U,...t){return await Re.repository.APIClone(this.id,...t),this}async APILoadVersion(e=U,t,...i){return await Re.repository.APILoadVersion(this.id,t,...i)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-entity"))){const i=[],s=[],l=[],o=[];return t!=null&&t.hasRemoved(this.id)?(t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(s.push(this),this.unsubscribe(),this.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(u=>{const{updated:f,removed:c,added:E}=u.entity.onDetachedDependencyRemoved(this,u.field,t);i.push(...f),s.push(...c),l.push(...E)}),this.inputs.forEach(u=>{const{updated:f,removed:c}=u.remove({ignoreUpstream:!0},t);i.push(...f),s.push(...c)}),pi(this).forEach(u=>{const{updated:f,removed:c}=u.remove({ignoreUpstream:!0},t);i.push(...f),s.push(...c)}),this.parent.type===n.DefinitionEntity&&!e&&(this.parent.removeMethod(this),t==null||t.add(this.parent,A.Affected),i.push(this.parent)),t==null||t.attemptAutoclose("remove-entity",this.id),{added:p(l),updated:p(i),removed:p(s),affected:p(o),self:this})}restore({}={},e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"restore-entity"))){const t=[],i=[],s=[],l=[];return e!=null&&e.hasAdded(this.id)?(e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),Object.values(this.detachedDependents).forEach(d=>{const{updated:u,removed:f,added:c}=d.entity.onDetachedDependencyRestored(this,d.field,e);i.push(...u),s.push(...f),t.push(...c)}),this.inputs.forEach(d=>{const{updated:u}=d.restore({},e);i.push(...u)}),pi(this).forEach(d=>{const{updated:u}=d.restore({},e);i.push(...u)}),this.parent.type===n.DefinitionEntity&&(this.parent.addMethod(this),e==null||e.add(this.parent,A.Affected),i.push(this.parent)),e==null||e.attemptAutoclose("restore-entity",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(l),self:this})}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.inputs.flatMap(i=>i.toFlat(e)),...this.calls.flatMap(i=>i.toFlat(e)),...this.returnStatements.flatMap(i=>i.toFlat(e)),...this.implements?this.implements.toFlat(e):[]])}toFlatIds(e=new Set){if(e.has(this.id))return[];e.add(this.id);const t=pi(this);return[this.id,...this.inputs.flatMap(s=>s.toFlatIds(e)),...this.calls.flatMap(s=>s.toFlatIds(e)),...this.returnStatements.flatMap(s=>s.toFlatIds(e)),...this.implements?this.implements.toFlatIds(e):[],...t.flatMap(s=>s.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,collapsed:this.collapsed,private:this.private,index:this.index,x:this.x,y:this.y,type:this.type,name:this.name}}toJSON(e=new Set){var t,i;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,x:this.x,y:this.y,collapsed:this.collapsed,private:this.private,calls:this.calls.map(s=>s.toJSON(e)),inputs:this.inputs.map(s=>s.toJSON(e)),implements:((t=this.implements)==null?void 0:t.toJSON(e))||null,extends:((i=this.extends)==null?void 0:i.toJSON(e))||null,parent:this.parent.toReference()})}toJSONClone(e=J){var i,s,l,o,d;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||yt(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(s=e.seenEntities)!=null&&s.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:m.UUID.uuid(),createdAt:e.timestamp||T().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,index:this.index,x:this.x,y:this.y,collapsed:this.collapsed,private:this.private,calls:this.calls.map(u=>u.toJSONClone({...e,newId:null})),inputs:this.inputs.map(u=>u.toJSONClone({...e,newId:null})),implements:(()=>{var u;return this.implements&&this.project.getBuiltIn(this.implements.id)?this.implements.toJSON():(u=this.implements)==null?void 0:u.toJSONClone({...e,newId:null})})(),extends:(()=>{var u;return this.extends&&this.project.getBuiltIn(this.extends.id)?this.extends.toJSON():(u=this.extends)==null?void 0:u.toJSONClone({...e,newId:null})})(),parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps})})}toReference(e=J){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+m.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=J){var i,s,l;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,index:this.index,collapsed:this.collapsed,private:this.private,x:this.x,y:this.y,inputs:this.inputs.map(o=>o.toReference(e)),calls:this.calls.map(o=>o.toReference(e)),implements:((s=this.implements)==null?void 0:s.toReference(e))||null,extends:((l=this.extends)==null?void 0:l.toReference(e))||null,parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.inputs.flatMap(i=>i.toFlatJSON(e)),...this.calls.flatMap(i=>i.toFlatJSON(e)),...this.returnStatements.flatMap(i=>i.toFlatJSON(e)),...this.implements?this.implements.toFlatJSON(e):[]])}toGenerationTarget(){var t,i;const e=this.parent.type===n.Project?void 0:this.parent.id;return{id:this.id,name:this.name,description:this.description||void 0,type:this.type,private:this.private,implements:((t=this.implements)==null?void 0:t.id)||void 0,extends:((i=this.extends)==null?void 0:i.id)||void 0,parent:e}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...this.inputs.flatMap(i=>i.toFlatGenerationTarget(e)),...this.calls.flatMap(i=>i.toFlatGenerationTarget(e)),...this.returnStatements.flatMap(i=>i.toFlatGenerationTarget(e))])}clearErrors(){return this.errors=[],this.inputs.forEach(e=>e.clearErrors()),this.calls.forEach(e=>e.clearErrors()),this.returnStatements.forEach(e=>e.clearErrors()),this}validate(){const e=o1(this);return this.errors=[...e],{success:!0,error:null,data:this.toJSON()}}getErrors(){const e=pi(this);return[...this.errors,...this.inputs.flatMap(i=>i.getErrors()),...e.flatMap(i=>i.getErrors())]}getShallowErrors(){return this.errors}clone(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"clone-entity")),t=null,i=null,s=!0,l=!1){var I;let o=mt(t,this);const d=this.toJSON(),u=i||m.UUID.uuid();d.inputs=[],d.calls=[],d.id=u,d.version=m.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 f=st(d,o);t?f.setParent(t,null):f.setParent(this.parent,null),s&&f.subscribe(),f.initChildren(e),e==null||e.add(f,A.Added);const c=(I=this.inputs)==null?void 0:I.map(D=>D.clone(e,f,m.UUID.uuid(),s));return f.inputs=c,l?(pi(this).map(D=>D.clone(e,f,m.UUID.uuid(),s)),e==null||e.attemptAutoclose("clone-entity",this.id),f):(e==null||e.attemptAutoclose("clone-entity",this.id),f)}getVariableInstances(){return He(this).filter(i=>i.type===n.VariableInstance)}getArgument(e){return this.inputs.find(t=>t.id===e)||null}createCall(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"create-call")),t=this.project,i={}){const s={id:i.id||m.UUID.uuid(),version:i.version||m.UUID.uuid(),createdAt:i.createdAt||(e==null?void 0:e.timestamp)||T().toISOString(),author:i.author||m.sessionAuthor||"1",previousVersion:i.previousVersion||null,deleted:i.deleted||!1,type:n.FunctionCall,parent:t.toReference(),successCalls:i.successCalls||[],errorCalls:i.errorCalls||[],inputs:i.inputs||[],outputs:i.outputs||[],error:i.error||null,process:i.process||null,calledBySuccess:i.calledBySuccess||[],calledByError:i.calledByError||[],calledByEntry:i.calledByEntry||[],declaration:this.toJSON(),x:0,y:0},l=C(s,this.project);return l.hydrateAncestors(),e==null||e.add(l,A.Added),l.addSelfToProject(e),l.setParent(t,e),l.initChildren(e),l.afterAllChildrenInitialized(e),e==null||e.add(l,A.Added),e==null||e.attemptAutoclose("create-call",this.id),l}createInternalCall(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"create-internal")),t,i={}){const s={id:i.id||m.UUID.uuid(),version:i.version||m.UUID.uuid(),createdAt:i.createdAt||(e==null?void 0:e.timestamp)||T().toISOString(),author:i.author||m.sessionAuthor||"1",previousVersion:i.previousVersion||null,deleted:i.deleted||!1,type:n.InternalCall,parent:t.toReference(),successCalls:i.successCalls||[],errorCalls:i.errorCalls||[],inputs:i.inputs||[],outputs:i.outputs||[],error:i.error||null,process:i.process||null,calledBySuccess:i.calledBySuccess||[],calledByError:i.calledByError||[],calledByEntry:i.calledByEntry||[],declaration:this.toShallowJSON(),index:t.internalCalls.length},l=C(s,this.project);return l.hydrateAncestors(),e==null||e.add(l,A.Added),l.addSelfToProject(e),l.setParent(t,e),l.initChildren(e),l.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("create-internal",this.id),l}addReturnStatement(e){return this.returnStatements.includes(e)||this.returnStatements.push(e),this}removeReturnStatement(e){const t=this.returnStatements.indexOf(e);return t!==-1&&this.returnStatements.splice(t,1),this}getUniqueReturnDeclarations(){const e=[],i=[...this.returnStatements].flatMap(s=>s.outputs);if(this.implements){const s=this.implements.outputs;return i.forEach(l=>{const o=s.find(u=>u===l.implements),d=e.find(u=>u.implements===l.implements);o&&!d&&e.push(l)}),p(e)}else return i.forEach(s=>{e.find(o=>o===s||x(o,this.project)===x(s,this.project)&&wi(o.dataType,s.dataType))||e.push(s)}),p(e)}};h(Re,"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,...i)=>null}),h(Re,"type",n.FunctionDeclaration),h(Re,"USER_MANAGED_PARENT_TYPES",[n.Project,n.InstalledProject,n.DefinitionEntity,n.Loop]),h(Re,"PARENT_TYPES",[...Re.USER_MANAGED_PARENT_TYPES,n.BuiltInBaseEntity,n.PrimitiveEntity]),h(Re,"MUTABLE_BASE_PROPERTIES",["name","description","private"]),h(Re,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),h(Re,"BASE_PROPERTIES",[...Re.MUTABLE_BASE_PROPERTIES,...Re.INMUTABLE_BASE_PROPERTIES]),h(Re,"MUTABLE_META_PROPERTIES",[...Re.MUTABLE_BASE_PROPERTIES,"x","y","index","collapsed"]),h(Re,"INMUTABLE_META_PROPERTIES",[...Re.INMUTABLE_BASE_PROPERTIES]),h(Re,"META_PROPERTIES",[...Re.MUTABLE_META_PROPERTIES,...Re.INMUTABLE_META_PROPERTIES]),h(Re,"MUTABLE_UPSTREAM_PROPERTIES",[]),h(Re,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","implements","extends"]),h(Re,"UPSTREAM_PROPERTIES",[...Re.MUTABLE_UPSTREAM_PROPERTIES,...Re.INMUTABLE_UPSTREAM_PROPERTIES]),h(Re,"MUTABLE_DOWNSTREAM_PROPERTIES",["inputs","calls"]),h(Re,"INMUATABLE_DOWNSTREAM_PROPERTIES",[]),h(Re,"DOWNSTREAM_PROPERTIES",[...Re.MUTABLE_DOWNSTREAM_PROPERTIES,...Re.INMUATABLE_DOWNSTREAM_PROPERTIES]),h(Re,"PROPERTIES",[...Re.META_PROPERTIES,...Re.UPSTREAM_PROPERTIES,...Re.DOWNSTREAM_PROPERTIES]);let Fr=Re;function d1(r){const a=OZ(),e=r.toJSON();a.safeParse(e).success;const i=[];if(r.entity&&r.andChildrenGroup||r.entity&&r.orChildrenGroup||r.andChildrenGroup&&r.orChildrenGroup){const s=de({id:r.id+"--"+F.InvalidPropertiesCombination,message:`Data type with id "${r.id}" has invalid properties combination. Only one of the following properties can be present at the time: 'entity', 'andChildrenGroup' or 'orChildrenGroup'`,issue:null,severity:O.Error,code:F.InvalidPropertiesCombination,entity:r});i.push(s.error)}return Ke(r.errors,i)}const jJ=Object.freeze(Object.defineProperty({__proto__:null,validate:d1},Symbol.toStringTag,{value:"Module"}));function UJ(r,a){const e=[],t=[n.DefinitionEntity,n.ActionDescriptor,n.Property,n.ArgumentDeclaration,n.ReturnDeclaration,n.VariableDeclaration,n.ValueDescriptor,n.DataType],i=`'${se(t,"', '","' or '")}'`;if(r.parent)if(r.id===r.parent)e.push(new w({id:`${r.id}--${r.parent}--${R.SelfReference}`,code:R.SelfReference,severity:O.Error,message:`Entity of type "${r.type}" with id "${r.id}", has a reference to itself at 'parent'. This is not allowed. Change the reference string or the 'entityId' property of the reference object.`,issue:null}));else{const s=a.get(r.parent);s?t.includes(s.type)||e.push(new w({id:`${r.id}--${r.parent}--${R.InvalidParentReference}`,code:R.InvalidParentReference,severity:O.Error,message:`Entity of type "${r.type}" with id "${r.id}", has a parent reference that isn't pointing to an entity of type ${i}.`,issue:null})):e.push(new w({id:`${r.id}--${r.parent}--${R.ReferencedEntityNotFound}`,code:R.ReferencedEntityNotFound,severity:O.Error,message:`Entity of type "${r.type}" with id "${r.id}", is referencing an entity with id "${r.parent}" that isn't yet found in the project. Perhaps it should be created first. Or perhaps the ID is incorrect.`,issue:null}))}else e.push(new w({id:`${r.id}--${$.InvalidObjectStructure}`,code:$.InvalidObjectStructure,severity:O.Error,message:`Entity of type "${r.type}" with id "${r.id}" is missing a 'parent' reference. The 'parent' of a 'data-type' entity must be a reference to an entity of type ${i}.`,issue:null}));if(r.entity){if(r.id===r.entity)return e.push(new w({id:`${r.id}--${r.entity}--${R.SelfReference}`,code:R.SelfReference,severity:O.Error,message:`Entity of type "${r.type}" with id "${r.id}", has a reference to itself at 'entity'. This is not allowed. Change the reference string or the 'entityId' property of the reference object.`,issue:null})),e;const s=a.get(r.entity);s?[n.DefinitionEntity,n.PrimitiveEntity,n.ActionDescriptor,n.BuiltInBaseEntity].includes(s.type)||e.push(new w({id:`${r.id}--${r.entity}--${R.InvalidImplementsReference}`,code:R.InvalidImplementsReference,severity:O.Error,message:`Entity of type "${r.type}" with id "${r.id}", has an 'entity' reference that isn't pointing to an entity of type 'definition-entity', 'primitive-entity', 'action-descriptor' or 'built-in-base-entity'.`,issue:null})):e.push(new w({id:`${r.id}--${r.entity}--${R.ReferencedEntityNotFound}`,code:R.ReferencedEntityNotFound,severity:O.Error,message:`Entity of type "${r.type}" with id "${r.id}", is referencing an entity with id "${r.entity}" that isn't yet found in the project. Perhaps it should be created first. Or perhaps the ID is incorrect.`,issue:null}))}return e}var Bc=(r=>(r.Entity="entity",r))(Bc||{});const De=class De extends lt{constructor(e,t){super(e);h(this,"initialData");h(this,"id");h(this,"isList",null);h(this,"asType",null);h(this,"type",n.DataType);h(this,"options",null);h(this,"parentRelationType",null);h(this,"like");h(this,"implementationChooseOne",!1);h(this,"inferred",!1);h(this,"staticEntities",null);h(this,"interactiveEntities",null);h(this,"actionEntities",null);h(this,"entity",null);h(this,"andChildrenGroup",null);h(this,"orChildrenGroup",null);h(this,"project");h(this,"errors",[]);h(this,"parent");h(this,"detachedDependents",{});h(this,"knownVersions",null);h(this,"activeVersion",!1);h(this,"initialized",!1);h(this,"startedInitialization",!1);this.initialData=e,this.project=t,this.id=e.id,this.isList=e.isList,this.asType=e.asType,this.options=e.options,this.parentRelationType=e.parentRelationType,this.inferred=e.inferred||!1,this.like=e.like||!1,this.implementationChooseOne=e.implementationChooseOne||!1,this.staticEntities=e.staticEntities,this.interactiveEntities=e.interactiveEntities,this.actionEntities=e.actionEntities}static new(e=null){return{id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:(e==null?void 0:e.author)||m.sessionAuthor,previousVersion:null,deleted:!1,type:n.DataType,entity:null,isList:!1,like:!1,inferred:!1,implementationChooseOne:!1,parentRelationType:null,options:null,asType:null,staticEntities:null,interactiveEntities:null,actionEntities:null,andChildrenGroup:null,orChildrenGroup:null,parent:null}}static fromGenerationTarget(e,t){const i=_(e.parent),s=t.get(i);let l=null;e.entity&&(l=t.get(e.entity));const o={id:e.id,version:m.UUID.uuid(),createdAt:T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.DataType,andChildrenGroup:null,orChildrenGroup:null,parentRelationType:e.parentRelationType||null,options:e.options||null,isList:e.isList,like:e.like||!1,inferred:!1,implementationChooseOne:e.implementationChooseOne||!1,staticEntities:e.staticEntities??null,interactiveEntities:e.interactiveEntities??null,actionEntities:e.actionEntities??null,entity:l,asType:e.asType,parent:s},d=C(o,t);return d.setParent(s,null),d.initChildren(null),d}static validateGenerationTarget(e,t){var u;let i=JSON.parse(JSON.stringify(e));const s=[],l=UJ(i,t);if(s.push(...l,...ut(i)),i.entity){const f=t.get(i.entity);if(f.type===n.DefinitionEntity){const E=Wt(f).filter(I=>!I.interactive);if(E.length){const I=E.length>1?`entities with ids '${se(E.map(D=>D.id),"', '","' and '")}'`:`entity with id '${E[0].id}'`;s.push(new w({id:`${e.id}--${R.NonInteractiveEntityReferenced}`,code:R.NonInteractiveEntityReferenced,severity:O.Error,message:`The entity with id '${e.id}' and type '${e.type}', cannot reference 'definition-entity' with id '${i.entity}' at 'entity'. The entity extends or implements non-interactive built-in-base-entity ${I}.
56
56
  ${rn}`,issue:null}))}}}const o=i.parent&&t.get(i.parent)||t.getBuiltIn(i.parent),d=o?an(o):null;if(d)s.push(new w({id:`${e.id}--${R.BuiltInEntityParent}`,code:R.BuiltInEntityParent,severity:O.Error,message:`The entity with id '${e.id}' and type '${e.type}', belongs to a built-in system entity "${x(d,t)}" with id '${d.id}', and therefore it cannot be created as it would affect a built in entity, which are inmutable.`,issue:null}));else if(o){const f=o.type,c=[n.Property,n.VariableDeclaration,n.ArgumentDeclaration,n.ReturnDeclaration,n.ValueDescriptor];if(c.includes(f)&&(i.parentRelationType&&s.push(new w({id:`${e.id}--${R.InvalidParentRelationType}`,code:R.InvalidParentRelationType,severity:O.Error,message:`The entity with id '${e.id}' and type '${e.type}', cannot have a 'parentRelationType' property set of type '${f}'.
57
57
  The entitities of type '${se(c,"', '","' and '")}' can only have one 'data-type' child under the 'dataType' property so no 'parentRelationType' is needed.`,issue:null})),o.dataType)){const E=(u=o.dataType)==null?void 0:u.id;s.push(new w({id:`${e.id}--${R.NewEntityWouldOverriteExisting}`,code:R.NewEntityWouldOverriteExisting,severity:O.Error,message:`The entity with id '${e.id}' and type '${e.type}', cannot be added as a child to the entity with id '${i.parent}' and type '${f}', because it already has a 'data-type' child with id '${E}'.
58
58
  The entitities of type '${se(c,"', '","' and '")}' can only have one 'data-type' child under the 'dataType' property. You can inspect the existing data-type entity with the 'describe_entity' action. Like so:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elyx-code/project-logic-tree",
3
- "version": "0.0.6266",
3
+ "version": "0.0.6267",
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",