@elyx-code/project-logic-tree 0.0.6241 → 0.0.6242
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 +3 -3
- package/dist/index.umd.cjs +2 -2
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -30173,7 +30173,7 @@ class I {
|
|
|
30173
30173
|
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;
|
|
30174
30174
|
}
|
|
30175
30175
|
async closeAsync() {
|
|
30176
|
-
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 ? (this.project.discardChangeSet(this), this.project.closePendingChangeSets(), this) : (await this.project.closeChangeSet(this), this);
|
|
30176
|
+
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);
|
|
30177
30177
|
}
|
|
30178
30178
|
attemptAutoclose(a, e) {
|
|
30179
30179
|
var t;
|
|
@@ -30217,7 +30217,7 @@ class I {
|
|
|
30217
30217
|
}
|
|
30218
30218
|
close() {
|
|
30219
30219
|
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)
|
|
30220
|
-
return this.project.discardChangeSet(this), this.project.closePendingChangeSets(), this;
|
|
30220
|
+
return console.warn(`Empty change-set (${this.id}) discarded upon closing.`), this.project.discardChangeSet(this), this.project.closePendingChangeSets(), this;
|
|
30221
30221
|
if (this.added[this.project.id] && this.updatedIds.length)
|
|
30222
30222
|
throw new Error(
|
|
30223
30223
|
"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"
|
|
@@ -55158,7 +55158,7 @@ const Be = class Be extends st {
|
|
|
55158
55158
|
f(this, "declaration");
|
|
55159
55159
|
f(this, "writesValues", []);
|
|
55160
55160
|
// Always inferred data type
|
|
55161
|
-
f(this, "dataType");
|
|
55161
|
+
f(this, "dataType", null);
|
|
55162
55162
|
// Parent project full state
|
|
55163
55163
|
f(this, "project");
|
|
55164
55164
|
f(this, "errors", []);
|
package/dist/index.umd.cjs
CHANGED
|
@@ -40,7 +40,7 @@ Please provide a unique 'name' string.`,severity:D.Error,code:$.NameNotUniqueInS
|
|
|
40
40
|
Please provide a unique 'name' string.`,severity:D.Error,code:$.NameNotUniqueInScope,issue:null}))}}return e}function Oc(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:D.Error,code:$.EmptyName,issue:null}));const t=_(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:D.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:D.Error,code:R.ReferencedEntityNotFound,issue:null}));else{const l=Kc(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:D.Error,code:$.NameNotUniqueInScope,issue:null}))}}return e}function Pc(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:D.Error,code:$.EmptyName,issue:null}));const t=_(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:D.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:D.Error,code:R.ReferencedEntityNotFound,issue:null}));else{const l=YP(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:D.Error,code:$.NameNotUniqueInScope,issue:null}))}}return e}function DJ(r,a){switch(r.type){case n.DefinitionEntity:return Ac(r,a);case n.FunctionDeclaration:return bc(r,a);case n.VariableDeclaration:return Rc(r,a);case n.Property:return Dc(r,a);case n.ArgumentDeclaration:return Oc(r,a);case n.ReturnDeclaration:return Pc(r,a);default:return[]}}function t1(r,a,e){const i=`${Ul(r)}-${a}-id`;return e.instances[i]?m.UUID.uuid():i}function wc(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 ht(r,a,e="uuid"){return e==="semantic"?t1(x(r,a),r.type,a):m.UUID.uuid()}function i1(r){var l;const a=e5(),e=r.toJSON();a.safeParse(e).success;const i=r1(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:D.Error,code:F.PropertyImplementsNonAbstact,entity:r});s.push(o.error)}return s}function r1(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:D.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:D.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:D.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:D.Error,code:F.PropertyImplementsIncompatibleType,entity:r});a.push(i.error)}return Ke(r.errors,a)}const OJ=Object.freeze(Object.defineProperty({__proto__:null,validate:i1,validateImplementation:r1},Symbol.toStringTag,{value:"Module"}));function PJ(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:D.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:D.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:D.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=qt(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
|
-
${rn}`,e.push(new w({id:`${r.id}--${R.NonInteractiveEntityReferenced}`,code:R.NonInteractiveEntityReferenced,severity:D.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:D.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:D.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(y=>{var c;return((c=y.implements)==null?void 0:c.id)===r.implements});u?e.push(new w({id:`${r.id}--${$.PropertyOverwritesOtherSiblingWithSameImplementation}`,code:$.PropertyOverwritesOtherSiblingWithSameImplementation,severity:D.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:D.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:D.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){f(this,"version");f(this,"previousVersion",null);f(this,"createdAt");f(this,"deleted",!1);f(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 Cc=(r=>(r.Manual="manual",r.Automatic="automatic",r))(Cc||{}),b=(r=>(r.Added="added",r.Updated="updated",r.Removed="removed",r.Affected="affected",r))(b||{});class A{constructor(a,e,t,i,s=!1,l=""){f(this,"id",m.UUID.uuid());f(this,"seenEntities",[]);f(this,"added",{});f(this,"updated",{});f(this,"removed",{});f(this,"affected",{});f(this,"self",null);f(this,"author");f(this,"timestamp");f(this,"open",!0);f(this,"dirty",!0);f(this,"type","manual");f(this,"autoclose",!1);f(this,"autoCloseActionName","");f(this,"project");if(this.project=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=Ui(),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?(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 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}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(),...Ui()]));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(y=>y!==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:y,updated:c,removed:E,affected:I}=a.recursiveCaptureUpstreamVersions(this.timestamp);for(const O of y)this.add(O,"added");for(const O of c)this.add(O,"updated");for(const O of E)this.add(O,"removed");for(const O of I)this.add(O,"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:y,updated:c,removed:E,affected:I}=a.recursiveCaptureUpstreamVersions(this.timestamp);for(const O of y)this.add(O,"added");for(const O of c)this.add(O,"updated");for(const O of E)this.add(O,"removed");for(const O of I)this.add(O,"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,this}if(e==="updated"){if(this.removed[a.id])return this;if(this.added[a.id])return a.captureVersion(),this;if(this.affected[a.id]&&delete this.affected[a.id],!this.hasUpdated(a.id)){a.increaseVersion(this.timestamp);const{added:y,updated:c,removed:E,affected:I}=a.recursiveCaptureUpstreamVersions(this.timestamp);for(const O of y)this.add(O,"added");for(const O of c)this.add(O,"updated");for(const O of E)this.add(O,"removed");for(const O of I)this.add(O,"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}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 wJ(r){return new Set([...Object.keys(r.added),...Object.keys(r.updated),...Object.keys(r.removed),...Array.from(r.affected)])}var n1=(r=>(r.Implements="implements",r.DataTypeEntity="data-type-entity",r))(n1||{});const Ae=class Ae extends lt{constructor(e,t){super(e);f(this,"initialData");f(this,"id");f(this,"name");f(this,"description",null);f(this,"private");f(this,"abstract");f(this,"index");f(this,"static");f(this,"required");f(this,"constant",!1);f(this,"type",n.Property);f(this,"hidden",!1);f(this,"defaultValue",null);f(this,"dataType",null);f(this,"implements",null);f(this,"project");f(this,"errors",[]);f(this,"parent");f(this,"detachedDependents",{});f(this,"knownVersions",null);f(this,"activeVersion",!1);f(this,"initialized",!1);f(this,"startedInitialization",!1);f(this,"suggestion",!1);f(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,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 u=_(e.implements);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.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,dataType:null,parent:s},d=C(o,t);return d.setParent(s,null),d.initChildren(null),d}static validateGenerationTarget(e,t){let i=JSON.parse(JSON.stringify(e));const s=[],l=PJ(i,t),o=Dc(i,t);return s.push(...l,...o,...pt(i)),{errors:s,modifiedData:i}}get isExtendedProperty(){const e=this.parent.allBasePropertiesFromExtendedAndImplementedEntities.find(t=>t.name===this.name);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:D.Error,message:`Entity of type '${this.type}' with id '${this.id}' cannot have the 'parent' property updated, as it would mean moving the '${this.type}' entity to another parent entity.
|
|
43
|
+
${rn}`,e.push(new w({id:`${r.id}--${R.NonInteractiveEntityReferenced}`,code:R.NonInteractiveEntityReferenced,severity:D.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:D.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:D.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(y=>{var c;return((c=y.implements)==null?void 0:c.id)===r.implements});u?e.push(new w({id:`${r.id}--${$.PropertyOverwritesOtherSiblingWithSameImplementation}`,code:$.PropertyOverwritesOtherSiblingWithSameImplementation,severity:D.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:D.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:D.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){f(this,"version");f(this,"previousVersion",null);f(this,"createdAt");f(this,"deleted",!1);f(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 Cc=(r=>(r.Manual="manual",r.Automatic="automatic",r))(Cc||{}),b=(r=>(r.Added="added",r.Updated="updated",r.Removed="removed",r.Affected="affected",r))(b||{});class A{constructor(a,e,t,i,s=!1,l=""){f(this,"id",m.UUID.uuid());f(this,"seenEntities",[]);f(this,"added",{});f(this,"updated",{});f(this,"removed",{});f(this,"affected",{});f(this,"self",null);f(this,"author");f(this,"timestamp");f(this,"open",!0);f(this,"dirty",!0);f(this,"type","manual");f(this,"autoclose",!1);f(this,"autoCloseActionName","");f(this,"project");if(this.project=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=Ui(),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}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(),...Ui()]));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(y=>y!==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:y,updated:c,removed:E,affected:I}=a.recursiveCaptureUpstreamVersions(this.timestamp);for(const O of y)this.add(O,"added");for(const O of c)this.add(O,"updated");for(const O of E)this.add(O,"removed");for(const O of I)this.add(O,"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:y,updated:c,removed:E,affected:I}=a.recursiveCaptureUpstreamVersions(this.timestamp);for(const O of y)this.add(O,"added");for(const O of c)this.add(O,"updated");for(const O of E)this.add(O,"removed");for(const O of I)this.add(O,"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,this}if(e==="updated"){if(this.removed[a.id])return this;if(this.added[a.id])return a.captureVersion(),this;if(this.affected[a.id]&&delete this.affected[a.id],!this.hasUpdated(a.id)){a.increaseVersion(this.timestamp);const{added:y,updated:c,removed:E,affected:I}=a.recursiveCaptureUpstreamVersions(this.timestamp);for(const O of y)this.add(O,"added");for(const O of c)this.add(O,"updated");for(const O of E)this.add(O,"removed");for(const O of I)this.add(O,"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}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 wJ(r){return new Set([...Object.keys(r.added),...Object.keys(r.updated),...Object.keys(r.removed),...Array.from(r.affected)])}var n1=(r=>(r.Implements="implements",r.DataTypeEntity="data-type-entity",r))(n1||{});const Ae=class Ae extends lt{constructor(e,t){super(e);f(this,"initialData");f(this,"id");f(this,"name");f(this,"description",null);f(this,"private");f(this,"abstract");f(this,"index");f(this,"static");f(this,"required");f(this,"constant",!1);f(this,"type",n.Property);f(this,"hidden",!1);f(this,"defaultValue",null);f(this,"dataType",null);f(this,"implements",null);f(this,"project");f(this,"errors",[]);f(this,"parent");f(this,"detachedDependents",{});f(this,"knownVersions",null);f(this,"activeVersion",!1);f(this,"initialized",!1);f(this,"startedInitialization",!1);f(this,"suggestion",!1);f(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,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 u=_(e.implements);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.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,dataType:null,parent:s},d=C(o,t);return d.setParent(s,null),d.initChildren(null),d}static validateGenerationTarget(e,t){let i=JSON.parse(JSON.stringify(e));const s=[],l=PJ(i,t),o=Dc(i,t);return s.push(...l,...o,...pt(i)),{errors:s,modifiedData:i}}get isExtendedProperty(){const e=this.parent.allBasePropertiesFromExtendedAndImplementedEntities.find(t=>t.name===this.name);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:D.Error,message:`Entity of type '${this.type}' with id '${this.id}' cannot have the 'parent' property updated, as it would mean moving the '${this.type}' entity to another parent entity.
|
|
44
44
|
This is likely an incorrect strategy, either the '${this.type}' entity doesn't need to be updated or it should be deleted and a new one created in the desired parent.`,issue:null})),(e.readsValue||e.writesValue)&&t.push(new w({id:`${this.id}--${$.InvalidObjectStructure}`,code:$.InvalidObjectStructure,severity:D.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}syncDependents(e=this.project.addChangeSet(new A(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=[];return t==="implements"&&(this.setImplements(null,i),s.push(this)),{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}onDetachedDependencyRestored(e,t,i){const s=[],l=[],o=[],d=[];return t==="implements"&&(this.setImplements(e,i),s.push(this)),{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}subscribeToDependencies(){var e,t,i,s,l;return(t=(e=this.implements)==null?void 0:e.subscribeDependents)==null||t.call(e,[{entity:this,field:"implements"}]),(l=(s=(i=this.dataType)==null?void 0:i.entity)==null?void 0:s.subscribeDependents)==null||l.call(s,[{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 Ae(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[y,c]of this.knownVersions||new Map){if(u.set(y,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 Ae(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(`${Zt(this.type)} with id '${this.id}' has a parent reference "${l}" which is missing in the project`)}else throw new Error(`${Zt(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);o&&(this.setImplements(o,null),e.push(o))}return{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new A(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 A(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 A(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,b.Updated),t==null||t.attemptAutoclose("set-parent",this.id))),this}setImplements(e,t=this.project.addChangeSet(new A(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,b.Updated),t==null||t.attemptAutoclose("set-implements",this.id))),this}initChildren(e=this.project.addChangeSet(new A(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)}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 A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"meta-sync"))){const i=ct(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,b.Removed):e.deleted===!1&&s.deleted?t==null||t.add(this,b.Added):i&&(t==null||t.add(this,b.Updated)),t==null||t.attemptAutoclose("meta-sync",this.id),this}async APILoad(e=U,...t){return await Ae.repository.APILoad(this.id,...t),this}async APICreate(e=U,...t){return await Ae.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=U,...t){return await Ae.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=U,...t){return await Ae.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=U,...t){return await Ae.repository.APIClone(this.id,...t),this}async APILoadVersion(e=U,t,...i){return await Ae.repository.APILoadVersion(this.id,t,...i)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new A(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.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(d=>{const{updated:u,removed:y,added:c}=d.entity.onDetachedDependencyRemoved(this,d.field,t);i.push(...u),s.push(...y),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 A(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:y}=o.entity.onDetachedDependencyRestored(this,o.field,e);i.push(...d),s.push(...u),t.push(...y)}),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;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,parent:this.parent.toReference()})}toJSONClone(e=J){var i,s,l,o,d,u,y;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||ht(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:((y=this.dataType)==null?void 0:y.toJSONClone({...e,newId:null}))||null,implements:(()=>{var c;return this.implements&&this.project.getBuiltIn(this.implements.id)?this.implements.toJSON():((c=this.implements)==null?void 0:c.toJSONClone({...e,newId:null}))||null})(),parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps})})}toReference(e=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;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,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;return{id:this.id,name:this.name,description:this.description,type:this.type,private:this.private,required:this.required,abstract:this.abstract,static:this.static,implements:((e=this.implements)==null?void 0:e.id)||null,parent:this.parent.id}}toFlatGenerationTarget(e=new Set){var i,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=i1(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 A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"clone-entity")),t=null,i=null,s=!0){var I,O;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,parent:d},y=nt(u,l);s&&y.subscribe(),y.setParent(d,null),y.initChildren(e),e==null||e.add(y,b.Added);const c=((I=this.dataType)==null?void 0:I.clone(e,y,m.UUID.uuid(),s))||null;c&&y.setDataType(c);const E=(O=this.defaultValue)==null?void 0:O.clone(e,y,m.UUID.uuid(),s);return y.defaultValue=E||null,this.implements&&(y.implements=this.implements),y.addSelfToProject(null),e==null||e.attemptAutoclose("clone-entity",this.id),y}setDataType(e){return this.dataType=e,this}removeDataType(){return this.dataType=null,this}getDataType(e=this.project.addChangeSet(new A(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}};f(Ae,"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}),f(Ae,"type",n.Property),f(Ae,"USER_MANAGED_PARENT_TYPES",[n.DefinitionEntity]),f(Ae,"PARENT_TYPES",[...Ae.USER_MANAGED_PARENT_TYPES,n.PrimitiveEntity,n.BuiltInBaseEntity]),f(Ae,"MUTABLE_BASE_PROPERTIES",["name","description","private","abstract","static","required","constant"]),f(Ae,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),f(Ae,"BASE_PROPERTIES",[...Ae.MUTABLE_BASE_PROPERTIES,...Ae.INMUTABLE_BASE_PROPERTIES]),f(Ae,"MUTABLE_META_PROPERTIES",[...Ae.MUTABLE_BASE_PROPERTIES,"index"]),f(Ae,"INMUTABLE_META_PROPERTIES",[...Ae.INMUTABLE_BASE_PROPERTIES]),f(Ae,"META_PROPERTIES",[...Ae.MUTABLE_META_PROPERTIES,...Ae.INMUTABLE_META_PROPERTIES]),f(Ae,"MUTABLE_UPSTREAM_PROPERTIES",[]),f(Ae,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","implements"]),f(Ae,"UPSTREAM_PROPERTIES",[...Ae.MUTABLE_UPSTREAM_PROPERTIES,...Ae.INMUTABLE_UPSTREAM_PROPERTIES]),f(Ae,"MUTABLE_DOWNSTREAM_PROPERTIES",["dataType"]),f(Ae,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),f(Ae,"DOWNSTREAM_PROPERTIES",[...Ae.MUTABLE_DOWNSTREAM_PROPERTIES,...Ae.INMUTABLE_DOWNSTREAM_PROPERTIES]),f(Ae,"PROPERTIES",[...Ae.META_PROPERTIES,...Ae.UPSTREAM_PROPERTIES,...Ae.DOWNSTREAM_PROPERTIES]);let Gr=Ae;function s1(r){var s;const a=D5(),e=r.toJSON();a.safeParse(e).success,(s=r.dataType)==null||s.validate();const i=[];if(r.id==="iterate-over-employee-list-continue-statement-employee-dto-output-decl-id"){const l=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:D.Error,code:F.PropertyImplementsNonAbstact,entity:r});i.push(l.error)}return Ke(r.errors,i)}const CJ=Object.freeze(Object.defineProperty({__proto__:null,validate:s1},Symbol.toStringTag,{value:"Module"}));var a1=(r=>(r.Implements="implements",r.DataTypeEntity="data-type-entity",r))(a1||{});const be=class be extends lt{constructor(e,t){super(e);f(this,"initialData");f(this,"id");f(this,"name");f(this,"description",null);f(this,"index");f(this,"required");f(this,"constant",!0);f(this,"isError");f(this,"type",n.ReturnDeclaration);f(this,"defaultValue",null);f(this,"dataType",null);f(this,"readsValue",null);f(this,"implements",null);f(this,"project");f(this,"errors",[]);f(this,"parent");f(this,"detachedDependents",{});f(this,"knownVersions",null);f(this,"activeVersion",!1);f(this,"initialized",!1);f(this,"startedInitialization",!1);f(this,"suggestion",!1);f(this,"_codeNativeValueValidation",null);this.initialData=e,this.project=t,this.id=e.id,this.index=e.index,this.name=e.name,this.description=e.description,this.required=e.required,this.constant=!0,this.isError=e.isError}static 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.ReturnDeclaration,name:"",description:"",dataType:null,index:0,required:!1,constant:!0,isError:!1,implements:null,readsValue:null,defaultValue:null,parent:null}}static fromGenerationTarget(e,t){const i=_(e.parent),s=t.get(i);let l=null;if(e.readsValue){const u=_(e.readsValue);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.ReturnDeclaration,index:s.outputs.length,isError:!1,description:e.description,defaultValue:null,implements:null,required:e.required,constant:!0,readsValue:l,dataType:null,parent:s},d=C(o,t);return d.setParent(s,null),d.initChildren(null),d}static validateGenerationTarget(e,t){var d,u;let i=JSON.parse(JSON.stringify(e));const s=[],l=bt(i,{parent:{list:!1,types:[n.ReturnStatement,n.Search,n.BreakStatement,n.ContinueStatement]}},t),o=Pc(i,t);if(i=l.modifiedData,i.parent){const y=t.get(_(i.parent));if(y&&[n.BreakStatement,n.ContinueStatement].includes(y.type)){const c=y,E=c.parent,I=[...E.breakStatements.filter(P=>P.id!==y.id),...E.continueStatements.filter(P=>P.id!==y.id)];if(c.outputs.length)s.push(new w({id:`${i.id}--${$.NoOverlapWithImplementedSignature}`,code:$.NoOverlapWithImplementedSignature,severity:D.Error,message:`Entity of type '${n.ReturnDeclaration}' with id '${i.id}' cannot be added to the parent entity of type '${c.type}' with id '${c.id}'. This '${c.type}' already has return declarations.
|
|
46
46
|
${$c}`,issue:null}));else{const P=(u=(d=I[0])==null?void 0:d.outputs[0])==null?void 0:u.name;P!==i.name&&s.push(new w({id:`${i.id}--${$.NoOverlapWithImplementedSignature}`,code:$.NoOverlapWithImplementedSignature,severity:D.Error,message:`Entity of type '${n.ReturnDeclaration}' with id '${i.id}' cannot be added to the parent entity of type '${c.type}' with id '${c.id}'. This new 'return-declaration' doesn't have the same name "${P}" as the return declarations on the other statements in the same scope.
|
|
@@ -155,7 +155,7 @@ Input maps can only be added to variables which hold an entity with properties.`
|
|
|
155
155
|
The entity of the data-type has the following properties that can be reads as input maps, ids: '${se(O.properties.map(V=>V.id),"', '","' and '")}'`,issue:null})))}else if(dt.filter(c=>it.includes(c)).includes(o.type)){const E=Kc(o),I=E.find(P=>P.id===i.declaration),O=`The parent entity has the following argument declarations that can be referenced by input-maps, ids: '${se(E.map(P=>P.id),"', '","' and '")}'`;I||s.push(new w({id:`${i.id}--${$.NoOverlapWithImplementedSignature}`,code:$.NoOverlapWithImplementedSignature,severity:D.Error,message:`Entity of type '${n.InputMap}' with id '${i.id}' cannot be added to the parent entity of type '${o.type}' with id '${o.id}'. The parent entity does not have an 'argument-declaration' with id '${i.declaration}'.
|
|
156
156
|
You can't add an input-map to an entity that doesn't have a matching 'argument-declaration'.
|
|
157
157
|
${O}`,issue:null}))}}return s.push(...l.errors,...pt(i)),{errors:s,modifiedData:i}}get codeNativeValueValidation(){var e;return this._codeNativeValueValidation||((e=this.declaration)==null?void 0:e.codeNativeValueValidation)||null}validateGeneratedUpdate(e){const t=[];let i=JSON.parse(JSON.stringify(e));const s=_a(i,this);return i=s.modifiedData,t.push(...s.errors),i.parent&&t.push(new w({id:`${this.id}--${R.InvalidParentUpdate}`,code:R.InvalidParentUpdate,severity:D.Error,message:`Entity of type '${this.type}' with id '${this.id}' cannot have the 'parent' property updated, as it would mean moving the '${this.type}' entity to another parent entity.
|
|
158
|
-
This is likely an incorrect strategy, either the '${this.type}' entity doesn't need to be updated or it should be deleted and a new one created in the desired parent.`,issue:null})),{errors:t,modifiedData:i}}subscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]||(this.detachedDependents[t.entity.id]=t)}),this}syncDependents(e=this.project.addChangeSet(new A(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==="declaration"){const{updated:u,added:y,removed:c}=this.remove({ignoreUpstream:!1},i);s.push(...u),l.push(...y),o.push(...c)}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==="declaration"){const{updated:u,added:y,removed:c}=this.restore({},i);s.push(...u),l.push(...y),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}subscribeToDependencies(){var e,t,i,s,l;return(t=(e=this.declaration)==null?void 0:e.subscribeDependents)==null||t.call(e,[{entity:this,field:"declaration"}]),(l=(s=(i=this.dataType)==null?void 0:i.entity)==null?void 0:s.subscribeDependents)==null||l.call(s,[{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 _e(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.declaration=this.declaration,e.defaultValue=this.defaultValue,e.readsValue=this.readsValue,e.dataType=this.dataType,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],i=[],s=[],l=[];if(this.parent){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[y,c]of this.knownVersions||new Map){if(u.set(y,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 _e(u,this.project)}return this.metaSync(o.toShallowJSON(),null),this.declaration=o.declaration,this.defaultValue=o.defaultValue,this.readsValue=o.readsValue,this.dataType=o.dataType,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(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(this.initialData.readsValue){const l=_(this.initialData.readsValue),o=this.project.get(l);o&&(this.setValueWriter(o,null),e.push(o))}if(this.initialData.declaration){const l=_(this.initialData.declaration),o=this.project.get(l);o&&(this.setDeclaration(o),e.push(o))}return Rr.hydrateReadsValue(this),{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new A(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 A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-self-to-project"))){var o,d;const t=[this],i=[],s=[],l=[];if(this.parent.addInput(this,e),t.push(this.parent),(o=this.readsValue)==null||o.addValueReader(this,e),this.readsValue&&t.push(this.readsValue),it.includes(this.parent.type)&&((d=this.parent.getDataType(e))!=null&&d.inferred)){const u=this.parent.type===n.VariableDeclaration?this.parent:this.parent.declaration,{updated:y,added:c,removed:E,affected:I}=u.inferDataTypeAndSyncInstancesInputsAndOutputs(e);t.push(...y),i.push(...c),s.push(...E),l.push(...I),t.push(u,...u.variableInstances)}return 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 A(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,b.Updated),t==null||t.attemptAutoclose("set-parent",this.id))),this}setDataType(e){return this.dataType=e,this}removeDataType(){return this.dataType=null,this}setDeclaration(e){return this.declaration=e,this}initChildren(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(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.declaration&&(this.declaration=C(this.initialData.declaration,this.project)),Rr.initReadsValue(this),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this)}setValueWriter(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"set-value-writer"))){return this.readsValue!==e&&(this.readsValue=e,t==null||t.add(this,b.Updated)),t==null||t.attemptAutoclose("set-value-writer",this.id),this}removeValueWriter(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-value-writer"))){return this.readsValue&&(this.readsValue=null,e==null||e.add(this,b.Updated)),e==null||e.attemptAutoclose("remove-value-writer",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 A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"meta-sync"))){const i=ct(this,e),s=this.toMeta();return this.index=e.index||(e.index!==0?s.index:0),this.name=e.name!==void 0?e.name:s.name,this.description=e.description!==void 0?e.description:s.description,super.metaSync(e),e.deleted===!0&&!s.deleted?t==null||t.add(this,b.Removed):e.deleted===!1&&s.deleted?t==null||t.add(this,b.Added):i&&(t==null||t.add(this,b.Updated)),t==null||t.attemptAutoclose("meta-sync",this.id),this}async APILoad(e=U,...t){return await _e.repository.APILoad(this.id,...t),this}async APICreate(e=U,...t){return await _e.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=U,...t){return await _e.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=U,...t){return await _e.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=U,...t){return await _e.repository.APIClone(this.id,...t),this}async APILoadVersion(e=U,t,...i){return await _e.repository.APILoadVersion(this.id,t,...i)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-entity"))){var d;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.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(u=>{const{updated:y,removed:c,added:E}=u.entity.onDetachedDependencyRemoved(this,u.field,t);i.push(...y),s.push(...c),l.push(...E)}),this.defaultValue){const{updated:u,removed:y}=this.defaultValue.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...y)}if(this.readsValue&&(i.push(this.readsValue),this.readsValue.removeValueReader(this,t)),this.defaultValue&&(i.push(this.defaultValue),this.defaultValue.remove({ignoreUpstream:!0},t)),this.declaration){if(this.declaration.type===n.Property&&this.declaration.parent.type===n.DefinitionEntity&&this.declaration.parent.parent.type===n.DataType&&!(t!=null&&t.hasRemoved(this.declaration.id))&&!this.declaration.deleted){const{updated:u,removed:y}=this.declaration.remove({ignoreUpstream:!1},t);i.push(...u),s.push(...y)}else if(this.declaration.type===n.ValueDescriptor&&((d=this.declaration.parent)==null?void 0:d.type)===n.Search&&!(t!=null&&t.hasRemoved(this.declaration.id))&&!this.declaration.deleted){const{updated:u,removed:y}=this.declaration.remove({ignoreUpstream:!1},t);i.push(...u),s.push(...y)}}return e||(i.push(this.parent),this.parent.removeInput(this,t)),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 A(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:y}=o.entity.onDetachedDependencyRestored(this,o.field,e);i.push(...d),s.push(...u),t.push(...y)}),this.defaultValue){const{updated:o}=this.defaultValue.restore({},e);i.push(...o)}return this.readsValue&&(i.push(this.readsValue),this.readsValue.addValueReader(this,e)),this.defaultValue&&(i.push(this.defaultValue),this.defaultValue.restore({},e)),i.push(this.parent),this.parent.addInput(this,e),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.defaultValue?this.defaultValue.toFlat(e):[],...this.dataType?this.dataType.toFlat(e):[],...this.declaration?this.declaration.toFlat(e):[],...this.readsValue?this.readsValue.toFlat(e):[]])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.defaultValue?this.defaultValue.toFlatIds(e):[],...this.dataType?this.dataType.toFlatIds(e):[],...this.declaration?this.declaration.toFlatIds(e):[],...this.readsValue?this.readsValue.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,type:this.type,name:this.name}}toJSON(e=new Set){var t,i,s;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,index:this.index,name:this.name,description:this.description,defaultValue:((t=this.defaultValue)==null?void 0:t.toJSON(e))||null,declaration:((i=this.declaration)==null?void 0:i.toJSON(e))||null,readsValue:((s=this.readsValue)==null?void 0:s.toReference())||null,parent:this.parent.toReference()})}toJSONClone(e=J){var i,s,l,o,d,u,y,c,E,I,O;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||ht(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,index:this.index,name:this.name,description:this.description,defaultValue:((u=this.defaultValue)==null?void 0:u.toJSONClone({...e,newId:null}))||null,declaration:(y=this.declaration)!=null&&y.id&&this.project.getBuiltIn((c=this.declaration)==null?void 0:c.id)?(E=this.declaration)==null?void 0:E.toJSON(e.seenEntities):((I=this.declaration)==null?void 0:I.toJSONClone({...e,newId:null}))||null,readsValue:((O=this.readsValue)==null?void 0:O.toReference({seenEntityMaps:e.seenEntityMaps}))||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;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,defaultValue:((s=this.defaultValue)==null?void 0:s.toReference(e))||null,declaration:((l=this.declaration)==null?void 0:l.toReference(e))||null,readsValue:((o=this.readsValue)==null?void 0:o.toReference(e))||null,parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.defaultValue?this.defaultValue.toFlatJSON(e):[],...this.dataType?this.dataType.toFlatJSON(e):[],...this.declaration?this.declaration.toFlatJSON(e):[],...this.readsValue?this.readsValue.toFlatJSON(e):[]])}toGenerationTarget(){var e;return{id:this.id,name:this.name||void 0,description:this.description||void 0,type:this.type,declaration:((e=this.declaration)==null?void 0:e.id)||null,parent:this.parent.id}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...this.defaultValue?this.defaultValue.toFlatGenerationTarget(e):[],...this.dataType?this.dataType.toFlatGenerationTarget(e):[],...this.readsValue?this.readsValue.toFlatGenerationTarget(e):[],...this.declaration?this.declaration.toFlatGenerationTarget(e):[]])}clearErrors(){var e;return this.errors=[],(e=this.defaultValue)==null||e.clearErrors(),this}validate(){const e=B1(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){var t;return[...this.errors,...((t=this.defaultValue)==null?void 0:t.getErrors())||[]]}getShallowErrors(){return this.errors}getDefaultValue(){var e;return this.defaultValue||((e=this.declaration)==null?void 0:e.defaultValue)||null}setDefaultValue(e){return this.defaultValue=e,this}clone(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"clone-entity")),t=null,i=null,s=!0){var c;let l=mt(t,this);const o=this.toJSON(),d=i||m.UUID.uuid();o.defaultValue=null,o.id=d,o.version=m.UUID.uuid(),o.createdAt=(e==null?void 0:e.timestamp)||T().toISOString(),o.author=(e==null?void 0:e.author)||"1",o.previousVersion=null,o.deleted=!1;const u=nt(o,l);t?u.setParent(t,null):u.setParent(this.parent,null),s&&u.subscribe(),u.initChildren(e),e==null||e.add(u,b.Added);const y=(c=this.defaultValue)==null?void 0:c.clone(e,u,m.UUID.uuid(),s);return u.defaultValue=y||null,e==null||e.attemptAutoclose("clone-entity",this.id),u}getDataType(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"get-data-type"))){var i;if(it.includes(this.parent.type)){const s=Un(this.parent),l=s.getDataType(e);(!l||l.inferred)&&s.inferDataTypeAndSyncInstancesInputsAndOutputs(e)}const t=(i=this.declaration)==null?void 0:i.getDataType(e);if(!t){const s=ji(this,e);if(s)return s}return t||null}};f(_e,"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}),f(_e,"type",n.InputMap),f(_e,"USER_MANAGED_PARENT_TYPES",[...dt]),f(_e,"PARENT_TYPES",[..._e.USER_MANAGED_PARENT_TYPES]),f(_e,"MUTABLE_BASE_PROPERTIES",["name","description"]),f(_e,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),f(_e,"BASE_PROPERTIES",[..._e.MUTABLE_BASE_PROPERTIES,..._e.INMUTABLE_BASE_PROPERTIES]),f(_e,"MUTABLE_META_PROPERTIES",[..._e.MUTABLE_BASE_PROPERTIES,"index"]),f(_e,"INMUTABLE_META_PROPERTIES",[..._e.INMUTABLE_BASE_PROPERTIES]),f(_e,"META_PROPERTIES",[..._e.MUTABLE_META_PROPERTIES,..._e.INMUTABLE_META_PROPERTIES]),f(_e,"MUTABLE_UPSTREAM_PROPERTIES",["readsValue"]),f(_e,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","declaration"]),f(_e,"UPSTREAM_PROPERTIES",[..._e.MUTABLE_UPSTREAM_PROPERTIES,..._e.INMUTABLE_UPSTREAM_PROPERTIES]),f(_e,"MUTABLE_DOWNSTREAM_PROPERTIES",["defaultValue"]),f(_e,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),f(_e,"DOWNSTREAM_PROPERTIES",[..._e.MUTABLE_DOWNSTREAM_PROPERTIES,..._e.INMUTABLE_DOWNSTREAM_PROPERTIES]),f(_e,"PROPERTIES",[..._e.META_PROPERTIES,..._e.UPSTREAM_PROPERTIES,..._e.DOWNSTREAM_PROPERTIES]);let Ki=_e;class HJ extends Ki{constructor(e,t){super(e,t);f(this,"declaration",null);f(this,"parent");f(this,"errors",[])}toJSON(e=new Set){return super.toJSON(e)}}class KJ extends Ki{constructor(e,t){super(e,t);f(this,"name",null);f(this,"description",null);f(this,"declaration");f(this,"parent");f(this,"errors",[])}toJSON(e=new Set){return super.toJSON(e)}}function M1(r){const a=M5(),e=r.toJSON();a.safeParse(e).success;const i=[];if(r.id==="exec-sequentially-return-map-id"){const s=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:D.Error,code:F.PropertyImplementsNonAbstact,entity:r});i.push(s.error)}return Ke(r.errors,i)}const XJ=Object.freeze(Object.defineProperty({__proto__:null,validate:M1},Symbol.toStringTag,{value:"Module"}));var N1=(r=>(r.Declaration="declaration",r.DataTypeEntity="data-type-entity",r))(N1||{});const Me=class Me extends lt{constructor(e,t){super(e);f(this,"initialData");f(this,"id");f(this,"index");f(this,"type",n.OutputMap);f(this,"parentRelationType");f(this,"defaultValue",null);f(this,"declaration");f(this,"writesValues",[]);f(this,"dataType");f(this,"project");f(this,"errors",[]);f(this,"parent");f(this,"detachedDependents",{});f(this,"knownVersions",null);f(this,"activeVersion",!1);f(this,"initialized",!1);f(this,"startedInitialization",!1);f(this,"suggestion",!1);f(this,"_codeNativeValueValidation",null);this.initialData=e,this.project=t,this.id=e.id,this.index=e.index,this.parentRelationType=e.parentRelationType}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.OutputMap,declaration:null,writesValues:[],index:0,defaultValue:null,parent:null}}static fromGenerationTarget(e,t){const i=_(e.parent),s=t.get(i);let l;if(e.declaration){const u=_(e.declaration);l=t.get(u)}const o={id:e.id,version:m.UUID.uuid(),createdAt:T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.OutputMap,index:(s.outputs||[]).length,defaultValue:null,declaration:l,writesValues:[],parent:s},d=C(o,t);return d.setParent(s,null),d.initChildren(null),d}static validateGenerationTarget(e,t){var d;let i=JSON.parse(JSON.stringify(e));const s=[],l=bt(i,{parent:{list:!1,types:dt.filter(u=>u!==n.Condition)},declaration:{list:!1,types:[n.ReturnDeclaration,n.Property]}},t);i=l.modifiedData;const o=t.get(i.parent);if(o&&dt.filter(u=>u!==n.Condition).includes(o.type)){const u=o.outputs.find(y=>y.declaration.id===(i.declaration?_(i.declaration):null));if(u)s.push(new w({id:`${i.id}--${R.OutputOverwrite}`,code:R.OutputOverwrite,severity:D.Error,message:`Entity of type '${n.OutputMap}' with id '${i.id}' cannot be added to the parent entity of type '${o.type}' with id '${o.id}'. The parent already has an output-map with id '${u.id}' that points to the same base 'return-declaration'.
|
|
158
|
+
This is likely an incorrect strategy, either the '${this.type}' entity doesn't need to be updated or it should be deleted and a new one created in the desired parent.`,issue:null})),{errors:t,modifiedData:i}}subscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]||(this.detachedDependents[t.entity.id]=t)}),this}syncDependents(e=this.project.addChangeSet(new A(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==="declaration"){const{updated:u,added:y,removed:c}=this.remove({ignoreUpstream:!1},i);s.push(...u),l.push(...y),o.push(...c)}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==="declaration"){const{updated:u,added:y,removed:c}=this.restore({},i);s.push(...u),l.push(...y),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}subscribeToDependencies(){var e,t,i,s,l;return(t=(e=this.declaration)==null?void 0:e.subscribeDependents)==null||t.call(e,[{entity:this,field:"declaration"}]),(l=(s=(i=this.dataType)==null?void 0:i.entity)==null?void 0:s.subscribeDependents)==null||l.call(s,[{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 _e(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.declaration=this.declaration,e.defaultValue=this.defaultValue,e.readsValue=this.readsValue,e.dataType=this.dataType,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],i=[],s=[],l=[];if(this.parent){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[y,c]of this.knownVersions||new Map){if(u.set(y,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 _e(u,this.project)}return this.metaSync(o.toShallowJSON(),null),this.declaration=o.declaration,this.defaultValue=o.defaultValue,this.readsValue=o.readsValue,this.dataType=o.dataType,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(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(this.initialData.readsValue){const l=_(this.initialData.readsValue),o=this.project.get(l);o&&(this.setValueWriter(o,null),e.push(o))}if(this.initialData.declaration){const l=_(this.initialData.declaration),o=this.project.get(l);o&&(this.setDeclaration(o),e.push(o))}return Rr.hydrateReadsValue(this),{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new A(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 A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-self-to-project"))){var o,d;const t=[this],i=[],s=[],l=[];if(this.parent.addInput(this,e),t.push(this.parent),(o=this.readsValue)==null||o.addValueReader(this,e),this.readsValue&&t.push(this.readsValue),it.includes(this.parent.type)&&((d=this.parent.getDataType(e))!=null&&d.inferred)){const u=this.parent.type===n.VariableDeclaration?this.parent:this.parent.declaration,{updated:y,added:c,removed:E,affected:I}=u.inferDataTypeAndSyncInstancesInputsAndOutputs(e);t.push(...y),i.push(...c),s.push(...E),l.push(...I),t.push(u,...u.variableInstances)}return 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 A(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,b.Updated),t==null||t.attemptAutoclose("set-parent",this.id))),this}setDataType(e){return this.dataType=e,this}removeDataType(){return this.dataType=null,this}setDeclaration(e){return this.declaration=e,this}initChildren(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(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.declaration&&(this.declaration=C(this.initialData.declaration,this.project)),Rr.initReadsValue(this),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this)}setValueWriter(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"set-value-writer"))){return this.readsValue!==e&&(this.readsValue=e,t==null||t.add(this,b.Updated)),t==null||t.attemptAutoclose("set-value-writer",this.id),this}removeValueWriter(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-value-writer"))){return this.readsValue&&(this.readsValue=null,e==null||e.add(this,b.Updated)),e==null||e.attemptAutoclose("remove-value-writer",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 A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"meta-sync"))){const i=ct(this,e),s=this.toMeta();return this.index=e.index||(e.index!==0?s.index:0),this.name=e.name!==void 0?e.name:s.name,this.description=e.description!==void 0?e.description:s.description,super.metaSync(e),e.deleted===!0&&!s.deleted?t==null||t.add(this,b.Removed):e.deleted===!1&&s.deleted?t==null||t.add(this,b.Added):i&&(t==null||t.add(this,b.Updated)),t==null||t.attemptAutoclose("meta-sync",this.id),this}async APILoad(e=U,...t){return await _e.repository.APILoad(this.id,...t),this}async APICreate(e=U,...t){return await _e.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=U,...t){return await _e.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=U,...t){return await _e.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=U,...t){return await _e.repository.APIClone(this.id,...t),this}async APILoadVersion(e=U,t,...i){return await _e.repository.APILoadVersion(this.id,t,...i)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-entity"))){var d;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.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(u=>{const{updated:y,removed:c,added:E}=u.entity.onDetachedDependencyRemoved(this,u.field,t);i.push(...y),s.push(...c),l.push(...E)}),this.defaultValue){const{updated:u,removed:y}=this.defaultValue.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...y)}if(this.readsValue&&(i.push(this.readsValue),this.readsValue.removeValueReader(this,t)),this.defaultValue&&(i.push(this.defaultValue),this.defaultValue.remove({ignoreUpstream:!0},t)),this.declaration){if(this.declaration.type===n.Property&&this.declaration.parent.type===n.DefinitionEntity&&this.declaration.parent.parent.type===n.DataType&&!(t!=null&&t.hasRemoved(this.declaration.id))&&!this.declaration.deleted){const{updated:u,removed:y}=this.declaration.remove({ignoreUpstream:!1},t);i.push(...u),s.push(...y)}else if(this.declaration.type===n.ValueDescriptor&&((d=this.declaration.parent)==null?void 0:d.type)===n.Search&&!(t!=null&&t.hasRemoved(this.declaration.id))&&!this.declaration.deleted){const{updated:u,removed:y}=this.declaration.remove({ignoreUpstream:!1},t);i.push(...u),s.push(...y)}}return e||(i.push(this.parent),this.parent.removeInput(this,t)),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 A(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:y}=o.entity.onDetachedDependencyRestored(this,o.field,e);i.push(...d),s.push(...u),t.push(...y)}),this.defaultValue){const{updated:o}=this.defaultValue.restore({},e);i.push(...o)}return this.readsValue&&(i.push(this.readsValue),this.readsValue.addValueReader(this,e)),this.defaultValue&&(i.push(this.defaultValue),this.defaultValue.restore({},e)),i.push(this.parent),this.parent.addInput(this,e),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.defaultValue?this.defaultValue.toFlat(e):[],...this.dataType?this.dataType.toFlat(e):[],...this.declaration?this.declaration.toFlat(e):[],...this.readsValue?this.readsValue.toFlat(e):[]])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.defaultValue?this.defaultValue.toFlatIds(e):[],...this.dataType?this.dataType.toFlatIds(e):[],...this.declaration?this.declaration.toFlatIds(e):[],...this.readsValue?this.readsValue.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,type:this.type,name:this.name}}toJSON(e=new Set){var t,i,s;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,index:this.index,name:this.name,description:this.description,defaultValue:((t=this.defaultValue)==null?void 0:t.toJSON(e))||null,declaration:((i=this.declaration)==null?void 0:i.toJSON(e))||null,readsValue:((s=this.readsValue)==null?void 0:s.toReference())||null,parent:this.parent.toReference()})}toJSONClone(e=J){var i,s,l,o,d,u,y,c,E,I,O;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||ht(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,index:this.index,name:this.name,description:this.description,defaultValue:((u=this.defaultValue)==null?void 0:u.toJSONClone({...e,newId:null}))||null,declaration:(y=this.declaration)!=null&&y.id&&this.project.getBuiltIn((c=this.declaration)==null?void 0:c.id)?(E=this.declaration)==null?void 0:E.toJSON(e.seenEntities):((I=this.declaration)==null?void 0:I.toJSONClone({...e,newId:null}))||null,readsValue:((O=this.readsValue)==null?void 0:O.toReference({seenEntityMaps:e.seenEntityMaps}))||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;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,defaultValue:((s=this.defaultValue)==null?void 0:s.toReference(e))||null,declaration:((l=this.declaration)==null?void 0:l.toReference(e))||null,readsValue:((o=this.readsValue)==null?void 0:o.toReference(e))||null,parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.defaultValue?this.defaultValue.toFlatJSON(e):[],...this.dataType?this.dataType.toFlatJSON(e):[],...this.declaration?this.declaration.toFlatJSON(e):[],...this.readsValue?this.readsValue.toFlatJSON(e):[]])}toGenerationTarget(){var e;return{id:this.id,name:this.name||void 0,description:this.description||void 0,type:this.type,declaration:((e=this.declaration)==null?void 0:e.id)||null,parent:this.parent.id}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...this.defaultValue?this.defaultValue.toFlatGenerationTarget(e):[],...this.dataType?this.dataType.toFlatGenerationTarget(e):[],...this.readsValue?this.readsValue.toFlatGenerationTarget(e):[],...this.declaration?this.declaration.toFlatGenerationTarget(e):[]])}clearErrors(){var e;return this.errors=[],(e=this.defaultValue)==null||e.clearErrors(),this}validate(){const e=B1(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){var t;return[...this.errors,...((t=this.defaultValue)==null?void 0:t.getErrors())||[]]}getShallowErrors(){return this.errors}getDefaultValue(){var e;return this.defaultValue||((e=this.declaration)==null?void 0:e.defaultValue)||null}setDefaultValue(e){return this.defaultValue=e,this}clone(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"clone-entity")),t=null,i=null,s=!0){var c;let l=mt(t,this);const o=this.toJSON(),d=i||m.UUID.uuid();o.defaultValue=null,o.id=d,o.version=m.UUID.uuid(),o.createdAt=(e==null?void 0:e.timestamp)||T().toISOString(),o.author=(e==null?void 0:e.author)||"1",o.previousVersion=null,o.deleted=!1;const u=nt(o,l);t?u.setParent(t,null):u.setParent(this.parent,null),s&&u.subscribe(),u.initChildren(e),e==null||e.add(u,b.Added);const y=(c=this.defaultValue)==null?void 0:c.clone(e,u,m.UUID.uuid(),s);return u.defaultValue=y||null,e==null||e.attemptAutoclose("clone-entity",this.id),u}getDataType(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"get-data-type"))){var i;if(it.includes(this.parent.type)){const s=Un(this.parent),l=s.getDataType(e);(!l||l.inferred)&&s.inferDataTypeAndSyncInstancesInputsAndOutputs(e)}const t=(i=this.declaration)==null?void 0:i.getDataType(e);if(!t){const s=ji(this,e);if(s)return s}return t||null}};f(_e,"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}),f(_e,"type",n.InputMap),f(_e,"USER_MANAGED_PARENT_TYPES",[...dt]),f(_e,"PARENT_TYPES",[..._e.USER_MANAGED_PARENT_TYPES]),f(_e,"MUTABLE_BASE_PROPERTIES",["name","description"]),f(_e,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),f(_e,"BASE_PROPERTIES",[..._e.MUTABLE_BASE_PROPERTIES,..._e.INMUTABLE_BASE_PROPERTIES]),f(_e,"MUTABLE_META_PROPERTIES",[..._e.MUTABLE_BASE_PROPERTIES,"index"]),f(_e,"INMUTABLE_META_PROPERTIES",[..._e.INMUTABLE_BASE_PROPERTIES]),f(_e,"META_PROPERTIES",[..._e.MUTABLE_META_PROPERTIES,..._e.INMUTABLE_META_PROPERTIES]),f(_e,"MUTABLE_UPSTREAM_PROPERTIES",["readsValue"]),f(_e,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","declaration"]),f(_e,"UPSTREAM_PROPERTIES",[..._e.MUTABLE_UPSTREAM_PROPERTIES,..._e.INMUTABLE_UPSTREAM_PROPERTIES]),f(_e,"MUTABLE_DOWNSTREAM_PROPERTIES",["defaultValue"]),f(_e,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),f(_e,"DOWNSTREAM_PROPERTIES",[..._e.MUTABLE_DOWNSTREAM_PROPERTIES,..._e.INMUTABLE_DOWNSTREAM_PROPERTIES]),f(_e,"PROPERTIES",[..._e.META_PROPERTIES,..._e.UPSTREAM_PROPERTIES,..._e.DOWNSTREAM_PROPERTIES]);let Ki=_e;class HJ extends Ki{constructor(e,t){super(e,t);f(this,"declaration",null);f(this,"parent");f(this,"errors",[])}toJSON(e=new Set){return super.toJSON(e)}}class KJ extends Ki{constructor(e,t){super(e,t);f(this,"name",null);f(this,"description",null);f(this,"declaration");f(this,"parent");f(this,"errors",[])}toJSON(e=new Set){return super.toJSON(e)}}function M1(r){const a=M5(),e=r.toJSON();a.safeParse(e).success;const i=[];if(r.id==="exec-sequentially-return-map-id"){const s=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:D.Error,code:F.PropertyImplementsNonAbstact,entity:r});i.push(s.error)}return Ke(r.errors,i)}const XJ=Object.freeze(Object.defineProperty({__proto__:null,validate:M1},Symbol.toStringTag,{value:"Module"}));var N1=(r=>(r.Declaration="declaration",r.DataTypeEntity="data-type-entity",r))(N1||{});const Me=class Me extends lt{constructor(e,t){super(e);f(this,"initialData");f(this,"id");f(this,"index");f(this,"type",n.OutputMap);f(this,"parentRelationType");f(this,"defaultValue",null);f(this,"declaration");f(this,"writesValues",[]);f(this,"dataType",null);f(this,"project");f(this,"errors",[]);f(this,"parent");f(this,"detachedDependents",{});f(this,"knownVersions",null);f(this,"activeVersion",!1);f(this,"initialized",!1);f(this,"startedInitialization",!1);f(this,"suggestion",!1);f(this,"_codeNativeValueValidation",null);this.initialData=e,this.project=t,this.id=e.id,this.index=e.index,this.parentRelationType=e.parentRelationType}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.OutputMap,declaration:null,writesValues:[],index:0,defaultValue:null,parent:null}}static fromGenerationTarget(e,t){const i=_(e.parent),s=t.get(i);let l;if(e.declaration){const u=_(e.declaration);l=t.get(u)}const o={id:e.id,version:m.UUID.uuid(),createdAt:T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.OutputMap,index:(s.outputs||[]).length,defaultValue:null,declaration:l,writesValues:[],parent:s},d=C(o,t);return d.setParent(s,null),d.initChildren(null),d}static validateGenerationTarget(e,t){var d;let i=JSON.parse(JSON.stringify(e));const s=[],l=bt(i,{parent:{list:!1,types:dt.filter(u=>u!==n.Condition)},declaration:{list:!1,types:[n.ReturnDeclaration,n.Property]}},t);i=l.modifiedData;const o=t.get(i.parent);if(o&&dt.filter(u=>u!==n.Condition).includes(o.type)){const u=o.outputs.find(y=>y.declaration.id===(i.declaration?_(i.declaration):null));if(u)s.push(new w({id:`${i.id}--${R.OutputOverwrite}`,code:R.OutputOverwrite,severity:D.Error,message:`Entity of type '${n.OutputMap}' with id '${i.id}' cannot be added to the parent entity of type '${o.type}' with id '${o.id}'. The parent already has an output-map with id '${u.id}' that points to the same base 'return-declaration'.
|
|
159
159
|
Any value reads can be done with that output-map instead.
|
|
160
160
|
You can't edit output-map entities as they need to match their return declarations, so you can only choose to read their outputted value if you need it.`,issue:null}));else{const y=i.declaration?t.get(i.declaration):null;if(y&&it.includes(o.type)){const c=Un(o),E=c.dataType,I=(d=c.dataType)==null?void 0:d.entity;E?I?I.type===n.ActionDescriptor?s.push(new w({id:`${i.id}--${$.NoOverlapWithImplementedSignature}`,code:$.NoOverlapWithImplementedSignature,severity:D.Error,message:`Entity of type '${n.OutputMap}' with id '${i.id}' cannot be added to the parent entity of type '${o.type}' with id '${o.id}'. The data type of the 'variable-declaration' is a 'action-descriptor' entity.
|
|
161
161
|
This means it can hold a function-call or operation as its value, to be executed programatically.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@elyx-code/project-logic-tree",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.6242",
|
|
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",
|