@elyx-code/project-logic-tree 0.0.6424 → 0.0.6425
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 +21 -21
- package/dist/index.umd.cjs +2 -2
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -77314,7 +77314,7 @@ This is likely an incorrect strategy, either the '${this.type}' entity doesn't n
|
|
|
77314
77314
|
};
|
|
77315
77315
|
}
|
|
77316
77316
|
toJSON(i = /* @__PURE__ */ new Set()) {
|
|
77317
|
-
var a, o;
|
|
77317
|
+
var a, o, p;
|
|
77318
77318
|
return i.has(this.id) ? this.toReference() : (i.add(this.id), {
|
|
77319
77319
|
id: this.id,
|
|
77320
77320
|
version: this.version,
|
|
@@ -77325,30 +77325,30 @@ This is likely an incorrect strategy, either the '${this.type}' entity doesn't n
|
|
|
77325
77325
|
type: this.type,
|
|
77326
77326
|
index: this.index,
|
|
77327
77327
|
successCalls: this.successCalls.map(
|
|
77328
|
-
(
|
|
77328
|
+
(e) => e.toJSON(i)
|
|
77329
77329
|
),
|
|
77330
77330
|
errorCalls: this.errorCalls.map(
|
|
77331
|
-
(
|
|
77331
|
+
(e) => e.toJSON(i)
|
|
77332
77332
|
),
|
|
77333
77333
|
calledBySuccess: this.calledBySuccess.map(
|
|
77334
|
-
(
|
|
77334
|
+
(e) => e.toReference()
|
|
77335
77335
|
),
|
|
77336
|
-
calledByError: this.calledByError.map((
|
|
77337
|
-
calledByEntry: this.calledByEntry.map((
|
|
77336
|
+
calledByError: this.calledByError.map((e) => e.toReference()),
|
|
77337
|
+
calledByEntry: this.calledByEntry.map((e) => e.toReference()),
|
|
77338
77338
|
process: (a = this.process) == null ? void 0 : a.toJSON(i),
|
|
77339
|
-
declaration: this.declaration.toJSON(i),
|
|
77339
|
+
declaration: (o = this.declaration) == null ? void 0 : o.toJSON(i),
|
|
77340
77340
|
inputs: this.inputs.map(
|
|
77341
|
-
(
|
|
77341
|
+
(e) => e.toJSON(i)
|
|
77342
77342
|
),
|
|
77343
77343
|
outputs: this.outputs.map(
|
|
77344
|
-
(
|
|
77344
|
+
(e) => e.toJSON(i)
|
|
77345
77345
|
),
|
|
77346
77346
|
parent: this.parent.toReference(),
|
|
77347
|
-
error: (
|
|
77347
|
+
error: (p = this.error) == null ? void 0 : p.toJSON(i)
|
|
77348
77348
|
});
|
|
77349
77349
|
}
|
|
77350
77350
|
toJSONClone(i = ke) {
|
|
77351
|
-
var o, p, e, y, v, E, b;
|
|
77351
|
+
var o, p, e, y, v, E, b, A, C;
|
|
77352
77352
|
let a;
|
|
77353
77353
|
return (o = i.seenEntityMaps) != null && o.has(this.id) ? a = i.seenEntityMaps.get(this.id) : (a = i.newId || qr(this, this.project, i.uuidStrategy), i.seenEntityMaps && i.seenEntityMaps.set(this.id, a)), (p = i.seenEntities) != null && p.has(a) || (e = i.seenEntities) != null && e.has(this.id) ? this.toReference({ seenEntityMaps: i.seenEntityMaps }) : ((y = i.seenEntities) == null || y.add(a), (v = i.seenEntities) == null || v.add(this.id), {
|
|
77354
77354
|
id: a,
|
|
@@ -77360,38 +77360,38 @@ This is likely an incorrect strategy, either the '${this.type}' entity doesn't n
|
|
|
77360
77360
|
type: this.type,
|
|
77361
77361
|
index: this.index,
|
|
77362
77362
|
successCalls: this.successCalls.map(
|
|
77363
|
-
(
|
|
77363
|
+
(N) => N.toJSONClone({
|
|
77364
77364
|
...i,
|
|
77365
77365
|
newId: null
|
|
77366
77366
|
})
|
|
77367
77367
|
),
|
|
77368
77368
|
errorCalls: this.errorCalls.map(
|
|
77369
|
-
(
|
|
77369
|
+
(N) => N.toJSONClone({
|
|
77370
77370
|
...i,
|
|
77371
77371
|
newId: null
|
|
77372
77372
|
})
|
|
77373
77373
|
),
|
|
77374
77374
|
calledBySuccess: this.calledBySuccess.map(
|
|
77375
|
-
(
|
|
77375
|
+
(N) => N.toReference({ seenEntityMaps: i.seenEntityMaps })
|
|
77376
77376
|
),
|
|
77377
77377
|
calledByError: this.calledByError.map(
|
|
77378
|
-
(
|
|
77378
|
+
(N) => N.toReference({ seenEntityMaps: i.seenEntityMaps })
|
|
77379
77379
|
),
|
|
77380
77380
|
calledByEntry: this.calledByEntry.map(
|
|
77381
|
-
(
|
|
77381
|
+
(N) => N.toReference({ seenEntityMaps: i.seenEntityMaps })
|
|
77382
77382
|
),
|
|
77383
77383
|
process: (E = this.process) == null ? void 0 : E.toJSONClone({
|
|
77384
77384
|
...i,
|
|
77385
77385
|
newId: null
|
|
77386
77386
|
}),
|
|
77387
|
-
declaration: this.project.getBuiltIn(this.declaration.id) ? this.declaration.toJSON() : this.declaration.toJSONClone({ ...i, newId: null }),
|
|
77387
|
+
declaration: this.project.getBuiltIn(this.declaration.id) ? (b = this.declaration) == null ? void 0 : b.toJSON() : (A = this.declaration) == null ? void 0 : A.toJSONClone({ ...i, newId: null }),
|
|
77388
77388
|
inputs: this.inputs.map(
|
|
77389
|
-
(
|
|
77389
|
+
(N) => N.toJSONClone({ ...i, newId: null })
|
|
77390
77390
|
),
|
|
77391
77391
|
outputs: this.outputs.map(
|
|
77392
|
-
(
|
|
77392
|
+
(N) => N.toJSONClone({ ...i, newId: null })
|
|
77393
77393
|
),
|
|
77394
|
-
error: (
|
|
77394
|
+
error: (C = this.error) == null ? void 0 : C.toJSONClone({
|
|
77395
77395
|
...i,
|
|
77396
77396
|
newId: null
|
|
77397
77397
|
}),
|
|
@@ -103803,7 +103803,7 @@ function se(d, u) {
|
|
|
103803
103803
|
case ai.DeletePersistedEntity:
|
|
103804
103804
|
return "Delete entry from database";
|
|
103805
103805
|
case ai.CreatePersistedEntity:
|
|
103806
|
-
return "Save
|
|
103806
|
+
return "Save new data entry in database";
|
|
103807
103807
|
case ai.UpdatePersistedEntity:
|
|
103808
103808
|
return "Update entity data to database";
|
|
103809
103809
|
default:
|
package/dist/index.umd.cjs
CHANGED
|
@@ -129,7 +129,7 @@ ${To}`);const V=o.declaration;if(!a.get(V))p.push(new ee({id:`${o.id}--${k.Refer
|
|
|
129
129
|
The declaration of the internal-call must be a 'function-declaration' entity which exists as a method in the entity of the data-type of the parent variable.${$}`})):p.push(new ee({id:`${o.id}--${ae.InternalCallDeclarationNotFoundInParentDatatypeEntity}`,code:ae.InternalCallDeclarationNotFoundInParentDatatypeEntity,severity:q.Error,message:`Entity of type "${o.type}" with id "${o.id}", belongs to a variable whose data type entity doesn't contain its declaration method (function-declaration) with id "${o.declaration}".${$}`}))}}(v.inputs.length||v.outputs.length||v.internalCalls.length)&&p.push(new ee({id:`${o.id}--${k.InvalidInternalCallParentRelation}`,code:k.InvalidInternalCallParentRelation,severity:q.Error,message:`Entity of type "${o.type}" with id "${o.id}", can only be added to a variable declaration or variable instance parent if the parent doesn't already have inputs, outputs or other internal calls.
|
|
130
130
|
If you need a new variable-instance for this, consider using the 'implement_variable_instance' generation action to create one and give it a caller.
|
|
131
131
|
The you can attach the new internal-call to it.`}))}return p.push(...e.errors,...Br(o)),{errors:p,modifiedData:o}}validateGeneratedUpdate(i){const a=[];return i.parent&&a.push(new ee({id:`${this.id}--${k.InvalidParentUpdate}`,code:k.InvalidParentUpdate,severity:q.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.
|
|
132
|
-
This is likely an incorrect strategy, either the '${this.type}' entity doesn't need to be updated or it should be deleted and a new one created in the desired parent.`})),{errors:a,modifiedData:i}}subscribeDependents(i){return i.forEach(a=>{this.detachedDependents[a.entity.id]||(this.detachedDependents[a.entity.id]=a)}),this}unsubscribeDependents(i){return i.forEach(a=>{this.detachedDependents[a.entity.id]&&delete this.detachedDependents[a.entity.id]}),this}syncDependents(i=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"sync-dependents"))){const a=[],o=[],p=[],e=[];return Object.values(this.detachedDependents).forEach(y=>{const v=y.entity.afterAllChildrenInitialized(i);a.push(...v.updated),o.push(...v.added),p.push(...v.removed),e.push(...v.affected)}),i==null||i.attemptAutoclose("sync-dependents",this.id),{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}onDetachedDependencyRemoved(i,a,o){const p=[],e=[],y=[],v=[];if(a==="declaration"){const{updated:E,added:b,removed:A}=this.remove({ignoreUpstream:!1},o);p.push(...E),e.push(...b),y.push(...A)}return{updated:R(p),added:R(e),removed:R(y),affected:R(v),self:this}}onDetachedDependencyRestored(i,a,o){const p=[],e=[],y=[],v=[];if(a==="declaration"){const{updated:E,added:b,removed:A}=this.restore({},o);p.push(...E),e.push(...b),y.push(...A)}return{updated:R(p),added:R(e),removed:R(y),affected:R(v),self:this}}unsubscribeFromDependencies(){return this.declaration.unsubscribeDependents([{entity:this,field:"declaration"}]),this}subscribeToDependencies(){return this.declaration.subscribeDependents([{entity:this,field:"declaration"}]),this}increaseVersion(i){if(i&&!L(i).isValid())throw new Error(`The shared timestamp '${i}' is not a valid ISO 8601 date string.`);return i&&L(i).isSame(L(this.createdAt))?this:(this.previousVersion=this.version,this.version=N.UUID.uuid(),this.createdAt=L(i).toISOString()||L().toISOString(),this)}captureVersion(){var a;const i=((a=this.knownVersions)==null?void 0:a.get(this.version))||new Gt(this,this.project);return i.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,i):new Map([[this.version,i]]),i.inputs=[...this.inputs],i.outputs=[...this.outputs],i.error=this.error,i.process=this.process,i.successCalls=[...this.successCalls],i.errorCalls=[...this.errorCalls],i.calledBySuccess=[...this.calledBySuccess],i.calledByError=[...this.calledByError],i.calledByEntry=[...this.calledByEntry],i.declaration=this.declaration,i.parent=this.parent,this}recursiveCaptureUpstreamVersions(i){const a=[],o=[],p=[],e=[];if(this.parent){this.parent.increaseVersion(i);const y=this.parent.recursiveCaptureUpstreamVersions(i);a.push(this.parent,...y.updated),o.push(...y.added),p.push(...y.removed)}return{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}async restoreVersion(i){var v;const a=[],o=[],p=[],e=[];if(this.version===i)return{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this};if(!this.knownVersions){const E=new Map;for(const[b,A]of this.knownVersions||new Map){if(E.set(b,A),A.activeVersion=!1,A.knownVersions)for(const[$,V]of A.knownVersions)E.set($,V);A.knownVersions=null}}let y=(v=this.knownVersions)==null?void 0:v.get(i);if(!y){const E=await this.APILoadVersion({},i);if(!E)throw new Error(`Version with id '${i}' for entity with id '${this.id}' not found.`);y=new Gt(E,this.project)}return this.metaSync(y.toShallowJSON(),null),this.previousVersion=y.previousVersion,this.version=y.version,this.createdAt=y.createdAt,this.author=y.author,this.deleted=y.deleted,this.inputs=y.inputs,this.outputs=y.outputs,this.error=y.error,this.process=y.process,this.successCalls=y.successCalls,this.errorCalls=y.errorCalls,this.calledBySuccess=y.calledBySuccess,this.calledByError=y.calledByError,this.calledByEntry=y.calledByEntry,this.declaration=y.declaration,this.parent=y.parent,{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}updateWithShallowTransfer(i,a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"update-with-shallow-transfer"))){if(this.metaSync(i,a),this.version=i.version,this.createdAt=i.createdAt,this.author=i.author,this.deleted=i.deleted,this.previousVersion=i.previousVersion,this.unsubscribeFromDependencies(),i.parent){const o=J(i.parent),p=this.project.get(o),e=this.parent;if(e&&e.id!==(p==null?void 0:p.id)&&this.removeFromParent(a),p)this.setParent(p,a);else throw a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${o}' that isn't found in the project`)}else throw a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(i.declaration){const o=J(i.declaration),p=this.project.get(o);p&&this.setDeclaration(p)}return i.calledByEntry.forEach(o=>{const p=J(o),e=this.project.get(p);e&&(this.addEntryCaller(e,a),e.addCall(this,a))}),[...this.calledByEntry].forEach(o=>{i.calledByEntry.find(e=>J(e)===o.id)||(this.removeCaller(o,a),o.removeCall(this,a))}),i.calledBySuccess.forEach(o=>{const p=J(o),e=this.project.get(p);e&&(this.addSuccessCaller(e,a),e.addSuccessCall(this,a))}),[...this.calledBySuccess].forEach(o=>{i.calledBySuccess.find(e=>J(e)===o.id)||(this.removeCaller(o,a),o.removeCall(this,a))}),i.calledByError.forEach(o=>{const p=J(o),e=this.project.get(p);e&&(this.addErrorCaller(e,a),e.addErrorCall(this,a))}),[...this.calledBySuccess].forEach(o=>{i.calledBySuccess.find(e=>J(e)===o.id)||(this.removeCaller(o,a),o.removeCall(this,a))}),this.captureVersion(),this.subscribeToDependencies(),a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),this}hydrateAncestors(){const i=[],a=[],o=[],p=[];if(this.initialData.parent){const e=J(this.initialData.parent),y=this.project.get(e);if(y)this.setParent(y,null),i.push(y);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${e}' that isn't found in the project`)}else throw new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(this.initialData.declaration){const e=J(this.initialData.declaration),y=this.project.get(e);y&&(this.setDeclaration(y),i.push(y))}return this.initialData.calledByEntry.forEach(e=>{const y=J(e),v=this.project.get(y);v&&this.addEntryCaller(v,null)}),this.initialData.calledBySuccess.forEach(e=>{const y=J(e),v=this.project.get(y);v&&this.addSuccessCaller(v,null)}),this.initialData.calledByError.forEach(e=>{const y=J(e),v=this.project.get(y);v&&this.addErrorCaller(v,null)}),{updated:R(i),added:R(a),removed:R(o),affected:R(p),self:this}}afterAllChildrenInitialized(i=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"after-all-children-initialized"))){const a=[],o=[],p=[],e=[];this.initialized=!0;const{updated:y,added:v,removed:E}=this.syncInputs(i),{updated:b,added:A,removed:$}=this.syncOutputs(i);return a.push(...y,...b),o.push(...v,...A),p.push(...E,...$),this.captureVersion(),i==null||i.attemptAutoclose("after-all-children-initialized",this.id),{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}addSelfToProject(i=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-self-to-project"))){var y;const a=[this],o=[],p=[],e=[];return this.parent.addInternalCall(this),e.push(this.parent),(y=this.process)==null||y.writesValues.forEach(v=>{v.setValueWriter(this.process,i),a.push(v)}),this.successCalls.forEach(v=>{v.addSuccessCaller(this,i),a.push(v)}),this.errorCalls.forEach(v=>{v.addErrorCaller(this,i),a.push(v)}),this.calledBySuccess.forEach(v=>{v.addSuccessCall(this,i),a.push(v)}),this.calledByError.forEach(v=>{v.addErrorCall(this,i),a.push(v)}),this.calledByEntry.forEach(v=>{v.addCall(this,i),a.push(v)}),this.subscribe(),this.subscribeToDependencies(),i==null||i.attemptAutoclose("add-self-to-project",this.id),{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}removeInput(i,a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-input"))){const o=this.inputs.findIndex(p=>p.id===i.id);return o>-1&&(this.inputs.splice(o,1),a&&(a==null||a.add(this,S.Affected))),a==null||a.attemptAutoclose("remove-input",this.id),this}addInput(i,a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-input"))){return this.inputs.includes(i)?(a==null||a.attemptAutoclose("add-input",this.id),this):(this.inputs.push(i),a==null||a.add(this,S.Affected),a==null||a.attemptAutoclose("add-input",this.id),this)}addOutput(i,a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-output"))){return this.outputs.includes(i)?(a==null||a.attemptAutoclose("add-output",this.id),this):(this.outputs.push(i),a==null||a.add(this,S.Affected),a==null||a.attemptAutoclose("add-output",this.id),this)}removeOutput(i,a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-output"))){const o=this.outputs.findIndex(p=>p.id===i.id);return o>-1&&(this.outputs.splice(o,1),a&&(a==null||a.add(this,S.Affected))),a==null||a.attemptAutoclose("remove-output",this.id),this}addValueReader(i,a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-value-reader"))){var o;return this.process&&!this.process.writesValues.includes(i)&&((o=this.process)==null||o.addValueReader(i,a),a==null||a.add(this,S.Affected)),a==null||a.attemptAutoclose("add-value-reader",this.id),this}removeValueReader(i,a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-value-reader"))){var o;return this.process&&this.process.writesValues.includes(i)&&((o=this.process)==null||o.removeValueReader(i,a),a==null||a.add(this,S.Affected)),a==null||a.attemptAutoclose("remove-value-reader",this.id),this}addSuccessCaller(i,a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-success-caller")),o=!1){return this.calledBySuccess.find(p=>p.id===i.id)||(this.calledBySuccess.push(i),a==null||a.add(this,S.Updated),o&&We(this,a)),a==null||a.attemptAutoclose("add-success-caller",this.id),this}addErrorCaller(i,a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-error-caller")),o=!1){return this.calledByError.find(p=>p.id===i.id)||(this.calledByError.push(i),a==null||a.add(this,S.Updated),o&&We(this,a)),a==null||a.attemptAutoclose("add-error-caller",this.id),this}addEntryCaller(i,a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-entry-caller")),o=!1){return this.calledByEntry.find(p=>p.id===i.id)||(this.calledByEntry.push(i),a==null||a.add(this,S.Updated),o&&We(this,a)),a==null||a.attemptAutoclose("add-entry-caller",this.id),this}addErrorCall(i,a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-error-call")),o=!1){return this.errorCalls.find(p=>p.id===i.id)||(this.errorCalls.push(i),o&&We(this,a),a==null||a.add(this,S.Affected)),a==null||a.attemptAutoclose("add-error-call",this.id),this}addSuccessCall(i,a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-success-call")),o=!1){return this.successCalls.find(p=>p.id===i.id)||(this.successCalls.push(i),o&&We(this,a),a==null||a.add(this,S.Affected)),a==null||a.attemptAutoclose("add-success-call",this.id),this}removeCall(i,a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-call")),o=!1){const p=this.successCalls.findIndex(y=>y.id===i.id);p>-1&&(this.successCalls.splice(p,1),a==null||a.add(this,S.Affected));const e=this.errorCalls.findIndex(y=>y.id===i.id);return e>-1&&(this.errorCalls.splice(e,1),a==null||a.add(this,S.Affected)),o&&We(this,a),a==null||a.attemptAutoclose("remove-call",this.id),this}removeCaller(i,a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-caller")),o=!1){return this.calledBySuccess=this.calledBySuccess.filter(p=>p.id!==i.id?!0:(a==null||a.add(this,S.Updated),a==null||a.add(p,S.Affected),!1)),this.calledByError=this.calledByError.filter(p=>p.id!==i.id?!0:(a==null||a.add(this,S.Updated),a==null||a.add(p,S.Affected),!1)),this.calledByEntry=this.calledByEntry.filter(p=>p.id!==i.id?!0:(a==null||a.add(this,S.Updated),a==null||a.add(p,S.Affected),!1)),o&&We(this,a),a==null||a.attemptAutoclose("remove-caller",this.id),this}setParent(i,a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"set-parent"))){var o;return((o=this.parent)==null?void 0:o.id)!==(i==null?void 0:i.id)&&(this.parent=i,a&&(a==null||a.add(this,S.Updated))),a==null||a.attemptAutoclose("set-parent",this.id),this}setDeclaration(i){return this.declaration=i,this}initChildren(i=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"init-children"))){if(this.initialized||this.startedInitialization)return this;if(this.startedInitialization=!0,this.initialData.parent.type!==f.GenericReference){const a=te(this.initialData.parent,this.project);this.setParent(a,null),this.parent.initChildren(i),this.parent.addInternalCall(this);const o=this.calledBy.find(p=>!!p.parent&&Mr.includes(p.parent.type));if(o){const p=te(o.parent,this.project);this.parent.setParent(p,null)}else if(!o&&!this.parent.calledBy.length)throw new Error("Parent of internal call parent could not be resolved")}return this.declaration=te(this.initialData.declaration,this.project),this.successCalls=this.initialData.successCalls.map(a=>{const o=te(a,this.project);if(o.addSuccessCaller(this),[f.BreakStatement,f.ContinueStatement].includes(o.type))o.setParent(this.parent.parent,null),o.initChildren(i);else if(o.type===f.ReturnStatement){const p=Wr(this.parent,this.project);o.setParent(p,null),o.initChildren(i)}else o.type!==f.InternalCall&&(o.setParent(this.parent.parent,null),o.initChildren(i));return o}),this.errorCalls=this.initialData.errorCalls.map(a=>{const o=te(a,this.project);if(o.addErrorCaller(this),[f.BreakStatement,f.ContinueStatement].includes(o.type))o.setParent(this.parent.parent.parent,null),o.initChildren(i);else if(o.type===f.ReturnStatement){const p=Wr(this.parent,this.project);o.setParent(p,null),o.initChildren(i)}else o.type!==f.InternalCall&&(o.setParent(this.parent.parent,null),o.initChildren(i));return o}),this.inputs=this.initialData.inputs.map(a=>{const o=te(a,this.project);return o.setParent(this,null),o.initChildren(i),o}),this.outputs=this.initialData.outputs.map(a=>{const o=te(a,this.project);return o.setParent(this,null),o.initChildren(i),o}),this.initialData.error&&(this.error=te(this.initialData.error,this.project),this.error.setParent(this,null),this.error.initChildren(i)),this.initialData.process&&(this.process=te(this.initialData.process,this.project),this.process.setParent(this,null),this.process.initChildren(i)),this.subscribeToDependencies(),this.afterAllChildrenInitialized(i),i==null||i.attemptAutoclose("init-children",this.id),this}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(i,a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"meta-sync"))){const o=Ur(this,i),p=this.toMeta();return this.index=i.index||(i.index!==0?p.index:0),super.metaSync(i),i.deleted===!0&&!p.deleted?a==null||a.add(this,S.Removed):i.deleted===!1&&p.deleted?a==null||a.add(this,S.Added):o&&(a==null||a.add(this,S.Updated)),a==null||a.attemptAutoclose("meta-sync",this.id),this}async APILoad(i=ve,...a){return await Gt.repository.APILoad(this.id,...a),this}async APICreate(i=ve,...a){return await Gt.repository.APICreate(this.toShallowJSON(),...a),this}async APIUpdate(i=ve,...a){return await Gt.repository.APIUpdate(this.toShallowJSON(),...a),this}async APIDelete(i=ve,...a){return await Gt.repository.APIDelete(this.toShallowJSON(),...a),this}async APIClone(i=ve,...a){return await Gt.repository.APIClone(this.id,...a),this}async APILoadVersion(i=ve,a,...o){return await Gt.repository.APILoadVersion(this.id,a,...o)}removeFromParent(i=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-from-parent"))){const a=[],o=[],p=[],e=[];return this.parent&&(this.parent.removeInternalCall(this,i),e.push(this.parent)),i==null||i.attemptAutoclose("remove-from-parent",this.id),{added:R(p),updated:R(a),removed:R(o),affected:R(e),self:this}}remove({ignoreUpstream:i}={ignoreUpstream:!1},a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-entity"))){var v;const o=[],p=[],e=[],y=[];if(a!=null&&a.hasRemoved(this.id))return a==null||a.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(p.push(this),this.unsubscribe(),this.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},a),Object.values(this.detachedDependents).forEach(E=>{const{updated:b,removed:A,added:$}=E.entity.onDetachedDependencyRemoved(this,E.field,a);o.push(...b),p.push(...A),e.push(...$)}),this.process){const{updated:E,removed:b}=(v=this.process)==null?void 0:v.remove({ignoreUpstream:!0},a);o.push(...E),p.push(...b)}if(this.inputs.forEach(E=>{const{updated:b,removed:A}=E.remove({ignoreUpstream:!0},a);o.push(...b),p.push(...A)}),this.outputs.forEach(E=>{const{updated:b,removed:A}=E.remove({ignoreUpstream:!0},a);o.push(...b),p.push(...A)}),this.error){const{updated:E,removed:b}=this.error.remove({ignoreUpstream:!0},a);o.push(...E),p.push(...b)}if(this.successCalls.forEach(E=>{o.push(E),E.removeCaller(this,a)}),this.errorCalls.forEach(E=>{o.push(E),E.removeCaller(this,a)}),!i){const E=this.removeFromParent(a);e.push(...E.added),o.push(...E.updated),p.push(...E.removed),y.push(...E.affected),this.calledBy.forEach(b=>{o.push(b),b.removeCall(this,a)})}return a==null||a.attemptAutoclose("remove-entity",this.id),{added:R(e),updated:R(o),removed:R(p),affected:R(y),self:this}}restore({}={},i=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"restore-entity"))){const a=[],o=[],p=[],e=[];if(i!=null&&i.hasAdded(this.id))return i==null||i.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},i),Object.values(this.detachedDependents).forEach(y=>{const{updated:v,removed:E,added:b}=y.entity.onDetachedDependencyRestored(this,y.field,i);o.push(...v),p.push(...E),a.push(...b)}),this.process){const{updated:y}=this.process.restore({},i);o.push(...y)}return this.inputs.forEach(y=>{const{updated:v}=y.restore({},i);o.push(...v)}),this.outputs.forEach(y=>{const{updated:v}=y.restore({},i);o.push(...v)}),this.successCalls.forEach(y=>{o.push(y),y.addSuccessCaller(this,i)}),this.errorCalls.forEach(y=>{o.push(y),y.addErrorCaller(this,i)}),this.calledBySuccess.forEach(y=>{o.push(y),y.addSuccessCall(this,i)}),this.calledByError.forEach(y=>{o.push(y),y.addErrorCall(this,i)}),this.calledByEntry.forEach(y=>{o.push(y),y.addCall(this,i)}),i==null||i.attemptAutoclose("restore-entity",this.id),{added:R(a),updated:R(o),removed:R(p),affected:R(e),self:this}}toFlat(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this,...this.successCalls.flatMap(o=>o.toFlat(i)),...this.errorCalls.flatMap(o=>o.toFlat(i)),...this.inputs.flatMap(o=>o.toFlat(i)),...this.outputs.flatMap(o=>o.toFlat(i)),...this.calledBy.flatMap(o=>o.toFlat(i)),...this.process?this.process.toFlat(i):[],...this.error?this.error.toFlat(i):[],...this.parent.toFlat(i)])}toFlatIds(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.id,...this.successCalls.flatMap(o=>o.toFlatIds(i)),...this.errorCalls.flatMap(o=>o.toFlatIds(i)),...this.inputs.flatMap(o=>o.toFlatIds(i)),...this.outputs.flatMap(o=>o.toFlatIds(i)),...this.calledBy.flatMap(o=>o.toFlatIds(i)),...this.process?this.process.toFlatIds(i):[],...this.error?this.error.toFlatIds(i):[],...this.parent.toFlatIds(i)])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,index:this.index,type:this.type}}toJSON(i=new Set){var a,o;return i.has(this.id)?this.toReference():(i.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,index:this.index,successCalls:this.successCalls.map(p=>p.toJSON(i)),errorCalls:this.errorCalls.map(p=>p.toJSON(i)),calledBySuccess:this.calledBySuccess.map(p=>p.toReference()),calledByError:this.calledByError.map(p=>p.toReference()),calledByEntry:this.calledByEntry.map(p=>p.toReference()),process:(a=this.process)==null?void 0:a.toJSON(i),declaration:this.declaration.toJSON(i),inputs:this.inputs.map(p=>p.toJSON(i)),outputs:this.outputs.map(p=>p.toJSON(i)),parent:this.parent.toReference(),error:(o=this.error)==null?void 0:o.toJSON(i)})}toJSONClone(i=ke){var o,p,e,y,v,E,b;let a;return(o=i.seenEntityMaps)!=null&&o.has(this.id)?a=i.seenEntityMaps.get(this.id):(a=i.newId||Sr(this,this.project,i.uuidStrategy),i.seenEntityMaps&&i.seenEntityMaps.set(this.id,a)),(p=i.seenEntities)!=null&&p.has(a)||(e=i.seenEntities)!=null&&e.has(this.id)?this.toReference({seenEntityMaps:i.seenEntityMaps}):((y=i.seenEntities)==null||y.add(a),(v=i.seenEntities)==null||v.add(this.id),{id:a,version:N.UUID.uuid(),createdAt:i.timestamp||L().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,index:this.index,successCalls:this.successCalls.map(A=>A.toJSONClone({...i,newId:null})),errorCalls:this.errorCalls.map(A=>A.toJSONClone({...i,newId:null})),calledBySuccess:this.calledBySuccess.map(A=>A.toReference({seenEntityMaps:i.seenEntityMaps})),calledByError:this.calledByError.map(A=>A.toReference({seenEntityMaps:i.seenEntityMaps})),calledByEntry:this.calledByEntry.map(A=>A.toReference({seenEntityMaps:i.seenEntityMaps})),process:(E=this.process)==null?void 0:E.toJSONClone({...i,newId:null}),declaration:this.project.getBuiltIn(this.declaration.id)?this.declaration.toJSON():this.declaration.toJSONClone({...i,newId:null}),inputs:this.inputs.map(A=>A.toJSONClone({...i,newId:null})),outputs:this.outputs.map(A=>A.toJSONClone({...i,newId:null})),error:(b=this.error)==null?void 0:b.toJSONClone({...i,newId:null}),parent:this.parent.calledBy.length||this.parent.readsValue?this.parent.toReference({seenEntityMaps:i.seenEntityMaps}):this.parent.toJSONClone({...i,newId:null})})}toReference(i=ke){var o;let a=this.id;return(o=i.seenEntityMaps)!=null&&o.has(this.id)&&(a=i.seenEntityMaps.get(this.id)),{id:a+"--"+N.UUID.uuid()+"--ref",type:f.GenericReference,entityId:a,version:this.version,entityType:this.type}}toShallowJSON(i=ke){var o;let a=this.id;return(o=i.seenEntityMaps)!=null&&o.has(this.id)&&(a=i.seenEntityMaps.get(this.id)),{id:a,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,index:this.index,process:this.process?this.process.toReference(i):null,inputs:this.inputs.map(p=>p.toReference(i)),outputs:this.outputs.map(p=>p.toReference(i)),declaration:this.declaration.toReference(i),successCalls:this.successCalls.map(p=>p.toReference(i)),errorCalls:this.errorCalls.map(p=>p.toReference(i)),calledBySuccess:this.calledBySuccess.map(p=>p.toReference(i)),calledByError:this.calledByError.map(p=>p.toReference(i)),calledByEntry:this.calledByEntry.map(p=>p.toReference(i)),error:this.error?this.error.toReference(i):null,parent:this.parent.toReference(i)}}toFlatJSON(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.toShallowJSON(),...this.process?this.process.toFlatJSON(i):[],...this.successCalls.flatMap(o=>o.toFlatJSON(i)),...this.errorCalls.flatMap(o=>o.toFlatJSON(i)),...this.inputs.flatMap(o=>o.toFlatJSON(i)),...this.outputs.flatMap(o=>o.toFlatJSON(i)),...this.calledBy.flatMap(o=>o.toFlatJSON(i)),...this.error?this.error.toFlatJSON(i):[],...this.parent.toFlatJSON(i)])}toGenerationTarget(){return{id:this.id,type:this.type,calledByEntry:this.calledByEntry.map(i=>i.id),calledBySuccess:this.calledBySuccess.map(i=>i.id),calledByError:this.calledByError.map(i=>i.id),declaration:this.declaration.id,parent:this.parent.id}}toFlatGenerationTarget(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.toGenerationTarget(),...this.process?this.process.toFlatGenerationTarget(i):[],...this.successCalls.flatMap(o=>o.toFlatGenerationTarget(i)),...this.errorCalls.flatMap(o=>o.toFlatGenerationTarget(i)),...this.inputs.flatMap(o=>o.toFlatGenerationTarget(i)),...this.outputs.flatMap(o=>o.toFlatGenerationTarget(i)),...this.error?this.error.toFlatGenerationTarget(i):[],...this.parent.toFlatGenerationTarget(i)])}clearErrors(){var i,a;return this.errors=[],this.inputs.forEach(o=>o.clearErrors()),this.outputs.forEach(o=>o.clearErrors()),this.successCalls.forEach(o=>o.clearErrors()),this.errorCalls.forEach(o=>o.clearErrors()),(i=this.process)==null||i.clearErrors(),(a=this.error)==null||a.clearErrors(),this}validate(){const i=mF(this);return this.errors=i,{success:!0}}getErrors(){return[...this.errors,...this.inputs.flatMap(a=>a.getErrors()),...this.outputs.flatMap(a=>a.getErrors()),...this.error?this.error.getErrors():[],...this.process?this.process.getErrors():[]]}getShallowErrors(){return this.errors}clone(i=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"clone-entity")),a=null,o=null,p=!0){var U,G;let e=Gr(a,this);const y=this.toJSON(),v=o||N.UUID.uuid();y.inputs=[];const E=v.split("-id"),b=E[E.length-1||0]||v;y.id=v,y.version=N.UUID.uuid();const A=lr(y,e);a?A.setParent(a,null):A.setParent(this.parent,null),p&&A.subscribe(),A.initChildren(i),i==null||i.add(A,S.Added);const $=(U=this.inputs)==null?void 0:U.map((K,Z)=>K.clone(i,A,b+"-input-map-"+Z+"-id",p));A.inputs=$;const V=(G=this.outputs)==null?void 0:G.map((K,Z)=>K.clone(i,A,b+"-output-map-"+Z+"-id",p));return A.outputs=V,this.error&&(A.error=this.error.clone(i,A,b+"-error-map-id",p)),this.process&&(A.process=this.process.clone(i,A,b+"-process-id",p)),i==null||i.attemptAutoclose("clone-entity",this.id),A}removeUnrecognizedInputs(i=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-unrecognized-inputs"))){const a=[],o=[],p=[],e=[];return this.inputs.forEach(v=>{if(!this.declaration.inputs.find(b=>{var A;return b.id===((A=v.declaration)==null?void 0:A.id)})){const b=v.remove({ignoreUpstream:!1},i);p.push(...b.removed),a.push(...b.updated)}}),this.inputs.filter((v,E)=>{const b=this.inputs.findIndex($=>$.declaration===v.declaration&&$!==v);if(b===-1)return!1;const A=this.inputs[b];return L(A==null?void 0:A.createdAt).isSame(L(v.createdAt))?E>b:!!L(A==null?void 0:A.createdAt).isAfter(v.createdAt)}).forEach(v=>{const E=v.remove({ignoreUpstream:!1},i);p.push(...E.removed),a.push(...E.updated)}),i==null||i.attemptAutoclose("remove-unrecognized-inputs",this.id),{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}removeUnrecognizedOutputs(i=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-unrecognized-outputs"))){const a=[],o=[],p=[],e=[];return this.outputs.forEach(v=>{if(!this.declaration.getUniqueReturnDeclarations().find(b=>{var A;return b.id===((A=v.declaration)==null?void 0:A.id)})){const b=v.remove({ignoreUpstream:!1},i);p.push(...b.removed),a.push(...b.updated)}}),this.outputs.filter((v,E)=>{const b=this.outputs.findIndex($=>$.declaration===v.declaration&&$!==v);if(b===-1)return!1;const A=this.outputs[b];return L(A==null?void 0:A.createdAt).isSame(L(v.createdAt))?E>b:!!L(A==null?void 0:A.createdAt).isAfter(v.createdAt)}).forEach(v=>{const E=v.remove({ignoreUpstream:!1},i);p.push(...E.removed),a.push(...E.updated)}),i==null||i.attemptAutoclose("remove-unrecognized-outputs",this.id),{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}syncInputs(i=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"sync-missing-fixed-inputs"))){const a=[],o=[],p=[],e=[],y=this.declaration.inputs.filter(A=>!this.inputs.find($=>$.declaration.id===A.id));this.inputs.sort((A,$)=>A.index-$.index),y.forEach(A=>{this.inputs.forEach(U=>{U.index>=A.index&&U.metaSync({index:U.index+1},i)});const $={id:N.UUID.uuid(),version:N.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||L().toISOString(),author:N.sessionAuthor,previousVersion:null,deleted:!1,type:f.InputMap,declaration:A.toJSON(),readsValue:null,defaultValue:null,index:A.index,name:null,codeName:null,description:null,parent:this.toReference()},V=te($,this.project);V.setParent(this,i),V.initChildren(i),i==null||i.add(V,S.Added),V.addSelfToProject(i),o.push(V)}),this.inputs.sort((A,$)=>A.index-$.index);const{updated:v,added:E,removed:b}=this.removeUnrecognizedInputs(i);return a.push(...v),o.push(...E),p.push(...b),i==null||i.attemptAutoclose("sync-missing-fixed-inputs",this.id),{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}syncOutputs(i=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"sync-missing-fixed-outputs"))){const a=[],o=[],p=[],e=[],y=[];this.outputs=this.initialData.outputs.map($=>{const V=te($,this.project);return y.push(V.index),V.setParent(this,null),V.initChildren(i),V});const v=this.declaration.getUniqueReturnDeclarations().filter($=>!this.outputs.find(V=>V.declaration.id===$.id));this.outputs.sort(($,V)=>$.index-V.index),v.forEach(($,V)=>{this.outputs.forEach(Z=>{Z.index>=$.index&&Z.index++});const U=y.includes($.index)?this.outputs.length-1+V:$.index,G={id:N.UUID.uuid(),version:N.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||L().toISOString(),author:N.sessionAuthor,previousVersion:null,deleted:!1,type:f.OutputMap,declaration:$.toJSON(),defaultValue:null,writesValues:[],index:U,parent:this.toReference()},K=te(G,this.project);K.setParent(this,i),K.initChildren(i),i==null||i.add(K,S.Added),K.addSelfToProject(i)}),this.outputs.sort(($,V)=>$.index-V.index);const{updated:E,added:b,removed:A}=this.removeUnrecognizedOutputs(i);return a.push(...E),o.push(...b),p.push(...A),i==null||i.attemptAutoclose("sync-missing-fixed-outputs",this.id),{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}getUnusedInputs(){return this.inputs.filter(i=>i.suggestion||!i.readsValue&&!i.defaultValue)}getUnusedOutputs(){return this.outputs.filter(i=>i.suggestion||!i.writesValues.length)}getUsedInputs(){return this.inputs.filter(i=>!i.suggestion&&(i.readsValue||i.defaultValue))}getUsedOutputs(){return this.outputs.filter(i=>!i.suggestion&&i.writesValues.length)}};g(Gt,"repository",{APICreate:async(i,...a)=>i,APIUpdate:async(i,...a)=>i,APIDelete:async(i,...a)=>i,APIClone:async(i,...a)=>{},APILoad:async(i,...a)=>null,APILoadVersion:async(i,a,...o)=>null}),g(Gt,"type",f.InternalCall),g(Gt,"USER_MANAGED_PARENT_TYPES",[...mt]),g(Gt,"PARENT_TYPES",[...Gt.USER_MANAGED_PARENT_TYPES]),g(Gt,"MUTABLE_BASE_PROPERTIES",[]),g(Gt,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),g(Gt,"BASE_PROPERTIES",[...Gt.MUTABLE_BASE_PROPERTIES,...Gt.INMUTABLE_BASE_PROPERTIES]),g(Gt,"MUTABLE_META_PROPERTIES",[...Gt.MUTABLE_BASE_PROPERTIES,"index"]),g(Gt,"INMUTABLE_META_PROPERTIES",[...Gt.INMUTABLE_BASE_PROPERTIES]),g(Gt,"META_PROPERTIES",[...Gt.MUTABLE_META_PROPERTIES,...Gt.INMUTABLE_META_PROPERTIES]),g(Gt,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry"]),g(Gt,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","declaration"]),g(Gt,"UPSTREAM_PROPERTIES",[...Gt.MUTABLE_UPSTREAM_PROPERTIES,...Gt.INMUTABLE_UPSTREAM_PROPERTIES]),g(Gt,"MUTABLE_DOWNSTREAM_PROPERTIES",["inputs","outputs","writesValues","successCalls","errorCalls","error"]),g(Gt,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),g(Gt,"DOWNSTREAM_PROPERTIES",[...Gt.MUTABLE_DOWNSTREAM_PROPERTIES,...Gt.INMUTABLE_DOWNSTREAM_PROPERTIES]),g(Gt,"PROPERTIES",[...Gt.META_PROPERTIES,...Gt.UPSTREAM_PROPERTIES,...Gt.DOWNSTREAM_PROPERTIES]);let fo=Gt;function gF(d){const u=rye(),i=d.toJSON();u.safeParse(i).success;const o=[...Io(d)];return vr(d.errors,o)}const iEe=Object.freeze(Object.defineProperty({__proto__:null,validate:gF},Symbol.toStringTag,{value:"Module"}));function Li(d){return d.declaration||d}function sEe(d){return d.type===f.VariableDeclaration?d.parent===d.project?"global-declaration":"local-declaration":d.declaration.parent===d.project?"global-instance":"local-instance"}function LA(d,u){const i=[];if(d.type===f.Project)i.push(...d.variableDeclarations);else{const o=ti(Rt(d)).filter(p=>p.type===f.VariableDeclaration);i.push(...o),d.parent&&(Mr.includes(d.parent.type)||d.parent.type===f.Project)&&i.push(...LA(d.parent))}return i}var DF=(d=>(d.Declaration="declaration",d.DataTypeEntity="data-type-entity",d))(DF||{});const St=class St extends Nr{constructor(i,a){super(i);g(this,"initialData");g(this,"id");g(this,"index");g(this,"name",null);g(this,"codeName",null);g(this,"description",null);g(this,"type",f.InputMap);g(this,"defaultValue",null);g(this,"readsValue",null);g(this,"dataType",null);g(this,"declaration",null);g(this,"project");g(this,"errors",[]);g(this,"parent");g(this,"detachedDependents",{});g(this,"knownVersions",null);g(this,"activeVersion",!1);g(this,"initialized",!1);g(this,"startedInitialization",!1);g(this,"suggestion",!1);g(this,"_codeNativeValueValidation",null);this.initialData=i,this.project=a,this.id=i.id,this.index=i.index,this.name=i.name||null,this.codeName=i.codeName||null,this.description=i.description||null}static new(i=null){return{id:N.UUID.uuid(),version:N.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||L().toISOString(),author:(i==null?void 0:i.author)||N.sessionAuthor,previousVersion:null,deleted:!1,type:f.InputMap,name:"",codeName:null,description:"",declaration:null,index:0,readsValue:null,defaultValue:null,parent:null}}static fromGenerationTarget(i,a){const o=J(i.parent),p=a.get(o);let e=null;if(i.declaration){const b=J(i.declaration);e=a.get(b)}let y=null;if(i.readsValue){const b=J(i.readsValue);y=a.get(b)}const v={id:i.id,version:N.UUID.uuid(),createdAt:L().toISOString(),author:N.sessionAuthor,previousVersion:null,deleted:!1,name:i.name||null,type:f.InputMap,index:(p.inputs||[]).length,codeName:i.codeName||null,description:i.description||null,declaration:e,readsValue:y,defaultValue:null,parent:p},E=te(v,a);return E.setParent(p,null),E}static validateGenerationTarget(i,a){var b;let o=JSON.parse(JSON.stringify(i));const p=[],e=oi(o,{parent:{list:!1,types:[...fr,f.InputMap]}},a);o=e.modifiedData;const y=a.get(o.parent),v=o.declaration&&(a.get(o.declaration)||a.getBuiltIn(o.declaration)),E=((y==null?void 0:y.inputs)||[]).find(A=>{var $;return o.declaration&&(($=A.declaration)==null?void 0:$.id)===o.declaration});if(o.declaration?v?[f.Property,f.ArgumentDeclaration,f.ValueDescriptor].includes(v.type)?y&&v.type===f.ArgumentDeclaration&&![f.FunctionCall,f.Search,f.InternalCall].includes(y.type)?p.push(new ee({id:`${o.id}--${k.InvalidInputMapDeclaration}`,code:k.InvalidInputMapDeclaration,severity:q.Error,message:`Entity of type '${f.InputMap}' with id '${o.id}' has a 'declaration' property pointing to an entity with type '${f.ArgumentDeclaration}' with id '${o.declaration}'.
|
|
132
|
+
This is likely an incorrect strategy, either the '${this.type}' entity doesn't need to be updated or it should be deleted and a new one created in the desired parent.`})),{errors:a,modifiedData:i}}subscribeDependents(i){return i.forEach(a=>{this.detachedDependents[a.entity.id]||(this.detachedDependents[a.entity.id]=a)}),this}unsubscribeDependents(i){return i.forEach(a=>{this.detachedDependents[a.entity.id]&&delete this.detachedDependents[a.entity.id]}),this}syncDependents(i=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"sync-dependents"))){const a=[],o=[],p=[],e=[];return Object.values(this.detachedDependents).forEach(y=>{const v=y.entity.afterAllChildrenInitialized(i);a.push(...v.updated),o.push(...v.added),p.push(...v.removed),e.push(...v.affected)}),i==null||i.attemptAutoclose("sync-dependents",this.id),{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}onDetachedDependencyRemoved(i,a,o){const p=[],e=[],y=[],v=[];if(a==="declaration"){const{updated:E,added:b,removed:A}=this.remove({ignoreUpstream:!1},o);p.push(...E),e.push(...b),y.push(...A)}return{updated:R(p),added:R(e),removed:R(y),affected:R(v),self:this}}onDetachedDependencyRestored(i,a,o){const p=[],e=[],y=[],v=[];if(a==="declaration"){const{updated:E,added:b,removed:A}=this.restore({},o);p.push(...E),e.push(...b),y.push(...A)}return{updated:R(p),added:R(e),removed:R(y),affected:R(v),self:this}}unsubscribeFromDependencies(){return this.declaration.unsubscribeDependents([{entity:this,field:"declaration"}]),this}subscribeToDependencies(){return this.declaration.subscribeDependents([{entity:this,field:"declaration"}]),this}increaseVersion(i){if(i&&!L(i).isValid())throw new Error(`The shared timestamp '${i}' is not a valid ISO 8601 date string.`);return i&&L(i).isSame(L(this.createdAt))?this:(this.previousVersion=this.version,this.version=N.UUID.uuid(),this.createdAt=L(i).toISOString()||L().toISOString(),this)}captureVersion(){var a;const i=((a=this.knownVersions)==null?void 0:a.get(this.version))||new Gt(this,this.project);return i.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,i):new Map([[this.version,i]]),i.inputs=[...this.inputs],i.outputs=[...this.outputs],i.error=this.error,i.process=this.process,i.successCalls=[...this.successCalls],i.errorCalls=[...this.errorCalls],i.calledBySuccess=[...this.calledBySuccess],i.calledByError=[...this.calledByError],i.calledByEntry=[...this.calledByEntry],i.declaration=this.declaration,i.parent=this.parent,this}recursiveCaptureUpstreamVersions(i){const a=[],o=[],p=[],e=[];if(this.parent){this.parent.increaseVersion(i);const y=this.parent.recursiveCaptureUpstreamVersions(i);a.push(this.parent,...y.updated),o.push(...y.added),p.push(...y.removed)}return{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}async restoreVersion(i){var v;const a=[],o=[],p=[],e=[];if(this.version===i)return{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this};if(!this.knownVersions){const E=new Map;for(const[b,A]of this.knownVersions||new Map){if(E.set(b,A),A.activeVersion=!1,A.knownVersions)for(const[$,V]of A.knownVersions)E.set($,V);A.knownVersions=null}}let y=(v=this.knownVersions)==null?void 0:v.get(i);if(!y){const E=await this.APILoadVersion({},i);if(!E)throw new Error(`Version with id '${i}' for entity with id '${this.id}' not found.`);y=new Gt(E,this.project)}return this.metaSync(y.toShallowJSON(),null),this.previousVersion=y.previousVersion,this.version=y.version,this.createdAt=y.createdAt,this.author=y.author,this.deleted=y.deleted,this.inputs=y.inputs,this.outputs=y.outputs,this.error=y.error,this.process=y.process,this.successCalls=y.successCalls,this.errorCalls=y.errorCalls,this.calledBySuccess=y.calledBySuccess,this.calledByError=y.calledByError,this.calledByEntry=y.calledByEntry,this.declaration=y.declaration,this.parent=y.parent,{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}updateWithShallowTransfer(i,a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"update-with-shallow-transfer"))){if(this.metaSync(i,a),this.version=i.version,this.createdAt=i.createdAt,this.author=i.author,this.deleted=i.deleted,this.previousVersion=i.previousVersion,this.unsubscribeFromDependencies(),i.parent){const o=J(i.parent),p=this.project.get(o),e=this.parent;if(e&&e.id!==(p==null?void 0:p.id)&&this.removeFromParent(a),p)this.setParent(p,a);else throw a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${o}' that isn't found in the project`)}else throw a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(i.declaration){const o=J(i.declaration),p=this.project.get(o);p&&this.setDeclaration(p)}return i.calledByEntry.forEach(o=>{const p=J(o),e=this.project.get(p);e&&(this.addEntryCaller(e,a),e.addCall(this,a))}),[...this.calledByEntry].forEach(o=>{i.calledByEntry.find(e=>J(e)===o.id)||(this.removeCaller(o,a),o.removeCall(this,a))}),i.calledBySuccess.forEach(o=>{const p=J(o),e=this.project.get(p);e&&(this.addSuccessCaller(e,a),e.addSuccessCall(this,a))}),[...this.calledBySuccess].forEach(o=>{i.calledBySuccess.find(e=>J(e)===o.id)||(this.removeCaller(o,a),o.removeCall(this,a))}),i.calledByError.forEach(o=>{const p=J(o),e=this.project.get(p);e&&(this.addErrorCaller(e,a),e.addErrorCall(this,a))}),[...this.calledBySuccess].forEach(o=>{i.calledBySuccess.find(e=>J(e)===o.id)||(this.removeCaller(o,a),o.removeCall(this,a))}),this.captureVersion(),this.subscribeToDependencies(),a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),this}hydrateAncestors(){const i=[],a=[],o=[],p=[];if(this.initialData.parent){const e=J(this.initialData.parent),y=this.project.get(e);if(y)this.setParent(y,null),i.push(y);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${e}' that isn't found in the project`)}else throw new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(this.initialData.declaration){const e=J(this.initialData.declaration),y=this.project.get(e);y&&(this.setDeclaration(y),i.push(y))}return this.initialData.calledByEntry.forEach(e=>{const y=J(e),v=this.project.get(y);v&&this.addEntryCaller(v,null)}),this.initialData.calledBySuccess.forEach(e=>{const y=J(e),v=this.project.get(y);v&&this.addSuccessCaller(v,null)}),this.initialData.calledByError.forEach(e=>{const y=J(e),v=this.project.get(y);v&&this.addErrorCaller(v,null)}),{updated:R(i),added:R(a),removed:R(o),affected:R(p),self:this}}afterAllChildrenInitialized(i=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"after-all-children-initialized"))){const a=[],o=[],p=[],e=[];this.initialized=!0;const{updated:y,added:v,removed:E}=this.syncInputs(i),{updated:b,added:A,removed:$}=this.syncOutputs(i);return a.push(...y,...b),o.push(...v,...A),p.push(...E,...$),this.captureVersion(),i==null||i.attemptAutoclose("after-all-children-initialized",this.id),{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}addSelfToProject(i=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-self-to-project"))){var y;const a=[this],o=[],p=[],e=[];return this.parent.addInternalCall(this),e.push(this.parent),(y=this.process)==null||y.writesValues.forEach(v=>{v.setValueWriter(this.process,i),a.push(v)}),this.successCalls.forEach(v=>{v.addSuccessCaller(this,i),a.push(v)}),this.errorCalls.forEach(v=>{v.addErrorCaller(this,i),a.push(v)}),this.calledBySuccess.forEach(v=>{v.addSuccessCall(this,i),a.push(v)}),this.calledByError.forEach(v=>{v.addErrorCall(this,i),a.push(v)}),this.calledByEntry.forEach(v=>{v.addCall(this,i),a.push(v)}),this.subscribe(),this.subscribeToDependencies(),i==null||i.attemptAutoclose("add-self-to-project",this.id),{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}removeInput(i,a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-input"))){const o=this.inputs.findIndex(p=>p.id===i.id);return o>-1&&(this.inputs.splice(o,1),a&&(a==null||a.add(this,S.Affected))),a==null||a.attemptAutoclose("remove-input",this.id),this}addInput(i,a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-input"))){return this.inputs.includes(i)?(a==null||a.attemptAutoclose("add-input",this.id),this):(this.inputs.push(i),a==null||a.add(this,S.Affected),a==null||a.attemptAutoclose("add-input",this.id),this)}addOutput(i,a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-output"))){return this.outputs.includes(i)?(a==null||a.attemptAutoclose("add-output",this.id),this):(this.outputs.push(i),a==null||a.add(this,S.Affected),a==null||a.attemptAutoclose("add-output",this.id),this)}removeOutput(i,a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-output"))){const o=this.outputs.findIndex(p=>p.id===i.id);return o>-1&&(this.outputs.splice(o,1),a&&(a==null||a.add(this,S.Affected))),a==null||a.attemptAutoclose("remove-output",this.id),this}addValueReader(i,a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-value-reader"))){var o;return this.process&&!this.process.writesValues.includes(i)&&((o=this.process)==null||o.addValueReader(i,a),a==null||a.add(this,S.Affected)),a==null||a.attemptAutoclose("add-value-reader",this.id),this}removeValueReader(i,a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-value-reader"))){var o;return this.process&&this.process.writesValues.includes(i)&&((o=this.process)==null||o.removeValueReader(i,a),a==null||a.add(this,S.Affected)),a==null||a.attemptAutoclose("remove-value-reader",this.id),this}addSuccessCaller(i,a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-success-caller")),o=!1){return this.calledBySuccess.find(p=>p.id===i.id)||(this.calledBySuccess.push(i),a==null||a.add(this,S.Updated),o&&We(this,a)),a==null||a.attemptAutoclose("add-success-caller",this.id),this}addErrorCaller(i,a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-error-caller")),o=!1){return this.calledByError.find(p=>p.id===i.id)||(this.calledByError.push(i),a==null||a.add(this,S.Updated),o&&We(this,a)),a==null||a.attemptAutoclose("add-error-caller",this.id),this}addEntryCaller(i,a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-entry-caller")),o=!1){return this.calledByEntry.find(p=>p.id===i.id)||(this.calledByEntry.push(i),a==null||a.add(this,S.Updated),o&&We(this,a)),a==null||a.attemptAutoclose("add-entry-caller",this.id),this}addErrorCall(i,a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-error-call")),o=!1){return this.errorCalls.find(p=>p.id===i.id)||(this.errorCalls.push(i),o&&We(this,a),a==null||a.add(this,S.Affected)),a==null||a.attemptAutoclose("add-error-call",this.id),this}addSuccessCall(i,a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-success-call")),o=!1){return this.successCalls.find(p=>p.id===i.id)||(this.successCalls.push(i),o&&We(this,a),a==null||a.add(this,S.Affected)),a==null||a.attemptAutoclose("add-success-call",this.id),this}removeCall(i,a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-call")),o=!1){const p=this.successCalls.findIndex(y=>y.id===i.id);p>-1&&(this.successCalls.splice(p,1),a==null||a.add(this,S.Affected));const e=this.errorCalls.findIndex(y=>y.id===i.id);return e>-1&&(this.errorCalls.splice(e,1),a==null||a.add(this,S.Affected)),o&&We(this,a),a==null||a.attemptAutoclose("remove-call",this.id),this}removeCaller(i,a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-caller")),o=!1){return this.calledBySuccess=this.calledBySuccess.filter(p=>p.id!==i.id?!0:(a==null||a.add(this,S.Updated),a==null||a.add(p,S.Affected),!1)),this.calledByError=this.calledByError.filter(p=>p.id!==i.id?!0:(a==null||a.add(this,S.Updated),a==null||a.add(p,S.Affected),!1)),this.calledByEntry=this.calledByEntry.filter(p=>p.id!==i.id?!0:(a==null||a.add(this,S.Updated),a==null||a.add(p,S.Affected),!1)),o&&We(this,a),a==null||a.attemptAutoclose("remove-caller",this.id),this}setParent(i,a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"set-parent"))){var o;return((o=this.parent)==null?void 0:o.id)!==(i==null?void 0:i.id)&&(this.parent=i,a&&(a==null||a.add(this,S.Updated))),a==null||a.attemptAutoclose("set-parent",this.id),this}setDeclaration(i){return this.declaration=i,this}initChildren(i=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"init-children"))){if(this.initialized||this.startedInitialization)return this;if(this.startedInitialization=!0,this.initialData.parent.type!==f.GenericReference){const a=te(this.initialData.parent,this.project);this.setParent(a,null),this.parent.initChildren(i),this.parent.addInternalCall(this);const o=this.calledBy.find(p=>!!p.parent&&Mr.includes(p.parent.type));if(o){const p=te(o.parent,this.project);this.parent.setParent(p,null)}else if(!o&&!this.parent.calledBy.length)throw new Error("Parent of internal call parent could not be resolved")}return this.declaration=te(this.initialData.declaration,this.project),this.successCalls=this.initialData.successCalls.map(a=>{const o=te(a,this.project);if(o.addSuccessCaller(this),[f.BreakStatement,f.ContinueStatement].includes(o.type))o.setParent(this.parent.parent,null),o.initChildren(i);else if(o.type===f.ReturnStatement){const p=Wr(this.parent,this.project);o.setParent(p,null),o.initChildren(i)}else o.type!==f.InternalCall&&(o.setParent(this.parent.parent,null),o.initChildren(i));return o}),this.errorCalls=this.initialData.errorCalls.map(a=>{const o=te(a,this.project);if(o.addErrorCaller(this),[f.BreakStatement,f.ContinueStatement].includes(o.type))o.setParent(this.parent.parent.parent,null),o.initChildren(i);else if(o.type===f.ReturnStatement){const p=Wr(this.parent,this.project);o.setParent(p,null),o.initChildren(i)}else o.type!==f.InternalCall&&(o.setParent(this.parent.parent,null),o.initChildren(i));return o}),this.inputs=this.initialData.inputs.map(a=>{const o=te(a,this.project);return o.setParent(this,null),o.initChildren(i),o}),this.outputs=this.initialData.outputs.map(a=>{const o=te(a,this.project);return o.setParent(this,null),o.initChildren(i),o}),this.initialData.error&&(this.error=te(this.initialData.error,this.project),this.error.setParent(this,null),this.error.initChildren(i)),this.initialData.process&&(this.process=te(this.initialData.process,this.project),this.process.setParent(this,null),this.process.initChildren(i)),this.subscribeToDependencies(),this.afterAllChildrenInitialized(i),i==null||i.attemptAutoclose("init-children",this.id),this}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(i,a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"meta-sync"))){const o=Ur(this,i),p=this.toMeta();return this.index=i.index||(i.index!==0?p.index:0),super.metaSync(i),i.deleted===!0&&!p.deleted?a==null||a.add(this,S.Removed):i.deleted===!1&&p.deleted?a==null||a.add(this,S.Added):o&&(a==null||a.add(this,S.Updated)),a==null||a.attemptAutoclose("meta-sync",this.id),this}async APILoad(i=ve,...a){return await Gt.repository.APILoad(this.id,...a),this}async APICreate(i=ve,...a){return await Gt.repository.APICreate(this.toShallowJSON(),...a),this}async APIUpdate(i=ve,...a){return await Gt.repository.APIUpdate(this.toShallowJSON(),...a),this}async APIDelete(i=ve,...a){return await Gt.repository.APIDelete(this.toShallowJSON(),...a),this}async APIClone(i=ve,...a){return await Gt.repository.APIClone(this.id,...a),this}async APILoadVersion(i=ve,a,...o){return await Gt.repository.APILoadVersion(this.id,a,...o)}removeFromParent(i=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-from-parent"))){const a=[],o=[],p=[],e=[];return this.parent&&(this.parent.removeInternalCall(this,i),e.push(this.parent)),i==null||i.attemptAutoclose("remove-from-parent",this.id),{added:R(p),updated:R(a),removed:R(o),affected:R(e),self:this}}remove({ignoreUpstream:i}={ignoreUpstream:!1},a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-entity"))){var v;const o=[],p=[],e=[],y=[];if(a!=null&&a.hasRemoved(this.id))return a==null||a.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(p.push(this),this.unsubscribe(),this.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},a),Object.values(this.detachedDependents).forEach(E=>{const{updated:b,removed:A,added:$}=E.entity.onDetachedDependencyRemoved(this,E.field,a);o.push(...b),p.push(...A),e.push(...$)}),this.process){const{updated:E,removed:b}=(v=this.process)==null?void 0:v.remove({ignoreUpstream:!0},a);o.push(...E),p.push(...b)}if(this.inputs.forEach(E=>{const{updated:b,removed:A}=E.remove({ignoreUpstream:!0},a);o.push(...b),p.push(...A)}),this.outputs.forEach(E=>{const{updated:b,removed:A}=E.remove({ignoreUpstream:!0},a);o.push(...b),p.push(...A)}),this.error){const{updated:E,removed:b}=this.error.remove({ignoreUpstream:!0},a);o.push(...E),p.push(...b)}if(this.successCalls.forEach(E=>{o.push(E),E.removeCaller(this,a)}),this.errorCalls.forEach(E=>{o.push(E),E.removeCaller(this,a)}),!i){const E=this.removeFromParent(a);e.push(...E.added),o.push(...E.updated),p.push(...E.removed),y.push(...E.affected),this.calledBy.forEach(b=>{o.push(b),b.removeCall(this,a)})}return a==null||a.attemptAutoclose("remove-entity",this.id),{added:R(e),updated:R(o),removed:R(p),affected:R(y),self:this}}restore({}={},i=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"restore-entity"))){const a=[],o=[],p=[],e=[];if(i!=null&&i.hasAdded(this.id))return i==null||i.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},i),Object.values(this.detachedDependents).forEach(y=>{const{updated:v,removed:E,added:b}=y.entity.onDetachedDependencyRestored(this,y.field,i);o.push(...v),p.push(...E),a.push(...b)}),this.process){const{updated:y}=this.process.restore({},i);o.push(...y)}return this.inputs.forEach(y=>{const{updated:v}=y.restore({},i);o.push(...v)}),this.outputs.forEach(y=>{const{updated:v}=y.restore({},i);o.push(...v)}),this.successCalls.forEach(y=>{o.push(y),y.addSuccessCaller(this,i)}),this.errorCalls.forEach(y=>{o.push(y),y.addErrorCaller(this,i)}),this.calledBySuccess.forEach(y=>{o.push(y),y.addSuccessCall(this,i)}),this.calledByError.forEach(y=>{o.push(y),y.addErrorCall(this,i)}),this.calledByEntry.forEach(y=>{o.push(y),y.addCall(this,i)}),i==null||i.attemptAutoclose("restore-entity",this.id),{added:R(a),updated:R(o),removed:R(p),affected:R(e),self:this}}toFlat(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this,...this.successCalls.flatMap(o=>o.toFlat(i)),...this.errorCalls.flatMap(o=>o.toFlat(i)),...this.inputs.flatMap(o=>o.toFlat(i)),...this.outputs.flatMap(o=>o.toFlat(i)),...this.calledBy.flatMap(o=>o.toFlat(i)),...this.process?this.process.toFlat(i):[],...this.error?this.error.toFlat(i):[],...this.parent.toFlat(i)])}toFlatIds(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.id,...this.successCalls.flatMap(o=>o.toFlatIds(i)),...this.errorCalls.flatMap(o=>o.toFlatIds(i)),...this.inputs.flatMap(o=>o.toFlatIds(i)),...this.outputs.flatMap(o=>o.toFlatIds(i)),...this.calledBy.flatMap(o=>o.toFlatIds(i)),...this.process?this.process.toFlatIds(i):[],...this.error?this.error.toFlatIds(i):[],...this.parent.toFlatIds(i)])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,index:this.index,type:this.type}}toJSON(i=new Set){var a,o,p;return i.has(this.id)?this.toReference():(i.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,index:this.index,successCalls:this.successCalls.map(e=>e.toJSON(i)),errorCalls:this.errorCalls.map(e=>e.toJSON(i)),calledBySuccess:this.calledBySuccess.map(e=>e.toReference()),calledByError:this.calledByError.map(e=>e.toReference()),calledByEntry:this.calledByEntry.map(e=>e.toReference()),process:(a=this.process)==null?void 0:a.toJSON(i),declaration:(o=this.declaration)==null?void 0:o.toJSON(i),inputs:this.inputs.map(e=>e.toJSON(i)),outputs:this.outputs.map(e=>e.toJSON(i)),parent:this.parent.toReference(),error:(p=this.error)==null?void 0:p.toJSON(i)})}toJSONClone(i=ke){var o,p,e,y,v,E,b,A,$;let a;return(o=i.seenEntityMaps)!=null&&o.has(this.id)?a=i.seenEntityMaps.get(this.id):(a=i.newId||Sr(this,this.project,i.uuidStrategy),i.seenEntityMaps&&i.seenEntityMaps.set(this.id,a)),(p=i.seenEntities)!=null&&p.has(a)||(e=i.seenEntities)!=null&&e.has(this.id)?this.toReference({seenEntityMaps:i.seenEntityMaps}):((y=i.seenEntities)==null||y.add(a),(v=i.seenEntities)==null||v.add(this.id),{id:a,version:N.UUID.uuid(),createdAt:i.timestamp||L().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,index:this.index,successCalls:this.successCalls.map(V=>V.toJSONClone({...i,newId:null})),errorCalls:this.errorCalls.map(V=>V.toJSONClone({...i,newId:null})),calledBySuccess:this.calledBySuccess.map(V=>V.toReference({seenEntityMaps:i.seenEntityMaps})),calledByError:this.calledByError.map(V=>V.toReference({seenEntityMaps:i.seenEntityMaps})),calledByEntry:this.calledByEntry.map(V=>V.toReference({seenEntityMaps:i.seenEntityMaps})),process:(E=this.process)==null?void 0:E.toJSONClone({...i,newId:null}),declaration:this.project.getBuiltIn(this.declaration.id)?(b=this.declaration)==null?void 0:b.toJSON():(A=this.declaration)==null?void 0:A.toJSONClone({...i,newId:null}),inputs:this.inputs.map(V=>V.toJSONClone({...i,newId:null})),outputs:this.outputs.map(V=>V.toJSONClone({...i,newId:null})),error:($=this.error)==null?void 0:$.toJSONClone({...i,newId:null}),parent:this.parent.calledBy.length||this.parent.readsValue?this.parent.toReference({seenEntityMaps:i.seenEntityMaps}):this.parent.toJSONClone({...i,newId:null})})}toReference(i=ke){var o;let a=this.id;return(o=i.seenEntityMaps)!=null&&o.has(this.id)&&(a=i.seenEntityMaps.get(this.id)),{id:a+"--"+N.UUID.uuid()+"--ref",type:f.GenericReference,entityId:a,version:this.version,entityType:this.type}}toShallowJSON(i=ke){var o;let a=this.id;return(o=i.seenEntityMaps)!=null&&o.has(this.id)&&(a=i.seenEntityMaps.get(this.id)),{id:a,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,index:this.index,process:this.process?this.process.toReference(i):null,inputs:this.inputs.map(p=>p.toReference(i)),outputs:this.outputs.map(p=>p.toReference(i)),declaration:this.declaration.toReference(i),successCalls:this.successCalls.map(p=>p.toReference(i)),errorCalls:this.errorCalls.map(p=>p.toReference(i)),calledBySuccess:this.calledBySuccess.map(p=>p.toReference(i)),calledByError:this.calledByError.map(p=>p.toReference(i)),calledByEntry:this.calledByEntry.map(p=>p.toReference(i)),error:this.error?this.error.toReference(i):null,parent:this.parent.toReference(i)}}toFlatJSON(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.toShallowJSON(),...this.process?this.process.toFlatJSON(i):[],...this.successCalls.flatMap(o=>o.toFlatJSON(i)),...this.errorCalls.flatMap(o=>o.toFlatJSON(i)),...this.inputs.flatMap(o=>o.toFlatJSON(i)),...this.outputs.flatMap(o=>o.toFlatJSON(i)),...this.calledBy.flatMap(o=>o.toFlatJSON(i)),...this.error?this.error.toFlatJSON(i):[],...this.parent.toFlatJSON(i)])}toGenerationTarget(){return{id:this.id,type:this.type,calledByEntry:this.calledByEntry.map(i=>i.id),calledBySuccess:this.calledBySuccess.map(i=>i.id),calledByError:this.calledByError.map(i=>i.id),declaration:this.declaration.id,parent:this.parent.id}}toFlatGenerationTarget(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.toGenerationTarget(),...this.process?this.process.toFlatGenerationTarget(i):[],...this.successCalls.flatMap(o=>o.toFlatGenerationTarget(i)),...this.errorCalls.flatMap(o=>o.toFlatGenerationTarget(i)),...this.inputs.flatMap(o=>o.toFlatGenerationTarget(i)),...this.outputs.flatMap(o=>o.toFlatGenerationTarget(i)),...this.error?this.error.toFlatGenerationTarget(i):[],...this.parent.toFlatGenerationTarget(i)])}clearErrors(){var i,a;return this.errors=[],this.inputs.forEach(o=>o.clearErrors()),this.outputs.forEach(o=>o.clearErrors()),this.successCalls.forEach(o=>o.clearErrors()),this.errorCalls.forEach(o=>o.clearErrors()),(i=this.process)==null||i.clearErrors(),(a=this.error)==null||a.clearErrors(),this}validate(){const i=mF(this);return this.errors=i,{success:!0}}getErrors(){return[...this.errors,...this.inputs.flatMap(a=>a.getErrors()),...this.outputs.flatMap(a=>a.getErrors()),...this.error?this.error.getErrors():[],...this.process?this.process.getErrors():[]]}getShallowErrors(){return this.errors}clone(i=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"clone-entity")),a=null,o=null,p=!0){var U,G;let e=Gr(a,this);const y=this.toJSON(),v=o||N.UUID.uuid();y.inputs=[];const E=v.split("-id"),b=E[E.length-1||0]||v;y.id=v,y.version=N.UUID.uuid();const A=lr(y,e);a?A.setParent(a,null):A.setParent(this.parent,null),p&&A.subscribe(),A.initChildren(i),i==null||i.add(A,S.Added);const $=(U=this.inputs)==null?void 0:U.map((K,Z)=>K.clone(i,A,b+"-input-map-"+Z+"-id",p));A.inputs=$;const V=(G=this.outputs)==null?void 0:G.map((K,Z)=>K.clone(i,A,b+"-output-map-"+Z+"-id",p));return A.outputs=V,this.error&&(A.error=this.error.clone(i,A,b+"-error-map-id",p)),this.process&&(A.process=this.process.clone(i,A,b+"-process-id",p)),i==null||i.attemptAutoclose("clone-entity",this.id),A}removeUnrecognizedInputs(i=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-unrecognized-inputs"))){const a=[],o=[],p=[],e=[];return this.inputs.forEach(v=>{if(!this.declaration.inputs.find(b=>{var A;return b.id===((A=v.declaration)==null?void 0:A.id)})){const b=v.remove({ignoreUpstream:!1},i);p.push(...b.removed),a.push(...b.updated)}}),this.inputs.filter((v,E)=>{const b=this.inputs.findIndex($=>$.declaration===v.declaration&&$!==v);if(b===-1)return!1;const A=this.inputs[b];return L(A==null?void 0:A.createdAt).isSame(L(v.createdAt))?E>b:!!L(A==null?void 0:A.createdAt).isAfter(v.createdAt)}).forEach(v=>{const E=v.remove({ignoreUpstream:!1},i);p.push(...E.removed),a.push(...E.updated)}),i==null||i.attemptAutoclose("remove-unrecognized-inputs",this.id),{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}removeUnrecognizedOutputs(i=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-unrecognized-outputs"))){const a=[],o=[],p=[],e=[];return this.outputs.forEach(v=>{if(!this.declaration.getUniqueReturnDeclarations().find(b=>{var A;return b.id===((A=v.declaration)==null?void 0:A.id)})){const b=v.remove({ignoreUpstream:!1},i);p.push(...b.removed),a.push(...b.updated)}}),this.outputs.filter((v,E)=>{const b=this.outputs.findIndex($=>$.declaration===v.declaration&&$!==v);if(b===-1)return!1;const A=this.outputs[b];return L(A==null?void 0:A.createdAt).isSame(L(v.createdAt))?E>b:!!L(A==null?void 0:A.createdAt).isAfter(v.createdAt)}).forEach(v=>{const E=v.remove({ignoreUpstream:!1},i);p.push(...E.removed),a.push(...E.updated)}),i==null||i.attemptAutoclose("remove-unrecognized-outputs",this.id),{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}syncInputs(i=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"sync-missing-fixed-inputs"))){const a=[],o=[],p=[],e=[],y=this.declaration.inputs.filter(A=>!this.inputs.find($=>$.declaration.id===A.id));this.inputs.sort((A,$)=>A.index-$.index),y.forEach(A=>{this.inputs.forEach(U=>{U.index>=A.index&&U.metaSync({index:U.index+1},i)});const $={id:N.UUID.uuid(),version:N.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||L().toISOString(),author:N.sessionAuthor,previousVersion:null,deleted:!1,type:f.InputMap,declaration:A.toJSON(),readsValue:null,defaultValue:null,index:A.index,name:null,codeName:null,description:null,parent:this.toReference()},V=te($,this.project);V.setParent(this,i),V.initChildren(i),i==null||i.add(V,S.Added),V.addSelfToProject(i),o.push(V)}),this.inputs.sort((A,$)=>A.index-$.index);const{updated:v,added:E,removed:b}=this.removeUnrecognizedInputs(i);return a.push(...v),o.push(...E),p.push(...b),i==null||i.attemptAutoclose("sync-missing-fixed-inputs",this.id),{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}syncOutputs(i=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"sync-missing-fixed-outputs"))){const a=[],o=[],p=[],e=[],y=[];this.outputs=this.initialData.outputs.map($=>{const V=te($,this.project);return y.push(V.index),V.setParent(this,null),V.initChildren(i),V});const v=this.declaration.getUniqueReturnDeclarations().filter($=>!this.outputs.find(V=>V.declaration.id===$.id));this.outputs.sort(($,V)=>$.index-V.index),v.forEach(($,V)=>{this.outputs.forEach(Z=>{Z.index>=$.index&&Z.index++});const U=y.includes($.index)?this.outputs.length-1+V:$.index,G={id:N.UUID.uuid(),version:N.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||L().toISOString(),author:N.sessionAuthor,previousVersion:null,deleted:!1,type:f.OutputMap,declaration:$.toJSON(),defaultValue:null,writesValues:[],index:U,parent:this.toReference()},K=te(G,this.project);K.setParent(this,i),K.initChildren(i),i==null||i.add(K,S.Added),K.addSelfToProject(i)}),this.outputs.sort(($,V)=>$.index-V.index);const{updated:E,added:b,removed:A}=this.removeUnrecognizedOutputs(i);return a.push(...E),o.push(...b),p.push(...A),i==null||i.attemptAutoclose("sync-missing-fixed-outputs",this.id),{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}getUnusedInputs(){return this.inputs.filter(i=>i.suggestion||!i.readsValue&&!i.defaultValue)}getUnusedOutputs(){return this.outputs.filter(i=>i.suggestion||!i.writesValues.length)}getUsedInputs(){return this.inputs.filter(i=>!i.suggestion&&(i.readsValue||i.defaultValue))}getUsedOutputs(){return this.outputs.filter(i=>!i.suggestion&&i.writesValues.length)}};g(Gt,"repository",{APICreate:async(i,...a)=>i,APIUpdate:async(i,...a)=>i,APIDelete:async(i,...a)=>i,APIClone:async(i,...a)=>{},APILoad:async(i,...a)=>null,APILoadVersion:async(i,a,...o)=>null}),g(Gt,"type",f.InternalCall),g(Gt,"USER_MANAGED_PARENT_TYPES",[...mt]),g(Gt,"PARENT_TYPES",[...Gt.USER_MANAGED_PARENT_TYPES]),g(Gt,"MUTABLE_BASE_PROPERTIES",[]),g(Gt,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),g(Gt,"BASE_PROPERTIES",[...Gt.MUTABLE_BASE_PROPERTIES,...Gt.INMUTABLE_BASE_PROPERTIES]),g(Gt,"MUTABLE_META_PROPERTIES",[...Gt.MUTABLE_BASE_PROPERTIES,"index"]),g(Gt,"INMUTABLE_META_PROPERTIES",[...Gt.INMUTABLE_BASE_PROPERTIES]),g(Gt,"META_PROPERTIES",[...Gt.MUTABLE_META_PROPERTIES,...Gt.INMUTABLE_META_PROPERTIES]),g(Gt,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry"]),g(Gt,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","declaration"]),g(Gt,"UPSTREAM_PROPERTIES",[...Gt.MUTABLE_UPSTREAM_PROPERTIES,...Gt.INMUTABLE_UPSTREAM_PROPERTIES]),g(Gt,"MUTABLE_DOWNSTREAM_PROPERTIES",["inputs","outputs","writesValues","successCalls","errorCalls","error"]),g(Gt,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),g(Gt,"DOWNSTREAM_PROPERTIES",[...Gt.MUTABLE_DOWNSTREAM_PROPERTIES,...Gt.INMUTABLE_DOWNSTREAM_PROPERTIES]),g(Gt,"PROPERTIES",[...Gt.META_PROPERTIES,...Gt.UPSTREAM_PROPERTIES,...Gt.DOWNSTREAM_PROPERTIES]);let fo=Gt;function gF(d){const u=rye(),i=d.toJSON();u.safeParse(i).success;const o=[...Io(d)];return vr(d.errors,o)}const iEe=Object.freeze(Object.defineProperty({__proto__:null,validate:gF},Symbol.toStringTag,{value:"Module"}));function Li(d){return d.declaration||d}function sEe(d){return d.type===f.VariableDeclaration?d.parent===d.project?"global-declaration":"local-declaration":d.declaration.parent===d.project?"global-instance":"local-instance"}function LA(d,u){const i=[];if(d.type===f.Project)i.push(...d.variableDeclarations);else{const o=ti(Rt(d)).filter(p=>p.type===f.VariableDeclaration);i.push(...o),d.parent&&(Mr.includes(d.parent.type)||d.parent.type===f.Project)&&i.push(...LA(d.parent))}return i}var DF=(d=>(d.Declaration="declaration",d.DataTypeEntity="data-type-entity",d))(DF||{});const St=class St extends Nr{constructor(i,a){super(i);g(this,"initialData");g(this,"id");g(this,"index");g(this,"name",null);g(this,"codeName",null);g(this,"description",null);g(this,"type",f.InputMap);g(this,"defaultValue",null);g(this,"readsValue",null);g(this,"dataType",null);g(this,"declaration",null);g(this,"project");g(this,"errors",[]);g(this,"parent");g(this,"detachedDependents",{});g(this,"knownVersions",null);g(this,"activeVersion",!1);g(this,"initialized",!1);g(this,"startedInitialization",!1);g(this,"suggestion",!1);g(this,"_codeNativeValueValidation",null);this.initialData=i,this.project=a,this.id=i.id,this.index=i.index,this.name=i.name||null,this.codeName=i.codeName||null,this.description=i.description||null}static new(i=null){return{id:N.UUID.uuid(),version:N.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||L().toISOString(),author:(i==null?void 0:i.author)||N.sessionAuthor,previousVersion:null,deleted:!1,type:f.InputMap,name:"",codeName:null,description:"",declaration:null,index:0,readsValue:null,defaultValue:null,parent:null}}static fromGenerationTarget(i,a){const o=J(i.parent),p=a.get(o);let e=null;if(i.declaration){const b=J(i.declaration);e=a.get(b)}let y=null;if(i.readsValue){const b=J(i.readsValue);y=a.get(b)}const v={id:i.id,version:N.UUID.uuid(),createdAt:L().toISOString(),author:N.sessionAuthor,previousVersion:null,deleted:!1,name:i.name||null,type:f.InputMap,index:(p.inputs||[]).length,codeName:i.codeName||null,description:i.description||null,declaration:e,readsValue:y,defaultValue:null,parent:p},E=te(v,a);return E.setParent(p,null),E}static validateGenerationTarget(i,a){var b;let o=JSON.parse(JSON.stringify(i));const p=[],e=oi(o,{parent:{list:!1,types:[...fr,f.InputMap]}},a);o=e.modifiedData;const y=a.get(o.parent),v=o.declaration&&(a.get(o.declaration)||a.getBuiltIn(o.declaration)),E=((y==null?void 0:y.inputs)||[]).find(A=>{var $;return o.declaration&&(($=A.declaration)==null?void 0:$.id)===o.declaration});if(o.declaration?v?[f.Property,f.ArgumentDeclaration,f.ValueDescriptor].includes(v.type)?y&&v.type===f.ArgumentDeclaration&&![f.FunctionCall,f.Search,f.InternalCall].includes(y.type)?p.push(new ee({id:`${o.id}--${k.InvalidInputMapDeclaration}`,code:k.InvalidInputMapDeclaration,severity:q.Error,message:`Entity of type '${f.InputMap}' with id '${o.id}' has a 'declaration' property pointing to an entity with type '${f.ArgumentDeclaration}' with id '${o.declaration}'.
|
|
133
133
|
The parent entity of type '${y.type}' with id '${y.id}' is not compatible with this type of declaration.
|
|
134
134
|
Only 'function-call', 'search' and 'internal-call' entities can have input-maps whose 'declaration' points to 'argument-declaration' entities.`})):y&&v.type===f.Property&&!mt.includes(y.type)?p.push(new ee({id:`${o.id}--${k.InvalidInputMapDeclaration}`,code:k.InvalidInputMapDeclaration,severity:q.Error,message:`Entity of type '${f.InputMap}' with id '${o.id}' has a 'declaration' property pointing to an entity with type '${f.Property}' with id '${o.declaration}'.
|
|
135
135
|
The parent entity of type '${y.type}' with id '${y.id}' is not compatible with this type of declaration.
|
|
@@ -393,7 +393,7 @@ All global 'function-declaration' entity ids are:
|
|
|
393
393
|
The project currently has no global 'function-declaration' entities that can be called as 'function-call' entities.`;p.push(new ee({id:`${o.id}--${k.InvalidReference}`,code:k.InvalidReference,severity:q.Error,message:`Entity of type "${f.FunctionCall}" with id "${o.id}", has an invalid reference at the 'declaration' property. The 'declaration' property must be a valid reference to an 'function-declaration' entity.
|
|
394
394
|
References can either be an ID string or an object with exacly four properties: 'id', 'entityId', 'entityType', 'type'.${v}`}))}return{errors:p,modifiedData:o}}validateGeneratedUpdate(i){const a=[];return i.parent&&a.push(new ee({id:`${this.id}--${k.InvalidParentUpdate}`,code:k.InvalidParentUpdate,severity:q.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.
|
|
395
395
|
If an entity is called by another, they must be in the same scope, which means they have the same parent.
|
|
396
|
-
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.`})),{errors:a,modifiedData:i}}subscribeDependents(i){return i.forEach(a=>{this.detachedDependents[a.entity.id]||(this.detachedDependents[a.entity.id]=a)}),this}unsubscribeDependents(i){return i.forEach(a=>{this.detachedDependents[a.entity.id]&&delete this.detachedDependents[a.entity.id]}),this}syncDependents(i=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"sync-dependents"))){const a=[],o=[],p=[],e=[];return Object.values(this.detachedDependents).forEach(y=>{const v=y.entity.afterAllChildrenInitialized(i);a.push(...v.updated),o.push(...v.added),p.push(...v.removed),e.push(...v.affected)}),i==null||i.attemptAutoclose("sync-dependents",this.id),{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}onDetachedDependencyRemoved(i,a,o){const p=[],e=[],y=[],v=[];if(a==="declaration"){const{updated:E,added:b,removed:A}=this.remove({ignoreUpstream:!1},o);p.push(...E),e.push(...b),y.push(...A)}if(a==="parent"){const{updated:E,added:b,removed:A}=this.remove({ignoreUpstream:!1},o);p.push(...E),e.push(...b),y.push(...A)}return{updated:R(p),added:R(e),removed:R(y),affected:R(v),self:this}}onDetachedDependencyRestored(i,a,o){const p=[],e=[],y=[],v=[];if(a==="declaration"){const{updated:E,added:b,removed:A}=this.restore({},o);p.push(...E),e.push(...b),y.push(...A)}if(a==="parent"){const{updated:E,added:b,removed:A}=this.restore({},o);p.push(...E),e.push(...b),y.push(...A)}return{updated:R(p),added:R(e),removed:R(y),affected:R(v),self:this}}unsubscribeFromDependencies(){var i;return(i=this.parent)==null||i.unsubscribeDependents([{entity:this,field:"parent"}]),this.declaration.unsubscribeDependents([{entity:this,field:"declaration"}]),this}subscribeToDependencies(){var i;return(i=this.parent)==null||i.subscribeDependents([{entity:this,field:"parent"}]),this.declaration.subscribeDependents([{entity:this,field:"declaration"}]),this}increaseVersion(i){if(i&&!L(i).isValid())throw new Error(`The shared timestamp '${i}' is not a valid ISO 8601 date string.`);return i&&L(i).isSame(L(this.createdAt))?this:(this.previousVersion=this.version,this.version=N.UUID.uuid(),this.createdAt=L(i).toISOString()||L().toISOString(),this)}captureVersion(){var a;const i=((a=this.knownVersions)==null?void 0:a.get(this.version))||new er(this,this.project);return i.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,i):new Map([[this.version,i]]),i.inputs=[...this.inputs],i.outputs=[...this.outputs],i.error=this.error,i.successCalls=[...this.successCalls],i.errorCalls=[...this.errorCalls],i.process=this.process,i.declaration=this.declaration,i.calledBySuccess=[...this.calledBySuccess],i.calledByError=[...this.calledByError],i.calledByEntry=[...this.calledByEntry],i.parent=this.parent,this}recursiveCaptureUpstreamVersions(i){const a=[],o=[],p=[],e=[];if(this.parent){this.parent.increaseVersion(i);const y=this.parent.recursiveCaptureUpstreamVersions(i);a.push(this.parent,...y.updated),o.push(...y.added),p.push(...y.removed)}return{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}async restoreVersion(i){var v;const a=[],o=[],p=[],e=[];if(this.version===i)return{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this};if(!this.knownVersions){const E=new Map;for(const[b,A]of this.knownVersions||new Map){if(E.set(b,A),A.activeVersion=!1,A.knownVersions)for(const[$,V]of A.knownVersions)E.set($,V);A.knownVersions=null}}let y=(v=this.knownVersions)==null?void 0:v.get(i);if(!y){const E=await this.APILoadVersion({},i);if(!E)throw new Error(`Version with id '${i}' for entity with id '${this.id}' not found.`);y=new er(E,this.project)}return this.metaSync(y.toShallowJSON(),null),this.previousVersion=y.previousVersion,this.version=y.version,this.createdAt=y.createdAt,this.author=y.author,this.deleted=y.deleted,this.inputs=y.inputs,this.outputs=y.outputs,this.error=y.error,this.successCalls=y.successCalls,this.errorCalls=y.errorCalls,this.process=y.process,this.declaration=y.declaration,this.calledBySuccess=y.calledBySuccess,this.calledByError=y.calledByError,this.calledByEntry=y.calledByEntry,this.parent=y.parent,{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}updateWithShallowTransfer(i,a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"update-with-shallow-transfer"))){if(this.metaSync(i,a),this.version=i.version,this.createdAt=i.createdAt,this.author=i.author,this.deleted=i.deleted,this.previousVersion=i.previousVersion,this.unsubscribeFromDependencies(),i.parent){const o=J(i.parent),p=this.project.get(o),e=this.parent;if(e&&e.id!==(p==null?void 0:p.id)&&this.removeFromParent(a),p)this.setParent(p,a);else throw a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${o}' that isn't found in the project`)}else throw a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(i.declaration){const o=J(i.declaration),p=this.project.get(o);p&&this.setDeclaration(p)}return i.calledByEntry.forEach(o=>{const p=J(o),e=this.project.get(p);e&&(this.addEntryCaller(e,a),e.addCall(this,a))}),[...this.calledByEntry].forEach(o=>{i.calledByEntry.find(e=>J(e)===o.id)||(this.removeCaller(o,a),o.removeCall(this,a))}),i.calledBySuccess.forEach(o=>{const p=J(o),e=this.project.get(p);e&&(this.addSuccessCaller(e,a),e.addSuccessCall(this,a))}),[...this.calledBySuccess].forEach(o=>{i.calledBySuccess.find(e=>J(e)===o.id)||(this.removeCaller(o,a),o.removeCall(this,a))}),i.calledByError.forEach(o=>{const p=J(o),e=this.project.get(p);e&&(this.addErrorCaller(e,a),e.addErrorCall(this,a))}),[...this.calledBySuccess].forEach(o=>{i.calledBySuccess.find(e=>J(e)===o.id)||(this.removeCaller(o,a),o.removeCall(this,a))}),this.captureVersion(),this.subscribeToDependencies(),a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),this}hydrateAncestors(){const i=[],a=[],o=[],p=[];if(this.initialData.parent){const e=J(this.initialData.parent),y=this.project.get(e);if(y)this.setParent(y,null),i.push(y);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${e}' that isn't found in the project`)}else throw new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(this.initialData.declaration){const e=J(this.initialData.declaration),y=this.project.get(e);y&&(this.setDeclaration(y),i.push(y))}return this.initialData.calledByEntry.forEach(e=>{const y=J(e),v=this.project.get(y);v&&this.addEntryCaller(v,null)}),this.initialData.calledBySuccess.forEach(e=>{const y=J(e),v=this.project.get(y);v&&this.addSuccessCaller(v,null)}),this.initialData.calledByError.forEach(e=>{const y=J(e),v=this.project.get(y);v&&this.addErrorCaller(v,null)}),{updated:R(i),added:R(a),removed:R(o),affected:R(p),self:this}}afterAllChildrenInitialized(i=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"after-all-children-initialized"))){const a=[],o=[],p=[],e=[];this.initialized=!0;const{updated:y,added:v,removed:E}=this.syncInputs(i),{updated:b,added:A,removed:$}=this.syncOutputs(i);return a.push(...y,...b),o.push(...v,...A),p.push(...E,...$),this.captureVersion(),i==null||i.attemptAutoclose("after-all-children-initialized",this.id),{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}addSelfToProject(i=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-self-to-project"))){var y;const a=[this],o=[],p=[],e=[];return this.parent===this.project&&this.project.addFunctionCall(this),(y=this.process)==null||y.writesValues.forEach(v=>{v.setValueWriter(this.process,i),a.push(v)}),this.successCalls.forEach(v=>{v.addSuccessCaller(this,i),a.push(v)}),this.errorCalls.forEach(v=>{v.addErrorCaller(this,i),a.push(v)}),this.calledBySuccess.forEach(v=>{v.addSuccessCall(this,i),a.push(v)}),this.calledByError.forEach(v=>{v.addErrorCall(this,i),a.push(v)}),this.calledByEntry.forEach(v=>{v.addCall(this,i),a.push(v)}),this.subscribe(),this.subscribeToDependencies(),i==null||i.attemptAutoclose("add-self-to-project",this.id),{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}removeInput(i,a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-input"))){const o=this.inputs.findIndex(p=>p.id===i.id);return o>-1&&(this.inputs.splice(o,1),a&&(a==null||a.add(this,S.Affected))),a==null||a.attemptAutoclose("remove-input",this.id),this}addInput(i,a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-input"))){return this.inputs.includes(i)?(a==null||a.attemptAutoclose("add-input",this.id),this):(this.inputs.push(i),a==null||a.add(this,S.Affected),a==null||a.attemptAutoclose("add-input",this.id),this)}addOutput(i,a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-output"))){return this.outputs.includes(i)?(a==null||a.attemptAutoclose("add-output",this.id),this):(this.outputs.push(i),a==null||a.add(this,S.Affected),a==null||a.attemptAutoclose("add-output",this.id),this)}removeOutput(i,a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-output"))){const o=this.outputs.findIndex(p=>p.id===i.id);return o>-1&&(this.outputs.splice(o,1),a&&(a==null||a.add(this,S.Affected))),a==null||a.attemptAutoclose("remove-output",this.id),this}addValueReader(i,a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-value-reader"))){var o;return this.process&&!this.process.writesValues.includes(i)&&((o=this.process)==null||o.addValueReader(i,a),a==null||a.add(this,S.Affected)),a==null||a.attemptAutoclose("add-value-reader",this.id),this}removeValueReader(i,a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-value-reader"))){var o;return this.process&&this.process.writesValues.includes(i)&&((o=this.process)==null||o.removeValueReader(i,a),a==null||a.add(this,S.Affected)),a==null||a.attemptAutoclose("remove-value-reader",this.id),this}addSuccessCaller(i,a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-success-caller")),o=!1){return this.calledBySuccess.find(p=>p.id===i.id)||(this.calledBySuccess.push(i),a==null||a.add(this,S.Updated),o&&We(this,a)),a==null||a.attemptAutoclose("add-success-caller",this.id),this}addErrorCaller(i,a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-error-caller")),o=!1){return this.calledByError.find(p=>p.id===i.id)||(this.calledByError.push(i),a==null||a.add(this,S.Updated),o&&We(this,a)),a==null||a.attemptAutoclose("add-error-caller",this.id),this}addEntryCaller(i,a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-entry-caller")),o=!1){return this.calledByEntry.find(p=>p.id===i.id)||(this.calledByEntry.push(i),a==null||a.add(this,S.Updated),o&&We(this,a)),a==null||a.attemptAutoclose("add-entry-caller",this.id),this}addErrorCall(i,a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-error-call")),o=!1){return this.errorCalls.find(p=>p.id===i.id)||(this.errorCalls.push(i),o&&We(this,a),a==null||a.add(this,S.Affected)),a==null||a.attemptAutoclose("add-error-call",this.id),this}addSuccessCall(i,a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-success-call")),o=!1){return this.successCalls.find(p=>p.id===i.id)||(this.successCalls.push(i),o&&We(this,a),a==null||a.add(this,S.Affected)),a==null||a.attemptAutoclose("add-success-call",this.id),this}removeCall(i,a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-call")),o=!1){const p=this.successCalls.findIndex(y=>y.id===i.id);p>-1&&(this.successCalls.splice(p,1),a==null||a.add(this,S.Affected));const e=this.errorCalls.findIndex(y=>y.id===i.id);return e>-1&&(this.errorCalls.splice(e,1),a==null||a.add(this,S.Affected)),o&&We(this,a),a==null||a.attemptAutoclose("remove-call",this.id),this}removeCaller(i,a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-caller")),o=!1){return this.calledBySuccess=this.calledBySuccess.filter(p=>p.id!==i.id?!0:(a==null||a.add(this,S.Updated),a==null||a.add(p,S.Affected),!1)),this.calledByError=this.calledByError.filter(p=>p.id!==i.id?!0:(a==null||a.add(this,S.Updated),a==null||a.add(p,S.Affected),!1)),this.calledByEntry=this.calledByEntry.filter(p=>p.id!==i.id?!0:(a==null||a.add(this,S.Updated),a==null||a.add(p,S.Affected),!1)),o&&We(this,a),a==null||a.attemptAutoclose("remove-caller",this.id),this}setParent(i,a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"set-parent"))){var o;return((o=this.parent)==null?void 0:o.id)!==(i==null?void 0:i.id)&&(this.parent=i,a&&(a==null||a.add(this,S.Updated))),a==null||a.attemptAutoclose("set-parent",this.id),this}setDeclaration(i){return this.declaration=i,this}initChildren(i=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"init-children"))){if(this.initialized||this.startedInitialization)return this;if(this.startedInitialization=!0,this.initialData.declaration.type===f.FunctionDeclaration){const a=te(this.initialData.declaration,this.project);this.declaration=a}else{const a=J(this.initialData.declaration),o=this.project.get(a);this.declaration=o}return this.successCalls=this.initialData.successCalls.map(a=>{const o=te(a,this.project);if(o.addSuccessCaller(this),[f.BreakStatement,f.ContinueStatement].includes(o.type))o.setParent(this.parent.parent,null),o.initChildren(i);else if(o.type===f.ReturnStatement){const p=Wr(this,this.project);o.setParent(p,null),o.initChildren(i)}else o.type!==f.InternalCall&&(o.setParent(this.parent,null),o.initChildren(i));return o}),this.errorCalls=this.initialData.errorCalls.map(a=>{const o=te(a,this.project);if(o.addErrorCaller(this),[f.BreakStatement,f.ContinueStatement].includes(o.type))o.setParent(this.parent.parent,null),o.initChildren(i);else if(o.type===f.ReturnStatement){const p=Wr(this,this.project);o.setParent(p,null),o.initChildren(i)}else o.type!==f.InternalCall&&(o.setParent(this.parent,null),o.initChildren(i));return o}),this.inputs=this.initialData.inputs.map(a=>{const o=te(a,this.project);return o.setParent(this,null),o.initChildren(i),o}),this.initialData.process&&(this.process=te(this.initialData.process,this.project),this.process.setParent(this,null),this.process.initChildren(i)),this.initialData.error&&(this.error=te(this.initialData.error,this.project),this.error.setParent(this,null),this.error.initChildren(i)),this.subscribeToDependencies(),this.afterAllChildrenInitialized(i),i==null||i.attemptAutoclose("init-children",this.id),this}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(i,a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"meta-sync"))){const o=Ur(this,i),p=this.toMeta();return this.x=i.x||p.x,this.y=i.y||p.y,super.metaSync(i),i.deleted===!0&&!p.deleted?a==null||a.add(this,S.Removed):i.deleted===!1&&p.deleted?a==null||a.add(this,S.Added):o&&(a==null||a.add(this,S.Updated)),a==null||a.attemptAutoclose("meta-sync",this.id),this}async APILoad(i=ve,...a){return await er.repository.APILoad(this.id,...a),this}async APICreate(i=ve,...a){return await er.repository.APICreate(this.toShallowJSON(),...a),this}async APIUpdate(i=ve,...a){return await er.repository.APIUpdate(this.toShallowJSON(),...a),this}async APIDelete(i=ve,...a){return await er.repository.APIDelete(this.toShallowJSON(),...a),this}async APIClone(i=ve,...a){return await er.repository.APIClone(this.id,...a),this}async APILoadVersion(i=ve,a,...o){return await er.repository.APILoadVersion(this.id,a,...o)}removeFromParent(i=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-from-parent"))){const a=[],o=[],p=[],e=[];return this.parent.type===f.Project?(this.parent.removeFunctionCall(this),e.push(this.parent)):this.parent.detachedChildren.includes(this)&&this.parent.unsubscribeDetachedChild(this),i==null||i.attemptAutoclose("remove-from-parent",this.id),{added:R(p),updated:R(a),removed:R(o),affected:R(e),self:this}}remove({ignoreUpstream:i}={ignoreUpstream:!1},a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-entity"))){var v;const o=[],p=[],e=[],y=[];if(a!=null&&a.hasRemoved(this.id))return a==null||a.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(p.push(this),this.unsubscribe(),this.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},a),Object.values(this.detachedDependents).forEach(E=>{const{updated:b,removed:A,added:$}=E.entity.onDetachedDependencyRemoved(this,E.field,a);o.push(...b),p.push(...A),e.push(...$)}),this.process){const{updated:E,removed:b}=(v=this.process)==null?void 0:v.remove({ignoreUpstream:!0},a);o.push(...E),p.push(...b)}if(this.inputs.forEach(E=>{const{updated:b,removed:A}=E.remove({ignoreUpstream:!0},a);o.push(...b),p.push(...A)}),this.outputs.forEach(E=>{const{updated:b,removed:A}=E.remove({ignoreUpstream:!0},a);o.push(...b),p.push(...A)}),this.error){const{updated:E,removed:b}=this.error.remove({ignoreUpstream:!0},a);o.push(...E),p.push(...b)}if(this.successCalls.forEach(E=>{o.push(E),E.removeCaller(this,a)}),this.errorCalls.forEach(E=>{o.push(E),E.removeCaller(this,a)}),!i){const E=this.removeFromParent(a);e.push(...E.added),o.push(...E.updated),p.push(...E.removed),y.push(...E.affected),this.calledBy.forEach(b=>{o.push(b),b.removeCall(this,a)})}return a==null||a.attemptAutoclose("remove-entity",this.id),{added:R(e),updated:R(o),removed:R(p),affected:R(y),self:this}}restore({}={},i=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"restore-entity"))){const a=[],o=[],p=[],e=[];if(i!=null&&i.hasAdded(this.id))return i==null||i.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},i),Object.values(this.detachedDependents).forEach(y=>{const{updated:v,removed:E,added:b}=y.entity.onDetachedDependencyRestored(this,y.field,i);o.push(...v),p.push(...E),a.push(...b)}),this.process){const{updated:y}=this.process.restore({},i);o.push(...y)}return this.inputs.forEach(y=>{const{updated:v}=y.restore({},i);o.push(...v)}),this.outputs.forEach(y=>{const{updated:v}=y.restore({},i);o.push(...v)}),this.successCalls.forEach(y=>{o.push(y),y.addSuccessCaller(this,i)}),this.errorCalls.forEach(y=>{o.push(y),y.addErrorCaller(this,i)}),this.calledBySuccess.forEach(y=>{o.push(y),y.addSuccessCall(this,i)}),this.calledByError.forEach(y=>{o.push(y),y.addErrorCall(this,i)}),this.calledByEntry.forEach(y=>{o.push(y),y.addCall(this,i)}),i==null||i.attemptAutoclose("restore-entity",this.id),{added:R(a),updated:R(o),removed:R(p),affected:R(e),self:this}}toFlat(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this,...this.successCalls.flatMap(o=>o.toFlat(i)),...this.errorCalls.flatMap(o=>o.toFlat(i)),...this.inputs.flatMap(o=>o.toFlat(i)),...this.outputs.flatMap(o=>o.toFlat(i)),...this.process?this.process.toFlat(i):[],...this.error?this.error.toFlat(i):[],...this.calledBy.flatMap(o=>o.toFlat(i))])}toFlatIds(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.id,...this.successCalls.flatMap(o=>o.toFlatIds(i)),...this.errorCalls.flatMap(o=>o.toFlatIds(i)),...this.inputs.flatMap(o=>o.toFlatIds(i)),...this.outputs.flatMap(o=>o.toFlatIds(i))])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,x:this.x,y:this.y,type:this.type}}toJSON(i=new Set){var a,o;return i.has(this.id)?this.toReference():(i.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,successCalls:this.successCalls.map(p=>p.toJSON(i)),errorCalls:this.errorCalls.map(p=>p.toJSON(i)),calledBySuccess:this.calledBySuccess.map(p=>p.toReference()),calledByError:this.calledByError.map(p=>p.toReference()),calledByEntry:this.calledByEntry.map(p=>p.toReference()),process:(a=this.process)==null?void 0:a.toJSON(i),declaration:this.declaration.toJSON(i),inputs:this.inputs.map(p=>p.toJSON(i)),outputs:this.outputs.map(p=>p.toJSON(i)),parent:this.parent.toReference(),error:(o=this.error)==null?void 0:o.toJSON(i)})}toJSONClone(i=ke){var o,p,e,y,v,E,b;let a;return(o=i.seenEntityMaps)!=null&&o.has(this.id)?a=i.seenEntityMaps.get(this.id):(a=i.newId||Sr(this,this.project,i.uuidStrategy),i.seenEntityMaps&&i.seenEntityMaps.set(this.id,a)),(p=i.seenEntities)!=null&&p.has(a)||(e=i.seenEntities)!=null&&e.has(this.id)?this.toReference({seenEntityMaps:i.seenEntityMaps}):((y=i.seenEntities)==null||y.add(a),(v=i.seenEntities)==null||v.add(this.id),{id:a,version:N.UUID.uuid(),createdAt:i.timestamp||L().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,successCalls:this.successCalls.map(A=>A.toJSONClone({...i,newId:null})),errorCalls:this.errorCalls.map(A=>A.toJSONClone({...i,newId:null})),calledBySuccess:this.calledBySuccess.map(A=>A.toReference({seenEntityMaps:i.seenEntityMaps})),calledByError:this.calledByError.map(A=>A.toReference({seenEntityMaps:i.seenEntityMaps})),calledByEntry:this.calledByEntry.map(A=>A.toReference({seenEntityMaps:i.seenEntityMaps})),process:(E=this.process)==null?void 0:E.toJSONClone({...i,newId:null}),declaration:this.declaration.toJSONClone({...i,newId:null}),inputs:this.inputs.map(A=>A.toJSONClone({...i,newId:null})),outputs:this.outputs.map(A=>A.toJSONClone({...i,newId:null})),error:(b=this.error)==null?void 0:b.toJSONClone({...i,newId:null}),parent:this.parent.toReference({seenEntityMaps:i.seenEntityMaps})})}toReference(i=ke){var o;let a=this.id;return(o=i.seenEntityMaps)!=null&&o.has(this.id)&&(a=i.seenEntityMaps.get(this.id)),{id:a+"--"+N.UUID.uuid()+"--ref",type:f.GenericReference,entityId:a,version:this.version,entityType:this.type}}toShallowJSON(i=ke){var o;let a=this.id;return(o=i.seenEntityMaps)!=null&&o.has(this.id)&&(a=i.seenEntityMaps.get(this.id)),{id:a,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,process:this.process?this.process.toReference(i):null,inputs:this.inputs.map(p=>p.toReference(i)),outputs:this.outputs.map(p=>p.toReference(i)),declaration:this.declaration.toReference(i),successCalls:this.successCalls.map(p=>p.toReference(i)),errorCalls:this.errorCalls.map(p=>p.toReference(i)),calledBySuccess:this.calledBySuccess.map(p=>p.toReference(i)),calledByError:this.calledByError.map(p=>p.toReference(i)),calledByEntry:this.calledByEntry.map(p=>p.toReference(i)),error:this.error?this.error.toReference(i):null,parent:this.parent.toReference(i)}}toFlatJSON(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.toShallowJSON(),...this.successCalls.flatMap(o=>o.toFlatJSON(i)),...this.errorCalls.flatMap(o=>o.toFlatJSON(i)),...this.inputs.flatMap(o=>o.toFlatJSON(i)),...this.outputs.flatMap(o=>o.toFlatJSON(i)),...this.process?this.process.toFlatJSON(i):[],...this.error?this.error.toFlatJSON(i):[]])}toGenerationTarget(){const i=this.parent.type===f.Project?void 0:this.parent.id;return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,calledByEntry:this.calledByEntry.map(a=>a.id),calledBySuccess:this.calledBySuccess.map(a=>a.id),calledByError:this.calledByError.map(a=>a.id),declaration:this.declaration.id,parent:i}}toFlatGenerationTarget(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.toGenerationTarget(),...this.successCalls.flatMap(o=>o.toFlatGenerationTarget(i)),...this.errorCalls.flatMap(o=>o.toFlatGenerationTarget(i)),...this.inputs.flatMap(o=>o.toFlatGenerationTarget(i)),...this.outputs.flatMap(o=>o.toFlatGenerationTarget(i)),...this.process?this.process.toFlatGenerationTarget(i):[],...this.error?this.error.toFlatGenerationTarget(i):[]])}clearErrors(){var i,a;return this.errors=[],this.inputs.forEach(o=>o.clearErrors()),this.outputs.forEach(o=>o.clearErrors()),this.successCalls.forEach(o=>o.clearErrors()),this.errorCalls.forEach(o=>o.clearErrors()),(i=this.process)==null||i.clearErrors(),(a=this.error)==null||a.clearErrors(),this}validate(){const i=A5(this);return this.errors=i,{success:!0}}getErrors(){return[...this.errors,...this.inputs.flatMap(a=>a.getErrors()),...this.outputs.flatMap(a=>a.getErrors()),...this.error?this.error.getErrors():[],...this.process?this.process.getErrors():[]]}getShallowErrors(){return this.errors}clone(i=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"clone-entity")),a=null,o=null,p=!0){var U,G;let e=Gr(a,this);const y=this.toJSON(),v=o||N.UUID.uuid();y.inputs=[];const E=v.split("-id"),b=E[E.length-1||0]||v;y.id=v,y.version=N.UUID.uuid(),y.createdAt=(i==null?void 0:i.timestamp)||L().toISOString(),y.author=(i==null?void 0:i.author)||"1",y.previousVersion=null,y.deleted=!1;const A=lr(y,e);a?A.setParent(a,null):A.setParent(this.parent,null),p&&A.subscribe(),A.initChildren(i),i==null||i.add(A,S.Added);const $=(U=this.inputs)==null?void 0:U.map((K,Z)=>K.clone(i,A,b+"-input-map-"+Z+"-id",p));A.inputs=$;const V=(G=this.outputs)==null?void 0:G.map((K,Z)=>K.clone(i,A,b+"-output-map-"+Z+"-id",p));return A.outputs=V,this.error&&(A.error=this.error.clone(i,A,b+"-error-map-id",p)),this.process&&(A.process=this.process.clone(i,A,b+"-process-id",p)),i==null||i.attemptAutoclose("clone-entity",this.id),A}removeUnrecognizedInputs(i=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-unrecognized-inputs"))){const a=[],o=[],p=[],e=[];return this.inputs.forEach(v=>{if(!this.declaration.inputs.find(b=>{var A;return b.id===((A=v.declaration)==null?void 0:A.id)})){const b=v.remove({ignoreUpstream:!1},i);p.push(...b.removed),a.push(...b.updated)}}),this.inputs.filter((v,E)=>{const b=this.inputs.findIndex($=>$.declaration===v.declaration&&$!==v);if(b===-1)return!1;const A=this.inputs[b];return L(A==null?void 0:A.createdAt).isSame(L(v.createdAt))?E>b:!!L(A==null?void 0:A.createdAt).isAfter(v.createdAt)}).forEach(v=>{const E=v.remove({ignoreUpstream:!1},i);p.push(...E.removed),a.push(...E.updated)}),i==null||i.attemptAutoclose("remove-unrecognized-inputs",this.id),{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}removeUnrecognizedOutputs(i=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-unrecognized-outputs"))){const a=[],o=[],p=[],e=[];return this.outputs.forEach(v=>{if(!this.declaration.getUniqueReturnDeclarations().find(b=>{var A;return b.id===((A=v.declaration)==null?void 0:A.id)})){const b=v.remove({ignoreUpstream:!1},i);p.push(...b.removed),a.push(...b.updated)}}),this.outputs.filter((v,E)=>{const b=this.outputs.findIndex($=>$.declaration===v.declaration&&$!==v);if(b===-1)return!1;const A=this.outputs[b];return L(A==null?void 0:A.createdAt).isSame(L(v.createdAt))?E>b:!!L(A==null?void 0:A.createdAt).isAfter(v.createdAt)}).forEach(v=>{const E=v.remove({ignoreUpstream:!1},i);p.push(...E.removed),a.push(...E.updated)}),i==null||i.attemptAutoclose("remove-unrecognized-outputs",this.id),{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}syncInputs(i=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"sync-missing-fixed-inputs"))){const a=[],o=[],p=[],e=[],y=this.declaration.inputs.filter(A=>!this.inputs.find($=>$.declaration.id===A.id));this.inputs.sort((A,$)=>A.index-$.index),y.forEach(A=>{this.inputs.forEach(U=>{U.index>=A.index&&U.metaSync({index:U.index+1},i)});const $={id:N.UUID.uuid(),version:N.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||L().toISOString(),author:N.sessionAuthor,previousVersion:null,deleted:!1,type:f.InputMap,declaration:A.toJSON(),readsValue:null,defaultValue:null,index:A.index,name:null,codeName:null,description:null,parent:this.toReference()},V=te($,this.project);V.setParent(this,i),V.initChildren(i),i==null||i.add(V,S.Added),V.addSelfToProject(i),o.push(V)}),this.inputs.sort((A,$)=>A.index-$.index);const{updated:v,added:E,removed:b}=this.removeUnrecognizedInputs(i);return a.push(...v),o.push(...E),p.push(...b),i==null||i.attemptAutoclose("sync-missing-fixed-inputs",this.id),{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}syncOutputs(i=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"sync-missing-fixed-outputs"))){const a=[],o=[],p=[],e=[],y=[];this.outputs=this.initialData.outputs.reduce(($,V)=>{if(V.type===f.GenericReference){const G=Hi(V,this.project);return G?[...$,G]:$}const U=te(V,this.project);return y.push(U.index),U.setParent(this,null),U.initChildren(i),[...$,U]},[]);const v=this.declaration.getUniqueReturnDeclarations().filter($=>!this.outputs.find(V=>V.declaration.id===$.id));this.outputs.sort(($,V)=>$.index-V.index),v.forEach(($,V)=>{this.outputs.forEach(Z=>{Z.index>=$.index&&Z.index++});const U=y.includes($.index)?this.outputs.length-1+V:$.index,G={id:N.UUID.uuid(),version:N.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||L().toISOString(),author:N.sessionAuthor,previousVersion:null,deleted:!1,type:f.OutputMap,declaration:$.toJSON(),defaultValue:null,writesValues:[],index:U,parent:this.toReference()},K=te(G,this.project);K.setParent(this,i),K.initChildren(i),i==null||i.add(K,S.Added),K.addSelfToProject(i)}),this.outputs.sort(($,V)=>$.index-V.index);const{updated:E,added:b,removed:A}=this.removeUnrecognizedOutputs(i);return a.push(...E),o.push(...b),p.push(...A),i==null||i.attemptAutoclose("sync-missing-fixed-outputs",this.id),{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}getUnusedInputs(){return this.inputs.filter(i=>i.suggestion||!i.readsValue&&!i.defaultValue)}getUnusedOutputs(){return this.outputs.filter(i=>i.suggestion||!i.writesValues.length)}getUsedInputs(){return this.inputs.filter(i=>!i.suggestion&&(i.readsValue||i.defaultValue))}getUsedOutputs(){return this.outputs.filter(i=>!i.suggestion&&i.writesValues.length)}};g(er,"repository",{APICreate:async(i,...a)=>i,APIUpdate:async(i,...a)=>i,APIDelete:async(i,...a)=>i,APIClone:async(i,...a)=>{},APILoad:async(i,...a)=>null,APILoadVersion:async(i,a,...o)=>null}),g(er,"type",f.FunctionCall),g(er,"USER_MANAGED_PARENT_TYPES",[...Mr,f.Project]),g(er,"PARENT_TYPES",[...er.USER_MANAGED_PARENT_TYPES]),g(er,"MUTABLE_BASE_PROPERTIES",[]),g(er,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),g(er,"BASE_PROPERTIES",[...er.MUTABLE_BASE_PROPERTIES,...er.INMUTABLE_BASE_PROPERTIES]),g(er,"MUTABLE_META_PROPERTIES",["x","y"]),g(er,"INMUTABLE_META_PROPERTIES",[...er.INMUTABLE_BASE_PROPERTIES]),g(er,"META_PROPERTIES",[...er.MUTABLE_META_PROPERTIES,...er.INMUTABLE_META_PROPERTIES]),g(er,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry"]),g(er,"INMUTABLE_UPSTREAM_PROPERTIES",["declaration","parent"]),g(er,"UPSTREAM_PROPERTIES",[...er.MUTABLE_UPSTREAM_PROPERTIES,...er.INMUTABLE_UPSTREAM_PROPERTIES]),g(er,"MUTABLE_DOWNSTREAM_PROPERTIES",["successCalls","errorCalls","writesValues","inputs","outputs","error"]),g(er,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),g(er,"DOWNSTREAM_PROPERTIES",[...er.MUTABLE_DOWNSTREAM_PROPERTIES,...er.INMUTABLE_DOWNSTREAM_PROPERTIES]),g(er,"PROPERTIES",[...er.META_PROPERTIES,...er.UPSTREAM_PROPERTIES,...er.DOWNSTREAM_PROPERTIES]);let Ao=er;function Pb(d){return d&&typeof d.then=="function"}function xIe(d){const u=new ea(d[0]),i=d.map(o=>o.id),a={};return d.forEach(o=>{a[o.id]=o}),u.order=i,u.flatRecord=a,u.orderEntities(),u.order.map(o=>u.flatRecord[o])}function FIe(d){const u=new ea(Object.values(d)[0]),i=Object.keys(d);return u.order=i,u.flatRecord=d,u.orderEntities(),u.order}class ea{constructor(u){g(this,"order",[]);g(this,"flatRecord",{});g(this,"allBuiltInEntityIds",Xs());g(this,"onGoingVisits",{});u&&(this.flatten(u),this.orderEntities())}flatten(u){const i=new Set(Xs()),a=R(me(u,i,{ignoreBuiltInBaseEntities:!0})),o=new Set;for(const p of a)this.flatRecord[p.id]=p,o.add(p.id);this.order=Array.from(o)}moveEntityAfterDependencies(u){const{upstream:i}=zd(u,this.flatRecord,{ignoreBuiltInBaseEntities:!0,allBuiltInEntityIds:this.allBuiltInEntityIds});for(const a of Object.keys(i)){const o=this.order.indexOf(a),p=this.order.indexOf(u.id);if(o>p)return this.order.splice(p,1),this.order.splice(o,0,u.id),!0}return!1}orderEntities(){let u=!1;for(let i=0;i<this.order.length;i++){const a=this.order[i],o=this.flatRecord[a];if(o||Me.warn(`Entity with id ${a} not found in flatRecord. Skipping...`),this.moveEntityAfterDependencies(o)){u=!0;break}}u&&this.orderEntities()}getUpstreamOngoingDependenciesVisits(u,i){const{upstream:a}=zd(this.flatRecord[u],this.flatRecord,{ignoreBuiltInBaseEntities:!0,allBuiltInEntityIds:this.allBuiltInEntityIds}),o={};return Object.entries(this.onGoingVisits[i]||{}).forEach(([p,e])=>{Object.keys(a).includes(p)&&(o[p]=e)}),o}getDownstreamOngoingDependenciesVisits(u,i){const a=Object.keys(this.onGoingVisits[i]||{}),o=new Set(a.flatMap(e=>Object.keys(zd(this.flatRecord[e],this.flatRecord,{ignoreBuiltInBaseEntities:!0,allBuiltInEntityIds:this.allBuiltInEntityIds}).downstream))),p={};return Array.from(o).forEach(e=>{e===u&&(p[e]=this.onGoingVisits[i][e])}),p}async settlePromises(u,i){const a=Object.values(u);a.length&&await Promise.all(a),Object.keys(u).forEach(o=>{delete this.onGoingVisits[i][o]})}visit(u){const i=this.order;for(const a of i)u(this.flatRecord[a],this.flatRecord);return this}reverseVisit(u){const i=this.order.slice().reverse();for(const a of i)u(this.flatRecord[a],this.flatRecord);return this}async visitAsync(u){const i=this.order,a=Math.random().toString(36).substring(7);this.onGoingVisits[a]={};for(const o of i){const p=this.getUpstreamOngoingDependenciesVisits(o,a);Object.keys(p).length&&await this.settlePromises(p,a);const e=u(this.flatRecord[o],this.flatRecord);Pb(e)&&(this.onGoingVisits[a][o]=e)}return await this.settlePromises(this.onGoingVisits[a],a),this.onGoingVisits[a]={},this}async reverseVisitAsync(u){const i=this.order.slice().reverse(),a=Math.random().toString(36).substring(7);this.onGoingVisits[a]={};for(const o of i){const p=this.getDownstreamOngoingDependenciesVisits(o,a);Object.keys(p).length&&await this.settlePromises(p,a);const e=u(this.flatRecord[o],this.flatRecord);Pb(e)&&(this.onGoingVisits[a][o]=e)}return await this.settlePromises(this.onGoingVisits[a],a),this.onGoingVisits[a]={},this}}function w5(d,u){switch(d.id){case Ee["built-in-base-entity"].BUILT_IN_PERSISTED_ENTITY_ENTITY.id:{const i=d.project.entities.filter(v=>!!v.implements.find(E=>E.id===Ee["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.id)),a=i.find(v=>{const E=v.properties.find($=>$.implements&&$.implements.id===Ee["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.default.id),b=E==null?void 0:E.getDefaultValue();return(b==null?void 0:b.value)===!0});if(!a&&i.length){const E=i[0].properties.find(A=>A.implements&&A.implements.id===Ee["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.default.id),b=E==null?void 0:E.defaultValue;if(b)b.metaSync({value:!0},u);else if(E!=null&&E.dataType){const A={id:N.UUID.uuid(),version:N.UUID.uuid(),createdAt:(u==null?void 0:u.timestamp)||new Date().toISOString(),author:N.sessionAuthor,previousVersion:null,deleted:!1,type:f.LiteralValue,standaloneParent:null,name:Q.EntityTemplate,autogeneration:null,value:!0,valueAsTypeSingle:null,valueAsTypeList:null,parent:E==null?void 0:E.toReference()},$=te(A,d.project);return $.setParent(E,u),$.initChildren(u),u==null||u.add($,S.Added),$.addSelfToProject(u),{newEntities:[$]}}return{newEntities:[]}}else if(a)return{newEntities:[]};const o=d.project.get(Ee["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.id),p=wm(o,"Main database",u);if(p.errors.length>0)return{newEntities:[]};const e=p.properties.find(v=>v.implements&&v.implements.id===Ee["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.default.id),y=e==null?void 0:e.defaultValue;if(y)y.metaSync({value:!0},u);else if(e!=null&&e.dataType){const v={id:N.UUID.uuid(),version:N.UUID.uuid(),createdAt:(u==null?void 0:u.timestamp)||new Date().toISOString(),author:N.sessionAuthor,previousVersion:null,deleted:!1,type:f.LiteralValue,standaloneParent:null,name:Q.EntityTemplate,autogeneration:null,value:!0,valueAsTypeSingle:null,valueAsTypeList:null,parent:e==null?void 0:e.toReference()},E=te(v,d.project);E.setParent(e,u),E.initChildren(u),u==null||u.add(E,S.Added),E.addSelfToProject(u)}return{newEntities:[p]}}}return{newEntities:[]}}function R5(d,u){const i=[],a=[],o=[],p=[];return d.implements.filter(y=>y.type===f.BuiltInBaseEntity).forEach(y=>{var v;switch(y.id){case Ee["built-in-base-entity"].BUILT_IN_PERSISTED_ENTITY_ENTITY.id:{const E=d.project.entities.filter(V=>V.implements.find(U=>U.id===Ee["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.id));let b=E.find(V=>!!V.properties.find(U=>{var G;return U.implements&&U.implements.id===Ee["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.default.id&&((G=U.getDefaultValue())==null?void 0:G.value)===!0}));if(!b&&E.length)b=E[0];else if(!b&&!E.length){b=d.project.getBuiltIn(Ee["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.id).implement("Relational database",u);const U=b.properties.find(G=>{var K;return((K=G.implements)==null?void 0:K.id)===Ee["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.default.id});(v=U==null?void 0:U.defaultValue)==null||v.metaSync({value:!0},u),a.push(b)}const A=d.properties.find(V=>V.implements&&V.implements.id===Ee["built-in-base-entity"].BUILT_IN_PERSISTED_ENTITY_ENTITY.properties.database.id),$=A==null?void 0:A.defaultValue;if(A&&!$){const V={id:N.UUID.uuid(),version:N.UUID.uuid(),createdAt:(u==null?void 0:u.timestamp)||new Date().toISOString(),author:N.sessionAuthor,previousVersion:null,deleted:!1,type:f.LiteralValue,standaloneParent:null,name:Q.EntityTemplate,autogeneration:null,value:null,valueAsTypeSingle:(b==null?void 0:b.toJSON())||null,valueAsTypeList:null,parent:A==null?void 0:A.toReference()},U=te(V,d.project);U.hydrateAncestors(),U.setParent(A,u),U.addSelfToProject(u),U.initChildren(u),u==null||u.add(U,S.Added),a.push(U);return}else $&&!$.valueAsTypeSingle&&$.setValueAsTypeSingle(b||null,u);return}}}),{self:d,updated:R(i),added:R(a),removed:R(o),affected:R(p)}}function wm(d,u,i,a){const o=a||N.UUID.uuid(),p=N.UUID.uuid(),e={id:o,version:p,createdAt:(i==null?void 0:i.timestamp)||new Date().toISOString(),author:N.sessionAuthor,previousVersion:null,deleted:!1,name:u,type:f.DefinitionEntity,codeName:null,description:null,static:d.static,abstract:!1,properties:[],methods:[],abstractMethods:[],extends:[],implements:[d.toJSON()],x:0,y:0,parent:d.project.toReference()};w5(d,i);const y=te(e,d.project);return y.hydrateAncestors(),i==null||i.add(y,S.Added),y.addSelfToProject(i),y.addImplementation(d),y.setParent(d.project,i),y.initChildren(i),R5(y,i),y}function Nb(d,u){return u.entities.find(o=>{const p=o.properties,e=p.map(A=>A.name),y=d.every(A=>e.includes(A)),v=e.filter(A=>!d.includes(A)),E=p.every(A=>!v.includes(A.name)||!A.required);return y&&E})||null}function _5(d,u,i,a=Ei.OrDataTypeGroup){const o=[],p=[],e=[],y=[],E={id:N.UUID.uuid(),version:N.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||new Date().toISOString(),author:N.sessionAuthor,previousVersion:null,deleted:!1,type:f.DataType,options:null,implementationChooseOne:!1,entity:d.toJSON(),isList:!1,asType:!1,andChildrenGroup:null,orChildrenGroup:null,staticEntities:null,interactiveEntities:null,actionEntities:null,like:!0,inferred:!1,parentRelationType:a,parent:u.toReference()},b=te(E,d.project);return p.push(b),b.setParent(u,i),b.initChildren(i),i==null||i.add(b,S.Added),b.setEntity(d,i),b.addSelfToProject(i),{updated:R(o),added:R(p),removed:R(e),affected:R(y),self:b}}function Vb(d,u,i,a,o){var E,b,A,$,V,U,G,K;const p=[],e=[],y=[],v=[];switch(typeof d){case"string":let Z=!1;const ie=new Date(d);if(ie instanceof Date&&!isNaN(ie.valueOf())&&(Z=!0),Z){const X=u.project.getBuiltIn(Ee[f.PrimitiveEntity][Q.Date].id);u.setEntity(X,a);break}else{const X=u.project.getBuiltIn(Ee[f.PrimitiveEntity][Q.String].id);u.setEntity(X,a);break}case"number":u.setEntity(u.project.getBuiltIn(Ee[f.PrimitiveEntity][Q.Number].id),a);break;case"boolean":u.setEntity(u.project.getBuiltIn(Ee[f.PrimitiveEntity][Q.Boolean].id),a);break;case"object":if(d===null){u.setEntity(u.project.getBuiltIn(Ee[f.PrimitiveEntity][Q.Null].id),a);break}else if(Array.isArray(d))if(u.metaSync({isList:!0},a),d.length>0){const X=d.slice(0,5).filter(re=>re!==void 0);if(X.every(re=>typeof re==typeof X[0])&&(typeof X[0]!="object"||X[0]===null))switch(typeof X[0]){case"string":u.setEntity(u.project.getBuiltIn(Ee[f.PrimitiveEntity][Q.String].id),a);break;case"number":u.setEntity(u.project.getBuiltIn(Ee[f.PrimitiveEntity][Q.Number].id),a);break;case"boolean":u.setEntity(u.project.getBuiltIn(Ee[f.PrimitiveEntity][Q.Boolean].id),a);break;case"object":u.setEntity(u.project.getBuiltIn(Ee[f.PrimitiveEntity][Q.Null].id),a);break}else{const re=[];let fe=!1;X.forEach(H=>{var ce,z,oe,we;if(Array.isArray(H)&&(fe=!0),typeof H=="object"&&!Array.isArray(H)&&H!==null){const xe=Rm(H,u.project,{...i,id:N.UUID.uuid()},a,o);xe.hasCreated&&re.push((ce=xe.changeSet)==null?void 0:ce.self),p.push(...(z=xe.changeSet)==null?void 0:z.updated),e.push(...(oe=xe.changeSet)==null?void 0:oe.added),y.push(...(we=xe.changeSet)==null?void 0:we.removed)}});const Y=R(re);if(!Y.length&&!fe){X.forEach(H=>{const ce={id:N.UUID.uuid(),version:N.UUID.uuid(),createdAt:(a==null?void 0:a.timestamp)||new Date().toISOString(),author:N.sessionAuthor,previousVersion:null,deleted:!1,type:f.DataType,options:null,implementationChooseOne:!1,entity:null,isList:!1,asType:!1,andChildrenGroup:null,orChildrenGroup:null,staticEntities:!1,interactiveEntities:!0,actionEntities:!1,like:!0,inferred:!1,parentRelationType:Ei.OrDataTypeGroup,parent:u.toReference()},z=te(ce,u.project);switch(z.setParent(u,a),z.initChildren(a),a==null||a.add(z,S.Added),z.addSelfToProject(a),typeof H){case"string":z.setEntity(z.project.getBuiltIn(Ee[f.PrimitiveEntity][Q.String].id),a);break;case"number":z.setEntity(z.project.getBuiltIn(Ee[f.PrimitiveEntity][Q.Number].id),a);break;case"boolean":z.setEntity(z.project.getBuiltIn(Ee[f.PrimitiveEntity][Q.Boolean].id),a);break;case"object":z.setEntity(z.project.getBuiltIn(Ee[f.PrimitiveEntity][Q.Null].id),a);break}});break}else Y.length===1&&!fe?u.setEntity(Y[0],a):X.forEach(H=>{if(typeof H=="object"&&!Array.isArray(H)&&H!==null){const ce=Nb(Object.keys(H),u.project);if(ce){const z=_5(ce||Y[0],u,a,Ei.OrDataTypeGroup);p.push(...z.updated),e.push(...z.added),y.push(...z.removed)}}else{const ce={id:N.UUID.uuid(),version:N.UUID.uuid(),createdAt:(a==null?void 0:a.timestamp)||new Date().toISOString(),author:N.sessionAuthor,previousVersion:null,deleted:!1,type:f.DataType,options:null,implementationChooseOne:!1,entity:null,isList:Array.isArray(H),asType:!1,andChildrenGroup:null,orChildrenGroup:null,staticEntities:!1,interactiveEntities:!0,actionEntities:!1,like:!0,inferred:!1,parentRelationType:Ei.OrDataTypeGroup,parent:u.toReference()},z=te(ce,u.project);z.setParent(u,a),z.initChildren(a),a==null||a.add(z,S.Added),z.addSelfToProject(a);const oe=Vb(H,z,{...i,id:N.UUID.uuid()},a,o);p.push(...oe.updated),e.push(...oe.added),y.push(...oe.removed)}})}}else{const X=Rm(d[0],u.project,{...i},a,o);u.setEntity((E=X.changeSet)==null?void 0:E.self,a),p.push(...(b=X.changeSet)==null?void 0:b.updated),e.push(...(A=X.changeSet)==null?void 0:A.added),y.push(...($=X.changeSet)==null?void 0:$.removed);break}else{const X=Rm(d,u.project,{...i},a,o);u.setEntity((V=X.changeSet)==null?void 0:V.self,a),p.push(...(U=X.changeSet)==null?void 0:U.updated),e.push(...(G=X.changeSet)==null?void 0:G.added),y.push(...(K=X.changeSet)==null?void 0:K.removed);break}}return{updated:R(p),added:R(e),removed:R(y),affected:R(v),self:u}}function Rm(d,u,i,a,o){const p=[],e=[],y=[],v=[],E=Object.keys(d),b=Nb(E,u);if(b)return{hasCreated:!1,changeSet:{updated:[],added:[],removed:[],affected:[],self:b}};const A=o?i.name+" of "+o.name:i.name,V={id:i.id||N.UUID.uuid(),version:N.UUID.uuid(),createdAt:(a==null?void 0:a.timestamp)||new Date().toISOString(),author:N.sessionAuthor,previousVersion:null,deleted:!1,name:A,codeName:null,type:f.DefinitionEntity,description:i.description||null,static:i.static||!1,abstract:i.abstract||!1,properties:[],methods:[],abstractMethods:[],extends:[],implements:[],x:0,y:0,parent:u.toReference()},U=te(V,u);return U.setParent(u,a),U.initChildren(a),a==null||a.add(U,S.Added),U.addSelfToProject(a),e.push(U),E.forEach((G,K)=>{const ie={id:N.UUID.uuid(),version:N.UUID.uuid(),createdAt:(a==null?void 0:a.timestamp)||new Date().toISOString(),author:N.sessionAuthor,previousVersion:null,deleted:!1,name:G,type:f.Property,codeName:G,description:null,static:!1,abstract:!1,defaultValue:null,constant:!1,interactive:!0,dataType:null,implements:null,extends:null,index:K,hidden:!1,private:!1,required:!0,parent:U.toReference()},X=te(ie,u);X.setParent(U,a),X.initChildren(a),a==null||a.add(X,S.Added),X.addSelfToProject(a),e.push(X);const ue=d[G],fe={id:N.UUID.uuid(),version:N.UUID.uuid(),createdAt:(a==null?void 0:a.timestamp)||new Date().toISOString(),author:N.sessionAuthor,previousVersion:null,deleted:!1,type:f.DataType,parentRelationType:null,options:null,implementationChooseOne:!1,entity:null,isList:!1,asType:!1,andChildrenGroup:null,orChildrenGroup:null,staticEntities:!1,interactiveEntities:!0,actionEntities:!1,like:!0,inferred:!1,parent:X.toReference()},Y=te(fe,u);Y.setParent(X,a),Y.initChildren(a),a==null||a.add(Y,S.Added),Y.addSelfToProject(a),e.push(Y);const H=Vb(ue,Y,{...i,name:G,id:N.UUID.uuid()},a,o||U);p.push(...H.updated),e.push(...H.added),y.push(...H.removed)}),{hasCreated:!0,changeSet:{updated:R(p),added:R(e),removed:R(y),affected:R(v),self:U}}}function ja(d,u,i,a){const o=[];return!d.length||!u.length?{errors:o,overlap:!1}:(d.length>u.length?d.forEach(p=>{const e=u.find(v=>v.name===p.name),y=u.find(v=>{var E,b;return!!p.implements&&((E=v.implements)==null?void 0:E.id)===((b=p.implements)==null?void 0:b.id)});if(e){const v=new dr({id:p.id+"--"+e.id+"--"+a,message:`Entity of type ${p.type} named "${p.name}" with id "${p.id}" overrides a base ${e.type} ${e.name} with id "${e.id}" that has the same name`,severity:q.Error,code:a,entity:p,firstRelationship:e});o.push(v)}if(y){const v=new dr({id:p.id+"--"+y.id+"--"+i,message:`Entity of type ${p.type} named "${p.name}" with id "${p.id}" overrides a base ${y.type} ${y.name} with id "${y.id}" that implements the same base descriptor`,severity:q.Error,code:i,entity:p,firstRelationship:y});o.push(v)}}):u.forEach(p=>{var v;const e=d.find(E=>E.name===p.name),y=d.find(E=>{var b,A;return!!E.implements&&((b=E.implements)==null?void 0:b.id)===((A=p.implements)==null?void 0:A.id)});if(e){const E=new dr({id:e.id+"--"+p.id+"--"+a,message:`Entity of type ${e.type} named "${e.name}" with id "${e.id}" overrides a base entity ${p.name} with id "${p.id}" that has the same name`,severity:q.Error,code:a,entity:e,firstRelationship:p});o.push(E)}if(y){const E=new dr({id:y.id+"--"+p.id+"--"+i,message:`Entity of type ${y.type} named "${y.name}" with id "${y.id}" overrides a base entity ${p.name} with id "${p.id}" that implements the same base ${(v=y==null?void 0:y.implements)==null?void 0:v.type}`,severity:q.Error,code:i,entity:y,firstRelationship:p});o.push(E)}}),{errors:o,overlap:!!o.length})}function GIe(d,u){return d.abstract||(d.properties.forEach(a=>{a.abstract||a.metaSync({abstract:!0},u)}),Object.values(d.detachedDependents).forEach(a=>{a.field===dA.Entity&&a.entity.remove({ignoreUpstream:!1},u)}),d.metaSync({abstract:!0},u)),d}function SIe(d,u){return d.abstract&&(d.properties.forEach(a=>{a.abstract&&a.metaSync({abstract:!1},u)}),Object.values(d.detachedDependents).forEach(a=>{(a.field===Sm.Implements||a.field===Sm.Extends)&&a.entity.onDetachedDependencyRemoved(d,a.field,u)}),d.metaSync({abstract:!1},u)),d}function KIe(d,u){return d.static||(d.properties.forEach(a=>{a.static||a.metaSync({static:!0},u)}),d.metaSync({static:!0},u)),d}function kIe(d,u){return d.static&&d.metaSync({static:!1},u),d}var g5=(d=>(d.StringValueMustNotHaveSpaces="string-value-must-not-have-spaces",d.StringValueMustNotHaveDashes="string-value-must-not-have-dashes",d))(g5||{});function D5(d,u){const i=[],a=u;if(!a)return{errors:i,override:u};if(typeof a!="string")return{errors:[],override:u};if(a.includes(" ")){const o=new dr({id:d.id+"--string-value-must-not-have-spaces",message:`Entity of type ${d.type} with id "${d.id}" has an invalid value "${u}". The value cannot contain spaces.`,severity:q.Error,code:"string-value-must-not-have-spaces",entity:d});i.push(o)}return{errors:i,override:a.replace(/\s/g,"-")}}function O5(d,u){const i=[],a=u;if(!a)return{errors:i,override:u};if(typeof a!="string")return{errors:[],override:u};if(a.includes(" ")){const o=new dr({id:d.id+"--string-value-must-not-have-spaces",message:`Entity of type ${d.type} with id "${d.id}" has an invalid value "${u}". The value cannot contain spaces or dashes.`,severity:q.Error,code:"string-value-must-not-have-spaces",entity:d});i.push(o)}if(a.includes("-")){const o=new dr({id:d.id+"--string-value-must-not-have-dashes",message:`Entity of type ${d.type} with id "${d.id}" has an invalid value "${u}". The value cannot contain spaces or dashes.`,severity:q.Error,code:"string-value-must-not-have-dashes",entity:d});i.push(o)}return{errors:i,override:a.replace(/\s|-/g,"_")}}function Lb(d,u){var i;if(d.type===f.LiteralValue){let a=(i=d.value)==null?void 0:i.toString();try{a=JSON.stringify(d.value,null,2)}catch{}return`${d.type}: ${d.id} (${ne(d,u)}) = ${a}`}if(d.type===f.DataType){if(d instanceof vs||d.increaseVersion)return`${d.type}: ${d.id} (${iu(d)})`;try{const a=iu(d);return`${d.type}: ${d.id} (${a})`}catch{}}return`${d.type}: ${d.id} (${ne(d,u)})`}function Yd(d,u){const i=bo(d);if(i.length===0)return{list:[],last:null};let a=null;return{list:i.flatMap(p=>{if(p===u)return a=p,[p];const e=Yd(p,u);return e.last&&(a=e.last),[p,...e.list]}),last:a}}function _l(d,u){const i=d.calledBy;if(i.length===0)return{list:[],last:null,callType:null};let a=null,o=null;return{list:i.flatMap(e=>{if(e===u)return a=e,Pt.includes(e.type)?e.parent.type===f.Loop?o="loop-body":o="entry":e.successCalls.includes(d)?o="success":e.errorCalls.includes(d)&&(o="error"),[e];if(!Ti.includes(e.type))return[e];const y=_l(e,u);return y.last&&(a=y.last,o=y.callType),[e,...y.list]}),last:a,callType:o}}function _m(d){if(d.type===f.Loop){const u=[...Mi(ti(d.successCalls)).map(o=>({callee:o,callType:"success"})),...Mi(ti(d.errorCalls)).map(o=>({callee:o,callType:"error"})),...(d.body?Rt(d.body):[]).map(o=>({callee:o,callType:"loop-body"}))];return R(u.map(o=>o.callee)).map(o=>{var e;const p=(e=u.find(y=>y.callee===o))==null?void 0:e.callType;return{callee:o,callType:p}})}if(fr.includes(d.type)){const u=[...Mi(ti(d.successCalls)).map(o=>({callee:o,callType:"success"})),...Mi(ti(d.errorCalls)).map(o=>({callee:o,callType:"error"}))];return R(u.map(o=>o.callee)).map(o=>{var e;const p=(e=u.find(y=>y.callee===o))==null?void 0:e.callType;return{callee:o,callType:p}})}if(Pt.includes(d.type)){const u=[...Mi(ti(d.calls)).map(o=>d.parent.type===f.Loop?{callee:o,callType:"loop-body"}:{callee:o,callType:"entry"})];return R(u.map(o=>o.callee)).map(o=>{var e;const p=(e=u.find(y=>y.callee===o))==null?void 0:e.callType;return{callee:o,callType:p}})}return[]}function Mb(d,u,i,a,o=!0){return d.reduce((e,y)=>{if(!gi.includes(y.type))return e;const v=_m(y);if(y===u||y===i)return[...e,{ancestor:y,callType:a}];const E=v.find(A=>A.callee===u),b=v.find(A=>A.callee===i);if(!E&&!b)return e;if(E&&b){if(E.callType===b.callType)return[...e,{ancestor:y,callType:E.callType}];if(!o)return[...e,{ancestor:y,callType:E.callType}]}else return[...e,{ancestor:y,callType:(E==null?void 0:E.callType)||(b==null?void 0:b.callType)}];return e},[])}function Bb(d,u,i,a=!0){let o,p=[];if(Pt.includes(i.type))i.parent.type===f.Loop?o="loop-body":o="entry",p=Mb(i.calls,d,u,o,a);else if(fr.includes(i.type)){const y=Mb(i.successCalls,d,u,"success",a),v=Mb(i.errorCalls,d,u,"error",a);y.length&&!v.length&&(p.push(...y.map(E=>({ancestor:E.ancestor,callType:E.callType}))),o="success"),!y.length&&v.length&&(p.push(...v.map(E=>({ancestor:E.ancestor,callType:E.callType}))),o="error")}if(p.length===0)return{ancestor:null,callType:null};if(p.length===1){const y=p[0].ancestor,v=_m(y),E=v.find(A=>A.callee===d),b=v.find(A=>A.callee===u);return!E&&!b&&!a?{ancestor:null,callType:null}:{ancestor:y,callType:(E==null?void 0:E.callType)||(b==null?void 0:b.callType)}}const e=p.filter(y=>!p.some(v=>v.ancestor!==y.ancestor&&_l(y.ancestor,v.ancestor).last===v.ancestor));if(e.length===1){const y=Bb(d,u,e[0].ancestor,a);return y.ancestor?{ancestor:y.ancestor,callType:y.callType}:{ancestor:e[0].ancestor,callType:e[0].callType}}return{ancestor:i,callType:o}}function Ub(d,u,i=!0){var e,y,v,E;if(!d||!u)throw new Error("Both entities must be defined to find a common ancestor");if(d===u)return{ancestor:d,callType:"same-entity"};if(!((e=d.calledBy)!=null&&e.length)&&!((y=u.calledBy)!=null&&y.length))return{ancestor:null,callType:null};if(Ti.includes(d.type)&&gi.includes(u.type)&&(v=d.calledBy)!=null&&v.every(b=>b===u)){if(Pt.includes(u.type))return u.parent.type===f.Loop?{ancestor:u,callType:"loop-body"}:{ancestor:u,callType:"entry"};if(u.successCalls.includes(d))return{ancestor:u,callType:"success"};if(u.errorCalls.includes(d))return{ancestor:u,callType:"error"}}if(Ti.includes(u.type)&&gi.includes(d.type)&&(E=u.calledBy)!=null&&E.every(b=>b===d)){if(Pt.includes(d.type))return d.parent.type===f.Loop?{ancestor:d,callType:"loop-body"}:{ancestor:d,callType:"entry"};if(d.successCalls.includes(u))return{ancestor:d,callType:"success"};if(d.errorCalls.includes(u))return{ancestor:d,callType:"error"}}const a=Qp(d),o=Qp(u);if(!a||!o)return{ancestor:null,callType:null};if(a!==o)return{ancestor:null,callType:null};const p=Bb(d,u,a,i);return p.ancestor?{ancestor:p.ancestor,callType:p.callType}:{ancestor:a,callType:"entry"}}function C5(d){if(!d)return{ancestor:null,callType:null};const u=d.calledBy;if(u.length===0){if(mt.includes(d.type)){const p=d.internalCalls.find(e=>!!e.calledBy.length);if(p)return C5(p)}return{ancestor:null,callType:null}}if(u.length===1){if(Pt.includes(u[0].type))return u[0].parent.type===f.Loop?{ancestor:u[0],callType:"loop-body"}:{ancestor:u[0],callType:"entry"};if(u[0].successCalls.includes(d))return{ancestor:u[0],callType:"success"};if(u[0].errorCalls.includes(d))return{ancestor:u[0],callType:"error"}}let i=u[0],a=null;for(let o=1;o<u.length&&i;o++){const p=u[o];if(!Ti.includes(p.type)){i=p,Pt.includes(i.type)?i.parent.type===f.Loop?a="loop-body":a="entry":i.successCalls.includes(d)?a="success":i.errorCalls.includes(d)&&(a="error");continue}if(i===p)continue;const e=Ub(i,p);e.ancestor?(i=e.ancestor,a=e.callType):(i=null,a=null)}return i?{ancestor:i,callType:a}:{ancestor:null,callType:null}}function jb(d){if(!d)return null;if(jv.includes(d.type))return d;const u=d.parent;return u?jb(u):null}function xb(d,u=new Set){return d.writesValues.reduce((i,a)=>u.has(a.id)?i:(u.add(a.id),cn.includes(a.type)?[...i,a]:Fr.includes(a.type)?[...i,a,...xb(a,u)]:i),[])}function qIe(d){if(![f.VariableDeclaration,f.OutputMap].includes(d.type))throw new Error("getEarliestSingleCallerAncestorOfValueWriterAndItsValueReaders can only be used with a value writer entity");let u;if(d.type===f.VariableDeclaration?u=d:d.type===f.OutputMap&&(u=d.parent),!u)throw new Error("getEarliestSingleCallerAncestorOfValueWriterAndItsValueReaders can only be used with a value writer entity that has a caller");const i=R([d,...xb(d)]),a=R(i.map(e=>jb(e)).flatMap(e=>Tr.includes(e==null?void 0:e.type)?e.calledBy:[e]));let o=a[0],p=null;for(let e=1;e<a.length&&o;e++){const y=a[e];if(!Ti.includes(y.type)){o=y,Pt.includes(o.type)?o.parent.type===f.Loop?p="loop-body":p="entry":o.successCalls.includes(u)?p="success":o.errorCalls.includes(u)&&(p="error");continue}if(o===y)continue;const v=Ub(o,y);v.ancestor?(o=v.ancestor,p=v.callType):(o=null,p=null)}return o?{ancestor:o,callType:p||"success"}:{ancestor:null,callType:null}}function Xp(d){const u=d.calledBy;if(u.length===0)return d.project;const i=u.reduce((a,o)=>{const p=Ji(o,d.project);return!p||p.type===f.Project?a:a.type===f.Project||Yd(p,a).last?p:(Yd(a,p).last,a)},d.project);return i.type===f.FunctionDeclaration&&i.parent.type===f.Loop?i.parent:i}function We(d,u){let i=Xp(d);if(d.type===f.InternalCall)if(d.parent.type===f.VariableInstance){const o=Qs(i,d.parent.declaration,d.project);!o.compatible&&o.type!=="b-is-global-a-is-not"?d.parent.remove({ignoreUpstream:!1},u):(d.parent.setParent(i,u),d.parent.addSelfToProject(u))}else d.parent.setParent(i,u),d.parent.addSelfToProject(u);else if((d.type===f.ContinueStatement||d.type===f.BreakStatement)&&i.type!==f.Loop){d.remove({ignoreUpstream:!1},u);return}else if(d.type===f.ReturnStatement&&!Mr.includes(i.type)){d.remove({ignoreUpstream:!1},u);return}else if(mt.includes(d.type)){const o=d.usedInternalCalls[0];if(o)if(i=Xp(o),d.type===f.VariableInstance){const p=Qs(i,d.declaration,d.project);!p.compatible&&p.type!=="b-is-global-a-is-not"?d.remove({ignoreUpstream:!1},u):(d.setParent(i,u),d.addSelfToProject(u))}else d.setParent(i,u),d.addSelfToProject(u);else if(d.type===f.VariableInstance){const p=Qs(i,d.declaration,d.project);!p.compatible&&p.type!=="b-is-global-a-is-not"?d.remove({ignoreUpstream:!1},u):(d.setParent(i,u),d.addSelfToProject(u))}else d.setParent(i,u),d.addSelfToProject(u)}else d.setParent(i,u),d.addSelfToProject(u);if(Tr.includes(d.type))return;Rt(d).forEach(o=>{let p=Xp(o);if(o.type===f.InternalCall)if(o.parent.type===f.VariableInstance){const e=Qs(p,o.parent.declaration,d.project);!e.compatible&&e.type!=="b-is-global-a-is-not"?o.parent.remove({ignoreUpstream:!1},u):(o.parent.setParent(p,u),o.parent.addSelfToProject(u))}else o.parent.setParent(p,u),o.parent.addSelfToProject(u);else if((o.type===f.ContinueStatement||o.type===f.BreakStatement)&&p.type!==f.Loop){o.remove({ignoreUpstream:!1},u);return}else if(o.type===f.ReturnStatement&&!Mr.includes(p.type)){o.remove({ignoreUpstream:!1},u);return}else if(mt.includes(o.type)){const e=o.usedInternalCalls[0];if(e)if(p=Xp(e),o.type===f.VariableInstance){const y=Qs(p,o.declaration,d.project);!y.compatible&&y.type!=="b-is-global-a-is-not"?o.remove({ignoreUpstream:!1},u):(o.setParent(p,u),o.addSelfToProject(u))}else o.setParent(p,u),o.addSelfToProject(u);else if(o.type===f.VariableInstance){const y=Qs(p,o.declaration,d.project);!y.compatible&&y.type!=="b-is-global-a-is-not"?o.remove({ignoreUpstream:!1},u):(o.setParent(p,u),o.addSelfToProject(u))}else o.setParent(p,u),o.addSelfToProject(u)}else o.setParent(p,u),o.addSelfToProject(u)})}function gm(d,u,i=new Set){const a=Rn(d),o=Rn(u),p=a.filter(v=>!o.includes(v)),e=a.filter(v=>o.includes(v)),y=p.reduce((v,E)=>i.has(E.id)?v:(i.add(E.id),R([...v,...gm(E,u,i)])),[]);return R([...e,...y])}function gl(d,u){const i=Yd(d,u);return i.last===u&&i.list.length>0&&i.list[0]!==u}function Fb(d,u){return!!Yd(d,u).last}function ZIe(d,u){return!!_l(d,u).last}function Qp(d){if(Pt.includes(d.type))return d;if([...Ti,f.VariableDeclaration].includes(d.type)){const u=d.parent;return Pt.includes(u.type)?u:null}return null}function Gb(d,u){if(!d||!u)throw new Error("Both entities must be defined to find a common ancestor");if(d===u)return d;const i=d.parent;if(i){if(i===u)return u;if(i.type===f.Project)return null}else return null;const a=u.parent;if(a){if(a===d)return d;if(a.type===f.Project)return null}else return null;return Gb(i,a)}function JIe(d,u,i=!0){if(!d||!u)throw new Error("Both entities must be defined to find a common ancestor");if(d===u)return{ancestor:d,callType:"same-entity"};if(Ti.includes(d.type)&&gi.includes(u.type)){const y=_l(d,u),v=y.last;if(v){if(v===u)return{ancestor:u,callType:y.callType}}else return{ancestor:null,callType:null}}if(Ti.includes(u.type)&&gi.includes(d.type)){const y=_l(u,d),v=y.last;if(v){if(v===d)return{ancestor:d,callType:y.callType}}else return{ancestor:null,callType:null}}const a=Qp(d),o=Qp(u);if(!a||!o)return{ancestor:null,callType:null};if(a!==o)return{ancestor:null,callType:null};if(a.calls.includes(d)||a.calls.includes(u))return{ancestor:a,callType:"entry"};const p=a.calls.reduce((y,v)=>{if(!gi.includes(v.type))return y;const E=_m(v),b=E.find($=>$.callee===d),A=E.find($=>$.callee===u);return b&&A&&(!i||b.callType===A.callType)?[...y,{ancestor:v,callType:b.callType}]:y},[]);if(p.length===0)return{ancestor:null,callType:null};if(p.length===1)return{ancestor:p[0].ancestor,callType:p[0].callType};const e=p.filter(y=>!p.some(v=>v.ancestor!==y.ancestor&&_l(y.ancestor,v.ancestor).last===v.ancestor));return e.length===1?{ancestor:e[0].ancestor,callType:e[0].callType}:{ancestor:a,callType:"entry"}}function Er(d){if(ih.includes(d.type)){if(d.type===f.FunctionDeclaration){const u=d.parent;if(u.type===f.DefinitionEntity)return Er(u);if(u.type===f.Loop)return u}return d.type===f.DefinitionEntity&&d.parent.type===f.DataType?Er(d.parent):d}else{const u=d.parent;return u?Er(u):null}}function Dm(d,u){const i=ef(d,u);if(!i)return null;if(ih.includes(i.type)){if(i.type===f.FunctionDeclaration){const a=ef(i.parent,u);if(a){if(a.type===f.DefinitionEntity)return a;if(a.type===f.Loop)return a}}return i}else{const a=i.parent?ef(i.parent,u):null;return a?Dm(a,u):null}}function $5(d){if(!d)return null;if(Ti.includes(d.type))return d;const u=d.parent;return u?$5(u):null}function P5(d){if(!d)return null;if(fr.includes(d.type))return d;const u=d.parent;return u?P5(u):null}function N5(d){if(!d)return null;if(gi.includes(d.type))return d;const u=d.parent;return u?N5(u):null}function HIe(d){return d.type===f.VariableDeclaration?[d]:fr.includes(d.type)?[...d.inputs,...d.outputs||[]]:Tr.includes(d.type)?d.outputs:So.includes(d.type)||d.type===f.FunctionDeclaration?d.inputs:[]}function WIe(d){const u=Rn(d),i=[],a=[];gg.includes(d.type)&&i.push(...Om(d));const o=u.filter(p=>{const e=i.includes(p);return e?!1:Ti.includes(p.type)&&!e?(a.push(p),!1):!0});return i.sort((p,e)=>gl(e,p)?-1:0),a.sort((p,e)=>gl(e,p)?-1:0),[...i,...a,...o]}function V5(d){return[...d].sort((u,i)=>gl(i,u)?-1:0)}function YIe(d){const u=V5(d),i=[];return u.forEach(a=>{const o=i[i.length-1];if(o){const p=o[o.length-1];gl(a,p)?i.push([a]):o.push(a)}else i.push([a])}),i}function ti(d){const u=d.map(i=>Er(i));return R(u)}function Om(d){return fr.includes(d.type)?[...ti(d.successCalls),...ti(d.errorCalls)]:Pt.includes(d.type)?ti(d.calls):[]}function zIe(d,u){return Om(d).includes(u)}function Cm(d){return d.writesValues||[]}function XIe(d,u){return Cm(d).includes(u)}function L5(d){var u;return mt.includes((u=d==null?void 0:d.readsValue)==null?void 0:u.type)?d.readsValue:null}function QIe(d){return d.writesValues}function M5(d=[]){return d.map(L5).filter(u=>!!u)}function $m(d=[]){return d.map(u=>u.writesValues).flat().filter(u=>mt.includes(u.type))}function B5(d=[]){return d.map(u=>u.readsValue).filter(u=>!!u&&mt.includes(u.type))}function U5(d){return mt.includes(d.type)?d:null}function j5(d){return d.writesValues.map(U5).filter(u=>!!u)}function x5(d=[]){return d.reduce((u,i)=>i.type===f.OutputMap?[...u,...j5(i)]:u,[])}function Rt(d){return d.type===f.Loop?R([...Mi(ti(d.successCalls)),...Mi(ti(d.errorCalls)),...d.body?Rt(d.body):[]]):fr.includes(d.type)?R([...Mi(ti(d.successCalls)),...Mi(ti(d.errorCalls))]):Pt.includes(d.type)?R(Mi(ti(d.calls))):[]}function eAe(d){return fr.includes(d.type)?[...Mi(ti(d.successCalls)),...Mi(ti(d.errorCalls))]:Pt.includes(d.type)?Mi(ti(d.calls)):[]}function F5(d,u=new Set){return d.writesValues.filter(a=>mt.includes(a.type)&&!u.has(a.id)).reduce((a,o)=>u.has(o.id)?a:[...a,...mr(o,u)],[])}function G5(d,u=new Set){var a;return(((a=d.readsValue)==null?void 0:a.writesValues)||[]).filter(o=>mt.includes(o.type)&&!u.has(o.id)).reduce((o,p)=>u.has(p.id)?o:[...o,...mr(p,u)],[])}function mr(d,u=new Set){if(u.has(d.id))return[];if(d.type===f.ReturnStatement)return B5(d.outputs).reduce((a,o)=>[...a,...mr(o,u)],[]);if(d.type===f.FunctionCall||d.type===f.Operation||d.type===f.Condition)return[...Rt(d).reduce((p,e)=>{const y=Er(e);return[...p,...mr(y||e,u)]},[]),...M5(d.inputs),...x5(d.outputs)].reduce((p,e)=>[...p,...mr(e,u)],[]);if(So.includes(d.type)){const i=$m(d.inputs),o=Rt(d).reduce((p,e)=>{const y=Er(e);return[...p,...mr(y||e,u)]},[]);return i.push(...o),i.reduce((p,e)=>[...p,...mr(e,u)],[])}if(d.type===f.FunctionDeclaration){const i=[...$m(d.inputs)],o=Rt(d).reduce((p,e)=>{const y=Er(e);return[...p,...mr(y||e,u)]},[]);return i.push(...o),i.reduce((p,e)=>[...p,...mr(e)],[])}if(mt.includes(d.type)){u.add(d.id);const a=Rt(d).reduce((o,p)=>{const e=Er(p);return[...o,...mr(e||p,u)]},[]);return[d,...a,...G5(d,u),...F5(d,u)]}return[]}function Is(d,u=new Set){return u.has(d.id)?[]:(u.add(d.id),[...Rn(d).reduce((o,p)=>[...o,p,...Is(p,u)],[])])}function Mi(d){return d.reduce((u,i)=>i.type===f.ReturnStatement||i.type===f.ContinueStatement||i.type===f.BreakStatement?[...u,i]:[...u,i,...Rt(i)],[])}function S5(d){const u=d.entities||[],i=[...u,...d.functions||[],...d.events||[],...d.projects||[]],a=u.reduce((v,E)=>[...v,...E.properties],[]),o=u.reduce((v,E)=>[...v,...E.methods],[]),p=o.reduce((v,E)=>[...v,...$m(E.inputs),...Mi(ti(E.calls)),...E.returnStatements],[]),e=d.functions.reduce((v,E)=>[...v,...Mi(ti(E.calls)),...E.returnStatements],[]),y=d.events.reduce((v,E)=>[...v,...Mi(ti(E.calls)),...E.returnStatements],[]);return[...i,...a,...o,...p,...e,...y]}function K5(d,u){return u.filter(a=>{if(!a)return!1;switch(a.type){case f.FunctionCall:return a.inputs.find(o=>o.id===d.id)!==void 0||a.outputs.find(o=>o.id===d.id)!==void 0;case f.Condition:return a.successCalls.find(o=>o.id===d.id)!==void 0||a.errorCalls.find(o=>o.id===d.id)!==void 0||a.inputs.find(o=>o.id===d.id)!==void 0;case f.Operation:return a.outputs.find(o=>o.id===d.id)!==void 0;case f.VariableDeclaration:return fr.includes(d.type)?ES(d).find(p=>{var e;return((e=p.readsValue)==null?void 0:e.id)===a.id})!==void 0:!1;case f.DefinitionEntity:return a.properties.find(o=>o.id===d.id)!==void 0||a.methods.find(o=>o.id===d.id)!==void 0;case f.FunctionDeclaration:return a.inputs.find(o=>o.id===d.id)!==void 0||(a.returnStatements.map(o=>o.outputs).flat()||[]).find(o=>o.id===d.id)!==void 0;default:return!1}})}function tAe(d){const u=S5(d.project);return K5(d,u)}function ef(d,u){return d?typeof d=="string"?u[d]:d.type===f.GenericReference?u[d.entityId]:u[d.id]?u[d.id]:null:null}function k5(d={},u){const i={};return Object.keys(d).forEach(a=>{const o=u.get(a)||a,p=d[a];i[o]=p}),i}function zd(d,u={},i={}){const a={ignoreBuiltInBaseEntities:!1,allBuiltInEntityIds:[],entityMaps:new Map,...i};if(a.ignoreBuiltInBaseEntities&&(Wi.includes(d.type)||(a.allBuiltInEntityIds||[]).includes(d.id)))return{upstream:{},downstream:{}};const o=d,p=d,e=d,y=d,v=d,E=d,b=d,A=d,$=d,V=d,U=d,G=d,K=d,Z=[...K.readsValue?[K.readsValue]:[],...K.declaration?[K.declaration]:[],...(G.calledByEntry||[]).flatMap(re=>re),...(G.calledBySuccess||[]).flatMap(re=>re),...(G.calledByError||[]).flatMap(re=>re),...V.parent?[V.parent]:[]];Array.isArray(e.implements)?Z.push(...e.implements.flatMap(re=>re)):$.implements&&Z.push($.implements),Array.isArray(e.extends)?Z.push(...e.extends.flatMap(re=>re)):$.extends&&Z.push($.extends),v.valueAsTypeList&&Array.isArray(v.valueAsTypeList)&&Z.push(...v.valueAsTypeList.flatMap(re=>re)),v.valueAsTypeSingle&&Z.push(v.valueAsTypeSingle),(K.internalCalls||[]).forEach(re=>{const fe=J(re);if(fe&&u[fe]){const Y=u[fe];[...Y.calledByEntry||[],...Y.calledBySuccess||[],...Y.calledByError||[]].forEach(H=>{const ce=J(H);ce&&u[ce]&&Z.push(u[ce])})}});const ie=[...(o.inputs||[]).flatMap(re=>re),...(U.inputsDeclarations||[]).flatMap(re=>re),...(o.outputs||[]).flatMap(re=>re),...(U.outputsDeclarations||[]).flatMap(re=>re),...(K.internalCalls||[]).flatMap(re=>re),...K.writesValues||[],...G.dataType?[G.dataType]:[],...E.body?[E.body]:[],...G.defaultValue?[G.defaultValue]:[],...(G.successCalls||[]).flatMap(re=>re),...(G.errorCalls||[]).flatMap(re=>re),...(e.properties||[]).flatMap(re=>re),...(e.methods||[]).flatMap(re=>re),...(e.abstractMethods||[]).flatMap(re=>re),...b.error?[b.error]:[],...b.process?[b.process]:[],...V.throws?[V.throws]:[],...(p.andChildrenGroup||[]).flatMap(re=>re),...(p.orChildrenGroup||[]).flatMap(re=>re),...(A.entities||[]).flatMap(re=>re),...(A.functions||[]).flatMap(re=>re),...(A.functionCalls||[]).flatMap(re=>re),...(A.events||[]).flatMap(re=>re),...(A.conditions||[]).flatMap(re=>re),...(A.operations||[]).flatMap(re=>re),...(A.loops||[]).flatMap(re=>re),...(A.variableDeclarations||[]).flatMap(re=>re),...(A.variableInstances||[]).flatMap(re=>re),...(A.searches||[]).flatMap(re=>re),...(A.projects||[]).flatMap(re=>re),...(y.calls||[]).flatMap(re=>re)];d.type===f.DataType&&(p.entity&&u[J(p.entity)]&&u[J(p.entity)].parent&&J(u[J(p.entity)].parent)===d.id?ie.push(p.entity):p.entity&&Z.push(p.entity)),(K.internalCalls||[]).forEach(re=>{const fe=J(re);if(fe&&u[fe]){const Y=u[fe];[...Y.successCalls||[],...Y.errorCalls||[]].forEach(H=>{const ce=J(H);ce&&u[ce]&&ie.push(u[ce])})}});const X={},ue={};return Z.forEach(re=>{var H;const fe=J(re);if(fe&&a.ignoreBuiltInBaseEntities&&(Wi.includes(re.type)||(a.allBuiltInEntityIds||[]).includes(fe)))return;const Y=re.version;if(fe){const ce=((H=a.entityMaps)==null?void 0:H.get(fe))||fe;X[ce]=Y}}),ie.forEach(re=>{var H;const fe=J(re);if(fe&&a.ignoreBuiltInBaseEntities&&(Wi.includes(re.type)||(a.allBuiltInEntityIds||[]).includes(fe)))return;const Y=re.version;if(fe){const ce=((H=a.entityMaps)==null?void 0:H.get(fe))||fe;ue[ce]=Y}}),{upstream:X,downstream:ue}}function rAe(d,u){const i=[];if(Ti.includes(d.type)){Bs(d).forEach(p=>{const e=Dm(p,u);e&&i.push(e)});const o=[...d.inputs||[],...d.outputs||[]].map(p=>{const e=ef(p,u);return e?IS(e,u):null}).filter(p=>p!==null);i.push(...R(o))}if(mt.includes(d.type)){const a=Pm(d);a&&i.push(a)}return R(i)}function bo(d){const u=[];if(Ti.includes(d.type)){d.calledBy.forEach(o=>{const p=Er(o);p&&u.push(p)});const a=[...d.inputs||[],...d.outputs||[]].map(o=>Pm(o)).filter(o=>o!==null);u.push(...R(a))}if(mt.includes(d.type)){const i=Pm(d);i&&u.push(i)}return R(u)}function Bs(d){return[...d.calledByEntry||[],...d.calledByError||[],...d.calledBySuccess||[]].filter(u=>u.type!==f.GenericReference)}function q5(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.ActionDescriptor)throw new Error("Entity must be an action descriptor to be flattened");return[d,...d.inputs.flatMap(a=>me(a,u,i)),...d.outputs.flatMap(a=>me(a,u,i)),...d.error?me(d.error,u,i):[],...d.parent?me(d.parent,u,i):[]]}function Z5(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.ArgumentDeclaration)throw new Error("Entity must be an argument declaration to be flattened");return[d,...d.defaultValue?me(d.defaultValue,u):[],...d.writesValues.flatMap(a=>me(a,u,i)),...d.dataType?me(d.dataType,u,i):[],...d.parent?me(d.parent,u,i):[]]}function J5(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.BreakStatement)throw new Error("Entity must be a break statement to be flattened");return[d,...d.outputs.flatMap(a=>me(a,u,i)),...d.throws?me(d.throws,u,i):[],...(Bs(d)||[]).flatMap(a=>me(a,u,i)),...d.parent?me(d.parent,u,i):[]]}function H5(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.BuiltInBaseEntity)throw new Error("Entity must be a built-in base entity to be flattened");return[d,...(d.properties||[]).flatMap(a=>me(a,u,i)),...(d.methods||[]).flatMap(a=>me(a,u,i)),...(d.abstractMethods||[]).flatMap(a=>me(a,u,i)),...(d.extends||[]).flatMap(a=>me(a,u,i))]}function W5(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.Condition)throw new Error("Entity must be a condition to be flattened");return[d,...(d.inputs||[]).flatMap(a=>me(a,u,i)),...(d.successCalls||[]).flatMap(a=>me(a,u,i)),...(d.errorCalls||[]).flatMap(a=>me(a,u,i)),...(Bs(d)||[]).flatMap(a=>me(a,u,i)),...d.parent?me(d.parent,u,i):[]]}function Y5(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.ContinueStatement)throw new Error("Entity must be a continue statement to be flattened");return[d,...d.outputs.flatMap(a=>me(a,u,i)),...d.throws?me(d.throws,u,i):[],...(Bs(d)||[]).flatMap(a=>me(a,u,i)),...d.parent?me(d.parent,u,i):[]]}function z5(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.DefinitionEntity)throw new Error("Entity must be a definition entity to be flattened");return[d,...(d.extends||[]).flatMap(a=>me(a,u,i)),...(d.implements||[]).flatMap(a=>me(a,u,i)),...(d.properties||[]).flatMap(a=>me(a,u,i)),...(d.methods||[]).flatMap(a=>me(a,u,i)),...(d.abstractMethods||[]).flatMap(a=>me(a,u,i)),...d.parent?me(d.parent,u,i):[]]}function X5(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.DataType)throw new Error("Entity must be a data type to be flattened");return[d,...(d.andChildrenGroup||[]).flatMap(a=>me(a,u,i)),...(d.orChildrenGroup||[]).flatMap(a=>me(a,u,i)),...d.entity?me(d.entity,u,i):[],...d.parent?me(d.parent,u,i):[]]}function Q5(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.FunctionCall)throw new Error("Entity must be a function call to be flattened");return[d,...(d.inputs||[]).flatMap(a=>me(a,u,i)),...(d.outputs||[]).flatMap(a=>me(a,u,i)),...d.error?me(d.error,u,i):[],...d.process?me(d.process,u,i):[],...(Bs(d)||[]).flatMap(a=>me(a,u,i)),...(d.successCalls||[]).flatMap(a=>me(a,u,i)),...(d.errorCalls||[]).flatMap(a=>me(a,u,i)),...d.parent?me(d.parent,u,i):[]]}function eS(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.FunctionDeclaration)throw new Error("Entity must be a function declaration to be flattened");return[d,...(d.inputs||[]).flatMap(a=>me(a,u,i)),...(d.calls||[]).flatMap(a=>me(a,u,i)),...d.implements?me(d.implements,u,i):[],...d.parent?me(d.parent,u,i):[]]}function tS(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.GlobalEvent)throw new Error("Entity must be a global event to be flattened");return[d,...(d.inputs||[]).flatMap(a=>me(a,u,i)),...(d.calls||[]).flatMap(a=>me(a,u,i)),...d.implements?me(d.implements,u,i):[],...d.parent?me(d.parent,u,i):[]]}function rS(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.InputMap)throw new Error("Entity must be an input map to be flattened");return[d,...d.readsValue?me(d.readsValue,u,i):[],...d.declaration?me(d.declaration,u,i):[],...d.defaultValue?me(d.defaultValue,u,i):[],...d.parent?me(d.parent,u,i):[]]}function iS(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.InstalledProject)throw new Error("Entity must be an installed project to be flattened");return[d,...(d.functions||[]).flatMap(a=>me(a,u,i)),...(d.events||[]).flatMap(a=>me(a,u,i)),...d.parent?me(d.parent,u,i):[]]}function sS(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.InternalCall)throw new Error("Entity must be an internal call to be flattened");return[d,...(d.successCalls||[]).flatMap(a=>me(a,u,i)),...(d.errorCalls||[]).flatMap(a=>me(a,u,i)),...(d.inputs||[]).flatMap(a=>me(a,u,i)),...(d.outputs||[]).flatMap(a=>me(a,u,i)),...(Bs(d)||[]).flatMap(a=>me(a,u,i)),...d.error?me(d.error,u,i):[],...d.process?me(d.process,u,i):[],...d.parent?me(d.parent,u,i):[]]}function nS(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.LiteralValue)throw new Error("Entity must be a literal value to be flattened");return[d,...d.valueAsTypeSingle?me(d.valueAsTypeSingle,u,i):[],...d.valueAsTypeList&&Array.isArray(d.valueAsTypeList)?d.valueAsTypeList.flatMap(a=>me(a,u,i)):[],...d.parent?me(d.parent,u,i):[]]}function aS(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.Loop)throw new Error("Entity must be a loop to be flattened");return[d,...(d.inputs||[]).flatMap(a=>me(a,u,i)),...(d.outputs||[]).flatMap(a=>me(a,u,i)),...(d.successCalls||[]).flatMap(a=>me(a,u,i)),...(d.errorCalls||[]).flatMap(a=>me(a,u,i)),...d.error?me(d.error,u,i):[],...d.process?me(d.process,u,i):[],...d.body?me(d.body,u,i):[],...(Bs(d)||[]).flatMap(a=>me(a,u,i)),...d.parent?me(d.parent,u,i):[]]}function oS(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.Operation)throw new Error("Entity must be an operation to be flattened");return[d,...(d.successCalls||[]).flatMap(a=>me(a,u,i)),...(d.errorCalls||[]).flatMap(a=>me(a,u,i)),...(d.inputs||[]).flatMap(a=>me(a,u,i)),...(d.outputs||[]).flatMap(a=>me(a,u,i)),...d.error?me(d.error,u,i):[],...d.process?me(d.process,u,i):[],...(Bs(d)||[]).flatMap(a=>me(a,u,i)),...d.parent?me(d.parent,u,i):[]]}function lS(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.OutputMap)throw new Error("Entity must be an output map to be flattened");return[d,...(d.writesValues||[]).flatMap(a=>me(a,u,i)),...d.declaration?me(d.declaration,u,i):[],...d.defaultValue?me(d.defaultValue,u,i):[],...d.parent?me(d.parent,u,i):[]]}function dS(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.PrimitiveEntity)throw new Error("Entity must be a primitive entity to be flattened");return[d,...(d.properties||[]).flatMap(a=>me(a,u,i)),...(d.methods||[]).flatMap(a=>me(a,u,i)),...(d.abstractMethods||[]).flatMap(a=>me(a,u,i))]}function uS(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.Project)throw new Error("Entity must be a project to be flattened");return[d,...(d.entities||[]).flatMap(a=>me(a,u,i)),...(d.functions||[]).flatMap(a=>me(a,u,i)),...(d.events||[]).flatMap(a=>me(a,u,i)),...(d.projects||[]).flatMap(a=>me(a,u,i)),...(d.variableDeclarations||[]).flatMap(a=>me(a,u,i)),...(d.variableInstances||[]).flatMap(a=>me(a,u,i)),...(d.operations||[]).flatMap(a=>me(a,u,i)),...(d.conditions||[]).flatMap(a=>me(a,u,i)),...(d.functionCalls||[]).flatMap(a=>me(a,u,i)),...(d.projects||[]).flatMap(a=>me(a,u,i)),...(d.loops||[]).flatMap(a=>me(a,u,i)),...(d.searches||[]).flatMap(a=>me(a,u,i))]}function cS(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.Property)throw new Error("Entity must be a property to be flattened");return[d,...d.defaultValue?me(d.defaultValue,u,i):[],...d.dataType?me(d.dataType,u,i):[],...d.parent?me(d.parent,u,i):[]]}function pS(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.ReturnDeclaration)throw new Error("Entity must be a return declaration to be flattened");return[d,...d.readsValue?me(d.readsValue,u,i):[],...d.defaultValue?me(d.defaultValue,u,i):[],...d.dataType?me(d.dataType,u,i):[],...d.parent?me(d.parent,u,i):[]]}function fS(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.ReturnStatement)throw new Error("Entity must be a return statement to be flattened");return[d,...(d.outputs||[]).flatMap(a=>me(a,u,i)),...d.throws?me(d.throws,u,i):[],...(Bs(d)||[]).flatMap(a=>me(a,u,i)),...d.parent?me(d.parent,u,i):[]]}function hS(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.Search)throw new Error("Entity must be a search to be flattened");return[d,...(d.successCalls||[]).flatMap(a=>me(a,u,i)),...(d.errorCalls||[]).flatMap(a=>me(a,u,i)),...(d.inputsDeclarations||[]).flatMap(a=>me(a,u,i)),...(d.inputs||[]).flatMap(a=>me(a,u,i)),...(d.outputsDeclarations||[]).flatMap(a=>me(a,u,i)),...(d.outputs||[]).flatMap(a=>me(a,u,i)),...d.error?me(d.error,u,i):[],...(Bs(d)||[]).flatMap(a=>me(a,u,i)),...d.parent?me(d.parent,u,i):[]]}function yS(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.ValueDescriptor)throw new Error("Entity must be a value descriptor to be flattened");return[d,...d.defaultValue?me(d.defaultValue,u,i):[],...d.dataType?me(d.dataType,u,i):[],...d.parent?me(d.parent,u,i):[]]}function mS(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.VariableDeclaration)throw new Error("Entity must be a variable declaration to be flattened");return[d,...(d.successCalls||[]).flatMap(a=>me(a,u,i)),...(d.errorCalls||[]).flatMap(a=>me(a,u,i)),...(d.inputs||[]).flatMap(a=>me(a,u,i)),...(d.outputs||[]).flatMap(a=>me(a,u,i)),...(d.internalCalls||[]).flatMap(a=>me(a,u,i)),...(d.writesValues||[]).flatMap(a=>me(a,u,i)),...d.readsValue?me(d.readsValue,u,i):[],...d.defaultValue?me(d.defaultValue,u,i):[],...(Bs(d)||[]).flatMap(a=>me(a,u,i)),...d.dataType?me(d.dataType,u,i):[],...d.parent?me(d.parent,u,i):[]]}function vS(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.VariableInstance)throw new Error("Entity must be a variable instance to be flattened");return[d,...(d.successCalls||[]).flatMap(a=>me(a,u,i)),...(d.errorCalls||[]).flatMap(a=>me(a,u,i)),...(d.inputs||[]).flatMap(a=>me(a,u,i)),...(d.outputs||[]).flatMap(a=>me(a,u,i)),...(d.internalCalls||[]).flatMap(a=>me(a,u,i)),...(d.writesValues||[]).flatMap(a=>me(a,u,i)),...d.readsValue?me(d.readsValue,u,i):[],...d.defaultValue?me(d.defaultValue,u,i):[],...(Bs(d)||[]).flatMap(a=>me(a,u,i)),...d.declaration?me(d.declaration,u,i):[],...d.parent?me(d.parent,u,i):[]]}function Xs(){const d=new Set,u=E2.flatMap(i=>me(i,d)).map(i=>i.id);if(!u.includes("http-request-error-return-delaration-id"))throw new Error("Built-in base entities must be included in the list");return u}function me(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(!d)throw new Error("Entity must be defined to be flattened");if(d.type===f.GenericReference)return[];if(i.ignoreBuiltInBaseEntities&&(Wi.includes(d.type)||Xs().includes(d.id)))return[];if(u.has(d.id))return[];switch(d.type){case f.FunctionCall:return Q5(d,u,i);case f.Operation:return oS(d,u,i);case f.Condition:return W5(d,u,i);case f.Loop:return aS(d,u,i);case f.Search:return hS(d,u,i);case f.GlobalEvent:return tS(d,u,i);case f.ReturnStatement:return fS(d,u,i);case f.ContinueStatement:return Y5(d,u,i);case f.BreakStatement:return J5(d,u,i);case f.VariableDeclaration:return mS(d,u,i);case f.DefinitionEntity:return z5(d,u,i);case f.FunctionDeclaration:return eS(d,u,i);case f.Project:return uS(d,u,i);case f.ActionDescriptor:return q5(d,u,i);case f.ArgumentDeclaration:return Z5(d,u,i);case f.ReturnDeclaration:return pS(d,u,i);case f.ValueDescriptor:return yS(d,u,i);case f.InputMap:return rS(d,u,i);case f.OutputMap:return lS(d,u,i);case f.DataType:return X5(d,u,i);case f.InstalledProject:return iS(d,u,i);case f.InternalCall:return sS(d,u,i);case f.LiteralValue:return nS(d,u,i);case f.Property:return cS(d,u,i);case f.VariableInstance:return vS(d,u,i);case f.BuiltInBaseEntity:return i.ignoreBuiltInBaseEntities?[]:H5(d,u,i);case f.PrimitiveEntity:return i.ignoreBuiltInBaseEntities?[]:dS(d,u,i)}return[]}function Sb(d){return d.type===f.FunctionCall||d.type===f.InternalCall||[f.Operation,f.Condition,f.Loop].includes(d.type)?d.declaration.inputs:d.type===f.FunctionDeclaration||So.includes(d.type)?d.inputs:d.type===f.Search?d.inputsDeclarations:[]}function iAe(d,u){return u.type===f.Condition?u.inputs.find(i=>i.declaration.id===d.id):u.type===f.FunctionCall||u.type===f.Operation?u.inputs.find(i=>i.declaration.id===d.id):null}function ES(d){return fr.includes(d.type)?d.inputs:[]}function TS(d){var u;return d.type===f.FunctionCall?((u=d.declaration.returnStatements[0])==null?void 0:u.outputs)||[]:[f.Operation,f.Condition,f.Loop].includes(d.type)?d.declaration.outputs:d.type===f.Search?d.outputsDeclarations:Tr.includes(d.type)?d.outputs:[]}function sAe(d,u){return u.type===f.Condition?null:u.type===f.FunctionCall||u.type===f.Operation?u.outputs.find(i=>i.declaration.id===d.id):null}function nAe(d){return d.type===f.Condition?[]:fr.includes(d.type)?d.outputs:[]}function Pm(d){const u=d.readsValue;return u?Er(u):null}function IS(d,u){const i=d.readsValue;return i?Dm(i,u):null}function AS(d){const u=d.internalCalls||[];return R(ti(R(u.flatMap(i=>[...i.successCalls,...i.errorCalls]))))}function bS(d){const u=d.internalCalls||[];return R(R(u.flatMap(i=>[...i.successCalls,...i.errorCalls])))}function Xd(d){const u=Cm(d),i=[];return u.forEach(a=>{if(mt.includes(a.type))i.push(a);else if(cn.includes(a.type)){const o=Er(a.parent);i.push(o)}}),i}function Qd(d){const u=Cm(d),i=[];return u.forEach(a=>{if(mt.includes(a.type))i.push(a);else if(cn.includes(a.type)){const o=a.parent;i.push(o)}}),i}function R(d){const u=new Set;return d.filter(i=>!i||u.has(i.id)?!1:(u.add(i.id),!0))}function wS(d){return d.type===f.Project?null:jv.includes(d.type)?d:Wi.includes(d.type)?null:d.parent?wS(d.parent):null}function Rn(d,u=!1){const i=[];if(d.type===f.Project&&i.push(...(d==null?void 0:d.entities)||[],...(d==null?void 0:d.functions)||[],...(d==null?void 0:d.variableDeclarations)||[],...(d==null?void 0:d.variableInstances)||[],...(d==null?void 0:d.searches)||[],...(d==null?void 0:d.loops)||[],...(d==null?void 0:d.operations)||[],...(d==null?void 0:d.conditions)||[],...(d==null?void 0:d.functionCalls)||[],...(d==null?void 0:d.events)||[],...(d==null?void 0:d.projects)||[]),Mr.includes(d.type)&&i.push(...(d==null?void 0:d.detachedChildren)||[]),d.type===f.DefinitionEntity){const a=[...d.suggestedMethods,...d.methods].flatMap(o=>o.collapsed&&u?[]:Rn(o));i.push(...a)}if(d.type===f.Condition){const a=d.successCalls.map(p=>Er(p)),o=d.errorCalls.map(p=>Er(p));i.push(...a,...o)}if(So.includes(d.type)){if(d.collapsed&&u)return[];const a=d.inputs.map(p=>Xd(p)).flat(),o=d.calls.map(p=>Er(p));i.push(...R(a),...o)}if(fr.includes(d.type)&&d.type!==f.Condition&&d.type!==f.Loop){const a=d==null?void 0:d.outputs.map(e=>Xd(e)).flat(),o=d.successCalls.map(e=>Er(e)),p=d.errorCalls.map(e=>Er(e));i.push(...R(a),...o,...p)}if(mt.includes(d.type)){const a=Xd(d),o=AS(d);i.push(...a,...o)}if(d.type===f.Loop){const a=d.outputs.map(e=>Xd(e)).flat();if(d.body){const e=Rn(d.body,u);i.push(...e)}const o=d.errorCalls.map(e=>Er(e)),p=d.successCalls.map(e=>Er(e));i.push(...R(a),...p,...o)}if(d.type===f.FunctionDeclaration){if(d.collapsed&&u)return[];const a=d.inputs.map(p=>Xd(p)).flat(),o=d.calls.map(p=>Er(p));i.push(...R(a),...o)}return R(i)}function Nm(d,u=!1){const i=[];if(d.type===f.Project&&i.push(...(d==null?void 0:d.variableDeclarations)||[],...(d==null?void 0:d.variableInstances)||[],...(d==null?void 0:d.searches)||[],...(d==null?void 0:d.loops)||[],...(d==null?void 0:d.operations)||[],...(d==null?void 0:d.conditions)||[],...(d==null?void 0:d.functionCalls)||[]),Mr.includes(d.type)&&i.push(...(d==null?void 0:d.detachedChildren)||[]),d.type===f.DefinitionEntity){const a=[...d.suggestedMethods,...d.methods].flatMap(o=>o.collapsed&&u?[]:Nm(o));i.push(...a)}if(d.type===f.Condition){const a=d.successCalls,o=d.errorCalls;i.push(...a,...o)}if(So.includes(d.type)){if(d.collapsed&&u)return[];const a=d.inputs.map(p=>Qd(p)).flat(),o=d.calls;i.push(...R(a),...o)}if(fr.includes(d.type)&&d.type!==f.Condition&&d.type!==f.Loop){const a=d==null?void 0:d.outputs.map(e=>Qd(e)).flat(),o=d.successCalls,p=d.errorCalls;i.push(...R(a),...o,...p)}if(mt.includes(d.type)){const a=Qd(d),o=bS(d);i.push(...a,...o)}if(d.type===f.Loop){const a=d.outputs.map(e=>Qd(e)).flat();if(d.body){const e=Nm(d.body,u);i.push(...e)}const o=d.errorCalls,p=d.successCalls;i.push(...R(a),...p,...o)}if(d.type===f.FunctionDeclaration){if(d.collapsed&&u)return[];const a=d.inputs.map(p=>Qd(p)).flat(),o=d.calls;i.push(...R(a),...o)}return R(i)}function Vm(d,u=!1){const i=Rn(d,u),a=[...i,...i.reduce((o,p)=>[...o,...Vm(p,u)],[])];return R(a)}function RS(d,u=!1){const i=Nm(d,u),a=[...i,...i.reduce((o,p)=>[...o,...RS(p,u)],[])];return R(a)}function _S(d){const u=bo(d),i=[...u,...u.reduce((a,o)=>[...a,..._S(o)],[])];return R(i)}function tf(d){return d.implements.reduce((u,i)=>i.type===f.DefinitionEntity?[...u,f.DefinitionEntity,...tf(i),...rf(i)]:[...u,i.name],[])}function rf(d){return d.extends.reduce((u,i)=>i.type===f.DefinitionEntity?[...u,f.DefinitionEntity,...rf(i),...tf(i)]:[...u,i.name],[])}function Kb(d){return d.extends.reduce((u,i)=>i.type===f.DefinitionEntity?[...u,i,...Kb(i),...kb(i)]:[...u,i],[])}function kb(d){return d.implements.reduce((u,i)=>i.type===f.DefinitionEntity?[...u,i,...kb(i),...Kb(i)]:[...u,i],[])}function eu(d){return[...rf(d),...tf(d)].filter((i,a,o)=>o.indexOf(i)===a)}function qb(d){return d.implements.length===0&&d.extends.length===0?null:d.implements.find(a=>a.type===f.BuiltInBaseEntity&&a.name===Ue.PERSISTED_ENTITY)?d:[...d.implements,...d.extends].reduce((a,o)=>{if(o.type===f.DefinitionEntity){const p=qb(o);if(p)return p}return a},null)}function aAe(d){const u=d.extends.find(i=>i.type===f.BuiltInBaseEntity);return u&&u.type===f.BuiltInBaseEntity?u:null}function oAe(d){const u=d.implements.find(i=>i.type===f.BuiltInBaseEntity);return u&&u.type===f.BuiltInBaseEntity?u:null}function Lm(d){const u=d.extends.find(i=>i.type===f.DefinitionEntity);return u&&u.type===f.DefinitionEntity?u:null}function Bi(d){if(d.type===f.BuiltInBaseEntity)return[d];const u=[...d.implements,...d.extends].reduce((i,a)=>a.type===f.BuiltInBaseEntity?[...i,a]:a.type===f.DefinitionEntity?[...i,...Bi(a)]:i,[]);return R(u)}function sf(d){return d.type===f.PrimitiveEntity?!0:d.type===f.BuiltInBaseEntity?d.interactive:!Bi(d).find(a=>!a.interactive)}function lAe(d){return d.parent===d.project&&d.project.variableDeclarations.includes(d)}function Zb(d){return d.parent!==d.project?!1:f.VariableDeclaration===d.type?d.project.variableDeclarations.includes(d):f.VariableInstance===d.type?d.project.variableInstances.includes(d):f.FunctionCall===d.type?d.project.functionCalls.includes(d):f.Condition===d.type?d.project.conditions.includes(d):f.Operation===d.type?d.project.operations.includes(d):f.Loop===d.type?d.project.loops.includes(d):f.Search===d.type?d.project.searches.includes(d):!1}function gS(d){if([...Pt,f.DefinitionEntity,f.InstalledProject,f.Project].includes(d.type)||Zb(d))return!1;const u=bo(d);return u.length===0?!0:u.some(i=>gS(i))}function Jb(d){return[...Pt,f.DefinitionEntity,f.InstalledProject,f.Project].includes(d.type)||Zb(d)?!1:bo(d).length===0}function DS(d,u=0){if(Jb(d)){const i=bo(d);return i.length===0?d:i.map(o=>DS(o,u+1)).reduce((o,p)=>o?p&&p.x<o.x?p:o:p,null)}return null}function OS(d){const u=[];if(Jb(d))u.push(d);else return[];return bo(d).forEach(a=>{u.push(...OS(a))}),u}function Hb(d){return d.type===f.FunctionDeclaration&&d.parent!==d.project&&!![f.DefinitionEntity,f.Loop,f.InstalledProject].includes(d.parent.type)}function dAe(d,u){const i=new Map;return d.forEach(a=>{i.set(a.id,a)}),u.forEach(a=>{i.set(a.id,a)}),Array.from(i.values())}function nf(d){switch(d){case f.DefinitionEntity:return ra;case f.FunctionDeclaration:return io;case f.VariableDeclaration:return uo;case f.VariableInstance:return lo;case f.FunctionCall:return Ao;case f.Operation:return so;case f.Condition:return oo;case f.ReturnStatement:return no;case f.Loop:return Ki;case f.Search:return co;case f.InputMap:return Yn;case f.OutputMap:return vn;case f.ArgumentDeclaration:return Jn;case f.ReturnDeclaration:return is;case f.Property:return ta;case f.InstalledProject:return po;case f.Project:return N;case f.DataType:return vs;case f.GlobalEvent:return ao;case f.InternalCall:return fo;case f.ValueDescriptor:return En;case f.BuiltInBaseEntity:return ia;case f.PrimitiveEntity:return ss;case f.ActionDescriptor:return wt;case f.LiteralValue:return qi;case f.ContinueStatement:return Vi;case f.BreakStatement:return ho;default:return null}}function Ji(d,u,i=null){const a=d!=null&&d.parent?J(d==null?void 0:d.parent):null;let o=a?u.get(a):null,p=i||d;if((d==null?void 0:d.id)===(u==null?void 0:u.id))return u;if(d.type===f.ReturnStatement)return Wr(d,u,p);if(d.type===f.FunctionDeclaration&&(o==null?void 0:o.type)===f.Loop)return o;if(Pt.includes(d.type))return d;if(d.type===f.Loop)return p.id===d.id?o:d;if(Wi.includes(d.type))return null;const e=d.parent;if(!e)return null;if(e.type===f.GenericReference){const y=J(e);if(!y)return null;const v=u.get(y);return v?Ji(v,u,p):null}else return e===u?u:Ji(e,u,p)}function Wr(d,u,i=null){const a=d!=null&&d.parent?J(d==null?void 0:d.parent):null;let o=a?u.get(a):null,p=i||d;if(d.type===f.FunctionDeclaration&&(o==null?void 0:o.type)===f.Loop)return Wr(o.parent,u,p);if(Pt.includes(d.type))return d;if(Wi.includes(d.type))return null;const e=d.parent;if(!e)return null;if(e.type===f.GenericReference){const y=J(e);if(!y)return null;const v=u.get(y);return v?Wr(v,u,p):null}else return e===u?u:Wr(e,u,p)}function af(d,u){if(Wi.includes(d.type)||u.getBuiltIn(d.id))return null;const i=Hi(d.parent,u);return i?i===u?Mr.includes(d.type)?d:null:i.type===f.DefinitionEntity?d:af(i,u):null}function Mm(d,u,i){if(d===u||u===i||d===i||!d||!u)return!1;const a=Ji(u.parent,i);return a===i?!1:a===d?!0:Mm(a,u,i)}var Bm=(d=>(d.SameBothLocal="same-both-local",d.AInB="a-in-b",d.BInA="b-in-a",d.ParallelInCommonParent="parallel-in-common-parent",d.ParallelInProject="parallel-in-project",d.AIsGlobalBIsNot="a-is-global-b-is-not",d.BIsGlobalAIsNot="b-is-global-a-is-not",d.SameBothGlobal="same-both-global",d))(Bm||{});function Qs(d,u,i){const a=Ji(d,i),o=Ji(u,i);if(!a)throw new Error("Could not find scope owner for the entity: "+d.id);if(!o)throw new Error("Could not find scope owner for the entity: "+u.id);if(a===o&&a.type!==f.Project)return{compatible:!0,type:"same-both-local",commonAncestorScope:a};if(a===o&&a.type===f.Project)return{compatible:!0,type:"same-both-global",commonAncestorScope:a};if(a.type===f.Project&&o.type!==f.Project)return{compatible:!1,type:"a-is-global-b-is-not",commonAncestorScope:a};if(a.type!==f.Project&&o.type===f.Project)return{compatible:!1,type:"b-is-global-a-is-not",commonAncestorScope:o};if(Mm(a,o,i))return{compatible:!0,type:"b-in-a",commonAncestorScope:a};if(Mm(o,a,i))return{compatible:!0,type:"a-in-b",commonAncestorScope:o};const y=Gb(a,o);return y===i?{compatible:!1,type:"parallel-in-project",commonAncestorScope:y}:y?{compatible:!1,type:"parallel-in-common-parent",commonAncestorScope:Ji(y,i)}:{compatible:!1,type:"parallel-in-project",commonAncestorScope:i}}function CS(d,u,i){const a=Qs(d,u,i);if(!a.compatible||a.type!=="same-both-local")return null;if(d===u)return d;let o=Ji(d.parent,i);if(o){if(o===u)return u;if(o.type===f.Project)return d}else return d;for(;o;){if(o){if(o===u)return u;if(o.type===f.Project)return d}else return d;o=Ji(o.parent,i)}let p=Ji(u.parent,i);if(p){if(p===d)return d;if(p.type===f.Project)return u}else return u;for(;p;){if(p){if(p===d)return d;if(p.type===f.Project)return u}else return u;p=Ji(p.parent,i)}return null}function $S(d){return d.length===0?null:d.length===1?d[0]:d.reduce((i,a)=>{const o=CS(i,a,a.project);return!o||o===a?i:a},d[0])}function Hi(d,u){if(!d)return null;let i;return typeof d=="string"?i=d:d.type===f.GenericReference?i=J(d):i=d.id,i===u.id?u:u.get(i)}function wo(d){if(!d)return null;if(Wi.includes(d.type))return d;if(d.type===f.Project)return null;if(d.project.getBuiltIn(d.id))return d;const u=d.parent;return!u||u.type===f.Project?null:wo(u)}function of(d){const u=[];function i(p,e){return u.some(y=>y.blockedByCaller===p&&y.blockedByCalling===e)}function a(p,e){i(p,e)||u.push({blockedByCaller:p,blockedByCalling:e})}const o=af(d,d.project);return d.calledBySuccess.forEach(p=>{[...p.successCalls||[]].forEach(v=>{Tr.includes(v.type)&&v!==d&&(Rt(d).find(A=>A===v)||a(p,v))});let y;if(fr.includes(p.type)&&(y=p),y){const v=of(y);v.reachable||Rt(d).find(A=>A===p)||v.blocks.forEach(A=>{a(p,A.blockedByCalling)})}}),d.calledByError.forEach(p=>{[...p.errorCalls||[]].forEach(v=>{Tr.includes(v.type)&&v!==d&&(Rt(d).find(A=>A===v)||a(p,v))});let y;if(fr.includes(p.type)&&(y=p),y){const v=of(y);v.reachable||Rt(d).find(A=>A===p)||v.blocks.forEach(A=>{a(p,A.blockedByCalling)})}}),d.calledByEntry.forEach(p=>{if([...p.calls||[]].forEach(v=>{Tr.includes(v.type)&&v!==d&&(Rt(d).find(A=>A===v)||a(p,v))}),p===o)return;let y;if(p.type===f.FunctionDeclaration){const v=Er(p);if(v.type===f.DefinitionEntity)return;v.type===f.Loop&&(y=v)}if(y){const v=of(y);v.reachable||v.blocks.forEach(E=>{a(p,E.blockedByCalling)})}}),{reachable:u.length===0,entryPoint:o,blocks:u}}function uAe(d){return ih.includes(d.type)?d.type===f.FunctionDeclaration?!Hb(d):!0:!1}function cAe(d){if(f.ActionDescriptor===d.type){if(d.project.operationDeclarations.find(p=>p.id===d.id))return f.Operation;if(d.project.globalEventActionDescriptors.find(p=>p.id===d.id))return f.GlobalEvent;if(d.project.loopDeclarations.find(p=>p.id===d.id))return f.Loop;if(d.project.conditionDeclarations.find(p=>p.id===d.id))return f.Condition}return d.type}function Um(d,u){return d.type===f.BuiltInBaseEntity?d.name===u:!!rf(d).includes(u)}function pAe(d,u){return d.type===f.BuiltInBaseEntity?d.name===u:!!tf(d).includes(u)}function As(d,u){return d.type===f.BuiltInBaseEntity?d.name===u:!!eu(d).includes(u)}function fAe(d){const u=[];return d.entities.forEach(i=>{if(Um(i,Ue.PERSISTED_ENTITY)){u.push(i);return}}),R(u)}function hAe(d){const u=[];return d.entities.forEach(i=>{if(Um(i,Ue.RELATIONAL_DATABASE)){u.push(i);return}}),R(u)}function yAe(d){return d.type!==f.DefinitionEntity||d.abstract||!Um(d,Ue.PERSISTED_ENTITY)?null:(d==null?void 0:d.properties.find(i=>{var a;return((a=i.implements)==null?void 0:a.id)===Ee[f.BuiltInBaseEntity][Ue.PERSISTED_ENTITY].properties.primaryKey.id&&!i.abstract}))||null}function PS(d){var a;const u=qb(d);if(!u)return null;const i=u.properties.find(o=>{var p;return((p=o.implements)==null?void 0:p.id)===Ee[f.BuiltInBaseEntity][Ue.PERSISTED_ENTITY].properties.database.id});return i?(a=i.getDefaultValue())==null?void 0:a.valueAsType:null}function tu(d){if(d.type!==f.DefinitionEntity)return[];if(d.abstract)return[];if(!As(d,Ue.PERSISTED_ENTITY))return[];const u=[],i=d.properties.filter(a=>{var o;return((o=a.implements)==null?void 0:o.id)!==Ee[f.BuiltInBaseEntity][Ue.PERSISTED_ENTITY].properties.database.id&&!a.abstract});return u.push(...i),u}function mAe(d){var i;if(!d||d.type!==f.DefinitionEntity||!As(d,Ue.PERSISTED_ENTITY))return null;const u=d.properties.find(a=>{var o;return((o=a.implements)==null?void 0:o.id)===Ee[f.BuiltInBaseEntity][Ue.PERSISTED_ENTITY].properties.database.id});return(i=u==null?void 0:u.getDefaultValue())==null?void 0:i.valueAsTypeSingle}function Gr(d,u){var a;if(!Cg.includes(u.type)||!d)return u.project||null;let i=u.project;return d.type===f.Project?i=d:((a=u.project)==null?void 0:a.id)!==d.project.id&&(i=d.project),i}function vAe(d){switch(d){case f.Project:return N;case f.InstalledProject:return po;case f.DefinitionEntity:return ra;case f.FunctionDeclaration:return io;case f.GlobalEvent:return ao;case f.VariableInstance:return lo;case f.VariableDeclaration:return uo;case f.InputMap:return Yn;case f.OutputMap:return vn;case f.Condition:return oo;case f.Operation:return so;case f.FunctionCall:return Ao;case f.ReturnDeclaration:return is;case f.ArgumentDeclaration:return Jn;case f.PrimitiveEntity:return ss;case f.DataType:return vs;case f.Property:return ta;case f.ActionDescriptor:return wt;case f.ReturnStatement:return no;case f.ContinueStatement:return Vi;case f.BreakStatement:return ho;case f.Loop:return Ki;case f.Search:return co;case f.ValueDescriptor:return En;case f.InternalCall:return fo;case f.LiteralValue:return qi}return null}function EAe(d){const u={added:{},updated:{},removed:{},affected:[],seenEntities:[],self:d==null?void 0:d.self};return d==null||d.added.forEach(i=>{u.added[i.id]=i}),d==null||d.updated.forEach(i=>{u.updated[i.id]=i}),d==null||d.removed.forEach(i=>{u.removed[i.id]=i}),u.affected=Array.from(new Set(d==null?void 0:d.affected.map(i=>i.id))),u}function Ur(d,u){const i=nf(d.type);return i?!i.MUTABLE_META_PROPERTIES.every(o=>{const p=d[o],e=u[o];return e===void 0||p===e?!0:Array.isArray(p)&&Array.isArray(e)?p.length!==e.length?!1:p.every((y,v)=>y===e[v]):!1}):!1}function jm(d,u={}){if(d.type===f.Project)return[];if(!d.parent)return[];const i=J(d.parent);if(!i)return[];const a=u[i];return a?[a.id,...jm(a,u)]:[]}function TAe(d){const u=[],i=new Set;return[...d.listAdded,...d.listUpdated,...d.listAffected].forEach(a=>{const o=Er(a);!o||i.has(o.id)||(i.add(o.id),u.push(o))}),R(u)}function IAe(d){if(d.type===f.Condition)return null;if(d.type===f.Search)return d.project.getBuiltIn(Ee["value-descriptor"][ed.SearchErrorOutputDescriptor].id)||null;if(d.type===f.Operation)return d.declaration.error;if(d.type===f.FunctionCall){const i=d.declaration.returnStatements.find(a=>!!a.throws);return(i==null?void 0:i.throws)||null}return null}function NS(d){const u=d.entities.filter(o=>!!o.implements.find(p=>p.id===Ee["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.id)),i=u.find(o=>{const p=o.properties.find(v=>v.implements&&v.implements.id===Ee["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.default.id),e=p==null?void 0:p.getDefaultValue();return(e==null?void 0:e.value)===!0});return i||u[0]||null}function Wb(d,u){const i=Array.from(new Set([...u.getAllBuiltInIds(),...Xs()]));return!!(i.includes(d.id)||!jm(d,{...u.instances,...u.builtInInstances}).every(p=>!i.includes(p)))}function VS(d){if(!d)return null;if(d.type===f.Project)return d.id;const u=d.parent;return u?VS(u):d.id}function lf(d){if(d.declaration&&d.declaration.type===f.Property){if(d.declaration.interactive){if(d.declaration.implements&&!d.declaration.implements.interactive)return!1;if(d.declaration.extends&&!d.declaration.extends.interactive)return!1}else return!1;if(d.declaration.private){const u=Er(d),i=af(u,d.project);if((i==null?void 0:i.type)===f.FunctionDeclaration&&(i==null?void 0:i.parent.type)===f.DefinitionEntity&&(i==null?void 0:i.parent.id)!==d.declaration.parent.id)return!1}}return!0}function Yb(d){if(d.interactive){if(d.implements&&!d.implements.interactive)return!1;if(d.extends&&!d.extends.interactive)return!1}else return!1;if(d.private){const u=Er(d),i=af(u,d.project);if((i==null?void 0:i.type)===f.FunctionDeclaration&&(i==null?void 0:i.parent.type)===f.DefinitionEntity&&(i==null?void 0:i.parent.id)!==d.parent.id)return!1}return!0}function AAe(d,u,i){const a=u,o=i,p=!!i,e=[];return a.forEach(y=>{var v;if(p){const E=Qs(o,y,d);if(!E.compatible&&E.type!=="b-is-global-a-is-not")return;e.push(y)}else{if(((v=y.parent)==null?void 0:v.type)!==f.Project)return;e.push(y)}}),R(e)}function xm(d){return d.replace(/["'`]/g,"")}function jr(d){const i=xm(d).split(/[\s-]+/).filter(e=>e.length>0);if(i.length===0)return"";const a=i[0],o=a[0].toLowerCase()+a.slice(1),p=i.slice(1).map(e=>e[0].toUpperCase()+e.slice(1));return[o,...p].join("")}function ru(d){return xm(d).split(/[\s-]+/).filter(a=>a.length>0).map(a=>a[0].toUpperCase()+a.slice(1)).join("")}function LS(d){const u=xm(d).trim();if(!u)return"";const i=u.replace(/[\s_-]+/g," ").split(" ").filter(Boolean),a=[];for(const o of i){let p=o;p=p.replace(/([A-Z]+)([A-Z][a-z]+)/g,"$1-$2"),p=p.replace(/([a-z0-9])([A-Z][a-z0-9]*)/g,"$1-$2"),p=p.replace(/([0-9])([a-zA-Z]+)/g,"$1-$2"),p=p.replace(/([a-zA-Z])([0-9])/g,"$1-$2");for(const e of p.split("-"))e&&a.push(e)}return a.join("-")}function bAe(d){const u=xm(d).trim();if(!u)return"";const i=u.replace(/[\s_-]+/g," ").split(" ").filter(Boolean),a=[];for(const o of i){let p=o;p=p.replace(/([A-Z]+)([A-Z][a-z]+)/g,"$1_$2"),p=p.replace(/([a-z0-9])([A-Z][a-z0-9]*)/g,"$1_$2"),p=p.replace(/([0-9])([a-zA-Z]+)/g,"$1_$2"),p=p.replace(/([a-zA-Z])([0-9])/g,"$1_$2");for(const e of p.split("_"))e&&a.push(e)}return a.join("_")}function Fm(d){return LS(d).toLowerCase()}function iu(d){var i,a,o,p;if(!d)return"Any data type";let u="";if(d.interactiveEntities===!1?u+=` but only definition nodes ${d.asType?"as template ":""}that don't include non-interactive built-in functionality`:d.interactiveEntities===!0&&(u+=` but only definition nodes ${d.asType?"as template ":""}that extend or implement interactive built-in functionality`),d.staticEntities===!1?u?u+=" and that aren't a single global copy instance":u+=` but only definition nodes ${d.asType?"as template ":""}that aren't a single global copy instance`:d.staticEntities===!0&&(u?u+=" and that are a single global copy instance":u+=` but only definition nodes ${d.asType?"as template ":""}that are a single global copy instance`),d.actionEntities===!1?u?u+=" excluding executable/action nodes":u+=` excluding executable/action nodes ${d.asType?"templates ":""}`:d.actionEntities===!0&&(u?u+=" and not executable/action nodes":u+=" but not executable/action nodes"),d.entity&&(u=""),d.asType&&!u&&!((i=d.andChildrenGroup)!=null&&i.length)&&!((a=d.orChildrenGroup)!=null&&a.length)&&(u=" as template"),!d.entity){const e=d.isList;if(!((o=d.andChildrenGroup)!=null&&o.length)&&!((p=d.orChildrenGroup)!=null&&p.length))return e?`List of an any data type${u}`:`Any data type${u}`;let y="",v=!1,E=!1;return(d.andChildrenGroup||[]).forEach(b=>{const A=iu(b),$=Dd(A);v&&(y+=" and "),b.isGroup?y+="("+$+")":v?y+=$:y+=A,v=!0,E=!0}),(d.orChildrenGroup||[]).forEach(b=>{const A=iu(b),$=Dd(A);v&&(E&&(y+=","),y+=" or "),b.isGroup?y+="("+$+")":v?y+=$:y+=A,v=!0}),e?`List of ${Dd(y)}`:y}if(d.entity.type===f.PrimitiveEntity){let e=d.entity.name;switch(d.entity.name){case Q.String:e="Text";break;case Q.KeyValue:e="Data structure";break}return d.isList?`List of ${e}s${u}`:`${e.slice(0,1).toUpperCase()}${e.slice(1)}${u}`}else if(d.entity.type===f.DefinitionEntity){const e=ne(d.entity,d.project);return d.isList?`List of ${e} values${u}`:e.slice(0,1).toUpperCase()+e.slice(1)+u}else if(d.entity.type===f.BuiltInBaseEntity){const e=BS(d.entity);return d.isList?`List of ${e} values${u}`:e.slice(0,1).toUpperCase()+e.slice(1)+u}else if(d.entity.type===f.LiteralValue){if(d.entity.name===Q.Null)return"Empty value";if(d.entity.name===Q.Untyped)return"Untyped value";if(d.entity.name===Q.File)return"File";if(d.entity.name===Q.String)return`"${d.entity.value}" text`;if(d.entity.name===Q.Number)return`Number '${d.entity.value}'`;if(d.entity.name===Q.Boolean)return`${d.entity.value} value`;if(d.entity.name===Q.UUID)return`"${d.entity.value}" unique identifier`;if(d.entity.name===Q.Date)return`"${d.entity.value}" date`}return d.isList?`List of ${ne(d.entity,d.project)} values${u}`:`${ne(d.entity,d.project).slice(0,1).toUpperCase()+ne(d.entity,d.project).slice(1)} value${u}`}function wAe(d){if(!d)return"Any data type";const u=d.getDataType(null);return iu(u)}function Gm(d){switch(d.declaration.id){case _r.Equal:return"is equal to";case _r.NotEqual:return"is not equal to";case _r.MoreThan:return"is greater than";case _r.MoreThanOrEqual:return"is greater than or equal to";case _r.LessThan:return"is less than";case _r.LessThanOrEqual:return"is less than or equal to";case _r.And:return"and";case _r.Or:return"or";case zr.Empty:return"is empty";case zr.NotEmpty:return"is present"}}function MS(d){return d.includes(Ue.HTTP_ENDPOINT)?"HTTP endpoint":d.includes(Ue.PERSISTED_ENTITY)?"Persisted entity":d.includes(Ue.CRON_JOB)?"Scheduled execution":d.includes(Ue.RELATIONAL_DATABASE)?"Relational database":"Entity"}function BS(d){switch(d.name){case Ue.HTTP_ENDPOINT:return"HTTP endpoint";case Ue.PERSISTED_ENTITY:return"Persisted entity";case Ue.CRON_JOB:return"Scheduled execution";case Ue.RELATIONAL_DATABASE:return"Relational database"}return"Entity"}function RAe(d){const u=Lm(d);if(!u){const i=eu(d);return i.includes(Ue.HTTP_ENDPOINT)?"HTTP endpoint":i.includes(Ue.PERSISTED_ENTITY)?"Persisted entity":i.includes(Ue.CRON_JOB)?"Scheduled execution":i.includes(Ue.RELATIONAL_DATABASE)?"Relational database":ne(d,d.project)+" entity"}return ne(u,d.project)+" entity"}function US(d){let u="Find ";return d.outputsDeclarations.forEach((i,a)=>{const o=Sy(i,null),p=Dd(o&&o.entity?ne(o.entity,d.project):"unstructured data");a===0?u+=`${p} `:a===d.outputsDeclarations.length-1?u+=`and ${p} `:u+=`, ${p} `}),u}function jS(d){switch(d.name){case Q.String:return"Text";case Q.Number:return"Number";case Q.Boolean:return"Boolean";case Q.KeyValue:return"Data structure";case Q.UUID:return"Unique identifier";case Q.Date:return"Date";case Q.EntityTemplate:return"Entity as template";case Q.Enum:return"Enumeration";case Q.File:return"File";case Q.Null:return"Empty";case Q.ActionDescriptor:return"Action descriptor";case Q.Untyped:return"Untyped";default:return d.name}}function xS(d){switch(d.id){case ze.List:return"Loop over list items";case ze.ManualFlow:return"Manual flow control loop";case ze.ObjectKeys:return"Loop over object keys";case ze.ObjectValues:return"Loop over object values";case ze.Counted:return"Loop given number of times";case ze.String:return"Loop over text characters";case Jt.Addition:return"Sum numbers";case Jt.Subtraction:return"Subtract numbers";case Jt.Multiplication:return"Multiply numbers";case Jt.Division:return"Divide numbers";case Jt.Remainder:return"Get remainder of numbers";case Jt.Exponentiation:return"Get exponent of numbers";case Se.AddIndex:return"Add at index position";case Se.DeleteFirst:return"Delete first character";case Se.DeleteLast:return"Delete last character";case Se.DeleteIndex:return"Delete at index position";case Se.Join:return"Join texts";case Se.ReplaceAllMatches:return"Replace all matches";case Se.ReplaceFirst:return"Replace first match";case Se.ReplaceLast:return"Replace last match";case Se.Split:return"Split text";case Se.ReplaceIndex:return"Replace at index position";case Se.ReplaceSingleMatch:return"Replace single match";case Se.GetFirst:return"Get first character";case Se.GetLast:return"Get last character";case Se.GetIndexItem:return"Get at index position";case Se.GetIndexOf:return"Get the index number of the character";case Se.Append:return"Add at the end";case Se.Prepend:return"Add at the start";case rr.Wait:return"Wait";case rr.Parallel:return"Run in parallel";case rr.Sequential:return"Run in sequence";case vi.HttpRequest:return"HTTP request";case pr.CreateNewInstance:return"Create new copy of entity";case Je.AddIndex:return"Add item at index position";case Je.DeleteFirst:return"Delete first item";case Je.DeleteLast:return"Delete last item";case Je.DeleteIndex:return"Delete item at index position";case Je.Join:return"Join lists";case Je.ReplaceFirst:return"Replace first match";case Je.ReplaceLast:return"Replace last match";case Je.Split:return"Split list";case Je.ReplaceIndex:return"Replace at index position";case Je.GetFirst:return"Get first item";case Je.GetLast:return"Get last item";case Je.GetIndexItem:return"Get item at index position";case Je.Append:return"Add item at the end";case Je.Prepend:return"Add item at the start";case Ia.PROJECT_PUBLICATION_COMPLETED:return"Project publication completed";default:return(d.name.slice(0,1).toUpperCase()+d.name.slice(1)).replaceAll("-"," ")}}function ne(d,u){var i;if(f.FunctionDeclaration===d.type){const a=d.name;if(Object.values(Xr).includes(a))switch(a){case Xr.AbortExecution:return"Abort ongoing execution";case Xr.DeletePersistedEntity:return"Delete entry from database";case Xr.CreatePersistedEntity:return"Save entity data to database";case Xr.UpdatePersistedEntity:return"Update entity data to database";default:return bi(d.type).replaceAll("-"," ")}return a}if(f.BuiltInBaseEntity===d.type)return MS([d.name]);if(Dg.includes(d.type)&&d.type!==f.ActionDescriptor)return d.name;switch(d.type){case f.Search:return US(d);case f.GlobalEvent:return d.implements?ne(d.implements,u):bi(d.type).replaceAll("-"," ");case f.Operation:case f.InternalCall:case f.Loop:const a=Hi(d.declaration,u);return a||Me.log("Loop without declaration: ",d),ne(a,u);case f.ActionDescriptor:return xS(d);case f.BreakStatement:const o=Hi(d.parent,u);return o||Me.log("Break without parent: ",d),`Stop loop ${ne(o,u)}`;case f.ContinueStatement:const p=Hi(d.parent,u);return p||Me.log("continue without parent: ",d),`Execute next iteration of ${ne(p,u)}`;case f.FunctionCall:return Hi(d.declaration,u).name;case f.Condition:{const y=d;if((i=d.inputs)!=null&&i.length){y.inputs[0]||Me.log("condition without input: ",d);const v=ne(y.inputs[0],y.project);if(y.inputs[1]){const E=y.inputs[1].declaration.name;return`If ${v} ${Gm(y)} ${E}`}return`If ${v} ${Gm(y)}`}else return`If ${Gm(y)}`}case f.ReturnStatement:{const y=Hi(d.parent,u);return y?`Output of ${ne(y,u)}`:"Return statement"}case f.InputMap:if(d.declaration){const y=Hi(d.declaration,u);return y||(Me.log("Input without declaration: ",d),Me.log("Og declaration: ",d.declaration)),ne(y,u)||""}else return d.name||"";case f.VariableInstance:{const y=Hi(d.declaration,u);return y||Me.log("Var without declaration: ",d),ne(y,u)||""}case f.OutputMap:if(d.declaration){const y=Hi(d.declaration,u);return(y==null?void 0:y.name)||""}else return"";case f.PrimitiveEntity:case f.LiteralValue:return jS(d);default:return bi(d.type).replaceAll("-"," ")}}function zb(d,u){const i=[];d.name||i.push(new ee({id:`${d.id}--${ae.EmptyName}`,message:`Entity with id "${d.id}" and type "${d.type}" has an empty name. Please provide a 'name' string.`,severity:q.Error,code:ae.EmptyName}));const a=u.entities.filter(o=>o.name===d.name);return a.length&&i.push(new ee({id:`${d.id}--${ae.NameNotUniqueInScope}`,message:`Entity with id "${d.id}" and type "${d.type}" has a name "${d.name}" that is not unique in the project. Entity with id "${a[0].id}" has the same name.
|
|
396
|
+
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.`})),{errors:a,modifiedData:i}}subscribeDependents(i){return i.forEach(a=>{this.detachedDependents[a.entity.id]||(this.detachedDependents[a.entity.id]=a)}),this}unsubscribeDependents(i){return i.forEach(a=>{this.detachedDependents[a.entity.id]&&delete this.detachedDependents[a.entity.id]}),this}syncDependents(i=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"sync-dependents"))){const a=[],o=[],p=[],e=[];return Object.values(this.detachedDependents).forEach(y=>{const v=y.entity.afterAllChildrenInitialized(i);a.push(...v.updated),o.push(...v.added),p.push(...v.removed),e.push(...v.affected)}),i==null||i.attemptAutoclose("sync-dependents",this.id),{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}onDetachedDependencyRemoved(i,a,o){const p=[],e=[],y=[],v=[];if(a==="declaration"){const{updated:E,added:b,removed:A}=this.remove({ignoreUpstream:!1},o);p.push(...E),e.push(...b),y.push(...A)}if(a==="parent"){const{updated:E,added:b,removed:A}=this.remove({ignoreUpstream:!1},o);p.push(...E),e.push(...b),y.push(...A)}return{updated:R(p),added:R(e),removed:R(y),affected:R(v),self:this}}onDetachedDependencyRestored(i,a,o){const p=[],e=[],y=[],v=[];if(a==="declaration"){const{updated:E,added:b,removed:A}=this.restore({},o);p.push(...E),e.push(...b),y.push(...A)}if(a==="parent"){const{updated:E,added:b,removed:A}=this.restore({},o);p.push(...E),e.push(...b),y.push(...A)}return{updated:R(p),added:R(e),removed:R(y),affected:R(v),self:this}}unsubscribeFromDependencies(){var i;return(i=this.parent)==null||i.unsubscribeDependents([{entity:this,field:"parent"}]),this.declaration.unsubscribeDependents([{entity:this,field:"declaration"}]),this}subscribeToDependencies(){var i;return(i=this.parent)==null||i.subscribeDependents([{entity:this,field:"parent"}]),this.declaration.subscribeDependents([{entity:this,field:"declaration"}]),this}increaseVersion(i){if(i&&!L(i).isValid())throw new Error(`The shared timestamp '${i}' is not a valid ISO 8601 date string.`);return i&&L(i).isSame(L(this.createdAt))?this:(this.previousVersion=this.version,this.version=N.UUID.uuid(),this.createdAt=L(i).toISOString()||L().toISOString(),this)}captureVersion(){var a;const i=((a=this.knownVersions)==null?void 0:a.get(this.version))||new er(this,this.project);return i.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,i):new Map([[this.version,i]]),i.inputs=[...this.inputs],i.outputs=[...this.outputs],i.error=this.error,i.successCalls=[...this.successCalls],i.errorCalls=[...this.errorCalls],i.process=this.process,i.declaration=this.declaration,i.calledBySuccess=[...this.calledBySuccess],i.calledByError=[...this.calledByError],i.calledByEntry=[...this.calledByEntry],i.parent=this.parent,this}recursiveCaptureUpstreamVersions(i){const a=[],o=[],p=[],e=[];if(this.parent){this.parent.increaseVersion(i);const y=this.parent.recursiveCaptureUpstreamVersions(i);a.push(this.parent,...y.updated),o.push(...y.added),p.push(...y.removed)}return{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}async restoreVersion(i){var v;const a=[],o=[],p=[],e=[];if(this.version===i)return{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this};if(!this.knownVersions){const E=new Map;for(const[b,A]of this.knownVersions||new Map){if(E.set(b,A),A.activeVersion=!1,A.knownVersions)for(const[$,V]of A.knownVersions)E.set($,V);A.knownVersions=null}}let y=(v=this.knownVersions)==null?void 0:v.get(i);if(!y){const E=await this.APILoadVersion({},i);if(!E)throw new Error(`Version with id '${i}' for entity with id '${this.id}' not found.`);y=new er(E,this.project)}return this.metaSync(y.toShallowJSON(),null),this.previousVersion=y.previousVersion,this.version=y.version,this.createdAt=y.createdAt,this.author=y.author,this.deleted=y.deleted,this.inputs=y.inputs,this.outputs=y.outputs,this.error=y.error,this.successCalls=y.successCalls,this.errorCalls=y.errorCalls,this.process=y.process,this.declaration=y.declaration,this.calledBySuccess=y.calledBySuccess,this.calledByError=y.calledByError,this.calledByEntry=y.calledByEntry,this.parent=y.parent,{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}updateWithShallowTransfer(i,a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"update-with-shallow-transfer"))){if(this.metaSync(i,a),this.version=i.version,this.createdAt=i.createdAt,this.author=i.author,this.deleted=i.deleted,this.previousVersion=i.previousVersion,this.unsubscribeFromDependencies(),i.parent){const o=J(i.parent),p=this.project.get(o),e=this.parent;if(e&&e.id!==(p==null?void 0:p.id)&&this.removeFromParent(a),p)this.setParent(p,a);else throw a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${o}' that isn't found in the project`)}else throw a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(i.declaration){const o=J(i.declaration),p=this.project.get(o);p&&this.setDeclaration(p)}return i.calledByEntry.forEach(o=>{const p=J(o),e=this.project.get(p);e&&(this.addEntryCaller(e,a),e.addCall(this,a))}),[...this.calledByEntry].forEach(o=>{i.calledByEntry.find(e=>J(e)===o.id)||(this.removeCaller(o,a),o.removeCall(this,a))}),i.calledBySuccess.forEach(o=>{const p=J(o),e=this.project.get(p);e&&(this.addSuccessCaller(e,a),e.addSuccessCall(this,a))}),[...this.calledBySuccess].forEach(o=>{i.calledBySuccess.find(e=>J(e)===o.id)||(this.removeCaller(o,a),o.removeCall(this,a))}),i.calledByError.forEach(o=>{const p=J(o),e=this.project.get(p);e&&(this.addErrorCaller(e,a),e.addErrorCall(this,a))}),[...this.calledBySuccess].forEach(o=>{i.calledBySuccess.find(e=>J(e)===o.id)||(this.removeCaller(o,a),o.removeCall(this,a))}),this.captureVersion(),this.subscribeToDependencies(),a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),this}hydrateAncestors(){const i=[],a=[],o=[],p=[];if(this.initialData.parent){const e=J(this.initialData.parent),y=this.project.get(e);if(y)this.setParent(y,null),i.push(y);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${e}' that isn't found in the project`)}else throw new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(this.initialData.declaration){const e=J(this.initialData.declaration),y=this.project.get(e);y&&(this.setDeclaration(y),i.push(y))}return this.initialData.calledByEntry.forEach(e=>{const y=J(e),v=this.project.get(y);v&&this.addEntryCaller(v,null)}),this.initialData.calledBySuccess.forEach(e=>{const y=J(e),v=this.project.get(y);v&&this.addSuccessCaller(v,null)}),this.initialData.calledByError.forEach(e=>{const y=J(e),v=this.project.get(y);v&&this.addErrorCaller(v,null)}),{updated:R(i),added:R(a),removed:R(o),affected:R(p),self:this}}afterAllChildrenInitialized(i=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"after-all-children-initialized"))){const a=[],o=[],p=[],e=[];this.initialized=!0;const{updated:y,added:v,removed:E}=this.syncInputs(i),{updated:b,added:A,removed:$}=this.syncOutputs(i);return a.push(...y,...b),o.push(...v,...A),p.push(...E,...$),this.captureVersion(),i==null||i.attemptAutoclose("after-all-children-initialized",this.id),{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}addSelfToProject(i=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-self-to-project"))){var y;const a=[this],o=[],p=[],e=[];return this.parent===this.project&&this.project.addFunctionCall(this),(y=this.process)==null||y.writesValues.forEach(v=>{v.setValueWriter(this.process,i),a.push(v)}),this.successCalls.forEach(v=>{v.addSuccessCaller(this,i),a.push(v)}),this.errorCalls.forEach(v=>{v.addErrorCaller(this,i),a.push(v)}),this.calledBySuccess.forEach(v=>{v.addSuccessCall(this,i),a.push(v)}),this.calledByError.forEach(v=>{v.addErrorCall(this,i),a.push(v)}),this.calledByEntry.forEach(v=>{v.addCall(this,i),a.push(v)}),this.subscribe(),this.subscribeToDependencies(),i==null||i.attemptAutoclose("add-self-to-project",this.id),{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}removeInput(i,a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-input"))){const o=this.inputs.findIndex(p=>p.id===i.id);return o>-1&&(this.inputs.splice(o,1),a&&(a==null||a.add(this,S.Affected))),a==null||a.attemptAutoclose("remove-input",this.id),this}addInput(i,a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-input"))){return this.inputs.includes(i)?(a==null||a.attemptAutoclose("add-input",this.id),this):(this.inputs.push(i),a==null||a.add(this,S.Affected),a==null||a.attemptAutoclose("add-input",this.id),this)}addOutput(i,a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-output"))){return this.outputs.includes(i)?(a==null||a.attemptAutoclose("add-output",this.id),this):(this.outputs.push(i),a==null||a.add(this,S.Affected),a==null||a.attemptAutoclose("add-output",this.id),this)}removeOutput(i,a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-output"))){const o=this.outputs.findIndex(p=>p.id===i.id);return o>-1&&(this.outputs.splice(o,1),a&&(a==null||a.add(this,S.Affected))),a==null||a.attemptAutoclose("remove-output",this.id),this}addValueReader(i,a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-value-reader"))){var o;return this.process&&!this.process.writesValues.includes(i)&&((o=this.process)==null||o.addValueReader(i,a),a==null||a.add(this,S.Affected)),a==null||a.attemptAutoclose("add-value-reader",this.id),this}removeValueReader(i,a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-value-reader"))){var o;return this.process&&this.process.writesValues.includes(i)&&((o=this.process)==null||o.removeValueReader(i,a),a==null||a.add(this,S.Affected)),a==null||a.attemptAutoclose("remove-value-reader",this.id),this}addSuccessCaller(i,a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-success-caller")),o=!1){return this.calledBySuccess.find(p=>p.id===i.id)||(this.calledBySuccess.push(i),a==null||a.add(this,S.Updated),o&&We(this,a)),a==null||a.attemptAutoclose("add-success-caller",this.id),this}addErrorCaller(i,a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-error-caller")),o=!1){return this.calledByError.find(p=>p.id===i.id)||(this.calledByError.push(i),a==null||a.add(this,S.Updated),o&&We(this,a)),a==null||a.attemptAutoclose("add-error-caller",this.id),this}addEntryCaller(i,a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-entry-caller")),o=!1){return this.calledByEntry.find(p=>p.id===i.id)||(this.calledByEntry.push(i),a==null||a.add(this,S.Updated),o&&We(this,a)),a==null||a.attemptAutoclose("add-entry-caller",this.id),this}addErrorCall(i,a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-error-call")),o=!1){return this.errorCalls.find(p=>p.id===i.id)||(this.errorCalls.push(i),o&&We(this,a),a==null||a.add(this,S.Affected)),a==null||a.attemptAutoclose("add-error-call",this.id),this}addSuccessCall(i,a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-success-call")),o=!1){return this.successCalls.find(p=>p.id===i.id)||(this.successCalls.push(i),o&&We(this,a),a==null||a.add(this,S.Affected)),a==null||a.attemptAutoclose("add-success-call",this.id),this}removeCall(i,a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-call")),o=!1){const p=this.successCalls.findIndex(y=>y.id===i.id);p>-1&&(this.successCalls.splice(p,1),a==null||a.add(this,S.Affected));const e=this.errorCalls.findIndex(y=>y.id===i.id);return e>-1&&(this.errorCalls.splice(e,1),a==null||a.add(this,S.Affected)),o&&We(this,a),a==null||a.attemptAutoclose("remove-call",this.id),this}removeCaller(i,a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-caller")),o=!1){return this.calledBySuccess=this.calledBySuccess.filter(p=>p.id!==i.id?!0:(a==null||a.add(this,S.Updated),a==null||a.add(p,S.Affected),!1)),this.calledByError=this.calledByError.filter(p=>p.id!==i.id?!0:(a==null||a.add(this,S.Updated),a==null||a.add(p,S.Affected),!1)),this.calledByEntry=this.calledByEntry.filter(p=>p.id!==i.id?!0:(a==null||a.add(this,S.Updated),a==null||a.add(p,S.Affected),!1)),o&&We(this,a),a==null||a.attemptAutoclose("remove-caller",this.id),this}setParent(i,a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"set-parent"))){var o;return((o=this.parent)==null?void 0:o.id)!==(i==null?void 0:i.id)&&(this.parent=i,a&&(a==null||a.add(this,S.Updated))),a==null||a.attemptAutoclose("set-parent",this.id),this}setDeclaration(i){return this.declaration=i,this}initChildren(i=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"init-children"))){if(this.initialized||this.startedInitialization)return this;if(this.startedInitialization=!0,this.initialData.declaration.type===f.FunctionDeclaration){const a=te(this.initialData.declaration,this.project);this.declaration=a}else{const a=J(this.initialData.declaration),o=this.project.get(a);this.declaration=o}return this.successCalls=this.initialData.successCalls.map(a=>{const o=te(a,this.project);if(o.addSuccessCaller(this),[f.BreakStatement,f.ContinueStatement].includes(o.type))o.setParent(this.parent.parent,null),o.initChildren(i);else if(o.type===f.ReturnStatement){const p=Wr(this,this.project);o.setParent(p,null),o.initChildren(i)}else o.type!==f.InternalCall&&(o.setParent(this.parent,null),o.initChildren(i));return o}),this.errorCalls=this.initialData.errorCalls.map(a=>{const o=te(a,this.project);if(o.addErrorCaller(this),[f.BreakStatement,f.ContinueStatement].includes(o.type))o.setParent(this.parent.parent,null),o.initChildren(i);else if(o.type===f.ReturnStatement){const p=Wr(this,this.project);o.setParent(p,null),o.initChildren(i)}else o.type!==f.InternalCall&&(o.setParent(this.parent,null),o.initChildren(i));return o}),this.inputs=this.initialData.inputs.map(a=>{const o=te(a,this.project);return o.setParent(this,null),o.initChildren(i),o}),this.initialData.process&&(this.process=te(this.initialData.process,this.project),this.process.setParent(this,null),this.process.initChildren(i)),this.initialData.error&&(this.error=te(this.initialData.error,this.project),this.error.setParent(this,null),this.error.initChildren(i)),this.subscribeToDependencies(),this.afterAllChildrenInitialized(i),i==null||i.attemptAutoclose("init-children",this.id),this}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(i,a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"meta-sync"))){const o=Ur(this,i),p=this.toMeta();return this.x=i.x||p.x,this.y=i.y||p.y,super.metaSync(i),i.deleted===!0&&!p.deleted?a==null||a.add(this,S.Removed):i.deleted===!1&&p.deleted?a==null||a.add(this,S.Added):o&&(a==null||a.add(this,S.Updated)),a==null||a.attemptAutoclose("meta-sync",this.id),this}async APILoad(i=ve,...a){return await er.repository.APILoad(this.id,...a),this}async APICreate(i=ve,...a){return await er.repository.APICreate(this.toShallowJSON(),...a),this}async APIUpdate(i=ve,...a){return await er.repository.APIUpdate(this.toShallowJSON(),...a),this}async APIDelete(i=ve,...a){return await er.repository.APIDelete(this.toShallowJSON(),...a),this}async APIClone(i=ve,...a){return await er.repository.APIClone(this.id,...a),this}async APILoadVersion(i=ve,a,...o){return await er.repository.APILoadVersion(this.id,a,...o)}removeFromParent(i=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-from-parent"))){const a=[],o=[],p=[],e=[];return this.parent.type===f.Project?(this.parent.removeFunctionCall(this),e.push(this.parent)):this.parent.detachedChildren.includes(this)&&this.parent.unsubscribeDetachedChild(this),i==null||i.attemptAutoclose("remove-from-parent",this.id),{added:R(p),updated:R(a),removed:R(o),affected:R(e),self:this}}remove({ignoreUpstream:i}={ignoreUpstream:!1},a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-entity"))){var v;const o=[],p=[],e=[],y=[];if(a!=null&&a.hasRemoved(this.id))return a==null||a.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(p.push(this),this.unsubscribe(),this.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},a),Object.values(this.detachedDependents).forEach(E=>{const{updated:b,removed:A,added:$}=E.entity.onDetachedDependencyRemoved(this,E.field,a);o.push(...b),p.push(...A),e.push(...$)}),this.process){const{updated:E,removed:b}=(v=this.process)==null?void 0:v.remove({ignoreUpstream:!0},a);o.push(...E),p.push(...b)}if(this.inputs.forEach(E=>{const{updated:b,removed:A}=E.remove({ignoreUpstream:!0},a);o.push(...b),p.push(...A)}),this.outputs.forEach(E=>{const{updated:b,removed:A}=E.remove({ignoreUpstream:!0},a);o.push(...b),p.push(...A)}),this.error){const{updated:E,removed:b}=this.error.remove({ignoreUpstream:!0},a);o.push(...E),p.push(...b)}if(this.successCalls.forEach(E=>{o.push(E),E.removeCaller(this,a)}),this.errorCalls.forEach(E=>{o.push(E),E.removeCaller(this,a)}),!i){const E=this.removeFromParent(a);e.push(...E.added),o.push(...E.updated),p.push(...E.removed),y.push(...E.affected),this.calledBy.forEach(b=>{o.push(b),b.removeCall(this,a)})}return a==null||a.attemptAutoclose("remove-entity",this.id),{added:R(e),updated:R(o),removed:R(p),affected:R(y),self:this}}restore({}={},i=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"restore-entity"))){const a=[],o=[],p=[],e=[];if(i!=null&&i.hasAdded(this.id))return i==null||i.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},i),Object.values(this.detachedDependents).forEach(y=>{const{updated:v,removed:E,added:b}=y.entity.onDetachedDependencyRestored(this,y.field,i);o.push(...v),p.push(...E),a.push(...b)}),this.process){const{updated:y}=this.process.restore({},i);o.push(...y)}return this.inputs.forEach(y=>{const{updated:v}=y.restore({},i);o.push(...v)}),this.outputs.forEach(y=>{const{updated:v}=y.restore({},i);o.push(...v)}),this.successCalls.forEach(y=>{o.push(y),y.addSuccessCaller(this,i)}),this.errorCalls.forEach(y=>{o.push(y),y.addErrorCaller(this,i)}),this.calledBySuccess.forEach(y=>{o.push(y),y.addSuccessCall(this,i)}),this.calledByError.forEach(y=>{o.push(y),y.addErrorCall(this,i)}),this.calledByEntry.forEach(y=>{o.push(y),y.addCall(this,i)}),i==null||i.attemptAutoclose("restore-entity",this.id),{added:R(a),updated:R(o),removed:R(p),affected:R(e),self:this}}toFlat(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this,...this.successCalls.flatMap(o=>o.toFlat(i)),...this.errorCalls.flatMap(o=>o.toFlat(i)),...this.inputs.flatMap(o=>o.toFlat(i)),...this.outputs.flatMap(o=>o.toFlat(i)),...this.process?this.process.toFlat(i):[],...this.error?this.error.toFlat(i):[],...this.calledBy.flatMap(o=>o.toFlat(i))])}toFlatIds(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.id,...this.successCalls.flatMap(o=>o.toFlatIds(i)),...this.errorCalls.flatMap(o=>o.toFlatIds(i)),...this.inputs.flatMap(o=>o.toFlatIds(i)),...this.outputs.flatMap(o=>o.toFlatIds(i))])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,x:this.x,y:this.y,type:this.type}}toJSON(i=new Set){var a,o;return i.has(this.id)?this.toReference():(i.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,successCalls:this.successCalls.map(p=>p.toJSON(i)),errorCalls:this.errorCalls.map(p=>p.toJSON(i)),calledBySuccess:this.calledBySuccess.map(p=>p.toReference()),calledByError:this.calledByError.map(p=>p.toReference()),calledByEntry:this.calledByEntry.map(p=>p.toReference()),process:(a=this.process)==null?void 0:a.toJSON(i),declaration:this.declaration.toJSON(i),inputs:this.inputs.map(p=>p.toJSON(i)),outputs:this.outputs.map(p=>p.toJSON(i)),parent:this.parent.toReference(),error:(o=this.error)==null?void 0:o.toJSON(i)})}toJSONClone(i=ke){var o,p,e,y,v,E,b;let a;return(o=i.seenEntityMaps)!=null&&o.has(this.id)?a=i.seenEntityMaps.get(this.id):(a=i.newId||Sr(this,this.project,i.uuidStrategy),i.seenEntityMaps&&i.seenEntityMaps.set(this.id,a)),(p=i.seenEntities)!=null&&p.has(a)||(e=i.seenEntities)!=null&&e.has(this.id)?this.toReference({seenEntityMaps:i.seenEntityMaps}):((y=i.seenEntities)==null||y.add(a),(v=i.seenEntities)==null||v.add(this.id),{id:a,version:N.UUID.uuid(),createdAt:i.timestamp||L().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,successCalls:this.successCalls.map(A=>A.toJSONClone({...i,newId:null})),errorCalls:this.errorCalls.map(A=>A.toJSONClone({...i,newId:null})),calledBySuccess:this.calledBySuccess.map(A=>A.toReference({seenEntityMaps:i.seenEntityMaps})),calledByError:this.calledByError.map(A=>A.toReference({seenEntityMaps:i.seenEntityMaps})),calledByEntry:this.calledByEntry.map(A=>A.toReference({seenEntityMaps:i.seenEntityMaps})),process:(E=this.process)==null?void 0:E.toJSONClone({...i,newId:null}),declaration:this.declaration.toJSONClone({...i,newId:null}),inputs:this.inputs.map(A=>A.toJSONClone({...i,newId:null})),outputs:this.outputs.map(A=>A.toJSONClone({...i,newId:null})),error:(b=this.error)==null?void 0:b.toJSONClone({...i,newId:null}),parent:this.parent.toReference({seenEntityMaps:i.seenEntityMaps})})}toReference(i=ke){var o;let a=this.id;return(o=i.seenEntityMaps)!=null&&o.has(this.id)&&(a=i.seenEntityMaps.get(this.id)),{id:a+"--"+N.UUID.uuid()+"--ref",type:f.GenericReference,entityId:a,version:this.version,entityType:this.type}}toShallowJSON(i=ke){var o;let a=this.id;return(o=i.seenEntityMaps)!=null&&o.has(this.id)&&(a=i.seenEntityMaps.get(this.id)),{id:a,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,process:this.process?this.process.toReference(i):null,inputs:this.inputs.map(p=>p.toReference(i)),outputs:this.outputs.map(p=>p.toReference(i)),declaration:this.declaration.toReference(i),successCalls:this.successCalls.map(p=>p.toReference(i)),errorCalls:this.errorCalls.map(p=>p.toReference(i)),calledBySuccess:this.calledBySuccess.map(p=>p.toReference(i)),calledByError:this.calledByError.map(p=>p.toReference(i)),calledByEntry:this.calledByEntry.map(p=>p.toReference(i)),error:this.error?this.error.toReference(i):null,parent:this.parent.toReference(i)}}toFlatJSON(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.toShallowJSON(),...this.successCalls.flatMap(o=>o.toFlatJSON(i)),...this.errorCalls.flatMap(o=>o.toFlatJSON(i)),...this.inputs.flatMap(o=>o.toFlatJSON(i)),...this.outputs.flatMap(o=>o.toFlatJSON(i)),...this.process?this.process.toFlatJSON(i):[],...this.error?this.error.toFlatJSON(i):[]])}toGenerationTarget(){const i=this.parent.type===f.Project?void 0:this.parent.id;return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,calledByEntry:this.calledByEntry.map(a=>a.id),calledBySuccess:this.calledBySuccess.map(a=>a.id),calledByError:this.calledByError.map(a=>a.id),declaration:this.declaration.id,parent:i}}toFlatGenerationTarget(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.toGenerationTarget(),...this.successCalls.flatMap(o=>o.toFlatGenerationTarget(i)),...this.errorCalls.flatMap(o=>o.toFlatGenerationTarget(i)),...this.inputs.flatMap(o=>o.toFlatGenerationTarget(i)),...this.outputs.flatMap(o=>o.toFlatGenerationTarget(i)),...this.process?this.process.toFlatGenerationTarget(i):[],...this.error?this.error.toFlatGenerationTarget(i):[]])}clearErrors(){var i,a;return this.errors=[],this.inputs.forEach(o=>o.clearErrors()),this.outputs.forEach(o=>o.clearErrors()),this.successCalls.forEach(o=>o.clearErrors()),this.errorCalls.forEach(o=>o.clearErrors()),(i=this.process)==null||i.clearErrors(),(a=this.error)==null||a.clearErrors(),this}validate(){const i=A5(this);return this.errors=i,{success:!0}}getErrors(){return[...this.errors,...this.inputs.flatMap(a=>a.getErrors()),...this.outputs.flatMap(a=>a.getErrors()),...this.error?this.error.getErrors():[],...this.process?this.process.getErrors():[]]}getShallowErrors(){return this.errors}clone(i=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"clone-entity")),a=null,o=null,p=!0){var U,G;let e=Gr(a,this);const y=this.toJSON(),v=o||N.UUID.uuid();y.inputs=[];const E=v.split("-id"),b=E[E.length-1||0]||v;y.id=v,y.version=N.UUID.uuid(),y.createdAt=(i==null?void 0:i.timestamp)||L().toISOString(),y.author=(i==null?void 0:i.author)||"1",y.previousVersion=null,y.deleted=!1;const A=lr(y,e);a?A.setParent(a,null):A.setParent(this.parent,null),p&&A.subscribe(),A.initChildren(i),i==null||i.add(A,S.Added);const $=(U=this.inputs)==null?void 0:U.map((K,Z)=>K.clone(i,A,b+"-input-map-"+Z+"-id",p));A.inputs=$;const V=(G=this.outputs)==null?void 0:G.map((K,Z)=>K.clone(i,A,b+"-output-map-"+Z+"-id",p));return A.outputs=V,this.error&&(A.error=this.error.clone(i,A,b+"-error-map-id",p)),this.process&&(A.process=this.process.clone(i,A,b+"-process-id",p)),i==null||i.attemptAutoclose("clone-entity",this.id),A}removeUnrecognizedInputs(i=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-unrecognized-inputs"))){const a=[],o=[],p=[],e=[];return this.inputs.forEach(v=>{if(!this.declaration.inputs.find(b=>{var A;return b.id===((A=v.declaration)==null?void 0:A.id)})){const b=v.remove({ignoreUpstream:!1},i);p.push(...b.removed),a.push(...b.updated)}}),this.inputs.filter((v,E)=>{const b=this.inputs.findIndex($=>$.declaration===v.declaration&&$!==v);if(b===-1)return!1;const A=this.inputs[b];return L(A==null?void 0:A.createdAt).isSame(L(v.createdAt))?E>b:!!L(A==null?void 0:A.createdAt).isAfter(v.createdAt)}).forEach(v=>{const E=v.remove({ignoreUpstream:!1},i);p.push(...E.removed),a.push(...E.updated)}),i==null||i.attemptAutoclose("remove-unrecognized-inputs",this.id),{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}removeUnrecognizedOutputs(i=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-unrecognized-outputs"))){const a=[],o=[],p=[],e=[];return this.outputs.forEach(v=>{if(!this.declaration.getUniqueReturnDeclarations().find(b=>{var A;return b.id===((A=v.declaration)==null?void 0:A.id)})){const b=v.remove({ignoreUpstream:!1},i);p.push(...b.removed),a.push(...b.updated)}}),this.outputs.filter((v,E)=>{const b=this.outputs.findIndex($=>$.declaration===v.declaration&&$!==v);if(b===-1)return!1;const A=this.outputs[b];return L(A==null?void 0:A.createdAt).isSame(L(v.createdAt))?E>b:!!L(A==null?void 0:A.createdAt).isAfter(v.createdAt)}).forEach(v=>{const E=v.remove({ignoreUpstream:!1},i);p.push(...E.removed),a.push(...E.updated)}),i==null||i.attemptAutoclose("remove-unrecognized-outputs",this.id),{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}syncInputs(i=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"sync-missing-fixed-inputs"))){const a=[],o=[],p=[],e=[],y=this.declaration.inputs.filter(A=>!this.inputs.find($=>$.declaration.id===A.id));this.inputs.sort((A,$)=>A.index-$.index),y.forEach(A=>{this.inputs.forEach(U=>{U.index>=A.index&&U.metaSync({index:U.index+1},i)});const $={id:N.UUID.uuid(),version:N.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||L().toISOString(),author:N.sessionAuthor,previousVersion:null,deleted:!1,type:f.InputMap,declaration:A.toJSON(),readsValue:null,defaultValue:null,index:A.index,name:null,codeName:null,description:null,parent:this.toReference()},V=te($,this.project);V.setParent(this,i),V.initChildren(i),i==null||i.add(V,S.Added),V.addSelfToProject(i),o.push(V)}),this.inputs.sort((A,$)=>A.index-$.index);const{updated:v,added:E,removed:b}=this.removeUnrecognizedInputs(i);return a.push(...v),o.push(...E),p.push(...b),i==null||i.attemptAutoclose("sync-missing-fixed-inputs",this.id),{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}syncOutputs(i=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"sync-missing-fixed-outputs"))){const a=[],o=[],p=[],e=[],y=[];this.outputs=this.initialData.outputs.reduce(($,V)=>{if(V.type===f.GenericReference){const G=Hi(V,this.project);return G?[...$,G]:$}const U=te(V,this.project);return y.push(U.index),U.setParent(this,null),U.initChildren(i),[...$,U]},[]);const v=this.declaration.getUniqueReturnDeclarations().filter($=>!this.outputs.find(V=>V.declaration.id===$.id));this.outputs.sort(($,V)=>$.index-V.index),v.forEach(($,V)=>{this.outputs.forEach(Z=>{Z.index>=$.index&&Z.index++});const U=y.includes($.index)?this.outputs.length-1+V:$.index,G={id:N.UUID.uuid(),version:N.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||L().toISOString(),author:N.sessionAuthor,previousVersion:null,deleted:!1,type:f.OutputMap,declaration:$.toJSON(),defaultValue:null,writesValues:[],index:U,parent:this.toReference()},K=te(G,this.project);K.setParent(this,i),K.initChildren(i),i==null||i.add(K,S.Added),K.addSelfToProject(i)}),this.outputs.sort(($,V)=>$.index-V.index);const{updated:E,added:b,removed:A}=this.removeUnrecognizedOutputs(i);return a.push(...E),o.push(...b),p.push(...A),i==null||i.attemptAutoclose("sync-missing-fixed-outputs",this.id),{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}getUnusedInputs(){return this.inputs.filter(i=>i.suggestion||!i.readsValue&&!i.defaultValue)}getUnusedOutputs(){return this.outputs.filter(i=>i.suggestion||!i.writesValues.length)}getUsedInputs(){return this.inputs.filter(i=>!i.suggestion&&(i.readsValue||i.defaultValue))}getUsedOutputs(){return this.outputs.filter(i=>!i.suggestion&&i.writesValues.length)}};g(er,"repository",{APICreate:async(i,...a)=>i,APIUpdate:async(i,...a)=>i,APIDelete:async(i,...a)=>i,APIClone:async(i,...a)=>{},APILoad:async(i,...a)=>null,APILoadVersion:async(i,a,...o)=>null}),g(er,"type",f.FunctionCall),g(er,"USER_MANAGED_PARENT_TYPES",[...Mr,f.Project]),g(er,"PARENT_TYPES",[...er.USER_MANAGED_PARENT_TYPES]),g(er,"MUTABLE_BASE_PROPERTIES",[]),g(er,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),g(er,"BASE_PROPERTIES",[...er.MUTABLE_BASE_PROPERTIES,...er.INMUTABLE_BASE_PROPERTIES]),g(er,"MUTABLE_META_PROPERTIES",["x","y"]),g(er,"INMUTABLE_META_PROPERTIES",[...er.INMUTABLE_BASE_PROPERTIES]),g(er,"META_PROPERTIES",[...er.MUTABLE_META_PROPERTIES,...er.INMUTABLE_META_PROPERTIES]),g(er,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry"]),g(er,"INMUTABLE_UPSTREAM_PROPERTIES",["declaration","parent"]),g(er,"UPSTREAM_PROPERTIES",[...er.MUTABLE_UPSTREAM_PROPERTIES,...er.INMUTABLE_UPSTREAM_PROPERTIES]),g(er,"MUTABLE_DOWNSTREAM_PROPERTIES",["successCalls","errorCalls","writesValues","inputs","outputs","error"]),g(er,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),g(er,"DOWNSTREAM_PROPERTIES",[...er.MUTABLE_DOWNSTREAM_PROPERTIES,...er.INMUTABLE_DOWNSTREAM_PROPERTIES]),g(er,"PROPERTIES",[...er.META_PROPERTIES,...er.UPSTREAM_PROPERTIES,...er.DOWNSTREAM_PROPERTIES]);let Ao=er;function Pb(d){return d&&typeof d.then=="function"}function xIe(d){const u=new ea(d[0]),i=d.map(o=>o.id),a={};return d.forEach(o=>{a[o.id]=o}),u.order=i,u.flatRecord=a,u.orderEntities(),u.order.map(o=>u.flatRecord[o])}function FIe(d){const u=new ea(Object.values(d)[0]),i=Object.keys(d);return u.order=i,u.flatRecord=d,u.orderEntities(),u.order}class ea{constructor(u){g(this,"order",[]);g(this,"flatRecord",{});g(this,"allBuiltInEntityIds",Xs());g(this,"onGoingVisits",{});u&&(this.flatten(u),this.orderEntities())}flatten(u){const i=new Set(Xs()),a=R(me(u,i,{ignoreBuiltInBaseEntities:!0})),o=new Set;for(const p of a)this.flatRecord[p.id]=p,o.add(p.id);this.order=Array.from(o)}moveEntityAfterDependencies(u){const{upstream:i}=zd(u,this.flatRecord,{ignoreBuiltInBaseEntities:!0,allBuiltInEntityIds:this.allBuiltInEntityIds});for(const a of Object.keys(i)){const o=this.order.indexOf(a),p=this.order.indexOf(u.id);if(o>p)return this.order.splice(p,1),this.order.splice(o,0,u.id),!0}return!1}orderEntities(){let u=!1;for(let i=0;i<this.order.length;i++){const a=this.order[i],o=this.flatRecord[a];if(o||Me.warn(`Entity with id ${a} not found in flatRecord. Skipping...`),this.moveEntityAfterDependencies(o)){u=!0;break}}u&&this.orderEntities()}getUpstreamOngoingDependenciesVisits(u,i){const{upstream:a}=zd(this.flatRecord[u],this.flatRecord,{ignoreBuiltInBaseEntities:!0,allBuiltInEntityIds:this.allBuiltInEntityIds}),o={};return Object.entries(this.onGoingVisits[i]||{}).forEach(([p,e])=>{Object.keys(a).includes(p)&&(o[p]=e)}),o}getDownstreamOngoingDependenciesVisits(u,i){const a=Object.keys(this.onGoingVisits[i]||{}),o=new Set(a.flatMap(e=>Object.keys(zd(this.flatRecord[e],this.flatRecord,{ignoreBuiltInBaseEntities:!0,allBuiltInEntityIds:this.allBuiltInEntityIds}).downstream))),p={};return Array.from(o).forEach(e=>{e===u&&(p[e]=this.onGoingVisits[i][e])}),p}async settlePromises(u,i){const a=Object.values(u);a.length&&await Promise.all(a),Object.keys(u).forEach(o=>{delete this.onGoingVisits[i][o]})}visit(u){const i=this.order;for(const a of i)u(this.flatRecord[a],this.flatRecord);return this}reverseVisit(u){const i=this.order.slice().reverse();for(const a of i)u(this.flatRecord[a],this.flatRecord);return this}async visitAsync(u){const i=this.order,a=Math.random().toString(36).substring(7);this.onGoingVisits[a]={};for(const o of i){const p=this.getUpstreamOngoingDependenciesVisits(o,a);Object.keys(p).length&&await this.settlePromises(p,a);const e=u(this.flatRecord[o],this.flatRecord);Pb(e)&&(this.onGoingVisits[a][o]=e)}return await this.settlePromises(this.onGoingVisits[a],a),this.onGoingVisits[a]={},this}async reverseVisitAsync(u){const i=this.order.slice().reverse(),a=Math.random().toString(36).substring(7);this.onGoingVisits[a]={};for(const o of i){const p=this.getDownstreamOngoingDependenciesVisits(o,a);Object.keys(p).length&&await this.settlePromises(p,a);const e=u(this.flatRecord[o],this.flatRecord);Pb(e)&&(this.onGoingVisits[a][o]=e)}return await this.settlePromises(this.onGoingVisits[a],a),this.onGoingVisits[a]={},this}}function w5(d,u){switch(d.id){case Ee["built-in-base-entity"].BUILT_IN_PERSISTED_ENTITY_ENTITY.id:{const i=d.project.entities.filter(v=>!!v.implements.find(E=>E.id===Ee["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.id)),a=i.find(v=>{const E=v.properties.find($=>$.implements&&$.implements.id===Ee["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.default.id),b=E==null?void 0:E.getDefaultValue();return(b==null?void 0:b.value)===!0});if(!a&&i.length){const E=i[0].properties.find(A=>A.implements&&A.implements.id===Ee["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.default.id),b=E==null?void 0:E.defaultValue;if(b)b.metaSync({value:!0},u);else if(E!=null&&E.dataType){const A={id:N.UUID.uuid(),version:N.UUID.uuid(),createdAt:(u==null?void 0:u.timestamp)||new Date().toISOString(),author:N.sessionAuthor,previousVersion:null,deleted:!1,type:f.LiteralValue,standaloneParent:null,name:Q.EntityTemplate,autogeneration:null,value:!0,valueAsTypeSingle:null,valueAsTypeList:null,parent:E==null?void 0:E.toReference()},$=te(A,d.project);return $.setParent(E,u),$.initChildren(u),u==null||u.add($,S.Added),$.addSelfToProject(u),{newEntities:[$]}}return{newEntities:[]}}else if(a)return{newEntities:[]};const o=d.project.get(Ee["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.id),p=wm(o,"Main database",u);if(p.errors.length>0)return{newEntities:[]};const e=p.properties.find(v=>v.implements&&v.implements.id===Ee["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.default.id),y=e==null?void 0:e.defaultValue;if(y)y.metaSync({value:!0},u);else if(e!=null&&e.dataType){const v={id:N.UUID.uuid(),version:N.UUID.uuid(),createdAt:(u==null?void 0:u.timestamp)||new Date().toISOString(),author:N.sessionAuthor,previousVersion:null,deleted:!1,type:f.LiteralValue,standaloneParent:null,name:Q.EntityTemplate,autogeneration:null,value:!0,valueAsTypeSingle:null,valueAsTypeList:null,parent:e==null?void 0:e.toReference()},E=te(v,d.project);E.setParent(e,u),E.initChildren(u),u==null||u.add(E,S.Added),E.addSelfToProject(u)}return{newEntities:[p]}}}return{newEntities:[]}}function R5(d,u){const i=[],a=[],o=[],p=[];return d.implements.filter(y=>y.type===f.BuiltInBaseEntity).forEach(y=>{var v;switch(y.id){case Ee["built-in-base-entity"].BUILT_IN_PERSISTED_ENTITY_ENTITY.id:{const E=d.project.entities.filter(V=>V.implements.find(U=>U.id===Ee["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.id));let b=E.find(V=>!!V.properties.find(U=>{var G;return U.implements&&U.implements.id===Ee["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.default.id&&((G=U.getDefaultValue())==null?void 0:G.value)===!0}));if(!b&&E.length)b=E[0];else if(!b&&!E.length){b=d.project.getBuiltIn(Ee["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.id).implement("Relational database",u);const U=b.properties.find(G=>{var K;return((K=G.implements)==null?void 0:K.id)===Ee["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.default.id});(v=U==null?void 0:U.defaultValue)==null||v.metaSync({value:!0},u),a.push(b)}const A=d.properties.find(V=>V.implements&&V.implements.id===Ee["built-in-base-entity"].BUILT_IN_PERSISTED_ENTITY_ENTITY.properties.database.id),$=A==null?void 0:A.defaultValue;if(A&&!$){const V={id:N.UUID.uuid(),version:N.UUID.uuid(),createdAt:(u==null?void 0:u.timestamp)||new Date().toISOString(),author:N.sessionAuthor,previousVersion:null,deleted:!1,type:f.LiteralValue,standaloneParent:null,name:Q.EntityTemplate,autogeneration:null,value:null,valueAsTypeSingle:(b==null?void 0:b.toJSON())||null,valueAsTypeList:null,parent:A==null?void 0:A.toReference()},U=te(V,d.project);U.hydrateAncestors(),U.setParent(A,u),U.addSelfToProject(u),U.initChildren(u),u==null||u.add(U,S.Added),a.push(U);return}else $&&!$.valueAsTypeSingle&&$.setValueAsTypeSingle(b||null,u);return}}}),{self:d,updated:R(i),added:R(a),removed:R(o),affected:R(p)}}function wm(d,u,i,a){const o=a||N.UUID.uuid(),p=N.UUID.uuid(),e={id:o,version:p,createdAt:(i==null?void 0:i.timestamp)||new Date().toISOString(),author:N.sessionAuthor,previousVersion:null,deleted:!1,name:u,type:f.DefinitionEntity,codeName:null,description:null,static:d.static,abstract:!1,properties:[],methods:[],abstractMethods:[],extends:[],implements:[d.toJSON()],x:0,y:0,parent:d.project.toReference()};w5(d,i);const y=te(e,d.project);return y.hydrateAncestors(),i==null||i.add(y,S.Added),y.addSelfToProject(i),y.addImplementation(d),y.setParent(d.project,i),y.initChildren(i),R5(y,i),y}function Nb(d,u){return u.entities.find(o=>{const p=o.properties,e=p.map(A=>A.name),y=d.every(A=>e.includes(A)),v=e.filter(A=>!d.includes(A)),E=p.every(A=>!v.includes(A.name)||!A.required);return y&&E})||null}function _5(d,u,i,a=Ei.OrDataTypeGroup){const o=[],p=[],e=[],y=[],E={id:N.UUID.uuid(),version:N.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||new Date().toISOString(),author:N.sessionAuthor,previousVersion:null,deleted:!1,type:f.DataType,options:null,implementationChooseOne:!1,entity:d.toJSON(),isList:!1,asType:!1,andChildrenGroup:null,orChildrenGroup:null,staticEntities:null,interactiveEntities:null,actionEntities:null,like:!0,inferred:!1,parentRelationType:a,parent:u.toReference()},b=te(E,d.project);return p.push(b),b.setParent(u,i),b.initChildren(i),i==null||i.add(b,S.Added),b.setEntity(d,i),b.addSelfToProject(i),{updated:R(o),added:R(p),removed:R(e),affected:R(y),self:b}}function Vb(d,u,i,a,o){var E,b,A,$,V,U,G,K;const p=[],e=[],y=[],v=[];switch(typeof d){case"string":let Z=!1;const ie=new Date(d);if(ie instanceof Date&&!isNaN(ie.valueOf())&&(Z=!0),Z){const X=u.project.getBuiltIn(Ee[f.PrimitiveEntity][Q.Date].id);u.setEntity(X,a);break}else{const X=u.project.getBuiltIn(Ee[f.PrimitiveEntity][Q.String].id);u.setEntity(X,a);break}case"number":u.setEntity(u.project.getBuiltIn(Ee[f.PrimitiveEntity][Q.Number].id),a);break;case"boolean":u.setEntity(u.project.getBuiltIn(Ee[f.PrimitiveEntity][Q.Boolean].id),a);break;case"object":if(d===null){u.setEntity(u.project.getBuiltIn(Ee[f.PrimitiveEntity][Q.Null].id),a);break}else if(Array.isArray(d))if(u.metaSync({isList:!0},a),d.length>0){const X=d.slice(0,5).filter(re=>re!==void 0);if(X.every(re=>typeof re==typeof X[0])&&(typeof X[0]!="object"||X[0]===null))switch(typeof X[0]){case"string":u.setEntity(u.project.getBuiltIn(Ee[f.PrimitiveEntity][Q.String].id),a);break;case"number":u.setEntity(u.project.getBuiltIn(Ee[f.PrimitiveEntity][Q.Number].id),a);break;case"boolean":u.setEntity(u.project.getBuiltIn(Ee[f.PrimitiveEntity][Q.Boolean].id),a);break;case"object":u.setEntity(u.project.getBuiltIn(Ee[f.PrimitiveEntity][Q.Null].id),a);break}else{const re=[];let fe=!1;X.forEach(H=>{var ce,z,oe,we;if(Array.isArray(H)&&(fe=!0),typeof H=="object"&&!Array.isArray(H)&&H!==null){const xe=Rm(H,u.project,{...i,id:N.UUID.uuid()},a,o);xe.hasCreated&&re.push((ce=xe.changeSet)==null?void 0:ce.self),p.push(...(z=xe.changeSet)==null?void 0:z.updated),e.push(...(oe=xe.changeSet)==null?void 0:oe.added),y.push(...(we=xe.changeSet)==null?void 0:we.removed)}});const Y=R(re);if(!Y.length&&!fe){X.forEach(H=>{const ce={id:N.UUID.uuid(),version:N.UUID.uuid(),createdAt:(a==null?void 0:a.timestamp)||new Date().toISOString(),author:N.sessionAuthor,previousVersion:null,deleted:!1,type:f.DataType,options:null,implementationChooseOne:!1,entity:null,isList:!1,asType:!1,andChildrenGroup:null,orChildrenGroup:null,staticEntities:!1,interactiveEntities:!0,actionEntities:!1,like:!0,inferred:!1,parentRelationType:Ei.OrDataTypeGroup,parent:u.toReference()},z=te(ce,u.project);switch(z.setParent(u,a),z.initChildren(a),a==null||a.add(z,S.Added),z.addSelfToProject(a),typeof H){case"string":z.setEntity(z.project.getBuiltIn(Ee[f.PrimitiveEntity][Q.String].id),a);break;case"number":z.setEntity(z.project.getBuiltIn(Ee[f.PrimitiveEntity][Q.Number].id),a);break;case"boolean":z.setEntity(z.project.getBuiltIn(Ee[f.PrimitiveEntity][Q.Boolean].id),a);break;case"object":z.setEntity(z.project.getBuiltIn(Ee[f.PrimitiveEntity][Q.Null].id),a);break}});break}else Y.length===1&&!fe?u.setEntity(Y[0],a):X.forEach(H=>{if(typeof H=="object"&&!Array.isArray(H)&&H!==null){const ce=Nb(Object.keys(H),u.project);if(ce){const z=_5(ce||Y[0],u,a,Ei.OrDataTypeGroup);p.push(...z.updated),e.push(...z.added),y.push(...z.removed)}}else{const ce={id:N.UUID.uuid(),version:N.UUID.uuid(),createdAt:(a==null?void 0:a.timestamp)||new Date().toISOString(),author:N.sessionAuthor,previousVersion:null,deleted:!1,type:f.DataType,options:null,implementationChooseOne:!1,entity:null,isList:Array.isArray(H),asType:!1,andChildrenGroup:null,orChildrenGroup:null,staticEntities:!1,interactiveEntities:!0,actionEntities:!1,like:!0,inferred:!1,parentRelationType:Ei.OrDataTypeGroup,parent:u.toReference()},z=te(ce,u.project);z.setParent(u,a),z.initChildren(a),a==null||a.add(z,S.Added),z.addSelfToProject(a);const oe=Vb(H,z,{...i,id:N.UUID.uuid()},a,o);p.push(...oe.updated),e.push(...oe.added),y.push(...oe.removed)}})}}else{const X=Rm(d[0],u.project,{...i},a,o);u.setEntity((E=X.changeSet)==null?void 0:E.self,a),p.push(...(b=X.changeSet)==null?void 0:b.updated),e.push(...(A=X.changeSet)==null?void 0:A.added),y.push(...($=X.changeSet)==null?void 0:$.removed);break}else{const X=Rm(d,u.project,{...i},a,o);u.setEntity((V=X.changeSet)==null?void 0:V.self,a),p.push(...(U=X.changeSet)==null?void 0:U.updated),e.push(...(G=X.changeSet)==null?void 0:G.added),y.push(...(K=X.changeSet)==null?void 0:K.removed);break}}return{updated:R(p),added:R(e),removed:R(y),affected:R(v),self:u}}function Rm(d,u,i,a,o){const p=[],e=[],y=[],v=[],E=Object.keys(d),b=Nb(E,u);if(b)return{hasCreated:!1,changeSet:{updated:[],added:[],removed:[],affected:[],self:b}};const A=o?i.name+" of "+o.name:i.name,V={id:i.id||N.UUID.uuid(),version:N.UUID.uuid(),createdAt:(a==null?void 0:a.timestamp)||new Date().toISOString(),author:N.sessionAuthor,previousVersion:null,deleted:!1,name:A,codeName:null,type:f.DefinitionEntity,description:i.description||null,static:i.static||!1,abstract:i.abstract||!1,properties:[],methods:[],abstractMethods:[],extends:[],implements:[],x:0,y:0,parent:u.toReference()},U=te(V,u);return U.setParent(u,a),U.initChildren(a),a==null||a.add(U,S.Added),U.addSelfToProject(a),e.push(U),E.forEach((G,K)=>{const ie={id:N.UUID.uuid(),version:N.UUID.uuid(),createdAt:(a==null?void 0:a.timestamp)||new Date().toISOString(),author:N.sessionAuthor,previousVersion:null,deleted:!1,name:G,type:f.Property,codeName:G,description:null,static:!1,abstract:!1,defaultValue:null,constant:!1,interactive:!0,dataType:null,implements:null,extends:null,index:K,hidden:!1,private:!1,required:!0,parent:U.toReference()},X=te(ie,u);X.setParent(U,a),X.initChildren(a),a==null||a.add(X,S.Added),X.addSelfToProject(a),e.push(X);const ue=d[G],fe={id:N.UUID.uuid(),version:N.UUID.uuid(),createdAt:(a==null?void 0:a.timestamp)||new Date().toISOString(),author:N.sessionAuthor,previousVersion:null,deleted:!1,type:f.DataType,parentRelationType:null,options:null,implementationChooseOne:!1,entity:null,isList:!1,asType:!1,andChildrenGroup:null,orChildrenGroup:null,staticEntities:!1,interactiveEntities:!0,actionEntities:!1,like:!0,inferred:!1,parent:X.toReference()},Y=te(fe,u);Y.setParent(X,a),Y.initChildren(a),a==null||a.add(Y,S.Added),Y.addSelfToProject(a),e.push(Y);const H=Vb(ue,Y,{...i,name:G,id:N.UUID.uuid()},a,o||U);p.push(...H.updated),e.push(...H.added),y.push(...H.removed)}),{hasCreated:!0,changeSet:{updated:R(p),added:R(e),removed:R(y),affected:R(v),self:U}}}function ja(d,u,i,a){const o=[];return!d.length||!u.length?{errors:o,overlap:!1}:(d.length>u.length?d.forEach(p=>{const e=u.find(v=>v.name===p.name),y=u.find(v=>{var E,b;return!!p.implements&&((E=v.implements)==null?void 0:E.id)===((b=p.implements)==null?void 0:b.id)});if(e){const v=new dr({id:p.id+"--"+e.id+"--"+a,message:`Entity of type ${p.type} named "${p.name}" with id "${p.id}" overrides a base ${e.type} ${e.name} with id "${e.id}" that has the same name`,severity:q.Error,code:a,entity:p,firstRelationship:e});o.push(v)}if(y){const v=new dr({id:p.id+"--"+y.id+"--"+i,message:`Entity of type ${p.type} named "${p.name}" with id "${p.id}" overrides a base ${y.type} ${y.name} with id "${y.id}" that implements the same base descriptor`,severity:q.Error,code:i,entity:p,firstRelationship:y});o.push(v)}}):u.forEach(p=>{var v;const e=d.find(E=>E.name===p.name),y=d.find(E=>{var b,A;return!!E.implements&&((b=E.implements)==null?void 0:b.id)===((A=p.implements)==null?void 0:A.id)});if(e){const E=new dr({id:e.id+"--"+p.id+"--"+a,message:`Entity of type ${e.type} named "${e.name}" with id "${e.id}" overrides a base entity ${p.name} with id "${p.id}" that has the same name`,severity:q.Error,code:a,entity:e,firstRelationship:p});o.push(E)}if(y){const E=new dr({id:y.id+"--"+p.id+"--"+i,message:`Entity of type ${y.type} named "${y.name}" with id "${y.id}" overrides a base entity ${p.name} with id "${p.id}" that implements the same base ${(v=y==null?void 0:y.implements)==null?void 0:v.type}`,severity:q.Error,code:i,entity:y,firstRelationship:p});o.push(E)}}),{errors:o,overlap:!!o.length})}function GIe(d,u){return d.abstract||(d.properties.forEach(a=>{a.abstract||a.metaSync({abstract:!0},u)}),Object.values(d.detachedDependents).forEach(a=>{a.field===dA.Entity&&a.entity.remove({ignoreUpstream:!1},u)}),d.metaSync({abstract:!0},u)),d}function SIe(d,u){return d.abstract&&(d.properties.forEach(a=>{a.abstract&&a.metaSync({abstract:!1},u)}),Object.values(d.detachedDependents).forEach(a=>{(a.field===Sm.Implements||a.field===Sm.Extends)&&a.entity.onDetachedDependencyRemoved(d,a.field,u)}),d.metaSync({abstract:!1},u)),d}function KIe(d,u){return d.static||(d.properties.forEach(a=>{a.static||a.metaSync({static:!0},u)}),d.metaSync({static:!0},u)),d}function kIe(d,u){return d.static&&d.metaSync({static:!1},u),d}var g5=(d=>(d.StringValueMustNotHaveSpaces="string-value-must-not-have-spaces",d.StringValueMustNotHaveDashes="string-value-must-not-have-dashes",d))(g5||{});function D5(d,u){const i=[],a=u;if(!a)return{errors:i,override:u};if(typeof a!="string")return{errors:[],override:u};if(a.includes(" ")){const o=new dr({id:d.id+"--string-value-must-not-have-spaces",message:`Entity of type ${d.type} with id "${d.id}" has an invalid value "${u}". The value cannot contain spaces.`,severity:q.Error,code:"string-value-must-not-have-spaces",entity:d});i.push(o)}return{errors:i,override:a.replace(/\s/g,"-")}}function O5(d,u){const i=[],a=u;if(!a)return{errors:i,override:u};if(typeof a!="string")return{errors:[],override:u};if(a.includes(" ")){const o=new dr({id:d.id+"--string-value-must-not-have-spaces",message:`Entity of type ${d.type} with id "${d.id}" has an invalid value "${u}". The value cannot contain spaces or dashes.`,severity:q.Error,code:"string-value-must-not-have-spaces",entity:d});i.push(o)}if(a.includes("-")){const o=new dr({id:d.id+"--string-value-must-not-have-dashes",message:`Entity of type ${d.type} with id "${d.id}" has an invalid value "${u}". The value cannot contain spaces or dashes.`,severity:q.Error,code:"string-value-must-not-have-dashes",entity:d});i.push(o)}return{errors:i,override:a.replace(/\s|-/g,"_")}}function Lb(d,u){var i;if(d.type===f.LiteralValue){let a=(i=d.value)==null?void 0:i.toString();try{a=JSON.stringify(d.value,null,2)}catch{}return`${d.type}: ${d.id} (${ne(d,u)}) = ${a}`}if(d.type===f.DataType){if(d instanceof vs||d.increaseVersion)return`${d.type}: ${d.id} (${iu(d)})`;try{const a=iu(d);return`${d.type}: ${d.id} (${a})`}catch{}}return`${d.type}: ${d.id} (${ne(d,u)})`}function Yd(d,u){const i=bo(d);if(i.length===0)return{list:[],last:null};let a=null;return{list:i.flatMap(p=>{if(p===u)return a=p,[p];const e=Yd(p,u);return e.last&&(a=e.last),[p,...e.list]}),last:a}}function _l(d,u){const i=d.calledBy;if(i.length===0)return{list:[],last:null,callType:null};let a=null,o=null;return{list:i.flatMap(e=>{if(e===u)return a=e,Pt.includes(e.type)?e.parent.type===f.Loop?o="loop-body":o="entry":e.successCalls.includes(d)?o="success":e.errorCalls.includes(d)&&(o="error"),[e];if(!Ti.includes(e.type))return[e];const y=_l(e,u);return y.last&&(a=y.last,o=y.callType),[e,...y.list]}),last:a,callType:o}}function _m(d){if(d.type===f.Loop){const u=[...Mi(ti(d.successCalls)).map(o=>({callee:o,callType:"success"})),...Mi(ti(d.errorCalls)).map(o=>({callee:o,callType:"error"})),...(d.body?Rt(d.body):[]).map(o=>({callee:o,callType:"loop-body"}))];return R(u.map(o=>o.callee)).map(o=>{var e;const p=(e=u.find(y=>y.callee===o))==null?void 0:e.callType;return{callee:o,callType:p}})}if(fr.includes(d.type)){const u=[...Mi(ti(d.successCalls)).map(o=>({callee:o,callType:"success"})),...Mi(ti(d.errorCalls)).map(o=>({callee:o,callType:"error"}))];return R(u.map(o=>o.callee)).map(o=>{var e;const p=(e=u.find(y=>y.callee===o))==null?void 0:e.callType;return{callee:o,callType:p}})}if(Pt.includes(d.type)){const u=[...Mi(ti(d.calls)).map(o=>d.parent.type===f.Loop?{callee:o,callType:"loop-body"}:{callee:o,callType:"entry"})];return R(u.map(o=>o.callee)).map(o=>{var e;const p=(e=u.find(y=>y.callee===o))==null?void 0:e.callType;return{callee:o,callType:p}})}return[]}function Mb(d,u,i,a,o=!0){return d.reduce((e,y)=>{if(!gi.includes(y.type))return e;const v=_m(y);if(y===u||y===i)return[...e,{ancestor:y,callType:a}];const E=v.find(A=>A.callee===u),b=v.find(A=>A.callee===i);if(!E&&!b)return e;if(E&&b){if(E.callType===b.callType)return[...e,{ancestor:y,callType:E.callType}];if(!o)return[...e,{ancestor:y,callType:E.callType}]}else return[...e,{ancestor:y,callType:(E==null?void 0:E.callType)||(b==null?void 0:b.callType)}];return e},[])}function Bb(d,u,i,a=!0){let o,p=[];if(Pt.includes(i.type))i.parent.type===f.Loop?o="loop-body":o="entry",p=Mb(i.calls,d,u,o,a);else if(fr.includes(i.type)){const y=Mb(i.successCalls,d,u,"success",a),v=Mb(i.errorCalls,d,u,"error",a);y.length&&!v.length&&(p.push(...y.map(E=>({ancestor:E.ancestor,callType:E.callType}))),o="success"),!y.length&&v.length&&(p.push(...v.map(E=>({ancestor:E.ancestor,callType:E.callType}))),o="error")}if(p.length===0)return{ancestor:null,callType:null};if(p.length===1){const y=p[0].ancestor,v=_m(y),E=v.find(A=>A.callee===d),b=v.find(A=>A.callee===u);return!E&&!b&&!a?{ancestor:null,callType:null}:{ancestor:y,callType:(E==null?void 0:E.callType)||(b==null?void 0:b.callType)}}const e=p.filter(y=>!p.some(v=>v.ancestor!==y.ancestor&&_l(y.ancestor,v.ancestor).last===v.ancestor));if(e.length===1){const y=Bb(d,u,e[0].ancestor,a);return y.ancestor?{ancestor:y.ancestor,callType:y.callType}:{ancestor:e[0].ancestor,callType:e[0].callType}}return{ancestor:i,callType:o}}function Ub(d,u,i=!0){var e,y,v,E;if(!d||!u)throw new Error("Both entities must be defined to find a common ancestor");if(d===u)return{ancestor:d,callType:"same-entity"};if(!((e=d.calledBy)!=null&&e.length)&&!((y=u.calledBy)!=null&&y.length))return{ancestor:null,callType:null};if(Ti.includes(d.type)&&gi.includes(u.type)&&(v=d.calledBy)!=null&&v.every(b=>b===u)){if(Pt.includes(u.type))return u.parent.type===f.Loop?{ancestor:u,callType:"loop-body"}:{ancestor:u,callType:"entry"};if(u.successCalls.includes(d))return{ancestor:u,callType:"success"};if(u.errorCalls.includes(d))return{ancestor:u,callType:"error"}}if(Ti.includes(u.type)&&gi.includes(d.type)&&(E=u.calledBy)!=null&&E.every(b=>b===d)){if(Pt.includes(d.type))return d.parent.type===f.Loop?{ancestor:d,callType:"loop-body"}:{ancestor:d,callType:"entry"};if(d.successCalls.includes(u))return{ancestor:d,callType:"success"};if(d.errorCalls.includes(u))return{ancestor:d,callType:"error"}}const a=Qp(d),o=Qp(u);if(!a||!o)return{ancestor:null,callType:null};if(a!==o)return{ancestor:null,callType:null};const p=Bb(d,u,a,i);return p.ancestor?{ancestor:p.ancestor,callType:p.callType}:{ancestor:a,callType:"entry"}}function C5(d){if(!d)return{ancestor:null,callType:null};const u=d.calledBy;if(u.length===0){if(mt.includes(d.type)){const p=d.internalCalls.find(e=>!!e.calledBy.length);if(p)return C5(p)}return{ancestor:null,callType:null}}if(u.length===1){if(Pt.includes(u[0].type))return u[0].parent.type===f.Loop?{ancestor:u[0],callType:"loop-body"}:{ancestor:u[0],callType:"entry"};if(u[0].successCalls.includes(d))return{ancestor:u[0],callType:"success"};if(u[0].errorCalls.includes(d))return{ancestor:u[0],callType:"error"}}let i=u[0],a=null;for(let o=1;o<u.length&&i;o++){const p=u[o];if(!Ti.includes(p.type)){i=p,Pt.includes(i.type)?i.parent.type===f.Loop?a="loop-body":a="entry":i.successCalls.includes(d)?a="success":i.errorCalls.includes(d)&&(a="error");continue}if(i===p)continue;const e=Ub(i,p);e.ancestor?(i=e.ancestor,a=e.callType):(i=null,a=null)}return i?{ancestor:i,callType:a}:{ancestor:null,callType:null}}function jb(d){if(!d)return null;if(jv.includes(d.type))return d;const u=d.parent;return u?jb(u):null}function xb(d,u=new Set){return d.writesValues.reduce((i,a)=>u.has(a.id)?i:(u.add(a.id),cn.includes(a.type)?[...i,a]:Fr.includes(a.type)?[...i,a,...xb(a,u)]:i),[])}function qIe(d){if(![f.VariableDeclaration,f.OutputMap].includes(d.type))throw new Error("getEarliestSingleCallerAncestorOfValueWriterAndItsValueReaders can only be used with a value writer entity");let u;if(d.type===f.VariableDeclaration?u=d:d.type===f.OutputMap&&(u=d.parent),!u)throw new Error("getEarliestSingleCallerAncestorOfValueWriterAndItsValueReaders can only be used with a value writer entity that has a caller");const i=R([d,...xb(d)]),a=R(i.map(e=>jb(e)).flatMap(e=>Tr.includes(e==null?void 0:e.type)?e.calledBy:[e]));let o=a[0],p=null;for(let e=1;e<a.length&&o;e++){const y=a[e];if(!Ti.includes(y.type)){o=y,Pt.includes(o.type)?o.parent.type===f.Loop?p="loop-body":p="entry":o.successCalls.includes(u)?p="success":o.errorCalls.includes(u)&&(p="error");continue}if(o===y)continue;const v=Ub(o,y);v.ancestor?(o=v.ancestor,p=v.callType):(o=null,p=null)}return o?{ancestor:o,callType:p||"success"}:{ancestor:null,callType:null}}function Xp(d){const u=d.calledBy;if(u.length===0)return d.project;const i=u.reduce((a,o)=>{const p=Ji(o,d.project);return!p||p.type===f.Project?a:a.type===f.Project||Yd(p,a).last?p:(Yd(a,p).last,a)},d.project);return i.type===f.FunctionDeclaration&&i.parent.type===f.Loop?i.parent:i}function We(d,u){let i=Xp(d);if(d.type===f.InternalCall)if(d.parent.type===f.VariableInstance){const o=Qs(i,d.parent.declaration,d.project);!o.compatible&&o.type!=="b-is-global-a-is-not"?d.parent.remove({ignoreUpstream:!1},u):(d.parent.setParent(i,u),d.parent.addSelfToProject(u))}else d.parent.setParent(i,u),d.parent.addSelfToProject(u);else if((d.type===f.ContinueStatement||d.type===f.BreakStatement)&&i.type!==f.Loop){d.remove({ignoreUpstream:!1},u);return}else if(d.type===f.ReturnStatement&&!Mr.includes(i.type)){d.remove({ignoreUpstream:!1},u);return}else if(mt.includes(d.type)){const o=d.usedInternalCalls[0];if(o)if(i=Xp(o),d.type===f.VariableInstance){const p=Qs(i,d.declaration,d.project);!p.compatible&&p.type!=="b-is-global-a-is-not"?d.remove({ignoreUpstream:!1},u):(d.setParent(i,u),d.addSelfToProject(u))}else d.setParent(i,u),d.addSelfToProject(u);else if(d.type===f.VariableInstance){const p=Qs(i,d.declaration,d.project);!p.compatible&&p.type!=="b-is-global-a-is-not"?d.remove({ignoreUpstream:!1},u):(d.setParent(i,u),d.addSelfToProject(u))}else d.setParent(i,u),d.addSelfToProject(u)}else d.setParent(i,u),d.addSelfToProject(u);if(Tr.includes(d.type))return;Rt(d).forEach(o=>{let p=Xp(o);if(o.type===f.InternalCall)if(o.parent.type===f.VariableInstance){const e=Qs(p,o.parent.declaration,d.project);!e.compatible&&e.type!=="b-is-global-a-is-not"?o.parent.remove({ignoreUpstream:!1},u):(o.parent.setParent(p,u),o.parent.addSelfToProject(u))}else o.parent.setParent(p,u),o.parent.addSelfToProject(u);else if((o.type===f.ContinueStatement||o.type===f.BreakStatement)&&p.type!==f.Loop){o.remove({ignoreUpstream:!1},u);return}else if(o.type===f.ReturnStatement&&!Mr.includes(p.type)){o.remove({ignoreUpstream:!1},u);return}else if(mt.includes(o.type)){const e=o.usedInternalCalls[0];if(e)if(p=Xp(e),o.type===f.VariableInstance){const y=Qs(p,o.declaration,d.project);!y.compatible&&y.type!=="b-is-global-a-is-not"?o.remove({ignoreUpstream:!1},u):(o.setParent(p,u),o.addSelfToProject(u))}else o.setParent(p,u),o.addSelfToProject(u);else if(o.type===f.VariableInstance){const y=Qs(p,o.declaration,d.project);!y.compatible&&y.type!=="b-is-global-a-is-not"?o.remove({ignoreUpstream:!1},u):(o.setParent(p,u),o.addSelfToProject(u))}else o.setParent(p,u),o.addSelfToProject(u)}else o.setParent(p,u),o.addSelfToProject(u)})}function gm(d,u,i=new Set){const a=Rn(d),o=Rn(u),p=a.filter(v=>!o.includes(v)),e=a.filter(v=>o.includes(v)),y=p.reduce((v,E)=>i.has(E.id)?v:(i.add(E.id),R([...v,...gm(E,u,i)])),[]);return R([...e,...y])}function gl(d,u){const i=Yd(d,u);return i.last===u&&i.list.length>0&&i.list[0]!==u}function Fb(d,u){return!!Yd(d,u).last}function ZIe(d,u){return!!_l(d,u).last}function Qp(d){if(Pt.includes(d.type))return d;if([...Ti,f.VariableDeclaration].includes(d.type)){const u=d.parent;return Pt.includes(u.type)?u:null}return null}function Gb(d,u){if(!d||!u)throw new Error("Both entities must be defined to find a common ancestor");if(d===u)return d;const i=d.parent;if(i){if(i===u)return u;if(i.type===f.Project)return null}else return null;const a=u.parent;if(a){if(a===d)return d;if(a.type===f.Project)return null}else return null;return Gb(i,a)}function JIe(d,u,i=!0){if(!d||!u)throw new Error("Both entities must be defined to find a common ancestor");if(d===u)return{ancestor:d,callType:"same-entity"};if(Ti.includes(d.type)&&gi.includes(u.type)){const y=_l(d,u),v=y.last;if(v){if(v===u)return{ancestor:u,callType:y.callType}}else return{ancestor:null,callType:null}}if(Ti.includes(u.type)&&gi.includes(d.type)){const y=_l(u,d),v=y.last;if(v){if(v===d)return{ancestor:d,callType:y.callType}}else return{ancestor:null,callType:null}}const a=Qp(d),o=Qp(u);if(!a||!o)return{ancestor:null,callType:null};if(a!==o)return{ancestor:null,callType:null};if(a.calls.includes(d)||a.calls.includes(u))return{ancestor:a,callType:"entry"};const p=a.calls.reduce((y,v)=>{if(!gi.includes(v.type))return y;const E=_m(v),b=E.find($=>$.callee===d),A=E.find($=>$.callee===u);return b&&A&&(!i||b.callType===A.callType)?[...y,{ancestor:v,callType:b.callType}]:y},[]);if(p.length===0)return{ancestor:null,callType:null};if(p.length===1)return{ancestor:p[0].ancestor,callType:p[0].callType};const e=p.filter(y=>!p.some(v=>v.ancestor!==y.ancestor&&_l(y.ancestor,v.ancestor).last===v.ancestor));return e.length===1?{ancestor:e[0].ancestor,callType:e[0].callType}:{ancestor:a,callType:"entry"}}function Er(d){if(ih.includes(d.type)){if(d.type===f.FunctionDeclaration){const u=d.parent;if(u.type===f.DefinitionEntity)return Er(u);if(u.type===f.Loop)return u}return d.type===f.DefinitionEntity&&d.parent.type===f.DataType?Er(d.parent):d}else{const u=d.parent;return u?Er(u):null}}function Dm(d,u){const i=ef(d,u);if(!i)return null;if(ih.includes(i.type)){if(i.type===f.FunctionDeclaration){const a=ef(i.parent,u);if(a){if(a.type===f.DefinitionEntity)return a;if(a.type===f.Loop)return a}}return i}else{const a=i.parent?ef(i.parent,u):null;return a?Dm(a,u):null}}function $5(d){if(!d)return null;if(Ti.includes(d.type))return d;const u=d.parent;return u?$5(u):null}function P5(d){if(!d)return null;if(fr.includes(d.type))return d;const u=d.parent;return u?P5(u):null}function N5(d){if(!d)return null;if(gi.includes(d.type))return d;const u=d.parent;return u?N5(u):null}function HIe(d){return d.type===f.VariableDeclaration?[d]:fr.includes(d.type)?[...d.inputs,...d.outputs||[]]:Tr.includes(d.type)?d.outputs:So.includes(d.type)||d.type===f.FunctionDeclaration?d.inputs:[]}function WIe(d){const u=Rn(d),i=[],a=[];gg.includes(d.type)&&i.push(...Om(d));const o=u.filter(p=>{const e=i.includes(p);return e?!1:Ti.includes(p.type)&&!e?(a.push(p),!1):!0});return i.sort((p,e)=>gl(e,p)?-1:0),a.sort((p,e)=>gl(e,p)?-1:0),[...i,...a,...o]}function V5(d){return[...d].sort((u,i)=>gl(i,u)?-1:0)}function YIe(d){const u=V5(d),i=[];return u.forEach(a=>{const o=i[i.length-1];if(o){const p=o[o.length-1];gl(a,p)?i.push([a]):o.push(a)}else i.push([a])}),i}function ti(d){const u=d.map(i=>Er(i));return R(u)}function Om(d){return fr.includes(d.type)?[...ti(d.successCalls),...ti(d.errorCalls)]:Pt.includes(d.type)?ti(d.calls):[]}function zIe(d,u){return Om(d).includes(u)}function Cm(d){return d.writesValues||[]}function XIe(d,u){return Cm(d).includes(u)}function L5(d){var u;return mt.includes((u=d==null?void 0:d.readsValue)==null?void 0:u.type)?d.readsValue:null}function QIe(d){return d.writesValues}function M5(d=[]){return d.map(L5).filter(u=>!!u)}function $m(d=[]){return d.map(u=>u.writesValues).flat().filter(u=>mt.includes(u.type))}function B5(d=[]){return d.map(u=>u.readsValue).filter(u=>!!u&&mt.includes(u.type))}function U5(d){return mt.includes(d.type)?d:null}function j5(d){return d.writesValues.map(U5).filter(u=>!!u)}function x5(d=[]){return d.reduce((u,i)=>i.type===f.OutputMap?[...u,...j5(i)]:u,[])}function Rt(d){return d.type===f.Loop?R([...Mi(ti(d.successCalls)),...Mi(ti(d.errorCalls)),...d.body?Rt(d.body):[]]):fr.includes(d.type)?R([...Mi(ti(d.successCalls)),...Mi(ti(d.errorCalls))]):Pt.includes(d.type)?R(Mi(ti(d.calls))):[]}function eAe(d){return fr.includes(d.type)?[...Mi(ti(d.successCalls)),...Mi(ti(d.errorCalls))]:Pt.includes(d.type)?Mi(ti(d.calls)):[]}function F5(d,u=new Set){return d.writesValues.filter(a=>mt.includes(a.type)&&!u.has(a.id)).reduce((a,o)=>u.has(o.id)?a:[...a,...mr(o,u)],[])}function G5(d,u=new Set){var a;return(((a=d.readsValue)==null?void 0:a.writesValues)||[]).filter(o=>mt.includes(o.type)&&!u.has(o.id)).reduce((o,p)=>u.has(p.id)?o:[...o,...mr(p,u)],[])}function mr(d,u=new Set){if(u.has(d.id))return[];if(d.type===f.ReturnStatement)return B5(d.outputs).reduce((a,o)=>[...a,...mr(o,u)],[]);if(d.type===f.FunctionCall||d.type===f.Operation||d.type===f.Condition)return[...Rt(d).reduce((p,e)=>{const y=Er(e);return[...p,...mr(y||e,u)]},[]),...M5(d.inputs),...x5(d.outputs)].reduce((p,e)=>[...p,...mr(e,u)],[]);if(So.includes(d.type)){const i=$m(d.inputs),o=Rt(d).reduce((p,e)=>{const y=Er(e);return[...p,...mr(y||e,u)]},[]);return i.push(...o),i.reduce((p,e)=>[...p,...mr(e,u)],[])}if(d.type===f.FunctionDeclaration){const i=[...$m(d.inputs)],o=Rt(d).reduce((p,e)=>{const y=Er(e);return[...p,...mr(y||e,u)]},[]);return i.push(...o),i.reduce((p,e)=>[...p,...mr(e)],[])}if(mt.includes(d.type)){u.add(d.id);const a=Rt(d).reduce((o,p)=>{const e=Er(p);return[...o,...mr(e||p,u)]},[]);return[d,...a,...G5(d,u),...F5(d,u)]}return[]}function Is(d,u=new Set){return u.has(d.id)?[]:(u.add(d.id),[...Rn(d).reduce((o,p)=>[...o,p,...Is(p,u)],[])])}function Mi(d){return d.reduce((u,i)=>i.type===f.ReturnStatement||i.type===f.ContinueStatement||i.type===f.BreakStatement?[...u,i]:[...u,i,...Rt(i)],[])}function S5(d){const u=d.entities||[],i=[...u,...d.functions||[],...d.events||[],...d.projects||[]],a=u.reduce((v,E)=>[...v,...E.properties],[]),o=u.reduce((v,E)=>[...v,...E.methods],[]),p=o.reduce((v,E)=>[...v,...$m(E.inputs),...Mi(ti(E.calls)),...E.returnStatements],[]),e=d.functions.reduce((v,E)=>[...v,...Mi(ti(E.calls)),...E.returnStatements],[]),y=d.events.reduce((v,E)=>[...v,...Mi(ti(E.calls)),...E.returnStatements],[]);return[...i,...a,...o,...p,...e,...y]}function K5(d,u){return u.filter(a=>{if(!a)return!1;switch(a.type){case f.FunctionCall:return a.inputs.find(o=>o.id===d.id)!==void 0||a.outputs.find(o=>o.id===d.id)!==void 0;case f.Condition:return a.successCalls.find(o=>o.id===d.id)!==void 0||a.errorCalls.find(o=>o.id===d.id)!==void 0||a.inputs.find(o=>o.id===d.id)!==void 0;case f.Operation:return a.outputs.find(o=>o.id===d.id)!==void 0;case f.VariableDeclaration:return fr.includes(d.type)?ES(d).find(p=>{var e;return((e=p.readsValue)==null?void 0:e.id)===a.id})!==void 0:!1;case f.DefinitionEntity:return a.properties.find(o=>o.id===d.id)!==void 0||a.methods.find(o=>o.id===d.id)!==void 0;case f.FunctionDeclaration:return a.inputs.find(o=>o.id===d.id)!==void 0||(a.returnStatements.map(o=>o.outputs).flat()||[]).find(o=>o.id===d.id)!==void 0;default:return!1}})}function tAe(d){const u=S5(d.project);return K5(d,u)}function ef(d,u){return d?typeof d=="string"?u[d]:d.type===f.GenericReference?u[d.entityId]:u[d.id]?u[d.id]:null:null}function k5(d={},u){const i={};return Object.keys(d).forEach(a=>{const o=u.get(a)||a,p=d[a];i[o]=p}),i}function zd(d,u={},i={}){const a={ignoreBuiltInBaseEntities:!1,allBuiltInEntityIds:[],entityMaps:new Map,...i};if(a.ignoreBuiltInBaseEntities&&(Wi.includes(d.type)||(a.allBuiltInEntityIds||[]).includes(d.id)))return{upstream:{},downstream:{}};const o=d,p=d,e=d,y=d,v=d,E=d,b=d,A=d,$=d,V=d,U=d,G=d,K=d,Z=[...K.readsValue?[K.readsValue]:[],...K.declaration?[K.declaration]:[],...(G.calledByEntry||[]).flatMap(re=>re),...(G.calledBySuccess||[]).flatMap(re=>re),...(G.calledByError||[]).flatMap(re=>re),...V.parent?[V.parent]:[]];Array.isArray(e.implements)?Z.push(...e.implements.flatMap(re=>re)):$.implements&&Z.push($.implements),Array.isArray(e.extends)?Z.push(...e.extends.flatMap(re=>re)):$.extends&&Z.push($.extends),v.valueAsTypeList&&Array.isArray(v.valueAsTypeList)&&Z.push(...v.valueAsTypeList.flatMap(re=>re)),v.valueAsTypeSingle&&Z.push(v.valueAsTypeSingle),(K.internalCalls||[]).forEach(re=>{const fe=J(re);if(fe&&u[fe]){const Y=u[fe];[...Y.calledByEntry||[],...Y.calledBySuccess||[],...Y.calledByError||[]].forEach(H=>{const ce=J(H);ce&&u[ce]&&Z.push(u[ce])})}});const ie=[...(o.inputs||[]).flatMap(re=>re),...(U.inputsDeclarations||[]).flatMap(re=>re),...(o.outputs||[]).flatMap(re=>re),...(U.outputsDeclarations||[]).flatMap(re=>re),...(K.internalCalls||[]).flatMap(re=>re),...K.writesValues||[],...G.dataType?[G.dataType]:[],...E.body?[E.body]:[],...G.defaultValue?[G.defaultValue]:[],...(G.successCalls||[]).flatMap(re=>re),...(G.errorCalls||[]).flatMap(re=>re),...(e.properties||[]).flatMap(re=>re),...(e.methods||[]).flatMap(re=>re),...(e.abstractMethods||[]).flatMap(re=>re),...b.error?[b.error]:[],...b.process?[b.process]:[],...V.throws?[V.throws]:[],...(p.andChildrenGroup||[]).flatMap(re=>re),...(p.orChildrenGroup||[]).flatMap(re=>re),...(A.entities||[]).flatMap(re=>re),...(A.functions||[]).flatMap(re=>re),...(A.functionCalls||[]).flatMap(re=>re),...(A.events||[]).flatMap(re=>re),...(A.conditions||[]).flatMap(re=>re),...(A.operations||[]).flatMap(re=>re),...(A.loops||[]).flatMap(re=>re),...(A.variableDeclarations||[]).flatMap(re=>re),...(A.variableInstances||[]).flatMap(re=>re),...(A.searches||[]).flatMap(re=>re),...(A.projects||[]).flatMap(re=>re),...(y.calls||[]).flatMap(re=>re)];d.type===f.DataType&&(p.entity&&u[J(p.entity)]&&u[J(p.entity)].parent&&J(u[J(p.entity)].parent)===d.id?ie.push(p.entity):p.entity&&Z.push(p.entity)),(K.internalCalls||[]).forEach(re=>{const fe=J(re);if(fe&&u[fe]){const Y=u[fe];[...Y.successCalls||[],...Y.errorCalls||[]].forEach(H=>{const ce=J(H);ce&&u[ce]&&ie.push(u[ce])})}});const X={},ue={};return Z.forEach(re=>{var H;const fe=J(re);if(fe&&a.ignoreBuiltInBaseEntities&&(Wi.includes(re.type)||(a.allBuiltInEntityIds||[]).includes(fe)))return;const Y=re.version;if(fe){const ce=((H=a.entityMaps)==null?void 0:H.get(fe))||fe;X[ce]=Y}}),ie.forEach(re=>{var H;const fe=J(re);if(fe&&a.ignoreBuiltInBaseEntities&&(Wi.includes(re.type)||(a.allBuiltInEntityIds||[]).includes(fe)))return;const Y=re.version;if(fe){const ce=((H=a.entityMaps)==null?void 0:H.get(fe))||fe;ue[ce]=Y}}),{upstream:X,downstream:ue}}function rAe(d,u){const i=[];if(Ti.includes(d.type)){Bs(d).forEach(p=>{const e=Dm(p,u);e&&i.push(e)});const o=[...d.inputs||[],...d.outputs||[]].map(p=>{const e=ef(p,u);return e?IS(e,u):null}).filter(p=>p!==null);i.push(...R(o))}if(mt.includes(d.type)){const a=Pm(d);a&&i.push(a)}return R(i)}function bo(d){const u=[];if(Ti.includes(d.type)){d.calledBy.forEach(o=>{const p=Er(o);p&&u.push(p)});const a=[...d.inputs||[],...d.outputs||[]].map(o=>Pm(o)).filter(o=>o!==null);u.push(...R(a))}if(mt.includes(d.type)){const i=Pm(d);i&&u.push(i)}return R(u)}function Bs(d){return[...d.calledByEntry||[],...d.calledByError||[],...d.calledBySuccess||[]].filter(u=>u.type!==f.GenericReference)}function q5(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.ActionDescriptor)throw new Error("Entity must be an action descriptor to be flattened");return[d,...d.inputs.flatMap(a=>me(a,u,i)),...d.outputs.flatMap(a=>me(a,u,i)),...d.error?me(d.error,u,i):[],...d.parent?me(d.parent,u,i):[]]}function Z5(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.ArgumentDeclaration)throw new Error("Entity must be an argument declaration to be flattened");return[d,...d.defaultValue?me(d.defaultValue,u):[],...d.writesValues.flatMap(a=>me(a,u,i)),...d.dataType?me(d.dataType,u,i):[],...d.parent?me(d.parent,u,i):[]]}function J5(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.BreakStatement)throw new Error("Entity must be a break statement to be flattened");return[d,...d.outputs.flatMap(a=>me(a,u,i)),...d.throws?me(d.throws,u,i):[],...(Bs(d)||[]).flatMap(a=>me(a,u,i)),...d.parent?me(d.parent,u,i):[]]}function H5(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.BuiltInBaseEntity)throw new Error("Entity must be a built-in base entity to be flattened");return[d,...(d.properties||[]).flatMap(a=>me(a,u,i)),...(d.methods||[]).flatMap(a=>me(a,u,i)),...(d.abstractMethods||[]).flatMap(a=>me(a,u,i)),...(d.extends||[]).flatMap(a=>me(a,u,i))]}function W5(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.Condition)throw new Error("Entity must be a condition to be flattened");return[d,...(d.inputs||[]).flatMap(a=>me(a,u,i)),...(d.successCalls||[]).flatMap(a=>me(a,u,i)),...(d.errorCalls||[]).flatMap(a=>me(a,u,i)),...(Bs(d)||[]).flatMap(a=>me(a,u,i)),...d.parent?me(d.parent,u,i):[]]}function Y5(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.ContinueStatement)throw new Error("Entity must be a continue statement to be flattened");return[d,...d.outputs.flatMap(a=>me(a,u,i)),...d.throws?me(d.throws,u,i):[],...(Bs(d)||[]).flatMap(a=>me(a,u,i)),...d.parent?me(d.parent,u,i):[]]}function z5(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.DefinitionEntity)throw new Error("Entity must be a definition entity to be flattened");return[d,...(d.extends||[]).flatMap(a=>me(a,u,i)),...(d.implements||[]).flatMap(a=>me(a,u,i)),...(d.properties||[]).flatMap(a=>me(a,u,i)),...(d.methods||[]).flatMap(a=>me(a,u,i)),...(d.abstractMethods||[]).flatMap(a=>me(a,u,i)),...d.parent?me(d.parent,u,i):[]]}function X5(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.DataType)throw new Error("Entity must be a data type to be flattened");return[d,...(d.andChildrenGroup||[]).flatMap(a=>me(a,u,i)),...(d.orChildrenGroup||[]).flatMap(a=>me(a,u,i)),...d.entity?me(d.entity,u,i):[],...d.parent?me(d.parent,u,i):[]]}function Q5(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.FunctionCall)throw new Error("Entity must be a function call to be flattened");return[d,...(d.inputs||[]).flatMap(a=>me(a,u,i)),...(d.outputs||[]).flatMap(a=>me(a,u,i)),...d.error?me(d.error,u,i):[],...d.process?me(d.process,u,i):[],...(Bs(d)||[]).flatMap(a=>me(a,u,i)),...(d.successCalls||[]).flatMap(a=>me(a,u,i)),...(d.errorCalls||[]).flatMap(a=>me(a,u,i)),...d.parent?me(d.parent,u,i):[]]}function eS(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.FunctionDeclaration)throw new Error("Entity must be a function declaration to be flattened");return[d,...(d.inputs||[]).flatMap(a=>me(a,u,i)),...(d.calls||[]).flatMap(a=>me(a,u,i)),...d.implements?me(d.implements,u,i):[],...d.parent?me(d.parent,u,i):[]]}function tS(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.GlobalEvent)throw new Error("Entity must be a global event to be flattened");return[d,...(d.inputs||[]).flatMap(a=>me(a,u,i)),...(d.calls||[]).flatMap(a=>me(a,u,i)),...d.implements?me(d.implements,u,i):[],...d.parent?me(d.parent,u,i):[]]}function rS(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.InputMap)throw new Error("Entity must be an input map to be flattened");return[d,...d.readsValue?me(d.readsValue,u,i):[],...d.declaration?me(d.declaration,u,i):[],...d.defaultValue?me(d.defaultValue,u,i):[],...d.parent?me(d.parent,u,i):[]]}function iS(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.InstalledProject)throw new Error("Entity must be an installed project to be flattened");return[d,...(d.functions||[]).flatMap(a=>me(a,u,i)),...(d.events||[]).flatMap(a=>me(a,u,i)),...d.parent?me(d.parent,u,i):[]]}function sS(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.InternalCall)throw new Error("Entity must be an internal call to be flattened");return[d,...(d.successCalls||[]).flatMap(a=>me(a,u,i)),...(d.errorCalls||[]).flatMap(a=>me(a,u,i)),...(d.inputs||[]).flatMap(a=>me(a,u,i)),...(d.outputs||[]).flatMap(a=>me(a,u,i)),...(Bs(d)||[]).flatMap(a=>me(a,u,i)),...d.error?me(d.error,u,i):[],...d.process?me(d.process,u,i):[],...d.parent?me(d.parent,u,i):[]]}function nS(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.LiteralValue)throw new Error("Entity must be a literal value to be flattened");return[d,...d.valueAsTypeSingle?me(d.valueAsTypeSingle,u,i):[],...d.valueAsTypeList&&Array.isArray(d.valueAsTypeList)?d.valueAsTypeList.flatMap(a=>me(a,u,i)):[],...d.parent?me(d.parent,u,i):[]]}function aS(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.Loop)throw new Error("Entity must be a loop to be flattened");return[d,...(d.inputs||[]).flatMap(a=>me(a,u,i)),...(d.outputs||[]).flatMap(a=>me(a,u,i)),...(d.successCalls||[]).flatMap(a=>me(a,u,i)),...(d.errorCalls||[]).flatMap(a=>me(a,u,i)),...d.error?me(d.error,u,i):[],...d.process?me(d.process,u,i):[],...d.body?me(d.body,u,i):[],...(Bs(d)||[]).flatMap(a=>me(a,u,i)),...d.parent?me(d.parent,u,i):[]]}function oS(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.Operation)throw new Error("Entity must be an operation to be flattened");return[d,...(d.successCalls||[]).flatMap(a=>me(a,u,i)),...(d.errorCalls||[]).flatMap(a=>me(a,u,i)),...(d.inputs||[]).flatMap(a=>me(a,u,i)),...(d.outputs||[]).flatMap(a=>me(a,u,i)),...d.error?me(d.error,u,i):[],...d.process?me(d.process,u,i):[],...(Bs(d)||[]).flatMap(a=>me(a,u,i)),...d.parent?me(d.parent,u,i):[]]}function lS(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.OutputMap)throw new Error("Entity must be an output map to be flattened");return[d,...(d.writesValues||[]).flatMap(a=>me(a,u,i)),...d.declaration?me(d.declaration,u,i):[],...d.defaultValue?me(d.defaultValue,u,i):[],...d.parent?me(d.parent,u,i):[]]}function dS(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.PrimitiveEntity)throw new Error("Entity must be a primitive entity to be flattened");return[d,...(d.properties||[]).flatMap(a=>me(a,u,i)),...(d.methods||[]).flatMap(a=>me(a,u,i)),...(d.abstractMethods||[]).flatMap(a=>me(a,u,i))]}function uS(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.Project)throw new Error("Entity must be a project to be flattened");return[d,...(d.entities||[]).flatMap(a=>me(a,u,i)),...(d.functions||[]).flatMap(a=>me(a,u,i)),...(d.events||[]).flatMap(a=>me(a,u,i)),...(d.projects||[]).flatMap(a=>me(a,u,i)),...(d.variableDeclarations||[]).flatMap(a=>me(a,u,i)),...(d.variableInstances||[]).flatMap(a=>me(a,u,i)),...(d.operations||[]).flatMap(a=>me(a,u,i)),...(d.conditions||[]).flatMap(a=>me(a,u,i)),...(d.functionCalls||[]).flatMap(a=>me(a,u,i)),...(d.projects||[]).flatMap(a=>me(a,u,i)),...(d.loops||[]).flatMap(a=>me(a,u,i)),...(d.searches||[]).flatMap(a=>me(a,u,i))]}function cS(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.Property)throw new Error("Entity must be a property to be flattened");return[d,...d.defaultValue?me(d.defaultValue,u,i):[],...d.dataType?me(d.dataType,u,i):[],...d.parent?me(d.parent,u,i):[]]}function pS(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.ReturnDeclaration)throw new Error("Entity must be a return declaration to be flattened");return[d,...d.readsValue?me(d.readsValue,u,i):[],...d.defaultValue?me(d.defaultValue,u,i):[],...d.dataType?me(d.dataType,u,i):[],...d.parent?me(d.parent,u,i):[]]}function fS(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.ReturnStatement)throw new Error("Entity must be a return statement to be flattened");return[d,...(d.outputs||[]).flatMap(a=>me(a,u,i)),...d.throws?me(d.throws,u,i):[],...(Bs(d)||[]).flatMap(a=>me(a,u,i)),...d.parent?me(d.parent,u,i):[]]}function hS(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.Search)throw new Error("Entity must be a search to be flattened");return[d,...(d.successCalls||[]).flatMap(a=>me(a,u,i)),...(d.errorCalls||[]).flatMap(a=>me(a,u,i)),...(d.inputsDeclarations||[]).flatMap(a=>me(a,u,i)),...(d.inputs||[]).flatMap(a=>me(a,u,i)),...(d.outputsDeclarations||[]).flatMap(a=>me(a,u,i)),...(d.outputs||[]).flatMap(a=>me(a,u,i)),...d.error?me(d.error,u,i):[],...(Bs(d)||[]).flatMap(a=>me(a,u,i)),...d.parent?me(d.parent,u,i):[]]}function yS(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.ValueDescriptor)throw new Error("Entity must be a value descriptor to be flattened");return[d,...d.defaultValue?me(d.defaultValue,u,i):[],...d.dataType?me(d.dataType,u,i):[],...d.parent?me(d.parent,u,i):[]]}function mS(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.VariableDeclaration)throw new Error("Entity must be a variable declaration to be flattened");return[d,...(d.successCalls||[]).flatMap(a=>me(a,u,i)),...(d.errorCalls||[]).flatMap(a=>me(a,u,i)),...(d.inputs||[]).flatMap(a=>me(a,u,i)),...(d.outputs||[]).flatMap(a=>me(a,u,i)),...(d.internalCalls||[]).flatMap(a=>me(a,u,i)),...(d.writesValues||[]).flatMap(a=>me(a,u,i)),...d.readsValue?me(d.readsValue,u,i):[],...d.defaultValue?me(d.defaultValue,u,i):[],...(Bs(d)||[]).flatMap(a=>me(a,u,i)),...d.dataType?me(d.dataType,u,i):[],...d.parent?me(d.parent,u,i):[]]}function vS(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(d.id))return[];if(u.add(d.id),d.type!==f.VariableInstance)throw new Error("Entity must be a variable instance to be flattened");return[d,...(d.successCalls||[]).flatMap(a=>me(a,u,i)),...(d.errorCalls||[]).flatMap(a=>me(a,u,i)),...(d.inputs||[]).flatMap(a=>me(a,u,i)),...(d.outputs||[]).flatMap(a=>me(a,u,i)),...(d.internalCalls||[]).flatMap(a=>me(a,u,i)),...(d.writesValues||[]).flatMap(a=>me(a,u,i)),...d.readsValue?me(d.readsValue,u,i):[],...d.defaultValue?me(d.defaultValue,u,i):[],...(Bs(d)||[]).flatMap(a=>me(a,u,i)),...d.declaration?me(d.declaration,u,i):[],...d.parent?me(d.parent,u,i):[]]}function Xs(){const d=new Set,u=E2.flatMap(i=>me(i,d)).map(i=>i.id);if(!u.includes("http-request-error-return-delaration-id"))throw new Error("Built-in base entities must be included in the list");return u}function me(d,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(!d)throw new Error("Entity must be defined to be flattened");if(d.type===f.GenericReference)return[];if(i.ignoreBuiltInBaseEntities&&(Wi.includes(d.type)||Xs().includes(d.id)))return[];if(u.has(d.id))return[];switch(d.type){case f.FunctionCall:return Q5(d,u,i);case f.Operation:return oS(d,u,i);case f.Condition:return W5(d,u,i);case f.Loop:return aS(d,u,i);case f.Search:return hS(d,u,i);case f.GlobalEvent:return tS(d,u,i);case f.ReturnStatement:return fS(d,u,i);case f.ContinueStatement:return Y5(d,u,i);case f.BreakStatement:return J5(d,u,i);case f.VariableDeclaration:return mS(d,u,i);case f.DefinitionEntity:return z5(d,u,i);case f.FunctionDeclaration:return eS(d,u,i);case f.Project:return uS(d,u,i);case f.ActionDescriptor:return q5(d,u,i);case f.ArgumentDeclaration:return Z5(d,u,i);case f.ReturnDeclaration:return pS(d,u,i);case f.ValueDescriptor:return yS(d,u,i);case f.InputMap:return rS(d,u,i);case f.OutputMap:return lS(d,u,i);case f.DataType:return X5(d,u,i);case f.InstalledProject:return iS(d,u,i);case f.InternalCall:return sS(d,u,i);case f.LiteralValue:return nS(d,u,i);case f.Property:return cS(d,u,i);case f.VariableInstance:return vS(d,u,i);case f.BuiltInBaseEntity:return i.ignoreBuiltInBaseEntities?[]:H5(d,u,i);case f.PrimitiveEntity:return i.ignoreBuiltInBaseEntities?[]:dS(d,u,i)}return[]}function Sb(d){return d.type===f.FunctionCall||d.type===f.InternalCall||[f.Operation,f.Condition,f.Loop].includes(d.type)?d.declaration.inputs:d.type===f.FunctionDeclaration||So.includes(d.type)?d.inputs:d.type===f.Search?d.inputsDeclarations:[]}function iAe(d,u){return u.type===f.Condition?u.inputs.find(i=>i.declaration.id===d.id):u.type===f.FunctionCall||u.type===f.Operation?u.inputs.find(i=>i.declaration.id===d.id):null}function ES(d){return fr.includes(d.type)?d.inputs:[]}function TS(d){var u;return d.type===f.FunctionCall?((u=d.declaration.returnStatements[0])==null?void 0:u.outputs)||[]:[f.Operation,f.Condition,f.Loop].includes(d.type)?d.declaration.outputs:d.type===f.Search?d.outputsDeclarations:Tr.includes(d.type)?d.outputs:[]}function sAe(d,u){return u.type===f.Condition?null:u.type===f.FunctionCall||u.type===f.Operation?u.outputs.find(i=>i.declaration.id===d.id):null}function nAe(d){return d.type===f.Condition?[]:fr.includes(d.type)?d.outputs:[]}function Pm(d){const u=d.readsValue;return u?Er(u):null}function IS(d,u){const i=d.readsValue;return i?Dm(i,u):null}function AS(d){const u=d.internalCalls||[];return R(ti(R(u.flatMap(i=>[...i.successCalls,...i.errorCalls]))))}function bS(d){const u=d.internalCalls||[];return R(R(u.flatMap(i=>[...i.successCalls,...i.errorCalls])))}function Xd(d){const u=Cm(d),i=[];return u.forEach(a=>{if(mt.includes(a.type))i.push(a);else if(cn.includes(a.type)){const o=Er(a.parent);i.push(o)}}),i}function Qd(d){const u=Cm(d),i=[];return u.forEach(a=>{if(mt.includes(a.type))i.push(a);else if(cn.includes(a.type)){const o=a.parent;i.push(o)}}),i}function R(d){const u=new Set;return d.filter(i=>!i||u.has(i.id)?!1:(u.add(i.id),!0))}function wS(d){return d.type===f.Project?null:jv.includes(d.type)?d:Wi.includes(d.type)?null:d.parent?wS(d.parent):null}function Rn(d,u=!1){const i=[];if(d.type===f.Project&&i.push(...(d==null?void 0:d.entities)||[],...(d==null?void 0:d.functions)||[],...(d==null?void 0:d.variableDeclarations)||[],...(d==null?void 0:d.variableInstances)||[],...(d==null?void 0:d.searches)||[],...(d==null?void 0:d.loops)||[],...(d==null?void 0:d.operations)||[],...(d==null?void 0:d.conditions)||[],...(d==null?void 0:d.functionCalls)||[],...(d==null?void 0:d.events)||[],...(d==null?void 0:d.projects)||[]),Mr.includes(d.type)&&i.push(...(d==null?void 0:d.detachedChildren)||[]),d.type===f.DefinitionEntity){const a=[...d.suggestedMethods,...d.methods].flatMap(o=>o.collapsed&&u?[]:Rn(o));i.push(...a)}if(d.type===f.Condition){const a=d.successCalls.map(p=>Er(p)),o=d.errorCalls.map(p=>Er(p));i.push(...a,...o)}if(So.includes(d.type)){if(d.collapsed&&u)return[];const a=d.inputs.map(p=>Xd(p)).flat(),o=d.calls.map(p=>Er(p));i.push(...R(a),...o)}if(fr.includes(d.type)&&d.type!==f.Condition&&d.type!==f.Loop){const a=d==null?void 0:d.outputs.map(e=>Xd(e)).flat(),o=d.successCalls.map(e=>Er(e)),p=d.errorCalls.map(e=>Er(e));i.push(...R(a),...o,...p)}if(mt.includes(d.type)){const a=Xd(d),o=AS(d);i.push(...a,...o)}if(d.type===f.Loop){const a=d.outputs.map(e=>Xd(e)).flat();if(d.body){const e=Rn(d.body,u);i.push(...e)}const o=d.errorCalls.map(e=>Er(e)),p=d.successCalls.map(e=>Er(e));i.push(...R(a),...p,...o)}if(d.type===f.FunctionDeclaration){if(d.collapsed&&u)return[];const a=d.inputs.map(p=>Xd(p)).flat(),o=d.calls.map(p=>Er(p));i.push(...R(a),...o)}return R(i)}function Nm(d,u=!1){const i=[];if(d.type===f.Project&&i.push(...(d==null?void 0:d.variableDeclarations)||[],...(d==null?void 0:d.variableInstances)||[],...(d==null?void 0:d.searches)||[],...(d==null?void 0:d.loops)||[],...(d==null?void 0:d.operations)||[],...(d==null?void 0:d.conditions)||[],...(d==null?void 0:d.functionCalls)||[]),Mr.includes(d.type)&&i.push(...(d==null?void 0:d.detachedChildren)||[]),d.type===f.DefinitionEntity){const a=[...d.suggestedMethods,...d.methods].flatMap(o=>o.collapsed&&u?[]:Nm(o));i.push(...a)}if(d.type===f.Condition){const a=d.successCalls,o=d.errorCalls;i.push(...a,...o)}if(So.includes(d.type)){if(d.collapsed&&u)return[];const a=d.inputs.map(p=>Qd(p)).flat(),o=d.calls;i.push(...R(a),...o)}if(fr.includes(d.type)&&d.type!==f.Condition&&d.type!==f.Loop){const a=d==null?void 0:d.outputs.map(e=>Qd(e)).flat(),o=d.successCalls,p=d.errorCalls;i.push(...R(a),...o,...p)}if(mt.includes(d.type)){const a=Qd(d),o=bS(d);i.push(...a,...o)}if(d.type===f.Loop){const a=d.outputs.map(e=>Qd(e)).flat();if(d.body){const e=Nm(d.body,u);i.push(...e)}const o=d.errorCalls,p=d.successCalls;i.push(...R(a),...p,...o)}if(d.type===f.FunctionDeclaration){if(d.collapsed&&u)return[];const a=d.inputs.map(p=>Qd(p)).flat(),o=d.calls;i.push(...R(a),...o)}return R(i)}function Vm(d,u=!1){const i=Rn(d,u),a=[...i,...i.reduce((o,p)=>[...o,...Vm(p,u)],[])];return R(a)}function RS(d,u=!1){const i=Nm(d,u),a=[...i,...i.reduce((o,p)=>[...o,...RS(p,u)],[])];return R(a)}function _S(d){const u=bo(d),i=[...u,...u.reduce((a,o)=>[...a,..._S(o)],[])];return R(i)}function tf(d){return d.implements.reduce((u,i)=>i.type===f.DefinitionEntity?[...u,f.DefinitionEntity,...tf(i),...rf(i)]:[...u,i.name],[])}function rf(d){return d.extends.reduce((u,i)=>i.type===f.DefinitionEntity?[...u,f.DefinitionEntity,...rf(i),...tf(i)]:[...u,i.name],[])}function Kb(d){return d.extends.reduce((u,i)=>i.type===f.DefinitionEntity?[...u,i,...Kb(i),...kb(i)]:[...u,i],[])}function kb(d){return d.implements.reduce((u,i)=>i.type===f.DefinitionEntity?[...u,i,...kb(i),...Kb(i)]:[...u,i],[])}function eu(d){return[...rf(d),...tf(d)].filter((i,a,o)=>o.indexOf(i)===a)}function qb(d){return d.implements.length===0&&d.extends.length===0?null:d.implements.find(a=>a.type===f.BuiltInBaseEntity&&a.name===Ue.PERSISTED_ENTITY)?d:[...d.implements,...d.extends].reduce((a,o)=>{if(o.type===f.DefinitionEntity){const p=qb(o);if(p)return p}return a},null)}function aAe(d){const u=d.extends.find(i=>i.type===f.BuiltInBaseEntity);return u&&u.type===f.BuiltInBaseEntity?u:null}function oAe(d){const u=d.implements.find(i=>i.type===f.BuiltInBaseEntity);return u&&u.type===f.BuiltInBaseEntity?u:null}function Lm(d){const u=d.extends.find(i=>i.type===f.DefinitionEntity);return u&&u.type===f.DefinitionEntity?u:null}function Bi(d){if(d.type===f.BuiltInBaseEntity)return[d];const u=[...d.implements,...d.extends].reduce((i,a)=>a.type===f.BuiltInBaseEntity?[...i,a]:a.type===f.DefinitionEntity?[...i,...Bi(a)]:i,[]);return R(u)}function sf(d){return d.type===f.PrimitiveEntity?!0:d.type===f.BuiltInBaseEntity?d.interactive:!Bi(d).find(a=>!a.interactive)}function lAe(d){return d.parent===d.project&&d.project.variableDeclarations.includes(d)}function Zb(d){return d.parent!==d.project?!1:f.VariableDeclaration===d.type?d.project.variableDeclarations.includes(d):f.VariableInstance===d.type?d.project.variableInstances.includes(d):f.FunctionCall===d.type?d.project.functionCalls.includes(d):f.Condition===d.type?d.project.conditions.includes(d):f.Operation===d.type?d.project.operations.includes(d):f.Loop===d.type?d.project.loops.includes(d):f.Search===d.type?d.project.searches.includes(d):!1}function gS(d){if([...Pt,f.DefinitionEntity,f.InstalledProject,f.Project].includes(d.type)||Zb(d))return!1;const u=bo(d);return u.length===0?!0:u.some(i=>gS(i))}function Jb(d){return[...Pt,f.DefinitionEntity,f.InstalledProject,f.Project].includes(d.type)||Zb(d)?!1:bo(d).length===0}function DS(d,u=0){if(Jb(d)){const i=bo(d);return i.length===0?d:i.map(o=>DS(o,u+1)).reduce((o,p)=>o?p&&p.x<o.x?p:o:p,null)}return null}function OS(d){const u=[];if(Jb(d))u.push(d);else return[];return bo(d).forEach(a=>{u.push(...OS(a))}),u}function Hb(d){return d.type===f.FunctionDeclaration&&d.parent!==d.project&&!![f.DefinitionEntity,f.Loop,f.InstalledProject].includes(d.parent.type)}function dAe(d,u){const i=new Map;return d.forEach(a=>{i.set(a.id,a)}),u.forEach(a=>{i.set(a.id,a)}),Array.from(i.values())}function nf(d){switch(d){case f.DefinitionEntity:return ra;case f.FunctionDeclaration:return io;case f.VariableDeclaration:return uo;case f.VariableInstance:return lo;case f.FunctionCall:return Ao;case f.Operation:return so;case f.Condition:return oo;case f.ReturnStatement:return no;case f.Loop:return Ki;case f.Search:return co;case f.InputMap:return Yn;case f.OutputMap:return vn;case f.ArgumentDeclaration:return Jn;case f.ReturnDeclaration:return is;case f.Property:return ta;case f.InstalledProject:return po;case f.Project:return N;case f.DataType:return vs;case f.GlobalEvent:return ao;case f.InternalCall:return fo;case f.ValueDescriptor:return En;case f.BuiltInBaseEntity:return ia;case f.PrimitiveEntity:return ss;case f.ActionDescriptor:return wt;case f.LiteralValue:return qi;case f.ContinueStatement:return Vi;case f.BreakStatement:return ho;default:return null}}function Ji(d,u,i=null){const a=d!=null&&d.parent?J(d==null?void 0:d.parent):null;let o=a?u.get(a):null,p=i||d;if((d==null?void 0:d.id)===(u==null?void 0:u.id))return u;if(d.type===f.ReturnStatement)return Wr(d,u,p);if(d.type===f.FunctionDeclaration&&(o==null?void 0:o.type)===f.Loop)return o;if(Pt.includes(d.type))return d;if(d.type===f.Loop)return p.id===d.id?o:d;if(Wi.includes(d.type))return null;const e=d.parent;if(!e)return null;if(e.type===f.GenericReference){const y=J(e);if(!y)return null;const v=u.get(y);return v?Ji(v,u,p):null}else return e===u?u:Ji(e,u,p)}function Wr(d,u,i=null){const a=d!=null&&d.parent?J(d==null?void 0:d.parent):null;let o=a?u.get(a):null,p=i||d;if(d.type===f.FunctionDeclaration&&(o==null?void 0:o.type)===f.Loop)return Wr(o.parent,u,p);if(Pt.includes(d.type))return d;if(Wi.includes(d.type))return null;const e=d.parent;if(!e)return null;if(e.type===f.GenericReference){const y=J(e);if(!y)return null;const v=u.get(y);return v?Wr(v,u,p):null}else return e===u?u:Wr(e,u,p)}function af(d,u){if(Wi.includes(d.type)||u.getBuiltIn(d.id))return null;const i=Hi(d.parent,u);return i?i===u?Mr.includes(d.type)?d:null:i.type===f.DefinitionEntity?d:af(i,u):null}function Mm(d,u,i){if(d===u||u===i||d===i||!d||!u)return!1;const a=Ji(u.parent,i);return a===i?!1:a===d?!0:Mm(a,u,i)}var Bm=(d=>(d.SameBothLocal="same-both-local",d.AInB="a-in-b",d.BInA="b-in-a",d.ParallelInCommonParent="parallel-in-common-parent",d.ParallelInProject="parallel-in-project",d.AIsGlobalBIsNot="a-is-global-b-is-not",d.BIsGlobalAIsNot="b-is-global-a-is-not",d.SameBothGlobal="same-both-global",d))(Bm||{});function Qs(d,u,i){const a=Ji(d,i),o=Ji(u,i);if(!a)throw new Error("Could not find scope owner for the entity: "+d.id);if(!o)throw new Error("Could not find scope owner for the entity: "+u.id);if(a===o&&a.type!==f.Project)return{compatible:!0,type:"same-both-local",commonAncestorScope:a};if(a===o&&a.type===f.Project)return{compatible:!0,type:"same-both-global",commonAncestorScope:a};if(a.type===f.Project&&o.type!==f.Project)return{compatible:!1,type:"a-is-global-b-is-not",commonAncestorScope:a};if(a.type!==f.Project&&o.type===f.Project)return{compatible:!1,type:"b-is-global-a-is-not",commonAncestorScope:o};if(Mm(a,o,i))return{compatible:!0,type:"b-in-a",commonAncestorScope:a};if(Mm(o,a,i))return{compatible:!0,type:"a-in-b",commonAncestorScope:o};const y=Gb(a,o);return y===i?{compatible:!1,type:"parallel-in-project",commonAncestorScope:y}:y?{compatible:!1,type:"parallel-in-common-parent",commonAncestorScope:Ji(y,i)}:{compatible:!1,type:"parallel-in-project",commonAncestorScope:i}}function CS(d,u,i){const a=Qs(d,u,i);if(!a.compatible||a.type!=="same-both-local")return null;if(d===u)return d;let o=Ji(d.parent,i);if(o){if(o===u)return u;if(o.type===f.Project)return d}else return d;for(;o;){if(o){if(o===u)return u;if(o.type===f.Project)return d}else return d;o=Ji(o.parent,i)}let p=Ji(u.parent,i);if(p){if(p===d)return d;if(p.type===f.Project)return u}else return u;for(;p;){if(p){if(p===d)return d;if(p.type===f.Project)return u}else return u;p=Ji(p.parent,i)}return null}function $S(d){return d.length===0?null:d.length===1?d[0]:d.reduce((i,a)=>{const o=CS(i,a,a.project);return!o||o===a?i:a},d[0])}function Hi(d,u){if(!d)return null;let i;return typeof d=="string"?i=d:d.type===f.GenericReference?i=J(d):i=d.id,i===u.id?u:u.get(i)}function wo(d){if(!d)return null;if(Wi.includes(d.type))return d;if(d.type===f.Project)return null;if(d.project.getBuiltIn(d.id))return d;const u=d.parent;return!u||u.type===f.Project?null:wo(u)}function of(d){const u=[];function i(p,e){return u.some(y=>y.blockedByCaller===p&&y.blockedByCalling===e)}function a(p,e){i(p,e)||u.push({blockedByCaller:p,blockedByCalling:e})}const o=af(d,d.project);return d.calledBySuccess.forEach(p=>{[...p.successCalls||[]].forEach(v=>{Tr.includes(v.type)&&v!==d&&(Rt(d).find(A=>A===v)||a(p,v))});let y;if(fr.includes(p.type)&&(y=p),y){const v=of(y);v.reachable||Rt(d).find(A=>A===p)||v.blocks.forEach(A=>{a(p,A.blockedByCalling)})}}),d.calledByError.forEach(p=>{[...p.errorCalls||[]].forEach(v=>{Tr.includes(v.type)&&v!==d&&(Rt(d).find(A=>A===v)||a(p,v))});let y;if(fr.includes(p.type)&&(y=p),y){const v=of(y);v.reachable||Rt(d).find(A=>A===p)||v.blocks.forEach(A=>{a(p,A.blockedByCalling)})}}),d.calledByEntry.forEach(p=>{if([...p.calls||[]].forEach(v=>{Tr.includes(v.type)&&v!==d&&(Rt(d).find(A=>A===v)||a(p,v))}),p===o)return;let y;if(p.type===f.FunctionDeclaration){const v=Er(p);if(v.type===f.DefinitionEntity)return;v.type===f.Loop&&(y=v)}if(y){const v=of(y);v.reachable||v.blocks.forEach(E=>{a(p,E.blockedByCalling)})}}),{reachable:u.length===0,entryPoint:o,blocks:u}}function uAe(d){return ih.includes(d.type)?d.type===f.FunctionDeclaration?!Hb(d):!0:!1}function cAe(d){if(f.ActionDescriptor===d.type){if(d.project.operationDeclarations.find(p=>p.id===d.id))return f.Operation;if(d.project.globalEventActionDescriptors.find(p=>p.id===d.id))return f.GlobalEvent;if(d.project.loopDeclarations.find(p=>p.id===d.id))return f.Loop;if(d.project.conditionDeclarations.find(p=>p.id===d.id))return f.Condition}return d.type}function Um(d,u){return d.type===f.BuiltInBaseEntity?d.name===u:!!rf(d).includes(u)}function pAe(d,u){return d.type===f.BuiltInBaseEntity?d.name===u:!!tf(d).includes(u)}function As(d,u){return d.type===f.BuiltInBaseEntity?d.name===u:!!eu(d).includes(u)}function fAe(d){const u=[];return d.entities.forEach(i=>{if(Um(i,Ue.PERSISTED_ENTITY)){u.push(i);return}}),R(u)}function hAe(d){const u=[];return d.entities.forEach(i=>{if(Um(i,Ue.RELATIONAL_DATABASE)){u.push(i);return}}),R(u)}function yAe(d){return d.type!==f.DefinitionEntity||d.abstract||!Um(d,Ue.PERSISTED_ENTITY)?null:(d==null?void 0:d.properties.find(i=>{var a;return((a=i.implements)==null?void 0:a.id)===Ee[f.BuiltInBaseEntity][Ue.PERSISTED_ENTITY].properties.primaryKey.id&&!i.abstract}))||null}function PS(d){var a;const u=qb(d);if(!u)return null;const i=u.properties.find(o=>{var p;return((p=o.implements)==null?void 0:p.id)===Ee[f.BuiltInBaseEntity][Ue.PERSISTED_ENTITY].properties.database.id});return i?(a=i.getDefaultValue())==null?void 0:a.valueAsType:null}function tu(d){if(d.type!==f.DefinitionEntity)return[];if(d.abstract)return[];if(!As(d,Ue.PERSISTED_ENTITY))return[];const u=[],i=d.properties.filter(a=>{var o;return((o=a.implements)==null?void 0:o.id)!==Ee[f.BuiltInBaseEntity][Ue.PERSISTED_ENTITY].properties.database.id&&!a.abstract});return u.push(...i),u}function mAe(d){var i;if(!d||d.type!==f.DefinitionEntity||!As(d,Ue.PERSISTED_ENTITY))return null;const u=d.properties.find(a=>{var o;return((o=a.implements)==null?void 0:o.id)===Ee[f.BuiltInBaseEntity][Ue.PERSISTED_ENTITY].properties.database.id});return(i=u==null?void 0:u.getDefaultValue())==null?void 0:i.valueAsTypeSingle}function Gr(d,u){var a;if(!Cg.includes(u.type)||!d)return u.project||null;let i=u.project;return d.type===f.Project?i=d:((a=u.project)==null?void 0:a.id)!==d.project.id&&(i=d.project),i}function vAe(d){switch(d){case f.Project:return N;case f.InstalledProject:return po;case f.DefinitionEntity:return ra;case f.FunctionDeclaration:return io;case f.GlobalEvent:return ao;case f.VariableInstance:return lo;case f.VariableDeclaration:return uo;case f.InputMap:return Yn;case f.OutputMap:return vn;case f.Condition:return oo;case f.Operation:return so;case f.FunctionCall:return Ao;case f.ReturnDeclaration:return is;case f.ArgumentDeclaration:return Jn;case f.PrimitiveEntity:return ss;case f.DataType:return vs;case f.Property:return ta;case f.ActionDescriptor:return wt;case f.ReturnStatement:return no;case f.ContinueStatement:return Vi;case f.BreakStatement:return ho;case f.Loop:return Ki;case f.Search:return co;case f.ValueDescriptor:return En;case f.InternalCall:return fo;case f.LiteralValue:return qi}return null}function EAe(d){const u={added:{},updated:{},removed:{},affected:[],seenEntities:[],self:d==null?void 0:d.self};return d==null||d.added.forEach(i=>{u.added[i.id]=i}),d==null||d.updated.forEach(i=>{u.updated[i.id]=i}),d==null||d.removed.forEach(i=>{u.removed[i.id]=i}),u.affected=Array.from(new Set(d==null?void 0:d.affected.map(i=>i.id))),u}function Ur(d,u){const i=nf(d.type);return i?!i.MUTABLE_META_PROPERTIES.every(o=>{const p=d[o],e=u[o];return e===void 0||p===e?!0:Array.isArray(p)&&Array.isArray(e)?p.length!==e.length?!1:p.every((y,v)=>y===e[v]):!1}):!1}function jm(d,u={}){if(d.type===f.Project)return[];if(!d.parent)return[];const i=J(d.parent);if(!i)return[];const a=u[i];return a?[a.id,...jm(a,u)]:[]}function TAe(d){const u=[],i=new Set;return[...d.listAdded,...d.listUpdated,...d.listAffected].forEach(a=>{const o=Er(a);!o||i.has(o.id)||(i.add(o.id),u.push(o))}),R(u)}function IAe(d){if(d.type===f.Condition)return null;if(d.type===f.Search)return d.project.getBuiltIn(Ee["value-descriptor"][ed.SearchErrorOutputDescriptor].id)||null;if(d.type===f.Operation)return d.declaration.error;if(d.type===f.FunctionCall){const i=d.declaration.returnStatements.find(a=>!!a.throws);return(i==null?void 0:i.throws)||null}return null}function NS(d){const u=d.entities.filter(o=>!!o.implements.find(p=>p.id===Ee["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.id)),i=u.find(o=>{const p=o.properties.find(v=>v.implements&&v.implements.id===Ee["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.default.id),e=p==null?void 0:p.getDefaultValue();return(e==null?void 0:e.value)===!0});return i||u[0]||null}function Wb(d,u){const i=Array.from(new Set([...u.getAllBuiltInIds(),...Xs()]));return!!(i.includes(d.id)||!jm(d,{...u.instances,...u.builtInInstances}).every(p=>!i.includes(p)))}function VS(d){if(!d)return null;if(d.type===f.Project)return d.id;const u=d.parent;return u?VS(u):d.id}function lf(d){if(d.declaration&&d.declaration.type===f.Property){if(d.declaration.interactive){if(d.declaration.implements&&!d.declaration.implements.interactive)return!1;if(d.declaration.extends&&!d.declaration.extends.interactive)return!1}else return!1;if(d.declaration.private){const u=Er(d),i=af(u,d.project);if((i==null?void 0:i.type)===f.FunctionDeclaration&&(i==null?void 0:i.parent.type)===f.DefinitionEntity&&(i==null?void 0:i.parent.id)!==d.declaration.parent.id)return!1}}return!0}function Yb(d){if(d.interactive){if(d.implements&&!d.implements.interactive)return!1;if(d.extends&&!d.extends.interactive)return!1}else return!1;if(d.private){const u=Er(d),i=af(u,d.project);if((i==null?void 0:i.type)===f.FunctionDeclaration&&(i==null?void 0:i.parent.type)===f.DefinitionEntity&&(i==null?void 0:i.parent.id)!==d.parent.id)return!1}return!0}function AAe(d,u,i){const a=u,o=i,p=!!i,e=[];return a.forEach(y=>{var v;if(p){const E=Qs(o,y,d);if(!E.compatible&&E.type!=="b-is-global-a-is-not")return;e.push(y)}else{if(((v=y.parent)==null?void 0:v.type)!==f.Project)return;e.push(y)}}),R(e)}function xm(d){return d.replace(/["'`]/g,"")}function jr(d){const i=xm(d).split(/[\s-]+/).filter(e=>e.length>0);if(i.length===0)return"";const a=i[0],o=a[0].toLowerCase()+a.slice(1),p=i.slice(1).map(e=>e[0].toUpperCase()+e.slice(1));return[o,...p].join("")}function ru(d){return xm(d).split(/[\s-]+/).filter(a=>a.length>0).map(a=>a[0].toUpperCase()+a.slice(1)).join("")}function LS(d){const u=xm(d).trim();if(!u)return"";const i=u.replace(/[\s_-]+/g," ").split(" ").filter(Boolean),a=[];for(const o of i){let p=o;p=p.replace(/([A-Z]+)([A-Z][a-z]+)/g,"$1-$2"),p=p.replace(/([a-z0-9])([A-Z][a-z0-9]*)/g,"$1-$2"),p=p.replace(/([0-9])([a-zA-Z]+)/g,"$1-$2"),p=p.replace(/([a-zA-Z])([0-9])/g,"$1-$2");for(const e of p.split("-"))e&&a.push(e)}return a.join("-")}function bAe(d){const u=xm(d).trim();if(!u)return"";const i=u.replace(/[\s_-]+/g," ").split(" ").filter(Boolean),a=[];for(const o of i){let p=o;p=p.replace(/([A-Z]+)([A-Z][a-z]+)/g,"$1_$2"),p=p.replace(/([a-z0-9])([A-Z][a-z0-9]*)/g,"$1_$2"),p=p.replace(/([0-9])([a-zA-Z]+)/g,"$1_$2"),p=p.replace(/([a-zA-Z])([0-9])/g,"$1_$2");for(const e of p.split("_"))e&&a.push(e)}return a.join("_")}function Fm(d){return LS(d).toLowerCase()}function iu(d){var i,a,o,p;if(!d)return"Any data type";let u="";if(d.interactiveEntities===!1?u+=` but only definition nodes ${d.asType?"as template ":""}that don't include non-interactive built-in functionality`:d.interactiveEntities===!0&&(u+=` but only definition nodes ${d.asType?"as template ":""}that extend or implement interactive built-in functionality`),d.staticEntities===!1?u?u+=" and that aren't a single global copy instance":u+=` but only definition nodes ${d.asType?"as template ":""}that aren't a single global copy instance`:d.staticEntities===!0&&(u?u+=" and that are a single global copy instance":u+=` but only definition nodes ${d.asType?"as template ":""}that are a single global copy instance`),d.actionEntities===!1?u?u+=" excluding executable/action nodes":u+=` excluding executable/action nodes ${d.asType?"templates ":""}`:d.actionEntities===!0&&(u?u+=" and not executable/action nodes":u+=" but not executable/action nodes"),d.entity&&(u=""),d.asType&&!u&&!((i=d.andChildrenGroup)!=null&&i.length)&&!((a=d.orChildrenGroup)!=null&&a.length)&&(u=" as template"),!d.entity){const e=d.isList;if(!((o=d.andChildrenGroup)!=null&&o.length)&&!((p=d.orChildrenGroup)!=null&&p.length))return e?`List of an any data type${u}`:`Any data type${u}`;let y="",v=!1,E=!1;return(d.andChildrenGroup||[]).forEach(b=>{const A=iu(b),$=Dd(A);v&&(y+=" and "),b.isGroup?y+="("+$+")":v?y+=$:y+=A,v=!0,E=!0}),(d.orChildrenGroup||[]).forEach(b=>{const A=iu(b),$=Dd(A);v&&(E&&(y+=","),y+=" or "),b.isGroup?y+="("+$+")":v?y+=$:y+=A,v=!0}),e?`List of ${Dd(y)}`:y}if(d.entity.type===f.PrimitiveEntity){let e=d.entity.name;switch(d.entity.name){case Q.String:e="Text";break;case Q.KeyValue:e="Data structure";break}return d.isList?`List of ${e}s${u}`:`${e.slice(0,1).toUpperCase()}${e.slice(1)}${u}`}else if(d.entity.type===f.DefinitionEntity){const e=ne(d.entity,d.project);return d.isList?`List of ${e} values${u}`:e.slice(0,1).toUpperCase()+e.slice(1)+u}else if(d.entity.type===f.BuiltInBaseEntity){const e=BS(d.entity);return d.isList?`List of ${e} values${u}`:e.slice(0,1).toUpperCase()+e.slice(1)+u}else if(d.entity.type===f.LiteralValue){if(d.entity.name===Q.Null)return"Empty value";if(d.entity.name===Q.Untyped)return"Untyped value";if(d.entity.name===Q.File)return"File";if(d.entity.name===Q.String)return`"${d.entity.value}" text`;if(d.entity.name===Q.Number)return`Number '${d.entity.value}'`;if(d.entity.name===Q.Boolean)return`${d.entity.value} value`;if(d.entity.name===Q.UUID)return`"${d.entity.value}" unique identifier`;if(d.entity.name===Q.Date)return`"${d.entity.value}" date`}return d.isList?`List of ${ne(d.entity,d.project)} values${u}`:`${ne(d.entity,d.project).slice(0,1).toUpperCase()+ne(d.entity,d.project).slice(1)} value${u}`}function wAe(d){if(!d)return"Any data type";const u=d.getDataType(null);return iu(u)}function Gm(d){switch(d.declaration.id){case _r.Equal:return"is equal to";case _r.NotEqual:return"is not equal to";case _r.MoreThan:return"is greater than";case _r.MoreThanOrEqual:return"is greater than or equal to";case _r.LessThan:return"is less than";case _r.LessThanOrEqual:return"is less than or equal to";case _r.And:return"and";case _r.Or:return"or";case zr.Empty:return"is empty";case zr.NotEmpty:return"is present"}}function MS(d){return d.includes(Ue.HTTP_ENDPOINT)?"HTTP endpoint":d.includes(Ue.PERSISTED_ENTITY)?"Persisted entity":d.includes(Ue.CRON_JOB)?"Scheduled execution":d.includes(Ue.RELATIONAL_DATABASE)?"Relational database":"Entity"}function BS(d){switch(d.name){case Ue.HTTP_ENDPOINT:return"HTTP endpoint";case Ue.PERSISTED_ENTITY:return"Persisted entity";case Ue.CRON_JOB:return"Scheduled execution";case Ue.RELATIONAL_DATABASE:return"Relational database"}return"Entity"}function RAe(d){const u=Lm(d);if(!u){const i=eu(d);return i.includes(Ue.HTTP_ENDPOINT)?"HTTP endpoint":i.includes(Ue.PERSISTED_ENTITY)?"Persisted entity":i.includes(Ue.CRON_JOB)?"Scheduled execution":i.includes(Ue.RELATIONAL_DATABASE)?"Relational database":ne(d,d.project)+" entity"}return ne(u,d.project)+" entity"}function US(d){let u="Find ";return d.outputsDeclarations.forEach((i,a)=>{const o=Sy(i,null),p=Dd(o&&o.entity?ne(o.entity,d.project):"unstructured data");a===0?u+=`${p} `:a===d.outputsDeclarations.length-1?u+=`and ${p} `:u+=`, ${p} `}),u}function jS(d){switch(d.name){case Q.String:return"Text";case Q.Number:return"Number";case Q.Boolean:return"Boolean";case Q.KeyValue:return"Data structure";case Q.UUID:return"Unique identifier";case Q.Date:return"Date";case Q.EntityTemplate:return"Entity as template";case Q.Enum:return"Enumeration";case Q.File:return"File";case Q.Null:return"Empty";case Q.ActionDescriptor:return"Action descriptor";case Q.Untyped:return"Untyped";default:return d.name}}function xS(d){switch(d.id){case ze.List:return"Loop over list items";case ze.ManualFlow:return"Manual flow control loop";case ze.ObjectKeys:return"Loop over object keys";case ze.ObjectValues:return"Loop over object values";case ze.Counted:return"Loop given number of times";case ze.String:return"Loop over text characters";case Jt.Addition:return"Sum numbers";case Jt.Subtraction:return"Subtract numbers";case Jt.Multiplication:return"Multiply numbers";case Jt.Division:return"Divide numbers";case Jt.Remainder:return"Get remainder of numbers";case Jt.Exponentiation:return"Get exponent of numbers";case Se.AddIndex:return"Add at index position";case Se.DeleteFirst:return"Delete first character";case Se.DeleteLast:return"Delete last character";case Se.DeleteIndex:return"Delete at index position";case Se.Join:return"Join texts";case Se.ReplaceAllMatches:return"Replace all matches";case Se.ReplaceFirst:return"Replace first match";case Se.ReplaceLast:return"Replace last match";case Se.Split:return"Split text";case Se.ReplaceIndex:return"Replace at index position";case Se.ReplaceSingleMatch:return"Replace single match";case Se.GetFirst:return"Get first character";case Se.GetLast:return"Get last character";case Se.GetIndexItem:return"Get at index position";case Se.GetIndexOf:return"Get the index number of the character";case Se.Append:return"Add at the end";case Se.Prepend:return"Add at the start";case rr.Wait:return"Wait";case rr.Parallel:return"Run in parallel";case rr.Sequential:return"Run in sequence";case vi.HttpRequest:return"HTTP request";case pr.CreateNewInstance:return"Create new copy of entity";case Je.AddIndex:return"Add item at index position";case Je.DeleteFirst:return"Delete first item";case Je.DeleteLast:return"Delete last item";case Je.DeleteIndex:return"Delete item at index position";case Je.Join:return"Join lists";case Je.ReplaceFirst:return"Replace first match";case Je.ReplaceLast:return"Replace last match";case Je.Split:return"Split list";case Je.ReplaceIndex:return"Replace at index position";case Je.GetFirst:return"Get first item";case Je.GetLast:return"Get last item";case Je.GetIndexItem:return"Get item at index position";case Je.Append:return"Add item at the end";case Je.Prepend:return"Add item at the start";case Ia.PROJECT_PUBLICATION_COMPLETED:return"Project publication completed";default:return(d.name.slice(0,1).toUpperCase()+d.name.slice(1)).replaceAll("-"," ")}}function ne(d,u){var i;if(f.FunctionDeclaration===d.type){const a=d.name;if(Object.values(Xr).includes(a))switch(a){case Xr.AbortExecution:return"Abort ongoing execution";case Xr.DeletePersistedEntity:return"Delete entry from database";case Xr.CreatePersistedEntity:return"Save new data entry in database";case Xr.UpdatePersistedEntity:return"Update entity data to database";default:return bi(d.type).replaceAll("-"," ")}return a}if(f.BuiltInBaseEntity===d.type)return MS([d.name]);if(Dg.includes(d.type)&&d.type!==f.ActionDescriptor)return d.name;switch(d.type){case f.Search:return US(d);case f.GlobalEvent:return d.implements?ne(d.implements,u):bi(d.type).replaceAll("-"," ");case f.Operation:case f.InternalCall:case f.Loop:const a=Hi(d.declaration,u);return a||Me.log("Loop without declaration: ",d),ne(a,u);case f.ActionDescriptor:return xS(d);case f.BreakStatement:const o=Hi(d.parent,u);return o||Me.log("Break without parent: ",d),`Stop loop ${ne(o,u)}`;case f.ContinueStatement:const p=Hi(d.parent,u);return p||Me.log("continue without parent: ",d),`Execute next iteration of ${ne(p,u)}`;case f.FunctionCall:return Hi(d.declaration,u).name;case f.Condition:{const y=d;if((i=d.inputs)!=null&&i.length){y.inputs[0]||Me.log("condition without input: ",d);const v=ne(y.inputs[0],y.project);if(y.inputs[1]){const E=y.inputs[1].declaration.name;return`If ${v} ${Gm(y)} ${E}`}return`If ${v} ${Gm(y)}`}else return`If ${Gm(y)}`}case f.ReturnStatement:{const y=Hi(d.parent,u);return y?`Output of ${ne(y,u)}`:"Return statement"}case f.InputMap:if(d.declaration){const y=Hi(d.declaration,u);return y||(Me.log("Input without declaration: ",d),Me.log("Og declaration: ",d.declaration)),ne(y,u)||""}else return d.name||"";case f.VariableInstance:{const y=Hi(d.declaration,u);return y||Me.log("Var without declaration: ",d),ne(y,u)||""}case f.OutputMap:if(d.declaration){const y=Hi(d.declaration,u);return(y==null?void 0:y.name)||""}else return"";case f.PrimitiveEntity:case f.LiteralValue:return jS(d);default:return bi(d.type).replaceAll("-"," ")}}function zb(d,u){const i=[];d.name||i.push(new ee({id:`${d.id}--${ae.EmptyName}`,message:`Entity with id "${d.id}" and type "${d.type}" has an empty name. Please provide a 'name' string.`,severity:q.Error,code:ae.EmptyName}));const a=u.entities.filter(o=>o.name===d.name);return a.length&&i.push(new ee({id:`${d.id}--${ae.NameNotUniqueInScope}`,message:`Entity with id "${d.id}" and type "${d.type}" has a name "${d.name}" that is not unique in the project. Entity with id "${a[0].id}" has the same name.
|
|
397
397
|
Please provide a unique 'name' string.`,severity:q.Error,code:ae.NameNotUniqueInScope})),i}function Xb(d,u){const i=[];d.name||i.push(new ee({id:`${d.id}--${ae.EmptyName}`,message:`Entity with id "${d.id}" and type "${d.type}" has an empty name. Please provide a 'name' string.`,severity:q.Error,code:ae.EmptyName}));const a=d.parent?J(d.parent):null;let o=u;a&&(o=u.get(a));const p=[];o.type===f.DefinitionEntity?p.push(...o.methods.map(y=>y)):o.type===f.Project?p.push(...o.functions.map(y=>y)):o.type===f.Loop?o.body&&p.push(o.body):o.type===f.InstalledProject&&p.push(...o.functions.map(y=>y));const e=p.filter(y=>y.name===d.name);return e.length&&i.push(new ee({id:`${d.id}--${ae.NameNotUniqueInScope}`,message:`Entity with id "${d.id}" and type "${d.type}" has a name "${d.name}" that is not unique in ${o.type===f.Project?"the globally declared project scope":"its parent entity"}. Entity with id "${e[0].id}" has the same name.
|
|
398
398
|
Please provide a unique 'name' string.`,severity:q.Error,code:ae.NameNotUniqueInScope})),i}function Qb(d,u){const i=[];d.name||i.push(new ee({id:`${d.id}--${ae.EmptyName}`,message:`Entity with id "${d.id}" and type "${d.type}" has an empty name. Please provide a 'name' string.`,severity:q.Error,code:ae.EmptyName}));const a=d.parent&&Hi(d.parent,u)||u;if(!a)i.push(new ee({id:`${d.id}--parent-reference--${k.ReferencedEntityNotFound}`,message:`The entity with id '${d.parent}' that isn't yet found in the project. Perhaps it should be created first. Or perhaps the ID is incorrect.`,severity:q.Error,code:k.ReferencedEntityNotFound}));else{const p=LA(a).filter(e=>e.name===d.name);p.length&&i.push(new ee({id:`${d.id}--${ae.NameNotUniqueInScope}`,message:`Entity with id "${d.id}" and type "${d.type}" has a name "${d.name}" that is not unique in its scope or higher scopes. Entity with id "${p[0].id}" has the same name.
|
|
399
399
|
Please provide a unique 'name' string.`,severity:q.Error,code:ae.NameNotUniqueInScope}))}return i}function ew(d,u){const i=[];d.name||i.push(new ee({id:`${d.id}--${ae.EmptyName}`,message:`Entity with id "${d.id}" and type "${d.type}" has an empty name. Please provide a 'name' string.`,severity:q.Error,code:ae.EmptyName}));const a=J(d.parent);if(!a)i.push(new ee({id:`${d.id}--parent-reference--${k.InvalidReferenceObjectStructure}`,message:`Reference object at 'parent' property for entity with id "${d.id}" and type "${d.type}" is not a valid reference. A reference needs to be a 'id' string of an existing entity in the project.`,severity:q.Error,code:k.InvalidReferenceObjectStructure}));else{const o=u.get(a);if(!o)i.push(new ee({id:`${d.id}--parent-reference--${k.ReferencedEntityNotFound}`,message:`The entity with id '${a}' that isn't yet found in the project. Perhaps it should be created first. Or perhaps the ID is incorrect.`,severity:q.Error,code:k.ReferencedEntityNotFound}));else{const e=o.properties.filter(y=>y.name===d.name);e.length&&i.push(new ee({id:`${d.id}--${ae.NameNotUniqueInScope}`,message:`Entity with id "${d.id}" and type "${d.type}" has a name "${d.name}" that is not unique among all properties in the parent entity. Entity with id "${e[0].id}" has the same name.
|
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.6425",
|
|
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",
|