@elyx-code/project-logic-tree 0.0.6425 → 0.0.6426

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -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, p;
77317
+ var a, o;
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
- (e) => e.toJSON(i)
77328
+ (p) => p.toJSON(i)
77329
77329
  ),
77330
77330
  errorCalls: this.errorCalls.map(
77331
- (e) => e.toJSON(i)
77331
+ (p) => p.toJSON(i)
77332
77332
  ),
77333
77333
  calledBySuccess: this.calledBySuccess.map(
77334
- (e) => e.toReference()
77334
+ (p) => p.toReference()
77335
77335
  ),
77336
- calledByError: this.calledByError.map((e) => e.toReference()),
77337
- calledByEntry: this.calledByEntry.map((e) => e.toReference()),
77336
+ calledByError: this.calledByError.map((p) => p.toReference()),
77337
+ calledByEntry: this.calledByEntry.map((p) => p.toReference()),
77338
77338
  process: (a = this.process) == null ? void 0 : a.toJSON(i),
77339
- declaration: (o = this.declaration) == null ? void 0 : o.toJSON(i),
77339
+ declaration: this.declaration.toJSON(i),
77340
77340
  inputs: this.inputs.map(
77341
- (e) => e.toJSON(i)
77341
+ (p) => p.toJSON(i)
77342
77342
  ),
77343
77343
  outputs: this.outputs.map(
77344
- (e) => e.toJSON(i)
77344
+ (p) => p.toJSON(i)
77345
77345
  ),
77346
77346
  parent: this.parent.toReference(),
77347
- error: (p = this.error) == null ? void 0 : p.toJSON(i)
77347
+ error: (o = this.error) == null ? void 0 : o.toJSON(i)
77348
77348
  });
77349
77349
  }
77350
77350
  toJSONClone(i = ke) {
77351
- var o, p, e, y, v, E, b, A, C;
77351
+ var o, p, e, y, v, E, b;
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
- (N) => N.toJSONClone({
77363
+ (A) => A.toJSONClone({
77364
77364
  ...i,
77365
77365
  newId: null
77366
77366
  })
77367
77367
  ),
77368
77368
  errorCalls: this.errorCalls.map(
77369
- (N) => N.toJSONClone({
77369
+ (A) => A.toJSONClone({
77370
77370
  ...i,
77371
77371
  newId: null
77372
77372
  })
77373
77373
  ),
77374
77374
  calledBySuccess: this.calledBySuccess.map(
77375
- (N) => N.toReference({ seenEntityMaps: i.seenEntityMaps })
77375
+ (A) => A.toReference({ seenEntityMaps: i.seenEntityMaps })
77376
77376
  ),
77377
77377
  calledByError: this.calledByError.map(
77378
- (N) => N.toReference({ seenEntityMaps: i.seenEntityMaps })
77378
+ (A) => A.toReference({ seenEntityMaps: i.seenEntityMaps })
77379
77379
  ),
77380
77380
  calledByEntry: this.calledByEntry.map(
77381
- (N) => N.toReference({ seenEntityMaps: i.seenEntityMaps })
77381
+ (A) => A.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) ? (b = this.declaration) == null ? void 0 : b.toJSON() : (A = this.declaration) == null ? void 0 : A.toJSONClone({ ...i, newId: null }),
77387
+ declaration: this.project.getBuiltIn(this.declaration.id) ? this.declaration.toJSON() : this.declaration.toJSONClone({ ...i, newId: null }),
77388
77388
  inputs: this.inputs.map(
77389
- (N) => N.toJSONClone({ ...i, newId: null })
77389
+ (A) => A.toJSONClone({ ...i, newId: null })
77390
77390
  ),
77391
77391
  outputs: this.outputs.map(
77392
- (N) => N.toJSONClone({ ...i, newId: null })
77392
+ (A) => A.toJSONClone({ ...i, newId: null })
77393
77393
  ),
77394
- error: (C = this.error) == null ? void 0 : C.toJSONClone({
77394
+ error: (b = this.error) == null ? void 0 : b.toJSONClone({
77395
77395
  ...i,
77396
77396
  newId: null
77397
77397
  }),
@@ -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,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}'.
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}'.
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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elyx-code/project-logic-tree",
3
- "version": "0.0.6425",
3
+ "version": "0.0.6426",
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",