@elyx-code/project-logic-tree 0.0.6432 → 0.0.6433

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -35278,7 +35278,7 @@ Alternatively you can update the entity with 'update' action. Or replace it by f
35278
35278
  if (this.metaSync(i, a), this.version = i.version, this.createdAt = i.createdAt, this.author = i.author, this.deleted = i.deleted, this.previousVersion = i.previousVersion, this.unsubscribeFromDependencies(), i.parent) {
35279
35279
  const o = Z(i.parent), p = this.project.get(o), e = this.parent;
35280
35280
  if (e && e.id !== (p == null ? void 0 : p.id) && this.removeFromParent(a), p)
35281
- this.setParent(p, a);
35281
+ this.setParent(p, a), this.addSelfToProject(a);
35282
35282
  else
35283
35283
  throw a == null || a.attemptAutoclose("update-with-shallow-transfer", this.id), new Error(
35284
35284
  `${this.type} with id '${this.id}' has a 'parent' reference '${o}' that isn't found in the project`
@@ -35289,7 +35289,23 @@ Alternatively you can update the entity with 'update' action. Or replace it by f
35289
35289
  const o = Z(i.entity), p = this.project.get(o);
35290
35290
  p && (p.type === f.DefinitionEntity && p.parent === this || this.setEntity(p, null));
35291
35291
  }
35292
- return this.captureVersion(), this.subscribeToDependencies(), a == null || a.attemptAutoclose("update-with-shallow-transfer", this.id), this;
35292
+ return i.andChildrenGroup && (this.andChildrenGroup = i.andChildrenGroup.map(
35293
+ (o) => {
35294
+ const p = Z(o), e = this.project.get(p);
35295
+ if (e && !(e.type === f.DataType && e.parent === this))
35296
+ return e;
35297
+ }
35298
+ ).filter(
35299
+ (o) => !!o
35300
+ )), i.orChildrenGroup && (this.orChildrenGroup = i.orChildrenGroup.map(
35301
+ (o) => {
35302
+ const p = Z(o), e = this.project.get(p);
35303
+ if (e && !(e.type === f.DataType && e.parent === this))
35304
+ return e;
35305
+ }
35306
+ ).filter(
35307
+ (o) => !!o
35308
+ )), this.captureVersion(), this.subscribeToDependencies(), a == null || a.attemptAutoclose("update-with-shallow-transfer", this.id), this;
35293
35309
  }
