@elyx-code/project-logic-tree 0.0.6798 → 0.0.6800

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.cjs CHANGED
@@ -129,7 +129,7 @@ This variable's data-type 'entity' is a non-interactive 'built-in-base-entity'.`
129
129
  The declaration of the internal-call must be a 'function-declaration' entity which exists as a method in the entity of the data-type of the parent variable.${V}`})):e.push(new _e({id:`${a.id}--${De.InternalCallDeclarationNotFoundInParentDatatypeEntity}`,code:De.InternalCallDeclarationNotFoundInParentDatatypeEntity,severity:he.Error,message:`Entity of type "${a.type}" with id "${a.id}", belongs to a variable whose data type entity doesn't contain its declaration method (function-declaration) with id "${a.declaration}".${V}`}))}}(T.inputs.length||T.outputs.length||T.internalCalls.length)&&e.push(new _e({id:`${a.id}--${ue.InvalidInternalCallParentRelation}`,code:ue.InvalidInternalCallParentRelation,severity:he.Error,message:`Entity of type "${a.type}" with id "${a.id}", can only be added to a variable declaration or variable instance parent if the parent doesn't already have inputs, outputs or other internal calls.
130
130
  If you need a new variable-instance for this, consider using the 'implement_variable_instance' generation action to create one and give it a caller.
131
131
  The you can attach the new internal-call to it.`}))}const E=jr(a);return e.push(...f.errors,...E.errors),c.push(...E.explanations),{errors:e,explanations:c,modifiedData:a}}validateGeneratedUpdate(i){const r=[],a=[];return i.parent&&r.push(new _e({id:`${this.id}--${ue.InvalidParentUpdate}`,code:ue.InvalidParentUpdate,severity:he.Error,message:`Entity of type '${this.type}' with id '${this.id}' cannot have the 'parent' property updated, as it would mean moving the '${this.type}' entity to another parent entity.
