@elyx-code/project-logic-tree 0.0.6855 → 0.0.6856

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
@@ -3,7 +3,7 @@ Please provide a unique 'name' string.`,severity:Te.Error,code:we.NameNotUniqueI
3
3
  Please provide a unique 'name' string.`,severity:Te.Error,code:we.NameNotUniqueInScope}))}return i}function lx(l,p){const i=[];l.name||i.push(new Re({id:`${l.id}--${we.EmptyName}`,message:`Entity with id "${l.id}" and type "${l.type}" has an empty name. Please provide a 'name' string.`,severity:Te.Error,code:we.EmptyName}));const r=l.parent&&ca(l.parent,p)||p;if(!r)i.push(new Re({id:`${l.id}--parent-reference--${fe.ReferencedEntityNotFound}`,message:`The entity with id '${l.parent}' that isn't yet found in the project. Perhaps it should be created first. Or perhaps the ID is incorrect.`,severity:Te.Error,code:fe.ReferencedEntityNotFound}));else{const c=rx(r).filter(e=>e.name===l.name);c.length&&i.push(new Re({id:`${l.id}--${we.NameNotUniqueInScope}`,message:`Entity with id "${l.id}" and type "${l.type}" has a name "${l.name}" that is not unique in its scope or higher scopes. Entity with id "${c[0].id}" has the same name.
4
4
  Please provide a unique 'name' string.`,severity:Te.Error,code:we.NameNotUniqueInScope}))}return i}function ox(l,p){const i=[];l.name||i.push(new Re({id:`${l.id}--${we.EmptyName}`,message:`Entity with id "${l.id}" and type "${l.type}" has an empty name. Please provide a 'name' string.`,severity:Te.Error,code:we.EmptyName}));const r=X(l.parent);if(!r)i.push(new Re({id:`${l.id}--parent-reference--${fe.InvalidReferenceObjectStructure}`,message:`Reference object at 'parent' property for entity with id "${l.id}" and type "${l.type}" is not a valid reference. A reference needs to be a 'id' string of an existing entity in the project.`,severity:Te.Error,code:fe.InvalidReferenceObjectStructure}));else{const a=p.get(r);if(!a)i.push(new Re({id:`${l.id}--parent-reference--${fe.ReferencedEntityNotFound}`,message:`The entity with id '${r}' that isn't yet found in the project. Perhaps it should be created first. Or perhaps the ID is incorrect.`,severity:Te.Error,code:fe.ReferencedEntityNotFound}));else{const e=a.properties.filter(f=>f.name===l.name);e.length&&i.push(new Re({id:`${l.id}--${we.NameNotUniqueInScope}`,message:`Entity with id "${l.id}" and type "${l.type}" has a name "${l.name}" that is not unique among all properties in the parent entity. Entity with id "${e[0].id}" has the same name.
5
5
  Please provide a unique 'name' string.`,severity:Te.Error,code:we.NameNotUniqueInScope}))}}return i}function dx(l,p){const i=[];l.name||i.push(new Re({id:`${l.id}--${we.EmptyName}`,message:`Entity with id "${l.id}" and type "${l.type}" has an empty name. Please provide a 'name' string.`,severity:Te.Error,code:we.EmptyName}));const r=X(l.parent);if(!r)i.push(new Re({id:`${l.id}--parent-reference--${fe.InvalidReferenceObjectStructure}`,message:`Reference object at 'parent' property for entity with id "${l.id}" and type "${l.type}" is not a valid reference. A reference needs to be a 'id' string of an existing entity in the project.`,severity:Te.Error,code:fe.InvalidReferenceObjectStructure}));else{const a=p.get(r);if(!a)i.push(new Re({id:`${l.id}--parent-reference--${fe.ReferencedEntityNotFound}`,message:`The entity with id '${r}' that isn't yet found in the project. Perhaps it should be created first. Or perhaps the ID is incorrect.`,severity:Te.Error,code:fe.ReferencedEntityNotFound}));else{const e=rL(a).filter(f=>f.name===l.name);e.length&&i.push(new Re({id:`${l.id}--${we.NameNotUniqueInScope}`,message:`Entity with id "${l.id}" and type "${l.type}" has a name "${l.name}" that is not unique among all inputs declared in the parent entity. Entity with id "${e[0].id}" has the same name.
6
- Please provide a unique 'name' string.`,severity:Te.Error,code:we.NameNotUniqueInScope}))}}return i}function vbi(l,p){switch(l.type){case d.DefinitionEntity:return ax(l,p);case d.FunctionDeclaration:return sx(l,p);case d.VariableDeclaration:return lx(l,p);case d.Property:return ox(l,p);case d.ArgumentDeclaration:return dx(l,p);default:return[]}}function nf(l,p){var r;const i=l;switch(l.type){case d.FunctionCall:case d.InternalCall:return ca(l.declaration,p).codeName;case d.ActionDescriptor:case d.DefinitionEntity:case d.VariableDeclaration:case d.ValueDescriptor:case d.FunctionDeclaration:return l.codeName||null;case d.Property:case d.ArgumentDeclaration:{if(l.codeName)return l.codeName;if((r=l.implements)!=null&&r.length){const a=l.implements.find(c=>{const e=ca(c,p);return!!(e!=null&&e.codeName)});if(a)return ca(a,p).codeName||null}break}case d.InputMap:case d.OutputMap:case d.VariableInstance:{if(l.declaration){const a=ca(l.declaration,p);return nf(a,p)||""}break}}return i.codeName||null}function uh(l,p){let i=l;if(!!p.some(a=>a.name===i)){const a=l.split(" "),c=a.pop()||"",e=parseInt(c);return!isNaN(e)?a.push(`${e+1}`):(a.push(c),a.push("1")),i=a.join(" "),uh(i,p)}return i}function POe(l,p,i){const a=`${pg(l)}-${p}-id`;return i.instances[a]?N.UUID.uuid():a}function o_(l,p){let i="",r=null;if(l.parent){const c=p.get(l.parent);c&&(r=c)}let a="";return r&&(a=`${pg(se(r,p))}-`),i=`${a}${pg(se(l,p))}-id`,p.instances[i]?N.UUID.uuid():i}function en(l,p,i="uuid"){return i==="semantic"?POe(se(l,p),l.type,p):N.UUID.uuid()}const Ebi=/^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;function ux(l){return typeof l=="string"&&Ebi.test(l)}const bbi=/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;function d_(l){return typeof l=="string"&&bbi.test(l)}function Abi(l){return l instanceof Error&&l.name==="ZodError"&&"issues"in l&&Array.isArray(l.issues)}var gbi=class extends Error{constructor(p,i){super(p,i);R(this,"name");R(this,"details");this.name="ZodValidationError",this.details=Ibi(i)}toString(){return this.message}};function Ibi(l){if(l){const p=l.cause;if(Abi(p))return p.issues}return[]}function Rbi(l){return l.length!==0}function EU(l){return l.description??""}var Dbi=/[$_\p{ID_Start}][$\u200c\u200d\p{ID_Continue}]*/u;function wbi(l){if(l.length===1){let p=l[0];return typeof p=="symbol"&&(p=EU(p)),p.toString()||'""'}return l.reduce((p,i)=>{if(typeof i=="number")return p+"["+i.toString()+"]";if(typeof i=="symbol"&&(i=EU(i)),i.includes('"'))return p+'["'+Cbi(i)+'"]';if(!Dbi.test(i))return p+'["'+i+'"]';const r=p.length===0?"":".";return p+r+i},"")}function Cbi(l){return l.replace(/"/g,'\\"')}var Obi="; ",_bi=99,NOe="Validation error",Vbi=": ",Pbi=", or ";function Nbi(l={}){const{issueSeparator:p=Obi,unionSeparator:i=Pbi,prefixSeparator:r=Vbi,prefix:a=NOe,includePath:c=!0,maxIssuesInMessage:e=_bi}=l;return f=>{const h=f.slice(0,e).map(m=>kA({issue:m,issueSeparator:p,unionSeparator:i,includePath:c})).join(p);return xbi(h,a,r)}}function kA(l){const{issue:p,issueSeparator:i,unionSeparator:r,includePath:a}=l;if(p.code===lt.invalid_union)return p.unionErrors.reduce((c,e)=>{const f=e.issues.map(h=>kA({issue:h,issueSeparator:i,unionSeparator:r,includePath:a})).join(i);return c.includes(f)||c.push(f),c},[]).join(r);if(p.code===lt.invalid_arguments)return[p.message,...p.argumentsError.issues.map(c=>kA({issue:c,issueSeparator:i,unionSeparator:r,includePath:a}))].join(i);if(p.code===lt.invalid_return_type)return[p.message,...p.returnTypeError.issues.map(c=>kA({issue:c,issueSeparator:i,unionSeparator:r,includePath:a}))].join(i);if(a&&Rbi(p.path)){if(p.path.length===1){const c=p.path[0];if(typeof c=="number")return`${p.message} at index ${c}`}return`${p.message} at "${wbi(p.path)}"`}return p.message}function xbi(l,p,i){return p!==null?l.length>0?[p,l].join(i):p:l.length>0?l:NOe}function $bi(l,p={}){const r=Lbi(p)([l]);return new gbi(r,{cause:new Qo([l])})}function Lbi(l){return"messageBuilder"in l?l.messageBuilder:Nbi(l)}async function xOe(l,p={}){var c;const i=z.YieldTracker.from(p),r=[...ys(l)];await i.tick();const a=kt(l.errors,r);return await((c=l.dataType)==null?void 0:c.validateAsync({tracker:i})),a}function $Oe(l){var i;(i=l.dataType)==null||i.validate();const p=[...ys(l)];return kt(l.errors,p)}const Bbi=Object.freeze(Object.defineProperty({__proto__:null,validate:$Oe,validateAsync:xOe},Symbol.toStringTag,{value:"Module"}));function LOe(l){return l.listAdded.forEach(p=>{const i=l.project.get(p.id);(i==null?void 0:i.type)===d.DefinitionEntity&&i.parent.type!==d.DataType&&(l.project.emit(ni.EXPLICIT_DEFINITION_ENTITY_ADDED,i,l),ai(i,Ie.PERSISTED_ENTITY)?l.project.emit(ni.PERSISTED_DEFINITION_ENTITY_ADDED,i,l):ai(i,Ie.RELATIONAL_DATABASE)&&l.project.emit(ni.RELATIONAL_DATABASE_DEFINITION_ENTITY_ADDED,i,l))}),l.listUpdated.forEach(p=>{const i=l.project.get(p.id);(i==null?void 0:i.type)===d.DefinitionEntity&&i.parent.type!==d.DataType&&(l.project.emit(ni.EXPLICIT_DEFINITION_ENTITY_UPDATED,i,l),ai(i,Ie.PERSISTED_ENTITY)?l.project.emit(ni.PERSISTED_DEFINITION_ENTITY_UPDATED,i,l):ai(i,Ie.RELATIONAL_DATABASE)&&l.project.emit(ni.RELATIONAL_DATABASE_DEFINITION_ENTITY_UPDATED,i,l))}),l.listRemoved.forEach(p=>{const i=l.project.get(p.id)||l.project.getDeleted(p.id);(i==null?void 0:i.type)===d.DefinitionEntity&&i.parent.type!==d.DataType&&(l.project.emit(ni.EXPLICIT_DEFINITION_ENTITY_REMOVED,i,l),ai(i,Ie.PERSISTED_ENTITY)?l.project.emit(ni.PERSISTED_DEFINITION_ENTITY_REMOVED,i,l):ai(i,Ie.RELATIONAL_DATABASE)&&l.project.emit(ni.RELATIONAL_DATABASE_DEFINITION_ENTITY_REMOVED,i,l))}),l}async function BOe(l,p={}){const i=z.YieldTracker.from(p),r=[];for(const a of l.listAdded){const c=l.project.get(a.id);(c==null?void 0:c.type)===d.DefinitionEntity&&c.parent.type!==d.DataType&&(r.push(l.project.emitAsync(ni.EXPLICIT_DEFINITION_ENTITY_ADDED,c,l)),ai(c,Ie.PERSISTED_ENTITY)?r.push(l.project.emitAsync(ni.PERSISTED_DEFINITION_ENTITY_ADDED,c,l)):ai(c,Ie.RELATIONAL_DATABASE)&&r.push(l.project.emitAsync(ni.RELATIONAL_DATABASE_DEFINITION_ENTITY_ADDED,c,l))),await i.tick()}for(const a of l.listUpdated){const c=l.project.get(a.id);(c==null?void 0:c.type)===d.DefinitionEntity&&c.parent.type!==d.DataType&&(r.push(l.project.emitAsync(ni.EXPLICIT_DEFINITION_ENTITY_UPDATED,c,l)),ai(c,Ie.PERSISTED_ENTITY)?r.push(l.project.emitAsync(ni.PERSISTED_DEFINITION_ENTITY_UPDATED,c,l)):ai(c,Ie.RELATIONAL_DATABASE)&&r.push(l.project.emitAsync(ni.RELATIONAL_DATABASE_DEFINITION_ENTITY_UPDATED,c,l))),await i.tick()}for(const a of l.listRemoved){const c=l.project.get(a.id)||l.project.getDeleted(a.id);(c==null?void 0:c.type)===d.DefinitionEntity&&c.parent.type!==d.DataType&&(r.push(l.project.emitAsync(ni.EXPLICIT_DEFINITION_ENTITY_REMOVED,c,l)),ai(c,Ie.PERSISTED_ENTITY)?r.push(l.project.emitAsync(ni.PERSISTED_DEFINITION_ENTITY_REMOVED,c,l)):ai(c,Ie.RELATIONAL_DATABASE)&&r.push(l.project.emitAsync(ni.RELATIONAL_DATABASE_DEFINITION_ENTITY_REMOVED,c,l))),await i.tick()}return await Promise.all(r),l}var zR=(l=>(l.Manual="manual",l.Automatic="automatic",l))(zR||{}),W=(l=>(l.Added="added",l.Updated="updated",l.Removed="removed",l.Affected="affected",l))(W||{}),w=(l=>(l.AddSuccessCall="add-success-call",l.AddErrorCall="add-error-call",l.AddCall="add-call",l.SetParent="set-parent",l.SetStandaloneParent="set-standalone-parent",l.AfterAllChildrenInitialized="after-all-children-initialized",l.UpdateWithShallowTransfer="update-with-shallow-transfer",l.UpdateWithGenerationTarget="update-with-generation-target",l.RemoveFromParent="remove-from-parent",l.RemoveEntity="remove-entity",l.RestoreEntity="restore-entity",l.CloneEntity="clone-entity",l.AddInput="add-input",l.RemoveInput="remove-input",l.SetDataType="set-data-type",l.RemoveDataType="remove-data-type",l.SetAdditionalPropertiesDataType="set-additional-properties-data-type",l.RemoveAdditionalPropertiesDataType="remove-additional-properties-data-type",l.SetAllPropertiesImplement="set-all-properties-implement",l.RemoveAllPropertiesImplement="remove-all-properties-implement",l.RemoveValueReader="remove-value-reader",l.AddValueReader="add-value-reader",l.RemoveValueWriter="remove-value-writer",l.SetValueWriter="set-value-writer",l.AddEntryCaller="add-entry-caller",l.AddSuccessCaller="add-success-caller",l.AddErrorCaller="add-error-caller",l.RemoveCall="remove-call",l.RemoveCaller="remove-caller",l.RemoveChildGroup="remove-child-group",l.AddToAndGroup="add-to-and-group",l.AddToOrGroup="add-to-or-group",l.RemoveUnrecognizedInputs="remove-unrecognized-inputs",l.RemoveUnrecognizedOutputs="remove-unrecognized-outputs",l.SyncInputs="sync-inputs",l.SyncOutputs="sync-outputs",l.SetImplements="set-implements",l.SetExtends="set-extends",l.SetExtension="set-extension",l.AddImplementation="add-implementation",l.RemoveImplementation="remove-implementation",l.AddProperty="add-property",l.RemoveProperty="remove-property",l.AddMethod="add-method",l.RemoveMethod="remove-method",l.AddAbstractMethod="add-abstract-method",l.RemoveAbstractMethod="remove-abstract-method",l.SetValueAsTypeSingle="set-value-as-type-single",l.SetValueAsTypeList="set-value-as-type-list",l.SetValueAsType="set-value-as-type",l.RemoveErrorCatching="remove-error-catching",l.RemoveAllErrorCallers="remove-all-error-callers",l.RemoveAllSuccessCallers="remove-all-success-callers",l.RemoveAllCallers="remove-all-callers",l.RemoveAllErrorCalls="remove-all-error-calls",l.SetDataTypeEntityValue="set-data-type-entity-value",l.MergeDataTypes="merge-data-types",l.SetDataTypeForeignKeyRef="set-data-type-foreign-key-ref",l.SetErrorEntity="set-error-entity",l.AddValueAsTypeToList="add-value-as-type-to-list",l.RemoveValueAsTypeFromList="remove-value-as-type-from-list",l.CreateFromGenerationTarget="create-from-generation-target",l))(w||{}),Me=(l=>(l.ActionOwnerEntityNotEditable="action-owner-entity-not-editable",l.ActionCounterpartEntityNotEditable="action-counterpart-entity-not-editable",l.ActionOwnerEntityNonDeletable="action-owner-entity-non-deletable",l.GlobalVariableDeclarationCannnotCatchError="global-variable-declaration-cannot-catch-error",l.GlobalVariableDeclarationCannotReadValue="global-variable-declaration-cannot-read-value",l.GlobalVariableDeclarationCannotBeCalled="global-variable-declaration-cannot-be-called",l.GlobalVariableDeclarationCannotCallFromError="global-variable-declaration-cannot-call-from-error",l.ValueReadingOverridesConstantProperty="value-reading-overrides-constant-property",l.DefaultValueOverridesConstantProperty="default-value-overrides-constant-property",l.ValueReadingOverridesConstantVariable="value-reading-overrides-constant-variable",l.DefaultValueOverridesConstantVariable="default-value-overrides-constant-variable",l.CannotSuccessCallItself="cannot-success-call-itself",l.CannotErrorCallItself="cannot-error-call-itself",l.CannotEntryCallItself="cannot-entry-call-itself",l.CannotValueWriteItself="cannot-value-write-itself",l.CannotBeCalledBeforeDeclaration="cannot-be-called-before-declaration",l.CannotBeCalledInParallelBranchToDeclaration="cannot-be-called-in-parallel-branch-to-declaration",l.CannotBeHigherScopeThanDeclaration="cannot-be-higher-scope-than-declaration",l))(Me||{});class MOe{constructor({id:p,action:i,errorReason:r,owner:a,counterpart:c,rootAction:e},f){R(this,"id");R(this,"action");R(this,"errorReason");R(this,"owner",null);R(this,"counterpart",null);R(this,"rootAction",!1);R(this,"parent");this.id=p,this.action=i,this.errorReason=r||null,this.owner=a||null,this.counterpart=c||null,this.rootAction=e||!1,this.parent=f}}class S extends z.Events{constructor(i,r,a,c,e=!1,f=""){super(f?f+"-cs-events":"anonymous-cs-events");R(this,"id",N.UUID.uuid());R(this,"seenEntities",[]);R(this,"added",{});R(this,"updated",{});R(this,"removed",{});R(this,"affected",{});R(this,"self",null);R(this,"author");R(this,"timestamp");R(this,"open",!0);R(this,"startedClose",!1);R(this,"dirty",!0);R(this,"submitting",!1);R(this,"lockedVersions",!1);R(this,"type","manual");R(this,"autoclose",!1);R(this,"autoCloseActionName","");R(this,"project");R(this,"events",new Map);R(this,"ignoreNonEditable",!1);R(this,"ignoreNonDeletable",!1);R(this,"logger");if(this.project=i,this.author=r||N.sessionAuthor||"",this.timestamp=a,this.self=c,this.autoclose=e,this.autoCloseActionName=f,this.logger=z.Logger.module("cs:"+(this.autoCloseActionName?this.autoCloseActionName+":":"")+this.id),this.autoclose&&!this.autoCloseActionName)throw new Error("Auto-close change-set must have an auto-close action name.")}get index(){const i=this.project.history.indexOf(this);return i===-1?null:i}get isEmpty(){return Object.keys(this.added).length===0&&Object.keys(this.updated).length===0&&Object.keys(this.removed).length===0}get isValid(){var i;return!(this.isEmpty&&this.self&&!this.affected[(i=this.self)==null?void 0:i.id])}get list(){return[...Object.values(this.added),...Object.values(this.updated),...Object.values(this.removed)]}get listAdded(){return Object.values(this.added)}get listUpdated(){return Object.values(this.updated)}get listRemoved(){return Object.values(this.removed)}get listAffected(){return Object.values(this.affected)}get addedIds(){return Object.keys(this.added)}get updatedIds(){return Object.keys(this.updated)}get removedIds(){return Object.keys(this.removed)}get affectedIds(){return Object.keys(this.affected)}event(i){this.logger.log(`ChangeSet Event: ${i.action} (${i.id})`);const r=new MOe(i,this);this.events.set(i.id,r),this.emit("change-set-event",r)}discardOrphans(){this.added[this.project.id]&&(this.updatedIds.forEach(e=>{const f=this.updated[e];this.added[e]=f,delete this.updated[e]}),this.removedIds.forEach(e=>{this.remove(e)}));const i=[...this.addedIds,...this.updatedIds],a=this.project.toFlatIds().filter(e=>!this.project.diggestedBuiltInBaseEntitiesIds.has(e));if(i.filter(e=>!a.includes(e)).forEach(e=>{const f=this.get(e);this.logger.warn(`[discardOrphans] Entity ${f==null?void 0:f.type} with id "${e}" present in change-set but not in project. Removing from change-set.`),this.remove(e)}),this.added[this.project.id]){const e=[...this.addedIds,...this.updatedIds];this.project.toFlatIds().filter(E=>!this.project.diggestedBuiltInBaseEntitiesIds.has(E)).filter(E=>!e.includes(E)).forEach(E=>{const b=this.project.get(E);this.add(b,"added")})}}async discardOrphansAsync(i={}){const r=z.YieldTracker.from(i),a=this.project.toFlatIds();if(this.added[this.project.id]){for(const h of this.updatedIds){const m=this.updated[h];this.added[h]=m,delete this.updated[h],await r.tick()}for(const h of this.removedIds)this.remove(h),await r.tick()}const c=[...this.addedIds,...this.updatedIds],e=a.filter(h=>!this.project.diggestedBuiltInBaseEntitiesIds.has(h)),f=c.filter(h=>!e.includes(h));for(const h of f){const m=this.get(h);this.logger.warn(`[discardOrphansAsync] Entity ${m==null?void 0:m.type} with id "${h}" present in change-set but not in project. Removing from change-set.`),this.remove(h),await r.tick()}if(this.added[this.project.id]){const h=[...this.addedIds,...this.updatedIds],E=a.filter(b=>!this.project.diggestedBuiltInBaseEntitiesIds.has(b)).filter(b=>!h.includes(b));for(const b of E){const g=this.project.get(b);this.add(g,"added"),await r.tick()}}}captureAllChangesInVersionInstances(){[...this.addedIds,...this.updatedIds].forEach(r=>{const a=this.project.get(r);if(!a){const e=this.added[r],f=this.updated[r],h=e||f;throw new Error(`Entity ${(h==null?void 0:h.type)||"of unknown type"} with id "${r}" was ${e?"added":"updated"} but isn't found in the project state when capturing version for change-set.`)}const c=this.get(r);a.version===c.version&&a.captureVersion()}),this.removedIds.forEach(r=>{const a=this.project.getDeleted(r);if(!a){const e=this.removed[r];throw new Error(`Entity ${(e==null?void 0:e.type)||"of unknown type"} with id "${r}" was removed but isn't found in the project state when capturing version for change-set.`)}const c=this.get(r);a.version===c.version&&a.captureVersion()})}async captureAllChangesInVersionInstancesAsync(i={}){const r=z.YieldTracker.from(i),a=[...this.addedIds,...this.updatedIds];for(const c of a){const e=this.project.get(c);if(!e){const h=this.added[c],m=this.updated[c],E=h||m;throw new Error(`Entity ${(E==null?void 0:E.type)||"of unknown type"} with id "${c}" was ${h?"added":"updated"} but isn't found in the project state when capturing version for change-set.`)}const f=this.get(c);e.version===f.version&&e.captureVersion(),await r.tick()}for(const c of this.removedIds){const e=this.project.getDeleted(c);if(!e){const h=this.removed[c];throw new Error(`Entity ${(h==null?void 0:h.type)||"of unknown type"} with id "${c}" was removed but isn't found in the project state when capturing version for change-set.`)}const f=this.get(c);e.version===f.version&&e.captureVersion(),await r.tick()}}async attemptAutocloseAsync(i,r){var a;return this.autoclose&&this.autoCloseActionName&&this.autoCloseActionName===i&&(this.self&&r===((a=this.self)==null?void 0:a.id)||!this.self)&&await this.closeAsync(),this}async closeAsync(i={}){const r=z.YieldTracker.from(i),a={persistType:"sequential",...i};if(!this.open||this.startedClose)return this.logger.warn(`Change-set (${this.id}) is already closed or in the process of closing.`),this;const c=i.awaitBeforeClose??!0,e=i.awaitExternalPersist??!0;return this.startedClose||(this.startedClose=!0,c?await this.beforeCloseAsync({tracker:r}):this.beforeCloseAsync({tracker:r})),!this.isValid&&this.self&&!this.added[this.self.id]&&!this.updated[this.self.id]&&this.removed[this.self.id],await this.discardOrphansAsync({tracker:r}),await this.sanitizeAsync({tracker:r}),await this.recursiveCaptureUpstreamVersionsAsync({tracker:r}),this.lockedVersions||(await this.captureAllChangesInVersionInstancesAsync({tracker:r}),await this.recursiveCaptureUpstreamVersionsAsync({tracker:r})),this.open=!1,this.isEmpty?(this.logger.warn(`[ChangeSet.closeAsync] Empty change-set (${this.id}) discarded upon closing.`),this.dirty=!1,this.project.discardChangeSet(this),this.logger.log("[ChangeSet.closeAsync] Closing pending change-sets..."),this.project.closePersistChangeSetsSequentially(),this):(this.project.emit(ni.CHANGE_SET_CLOSED_BEFORE_PERSIST,this),e?a.persistType==="parallel"?await this.project.persistChangeSetInParallel(this):await this.project.persistChangeSetSequentially(this):a.persistType==="parallel"?this.project.persistChangeSetInParallel(this):this.project.persistChangeSetSequentially(this),this.destroy(),this)}attemptAutoclose(i,r){var a;return this.autoclose&&this.autoCloseActionName&&this.autoCloseActionName===i&&(this.self&&r===((a=this.self)==null?void 0:a.id)||!this.self)&&this.close(),this}recursiveCaptureUpstreamVersions(){if(this.lockedVersions)return;[...this.addedIds,...this.updatedIds,...this.removedIds].forEach(r=>{const a=this.get(r),{added:c,updated:e,removed:f,affected:h}=a.recursiveCaptureUpstreamVersions(this.timestamp);for(const m of c)this.add(m,"added");for(const m of e)this.add(m,"updated");for(const m of f)this.add(m,"removed");for(const m of h)this.add(m,"affected")})}async recursiveCaptureUpstreamVersionsAsync(i={}){if(this.lockedVersions)return;const r=z.YieldTracker.from(i),a=[...this.addedIds,...this.updatedIds,...this.removedIds];for await(const c of a){const e=this.get(c),{added:f,updated:h,removed:m,affected:E}=e.recursiveCaptureUpstreamVersions(this.timestamp);for(const b of f)this.add(b,"added");for(const b of h)this.add(b,"updated");for(const b of m)this.add(b,"removed");for(const b of E)this.add(b,"affected");await r.tick()}}sanitize(){this.listAdded.forEach(i=>{i.previousVersion=null})}async sanitizeAsync(i={}){const r=z.YieldTracker.from(i);for(const a of this.listAdded)a.previousVersion=null,await r.tick()}syncDependents(){return[...this.list,...this.listAffected].forEach(i=>{const r=this.project.get(i.id);!r||r.deleted||rg(r,this.project)||r==null||r.syncDependents(this)}),this}async syncDependentsAsync(i={}){const r=z.YieldTracker.from(i);for(const a of[...this.list,...this.listAffected]){const c=this.project.get(a.id);!c||c.deleted||rg(c,this.project)||(c==null||c.syncDependents(this),await r.tick())}return this}async beforeCloseAsync(i={}){const r=z.YieldTracker.from(i);await this.project.emitAsync(ni.BEFORE_CHANGE_SET_CLOSE_BEFORE_SIDE_EFFECTS,this),await this.syncDependentsAsync({tracker:r}),await this.emitAsyncProjectSideEffects({tracker:r}),await this.project.emitAsync(ni.BEFORE_CHANGE_SET_CLOSE_AFTER_SIDE_EFFECTS,this),this.teardown()}beforeClose(){this.project.emit(ni.BEFORE_CHANGE_SET_CLOSE_BEFORE_SIDE_EFFECTS,this),this.syncDependents(),this.emitProjectSideEffects(),this.project.emit(ni.BEFORE_CHANGE_SET_CLOSE_AFTER_SIDE_EFFECTS,this),this.teardown()}teardown(){this.destroy()}emitProjectSideEffects(){return LOe(this)}async emitAsyncProjectSideEffects(i={}){return BOe(this,i)}close(i={}){const r={persistType:"sequential",...i};if(!this.open||this.startedClose)return this.logger.warn(`Change-set (${this.id}) is already closed or in the process of closing.`),this;if(this.startedClose||(this.startedClose=!0,this.beforeClose()),!this.isValid&&this.self&&!this.added[this.self.id]&&!this.updated[this.self.id]&&this.removed[this.self.id],this.discardOrphans(),this.sanitize(),this.captureAllChangesInVersionInstances(),this.lockedVersions||(this.recursiveCaptureUpstreamVersions(),this.captureAllChangesInVersionInstances()),this.open=!1,this.isEmpty)return this.logger.warn(`[ChangeSet.close] Empty change-set (${this.id}) discarded upon closing.`),this.project.discardChangeSet(this),this.logger.log("[ChangeSet.close] Closing pending change-sets..."),this.project.closePersistChangeSetsSequentially(),this;if(this.added[this.project.id]&&this.updatedIds.length)throw new Error("No 'updated' entities should be present in the change-set when the project entity is in the 'added' list. New projects can only have newly added entities");if(this.added[this.project.id]&&this.removedIds.length)throw new Error("No 'removed' entities should be present in the change-set when the project entity is in the 'added' list. New projects can only have newly added entities");if(!this.updated[this.project.id]&&!this.added[this.project.id])throw new Error("Change-set must also have the project entity as 'updated' or 'added'. All changes must propagate upstream until the root project entity.");return this.project.emit(ni.CHANGE_SET_CLOSED_BEFORE_PERSIST,this),r.persistType==="parallel"?this.project.persistChangeSetInParallel(this):this.project.persistChangeSetSequentially(this),this.destroy(),this}addDependentsToAffected(i){Object.values(i.detachedDependents).forEach(r=>{const{entity:a,field:c}=r;this.has(a.id)||this.add(a,"affected")})}get(i){return this.added[i]?this.added[i]:this.updated[i]?this.updated[i]:this.removed[i]?this.removed[i]:null}remove(i){return this.has(i)&&(delete this.added[i],delete this.updated[i],delete this.removed[i],delete this.affected[i],this.seenEntities=this.seenEntities.filter(r=>r!==i)),this}add(i,r,a={preventRecursion:!1}){var e,f,h;if(!this.open||!this.dirty)return this;if(rg(i,this.project))return this;if(this.seenEntities.indexOf(i.id)===-1&&this.seenEntities.push(i.id),r==="removed"){if(this.added[i.id])return delete this.added[i.id],delete this.affected[i.id],delete this.updated[i.id],this.seenEntities=this.seenEntities.filter(E=>E!==i.id),delete this.project.deletedInstances[i.id],this;if(this.updated[i.id]&&delete this.updated[i.id],this.affected[i.id]&&delete this.affected[i.id],!this.hasRemoved(i.id)&&!this.lockedVersions&&(i.increaseVersion(this.timestamp),!a.preventRecursion)){const{added:E,updated:b,removed:g,affected:_}=i.recursiveCaptureUpstreamVersions(this.timestamp);for(const P of E)this.add(P,"added");for(const P of b)this.add(P,"updated");for(const P of g)this.add(P,"removed");for(const P of _)this.add(P,"affected")}i.captureVersion();const m=(e=i.knownVersions)==null?void 0:e.get(i.version);if(!m)throw Error(`Version ${i.version} should have a cached version instance but it wasn't found when adding entity to change-set`);return this.removed[i.id]=m,this}if(r==="added"){if(this.removed[i.id])return this;if(this.updated[i.id]&&delete this.updated[i.id],this.affected[i.id]&&delete this.affected[i.id],!this.hasAdded(i.id)&&!this.lockedVersions&&!a.preventRecursion){const{added:E,updated:b,removed:g,affected:_}=i.recursiveCaptureUpstreamVersions(this.timestamp);for(const P of E)this.add(P,"added");for(const P of b)this.add(P,"updated");for(const P of g)this.add(P,"removed");for(const P of _)this.add(P,"affected")}i.previousVersion=null,i.captureVersion();const m=(f=i.knownVersions)==null?void 0:f.get(i.version);if(!m)throw Error(`Version ${i.version} should have a cached version instance but it wasn't found when adding entity to change-set`);return this.added[i.id]=m,delete this.affected[i.id],this.addDependentsToAffected(i),this}if(r==="updated"){if(this.removed[i.id])return this;if(this.added[i.id])return i.captureVersion(),this.addDependentsToAffected(i),this;if(this.affected[i.id]&&delete this.affected[i.id],!this.hasUpdated(i.id)&&!this.lockedVersions&&(i.increaseVersion(this.timestamp),!a.preventRecursion)){const{added:E,updated:b,removed:g,affected:_}=i.recursiveCaptureUpstreamVersions(this.timestamp);for(const P of E)this.add(P,"added");for(const P of b)this.add(P,"updated");for(const P of g)this.add(P,"removed");for(const P of _)this.add(P,"affected")}i.captureVersion();const m=(h=i.knownVersions)==null?void 0:h.get(i.version);if(!m)throw Error(`Version ${i.version} should have a cached version instance but it wasn't found when adding entity to change-set`);return this.updated[i.id]=m,this.addDependentsToAffected(i),this}if(r==="affected"){if(this.removed[i.id])return this;if(this.added[i.id])return this;if(this.updated[i.id])return this;this.affected[i.id]=i}return this}toJSON(){var f;const i={},r={},a={},c=new Set;for(const h of Object.values(this.added))i[h.id]=h.toShallowJSON();for(const h of Object.values(this.updated))r[h.id]=h.toShallowJSON();for(const h of Object.values(this.removed))a[h.id]=h.toShallowJSON();for(const h of Object.values(this.affected))c.add(h.id);const e=this.get(((f=this.self)==null?void 0:f.id)||"");return{added:i,updated:r,removed:a,affected:Array.from(c),self:e?e.toShallowJSON():null,seenEntities:this.seenEntities}}has(i){return!!this.added[i]||!!this.removed[i]||!!this.updated[i]||!!this.affected[i]}hasAdded(i){return!!this.added[i]}hasUpdated(i){return!!this.updated[i]}hasRemoved(i){return!!this.removed[i]}hasAffected(i){return!!this.affected[i]}}function Mbi(l){return new Set([...Object.keys(l.added),...Object.keys(l.updated),...Object.keys(l.removed),...Array.from(l.affected)])}function u_(l,p,i){var f;const r=new Date().toISOString(),a=new S(i,N.sessionAuthor,r,i);if(a.lockedVersions=!0,l===p)throw z.Logger.error("From: ",l),z.Logger.error("To: ",p),new Error("Cannot generate transitional change set between the same two versions or change-sets");let c;if(l==="initial"?c=!0:p==="initial"?c=!1:B(l.timestamp).isBefore(B(p.timestamp))?c=!0:c=!1,z.Logger.log("Transitioning from ",l==="initial"?"initial":l.index),z.Logger.log("Transitioning to ",p==="initial"?"initial":p.index),z.Logger.log("Is forward: ",c),c){const m=p.index,E=l==="initial"?0:l.index;z.Logger.log("ownIndex: ",m),z.Logger.log("startIndex: ",E);const b=m===E?[i.history[m]]:i.history.slice(E+1,m+1);if(b.sort((g,_)=>B(g.timestamp).isAfter(B(_.timestamp))?1:-1),!b.length)throw new Error("No change sets in the history between the history indexes provided");z.Logger.log("REDO change-set: ",b[0].id," ",b[0].timestamp),b.forEach(g=>{p_(g,_=>{const P=i.instances[_.id]||i.deletedInstances[_.id];let x="";try{x=se(_,i)}catch{}if(!P)throw new Error(`Entity ${_.type} ${x?`"${x}" `:""}with id "${_.id}" doesn't have an 'activeVersion' set.`);if(!P.knownVersions)throw new Error(`Entity ${_.type} ${x?`"${x}" `:""}with id "${_.id}" has an active version instance missing the 'knownVersions' property value.`);if(!P.knownVersions.get(_.version))throw new Error(`Entity ${_.type} ${x?`"${x}" `:""}with id "${_.id}" has an active version instance missing the 'knownVersions' property value for version "${_.version}".`);P.restoreVersion(_.version),a.timestamp=P.createdAt,a.add(P,W.Added,{preventRecursion:!0})},_=>{const P=i.instances[_.id]||i.deletedInstances[_.id];let x="";try{x=se(_,i)}catch{}if(!P)throw new Error(`Entity ${_.type} ${x?`"${x}" `:""}with id "${_.id}" doesn't have an 'activeVersion' set.`);if(!P.knownVersions)throw new Error(`Entity ${_.type} ${x?`"${x}" `:""}with id "${_.id}" has an active version instance missing the 'knownVersions' property value.`);if(!P.knownVersions.get(_.version))throw new Error(`Entity ${_.type} ${x?`"${x}" `:""}with id "${_.id}" has an active version instance missing the 'knownVersions' property value for version "${_.version}".`);P.restoreVersion(_.version),a.timestamp=P.createdAt,a.add(P,W.Updated,{preventRecursion:!0})},_=>{const P=i.instances[_.id]||i.deletedInstances[_.id];let x="";try{x=se(_,i)}catch{}if(!P)throw new Error(`Entity ${_.type} ${x?`"${x}" `:""}with id "${_.id}" doesn't have an 'activeVersion' set.`);if(!P.knownVersions)throw new Error(`Entity ${_.type} ${x?`"${x}" `:""}with id "${_.id}" has an active version instance missing the 'knownVersions' property value.`);if(!P.knownVersions.get(_.version))throw new Error(`Entity ${_.type} ${x?`"${x}" `:""}with id "${_.id}" has an active version instance missing the 'knownVersions' property value for version "${_.version}".`);P.restoreVersion(_.version),a.timestamp=P.createdAt,a.add(P,W.Removed,{preventRecursion:!0})})})}else{const m=l.index,E=p==="initial"?0:p.index,b=m===E?[i.history[m]]:i.history.slice(E+1,m+1);if(b.sort((g,_)=>B(_.timestamp).isAfter(B(g.timestamp))?1:-1),!b.length)throw new Error("No change sets in the history between the history indexes provided");z.Logger.log("UNDO change-set: ",b[0].id," ",b[0].timestamp),b.forEach(g=>{p_(g,_=>{const P=i.instances[_.id]||i.deletedInstances[_.id];let x="";try{x=se(_,i)}catch{}if(!P)throw new Error(`Entity ${_.type} ${x?`"${x}" `:""}with id "${_.id}" doesn't have an 'activeVersion' set.`);if(!P.knownVersions)throw new Error(`Entity ${_.type} ${x?`"${x}" `:""}with id "${_.id}" has an active version instance missing the 'knownVersions' property value.`);if(!P.knownVersions.get(_.version))throw new Error(`Entity ${_.type} ${x?`"${x}" `:""}with id "${_.id}" has an active version instance missing the 'knownVersions' property value for version "${_.version}".`);_.previousVersion&&P.restoreVersion(_.previousVersion),a.timestamp=P.createdAt,a.add(P,W.Removed,{preventRecursion:!0})},_=>{const P=i.instances[_.id]||i.deletedInstances[_.id];let x="";try{x=se(_,i)}catch{}if(!P)throw new Error(`Entity ${_.type} ${x?`"${x}" `:""}with id "${_.id}" doesn't have an 'activeVersion' set.`);if(!P.knownVersions)throw new Error(`Entity ${_.type} ${x?`"${x}" `:""}with id "${_.id}" has an active version instance missing the 'knownVersions' property value.`);if(!P.knownVersions.get(_.version))throw new Error(`Entity ${_.type} ${x?`"${x}" `:""}with id "${_.id}" has an active version instance missing the 'knownVersions' property value for version "${_.version}".`);P.restoreVersion(_.previousVersion),a.timestamp=P.createdAt,a.add(P,W.Updated,{preventRecursion:!0})},_=>{const P=i.instances[_.id]||i.deletedInstances[_.id];let x="";try{x=se(_,i)}catch{}if(!P)throw new Error(`Entity ${_.type} ${x?`"${x}" `:""}with id "${_.id}" doesn't have an 'activeVersion' set.`);if(!P.knownVersions)throw new Error(`Entity ${_.type} ${x?`"${x}" `:""}with id "${_.id}" has an active version instance missing the 'knownVersions' property value.`);if(!P.knownVersions.get(_.version))throw new Error(`Entity ${_.type} ${x?`"${x}" `:""}with id "${_.id}" has an active version instance missing the 'knownVersions' property value for version "${_.version}".`);P.restoreVersion(_.previousVersion),a.timestamp=P.createdAt,a.add(P,W.Added,{preventRecursion:!0})})})}let e;if(p==="initial"){const h=Array.from(((f=i.knownVersions)==null?void 0:f.values())||[]).reduce((m,E)=>!m||B(E.createdAt).isBefore(B(m.createdAt))?E:m,null);if(!h)throw new Error("No oldest version found");e=h.createdAt}else e=p.timestamp;return a.open=!1,{transitionalChangeSet:a,transitionTime:r,timeOfOriginalTargetChanges:e}}function p_(l,p,i,r){var f;if(!(l!=null&&l.self))throw new Error("Change set must have a valid `self` entity state to be traversed");const a=((f=l.self)==null?void 0:f.type)===d.Project?l.self:l.self.project,c=new fn(l.self,{allBuiltInEntityIds:a.diggestedBuiltInBaseEntitiesIds});z.Logger.log("changeSet.added: ",Object.keys(l.added).length),z.Logger.log("changeSet.updated: ",Object.keys(l.updated).length),z.Logger.log("changeSet.removed: ",Object.keys(l.removed).length);const e={...l.added,...l.updated,...l.removed};c.order=Object.keys(e),c.flatRecord=e,c.orderEntities(),z.Logger.log("All entities: ",c.order.map((h,m)=>`${m+1}: ${e[h].type} - ${h}`).join(`,
6
+ Please provide a unique 'name' string.`,severity:Te.Error,code:we.NameNotUniqueInScope}))}}return i}function vbi(l,p){switch(l.type){case d.DefinitionEntity:return ax(l,p);case d.FunctionDeclaration:return sx(l,p);case d.VariableDeclaration:return lx(l,p);case d.Property:return ox(l,p);case d.ArgumentDeclaration:return dx(l,p);default:return[]}}function nf(l,p){var r;const i=l;switch(l.type){case d.FunctionCall:case d.InternalCall:return ca(l.declaration,p).codeName;case d.ActionDescriptor:case d.DefinitionEntity:case d.VariableDeclaration:case d.ValueDescriptor:case d.FunctionDeclaration:return l.codeName||null;case d.Property:case d.ArgumentDeclaration:{if(l.codeName)return l.codeName;if((r=l.implements)!=null&&r.length){const a=l.implements.find(c=>{const e=ca(c,p);return!!(e!=null&&e.codeName)});if(a)return ca(a,p).codeName||null}break}case d.InputMap:case d.OutputMap:case d.VariableInstance:{if(l.declaration){const a=ca(l.declaration,p);return nf(a,p)||""}break}}return i.codeName||null}function uh(l,p){let i=l;if(!!p.some(a=>a.name===i)){const a=l.split(" "),c=a.pop()||"",e=parseInt(c);return!isNaN(e)?a.push(`${e+1}`):(a.push(c),a.push("1")),i=a.join(" "),uh(i,p)}return i}function POe(l,p,i){const a=`${pg(l)}-${p}-id`;return i.instances[a]?N.UUID.uuid():a}function o_(l,p){let i="",r=null;if(l.parent){const c=p.get(l.parent);c&&(r=c)}let a="";return r&&(a=`${pg(se(r,p))}-`),i=`${a}${pg(se(l,p))}-id`,p.instances[i]?N.UUID.uuid():i}function en(l,p,i="uuid"){return i==="semantic"?POe(se(l,p),l.type,p):N.UUID.uuid()}const Ebi=/^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;function ux(l){return typeof l=="string"&&Ebi.test(l)}const bbi=/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;function d_(l){return typeof l=="string"&&bbi.test(l)}function Abi(l){return l instanceof Error&&l.name==="ZodError"&&"issues"in l&&Array.isArray(l.issues)}var gbi=class extends Error{constructor(p,i){super(p,i);R(this,"name");R(this,"details");this.name="ZodValidationError",this.details=Ibi(i)}toString(){return this.message}};function Ibi(l){if(l){const p=l.cause;if(Abi(p))return p.issues}return[]}function Rbi(l){return l.length!==0}function EU(l){return l.description??""}var Dbi=/[$_\p{ID_Start}][$\u200c\u200d\p{ID_Continue}]*/u;function wbi(l){if(l.length===1){let p=l[0];return typeof p=="symbol"&&(p=EU(p)),p.toString()||'""'}return l.reduce((p,i)=>{if(typeof i=="number")return p+"["+i.toString()+"]";if(typeof i=="symbol"&&(i=EU(i)),i.includes('"'))return p+'["'+Cbi(i)+'"]';if(!Dbi.test(i))return p+'["'+i+'"]';const r=p.length===0?"":".";return p+r+i},"")}function Cbi(l){return l.replace(/"/g,'\\"')}var Obi="; ",_bi=99,NOe="Validation error",Vbi=": ",Pbi=", or ";function Nbi(l={}){const{issueSeparator:p=Obi,unionSeparator:i=Pbi,prefixSeparator:r=Vbi,prefix:a=NOe,includePath:c=!0,maxIssuesInMessage:e=_bi}=l;return f=>{const h=f.slice(0,e).map(m=>kA({issue:m,issueSeparator:p,unionSeparator:i,includePath:c})).join(p);return xbi(h,a,r)}}function kA(l){const{issue:p,issueSeparator:i,unionSeparator:r,includePath:a}=l;if(p.code===lt.invalid_union)return p.unionErrors.reduce((c,e)=>{const f=e.issues.map(h=>kA({issue:h,issueSeparator:i,unionSeparator:r,includePath:a})).join(i);return c.includes(f)||c.push(f),c},[]).join(r);if(p.code===lt.invalid_arguments)return[p.message,...p.argumentsError.issues.map(c=>kA({issue:c,issueSeparator:i,unionSeparator:r,includePath:a}))].join(i);if(p.code===lt.invalid_return_type)return[p.message,...p.returnTypeError.issues.map(c=>kA({issue:c,issueSeparator:i,unionSeparator:r,includePath:a}))].join(i);if(a&&Rbi(p.path)){if(p.path.length===1){const c=p.path[0];if(typeof c=="number")return`${p.message} at index ${c}`}return`${p.message} at "${wbi(p.path)}"`}return p.message}function xbi(l,p,i){return p!==null?l.length>0?[p,l].join(i):p:l.length>0?l:NOe}function $bi(l,p={}){const r=Lbi(p)([l]);return new gbi(r,{cause:new Qo([l])})}function Lbi(l){return"messageBuilder"in l?l.messageBuilder:Nbi(l)}async function xOe(l,p={}){var c;const i=z.YieldTracker.from(p),r=[...ys(l)];await i.tick();const a=kt(l.errors,r);return await((c=l.dataType)==null?void 0:c.validateAsync({tracker:i})),a}function $Oe(l){var i;(i=l.dataType)==null||i.validate();const p=[...ys(l)];return kt(l.errors,p)}const Bbi=Object.freeze(Object.defineProperty({__proto__:null,validate:$Oe,validateAsync:xOe},Symbol.toStringTag,{value:"Module"}));function LOe(l){return l.listAdded.forEach(p=>{const i=l.project.get(p.id);(i==null?void 0:i.type)===d.DefinitionEntity&&i.parent.type!==d.DataType&&(l.project.emit(ni.EXPLICIT_DEFINITION_ENTITY_ADDED,i,l),ai(i,Ie.PERSISTED_ENTITY)?l.project.emit(ni.PERSISTED_DEFINITION_ENTITY_ADDED,i,l):ai(i,Ie.RELATIONAL_DATABASE)&&l.project.emit(ni.RELATIONAL_DATABASE_DEFINITION_ENTITY_ADDED,i,l))}),l.listUpdated.forEach(p=>{const i=l.project.get(p.id);(i==null?void 0:i.type)===d.DefinitionEntity&&i.parent.type!==d.DataType&&(l.project.emit(ni.EXPLICIT_DEFINITION_ENTITY_UPDATED,i,l),ai(i,Ie.PERSISTED_ENTITY)?l.project.emit(ni.PERSISTED_DEFINITION_ENTITY_UPDATED,i,l):ai(i,Ie.RELATIONAL_DATABASE)&&l.project.emit(ni.RELATIONAL_DATABASE_DEFINITION_ENTITY_UPDATED,i,l))}),l.listRemoved.forEach(p=>{const i=l.project.get(p.id)||l.project.getDeleted(p.id);(i==null?void 0:i.type)===d.DefinitionEntity&&i.parent.type!==d.DataType&&(l.project.emit(ni.EXPLICIT_DEFINITION_ENTITY_REMOVED,i,l),ai(i,Ie.PERSISTED_ENTITY)?l.project.emit(ni.PERSISTED_DEFINITION_ENTITY_REMOVED,i,l):ai(i,Ie.RELATIONAL_DATABASE)&&l.project.emit(ni.RELATIONAL_DATABASE_DEFINITION_ENTITY_REMOVED,i,l))}),l}async function BOe(l,p={}){const i=z.YieldTracker.from(p),r=[];for(const a of l.listAdded){const c=l.project.get(a.id);(c==null?void 0:c.type)===d.DefinitionEntity&&c.parent.type!==d.DataType&&(r.push(l.project.emitAsync(ni.EXPLICIT_DEFINITION_ENTITY_ADDED,c,l)),ai(c,Ie.PERSISTED_ENTITY)?r.push(l.project.emitAsync(ni.PERSISTED_DEFINITION_ENTITY_ADDED,c,l)):ai(c,Ie.RELATIONAL_DATABASE)&&r.push(l.project.emitAsync(ni.RELATIONAL_DATABASE_DEFINITION_ENTITY_ADDED,c,l))),await i.tick()}for(const a of l.listUpdated){const c=l.project.get(a.id);(c==null?void 0:c.type)===d.DefinitionEntity&&c.parent.type!==d.DataType&&(r.push(l.project.emitAsync(ni.EXPLICIT_DEFINITION_ENTITY_UPDATED,c,l)),ai(c,Ie.PERSISTED_ENTITY)?r.push(l.project.emitAsync(ni.PERSISTED_DEFINITION_ENTITY_UPDATED,c,l)):ai(c,Ie.RELATIONAL_DATABASE)&&r.push(l.project.emitAsync(ni.RELATIONAL_DATABASE_DEFINITION_ENTITY_UPDATED,c,l))),await i.tick()}for(const a of l.listRemoved){const c=l.project.get(a.id)||l.project.getDeleted(a.id);(c==null?void 0:c.type)===d.DefinitionEntity&&c.parent.type!==d.DataType&&(r.push(l.project.emitAsync(ni.EXPLICIT_DEFINITION_ENTITY_REMOVED,c,l)),ai(c,Ie.PERSISTED_ENTITY)?r.push(l.project.emitAsync(ni.PERSISTED_DEFINITION_ENTITY_REMOVED,c,l)):ai(c,Ie.RELATIONAL_DATABASE)&&r.push(l.project.emitAsync(ni.RELATIONAL_DATABASE_DEFINITION_ENTITY_REMOVED,c,l))),await i.tick()}return await Promise.all(r),l}var zR=(l=>(l.Manual="manual",l.Automatic="automatic",l))(zR||{}),W=(l=>(l.Added="added",l.Updated="updated",l.Removed="removed",l.Affected="affected",l))(W||{}),w=(l=>(l.AddSuccessCall="add-success-call",l.AddErrorCall="add-error-call",l.AddCall="add-call",l.SetParent="set-parent",l.SetStandaloneParent="set-standalone-parent",l.AfterAllChildrenInitialized="after-all-children-initialized",l.UpdateWithShallowTransfer="update-with-shallow-transfer",l.UpdateWithGenerationTarget="update-with-generation-target",l.RemoveFromParent="remove-from-parent",l.RemoveEntity="remove-entity",l.RestoreEntity="restore-entity",l.CloneEntity="clone-entity",l.AddInput="add-input",l.RemoveInput="remove-input",l.SetDataType="set-data-type",l.RemoveDataType="remove-data-type",l.SetAdditionalPropertiesDataType="set-additional-properties-data-type",l.RemoveAdditionalPropertiesDataType="remove-additional-properties-data-type",l.SetAllPropertiesImplement="set-all-properties-implement",l.RemoveAllPropertiesImplement="remove-all-properties-implement",l.RemoveValueReader="remove-value-reader",l.AddValueReader="add-value-reader",l.RemoveValueWriter="remove-value-writer",l.SetValueWriter="set-value-writer",l.AddEntryCaller="add-entry-caller",l.AddSuccessCaller="add-success-caller",l.AddErrorCaller="add-error-caller",l.RemoveCall="remove-call",l.RemoveCaller="remove-caller",l.RemoveChildGroup="remove-child-group",l.AddToAndGroup="add-to-and-group",l.AddToOrGroup="add-to-or-group",l.RemoveUnrecognizedInputs="remove-unrecognized-inputs",l.RemoveUnrecognizedOutputs="remove-unrecognized-outputs",l.SyncInputs="sync-inputs",l.SyncOutputs="sync-outputs",l.SetImplements="set-implements",l.SetExtends="set-extends",l.SetExtension="set-extension",l.AddImplementation="add-implementation",l.RemoveImplementation="remove-implementation",l.AddProperty="add-property",l.RemoveProperty="remove-property",l.AddMethod="add-method",l.RemoveMethod="remove-method",l.AddAbstractMethod="add-abstract-method",l.RemoveAbstractMethod="remove-abstract-method",l.SetValueAsTypeSingle="set-value-as-type-single",l.SetValueAsTypeList="set-value-as-type-list",l.SetValueAsType="set-value-as-type",l.RemoveErrorCatching="remove-error-catching",l.RemoveAllErrorCallers="remove-all-error-callers",l.RemoveAllSuccessCallers="remove-all-success-callers",l.RemoveAllCallers="remove-all-callers",l.RemoveAllErrorCalls="remove-all-error-calls",l.SetDataTypeEntityValue="set-data-type-entity-value",l.MergeDataTypes="merge-data-types",l.SetDataTypeForeignKeyRef="set-data-type-foreign-key-ref",l.SetErrorEntity="set-error-entity",l.AddValueAsTypeToList="add-value-as-type-to-list",l.RemoveValueAsTypeFromList="remove-value-as-type-from-list",l.CreateFromGenerationTarget="create-from-generation-target",l))(w||{}),Me=(l=>(l.ActionOwnerEntityNotEditable="action-owner-entity-not-editable",l.ActionCounterpartEntityNotEditable="action-counterpart-entity-not-editable",l.ActionOwnerEntityNonDeletable="action-owner-entity-non-deletable",l.GlobalVariableDeclarationCannnotCatchError="global-variable-declaration-cannot-catch-error",l.GlobalVariableDeclarationCannotReadValue="global-variable-declaration-cannot-read-value",l.GlobalVariableDeclarationCannotBeCalled="global-variable-declaration-cannot-be-called",l.GlobalVariableDeclarationCannotCallFromError="global-variable-declaration-cannot-call-from-error",l.ValueReadingOverridesConstantProperty="value-reading-overrides-constant-property",l.DefaultValueOverridesConstantProperty="default-value-overrides-constant-property",l.ValueReadingOverridesConstantVariable="value-reading-overrides-constant-variable",l.DefaultValueOverridesConstantVariable="default-value-overrides-constant-variable",l.CannotSuccessCallItself="cannot-success-call-itself",l.CannotErrorCallItself="cannot-error-call-itself",l.CannotEntryCallItself="cannot-entry-call-itself",l.CannotValueWriteItself="cannot-value-write-itself",l.CannotBeCalledBeforeDeclaration="cannot-be-called-before-declaration",l.CannotBeCalledInParallelBranchToDeclaration="cannot-be-called-in-parallel-branch-to-declaration",l.CannotBeHigherScopeThanDeclaration="cannot-be-higher-scope-than-declaration",l.InputsInGlobalVariableDeclarationsCannotReadValues="inputs-in-global-variable-declarations-cannot-read-values",l))(Me||{});class MOe{constructor({id:p,action:i,errorReason:r,owner:a,counterpart:c,rootAction:e},f){R(this,"id");R(this,"action");R(this,"errorReason");R(this,"owner",null);R(this,"counterpart",null);R(this,"rootAction",!1);R(this,"parent");this.id=p,this.action=i,this.errorReason=r||null,this.owner=a||null,this.counterpart=c||null,this.rootAction=e||!1,this.parent=f}}class S extends z.Events{constructor(i,r,a,c,e=!1,f=""){super(f?f+"-cs-events":"anonymous-cs-events");R(this,"id",N.UUID.uuid());R(this,"seenEntities",[]);R(this,"added",{});R(this,"updated",{});R(this,"removed",{});R(this,"affected",{});R(this,"self",null);R(this,"author");R(this,"timestamp");R(this,"open",!0);R(this,"startedClose",!1);R(this,"dirty",!0);R(this,"submitting",!1);R(this,"lockedVersions",!1);R(this,"type","manual");R(this,"autoclose",!1);R(this,"autoCloseActionName","");R(this,"project");R(this,"events",new Map);R(this,"ignoreNonEditable",!1);R(this,"ignoreNonDeletable",!1);R(this,"logger");if(this.project=i,this.author=r||N.sessionAuthor||"",this.timestamp=a,this.self=c,this.autoclose=e,this.autoCloseActionName=f,this.logger=z.Logger.module("cs:"+(this.autoCloseActionName?this.autoCloseActionName+":":"")+this.id),this.autoclose&&!this.autoCloseActionName)throw new Error("Auto-close change-set must have an auto-close action name.")}get index(){const i=this.project.history.indexOf(this);return i===-1?null:i}get isEmpty(){return Object.keys(this.added).length===0&&Object.keys(this.updated).length===0&&Object.keys(this.removed).length===0}get isValid(){var i;return!(this.isEmpty&&this.self&&!this.affected[(i=this.self)==null?void 0:i.id])}get list(){return[...Object.values(this.added),...Object.values(this.updated),...Object.values(this.removed)]}get listAdded(){return Object.values(this.added)}get listUpdated(){return Object.values(this.updated)}get listRemoved(){return Object.values(this.removed)}get listAffected(){return Object.values(this.affected)}get addedIds(){return Object.keys(this.added)}get updatedIds(){return Object.keys(this.updated)}get removedIds(){return Object.keys(this.removed)}get affectedIds(){return Object.keys(this.affected)}event(i){this.logger.log(`ChangeSet Event: ${i.action} (${i.id})`);const r=new MOe(i,this);this.events.set(i.id,r),this.emit("change-set-event",r)}discardOrphans(){this.added[this.project.id]&&(this.updatedIds.forEach(e=>{const f=this.updated[e];this.added[e]=f,delete this.updated[e]}),this.removedIds.forEach(e=>{this.remove(e)}));const i=[...this.addedIds,...this.updatedIds],a=this.project.toFlatIds().filter(e=>!this.project.diggestedBuiltInBaseEntitiesIds.has(e));if(i.filter(e=>!a.includes(e)).forEach(e=>{const f=this.get(e);this.logger.warn(`[discardOrphans] Entity ${f==null?void 0:f.type} with id "${e}" present in change-set but not in project. Removing from change-set.`),this.remove(e)}),this.added[this.project.id]){const e=[...this.addedIds,...this.updatedIds];this.project.toFlatIds().filter(E=>!this.project.diggestedBuiltInBaseEntitiesIds.has(E)).filter(E=>!e.includes(E)).forEach(E=>{const b=this.project.get(E);this.add(b,"added")})}}async discardOrphansAsync(i={}){const r=z.YieldTracker.from(i),a=this.project.toFlatIds();if(this.added[this.project.id]){for(const h of this.updatedIds){const m=this.updated[h];this.added[h]=m,delete this.updated[h],await r.tick()}for(const h of this.removedIds)this.remove(h),await r.tick()}const c=[...this.addedIds,...this.updatedIds],e=a.filter(h=>!this.project.diggestedBuiltInBaseEntitiesIds.has(h)),f=c.filter(h=>!e.includes(h));for(const h of f){const m=this.get(h);this.logger.warn(`[discardOrphansAsync] Entity ${m==null?void 0:m.type} with id "${h}" present in change-set but not in project. Removing from change-set.`),this.remove(h),await r.tick()}if(this.added[this.project.id]){const h=[...this.addedIds,...this.updatedIds],E=a.filter(b=>!this.project.diggestedBuiltInBaseEntitiesIds.has(b)).filter(b=>!h.includes(b));for(const b of E){const g=this.project.get(b);this.add(g,"added"),await r.tick()}}}captureAllChangesInVersionInstances(){[...this.addedIds,...this.updatedIds].forEach(r=>{const a=this.project.get(r);if(!a){const e=this.added[r],f=this.updated[r],h=e||f;throw new Error(`Entity ${(h==null?void 0:h.type)||"of unknown type"} with id "${r}" was ${e?"added":"updated"} but isn't found in the project state when capturing version for change-set.`)}const c=this.get(r);a.version===c.version&&a.captureVersion()}),this.removedIds.forEach(r=>{const a=this.project.getDeleted(r);if(!a){const e=this.removed[r];throw new Error(`Entity ${(e==null?void 0:e.type)||"of unknown type"} with id "${r}" was removed but isn't found in the project state when capturing version for change-set.`)}const c=this.get(r);a.version===c.version&&a.captureVersion()})}async captureAllChangesInVersionInstancesAsync(i={}){const r=z.YieldTracker.from(i),a=[...this.addedIds,...this.updatedIds];for(const c of a){const e=this.project.get(c);if(!e){const h=this.added[c],m=this.updated[c],E=h||m;throw new Error(`Entity ${(E==null?void 0:E.type)||"of unknown type"} with id "${c}" was ${h?"added":"updated"} but isn't found in the project state when capturing version for change-set.`)}const f=this.get(c);e.version===f.version&&e.captureVersion(),await r.tick()}for(const c of this.removedIds){const e=this.project.getDeleted(c);if(!e){const h=this.removed[c];throw new Error(`Entity ${(h==null?void 0:h.type)||"of unknown type"} with id "${c}" was removed but isn't found in the project state when capturing version for change-set.`)}const f=this.get(c);e.version===f.version&&e.captureVersion(),await r.tick()}}async attemptAutocloseAsync(i,r){var a;return this.autoclose&&this.autoCloseActionName&&this.autoCloseActionName===i&&(this.self&&r===((a=this.self)==null?void 0:a.id)||!this.self)&&await this.closeAsync(),this}async closeAsync(i={}){const r=z.YieldTracker.from(i),a={persistType:"sequential",...i};if(!this.open||this.startedClose)return this.logger.warn(`Change-set (${this.id}) is already closed or in the process of closing.`),this;const c=i.awaitBeforeClose??!0,e=i.awaitExternalPersist??!0;return this.startedClose||(this.startedClose=!0,c?await this.beforeCloseAsync({tracker:r}):this.beforeCloseAsync({tracker:r})),!this.isValid&&this.self&&!this.added[this.self.id]&&!this.updated[this.self.id]&&this.removed[this.self.id],await this.discardOrphansAsync({tracker:r}),await this.sanitizeAsync({tracker:r}),await this.recursiveCaptureUpstreamVersionsAsync({tracker:r}),this.lockedVersions||(await this.captureAllChangesInVersionInstancesAsync({tracker:r}),await this.recursiveCaptureUpstreamVersionsAsync({tracker:r})),this.open=!1,this.isEmpty?(this.logger.warn(`[ChangeSet.closeAsync] Empty change-set (${this.id}) discarded upon closing.`),this.dirty=!1,this.project.discardChangeSet(this),this.logger.log("[ChangeSet.closeAsync] Closing pending change-sets..."),this.project.closePersistChangeSetsSequentially(),this):(this.project.emit(ni.CHANGE_SET_CLOSED_BEFORE_PERSIST,this),e?a.persistType==="parallel"?await this.project.persistChangeSetInParallel(this):await this.project.persistChangeSetSequentially(this):a.persistType==="parallel"?this.project.persistChangeSetInParallel(this):this.project.persistChangeSetSequentially(this),this.destroy(),this)}attemptAutoclose(i,r){var a;return this.autoclose&&this.autoCloseActionName&&this.autoCloseActionName===i&&(this.self&&r===((a=this.self)==null?void 0:a.id)||!this.self)&&this.close(),this}recursiveCaptureUpstreamVersions(){if(this.lockedVersions)return;[...this.addedIds,...this.updatedIds,...this.removedIds].forEach(r=>{const a=this.get(r),{added:c,updated:e,removed:f,affected:h}=a.recursiveCaptureUpstreamVersions(this.timestamp);for(const m of c)this.add(m,"added");for(const m of e)this.add(m,"updated");for(const m of f)this.add(m,"removed");for(const m of h)this.add(m,"affected")})}async recursiveCaptureUpstreamVersionsAsync(i={}){if(this.lockedVersions)return;const r=z.YieldTracker.from(i),a=[...this.addedIds,...this.updatedIds,...this.removedIds];for await(const c of a){const e=this.get(c),{added:f,updated:h,removed:m,affected:E}=e.recursiveCaptureUpstreamVersions(this.timestamp);for(const b of f)this.add(b,"added");for(const b of h)this.add(b,"updated");for(const b of m)this.add(b,"removed");for(const b of E)this.add(b,"affected");await r.tick()}}sanitize(){this.listAdded.forEach(i=>{i.previousVersion=null})}async sanitizeAsync(i={}){const r=z.YieldTracker.from(i);for(const a of this.listAdded)a.previousVersion=null,await r.tick()}syncDependents(){return[...this.list,...this.listAffected].forEach(i=>{const r=this.project.get(i.id);!r||r.deleted||rg(r,this.project)||r==null||r.syncDependents(this)}),this}async syncDependentsAsync(i={}){const r=z.YieldTracker.from(i);for(const a of[...this.list,...this.listAffected]){const c=this.project.get(a.id);!c||c.deleted||rg(c,this.project)||(c==null||c.syncDependents(this),await r.tick())}return this}async beforeCloseAsync(i={}){const r=z.YieldTracker.from(i);await this.project.emitAsync(ni.BEFORE_CHANGE_SET_CLOSE_BEFORE_SIDE_EFFECTS,this),await this.syncDependentsAsync({tracker:r}),await this.emitAsyncProjectSideEffects({tracker:r}),await this.project.emitAsync(ni.BEFORE_CHANGE_SET_CLOSE_AFTER_SIDE_EFFECTS,this),this.teardown()}beforeClose(){this.project.emit(ni.BEFORE_CHANGE_SET_CLOSE_BEFORE_SIDE_EFFECTS,this),this.syncDependents(),this.emitProjectSideEffects(),this.project.emit(ni.BEFORE_CHANGE_SET_CLOSE_AFTER_SIDE_EFFECTS,this),this.teardown()}teardown(){this.destroy()}emitProjectSideEffects(){return LOe(this)}async emitAsyncProjectSideEffects(i={}){return BOe(this,i)}close(i={}){const r={persistType:"sequential",...i};if(!this.open||this.startedClose)return this.logger.warn(`Change-set (${this.id}) is already closed or in the process of closing.`),this;if(this.startedClose||(this.startedClose=!0,this.beforeClose()),!this.isValid&&this.self&&!this.added[this.self.id]&&!this.updated[this.self.id]&&this.removed[this.self.id],this.discardOrphans(),this.sanitize(),this.captureAllChangesInVersionInstances(),this.lockedVersions||(this.recursiveCaptureUpstreamVersions(),this.captureAllChangesInVersionInstances()),this.open=!1,this.isEmpty)return this.logger.warn(`[ChangeSet.close] Empty change-set (${this.id}) discarded upon closing.`),this.project.discardChangeSet(this),this.logger.log("[ChangeSet.close] Closing pending change-sets..."),this.project.closePersistChangeSetsSequentially(),this;if(this.added[this.project.id]&&this.updatedIds.length)throw new Error("No 'updated' entities should be present in the change-set when the project entity is in the 'added' list. New projects can only have newly added entities");if(this.added[this.project.id]&&this.removedIds.length)throw new Error("No 'removed' entities should be present in the change-set when the project entity is in the 'added' list. New projects can only have newly added entities");if(!this.updated[this.project.id]&&!this.added[this.project.id])throw new Error("Change-set must also have the project entity as 'updated' or 'added'. All changes must propagate upstream until the root project entity.");return this.project.emit(ni.CHANGE_SET_CLOSED_BEFORE_PERSIST,this),r.persistType==="parallel"?this.project.persistChangeSetInParallel(this):this.project.persistChangeSetSequentially(this),this.destroy(),this}addDependentsToAffected(i){Object.values(i.detachedDependents).forEach(r=>{const{entity:a,field:c}=r;this.has(a.id)||this.add(a,"affected")})}get(i){return this.added[i]?this.added[i]:this.updated[i]?this.updated[i]:this.removed[i]?this.removed[i]:null}remove(i){return this.has(i)&&(delete this.added[i],delete this.updated[i],delete this.removed[i],delete this.affected[i],this.seenEntities=this.seenEntities.filter(r=>r!==i)),this}add(i,r,a={preventRecursion:!1}){var e,f,h;if(!this.open||!this.dirty)return this;if(rg(i,this.project))return this;if(this.seenEntities.indexOf(i.id)===-1&&this.seenEntities.push(i.id),r==="removed"){if(this.added[i.id])return delete this.added[i.id],delete this.affected[i.id],delete this.updated[i.id],this.seenEntities=this.seenEntities.filter(E=>E!==i.id),delete this.project.deletedInstances[i.id],this;if(this.updated[i.id]&&delete this.updated[i.id],this.affected[i.id]&&delete this.affected[i.id],!this.hasRemoved(i.id)&&!this.lockedVersions&&(i.increaseVersion(this.timestamp),!a.preventRecursion)){const{added:E,updated:b,removed:g,affected:_}=i.recursiveCaptureUpstreamVersions(this.timestamp);for(const P of E)this.add(P,"added");for(const P of b)this.add(P,"updated");for(const P of g)this.add(P,"removed");for(const P of _)this.add(P,"affected")}i.captureVersion();const m=(e=i.knownVersions)==null?void 0:e.get(i.version);if(!m)throw Error(`Version ${i.version} should have a cached version instance but it wasn't found when adding entity to change-set`);return this.removed[i.id]=m,this}if(r==="added"){if(this.removed[i.id])return this;if(this.updated[i.id]&&delete this.updated[i.id],this.affected[i.id]&&delete this.affected[i.id],!this.hasAdded(i.id)&&!this.lockedVersions&&!a.preventRecursion){const{added:E,updated:b,removed:g,affected:_}=i.recursiveCaptureUpstreamVersions(this.timestamp);for(const P of E)this.add(P,"added");for(const P of b)this.add(P,"updated");for(const P of g)this.add(P,"removed");for(const P of _)this.add(P,"affected")}i.previousVersion=null,i.captureVersion();const m=(f=i.knownVersions)==null?void 0:f.get(i.version);if(!m)throw Error(`Version ${i.version} should have a cached version instance but it wasn't found when adding entity to change-set`);return this.added[i.id]=m,delete this.affected[i.id],this.addDependentsToAffected(i),this}if(r==="updated"){if(this.removed[i.id])return this;if(this.added[i.id])return i.captureVersion(),this.addDependentsToAffected(i),this;if(this.affected[i.id]&&delete this.affected[i.id],!this.hasUpdated(i.id)&&!this.lockedVersions&&(i.increaseVersion(this.timestamp),!a.preventRecursion)){const{added:E,updated:b,removed:g,affected:_}=i.recursiveCaptureUpstreamVersions(this.timestamp);for(const P of E)this.add(P,"added");for(const P of b)this.add(P,"updated");for(const P of g)this.add(P,"removed");for(const P of _)this.add(P,"affected")}i.captureVersion();const m=(h=i.knownVersions)==null?void 0:h.get(i.version);if(!m)throw Error(`Version ${i.version} should have a cached version instance but it wasn't found when adding entity to change-set`);return this.updated[i.id]=m,this.addDependentsToAffected(i),this}if(r==="affected"){if(this.removed[i.id])return this;if(this.added[i.id])return this;if(this.updated[i.id])return this;this.affected[i.id]=i}return this}toJSON(){var f;const i={},r={},a={},c=new Set;for(const h of Object.values(this.added))i[h.id]=h.toShallowJSON();for(const h of Object.values(this.updated))r[h.id]=h.toShallowJSON();for(const h of Object.values(this.removed))a[h.id]=h.toShallowJSON();for(const h of Object.values(this.affected))c.add(h.id);const e=this.get(((f=this.self)==null?void 0:f.id)||"");return{added:i,updated:r,removed:a,affected:Array.from(c),self:e?e.toShallowJSON():null,seenEntities:this.seenEntities}}has(i){return!!this.added[i]||!!this.removed[i]||!!this.updated[i]||!!this.affected[i]}hasAdded(i){return!!this.added[i]}hasUpdated(i){return!!this.updated[i]}hasRemoved(i){return!!this.removed[i]}hasAffected(i){return!!this.affected[i]}}function Mbi(l){return new Set([...Object.keys(l.added),...Object.keys(l.updated),...Object.keys(l.removed),...Array.from(l.affected)])}function u_(l,p,i){var f;const r=new Date().toISOString(),a=new S(i,N.sessionAuthor,r,i);if(a.lockedVersions=!0,l===p)throw z.Logger.error("From: ",l),z.Logger.error("To: ",p),new Error("Cannot generate transitional change set between the same two versions or change-sets");let c;if(l==="initial"?c=!0:p==="initial"?c=!1:B(l.timestamp).isBefore(B(p.timestamp))?c=!0:c=!1,z.Logger.log("Transitioning from ",l==="initial"?"initial":l.index),z.Logger.log("Transitioning to ",p==="initial"?"initial":p.index),z.Logger.log("Is forward: ",c),c){const m=p.index,E=l==="initial"?0:l.index;z.Logger.log("ownIndex: ",m),z.Logger.log("startIndex: ",E);const b=m===E?[i.history[m]]:i.history.slice(E+1,m+1);if(b.sort((g,_)=>B(g.timestamp).isAfter(B(_.timestamp))?1:-1),!b.length)throw new Error("No change sets in the history between the history indexes provided");z.Logger.log("REDO change-set: ",b[0].id," ",b[0].timestamp),b.forEach(g=>{p_(g,_=>{const P=i.instances[_.id]||i.deletedInstances[_.id];let x="";try{x=se(_,i)}catch{}if(!P)throw new Error(`Entity ${_.type} ${x?`"${x}" `:""}with id "${_.id}" doesn't have an 'activeVersion' set.`);if(!P.knownVersions)throw new Error(`Entity ${_.type} ${x?`"${x}" `:""}with id "${_.id}" has an active version instance missing the 'knownVersions' property value.`);if(!P.knownVersions.get(_.version))throw new Error(`Entity ${_.type} ${x?`"${x}" `:""}with id "${_.id}" has an active version instance missing the 'knownVersions' property value for version "${_.version}".`);P.restoreVersion(_.version),a.timestamp=P.createdAt,a.add(P,W.Added,{preventRecursion:!0})},_=>{const P=i.instances[_.id]||i.deletedInstances[_.id];let x="";try{x=se(_,i)}catch{}if(!P)throw new Error(`Entity ${_.type} ${x?`"${x}" `:""}with id "${_.id}" doesn't have an 'activeVersion' set.`);if(!P.knownVersions)throw new Error(`Entity ${_.type} ${x?`"${x}" `:""}with id "${_.id}" has an active version instance missing the 'knownVersions' property value.`);if(!P.knownVersions.get(_.version))throw new Error(`Entity ${_.type} ${x?`"${x}" `:""}with id "${_.id}" has an active version instance missing the 'knownVersions' property value for version "${_.version}".`);P.restoreVersion(_.version),a.timestamp=P.createdAt,a.add(P,W.Updated,{preventRecursion:!0})},_=>{const P=i.instances[_.id]||i.deletedInstances[_.id];let x="";try{x=se(_,i)}catch{}if(!P)throw new Error(`Entity ${_.type} ${x?`"${x}" `:""}with id "${_.id}" doesn't have an 'activeVersion' set.`);if(!P.knownVersions)throw new Error(`Entity ${_.type} ${x?`"${x}" `:""}with id "${_.id}" has an active version instance missing the 'knownVersions' property value.`);if(!P.knownVersions.get(_.version))throw new Error(`Entity ${_.type} ${x?`"${x}" `:""}with id "${_.id}" has an active version instance missing the 'knownVersions' property value for version "${_.version}".`);P.restoreVersion(_.version),a.timestamp=P.createdAt,a.add(P,W.Removed,{preventRecursion:!0})})})}else{const m=l.index,E=p==="initial"?0:p.index,b=m===E?[i.history[m]]:i.history.slice(E+1,m+1);if(b.sort((g,_)=>B(_.timestamp).isAfter(B(g.timestamp))?1:-1),!b.length)throw new Error("No change sets in the history between the history indexes provided");z.Logger.log("UNDO change-set: ",b[0].id," ",b[0].timestamp),b.forEach(g=>{p_(g,_=>{const P=i.instances[_.id]||i.deletedInstances[_.id];let x="";try{x=se(_,i)}catch{}if(!P)throw new Error(`Entity ${_.type} ${x?`"${x}" `:""}with id "${_.id}" doesn't have an 'activeVersion' set.`);if(!P.knownVersions)throw new Error(`Entity ${_.type} ${x?`"${x}" `:""}with id "${_.id}" has an active version instance missing the 'knownVersions' property value.`);if(!P.knownVersions.get(_.version))throw new Error(`Entity ${_.type} ${x?`"${x}" `:""}with id "${_.id}" has an active version instance missing the 'knownVersions' property value for version "${_.version}".`);_.previousVersion&&P.restoreVersion(_.previousVersion),a.timestamp=P.createdAt,a.add(P,W.Removed,{preventRecursion:!0})},_=>{const P=i.instances[_.id]||i.deletedInstances[_.id];let x="";try{x=se(_,i)}catch{}if(!P)throw new Error(`Entity ${_.type} ${x?`"${x}" `:""}with id "${_.id}" doesn't have an 'activeVersion' set.`);if(!P.knownVersions)throw new Error(`Entity ${_.type} ${x?`"${x}" `:""}with id "${_.id}" has an active version instance missing the 'knownVersions' property value.`);if(!P.knownVersions.get(_.version))throw new Error(`Entity ${_.type} ${x?`"${x}" `:""}with id "${_.id}" has an active version instance missing the 'knownVersions' property value for version "${_.version}".`);P.restoreVersion(_.previousVersion),a.timestamp=P.createdAt,a.add(P,W.Updated,{preventRecursion:!0})},_=>{const P=i.instances[_.id]||i.deletedInstances[_.id];let x="";try{x=se(_,i)}catch{}if(!P)throw new Error(`Entity ${_.type} ${x?`"${x}" `:""}with id "${_.id}" doesn't have an 'activeVersion' set.`);if(!P.knownVersions)throw new Error(`Entity ${_.type} ${x?`"${x}" `:""}with id "${_.id}" has an active version instance missing the 'knownVersions' property value.`);if(!P.knownVersions.get(_.version))throw new Error(`Entity ${_.type} ${x?`"${x}" `:""}with id "${_.id}" has an active version instance missing the 'knownVersions' property value for version "${_.version}".`);P.restoreVersion(_.previousVersion),a.timestamp=P.createdAt,a.add(P,W.Added,{preventRecursion:!0})})})}let e;if(p==="initial"){const h=Array.from(((f=i.knownVersions)==null?void 0:f.values())||[]).reduce((m,E)=>!m||B(E.createdAt).isBefore(B(m.createdAt))?E:m,null);if(!h)throw new Error("No oldest version found");e=h.createdAt}else e=p.timestamp;return a.open=!1,{transitionalChangeSet:a,transitionTime:r,timeOfOriginalTargetChanges:e}}function p_(l,p,i,r){var f;if(!(l!=null&&l.self))throw new Error("Change set must have a valid `self` entity state to be traversed");const a=((f=l.self)==null?void 0:f.type)===d.Project?l.self:l.self.project,c=new fn(l.self,{allBuiltInEntityIds:a.diggestedBuiltInBaseEntitiesIds});z.Logger.log("changeSet.added: ",Object.keys(l.added).length),z.Logger.log("changeSet.updated: ",Object.keys(l.updated).length),z.Logger.log("changeSet.removed: ",Object.keys(l.removed).length);const e={...l.added,...l.updated,...l.removed};c.order=Object.keys(e),c.flatRecord=e,c.orderEntities(),z.Logger.log("All entities: ",c.order.map((h,m)=>`${m+1}: ${e[h].type} - ${h}`).join(`,
7
7
  `)),z.Logger.log("Traversing new additions"),c.visit(async h=>{if(l.added[h.id])try{z.Logger.log("Adding: ",h.id),p(h)}catch(m){z.Logger.error("Error: ",m),z.Logger.error("Errored entity: ",h)}}),z.Logger.log("Traversing updates"),c.visit(async h=>{if(l.updated[h.id])try{z.Logger.log("Updating: ",h.id),i(h)}catch(m){z.Logger.error("Error: ",m),z.Logger.error("Errored entity: ",h)}}),z.Logger.log("Traversing removals"),c.visit(async(h,m)=>{if(l.removed[h.id])try{z.Logger.log("Removing: ",h.id),r(h)}catch(E){z.Logger.error("Error: ",E),z.Logger.error("Errored entity: ",h)}})}function c_(l,p,i){const r=l+1;return p.splice(r,p.length-r,i),p.length-1}function Gbi(l){[...l.listUpdated,...l.listAdded].forEach(p=>{const i=l.project.get(p.id);i.editable=!0})}function jbi(l){[...l.listUpdated,...l.listAdded].forEach(p=>{const i=l.project.get(p.id);i.deletable=!0})}function Ubi(l){[...l.listUpdated,...l.listAdded].forEach(p=>{const i=l.project.get(p.id);i.editable=!0,i.deletable=!0})}function kbi(l){[...l.listUpdated,...l.listAdded].forEach(p=>{const i=l.project.get(p.id);i.editable=!1})}function Fbi(l){[...l.listUpdated,...l.listAdded].forEach(p=>{const i=l.project.get(p.id);i.deletable=!1})}function Kbi(l){[...l.listUpdated,...l.listAdded].forEach(p=>{const i=l.project.get(p.id);i.editable=!1,i.deletable=!1})}function Sbi(l,p){p?l.metaSync({editable:!1,deletable:!1},p):(l.editable=!1,l.deletable=!1),ke(l,new Set,{ignoreBuiltInBaseEntities:!0}).forEach(r=>{p?r.metaSync({editable:!1,deletable:!1},p):(r.editable=!1,r.deletable=!1)})}function qbi(l,p){p?l.metaSync({editable:!0,deletable:!0},p):(l.editable=!0,l.deletable=!0),ke(l,new Set,{ignoreBuiltInBaseEntities:!0}).forEach(r=>{p?r.metaSync({editable:!0,deletable:!0},p):(r.editable=!0,r.deletable=!0)})}function Zbi(l){const{projectRecord:p,chain:i,projectId:r,sort:a,order:c}=l,e=a?(i||[]).sort((E,b)=>{const g=E.updated[r],_=b.updated[r];return B(g.createdAt).valueOf()-B(_.createdAt).valueOf()}):i||[],f={...p};e.forEach(E=>{Object.values(E.removed).forEach(g=>{delete f[g.id]}),Object.values(E.added).forEach(g=>{f[g.id]=g}),Object.values(E.updated).forEach(g=>{f[g.id]=g});const b=E.updated[r];f[r]=b});let h=null;if(c){const E=new fn;E.flatRecord=f,E.orderEntities(),h=E.order}return{project:f[r],record:f,order:h}}class px{constructor(p){R(this,"version");R(this,"previousVersion");R(this,"createdAt");R(this,"deleted",!1);R(this,"author");this.version=p.version,this.previousVersion=p.previousVersion,this.createdAt=B(p.createdAt).toISOString(),this.deleted=p.deleted,this.author=p.author}baseMetaSync(p,i,r){this.deleted=p.deleted!==void 0?p.deleted:this.deleted}}class tn extends px{constructor(i){super(i);R(this,"deletable",!0);R(this,"editable",!0);this.deletable=i.deletable,this.editable=i.editable}checkCanEditWithCounterpartAndSideEffects(i,r,a,c){var e,f;return!this.checkCanEdit(i,c)||!this.checkCanEdit(r,c)?(this.checkCanEdit(r,c)?(z.Logger.warn(`[${a}] User is not allowed to edit this ${i.type} entity with id: ${i.id}`),c==null||c.event({id:`${a}-${i.id}--${r.id}--${Me.ActionOwnerEntityNotEditable}`,action:a,owner:i,counterpart:r,errorReason:Me.ActionOwnerEntityNotEditable,rootAction:((f=c==null?void 0:c.self)==null?void 0:f.id)===i.id&&(c==null?void 0:c.autoCloseActionName)===a})):(z.Logger.warn(`[${a}] User is not allowed to edit this ${i.type} entity with id: ${i.id} because its counterpart ${r.type} with id: ${r.id} is not editable`),c==null||c.event({id:`${a}-${i.id}--${r.id}--${Me.ActionCounterpartEntityNotEditable}`,action:a,owner:i,counterpart:r,errorReason:Me.ActionCounterpartEntityNotEditable,rootAction:((e=c==null?void 0:c.self)==null?void 0:e.id)===i.id&&(c==null?void 0:c.autoCloseActionName)===a})),c==null||c.attemptAutoclose(a,i.id),!1):!0}checkCanEditFromScopeOwner(i,r){const a=St(i,i.project);return a?this.checkCanEdit(a,r):!0}checkCanEditFromScopeOwnerWithSideEffects(i,r,a){var e;const c=this.checkCanEditFromScopeOwner(i,a);return!c&&!(a!=null&&a.ignoreNonEditable)&&(z.Logger.warn(`[${r}] User is not allowed to edit this ${i.type} entity with id: ${i.id}`),a==null||a.event({id:`${r}-${i.id}--${Me.ActionOwnerEntityNotEditable}`,action:r,owner:i,errorReason:Me.ActionOwnerEntityNotEditable,rootAction:((e=a==null?void 0:a.self)==null?void 0:e.id)===i.id&&(a==null?void 0:a.autoCloseActionName)===r}),a==null||a.attemptAutoclose(r,i.id)),c}checkCanEdit(i,r){var a;return(a=i.project)!=null&&a.initialized?i.type===d.BuiltInBaseEntity||i.type===d.PrimitiveEntity?!1:i.initialized?!(i.project.diggestedBuiltInBaseEntitiesIds.has(i.id)||i.parent&&!(this.checkCanEdit(i.parent,r)&&i.editable)&&!(r!=null&&r.ignoreNonEditable)||!i.editable&&!(r!=null&&r.ignoreNonEditable)):!0:!0}checkCanDelete(i,r){var a;return i.type!==d.Project&&i.project.diggestedBuiltInBaseEntitiesIds.has(i.id)?!1:i.type===d.Project||(a=i.parent)!=null&&a.deleted?!0:!(!i.deletable&&!(r!=null&&r.ignoreNonDeletable))}baseMetaSync(i,r,a){this.deletable=i.deletable!==void 0?i.deletable:this.deletable,this.editable=i.editable!==void 0?i.editable:this.editable;const c={...i,deleted:this.checkCanDelete(r,a)?i.deleted:!1};super.baseMetaSync(c,r,a)}}var GOe=(l=>(l.ArgumentDataTypeEntityField="data-type-entity-field",l.ArgumentDataTypeField="data-type-field",l.ArgumentImplementsField="argument-implements-field",l))(GOe||{});const Ai=class Ai extends tn{constructor(i,r){super(i);R(this,"initialData");R(this,"id");R(this,"name");R(this,"codeName",null);R(this,"description",null);R(this,"index");R(this,"required");R(this,"constant",!0);R(this,"type",d.ArgumentDeclaration);R(this,"defaultValue",null);R(this,"dataType",null);R(this,"writesValues",[]);R(this,"implements",[]);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,this.description=i.description,this.codeName=i.codeName,this.required=i.required,this.constant=!0}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.ArgumentDeclaration,name:"",codeName:null,description:"",index:0,required:!1,constant:!0,implements:[],dataType:null,defaultValue:null,writesValues:[],parent:null}}static fromGenerationTarget(i,r,a){const c=a===void 0?r.addChangeSet(new S(r,N.sessionAuthor,B().toISOString(),r,!0,w.CreateFromGenerationTarget)):a,e=X(i.parent),f=r.get(e),h={id:i.id,version:N.UUID.uuid(),createdAt:(c==null?void 0:c.timestamp)||B().toISOString(),author:(c==null?void 0:c.author)||N.sessionAuthor,previousVersion:null,deleted:!1,name:i.name,deletable:!0,editable:!0,type:d.ArgumentDeclaration,index:f.inputs.length,defaultValue:null,codeName:i.codeName||null,description:i.description||null,required:i.required??!1,constant:!0,implements:[],dataType:null,writesValues:[],parent:f.toReference()},m=Ae(h,r);return m.hydrateAncestors(),m.setParent(f,c),m.addSelfToProject(c),c==null||c.add(m,W.Added),m.initChildren(c),m}static validateGenerationTarget(i,r){let a=JSON.parse(JSON.stringify(i));const c=[],e=[],f=On(a,{parent:{list:!1,types:[d.FunctionDeclaration,d.Search,d.Condition]}},r);c.push(...f.explanations),a=f.modifiedData;const h=dx(a,r);if(a.parent){const E=r.get(X(a.parent));if(E&&Ft.includes(E.type)){const b=E.implements;if(b){const g=b.inputs.find(M=>M.name===a.name),_=b.inputs.filter(M=>!E.inputs.find(ie=>ie.type===d.ArgumentDeclaration&&ie.name===M.name)),P=E.inputs.filter(M=>M.type===d.ArgumentDeclaration),x=P.find(M=>M.name===a.name),j=P.length?`The parent entity already implements the following arguments: ${Et(P.map(M=>`'${M.id}' (${M.name})`),", "," and ")}.`:"The parent entity does not yet have any implemented arguments.",G=_.length?`The parent entity is still missing the following arguments in the implementation: ${Et(_.map(M=>`'${M.id}' (${M.name})`),", "," and ")}.`:"The parent entity has all the arguments it needs implemented.";g?x&&e.push(new Re({id:`${a.id}--${we.NoOverlapWithImplementedSignature}`,code:we.NoOverlapWithImplementedSignature,severity:Te.Error,message:`Entity of type '${d.ArgumentDeclaration}' with id '${a.id}' should not exist in a parent entity of type '${E.type}' with id '${E.id}' that implements a ${d.ActionDescriptor} with fixed arguments.
8
8
  Adding a new argument would make the implementation invalid. An argument with the same name already exists in the parent entity.
9
9
  ${j}
@@ -107,7 +107,7 @@ The parent ${h.type} has a data-type that references an entity with `;H.length?i
107
107
  The entity is ${ei(G,{nested:!1}).lines[0].text}.`,ie+="Technically, an implemented variable-declaration or variable-instance will be generated with all ",e.push(new Re({id:`${a.id}--${we.NoOverlapWithImplementedSignature}`,code:we.NoOverlapWithImplementedSignature,severity:Te.Error,message:`Entity of type '${d.InputMap}' with id '${a.id}' cannot be added to the parent entity of type '${h.type}' with id '${h.id}'. The 'declaration' with '${m.id}' of the 'input-map' does not exist in 'entity' field implemented the parent ${h.type}'s 'data-type'.${ie}`}))}}else if(Vt.filter(P=>Pt.includes(P)).includes(h.type)){const x=rL(h),j=x.find(M=>M.id===a.declaration),G=`The parent entity has the following argument declarations that can be referenced by input-maps, ids: '${Et(x.map(M=>M.id),"', '","' and '")}'`;j||e.push(new Re({id:`${a.id}--${we.NoOverlapWithImplementedSignature}`,code:we.NoOverlapWithImplementedSignature,severity:Te.Error,message:`Entity of type '${d.InputMap}' with id '${a.id}' cannot be added to the parent entity of type '${h.type}' with id '${h.id}'. The parent entity does not have an 'argument-declaration' with id '${a.declaration}'.
108
108
  You can't add an input-map to an entity that doesn't have a matching 'argument-declaration'.
109
109
  ${G}`}))}}const b=Hr(a);return e.push(...f.errors,...b.errors),c.push(...b.explanations),{errors:e,explanations:c,modifiedData:a}}get codeNativeValueValidation(){var i;return this._codeNativeValueValidation||((i=this.declaration)==null?void 0:i.codeNativeValueValidation)||null}validateGeneratedUpdate(i){const r=[],a=[];let c=JSON.parse(JSON.stringify(i));const e=qf(c,this);return c=e.modifiedData,r.push(...e.errors),c.parent&&r.push(new Re({id:`${this.id}--${fe.InvalidParentUpdate}`,code:fe.InvalidParentUpdate,severity:Te.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.
110
- 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:c}}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 S(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:C(r),added:C(a),removed:C(c),affected:C(e),self:this}}onDetachedDependencyRemoved(i,r,a){const c=[],e=[],f=[],h=[];if(r==="declaration"){const{updated:m,added:E,removed:b}=this.remove({ignoreUpstream:!1},a);c.push(...m),e.push(...E),f.push(...b)}return{updated:C(c),added:C(e),removed:C(f),affected:C(h),self:this}}onDetachedDependencyRestored(i,r,a){const c=[],e=[],f=[],h=[];if(r==="declaration"){const{updated:m,added:E,removed:b}=this.restore({},a);c.push(...m),e.push(...E),f.push(...b)}return{updated:C(c),added:C(e),removed:C(f),affected:C(h),self:this}}unsubscribeFromDependencies(){var i,r,a,c,e;return(r=(i=this.declaration)==null?void 0:i.unsubscribeDependents)==null||r.call(i,[{entity:this,field:"declaration"}]),(e=(c=(a=this.dataType)==null?void 0:a.entity)==null?void 0:c.unsubscribeDependents)==null||e.call(c,[{entity:this,field:"data-type-entity"}]),this}subscribeToDependencies(){var i,r,a,c,e;return(r=(i=this.declaration)==null?void 0:i.subscribeDependents)==null||r.call(i,[{entity:this,field:"declaration"}]),(e=(c=(a=this.dataType)==null?void 0:a.entity)==null?void 0:c.subscribeDependents)==null||e.call(c,[{entity:this,field:"data-type-entity"}]),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 Oi(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.declaration=this.declaration,i.defaultValue=this.defaultValue,i.readsValue=this.readsValue,i.dataType=this.dataType,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:C(r),added:C(a),removed:C(c),affected:C(e),self:this}}async restoreVersion(i){var h;const r=[],a=[],c=[],e=[];if(this.version===i)return{updated:C(r),added:C(a),removed:C(c),affected:C(e),self:this};if(!this.knownVersions){const m=new Map;for(const[E,b]of this.knownVersions||new Map){if(m.set(E,b),b.activeVersion=!1,b.knownVersions)for(const[g,_]of b.knownVersions)m.set(g,_);b.knownVersions=null}}let f=(h=this.knownVersions)==null?void 0:h.get(i);if(!f){const m=await this.APILoadVersion({},i);if(!m)throw new Error(`Version with id '${i}' for entity with id '${this.id}' not found.`);f=new Oi(m,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.declaration=f.declaration,this.defaultValue=f.defaultValue,this.readsValue=f.readsValue,this.dataType=f.dataType,this.parent=f.parent,{updated:C(r),added:C(a),removed:C(c),affected:C(e),self:this}}updateWithShallowTransfer(i,r=this.project.addChangeSet(new S(this.project,N.sessionAuthor,B().toISOString(),this,!0,w.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(w.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(w.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(w.UpdateWithShallowTransfer,this.id),new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(i.readsValue){const a=X(i.readsValue),c=this.project.get(a),e=this.readsValue;e&&e.id!==(c==null?void 0:c.id)&&this.removeValueWriter(r),c&&this.setValueWriter(c,r)}else this.removeValueWriter(r);if(i.declaration){const a=X(i.declaration),c=this.project.get(a);c&&this.setDeclaration(c,r)}else this.setDeclaration(null,r);if(i.dataType){const a=X(i.dataType),c=this.project.get(a);c&&this.setDataType(c,r)}else this.setDataType(null,r);if(i.defaultValue){const a=X(i.defaultValue),c=this.project.get(a);c&&this.setDefaultValue(c,r)}else this.setDefaultValue(null,r);return this.captureVersion(),this.subscribeToDependencies(),r==null||r.attemptAutoclose(w.UpdateWithShallowTransfer,this.id),this}updateWithGenerationTarget(i,r=this.project.addChangeSet(new S(this.project,N.sessionAuthor,B().toISOString(),this,!0,w.UpdateWithGenerationTarget))){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(w.UpdateWithGenerationTarget,this.id),this;if(this.metaSync(i,r),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(w.UpdateWithGenerationTarget,this.id),new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${a}' that isn't found in the project`)}if(i.readsValue){const a=X(i.readsValue),c=this.project.get(a),e=this.readsValue;if(e&&e.id!==(c==null?void 0:c.id)&&this.removeValueWriter(r),c)this.setValueWriter(c,r);else throw new Error(`${this.type} with id '${this.id}' has a 'readsValue' reference '${a}' that isn't found in the project`)}else i.readsValue===null&&this.removeValueWriter(r);if(i.declaration){const a=X(i.declaration),c=this.project.get(a);if(c)this.setDeclaration(c,r);else throw new Error(`${this.type} with id '${this.id}' has a 'declaration' reference '${a}' that isn't found in the project`)}else i.declaration===null&&this.setDeclaration(null,r);return this.captureVersion(),this.subscribeToDependencies(),r==null||r.attemptAutoclose(w.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.readsValue){const e=X(this.initialData.readsValue),f=this.project.get(e);f&&(this.setValueWriter(f,null),i.push(f))}if(this.initialData.declaration){const e=X(this.initialData.declaration),f=this.project.get(e);f&&(this.setDeclaration(f,null),i.push(f))}return{updated:C(i),added:C(r),removed:C(a),affected:C(c),self:this}}afterAllChildrenInitialized(i=this.project.addChangeSet(new S(this.project,N.sessionAuthor,B().toISOString(),this,!0,w.AfterAllChildrenInitialized))){var b,g;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(w.AfterAllChildrenInitialized,this.id),{updated:[],added:[],removed:[],affected:[],self:this};const r=[],a=[],c=[],e=[];this.initialized=!0;let f=this.index||0;const h=(Dt.includes(this.parent.type)?this.parent.outputs:this.parent.inputs).filter(_=>!_.deleted&&_.id!==this.id);h.length&&(f>h.length+1?f=h.length:f<0&&(f=0)),h.find(_=>(_.index||0)===f&&!_.deleted)&&h.filter(_=>(_.index||0)>=f&&!_.deleted).forEach(_=>{_.metaSync({index:(_.index||0)+1},i),i==null||i.add(_,W.Updated),r.push(_)});const E=this.parent.type===d.VariableInstance&&((b=this.declaration)==null?void 0:b.type)===d.Property&&((g=this.declaration)==null?void 0:g.constant);if(E&&this.readsValue&&(this.readsValue.removeValueReader(this,i),this.removeValueWriter(i)),E&&this.defaultValue&&this.defaultValue.remove({ignoreUpstream:!1},i),this.readsValue&&this.defaultValue&&(this.project.diggestedBuiltInBaseEntitiesIds.has(this.defaultValue.id)||this.defaultValue.remove({ignoreUpstream:!1},i),this.setDefaultValue(null,i)),this.defaultValue&&!this.readsValue&&!this.project.diggestedBuiltInBaseEntitiesIds.has(this.id)&&this.project.diggestedBuiltInBaseEntitiesIds.has(this.defaultValue.id)){const _=this.defaultValue.clone(i,this);this.setDefaultValue(_,i)}return this.metaSync({index:f},i),this.captureVersion(),i==null||i.attemptAutoclose(w.AfterAllChildrenInitialized,this.id),{updated:C(r),added:C(a),removed:C(c),affected:C(e),self:this}}addSelfToProject(i=this.project.addChangeSet(new S(this.project,N.sessionAuthor,B().toISOString(),this,!0,"add-self-to-project"))){var f;const r=[this],a=[],c=[],e=[];return Dt.includes(this.parent.type)?this.parentRelationType===Wo.Error?this.parent.setThrows(this,i):this.parent.addOutput(this,i):this.parent.addInput(this,i),e.push(this.parent),(f=this.readsValue)==null||f.addValueReader(this,i),this.readsValue&&r.push(this.readsValue),this.subscribe(),this.subscribeToDependencies(),i==null||i.attemptAutoclose("add-self-to-project",this.id),{updated:C(r),added:C(a),removed:C(c),affected:C(e),self:this}}setParent(i,r=this.project.addChangeSet(new S(this.project,N.sessionAuthor,B().toISOString(),this,!0,w.SetParent))){var a;return this.checkCanEditWithCounterpartAndSideEffects(this,i,w.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(w.SetParent,this.id),this):this}setDataType(i,r=this.project.addChangeSet(new S(this.project,N.sessionAuthor,B().toISOString(),this,!0,w.SetDataType))){if(!this.checkCanEdit(this,r))return z.Logger.warn(`[setDataType] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),r==null||r.attemptAutoclose(w.SetDataType,this.id),this;const a=this.dataType;return(a==null?void 0:a.id)!==(i==null?void 0:i.id)&&(a==null||a.remove({ignoreUpstream:!0},r),this.dataType=i,this.subscribeToDependencies(),r==null||r.add(this,W.Affected)),r==null||r.attemptAutoclose(w.SetDataType,this.id),this}removeDataType(i=this.project.addChangeSet(new S(this.project,N.sessionAuthor,B().toISOString(),this,!0,w.RemoveDataType))){return this.checkCanEdit(this,i)?(this.dataType&&(this.dataType.remove({ignoreUpstream:!0},i),i==null||i.add(this,W.Affected),this.dataType=null),i==null||i.attemptAutoclose(w.RemoveDataType,this.id),this):(z.Logger.warn(`[removeDataType] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(w.RemoveDataType,this.id),this)}setDeclaration(i,r=this.project.addChangeSet(new S(this.project,N.sessionAuthor,B().toISOString(),this,!0,"set-declaration"))){var a;return((a=this.declaration)==null?void 0:a.id)!==(i==null?void 0:i.id)&&(this.declaration=i,this.subscribeToDependencies(),r&&(r==null||r.add(this,W.Updated))),r==null||r.attemptAutoclose("set-declaration",this.id),this}initChildren(i=this.project.addChangeSet(new S(this.project,N.sessionAuthor,B().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.initialData.defaultValue&&(this.defaultValue=Ae(this.initialData.defaultValue,this.project),this.defaultValue.setParent(this,null),this.defaultValue.initChildren(i)),this.initialData.declaration&&(this.declaration=Ae(this.initialData.declaration,this.project)),Zf.initReadsValue(this),this.subscribeToDependencies(),this.afterAllChildrenInitialized(i),i==null||i.attemptAutoclose("init-children",this.id),this)}setValueWriter(i,r=this.project.addChangeSet(new S(this.project,N.sessionAuthor,B().toISOString(),this,!0,w.SetValueWriter))){var c,e,f,h,m,E;return this.checkCanEditFromScopeOwnerWithSideEffects(this,w.SetValueWriter,r)?((i==null?void 0:i.id)===this.id&&(r==null||r.event({id:`${w.SetValueWriter}-${this.id}`,action:w.SetValueWriter,owner:this,errorReason:Me.CannotValueWriteItself,rootAction:((c=r==null?void 0:r.self)==null?void 0:c.id)===this.id&&(r==null?void 0:r.autoCloseActionName)===w.SetValueWriter})),this.parent.type===d.VariableInstance&&((e=this.declaration)==null?void 0:e.type)===d.Property&&((f=this.declaration)==null?void 0:f.constant)&&i?(r==null||r.event({id:`${w.SetValueWriter}-${this.id}--${i.id}`,action:w.SetValueWriter,owner:this,counterpart:i,errorReason:Me.ValueReadingOverridesConstantVariable,rootAction:((h=r==null?void 0:r.self)==null?void 0:h.id)===this.id&&(r==null?void 0:r.autoCloseActionName)===w.SetValueWriter}),r==null||r.attemptAutoclose(w.SetValueWriter,this.id),this):(((m=this.readsValue)==null?void 0:m.id)!==(i==null?void 0:i.id)&&(this.readsValue=i,this.readsValue&&((E=this.defaultValue)==null||E.remove({ignoreUpstream:!1},r)),r==null||r.add(this,W.Updated)),r==null||r.attemptAutoclose(w.SetValueWriter,this.id),this)):this}removeValueWriter(i=this.project.addChangeSet(new S(this.project,N.sessionAuthor,B().toISOString(),this,!0,w.RemoveValueWriter))){return this.readsValue&&!this.checkCanEditWithCounterpartAndSideEffects(this,this.readsValue,w.RemoveValueWriter,i)?this:(this.readsValue&&(this.readsValue=null,i==null||i.add(this,W.Updated)),i==null||i.attemptAutoclose(w.RemoveValueWriter,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 S(this.project,N.sessionAuthor,B().toISOString(),this,!0,"meta-sync"))){const a=zr(this,i,r),c=Wr(this,a),e=this.toMeta();return this.index=a.index||(a.index!==0?e.index:0),this.name=a.name!==void 0?a.name:e.name,this.codeName=a.codeName!==void 0?a.codeName:e.codeName,this.description=a.description!==void 0?a.description:e.description,this.parentRelationType=a.parentRelationType!==void 0?a.parentRelationType:this.parentRelationType,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=Se,...r){return await Oi.repository.APILoad(this.id,...r),this}async APICreate(i=Se,...r){return await Oi.repository.APICreate(this.toShallowJSON(),...r),this}async APIUpdate(i=Se,...r){return await Oi.repository.APIUpdate(this.toShallowJSON(),...r),this}async APIDelete(i=Se,...r){return await Oi.repository.APIDelete(this.toShallowJSON(),...r),this}async APIClone(i=Se,...r){return await Oi.repository.APIClone(this.id,...r),this}async APILoadVersion(i=Se,r,...a){return await Oi.repository.APILoadVersion(this.id,r,...a)}removeFromParent(i=this.project.addChangeSet(new S(this.project,N.sessionAuthor,B().toISOString(),this,!0,w.RemoveFromParent))){var f;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(w.RemoveFromParent,this.id),{added:[],updated:[],removed:[],affected:[],self:this};const r=[],a=[],c=[],e=[];return Dt.includes((f=this.parent)==null?void 0:f.type)?this.parentRelationType===Wo.Error?(this.parent.setThrows(null,i),e.push(this.parent)):(this.parent.removeOutput(this,i),e.push(this.parent)):(this.parent.removeInput(this,i),e.push(this.parent)),i==null||i.attemptAutoclose(w.RemoveFromParent,this.id),{added:C(c),updated:C(r),removed:C(a),affected:C(e),self:this}}remove({ignoreUpstream:i}={ignoreUpstream:!1},r=this.project.addChangeSet(new S(this.project,N.sessionAuthor,B().toISOString(),this,!0,w.RemoveEntity))){var h,m,E,b,g;if(this.deleted)return r==null||r.attemptAutoclose(w.RemoveEntity,this.id),{added:[],updated:[],removed:[],affected:[],self:this};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:`${w.RemoveEntity}-${this.id}--${Me.ActionOwnerEntityNonDeletable}`,action:w.RemoveEntity,owner:this,errorReason:Me.ActionOwnerEntityNonDeletable,rootAction:((h=r==null?void 0:r.self)==null?void 0:h.id)===this.id&&(r==null?void 0:r.autoCloseActionName)===w.RemoveEntity}),r==null||r.attemptAutoclose(w.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(w.RemoveEntity,this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(c.push(this),this.unsubscribe(),this.unsubscribeFromDependencies(),this.metaSync({deleted:!0},r),r!=null&&r.hasAdded(this.id)||this.project.subscribeDeletedInstance(this),Object.values(this.detachedDependents).forEach(_=>{const{updated:P,removed:x,added:j}=_.entity.onDetachedDependencyRemoved(this,_.field,r);a.push(...P),c.push(...x),e.push(...j)}),this.defaultValue){const{updated:_,removed:P}=this.defaultValue.remove({ignoreUpstream:!0},r);a.push(..._),c.push(...P)}if(this.readsValue&&(a.push(this.readsValue),this.readsValue.removeValueReader(this,r)),this.defaultValue&&(a.push(this.defaultValue),this.defaultValue.remove({ignoreUpstream:!0},r)),this.declaration){if(this.declaration.type===d.Property&&((m=this.declaration.parent)==null?void 0:m.type)===d.DefinitionEntity&&((b=(E=this.declaration.parent)==null?void 0:E.parent)==null?void 0:b.type)===d.DataType&&!(r!=null&&r.hasRemoved(this.declaration.id))&&!this.declaration.deleted){const{updated:_,removed:P}=this.declaration.remove({ignoreUpstream:!1},r);a.push(..._),c.push(...P)}else if(this.declaration.type===d.ValueDescriptor&&((g=this.declaration.parent)==null?void 0:g.type)===d.Search&&!(r!=null&&r.hasRemoved(this.declaration.id))&&!this.declaration.deleted){const{updated:_,removed:P}=this.declaration.remove({ignoreUpstream:!1},r);a.push(..._),c.push(...P)}}if(!i){const _=this.removeFromParent(r);e.push(..._.added),a.push(..._.updated),c.push(..._.removed),f.push(..._.affected)}if(!i&&this.parent&&[d.BreakStatement,d.ContinueStatement].includes(this.parent.type)&&this.parent.parent&&this.parent.parent.type===d.Loop&&this.parent.initialized&&this.parent.parent.syncFromDataType(r),this.parentRelationType===Wo.Error&&this.parent.type===d.ReturnStatement){const{updated:_,added:P,removed:x,affected:j}=this.parent.syncInputs(r);a.push(..._),e.push(...P),c.push(...x),f.push(...j)}return r==null||r.attemptAutoclose(w.RemoveEntity,this.id),{added:C(e),updated:C(a),removed:C(c),affected:C(f),self:this}}restore({}={},i=this.project.addChangeSet(new S(this.project,N.sessionAuthor,B().toISOString(),this,!0,w.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(w.RestoreEntity,this.id),{added:[],updated:[],removed:[],affected:[],self:this};const r=[],a=[],c=[],e=[];if(i!=null&&i.hasAdded(this.id))return i==null||i.attemptAutoclose(w.RestoreEntity,this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},i),Object.values(this.detachedDependents).forEach(f=>{const{updated:h,removed:m,added:E}=f.entity.onDetachedDependencyRestored(this,f.field,i);a.push(...h),c.push(...m),r.push(...E)}),this.defaultValue){const{updated:f}=this.defaultValue.restore({},i);a.push(...f)}return this.readsValue&&(a.push(this.readsValue),this.readsValue.addValueReader(this,i)),this.defaultValue&&(a.push(this.defaultValue),this.defaultValue.restore({},i)),e.push(this.parent),this.parent.addInput(this,i),i==null||i.attemptAutoclose(w.RestoreEntity,this.id),{added:C(r),updated:C(a),removed:C(c),affected:C(e),self:this}}toFlat(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this,...this.defaultValue?this.defaultValue.toFlat(i):[],...this.dataType?this.dataType.toFlat(i):[],...this.declaration?this.declaration.toFlat(i):[],...this.readsValue?this.readsValue.toFlat(i):[]])}toFlatIds(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.id,...this.defaultValue?this.defaultValue.toFlatIds(i):[],...this.dataType?this.dataType.toFlatIds(i):[],...this.declaration?this.declaration.toFlatIds(i):[],...this.readsValue?this.readsValue.toFlatIds(i):[]])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,codeName:this.codeName,description:this.description,parentRelationType:this.parentRelationType,index:this.index,type:this.type,editable:this.editable,deletable:this.deletable,name:this.name}}toJSON(i=new Set){var r,a,c,e;return i.has(this.id)?this.toReference():(i.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,editable:this.editable,deletable:this.deletable,index:this.index,name:this.name,codeName:this.codeName,description:this.description,parentRelationType:this.parentRelationType,defaultValue:((r=this.defaultValue)==null?void 0:r.toJSON(i))||null,dataType:((a=this.dataType)==null?void 0:a.toJSON(i))||null,declaration:((c=this.declaration)==null?void 0:c.toJSON(i))||null,readsValue:((e=this.readsValue)==null?void 0:e.toReference())||null,parent:this.parent.toReference()})}toJSONClone(i=nt){var a,c,e,f,h,m,E,b,g,_,P,x;let r;return(a=i.seenEntityMaps)!=null&&a.has(this.id)?r=i.seenEntityMaps.get(this.id):(r=i.newId||en(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,type:this.type,editable:this.editable,deletable:this.deletable,index:this.index,name:this.name,codeName:this.codeName,description:this.description,parentRelationType:this.parentRelationType,defaultValue:((m=this.defaultValue)==null?void 0:m.toJSONClone({...i,newId:null}))||null,dataType:((E=this.dataType)==null?void 0:E.toJSONClone({...i,newId:null}))||null,declaration:(b=this.declaration)!=null&&b.id&&this.project.getBuiltIn((g=this.declaration)==null?void 0:g.id)?(_=this.declaration)==null?void 0:_.toJSON(i.seenEntities):((P=this.declaration)==null?void 0:P.toJSONClone({...i,newId:null}))||null,readsValue:((x=this.readsValue)==null?void 0:x.toReference({seenEntityMaps:i.seenEntityMaps}))||null,parent:this.parent.toReference({seenEntityMaps:i.seenEntityMaps})})}toReference(i=nt){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=nt){var a,c,e,f,h;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,type:this.type,editable:this.editable,deletable:this.deletable,name:this.name,codeName:this.codeName,description:this.description,parentRelationType:this.parentRelationType,index:this.index,dataType:((c=this.dataType)==null?void 0:c.toReference(i))||null,defaultValue:((e=this.defaultValue)==null?void 0:e.toReference(i))||null,declaration:((f=this.declaration)==null?void 0:f.toReference(i))||null,readsValue:((h=this.readsValue)==null?void 0:h.toReference(i))||null,parent:this.parent.toReference(i)}}toFlatJSON(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.toShallowJSON(),...this.defaultValue?this.defaultValue.toFlatJSON(i):[],...this.dataType?this.dataType.toFlatJSON(i):[],...this.declaration?this.declaration.toFlatJSON(i):[],...this.readsValue?this.readsValue.toFlatJSON(i):[]])}toGenerationTarget(i=nt){var a,c;let r=this.id;return(a=i.seenEntityMaps)!=null&&a.has(this.id)&&(r=i.seenEntityMaps.get(this.id)),{id:r,name:this.name||void 0,description:this.description||void 0,type:this.type,declaration:((c=this.declaration)==null?void 0:c.id)||null,parent:this.parent.id}}toFlatGenerationTarget(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.toGenerationTarget(),...this.defaultValue?this.defaultValue.toFlatGenerationTarget(i):[],...this.dataType?this.dataType.toFlatGenerationTarget(i):[],...this.readsValue?this.readsValue.toFlatGenerationTarget(i):[],...this.declaration?this.declaration.toFlatGenerationTarget(i):[]])}clearErrors(){var i;return this.errors=[],(i=this.defaultValue)==null||i.clearErrors(),this}validate(){return this.errors=UBe(this),{success:!0}}async validateAsync(i={}){const r=z.YieldTracker.from(i);return this.errors=await jBe(this,{tracker:r}),{success:!0}}getErrors(){var r;return[...this.errors,...((r=this.defaultValue)==null?void 0:r.getErrors())||[]]}async getErrorsAsync(i={}){var e;const r=z.YieldTracker.from(i),a=[...this.errors];await r.tick();const c=await((e=this.defaultValue)==null?void 0:e.getErrorsAsync({tracker:r}));return c&&a.push(...c),a}getShallowErrors(){return this.errors}getDefaultValue(){var i;return this.defaultValue||((i=this.declaration)==null?void 0:i.getDefaultValue())||null}setDefaultValue(i,r=this.project.addChangeSet(new S(this.project,N.sessionAuthor,B().toISOString(),this,!0,"set-default-value"))){if(!this.checkCanEdit(this,r))return z.Logger.warn(`[setDefaultValue] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),r==null||r.attemptAutoclose("set-default-value",this.id),this;const a=this.defaultValue;if((a==null?void 0:a.id)!==(i==null?void 0:i.id)){if(a==null||a.remove({ignoreUpstream:!0},r),this.defaultValue=i,this.defaultValue){const c=this.readsValue;this.removeValueWriter(r),c==null||c.removeValueReader(this,r)}r==null||r.add(this,W.Affected)}return r==null||r.attemptAutoclose("set-default-value",this.id),this}clone(i=this.project.addChangeSet(new S(this.project,N.sessionAuthor,B().toISOString(),this,!0,w.CloneEntity)),r=null,a=null,c=!0){var b;const e=Mr(r,this),f=this.toJSON(),h=a||N.UUID.uuid();f.defaultValue=null,f.id=h,f.version=N.UUID.uuid(),f.createdAt=(i==null?void 0:i.timestamp)||B().toISOString(),f.author=(i==null?void 0:i.author)||"1",f.previousVersion=null,f.deleted=!1,f.deletable=!0,f.editable=!0;const m=tr(f,e);m.hydrateAncestors(),r&&m.setParent(r,i),c&&(m.subscribe(),m.addSelfToProject(i)),m.initChildren(i),i==null||i.add(m,W.Added);const E=(b=this.defaultValue)==null?void 0:b.clone(i,m,N.UUID.uuid(),c);return m.defaultValue=E||null,i==null||i.attemptAutoclose(w.CloneEntity,this.id),m}getDataType(i=this.project.addChangeSet(new S(this.project,N.sessionAuthor,B().toISOString(),this,!0,"get-data-type"))){var a;if(this.parent.type===d.Operation){const c=this.parent.declaration.inferInputMapDataType(this,i);return i==null||i.attemptAutoclose("get-data-type",this.id),c.self}else Pt.includes(this.parent.type)&&Tr(this.parent).getDataType(i);const r=(a=this.declaration)==null?void 0:a.getDataType(i);if(!r){const c=Ud(this,i);if(c)return i==null||i.attemptAutoclose("get-data-type",this.id),c}return i==null||i.attemptAutoclose("get-data-type",this.id),r||null}getCounterparts(){let i=[];if([d.BreakStatement,d.ContinueStatement].includes(this.parent.type)){const r=this.parent.parent;i=[...r.breakStatements,...r.continueStatements].flatMap(e=>e.outputs).filter(e=>se(e,this.project)===se(this,this.project)&&e.id!==this.id)}else if(this.parent.type===d.ReturnStatement&&[d.FunctionDeclaration,d.GlobalEvent].includes(this.parent.parent.type)&&this.parent.parent.implements){const a=this.parent.parent.returnStatements.flatMap(c=>c.outputs);this.declaration?i=a.filter(e=>{var f;return this.declaration.id===((f=e.declaration)==null?void 0:f.id)&&e.id!==this.id}):i=a.filter(e=>se(e,this.project)===se(this,this.project)&&e.id!==this.id)}return i}};R(Oi,"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(Oi,"type",d.InputMap),R(Oi,"USER_MANAGED_PARENT_TYPES",[...Vt,...Dt]),R(Oi,"PARENT_TYPES",[...Oi.USER_MANAGED_PARENT_TYPES]),R(Oi,"MUTABLE_BASE_PROPERTIES",["name","codeName","description"]),R(Oi,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion","parentRelationType"]),R(Oi,"BASE_PROPERTIES",[...Oi.MUTABLE_BASE_PROPERTIES,...Oi.INMUTABLE_BASE_PROPERTIES]),R(Oi,"MUTABLE_META_PROPERTIES",[...Oi.MUTABLE_BASE_PROPERTIES,"index"]),R(Oi,"INMUTABLE_META_PROPERTIES",[...Oi.INMUTABLE_BASE_PROPERTIES]),R(Oi,"META_PROPERTIES",[...Oi.MUTABLE_META_PROPERTIES,...Oi.INMUTABLE_META_PROPERTIES]),R(Oi,"MUTABLE_UPSTREAM_PROPERTIES",["readsValue"]),R(Oi,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","declaration"]),R(Oi,"UPSTREAM_PROPERTIES",[...Oi.MUTABLE_UPSTREAM_PROPERTIES,...Oi.INMUTABLE_UPSTREAM_PROPERTIES]),R(Oi,"MUTABLE_DOWNSTREAM_PROPERTIES",["defaultValue"]),R(Oi,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),R(Oi,"DOWNSTREAM_PROPERTIES",[...Oi.MUTABLE_DOWNSTREAM_PROPERTIES,...Oi.INMUTABLE_DOWNSTREAM_PROPERTIES]),R(Oi,"PROPERTIES",[...Oi.META_PROPERTIES,...Oi.UPSTREAM_PROPERTIES,...Oi.DOWNSTREAM_PROPERTIES]);let ts=Oi;class gRi extends ts{constructor(i,r){super(i,r);R(this,"parentRelationType",null);R(this,"errors",[])}toJSON(i=new Set){return super.toJSON(i)}}class IRi extends ts{constructor(i,r){super(i,r);R(this,"parentRelationType",null);R(this,"errors",[])}toJSON(i=new Set){return super.toJSON(i)}}class RRi extends ts{constructor(i,r){super(i,r);R(this,"parentRelationType",null);R(this,"name",null);R(this,"description",null);R(this,"errors",[])}toJSON(i=new Set){return super.toJSON(i)}}async function qBe(l,p={}){var f,h;const i=z.YieldTracker.from(p),r=ua(l),a=pa(l),c=[...r,...a],e=kt(l.errors,c);await i.tick();for(const m of l.inputsDeclarations)await m.validateAsync({tracker:i});for(const m of l.inputs)await m.validateAsync({tracker:i});for(const m of l.outputs)await m.validateAsync({tracker:i});return await((f=l.error)==null?void 0:f.validateAsync({tracker:i})),await((h=l.dataType)==null?void 0:h.validateAsync({tracker:i})),e}function ZBe(l){var r,a;l.inputsDeclarations.forEach(c=>c.validate()),l.inputs.forEach(c=>c.validate()),l.outputs.forEach(c=>c.validate()),(r=l.error)==null||r.validate(),(a=l.dataType)==null||a.validate();const i=[...ua(l),...pa(l)];return kt(l.errors,i)}const DRi=Object.freeze(Object.defineProperty({__proto__:null,validate:ZBe,validateAsync:qBe},Symbol.toStringTag,{value:"Module"}));async function HBe(l,p={}){var a;const i=z.YieldTracker.from(p),r=[];return await i.tick(),await((a=l.dataType)==null?void 0:a.validateAsync({tracker:i})),kt(l.errors,r)}function WBe(l){var i;(i=l.dataType)==null||i.validate();const p=[];return kt(l.errors,p)}const wRi=Object.freeze(Object.defineProperty({__proto__:null,validate:WBe,validateAsync:HBe},Symbol.toStringTag,{value:"Module"}));var zBe=(l=>(l.DataTypeEntity="data-type-entity",l))(zBe||{});const mi=class mi extends tn{constructor(i,r){super(i);R(this,"initialData");R(this,"id");R(this,"name");R(this,"codeName",null);R(this,"description",null);R(this,"index");R(this,"required");R(this,"parentRelationType");R(this,"type",d.ValueDescriptor);R(this,"defaultValue",null);R(this,"dataType",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,"codeNativeValueValidation",null);this.initialData=i,this.project=r,this.id=i.id,this.name=i.name,this.description=i.description,this.index=i.index,this.codeName=i.codeName,this.required=i.required,this.parentRelationType=i.parentRelationType}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.ValueDescriptor,name:"",codeName:null,description:"",dataType:null,index:0,required:!1,parentRelationType:U.FixedArguments,defaultValue:null,parent:null}}static fromGenerationTarget(i,r,a){const c=a===void 0?r.addChangeSet(new S(r,N.sessionAuthor,B().toISOString(),r,!0,w.CreateFromGenerationTarget)):a,e=i.parent?X(i.parent):null,f=e?r.get(e):null,h=i.parentRelationType===U.FixedArguments?f==null?void 0:f.inputs.length:null,m={id:i.id,version:N.UUID.uuid(),createdAt:(c==null?void 0:c.timestamp)||B().toISOString(),author:(c==null?void 0:c.author)||N.sessionAuthor,previousVersion:null,deleted:!1,name:i.name,deletable:!0,editable:!0,type:d.ValueDescriptor,index:h||0,codeName:i.codeName,description:i.description,required:i.required,defaultValue:null,parentRelationType:i.parentRelationType,dataType:null,parent:(f==null?void 0:f.toReference())||null},E=Ae(m,r);return E.hydrateAncestors(),f&&E.setParent(f,null),E.addSelfToProject(c),c==null||c.add(E,W.Added),E.initChildren(c),E}static validateGenerationTarget(i,r){let a=JSON.parse(JSON.stringify(i));const c=[],e=[],f=On(a,{parent:{list:!1,types:mi.USER_MANAGED_PARENT_TYPES}},r);c.push(...f.explanations),a=f.modifiedData;const h=Hr(a);e.push(...f.errors,...h.errors),c.push(...h.explanations);const m=a.parent&&r.get(a.parent),E=m&&Jd(m);return E&&E.type===d.ActionDescriptor&&e.push(new Re({id:`${i.id}--${fe.BuiltInEntityParent}`,code:fe.BuiltInEntityParent,severity:Te.Error,message:`Entity of type "${i.type}" with id "${i.id}", has a parent that is a built-in entity "${E.name}" of type '${E.type}' with id '${E.id}'.
110
+ 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:c}}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 S(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:C(r),added:C(a),removed:C(c),affected:C(e),self:this}}onDetachedDependencyRemoved(i,r,a){const c=[],e=[],f=[],h=[];if(r==="declaration"){const{updated:m,added:E,removed:b}=this.remove({ignoreUpstream:!1},a);c.push(...m),e.push(...E),f.push(...b)}return{updated:C(c),added:C(e),removed:C(f),affected:C(h),self:this}}onDetachedDependencyRestored(i,r,a){const c=[],e=[],f=[],h=[];if(r==="declaration"){const{updated:m,added:E,removed:b}=this.restore({},a);c.push(...m),e.push(...E),f.push(...b)}return{updated:C(c),added:C(e),removed:C(f),affected:C(h),self:this}}unsubscribeFromDependencies(){var i,r,a,c,e;return(r=(i=this.declaration)==null?void 0:i.unsubscribeDependents)==null||r.call(i,[{entity:this,field:"declaration"}]),(e=(c=(a=this.dataType)==null?void 0:a.entity)==null?void 0:c.unsubscribeDependents)==null||e.call(c,[{entity:this,field:"data-type-entity"}]),this}subscribeToDependencies(){var i,r,a,c,e;return(r=(i=this.declaration)==null?void 0:i.subscribeDependents)==null||r.call(i,[{entity:this,field:"declaration"}]),(e=(c=(a=this.dataType)==null?void 0:a.entity)==null?void 0:c.subscribeDependents)==null||e.call(c,[{entity:this,field:"data-type-entity"}]),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 Oi(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.declaration=this.declaration,i.defaultValue=this.defaultValue,i.readsValue=this.readsValue,i.dataType=this.dataType,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:C(r),added:C(a),removed:C(c),affected:C(e),self:this}}async restoreVersion(i){var h;const r=[],a=[],c=[],e=[];if(this.version===i)return{updated:C(r),added:C(a),removed:C(c),affected:C(e),self:this};if(!this.knownVersions){const m=new Map;for(const[E,b]of this.knownVersions||new Map){if(m.set(E,b),b.activeVersion=!1,b.knownVersions)for(const[g,_]of b.knownVersions)m.set(g,_);b.knownVersions=null}}let f=(h=this.knownVersions)==null?void 0:h.get(i);if(!f){const m=await this.APILoadVersion({},i);if(!m)throw new Error(`Version with id '${i}' for entity with id '${this.id}' not found.`);f=new Oi(m,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.declaration=f.declaration,this.defaultValue=f.defaultValue,this.readsValue=f.readsValue,this.dataType=f.dataType,this.parent=f.parent,{updated:C(r),added:C(a),removed:C(c),affected:C(e),self:this}}updateWithShallowTransfer(i,r=this.project.addChangeSet(new S(this.project,N.sessionAuthor,B().toISOString(),this,!0,w.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(w.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(w.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(w.UpdateWithShallowTransfer,this.id),new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(i.readsValue){const a=X(i.readsValue),c=this.project.get(a),e=this.readsValue;e&&e.id!==(c==null?void 0:c.id)&&this.removeValueWriter(r),c&&this.setValueWriter(c,r)}else this.removeValueWriter(r);if(i.declaration){const a=X(i.declaration),c=this.project.get(a);c&&this.setDeclaration(c,r)}else this.setDeclaration(null,r);if(i.dataType){const a=X(i.dataType),c=this.project.get(a);c&&this.setDataType(c,r)}else this.setDataType(null,r);if(i.defaultValue){const a=X(i.defaultValue),c=this.project.get(a);c&&this.setDefaultValue(c,r)}else this.setDefaultValue(null,r);return this.captureVersion(),this.subscribeToDependencies(),r==null||r.attemptAutoclose(w.UpdateWithShallowTransfer,this.id),this}updateWithGenerationTarget(i,r=this.project.addChangeSet(new S(this.project,N.sessionAuthor,B().toISOString(),this,!0,w.UpdateWithGenerationTarget))){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(w.UpdateWithGenerationTarget,this.id),this;if(this.metaSync(i,r),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(w.UpdateWithGenerationTarget,this.id),new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${a}' that isn't found in the project`)}if(i.readsValue){const a=X(i.readsValue),c=this.project.get(a),e=this.readsValue;if(e&&e.id!==(c==null?void 0:c.id)&&this.removeValueWriter(r),c)this.setValueWriter(c,r);else throw new Error(`${this.type} with id '${this.id}' has a 'readsValue' reference '${a}' that isn't found in the project`)}else i.readsValue===null&&this.removeValueWriter(r);if(i.declaration){const a=X(i.declaration),c=this.project.get(a);if(c)this.setDeclaration(c,r);else throw new Error(`${this.type} with id '${this.id}' has a 'declaration' reference '${a}' that isn't found in the project`)}else i.declaration===null&&this.setDeclaration(null,r);return this.captureVersion(),this.subscribeToDependencies(),r==null||r.attemptAutoclose(w.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.readsValue){const e=X(this.initialData.readsValue),f=this.project.get(e);f&&(this.setValueWriter(f,null),i.push(f))}if(this.initialData.declaration){const e=X(this.initialData.declaration),f=this.project.get(e);f&&(this.setDeclaration(f,null),i.push(f))}return{updated:C(i),added:C(r),removed:C(a),affected:C(c),self:this}}afterAllChildrenInitialized(i=this.project.addChangeSet(new S(this.project,N.sessionAuthor,B().toISOString(),this,!0,w.AfterAllChildrenInitialized))){var b,g,_;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(w.AfterAllChildrenInitialized,this.id),{updated:[],added:[],removed:[],affected:[],self:this};const r=[],a=[],c=[],e=[];this.initialized=!0;let f=this.index||0;const h=(Dt.includes(this.parent.type)?this.parent.outputs:this.parent.inputs).filter(P=>!P.deleted&&P.id!==this.id);h.length&&(f>h.length+1?f=h.length:f<0&&(f=0)),h.find(P=>(P.index||0)===f&&!P.deleted)&&h.filter(P=>(P.index||0)>=f&&!P.deleted).forEach(P=>{P.metaSync({index:(P.index||0)+1},i),i==null||i.add(P,W.Updated),r.push(P)});const E=this.parent.type===d.VariableInstance&&((b=this.declaration)==null?void 0:b.type)===d.Property&&((g=this.declaration)==null?void 0:g.constant);if(E&&this.readsValue&&(this.readsValue.removeValueReader(this,i),this.removeValueWriter(i)),E&&this.defaultValue&&this.defaultValue.remove({ignoreUpstream:!1},i),this.readsValue&&this.defaultValue&&(this.project.diggestedBuiltInBaseEntitiesIds.has(this.defaultValue.id)||this.defaultValue.remove({ignoreUpstream:!1},i),this.setDefaultValue(null,i)),this.defaultValue&&!this.readsValue&&!this.project.diggestedBuiltInBaseEntitiesIds.has(this.id)&&this.project.diggestedBuiltInBaseEntitiesIds.has(this.defaultValue.id)){const P=this.defaultValue.clone(i,this);this.setDefaultValue(P,i)}return this.readsValue&&this.parent.type===d.VariableDeclaration&&((_=this.parent.parent)==null?void 0:_.type)===d.Project&&(i==null||i.event({id:`${w.RemoveValueWriter}-${this.id}--${Me.InputsInGlobalVariableDeclarationsCannotReadValues}`,action:w.RemoveValueWriter,owner:this,errorReason:Me.InputsInGlobalVariableDeclarationsCannotReadValues,rootAction:!1}),this.readsValue.removeValueReader(this,i),this.removeValueWriter(i)),this.metaSync({index:f},i),this.captureVersion(),i==null||i.attemptAutoclose(w.AfterAllChildrenInitialized,this.id),{updated:C(r),added:C(a),removed:C(c),affected:C(e),self:this}}addSelfToProject(i=this.project.addChangeSet(new S(this.project,N.sessionAuthor,B().toISOString(),this,!0,"add-self-to-project"))){var f;const r=[this],a=[],c=[],e=[];return Dt.includes(this.parent.type)?this.parentRelationType===Wo.Error?this.parent.setThrows(this,i):this.parent.addOutput(this,i):this.parent.addInput(this,i),e.push(this.parent),(f=this.readsValue)==null||f.addValueReader(this,i),this.readsValue&&r.push(this.readsValue),this.subscribe(),this.subscribeToDependencies(),i==null||i.attemptAutoclose("add-self-to-project",this.id),{updated:C(r),added:C(a),removed:C(c),affected:C(e),self:this}}setParent(i,r=this.project.addChangeSet(new S(this.project,N.sessionAuthor,B().toISOString(),this,!0,w.SetParent))){var a;return this.checkCanEditWithCounterpartAndSideEffects(this,i,w.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(w.SetParent,this.id),this):this}setDataType(i,r=this.project.addChangeSet(new S(this.project,N.sessionAuthor,B().toISOString(),this,!0,w.SetDataType))){if(!this.checkCanEdit(this,r))return z.Logger.warn(`[setDataType] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),r==null||r.attemptAutoclose(w.SetDataType,this.id),this;const a=this.dataType;return(a==null?void 0:a.id)!==(i==null?void 0:i.id)&&(a==null||a.remove({ignoreUpstream:!0},r),this.dataType=i,this.subscribeToDependencies(),r==null||r.add(this,W.Affected)),r==null||r.attemptAutoclose(w.SetDataType,this.id),this}removeDataType(i=this.project.addChangeSet(new S(this.project,N.sessionAuthor,B().toISOString(),this,!0,w.RemoveDataType))){return this.checkCanEdit(this,i)?(this.dataType&&(this.dataType.remove({ignoreUpstream:!0},i),i==null||i.add(this,W.Affected),this.dataType=null),i==null||i.attemptAutoclose(w.RemoveDataType,this.id),this):(z.Logger.warn(`[removeDataType] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(w.RemoveDataType,this.id),this)}setDeclaration(i,r=this.project.addChangeSet(new S(this.project,N.sessionAuthor,B().toISOString(),this,!0,"set-declaration"))){var a;return((a=this.declaration)==null?void 0:a.id)!==(i==null?void 0:i.id)&&(this.declaration=i,this.subscribeToDependencies(),r&&(r==null||r.add(this,W.Updated))),r==null||r.attemptAutoclose("set-declaration",this.id),this}initChildren(i=this.project.addChangeSet(new S(this.project,N.sessionAuthor,B().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.initialData.defaultValue&&(this.defaultValue=Ae(this.initialData.defaultValue,this.project),this.defaultValue.setParent(this,null),this.defaultValue.initChildren(i)),this.initialData.declaration&&(this.declaration=Ae(this.initialData.declaration,this.project)),Zf.initReadsValue(this),this.subscribeToDependencies(),this.afterAllChildrenInitialized(i),i==null||i.attemptAutoclose("init-children",this.id),this)}setValueWriter(i,r=this.project.addChangeSet(new S(this.project,N.sessionAuthor,B().toISOString(),this,!0,w.SetValueWriter))){var c,e,f,h,m,E;return this.checkCanEditFromScopeOwnerWithSideEffects(this,w.SetValueWriter,r)?((i==null?void 0:i.id)===this.id&&(r==null||r.event({id:`${w.SetValueWriter}-${this.id}`,action:w.SetValueWriter,owner:this,errorReason:Me.CannotValueWriteItself,rootAction:((c=r==null?void 0:r.self)==null?void 0:c.id)===this.id&&(r==null?void 0:r.autoCloseActionName)===w.SetValueWriter})),this.parent.type===d.VariableInstance&&((e=this.declaration)==null?void 0:e.type)===d.Property&&((f=this.declaration)==null?void 0:f.constant)&&i?(r==null||r.event({id:`${w.SetValueWriter}-${this.id}--${i.id}`,action:w.SetValueWriter,owner:this,counterpart:i,errorReason:Me.ValueReadingOverridesConstantVariable,rootAction:((h=r==null?void 0:r.self)==null?void 0:h.id)===this.id&&(r==null?void 0:r.autoCloseActionName)===w.SetValueWriter}),r==null||r.attemptAutoclose(w.SetValueWriter,this.id),this):(((m=this.readsValue)==null?void 0:m.id)!==(i==null?void 0:i.id)&&(this.readsValue=i,this.readsValue&&((E=this.defaultValue)==null||E.remove({ignoreUpstream:!1},r)),r==null||r.add(this,W.Updated)),r==null||r.attemptAutoclose(w.SetValueWriter,this.id),this)):this}removeValueWriter(i=this.project.addChangeSet(new S(this.project,N.sessionAuthor,B().toISOString(),this,!0,w.RemoveValueWriter))){return this.readsValue&&!this.checkCanEditWithCounterpartAndSideEffects(this,this.readsValue,w.RemoveValueWriter,i)?this:(this.readsValue&&(this.readsValue=null,i==null||i.add(this,W.Updated)),i==null||i.attemptAutoclose(w.RemoveValueWriter,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 S(this.project,N.sessionAuthor,B().toISOString(),this,!0,"meta-sync"))){const a=zr(this,i,r),c=Wr(this,a),e=this.toMeta();return this.index=a.index||(a.index!==0?e.index:0),this.name=a.name!==void 0?a.name:e.name,this.codeName=a.codeName!==void 0?a.codeName:e.codeName,this.description=a.description!==void 0?a.description:e.description,this.parentRelationType=a.parentRelationType!==void 0?a.parentRelationType:this.parentRelationType,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=Se,...r){return await Oi.repository.APILoad(this.id,...r),this}async APICreate(i=Se,...r){return await Oi.repository.APICreate(this.toShallowJSON(),...r),this}async APIUpdate(i=Se,...r){return await Oi.repository.APIUpdate(this.toShallowJSON(),...r),this}async APIDelete(i=Se,...r){return await Oi.repository.APIDelete(this.toShallowJSON(),...r),this}async APIClone(i=Se,...r){return await Oi.repository.APIClone(this.id,...r),this}async APILoadVersion(i=Se,r,...a){return await Oi.repository.APILoadVersion(this.id,r,...a)}removeFromParent(i=this.project.addChangeSet(new S(this.project,N.sessionAuthor,B().toISOString(),this,!0,w.RemoveFromParent))){var f;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(w.RemoveFromParent,this.id),{added:[],updated:[],removed:[],affected:[],self:this};const r=[],a=[],c=[],e=[];return Dt.includes((f=this.parent)==null?void 0:f.type)?this.parentRelationType===Wo.Error?(this.parent.setThrows(null,i),e.push(this.parent)):(this.parent.removeOutput(this,i),e.push(this.parent)):(this.parent.removeInput(this,i),e.push(this.parent)),i==null||i.attemptAutoclose(w.RemoveFromParent,this.id),{added:C(c),updated:C(r),removed:C(a),affected:C(e),self:this}}remove({ignoreUpstream:i}={ignoreUpstream:!1},r=this.project.addChangeSet(new S(this.project,N.sessionAuthor,B().toISOString(),this,!0,w.RemoveEntity))){var h,m,E,b,g;if(this.deleted)return r==null||r.attemptAutoclose(w.RemoveEntity,this.id),{added:[],updated:[],removed:[],affected:[],self:this};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:`${w.RemoveEntity}-${this.id}--${Me.ActionOwnerEntityNonDeletable}`,action:w.RemoveEntity,owner:this,errorReason:Me.ActionOwnerEntityNonDeletable,rootAction:((h=r==null?void 0:r.self)==null?void 0:h.id)===this.id&&(r==null?void 0:r.autoCloseActionName)===w.RemoveEntity}),r==null||r.attemptAutoclose(w.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(w.RemoveEntity,this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(c.push(this),this.unsubscribe(),this.unsubscribeFromDependencies(),this.metaSync({deleted:!0},r),r!=null&&r.hasAdded(this.id)||this.project.subscribeDeletedInstance(this),Object.values(this.detachedDependents).forEach(_=>{const{updated:P,removed:x,added:j}=_.entity.onDetachedDependencyRemoved(this,_.field,r);a.push(...P),c.push(...x),e.push(...j)}),this.defaultValue){const{updated:_,removed:P}=this.defaultValue.remove({ignoreUpstream:!0},r);a.push(..._),c.push(...P)}if(this.readsValue&&(a.push(this.readsValue),this.readsValue.removeValueReader(this,r)),this.defaultValue&&(a.push(this.defaultValue),this.defaultValue.remove({ignoreUpstream:!0},r)),this.declaration){if(this.declaration.type===d.Property&&((m=this.declaration.parent)==null?void 0:m.type)===d.DefinitionEntity&&((b=(E=this.declaration.parent)==null?void 0:E.parent)==null?void 0:b.type)===d.DataType&&!(r!=null&&r.hasRemoved(this.declaration.id))&&!this.declaration.deleted){const{updated:_,removed:P}=this.declaration.remove({ignoreUpstream:!1},r);a.push(..._),c.push(...P)}else if(this.declaration.type===d.ValueDescriptor&&((g=this.declaration.parent)==null?void 0:g.type)===d.Search&&!(r!=null&&r.hasRemoved(this.declaration.id))&&!this.declaration.deleted){const{updated:_,removed:P}=this.declaration.remove({ignoreUpstream:!1},r);a.push(..._),c.push(...P)}}if(!i){const _=this.removeFromParent(r);e.push(..._.added),a.push(..._.updated),c.push(..._.removed),f.push(..._.affected)}if(!i&&this.parent&&[d.BreakStatement,d.ContinueStatement].includes(this.parent.type)&&this.parent.parent&&this.parent.parent.type===d.Loop&&this.parent.initialized&&this.parent.parent.syncFromDataType(r),this.parentRelationType===Wo.Error&&this.parent.type===d.ReturnStatement){const{updated:_,added:P,removed:x,affected:j}=this.parent.syncInputs(r);a.push(..._),e.push(...P),c.push(...x),f.push(...j)}return r==null||r.attemptAutoclose(w.RemoveEntity,this.id),{added:C(e),updated:C(a),removed:C(c),affected:C(f),self:this}}restore({}={},i=this.project.addChangeSet(new S(this.project,N.sessionAuthor,B().toISOString(),this,!0,w.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(w.RestoreEntity,this.id),{added:[],updated:[],removed:[],affected:[],self:this};const r=[],a=[],c=[],e=[];if(i!=null&&i.hasAdded(this.id))return i==null||i.attemptAutoclose(w.RestoreEntity,this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},i),Object.values(this.detachedDependents).forEach(f=>{const{updated:h,removed:m,added:E}=f.entity.onDetachedDependencyRestored(this,f.field,i);a.push(...h),c.push(...m),r.push(...E)}),this.defaultValue){const{updated:f}=this.defaultValue.restore({},i);a.push(...f)}return this.readsValue&&(a.push(this.readsValue),this.readsValue.addValueReader(this,i)),this.defaultValue&&(a.push(this.defaultValue),this.defaultValue.restore({},i)),e.push(this.parent),this.parent.addInput(this,i),i==null||i.attemptAutoclose(w.RestoreEntity,this.id),{added:C(r),updated:C(a),removed:C(c),affected:C(e),self:this}}toFlat(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this,...this.defaultValue?this.defaultValue.toFlat(i):[],...this.dataType?this.dataType.toFlat(i):[],...this.declaration?this.declaration.toFlat(i):[],...this.readsValue?this.readsValue.toFlat(i):[]])}toFlatIds(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.id,...this.defaultValue?this.defaultValue.toFlatIds(i):[],...this.dataType?this.dataType.toFlatIds(i):[],...this.declaration?this.declaration.toFlatIds(i):[],...this.readsValue?this.readsValue.toFlatIds(i):[]])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,codeName:this.codeName,description:this.description,parentRelationType:this.parentRelationType,index:this.index,type:this.type,editable:this.editable,deletable:this.deletable,name:this.name}}toJSON(i=new Set){var r,a,c,e;return i.has(this.id)?this.toReference():(i.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,editable:this.editable,deletable:this.deletable,index:this.index,name:this.name,codeName:this.codeName,description:this.description,parentRelationType:this.parentRelationType,defaultValue:((r=this.defaultValue)==null?void 0:r.toJSON(i))||null,dataType:((a=this.dataType)==null?void 0:a.toJSON(i))||null,declaration:((c=this.declaration)==null?void 0:c.toJSON(i))||null,readsValue:((e=this.readsValue)==null?void 0:e.toReference())||null,parent:this.parent.toReference()})}toJSONClone(i=nt){var a,c,e,f,h,m,E,b,g,_,P,x;let r;return(a=i.seenEntityMaps)!=null&&a.has(this.id)?r=i.seenEntityMaps.get(this.id):(r=i.newId||en(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,type:this.type,editable:this.editable,deletable:this.deletable,index:this.index,name:this.name,codeName:this.codeName,description:this.description,parentRelationType:this.parentRelationType,defaultValue:((m=this.defaultValue)==null?void 0:m.toJSONClone({...i,newId:null}))||null,dataType:((E=this.dataType)==null?void 0:E.toJSONClone({...i,newId:null}))||null,declaration:(b=this.declaration)!=null&&b.id&&this.project.getBuiltIn((g=this.declaration)==null?void 0:g.id)?(_=this.declaration)==null?void 0:_.toJSON(i.seenEntities):((P=this.declaration)==null?void 0:P.toJSONClone({...i,newId:null}))||null,readsValue:((x=this.readsValue)==null?void 0:x.toReference({seenEntityMaps:i.seenEntityMaps}))||null,parent:this.parent.toReference({seenEntityMaps:i.seenEntityMaps})})}toReference(i=nt){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=nt){var a,c,e,f,h;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,type:this.type,editable:this.editable,deletable:this.deletable,name:this.name,codeName:this.codeName,description:this.description,parentRelationType:this.parentRelationType,index:this.index,dataType:((c=this.dataType)==null?void 0:c.toReference(i))||null,defaultValue:((e=this.defaultValue)==null?void 0:e.toReference(i))||null,declaration:((f=this.declaration)==null?void 0:f.toReference(i))||null,readsValue:((h=this.readsValue)==null?void 0:h.toReference(i))||null,parent:this.parent.toReference(i)}}toFlatJSON(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.toShallowJSON(),...this.defaultValue?this.defaultValue.toFlatJSON(i):[],...this.dataType?this.dataType.toFlatJSON(i):[],...this.declaration?this.declaration.toFlatJSON(i):[],...this.readsValue?this.readsValue.toFlatJSON(i):[]])}toGenerationTarget(i=nt){var a,c;let r=this.id;return(a=i.seenEntityMaps)!=null&&a.has(this.id)&&(r=i.seenEntityMaps.get(this.id)),{id:r,name:this.name||void 0,description:this.description||void 0,type:this.type,declaration:((c=this.declaration)==null?void 0:c.id)||null,parent:this.parent.id}}toFlatGenerationTarget(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.toGenerationTarget(),...this.defaultValue?this.defaultValue.toFlatGenerationTarget(i):[],...this.dataType?this.dataType.toFlatGenerationTarget(i):[],...this.readsValue?this.readsValue.toFlatGenerationTarget(i):[],...this.declaration?this.declaration.toFlatGenerationTarget(i):[]])}clearErrors(){var i;return this.errors=[],(i=this.defaultValue)==null||i.clearErrors(),this}validate(){return this.errors=UBe(this),{success:!0}}async validateAsync(i={}){const r=z.YieldTracker.from(i);return this.errors=await jBe(this,{tracker:r}),{success:!0}}getErrors(){var r;return[...this.errors,...((r=this.defaultValue)==null?void 0:r.getErrors())||[]]}async getErrorsAsync(i={}){var e;const r=z.YieldTracker.from(i),a=[...this.errors];await r.tick();const c=await((e=this.defaultValue)==null?void 0:e.getErrorsAsync({tracker:r}));return c&&a.push(...c),a}getShallowErrors(){return this.errors}getDefaultValue(){var i;return this.defaultValue||((i=this.declaration)==null?void 0:i.getDefaultValue())||null}setDefaultValue(i,r=this.project.addChangeSet(new S(this.project,N.sessionAuthor,B().toISOString(),this,!0,"set-default-value"))){if(!this.checkCanEdit(this,r))return z.Logger.warn(`[setDefaultValue] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),r==null||r.attemptAutoclose("set-default-value",this.id),this;const a=this.defaultValue;if((a==null?void 0:a.id)!==(i==null?void 0:i.id)){if(a==null||a.remove({ignoreUpstream:!0},r),this.defaultValue=i,this.defaultValue){const c=this.readsValue;this.removeValueWriter(r),c==null||c.removeValueReader(this,r)}r==null||r.add(this,W.Affected)}return r==null||r.attemptAutoclose("set-default-value",this.id),this}clone(i=this.project.addChangeSet(new S(this.project,N.sessionAuthor,B().toISOString(),this,!0,w.CloneEntity)),r=null,a=null,c=!0){var b;const e=Mr(r,this),f=this.toJSON(),h=a||N.UUID.uuid();f.defaultValue=null,f.id=h,f.version=N.UUID.uuid(),f.createdAt=(i==null?void 0:i.timestamp)||B().toISOString(),f.author=(i==null?void 0:i.author)||"1",f.previousVersion=null,f.deleted=!1,f.deletable=!0,f.editable=!0;const m=tr(f,e);m.hydrateAncestors(),r&&m.setParent(r,i),c&&(m.subscribe(),m.addSelfToProject(i)),m.initChildren(i),i==null||i.add(m,W.Added);const E=(b=this.defaultValue)==null?void 0:b.clone(i,m,N.UUID.uuid(),c);return m.defaultValue=E||null,i==null||i.attemptAutoclose(w.CloneEntity,this.id),m}getDataType(i=this.project.addChangeSet(new S(this.project,N.sessionAuthor,B().toISOString(),this,!0,"get-data-type"))){var a;if(this.parent.type===d.Operation){const c=this.parent.declaration.inferInputMapDataType(this,i);return i==null||i.attemptAutoclose("get-data-type",this.id),c.self}else Pt.includes(this.parent.type)&&Tr(this.parent).getDataType(i);const r=(a=this.declaration)==null?void 0:a.getDataType(i);if(!r){const c=Ud(this,i);if(c)return i==null||i.attemptAutoclose("get-data-type",this.id),c}return i==null||i.attemptAutoclose("get-data-type",this.id),r||null}getCounterparts(){let i=[];if([d.BreakStatement,d.ContinueStatement].includes(this.parent.type)){const r=this.parent.parent;i=[...r.breakStatements,...r.continueStatements].flatMap(e=>e.outputs).filter(e=>se(e,this.project)===se(this,this.project)&&e.id!==this.id)}else if(this.parent.type===d.ReturnStatement&&[d.FunctionDeclaration,d.GlobalEvent].includes(this.parent.parent.type)&&this.parent.parent.implements){const a=this.parent.parent.returnStatements.flatMap(c=>c.outputs);this.declaration?i=a.filter(e=>{var f;return this.declaration.id===((f=e.declaration)==null?void 0:f.id)&&e.id!==this.id}):i=a.filter(e=>se(e,this.project)===se(this,this.project)&&e.id!==this.id)}return i}};R(Oi,"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(Oi,"type",d.InputMap),R(Oi,"USER_MANAGED_PARENT_TYPES",[...Vt,...Dt]),R(Oi,"PARENT_TYPES",[...Oi.USER_MANAGED_PARENT_TYPES]),R(Oi,"MUTABLE_BASE_PROPERTIES",["name","codeName","description"]),R(Oi,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion","parentRelationType"]),R(Oi,"BASE_PROPERTIES",[...Oi.MUTABLE_BASE_PROPERTIES,...Oi.INMUTABLE_BASE_PROPERTIES]),R(Oi,"MUTABLE_META_PROPERTIES",[...Oi.MUTABLE_BASE_PROPERTIES,"index"]),R(Oi,"INMUTABLE_META_PROPERTIES",[...Oi.INMUTABLE_BASE_PROPERTIES]),R(Oi,"META_PROPERTIES",[...Oi.MUTABLE_META_PROPERTIES,...Oi.INMUTABLE_META_PROPERTIES]),R(Oi,"MUTABLE_UPSTREAM_PROPERTIES",["readsValue"]),R(Oi,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","declaration"]),R(Oi,"UPSTREAM_PROPERTIES",[...Oi.MUTABLE_UPSTREAM_PROPERTIES,...Oi.INMUTABLE_UPSTREAM_PROPERTIES]),R(Oi,"MUTABLE_DOWNSTREAM_PROPERTIES",["defaultValue"]),R(Oi,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),R(Oi,"DOWNSTREAM_PROPERTIES",[...Oi.MUTABLE_DOWNSTREAM_PROPERTIES,...Oi.INMUTABLE_DOWNSTREAM_PROPERTIES]),R(Oi,"PROPERTIES",[...Oi.META_PROPERTIES,...Oi.UPSTREAM_PROPERTIES,...Oi.DOWNSTREAM_PROPERTIES]);let ts=Oi;class gRi extends ts{constructor(i,r){super(i,r);R(this,"parentRelationType",null);R(this,"errors",[])}toJSON(i=new Set){return super.toJSON(i)}}class IRi extends ts{constructor(i,r){super(i,r);R(this,"parentRelationType",null);R(this,"errors",[])}toJSON(i=new Set){return super.toJSON(i)}}class RRi extends ts{constructor(i,r){super(i,r);R(this,"parentRelationType",null);R(this,"name",null);R(this,"description",null);R(this,"errors",[])}toJSON(i=new Set){return super.toJSON(i)}}async function qBe(l,p={}){var f,h;const i=z.YieldTracker.from(p),r=ua(l),a=pa(l),c=[...r,...a],e=kt(l.errors,c);await i.tick();for(const m of l.inputsDeclarations)await m.validateAsync({tracker:i});for(const m of l.inputs)await m.validateAsync({tracker:i});for(const m of l.outputs)await m.validateAsync({tracker:i});return await((f=l.error)==null?void 0:f.validateAsync({tracker:i})),await((h=l.dataType)==null?void 0:h.validateAsync({tracker:i})),e}function ZBe(l){var r,a;l.inputsDeclarations.forEach(c=>c.validate()),l.inputs.forEach(c=>c.validate()),l.outputs.forEach(c=>c.validate()),(r=l.error)==null||r.validate(),(a=l.dataType)==null||a.validate();const i=[...ua(l),...pa(l)];return kt(l.errors,i)}const DRi=Object.freeze(Object.defineProperty({__proto__:null,validate:ZBe,validateAsync:qBe},Symbol.toStringTag,{value:"Module"}));async function HBe(l,p={}){var a;const i=z.YieldTracker.from(p),r=[];return await i.tick(),await((a=l.dataType)==null?void 0:a.validateAsync({tracker:i})),kt(l.errors,r)}function WBe(l){var i;(i=l.dataType)==null||i.validate();const p=[];return kt(l.errors,p)}const wRi=Object.freeze(Object.defineProperty({__proto__:null,validate:WBe,validateAsync:HBe},Symbol.toStringTag,{value:"Module"}));var zBe=(l=>(l.DataTypeEntity="data-type-entity",l))(zBe||{});const mi=class mi extends tn{constructor(i,r){super(i);R(this,"initialData");R(this,"id");R(this,"name");R(this,"codeName",null);R(this,"description",null);R(this,"index");R(this,"required");R(this,"parentRelationType");R(this,"type",d.ValueDescriptor);R(this,"defaultValue",null);R(this,"dataType",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,"codeNativeValueValidation",null);this.initialData=i,this.project=r,this.id=i.id,this.name=i.name,this.description=i.description,this.index=i.index,this.codeName=i.codeName,this.required=i.required,this.parentRelationType=i.parentRelationType}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.ValueDescriptor,name:"",codeName:null,description:"",dataType:null,index:0,required:!1,parentRelationType:U.FixedArguments,defaultValue:null,parent:null}}static fromGenerationTarget(i,r,a){const c=a===void 0?r.addChangeSet(new S(r,N.sessionAuthor,B().toISOString(),r,!0,w.CreateFromGenerationTarget)):a,e=i.parent?X(i.parent):null,f=e?r.get(e):null,h=i.parentRelationType===U.FixedArguments?f==null?void 0:f.inputs.length:null,m={id:i.id,version:N.UUID.uuid(),createdAt:(c==null?void 0:c.timestamp)||B().toISOString(),author:(c==null?void 0:c.author)||N.sessionAuthor,previousVersion:null,deleted:!1,name:i.name,deletable:!0,editable:!0,type:d.ValueDescriptor,index:h||0,codeName:i.codeName,description:i.description,required:i.required,defaultValue:null,parentRelationType:i.parentRelationType,dataType:null,parent:(f==null?void 0:f.toReference())||null},E=Ae(m,r);return E.hydrateAncestors(),f&&E.setParent(f,null),E.addSelfToProject(c),c==null||c.add(E,W.Added),E.initChildren(c),E}static validateGenerationTarget(i,r){let a=JSON.parse(JSON.stringify(i));const c=[],e=[],f=On(a,{parent:{list:!1,types:mi.USER_MANAGED_PARENT_TYPES}},r);c.push(...f.explanations),a=f.modifiedData;const h=Hr(a);e.push(...f.errors,...h.errors),c.push(...h.explanations);const m=a.parent&&r.get(a.parent),E=m&&Jd(m);return E&&E.type===d.ActionDescriptor&&e.push(new Re({id:`${i.id}--${fe.BuiltInEntityParent}`,code:fe.BuiltInEntityParent,severity:Te.Error,message:`Entity of type "${i.type}" with id "${i.id}", has a parent that is a built-in entity "${E.name}" of type '${E.type}' with id '${E.id}'.
111
111
  You can't modify system entities that are built-in.`})),m&&m.type===d.ActionDescriptor&&(!a.parentRelationType||!(a.parentRelationType===U.FixedArguments||a.parentRelationType===U.ReturnedError||a.parentRelationType===U.DynamicArgument))&&e.push(new Re({id:`${i.id}--${fe.InvalidParentRelationType}`,code:fe.InvalidParentRelationType,severity:Te.Error,message:`The entity with id '${i.id}' and type '${i.type}', must have a 'parentRelationType' property set to either '${U.FixedArguments}' or '${U.ReturnedError}' when being added as a child to an entity of type 'action-descriptor'.`})),{errors:e,explanations:c,modifiedData:a}}validateGeneratedUpdate(i){return{errors:[],explanations:[],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 S(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:C(r),added:C(a),removed:C(c),affected:C(e),self:this}}onDetachedDependencyRemoved(i,r,a){const c=[],e=[],f=[],h=[];return{updated:C(c),added:C(e),removed:C(f),affected:C(h),self:this}}onDetachedDependencyRestored(i,r,a){const c=[],e=[],f=[],h=[];return{updated:C(c),added:C(e),removed:C(f),affected:C(h),self:this}}unsubscribeFromDependencies(){var i,r,a;return(a=(r=(i=this.dataType)==null?void 0:i.entity)==null?void 0:r.unsubscribeDependents)==null||a.call(r,[{entity:this,field:"data-type-entity"}]),this}subscribeToDependencies(){var i,r,a;return(a=(r=(i=this.dataType)==null?void 0:i.entity)==null?void 0:r.subscribeDependents)==null||a.call(r,[{entity:this,field:"data-type-entity"}]),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 mi(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.defaultValue=this.defaultValue,i.dataType=this.dataType,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:C(r),added:C(a),removed:C(c),affected:C(e),self:this}}async restoreVersion(i){var h;const r=[],a=[],c=[],e=[];if(this.version===i)return{updated:C(r),added:C(a),removed:C(c),affected:C(e),self:this};if(!this.knownVersions){const m=new Map;for(const[E,b]of this.knownVersions||new Map){if(m.set(E,b),b.activeVersion=!1,b.knownVersions)for(const[g,_]of b.knownVersions)m.set(g,_);b.knownVersions=null}}let f=(h=this.knownVersions)==null?void 0:h.get(i);if(!f){const m=await this.APILoadVersion({},i);if(!m)throw new Error(`Version with id '${i}' for entity with id '${this.id}' not found.`);f=new mi(m,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.defaultValue=f.defaultValue,this.dataType=f.dataType,this.parent=f.parent,{updated:C(r),added:C(a),removed:C(c),affected:C(e),self:this}}updateWithShallowTransfer(i,r=this.project.addChangeSet(new S(this.project,N.sessionAuthor,B().toISOString(),this,!0,w.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(w.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(w.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(w.UpdateWithShallowTransfer,this.id),new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(i.dataType){const a=X(i.dataType),c=this.project.get(a);c&&this.setDataType(c,r)}else this.setDataType(null,r);if(i.defaultValue){const a=X(i.defaultValue),c=this.project.get(a);c&&this.setDefaultValue(c,r)}else this.setDefaultValue(null,r);return this.captureVersion(),this.subscribeToDependencies(),r==null||r.attemptAutoclose(w.UpdateWithShallowTransfer,this.id),this}updateWithGenerationTarget(i,r=this.project.addChangeSet(new S(this.project,N.sessionAuthor,B().toISOString(),this,!0,w.UpdateWithGenerationTarget))){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(w.UpdateWithGenerationTarget,this.id),this;if(this.metaSync(i,r),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(w.UpdateWithGenerationTarget,this.id),new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${a}' that isn't found in the project`)}return this.captureVersion(),this.subscribeToDependencies(),r==null||r.attemptAutoclose(w.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'`);return{updated:C(i),added:C(r),removed:C(a),affected:C(c),self:this}}afterAllChildrenInitialized(i=this.project.addChangeSet(new S(this.project,N.sessionAuthor,B().toISOString(),this,!0,w.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(w.AfterAllChildrenInitialized,this.id),{updated:[],added:[],removed:[],affected:[],self:this};const r=[],a=[],c=[],e=[];if(this.defaultValue&&!this.project.diggestedBuiltInBaseEntitiesIds.has(this.id)&&this.project.diggestedBuiltInBaseEntitiesIds.has(this.defaultValue.id)){const f=this.defaultValue.clone(i,this);this.setDefaultValue(f,i)}return this.initialized=!0,this.captureVersion(),i==null||i.attemptAutoclose(w.AfterAllChildrenInitialized,this.id),{updated:C(r),added:C(a),removed:C(c),affected:C(e),self:this}}addSelfToProject(i=this.project.addChangeSet(new S(this.project,N.sessionAuthor,B().toISOString(),this,!0,"add-self-to-project"))){var f,h,m;const r=[this],a=[],c=[],e=[];return this.parentRelationType===U.FixedArguments||this.parentRelationType===U.DynamicArgument?((f=this.parent)==null?void 0:f.type)===d.Search?(this.parent.addInputDeclaration(this,i),e.push(this.parent)):((m=(h=this.parent)==null?void 0:h.addInput)==null||m.call(h,this,i),r.push(this.parent)):this.parentRelationType===U.ReturnedError&&this.parent&&(this.parent.error=this,e.push(this.parent)),this.subscribe(),this.subscribeToDependencies(),i==null||i.attemptAutoclose("add-self-to-project",this.id),{updated:C(r),added:C(a),removed:C(c),affected:C(e),self:this}}setParent(i,r=this.project.addChangeSet(new S(this.project,N.sessionAuthor,B().toISOString(),this,!0,w.SetParent))){var a;return this.checkCanEditWithCounterpartAndSideEffects(this,i,w.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(w.SetParent,this.id),this):this}initChildren(i=this.project.addChangeSet(new S(this.project,N.sessionAuthor,B().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.initialData.defaultValue&&(this.defaultValue=Ae(this.initialData.defaultValue,this.project),this.defaultValue.setParent(this,null),this.defaultValue.initChildren(i)),this.initialData.dataType&&(this.dataType=Ae(this.initialData.dataType,this.project),this.dataType.setParent(this,null),this.dataType.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 S(this.project,N.sessionAuthor,B().toISOString(),this,!0,"meta-sync"))){const a=zr(this,i,r),c=Wr(this,a),e=this.toMeta();return this.name=a.name!==void 0?a.name:e.name,this.codeName=a.codeName!==void 0?a.codeName:e.codeName,this.description=a.description!==void 0?a.description:e.description,this.index=a.index||(a.index!==0?e.index:0),this.required=a.required!==void 0?a.required:this.required,this.parentRelationType=a.parentRelationType!==void 0?a.parentRelationType:this.parentRelationType,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=Se,...r){return await mi.repository.APILoad(this.id,...r),this}async APICreate(i=Se,...r){return await mi.repository.APICreate(this.toShallowJSON(),...r),this}async APIUpdate(i=Se,...r){return await mi.repository.APIUpdate(this.toShallowJSON(),...r),this}async APIDelete(i=Se,...r){return await mi.repository.APIDelete(this.toShallowJSON(),...r),this}async APIClone(i=Se,...r){return await mi.repository.APIClone(this.id,...r),this}async APILoadVersion(i=Se,r,...a){return await mi.repository.APILoadVersion(this.id,r,...a)}removeFromParent(i=this.project.addChangeSet(new S(this.project,N.sessionAuthor,B().toISOString(),this,!0,w.RemoveFromParent))){var f,h,m;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(w.RemoveFromParent,this.id),{added:[],updated:[],removed:[],affected:[],self:this};const r=[],a=[],c=[],e=[];return this.parent&&(((f=this.parent)==null?void 0:f.type)===d.Search?this.parentRelationType===U.FixedArguments||this.parentRelationType===U.DynamicArgument?((h=this.parent)==null||h.removeInputDeclaration(this,i),e.push(this.parent)):this.parentRelationType===U.ReturnedError&&(this.parent.error=null,e.push(this.parent)):(this.parentRelationType===U.FixedArguments||this.parentRelationType===U.DynamicArgument)&&((m=this.parent)==null||m.removeInput(this,i),e.push(this.parent))),i==null||i.attemptAutoclose(w.RemoveFromParent,this.id),{added:C(c),updated:C(r),removed:C(a),affected:C(e),self:this}}remove({ignoreUpstream:i}={ignoreUpstream:!1},r=this.project.addChangeSet(new S(this.project,N.sessionAuthor,B().toISOString(),this,!0,w.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:`${w.RemoveEntity}-${this.id}--${Me.ActionOwnerEntityNonDeletable}`,action:w.RemoveEntity,owner:this,errorReason:Me.ActionOwnerEntityNonDeletable,rootAction:((h=r==null?void 0:r.self)==null?void 0:h.id)===this.id&&(r==null?void 0:r.autoCloseActionName)===w.RemoveEntity}),r==null||r.attemptAutoclose(w.RemoveEntity,this.id),{added:[],updated:[],removed:[],affected:[],self:this};const a=[],c=[],e=[],f=[];if(this.project.diggestedBuiltInBaseEntitiesIds.has(this.id))return r==null||r.attemptAutoclose(w.RemoveEntity,this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(r!=null&&r.hasRemoved(this.id))return r==null||r.attemptAutoclose(w.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(m=>{const{updated:E,removed:b,added:g}=m.entity.onDetachedDependencyRemoved(this,m.field,r);a.push(...E),c.push(...b),e.push(...g)}),this.defaultValue){const{updated:m,removed:E}=this.defaultValue.remove({ignoreUpstream:!0},r);a.push(...m),c.push(...E)}if(this.dataType){const{updated:m,removed:E}=this.dataType.remove({ignoreUpstream:!0},r);a.push(...m),c.push(...E)}if(!i){const m=this.removeFromParent(r);e.push(...m.added),a.push(...m.updated),c.push(...m.removed),f.push(...m.affected)}return r==null||r.attemptAutoclose(w.RemoveEntity,this.id),{added:C(e),updated:C(a),removed:C(c),affected:C(f),self:this}}restore({}={},i=this.project.addChangeSet(new S(this.project,N.sessionAuthor,B().toISOString(),this,!0,w.RestoreEntity))){var f,h,m;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(w.RestoreEntity,this.id),{added:[],updated:[],removed:[],affected:[],self:this};const r=[],a=[],c=[],e=[];if(i!=null&&i.hasAdded(this.id))return i==null||i.attemptAutoclose(w.RestoreEntity,this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},i),Object.values(this.detachedDependents).forEach(E=>{const{updated:b,removed:g,added:_}=E.entity.onDetachedDependencyRestored(this,E.field,i);a.push(...b),c.push(...g),r.push(..._)}),this.defaultValue){const{updated:E}=this.defaultValue.restore({},i);a.push(...E)}if(this.dataType){const{updated:E}=this.dataType.restore({},i);a.push(...E)}return((f=this.parent)==null?void 0:f.type)===d.Search?(this.parentRelationType===U.FixedArguments||this.parentRelationType===U.DynamicArgument)&&((h=this.parent)==null||h.addInputDeclaration(this,i)):(this.parentRelationType===U.FixedArguments||this.parentRelationType===U.DynamicArgument)&&((m=this.parent)==null||m.addInput(this,i)),i==null||i.attemptAutoclose(w.RestoreEntity,this.id),{added:C(r),updated:C(a),removed:C(c),affected:C(e),self:this}}toFlat(i=new Set){var a;return i.has(this.id)?[]:(i.add(this.id),[this,...((a=this.defaultValue)==null?void 0:a.toFlat(i))||[],...this.dataType?this.dataType.toFlat(i):[]])}toFlatIds(i=new Set){var a;return i.has(this.id)?[]:(i.add(this.id),[this.id,...((a=this.defaultValue)==null?void 0:a.toFlatIds(i))||[],...this.dataType?this.dataType.toFlatIds(i):[]])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,codeName:this.codeName,description:this.description,index:this.index,required:this.required,parentRelationType:this.parentRelationType,type:this.type,editable:this.editable,deletable:this.deletable,name:this.name}}toJSON(i=new Set){var r,a,c;return i.has(this.id)?this.toReference():(i.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,editable:this.editable,deletable:this.deletable,name:this.name,codeName:this.codeName,description:this.description,index:this.index,required:this.required,defaultValue:((r=this.defaultValue)==null?void 0:r.toJSON(i))||null,parentRelationType:this.parentRelationType,dataType:((a=this.dataType)==null?void 0:a.toJSON(i))||null,parent:((c=this.parent)==null?void 0:c.toReference())||null})}toJSONClone(i=nt){var a,c,e,f,h,m,E,b;let r;return(a=i.seenEntityMaps)!=null&&a.has(this.id)?r=i.seenEntityMaps.get(this.id):(r=i.newId||en(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(),author:N.sessionAuthor,previousVersion:null,deleted:!1,type:this.type,editable:this.editable,deletable:this.deletable,name:this.name,codeName:this.codeName,description:this.description,index:this.index,required:this.required,defaultValue:((m=this.defaultValue)==null?void 0:m.toJSONClone({...i,newId:null}))||null,parentRelationType:this.parentRelationType,dataType:((E=this.dataType)==null?void 0:E.toJSONClone({...i,newId:null}))||null,parent:((b=this.parent)==null?void 0:b.toReference({seenEntityMaps:i.seenEntityMaps}))||null})}toReference(i=nt){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=nt){var a,c,e,f;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,type:this.type,editable:this.editable,deletable:this.deletable,name:this.name,codeName:this.codeName,description:this.description,index:this.index,required:this.required,parentRelationType:this.parentRelationType,defaultValue:((c=this.defaultValue)==null?void 0:c.toReference(i))||null,dataType:((e=this.dataType)==null?void 0:e.toReference(i))||null,parent:((f=this.parent)==null?void 0:f.toReference(i))||null}}toFlatJSON(i=new Set){var a;return i.has(this.id)?[]:(i.add(this.id),[this.toShallowJSON(),...((a=this.defaultValue)==null?void 0:a.toFlatJSON(i))||[],...this.dataType?this.dataType.toFlatJSON(i):[]])}toGenerationTarget(i=nt){var a,c;let r=this.id;return(a=i.seenEntityMaps)!=null&&a.has(this.id)&&(r=i.seenEntityMaps.get(this.id)),{id:r,name:this.name,codeName:this.codeName,description:this.description,type:this.type,required:this.required,parentRelationType:this.parentRelationType,parent:(c=this.parent)==null?void 0:c.id}}toFlatGenerationTarget(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.toGenerationTarget(),...this.defaultValue?this.defaultValue.toFlatGenerationTarget(i):[],...this.dataType?this.dataType.toFlatGenerationTarget(i):[]])}clearErrors(){var i,r;return this.errors=[],(i=this.defaultValue)==null||i.clearErrors(),(r=this.dataType)==null||r.clearErrors(),this}validate(){return this.errors=WBe(this),{success:!0}}async validateAsync(i={}){const r=z.YieldTracker.from(i);return this.errors=await HBe(this,{tracker:r}),{success:!0}}getErrors(){return[...this.errors,...this.dataType?this.dataType.getErrors():[]]}async getErrorsAsync(i={}){const r=z.YieldTracker.from(i),a=[...this.errors];if(await r.tick(),this.dataType){const c=await this.dataType.getErrorsAsync({tracker:r});a.push(...c)}return a}getShallowErrors(){return this.errors}clone(i=this.project.addChangeSet(new S(this.project,N.sessionAuthor,B().toISOString(),this,!0,w.CloneEntity)),r=null,a=null,c=!0){var g,_;if(this.project.diggestedBuiltInBaseEntitiesIds.has(this.id))return this;const e=Mr(r,this),f=a||N.UUID.uuid(),h=this.toJSON();h.id=f,h.version=N.UUID.uuid(),h.createdAt=(i==null?void 0:i.timestamp)||B().toISOString(),h.author=(i==null?void 0:i.author)||"1",h.previousVersion=null,h.deleted=!1,h.deletable=!0,h.editable=!0;const m=tr(h,e);r&&m.setParent(r,i),i==null||i.add(m,W.Added),c&&m.subscribe();const E=((g=this.dataType)==null?void 0:g.clone(i,m,N.UUID.uuid(),c))||null;E&&m.setDataType(E,i);const b=(_=this.defaultValue)==null?void 0:_.clone(i,m,N.UUID.uuid(),c);return m.defaultValue=b||null,i==null||i.attemptAutoclose(w.CloneEntity,this.id),m}getDataType(i=this.project.addChangeSet(new S(this.project,N.sessionAuthor,B().toISOString(),this,!0,"get-data-type"))){return i==null||i.attemptAutoclose("get-data-type",this.id),this.dataType||null}setDataType(i,r=this.project.addChangeSet(new S(this.project,N.sessionAuthor,B().toISOString(),this,!0,w.SetDataType))){if(!this.checkCanEdit(this,r))return z.Logger.warn(`[setDataType] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),r==null||r.attemptAutoclose(w.SetDataType,this.id),this;const a=this.dataType;return(a==null?void 0:a.id)!==(i==null?void 0:i.id)&&(a==null||a.remove({ignoreUpstream:!0},r),this.dataType=i,this.subscribeToDependencies(),r==null||r.add(this,W.Affected)),r==null||r.attemptAutoclose(w.SetDataType,this.id),this}getDefaultValue(){return this.defaultValue||null}setDefaultValue(i,r=this.project.addChangeSet(new S(this.project,N.sessionAuthor,B().toISOString(),this,!0,"set-default-value"))){if(!this.checkCanEdit(this,r))return z.Logger.warn(`[setDefaultValue] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),r==null||r.attemptAutoclose("set-default-value",this.id),this;const a=this.defaultValue;return(a==null?void 0:a.id)!==(i==null?void 0:i.id)&&(a==null||a.remove({ignoreUpstream:!0},r),this.defaultValue=i,r==null||r.add(this,W.Affected)),r==null||r.attemptAutoclose("set-default-value",this.id),this}removeDataType(i=this.project.addChangeSet(new S(this.project,N.sessionAuthor,B().toISOString(),this,!0,w.RemoveDataType))){return this.checkCanEdit(this,i)?(this.dataType&&(this.dataType.remove({ignoreUpstream:!0},i),i==null||i.add(this,W.Affected),this.dataType=null),i==null||i.attemptAutoclose(w.RemoveDataType,this.id),this):(z.Logger.warn(`[removeDataType] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(w.RemoveDataType,this.id),this)}implementAsInputMap(i=this.project.addChangeSet(new S(this.project,N.sessionAuthor,B().toISOString(),this,!0,"implement-as-input-map")),r,a){const c=ts.new(i);c.id=a||c.id,c.name=this.name,c.description=this.description,c.parent=r.toReference(),c.declaration=this.toJSON(),c.parentRelationType=this.parentRelationType===U.ReturnedError?Wo.Error:null;const e=tr(c,this.project);if(e.hydrateAncestors(),e.addSelfToProject(i),i==null||i.add(e,W.Added),e.initChildren(i),this.dataType){const f=this.dataType.clone(i,e);e.setDataType(f,i)}if(this.defaultValue){const f=this.defaultValue.clone(i,e);e.setDefaultValue(f,i)}return i==null||i.attemptAutoclose("implement-as-input-map",this.id),e}implementAsArgumentDeclaration(i=this.project.addChangeSet(new S(this.project,N.sessionAuthor,B().toISOString(),this,!0,"implement-as-argument-declaration")),r,a){const c=xa.new(i);c.id=a||c.id,c.name=this.name,c.description=this.description,c.parent=r.toReference(),c.implements=[this.toJSON()];const e=tr(c,this.project);if(e.hydrateAncestors(),e.addSelfToProject(i),i==null||i.add(e,W.Added),e.initChildren(i),this.dataType){const f=this.dataType.clone(i,e);e.setDataType(f,i)}if(this.defaultValue){const f=this.defaultValue.clone(i,e);e.setDefaultValue(f,i)}return i==null||i.attemptAutoclose("implement-as-argument-declaration",this.id),e}};R(mi,"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(mi,"type",d.ValueDescriptor),R(mi,"USER_MANAGED_PARENT_TYPES",[d.ActionDescriptor,d.Search]),R(mi,"PARENT_TYPES",[...mi.USER_MANAGED_PARENT_TYPES]),R(mi,"MUTABLE_BASE_PROPERTIES",["name","codeName","description","required"]),R(mi,"INMUTABLE_BASE_PROPERTIES",["id","version","type","parentRelationType","createdAt","author","previousVersion"]),R(mi,"BASE_PROPERTIES",[...mi.MUTABLE_BASE_PROPERTIES,...mi.INMUTABLE_BASE_PROPERTIES]),R(mi,"MUTABLE_META_PROPERTIES",[...mi.MUTABLE_BASE_PROPERTIES,"index"]),R(mi,"INMUTABLE_META_PROPERTIES",[...mi.INMUTABLE_BASE_PROPERTIES]),R(mi,"META_PROPERTIES",[...mi.MUTABLE_META_PROPERTIES,...mi.INMUTABLE_META_PROPERTIES]),R(mi,"MUTABLE_UPSTREAM_PROPERTIES",[]),R(mi,"INMUTABLE_UPSTREAM_PROPERTIES",["parent"]),R(mi,"UPSTREAM_PROPERTIES",[...mi.MUTABLE_UPSTREAM_PROPERTIES,...mi.INMUTABLE_UPSTREAM_PROPERTIES]),R(mi,"MUTABLE_DOWNSTREAM_PROPERTIES",["dataType","defaultValue"]),R(mi,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),R(mi,"DOWNSTREAM_PROPERTIES",[...mi.MUTABLE_DOWNSTREAM_PROPERTIES,...mi.INMUTABLE_DOWNSTREAM_PROPERTIES]),R(mi,"PROPERTIES",[...mi.META_PROPERTIES,...mi.UPSTREAM_PROPERTIES,...mi.DOWNSTREAM_PROPERTIES]);let rd=mi;var ip={},YBe={},JBe={};Object.defineProperty(JBe,"__esModule",{value:!0});var QBe={};Object.defineProperty(QBe,"__esModule",{value:!0});var XBe={};Object.defineProperty(XBe,"__esModule",{value:!0});var eMe={};Object.defineProperty(eMe,"__esModule",{value:!0});var tMe={};Object.defineProperty(tMe,"__esModule",{value:!0});var iMe={};Object.defineProperty(iMe,"__esModule",{value:!0});var rMe={};Object.defineProperty(rMe,"__esModule",{value:!0});var nMe={};Object.defineProperty(nMe,"__esModule",{value:!0});var aMe={};Object.defineProperty(aMe,"__esModule",{value:!0});var sMe={};Object.defineProperty(sMe,"__esModule",{value:!0});var lMe={};Object.defineProperty(lMe,"__esModule",{value:!0});var oMe={};Object.defineProperty(oMe,"__esModule",{value:!0});var dMe={};Object.defineProperty(dMe,"__esModule",{value:!0});var uMe={};Object.defineProperty(uMe,"__esModule",{value:!0});var pMe={};Object.defineProperty(pMe,"__esModule",{value:!0});var cMe={};Object.defineProperty(cMe,"__esModule",{value:!0});var fMe={};Object.defineProperty(fMe,"__esModule",{value:!0});var yMe={};Object.defineProperty(yMe,"__esModule",{value:!0});var hMe={};Object.defineProperty(hMe,"__esModule",{value:!0});var mMe={};Object.defineProperty(mMe,"__esModule",{value:!0});var TMe={};Object.defineProperty(TMe,"__esModule",{value:!0});var vMe={};Object.defineProperty(vMe,"__esModule",{value:!0});var EMe={};Object.defineProperty(EMe,"__esModule",{value:!0});var bMe={};Object.defineProperty(bMe,"__esModule",{value:!0});var AMe={};Object.defineProperty(AMe,"__esModule",{value:!0});var gMe={};Object.defineProperty(gMe,"__esModule",{value:!0});var IMe={};Object.defineProperty(IMe,"__esModule",{value:!0});var RMe={};Object.defineProperty(RMe,"__esModule",{value:!0});var DMe={};Object.defineProperty(DMe,"__esModule",{value:!0});var wMe={};Object.defineProperty(wMe,"__esModule",{value:!0});var CMe={};Object.defineProperty(CMe,"__esModule",{value:!0});var OMe={};Object.defineProperty(OMe,"__esModule",{value:!0});var _Me={};Object.defineProperty(_Me,"__esModule",{value:!0});var VMe={};Object.defineProperty(VMe,"__esModule",{value:!0});var PMe={};Object.defineProperty(PMe,"__esModule",{value:!0});var NMe={};Object.defineProperty(NMe,"__esModule",{value:!0});var xMe={};Object.defineProperty(xMe,"__esModule",{value:!0});var $Me={};Object.defineProperty($Me,"__esModule",{value:!0});var LMe={};Object.defineProperty(LMe,"__esModule",{value:!0});var BMe={};Object.defineProperty(BMe,"__esModule",{value:!0});var MMe={};Object.defineProperty(MMe,"__esModule",{value:!0});var GMe={};Object.defineProperty(GMe,"__esModule",{value:!0});var jMe={};Object.defineProperty(jMe,"__esModule",{value:!0});(function(l){var p=qr&&qr.__createBinding||(Object.create?function(r,a,c,e){e===void 0&&(e=c);var f=Object.getOwnPropertyDescriptor(a,c);(!f||("get"in f?!a.__esModule:f.writable||f.configurable))&&(f={enumerable:!0,get:function(){return a[c]}}),Object.defineProperty(r,e,f)}:function(r,a,c,e){e===void 0&&(e=c),r[e]=a[c]}),i=qr&&qr.__exportStar||function(r,a){for(var c in r)c!=="default"&&!Object.prototype.hasOwnProperty.call(a,c)&&p(a,r,c)};Object.defineProperty(l,"__esModule",{value:!0}),i(JBe,l),i(QBe,l),i(XBe,l),i(eMe,l),i(tMe,l),i(iMe,l),i(rMe,l),i(nMe,l),i(aMe,l),i(sMe,l),i(lMe,l),i(oMe,l),i(dMe,l),i(uMe,l),i(pMe,l),i(cMe,l),i(fMe,l),i(yMe,l),i(hMe,l),i(mMe,l),i(TMe,l),i(vMe,l),i(EMe,l),i(bMe,l),i(AMe,l),i(gMe,l),i(IMe,l),i(RMe,l),i(DMe,l),i(wMe,l),i(CMe,l),i(OMe,l),i(_Me,l),i(VMe,l),i(PMe,l),i(NMe,l),i(xMe,l),i($Me,l),i(LMe,l),i(BMe,l),i(MMe,l),i(GMe,l),i(jMe,l)})(YBe);var UMe={},ya={};Object.defineProperty(ya,"__esModule",{value:!0});ya.isObject=ya.isString=ya.isDefined=ya.last=ya.identity=void 0;const CRi=l=>l;ya.identity=CRi;const ORi=l=>l[l.length-1];ya.last=ORi;const _Ri=l=>l!==void 0;ya.isDefined=_Ri;const VRi=l=>typeof l=="string";ya.isString=VRi;const PRi=l=>typeof l=="object"&&l!==null&&!(l instanceof Array);ya.isObject=PRi;(function(l){Object.defineProperty(l,"__esModule",{value:!0}),l.cstVisitor=l.VisitorAction=void 0;const p=ya;var i;(function(c){c[c.SKIP=1]="SKIP"})(i=l.VisitorAction||(l.VisitorAction={}));function r(c){const e=f=>{const h=c[f.type];if((h==null?void 0:h(f))!==i.SKIP)for(const E of Object.values(f))a(E)?e(E):E instanceof Array&&E.filter(a).forEach(b=>e(b))};return e}l.cstVisitor=r;const a=c=>(0,p.isObject)(c)&&(0,p.isString)(c.type)})(UMe);var dE={};Object.defineProperty(dE,"__esModule",{value:!0});dE.cstTransformer=void 0;function NRi(l){return p=>{const i=l[p.type];if(!i)throw p.type?new Error(`No transform map entry for ${p.type}`):new Error(`No type field on node: ${JSON.stringify(p)}`);return i(p)}}dE.cstTransformer=NRi;var kMe={},uE={};Object.defineProperty(uE,"__esModule",{value:!0});uE.bigqueryKeywords=void 0;uE.bigqueryKeywords={ALL:!0,AND:!0,ANY:!0,ARRAY:!0,AS:!0,ASC:!0,ASSERT_ROWS_MODIFIED:!0,AT:!0,BETWEEN:!0,BY:!0,CASE:!0,CAST:!0,COLLATE:!0,CONTAINS:!0,CREATE:!0,CROSS:!0,CUBE:!0,CURRENT:!0,DEFAULT:!0,DEFINE:!0,DESC:!0,DISTINCT:!0,ELSE:!0,END:!0,ENUM:!0,ESCAPE:!0,EXCEPT:!0,EXCLUDE:!0,EXISTS:!0,EXTRACT:!0,FALSE:!0,FETCH:!0,FOLLOWING:!0,FOR:!0,FROM:!0,FULL:!0,GROUP:!0,GROUPING:!0,GROUPS:!0,HASH:!0,HAVING:!0,IF:!0,IGNORE:!0,IN:!0,INNER:!0,INTERSECT:!0,INTERVAL:!0,INTO:!0,IS:!0,JOIN:!0,LATERAL:!0,LEFT:!0,LIKE:!0,LIMIT:!0,LOOKUP:!0,MERGE:!0,NATURAL:!0,NEW:!0,NO:!0,NOT:!0,NULL:!0,NULLS:!0,OF:!0,ON:!0,OR:!0,ORDER:!0,OUTER:!0,OVER:!0,PARTITION:!0,PRECEDING:!0,PROTO:!0,QUALIFY:!0,RANGE:!0,RECURSIVE:!0,RESPECT:!0,RIGHT:!0,ROLLUP:!0,ROWS:!0,SELECT:!0,SET:!0,SOME:!0,STRUCT:!0,TABLESAMPLE:!0,THEN:!0,TO:!0,TREAT:!0,TRUE:!0,UNBOUNDED:!0,UNION:!0,UNNEST:!0,USING:!0,WHEN:!0,WHERE:!0,WINDOW:!0,WITH:!0,WITHIN:!0};var pE={};Object.defineProperty(pE,"__esModule",{value:!0});pE.mariadbKeywords=void 0;pE.mariadbKeywords={ACCESSIBLE:!0,ADD:!0,ALL:!0,ALTER:!0,ANALYZE:!0,AND:!0,AS:!0,ASC:!0,ASENSITIVE:!0,BEFORE:!0,BETWEEN:!0,BIGINT:!0,BINARY:!0,BLOB:!0,BOTH:!0,BY:!0,CALL:!0,CASCADE:!0,CASE:!0,CHANGE:!0,CHAR:!0,CHARACTER:!0,CHECK:!0,COLLATE:!0,COLUMN:!0,CONDITION:!0,CONSTRAINT:!0,CONTINUE:!0,CONVERT:!0,CREATE:!0,CROSS:!0,CURRENT_DATE:!0,CURRENT_ROLE:!0,CURRENT_TIME:!0,CURRENT_TIMESTAMP:!0,CURRENT_USER:!0,CURSOR:!0,DATABASE:!0,DATABASES:!0,DAY_HOUR:!0,DAY_MICROSECOND:!0,DAY_MINUTE:!0,DAY_SECOND:!0,DEC:!0,DECIMAL:!0,DECLARE:!0,DEFAULT:!0,DELAYED:!0,DELETE:!0,DELETE_DOMAIN_ID:!0,DESC:!0,DESCRIBE:!0,DETERMINISTIC:!0,DISTINCT:!0,DISTINCTROW:!0,DIV:!0,DO_DOMAIN_IDS:!0,DOUBLE:!0,DROP:!0,DUAL:!0,EACH:!0,ELSE:!0,ELSEIF:!0,ENCLOSED:!0,ESCAPED:!0,EXCEPT:!0,EXISTS:!0,EXIT:!0,EXPLAIN:!0,FALSE:!0,FETCH:!0,FLOAT:!0,FLOAT4:!0,FLOAT8:!0,FOR:!0,FORCE:!0,FOREIGN:!0,FROM:!0,FULLTEXT:!0,GENERAL:!0,GRANT:!0,GROUP:!0,HAVING:!0,HIGH_PRIORITY:!0,HOUR_MICROSECOND:!0,HOUR_MINUTE:!0,HOUR_SECOND:!0,IF:!0,IGNORE:!0,IGNORE_DOMAIN_IDS:!0,IGNORE_SERVER_IDS:!0,IN:!0,INDEX:!0,INFILE:!0,INNER:!0,INOUT:!0,INSENSITIVE:!0,INSERT:!0,INT:!0,INT1:!0,INT2:!0,INT3:!0,INT4:!0,INT8:!0,INTEGER:!0,INTERSECT:!0,INTERVAL:!0,INTO:!0,IS:!0,ITERATE:!0,JOIN:!0,KEY:!0,KEYS:!0,KILL:!0,LEADING:!0,LEAVE:!0,LEFT:!0,LIKE:!0,LIMIT:!0,LINEAR:!0,LINES:!0,LOAD:!0,LOCALTIME:!0,LOCALTIMESTAMP:!0,LOCK:!0,LONG:!0,LONGBLOB:!0,LONGTEXT:!0,LOOP:!0,LOW_PRIORITY:!0,MASTER_HEARTBEAT_PERIOD:!0,MASTER_SSL_VERIFY_SERVER_CERT:!0,MATCH:!0,MAXVALUE:!0,MEDIUMBLOB:!0,MEDIUMINT:!0,MEDIUMTEXT:!0,MIDDLEINT:!0,MINUTE_MICROSECOND:!0,MINUTE_SECOND:!0,MOD:!0,MODIFIES:!0,NATURAL:!0,NOT:!0,NO_WRITE_TO_BINLOG:!0,NULL:!0,NUMERIC:!0,OFFSET:!0,ON:!0,OPTIMIZE:!0,OPTION:!0,OPTIONALLY:!0,OR:!0,ORDER:!0,OUT:!0,OUTER:!0,OUTFILE:!0,OVER:!0,PAGE_CHECKSUM:!0,PARSE_VCOL_EXPR:!0,PARTITION:!0,POSITION:!0,PRECISION:!0,PRIMARY:!0,PROCEDURE:!0,PURGE:!0,RANGE:!0,READ:!0,READS:!0,READ_WRITE:!0,REAL:!0,RECURSIVE:!0,REF_SYSTEM_ID:!0,REFERENCES:!0,REGEXP:!0,RELEASE:!0,RENAME:!0,REPEAT:!0,REPLACE:!0,REQUIRE:!0,RESIGNAL:!0,RESTRICT:!0,RETURN:!0,RETURNING:!0,REVOKE:!0,RIGHT:!0,RLIKE:!0,ROWS:!0,SCHEMA:!0,SCHEMAS:!0,SECOND_MICROSECOND:!0,SELECT:!0,SENSITIVE:!0,SEPARATOR:!0,SET:!0,SHOW:!0,SIGNAL:!0,SLOW:!0,SMALLINT:!0,SPATIAL:!0,SPECIFIC:!0,SQL:!0,SQLEXCEPTION:!0,SQLSTATE:!0,SQLWARNING:!0,SQL_BIG_RESULT:!0,SQL_CALC_FOUND_ROWS:!0,SQL_SMALL_RESULT:!0,SSL:!0,STARTING:!0,STATS_AUTO_RECALC:!0,STATS_PERSISTENT:!0,STATS_SAMPLE_PAGES:!0,STRAIGHT_JOIN:!0,TABLE:!0,TERMINATED:!0,THEN:!0,TINYBLOB:!0,TINYINT:!0,TINYTEXT:!0,TO:!0,TRAILING:!0,TRIGGER:!0,TRUE:!0,UNDO:!0,UNION:!0,UNIQUE:!0,UNLOCK:!0,UNSIGNED:!0,UPDATE:!0,USAGE:!0,USE:!0,USING:!0,UTC_DATE:!0,UTC_TIME:!0,UTC_TIMESTAMP:!0,VALUES:!0,VARBINARY:!0,VARCHAR:!0,VARCHARACTER:!0,VARYING:!0,WHEN:!0,WHERE:!0,WHILE:!0,WINDOW:!0,WITH:!0,WRITE:!0,XOR:!0,YEAR_MONTH:!0,ZEROFILL:!0};var cE={};Object.defineProperty(cE,"__esModule",{value:!0});cE.mysqlKeywords=void 0;cE.mysqlKeywords={ACCESSIBLE:!0,ADD:!0,ALL:!0,ALTER:!0,ANALYZE:!0,AND:!0,AS:!0,ASC:!0,ASENSITIVE:!0,BEFORE:!0,BETWEEN:!0,BIGINT:!0,BINARY:!0,BLOB:!0,BOTH:!0,BY:!0,CALL:!0,CASCADE:!0,CASE:!0,CHANGE:!0,CHAR:!0,CHARACTER:!0,CHECK:!0,COLLATE:!0,COLUMN:!0,CONDITION:!0,CONSTRAINT:!0,CONTINUE:!0,CONVERT:!0,CREATE:!0,CROSS:!0,CUBE:!0,CUME_DIST:!0,CURRENT_DATE:!0,CURRENT_TIME:!0,CURRENT_TIMESTAMP:!0,CURRENT_USER:!0,CURSOR:!0,DATABASE:!0,DATABASES:!0,DAY_HOUR:!0,DAY_MICROSECOND:!0,DAY_MINUTE:!0,DAY_SECOND:!0,DEC:!0,DECIMAL:!0,DECLARE:!0,DEFAULT:!0,DELAYED:!0,DELETE:!0,DENSE_RANK:!0,DESC:!0,DESCRIBE:!0,DETERMINISTIC:!0,DISTINCT:!0,DISTINCTROW:!0,DIV:!0,DOUBLE:!0,DROP:!0,DUAL:!0,EACH:!0,ELSE:!0,ELSEIF:!0,EMPTY:!0,ENCLOSED:!0,ESCAPED:!0,EXCEPT:!0,EXISTS:!0,EXIT:!0,EXPLAIN:!0,FALSE:!0,FETCH:!0,FIRST_VALUE:!0,FLOAT:!0,FLOAT4:!0,FLOAT8:!0,FOR:!0,FORCE:!0,FOREIGN:!0,FROM:!0,FULLTEXT:!0,FUNCTION:!0,GENERATED:!0,GET:!0,GRANT:!0,GROUP:!0,GROUPING:!0,GROUPS:!0,HAVING:!0,HIGH_PRIORITY:!0,HOUR_MICROSECOND:!0,HOUR_MINUTE:!0,HOUR_SECOND:!0,IF:!0,IGNORE:!0,IN:!0,INDEX:!0,INFILE:!0,INNER:!0,INOUT:!0,INSENSITIVE:!0,INSERT:!0,INT:!0,INT1:!0,INT2:!0,INT3:!0,INT4:!0,INT8:!0,INTEGER:!0,INTERSECT:!0,INTERVAL:!0,INTO:!0,IO_AFTER_GTIDS:!0,IO_BEFORE_GTIDS:!0,IS:!0,ITERATE:!0,JOIN:!0,JSON_TABLE:!0,KEY:!0,KEYS:!0,KILL:!0,LAG:!0,LAST_VALUE:!0,LATERAL:!0,LEAD:!0,LEADING:!0,LEAVE:!0,LEFT:!0,LIKE:!0,LIMIT:!0,LINEAR:!0,LINES:!0,LOAD:!0,LOCALTIME:!0,LOCALTIMESTAMP:!0,LOCK:!0,LONG:!0,LONGBLOB:!0,LONGTEXT:!0,LOOP:!0,LOW_PRIORITY:!0,MASTER_BIND:!0,MASTER_SSL_VERIFY_SERVER_CERT:!0,MATCH:!0,MAXVALUE:!0,MEDIUMBLOB:!0,MEDIUMINT:!0,MEDIUMTEXT:!0,MIDDLEINT:!0,MINUTE_MICROSECOND:!0,MINUTE_SECOND:!0,MOD:!0,MODIFIES:!0,NATURAL:!0,NOT:!0,NO_WRITE_TO_BINLOG:!0,NTH_VALUE:!0,NTILE:!0,NULL:!0,NUMERIC:!0,OF:!0,ON:!0,OPTIMIZE:!0,OPTIMIZER_COSTS:!0,OPTION:!0,OPTIONALLY:!0,OR:!0,ORDER:!0,OUT:!0,OUTER:!0,OUTFILE:!0,OVER:!0,PARTITION:!0,PERCENT_RANK:!0,PRECISION:!0,PRIMARY:!0,PROCEDURE:!0,PURGE:!0,RANGE:!0,RANK:!0,READ:!0,READS:!0,READ_WRITE:!0,REAL:!0,RECURSIVE:!0,REFERENCES:!0,REGEXP:!0,RELEASE:!0,RENAME:!0,REPEAT:!0,REPLACE:!0,REQUIRE:!0,RESIGNAL:!0,RESTRICT:!0,RETURN:!0,REVOKE:!0,RIGHT:!0,RLIKE:!0,ROW:!0,ROWS:!0,ROW_NUMBER:!0,SCHEMA:!0,SCHEMAS:!0,SECOND_MICROSECOND:!0,SELECT:!0,SENSITIVE:!0,SEPARATOR:!0,SET:!0,SHOW:!0,SIGNAL:!0,SMALLINT:!0,SPATIAL:!0,SPECIFIC:!0,SQL:!0,SQLEXCEPTION:!0,SQLSTATE:!0,SQLWARNING:!0,SQL_BIG_RESULT:!0,SQL_CALC_FOUND_ROWS:!0,SQL_SMALL_RESULT:!0,SSL:!0,STARTING:!0,STORED:!0,STRAIGHT_JOIN:!0,SYSTEM:!0,TABLE:!0,TERMINATED:!0,THEN:!0,TINYBLOB:!0,TINYINT:!0,TINYTEXT:!0,TO:!0,TRAILING:!0,TRIGGER:!0,TRUE:!0,UNDO:!0,UNION:!0,UNIQUE:!0,UNLOCK:!0,UNSIGNED:!0,UPDATE:!0,USAGE:!0,USE:!0,USING:!0,UTC_DATE:!0,UTC_TIME:!0,UTC_TIMESTAMP:!0,VALUES:!0,VARBINARY:!0,VARCHAR:!0,VARCHARACTER:!0,VARYING:!0,VIRTUAL:!0,WHEN:!0,WHERE:!0,WHILE:!0,WINDOW:!0,WITH:!0,WRITE:!0,XOR:!0,YEAR_MONTH:!0,ZEROFILL:!0};var fE={};Object.defineProperty(fE,"__esModule",{value:!0});fE.sqliteKeywords=void 0;fE.sqliteKeywords={ABORT:!0,ACTION:!0,ADD:!0,AFTER:!0,ALL:!0,ALTER:!0,ALWAYS:!0,ANALYZE:!0,AND:!0,AS:!0,ASC:!0,ATTACH:!0,AUTOINCREMENT:!0,BEFORE:!0,BEGIN:!0,BETWEEN:!0,BY:!0,CASCADE:!0,CASE:!0,CAST:!0,CHECK:!0,COLLATE:!0,COMMIT:!0,CONFLICT:!0,CONSTRAINT:!0,CREATE:!0,CROSS:!0,CURRENT:!0,CURRENT_DATE:!0,CURRENT_TIME:!0,CURRENT_TIMESTAMP:!0,DATABASE:!0,DEFAULT:!0,DEFERRABLE:!0,DEFERRED:!0,DELETE:!0,DESC:!0,DETACH:!0,DISTINCT:!0,DO:!0,DROP:!0,EACH:!0,ELSE:!0,END:!0,ESCAPE:!0,EXCEPT:!0,EXCLUDE:!0,EXCLUSIVE:!0,EXISTS:!0,EXPLAIN:!0,FAIL:!0,FILTER:!0,FIRST:!0,FOLLOWING:!0,FOR:!0,FOREIGN:!0,FROM:!0,FULL:!0,GENERATED:!0,GLOB:!0,GROUP:!0,GROUPS:!0,HAVING:!0,IF:!0,IGNORE:!0,IMMEDIATE:!0,IN:!0,INDEX:!0,INDEXED:!0,INITIALLY:!0,INNER:!0,INSERT:!0,INSTEAD:!0,INTERSECT:!0,INTO:!0,IS:!0,ISNULL:!0,JOIN:!0,LAST:!0,LEFT:!0,LIKE:!0,LIMIT:!0,MATCH:!0,MATERIALIZED:!0,NATURAL:!0,NO:!0,NOT:!0,NOTHING:!0,NOTNULL:!0,NULL:!0,NULLS:!0,OF:!0,OFFSET:!0,ON:!0,OR:!0,ORDER:!0,OTHERS:!0,OUTER:!0,OVER:!0,PARTITION:!0,PLAN:!0,PRAGMA:!0,PRECEDING:!0,PRIMARY:!0,QUERY:!0,RAISE:!0,RANGE:!0,RECURSIVE:!0,REFERENCES:!0,REGEXP:!0,REINDEX:!0,RELEASE:!0,RENAME:!0,REPLACE:!0,RESTRICT:!0,RETURNING:!0,RIGHT:!0,ROLLBACK:!0,ROW:!0,ROWS:!0,SAVEPOINT:!0,SELECT:!0,SET:!0,TABLE:!0,TEMP:!0,TEMPORARY:!0,THEN:!0,TIES:!0,TO:!0,TRANSACTION:!0,TRIGGER:!0,UNBOUNDED:!0,UNION:!0,UNIQUE:!0,UPDATE:!0,USING:!0,VACUUM:!0,VALUES:!0,VIEW:!0,VIRTUAL:!0,WHEN:!0,WHERE:!0,WINDOW:!0,WITH:!0,WITHOUT:!0};var yE={};Object.defineProperty(yE,"__esModule",{value:!0});yE.postgresqlKeywords=void 0;yE.postgresqlKeywords={ALL:!0,ANALYSE:!0,ANALYZE:!0,AND:!0,ANY:!0,ARRAY:!0,AS:!0,ASC:!0,ASYMMETRIC:!0,AUTHORIZATION:!0,BOTH:!0,CASE:!0,CAST:!0,CHECK:!0,COLLATE:!0,COLUMN:!0,CONSTRAINT:!0,CREATE:!0,CROSS:!0,CURRENT_CATALOG:!0,CURRENT_DATE:!0,CURRENT_ROLE:!0,CURRENT_SCHEMA:!0,CURRENT_TIME:!0,CURRENT_TIMESTAMP:!0,CURRENT_USER:!0,DAY:!0,DEFAULT:!0,DEFERRABLE:!0,DESC:!0,DISTINCT:!0,DO:!0,ELSE:!0,END:!0,EXCEPT:!0,FALSE:!0,FETCH:!0,FILTER:!0,FOR:!0,FOREIGN:!0,FREEZE:!0,FROM:!0,FULL:!0,GRANT:!0,GROUP:!0,HAVING:!0,HOUR:!0,ILIKE:!0,IN:!0,INITIALLY:!0,INNER:!0,INTERSECT:!0,INTO:!0,IS:!0,ISNULL:!0,JOIN:!0,LATERAL:!0,LEADING:!0,LEFT:!0,LIKE:!0,LIMIT:!0,LOCALTIME:!0,LOCALTIMESTAMP:!0,MINUTE:!0,MONTH:!0,NATURAL:!0,NOT:!0,NOTNULL:!0,NULL:!0,OFFSET:!0,ON:!0,ONLY:!0,OR:!0,ORDER:!0,OUTER:!0,OVER:!0,OVERLAPS:!0,PLACING:!0,PRECISION:!0,PRIMARY:!0,REFERENCES:!0,RETURNING:!0,RIGHT:!0,SECOND:!0,SELECT:!0,SESSION_USER:!0,SIMILAR:!0,SOME:!0,SYMMETRIC:!0,SYSTEM_USER:!0,TABLE:!0,TABLESAMPLE:!0,THEN:!0,TO:!0,TRAILING:!0,TRUE:!0,UNION:!0,UNIQUE:!0,USER:!0,USING:!0,VARIADIC:!0,VARYING:!0,VERBOSE:!0,WHEN:!0,WHERE:!0,WINDOW:!0,WITH:!0,WITHIN:!0,WITHOUT:!0,YEAR:!0,SET:!0};(function(l){var p=qr&&qr.__createBinding||(Object.create?function(r,a,c,e){e===void 0&&(e=c);var f=Object.getOwnPropertyDescriptor(a,c);(!f||("get"in f?!a.__esModule:f.writable||f.configurable))&&(f={enumerable:!0,get:function(){return a[c]}}),Object.defineProperty(r,e,f)}:function(r,a,c,e){e===void 0&&(e=c),r[e]=a[c]}),i=qr&&qr.__exportStar||function(r,a){for(var c in r)c!=="default"&&!Object.prototype.hasOwnProperty.call(a,c)&&p(a,r,c)};Object.defineProperty(l,"__esModule",{value:!0}),i(uE,l),i(pE,l),i(cE,l),i(fE,l),i(yE,l)})(kMe);var kT={};Object.defineProperty(kT,"__esModule",{value:!0});kT.FormattedSyntaxError=void 0;class xRi extends Error{constructor(p,i,r){super($Ri(p,i,r))}}kT.FormattedSyntaxError=xRi;function $Ri(l,p,i){const r=l.location.start.line,a=l.location.start.column,c=p.split(/\r\n|\n|\r/)[r-1],e="".padStart(String(r).length),f=BRi(LRi(l.found,a,c)),h=MRi(l.expected);return`Syntax Error: Unexpected ${f}
112
112
  Was expecting to see: ${h}
113
113
  --> ${i||"undefined"}:${r}:${a}
package/dist/index.d.ts CHANGED
@@ -32734,7 +32734,8 @@ export declare enum BaseValueDescriptorIds {
32734
32734
  CannotValueWriteItself = "cannot-value-write-itself",
32735
32735
  CannotBeCalledBeforeDeclaration = "cannot-be-called-before-declaration",
32736
32736
  CannotBeCalledInParallelBranchToDeclaration = "cannot-be-called-in-parallel-branch-to-declaration",
32737
- CannotBeHigherScopeThanDeclaration = "cannot-be-higher-scope-than-declaration"
32737
+ CannotBeHigherScopeThanDeclaration = "cannot-be-higher-scope-than-declaration",
32738
+ InputsInGlobalVariableDeclarationsCannotReadValues = "inputs-in-global-variable-declarations-cannot-read-values"
32738
32739
  }
32739
32740
 
32740
32741
  export declare const STATIC_PROPERTY_HEIGHT = 49;
package/dist/index.js CHANGED
@@ -79891,7 +79891,7 @@ async function gdi(l, p = {}) {
79891
79891
  }
79892
79892
  return await Promise.all(r), l;
79893
79893
  }
79894
- var g_ = /* @__PURE__ */ ((l) => (l.Manual = "manual", l.Automatic = "automatic", l))(g_ || {}), H = /* @__PURE__ */ ((l) => (l.Added = "added", l.Updated = "updated", l.Removed = "removed", l.Affected = "affected", l))(H || {}), D = /* @__PURE__ */ ((l) => (l.AddSuccessCall = "add-success-call", l.AddErrorCall = "add-error-call", l.AddCall = "add-call", l.SetParent = "set-parent", l.SetStandaloneParent = "set-standalone-parent", l.AfterAllChildrenInitialized = "after-all-children-initialized", l.UpdateWithShallowTransfer = "update-with-shallow-transfer", l.UpdateWithGenerationTarget = "update-with-generation-target", l.RemoveFromParent = "remove-from-parent", l.RemoveEntity = "remove-entity", l.RestoreEntity = "restore-entity", l.CloneEntity = "clone-entity", l.AddInput = "add-input", l.RemoveInput = "remove-input", l.SetDataType = "set-data-type", l.RemoveDataType = "remove-data-type", l.SetAdditionalPropertiesDataType = "set-additional-properties-data-type", l.RemoveAdditionalPropertiesDataType = "remove-additional-properties-data-type", l.SetAllPropertiesImplement = "set-all-properties-implement", l.RemoveAllPropertiesImplement = "remove-all-properties-implement", l.RemoveValueReader = "remove-value-reader", l.AddValueReader = "add-value-reader", l.RemoveValueWriter = "remove-value-writer", l.SetValueWriter = "set-value-writer", l.AddEntryCaller = "add-entry-caller", l.AddSuccessCaller = "add-success-caller", l.AddErrorCaller = "add-error-caller", l.RemoveCall = "remove-call", l.RemoveCaller = "remove-caller", l.RemoveChildGroup = "remove-child-group", l.AddToAndGroup = "add-to-and-group", l.AddToOrGroup = "add-to-or-group", l.RemoveUnrecognizedInputs = "remove-unrecognized-inputs", l.RemoveUnrecognizedOutputs = "remove-unrecognized-outputs", l.SyncInputs = "sync-inputs", l.SyncOutputs = "sync-outputs", l.SetImplements = "set-implements", l.SetExtends = "set-extends", l.SetExtension = "set-extension", l.AddImplementation = "add-implementation", l.RemoveImplementation = "remove-implementation", l.AddProperty = "add-property", l.RemoveProperty = "remove-property", l.AddMethod = "add-method", l.RemoveMethod = "remove-method", l.AddAbstractMethod = "add-abstract-method", l.RemoveAbstractMethod = "remove-abstract-method", l.SetValueAsTypeSingle = "set-value-as-type-single", l.SetValueAsTypeList = "set-value-as-type-list", l.SetValueAsType = "set-value-as-type", l.RemoveErrorCatching = "remove-error-catching", l.RemoveAllErrorCallers = "remove-all-error-callers", l.RemoveAllSuccessCallers = "remove-all-success-callers", l.RemoveAllCallers = "remove-all-callers", l.RemoveAllErrorCalls = "remove-all-error-calls", l.SetDataTypeEntityValue = "set-data-type-entity-value", l.MergeDataTypes = "merge-data-types", l.SetDataTypeForeignKeyRef = "set-data-type-foreign-key-ref", l.SetErrorEntity = "set-error-entity", l.AddValueAsTypeToList = "add-value-as-type-to-list", l.RemoveValueAsTypeFromList = "remove-value-as-type-from-list", l.CreateFromGenerationTarget = "create-from-generation-target", l))(D || {}), Ge = /* @__PURE__ */ ((l) => (l.ActionOwnerEntityNotEditable = "action-owner-entity-not-editable", l.ActionCounterpartEntityNotEditable = "action-counterpart-entity-not-editable", l.ActionOwnerEntityNonDeletable = "action-owner-entity-non-deletable", l.GlobalVariableDeclarationCannnotCatchError = "global-variable-declaration-cannot-catch-error", l.GlobalVariableDeclarationCannotReadValue = "global-variable-declaration-cannot-read-value", l.GlobalVariableDeclarationCannotBeCalled = "global-variable-declaration-cannot-be-called", l.GlobalVariableDeclarationCannotCallFromError = "global-variable-declaration-cannot-call-from-error", l.ValueReadingOverridesConstantProperty = "value-reading-overrides-constant-property", l.DefaultValueOverridesConstantProperty = "default-value-overrides-constant-property", l.ValueReadingOverridesConstantVariable = "value-reading-overrides-constant-variable", l.DefaultValueOverridesConstantVariable = "default-value-overrides-constant-variable", l.CannotSuccessCallItself = "cannot-success-call-itself", l.CannotErrorCallItself = "cannot-error-call-itself", l.CannotEntryCallItself = "cannot-entry-call-itself", l.CannotValueWriteItself = "cannot-value-write-itself", l.CannotBeCalledBeforeDeclaration = "cannot-be-called-before-declaration", l.CannotBeCalledInParallelBranchToDeclaration = "cannot-be-called-in-parallel-branch-to-declaration", l.CannotBeHigherScopeThanDeclaration = "cannot-be-higher-scope-than-declaration", l))(Ge || {});
79894
+ var g_ = /* @__PURE__ */ ((l) => (l.Manual = "manual", l.Automatic = "automatic", l))(g_ || {}), H = /* @__PURE__ */ ((l) => (l.Added = "added", l.Updated = "updated", l.Removed = "removed", l.Affected = "affected", l))(H || {}), D = /* @__PURE__ */ ((l) => (l.AddSuccessCall = "add-success-call", l.AddErrorCall = "add-error-call", l.AddCall = "add-call", l.SetParent = "set-parent", l.SetStandaloneParent = "set-standalone-parent", l.AfterAllChildrenInitialized = "after-all-children-initialized", l.UpdateWithShallowTransfer = "update-with-shallow-transfer", l.UpdateWithGenerationTarget = "update-with-generation-target", l.RemoveFromParent = "remove-from-parent", l.RemoveEntity = "remove-entity", l.RestoreEntity = "restore-entity", l.CloneEntity = "clone-entity", l.AddInput = "add-input", l.RemoveInput = "remove-input", l.SetDataType = "set-data-type", l.RemoveDataType = "remove-data-type", l.SetAdditionalPropertiesDataType = "set-additional-properties-data-type", l.RemoveAdditionalPropertiesDataType = "remove-additional-properties-data-type", l.SetAllPropertiesImplement = "set-all-properties-implement", l.RemoveAllPropertiesImplement = "remove-all-properties-implement", l.RemoveValueReader = "remove-value-reader", l.AddValueReader = "add-value-reader", l.RemoveValueWriter = "remove-value-writer", l.SetValueWriter = "set-value-writer", l.AddEntryCaller = "add-entry-caller", l.AddSuccessCaller = "add-success-caller", l.AddErrorCaller = "add-error-caller", l.RemoveCall = "remove-call", l.RemoveCaller = "remove-caller", l.RemoveChildGroup = "remove-child-group", l.AddToAndGroup = "add-to-and-group", l.AddToOrGroup = "add-to-or-group", l.RemoveUnrecognizedInputs = "remove-unrecognized-inputs", l.RemoveUnrecognizedOutputs = "remove-unrecognized-outputs", l.SyncInputs = "sync-inputs", l.SyncOutputs = "sync-outputs", l.SetImplements = "set-implements", l.SetExtends = "set-extends", l.SetExtension = "set-extension", l.AddImplementation = "add-implementation", l.RemoveImplementation = "remove-implementation", l.AddProperty = "add-property", l.RemoveProperty = "remove-property", l.AddMethod = "add-method", l.RemoveMethod = "remove-method", l.AddAbstractMethod = "add-abstract-method", l.RemoveAbstractMethod = "remove-abstract-method", l.SetValueAsTypeSingle = "set-value-as-type-single", l.SetValueAsTypeList = "set-value-as-type-list", l.SetValueAsType = "set-value-as-type", l.RemoveErrorCatching = "remove-error-catching", l.RemoveAllErrorCallers = "remove-all-error-callers", l.RemoveAllSuccessCallers = "remove-all-success-callers", l.RemoveAllCallers = "remove-all-callers", l.RemoveAllErrorCalls = "remove-all-error-calls", l.SetDataTypeEntityValue = "set-data-type-entity-value", l.MergeDataTypes = "merge-data-types", l.SetDataTypeForeignKeyRef = "set-data-type-foreign-key-ref", l.SetErrorEntity = "set-error-entity", l.AddValueAsTypeToList = "add-value-as-type-to-list", l.RemoveValueAsTypeFromList = "remove-value-as-type-from-list", l.CreateFromGenerationTarget = "create-from-generation-target", l))(D || {}), Ge = /* @__PURE__ */ ((l) => (l.ActionOwnerEntityNotEditable = "action-owner-entity-not-editable", l.ActionCounterpartEntityNotEditable = "action-counterpart-entity-not-editable", l.ActionOwnerEntityNonDeletable = "action-owner-entity-non-deletable", l.GlobalVariableDeclarationCannnotCatchError = "global-variable-declaration-cannot-catch-error", l.GlobalVariableDeclarationCannotReadValue = "global-variable-declaration-cannot-read-value", l.GlobalVariableDeclarationCannotBeCalled = "global-variable-declaration-cannot-be-called", l.GlobalVariableDeclarationCannotCallFromError = "global-variable-declaration-cannot-call-from-error", l.ValueReadingOverridesConstantProperty = "value-reading-overrides-constant-property", l.DefaultValueOverridesConstantProperty = "default-value-overrides-constant-property", l.ValueReadingOverridesConstantVariable = "value-reading-overrides-constant-variable", l.DefaultValueOverridesConstantVariable = "default-value-overrides-constant-variable", l.CannotSuccessCallItself = "cannot-success-call-itself", l.CannotErrorCallItself = "cannot-error-call-itself", l.CannotEntryCallItself = "cannot-entry-call-itself", l.CannotValueWriteItself = "cannot-value-write-itself", l.CannotBeCalledBeforeDeclaration = "cannot-be-called-before-declaration", l.CannotBeCalledInParallelBranchToDeclaration = "cannot-be-called-in-parallel-branch-to-declaration", l.CannotBeHigherScopeThanDeclaration = "cannot-be-higher-scope-than-declaration", l.InputsInGlobalVariableDeclarationsCannotReadValues = "inputs-in-global-variable-declarations-cannot-read-values", l))(Ge || {});
79895
79895
  class Rdi {
79896
79896
  constructor({
79897
79897
  id: p,
@@ -135302,7 +135302,7 @@ This is likely an incorrect strategy, either the '${this.type}' entity doesn't n
135302
135302
  D.AfterAllChildrenInitialized
135303
135303
  )
135304
135304
  )) {
135305
- var E, I;
135305
+ var E, I, _;
135306
135306
  if (!this.checkCanEdit(this, i))
135307
135307
  return se.warn(
135308
135308
  `[afterAllChildrenInitialized] User is not allowed to edit this ${this.type} entity with id: ${this.id}`
@@ -135319,18 +135319,24 @@ This is likely an incorrect strategy, either the '${this.type}' entity doesn't n
135319
135319
  const r = [], a = [], c = [], e = [];
135320
135320
  this.initialized = !0;
135321
135321
  let f = this.index || 0;
135322
- const h = (_t.includes(this.parent.type) ? this.parent.outputs : this.parent.inputs).filter((_) => !_.deleted && _.id !== this.id);
135322
+ const h = (_t.includes(this.parent.type) ? this.parent.outputs : this.parent.inputs).filter((P) => !P.deleted && P.id !== this.id);
135323
135323
  h.length && (f > h.length + 1 ? f = h.length : f < 0 && (f = 0)), h.find(
135324
- (_) => (_.index || 0) === f && !_.deleted
135325
- ) && h.filter((_) => (_.index || 0) >= f && !_.deleted).forEach((_) => {
135326
- _.metaSync({ index: (_.index || 0) + 1 }, i), i == null || i.add(_, H.Updated), r.push(_);
135324
+ (P) => (P.index || 0) === f && !P.deleted
135325
+ ) && h.filter((P) => (P.index || 0) >= f && !P.deleted).forEach((P) => {
135326
+ P.metaSync({ index: (P.index || 0) + 1 }, i), i == null || i.add(P, H.Updated), r.push(P);
135327
135327
  });
135328
135328
  const b = this.parent.type === d.VariableInstance && ((E = this.declaration) == null ? void 0 : E.type) === d.Property && ((I = this.declaration) == null ? void 0 : I.constant);
135329
135329
  if (b && this.readsValue && (this.readsValue.removeValueReader(this, i), this.removeValueWriter(i)), b && this.defaultValue && this.defaultValue.remove({ ignoreUpstream: !1 }, i), this.readsValue && this.defaultValue && (this.project.diggestedBuiltInBaseEntitiesIds.has(this.defaultValue.id) || this.defaultValue.remove({ ignoreUpstream: !1 }, i), this.setDefaultValue(null, i)), this.defaultValue && !this.readsValue && !this.project.diggestedBuiltInBaseEntitiesIds.has(this.id) && this.project.diggestedBuiltInBaseEntitiesIds.has(this.defaultValue.id)) {
135330
- const _ = this.defaultValue.clone(i, this);
135331
- this.setDefaultValue(_, i);
135330
+ const P = this.defaultValue.clone(i, this);
135331
+ this.setDefaultValue(P, i);
135332
135332
  }
135333
- return this.metaSync(
135333
+ return this.readsValue && this.parent.type === d.VariableDeclaration && ((_ = this.parent.parent) == null ? void 0 : _.type) === d.Project && (i == null || i.event({
135334
+ id: `${D.RemoveValueWriter}-${this.id}--${Ge.InputsInGlobalVariableDeclarationsCannotReadValues}`,
135335
+ action: D.RemoveValueWriter,
135336
+ owner: this,
135337
+ errorReason: Ge.InputsInGlobalVariableDeclarationsCannotReadValues,
135338
+ rootAction: !1
135339
+ }), this.readsValue.removeValueReader(this, i), this.removeValueWriter(i)), this.metaSync(
135334
135340
  {
135335
135341
  index: f
135336
135342
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elyx-code/project-logic-tree",
3
- "version": "0.0.6855",
3
+ "version": "0.0.6856",
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",