@elyx-code/project-logic-tree 0.0.6407 → 0.0.6408
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.d.ts +1 -0
- package/dist/index.js +4 -0
- package/dist/index.umd.cjs +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -16522,6 +16522,7 @@ export declare class VariableInstanceState extends VersionedState implements IVa
|
|
|
16522
16522
|
errors: EntityGenerationError[];
|
|
16523
16523
|
modifiedData: IVariableInstanceGenerationTarget;
|
|
16524
16524
|
};
|
|
16525
|
+
get codeName(): string | null;
|
|
16525
16526
|
get codeNativeValueValidation(): ValueValidationCallback | null;
|
|
16526
16527
|
validateGeneratedUpdate(data: Partial<IVariableInstanceGenerationTarget>): {
|
|
16527
16528
|
errors: EntityGenerationError[];
|
package/dist/index.js
CHANGED
|
@@ -47805,6 +47805,10 @@ const Bt = class Bt extends Nr {
|
|
|
47805
47805
|
modifiedData: l
|
|
47806
47806
|
};
|
|
47807
47807
|
}
|
|
47808
|
+
get codeName() {
|
|
47809
|
+
var i;
|
|
47810
|
+
return (i = this.declaration) == null ? void 0 : i.codeName;
|
|
47811
|
+
}
|
|
47808
47812
|
get codeNativeValueValidation() {
|
|
47809
47813
|
var i;
|
|
47810
47814
|
return this._codeNativeValueValidation || ((i = this.declaration) == null ? void 0 : i.codeNativeValueValidation) || null;
|
package/dist/index.umd.cjs
CHANGED
|
@@ -76,7 +76,7 @@ You shouldn't have to manually update a 'parent' property. The equivalent result
|
|
|
76
76
|
${Tm(a)}`,issue:null})):p.push(new ee({id:`${i.id}--${k.ReferencedEntityNotFound}`,code:k.ReferencedEntityNotFound,severity:q.Error,message:`Entity of type '${i.type}' with id '${i.id}' has an 'declaration' property that isn't found in the project. The 'declaration' property must point to one of the built-in action descriptors reserved for '${f.Condition}' entities.
|
|
77
77
|
${Tm(a)}`,issue:null})):p.push(new ee({id:`${i.id}--${ae.InvalidObjectStructure}`,code:ae.InvalidObjectStructure,severity:q.Error,message:`Entity of type '${i.type}' with id '${i.id}' is missing the 'declaration' property. This property is required for a '${i.type}' entity and must point to one of the built-in action descriptors reserved for '${f.Condition}' entities.
|
|
78
78
|
${Tm(a)}`,issue:null})),{errors:p,modifiedData:l}}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.
|
|
79
|
-
If an entity is called by another, they must be in the same scope, which means they have the same parent.`,issue:null})),{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=[],l=[],p=[],e=[];return Object.values(this.detachedDependents).forEach(y=>{const v=y.entity.afterAllChildrenInitialized(i);a.push(...v.updated),l.push(...v.added),p.push(...v.removed),e.push(...v.affected)}),i==null||i.attemptAutoclose("sync-dependents",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(e),self:this}}onDetachedDependencyRemoved(i,a,l){const p=[],e=[],y=[],v=[];if(a==="parent"){const{updated:E,added:w,removed:A}=this.remove({ignoreUpstream:!1},l);p.push(...E),e.push(...w),y.push(...A)}return{updated:R(p),added:R(e),removed:R(y),affected:R(v),self:this}}onDetachedDependencyRestored(i,a,l){const p=[],e=[],y=[],v=[];if(a==="parent"){const{updated:E,added:w,removed:A}=this.restore({},l);p.push(...E),e.push(...w),y.push(...A)}return{updated:R(p),added:R(e),removed:R(y),affected:R(v),self:this}}unsubscribeFromDependencies(){return this.parent.unsubscribeDependents([{entity:this,field:"parent"}]),this}subscribeToDependencies(){var i;return(i=this.parent)==null||i.subscribeDependents([{entity:this,field:"parent"}]),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 Yt(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.declaration=this.declaration,i.successCalls=[...this.successCalls],i.errorCalls=[...this.errorCalls],i.calledBySuccess=[...this.calledBySuccess],i.calledByError=[...this.calledByError],i.calledByEntry=[...this.calledByEntry],i.parent=this.parent,this}recursiveCaptureUpstreamVersions(i){const a=[],l=[],p=[],e=[];if(this.parent){this.parent.increaseVersion(i);const y=this.parent.recursiveCaptureUpstreamVersions(i);a.push(this.parent,...y.updated),l.push(...y.added),p.push(...y.removed)}return{updated:R(a),added:R(l),removed:R(p),affected:R(e),self:this}}async restoreVersion(i){var v;const a=[],l=[],p=[],e=[];if(this.version===i)return{updated:R(a),added:R(l),removed:R(p),affected:R(e),self:this};if(!this.knownVersions){const E=new Map;for(const[w,A]of this.knownVersions||new Map){if(E.set(w,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 Yt(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.declaration=y.declaration,this.successCalls=y.successCalls,this.errorCalls=y.errorCalls,this.calledBySuccess=y.calledBySuccess,this.calledByError=y.calledByError,this.calledByEntry=y.calledByEntry,this.parent=y.parent,{updated:R(a),added:R(l),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,i.parent){const l=Z(i.parent),p=this.project.get(l),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 '${l}' 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 l=Z(i.declaration),p=this.project.get(l);p&&this.setDeclaration(p)}return i.calledByEntry.forEach(l=>{const p=Z(l),e=this.project.get(p);e&&(this.addEntryCaller(e,a),e.addCall(this,a))}),[...this.calledByEntry].forEach(l=>{i.calledByEntry.find(e=>Z(e)===l.id)||(this.removeCaller(l,a),l.removeCall(this,a))}),i.calledBySuccess.forEach(l=>{const p=Z(l),e=this.project.get(p);e&&(this.addSuccessCaller(e,a),e.addSuccessCall(this,a))}),[...this.calledBySuccess].forEach(l=>{i.calledBySuccess.find(e=>Z(e)===l.id)||(this.removeCaller(l,a),l.removeCall(this,a))}),i.calledByError.forEach(l=>{const p=Z(l),e=this.project.get(p);e&&(this.addErrorCaller(e,a),e.addErrorCall(this,a))}),[...this.calledBySuccess].forEach(l=>{i.calledBySuccess.find(e=>Z(e)===l.id)||(this.removeCaller(l,a),l.removeCall(this,a))}),this.captureVersion(),this.subscribeToDependencies(),a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),this}hydrateAncestors(){const i=[],a=[],l=[],p=[];if(this.initialData.parent){const e=Z(this.initialData.parent),y=this.project.get(e);if(y)this.setParent(y,null);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=Z(this.initialData.declaration),y=this.project.get(e);y&&(this.setDeclaration(y),i.push(y))}return this.initialData.calledByEntry.forEach(e=>{const y=Z(e),v=this.project.get(y);v&&this.addEntryCaller(v,null)}),this.initialData.calledBySuccess.forEach(e=>{const y=Z(e),v=this.project.get(y);v&&this.addSuccessCaller(v,null)}),this.initialData.calledByError.forEach(e=>{const y=Z(e),v=this.project.get(y);v&&this.addErrorCaller(v,null)}),{updated:R(i),added:R(a),removed:R(l),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=[],l=[],p=[],e=[];this.initialized=!0;const{updated:y,added:v,removed:E}=this.syncInputs(i);return a.push(...y),l.push(...v),p.push(...E),this.captureVersion(),i==null||i.attemptAutoclose("after-all-children-initialized",this.id),{updated:R(a),added:R(l),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"))){const a=[this],l=[],p=[],e=[];return this.parent===this.project&&this.project.addCondition(this),this.successCalls.forEach(y=>{y.addSuccessCaller(this,i),a.push(y)}),this.errorCalls.forEach(y=>{y.addErrorCaller(this,i),a.push(y)}),this.calledByEntry.forEach(y=>{y.addCall(this,i),a.push(y)}),this.calledBySuccess.forEach(y=>{y.addSuccessCall(this,i),a.push(y)}),this.calledByError.forEach(y=>{y.addErrorCall(this,i),a.push(y)}),this.subscribe(),this.subscribeToDependencies(),i==null||i.attemptAutoclose("add-self-to-project",this.id),{updated:R(a),added:R(l),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 l=this.inputs.findIndex(p=>p.id===i.id);return l>-1&&(this.inputs.splice(l,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){return this}removeOutput(i){return this}addSuccessCaller(i,a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-success-caller")),l=!1){return this.calledBySuccess.find(p=>p.id===i.id)||(this.calledBySuccess.push(i),a==null||a.add(this,S.Updated),l&&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")),l=!1){return this.calledByError.find(p=>p.id===i.id)||(this.calledByError.push(i),a==null||a.add(this,S.Updated),l&&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")),l=!1){return this.calledByEntry.find(p=>p.id===i.id)||(this.calledByEntry.push(i),a==null||a.add(this,S.Updated),l&&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")),l=!1){return this.errorCalls.find(p=>p.id===i.id)||(this.errorCalls.push(i),l&&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")),l=!1){return this.successCalls.find(p=>p.id===i.id)||(this.successCalls.push(i),l&&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")),l=!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)),l&&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")),l=!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)),l&&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 l;return((l=this.parent)==null?void 0:l.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"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.declaration=te(this.initialData.declaration,this.project),this.successCalls=this.initialData.successCalls.map(a=>{const l=te(a,this.project);if(l.addSuccessCaller(this),[f.BreakStatement,f.ContinueStatement].includes(l.type))l.setParent(this.parent.parent,null),l.initChildren(i);else if(l.type===f.ReturnStatement){const p=Wr(this,this.project);l.setParent(p,null),l.initChildren(i)}else l.type!==f.InternalCall&&(l.setParent(this.parent,null),l.initChildren(i));return l}),this.errorCalls=this.initialData.errorCalls.map(a=>{const l=te(a,this.project);if(l.addErrorCaller(this),[f.BreakStatement,f.ContinueStatement].includes(l.type))l.setParent(this.parent.parent,null),l.initChildren(i);else if(l.type===f.ReturnStatement){const p=Wr(this,this.project);l.setParent(p,null),l.initChildren(i)}else l.type!==f.InternalCall&&(l.setParent(this.parent,null),l.initChildren(i));return l}),this.inputs=this.initialData.inputs.map(a=>{const l=te(a,this.project);return l.setParent(this,null),l.initChildren(i),l}),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 l=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):l&&(a==null||a.add(this,S.Updated)),a==null||a.attemptAutoclose("meta-sync",this.id),this}async APILoad(i=ve,...a){return await Yt.repository.APILoad(this.id,...a),this}async APICreate(i=ve,...a){return await Yt.repository.APICreate(this.toShallowJSON(),...a),this}async APIUpdate(i=ve,...a){return await Yt.repository.APIUpdate(this.toShallowJSON(),...a),this}async APIDelete(i=ve,...a){return await Yt.repository.APIDelete(this.toShallowJSON(),...a),this}async APIClone(i=ve,...a){return await Yt.repository.APIClone(this.id,...a),this}async APILoadVersion(i=ve,a,...l){return await Yt.repository.APILoadVersion(this.id,a,...l)}removeFromParent(i=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-from-parent"))){const a=[],l=[],p=[],e=[];return this.parent.type===f.Project?(this.parent.removeCondition(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(l),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"))){const l=[],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(v=>{const{updated:E,removed:w,added:A}=v.entity.onDetachedDependencyRemoved(this,v.field,a);l.push(...E),p.push(...w),e.push(...A)}),this.inputs.forEach(v=>{const{updated:E,removed:w}=v.remove({ignoreUpstream:!0},a);l.push(...E),p.push(...w)}),this.successCalls.forEach(v=>{l.push(v),v.removeCaller(this,a)}),this.errorCalls.forEach(v=>{l.push(v),v.removeCaller(this,a)}),!i){const v=this.removeFromParent(a);e.push(...v.added),l.push(...v.updated),p.push(...v.removed),y.push(...v.affected),this.calledBy.forEach(E=>{l.push(E),E.removeCall(this,a)})}return a==null||a.attemptAutoclose("remove-entity",this.id),{added:R(e),updated:R(l),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=[],l=[],p=[],e=[];return i!=null&&i.hasAdded(this.id)?(i==null||i.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},i),Object.values(this.detachedDependents).forEach(y=>{const{updated:v,removed:E,added:w}=y.entity.onDetachedDependencyRestored(this,y.field,i);l.push(...v),p.push(...E),a.push(...w)}),this.inputs.forEach(y=>{const{updated:v}=y.restore({},i);l.push(...v)}),this.successCalls.forEach(y=>{l.push(y),y.addSuccessCaller(this,i)}),this.errorCalls.forEach(y=>{l.push(y),y.addErrorCaller(this,i)}),this.calledBySuccess.forEach(y=>{l.push(y),y.addSuccessCall(this,i)}),this.calledByError.forEach(y=>{l.push(y),y.addErrorCall(this,i)}),this.calledByEntry.forEach(y=>{l.push(y),y.addCall(this,i)}),this.parent.type===f.Project&&this.project.addCondition(this),i==null||i.attemptAutoclose("restore-entity",this.id),{added:R(a),updated:R(l),removed:R(p),affected:R(e),self:this})}toFlat(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this,...this.inputs.flatMap(l=>l.toFlat(i)),...this.successCalls.flatMap(l=>l.toFlat(i)),...this.errorCalls.flatMap(l=>l.toFlat(i)),...this.calledBy.flatMap(l=>l.toFlat(i))])}toFlatIds(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.id,...this.inputs.flatMap(l=>l.toFlatIds(i)),...this.successCalls.flatMap(l=>l.toFlatIds(i)),...this.errorCalls.flatMap(l=>l.toFlatIds(i)),...this.calledBy.flatMap(l=>l.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){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,declaration:this.declaration.toJSON(i),successCalls:this.successCalls.map(a=>a.toJSON(i)),errorCalls:this.errorCalls.map(a=>a.toJSON(i)),calledBySuccess:this.calledBySuccess.map(a=>a.toReference()),calledByError:this.calledByError.map(a=>a.toReference()),calledByEntry:this.calledByEntry.map(a=>a.toReference()),inputs:this.inputs.map(a=>a.toJSON(i)),parent:this.parent.toReference()})}toJSONClone(i=ke){var l,p,e,y,v;let a;return(l=i.seenEntityMaps)!=null&&l.has(this.id)?a=i.seenEntityMaps.get(this.id):(a=i.newId||Gr(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,declaration:this.declaration.toJSON(),successCalls:this.successCalls.map(E=>E.toJSONClone({...i,newId:null})),errorCalls:this.errorCalls.map(E=>E.toJSONClone({...i,newId:null})),calledBySuccess:this.calledBySuccess.map(E=>E.toReference({seenEntityMaps:i.seenEntityMaps})),calledByError:this.calledByError.map(E=>E.toReference({seenEntityMaps:i.seenEntityMaps})),calledByEntry:this.calledByEntry.map(E=>E.toReference({seenEntityMaps:i.seenEntityMaps})),inputs:this.inputs.map(E=>E.toJSONClone({...i,newId:null})),parent:this.parent.toReference({seenEntityMaps:i.seenEntityMaps})})}toReference(i=ke){var l;let a=this.id;return(l=i.seenEntityMaps)!=null&&l.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 l;let a=this.id;return(l=i.seenEntityMaps)!=null&&l.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,declaration:this.declaration.toReference(i),inputs:this.inputs.map(p=>p.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)),parent:this.parent.toReference(i)}}toFlatJSON(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.toShallowJSON(),...this.inputs.flatMap(l=>l.toFlatJSON(i)),...this.successCalls.flatMap(l=>l.toFlatJSON(i)),...this.errorCalls.flatMap(l=>l.toFlatJSON(i)),...this.calledBy.flatMap(l=>l.toFlatJSON(i))])}toGenerationTarget(){const i=this.parent.type===f.Project?void 0:this.parent.id;return{id:this.id,type:this.type,declaration:this.declaration.id,calledByEntry:this.calledByEntry.map(a=>a.id),calledBySuccess:this.calledBySuccess.map(a=>a.id),calledByError:this.calledByError.map(a=>a.id),parent:i}}toFlatGenerationTarget(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.toGenerationTarget(),...this.inputs.flatMap(l=>l.toFlatGenerationTarget(i)),...this.successCalls.flatMap(l=>l.toFlatGenerationTarget(i)),...this.errorCalls.flatMap(l=>l.toFlatGenerationTarget(i))])}clearErrors(){return this.errors=[],this.inputs.forEach(i=>i.clearErrors()),this.successCalls.forEach(i=>i.clearErrors()),this.errorCalls.forEach(i=>i.clearErrors()),this}validate(){const i=Gj(this);return this.errors=i,{success:!0,error:null,data:this.toJSON()}}getErrors(){return[...this.errors,...this.inputs.flatMap(a=>a.getErrors())]}getShallowErrors(){return this.errors}clone(i=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"clone-entity")),a=null,l=null,p=!0){var V;let e=Fr(a,this);const y=this.toJSON(),v=l||N.UUID.uuid();y.inputs=[];const E=v.split("-id"),w=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=or(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 $=(V=this.inputs)==null?void 0:V.map((U,G)=>U.clone(i,A,w+"-input-map-"+G+"-id",p));return A.inputs=$,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=[],l=[],p=[],e=[];return this.inputs.forEach(v=>{if(!this.declaration.inputs.find(w=>{var A;return w.id===((A=v.declaration)==null?void 0:A.id)})){const w=v.remove({ignoreUpstream:!1},i);p.push(...w.removed),a.push(...w.updated)}}),this.inputs.filter((v,E)=>{const w=this.inputs.findIndex($=>$.declaration===v.declaration&&$!==v);if(w===-1)return!1;const A=this.inputs[w];return L(A==null?void 0:A.createdAt).isSame(L(v.createdAt))?E>w:!!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(l),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=[],l=[],p=[],e=[],y=this.declaration.inputs.filter(A=>A.parentRelationType===de.FixedArguments&&!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)}),this.inputs.sort((A,$)=>A.index-$.index);const{updated:v,added:E,removed:w}=this.removeUnrecognizedInputs(i);return a.push(...v),l.push(...E),p.push(...w),i==null||i.attemptAutoclose("sync-missing-fixed-inputs",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(e),self:this}}getUnusedInputs(){return this.inputs.filter(i=>i.suggestion||!i.readsValue&&!i.defaultValue)}getUnusedOutputs(){return[]}getUsedInputs(){return this.inputs.filter(i=>!i.suggestion&&(i.readsValue||i.defaultValue))}getUsedOutputs(){return[]}};g(Yt,"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,...l)=>null}),g(Yt,"type",f.Condition),g(Yt,"USER_MANAGED_PARENT_TYPES",[...Mr,f.Project]),g(Yt,"PARENT_TYPES",[...Yt.USER_MANAGED_PARENT_TYPES]),g(Yt,"MUTABLE_BASE_PROPERTIES",["operator"]),g(Yt,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),g(Yt,"BASE_PROPERTIES",[...Yt.MUTABLE_BASE_PROPERTIES,...Yt.INMUTABLE_BASE_PROPERTIES]),g(Yt,"MUTABLE_META_PROPERTIES",["x","y"]),g(Yt,"INMUTABLE_META_PROPERTIES",[...Yt.INMUTABLE_BASE_PROPERTIES]),g(Yt,"META_PROPERTIES",[...Yt.MUTABLE_META_PROPERTIES,...Yt.INMUTABLE_META_PROPERTIES]),g(Yt,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry","parent"]),g(Yt,"INMUTABLE_UPSTREAM_PROPERTIES",[]),g(Yt,"UPSTREAM_PROPERTIES",[...Yt.MUTABLE_UPSTREAM_PROPERTIES,...Yt.INMUTABLE_UPSTREAM_PROPERTIES]),g(Yt,"MUTABLE_DOWNSTREAM_PROPERTIES",["successCalls","errorCalls","inputsDeclarations","inputs"]),g(Yt,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),g(Yt,"DOWNSTREAM_PROPERTIES",[...Yt.MUTABLE_DOWNSTREAM_PROPERTIES,...Yt.INMUTABLE_DOWNSTREAM_PROPERTIES]),g(Yt,"PROPERTIES",[...Yt.META_PROPERTIES,...Yt.UPSTREAM_PROPERTIES,...Yt.DOWNSTREAM_PROPERTIES]);let oo=Yt;function Kj(d){var y;const u=lme(),i=d.toJSON();u.safeParse(i).success,(y=d.dataType)==null||y.validate(),d.inputs.forEach(v=>v.validate()),d.outputs.forEach(v=>v.validate()),d.internalCalls.forEach(v=>v.validate());const p=[...Ua(d),...Io(d),...kj(d)],e=Db(d);return p.push(...e),vr(d.errors,p)}function kj(d){const u=[],i=d.name;if(!i){const $=ft({id:`${d.id}--${ae.EmptyName}`,message:`Variable declaration "${ne(d,d.project)}" with id "${d.id}" does not have a name. Entities of type ${d.type} must have valid names.`,issue:null,severity:q.Error,code:ae.EmptyName,entity:d});return u.push($.error),u}const l=[...d.project.functions,...d.project.entities.flatMap($=>$.methods)].filter($=>$.id!==d.id),p=i.trim(),e=!l.some($=>$.name===i||$.name===p);if(!e){const $=ft({id:`${d.id}--${ae.NameNotUniqueInScope}`,message:`Variable declaration "${ne(d,d.project)}" with id "${d.id}" does not have a unique name. Entities of type ${d.type} must have valid names among all other entities of its type.`,issue:null,severity:q.Error,code:ae.NameNotUniqueInScope,entity:d});u.push($.error)}const y=jr(i);if(!!l.some($=>jr($.name)===y)&&e){const $=ft({id:`${d.id}--${ae.NameAsResolvedCodeNameNotUniqueInScope}`,message:`Variable declaration "${ne(d,d.project)}" with id "${d.id}" does not have a unique name once it is resolved as it will appear in code: "${y}". Entities of type ${d.type} must have valid names including their code name form.`,issue:null,severity:q.Error,code:ae.NameAsResolvedCodeNameNotUniqueInScope,entity:d});u.push($.error)}if(!/^[a-zA-Z_]/.test(i)){const $=ft({id:`${d.id}--${ae.NameMustStartWithLetterOrUnderscore}`,message:`Variable declaration "${ne(d,d.project)}" with id "${d.id}" has a name that does not start with a letter or underscore.`,issue:null,severity:q.Error,code:ae.NameMustStartWithLetterOrUnderscore,entity:d});u.push($.error)}const w=i.substring(1);if(!/^[a-zA-Z0-9_ ]*$/.test(w)){const $=ft({id:`${d.id}--${ae.NameCanOnlyContainLettersNumbersUnderscoreAndSpaces}`,message:`Variable declaration "${ne(d,d.project)}" with id "${d.id}" has a name that contains invalid characters. It can only contain letters, numbers, underscores and spaces.`,issue:null,severity:q.Error,code:ae.NameCanOnlyContainLettersNumbersUnderscoreAndSpaces,entity:d});u.push($.error)}return u}const zme=Object.freeze(Object.defineProperty({__proto__:null,validate:Kj,validateVariableDeclarationName:kj},Symbol.toStringTag,{value:"Module"}));function qj(d){const u=Cye(),i=d.toJSON();u.safeParse(i).success,d.inputs.forEach(y=>y.validate()),d.outputs.forEach(y=>y.validate()),d.internalCalls.forEach(y=>y.validate());const p=[...Ua(d),...Io(d)],e=Db(d);return p.push(...e),vr(d.errors,p)}const Xme=Object.freeze(Object.defineProperty({__proto__:null,validate:qj},Symbol.toStringTag,{value:"Module"}));var lA=(d=>(d.Parent="parent",d.DataTypeEntity="data-type-entity",d.VarDeclaration="var-declaration",d))(lA||{});const jt=class jt extends Nr{constructor(i,a){super(i);g(this,"initialData");g(this,"id");g(this,"x");g(this,"y");g(this,"type",f.VariableInstance);g(this,"defaultValue",null);g(this,"writesValues",[]);g(this,"readsValue",null);g(this,"declaration");g(this,"inputs",[]);g(this,"outputs",[]);g(this,"calledBySuccess",[]);g(this,"calledByError",[]);g(this,"calledByEntry",[]);g(this,"successCalls",[]);g(this,"errorCalls",[]);g(this,"internalCalls",[]);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.x=i.x,this.y=i.y}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.VariableInstance,declaration:null,internalCalls:[],successCalls:[],errorCalls:[],readsValue:null,writesValues:[],defaultValue:null,inputs:[],outputs:[],parent:null,calledByEntry:[],calledBySuccess:[],calledByError:[],x:0,y:0}}static fromGenerationTarget(i,a){let l=a;if(i.parent){const V=Z(i.parent);l=a.get(V)}const p=Z(i.declaration),e=a.get(p),y=i.calledByEntry.map(V=>{const U=Z(V);return a.get(U)}),v=i.calledBySuccess.map(V=>{const U=Z(V);return a.get(U)}),E=i.calledByError.map(V=>{const U=Z(V);return a.get(U)});let w=null;if(i.readsValue){const V=Z(i.readsValue);w=a.get(V)}const A={id:i.id,version:N.UUID.uuid(),createdAt:L().toISOString(),author:N.sessionAuthor,previousVersion:null,deleted:!1,type:f.VariableInstance,declaration:e.toReference(),calledByEntry:y,calledBySuccess:v,calledByError:E,defaultValue:null,errorCalls:[],successCalls:[],internalCalls:[],readsValue:w,inputs:[],outputs:[],writesValues:[],x:0,y:0,parent:l},$=te(A,a);return $.setParent(l,null),$}static validateGenerationTarget(i,a){let l=JSON.parse(JSON.stringify(i));const p=[],e=ni(l,{parent:{list:!1,types:[...Mr,f.Project],optional:!0},declaration:{list:!1,types:[f.VariableDeclaration]}},a);return l=e.modifiedData,p.push(...e.errors,...Br(l)),{errors:p,modifiedData:l}}get codeNativeValueValidation(){var i;return this._codeNativeValueValidation||((i=this.declaration)==null?void 0:i.codeNativeValueValidation)||null}validateGeneratedUpdate(i){const a=[];let l=JSON.parse(JSON.stringify(i));const p=zp(l,this);return l=p.modifiedData,a.push(...p.errors),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.
|
|
79
|
+
If an entity is called by another, they must be in the same scope, which means they have the same parent.`,issue:null})),{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=[],l=[],p=[],e=[];return Object.values(this.detachedDependents).forEach(y=>{const v=y.entity.afterAllChildrenInitialized(i);a.push(...v.updated),l.push(...v.added),p.push(...v.removed),e.push(...v.affected)}),i==null||i.attemptAutoclose("sync-dependents",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(e),self:this}}onDetachedDependencyRemoved(i,a,l){const p=[],e=[],y=[],v=[];if(a==="parent"){const{updated:E,added:w,removed:A}=this.remove({ignoreUpstream:!1},l);p.push(...E),e.push(...w),y.push(...A)}return{updated:R(p),added:R(e),removed:R(y),affected:R(v),self:this}}onDetachedDependencyRestored(i,a,l){const p=[],e=[],y=[],v=[];if(a==="parent"){const{updated:E,added:w,removed:A}=this.restore({},l);p.push(...E),e.push(...w),y.push(...A)}return{updated:R(p),added:R(e),removed:R(y),affected:R(v),self:this}}unsubscribeFromDependencies(){return this.parent.unsubscribeDependents([{entity:this,field:"parent"}]),this}subscribeToDependencies(){var i;return(i=this.parent)==null||i.subscribeDependents([{entity:this,field:"parent"}]),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 Yt(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.declaration=this.declaration,i.successCalls=[...this.successCalls],i.errorCalls=[...this.errorCalls],i.calledBySuccess=[...this.calledBySuccess],i.calledByError=[...this.calledByError],i.calledByEntry=[...this.calledByEntry],i.parent=this.parent,this}recursiveCaptureUpstreamVersions(i){const a=[],l=[],p=[],e=[];if(this.parent){this.parent.increaseVersion(i);const y=this.parent.recursiveCaptureUpstreamVersions(i);a.push(this.parent,...y.updated),l.push(...y.added),p.push(...y.removed)}return{updated:R(a),added:R(l),removed:R(p),affected:R(e),self:this}}async restoreVersion(i){var v;const a=[],l=[],p=[],e=[];if(this.version===i)return{updated:R(a),added:R(l),removed:R(p),affected:R(e),self:this};if(!this.knownVersions){const E=new Map;for(const[w,A]of this.knownVersions||new Map){if(E.set(w,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 Yt(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.declaration=y.declaration,this.successCalls=y.successCalls,this.errorCalls=y.errorCalls,this.calledBySuccess=y.calledBySuccess,this.calledByError=y.calledByError,this.calledByEntry=y.calledByEntry,this.parent=y.parent,{updated:R(a),added:R(l),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,i.parent){const l=Z(i.parent),p=this.project.get(l),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 '${l}' 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 l=Z(i.declaration),p=this.project.get(l);p&&this.setDeclaration(p)}return i.calledByEntry.forEach(l=>{const p=Z(l),e=this.project.get(p);e&&(this.addEntryCaller(e,a),e.addCall(this,a))}),[...this.calledByEntry].forEach(l=>{i.calledByEntry.find(e=>Z(e)===l.id)||(this.removeCaller(l,a),l.removeCall(this,a))}),i.calledBySuccess.forEach(l=>{const p=Z(l),e=this.project.get(p);e&&(this.addSuccessCaller(e,a),e.addSuccessCall(this,a))}),[...this.calledBySuccess].forEach(l=>{i.calledBySuccess.find(e=>Z(e)===l.id)||(this.removeCaller(l,a),l.removeCall(this,a))}),i.calledByError.forEach(l=>{const p=Z(l),e=this.project.get(p);e&&(this.addErrorCaller(e,a),e.addErrorCall(this,a))}),[...this.calledBySuccess].forEach(l=>{i.calledBySuccess.find(e=>Z(e)===l.id)||(this.removeCaller(l,a),l.removeCall(this,a))}),this.captureVersion(),this.subscribeToDependencies(),a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),this}hydrateAncestors(){const i=[],a=[],l=[],p=[];if(this.initialData.parent){const e=Z(this.initialData.parent),y=this.project.get(e);if(y)this.setParent(y,null);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=Z(this.initialData.declaration),y=this.project.get(e);y&&(this.setDeclaration(y),i.push(y))}return this.initialData.calledByEntry.forEach(e=>{const y=Z(e),v=this.project.get(y);v&&this.addEntryCaller(v,null)}),this.initialData.calledBySuccess.forEach(e=>{const y=Z(e),v=this.project.get(y);v&&this.addSuccessCaller(v,null)}),this.initialData.calledByError.forEach(e=>{const y=Z(e),v=this.project.get(y);v&&this.addErrorCaller(v,null)}),{updated:R(i),added:R(a),removed:R(l),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=[],l=[],p=[],e=[];this.initialized=!0;const{updated:y,added:v,removed:E}=this.syncInputs(i);return a.push(...y),l.push(...v),p.push(...E),this.captureVersion(),i==null||i.attemptAutoclose("after-all-children-initialized",this.id),{updated:R(a),added:R(l),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"))){const a=[this],l=[],p=[],e=[];return this.parent===this.project&&this.project.addCondition(this),this.successCalls.forEach(y=>{y.addSuccessCaller(this,i),a.push(y)}),this.errorCalls.forEach(y=>{y.addErrorCaller(this,i),a.push(y)}),this.calledByEntry.forEach(y=>{y.addCall(this,i),a.push(y)}),this.calledBySuccess.forEach(y=>{y.addSuccessCall(this,i),a.push(y)}),this.calledByError.forEach(y=>{y.addErrorCall(this,i),a.push(y)}),this.subscribe(),this.subscribeToDependencies(),i==null||i.attemptAutoclose("add-self-to-project",this.id),{updated:R(a),added:R(l),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 l=this.inputs.findIndex(p=>p.id===i.id);return l>-1&&(this.inputs.splice(l,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){return this}removeOutput(i){return this}addSuccessCaller(i,a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-success-caller")),l=!1){return this.calledBySuccess.find(p=>p.id===i.id)||(this.calledBySuccess.push(i),a==null||a.add(this,S.Updated),l&&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")),l=!1){return this.calledByError.find(p=>p.id===i.id)||(this.calledByError.push(i),a==null||a.add(this,S.Updated),l&&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")),l=!1){return this.calledByEntry.find(p=>p.id===i.id)||(this.calledByEntry.push(i),a==null||a.add(this,S.Updated),l&&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")),l=!1){return this.errorCalls.find(p=>p.id===i.id)||(this.errorCalls.push(i),l&&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")),l=!1){return this.successCalls.find(p=>p.id===i.id)||(this.successCalls.push(i),l&&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")),l=!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)),l&&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")),l=!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)),l&&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 l;return((l=this.parent)==null?void 0:l.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"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.declaration=te(this.initialData.declaration,this.project),this.successCalls=this.initialData.successCalls.map(a=>{const l=te(a,this.project);if(l.addSuccessCaller(this),[f.BreakStatement,f.ContinueStatement].includes(l.type))l.setParent(this.parent.parent,null),l.initChildren(i);else if(l.type===f.ReturnStatement){const p=Wr(this,this.project);l.setParent(p,null),l.initChildren(i)}else l.type!==f.InternalCall&&(l.setParent(this.parent,null),l.initChildren(i));return l}),this.errorCalls=this.initialData.errorCalls.map(a=>{const l=te(a,this.project);if(l.addErrorCaller(this),[f.BreakStatement,f.ContinueStatement].includes(l.type))l.setParent(this.parent.parent,null),l.initChildren(i);else if(l.type===f.ReturnStatement){const p=Wr(this,this.project);l.setParent(p,null),l.initChildren(i)}else l.type!==f.InternalCall&&(l.setParent(this.parent,null),l.initChildren(i));return l}),this.inputs=this.initialData.inputs.map(a=>{const l=te(a,this.project);return l.setParent(this,null),l.initChildren(i),l}),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 l=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):l&&(a==null||a.add(this,S.Updated)),a==null||a.attemptAutoclose("meta-sync",this.id),this}async APILoad(i=ve,...a){return await Yt.repository.APILoad(this.id,...a),this}async APICreate(i=ve,...a){return await Yt.repository.APICreate(this.toShallowJSON(),...a),this}async APIUpdate(i=ve,...a){return await Yt.repository.APIUpdate(this.toShallowJSON(),...a),this}async APIDelete(i=ve,...a){return await Yt.repository.APIDelete(this.toShallowJSON(),...a),this}async APIClone(i=ve,...a){return await Yt.repository.APIClone(this.id,...a),this}async APILoadVersion(i=ve,a,...l){return await Yt.repository.APILoadVersion(this.id,a,...l)}removeFromParent(i=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-from-parent"))){const a=[],l=[],p=[],e=[];return this.parent.type===f.Project?(this.parent.removeCondition(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(l),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"))){const l=[],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(v=>{const{updated:E,removed:w,added:A}=v.entity.onDetachedDependencyRemoved(this,v.field,a);l.push(...E),p.push(...w),e.push(...A)}),this.inputs.forEach(v=>{const{updated:E,removed:w}=v.remove({ignoreUpstream:!0},a);l.push(...E),p.push(...w)}),this.successCalls.forEach(v=>{l.push(v),v.removeCaller(this,a)}),this.errorCalls.forEach(v=>{l.push(v),v.removeCaller(this,a)}),!i){const v=this.removeFromParent(a);e.push(...v.added),l.push(...v.updated),p.push(...v.removed),y.push(...v.affected),this.calledBy.forEach(E=>{l.push(E),E.removeCall(this,a)})}return a==null||a.attemptAutoclose("remove-entity",this.id),{added:R(e),updated:R(l),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=[],l=[],p=[],e=[];return i!=null&&i.hasAdded(this.id)?(i==null||i.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},i),Object.values(this.detachedDependents).forEach(y=>{const{updated:v,removed:E,added:w}=y.entity.onDetachedDependencyRestored(this,y.field,i);l.push(...v),p.push(...E),a.push(...w)}),this.inputs.forEach(y=>{const{updated:v}=y.restore({},i);l.push(...v)}),this.successCalls.forEach(y=>{l.push(y),y.addSuccessCaller(this,i)}),this.errorCalls.forEach(y=>{l.push(y),y.addErrorCaller(this,i)}),this.calledBySuccess.forEach(y=>{l.push(y),y.addSuccessCall(this,i)}),this.calledByError.forEach(y=>{l.push(y),y.addErrorCall(this,i)}),this.calledByEntry.forEach(y=>{l.push(y),y.addCall(this,i)}),this.parent.type===f.Project&&this.project.addCondition(this),i==null||i.attemptAutoclose("restore-entity",this.id),{added:R(a),updated:R(l),removed:R(p),affected:R(e),self:this})}toFlat(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this,...this.inputs.flatMap(l=>l.toFlat(i)),...this.successCalls.flatMap(l=>l.toFlat(i)),...this.errorCalls.flatMap(l=>l.toFlat(i)),...this.calledBy.flatMap(l=>l.toFlat(i))])}toFlatIds(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.id,...this.inputs.flatMap(l=>l.toFlatIds(i)),...this.successCalls.flatMap(l=>l.toFlatIds(i)),...this.errorCalls.flatMap(l=>l.toFlatIds(i)),...this.calledBy.flatMap(l=>l.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){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,declaration:this.declaration.toJSON(i),successCalls:this.successCalls.map(a=>a.toJSON(i)),errorCalls:this.errorCalls.map(a=>a.toJSON(i)),calledBySuccess:this.calledBySuccess.map(a=>a.toReference()),calledByError:this.calledByError.map(a=>a.toReference()),calledByEntry:this.calledByEntry.map(a=>a.toReference()),inputs:this.inputs.map(a=>a.toJSON(i)),parent:this.parent.toReference()})}toJSONClone(i=ke){var l,p,e,y,v;let a;return(l=i.seenEntityMaps)!=null&&l.has(this.id)?a=i.seenEntityMaps.get(this.id):(a=i.newId||Gr(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,declaration:this.declaration.toJSON(),successCalls:this.successCalls.map(E=>E.toJSONClone({...i,newId:null})),errorCalls:this.errorCalls.map(E=>E.toJSONClone({...i,newId:null})),calledBySuccess:this.calledBySuccess.map(E=>E.toReference({seenEntityMaps:i.seenEntityMaps})),calledByError:this.calledByError.map(E=>E.toReference({seenEntityMaps:i.seenEntityMaps})),calledByEntry:this.calledByEntry.map(E=>E.toReference({seenEntityMaps:i.seenEntityMaps})),inputs:this.inputs.map(E=>E.toJSONClone({...i,newId:null})),parent:this.parent.toReference({seenEntityMaps:i.seenEntityMaps})})}toReference(i=ke){var l;let a=this.id;return(l=i.seenEntityMaps)!=null&&l.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 l;let a=this.id;return(l=i.seenEntityMaps)!=null&&l.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,declaration:this.declaration.toReference(i),inputs:this.inputs.map(p=>p.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)),parent:this.parent.toReference(i)}}toFlatJSON(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.toShallowJSON(),...this.inputs.flatMap(l=>l.toFlatJSON(i)),...this.successCalls.flatMap(l=>l.toFlatJSON(i)),...this.errorCalls.flatMap(l=>l.toFlatJSON(i)),...this.calledBy.flatMap(l=>l.toFlatJSON(i))])}toGenerationTarget(){const i=this.parent.type===f.Project?void 0:this.parent.id;return{id:this.id,type:this.type,declaration:this.declaration.id,calledByEntry:this.calledByEntry.map(a=>a.id),calledBySuccess:this.calledBySuccess.map(a=>a.id),calledByError:this.calledByError.map(a=>a.id),parent:i}}toFlatGenerationTarget(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.toGenerationTarget(),...this.inputs.flatMap(l=>l.toFlatGenerationTarget(i)),...this.successCalls.flatMap(l=>l.toFlatGenerationTarget(i)),...this.errorCalls.flatMap(l=>l.toFlatGenerationTarget(i))])}clearErrors(){return this.errors=[],this.inputs.forEach(i=>i.clearErrors()),this.successCalls.forEach(i=>i.clearErrors()),this.errorCalls.forEach(i=>i.clearErrors()),this}validate(){const i=Gj(this);return this.errors=i,{success:!0,error:null,data:this.toJSON()}}getErrors(){return[...this.errors,...this.inputs.flatMap(a=>a.getErrors())]}getShallowErrors(){return this.errors}clone(i=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"clone-entity")),a=null,l=null,p=!0){var V;let e=Fr(a,this);const y=this.toJSON(),v=l||N.UUID.uuid();y.inputs=[];const E=v.split("-id"),w=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=or(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 $=(V=this.inputs)==null?void 0:V.map((U,G)=>U.clone(i,A,w+"-input-map-"+G+"-id",p));return A.inputs=$,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=[],l=[],p=[],e=[];return this.inputs.forEach(v=>{if(!this.declaration.inputs.find(w=>{var A;return w.id===((A=v.declaration)==null?void 0:A.id)})){const w=v.remove({ignoreUpstream:!1},i);p.push(...w.removed),a.push(...w.updated)}}),this.inputs.filter((v,E)=>{const w=this.inputs.findIndex($=>$.declaration===v.declaration&&$!==v);if(w===-1)return!1;const A=this.inputs[w];return L(A==null?void 0:A.createdAt).isSame(L(v.createdAt))?E>w:!!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(l),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=[],l=[],p=[],e=[],y=this.declaration.inputs.filter(A=>A.parentRelationType===de.FixedArguments&&!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)}),this.inputs.sort((A,$)=>A.index-$.index);const{updated:v,added:E,removed:w}=this.removeUnrecognizedInputs(i);return a.push(...v),l.push(...E),p.push(...w),i==null||i.attemptAutoclose("sync-missing-fixed-inputs",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(e),self:this}}getUnusedInputs(){return this.inputs.filter(i=>i.suggestion||!i.readsValue&&!i.defaultValue)}getUnusedOutputs(){return[]}getUsedInputs(){return this.inputs.filter(i=>!i.suggestion&&(i.readsValue||i.defaultValue))}getUsedOutputs(){return[]}};g(Yt,"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,...l)=>null}),g(Yt,"type",f.Condition),g(Yt,"USER_MANAGED_PARENT_TYPES",[...Mr,f.Project]),g(Yt,"PARENT_TYPES",[...Yt.USER_MANAGED_PARENT_TYPES]),g(Yt,"MUTABLE_BASE_PROPERTIES",["operator"]),g(Yt,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),g(Yt,"BASE_PROPERTIES",[...Yt.MUTABLE_BASE_PROPERTIES,...Yt.INMUTABLE_BASE_PROPERTIES]),g(Yt,"MUTABLE_META_PROPERTIES",["x","y"]),g(Yt,"INMUTABLE_META_PROPERTIES",[...Yt.INMUTABLE_BASE_PROPERTIES]),g(Yt,"META_PROPERTIES",[...Yt.MUTABLE_META_PROPERTIES,...Yt.INMUTABLE_META_PROPERTIES]),g(Yt,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry","parent"]),g(Yt,"INMUTABLE_UPSTREAM_PROPERTIES",[]),g(Yt,"UPSTREAM_PROPERTIES",[...Yt.MUTABLE_UPSTREAM_PROPERTIES,...Yt.INMUTABLE_UPSTREAM_PROPERTIES]),g(Yt,"MUTABLE_DOWNSTREAM_PROPERTIES",["successCalls","errorCalls","inputsDeclarations","inputs"]),g(Yt,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),g(Yt,"DOWNSTREAM_PROPERTIES",[...Yt.MUTABLE_DOWNSTREAM_PROPERTIES,...Yt.INMUTABLE_DOWNSTREAM_PROPERTIES]),g(Yt,"PROPERTIES",[...Yt.META_PROPERTIES,...Yt.UPSTREAM_PROPERTIES,...Yt.DOWNSTREAM_PROPERTIES]);let oo=Yt;function Kj(d){var y;const u=lme(),i=d.toJSON();u.safeParse(i).success,(y=d.dataType)==null||y.validate(),d.inputs.forEach(v=>v.validate()),d.outputs.forEach(v=>v.validate()),d.internalCalls.forEach(v=>v.validate());const p=[...Ua(d),...Io(d),...kj(d)],e=Db(d);return p.push(...e),vr(d.errors,p)}function kj(d){const u=[],i=d.name;if(!i){const $=ft({id:`${d.id}--${ae.EmptyName}`,message:`Variable declaration "${ne(d,d.project)}" with id "${d.id}" does not have a name. Entities of type ${d.type} must have valid names.`,issue:null,severity:q.Error,code:ae.EmptyName,entity:d});return u.push($.error),u}const l=[...d.project.functions,...d.project.entities.flatMap($=>$.methods)].filter($=>$.id!==d.id),p=i.trim(),e=!l.some($=>$.name===i||$.name===p);if(!e){const $=ft({id:`${d.id}--${ae.NameNotUniqueInScope}`,message:`Variable declaration "${ne(d,d.project)}" with id "${d.id}" does not have a unique name. Entities of type ${d.type} must have valid names among all other entities of its type.`,issue:null,severity:q.Error,code:ae.NameNotUniqueInScope,entity:d});u.push($.error)}const y=jr(i);if(!!l.some($=>jr($.name)===y)&&e){const $=ft({id:`${d.id}--${ae.NameAsResolvedCodeNameNotUniqueInScope}`,message:`Variable declaration "${ne(d,d.project)}" with id "${d.id}" does not have a unique name once it is resolved as it will appear in code: "${y}". Entities of type ${d.type} must have valid names including their code name form.`,issue:null,severity:q.Error,code:ae.NameAsResolvedCodeNameNotUniqueInScope,entity:d});u.push($.error)}if(!/^[a-zA-Z_]/.test(i)){const $=ft({id:`${d.id}--${ae.NameMustStartWithLetterOrUnderscore}`,message:`Variable declaration "${ne(d,d.project)}" with id "${d.id}" has a name that does not start with a letter or underscore.`,issue:null,severity:q.Error,code:ae.NameMustStartWithLetterOrUnderscore,entity:d});u.push($.error)}const w=i.substring(1);if(!/^[a-zA-Z0-9_ ]*$/.test(w)){const $=ft({id:`${d.id}--${ae.NameCanOnlyContainLettersNumbersUnderscoreAndSpaces}`,message:`Variable declaration "${ne(d,d.project)}" with id "${d.id}" has a name that contains invalid characters. It can only contain letters, numbers, underscores and spaces.`,issue:null,severity:q.Error,code:ae.NameCanOnlyContainLettersNumbersUnderscoreAndSpaces,entity:d});u.push($.error)}return u}const zme=Object.freeze(Object.defineProperty({__proto__:null,validate:Kj,validateVariableDeclarationName:kj},Symbol.toStringTag,{value:"Module"}));function qj(d){const u=Cye(),i=d.toJSON();u.safeParse(i).success,d.inputs.forEach(y=>y.validate()),d.outputs.forEach(y=>y.validate()),d.internalCalls.forEach(y=>y.validate());const p=[...Ua(d),...Io(d)],e=Db(d);return p.push(...e),vr(d.errors,p)}const Xme=Object.freeze(Object.defineProperty({__proto__:null,validate:qj},Symbol.toStringTag,{value:"Module"}));var lA=(d=>(d.Parent="parent",d.DataTypeEntity="data-type-entity",d.VarDeclaration="var-declaration",d))(lA||{});const jt=class jt extends Nr{constructor(i,a){super(i);g(this,"initialData");g(this,"id");g(this,"x");g(this,"y");g(this,"type",f.VariableInstance);g(this,"defaultValue",null);g(this,"writesValues",[]);g(this,"readsValue",null);g(this,"declaration");g(this,"inputs",[]);g(this,"outputs",[]);g(this,"calledBySuccess",[]);g(this,"calledByError",[]);g(this,"calledByEntry",[]);g(this,"successCalls",[]);g(this,"errorCalls",[]);g(this,"internalCalls",[]);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.x=i.x,this.y=i.y}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.VariableInstance,declaration:null,internalCalls:[],successCalls:[],errorCalls:[],readsValue:null,writesValues:[],defaultValue:null,inputs:[],outputs:[],parent:null,calledByEntry:[],calledBySuccess:[],calledByError:[],x:0,y:0}}static fromGenerationTarget(i,a){let l=a;if(i.parent){const V=Z(i.parent);l=a.get(V)}const p=Z(i.declaration),e=a.get(p),y=i.calledByEntry.map(V=>{const U=Z(V);return a.get(U)}),v=i.calledBySuccess.map(V=>{const U=Z(V);return a.get(U)}),E=i.calledByError.map(V=>{const U=Z(V);return a.get(U)});let w=null;if(i.readsValue){const V=Z(i.readsValue);w=a.get(V)}const A={id:i.id,version:N.UUID.uuid(),createdAt:L().toISOString(),author:N.sessionAuthor,previousVersion:null,deleted:!1,type:f.VariableInstance,declaration:e.toReference(),calledByEntry:y,calledBySuccess:v,calledByError:E,defaultValue:null,errorCalls:[],successCalls:[],internalCalls:[],readsValue:w,inputs:[],outputs:[],writesValues:[],x:0,y:0,parent:l},$=te(A,a);return $.setParent(l,null),$}static validateGenerationTarget(i,a){let l=JSON.parse(JSON.stringify(i));const p=[],e=ni(l,{parent:{list:!1,types:[...Mr,f.Project],optional:!0},declaration:{list:!1,types:[f.VariableDeclaration]}},a);return l=e.modifiedData,p.push(...e.errors,...Br(l)),{errors:p,modifiedData:l}}get codeName(){var i;return(i=this.declaration)==null?void 0:i.codeName}get codeNativeValueValidation(){var i;return this._codeNativeValueValidation||((i=this.declaration)==null?void 0:i.codeNativeValueValidation)||null}validateGeneratedUpdate(i){const a=[];let l=JSON.parse(JSON.stringify(i));const p=zp(l,this);return l=p.modifiedData,a.push(...p.errors),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.
|
|
80
80
|
If an entity is called by another, they must be in the same scope, which means they have the same parent.
|
|
81
81
|
Specifically for variables, their scope is also calculated from their value readers and value writters.
|
|
82
82
|
You shouldn't have to manually update a 'parent' property. The equivalent result is to change its value readers, value writters, or callers.`,issue:null})),{errors:a,modifiedData:l}}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=[],l=[],p=[],e=[];return Object.values(this.detachedDependents).forEach(y=>{const v=y.entity.afterAllChildrenInitialized(i);a.push(...v.updated),l.push(...v.added),p.push(...v.removed),e.push(...v.affected)}),i==null||i.attemptAutoclose("sync-dependents",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(e),self:this}}onDetachedDependencyRemoved(i,a,l){const p=[],e=[],y=[],v=[];if(a==="parent"){const{updated:E,added:w,removed:A}=this.remove({ignoreUpstream:!1},l);p.push(...E),e.push(...w),y.push(...A)}if(a==="var-declaration"){const{updated:E,added:w,removed:A}=this.remove({ignoreUpstream:!1},l);p.push(...E),e.push(...w),y.push(...A)}return{updated:R(p),added:R(e),removed:R(y),affected:R(v),self:this}}onDetachedDependencyRestored(i,a,l){const p=[],e=[],y=[],v=[];if(a==="parent"){const{updated:E,added:w,removed:A}=this.restore({},l);p.push(...E),e.push(...w),y.push(...A)}if(a==="var-declaration"){const{updated:E,added:w,removed:A}=this.restore({},l);p.push(...E),e.push(...w),y.push(...A)}return{updated:R(p),added:R(e),removed:R(y),affected:R(v),self:this}}unsubscribeFromDependencies(){var i,a,l,p,e,y,v;return(a=(i=this.parent)==null?void 0:i.unsubscribeDependents)==null||a.call(i,[{entity:this,field:"parent"}]),(e=(p=(l=this.declaration.dataType)==null?void 0:l.entity)==null?void 0:p.unsubscribeDependents)==null||e.call(p,[{entity:this,field:"data-type-entity"}]),(v=(y=this.declaration)==null?void 0:y.unsubscribeDependents)==null||v.call(y,[{entity:this,field:"var-declaration"}]),this}subscribeToDependencies(){var i,a,l,p;return(i=this.parent)==null||i.subscribeDependents([{entity:this,field:"parent"}]),(p=(l=(a=this.declaration.dataType)==null?void 0:a.entity)==null?void 0:l.subscribeDependents)==null||p.call(l,[{entity:this,field:"data-type-entity"}]),this.declaration.subscribeDependents([{entity:this,field:"var-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 jt(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.internalCalls=[...this.internalCalls],i.successCalls=[...this.successCalls],i.errorCalls=[...this.errorCalls],i.writesValues=[...this.writesValues],i.readsValue=this.readsValue,i.defaultValue=this.defaultValue,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=[],l=[],p=[],e=[];if(this.parent){this.parent.increaseVersion(i);const y=this.parent.recursiveCaptureUpstreamVersions(i);a.push(this.parent,...y.updated),l.push(...y.added),p.push(...y.removed)}return{updated:R(a),added:R(l),removed:R(p),affected:R(e),self:this}}async restoreVersion(i){var v;const a=[],l=[],p=[],e=[];if(this.version===i)return{updated:R(a),added:R(l),removed:R(p),affected:R(e),self:this};if(!this.knownVersions){const E=new Map;for(const[w,A]of this.knownVersions||new Map){if(E.set(w,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 jt(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.internalCalls=y.internalCalls,this.successCalls=y.successCalls,this.errorCalls=y.errorCalls,this.writesValues=y.writesValues,this.readsValue=y.readsValue,this.defaultValue=y.defaultValue,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(l),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 l=Z(i.parent),p=this.project.get(l),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 '${l}' 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.readsValue){const l=Z(i.readsValue),p=this.project.get(l),e=this.readsValue;e&&e.id!==(p==null?void 0:p.id)&&this.removeValueWriter(a),p&&this.setValueWriter(p,a)}if(i.declaration){const l=Z(i.declaration),p=this.project.get(l);p&&this.setDeclaration(p)}return i.calledByEntry.forEach(l=>{const p=Z(l),e=this.project.get(p);e&&(this.addEntryCaller(e,a),e.addCall(this,a))}),[...this.calledByEntry].forEach(l=>{i.calledByEntry.find(e=>Z(e)===l.id)||(this.removeCaller(l,a),l.removeCall(this,a))}),i.calledBySuccess.forEach(l=>{const p=Z(l),e=this.project.get(p);e&&(this.addSuccessCaller(e,a),e.addSuccessCall(this,a))}),[...this.calledBySuccess].forEach(l=>{i.calledBySuccess.find(e=>Z(e)===l.id)||(this.removeCaller(l,a),l.removeCall(this,a))}),i.calledByError.forEach(l=>{const p=Z(l),e=this.project.get(p);e&&(this.addErrorCaller(e,a),e.addErrorCall(this,a))}),[...this.calledBySuccess].forEach(l=>{i.calledBySuccess.find(e=>Z(e)===l.id)||(this.removeCaller(l,a),l.removeCall(this,a))}),this.captureVersion(),this.subscribeToDependencies(),a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),this}hydrateAncestors(){const i=[],a=[],l=[],p=[];if(this.initialData.parent){const e=Z(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.readsValue){const e=Z(this.initialData.readsValue),y=this.project.get(e);y&&(this.setValueWriter(y,null),i.push(y))}if(this.initialData.declaration){const e=Z(this.initialData.declaration),y=this.project.get(e);y&&(this.setDeclaration(y),i.push(y))}return this.initialData.calledByEntry.forEach(e=>{const y=Z(e),v=this.project.get(y);v&&this.addEntryCaller(v,null)}),this.initialData.calledBySuccess.forEach(e=>{const y=Z(e),v=this.project.get(y);v&&this.addSuccessCaller(v,null)}),this.initialData.calledByError.forEach(e=>{const y=Z(e),v=this.project.get(y);v&&this.addErrorCaller(v,null)}),{updated:R(i),added:R(a),removed:R(l),affected:R(p),self:this}}afterAllChildrenInitialized(i=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"after-all-children-initialized"))){var $e;const a=[],l=[],p=[],e=[];if(this.initialized=!0,!this.declaration.dataType||($e=this.declaration.dataType)!=null&&$e.inferred){const{added:Pe,updated:Je,removed:Fe,affected:lt}=this.declaration.inferDataTypeAndSyncInstancesInputsAndOutputs(i);l.push(...Pe),a.push(...Je),p.push(...Fe),e.push(...lt)}const{added:y,updated:v,removed:E,affected:w}=this.syncInputs(i);l.push(...y),a.push(...v),p.push(...E),e.push(...w);const{added:A,updated:$,removed:V,affected:U}=this.syncOutputs(i);l.push(...A),a.push(...$),p.push(...V),e.push(...U);const{added:G,updated:K,removed:J,affected:ie}=this.generateUnusedInternalCalls(i);l.push(...G),a.push(...K),p.push(...J),e.push(...ie);const{added:X,updated:ue,removed:re,affected:fe}=this.removeUnrecognizedInputs(i);l.push(...X),a.push(...ue),p.push(...re),e.push(...fe);const{added:Y,updated:H,removed:ce,affected:z}=this.removeUnrecognizedOutputs(i);l.push(...Y),a.push(...H),p.push(...ce),e.push(...z);const{added:oe,updated:we,removed:xe,affected:Ne}=this.removeUnrecognizedInternalCalls(i);return l.push(...oe),a.push(...we),p.push(...xe),e.push(...Ne),this.captureVersion(),i==null||i.attemptAutoclose("after-all-children-initialized",this.id),{updated:R(a),added:R(l),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"))){const a=[this],l=[],p=[],e=[];return this.parent===this.project&&this.project.addVariableInstance(this),this.readsValue&&(this.readsValue.addValueReader(this,i),a.push(this.readsValue)),this.writesValues.forEach(y=>{y.setValueWriter(this,i),a.push(y)}),this.successCalls.forEach(y=>{y.addSuccessCaller(this,i),a.push(y)}),this.errorCalls.forEach(y=>{y.addErrorCaller(this,i),a.push(y)}),this.calledBySuccess.forEach(y=>{y.addSuccessCall(this,i),a.push(y)}),this.calledByError.forEach(y=>{y.addErrorCall(this,i),a.push(y)}),this.calledByEntry.forEach(y=>{y.addCall(this,i),a.push(y)}),this.subscribe(),this.subscribeToDependencies(),i==null||i.attemptAutoclose("add-self-to-project",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(e),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}get usedInputs(){return this.inputs.filter(i=>i.readsValue||i.defaultValue)}get unusedInputs(){return this.inputs.filter(i=>!i.readsValue&&!i.defaultValue)}get usedOutputs(){return this.outputs.filter(i=>i.writesValues.length)}get unusedOutputs(){return this.outputs.filter(i=>!i.writesValues.length)}get usedInternalCalls(){return this.internalCalls.filter(i=>!!i.calledBy.length)}get unusedInternalCalls(){const i=this.usedInternalCalls;return this.internalCalls.filter(l=>!(i.find(y=>y.id===l.id)||i.find(y=>y.declaration===l.declaration)))}removeInternalCall(i,a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-variable-instance-internal-call"))){const l=this.internalCalls.findIndex(p=>p.id===i.id);return l>-1&&(this.internalCalls.splice(l,1),a&&(a==null||a.add(this,S.Affected))),a==null||a.attemptAutoclose("remove-variable-instance-internal-call",this.id),this}removeInput(i,a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-input"))){const l=this.inputs.findIndex(p=>p.id===i.id);return l>-1&&(this.inputs.splice(l,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 l=this.outputs.findIndex(p=>p.id===i.id);return l>-1&&(this.outputs.splice(l,1),a&&(a==null||a.add(this,S.Affected))),a==null||a.attemptAutoclose("remove-output",this.id),this}addSuccessCaller(i,a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-success-caller")),l=!1){return this.calledBySuccess.find(p=>p.id===i.id)||(this.calledBySuccess.push(i),a==null||a.add(this,S.Updated),l&&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")),l=!1){return this.calledByError.find(p=>p.id===i.id)||(this.calledByError.push(i),a==null||a.add(this,S.Updated),l&&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")),l=!1){return this.calledByEntry.find(p=>p.id===i.id)||(this.calledByEntry.push(i),a==null||a.add(this,S.Updated),l&&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")),l=!1){return this.errorCalls.find(p=>p.id===i.id)||(this.errorCalls.push(i),l&&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")),l=!1){return this.successCalls.find(p=>p.id===i.id)||(this.successCalls.push(i),l&&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")),l=!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)),l&&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")),l=!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)),l&&We(this,a),a==null||a.attemptAutoclose("remove-caller",this.id),this}addValueReader(i,a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-value-reader"))){return this.writesValues.includes(i)?(a==null||a.attemptAutoclose("add-value-reader",this.id),this):(this.writesValues.push(i),a==null||a.add(this,S.Affected),this)}setParent(i,a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"set-parent"))){var l;return((l=this.parent)==null?void 0:l.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}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.defaultValue&&(this.defaultValue=te(this.initialData.defaultValue,this.project),this.defaultValue.setParent(this,null),this.defaultValue.initChildren(i)),this.initialData.declaration.type===f.GenericReference){const a=this.project.findSubscribedInstanceFromReference(this.initialData.declaration);if(!a)return this;this.declaration=a}else this.declaration=te(this.initialData.declaration,this.project),this.declaration.initChildren(i);return df.initWritesValues(this,this.parent),lf.initReadsValue(this),this.initialData.inputs.forEach(a=>{const l=te(a,this.project);return l.setParent(this,null),l.initChildren(i),this.addInput(l,null),l}),this.initialData.outputs.forEach(a=>{const l=te(a,this.project);return l.setParent(this,null),l.initChildren(i),this.addOutput(l,i),l}),this.successCalls=this.initialData.successCalls.map(a=>{const l=te(a,this.project);if(l.addSuccessCaller(this),[f.BreakStatement,f.ContinueStatement].includes(l.type))l.setParent(this.parent.parent,null),l.initChildren(i);else if(l.type===f.ReturnStatement){const p=Wr(this,this.project);l.setParent(p,null),l.initChildren(i)}else l.type!==f.InternalCall&&(l.setParent(this.parent,null),l.initChildren(i));return l}),this.errorCalls=this.initialData.errorCalls.map(a=>{const l=te(a,this.project);if(l.addErrorCaller(this),[f.BreakStatement,f.ContinueStatement].includes(l.type))l.setParent(this.parent.parent,null),l.initChildren(i);else if(l.type===f.ReturnStatement){const p=Wr(this,this.project);l.setParent(p,null),l.initChildren(i)}else l.type!==f.InternalCall&&(l.setParent(this.parent,null),l.initChildren(i));return l}),this.internalCalls=this.initialData.internalCalls.reduce((a,l)=>{if(l.type===f.GenericReference){const p=this.project.findSubscribedInstanceFromReference(l);if(!p)return a;const e=p;return e.setParent(this,null),[...a,e]}else{const p=te(l,this.project);return p.setParent(this,null),p.initChildren(i),[...a,p]}},[]),this.subscribeToDependencies(),this.afterAllChildrenInitialized(i),i==null||i.attemptAutoclose("init-children",this.id),this}setValueWriter(i,a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"set-value-writer"))){return this.readsValue!==i&&(this.readsValue=i,a==null||a.add(this,S.Updated)),a==null||a.attemptAutoclose("set-value-writer",this.id),this}removeValueWriter(i=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-value-writer"))){return this.readsValue&&(this.readsValue=null,i==null||i.add(this,S.Updated)),i==null||i.attemptAutoclose("remove-value-writer",this.id),this}removeValueReader(i,a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-value-reader"))){return this.writesValues.includes(i)?(this.writesValues=this.writesValues.filter(l=>l.id!==i.id),a==null||a.add(this,S.Affected),this):(a==null||a.attemptAutoclose("remove-value-reader",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 l=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):l&&(a==null||a.add(this,S.Updated)),a==null||a.attemptAutoclose("meta-sync",this.id),this}async APILoad(i=ve,...a){return await jt.repository.APILoad(this.id,...a),this}async APICreate(i=ve,...a){return await jt.repository.APICreate(this.toShallowJSON(),...a),this}async APIUpdate(i=ve,...a){return await jt.repository.APIUpdate(this.toShallowJSON(),...a),this}async APIDelete(i=ve,...a){return await jt.repository.APIDelete(this.toShallowJSON(),...a),this}async APIClone(i=ve,...a){return await jt.repository.APIClone(this.id,...a),this}async APILoadVersion(i=ve,a,...l){return await jt.repository.APILoadVersion(this.id,a,...l)}removeFromParent(i=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-from-parent"))){const a=[],l=[],p=[],e=[];return this.parent.type===f.Project?(this.parent.removeVariableInstance(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(l),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"))){const l=[],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(v=>{const{updated:E,removed:w,added:A}=v.entity.onDetachedDependencyRemoved(this,v.field,a);l.push(...E),p.push(...w),e.push(...A)}),this.defaultValue){const{updated:v,removed:E}=this.defaultValue.remove({ignoreUpstream:!0},a);l.push(...v),p.push(...E)}if(this.readsValue&&(l.push(this.readsValue),this.readsValue.removeValueReader(this,a)),this.writesValues.forEach(v=>{l.push(v),v.setValueWriter(null,a)}),this.inputs.forEach(v=>{const{updated:E,removed:w}=v.remove({ignoreUpstream:!0},a);l.push(...E),p.push(...w)}),this.outputs.forEach(v=>{const{updated:E,removed:w}=v.remove({ignoreUpstream:!0},a);l.push(...E),p.push(...w)}),this.successCalls.forEach(v=>{l.push(v),v.removeCaller(this,a)}),this.errorCalls.forEach(v=>{l.push(v),v.removeCaller(this,a)}),this.internalCalls.forEach(v=>{const{updated:E,removed:w}=v.remove({ignoreUpstream:!0},a);l.push(...E),p.push(...w)}),!i){const v=this.removeFromParent(a);e.push(...v.added),l.push(...v.updated),p.push(...v.removed),y.push(...v.affected),this.calledBy.forEach(E=>{l.push(E),E.removeCall(this,a)})}return a==null||a.attemptAutoclose("remove-entity",this.id),{added:R(e),updated:R(l),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=[],l=[],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:w}=y.entity.onDetachedDependencyRestored(this,y.field,i);l.push(...v),p.push(...E),a.push(...w)}),this.defaultValue){const{updated:y}=this.defaultValue.restore({},i);l.push(...y)}return this.readsValue&&(l.push(this.readsValue),this.readsValue.addValueReader(this,i)),this.writesValues.forEach(y=>{l.push(y),y.setValueWriter(this,i)}),this.inputs.forEach(y=>{const{updated:v}=y.restore({},i);l.push(...v)}),this.outputs.forEach(y=>{const{updated:v}=y.restore({},i);l.push(...v)}),this.successCalls.forEach(y=>{l.push(y),y.addSuccessCaller(this,i)}),this.errorCalls.forEach(y=>{l.push(y),y.addErrorCaller(this,i)}),this.internalCalls.forEach(y=>{const{updated:v}=y.restore({},i);l.push(...v)}),this.calledBySuccess.forEach(y=>{l.push(y),y.addSuccessCall(this,i)}),this.calledByError.forEach(y=>{l.push(y),y.addErrorCall(this,i)}),this.calledByEntry.forEach(y=>{l.push(y),y.addCall(this,i)}),i==null||i.attemptAutoclose("restore-entity",this.id),{added:R(a),updated:R(l),removed:R(p),affected:R(e),self:this}}toFlat(i=new Set){var l,p;return i.has(this.id)?[]:(i.add(this.id),[this,...((l=this.defaultValue)==null?void 0:l.toFlat(i))||[],...this.writesValues.flatMap(e=>e.toFlat(i)),...((p=this.readsValue)==null?void 0:p.toFlat(i))||[],...this.successCalls.flatMap(e=>e.toFlat(i)),...this.errorCalls.flatMap(e=>e.toFlat(i)),...this.inputs.flatMap(e=>e.toFlat(i)),...this.outputs.flatMap(e=>e.toFlat(i)),...this.internalCalls.flatMap(e=>e.toFlat(i))])}toFlatIds(i=new Set){var l;return i.has(this.id)?[]:(i.add(this.id),[this.id,...((l=this.defaultValue)==null?void 0:l.toFlatIds(i))||[],...this.writesValues.flatMap(p=>p.toFlatIds(i)),...this.successCalls.flatMap(p=>p.toFlatIds(i)),...this.errorCalls.flatMap(p=>p.toFlatIds(i)),...this.inputs.flatMap(p=>p.toFlatIds(i)),...this.outputs.flatMap(p=>p.toFlatIds(i)),...this.internalCalls.flatMap(p=>p.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,l;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,declaration:this.declaration.toJSON(i),defaultValue:((a=this.defaultValue)==null?void 0:a.toJSON(i))||null,readsValue:((l=this.readsValue)==null?void 0:l.toReference())||null,writesValues:this.writesValues.map(p=>p.toJSON(i)),inputs:this.inputs.map(p=>p.toJSON(i)),outputs:this.outputs.map(p=>p.toJSON(i)),successCalls:this.successCalls.map(p=>p.toJSON(i)),errorCalls:this.errorCalls.map(p=>p.toJSON(i)),internalCalls:this.internalCalls.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()),parent:this.parent.toReference(),x:this.x,y:this.y})}toJSONClone(i=ke){var l,p,e,y,v,E,w;let a;return(l=i.seenEntityMaps)!=null&&l.has(this.id)?a=i.seenEntityMaps.get(this.id):(a=i.newId||Gr(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,defaultValue:((E=this.defaultValue)==null?void 0:E.toJSONClone({...i,newId:null}))||null,declaration:this.declaration.toReference({seenEntityMaps:i.seenEntityMaps}),readsValue:((w=this.readsValue)==null?void 0:w.toReference({seenEntityMaps:i.seenEntityMaps}))||null,writesValues:this.writesValues.map(A=>A.toJSONClone({...i,newId:null})),inputs:this.inputs.map(A=>A.toJSONClone({...i,newId:null})),outputs:this.outputs.map(A=>A.toJSONClone({...i,newId:null})),successCalls:this.successCalls.map(A=>A.toJSONClone({...i,newId:null})),errorCalls:this.errorCalls.map(A=>A.toJSONClone({...i,newId:null})),internalCalls:this.internalCalls.map(A=>this.calledBy.length||this.readsValue?A.toJSONClone({...i,newId:null}):A.toReference({seenEntityMaps:i.seenEntityMaps})),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})),parent:this.parent.toReference({seenEntityMaps:i.seenEntityMaps}),x:this.x,y:this.y})}toReference(i=ke){var l;let a=this.id;return(l=i.seenEntityMaps)!=null&&l.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 l,p,e,y;let a=this.id;return(l=i.seenEntityMaps)!=null&&l.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,defaultValue:((p=this.defaultValue)==null?void 0:p.toReference(i))||null,declaration:((e=this.declaration)==null?void 0:e.toReference(i))||null,readsValue:((y=this.readsValue)==null?void 0:y.toReference(i))||null,writesValues:this.writesValues.map(v=>v.toReference(i)),inputs:this.inputs.map(v=>v.toReference(i)),outputs:this.outputs.map(v=>v.toReference(i)),successCalls:this.successCalls.map(v=>v.toReference(i)),errorCalls:this.errorCalls.map(v=>v.toReference(i)),calledBySuccess:this.calledBySuccess.map(v=>v.toReference(i)),calledByError:this.calledByError.map(v=>v.toReference(i)),calledByEntry:this.calledByEntry.map(v=>v.toReference(i)),internalCalls:this.internalCalls.map(v=>v.toReference(i)),parent:this.parent.toReference(i)}}toFlatJSON(i=new Set){var l,p;return i.has(this.id)?[]:(i.add(this.id),[this.toShallowJSON(),...((l=this.defaultValue)==null?void 0:l.toFlatJSON(i))||[],...((p=this.declaration)==null?void 0:p.toFlatJSON(i))||[],...this.writesValues.flatMap(e=>e.toFlatJSON(i)),...this.successCalls.flatMap(e=>e.toFlatJSON(i)),...this.errorCalls.flatMap(e=>e.toFlatJSON(i)),...this.inputs.flatMap(e=>e.toFlatJSON(i)),...this.outputs.flatMap(e=>e.toFlatJSON(i)),...this.internalCalls.flatMap(e=>e.toFlatJSON(i)),...this.calledBy.flatMap(e=>e.toFlatJSON(i))])}toGenerationTarget(){const i=this.parent.type===f.Project?void 0:this.parent.id;return{id:this.id,type:this.type,declaration:this.declaration.id,calledByEntry:this.calledByEntry.map(a=>a.id),calledBySuccess:this.calledBySuccess.map(a=>a.id),calledByError:this.calledByError.map(a=>a.id),parent:i}}toFlatGenerationTarget(i=new Set){var l,p,e;return i.has(this.id)?[]:(i.add(this.id),[this.toGenerationTarget(),...((l=this.defaultValue)==null?void 0:l.toFlatGenerationTarget(i))||[],...((p=this.declaration)==null?void 0:p.toFlatGenerationTarget(i))||[],...((e=this.readsValue)==null?void 0:e.toFlatGenerationTarget(i))||[],...this.writesValues.flatMap(y=>y.toFlatGenerationTarget(i)),...this.successCalls.flatMap(y=>y.toFlatGenerationTarget(i)),...this.errorCalls.flatMap(y=>y.toFlatGenerationTarget(i)),...this.inputs.flatMap(y=>y.toFlatGenerationTarget(i)),...this.outputs.flatMap(y=>y.toFlatGenerationTarget(i)),...this.internalCalls.flatMap(y=>y.toFlatGenerationTarget(i))])}clearErrors(){var i;return this.errors=[],(i=this.defaultValue)==null||i.clearErrors(),this.inputs.forEach(a=>a.clearErrors()),this.outputs.forEach(a=>a.clearErrors()),this.successCalls.forEach(a=>a.clearErrors()),this.errorCalls.forEach(a=>a.clearErrors()),this.internalCalls.forEach(a=>a.clearErrors()),this}validate(){const i=qj(this);return this.errors=i,{success:!0,error:null,data:this.toJSON()}}getErrors(){var a,l;return[...this.errors,...((a=this.defaultValue)==null?void 0:a.getErrors())||[],...this.inputs.flatMap(p=>p.getErrors()),...this.internalCalls.flatMap(p=>p.getErrors()),...this.outputs.flatMap(p=>p.getErrors()),...((l=this.readsValue)==null?void 0:l.getErrors())||[]]}getShallowErrors(){return this.errors}getDefaultValue(){var i;return this.defaultValue||((i=this.declaration)==null?void 0:i.defaultValue)||null}setDefaultValue(i,a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"set-default-value"))){const l=this.defaultValue;return(l==null?void 0:l.id)!==(i==null?void 0:i.id)&&(l==null||l.remove({ignoreUpstream:!0},a),this.defaultValue=i,a==null||a.add(this,S.Affected)),a==null||a.attemptAutoclose("set-default-value",this.id),this}clone(i=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"clone-entity")),a=null,l=null,p=!0){var U,G,K,J;let e=Fr(a,this);const y=this.toJSON(),v=l||N.UUID.uuid();y.inputs=[],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 E=or(y,e);a?E.setParent(a,null):E.setParent(this.parent,null),p&&E.subscribe(),E.initChildren(i),i==null||i.add(E,S.Added);const w=(U=this.defaultValue)==null?void 0:U.clone(i,E,N.UUID.uuid(),p);E.defaultValue=w||null;const A=(G=this.inputs)==null?void 0:G.map(ie=>ie.clone(i,E,N.UUID.uuid(),p));E.inputs=A;const $=(K=this.outputs)==null?void 0:K.map(ie=>ie.clone(i,E,N.UUID.uuid(),p));E.outputs=$;const V=(J=this.internalCalls)==null?void 0:J.map(ie=>ie.clone(i,E,N.UUID.uuid(),p));return E.internalCalls=V,i==null||i.attemptAutoclose("clone-entity",this.id),E}addInternalCall(i){return this.internalCalls.find(a=>a===i)||this.internalCalls.push(i),this}setDeclaration(i){return this.declaration!==i&&(this.declaration=i),this}removeUnrecognizedInputs(i=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-unrecognized-variable-instance-inputs"))){const a=[],l=[],p=[],e=[];return this.declaration.dataType&&!this.declaration.dataType.isObject()?[...this.inputs].forEach(y=>{const v=y.remove({ignoreUpstream:!1},i);p.push(...v.removed),a.push(...v.updated)}):this.declaration.dataType&&this.declaration.dataType.hasStrictObjectStructure()&&[...this.inputs].forEach(y=>{var E;if(!y.declaration){const w=y.remove({ignoreUpstream:!1},i);p.push(...w.removed),a.push(...w.updated);return}if(![...((E=this.declaration.dataType)==null?void 0:E.entity).allProperties].find(w=>y.declaration===w)){const w=y.remove({ignoreUpstream:!1},i);p.push(...w.removed),a.push(...w.updated)}}),i==null||i.attemptAutoclose("remove-unrecognized-variable-instance-inputs",this.id),{updated:R(a),added:R(l),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-variable-instance-outputs"))){const a=[],l=[],p=[],e=[];return this.declaration.dataType&&!this.declaration.dataType.isObject()?[...this.outputs].forEach(y=>{const v=y.remove({ignoreUpstream:!1},i);p.push(...v.removed),a.push(...v.updated)}):this.declaration.dataType&&this.declaration.dataType.hasStrictObjectStructure()&&[...this.outputs].forEach(y=>{var E;if(!y.declaration){const w=y.remove({ignoreUpstream:!1},i);p.push(...w.removed),a.push(...w.updated);return}if(![...((E=this.declaration.dataType)==null?void 0:E.entity).allProperties].find(w=>y.declaration===w)){const w=y.remove({ignoreUpstream:!1},i);p.push(...w.removed),a.push(...w.updated)}}),i==null||i.attemptAutoclose("remove-unrecognized-variable-instance-outputs",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(e),self:this}}removeUnrecognizedInternalCalls(i=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-unrecognized-variable-declaration-internal-calls"))){var v;const a=[],l=[],p=[],e=[];if(!this.declaration.dataType||!this.declaration.dataType.entity||![f.DefinitionEntity,f.PrimitiveEntity,f.BuiltInBaseEntity].includes(this.declaration.dataType.entity.type))[...this.internalCalls].forEach(E=>{const w=E.remove({ignoreUpstream:!1},i);p.push(...w.removed),a.push(...w.updated)});else if(this.declaration.dataType&&this.declaration.dataType.entity&&[f.DefinitionEntity,f.PrimitiveEntity,f.BuiltInBaseEntity].includes(this.declaration.dataType.entity.type)){const E=[...((v=this.declaration.dataType)==null?void 0:v.entity).allMethods];[...this.internalCalls].forEach(w=>{if(!w.declaration){const $=w.remove({ignoreUpstream:!1},i);p.push(...$.removed),a.push(...$.updated);return}if(!E.find($=>w.declaration===$)){const $=w.remove({ignoreUpstream:!1},i);p.push(...$.removed),a.push(...$.updated);return}})}return this.internalCalls.filter((E,w)=>{const A=this.internalCalls.findIndex(V=>V.declaration===E.declaration&&V!==E);if(A===-1)return!1;const $=this.internalCalls[A];return L($==null?void 0:$.createdAt).isSame(L(E.createdAt))?w>A:!!L($==null?void 0:$.createdAt).isAfter(E.createdAt)}).forEach(E=>{const w=E.remove({ignoreUpstream:!1},i);p.push(...w.removed),a.push(...w.updated)}),i==null||i.attemptAutoclose("remove-unrecognized-variable-declaration-internal-calls",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(e),self:this}}syncInputs(i=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"sync-variable-instance-inputs"))){const a=[],l=[],p=[],e=[];if(this.declaration.dataType)if(this.declaration.dataType.entity){if([f.DefinitionEntity,f.PrimitiveEntity,f.BuiltInBaseEntity].includes(this.declaration.dataType.entity.type)&&!this.declaration.dataType.isList){const y=[...this.declaration.dataType.entity.properties];y.filter(A=>!A.getDataType(i)).forEach(A=>{const $=this.inputs.find(G=>ne(G,this.project)===ne(A,this.project));if(!$)return;const V=this.declaration.getMasterInputWithValueWritterFromAllInstances($);if(!V)return;const U=yn(V);A.setDataType(U,i),$.setDeclaration(A,i)}),y.filter(A=>!this.inputs.find($=>{var V;return((V=$.declaration)==null?void 0:V.id)===A.id})).forEach(A=>{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,parent:this.toReference(),name:null,description:null,codeName:null,declaration:A,defaultValue:null,index:A.index,readsValue:null},V=te($,this.project);return V.setParent(this,i),V.initChildren(i),i==null||i.add(V,S.Added),this.addInput(V,i),V}),this.inputs.filter(A=>!A.declaration).forEach(A=>{const $=y.find(V=>ne(V,this.project)===ne(A,this.project));$&&A.setDeclaration($,i)})}}else return i==null||i.attemptAutoclose("sync-variable-instance-inputs",this.id),{added:[],updated:[],removed:[],affected:[],self:this};else return i==null||i.attemptAutoclose("sync-variable-instance-inputs",this.id),{added:[],updated:[],removed:[],affected:[],self:this};return i==null||i.attemptAutoclose("sync-variable-instance-inputs",this.id),{added:R(a),updated:R(l),removed:R(p),affected:R(e),self:this}}syncOutputs(i=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"sync-variable-instance-outputs"))){const a=[],l=[],p=[],e=[];if(this.declaration.dataType)if(this.declaration.dataType.entity)[f.DefinitionEntity,f.PrimitiveEntity,f.BuiltInBaseEntity].includes(this.declaration.dataType.entity.type)&&!this.declaration.dataType.isList&&[...this.declaration.dataType.entity.properties].filter(E=>!this.outputs.find(w=>w.declaration===E)).map(E=>{const w={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,parent:this.toReference(),defaultValue:null,declaration:E,index:E.index,writesValues:[]},A=te(w,this.project);return A.setParent(this,i),A.initChildren(i),i==null||i.add(A,S.Added),this.addOutput(A,i),A});else return i==null||i.attemptAutoclose("sync-variable-instance-outputs",this.id),{added:[],updated:[],removed:[],affected:[],self:this};else return i==null||i.attemptAutoclose("sync-variable-instance-outputs",this.id),{added:[],updated:[],removed:[],affected:[],self:this};return i==null||i.attemptAutoclose("sync-variable-instance-outputs",this.id),{added:R(a),updated:R(l),removed:R(p),affected:R(e),self:this}}generateUnusedInternalCalls(i=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"generate-unused-internal-calls"))){const a=[],l=[],p=[],e=[];if(this.declaration.dataType)if(this.declaration.dataType.entity)[f.DefinitionEntity,f.PrimitiveEntity,f.BuiltInBaseEntity].includes(this.declaration.dataType.entity.type)&&!this.declaration.dataType.isList&&[...this.declaration.dataType.entity.getAllInteractiveMethods()].filter(E=>!this.internalCalls.find(A=>{var V,U,G,K,J;return(((V=A.declaration)==null?void 0:V.id)||((G=(U=A.initialData)==null?void 0:U.declaration)==null?void 0:G.entityId)||((J=(K=A.initialData)==null?void 0:K.declaration)==null?void 0:J.id))===E.id})).map(E=>{const w=E.createInternalCall(i,this);return i==null||i.add(w,S.Added),this.addInternalCall(w),w});else return i==null||i.attemptAutoclose("generate-unused-internal-calls",this.id),{added:[],updated:[],removed:[],affected:[],self:this};else return i==null||i.attemptAutoclose("generate-unused-internal-calls",this.id),{added:[],updated:[],removed:[],affected:[],self:this};return i==null||i.attemptAutoclose("generate-unused-internal-calls",this.id),{added:R(a),updated:R(l),removed:R(p),affected:R(e),self:this}}getDataType(i=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"get-data-type"))){var a;return((a=this.declaration)==null?void 0:a.getDataType(i))||null}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(jt,"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,...l)=>null}),g(jt,"type",f.VariableInstance),g(jt,"USER_MANAGED_PARENT_TYPES",[...Mr,f.Project]),g(jt,"PARENT_TYPES",[...jt.USER_MANAGED_PARENT_TYPES]),g(jt,"MUTABLE_BASE_PROPERTIES",[]),g(jt,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),g(jt,"BASE_PROPERTIES",[...jt.MUTABLE_BASE_PROPERTIES,...jt.INMUTABLE_BASE_PROPERTIES]),g(jt,"MUTABLE_META_PROPERTIES",[...jt.MUTABLE_BASE_PROPERTIES,"x","y"]),g(jt,"INMUTABLE_META_PROPERTIES",[...jt.INMUTABLE_BASE_PROPERTIES]),g(jt,"META_PROPERTIES",[...jt.MUTABLE_META_PROPERTIES,...jt.INMUTABLE_META_PROPERTIES]),g(jt,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry","readsValue"]),g(jt,"INMUTABLE_UPSTREAM_PROPERTIES",["declaration","parent"]),g(jt,"UPSTREAM_PROPERTIES",[...jt.MUTABLE_UPSTREAM_PROPERTIES,...jt.INMUTABLE_UPSTREAM_PROPERTIES]),g(jt,"MUTABLE_DOWNSTREAM_PROPERTIES",["writesValues","inputs","outputs","successCalls","errorCalls","internalCalls"]),g(jt,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),g(jt,"DOWNSTREAM_PROPERTIES",[...jt.MUTABLE_DOWNSTREAM_PROPERTIES,...jt.INMUTABLE_DOWNSTREAM_PROPERTIES]),g(jt,"PROPERTIES",[...jt.META_PROPERTIES,...jt.UPSTREAM_PROPERTIES,...jt.DOWNSTREAM_PROPERTIES]);let lo=jt;var Jj=(d=>(d.Parent="parent",d.DataTypeEntity="variable-data-type-entity",d.DataType="variable-data-type",d))(Jj||{});const xt=class xt extends Nr{constructor(i,a){super(i);g(this,"initialData");g(this,"id");g(this,"name");g(this,"codeName",null);g(this,"description",null);g(this,"required",!1);g(this,"constant",!1);g(this,"x");g(this,"y");g(this,"type",f.VariableDeclaration);g(this,"defaultValue",null);g(this,"dataType",null);g(this,"writesValues",[]);g(this,"readsValue",null);g(this,"inputs",[]);g(this,"outputs",[]);g(this,"calledBySuccess",[]);g(this,"calledByError",[]);g(this,"calledByEntry",[]);g(this,"successCalls",[]);g(this,"errorCalls",[]);g(this,"internalCalls",[]);g(this,"parent");g(this,"errors",[]);g(this,"project");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.name=i.name,this.description=i.description,this.constant=i.constant,this.codeName=i.codeName,this.required=i.required,this.x=i.x,this.y=i.y}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.VariableDeclaration,name:"",codeName:null,description:"",dataType:null,internalCalls:[],successCalls:[],errorCalls:[],readsValue:null,writesValues:[],defaultValue:null,constant:!1,required:!1,inputs:[],outputs:[],parent:null,calledByEntry:[],calledBySuccess:[],calledByError:[],x:0,y:0}}static fromGenerationTarget(i,a){let l=a;if(i.parent){const A=Z(i.parent);l=a.get(A)}const p=i.calledByEntry.map(A=>{const $=Z(A);return a.get($)}),e=i.calledBySuccess.map(A=>{const $=Z(A);return a.get($)}),y=i.calledByError.map(A=>{const $=Z(A);return a.get($)});let v=null;if(i.readsValue){const A=Z(i.readsValue);v=a.get(A)}const E={id:i.id,version:N.UUID.uuid(),createdAt:L().toISOString(),author:N.sessionAuthor,previousVersion:null,deleted:!1,type:f.VariableDeclaration,name:i.name,defaultValue:null,codeName:i.codeName||null,description:i.description||null,constant:i.constant||!1,required:i.required||!1,calledByEntry:p,calledBySuccess:e,calledByError:y,dataType:null,errorCalls:[],successCalls:[],internalCalls:[],readsValue:v,inputs:[],outputs:[],writesValues:[],x:0,y:0,parent:l},w=te(E,a);return w.setParent(l,null),w}static validateGenerationTarget(i,a){let l=JSON.parse(JSON.stringify(i));const p=[],e=ni(l,{parent:{list:!1,types:[...Mr,f.Project],optional:!0}},a);l=e.modifiedData;const y=qb(l,a);return p.push(...e.errors,...y,...Br(l)),{errors:p,modifiedData:l}}get variableInstances(){const i=[];return Object.values(this.detachedDependents).forEach(a=>{a.field===lA.VarDeclaration&&!i.includes(a.entity)&&i.push(a.entity)}),i}validateGeneratedUpdate(i){const a=[];let l=JSON.parse(JSON.stringify(i));const p=zp(l,this);return l=p.modifiedData,a.push(...p.errors),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.
|
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.6408",
|
|
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",
|