132
- This is likely an incorrect strategy, either the '${this.type}' entity doesn't need to be updated or it should be deleted and a new one created in the desired parent.`})),{errors:r,explanations:a,modifiedData:i}}subscribeDependents(i){return i.forEach(r=>{this.detachedDependents[r.entity.id]||(this.detachedDependents[r.entity.id]=r)}),this}unsubscribeDependents(i){return i.forEach(r=>{this.detachedDependents[r.entity.id]&&delete this.detachedDependents[r.entity.id]}),this}syncDependents(i=this.project.addChangeSet(new q(this.project,N.sessionAuthor,B().toISOString(),this,!0,"sync-dependents"))){const r=[],a=[],c=[],e=[];return Object.values(this.detachedDependents).forEach(f=>{const h=f.entity.afterAllChildrenInitialized(i);r.push(...h.updated),a.push(...h.added),c.push(...h.removed),e.push(...h.affected)}),i==null||i.attemptAutoclose("sync-dependents",this.id),{updated:w(r),added:w(a),removed:w(c),affected:w(e),self:this}}onDetachedDependencyRemoved(i,r,a){const c=[],e=[],f=[],h=[];if(r==="declaration"){const{updated:T,added:E,removed:b}=this.remove({ignoreUpstream:!1},a);c.push(...T),e.push(...E),f.push(...b)}return{updated:w(c),added:w(e),removed:w(f),affected:w(h),self:this}}onDetachedDependencyRestored(i,r,a){const c=[],e=[],f=[],h=[];if(r==="declaration"){const{updated:T,added:E,removed:b}=this.restore({},a);c.push(...T),e.push(...E),f.push(...b)}return{updated:w(c),added:w(e),removed:w(f),affected:w(h),self:this}}unsubscribeFromDependencies(){return this.declaration.unsubscribeDependents([{entity:this,field:"declaration"}]),this}subscribeToDependencies(){return this.declaration.subscribeDependents([{entity:this,field:"declaration"}]),this}increaseVersion(i){if(i&&!B(i).isValid())throw new Error(`The shared timestamp '${i}' is not a valid ISO 8601 date string.`);return i&&B(i).isSame(B(this.createdAt))?this:(this.previousVersion=this.version,this.version=N.UUID.uuid(),this.createdAt=B(i).toISOString()||B().toISOString(),this)}captureVersion(){var r;const i=((r=this.knownVersions)==null?void 0:r.get(this.version))||new bi(this,this.project);return i.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,i):new Map([[this.version,i]]),i.inputs=[...this.inputs],i.outputs=[...this.outputs],i.error=this.error,i.successCalls=[...this.successCalls],i.errorCalls=[...this.errorCalls],i.calledBySuccess=[...this.calledBySuccess],i.calledByError=[...this.calledByError],i.calledByEntry=[...this.calledByEntry],i.declaration=this.declaration,i.parent=this.parent,this}recursiveCaptureUpstreamVersions(i){const r=[],a=[],c=[],e=[];if(this.parent){this.parent.increaseVersion(i);const f=this.parent.recursiveCaptureUpstreamVersions(i);r.push(this.parent,...f.updated),a.push(...f.added),c.push(...f.removed)}return{updated:w(r),added:w(a),removed:w(c),affected:w(e),self:this}}async restoreVersion(i){var h;const r=[],a=[],c=[],e=[];if(this.version===i)return{updated:w(r),added:w(a),removed:w(c),affected:w(e),self:this};if(!this.knownVersions){const T=new Map;for(const[E,b]of this.knownVersions||new Map){if(T.set(E,b),b.activeVersion=!1,b.knownVersions)for(const[I,P]of b.knownVersions)T.set(I,P);b.knownVersions=null}}let f=(h=this.knownVersions)==null?void 0:h.get(i);if(!f){const T=await this.APILoadVersion({},i);if(!T)throw new Error(`Version with id '${i}' for entity with id '${this.id}' not found.`);f=new bi(T,this.project)}return this.metaSync(f.toShallowJSON(),null),this.previousVersion=f.previousVersion,this.version=f.version,this.createdAt=f.createdAt,this.author=f.author,this.deleted=f.deleted,this.inputs=f.inputs,this.outputs=f.outputs,this.error=f.error,this.successCalls=f.successCalls,this.errorCalls=f.errorCalls,this.calledBySuccess=f.calledBySuccess,this.calledByError=f.calledByError,this.calledByEntry=f.calledByEntry,this.declaration=f.declaration,this.parent=f.parent,{updated:w(r),added:w(a),removed:w(c),affected:w(e),self:this}}updateWithShallowTransfer(i,r=this.project.addChangeSet(new q(this.project,N.sessionAuthor,B().toISOString(),this,!0,C.UpdateWithShallowTransfer))){if(!this.checkCanEdit(this,r))return z.Logger.warn(`[updateWithShallowTransfer] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),r==null||r.attemptAutoclose(C.UpdateWithShallowTransfer,this.id),this;if(this.metaSync(i,r),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 a=X(i.parent),c=this.project.get(a),e=this.parent;if(e&&e.id!==(c==null?void 0:c.id)&&this.removeFromParent(r),c)this.setParent(c,r),this.addSelfToProject(r);else throw r==null||r.attemptAutoclose(C.UpdateWithShallowTransfer,this.id),new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${a}' that isn't found in the project`)}else throw r==null||r.attemptAutoclose(C.UpdateWithShallowTransfer,this.id),new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(i.declaration){const a=X(i.declaration),c=this.project.get(a);c&&this.setDeclaration(c)}else throw r==null||r.attemptAutoclose(C.UpdateWithShallowTransfer,this.id),new Error(`${this.type} with id '${this.id}' must have a 'declaration'`);return i.calledByEntry.forEach(a=>{const c=X(a),e=this.project.get(c);e&&(this.addEntryCaller(e,r),e.addCall(this,r))}),[...this.calledByEntry].forEach(a=>{i.calledByEntry.find(e=>X(e)===a.id)||(this.removeCaller(a,r),a.removeCall(this,r))}),i.calledBySuccess.forEach(a=>{const c=X(a),e=this.project.get(c);e&&(this.addSuccessCaller(e,r),e.addSuccessCall(this,r))}),[...this.calledBySuccess].forEach(a=>{i.calledBySuccess.find(e=>X(e)===a.id)||(this.removeCaller(a,r),a.removeCall(this,r))}),i.calledByError.forEach(a=>{const c=X(a),e=this.project.get(c);e&&(this.addErrorCaller(e,r),e.addErrorCall(this,r))}),[...this.calledByError].forEach(a=>{i.calledByError.find(e=>X(e)===a.id)||(this.removeCaller(a,r),a.removeCall(this,r))}),i.outputs.forEach(a=>{const c=X(a),e=this.project.get(c);e&&(this.addOutput(e,r),e.setParent(this,r))}),[...this.outputs].forEach(a=>{i.outputs.find(e=>X(e)===a.id)||(this.removeOutput(a,r),a.removeFromParent(r))}),i.inputs.forEach(a=>{const c=X(a),e=this.project.get(c);e&&(this.addInput(e,r),e.setParent(this,r))}),[...this.inputs].forEach(a=>{i.inputs.find(e=>X(e)===a.id)||(this.removeInput(a,r),a.removeFromParent(r))}),i.writesValues.forEach(a=>{const c=X(a),e=this.project.get(c);e&&(this.addValueReader(e,r),e.setValueWriter(this,r))}),[...this.writesValues].forEach(a=>{i.writesValues.find(e=>X(e)===a.id)||(this.removeValueReader(a,r),a.setValueWriter(null,r))}),this.captureVersion(),this.subscribeToDependencies(),r==null||r.attemptAutoclose(C.UpdateWithShallowTransfer,this.id),this}updateWithGenerationTarget(i,r=this.project.addChangeSet(new q(this.project,N.sessionAuthor,B().toISOString(),this,!0,C.UpdateWithGenerationTarget))){var a,c,e;if(!this.checkCanEdit(this,r))return z.Logger.warn(`[updateWithGenerationTarget] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),r==null||r.attemptAutoclose(C.UpdateWithGenerationTarget,this.id),this;if(this.metaSync(i,r),i.parent){const f=X(i.parent),h=this.project.get(f),T=this.parent;if(T&&T.id!==(h==null?void 0:h.id)&&this.removeFromParent(r),h)this.setParent(h,r),this.addSelfToProject(r);else throw r==null||r.attemptAutoclose(C.UpdateWithGenerationTarget,this.id),new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${f}' that isn't found in the project`)}if(i.declaration){const f=X(i.declaration),h=this.project.get(f);h&&this.setDeclaration(h)}else throw r==null||r.attemptAutoclose(C.UpdateWithGenerationTarget,this.id),new Error(`${this.type} with id '${this.id}' must have a 'declaration'`);return(a=i.calledByEntry)==null||a.forEach(f=>{const h=X(f),T=this.project.get(h);if(T)this.addEntryCaller(T,r),T.addCall(this,r);else throw new Error(`${this.type} with id '${this.id}' has a 'calledByEntry' reference '${h}' that isn't found in the project`)}),i.calledByEntry&&[...this.calledByEntry].forEach(f=>{var T;((T=i.calledByEntry)==null?void 0:T.find(E=>X(E)===f.id))||(this.removeCaller(f,r),f.removeCall(this,r))}),(c=i.calledBySuccess)==null||c.forEach(f=>{const h=X(f),T=this.project.get(h);if(T)this.addSuccessCaller(T,r),T.addSuccessCall(this,r);else throw new Error(`${this.type} with id '${this.id}' has a 'calledBySuccess' reference '${h}' that isn't found in the project`)}),i.calledBySuccess&&[...this.calledBySuccess].forEach(f=>{var T;((T=i.calledBySuccess)==null?void 0:T.find(E=>X(E)===f.id))||(this.removeCaller(f,r),f.removeCall(this,r))}),(e=i.calledByError)==null||e.forEach(f=>{const h=X(f),T=this.project.get(h);if(T)this.addErrorCaller(T,r),T.addErrorCall(this,r);else throw new Error(`${this.type} with id '${this.id}' has a 'calledByError' reference '${h}' that isn't found in the project`)}),i.calledByError&&[...this.calledByError].forEach(f=>{var T;((T=i.calledByError)==null?void 0:T.find(E=>X(E)===f.id))||(this.removeCaller(f,r),f.removeCall(this,r))}),this.captureVersion(),this.subscribeToDependencies(),r==null||r.attemptAutoclose(C.UpdateWithGenerationTarget,this.id),this}hydrateAncestors(){const i=[],r=[],a=[],c=[];if(this.initialData.parent){const e=X(this.initialData.parent),f=this.project.get(e);if(f)this.setParent(f,null),i.push(f);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=X(this.initialData.declaration),f=this.project.get(e);if(f)this.setDeclaration(f),i.push(f);else throw new Error(`${this.type} with id '${this.id}' has a 'declaration' reference '${e}' that isn't found in the project`)}else throw new Error(`${this.type} with id '${this.id}' must have a 'declaration'`);return this.initialData.calledByEntry.forEach(e=>{const f=X(e),h=this.project.get(f);h&&this.addEntryCaller(h,null)}),this.initialData.calledBySuccess.forEach(e=>{const f=X(e),h=this.project.get(f);h&&this.addSuccessCaller(h,null)}),this.initialData.calledByError.forEach(e=>{const f=X(e),h=this.project.get(f);h&&this.addErrorCaller(h,null)}),{updated:w(i),added:w(r),removed:w(a),affected:w(c),self:this}}afterAllChildrenInitialized(i=this.project.addChangeSet(new q(this.project,N.sessionAuthor,B().toISOString(),this,!0,C.AfterAllChildrenInitialized))){if(!this.checkCanEdit(this,i))return z.Logger.warn(`[afterAllChildrenInitialized] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(C.AfterAllChildrenInitialized,this.id),{updated:[],added:[],removed:[],affected:[],self:this};const r=[],a=[],c=[],e=[];this.initialized=!0;let f=this.index||0;const h=this.parent.internalCalls.filter(U=>!U.deleted&&U.id!==this.id);h.length&&(f>h.length+1?f=h.length:f<0&&(f=0)),h.find(U=>(U.index||0)===f&&!U.deleted)&&h.filter(U=>(U.index||0)>=f&&!U.deleted).forEach(U=>{U.metaSync({index:(U.index||0)+1},i),i==null||i.add(U,W.Updated),r.push(U)}),this.metaSync({index:f},i);const{updated:E,added:b,removed:I}=this.syncInputs(i),{updated:P,added:V,removed:$}=this.syncOutputs(i);return r.push(...E,...P),a.push(...b,...V),c.push(...I,...$),this.inputs.sort((U,M)=>{var G,H;return(U.index??((G=U.declaration)==null?void 0:G.index))-(M.index??((H=M.declaration)==null?void 0:H.index))}),this.outputs.sort((U,M)=>{var G,H;return(U.index??((G=U.declaration)==null?void 0:G.index))-(M.index??((H=M.declaration)==null?void 0:H.index))}),this.captureVersion(),i==null||i.attemptAutoclose(C.AfterAllChildrenInitialized,this.id),{updated:w(r),added:w(a),removed:w(c),affected:w(e),self:this}}addSelfToProject(i=this.project.addChangeSet(new q(this.project,N.sessionAuthor,B().toISOString(),this,!0,"add-self-to-project"))){const r=[this],a=[],c=[],e=[];return this.parent.addInternalCall(this),e.push(this.parent),this.successCalls.forEach(f=>{f.addSuccessCaller(this,i),r.push(f)}),this.errorCalls.forEach(f=>{f.addErrorCaller(this,i),r.push(f)}),this.calledBySuccess.forEach(f=>{f.addSuccessCall(this,i),r.push(f)}),this.calledByError.forEach(f=>{f.addErrorCall(this,i),r.push(f)}),this.calledByEntry.forEach(f=>{f.addCall(this,i),r.push(f)}),this.subscribe(),this.subscribeToDependencies(),i==null||i.attemptAutoclose("add-self-to-project",this.id),{updated:w(r),added:w(a),removed:w(c),affected:w(e),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}removeInput(i,r=this.project.addChangeSet(new q(this.project,N.sessionAuthor,B().toISOString(),this,!0,C.RemoveInput))){if(!this.checkCanEdit(this,r))return z.Logger.warn(`[removeInput] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),r==null||r.attemptAutoclose(C.RemoveInput,this.id),this;const a=this.inputs.findIndex(c=>c.id===i.id);return a>-1&&(this.inputs.splice(a,1),r&&(r==null||r.add(this,W.Affected))),r==null||r.attemptAutoclose(C.RemoveInput,this.id),this}addInput(i,r=this.project.addChangeSet(new q(this.project,N.sessionAuthor,B().toISOString(),this,!0,C.AddInput))){return this.checkCanEdit(this,r)?this.inputs.includes(i)?(r==null||r.attemptAutoclose(C.AddInput,this.id),this):(this.inputs.push(i),r==null||r.add(this,W.Affected),r==null||r.attemptAutoclose(C.AddInput,this.id),this):(z.Logger.warn(`[addInput] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),r==null||r.attemptAutoclose(C.AddInput,this.id),this)}addOutput(i,r=this.project.addChangeSet(new q(this.project,N.sessionAuthor,B().toISOString(),this,!0,"add-output"))){return this.checkCanEdit(this,r)?this.outputs.includes(i)?(r==null||r.attemptAutoclose("add-output",this.id),this):(this.outputs.push(i),r==null||r.add(this,W.Affected),r==null||r.attemptAutoclose("add-output",this.id),this):(z.Logger.warn(`[addOutput] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),r==null||r.attemptAutoclose("add-output",this.id),this)}removeOutput(i,r=this.project.addChangeSet(new q(this.project,N.sessionAuthor,B().toISOString(),this,!0,"remove-output"))){if(!this.checkCanEdit(this,r))return z.Logger.warn(`[removeOutput] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),r==null||r.attemptAutoclose("remove-output",this.id),this;const a=this.outputs.findIndex(c=>c.id===i.id);return a>-1&&(this.outputs.splice(a,1),r&&(r==null||r.add(this,W.Affected))),r==null||r.attemptAutoclose("remove-output",this.id),this}addValueReader(i,r=this.project.addChangeSet(new q(this.project,N.sessionAuthor,B().toISOString(),this,!0,C.AddValueReader))){var e,f,h;if(!this.checkCanEditFromScopeOwnerWithSideEffects(this,C.AddValueReader,r))return this;const a=i.type===d.InputMap&&i.parent.type===d.VariableInstance&&((e=i.declaration)==null?void 0:e.type)===d.Property&&((f=i.declaration)==null?void 0:f.constant),c=i.type===d.VariableInstance&&((h=i.declaration)==null?void 0:h.constant);return(a||c)&&i?(r==null||r.event({id:`${C.SetValueWriter}-${this.id}--${this.id}`,action:C.SetValueWriter,owner:i,counterpart:this,errorReason:Di.ValueReadingOverridesConstantVariable,rootAction:!1}),r==null||r.attemptAutoclose(C.AddValueReader,this.id),this):this.writesValues.includes(i)?(r==null||r.attemptAutoclose(C.AddValueReader,this.id),this):(this.writesValues.push(i),r==null||r.add(this,W.Affected),this)}removeValueReader(i,r=this.project.addChangeSet(new q(this.project,N.sessionAuthor,B().toISOString(),this,!0,C.RemoveValueReader))){return this.checkCanEditFromScopeOwnerWithSideEffects(this,C.RemoveValueReader,r)?this.writesValues.includes(i)?(this.writesValues=this.writesValues.filter(a=>a.id!==i.id),r==null||r.add(this,W.Affected),this):(r==null||r.attemptAutoclose(C.RemoveValueReader,this.id),this):this}addSuccessCaller(i,r=this.project.addChangeSet(new q(this.project,N.sessionAuthor,B().toISOString(),this,!0,C.AddSuccessCaller)),a=!1){return this.checkCanEditWithCounterpartAndSideEffects(this,i,C.AddSuccessCaller,r)?(this.calledBySuccess.find(c=>c.id===i.id)||(this.calledBySuccess.push(i),r==null||r.add(this,W.Updated),a&&mt(this,r)),r==null||r.attemptAutoclose(C.AddSuccessCaller,this.id),this):this}addErrorCaller(i,r=this.project.addChangeSet(new q(this.project,N.sessionAuthor,B().toISOString(),this,!0,C.AddErrorCaller)),a=!1){return this.checkCanEditWithCounterpartAndSideEffects(this,i,C.AddErrorCaller,r)?(this.calledByError.find(c=>c.id===i.id)||(this.calledByError.push(i),r==null||r.add(this,W.Updated),a&&mt(this,r)),r==null||r.attemptAutoclose(C.AddErrorCaller,this.id),this):this}addEntryCaller(i,r=this.project.addChangeSet(new q(this.project,N.sessionAuthor,B().toISOString(),this,!0,C.AddEntryCaller)),a=!1){return this.checkCanEditWithCounterpartAndSideEffects(this,i,C.AddEntryCaller,r)?(this.calledByEntry.find(c=>c.id===i.id)||(this.calledByEntry.push(i),r==null||r.add(this,W.Updated),a&&mt(this,r)),r==null||r.attemptAutoclose(C.AddEntryCaller,this.id),this):this}addErrorCall(i,r=this.project.addChangeSet(new q(this.project,N.sessionAuthor,B().toISOString(),this,!0,C.AddErrorCall)),a=!1){return this.checkCanEditWithCounterpartAndSideEffects(this,i,C.AddErrorCall,r)?(this.errorCalls.find(c=>c.id===i.id)||(this.errorCalls.push(i),a&&mt(this,r),r==null||r.add(this,W.Affected)),r==null||r.attemptAutoclose(C.AddErrorCall,this.id),this):this}addSuccessCall(i,r=this.project.addChangeSet(new q(this.project,N.sessionAuthor,B().toISOString(),this,!0,C.AddSuccessCall)),a=!1){return this.checkCanEditWithCounterpartAndSideEffects(this,i,C.AddSuccessCall,r)?(this.successCalls.find(c=>c.id===i.id)||(this.successCalls.push(i),a&&mt(this,r),r==null||r.add(this,W.Affected)),r==null||r.attemptAutoclose(C.AddSuccessCall,this.id),this):this}removeCall(i,r=this.project.addChangeSet(new q(this.project,N.sessionAuthor,B().toISOString(),this,!0,C.RemoveCall)),a=!1){if(!this.checkCanEditWithCounterpartAndSideEffects(this,i,C.RemoveCall,r))return this;const c=this.successCalls.findIndex(f=>f.id===i.id);c>-1&&(this.successCalls.splice(c,1),r==null||r.add(this,W.Affected));const e=this.errorCalls.findIndex(f=>f.id===i.id);return e>-1&&(this.errorCalls.splice(e,1),r==null||r.add(this,W.Affected)),a&&mt(this,r),r==null||r.attemptAutoclose(C.RemoveCall,this.id),this}removeCaller(i,r=this.project.addChangeSet(new q(this.project,N.sessionAuthor,B().toISOString(),this,!0,"remove-caller")),a=!1){return this.checkCanEditWithCounterpartAndSideEffects(this,i,C.RemoveCaller,r)?(this.calledBySuccess=this.calledBySuccess.filter(c=>c.id!==i.id?!0:(r==null||r.add(this,W.Updated),r==null||r.add(c,W.Affected),!1)),this.calledByError=this.calledByError.filter(c=>c.id!==i.id?!0:(r==null||r.add(this,W.Updated),r==null||r.add(c,W.Affected),!1)),this.calledByEntry=this.calledByEntry.filter(c=>c.id!==i.id?!0:(r==null||r.add(this,W.Updated),r==null||r.add(c,W.Affected),!1)),a&&mt(this,r),r==null||r.attemptAutoclose(C.RemoveCaller,this.id),this):this}setError(i,r=this.project.addChangeSet(new q(this.project,N.sessionAuthor,B().toISOString(),this,!0,C.SetErrorEntity))){if(!this.checkCanEdit(this,r))return z.Logger.warn(`[setError] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),r==null||r.attemptAutoclose(C.SetErrorEntity,this.id),this;const a=this.error;return(a==null?void 0:a.id)!==(i==null?void 0:i.id)&&(a==null||a.remove({ignoreUpstream:!0},r),this.error=i,this.subscribeToDependencies(),r==null||r.add(this,W.Affected)),r==null||r.attemptAutoclose(C.SetErrorEntity,this.id),this}setParent(i,r=this.project.addChangeSet(new q(this.project,N.sessionAuthor,B().toISOString(),this,!0,C.SetParent))){var a;return this.checkCanEditWithCounterpartAndSideEffects(this,i,C.SetParent,r)?(((a=this.parent)==null?void 0:a.id)!==(i==null?void 0:i.id)&&(this.parent=i,r&&(r==null||r.add(this,W.Updated))),r==null||r.attemptAutoclose(C.SetParent,this.id),this):this}setDeclaration(i){return this.declaration=i,this}initChildren(i=this.project.addChangeSet(new q(this.project,N.sessionAuthor,B().toISOString(),this,!0,"init-children"))){if(this.initialized||this.startedInitialization)return this;if(this.startedInitialization=!0,this.initialData.parent.type!==d.GenericReference){const r=Ee(this.initialData.parent,this.project);this.setParent(r,null),this.parent.initChildren(i),this.parent.addInternalCall(this);const a=this.calledBy.find(c=>!!c.parent&&pr.includes(c.parent.type));if(a){const c=Ee(a.parent,this.project);this.parent.setParent(c,null)}else if(!a&&!this.parent.calledBy.length)throw new Error("Parent of internal call parent could not be resolved")}return this.declaration=Ee(this.initialData.declaration,this.project),this.successCalls=this.initialData.successCalls.map(r=>{const a=Ee(r,this.project);if(a.addSuccessCaller(this,null),[d.BreakStatement,d.ContinueStatement].includes(a.type))a.setParent(this.parent.parent,null),a.initChildren(i);else if(a.type===d.ReturnStatement){const c=on(this.parent,this.project);a.setParent(c,null),a.initChildren(i)}else a.type!==d.InternalCall&&(a.setParent(this.parent.parent,null),a.initChildren(i));return a}),this.errorCalls=this.initialData.errorCalls.map(r=>{const a=Ee(r,this.project);if(a.addErrorCaller(this,null),[d.BreakStatement,d.ContinueStatement].includes(a.type))a.setParent(this.parent.parent.parent,null),a.initChildren(i);else if(a.type===d.ReturnStatement){const c=on(this.parent,this.project);a.setParent(c,null),a.initChildren(i)}else a.type!==d.InternalCall&&(a.setParent(this.parent.parent,null),a.initChildren(i));return a}),this.inputs=this.initialData.inputs.map(r=>{const a=Ee(r,this.project);return a.setParent(this,null),a.initChildren(i),a}),this.outputs=this.initialData.outputs.map(r=>{let a;return r.type===d.GenericReference?a=this.project.get(r.entityId):a=Ee(r,this.project),a.setParent(this,null),a.initChildren(i),a}),this.initialData.error&&(this.error=Ee(this.initialData.error,this.project),this.error.setParent(this,null),this.error.initChildren(i)),this.subscribeToDependencies(),this.afterAllChildrenInitialized(i),i==null||i.attemptAutoclose("init-children",this.id),this}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(i,r=this.project.addChangeSet(new q(this.project,N.sessionAuthor,B().toISOString(),this,!0,"meta-sync"))){const a=kr(this,i,r),c=Ur(this,a),e=this.toMeta();return this.index=a.index||(a.index!==0?e.index:0),this.catchesError=a.catchesError!==void 0?a.catchesError:this.catchesError,super.baseMetaSync(a,this,r),a.deleted===!0&&!e.deleted?r==null||r.add(this,W.Removed):a.deleted===!1&&e.deleted?r==null||r.add(this,W.Added):c&&(r==null||r.add(this,W.Updated)),r==null||r.attemptAutoclose("meta-sync",this.id),this}async APILoad(i=je,...r){return await bi.repository.APILoad(this.id,...r),this}async APICreate(i=je,...r){return await bi.repository.APICreate(this.toShallowJSON(),...r),this}async APIUpdate(i=je,...r){return await bi.repository.APIUpdate(this.toShallowJSON(),...r),this}async APIDelete(i=je,...r){return await bi.repository.APIDelete(this.toShallowJSON(),...r),this}async APIClone(i=je,...r){return await bi.repository.APIClone(this.id,...r),this}async APILoadVersion(i=je,r,...a){return await bi.repository.APILoadVersion(this.id,r,...a)}removeFromParent(i=this.project.addChangeSet(new q(this.project,N.sessionAuthor,B().toISOString(),this,!0,C.RemoveFromParent))){if(!this.checkCanEdit(this,i))return z.Logger.warn(`[removeFromParent] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(C.RemoveFromParent,this.id),{added:[],updated:[],removed:[],affected:[],self:this};const r=[],a=[],c=[],e=[];return this.parent&&(this.parent.removeInternalCall(this,i),e.push(this.parent)),i==null||i.attemptAutoclose(C.RemoveFromParent,this.id),{added:w(c),updated:w(r),removed:w(a),affected:w(e),self:this}}remove({ignoreUpstream:i}={ignoreUpstream:!1},r=this.project.addChangeSet(new q(this.project,N.sessionAuthor,B().toISOString(),this,!0,C.RemoveEntity))){var h;if(!this.checkCanDelete(this,r))return z.Logger.warn(`[remove] User is not allowed to delete or edit this ${this.type} entity with id: ${this.id}`),r==null||r.event({id:`${C.RemoveEntity}-${this.id}`,action:C.RemoveEntity,owner:this,errorReason:Di.ActionOwnerEntityNonDeletable,rootAction:((h=r==null?void 0:r.self)==null?void 0:h.id)===this.id&&(r==null?void 0:r.autoCloseActionName)===C.RemoveEntity}),r==null||r.attemptAutoclose(C.RemoveEntity,this.id),{added:[],updated:[],removed:[],affected:[],self:this};const a=[],c=[],e=[],f=[];if(r!=null&&r.hasRemoved(this.id))return r==null||r.attemptAutoclose(C.RemoveEntity,this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(c.push(this),this.unsubscribe(),this.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},r),Object.values(this.detachedDependents).forEach(T=>{const{updated:E,removed:b,added:I}=T.entity.onDetachedDependencyRemoved(this,T.field,r);a.push(...E),c.push(...b),e.push(...I)}),this.inputs.forEach(T=>{const{updated:E,removed:b}=T.remove({ignoreUpstream:!0},r);a.push(...E),c.push(...b)}),this.outputs.forEach(T=>{const{updated:E,removed:b}=T.remove({ignoreUpstream:!0},r);a.push(...E),c.push(...b)}),this.error){const{updated:T,removed:E}=this.error.remove({ignoreUpstream:!0},r);a.push(...T),c.push(...E)}if(this.successCalls.forEach(T=>{a.push(T),T.removeCaller(this,r)}),this.errorCalls.forEach(T=>{a.push(T),T.removeCaller(this,r)}),!i){const T=this.removeFromParent(r);e.push(...T.added),a.push(...T.updated),c.push(...T.removed),f.push(...T.affected),this.calledBy.forEach(E=>{a.push(E),E.removeCall(this,r)})}return r==null||r.attemptAutoclose(C.RemoveEntity,this.id),{added:w(e),updated:w(a),removed:w(c),affected:w(f),self:this}}restore({}={},i=this.project.addChangeSet(new q(this.project,N.sessionAuthor,B().toISOString(),this,!0,C.RestoreEntity))){if(!this.checkCanEdit(this,i))return z.Logger.warn(`[restore] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(C.RestoreEntity,this.id),{added:[],updated:[],removed:[],affected:[],self:this};const r=[],a=[],c=[],e=[];return i!=null&&i.hasAdded(this.id)?(i==null||i.attemptAutoclose(C.RestoreEntity,this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},i),Object.values(this.detachedDependents).forEach(f=>{const{updated:h,removed:T,added:E}=f.entity.onDetachedDependencyRestored(this,f.field,i);a.push(...h),c.push(...T),r.push(...E)}),this.inputs.forEach(f=>{const{updated:h}=f.restore({},i);a.push(...h)}),this.outputs.forEach(f=>{const{updated:h}=f.restore({},i);a.push(...h)}),this.successCalls.forEach(f=>{a.push(f),f.addSuccessCaller(this,i)}),this.errorCalls.forEach(f=>{a.push(f),f.addErrorCaller(this,i)}),this.calledBySuccess.forEach(f=>{a.push(f),f.addSuccessCall(this,i)}),this.calledByError.forEach(f=>{a.push(f),f.addErrorCall(this,i)}),this.calledByEntry.forEach(f=>{a.push(f),f.addCall(this,i)}),i==null||i.attemptAutoclose(C.RestoreEntity,this.id),{added:w(r),updated:w(a),removed:w(c),affected:w(e),self:this})}toFlat(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this,...this.successCalls.flatMap(a=>a.toFlat(i)),...this.errorCalls.flatMap(a=>a.toFlat(i)),...this.inputs.flatMap(a=>a.toFlat(i)),...this.outputs.flatMap(a=>a.toFlat(i)),...this.calledBy.flatMap(a=>a.toFlat(i)),...this.error?this.error.toFlat(i):[],...this.parent.toFlat(i)])}toFlatIds(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.id,...this.successCalls.flatMap(a=>a.toFlatIds(i)),...this.errorCalls.flatMap(a=>a.toFlatIds(i)),...this.inputs.flatMap(a=>a.toFlatIds(i)),...this.outputs.flatMap(a=>a.toFlatIds(i)),...this.calledBy.flatMap(a=>a.toFlatIds(i)),...this.error?this.error.toFlatIds(i):[],...this.parent.toFlatIds(i)])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,catchesError:this.catchesError,author:this.author,deleted:this.deleted,index:this.index,type:this.type,editable:this.editable,deletable:this.deletable}}toJSON(i=new Set){var r;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,catchesError:this.catchesError,type:this.type,editable:this.editable,deletable:this.deletable,index:this.index,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()),writesValues:this.writesValues.map(a=>a.toJSON(i)),declaration:(()=>{var a;return this.declaration&&this.project.getBuiltIn(this.declaration.id)?this.declaration.toJSON():(a=this.declaration)==null?void 0:a.toJSON(i)})(),inputs:this.inputs.map(a=>a.toJSON(i)),outputs:this.outputs.map(a=>a.toJSON(i)),parent:this.parent.toReference(),error:(r=this.error)==null?void 0:r.toJSON(i)})}toJSONClone(i=tt){var a,c,e,f,h,T;let r;return(a=i.seenEntityMaps)!=null&&a.has(this.id)?r=i.seenEntityMaps.get(this.id):(r=i.newId||Wr(this,this.project,i.uuidStrategy),i.seenEntityMaps&&i.seenEntityMaps.set(this.id,r)),(c=i.seenEntities)!=null&&c.has(r)||(e=i.seenEntities)!=null&&e.has(this.id)?this.toReference({seenEntityMaps:i.seenEntityMaps}):((f=i.seenEntities)==null||f.add(r),(h=i.seenEntities)==null||h.add(this.id),{id:r,version:N.UUID.uuid(),createdAt:i.timestamp||B().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,catchesError:this.catchesError,type:this.type,editable:this.editable,deletable:this.deletable,index:this.index,writesValues:this.writesValues.map(E=>E.toJSONClone({...i,newId:null})),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})),declaration:(()=>{var E;return this.declaration&&this.project.getBuiltIn(this.declaration.id)?this.declaration.toJSON():(E=this.declaration)==null?void 0:E.toJSONClone({...i,newId:null})})(),inputs:this.inputs.map(E=>E.toJSONClone({...i,newId:null})),outputs:this.outputs.map(E=>E.toJSONClone({...i,newId:null})),error:(T=this.error)==null?void 0:T.toJSONClone({...i,newId:null}),parent:this.parent.calledBy.length||this.parent.readsValue?this.parent.toReference({seenEntityMaps:i.seenEntityMaps}):this.parent.toJSONClone({...i,newId:null})})}toReference(i=tt){var a;let r=this.id;return(a=i.seenEntityMaps)!=null&&a.has(this.id)&&(r=i.seenEntityMaps.get(this.id)),{id:r+"--"+N.UUID.uuid()+"--ref",type:d.GenericReference,entityId:r,version:this.version,entityType:this.type}}toShallowJSON(i=tt){var a;let r=this.id;return(a=i.seenEntityMaps)!=null&&a.has(this.id)&&(r=i.seenEntityMaps.get(this.id)),{id:r,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,catchesError:this.catchesError,type:this.type,editable:this.editable,deletable:this.deletable,index:this.index,writesValues:this.writesValues.map(c=>c.toReference(i)),inputs:this.inputs.map(c=>c.toReference(i)),outputs:this.outputs.map(c=>c.toReference(i)),declaration:this.declaration.toReference(i),successCalls:this.successCalls.map(c=>c.toReference(i)),errorCalls:this.errorCalls.map(c=>c.toReference(i)),calledBySuccess:this.calledBySuccess.map(c=>c.toReference(i)),calledByError:this.calledByError.map(c=>c.toReference(i)),calledByEntry:this.calledByEntry.map(c=>c.toReference(i)),error:this.error?this.error.toReference(i):null,parent:this.parent.toReference(i)}}toFlatJSON(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.toShallowJSON(),...this.successCalls.flatMap(a=>a.toFlatJSON(i)),...this.errorCalls.flatMap(a=>a.toFlatJSON(i)),...this.inputs.flatMap(a=>a.toFlatJSON(i)),...this.outputs.flatMap(a=>a.toFlatJSON(i)),...this.calledBy.flatMap(a=>a.toFlatJSON(i)),...this.error?this.error.toFlatJSON(i):[],...this.parent.toFlatJSON(i)])}toGenerationTarget(i=tt){var a;let r=this.id;return(a=i.seenEntityMaps)!=null&&a.has(this.id)&&(r=i.seenEntityMaps.get(this.id)),{id:r,type:this.type,calledByEntry:this.calledByEntry.map(c=>c.id),calledBySuccess:this.calledBySuccess.map(c=>c.id),calledByError:this.calledByError.map(c=>c.id),declaration:this.declaration.id,parent:this.parent.id}}toFlatGenerationTarget(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.toGenerationTarget(),...this.successCalls.flatMap(a=>a.toFlatGenerationTarget(i)),...this.errorCalls.flatMap(a=>a.toFlatGenerationTarget(i)),...this.inputs.flatMap(a=>a.toFlatGenerationTarget(i)),...this.outputs.flatMap(a=>a.toFlatGenerationTarget(i)),...this.error?this.error.toFlatGenerationTarget(i):[],...this.parent.toFlatGenerationTarget(i)])}clearErrors(){var i;return this.errors=[],this.inputs.forEach(r=>r.clearErrors()),this.outputs.forEach(r=>r.clearErrors()),this.successCalls.forEach(r=>r.clearErrors()),this.errorCalls.forEach(r=>r.clearErrors()),(i=this.error)==null||i.clearErrors(),this}validate(){return this.errors=aGe(this),{success:!0}}async validateAsync(i={}){const r=z.YieldTracker.from(i);return this.errors=await nGe(this,{tracker:r}),{success:!0}}getErrors(){return[...this.errors,...this.inputs.flatMap(r=>r.getErrors()),...this.outputs.flatMap(r=>r.getErrors()),...this.error?this.error.getErrors():[]]}async getErrorsAsync(i={}){const r=z.YieldTracker.from(i),a=[...this.errors];await r.tick();for(const c of this.inputs)a.push(...await c.getErrorsAsync({tracker:r}));for(const c of this.outputs)a.push(...await c.getErrorsAsync({tracker:r}));return this.error&&a.push(...await this.error.getErrorsAsync({tracker:r})),a}getShallowErrors(){return this.errors}clone(i=this.project.addChangeSet(new q(this.project,N.sessionAuthor,B().toISOString(),this,!0,C.CloneEntity)),r=null,a=null,c=!0){var V,$;const e=_r(r,this),f=this.toJSON(),h=a||N.UUID.uuid();f.inputs=[];const T=h.split("-id"),E=T[T.length-1||0]||h;f.id=h,f.createdAt=(i==null?void 0:i.timestamp)||B().toISOString(),f.author=(i==null?void 0:i.author)||"1",f.previousVersion=null,f.version=N.UUID.uuid(),f.deletable=!0,f.editable=!0;const b=Hi(f,e);r?b.setParent(r,i):b.setParent(this.parent,null),c&&b.subscribe(),b.initChildren(i),i==null||i.add(b,W.Added);const I=(V=this.inputs)==null?void 0:V.map((U,M)=>U.clone(i,b,E+"-input-map-"+M+"-id",c));b.inputs=I;const P=($=this.outputs)==null?void 0:$.map((U,M)=>U.clone(i,b,E+"-output-map-"+M+"-id",c));return b.outputs=P,this.error&&(b.error=this.error.clone(i,b,E+"-error-map-id",c)),i==null||i.attemptAutoclose(C.CloneEntity,this.id),b}removeUnrecognizedInputs(i=this.project.addChangeSet(new q(this.project,N.sessionAuthor,B().toISOString(),this,!0,C.RemoveUnrecognizedInputs))){if(!this.checkCanEdit(this,i))return z.Logger.warn(`[removeUnrecognizedInputs] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(C.RemoveUnrecognizedInputs,this.id),{updated:[],added:[],removed:[],affected:[],self:this};const r=[],a=[],c=[],e=[];return this.inputs.forEach(h=>{if(!this.declaration.inputs.find(E=>{var b;return E.id===((b=h.declaration)==null?void 0:b.id)})){const E=h.remove({ignoreUpstream:!1},i);c.push(...E.removed),r.push(...E.updated)}}),this.inputs.filter((h,T)=>{const E=this.inputs.findIndex(I=>I.declaration===h.declaration&&I!==h);if(E===-1)return!1;const b=this.inputs[E];return B(b==null?void 0:b.createdAt).isSame(B(h.createdAt))?T>E:!!B(b==null?void 0:b.createdAt).isAfter(h.createdAt)}).forEach(h=>{const T=h.remove({ignoreUpstream:!1},i);c.push(...T.removed),r.push(...T.updated)}),i==null||i.attemptAutoclose(C.RemoveUnrecognizedInputs,this.id),{updated:w(r),added:w(a),removed:w(c),affected:w(e),self:this}}removeUnrecognizedOutputs(i=this.project.addChangeSet(new q(this.project,N.sessionAuthor,B().toISOString(),this,!0,C.RemoveUnrecognizedOutputs))){if(!this.checkCanEdit(this,i))return z.Logger.warn(`[removeUnrecognizedOutputs] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(C.RemoveUnrecognizedOutputs,this.id),{updated:[],added:[],removed:[],affected:[],self:this};const r=[],a=[],c=[],e=[];return this.outputs.forEach(h=>{if(!this.declaration.getUniqueOutputProperties().find(E=>{var b;return E.id===((b=h.declaration)==null?void 0:b.id)})){const E=h.remove({ignoreUpstream:!1},i);c.push(...E.removed),r.push(...E.updated)}}),this.outputs.filter((h,T)=>{const E=this.outputs.findIndex(I=>I.declaration===h.declaration&&I!==h);if(E===-1)return!1;const b=this.outputs[E];return B(b==null?void 0:b.createdAt).isSame(B(h.createdAt))?T>E:!!B(b==null?void 0:b.createdAt).isAfter(h.createdAt)}).forEach(h=>{const T=h.remove({ignoreUpstream:!1},i);c.push(...T.removed),r.push(...T.updated)}),i==null||i.attemptAutoclose(C.RemoveUnrecognizedOutputs,this.id),{updated:w(r),added:w(a),removed:w(c),affected:w(e),self:this}}syncInputs(i=this.project.addChangeSet(new q(this.project,N.sessionAuthor,B().toISOString(),this,!0,C.SyncInputs))){if(!this.checkCanEdit(this,i))return z.Logger.warn(`[syncInputs] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(C.SyncInputs,this.id),{updated:[],added:[],removed:[],affected:[],self:this};const r=[],a=[],c=[],e=[],f=this.declaration.inputs.filter(b=>!this.inputs.find(I=>{var P;return((P=I.declaration)==null?void 0:P.id)===b.id}));this.inputs.sort((b,I)=>b.index-I.index),f.forEach(b=>{this.inputs.forEach(V=>{V.index>=b.index&&V.metaSync({index:V.index+1},i)});const I={id:N.UUID.uuid(),version:N.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||B().toISOString(),author:N.sessionAuthor,previousVersion:null,deleted:!1,deletable:!0,editable:!0,type:d.InputMap,dataType:null,parentRelationType:null,declaration:b.toJSON(),readsValue:null,defaultValue:null,index:b.index,name:null,codeName:null,description:null,parent:this.toReference()},P=Ee(I,this.project);P.setParent(this,i),P.initChildren(i),i==null||i.add(P,W.Added),P.addSelfToProject(i),a.push(P)}),this.inputs.sort((b,I)=>b.index-I.index);const{updated:h,added:T,removed:E}=this.removeUnrecognizedInputs(i);return r.push(...h),a.push(...T),c.push(...E),i==null||i.attemptAutoclose(C.SyncInputs,this.id),{updated:w(r),added:w(a),removed:w(c),affected:w(e),self:this}}syncOutputs(i=this.project.addChangeSet(new q(this.project,N.sessionAuthor,B().toISOString(),this,!0,C.SyncOutputs))){if(!this.checkCanEdit(this,i))return z.Logger.warn(`[syncOutputs] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(C.SyncOutputs,this.id),{updated:[],added:[],removed:[],affected:[],self:this};const r=[],a=[],c=[],e=[],f=this.getDataType(i);if(f)if(f.entity){if(f.isObject()){const b=[...f.entity.properties];b.filter(V=>zy(V)?!this.outputs.find($=>{var U;return((U=$.declaration)==null?void 0:U.id)===(V==null?void 0:V.id)}):!1).map(V=>{const $={dataType:null,id:N.UUID.uuid(),version:N.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||B().toISOString(),author:N.sessionAuthor,previousVersion:null,deleted:!1,deletable:!0,editable:!0,type:d.OutputMap,parent:this.toReference(),declaration:V==null?void 0:V.toJSON(),index:V.index,writesValues:[]},U=Ee($,this.project);return U.hydrateAncestors(),i==null||i.add(U,W.Added),U.setParent(this,i),U.initChildren(i),this.addOutput(U,i),U}),this.outputs.filter(V=>!V.declaration).forEach(V=>{const $=b.find(U=>se(U,this.project)===se(V,this.project));$&&V.setDeclaration($,i)})}}else return i==null||i.attemptAutoclose(C.SyncOutputs,this.id),{added:[],updated:[],removed:[],affected:[],self:this};else return i==null||i.attemptAutoclose(C.SyncOutputs,this.id),{added:[],updated:[],removed:[],affected:[],self:this};const{updated:h,added:T,removed:E}=this.removeUnrecognizedOutputs(i);return r.push(...h),a.push(...T),c.push(...E),this.outputs.sort((b,I)=>b.index-I.index),i==null||i.attemptAutoclose(C.SyncOutputs,this.id),{updated:w(r),added:w(a),removed:w(c),affected:w(e),self:this}}getUnusedInputs(){return this.inputs.filter(i=>i.suggestion||!i.readsValue&&!i.defaultValue)}getUnusedOutputs(){return this.outputs.filter(i=>i.suggestion||!i.writesValues.length)}getUsedInputs(){return this.inputs.filter(i=>!i.suggestion&&(i.readsValue||i.defaultValue))}getUsedOutputs(){return this.outputs.filter(i=>!i.suggestion&&i.writesValues.length)}getDataType(i=this.project.addChangeSet(new q(this.project,N.sessionAuthor,B().toISOString(),this,!0,"get-data-type"))){var r;if(this.declaration.type===d.ActionDescriptor){const a=((r=this.declaration)==null?void 0:r.getDataType(i))||null;return i==null||i.attemptAutoclose("get-data-type",this.id),a}return i==null||i.attemptAutoclose("get-data-type",this.id),null}};R(bi,"repository",{APICreate:async(i,...r)=>i,APIUpdate:async(i,...r)=>i,APIDelete:async(i,...r)=>i,APIClone:async(i,...r)=>{},APILoad:async(i,...r)=>null,APILoadVersion:async(i,r,...a)=>null}),R(bi,"type",d.InternalCall),R(bi,"USER_MANAGED_PARENT_TYPES",[...Ot]),R(bi,"PARENT_TYPES",[...bi.USER_MANAGED_PARENT_TYPES]),R(bi,"MUTABLE_BASE_PROPERTIES",["catchesError"]),R(bi,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),R(bi,"BASE_PROPERTIES",[...bi.MUTABLE_BASE_PROPERTIES,...bi.INMUTABLE_BASE_PROPERTIES]),R(bi,"MUTABLE_META_PROPERTIES",[...bi.MUTABLE_BASE_PROPERTIES,"index"]),R(bi,"INMUTABLE_META_PROPERTIES",[...bi.INMUTABLE_BASE_PROPERTIES]),R(bi,"META_PROPERTIES",[...bi.MUTABLE_META_PROPERTIES,...bi.INMUTABLE_META_PROPERTIES]),R(bi,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry"]),R(bi,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","declaration"]),R(bi,"UPSTREAM_PROPERTIES",[...bi.MUTABLE_UPSTREAM_PROPERTIES,...bi.INMUTABLE_UPSTREAM_PROPERTIES]),R(bi,"MUTABLE_DOWNSTREAM_PROPERTIES",["inputs","outputs","writesValues","successCalls","errorCalls","error"]),R(bi,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),R(bi,"DOWNSTREAM_PROPERTIES",[...bi.MUTABLE_DOWNSTREAM_PROPERTIES,...bi.INMUTABLE_DOWNSTREAM_PROPERTIES]),R(bi,"PROPERTIES",[...bi.META_PROPERTIES,...bi.UPSTREAM_PROPERTIES,...bi.DOWNSTREAM_PROPERTIES]);let op=bi;async function lGe(o,p={}){const i=z.YieldTracker.from(p),r=[...Bs(o),...dGe(o)],a=Mt(o.errors,r);return await i.tick(),a}function oGe(o){const p=[...Bs(o)];return Mt(o.errors,p)}function dGe(o){var r,a;const p=[],i=o.parent.type===d.VariableInstance&&((r=o.declaration)==null?void 0:r.type)===d.Property&&((a=o.declaration)==null?void 0:a.constant);if(i&&o.readsValue){const c=_t({id:`${o.id}--${ve.ValueReadingOverridesConstantProperty}`,message:`The '${o.type}' entity "${se(o,o.project)}" with id "${o.id}" represents a constant property whose value cannot be overriden, but reads a value.`,severity:he.Error,code:ve.ValueReadingOverridesConstantProperty,entity:o});p.push(c.error)}if(i&&o.defaultValue){const c=_t({id:`${o.id}--${ve.DefaultValueOverridesConstantProperty}`,message:`The '${o.type}' entity "${se(o,o.project)}" with id "${o.id}" represents a constant property whose value cannot be overridden, but has a 'defaultValue'.`,severity:he.Error,code:ve.DefaultValueOverridesConstantProperty,entity:o});p.push(c.error)}return p}const iDi=Object.freeze(Object.defineProperty({__proto__:null,validate:oGe,validateAsync:lGe,validateConstantValueOverride:dGe},Symbol.toStringTag,{value:"Module"}));function rDi(o,p){var i;if(o.type===d.LiteralValue){let r=(i=o.value)==null?void 0:i.toString();try{r=JSON.stringify(o.value,null,2)}catch{}return`${o.type}: ${o.id} (${se(o,p)}) = ${r}`}return`${o.type}: ${o.id} (${se(o,p)})`}function og(o,p={nested:!1,omitTopLevelType:!1,firstLabel:"name",omitIdsFor:[],omitTypesFor:[],metadataIndent:1,ownMetadataIndent:1,omitFields:[],onlyFields:[]}){var E,b,I,P,V,$,U;const i={nested:p.nested??!1,omitTopLevelType:p.omitTopLevelType??!1,firstLabel:p.firstLabel??"name",omitIdsFor:p.omitIdsFor??[],omitTypesFor:p.omitTypesFor??[],metadataIndent:p.metadataIndent??1,omitFields:p.omitFields??[],onlyFields:p.onlyFields??[]};if(!o)return{lines:[{text:"Any (unspecified data type)",indentLevel:0}]};const r=p.onPrefix?p.onPrefix(o):"";function a(M){return i.onlyFields.length>0?i.onlyFields.includes(M):i.omitFields.length>0?!i.omitFields.includes(M):!0}const c=a("id")&&!i.omitIdsFor.includes(d.DataType)?o.id:"",e=a("type")&&!i.omitTypesFor.includes(d.DataType)?o.type:"",f=c;let h=`${r}${i.omitTopLevelType?"":e?`${e}: `:""}${f}`;h=h?h+" | ":"";let T="";if(o.interactiveEntities===!1?T+=` but only definition nodes ${o.asType?"as template ":""}that don't include non-interactive built-in functionality`:o.interactiveEntities===!0&&(T+=` but only definition nodes ${o.asType?"as template ":""}that extend or implement interactive built-in functionality`),o.staticEntities===!1?T?T+=" and that aren't a single global copy instance":T+=` but only definition nodes ${o.asType?"as template ":""}that aren't a single global copy instance`:o.staticEntities===!0&&(T?T+=" and that are a single global copy instance":T+=` but only definition nodes ${o.asType?"as template ":""}that are a single global copy instance`),o.actionEntities===!1?T?T+=" excluding executable/action nodes":T+=` excluding executable/action nodes ${o.asType?"templates ":""}`:o.actionEntities===!0&&(T?T+=" and not executable/action nodes":T+=" but not executable/action nodes"),o.entity&&(T=""),o.asType&&!T&&!((E=o.andChildrenGroup)!=null&&E.length)&&!((b=o.orChildrenGroup)!=null&&b.length)&&(T=" as template"),o.foreignKeyRef){const M=o.isList,G=se(o.foreignKeyRef,o.project),H=se(o.foreignKeyRef.parent,o.project);return{lines:[{text:M?`${h}List references to "${G}" from "${H}"${T}`:`${h}Reference to "${G}" from "${H}"${T}`,indentLevel:0}]}}else{if(o.foreignKeyAllowed)return{lines:[{text:o.isList?`${h}List of foreign key references${T}`:`${h}Foreign key reference${T}`,indentLevel:0}]};if(!o.entity){const M=o.isList;if(!((I=o.andChildrenGroup)!=null&&I.length)&&!((P=o.orChildrenGroup)!=null&&P.length))return{lines:[{text:M?`${h}List of an any data type${T}`:`${h}Any data type${T}`,indentLevel:0}]};const G=[];return M&&G.push({text:`${h}List of `,indentLevel:0}),o.andChildrenGroup&&((V=o.andChildrenGroup)==null?void 0:V.length)>1&&G.push({text:(M?"":h)+"All of the following data types (union):",indentLevel:M?0:-1}),(o.andChildrenGroup||[]).forEach((H,ie)=>{const ee=ie===(o.andChildrenGroup||[]).length-1;og(H,{...i,omitTopLevelType:!0,onPrefix:p.onPrefix}).lines.forEach((de,ye)=>{const ce=ye===0,re=M?de.indentLevel+1:de.indentLevel;G.push({text:ce?"- "+de.text:de.text,indentLevel:ce?re:re+1})}),ee||G.push({text:"AND",indentLevel:0})}),o.orChildrenGroup&&(($=o.orChildrenGroup)==null?void 0:$.length)>1&&G.push({text:(M?"":h)+"One of the following data types (intersection):",indentLevel:M?0:-1}),(o.orChildrenGroup||[]).forEach((H,ie)=>{const ee=ie===(o.orChildrenGroup||[]).length-1;og(H,{...i,omitTopLevelType:!0,onPrefix:p.onPrefix}).lines.forEach((de,ye)=>{const ce=ye===0,re=M?de.indentLevel+1:de.indentLevel;G.push({text:ce?"- "+de.text:de.text,indentLevel:ce?re:re+1})}),ee||G.push({text:"OR",indentLevel:0})}),{lines:G}}}if(o.entity.type===d.PrimitiveEntity){let M=o.entity.name;switch(o.entity.name){case le.String:M="Text";break;case le.KeyValue:M="Object";break;case le.Number:M="Number";break;case le.Boolean:M="Boolean";break;case le.UUID:M="UUIDv4";break;case le.Date:M="Date (string in ISO 8601 format)";break;case le.File:M="File";break;case le.Null:M="Null value";break;case le.Untyped:M="Untyped value (explicit any)";break;case le.Void:M="Void (no returned value)";break;case le.Enum:M=`Enum (options: "${Et(o.options||[],'", "','" and "')}")`;break}return{lines:[{text:o.isList?`${h}List of ${M}s${T}`:`${h}${M.slice(0,1).toUpperCase()}${M.slice(1)}${T}`,indentLevel:0}]}}else if(o.entity.type===d.DefinitionEntity){const M=se(o.entity,o.project),G=a("id")&&!i.omitIdsFor.includes(d.DefinitionEntity)?o.entity.id:"",H=a("type")&&!i.omitTypesFor.includes(d.DefinitionEntity)?d.DefinitionEntity:"",ie=i.firstLabel==="name"?M:G,ee=i.firstLabel==="name"?G:M,pe=`${r}${i.omitTopLevelType?"":H?`${H}: `:""}${ie}${ee?` (${ee})`:""}`,de=[];if(i.nested&&((U=o.entity.parent)==null?void 0:U.id)===o.id){const ye=zt(o.entity,{...i,nested:!0,omitTopLevelType:!1,firstLabel:i.firstLabel,omitIdsFor:i.omitIdsFor,omitTypesFor:i.omitTypesFor,metadataIndent:i.metadataIndent,omitFields:i.omitFields,onlyFields:i.onlyFields,onPrefix:p.onPrefix});o.isList&&de.push({text:`${h}List of:`,indentLevel:0}),ye.lines.forEach(ce=>{de.push({text:ce.text,indentLevel:o.isList?ce.indentLevel+1:ce.indentLevel})})}else de.push({text:o.isList?`${h}List of ${pe} values${T}`:h+pe.slice(0,1).toUpperCase()+pe.slice(1)+T,indentLevel:0});return{lines:de}}else if(o.entity.type===d.BuiltInBaseEntity){const M=jx(o.entity);return{lines:[{text:o.isList?`${h}List of ${M} values${T}`:h+M.slice(0,1).toUpperCase()+M.slice(1)+T,indentLevel:0}]}}else if(o.entity.type===d.LiteralValue){if(o.entity.name===le.Null)return{lines:[{text:`${h}Null value`,indentLevel:0}]};if(o.entity.name===le.Untyped)return{lines:[{text:`${h}Untyped value`,indentLevel:0}]};if(o.entity.name===le.File)return{lines:[{text:`${h}File`,indentLevel:0}]};if(o.entity.name===le.String||o.entity.name===le.Enum)return{lines:[{text:`${h}"${o.entity.value}" text`,indentLevel:0}]};if(o.entity.name===le.Number)return{lines:[{text:`${h}Number '${o.entity.value}'`,indentLevel:0}]};if(o.entity.name===le.Boolean)return{lines:[{text:`${h}${o.entity.value} value`,indentLevel:0}]};if(o.entity.name===le.UUID)return{lines:[{text:`${h}"${o.entity.value}" UUIDv4`,indentLevel:0}]};if(o.entity.name===le.Date)return{lines:[{text:`${h}"${o.entity.value}" date`,indentLevel:0}]};if(o.entity.name===le.KeyValue)return{lines:[{text:`${h}"${o.entity.value}" object`,indentLevel:0}]};if(o.entity.name===le.Bytes)return{lines:[{text:`${h}"${o.entity.value}" bytes`,indentLevel:0}]}}return{lines:[{text:o.isList?`${h}List of ${se(o.entity,o.project)} values${T}`:`${h}${se(o.entity,o.project).slice(0,1).toUpperCase()+se(o.entity,o.project).slice(1)} value${T}`,indentLevel:0}]}}var uGe=(o=>(o.All="all",o.Callers="callers",o.ReadsValue="reads-value",o.WritesValues="writes-values",o.Declaration="declaration",o.Id="id",o.Type="type",o.Name="name",o.Description="description",o.Extends="extends",o.Implements="implements",o.CodeName="code-name",o.DataType="data-type",o))(uGe||{});function ky(o,p={nested:!1,omitTopLevelType:!1,firstLabel:"name",omitIdsFor:[],omitTypesFor:[],metadataIndent:1,ownMetadataIndent:1,omitFields:[],onlyFields:[]}){var a;if(!Vg.includes(o.type))throw new Error(`[generateValueAssignmentLogLine] Entity type ${o.type} is not an entity with value type.`);const i={nested:p.nested??!1,omitTopLevelType:p.omitTopLevelType??!1,firstLabel:p.firstLabel??"name",omitIdsFor:p.omitIdsFor??[],omitTypesFor:p.omitTypesFor??[],metadataIndent:p.metadataIndent??1,omitFields:p.omitFields??[],onlyFields:p.onlyFields??[]},r=p.prefix??"Value assignment";if(Mn.includes(o.type)&&o.readsValue){const e=o.readsValue,f=se(e,o.project);let h="";if(e.type===d.OutputMap||e.type===d.ArgumentDeclaration){const T=e.parent,E=se(T,o.project);h=`${e.type}: "${f}" (${e.id}) of ${T.type}: "${E}"`}else h=`${e.type}: "${f}" (${e.id})`;return`${r} (READING FROM) ${h}`}else if(o.defaultValue){const c=zt(o.defaultValue,{...i,nested:!0,omitTopLevelType:!1,firstLabel:i.firstLabel,omitIdsFor:i.omitIdsFor,omitTypesFor:i.omitTypesFor,metadataIndent:i.metadataIndent,omitFields:i.omitFields,onlyFields:i.onlyFields,onPrefix:p.onPrefix});return`${r} (INLINE) ${c.lines[0].text}`}else return o.type===d.ArgumentDeclaration?o.parent.parent.type===d.Loop?((a=o.parent.parent.currentIterationNumberArgumentDeclaration)==null?void 0:a.id)===o.id?`${r} INIT BY SYSTEM current loop iteration number`:`${r} INIT BY SYSTEM with aggregate value from prev loop body`:o.parent.parent.type===d.DefinitionEntity&&[...Hke(o.parent.parent)].some(e=>o.project.diggestedBuiltInBaseEntitiesIds.has(e.id))?`${r} INIT BY SYSTEM when function is invoked`:`${r} NONE`:`${r} NONE`}function pGe(o,p={nested:!1,omitTopLevelType:!1,firstLabel:"name",omitIdsFor:[],omitTypesFor:[],metadataIndent:1,ownMetadataIndent:1,omitFields:[],onlyFields:[]}){if(!Ji.includes(o.type))throw new Error(`[generateValueAssignmentLogLine] Entity type ${o.type} is not a value writing type.`);const i={nested:p.nested??!1,omitTopLevelType:p.omitTopLevelType??!1,firstLabel:p.firstLabel??"name",omitIdsFor:p.omitIdsFor??[],omitTypesFor:p.omitTypesFor??[],metadataIndent:p.metadataIndent??1,omitFields:p.omitFields??[],onlyFields:p.onlyFields??[]},r=[],a=p.prefix??"Writes values to";return o.writesValues.length?o.writesValues.forEach(c=>{const e=se(c,o.project);let f="";if(c.type===d.InputMap){const h=c.parent,T=se(h,o.project);f=`${c.type}: "${e}" (${c.id}) of ${h.type}: "${T}"`}else f=`${c.type}: "${e}" (${c.id})`;r.push({text:`${a} ${f}`,indentLevel:i.metadataIndent})}):r.push({text:`${a} NONE`,indentLevel:i.metadataIndent}),{lines:r}}function sT(o,p={nested:!1,omitTopLevelType:!1,firstLabel:"name",omitIdsFor:[],omitTypesFor:[],metadataIndent:1,ownMetadataIndent:1,omitFields:[],onlyFields:[]}){const i={nested:p.nested??!1,omitTopLevelType:p.omitTopLevelType??!1,firstLabel:p.firstLabel??"name",omitIdsFor:p.omitIdsFor??[],omitTypesFor:p.omitTypesFor??[],metadataIndent:p.metadataIndent??1,omitFields:p.omitFields??[],onlyFields:p.onlyFields??[]},r=[];if(o.length>0){r.push({text:`${p.label??"OUTPUTS:"}`,indentLevel:i.metadataIndent});for(const a of o)if(a){const c=zt(a,{...i,nested:!0,omitTopLevelType:!1,firstLabel:i.firstLabel,omitIdsFor:i.omitIdsFor,omitTypesFor:i.omitTypesFor,metadataIndent:i.metadataIndent,omitFields:i.omitFields,onlyFields:i.onlyFields,onPrefix:p.onPrefix});c.lines.forEach((e,f)=>{const h=f===0,T=f===c.lines.length-1;r.push({text:h?"- "+e.text:e.text,indentLevel:h?e.indentLevel+2:e.indentLevel+3}),T&&r.push({text:"",indentLevel:e.indentLevel+2})})}}else r.push({text:`${p.label??"OUTPUTS:"} None`,indentLevel:i.metadataIndent});return{lines:r}}function Bu(o,p={nested:!1,omitTopLevelType:!1,firstLabel:"name",omitIdsFor:[],omitTypesFor:[],metadataIndent:1,ownMetadataIndent:1,omitFields:[],onlyFields:[]}){const i={nested:p.nested??!1,omitTopLevelType:p.omitTopLevelType??!1,firstLabel:p.firstLabel??"name",omitIdsFor:p.omitIdsFor??[],omitTypesFor:p.omitTypesFor??[],metadataIndent:p.metadataIndent??1,omitFields:p.omitFields??[],onlyFields:p.onlyFields??[]},r=[];if(o.length>0){r.push({text:`${p.label??"INPUTS:"}`,indentLevel:i.metadataIndent});for(const a of o)if(a){const c=zt(a,{...i,nested:!0,omitTopLevelType:!1,firstLabel:i.firstLabel,omitIdsFor:i.omitIdsFor,omitTypesFor:i.omitTypesFor,metadataIndent:i.metadataIndent,omitFields:i.omitFields,onlyFields:i.onlyFields,onPrefix:p.onPrefix});c.lines.forEach((e,f)=>{const h=f===0,T=f===c.lines.length-1;r.push({text:h?"- "+e.text:e.text,indentLevel:h?e.indentLevel+(p.firstListItemIndent??2):e.indentLevel+(p.otherListItemIndent??3)}),T&&r.push({text:"",indentLevel:e.indentLevel+2})})}}else r.push({text:`${p.label??"INPUTS:"} None`,indentLevel:i.metadataIndent});return{lines:r}}function Mu(o,p={nested:!1,omitTopLevelType:!1,firstLabel:"name",omitIdsFor:[],omitTypesFor:[],metadataIndent:1,ownMetadataIndent:1,omitFields:[],onlyFields:[]}){const i={nested:p.nested??!1,omitTopLevelType:p.omitTopLevelType??!1,firstLabel:p.firstLabel??"name",omitIdsFor:p.omitIdsFor??[],omitTypesFor:p.omitTypesFor??[],metadataIndent:p.metadataIndent??1,omitFields:p.omitFields??[],onlyFields:p.onlyFields??[]},r=[],a=i.onlyFields.length>0&&i.onlyFields.includes("data-type")||i.omitFields.length>0&&!i.omitFields.includes("data-type")||i.onlyFields.length===0&&i.omitFields.length===0;if(!o)a&&r.push({text:"Data Type: Any (unspecified data type)",indentLevel:0});else if(a){const c=zt(o,{...i,nested:!0,omitTopLevelType:!0,firstLabel:i.firstLabel,omitIdsFor:i.omitIdsFor,omitTypesFor:i.omitTypesFor,metadataIndent:i.metadataIndent,omitFields:i.omitFields,onlyFields:i.onlyFields,onPrefix:p.onPrefix});c.lines.length===1?r.push({text:`Data Type: ${c.lines[0].text}`,indentLevel:0}):(r.push({text:"Data Type:",indentLevel:0}),c.lines.forEach(e=>{r.push({text:e.text,indentLevel:e.indentLevel+1})}))}return{lines:r}}function lT(o,p={nested:!1,omitTopLevelType:!1,firstLabel:"name",omitIdsFor:[],omitTypesFor:[],metadataIndent:1,ownMetadataIndent:1,omitFields:[],onlyFields:[]}){var a;const i={nested:p.nested??!1,omitTopLevelType:p.omitTopLevelType??!1,firstLabel:p.firstLabel??"name",omitIdsFor:p.omitIdsFor??[],omitTypesFor:p.omitTypesFor??[],metadataIndent:p.metadataIndent??1,omitFields:p.omitFields??[],onlyFields:p.onlyFields??[]},r=[];if(o.error&&(((a=o.error)==null?void 0:a.writesValues)||[]).length>0){const c="CAUGHT ERROR value read by:";r.push({text:c,indentLevel:i.metadataIndent}),o.error.writesValues.forEach(f=>{const h=se(f,o.project);let T="";if(f.type===d.InputMap){const E=f.parent,b=se(E,o.project);T=`${f.type}: "${h}" (${f.id}) of ${E.type}: "${b}"`}else T=`${f.type}: "${h}" (${f.id})`;r.push({text:T,indentLevel:i.metadataIndent+1})})}return{lines:r}}function zt(o,p={nested:!1,omitTopLevelType:!1,firstLabel:"name",omitIdsFor:[],omitTypesFor:[],metadataIndent:1,ownMetadataIndent:1,omitFields:[],onlyFields:[]}){var V,$,U,M,G,H,ie,ee,pe,de,ye;const i={nested:p.nested??!1,omitTopLevelType:p.omitTopLevelType??!1,firstLabel:p.firstLabel??"name",omitIdsFor:p.omitIdsFor??[],omitTypesFor:p.omitTypesFor??[],metadataIndent:p.metadataIndent??1,omitFields:p.omitFields??[],onlyFields:p.onlyFields??[]};function r(ce){return i.onlyFields.length>0?i.onlyFields.includes(ce):i.omitFields.length>0?!i.omitFields.includes(ce):!0}const a=p.ownMetadataIndent??p.metadataIndent??1,c=p.onPrefix?p.onPrefix(o):"";if(o.type===d.LiteralValue){let ce=(V=o.value)==null?void 0:V.toString();try{ce=JSON.stringify(o.value,null,2).replace(/\n/g,"")}catch{}if(o.valueAsTypeList&&!o.valueAsTypeSingle&&o.valueAsTypeList.length>0)ce=Et(o.valueAsTypeList.map(ge=>`${ge.type} "${se(ge,o.project)}" (${ge.id})`),", "," and ");else if(o.valueAsTypeSingle){const ge=o.valueAsTypeSingle;ce=`${ge.type} "${se(ge,o.project)}" (${ge.id})`}let re="";switch(o.name){case le.Bytes:re="Bytes";break;case le.String:re="Text";break;case le.KeyValue:re="Object";break;case le.Number:re="Number";break;case le.Boolean:re="Boolean";break;case le.UUID:re="Unique identifier UUIDv4";break;case le.Date:re="Date (string in ISO 8601 format)";break;case le.File:re="File";break;case le.Null:re="Null value (explicit empty)";break;case le.Untyped:re="Untyped value (explicit any)";break;case le.Void:re="Void (no returned value)";break;case le.Enum:re="Enum (set of text options)";break;case le.EntityTemplate:{re="Entity (as type/constructor)",o.valueAsTypeList&&!o.valueAsTypeSingle&&(re+=" list");break}default:re=se(o,o.project);break}r("name")||(re="");const ne=r("id")&&!i.omitIdsFor.includes(d.LiteralValue)?o.id:"",fe=r("type")&&!i.omitTypesFor.includes(d.LiteralValue)?o.type:"",Te=i.firstLabel==="name"?re:ne,Ae=i.firstLabel==="name"?ne:re;return{lines:[{text:`${c}${i.omitTopLevelType?"":fe?`${fe}: `:""}${Te}${Ae?` (${Ae})`:""} = ${ce}`,indentLevel:0}]}}if(o.type===d.PrimitiveEntity){const ce=r("id")&&!i.omitIdsFor.includes(d.PrimitiveEntity)?o.id:"",re=r("type")&&!i.omitTypesFor.includes(d.PrimitiveEntity)?o.type:"";let ne="";switch(o.name){case le.Bytes:ne="Bytes";break;case le.String:ne="Text";break;case le.KeyValue:ne="Object";break;case le.Number:ne="Number";break;case le.Boolean:ne="Boolean";break;case le.UUID:ne="Unique identifier UUIDv4";break;case le.Date:ne="Date (string in ISO 8601 format)";break;case le.File:ne="File";break;case le.Null:ne="Null value (explicit empty)";break;case le.Untyped:ne="Untyped value (explicit any)";break;case le.Void:ne="Void (no returned value)";break;case le.Enum:ne="Enum (set of text options)";break;case le.EntityTemplate:{ne="Entity as type/constructor";break}default:ne=se(o,o.project);break}r("name")||(ne="");const fe=i.firstLabel==="name"?ne:ce,Te=i.firstLabel==="name"?ce:ne,Ae=[{text:`${c}${i.omitTopLevelType?"":re?`${re}: `:""}${fe}${Te?` (${Te})`:""}`,indentLevel:0}],ge=(($=o.description)==null?void 0:$.replace(/[\r\n]+/g," ").trim())||"";if(ge&&r("description")&&Ae.push({text:`${ge}`,indentLevel:a}),o.extends&&r("extends")){const Ne=se(o.extends,o.project);Ae.push({text:`Extends: ${Ne}`,indentLevel:a})}return{lines:Ae}}if(o.type===d.DataType){const ce=og(o,{...i,onPrefix:p.onPrefix}),re=[];return ce.lines.forEach(ne=>{re.push({text:ne.text,indentLevel:ne.indentLevel+1})}),{lines:re}}const e=r("name")?se(o,o.project):"",f=r("id")&&!i.omitIdsFor.includes(o.type)?o.id:"",h=r("type")&&!i.omitTypesFor.includes(o.type)?o.type:"",T=i.firstLabel==="name"?e:f,E=i.firstLabel==="name"?f:e,I=[{text:`${c}${i.omitTopLevelType?"":h?`${h}: `:""}${T}${E?` (${E})`:""}`,indentLevel:0}],P=((U=o.description)==null?void 0:U.replace(/[\r\n]+/g," ").trim())||"";if(P&&r("description")&&I.push({text:`${P}`,indentLevel:a}),o.codeName&&r("code-name")&&I.push({text:`Explicit name when compiled: ${o.codeName}`,indentLevel:a}),Mn.includes(o.type)&&r("reads-value")&&!o.defaultValue&&(!Nt.includes(o.type)||!o.throws)){const ce=ky(o,{prefix:"Value assignment",...i});I.push({text:ce,indentLevel:a})}if(Ji.includes(o.type)&&r("writes-values")){let ce="Writes values to";Jt.includes(o.type)?ce="Full returned value read by":Ot.includes(o.type)&&(ce="Main (full) value written to"),pGe(o,{prefix:ce,...i}).lines.forEach(ne=>{I.push({text:ne.text,indentLevel:ne.indentLevel})})}if(o.declaration&&r("declaration")){const ce=o;let re="";ce.declaration.type!==d.VariableDeclaration&&(re=`${ce.declaration.type}: `),I.push({text:`Declaration ${re}${ce.declaration.id}`,indentLevel:a})}if(i.nested)switch(o.type){case d.Search:{if(I.push({text:`QUERY: \`${(o.query||"").replace("{{::","{{::input-map-value:")}\``,indentLevel:a}),I.push({text:`Error handling: ${o.catchesError?"YES (catches)":"NO (can throw)"}`,indentLevel:a}),o.inputsDeclarations.length>0){I.push({text:"INPUTS (inline-declared):",indentLevel:i.metadataIndent});for(const fe of o.inputsDeclarations)if(fe){const Te=zt(fe,{...i,nested:!0,omitTopLevelType:!1,firstLabel:i.firstLabel,omitIdsFor:i.omitIdsFor,omitTypesFor:i.omitTypesFor,metadataIndent:i.metadataIndent,omitFields:i.omitFields,onlyFields:i.onlyFields,onPrefix:p.onPrefix});Te.lines.forEach((Ae,ge)=>{const Ne=ge===0,Fe=ge===Te.lines.length-1;I.push({text:Ne?"- "+Ae.text:Ae.text,indentLevel:Ne?Ae.indentLevel+2:Ae.indentLevel+3}),Fe&&I.push({text:"",indentLevel:Ae.indentLevel+2})})}}else I.push({text:"INPUTS: None",indentLevel:i.metadataIndent});lT(o,{...i,onPrefix:p.onPrefix}).lines.forEach(fe=>{I.push({text:fe.text,indentLevel:fe.indentLevel})}),I.push({text:"OUTPUT:",indentLevel:a});const re=o.getDataType(null);if(!re)I.push({text:"Data Type: Any (unspecified data type)",indentLevel:a+1});else{const fe=zt(re,{...i,nested:!0,omitTopLevelType:!0,firstLabel:i.firstLabel,omitIdsFor:i.omitIdsFor,omitTypesFor:i.omitTypesFor,metadataIndent:i.metadataIndent,omitFields:i.omitFields,onlyFields:i.onlyFields,onPrefix:p.onPrefix});fe.lines.length===1?I.push({text:`Data Type: ${fe.lines[0].text}`,indentLevel:2}):fe.lines.forEach(Te=>{I.push({text:Te.text,indentLevel:Te.indentLevel+1})})}const ne=o.outputs.filter(fe=>!!fe.writesValues.length);ne.length>0&&sT(ne,{label:"DESTRUCT RETURNED PROPERTIES: ",...i,onPrefix:p.onPrefix}).lines.forEach(Te=>{I.push({text:Te.text,indentLevel:Te.indentLevel})});break}case d.Condition:{((M=o.declaration)==null?void 0:M.id)!==te.condition["condition-group-and"].id&&((G=o.declaration)==null?void 0:G.id)!==te.condition["condition-group-or"].id&&Bu(o.inputs,{...i,onPrefix:p.onPrefix}).lines.forEach(re=>{I.push({text:re.text,indentLevel:re.indentLevel})}),((H=o.declaration)==null?void 0:H.id)===te.condition["condition-group-and"].id?(I.push({text:"NESTED AND (all conditions must be true)",indentLevel:a}),(o.andChildrenGroup||[]).forEach((ce,re)=>{const ne=zt(ce,{...i,nested:!0,omitTopLevelType:!1,firstLabel:i.firstLabel,omitIdsFor:i.omitIdsFor,omitTypesFor:i.omitTypesFor,metadataIndent:i.metadataIndent,omitFields:i.omitFields,onlyFields:i.onlyFields,onPrefix:p.onPrefix}),fe=re===(o.andChildrenGroup||[]).length-1;ne.lines.forEach((Te,Ae)=>{const ge=Ae===0;I.push({text:ge?"- "+Te.text:Te.text,indentLevel:ge?Te.indentLevel+2:Te.indentLevel+3})}),fe||I.push({text:"AND",indentLevel:a+2})})):((ie=o.declaration)==null?void 0:ie.id)===te.condition["condition-group-or"].id&&(I.push({text:"NESTED OR (at least one condition must be true)",indentLevel:a}),(o.orChildrenGroup||[]).forEach((ce,re)=>{const ne=zt(ce,{...i,nested:!0,omitTopLevelType:!1,firstLabel:i.firstLabel,omitIdsFor:i.omitIdsFor,omitTypesFor:i.omitTypesFor,metadataIndent:i.metadataIndent,omitFields:i.omitFields,onlyFields:i.onlyFields,onPrefix:p.onPrefix}),fe=re===(o.orChildrenGroup||[]).length-1;ne.lines.forEach((Te,Ae)=>{const ge=Ae===0;I.push({text:ge?"- "+Te.text:Te.text,indentLevel:ge?Te.indentLevel+2:Te.indentLevel+3})}),fe||I.push({text:"OR",indentLevel:a+2})}));break}case d.ActionDescriptor:{if(Bu(o.inputs,{...i,onPrefix:p.onPrefix}).lines.forEach(fe=>{I.push({text:fe.text,indentLevel:fe.indentLevel})}),o.error&&(I.push({text:"POTENTIAL ERROR:",indentLevel:a}),zt(o.error,{...i,nested:!0,omitTopLevelType:!1,firstLabel:i.firstLabel,omitIdsFor:i.omitIdsFor,omitTypesFor:i.omitTypesFor,metadataIndent:i.metadataIndent,omitFields:i.omitFields,onlyFields:i.onlyFields,onPrefix:p.onPrefix}).lines.forEach(Te=>{I.push({text:Te.text,indentLevel:Te.indentLevel+2})})),eFe(o)===d.Loop){const fe=tFe(o);fe&&(I.push({text:"Body:",indentLevel:a}),zt(fe,{...i,nested:!0,omitTopLevelType:!1,firstLabel:i.firstLabel,omitIdsFor:i.omitIdsFor,omitTypesFor:i.omitTypesFor,metadataIndent:i.metadataIndent,omitFields:i.omitFields,onlyFields:i.onlyFields,onPrefix:p.onPrefix}).lines.forEach(Ae=>{I.push({text:Ae.text,indentLevel:Ae.indentLevel+2})}))}I.push({text:"OUTPUT:",indentLevel:a});const ne=o.getDataType(null);if(!ne)I.push({text:"Data Type: Any (unspecified data type)",indentLevel:a+1});else{const fe=zt(ne,{...i,nested:!0,omitTopLevelType:!0,firstLabel:i.firstLabel,omitIdsFor:i.omitIdsFor,omitTypesFor:i.omitTypesFor,metadataIndent:i.metadataIndent,omitFields:i.omitFields,onlyFields:i.onlyFields,onPrefix:p.onPrefix});fe.lines.length===1?I.push({text:`Data Type: ${fe.lines[0].text}`,indentLevel:2}):fe.lines.forEach(Te=>{I.push({text:Te.text,indentLevel:Te.indentLevel+1})})}break}case d.GlobalEvent:case d.FunctionDeclaration:{Bu(o.inputs,{...i,firstListItemIndent:2,otherListItemIndent:4,onPrefix:p.onPrefix}).lines.forEach(ne=>{I.push({text:ne.text,indentLevel:ne.indentLevel})}),I.push({text:"OUTPUT:",indentLevel:a});const re=o.getDataType(null);if(!re)I.push({text:"Data Type: Any (unspecified data type)",indentLevel:a+1});else{const ne=zt(re,{...i,nested:!0,omitTopLevelType:!0,firstLabel:i.firstLabel,omitIdsFor:i.omitIdsFor,omitTypesFor:i.omitTypesFor,metadataIndent:i.metadataIndent,omitFields:i.omitFields,onlyFields:i.onlyFields,onPrefix:p.onPrefix});ne.lines.length===1?I.push({text:`Data Type: ${ne.lines[0].text}`,indentLevel:2}):ne.lines.forEach(fe=>{I.push({text:fe.text,indentLevel:fe.indentLevel+1})})}break}case d.InputMap:{const ce=o.getDataType(null);if(Mu(ce,{...i,onPrefix:p.onPrefix}).lines.forEach(ne=>{I.push({text:ne.text,indentLevel:ne.indentLevel+1})}),o.defaultValue){const fe=`Value assignment (INLINE): ${zt(o.defaultValue,{...i,nested:!0,omitTopLevelType:!1,firstLabel:i.firstLabel,omitIdsFor:i.omitIdsFor,omitTypesFor:i.omitTypesFor,metadataIndent:i.metadataIndent,omitFields:i.omitFields,onlyFields:i.onlyFields,onPrefix:p.onPrefix}).lines[0].text}`;I.push({text:fe,indentLevel:1})}break}case d.ValueDescriptor:{const ce=o.getDataType(null);if(Mu(ce,{...i,onPrefix:p.onPrefix}).lines.forEach(ne=>{I.push({text:ne.text,indentLevel:ne.indentLevel+1})}),((ee=o.parent)==null?void 0:ee.type)===d.Search){const ne=o.parent.inputs.find(fe=>{var Te;return((Te=fe.declaration)==null?void 0:Te.id)===o.id});ne&&zt(ne,{...i,nested:!0,omitTopLevelType:!1,firstLabel:i.firstLabel,omitIdsFor:i.omitIdsFor,omitTypesFor:i.omitTypesFor,metadataIndent:i.metadataIndent,omitFields:[...i.omitFields,"declaration","data-type","name"],onlyFields:i.onlyFields,onPrefix:p.onPrefix}).lines.forEach(Te=>{I.push({text:Te.text,indentLevel:Te.indentLevel})})}else if(o.defaultValue){const fe=`Value assignment (INLINE): ${zt(o.defaultValue,{...i,nested:!0,omitTopLevelType:!1,firstLabel:i.firstLabel,omitIdsFor:i.omitIdsFor,omitTypesFor:i.omitTypesFor,metadataIndent:i.metadataIndent,omitFields:i.omitFields,onlyFields:i.onlyFields,onPrefix:p.onPrefix}).lines[0].text}`;I.push({text:fe,indentLevel:1})}break}case d.DefinitionEntity:{const ce=[];if(o.abstract&&ce.push("abstract"),o.static&&ce.push("static"),o.additionalProperties?ce.push("additional properties allowed"):ce.push("no additional properties allowed"),I.push({text:`Modifiers: ${ce.join(", ")}`,indentLevel:a}),(pe=o.implements)!=null&&pe.length&&(I.push({text:"Implements:",indentLevel:a}),o.implements.forEach(re=>{const ne=se(re,o.project),fe=i.firstLabel==="name"?ne:re.id,Te=i.firstLabel==="name"?re.id:ne,Ae=r("type")&&!i.omitTypesFor.includes(re.type)?re.type:"",ge=`${Ae?Ae+": ":""}${fe}${Te?` (${Te})`:""}`;I.push({text:`- ${ge}`,indentLevel:a+1})})),o.extends){const re=se(o.extends,o.project),ne=i.firstLabel==="name"?re:o.extends.id,fe=i.firstLabel==="name"?o.extends.id:re,Te=r("type")&&!i.omitTypesFor.includes(o.extends.type)?o.extends.type:"",Ae=`${Te?Te+": ":""}${ne}${fe?` (${fe})`:""}`;I.push({text:`Extends: ${Ae}`,indentLevel:a})}if(o.allPropertiesImplement&&(I.push({text:"ALL PROPERTIES IMPLEMENT:",indentLevel:a}),zt(o.allPropertiesImplement,{...i,nested:!0,omitTopLevelType:!1,firstLabel:i.firstLabel,omitIdsFor:i.omitIdsFor,omitTypesFor:i.omitTypesFor,metadataIndent:1,ownMetadataIndent:0,omitFields:i.omitFields,onlyFields:i.onlyFields,onPrefix:p.onPrefix}).lines.forEach(ne=>{I.push({text:ne.text,indentLevel:ne.indentLevel+1})})),o.additionalPropertiesDataType&&(I.push({text:"ADDITIONAL PROPERTIES DATA TYPE:",indentLevel:a}),zt(o.additionalPropertiesDataType,{...i,nested:!0,omitTopLevelType:!1,firstLabel:i.firstLabel,omitIdsFor:i.omitIdsFor,omitTypesFor:i.omitTypesFor,metadataIndent:1,ownMetadataIndent:0,omitFields:i.omitFields,onlyFields:i.onlyFields,onPrefix:p.onPrefix}).lines.forEach(ne=>{I.push({text:ne.text,indentLevel:ne.indentLevel+1})})),o.ownDeclaredProperties.length>0){I.push({text:"PROPERTIES:",indentLevel:a});for(const re of o.properties){const ne=zt(re,{...i,nested:!0,omitTopLevelType:!1,firstLabel:i.firstLabel,omitIdsFor:i.omitIdsFor,omitTypesFor:i.omitTypesFor,metadataIndent:1,ownMetadataIndent:0,omitFields:i.omitFields,onlyFields:i.onlyFields,onPrefix:p.onPrefix});ne.lines.forEach((fe,Te)=>{const Ae=Te===0,ge=Te===ne.lines.length-1;I.push({text:Ae?"- "+fe.text:fe.text,indentLevel:Ae?fe.indentLevel+2:fe.indentLevel+4}),ge&&I.push({text:"",indentLevel:fe.indentLevel+2})})}}if(o.methods.length>0){I.push({text:"METHODS:",indentLevel:a});for(const re of o.methods){const ne=zt(re,{...i,nested:!0,omitTopLevelType:!1,firstLabel:i.firstLabel,omitIdsFor:i.omitIdsFor,omitTypesFor:i.omitTypesFor,metadataIndent:0,omitFields:i.omitFields,onlyFields:i.onlyFields,onPrefix:p.onPrefix});ne.lines.forEach((fe,Te)=>{const Ae=Te===0,ge=Te===ne.lines.length-1;I.push({text:Ae?"- "+fe.text:fe.text,indentLevel:Ae?fe.indentLevel+2:fe.indentLevel+3}),ge&&I.push({text:"",indentLevel:fe.indentLevel+2})})}}if(o.abstractMethods.length>0){I.push({text:"Abstract methods (action-descriptors):",indentLevel:1});for(const re of o.abstractMethods){const ne=zt(re,{...i,nested:!0,omitTopLevelType:!1,firstLabel:i.firstLabel,omitIdsFor:i.omitIdsFor,omitTypesFor:i.omitTypesFor,metadataIndent:0,omitFields:i.omitFields,onlyFields:i.onlyFields,onPrefix:p.onPrefix});ne.lines.forEach((fe,Te)=>{const Ae=Te===0,ge=Te===ne.lines.length-1;I.push({text:Ae?"- "+fe.text:fe.text,indentLevel:Ae?fe.indentLevel+2:fe.indentLevel+3}),ge&&I.push({text:"",indentLevel:fe.indentLevel+2})})}}break}case d.BuiltInBaseEntity:{const ce=[];if(o.abstract&&ce.push("abstract"),o.static&&ce.push("static"),o.additionalProperties?ce.push("additional properties allowed"):ce.push("no additional properties allowed"),I.push({text:`Modifiers: ${ce.join(", ")}`,indentLevel:a}),o.extends){const re=se(o.extends,o.project),ne=i.firstLabel==="name"?re:o.extends.id,fe=i.firstLabel==="name"?o.extends.id:re,Te=r("type")&&!i.omitTypesFor.includes(o.extends.type)?o.extends.type:"",Ae=`${Te?Te+": ":""}${ne}${fe?` (${fe})`:""}`;I.push({text:`Extends: ${Ae}`,indentLevel:a})}if(o.allPropertiesImplement&&(I.push({text:"ALL PROPERTIES IMPLEMENT:",indentLevel:a}),zt(o.allPropertiesImplement,{...i,nested:!0,omitTopLevelType:!1,firstLabel:i.firstLabel,omitIdsFor:i.omitIdsFor,omitTypesFor:i.omitTypesFor,metadataIndent:1,ownMetadataIndent:0,omitFields:i.omitFields,onlyFields:i.onlyFields,onPrefix:p.onPrefix}).lines.forEach(ne=>{I.push({text:ne.text,indentLevel:ne.indentLevel+1})})),o.additionalPropertiesDataType&&(I.push({text:"ADDITIONAL PROPERTIES DATA TYPE:",indentLevel:a}),zt(o.additionalPropertiesDataType,{...i,nested:!0,omitTopLevelType:!1,firstLabel:i.firstLabel,omitIdsFor:i.omitIdsFor,omitTypesFor:i.omitTypesFor,metadataIndent:1,ownMetadataIndent:0,omitFields:i.omitFields,onlyFields:i.onlyFields,onPrefix:p.onPrefix}).lines.forEach(ne=>{I.push({text:ne.text,indentLevel:ne.indentLevel+1})})),o.ownDeclaredProperties.length>0){I.push({text:"PROPERTIES:",indentLevel:a});for(const re of o.properties){const ne=zt(re,{...i,nested:!0,omitTopLevelType:!1,firstLabel:i.firstLabel,omitIdsFor:i.omitIdsFor,omitTypesFor:i.omitTypesFor,metadataIndent:0,omitFields:i.omitFields,onlyFields:i.onlyFields,onPrefix:p.onPrefix});ne.lines.forEach((fe,Te)=>{const Ae=Te===0,ge=Te===ne.lines.length-1;I.push({text:Ae?"- "+fe.text:fe.text,indentLevel:Ae?fe.indentLevel+2:fe.indentLevel+3}),ge&&I.push({text:"",indentLevel:fe.indentLevel+2})})}}if(o.abstractMethods.length>0){I.push({text:"ABSTRACT METHODS (action-descriptors):",indentLevel:a});for(const re of o.abstractMethods){const ne=zt(re,{...i,nested:!0,omitTopLevelType:!1,firstLabel:i.firstLabel,omitIdsFor:i.omitIdsFor,omitTypesFor:i.omitTypesFor,metadataIndent:0,omitFields:i.omitFields,onlyFields:i.onlyFields,onPrefix:p.onPrefix});ne.lines.forEach((fe,Te)=>{const Ae=Te===0,ge=Te===ne.lines.length-1;I.push({text:Ae?"- "+fe.text:fe.text,indentLevel:Ae?fe.indentLevel+2:fe.indentLevel+3}),ge&&I.push({text:"",indentLevel:fe.indentLevel+2})})}}break}case d.Property:{if(o.abstract||o.static||o.constant||o.private||o.required){const ce=[];o.abstract&&ce.push("abstract"),o.static&&ce.push("static"),o.constant&&ce.push("constant"),o.private&&ce.push("private"),o.required&&ce.push("required"),I.push({text:`Modifiers: ${ce.join(", ")}`,indentLevel:a})}if((de=o.implements)!=null&&de.length&&(I.push({text:"Implements:",indentLevel:a}),o.implements.forEach(ce=>{const re=se(ce,o.project),ne=i.firstLabel==="name"?re:ce.id,fe=i.firstLabel==="name"?ce.id:re,Te=r("type")&&!i.omitTypesFor.includes(ce.type)?ce.type:"",Ae=`${Te?Te+": ":""}${ne}${fe?` (${fe})`:""}`;I.push({text:`- ${Ae}`,indentLevel:a+1})})),o.extends){const ce=se(o.extends,o.project),re=se(o.extends.parent,o.project),ne=i.firstLabel==="name"?ce:o.extends.id,fe=i.firstLabel==="name"?o.extends.id:ce,Te=r("type")&&!i.omitTypesFor.includes(o.extends.type)?o.extends.type:"",Ae=`${Te?Te+": ":""}${ne}${fe?` (${fe})`:""}`;I.push({text:`Extends: ${Ae} -- from: ${re}`,indentLevel:a})}if(!o.extends){const ce=o.getDataType(null);Mu(ce,{...i,onPrefix:p.onPrefix}).lines.forEach(ne=>{I.push({text:ne.text,indentLevel:ne.indentLevel})})}if(o.defaultValue){const re=`Value assignment (INLINE): ${zt(o.defaultValue,{...i,nested:!0,omitTopLevelType:!1,firstLabel:i.firstLabel,omitIdsFor:i.omitIdsFor,omitTypesFor:i.omitTypesFor,metadataIndent:i.metadataIndent,omitFields:i.omitFields,onlyFields:i.onlyFields,onPrefix:p.onPrefix}).lines[0].text}`;I.push({text:re,indentLevel:a})}break}case d.ArgumentDeclaration:{if(o.required||o.constant){const ne=[];o.constant&&ne.push("constant (mandatory)"),o.required&&ne.push("required"),I.push({text:`Modifiers: ${ne.join(", ")}`,indentLevel:a})}(ye=o.implements)!=null&&ye.length&&(I.push({text:"Implements:",indentLevel:a}),o.implements.forEach(ne=>{const fe=se(ne,o.project),Te=i.firstLabel==="name"?fe:ne.id,Ae=i.firstLabel==="name"?ne.id:fe,ge=r("type")&&!i.omitTypesFor.includes(ne.type)?ne.type:"",Ne=`${ge?ge+": ":""}${Te}${Ae?` (${Ae})`:""}`;I.push({text:`- ${Ne}`,indentLevel:a+1})}));const ce=o.getDataType(null);if(Mu(ce,{...i,onPrefix:p.onPrefix}).lines.forEach(ne=>{I.push({text:ne.text,indentLevel:ne.indentLevel})}),o.defaultValue){const fe=`Default value (INLINE): ${zt(o.defaultValue,{...i,nested:!0,omitTopLevelType:!1,firstLabel:i.firstLabel,omitIdsFor:i.omitIdsFor,omitTypesFor:i.omitTypesFor,metadataIndent:i.metadataIndent,omitFields:i.omitFields,onlyFields:i.onlyFields,onPrefix:p.onPrefix}).lines[0].text}`;I.push({text:fe,indentLevel:a})}break}case d.OutputMap:{const ce=o.getDataType(null);Mu(ce,{...i,onPrefix:p.onPrefix}).lines.forEach(ne=>{I.push({text:ne.text,indentLevel:ne.indentLevel+1})});break}case d.ContinueStatement:case d.BreakStatement:case d.ReturnStatement:{const ce=o.getDataType(null);if(Mu(ce,{...i,onPrefix:p.onPrefix}).lines.forEach(fe=>{I.push({text:fe.text,indentLevel:fe.indentLevel+1})}),o.throws){const fe=ky(o.throws,{prefix:"THROWS ERROR:"});I.push({text:fe,indentLevel:a})}if(o.defaultValue){const Te=`Value assignment (INLINE): ${zt(o.defaultValue,{...i,nested:!0,omitTopLevelType:!1,firstLabel:i.firstLabel,omitIdsFor:i.omitIdsFor,omitTypesFor:i.omitTypesFor,metadataIndent:i.metadataIndent,omitFields:i.omitFields,onlyFields:i.onlyFields,onPrefix:p.onPrefix}).lines[0].text}`;I.push({text:Te,indentLevel:a})}const ne=o.outputs.filter(fe=>!!fe.readsValue||!!fe.defaultValue);ne.length>0&&Bu(ne,{label:"PROPERTIES ASSIGNED: ",...i,onPrefix:p.onPrefix}).lines.forEach(Te=>{I.push({text:Te.text,indentLevel:Te.indentLevel})});break}case d.VariableInstance:case d.VariableDeclaration:{I.push({text:`Error handling: ${o.catchesError?"YES (catches)":"NO (can throw)"}`,indentLevel:a});const ce=o.getDataType(null);if(Mu(ce,{...i,onPrefix:p.onPrefix}).lines.forEach(ge=>{I.push({text:ge.text,indentLevel:ge.indentLevel+1})}),o.defaultValue){const Ne=`Value assignment (INLINE): ${zt(o.defaultValue,{...i,nested:!0,omitTopLevelType:!1,firstLabel:i.firstLabel,omitIdsFor:i.omitIdsFor,omitTypesFor:i.omitTypesFor,metadataIndent:i.metadataIndent,omitFields:i.omitFields,onlyFields:i.onlyFields,onPrefix:p.onPrefix}).lines[0].text}`;I.push({text:Ne,indentLevel:a})}const ne=o.inputs.filter(ge=>!!ge.readsValue||!!ge.defaultValue);ne.length>0&&Bu(ne,{label:"PROPERTIES ASSIGNED: ",...i,onPrefix:p.onPrefix,omitFields:[...i.omitFields,"data-type"]}).lines.forEach(Ne=>{I.push({text:Ne.text,indentLevel:Ne.indentLevel})}),lT(o,{...i,onPrefix:p.onPrefix}).lines.forEach(ge=>{I.push({text:ge.text,indentLevel:ge.indentLevel})});const Te=o.outputs.filter(ge=>!!ge.writesValues.length);Te.length>0&&sT(Te,{label:"DESTRUCT PROPS READ BY OTHERS: ",...i,onPrefix:p.onPrefix,omitFields:[...i.omitFields]}).lines.forEach(Ne=>{I.push({text:Ne.text,indentLevel:Ne.indentLevel})});const Ae=o.internalCalls.filter(ge=>!!ge.calledBy.length||!!ge.successCalls.length||!!ge.errorCalls.length);if(Ae.length>0){I.push({text:"METHOD CALLS:",indentLevel:a});for(const ge of Ae){const Ne=zt(ge,{...i,nested:!0,omitTopLevelType:!1,firstLabel:i.firstLabel,omitIdsFor:i.omitIdsFor,omitTypesFor:i.omitTypesFor,metadataIndent:0,omitFields:i.omitFields,onlyFields:i.onlyFields,onPrefix:p.onPrefix});Ne.lines.forEach((Fe,Ue)=>{const qe=Ue===0,Je=Ue===Ne.lines.length-1;I.push({text:qe?"- "+Fe.text:Fe.text,indentLevel:qe?Fe.indentLevel+2:Fe.indentLevel+3}),Je&&I.push({text:"",indentLevel:Fe.indentLevel+2})})}}break}case d.Loop:{I.push({text:`Error handling: ${o.catchesError?"YES (catches)":"NO (can throw)"}`,indentLevel:a});const ce=o.inputs.filter(Te=>!!Te.readsValue||!!Te.defaultValue);ce.length>0&&Bu(ce,{...i,onPrefix:p.onPrefix}).lines.forEach(Ae=>{I.push({text:Ae.text,indentLevel:Ae.indentLevel})}),lT(o,{...i,onPrefix:p.onPrefix}).lines.forEach(Te=>{I.push({text:Te.text,indentLevel:Te.indentLevel})}),I.push({text:"OUTPUT:",indentLevel:a});const ne=o.getDataType(null);if(!ne)I.push({text:"Data Type: Any (unspecified data type)",indentLevel:a+1});else{const Te=zt(ne,{...i,nested:!0,omitTopLevelType:!0,firstLabel:i.firstLabel,omitIdsFor:i.omitIdsFor,omitTypesFor:i.omitTypesFor,metadataIndent:i.metadataIndent,omitFields:i.omitFields,onlyFields:i.onlyFields,onPrefix:p.onPrefix});Te.lines.length===1?I.push({text:`Data Type: ${Te.lines[0].text}`,indentLevel:2}):Te.lines.forEach(Ae=>{I.push({text:Ae.text,indentLevel:Ae.indentLevel+1})})}const fe=o.outputs.filter(Te=>!!Te.writesValues.length);fe.length>0&&sT(fe,{label:"DESTRUCT RETURNED PROPERTIES: ",...i,onPrefix:p.onPrefix}).lines.forEach(Ae=>{I.push({text:Ae.text,indentLevel:Ae.indentLevel})}),o.body&&(I.push({text:"BODY:",indentLevel:a}),zt(o.body,{...i,nested:!0,omitTopLevelType:!1,firstLabel:i.firstLabel,omitIdsFor:i.omitIdsFor,omitTypesFor:i.omitTypesFor,metadataIndent:i.metadataIndent,omitFields:i.omitFields,onlyFields:i.onlyFields,onPrefix:p.onPrefix}).lines.forEach(Ae=>{I.push({text:Ae.text,indentLevel:Ae.indentLevel+2})}));break}case d.FunctionCall:case d.Operation:case d.InternalCall:{I.push({text:`Error handling: ${o.catchesError?"YES (catches)":"NO (can throw)"}`,indentLevel:a});const ce=o.inputs.filter(Te=>!!Te.readsValue||!!Te.defaultValue);ce.length>0&&Bu(ce,{...i,onPrefix:p.onPrefix}).lines.forEach(Ae=>{I.push({text:Ae.text,indentLevel:Ae.indentLevel})}),lT(o,{...i,onPrefix:p.onPrefix}).lines.forEach(Te=>{I.push({text:Te.text,indentLevel:Te.indentLevel})}),I.push({text:"OUTPUT:",indentLevel:a});const ne=o.getDataType(null);if(!ne)I.push({text:"Data Type: Any (unspecified data type)",indentLevel:a+1});else{const Te=zt(ne,{...i,nested:!0,omitTopLevelType:!0,firstLabel:i.firstLabel,omitIdsFor:i.omitIdsFor,omitTypesFor:i.omitTypesFor,metadataIndent:i.metadataIndent,omitFields:i.omitFields,onlyFields:i.onlyFields,onPrefix:p.onPrefix});Te.lines.length===1?I.push({text:`Data Type: ${Te.lines[0].text}`,indentLevel:2}):Te.lines.forEach(Ae=>{I.push({text:Ae.text,indentLevel:Ae.indentLevel+1})})}const fe=o.outputs.filter(Te=>!!Te.writesValues.length);fe.length>0&&sT(fe,{label:"DESTRUCT RETURNED PROPERTIES: ",...i,onPrefix:p.onPrefix}).lines.forEach(Ae=>{I.push({text:Ae.text,indentLevel:Ae.indentLevel})});break}case d.Project:{if(o.entities.length>0){I.push({text:"DEFINITIONS:",indentLevel:a});for(const re of o.entities){const ne=zt(re,{...i,nested:!0,omitTopLevelType:!1,firstLabel:i.firstLabel,omitIdsFor:i.omitIdsFor,omitTypesFor:i.omitTypesFor,metadataIndent:i.metadataIndent,omitFields:i.omitFields,onlyFields:i.onlyFields,onPrefix:p.onPrefix});ne.lines.forEach((fe,Te)=>{const Ae=Te===0,ge=Te===ne.lines.length-1;I.push({text:Ae?"- "+fe.text:fe.text,indentLevel:Ae?fe.indentLevel+2:fe.indentLevel+3}),ge&&I.push({text:"",indentLevel:fe.indentLevel+2})})}}else I.push({text:"DEFINITIONS: None",indentLevel:a}),I.push({text:"",indentLevel:a});if(o.functions.length>0){I.push({text:"FUNCTION DECLARATIONS:",indentLevel:a});for(const re of o.functions){const ne=zt(re,{...i,nested:!0,omitTopLevelType:!1,firstLabel:i.firstLabel,omitIdsFor:i.omitIdsFor,omitTypesFor:i.omitTypesFor,metadataIndent:i.metadataIndent,omitFields:i.omitFields,onlyFields:i.onlyFields,onPrefix:p.onPrefix});ne.lines.forEach((fe,Te)=>{const Ae=Te===0,ge=Te===ne.lines.length-1;I.push({text:Ae?"- "+fe.text:fe.text,indentLevel:Ae?fe.indentLevel+2:fe.indentLevel+3}),ge&&I.push({text:"",indentLevel:fe.indentLevel+2})})}}else I.push({text:"FUNCTION DECLARATIONS: None",indentLevel:a}),I.push({text:"",indentLevel:a});if(o.events.length>0){I.push({text:"GLOBAL EVENTS:",indentLevel:a});for(const re of o.events){const ne=zt(re,{...i,nested:!0,omitTopLevelType:!1,firstLabel:i.firstLabel,omitIdsFor:i.omitIdsFor,omitTypesFor:i.omitTypesFor,metadataIndent:i.metadataIndent,omitFields:i.omitFields,onlyFields:i.onlyFields,onPrefix:p.onPrefix});ne.lines.forEach((fe,Te)=>{const Ae=Te===0,ge=Te===ne.lines.length-1;I.push({text:Ae?"- "+fe.text:fe.text,indentLevel:Ae?fe.indentLevel+2:fe.indentLevel+3}),ge&&I.push({text:"",indentLevel:fe.indentLevel+2})})}}else I.push({text:"GLOBAL EVENTS: None",indentLevel:a}),I.push({text:"",indentLevel:a});if(o.variableDeclarations.length>0){I.push({text:"GLOBALLY DECLARED VARIABLES:",indentLevel:a});for(const re of o.variableDeclarations){const ne=zt(re,{...i,nested:!0,omitTopLevelType:!1,firstLabel:i.firstLabel,omitIdsFor:i.omitIdsFor,omitTypesFor:i.omitTypesFor,metadataIndent:i.metadataIndent,omitFields:i.omitFields,onlyFields:i.onlyFields,onPrefix:p.onPrefix});ne.lines.forEach((fe,Te)=>{const Ae=Te===0,ge=Te===ne.lines.length-1;I.push({text:Ae?"- "+fe.text:fe.text,indentLevel:Ae?fe.indentLevel+2:fe.indentLevel+3}),ge&&I.push({text:"",indentLevel:fe.indentLevel+2})})}}else I.push({text:"GLOBALLY DECLARED VARIABLES: None",indentLevel:a}),I.push({text:"",indentLevel:a});if(o.projects.length>0){I.push({text:"INSTALLED PROJECTS (external logic):",indentLevel:a});for(const re of o.projects){const ne=zt(re,{...i,nested:!0,omitTopLevelType:!1,firstLabel:i.firstLabel,omitIdsFor:i.omitIdsFor,omitTypesFor:i.omitTypesFor,metadataIndent:i.metadataIndent,omitFields:i.omitFields,onlyFields:i.onlyFields,onPrefix:p.onPrefix});ne.lines.forEach((fe,Te)=>{const Ae=Te===0,ge=Te===ne.lines.length-1;I.push({text:Ae?"- "+fe.text:fe.text,indentLevel:Ae?fe.indentLevel+2:fe.indentLevel+3}),ge&&I.push({text:"",indentLevel:fe.indentLevel+2})})}}const ce=[...o.variableInstances,...o.operations,...o.searches,...o.loops,...o.conditions,...o.functionCalls];if(ce.length>0){I.push({text:"OTHER GLOBAL LOGIC (will be ignored when deployed, since it isn't called by any entry-point):",indentLevel:a});for(const re of ce){const ne=zt(re,{...i,nested:!0,omitTopLevelType:!1,firstLabel:i.firstLabel,omitIdsFor:i.omitIdsFor,omitTypesFor:i.omitTypesFor,metadataIndent:i.metadataIndent,omitFields:i.omitFields,onlyFields:i.onlyFields,onPrefix:p.onPrefix});ne.lines.forEach((fe,Te)=>{const Ae=Te===0,ge=Te===ne.lines.length-1;I.push({text:Ae?"- "+fe.text:fe.text,indentLevel:Ae?fe.indentLevel+2:fe.indentLevel+3}),ge&&I.push({text:"",indentLevel:fe.indentLevel+2})})}}break}case d.InstalledProject:{if(o.functions.length>0){I.push({text:"EXPORTED FUNCTIONS:",indentLevel:a});for(const ce of o.functions){const re=zt(ce,{...i,nested:!0,omitTopLevelType:!1,firstLabel:i.firstLabel,omitIdsFor:i.omitIdsFor,omitTypesFor:i.omitTypesFor,metadataIndent:i.metadataIndent,omitFields:i.omitFields,onlyFields:i.onlyFields,onPrefix:p.onPrefix});re.lines.forEach((ne,fe)=>{const Te=fe===0,Ae=fe===re.lines.length-1;I.push({text:Te?"- "+ne.text:ne.text,indentLevel:Te?ne.indentLevel+2:ne.indentLevel+3}),Ae&&I.push({text:"",indentLevel:ne.indentLevel+2})})}}if(o.events.length>0){I.push({text:"EVENTS:",indentLevel:a});for(const ce of o.events){const re=zt(ce,{...i,nested:!0,omitTopLevelType:!1,firstLabel:i.firstLabel,omitIdsFor:i.omitIdsFor,omitTypesFor:i.omitTypesFor,metadataIndent:i.metadataIndent,omitFields:i.omitFields,onlyFields:i.onlyFields,onPrefix:p.onPrefix});re.lines.forEach((ne,fe)=>{const Te=fe===0,Ae=fe===re.lines.length-1;I.push({text:Te?"- "+ne.text:ne.text,indentLevel:Te?ne.indentLevel+2:ne.indentLevel+3}),Ae&&I.push({text:"",indentLevel:ne.indentLevel+2})})}}break}}return{lines:I}}function a1(o,p){const i={singleLine:(p==null?void 0:p.singleLine)??!1,indentSize:(p==null?void 0:p.indentSize)??2,singleLineSpacer:(p==null?void 0:p.singleLineSpacer)??" "};if(i.singleLine)return o.lines.map(a=>a.text.trim()).join(i.singleLineSpacer);const r=" ".repeat(i.indentSize);return o.lines.map(a=>r.repeat(a.indentLevel)+a.text).join(`
132
+ This is likely an incorrect strategy, either the '${this.type}' entity doesn't need to be updated or it should be deleted and a new one created in the desired parent.`})),{errors:r,explanations:a,modifiedData:i}}subscribeDependents(i){return i.forEach(r=>{this.detachedDependents[r.entity.id]||(this.detachedDependents[r.entity.id]=r)}),this}unsubscribeDependents(i){return i.forEach(r=>{this.detachedDependents[r.entity.id]&&delete this.detachedDependents[r.entity.id]}),this}syncDependents(i=this.project.addChangeSet(new q(this.project,N.sessionAuthor,B().toISOString(),this,!0,"sync-dependents"))){const r=[],a=[],c=[],e=[];return Object.values(this.detachedDependents).forEach(f=>{const h=f.entity.afterAllChildrenInitialized(i);r.push(...h.updated),a.push(...h.added),c.push(...h.removed),e.push(...h.affected)}),i==null||i.attemptAutoclose("sync-dependents",this.id),{updated:w(r),added:w(a),removed:w(c),affected:w(e),self:this}}onDetachedDependencyRemoved(i,r,a){const c=[],e=[],f=[],h=[];if(r==="declaration"){const{updated:T,added:E,removed:b}=this.remove({ignoreUpstream:!1},a);c.push(...T),e.push(...E),f.push(...b)}return{updated:w(c),added:w(e),removed:w(f),affected:w(h),self:this}}onDetachedDependencyRestored(i,r,a){const c=[],e=[],f=[],h=[];if(r==="declaration"){const{updated:T,added:E,removed:b}=this.restore({},a);c.push(...T),e.push(...E),f.push(...b)}return{updated:w(c),added:w(e),removed:w(f),affected:w(h),self:this}}unsubscribeFromDependencies(){return this.declaration.unsubscribeDependents([{entity:this,field:"declaration"}]),this}subscribeToDependencies(){return this.declaration.subscribeDependents([{entity:this,field:"declaration"}]),this}increaseVersion(i){if(i&&!B(i).isValid())throw new Error(`The shared timestamp '${i}' is not a valid ISO 8601 date string.`);return i&&B(i).isSame(B(this.createdAt))?this:(this.previousVersion=this.version,this.version=N.UUID.uuid(),this.createdAt=B(i).toISOString()||B().toISOString(),this)}captureVersion(){var r;const i=((r=this.knownVersions)==null?void 0:r.get(this.version))||new bi(this,this.project);return i.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,i):new Map([[this.version,i]]),i.inputs=[...this.inputs],i.outputs=[...this.outputs],i.error=this.error,i.successCalls=[...this.successCalls],i.errorCalls=[...this.errorCalls],i.calledBySuccess=[...this.calledBySuccess],i.calledByError=[...this.calledByError],i.calledByEntry=[...this.calledByEntry],i.declaration=this.declaration,i.parent=this.parent,this}recursiveCaptureUpstreamVersions(i){const r=[],a=[],c=[],e=[];if(this.parent){this.parent.increaseVersion(i);const f=this.parent.recursiveCaptureUpstreamVersions(i);r.push(this.parent,...f.updated),a.push(...f.added),c.push(...f.removed)}return{updated:w(r),added:w(a),removed:w(c),affected:w(e),self:this}}async restoreVersion(i){var h;const r=[],a=[],c=[],e=[];if(this.version===i)return{updated:w(r),added:w(a),removed:w(c),affected:w(e),self:this};if(!this.knownVersions){const T=new Map;for(const[E,b]of this.knownVersions||new Map){if(T.set(E,b),b.activeVersion=!1,b.knownVersions)for(const[I,P]of b.knownVersions)T.set(I,P);b.knownVersions=null}}let f=(h=this.knownVersions)==null?void 0:h.get(i);if(!f){const T=await this.APILoadVersion({},i);if(!T)throw new Error(`Version with id '${i}' for entity with id '${this.id}' not found.`);f=new bi(T,this.project)}return this.metaSync(f.toShallowJSON(),null),this.previousVersion=f.previousVersion,this.version=f.version,this.createdAt=f.createdAt,this.author=f.author,this.deleted=f.deleted,this.inputs=f.inputs,this.outputs=f.outputs,this.error=f.error,this.successCalls=f.successCalls,this.errorCalls=f.errorCalls,this.calledBySuccess=f.calledBySuccess,this.calledByError=f.calledByError,this.calledByEntry=f.calledByEntry,this.declaration=f.declaration,this.parent=f.parent,{updated:w(r),added:w(a),removed:w(c),affected:w(e),self:this}}updateWithShallowTransfer(i,r=this.project.addChangeSet(new q(this.project,N.sessionAuthor,B().toISOString(),this,!0,C.UpdateWithShallowTransfer))){if(!this.checkCanEdit(this,r))return z.Logger.warn(`[updateWithShallowTransfer] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),r==null||r.attemptAutoclose(C.UpdateWithShallowTransfer,this.id),this;if(this.metaSync(i,r),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 a=X(i.parent),c=this.project.get(a),e=this.parent;if(e&&e.id!==(c==null?void 0:c.id)&&this.removeFromParent(r),c)this.setParent(c,r),this.addSelfToProject(r);else throw r==null||r.attemptAutoclose(C.UpdateWithShallowTransfer,this.id),new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${a}' that isn't found in the project`)}else throw r==null||r.attemptAutoclose(C.UpdateWithShallowTransfer,this.id),new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(i.declaration){const a=X(i.declaration),c=this.project.get(a);c&&this.setDeclaration(c)}else throw r==null||r.attemptAutoclose(C.UpdateWithShallowTransfer,this.id),new Error(`${this.type} with id '${this.id}' must have a 'declaration'`);return i.calledByEntry.forEach(a=>{const c=X(a),e=this.project.get(c);e&&(this.addEntryCaller(e,r),e.addCall(this,r))}),[...this.calledByEntry].forEach(a=>{i.calledByEntry.find(e=>X(e)===a.id)||(this.removeCaller(a,r),a.removeCall(this,r))}),i.calledBySuccess.forEach(a=>{const c=X(a),e=this.project.get(c);e&&(this.addSuccessCaller(e,r),e.addSuccessCall(this,r))}),[...this.calledBySuccess].forEach(a=>{i.calledBySuccess.find(e=>X(e)===a.id)||(this.removeCaller(a,r),a.removeCall(this,r))}),i.calledByError.forEach(a=>{const c=X(a),e=this.project.get(c);e&&(this.addErrorCaller(e,r),e.addErrorCall(this,r))}),[...this.calledByError].forEach(a=>{i.calledByError.find(e=>X(e)===a.id)||(this.removeCaller(a,r),a.removeCall(this,r))}),i.outputs.forEach(a=>{const c=X(a),e=this.project.get(c);e&&(this.addOutput(e,r),e.setParent(this,r))}),[...this.outputs].forEach(a=>{i.outputs.find(e=>X(e)===a.id)||(this.removeOutput(a,r),a.removeFromParent(r))}),i.inputs.forEach(a=>{const c=X(a),e=this.project.get(c);e&&(this.addInput(e,r),e.setParent(this,r))}),[...this.inputs].forEach(a=>{i.inputs.find(e=>X(e)===a.id)||(this.removeInput(a,r),a.removeFromParent(r))}),i.writesValues.forEach(a=>{const c=X(a),e=this.project.get(c);e&&(this.addValueReader(e,r),e.setValueWriter(this,r))}),[...this.writesValues].forEach(a=>{i.writesValues.find(e=>X(e)===a.id)||(this.removeValueReader(a,r),a.setValueWriter(null,r))}),this.captureVersion(),this.subscribeToDependencies(),r==null||r.attemptAutoclose(C.UpdateWithShallowTransfer,this.id),this}updateWithGenerationTarget(i,r=this.project.addChangeSet(new q(this.project,N.sessionAuthor,B().toISOString(),this,!0,C.UpdateWithGenerationTarget))){var a,c,e;if(!this.checkCanEdit(this,r))return z.Logger.warn(`[updateWithGenerationTarget] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),r==null||r.attemptAutoclose(C.UpdateWithGenerationTarget,this.id),this;if(this.metaSync(i,r),i.parent){const f=X(i.parent),h=this.project.get(f),T=this.parent;if(T&&T.id!==(h==null?void 0:h.id)&&this.removeFromParent(r),h)this.setParent(h,r),this.addSelfToProject(r);else throw r==null||r.attemptAutoclose(C.UpdateWithGenerationTarget,this.id),new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${f}' that isn't found in the project`)}if(i.declaration){const f=X(i.declaration),h=this.project.get(f);h&&this.setDeclaration(h)}else throw r==null||r.attemptAutoclose(C.UpdateWithGenerationTarget,this.id),new Error(`${this.type} with id '${this.id}' must have a 'declaration'`);return(a=i.calledByEntry)==null||a.forEach(f=>{const h=X(f),T=this.project.get(h);if(T)this.addEntryCaller(T,r),T.addCall(this,r);else throw new Error(`${this.type} with id '${this.id}' has a 'calledByEntry' reference '${h}' that isn't found in the project`)}),i.calledByEntry&&[...this.calledByEntry].forEach(f=>{var T;((T=i.calledByEntry)==null?void 0:T.find(E=>X(E)===f.id))||(this.removeCaller(f,r),f.removeCall(this,r))}),(c=i.calledBySuccess)==null||c.forEach(f=>{const h=X(f),T=this.project.get(h);if(T)this.addSuccessCaller(T,r),T.addSuccessCall(this,r);else throw new Error(`${this.type} with id '${this.id}' has a 'calledBySuccess' reference '${h}' that isn't found in the project`)}),i.calledBySuccess&&[...this.calledBySuccess].forEach(f=>{var T;((T=i.calledBySuccess)==null?void 0:T.find(E=>X(E)===f.id))||(this.removeCaller(f,r),f.removeCall(this,r))}),(e=i.calledByError)==null||e.forEach(f=>{const h=X(f),T=this.project.get(h);if(T)this.addErrorCaller(T,r),T.addErrorCall(this,r);else throw new Error(`${this.type} with id '${this.id}' has a 'calledByError' reference '${h}' that isn't found in the project`)}),i.calledByError&&[...this.calledByError].forEach(f=>{var T;((T=i.calledByError)==null?void 0:T.find(E=>X(E)===f.id))||(this.removeCaller(f,r),f.removeCall(this,r))}),this.captureVersion(),this.subscribeToDependencies(),r==null||r.attemptAutoclose(C.UpdateWithGenerationTarget,this.id),this}hydrateAncestors(){const i=[],r=[],a=[],c=[];if(this.initialData.parent){const e=X(this.initialData.parent),f=this.project.get(e);if(f)this.setParent(f,null),i.push(f);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=X(this.initialData.declaration),f=this.project.get(e);if(f)this.setDeclaration(f),i.push(f);else throw new Error(`${this.type} with id '${this.id}' has a 'declaration' reference '${e}' that isn't found in the project`)}else throw new Error(`${this.type} with id '${this.id}' must have a 'declaration'`);return this.initialData.calledByEntry.forEach(e=>{const f=X(e),h=this.project.get(f);h&&this.addEntryCaller(h,null)}),this.initialData.calledBySuccess.forEach(e=>{const f=X(e),h=this.project.get(f);h&&this.addSuccessCaller(h,null)}),this.initialData.calledByError.forEach(e=>{const f=X(e),h=this.project.get(f);h&&this.addErrorCaller(h,null)}),{updated:w(i),added:w(r),removed:w(a),affected:w(c),self:this}}afterAllChildrenInitialized(i=this.project.addChangeSet(new q(this.project,N.sessionAuthor,B().toISOString(),this,!0,C.AfterAllChildrenInitialized))){if(!this.checkCanEdit(this,i))return z.Logger.warn(`[afterAllChildrenInitialized] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(C.AfterAllChildrenInitialized,this.id),{updated:[],added:[],removed:[],affected:[],self:this};const r=[],a=[],c=[],e=[];this.initialized=!0;let f=this.index||0;const h=this.parent.internalCalls.filter(U=>!U.deleted&&U.id!==this.id);h.length&&(f>h.length+1?f=h.length:f<0&&(f=0)),h.find(U=>(U.index||0)===f&&!U.deleted)&&h.filter(U=>(U.index||0)>=f&&!U.deleted).forEach(U=>{U.metaSync({index:(U.index||0)+1},i),i==null||i.add(U,W.Updated),r.push(U)}),this.metaSync({index:f},i);const{updated:E,added:b,removed:I}=this.syncInputs(i),{updated:P,added:V,removed:$}=this.syncOutputs(i);return r.push(...E,...P),a.push(...b,...V),c.push(...I,...$),this.inputs.sort((U,M)=>{var G,H;return(U.index??((G=U.declaration)==null?void 0:G.index))-(M.index??((H=M.declaration)==null?void 0:H.index))}),this.outputs.sort((U,M)=>{var G,H;return(U.index??((G=U.declaration)==null?void 0:G.index))-(M.index??((H=M.declaration)==null?void 0:H.index))}),this.captureVersion(),i==null||i.attemptAutoclose(C.AfterAllChildrenInitialized,this.id),{updated:w(r),added:w(a),removed:w(c),affected:w(e),self:this}}addSelfToProject(i=this.project.addChangeSet(new q(this.project,N.sessionAuthor,B().toISOString(),this,!0,"add-self-to-project"))){const r=[this],a=[],c=[],e=[];return this.parent.addInternalCall(this),e.push(this.parent),this.successCalls.forEach(f=>{f.addSuccessCaller(this,i),r.push(f)}),this.errorCalls.forEach(f=>{f.addErrorCaller(this,i),r.push(f)}),this.calledBySuccess.forEach(f=>{f.addSuccessCall(this,i),r.push(f)}),this.calledByError.forEach(f=>{f.addErrorCall(this,i),r.push(f)}),this.calledByEntry.forEach(f=>{f.addCall(this,i),r.push(f)}),this.subscribe(),this.subscribeToDependencies(),i==null||i.attemptAutoclose("add-self-to-project",this.id),{updated:w(r),added:w(a),removed:w(c),affected:w(e),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}removeInput(i,r=this.project.addChangeSet(new q(this.project,N.sessionAuthor,B().toISOString(),this,!0,C.RemoveInput))){if(!this.checkCanEdit(this,r))return z.Logger.warn(`[removeInput] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),r==null||r.attemptAutoclose(C.RemoveInput,this.id),this;const a=this.inputs.findIndex(c=>c.id===i.id);return a>-1&&(this.inputs.splice(a,1),r&&(r==null||r.add(this,W.Affected))),r==null||r.attemptAutoclose(C.RemoveInput,this.id),this}addInput(i,r=this.project.addChangeSet(new q(this.project,N.sessionAuthor,B().toISOString(),this,!0,C.AddInput))){return this.checkCanEdit(this,r)?this.inputs.includes(i)?(r==null||r.attemptAutoclose(C.AddInput,this.id),this):(this.inputs.push(i),r==null||r.add(this,W.Affected),r==null||r.attemptAutoclose(C.AddInput,this.id),this):(z.Logger.warn(`[addInput] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),r==null||r.attemptAutoclose(C.AddInput,this.id),this)}addOutput(i,r=this.project.addChangeSet(new q(this.project,N.sessionAuthor,B().toISOString(),this,!0,"add-output"))){return this.checkCanEdit(this,r)?this.outputs.includes(i)?(r==null||r.attemptAutoclose("add-output",this.id),this):(this.outputs.push(i),r==null||r.add(this,W.Affected),r==null||r.attemptAutoclose("add-output",this.id),this):(z.Logger.warn(`[addOutput] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),r==null||r.attemptAutoclose("add-output",this.id),this)}removeOutput(i,r=this.project.addChangeSet(new q(this.project,N.sessionAuthor,B().toISOString(),this,!0,"remove-output"))){if(!this.checkCanEdit(this,r))return z.Logger.warn(`[removeOutput] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),r==null||r.attemptAutoclose("remove-output",this.id),this;const a=this.outputs.findIndex(c=>c.id===i.id);return a>-1&&(this.outputs.splice(a,1),r&&(r==null||r.add(this,W.Affected))),r==null||r.attemptAutoclose("remove-output",this.id),this}addValueReader(i,r=this.project.addChangeSet(new q(this.project,N.sessionAuthor,B().toISOString(),this,!0,C.AddValueReader))){var e,f,h;if(!this.checkCanEditFromScopeOwnerWithSideEffects(this,C.AddValueReader,r))return this;const a=i.type===d.InputMap&&i.parent.type===d.VariableInstance&&((e=i.declaration)==null?void 0:e.type)===d.Property&&((f=i.declaration)==null?void 0:f.constant),c=i.type===d.VariableInstance&&((h=i.declaration)==null?void 0:h.constant);return(a||c)&&i?(r==null||r.event({id:`${C.SetValueWriter}-${this.id}--${this.id}`,action:C.SetValueWriter,owner:i,counterpart:this,errorReason:Di.ValueReadingOverridesConstantVariable,rootAction:!1}),r==null||r.attemptAutoclose(C.AddValueReader,this.id),this):this.writesValues.includes(i)?(r==null||r.attemptAutoclose(C.AddValueReader,this.id),this):(this.writesValues.push(i),r==null||r.add(this,W.Affected),this)}removeValueReader(i,r=this.project.addChangeSet(new q(this.project,N.sessionAuthor,B().toISOString(),this,!0,C.RemoveValueReader))){return this.checkCanEditFromScopeOwnerWithSideEffects(this,C.RemoveValueReader,r)?this.writesValues.includes(i)?(this.writesValues=this.writesValues.filter(a=>a.id!==i.id),r==null||r.add(this,W.Affected),this):(r==null||r.attemptAutoclose(C.RemoveValueReader,this.id),this):this}addSuccessCaller(i,r=this.project.addChangeSet(new q(this.project,N.sessionAuthor,B().toISOString(),this,!0,C.AddSuccessCaller)),a=!1){return this.checkCanEditWithCounterpartAndSideEffects(this,i,C.AddSuccessCaller,r)?(this.calledBySuccess.find(c=>c.id===i.id)||(this.calledBySuccess.push(i),r==null||r.add(this,W.Updated),a&&mt(this,r)),r==null||r.attemptAutoclose(C.AddSuccessCaller,this.id),this):this}addErrorCaller(i,r=this.project.addChangeSet(new q(this.project,N.sessionAuthor,B().toISOString(),this,!0,C.AddErrorCaller)),a=!1){return this.checkCanEditWithCounterpartAndSideEffects(this,i,C.AddErrorCaller,r)?(this.calledByError.find(c=>c.id===i.id)||(this.calledByError.push(i),r==null||r.add(this,W.Updated),a&&mt(this,r)),r==null||r.attemptAutoclose(C.AddErrorCaller,this.id),this):this}addEntryCaller(i,r=this.project.addChangeSet(new q(this.project,N.sessionAuthor,B().toISOString(),this,!0,C.AddEntryCaller)),a=!1){return this.checkCanEditWithCounterpartAndSideEffects(this,i,C.AddEntryCaller,r)?(this.calledByEntry.find(c=>c.id===i.id)||(this.calledByEntry.push(i),r==null||r.add(this,W.Updated),a&&mt(this,r)),r==null||r.attemptAutoclose(C.AddEntryCaller,this.id),this):this}addErrorCall(i,r=this.project.addChangeSet(new q(this.project,N.sessionAuthor,B().toISOString(),this,!0,C.AddErrorCall)),a=!1){return this.checkCanEditWithCounterpartAndSideEffects(this,i,C.AddErrorCall,r)?(this.errorCalls.find(c=>c.id===i.id)||(this.errorCalls.push(i),a&&mt(this,r),r==null||r.add(this,W.Affected)),r==null||r.attemptAutoclose(C.AddErrorCall,this.id),this):this}addSuccessCall(i,r=this.project.addChangeSet(new q(this.project,N.sessionAuthor,B().toISOString(),this,!0,C.AddSuccessCall)),a=!1){return this.checkCanEditWithCounterpartAndSideEffects(this,i,C.AddSuccessCall,r)?(this.successCalls.find(c=>c.id===i.id)||(this.successCalls.push(i),a&&mt(this,r),r==null||r.add(this,W.Affected)),r==null||r.attemptAutoclose(C.AddSuccessCall,this.id),this):this}removeCall(i,r=this.project.addChangeSet(new q(this.project,N.sessionAuthor,B().toISOString(),this,!0,C.RemoveCall)),a=!1){if(!this.checkCanEditWithCounterpartAndSideEffects(this,i,C.RemoveCall,r))return this;const c=this.successCalls.findIndex(f=>f.id===i.id);c>-1&&(this.successCalls.splice(c,1),r==null||r.add(this,W.Affected));const e=this.errorCalls.findIndex(f=>f.id===i.id);return e>-1&&(this.errorCalls.splice(e,1),r==null||r.add(this,W.Affected)),a&&mt(this,r),r==null||r.attemptAutoclose(C.RemoveCall,this.id),this}removeCaller(i,r=this.project.addChangeSet(new q(this.project,N.sessionAuthor,B().toISOString(),this,!0,"remove-caller")),a=!1){return this.checkCanEditWithCounterpartAndSideEffects(this,i,C.RemoveCaller,r)?(this.calledBySuccess=this.calledBySuccess.filter(c=>c.id!==i.id?!0:(r==null||r.add(this,W.Updated),r==null||r.add(c,W.Affected),!1)),this.calledByError=this.calledByError.filter(c=>c.id!==i.id?!0:(r==null||r.add(this,W.Updated),r==null||r.add(c,W.Affected),!1)),this.calledByEntry=this.calledByEntry.filter(c=>c.id!==i.id?!0:(r==null||r.add(this,W.Updated),r==null||r.add(c,W.Affected),!1)),a&&mt(this,r),r==null||r.attemptAutoclose(C.RemoveCaller,this.id),this):this}setError(i,r=this.project.addChangeSet(new q(this.project,N.sessionAuthor,B().toISOString(),this,!0,C.SetErrorEntity))){if(!this.checkCanEdit(this,r))return z.Logger.warn(`[setError] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),r==null||r.attemptAutoclose(C.SetErrorEntity,this.id),this;const a=this.error;return(a==null?void 0:a.id)!==(i==null?void 0:i.id)&&(a==null||a.remove({ignoreUpstream:!0},r),this.error=i,this.subscribeToDependencies(),r==null||r.add(this,W.Affected)),r==null||r.attemptAutoclose(C.SetErrorEntity,this.id),this}setParent(i,r=this.project.addChangeSet(new q(this.project,N.sessionAuthor,B().toISOString(),this,!0,C.SetParent))){var a;return this.checkCanEditWithCounterpartAndSideEffects(this,i,C.SetParent,r)?(((a=this.parent)==null?void 0:a.id)!==(i==null?void 0:i.id)&&(this.parent=i,r&&(r==null||r.add(this,W.Updated))),r==null||r.attemptAutoclose(C.SetParent,this.id),this):this}setDeclaration(i){return this.declaration=i,this}initChildren(i=this.project.addChangeSet(new q(this.project,N.sessionAuthor,B().toISOString(),this,!0,"init-children"))){if(this.initialized||this.startedInitialization)return this;if(this.startedInitialization=!0,this.initialData.parent.type!==d.GenericReference){const r=Ee(this.initialData.parent,this.project);this.setParent(r,null),this.parent.initChildren(i),this.parent.addInternalCall(this);const a=this.calledBy.find(c=>!!c.parent&&pr.includes(c.parent.type));if(a){const c=Ee(a.parent,this.project);this.parent.setParent(c,null)}else if(!a&&!this.parent.calledBy.length)throw new Error("Parent of internal call parent could not be resolved")}return this.declaration=Ee(this.initialData.declaration,this.project),this.successCalls=this.initialData.successCalls.map(r=>{const a=Ee(r,this.project);if(a.addSuccessCaller(this,null),[d.BreakStatement,d.ContinueStatement].includes(a.type))a.setParent(this.parent.parent,null),a.initChildren(i);else if(a.type===d.ReturnStatement){const c=on(this.parent,this.project);a.setParent(c,null),a.initChildren(i)}else a.type!==d.InternalCall&&(a.setParent(this.parent.parent,null),a.initChildren(i));return a}),this.errorCalls=this.initialData.errorCalls.map(r=>{const a=Ee(r,this.project);if(a.addErrorCaller(this,null),[d.BreakStatement,d.ContinueStatement].includes(a.type))a.setParent(this.parent.parent.parent,null),a.initChildren(i);else if(a.type===d.ReturnStatement){const c=on(this.parent,this.project);a.setParent(c,null),a.initChildren(i)}else a.type!==d.InternalCall&&(a.setParent(this.parent.parent,null),a.initChildren(i));return a}),this.inputs=this.initialData.inputs.map(r=>{const a=Ee(r,this.project);return a.setParent(this,null),a.initChildren(i),a}),this.outputs=this.initialData.outputs.map(r=>{let a;return r.type===d.GenericReference?a=this.project.get(r.entityId):a=Ee(r,this.project),a.setParent(this,null),a.initChildren(i),a}),this.initialData.error&&(this.error=Ee(this.initialData.error,this.project),this.error.setParent(this,null),this.error.initChildren(i)),this.subscribeToDependencies(),this.afterAllChildrenInitialized(i),i==null||i.attemptAutoclose("init-children",this.id),this}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(i,r=this.project.addChangeSet(new q(this.project,N.sessionAuthor,B().toISOString(),this,!0,"meta-sync"))){const a=kr(this,i,r),c=Ur(this,a),e=this.toMeta();return this.index=a.index||(a.index!==0?e.index:0),this.catchesError=a.catchesError!==void 0?a.catchesError:this.catchesError,super.baseMetaSync(a,this,r),a.deleted===!0&&!e.deleted?r==null||r.add(this,W.Removed):a.deleted===!1&&e.deleted?r==null||r.add(this,W.Added):c&&(r==null||r.add(this,W.Updated)),r==null||r.attemptAutoclose("meta-sync",this.id),this}async APILoad(i=je,...r){return await bi.repository.APILoad(this.id,...r),this}async APICreate(i=je,...r){return await bi.repository.APICreate(this.toShallowJSON(),...r),this}async APIUpdate(i=je,...r){return await bi.repository.APIUpdate(this.toShallowJSON(),...r),this}async APIDelete(i=je,...r){return await bi.repository.APIDelete(this.toShallowJSON(),...r),this}async APIClone(i=je,...r){return await bi.repository.APIClone(this.id,...r),this}async APILoadVersion(i=je,r,...a){return await bi.repository.APILoadVersion(this.id,r,...a)}removeFromParent(i=this.project.addChangeSet(new q(this.project,N.sessionAuthor,B().toISOString(),this,!0,C.RemoveFromParent))){if(!this.checkCanEdit(this,i))return z.Logger.warn(`[removeFromParent] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(C.RemoveFromParent,this.id),{added:[],updated:[],removed:[],affected:[],self:this};const r=[],a=[],c=[],e=[];return this.parent&&(this.parent.removeInternalCall(this,i),e.push(this.parent)),i==null||i.attemptAutoclose(C.RemoveFromParent,this.id),{added:w(c),updated:w(r),removed:w(a),affected:w(e),self:this}}remove({ignoreUpstream:i}={ignoreUpstream:!1},r=this.project.addChangeSet(new q(this.project,N.sessionAuthor,B().toISOString(),this,!0,C.RemoveEntity))){var h;if(!this.checkCanDelete(this,r))return z.Logger.warn(`[remove] User is not allowed to delete or edit this ${this.type} entity with id: ${this.id}`),r==null||r.event({id:`${C.RemoveEntity}-${this.id}`,action:C.RemoveEntity,owner:this,errorReason:Di.ActionOwnerEntityNonDeletable,rootAction:((h=r==null?void 0:r.self)==null?void 0:h.id)===this.id&&(r==null?void 0:r.autoCloseActionName)===C.RemoveEntity}),r==null||r.attemptAutoclose(C.RemoveEntity,this.id),{added:[],updated:[],removed:[],affected:[],self:this};const a=[],c=[],e=[],f=[];if(r!=null&&r.hasRemoved(this.id))return r==null||r.attemptAutoclose(C.RemoveEntity,this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(c.push(this),this.unsubscribe(),this.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},r),Object.values(this.detachedDependents).forEach(T=>{const{updated:E,removed:b,added:I}=T.entity.onDetachedDependencyRemoved(this,T.field,r);a.push(...E),c.push(...b),e.push(...I)}),this.inputs.forEach(T=>{const{updated:E,removed:b}=T.remove({ignoreUpstream:!0},r);a.push(...E),c.push(...b)}),this.outputs.forEach(T=>{const{updated:E,removed:b}=T.remove({ignoreUpstream:!0},r);a.push(...E),c.push(...b)}),this.error){const{updated:T,removed:E}=this.error.remove({ignoreUpstream:!0},r);a.push(...T),c.push(...E)}if(this.successCalls.forEach(T=>{a.push(T),T.removeCaller(this,r)}),this.errorCalls.forEach(T=>{a.push(T),T.removeCaller(this,r)}),!i){const T=this.removeFromParent(r);e.push(...T.added),a.push(...T.updated),c.push(...T.removed),f.push(...T.affected),this.calledBy.forEach(E=>{a.push(E),E.removeCall(this,r)})}return r==null||r.attemptAutoclose(C.RemoveEntity,this.id),{added:w(e),updated:w(a),removed:w(c),affected:w(f),self:this}}restore({}={},i=this.project.addChangeSet(new q(this.project,N.sessionAuthor,B().toISOString(),this,!0,C.RestoreEntity))){if(!this.checkCanEdit(this,i))return z.Logger.warn(`[restore] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(C.RestoreEntity,this.id),{added:[],updated:[],removed:[],affected:[],self:this};const r=[],a=[],c=[],e=[];return i!=null&&i.hasAdded(this.id)?(i==null||i.attemptAutoclose(C.RestoreEntity,this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},i),Object.values(this.detachedDependents).forEach(f=>{const{updated:h,removed:T,added:E}=f.entity.onDetachedDependencyRestored(this,f.field,i);a.push(...h),c.push(...T),r.push(...E)}),this.inputs.forEach(f=>{const{updated:h}=f.restore({},i);a.push(...h)}),this.outputs.forEach(f=>{const{updated:h}=f.restore({},i);a.push(...h)}),this.successCalls.forEach(f=>{a.push(f),f.addSuccessCaller(this,i)}),this.errorCalls.forEach(f=>{a.push(f),f.addErrorCaller(this,i)}),this.calledBySuccess.forEach(f=>{a.push(f),f.addSuccessCall(this,i)}),this.calledByError.forEach(f=>{a.push(f),f.addErrorCall(this,i)}),this.calledByEntry.forEach(f=>{a.push(f),f.addCall(this,i)}),i==null||i.attemptAutoclose(C.RestoreEntity,this.id),{added:w(r),updated:w(a),removed:w(c),affected:w(e),self:this})}toFlat(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this,...this.successCalls.flatMap(a=>a.toFlat(i)),...this.errorCalls.flatMap(a=>a.toFlat(i)),...this.inputs.flatMap(a=>a.toFlat(i)),...this.outputs.flatMap(a=>a.toFlat(i)),...this.calledBy.flatMap(a=>a.toFlat(i)),...this.error?this.error.toFlat(i):[],...this.parent.toFlat(i)])}toFlatIds(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.id,...this.successCalls.flatMap(a=>a.toFlatIds(i)),...this.errorCalls.flatMap(a=>a.toFlatIds(i)),...this.inputs.flatMap(a=>a.toFlatIds(i)),...this.outputs.flatMap(a=>a.toFlatIds(i)),...this.calledBy.flatMap(a=>a.toFlatIds(i)),...this.error?this.error.toFlatIds(i):[],...this.parent.toFlatIds(i)])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,catchesError:this.catchesError,author:this.author,deleted:this.deleted,index:this.index,type:this.type,editable:this.editable,deletable:this.deletable}}toJSON(i=new Set){var r;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,catchesError:this.catchesError,type:this.type,editable:this.editable,deletable:this.deletable,index:this.index,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()),writesValues:this.writesValues.map(a=>a.toJSON(i)),declaration:(()=>{var a;return this.declaration&&this.project.getBuiltIn(this.declaration.id)?this.declaration.toJSON():(a=this.declaration)==null?void 0:a.toJSON(i)})(),inputs:this.inputs.map(a=>a.toJSON(i)),outputs:this.outputs.map(a=>a.toJSON(i)),parent:this.parent.toReference(),error:(r=this.error)==null?void 0:r.toJSON(i)})}toJSONClone(i=tt){var a,c,e,f,h,T;let r;return(a=i.seenEntityMaps)!=null&&a.has(this.id)?r=i.seenEntityMaps.get(this.id):(r=i.newId||Wr(this,this.project,i.uuidStrategy),i.seenEntityMaps&&i.seenEntityMaps.set(this.id,r)),(c=i.seenEntities)!=null&&c.has(r)||(e=i.seenEntities)!=null&&e.has(this.id)?this.toReference({seenEntityMaps:i.seenEntityMaps}):((f=i.seenEntities)==null||f.add(r),(h=i.seenEntities)==null||h.add(this.id),{id:r,version:N.UUID.uuid(),createdAt:i.timestamp||B().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,catchesError:this.catchesError,type:this.type,editable:this.editable,deletable:this.deletable,index:this.index,writesValues:this.writesValues.map(E=>E.toJSONClone({...i,newId:null})),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})),declaration:(()=>{var E;return this.declaration&&this.project.getBuiltIn(this.declaration.id)?this.declaration.toJSON():(E=this.declaration)==null?void 0:E.toJSONClone({...i,newId:null})})(),inputs:this.inputs.map(E=>E.toJSONClone({...i,newId:null})),outputs:this.outputs.map(E=>E.toJSONClone({...i,newId:null})),error:(T=this.error)==null?void 0:T.toJSONClone({...i,newId:null}),parent:this.parent.calledBy.length||this.parent.readsValue?this.parent.toReference({seenEntityMaps:i.seenEntityMaps}):this.parent.toJSONClone({...i,newId:null})})}toReference(i=tt){var a;let r=this.id;return(a=i.seenEntityMaps)!=null&&a.has(this.id)&&(r=i.seenEntityMaps.get(this.id)),{id:r+"--"+N.UUID.uuid()+"--ref",type:d.GenericReference,entityId:r,version:this.version,entityType:this.type}}toShallowJSON(i=tt){var a;let r=this.id;return(a=i.seenEntityMaps)!=null&&a.has(this.id)&&(r=i.seenEntityMaps.get(this.id)),{id:r,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,catchesError:this.catchesError,type:this.type,editable:this.editable,deletable:this.deletable,index:this.index,writesValues:this.writesValues.map(c=>c.toReference(i)),inputs:this.inputs.map(c=>c.toReference(i)),outputs:this.outputs.map(c=>c.toReference(i)),declaration:this.declaration.toReference(i),successCalls:this.successCalls.map(c=>c.toReference(i)),errorCalls:this.errorCalls.map(c=>c.toReference(i)),calledBySuccess:this.calledBySuccess.map(c=>c.toReference(i)),calledByError:this.calledByError.map(c=>c.toReference(i)),calledByEntry:this.calledByEntry.map(c=>c.toReference(i)),error:this.error?this.error.toReference(i):null,parent:this.parent.toReference(i)}}toFlatJSON(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.toShallowJSON(),...this.successCalls.flatMap(a=>a.toFlatJSON(i)),...this.errorCalls.flatMap(a=>a.toFlatJSON(i)),...this.inputs.flatMap(a=>a.toFlatJSON(i)),...this.outputs.flatMap(a=>a.toFlatJSON(i)),...this.calledBy.flatMap(a=>a.toFlatJSON(i)),...this.error?this.error.toFlatJSON(i):[],...this.parent.toFlatJSON(i)])}toGenerationTarget(i=tt){var a;let r=this.id;return(a=i.seenEntityMaps)!=null&&a.has(this.id)&&(r=i.seenEntityMaps.get(this.id)),{id:r,type:this.type,calledByEntry:this.calledByEntry.map(c=>c.id),calledBySuccess:this.calledBySuccess.map(c=>c.id),calledByError:this.calledByError.map(c=>c.id),declaration:this.declaration.id,parent:this.parent.id}}toFlatGenerationTarget(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.toGenerationTarget(),...this.successCalls.flatMap(a=>a.toFlatGenerationTarget(i)),...this.errorCalls.flatMap(a=>a.toFlatGenerationTarget(i)),...this.inputs.flatMap(a=>a.toFlatGenerationTarget(i)),...this.outputs.flatMap(a=>a.toFlatGenerationTarget(i)),...this.error?this.error.toFlatGenerationTarget(i):[],...this.parent.toFlatGenerationTarget(i)])}clearErrors(){var i;return this.errors=[],this.inputs.forEach(r=>r.clearErrors()),this.outputs.forEach(r=>r.clearErrors()),this.successCalls.forEach(r=>r.clearErrors()),this.errorCalls.forEach(r=>r.clearErrors()),(i=this.error)==null||i.clearErrors(),this}validate(){return this.errors=aGe(this),{success:!0}}async validateAsync(i={}){const r=z.YieldTracker.from(i);return this.errors=await nGe(this,{tracker:r}),{success:!0}}getErrors(){return[...this.errors,...this.inputs.flatMap(r=>r.getErrors()),...this.outputs.flatMap(r=>r.getErrors()),...this.error?this.error.getErrors():[]]}async getErrorsAsync(i={}){const r=z.YieldTracker.from(i),a=[...this.errors];await r.tick();for(const c of this.inputs)a.push(...await c.getErrorsAsync({tracker:r}));for(const c of this.outputs)a.push(...await c.getErrorsAsync({tracker:r}));return this.error&&a.push(...await this.error.getErrorsAsync({tracker:r})),a}getShallowErrors(){return this.errors}clone(i=this.project.addChangeSet(new q(this.project,N.sessionAuthor,B().toISOString(),this,!0,C.CloneEntity)),r=null,a=null,c=!0){var V,$;const e=_r(r,this),f=this.toJSON(),h=a||N.UUID.uuid();f.inputs=[];const T=h.split("-id"),E=T[T.length-1||0]||h;f.id=h,f.createdAt=(i==null?void 0:i.timestamp)||B().toISOString(),f.author=(i==null?void 0:i.author)||"1",f.previousVersion=null,f.version=N.UUID.uuid(),f.deletable=!0,f.editable=!0;const b=Hi(f,e);r?b.setParent(r,i):b.setParent(this.parent,null),c&&b.subscribe(),b.initChildren(i),i==null||i.add(b,W.Added);const I=(V=this.inputs)==null?void 0:V.map((U,M)=>U.clone(i,b,E+"-input-map-"+M+"-id",c));b.inputs=I;const P=($=this.outputs)==null?void 0:$.map((U,M)=>U.clone(i,b,E+"-output-map-"+M+"-id",c));return b.outputs=P,this.error&&(b.error=this.error.clone(i,b,E+"-error-map-id",c)),i==null||i.attemptAutoclose(C.CloneEntity,this.id),b}removeUnrecognizedInputs(i=this.project.addChangeSet(new q(this.project,N.sessionAuthor,B().toISOString(),this,!0,C.RemoveUnrecognizedInputs))){if(!this.checkCanEdit(this,i))return z.Logger.warn(`[removeUnrecognizedInputs] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(C.RemoveUnrecognizedInputs,this.id),{updated:[],added:[],removed:[],affected:[],self:this};const r=[],a=[],c=[],e=[];return this.inputs.forEach(h=>{if(!this.declaration.inputs.find(E=>{var b;return E.id===((b=h.declaration)==null?void 0:b.id)})){const E=h.remove({ignoreUpstream:!1},i);c.push(...E.removed),r.push(...E.updated)}}),this.inputs.filter((h,T)=>{const E=this.inputs.findIndex(I=>I.declaration===h.declaration&&I!==h);if(E===-1)return!1;const b=this.inputs[E];return B(b==null?void 0:b.createdAt).isSame(B(h.createdAt))?T>E:!!B(b==null?void 0:b.createdAt).isAfter(h.createdAt)}).forEach(h=>{const T=h.remove({ignoreUpstream:!1},i);c.push(...T.removed),r.push(...T.updated)}),i==null||i.attemptAutoclose(C.RemoveUnrecognizedInputs,this.id),{updated:w(r),added:w(a),removed:w(c),affected:w(e),self:this}}removeUnrecognizedOutputs(i=this.project.addChangeSet(new q(this.project,N.sessionAuthor,B().toISOString(),this,!0,C.RemoveUnrecognizedOutputs))){if(!this.checkCanEdit(this,i))return z.Logger.warn(`[removeUnrecognizedOutputs] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(C.RemoveUnrecognizedOutputs,this.id),{updated:[],added:[],removed:[],affected:[],self:this};const r=[],a=[],c=[],e=[];return this.outputs.forEach(h=>{if(!this.declaration.getUniqueOutputProperties().find(E=>{var b;return E.id===((b=h.declaration)==null?void 0:b.id)})){const E=h.remove({ignoreUpstream:!1},i);c.push(...E.removed),r.push(...E.updated)}}),this.outputs.filter((h,T)=>{const E=this.outputs.findIndex(I=>I.declaration===h.declaration&&I!==h);if(E===-1)return!1;const b=this.outputs[E];return B(b==null?void 0:b.createdAt).isSame(B(h.createdAt))?T>E:!!B(b==null?void 0:b.createdAt).isAfter(h.createdAt)}).forEach(h=>{const T=h.remove({ignoreUpstream:!1},i);c.push(...T.removed),r.push(...T.updated)}),i==null||i.attemptAutoclose(C.RemoveUnrecognizedOutputs,this.id),{updated:w(r),added:w(a),removed:w(c),affected:w(e),self:this}}syncInputs(i=this.project.addChangeSet(new q(this.project,N.sessionAuthor,B().toISOString(),this,!0,C.SyncInputs))){if(!this.checkCanEdit(this,i))return z.Logger.warn(`[syncInputs] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(C.SyncInputs,this.id),{updated:[],added:[],removed:[],affected:[],self:this};const r=[],a=[],c=[],e=[],f=this.declaration.inputs.filter(b=>!this.inputs.find(I=>{var P;return((P=I.declaration)==null?void 0:P.id)===b.id}));this.inputs.sort((b,I)=>b.index-I.index),f.forEach(b=>{this.inputs.forEach(V=>{V.index>=b.index&&V.metaSync({index:V.index+1},i)});const I={id:N.UUID.uuid(),version:N.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||B().toISOString(),author:N.sessionAuthor,previousVersion:null,deleted:!1,deletable:!0,editable:!0,type:d.InputMap,dataType:null,parentRelationType:null,declaration:b.toJSON(),readsValue:null,defaultValue:null,index:b.index,name:null,codeName:null,description:null,parent:this.toReference()},P=Ee(I,this.project);P.setParent(this,i),P.initChildren(i),i==null||i.add(P,W.Added),P.addSelfToProject(i),a.push(P)}),this.inputs.sort((b,I)=>b.index-I.index);const{updated:h,added:T,removed:E}=this.removeUnrecognizedInputs(i);return r.push(...h),a.push(...T),c.push(...E),i==null||i.attemptAutoclose(C.SyncInputs,this.id),{updated:w(r),added:w(a),removed:w(c),affected:w(e),self:this}}syncOutputs(i=this.project.addChangeSet(new q(this.project,N.sessionAuthor,B().toISOString(),this,!0,C.SyncOutputs))){if(!this.checkCanEdit(this,i))return z.Logger.warn(`[syncOutputs] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(C.SyncOutputs,this.id),{updated:[],added:[],removed:[],affected:[],self:this};const r=[],a=[],c=[],e=[],f=this.getDataType(i);if(f)if(f.entity){if(f.isObject()){const b=[...f.entity.properties];b.filter(V=>zy(V)?!this.outputs.find($=>{var U;return((U=$.declaration)==null?void 0:U.id)===(V==null?void 0:V.id)}):!1).map(V=>{const $={dataType:null,id:N.UUID.uuid(),version:N.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||B().toISOString(),author:N.sessionAuthor,previousVersion:null,deleted:!1,deletable:!0,editable:!0,type:d.OutputMap,parent:this.toReference(),declaration:V==null?void 0:V.toJSON(),index:V.index,writesValues:[]},U=Ee($,this.project);return U.hydrateAncestors(),i==null||i.add(U,W.Added),U.setParent(this,i),U.initChildren(i),this.addOutput(U,i),U}),this.outputs.filter(V=>!V.declaration).forEach(V=>{const $=b.find(U=>se(U,this.project)===se(V,this.project));$&&V.setDeclaration($,i)})}}else return i==null||i.attemptAutoclose(C.SyncOutputs,this.id),{added:[],updated:[],removed:[],affected:[],self:this};else return i==null||i.attemptAutoclose(C.SyncOutputs,this.id),{added:[],updated:[],removed:[],affected:[],self:this};const{updated:h,added:T,removed:E}=this.removeUnrecognizedOutputs(i);return r.push(...h),a.push(...T),c.push(...E),this.outputs.sort((b,I)=>b.index-I.index),i==null||i.attemptAutoclose(C.SyncOutputs,this.id),{updated:w(r),added:w(a),removed:w(c),affected:w(e),self:this}}getUnusedInputs(){return this.inputs.filter(i=>i.suggestion||!i.readsValue&&!i.defaultValue)}getUnusedOutputs(){return this.outputs.filter(i=>i.suggestion||!i.writesValues.length)}getUsedInputs(){return this.inputs.filter(i=>!i.suggestion&&(i.readsValue||i.defaultValue))}getUsedOutputs(){return this.outputs.filter(i=>!i.suggestion&&i.writesValues.length)}getDataType(i=this.project.addChangeSet(new q(this.project,N.sessionAuthor,B().toISOString(),this,!0,"get-data-type"))){var r;if(this.declaration.type===d.ActionDescriptor){const a=((r=this.declaration)==null?void 0:r.getDataType(i))||null;return i==null||i.attemptAutoclose("get-data-type",this.id),a}return i==null||i.attemptAutoclose("get-data-type",this.id),null}};R(bi,"repository",{APICreate:async(i,...r)=>i,APIUpdate:async(i,...r)=>i,APIDelete:async(i,...r)=>i,APIClone:async(i,...r)=>{},APILoad:async(i,...r)=>null,APILoadVersion:async(i,r,...a)=>null}),R(bi,"type",d.InternalCall),R(bi,"USER_MANAGED_PARENT_TYPES",[...Ot]),R(bi,"PARENT_TYPES",[...bi.USER_MANAGED_PARENT_TYPES]),R(bi,"MUTABLE_BASE_PROPERTIES",["catchesError"]),R(bi,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),R(bi,"BASE_PROPERTIES",[...bi.MUTABLE_BASE_PROPERTIES,...bi.INMUTABLE_BASE_PROPERTIES]),R(bi,"MUTABLE_META_PROPERTIES",[...bi.MUTABLE_BASE_PROPERTIES,"index"]),R(bi,"INMUTABLE_META_PROPERTIES",[...bi.INMUTABLE_BASE_PROPERTIES]),R(bi,"META_PROPERTIES",[...bi.MUTABLE_META_PROPERTIES,...bi.INMUTABLE_META_PROPERTIES]),R(bi,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry"]),R(bi,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","declaration"]),R(bi,"UPSTREAM_PROPERTIES",[...bi.MUTABLE_UPSTREAM_PROPERTIES,...bi.INMUTABLE_UPSTREAM_PROPERTIES]),R(bi,"MUTABLE_DOWNSTREAM_PROPERTIES",["inputs","outputs","writesValues","successCalls","errorCalls","error"]),R(bi,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),R(bi,"DOWNSTREAM_PROPERTIES",[...bi.MUTABLE_DOWNSTREAM_PROPERTIES,...bi.INMUTABLE_DOWNSTREAM_PROPERTIES]),R(bi,"PROPERTIES",[...bi.META_PROPERTIES,...bi.UPSTREAM_PROPERTIES,...bi.DOWNSTREAM_PROPERTIES]);let op=bi;async function lGe(o,p={}){const i=z.YieldTracker.from(p),r=[...Bs(o),...dGe(o)],a=Mt(o.errors,r);return await i.tick(),a}function oGe(o){const p=[...Bs(o)];return Mt(o.errors,p)}function dGe(o){var r,a;const p=[],i=o.parent.type===d.VariableInstance&&((r=o.declaration)==null?void 0:r.type)===d.Property&&((a=o.declaration)==null?void 0:a.constant);if(i&&o.readsValue){const c=_t({id:`${o.id}--${ve.ValueReadingOverridesConstantProperty}`,message:`The '${o.type}' entity "${se(o,o.project)}" with id "${o.id}" represents a constant property whose value cannot be overriden, but reads a value.`,severity:he.Error,code:ve.ValueReadingOverridesConstantProperty,entity:o});p.push(c.error)}if(i&&o.defaultValue){const c=_t({id:`${o.id}--${ve.DefaultValueOverridesConstantProperty}`,message:`The '${o.type}' entity "${se(o,o.project)}" with id "${o.id}" represents a constant property whose value cannot be overridden, but has a 'defaultValue'.`,severity:he.Error,code:ve.DefaultValueOverridesConstantProperty,entity:o});p.push(c.error)}return p}const iDi=Object.freeze(Object.defineProperty({__proto__:null,validate:oGe,validateAsync:lGe,validateConstantValueOverride:dGe},Symbol.toStringTag,{value:"Module"}));function rDi(o,p){var i;if(o.type===d.LiteralValue){let r=(i=o.value)==null?void 0:i.toString();try{r=JSON.stringify(o.value,null,2)}catch{}return`${o.type}: ${o.id} (${se(o,p)}) = ${r}`}return`${o.type}: ${o.id} (${se(o,p)})`}function og(o,p={nested:!1,omitTopLevelType:!1,firstLabel:"name",omitIdsFor:[],omitTypesFor:[],metadataIndent:1,ownMetadataIndent:1,omitFields:[],onlyFields:[]}){var E,b,I,P,V,$,U;const i={nested:p.nested??!1,omitTopLevelType:p.omitTopLevelType??!1,firstLabel:p.firstLabel??"name",omitIdsFor:p.omitIdsFor??[],omitTypesFor:p.omitTypesFor??[],metadataIndent:p.metadataIndent??1,omitFields:p.omitFields??[],onlyFields:p.onlyFields??[]};if(!o)return{lines:[{text:"Any (unspecified data type)",indentLevel:0}]};const r=p.onPrefix?p.onPrefix(o):"";function a(M){return i.onlyFields.length>0?i.onlyFields.includes(M):i.omitFields.length>0?!i.omitFields.includes(M):!0}const c=a("id")&&!i.omitIdsFor.includes(d.DataType)?o.id:"",e=a("type")&&!i.omitTypesFor.includes(d.DataType)?o.type:"",f=c;let h=`${r}${i.omitTopLevelType?"":e?`${e}: `:""}${f}`;h=h?h+" | ":"";let T="";if(o.interactiveEntities===!1?T+=` but only definition nodes ${o.asType?"as template ":""}that don't include non-interactive built-in functionality`:o.interactiveEntities===!0&&(T+=` but only definition nodes ${o.asType?"as template ":""}that extend or implement interactive built-in functionality`),o.staticEntities===!1?T?T+=" and that aren't a single global copy instance":T+=` but only definition nodes ${o.asType?"as template ":""}that aren't a single global copy instance`:o.staticEntities===!0&&(T?T+=" and that are a single global copy instance":T+=` but only definition nodes ${o.asType?"as template ":""}that are a single global copy instance`),o.actionEntities===!1?T?T+=" excluding executable/action nodes":T+=` excluding executable/action nodes ${o.asType?"templates ":""}`:o.actionEntities===!0&&(T?T+=" and not executable/action nodes":T+=" but not executable/action nodes"),o.entity&&(T=""),o.asType&&!T&&!((E=o.andChildrenGroup)!=null&&E.length)&&!((b=o.orChildrenGroup)!=null&&b.length)&&(T=" as template"),o.foreignKeyRef){const M=o.isList,G=se(o.foreignKeyRef,o.project),H=se(o.foreignKeyRef.parent,o.project);return{lines:[{text:M?`${h}List references to "${G}" from "${H}"${T}`:`${h}Reference to "${G}" from "${H}"${T}`,indentLevel:0}]}}else{if(o.foreignKeyAllowed)return{lines:[{text:o.isList?`${h}List of foreign key references${T}`:`${h}Foreign key reference${T}`,indentLevel:0}]};if(!o.entity){const M=o.isList;if(!((I=o.andChildrenGroup)!=null&&I.length)&&!((P=o.orChildrenGroup)!=null&&P.length))return{lines:[{text:M?`${h}List of an any data type${T}`:`${h}Any data type${T}`,indentLevel:0}]};const G=[];return M&&G.push({text:`${h}List of `,indentLevel:0}),o.andChildrenGroup&&((V=o.andChildrenGroup)==null?void 0:V.length)>1&&G.push({text:(M?"":h)+"All of the following data types (union):",indentLevel:M?0:-1}),(o.andChildrenGroup||[]).forEach((H,ie)=>{const ee=ie===(o.andChildrenGroup||[]).length-1;og(H,{...i,omitTopLevelType:!0,onPrefix:p.onPrefix}).lines.forEach((de,ye)=>{const ce=ye===0,re=M?de.indentLevel+1:de.indentLevel;G.push({text:ce?"- "+de.text:de.text,indentLevel:ce?re:re+1})}),ee||G.push({text:"AND",indentLevel:0})}),o.orChildrenGroup&&(($=o.orChildrenGroup)==null?void 0:$.length)>1&&G.push({text:(M?"":h)+"One of the following data types (intersection):",indentLevel:M?0:-1}),(o.orChildrenGroup||[]).forEach((H,ie)=>{const ee=ie===(o.orChildrenGroup||[]).length-1;og(H,{...i,omitTopLevelType:!0,onPrefix:p.onPrefix}).lines.forEach((de,ye)=>{const ce=ye===0,re=M?de.indentLevel+1:de.indentLevel;G.push({text:ce?"- "+de.text:de.text,indentLevel:ce?re:re+1})}),ee||G.push({text:"OR",indentLevel:0})}),{lines:G}}}if(o.entity.type===d.PrimitiveEntity){let M=o.entity.name;switch(o.entity.name){case le.String:M="Text";break;case le.KeyValue:M="Object";break;case le.Number:M="Number";break;case le.Boolean:M="Boolean";break;case le.UUID:M="UUIDv4";break;case le.Date:M="Date (string in ISO 8601 format)";break;case le.File:M="File";break;case le.Null:M="Null value";break;case le.Untyped:M="Untyped value (explicit any)";break;case le.Void:M="Void (no returned value)";break;case le.Enum:M=`Enum (options: "${Et(o.options||[],'", "','" and "')}")`;break}return{lines:[{text:o.isList?`${h}List of ${M}s${T}`:`${h}${M.slice(0,1).toUpperCase()}${M.slice(1)}${T}`,indentLevel:0}]}}else if(o.entity.type===d.DefinitionEntity){const M=se(o.entity,o.project),G=a("id")&&!i.omitIdsFor.includes(d.DefinitionEntity)?o.entity.id:"",H=a("type")&&!i.omitTypesFor.includes(d.DefinitionEntity)?d.DefinitionEntity:"",ie=i.firstLabel==="name"?M:G,ee=i.firstLabel==="name"?G:M,pe=`${r}${i.omitTopLevelType?"":H?`${H}: `:""}${ie}${ee?` (${ee})`:""}`,de=[];if(i.nested&&((U=o.entity.parent)==null?void 0:U.id)===o.id){const ye=zt(o.entity,{...i,nested:!0,omitTopLevelType:!1,firstLabel:i.firstLabel,omitIdsFor:i.omitIdsFor,omitTypesFor:i.omitTypesFor,metadataIndent:i.metadataIndent,omitFields:i.omitFields,onlyFields:i.onlyFields,onPrefix:p.onPrefix});o.isList&&de.push({text:`${h}List of:`,indentLevel:0}),ye.lines.forEach(ce=>{de.push({text:ce.text,indentLevel:o.isList?ce.indentLevel+1:ce.indentLevel})})}else de.push({text:o.isList?`${h}List of ${pe} values${T}`:h+pe.slice(0,1).toUpperCase()+pe.slice(1)+T,indentLevel:0});return{lines:de}}else if(o.entity.type===d.BuiltInBaseEntity){const M=jx(o.entity);return{lines:[{text:o.isList?`${h}List of ${M} values${T}`:h+M.slice(0,1).toUpperCase()+M.slice(1)+T,indentLevel:0}]}}else if(o.entity.type===d.LiteralValue){if(o.entity.name===le.Null)return{lines:[{text:`${h}Null value`,indentLevel:0}]};if(o.entity.name===le.Untyped)return{lines:[{text:`${h}Untyped value`,indentLevel:0}]};if(o.entity.name===le.File)return{lines:[{text:`${h}File`,indentLevel:0}]};if(o.entity.name===le.String||o.entity.name===le.Enum)return{lines:[{text:`${h}"${o.entity.value}" text`,indentLevel:0}]};if(o.entity.name===le.Number)return{lines:[{text:`${h}Number '${o.entity.value}'`,indentLevel:0}]};if(o.entity.name===le.Boolean)return{lines:[{text:`${h}${o.entity.value} value`,indentLevel:0}]};if(o.entity.name===le.UUID)return{lines:[{text:`${h}"${o.entity.value}" UUIDv4`,indentLevel:0}]};if(o.entity.name===le.Date)return{lines:[{text:`${h}"${o.entity.value}" date`,indentLevel:0}]};if(o.entity.name===le.KeyValue)return{lines:[{text:`${h}"${o.entity.value}" object`,indentLevel:0}]};if(o.entity.name===le.Bytes)return{lines:[{text:`${h}"${o.entity.value}" bytes`,indentLevel:0}]}}return{lines:[{text:o.isList?`${h}List of ${se(o.entity,o.project)} values${T}`:`${h}${se(o.entity,o.project).slice(0,1).toUpperCase()+se(o.entity,o.project).slice(1)} value${T}`,indentLevel:0}]}}var uGe=(o=>(o.All="all",o.Callers="callers",o.ReadsValue="reads-value",o.WritesValues="writes-values",o.Declaration="declaration",o.Id="id",o.Type="type",o.Name="name",o.Description="description",o.Extends="extends",o.Implements="implements",o.CodeName="code-name",o.DataType="data-type",o))(uGe||{});function ky(o,p={nested:!1,omitTopLevelType:!1,firstLabel:"name",omitIdsFor:[],omitTypesFor:[],metadataIndent:1,ownMetadataIndent:1,omitFields:[],onlyFields:[]}){var a;if(!Vg.includes(o.type))throw new Error(`[generateValueAssignmentLogLine] Entity type ${o.type} is not an entity with value type.`);const i={nested:p.nested??!1,omitTopLevelType:p.omitTopLevelType??!1,firstLabel:p.firstLabel??"name",omitIdsFor:p.omitIdsFor??[],omitTypesFor:p.omitTypesFor??[],metadataIndent:p.metadataIndent??1,omitFields:p.omitFields??[],onlyFields:p.onlyFields??[]},r=p.prefix??"Value assignment";if(Mn.includes(o.type)&&o.readsValue){const e=o.readsValue,f=se(e,o.project);let h="";if(e.type===d.OutputMap||e.type===d.ArgumentDeclaration){const T=e.parent,E=se(T,o.project);h=`${e.type}: "${f}" (${e.id}) of ${T.type}: "${E}"`}else h=`${e.type}: "${f}" (${e.id})`;return`${r} (READING FROM) ${h}`}else if(o.defaultValue){const c=zt(o.defaultValue,{...i,nested:!0,omitTopLevelType:!1,firstLabel:i.firstLabel,omitIdsFor:i.omitIdsFor,omitTypesFor:i.omitTypesFor,metadataIndent:i.metadataIndent,omitFields:i.omitFields,onlyFields:i.onlyFields,onPrefix:p.onPrefix});return`${r} (INLINE) ${c.lines[0].text}`}else return o.type===d.ArgumentDeclaration?o.parent.parent.type===d.Loop?((a=o.parent.parent.currentIterationNumberArgumentDeclaration)==null?void 0:a.id)===o.id?`${r} INIT BY SYSTEM current loop iteration number`:`${r} INIT BY SYSTEM with aggregate value from prev loop body`:o.parent.parent.type===d.DefinitionEntity&&[...Hke(o.parent.parent)].some(e=>o.project.diggestedBuiltInBaseEntitiesIds.has(e.id))?`${r} INIT BY SYSTEM when function is invoked`:`${r} NONE`:`${r} NONE`}function pGe(o,p={nested:!1,omitTopLevelType:!1,firstLabel:"name",omitIdsFor:[],omitTypesFor:[],metadataIndent:1,ownMetadataIndent:1,omitFields:[],onlyFields:[]}){if(!Ji.includes(o.type))throw new Error(`[generateValueAssignmentLogLine] Entity type ${o.type} is not a value writing type.`);const i={nested:p.nested??!1,omitTopLevelType:p.omitTopLevelType??!1,firstLabel:p.firstLabel??"name",omitIdsFor:p.omitIdsFor??[],omitTypesFor:p.omitTypesFor??[],metadataIndent:p.metadataIndent??1,omitFields:p.omitFields??[],onlyFields:p.onlyFields??[]},r=[],a=p.prefix??"Writes values to";return o.writesValues.length?o.writesValues.forEach(c=>{const e=se(c,o.project);let f="";if(c.type===d.InputMap){const h=c.parent,T=se(h,o.project);f=`${c.type}: "${e}" (${c.id}) of ${h.type}: "${T}"`}else f=`${c.type}: "${e}" (${c.id})`;r.push({text:`${a} ${f}`,indentLevel:i.metadataIndent})}):r.push({text:`${a} NONE`,indentLevel:i.metadataIndent}),{lines:r}}function sT(o,p={nested:!1,omitTopLevelType:!1,firstLabel:"name",omitIdsFor:[],omitTypesFor:[],metadataIndent:1,ownMetadataIndent:1,omitFields:[],onlyFields:[]}){const i={nested:p.nested??!1,omitTopLevelType:p.omitTopLevelType??!1,firstLabel:p.firstLabel??"name",omitIdsFor:p.omitIdsFor??[],omitTypesFor:p.omitTypesFor??[],metadataIndent:p.metadataIndent??1,omitFields:p.omitFields??[],onlyFields:p.onlyFields??[]},r=[];if(o.length>0){r.push({text:`${p.label??"OUTPUTS:"}`,indentLevel:i.metadataIndent});for(const a of o)if(a){const c=zt(a,{...i,nested:!0,omitTopLevelType:!1,firstLabel:i.firstLabel,omitIdsFor:i.omitIdsFor,omitTypesFor:i.omitTypesFor,metadataIndent:i.metadataIndent,omitFields:i.omitFields,onlyFields:i.onlyFields,onPrefix:p.onPrefix});c.lines.forEach((e,f)=>{const h=f===0,T=f===c.lines.length-1;r.push({text:h?"- "+e.text:e.text,indentLevel:h?e.indentLevel+2:e.indentLevel+3}),T&&r.push({text:"",indentLevel:e.indentLevel+2})})}}else r.push({text:`${p.label??"OUTPUTS:"} None`,indentLevel:i.metadataIndent});return{lines:r}}function Bu(o,p={nested:!1,omitTopLevelType:!1,firstLabel:"name",omitIdsFor:[],omitTypesFor:[],metadataIndent:1,ownMetadataIndent:1,omitFields:[],onlyFields:[]}){const i={nested:p.nested??!1,omitTopLevelType:p.omitTopLevelType??!1,firstLabel:p.firstLabel??"name",omitIdsFor:p.omitIdsFor??[],omitTypesFor:p.omitTypesFor??[],metadataIndent:p.metadataIndent??1,omitFields:p.omitFields??[],onlyFields:p.onlyFields??[]},r=[];if(o.length>0){r.push({text:`${p.label??"INPUTS:"}`,indentLevel:i.metadataIndent});for(const a of o)if(a){const c=zt(a,{...i,nested:!0,omitTopLevelType:!1,firstLabel:i.firstLabel,omitIdsFor:i.omitIdsFor,omitTypesFor:i.omitTypesFor,metadataIndent:i.metadataIndent,omitFields:i.omitFields,onlyFields:i.onlyFields,onPrefix:p.onPrefix});c.lines.forEach((e,f)=>{const h=f===0,T=f===c.lines.length-1;r.push({text:h?"- "+e.text:e.text,indentLevel:h?e.indentLevel+(p.firstListItemIndent??2):e.indentLevel+(p.otherListItemIndent??3)}),T&&r.push({text:"",indentLevel:e.indentLevel+2})})}}else r.push({text:`${p.label??"INPUTS:"} None`,indentLevel:i.metadataIndent});return{lines:r}}function Mu(o,p={nested:!1,omitTopLevelType:!1,firstLabel:"name",omitIdsFor:[],omitTypesFor:[],metadataIndent:1,ownMetadataIndent:1,omitFields:[],onlyFields:[]}){const i={nested:p.nested??!1,omitTopLevelType:p.omitTopLevelType??!1,firstLabel:p.firstLabel??"name",omitIdsFor:p.omitIdsFor??[],omitTypesFor:p.omitTypesFor??[],metadataIndent:p.metadataIndent??1,omitFields:p.omitFields??[],onlyFields:p.onlyFields??[]},r=[],a=i.onlyFields.length>0&&i.onlyFields.includes("data-type")||i.omitFields.length>0&&!i.omitFields.includes("data-type")||i.onlyFields.length===0&&i.omitFields.length===0;if(!o)a&&r.push({text:"Data Type: Any (unspecified data type)",indentLevel:0});else if(a){const c=zt(o,{...i,nested:!0,omitTopLevelType:!0,firstLabel:i.firstLabel,omitIdsFor:i.omitIdsFor,omitTypesFor:i.omitTypesFor,metadataIndent:i.metadataIndent,omitFields:i.omitFields,onlyFields:i.onlyFields,onPrefix:p.onPrefix});c.lines.length===1?r.push({text:`Data Type: ${c.lines[0].text}`,indentLevel:0}):(r.push({text:"Data Type:",indentLevel:0}),c.lines.forEach(e=>{r.push({text:e.text,indentLevel:e.indentLevel+1})}))}return{lines:r}}function lT(o,p={nested:!1,omitTopLevelType:!1,firstLabel:"name",omitIdsFor:[],omitTypesFor:[],metadataIndent:1,ownMetadataIndent:1,omitFields:[],onlyFields:[]}){var a;const i={nested:p.nested??!1,omitTopLevelType:p.omitTopLevelType??!1,firstLabel:p.firstLabel??"name",omitIdsFor:p.omitIdsFor??[],omitTypesFor:p.omitTypesFor??[],metadataIndent:p.metadataIndent??1,omitFields:p.omitFields??[],onlyFields:p.onlyFields??[]},r=[];if(o.error&&(((a=o.error)==null?void 0:a.writesValues)||[]).length>0){const c="CAUGHT ERROR value read by:";r.push({text:c,indentLevel:i.metadataIndent}),o.error.writesValues.forEach(f=>{const h=se(f,o.project);let T="";if(f.type===d.InputMap){const E=f.parent,b=se(E,o.project);T=`${f.type}: "${h}" (${f.id}) of ${E.type}: "${b}"`}else T=`${f.type}: "${h}" (${f.id})`;r.push({text:T,indentLevel:i.metadataIndent+1})})}return{lines:r}}function zt(o,p={nested:!1,omitTopLevelType:!1,firstLabel:"name",omitIdsFor:[],omitTypesFor:[],metadataIndent:1,ownMetadataIndent:1,omitFields:[],onlyFields:[]}){var V,$,U,M,G,H,ie,ee,pe,de,ye;const i={nested:p.nested??!1,omitTopLevelType:p.omitTopLevelType??!1,firstLabel:p.firstLabel??"name",omitIdsFor:p.omitIdsFor??[],omitTypesFor:p.omitTypesFor??[],metadataIndent:p.metadataIndent??1,omitFields:p.omitFields??[],onlyFields:p.onlyFields??[]};function r(ce){return i.onlyFields.length>0?i.onlyFields.includes(ce):i.omitFields.length>0?!i.omitFields.includes(ce):!0}const a=p.ownMetadataIndent??p.metadataIndent??1,c=p.onPrefix?p.onPrefix(o):"";if(o.type===d.LiteralValue){let ce=(V=o.value)==null?void 0:V.toString();try{ce=JSON.stringify(o.value,null,2).replace(/\n/g,"")}catch{}if(o.valueAsTypeList&&!o.valueAsTypeSingle&&o.valueAsTypeList.length>0)ce=Et(o.valueAsTypeList.map(ge=>`${ge.type} "${se(ge,o.project)}" (${ge.id})`),", "," and ");else if(o.valueAsTypeSingle){const ge=o.valueAsTypeSingle;ce=`${ge.type} "${se(ge,o.project)}" (${ge.id})`}let re="";switch(o.name){case le.Bytes:re="Bytes";break;case le.String:re="Text";break;case le.KeyValue:re="Object";break;case le.Number:re="Number";break;case le.Boolean:re="Boolean";break;case le.UUID:re="Unique identifier UUIDv4";break;case le.Date:re="Date (string in ISO 8601 format)";break;case le.File:re="File";break;case le.Null:re="Null value (explicit empty)";break;case le.Untyped:re="Untyped value (explicit any)";break;case le.Void:re="Void (no returned value)";break;case le.Enum:re="Enum (set of text options)";break;case le.EntityTemplate:{re="Entity (as type/constructor)",o.valueAsTypeList&&!o.valueAsTypeSingle&&(re+=" list");break}default:re=se(o,o.project);break}r("name")||(re="");const ne=r("id")&&!i.omitIdsFor.includes(d.LiteralValue)?o.id:"",fe=r("type")&&!i.omitTypesFor.includes(d.LiteralValue)?o.type:"",Te=i.firstLabel==="name"?re:ne,Ae=i.firstLabel==="name"?ne:re;return{lines:[{text:`${c}${i.omitTopLevelType?"":fe?`${fe}: `:""}${Te}${Ae?` (${Ae})`:""} = ${ce}`,indentLevel:0}]}}if(o.type===d.PrimitiveEntity){const ce=r("id")&&!i.omitIdsFor.includes(d.PrimitiveEntity)?o.id:"",re=r("type")&&!i.omitTypesFor.includes(d.PrimitiveEntity)?o.type:"";let ne="";switch(o.name){case le.Bytes:ne="Bytes";break;case le.String:ne="Text";break;case le.KeyValue:ne="Object";break;case le.Number:ne="Number";break;case le.Boolean:ne="Boolean";break;case le.UUID:ne="Unique identifier UUIDv4";break;case le.Date:ne="Date (string in ISO 8601 format)";break;case le.File:ne="File";break;case le.Null:ne="Null value (explicit empty)";break;case le.Untyped:ne="Untyped value (explicit any)";break;case le.Void:ne="Void (no returned value)";break;case le.Enum:ne="Enum (set of text options)";break;case le.EntityTemplate:{ne="Entity as type/constructor";break}default:ne=se(o,o.project);break}r("name")||(ne="");const fe=i.firstLabel==="name"?ne:ce,Te=i.firstLabel==="name"?ce:ne,Ae=[{text:`${c}${i.omitTopLevelType?"":re?`${re}: `:""}${fe}${Te?` (${Te})`:""}`,indentLevel:0}],ge=(($=o.description)==null?void 0:$.replace(/[\r\n]+/g," ").trim())||"";if(ge&&r("description")&&Ae.push({text:`${ge}`,indentLevel:a}),o.extends&&r("extends")){const Ne=se(o.extends,o.project);Ae.push({text:`Extends: ${Ne}`,indentLevel:a})}return{lines:Ae}}if(o.type===d.DataType){const ce=og(o,{...i,onPrefix:p.onPrefix}),re=[];return ce.lines.forEach(ne=>{re.push({text:ne.text,indentLevel:ne.indentLevel+1})}),{lines:re}}const e=r("name")?se(o,o.project):"",f=r("id")&&!i.omitIdsFor.includes(o.type)?o.id:"",h=r("type")&&!i.omitTypesFor.includes(o.type)?o.type:"",T=i.firstLabel==="name"?e:f,E=i.firstLabel==="name"?f:e,I=[{text:`${c}${i.omitTopLevelType?"":h?`${h}: `:""}${T}${E?` (${E})`:""}`,indentLevel:0}],P=((U=o.description)==null?void 0:U.replace(/[\r\n]+/g," ").trim())||"";if(P&&r("description")&&I.push({text:`${P}`,indentLevel:a}),o.codeName&&r("code-name")&&I.push({text:`Explicit name when compiled: ${o.codeName}`,indentLevel:a}),Mn.includes(o.type)&&r("reads-value")&&!o.defaultValue&&(!Nt.includes(o.type)||!o.throws)){const ce=ky(o,{prefix:"Value assignment",...i});I.push({text:ce,indentLevel:a})}if(Ji.includes(o.type)&&r("writes-values")){let ce="Writes values to";Jt.includes(o.type)?ce="Full returned value read by":Ot.includes(o.type)&&(ce="Main (full) value written to"),pGe(o,{prefix:ce,...i}).lines.forEach(ne=>{I.push({text:ne.text,indentLevel:ne.indentLevel})})}if(o.declaration&&r("declaration")){const ce=o;let re="";ce.declaration.type!==d.VariableDeclaration&&(re=`${ce.declaration.type}: `),I.push({text:`Declaration ${re}${ce.declaration.id}`,indentLevel:a})}if(i.nested)switch(o.type){case d.Search:{if(I.push({text:`QUERY: \`${(o.query||"").replace("{{::","{{::input-map-value:")}\``,indentLevel:a}),I.push({text:`Error handling: ${o.catchesError?"YES (catches)":"NO (can throw)"}`,indentLevel:a}),o.inputsDeclarations.length>0){I.push({text:"INPUTS (inline-declared):",indentLevel:i.metadataIndent});for(const fe of o.inputsDeclarations)if(fe){const Te=zt(fe,{...i,nested:!0,omitTopLevelType:!1,firstLabel:i.firstLabel,omitIdsFor:i.omitIdsFor,omitTypesFor:i.omitTypesFor,metadataIndent:i.metadataIndent,omitFields:i.omitFields,onlyFields:i.onlyFields,onPrefix:p.onPrefix});Te.lines.forEach((Ae,ge)=>{const Ne=ge===0,Fe=ge===Te.lines.length-1;I.push({text:Ne?"- "+Ae.text:Ae.text,indentLevel:Ne?Ae.indentLevel+2:Ae.indentLevel+3}),Fe&&I.push({text:"",indentLevel:Ae.indentLevel+2})})}}else I.push({text:"INPUTS: None",indentLevel:i.metadataIndent});lT(o,{...i,onPrefix:p.onPrefix}).lines.forEach(fe=>{I.push({text:fe.text,indentLevel:fe.indentLevel})}),I.push({text:"OUTPUT:",indentLevel:a});const re=o.getDataType(null);if(!re)I.push({text:"Data Type: Any (unspecified data type)",indentLevel:a+1});else{const fe=zt(re,{...i,nested:!0,omitTopLevelType:!0,firstLabel:i.firstLabel,omitIdsFor:i.omitIdsFor,omitTypesFor:i.omitTypesFor,metadataIndent:i.metadataIndent,omitFields:i.omitFields,onlyFields:i.onlyFields,onPrefix:p.onPrefix});fe.lines.length===1?I.push({text:`Data Type: ${fe.lines[0].text}`,indentLevel:2}):fe.lines.forEach(Te=>{I.push({text:Te.text,indentLevel:Te.indentLevel+1})})}const ne=o.outputs.filter(fe=>!!fe.writesValues.length);ne.length>0&&sT(ne,{label:"DESTRUCT RETURNED PROPERTIES: ",...i,onPrefix:p.onPrefix}).lines.forEach(Te=>{I.push({text:Te.text,indentLevel:Te.indentLevel})});break}case d.Condition:{((M=o.declaration)==null?void 0:M.id)!==te.condition["condition-group-and"].id&&((G=o.declaration)==null?void 0:G.id)!==te.condition["condition-group-or"].id&&Bu(o.inputs,{...i,onPrefix:p.onPrefix}).lines.forEach(re=>{I.push({text:re.text,indentLevel:re.indentLevel})}),((H=o.declaration)==null?void 0:H.id)===te.condition["condition-group-and"].id?(I.push({text:"NESTED AND (all conditions must be true)",indentLevel:a}),(o.andChildrenGroup||[]).forEach((ce,re)=>{const ne=zt(ce,{...i,nested:!0,omitTopLevelType:!1,firstLabel:i.firstLabel,omitIdsFor:i.omitIdsFor,omitTypesFor:i.omitTypesFor,metadataIndent:i.metadataIndent,omitFields:i.omitFields,onlyFields:i.onlyFields,onPrefix:p.onPrefix}),fe=re===(o.andChildrenGroup||[]).length-1;ne.lines.forEach((Te,Ae)=>{const ge=Ae===0;I.push({text:ge?"- "+Te.text:Te.text,indentLevel:ge?Te.indentLevel+2:Te.indentLevel+3})}),fe||I.push({text:"AND",indentLevel:a+2})})):((ie=o.declaration)==null?void 0:ie.id)===te.condition["condition-group-or"].id&&(I.push({text:"NESTED OR (at least one condition must be true)",indentLevel:a}),(o.orChildrenGroup||[]).forEach((ce,re)=>{const ne=zt(ce,{...i,nested:!0,omitTopLevelType:!1,firstLabel:i.firstLabel,omitIdsFor:i.omitIdsFor,omitTypesFor:i.omitTypesFor,metadataIndent:i.metadataIndent,omitFields:i.omitFields,onlyFields:i.onlyFields,onPrefix:p.onPrefix}),fe=re===(o.orChildrenGroup||[]).length-1;ne.lines.forEach((Te,Ae)=>{const ge=Ae===0;I.push({text:ge?"- "+Te.text:Te.text,indentLevel:ge?Te.indentLevel+2:Te.indentLevel+3})}),fe||I.push({text:"OR",indentLevel:a+2})}));break}case d.ActionDescriptor:{if(Bu(o.inputs,{...i,onPrefix:p.onPrefix}).lines.forEach(fe=>{I.push({text:fe.text,indentLevel:fe.indentLevel})}),o.error&&(I.push({text:"POTENTIAL ERROR:",indentLevel:a}),zt(o.error,{...i,nested:!0,omitTopLevelType:!1,firstLabel:i.firstLabel,omitIdsFor:i.omitIdsFor,omitTypesFor:i.omitTypesFor,metadataIndent:i.metadataIndent,omitFields:i.omitFields,onlyFields:i.onlyFields,onPrefix:p.onPrefix}).lines.forEach(Te=>{I.push({text:Te.text,indentLevel:Te.indentLevel+2})})),eFe(o)===d.Loop){const fe=tFe(o);fe&&(I.push({text:"Body:",indentLevel:a}),zt(fe,{...i,nested:!0,omitTopLevelType:!1,firstLabel:i.firstLabel,omitIdsFor:i.omitIdsFor,omitTypesFor:i.omitTypesFor,metadataIndent:i.metadataIndent,omitFields:i.omitFields,onlyFields:i.onlyFields,onPrefix:p.onPrefix}).lines.forEach(Ae=>{I.push({text:Ae.text,indentLevel:Ae.indentLevel+2})}))}I.push({text:"OUTPUT:",indentLevel:a});const ne=o.getDataType(null);if(!ne)I.push({text:"Data Type: Any (unspecified data type)",indentLevel:a+1});else{const fe=zt(ne,{...i,nested:!0,omitTopLevelType:!0,firstLabel:i.firstLabel,omitIdsFor:i.omitIdsFor,omitTypesFor:i.omitTypesFor,metadataIndent:i.metadataIndent,omitFields:i.omitFields,onlyFields:i.onlyFields,onPrefix:p.onPrefix});fe.lines.length===1?I.push({text:`Data Type: ${fe.lines[0].text}`,indentLevel:2}):fe.lines.forEach(Te=>{I.push({text:Te.text,indentLevel:Te.indentLevel+1})})}break}case d.GlobalEvent:case d.FunctionDeclaration:{Bu(o.inputs,{...i,onPrefix:p.onPrefix}).lines.forEach(ne=>{I.push({text:ne.text,indentLevel:ne.indentLevel})}),I.push({text:"OUTPUT:",indentLevel:a});const re=o.getDataType(null);if(!re)I.push({text:"Data Type: Any (unspecified data type)",indentLevel:a+1});else{const ne=zt(re,{...i,nested:!0,omitTopLevelType:!0,firstLabel:i.firstLabel,omitIdsFor:i.omitIdsFor,omitTypesFor:i.omitTypesFor,metadataIndent:i.metadataIndent,omitFields:i.omitFields,onlyFields:i.onlyFields,onPrefix:p.onPrefix});ne.lines.length===1?I.push({text:`Data Type: ${ne.lines[0].text}`,indentLevel:2}):ne.lines.forEach(fe=>{I.push({text:fe.text,indentLevel:fe.indentLevel+1})})}break}case d.InputMap:{const ce=o.getDataType(null);if(Mu(ce,{...i,onPrefix:p.onPrefix}).lines.forEach(ne=>{I.push({text:ne.text,indentLevel:ne.indentLevel+1})}),o.defaultValue){const fe=`Value assignment (INLINE): ${zt(o.defaultValue,{...i,nested:!0,omitTopLevelType:!1,firstLabel:i.firstLabel,omitIdsFor:i.omitIdsFor,omitTypesFor:i.omitTypesFor,metadataIndent:i.metadataIndent,omitFields:i.omitFields,onlyFields:i.onlyFields,onPrefix:p.onPrefix}).lines[0].text}`;I.push({text:fe,indentLevel:1})}break}case d.ValueDescriptor:{const ce=o.getDataType(null);if(Mu(ce,{...i,onPrefix:p.onPrefix}).lines.forEach(ne=>{I.push({text:ne.text,indentLevel:ne.indentLevel+1})}),((ee=o.parent)==null?void 0:ee.type)===d.Search){const ne=o.parent.inputs.find(fe=>{var Te;return((Te=fe.declaration)==null?void 0:Te.id)===o.id});ne&&zt(ne,{...i,nested:!0,omitTopLevelType:!1,firstLabel:i.firstLabel,omitIdsFor:i.omitIdsFor,omitTypesFor:i.omitTypesFor,metadataIndent:i.metadataIndent,omitFields:[...i.omitFields,"declaration","data-type","name"],onlyFields:i.onlyFields,onPrefix:p.onPrefix}).lines.forEach(Te=>{I.push({text:Te.text,indentLevel:Te.indentLevel})})}else if(o.defaultValue){const fe=`Value assignment (INLINE): ${zt(o.defaultValue,{...i,nested:!0,omitTopLevelType:!1,firstLabel:i.firstLabel,omitIdsFor:i.omitIdsFor,omitTypesFor:i.omitTypesFor,metadataIndent:i.metadataIndent,omitFields:i.omitFields,onlyFields:i.onlyFields,onPrefix:p.onPrefix}).lines[0].text}`;I.push({text:fe,indentLevel:1})}break}case d.DefinitionEntity:{const ce=[];if(o.abstract&&ce.push("abstract"),o.static&&ce.push("static"),o.additionalProperties?ce.push("additional properties allowed"):ce.push("no additional properties allowed"),I.push({text:`Modifiers: ${ce.join(", ")}`,indentLevel:a}),(pe=o.implements)!=null&&pe.length&&(I.push({text:"Implements:",indentLevel:a}),o.implements.forEach(re=>{const ne=se(re,o.project),fe=i.firstLabel==="name"?ne:re.id,Te=i.firstLabel==="name"?re.id:ne,Ae=r("type")&&!i.omitTypesFor.includes(re.type)?re.type:"",ge=`${Ae?Ae+": ":""}${fe}${Te?` (${Te})`:""}`;I.push({text:`- ${ge}`,indentLevel:a+1})})),o.extends){const re=se(o.extends,o.project),ne=i.firstLabel==="name"?re:o.extends.id,fe=i.firstLabel==="name"?o.extends.id:re,Te=r("type")&&!i.omitTypesFor.includes(o.extends.type)?o.extends.type:"",Ae=`${Te?Te+": ":""}${ne}${fe?` (${fe})`:""}`;I.push({text:`Extends: ${Ae}`,indentLevel:a})}if(o.allPropertiesImplement&&(I.push({text:"ALL PROPERTIES IMPLEMENT:",indentLevel:a}),zt(o.allPropertiesImplement,{...i,nested:!0,omitTopLevelType:!1,firstLabel:i.firstLabel,omitIdsFor:i.omitIdsFor,omitTypesFor:i.omitTypesFor,metadataIndent:1,ownMetadataIndent:0,omitFields:i.omitFields,onlyFields:i.onlyFields,onPrefix:p.onPrefix}).lines.forEach(ne=>{I.push({text:ne.text,indentLevel:ne.indentLevel+1})})),o.additionalPropertiesDataType&&(I.push({text:"ADDITIONAL PROPERTIES DATA TYPE:",indentLevel:a}),zt(o.additionalPropertiesDataType,{...i,nested:!0,omitTopLevelType:!1,firstLabel:i.firstLabel,omitIdsFor:i.omitIdsFor,omitTypesFor:i.omitTypesFor,metadataIndent:1,ownMetadataIndent:0,omitFields:i.omitFields,onlyFields:i.onlyFields,onPrefix:p.onPrefix}).lines.forEach(ne=>{I.push({text:ne.text,indentLevel:ne.indentLevel+1})})),o.ownDeclaredProperties.length>0){I.push({text:"PROPERTIES:",indentLevel:a});for(const re of o.properties){const ne=zt(re,{...i,nested:!0,omitTopLevelType:!1,firstLabel:i.firstLabel,omitIdsFor:i.omitIdsFor,omitTypesFor:i.omitTypesFor,omitFields:i.omitFields,onlyFields:i.onlyFields,onPrefix:p.onPrefix});ne.lines.forEach((fe,Te)=>{const Ae=Te===0,ge=Te===ne.lines.length-1;I.push({text:Ae?"- "+fe.text:fe.text,indentLevel:Ae?fe.indentLevel+2:fe.indentLevel+3}),ge&&I.push({text:"",indentLevel:fe.indentLevel+2})})}}if(o.methods.length>0){I.push({text:"METHODS:",indentLevel:a});for(const re of o.methods){const ne=zt(re,{...i,nested:!0,omitTopLevelType:!1,firstLabel:i.firstLabel,omitIdsFor:i.omitIdsFor,omitTypesFor:i.omitTypesFor,metadataIndent:0,omitFields:i.omitFields,onlyFields:i.onlyFields,onPrefix:p.onPrefix});ne.lines.forEach((fe,Te)=>{const Ae=Te===0,ge=Te===ne.lines.length-1;I.push({text:Ae?"- "+fe.text:fe.text,indentLevel:Ae?fe.indentLevel+2:fe.indentLevel+3}),ge&&I.push({text:"",indentLevel:fe.indentLevel+2})})}}if(o.abstractMethods.length>0){I.push({text:"Abstract methods (action-descriptors):",indentLevel:1});for(const re of o.abstractMethods){const ne=zt(re,{...i,nested:!0,omitTopLevelType:!1,firstLabel:i.firstLabel,omitIdsFor:i.omitIdsFor,omitTypesFor:i.omitTypesFor,metadataIndent:0,omitFields:i.omitFields,onlyFields:i.onlyFields,onPrefix:p.onPrefix});ne.lines.forEach((fe,Te)=>{const Ae=Te===0,ge=Te===ne.lines.length-1;I.push({text:Ae?"- "+fe.text:fe.text,indentLevel:Ae?fe.indentLevel+2:fe.indentLevel+3}),ge&&I.push({text:"",indentLevel:fe.indentLevel+2})})}}break}case d.BuiltInBaseEntity:{const ce=[];if(o.abstract&&ce.push("abstract"),o.static&&ce.push("static"),o.additionalProperties?ce.push("additional properties allowed"):ce.push("no additional properties allowed"),I.push({text:`Modifiers: ${ce.join(", ")}`,indentLevel:a}),o.extends){const re=se(o.extends,o.project),ne=i.firstLabel==="name"?re:o.extends.id,fe=i.firstLabel==="name"?o.extends.id:re,Te=r("type")&&!i.omitTypesFor.includes(o.extends.type)?o.extends.type:"",Ae=`${Te?Te+": ":""}${ne}${fe?` (${fe})`:""}`;I.push({text:`Extends: ${Ae}`,indentLevel:a})}if(o.allPropertiesImplement&&(I.push({text:"ALL PROPERTIES IMPLEMENT:",indentLevel:a}),zt(o.allPropertiesImplement,{...i,nested:!0,omitTopLevelType:!1,firstLabel:i.firstLabel,omitIdsFor:i.omitIdsFor,omitTypesFor:i.omitTypesFor,metadataIndent:1,ownMetadataIndent:0,omitFields:i.omitFields,onlyFields:i.onlyFields,onPrefix:p.onPrefix}).lines.forEach(ne=>{I.push({text:ne.text,indentLevel:ne.indentLevel+1})})),o.additionalPropertiesDataType&&(I.push({text:"ADDITIONAL PROPERTIES DATA TYPE:",indentLevel:a}),zt(o.additionalPropertiesDataType,{...i,nested:!0,omitTopLevelType:!1,firstLabel:i.firstLabel,omitIdsFor:i.omitIdsFor,omitTypesFor:i.omitTypesFor,metadataIndent:1,ownMetadataIndent:0,omitFields:i.omitFields,onlyFields:i.onlyFields,onPrefix:p.onPrefix}).lines.forEach(ne=>{I.push({text:ne.text,indentLevel:ne.indentLevel+1})})),o.ownDeclaredProperties.length>0){I.push({text:"PROPERTIES:",indentLevel:a});for(const re of o.properties){const ne=zt(re,{...i,nested:!0,omitTopLevelType:!1,firstLabel:i.firstLabel,omitIdsFor:i.omitIdsFor,omitTypesFor:i.omitTypesFor,metadataIndent:0,omitFields:i.omitFields,onlyFields:i.onlyFields,onPrefix:p.onPrefix});ne.lines.forEach((fe,Te)=>{const Ae=Te===0,ge=Te===ne.lines.length-1;I.push({text:Ae?"- "+fe.text:fe.text,indentLevel:Ae?fe.indentLevel+2:fe.indentLevel+3}),ge&&I.push({text:"",indentLevel:fe.indentLevel+2})})}}if(o.abstractMethods.length>0){I.push({text:"ABSTRACT METHODS (action-descriptors):",indentLevel:a});for(const re of o.abstractMethods){const ne=zt(re,{...i,nested:!0,omitTopLevelType:!1,firstLabel:i.firstLabel,omitIdsFor:i.omitIdsFor,omitTypesFor:i.omitTypesFor,metadataIndent:0,omitFields:i.omitFields,onlyFields:i.onlyFields,onPrefix:p.onPrefix});ne.lines.forEach((fe,Te)=>{const Ae=Te===0,ge=Te===ne.lines.length-1;I.push({text:Ae?"- "+fe.text:fe.text,indentLevel:Ae?fe.indentLevel+2:fe.indentLevel+3}),ge&&I.push({text:"",indentLevel:fe.indentLevel+2})})}}break}case d.Property:{if(o.abstract||o.static||o.constant||o.private||o.required){const ce=[];o.abstract&&ce.push("abstract"),o.static&&ce.push("static"),o.constant&&ce.push("constant"),o.private&&ce.push("private"),o.required&&ce.push("required"),I.push({text:`Modifiers: ${ce.join(", ")}`,indentLevel:a})}if((de=o.implements)!=null&&de.length&&(I.push({text:"Implements:",indentLevel:a}),o.implements.forEach(ce=>{const re=se(ce,o.project),ne=i.firstLabel==="name"?re:ce.id,fe=i.firstLabel==="name"?ce.id:re,Te=r("type")&&!i.omitTypesFor.includes(ce.type)?ce.type:"",Ae=`${Te?Te+": ":""}${ne}${fe?` (${fe})`:""}`;I.push({text:`- ${Ae}`,indentLevel:a+1})})),o.extends){const ce=se(o.extends,o.project),re=se(o.extends.parent,o.project),ne=i.firstLabel==="name"?ce:o.extends.id,fe=i.firstLabel==="name"?o.extends.id:ce,Te=r("type")&&!i.omitTypesFor.includes(o.extends.type)?o.extends.type:"",Ae=`${Te?Te+": ":""}${ne}${fe?` (${fe})`:""}`;I.push({text:`Extends: ${Ae} -- from: ${re}`,indentLevel:a})}if(!o.extends){const ce=o.getDataType(null);Mu(ce,{...i,onPrefix:p.onPrefix}).lines.forEach(ne=>{I.push({text:ne.text,indentLevel:ne.indentLevel+1})})}if(o.defaultValue){const re=`Value assignment (INLINE): ${zt(o.defaultValue,{...i,nested:!0,omitTopLevelType:!1,firstLabel:i.firstLabel,omitIdsFor:i.omitIdsFor,omitTypesFor:i.omitTypesFor,metadataIndent:i.metadataIndent,omitFields:i.omitFields,onlyFields:i.onlyFields,onPrefix:p.onPrefix}).lines[0].text}`;I.push({text:re,indentLevel:a})}break}case d.ArgumentDeclaration:{if(o.required||o.constant){const ne=[];o.constant&&ne.push("constant (mandatory)"),o.required&&ne.push("required"),I.push({text:`Modifiers: ${ne.join(", ")}`,indentLevel:a})}(ye=o.implements)!=null&&ye.length&&(I.push({text:"Implements:",indentLevel:a}),o.implements.forEach(ne=>{const fe=se(ne,o.project),Te=i.firstLabel==="name"?fe:ne.id,Ae=i.firstLabel==="name"?ne.id:fe,ge=r("type")&&!i.omitTypesFor.includes(ne.type)?ne.type:"",Ne=`${ge?ge+": ":""}${Te}${Ae?` (${Ae})`:""}`;I.push({text:`- ${Ne}`,indentLevel:a+1})}));const ce=o.getDataType(null);if(Mu(ce,{...i,onPrefix:p.onPrefix}).lines.forEach(ne=>{I.push({text:ne.text,indentLevel:ne.indentLevel+1})}),o.defaultValue){const fe=`Default value (INLINE): ${zt(o.defaultValue,{...i,nested:!0,omitTopLevelType:!1,firstLabel:i.firstLabel,omitIdsFor:i.omitIdsFor,omitTypesFor:i.omitTypesFor,metadataIndent:i.metadataIndent,omitFields:i.omitFields,onlyFields:i.onlyFields,onPrefix:p.onPrefix}).lines[0].text}`;I.push({text:fe,indentLevel:a})}break}case d.OutputMap:{const ce=o.getDataType(null);Mu(ce,{...i,onPrefix:p.onPrefix}).lines.forEach(ne=>{I.push({text:ne.text,indentLevel:ne.indentLevel+1})});break}case d.ContinueStatement:case d.BreakStatement:case d.ReturnStatement:{const ce=o.getDataType(null);if(Mu(ce,{...i,onPrefix:p.onPrefix}).lines.forEach(fe=>{I.push({text:fe.text,indentLevel:fe.indentLevel+1})}),o.throws){const fe=ky(o.throws,{prefix:"THROWS ERROR:"});I.push({text:fe,indentLevel:a})}if(o.defaultValue){const Te=`Value assignment (INLINE): ${zt(o.defaultValue,{...i,nested:!0,omitTopLevelType:!1,firstLabel:i.firstLabel,omitIdsFor:i.omitIdsFor,omitTypesFor:i.omitTypesFor,metadataIndent:i.metadataIndent,omitFields:i.omitFields,onlyFields:i.onlyFields,onPrefix:p.onPrefix}).lines[0].text}`;I.push({text:Te,indentLevel:a})}const ne=o.outputs.filter(fe=>!!fe.readsValue||!!fe.defaultValue);ne.length>0&&Bu(ne,{label:"PROPERTIES ASSIGNED: ",...i,onPrefix:p.onPrefix}).lines.forEach(Te=>{I.push({text:Te.text,indentLevel:Te.indentLevel})});break}case d.VariableInstance:case d.VariableDeclaration:{I.push({text:`Error handling: ${o.catchesError?"YES (catches)":"NO (can throw)"}`,indentLevel:a});const ce=o.getDataType(null);if(Mu(ce,{...i,onPrefix:p.onPrefix}).lines.forEach(ge=>{I.push({text:ge.text,indentLevel:ge.indentLevel+1})}),o.defaultValue){const Ne=`Value assignment (INLINE): ${zt(o.defaultValue,{...i,nested:!0,omitTopLevelType:!1,firstLabel:i.firstLabel,omitIdsFor:i.omitIdsFor,omitTypesFor:i.omitTypesFor,metadataIndent:i.metadataIndent,omitFields:i.omitFields,onlyFields:i.onlyFields,onPrefix:p.onPrefix}).lines[0].text}`;I.push({text:Ne,indentLevel:a})}const ne=o.inputs.filter(ge=>!!ge.readsValue||!!ge.defaultValue);ne.length>0&&Bu(ne,{label:"PROPERTIES ASSIGNED: ",...i,onPrefix:p.onPrefix,omitFields:[...i.omitFields,"data-type"]}).lines.forEach(Ne=>{I.push({text:Ne.text,indentLevel:Ne.indentLevel})}),lT(o,{...i,onPrefix:p.onPrefix}).lines.forEach(ge=>{I.push({text:ge.text,indentLevel:ge.indentLevel})});const Te=o.outputs.filter(ge=>!!ge.writesValues.length);Te.length>0&&sT(Te,{label:"DESTRUCT PROPS READ BY OTHERS: ",...i,onPrefix:p.onPrefix,omitFields:[...i.omitFields]}).lines.forEach(Ne=>{I.push({text:Ne.text,indentLevel:Ne.indentLevel})});const Ae=o.internalCalls.filter(ge=>!!ge.calledBy.length||!!ge.successCalls.length||!!ge.errorCalls.length);if(Ae.length>0){I.push({text:"METHOD CALLS:",indentLevel:a});for(const ge of Ae){const Ne=zt(ge,{...i,nested:!0,omitTopLevelType:!1,firstLabel:i.firstLabel,omitIdsFor:i.omitIdsFor,omitTypesFor:i.omitTypesFor,metadataIndent:0,omitFields:i.omitFields,onlyFields:i.onlyFields,onPrefix:p.onPrefix});Ne.lines.forEach((Fe,Ue)=>{const qe=Ue===0,Je=Ue===Ne.lines.length-1;I.push({text:qe?"- "+Fe.text:Fe.text,indentLevel:qe?Fe.indentLevel+2:Fe.indentLevel+3}),Je&&I.push({text:"",indentLevel:Fe.indentLevel+2})})}}break}case d.Loop:{I.push({text:`Error handling: ${o.catchesError?"YES (catches)":"NO (can throw)"}`,indentLevel:a});const ce=o.inputs.filter(Te=>!!Te.readsValue||!!Te.defaultValue);ce.length>0&&Bu(ce,{...i,onPrefix:p.onPrefix}).lines.forEach(Ae=>{I.push({text:Ae.text,indentLevel:Ae.indentLevel})}),lT(o,{...i,onPrefix:p.onPrefix}).lines.forEach(Te=>{I.push({text:Te.text,indentLevel:Te.indentLevel})}),I.push({text:"OUTPUT:",indentLevel:a});const ne=o.getDataType(null);if(!ne)I.push({text:"Data Type: Any (unspecified data type)",indentLevel:a+1});else{const Te=zt(ne,{...i,nested:!0,omitTopLevelType:!0,firstLabel:i.firstLabel,omitIdsFor:i.omitIdsFor,omitTypesFor:i.omitTypesFor,metadataIndent:i.metadataIndent,omitFields:i.omitFields,onlyFields:i.onlyFields,onPrefix:p.onPrefix});Te.lines.length===1?I.push({text:`Data Type: ${Te.lines[0].text}`,indentLevel:2}):Te.lines.forEach(Ae=>{I.push({text:Ae.text,indentLevel:Ae.indentLevel+1})})}const fe=o.outputs.filter(Te=>!!Te.writesValues.length);fe.length>0&&sT(fe,{label:"DESTRUCT RETURNED PROPERTIES: ",...i,onPrefix:p.onPrefix}).lines.forEach(Ae=>{I.push({text:Ae.text,indentLevel:Ae.indentLevel})}),o.body&&(I.push({text:"BODY:",indentLevel:a}),zt(o.body,{...i,nested:!0,omitTopLevelType:!1,firstLabel:i.firstLabel,omitIdsFor:i.omitIdsFor,omitTypesFor:i.omitTypesFor,metadataIndent:i.metadataIndent,omitFields:i.omitFields,onlyFields:i.onlyFields,onPrefix:p.onPrefix}).lines.forEach(Ae=>{I.push({text:Ae.text,indentLevel:Ae.indentLevel+2})}));break}case d.FunctionCall:case d.Operation:case d.InternalCall:{I.push({text:`Error handling: ${o.catchesError?"YES (catches)":"NO (can throw)"}`,indentLevel:a});const ce=o.inputs.filter(Te=>!!Te.readsValue||!!Te.defaultValue);ce.length>0&&Bu(ce,{...i,onPrefix:p.onPrefix}).lines.forEach(Ae=>{I.push({text:Ae.text,indentLevel:Ae.indentLevel})}),lT(o,{...i,onPrefix:p.onPrefix}).lines.forEach(Te=>{I.push({text:Te.text,indentLevel:Te.indentLevel})}),I.push({text:"OUTPUT:",indentLevel:a});const ne=o.getDataType(null);if(!ne)I.push({text:"Data Type: Any (unspecified data type)",indentLevel:a+1});else{const Te=zt(ne,{...i,nested:!0,omitTopLevelType:!0,firstLabel:i.firstLabel,omitIdsFor:i.omitIdsFor,omitTypesFor:i.omitTypesFor,metadataIndent:i.metadataIndent,omitFields:i.omitFields,onlyFields:i.onlyFields,onPrefix:p.onPrefix});Te.lines.length===1?I.push({text:`Data Type: ${Te.lines[0].text}`,indentLevel:2}):Te.lines.forEach(Ae=>{I.push({text:Ae.text,indentLevel:Ae.indentLevel+1})})}const fe=o.outputs.filter(Te=>!!Te.writesValues.length);fe.length>0&&sT(fe,{label:"DESTRUCT RETURNED PROPERTIES: ",...i,onPrefix:p.onPrefix}).lines.forEach(Ae=>{I.push({text:Ae.text,indentLevel:Ae.indentLevel})});break}case d.Project:{if(o.entities.length>0){I.push({text:"DEFINITIONS:",indentLevel:a});for(const re of o.entities){const ne=zt(re,{...i,nested:!0,omitTopLevelType:!1,firstLabel:i.firstLabel,omitIdsFor:i.omitIdsFor,omitTypesFor:i.omitTypesFor,metadataIndent:i.metadataIndent,omitFields:i.omitFields,onlyFields:i.onlyFields,onPrefix:p.onPrefix});ne.lines.forEach((fe,Te)=>{const Ae=Te===0,ge=Te===ne.lines.length-1;I.push({text:Ae?"- "+fe.text:fe.text,indentLevel:Ae?fe.indentLevel+2:fe.indentLevel+3}),ge&&I.push({text:"",indentLevel:fe.indentLevel+2})})}}else I.push({text:"DEFINITIONS: None",indentLevel:a}),I.push({text:"",indentLevel:a});if(o.functions.length>0){I.push({text:"FUNCTION DECLARATIONS:",indentLevel:a});for(const re of o.functions){const ne=zt(re,{...i,nested:!0,omitTopLevelType:!1,firstLabel:i.firstLabel,omitIdsFor:i.omitIdsFor,omitTypesFor:i.omitTypesFor,metadataIndent:i.metadataIndent,omitFields:i.omitFields,onlyFields:i.onlyFields,onPrefix:p.onPrefix});ne.lines.forEach((fe,Te)=>{const Ae=Te===0,ge=Te===ne.lines.length-1;I.push({text:Ae?"- "+fe.text:fe.text,indentLevel:Ae?fe.indentLevel+2:fe.indentLevel+3}),ge&&I.push({text:"",indentLevel:fe.indentLevel+2})})}}else I.push({text:"FUNCTION DECLARATIONS: None",indentLevel:a}),I.push({text:"",indentLevel:a});if(o.events.length>0){I.push({text:"GLOBAL EVENTS:",indentLevel:a});for(const re of o.events){const ne=zt(re,{...i,nested:!0,omitTopLevelType:!1,firstLabel:i.firstLabel,omitIdsFor:i.omitIdsFor,omitTypesFor:i.omitTypesFor,metadataIndent:i.metadataIndent,omitFields:i.omitFields,onlyFields:i.onlyFields,onPrefix:p.onPrefix});ne.lines.forEach((fe,Te)=>{const Ae=Te===0,ge=Te===ne.lines.length-1;I.push({text:Ae?"- "+fe.text:fe.text,indentLevel:Ae?fe.indentLevel+2:fe.indentLevel+3}),ge&&I.push({text:"",indentLevel:fe.indentLevel+2})})}}else I.push({text:"GLOBAL EVENTS: None",indentLevel:a}),I.push({text:"",indentLevel:a});if(o.variableDeclarations.length>0){I.push({text:"GLOBALLY DECLARED VARIABLES:",indentLevel:a});for(const re of o.variableDeclarations){const ne=zt(re,{...i,nested:!0,omitTopLevelType:!1,firstLabel:i.firstLabel,omitIdsFor:i.omitIdsFor,omitTypesFor:i.omitTypesFor,metadataIndent:i.metadataIndent,omitFields:i.omitFields,onlyFields:i.onlyFields,onPrefix:p.onPrefix});ne.lines.forEach((fe,Te)=>{const Ae=Te===0,ge=Te===ne.lines.length-1;I.push({text:Ae?"- "+fe.text:fe.text,indentLevel:Ae?fe.indentLevel+2:fe.indentLevel+3}),ge&&I.push({text:"",indentLevel:fe.indentLevel+2})})}}else I.push({text:"GLOBALLY DECLARED VARIABLES: None",indentLevel:a}),I.push({text:"",indentLevel:a});if(o.projects.length>0){I.push({text:"INSTALLED PROJECTS (external logic):",indentLevel:a});for(const re of o.projects){const ne=zt(re,{...i,nested:!0,omitTopLevelType:!1,firstLabel:i.firstLabel,omitIdsFor:i.omitIdsFor,omitTypesFor:i.omitTypesFor,metadataIndent:i.metadataIndent,omitFields:i.omitFields,onlyFields:i.onlyFields,onPrefix:p.onPrefix});ne.lines.forEach((fe,Te)=>{const Ae=Te===0,ge=Te===ne.lines.length-1;I.push({text:Ae?"- "+fe.text:fe.text,indentLevel:Ae?fe.indentLevel+2:fe.indentLevel+3}),ge&&I.push({text:"",indentLevel:fe.indentLevel+2})})}}const ce=[...o.variableInstances,...o.operations,...o.searches,...o.loops,...o.conditions,...o.functionCalls];if(ce.length>0){I.push({text:"OTHER GLOBAL LOGIC (will be ignored when deployed, since it isn't called by any entry-point):",indentLevel:a});for(const re of ce){const ne=zt(re,{...i,nested:!0,omitTopLevelType:!1,firstLabel:i.firstLabel,omitIdsFor:i.omitIdsFor,omitTypesFor:i.omitTypesFor,metadataIndent:i.metadataIndent,omitFields:i.omitFields,onlyFields:i.onlyFields,onPrefix:p.onPrefix});ne.lines.forEach((fe,Te)=>{const Ae=Te===0,ge=Te===ne.lines.length-1;I.push({text:Ae?"- "+fe.text:fe.text,indentLevel:Ae?fe.indentLevel+2:fe.indentLevel+3}),ge&&I.push({text:"",indentLevel:fe.indentLevel+2})})}}break}case d.InstalledProject:{if(o.functions.length>0){I.push({text:"EXPORTED FUNCTIONS:",indentLevel:a});for(const ce of o.functions){const re=zt(ce,{...i,nested:!0,omitTopLevelType:!1,firstLabel:i.firstLabel,omitIdsFor:i.omitIdsFor,omitTypesFor:i.omitTypesFor,metadataIndent:i.metadataIndent,omitFields:i.omitFields,onlyFields:i.onlyFields,onPrefix:p.onPrefix});re.lines.forEach((ne,fe)=>{const Te=fe===0,Ae=fe===re.lines.length-1;I.push({text:Te?"- "+ne.text:ne.text,indentLevel:Te?ne.indentLevel+2:ne.indentLevel+3}),Ae&&I.push({text:"",indentLevel:ne.indentLevel+2})})}}if(o.events.length>0){I.push({text:"EVENTS:",indentLevel:a});for(const ce of o.events){const re=zt(ce,{...i,nested:!0,omitTopLevelType:!1,firstLabel:i.firstLabel,omitIdsFor:i.omitIdsFor,omitTypesFor:i.omitTypesFor,metadataIndent:i.metadataIndent,omitFields:i.omitFields,onlyFields:i.onlyFields,onPrefix:p.onPrefix});re.lines.forEach((ne,fe)=>{const Te=fe===0,Ae=fe===re.lines.length-1;I.push({text:Te?"- "+ne.text:ne.text,indentLevel:Te?ne.indentLevel+2:ne.indentLevel+3}),Ae&&I.push({text:"",indentLevel:ne.indentLevel+2})})}}break}}return{lines:I}}function a1(o,p){const i={singleLine:(p==null?void 0:p.singleLine)??!1,indentSize:(p==null?void 0:p.indentSize)??2,singleLineSpacer:(p==null?void 0:p.singleLineSpacer)??" "};if(i.singleLine)return o.lines.map(a=>a.text.trim()).join(i.singleLineSpacer);const r=" ".repeat(i.indentSize);return o.lines.map(a=>r.repeat(a.indentLevel)+a.text).join(`
133
133
  `)}function nDi(o,p={nested:!1,omitTopLevelType:!1,firstLabel:"name",omitIdsFor:[],omitTypesFor:[],omitFields:[],onlyFields:[]},i={}){const r={nested:p.nested??!1,omitTopLevelType:p.omitTopLevelType??!1,firstLabel:p.firstLabel??"name",omitIdsFor:p.omitIdsFor??[],omitTypesFor:p.omitTypesFor??[],omitFields:p.omitFields??[],onlyFields:p.onlyFields??[]},a=i.newLinesBetweenItems??3;return o.map(c=>{const e=zt(c,{...r,nested:r.nested,omitTopLevelType:r.omitTopLevelType,firstLabel:r.firstLabel,omitIdsFor:r.omitIdsFor,omitTypesFor:r.omitTypesFor,omitFields:r.omitFields,onlyFields:r.onlyFields,onPrefix:p.onPrefix});return a1(e,i)}).join(`
