@elyx-code/project-logic-tree 0.0.6230 → 0.0.6231
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 +17 -11
- package/dist/index.umd.cjs +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -57348,7 +57348,7 @@ This is likely an incorrect strategy, either the '${this.type}' entity doesn't n
|
|
|
57348
57348
|
};
|
|
57349
57349
|
}
|
|
57350
57350
|
toJSON(e = /* @__PURE__ */ new Set()) {
|
|
57351
|
-
var t, r;
|
|
57351
|
+
var t, r, s;
|
|
57352
57352
|
return e.has(this.id) ? this.toReference() : (e.add(this.id), {
|
|
57353
57353
|
id: this.id,
|
|
57354
57354
|
version: this.version,
|
|
@@ -57364,13 +57364,14 @@ This is likely an incorrect strategy, either the '${this.type}' entity doesn't n
|
|
|
57364
57364
|
e
|
|
57365
57365
|
)) || null,
|
|
57366
57366
|
valueAsTypeList: Array.isArray(this.valueAsTypeSingle) ? this.valueAsTypeSingle.map(
|
|
57367
|
-
(
|
|
57367
|
+
(d) => d.toJSON(e)
|
|
57368
57368
|
) : null,
|
|
57369
|
-
parent: (r = this.parent) == null ? void 0 : r.toReference()
|
|
57369
|
+
parent: (r = this.parent) == null ? void 0 : r.toReference(),
|
|
57370
|
+
standaloneParent: (s = this.standaloneParent) == null ? void 0 : s.toReference()
|
|
57370
57371
|
});
|
|
57371
57372
|
}
|
|
57372
57373
|
toJSONClone(e = J) {
|
|
57373
|
-
var r, s, d, o, l, u;
|
|
57374
|
+
var r, s, d, o, l, u, h;
|
|
57374
57375
|
let t;
|
|
57375
57376
|
return (r = e.seenEntityMaps) != null && r.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) || (d = e.seenEntities) != null && d.has(this.id) ? this.toReference({ seenEntityMaps: e.seenEntityMaps }) : ((o = e.seenEntities) == null || o.add(t), (l = e.seenEntities) == null || l.add(this.id), {
|
|
57376
57377
|
id: t,
|
|
@@ -57386,10 +57387,13 @@ This is likely an incorrect strategy, either the '${this.type}' entity doesn't n
|
|
|
57386
57387
|
// @ts-ignore
|
|
57387
57388
|
valueAsTypeSingle: this.valueAsTypeSingle ? this.project.getBuiltIn(this.valueAsTypeSingle.id) ? this.valueAsTypeSingle.toJSON() : this.valueAsTypeSingle.toJSONClone({ ...e, newId: null }) : null,
|
|
57388
57389
|
valueAsTypeList: this.valueAsTypeSingle && Array.isArray(this.valueAsTypeSingle) ? this.valueAsTypeSingle.map(
|
|
57389
|
-
(
|
|
57390
|
+
(c) => this.project.getBuiltIn(c.id) ? c.toJSON() : c.toJSONClone({ ...e, newId: null })
|
|
57390
57391
|
) : null,
|
|
57391
57392
|
parent: (u = this.parent) == null ? void 0 : u.toReference({
|
|
57392
57393
|
seenEntityMaps: e.seenEntityMaps
|
|
57394
|
+
}),
|
|
57395
|
+
standaloneParent: (h = this.standaloneParent) == null ? void 0 : h.toReference({
|
|
57396
|
+
seenEntityMaps: e.seenEntityMaps
|
|
57393
57397
|
})
|
|
57394
57398
|
});
|
|
57395
57399
|
}
|
|
@@ -57405,7 +57409,7 @@ This is likely an incorrect strategy, either the '${this.type}' entity doesn't n
|
|
|
57405
57409
|
};
|
|
57406
57410
|
}
|
|
57407
57411
|
toShallowJSON(e = J) {
|
|
57408
|
-
var r, s, d;
|
|
57412
|
+
var r, s, d, o;
|
|
57409
57413
|
let t = this.id;
|
|
57410
57414
|
return (r = e.seenEntityMaps) != null && r.has(this.id) && (t = e.seenEntityMaps.get(this.id)), {
|
|
57411
57415
|
id: t,
|
|
@@ -57420,11 +57424,12 @@ This is likely an incorrect strategy, either the '${this.type}' entity doesn't n
|
|
|
57420
57424
|
e
|
|
57421
57425
|
)) || null,
|
|
57422
57426
|
valueAsTypeList: Array.isArray(this.valueAsTypeSingle) ? this.valueAsTypeSingle.map(
|
|
57423
|
-
(
|
|
57427
|
+
(l) => l.toReference(e)
|
|
57424
57428
|
) : null,
|
|
57425
57429
|
value: this.value,
|
|
57426
57430
|
autogeneration: this.autogeneration,
|
|
57427
|
-
parent: (d = this.parent) == null ? void 0 : d.toReference(e)
|
|
57431
|
+
parent: (d = this.parent) == null ? void 0 : d.toReference(e),
|
|
57432
|
+
standaloneParent: (o = this.standaloneParent) == null ? void 0 : o.toReference(e)
|
|
57428
57433
|
};
|
|
57429
57434
|
}
|
|
57430
57435
|
toFlatJSON(e = /* @__PURE__ */ new Set()) {
|
|
@@ -57437,16 +57442,17 @@ This is likely an incorrect strategy, either the '${this.type}' entity doesn't n
|
|
|
57437
57442
|
]);
|
|
57438
57443
|
}
|
|
57439
57444
|
toGenerationTarget() {
|
|
57440
|
-
var e, t;
|
|
57445
|
+
var e, t, r;
|
|
57441
57446
|
return {
|
|
57442
57447
|
id: this.id,
|
|
57443
57448
|
type: this.type,
|
|
57444
57449
|
name: this.name,
|
|
57445
57450
|
valueAsTypeSingle: ((e = this.valueAsTypeSingle) == null ? void 0 : e.id) || null,
|
|
57446
|
-
valueAsTypeList: Array.isArray(this.valueAsTypeSingle) ? this.valueAsTypeSingle.map((
|
|
57451
|
+
valueAsTypeList: Array.isArray(this.valueAsTypeSingle) ? this.valueAsTypeSingle.map((s) => s.id) : null,
|
|
57447
57452
|
value: this.value,
|
|
57448
57453
|
autogeneration: this.autogeneration,
|
|
57449
|
-
parent: (t = this.parent) == null ? void 0 : t.id
|
|
57454
|
+
parent: (t = this.parent) == null ? void 0 : t.id,
|
|
57455
|
+
standaloneParent: (r = this.standaloneParent) == null ? void 0 : r.id
|
|
57450
57456
|
};
|
|
57451
57457
|
}
|
|
57452
57458
|
toFlatGenerationTarget(e = /* @__PURE__ */ new Set()) {
|
package/dist/index.umd.cjs
CHANGED
|
@@ -199,7 +199,7 @@ You can update the existing 'literal-value' with the 'update' action, for exampl
|
|
|
199
199
|
}
|
|
200
200
|
}\`\`\`
|
|
201
201
|
Or 'delete' and then 'post' actions to replace it.`,issue:null})):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 'input-map' or 'data-type'.`,issue:null})):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 e.push(new w({id:`${r.id}--${$.InvalidObjectStructure}`,code:$.InvalidObjectStructure,severity:D.Error,message:`Entity of type "${r.type}" with id "${r.id}" is missing a 'parent' reference. The 'parent' of a literal value entity must be a reference to an entity of type 'input-map' or 'data-type'.`,issue:null}));else return e.push(new w({id:`${r.id}--${$.InvalidObjectStructure}`,code:$.InvalidObjectStructure,severity:D.Error,message:`Entity of type "${r.type}" with id "${r.id}" is missing a 'parent' reference. The 'parent' of a literal value entity must be a reference to an entity of type 'input-map' or 'data-type'.`,issue:null})),e;if(r.valueAsTypeSingle){const s=[],d=[],o=r.valueAsTypeSingle;Array.isArray(o)?o.forEach(l=>{typeof l=="string"?d.push(l):s.push(l)}):typeof o=="string"?d.push(o):s.push(o),s.forEach(l=>{const u=xd(l);e.push(...u),u.length===0&&d.push(l.entityId)}),d.forEach(l=>{const u=a.get(l);u?[n.DefinitionEntity,n.BuiltInBaseEntity].includes(u.type)||e.push(new w({id:`${r.id}--${l}--${R.InvalidImplementsReference}`,code:R.InvalidImplementsReference,severity:D.Error,message:`Entity of type "${r.type}" with id "${r.id}", has an 'valueAsTypeSingle' reference that isn't pointing to an entity of type 'definition-entity', 'function-declaration' or 'operation'.`,issue:null})):e.push(new w({id:`${r.id}--${l}--${R.ReferencedEntityNotFound}`,code:R.ReferencedEntityNotFound,severity:D.Error,message:`Entity of type "${r.type}" with id "${r.id}", is referencing an entity with id "${l}" that isn't yet found in the project. Perhaps it should be created first. Or perhaps the ID is incorrect.`,issue:null}))})}return e}var $1=(r=>(r.ValueAsTypeSingle="value-as-type-single",r.ValueAsTypeList="value-as-type-list",r))($1||{});const Le=class Le extends dt{constructor(e,t){super(e);f(this,"initialData");f(this,"type",n.LiteralValue);f(this,"id");f(this,"name");f(this,"autogeneration",null);f(this,"value",null);f(this,"valueAsTypeSingle",null);f(this,"valueAsTypeList",null);f(this,"errors",[]);f(this,"parent");f(this,"standaloneParent");f(this,"project");f(this,"detachedDependents",{});f(this,"knownVersions",null);f(this,"activeVersion",!1);f(this,"initialized",!1);f(this,"startedInitialization",!1);f(this,"standalone",!1);this.initialData=e,this.project=t,this.id=e.id,this.name=e.name,this.autogeneration=e.autogeneration,this.value=e.value}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.LiteralValue,name:"",autogeneration:null,value:null,valueAsTypeSingle:null,valueAsTypeList:null,parent:null}}static fromGenerationTarget(e,t){const i=_(e.parent),s=t.get(i);let d=null,o=null;e.valueAsTypeList?Array.isArray(e.valueAsTypeList)&&(o=e.valueAsTypeList.map(y=>t.get(y)||t.getBuiltIn(y))):e.valueAsTypeSingle&&(d=t.get(e.valueAsTypeSingle)||t.getBuiltIn(e.valueAsTypeSingle));const l={id:e.id,version:m.UUID.uuid(),createdAt:T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.LiteralValue,name:e.name,autogeneration:e.autogeneration,valueAsTypeSingle:d,valueAsTypeList:o,value:e.value||null,parent:s},u=C(l,t);return u.setParent(s,null),u.initChildren(null),u}static validateGenerationTarget(e,t){let i=JSON.parse(JSON.stringify(e));const s=[],d=rS(i,t);return s.push(...d,...pt(i)),{errors:s,modifiedData:i}}get valueAsType(){return this.valueAsTypeSingle?this.valueAsTypeSingle:this.valueAsTypeList?this.valueAsTypeList:null}get isFinal(){var e;return!!(this.parent.type===n.Property&&(this.parent.constant||(e=this.parent.implements)!=null&&e.constant)||this.parent.type===n.Property&&this.parent.parent.type===n.DefinitionEntity&&!Ua(this.parent.parent))}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.
|
|
202
|
-
This is likely an incorrect strategy, either the '${this.type}' entity doesn't need to be updated or it should be deleted and a new one created in the desired parent.`,issue:null})),{errors:t,modifiedData:e}}subscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]||(this.detachedDependents[t.entity.id]=t)}),this}syncDependents(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-dependents"))){const t=[],i=[],s=[],d=[];return Object.values(this.detachedDependents).forEach(o=>{const l=o.entity.afterAllChildrenInitialized(e);t.push(...l.updated),i.push(...l.added),s.push(...l.removed),d.push(...l.affected)}),e==null||e.attemptAutoclose("sync-dependents",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(d),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],d=[],o=[],l=[];return t==="value-as-type-single"&&(this.valueAsTypeSingle=null,i==null||i.add(this,b.Updated)),t==="value-as-type-list"&&(this.valueAsTypeList=(this.valueAsTypeList||[]).filter(u=>u.id!==e.id),i==null||i.add(this,b.Updated)),{updated:p(s),added:p(d),removed:p(o),affected:p(l),self:this}}onDetachedDependencyRestored(e,t,i){const s=[],d=[],o=[],l=[];return t==="value-as-type-single"&&(this.valueAsTypeSingle=e,i==null||i.add(this,b.Updated)),t==="value-as-type-list"&&(this.valueAsTypeList=[...Array.isArray(this.valueAsTypeList||[])?this.valueAsTypeList:[],e],i==null||i.add(this,b.Updated)),{updated:p(s),added:p(d),removed:p(o),affected:p(l),self:this}}subscribeToDependencies(){return!this.valueAsTypeSingle&&!this.valueAsTypeList?this:(this.valueAsTypeList&&Array.isArray(this.valueAsTypeList)?this.valueAsTypeList.forEach(e=>e.subscribeDependents([{entity:this,field:"value-as-type-list"}])):this.valueAsTypeSingle&&this.valueAsTypeSingle.subscribeDependents([{entity:this,field:"value-as-type-single"}]),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 Le(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.valueAsTypeSingle=this.valueAsTypeSingle,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],i=[],s=[],d=[];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(d),self:this}}async restoreVersion(e){var l;const t=[],i=[],s=[],d=[];if(this.version===e)return{updated:p(t),added:p(i),removed:p(s),affected:p(d),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[I,E]of c.knownVersions)u.set(I,E);c.knownVersions=null}}let o=(l=this.knownVersions)==null?void 0:l.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 Le(u,this.project)}return this.metaSync(o.toShallowJSON(),null),this.valueAsTypeSingle=o.valueAsTypeSingle,this.parent=o.parent,{updated:p(t),added:p(i),removed:p(s),affected:p(d),self:this}}hydrateAncestors(){const e=[],t=[],i=[],s=[];if(this.initialData.parent&&this.initialData.standaloneParent)throw new Error(`Entity with id '${this.id}' cannot have both 'parent' and 'standaloneParent' properties set.`);if(this.initialData.parent){const d=_(this.initialData.parent),o=this.project.get(d);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${d}' that isn't found in the project`)}else if(this.initialData.standaloneParent){const d=_(this.initialData.standaloneParent),o=this.project.get(d);if(o)this.setStandaloneParent(o);else throw new Error(`${this.type} with id '${this.id}' has a 'standaloneParent' reference '${d}' that isn't found in the project`)}else throw new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(this.initialData.valueAsTypeList&&Array.isArray(this.initialData.valueAsTypeList))this.valueAsTypeList=this.valueAsTypeList||[],this.initialData.valueAsTypeList.forEach(d=>{const o=_(d),l=this.project.get(o);l&&this.valueAsTypeList.push(l)});else if(this.initialData.valueAsTypeSingle){const d=_(this.initialData.valueAsTypeSingle),o=this.project.get(d);o&&(this.valueAsTypeSingle=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=[],d=[];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(d),self:this}}addSelfToProject(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-self-to-project"))){var o,l;const t=[this],i=[],s=[],d=[];return((o=this.parent)==null?void 0:o.type)===n.DataType?this.parent.setEntity(this):(l=this.parent)==null||l.setDefaultValue(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(d),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}setStandaloneParent(e){return this.standaloneParent=e,this}setValueAsTypeSingle(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"set-value-as-type-single"))){return this.valueAsTypeSingle!==e&&(this.valueAsTypeSingle=e,t==null||t.add(this,b.Updated)),t==null||t.attemptAutoclose("set-value-as-type-single",this.id),this}setValueAsTypeList(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"set-value-as-type-list"))){var i,s;return!e&&this.valueAsTypeList?(this.valueAsTypeList=null,t==null||t.add(this,b.Updated)):e&&!this.valueAsTypeList?(this.valueAsTypeList=e,t==null||t.add(this,b.Updated)):e&&this.valueAsTypeList&&((i=this.valueAsTypeList)==null?void 0:i.length)!==e.length?(this.valueAsTypeList=e,t==null||t.add(this,b.Updated)):e&&this.valueAsTypeList&&((s=this.valueAsTypeList)!=null&&s.every((d,o)=>d!==e[o]))&&(this.valueAsTypeList=e,t==null||t.add(this,b.Updated)),t==null||t.attemptAutoclose("set-value-as-type-list",this.id),this}setValueAsType(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"set-value-as-type"))){return e?(Array.isArray(e)?this.setValueAsTypeList(e,t):this.setValueAsTypeSingle(e,t),t==null||t.attemptAutoclose("set-value-as-type",this.id),this):(this.setValueAsTypeSingle(null,t),this.setValueAsTypeList(null,t),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.standalone){if(this.initialData.valueAsTypeList&&Array.isArray(this.initialData.valueAsTypeList))this.valueAsTypeList=this.initialData.valueAsTypeList.map(t=>{if(t.type===n.GenericReference){const s=this.project.findSubscribedBuiltInInstanceFromReference(t);if(!s)throw new Error(`Standalone entity of type '${this.type}' with id '${this.id}' has a reference to an entity of type '${t.entityType}' with id '${t.entityId}' that is not part of the project state.`);return s}const i=this.project.get(t.id);if(!i)throw new Error(`Standalone entity of type '${this.type}' with id '${this.id}' has a reference to an entity of type '${t.type}' with id '${t.id}' that is not part of the project state.`);return i});else if(this.initialData.valueAsTypeSingle){if(this.initialData.valueAsTypeSingle.type===n.GenericReference){const i=this.project.findSubscribedBuiltInInstanceFromReference(this.initialData.valueAsTypeSingle);if(!i)throw new Error(`Standalone entity of type '${this.type}' with id '${this.id}' has a reference to an entity of type '${this.initialData.valueAsTypeSingle.entityType}' with id '${this.initialData.valueAsTypeSingle.entityId}' that is not part of the project state.`);return this.valueAsTypeSingle=i,this}const t=this.project.get(this.initialData.valueAsTypeSingle.id);if(!t)throw new Error(`Standalone entity of type '${this.type}' with id '${this.id}' has a reference to an entity of type '${this.initialData.valueAsTypeSingle.type}' with id '${this.initialData.valueAsTypeSingle.id}' that is not part of the project state.`);this.valueAsTypeSingle=t}return this}if(this.initialData.valueAsTypeList&&Array.isArray(this.initialData.valueAsTypeList))this.valueAsTypeList=this.initialData.valueAsTypeList.map(t=>{if(t.type===n.GenericReference){const s=this.project.findSubscribedBuiltInInstanceFromReference(t);if(!s)throw new Error(`Standalone entity of type '${this.type}' with id '${this.id}' has a reference to an entity of type '${t.entityType}' with id '${t.entityId}' that is not part of the project state.`);return s}const i=this.project.get(t.id);if(!i)throw new Error(`Standalone entity of type '${this.type}' with id '${this.id}' has a reference to an entity of type '${t.type}' with id '${t.id}' that is not part of the project state.`);return i});else if(this.initialData.valueAsTypeSingle){if(this.initialData.valueAsTypeSingle.type===n.GenericReference){const i=_(this.initialData.valueAsTypeSingle),s=i?this.project.get(i):null;if(!s)throw new Error(`Standalone entity of type '${this.type}' with id '${this.id}' has a reference to an entity of type '${this.initialData.valueAsTypeSingle.entityType}' with id '${this.initialData.valueAsTypeSingle.entityId}' that is not part of the project state.`);return this.valueAsTypeSingle=s,this}const t=this.project.get(this.initialData.valueAsTypeSingle.id);if(!t)throw new Error(`Standalone entity of type '${this.type}' with id '${this.id}' has a reference to an entity of type '${this.initialData.valueAsTypeSingle.type}' with id '${this.initialData.valueAsTypeSingle.id}' that is not part of the project state.`);this.valueAsTypeSingle=t}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.autogeneration=e.autogeneration!==void 0?e.autogeneration:s.autogeneration,this.value=e.value!==void 0?e.value:s.value,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 Le.repository.APILoad(this.id,...t),this}async APICreate(e=U,...t){return await Le.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=U,...t){return await Le.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=U,...t){return await Le.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=U,...t){return await Le.repository.APIClone(this.id,...t),this}async APILoadVersion(e=U,t,...i){return await Le.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=[],d=[],o=[];return t!=null&&t.hasRemoved(this.id)?(t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(s.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(l=>{const{updated:u,removed:y,added:c}=l.entity.onDetachedDependencyRemoved(this,l.field,t);i.push(...u),s.push(...y),d.push(...c)}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:p(d),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=[],d=[];return e!=null&&e.hasAdded(this.id)?(e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),Object.values(this.detachedDependents).forEach(o=>{const{updated:l,removed:u,added:y}=o.entity.onDetachedDependencyRestored(this,o.field,e);i.push(...l),s.push(...u),t.push(...y)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(d),self:this})}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.valueAsTypeSingle?this.valueAsTypeSingle.toFlat(e):[],...this.valueAsTypeList&&Array.isArray(this.valueAsTypeList)?this.valueAsTypeList.flatMap(i=>i.toFlat(e)):[]])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.valueAsTypeSingle?this.valueAsTypeSingle.toFlatIds(e):[],...this.valueAsTypeList&&Array.isArray(this.valueAsTypeList)?this.valueAsTypeList.flatMap(i=>i.toFlatIds(e)):[]])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,value:this.value,autogeneration:this.autogeneration,type:this.type,name:this.name}}toJSON(e=new Set){var t,i;return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,autogeneration:this.autogeneration,value:this.value,valueAsTypeSingle:((t=this.valueAsTypeSingle)==null?void 0:t.toJSON(e))||null,valueAsTypeList:Array.isArray(this.valueAsTypeSingle)?this.valueAsTypeSingle.map(s=>s.toJSON(e)):null,parent:(i=this.parent)==null?void 0:i.toReference()})}toJSONClone(e=J){var i,s,d,o,l,u;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)||(d=e.seenEntities)!=null&&d.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(l=e.seenEntities)==null||l.add(this.id),{id:t,version:m.UUID.uuid(),createdAt:e.timestamp||T().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,name:this.name,autogeneration:this.autogeneration,value:this.value,valueAsTypeSingle:this.valueAsTypeSingle?this.project.getBuiltIn(this.valueAsTypeSingle.id)?this.valueAsTypeSingle.toJSON():this.valueAsTypeSingle.toJSONClone({...e,newId:null}):null,valueAsTypeList:this.valueAsTypeSingle&&Array.isArray(this.valueAsTypeSingle)?this.valueAsTypeSingle.map(y=>this.project.getBuiltIn(y.id)?y.toJSON():y.toJSONClone({...e,newId:null})):null,parent:(u=this.parent)==null?void 0:u.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,d;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,valueAsTypeSingle:((s=this.valueAsTypeSingle)==null?void 0:s.toReference(e))||null,valueAsTypeList:Array.isArray(this.valueAsTypeSingle)?this.valueAsTypeSingle.map(o=>o.toReference(e)):null,value:this.value,autogeneration:this.autogeneration,parent:(d=this.parent)==null?void 0:d.toReference(e)}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.valueAsTypeSingle?this.valueAsTypeSingle.toFlatJSON(e):[],...this.valueAsTypeList&&Array.isArray(this.valueAsTypeList)?this.valueAsTypeList.flatMap(i=>i.toFlatJSON(e)):[]])}toGenerationTarget(){var e,t;return{id:this.id,type:this.type,name:this.name,valueAsTypeSingle:((e=this.valueAsTypeSingle)==null?void 0:e.id)||null,valueAsTypeList:Array.isArray(this.valueAsTypeSingle)?this.valueAsTypeSingle.map(i=>i.id):null,value:this.value,autogeneration:this.autogeneration,parent:(t=this.parent)==null?void 0:t.id}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...this.valueAsTypeSingle?this.valueAsTypeSingle.toFlatGenerationTarget(e):[],...this.valueAsTypeList&&Array.isArray(this.valueAsTypeList)?this.valueAsTypeList.flatMap(i=>i.toFlatGenerationTarget(e)):[]])}clearErrors(){return this.errors=[],this}validate(){const e=U1(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){return[...this.errors]}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){let d=mt(t,this);const o=this.toJSON(),l=i||m.UUID.uuid();o.id=l,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,d);return u.initChildren(e),t&&u.setParent(t,null),e==null||e.add(u,b.Added),s&&u.subscribe(),e==null||e.attemptAutoclose("clone-entity",this.id),u}merge(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"merge-literal-value"))){const i=[],s=[],d=[],o=[];return this.valueAsTypeSingle!==(e==null?void 0:e.valueAsTypeSingle)&&(this.setValueAsType(e.valueAsTypeSingle,t),i.push(this)),this.value!==e.value&&(this.metaSync({value:e.value},t),i.push(this)),this.autogeneration!==e.autogeneration&&(this.metaSync({autogeneration:e.autogeneration},t),i.push(this)),this.name!==e.name&&(this.metaSync({name:e.name},t),i.push(this)),t==null||t.attemptAutoclose("merge-literal-value",this.id),{updated:p(i),added:p(s),removed:p(d),affected:p(o),self:this}}};f(Le,"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(Le,"type",n.LiteralValue),f(Le,"USER_MANAGED_PARENT_TYPES",[n.DataType,n.InputMap,n.Property,n.ArgumentDeclaration,n.ReturnDeclaration,n.VariableDeclaration,n.VariableInstance,n.ValueDescriptor,n.OutputMap]),f(Le,"PARENT_TYPES",[...Le.USER_MANAGED_PARENT_TYPES]),f(Le,"MUTABLE_BASE_PROPERTIES",["name","autogeneration","value"]),f(Le,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),f(Le,"BASE_PROPERTIES",[...Le.MUTABLE_BASE_PROPERTIES,...Le.INMUTABLE_BASE_PROPERTIES]),f(Le,"MUTABLE_META_PROPERTIES",[...Le.MUTABLE_BASE_PROPERTIES]),f(Le,"INMUTABLE_META_PROPERTIES",[...Le.INMUTABLE_BASE_PROPERTIES]),f(Le,"META_PROPERTIES",[...Le.MUTABLE_META_PROPERTIES,...Le.INMUTABLE_META_PROPERTIES]),f(Le,"MUTABLE_UPSTREAM_PROPERTIES",[]),f(Le,"INMUTABLE_UPSTREAM_PROPERTIES",["parent"]),f(Le,"UPSTREAM_PROPERTIES",[...Le.MUTABLE_UPSTREAM_PROPERTIES,...Le.INMUTABLE_UPSTREAM_PROPERTIES]),f(Le,"MUTABLE_DOWNSTREAM_PROPERTIES",["valueAsTypeSingle","valueAsTypeList"]),f(Le,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),f(Le,"DOWNSTREAM_PROPERTIES",[...Le.MUTABLE_DOWNSTREAM_PROPERTIES,...Le.INMUTABLE_DOWNSTREAM_PROPERTIES]),f(Le,"PROPERTIES",[...Le.META_PROPERTIES,...Le.UPSTREAM_PROPERTIES,...Le.DOWNSTREAM_PROPERTIES]);let Qr=Le;function g1(r){var s;const a=S3(),e=r.toJSON();a.safeParse(e).success,(s=r.dataType)==null||s.validate();const i=[];return Ke(r.errors,i)}const nS=Object.freeze(Object.defineProperty({__proto__:null,validate:g1},Symbol.toStringTag,{value:"Module"}));var G1=(r=>(r.DataTypeEntity="data-type-entity",r))(G1||{});const je=class je extends dt{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,"parentRelationType");f(this,"type",n.ValueDescriptor);f(this,"defaultValue",null);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,"codeNativeValueValidation",null);this.initialData=e,this.project=t,this.id=e.id,this.name=e.name,this.description=e.description,this.index=e.index,this.required=e.required,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.ValueDescriptor,name:"",description:"",dataType:null,index:0,required:!1,parentRelationType:N.FixedArguments,defaultValue:null,parent:null}}static fromGenerationTarget(e,t){const i=e.parent?_(e.parent):null,s=i?t.get(i):null,d=e.parentRelationType===N.FixedArguments?s==null?void 0:s.inputs.length:s==null?void 0:s.outputs.length,o={id:e.id,version:m.UUID.uuid(),createdAt:T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,name:e.name,type:n.ValueDescriptor,index:d||0,description:e.description,required:e.required,defaultValue:null,parentRelationType:e.parentRelationType,dataType:null,parent:s},l=C(o,t);return s&&l.setParent(s,null),l.initChildren(null),l}static validateGenerationTarget(e,t){let i=JSON.parse(JSON.stringify(e));const s=[],d=bt(i,{parent:{list:!1,types:[n.ActionDescriptor]}},t);i=d.modifiedData,s.push(...d.errors,...pt(i));const o=i.parent&&t.get(i.parent),l=o&&an(o);return l&&l.type===n.ActionDescriptor&&s.push(new w({id:`${e.id}--${R.BuiltInEntityParent}`,code:R.BuiltInEntityParent,severity:D.Error,message:`Entity of type "${e.type}" with id "${e.id}", has a parent that is a built-in entity "${l.name}" of type '${l.type}' with id '${l.id}'.
|
|
202
|
+
This is likely an incorrect strategy, either the '${this.type}' entity doesn't need to be updated or it should be deleted and a new one created in the desired parent.`,issue:null})),{errors:t,modifiedData:e}}subscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]||(this.detachedDependents[t.entity.id]=t)}),this}syncDependents(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-dependents"))){const t=[],i=[],s=[],d=[];return Object.values(this.detachedDependents).forEach(o=>{const l=o.entity.afterAllChildrenInitialized(e);t.push(...l.updated),i.push(...l.added),s.push(...l.removed),d.push(...l.affected)}),e==null||e.attemptAutoclose("sync-dependents",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(d),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],d=[],o=[],l=[];return t==="value-as-type-single"&&(this.valueAsTypeSingle=null,i==null||i.add(this,b.Updated)),t==="value-as-type-list"&&(this.valueAsTypeList=(this.valueAsTypeList||[]).filter(u=>u.id!==e.id),i==null||i.add(this,b.Updated)),{updated:p(s),added:p(d),removed:p(o),affected:p(l),self:this}}onDetachedDependencyRestored(e,t,i){const s=[],d=[],o=[],l=[];return t==="value-as-type-single"&&(this.valueAsTypeSingle=e,i==null||i.add(this,b.Updated)),t==="value-as-type-list"&&(this.valueAsTypeList=[...Array.isArray(this.valueAsTypeList||[])?this.valueAsTypeList:[],e],i==null||i.add(this,b.Updated)),{updated:p(s),added:p(d),removed:p(o),affected:p(l),self:this}}subscribeToDependencies(){return!this.valueAsTypeSingle&&!this.valueAsTypeList?this:(this.valueAsTypeList&&Array.isArray(this.valueAsTypeList)?this.valueAsTypeList.forEach(e=>e.subscribeDependents([{entity:this,field:"value-as-type-list"}])):this.valueAsTypeSingle&&this.valueAsTypeSingle.subscribeDependents([{entity:this,field:"value-as-type-single"}]),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 Le(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.valueAsTypeSingle=this.valueAsTypeSingle,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],i=[],s=[],d=[];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(d),self:this}}async restoreVersion(e){var l;const t=[],i=[],s=[],d=[];if(this.version===e)return{updated:p(t),added:p(i),removed:p(s),affected:p(d),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[I,E]of c.knownVersions)u.set(I,E);c.knownVersions=null}}let o=(l=this.knownVersions)==null?void 0:l.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 Le(u,this.project)}return this.metaSync(o.toShallowJSON(),null),this.valueAsTypeSingle=o.valueAsTypeSingle,this.parent=o.parent,{updated:p(t),added:p(i),removed:p(s),affected:p(d),self:this}}hydrateAncestors(){const e=[],t=[],i=[],s=[];if(this.initialData.parent&&this.initialData.standaloneParent)throw new Error(`Entity with id '${this.id}' cannot have both 'parent' and 'standaloneParent' properties set.`);if(this.initialData.parent){const d=_(this.initialData.parent),o=this.project.get(d);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${d}' that isn't found in the project`)}else if(this.initialData.standaloneParent){const d=_(this.initialData.standaloneParent),o=this.project.get(d);if(o)this.setStandaloneParent(o);else throw new Error(`${this.type} with id '${this.id}' has a 'standaloneParent' reference '${d}' that isn't found in the project`)}else throw new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(this.initialData.valueAsTypeList&&Array.isArray(this.initialData.valueAsTypeList))this.valueAsTypeList=this.valueAsTypeList||[],this.initialData.valueAsTypeList.forEach(d=>{const o=_(d),l=this.project.get(o);l&&this.valueAsTypeList.push(l)});else if(this.initialData.valueAsTypeSingle){const d=_(this.initialData.valueAsTypeSingle),o=this.project.get(d);o&&(this.valueAsTypeSingle=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=[],d=[];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(d),self:this}}addSelfToProject(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-self-to-project"))){var o,l;const t=[this],i=[],s=[],d=[];return((o=this.parent)==null?void 0:o.type)===n.DataType?this.parent.setEntity(this):(l=this.parent)==null||l.setDefaultValue(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(d),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}setStandaloneParent(e){return this.standaloneParent=e,this}setValueAsTypeSingle(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"set-value-as-type-single"))){return this.valueAsTypeSingle!==e&&(this.valueAsTypeSingle=e,t==null||t.add(this,b.Updated)),t==null||t.attemptAutoclose("set-value-as-type-single",this.id),this}setValueAsTypeList(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"set-value-as-type-list"))){var i,s;return!e&&this.valueAsTypeList?(this.valueAsTypeList=null,t==null||t.add(this,b.Updated)):e&&!this.valueAsTypeList?(this.valueAsTypeList=e,t==null||t.add(this,b.Updated)):e&&this.valueAsTypeList&&((i=this.valueAsTypeList)==null?void 0:i.length)!==e.length?(this.valueAsTypeList=e,t==null||t.add(this,b.Updated)):e&&this.valueAsTypeList&&((s=this.valueAsTypeList)!=null&&s.every((d,o)=>d!==e[o]))&&(this.valueAsTypeList=e,t==null||t.add(this,b.Updated)),t==null||t.attemptAutoclose("set-value-as-type-list",this.id),this}setValueAsType(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"set-value-as-type"))){return e?(Array.isArray(e)?this.setValueAsTypeList(e,t):this.setValueAsTypeSingle(e,t),t==null||t.attemptAutoclose("set-value-as-type",this.id),this):(this.setValueAsTypeSingle(null,t),this.setValueAsTypeList(null,t),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.standalone){if(this.initialData.valueAsTypeList&&Array.isArray(this.initialData.valueAsTypeList))this.valueAsTypeList=this.initialData.valueAsTypeList.map(t=>{if(t.type===n.GenericReference){const s=this.project.findSubscribedBuiltInInstanceFromReference(t);if(!s)throw new Error(`Standalone entity of type '${this.type}' with id '${this.id}' has a reference to an entity of type '${t.entityType}' with id '${t.entityId}' that is not part of the project state.`);return s}const i=this.project.get(t.id);if(!i)throw new Error(`Standalone entity of type '${this.type}' with id '${this.id}' has a reference to an entity of type '${t.type}' with id '${t.id}' that is not part of the project state.`);return i});else if(this.initialData.valueAsTypeSingle){if(this.initialData.valueAsTypeSingle.type===n.GenericReference){const i=this.project.findSubscribedBuiltInInstanceFromReference(this.initialData.valueAsTypeSingle);if(!i)throw new Error(`Standalone entity of type '${this.type}' with id '${this.id}' has a reference to an entity of type '${this.initialData.valueAsTypeSingle.entityType}' with id '${this.initialData.valueAsTypeSingle.entityId}' that is not part of the project state.`);return this.valueAsTypeSingle=i,this}const t=this.project.get(this.initialData.valueAsTypeSingle.id);if(!t)throw new Error(`Standalone entity of type '${this.type}' with id '${this.id}' has a reference to an entity of type '${this.initialData.valueAsTypeSingle.type}' with id '${this.initialData.valueAsTypeSingle.id}' that is not part of the project state.`);this.valueAsTypeSingle=t}return this}if(this.initialData.valueAsTypeList&&Array.isArray(this.initialData.valueAsTypeList))this.valueAsTypeList=this.initialData.valueAsTypeList.map(t=>{if(t.type===n.GenericReference){const s=this.project.findSubscribedBuiltInInstanceFromReference(t);if(!s)throw new Error(`Standalone entity of type '${this.type}' with id '${this.id}' has a reference to an entity of type '${t.entityType}' with id '${t.entityId}' that is not part of the project state.`);return s}const i=this.project.get(t.id);if(!i)throw new Error(`Standalone entity of type '${this.type}' with id '${this.id}' has a reference to an entity of type '${t.type}' with id '${t.id}' that is not part of the project state.`);return i});else if(this.initialData.valueAsTypeSingle){if(this.initialData.valueAsTypeSingle.type===n.GenericReference){const i=_(this.initialData.valueAsTypeSingle),s=i?this.project.get(i):null;if(!s)throw new Error(`Standalone entity of type '${this.type}' with id '${this.id}' has a reference to an entity of type '${this.initialData.valueAsTypeSingle.entityType}' with id '${this.initialData.valueAsTypeSingle.entityId}' that is not part of the project state.`);return this.valueAsTypeSingle=s,this}const t=this.project.get(this.initialData.valueAsTypeSingle.id);if(!t)throw new Error(`Standalone entity of type '${this.type}' with id '${this.id}' has a reference to an entity of type '${this.initialData.valueAsTypeSingle.type}' with id '${this.initialData.valueAsTypeSingle.id}' that is not part of the project state.`);this.valueAsTypeSingle=t}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.autogeneration=e.autogeneration!==void 0?e.autogeneration:s.autogeneration,this.value=e.value!==void 0?e.value:s.value,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 Le.repository.APILoad(this.id,...t),this}async APICreate(e=U,...t){return await Le.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=U,...t){return await Le.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=U,...t){return await Le.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=U,...t){return await Le.repository.APIClone(this.id,...t),this}async APILoadVersion(e=U,t,...i){return await Le.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=[],d=[],o=[];return t!=null&&t.hasRemoved(this.id)?(t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(s.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(l=>{const{updated:u,removed:y,added:c}=l.entity.onDetachedDependencyRemoved(this,l.field,t);i.push(...u),s.push(...y),d.push(...c)}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:p(d),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=[],d=[];return e!=null&&e.hasAdded(this.id)?(e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),Object.values(this.detachedDependents).forEach(o=>{const{updated:l,removed:u,added:y}=o.entity.onDetachedDependencyRestored(this,o.field,e);i.push(...l),s.push(...u),t.push(...y)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(d),self:this})}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.valueAsTypeSingle?this.valueAsTypeSingle.toFlat(e):[],...this.valueAsTypeList&&Array.isArray(this.valueAsTypeList)?this.valueAsTypeList.flatMap(i=>i.toFlat(e)):[]])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.valueAsTypeSingle?this.valueAsTypeSingle.toFlatIds(e):[],...this.valueAsTypeList&&Array.isArray(this.valueAsTypeList)?this.valueAsTypeList.flatMap(i=>i.toFlatIds(e)):[]])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,value:this.value,autogeneration:this.autogeneration,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,autogeneration:this.autogeneration,value:this.value,valueAsTypeSingle:((t=this.valueAsTypeSingle)==null?void 0:t.toJSON(e))||null,valueAsTypeList:Array.isArray(this.valueAsTypeSingle)?this.valueAsTypeSingle.map(d=>d.toJSON(e)):null,parent:(i=this.parent)==null?void 0:i.toReference(),standaloneParent:(s=this.standaloneParent)==null?void 0:s.toReference()})}toJSONClone(e=J){var i,s,d,o,l,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)||(d=e.seenEntities)!=null&&d.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(l=e.seenEntities)==null||l.add(this.id),{id:t,version:m.UUID.uuid(),createdAt:e.timestamp||T().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,name:this.name,autogeneration:this.autogeneration,value:this.value,valueAsTypeSingle:this.valueAsTypeSingle?this.project.getBuiltIn(this.valueAsTypeSingle.id)?this.valueAsTypeSingle.toJSON():this.valueAsTypeSingle.toJSONClone({...e,newId:null}):null,valueAsTypeList:this.valueAsTypeSingle&&Array.isArray(this.valueAsTypeSingle)?this.valueAsTypeSingle.map(c=>this.project.getBuiltIn(c.id)?c.toJSON():c.toJSONClone({...e,newId:null})):null,parent:(u=this.parent)==null?void 0:u.toReference({seenEntityMaps:e.seenEntityMaps}),standaloneParent:(y=this.standaloneParent)==null?void 0:y.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,d,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,valueAsTypeSingle:((s=this.valueAsTypeSingle)==null?void 0:s.toReference(e))||null,valueAsTypeList:Array.isArray(this.valueAsTypeSingle)?this.valueAsTypeSingle.map(l=>l.toReference(e)):null,value:this.value,autogeneration:this.autogeneration,parent:(d=this.parent)==null?void 0:d.toReference(e),standaloneParent:(o=this.standaloneParent)==null?void 0:o.toReference(e)}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.valueAsTypeSingle?this.valueAsTypeSingle.toFlatJSON(e):[],...this.valueAsTypeList&&Array.isArray(this.valueAsTypeList)?this.valueAsTypeList.flatMap(i=>i.toFlatJSON(e)):[]])}toGenerationTarget(){var e,t,i;return{id:this.id,type:this.type,name:this.name,valueAsTypeSingle:((e=this.valueAsTypeSingle)==null?void 0:e.id)||null,valueAsTypeList:Array.isArray(this.valueAsTypeSingle)?this.valueAsTypeSingle.map(s=>s.id):null,value:this.value,autogeneration:this.autogeneration,parent:(t=this.parent)==null?void 0:t.id,standaloneParent:(i=this.standaloneParent)==null?void 0:i.id}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...this.valueAsTypeSingle?this.valueAsTypeSingle.toFlatGenerationTarget(e):[],...this.valueAsTypeList&&Array.isArray(this.valueAsTypeList)?this.valueAsTypeList.flatMap(i=>i.toFlatGenerationTarget(e)):[]])}clearErrors(){return this.errors=[],this}validate(){const e=U1(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){return[...this.errors]}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){let d=mt(t,this);const o=this.toJSON(),l=i||m.UUID.uuid();o.id=l,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,d);return u.initChildren(e),t&&u.setParent(t,null),e==null||e.add(u,b.Added),s&&u.subscribe(),e==null||e.attemptAutoclose("clone-entity",this.id),u}merge(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"merge-literal-value"))){const i=[],s=[],d=[],o=[];return this.valueAsTypeSingle!==(e==null?void 0:e.valueAsTypeSingle)&&(this.setValueAsType(e.valueAsTypeSingle,t),i.push(this)),this.value!==e.value&&(this.metaSync({value:e.value},t),i.push(this)),this.autogeneration!==e.autogeneration&&(this.metaSync({autogeneration:e.autogeneration},t),i.push(this)),this.name!==e.name&&(this.metaSync({name:e.name},t),i.push(this)),t==null||t.attemptAutoclose("merge-literal-value",this.id),{updated:p(i),added:p(s),removed:p(d),affected:p(o),self:this}}};f(Le,"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(Le,"type",n.LiteralValue),f(Le,"USER_MANAGED_PARENT_TYPES",[n.DataType,n.InputMap,n.Property,n.ArgumentDeclaration,n.ReturnDeclaration,n.VariableDeclaration,n.VariableInstance,n.ValueDescriptor,n.OutputMap]),f(Le,"PARENT_TYPES",[...Le.USER_MANAGED_PARENT_TYPES]),f(Le,"MUTABLE_BASE_PROPERTIES",["name","autogeneration","value"]),f(Le,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),f(Le,"BASE_PROPERTIES",[...Le.MUTABLE_BASE_PROPERTIES,...Le.INMUTABLE_BASE_PROPERTIES]),f(Le,"MUTABLE_META_PROPERTIES",[...Le.MUTABLE_BASE_PROPERTIES]),f(Le,"INMUTABLE_META_PROPERTIES",[...Le.INMUTABLE_BASE_PROPERTIES]),f(Le,"META_PROPERTIES",[...Le.MUTABLE_META_PROPERTIES,...Le.INMUTABLE_META_PROPERTIES]),f(Le,"MUTABLE_UPSTREAM_PROPERTIES",[]),f(Le,"INMUTABLE_UPSTREAM_PROPERTIES",["parent"]),f(Le,"UPSTREAM_PROPERTIES",[...Le.MUTABLE_UPSTREAM_PROPERTIES,...Le.INMUTABLE_UPSTREAM_PROPERTIES]),f(Le,"MUTABLE_DOWNSTREAM_PROPERTIES",["valueAsTypeSingle","valueAsTypeList"]),f(Le,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),f(Le,"DOWNSTREAM_PROPERTIES",[...Le.MUTABLE_DOWNSTREAM_PROPERTIES,...Le.INMUTABLE_DOWNSTREAM_PROPERTIES]),f(Le,"PROPERTIES",[...Le.META_PROPERTIES,...Le.UPSTREAM_PROPERTIES,...Le.DOWNSTREAM_PROPERTIES]);let Qr=Le;function g1(r){var s;const a=S3(),e=r.toJSON();a.safeParse(e).success,(s=r.dataType)==null||s.validate();const i=[];return Ke(r.errors,i)}const nS=Object.freeze(Object.defineProperty({__proto__:null,validate:g1},Symbol.toStringTag,{value:"Module"}));var G1=(r=>(r.DataTypeEntity="data-type-entity",r))(G1||{});const je=class je extends dt{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,"parentRelationType");f(this,"type",n.ValueDescriptor);f(this,"defaultValue",null);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,"codeNativeValueValidation",null);this.initialData=e,this.project=t,this.id=e.id,this.name=e.name,this.description=e.description,this.index=e.index,this.required=e.required,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.ValueDescriptor,name:"",description:"",dataType:null,index:0,required:!1,parentRelationType:N.FixedArguments,defaultValue:null,parent:null}}static fromGenerationTarget(e,t){const i=e.parent?_(e.parent):null,s=i?t.get(i):null,d=e.parentRelationType===N.FixedArguments?s==null?void 0:s.inputs.length:s==null?void 0:s.outputs.length,o={id:e.id,version:m.UUID.uuid(),createdAt:T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,name:e.name,type:n.ValueDescriptor,index:d||0,description:e.description,required:e.required,defaultValue:null,parentRelationType:e.parentRelationType,dataType:null,parent:s},l=C(o,t);return s&&l.setParent(s,null),l.initChildren(null),l}static validateGenerationTarget(e,t){let i=JSON.parse(JSON.stringify(e));const s=[],d=bt(i,{parent:{list:!1,types:[n.ActionDescriptor]}},t);i=d.modifiedData,s.push(...d.errors,...pt(i));const o=i.parent&&t.get(i.parent),l=o&&an(o);return l&&l.type===n.ActionDescriptor&&s.push(new w({id:`${e.id}--${R.BuiltInEntityParent}`,code:R.BuiltInEntityParent,severity:D.Error,message:`Entity of type "${e.type}" with id "${e.id}", has a parent that is a built-in entity "${l.name}" of type '${l.type}' with id '${l.id}'.
|
|
203
203
|
You can't modify system entities that are built-in.`,issue:null})),o&&o.type===n.ActionDescriptor&&(!i.parentRelationType||!(i.parentRelationType===N.FixedArguments||i.parentRelationType===N.FixedReturns||i.parentRelationType===N.ReturnedError||i.parentRelationType===N.DynamicArgument||i.parentRelationType===N.DynamicReturn)?s.push(new w({id:`${e.id}--${R.InvalidParentRelationType}`,code:R.InvalidParentRelationType,severity:D.Error,message:`The entity with id '${e.id}' and type '${e.type}', must have a 'parentRelationType' property set to either '${N.FixedArguments}', '${N.FixedReturns}', or '${N.ReturnedError}' when being added as a child to an entity of type 'action-descriptor'.`,issue:null})):i.parentRelationType===N.ReturnedError&&o.error&&s.push(new w({id:`${e.id}--${R.NewEntityWouldOverriteExisting}`,code:R.NewEntityWouldOverriteExisting,severity:D.Error,message:`The entity with id '${e.id}' and type '${e.type}', is being added as an error value-descriptor to an entity of type 'action-descriptor' with id '${o.id}', which already has an error value descriptor with id '${o.error.id}'.
|
|
204
204
|
An action descriptor can only have one error value descriptor child.
|
|
205
205
|
Either remove the existing error value descriptor or update it with the 'update' action.
|
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.6231",
|
|
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",
|