@elyx-code/project-logic-tree 0.0.6184 → 0.0.6185
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js
CHANGED
|
@@ -34015,59 +34015,77 @@ Please consider that any updates might affect the overlap with the signature of
|
|
|
34015
34015
|
return this.inputs.find((t) => t.id === e) || null;
|
|
34016
34016
|
}
|
|
34017
34017
|
// Creates a call enitity for this function declaration
|
|
34018
|
-
createCall(e = this.project
|
|
34019
|
-
|
|
34020
|
-
|
|
34021
|
-
|
|
34022
|
-
|
|
34023
|
-
|
|
34024
|
-
|
|
34025
|
-
|
|
34018
|
+
createCall(e = this.project.addChangeSet(
|
|
34019
|
+
new A(
|
|
34020
|
+
this.project,
|
|
34021
|
+
"",
|
|
34022
|
+
v().toISOString(),
|
|
34023
|
+
this,
|
|
34024
|
+
!0,
|
|
34025
|
+
"create-call"
|
|
34026
|
+
)
|
|
34027
|
+
), t = this.project, r = {}) {
|
|
34028
|
+
const s = {
|
|
34029
|
+
id: r.id || I.UUID.uuid(),
|
|
34030
|
+
version: r.version || I.UUID.uuid(),
|
|
34031
|
+
createdAt: r.createdAt || v().toISOString(),
|
|
34032
|
+
author: r.author || "1",
|
|
34033
|
+
previousVersion: r.previousVersion || null,
|
|
34034
|
+
deleted: r.deleted || !1,
|
|
34026
34035
|
type: n.FunctionCall,
|
|
34027
|
-
parent:
|
|
34028
|
-
successCalls:
|
|
34029
|
-
errorCalls:
|
|
34030
|
-
inputs:
|
|
34031
|
-
outputs:
|
|
34032
|
-
error:
|
|
34033
|
-
process:
|
|
34034
|
-
calledBySuccess:
|
|
34035
|
-
calledByError:
|
|
34036
|
-
calledByEntry:
|
|
34036
|
+
parent: t.toReference(),
|
|
34037
|
+
successCalls: r.successCalls || [],
|
|
34038
|
+
errorCalls: r.errorCalls || [],
|
|
34039
|
+
inputs: r.inputs || [],
|
|
34040
|
+
outputs: r.outputs || [],
|
|
34041
|
+
error: r.error || null,
|
|
34042
|
+
process: r.process || null,
|
|
34043
|
+
calledBySuccess: r.calledBySuccess || [],
|
|
34044
|
+
calledByError: r.calledByError || [],
|
|
34045
|
+
calledByEntry: r.calledByEntry || [],
|
|
34037
34046
|
declaration: this.toJSON(),
|
|
34038
34047
|
x: 0,
|
|
34039
34048
|
y: 0
|
|
34040
|
-
},
|
|
34041
|
-
|
|
34049
|
+
}, d = O(
|
|
34050
|
+
s,
|
|
34042
34051
|
this.project
|
|
34043
34052
|
);
|
|
34044
|
-
return
|
|
34053
|
+
return d.setParent(t, e), d.initChildren(e), e == null || e.add(d, b.Added), d.hydrateAncestors(), d.afterAllChildrenInitialized(e), t === this.project && this.project.addFunctionCall(d), e == null || e.attemptAutoclose("create-call", this.id), d;
|
|
34045
34054
|
}
|
|
34046
34055
|
// Creates a call enitity for this function declaration
|
|
34047
|
-
createInternalCall(e
|
|
34048
|
-
|
|
34049
|
-
|
|
34050
|
-
|
|
34056
|
+
createInternalCall(e = this.project.addChangeSet(
|
|
34057
|
+
new A(
|
|
34058
|
+
this.project,
|
|
34059
|
+
"",
|
|
34060
|
+
v().toISOString(),
|
|
34061
|
+
this,
|
|
34062
|
+
!0,
|
|
34063
|
+
"create-internal"
|
|
34064
|
+
)
|
|
34065
|
+
), t, r = {}) {
|
|
34066
|
+
const s = {
|
|
34067
|
+
id: r.id || I.UUID.uuid(),
|
|
34068
|
+
version: r.version || I.UUID.uuid(),
|
|
34051
34069
|
type: n.InternalCall,
|
|
34052
|
-
parent:
|
|
34053
|
-
successCalls:
|
|
34054
|
-
deleted:
|
|
34055
|
-
errorCalls:
|
|
34056
|
-
inputs:
|
|
34057
|
-
outputs:
|
|
34058
|
-
error:
|
|
34059
|
-
process:
|
|
34060
|
-
calledBySuccess:
|
|
34061
|
-
calledByError:
|
|
34062
|
-
calledByEntry:
|
|
34070
|
+
parent: t.toReference(),
|
|
34071
|
+
successCalls: r.successCalls || [],
|
|
34072
|
+
deleted: r.deleted || !1,
|
|
34073
|
+
errorCalls: r.errorCalls || [],
|
|
34074
|
+
inputs: r.inputs || [],
|
|
34075
|
+
outputs: r.outputs || [],
|
|
34076
|
+
error: r.error || null,
|
|
34077
|
+
process: r.process || null,
|
|
34078
|
+
calledBySuccess: r.calledBySuccess || [],
|
|
34079
|
+
calledByError: r.calledByError || [],
|
|
34080
|
+
calledByEntry: r.calledByEntry || [],
|
|
34063
34081
|
// @ts-ignore This is because using the correct 'toJSON' method would recursively call the same method in other entities. Which during load, might not yet be available
|
|
34064
34082
|
declaration: this.toShallowJSON(),
|
|
34065
|
-
index:
|
|
34066
|
-
},
|
|
34067
|
-
|
|
34083
|
+
index: t.internalCalls.length
|
|
34084
|
+
}, d = O(
|
|
34085
|
+
s,
|
|
34068
34086
|
this.project
|
|
34069
34087
|
);
|
|
34070
|
-
return
|
|
34088
|
+
return d.setParent(t, e), d.initChildren(e), e == null || e.add(d, b.Added), d.hydrateAncestors(), d.afterAllChildrenInitialized(e), e == null || e.attemptAutoclose("create-internal", this.id), d;
|
|
34071
34089
|
}
|
|
34072
34090
|
addReturnStatement(e) {
|
|
34073
34091
|
return this.returnStatements.includes(e) || this.returnStatements.push(e), this;
|
|
@@ -45358,7 +45376,7 @@ You shouldn't have to manually update a 'parent' property. The equivalent result
|
|
|
45358
45376
|
var T, D, w, V, L;
|
|
45359
45377
|
return (((T = c.declaration) == null ? void 0 : T.id) || ((w = (D = c.initialData) == null ? void 0 : D.declaration) == null ? void 0 : w.entityId) || ((L = (V = c.initialData) == null ? void 0 : V.declaration) == null ? void 0 : L.id)) === u.id;
|
|
45360
45378
|
})).map((u) => {
|
|
45361
|
-
const y = u.createInternalCall(this);
|
|
45379
|
+
const y = u.createInternalCall(e, this);
|
|
45362
45380
|
return e == null || e.add(y, b.Added), y.suggestion = !0, this.addInternalCall(y), y;
|
|
45363
45381
|
});
|
|
45364
45382
|
else
|
|
@@ -47139,7 +47157,7 @@ You shouldn't have to manually update a 'parent' property. The equivalent result
|
|
|
47139
47157
|
var T, D, w, V, L;
|
|
47140
47158
|
return (((T = c.declaration) == null ? void 0 : T.id) || ((w = (D = c.initialData) == null ? void 0 : D.declaration) == null ? void 0 : w.entityId) || ((L = (V = c.initialData) == null ? void 0 : V.declaration) == null ? void 0 : L.id)) === u.id;
|
|
47141
47159
|
})).map((u) => {
|
|
47142
|
-
const y = u.createInternalCall(this);
|
|
47160
|
+
const y = u.createInternalCall(e, this);
|
|
47143
47161
|
return e == null || e.add(y, b.Added), y.suggestion = !0, this.addInternalCall(y), y;
|
|
47144
47162
|
});
|
|
47145
47163
|
else
|
package/dist/index.umd.cjs
CHANGED
|
@@ -67,7 +67,7 @@ If you want to implement a new method, you can create a new 'function-declaratio
|
|
|
67
67
|
If you want to modify the existing implementation, you can update the existing method instead, but it will have to match the same base ${n.ActionDescriptor} signature, otherwise the implementation will have a validation error.`,issue:null}))}}else if(l&&l.type===n.Loop){const v=l.body;v&&((c=v.implements)==null?void 0:c.id)===r.implements&&a.push(new P({id:`${r.id}--${j.MethodOverwrite}`,code:j.MethodOverwrite,severity:D.Error,message:`The '${n.FunctionDeclaration}' with id "${r.id}" is being added as the 'body' of the ${n.Loop} with id "${l.id}", but the loop already has a function-declaration body. A loop can only have one function-declaration body at a time. You can edit the existing body instead, but it will have to match the same base signature, otherwise the implementation will have a validation error.`,issue:null}))}const u=r.parent&&t.get(r.parent)||t.getBuiltIn(r.parent),h=u?zi(u):null;return h&&a.push(new P({id:`${e.id}--${A.BuiltInEntityParent}`,code:A.BuiltInEntityParent,severity:D.Error,message:`The entity with id '${e.id}' and type '${e.type}', belongs to a built-in system entity "${F(h,t)}" with id '${h.id}', and therefore it cannot be created as it would affect a built in entity, which are inmutable.`,issue:null})),a.push(...d.errors,...o,...ot(r)),{errors:a,modifiedData:r}}get returnStatements(){const e=[];return Object.values(this.detachedDependents).forEach(t=>{t.field===_d.Parent&&t.entity.type===n.ReturnStatement&&!e.includes(t.entity)&&e.push(t.entity)}),e}validateGeneratedUpdate(e){const t=[];return e.parent&&(this.parent.type===n.Project?t.push(new P({id:`${this.id}--${A.InvalidParentUpdate}`,code:A.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.
|
|
68
68
|
This is likely an incorrect strategy because this is a globally declared '${this.type}' entity which can only have the root project as its parent.`,issue:null})):t.push(new P({id:`${this.id}--${A.InvalidParentUpdate}`,code:A.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.
|
|
69
69
|
This is likely an incorrect strategy because this function declaration is a method, since it belongs to a '${this.parent.type}' entity, either the '${this.type}' entity doesn't need to be updated or it should be deleted and a new one created in the desired parent.
|
|
70
|
-
Please consider that any updates might affect the overlap with the signature of the parent entity's action descriptors.`,issue:null}))),{errors:t,modifiedData:e}}subscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]||(this.detachedDependents[t.entity.id]=t)}),this}syncDependents(){const e=[],t=[],r=[],a=[];return Object.values(this.detachedDependents).forEach(d=>{const o=d.entity.afterAllChildrenInitialized();e.push(...o.updated),t.push(...o.added),r.push(...o.removed),a.push(...o.affected)}),{updated:p(e),added:p(t),removed:p(r),affected:p(a),self:this}}onDetachedDependencyRemoved(e,t,r){const a=[],d=[],o=[],l=[];return t==="implements"&&this.setImplements(null,r),{updated:p(a),added:p(d),removed:p(o),affected:p(l),self:this}}onDetachedDependencyRestored(e,t,r){const a=[],d=[],o=[],l=[];return t==="implements"&&(this.setImplements(e,r),a.push(e)),{updated:p(a),added:p(d),removed:p(o),affected:p(l),self:this}}subscribeToDependencies(){var e;return(e=this.implements)==null||e.subscribeDependents([{entity:this,field:"implements"}]),this}increaseVersion(e){if(e&&!T(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&T(e).isSame(T(this.createdAt))?this:(this.previousVersion=this.version,this.version=I.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t,r;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new be(this,this.project);return(r=this.knownVersions)==null||r.set(this.version,e),e.inputs=this.inputs,e.calls=this.calls,e.implements=this.implements,e.detachedChildren=this.detachedChildren,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],r=[],a=[],d=[];if(this.parent&&this.parent.type!==n.PrimitiveEntity&&this.parent.type!==n.BuiltInBaseEntity){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),r.push(...o.added),a.push(...o.removed)}return{updated:p(t),added:p(r),removed:p(a),affected:p(d),self:this}}async restoreVersion(e){var l;const t=[],r=[],a=[],d=[];if(this.version===e)return{updated:p(t),added:p(r),removed:p(a),affected:p(d),self:this};if(!this.knownVersions){const u=new Map;for(const[h,c]of this.knownVersions||new Map){if(u.set(h,c),c.activeVersion=!1,c.knownVersions)for(const[v,E]of c.knownVersions)u.set(v,E);c.knownVersions=null}}let o=(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 be(u,this.project)}return this.metaSync(o.toShallowJSON(),null),this.inputs=o.inputs,this.calls=o.calls,this.implements=o.implements,this.detachedChildren=o.detachedChildren,this.parent=o.parent,{updated:p(t),added:p(r),removed:p(a),affected:p(d),self:this}}hydrateAncestors(){const e=[],t=[],r=[],a=[];if(this.initialData.parent){const d=B(this.initialData.parent),o=this.project.get(d);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${Wt(this.type)} with id '${this.id}' has a 'parent' reference "${d}" which is missing in the project`)}else throw new Error(`${Wt(this.type)} with id '${this.id}' is missing a 'parent' reference`);if(this.initialData.implements){const d=B(this.initialData.implements),o=this.project.get(d);if(o)this.setImplements(o,null),e.push(o);else if(d)throw new Error(`${Wt(this.type)} with id '${this.id}' has a 'implements' reference "${d}" which is missing in the project`)}return{updated:p(e),added:p(t),removed:p(r),affected:p(a),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new R(this.project,"",T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],r=[],a=[],d=[];return this.initialized=!0,this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:p(t),added:p(r),removed:p(a),affected:p(d),self:this}}addSelfToProject(e=this.project.addChangeSet(new R(this.project,"",T().toISOString(),this,!0,"add-self-to-project"))){const t=[this],r=[],a=[],d=[];return this.parent===this.project?this.project.addFunctionDeclaration(this):this.parent.type===n.DefinitionEntity?(this.parent.addMethod(this),t.push(this.parent)):this.parent.type===n.Loop&&(this.parent.setBody(this),t.push(this.parent)),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:p(t),added:p(r),removed:p(a),affected:p(d),self:this}}replaceDetachedChild(e,t){const r=this.detachedChildren.indexOf(e);return r!==-1&&(this.detachedChildren[r]=t),this}subscribeDetachedChild(e){return this.detachedChildren.includes(e)||this.detachedChildren.push(e),this}addInputDeclaration(e,t=this.project.addChangeSet(new R(this.project,"",T().toISOString(),this,!0,"add-input-declaration"))){return this.inputs.includes(e)?(t==null||t.attemptAutoclose("add-input-declaration",this.id),this):(this.inputs.push(e),t==null||t.attemptAutoclose("add-input-declaration",this.id),this)}removeInputDeclaration(e){const t=this.inputs.indexOf(e);return t!==-1&&this.inputs.splice(t,1),this}setParent(e,t=this.project.addChangeSet(new R(this.project,"",T().toISOString(),this,!0,"set-parent"))){var r;return((r=this.parent)==null?void 0:r.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,b.Updated),t==null||t.attemptAutoclose("set-parent",this.id))),this}setImplements(e,t=this.project.addChangeSet(new R(this.project,"",T().toISOString(),this,!0,"set-implements"))){var r;return((r=this.implements)==null?void 0:r.id)!==(e==null?void 0:e.id)&&(this.implements=e,t&&(t==null||t.add(this,b.Updated),t==null||t.attemptAutoclose("set-implements",this.id))),this}addCall(e){return this.calls.includes(e)||this.calls.push(e),this}removeCall(e){const t=this.calls.indexOf(e);return t!==-1&&this.calls.splice(t,1),this}initChildren(e=this.project.addChangeSet(new R(this.project,"",T().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.inputs=this.initialData.inputs.map(t=>{const r=V(t,this.project);return r.setParent(this,null),r.initChildren(e),r}),this.calls=this.initialData.calls.map(t=>{const r=V(t,this.project);return r.addEntryCaller(this,null),[n.BreakStatement,n.ContinueStatement].includes(r.type)?(r.setParent(this.parent,null),r.initChildren(e)):r.type!==n.InternalCall&&(r.setParent(this,null),r.initChildren(e)),r}),this.initialData.implements&&(this.implements=V(this.initialData.implements,this.project)),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this)}subscribe(){return this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new R(this.project,"",T().toISOString(),this,!0,"sync-meta"))){const r=dt(this,e);return e.deleted===!0&&!this.deleted?t==null||t.add(this,b.Removed):e.deleted===!1&&this.deleted?t==null||t.add(this,b.Added):r&&(t==null||t.add(this,b.Updated)),super.metaSync(e),this.name=e.name||this.name,this.description=e.description||this.description,this.private=e.private||this.private,this.index=e.index||(e.index!==0?this.index:0),this.collapsed=e.collapsed!==void 0?e.collapsed:this.collapsed,this.x=e.x||this.x,this.y=e.y||this.y,t==null||t.attemptAutoclose("sync-meta",this.id),this}async APILoad(e=L,...t){return await be.repository.APILoad(this.id,...t),this}async APICreate(e=L,...t){return await be.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=L,...t){return await be.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=L,...t){return await be.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=L,...t){return await be.repository.APIClone(this.id,...t),this}async APILoadVersion(e=L,t,...r){return await be.repository.APILoadVersion(this.id,t,...r)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new R(this.project,"",T().toISOString(),this,!0,"remove-entity"))){const r=[],a=[],d=[],o=[];return t!=null&&t.hasRemoved(this.id)?(t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(a.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(u=>{const{updated:h,removed:c,added:v}=u.entity.onDetachedDependencyRemoved(this,u.field,t);r.push(...h),a.push(...c),d.push(...v)}),this.inputs.forEach(u=>{const{updated:h,removed:c}=u.remove({ignoreUpstream:!0},t);r.push(...h),a.push(...c)}),ir(this).forEach(u=>{const{updated:h,removed:c}=u.remove({ignoreUpstream:!0},t);r.push(...h),a.push(...c)}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:p(d),updated:p(r),removed:p(a),affected:p(o),self:this})}restore({}={},e=this.project.addChangeSet(new R(this.project,"",T().toISOString(),this,!0,"restore-entity"))){const t=[],r=[],a=[],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),this.inputs.forEach(l=>{const{updated:u}=l.restore({},e);r.push(...u)}),ir(this).forEach(l=>{const{updated:u}=l.restore({},e);r.push(...u)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:p(t),updated:p(r),removed:p(a),affected:p(d),self:this})}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.inputs.flatMap(r=>r.toFlat(e)),...this.calls.flatMap(r=>r.toFlat(e)),...this.returnStatements.flatMap(r=>r.toFlat(e)),...this.implements?this.implements.toFlat(e):[]])}toFlatIds(e=new Set){if(e.has(this.id))return[];e.add(this.id);const t=ir(this);return[this.id,...this.inputs.flatMap(a=>a.toFlatIds(e)),...this.calls.flatMap(a=>a.toFlatIds(e)),...this.returnStatements.flatMap(a=>a.toFlatIds(e)),...this.implements?this.implements.toFlatIds(e):[],...t.flatMap(a=>a.toFlatIds(e))]}toJSON(e=new Set){var t;return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,index:this.index,x:this.x,y:this.y,collapsed:this.collapsed,private:this.private,calls:this.calls.map(r=>r.toJSON(e)),inputs:this.inputs.map(r=>r.toJSON(e)),implements:((t=this.implements)==null?void 0:t.toJSON(e))||null,parent:this.parent.toReference()})}toJSONClone(e=Z){var r,a,d,o,l;let t;return(r=e.seenEntityMaps)!=null&&r.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||ct(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(a=e.seenEntities)!=null&&a.has(t)||(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:I.UUID.uuid(),createdAt:e.timestamp||T().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,index:this.index,x:this.x,y:this.y,collapsed:this.collapsed,private:this.private,calls:this.calls.map(u=>u.toJSONClone({...e,newId:null})),inputs:this.inputs.map(u=>u.toJSONClone({...e,newId:null})),implements:(()=>{var u;return this.implements&&this.project.getBuiltIn(this.implements.id)?this.implements.toJSON():(u=this.implements)==null?void 0:u.toJSONClone({...e,newId:null})})(),parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps})})}toReference(e=Z){var r;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+I.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=Z){var r,a;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,index:this.index,collapsed:this.collapsed,private:this.private,x:this.x,y:this.y,inputs:this.inputs.map(d=>d.toReference(e)),calls:this.calls.map(d=>d.toReference(e)),implements:((a=this.implements)==null?void 0:a.toReference(e))||null,parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.inputs.flatMap(r=>r.toFlatJSON(e)),...this.calls.flatMap(r=>r.toFlatJSON(e)),...this.returnStatements.flatMap(r=>r.toFlatJSON(e)),...this.implements?this.implements.toFlatJSON(e):[]])}toGenerationTarget(){var t;const e=this.parent.type===n.Project?void 0:this.parent.id;return{id:this.id,name:this.name,description:this.description,type:this.type,private:this.private,implements:((t=this.implements)==null?void 0:t.id)||null,parent:e}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...this.inputs.flatMap(r=>r.toFlatGenerationTarget(e)),...this.calls.flatMap(r=>r.toFlatGenerationTarget(e)),...this.returnStatements.flatMap(r=>r.toFlatGenerationTarget(e))])}clearErrors(){return this.errors=[],this.inputs.forEach(e=>e.clearErrors()),this.calls.forEach(e=>e.clearErrors()),this.returnStatements.forEach(e=>e.clearErrors()),this}validate(){const e=z7(this);return this.errors=[...e],{success:!0,error:null,data:this.toJSON()}}getErrors(){const e=ir(this);return[...this.errors,...this.inputs.flatMap(r=>r.getErrors()),...e.flatMap(r=>r.getErrors())]}getShallowErrors(){return this.errors}clone(e=this.project.addChangeSet(new R(this.project,"",T().toISOString(),this,!0,"clone-entity")),t=null,r=null,a=!0,d=!1){var w;let o=ft(t,this);const l=this.toJSON(),u=r||I.UUID.uuid();l.inputs=[],l.calls=[];const h=u.split("-id"),c=h[h.length-1||0]||u;l.id=u,l.version=I.UUID.uuid(),l.createdAt=(e==null?void 0:e.timestamp)||T().toISOString(),l.author=(e==null?void 0:e.author)||"1",l.previousVersion=null,l.deleted=!1;const v=lt(l,o);t?v.setParent(t,null):v.setParent(this.parent,null),a&&v.subscribe(),v.initChildren(e),e==null||e.add(v,b.Added);const E=(w=this.inputs)==null?void 0:w.map((C,U)=>C.clone(e,v,c+"-argument-declaration-"+U+"-id",a));return v.inputs=E,d?(ir(this).map((C,U)=>C.clone(e,v,c+"-body-entity-"+U+"-id")),e==null||e.attemptAutoclose("clone-entity",this.id),v):(e==null||e.attemptAutoclose("clone-entity",this.id),v)}getVariableInstances(){return We(this).filter(r=>r.type===n.VariableInstance)}getArgument(e){return this.inputs.find(t=>t.id===e)||null}createCall(e=this.project,t={}){const r={id:t.id||I.UUID.uuid(),version:t.version||I.UUID.uuid(),createdAt:t.createdAt||T().toISOString(),author:t.author||"1",previousVersion:t.previousVersion||null,deleted:t.deleted||!1,type:n.FunctionCall,parent:e.toReference(),successCalls:t.successCalls||[],errorCalls:t.errorCalls||[],inputs:t.inputs||[],outputs:t.outputs||[],error:t.error||null,process:t.process||null,calledBySuccess:t.calledBySuccess||[],calledByError:t.calledByError||[],calledByEntry:t.calledByEntry||[],declaration:this.toJSON(),x:0,y:0},a=V(r,this.project);return a.setParent(e,null),a.initChildren(null),e===this.project&&this.project.addFunctionCall(a),a}createInternalCall(e,t={}){const r={id:t.id||I.UUID.uuid(),version:t.version||I.UUID.uuid(),type:n.InternalCall,parent:e.toReference(),successCalls:t.successCalls||[],deleted:t.deleted||!1,errorCalls:t.errorCalls||[],inputs:t.inputs||[],outputs:t.outputs||[],error:t.error||null,process:t.process||null,calledBySuccess:t.calledBySuccess||[],calledByError:t.calledByError||[],calledByEntry:t.calledByEntry||[],declaration:this.toShallowJSON(),index:e.internalCalls.length},a=V(r,this.project);return a.setParent(e,null),a.initChildren(null),a}addReturnStatement(e){return this.returnStatements.includes(e)||this.returnStatements.push(e),this}removeReturnStatement(e){const t=this.returnStatements.indexOf(e);return t!==-1&&this.returnStatements.splice(t,1),this}getUniqueReturnDeclarations(){const e=[],r=[...this.returnStatements].flatMap(a=>a.outputs);if(this.implements){const a=this.implements.outputs;return r.forEach(d=>{const o=a.find(u=>u===d.implements),l=e.find(u=>u.implements===d.implements);o&&!l&&e.push(d)}),p(e)}else return r.forEach(a=>{e.find(o=>o===a||F(o,this.project)===F(a,this.project)&&Ir(o.dataType,a.dataType))||e.push(a)}),p(e)}};f(be,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>e,APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...r)=>null}),f(be,"type",n.FunctionDeclaration),f(be,"USER_MANAGED_PARENT_TYPES",[n.Project,n.InstalledProject,n.DefinitionEntity,n.Loop]),f(be,"PARENT_TYPES",[...be.USER_MANAGED_PARENT_TYPES,n.BuiltInBaseEntity,n.PrimitiveEntity]),f(be,"MUTABLE_BASE_PROPERTIES",["name","description","private"]),f(be,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),f(be,"BASE_PROPERTIES",[...be.MUTABLE_BASE_PROPERTIES,...be.INMUTABLE_BASE_PROPERTIES]),f(be,"MUTABLE_META_PROPERTIES",[...be.MUTABLE_BASE_PROPERTIES,"x","y","index","collapsed"]),f(be,"INMUTABLE_META_PROPERTIES",[...be.INMUTABLE_BASE_PROPERTIES]),f(be,"META_PROPERTIES",[...be.MUTABLE_META_PROPERTIES,...be.INMUTABLE_META_PROPERTIES]),f(be,"MUTABLE_UPSTREAM_PROPERTIES",[]),f(be,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","implements"]),f(be,"UPSTREAM_PROPERTIES",[...be.MUTABLE_UPSTREAM_PROPERTIES,...be.INMUTABLE_UPSTREAM_PROPERTIES]),f(be,"MUTABLE_DOWNSTREAM_PROPERTIES",["inputs","calls","returnStatements"]),f(be,"INMUATABLE_DOWNSTREAM_PROPERTIES",[]),f(be,"DOWNSTREAM_PROPERTIES",[...be.MUTABLE_DOWNSTREAM_PROPERTIES,...be.INMUATABLE_DOWNSTREAM_PROPERTIES]),f(be,"PROPERTIES",[...be.META_PROPERTIES,...be.UPSTREAM_PROPERTIES,...be.DOWNSTREAM_PROPERTIES]);let Mi=be;function K7(i){const s=B3(),e=i.toJSON();s.safeParse(e).success;const r=[];if(i.entity&&i.andChildrenGroup||i.entity&&i.orChildrenGroup||i.andChildrenGroup&&i.orChildrenGroup){const a=ye({id:i.id+"--"+q.InvalidPropertiesCombination,message:`Data type with id "${i.id}" has invalid properties combination. Only one of the following properties can be present at the time: 'entity', 'andChildrenGroup' or 'orChildrenGroup'`,issue:null,severity:D.Error,code:q.InvalidPropertiesCombination,entity:i});r.push(a.error)}return ze(i.errors,r)}function X7(i,s){const e=[],t=[n.DefinitionEntity,n.ActionDescriptor,n.Property,n.ArgumentDeclaration,n.ReturnDeclaration,n.VariableDeclaration,n.ValueDescriptor,n.DataType],r=`'${ie(t,"', '","' or '")}'`;if(i.parent)if(i.id===i.parent)e.push(new P({id:`${i.id}--${i.parent}--${A.SelfReference}`,code:A.SelfReference,severity:D.Error,message:`Entity of type "${i.type}" with id "${i.id}", has a reference to itself at 'parent'. This is not allowed. Change the reference string or the 'entityId' property of the reference object.`,issue:null}));else{const a=s.get(i.parent);a?t.includes(a.type)||e.push(new P({id:`${i.id}--${i.parent}--${A.InvalidParentReference}`,code:A.InvalidParentReference,severity:D.Error,message:`Entity of type "${i.type}" with id "${i.id}", has a parent reference that isn't pointing to an entity of type ${r}.`,issue:null})):e.push(new P({id:`${i.id}--${i.parent}--${A.ReferencedEntityNotFound}`,code:A.ReferencedEntityNotFound,severity:D.Error,message:`Entity of type "${i.type}" with id "${i.id}", is referencing an entity with id "${i.parent}" that isn't yet found in the project. Perhaps it should be created first. Or perhaps the ID is incorrect.`,issue:null}))}else e.push(new P({id:`${i.id}--${j.InvalidObjectStructure}`,code:j.InvalidObjectStructure,severity:D.Error,message:`Entity of type "${i.type}" with id "${i.id}" is missing a 'parent' reference. The 'parent' of a 'data-type' entity must be a reference to an entity of type ${r}.`,issue:null}));if(i.entity){if(i.id===i.entity)return e.push(new P({id:`${i.id}--${i.entity}--${A.SelfReference}`,code:A.SelfReference,severity:D.Error,message:`Entity of type "${i.type}" with id "${i.id}", has a reference to itself at 'entity'. This is not allowed. Change the reference string or the 'entityId' property of the reference object.`,issue:null})),e;const a=s.get(i.entity);a?[n.DefinitionEntity,n.PrimitiveEntity,n.ActionDescriptor,n.BuiltInBaseEntity].includes(a.type)||e.push(new P({id:`${i.id}--${i.entity}--${A.InvalidImplementsReference}`,code:A.InvalidImplementsReference,severity:D.Error,message:`Entity of type "${i.type}" with id "${i.id}", has an 'entity' reference that isn't pointing to an entity of type 'definition-entity', 'primitive-entity', 'action-descriptor' or 'built-in-base-entity'.`,issue:null})):e.push(new P({id:`${i.id}--${i.entity}--${A.ReferencedEntityNotFound}`,code:A.ReferencedEntityNotFound,severity:D.Error,message:`Entity of type "${i.type}" with id "${i.id}", is referencing an entity with id "${i.entity}" that isn't yet found in the project. Perhaps it should be created first. Or perhaps the ID is incorrect.`,issue:null}))}return e}var Y1=(i=>(i.Entity="entity",i))(Y1||{});const Re=class Re extends rt{constructor(e,t){super(e);f(this,"initialData");f(this,"id");f(this,"isList",null);f(this,"asType",null);f(this,"type",n.DataType);f(this,"options");f(this,"parentRelationType");f(this,"like");f(this,"implementationChooseOne",!1);f(this,"inferred",!1);f(this,"entity",null);f(this,"andChildrenGroup",null);f(this,"orChildrenGroup",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);this.initialData=e,this.project=t,this.id=e.id,this.isList=e.isList,this.asType=e.asType,this.options=e.options,this.parentRelationType=e.parentRelationType,this.inferred=e.inferred||!1,this.like=e.like||!1,this.implementationChooseOne=e.implementationChooseOne||!1}static fromGenerationTarget(e,t){const r=B(e.parent),a=t.get(r);let d=null;e.entity&&(d=t.get(e.entity));const o={id:e.id,version:I.UUID.uuid(),createdAt:T().toISOString(),author:I.sessionAuthor,previousVersion:null,deleted:!1,type:n.DataType,andChildrenGroup:null,orChildrenGroup:null,parentRelationType:e.parentRelationType,isList:e.isList,like:e.like||!1,inferred:!1,implementationChooseOne:e.implementationChooseOne||!1,entity:d,asType:e.asType,parent:a},l=V(o,t);return l.setParent(a,null),l.initChildren(null),l}static validateGenerationTarget(e,t){var u;let r=JSON.parse(JSON.stringify(e));const a=[],d=X7(r,t);if(a.push(...d,...ot(r)),r.entity){const h=t.get(r.entity);if(h.type===n.DefinitionEntity){const v=Wi(h).filter(E=>!E.interactive);if(v.length){const E=v.length>1?`entities with ids '${ie(v.map(O=>O.id),"', '","' and '")}'`:`entity with id '${v[0].id}'`;a.push(new P({id:`${e.id}--${A.NonInteractiveEntityReferenced}`,code:A.NonInteractiveEntityReferenced,severity:D.Error,message:`The entity with id '${e.id}' and type '${e.type}', cannot reference 'definition-entity' with id '${r.entity}' at 'entity'. The entity extends or implements non-interactive built-in-base-entity ${E}.
|
|
70
|
+
Please consider that any updates might affect the overlap with the signature of the parent entity's action descriptors.`,issue:null}))),{errors:t,modifiedData:e}}subscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]||(this.detachedDependents[t.entity.id]=t)}),this}syncDependents(){const e=[],t=[],r=[],a=[];return Object.values(this.detachedDependents).forEach(d=>{const o=d.entity.afterAllChildrenInitialized();e.push(...o.updated),t.push(...o.added),r.push(...o.removed),a.push(...o.affected)}),{updated:p(e),added:p(t),removed:p(r),affected:p(a),self:this}}onDetachedDependencyRemoved(e,t,r){const a=[],d=[],o=[],l=[];return t==="implements"&&this.setImplements(null,r),{updated:p(a),added:p(d),removed:p(o),affected:p(l),self:this}}onDetachedDependencyRestored(e,t,r){const a=[],d=[],o=[],l=[];return t==="implements"&&(this.setImplements(e,r),a.push(e)),{updated:p(a),added:p(d),removed:p(o),affected:p(l),self:this}}subscribeToDependencies(){var e;return(e=this.implements)==null||e.subscribeDependents([{entity:this,field:"implements"}]),this}increaseVersion(e){if(e&&!T(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&T(e).isSame(T(this.createdAt))?this:(this.previousVersion=this.version,this.version=I.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t,r;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new be(this,this.project);return(r=this.knownVersions)==null||r.set(this.version,e),e.inputs=this.inputs,e.calls=this.calls,e.implements=this.implements,e.detachedChildren=this.detachedChildren,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],r=[],a=[],d=[];if(this.parent&&this.parent.type!==n.PrimitiveEntity&&this.parent.type!==n.BuiltInBaseEntity){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),r.push(...o.added),a.push(...o.removed)}return{updated:p(t),added:p(r),removed:p(a),affected:p(d),self:this}}async restoreVersion(e){var l;const t=[],r=[],a=[],d=[];if(this.version===e)return{updated:p(t),added:p(r),removed:p(a),affected:p(d),self:this};if(!this.knownVersions){const u=new Map;for(const[h,c]of this.knownVersions||new Map){if(u.set(h,c),c.activeVersion=!1,c.knownVersions)for(const[v,E]of c.knownVersions)u.set(v,E);c.knownVersions=null}}let o=(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 be(u,this.project)}return this.metaSync(o.toShallowJSON(),null),this.inputs=o.inputs,this.calls=o.calls,this.implements=o.implements,this.detachedChildren=o.detachedChildren,this.parent=o.parent,{updated:p(t),added:p(r),removed:p(a),affected:p(d),self:this}}hydrateAncestors(){const e=[],t=[],r=[],a=[];if(this.initialData.parent){const d=B(this.initialData.parent),o=this.project.get(d);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${Wt(this.type)} with id '${this.id}' has a 'parent' reference "${d}" which is missing in the project`)}else throw new Error(`${Wt(this.type)} with id '${this.id}' is missing a 'parent' reference`);if(this.initialData.implements){const d=B(this.initialData.implements),o=this.project.get(d);if(o)this.setImplements(o,null),e.push(o);else if(d)throw new Error(`${Wt(this.type)} with id '${this.id}' has a 'implements' reference "${d}" which is missing in the project`)}return{updated:p(e),added:p(t),removed:p(r),affected:p(a),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new R(this.project,"",T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],r=[],a=[],d=[];return this.initialized=!0,this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:p(t),added:p(r),removed:p(a),affected:p(d),self:this}}addSelfToProject(e=this.project.addChangeSet(new R(this.project,"",T().toISOString(),this,!0,"add-self-to-project"))){const t=[this],r=[],a=[],d=[];return this.parent===this.project?this.project.addFunctionDeclaration(this):this.parent.type===n.DefinitionEntity?(this.parent.addMethod(this),t.push(this.parent)):this.parent.type===n.Loop&&(this.parent.setBody(this),t.push(this.parent)),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:p(t),added:p(r),removed:p(a),affected:p(d),self:this}}replaceDetachedChild(e,t){const r=this.detachedChildren.indexOf(e);return r!==-1&&(this.detachedChildren[r]=t),this}subscribeDetachedChild(e){return this.detachedChildren.includes(e)||this.detachedChildren.push(e),this}addInputDeclaration(e,t=this.project.addChangeSet(new R(this.project,"",T().toISOString(),this,!0,"add-input-declaration"))){return this.inputs.includes(e)?(t==null||t.attemptAutoclose("add-input-declaration",this.id),this):(this.inputs.push(e),t==null||t.attemptAutoclose("add-input-declaration",this.id),this)}removeInputDeclaration(e){const t=this.inputs.indexOf(e);return t!==-1&&this.inputs.splice(t,1),this}setParent(e,t=this.project.addChangeSet(new R(this.project,"",T().toISOString(),this,!0,"set-parent"))){var r;return((r=this.parent)==null?void 0:r.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,b.Updated),t==null||t.attemptAutoclose("set-parent",this.id))),this}setImplements(e,t=this.project.addChangeSet(new R(this.project,"",T().toISOString(),this,!0,"set-implements"))){var r;return((r=this.implements)==null?void 0:r.id)!==(e==null?void 0:e.id)&&(this.implements=e,t&&(t==null||t.add(this,b.Updated),t==null||t.attemptAutoclose("set-implements",this.id))),this}addCall(e){return this.calls.includes(e)||this.calls.push(e),this}removeCall(e){const t=this.calls.indexOf(e);return t!==-1&&this.calls.splice(t,1),this}initChildren(e=this.project.addChangeSet(new R(this.project,"",T().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.inputs=this.initialData.inputs.map(t=>{const r=V(t,this.project);return r.setParent(this,null),r.initChildren(e),r}),this.calls=this.initialData.calls.map(t=>{const r=V(t,this.project);return r.addEntryCaller(this,null),[n.BreakStatement,n.ContinueStatement].includes(r.type)?(r.setParent(this.parent,null),r.initChildren(e)):r.type!==n.InternalCall&&(r.setParent(this,null),r.initChildren(e)),r}),this.initialData.implements&&(this.implements=V(this.initialData.implements,this.project)),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this)}subscribe(){return this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new R(this.project,"",T().toISOString(),this,!0,"sync-meta"))){const r=dt(this,e);return e.deleted===!0&&!this.deleted?t==null||t.add(this,b.Removed):e.deleted===!1&&this.deleted?t==null||t.add(this,b.Added):r&&(t==null||t.add(this,b.Updated)),super.metaSync(e),this.name=e.name||this.name,this.description=e.description||this.description,this.private=e.private||this.private,this.index=e.index||(e.index!==0?this.index:0),this.collapsed=e.collapsed!==void 0?e.collapsed:this.collapsed,this.x=e.x||this.x,this.y=e.y||this.y,t==null||t.attemptAutoclose("sync-meta",this.id),this}async APILoad(e=L,...t){return await be.repository.APILoad(this.id,...t),this}async APICreate(e=L,...t){return await be.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=L,...t){return await be.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=L,...t){return await be.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=L,...t){return await be.repository.APIClone(this.id,...t),this}async APILoadVersion(e=L,t,...r){return await be.repository.APILoadVersion(this.id,t,...r)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new R(this.project,"",T().toISOString(),this,!0,"remove-entity"))){const r=[],a=[],d=[],o=[];return t!=null&&t.hasRemoved(this.id)?(t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(a.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(u=>{const{updated:h,removed:c,added:v}=u.entity.onDetachedDependencyRemoved(this,u.field,t);r.push(...h),a.push(...c),d.push(...v)}),this.inputs.forEach(u=>{const{updated:h,removed:c}=u.remove({ignoreUpstream:!0},t);r.push(...h),a.push(...c)}),ir(this).forEach(u=>{const{updated:h,removed:c}=u.remove({ignoreUpstream:!0},t);r.push(...h),a.push(...c)}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:p(d),updated:p(r),removed:p(a),affected:p(o),self:this})}restore({}={},e=this.project.addChangeSet(new R(this.project,"",T().toISOString(),this,!0,"restore-entity"))){const t=[],r=[],a=[],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),this.inputs.forEach(l=>{const{updated:u}=l.restore({},e);r.push(...u)}),ir(this).forEach(l=>{const{updated:u}=l.restore({},e);r.push(...u)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:p(t),updated:p(r),removed:p(a),affected:p(d),self:this})}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.inputs.flatMap(r=>r.toFlat(e)),...this.calls.flatMap(r=>r.toFlat(e)),...this.returnStatements.flatMap(r=>r.toFlat(e)),...this.implements?this.implements.toFlat(e):[]])}toFlatIds(e=new Set){if(e.has(this.id))return[];e.add(this.id);const t=ir(this);return[this.id,...this.inputs.flatMap(a=>a.toFlatIds(e)),...this.calls.flatMap(a=>a.toFlatIds(e)),...this.returnStatements.flatMap(a=>a.toFlatIds(e)),...this.implements?this.implements.toFlatIds(e):[],...t.flatMap(a=>a.toFlatIds(e))]}toJSON(e=new Set){var t;return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,index:this.index,x:this.x,y:this.y,collapsed:this.collapsed,private:this.private,calls:this.calls.map(r=>r.toJSON(e)),inputs:this.inputs.map(r=>r.toJSON(e)),implements:((t=this.implements)==null?void 0:t.toJSON(e))||null,parent:this.parent.toReference()})}toJSONClone(e=Z){var r,a,d,o,l;let t;return(r=e.seenEntityMaps)!=null&&r.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||ct(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(a=e.seenEntities)!=null&&a.has(t)||(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:I.UUID.uuid(),createdAt:e.timestamp||T().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,index:this.index,x:this.x,y:this.y,collapsed:this.collapsed,private:this.private,calls:this.calls.map(u=>u.toJSONClone({...e,newId:null})),inputs:this.inputs.map(u=>u.toJSONClone({...e,newId:null})),implements:(()=>{var u;return this.implements&&this.project.getBuiltIn(this.implements.id)?this.implements.toJSON():(u=this.implements)==null?void 0:u.toJSONClone({...e,newId:null})})(),parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps})})}toReference(e=Z){var r;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+I.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=Z){var r,a;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,index:this.index,collapsed:this.collapsed,private:this.private,x:this.x,y:this.y,inputs:this.inputs.map(d=>d.toReference(e)),calls:this.calls.map(d=>d.toReference(e)),implements:((a=this.implements)==null?void 0:a.toReference(e))||null,parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.inputs.flatMap(r=>r.toFlatJSON(e)),...this.calls.flatMap(r=>r.toFlatJSON(e)),...this.returnStatements.flatMap(r=>r.toFlatJSON(e)),...this.implements?this.implements.toFlatJSON(e):[]])}toGenerationTarget(){var t;const e=this.parent.type===n.Project?void 0:this.parent.id;return{id:this.id,name:this.name,description:this.description,type:this.type,private:this.private,implements:((t=this.implements)==null?void 0:t.id)||null,parent:e}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...this.inputs.flatMap(r=>r.toFlatGenerationTarget(e)),...this.calls.flatMap(r=>r.toFlatGenerationTarget(e)),...this.returnStatements.flatMap(r=>r.toFlatGenerationTarget(e))])}clearErrors(){return this.errors=[],this.inputs.forEach(e=>e.clearErrors()),this.calls.forEach(e=>e.clearErrors()),this.returnStatements.forEach(e=>e.clearErrors()),this}validate(){const e=z7(this);return this.errors=[...e],{success:!0,error:null,data:this.toJSON()}}getErrors(){const e=ir(this);return[...this.errors,...this.inputs.flatMap(r=>r.getErrors()),...e.flatMap(r=>r.getErrors())]}getShallowErrors(){return this.errors}clone(e=this.project.addChangeSet(new R(this.project,"",T().toISOString(),this,!0,"clone-entity")),t=null,r=null,a=!0,d=!1){var w;let o=ft(t,this);const l=this.toJSON(),u=r||I.UUID.uuid();l.inputs=[],l.calls=[];const h=u.split("-id"),c=h[h.length-1||0]||u;l.id=u,l.version=I.UUID.uuid(),l.createdAt=(e==null?void 0:e.timestamp)||T().toISOString(),l.author=(e==null?void 0:e.author)||"1",l.previousVersion=null,l.deleted=!1;const v=lt(l,o);t?v.setParent(t,null):v.setParent(this.parent,null),a&&v.subscribe(),v.initChildren(e),e==null||e.add(v,b.Added);const E=(w=this.inputs)==null?void 0:w.map((C,U)=>C.clone(e,v,c+"-argument-declaration-"+U+"-id",a));return v.inputs=E,d?(ir(this).map((C,U)=>C.clone(e,v,c+"-body-entity-"+U+"-id")),e==null||e.attemptAutoclose("clone-entity",this.id),v):(e==null||e.attemptAutoclose("clone-entity",this.id),v)}getVariableInstances(){return We(this).filter(r=>r.type===n.VariableInstance)}getArgument(e){return this.inputs.find(t=>t.id===e)||null}createCall(e=this.project.addChangeSet(new R(this.project,"",T().toISOString(),this,!0,"create-call")),t=this.project,r={}){const a={id:r.id||I.UUID.uuid(),version:r.version||I.UUID.uuid(),createdAt:r.createdAt||T().toISOString(),author:r.author||"1",previousVersion:r.previousVersion||null,deleted:r.deleted||!1,type:n.FunctionCall,parent:t.toReference(),successCalls:r.successCalls||[],errorCalls:r.errorCalls||[],inputs:r.inputs||[],outputs:r.outputs||[],error:r.error||null,process:r.process||null,calledBySuccess:r.calledBySuccess||[],calledByError:r.calledByError||[],calledByEntry:r.calledByEntry||[],declaration:this.toJSON(),x:0,y:0},d=V(a,this.project);return d.setParent(t,e),d.initChildren(e),e==null||e.add(d,b.Added),d.hydrateAncestors(),d.afterAllChildrenInitialized(e),t===this.project&&this.project.addFunctionCall(d),e==null||e.attemptAutoclose("create-call",this.id),d}createInternalCall(e=this.project.addChangeSet(new R(this.project,"",T().toISOString(),this,!0,"create-internal")),t,r={}){const a={id:r.id||I.UUID.uuid(),version:r.version||I.UUID.uuid(),type:n.InternalCall,parent:t.toReference(),successCalls:r.successCalls||[],deleted:r.deleted||!1,errorCalls:r.errorCalls||[],inputs:r.inputs||[],outputs:r.outputs||[],error:r.error||null,process:r.process||null,calledBySuccess:r.calledBySuccess||[],calledByError:r.calledByError||[],calledByEntry:r.calledByEntry||[],declaration:this.toShallowJSON(),index:t.internalCalls.length},d=V(a,this.project);return d.setParent(t,e),d.initChildren(e),e==null||e.add(d,b.Added),d.hydrateAncestors(),d.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("create-internal",this.id),d}addReturnStatement(e){return this.returnStatements.includes(e)||this.returnStatements.push(e),this}removeReturnStatement(e){const t=this.returnStatements.indexOf(e);return t!==-1&&this.returnStatements.splice(t,1),this}getUniqueReturnDeclarations(){const e=[],r=[...this.returnStatements].flatMap(a=>a.outputs);if(this.implements){const a=this.implements.outputs;return r.forEach(d=>{const o=a.find(u=>u===d.implements),l=e.find(u=>u.implements===d.implements);o&&!l&&e.push(d)}),p(e)}else return r.forEach(a=>{e.find(o=>o===a||F(o,this.project)===F(a,this.project)&&Ir(o.dataType,a.dataType))||e.push(a)}),p(e)}};f(be,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>e,APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...r)=>null}),f(be,"type",n.FunctionDeclaration),f(be,"USER_MANAGED_PARENT_TYPES",[n.Project,n.InstalledProject,n.DefinitionEntity,n.Loop]),f(be,"PARENT_TYPES",[...be.USER_MANAGED_PARENT_TYPES,n.BuiltInBaseEntity,n.PrimitiveEntity]),f(be,"MUTABLE_BASE_PROPERTIES",["name","description","private"]),f(be,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),f(be,"BASE_PROPERTIES",[...be.MUTABLE_BASE_PROPERTIES,...be.INMUTABLE_BASE_PROPERTIES]),f(be,"MUTABLE_META_PROPERTIES",[...be.MUTABLE_BASE_PROPERTIES,"x","y","index","collapsed"]),f(be,"INMUTABLE_META_PROPERTIES",[...be.INMUTABLE_BASE_PROPERTIES]),f(be,"META_PROPERTIES",[...be.MUTABLE_META_PROPERTIES,...be.INMUTABLE_META_PROPERTIES]),f(be,"MUTABLE_UPSTREAM_PROPERTIES",[]),f(be,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","implements"]),f(be,"UPSTREAM_PROPERTIES",[...be.MUTABLE_UPSTREAM_PROPERTIES,...be.INMUTABLE_UPSTREAM_PROPERTIES]),f(be,"MUTABLE_DOWNSTREAM_PROPERTIES",["inputs","calls","returnStatements"]),f(be,"INMUATABLE_DOWNSTREAM_PROPERTIES",[]),f(be,"DOWNSTREAM_PROPERTIES",[...be.MUTABLE_DOWNSTREAM_PROPERTIES,...be.INMUATABLE_DOWNSTREAM_PROPERTIES]),f(be,"PROPERTIES",[...be.META_PROPERTIES,...be.UPSTREAM_PROPERTIES,...be.DOWNSTREAM_PROPERTIES]);let Mi=be;function K7(i){const s=B3(),e=i.toJSON();s.safeParse(e).success;const r=[];if(i.entity&&i.andChildrenGroup||i.entity&&i.orChildrenGroup||i.andChildrenGroup&&i.orChildrenGroup){const a=ye({id:i.id+"--"+q.InvalidPropertiesCombination,message:`Data type with id "${i.id}" has invalid properties combination. Only one of the following properties can be present at the time: 'entity', 'andChildrenGroup' or 'orChildrenGroup'`,issue:null,severity:D.Error,code:q.InvalidPropertiesCombination,entity:i});r.push(a.error)}return ze(i.errors,r)}function X7(i,s){const e=[],t=[n.DefinitionEntity,n.ActionDescriptor,n.Property,n.ArgumentDeclaration,n.ReturnDeclaration,n.VariableDeclaration,n.ValueDescriptor,n.DataType],r=`'${ie(t,"', '","' or '")}'`;if(i.parent)if(i.id===i.parent)e.push(new P({id:`${i.id}--${i.parent}--${A.SelfReference}`,code:A.SelfReference,severity:D.Error,message:`Entity of type "${i.type}" with id "${i.id}", has a reference to itself at 'parent'. This is not allowed. Change the reference string or the 'entityId' property of the reference object.`,issue:null}));else{const a=s.get(i.parent);a?t.includes(a.type)||e.push(new P({id:`${i.id}--${i.parent}--${A.InvalidParentReference}`,code:A.InvalidParentReference,severity:D.Error,message:`Entity of type "${i.type}" with id "${i.id}", has a parent reference that isn't pointing to an entity of type ${r}.`,issue:null})):e.push(new P({id:`${i.id}--${i.parent}--${A.ReferencedEntityNotFound}`,code:A.ReferencedEntityNotFound,severity:D.Error,message:`Entity of type "${i.type}" with id "${i.id}", is referencing an entity with id "${i.parent}" that isn't yet found in the project. Perhaps it should be created first. Or perhaps the ID is incorrect.`,issue:null}))}else e.push(new P({id:`${i.id}--${j.InvalidObjectStructure}`,code:j.InvalidObjectStructure,severity:D.Error,message:`Entity of type "${i.type}" with id "${i.id}" is missing a 'parent' reference. The 'parent' of a 'data-type' entity must be a reference to an entity of type ${r}.`,issue:null}));if(i.entity){if(i.id===i.entity)return e.push(new P({id:`${i.id}--${i.entity}--${A.SelfReference}`,code:A.SelfReference,severity:D.Error,message:`Entity of type "${i.type}" with id "${i.id}", has a reference to itself at 'entity'. This is not allowed. Change the reference string or the 'entityId' property of the reference object.`,issue:null})),e;const a=s.get(i.entity);a?[n.DefinitionEntity,n.PrimitiveEntity,n.ActionDescriptor,n.BuiltInBaseEntity].includes(a.type)||e.push(new P({id:`${i.id}--${i.entity}--${A.InvalidImplementsReference}`,code:A.InvalidImplementsReference,severity:D.Error,message:`Entity of type "${i.type}" with id "${i.id}", has an 'entity' reference that isn't pointing to an entity of type 'definition-entity', 'primitive-entity', 'action-descriptor' or 'built-in-base-entity'.`,issue:null})):e.push(new P({id:`${i.id}--${i.entity}--${A.ReferencedEntityNotFound}`,code:A.ReferencedEntityNotFound,severity:D.Error,message:`Entity of type "${i.type}" with id "${i.id}", is referencing an entity with id "${i.entity}" that isn't yet found in the project. Perhaps it should be created first. Or perhaps the ID is incorrect.`,issue:null}))}return e}var Y1=(i=>(i.Entity="entity",i))(Y1||{});const Re=class Re extends rt{constructor(e,t){super(e);f(this,"initialData");f(this,"id");f(this,"isList",null);f(this,"asType",null);f(this,"type",n.DataType);f(this,"options");f(this,"parentRelationType");f(this,"like");f(this,"implementationChooseOne",!1);f(this,"inferred",!1);f(this,"entity",null);f(this,"andChildrenGroup",null);f(this,"orChildrenGroup",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);this.initialData=e,this.project=t,this.id=e.id,this.isList=e.isList,this.asType=e.asType,this.options=e.options,this.parentRelationType=e.parentRelationType,this.inferred=e.inferred||!1,this.like=e.like||!1,this.implementationChooseOne=e.implementationChooseOne||!1}static fromGenerationTarget(e,t){const r=B(e.parent),a=t.get(r);let d=null;e.entity&&(d=t.get(e.entity));const o={id:e.id,version:I.UUID.uuid(),createdAt:T().toISOString(),author:I.sessionAuthor,previousVersion:null,deleted:!1,type:n.DataType,andChildrenGroup:null,orChildrenGroup:null,parentRelationType:e.parentRelationType,isList:e.isList,like:e.like||!1,inferred:!1,implementationChooseOne:e.implementationChooseOne||!1,entity:d,asType:e.asType,parent:a},l=V(o,t);return l.setParent(a,null),l.initChildren(null),l}static validateGenerationTarget(e,t){var u;let r=JSON.parse(JSON.stringify(e));const a=[],d=X7(r,t);if(a.push(...d,...ot(r)),r.entity){const h=t.get(r.entity);if(h.type===n.DefinitionEntity){const v=Wi(h).filter(E=>!E.interactive);if(v.length){const E=v.length>1?`entities with ids '${ie(v.map(O=>O.id),"', '","' and '")}'`:`entity with id '${v[0].id}'`;a.push(new P({id:`${e.id}--${A.NonInteractiveEntityReferenced}`,code:A.NonInteractiveEntityReferenced,severity:D.Error,message:`The entity with id '${e.id}' and type '${e.type}', cannot reference 'definition-entity' with id '${r.entity}' at 'entity'. The entity extends or implements non-interactive built-in-base-entity ${E}.
|
|
71
71
|
${Zi}`,issue:null}))}}}const o=r.parent&&t.get(r.parent)||t.getBuiltIn(r.parent),l=o?zi(o):null;if(l)a.push(new P({id:`${e.id}--${A.BuiltInEntityParent}`,code:A.BuiltInEntityParent,severity:D.Error,message:`The entity with id '${e.id}' and type '${e.type}', belongs to a built-in system entity "${F(l,t)}" with id '${l.id}', and therefore it cannot be created as it would affect a built in entity, which are inmutable.`,issue:null}));else if(o){const h=o.type,c=[n.Property,n.VariableDeclaration,n.ArgumentDeclaration,n.ReturnDeclaration,n.ValueDescriptor];if(c.includes(h)&&(r.parentRelationType&&a.push(new P({id:`${e.id}--${A.InvalidParentRelationType}`,code:A.InvalidParentRelationType,severity:D.Error,message:`The entity with id '${e.id}' and type '${e.type}', cannot have a 'parentRelationType' property set of type '${h}'.
|
|
72
72
|
The entitities of type '${ie(c,"', '","' and '")}' can only have one 'data-type' child under the 'dataType' property so no 'parentRelationType' is needed.`,issue:null})),o.dataType)){const v=(u=o.dataType)==null?void 0:u.id;a.push(new P({id:`${e.id}--${A.NewEntityWouldOverriteExisting}`,code:A.NewEntityWouldOverriteExisting,severity:D.Error,message:`The entity with id '${e.id}' and type '${e.type}', cannot be added as a child to the entity with id '${r.parent}' and type '${h}', because it already has a 'data-type' child with id '${v}'.
|
|
73
73
|
The entitities of type '${ie(c,"', '","' and '")}' can only have one 'data-type' child under the 'dataType' property. You can inspect the existing data-type entity with the 'describe_entity' action. Like so:
|
|
@@ -103,10 +103,10 @@ ${Gd(t)}`,issue:null})),{errors:a,modifiedData:r}}validateGeneratedUpdate(e){con
|
|
|
103
103
|
If an entity is called by another, they must be in the same scope, which means they have the same parent.`,issue:null})),{errors:t,modifiedData:e}}subscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]||(this.detachedDependents[t.entity.id]=t)}),this}syncDependents(){const e=[],t=[],r=[],a=[];return Object.values(this.detachedDependents).forEach(d=>{const o=d.entity.afterAllChildrenInitialized();e.push(...o.updated),t.push(...o.added),r.push(...o.removed),a.push(...o.affected)}),{updated:p(e),added:p(t),removed:p(r),affected:p(a),self:this}}onDetachedDependencyRemoved(e,t,r){const a=[],d=[],o=[],l=[];if(t==="parent"){const{updated:u,added:h,removed:c}=this.remove({ignoreUpstream:!1},r);a.push(...u),d.push(...h),o.push(...c)}return{updated:p(a),added:p(d),removed:p(o),affected:p(l),self:this}}onDetachedDependencyRestored(e,t,r){const a=[],d=[],o=[],l=[];if(t==="parent"){const{updated:u,added:h,removed:c}=this.restore({},r);a.push(...u),d.push(...h),o.push(...c)}return{updated:p(a),added:p(d),removed:p(o),affected:p(l),self:this}}subscribeToDependencies(){var e;return(e=this.parent)==null||e.subscribeDependents([{entity:this,field:"parent"}]),this}increaseVersion(e){if(e&&!T(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&T(e).isSame(T(this.createdAt))?this:(this.previousVersion=this.version,this.version=I.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t,r;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new xe(this,this.project);return(r=this.knownVersions)==null||r.set(this.version,e),e.inputs=this.inputs,e.declaration=this.declaration,e.successCalls=this.successCalls,e.errorCalls=this.errorCalls,e.calledBySuccess=this.calledBySuccess,e.calledByError=this.calledByError,e.calledByEntry=this.calledByEntry,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],r=[],a=[],d=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),r.push(...o.added),a.push(...o.removed)}return{updated:p(t),added:p(r),removed:p(a),affected:p(d),self:this}}async restoreVersion(e){var l;const t=[],r=[],a=[],d=[];if(this.version===e)return{updated:p(t),added:p(r),removed:p(a),affected:p(d),self:this};if(!this.knownVersions){const u=new Map;for(const[h,c]of this.knownVersions||new Map){if(u.set(h,c),c.activeVersion=!1,c.knownVersions)for(const[v,E]of c.knownVersions)u.set(v,E);c.knownVersions=null}}let o=(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 xe(u,this.project)}return this.metaSync(o.toShallowJSON(),null),this.inputs=o.inputs,this.declaration=o.declaration,this.successCalls=o.successCalls,this.errorCalls=o.errorCalls,this.calledBySuccess=o.calledBySuccess,this.calledByError=o.calledByError,this.calledByEntry=o.calledByEntry,this.parent=o.parent,{updated:p(t),added:p(r),removed:p(a),affected:p(d),self:this}}hydrateAncestors(){const e=[],t=[],r=[],a=[];if(this.initialData.parent){const d=B(this.initialData.parent),o=this.project.get(d);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${Wt(this.type)} with id '${this.id}' has a parent reference "${d}" which is missing in the project`)}else throw new Error(`${Wt(this.type)} with id '${this.id}' is missing a parent reference`);if(this.initialData.declaration){const d=B(this.initialData.declaration),o=this.project.get(d);o&&(this.setDeclaration(o),e.push(o))}return this.initialData.calledByEntry.forEach(d=>{const o=B(d),l=this.project.get(o);l&&(this.addEntryCaller(l,null),e.push(l))}),this.initialData.calledBySuccess.forEach(d=>{const o=B(d),l=this.project.get(o);l&&(this.addSuccessCaller(l,null),e.push(l))}),this.initialData.calledByError.forEach(d=>{const o=B(d),l=this.project.get(o);l&&(this.addErrorCaller(l,null),e.push(l))}),{updated:p(e),added:p(t),removed:p(r),affected:p(a),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new R(this.project,"",T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],r=[],a=[],d=[];this.initialized=!0,this.captureVersion();const{updated:o,added:l,removed:u}=this.syncMissingFixedInputs(e);return t.push(...o),r.push(...l),a.push(...u),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:p(t),added:p(r),removed:p(a),affected:p(d),self:this}}addSelfToProject(e=this.project.addChangeSet(new R(this.project,"",T().toISOString(),this,!0,"add-self-to-project"))){const t=[this],r=[],a=[],d=[];return this.parent===this.project&&this.project.addCondition(this),this.successCalls.forEach(o=>{o.addSuccessCaller(this,e),t.push(o)}),this.errorCalls.forEach(o=>{o.addErrorCaller(this,e),t.push(o)}),this.calledByEntry.forEach(o=>{o.addCall(this),t.push(o)}),this.calledBySuccess.forEach(o=>{o.addSuccessCall(this),t.push(o)}),this.calledByError.forEach(o=>{o.addErrorCall(this),t.push(o)}),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:p(t),added:p(r),removed:p(a),affected:p(d),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}removeInput(e){const t=this.inputs.findIndex(r=>r.id===e.id);return t>-1&&this.inputs.splice(t,1),this}addInput(e){return this.inputs.includes(e)?this:(this.inputs.push(e),this)}addOutput(e){return this}removeOutput(e){return this}addSuccessCaller(e,t=this.project.addChangeSet(new R(this.project,"",T().toISOString(),this,!0,"add-success-caller"))){return this.calledBySuccess.find(r=>r.id===e.id)||(this.calledBySuccess.push(e),t&&(t==null||t.add(this,b.Updated),t==null||t.add(e,b.Affected)),t==null||t.attemptAutoclose("add-success-caller",this.id)),this}addErrorCaller(e,t=this.project.addChangeSet(new R(this.project,"",T().toISOString(),this,!0,"add-error-caller"))){return this.calledByError.find(r=>r.id===e.id)||(this.calledByError.push(e),t&&(t==null||t.add(this,b.Updated),t==null||t.add(e,b.Affected)),t==null||t.attemptAutoclose("add-error-caller",this.id)),this}addEntryCaller(e,t=this.project.addChangeSet(new R(this.project,"",T().toISOString(),this,!0,"add-entry-caller"))){return this.calledByEntry.find(r=>r.id===e.id)||(this.calledByEntry.push(e),t&&(t==null||t.add(this,b.Updated),t==null||t.add(e,b.Affected)),t==null||t.attemptAutoclose("add-entry-caller",this.id)),this}addErrorCall(e){return this.errorCalls.find(t=>t.id===e.id)||this.errorCalls.push(e),this}addSuccessCall(e){return this.successCalls.find(t=>t.id===e.id)||this.successCalls.push(e),this}removeCall(e){const t=this.successCalls.findIndex(a=>a.id===e.id);t>-1&&this.successCalls.splice(t,1);const r=this.errorCalls.findIndex(a=>a.id===e.id);return r>-1&&this.errorCalls.splice(r,1),this}removeCaller(e,t=this.project.addChangeSet(new R(this.project,"",T().toISOString(),this,!0,"remove-caller"))){return this.calledBySuccess=this.calledBySuccess.filter(r=>r.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(r,b.Affected)),!0):!1),this.calledByError=this.calledByError.filter(r=>r.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(r,b.Affected)),!0):!1),this.calledByEntry=this.calledByEntry.filter(r=>r.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(r,b.Affected)),!0):!1),t==null||t.attemptAutoclose("remove-caller",this.id),this}setParent(e,t=this.project.addChangeSet(new R(this.project,"",T().toISOString(),this,!0,"set-parent"))){var r;return((r=this.parent)==null?void 0:r.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,b.Updated),t==null||t.attemptAutoclose("set-parent",this.id))),this}setDeclaration(e){return this.declaration=e,this}initChildren(e=this.project.addChangeSet(new R(this.project,"",T().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.declaration=V(this.initialData.declaration,this.project),this.successCalls=this.initialData.successCalls.map(t=>{const r=V(t,this.project);return r.addSuccessCaller(this),[n.BreakStatement,n.ContinueStatement].includes(r.type)?(r.setParent(this.parent.parent,null),r.initChildren(e)):r.type!==n.InternalCall&&(r.setParent(this.parent,null),r.initChildren(e)),r}),this.errorCalls=this.initialData.errorCalls.map(t=>{const r=V(t,this.project);return r.addErrorCaller(this),[n.BreakStatement,n.ContinueStatement].includes(r.type)?(r.setParent(this.parent.parent,null),r.initChildren(e)):r.type!==n.InternalCall&&(r.setParent(this.parent,null),r.initChildren(e)),r}),this.inputs=this.initialData.inputs.map(t=>{const r=V(t,this.project);return r.setParent(this,null),r.initChildren(e),r}),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this)}subscribe(){return this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new R(this.project,"",T().toISOString(),this,!0,"sync-meta"))){const r=dt(this,e);return e.deleted===!0&&!this.deleted?t==null||t.add(this,b.Removed):e.deleted===!1&&this.deleted?t==null||t.add(this,b.Added):r&&(t==null||t.add(this,b.Updated)),super.metaSync(e),this.x=e.x||this.x,this.y=e.y||this.y,t==null||t.attemptAutoclose("sync-meta",this.id),this}async APILoad(e=L,...t){return await xe.repository.APILoad(this.id,...t),this}async APICreate(e=L,...t){return await xe.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=L,...t){return await xe.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=L,...t){return await xe.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=L,...t){return await xe.repository.APIClone(this.id,...t),this}async APILoadVersion(e=L,t,...r){return await xe.repository.APILoadVersion(this.id,t,...r)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new R(this.project,"",T().toISOString(),this,!0,"remove-entity"))){const r=[],a=[],d=[],o=[];return t!=null&&t.hasRemoved(this.id)?(t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(a.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(l=>{const{updated:u,removed:h,added:c}=l.entity.onDetachedDependencyRemoved(this,l.field,t);r.push(...u),a.push(...h),d.push(...c)}),this.inputs.forEach(l=>{const{updated:u,removed:h}=l.remove({ignoreUpstream:!0},t);r.push(...u),a.push(...h)}),this.successCalls.forEach(l=>{r.push(l),l.removeCaller(this)}),this.errorCalls.forEach(l=>{r.push(l),l.removeCaller(this)}),e||this.calledBy.forEach(l=>{r.push(l),l.removeCall(this)}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:p(d),updated:p(r),removed:p(a),affected:p(o),self:this})}restore({}={},e=this.project.addChangeSet(new R(this.project,"",T().toISOString(),this,!0,"restore-entity"))){const t=[],r=[],a=[],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),this.inputs.forEach(o=>{const{updated:l}=o.restore({},e);r.push(...l)}),this.successCalls.forEach(o=>{r.push(o),o.addSuccessCaller(this)}),this.errorCalls.forEach(o=>{r.push(o),o.addErrorCaller(this)}),this.calledBySuccess.forEach(o=>{r.push(o),o.addSuccessCall(this)}),this.calledByError.forEach(o=>{r.push(o),o.addErrorCall(this)}),this.calledByEntry.forEach(o=>{r.push(o),o.addCall(this)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:p(t),updated:p(r),removed:p(a),affected:p(d),self:this})}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.inputs.flatMap(r=>r.toFlat(e)),...this.successCalls.flatMap(r=>r.toFlat(e)),...this.errorCalls.flatMap(r=>r.toFlat(e)),...this.calledBy.flatMap(r=>r.toFlat(e))])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.inputs.flatMap(r=>r.toFlatIds(e)),...this.successCalls.flatMap(r=>r.toFlatIds(e)),...this.errorCalls.flatMap(r=>r.toFlatIds(e)),...this.calledBy.flatMap(r=>r.toFlatIds(e))])}toJSON(e=new Set){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,x:this.x,y:this.y,declaration:this.declaration.toJSON(e),successCalls:this.successCalls.map(t=>t.toJSON(e)),errorCalls:this.errorCalls.map(t=>t.toJSON(e)),calledBySuccess:this.calledBySuccess.map(t=>t.toReference()),calledByError:this.calledByError.map(t=>t.toReference()),calledByEntry:this.calledByEntry.map(t=>t.toReference()),inputs:this.inputs.map(t=>t.toJSON(e)),parent:this.parent.toReference()})}toJSONClone(e=Z){var r,a,d,o,l;let t;return(r=e.seenEntityMaps)!=null&&r.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||ct(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(a=e.seenEntities)!=null&&a.has(t)||(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:I.UUID.uuid(),createdAt:e.timestamp||T().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,declaration:this.declaration.toJSON(),successCalls:this.successCalls.map(u=>u.toJSONClone({...e,newId:null})),errorCalls:this.errorCalls.map(u=>u.toJSONClone({...e,newId:null})),calledBySuccess:this.calledBySuccess.map(u=>u.toReference({seenEntityMaps:e.seenEntityMaps})),calledByError:this.calledByError.map(u=>u.toReference({seenEntityMaps:e.seenEntityMaps})),calledByEntry:this.calledByEntry.map(u=>u.toReference({seenEntityMaps:e.seenEntityMaps})),inputs:this.inputs.map(u=>u.toJSONClone({...e,newId:null})),parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps})})}toReference(e=Z){var r;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+I.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=Z){var r;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,declaration:this.declaration.toReference(e),inputs:this.inputs.map(a=>a.toReference(e)),successCalls:this.successCalls.map(a=>a.toReference(e)),errorCalls:this.errorCalls.map(a=>a.toReference(e)),calledBySuccess:this.calledBySuccess.map(a=>a.toReference(e)),calledByError:this.calledByError.map(a=>a.toReference(e)),calledByEntry:this.calledByEntry.map(a=>a.toReference(e)),parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.inputs.flatMap(r=>r.toFlatJSON(e)),...this.successCalls.flatMap(r=>r.toFlatJSON(e)),...this.errorCalls.flatMap(r=>r.toFlatJSON(e)),...this.calledBy.flatMap(r=>r.toFlatJSON(e))])}toGenerationTarget(){const e=this.parent.type===n.Project?void 0:this.parent.id;return{id:this.id,type:this.type,declaration:this.declaration.id,calledByEntry:this.calledByEntry.map(t=>t.id),calledBySuccess:this.calledBySuccess.map(t=>t.id),calledByError:this.calledByError.map(t=>t.id),parent:e}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...this.inputs.flatMap(r=>r.toFlatGenerationTarget(e)),...this.successCalls.flatMap(r=>r.toFlatGenerationTarget(e)),...this.errorCalls.flatMap(r=>r.toFlatGenerationTarget(e))])}clearErrors(){return this.errors=[],this.inputs.forEach(e=>e.clearErrors()),this.successCalls.forEach(e=>e.clearErrors()),this.errorCalls.forEach(e=>e.clearErrors()),this}validate(){const e=aq(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){return[...this.errors,...this.inputs.flatMap(t=>t.getErrors())]}getShallowErrors(){return this.errors}clone(e=this.project.addChangeSet(new R(this.project,"",T().toISOString(),this,!0,"clone-entity")),t=null,r=null,a=!0){var E;let d=ft(t,this);const o=this.toJSON(),l=r||I.UUID.uuid();o.inputs=[];const u=l.split("-id"),h=u[u.length-1||0]||l;o.id=l,o.version=I.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 c=lt(o,d);t?c.setParent(t,null):c.setParent(this.parent,null),a&&c.subscribe(),c.initChildren(e),e==null||e.add(c,b.Added);const v=(E=this.inputs)==null?void 0:E.map((O,w)=>O.clone(e,c,h+"-input-map-"+w+"-id",a));return c.inputs=v,e==null||e.attemptAutoclose("clone-entity",this.id),c}removeUnrecognizedInputs(e=this.project.addChangeSet(new R(this.project,"",T().toISOString(),this,!0,"remove-unrecognized-inputs"))){const t=[],r=[],a=[],d=[];return this.inputs.forEach(o=>{if(!this.declaration.inputs.find(u=>{var h;return u.id===((h=o.declaration)==null?void 0:h.id)})){const u=o.remove({ignoreUpstream:!0},e);a.push(...u.removed),t.push(...u.updated)}}),e==null||e.attemptAutoclose("remove-unrecognized-inputs",this.id),{updated:p(t),added:p(r),removed:p(a),affected:p(d),self:this}}syncMissingFixedInputs(e=this.project.addChangeSet(new R(this.project,"",T().toISOString(),this,!0,"sync-missing-fixed-inputs"))){const t=[],r=[],a=[],d=[],o=this.declaration.inputs.filter(c=>c.parentRelationType===M.FixedArguments&&!this.inputs.find(v=>v.declaration.id===c.id));this.inputs.sort((c,v)=>c.index-v.index),o.forEach(c=>{this.inputs.forEach(O=>{O.index>=c.index&&O.metaSync({index:O.index+1})});const v={id:I.UUID.uuid(),version:I.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:I.sessionAuthor,previousVersion:null,deleted:!1,type:n.InputMap,declaration:c.toJSON(),readsValue:null,defaultValue:null,index:c.index,name:null,description:null,parent:this.toReference()},E=V(v,this.project);E.setParent(this,e),E.initChildren(e),e==null||e.add(E,b.Added),E.addSelfToProject(e)}),this.inputs.sort((c,v)=>c.index-v.index);const{updated:l,added:u,removed:h}=this.removeUnrecognizedInputs(e);return t.push(...l),r.push(...u),a.push(...h),e==null||e.attemptAutoclose("sync-missing-fixed-inputs",this.id),{updated:p(t),added:p(r),removed:p(a),affected:p(d),self:this}}};f(xe,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>e,APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...r)=>null}),f(xe,"type",n.Condition),f(xe,"USER_MANAGED_PARENT_TYPES",[...mt,n.Project]),f(xe,"PARENT_TYPES",[...xe.USER_MANAGED_PARENT_TYPES]),f(xe,"MUTABLE_BASE_PROPERTIES",["operator"]),f(xe,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),f(xe,"BASE_PROPERTIES",[...xe.MUTABLE_BASE_PROPERTIES,...xe.INMUTABLE_BASE_PROPERTIES]),f(xe,"MUTABLE_META_PROPERTIES",["x","y"]),f(xe,"INMUTABLE_META_PROPERTIES",[...xe.INMUTABLE_BASE_PROPERTIES]),f(xe,"META_PROPERTIES",[...xe.MUTABLE_META_PROPERTIES,...xe.INMUTABLE_META_PROPERTIES]),f(xe,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry","parent"]),f(xe,"INMUTABLE_UPSTREAM_PROPERTIES",[]),f(xe,"UPSTREAM_PROPERTIES",[...xe.MUTABLE_UPSTREAM_PROPERTIES,...xe.INMUTABLE_UPSTREAM_PROPERTIES]),f(xe,"MUTABLE_DOWNSTREAM_PROPERTIES",["successCalls","errorCalls","inputsDeclarations","inputs"]),f(xe,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),f(xe,"DOWNSTREAM_PROPERTIES",[...xe.MUTABLE_DOWNSTREAM_PROPERTIES,...xe.INMUTABLE_DOWNSTREAM_PROPERTIES]),f(xe,"PROPERTIES",[...xe.META_PROPERTIES,...xe.UPSTREAM_PROPERTIES,...xe.DOWNSTREAM_PROPERTIES]);let Li=xe;function sq(i){var o;const s=L3(),e=i.toJSON();s.safeParse(e).success,(o=i.dataType)==null||o.validate(),i.inputs.forEach(l=>l.validate()),i.outputs.forEach(l=>l.validate()),i.internalCalls.forEach(l=>l.validate());const a=[...fi(i)];if(i.id==="random-company-employee-test-variable-id"){const l=ye({id:`${i.id}--${q.PropertyImplementsNonAbstact}`,message:`Property "${F(i,i.project)}" with id "${i.id}" implements a non-abstract property "${F(i,i.project)}" with id "${i.id}".`,issue:null,severity:D.Error,code:q.PropertyImplementsNonAbstact,entity:i});a.push(l.error)}if(i.id==="company-dto-variable-one-id"){const l=ye({id:`${i.id}--${q.PropertyImplementsNonAbstact}`,message:`Property "${F(i,i.project)}" with id "${i.id}" implements a non-abstract property "${F(i,i.project)}" with id "${i.id}".`,issue:null,severity:D.Error,code:q.PropertyImplementsNonAbstact,entity:i});a.push(l.error)}const d=Nc(i);return a.push(...d),ze(i.errors,a)}function oq(i){const s=F3(),e=i.toJSON();s.safeParse(e).success,i.inputs.forEach(o=>o.validate()),i.outputs.forEach(o=>o.validate()),i.internalCalls.forEach(o=>o.validate());const a=[...fi(i)];if(i.id==="exec-sequentially-result-variable-id"){const o=ye({id:`${i.id}--${q.PropertyImplementsNonAbstact}`,message:`Property "${F(i,i.project)}" with id "${i.id}" implements a non-abstract property "${F(i,i.project)}" with id "${i.id}".`,issue:null,severity:D.Error,code:q.PropertyImplementsNonAbstact,entity:i});a.push(o.error)}const d=Nc(i);return a.push(...d),ze(i.errors,a)}var Dc=(i=>(i.Parent="parent",i.DataTypeEntity="data-type-entity",i.VarDeclaration="var-declaration",i))(Dc||{});const we=class we extends rt{constructor(e,t){super(e);f(this,"initialData");f(this,"id");f(this,"x");f(this,"y");f(this,"type",n.VariableInstance);f(this,"defaultValue",null);f(this,"writesValues",[]);f(this,"readsValue",null);f(this,"declaration");f(this,"inputs",[]);f(this,"outputs",[]);f(this,"calledBySuccess",[]);f(this,"calledByError",[]);f(this,"calledByEntry",[]);f(this,"successCalls",[]);f(this,"errorCalls",[]);f(this,"internalCalls",[]);f(this,"project");f(this,"errors",[]);f(this,"parent");f(this,"detachedDependents",{});f(this,"knownVersions",null);f(this,"activeVersion",!1);f(this,"initialized",!1);f(this,"startedInitialization",!1);f(this,"suggestion",!1);this.initialData=e,this.project=t,this.id=e.id,this.x=e.x,this.y=e.y}static fromGenerationTarget(e,t){let r=t;if(e.parent){const E=B(e.parent);r=t.get(E)}const a=B(e.declaration),d=t.get(a),o=e.calledByEntry.map(E=>{const O=B(E);return t.get(O)}),l=e.calledBySuccess.map(E=>{const O=B(E);return t.get(O)}),u=e.calledByError.map(E=>{const O=B(E);return t.get(O)});let h=null;if(e.readsValue){const E=B(e.readsValue);h=t.get(E)}const c={id:e.id,version:I.UUID.uuid(),createdAt:T().toISOString(),author:I.sessionAuthor,previousVersion:null,deleted:!1,type:n.VariableInstance,declaration:d.toReference(),calledByEntry:o,calledBySuccess:l,calledByError:u,defaultValue:null,errorCalls:[],successCalls:[],internalCalls:[],readsValue:h,inputs:[],outputs:[],writesValues:[],x:0,y:0,parent:r},v=V(c,t);return v.setParent(r,null),v.initChildren(null),v}static validateGenerationTarget(e,t){let r=JSON.parse(JSON.stringify(e));const a=[],d=Et(r,{parent:{list:!1,types:[...mt,n.Project],optional:!0},declaration:{list:!1,types:[n.VariableDeclaration]}},t);return r=d.modifiedData,a.push(...d.errors,...ot(r)),{errors:a,modifiedData:r}}validateGeneratedUpdate(e){const t=[];let r=JSON.parse(JSON.stringify(e));const a=ws(r,this);return r=a.modifiedData,t.push(...a.errors),e.parent&&t.push(new P({id:`${this.id}--${A.InvalidParentUpdate}`,code:A.InvalidParentUpdate,severity:D.Error,message:`Entity of type '${this.type}' with id '${this.id}' cannot have the 'parent' property updated. The 'parent' on a callable entity, is its scope. It scope is auto-calculated implicitly by the its caller.
|
|
104
104
|
If an entity is called by another, they must be in the same scope, which means they have the same parent.
|
|
105
105
|
Specifically for variables, their scope is also calculated from their value readers and value writters.
|
|
106
|
-
You shouldn't have to manually update a 'parent' property. The equivalent result is to change its value readers, value writters, or callers.`,issue:null})),{errors:t,modifiedData:r}}subscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]||(this.detachedDependents[t.entity.id]=t)}),this}syncDependents(){const e=[],t=[],r=[],a=[];return Object.values(this.detachedDependents).forEach(d=>{const o=d.entity.afterAllChildrenInitialized();e.push(...o.updated),t.push(...o.added),r.push(...o.removed),a.push(...o.affected)}),{updated:p(e),added:p(t),removed:p(r),affected:p(a),self:this}}onDetachedDependencyRemoved(e,t,r){const a=[],d=[],o=[],l=[];if(t==="parent"){const{updated:u,added:h,removed:c}=this.remove({ignoreUpstream:!1},r);a.push(...u),d.push(...h),o.push(...c)}if(t==="var-declaration"){const{updated:u,added:h,removed:c}=this.remove({ignoreUpstream:!1},r);a.push(...u),d.push(...h),o.push(...c)}return{updated:p(a),added:p(d),removed:p(o),affected:p(l),self:this}}onDetachedDependencyRestored(e,t,r){const a=[],d=[],o=[],l=[];if(t==="parent"){const{updated:u,added:h,removed:c}=this.restore({},r);a.push(...u),d.push(...h),o.push(...c)}if(t==="var-declaration"){const{updated:u,added:h,removed:c}=this.restore({},r);a.push(...u),d.push(...h),o.push(...c)}return{updated:p(a),added:p(d),removed:p(o),affected:p(l),self:this}}subscribeToDependencies(){var e,t,r,a;return(e=this.parent)==null||e.subscribeDependents([{entity:this,field:"parent"}]),(a=(r=(t=this.declaration.dataType)==null?void 0:t.entity)==null?void 0:r.subscribeDependents)==null||a.call(r,[{entity:this,field:"data-type-entity"}]),this.declaration.subscribeDependents([{entity:this,field:"var-declaration"}]),this}increaseVersion(e){if(e&&!T(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&T(e).isSame(T(this.createdAt))?this:(this.previousVersion=this.version,this.version=I.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t,r;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new we(this,this.project);return(r=this.knownVersions)==null||r.set(this.version,e),e.inputs=this.inputs,e.outputs=this.outputs,e.internalCalls=this.internalCalls,e.successCalls=this.successCalls,e.errorCalls=this.errorCalls,e.writesValues=this.writesValues,e.readsValue=this.readsValue,e.defaultValue=this.defaultValue,e.declaration=this.declaration,e.calledBySuccess=this.calledBySuccess,e.calledByError=this.calledByError,e.calledByEntry=this.calledByEntry,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],r=[],a=[],d=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),r.push(...o.added),a.push(...o.removed)}return{updated:p(t),added:p(r),removed:p(a),affected:p(d),self:this}}async restoreVersion(e){var l;const t=[],r=[],a=[],d=[];if(this.version===e)return{updated:p(t),added:p(r),removed:p(a),affected:p(d),self:this};if(!this.knownVersions){const u=new Map;for(const[h,c]of this.knownVersions||new Map){if(u.set(h,c),c.activeVersion=!1,c.knownVersions)for(const[v,E]of c.knownVersions)u.set(v,E);c.knownVersions=null}}let o=(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 we(u,this.project)}return this.metaSync(o.toShallowJSON(),null),this.inputs=o.inputs,this.outputs=o.outputs,this.internalCalls=o.internalCalls,this.successCalls=o.successCalls,this.errorCalls=o.errorCalls,this.writesValues=o.writesValues,this.readsValue=o.readsValue,this.defaultValue=o.defaultValue,this.declaration=o.declaration,this.calledBySuccess=o.calledBySuccess,this.calledByError=o.calledByError,this.calledByEntry=o.calledByEntry,this.parent=o.parent,{updated:p(t),added:p(r),removed:p(a),affected:p(d),self:this}}hydrateAncestors(){const e=[],t=[],r=[],a=[];if(this.initialData.parent){const d=B(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 throw new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(this.initialData.readsValue){const d=B(this.initialData.readsValue),o=this.project.get(d);o&&(this.setValueWriter(o),e.push(o))}if(this.initialData.declaration){const d=B(this.initialData.declaration),o=this.project.get(d);o&&(this.setDeclaration(o),e.push(o))}return this.initialData.calledByEntry.forEach(d=>{const o=B(d),l=this.project.get(o);l&&(this.addEntryCaller(l,null),e.push(l))}),this.initialData.calledBySuccess.forEach(d=>{const o=B(d),l=this.project.get(o);l&&(this.addSuccessCaller(l,null),e.push(l))}),this.initialData.calledByError.forEach(d=>{const o=B(d),l=this.project.get(o);l&&(this.addErrorCaller(l,null),e.push(l))}),yi.hydrateReadsValue(this),{updated:p(e),added:p(t),removed:p(r),affected:p(a),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new R(this.project,"",T().toISOString(),this,!0,"after-all-children-initialized"))){var _;const t=[],r=[],a=[],d=[];this.initialized=!0,this.captureVersion();const{added:o,updated:l,removed:u,affected:h}=this.generateUnusedInputs(e);r.push(...o),t.push(...l),a.push(...u),d.push(...h);const{added:c,updated:v,removed:E,affected:O}=this.generateUnusedOutputs(e);r.push(...c),t.push(...v),a.push(...E),d.push(...O);const{added:w,updated:C,removed:U,affected:G}=this.generateUnusedInternalCalls(e);if(r.push(...w),t.push(...C),a.push(...U),d.push(...G),!this.declaration.dataType||(_=this.declaration.dataType)!=null&&_.inferred){const{added:$,updated:k,removed:J,affected:ee}=this.declaration.inferDataTypeAndSyncInstancesInputsAndOutputs(e);r.push(...$),t.push(...k),a.push(...J),d.push(...ee)}return e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:p(t),added:p(r),removed:p(a),affected:p(d),self:this}}addSelfToProject(e=this.project.addChangeSet(new R(this.project,"",T().toISOString(),this,!0,"add-self-to-project"))){const t=[this],r=[],a=[],d=[];return this.parent===this.project&&this.project.addVariableInstance(this),this.readsValue&&(this.readsValue.addValueReader(this),t.push(this.readsValue)),this.writesValues.forEach(o=>{o.setValueWriter(this),t.push(o)}),this.successCalls.forEach(o=>{o.addSuccessCaller(this,e),t.push(o)}),this.errorCalls.forEach(o=>{o.addErrorCaller(this,e),t.push(o)}),this.calledBySuccess.forEach(o=>{o.addSuccessCall(this),t.push(o)}),this.calledByError.forEach(o=>{o.addErrorCall(this),t.push(o)}),this.calledByEntry.forEach(o=>{o.addCall(this),t.push(o)}),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:p(t),added:p(r),removed:p(a),affected:p(d),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}get usedInputs(){return this.inputs.filter(e=>e.readsValue||e.defaultValue)}get unusedInputs(){return this.inputs.filter(e=>!e.readsValue&&!e.defaultValue)}get usedOutputs(){return this.outputs.filter(e=>e.writesValues.length)}get unusedOutputs(){return this.outputs.filter(e=>!e.writesValues.length)}get usedInternalCalls(){return this.internalCalls.filter(e=>!!e.calledBy.length)}get unusedInternalCalls(){const e=this.usedInternalCalls;return this.internalCalls.filter(r=>!(e.find(o=>o.id===r.id)||e.find(o=>o.declaration===r.declaration)))}removeInput(e){const t=this.inputs.findIndex(r=>r.id===e.id);return t>-1&&this.inputs.splice(t,1),this}addInput(e){return this.inputs.includes(e)?this:(this.inputs.push(e),this)}addOutput(e){return this.outputs.includes(e)?this:(this.outputs.push(e),this)}removeOutput(e){const t=this.outputs.findIndex(r=>r.id===e.id);return t>-1&&this.outputs.splice(t,1),this}addSuccessCaller(e,t=this.project.addChangeSet(new R(this.project,"",T().toISOString(),this,!0,"add-success-caller"))){return this.calledBySuccess.find(r=>r.id===e.id)||(this.calledBySuccess.push(e),t&&(t==null||t.add(this,b.Updated),t==null||t.add(e,b.Affected)),t==null||t.attemptAutoclose("add-success-caller",this.id)),this}addErrorCaller(e,t=this.project.addChangeSet(new R(this.project,"",T().toISOString(),this,!0,"add-error-caller"))){return this.calledByError.find(r=>r.id===e.id)||(this.calledByError.push(e),t&&(t==null||t.add(this,b.Updated),t==null||t.add(e,b.Affected)),t==null||t.attemptAutoclose("add-error-caller",this.id)),this}addEntryCaller(e,t=this.project.addChangeSet(new R(this.project,"",T().toISOString(),this,!0,"add-entry-caller"))){return this.calledByEntry.find(r=>r.id===e.id)||(this.calledByEntry.push(e),t&&(t==null||t.add(this,b.Updated),t==null||t.add(e,b.Affected)),t==null||t.attemptAutoclose("add-entry-caller",this.id)),this}addErrorCall(e){return this.errorCalls.find(t=>t.id===e.id)||this.errorCalls.push(e),this}addSuccessCall(e){return this.successCalls.find(t=>t.id===e.id)||this.successCalls.push(e),this}removeCall(e){const t=this.successCalls.findIndex(a=>a.id===e.id);t>-1&&this.successCalls.splice(t,1);const r=this.errorCalls.findIndex(a=>a.id===e.id);return r>-1&&this.errorCalls.splice(r,1),this}removeCaller(e,t=this.project.addChangeSet(new R(this.project,"",T().toISOString(),this,!0,"remove-caller"))){return this.calledBySuccess=this.calledBySuccess.filter(r=>r.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(r,b.Affected)),!0):!1),this.calledByError=this.calledByError.filter(r=>r.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(r,b.Affected)),!0):!1),this.calledByEntry=this.calledByEntry.filter(r=>r.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(r,b.Affected)),!0):!1),t==null||t.attemptAutoclose("remove-caller",this.id),this}addValueReader(e){return this.writesValues.includes(e)?this:(this.writesValues.push(e),this)}setParent(e,t=this.project.addChangeSet(new R(this.project,"",T().toISOString(),this,!0,"set-parent"))){var r;return((r=this.parent)==null?void 0:r.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,b.Updated),t==null||t.attemptAutoclose("set-parent",this.id))),this}initChildren(e=this.project.addChangeSet(new R(this.project,"",T().toISOString(),this,!0,"init-children"))){if(this.initialized||this.startedInitialization)return this;if(this.startedInitialization=!0,this.initialData.defaultValue&&(this.defaultValue=V(this.initialData.defaultValue,this.project),this.defaultValue.setParent(this,null),this.defaultValue.initChildren(e)),this.initialData.declaration.type===n.GenericReference){const t=this.project.findSubscribedInstanceFromReference(this.initialData.declaration);if(!t)return this;this.declaration=t}else this.declaration=V(this.initialData.declaration,this.project),this.declaration.setParent(this.parent,null),this.declaration.initChildren(e);return gs.initWritesValues(this,this.parent),yi.initReadsValue(this),this.initialData.inputs.forEach(t=>{const r=V(t,this.project);return r.setParent(this,null),r.initChildren(e),this.addInput(r),r}),this.initialData.outputs.forEach(t=>{const r=V(t,this.project);return r.setParent(this,null),r.initChildren(e),this.addOutput(r),r}),this.successCalls=this.initialData.successCalls.map(t=>{const r=V(t,this.project);return r.addSuccessCaller(this),[n.BreakStatement,n.ContinueStatement].includes(r.type)?(r.setParent(this.parent.parent,null),r.initChildren(e)):r.type!==n.InternalCall&&(r.setParent(this.parent,null),r.initChildren(e)),r}),this.errorCalls=this.initialData.errorCalls.map(t=>{const r=V(t,this.project);return r.addErrorCaller(this),[n.BreakStatement,n.ContinueStatement].includes(r.type)?(r.setParent(this.parent.parent,null),r.initChildren(e)):r.type!==n.InternalCall&&(r.setParent(this.parent,null),r.initChildren(e)),r}),this.internalCalls=this.initialData.internalCalls.reduce((t,r)=>{if(r.type===n.GenericReference){const a=this.project.findSubscribedInstanceFromReference(r);if(!a)return t;const d=a;return d.setParent(this,null),[...t,d]}else{const a=V(r,this.project);return a.setParent(this,null),a.initChildren(e),[...t,a]}},[]),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this}setValueWriter(e){return this.readsValue=e,this}removeValueWriter(){return this.readsValue=null,this}removeValueReader(e){return this.writesValues=this.writesValues.filter(t=>t.id!==e.id),this}subscribe(){return this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new R(this.project,"",T().toISOString(),this,!0,"sync-meta"))){const r=dt(this,e);return e.deleted===!0&&!this.deleted?t==null||t.add(this,b.Removed):e.deleted===!1&&this.deleted?t==null||t.add(this,b.Added):r&&(t==null||t.add(this,b.Updated)),super.metaSync(e),this.x=e.x||this.x,this.y=e.y||this.y,t==null||t.attemptAutoclose("sync-meta",this.id),this}async APILoad(e=L,...t){return await we.repository.APILoad(this.id,...t),this}async APICreate(e=L,...t){return await we.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=L,...t){return await we.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=L,...t){return await we.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=L,...t){return await we.repository.APIClone(this.id,...t),this}async APILoadVersion(e=L,t,...r){return await we.repository.APILoadVersion(this.id,t,...r)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new R(this.project,"",T().toISOString(),this,!0,"remove-entity"))){const r=[],a=[],d=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(a.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(l=>{const{updated:u,removed:h,added:c}=l.entity.onDetachedDependencyRemoved(this,l.field,t);r.push(...u),a.push(...h),d.push(...c)}),this.defaultValue){const{updated:l,removed:u}=this.defaultValue.remove({ignoreUpstream:!0},t);r.push(...l),a.push(...u)}return this.readsValue&&(r.push(this.readsValue),this.readsValue.removeValueReader(this)),this.writesValues.forEach(l=>{r.push(l),l.readsValue=null}),this.inputs.forEach(l=>{const{updated:u,removed:h}=l.remove({ignoreUpstream:!0},t);r.push(...u),a.push(...h)}),this.outputs.forEach(l=>{const{updated:u,removed:h}=l.remove({ignoreUpstream:!0},t);r.push(...u),a.push(...h)}),this.successCalls.forEach(l=>{r.push(l),l.removeCaller(this)}),this.errorCalls.forEach(l=>{r.push(l),l.removeCaller(this)}),this.internalCalls.forEach(l=>{const{updated:u,removed:h}=l.remove({ignoreUpstream:!0},t);r.push(...u),a.push(...h)}),e||this.calledBy.forEach(l=>{r.push(l),l.removeCall(this)}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:p(d),updated:p(r),removed:p(a),affected:p(o),self:this}}restore({}={},e=this.project.addChangeSet(new R(this.project,"",T().toISOString(),this,!0,"restore-entity"))){const t=[],r=[],a=[],d=[];if(e!=null&&e.hasAdded(this.id))return e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),this.defaultValue){const{updated:o}=this.defaultValue.restore({},e);r.push(...o)}return this.readsValue&&(r.push(this.readsValue),this.readsValue.addValueReader(this)),this.writesValues.forEach(o=>{r.push(o),o.setValueWriter(this)}),this.inputs.forEach(o=>{const{updated:l}=o.restore({},e);r.push(...l)}),this.outputs.forEach(o=>{const{updated:l}=o.restore({},e);r.push(...l)}),this.successCalls.forEach(o=>{r.push(o),o.addSuccessCaller(this)}),this.errorCalls.forEach(o=>{r.push(o),o.addErrorCaller(this)}),this.internalCalls.forEach(o=>{const{updated:l}=o.restore({},e);r.push(...l)}),this.calledBySuccess.forEach(o=>{r.push(o),o.addSuccessCall(this)}),this.calledByError.forEach(o=>{r.push(o),o.addErrorCall(this)}),this.calledByEntry.forEach(o=>{r.push(o),o.addCall(this)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:p(t),updated:p(r),removed:p(a),affected:p(d),self:this}}toFlat(e=new Set){var r,a;return e.has(this.id)?[]:(e.add(this.id),[this,...((r=this.defaultValue)==null?void 0:r.toFlat(e))||[],...this.writesValues.flatMap(d=>d.toFlat(e)),...((a=this.readsValue)==null?void 0:a.toFlat(e))||[],...this.successCalls.flatMap(d=>d.toFlat(e)),...this.errorCalls.flatMap(d=>d.toFlat(e)),...this.inputs.flatMap(d=>d.toFlat(e)),...this.outputs.flatMap(d=>d.toFlat(e)),...this.internalCalls.flatMap(d=>d.toFlat(e))])}toFlatIds(e=new Set){var r;return e.has(this.id)?[]:(e.add(this.id),[this.id,...((r=this.defaultValue)==null?void 0:r.toFlatIds(e))||[],...this.writesValues.flatMap(a=>a.toFlatIds(e)),...this.successCalls.flatMap(a=>a.toFlatIds(e)),...this.errorCalls.flatMap(a=>a.toFlatIds(e)),...this.inputs.flatMap(a=>a.toFlatIds(e)),...this.outputs.flatMap(a=>a.toFlatIds(e)),...this.internalCalls.flatMap(a=>a.toFlatIds(e))])}toJSON(e=new Set){var t,r;return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,declaration:this.declaration.toJSON(e),defaultValue:((t=this.defaultValue)==null?void 0:t.toJSON(e))||null,readsValue:((r=this.readsValue)==null?void 0:r.toReference())||null,writesValues:this.writesValues.map(a=>a.toJSON(e)),inputs:this.inputs.map(a=>a.toJSON(e)),outputs:this.outputs.map(a=>a.toJSON(e)),successCalls:this.successCalls.map(a=>a.toJSON(e)),errorCalls:this.errorCalls.map(a=>a.toJSON(e)),internalCalls:this.internalCalls.map(a=>a.toJSON(e)),calledBySuccess:this.calledBySuccess.map(a=>a.toReference()),calledByError:this.calledByError.map(a=>a.toReference()),calledByEntry:this.calledByEntry.map(a=>a.toReference()),parent:this.parent.toReference(),x:this.x,y:this.y})}toJSONClone(e=Z){var r,a,d,o,l,u,h;let t;return(r=e.seenEntityMaps)!=null&&r.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||ct(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(a=e.seenEntities)!=null&&a.has(t)||(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:I.UUID.uuid(),createdAt:e.timestamp||T().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,defaultValue:((u=this.defaultValue)==null?void 0:u.toJSONClone({...e,newId:null}))||null,declaration:this.declaration.toReference({seenEntityMaps:e.seenEntityMaps}),readsValue:((h=this.readsValue)==null?void 0:h.toReference({seenEntityMaps:e.seenEntityMaps}))||null,writesValues:this.writesValues.map(c=>c.toJSONClone({...e,newId:null})),inputs:this.inputs.map(c=>c.toJSONClone({...e,newId:null})),outputs:this.outputs.map(c=>c.toJSONClone({...e,newId:null})),successCalls:this.successCalls.map(c=>c.toJSONClone({...e,newId:null})),errorCalls:this.errorCalls.map(c=>c.toJSONClone({...e,newId:null})),internalCalls:this.internalCalls.map(c=>this.calledBy.length||this.readsValue?c.toJSONClone({...e,newId:null}):c.toReference({seenEntityMaps:e.seenEntityMaps})),calledBySuccess:this.calledBySuccess.map(c=>c.toReference({seenEntityMaps:e.seenEntityMaps})),calledByError:this.calledByError.map(c=>c.toReference({seenEntityMaps:e.seenEntityMaps})),calledByEntry:this.calledByEntry.map(c=>c.toReference({seenEntityMaps:e.seenEntityMaps})),parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps}),x:this.x,y:this.y})}toReference(e=Z){var r;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+I.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=Z){var r,a,d,o;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,defaultValue:((a=this.defaultValue)==null?void 0:a.toReference(e))||null,declaration:((d=this.declaration)==null?void 0:d.toReference(e))||null,readsValue:((o=this.readsValue)==null?void 0:o.toReference(e))||null,writesValues:this.writesValues.map(l=>l.toReference(e)),inputs:this.inputs.map(l=>l.toReference(e)),outputs:this.outputs.map(l=>l.toReference(e)),successCalls:this.successCalls.map(l=>l.toReference(e)),errorCalls:this.errorCalls.map(l=>l.toReference(e)),calledBySuccess:this.calledBySuccess.map(l=>l.toReference(e)),calledByError:this.calledByError.map(l=>l.toReference(e)),calledByEntry:this.calledByEntry.map(l=>l.toReference(e)),internalCalls:this.internalCalls.map(l=>l.toReference(e)),parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){var r,a;return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...((r=this.defaultValue)==null?void 0:r.toFlatJSON(e))||[],...((a=this.declaration)==null?void 0:a.toFlatJSON(e))||[],...this.writesValues.flatMap(d=>d.toFlatJSON(e)),...this.successCalls.flatMap(d=>d.toFlatJSON(e)),...this.errorCalls.flatMap(d=>d.toFlatJSON(e)),...this.inputs.flatMap(d=>d.toFlatJSON(e)),...this.outputs.flatMap(d=>d.toFlatJSON(e)),...this.internalCalls.flatMap(d=>d.toFlatJSON(e)),...this.calledBy.flatMap(d=>d.toFlatJSON(e))])}toGenerationTarget(){const e=this.parent.type===n.Project?void 0:this.parent.id;return{id:this.id,type:this.type,declaration:this.declaration.id,calledByEntry:this.calledByEntry.map(t=>t.id),calledBySuccess:this.calledBySuccess.map(t=>t.id),calledByError:this.calledByError.map(t=>t.id),parent:e}}toFlatGenerationTarget(e=new Set){var r,a,d;return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...((r=this.defaultValue)==null?void 0:r.toFlatGenerationTarget(e))||[],...((a=this.declaration)==null?void 0:a.toFlatGenerationTarget(e))||[],...((d=this.readsValue)==null?void 0:d.toFlatGenerationTarget(e))||[],...this.writesValues.flatMap(o=>o.toFlatGenerationTarget(e)),...this.successCalls.flatMap(o=>o.toFlatGenerationTarget(e)),...this.errorCalls.flatMap(o=>o.toFlatGenerationTarget(e)),...this.inputs.flatMap(o=>o.toFlatGenerationTarget(e)),...this.outputs.flatMap(o=>o.toFlatGenerationTarget(e)),...this.internalCalls.flatMap(o=>o.toFlatGenerationTarget(e))])}clearErrors(){var e;return this.errors=[],(e=this.defaultValue)==null||e.clearErrors(),this.inputs.forEach(t=>t.clearErrors()),this.outputs.forEach(t=>t.clearErrors()),this.successCalls.forEach(t=>t.clearErrors()),this.errorCalls.forEach(t=>t.clearErrors()),this.internalCalls.forEach(t=>t.clearErrors()),this}validate(){const e=oq(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){var t,r;return[...this.errors,...((t=this.defaultValue)==null?void 0:t.getErrors())||[],...this.inputs.flatMap(a=>a.getErrors()),...this.internalCalls.flatMap(a=>a.getErrors()),...this.outputs.flatMap(a=>a.getErrors()),...((r=this.readsValue)==null?void 0:r.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 R(this.project,"",T().toISOString(),this,!0,"clone-entity")),t=null,r=null,a=!0){var O,w,C,U;let d=ft(t,this);const o=this.toJSON(),l=r||I.UUID.uuid();o.inputs=[],o.id=l,o.version=I.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=lt(o,d);t?u.setParent(t,null):u.setParent(this.parent,null),a&&u.subscribe(),u.initChildren(e),e==null||e.add(u,b.Added);const h=(O=this.defaultValue)==null?void 0:O.clone(e,u,I.UUID.uuid(),a);u.defaultValue=h||null;const c=(w=this.inputs)==null?void 0:w.map(G=>G.clone(e,u,I.UUID.uuid(),a));u.inputs=c;const v=(C=this.outputs)==null?void 0:C.map(G=>G.clone(e,u,I.UUID.uuid(),a));u.outputs=v;const E=(U=this.internalCalls)==null?void 0:U.map(G=>G.clone(e,u,I.UUID.uuid(),a));return u.internalCalls=E,e==null||e.attemptAutoclose("clone-entity",this.id),u}addInternalCall(e){return this.internalCalls.find(t=>t===e)||this.internalCalls.push(e),this}setDeclaration(e){return this.declaration!==e&&(this.declaration=e),this}generateUnusedInputs(e=this.project.addChangeSet(new R(this.project,"",T().toISOString(),this,!0,"generate-unused-inputs"))){const t=[],r=[],a=[],d=[];if(this.declaration.dataType)if(this.declaration.dataType.entity){if([n.DefinitionEntity,n.PrimitiveEntity,n.BuiltInBaseEntity].includes(this.declaration.dataType.entity.type)){const o=[...this.declaration.dataType.entity.properties];o.filter(c=>!c.getDataType(e)).forEach(c=>{const v=this.inputs.find(w=>F(w,this.project)===F(c,this.project));if(!v)return;const E=this.declaration.getMasterInputWithValueWritterFromAllInstances(v);if(!E)return;const O=kr(E);c.setDataType(O),v.setDeclaration(c)}),o.filter(c=>!this.inputs.find(v=>{var E;return((E=v.declaration)==null?void 0:E.id)===c.id})).forEach(c=>{const v={id:I.UUID.uuid(),version:I.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:I.sessionAuthor,previousVersion:null,deleted:!1,type:n.InputMap,parent:this.toReference(),name:null,description:null,declaration:c,defaultValue:null,index:c.index,readsValue:null},E=V(v,this.project);return E.setParent(this,e),E.initChildren(e),e==null||e.add(E,b.Added),E.suggestion=!0,this.addInput(E),E}),this.inputs.filter(c=>!c.declaration).forEach(c=>{const v=o.find(E=>F(E,this.project)===F(c,this.project));v&&c.setDeclaration(v)})}}else return e==null||e.attemptAutoclose("generate-unused-inputs",this.id),{added:[],updated:[],removed:[],affected:[],self:this};else return e==null||e.attemptAutoclose("generate-unused-inputs",this.id),{added:[],updated:[],removed:[],affected:[],self:this};return e==null||e.attemptAutoclose("generate-unused-inputs",this.id),{added:p(t),updated:p(r),removed:p(a),affected:p(d),self:this}}generateUnusedOutputs(e=this.project.addChangeSet(new R(this.project,"",T().toISOString(),this,!0,"generate-unused-outputs"))){const t=[],r=[],a=[],d=[];if(this.declaration.dataType)if(this.declaration.dataType.entity)[n.DefinitionEntity,n.PrimitiveEntity,n.BuiltInBaseEntity].includes(this.declaration.dataType.entity.type)&&[...this.declaration.dataType.entity.properties].filter(u=>!this.outputs.find(h=>h.declaration===u)).map(u=>{const h={id:I.UUID.uuid(),version:I.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:I.sessionAuthor,previousVersion:null,deleted:!1,type:n.OutputMap,parent:this.toReference(),defaultValue:null,declaration:u,index:u.index,writesValues:[]},c=V(h,this.project);return c.setParent(this,e),c.initChildren(e),e==null||e.add(c,b.Added),c.suggestion=!0,this.addOutput(c),c});else return e==null||e.attemptAutoclose("generate-unused-outputs",this.id),{added:[],updated:[],removed:[],affected:[],self:this};else return e==null||e.attemptAutoclose("generate-unused-outputs",this.id),{added:[],updated:[],removed:[],affected:[],self:this};return e==null||e.attemptAutoclose("generate-unused-outputs",this.id),{added:p(t),updated:p(r),removed:p(a),affected:p(d),self:this}}generateUnusedInternalCalls(e=this.project.addChangeSet(new R(this.project,"",T().toISOString(),this,!0,"generate-unused-internal-calls"))){const t=[],r=[],a=[],d=[];if(this.declaration.dataType)if(this.declaration.dataType.entity)[n.DefinitionEntity,n.PrimitiveEntity,n.BuiltInBaseEntity].includes(this.declaration.dataType.entity.type)&&[...this.declaration.dataType.entity.getAllInteractiveMethods()].filter(u=>!this.internalCalls.find(c=>{var E,O,w,C,U;return(((E=c.declaration)==null?void 0:E.id)||((w=(O=c.initialData)==null?void 0:O.declaration)==null?void 0:w.entityId)||((U=(C=c.initialData)==null?void 0:C.declaration)==null?void 0:U.id))===u.id})).map(u=>{const h=u.createInternalCall(this);return e==null||e.add(h,b.Added),h.suggestion=!0,this.addInternalCall(h),h});else return e==null||e.attemptAutoclose("generate-unused-internal-calls",this.id),{added:[],updated:[],removed:[],affected:[],self:this};else return e==null||e.attemptAutoclose("generate-unused-internal-calls",this.id),{added:[],updated:[],removed:[],affected:[],self:this};return e==null||e.attemptAutoclose("generate-unused-internal-calls",this.id),{added:p(t),updated:p(r),removed:p(a),affected:p(d),self:this}}getDataType(e=this.project.addChangeSet(new R(this.project,"",T().toISOString(),this,!0,"get-data-type"))){var t;return((t=this.declaration)==null?void 0:t.getDataType(e))||null}getUnusedInputs(){return this.inputs.filter(e=>e.suggestion||!e.readsValue&&!e.defaultValue)}getUnusedOutputs(){return this.outputs.filter(e=>e.suggestion||!e.writesValues.length)}getUsedInputs(){return this.inputs.filter(e=>!e.suggestion&&(e.readsValue||e.defaultValue))}getUsedOutputs(){return this.outputs.filter(e=>!e.suggestion&&e.writesValues.length)}};f(we,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>e,APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...r)=>null}),f(we,"type",n.VariableInstance),f(we,"USER_MANAGED_PARENT_TYPES",[...mt,n.Project]),f(we,"PARENT_TYPES",[...we.USER_MANAGED_PARENT_TYPES]),f(we,"MUTABLE_BASE_PROPERTIES",[]),f(we,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),f(we,"BASE_PROPERTIES",[...we.MUTABLE_BASE_PROPERTIES,...we.INMUTABLE_BASE_PROPERTIES]),f(we,"MUTABLE_META_PROPERTIES",[...we.MUTABLE_BASE_PROPERTIES,"x","y"]),f(we,"INMUTABLE_META_PROPERTIES",[...we.INMUTABLE_BASE_PROPERTIES]),f(we,"META_PROPERTIES",[...we.MUTABLE_META_PROPERTIES,...we.INMUTABLE_META_PROPERTIES]),f(we,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry","readsValue"]),f(we,"INMUTABLE_UPSTREAM_PROPERTIES",["declaration","parent"]),f(we,"UPSTREAM_PROPERTIES",[...we.MUTABLE_UPSTREAM_PROPERTIES,...we.INMUTABLE_UPSTREAM_PROPERTIES]),f(we,"MUTABLE_DOWNSTREAM_PROPERTIES",["writesValues","inputs","outputs","successCalls","errorCalls","internalCalls"]),f(we,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),f(we,"DOWNSTREAM_PROPERTIES",[...we.MUTABLE_DOWNSTREAM_PROPERTIES,...we.INMUTABLE_DOWNSTREAM_PROPERTIES]),f(we,"PROPERTIES",[...we.META_PROPERTIES,...we.UPSTREAM_PROPERTIES,...we.DOWNSTREAM_PROPERTIES]);let Ui=we;var eO=(i=>(i.Parent="parent",i.DataTypeEntity="data-type-entity",i))(eO||{});const Ve=class Ve extends rt{constructor(e,t){super(e);f(this,"initialData");f(this,"id");f(this,"name");f(this,"description",null);f(this,"required",!1);f(this,"constant",!1);f(this,"x");f(this,"y");f(this,"type",n.VariableDeclaration);f(this,"defaultValue",null);f(this,"dataType",null);f(this,"writesValues",[]);f(this,"readsValue",null);f(this,"inputs",[]);f(this,"outputs",[]);f(this,"calledBySuccess",[]);f(this,"calledByError",[]);f(this,"calledByEntry",[]);f(this,"successCalls",[]);f(this,"errorCalls",[]);f(this,"internalCalls",[]);f(this,"parent");f(this,"errors",[]);f(this,"project");f(this,"detachedDependents",{});f(this,"knownVersions",null);f(this,"activeVersion",!1);f(this,"initialized",!1);f(this,"startedInitialization",!1);f(this,"suggestion",!1);this.initialData=e,this.project=t,this.id=e.id,this.name=e.name,this.description=e.description,this.constant=e.constant,this.required=e.required,this.x=e.x,this.y=e.y}static fromGenerationTarget(e,t){let r=t;if(e.parent){const c=B(e.parent);r=t.get(c)}const a=e.calledByEntry.map(c=>{const v=B(c);return t.get(v)}),d=e.calledBySuccess.map(c=>{const v=B(c);return t.get(v)}),o=e.calledByError.map(c=>{const v=B(c);return t.get(v)});let l=null;if(e.readsValue){const c=B(e.readsValue);l=t.get(c)}const u={id:e.id,version:I.UUID.uuid(),createdAt:T().toISOString(),author:I.sessionAuthor,previousVersion:null,deleted:!1,type:n.VariableDeclaration,name:e.name,defaultValue:null,description:e.description,constant:e.constant||!1,required:e.required||!1,calledByEntry:a,calledBySuccess:d,calledByError:o,dataType:null,errorCalls:[],successCalls:[],internalCalls:[],readsValue:l,inputs:[],outputs:[],writesValues:[],x:0,y:0,parent:r},h=V(u,t);return h.setParent(r,null),h.initChildren(null),h}static validateGenerationTarget(e,t){let r=JSON.parse(JSON.stringify(e));const a=[],d=Et(r,{parent:{list:!1,types:[...mt,n.Project],optional:!0}},t);r=d.modifiedData;const o=mc(r,t);return a.push(...d.errors,...o,...ot(r)),{errors:a,modifiedData:r}}get variableInstances(){const e=[];return Object.values(this.detachedDependents).forEach(t=>{t.field===Dc.VarDeclaration&&!e.includes(t.entity)&&e.push(t.entity)}),e}validateGeneratedUpdate(e){const t=[];let r=JSON.parse(JSON.stringify(e));const a=ws(r,this);return r=a.modifiedData,t.push(...a.errors),e.parent&&t.push(new P({id:`${this.id}--${A.InvalidParentUpdate}`,code:A.InvalidParentUpdate,severity:D.Error,message:`Entity of type '${this.type}' with id '${this.id}' cannot have the 'parent' property updated. The 'parent' on a callable entity, is its scope. It scope is auto-calculated implicitly by the its caller.
|
|
106
|
+
You shouldn't have to manually update a 'parent' property. The equivalent result is to change its value readers, value writters, or callers.`,issue:null})),{errors:t,modifiedData:r}}subscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]||(this.detachedDependents[t.entity.id]=t)}),this}syncDependents(){const e=[],t=[],r=[],a=[];return Object.values(this.detachedDependents).forEach(d=>{const o=d.entity.afterAllChildrenInitialized();e.push(...o.updated),t.push(...o.added),r.push(...o.removed),a.push(...o.affected)}),{updated:p(e),added:p(t),removed:p(r),affected:p(a),self:this}}onDetachedDependencyRemoved(e,t,r){const a=[],d=[],o=[],l=[];if(t==="parent"){const{updated:u,added:h,removed:c}=this.remove({ignoreUpstream:!1},r);a.push(...u),d.push(...h),o.push(...c)}if(t==="var-declaration"){const{updated:u,added:h,removed:c}=this.remove({ignoreUpstream:!1},r);a.push(...u),d.push(...h),o.push(...c)}return{updated:p(a),added:p(d),removed:p(o),affected:p(l),self:this}}onDetachedDependencyRestored(e,t,r){const a=[],d=[],o=[],l=[];if(t==="parent"){const{updated:u,added:h,removed:c}=this.restore({},r);a.push(...u),d.push(...h),o.push(...c)}if(t==="var-declaration"){const{updated:u,added:h,removed:c}=this.restore({},r);a.push(...u),d.push(...h),o.push(...c)}return{updated:p(a),added:p(d),removed:p(o),affected:p(l),self:this}}subscribeToDependencies(){var e,t,r,a;return(e=this.parent)==null||e.subscribeDependents([{entity:this,field:"parent"}]),(a=(r=(t=this.declaration.dataType)==null?void 0:t.entity)==null?void 0:r.subscribeDependents)==null||a.call(r,[{entity:this,field:"data-type-entity"}]),this.declaration.subscribeDependents([{entity:this,field:"var-declaration"}]),this}increaseVersion(e){if(e&&!T(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&T(e).isSame(T(this.createdAt))?this:(this.previousVersion=this.version,this.version=I.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t,r;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new we(this,this.project);return(r=this.knownVersions)==null||r.set(this.version,e),e.inputs=this.inputs,e.outputs=this.outputs,e.internalCalls=this.internalCalls,e.successCalls=this.successCalls,e.errorCalls=this.errorCalls,e.writesValues=this.writesValues,e.readsValue=this.readsValue,e.defaultValue=this.defaultValue,e.declaration=this.declaration,e.calledBySuccess=this.calledBySuccess,e.calledByError=this.calledByError,e.calledByEntry=this.calledByEntry,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],r=[],a=[],d=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),r.push(...o.added),a.push(...o.removed)}return{updated:p(t),added:p(r),removed:p(a),affected:p(d),self:this}}async restoreVersion(e){var l;const t=[],r=[],a=[],d=[];if(this.version===e)return{updated:p(t),added:p(r),removed:p(a),affected:p(d),self:this};if(!this.knownVersions){const u=new Map;for(const[h,c]of this.knownVersions||new Map){if(u.set(h,c),c.activeVersion=!1,c.knownVersions)for(const[v,E]of c.knownVersions)u.set(v,E);c.knownVersions=null}}let o=(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 we(u,this.project)}return this.metaSync(o.toShallowJSON(),null),this.inputs=o.inputs,this.outputs=o.outputs,this.internalCalls=o.internalCalls,this.successCalls=o.successCalls,this.errorCalls=o.errorCalls,this.writesValues=o.writesValues,this.readsValue=o.readsValue,this.defaultValue=o.defaultValue,this.declaration=o.declaration,this.calledBySuccess=o.calledBySuccess,this.calledByError=o.calledByError,this.calledByEntry=o.calledByEntry,this.parent=o.parent,{updated:p(t),added:p(r),removed:p(a),affected:p(d),self:this}}hydrateAncestors(){const e=[],t=[],r=[],a=[];if(this.initialData.parent){const d=B(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 throw new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(this.initialData.readsValue){const d=B(this.initialData.readsValue),o=this.project.get(d);o&&(this.setValueWriter(o),e.push(o))}if(this.initialData.declaration){const d=B(this.initialData.declaration),o=this.project.get(d);o&&(this.setDeclaration(o),e.push(o))}return this.initialData.calledByEntry.forEach(d=>{const o=B(d),l=this.project.get(o);l&&(this.addEntryCaller(l,null),e.push(l))}),this.initialData.calledBySuccess.forEach(d=>{const o=B(d),l=this.project.get(o);l&&(this.addSuccessCaller(l,null),e.push(l))}),this.initialData.calledByError.forEach(d=>{const o=B(d),l=this.project.get(o);l&&(this.addErrorCaller(l,null),e.push(l))}),yi.hydrateReadsValue(this),{updated:p(e),added:p(t),removed:p(r),affected:p(a),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new R(this.project,"",T().toISOString(),this,!0,"after-all-children-initialized"))){var _;const t=[],r=[],a=[],d=[];this.initialized=!0,this.captureVersion();const{added:o,updated:l,removed:u,affected:h}=this.generateUnusedInputs(e);r.push(...o),t.push(...l),a.push(...u),d.push(...h);const{added:c,updated:v,removed:E,affected:O}=this.generateUnusedOutputs(e);r.push(...c),t.push(...v),a.push(...E),d.push(...O);const{added:w,updated:C,removed:U,affected:G}=this.generateUnusedInternalCalls(e);if(r.push(...w),t.push(...C),a.push(...U),d.push(...G),!this.declaration.dataType||(_=this.declaration.dataType)!=null&&_.inferred){const{added:$,updated:k,removed:J,affected:ee}=this.declaration.inferDataTypeAndSyncInstancesInputsAndOutputs(e);r.push(...$),t.push(...k),a.push(...J),d.push(...ee)}return e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:p(t),added:p(r),removed:p(a),affected:p(d),self:this}}addSelfToProject(e=this.project.addChangeSet(new R(this.project,"",T().toISOString(),this,!0,"add-self-to-project"))){const t=[this],r=[],a=[],d=[];return this.parent===this.project&&this.project.addVariableInstance(this),this.readsValue&&(this.readsValue.addValueReader(this),t.push(this.readsValue)),this.writesValues.forEach(o=>{o.setValueWriter(this),t.push(o)}),this.successCalls.forEach(o=>{o.addSuccessCaller(this,e),t.push(o)}),this.errorCalls.forEach(o=>{o.addErrorCaller(this,e),t.push(o)}),this.calledBySuccess.forEach(o=>{o.addSuccessCall(this),t.push(o)}),this.calledByError.forEach(o=>{o.addErrorCall(this),t.push(o)}),this.calledByEntry.forEach(o=>{o.addCall(this),t.push(o)}),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:p(t),added:p(r),removed:p(a),affected:p(d),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}get usedInputs(){return this.inputs.filter(e=>e.readsValue||e.defaultValue)}get unusedInputs(){return this.inputs.filter(e=>!e.readsValue&&!e.defaultValue)}get usedOutputs(){return this.outputs.filter(e=>e.writesValues.length)}get unusedOutputs(){return this.outputs.filter(e=>!e.writesValues.length)}get usedInternalCalls(){return this.internalCalls.filter(e=>!!e.calledBy.length)}get unusedInternalCalls(){const e=this.usedInternalCalls;return this.internalCalls.filter(r=>!(e.find(o=>o.id===r.id)||e.find(o=>o.declaration===r.declaration)))}removeInput(e){const t=this.inputs.findIndex(r=>r.id===e.id);return t>-1&&this.inputs.splice(t,1),this}addInput(e){return this.inputs.includes(e)?this:(this.inputs.push(e),this)}addOutput(e){return this.outputs.includes(e)?this:(this.outputs.push(e),this)}removeOutput(e){const t=this.outputs.findIndex(r=>r.id===e.id);return t>-1&&this.outputs.splice(t,1),this}addSuccessCaller(e,t=this.project.addChangeSet(new R(this.project,"",T().toISOString(),this,!0,"add-success-caller"))){return this.calledBySuccess.find(r=>r.id===e.id)||(this.calledBySuccess.push(e),t&&(t==null||t.add(this,b.Updated),t==null||t.add(e,b.Affected)),t==null||t.attemptAutoclose("add-success-caller",this.id)),this}addErrorCaller(e,t=this.project.addChangeSet(new R(this.project,"",T().toISOString(),this,!0,"add-error-caller"))){return this.calledByError.find(r=>r.id===e.id)||(this.calledByError.push(e),t&&(t==null||t.add(this,b.Updated),t==null||t.add(e,b.Affected)),t==null||t.attemptAutoclose("add-error-caller",this.id)),this}addEntryCaller(e,t=this.project.addChangeSet(new R(this.project,"",T().toISOString(),this,!0,"add-entry-caller"))){return this.calledByEntry.find(r=>r.id===e.id)||(this.calledByEntry.push(e),t&&(t==null||t.add(this,b.Updated),t==null||t.add(e,b.Affected)),t==null||t.attemptAutoclose("add-entry-caller",this.id)),this}addErrorCall(e){return this.errorCalls.find(t=>t.id===e.id)||this.errorCalls.push(e),this}addSuccessCall(e){return this.successCalls.find(t=>t.id===e.id)||this.successCalls.push(e),this}removeCall(e){const t=this.successCalls.findIndex(a=>a.id===e.id);t>-1&&this.successCalls.splice(t,1);const r=this.errorCalls.findIndex(a=>a.id===e.id);return r>-1&&this.errorCalls.splice(r,1),this}removeCaller(e,t=this.project.addChangeSet(new R(this.project,"",T().toISOString(),this,!0,"remove-caller"))){return this.calledBySuccess=this.calledBySuccess.filter(r=>r.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(r,b.Affected)),!0):!1),this.calledByError=this.calledByError.filter(r=>r.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(r,b.Affected)),!0):!1),this.calledByEntry=this.calledByEntry.filter(r=>r.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(r,b.Affected)),!0):!1),t==null||t.attemptAutoclose("remove-caller",this.id),this}addValueReader(e){return this.writesValues.includes(e)?this:(this.writesValues.push(e),this)}setParent(e,t=this.project.addChangeSet(new R(this.project,"",T().toISOString(),this,!0,"set-parent"))){var r;return((r=this.parent)==null?void 0:r.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,b.Updated),t==null||t.attemptAutoclose("set-parent",this.id))),this}initChildren(e=this.project.addChangeSet(new R(this.project,"",T().toISOString(),this,!0,"init-children"))){if(this.initialized||this.startedInitialization)return this;if(this.startedInitialization=!0,this.initialData.defaultValue&&(this.defaultValue=V(this.initialData.defaultValue,this.project),this.defaultValue.setParent(this,null),this.defaultValue.initChildren(e)),this.initialData.declaration.type===n.GenericReference){const t=this.project.findSubscribedInstanceFromReference(this.initialData.declaration);if(!t)return this;this.declaration=t}else this.declaration=V(this.initialData.declaration,this.project),this.declaration.setParent(this.parent,null),this.declaration.initChildren(e);return gs.initWritesValues(this,this.parent),yi.initReadsValue(this),this.initialData.inputs.forEach(t=>{const r=V(t,this.project);return r.setParent(this,null),r.initChildren(e),this.addInput(r),r}),this.initialData.outputs.forEach(t=>{const r=V(t,this.project);return r.setParent(this,null),r.initChildren(e),this.addOutput(r),r}),this.successCalls=this.initialData.successCalls.map(t=>{const r=V(t,this.project);return r.addSuccessCaller(this),[n.BreakStatement,n.ContinueStatement].includes(r.type)?(r.setParent(this.parent.parent,null),r.initChildren(e)):r.type!==n.InternalCall&&(r.setParent(this.parent,null),r.initChildren(e)),r}),this.errorCalls=this.initialData.errorCalls.map(t=>{const r=V(t,this.project);return r.addErrorCaller(this),[n.BreakStatement,n.ContinueStatement].includes(r.type)?(r.setParent(this.parent.parent,null),r.initChildren(e)):r.type!==n.InternalCall&&(r.setParent(this.parent,null),r.initChildren(e)),r}),this.internalCalls=this.initialData.internalCalls.reduce((t,r)=>{if(r.type===n.GenericReference){const a=this.project.findSubscribedInstanceFromReference(r);if(!a)return t;const d=a;return d.setParent(this,null),[...t,d]}else{const a=V(r,this.project);return a.setParent(this,null),a.initChildren(e),[...t,a]}},[]),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this}setValueWriter(e){return this.readsValue=e,this}removeValueWriter(){return this.readsValue=null,this}removeValueReader(e){return this.writesValues=this.writesValues.filter(t=>t.id!==e.id),this}subscribe(){return this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new R(this.project,"",T().toISOString(),this,!0,"sync-meta"))){const r=dt(this,e);return e.deleted===!0&&!this.deleted?t==null||t.add(this,b.Removed):e.deleted===!1&&this.deleted?t==null||t.add(this,b.Added):r&&(t==null||t.add(this,b.Updated)),super.metaSync(e),this.x=e.x||this.x,this.y=e.y||this.y,t==null||t.attemptAutoclose("sync-meta",this.id),this}async APILoad(e=L,...t){return await we.repository.APILoad(this.id,...t),this}async APICreate(e=L,...t){return await we.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=L,...t){return await we.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=L,...t){return await we.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=L,...t){return await we.repository.APIClone(this.id,...t),this}async APILoadVersion(e=L,t,...r){return await we.repository.APILoadVersion(this.id,t,...r)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new R(this.project,"",T().toISOString(),this,!0,"remove-entity"))){const r=[],a=[],d=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(a.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(l=>{const{updated:u,removed:h,added:c}=l.entity.onDetachedDependencyRemoved(this,l.field,t);r.push(...u),a.push(...h),d.push(...c)}),this.defaultValue){const{updated:l,removed:u}=this.defaultValue.remove({ignoreUpstream:!0},t);r.push(...l),a.push(...u)}return this.readsValue&&(r.push(this.readsValue),this.readsValue.removeValueReader(this)),this.writesValues.forEach(l=>{r.push(l),l.readsValue=null}),this.inputs.forEach(l=>{const{updated:u,removed:h}=l.remove({ignoreUpstream:!0},t);r.push(...u),a.push(...h)}),this.outputs.forEach(l=>{const{updated:u,removed:h}=l.remove({ignoreUpstream:!0},t);r.push(...u),a.push(...h)}),this.successCalls.forEach(l=>{r.push(l),l.removeCaller(this)}),this.errorCalls.forEach(l=>{r.push(l),l.removeCaller(this)}),this.internalCalls.forEach(l=>{const{updated:u,removed:h}=l.remove({ignoreUpstream:!0},t);r.push(...u),a.push(...h)}),e||this.calledBy.forEach(l=>{r.push(l),l.removeCall(this)}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:p(d),updated:p(r),removed:p(a),affected:p(o),self:this}}restore({}={},e=this.project.addChangeSet(new R(this.project,"",T().toISOString(),this,!0,"restore-entity"))){const t=[],r=[],a=[],d=[];if(e!=null&&e.hasAdded(this.id))return e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),this.defaultValue){const{updated:o}=this.defaultValue.restore({},e);r.push(...o)}return this.readsValue&&(r.push(this.readsValue),this.readsValue.addValueReader(this)),this.writesValues.forEach(o=>{r.push(o),o.setValueWriter(this)}),this.inputs.forEach(o=>{const{updated:l}=o.restore({},e);r.push(...l)}),this.outputs.forEach(o=>{const{updated:l}=o.restore({},e);r.push(...l)}),this.successCalls.forEach(o=>{r.push(o),o.addSuccessCaller(this)}),this.errorCalls.forEach(o=>{r.push(o),o.addErrorCaller(this)}),this.internalCalls.forEach(o=>{const{updated:l}=o.restore({},e);r.push(...l)}),this.calledBySuccess.forEach(o=>{r.push(o),o.addSuccessCall(this)}),this.calledByError.forEach(o=>{r.push(o),o.addErrorCall(this)}),this.calledByEntry.forEach(o=>{r.push(o),o.addCall(this)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:p(t),updated:p(r),removed:p(a),affected:p(d),self:this}}toFlat(e=new Set){var r,a;return e.has(this.id)?[]:(e.add(this.id),[this,...((r=this.defaultValue)==null?void 0:r.toFlat(e))||[],...this.writesValues.flatMap(d=>d.toFlat(e)),...((a=this.readsValue)==null?void 0:a.toFlat(e))||[],...this.successCalls.flatMap(d=>d.toFlat(e)),...this.errorCalls.flatMap(d=>d.toFlat(e)),...this.inputs.flatMap(d=>d.toFlat(e)),...this.outputs.flatMap(d=>d.toFlat(e)),...this.internalCalls.flatMap(d=>d.toFlat(e))])}toFlatIds(e=new Set){var r;return e.has(this.id)?[]:(e.add(this.id),[this.id,...((r=this.defaultValue)==null?void 0:r.toFlatIds(e))||[],...this.writesValues.flatMap(a=>a.toFlatIds(e)),...this.successCalls.flatMap(a=>a.toFlatIds(e)),...this.errorCalls.flatMap(a=>a.toFlatIds(e)),...this.inputs.flatMap(a=>a.toFlatIds(e)),...this.outputs.flatMap(a=>a.toFlatIds(e)),...this.internalCalls.flatMap(a=>a.toFlatIds(e))])}toJSON(e=new Set){var t,r;return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,declaration:this.declaration.toJSON(e),defaultValue:((t=this.defaultValue)==null?void 0:t.toJSON(e))||null,readsValue:((r=this.readsValue)==null?void 0:r.toReference())||null,writesValues:this.writesValues.map(a=>a.toJSON(e)),inputs:this.inputs.map(a=>a.toJSON(e)),outputs:this.outputs.map(a=>a.toJSON(e)),successCalls:this.successCalls.map(a=>a.toJSON(e)),errorCalls:this.errorCalls.map(a=>a.toJSON(e)),internalCalls:this.internalCalls.map(a=>a.toJSON(e)),calledBySuccess:this.calledBySuccess.map(a=>a.toReference()),calledByError:this.calledByError.map(a=>a.toReference()),calledByEntry:this.calledByEntry.map(a=>a.toReference()),parent:this.parent.toReference(),x:this.x,y:this.y})}toJSONClone(e=Z){var r,a,d,o,l,u,h;let t;return(r=e.seenEntityMaps)!=null&&r.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||ct(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(a=e.seenEntities)!=null&&a.has(t)||(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:I.UUID.uuid(),createdAt:e.timestamp||T().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,defaultValue:((u=this.defaultValue)==null?void 0:u.toJSONClone({...e,newId:null}))||null,declaration:this.declaration.toReference({seenEntityMaps:e.seenEntityMaps}),readsValue:((h=this.readsValue)==null?void 0:h.toReference({seenEntityMaps:e.seenEntityMaps}))||null,writesValues:this.writesValues.map(c=>c.toJSONClone({...e,newId:null})),inputs:this.inputs.map(c=>c.toJSONClone({...e,newId:null})),outputs:this.outputs.map(c=>c.toJSONClone({...e,newId:null})),successCalls:this.successCalls.map(c=>c.toJSONClone({...e,newId:null})),errorCalls:this.errorCalls.map(c=>c.toJSONClone({...e,newId:null})),internalCalls:this.internalCalls.map(c=>this.calledBy.length||this.readsValue?c.toJSONClone({...e,newId:null}):c.toReference({seenEntityMaps:e.seenEntityMaps})),calledBySuccess:this.calledBySuccess.map(c=>c.toReference({seenEntityMaps:e.seenEntityMaps})),calledByError:this.calledByError.map(c=>c.toReference({seenEntityMaps:e.seenEntityMaps})),calledByEntry:this.calledByEntry.map(c=>c.toReference({seenEntityMaps:e.seenEntityMaps})),parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps}),x:this.x,y:this.y})}toReference(e=Z){var r;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+I.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=Z){var r,a,d,o;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,defaultValue:((a=this.defaultValue)==null?void 0:a.toReference(e))||null,declaration:((d=this.declaration)==null?void 0:d.toReference(e))||null,readsValue:((o=this.readsValue)==null?void 0:o.toReference(e))||null,writesValues:this.writesValues.map(l=>l.toReference(e)),inputs:this.inputs.map(l=>l.toReference(e)),outputs:this.outputs.map(l=>l.toReference(e)),successCalls:this.successCalls.map(l=>l.toReference(e)),errorCalls:this.errorCalls.map(l=>l.toReference(e)),calledBySuccess:this.calledBySuccess.map(l=>l.toReference(e)),calledByError:this.calledByError.map(l=>l.toReference(e)),calledByEntry:this.calledByEntry.map(l=>l.toReference(e)),internalCalls:this.internalCalls.map(l=>l.toReference(e)),parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){var r,a;return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...((r=this.defaultValue)==null?void 0:r.toFlatJSON(e))||[],...((a=this.declaration)==null?void 0:a.toFlatJSON(e))||[],...this.writesValues.flatMap(d=>d.toFlatJSON(e)),...this.successCalls.flatMap(d=>d.toFlatJSON(e)),...this.errorCalls.flatMap(d=>d.toFlatJSON(e)),...this.inputs.flatMap(d=>d.toFlatJSON(e)),...this.outputs.flatMap(d=>d.toFlatJSON(e)),...this.internalCalls.flatMap(d=>d.toFlatJSON(e)),...this.calledBy.flatMap(d=>d.toFlatJSON(e))])}toGenerationTarget(){const e=this.parent.type===n.Project?void 0:this.parent.id;return{id:this.id,type:this.type,declaration:this.declaration.id,calledByEntry:this.calledByEntry.map(t=>t.id),calledBySuccess:this.calledBySuccess.map(t=>t.id),calledByError:this.calledByError.map(t=>t.id),parent:e}}toFlatGenerationTarget(e=new Set){var r,a,d;return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...((r=this.defaultValue)==null?void 0:r.toFlatGenerationTarget(e))||[],...((a=this.declaration)==null?void 0:a.toFlatGenerationTarget(e))||[],...((d=this.readsValue)==null?void 0:d.toFlatGenerationTarget(e))||[],...this.writesValues.flatMap(o=>o.toFlatGenerationTarget(e)),...this.successCalls.flatMap(o=>o.toFlatGenerationTarget(e)),...this.errorCalls.flatMap(o=>o.toFlatGenerationTarget(e)),...this.inputs.flatMap(o=>o.toFlatGenerationTarget(e)),...this.outputs.flatMap(o=>o.toFlatGenerationTarget(e)),...this.internalCalls.flatMap(o=>o.toFlatGenerationTarget(e))])}clearErrors(){var e;return this.errors=[],(e=this.defaultValue)==null||e.clearErrors(),this.inputs.forEach(t=>t.clearErrors()),this.outputs.forEach(t=>t.clearErrors()),this.successCalls.forEach(t=>t.clearErrors()),this.errorCalls.forEach(t=>t.clearErrors()),this.internalCalls.forEach(t=>t.clearErrors()),this}validate(){const e=oq(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){var t,r;return[...this.errors,...((t=this.defaultValue)==null?void 0:t.getErrors())||[],...this.inputs.flatMap(a=>a.getErrors()),...this.internalCalls.flatMap(a=>a.getErrors()),...this.outputs.flatMap(a=>a.getErrors()),...((r=this.readsValue)==null?void 0:r.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 R(this.project,"",T().toISOString(),this,!0,"clone-entity")),t=null,r=null,a=!0){var O,w,C,U;let d=ft(t,this);const o=this.toJSON(),l=r||I.UUID.uuid();o.inputs=[],o.id=l,o.version=I.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=lt(o,d);t?u.setParent(t,null):u.setParent(this.parent,null),a&&u.subscribe(),u.initChildren(e),e==null||e.add(u,b.Added);const h=(O=this.defaultValue)==null?void 0:O.clone(e,u,I.UUID.uuid(),a);u.defaultValue=h||null;const c=(w=this.inputs)==null?void 0:w.map(G=>G.clone(e,u,I.UUID.uuid(),a));u.inputs=c;const v=(C=this.outputs)==null?void 0:C.map(G=>G.clone(e,u,I.UUID.uuid(),a));u.outputs=v;const E=(U=this.internalCalls)==null?void 0:U.map(G=>G.clone(e,u,I.UUID.uuid(),a));return u.internalCalls=E,e==null||e.attemptAutoclose("clone-entity",this.id),u}addInternalCall(e){return this.internalCalls.find(t=>t===e)||this.internalCalls.push(e),this}setDeclaration(e){return this.declaration!==e&&(this.declaration=e),this}generateUnusedInputs(e=this.project.addChangeSet(new R(this.project,"",T().toISOString(),this,!0,"generate-unused-inputs"))){const t=[],r=[],a=[],d=[];if(this.declaration.dataType)if(this.declaration.dataType.entity){if([n.DefinitionEntity,n.PrimitiveEntity,n.BuiltInBaseEntity].includes(this.declaration.dataType.entity.type)){const o=[...this.declaration.dataType.entity.properties];o.filter(c=>!c.getDataType(e)).forEach(c=>{const v=this.inputs.find(w=>F(w,this.project)===F(c,this.project));if(!v)return;const E=this.declaration.getMasterInputWithValueWritterFromAllInstances(v);if(!E)return;const O=kr(E);c.setDataType(O),v.setDeclaration(c)}),o.filter(c=>!this.inputs.find(v=>{var E;return((E=v.declaration)==null?void 0:E.id)===c.id})).forEach(c=>{const v={id:I.UUID.uuid(),version:I.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:I.sessionAuthor,previousVersion:null,deleted:!1,type:n.InputMap,parent:this.toReference(),name:null,description:null,declaration:c,defaultValue:null,index:c.index,readsValue:null},E=V(v,this.project);return E.setParent(this,e),E.initChildren(e),e==null||e.add(E,b.Added),E.suggestion=!0,this.addInput(E),E}),this.inputs.filter(c=>!c.declaration).forEach(c=>{const v=o.find(E=>F(E,this.project)===F(c,this.project));v&&c.setDeclaration(v)})}}else return e==null||e.attemptAutoclose("generate-unused-inputs",this.id),{added:[],updated:[],removed:[],affected:[],self:this};else return e==null||e.attemptAutoclose("generate-unused-inputs",this.id),{added:[],updated:[],removed:[],affected:[],self:this};return e==null||e.attemptAutoclose("generate-unused-inputs",this.id),{added:p(t),updated:p(r),removed:p(a),affected:p(d),self:this}}generateUnusedOutputs(e=this.project.addChangeSet(new R(this.project,"",T().toISOString(),this,!0,"generate-unused-outputs"))){const t=[],r=[],a=[],d=[];if(this.declaration.dataType)if(this.declaration.dataType.entity)[n.DefinitionEntity,n.PrimitiveEntity,n.BuiltInBaseEntity].includes(this.declaration.dataType.entity.type)&&[...this.declaration.dataType.entity.properties].filter(u=>!this.outputs.find(h=>h.declaration===u)).map(u=>{const h={id:I.UUID.uuid(),version:I.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:I.sessionAuthor,previousVersion:null,deleted:!1,type:n.OutputMap,parent:this.toReference(),defaultValue:null,declaration:u,index:u.index,writesValues:[]},c=V(h,this.project);return c.setParent(this,e),c.initChildren(e),e==null||e.add(c,b.Added),c.suggestion=!0,this.addOutput(c),c});else return e==null||e.attemptAutoclose("generate-unused-outputs",this.id),{added:[],updated:[],removed:[],affected:[],self:this};else return e==null||e.attemptAutoclose("generate-unused-outputs",this.id),{added:[],updated:[],removed:[],affected:[],self:this};return e==null||e.attemptAutoclose("generate-unused-outputs",this.id),{added:p(t),updated:p(r),removed:p(a),affected:p(d),self:this}}generateUnusedInternalCalls(e=this.project.addChangeSet(new R(this.project,"",T().toISOString(),this,!0,"generate-unused-internal-calls"))){const t=[],r=[],a=[],d=[];if(this.declaration.dataType)if(this.declaration.dataType.entity)[n.DefinitionEntity,n.PrimitiveEntity,n.BuiltInBaseEntity].includes(this.declaration.dataType.entity.type)&&[...this.declaration.dataType.entity.getAllInteractiveMethods()].filter(u=>!this.internalCalls.find(c=>{var E,O,w,C,U;return(((E=c.declaration)==null?void 0:E.id)||((w=(O=c.initialData)==null?void 0:O.declaration)==null?void 0:w.entityId)||((U=(C=c.initialData)==null?void 0:C.declaration)==null?void 0:U.id))===u.id})).map(u=>{const h=u.createInternalCall(e,this);return e==null||e.add(h,b.Added),h.suggestion=!0,this.addInternalCall(h),h});else return e==null||e.attemptAutoclose("generate-unused-internal-calls",this.id),{added:[],updated:[],removed:[],affected:[],self:this};else return e==null||e.attemptAutoclose("generate-unused-internal-calls",this.id),{added:[],updated:[],removed:[],affected:[],self:this};return e==null||e.attemptAutoclose("generate-unused-internal-calls",this.id),{added:p(t),updated:p(r),removed:p(a),affected:p(d),self:this}}getDataType(e=this.project.addChangeSet(new R(this.project,"",T().toISOString(),this,!0,"get-data-type"))){var t;return((t=this.declaration)==null?void 0:t.getDataType(e))||null}getUnusedInputs(){return this.inputs.filter(e=>e.suggestion||!e.readsValue&&!e.defaultValue)}getUnusedOutputs(){return this.outputs.filter(e=>e.suggestion||!e.writesValues.length)}getUsedInputs(){return this.inputs.filter(e=>!e.suggestion&&(e.readsValue||e.defaultValue))}getUsedOutputs(){return this.outputs.filter(e=>!e.suggestion&&e.writesValues.length)}};f(we,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>e,APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...r)=>null}),f(we,"type",n.VariableInstance),f(we,"USER_MANAGED_PARENT_TYPES",[...mt,n.Project]),f(we,"PARENT_TYPES",[...we.USER_MANAGED_PARENT_TYPES]),f(we,"MUTABLE_BASE_PROPERTIES",[]),f(we,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),f(we,"BASE_PROPERTIES",[...we.MUTABLE_BASE_PROPERTIES,...we.INMUTABLE_BASE_PROPERTIES]),f(we,"MUTABLE_META_PROPERTIES",[...we.MUTABLE_BASE_PROPERTIES,"x","y"]),f(we,"INMUTABLE_META_PROPERTIES",[...we.INMUTABLE_BASE_PROPERTIES]),f(we,"META_PROPERTIES",[...we.MUTABLE_META_PROPERTIES,...we.INMUTABLE_META_PROPERTIES]),f(we,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry","readsValue"]),f(we,"INMUTABLE_UPSTREAM_PROPERTIES",["declaration","parent"]),f(we,"UPSTREAM_PROPERTIES",[...we.MUTABLE_UPSTREAM_PROPERTIES,...we.INMUTABLE_UPSTREAM_PROPERTIES]),f(we,"MUTABLE_DOWNSTREAM_PROPERTIES",["writesValues","inputs","outputs","successCalls","errorCalls","internalCalls"]),f(we,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),f(we,"DOWNSTREAM_PROPERTIES",[...we.MUTABLE_DOWNSTREAM_PROPERTIES,...we.INMUTABLE_DOWNSTREAM_PROPERTIES]),f(we,"PROPERTIES",[...we.META_PROPERTIES,...we.UPSTREAM_PROPERTIES,...we.DOWNSTREAM_PROPERTIES]);let Ui=we;var eO=(i=>(i.Parent="parent",i.DataTypeEntity="data-type-entity",i))(eO||{});const Ve=class Ve extends rt{constructor(e,t){super(e);f(this,"initialData");f(this,"id");f(this,"name");f(this,"description",null);f(this,"required",!1);f(this,"constant",!1);f(this,"x");f(this,"y");f(this,"type",n.VariableDeclaration);f(this,"defaultValue",null);f(this,"dataType",null);f(this,"writesValues",[]);f(this,"readsValue",null);f(this,"inputs",[]);f(this,"outputs",[]);f(this,"calledBySuccess",[]);f(this,"calledByError",[]);f(this,"calledByEntry",[]);f(this,"successCalls",[]);f(this,"errorCalls",[]);f(this,"internalCalls",[]);f(this,"parent");f(this,"errors",[]);f(this,"project");f(this,"detachedDependents",{});f(this,"knownVersions",null);f(this,"activeVersion",!1);f(this,"initialized",!1);f(this,"startedInitialization",!1);f(this,"suggestion",!1);this.initialData=e,this.project=t,this.id=e.id,this.name=e.name,this.description=e.description,this.constant=e.constant,this.required=e.required,this.x=e.x,this.y=e.y}static fromGenerationTarget(e,t){let r=t;if(e.parent){const c=B(e.parent);r=t.get(c)}const a=e.calledByEntry.map(c=>{const v=B(c);return t.get(v)}),d=e.calledBySuccess.map(c=>{const v=B(c);return t.get(v)}),o=e.calledByError.map(c=>{const v=B(c);return t.get(v)});let l=null;if(e.readsValue){const c=B(e.readsValue);l=t.get(c)}const u={id:e.id,version:I.UUID.uuid(),createdAt:T().toISOString(),author:I.sessionAuthor,previousVersion:null,deleted:!1,type:n.VariableDeclaration,name:e.name,defaultValue:null,description:e.description,constant:e.constant||!1,required:e.required||!1,calledByEntry:a,calledBySuccess:d,calledByError:o,dataType:null,errorCalls:[],successCalls:[],internalCalls:[],readsValue:l,inputs:[],outputs:[],writesValues:[],x:0,y:0,parent:r},h=V(u,t);return h.setParent(r,null),h.initChildren(null),h}static validateGenerationTarget(e,t){let r=JSON.parse(JSON.stringify(e));const a=[],d=Et(r,{parent:{list:!1,types:[...mt,n.Project],optional:!0}},t);r=d.modifiedData;const o=mc(r,t);return a.push(...d.errors,...o,...ot(r)),{errors:a,modifiedData:r}}get variableInstances(){const e=[];return Object.values(this.detachedDependents).forEach(t=>{t.field===Dc.VarDeclaration&&!e.includes(t.entity)&&e.push(t.entity)}),e}validateGeneratedUpdate(e){const t=[];let r=JSON.parse(JSON.stringify(e));const a=ws(r,this);return r=a.modifiedData,t.push(...a.errors),e.parent&&t.push(new P({id:`${this.id}--${A.InvalidParentUpdate}`,code:A.InvalidParentUpdate,severity:D.Error,message:`Entity of type '${this.type}' with id '${this.id}' cannot have the 'parent' property updated. The 'parent' on a callable entity, is its scope. It scope is auto-calculated implicitly by the its caller.
|
|
107
107
|
If an entity is called by another, they must be in the same scope, which means they have the same parent.
|
|
108
108
|
Specifically for variables, their scope is also calculated from their value readers and value writters.
|
|
109
|
-
You shouldn't have to manually update a 'parent' property. The equivalent result is to change its value readers, value writters, or callers.`,issue:null})),{errors:t,modifiedData:r}}subscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]||(this.detachedDependents[t.entity.id]=t)}),this}syncDependents(){const e=[],t=[],r=[],a=[];return Object.values(this.detachedDependents).forEach(d=>{const o=d.entity.afterAllChildrenInitialized();e.push(...o.updated),t.push(...o.added),r.push(...o.removed),a.push(...o.affected)}),{updated:p(e),added:p(t),removed:p(r),affected:p(a),self:this}}onDetachedDependencyRemoved(e,t,r){const a=[],d=[],o=[],l=[];if(t==="parent"){const{updated:u,added:h,removed:c}=this.remove({ignoreUpstream:!1},r);a.push(...u),d.push(...h),o.push(...c)}return{updated:p(a),added:p(d),removed:p(o),affected:p(l),self:this}}onDetachedDependencyRestored(e,t,r){const a=[],d=[],o=[],l=[];if(t==="parent"){const{updated:u,added:h,removed:c}=this.restore({},r);a.push(...u),d.push(...h),o.push(...c)}return{updated:p(a),added:p(d),removed:p(o),affected:p(l),self:this}}subscribeToDependencies(){var e,t,r,a;return(e=this.parent)==null||e.subscribeDependents([{entity:this,field:"parent"}]),(a=(r=(t=this.dataType)==null?void 0:t.entity)==null?void 0:r.subscribeDependents)==null||a.call(r,[{entity:this,field:"data-type-entity"}]),this}increaseVersion(e){if(e&&!T(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&T(e).isSame(T(this.createdAt))?this:(this.previousVersion=this.version,this.version=I.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t,r;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new Ve(this,this.project);return(r=this.knownVersions)==null||r.set(this.version,e),e.inputs=this.inputs,e.outputs=this.outputs,e.internalCalls=this.internalCalls,e.successCalls=this.successCalls,e.errorCalls=this.errorCalls,e.writesValues=this.writesValues,e.readsValue=this.readsValue,e.defaultValue=this.defaultValue,e.dataType=this.dataType,e.calledBySuccess=this.calledBySuccess,e.calledByError=this.calledByError,e.calledByEntry=this.calledByEntry,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],r=[],a=[],d=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),r.push(...o.added),a.push(...o.removed)}return{updated:p(t),added:p(r),removed:p(a),affected:p(d),self:this}}async restoreVersion(e){var l;const t=[],r=[],a=[],d=[];if(this.version===e)return{updated:p(t),added:p(r),removed:p(a),affected:p(d),self:this};if(!this.knownVersions){const u=new Map;for(const[h,c]of this.knownVersions||new Map){if(u.set(h,c),c.activeVersion=!1,c.knownVersions)for(const[v,E]of c.knownVersions)u.set(v,E);c.knownVersions=null}}let o=(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 Ve(u,this.project)}return this.metaSync(o.toShallowJSON(),null),this.inputs=o.inputs,this.outputs=o.outputs,this.internalCalls=o.internalCalls,this.successCalls=o.successCalls,this.errorCalls=o.errorCalls,this.writesValues=o.writesValues,this.readsValue=o.readsValue,this.defaultValue=o.defaultValue,this.dataType=o.dataType,this.calledBySuccess=o.calledBySuccess,this.calledByError=o.calledByError,this.calledByEntry=o.calledByEntry,this.parent=o.parent,{updated:p(t),added:p(r),removed:p(a),affected:p(d),self:this}}hydrateAncestors(){const e=[],t=[],r=[],a=[];if(this.initialData.parent){const d=B(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 throw new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(this.initialData.readsValue){const d=B(this.initialData.readsValue),o=this.project.get(d);o&&(this.setValueWriter(o),e.push(o))}return this.initialData.calledByEntry.forEach(d=>{const o=B(d),l=this.project.get(o);l&&(this.addEntryCaller(l,null),e.push(l))}),this.initialData.calledBySuccess.forEach(d=>{const o=B(d),l=this.project.get(o);l&&(this.addSuccessCaller(l,null),e.push(l))}),this.initialData.calledByError.forEach(d=>{const o=B(d),l=this.project.get(o);l&&(this.addErrorCaller(l,null),e.push(l))}),yi.hydrateReadsValue(this),{updated:p(e),added:p(t),removed:p(r),affected:p(a),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new R(this.project,"",T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],r=[],a=[],d=[];this.initialized=!0,this.captureVersion();const{added:o,updated:l,removed:u,affected:h}=this.generateUnusedInputs(e);r.push(...o),t.push(...l),a.push(...u),d.push(...h);const{added:c,updated:v,removed:E,affected:O}=this.generateUnusedOutputs(e);r.push(...c),t.push(...v),a.push(...E),d.push(...O);const{added:w,updated:C,removed:U,affected:G}=this.generateUnusedInternalCalls(e);if(r.push(...w),t.push(...C),a.push(...U),d.push(...G),!this.dataType||this.dataType.inferred){const{added:_,updated:$,removed:k,affected:J}=this.inferDataTypeAndSyncInstancesInputsAndOutputs(e);r.push(..._),t.push(...$),a.push(...k),d.push(...J)}return e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:p(t),added:p(r),removed:p(a),affected:p(d),self:this}}addSelfToProject(e=this.project.addChangeSet(new R(this.project,"",T().toISOString(),this,!0,"add-self-to-project"))){const t=[this],r=[],a=[],d=[];return this.parent===this.project&&this.project.addVariableDeclaration(this),this.readsValue&&(this.readsValue.addValueReader(this),t.push(this.readsValue)),this.writesValues.forEach(o=>{o.setValueWriter(this),t.push(o)}),this.successCalls.forEach(o=>{o.addSuccessCaller(this,e),t.push(o)}),this.errorCalls.forEach(o=>{o.addErrorCaller(this,e),t.push(o)}),this.calledBySuccess.forEach(o=>{o.addSuccessCall(this),t.push(o)}),this.calledByError.forEach(o=>{o.addErrorCall(this),t.push(o)}),this.calledByEntry.forEach(o=>{o.addCall(this),t.push(o)}),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:p(t),added:p(r),removed:p(a),affected:p(d),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}get usedInputs(){return this.inputs.filter(e=>e.readsValue||e.defaultValue)}get unusedInputs(){return this.inputs.filter(e=>!e.readsValue&&!e.defaultValue)}get usedOutputs(){return this.outputs.filter(e=>e.writesValues.length)}get unusedOutputs(){return this.outputs.filter(e=>!e.writesValues.length)}get usedInternalCalls(){return this.internalCalls.filter(e=>!!e.calledBy.length)}get unusedInternalCalls(){return this.internalCalls.filter(e=>!e.calledBy.length)}removeInput(e){const t=this.inputs.findIndex(r=>r.id===e.id);return t>-1&&this.inputs.splice(t,1),this}addInput(e){return this.inputs.includes(e)?this:(this.inputs.push(e),this)}addOutput(e){return this.outputs.includes(e)?this:(this.outputs.push(e),this)}removeOutput(e){const t=this.outputs.findIndex(r=>r.id===e.id);return t>-1&&this.outputs.splice(t,1),this}addSuccessCaller(e,t=this.project.addChangeSet(new R(this.project,"",T().toISOString(),this,!0,"add-success-caller"))){return this.calledBySuccess.find(r=>r.id===e.id)||(this.calledBySuccess.push(e),t&&(t==null||t.add(this,b.Updated),t==null||t.add(e,b.Affected)),t==null||t.attemptAutoclose("add-success-caller",this.id)),this}addErrorCaller(e,t=this.project.addChangeSet(new R(this.project,"",T().toISOString(),this,!0,"add-error-caller"))){return this.calledByError.find(r=>r.id===e.id)||(this.calledByError.push(e),t&&(t==null||t.add(this,b.Updated),t==null||t.add(e,b.Affected)),t==null||t.attemptAutoclose("add-error-caller",this.id)),this}addEntryCaller(e,t=this.project.addChangeSet(new R(this.project,"",T().toISOString(),this,!0,"add-entry-caller"))){return this.calledByEntry.find(r=>r.id===e.id)||(this.calledByEntry.push(e),t&&(t==null||t.add(this,b.Updated),t==null||t.add(e,b.Affected)),t==null||t.attemptAutoclose("add-entry-caller",this.id)),this}addErrorCall(e){return this.errorCalls.find(t=>t.id===e.id)||this.errorCalls.push(e),this}addSuccessCall(e){return this.successCalls.find(t=>t.id===e.id)||this.successCalls.push(e),this}removeCall(e){const t=this.successCalls.findIndex(a=>a.id===e.id);t>-1&&this.successCalls.splice(t,1);const r=this.errorCalls.findIndex(a=>a.id===e.id);return r>-1&&this.errorCalls.splice(r,1),this}removeCaller(e,t=this.project.addChangeSet(new R(this.project,"",T().toISOString(),this,!0,"remove-caller"))){return this.calledBySuccess=this.calledBySuccess.filter(r=>r.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(r,b.Affected)),!0):!1),this.calledByError=this.calledByError.filter(r=>r.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(r,b.Affected)),!0):!1),this.calledByEntry=this.calledByEntry.filter(r=>r.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(r,b.Affected)),!0):!1),t==null||t.attemptAutoclose("remove-caller",this.id),this}addValueReader(e){return this.writesValues.includes(e)?this:(this.writesValues.push(e),this)}removeValueReader(e){return this.writesValues=this.writesValues.filter(t=>t.id!==e.id),this}setParent(e,t=this.project.addChangeSet(new R(this.project,"",T().toISOString(),this,!0,"set-parent"))){var r;return((r=this.parent)==null?void 0:r.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,b.Updated),t==null||t.attemptAutoclose("set-parent",this.id))),this}initChildren(e=this.project.addChangeSet(new R(this.project,"",T().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.initialData.defaultValue&&(this.defaultValue=V(this.initialData.defaultValue,this.project),this.defaultValue.setParent(this,null),this.defaultValue.initChildren(e)),this.initialData.dataType&&(this.dataType=V(this.initialData.dataType,this.project),this.dataType.setParent(this,null),this.dataType.initChildren(e)),gs.initWritesValues(this,this.parent),yi.initReadsValue(this),this.successCalls=this.initialData.successCalls.map(t=>{const r=V(t,this.project);return r.addSuccessCaller(this),[n.BreakStatement,n.ContinueStatement].includes(r.type)?(r.setParent(this.parent.parent,null),r.initChildren(e)):r.type!==n.InternalCall&&(r.setParent(this.parent,null),r.initChildren(e)),r}),this.errorCalls=this.initialData.errorCalls.map(t=>{const r=V(t,this.project);return r.addErrorCaller(this),[n.BreakStatement,n.ContinueStatement].includes(r.type)?(r.setParent(this.parent.parent,null),r.initChildren(e)):r.type!==n.InternalCall&&(r.setParent(this.parent,null),r.initChildren(e)),r}),this.initialData.inputs.forEach(t=>{const r=V(t,this.project);return r.setParent(this,null),r.initChildren(e),this.addInput(r),r}),this.initialData.outputs.forEach(t=>{const r=V(t,this.project);return r.setParent(this,null),r.initChildren(e),this.addOutput(r),r}),this.initialData.internalCalls.forEach(t=>{if(t.type===n.GenericReference){const a=this.project.findSubscribedInstanceFromReference(t);if(!a)return;a.setParent(this,null),a.initChildren(e),this.addInternalCall(a);return}const r=V(t,this.project);return r.setParent(this,null),r.initChildren(e),this.addInternalCall(r),r}),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this)}setValueWriter(e){return this.readsValue=e,this}removeValueWriter(){return this.readsValue=null,this}subscribe(){return this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}getMasterInputWithValueWritterFromAllInstances(e){return p([...this.inputs,...this.variableInstances.flatMap(a=>a.inputs)]).find(a=>F(a,this.project)===F(e,this.project)&&!!a.readsValue)||e}inferDataTypeAndSyncInstancesInputsAndOutputs(e=this.project.addChangeSet(new R(this.project,"",T().toISOString(),this,!0,"infer-data-type-and-sync-instances-inputs-and-outputs"))){var U,G,_,$;const t=[],r=[],a=[],d=[];if(!this.dataType){const k=V({id:I.UUID.uuid(),version:I.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:I.sessionAuthor,previousVersion:null,deleted:!1,type:n.DataType,isList:!1,andChildrenGroup:null,orChildrenGroup:null,asType:!1,entity:null,like:!0,inferred:!0,parent:this.toReference()},this.project);this.setDataType(k),k.setParent(this,e),k.initChildren(e),e==null||e.add(k,b.Added),k.metaSync({inferred:!0,like:!0},e)}if(this.readsValue){const k=(U=this.readsValue.getDataType(e))==null?void 0:U.clone(e);if(k){const J=(G=this.dataType)==null?void 0:G.merge(k,e);this.dataType&&(J==null?void 0:J.self.id)!==this.dataType.id&&this.dataType.remove({ignoreUpstream:!1},e),k.id!==((_=J==null?void 0:J.self)==null?void 0:_.id)&&k.remove({ignoreUpstream:!1},e),J!=null&&J.self&&(J.self.metaSync({inferred:!0,like:!0},e),e==null||e.add(J.self,b.Added),this.setDataType(J.self))}return e==null||e.attemptAutoclose("infer-data-type-and-sync-instances-inputs-and-outputs",this.id),{updated:p(r),added:p(t),removed:p(a),affected:p(d),self:this}}const o=p([...this.inputs,...this.variableInstances.flatMap(k=>k.inputs)]),l=[];if(o.forEach(k=>{l.find(ee=>F(ee,this.project)===F(k,this.project))||l.push(k)}),!l.length)return e==null||e.attemptAutoclose("infer-data-type-and-sync-instances-inputs-and-outputs",this.id),{updated:p(r),added:p(t),removed:p(a),affected:p(d),self:this};if(($=this.dataType)==null||$.inferFromInputs(l,e),!this.dataType)return e==null||e.attemptAutoclose("infer-data-type-and-sync-instances-inputs-and-outputs",this.id),{updated:p(r),added:p(t),removed:p(a),affected:p(d),self:this};const{updated:u,added:h,removed:c,affected:v}=this.generateUnusedInputs(e);t.push(...h),r.push(...u),a.push(...c),d.push(...v);const{updated:E,added:O,removed:w,affected:C}=this.generateUnusedOutputs(e);return t.push(...O),r.push(...E),a.push(...w),d.push(...C),this.variableInstances.forEach(k=>{const{updated:J,added:ee,removed:pe,affected:Te}=k.generateUnusedInputs(e);t.push(...ee),r.push(...J),a.push(...pe),d.push(...Te);const{updated:K,added:se,removed:Ht,affected:Yr}=k.generateUnusedOutputs(e);t.push(...se),r.push(...K),a.push(...Ht),d.push(...Yr)}),e==null||e.attemptAutoclose("infer-data-type-and-sync-instances-inputs-and-outputs",this.id),{updated:p(r),added:p(t),removed:p(a),affected:p(d),self:this}}metaSync(e,t=this.project.addChangeSet(new R(this.project,"",T().toISOString(),this,!0,"sync-meta"))){const r=dt(this,e);return e.deleted===!0&&!this.deleted?t==null||t.add(this,b.Removed):e.deleted===!1&&this.deleted?t==null||t.add(this,b.Added):r&&(t==null||t.add(this,b.Updated)),super.metaSync(e),this.name=e.name||this.name,this.description=e.description||this.description,this.x=e.x||this.x,this.y=e.y||this.y,this.constant=e.constant!==void 0?e.constant:this.constant,this.required=e.required!==void 0?e.required:this.required,t==null||t.attemptAutoclose("sync-meta",this.id),this}async APILoad(e=L,...t){return await Ve.repository.APILoad(this.id,...t),this}async APICreate(e=L,...t){return await Ve.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=L,...t){return await Ve.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=L,...t){return await Ve.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=L,...t){return await Ve.repository.APIClone(this.id,...t),this}async APILoadVersion(e=L,t,...r){return await Ve.repository.APILoadVersion(this.id,t,...r)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new R(this.project,"",T().toISOString(),this,!0,"remove-entity"))){const r=[],a=[],d=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(a.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(l=>{const{updated:u,removed:h,added:c}=l.entity.onDetachedDependencyRemoved(this,l.field,t);r.push(...u),a.push(...h),d.push(...c)}),this.defaultValue){const{updated:l,removed:u}=this.defaultValue.remove({ignoreUpstream:!0},t);r.push(...l),a.push(...u)}if(this.readsValue&&(r.push(this.readsValue),this.readsValue.removeValueReader(this)),this.writesValues.forEach(l=>{r.push(l),l.readsValue=null}),this.inputs.forEach(l=>{const{updated:u,removed:h}=l.remove({ignoreUpstream:!0},t);r.push(...u),a.push(...h)}),this.outputs.forEach(l=>{const{updated:u,removed:h}=l.remove({ignoreUpstream:!0},t);r.push(...u),a.push(...h)}),this.successCalls.forEach(l=>{r.push(l),l.removeCaller(this)}),this.errorCalls.forEach(l=>{r.push(l),l.removeCaller(this)}),this.internalCalls.forEach(l=>{const{updated:u,removed:h}=l.remove({ignoreUpstream:!0},t);r.push(...u),a.push(...h)}),this.dataType){const{updated:l,removed:u}=this.dataType.remove({ignoreUpstream:!0},t);r.push(...l),a.push(...u)}return e||this.calledBy.forEach(l=>{r.push(l),l.removeCall(this)}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:p(d),updated:p(r),removed:p(a),affected:p(o),self:this}}restore({}={},e=this.project.addChangeSet(new R(this.project,"",T().toISOString(),this,!0,"restore-entity"))){const t=[],r=[],a=[],d=[];if(e!=null&&e.hasAdded(this.id))return e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),this.defaultValue){const{updated:o}=this.defaultValue.restore({},e);r.push(...o)}if(this.readsValue&&(r.push(this.readsValue),this.readsValue.addValueReader(this)),this.writesValues.forEach(o=>{r.push(o),o.setValueWriter(this)}),this.inputs.forEach(o=>{const{updated:l}=o.restore({},e);r.push(...l)}),this.outputs.forEach(o=>{const{updated:l}=o.restore({},e);r.push(...l)}),this.successCalls.forEach(o=>{r.push(o),o.addSuccessCaller(this)}),this.errorCalls.forEach(o=>{r.push(o),o.addErrorCaller(this)}),this.internalCalls.forEach(o=>{const{updated:l}=o.restore({},e);r.push(...l)}),this.dataType){const{updated:o}=this.dataType.restore({},e);r.push(...o)}return this.calledBySuccess.forEach(o=>{r.push(o),o.addSuccessCall(this)}),this.calledByError.forEach(o=>{r.push(o),o.addErrorCall(this)}),this.calledByEntry.forEach(o=>{r.push(o),o.addCall(this)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:p(t),updated:p(r),removed:p(a),affected:p(d),self:this}}toFlat(e=new Set){var r,a,d;return e.has(this.id)?[]:(e.add(this.id),[this,...((r=this.defaultValue)==null?void 0:r.toFlat(e))||[],...((a=this.dataType)==null?void 0:a.toFlat(e))||[],...((d=this.readsValue)==null?void 0:d.toFlat(e))||[],...this.writesValues.flatMap(o=>o.toFlat(e)),...this.successCalls.flatMap(o=>o.toFlat(e)),...this.errorCalls.flatMap(o=>o.toFlat(e)),...this.inputs.flatMap(o=>o.toFlat(e)),...this.outputs.flatMap(o=>o.toFlat(e)),...this.internalCalls.flatMap(o=>o.toFlat(e)),...this.calledBy.flatMap(o=>o.toFlat(e))])}toFlatIds(e=new Set){var r,a;return e.has(this.id)?[]:(e.add(this.id),[this.id,...((r=this.defaultValue)==null?void 0:r.toFlatIds(e))||[],...((a=this.dataType)==null?void 0:a.toFlatIds(e))||[],...this.writesValues.flatMap(d=>d.toFlatIds(e)),...this.successCalls.flatMap(d=>d.toFlatIds(e)),...this.errorCalls.flatMap(d=>d.toFlatIds(e)),...this.inputs.flatMap(d=>d.toFlatIds(e)),...this.outputs.flatMap(d=>d.toFlatIds(e)),...this.internalCalls.flatMap(d=>d.toFlatIds(e))])}toJSON(e=new Set){var t,r,a;return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,constant:this.constant,required:this.required,defaultValue:((t=this.defaultValue)==null?void 0:t.toJSON(e))||null,dataType:((r=this.dataType)==null?void 0:r.toJSON(e))||null,readsValue:((a=this.readsValue)==null?void 0:a.toReference())||null,writesValues:this.writesValues.map(d=>d.toJSON(e)),inputs:this.inputs.map(d=>d.toJSON(e)),outputs:this.outputs.map(d=>d.toJSON(e)),successCalls:this.successCalls.map(d=>d.toJSON(e)),errorCalls:this.errorCalls.map(d=>d.toJSON(e)),internalCalls:this.internalCalls.map(d=>d.toJSON(e)),calledBySuccess:this.calledBySuccess.map(d=>d.toReference()),calledByError:this.calledByError.map(d=>d.toReference()),calledByEntry:this.calledByEntry.map(d=>d.toReference()),parent:this.parent.toReference(),x:this.x,y:this.y})}toJSONClone(e=Z){var r,a,d,o,l,u,h,c;let t;return(r=e.seenEntityMaps)!=null&&r.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||ct(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(a=e.seenEntities)!=null&&a.has(t)||(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:I.UUID.uuid(),createdAt:e.timestamp||T().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,defaultValue:((u=this.defaultValue)==null?void 0:u.toJSONClone({...e,newId:null}))||null,dataType:((h=this.dataType)==null?void 0:h.toJSONClone({...e,newId:null}))||null,readsValue:((c=this.readsValue)==null?void 0:c.toReference({seenEntityMaps:e.seenEntityMaps}))||null,writesValues:this.writesValues.map(v=>v.toJSONClone({...e,newId:null})),inputs:this.inputs.map(v=>v.toJSONClone({...e,newId:null})),outputs:this.outputs.map(v=>v.toJSONClone({...e,newId:null})),successCalls:this.successCalls.map(v=>v.toJSONClone({...e,newId:null})),errorCalls:this.errorCalls.map(v=>v.toJSONClone({...e,newId:null})),internalCalls:this.internalCalls.map(v=>this.calledBy.length||this.readsValue?v.toJSONClone({...e,newId:null}):v.toReference({seenEntityMaps:e.seenEntityMaps})),calledBySuccess:this.calledBySuccess.map(v=>v.toReference({seenEntityMaps:e.seenEntityMaps})),calledByError:this.calledByError.map(v=>v.toReference({seenEntityMaps:e.seenEntityMaps})),calledByEntry:this.calledByEntry.map(v=>v.toReference({seenEntityMaps:e.seenEntityMaps})),parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps}),x:this.x,y:this.y})}toReference(e=Z){var r;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+I.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=Z){var r,a,d,o;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,required:this.required,constant:this.constant,x:this.x,y:this.y,defaultValue:((a=this.defaultValue)==null?void 0:a.toReference(e))||null,dataType:((d=this.dataType)==null?void 0:d.toReference(e))||null,readsValue:((o=this.readsValue)==null?void 0:o.toReference(e))||null,writesValues:this.writesValues.map(l=>l.toReference(e)),inputs:this.inputs.map(l=>l.toReference(e)),outputs:this.outputs.map(l=>l.toReference(e)),successCalls:this.successCalls.map(l=>l.toReference(e)),errorCalls:this.errorCalls.map(l=>l.toReference(e)),calledBySuccess:this.calledBySuccess.map(l=>l.toReference(e)),calledByError:this.calledByError.map(l=>l.toReference(e)),calledByEntry:this.calledByEntry.map(l=>l.toReference(e)),internalCalls:this.internalCalls.map(l=>l.toReference(e)),parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){var r,a;return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...((r=this.defaultValue)==null?void 0:r.toFlatJSON(e))||[],...((a=this.dataType)==null?void 0:a.toFlatJSON(e))||[],...this.writesValues.flatMap(d=>d.toFlatJSON(e)),...this.successCalls.flatMap(d=>d.toFlatJSON(e)),...this.errorCalls.flatMap(d=>d.toFlatJSON(e)),...this.inputs.flatMap(d=>d.toFlatJSON(e)),...this.outputs.flatMap(d=>d.toFlatJSON(e)),...this.internalCalls.flatMap(d=>d.toFlatJSON(e))])}toGenerationTarget(){const e=this.parent.type===n.Project?void 0:this.parent.id;return{id:this.id,type:this.type,name:this.name,description:this.description,calledByEntry:this.calledByEntry.map(t=>t.id),calledBySuccess:this.calledBySuccess.map(t=>t.id),calledByError:this.calledByError.map(t=>t.id),parent:e}}toFlatGenerationTarget(e=new Set){var r,a;return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...((r=this.defaultValue)==null?void 0:r.toFlatGenerationTarget(e))||[],...((a=this.dataType)==null?void 0:a.toFlatGenerationTarget(e))||[],...this.writesValues.flatMap(d=>d.toFlatGenerationTarget(e)),...this.successCalls.flatMap(d=>d.toFlatGenerationTarget(e)),...this.errorCalls.flatMap(d=>d.toFlatGenerationTarget(e)),...this.inputs.flatMap(d=>d.toFlatGenerationTarget(e)),...this.outputs.flatMap(d=>d.toFlatGenerationTarget(e)),...this.internalCalls.flatMap(d=>d.toFlatGenerationTarget(e))])}clearErrors(){var e,t;return this.errors=[],this.inputs.forEach(r=>r.clearErrors()),this.outputs.forEach(r=>r.clearErrors()),this.successCalls.forEach(r=>r.clearErrors()),this.errorCalls.forEach(r=>r.clearErrors()),this.internalCalls.forEach(r=>r.clearErrors()),(e=this.dataType)==null||e.clearErrors(),(t=this.defaultValue)==null||t.clearErrors(),this}validate(){const e=sq(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){var t,r,a;return[...this.errors,...((t=this.defaultValue)==null?void 0:t.getErrors())||[],...((r=this.dataType)==null?void 0:r.getErrors())||[],...this.inputs.flatMap(d=>d.getErrors()),...this.internalCalls.flatMap(d=>d.getErrors()),...this.outputs.flatMap(d=>d.getErrors()),...((a=this.readsValue)==null?void 0:a.getErrors())||[]]}getShallowErrors(){return this.errors}getDefaultValue(){return this.defaultValue||null}setDefaultValue(e){return this.defaultValue=e,this}clone(e=this.project.addChangeSet(new R(this.project,"",T().toISOString(),this,!0,"clone-entity")),t=null,r=null,a=!0){var w,C,U,G,_;let d=ft(t,this);const o=this.toJSON(),l=r||I.UUID.uuid();o.inputs=[],o.id=l,o.version=I.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=lt(o,d);t?u.setParent(t,null):u.setParent(this.parent,null),a&&u.subscribe(),u.initChildren(e),e==null||e.add(u,b.Added);const h=(w=this.dataType)==null?void 0:w.clone(e,u,I.UUID.uuid(),a);u.dataType=h||null;const c=(C=this.defaultValue)==null?void 0:C.clone(e,u,I.UUID.uuid(),a);u.defaultValue=c||null;const v=(U=this.inputs)==null?void 0:U.map($=>$.clone(e,u,I.UUID.uuid(),a));u.inputs=v;const E=(G=this.outputs)==null?void 0:G.map($=>$.clone(e,u,I.UUID.uuid(),a));u.outputs=E;const O=(_=this.internalCalls)==null?void 0:_.map($=>$.clone(e,u,I.UUID.uuid(),a));return u.internalCalls=O,e==null||e.attemptAutoclose("clone-entity",this.id),u}addInternalCall(e){return this.internalCalls.find(t=>t===e)||this.internalCalls.push(e),this}createInstance(e=this.project,t=this.project.addChangeSet(new R(this.project,"",T().toISOString(),this,!0,"create-instance")),r={}){const a={id:r.id||I.UUID.uuid(),version:r.version||I.UUID.uuid(),createdAt:(t==null?void 0:t.timestamp)||T().toISOString(),author:I.sessionAuthor,previousVersion:null,deleted:!1,type:n.VariableInstance,parent:e.toReference(),defaultValue:r.defaultValue||null,successCalls:r.successCalls||[],errorCalls:r.errorCalls||[],inputs:r.inputs||[],outputs:r.outputs||[],writesValues:r.writesValues||[],internalCalls:r.internalCalls||[],readsValue:r.readsValue||null,calledByEntry:r.calledByEntry||[],calledBySuccess:r.calledBySuccess||[],calledByError:r.calledByError||[],declaration:this.toJSON(),x:0,y:0},d=V(a,this.project);return d.setParent(e,null),d.initChildren(null),t==null||t.add(d,b.Added),e===this.project&&this.project.addVariableInstance(d),t==null||t.attemptAutoclose("create-instance",this.id),d}generateUnusedInputs(e=this.project.addChangeSet(new R(this.project,"",T().toISOString(),this,!0,"generate-unused-inputs"))){const t=[],r=[],a=[],d=[];if(this.dataType)if(this.dataType.entity){if([n.DefinitionEntity,n.PrimitiveEntity,n.BuiltInBaseEntity].includes(this.dataType.entity.type)){const o=[...this.dataType.entity.properties];o.filter(c=>!c.getDataType(e)).forEach(c=>{const v=this.inputs.find(w=>F(w,this.project)===F(c,this.project));if(!v)return;const E=this.getMasterInputWithValueWritterFromAllInstances(v);if(!E)return;const O=kr(E);c.setDataType(O),v.setDeclaration(c)}),o.filter(c=>!this.inputs.find(v=>{var E;return((E=v.declaration)==null?void 0:E.id)===c.id})).forEach(c=>{const v={id:I.UUID.uuid(),version:I.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:I.sessionAuthor,previousVersion:null,deleted:!1,type:n.InputMap,parent:this.toReference(),name:null,description:null,declaration:c,defaultValue:null,index:c.index,readsValue:null},E=V(v,this.project);return E.setParent(this,e),E.initChildren(e),e==null||e.add(E,b.Added),E.suggestion=!0,this.addInput(E),E}),this.inputs.filter(c=>!c.declaration).forEach(c=>{const v=o.find(E=>F(E,this.project)===F(c,this.project));v&&c.setDeclaration(v)})}}else return e==null||e.attemptAutoclose("generate-unused-inputs",this.id),{added:[],updated:[],removed:[],affected:[],self:this};else return e==null||e.attemptAutoclose("generate-unused-inputs",this.id),{added:[],updated:[],removed:[],affected:[],self:this};return e==null||e.attemptAutoclose("generate-unused-inputs",this.id),{added:p(t),updated:p(r),removed:p(a),affected:p(d),self:this}}generateUnusedOutputs(e=this.project.addChangeSet(new R(this.project,"",T().toISOString(),this,!0,"generate-unused-outputs"))){const t=[],r=[],a=[],d=[];if(this.dataType)if(this.dataType.entity)[n.DefinitionEntity,n.PrimitiveEntity,n.BuiltInBaseEntity].includes(this.dataType.entity.type)&&[...this.dataType.entity.properties].filter(u=>!this.outputs.find(h=>h.declaration===u)).map(u=>{const h={id:I.UUID.uuid(),version:I.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:I.sessionAuthor,previousVersion:null,deleted:!1,type:n.OutputMap,defaultValue:null,parent:this.toReference(),declaration:u,index:u.index,writesValues:[]},c=V(h,this.project);return c.setParent(this,e),c.initChildren(e),e==null||e.add(c,b.Added),c.suggestion=!0,this.addOutput(c),c});else return e==null||e.attemptAutoclose("generate-unused-outputs",this.id),{added:[],updated:[],removed:[],affected:[],self:this};else return e==null||e.attemptAutoclose("generate-unused-outputs",this.id),{added:[],updated:[],removed:[],affected:[],self:this};return e==null||e.attemptAutoclose("generate-unused-outputs",this.id),{added:p(t),updated:p(r),removed:p(a),affected:p(d),self:this}}generateUnusedInternalCalls(e=this.project.addChangeSet(new R(this.project,"",T().toISOString(),this,!0,"generate-unused-internal-calls"))){const t=[],r=[],a=[],d=[];if(this.dataType)if(this.dataType.entity)[n.DefinitionEntity,n.PrimitiveEntity,n.BuiltInBaseEntity].includes(this.dataType.entity.type)&&[...this.dataType.entity.getAllInteractiveMethods()].filter(u=>!this.internalCalls.find(c=>{var E,O,w,C,U;return(((E=c.declaration)==null?void 0:E.id)||((w=(O=c.initialData)==null?void 0:O.declaration)==null?void 0:w.entityId)||((U=(C=c.initialData)==null?void 0:C.declaration)==null?void 0:U.id))===u.id})).map(u=>{const h=u.createInternalCall(this);return e==null||e.add(h,b.Added),h.suggestion=!0,this.addInternalCall(h),h});else return e==null||e.attemptAutoclose("generate-unused-internal-calls",this.id),{added:[],updated:[],removed:[],affected:[],self:this};else return e==null||e.attemptAutoclose("generate-unused-internal-calls",this.id),{added:[],updated:[],removed:[],affected:[],self:this};return e==null||e.attemptAutoclose("generate-unused-internal-calls",this.id),{added:p(t),updated:p(r),removed:p(a),affected:p(d),self:this}}setDataType(e){return this.dataType=e,this}removeDataType(){return this.dataType=null,this}getDataType(e=this.project.addChangeSet(new R(this.project,"",T().toISOString(),this,!0,"get-data-type"))){return(!this.dataType||this.dataType.inferred)&&this.inferDataTypeAndSyncInstancesInputsAndOutputs(e),this.dataType||null}getUnusedInputs(){return this.inputs.filter(e=>e.suggestion||!e.readsValue&&!e.defaultValue)}getUnusedOutputs(){return this.outputs.filter(e=>e.suggestion||!e.writesValues.length)}getUsedInputs(){return this.inputs.filter(e=>!e.suggestion&&(e.readsValue||e.defaultValue))}getUsedOutputs(){return this.outputs.filter(e=>!e.suggestion&&e.writesValues.length)}};f(Ve,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>e,APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...r)=>null}),f(Ve,"type",n.VariableDeclaration),f(Ve,"USER_MANAGED_PARENT_TYPES",[...mt,n.Project]),f(Ve,"PARENT_TYPES",[...Ve.USER_MANAGED_PARENT_TYPES]),f(Ve,"MUTABLE_BASE_PROPERTIES",["name","description"]),f(Ve,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),f(Ve,"BASE_PROPERTIES",[...Ve.MUTABLE_BASE_PROPERTIES,...Ve.INMUTABLE_BASE_PROPERTIES]),f(Ve,"MUTABLE_META_PROPERTIES",[...Ve.MUTABLE_BASE_PROPERTIES,"x","y"]),f(Ve,"INMUTABLE_META_PROPERTIES",[...Ve.INMUTABLE_BASE_PROPERTIES]),f(Ve,"META_PROPERTIES",[...Ve.MUTABLE_META_PROPERTIES,...Ve.INMUTABLE_META_PROPERTIES]),f(Ve,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry","readsValue"]),f(Ve,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","dataType"]),f(Ve,"UPSTREAM_PROPERTIES",[...Ve.MUTABLE_UPSTREAM_PROPERTIES,...Ve.INMUTABLE_UPSTREAM_PROPERTIES]),f(Ve,"MUTABLE_DOWNSTREAM_PROPERTIES",["writesValues","inputs","outputs","successCalls","errorCalls","internalCalls"]),f(Ve,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),f(Ve,"DOWNSTREAM_PROPERTIES",[...Ve.MUTABLE_DOWNSTREAM_PROPERTIES,...Ve.INMUTABLE_DOWNSTREAM_PROPERTIES]),f(Ve,"PROPERTIES",[...Ve.META_PROPERTIES,...Ve.UPSTREAM_PROPERTIES,...Ve.DOWNSTREAM_PROPERTIES]);let $i=Ve;function dq(i){var d;const s=e3(),e=i.toJSON();s.safeParse(e).success,i.inputsDeclarations.forEach(o=>o.validate()),i.inputs.forEach(o=>o.validate()),i.outputsDeclarations.forEach(o=>o.validate()),i.outputs.forEach(o=>o.validate()),(d=i.error)==null||d.validate();const a=[...fi(i)];if(i.id==="search-person-by-id-id"){const o=ye({id:`${i.id}--${q.PropertyImplementsNonAbstact}`,message:`Property "${F(i,i.project)}" with id "${i.id}" implements a non-abstract property "${F(i,i.project)}" with id "${i.id}".`,issue:null,severity:D.Error,code:q.PropertyImplementsNonAbstact,entity:i});a.push(o.error)}return ze(i.errors,a)}var tO=(i=>(i.Parent="parent",i))(tO||{});const Ze=class Ze extends rt{constructor(e,t){super(e);f(this,"initialData");f(this,"id");f(this,"name");f(this,"description",null);f(this,"x");f(this,"y");f(this,"query","");f(this,"type",n.Search);f(this,"successCalls",[]);f(this,"errorCalls",[]);f(this,"inputsDeclarations",[]);f(this,"inputs",[]);f(this,"outputsDeclarations",[]);f(this,"outputs",[]);f(this,"calledBySuccess",[]);f(this,"calledByError",[]);f(this,"calledByEntry",[]);f(this,"error",null);f(this,"parent");f(this,"errors",[]);f(this,"project");f(this,"detachedDependents",{});f(this,"knownVersions",null);f(this,"activeVersion",!1);f(this,"initialized",!1);f(this,"startedInitialization",!1);this.initialData=e,this.project=t,this.id=e.id,this.x=e.x,this.y=e.y,this.name=e.name,this.query=e.query,this.description=e.description}static fromGenerationTarget(e,t){let r=t;if(e.parent){const h=B(e.parent);r=t.get(h)}const a=e.calledByEntry.map(h=>{const c=B(h);return t.get(c)}),d=e.calledBySuccess.map(h=>{const c=B(h);return t.get(c)}),o=e.calledByError.map(h=>{const c=B(h);return t.get(c)}),l={id:e.id,version:I.UUID.uuid(),createdAt:T().toISOString(),author:I.sessionAuthor,previousVersion:null,deleted:!1,type:n.Search,name:e.name,description:e.description,query:e.query,calledByEntry:a,calledBySuccess:d,calledByError:o,errorCalls:[],successCalls:[],inputsDeclarations:[],inputs:[],outputsDeclarations:[],outputs:[],error:null,x:0,y:0,parent:r},u=V(l,t);return u.setParent(r,null),u.initChildren(null),u}static validateGenerationTarget(e,t){let r=JSON.parse(JSON.stringify(e));const a=[],d=Et(r,{parent:{list:!1,types:[...mt,n.Project],optional:!0}},t);return r=d.modifiedData,a.push(...d.errors,...ot(r)),{errors:a,modifiedData:r}}get resultsAsList(){const e=this.outputsDeclarations[0];if(e){const t=e.getDataType(null);return t?t.isList===!0:!0}return!0}validateGeneratedUpdate(e){const t=[];return e.parent&&t.push(new P({id:`${this.id}--${A.InvalidParentUpdate}`,code:A.InvalidParentUpdate,severity:D.Error,message:`Entity of type '${this.type}' with id '${this.id}' cannot have the 'parent' property updated. The 'parent' on a callable entity, is its scope. It scope is auto-calculated implicitly by the its caller.
|
|
109
|
+
You shouldn't have to manually update a 'parent' property. The equivalent result is to change its value readers, value writters, or callers.`,issue:null})),{errors:t,modifiedData:r}}subscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]||(this.detachedDependents[t.entity.id]=t)}),this}syncDependents(){const e=[],t=[],r=[],a=[];return Object.values(this.detachedDependents).forEach(d=>{const o=d.entity.afterAllChildrenInitialized();e.push(...o.updated),t.push(...o.added),r.push(...o.removed),a.push(...o.affected)}),{updated:p(e),added:p(t),removed:p(r),affected:p(a),self:this}}onDetachedDependencyRemoved(e,t,r){const a=[],d=[],o=[],l=[];if(t==="parent"){const{updated:u,added:h,removed:c}=this.remove({ignoreUpstream:!1},r);a.push(...u),d.push(...h),o.push(...c)}return{updated:p(a),added:p(d),removed:p(o),affected:p(l),self:this}}onDetachedDependencyRestored(e,t,r){const a=[],d=[],o=[],l=[];if(t==="parent"){const{updated:u,added:h,removed:c}=this.restore({},r);a.push(...u),d.push(...h),o.push(...c)}return{updated:p(a),added:p(d),removed:p(o),affected:p(l),self:this}}subscribeToDependencies(){var e,t,r,a;return(e=this.parent)==null||e.subscribeDependents([{entity:this,field:"parent"}]),(a=(r=(t=this.dataType)==null?void 0:t.entity)==null?void 0:r.subscribeDependents)==null||a.call(r,[{entity:this,field:"data-type-entity"}]),this}increaseVersion(e){if(e&&!T(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&T(e).isSame(T(this.createdAt))?this:(this.previousVersion=this.version,this.version=I.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t,r;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new Ve(this,this.project);return(r=this.knownVersions)==null||r.set(this.version,e),e.inputs=this.inputs,e.outputs=this.outputs,e.internalCalls=this.internalCalls,e.successCalls=this.successCalls,e.errorCalls=this.errorCalls,e.writesValues=this.writesValues,e.readsValue=this.readsValue,e.defaultValue=this.defaultValue,e.dataType=this.dataType,e.calledBySuccess=this.calledBySuccess,e.calledByError=this.calledByError,e.calledByEntry=this.calledByEntry,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],r=[],a=[],d=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),r.push(...o.added),a.push(...o.removed)}return{updated:p(t),added:p(r),removed:p(a),affected:p(d),self:this}}async restoreVersion(e){var l;const t=[],r=[],a=[],d=[];if(this.version===e)return{updated:p(t),added:p(r),removed:p(a),affected:p(d),self:this};if(!this.knownVersions){const u=new Map;for(const[h,c]of this.knownVersions||new Map){if(u.set(h,c),c.activeVersion=!1,c.knownVersions)for(const[v,E]of c.knownVersions)u.set(v,E);c.knownVersions=null}}let o=(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 Ve(u,this.project)}return this.metaSync(o.toShallowJSON(),null),this.inputs=o.inputs,this.outputs=o.outputs,this.internalCalls=o.internalCalls,this.successCalls=o.successCalls,this.errorCalls=o.errorCalls,this.writesValues=o.writesValues,this.readsValue=o.readsValue,this.defaultValue=o.defaultValue,this.dataType=o.dataType,this.calledBySuccess=o.calledBySuccess,this.calledByError=o.calledByError,this.calledByEntry=o.calledByEntry,this.parent=o.parent,{updated:p(t),added:p(r),removed:p(a),affected:p(d),self:this}}hydrateAncestors(){const e=[],t=[],r=[],a=[];if(this.initialData.parent){const d=B(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 throw new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(this.initialData.readsValue){const d=B(this.initialData.readsValue),o=this.project.get(d);o&&(this.setValueWriter(o),e.push(o))}return this.initialData.calledByEntry.forEach(d=>{const o=B(d),l=this.project.get(o);l&&(this.addEntryCaller(l,null),e.push(l))}),this.initialData.calledBySuccess.forEach(d=>{const o=B(d),l=this.project.get(o);l&&(this.addSuccessCaller(l,null),e.push(l))}),this.initialData.calledByError.forEach(d=>{const o=B(d),l=this.project.get(o);l&&(this.addErrorCaller(l,null),e.push(l))}),yi.hydrateReadsValue(this),{updated:p(e),added:p(t),removed:p(r),affected:p(a),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new R(this.project,"",T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],r=[],a=[],d=[];this.initialized=!0,this.captureVersion();const{added:o,updated:l,removed:u,affected:h}=this.generateUnusedInputs(e);r.push(...o),t.push(...l),a.push(...u),d.push(...h);const{added:c,updated:v,removed:E,affected:O}=this.generateUnusedOutputs(e);r.push(...c),t.push(...v),a.push(...E),d.push(...O);const{added:w,updated:C,removed:U,affected:G}=this.generateUnusedInternalCalls(e);if(r.push(...w),t.push(...C),a.push(...U),d.push(...G),!this.dataType||this.dataType.inferred){const{added:_,updated:$,removed:k,affected:J}=this.inferDataTypeAndSyncInstancesInputsAndOutputs(e);r.push(..._),t.push(...$),a.push(...k),d.push(...J)}return e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:p(t),added:p(r),removed:p(a),affected:p(d),self:this}}addSelfToProject(e=this.project.addChangeSet(new R(this.project,"",T().toISOString(),this,!0,"add-self-to-project"))){const t=[this],r=[],a=[],d=[];return this.parent===this.project&&this.project.addVariableDeclaration(this),this.readsValue&&(this.readsValue.addValueReader(this),t.push(this.readsValue)),this.writesValues.forEach(o=>{o.setValueWriter(this),t.push(o)}),this.successCalls.forEach(o=>{o.addSuccessCaller(this,e),t.push(o)}),this.errorCalls.forEach(o=>{o.addErrorCaller(this,e),t.push(o)}),this.calledBySuccess.forEach(o=>{o.addSuccessCall(this),t.push(o)}),this.calledByError.forEach(o=>{o.addErrorCall(this),t.push(o)}),this.calledByEntry.forEach(o=>{o.addCall(this),t.push(o)}),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:p(t),added:p(r),removed:p(a),affected:p(d),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}get usedInputs(){return this.inputs.filter(e=>e.readsValue||e.defaultValue)}get unusedInputs(){return this.inputs.filter(e=>!e.readsValue&&!e.defaultValue)}get usedOutputs(){return this.outputs.filter(e=>e.writesValues.length)}get unusedOutputs(){return this.outputs.filter(e=>!e.writesValues.length)}get usedInternalCalls(){return this.internalCalls.filter(e=>!!e.calledBy.length)}get unusedInternalCalls(){return this.internalCalls.filter(e=>!e.calledBy.length)}removeInput(e){const t=this.inputs.findIndex(r=>r.id===e.id);return t>-1&&this.inputs.splice(t,1),this}addInput(e){return this.inputs.includes(e)?this:(this.inputs.push(e),this)}addOutput(e){return this.outputs.includes(e)?this:(this.outputs.push(e),this)}removeOutput(e){const t=this.outputs.findIndex(r=>r.id===e.id);return t>-1&&this.outputs.splice(t,1),this}addSuccessCaller(e,t=this.project.addChangeSet(new R(this.project,"",T().toISOString(),this,!0,"add-success-caller"))){return this.calledBySuccess.find(r=>r.id===e.id)||(this.calledBySuccess.push(e),t&&(t==null||t.add(this,b.Updated),t==null||t.add(e,b.Affected)),t==null||t.attemptAutoclose("add-success-caller",this.id)),this}addErrorCaller(e,t=this.project.addChangeSet(new R(this.project,"",T().toISOString(),this,!0,"add-error-caller"))){return this.calledByError.find(r=>r.id===e.id)||(this.calledByError.push(e),t&&(t==null||t.add(this,b.Updated),t==null||t.add(e,b.Affected)),t==null||t.attemptAutoclose("add-error-caller",this.id)),this}addEntryCaller(e,t=this.project.addChangeSet(new R(this.project,"",T().toISOString(),this,!0,"add-entry-caller"))){return this.calledByEntry.find(r=>r.id===e.id)||(this.calledByEntry.push(e),t&&(t==null||t.add(this,b.Updated),t==null||t.add(e,b.Affected)),t==null||t.attemptAutoclose("add-entry-caller",this.id)),this}addErrorCall(e){return this.errorCalls.find(t=>t.id===e.id)||this.errorCalls.push(e),this}addSuccessCall(e){return this.successCalls.find(t=>t.id===e.id)||this.successCalls.push(e),this}removeCall(e){const t=this.successCalls.findIndex(a=>a.id===e.id);t>-1&&this.successCalls.splice(t,1);const r=this.errorCalls.findIndex(a=>a.id===e.id);return r>-1&&this.errorCalls.splice(r,1),this}removeCaller(e,t=this.project.addChangeSet(new R(this.project,"",T().toISOString(),this,!0,"remove-caller"))){return this.calledBySuccess=this.calledBySuccess.filter(r=>r.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(r,b.Affected)),!0):!1),this.calledByError=this.calledByError.filter(r=>r.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(r,b.Affected)),!0):!1),this.calledByEntry=this.calledByEntry.filter(r=>r.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(r,b.Affected)),!0):!1),t==null||t.attemptAutoclose("remove-caller",this.id),this}addValueReader(e){return this.writesValues.includes(e)?this:(this.writesValues.push(e),this)}removeValueReader(e){return this.writesValues=this.writesValues.filter(t=>t.id!==e.id),this}setParent(e,t=this.project.addChangeSet(new R(this.project,"",T().toISOString(),this,!0,"set-parent"))){var r;return((r=this.parent)==null?void 0:r.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,b.Updated),t==null||t.attemptAutoclose("set-parent",this.id))),this}initChildren(e=this.project.addChangeSet(new R(this.project,"",T().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.initialData.defaultValue&&(this.defaultValue=V(this.initialData.defaultValue,this.project),this.defaultValue.setParent(this,null),this.defaultValue.initChildren(e)),this.initialData.dataType&&(this.dataType=V(this.initialData.dataType,this.project),this.dataType.setParent(this,null),this.dataType.initChildren(e)),gs.initWritesValues(this,this.parent),yi.initReadsValue(this),this.successCalls=this.initialData.successCalls.map(t=>{const r=V(t,this.project);return r.addSuccessCaller(this),[n.BreakStatement,n.ContinueStatement].includes(r.type)?(r.setParent(this.parent.parent,null),r.initChildren(e)):r.type!==n.InternalCall&&(r.setParent(this.parent,null),r.initChildren(e)),r}),this.errorCalls=this.initialData.errorCalls.map(t=>{const r=V(t,this.project);return r.addErrorCaller(this),[n.BreakStatement,n.ContinueStatement].includes(r.type)?(r.setParent(this.parent.parent,null),r.initChildren(e)):r.type!==n.InternalCall&&(r.setParent(this.parent,null),r.initChildren(e)),r}),this.initialData.inputs.forEach(t=>{const r=V(t,this.project);return r.setParent(this,null),r.initChildren(e),this.addInput(r),r}),this.initialData.outputs.forEach(t=>{const r=V(t,this.project);return r.setParent(this,null),r.initChildren(e),this.addOutput(r),r}),this.initialData.internalCalls.forEach(t=>{if(t.type===n.GenericReference){const a=this.project.findSubscribedInstanceFromReference(t);if(!a)return;a.setParent(this,null),a.initChildren(e),this.addInternalCall(a);return}const r=V(t,this.project);return r.setParent(this,null),r.initChildren(e),this.addInternalCall(r),r}),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this)}setValueWriter(e){return this.readsValue=e,this}removeValueWriter(){return this.readsValue=null,this}subscribe(){return this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}getMasterInputWithValueWritterFromAllInstances(e){return p([...this.inputs,...this.variableInstances.flatMap(a=>a.inputs)]).find(a=>F(a,this.project)===F(e,this.project)&&!!a.readsValue)||e}inferDataTypeAndSyncInstancesInputsAndOutputs(e=this.project.addChangeSet(new R(this.project,"",T().toISOString(),this,!0,"infer-data-type-and-sync-instances-inputs-and-outputs"))){var U,G,_,$;const t=[],r=[],a=[],d=[];if(!this.dataType){const k=V({id:I.UUID.uuid(),version:I.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:I.sessionAuthor,previousVersion:null,deleted:!1,type:n.DataType,isList:!1,andChildrenGroup:null,orChildrenGroup:null,asType:!1,entity:null,like:!0,inferred:!0,parent:this.toReference()},this.project);this.setDataType(k),k.setParent(this,e),k.initChildren(e),e==null||e.add(k,b.Added),k.metaSync({inferred:!0,like:!0},e)}if(this.readsValue){const k=(U=this.readsValue.getDataType(e))==null?void 0:U.clone(e);if(k){const J=(G=this.dataType)==null?void 0:G.merge(k,e);this.dataType&&(J==null?void 0:J.self.id)!==this.dataType.id&&this.dataType.remove({ignoreUpstream:!1},e),k.id!==((_=J==null?void 0:J.self)==null?void 0:_.id)&&k.remove({ignoreUpstream:!1},e),J!=null&&J.self&&(J.self.metaSync({inferred:!0,like:!0},e),e==null||e.add(J.self,b.Added),this.setDataType(J.self))}return e==null||e.attemptAutoclose("infer-data-type-and-sync-instances-inputs-and-outputs",this.id),{updated:p(r),added:p(t),removed:p(a),affected:p(d),self:this}}const o=p([...this.inputs,...this.variableInstances.flatMap(k=>k.inputs)]),l=[];if(o.forEach(k=>{l.find(ee=>F(ee,this.project)===F(k,this.project))||l.push(k)}),!l.length)return e==null||e.attemptAutoclose("infer-data-type-and-sync-instances-inputs-and-outputs",this.id),{updated:p(r),added:p(t),removed:p(a),affected:p(d),self:this};if(($=this.dataType)==null||$.inferFromInputs(l,e),!this.dataType)return e==null||e.attemptAutoclose("infer-data-type-and-sync-instances-inputs-and-outputs",this.id),{updated:p(r),added:p(t),removed:p(a),affected:p(d),self:this};const{updated:u,added:h,removed:c,affected:v}=this.generateUnusedInputs(e);t.push(...h),r.push(...u),a.push(...c),d.push(...v);const{updated:E,added:O,removed:w,affected:C}=this.generateUnusedOutputs(e);return t.push(...O),r.push(...E),a.push(...w),d.push(...C),this.variableInstances.forEach(k=>{const{updated:J,added:ee,removed:pe,affected:Te}=k.generateUnusedInputs(e);t.push(...ee),r.push(...J),a.push(...pe),d.push(...Te);const{updated:K,added:se,removed:Ht,affected:Yr}=k.generateUnusedOutputs(e);t.push(...se),r.push(...K),a.push(...Ht),d.push(...Yr)}),e==null||e.attemptAutoclose("infer-data-type-and-sync-instances-inputs-and-outputs",this.id),{updated:p(r),added:p(t),removed:p(a),affected:p(d),self:this}}metaSync(e,t=this.project.addChangeSet(new R(this.project,"",T().toISOString(),this,!0,"sync-meta"))){const r=dt(this,e);return e.deleted===!0&&!this.deleted?t==null||t.add(this,b.Removed):e.deleted===!1&&this.deleted?t==null||t.add(this,b.Added):r&&(t==null||t.add(this,b.Updated)),super.metaSync(e),this.name=e.name||this.name,this.description=e.description||this.description,this.x=e.x||this.x,this.y=e.y||this.y,this.constant=e.constant!==void 0?e.constant:this.constant,this.required=e.required!==void 0?e.required:this.required,t==null||t.attemptAutoclose("sync-meta",this.id),this}async APILoad(e=L,...t){return await Ve.repository.APILoad(this.id,...t),this}async APICreate(e=L,...t){return await Ve.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=L,...t){return await Ve.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=L,...t){return await Ve.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=L,...t){return await Ve.repository.APIClone(this.id,...t),this}async APILoadVersion(e=L,t,...r){return await Ve.repository.APILoadVersion(this.id,t,...r)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new R(this.project,"",T().toISOString(),this,!0,"remove-entity"))){const r=[],a=[],d=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(a.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(l=>{const{updated:u,removed:h,added:c}=l.entity.onDetachedDependencyRemoved(this,l.field,t);r.push(...u),a.push(...h),d.push(...c)}),this.defaultValue){const{updated:l,removed:u}=this.defaultValue.remove({ignoreUpstream:!0},t);r.push(...l),a.push(...u)}if(this.readsValue&&(r.push(this.readsValue),this.readsValue.removeValueReader(this)),this.writesValues.forEach(l=>{r.push(l),l.readsValue=null}),this.inputs.forEach(l=>{const{updated:u,removed:h}=l.remove({ignoreUpstream:!0},t);r.push(...u),a.push(...h)}),this.outputs.forEach(l=>{const{updated:u,removed:h}=l.remove({ignoreUpstream:!0},t);r.push(...u),a.push(...h)}),this.successCalls.forEach(l=>{r.push(l),l.removeCaller(this)}),this.errorCalls.forEach(l=>{r.push(l),l.removeCaller(this)}),this.internalCalls.forEach(l=>{const{updated:u,removed:h}=l.remove({ignoreUpstream:!0},t);r.push(...u),a.push(...h)}),this.dataType){const{updated:l,removed:u}=this.dataType.remove({ignoreUpstream:!0},t);r.push(...l),a.push(...u)}return e||this.calledBy.forEach(l=>{r.push(l),l.removeCall(this)}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:p(d),updated:p(r),removed:p(a),affected:p(o),self:this}}restore({}={},e=this.project.addChangeSet(new R(this.project,"",T().toISOString(),this,!0,"restore-entity"))){const t=[],r=[],a=[],d=[];if(e!=null&&e.hasAdded(this.id))return e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),this.defaultValue){const{updated:o}=this.defaultValue.restore({},e);r.push(...o)}if(this.readsValue&&(r.push(this.readsValue),this.readsValue.addValueReader(this)),this.writesValues.forEach(o=>{r.push(o),o.setValueWriter(this)}),this.inputs.forEach(o=>{const{updated:l}=o.restore({},e);r.push(...l)}),this.outputs.forEach(o=>{const{updated:l}=o.restore({},e);r.push(...l)}),this.successCalls.forEach(o=>{r.push(o),o.addSuccessCaller(this)}),this.errorCalls.forEach(o=>{r.push(o),o.addErrorCaller(this)}),this.internalCalls.forEach(o=>{const{updated:l}=o.restore({},e);r.push(...l)}),this.dataType){const{updated:o}=this.dataType.restore({},e);r.push(...o)}return this.calledBySuccess.forEach(o=>{r.push(o),o.addSuccessCall(this)}),this.calledByError.forEach(o=>{r.push(o),o.addErrorCall(this)}),this.calledByEntry.forEach(o=>{r.push(o),o.addCall(this)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:p(t),updated:p(r),removed:p(a),affected:p(d),self:this}}toFlat(e=new Set){var r,a,d;return e.has(this.id)?[]:(e.add(this.id),[this,...((r=this.defaultValue)==null?void 0:r.toFlat(e))||[],...((a=this.dataType)==null?void 0:a.toFlat(e))||[],...((d=this.readsValue)==null?void 0:d.toFlat(e))||[],...this.writesValues.flatMap(o=>o.toFlat(e)),...this.successCalls.flatMap(o=>o.toFlat(e)),...this.errorCalls.flatMap(o=>o.toFlat(e)),...this.inputs.flatMap(o=>o.toFlat(e)),...this.outputs.flatMap(o=>o.toFlat(e)),...this.internalCalls.flatMap(o=>o.toFlat(e)),...this.calledBy.flatMap(o=>o.toFlat(e))])}toFlatIds(e=new Set){var r,a;return e.has(this.id)?[]:(e.add(this.id),[this.id,...((r=this.defaultValue)==null?void 0:r.toFlatIds(e))||[],...((a=this.dataType)==null?void 0:a.toFlatIds(e))||[],...this.writesValues.flatMap(d=>d.toFlatIds(e)),...this.successCalls.flatMap(d=>d.toFlatIds(e)),...this.errorCalls.flatMap(d=>d.toFlatIds(e)),...this.inputs.flatMap(d=>d.toFlatIds(e)),...this.outputs.flatMap(d=>d.toFlatIds(e)),...this.internalCalls.flatMap(d=>d.toFlatIds(e))])}toJSON(e=new Set){var t,r,a;return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,constant:this.constant,required:this.required,defaultValue:((t=this.defaultValue)==null?void 0:t.toJSON(e))||null,dataType:((r=this.dataType)==null?void 0:r.toJSON(e))||null,readsValue:((a=this.readsValue)==null?void 0:a.toReference())||null,writesValues:this.writesValues.map(d=>d.toJSON(e)),inputs:this.inputs.map(d=>d.toJSON(e)),outputs:this.outputs.map(d=>d.toJSON(e)),successCalls:this.successCalls.map(d=>d.toJSON(e)),errorCalls:this.errorCalls.map(d=>d.toJSON(e)),internalCalls:this.internalCalls.map(d=>d.toJSON(e)),calledBySuccess:this.calledBySuccess.map(d=>d.toReference()),calledByError:this.calledByError.map(d=>d.toReference()),calledByEntry:this.calledByEntry.map(d=>d.toReference()),parent:this.parent.toReference(),x:this.x,y:this.y})}toJSONClone(e=Z){var r,a,d,o,l,u,h,c;let t;return(r=e.seenEntityMaps)!=null&&r.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||ct(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(a=e.seenEntities)!=null&&a.has(t)||(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:I.UUID.uuid(),createdAt:e.timestamp||T().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,defaultValue:((u=this.defaultValue)==null?void 0:u.toJSONClone({...e,newId:null}))||null,dataType:((h=this.dataType)==null?void 0:h.toJSONClone({...e,newId:null}))||null,readsValue:((c=this.readsValue)==null?void 0:c.toReference({seenEntityMaps:e.seenEntityMaps}))||null,writesValues:this.writesValues.map(v=>v.toJSONClone({...e,newId:null})),inputs:this.inputs.map(v=>v.toJSONClone({...e,newId:null})),outputs:this.outputs.map(v=>v.toJSONClone({...e,newId:null})),successCalls:this.successCalls.map(v=>v.toJSONClone({...e,newId:null})),errorCalls:this.errorCalls.map(v=>v.toJSONClone({...e,newId:null})),internalCalls:this.internalCalls.map(v=>this.calledBy.length||this.readsValue?v.toJSONClone({...e,newId:null}):v.toReference({seenEntityMaps:e.seenEntityMaps})),calledBySuccess:this.calledBySuccess.map(v=>v.toReference({seenEntityMaps:e.seenEntityMaps})),calledByError:this.calledByError.map(v=>v.toReference({seenEntityMaps:e.seenEntityMaps})),calledByEntry:this.calledByEntry.map(v=>v.toReference({seenEntityMaps:e.seenEntityMaps})),parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps}),x:this.x,y:this.y})}toReference(e=Z){var r;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+I.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=Z){var r,a,d,o;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,required:this.required,constant:this.constant,x:this.x,y:this.y,defaultValue:((a=this.defaultValue)==null?void 0:a.toReference(e))||null,dataType:((d=this.dataType)==null?void 0:d.toReference(e))||null,readsValue:((o=this.readsValue)==null?void 0:o.toReference(e))||null,writesValues:this.writesValues.map(l=>l.toReference(e)),inputs:this.inputs.map(l=>l.toReference(e)),outputs:this.outputs.map(l=>l.toReference(e)),successCalls:this.successCalls.map(l=>l.toReference(e)),errorCalls:this.errorCalls.map(l=>l.toReference(e)),calledBySuccess:this.calledBySuccess.map(l=>l.toReference(e)),calledByError:this.calledByError.map(l=>l.toReference(e)),calledByEntry:this.calledByEntry.map(l=>l.toReference(e)),internalCalls:this.internalCalls.map(l=>l.toReference(e)),parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){var r,a;return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...((r=this.defaultValue)==null?void 0:r.toFlatJSON(e))||[],...((a=this.dataType)==null?void 0:a.toFlatJSON(e))||[],...this.writesValues.flatMap(d=>d.toFlatJSON(e)),...this.successCalls.flatMap(d=>d.toFlatJSON(e)),...this.errorCalls.flatMap(d=>d.toFlatJSON(e)),...this.inputs.flatMap(d=>d.toFlatJSON(e)),...this.outputs.flatMap(d=>d.toFlatJSON(e)),...this.internalCalls.flatMap(d=>d.toFlatJSON(e))])}toGenerationTarget(){const e=this.parent.type===n.Project?void 0:this.parent.id;return{id:this.id,type:this.type,name:this.name,description:this.description,calledByEntry:this.calledByEntry.map(t=>t.id),calledBySuccess:this.calledBySuccess.map(t=>t.id),calledByError:this.calledByError.map(t=>t.id),parent:e}}toFlatGenerationTarget(e=new Set){var r,a;return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...((r=this.defaultValue)==null?void 0:r.toFlatGenerationTarget(e))||[],...((a=this.dataType)==null?void 0:a.toFlatGenerationTarget(e))||[],...this.writesValues.flatMap(d=>d.toFlatGenerationTarget(e)),...this.successCalls.flatMap(d=>d.toFlatGenerationTarget(e)),...this.errorCalls.flatMap(d=>d.toFlatGenerationTarget(e)),...this.inputs.flatMap(d=>d.toFlatGenerationTarget(e)),...this.outputs.flatMap(d=>d.toFlatGenerationTarget(e)),...this.internalCalls.flatMap(d=>d.toFlatGenerationTarget(e))])}clearErrors(){var e,t;return this.errors=[],this.inputs.forEach(r=>r.clearErrors()),this.outputs.forEach(r=>r.clearErrors()),this.successCalls.forEach(r=>r.clearErrors()),this.errorCalls.forEach(r=>r.clearErrors()),this.internalCalls.forEach(r=>r.clearErrors()),(e=this.dataType)==null||e.clearErrors(),(t=this.defaultValue)==null||t.clearErrors(),this}validate(){const e=sq(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){var t,r,a;return[...this.errors,...((t=this.defaultValue)==null?void 0:t.getErrors())||[],...((r=this.dataType)==null?void 0:r.getErrors())||[],...this.inputs.flatMap(d=>d.getErrors()),...this.internalCalls.flatMap(d=>d.getErrors()),...this.outputs.flatMap(d=>d.getErrors()),...((a=this.readsValue)==null?void 0:a.getErrors())||[]]}getShallowErrors(){return this.errors}getDefaultValue(){return this.defaultValue||null}setDefaultValue(e){return this.defaultValue=e,this}clone(e=this.project.addChangeSet(new R(this.project,"",T().toISOString(),this,!0,"clone-entity")),t=null,r=null,a=!0){var w,C,U,G,_;let d=ft(t,this);const o=this.toJSON(),l=r||I.UUID.uuid();o.inputs=[],o.id=l,o.version=I.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=lt(o,d);t?u.setParent(t,null):u.setParent(this.parent,null),a&&u.subscribe(),u.initChildren(e),e==null||e.add(u,b.Added);const h=(w=this.dataType)==null?void 0:w.clone(e,u,I.UUID.uuid(),a);u.dataType=h||null;const c=(C=this.defaultValue)==null?void 0:C.clone(e,u,I.UUID.uuid(),a);u.defaultValue=c||null;const v=(U=this.inputs)==null?void 0:U.map($=>$.clone(e,u,I.UUID.uuid(),a));u.inputs=v;const E=(G=this.outputs)==null?void 0:G.map($=>$.clone(e,u,I.UUID.uuid(),a));u.outputs=E;const O=(_=this.internalCalls)==null?void 0:_.map($=>$.clone(e,u,I.UUID.uuid(),a));return u.internalCalls=O,e==null||e.attemptAutoclose("clone-entity",this.id),u}addInternalCall(e){return this.internalCalls.find(t=>t===e)||this.internalCalls.push(e),this}createInstance(e=this.project,t=this.project.addChangeSet(new R(this.project,"",T().toISOString(),this,!0,"create-instance")),r={}){const a={id:r.id||I.UUID.uuid(),version:r.version||I.UUID.uuid(),createdAt:(t==null?void 0:t.timestamp)||T().toISOString(),author:I.sessionAuthor,previousVersion:null,deleted:!1,type:n.VariableInstance,parent:e.toReference(),defaultValue:r.defaultValue||null,successCalls:r.successCalls||[],errorCalls:r.errorCalls||[],inputs:r.inputs||[],outputs:r.outputs||[],writesValues:r.writesValues||[],internalCalls:r.internalCalls||[],readsValue:r.readsValue||null,calledByEntry:r.calledByEntry||[],calledBySuccess:r.calledBySuccess||[],calledByError:r.calledByError||[],declaration:this.toJSON(),x:0,y:0},d=V(a,this.project);return d.setParent(e,null),d.initChildren(null),t==null||t.add(d,b.Added),e===this.project&&this.project.addVariableInstance(d),t==null||t.attemptAutoclose("create-instance",this.id),d}generateUnusedInputs(e=this.project.addChangeSet(new R(this.project,"",T().toISOString(),this,!0,"generate-unused-inputs"))){const t=[],r=[],a=[],d=[];if(this.dataType)if(this.dataType.entity){if([n.DefinitionEntity,n.PrimitiveEntity,n.BuiltInBaseEntity].includes(this.dataType.entity.type)){const o=[...this.dataType.entity.properties];o.filter(c=>!c.getDataType(e)).forEach(c=>{const v=this.inputs.find(w=>F(w,this.project)===F(c,this.project));if(!v)return;const E=this.getMasterInputWithValueWritterFromAllInstances(v);if(!E)return;const O=kr(E);c.setDataType(O),v.setDeclaration(c)}),o.filter(c=>!this.inputs.find(v=>{var E;return((E=v.declaration)==null?void 0:E.id)===c.id})).forEach(c=>{const v={id:I.UUID.uuid(),version:I.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:I.sessionAuthor,previousVersion:null,deleted:!1,type:n.InputMap,parent:this.toReference(),name:null,description:null,declaration:c,defaultValue:null,index:c.index,readsValue:null},E=V(v,this.project);return E.setParent(this,e),E.initChildren(e),e==null||e.add(E,b.Added),E.suggestion=!0,this.addInput(E),E}),this.inputs.filter(c=>!c.declaration).forEach(c=>{const v=o.find(E=>F(E,this.project)===F(c,this.project));v&&c.setDeclaration(v)})}}else return e==null||e.attemptAutoclose("generate-unused-inputs",this.id),{added:[],updated:[],removed:[],affected:[],self:this};else return e==null||e.attemptAutoclose("generate-unused-inputs",this.id),{added:[],updated:[],removed:[],affected:[],self:this};return e==null||e.attemptAutoclose("generate-unused-inputs",this.id),{added:p(t),updated:p(r),removed:p(a),affected:p(d),self:this}}generateUnusedOutputs(e=this.project.addChangeSet(new R(this.project,"",T().toISOString(),this,!0,"generate-unused-outputs"))){const t=[],r=[],a=[],d=[];if(this.dataType)if(this.dataType.entity)[n.DefinitionEntity,n.PrimitiveEntity,n.BuiltInBaseEntity].includes(this.dataType.entity.type)&&[...this.dataType.entity.properties].filter(u=>!this.outputs.find(h=>h.declaration===u)).map(u=>{const h={id:I.UUID.uuid(),version:I.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:I.sessionAuthor,previousVersion:null,deleted:!1,type:n.OutputMap,defaultValue:null,parent:this.toReference(),declaration:u,index:u.index,writesValues:[]},c=V(h,this.project);return c.setParent(this,e),c.initChildren(e),e==null||e.add(c,b.Added),c.suggestion=!0,this.addOutput(c),c});else return e==null||e.attemptAutoclose("generate-unused-outputs",this.id),{added:[],updated:[],removed:[],affected:[],self:this};else return e==null||e.attemptAutoclose("generate-unused-outputs",this.id),{added:[],updated:[],removed:[],affected:[],self:this};return e==null||e.attemptAutoclose("generate-unused-outputs",this.id),{added:p(t),updated:p(r),removed:p(a),affected:p(d),self:this}}generateUnusedInternalCalls(e=this.project.addChangeSet(new R(this.project,"",T().toISOString(),this,!0,"generate-unused-internal-calls"))){const t=[],r=[],a=[],d=[];if(this.dataType)if(this.dataType.entity)[n.DefinitionEntity,n.PrimitiveEntity,n.BuiltInBaseEntity].includes(this.dataType.entity.type)&&[...this.dataType.entity.getAllInteractiveMethods()].filter(u=>!this.internalCalls.find(c=>{var E,O,w,C,U;return(((E=c.declaration)==null?void 0:E.id)||((w=(O=c.initialData)==null?void 0:O.declaration)==null?void 0:w.entityId)||((U=(C=c.initialData)==null?void 0:C.declaration)==null?void 0:U.id))===u.id})).map(u=>{const h=u.createInternalCall(e,this);return e==null||e.add(h,b.Added),h.suggestion=!0,this.addInternalCall(h),h});else return e==null||e.attemptAutoclose("generate-unused-internal-calls",this.id),{added:[],updated:[],removed:[],affected:[],self:this};else return e==null||e.attemptAutoclose("generate-unused-internal-calls",this.id),{added:[],updated:[],removed:[],affected:[],self:this};return e==null||e.attemptAutoclose("generate-unused-internal-calls",this.id),{added:p(t),updated:p(r),removed:p(a),affected:p(d),self:this}}setDataType(e){return this.dataType=e,this}removeDataType(){return this.dataType=null,this}getDataType(e=this.project.addChangeSet(new R(this.project,"",T().toISOString(),this,!0,"get-data-type"))){return(!this.dataType||this.dataType.inferred)&&this.inferDataTypeAndSyncInstancesInputsAndOutputs(e),this.dataType||null}getUnusedInputs(){return this.inputs.filter(e=>e.suggestion||!e.readsValue&&!e.defaultValue)}getUnusedOutputs(){return this.outputs.filter(e=>e.suggestion||!e.writesValues.length)}getUsedInputs(){return this.inputs.filter(e=>!e.suggestion&&(e.readsValue||e.defaultValue))}getUsedOutputs(){return this.outputs.filter(e=>!e.suggestion&&e.writesValues.length)}};f(Ve,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>e,APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...r)=>null}),f(Ve,"type",n.VariableDeclaration),f(Ve,"USER_MANAGED_PARENT_TYPES",[...mt,n.Project]),f(Ve,"PARENT_TYPES",[...Ve.USER_MANAGED_PARENT_TYPES]),f(Ve,"MUTABLE_BASE_PROPERTIES",["name","description"]),f(Ve,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),f(Ve,"BASE_PROPERTIES",[...Ve.MUTABLE_BASE_PROPERTIES,...Ve.INMUTABLE_BASE_PROPERTIES]),f(Ve,"MUTABLE_META_PROPERTIES",[...Ve.MUTABLE_BASE_PROPERTIES,"x","y"]),f(Ve,"INMUTABLE_META_PROPERTIES",[...Ve.INMUTABLE_BASE_PROPERTIES]),f(Ve,"META_PROPERTIES",[...Ve.MUTABLE_META_PROPERTIES,...Ve.INMUTABLE_META_PROPERTIES]),f(Ve,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry","readsValue"]),f(Ve,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","dataType"]),f(Ve,"UPSTREAM_PROPERTIES",[...Ve.MUTABLE_UPSTREAM_PROPERTIES,...Ve.INMUTABLE_UPSTREAM_PROPERTIES]),f(Ve,"MUTABLE_DOWNSTREAM_PROPERTIES",["writesValues","inputs","outputs","successCalls","errorCalls","internalCalls"]),f(Ve,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),f(Ve,"DOWNSTREAM_PROPERTIES",[...Ve.MUTABLE_DOWNSTREAM_PROPERTIES,...Ve.INMUTABLE_DOWNSTREAM_PROPERTIES]),f(Ve,"PROPERTIES",[...Ve.META_PROPERTIES,...Ve.UPSTREAM_PROPERTIES,...Ve.DOWNSTREAM_PROPERTIES]);let $i=Ve;function dq(i){var d;const s=e3(),e=i.toJSON();s.safeParse(e).success,i.inputsDeclarations.forEach(o=>o.validate()),i.inputs.forEach(o=>o.validate()),i.outputsDeclarations.forEach(o=>o.validate()),i.outputs.forEach(o=>o.validate()),(d=i.error)==null||d.validate();const a=[...fi(i)];if(i.id==="search-person-by-id-id"){const o=ye({id:`${i.id}--${q.PropertyImplementsNonAbstact}`,message:`Property "${F(i,i.project)}" with id "${i.id}" implements a non-abstract property "${F(i,i.project)}" with id "${i.id}".`,issue:null,severity:D.Error,code:q.PropertyImplementsNonAbstact,entity:i});a.push(o.error)}return ze(i.errors,a)}var tO=(i=>(i.Parent="parent",i))(tO||{});const Ze=class Ze extends rt{constructor(e,t){super(e);f(this,"initialData");f(this,"id");f(this,"name");f(this,"description",null);f(this,"x");f(this,"y");f(this,"query","");f(this,"type",n.Search);f(this,"successCalls",[]);f(this,"errorCalls",[]);f(this,"inputsDeclarations",[]);f(this,"inputs",[]);f(this,"outputsDeclarations",[]);f(this,"outputs",[]);f(this,"calledBySuccess",[]);f(this,"calledByError",[]);f(this,"calledByEntry",[]);f(this,"error",null);f(this,"parent");f(this,"errors",[]);f(this,"project");f(this,"detachedDependents",{});f(this,"knownVersions",null);f(this,"activeVersion",!1);f(this,"initialized",!1);f(this,"startedInitialization",!1);this.initialData=e,this.project=t,this.id=e.id,this.x=e.x,this.y=e.y,this.name=e.name,this.query=e.query,this.description=e.description}static fromGenerationTarget(e,t){let r=t;if(e.parent){const h=B(e.parent);r=t.get(h)}const a=e.calledByEntry.map(h=>{const c=B(h);return t.get(c)}),d=e.calledBySuccess.map(h=>{const c=B(h);return t.get(c)}),o=e.calledByError.map(h=>{const c=B(h);return t.get(c)}),l={id:e.id,version:I.UUID.uuid(),createdAt:T().toISOString(),author:I.sessionAuthor,previousVersion:null,deleted:!1,type:n.Search,name:e.name,description:e.description,query:e.query,calledByEntry:a,calledBySuccess:d,calledByError:o,errorCalls:[],successCalls:[],inputsDeclarations:[],inputs:[],outputsDeclarations:[],outputs:[],error:null,x:0,y:0,parent:r},u=V(l,t);return u.setParent(r,null),u.initChildren(null),u}static validateGenerationTarget(e,t){let r=JSON.parse(JSON.stringify(e));const a=[],d=Et(r,{parent:{list:!1,types:[...mt,n.Project],optional:!0}},t);return r=d.modifiedData,a.push(...d.errors,...ot(r)),{errors:a,modifiedData:r}}get resultsAsList(){const e=this.outputsDeclarations[0];if(e){const t=e.getDataType(null);return t?t.isList===!0:!0}return!0}validateGeneratedUpdate(e){const t=[];return e.parent&&t.push(new P({id:`${this.id}--${A.InvalidParentUpdate}`,code:A.InvalidParentUpdate,severity:D.Error,message:`Entity of type '${this.type}' with id '${this.id}' cannot have the 'parent' property updated. The 'parent' on a callable entity, is its scope. It scope is auto-calculated implicitly by the its caller.
|
|
110
110
|
If an entity is called by another, they must be in the same scope, which means they have the same parent.
|
|
111
111
|
You shouldn't have to manually update a 'parent' property. The equivalent result is to change its callers, the value writters of its inputs, or the value readers of its outputs.`,issue:null})),{errors:t,modifiedData:e}}subscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]||(this.detachedDependents[t.entity.id]=t)}),this}syncDependents(){const e=[],t=[],r=[],a=[];return Object.values(this.detachedDependents).forEach(d=>{const o=d.entity.afterAllChildrenInitialized();e.push(...o.updated),t.push(...o.added),r.push(...o.removed),a.push(...o.affected)}),{updated:p(e),added:p(t),removed:p(r),affected:p(a),self:this}}onDetachedDependencyRemoved(e,t,r){const a=[],d=[],o=[],l=[];if(t==="parent"){const{updated:u,added:h,removed:c}=this.remove({ignoreUpstream:!1},r);a.push(...u),d.push(...h),o.push(...c)}return{updated:p(a),added:p(d),removed:p(o),affected:p(l),self:this}}onDetachedDependencyRestored(e,t,r){const a=[],d=[],o=[],l=[];if(t==="parent"){const{updated:u,added:h,removed:c}=this.restore({},r);a.push(...u),d.push(...h),o.push(...c)}return{updated:p(a),added:p(d),removed:p(o),affected:p(l),self:this}}subscribeToDependencies(){var e;return(e=this.parent)==null||e.subscribeDependents([{entity:this,field:"parent"}]),this}increaseVersion(e){if(e&&!T(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&T(e).isSame(T(this.createdAt))?this:(this.previousVersion=this.version,this.version=I.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t,r;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new Ze(this,this.project);return(r=this.knownVersions)==null||r.set(this.version,e),e.inputs=this.inputs,e.outputs=this.outputs,e.error=this.error,e.inputsDeclarations=this.inputsDeclarations,e.outputsDeclarations=this.outputsDeclarations,e.successCalls=this.successCalls,e.errorCalls=this.errorCalls,e.calledByEntry=this.calledByEntry,e.calledBySuccess=this.calledBySuccess,e.calledByError=this.calledByError,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],r=[],a=[],d=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),r.push(...o.added),a.push(...o.removed)}return{updated:p(t),added:p(r),removed:p(a),affected:p(d),self:this}}async restoreVersion(e){var l;const t=[],r=[],a=[],d=[];if(this.version===e)return{updated:p(t),added:p(r),removed:p(a),affected:p(d),self:this};if(!this.knownVersions){const u=new Map;for(const[h,c]of this.knownVersions||new Map){if(u.set(h,c),c.activeVersion=!1,c.knownVersions)for(const[v,E]of c.knownVersions)u.set(v,E);c.knownVersions=null}}let o=(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 Ze(u,this.project)}return this.metaSync(o.toShallowJSON(),null),this.inputs=o.inputs,this.outputs=o.outputs,this.error=o.error,this.inputsDeclarations=o.inputsDeclarations,this.outputsDeclarations=o.outputsDeclarations,this.successCalls=o.successCalls,this.errorCalls=o.errorCalls,this.calledByEntry=o.calledByEntry,this.calledBySuccess=o.calledBySuccess,this.calledByError=o.calledByError,this.parent=o.parent,{updated:p(t),added:p(r),removed:p(a),affected:p(d),self:this}}hydrateAncestors(){const e=[],t=[],r=[],a=[];if(this.initialData.parent){const d=B(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 throw new Error(`${this.type} with id '${this.id}' must have a 'parent'`);return this.initialData.calledByEntry.forEach(d=>{const o=B(d),l=this.project.get(o);l&&(this.addEntryCaller(l,null),e.push(l))}),this.initialData.calledBySuccess.forEach(d=>{const o=B(d),l=this.project.get(o);l&&(this.addSuccessCaller(l,null),e.push(l))}),this.initialData.calledByError.forEach(d=>{const o=B(d),l=this.project.get(o);l&&(this.addErrorCaller(l,null),e.push(l))}),{updated:p(e),added:p(t),removed:p(r),affected:p(a),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new R(this.project,"",T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],r=[],a=[],d=[];this.initialized=!0,this.captureVersion();const{updated:o,added:l,removed:u}=this.syncInputMaps(e);return t.push(...o),r.push(...l),a.push(...u),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:p(t),added:p(r),removed:p(a),affected:p(d),self:this}}addSelfToProject(e=this.project.addChangeSet(new R(this.project,"",T().toISOString(),this,!0,"add-self-to-project"))){const t=[this],r=[],a=[],d=[];return this.parent===this.project&&this.project.addSearch(this),this.successCalls.forEach(o=>{o.addSuccessCaller(this,e),t.push(o)}),this.errorCalls.forEach(o=>{o.addErrorCaller(this,e),t.push(o)}),this.calledByEntry.forEach(o=>{o.addCall(this),t.push(o)}),this.calledBySuccess.forEach(o=>{o.addSuccessCall(this),t.push(o)}),this.calledByError.forEach(o=>{o.addErrorCall(this),t.push(o)}),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:p(t),added:p(r),removed:p(a),affected:p(d),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}removeInput(e){const t=this.inputs.findIndex(a=>a.id===e.id);t>-1&&this.inputs.splice(t,1);const r=this.inputsDeclarations.findIndex(a=>{var d;return a.id===((d=e.declaration)==null?void 0:d.id)});return r>-1&&this.inputsDeclarations.splice(r,1),this}addInput(e){return this.inputs.includes(e)?this:(this.inputs.push(e),this)}addInputDeclaration(e,t=this.project.addChangeSet(new R(this.project,"",T().toISOString(),this,!0,"add-input-declaration"))){return this.inputsDeclarations.includes(e)?(t==null||t.attemptAutoclose("add-input-declaration",this.id),this):(this.inputsDeclarations.push(e),this.syncInputMaps(t),t==null||t.attemptAutoclose("add-input-declaration",this.id),this)}removeInputDeclaration(e){const t=this.inputsDeclarations.findIndex(r=>r.id===e.id);return t>-1&&this.inputsDeclarations.splice(t,1),this}addOutputDeclaration(e){return this.outputsDeclarations.includes(e)?this:(this.outputsDeclarations.push(e),this)}removeOutputDeclaration(e){const t=this.outputsDeclarations.findIndex(r=>r.id===e.id);return t>-1&&this.outputsDeclarations.splice(t,1),this}addOutput(e){return this.outputs.includes(e)?this:(this.outputs.push(e),this)}removeOutput(e){const t=this.outputs.findIndex(r=>r.id===e.id);return t>-1&&this.outputs.splice(t,1),this}addSuccessCaller(e,t=this.project.addChangeSet(new R(this.project,"",T().toISOString(),this,!0,"add-success-caller"))){return this.calledBySuccess.find(r=>r.id===e.id)||(this.calledBySuccess.push(e),t&&(t==null||t.add(this,b.Updated),t==null||t.add(e,b.Affected)),t==null||t.attemptAutoclose("add-success-caller",this.id)),this}addErrorCaller(e,t=this.project.addChangeSet(new R(this.project,"",T().toISOString(),this,!0,"add-error-caller"))){return this.calledByError.find(r=>r.id===e.id)||(this.calledByError.push(e),t&&(t==null||t.add(this,b.Updated),t==null||t.add(e,b.Affected)),t==null||t.attemptAutoclose("add-error-caller",this.id)),this}addEntryCaller(e,t=this.project.addChangeSet(new R(this.project,"",T().toISOString(),this,!0,"add-entry-caller"))){return this.calledByEntry.find(r=>r.id===e.id)||(this.calledByEntry.push(e),t&&(t==null||t.add(this,b.Updated),t==null||t.add(e,b.Affected)),t==null||t.attemptAutoclose("add-entry-caller",this.id)),this}addErrorCall(e){return this.errorCalls.find(t=>t.id===e.id)||this.errorCalls.push(e),this}addSuccessCall(e){return this.successCalls.find(t=>t.id===e.id)||this.successCalls.push(e),this}removeCall(e){const t=this.successCalls.findIndex(a=>a.id===e.id);t>-1&&this.successCalls.splice(t,1);const r=this.errorCalls.findIndex(a=>a.id===e.id);return r>-1&&this.errorCalls.splice(r,1),this}removeCaller(e,t=this.project.addChangeSet(new R(this.project,"",T().toISOString(),this,!0,"remove-caller"))){return this.calledBySuccess=this.calledBySuccess.filter(r=>r.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(r,b.Affected)),!0):!1),this.calledByError=this.calledByError.filter(r=>r.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(r,b.Affected)),!0):!1),this.calledByEntry=this.calledByEntry.filter(r=>r.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(r,b.Affected)),!0):!1),t==null||t.attemptAutoclose("remove-caller",this.id),this}setParent(e,t=this.project.addChangeSet(new R(this.project,"",T().toISOString(),this,!0,"set-parent"))){var r;return((r=this.parent)==null?void 0:r.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,b.Updated),t==null||t.attemptAutoclose("set-parent",this.id))),this}initChildren(e=this.project.addChangeSet(new R(this.project,"",T().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.successCalls=this.initialData.successCalls.map(t=>{const r=V(t,this.project);return[n.BreakStatement,n.ContinueStatement].includes(r.type)?(r.setParent(this.parent.parent,null),r.initChildren(e)):r.type!==n.InternalCall&&(r.setParent(this.parent,null),r.initChildren(e)),r}),this.errorCalls=this.initialData.errorCalls.map(t=>{const r=V(t,this.project);return r.addErrorCaller(this),[n.BreakStatement,n.ContinueStatement].includes(r.type)?(r.setParent(this.parent.parent,null),r.initChildren(e)):r.type!==n.InternalCall&&(r.setParent(this.parent,null),r.initChildren(e)),r}),this.inputsDeclarations=this.initialData.inputsDeclarations.map(t=>{const r=V(t,this.project);return r.setParent(this,null),r.initChildren(e),r}),this.inputs=this.initialData.inputs.map(t=>{const r=V(t,this.project);return r.setParent(this,null),r.initChildren(e),r}),this.outputsDeclarations=this.initialData.outputsDeclarations.map(t=>{const r=V(t,this.project);return r.setParent(this,null),r.initChildren(e),r}),this.outputs=this.initialData.outputs.map(t=>{const r=V(t,this.project);return r.setParent(this,null),r.initChildren(e),r}),this.initialData.error&&(this.error=V(this.initialData.error,this.project),this.error.setParent(this,null),this.error.initChildren(e)),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this)}subscribe(){return this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new R(this.project,"",T().toISOString(),this,!0,"sync-meta"))){const r=dt(this,e);return e.deleted===!0&&!this.deleted?t==null||t.add(this,b.Removed):e.deleted===!1&&this.deleted?t==null||t.add(this,b.Added):r&&(t==null||t.add(this,b.Updated)),super.metaSync(e),this.x=e.x||this.x,this.y=e.y||this.y,this.name=e.name||this.name,this.description=e.description||this.description,e.query!==void 0&&(this.query=e.query),t==null||t.attemptAutoclose("sync-meta",this.id),this}async APILoad(e=L,...t){return await Ze.repository.APILoad(this.id,...t),this}async APICreate(e=L,...t){return await Ze.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=L,...t){return await Ze.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=L,...t){return await Ze.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=L,...t){return await Ze.repository.APIClone(this.id,...t),this}async APILoadVersion(e=L,t,...r){return await Ze.repository.APILoadVersion(this.id,t,...r)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new R(this.project,"",T().toISOString(),this,!0,"remove-entity"))){const r=[],a=[],d=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(a.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(l=>{const{updated:u,removed:h,added:c}=l.entity.onDetachedDependencyRemoved(this,l.field,t);r.push(...u),a.push(...h),d.push(...c)}),this.inputs.forEach(l=>{const{updated:u,removed:h}=l.remove({ignoreUpstream:!0},t);r.push(...u),a.push(...h)}),this.inputsDeclarations.forEach(l=>{const{updated:u,removed:h}=l.remove({ignoreUpstream:!0},t);r.push(...u),a.push(...h)}),this.outputs.forEach(l=>{const{updated:u,removed:h}=l.remove({ignoreUpstream:!0},t);r.push(...u),a.push(...h)}),this.outputsDeclarations.forEach(l=>{const{updated:u,removed:h}=l.remove({ignoreUpstream:!0},t);r.push(...u),a.push(...h)}),this.error){const{updated:l,removed:u}=this.error.remove({ignoreUpstream:!0},t);r.push(...l),a.push(...u)}return this.successCalls.forEach(l=>{r.push(l),l.removeCaller(this)}),this.errorCalls.forEach(l=>{r.push(l),l.removeCaller(this)}),e||this.calledBy.forEach(l=>{r.push(l),l.removeCall(this)}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:p(d),updated:p(r),removed:p(a),affected:p(o),self:this}}restore({}={},e=this.project.addChangeSet(new R(this.project,"",T().toISOString(),this,!0,"restore-entity"))){const t=[],r=[],a=[],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),this.inputsDeclarations.forEach(o=>{const{updated:l}=o.restore({},e);r.push(...l)}),this.inputs.forEach(o=>{const{updated:l}=o.restore({},e);r.push(...l)}),this.outputsDeclarations.forEach(o=>{const{updated:l}=o.restore({},e);r.push(...l)}),this.outputs.forEach(o=>{const{updated:l}=o.restore({},e);r.push(...l)}),this.successCalls.forEach(o=>{r.push(o),o.addSuccessCaller(this)}),this.errorCalls.forEach(o=>{r.push(o),o.addErrorCaller(this)}),this.calledBySuccess.forEach(o=>{r.push(o),o.addSuccessCall(this)}),this.calledByError.forEach(o=>{r.push(o),o.addErrorCall(this)}),this.calledByEntry.forEach(o=>{r.push(o),o.addCall(this)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:p(t),updated:p(r),removed:p(a),affected:p(d),self:this})}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.successCalls.flatMap(r=>r.toFlat(e)),...this.errorCalls.flatMap(r=>r.toFlat(e)),...this.inputs.flatMap(r=>r.toFlat(e)),...this.inputsDeclarations.flatMap(r=>r.toFlat(e)),...this.outputs.flatMap(r=>r.toFlat(e)),...this.outputsDeclarations.flatMap(r=>r.toFlat(e)),...this.calledBy.flatMap(r=>r.toFlat(e)),...this.error?this.error.toFlat(e):[]])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.successCalls.flatMap(r=>r.toFlatIds(e)),...this.errorCalls.flatMap(r=>r.toFlatIds(e)),...this.inputs.flatMap(r=>r.toFlatIds(e)),...this.inputsDeclarations.flatMap(r=>r.toFlatIds(e)),...this.outputs.flatMap(r=>r.toFlatIds(e)),...this.outputsDeclarations.flatMap(r=>r.toFlatIds(e)),...this.calledBy.flatMap(r=>r.toFlatIds(e)),...this.error?this.error.toFlatIds(e):[]])}toJSON(e=new Set){var t;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,query:this.query,description:this.description,x:this.x,y:this.y,successCalls:this.successCalls.map(r=>r.toJSON()),errorCalls:this.errorCalls.map(r=>r.toJSON()),calledBySuccess:this.calledBySuccess.map(r=>r.toReference()),calledByError:this.calledByError.map(r=>r.toReference()),calledByEntry:this.calledByEntry.map(r=>r.toReference()),inputsDeclarations:this.inputsDeclarations.map(r=>r.toJSON()),inputs:this.inputs.map(r=>r.toJSON()),outputsDeclarations:this.outputsDeclarations.map(r=>r.toJSON()),outputs:this.outputs.map(r=>r.toJSON()),error:((t=this.error)==null?void 0:t.toJSON())||null,parent:this.parent.toReference()})}toJSONClone(e=Z){var r,a,d,o,l,u;let t;return(r=e.seenEntityMaps)!=null&&r.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||ct(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(a=e.seenEntities)!=null&&a.has(t)||(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:I.UUID.uuid(),createdAt:e.timestamp||T().toISOString(),author:I.sessionAuthor,previousVersion:null,deleted:!1,type:n.Search,name:this.name,query:this.query,description:this.description,x:this.x,y:this.y,successCalls:this.successCalls.map(h=>h.toJSONClone({...e,newId:null})),errorCalls:this.errorCalls.map(h=>h.toJSONClone({...e,newId:null})),calledBySuccess:this.calledBySuccess.map(h=>h.toReference({seenEntityMaps:e.seenEntityMaps})),calledByError:this.calledByError.map(h=>h.toReference({seenEntityMaps:e.seenEntityMaps})),calledByEntry:this.calledByEntry.map(h=>h.toReference({seenEntityMaps:e.seenEntityMaps})),inputsDeclarations:this.inputsDeclarations.map(h=>h.toJSONClone({...e,newId:null})),inputs:this.inputs.map(h=>h.toJSONClone({...e,newId:null})),outputsDeclarations:this.outputsDeclarations.map(h=>h.toJSONClone({...e,newId:null})),outputs:this.outputs.map(h=>h.toJSONClone({...e,newId:null})),error:((u=this.error)==null?void 0:u.toJSONClone({...e,newId:null}))||null,parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps})})}toReference(e=Z){var r;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+I.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=Z){var r;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,query:this.query,x:this.x,y:this.y,inputs:this.inputs.map(a=>a.toReference(e)),inputsDeclarations:this.inputsDeclarations.map(a=>a.toReference(e)),outputs:this.outputs.map(a=>a.toReference(e)),outputsDeclarations:this.outputsDeclarations.map(a=>a.toReference(e)),successCalls:this.successCalls.map(a=>a.toReference(e)),errorCalls:this.errorCalls.map(a=>a.toReference(e)),calledBySuccess:this.calledBySuccess.map(a=>a.toReference(e)),calledByError:this.calledByError.map(a=>a.toReference(e)),calledByEntry:this.calledByEntry.map(a=>a.toReference(e)),error:this.error?this.error.toReference(e):null,parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.successCalls.flatMap(r=>r.toFlatJSON(e)),...this.errorCalls.flatMap(r=>r.toFlatJSON(e)),...this.inputs.flatMap(r=>r.toFlatJSON(e)),...this.inputsDeclarations.flatMap(r=>r.toFlatJSON(e)),...this.outputs.flatMap(r=>r.toFlatJSON(e)),...this.outputsDeclarations.flatMap(r=>r.toFlatJSON(e)),...this.calledBy.flatMap(r=>r.toFlatJSON(e)),...this.error?this.error.toFlatJSON(e):[]])}toGenerationTarget(){const e=this.parent.type===n.Project?void 0:this.parent.id;return{id:this.id,name:this.name,description:this.description,type:this.type,query:this.query,calledByEntry:this.calledByEntry.map(t=>t.id),calledBySuccess:this.calledBySuccess.map(t=>t.id),calledByError:this.calledByError.map(t=>t.id),parent:e}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...this.successCalls.flatMap(r=>r.toFlatGenerationTarget(e)),...this.errorCalls.flatMap(r=>r.toFlatGenerationTarget(e)),...this.inputs.flatMap(r=>r.toFlatGenerationTarget(e)),...this.inputsDeclarations.flatMap(r=>r.toFlatGenerationTarget(e)),...this.outputs.flatMap(r=>r.toFlatGenerationTarget(e)),...this.outputsDeclarations.flatMap(r=>r.toFlatGenerationTarget(e)),...this.error?this.error.toFlatGenerationTarget(e):[]])}clearErrors(){var e;return this.errors=[],this.inputsDeclarations.forEach(t=>t.clearErrors()),this.inputs.forEach(t=>t.clearErrors()),this.outputs.forEach(t=>t.clearErrors()),this.successCalls.forEach(t=>t.clearErrors()),this.errorCalls.forEach(t=>t.clearErrors()),(e=this.error)==null||e.clearErrors(),this}validate(){const e=dq(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){return[...this.errors,...this.inputsDeclarations.flatMap(t=>t.getErrors()),...this.inputs.flatMap(t=>t.getErrors()),...this.outputsDeclarations.flatMap(t=>t.getErrors()),...this.outputs.flatMap(t=>t.getErrors()),...this.error?this.error.getErrors():[]]}getShallowErrors(){return this.errors}clone(e=this.project.addChangeSet(new R(this.project,"",T().toISOString(),this,!0,"clone-entity")),t=null,r=null,a=!0){var C,U,G,_;let d=ft(t,this);const o=this.toJSON(),l=r||I.UUID.uuid();o.inputs=[];const u=l.split("-id"),h=u[u.length-1||0]||l;o.id=l,o.version=I.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 c=lt(o,d);t?c.setParent(t,null):c.setParent(this.parent,null),a&&c.subscribe(),c.initChildren(e),e==null||e.add(c,b.Added);const v=(C=this.inputsDeclarations)==null?void 0:C.map(($,k)=>$.clone(e,this,h+"-input-declaration-"+k+"-id",a));c.inputsDeclarations=v;const E=(U=this.outputsDeclarations)==null?void 0:U.map(($,k)=>$.clone(e,this,h+"-output-declaration-"+k+"-id",a));c.outputsDeclarations=E;const O=(G=this.inputs)==null?void 0:G.map(($,k)=>$.clone(e,c,h+"-input-map-"+k+"-id",a));c.inputs=O;const w=(_=this.outputs)==null?void 0:_.map(($,k)=>$.clone(e,c,h+"-output-map-"+k+"-id",a));return c.outputs=w,this.error&&(c.error=this.error.clone(e,c,h+"-error-map-id",a)),e==null||e.attemptAutoclose("clone-entity",this.id),c}syncInputMaps(e=this.project.addChangeSet(new R(this.project,"",T().toISOString(),this,!0,"sync-input-maps"))){const t=[],r=[],a=[],d=[];return this.inputsDeclarations.forEach(o=>{if(!this.inputs.find(u=>{var h;return((h=u.declaration)==null?void 0:h.id)===o.id})){const u={id:I.UUID.uuid(),version:I.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:I.sessionAuthor,previousVersion:null,deleted:!1,type:n.InputMap,declaration:o.toJSON(),readsValue:null,defaultValue:null,index:this.inputs.length,name:null,description:null,parent:this.toReference()},h=V(u,this.project);h.setParent(this,e),h.initChildren(e),e==null||e.add(h,b.Added),h.addSelfToProject(e),t.push(this),r.push(h)}}),this.inputs.forEach(o=>{if(!this.inputsDeclarations.find(u=>{var h;return u.id===((h=o.declaration)==null?void 0:h.id)})){const{updated:u,removed:h}=o.remove({ignoreUpstream:!1},e);u.push(...u),a.push(...h)}}),e==null||e.attemptAutoclose("sync-input-maps",this.id),{updated:p(t),added:p(r),removed:p(a),affected:p(d),self:this}}};f(Ze,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>e,APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...r)=>null}),f(Ze,"type",n.Search),f(Ze,"USER_MANAGED_PARENT_TYPES",[...mt,n.Project]),f(Ze,"PARENT_TYPES",[...Ze.USER_MANAGED_PARENT_TYPES]),f(Ze,"MUTABLE_BASE_PROPERTIES",["name","description","query"]),f(Ze,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),f(Ze,"BASE_PROPERTIES",[...Ze.MUTABLE_BASE_PROPERTIES,...Ze.INMUTABLE_BASE_PROPERTIES]),f(Ze,"MUTABLE_META_PROPERTIES",[...Ze.MUTABLE_BASE_PROPERTIES,"x","y"]),f(Ze,"INMUTABLE_META_PROPERTIES",[...Ze.INMUTABLE_BASE_PROPERTIES]),f(Ze,"META_PROPERTIES",[...Ze.MUTABLE_META_PROPERTIES,...Ze.INMUTABLE_META_PROPERTIES]),f(Ze,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry"]),f(Ze,"INMUTABLE_UPSTREAM_PROPERTIES",["parent"]),f(Ze,"UPSTREAM_PROPERTIES",[...Ze.MUTABLE_UPSTREAM_PROPERTIES,...Ze.INMUTABLE_UPSTREAM_PROPERTIES]),f(Ze,"MUTABLE_DOWNSTREAM_PROPERTIES",["successCalls","errorCalls","inputsDeclarations","inputs","outputsDeclarations","outputs","error"]),f(Ze,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),f(Ze,"DOWNSTREAM_PROPERTIES",[...Ze.MUTABLE_DOWNSTREAM_PROPERTIES,...Ze.INMUTABLE_DOWNSTREAM_PROPERTIES]),f(Ze,"PROPERTIES",[...rr.META_PROPERTIES,...rr.UPSTREAM_PROPERTIES,...rr.DOWNSTREAM_PROPERTIES]);let ji=Ze;function lq(i){const s=q3(),e=i.toJSON();s.safeParse(e).success,i.functions.forEach(a=>a.validate()),i.events.forEach(a=>a.validate());const r=[];return ze(i.errors,r)}const Se=class Se extends rt{constructor(e,t){super(e);f(this,"initialData");f(this,"id");f(this,"name");f(this,"description",null);f(this,"x");f(this,"y");f(this,"type",n.InstalledProject);f(this,"implements");f(this,"functions",[]);f(this,"events",[]);f(this,"parent");f(this,"errors",[]);f(this,"project");f(this,"detachedDependents",{});f(this,"knownVersions",null);f(this,"activeVersion",!1);f(this,"initialized",!1);f(this,"startedInitialization",!1);this.initialData=e,this.project=t,this.id=e.id,this.name=e.name,this.description=e.description,this.x=e.x,this.y=e.y,this.implements=e.implements}static fromGenerationTarget(e,t){const r=t,a={id:e.id,version:I.UUID.uuid(),createdAt:T().toISOString(),author:I.sessionAuthor,previousVersion:null,deleted:!1,name:e.name,type:n.InstalledProject,description:e.description,functions:[],events:[],implements:{entityId:e.implements,version:I.UUID.uuid(),entityType:n.Project,type:n.GenericReference,id:I.UUID.uuid()},x:0,y:0,parent:r},d=V(a,t);return d.setParent(r,null),d.initChildren(null),d}static validateGenerationTarget(e,t){let r=JSON.parse(JSON.stringify(e));const a=[];return a.push(...ot(r)),{errors:a,modifiedData:r}}validateGeneratedUpdate(e){const t=[];return e.parent&&t.push(new P({id:`${this.id}--${A.InvalidParentUpdate}`,code:A.InvalidParentUpdate,severity:D.Error,message:`Entity of type '${this.type}' with id '${this.id}' cannot have the 'parent' property updated. The 'parent' on an installed project, must be the root project as it is a globally declared entity.`,issue:null})),{errors:t,modifiedData:e}}subscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]||(this.detachedDependents[t.entity.id]=t)}),this}syncDependents(){const e=[],t=[],r=[],a=[];return Object.values(this.detachedDependents).forEach(d=>{const o=d.entity.afterAllChildrenInitialized();e.push(...o.updated),t.push(...o.added),r.push(...o.removed),a.push(...o.affected)}),{updated:p(e),added:p(t),removed:p(r),affected:p(a),self:this}}onDetachedDependencyRemoved(e,t,r){const a=[],d=[],o=[],l=[];return{updated:p(a),added:p(d),removed:p(o),affected:p(l),self:this}}onDetachedDependencyRestored(e,t,r){const a=[],d=[],o=[],l=[];return{updated:p(a),added:p(d),removed:p(o),affected:p(l),self:this}}subscribeToDependencies(){return this}increaseVersion(e){if(e&&!T(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&T(e).isSame(T(this.createdAt))?this:(this.previousVersion=this.version,this.version=I.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t,r;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new Se(this,this.project);return(r=this.knownVersions)==null||r.set(this.version,e),e.functions=this.functions,e.events=this.events,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],r=[],a=[],d=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),r.push(...o.added),a.push(...o.removed)}return{updated:p(t),added:p(r),removed:p(a),affected:p(d),self:this}}async restoreVersion(e){var l;const t=[],r=[],a=[],d=[];if(this.version===e)return{updated:p(t),added:p(r),removed:p(a),affected:p(d),self:this};if(!this.knownVersions){const u=new Map;for(const[h,c]of this.knownVersions||new Map){if(u.set(h,c),c.activeVersion=!1,c.knownVersions)for(const[v,E]of c.knownVersions)u.set(v,E);c.knownVersions=null}}let o=(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 Se(u,this.project)}return this.metaSync(o.toShallowJSON(),null),this.functions=o.functions,this.events=o.events,this.parent=o.parent,{updated:p(t),added:p(r),removed:p(a),affected:p(d),self:this}}hydrateAncestors(){const e=[],t=[],r=[],a=[];if(this.initialData.parent){const d=B(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 throw new Error(`${this.type} with id '${this.id}' must have a 'parent'`);return{updated:p(e),added:p(t),removed:p(r),affected:p(a),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new R(this.project,"",T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],r=[],a=[],d=[];return this.initialized=!0,this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:p(t),added:p(r),removed:p(a),affected:p(d),self:this}}addSelfToProject(e=this.project.addChangeSet(new R(this.project,"",T().toISOString(),this,!0,"add-self-to-project"))){const t=[this],r=[],a=[],d=[];return this.project.addInstalledProject(this),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:p(t),added:p(r),removed:p(a),affected:p(d),self:this}}setParent(e,t=this.project.addChangeSet(new R(this.project,"",T().toISOString(),this,!0,"set-parent"))){var r;return((r=this.parent)==null?void 0:r.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,b.Updated),t==null||t.attemptAutoclose("set-parent",this.id))),this}initChildren(e=this.project.addChangeSet(new R(this.project,"",T().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.functions=this.initialData.functions.map(t=>{const r=V(t,this.project);return r.setParent(this,null),r.initChildren(e),r}),this.events=this.initialData.events.map(t=>{const r=V(t,this.project);return r.setParent(this,null),r.initChildren(e),r}),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this)}subscribe(){return this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new R(this.project,"",T().toISOString(),this,!0,"sync-meta"))){const r=dt(this,e);return e.deleted===!0&&!this.deleted?t==null||t.add(this,b.Removed):e.deleted===!1&&this.deleted?t==null||t.add(this,b.Added):r&&(t==null||t.add(this,b.Updated)),super.metaSync(e),this.x=e.x||this.x,this.y=e.y||this.y,t==null||t.attemptAutoclose("sync-meta",this.id),this}async APILoad(e=L,...t){return await Se.repository.APILoad(this.id,...t),this}async APICreate(e=L,...t){return await Se.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=L,...t){return await Se.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=L,...t){return await Se.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=L,...t){return await Se.repository.APIClone(this.id,...t),this}async APILoadVersion(e=L,t,...r){return await Se.repository.APILoadVersion(this.id,t,...r)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new R(this.project,"",T().toISOString(),this,!0,"remove-entity"))){const r=[],a=[],d=[],o=[];return t!=null&&t.hasRemoved(this.id)?(t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(a.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(l=>{const{updated:u,removed:h,added:c}=l.entity.onDetachedDependencyRemoved(this,l.field,t);r.push(...u),a.push(...h),d.push(...c)}),this.functions.forEach(l=>{const{updated:u,removed:h}=l.remove({ignoreUpstream:!1},t);r.push(...u),a.push(...h)}),this.events.forEach(l=>{const{updated:u,removed:h}=l.remove({ignoreUpstream:!1},t);r.push(...u),a.push(...h)}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:p(o),self:this})}restore({}={},e=this.project.addChangeSet(new R(this.project,"",T().toISOString(),this,!0,"restore-entity"))){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),this.functions.forEach(t=>{t.restore({},e)}),this.events.forEach(t=>{t.restore({},e)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this})}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.functions.flatMap(r=>r.toFlat(e)),...this.events.flatMap(r=>r.toFlat(e))])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.functions.flatMap(r=>r.toFlatIds(e)),...this.events.flatMap(r=>r.toFlatIds(e))])}toJSON(e=new Set){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,implements:this.implements,functions:this.functions.map(t=>t.toJSON(e)),events:this.events.map(t=>t.toJSON(e)),parent:this.parent.toReference(),x:this.x,y:this.y})}toJSONClone(e=Z){var r,a,d,o,l;let t;return(r=e.seenEntityMaps)!=null&&r.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||ct(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(a=e.seenEntities)!=null&&a.has(t)||(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:I.UUID.uuid(),createdAt:e.timestamp||T().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,implements:this.implements,functions:this.functions.map(u=>u.toJSONClone({...e,newId:null})),events:this.events.map(u=>u.toJSONClone({...e,newId:null})),parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps}),x:this.x,y:this.y})}toReference(e=Z){var r;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+I.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=Z){var r;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,x:this.x,y:this.y,implements:this.implements,functions:this.functions.map(a=>a.toReference(e)),events:this.events.map(a=>a.toReference(e)),parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.functions.flatMap(r=>r.toFlatJSON(e)),...this.events.flatMap(r=>r.toFlatJSON(e))])}toGenerationTarget(){return{id:this.id,name:this.name,description:this.description,type:this.type,implements:this.implements.id}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...this.functions.flatMap(r=>r.toFlatGenerationTarget(e)),...this.events.flatMap(r=>r.toFlatGenerationTarget(e))])}clearErrors(){return this.errors=[],this.functions.forEach(e=>e.clearErrors()),this.events.forEach(e=>e.clearErrors()),this}validate(){const e=lq(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){return[...this.errors,...this.functions.flatMap(t=>t.getErrors()),...this.events.flatMap(t=>t.getErrors())]}getShallowErrors(){return this.errors}clone(e=this.project.addChangeSet(new R(this.project,"",T().toISOString(),this,!0,"clone-entity")),t=null,r=null,a=!0){var O,w;let d=ft(t,this);const o=this.toJSON(),l=r||I.UUID.uuid();o.functions=[],o.events=[];const u=l.split("-id"),h=u[u.length-1||0]||l;o.id=l,o.version=I.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 c=lt(o,d);t&&c.setParent(t,null),a&&c.subscribe(),c.initChildren(e),e==null||e.add(c,b.Added);const v=(O=this.functions)==null?void 0:O.map((C,U)=>C.clone(e,c,h+"-exported-function-declaration-"+U+"-id",a));c.functions=v;const E=(w=this.events)==null?void 0:w.map((C,U)=>C.clone(e,c,h+"-exported-event-"+U+"-id",a));return c.events=E,e==null||e.attemptAutoclose("clone-entity",this.id),c}};f(Se,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>e,APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...r)=>null}),f(Se,"type",n.InstalledProject),f(Se,"USER_MANAGED_PARENT_TYPES",[n.Project]),f(Se,"PARENT_TYPES",[...Se.USER_MANAGED_PARENT_TYPES]),f(Se,"MUTABLE_BASE_PROPERTIES",[]),f(Se,"INMUTABLE_BASE_PROPERTIES",["id","version","name","description","type","createdAt","author","previousVersion"]),f(Se,"BASE_PROPERTIES",[...Se.MUTABLE_BASE_PROPERTIES,...Se.INMUTABLE_BASE_PROPERTIES]),f(Se,"MUTABLE_META_PROPERTIES",["x","y"]),f(Se,"INMUTABLE_META_PROPERTIES",[...Se.INMUTABLE_BASE_PROPERTIES]),f(Se,"META_PROPERTIES",[...Se.MUTABLE_META_PROPERTIES,...Se.INMUTABLE_META_PROPERTIES]),f(Se,"MUTABLE_UPSTREAM_PROPERTIES",[]),f(Se,"INMUTABLE_UPSTREAM_PROPERTIES",["implements","parent"]),f(Se,"UPSTREAM_PROPERTIES",[...Se.MUTABLE_UPSTREAM_PROPERTIES,...Se.INMUTABLE_UPSTREAM_PROPERTIES]),f(Se,"MUTABLE_DOWNSTREAM_PROPERTIES",["functions","events"]),f(Se,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),f(Se,"DOWNSTREAM_PROPERTIES",[...Se.MUTABLE_DOWNSTREAM_PROPERTIES,...Se.INMUTABLE_DOWNSTREAM_PROPERTIES]),f(Se,"PROPERTIES",[...Se.META_PROPERTIES,...Se.UPSTREAM_PROPERTIES,...Se.DOWNSTREAM_PROPERTIES]);let Gi=Se;function uq(i){var o;const s=n3(),e=i.toJSON();s.safeParse(e).success,i.inputs.forEach(l=>l.validate()),i.outputs.forEach(l=>l.validate()),(o=i.error)==null||o.validate();const r=fi(i),a=pq(i),d=[...r,...a];return ze(i.errors,d)}function pq(i){const s=[],e=wd(i.parent,null),t=e==null?void 0:e.entity;if(!t)s.push(ye({id:`${i.id}--${j.InternalCallParentMissingDataType}`,code:j.InternalCallParentMissingDataType,severity:D.Error,message:`Entity of type "${i.type}" with id "${i.id}", belongs to a variable whose data type entity doesn't contain its declaration method (function-declaration) its id "${i.declaration}".`,issue:null,entity:i}).error);else if(![n.DefinitionEntity,n.BuiltInBaseEntity,n.PrimitiveEntity].includes(t.type))s.push(ye({id:`${i.id}--${j.InternalCallParentDeclarationEntityInvalidType}`,code:j.InternalCallParentDeclarationEntityInvalidType,severity:D.Error,message:`Entity of type "${i.type}" with id "${i.id}", belongs to a variable whose data type 'entity' is not a definition entity, built-in base entity or primitive entity.
|
|
112
112
|
This variable's data-type has an 'entity' field that references an entity with id '${t.id}' and of type '${t.type}'.`,issue:null,entity:i}).error);else{const r=Jc(t),a=[];[n.DefinitionEntity,n.BuiltInBaseEntity,n.PrimitiveEntity].includes(t.type)&&a.push(...t.getAllInteractiveMethods());let d="";r?t.methods.length?d=`
|
|
@@ -134,8 +134,8 @@ export declare class FunctionDeclarationState extends VersionedState implements
|
|
|
134
134
|
clone(changeSet?: ChangeSet | null, parent?: InstalledProjectState | ProjectState | DefinitionEntityState | LoopState | null, newId?: string | null, subscribe?: boolean, cloneBody?: boolean): FunctionDeclarationState;
|
|
135
135
|
getVariableInstances(): VariableInstanceState[];
|
|
136
136
|
getArgument(id: EntityId): ArgumentDeclarationState | null;
|
|
137
|
-
createCall(parent?: EntityWithLogicScopeState | ProjectState, overrides?: Partial<IFunctionCallTransfer>): FunctionCallState;
|
|
138
|
-
createInternalCall(parent: VariableState, overrides?: Partial<IInternalCallTransfer>): InternalCallState;
|
|
137
|
+
createCall(changeSet?: ChangeSet | null, parent?: EntityWithLogicScopeState | ProjectState, overrides?: Partial<IFunctionCallTransfer>): FunctionCallState;
|
|
138
|
+
createInternalCall(changeSet: (ChangeSet | null) | undefined, parent: VariableState, overrides?: Partial<IInternalCallTransfer>): InternalCallState;
|
|
139
139
|
addReturnStatement(statement: ReturnStatementState): FunctionDeclarationState;
|
|
140
140
|
removeReturnStatement(statement: ReturnStatementState): FunctionDeclarationState;
|
|
141
141
|
getUniqueReturnDeclarations(): ReturnDeclarationState[];
|
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.6185",
|
|
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",
|