134
134
  `.repeat(a))}var cGe=(o=>(o.Declaration="declaration",o.DataTypeEntity="data-type-entity",o))(cGe||{});const Ai=class Ai extends zr{constructor(i,r){super(i);R(this,"initialData");R(this,"id");R(this,"index");R(this,"name",null);R(this,"codeName",null);R(this,"description",null);R(this,"parentRelationType",null);R(this,"type",d.InputMap);R(this,"defaultValue",null);R(this,"readsValue",null);R(this,"dataType",null);R(this,"declaration",null);R(this,"project");R(this,"errors",[]);R(this,"parent");R(this,"detachedDependents",{});R(this,"knownVersions",null);R(this,"activeVersion",!1);R(this,"initialized",!1);R(this,"startedInitialization",!1);R(this,"suggestion",!1);R(this,"_codeNativeValueValidation",null);this.initialData=i,this.project=r,this.id=i.id,this.index=i.index,this.name=i.name||null,this.codeName=i.codeName||null,this.description=i.description||null,this.parentRelationType=i.parentRelationType||null}static new(i=null){return{id:N.UUID.uuid(),version:N.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||B().toISOString(),author:(i==null?void 0:i.author)||N.sessionAuthor,previousVersion:null,deleted:!1,deletable:!0,editable:!0,type:d.InputMap,parentRelationType:null,dataType:null,name:"",codeName:null,description:"",declaration:null,index:0,readsValue:null,defaultValue:null,parent:null}}static fromGenerationTarget(i,r){const a=X(i.parent),c=r.get(a);let e=null;if(i.declaration){const E=X(i.declaration);e=r.get(E)}let f=null;if(i.readsValue){const E=X(i.readsValue);f=r.get(E)}const h={id:i.id,version:N.UUID.uuid(),createdAt:B().toISOString(),author:N.sessionAuthor,previousVersion:null,deleted:!1,name:i.name||null,deletable:!0,editable:!0,type:d.InputMap,parentRelationType:null,index:(c.inputs||[]).length,codeName:i.codeName||null,description:i.description||null,declaration:e,readsValue:f,dataType:null,defaultValue:null,parent:c},T=Ee(h,r);return T.setParent(c,null),T}static validateGenerationTarget(i,r){var I;let a=JSON.parse(JSON.stringify(i));const c=[],e=[],f=wn(a,{parent:{list:!1,types:[...Jt,...Nt]}},r);c.push(...f.explanations),a=f.modifiedData;const h=r.get(a.parent),T=a.declaration&&(r.get(a.declaration)||r.getBuiltIn(a.declaration)),E=((h==null?void 0:h.inputs)||[]).find(P=>{var V;return a.declaration&&((V=P.declaration)==null?void 0:V.id)===a.declaration});if(a.declaration?T?[d.Property,d.ArgumentDeclaration,d.ValueDescriptor].includes(T.type)?h&&T.type===d.ArgumentDeclaration&&![d.FunctionCall,d.Search,d.InternalCall].includes(h.type)?e.push(new _e({id:`${a.id}--${ue.InvalidInputMapDeclaration}`,code:ue.InvalidInputMapDeclaration,severity:he.Error,message:`Entity of type '${d.InputMap}' with id '${a.id}' has a 'declaration' property pointing to an entity with type '${d.ArgumentDeclaration}' with id '${a.declaration}'.
