@elyx-code/project-logic-tree 0.0.6272 → 0.0.6273

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
@@ -30305,6 +30305,11 @@ class A {
30305
30305
  "Auto-close change-set must have an auto-close action name."
30306
30306
  );
30307
30307
  }
30308
+ // Resolves its own index in the project's history list of change-sets if it is present
30309
+ get index() {
30310
+ const a = this.project.history.indexOf(this);
30311
+ return a === -1 ? null : a;
30312
+ }
30308
30313
  get isEmpty() {
30309
30314
  return Object.keys(this.added).length === 0 && Object.keys(this.updated).length === 0 && Object.keys(this.removed).length === 0;
30310
30315
  }
@@ -40,7 +40,7 @@ Please provide a unique 'name' string.`,severity:O.Error,code:$.NameNotUniqueInS
40
40
  Please provide a unique 'name' string.`,severity:O.Error,code:$.NameNotUniqueInScope,issue:null}))}}return e}function wc(r,a){const e=[];r.name||e.push(new w({id:`${r.id}--${$.EmptyName}`,message:`Entity with id "${r.id}" and type "${r.type}" has an empty name. Please provide a 'name' string.`,severity:O.Error,code:$.EmptyName,issue:null}));const t=B(r.parent);if(!t)e.push(new w({id:`${r.id}--parent-reference--${R.InvalidReferenceObjectStructure}`,message:`Reference object at 'parent' property for entity with id "${r.id}" and type "${r.type}" is not a valid reference. A reference needs to be a 'id' string of an existing entity in the project.`,severity:O.Error,code:R.InvalidReferenceObjectStructure,issue:null}));else{const i=a.get(t);if(!i)e.push(new w({id:`${r.id}--parent-reference--${R.ReferencedEntityNotFound}`,message:`The entity with id '${t}' that isn't yet found in the project. Perhaps it should be created first. Or perhaps the ID is incorrect.`,severity:O.Error,code:R.ReferencedEntityNotFound,issue:null}));else{const l=Xc(i).filter(o=>o.name===r.name);l.length&&e.push(new w({id:`${r.id}--${$.NameNotUniqueInScope}`,message:`Entity with id "${r.id}" and type "${r.type}" has a name "${r.name}" that is not unique among all inputs declared in the parent entity. Entity with id "${l[0].id}" has the same name.
41
41
  Please provide a unique 'name' string.`,severity:O.Error,code:$.NameNotUniqueInScope,issue:null}))}}return e}function Cc(r,a){const e=[];r.name||e.push(new w({id:`${r.id}--${$.EmptyName}`,message:`Entity with id "${r.id}" and type "${r.type}" has an empty name. Please provide a 'name' string.`,severity:O.Error,code:$.EmptyName,issue:null}));const t=B(r.parent);if(!t)e.push(new w({id:`${r.id}--parent-reference--${R.InvalidReferenceObjectStructure}`,message:`Reference object at 'parent' property for entity with id "${r.id}" and type "${r.type}" is not a valid reference. A reference needs to be a 'id' string of an existing entity in the project.`,severity:O.Error,code:R.InvalidReferenceObjectStructure,issue:null}));else{const i=a.get(t);if(!i)e.push(new w({id:`${r.id}--parent-reference--${R.ReferencedEntityNotFound}`,message:`The entity with id '${t}' that isn't yet found in the project. Perhaps it should be created first. Or perhaps the ID is incorrect.`,severity:O.Error,code:R.ReferencedEntityNotFound,issue:null}));else{const l=tw(i).filter(o=>o.name===r.name);l.length&&e.push(new w({id:`${r.id}--${$.NameNotUniqueInScope}`,message:`Entity with id "${r.id}" and type "${r.type}" has a name "${r.name}" that is not unique among all outputs declared in the parent entity. Entity with id "${l[0].id}" has the same name.
42
42
  Please provide a unique 'name' string.`,severity:O.Error,code:$.NameNotUniqueInScope,issue:null}))}}return e}function BJ(r,a){switch(r.type){case n.DefinitionEntity:return Rc(r,a);case n.FunctionDeclaration:return Dc(r,a);case n.VariableDeclaration:return Oc(r,a);case n.Property:return Pc(r,a);case n.ArgumentDeclaration:return wc(r,a);case n.ReturnDeclaration:return Cc(r,a);default:return[]}}function s1(r,a,e){const i=`${$l(r)}-${a}-id`;return e.instances[i]?m.UUID.uuid():i}function Vc(r,a){let e="",t=null;if(r.parent){const s=a.get(r.parent);s&&(t=s)}let i="";return t&&(i=`${$l(F(t,a))}-`),e=`${i}${$l(F(r,a))}-id`,a.instances[e]?m.UUID.uuid():e}function yt(r,a,e="uuid"){return e==="semantic"?s1(F(r,a),r.type,a):m.UUID.uuid()}function a1(r){var l;const a=o5(),e=r.toJSON();a.safeParse(e).success;const i=o1(r);(l=r.dataType)==null||l.validate();const s=[...i];if(r.id==="80c86e1b-caca-4ba5-9b1f-38f72d10e4a3"){const o=fe({id:`${r.id}--${x.PropertyImplementsNonAbstact}`,message:`Property "${F(r,r.project)}" with id "${r.id}" implements a non-abstract property "${F(r,r.project)}" with id "${r.id}".`,issue:null,severity:O.Error,code:x.PropertyImplementsNonAbstact,entity:r});s.push(o.error)}return s}function o1(r){const a=[];if(!r.implements)return a;const e=r.implements;if(!e.abstract){const i=fe({id:`${r.id}--${x.PropertyImplementsNonAbstact}`,message:`Property "${F(r,r.project)}" with id "${r.id}" implements a non-abstract property "${F(e,r.project)}" with id "${e.id}".`,issue:null,severity:O.Error,code:x.PropertyImplementsNonAbstact,entity:r});a.push(i.error)}if(r.static&&!e.static){const i=fe({id:`${r.id}--${x.NonStaticPropertyImplementsStatic}`,message:`Static property "${F(r,r.project)}" with id "${r.id}" implements a non-static property "${F(e,r.project)}" with id "${e.id}".`,issue:null,severity:O.Error,code:x.NonStaticPropertyImplementsStatic,entity:r});a.push(i.error)}if(!r.static&&e.static){const i=fe({id:`${r.id}--${x.StaticPropertyImplementsNonStatic}`,message:`Non-static property "${F(r,r.project)}" with id "${r.id}" implements a static property "${F(e,r.project)}" with id "${e.id}".`,issue:null,severity:O.Error,code:x.StaticPropertyImplementsNonStatic,entity:r});a.push(i.error)}if(!Ci(r.dataType,e.dataType)){const i=fe({id:`${r.id}--${x.PropertyImplementsIncompatibleType}`,message:`Property "${F(r,r.project)}" with id "${r.id}" implements a property "${F(e,r.project)}" with id "${e.id}" that has an incompatible data type.`,issue:null,severity:O.Error,code:x.PropertyImplementsIncompatibleType,entity:r});a.push(i.error)}return Ke(r.errors,a)}const MJ=Object.freeze(Object.defineProperty({__proto__:null,validate:a1,validateImplementation:o1},Symbol.toStringTag,{value:"Module"}));function NJ(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=ln(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}' (${F(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=St(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=>F(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 ("${F(o[0],o[0].project)}").`;d+=`
43
- ${sn}`,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=E(a.createdAt).toISOString(),this.deleted=a.deleted,this.author=a.author}metaSync(a){this.deleted=a.deleted!==void 0?a.deleted:this.deleted}}function LJ(r){return r.listAdded.forEach(a=>{const e=r.project.get(a.id);(e==null?void 0:e.type)===n.DefinitionEntity&&(r.project.emit(Bt.DEFINITION_ENTITY_ADDED,e,r),gi(e,J.PERSISTED_ENTITY)?r.project.emit(Bt.PERSISTED_DEFINITION_ENTITY_ADDED,e,r):gi(e,J.RELATIONAL_DATABASE)&&r.project.emit(Bt.RELATIONAL_DATABASE_DEFINITION_ENTITY_ADDED,e,r))}),r.listUpdated.forEach(a=>{const e=r.project.get(a.id);(e==null?void 0:e.type)===n.DefinitionEntity&&(r.project.emit(Bt.DEFINITION_ENTITY_UPDATED,e,r),gi(e,J.PERSISTED_ENTITY)?r.project.emit(Bt.PERSISTED_DEFINITION_ENTITY_UPDATED,e,r):gi(e,J.RELATIONAL_DATABASE)&&r.project.emit(Bt.RELATIONAL_DATABASE_DEFINITION_ENTITY_UPDATED,e,r))}),r.listRemoved.forEach(a=>{const e=r.project.get(a.id);(e==null?void 0:e.type)===n.DefinitionEntity&&(r.project.emit(Bt.DEFINITION_ENTITY_REMOVED,e,r),gi(e,J.PERSISTED_ENTITY)?r.project.emit(Bt.PERSISTED_DEFINITION_ENTITY_REMOVED,e,r):gi(e,J.RELATIONAL_DATABASE)&&r.project.emit(Bt.RELATIONAL_DATABASE_DEFINITION_ENTITY_REMOVED,e,r))}),r}var _c=(r=>(r.Manual="manual",r.Automatic="automatic",r))(_c||{}),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=Gi(),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.beforeClose(),!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})}beforeClose(){this.emitSideEffects()}emitSideEffects(){LJ(this)}close(){if(this.beforeClose(),!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(),...Gi()]));if(t.includes(a.id))return this;if(!nd(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:T,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 T)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:T,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 T)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:T,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 T)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 jJ(r){return new Set([...Object.keys(r.added),...Object.keys(r.updated),...Object.keys(r.removed),...Array.from(r.affected)])}var l1=(r=>(r.PropertyImplements="property-implements",r.PropertyExtends="property-extends",r.DataTypeEntity="data-type-entity",r))(l1||{});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)||E().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=B(e.parent),s=t.get(i);let l=null;if(e.implements){const f=B(e.implements);l=t.get(f)}let o=null;if(e.extends){const f=B(e.extends);o=t.get(f)}const d={id:e.id,version:m.UUID.uuid(),createdAt:E().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=V(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=NJ(i,t),o=Pc(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.
43
+ ${sn}`,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=E(a.createdAt).toISOString(),this.deleted=a.deleted,this.author=a.author}metaSync(a){this.deleted=a.deleted!==void 0?a.deleted:this.deleted}}function LJ(r){return r.listAdded.forEach(a=>{const e=r.project.get(a.id);(e==null?void 0:e.type)===n.DefinitionEntity&&(r.project.emit(Bt.DEFINITION_ENTITY_ADDED,e,r),gi(e,J.PERSISTED_ENTITY)?r.project.emit(Bt.PERSISTED_DEFINITION_ENTITY_ADDED,e,r):gi(e,J.RELATIONAL_DATABASE)&&r.project.emit(Bt.RELATIONAL_DATABASE_DEFINITION_ENTITY_ADDED,e,r))}),r.listUpdated.forEach(a=>{const e=r.project.get(a.id);(e==null?void 0:e.type)===n.DefinitionEntity&&(r.project.emit(Bt.DEFINITION_ENTITY_UPDATED,e,r),gi(e,J.PERSISTED_ENTITY)?r.project.emit(Bt.PERSISTED_DEFINITION_ENTITY_UPDATED,e,r):gi(e,J.RELATIONAL_DATABASE)&&r.project.emit(Bt.RELATIONAL_DATABASE_DEFINITION_ENTITY_UPDATED,e,r))}),r.listRemoved.forEach(a=>{const e=r.project.get(a.id);(e==null?void 0:e.type)===n.DefinitionEntity&&(r.project.emit(Bt.DEFINITION_ENTITY_REMOVED,e,r),gi(e,J.PERSISTED_ENTITY)?r.project.emit(Bt.PERSISTED_DEFINITION_ENTITY_REMOVED,e,r):gi(e,J.RELATIONAL_DATABASE)&&r.project.emit(Bt.RELATIONAL_DATABASE_DEFINITION_ENTITY_REMOVED,e,r))}),r}var _c=(r=>(r.Manual="manual",r.Automatic="automatic",r))(_c||{}),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 index(){const a=this.project.history.indexOf(this);return a===-1?null:a}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=Gi(),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.beforeClose(),!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})}beforeClose(){this.emitSideEffects()}emitSideEffects(){LJ(this)}close(){if(this.beforeClose(),!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(),...Gi()]));if(t.includes(a.id))return this;if(!nd(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:T,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 T)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:T,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 T)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:T,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 T)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 jJ(r){return new Set([...Object.keys(r.added),...Object.keys(r.updated),...Object.keys(r.removed),...Array.from(r.affected)])}var l1=(r=>(r.PropertyImplements="property-implements",r.PropertyExtends="property-extends",r.DataTypeEntity="data-type-entity",r))(l1||{});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)||E().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=B(e.parent),s=t.get(i);let l=null;if(e.implements){const f=B(e.implements);l=t.get(f)}let o=null;if(e.extends){const f=B(e.extends);o=t.get(f)}const d={id:e.id,version:m.UUID.uuid(),createdAt:E().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=V(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=NJ(i,t),o=Pc(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
45
  ${Zl}`,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,E().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:T}=this.remove({ignoreUpstream:!1},i);s.push(...u),l.push(...f),o.push(...c),d.push(...T)}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:T}=this.restore({},i);s.push(...u),l.push(...f),o.push(...c),d.push(...T)}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&&!E(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&E(e).isSame(E(this.createdAt))?this:(this.previousVersion=this.version,this.version=m.UUID.uuid(),this.createdAt=E(e).toISOString()||E().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[T,I]of c.knownVersions)u.set(T,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=B(this.initialData.parent),o=this.project.get(l);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${_t(this.type)} with id '${this.id}' has a parent reference "${l}" which is missing in the project`)}else throw new Error(`${_t(this.type)} with id '${this.id}' is missing a parent reference`);if(this.initialData.implements){const l=B(this.initialData.implements),o=this.project.get(l);if(o)this.setImplements(o,null),e.push(o);else if(l)throw new Error(`${_t(this.type)} with id '${this.id}' has a 'implements' reference "${l}" which is missing in the project`)}if(this.initialData.extends){const l=B(this.initialData.extends),o=this.project.get(l);if(o)this.setExtends(o,null),e.push(o);else if(l)throw new Error(`${_t(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,E().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,E().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,E().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,E().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,E().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,E().toISOString(),this,!0,"init-children"))){if(this.initialized||this.startedInitialization)return this;if(this.startedInitialization=!0,this.initialData.defaultValue&&(this.defaultValue=V(this.initialData.defaultValue,this.project),this.defaultValue.setParent(this,null),this.defaultValue.initChildren(e)),this.initialData.dataType){const t=V(this.initialData.dataType,this.project);t.setParent(this,null),t.initChildren(e),this.dataType=t}if(this.initialData.implements){const t=V(this.initialData.implements,this.project);this.setImplements(t,null)}if(this.initialData.extends){const t=V(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,E().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,E().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,E().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=W){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||E().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=W){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=W){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=a1(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,E().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)||E().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 T=(D=this.defaultValue)==null?void 0:D.clone(e,f,m.UUID.uuid(),s);return f.defaultValue=T||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,E().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 xr=be;function d1(r){const a=Rq(),e=r.toJSON();a.safeParse(e).success;const i=UJ(r),s=$J(r),l=ci(r);r.inputs.forEach(d=>d.validate()),l.forEach(d=>d.validate());const o=[...i,...s];return Ke(r.errors,o)}function UJ(r){const a=[];if(!r.calls.length&&!r.extends){const e=fe({id:`${r.id}--${x.ScopeWithoutLogic}`,message:`Action "${F(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:x.ScopeWithoutLogic,entity:r});a.push(e.error)}return Ke(r.errors,a)}function $J(r){const a=[];return r.implements,Ke(r.errors,a)}const GJ=Object.freeze(Object.defineProperty({__proto__:null,validate:d1},Symbol.toStringTag,{value:"Module"}));var u1=(r=>(r.FunctionDeclarationImplements="function-declaration-implements",r.FunctionDeclarationExtends="function-declaration-extends",r))(u1||{});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)||E().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=B(e.parent);i=t.get(u)}let s=null;if(e.implements){const u=B(e.implements);s=t.get(u)}let l=null;if(e.extends){const u=B(e.extends);l=t.get(u)}const o={id:e.id,version:m.UUID.uuid(),createdAt:E().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=V(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=Dc(i,t),d=i.parent?t.get(i.parent):null;if(d&&d.type===n.DefinitionEntity){const T=d,D=St(T).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 '${T.id}' because it extends or implements multiple '${n.BuiltInBaseEntity}' entities that are non-interactive ("${se(D.map(C=>F(C,C.project)),'", "','" and "')}").`:`The entity of type '${e.type}' with id '${e.id}' can't be added to the 'parent' entity with id '${T.id}' because it extends or implements a '${n.BuiltInBaseEntity}' entity that is non-interactive ("${F(D[0],D[0].project)}").`;P+=`
46
46
  ${sn}`,s.push(new w({id:`${e.id}--${R.NonInteractiveEntityReferenced}`,code:R.NonInteractiveEntityReferenced,severity:O.Error,message:P,issue:null}))}else{const P=T.methods.find(G=>{var _;return((_=G.implements)==null?void 0:_.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.
@@ -57,6 +57,7 @@ export declare class ChangeSet {
57
57
  project: ProjectState;
58
58
  constructor(project: ProjectState, author: string, timestamp: string, // ISO 8601 format
59
59
  self: UserManagedEntityState | null, autoclose?: boolean, autoCloseActionName?: string);
60
+ get index(): number | null;
60
61
  get isEmpty(): boolean;
61
62
  get isValid(): boolean;
62
63
  get list(): UserManagedEntityState[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elyx-code/project-logic-tree",
3
- "version": "0.0.6272",
3
+ "version": "0.0.6273",
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",