35294
35310
  hydrateAncestors() {
35295
35311
  const i = [], a = [], o = [], p = [];
@@ -47469,7 +47485,7 @@ If an entity is called by another, they must be in the same scope, which means t
47469
47485
  if (this.metaSync(i, a), this.version = i.version, this.createdAt = i.createdAt, this.author = i.author, this.deleted = i.deleted, this.previousVersion = i.previousVersion, i.parent) {
47470
47486
  const o = Z(i.parent), p = this.project.get(o), e = this.parent;
47471
47487
  if (e && e.id !== (p == null ? void 0 : p.id) && this.removeFromParent(a), p)
47472
- this.setParent(p, a);
47488
+ this.setParent(p, a), this.addSelfToProject(a);
47473
47489
  else
47474
47490
  throw a == null || a.attemptAutoclose("update-with-shallow-transfer", this.id), new Error(
47475
47491
  `${this.type} with id '${this.id}' has a 'parent' reference '${o}' that isn't found in the project`
@@ -47484,7 +47500,15 @@ If an entity is called by another, they must be in the same scope, which means t
47484
47500
  );
47485
47501
  p && this.setDeclaration(p);
47486
47502
  }
47487
- return i.calledByEntry.forEach((o) => {
47503
+ return i.andChildrenGroup && (this.andChildrenGroup = i.andChildrenGroup.map((o) => {
47504
+ const p = Z(o), e = this.project.get(p);
47505
+ if (e && !(e.type === f.Condition && e.parent === this))
47506
+ return e;
47507
+ }).filter((o) => !!o)), i.orChildrenGroup && (this.orChildrenGroup = i.orChildrenGroup.map((o) => {
47508
+ const p = Z(o), e = this.project.get(p);
47509
+ if (e && !(e.type === f.Condition && e.parent === this))
47510
+ return e;
47511
+ }).filter((o) => !!o)), i.calledByEntry.forEach((o) => {
47488
47512
  const p = Z(o), e = this.project.get(p);
47489
47513
  e && (this.addEntryCaller(e, a), e.addCall(this, a));
47490
47514
  }), [...this.calledByEntry].forEach((o) => {
@@ -36,7 +36,7 @@ ${_o}`}))}}}const y=o.parent&&a.get(o.parent)||a.getBuiltIn(o.parent),v=y?Co(y):
36
36
  The entitities of type '${ot(A,"', '","' and '")}' can only have one 'data-type' child under the 'dataType' property so no 'parentRelationType' is needed.`})),y.dataType)){const $=(E=y.dataType)==null?void 0:E.id;p.push(new ee({id:`${i.id}--${k.NewEntityWouldOverriteExisting}`,code:k.NewEntityWouldOverriteExisting,severity:q.Error,message:`The entity with id '${i.id}' and type '${i.type}', cannot be added as a child to the entity with id '${o.parent}' and type '${b}', because it already has a 'data-type' child with id '${$}'.
37
37
  The entitities of type '${ot(A,"', '","' and '")}' can only have one 'data-type' child under the 'dataType' property. You can inspect the existing data-type entity with the 'describe_entity' action. Like so:
38
38
  ${aa({describe_entity:$})}
39
- Alternatively you can update the entity with 'update' action. Or replace it by first removing it and then creating a new one.`}))}b===f.DataType&&(!o.parentRelationType||!(o.parentRelationType===Ii.AndDataTypeGroup||o.parentRelationType===Ii.OrDataTypeGroup))&&p.push(new ee({id:`${i.id}--${k.InvalidParentRelationType}`,code:k.InvalidParentRelationType,severity:q.Error,message:`The entity with id '${i.id}' and type '${i.type}', must have a 'parentRelationType' property set to either 'or-data-type-group' or 'and-data-type-group' when being added as a child to an entity of type 'data-type'.`}))}return{errors:p,modifiedData:o}}get isGroup(){const i=[...this.andChildrenGroup||[],...this.orChildrenGroup||[]];if(i.length>1){let a=0;for(const o of i)if(o.isResolved&&(a++,a>1))return!0}return!1}get isResolved(){return[f.BuiltInBaseEntity,f.ActionDescriptor].includes(this.parent.type)||Co(this.parent)?!0:!(!this.entity&&!this.isGroup)}validateGeneratedUpdate(i){return{errors:[],modifiedData:i}}subscribeDependents(i){return i.forEach(a=>{this.detachedDependents[a.entity.id]||(this.detachedDependents[a.entity.id]=a)}),this}unsubscribeDependents(i){return i.forEach(a=>{this.detachedDependents[a.entity.id]&&delete this.detachedDependents[a.entity.id]}),this}syncDependents(i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"sync-dependents"))){const a=[],o=[],p=[],e=[];return Object.values(this.detachedDependents).forEach(y=>{const v=y.entity.afterAllChildrenInitialized(i);a.push(...v.updated),o.push(...v.added),p.push(...v.removed),e.push(...v.affected)}),i==null||i.attemptAutoclose("sync-dependents",this.id),{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}onDetachedDependencyRemoved(i,a,o){const p=[],e=[],y=[],v=[];return a==="entity"&&this.setEntity(i,o),{updated:R(p),added:R(e),removed:R(y),affected:R(v),self:this}}onDetachedDependencyRestored(i,a,o){const p=[],e=[],y=[],v=[];return a==="entity"&&this.setEntity(null,o),{updated:R(p),added:R(e),removed:R(y),affected:R(v),self:this}}unsubscribeFromDependencies(){var i,a;return(a=(i=this.entity)==null?void 0:i.unsubscribeDependents)==null||a.call(i,[{entity:this,field:"entity"}]),this}subscribeToDependencies(){var i,a;return(a=(i=this.entity)==null?void 0:i.subscribeDependents)==null||a.call(i,[{entity:this,field:"entity"}]),this}increaseVersion(i){if(i&&!L(i).isValid())throw new Error(`The shared timestamp '${i}' is not a valid ISO 8601 date string.`);return i&&L(i).isSame(L(this.createdAt))?this:(this.previousVersion=this.version,this.version=N.UUID.uuid(),this.createdAt=L(i).toISOString()||L().toISOString(),this)}captureVersion(){var a;const i=((a=this.knownVersions)==null?void 0:a.get(this.version))||new Mt(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.entity=this.entity,i.andChildrenGroup=this.andChildrenGroup?[...this.andChildrenGroup]:this.andChildrenGroup,i.orChildrenGroup=this.orChildrenGroup?[...this.orChildrenGroup]:this.orChildrenGroup,i.parent=this.parent,this}recursiveCaptureUpstreamVersions(i){const a=[],o=[],p=[],e=[];if(this.parent){this.parent.increaseVersion(i);const y=this.parent.recursiveCaptureUpstreamVersions(i);a.push(this.parent,...y.updated),o.push(...y.added),p.push(...y.removed)}return{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}async restoreVersion(i){var v;const a=[],o=[],p=[],e=[];if(this.version===i)return{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this};if(!this.knownVersions){const E=new Map;for(const[b,A]of this.knownVersions||new Map){if(E.set(b,A),A.activeVersion=!1,A.knownVersions)for(const[$,V]of A.knownVersions)E.set($,V);A.knownVersions=null}}let y=(v=this.knownVersions)==null?void 0:v.get(i);if(!y){const E=await this.APILoadVersion({},i);if(!E)throw new Error(`Version with id '${i}' for entity with id '${this.id}' not found.`);y=new Mt(E,this.project)}return this.metaSync(y.toShallowJSON(),null),this.previousVersion=y.previousVersion,this.version=y.version,this.createdAt=y.createdAt,this.author=y.author,this.deleted=y.deleted,this.entity=y.entity,this.andChildrenGroup=y.andChildrenGroup,this.orChildrenGroup=y.orChildrenGroup,this.parent=y.parent,{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}updateWithShallowTransfer(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"update-with-shallow-transfer"))){if(this.metaSync(i,a),this.version=i.version,this.createdAt=i.createdAt,this.author=i.author,this.deleted=i.deleted,this.previousVersion=i.previousVersion,this.unsubscribeFromDependencies(),i.parent){const o=H(i.parent),p=this.project.get(o),e=this.parent;if(e&&e.id!==(p==null?void 0:p.id)&&this.removeFromParent(a),p)this.setParent(p,a);else throw a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${o}' that isn't found in the project`)}else throw a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(i.entity){const o=H(i.entity),p=this.project.get(o);p&&(p.type===f.DefinitionEntity&&p.parent===this||this.setEntity(p,null))}return this.captureVersion(),this.subscribeToDependencies(),a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),this}hydrateAncestors(){const i=[],a=[],o=[],p=[];if(this.initialData.parent){const e=H(this.initialData.parent),y=this.project.get(e);if(y)this.setParent(y,null),i.push(y);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${e}' that isn't found in the project`)}else throw new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(this.initialData.entity){const e=H(this.initialData.entity),y=this.project.get(e);y&&(y.type===f.DefinitionEntity&&y.parent===this||(this.setEntity(y,null),y.type!==f.BuiltInBaseEntity&&y.type!==f.PrimitiveEntity&&i.push(y)))}return{updated:R(i),added:R(a),removed:R(o),affected:R(p),self:this}}afterAllChildrenInitialized(i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"after-all-children-initialized"))){const a=[],o=[],p=[],e=[];return this.initialized=!0,this.captureVersion(),i==null||i.attemptAutoclose("after-all-children-initialized",this.id),{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}addSelfToProject(i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-self-to-project"))){const a=[this],o=[],p=[],e=[];return this.parent.type===f.DataType?this.parentRelationType===Ii.AndDataTypeGroup?this.parent.addToAndGroup(this):this.parentRelationType===Ii.OrDataTypeGroup&&this.parent.addToOrGroup(this):this.parent.setDataType(this,i),e.push(this.parent),this.subscribe(),this.subscribeToDependencies(),i==null||i.attemptAutoclose("add-self-to-project",this.id),{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}setParent(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"set-parent"))){var o;return((o=this.parent)==null?void 0:o.id)!==(i==null?void 0:i.id)&&(this.parent=i,a&&(a==null||a.add(this,S.Updated))),a==null||a.attemptAutoclose("set-parent",this.id),this}removeChildGroup(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-child-group"))){if(this.andChildrenGroup){const o=this.andChildrenGroup.findIndex(p=>p.id===i.id);o!==-1&&(this.andChildrenGroup.splice(o,1),a==null||a.add(this,S.Updated))}if(this.orChildrenGroup){const o=this.orChildrenGroup.findIndex(p=>p.id===i.id);o!==-1&&(this.orChildrenGroup.splice(o,1),a==null||a.add(this,S.Updated))}return a==null||a.attemptAutoclose("remove-child-group",this.id),this}initChildren(i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"init-children"))){var a,o,p,e;if(this.initialized||this.startedInitialization)return this;if(this.startedInitialization=!0,this.initialData.entity)if(this.initialData.entity.type===f.GenericReference){const y=this.project.findSubscribedInstanceFromReference(this.initialData.entity);this.entity=y}else this.entity=te(this.initialData.entity,this.project),((o=(a=this.initialData.entity)==null?void 0:a.parent)==null?void 0:o.id)===this.id&&this.entity.setParent(this,null),(e=(p=this.entity).initChildren)==null||e.call(p,i);return this.initialData.andChildrenGroup&&(this.andChildrenGroup=this.initialData.andChildrenGroup.map(y=>{const v=te(y,this.project);return v.setParent(this,null),v.initChildren(i),v})),this.initialData.orChildrenGroup&&(this.orChildrenGroup=this.initialData.orChildrenGroup.map(y=>{const v=te(y,this.project);return v.setParent(this,null),v.initChildren(i),v})),this.subscribeToDependencies(),this.afterAllChildrenInitialized(i),i==null||i.attemptAutoclose("init-children",this.id),this}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"meta-sync"))){const o=xr(this,i),p=this.toMeta();return this.options=i.options||p.options,this.parentRelationType=i.parentRelationType||p.parentRelationType,this.isList=i.isList!==void 0?i.isList:p.isList,this.inferred=i.inferred!==void 0?i.inferred:p.inferred,this.like=i.like!==void 0?i.like:p.like,this.asType=i.asType!==void 0?i.asType:p.asType,this.index=i.index!==void 0?i.index:p.index,this.implementationChooseOne=i.implementationChooseOne!==void 0?i.implementationChooseOne:p.implementationChooseOne,this.staticEntities=i.staticEntities!==void 0?i.staticEntities:p.staticEntities,this.interactiveEntities=i.interactiveEntities!==void 0?i.interactiveEntities:p.interactiveEntities,this.actionEntities=i.actionEntities!==void 0?i.actionEntities:p.actionEntities,super.metaSync(i),i.deleted===!0&&!p.deleted?a==null||a.add(this,S.Removed):i.deleted===!1&&p.deleted?a==null||a.add(this,S.Added):o&&(a==null||a.add(this,S.Updated)),a==null||a.attemptAutoclose("meta-sync",this.id),this}async APILoad(i=ve,...a){return await Mt.repository.APILoad(this.id,...a),this}async APICreate(i=ve,...a){return await Mt.repository.APICreate(this.toShallowJSON(),...a),this}async APIUpdate(i=ve,...a){return await Mt.repository.APIUpdate(this.toShallowJSON(),...a),this}async APIDelete(i=ve,...a){return await Mt.repository.APIDelete(this.toShallowJSON(),...a),this}async APIClone(i=ve,...a){return await Mt.repository.APIClone(this.id,...a),this}async APILoadVersion(i=ve,a,...o){return await Mt.repository.APILoadVersion(this.id,a,...o)}removeFromParent(i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-from-parent"))){var y;const a=[],o=[],p=[],e=[];if(((y=this.parent)==null?void 0:y.type)===f.DataType)this.parent.removeChildGroup(this,i);else{const v=this.parent;v==null||v.removeDataType()}return this.parent&&a.push(this.parent),i==null||i.attemptAutoclose("remove-from-parent",this.id),{added:R(p),updated:R(a),removed:R(o),affected:R(e),self:this}}remove({ignoreUpstream:i}={ignoreUpstream:!1},a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-entity"))){if(this.id==="iterate-over-string-loop-string-argument-declaration-data-type-id")throw new Error("You are trying to remove the iterate-over-string-loop-string-argument-declaration-data-type-id entity. This is not allowed.");const o=[],p=[],e=[],y=[];if(a!=null&&a.hasRemoved(this.id))return a==null||a.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(p.push(this),this.unsubscribe(),this.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},a),Object.values(this.detachedDependents).forEach(v=>{const{updated:E,removed:b,added:A}=v.entity.onDetachedDependencyRemoved(this,v.field,a);o.push(...E),p.push(...b),e.push(...A)}),this.entity&&this.entity.type===f.DefinitionEntity&&this.entity.parent===this){const{updated:v,removed:E}=this.entity.remove({ignoreUpstream:!0},a);o.push(...v),p.push(...E)}if(this.andChildrenGroup&&this.andChildrenGroup.forEach(v=>{const{removed:E,updated:b}=v.remove({ignoreUpstream:!0},a);p.push(...E),o.push(...b)}),this.orChildrenGroup&&this.orChildrenGroup.forEach(v=>{const{removed:E,updated:b}=v.remove({ignoreUpstream:!0},a);p.push(...E),o.push(...b)}),!i){const v=this.removeFromParent(a);e.push(...v.added),o.push(...v.updated),p.push(...v.removed),y.push(...v.affected)}return a==null||a.attemptAutoclose("remove-entity",this.id),{added:R(e),updated:R(o),removed:R(p),affected:R(y),self:this}}restore({}={},i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"restore-entity"))){const a=[],o=[],p=[],e=[];if(i!=null&&i.hasAdded(this.id))return i==null||i.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},i),Object.values(this.detachedDependents).forEach(y=>{const{updated:v,removed:E,added:b}=y.entity.onDetachedDependencyRestored(this,y.field,i);o.push(...v),p.push(...E),a.push(...b)}),this.entity&&this.entity.type===f.DefinitionEntity&&this.entity.parent===this){const{updated:y}=this.entity.restore({},i);o.push(...y)}if(this.andChildrenGroup&&this.andChildrenGroup.forEach(y=>{const{updated:v,added:E}=y.restore({},i);o.push(...v),a.push(...E)}),this.orChildrenGroup&&this.orChildrenGroup.forEach(y=>{const{updated:v,added:E}=y.restore({},i);o.push(...v),a.push(...E)}),this.parent.type===f.DataType){const y=this.parent;Array.isArray(y.andChildrenGroup)&&y.andChildrenGroup.push(this)}if(this.parent.type===f.DataType){const y=this.parent;this.parentRelationType===Ii.AndDataTypeGroup?Array.isArray(y.andChildrenGroup)&&y.andChildrenGroup.push(this):this.parentRelationType===Ii.OrDataTypeGroup&&Array.isArray(y.orChildrenGroup)&&y.orChildrenGroup.push(this)}else{const y=this.parent;y.setDataType(this,i),o.push(y)}return i==null||i.attemptAutoclose("restore-entity",this.id),{added:R(a),updated:R(o),removed:R(p),affected:R(e),self:this}}toFlat(i=new Set){var o,p,e;return i.has(this.id)?[]:(i.add(this.id),[this,...((o=this.andChildrenGroup)==null?void 0:o.flatMap(y=>y.toFlat(i)))||[],...((p=this.orChildrenGroup)==null?void 0:p.flatMap(y=>y.toFlat(i)))||[],...((e=this.entity)==null?void 0:e.toFlat(i))||[]])}toFlatIds(i=new Set){var o,p,e;return i.has(this.id)?[]:(i.add(this.id),[this.id,...((o=this.andChildrenGroup)==null?void 0:o.flatMap(y=>y.toFlatIds(i)))||[],...((p=this.orChildrenGroup)==null?void 0:p.flatMap(y=>y.toFlatIds(i)))||[],...((e=this.entity)==null?void 0:e.toFlatIds(i))||[]])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,like:this.like,isList:this.isList,inferred:this.inferred,index:this.index,parentRelationType:this.parentRelationType,implementationChooseOne:this.implementationChooseOne,staticEntities:this.staticEntities,interactiveEntities:this.interactiveEntities,actionEntities:this.actionEntities,options:this.options,asType:this.asType,type:this.type}}toJSON(i=new Set){var a,o,p,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,options:this.options,isList:this.isList,asType:this.asType,index:this.index,like:this.like,inferred:this.inferred,parentRelationType:this.parentRelationType,implementationChooseOne:this.implementationChooseOne,staticEntities:this.staticEntities,interactiveEntities:this.interactiveEntities,actionEntities:this.actionEntities,andChildrenGroup:((a=this.andChildrenGroup)==null?void 0:a.map(y=>y.toJSON(i)))||null,orChildrenGroup:((o=this.orChildrenGroup)==null?void 0:o.map(y=>y.toJSON(i)))||null,entity:((p=this.entity)==null?void 0:p.parent)===this?this.entity.toJSON(i):((e=this.entity)==null?void 0:e.toReference())||null,parent:this.parent.toReference()})}toJSONClone(i=ke){var o,p,e,y,v,E,b,A,$;let a;return(o=i.seenEntityMaps)!=null&&o.has(this.id)?a=i.seenEntityMaps.get(this.id):(a=i.newId||Kr(this,this.project,i.uuidStrategy),i.seenEntityMaps&&i.seenEntityMaps.set(this.id,a)),(p=i.seenEntities)!=null&&p.has(a)||(e=i.seenEntities)!=null&&e.has(this.id)?this.toReference({seenEntityMaps:i.seenEntityMaps}):((y=i.seenEntities)==null||y.add(a),(v=i.seenEntities)==null||v.add(this.id),{id:a,version:N.UUID.uuid(),createdAt:i.timestamp||L().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,options:this.options,isList:this.isList,asType:this.asType,like:this.like,index:this.index,inferred:this.inferred,parentRelationType:this.parentRelationType,implementationChooseOne:this.implementationChooseOne,staticEntities:this.staticEntities,interactiveEntities:this.interactiveEntities,actionEntities:this.actionEntities,andChildrenGroup:((E=this.andChildrenGroup)==null?void 0:E.map(V=>V.toJSONClone({...i,newId:null})))||null,orChildrenGroup:((b=this.orChildrenGroup)==null?void 0:b.map(V=>V.toJSONClone({...i,newId:null})))||null,entity:((A=this.entity)==null?void 0:A.parent)===this?this.entity.toJSONClone({...i,newId:null}):(($=this.entity)==null?void 0:$.toReference({seenEntityMaps:i.seenEntityMaps}))||null,parent:this.parent.toReference({seenEntityMaps:i.seenEntityMaps})})}toReference(i=ke){var o;let a=this.id;return(o=i.seenEntityMaps)!=null&&o.has(this.id)&&(a=i.seenEntityMaps.get(this.id)),{id:a+"--"+N.UUID.uuid()+"--ref",type:f.GenericReference,entityId:a,version:this.version,entityType:this.type}}toShallowJSON(i=ke){var o,p,e,y;let a=this.id;return(o=i.seenEntityMaps)!=null&&o.has(this.id)&&(a=i.seenEntityMaps.get(this.id)),{id:a,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,isList:this.isList,options:this.options,asType:this.asType,index:this.index,parentRelationType:this.parentRelationType,like:this.like,inferred:this.inferred,implementationChooseOne:this.implementationChooseOne,staticEntities:this.staticEntities,interactiveEntities:this.interactiveEntities,actionEntities:this.actionEntities,andChildrenGroup:((p=this.andChildrenGroup)==null?void 0:p.map(v=>v.toReference(i)))||null,orChildrenGroup:((e=this.orChildrenGroup)==null?void 0:e.map(v=>v.toReference(i)))||null,entity:((y=this.entity)==null?void 0:y.toReference(i))||null,parent:this.parent.toReference(i)}}toFlatJSON(i=new Set){var o,p,e;return i.has(this.id)?[]:(i.add(this.id),[this.toShallowJSON(),...((o=this.andChildrenGroup)==null?void 0:o.flatMap(y=>y.toFlatJSON(i)))||[],...((p=this.orChildrenGroup)==null?void 0:p.flatMap(y=>y.toFlatJSON(i)))||[],...((e=this.entity)==null?void 0:e.toFlatJSON(i))||[]])}toGenerationTarget(){var i;return{id:this.id,type:this.type,options:this.options||void 0,isList:this.isList,like:this.like,parentRelationType:this.parentRelationType||void 0,asType:this.asType,entity:((i=this.entity)==null?void 0:i.id)||null,parent:this.parent.id}}toFlatGenerationTarget(i=new Set){var o,p;return i.has(this.id)?[]:(i.add(this.id),[this.toGenerationTarget(),...((o=this.andChildrenGroup)==null?void 0:o.flatMap(e=>e.toFlatGenerationTarget(i)))||[],...((p=this.orChildrenGroup)==null?void 0:p.flatMap(e=>e.toFlatGenerationTarget(i)))||[],...this.entity&&this.entity.type==f.DefinitionEntity&&this.entity.parent===this&&this.entity.toFlatGenerationTarget(i)||[]])}clearErrors(){var i,a,o,p;return this.errors=[],(i=this.andChildrenGroup)==null||i.forEach(e=>e.clearErrors()),(a=this.orChildrenGroup)==null||a.forEach(e=>e.clearErrors()),this.inferred&&this.entity&&this.entity.type===f.DefinitionEntity&&((o=this.entity)==null?void 0:o.parent)===this&&((p=this.entity)==null||p.clearErrors()),this}validate(){const i=tj(this);return this.errors=i,{success:!0}}getErrors(){return[...this.errors]}getShallowErrors(){return this.errors}clone(i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"clone-entity")),a=null,o=null,p=!0){var V,B,F;let e=Sr(a,this),y=a||this.parent;const E={id:o||N.UUID.uuid(),version:N.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||L().toISOString(),author:(i==null?void 0:i.author)||"1",previousVersion:null,deleted:!1,type:f.DataType,isList:this.isList,asType:this.asType,options:this.options,index:this.index,parentRelationType:this.parentRelationType,staticEntities:this.staticEntities,interactiveEntities:this.interactiveEntities,actionEntities:this.actionEntities,like:this.like,inferred:this.inferred,implementationChooseOne:this.implementationChooseOne,andChildrenGroup:null,orChildrenGroup:null,entity:null,parent:y.toReference()},b=dr(E,e);a&&b.setParent(a,null),p&&b.subscribe(),b.initChildren(i),i==null||i.add(b,S.Added);const A=(V=this.andChildrenGroup)==null?void 0:V.map(K=>K.clone(i,b,N.UUID.uuid(),p)),$=(B=this.orChildrenGroup)==null?void 0:B.map(K=>K.clone(i,b,N.UUID.uuid(),p));if(b.andChildrenGroup=A||null,b.orChildrenGroup=$||null,this.entity&&this.entity.type===f.DefinitionEntity&&((F=this.entity)==null?void 0:F.parent)===this){const K=this.entity.clone(i,b,N.UUID.uuid(),p);b.setEntity(K,i)}else this.entity&&b.setEntity(this.entity,i);return i==null||i.attemptAutoclose("clone-entity",this.id),b}merge(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"merge-entity"))){const o=[],p=[],e=[],y=[];if(this.asType!==(i==null?void 0:i.asType)&&(this.metaSync({asType:i==null?void 0:i.asType},a),a==null||a.add(this,S.Updated),o.push(this)),this.index!==(i==null?void 0:i.index)&&(this.metaSync({index:i==null?void 0:i.index},a),a==null||a.add(this,S.Updated),o.push(this)),this.isList!==(i==null?void 0:i.isList)&&(this.metaSync({isList:i==null?void 0:i.isList},a),a==null||a.add(this,S.Updated),o.push(this)),this.like!==(i==null?void 0:i.like)&&(this.metaSync({like:i==null?void 0:i.like},a),a==null||a.add(this,S.Updated),o.push(this)),i!=null&&i.inferred){if(i.entity&&i.entity.type===f.DefinitionEntity&&i.entity.parent===i){const v=i.entity.clone(a,this,N.UUID.uuid(),!0);this.setEntity(v,a),p.push(v)}else i.entity&&(this.setEntity(i.entity,a),a==null||a.add(this,S.Updated),o.push(this));this.inferred||(this.metaSync({inferred:!0},a),a==null||a.add(this,S.Updated),o.push(this))}else if(this.inferred){if(this.metaSync({inferred:!1},a),a==null||a.add(this,S.Updated),o.push(this),this.entity&&this.entity.type===f.DefinitionEntity&&this.entity.parent===this){const{updated:v,removed:E}=this.entity.remove({ignoreUpstream:!0},a);e.push(...E),v.push(...v)}i.entity!==this.entity&&(this.setEntity(i.entity,a),a==null||a.add(this,S.Updated),o.push(this))}else i.entity!==this.entity&&(this.setEntity(i.entity,a),a==null||a.add(this,S.Updated),o.push(this));return a==null||a.attemptAutoclose("merge-entity",this.id),{updated:R(o),added:R(p),removed:R(e),affected:R(y),self:this}}addToAndGroup(i){return this.andChildrenGroup||(this.andChildrenGroup=[]),this.andChildrenGroup.includes(i)||this.andChildrenGroup.push(i),this}addToOrGroup(i){return this.orChildrenGroup||(this.orChildrenGroup=[]),this.orChildrenGroup.includes(i)||this.orChildrenGroup.push(i),this}setEntity(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"set-data-type-entity-value"))){var p;const o=this.entity;return(o==null?void 0:o.id)!==(i==null?void 0:i.id)&&(this.entity=i,a==null||a.add(this,S.Affected),o&&o.type===f.DefinitionEntity&&((p=o.parent)==null?void 0:p.id)===this.id&&(o==null||o.remove({ignoreUpstream:!0},a))),a==null||a.attemptAutoclose("set-data-type-entity-value",this.id),this}isObject(){return!!this.entity&&(this.entity.type===f.DefinitionEntity||this.entity.type===f.BuiltInBaseEntity||this.entity.name===Q.KeyValue)&&!this.isList}canBeObject(){var a;let i=!1;if(this.parent.type!==f.DataType){const o=(a=this.project.requestActiveDynamicValue(this.parent))==null?void 0:a.value;o?!o.valueAsType&&(o.value===""||o.value===null||Ar(o))&&(i=!0):i=!0}return(this.isObject()||!this.entity||this.entity.name===Q.Untyped)&&i}hasStrictObjectStructure(){var i;return this.isObject()&&((i=this.entity)==null?void 0:i.type)===f.DefinitionEntity}isInlineDeclaredEntity(){var i,a;return((i=this.entity)==null?void 0:i.type)===f.DefinitionEntity&&((a=this.entity.parent)==null?void 0:a.id)===(this==null?void 0:this.id)}isIndependentlyUserDeclaredEntity(){var i,a;return((i=this.entity)==null?void 0:i.type)===f.DefinitionEntity&&((a=this.entity)==null?void 0:a.parent)!==this}canModifyObjectStructure(){var a;const i=this.isIndependentlyUserDeclaredEntity();return(this.isInlineDeclaredEntity()||this.canBeObject()||((a=this.entity)==null?void 0:a.name)===Q.KeyValue)&&!i}inferFromInputs(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"infer-data-type-from-inputs"))){var v;const o=[],p=[],e=[],y=[];if(!this.inferred)return a==null||a.attemptAutoclose("infer-data-type-from-inputs",this.id),{updated:[],added:[],removed:[],affected:[],self:this};if(!this.entity&&i.length){const E=ne(this.parent,this.project)+" data type definition",b={id:N.UUID.uuid(),type:f.DefinitionEntity,version:N.UUID.uuid(),createdAt:(a==null?void 0:a.timestamp)||L().toISOString(),author:N.sessionAuthor,previousVersion:null,deleted:!1,name:E,description:((v=this.parent)==null?void 0:v.description)||null,codeName:null,static:!0,abstract:!1,properties:[],methods:[],extends:[],implements:[],abstractMethods:[],x:0,y:0,parent:this.toReference()},A=te(b,this.project);A.hydrateAncestors(),A.setParent(this,a),A.initChildren(a),a==null||a.add(A,S.Added),A.metaSync(b,a),this.setEntity(A,a),a==null||a.add(this,S.Updated)}if(this.entity){const{updated:E,added:b,removed:A,affected:$}=this.entity.inferFromInputs(i,a);p.push(...E),o.push(...b),e.push(...A),y.push(...$)}return this.like||this.metaSync({like:!0},a),a==null||a.attemptAutoclose("infer-data-type-from-inputs",this.id),{updated:R(p),added:R(o),removed:R(e),affected:R(y),self:this}}};g(Mt,"repository",{APICreate:async(i,...a)=>i,APIUpdate:async(i,...a)=>i,APIDelete:async(i,...a)=>i,APIClone:async(i,...a)=>{},APILoad:async(i,...a)=>null,APILoadVersion:async(i,a,...o)=>null}),g(Mt,"type",f.DataType),g(Mt,"USER_MANAGED_PARENT_TYPES",[f.Property,f.ArgumentDeclaration,f.ReturnDeclaration,f.VariableDeclaration,f.ValueDescriptor,f.InputMap,f.OutputMap,f.DataType]),g(Mt,"PARENT_TYPES",[...Mt.USER_MANAGED_PARENT_TYPES]),g(Mt,"MUTABLE_BASE_PROPERTIES",["isList","asType","options","parentRelationType","like","implementationChooseOne","staticEntities","interactiveEntities","actionEntities"]),g(Mt,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","index","author","previousVersion"]),g(Mt,"BASE_PROPERTIES",[...Mt.MUTABLE_BASE_PROPERTIES,...Mt.INMUTABLE_BASE_PROPERTIES]),g(Mt,"MUTABLE_META_PROPERTIES",[...Mt.MUTABLE_BASE_PROPERTIES,"inferred"]),g(Mt,"INMUTABLE_META_PROPERTIES",[...Mt.INMUTABLE_BASE_PROPERTIES]),g(Mt,"META_PROPERTIES",[...Mt.MUTABLE_META_PROPERTIES,...Mt.INMUTABLE_META_PROPERTIES]),g(Mt,"MUTABLE_UPSTREAM_PROPERTIES",["entity","parent"]),g(Mt,"INMUTABLE_UPSTREAM_PROPERTIES",[]),g(Mt,"UPSTREAM_PROPERTIES",[...Mt.MUTABLE_UPSTREAM_PROPERTIES,...Mt.INMUTABLE_UPSTREAM_PROPERTIES]),g(Mt,"MUTABLE_DOWNSTREAM_PROPERTIES",[]),g(Mt,"INMUTABLE_DOWNSTREAM_PROPERTIES",["andChildrenGroup","orChildrenGroup"]),g(Mt,"DOWNSTREAM_PROPERTIES",[...Mt.MUTABLE_DOWNSTREAM_PROPERTIES,...Mt.INMUTABLE_DOWNSTREAM_PROPERTIES]),g(Mt,"PROPERTIES",[...Mt.META_PROPERTIES,...Mt.UPSTREAM_PROPERTIES,...Mt.DOWNSTREAM_PROPERTIES]);let vs=Mt;function rj(d){var y;const u=Gye(),i=d.toJSON();u.safeParse(i).success;const o=K0e(d),p=Ka(d),e=[...o,...p];return d.outputs.forEach(v=>v.validate()),(y=d.error)==null||y.validate(),Er(d.errors,e)}function K0e(d){const u=[];return d.inputs.forEach(i=>{i.validate()}),Er(d.errors,u)}const k0e=Object.freeze(Object.defineProperty({__proto__:null,validate:rj},Symbol.toStringTag,{value:"Module"}));var ij=(d=>(d.Parent="parent",d))(ij||{});const Bt=class Bt extends Nr{constructor(i,a){super(i);g(this,"initialData");g(this,"id");g(this,"x");g(this,"y");g(this,"type",f.Operation);g(this,"declaration");g(this,"inputs",[]);g(this,"outputs",[]);g(this,"process",null);g(this,"successCalls",[]);g(this,"errorCalls",[]);g(this,"error",null);g(this,"calledBySuccess",[]);g(this,"calledByError",[]);g(this,"calledByEntry",[]);g(this,"parent");g(this,"errors",[]);g(this,"project");g(this,"detachedDependents",{});g(this,"knownVersions",null);g(this,"activeVersion",!1);g(this,"initialized",!1);g(this,"startedInitialization",!1);this.initialData=i,this.project=a,this.id=i.id,this.x=i.x,this.y=i.y}static new(i=null){return{id:N.UUID.uuid(),version:N.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||L().toISOString(),author:(i==null?void 0:i.author)||N.sessionAuthor,previousVersion:null,deleted:!1,type:f.Operation,declaration:null,inputs:[],outputs:[],process:null,error:null,parent:null,calledByEntry:[],calledBySuccess:[],calledByError:[],errorCalls:[],successCalls:[],x:0,y:0}}static fromGenerationTarget(i,a){let o=a;if(i.parent){const $=H(i.parent);o=a.get($)}const p=H(i.declaration),e=a.get(p),y=i.calledByEntry.map($=>{const V=H($);return a.get(V)}),v=i.calledBySuccess.map($=>{const V=H($);return a.get(V)}),E=i.calledByError.map($=>{const V=H($);return a.get(V)}),b={id:i.id,version:N.UUID.uuid(),createdAt:L().toISOString(),author:N.sessionAuthor,previousVersion:null,deleted:!1,type:f.Operation,declaration:e,calledByEntry:y,calledBySuccess:v,calledByError:E,errorCalls:[],successCalls:[],inputs:[],outputs:[],process:null,error:null,x:0,y:0,parent:o},A=te(b,a);return A.setParent(o,null),A}static validateGenerationTarget(i,a){let o=JSON.parse(JSON.stringify(i));const p=[],e=li(o,{parent:{list:!1,types:[...Br,f.Project],optional:!0}},a);o=e.modifiedData,p.push(...e.errors,...Ur(o));const y=H(o.declaration);if(y){const v=L5(y,a);p.push(...v)}else{const v=`
39
+ Alternatively you can update the entity with 'update' action. Or replace it by first removing it and then creating a new one.`}))}b===f.DataType&&(!o.parentRelationType||!(o.parentRelationType===Ii.AndDataTypeGroup||o.parentRelationType===Ii.OrDataTypeGroup))&&p.push(new ee({id:`${i.id}--${k.InvalidParentRelationType}`,code:k.InvalidParentRelationType,severity:q.Error,message:`The entity with id '${i.id}' and type '${i.type}', must have a 'parentRelationType' property set to either 'or-data-type-group' or 'and-data-type-group' when being added as a child to an entity of type 'data-type'.`}))}return{errors:p,modifiedData:o}}get isGroup(){const i=[...this.andChildrenGroup||[],...this.orChildrenGroup||[]];if(i.length>1){let a=0;for(const o of i)if(o.isResolved&&(a++,a>1))return!0}return!1}get isResolved(){return[f.BuiltInBaseEntity,f.ActionDescriptor].includes(this.parent.type)||Co(this.parent)?!0:!(!this.entity&&!this.isGroup)}validateGeneratedUpdate(i){return{errors:[],modifiedData:i}}subscribeDependents(i){return i.forEach(a=>{this.detachedDependents[a.entity.id]||(this.detachedDependents[a.entity.id]=a)}),this}unsubscribeDependents(i){return i.forEach(a=>{this.detachedDependents[a.entity.id]&&delete this.detachedDependents[a.entity.id]}),this}syncDependents(i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"sync-dependents"))){const a=[],o=[],p=[],e=[];return Object.values(this.detachedDependents).forEach(y=>{const v=y.entity.afterAllChildrenInitialized(i);a.push(...v.updated),o.push(...v.added),p.push(...v.removed),e.push(...v.affected)}),i==null||i.attemptAutoclose("sync-dependents",this.id),{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}onDetachedDependencyRemoved(i,a,o){const p=[],e=[],y=[],v=[];return a==="entity"&&this.setEntity(i,o),{updated:R(p),added:R(e),removed:R(y),affected:R(v),self:this}}onDetachedDependencyRestored(i,a,o){const p=[],e=[],y=[],v=[];return a==="entity"&&this.setEntity(null,o),{updated:R(p),added:R(e),removed:R(y),affected:R(v),self:this}}unsubscribeFromDependencies(){var i,a;return(a=(i=this.entity)==null?void 0:i.unsubscribeDependents)==null||a.call(i,[{entity:this,field:"entity"}]),this}subscribeToDependencies(){var i,a;return(a=(i=this.entity)==null?void 0:i.subscribeDependents)==null||a.call(i,[{entity:this,field:"entity"}]),this}increaseVersion(i){if(i&&!L(i).isValid())throw new Error(`The shared timestamp '${i}' is not a valid ISO 8601 date string.`);return i&&L(i).isSame(L(this.createdAt))?this:(this.previousVersion=this.version,this.version=N.UUID.uuid(),this.createdAt=L(i).toISOString()||L().toISOString(),this)}captureVersion(){var a;const i=((a=this.knownVersions)==null?void 0:a.get(this.version))||new Mt(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.entity=this.entity,i.andChildrenGroup=this.andChildrenGroup?[...this.andChildrenGroup]:this.andChildrenGroup,i.orChildrenGroup=this.orChildrenGroup?[...this.orChildrenGroup]:this.orChildrenGroup,i.parent=this.parent,this}recursiveCaptureUpstreamVersions(i){const a=[],o=[],p=[],e=[];if(this.parent){this.parent.increaseVersion(i);const y=this.parent.recursiveCaptureUpstreamVersions(i);a.push(this.parent,...y.updated),o.push(...y.added),p.push(...y.removed)}return{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}async restoreVersion(i){var v;const a=[],o=[],p=[],e=[];if(this.version===i)return{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this};if(!this.knownVersions){const E=new Map;for(const[b,A]of this.knownVersions||new Map){if(E.set(b,A),A.activeVersion=!1,A.knownVersions)for(const[$,V]of A.knownVersions)E.set($,V);A.knownVersions=null}}let y=(v=this.knownVersions)==null?void 0:v.get(i);if(!y){const E=await this.APILoadVersion({},i);if(!E)throw new Error(`Version with id '${i}' for entity with id '${this.id}' not found.`);y=new Mt(E,this.project)}return this.metaSync(y.toShallowJSON(),null),this.previousVersion=y.previousVersion,this.version=y.version,this.createdAt=y.createdAt,this.author=y.author,this.deleted=y.deleted,this.entity=y.entity,this.andChildrenGroup=y.andChildrenGroup,this.orChildrenGroup=y.orChildrenGroup,this.parent=y.parent,{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}updateWithShallowTransfer(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"update-with-shallow-transfer"))){if(this.metaSync(i,a),this.version=i.version,this.createdAt=i.createdAt,this.author=i.author,this.deleted=i.deleted,this.previousVersion=i.previousVersion,this.unsubscribeFromDependencies(),i.parent){const o=H(i.parent),p=this.project.get(o),e=this.parent;if(e&&e.id!==(p==null?void 0:p.id)&&this.removeFromParent(a),p)this.setParent(p,a),this.addSelfToProject(a);else throw a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${o}' that isn't found in the project`)}else throw a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(i.entity){const o=H(i.entity),p=this.project.get(o);p&&(p.type===f.DefinitionEntity&&p.parent===this||this.setEntity(p,null))}return i.andChildrenGroup&&(this.andChildrenGroup=i.andChildrenGroup.map(o=>{const p=H(o),e=this.project.get(p);if(e&&!(e.type===f.DataType&&e.parent===this))return e}).filter(o=>!!o)),i.orChildrenGroup&&(this.orChildrenGroup=i.orChildrenGroup.map(o=>{const p=H(o),e=this.project.get(p);if(e&&!(e.type===f.DataType&&e.parent===this))return e}).filter(o=>!!o)),this.captureVersion(),this.subscribeToDependencies(),a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),this}hydrateAncestors(){const i=[],a=[],o=[],p=[];if(this.initialData.parent){const e=H(this.initialData.parent),y=this.project.get(e);if(y)this.setParent(y,null),i.push(y);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${e}' that isn't found in the project`)}else throw new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(this.initialData.entity){const e=H(this.initialData.entity),y=this.project.get(e);y&&(y.type===f.DefinitionEntity&&y.parent===this||(this.setEntity(y,null),y.type!==f.BuiltInBaseEntity&&y.type!==f.PrimitiveEntity&&i.push(y)))}return{updated:R(i),added:R(a),removed:R(o),affected:R(p),self:this}}afterAllChildrenInitialized(i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"after-all-children-initialized"))){const a=[],o=[],p=[],e=[];return this.initialized=!0,this.captureVersion(),i==null||i.attemptAutoclose("after-all-children-initialized",this.id),{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}addSelfToProject(i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-self-to-project"))){const a=[this],o=[],p=[],e=[];return this.parent.type===f.DataType?this.parentRelationType===Ii.AndDataTypeGroup?this.parent.addToAndGroup(this):this.parentRelationType===Ii.OrDataTypeGroup&&this.parent.addToOrGroup(this):this.parent.setDataType(this,i),e.push(this.parent),this.subscribe(),this.subscribeToDependencies(),i==null||i.attemptAutoclose("add-self-to-project",this.id),{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}setParent(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"set-parent"))){var o;return((o=this.parent)==null?void 0:o.id)!==(i==null?void 0:i.id)&&(this.parent=i,a&&(a==null||a.add(this,S.Updated))),a==null||a.attemptAutoclose("set-parent",this.id),this}removeChildGroup(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-child-group"))){if(this.andChildrenGroup){const o=this.andChildrenGroup.findIndex(p=>p.id===i.id);o!==-1&&(this.andChildrenGroup.splice(o,1),a==null||a.add(this,S.Updated))}if(this.orChildrenGroup){const o=this.orChildrenGroup.findIndex(p=>p.id===i.id);o!==-1&&(this.orChildrenGroup.splice(o,1),a==null||a.add(this,S.Updated))}return a==null||a.attemptAutoclose("remove-child-group",this.id),this}initChildren(i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"init-children"))){var a,o,p,e;if(this.initialized||this.startedInitialization)return this;if(this.startedInitialization=!0,this.initialData.entity)if(this.initialData.entity.type===f.GenericReference){const y=this.project.findSubscribedInstanceFromReference(this.initialData.entity);this.entity=y}else this.entity=te(this.initialData.entity,this.project),((o=(a=this.initialData.entity)==null?void 0:a.parent)==null?void 0:o.id)===this.id&&this.entity.setParent(this,null),(e=(p=this.entity).initChildren)==null||e.call(p,i);return this.initialData.andChildrenGroup&&(this.andChildrenGroup=this.initialData.andChildrenGroup.map(y=>{const v=te(y,this.project);return v.setParent(this,null),v.initChildren(i),v})),this.initialData.orChildrenGroup&&(this.orChildrenGroup=this.initialData.orChildrenGroup.map(y=>{const v=te(y,this.project);return v.setParent(this,null),v.initChildren(i),v})),this.subscribeToDependencies(),this.afterAllChildrenInitialized(i),i==null||i.attemptAutoclose("init-children",this.id),this}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"meta-sync"))){const o=xr(this,i),p=this.toMeta();return this.options=i.options||p.options,this.parentRelationType=i.parentRelationType||p.parentRelationType,this.isList=i.isList!==void 0?i.isList:p.isList,this.inferred=i.inferred!==void 0?i.inferred:p.inferred,this.like=i.like!==void 0?i.like:p.like,this.asType=i.asType!==void 0?i.asType:p.asType,this.index=i.index!==void 0?i.index:p.index,this.implementationChooseOne=i.implementationChooseOne!==void 0?i.implementationChooseOne:p.implementationChooseOne,this.staticEntities=i.staticEntities!==void 0?i.staticEntities:p.staticEntities,this.interactiveEntities=i.interactiveEntities!==void 0?i.interactiveEntities:p.interactiveEntities,this.actionEntities=i.actionEntities!==void 0?i.actionEntities:p.actionEntities,super.metaSync(i),i.deleted===!0&&!p.deleted?a==null||a.add(this,S.Removed):i.deleted===!1&&p.deleted?a==null||a.add(this,S.Added):o&&(a==null||a.add(this,S.Updated)),a==null||a.attemptAutoclose("meta-sync",this.id),this}async APILoad(i=ve,...a){return await Mt.repository.APILoad(this.id,...a),this}async APICreate(i=ve,...a){return await Mt.repository.APICreate(this.toShallowJSON(),...a),this}async APIUpdate(i=ve,...a){return await Mt.repository.APIUpdate(this.toShallowJSON(),...a),this}async APIDelete(i=ve,...a){return await Mt.repository.APIDelete(this.toShallowJSON(),...a),this}async APIClone(i=ve,...a){return await Mt.repository.APIClone(this.id,...a),this}async APILoadVersion(i=ve,a,...o){return await Mt.repository.APILoadVersion(this.id,a,...o)}removeFromParent(i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-from-parent"))){var y;const a=[],o=[],p=[],e=[];if(((y=this.parent)==null?void 0:y.type)===f.DataType)this.parent.removeChildGroup(this,i);else{const v=this.parent;v==null||v.removeDataType()}return this.parent&&a.push(this.parent),i==null||i.attemptAutoclose("remove-from-parent",this.id),{added:R(p),updated:R(a),removed:R(o),affected:R(e),self:this}}remove({ignoreUpstream:i}={ignoreUpstream:!1},a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-entity"))){if(this.id==="iterate-over-string-loop-string-argument-declaration-data-type-id")throw new Error("You are trying to remove the iterate-over-string-loop-string-argument-declaration-data-type-id entity. This is not allowed.");const o=[],p=[],e=[],y=[];if(a!=null&&a.hasRemoved(this.id))return a==null||a.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(p.push(this),this.unsubscribe(),this.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},a),Object.values(this.detachedDependents).forEach(v=>{const{updated:E,removed:b,added:A}=v.entity.onDetachedDependencyRemoved(this,v.field,a);o.push(...E),p.push(...b),e.push(...A)}),this.entity&&this.entity.type===f.DefinitionEntity&&this.entity.parent===this){const{updated:v,removed:E}=this.entity.remove({ignoreUpstream:!0},a);o.push(...v),p.push(...E)}if(this.andChildrenGroup&&this.andChildrenGroup.forEach(v=>{const{removed:E,updated:b}=v.remove({ignoreUpstream:!0},a);p.push(...E),o.push(...b)}),this.orChildrenGroup&&this.orChildrenGroup.forEach(v=>{const{removed:E,updated:b}=v.remove({ignoreUpstream:!0},a);p.push(...E),o.push(...b)}),!i){const v=this.removeFromParent(a);e.push(...v.added),o.push(...v.updated),p.push(...v.removed),y.push(...v.affected)}return a==null||a.attemptAutoclose("remove-entity",this.id),{added:R(e),updated:R(o),removed:R(p),affected:R(y),self:this}}restore({}={},i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"restore-entity"))){const a=[],o=[],p=[],e=[];if(i!=null&&i.hasAdded(this.id))return i==null||i.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},i),Object.values(this.detachedDependents).forEach(y=>{const{updated:v,removed:E,added:b}=y.entity.onDetachedDependencyRestored(this,y.field,i);o.push(...v),p.push(...E),a.push(...b)}),this.entity&&this.entity.type===f.DefinitionEntity&&this.entity.parent===this){const{updated:y}=this.entity.restore({},i);o.push(...y)}if(this.andChildrenGroup&&this.andChildrenGroup.forEach(y=>{const{updated:v,added:E}=y.restore({},i);o.push(...v),a.push(...E)}),this.orChildrenGroup&&this.orChildrenGroup.forEach(y=>{const{updated:v,added:E}=y.restore({},i);o.push(...v),a.push(...E)}),this.parent.type===f.DataType){const y=this.parent;Array.isArray(y.andChildrenGroup)&&y.andChildrenGroup.push(this)}if(this.parent.type===f.DataType){const y=this.parent;this.parentRelationType===Ii.AndDataTypeGroup?Array.isArray(y.andChildrenGroup)&&y.andChildrenGroup.push(this):this.parentRelationType===Ii.OrDataTypeGroup&&Array.isArray(y.orChildrenGroup)&&y.orChildrenGroup.push(this)}else{const y=this.parent;y.setDataType(this,i),o.push(y)}return i==null||i.attemptAutoclose("restore-entity",this.id),{added:R(a),updated:R(o),removed:R(p),affected:R(e),self:this}}toFlat(i=new Set){var o,p,e;return i.has(this.id)?[]:(i.add(this.id),[this,...((o=this.andChildrenGroup)==null?void 0:o.flatMap(y=>y.toFlat(i)))||[],...((p=this.orChildrenGroup)==null?void 0:p.flatMap(y=>y.toFlat(i)))||[],...((e=this.entity)==null?void 0:e.toFlat(i))||[]])}toFlatIds(i=new Set){var o,p,e;return i.has(this.id)?[]:(i.add(this.id),[this.id,...((o=this.andChildrenGroup)==null?void 0:o.flatMap(y=>y.toFlatIds(i)))||[],...((p=this.orChildrenGroup)==null?void 0:p.flatMap(y=>y.toFlatIds(i)))||[],...((e=this.entity)==null?void 0:e.toFlatIds(i))||[]])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,like:this.like,isList:this.isList,inferred:this.inferred,index:this.index,parentRelationType:this.parentRelationType,implementationChooseOne:this.implementationChooseOne,staticEntities:this.staticEntities,interactiveEntities:this.interactiveEntities,actionEntities:this.actionEntities,options:this.options,asType:this.asType,type:this.type}}toJSON(i=new Set){var a,o,p,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,options:this.options,isList:this.isList,asType:this.asType,index:this.index,like:this.like,inferred:this.inferred,parentRelationType:this.parentRelationType,implementationChooseOne:this.implementationChooseOne,staticEntities:this.staticEntities,interactiveEntities:this.interactiveEntities,actionEntities:this.actionEntities,andChildrenGroup:((a=this.andChildrenGroup)==null?void 0:a.map(y=>y.toJSON(i)))||null,orChildrenGroup:((o=this.orChildrenGroup)==null?void 0:o.map(y=>y.toJSON(i)))||null,entity:((p=this.entity)==null?void 0:p.parent)===this?this.entity.toJSON(i):((e=this.entity)==null?void 0:e.toReference())||null,parent:this.parent.toReference()})}toJSONClone(i=ke){var o,p,e,y,v,E,b,A,$;let a;return(o=i.seenEntityMaps)!=null&&o.has(this.id)?a=i.seenEntityMaps.get(this.id):(a=i.newId||Kr(this,this.project,i.uuidStrategy),i.seenEntityMaps&&i.seenEntityMaps.set(this.id,a)),(p=i.seenEntities)!=null&&p.has(a)||(e=i.seenEntities)!=null&&e.has(this.id)?this.toReference({seenEntityMaps:i.seenEntityMaps}):((y=i.seenEntities)==null||y.add(a),(v=i.seenEntities)==null||v.add(this.id),{id:a,version:N.UUID.uuid(),createdAt:i.timestamp||L().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,options:this.options,isList:this.isList,asType:this.asType,like:this.like,index:this.index,inferred:this.inferred,parentRelationType:this.parentRelationType,implementationChooseOne:this.implementationChooseOne,staticEntities:this.staticEntities,interactiveEntities:this.interactiveEntities,actionEntities:this.actionEntities,andChildrenGroup:((E=this.andChildrenGroup)==null?void 0:E.map(V=>V.toJSONClone({...i,newId:null})))||null,orChildrenGroup:((b=this.orChildrenGroup)==null?void 0:b.map(V=>V.toJSONClone({...i,newId:null})))||null,entity:((A=this.entity)==null?void 0:A.parent)===this?this.entity.toJSONClone({...i,newId:null}):(($=this.entity)==null?void 0:$.toReference({seenEntityMaps:i.seenEntityMaps}))||null,parent:this.parent.toReference({seenEntityMaps:i.seenEntityMaps})})}toReference(i=ke){var o;let a=this.id;return(o=i.seenEntityMaps)!=null&&o.has(this.id)&&(a=i.seenEntityMaps.get(this.id)),{id:a+"--"+N.UUID.uuid()+"--ref",type:f.GenericReference,entityId:a,version:this.version,entityType:this.type}}toShallowJSON(i=ke){var o,p,e,y;let a=this.id;return(o=i.seenEntityMaps)!=null&&o.has(this.id)&&(a=i.seenEntityMaps.get(this.id)),{id:a,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,isList:this.isList,options:this.options,asType:this.asType,index:this.index,parentRelationType:this.parentRelationType,like:this.like,inferred:this.inferred,implementationChooseOne:this.implementationChooseOne,staticEntities:this.staticEntities,interactiveEntities:this.interactiveEntities,actionEntities:this.actionEntities,andChildrenGroup:((p=this.andChildrenGroup)==null?void 0:p.map(v=>v.toReference(i)))||null,orChildrenGroup:((e=this.orChildrenGroup)==null?void 0:e.map(v=>v.toReference(i)))||null,entity:((y=this.entity)==null?void 0:y.toReference(i))||null,parent:this.parent.toReference(i)}}toFlatJSON(i=new Set){var o,p,e;return i.has(this.id)?[]:(i.add(this.id),[this.toShallowJSON(),...((o=this.andChildrenGroup)==null?void 0:o.flatMap(y=>y.toFlatJSON(i)))||[],...((p=this.orChildrenGroup)==null?void 0:p.flatMap(y=>y.toFlatJSON(i)))||[],...((e=this.entity)==null?void 0:e.toFlatJSON(i))||[]])}toGenerationTarget(){var i;return{id:this.id,type:this.type,options:this.options||void 0,isList:this.isList,like:this.like,parentRelationType:this.parentRelationType||void 0,asType:this.asType,entity:((i=this.entity)==null?void 0:i.id)||null,parent:this.parent.id}}toFlatGenerationTarget(i=new Set){var o,p;return i.has(this.id)?[]:(i.add(this.id),[this.toGenerationTarget(),...((o=this.andChildrenGroup)==null?void 0:o.flatMap(e=>e.toFlatGenerationTarget(i)))||[],...((p=this.orChildrenGroup)==null?void 0:p.flatMap(e=>e.toFlatGenerationTarget(i)))||[],...this.entity&&this.entity.type==f.DefinitionEntity&&this.entity.parent===this&&this.entity.toFlatGenerationTarget(i)||[]])}clearErrors(){var i,a,o,p;return this.errors=[],(i=this.andChildrenGroup)==null||i.forEach(e=>e.clearErrors()),(a=this.orChildrenGroup)==null||a.forEach(e=>e.clearErrors()),this.inferred&&this.entity&&this.entity.type===f.DefinitionEntity&&((o=this.entity)==null?void 0:o.parent)===this&&((p=this.entity)==null||p.clearErrors()),this}validate(){const i=tj(this);return this.errors=i,{success:!0}}getErrors(){return[...this.errors]}getShallowErrors(){return this.errors}clone(i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"clone-entity")),a=null,o=null,p=!0){var V,B,F;let e=Sr(a,this),y=a||this.parent;const E={id:o||N.UUID.uuid(),version:N.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||L().toISOString(),author:(i==null?void 0:i.author)||"1",previousVersion:null,deleted:!1,type:f.DataType,isList:this.isList,asType:this.asType,options:this.options,index:this.index,parentRelationType:this.parentRelationType,staticEntities:this.staticEntities,interactiveEntities:this.interactiveEntities,actionEntities:this.actionEntities,like:this.like,inferred:this.inferred,implementationChooseOne:this.implementationChooseOne,andChildrenGroup:null,orChildrenGroup:null,entity:null,parent:y.toReference()},b=dr(E,e);a&&b.setParent(a,null),p&&b.subscribe(),b.initChildren(i),i==null||i.add(b,S.Added);const A=(V=this.andChildrenGroup)==null?void 0:V.map(K=>K.clone(i,b,N.UUID.uuid(),p)),$=(B=this.orChildrenGroup)==null?void 0:B.map(K=>K.clone(i,b,N.UUID.uuid(),p));if(b.andChildrenGroup=A||null,b.orChildrenGroup=$||null,this.entity&&this.entity.type===f.DefinitionEntity&&((F=this.entity)==null?void 0:F.parent)===this){const K=this.entity.clone(i,b,N.UUID.uuid(),p);b.setEntity(K,i)}else this.entity&&b.setEntity(this.entity,i);return i==null||i.attemptAutoclose("clone-entity",this.id),b}merge(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"merge-entity"))){const o=[],p=[],e=[],y=[];if(this.asType!==(i==null?void 0:i.asType)&&(this.metaSync({asType:i==null?void 0:i.asType},a),a==null||a.add(this,S.Updated),o.push(this)),this.index!==(i==null?void 0:i.index)&&(this.metaSync({index:i==null?void 0:i.index},a),a==null||a.add(this,S.Updated),o.push(this)),this.isList!==(i==null?void 0:i.isList)&&(this.metaSync({isList:i==null?void 0:i.isList},a),a==null||a.add(this,S.Updated),o.push(this)),this.like!==(i==null?void 0:i.like)&&(this.metaSync({like:i==null?void 0:i.like},a),a==null||a.add(this,S.Updated),o.push(this)),i!=null&&i.inferred){if(i.entity&&i.entity.type===f.DefinitionEntity&&i.entity.parent===i){const v=i.entity.clone(a,this,N.UUID.uuid(),!0);this.setEntity(v,a),p.push(v)}else i.entity&&(this.setEntity(i.entity,a),a==null||a.add(this,S.Updated),o.push(this));this.inferred||(this.metaSync({inferred:!0},a),a==null||a.add(this,S.Updated),o.push(this))}else if(this.inferred){if(this.metaSync({inferred:!1},a),a==null||a.add(this,S.Updated),o.push(this),this.entity&&this.entity.type===f.DefinitionEntity&&this.entity.parent===this){const{updated:v,removed:E}=this.entity.remove({ignoreUpstream:!0},a);e.push(...E),v.push(...v)}i.entity!==this.entity&&(this.setEntity(i.entity,a),a==null||a.add(this,S.Updated),o.push(this))}else i.entity!==this.entity&&(this.setEntity(i.entity,a),a==null||a.add(this,S.Updated),o.push(this));return a==null||a.attemptAutoclose("merge-entity",this.id),{updated:R(o),added:R(p),removed:R(e),affected:R(y),self:this}}addToAndGroup(i){return this.andChildrenGroup||(this.andChildrenGroup=[]),this.andChildrenGroup.includes(i)||this.andChildrenGroup.push(i),this}addToOrGroup(i){return this.orChildrenGroup||(this.orChildrenGroup=[]),this.orChildrenGroup.includes(i)||this.orChildrenGroup.push(i),this}setEntity(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"set-data-type-entity-value"))){var p;const o=this.entity;return(o==null?void 0:o.id)!==(i==null?void 0:i.id)&&(this.entity=i,a==null||a.add(this,S.Affected),o&&o.type===f.DefinitionEntity&&((p=o.parent)==null?void 0:p.id)===this.id&&(o==null||o.remove({ignoreUpstream:!0},a))),a==null||a.attemptAutoclose("set-data-type-entity-value",this.id),this}isObject(){return!!this.entity&&(this.entity.type===f.DefinitionEntity||this.entity.type===f.BuiltInBaseEntity||this.entity.name===Q.KeyValue)&&!this.isList}canBeObject(){var a;let i=!1;if(this.parent.type!==f.DataType){const o=(a=this.project.requestActiveDynamicValue(this.parent))==null?void 0:a.value;o?!o.valueAsType&&(o.value===""||o.value===null||Ar(o))&&(i=!0):i=!0}return(this.isObject()||!this.entity||this.entity.name===Q.Untyped)&&i}hasStrictObjectStructure(){var i;return this.isObject()&&((i=this.entity)==null?void 0:i.type)===f.DefinitionEntity}isInlineDeclaredEntity(){var i,a;return((i=this.entity)==null?void 0:i.type)===f.DefinitionEntity&&((a=this.entity.parent)==null?void 0:a.id)===(this==null?void 0:this.id)}isIndependentlyUserDeclaredEntity(){var i,a;return((i=this.entity)==null?void 0:i.type)===f.DefinitionEntity&&((a=this.entity)==null?void 0:a.parent)!==this}canModifyObjectStructure(){var a;const i=this.isIndependentlyUserDeclaredEntity();return(this.isInlineDeclaredEntity()||this.canBeObject()||((a=this.entity)==null?void 0:a.name)===Q.KeyValue)&&!i}inferFromInputs(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"infer-data-type-from-inputs"))){var v;const o=[],p=[],e=[],y=[];if(!this.inferred)return a==null||a.attemptAutoclose("infer-data-type-from-inputs",this.id),{updated:[],added:[],removed:[],affected:[],self:this};if(!this.entity&&i.length){const E=ne(this.parent,this.project)+" data type definition",b={id:N.UUID.uuid(),type:f.DefinitionEntity,version:N.UUID.uuid(),createdAt:(a==null?void 0:a.timestamp)||L().toISOString(),author:N.sessionAuthor,previousVersion:null,deleted:!1,name:E,description:((v=this.parent)==null?void 0:v.description)||null,codeName:null,static:!0,abstract:!1,properties:[],methods:[],extends:[],implements:[],abstractMethods:[],x:0,y:0,parent:this.toReference()},A=te(b,this.project);A.hydrateAncestors(),A.setParent(this,a),A.initChildren(a),a==null||a.add(A,S.Added),A.metaSync(b,a),this.setEntity(A,a),a==null||a.add(this,S.Updated)}if(this.entity){const{updated:E,added:b,removed:A,affected:$}=this.entity.inferFromInputs(i,a);p.push(...E),o.push(...b),e.push(...A),y.push(...$)}return this.like||this.metaSync({like:!0},a),a==null||a.attemptAutoclose("infer-data-type-from-inputs",this.id),{updated:R(p),added:R(o),removed:R(e),affected:R(y),self:this}}};g(Mt,"repository",{APICreate:async(i,...a)=>i,APIUpdate:async(i,...a)=>i,APIDelete:async(i,...a)=>i,APIClone:async(i,...a)=>{},APILoad:async(i,...a)=>null,APILoadVersion:async(i,a,...o)=>null}),g(Mt,"type",f.DataType),g(Mt,"USER_MANAGED_PARENT_TYPES",[f.Property,f.ArgumentDeclaration,f.ReturnDeclaration,f.VariableDeclaration,f.ValueDescriptor,f.InputMap,f.OutputMap,f.DataType]),g(Mt,"PARENT_TYPES",[...Mt.USER_MANAGED_PARENT_TYPES]),g(Mt,"MUTABLE_BASE_PROPERTIES",["isList","asType","options","parentRelationType","like","implementationChooseOne","staticEntities","interactiveEntities","actionEntities"]),g(Mt,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","index","author","previousVersion"]),g(Mt,"BASE_PROPERTIES",[...Mt.MUTABLE_BASE_PROPERTIES,...Mt.INMUTABLE_BASE_PROPERTIES]),g(Mt,"MUTABLE_META_PROPERTIES",[...Mt.MUTABLE_BASE_PROPERTIES,"inferred"]),g(Mt,"INMUTABLE_META_PROPERTIES",[...Mt.INMUTABLE_BASE_PROPERTIES]),g(Mt,"META_PROPERTIES",[...Mt.MUTABLE_META_PROPERTIES,...Mt.INMUTABLE_META_PROPERTIES]),g(Mt,"MUTABLE_UPSTREAM_PROPERTIES",["entity","parent"]),g(Mt,"INMUTABLE_UPSTREAM_PROPERTIES",[]),g(Mt,"UPSTREAM_PROPERTIES",[...Mt.MUTABLE_UPSTREAM_PROPERTIES,...Mt.INMUTABLE_UPSTREAM_PROPERTIES]),g(Mt,"MUTABLE_DOWNSTREAM_PROPERTIES",[]),g(Mt,"INMUTABLE_DOWNSTREAM_PROPERTIES",["andChildrenGroup","orChildrenGroup"]),g(Mt,"DOWNSTREAM_PROPERTIES",[...Mt.MUTABLE_DOWNSTREAM_PROPERTIES,...Mt.INMUTABLE_DOWNSTREAM_PROPERTIES]),g(Mt,"PROPERTIES",[...Mt.META_PROPERTIES,...Mt.UPSTREAM_PROPERTIES,...Mt.DOWNSTREAM_PROPERTIES]);let vs=Mt;function rj(d){var y;const u=Gye(),i=d.toJSON();u.safeParse(i).success;const o=K0e(d),p=Ka(d),e=[...o,...p];return d.outputs.forEach(v=>v.validate()),(y=d.error)==null||y.validate(),Er(d.errors,e)}function K0e(d){const u=[];return d.inputs.forEach(i=>{i.validate()}),Er(d.errors,u)}const k0e=Object.freeze(Object.defineProperty({__proto__:null,validate:rj},Symbol.toStringTag,{value:"Module"}));var ij=(d=>(d.Parent="parent",d))(ij||{});const Bt=class Bt extends Nr{constructor(i,a){super(i);g(this,"initialData");g(this,"id");g(this,"x");g(this,"y");g(this,"type",f.Operation);g(this,"declaration");g(this,"inputs",[]);g(this,"outputs",[]);g(this,"process",null);g(this,"successCalls",[]);g(this,"errorCalls",[]);g(this,"error",null);g(this,"calledBySuccess",[]);g(this,"calledByError",[]);g(this,"calledByEntry",[]);g(this,"parent");g(this,"errors",[]);g(this,"project");g(this,"detachedDependents",{});g(this,"knownVersions",null);g(this,"activeVersion",!1);g(this,"initialized",!1);g(this,"startedInitialization",!1);this.initialData=i,this.project=a,this.id=i.id,this.x=i.x,this.y=i.y}static new(i=null){return{id:N.UUID.uuid(),version:N.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||L().toISOString(),author:(i==null?void 0:i.author)||N.sessionAuthor,previousVersion:null,deleted:!1,type:f.Operation,declaration:null,inputs:[],outputs:[],process:null,error:null,parent:null,calledByEntry:[],calledBySuccess:[],calledByError:[],errorCalls:[],successCalls:[],x:0,y:0}}static fromGenerationTarget(i,a){let o=a;if(i.parent){const $=H(i.parent);o=a.get($)}const p=H(i.declaration),e=a.get(p),y=i.calledByEntry.map($=>{const V=H($);return a.get(V)}),v=i.calledBySuccess.map($=>{const V=H($);return a.get(V)}),E=i.calledByError.map($=>{const V=H($);return a.get(V)}),b={id:i.id,version:N.UUID.uuid(),createdAt:L().toISOString(),author:N.sessionAuthor,previousVersion:null,deleted:!1,type:f.Operation,declaration:e,calledByEntry:y,calledBySuccess:v,calledByError:E,errorCalls:[],successCalls:[],inputs:[],outputs:[],process:null,error:null,x:0,y:0,parent:o},A=te(b,a);return A.setParent(o,null),A}static validateGenerationTarget(i,a){let o=JSON.parse(JSON.stringify(i));const p=[],e=li(o,{parent:{list:!1,types:[...Br,f.Project],optional:!0}},a);o=e.modifiedData,p.push(...e.errors,...Ur(o));const y=H(o.declaration);if(y){const v=L5(y,a);p.push(...v)}else{const v=`
40
40
  All built-in 'action-descriptor' entity ids are:
41
41
  - ${a.operationDeclarations.map(E=>`${E.id} (${ne(E,a)})`).join(`
42
42
  - `)}.
@@ -76,7 +76,7 @@ You shouldn't have to manually update a 'parent' property. The equivalent result
76
76
  ${Nm(a)}`})):p.push(new ee({id:`${i.id}--${k.ReferencedEntityNotFound}`,code:k.ReferencedEntityNotFound,severity:q.Error,message:`Entity of type '${i.type}' with id '${i.id}' has an 'declaration' property that isn't found in the project. The 'declaration' property must point to one of the built-in action descriptors reserved for '${f.Condition}' entities.
77
77
  ${Nm(a)}`})):p.push(new ee({id:`${i.id}--${ae.InvalidObjectStructure}`,code:ae.InvalidObjectStructure,severity:q.Error,message:`Entity of type '${i.type}' with id '${i.id}' is missing the 'declaration' property. This property is required for a '${i.type}' entity and must point to one of the built-in action descriptors reserved for '${f.Condition}' entities.
78
78
  ${Nm(a)}`})),{errors:p,modifiedData:o}}validateGeneratedUpdate(i){const a=[];return i.parent&&a.push(new ee({id:`${this.id}--${k.InvalidParentUpdate}`,code:k.InvalidParentUpdate,severity:q.Error,message:`Entity of type '${this.type}' with id '${this.id}' cannot have the 'parent' property updated. The 'parent' on a callable entity, is its scope. It scope is auto-calculated implicitly by the its caller.
79
- If an entity is called by another, they must be in the same scope, which means they have the same parent.`})),{errors:a,modifiedData:i}}subscribeDependents(i){return i.forEach(a=>{this.detachedDependents[a.entity.id]||(this.detachedDependents[a.entity.id]=a)}),this}unsubscribeDependents(i){return i.forEach(a=>{this.detachedDependents[a.entity.id]&&delete this.detachedDependents[a.entity.id]}),this}syncDependents(i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"sync-dependents"))){const a=[],o=[],p=[],e=[];return Object.values(this.detachedDependents).forEach(y=>{const v=y.entity.afterAllChildrenInitialized(i);a.push(...v.updated),o.push(...v.added),p.push(...v.removed),e.push(...v.affected)}),i==null||i.attemptAutoclose("sync-dependents",this.id),{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}onDetachedDependencyRemoved(i,a,o){const p=[],e=[],y=[],v=[];if(a==="parent"){const{updated:E,added:b,removed:A}=this.remove({ignoreUpstream:!1},o);p.push(...E),e.push(...b),y.push(...A)}return{updated:R(p),added:R(e),removed:R(y),affected:R(v),self:this}}onDetachedDependencyRestored(i,a,o){const p=[],e=[],y=[],v=[];if(a==="parent"){const{updated:E,added:b,removed:A}=this.restore({},o);p.push(...E),e.push(...b),y.push(...A)}return{updated:R(p),added:R(e),removed:R(y),affected:R(v),self:this}}unsubscribeFromDependencies(){return this.parent.unsubscribeDependents([{entity:this,field:"parent"}]),this}subscribeToDependencies(){var i;return(i=this.parent)==null||i.subscribeDependents([{entity:this,field:"parent"}]),this}increaseVersion(i){if(i&&!L(i).isValid())throw new Error(`The shared timestamp '${i}' is not a valid ISO 8601 date string.`);return i&&L(i).isSame(L(this.createdAt))?this:(this.previousVersion=this.version,this.version=N.UUID.uuid(),this.createdAt=L(i).toISOString()||L().toISOString(),this)}captureVersion(){var a;const i=((a=this.knownVersions)==null?void 0:a.get(this.version))||new Xt(this,this.project);return i.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,i):new Map([[this.version,i]]),i.inputs=[...this.inputs],i.declaration=this.declaration,i.andChildrenGroup=this.andChildrenGroup?[...this.andChildrenGroup]:this.andChildrenGroup,i.orChildrenGroup=this.orChildrenGroup?[...this.orChildrenGroup]:this.orChildrenGroup,i.successCalls=[...this.successCalls],i.errorCalls=[...this.errorCalls],i.calledBySuccess=[...this.calledBySuccess],i.calledByError=[...this.calledByError],i.calledByEntry=[...this.calledByEntry],i.parent=this.parent,this}recursiveCaptureUpstreamVersions(i){const a=[],o=[],p=[],e=[];if(this.parent){this.parent.increaseVersion(i);const y=this.parent.recursiveCaptureUpstreamVersions(i);a.push(this.parent,...y.updated),o.push(...y.added),p.push(...y.removed)}return{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}async restoreVersion(i){var v;const a=[],o=[],p=[],e=[];if(this.version===i)return{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this};if(!this.knownVersions){const E=new Map;for(const[b,A]of this.knownVersions||new Map){if(E.set(b,A),A.activeVersion=!1,A.knownVersions)for(const[$,V]of A.knownVersions)E.set($,V);A.knownVersions=null}}let y=(v=this.knownVersions)==null?void 0:v.get(i);if(!y){const E=await this.APILoadVersion({},i);if(!E)throw new Error(`Version with id '${i}' for entity with id '${this.id}' not found.`);y=new Xt(E,this.project)}return this.metaSync(y.toShallowJSON(),null),this.previousVersion=y.previousVersion,this.version=y.version,this.createdAt=y.createdAt,this.author=y.author,this.deleted=y.deleted,this.inputs=y.inputs,this.declaration=y.declaration,this.andChildrenGroup=y.andChildrenGroup,this.orChildrenGroup=y.orChildrenGroup,this.successCalls=y.successCalls,this.errorCalls=y.errorCalls,this.calledBySuccess=y.calledBySuccess,this.calledByError=y.calledByError,this.calledByEntry=y.calledByEntry,this.parent=y.parent,{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}updateWithShallowTransfer(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"update-with-shallow-transfer"))){if(this.metaSync(i,a),this.version=i.version,this.createdAt=i.createdAt,this.author=i.author,this.deleted=i.deleted,this.previousVersion=i.previousVersion,i.parent){const o=H(i.parent),p=this.project.get(o),e=this.parent;if(e&&e.id!==(p==null?void 0:p.id)&&this.removeFromParent(a),p)this.setParent(p,a);else throw a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${o}' that isn't found in the project`)}else throw a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(i.declaration){const o=H(i.declaration),p=this.project.get(o);p&&this.setDeclaration(p)}return i.calledByEntry.forEach(o=>{const p=H(o),e=this.project.get(p);e&&(this.addEntryCaller(e,a),e.addCall(this,a))}),[...this.calledByEntry].forEach(o=>{i.calledByEntry.find(e=>H(e)===o.id)||(this.removeCaller(o,a),o.removeCall(this,a))}),i.calledBySuccess.forEach(o=>{const p=H(o),e=this.project.get(p);e&&(this.addSuccessCaller(e,a),e.addSuccessCall(this,a))}),[...this.calledBySuccess].forEach(o=>{i.calledBySuccess.find(e=>H(e)===o.id)||(this.removeCaller(o,a),o.removeCall(this,a))}),i.calledByError.forEach(o=>{const p=H(o),e=this.project.get(p);e&&(this.addErrorCaller(e,a),e.addErrorCall(this,a))}),[...this.calledBySuccess].forEach(o=>{i.calledBySuccess.find(e=>H(e)===o.id)||(this.removeCaller(o,a),o.removeCall(this,a))}),this.captureVersion(),this.subscribeToDependencies(),a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),this}hydrateAncestors(){const i=[],a=[],o=[],p=[];if(this.initialData.parent){const e=H(this.initialData.parent),y=this.project.get(e);if(y)this.setParent(y,null);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${e}' that isn't found in the project`)}else throw new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(this.initialData.declaration){const e=H(this.initialData.declaration),y=this.project.get(e);y&&(this.setDeclaration(y),i.push(y))}return this.initialData.calledByEntry.forEach(e=>{const y=H(e),v=this.project.get(y);v&&this.addEntryCaller(v,null)}),this.initialData.calledBySuccess.forEach(e=>{const y=H(e),v=this.project.get(y);v&&this.addSuccessCaller(v,null)}),this.initialData.calledByError.forEach(e=>{const y=H(e),v=this.project.get(y);v&&this.addErrorCaller(v,null)}),{updated:R(i),added:R(a),removed:R(o),affected:R(p),self:this}}afterAllChildrenInitialized(i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"after-all-children-initialized"))){const a=[],o=[],p=[],e=[];this.initialized=!0;const{updated:y,added:v,removed:E}=this.syncInputs(i);return a.push(...y),o.push(...v),p.push(...E),this.captureVersion(),i==null||i.attemptAutoclose("after-all-children-initialized",this.id),{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}addSelfToProject(i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-self-to-project"))){const a=[this],o=[],p=[],e=[];return this.parent===this.project?this.project.addCondition(this):this.parent.type===f.Condition&&(this.parent.declaration.id===Mr.And?this.parent.addToAndGroup(this):this.parent.declaration.id===Mr.Or&&this.parent.addToOrGroup(this)),this.successCalls.forEach(y=>{y.addSuccessCaller(this,i),a.push(y)}),this.errorCalls.forEach(y=>{y.addErrorCaller(this,i),a.push(y)}),this.calledByEntry.forEach(y=>{y.addCall(this,i),a.push(y)}),this.calledBySuccess.forEach(y=>{y.addSuccessCall(this,i),a.push(y)}),this.calledByError.forEach(y=>{y.addErrorCall(this,i),a.push(y)}),this.subscribe(),this.subscribeToDependencies(),i==null||i.attemptAutoclose("add-self-to-project",this.id),{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}removeInput(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-input"))){const o=this.inputs.findIndex(p=>p.id===i.id);return o>-1&&(this.inputs.splice(o,1),a&&(a==null||a.add(this,S.Affected))),a==null||a.attemptAutoclose("remove-input",this.id),this}addInput(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-input"))){return this.inputs.includes(i)?(a==null||a.attemptAutoclose("add-input",this.id),this):(this.inputs.push(i),a==null||a.add(this,S.Affected),a==null||a.attemptAutoclose("add-input",this.id),this)}addOutput(i){return this}removeOutput(i){return this}addSuccessCaller(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-success-caller")),o=!1){return this.calledBySuccess.find(p=>p.id===i.id)||(this.calledBySuccess.push(i),a==null||a.add(this,S.Updated),o&&We(this,a)),a==null||a.attemptAutoclose("add-success-caller",this.id),this}addErrorCaller(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-error-caller")),o=!1){return this.calledByError.find(p=>p.id===i.id)||(this.calledByError.push(i),a==null||a.add(this,S.Updated),o&&We(this,a)),a==null||a.attemptAutoclose("add-error-caller",this.id),this}addEntryCaller(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-entry-caller")),o=!1){return this.calledByEntry.find(p=>p.id===i.id)||(this.calledByEntry.push(i),a==null||a.add(this,S.Updated),o&&We(this,a)),a==null||a.attemptAutoclose("add-entry-caller",this.id),this}addErrorCall(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-error-call")),o=!1){return this.errorCalls.find(p=>p.id===i.id)||(this.errorCalls.push(i),o&&We(this,a),a==null||a.add(this,S.Affected)),a==null||a.attemptAutoclose("add-error-call",this.id),this}addSuccessCall(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-success-call")),o=!1){return this.successCalls.find(p=>p.id===i.id)||(this.successCalls.push(i),o&&We(this,a),a==null||a.add(this,S.Affected)),a==null||a.attemptAutoclose("add-success-call",this.id),this}removeCall(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-call")),o=!1){const p=this.successCalls.findIndex(y=>y.id===i.id);p>-1&&(this.successCalls.splice(p,1),a==null||a.add(this,S.Affected));const e=this.errorCalls.findIndex(y=>y.id===i.id);return e>-1&&(this.errorCalls.splice(e,1),a==null||a.add(this,S.Affected)),o&&We(this,a),a==null||a.attemptAutoclose("remove-call",this.id),this}removeCaller(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-caller")),o=!1){return this.calledBySuccess=this.calledBySuccess.filter(p=>p.id!==i.id?!0:(a==null||a.add(this,S.Updated),a==null||a.add(p,S.Affected),!1)),this.calledByError=this.calledByError.filter(p=>p.id!==i.id?!0:(a==null||a.add(this,S.Updated),a==null||a.add(p,S.Affected),!1)),this.calledByEntry=this.calledByEntry.filter(p=>p.id!==i.id?!0:(a==null||a.add(this,S.Updated),a==null||a.add(p,S.Affected),!1)),o&&We(this,a),a==null||a.attemptAutoclose("remove-caller",this.id),this}setParent(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"set-parent"))){var o;return((o=this.parent)==null?void 0:o.id)!==(i==null?void 0:i.id)&&(this.parent=i,a&&(a==null||a.add(this,S.Updated))),a==null||a.attemptAutoclose("set-parent",this.id),this}removeChildGroup(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-child-group"))){if(this.andChildrenGroup){const o=this.andChildrenGroup.findIndex(p=>p.id===i.id);o!==-1&&(this.andChildrenGroup.splice(o,1),a==null||a.add(this,S.Updated))}if(this.orChildrenGroup){const o=this.orChildrenGroup.findIndex(p=>p.id===i.id);o!==-1&&(this.orChildrenGroup.splice(o,1),a==null||a.add(this,S.Updated))}return a==null||a.attemptAutoclose("remove-child-group",this.id),this}setDeclaration(i){return this.declaration=i,this}initChildren(i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.declaration=te(this.initialData.declaration,this.project),this.initialData.andChildrenGroup&&(this.andChildrenGroup=this.initialData.andChildrenGroup.map(a=>{const o=te(a,this.project);return o.setParent(this,null),o.initChildren(i),o})),this.initialData.orChildrenGroup&&(this.orChildrenGroup=this.initialData.orChildrenGroup.map(a=>{const o=te(a,this.project);return o.setParent(this,null),o.initChildren(i),o})),this.successCalls=this.initialData.successCalls.map(a=>{const o=te(a,this.project);if(o.addSuccessCaller(this),[f.BreakStatement,f.ContinueStatement].includes(o.type))o.setParent(this.parent.parent,null),o.initChildren(i);else if(o.type===f.ReturnStatement){const p=Yr(this,this.project);o.setParent(p,null),o.initChildren(i)}else o.type!==f.InternalCall&&(o.setParent(this.parent,null),o.initChildren(i));return o}),this.errorCalls=this.initialData.errorCalls.map(a=>{const o=te(a,this.project);if(o.addErrorCaller(this),[f.BreakStatement,f.ContinueStatement].includes(o.type))o.setParent(this.parent.parent,null),o.initChildren(i);else if(o.type===f.ReturnStatement){const p=Yr(this,this.project);o.setParent(p,null),o.initChildren(i)}else o.type!==f.InternalCall&&(o.setParent(this.parent,null),o.initChildren(i));return o}),this.inputs=this.initialData.inputs.map(a=>{const o=te(a,this.project);return o.setParent(this,null),o.initChildren(i),o}),this.subscribeToDependencies(),this.afterAllChildrenInitialized(i),i==null||i.attemptAutoclose("init-children",this.id),this)}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"meta-sync"))){const o=xr(this,i),p=this.toMeta();return this.x=i.x!==void 0?i.x:p.x,this.y=i.y!==void 0?i.y:p.y,this.index=i.index!==void 0?i.index:p.index,super.metaSync(i),i.deleted===!0&&!p.deleted?a==null||a.add(this,S.Removed):i.deleted===!1&&p.deleted?a==null||a.add(this,S.Added):o&&(a==null||a.add(this,S.Updated)),a==null||a.attemptAutoclose("meta-sync",this.id),this}async APILoad(i=ve,...a){return await Xt.repository.APILoad(this.id,...a),this}async APICreate(i=ve,...a){return await Xt.repository.APICreate(this.toShallowJSON(),...a),this}async APIUpdate(i=ve,...a){return await Xt.repository.APIUpdate(this.toShallowJSON(),...a),this}async APIDelete(i=ve,...a){return await Xt.repository.APIDelete(this.toShallowJSON(),...a),this}async APIClone(i=ve,...a){return await Xt.repository.APIClone(this.id,...a),this}async APILoadVersion(i=ve,a,...o){return await Xt.repository.APILoadVersion(this.id,a,...o)}removeFromParent(i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-from-parent"))){var y;const a=[],o=[],p=[],e=[];return this.parent.type===f.Project?(this.parent.removeCondition(this),e.push(this.parent)):((y=this.parent)==null?void 0:y.type)===f.Condition?this.parent.removeChildGroup(this):this.parent.detachedChildren.includes(this)&&this.parent.unsubscribeDetachedChild(this),i==null||i.attemptAutoclose("remove-from-parent",this.id),{added:R(p),updated:R(a),removed:R(o),affected:R(e),self:this}}remove({ignoreUpstream:i}={ignoreUpstream:!1},a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-entity"))){const o=[],p=[],e=[],y=[];if(a!=null&&a.hasRemoved(this.id))return a==null||a.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(p.push(this),this.unsubscribe(),this.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},a),Object.values(this.detachedDependents).forEach(v=>{const{updated:E,removed:b,added:A}=v.entity.onDetachedDependencyRemoved(this,v.field,a);o.push(...E),p.push(...b),e.push(...A)}),this.andChildrenGroup&&this.andChildrenGroup.forEach(v=>{const{removed:E,updated:b}=v.remove({ignoreUpstream:!0},a);p.push(...E),o.push(...b)}),this.orChildrenGroup&&this.orChildrenGroup.forEach(v=>{const{removed:E,updated:b}=v.remove({ignoreUpstream:!0},a);p.push(...E),o.push(...b)}),this.inputs.forEach(v=>{const{updated:E,removed:b}=v.remove({ignoreUpstream:!0},a);o.push(...E),p.push(...b)}),this.successCalls.forEach(v=>{o.push(v),v.removeCaller(this,a)}),this.errorCalls.forEach(v=>{o.push(v),v.removeCaller(this,a)}),!i){const v=this.removeFromParent(a);e.push(...v.added),o.push(...v.updated),p.push(...v.removed),y.push(...v.affected),this.calledBy.forEach(E=>{o.push(E),E.removeCall(this,a)})}return a==null||a.attemptAutoclose("remove-entity",this.id),{added:R(e),updated:R(o),removed:R(p),affected:R(y),self:this}}restore({}={},i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"restore-entity"))){const a=[],o=[],p=[],e=[];return i!=null&&i.hasAdded(this.id)?(i==null||i.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},i),Object.values(this.detachedDependents).forEach(y=>{const{updated:v,removed:E,added:b}=y.entity.onDetachedDependencyRestored(this,y.field,i);o.push(...v),p.push(...E),a.push(...b)}),this.andChildrenGroup&&this.andChildrenGroup.forEach(y=>{const{updated:v,added:E}=y.restore({},i);o.push(...v),a.push(...E)}),this.orChildrenGroup&&this.orChildrenGroup.forEach(y=>{const{updated:v,added:E}=y.restore({},i);o.push(...v),a.push(...E)}),this.inputs.forEach(y=>{const{updated:v}=y.restore({},i);o.push(...v)}),this.successCalls.forEach(y=>{o.push(y),y.addSuccessCaller(this,i)}),this.errorCalls.forEach(y=>{o.push(y),y.addErrorCaller(this,i)}),this.calledBySuccess.forEach(y=>{o.push(y),y.addSuccessCall(this,i)}),this.calledByError.forEach(y=>{o.push(y),y.addErrorCall(this,i)}),this.calledByEntry.forEach(y=>{o.push(y),y.addCall(this,i)}),this.parent.type===f.Project&&this.project.addCondition(this),i==null||i.attemptAutoclose("restore-entity",this.id),{added:R(a),updated:R(o),removed:R(p),affected:R(e),self:this})}toFlat(i=new Set){var o,p;return i.has(this.id)?[]:(i.add(this.id),[this,...((o=this.andChildrenGroup)==null?void 0:o.flatMap(e=>e.toFlat(i)))||[],...((p=this.orChildrenGroup)==null?void 0:p.flatMap(e=>e.toFlat(i)))||[],...this.inputs.flatMap(e=>e.toFlat(i)),...this.successCalls.flatMap(e=>e.toFlat(i)),...this.errorCalls.flatMap(e=>e.toFlat(i)),...this.calledBy.flatMap(e=>e.toFlat(i))])}toFlatIds(i=new Set){var o,p;return i.has(this.id)?[]:(i.add(this.id),[this.id,...((o=this.andChildrenGroup)==null?void 0:o.flatMap(e=>e.toFlatIds(i)))||[],...((p=this.orChildrenGroup)==null?void 0:p.flatMap(e=>e.toFlatIds(i)))||[],...this.inputs.flatMap(e=>e.toFlatIds(i)),...this.successCalls.flatMap(e=>e.toFlatIds(i)),...this.errorCalls.flatMap(e=>e.toFlatIds(i)),...this.calledBy.flatMap(e=>e.toFlatIds(i))])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,index:this.index,x:this.x,y:this.y,type:this.type}}toJSON(i=new Set){var a,o;return i.has(this.id)?this.toReference():(i.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,index:this.index,x:this.x,y:this.y,declaration:this.declaration.toJSON(i),andChildrenGroup:((a=this.andChildrenGroup)==null?void 0:a.map(p=>p.toJSON(i)))||null,orChildrenGroup:((o=this.orChildrenGroup)==null?void 0:o.map(p=>p.toJSON(i)))||null,successCalls:this.successCalls.map(p=>p.toJSON(i)),errorCalls:this.errorCalls.map(p=>p.toJSON(i)),calledBySuccess:this.calledBySuccess.map(p=>p.toReference()),calledByError:this.calledByError.map(p=>p.toReference()),calledByEntry:this.calledByEntry.map(p=>p.toReference()),inputs:this.inputs.map(p=>p.toJSON(i)),parent:this.parent.toReference()})}toJSONClone(i=ke){var o,p,e,y,v,E,b;let a;return(o=i.seenEntityMaps)!=null&&o.has(this.id)?a=i.seenEntityMaps.get(this.id):(a=i.newId||Kr(this,this.project,i.uuidStrategy),i.seenEntityMaps&&i.seenEntityMaps.set(this.id,a)),(p=i.seenEntities)!=null&&p.has(a)||(e=i.seenEntities)!=null&&e.has(this.id)?this.toReference({seenEntityMaps:i.seenEntityMaps}):((y=i.seenEntities)==null||y.add(a),(v=i.seenEntities)==null||v.add(this.id),{id:a,version:N.UUID.uuid(),createdAt:i.timestamp||L().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,index:this.index,x:this.x,y:this.y,declaration:this.declaration.toJSON(),andChildrenGroup:((E=this.andChildrenGroup)==null?void 0:E.map(A=>A.toJSONClone({...i,newId:null})))||null,orChildrenGroup:((b=this.orChildrenGroup)==null?void 0:b.map(A=>A.toJSONClone({...i,newId:null})))||null,successCalls:this.successCalls.map(A=>A.toJSONClone({...i,newId:null})),errorCalls:this.errorCalls.map(A=>A.toJSONClone({...i,newId:null})),calledBySuccess:this.calledBySuccess.map(A=>A.toReference({seenEntityMaps:i.seenEntityMaps})),calledByError:this.calledByError.map(A=>A.toReference({seenEntityMaps:i.seenEntityMaps})),calledByEntry:this.calledByEntry.map(A=>A.toReference({seenEntityMaps:i.seenEntityMaps})),inputs:this.inputs.map(A=>A.toJSONClone({...i,newId:null})),parent:this.parent.toReference({seenEntityMaps:i.seenEntityMaps})})}toReference(i=ke){var o;let a=this.id;return(o=i.seenEntityMaps)!=null&&o.has(this.id)&&(a=i.seenEntityMaps.get(this.id)),{id:a+"--"+N.UUID.uuid()+"--ref",type:f.GenericReference,entityId:a,version:this.version,entityType:this.type}}toShallowJSON(i=ke){var o,p,e;let a=this.id;return(o=i.seenEntityMaps)!=null&&o.has(this.id)&&(a=i.seenEntityMaps.get(this.id)),{id:a,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,index:this.index,x:this.x,y:this.y,declaration:this.declaration.toReference(i),andChildrenGroup:((p=this.andChildrenGroup)==null?void 0:p.map(y=>y.toReference(i)))||null,orChildrenGroup:((e=this.orChildrenGroup)==null?void 0:e.map(y=>y.toReference(i)))||null,inputs:this.inputs.map(y=>y.toReference(i)),successCalls:this.successCalls.map(y=>y.toReference(i)),errorCalls:this.errorCalls.map(y=>y.toReference(i)),calledBySuccess:this.calledBySuccess.map(y=>y.toReference(i)),calledByError:this.calledByError.map(y=>y.toReference(i)),calledByEntry:this.calledByEntry.map(y=>y.toReference(i)),parent:this.parent.toReference(i)}}toFlatJSON(i=new Set){var o,p;return i.has(this.id)?[]:(i.add(this.id),[this.toShallowJSON(),...((o=this.andChildrenGroup)==null?void 0:o.flatMap(e=>e.toFlatJSON(i)))||[],...((p=this.orChildrenGroup)==null?void 0:p.flatMap(e=>e.toFlatJSON(i)))||[],...this.inputs.flatMap(e=>e.toFlatJSON(i)),...this.successCalls.flatMap(e=>e.toFlatJSON(i)),...this.errorCalls.flatMap(e=>e.toFlatJSON(i)),...this.calledBy.flatMap(e=>e.toFlatJSON(i))])}toGenerationTarget(){const i=this.parent.type===f.Project?void 0:this.parent.id;return{id:this.id,type:this.type,declaration:this.declaration.id,calledByEntry:this.calledByEntry.map(a=>a.id),calledBySuccess:this.calledBySuccess.map(a=>a.id),calledByError:this.calledByError.map(a=>a.id),parent:i}}toFlatGenerationTarget(i=new Set){var o,p;return i.has(this.id)?[]:(i.add(this.id),[this.toGenerationTarget(),...((o=this.andChildrenGroup)==null?void 0:o.flatMap(e=>e.toFlatGenerationTarget(i)))||[],...((p=this.orChildrenGroup)==null?void 0:p.flatMap(e=>e.toFlatGenerationTarget(i)))||[],...this.inputs.flatMap(e=>e.toFlatGenerationTarget(i)),...this.successCalls.flatMap(e=>e.toFlatGenerationTarget(i)),...this.errorCalls.flatMap(e=>e.toFlatGenerationTarget(i))])}clearErrors(){var i,a;return this.errors=[],(i=this.andChildrenGroup)==null||i.forEach(o=>o.clearErrors()),(a=this.orChildrenGroup)==null||a.forEach(o=>o.clearErrors()),this.inputs.forEach(o=>o.clearErrors()),this.successCalls.forEach(o=>o.clearErrors()),this.errorCalls.forEach(o=>o.clearErrors()),this}validate(){const i=pj(this);return this.errors=i,{success:!0}}getErrors(){return[...this.errors,...this.inputs.flatMap(a=>a.getErrors())]}getShallowErrors(){return this.errors}clone(i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"clone-entity")),a=null,o=null,p=!0){var F,K,Z;let e=Sr(a,this);const y=this.toJSON(),v=o||N.UUID.uuid();y.inputs=[];const E=v.split("-id"),b=E[E.length-1||0]||v;y.id=v,y.version=N.UUID.uuid(),y.createdAt=(i==null?void 0:i.timestamp)||L().toISOString(),y.author=(i==null?void 0:i.author)||"1",y.previousVersion=null,y.deleted=!1;const A=dr(y,e);a?A.setParent(a,null):A.setParent(this.parent,null),p&&A.subscribe(),A.initChildren(i),i==null||i.add(A,S.Added);const $=(F=this.andChildrenGroup)==null?void 0:F.map(ie=>ie.clone(i,A,N.UUID.uuid(),p)),V=(K=this.orChildrenGroup)==null?void 0:K.map(ie=>ie.clone(i,A,N.UUID.uuid(),p));A.andChildrenGroup=$||null,A.orChildrenGroup=V||null;const B=(Z=this.inputs)==null?void 0:Z.map((ie,X)=>ie.clone(i,A,b+"-input-map-"+X+"-id",p));return A.inputs=B,i==null||i.attemptAutoclose("clone-entity",this.id),A}addToAndGroup(i){return this.andChildrenGroup||(this.andChildrenGroup=[]),this.andChildrenGroup.includes(i)||this.andChildrenGroup.push(i),this}addToOrGroup(i){return this.orChildrenGroup||(this.orChildrenGroup=[]),this.orChildrenGroup.includes(i)||this.orChildrenGroup.push(i),this}removeUnrecognizedInputs(i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-unrecognized-inputs"))){const a=[],o=[],p=[],e=[];return this.inputs.forEach(v=>{if(!this.declaration.inputs.find(b=>{var A;return b.id===((A=v.declaration)==null?void 0:A.id)})){const b=v.remove({ignoreUpstream:!1},i);p.push(...b.removed),a.push(...b.updated)}}),this.inputs.filter((v,E)=>{const b=this.inputs.findIndex($=>$.declaration===v.declaration&&$!==v);if(b===-1)return!1;const A=this.inputs[b];return L(A==null?void 0:A.createdAt).isSame(L(v.createdAt))?E>b:!!L(A==null?void 0:A.createdAt).isAfter(v.createdAt)}).forEach(v=>{const E=v.remove({ignoreUpstream:!1},i);p.push(...E.removed),a.push(...E.updated)}),i==null||i.attemptAutoclose("remove-unrecognized-inputs",this.id),{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}syncInputs(i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"sync-missing-fixed-inputs"))){const a=[],o=[],p=[],e=[],y=this.declaration.inputs.filter(A=>A.parentRelationType===oe.FixedArguments&&!this.inputs.find($=>$.declaration.id===A.id));this.inputs.sort((A,$)=>A.index-$.index),y.forEach(A=>{this.inputs.forEach(B=>{B.index>=A.index&&B.metaSync({index:B.index+1},i)});const $={id:N.UUID.uuid(),version:N.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||L().toISOString(),author:N.sessionAuthor,previousVersion:null,deleted:!1,type:f.InputMap,declaration:A.toJSON(),readsValue:null,defaultValue:null,index:A.index,name:null,codeName:null,description:null,parent:this.toReference()},V=te($,this.project);V.setParent(this,i),V.initChildren(i),i==null||i.add(V,S.Added),V.addSelfToProject(i)}),this.inputs.sort((A,$)=>A.index-$.index);const{updated:v,added:E,removed:b}=this.removeUnrecognizedInputs(i);return a.push(...v),o.push(...E),p.push(...b),i==null||i.attemptAutoclose("sync-missing-fixed-inputs",this.id),{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}getUnusedInputs(){return this.inputs.filter(i=>i.suggestion||!i.readsValue&&!i.defaultValue)}getUnusedOutputs(){return[]}getUsedInputs(){return this.inputs.filter(i=>!i.suggestion&&(i.readsValue||i.defaultValue))}getUsedOutputs(){return[]}};g(Xt,"repository",{APICreate:async(i,...a)=>i,APIUpdate:async(i,...a)=>i,APIDelete:async(i,...a)=>i,APIClone:async(i,...a)=>{},APILoad:async(i,...a)=>null,APILoadVersion:async(i,a,...o)=>null}),g(Xt,"type",f.Condition),g(Xt,"USER_MANAGED_PARENT_TYPES",[...Br,f.Project,f.Condition]),g(Xt,"PARENT_TYPES",[...Xt.USER_MANAGED_PARENT_TYPES]),g(Xt,"MUTABLE_BASE_PROPERTIES",["operator"]),g(Xt,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion","index"]),g(Xt,"BASE_PROPERTIES",[...Xt.MUTABLE_BASE_PROPERTIES,...Xt.INMUTABLE_BASE_PROPERTIES]),g(Xt,"MUTABLE_META_PROPERTIES",["x","y"]),g(Xt,"INMUTABLE_META_PROPERTIES",[...Xt.INMUTABLE_BASE_PROPERTIES]),g(Xt,"META_PROPERTIES",[...Xt.MUTABLE_META_PROPERTIES,...Xt.INMUTABLE_META_PROPERTIES]),g(Xt,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry","parent"]),g(Xt,"INMUTABLE_UPSTREAM_PROPERTIES",[]),g(Xt,"UPSTREAM_PROPERTIES",[...Xt.MUTABLE_UPSTREAM_PROPERTIES,...Xt.INMUTABLE_UPSTREAM_PROPERTIES]),g(Xt,"MUTABLE_DOWNSTREAM_PROPERTIES",["andChildrenGroup","orChildrenGroup","successCalls","errorCalls","inputsDeclarations","inputs"]),g(Xt,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),g(Xt,"DOWNSTREAM_PROPERTIES",[...Xt.MUTABLE_DOWNSTREAM_PROPERTIES,...Xt.INMUTABLE_DOWNSTREAM_PROPERTIES]),g(Xt,"PROPERTIES",[...Xt.META_PROPERTIES,...Xt.UPSTREAM_PROPERTIES,...Xt.DOWNSTREAM_PROPERTIES]);let ho=Xt;function hj(d){var y;const u=u0e(),i=d.toJSON();u.safeParse(i).success,(y=d.dataType)==null||y.validate(),d.inputs.forEach(v=>v.validate()),d.outputs.forEach(v=>v.validate()),d.internalCalls.forEach(v=>v.validate());const p=[...Ka(d),...go(d),...yj(d)],e=xb(d);return p.push(...e),Er(d.errors,p)}function yj(d){const u=[],i=d.name;if(!i){const $=mt({id:`${d.id}--${ae.EmptyName}`,message:`Variable declaration "${ne(d,d.project)}" with id "${d.id}" does not have a name. Entities of type ${d.type} must have valid names.`,severity:q.Error,code:ae.EmptyName,entity:d});return u.push($.error),u}const o=[...d.project.functions,...d.project.entities.flatMap($=>$.methods)].filter($=>$.id!==d.id),p=i.trim(),e=!o.some($=>$.name===i||$.name===p);if(!e){const $=mt({id:`${d.id}--${ae.NameNotUniqueInScope}`,message:`Variable declaration "${ne(d,d.project)}" with id "${d.id}" does not have a unique name. Entities of type ${d.type} must have valid names among all other entities of its type.`,severity:q.Error,code:ae.NameNotUniqueInScope,entity:d});u.push($.error)}const y=jr(i);if(!!o.some($=>jr($.name)===y)&&e){const $=mt({id:`${d.id}--${ae.NameAsResolvedCodeNameNotUniqueInScope}`,message:`Variable declaration "${ne(d,d.project)}" with id "${d.id}" does not have a unique name once it is resolved as it will appear in code: "${y}". Entities of type ${d.type} must have valid names including their code name form.`,severity:q.Error,code:ae.NameAsResolvedCodeNameNotUniqueInScope,entity:d});u.push($.error)}if(!/^[a-zA-Z_]/.test(i)){const $=mt({id:`${d.id}--${ae.NameMustStartWithLetterOrUnderscore}`,message:`Variable declaration "${ne(d,d.project)}" with id "${d.id}" has a name that does not start with a letter or underscore.`,severity:q.Error,code:ae.NameMustStartWithLetterOrUnderscore,entity:d});u.push($.error)}const b=i.substring(1);if(!/^[a-zA-Z0-9_ ]*$/.test(b)){const $=mt({id:`${d.id}--${ae.NameCanOnlyContainLettersNumbersUnderscoreAndSpaces}`,message:`Variable declaration "${ne(d,d.project)}" with id "${d.id}" has a name that contains invalid characters. It can only contain letters, numbers, underscores and spaces.`,severity:q.Error,code:ae.NameCanOnlyContainLettersNumbersUnderscoreAndSpaces,entity:d});u.push($.error)}return u}const Q0e=Object.freeze(Object.defineProperty({__proto__:null,validate:hj,validateVariableDeclarationName:yj},Symbol.toStringTag,{value:"Module"}));function mj(d){const u=Lme(),i=d.toJSON();u.safeParse(i).success,d.inputs.forEach(y=>y.validate()),d.outputs.forEach(y=>y.validate()),d.internalCalls.forEach(y=>y.validate());const p=[...Ka(d),...go(d)],e=xb(d);return p.push(...e),Er(d.errors,p)}const eve=Object.freeze(Object.defineProperty({__proto__:null,validate:mj},Symbol.toStringTag,{value:"Module"}));var IA=(d=>(d.Parent="parent",d.DataTypeEntity="data-type-entity",d.VarDeclaration="var-declaration",d))(IA||{});const Gt=class Gt extends Nr{constructor(i,a){super(i);g(this,"initialData");g(this,"id");g(this,"x");g(this,"y");g(this,"type",f.VariableInstance);g(this,"defaultValue",null);g(this,"writesValues",[]);g(this,"readsValue",null);g(this,"declaration");g(this,"inputs",[]);g(this,"outputs",[]);g(this,"calledBySuccess",[]);g(this,"calledByError",[]);g(this,"calledByEntry",[]);g(this,"successCalls",[]);g(this,"errorCalls",[]);g(this,"internalCalls",[]);g(this,"project");g(this,"errors",[]);g(this,"parent");g(this,"detachedDependents",{});g(this,"knownVersions",null);g(this,"activeVersion",!1);g(this,"initialized",!1);g(this,"startedInitialization",!1);g(this,"suggestion",!1);g(this,"_codeNativeValueValidation",null);this.initialData=i,this.project=a,this.id=i.id,this.x=i.x,this.y=i.y}static new(i=null){return{id:N.UUID.uuid(),version:N.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||L().toISOString(),author:(i==null?void 0:i.author)||N.sessionAuthor,previousVersion:null,deleted:!1,type:f.VariableInstance,declaration:null,internalCalls:[],successCalls:[],errorCalls:[],readsValue:null,writesValues:[],defaultValue:null,inputs:[],outputs:[],parent:null,calledByEntry:[],calledBySuccess:[],calledByError:[],x:0,y:0}}static fromGenerationTarget(i,a){let o=a;if(i.parent){const V=H(i.parent);o=a.get(V)}const p=H(i.declaration),e=a.get(p),y=i.calledByEntry.map(V=>{const B=H(V);return a.get(B)}),v=i.calledBySuccess.map(V=>{const B=H(V);return a.get(B)}),E=i.calledByError.map(V=>{const B=H(V);return a.get(B)});let b=null;if(i.readsValue){const V=H(i.readsValue);b=a.get(V)}const A={id:i.id,version:N.UUID.uuid(),createdAt:L().toISOString(),author:N.sessionAuthor,previousVersion:null,deleted:!1,type:f.VariableInstance,declaration:e.toReference(),calledByEntry:y,calledBySuccess:v,calledByError:E,defaultValue:null,errorCalls:[],successCalls:[],internalCalls:[],readsValue:b,inputs:[],outputs:[],writesValues:[],x:0,y:0,parent:o},$=te(A,a);return $.setParent(o,null),$}static validateGenerationTarget(i,a){let o=JSON.parse(JSON.stringify(i));const p=[],e=li(o,{parent:{list:!1,types:[...Br,f.Project],optional:!0},declaration:{list:!1,types:[f.VariableDeclaration]}},a);return o=e.modifiedData,p.push(...e.errors,...Ur(o)),{errors:p,modifiedData:o}}get codeName(){var i;return(i=this.declaration)==null?void 0:i.codeName}get codeNativeValueValidation(){var i;return this._codeNativeValueValidation||((i=this.declaration)==null?void 0:i.codeNativeValueValidation)||null}validateGeneratedUpdate(i){const a=[];let o=JSON.parse(JSON.stringify(i));const p=sf(o,this);return o=p.modifiedData,a.push(...p.errors),i.parent&&a.push(new ee({id:`${this.id}--${k.InvalidParentUpdate}`,code:k.InvalidParentUpdate,severity:q.Error,message:`Entity of type '${this.type}' with id '${this.id}' cannot have the 'parent' property updated. The 'parent' on a callable entity, is its scope. It scope is auto-calculated implicitly by the its caller.
79
+ If an entity is called by another, they must be in the same scope, which means they have the same parent.`})),{errors:a,modifiedData:i}}subscribeDependents(i){return i.forEach(a=>{this.detachedDependents[a.entity.id]||(this.detachedDependents[a.entity.id]=a)}),this}unsubscribeDependents(i){return i.forEach(a=>{this.detachedDependents[a.entity.id]&&delete this.detachedDependents[a.entity.id]}),this}syncDependents(i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"sync-dependents"))){const a=[],o=[],p=[],e=[];return Object.values(this.detachedDependents).forEach(y=>{const v=y.entity.afterAllChildrenInitialized(i);a.push(...v.updated),o.push(...v.added),p.push(...v.removed),e.push(...v.affected)}),i==null||i.attemptAutoclose("sync-dependents",this.id),{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}onDetachedDependencyRemoved(i,a,o){const p=[],e=[],y=[],v=[];if(a==="parent"){const{updated:E,added:b,removed:A}=this.remove({ignoreUpstream:!1},o);p.push(...E),e.push(...b),y.push(...A)}return{updated:R(p),added:R(e),removed:R(y),affected:R(v),self:this}}onDetachedDependencyRestored(i,a,o){const p=[],e=[],y=[],v=[];if(a==="parent"){const{updated:E,added:b,removed:A}=this.restore({},o);p.push(...E),e.push(...b),y.push(...A)}return{updated:R(p),added:R(e),removed:R(y),affected:R(v),self:this}}unsubscribeFromDependencies(){return this.parent.unsubscribeDependents([{entity:this,field:"parent"}]),this}subscribeToDependencies(){var i;return(i=this.parent)==null||i.subscribeDependents([{entity:this,field:"parent"}]),this}increaseVersion(i){if(i&&!L(i).isValid())throw new Error(`The shared timestamp '${i}' is not a valid ISO 8601 date string.`);return i&&L(i).isSame(L(this.createdAt))?this:(this.previousVersion=this.version,this.version=N.UUID.uuid(),this.createdAt=L(i).toISOString()||L().toISOString(),this)}captureVersion(){var a;const i=((a=this.knownVersions)==null?void 0:a.get(this.version))||new Xt(this,this.project);return i.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,i):new Map([[this.version,i]]),i.inputs=[...this.inputs],i.declaration=this.declaration,i.andChildrenGroup=this.andChildrenGroup?[...this.andChildrenGroup]:this.andChildrenGroup,i.orChildrenGroup=this.orChildrenGroup?[...this.orChildrenGroup]:this.orChildrenGroup,i.successCalls=[...this.successCalls],i.errorCalls=[...this.errorCalls],i.calledBySuccess=[...this.calledBySuccess],i.calledByError=[...this.calledByError],i.calledByEntry=[...this.calledByEntry],i.parent=this.parent,this}recursiveCaptureUpstreamVersions(i){const a=[],o=[],p=[],e=[];if(this.parent){this.parent.increaseVersion(i);const y=this.parent.recursiveCaptureUpstreamVersions(i);a.push(this.parent,...y.updated),o.push(...y.added),p.push(...y.removed)}return{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}async restoreVersion(i){var v;const a=[],o=[],p=[],e=[];if(this.version===i)return{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this};if(!this.knownVersions){const E=new Map;for(const[b,A]of this.knownVersions||new Map){if(E.set(b,A),A.activeVersion=!1,A.knownVersions)for(const[$,V]of A.knownVersions)E.set($,V);A.knownVersions=null}}let y=(v=this.knownVersions)==null?void 0:v.get(i);if(!y){const E=await this.APILoadVersion({},i);if(!E)throw new Error(`Version with id '${i}' for entity with id '${this.id}' not found.`);y=new Xt(E,this.project)}return this.metaSync(y.toShallowJSON(),null),this.previousVersion=y.previousVersion,this.version=y.version,this.createdAt=y.createdAt,this.author=y.author,this.deleted=y.deleted,this.inputs=y.inputs,this.declaration=y.declaration,this.andChildrenGroup=y.andChildrenGroup,this.orChildrenGroup=y.orChildrenGroup,this.successCalls=y.successCalls,this.errorCalls=y.errorCalls,this.calledBySuccess=y.calledBySuccess,this.calledByError=y.calledByError,this.calledByEntry=y.calledByEntry,this.parent=y.parent,{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}updateWithShallowTransfer(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"update-with-shallow-transfer"))){if(this.metaSync(i,a),this.version=i.version,this.createdAt=i.createdAt,this.author=i.author,this.deleted=i.deleted,this.previousVersion=i.previousVersion,i.parent){const o=H(i.parent),p=this.project.get(o),e=this.parent;if(e&&e.id!==(p==null?void 0:p.id)&&this.removeFromParent(a),p)this.setParent(p,a),this.addSelfToProject(a);else throw a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${o}' that isn't found in the project`)}else throw a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(i.declaration){const o=H(i.declaration),p=this.project.get(o);p&&this.setDeclaration(p)}return i.andChildrenGroup&&(this.andChildrenGroup=i.andChildrenGroup.map(o=>{const p=H(o),e=this.project.get(p);if(e&&!(e.type===f.Condition&&e.parent===this))return e}).filter(o=>!!o)),i.orChildrenGroup&&(this.orChildrenGroup=i.orChildrenGroup.map(o=>{const p=H(o),e=this.project.get(p);if(e&&!(e.type===f.Condition&&e.parent===this))return e}).filter(o=>!!o)),i.calledByEntry.forEach(o=>{const p=H(o),e=this.project.get(p);e&&(this.addEntryCaller(e,a),e.addCall(this,a))}),[...this.calledByEntry].forEach(o=>{i.calledByEntry.find(e=>H(e)===o.id)||(this.removeCaller(o,a),o.removeCall(this,a))}),i.calledBySuccess.forEach(o=>{const p=H(o),e=this.project.get(p);e&&(this.addSuccessCaller(e,a),e.addSuccessCall(this,a))}),[...this.calledBySuccess].forEach(o=>{i.calledBySuccess.find(e=>H(e)===o.id)||(this.removeCaller(o,a),o.removeCall(this,a))}),i.calledByError.forEach(o=>{const p=H(o),e=this.project.get(p);e&&(this.addErrorCaller(e,a),e.addErrorCall(this,a))}),[...this.calledBySuccess].forEach(o=>{i.calledBySuccess.find(e=>H(e)===o.id)||(this.removeCaller(o,a),o.removeCall(this,a))}),this.captureVersion(),this.subscribeToDependencies(),a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),this}hydrateAncestors(){const i=[],a=[],o=[],p=[];if(this.initialData.parent){const e=H(this.initialData.parent),y=this.project.get(e);if(y)this.setParent(y,null);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${e}' that isn't found in the project`)}else throw new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(this.initialData.declaration){const e=H(this.initialData.declaration),y=this.project.get(e);y&&(this.setDeclaration(y),i.push(y))}return this.initialData.calledByEntry.forEach(e=>{const y=H(e),v=this.project.get(y);v&&this.addEntryCaller(v,null)}),this.initialData.calledBySuccess.forEach(e=>{const y=H(e),v=this.project.get(y);v&&this.addSuccessCaller(v,null)}),this.initialData.calledByError.forEach(e=>{const y=H(e),v=this.project.get(y);v&&this.addErrorCaller(v,null)}),{updated:R(i),added:R(a),removed:R(o),affected:R(p),self:this}}afterAllChildrenInitialized(i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"after-all-children-initialized"))){const a=[],o=[],p=[],e=[];this.initialized=!0;const{updated:y,added:v,removed:E}=this.syncInputs(i);return a.push(...y),o.push(...v),p.push(...E),this.captureVersion(),i==null||i.attemptAutoclose("after-all-children-initialized",this.id),{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}addSelfToProject(i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-self-to-project"))){const a=[this],o=[],p=[],e=[];return this.parent===this.project?this.project.addCondition(this):this.parent.type===f.Condition&&(this.parent.declaration.id===Mr.And?this.parent.addToAndGroup(this):this.parent.declaration.id===Mr.Or&&this.parent.addToOrGroup(this)),this.successCalls.forEach(y=>{y.addSuccessCaller(this,i),a.push(y)}),this.errorCalls.forEach(y=>{y.addErrorCaller(this,i),a.push(y)}),this.calledByEntry.forEach(y=>{y.addCall(this,i),a.push(y)}),this.calledBySuccess.forEach(y=>{y.addSuccessCall(this,i),a.push(y)}),this.calledByError.forEach(y=>{y.addErrorCall(this,i),a.push(y)}),this.subscribe(),this.subscribeToDependencies(),i==null||i.attemptAutoclose("add-self-to-project",this.id),{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}removeInput(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-input"))){const o=this.inputs.findIndex(p=>p.id===i.id);return o>-1&&(this.inputs.splice(o,1),a&&(a==null||a.add(this,S.Affected))),a==null||a.attemptAutoclose("remove-input",this.id),this}addInput(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-input"))){return this.inputs.includes(i)?(a==null||a.attemptAutoclose("add-input",this.id),this):(this.inputs.push(i),a==null||a.add(this,S.Affected),a==null||a.attemptAutoclose("add-input",this.id),this)}addOutput(i){return this}removeOutput(i){return this}addSuccessCaller(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-success-caller")),o=!1){return this.calledBySuccess.find(p=>p.id===i.id)||(this.calledBySuccess.push(i),a==null||a.add(this,S.Updated),o&&We(this,a)),a==null||a.attemptAutoclose("add-success-caller",this.id),this}addErrorCaller(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-error-caller")),o=!1){return this.calledByError.find(p=>p.id===i.id)||(this.calledByError.push(i),a==null||a.add(this,S.Updated),o&&We(this,a)),a==null||a.attemptAutoclose("add-error-caller",this.id),this}addEntryCaller(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-entry-caller")),o=!1){return this.calledByEntry.find(p=>p.id===i.id)||(this.calledByEntry.push(i),a==null||a.add(this,S.Updated),o&&We(this,a)),a==null||a.attemptAutoclose("add-entry-caller",this.id),this}addErrorCall(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-error-call")),o=!1){return this.errorCalls.find(p=>p.id===i.id)||(this.errorCalls.push(i),o&&We(this,a),a==null||a.add(this,S.Affected)),a==null||a.attemptAutoclose("add-error-call",this.id),this}addSuccessCall(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-success-call")),o=!1){return this.successCalls.find(p=>p.id===i.id)||(this.successCalls.push(i),o&&We(this,a),a==null||a.add(this,S.Affected)),a==null||a.attemptAutoclose("add-success-call",this.id),this}removeCall(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-call")),o=!1){const p=this.successCalls.findIndex(y=>y.id===i.id);p>-1&&(this.successCalls.splice(p,1),a==null||a.add(this,S.Affected));const e=this.errorCalls.findIndex(y=>y.id===i.id);return e>-1&&(this.errorCalls.splice(e,1),a==null||a.add(this,S.Affected)),o&&We(this,a),a==null||a.attemptAutoclose("remove-call",this.id),this}removeCaller(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-caller")),o=!1){return this.calledBySuccess=this.calledBySuccess.filter(p=>p.id!==i.id?!0:(a==null||a.add(this,S.Updated),a==null||a.add(p,S.Affected),!1)),this.calledByError=this.calledByError.filter(p=>p.id!==i.id?!0:(a==null||a.add(this,S.Updated),a==null||a.add(p,S.Affected),!1)),this.calledByEntry=this.calledByEntry.filter(p=>p.id!==i.id?!0:(a==null||a.add(this,S.Updated),a==null||a.add(p,S.Affected),!1)),o&&We(this,a),a==null||a.attemptAutoclose("remove-caller",this.id),this}setParent(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"set-parent"))){var o;return((o=this.parent)==null?void 0:o.id)!==(i==null?void 0:i.id)&&(this.parent=i,a&&(a==null||a.add(this,S.Updated))),a==null||a.attemptAutoclose("set-parent",this.id),this}removeChildGroup(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-child-group"))){if(this.andChildrenGroup){const o=this.andChildrenGroup.findIndex(p=>p.id===i.id);o!==-1&&(this.andChildrenGroup.splice(o,1),a==null||a.add(this,S.Updated))}if(this.orChildrenGroup){const o=this.orChildrenGroup.findIndex(p=>p.id===i.id);o!==-1&&(this.orChildrenGroup.splice(o,1),a==null||a.add(this,S.Updated))}return a==null||a.attemptAutoclose("remove-child-group",this.id),this}setDeclaration(i){return this.declaration=i,this}initChildren(i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.declaration=te(this.initialData.declaration,this.project),this.initialData.andChildrenGroup&&(this.andChildrenGroup=this.initialData.andChildrenGroup.map(a=>{const o=te(a,this.project);return o.setParent(this,null),o.initChildren(i),o})),this.initialData.orChildrenGroup&&(this.orChildrenGroup=this.initialData.orChildrenGroup.map(a=>{const o=te(a,this.project);return o.setParent(this,null),o.initChildren(i),o})),this.successCalls=this.initialData.successCalls.map(a=>{const o=te(a,this.project);if(o.addSuccessCaller(this),[f.BreakStatement,f.ContinueStatement].includes(o.type))o.setParent(this.parent.parent,null),o.initChildren(i);else if(o.type===f.ReturnStatement){const p=Yr(this,this.project);o.setParent(p,null),o.initChildren(i)}else o.type!==f.InternalCall&&(o.setParent(this.parent,null),o.initChildren(i));return o}),this.errorCalls=this.initialData.errorCalls.map(a=>{const o=te(a,this.project);if(o.addErrorCaller(this),[f.BreakStatement,f.ContinueStatement].includes(o.type))o.setParent(this.parent.parent,null),o.initChildren(i);else if(o.type===f.ReturnStatement){const p=Yr(this,this.project);o.setParent(p,null),o.initChildren(i)}else o.type!==f.InternalCall&&(o.setParent(this.parent,null),o.initChildren(i));return o}),this.inputs=this.initialData.inputs.map(a=>{const o=te(a,this.project);return o.setParent(this,null),o.initChildren(i),o}),this.subscribeToDependencies(),this.afterAllChildrenInitialized(i),i==null||i.attemptAutoclose("init-children",this.id),this)}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"meta-sync"))){const o=xr(this,i),p=this.toMeta();return this.x=i.x!==void 0?i.x:p.x,this.y=i.y!==void 0?i.y:p.y,this.index=i.index!==void 0?i.index:p.index,super.metaSync(i),i.deleted===!0&&!p.deleted?a==null||a.add(this,S.Removed):i.deleted===!1&&p.deleted?a==null||a.add(this,S.Added):o&&(a==null||a.add(this,S.Updated)),a==null||a.attemptAutoclose("meta-sync",this.id),this}async APILoad(i=ve,...a){return await Xt.repository.APILoad(this.id,...a),this}async APICreate(i=ve,...a){return await Xt.repository.APICreate(this.toShallowJSON(),...a),this}async APIUpdate(i=ve,...a){return await Xt.repository.APIUpdate(this.toShallowJSON(),...a),this}async APIDelete(i=ve,...a){return await Xt.repository.APIDelete(this.toShallowJSON(),...a),this}async APIClone(i=ve,...a){return await Xt.repository.APIClone(this.id,...a),this}async APILoadVersion(i=ve,a,...o){return await Xt.repository.APILoadVersion(this.id,a,...o)}removeFromParent(i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-from-parent"))){var y;const a=[],o=[],p=[],e=[];return this.parent.type===f.Project?(this.parent.removeCondition(this),e.push(this.parent)):((y=this.parent)==null?void 0:y.type)===f.Condition?this.parent.removeChildGroup(this):this.parent.detachedChildren.includes(this)&&this.parent.unsubscribeDetachedChild(this),i==null||i.attemptAutoclose("remove-from-parent",this.id),{added:R(p),updated:R(a),removed:R(o),affected:R(e),self:this}}remove({ignoreUpstream:i}={ignoreUpstream:!1},a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-entity"))){const o=[],p=[],e=[],y=[];if(a!=null&&a.hasRemoved(this.id))return a==null||a.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(p.push(this),this.unsubscribe(),this.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},a),Object.values(this.detachedDependents).forEach(v=>{const{updated:E,removed:b,added:A}=v.entity.onDetachedDependencyRemoved(this,v.field,a);o.push(...E),p.push(...b),e.push(...A)}),this.andChildrenGroup&&this.andChildrenGroup.forEach(v=>{const{removed:E,updated:b}=v.remove({ignoreUpstream:!0},a);p.push(...E),o.push(...b)}),this.orChildrenGroup&&this.orChildrenGroup.forEach(v=>{const{removed:E,updated:b}=v.remove({ignoreUpstream:!0},a);p.push(...E),o.push(...b)}),this.inputs.forEach(v=>{const{updated:E,removed:b}=v.remove({ignoreUpstream:!0},a);o.push(...E),p.push(...b)}),this.successCalls.forEach(v=>{o.push(v),v.removeCaller(this,a)}),this.errorCalls.forEach(v=>{o.push(v),v.removeCaller(this,a)}),!i){const v=this.removeFromParent(a);e.push(...v.added),o.push(...v.updated),p.push(...v.removed),y.push(...v.affected),this.calledBy.forEach(E=>{o.push(E),E.removeCall(this,a)})}return a==null||a.attemptAutoclose("remove-entity",this.id),{added:R(e),updated:R(o),removed:R(p),affected:R(y),self:this}}restore({}={},i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"restore-entity"))){const a=[],o=[],p=[],e=[];return i!=null&&i.hasAdded(this.id)?(i==null||i.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},i),Object.values(this.detachedDependents).forEach(y=>{const{updated:v,removed:E,added:b}=y.entity.onDetachedDependencyRestored(this,y.field,i);o.push(...v),p.push(...E),a.push(...b)}),this.andChildrenGroup&&this.andChildrenGroup.forEach(y=>{const{updated:v,added:E}=y.restore({},i);o.push(...v),a.push(...E)}),this.orChildrenGroup&&this.orChildrenGroup.forEach(y=>{const{updated:v,added:E}=y.restore({},i);o.push(...v),a.push(...E)}),this.inputs.forEach(y=>{const{updated:v}=y.restore({},i);o.push(...v)}),this.successCalls.forEach(y=>{o.push(y),y.addSuccessCaller(this,i)}),this.errorCalls.forEach(y=>{o.push(y),y.addErrorCaller(this,i)}),this.calledBySuccess.forEach(y=>{o.push(y),y.addSuccessCall(this,i)}),this.calledByError.forEach(y=>{o.push(y),y.addErrorCall(this,i)}),this.calledByEntry.forEach(y=>{o.push(y),y.addCall(this,i)}),this.parent.type===f.Project&&this.project.addCondition(this),i==null||i.attemptAutoclose("restore-entity",this.id),{added:R(a),updated:R(o),removed:R(p),affected:R(e),self:this})}toFlat(i=new Set){var o,p;return i.has(this.id)?[]:(i.add(this.id),[this,...((o=this.andChildrenGroup)==null?void 0:o.flatMap(e=>e.toFlat(i)))||[],...((p=this.orChildrenGroup)==null?void 0:p.flatMap(e=>e.toFlat(i)))||[],...this.inputs.flatMap(e=>e.toFlat(i)),...this.successCalls.flatMap(e=>e.toFlat(i)),...this.errorCalls.flatMap(e=>e.toFlat(i)),...this.calledBy.flatMap(e=>e.toFlat(i))])}toFlatIds(i=new Set){var o,p;return i.has(this.id)?[]:(i.add(this.id),[this.id,...((o=this.andChildrenGroup)==null?void 0:o.flatMap(e=>e.toFlatIds(i)))||[],...((p=this.orChildrenGroup)==null?void 0:p.flatMap(e=>e.toFlatIds(i)))||[],...this.inputs.flatMap(e=>e.toFlatIds(i)),...this.successCalls.flatMap(e=>e.toFlatIds(i)),...this.errorCalls.flatMap(e=>e.toFlatIds(i)),...this.calledBy.flatMap(e=>e.toFlatIds(i))])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,index:this.index,x:this.x,y:this.y,type:this.type}}toJSON(i=new Set){var a,o;return i.has(this.id)?this.toReference():(i.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,index:this.index,x:this.x,y:this.y,declaration:this.declaration.toJSON(i),andChildrenGroup:((a=this.andChildrenGroup)==null?void 0:a.map(p=>p.toJSON(i)))||null,orChildrenGroup:((o=this.orChildrenGroup)==null?void 0:o.map(p=>p.toJSON(i)))||null,successCalls:this.successCalls.map(p=>p.toJSON(i)),errorCalls:this.errorCalls.map(p=>p.toJSON(i)),calledBySuccess:this.calledBySuccess.map(p=>p.toReference()),calledByError:this.calledByError.map(p=>p.toReference()),calledByEntry:this.calledByEntry.map(p=>p.toReference()),inputs:this.inputs.map(p=>p.toJSON(i)),parent:this.parent.toReference()})}toJSONClone(i=ke){var o,p,e,y,v,E,b;let a;return(o=i.seenEntityMaps)!=null&&o.has(this.id)?a=i.seenEntityMaps.get(this.id):(a=i.newId||Kr(this,this.project,i.uuidStrategy),i.seenEntityMaps&&i.seenEntityMaps.set(this.id,a)),(p=i.seenEntities)!=null&&p.has(a)||(e=i.seenEntities)!=null&&e.has(this.id)?this.toReference({seenEntityMaps:i.seenEntityMaps}):((y=i.seenEntities)==null||y.add(a),(v=i.seenEntities)==null||v.add(this.id),{id:a,version:N.UUID.uuid(),createdAt:i.timestamp||L().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,index:this.index,x:this.x,y:this.y,declaration:this.declaration.toJSON(),andChildrenGroup:((E=this.andChildrenGroup)==null?void 0:E.map(A=>A.toJSONClone({...i,newId:null})))||null,orChildrenGroup:((b=this.orChildrenGroup)==null?void 0:b.map(A=>A.toJSONClone({...i,newId:null})))||null,successCalls:this.successCalls.map(A=>A.toJSONClone({...i,newId:null})),errorCalls:this.errorCalls.map(A=>A.toJSONClone({...i,newId:null})),calledBySuccess:this.calledBySuccess.map(A=>A.toReference({seenEntityMaps:i.seenEntityMaps})),calledByError:this.calledByError.map(A=>A.toReference({seenEntityMaps:i.seenEntityMaps})),calledByEntry:this.calledByEntry.map(A=>A.toReference({seenEntityMaps:i.seenEntityMaps})),inputs:this.inputs.map(A=>A.toJSONClone({...i,newId:null})),parent:this.parent.toReference({seenEntityMaps:i.seenEntityMaps})})}toReference(i=ke){var o;let a=this.id;return(o=i.seenEntityMaps)!=null&&o.has(this.id)&&(a=i.seenEntityMaps.get(this.id)),{id:a+"--"+N.UUID.uuid()+"--ref",type:f.GenericReference,entityId:a,version:this.version,entityType:this.type}}toShallowJSON(i=ke){var o,p,e;let a=this.id;return(o=i.seenEntityMaps)!=null&&o.has(this.id)&&(a=i.seenEntityMaps.get(this.id)),{id:a,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,index:this.index,x:this.x,y:this.y,declaration:this.declaration.toReference(i),andChildrenGroup:((p=this.andChildrenGroup)==null?void 0:p.map(y=>y.toReference(i)))||null,orChildrenGroup:((e=this.orChildrenGroup)==null?void 0:e.map(y=>y.toReference(i)))||null,inputs:this.inputs.map(y=>y.toReference(i)),successCalls:this.successCalls.map(y=>y.toReference(i)),errorCalls:this.errorCalls.map(y=>y.toReference(i)),calledBySuccess:this.calledBySuccess.map(y=>y.toReference(i)),calledByError:this.calledByError.map(y=>y.toReference(i)),calledByEntry:this.calledByEntry.map(y=>y.toReference(i)),parent:this.parent.toReference(i)}}toFlatJSON(i=new Set){var o,p;return i.has(this.id)?[]:(i.add(this.id),[this.toShallowJSON(),...((o=this.andChildrenGroup)==null?void 0:o.flatMap(e=>e.toFlatJSON(i)))||[],...((p=this.orChildrenGroup)==null?void 0:p.flatMap(e=>e.toFlatJSON(i)))||[],...this.inputs.flatMap(e=>e.toFlatJSON(i)),...this.successCalls.flatMap(e=>e.toFlatJSON(i)),...this.errorCalls.flatMap(e=>e.toFlatJSON(i)),...this.calledBy.flatMap(e=>e.toFlatJSON(i))])}toGenerationTarget(){const i=this.parent.type===f.Project?void 0:this.parent.id;return{id:this.id,type:this.type,declaration:this.declaration.id,calledByEntry:this.calledByEntry.map(a=>a.id),calledBySuccess:this.calledBySuccess.map(a=>a.id),calledByError:this.calledByError.map(a=>a.id),parent:i}}toFlatGenerationTarget(i=new Set){var o,p;return i.has(this.id)?[]:(i.add(this.id),[this.toGenerationTarget(),...((o=this.andChildrenGroup)==null?void 0:o.flatMap(e=>e.toFlatGenerationTarget(i)))||[],...((p=this.orChildrenGroup)==null?void 0:p.flatMap(e=>e.toFlatGenerationTarget(i)))||[],...this.inputs.flatMap(e=>e.toFlatGenerationTarget(i)),...this.successCalls.flatMap(e=>e.toFlatGenerationTarget(i)),...this.errorCalls.flatMap(e=>e.toFlatGenerationTarget(i))])}clearErrors(){var i,a;return this.errors=[],(i=this.andChildrenGroup)==null||i.forEach(o=>o.clearErrors()),(a=this.orChildrenGroup)==null||a.forEach(o=>o.clearErrors()),this.inputs.forEach(o=>o.clearErrors()),this.successCalls.forEach(o=>o.clearErrors()),this.errorCalls.forEach(o=>o.clearErrors()),this}validate(){const i=pj(this);return this.errors=i,{success:!0}}getErrors(){return[...this.errors,...this.inputs.flatMap(a=>a.getErrors())]}getShallowErrors(){return this.errors}clone(i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"clone-entity")),a=null,o=null,p=!0){var F,K,Z;let e=Sr(a,this);const y=this.toJSON(),v=o||N.UUID.uuid();y.inputs=[];const E=v.split("-id"),b=E[E.length-1||0]||v;y.id=v,y.version=N.UUID.uuid(),y.createdAt=(i==null?void 0:i.timestamp)||L().toISOString(),y.author=(i==null?void 0:i.author)||"1",y.previousVersion=null,y.deleted=!1;const A=dr(y,e);a?A.setParent(a,null):A.setParent(this.parent,null),p&&A.subscribe(),A.initChildren(i),i==null||i.add(A,S.Added);const $=(F=this.andChildrenGroup)==null?void 0:F.map(ie=>ie.clone(i,A,N.UUID.uuid(),p)),V=(K=this.orChildrenGroup)==null?void 0:K.map(ie=>ie.clone(i,A,N.UUID.uuid(),p));A.andChildrenGroup=$||null,A.orChildrenGroup=V||null;const B=(Z=this.inputs)==null?void 0:Z.map((ie,X)=>ie.clone(i,A,b+"-input-map-"+X+"-id",p));return A.inputs=B,i==null||i.attemptAutoclose("clone-entity",this.id),A}addToAndGroup(i){return this.andChildrenGroup||(this.andChildrenGroup=[]),this.andChildrenGroup.includes(i)||this.andChildrenGroup.push(i),this}addToOrGroup(i){return this.orChildrenGroup||(this.orChildrenGroup=[]),this.orChildrenGroup.includes(i)||this.orChildrenGroup.push(i),this}removeUnrecognizedInputs(i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-unrecognized-inputs"))){const a=[],o=[],p=[],e=[];return this.inputs.forEach(v=>{if(!this.declaration.inputs.find(b=>{var A;return b.id===((A=v.declaration)==null?void 0:A.id)})){const b=v.remove({ignoreUpstream:!1},i);p.push(...b.removed),a.push(...b.updated)}}),this.inputs.filter((v,E)=>{const b=this.inputs.findIndex($=>$.declaration===v.declaration&&$!==v);if(b===-1)return!1;const A=this.inputs[b];return L(A==null?void 0:A.createdAt).isSame(L(v.createdAt))?E>b:!!L(A==null?void 0:A.createdAt).isAfter(v.createdAt)}).forEach(v=>{const E=v.remove({ignoreUpstream:!1},i);p.push(...E.removed),a.push(...E.updated)}),i==null||i.attemptAutoclose("remove-unrecognized-inputs",this.id),{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}syncInputs(i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"sync-missing-fixed-inputs"))){const a=[],o=[],p=[],e=[],y=this.declaration.inputs.filter(A=>A.parentRelationType===oe.FixedArguments&&!this.inputs.find($=>$.declaration.id===A.id));this.inputs.sort((A,$)=>A.index-$.index),y.forEach(A=>{this.inputs.forEach(B=>{B.index>=A.index&&B.metaSync({index:B.index+1},i)});const $={id:N.UUID.uuid(),version:N.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||L().toISOString(),author:N.sessionAuthor,previousVersion:null,deleted:!1,type:f.InputMap,declaration:A.toJSON(),readsValue:null,defaultValue:null,index:A.index,name:null,codeName:null,description:null,parent:this.toReference()},V=te($,this.project);V.setParent(this,i),V.initChildren(i),i==null||i.add(V,S.Added),V.addSelfToProject(i)}),this.inputs.sort((A,$)=>A.index-$.index);const{updated:v,added:E,removed:b}=this.removeUnrecognizedInputs(i);return a.push(...v),o.push(...E),p.push(...b),i==null||i.attemptAutoclose("sync-missing-fixed-inputs",this.id),{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}getUnusedInputs(){return this.inputs.filter(i=>i.suggestion||!i.readsValue&&!i.defaultValue)}getUnusedOutputs(){return[]}getUsedInputs(){return this.inputs.filter(i=>!i.suggestion&&(i.readsValue||i.defaultValue))}getUsedOutputs(){return[]}};g(Xt,"repository",{APICreate:async(i,...a)=>i,APIUpdate:async(i,...a)=>i,APIDelete:async(i,...a)=>i,APIClone:async(i,...a)=>{},APILoad:async(i,...a)=>null,APILoadVersion:async(i,a,...o)=>null}),g(Xt,"type",f.Condition),g(Xt,"USER_MANAGED_PARENT_TYPES",[...Br,f.Project,f.Condition]),g(Xt,"PARENT_TYPES",[...Xt.USER_MANAGED_PARENT_TYPES]),g(Xt,"MUTABLE_BASE_PROPERTIES",["operator"]),g(Xt,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion","index"]),g(Xt,"BASE_PROPERTIES",[...Xt.MUTABLE_BASE_PROPERTIES,...Xt.INMUTABLE_BASE_PROPERTIES]),g(Xt,"MUTABLE_META_PROPERTIES",["x","y"]),g(Xt,"INMUTABLE_META_PROPERTIES",[...Xt.INMUTABLE_BASE_PROPERTIES]),g(Xt,"META_PROPERTIES",[...Xt.MUTABLE_META_PROPERTIES,...Xt.INMUTABLE_META_PROPERTIES]),g(Xt,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry","parent"]),g(Xt,"INMUTABLE_UPSTREAM_PROPERTIES",[]),g(Xt,"UPSTREAM_PROPERTIES",[...Xt.MUTABLE_UPSTREAM_PROPERTIES,...Xt.INMUTABLE_UPSTREAM_PROPERTIES]),g(Xt,"MUTABLE_DOWNSTREAM_PROPERTIES",["andChildrenGroup","orChildrenGroup","successCalls","errorCalls","inputsDeclarations","inputs"]),g(Xt,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),g(Xt,"DOWNSTREAM_PROPERTIES",[...Xt.MUTABLE_DOWNSTREAM_PROPERTIES,...Xt.INMUTABLE_DOWNSTREAM_PROPERTIES]),g(Xt,"PROPERTIES",[...Xt.META_PROPERTIES,...Xt.UPSTREAM_PROPERTIES,...Xt.DOWNSTREAM_PROPERTIES]);let ho=Xt;function hj(d){var y;const u=u0e(),i=d.toJSON();u.safeParse(i).success,(y=d.dataType)==null||y.validate(),d.inputs.forEach(v=>v.validate()),d.outputs.forEach(v=>v.validate()),d.internalCalls.forEach(v=>v.validate());const p=[...Ka(d),...go(d),...yj(d)],e=xb(d);return p.push(...e),Er(d.errors,p)}function yj(d){const u=[],i=d.name;if(!i){const $=mt({id:`${d.id}--${ae.EmptyName}`,message:`Variable declaration "${ne(d,d.project)}" with id "${d.id}" does not have a name. Entities of type ${d.type} must have valid names.`,severity:q.Error,code:ae.EmptyName,entity:d});return u.push($.error),u}const o=[...d.project.functions,...d.project.entities.flatMap($=>$.methods)].filter($=>$.id!==d.id),p=i.trim(),e=!o.some($=>$.name===i||$.name===p);if(!e){const $=mt({id:`${d.id}--${ae.NameNotUniqueInScope}`,message:`Variable declaration "${ne(d,d.project)}" with id "${d.id}" does not have a unique name. Entities of type ${d.type} must have valid names among all other entities of its type.`,severity:q.Error,code:ae.NameNotUniqueInScope,entity:d});u.push($.error)}const y=jr(i);if(!!o.some($=>jr($.name)===y)&&e){const $=mt({id:`${d.id}--${ae.NameAsResolvedCodeNameNotUniqueInScope}`,message:`Variable declaration "${ne(d,d.project)}" with id "${d.id}" does not have a unique name once it is resolved as it will appear in code: "${y}". Entities of type ${d.type} must have valid names including their code name form.`,severity:q.Error,code:ae.NameAsResolvedCodeNameNotUniqueInScope,entity:d});u.push($.error)}if(!/^[a-zA-Z_]/.test(i)){const $=mt({id:`${d.id}--${ae.NameMustStartWithLetterOrUnderscore}`,message:`Variable declaration "${ne(d,d.project)}" with id "${d.id}" has a name that does not start with a letter or underscore.`,severity:q.Error,code:ae.NameMustStartWithLetterOrUnderscore,entity:d});u.push($.error)}const b=i.substring(1);if(!/^[a-zA-Z0-9_ ]*$/.test(b)){const $=mt({id:`${d.id}--${ae.NameCanOnlyContainLettersNumbersUnderscoreAndSpaces}`,message:`Variable declaration "${ne(d,d.project)}" with id "${d.id}" has a name that contains invalid characters. It can only contain letters, numbers, underscores and spaces.`,severity:q.Error,code:ae.NameCanOnlyContainLettersNumbersUnderscoreAndSpaces,entity:d});u.push($.error)}return u}const Q0e=Object.freeze(Object.defineProperty({__proto__:null,validate:hj,validateVariableDeclarationName:yj},Symbol.toStringTag,{value:"Module"}));function mj(d){const u=Lme(),i=d.toJSON();u.safeParse(i).success,d.inputs.forEach(y=>y.validate()),d.outputs.forEach(y=>y.validate()),d.internalCalls.forEach(y=>y.validate());const p=[...Ka(d),...go(d)],e=xb(d);return p.push(...e),Er(d.errors,p)}const eve=Object.freeze(Object.defineProperty({__proto__:null,validate:mj},Symbol.toStringTag,{value:"Module"}));var IA=(d=>(d.Parent="parent",d.DataTypeEntity="data-type-entity",d.VarDeclaration="var-declaration",d))(IA||{});const Gt=class Gt extends Nr{constructor(i,a){super(i);g(this,"initialData");g(this,"id");g(this,"x");g(this,"y");g(this,"type",f.VariableInstance);g(this,"defaultValue",null);g(this,"writesValues",[]);g(this,"readsValue",null);g(this,"declaration");g(this,"inputs",[]);g(this,"outputs",[]);g(this,"calledBySuccess",[]);g(this,"calledByError",[]);g(this,"calledByEntry",[]);g(this,"successCalls",[]);g(this,"errorCalls",[]);g(this,"internalCalls",[]);g(this,"project");g(this,"errors",[]);g(this,"parent");g(this,"detachedDependents",{});g(this,"knownVersions",null);g(this,"activeVersion",!1);g(this,"initialized",!1);g(this,"startedInitialization",!1);g(this,"suggestion",!1);g(this,"_codeNativeValueValidation",null);this.initialData=i,this.project=a,this.id=i.id,this.x=i.x,this.y=i.y}static new(i=null){return{id:N.UUID.uuid(),version:N.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||L().toISOString(),author:(i==null?void 0:i.author)||N.sessionAuthor,previousVersion:null,deleted:!1,type:f.VariableInstance,declaration:null,internalCalls:[],successCalls:[],errorCalls:[],readsValue:null,writesValues:[],defaultValue:null,inputs:[],outputs:[],parent:null,calledByEntry:[],calledBySuccess:[],calledByError:[],x:0,y:0}}static fromGenerationTarget(i,a){let o=a;if(i.parent){const V=H(i.parent);o=a.get(V)}const p=H(i.declaration),e=a.get(p),y=i.calledByEntry.map(V=>{const B=H(V);return a.get(B)}),v=i.calledBySuccess.map(V=>{const B=H(V);return a.get(B)}),E=i.calledByError.map(V=>{const B=H(V);return a.get(B)});let b=null;if(i.readsValue){const V=H(i.readsValue);b=a.get(V)}const A={id:i.id,version:N.UUID.uuid(),createdAt:L().toISOString(),author:N.sessionAuthor,previousVersion:null,deleted:!1,type:f.VariableInstance,declaration:e.toReference(),calledByEntry:y,calledBySuccess:v,calledByError:E,defaultValue:null,errorCalls:[],successCalls:[],internalCalls:[],readsValue:b,inputs:[],outputs:[],writesValues:[],x:0,y:0,parent:o},$=te(A,a);return $.setParent(o,null),$}static validateGenerationTarget(i,a){let o=JSON.parse(JSON.stringify(i));const p=[],e=li(o,{parent:{list:!1,types:[...Br,f.Project],optional:!0},declaration:{list:!1,types:[f.VariableDeclaration]}},a);return o=e.modifiedData,p.push(...e.errors,...Ur(o)),{errors:p,modifiedData:o}}get codeName(){var i;return(i=this.declaration)==null?void 0:i.codeName}get codeNativeValueValidation(){var i;return this._codeNativeValueValidation||((i=this.declaration)==null?void 0:i.codeNativeValueValidation)||null}validateGeneratedUpdate(i){const a=[];let o=JSON.parse(JSON.stringify(i));const p=sf(o,this);return o=p.modifiedData,a.push(...p.errors),i.parent&&a.push(new ee({id:`${this.id}--${k.InvalidParentUpdate}`,code:k.InvalidParentUpdate,severity:q.Error,message:`Entity of type '${this.type}' with id '${this.id}' cannot have the 'parent' property updated. The 'parent' on a callable entity, is its scope. It scope is auto-calculated implicitly by the its caller.
80
80
  If an entity is called by another, they must be in the same scope, which means they have the same parent.
81
81
  Specifically for variables, their scope is also calculated from their value readers and value writters.
82
82
  You shouldn't have to manually update a 'parent' property. The equivalent result is to change its value readers, value writters, or callers.`})),{errors:a,modifiedData:o}}subscribeDependents(i){return i.forEach(a=>{this.detachedDependents[a.entity.id]||(this.detachedDependents[a.entity.id]=a)}),this}unsubscribeDependents(i){return i.forEach(a=>{this.detachedDependents[a.entity.id]&&delete this.detachedDependents[a.entity.id]}),this}syncDependents(i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"sync-dependents"))){const a=[],o=[],p=[],e=[];return Object.values(this.detachedDependents).forEach(y=>{const v=y.entity.afterAllChildrenInitialized(i);a.push(...v.updated),o.push(...v.added),p.push(...v.removed),e.push(...v.affected)}),i==null||i.attemptAutoclose("sync-dependents",this.id),{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}onDetachedDependencyRemoved(i,a,o){const p=[],e=[],y=[],v=[];if(a==="parent"){const{updated:E,added:b,removed:A}=this.remove({ignoreUpstream:!1},o);p.push(...E),e.push(...b),y.push(...A)}if(a==="var-declaration"){const{updated:E,added:b,removed:A}=this.remove({ignoreUpstream:!1},o);p.push(...E),e.push(...b),y.push(...A)}return{updated:R(p),added:R(e),removed:R(y),affected:R(v),self:this}}onDetachedDependencyRestored(i,a,o){const p=[],e=[],y=[],v=[];if(a==="parent"){const{updated:E,added:b,removed:A}=this.restore({},o);p.push(...E),e.push(...b),y.push(...A)}if(a==="var-declaration"){const{updated:E,added:b,removed:A}=this.restore({},o);p.push(...E),e.push(...b),y.push(...A)}return{updated:R(p),added:R(e),removed:R(y),affected:R(v),self:this}}unsubscribeFromDependencies(){var i,a,o,p,e,y,v;return(a=(i=this.parent)==null?void 0:i.unsubscribeDependents)==null||a.call(i,[{entity:this,field:"parent"}]),(e=(p=(o=this.declaration.dataType)==null?void 0:o.entity)==null?void 0:p.unsubscribeDependents)==null||e.call(p,[{entity:this,field:"data-type-entity"}]),(v=(y=this.declaration)==null?void 0:y.unsubscribeDependents)==null||v.call(y,[{entity:this,field:"var-declaration"}]),this}subscribeToDependencies(){var i,a,o,p;return(i=this.parent)==null||i.subscribeDependents([{entity:this,field:"parent"}]),(p=(o=(a=this.declaration.dataType)==null?void 0:a.entity)==null?void 0:o.subscribeDependents)==null||p.call(o,[{entity:this,field:"data-type-entity"}]),this.declaration.subscribeDependents([{entity:this,field:"var-declaration"}]),this}increaseVersion(i){if(i&&!L(i).isValid())throw new Error(`The shared timestamp '${i}' is not a valid ISO 8601 date string.`);return i&&L(i).isSame(L(this.createdAt))?this:(this.previousVersion=this.version,this.version=N.UUID.uuid(),this.createdAt=L(i).toISOString()||L().toISOString(),this)}captureVersion(){var a;const i=((a=this.knownVersions)==null?void 0:a.get(this.version))||new Gt(this,this.project);return i.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,i):new Map([[this.version,i]]),i.inputs=[...this.inputs],i.outputs=[...this.outputs],i.internalCalls=[...this.internalCalls],i.successCalls=[...this.successCalls],i.errorCalls=[...this.errorCalls],i.writesValues=[...this.writesValues],i.readsValue=this.readsValue,i.defaultValue=this.defaultValue,i.declaration=this.declaration,i.calledBySuccess=[...this.calledBySuccess],i.calledByError=[...this.calledByError],i.calledByEntry=[...this.calledByEntry],i.parent=this.parent,this}recursiveCaptureUpstreamVersions(i){const a=[],o=[],p=[],e=[];if(this.parent){this.parent.increaseVersion(i);const y=this.parent.recursiveCaptureUpstreamVersions(i);a.push(this.parent,...y.updated),o.push(...y.added),p.push(...y.removed)}return{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}async restoreVersion(i){var v;const a=[],o=[],p=[],e=[];if(this.version===i)return{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this};if(!this.knownVersions){const E=new Map;for(const[b,A]of this.knownVersions||new Map){if(E.set(b,A),A.activeVersion=!1,A.knownVersions)for(const[$,V]of A.knownVersions)E.set($,V);A.knownVersions=null}}let y=(v=this.knownVersions)==null?void 0:v.get(i);if(!y){const E=await this.APILoadVersion({},i);if(!E)throw new Error(`Version with id '${i}' for entity with id '${this.id}' not found.`);y=new Gt(E,this.project)}return this.metaSync(y.toShallowJSON(),null),this.previousVersion=y.previousVersion,this.version=y.version,this.createdAt=y.createdAt,this.author=y.author,this.deleted=y.deleted,this.inputs=y.inputs,this.outputs=y.outputs,this.internalCalls=y.internalCalls,this.successCalls=y.successCalls,this.errorCalls=y.errorCalls,this.writesValues=y.writesValues,this.readsValue=y.readsValue,this.defaultValue=y.defaultValue,this.declaration=y.declaration,this.calledBySuccess=y.calledBySuccess,this.calledByError=y.calledByError,this.calledByEntry=y.calledByEntry,this.parent=y.parent,{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}updateWithShallowTransfer(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"update-with-shallow-transfer"))){if(this.metaSync(i,a),this.version=i.version,this.createdAt=i.createdAt,this.author=i.author,this.deleted=i.deleted,this.previousVersion=i.previousVersion,this.unsubscribeFromDependencies(),i.parent){const o=H(i.parent),p=this.project.get(o),e=this.parent;if(e&&e.id!==(p==null?void 0:p.id)&&this.removeFromParent(a),p)this.setParent(p,a);else throw a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${o}' that isn't found in the project`)}else throw a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(i.readsValue){const o=H(i.readsValue),p=this.project.get(o),e=this.readsValue;e&&e.id!==(p==null?void 0:p.id)&&this.removeValueWriter(a),p&&this.setValueWriter(p,a)}if(i.declaration){const o=H(i.declaration),p=this.project.get(o);p&&this.setDeclaration(p)}return i.calledByEntry.forEach(o=>{const p=H(o),e=this.project.get(p);e&&(this.addEntryCaller(e,a),e.addCall(this,a))}),[...this.calledByEntry].forEach(o=>{i.calledByEntry.find(e=>H(e)===o.id)||(this.removeCaller(o,a),o.removeCall(this,a))}),i.calledBySuccess.forEach(o=>{const p=H(o),e=this.project.get(p);e&&(this.addSuccessCaller(e,a),e.addSuccessCall(this,a))}),[...this.calledBySuccess].forEach(o=>{i.calledBySuccess.find(e=>H(e)===o.id)||(this.removeCaller(o,a),o.removeCall(this,a))}),i.calledByError.forEach(o=>{const p=H(o),e=this.project.get(p);e&&(this.addErrorCaller(e,a),e.addErrorCall(this,a))}),[...this.calledBySuccess].forEach(o=>{i.calledBySuccess.find(e=>H(e)===o.id)||(this.removeCaller(o,a),o.removeCall(this,a))}),this.captureVersion(),this.subscribeToDependencies(),a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),this}hydrateAncestors(){const i=[],a=[],o=[],p=[];if(this.initialData.parent){const e=H(this.initialData.parent),y=this.project.get(e);if(y)this.setParent(y,null),i.push(y);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${e}' that isn't found in the project`)}else throw new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(this.initialData.readsValue){const e=H(this.initialData.readsValue),y=this.project.get(e);y&&(this.setValueWriter(y,null),i.push(y))}if(this.initialData.declaration){const e=H(this.initialData.declaration),y=this.project.get(e);y&&(this.setDeclaration(y),i.push(y))}return this.initialData.calledByEntry.forEach(e=>{const y=H(e),v=this.project.get(y);v&&this.addEntryCaller(v,null)}),this.initialData.calledBySuccess.forEach(e=>{const y=H(e),v=this.project.get(y);v&&this.addSuccessCaller(v,null)}),this.initialData.calledByError.forEach(e=>{const y=H(e),v=this.project.get(y);v&&this.addErrorCaller(v,null)}),{updated:R(i),added:R(a),removed:R(o),affected:R(p),self:this}}afterAllChildrenInitialized(i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"after-all-children-initialized"))){var $e;const a=[],o=[],p=[],e=[];if(this.initialized=!0,!this.declaration.dataType||($e=this.declaration.dataType)!=null&&$e.inferred){const{added:Pe,updated:Ze,removed:Ge,affected:ut}=this.declaration.inferDataTypeAndSyncInstancesInputsAndOutputs(i);o.push(...Pe),a.push(...Ze),p.push(...Ge),e.push(...ut)}const{added:y,updated:v,removed:E,affected:b}=this.syncInputs(i);o.push(...y),a.push(...v),p.push(...E),e.push(...b);const{added:A,updated:$,removed:V,affected:B}=this.syncOutputs(i);o.push(...A),a.push(...$),p.push(...V),e.push(...B);const{added:F,updated:K,removed:Z,affected:ie}=this.generateUnusedInternalCalls(i);o.push(...F),a.push(...K),p.push(...Z),e.push(...ie);const{added:X,updated:ue,removed:re,affected:fe}=this.removeUnrecognizedInputs(i);o.push(...X),a.push(...ue),p.push(...re),e.push(...fe);const{added:Y,updated:J,removed:ce,affected:z}=this.removeUnrecognizedOutputs(i);o.push(...Y),a.push(...J),p.push(...ce),e.push(...z);const{added:de,updated:Ae,removed:je,affected:Ne}=this.removeUnrecognizedInternalCalls(i);return o.push(...de),a.push(...Ae),p.push(...je),e.push(...Ne),this.captureVersion(),i==null||i.attemptAutoclose("after-all-children-initialized",this.id),{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}addSelfToProject(i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-self-to-project"))){const a=[this],o=[],p=[],e=[];return this.parent===this.project&&this.project.addVariableInstance(this),this.readsValue&&(this.readsValue.addValueReader(this,i),a.push(this.readsValue)),this.writesValues.forEach(y=>{y.setValueWriter(this,i),a.push(y)}),this.successCalls.forEach(y=>{y.addSuccessCaller(this,i),a.push(y)}),this.errorCalls.forEach(y=>{y.addErrorCaller(this,i),a.push(y)}),this.calledBySuccess.forEach(y=>{y.addSuccessCall(this,i),a.push(y)}),this.calledByError.forEach(y=>{y.addErrorCall(this,i),a.push(y)}),this.calledByEntry.forEach(y=>{y.addCall(this,i),a.push(y)}),this.subscribe(),this.subscribeToDependencies(),i==null||i.attemptAutoclose("add-self-to-project",this.id),{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}get usedInputs(){return this.inputs.filter(i=>i.readsValue||i.defaultValue)}get unusedInputs(){return this.inputs.filter(i=>!i.readsValue&&!i.defaultValue)}get usedOutputs(){return this.outputs.filter(i=>i.writesValues.length)}get unusedOutputs(){return this.outputs.filter(i=>!i.writesValues.length)}get usedInternalCalls(){return this.internalCalls.filter(i=>!!i.calledBy.length)}get unusedInternalCalls(){const i=this.usedInternalCalls;return this.internalCalls.filter(o=>!(i.find(y=>y.id===o.id)||i.find(y=>y.declaration===o.declaration)))}removeInternalCall(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-variable-instance-internal-call"))){const o=this.internalCalls.findIndex(p=>p.id===i.id);return o>-1&&(this.internalCalls.splice(o,1),a&&(a==null||a.add(this,S.Affected))),a==null||a.attemptAutoclose("remove-variable-instance-internal-call",this.id),this}removeInput(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-input"))){const o=this.inputs.findIndex(p=>p.id===i.id);return o>-1&&(this.inputs.splice(o,1),a&&(a==null||a.add(this,S.Affected))),a==null||a.attemptAutoclose("remove-input",this.id),this}addInput(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-input"))){return this.inputs.includes(i)?(a==null||a.attemptAutoclose("add-input",this.id),this):(this.inputs.push(i),a==null||a.add(this,S.Affected),a==null||a.attemptAutoclose("add-input",this.id),this)}addOutput(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-output"))){return this.outputs.includes(i)?(a==null||a.attemptAutoclose("add-output",this.id),this):(this.outputs.push(i),a==null||a.add(this,S.Affected),a==null||a.attemptAutoclose("add-output",this.id),this)}removeOutput(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-output"))){const o=this.outputs.findIndex(p=>p.id===i.id);return o>-1&&(this.outputs.splice(o,1),a&&(a==null||a.add(this,S.Affected))),a==null||a.attemptAutoclose("remove-output",this.id),this}addSuccessCaller(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-success-caller")),o=!1){return this.calledBySuccess.find(p=>p.id===i.id)||(this.calledBySuccess.push(i),a==null||a.add(this,S.Updated),o&&We(this,a)),a==null||a.attemptAutoclose("add-success-caller",this.id),this}addErrorCaller(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-error-caller")),o=!1){return this.calledByError.find(p=>p.id===i.id)||(this.calledByError.push(i),a==null||a.add(this,S.Updated),o&&We(this,a)),a==null||a.attemptAutoclose("add-error-caller",this.id),this}addEntryCaller(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-entry-caller")),o=!1){return this.calledByEntry.find(p=>p.id===i.id)||(this.calledByEntry.push(i),a==null||a.add(this,S.Updated),o&&We(this,a)),a==null||a.attemptAutoclose("add-entry-caller",this.id),this}addErrorCall(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-error-call")),o=!1){return this.errorCalls.find(p=>p.id===i.id)||(this.errorCalls.push(i),o&&We(this,a),a==null||a.add(this,S.Affected)),a==null||a.attemptAutoclose("add-error-call",this.id),this}addSuccessCall(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-success-call")),o=!1){return this.successCalls.find(p=>p.id===i.id)||(this.successCalls.push(i),o&&We(this,a),a==null||a.add(this,S.Affected)),a==null||a.attemptAutoclose("add-success-call",this.id),this}removeCall(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-call")),o=!1){const p=this.successCalls.findIndex(y=>y.id===i.id);p>-1&&(this.successCalls.splice(p,1),a==null||a.add(this,S.Affected));const e=this.errorCalls.findIndex(y=>y.id===i.id);return e>-1&&(this.errorCalls.splice(e,1),a==null||a.add(this,S.Affected)),o&&We(this,a),a==null||a.attemptAutoclose("remove-call",this.id),this}removeCaller(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-caller")),o=!1){return this.calledBySuccess=this.calledBySuccess.filter(p=>p.id!==i.id?!0:(a==null||a.add(this,S.Updated),a==null||a.add(p,S.Affected),!1)),this.calledByError=this.calledByError.filter(p=>p.id!==i.id?!0:(a==null||a.add(this,S.Updated),a==null||a.add(p,S.Affected),!1)),this.calledByEntry=this.calledByEntry.filter(p=>p.id!==i.id?!0:(a==null||a.add(this,S.Updated),a==null||a.add(p,S.Affected),!1)),o&&We(this,a),a==null||a.attemptAutoclose("remove-caller",this.id),this}addValueReader(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-value-reader"))){return this.writesValues.includes(i)?(a==null||a.attemptAutoclose("add-value-reader",this.id),this):(this.writesValues.push(i),a==null||a.add(this,S.Affected),this)}setParent(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"set-parent"))){var o;return((o=this.parent)==null?void 0:o.id)!==(i==null?void 0:i.id)&&(this.parent=i,a&&(a==null||a.add(this,S.Updated))),a==null||a.attemptAutoclose("set-parent",this.id),this}initChildren(i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"init-children"))){if(this.initialized||this.startedInitialization)return this;if(this.startedInitialization=!0,this.initialData.defaultValue&&(this.defaultValue=te(this.initialData.defaultValue,this.project),this.defaultValue.setParent(this,null),this.defaultValue.initChildren(i)),this.initialData.declaration.type===f.GenericReference){const a=this.project.findSubscribedInstanceFromReference(this.initialData.declaration);if(!a)return this;this.declaration=a}else this.declaration=te(this.initialData.declaration,this.project),this.declaration.initChildren(i);return mf.initWritesValues(this,this.parent),yf.initReadsValue(this),this.initialData.inputs.forEach(a=>{const o=te(a,this.project);return o.setParent(this,null),o.initChildren(i),this.addInput(o,null),o}),this.initialData.outputs.forEach(a=>{const o=te(a,this.project);return o.setParent(this,null),o.initChildren(i),this.addOutput(o,i),o}),this.successCalls=this.initialData.successCalls.map(a=>{const o=te(a,this.project);if(o.addSuccessCaller(this),[f.BreakStatement,f.ContinueStatement].includes(o.type))o.setParent(this.parent.parent,null),o.initChildren(i);else if(o.type===f.ReturnStatement){const p=Yr(this,this.project);o.setParent(p,null),o.initChildren(i)}else o.type!==f.InternalCall&&(o.setParent(this.parent,null),o.initChildren(i));return o}),this.errorCalls=this.initialData.errorCalls.map(a=>{const o=te(a,this.project);if(o.addErrorCaller(this),[f.BreakStatement,f.ContinueStatement].includes(o.type))o.setParent(this.parent.parent,null),o.initChildren(i);else if(o.type===f.ReturnStatement){const p=Yr(this,this.project);o.setParent(p,null),o.initChildren(i)}else o.type!==f.InternalCall&&(o.setParent(this.parent,null),o.initChildren(i));return o}),this.internalCalls=this.initialData.internalCalls.reduce((a,o)=>{if(o.type===f.GenericReference){const p=this.project.findSubscribedInstanceFromReference(o);if(!p)return a;const e=p;return e.setParent(this,null),[...a,e]}else{const p=te(o,this.project);return p.setParent(this,null),p.initChildren(i),[...a,p]}},[]),this.subscribeToDependencies(),this.afterAllChildrenInitialized(i),i==null||i.attemptAutoclose("init-children",this.id),this}setValueWriter(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"set-value-writer"))){return this.readsValue!==i&&(this.readsValue=i,a==null||a.add(this,S.Updated)),a==null||a.attemptAutoclose("set-value-writer",this.id),this}removeValueWriter(i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-value-writer"))){return this.readsValue&&(this.readsValue=null,i==null||i.add(this,S.Updated)),i==null||i.attemptAutoclose("remove-value-writer",this.id),this}removeValueReader(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-value-reader"))){return this.writesValues.includes(i)?(this.writesValues=this.writesValues.filter(o=>o.id!==i.id),a==null||a.add(this,S.Affected),this):(a==null||a.attemptAutoclose("remove-value-reader",this.id),this)}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"meta-sync"))){const o=xr(this,i),p=this.toMeta();return this.x=i.x||p.x,this.y=i.y||p.y,super.metaSync(i),i.deleted===!0&&!p.deleted?a==null||a.add(this,S.Removed):i.deleted===!1&&p.deleted?a==null||a.add(this,S.Added):o&&(a==null||a.add(this,S.Updated)),a==null||a.attemptAutoclose("meta-sync",this.id),this}async APILoad(i=ve,...a){return await Gt.repository.APILoad(this.id,...a),this}async APICreate(i=ve,...a){return await Gt.repository.APICreate(this.toShallowJSON(),...a),this}async APIUpdate(i=ve,...a){return await Gt.repository.APIUpdate(this.toShallowJSON(),...a),this}async APIDelete(i=ve,...a){return await Gt.repository.APIDelete(this.toShallowJSON(),...a),this}async APIClone(i=ve,...a){return await Gt.repository.APIClone(this.id,...a),this}async APILoadVersion(i=ve,a,...o){return await Gt.repository.APILoadVersion(this.id,a,...o)}removeFromParent(i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-from-parent"))){const a=[],o=[],p=[],e=[];return this.parent.type===f.Project?(this.parent.removeVariableInstance(this),e.push(this.parent)):this.parent.detachedChildren.includes(this)&&this.parent.unsubscribeDetachedChild(this),i==null||i.attemptAutoclose("remove-from-parent",this.id),{added:R(p),updated:R(a),removed:R(o),affected:R(e),self:this}}remove({ignoreUpstream:i}={ignoreUpstream:!1},a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-entity"))){const o=[],p=[],e=[],y=[];if(a!=null&&a.hasRemoved(this.id))return a==null||a.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(p.push(this),this.unsubscribe(),this.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},a),Object.values(this.detachedDependents).forEach(v=>{const{updated:E,removed:b,added:A}=v.entity.onDetachedDependencyRemoved(this,v.field,a);o.push(...E),p.push(...b),e.push(...A)}),this.defaultValue){const{updated:v,removed:E}=this.defaultValue.remove({ignoreUpstream:!0},a);o.push(...v),p.push(...E)}if(this.readsValue&&(o.push(this.readsValue),this.readsValue.removeValueReader(this,a)),this.writesValues.forEach(v=>{o.push(v),v.setValueWriter(null,a)}),this.inputs.forEach(v=>{const{updated:E,removed:b}=v.remove({ignoreUpstream:!0},a);o.push(...E),p.push(...b)}),this.outputs.forEach(v=>{const{updated:E,removed:b}=v.remove({ignoreUpstream:!0},a);o.push(...E),p.push(...b)}),this.successCalls.forEach(v=>{o.push(v),v.removeCaller(this,a)}),this.errorCalls.forEach(v=>{o.push(v),v.removeCaller(this,a)}),this.internalCalls.forEach(v=>{const{updated:E,removed:b}=v.remove({ignoreUpstream:!0},a);o.push(...E),p.push(...b)}),!i){const v=this.removeFromParent(a);e.push(...v.added),o.push(...v.updated),p.push(...v.removed),y.push(...v.affected),this.calledBy.forEach(E=>{o.push(E),E.removeCall(this,a)})}return a==null||a.attemptAutoclose("remove-entity",this.id),{added:R(e),updated:R(o),removed:R(p),affected:R(y),self:this}}restore({}={},i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"restore-entity"))){const a=[],o=[],p=[],e=[];if(i!=null&&i.hasAdded(this.id))return i==null||i.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},i),Object.values(this.detachedDependents).forEach(y=>{const{updated:v,removed:E,added:b}=y.entity.onDetachedDependencyRestored(this,y.field,i);o.push(...v),p.push(...E),a.push(...b)}),this.defaultValue){const{updated:y}=this.defaultValue.restore({},i);o.push(...y)}return this.readsValue&&(o.push(this.readsValue),this.readsValue.addValueReader(this,i)),this.writesValues.forEach(y=>{o.push(y),y.setValueWriter(this,i)}),this.inputs.forEach(y=>{const{updated:v}=y.restore({},i);o.push(...v)}),this.outputs.forEach(y=>{const{updated:v}=y.restore({},i);o.push(...v)}),this.successCalls.forEach(y=>{o.push(y),y.addSuccessCaller(this,i)}),this.errorCalls.forEach(y=>{o.push(y),y.addErrorCaller(this,i)}),this.internalCalls.forEach(y=>{const{updated:v}=y.restore({},i);o.push(...v)}),this.calledBySuccess.forEach(y=>{o.push(y),y.addSuccessCall(this,i)}),this.calledByError.forEach(y=>{o.push(y),y.addErrorCall(this,i)}),this.calledByEntry.forEach(y=>{o.push(y),y.addCall(this,i)}),i==null||i.attemptAutoclose("restore-entity",this.id),{added:R(a),updated:R(o),removed:R(p),affected:R(e),self:this}}toFlat(i=new Set){var o,p;return i.has(this.id)?[]:(i.add(this.id),[this,...((o=this.defaultValue)==null?void 0:o.toFlat(i))||[],...this.writesValues.flatMap(e=>e.toFlat(i)),...((p=this.readsValue)==null?void 0:p.toFlat(i))||[],...this.successCalls.flatMap(e=>e.toFlat(i)),...this.errorCalls.flatMap(e=>e.toFlat(i)),...this.inputs.flatMap(e=>e.toFlat(i)),...this.outputs.flatMap(e=>e.toFlat(i)),...this.internalCalls.flatMap(e=>e.toFlat(i))])}toFlatIds(i=new Set){var o;return i.has(this.id)?[]:(i.add(this.id),[this.id,...((o=this.defaultValue)==null?void 0:o.toFlatIds(i))||[],...this.writesValues.flatMap(p=>p.toFlatIds(i)),...this.successCalls.flatMap(p=>p.toFlatIds(i)),...this.errorCalls.flatMap(p=>p.toFlatIds(i)),...this.inputs.flatMap(p=>p.toFlatIds(i)),...this.outputs.flatMap(p=>p.toFlatIds(i)),...this.internalCalls.flatMap(p=>p.toFlatIds(i))])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,x:this.x,y:this.y,type:this.type}}toJSON(i=new Set){var a,o;return i.has(this.id)?this.toReference():(i.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,declaration:this.declaration.toJSON(i),defaultValue:((a=this.defaultValue)==null?void 0:a.toJSON(i))||null,readsValue:((o=this.readsValue)==null?void 0:o.toReference())||null,writesValues:this.writesValues.map(p=>p.toJSON(i)),inputs:this.inputs.map(p=>p.toJSON(i)),outputs:this.outputs.map(p=>p.toJSON(i)),successCalls:this.successCalls.map(p=>p.toJSON(i)),errorCalls:this.errorCalls.map(p=>p.toJSON(i)),internalCalls:this.internalCalls.map(p=>p.toJSON(i)),calledBySuccess:this.calledBySuccess.map(p=>p.toReference()),calledByError:this.calledByError.map(p=>p.toReference()),calledByEntry:this.calledByEntry.map(p=>p.toReference()),parent:this.parent.toReference(),x:this.x,y:this.y})}toJSONClone(i=ke){var o,p,e,y,v,E,b;let a;return(o=i.seenEntityMaps)!=null&&o.has(this.id)?a=i.seenEntityMaps.get(this.id):(a=i.newId||Kr(this,this.project,i.uuidStrategy),i.seenEntityMaps&&i.seenEntityMaps.set(this.id,a)),(p=i.seenEntities)!=null&&p.has(a)||(e=i.seenEntities)!=null&&e.has(this.id)?this.toReference({seenEntityMaps:i.seenEntityMaps}):((y=i.seenEntities)==null||y.add(a),(v=i.seenEntities)==null||v.add(this.id),{id:a,version:N.UUID.uuid(),createdAt:i.timestamp||L().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,defaultValue:((E=this.defaultValue)==null?void 0:E.toJSONClone({...i,newId:null}))||null,declaration:this.declaration.toReference({seenEntityMaps:i.seenEntityMaps}),readsValue:((b=this.readsValue)==null?void 0:b.toReference({seenEntityMaps:i.seenEntityMaps}))||null,writesValues:this.writesValues.map(A=>A.toJSONClone({...i,newId:null})),inputs:this.inputs.map(A=>A.toJSONClone({...i,newId:null})),outputs:this.outputs.map(A=>A.toJSONClone({...i,newId:null})),successCalls:this.successCalls.map(A=>A.toJSONClone({...i,newId:null})),errorCalls:this.errorCalls.map(A=>A.toJSONClone({...i,newId:null})),internalCalls:this.internalCalls.map(A=>this.calledBy.length||this.readsValue?A.toJSONClone({...i,newId:null}):A.toReference({seenEntityMaps:i.seenEntityMaps})),calledBySuccess:this.calledBySuccess.map(A=>A.toReference({seenEntityMaps:i.seenEntityMaps})),calledByError:this.calledByError.map(A=>A.toReference({seenEntityMaps:i.seenEntityMaps})),calledByEntry:this.calledByEntry.map(A=>A.toReference({seenEntityMaps:i.seenEntityMaps})),parent:this.parent.toReference({seenEntityMaps:i.seenEntityMaps}),x:this.x,y:this.y})}toReference(i=ke){var o;let a=this.id;return(o=i.seenEntityMaps)!=null&&o.has(this.id)&&(a=i.seenEntityMaps.get(this.id)),{id:a+"--"+N.UUID.uuid()+"--ref",type:f.GenericReference,entityId:a,version:this.version,entityType:this.type}}toShallowJSON(i=ke){var o,p,e,y;let a=this.id;return(o=i.seenEntityMaps)!=null&&o.has(this.id)&&(a=i.seenEntityMaps.get(this.id)),{id:a,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,defaultValue:((p=this.defaultValue)==null?void 0:p.toReference(i))||null,declaration:((e=this.declaration)==null?void 0:e.toReference(i))||null,readsValue:((y=this.readsValue)==null?void 0:y.toReference(i))||null,writesValues:this.writesValues.map(v=>v.toReference(i)),inputs:this.inputs.map(v=>v.toReference(i)),outputs:this.outputs.map(v=>v.toReference(i)),successCalls:this.successCalls.map(v=>v.toReference(i)),errorCalls:this.errorCalls.map(v=>v.toReference(i)),calledBySuccess:this.calledBySuccess.map(v=>v.toReference(i)),calledByError:this.calledByError.map(v=>v.toReference(i)),calledByEntry:this.calledByEntry.map(v=>v.toReference(i)),internalCalls:this.internalCalls.map(v=>v.toReference(i)),parent:this.parent.toReference(i)}}toFlatJSON(i=new Set){var o,p;return i.has(this.id)?[]:(i.add(this.id),[this.toShallowJSON(),...((o=this.defaultValue)==null?void 0:o.toFlatJSON(i))||[],...((p=this.declaration)==null?void 0:p.toFlatJSON(i))||[],...this.writesValues.flatMap(e=>e.toFlatJSON(i)),...this.successCalls.flatMap(e=>e.toFlatJSON(i)),...this.errorCalls.flatMap(e=>e.toFlatJSON(i)),...this.inputs.flatMap(e=>e.toFlatJSON(i)),...this.outputs.flatMap(e=>e.toFlatJSON(i)),...this.internalCalls.flatMap(e=>e.toFlatJSON(i)),...this.calledBy.flatMap(e=>e.toFlatJSON(i))])}toGenerationTarget(){const i=this.parent.type===f.Project?void 0:this.parent.id;return{id:this.id,type:this.type,declaration:this.declaration.id,calledByEntry:this.calledByEntry.map(a=>a.id),calledBySuccess:this.calledBySuccess.map(a=>a.id),calledByError:this.calledByError.map(a=>a.id),parent:i}}toFlatGenerationTarget(i=new Set){var o,p,e;return i.has(this.id)?[]:(i.add(this.id),[this.toGenerationTarget(),...((o=this.defaultValue)==null?void 0:o.toFlatGenerationTarget(i))||[],...((p=this.declaration)==null?void 0:p.toFlatGenerationTarget(i))||[],...((e=this.readsValue)==null?void 0:e.toFlatGenerationTarget(i))||[],...this.writesValues.flatMap(y=>y.toFlatGenerationTarget(i)),...this.successCalls.flatMap(y=>y.toFlatGenerationTarget(i)),...this.errorCalls.flatMap(y=>y.toFlatGenerationTarget(i)),...this.inputs.flatMap(y=>y.toFlatGenerationTarget(i)),...this.outputs.flatMap(y=>y.toFlatGenerationTarget(i)),...this.internalCalls.flatMap(y=>y.toFlatGenerationTarget(i))])}clearErrors(){var i;return this.errors=[],(i=this.defaultValue)==null||i.clearErrors(),this.inputs.forEach(a=>a.clearErrors()),this.outputs.forEach(a=>a.clearErrors()),this.successCalls.forEach(a=>a.clearErrors()),this.errorCalls.forEach(a=>a.clearErrors()),this.internalCalls.forEach(a=>a.clearErrors()),this}validate(){const i=mj(this);return this.errors=i,{success:!0}}getErrors(){var a,o;return[...this.errors,...((a=this.defaultValue)==null?void 0:a.getErrors())||[],...this.inputs.flatMap(p=>p.getErrors()),...this.internalCalls.flatMap(p=>p.getErrors()),...this.outputs.flatMap(p=>p.getErrors()),...((o=this.readsValue)==null?void 0:o.getErrors())||[]]}getShallowErrors(){return this.errors}getDefaultValue(){var i;return this.defaultValue||((i=this.declaration)==null?void 0:i.defaultValue)||null}setDefaultValue(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"set-default-value"))){const o=this.defaultValue;return(o==null?void 0:o.id)!==(i==null?void 0:i.id)&&(o==null||o.remove({ignoreUpstream:!0},a),this.defaultValue=i,a==null||a.add(this,S.Affected)),a==null||a.attemptAutoclose("set-default-value",this.id),this}clone(i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"clone-entity")),a=null,o=null,p=!0){var B,F,K,Z;let e=Sr(a,this);const y=this.toJSON(),v=o||N.UUID.uuid();y.inputs=[],y.id=v,y.version=N.UUID.uuid(),y.createdAt=(i==null?void 0:i.timestamp)||L().toISOString(),y.author=(i==null?void 0:i.author)||"1",y.previousVersion=null,y.deleted=!1;const E=dr(y,e);a?E.setParent(a,null):E.setParent(this.parent,null),p&&E.subscribe(),E.initChildren(i),i==null||i.add(E,S.Added);const b=(B=this.defaultValue)==null?void 0:B.clone(i,E,N.UUID.uuid(),p);E.defaultValue=b||null;const A=(F=this.inputs)==null?void 0:F.map(ie=>ie.clone(i,E,N.UUID.uuid(),p));E.inputs=A;const $=(K=this.outputs)==null?void 0:K.map(ie=>ie.clone(i,E,N.UUID.uuid(),p));E.outputs=$;const V=(Z=this.internalCalls)==null?void 0:Z.map(ie=>ie.clone(i,E,N.UUID.uuid(),p));return E.internalCalls=V,i==null||i.attemptAutoclose("clone-entity",this.id),E}addInternalCall(i){return this.internalCalls.find(a=>a===i)||this.internalCalls.push(i),this}setDeclaration(i){return this.declaration!==i&&(this.declaration=i),this}removeUnrecognizedInputs(i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-unrecognized-variable-instance-inputs"))){const a=[],o=[],p=[],e=[];return this.declaration.dataType&&!this.declaration.dataType.isObject()?[...this.inputs].forEach(y=>{const v=y.remove({ignoreUpstream:!1},i);p.push(...v.removed),a.push(...v.updated)}):this.declaration.dataType&&this.declaration.dataType.hasStrictObjectStructure()&&[...this.inputs].forEach(y=>{var E;if(!y.declaration){const b=y.remove({ignoreUpstream:!1},i);p.push(...b.removed),a.push(...b.updated);return}if(![...((E=this.declaration.dataType)==null?void 0:E.entity).allProperties].find(b=>y.declaration===b)){const b=y.remove({ignoreUpstream:!1},i);p.push(...b.removed),a.push(...b.updated)}}),i==null||i.attemptAutoclose("remove-unrecognized-variable-instance-inputs",this.id),{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}removeUnrecognizedOutputs(i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-unrecognized-variable-instance-outputs"))){const a=[],o=[],p=[],e=[];return this.declaration.dataType&&!this.declaration.dataType.isObject()?[...this.outputs].forEach(y=>{const v=y.remove({ignoreUpstream:!1},i);p.push(...v.removed),a.push(...v.updated)}):this.declaration.dataType&&this.declaration.dataType.hasStrictObjectStructure()&&[...this.outputs].forEach(y=>{var E;if(!y.declaration){const b=y.remove({ignoreUpstream:!1},i);p.push(...b.removed),a.push(...b.updated);return}if(![...((E=this.declaration.dataType)==null?void 0:E.entity).allProperties].find(b=>y.declaration===b)){const b=y.remove({ignoreUpstream:!1},i);p.push(...b.removed),a.push(...b.updated)}}),i==null||i.attemptAutoclose("remove-unrecognized-variable-instance-outputs",this.id),{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}removeUnrecognizedInternalCalls(i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-unrecognized-variable-declaration-internal-calls"))){var v;const a=[],o=[],p=[],e=[];if(!this.declaration.dataType||!this.declaration.dataType.entity||![f.DefinitionEntity,f.PrimitiveEntity,f.BuiltInBaseEntity].includes(this.declaration.dataType.entity.type))[...this.internalCalls].forEach(E=>{const b=E.remove({ignoreUpstream:!1},i);p.push(...b.removed),a.push(...b.updated)});else if(this.declaration.dataType&&this.declaration.dataType.entity&&[f.DefinitionEntity,f.PrimitiveEntity,f.BuiltInBaseEntity].includes(this.declaration.dataType.entity.type)){const E=[...((v=this.declaration.dataType)==null?void 0:v.entity).allMethods];[...this.internalCalls].forEach(b=>{if(!b.declaration){const $=b.remove({ignoreUpstream:!1},i);p.push(...$.removed),a.push(...$.updated);return}if(!E.find($=>b.declaration===$)){const $=b.remove({ignoreUpstream:!1},i);p.push(...$.removed),a.push(...$.updated);return}})}return this.internalCalls.filter((E,b)=>{const A=this.internalCalls.findIndex(V=>V.declaration===E.declaration&&V!==E);if(A===-1)return!1;const $=this.internalCalls[A];return L($==null?void 0:$.createdAt).isSame(L(E.createdAt))?b>A:!!L($==null?void 0:$.createdAt).isAfter(E.createdAt)}).forEach(E=>{const b=E.remove({ignoreUpstream:!1},i);p.push(...b.removed),a.push(...b.updated)}),i==null||i.attemptAutoclose("remove-unrecognized-variable-declaration-internal-calls",this.id),{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}syncInputs(i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"sync-variable-instance-inputs"))){const a=[],o=[],p=[],e=[];if(this.declaration.dataType)if(this.declaration.dataType.entity){if([f.DefinitionEntity,f.PrimitiveEntity,f.BuiltInBaseEntity].includes(this.declaration.dataType.entity.type)&&!this.declaration.dataType.isList){const y=[...this.declaration.dataType.entity.properties];y.filter(A=>!A.getDataType(i)).forEach(A=>{const $=this.inputs.find(F=>ne(F,this.project)===ne(A,this.project));if(!$)return;const V=this.declaration.getMasterInputWithValueWritterFromAllInstances($);if(!V)return;const B=bn(V);A.setDataType(B,i),$.setDeclaration(A,i)}),y.filter(A=>!this.inputs.find($=>{var V;return((V=$.declaration)==null?void 0:V.id)===A.id})).forEach(A=>{const $={id:N.UUID.uuid(),version:N.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||L().toISOString(),author:N.sessionAuthor,previousVersion:null,deleted:!1,type:f.InputMap,parent:this.toReference(),name:null,description:null,codeName:null,declaration:A,defaultValue:null,index:A.index,readsValue:null},V=te($,this.project);return V.setParent(this,i),V.initChildren(i),i==null||i.add(V,S.Added),this.addInput(V,i),V}),this.inputs.filter(A=>!A.declaration).forEach(A=>{const $=y.find(V=>ne(V,this.project)===ne(A,this.project));$&&A.setDeclaration($,i)})}}else return i==null||i.attemptAutoclose("sync-variable-instance-inputs",this.id),{added:[],updated:[],removed:[],affected:[],self:this};else return i==null||i.attemptAutoclose("sync-variable-instance-inputs",this.id),{added:[],updated:[],removed:[],affected:[],self:this};return i==null||i.attemptAutoclose("sync-variable-instance-inputs",this.id),{added:R(a),updated:R(o),removed:R(p),affected:R(e),self:this}}syncOutputs(i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"sync-variable-instance-outputs"))){const a=[],o=[],p=[],e=[];if(this.declaration.dataType)if(this.declaration.dataType.entity)[f.DefinitionEntity,f.PrimitiveEntity,f.BuiltInBaseEntity].includes(this.declaration.dataType.entity.type)&&!this.declaration.dataType.isList&&[...this.declaration.dataType.entity.properties].filter(E=>!this.outputs.find(b=>b.declaration===E)).map(E=>{const b={id:N.UUID.uuid(),version:N.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||L().toISOString(),author:N.sessionAuthor,previousVersion:null,deleted:!1,type:f.OutputMap,parent:this.toReference(),defaultValue:null,declaration:E,index:E.index,writesValues:[]},A=te(b,this.project);return A.setParent(this,i),A.initChildren(i),i==null||i.add(A,S.Added),this.addOutput(A,i),A});else return i==null||i.attemptAutoclose("sync-variable-instance-outputs",this.id),{added:[],updated:[],removed:[],affected:[],self:this};else return i==null||i.attemptAutoclose("sync-variable-instance-outputs",this.id),{added:[],updated:[],removed:[],affected:[],self:this};return i==null||i.attemptAutoclose("sync-variable-instance-outputs",this.id),{added:R(a),updated:R(o),removed:R(p),affected:R(e),self:this}}generateUnusedInternalCalls(i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"generate-unused-internal-calls"))){const a=[],o=[],p=[],e=[];if(this.declaration.dataType)if(this.declaration.dataType.entity)[f.DefinitionEntity,f.PrimitiveEntity,f.BuiltInBaseEntity].includes(this.declaration.dataType.entity.type)&&!this.declaration.dataType.isList&&[...this.declaration.dataType.entity.getAllInteractiveMethods()].filter(E=>!this.internalCalls.find(A=>{var V,B,F,K,Z;return(((V=A.declaration)==null?void 0:V.id)||((F=(B=A.initialData)==null?void 0:B.declaration)==null?void 0:F.entityId)||((Z=(K=A.initialData)==null?void 0:K.declaration)==null?void 0:Z.id))===E.id})).map(E=>{const b=E.createInternalCall(i,this);return i==null||i.add(b,S.Added),this.addInternalCall(b),b});else return i==null||i.attemptAutoclose("generate-unused-internal-calls",this.id),{added:[],updated:[],removed:[],affected:[],self:this};else return i==null||i.attemptAutoclose("generate-unused-internal-calls",this.id),{added:[],updated:[],removed:[],affected:[],self:this};return i==null||i.attemptAutoclose("generate-unused-internal-calls",this.id),{added:R(a),updated:R(o),removed:R(p),affected:R(e),self:this}}getDataType(i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"get-data-type"))){var a;return((a=this.declaration)==null?void 0:a.getDataType(i))||null}getUnusedInputs(){return this.inputs.filter(i=>i.suggestion||!i.readsValue&&!i.defaultValue)}getUnusedOutputs(){return this.outputs.filter(i=>i.suggestion||!i.writesValues.length)}getUsedInputs(){return this.inputs.filter(i=>!i.suggestion&&(i.readsValue||i.defaultValue))}getUsedOutputs(){return this.outputs.filter(i=>!i.suggestion&&i.writesValues.length)}};g(Gt,"repository",{APICreate:async(i,...a)=>i,APIUpdate:async(i,...a)=>i,APIDelete:async(i,...a)=>i,APIClone:async(i,...a)=>{},APILoad:async(i,...a)=>null,APILoadVersion:async(i,a,...o)=>null}),g(Gt,"type",f.VariableInstance),g(Gt,"USER_MANAGED_PARENT_TYPES",[...Br,f.Project]),g(Gt,"PARENT_TYPES",[...Gt.USER_MANAGED_PARENT_TYPES]),g(Gt,"MUTABLE_BASE_PROPERTIES",[]),g(Gt,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),g(Gt,"BASE_PROPERTIES",[...Gt.MUTABLE_BASE_PROPERTIES,...Gt.INMUTABLE_BASE_PROPERTIES]),g(Gt,"MUTABLE_META_PROPERTIES",[...Gt.MUTABLE_BASE_PROPERTIES,"x","y"]),g(Gt,"INMUTABLE_META_PROPERTIES",[...Gt.INMUTABLE_BASE_PROPERTIES]),g(Gt,"META_PROPERTIES",[...Gt.MUTABLE_META_PROPERTIES,...Gt.INMUTABLE_META_PROPERTIES]),g(Gt,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry","readsValue"]),g(Gt,"INMUTABLE_UPSTREAM_PROPERTIES",["declaration","parent"]),g(Gt,"UPSTREAM_PROPERTIES",[...Gt.MUTABLE_UPSTREAM_PROPERTIES,...Gt.INMUTABLE_UPSTREAM_PROPERTIES]),g(Gt,"MUTABLE_DOWNSTREAM_PROPERTIES",["writesValues","inputs","outputs","successCalls","errorCalls","internalCalls"]),g(Gt,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),g(Gt,"DOWNSTREAM_PROPERTIES",[...Gt.MUTABLE_DOWNSTREAM_PROPERTIES,...Gt.INMUTABLE_DOWNSTREAM_PROPERTIES]),g(Gt,"PROPERTIES",[...Gt.META_PROPERTIES,...Gt.UPSTREAM_PROPERTIES,...Gt.DOWNSTREAM_PROPERTIES]);let yo=Gt;var vj=(d=>(d.Parent="parent",d.DataTypeEntity="variable-data-type-entity",d.DataType="variable-data-type",d))(vj||{});const Ft=class Ft extends Nr{constructor(i,a){super(i);g(this,"initialData");g(this,"id");g(this,"name");g(this,"codeName",null);g(this,"description",null);g(this,"required",!1);g(this,"constant",!1);g(this,"x");g(this,"y");g(this,"type",f.VariableDeclaration);g(this,"defaultValue",null);g(this,"dataType",null);g(this,"writesValues",[]);g(this,"readsValue",null);g(this,"inputs",[]);g(this,"outputs",[]);g(this,"calledBySuccess",[]);g(this,"calledByError",[]);g(this,"calledByEntry",[]);g(this,"successCalls",[]);g(this,"errorCalls",[]);g(this,"internalCalls",[]);g(this,"parent");g(this,"errors",[]);g(this,"project");g(this,"detachedDependents",{});g(this,"knownVersions",null);g(this,"activeVersion",!1);g(this,"initialized",!1);g(this,"startedInitialization",!1);g(this,"suggestion",!1);g(this,"codeNativeValueValidation",null);this.initialData=i,this.project=a,this.id=i.id,this.name=i.name,this.description=i.description,this.constant=i.constant,this.codeName=i.codeName,this.required=i.required,this.x=i.x,this.y=i.y}static new(i=null){return{id:N.UUID.uuid(),version:N.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||L().toISOString(),author:(i==null?void 0:i.author)||N.sessionAuthor,previousVersion:null,deleted:!1,type:f.VariableDeclaration,name:"",codeName:null,description:"",dataType:null,internalCalls:[],successCalls:[],errorCalls:[],readsValue:null,writesValues:[],defaultValue:null,constant:!1,required:!1,inputs:[],outputs:[],parent:null,calledByEntry:[],calledBySuccess:[],calledByError:[],x:0,y:0}}static fromGenerationTarget(i,a){let o=a;if(i.parent){const A=H(i.parent);o=a.get(A)}const p=i.calledByEntry.map(A=>{const $=H(A);return a.get($)}),e=i.calledBySuccess.map(A=>{const $=H(A);return a.get($)}),y=i.calledByError.map(A=>{const $=H(A);return a.get($)});let v=null;if(i.readsValue){const A=H(i.readsValue);v=a.get(A)}const E={id:i.id,version:N.UUID.uuid(),createdAt:L().toISOString(),author:N.sessionAuthor,previousVersion:null,deleted:!1,type:f.VariableDeclaration,name:i.name,defaultValue:null,codeName:i.codeName||null,description:i.description||null,constant:i.constant||!1,required:i.required||!1,calledByEntry:p,calledBySuccess:e,calledByError:y,dataType:null,errorCalls:[],successCalls:[],internalCalls:[],readsValue:v,inputs:[],outputs:[],writesValues:[],x:0,y:0,parent:o},b=te(E,a);return b.setParent(o,null),b}static validateGenerationTarget(i,a){let o=JSON.parse(JSON.stringify(i));const p=[],e=li(o,{parent:{list:!1,types:[...Br,f.Project],optional:!0}},a);o=e.modifiedData;const y=ow(o,a);return p.push(...e.errors,...y,...Ur(o)),{errors:p,modifiedData:o}}get variableInstances(){const i=[];return Object.values(this.detachedDependents).forEach(a=>{a.field===IA.VarDeclaration&&!i.includes(a.entity)&&i.push(a.entity)}),i}validateGeneratedUpdate(i){const a=[];let o=JSON.parse(JSON.stringify(i));const p=sf(o,this);return o=p.modifiedData,a.push(...p.errors),i.parent&&a.push(new ee({id:`${this.id}--${k.InvalidParentUpdate}`,code:k.InvalidParentUpdate,severity:q.Error,message:`Entity of type '${this.type}' with id '${this.id}' cannot have the 'parent' property updated. The 'parent' on a callable entity, is its scope. It scope is auto-calculated implicitly by the its caller.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elyx-code/project-logic-tree",
3
- "version": "0.0.6432",
3
+ "version": "0.0.6433",
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",