135
135
  The parent entity of type '${h.type}' with id '${h.id}' is not compatible with this type of declaration.
package/dist/index.js CHANGED
@@ -160008,10 +160008,6 @@ function Jt(o, p = {
160008
160008
  case d.FunctionDeclaration: {
160009
160009
  sc(o.inputs, {
160010
160010
  ...i,
160011
- firstListItemIndent: 2,
160012
- // For function declarations, we want a bit more indentation
160013
- // This is on purpose
160014
- otherListItemIndent: 4,
160015
160011
  onPrefix: p.onPrefix
160016
160012
  }).lines.forEach((re) => {
160017
160013
  g.push({
@@ -160219,8 +160215,6 @@ function Jt(o, p = {
160219
160215
  firstLabel: i.firstLabel,
160220
160216
  omitIdsFor: i.omitIdsFor,
160221
160217
  omitTypesFor: i.omitTypesFor,
160222
- metadataIndent: 1,
160223
- ownMetadataIndent: 0,
160224
160218
  omitFields: i.omitFields,
160225
160219
  onlyFields: i.onlyFields,
160226
160220
  onPrefix: p.onPrefix
@@ -160229,11 +160223,7 @@ function Jt(o, p = {
160229
160223
  const Ae = Te === 0, Ie = Te === re.lines.length - 1;
160230
160224
  g.push({
160231
160225
  text: Ae ? "- " + fe.text : fe.text,
160232
- indentLevel: Ae ? fe.indentLevel + 2 : (
160233
- // With properties we add an extra indentation level
160234
- // This is on purpose
160235
- fe.indentLevel + 4
160236
- )
160226
+ indentLevel: Ae ? fe.indentLevel + 2 : fe.indentLevel + 3
160237
160227
  }), Ie && g.push({
160238
160228
  text: "",
160239
160229
  indentLevel: fe.indentLevel + 2
@@ -160464,7 +160454,7 @@ function Jt(o, p = {
160464
160454
  }).lines.forEach((re) => {
160465
160455
  g.push({
160466
160456
  text: re.text,
160467
- indentLevel: re.indentLevel
160457
+ indentLevel: re.indentLevel + 1
160468
160458
  });
160469
160459
  });
160470
160460
  }
@@ -160513,7 +160503,7 @@ function Jt(o, p = {
160513
160503
  }).lines.forEach((re) => {
160514
160504
  g.push({
160515
160505
  text: re.text,
160516
- indentLevel: re.indentLevel
160506
+ indentLevel: re.indentLevel + 1
160517
160507
  });
160518
160508
  }), o.defaultValue) {
160519
160509
  const fe = `Default value (INLINE): ${Jt(o.defaultValue, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elyx-code/project-logic-tree",
3
- "version": "0.0.6798",
3
+ "version": "0.0.6800",
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",