@elyx-code/project-logic-tree 0.0.6643 → 0.0.6645

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
@@ -188663,7 +188663,7 @@ Alternatively you can update the entity with 'update' action. Or replace it by f
188663
188663
  this.id
188664
188664
  ), this;
188665
188665
  const l = this.foreignKeyRef;
188666
- return (l == null ? void 0 : l.id) !== (i == null ? void 0 : i.id) && (this.foreignKeyRef = i, n == null || n.add(this, H.Affected)), n == null || n.attemptAutoclose(
188666
+ return (l == null ? void 0 : l.id) !== (i == null ? void 0 : i.id) && (this.foreignKeyRef = i, n == null || n.add(this, H.Updated)), n == null || n.attemptAutoclose(
188667
188667
  V.SetDataTypeForeignKeyRef,
188668
188668
  this.id
188669
188669
  ), this;
@@ -189921,7 +189921,7 @@ ${DD}`
189921
189921
  i,
189922
189922
  n
189923
189923
  ), c = Gr(this, l), e = this.toMeta();
189924
- return this.name = l.name !== void 0 ? l.name : e.name, this.codeName = l.codeName !== void 0 ? l.codeName : e.codeName, this.description = l.description !== void 0 ? l.description : e.description, this.abstract = l.abstract !== void 0 ? l.abstract : e.abstract, this.private = l.private !== void 0 ? l.private : e.private, this.index = l.index || (l.index !== 0 ? e.index : 0), this.static = l.static !== void 0 ? l.static : e.static, this.hidden = l.hidden !== void 0 ? l.hidden : e.hidden, this.constant = l.constant !== void 0 ? l.constant : e.constant, this.interactive = l.interactive !== void 0 ? l.interactive : e.interactive, this.required = l.required !== void 0 ? l.required : e.required, super.baseMetaSync(l, this, n), l.deleted === !0 && !e.deleted ? n == null || n.add(this, H.Removed) : l.deleted === !1 && e.deleted ? n == null || n.add(this, H.Added) : c && (n == null || n.add(this, H.Updated)), n == null || n.attemptAutoclose("meta-sync", this.id), this;
189924
+ return this.name = l.name !== void 0 ? l.name : e.name, this.codeName = l.codeName !== void 0 ? l.codeName : e.codeName, this.description = l.description !== void 0 ? l.description : e.description, this.abstract = l.abstract !== void 0 ? l.abstract : e.abstract, this.private = l.private !== void 0 ? l.private : e.private, this.index = l.index || (l.index !== 0 ? e.index : 0), this.static = l.static !== void 0 ? l.static : e.static, this.hidden = l.hidden !== void 0 ? l.hidden : e.hidden, this.constant = l.constant !== void 0 ? l.constant : e.constant, this.interactive = l.interactive !== void 0 ? l.interactive : e.interactive, this.required = l.required !== void 0 ? l.required : e.required, this.unique = l.unique !== void 0 ? l.unique : e.unique, super.baseMetaSync(l, this, n), l.deleted === !0 && !e.deleted ? n == null || n.add(this, H.Removed) : l.deleted === !1 && e.deleted ? n == null || n.add(this, H.Added) : c && (n == null || n.add(this, H.Updated)), n == null || n.attemptAutoclose("meta-sync", this.id), this;
189925
189925
  }
189926
189926
  async APILoad(i = Ge, ...n) {
189927
189927
  return await Xt.repository.APILoad(this.id, ...n), this;
@@ -384,10 +384,10 @@ ${Ap}`}))}}}const y=l.parent&&r.get(l.parent)||r.getBuiltIn(l.parent),v=y?Op(y):
384
384
  The entitities of type '${Dt(E,"', '","' and '")}' can only have one 'data-type' child under the 'dataType' property so no 'parentRelationType' is needed.`})),y.dataType)){const w=(b=y.dataType)==null?void 0:b.id;c.push(new Oe({id:`${i.id}--${re.NewEntityWouldOverriteExisting}`,code:re.NewEntityWouldOverriteExisting,severity:ce.Error,message:`The entity with id '${i.id}' and type '${i.type}', cannot be added as a child to the entity with id '${l.parent}' and type '${A}', because it already has a 'data-type' child with id '${w}'.
385
385
  The entitities of type '${Dt(E,"', '","' 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:
386
386
  ${No({describe_entity:w})}
387
- Alternatively you can update the entity with 'update' action. Or replace it by first removing it and then creating a new one.`}))}A===o.DataType&&(!l.parentRelationType||!(l.parentRelationType===Fe.AndDataTypeGroup||l.parentRelationType===Fe.OrDataTypeGroup))&&c.push(new Oe({id:`${i.id}--${re.InvalidParentRelationType}`,code:re.InvalidParentRelationType,severity:ce.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:c,modifiedData:l}}get isGroup(){const i=[...this.andChildrenGroup||[],...this.orChildrenGroup||[]];if(i.length>1){let r=0;for(const l of i)if(l.isResolved&&(r++,r>1))return!0}return!1}get isResolved(){return[o.BuiltInBaseEntity,o.ActionDescriptor].includes(this.parent.type)||Op(this.parent)?!0:!(!this.entity&&!this.isGroup&&!this.foreignKeyRef&&!this.foreignKeyAllowed)}validateGeneratedUpdate(i){return{errors:[],modifiedData:i}}subscribeDependents(i){return i.forEach(r=>{this.detachedDependents[r.entity.id]||(this.detachedDependents[r.entity.id]=r)}),this}unsubscribeDependents(i){return i.forEach(r=>{this.detachedDependents[r.entity.id]&&delete this.detachedDependents[r.entity.id]}),this}syncDependents(i=this.project.addChangeSet(new H(this.project,L.sessionAuthor,B().toISOString(),this,!0,"sync-dependents"))){const r=[],l=[],c=[],e=[];return Object.values(this.detachedDependents).forEach(y=>{const v=y.entity.afterAllChildrenInitialized(i);r.push(...v.updated),l.push(...v.added),c.push(...v.removed),e.push(...v.affected)}),i==null||i.attemptAutoclose("sync-dependents",this.id),{updated:O(r),added:O(l),removed:O(c),affected:O(e),self:this}}onDetachedDependencyRemoved(i,r,l){const c=[],e=[],y=[],v=[];return r==="entity-field"&&this.setEntity(null,l),r==="foreign-key-ref-field"&&this.setForeignKeyRef(null,l),{updated:O(c),added:O(e),removed:O(y),affected:O(v),self:this}}onDetachedDependencyRestored(i,r,l){const c=[],e=[],y=[],v=[];return r==="entity-field"&&this.setEntity(i,l),r==="foreign-key-ref-field"&&this.setForeignKeyRef(i,l),{updated:O(c),added:O(e),removed:O(y),affected:O(v),self:this}}unsubscribeFromDependencies(){var i,r,l,c;return(r=(i=this.entity)==null?void 0:i.unsubscribeDependents)==null||r.call(i,[{entity:this,field:"entity-field"}]),(c=(l=this.foreignKeyRef)==null?void 0:l.unsubscribeDependents)==null||c.call(l,[{entity:this,field:"foreign-key-ref-field"}]),this}subscribeToDependencies(){var i,r,l,c;return(r=(i=this.entity)==null?void 0:i.subscribeDependents)==null||r.call(i,[{entity:this,field:"entity-field"}]),(c=(l=this.foreignKeyRef)==null?void 0:l.subscribeDependents)==null||c.call(l,[{entity:this,field:"foreign-key-ref-field"}]),this}increaseVersion(i){if(i&&!B(i).isValid())throw new Error(`The shared timestamp '${i}' is not a valid ISO 8601 date string.`);return i&&B(i).isSame(B(this.createdAt))?this:(this.previousVersion=this.version,this.version=L.UUID.uuid(),this.createdAt=B(i).toISOString()||B().toISOString(),this)}captureVersion(){var r;const i=((r=this.knownVersions)==null?void 0:r.get(this.version))||new vi(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.foreignKeyRef=this.foreignKeyRef,i.andChildrenGroup=this.andChildrenGroup?[...this.andChildrenGroup]:this.andChildrenGroup,i.orChildrenGroup=this.orChildrenGroup?[...this.orChildrenGroup]:this.orChildrenGroup,i.parent=this.parent,this}recursiveCaptureUpstreamVersions(i){const r=[],l=[],c=[],e=[];if(this.parent&&this.parent.type!==o.BuiltInBaseEntity){this.parent.increaseVersion(i);const y=this.parent.recursiveCaptureUpstreamVersions(i);r.push(this.parent,...y.updated),l.push(...y.added),c.push(...y.removed)}return{updated:O(r),added:O(l),removed:O(c),affected:O(e),self:this}}async restoreVersion(i){var v;const r=[],l=[],c=[],e=[];if(this.version===i)return{updated:O(r),added:O(l),removed:O(c),affected:O(e),self:this};if(!this.knownVersions){const b=new Map;for(const[A,E]of this.knownVersions||new Map){if(b.set(A,E),E.activeVersion=!1,E.knownVersions)for(const[w,P]of E.knownVersions)b.set(w,P);E.knownVersions=null}}let y=(v=this.knownVersions)==null?void 0:v.get(i);if(!y){const b=await this.APILoadVersion({},i);if(!b)throw new Error(`Version with id '${i}' for entity with id '${this.id}' not found.`);y=new vi(b,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.foreignKeyRef=y.foreignKeyRef,this.andChildrenGroup=y.andChildrenGroup?[...y.andChildrenGroup]:null,this.orChildrenGroup=y.orChildrenGroup?[...y.orChildrenGroup]:null,this.parent=y.parent,{updated:O(r),added:O(l),removed:O(c),affected:O(e),self:this}}updateWithShallowTransfer(i,r=this.project.addChangeSet(new H(this.project,L.sessionAuthor,B().toISOString(),this,!0,V.UpdateWithShallowTransfer))){var l,c;if(!this.checkCanEdit(this,r))return ae.warn(`[updateWithShallowTransfer] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),r==null||r.attemptAutoclose(V.UpdateWithShallowTransfer,this.id),this;if(this.metaSync(i,r),this.version=i.version,this.createdAt=i.createdAt,this.author=i.author,this.deleted=i.deleted,this.previousVersion=i.previousVersion,this.unsubscribeFromDependencies(),i.parent){const e=ye(i.parent),y=this.project.get(e),v=this.parent;if(v&&v.id!==(y==null?void 0:y.id)&&this.removeFromParent(r),y)this.setParent(y,r),this.addSelfToProject(r);else throw r==null||r.attemptAutoclose(V.UpdateWithShallowTransfer,this.id),new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${e}' that isn't found in the project`)}else throw r==null||r.attemptAutoclose(V.UpdateWithShallowTransfer,this.id),new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(i.entity){const e=ye(i.entity),y=this.project.get(e);y&&(y.type===o.DefinitionEntity&&y.parent===this||this.setEntity(y,null))}if(i.foreignKeyRef){const e=ye(i.foreignKeyRef),y=this.project.get(e);y&&this.setForeignKeyRef(y,null)}return(l=i.andChildrenGroup)==null||l.forEach(e=>{const y=ye(e),v=this.project.get(y);v&&(this.addToAndGroup(v,r),v.setParent(this,r))}),[...this.andChildrenGroup||[]].forEach(e=>{var v;((v=i.andChildrenGroup)==null?void 0:v.find(b=>ye(b)===e.id))||(this.removeChildGroup(e,r),e.removeFromParent(r))}),(c=i.orChildrenGroup)==null||c.forEach(e=>{const y=ye(e),v=this.project.get(y);v&&(this.addToOrGroup(v,r),v.setParent(this,r))}),[...this.orChildrenGroup||[]].forEach(e=>{var v;((v=i.orChildrenGroup)==null?void 0:v.find(b=>ye(b)===e.id))||(this.removeChildGroup(e,r),e.removeFromParent(r))}),this.captureVersion(),this.subscribeToDependencies(),r==null||r.attemptAutoclose(V.UpdateWithShallowTransfer,this.id),this}hydrateAncestors(){const i=[],r=[],l=[],c=[];if(this.initialData.parent){const e=ye(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=ye(this.initialData.entity),y=this.project.get(e);y&&(y.type===o.DefinitionEntity&&y.parent===this||(this.setEntity(y,null),y.type!==o.BuiltInBaseEntity&&y.type!==o.PrimitiveEntity&&i.push(y)))}if(this.initialData.foreignKeyRef){const e=ye(this.initialData.foreignKeyRef),y=this.project.get(e);y&&this.setForeignKeyRef(y,null)}return{updated:O(i),added:O(r),removed:O(l),affected:O(c),self:this}}afterAllChildrenInitialized(i=this.project.addChangeSet(new H(this.project,L.sessionAuthor,B().toISOString(),this,!0,V.AfterAllChildrenInitialized))){var y,v,b;if(!this.checkCanEdit(this,i))return ae.warn(`[afterAllChildrenInitialized] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(V.AfterAllChildrenInitialized,this.id),{updated:[],added:[],removed:[],affected:[],self:this};const r=[],l=[],c=[],e=[];if(this.initialized=!0,((y=this.parent)==null?void 0:y.type)===o.DataType){let A=this.index||0;const E=(this.parentRelationType===Fe.AndDataTypeGroup?this.parent.andChildrenGroup||[]:this.parent.orChildrenGroup||[]).filter(P=>!P.deleted&&P.id!==this.id);E.length&&(A>E.length+1?A=E.length:A<0&&(A=0)),E.find(P=>(P.index||0)===A&&!P.deleted)&&E.filter(P=>(P.index||0)>=A&&!P.deleted).forEach(P=>{P.metaSync({index:(P.index||0)+1},i),i==null||i.add(P,W.Updated),r.push(P)}),this.metaSync({index:A},i)}return(v=this.andChildrenGroup)!=null&&v.length&&this.andChildrenGroup.sort((A,E)=>(A.index||0)-(E.index||0)),(b=this.orChildrenGroup)!=null&&b.length&&this.orChildrenGroup.sort((A,E)=>(A.index||0)-(E.index||0)),this.captureVersion(),i==null||i.attemptAutoclose(V.AfterAllChildrenInitialized,this.id),{updated:O(r),added:O(l),removed:O(c),affected:O(e),self:this}}addSelfToProject(i=this.project.addChangeSet(new H(this.project,L.sessionAuthor,B().toISOString(),this,!0,"add-self-to-project"))){const r=[this],l=[],c=[],e=[];return this.parent.type===o.DataType?(this.parentRelationType===Fe.AndDataTypeGroup?this.parent.addToAndGroup(this,i):this.parentRelationType===Fe.OrDataTypeGroup&&this.parent.addToOrGroup(this,i),e.push(this.parent)):this.parent.type===o.DefinitionEntity?(this.parent.setAdditionalPropertiesDataType(this,i),e.push(this.parent)):this.parent.type!==o.BuiltInBaseEntity&&this.parent.setDataType(this,i),this.subscribe(),this.subscribeToDependencies(),i==null||i.attemptAutoclose("add-self-to-project",this.id),{updated:O(r),added:O(l),removed:O(c),affected:O(e),self:this}}setParent(i,r=this.project.addChangeSet(new H(this.project,L.sessionAuthor,B().toISOString(),this,!0,V.SetParent))){var l;return this.checkCanEditWithCounterpartAndSideEffects(this,i,V.SetParent,r)?(((l=this.parent)==null?void 0:l.id)!==(i==null?void 0:i.id)&&(this.parent=i,r&&(r==null||r.add(this,W.Updated))),r==null||r.attemptAutoclose(V.SetParent,this.id),this):this}removeChildGroup(i,r=this.project.addChangeSet(new H(this.project,L.sessionAuthor,B().toISOString(),this,!0,V.RemoveChildGroup))){if(!this.checkCanEdit(this,r))return ae.warn(`[removeChildGroup] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),r==null||r.attemptAutoclose(V.RemoveChildGroup,this.id),this;if(this.andChildrenGroup){const l=this.andChildrenGroup.findIndex(c=>c.id===i.id);l!==-1&&(this.andChildrenGroup.splice(l,1),r==null||r.add(this,W.Updated))}if(this.orChildrenGroup){const l=this.orChildrenGroup.findIndex(c=>c.id===i.id);l!==-1&&(this.orChildrenGroup.splice(l,1),r==null||r.add(this,W.Updated))}return r==null||r.attemptAutoclose(V.RemoveChildGroup,this.id),this}initChildren(i=this.project.addChangeSet(new H(this.project,L.sessionAuthor,B().toISOString(),this,!0,"init-children"))){var r,l,c,e,y,v,b,A,E,w;if(this.initialized||this.startedInitialization)return this;if(this.startedInitialization=!0,this.initialData.entity)if(this.initialData.entity.type===o.GenericReference){const P=this.project.findSubscribedInstanceFromReference(this.initialData.entity);this.entity=P}else this.entity=me(this.initialData.entity,this.project),(((l=(r=this.initialData.entity)==null?void 0:r.parent)==null?void 0:l.id)===this.id||((e=(c=this.initialData.entity)==null?void 0:c.parent)==null?void 0:e.type)===o.GenericReference&&((v=(y=this.initialData.entity)==null?void 0:y.parent)==null?void 0:v.entityId)==this.id)&&this.entity.setParent(this,null),(A=(b=this.entity).initChildren)==null||A.call(b,i);if(this.initialData.foreignKeyRef)if(this.initialData.foreignKeyRef.type===o.GenericReference){const P=this.project.findSubscribedInstanceFromReference(this.initialData.foreignKeyRef);this.foreignKeyRef=P}else this.foreignKeyRef=me(this.initialData.foreignKeyRef,this.project),(w=(E=this.foreignKeyRef).initChildren)==null||w.call(E,i);return this.initialData.andChildrenGroup&&(this.andChildrenGroup=this.initialData.andChildrenGroup.map(P=>{const x=me(P,this.project);return x.setParent(this,null),x.initChildren(i),x})),this.initialData.orChildrenGroup&&(this.orChildrenGroup=this.initialData.orChildrenGroup.map(P=>{const x=me(P,this.project);return x.setParent(this,null),x.initChildren(i),x})),this.subscribeToDependencies(),this.afterAllChildrenInitialized(i),i==null||i.attemptAutoclose("init-children",this.id),this}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(i,r=this.project.addChangeSet(new H(this.project,L.sessionAuthor,B().toISOString(),this,!0,"meta-sync"))){const l=$n(this,i,r),c=Nn(this,l),e=this.toMeta();return this.options=l.options||e.options,this.parentRelationType=l.parentRelationType||e.parentRelationType,this.isList=l.isList!==void 0?l.isList:e.isList,this.inferred=l.inferred!==void 0?l.inferred:e.inferred,this.like=l.like!==void 0?l.like:e.like,this.asType=l.asType!==void 0?l.asType:e.asType,this.index=l.index!==void 0?l.index:e.index,this.implementationChooseOne=l.implementationChooseOne!==void 0?l.implementationChooseOne:e.implementationChooseOne,this.staticEntities=l.staticEntities!==void 0?l.staticEntities:e.staticEntities,this.interactiveEntities=l.interactiveEntities!==void 0?l.interactiveEntities:e.interactiveEntities,this.actionEntities=l.actionEntities!==void 0?l.actionEntities:e.actionEntities,super.baseMetaSync(l,this,r),l.deleted===!0&&!e.deleted?r==null||r.add(this,W.Removed):l.deleted===!1&&e.deleted?r==null||r.add(this,W.Added):c&&(r==null||r.add(this,W.Updated)),r==null||r.attemptAutoclose("meta-sync",this.id),this}async APILoad(i=Be,...r){return await vi.repository.APILoad(this.id,...r),this}async APICreate(i=Be,...r){return await vi.repository.APICreate(this.toShallowJSON(),...r),this}async APIUpdate(i=Be,...r){return await vi.repository.APIUpdate(this.toShallowJSON(),...r),this}async APIDelete(i=Be,...r){return await vi.repository.APIDelete(this.toShallowJSON(),...r),this}async APIClone(i=Be,...r){return await vi.repository.APIClone(this.id,...r),this}async APILoadVersion(i=Be,r,...l){return await vi.repository.APILoadVersion(this.id,r,...l)}removeFromParent(i=this.project.addChangeSet(new H(this.project,L.sessionAuthor,B().toISOString(),this,!0,V.RemoveFromParent))){var y,v;if(!this.checkCanEdit(this,i))return ae.warn(`[removeFromParent] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(V.RemoveFromParent,this.id),{added:[],updated:[],removed:[],affected:[],self:this};const r=[],l=[],c=[],e=[];if(((y=this.parent)==null?void 0:y.type)===o.DataType)this.parent.removeChildGroup(this,i);else if(((v=this.parent)==null?void 0:v.type)===o.DefinitionEntity)this.parent.removeAdditionalPropertiesDataType(i);else{const b=this.parent;b==null||b.removeDataType(i)}return this.parent&&this.parent.type!==o.BuiltInBaseEntity&&r.push(this.parent),i==null||i.attemptAutoclose(V.RemoveFromParent,this.id),{added:O(c),updated:O(r),removed:O(l),affected:O(e),self:this}}remove({ignoreUpstream:i}={ignoreUpstream:!1},r=this.project.addChangeSet(new H(this.project,L.sessionAuthor,B().toISOString(),this,!0,V.RemoveEntity))){const l=[],c=[],e=[],y=[];if(r!=null&&r.hasRemoved(this.id))return r==null||r.attemptAutoclose(V.RemoveEntity,this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(c.push(this),this.unsubscribe(),this.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},r),Object.values(this.detachedDependents).forEach(v=>{const{updated:b,removed:A,added:E}=v.entity.onDetachedDependencyRemoved(this,v.field,r);l.push(...b),c.push(...A),e.push(...E)}),this.entity&&this.entity.type===o.DefinitionEntity&&this.entity.parent===this){const{updated:v,removed:b}=this.entity.remove({ignoreUpstream:!0},r);l.push(...v),c.push(...b)}if(this.andChildrenGroup&&this.andChildrenGroup.forEach(v=>{const{removed:b,updated:A}=v.remove({ignoreUpstream:!0},r);c.push(...b),l.push(...A)}),this.orChildrenGroup&&this.orChildrenGroup.forEach(v=>{const{removed:b,updated:A}=v.remove({ignoreUpstream:!0},r);c.push(...b),l.push(...A)}),!i){const v=this.removeFromParent(r);e.push(...v.added),l.push(...v.updated),c.push(...v.removed),y.push(...v.affected)}return r==null||r.attemptAutoclose(V.RemoveEntity,this.id),{added:O(e),updated:O(l),removed:O(c),affected:O(y),self:this}}restore({}={},i=this.project.addChangeSet(new H(this.project,L.sessionAuthor,B().toISOString(),this,!0,V.RestoreEntity))){if(!this.checkCanEdit(this,i))return ae.warn(`[restore] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(V.RestoreEntity,this.id),{added:[],updated:[],removed:[],affected:[],self:this};const r=[],l=[],c=[],e=[];if(i!=null&&i.hasAdded(this.id))return i==null||i.attemptAutoclose(V.RestoreEntity,this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},i),Object.values(this.detachedDependents).forEach(y=>{const{updated:v,removed:b,added:A}=y.entity.onDetachedDependencyRestored(this,y.field,i);l.push(...v),c.push(...b),r.push(...A)}),this.entity&&this.entity.type===o.DefinitionEntity&&this.entity.parent===this){const{updated:y}=this.entity.restore({},i);l.push(...y)}if(this.andChildrenGroup&&this.andChildrenGroup.forEach(y=>{const{updated:v,added:b}=y.restore({},i);l.push(...v),r.push(...b)}),this.orChildrenGroup&&this.orChildrenGroup.forEach(y=>{const{updated:v,added:b}=y.restore({},i);l.push(...v),r.push(...b)}),this.parent.type===o.DataType){const y=this.parent;Array.isArray(y.andChildrenGroup)&&y.andChildrenGroup.push(this)}if(this.parent.type===o.DataType){const y=this.parent;this.parentRelationType===Fe.AndDataTypeGroup?Array.isArray(y.andChildrenGroup)&&y.andChildrenGroup.push(this):this.parentRelationType===Fe.OrDataTypeGroup&&Array.isArray(y.orChildrenGroup)&&y.orChildrenGroup.push(this)}else if(this.parent.type===o.DefinitionEntity){const y=this.parent;y.setAdditionalPropertiesDataType(this,i),l.push(y)}else{const y=this.parent;y.setDataType(this,i),l.push(y)}return i==null||i.attemptAutoclose(V.RestoreEntity,this.id),{added:O(r),updated:O(l),removed:O(c),affected:O(e),self:this}}toFlat(i=new Set){var l,c,e,y;return i.has(this.id)?[]:(i.add(this.id),[this,...((l=this.andChildrenGroup)==null?void 0:l.flatMap(v=>v.toFlat(i)))||[],...((c=this.orChildrenGroup)==null?void 0:c.flatMap(v=>v.toFlat(i)))||[],...((e=this.entity)==null?void 0:e.toFlat(i))||[],...((y=this.foreignKeyRef)==null?void 0:y.toFlat(i))||[]])}toFlatIds(i=new Set){var l,c,e,y;return i.has(this.id)?[]:(i.add(this.id),[this.id,...((l=this.andChildrenGroup)==null?void 0:l.flatMap(v=>v.toFlatIds(i)))||[],...((c=this.orChildrenGroup)==null?void 0:c.flatMap(v=>v.toFlatIds(i)))||[],...((e=this.entity)==null?void 0:e.toFlatIds(i))||[],...((y=this.foreignKeyRef)==null?void 0:y.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,foreignKeyAllowed:this.foreignKeyAllowed,parentRelationType:this.parentRelationType,implementationChooseOne:this.implementationChooseOne,staticEntities:this.staticEntities,interactiveEntities:this.interactiveEntities,actionEntities:this.actionEntities,options:this.options,asType:this.asType,type:this.type,editable:this.editable,deletable:this.deletable}}toJSON(i=new Set){var r,l,c,e,y;return i.has(this.id)?this.toReference():(i.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,editable:this.editable,deletable:this.deletable,options:this.options,isList:this.isList,asType:this.asType,index:this.index,like:this.like,foreignKeyAllowed:this.foreignKeyAllowed,inferred:this.inferred,parentRelationType:this.parentRelationType,implementationChooseOne:this.implementationChooseOne,staticEntities:this.staticEntities,interactiveEntities:this.interactiveEntities,actionEntities:this.actionEntities,foreignKeyRef:((r=this.foreignKeyRef)==null?void 0:r.toJSON(i))||null,andChildrenGroup:((l=this.andChildrenGroup)==null?void 0:l.map(v=>v.toJSON(i)))||null,orChildrenGroup:((c=this.orChildrenGroup)==null?void 0:c.map(v=>v.toJSON(i)))||null,entity:((e=this.entity)==null?void 0:e.parent)===this?this.entity.toJSON(i):((y=this.entity)==null?void 0:y.toReference())||null,parent:this.parent.toReference()})}toJSONClone(i=dt){var l,c,e,y,v,b,A,E,w,P;let r;return(l=i.seenEntityMaps)!=null&&l.has(this.id)?r=i.seenEntityMaps.get(this.id):(r=i.newId||jn(this,this.project,i.uuidStrategy),i.seenEntityMaps&&i.seenEntityMaps.set(this.id,r)),(c=i.seenEntities)!=null&&c.has(r)||(e=i.seenEntities)!=null&&e.has(this.id)?this.toReference({seenEntityMaps:i.seenEntityMaps}):((y=i.seenEntities)==null||y.add(r),(v=i.seenEntities)==null||v.add(this.id),{id:r,version:L.UUID.uuid(),createdAt:i.timestamp||B().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,editable:this.editable,deletable:this.deletable,options:this.options,isList:this.isList,asType:this.asType,like:this.like,index:this.index,inferred:this.inferred,foreignKeyAllowed:this.foreignKeyAllowed,parentRelationType:this.parentRelationType,implementationChooseOne:this.implementationChooseOne,staticEntities:this.staticEntities,interactiveEntities:this.interactiveEntities,actionEntities:this.actionEntities,foreignKeyRef:((b=this.foreignKeyRef)==null?void 0:b.toJSONClone({...i,newId:null}))||null,andChildrenGroup:((A=this.andChildrenGroup)==null?void 0:A.map(x=>x.toJSONClone({...i,newId:null})))||null,orChildrenGroup:((E=this.orChildrenGroup)==null?void 0:E.map(x=>x.toJSONClone({...i,newId:null})))||null,entity:((w=this.entity)==null?void 0:w.parent)===this?this.entity.toJSONClone({...i,newId:null}):((P=this.entity)==null?void 0:P.toReference({seenEntityMaps:i.seenEntityMaps}))||null,parent:this.parent.toReference({seenEntityMaps:i.seenEntityMaps})})}toReference(i=dt){var l;let r=this.id;return(l=i.seenEntityMaps)!=null&&l.has(this.id)&&(r=i.seenEntityMaps.get(this.id)),{id:r+"--"+L.UUID.uuid()+"--ref",type:o.GenericReference,entityId:r,version:this.version,entityType:this.type}}toShallowJSON(i=dt){var l,c,e,y,v;let r=this.id;return(l=i.seenEntityMaps)!=null&&l.has(this.id)&&(r=i.seenEntityMaps.get(this.id)),{id:r,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,editable:this.editable,deletable:this.deletable,isList:this.isList,options:this.options,asType:this.asType,index:this.index,parentRelationType:this.parentRelationType,like:this.like,inferred:this.inferred,foreignKeyAllowed:this.foreignKeyAllowed,implementationChooseOne:this.implementationChooseOne,staticEntities:this.staticEntities,interactiveEntities:this.interactiveEntities,actionEntities:this.actionEntities,foreignKeyRef:((c=this.foreignKeyRef)==null?void 0:c.toReference(i))||null,andChildrenGroup:((e=this.andChildrenGroup)==null?void 0:e.map(b=>b.toReference(i)))||null,orChildrenGroup:((y=this.orChildrenGroup)==null?void 0:y.map(b=>b.toReference(i)))||null,entity:((v=this.entity)==null?void 0:v.toReference(i))||null,parent:this.parent.toReference(i)}}toFlatJSON(i=new Set){var l,c,e;return i.has(this.id)?[]:(i.add(this.id),[this.toShallowJSON(),...((l=this.andChildrenGroup)==null?void 0:l.flatMap(y=>y.toFlatJSON(i)))||[],...((c=this.orChildrenGroup)==null?void 0:c.flatMap(y=>y.toFlatJSON(i)))||[],...((e=this.entity)==null?void 0:e.toFlatJSON(i))||[]])}toGenerationTarget(){var i,r;return{id:this.id,type:this.type,options:this.options||void 0,isList:this.isList,like:this.like,parentRelationType:this.parentRelationType||void 0,foreignKeyRef:((i=this.foreignKeyRef)==null?void 0:i.id)||null,asType:this.asType,entity:((r=this.entity)==null?void 0:r.id)||null,parent:this.parent.id}}toFlatGenerationTarget(i=new Set){var l,c;return i.has(this.id)?[]:(i.add(this.id),[this.toGenerationTarget(),...((l=this.andChildrenGroup)==null?void 0:l.flatMap(e=>e.toFlatGenerationTarget(i)))||[],...((c=this.orChildrenGroup)==null?void 0:c.flatMap(e=>e.toFlatGenerationTarget(i)))||[],...this.entity&&this.entity.type==o.DefinitionEntity&&this.entity.parent===this&&this.entity.toFlatGenerationTarget(i)||[]])}clearErrors(){var i,r,l,c;return this.errors=[],(i=this.andChildrenGroup)==null||i.forEach(e=>e.clearErrors()),(r=this.orChildrenGroup)==null||r.forEach(e=>e.clearErrors()),this.inferred&&this.entity&&this.entity.type===o.DefinitionEntity&&((l=this.entity)==null?void 0:l.parent)===this&&((c=this.entity)==null||c.clearErrors()),this}validate(){const i=hxe(this);return this.errors=i,{success:!0}}getErrors(){return[...this.errors]}getShallowErrors(){return this.errors}clone(i=this.project.addChangeSet(new H(this.project,L.sessionAuthor,B().toISOString(),this,!0,V.CloneEntity)),r=null,l=null,c=!0){var x,M,k,q;const e=Vn(r,this),y=r||this.parent,v=l||L.UUID.uuid(),b=new Set([...this.project.getAllBuiltInIds(),...rn()]),A={id:v,version:L.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||B().toISOString(),author:(i==null?void 0:i.author)||"1",previousVersion:null,deleted:!1,deletable:!0,editable:!0,type:o.DataType,isList:this.isList,asType:this.asType,options:this.options,index:this.index,parentRelationType:this.parentRelationType,staticEntities:this.staticEntities,foreignKeyAllowed:this.foreignKeyAllowed,interactiveEntities:this.interactiveEntities,actionEntities:this.actionEntities,like:this.like,inferred:this.inferred,implementationChooseOne:this.implementationChooseOne,foreignKeyRef:((x=this.foreignKeyRef)==null?void 0:x.toReference())||null,andChildrenGroup:null,orChildrenGroup:null,entity:null,parent:y.toReference()},E=Ui(A,e);E.hydrateAncestors(),E.setParent(y,null),c&&(E.subscribe(),E.addSelfToProject(i)),E.initChildren(i),i==null||i.add(E,W.Added);const w=(M=this.andChildrenGroup)==null?void 0:M.map(Z=>b.has(Z.id)?e.getBuiltIn(Z.id):Z.clone(i,E,L.UUID.uuid(),c)),P=(k=this.orChildrenGroup)==null?void 0:k.map(Z=>b.has(Z.id)?e.getBuiltIn(Z.id):Z.clone(i,E,L.UUID.uuid(),c));if(E.andChildrenGroup=w||null,E.orChildrenGroup=P||null,this.entity&&this.entity.type===o.DefinitionEntity&&((q=this.entity)==null?void 0:q.parent)===this)if(b.has(this.entity.id))E.setEntity(e.getBuiltIn(this.entity.id),i);else{const Z=this.entity.clone(i,E,L.UUID.uuid(),c);E.setEntity(Z,i)}else if(this.entity){const Z=e.get(this.entity.id)||e.getBuiltIn(this.entity.id);E.setEntity(Z,i)}return i==null||i.attemptAutoclose(V.CloneEntity,this.id),E}merge(i,r=this.project.addChangeSet(new H(this.project,L.sessionAuthor,B().toISOString(),this,!0,V.MergeDataTypes))){var v,b,A;const l=[],c=[],e=[],y=[];if(!this.checkCanEdit(this,r))return ae.warn(`[${V.MergeDataTypes}] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),r==null||r.attemptAutoclose(V.MergeDataTypes,this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.asType!==(i==null?void 0:i.asType)&&(this.metaSync({asType:i==null?void 0:i.asType},r),r==null||r.add(this,W.Updated),l.push(this)),this.index!==(i==null?void 0:i.index)&&(this.metaSync({index:i==null?void 0:i.index},r),r==null||r.add(this,W.Updated),l.push(this)),this.foreignKeyAllowed!==(i==null?void 0:i.foreignKeyAllowed)&&(this.metaSync({foreignKeyAllowed:i==null?void 0:i.foreignKeyAllowed},r),r==null||r.add(this,W.Updated),l.push(this)),this.isList!==(i==null?void 0:i.isList)&&(this.metaSync({isList:i==null?void 0:i.isList},r),r==null||r.add(this,W.Updated),l.push(this)),this.like!==(i==null?void 0:i.like)&&(this.metaSync({like:i==null?void 0:i.like},r),r==null||r.add(this,W.Updated),l.push(this)),((v=i==null?void 0:i.foreignKeyRef)==null?void 0:v.id)!==((b=this.foreignKeyRef)==null?void 0:b.id)&&(this.setForeignKeyRef((i==null?void 0:i.foreignKeyRef)||null,r),r==null||r.add(this,W.Updated),l.push(this)),i!=null&&i.entity&&(i==null?void 0:i.entity.type)===o.DefinitionEntity&&(i==null?void 0:i.entity).parent===i)if(((A=this.entity)==null?void 0:A.type)===o.DefinitionEntity&&this.entity.parent===this)f_(this.entity,i.entity)||d$e(this.entity,i.entity,r);else{const E=i.entity.clone(r,this,L.UUID.uuid(),!0);this.setEntity(E,r),c.push(E)}else i!=null&&i.entity&&(this.setEntity(i==null?void 0:i.entity,r),r==null||r.add(this,W.Updated),l.push(this));return this.inferred!==(i==null?void 0:i.inferred)&&this.metaSync({inferred:(i==null?void 0:i.inferred)??!1},r),r==null||r.attemptAutoclose(V.MergeDataTypes,this.id),{updated:O(l),added:O(c),removed:O(e),affected:O(y),self:this}}addToAndGroup(i,r=this.project.addChangeSet(new H(this.project,L.sessionAuthor,B().toISOString(),this,!0,V.AddToAndGroup))){return this.checkCanEdit(this,r)?(this.andChildrenGroup||(this.andChildrenGroup=[]),this.andChildrenGroup.includes(i)||(this.andChildrenGroup.push(i),r==null||r.add(i,W.Affected)),r==null||r.attemptAutoclose(V.AddToAndGroup,this.id),this):(ae.warn(`[${V.AddToAndGroup}] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),r==null||r.attemptAutoclose(V.AddToAndGroup,this.id),this)}addToOrGroup(i,r=this.project.addChangeSet(new H(this.project,L.sessionAuthor,B().toISOString(),this,!0,V.AddToOrGroup))){return this.checkCanEdit(this,r)?(this.orChildrenGroup||(this.orChildrenGroup=[]),this.orChildrenGroup.includes(i)||(this.orChildrenGroup.push(i),r==null||r.add(i,W.Affected)),r==null||r.attemptAutoclose(V.AddToOrGroup,this.id),this):(ae.warn(`[${V.AddToOrGroup}] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),r==null||r.attemptAutoclose(V.AddToOrGroup,this.id),this)}setForeignKeyRef(i,r=this.project.addChangeSet(new H(this.project,L.sessionAuthor,B().toISOString(),this,!0,V.SetDataTypeForeignKeyRef))){if(!this.checkCanEdit(this,r))return ae.warn(`[${V.SetDataTypeForeignKeyRef}] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),r==null||r.attemptAutoclose(V.SetDataTypeForeignKeyRef,this.id),this;const l=this.foreignKeyRef;return(l==null?void 0:l.id)!==(i==null?void 0:i.id)&&(this.foreignKeyRef=i,r==null||r.add(this,W.Affected)),r==null||r.attemptAutoclose(V.SetDataTypeForeignKeyRef,this.id),this}setEntity(i,r=this.project.addChangeSet(new H(this.project,L.sessionAuthor,B().toISOString(),this,!0,V.SetDataTypeEntityValue))){var c;if(!this.checkCanEdit(this,r))return ae.warn(`[${V.SetDataTypeEntityValue}] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),r==null||r.attemptAutoclose(V.SetDataTypeEntityValue,this.id),this;const l=this.entity;return(l==null?void 0:l.id)!==(i==null?void 0:i.id)&&(this.entity=i,r==null||r.add(this,W.Affected),l&&l.type===o.DefinitionEntity&&((c=l.parent)==null?void 0:c.id)===this.id&&(l==null||l.remove({ignoreUpstream:!0},r))),r==null||r.attemptAutoclose(V.SetDataTypeEntityValue,this.id),this}isObject(){return!!this.entity&&(this.entity.type===o.DefinitionEntity||this.entity.type===o.BuiltInBaseEntity||this.entity.name===le.KeyValue)&&!this.isList}canBeObject(){var r;let i=!1;if(this.parent.type!==o.DataType&&this.parent.type!==o.ActionDescriptor&&this.parent.type!==o.BuiltInBaseEntity&&this.parent.type!==o.DefinitionEntity&&this.parent.type!==o.FunctionDeclaration){const l=(r=this.project.requestActiveDynamicValue(this.parent))==null?void 0:r.value;l?!l.valueAsType&&(l.value===""||l.value===null||o2t(l))&&(i=!0):i=!0}return(this.isObject()||!this.entity||this.entity.name===le.Untyped)&&i}hasStrictObjectStructure(){var i;return this.isObject()&&((i=this.entity)==null?void 0:i.type)===o.DefinitionEntity}isInlineDeclaredEntity(){var i,r;return((i=this.entity)==null?void 0:i.type)===o.DefinitionEntity&&((r=this.entity.parent)==null?void 0:r.id)===(this==null?void 0:this.id)}isIndependentlyUserDeclaredEntity(){var i,r;return((i=this.entity)==null?void 0:i.type)===o.DefinitionEntity&&((r=this.entity)==null?void 0:r.parent)!==this}canModifyObjectStructure(){var r;const i=this.isIndependentlyUserDeclaredEntity();return(this.isInlineDeclaredEntity()||this.canBeObject()||((r=this.entity)==null?void 0:r.name)===le.KeyValue)&&!i}inferFromInputs(i,r=this.project.addChangeSet(new H(this.project,L.sessionAuthor,B().toISOString(),this,!0,"infer-data-type-from-inputs"))){var v;const l=[],c=[],e=[],y=[];if(!this.inferred)return r==null||r.attemptAutoclose("infer-data-type-from-inputs",this.id),{updated:[],added:[],removed:[],affected:[],self:this};if(!this.entity&&i.length){const b=oe(this.parent,this.project)+" data type definition",A={id:L.UUID.uuid(),deletable:!0,editable:!0,type:o.DefinitionEntity,version:L.UUID.uuid(),createdAt:(r==null?void 0:r.timestamp)||B().toISOString(),author:L.sessionAuthor,previousVersion:null,deleted:!1,name:b,description:((v=this.parent)==null?void 0:v.description)||null,codeName:null,static:!0,abstract:!1,properties:[],methods:[],extends:null,implements:[],abstractMethods:[],allPropertiesImplement:null,additionalPropertiesDataType:null,additionalProperties:!0,x:0,y:0,parent:this.toReference()},E=me(A,this.project);E.hydrateAncestors(),E.setParent(this,r),E.initChildren(r),r==null||r.add(E,W.Added),E.metaSync(A,r),this.setEntity(E,r),r==null||r.add(this,W.Updated)}if(this.entity){const{updated:b,added:A,removed:E,affected:w}=this.entity.inferFromInputs(i,r);c.push(...b),l.push(...A),e.push(...E),y.push(...w)}return this.like||this.metaSync({like:!0},r),r==null||r.attemptAutoclose("infer-data-type-from-inputs",this.id),{updated:O(c),added:O(l),removed:O(e),affected:O(y),self:this}}};R(vi,"repository",{APICreate:async(i,...r)=>i,APIUpdate:async(i,...r)=>i,APIDelete:async(i,...r)=>i,APIClone:async(i,...r)=>{},APILoad:async(i,...r)=>null,APILoadVersion:async(i,r,...l)=>null}),R(vi,"type",o.DataType),R(vi,"USER_MANAGED_PARENT_TYPES",[o.Property,o.ArgumentDeclaration,o.ReturnStatement,o.BreakStatement,o.ContinueStatement,o.VariableDeclaration,o.ValueDescriptor,o.InputMap,o.OutputMap,o.DataType,o.FunctionDeclaration,o.ActionDescriptor,o.Loop,o.Search,o.DefinitionEntity]),R(vi,"PARENT_TYPES",[...vi.USER_MANAGED_PARENT_TYPES,o.BuiltInBaseEntity]),R(vi,"MUTABLE_BASE_PROPERTIES",["isList","asType","options","foreignKeyAllowed","parentRelationType","like","implementationChooseOne","staticEntities","interactiveEntities","actionEntities"]),R(vi,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","index","author","previousVersion"]),R(vi,"BASE_PROPERTIES",[...vi.MUTABLE_BASE_PROPERTIES,...vi.INMUTABLE_BASE_PROPERTIES]),R(vi,"MUTABLE_META_PROPERTIES",[...vi.MUTABLE_BASE_PROPERTIES,"inferred"]),R(vi,"INMUTABLE_META_PROPERTIES",[...vi.INMUTABLE_BASE_PROPERTIES]),R(vi,"META_PROPERTIES",[...vi.MUTABLE_META_PROPERTIES,...vi.INMUTABLE_META_PROPERTIES]),R(vi,"MUTABLE_UPSTREAM_PROPERTIES",["entity","foreignKeyRef","parent"]),R(vi,"INMUTABLE_UPSTREAM_PROPERTIES",[]),R(vi,"UPSTREAM_PROPERTIES",[...vi.MUTABLE_UPSTREAM_PROPERTIES,...vi.INMUTABLE_UPSTREAM_PROPERTIES]),R(vi,"MUTABLE_DOWNSTREAM_PROPERTIES",[]),R(vi,"INMUTABLE_DOWNSTREAM_PROPERTIES",["andChildrenGroup","orChildrenGroup"]),R(vi,"DOWNSTREAM_PROPERTIES",[...vi.MUTABLE_DOWNSTREAM_PROPERTIES,...vi.INMUTABLE_DOWNSTREAM_PROPERTIES]),R(vi,"PROPERTIES",[...vi.META_PROPERTIES,...vi.UPSTREAM_PROPERTIES,...vi.DOWNSTREAM_PROPERTIES]);let dn=vi;function mxe(d){var r;const p=d.implements.flatMap(l=>Txe(d,l));return(r=d.dataType)==null||r.validate(),[...p,...xc(d),...vxe(d)]}function Txe(d,p){const i=[];if(!d.implements)return i;if(!p.abstract){const l=Ut({id:`${d.id}--${be.PropertyImplementsNonAbstact}`,message:`Property "${oe(d,d.project)}" with id "${d.id}" implements a non-abstract property "${oe(p,d.project)}" with id "${p.id}".`,severity:ce.Error,code:be.PropertyImplementsNonAbstact,entity:d});i.push(l.error)}if(d.static&&!p.static){const l=Ut({id:`${d.id}--${be.NonStaticPropertyImplementsStatic}`,message:`Static property "${oe(d,d.project)}" with id "${d.id}" implements a non-static property "${oe(p,d.project)}" with id "${p.id}".`,severity:ce.Error,code:be.NonStaticPropertyImplementsStatic,entity:d});i.push(l.error)}if(!d.static&&p.static){const l=Ut({id:`${d.id}--${be.StaticPropertyImplementsNonStatic}`,message:`Non-static property "${oe(d,d.project)}" with id "${d.id}" implements a static property "${oe(p,d.project)}" with id "${p.id}".`,severity:ce.Error,code:be.StaticPropertyImplementsNonStatic,entity:d});i.push(l.error)}if(!Rr(d.dataType,p.dataType)){const l=Ut({id:`${d.id}--${be.PropertyImplementsIncompatibleType}`,message:`Property "${oe(d,d.project)}" with id "${d.id}" implements a property "${oe(p,d.project)}" with id "${p.id}" that has an incompatible data type.`,severity:ce.Error,code:be.PropertyImplementsIncompatibleType,entity:d});i.push(l.error)}return nn(d.errors,i)}function vxe(d,p){const r=[...d.parent.allProperties].filter(l=>{var c;return l.id!==d.id&&!d.implements.find(e=>e.id===l.id)&&l.id!==((c=d.extends)==null?void 0:c.id)});return xT(d,[Ji],r,p)}const d2t=Object.freeze(Object.defineProperty({__proto__:null,validate:mxe,validateImplementation:Txe,validatePropertyEntityName:vxe},Symbol.toStringTag,{value:"Module"}));function u2t(d,p){const i=[];if(d.parent){const l=p.get(d.parent);if(!l)i.push(new Oe({id:`${d.id}--${d.parent}--${re.ReferencedEntityNotFound}`,code:re.ReferencedEntityNotFound,severity:ce.Error,message:`Entity of type "${d.type}" with id "${d.id}", is referencing an entity with id "${d.parent}" that isn't yet found in the project. Perhaps it should be created first. Or perhaps the ID is incorrect.`}));else{const c=Op(l);if(c){const e=l!==c?`The entity of type '${d.type}' with id '${d.id}' have 'parent' with id '${d.parent}' because the entity belongs to a built-in '${c.type}' entity with id '${c.id}' (${oe(c,l.project)}) higher up in the tree.`:`The entity of type '${d.type}' with id '${d.id}' have 'parent' with id '${d.parent}' because it is a built-in entity of type ${c.type}.`;i.push(new Oe({id:`${d.id}--${re.InvalidBuiltInEntityReference}`,code:re.InvalidBuiltInEntityReference,severity:ce.Error,message:e}))}else if(![o.DefinitionEntity].includes(l.type))i.push(new Oe({id:`${d.id}--${d.parent}--${re.InvalidParentReference}`,code:re.InvalidParentReference,severity:ce.Error,message:`Entity of type "${d.type}" with id "${d.id}", has a parent reference that isn't pointing to an entity of type 'definition-entity'.`}));else{const y=Hr(l).filter(v=>!v.interactive);if(y.length){let v=y.length>1?`The entity of type '${d.type}' with id '${d.id}' can't be added to the 'parent' entity with id '${l.id}' because it extends or implements multiple '${o.BuiltInBaseEntity}' entities that are non-interactive ("${Dt(y.map(b=>oe(b,b.project)),'", "','" and "')}").`:`The entity of type '${d.type}' with id '${d.id}' can't be added to the 'parent' entity with id '${l.id}' because it extends or implements a '${o.BuiltInBaseEntity}' entity that is non-interactive ("${oe(y[0],y[0].project)}").`;v+=`
387
+ Alternatively you can update the entity with 'update' action. Or replace it by first removing it and then creating a new one.`}))}A===o.DataType&&(!l.parentRelationType||!(l.parentRelationType===Fe.AndDataTypeGroup||l.parentRelationType===Fe.OrDataTypeGroup))&&c.push(new Oe({id:`${i.id}--${re.InvalidParentRelationType}`,code:re.InvalidParentRelationType,severity:ce.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:c,modifiedData:l}}get isGroup(){const i=[...this.andChildrenGroup||[],...this.orChildrenGroup||[]];if(i.length>1){let r=0;for(const l of i)if(l.isResolved&&(r++,r>1))return!0}return!1}get isResolved(){return[o.BuiltInBaseEntity,o.ActionDescriptor].includes(this.parent.type)||Op(this.parent)?!0:!(!this.entity&&!this.isGroup&&!this.foreignKeyRef&&!this.foreignKeyAllowed)}validateGeneratedUpdate(i){return{errors:[],modifiedData:i}}subscribeDependents(i){return i.forEach(r=>{this.detachedDependents[r.entity.id]||(this.detachedDependents[r.entity.id]=r)}),this}unsubscribeDependents(i){return i.forEach(r=>{this.detachedDependents[r.entity.id]&&delete this.detachedDependents[r.entity.id]}),this}syncDependents(i=this.project.addChangeSet(new H(this.project,L.sessionAuthor,B().toISOString(),this,!0,"sync-dependents"))){const r=[],l=[],c=[],e=[];return Object.values(this.detachedDependents).forEach(y=>{const v=y.entity.afterAllChildrenInitialized(i);r.push(...v.updated),l.push(...v.added),c.push(...v.removed),e.push(...v.affected)}),i==null||i.attemptAutoclose("sync-dependents",this.id),{updated:O(r),added:O(l),removed:O(c),affected:O(e),self:this}}onDetachedDependencyRemoved(i,r,l){const c=[],e=[],y=[],v=[];return r==="entity-field"&&this.setEntity(null,l),r==="foreign-key-ref-field"&&this.setForeignKeyRef(null,l),{updated:O(c),added:O(e),removed:O(y),affected:O(v),self:this}}onDetachedDependencyRestored(i,r,l){const c=[],e=[],y=[],v=[];return r==="entity-field"&&this.setEntity(i,l),r==="foreign-key-ref-field"&&this.setForeignKeyRef(i,l),{updated:O(c),added:O(e),removed:O(y),affected:O(v),self:this}}unsubscribeFromDependencies(){var i,r,l,c;return(r=(i=this.entity)==null?void 0:i.unsubscribeDependents)==null||r.call(i,[{entity:this,field:"entity-field"}]),(c=(l=this.foreignKeyRef)==null?void 0:l.unsubscribeDependents)==null||c.call(l,[{entity:this,field:"foreign-key-ref-field"}]),this}subscribeToDependencies(){var i,r,l,c;return(r=(i=this.entity)==null?void 0:i.subscribeDependents)==null||r.call(i,[{entity:this,field:"entity-field"}]),(c=(l=this.foreignKeyRef)==null?void 0:l.subscribeDependents)==null||c.call(l,[{entity:this,field:"foreign-key-ref-field"}]),this}increaseVersion(i){if(i&&!B(i).isValid())throw new Error(`The shared timestamp '${i}' is not a valid ISO 8601 date string.`);return i&&B(i).isSame(B(this.createdAt))?this:(this.previousVersion=this.version,this.version=L.UUID.uuid(),this.createdAt=B(i).toISOString()||B().toISOString(),this)}captureVersion(){var r;const i=((r=this.knownVersions)==null?void 0:r.get(this.version))||new vi(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.foreignKeyRef=this.foreignKeyRef,i.andChildrenGroup=this.andChildrenGroup?[...this.andChildrenGroup]:this.andChildrenGroup,i.orChildrenGroup=this.orChildrenGroup?[...this.orChildrenGroup]:this.orChildrenGroup,i.parent=this.parent,this}recursiveCaptureUpstreamVersions(i){const r=[],l=[],c=[],e=[];if(this.parent&&this.parent.type!==o.BuiltInBaseEntity){this.parent.increaseVersion(i);const y=this.parent.recursiveCaptureUpstreamVersions(i);r.push(this.parent,...y.updated),l.push(...y.added),c.push(...y.removed)}return{updated:O(r),added:O(l),removed:O(c),affected:O(e),self:this}}async restoreVersion(i){var v;const r=[],l=[],c=[],e=[];if(this.version===i)return{updated:O(r),added:O(l),removed:O(c),affected:O(e),self:this};if(!this.knownVersions){const b=new Map;for(const[A,E]of this.knownVersions||new Map){if(b.set(A,E),E.activeVersion=!1,E.knownVersions)for(const[w,P]of E.knownVersions)b.set(w,P);E.knownVersions=null}}let y=(v=this.knownVersions)==null?void 0:v.get(i);if(!y){const b=await this.APILoadVersion({},i);if(!b)throw new Error(`Version with id '${i}' for entity with id '${this.id}' not found.`);y=new vi(b,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.foreignKeyRef=y.foreignKeyRef,this.andChildrenGroup=y.andChildrenGroup?[...y.andChildrenGroup]:null,this.orChildrenGroup=y.orChildrenGroup?[...y.orChildrenGroup]:null,this.parent=y.parent,{updated:O(r),added:O(l),removed:O(c),affected:O(e),self:this}}updateWithShallowTransfer(i,r=this.project.addChangeSet(new H(this.project,L.sessionAuthor,B().toISOString(),this,!0,V.UpdateWithShallowTransfer))){var l,c;if(!this.checkCanEdit(this,r))return ae.warn(`[updateWithShallowTransfer] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),r==null||r.attemptAutoclose(V.UpdateWithShallowTransfer,this.id),this;if(this.metaSync(i,r),this.version=i.version,this.createdAt=i.createdAt,this.author=i.author,this.deleted=i.deleted,this.previousVersion=i.previousVersion,this.unsubscribeFromDependencies(),i.parent){const e=ye(i.parent),y=this.project.get(e),v=this.parent;if(v&&v.id!==(y==null?void 0:y.id)&&this.removeFromParent(r),y)this.setParent(y,r),this.addSelfToProject(r);else throw r==null||r.attemptAutoclose(V.UpdateWithShallowTransfer,this.id),new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${e}' that isn't found in the project`)}else throw r==null||r.attemptAutoclose(V.UpdateWithShallowTransfer,this.id),new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(i.entity){const e=ye(i.entity),y=this.project.get(e);y&&(y.type===o.DefinitionEntity&&y.parent===this||this.setEntity(y,null))}if(i.foreignKeyRef){const e=ye(i.foreignKeyRef),y=this.project.get(e);y&&this.setForeignKeyRef(y,null)}return(l=i.andChildrenGroup)==null||l.forEach(e=>{const y=ye(e),v=this.project.get(y);v&&(this.addToAndGroup(v,r),v.setParent(this,r))}),[...this.andChildrenGroup||[]].forEach(e=>{var v;((v=i.andChildrenGroup)==null?void 0:v.find(b=>ye(b)===e.id))||(this.removeChildGroup(e,r),e.removeFromParent(r))}),(c=i.orChildrenGroup)==null||c.forEach(e=>{const y=ye(e),v=this.project.get(y);v&&(this.addToOrGroup(v,r),v.setParent(this,r))}),[...this.orChildrenGroup||[]].forEach(e=>{var v;((v=i.orChildrenGroup)==null?void 0:v.find(b=>ye(b)===e.id))||(this.removeChildGroup(e,r),e.removeFromParent(r))}),this.captureVersion(),this.subscribeToDependencies(),r==null||r.attemptAutoclose(V.UpdateWithShallowTransfer,this.id),this}hydrateAncestors(){const i=[],r=[],l=[],c=[];if(this.initialData.parent){const e=ye(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=ye(this.initialData.entity),y=this.project.get(e);y&&(y.type===o.DefinitionEntity&&y.parent===this||(this.setEntity(y,null),y.type!==o.BuiltInBaseEntity&&y.type!==o.PrimitiveEntity&&i.push(y)))}if(this.initialData.foreignKeyRef){const e=ye(this.initialData.foreignKeyRef),y=this.project.get(e);y&&this.setForeignKeyRef(y,null)}return{updated:O(i),added:O(r),removed:O(l),affected:O(c),self:this}}afterAllChildrenInitialized(i=this.project.addChangeSet(new H(this.project,L.sessionAuthor,B().toISOString(),this,!0,V.AfterAllChildrenInitialized))){var y,v,b;if(!this.checkCanEdit(this,i))return ae.warn(`[afterAllChildrenInitialized] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(V.AfterAllChildrenInitialized,this.id),{updated:[],added:[],removed:[],affected:[],self:this};const r=[],l=[],c=[],e=[];if(this.initialized=!0,((y=this.parent)==null?void 0:y.type)===o.DataType){let A=this.index||0;const E=(this.parentRelationType===Fe.AndDataTypeGroup?this.parent.andChildrenGroup||[]:this.parent.orChildrenGroup||[]).filter(P=>!P.deleted&&P.id!==this.id);E.length&&(A>E.length+1?A=E.length:A<0&&(A=0)),E.find(P=>(P.index||0)===A&&!P.deleted)&&E.filter(P=>(P.index||0)>=A&&!P.deleted).forEach(P=>{P.metaSync({index:(P.index||0)+1},i),i==null||i.add(P,W.Updated),r.push(P)}),this.metaSync({index:A},i)}return(v=this.andChildrenGroup)!=null&&v.length&&this.andChildrenGroup.sort((A,E)=>(A.index||0)-(E.index||0)),(b=this.orChildrenGroup)!=null&&b.length&&this.orChildrenGroup.sort((A,E)=>(A.index||0)-(E.index||0)),this.captureVersion(),i==null||i.attemptAutoclose(V.AfterAllChildrenInitialized,this.id),{updated:O(r),added:O(l),removed:O(c),affected:O(e),self:this}}addSelfToProject(i=this.project.addChangeSet(new H(this.project,L.sessionAuthor,B().toISOString(),this,!0,"add-self-to-project"))){const r=[this],l=[],c=[],e=[];return this.parent.type===o.DataType?(this.parentRelationType===Fe.AndDataTypeGroup?this.parent.addToAndGroup(this,i):this.parentRelationType===Fe.OrDataTypeGroup&&this.parent.addToOrGroup(this,i),e.push(this.parent)):this.parent.type===o.DefinitionEntity?(this.parent.setAdditionalPropertiesDataType(this,i),e.push(this.parent)):this.parent.type!==o.BuiltInBaseEntity&&this.parent.setDataType(this,i),this.subscribe(),this.subscribeToDependencies(),i==null||i.attemptAutoclose("add-self-to-project",this.id),{updated:O(r),added:O(l),removed:O(c),affected:O(e),self:this}}setParent(i,r=this.project.addChangeSet(new H(this.project,L.sessionAuthor,B().toISOString(),this,!0,V.SetParent))){var l;return this.checkCanEditWithCounterpartAndSideEffects(this,i,V.SetParent,r)?(((l=this.parent)==null?void 0:l.id)!==(i==null?void 0:i.id)&&(this.parent=i,r&&(r==null||r.add(this,W.Updated))),r==null||r.attemptAutoclose(V.SetParent,this.id),this):this}removeChildGroup(i,r=this.project.addChangeSet(new H(this.project,L.sessionAuthor,B().toISOString(),this,!0,V.RemoveChildGroup))){if(!this.checkCanEdit(this,r))return ae.warn(`[removeChildGroup] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),r==null||r.attemptAutoclose(V.RemoveChildGroup,this.id),this;if(this.andChildrenGroup){const l=this.andChildrenGroup.findIndex(c=>c.id===i.id);l!==-1&&(this.andChildrenGroup.splice(l,1),r==null||r.add(this,W.Updated))}if(this.orChildrenGroup){const l=this.orChildrenGroup.findIndex(c=>c.id===i.id);l!==-1&&(this.orChildrenGroup.splice(l,1),r==null||r.add(this,W.Updated))}return r==null||r.attemptAutoclose(V.RemoveChildGroup,this.id),this}initChildren(i=this.project.addChangeSet(new H(this.project,L.sessionAuthor,B().toISOString(),this,!0,"init-children"))){var r,l,c,e,y,v,b,A,E,w;if(this.initialized||this.startedInitialization)return this;if(this.startedInitialization=!0,this.initialData.entity)if(this.initialData.entity.type===o.GenericReference){const P=this.project.findSubscribedInstanceFromReference(this.initialData.entity);this.entity=P}else this.entity=me(this.initialData.entity,this.project),(((l=(r=this.initialData.entity)==null?void 0:r.parent)==null?void 0:l.id)===this.id||((e=(c=this.initialData.entity)==null?void 0:c.parent)==null?void 0:e.type)===o.GenericReference&&((v=(y=this.initialData.entity)==null?void 0:y.parent)==null?void 0:v.entityId)==this.id)&&this.entity.setParent(this,null),(A=(b=this.entity).initChildren)==null||A.call(b,i);if(this.initialData.foreignKeyRef)if(this.initialData.foreignKeyRef.type===o.GenericReference){const P=this.project.findSubscribedInstanceFromReference(this.initialData.foreignKeyRef);this.foreignKeyRef=P}else this.foreignKeyRef=me(this.initialData.foreignKeyRef,this.project),(w=(E=this.foreignKeyRef).initChildren)==null||w.call(E,i);return this.initialData.andChildrenGroup&&(this.andChildrenGroup=this.initialData.andChildrenGroup.map(P=>{const x=me(P,this.project);return x.setParent(this,null),x.initChildren(i),x})),this.initialData.orChildrenGroup&&(this.orChildrenGroup=this.initialData.orChildrenGroup.map(P=>{const x=me(P,this.project);return x.setParent(this,null),x.initChildren(i),x})),this.subscribeToDependencies(),this.afterAllChildrenInitialized(i),i==null||i.attemptAutoclose("init-children",this.id),this}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(i,r=this.project.addChangeSet(new H(this.project,L.sessionAuthor,B().toISOString(),this,!0,"meta-sync"))){const l=$n(this,i,r),c=Nn(this,l),e=this.toMeta();return this.options=l.options||e.options,this.parentRelationType=l.parentRelationType||e.parentRelationType,this.isList=l.isList!==void 0?l.isList:e.isList,this.inferred=l.inferred!==void 0?l.inferred:e.inferred,this.like=l.like!==void 0?l.like:e.like,this.asType=l.asType!==void 0?l.asType:e.asType,this.index=l.index!==void 0?l.index:e.index,this.implementationChooseOne=l.implementationChooseOne!==void 0?l.implementationChooseOne:e.implementationChooseOne,this.staticEntities=l.staticEntities!==void 0?l.staticEntities:e.staticEntities,this.interactiveEntities=l.interactiveEntities!==void 0?l.interactiveEntities:e.interactiveEntities,this.actionEntities=l.actionEntities!==void 0?l.actionEntities:e.actionEntities,super.baseMetaSync(l,this,r),l.deleted===!0&&!e.deleted?r==null||r.add(this,W.Removed):l.deleted===!1&&e.deleted?r==null||r.add(this,W.Added):c&&(r==null||r.add(this,W.Updated)),r==null||r.attemptAutoclose("meta-sync",this.id),this}async APILoad(i=Be,...r){return await vi.repository.APILoad(this.id,...r),this}async APICreate(i=Be,...r){return await vi.repository.APICreate(this.toShallowJSON(),...r),this}async APIUpdate(i=Be,...r){return await vi.repository.APIUpdate(this.toShallowJSON(),...r),this}async APIDelete(i=Be,...r){return await vi.repository.APIDelete(this.toShallowJSON(),...r),this}async APIClone(i=Be,...r){return await vi.repository.APIClone(this.id,...r),this}async APILoadVersion(i=Be,r,...l){return await vi.repository.APILoadVersion(this.id,r,...l)}removeFromParent(i=this.project.addChangeSet(new H(this.project,L.sessionAuthor,B().toISOString(),this,!0,V.RemoveFromParent))){var y,v;if(!this.checkCanEdit(this,i))return ae.warn(`[removeFromParent] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(V.RemoveFromParent,this.id),{added:[],updated:[],removed:[],affected:[],self:this};const r=[],l=[],c=[],e=[];if(((y=this.parent)==null?void 0:y.type)===o.DataType)this.parent.removeChildGroup(this,i);else if(((v=this.parent)==null?void 0:v.type)===o.DefinitionEntity)this.parent.removeAdditionalPropertiesDataType(i);else{const b=this.parent;b==null||b.removeDataType(i)}return this.parent&&this.parent.type!==o.BuiltInBaseEntity&&r.push(this.parent),i==null||i.attemptAutoclose(V.RemoveFromParent,this.id),{added:O(c),updated:O(r),removed:O(l),affected:O(e),self:this}}remove({ignoreUpstream:i}={ignoreUpstream:!1},r=this.project.addChangeSet(new H(this.project,L.sessionAuthor,B().toISOString(),this,!0,V.RemoveEntity))){const l=[],c=[],e=[],y=[];if(r!=null&&r.hasRemoved(this.id))return r==null||r.attemptAutoclose(V.RemoveEntity,this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(c.push(this),this.unsubscribe(),this.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},r),Object.values(this.detachedDependents).forEach(v=>{const{updated:b,removed:A,added:E}=v.entity.onDetachedDependencyRemoved(this,v.field,r);l.push(...b),c.push(...A),e.push(...E)}),this.entity&&this.entity.type===o.DefinitionEntity&&this.entity.parent===this){const{updated:v,removed:b}=this.entity.remove({ignoreUpstream:!0},r);l.push(...v),c.push(...b)}if(this.andChildrenGroup&&this.andChildrenGroup.forEach(v=>{const{removed:b,updated:A}=v.remove({ignoreUpstream:!0},r);c.push(...b),l.push(...A)}),this.orChildrenGroup&&this.orChildrenGroup.forEach(v=>{const{removed:b,updated:A}=v.remove({ignoreUpstream:!0},r);c.push(...b),l.push(...A)}),!i){const v=this.removeFromParent(r);e.push(...v.added),l.push(...v.updated),c.push(...v.removed),y.push(...v.affected)}return r==null||r.attemptAutoclose(V.RemoveEntity,this.id),{added:O(e),updated:O(l),removed:O(c),affected:O(y),self:this}}restore({}={},i=this.project.addChangeSet(new H(this.project,L.sessionAuthor,B().toISOString(),this,!0,V.RestoreEntity))){if(!this.checkCanEdit(this,i))return ae.warn(`[restore] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(V.RestoreEntity,this.id),{added:[],updated:[],removed:[],affected:[],self:this};const r=[],l=[],c=[],e=[];if(i!=null&&i.hasAdded(this.id))return i==null||i.attemptAutoclose(V.RestoreEntity,this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},i),Object.values(this.detachedDependents).forEach(y=>{const{updated:v,removed:b,added:A}=y.entity.onDetachedDependencyRestored(this,y.field,i);l.push(...v),c.push(...b),r.push(...A)}),this.entity&&this.entity.type===o.DefinitionEntity&&this.entity.parent===this){const{updated:y}=this.entity.restore({},i);l.push(...y)}if(this.andChildrenGroup&&this.andChildrenGroup.forEach(y=>{const{updated:v,added:b}=y.restore({},i);l.push(...v),r.push(...b)}),this.orChildrenGroup&&this.orChildrenGroup.forEach(y=>{const{updated:v,added:b}=y.restore({},i);l.push(...v),r.push(...b)}),this.parent.type===o.DataType){const y=this.parent;Array.isArray(y.andChildrenGroup)&&y.andChildrenGroup.push(this)}if(this.parent.type===o.DataType){const y=this.parent;this.parentRelationType===Fe.AndDataTypeGroup?Array.isArray(y.andChildrenGroup)&&y.andChildrenGroup.push(this):this.parentRelationType===Fe.OrDataTypeGroup&&Array.isArray(y.orChildrenGroup)&&y.orChildrenGroup.push(this)}else if(this.parent.type===o.DefinitionEntity){const y=this.parent;y.setAdditionalPropertiesDataType(this,i),l.push(y)}else{const y=this.parent;y.setDataType(this,i),l.push(y)}return i==null||i.attemptAutoclose(V.RestoreEntity,this.id),{added:O(r),updated:O(l),removed:O(c),affected:O(e),self:this}}toFlat(i=new Set){var l,c,e,y;return i.has(this.id)?[]:(i.add(this.id),[this,...((l=this.andChildrenGroup)==null?void 0:l.flatMap(v=>v.toFlat(i)))||[],...((c=this.orChildrenGroup)==null?void 0:c.flatMap(v=>v.toFlat(i)))||[],...((e=this.entity)==null?void 0:e.toFlat(i))||[],...((y=this.foreignKeyRef)==null?void 0:y.toFlat(i))||[]])}toFlatIds(i=new Set){var l,c,e,y;return i.has(this.id)?[]:(i.add(this.id),[this.id,...((l=this.andChildrenGroup)==null?void 0:l.flatMap(v=>v.toFlatIds(i)))||[],...((c=this.orChildrenGroup)==null?void 0:c.flatMap(v=>v.toFlatIds(i)))||[],...((e=this.entity)==null?void 0:e.toFlatIds(i))||[],...((y=this.foreignKeyRef)==null?void 0:y.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,foreignKeyAllowed:this.foreignKeyAllowed,parentRelationType:this.parentRelationType,implementationChooseOne:this.implementationChooseOne,staticEntities:this.staticEntities,interactiveEntities:this.interactiveEntities,actionEntities:this.actionEntities,options:this.options,asType:this.asType,type:this.type,editable:this.editable,deletable:this.deletable}}toJSON(i=new Set){var r,l,c,e,y;return i.has(this.id)?this.toReference():(i.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,editable:this.editable,deletable:this.deletable,options:this.options,isList:this.isList,asType:this.asType,index:this.index,like:this.like,foreignKeyAllowed:this.foreignKeyAllowed,inferred:this.inferred,parentRelationType:this.parentRelationType,implementationChooseOne:this.implementationChooseOne,staticEntities:this.staticEntities,interactiveEntities:this.interactiveEntities,actionEntities:this.actionEntities,foreignKeyRef:((r=this.foreignKeyRef)==null?void 0:r.toJSON(i))||null,andChildrenGroup:((l=this.andChildrenGroup)==null?void 0:l.map(v=>v.toJSON(i)))||null,orChildrenGroup:((c=this.orChildrenGroup)==null?void 0:c.map(v=>v.toJSON(i)))||null,entity:((e=this.entity)==null?void 0:e.parent)===this?this.entity.toJSON(i):((y=this.entity)==null?void 0:y.toReference())||null,parent:this.parent.toReference()})}toJSONClone(i=dt){var l,c,e,y,v,b,A,E,w,P;let r;return(l=i.seenEntityMaps)!=null&&l.has(this.id)?r=i.seenEntityMaps.get(this.id):(r=i.newId||jn(this,this.project,i.uuidStrategy),i.seenEntityMaps&&i.seenEntityMaps.set(this.id,r)),(c=i.seenEntities)!=null&&c.has(r)||(e=i.seenEntities)!=null&&e.has(this.id)?this.toReference({seenEntityMaps:i.seenEntityMaps}):((y=i.seenEntities)==null||y.add(r),(v=i.seenEntities)==null||v.add(this.id),{id:r,version:L.UUID.uuid(),createdAt:i.timestamp||B().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,editable:this.editable,deletable:this.deletable,options:this.options,isList:this.isList,asType:this.asType,like:this.like,index:this.index,inferred:this.inferred,foreignKeyAllowed:this.foreignKeyAllowed,parentRelationType:this.parentRelationType,implementationChooseOne:this.implementationChooseOne,staticEntities:this.staticEntities,interactiveEntities:this.interactiveEntities,actionEntities:this.actionEntities,foreignKeyRef:((b=this.foreignKeyRef)==null?void 0:b.toJSONClone({...i,newId:null}))||null,andChildrenGroup:((A=this.andChildrenGroup)==null?void 0:A.map(x=>x.toJSONClone({...i,newId:null})))||null,orChildrenGroup:((E=this.orChildrenGroup)==null?void 0:E.map(x=>x.toJSONClone({...i,newId:null})))||null,entity:((w=this.entity)==null?void 0:w.parent)===this?this.entity.toJSONClone({...i,newId:null}):((P=this.entity)==null?void 0:P.toReference({seenEntityMaps:i.seenEntityMaps}))||null,parent:this.parent.toReference({seenEntityMaps:i.seenEntityMaps})})}toReference(i=dt){var l;let r=this.id;return(l=i.seenEntityMaps)!=null&&l.has(this.id)&&(r=i.seenEntityMaps.get(this.id)),{id:r+"--"+L.UUID.uuid()+"--ref",type:o.GenericReference,entityId:r,version:this.version,entityType:this.type}}toShallowJSON(i=dt){var l,c,e,y,v;let r=this.id;return(l=i.seenEntityMaps)!=null&&l.has(this.id)&&(r=i.seenEntityMaps.get(this.id)),{id:r,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,editable:this.editable,deletable:this.deletable,isList:this.isList,options:this.options,asType:this.asType,index:this.index,parentRelationType:this.parentRelationType,like:this.like,inferred:this.inferred,foreignKeyAllowed:this.foreignKeyAllowed,implementationChooseOne:this.implementationChooseOne,staticEntities:this.staticEntities,interactiveEntities:this.interactiveEntities,actionEntities:this.actionEntities,foreignKeyRef:((c=this.foreignKeyRef)==null?void 0:c.toReference(i))||null,andChildrenGroup:((e=this.andChildrenGroup)==null?void 0:e.map(b=>b.toReference(i)))||null,orChildrenGroup:((y=this.orChildrenGroup)==null?void 0:y.map(b=>b.toReference(i)))||null,entity:((v=this.entity)==null?void 0:v.toReference(i))||null,parent:this.parent.toReference(i)}}toFlatJSON(i=new Set){var l,c,e;return i.has(this.id)?[]:(i.add(this.id),[this.toShallowJSON(),...((l=this.andChildrenGroup)==null?void 0:l.flatMap(y=>y.toFlatJSON(i)))||[],...((c=this.orChildrenGroup)==null?void 0:c.flatMap(y=>y.toFlatJSON(i)))||[],...((e=this.entity)==null?void 0:e.toFlatJSON(i))||[]])}toGenerationTarget(){var i,r;return{id:this.id,type:this.type,options:this.options||void 0,isList:this.isList,like:this.like,parentRelationType:this.parentRelationType||void 0,foreignKeyRef:((i=this.foreignKeyRef)==null?void 0:i.id)||null,asType:this.asType,entity:((r=this.entity)==null?void 0:r.id)||null,parent:this.parent.id}}toFlatGenerationTarget(i=new Set){var l,c;return i.has(this.id)?[]:(i.add(this.id),[this.toGenerationTarget(),...((l=this.andChildrenGroup)==null?void 0:l.flatMap(e=>e.toFlatGenerationTarget(i)))||[],...((c=this.orChildrenGroup)==null?void 0:c.flatMap(e=>e.toFlatGenerationTarget(i)))||[],...this.entity&&this.entity.type==o.DefinitionEntity&&this.entity.parent===this&&this.entity.toFlatGenerationTarget(i)||[]])}clearErrors(){var i,r,l,c;return this.errors=[],(i=this.andChildrenGroup)==null||i.forEach(e=>e.clearErrors()),(r=this.orChildrenGroup)==null||r.forEach(e=>e.clearErrors()),this.inferred&&this.entity&&this.entity.type===o.DefinitionEntity&&((l=this.entity)==null?void 0:l.parent)===this&&((c=this.entity)==null||c.clearErrors()),this}validate(){const i=hxe(this);return this.errors=i,{success:!0}}getErrors(){return[...this.errors]}getShallowErrors(){return this.errors}clone(i=this.project.addChangeSet(new H(this.project,L.sessionAuthor,B().toISOString(),this,!0,V.CloneEntity)),r=null,l=null,c=!0){var x,M,k,q;const e=Vn(r,this),y=r||this.parent,v=l||L.UUID.uuid(),b=new Set([...this.project.getAllBuiltInIds(),...rn()]),A={id:v,version:L.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||B().toISOString(),author:(i==null?void 0:i.author)||"1",previousVersion:null,deleted:!1,deletable:!0,editable:!0,type:o.DataType,isList:this.isList,asType:this.asType,options:this.options,index:this.index,parentRelationType:this.parentRelationType,staticEntities:this.staticEntities,foreignKeyAllowed:this.foreignKeyAllowed,interactiveEntities:this.interactiveEntities,actionEntities:this.actionEntities,like:this.like,inferred:this.inferred,implementationChooseOne:this.implementationChooseOne,foreignKeyRef:((x=this.foreignKeyRef)==null?void 0:x.toReference())||null,andChildrenGroup:null,orChildrenGroup:null,entity:null,parent:y.toReference()},E=Ui(A,e);E.hydrateAncestors(),E.setParent(y,null),c&&(E.subscribe(),E.addSelfToProject(i)),E.initChildren(i),i==null||i.add(E,W.Added);const w=(M=this.andChildrenGroup)==null?void 0:M.map(Z=>b.has(Z.id)?e.getBuiltIn(Z.id):Z.clone(i,E,L.UUID.uuid(),c)),P=(k=this.orChildrenGroup)==null?void 0:k.map(Z=>b.has(Z.id)?e.getBuiltIn(Z.id):Z.clone(i,E,L.UUID.uuid(),c));if(E.andChildrenGroup=w||null,E.orChildrenGroup=P||null,this.entity&&this.entity.type===o.DefinitionEntity&&((q=this.entity)==null?void 0:q.parent)===this)if(b.has(this.entity.id))E.setEntity(e.getBuiltIn(this.entity.id),i);else{const Z=this.entity.clone(i,E,L.UUID.uuid(),c);E.setEntity(Z,i)}else if(this.entity){const Z=e.get(this.entity.id)||e.getBuiltIn(this.entity.id);E.setEntity(Z,i)}return i==null||i.attemptAutoclose(V.CloneEntity,this.id),E}merge(i,r=this.project.addChangeSet(new H(this.project,L.sessionAuthor,B().toISOString(),this,!0,V.MergeDataTypes))){var v,b,A;const l=[],c=[],e=[],y=[];if(!this.checkCanEdit(this,r))return ae.warn(`[${V.MergeDataTypes}] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),r==null||r.attemptAutoclose(V.MergeDataTypes,this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.asType!==(i==null?void 0:i.asType)&&(this.metaSync({asType:i==null?void 0:i.asType},r),r==null||r.add(this,W.Updated),l.push(this)),this.index!==(i==null?void 0:i.index)&&(this.metaSync({index:i==null?void 0:i.index},r),r==null||r.add(this,W.Updated),l.push(this)),this.foreignKeyAllowed!==(i==null?void 0:i.foreignKeyAllowed)&&(this.metaSync({foreignKeyAllowed:i==null?void 0:i.foreignKeyAllowed},r),r==null||r.add(this,W.Updated),l.push(this)),this.isList!==(i==null?void 0:i.isList)&&(this.metaSync({isList:i==null?void 0:i.isList},r),r==null||r.add(this,W.Updated),l.push(this)),this.like!==(i==null?void 0:i.like)&&(this.metaSync({like:i==null?void 0:i.like},r),r==null||r.add(this,W.Updated),l.push(this)),((v=i==null?void 0:i.foreignKeyRef)==null?void 0:v.id)!==((b=this.foreignKeyRef)==null?void 0:b.id)&&(this.setForeignKeyRef((i==null?void 0:i.foreignKeyRef)||null,r),r==null||r.add(this,W.Updated),l.push(this)),i!=null&&i.entity&&(i==null?void 0:i.entity.type)===o.DefinitionEntity&&(i==null?void 0:i.entity).parent===i)if(((A=this.entity)==null?void 0:A.type)===o.DefinitionEntity&&this.entity.parent===this)f_(this.entity,i.entity)||d$e(this.entity,i.entity,r);else{const E=i.entity.clone(r,this,L.UUID.uuid(),!0);this.setEntity(E,r),c.push(E)}else i!=null&&i.entity&&(this.setEntity(i==null?void 0:i.entity,r),r==null||r.add(this,W.Updated),l.push(this));return this.inferred!==(i==null?void 0:i.inferred)&&this.metaSync({inferred:(i==null?void 0:i.inferred)??!1},r),r==null||r.attemptAutoclose(V.MergeDataTypes,this.id),{updated:O(l),added:O(c),removed:O(e),affected:O(y),self:this}}addToAndGroup(i,r=this.project.addChangeSet(new H(this.project,L.sessionAuthor,B().toISOString(),this,!0,V.AddToAndGroup))){return this.checkCanEdit(this,r)?(this.andChildrenGroup||(this.andChildrenGroup=[]),this.andChildrenGroup.includes(i)||(this.andChildrenGroup.push(i),r==null||r.add(i,W.Affected)),r==null||r.attemptAutoclose(V.AddToAndGroup,this.id),this):(ae.warn(`[${V.AddToAndGroup}] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),r==null||r.attemptAutoclose(V.AddToAndGroup,this.id),this)}addToOrGroup(i,r=this.project.addChangeSet(new H(this.project,L.sessionAuthor,B().toISOString(),this,!0,V.AddToOrGroup))){return this.checkCanEdit(this,r)?(this.orChildrenGroup||(this.orChildrenGroup=[]),this.orChildrenGroup.includes(i)||(this.orChildrenGroup.push(i),r==null||r.add(i,W.Affected)),r==null||r.attemptAutoclose(V.AddToOrGroup,this.id),this):(ae.warn(`[${V.AddToOrGroup}] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),r==null||r.attemptAutoclose(V.AddToOrGroup,this.id),this)}setForeignKeyRef(i,r=this.project.addChangeSet(new H(this.project,L.sessionAuthor,B().toISOString(),this,!0,V.SetDataTypeForeignKeyRef))){if(!this.checkCanEdit(this,r))return ae.warn(`[${V.SetDataTypeForeignKeyRef}] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),r==null||r.attemptAutoclose(V.SetDataTypeForeignKeyRef,this.id),this;const l=this.foreignKeyRef;return(l==null?void 0:l.id)!==(i==null?void 0:i.id)&&(this.foreignKeyRef=i,r==null||r.add(this,W.Updated)),r==null||r.attemptAutoclose(V.SetDataTypeForeignKeyRef,this.id),this}setEntity(i,r=this.project.addChangeSet(new H(this.project,L.sessionAuthor,B().toISOString(),this,!0,V.SetDataTypeEntityValue))){var c;if(!this.checkCanEdit(this,r))return ae.warn(`[${V.SetDataTypeEntityValue}] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),r==null||r.attemptAutoclose(V.SetDataTypeEntityValue,this.id),this;const l=this.entity;return(l==null?void 0:l.id)!==(i==null?void 0:i.id)&&(this.entity=i,r==null||r.add(this,W.Affected),l&&l.type===o.DefinitionEntity&&((c=l.parent)==null?void 0:c.id)===this.id&&(l==null||l.remove({ignoreUpstream:!0},r))),r==null||r.attemptAutoclose(V.SetDataTypeEntityValue,this.id),this}isObject(){return!!this.entity&&(this.entity.type===o.DefinitionEntity||this.entity.type===o.BuiltInBaseEntity||this.entity.name===le.KeyValue)&&!this.isList}canBeObject(){var r;let i=!1;if(this.parent.type!==o.DataType&&this.parent.type!==o.ActionDescriptor&&this.parent.type!==o.BuiltInBaseEntity&&this.parent.type!==o.DefinitionEntity&&this.parent.type!==o.FunctionDeclaration){const l=(r=this.project.requestActiveDynamicValue(this.parent))==null?void 0:r.value;l?!l.valueAsType&&(l.value===""||l.value===null||o2t(l))&&(i=!0):i=!0}return(this.isObject()||!this.entity||this.entity.name===le.Untyped)&&i}hasStrictObjectStructure(){var i;return this.isObject()&&((i=this.entity)==null?void 0:i.type)===o.DefinitionEntity}isInlineDeclaredEntity(){var i,r;return((i=this.entity)==null?void 0:i.type)===o.DefinitionEntity&&((r=this.entity.parent)==null?void 0:r.id)===(this==null?void 0:this.id)}isIndependentlyUserDeclaredEntity(){var i,r;return((i=this.entity)==null?void 0:i.type)===o.DefinitionEntity&&((r=this.entity)==null?void 0:r.parent)!==this}canModifyObjectStructure(){var r;const i=this.isIndependentlyUserDeclaredEntity();return(this.isInlineDeclaredEntity()||this.canBeObject()||((r=this.entity)==null?void 0:r.name)===le.KeyValue)&&!i}inferFromInputs(i,r=this.project.addChangeSet(new H(this.project,L.sessionAuthor,B().toISOString(),this,!0,"infer-data-type-from-inputs"))){var v;const l=[],c=[],e=[],y=[];if(!this.inferred)return r==null||r.attemptAutoclose("infer-data-type-from-inputs",this.id),{updated:[],added:[],removed:[],affected:[],self:this};if(!this.entity&&i.length){const b=oe(this.parent,this.project)+" data type definition",A={id:L.UUID.uuid(),deletable:!0,editable:!0,type:o.DefinitionEntity,version:L.UUID.uuid(),createdAt:(r==null?void 0:r.timestamp)||B().toISOString(),author:L.sessionAuthor,previousVersion:null,deleted:!1,name:b,description:((v=this.parent)==null?void 0:v.description)||null,codeName:null,static:!0,abstract:!1,properties:[],methods:[],extends:null,implements:[],abstractMethods:[],allPropertiesImplement:null,additionalPropertiesDataType:null,additionalProperties:!0,x:0,y:0,parent:this.toReference()},E=me(A,this.project);E.hydrateAncestors(),E.setParent(this,r),E.initChildren(r),r==null||r.add(E,W.Added),E.metaSync(A,r),this.setEntity(E,r),r==null||r.add(this,W.Updated)}if(this.entity){const{updated:b,added:A,removed:E,affected:w}=this.entity.inferFromInputs(i,r);c.push(...b),l.push(...A),e.push(...E),y.push(...w)}return this.like||this.metaSync({like:!0},r),r==null||r.attemptAutoclose("infer-data-type-from-inputs",this.id),{updated:O(c),added:O(l),removed:O(e),affected:O(y),self:this}}};R(vi,"repository",{APICreate:async(i,...r)=>i,APIUpdate:async(i,...r)=>i,APIDelete:async(i,...r)=>i,APIClone:async(i,...r)=>{},APILoad:async(i,...r)=>null,APILoadVersion:async(i,r,...l)=>null}),R(vi,"type",o.DataType),R(vi,"USER_MANAGED_PARENT_TYPES",[o.Property,o.ArgumentDeclaration,o.ReturnStatement,o.BreakStatement,o.ContinueStatement,o.VariableDeclaration,o.ValueDescriptor,o.InputMap,o.OutputMap,o.DataType,o.FunctionDeclaration,o.ActionDescriptor,o.Loop,o.Search,o.DefinitionEntity]),R(vi,"PARENT_TYPES",[...vi.USER_MANAGED_PARENT_TYPES,o.BuiltInBaseEntity]),R(vi,"MUTABLE_BASE_PROPERTIES",["isList","asType","options","foreignKeyAllowed","parentRelationType","like","implementationChooseOne","staticEntities","interactiveEntities","actionEntities"]),R(vi,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","index","author","previousVersion"]),R(vi,"BASE_PROPERTIES",[...vi.MUTABLE_BASE_PROPERTIES,...vi.INMUTABLE_BASE_PROPERTIES]),R(vi,"MUTABLE_META_PROPERTIES",[...vi.MUTABLE_BASE_PROPERTIES,"inferred"]),R(vi,"INMUTABLE_META_PROPERTIES",[...vi.INMUTABLE_BASE_PROPERTIES]),R(vi,"META_PROPERTIES",[...vi.MUTABLE_META_PROPERTIES,...vi.INMUTABLE_META_PROPERTIES]),R(vi,"MUTABLE_UPSTREAM_PROPERTIES",["entity","foreignKeyRef","parent"]),R(vi,"INMUTABLE_UPSTREAM_PROPERTIES",[]),R(vi,"UPSTREAM_PROPERTIES",[...vi.MUTABLE_UPSTREAM_PROPERTIES,...vi.INMUTABLE_UPSTREAM_PROPERTIES]),R(vi,"MUTABLE_DOWNSTREAM_PROPERTIES",[]),R(vi,"INMUTABLE_DOWNSTREAM_PROPERTIES",["andChildrenGroup","orChildrenGroup"]),R(vi,"DOWNSTREAM_PROPERTIES",[...vi.MUTABLE_DOWNSTREAM_PROPERTIES,...vi.INMUTABLE_DOWNSTREAM_PROPERTIES]),R(vi,"PROPERTIES",[...vi.META_PROPERTIES,...vi.UPSTREAM_PROPERTIES,...vi.DOWNSTREAM_PROPERTIES]);let dn=vi;function mxe(d){var r;const p=d.implements.flatMap(l=>Txe(d,l));return(r=d.dataType)==null||r.validate(),[...p,...xc(d),...vxe(d)]}function Txe(d,p){const i=[];if(!d.implements)return i;if(!p.abstract){const l=Ut({id:`${d.id}--${be.PropertyImplementsNonAbstact}`,message:`Property "${oe(d,d.project)}" with id "${d.id}" implements a non-abstract property "${oe(p,d.project)}" with id "${p.id}".`,severity:ce.Error,code:be.PropertyImplementsNonAbstact,entity:d});i.push(l.error)}if(d.static&&!p.static){const l=Ut({id:`${d.id}--${be.NonStaticPropertyImplementsStatic}`,message:`Static property "${oe(d,d.project)}" with id "${d.id}" implements a non-static property "${oe(p,d.project)}" with id "${p.id}".`,severity:ce.Error,code:be.NonStaticPropertyImplementsStatic,entity:d});i.push(l.error)}if(!d.static&&p.static){const l=Ut({id:`${d.id}--${be.StaticPropertyImplementsNonStatic}`,message:`Non-static property "${oe(d,d.project)}" with id "${d.id}" implements a static property "${oe(p,d.project)}" with id "${p.id}".`,severity:ce.Error,code:be.StaticPropertyImplementsNonStatic,entity:d});i.push(l.error)}if(!Rr(d.dataType,p.dataType)){const l=Ut({id:`${d.id}--${be.PropertyImplementsIncompatibleType}`,message:`Property "${oe(d,d.project)}" with id "${d.id}" implements a property "${oe(p,d.project)}" with id "${p.id}" that has an incompatible data type.`,severity:ce.Error,code:be.PropertyImplementsIncompatibleType,entity:d});i.push(l.error)}return nn(d.errors,i)}function vxe(d,p){const r=[...d.parent.allProperties].filter(l=>{var c;return l.id!==d.id&&!d.implements.find(e=>e.id===l.id)&&l.id!==((c=d.extends)==null?void 0:c.id)});return xT(d,[Ji],r,p)}const d2t=Object.freeze(Object.defineProperty({__proto__:null,validate:mxe,validateImplementation:Txe,validatePropertyEntityName:vxe},Symbol.toStringTag,{value:"Module"}));function u2t(d,p){const i=[];if(d.parent){const l=p.get(d.parent);if(!l)i.push(new Oe({id:`${d.id}--${d.parent}--${re.ReferencedEntityNotFound}`,code:re.ReferencedEntityNotFound,severity:ce.Error,message:`Entity of type "${d.type}" with id "${d.id}", is referencing an entity with id "${d.parent}" that isn't yet found in the project. Perhaps it should be created first. Or perhaps the ID is incorrect.`}));else{const c=Op(l);if(c){const e=l!==c?`The entity of type '${d.type}' with id '${d.id}' have 'parent' with id '${d.parent}' because the entity belongs to a built-in '${c.type}' entity with id '${c.id}' (${oe(c,l.project)}) higher up in the tree.`:`The entity of type '${d.type}' with id '${d.id}' have 'parent' with id '${d.parent}' because it is a built-in entity of type ${c.type}.`;i.push(new Oe({id:`${d.id}--${re.InvalidBuiltInEntityReference}`,code:re.InvalidBuiltInEntityReference,severity:ce.Error,message:e}))}else if(![o.DefinitionEntity].includes(l.type))i.push(new Oe({id:`${d.id}--${d.parent}--${re.InvalidParentReference}`,code:re.InvalidParentReference,severity:ce.Error,message:`Entity of type "${d.type}" with id "${d.id}", has a parent reference that isn't pointing to an entity of type 'definition-entity'.`}));else{const y=Hr(l).filter(v=>!v.interactive);if(y.length){let v=y.length>1?`The entity of type '${d.type}' with id '${d.id}' can't be added to the 'parent' entity with id '${l.id}' because it extends or implements multiple '${o.BuiltInBaseEntity}' entities that are non-interactive ("${Dt(y.map(b=>oe(b,b.project)),'", "','" and "')}").`:`The entity of type '${d.type}' with id '${d.id}' can't be added to the 'parent' entity with id '${l.id}' because it extends or implements a '${o.BuiltInBaseEntity}' entity that is non-interactive ("${oe(y[0],y[0].project)}").`;v+=`
388
388
  ${Ap}`,i.push(new Oe({id:`${d.id}--${re.NonInteractiveEntityReferenced}`,code:re.NonInteractiveEntityReferenced,severity:ce.Error,message:v}))}else d.implements&&d.implements.forEach(v=>{const b=p.get(v);if(v===d.id)return i.push(new Oe({id:`${d.id}--${d.implements}--${re.SelfReference}`,code:re.SelfReference,severity:ce.Error,message:`Entity of type "${d.type}" with id "${d.id}", has a reference to itself at 'implements'. This is not allowed. Change the reference string or the 'entityId' property of the reference object.`})),i;if(!b)i.push(new Oe({id:`${d.id}--${d.implements}--${re.ReferencedEntityNotFound}`,code:re.ReferencedEntityNotFound,severity:ce.Error,message:`Entity of type "${d.type}" with id "${d.id}", is referencing an entity with id "${d.implements}" that isn't yet found in the project. Perhaps it should be created first. Or perhaps the ID is incorrect.`}));else{const A=l.properties.find(E=>E.implements.find(w=>{var P;return(P=d.implements)==null?void 0:P.includes(w.id)}));A?i.push(new Oe({id:`${d.id}--${Re.PropertyOverwritesOtherSiblingWithSameImplementation}`,code:Re.PropertyOverwritesOtherSiblingWithSameImplementation,severity:ce.Error,message:`The property with id "${d.id}" is trying to implement the property with id "${d.implements}", but the parent entity already has a property with id '${A.id}' that implements the same base property.`})):[o.Property].includes(b.type)?b.abstract||i.push(new Oe({id:`${d.id}--${d.implements}--${re.InvalidImplementsReference}`,code:re.InvalidImplementsReference,severity:ce.Error,message:`Entity of type "${d.type}" with id "${d.id}", has an 'implements' reference that isn't pointing to an abstract entity.`})):i.push(new Oe({id:`${d.id}--${d.implements}--${re.InvalidImplementsReference}`,code:re.InvalidImplementsReference,severity:ce.Error,message:`Entity of type "${d.type}" with id "${d.id}", has an 'implements' reference that isn't pointing to an entity of type 'property'.`}))}})}}}const r=hr(d,{},p);return i.push(...r.errors),i}function bxe(d,p){const i=[],r=[],l=[],c=[];if(d.implements.find(e=>e.id===Q["built-in-base-entity"].BUILT_IN_PERSISTED_ENTITY_ENTITY.properties.database.id)){let e=d.defaultValue;if(!d.defaultValue){const y=Xn.new(p);y.name=le.EntityTemplate,y.parent=d.toReference();const v=me(y,d.project);v.hydrateAncestors(),v.addSelfToProject(p),p==null||p.add(v,W.Added),r.push(v),v.initChildren(p),e=v}if(!e.valueAsTypeSingle){const y=axe(d.project);y&&e.setValueAsTypeSingle(y,p)}}return{updated:O(i),added:O(r),removed:O(l),affected:O(c),self:d}}var Exe=(d=>(d.PropertyImplements="property-implements-field",d.PropertyExtends="property-extends-field",d.PropertyDataTypeEntity="property-data-type-entity-field",d.PropertyDataType="property-data-type-field",d))(Exe||{});const ii=class ii extends Un{constructor(i,r){super(i);R(this,"initialData");R(this,"id");R(this,"name");R(this,"codeName",null);R(this,"description",null);R(this,"private");R(this,"abstract");R(this,"index");R(this,"static");R(this,"unique");R(this,"required");R(this,"constant",!1);R(this,"interactive",!1);R(this,"type",o.Property);R(this,"hidden",!1);R(this,"parentRelationType",null);R(this,"defaultValue",null);R(this,"dataType",null);R(this,"implements",[]);R(this,"extends",null);R(this,"project");R(this,"errors",[]);R(this,"parent");R(this,"detachedDependents",{});R(this,"knownVersions",null);R(this,"activeVersion",!1);R(this,"initialized",!1);R(this,"startedInitialization",!1);R(this,"suggestion",!1);R(this,"_codeNativeValueValidation",null);this.initialData=i,this.project=r,this.id=i.id,this.name=i.name,this.description=i.description,this.private=i.private,this.abstract=i.abstract,this.index=i.index,this.static=i.static,this.required=i.required||!1,this.unique=i.unique||!1,this.codeName=i.codeName,this.hidden=i.hidden||!1,this.constant=i.constant||!1,this.interactive=i.interactive||!1,this.onProjectInitialized=this.onProjectInitialized.bind(this)}static new(i=null){return{id:L.UUID.uuid(),version:L.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||B().toISOString(),author:(i==null?void 0:i.author)||L.sessionAuthor,previousVersion:null,deleted:!1,deletable:!0,editable:!0,unique:!1,type:o.Property,parentRelationType:null,name:"",codeName:null,description:"",dataType:null,implements:[],extends:null,private:!1,abstract:!1,static:!1,constant:!1,interactive:!0,hidden:!1,index:0,required:!1,defaultValue:null,parent:null}}static fromGenerationTarget(i,r){const l=ye(i.parent),c=r.get(l),e=[];i.implements&&i.implements.forEach(A=>{e.push(r.get(A)||r.getBuiltIn(A))});let y=null;if(i.extends){const A=ye(i.extends);y=r.get(A)}const v={id:i.id,version:L.UUID.uuid(),createdAt:B().toISOString(),author:L.sessionAuthor,previousVersion:null,deleted:!1,name:i.name,deletable:!0,editable:!0,type:o.Property,index:c.properties.length,unique:i.unique||!1,parentRelationType:i.parentRelationType||null,private:i.private||!1,abstract:i.abstract||!1,static:i.static||!1,required:i.required||!1,constant:i.constant||!1,interactive:i.interactive||!1,hidden:!1,codeName:i.codeName||null,description:i.description||null,defaultValue:null,implements:e,extends:y,dataType:null,parent:c},b=me(v,r);return b.setParent(c,null),b}static validateGenerationTarget(i,r){let l=JSON.parse(JSON.stringify(i));const c=[],e=u2t(l,r),y=uP(l,r);return c.push(...e,...y,...Pn(l)),{errors:c,modifiedData:l}}get isExtendedProperty(){const i=this.parent.allBasePropertiesFromExtendedAndImplementedEntities.find(r=>{var l;return r.id===((l=this.extends)==null?void 0:l.id)});return!!i&&i.id!==this.id&&!i.abstract}get codeNativeValueValidation(){const i=[...this.implements].filter(l=>!this.implements.filter(y=>y.id!==l.id).some(y=>!!y.implements.find(v=>v.id===l.id)));return this._codeNativeValueValidation||(i==null?void 0:i.some(l=>l.codeNativeValueValidation))?(l,c)=>{const e=[];let y=c;if(this._codeNativeValueValidation){const v=this._codeNativeValueValidation(l,c);v&&(e.push(...v.errors),y=v.override)}return i.forEach(v=>{const b=v.codeNativeValueValidation;if(b){const A=b(l,c);A&&(e.push(...A.errors),y=A.override)}}),{errors:om(e),override:y}}:null}validateGeneratedUpdate(i){const r=[];return i.parent&&r.push(new Oe({id:`${this.id}--${re.InvalidParentUpdate}`,code:re.InvalidParentUpdate,severity:ce.Error,message:`Entity of type '${this.type}' with id '${this.id}' cannot have the 'parent' property updated, as it would mean moving the '${this.type}' entity to another parent entity.
389
389
  This is likely an incorrect strategy, either the '${this.type}' entity doesn't need to be updated or it should be deleted and a new one created in the desired parent.`})),(i.readsValue||i.writesValue)&&r.push(new Oe({id:`${this.id}--${Re.InvalidObjectStructure}`,code:Re.InvalidObjectStructure,severity:ce.Error,message:`Entity of type '${this.type}' with id '${this.id}' is not a value reading or writing entity.
390
- ${Ag}`})),{errors:r,modifiedData:i}}onProjectInitialized(i,r=this.project.addChangeSet(new H(this.project,L.sessionAuthor,new Date().toISOString(),this,!0,"on-property-received-project-initialized"))){return bxe(this,r),r==null||r.attemptAutoclose("on-property-received-project-initialized",this.id),this}subscribeDependents(i){return i.forEach(r=>{this.detachedDependents[r.entity.id]||(this.detachedDependents[r.entity.id]=r)}),this}unsubscribeDependents(i){return i.forEach(r=>{this.detachedDependents[r.entity.id]&&delete this.detachedDependents[r.entity.id]}),this}syncDependents(i=this.project.addChangeSet(new H(this.project,L.sessionAuthor,B().toISOString(),this,!0,"sync-dependents"))){const r=[],l=[],c=[],e=[];return Object.values(this.detachedDependents).forEach(y=>{const v=y.entity.afterAllChildrenInitialized(i);r.push(...v.updated),l.push(...v.added),c.push(...v.removed),e.push(...v.affected)}),i==null||i.attemptAutoclose("sync-dependents",this.id),{updated:O(r),added:O(l),removed:O(c),affected:O(e),self:this}}onDetachedDependencyRemoved(i,r,l){const c=[],e=[],y=[],v=[];if(r==="property-implements-field"&&(this.removeImplementation(i,l),c.push(this)),r==="property-extends-field"){const{updated:b,added:A,removed:E,affected:w}=this.remove({ignoreUpstream:!1},l);c.push(...b),e.push(...A),y.push(...E),v.push(...w)}return{updated:O(c),added:O(e),removed:O(y),affected:O(v),self:this}}onDetachedDependencyRestored(i,r,l){const c=[],e=[],y=[],v=[];if(r==="property-implements-field"&&(this.addImplementation(i,l),c.push(this)),r==="property-extends-field"){const{updated:b,added:A,removed:E,affected:w}=this.restore({},l);c.push(...b),e.push(...A),y.push(...E),v.push(...w)}return{updated:O(c),added:O(e),removed:O(y),affected:O(v),self:this}}unsubscribeFromDependencies(){var i,r,l,c,e,y,v;return this.implements.forEach(b=>{this.project.getBuiltIn(b.id)||b.unsubscribeDependents([{entity:this,field:"property-implements-field"}])}),(r=(i=this.extends)==null?void 0:i.unsubscribeDependents)==null||r.call(i,[{entity:this,field:"property-extends-field"}]),(e=(c=(l=this.dataType)==null?void 0:l.entity)==null?void 0:c.unsubscribeDependents)==null||e.call(c,[{entity:this,field:"property-data-type-entity-field"}]),(v=(y=this.dataType)==null?void 0:y.unsubscribeDependents)==null||v.call(y,[{entity:this,field:"property-data-type-field"}]),this.project.off(ti.PROJECT_INITIALIZED,this.onProjectInitialized),this}subscribeToDependencies(){var i,r,l,c,e,y,v;return this.implements.forEach(b=>{this.project.getBuiltIn(b.id)||b.subscribeDependents([{entity:this,field:"property-implements-field"}])}),(r=(i=this.extends)==null?void 0:i.subscribeDependents)==null||r.call(i,[{entity:this,field:"property-extends-field"}]),(e=(c=(l=this.dataType)==null?void 0:l.entity)==null?void 0:c.subscribeDependents)==null||e.call(c,[{entity:this,field:"property-data-type-entity-field"}]),(v=(y=this.dataType)==null?void 0:y.subscribeDependents)==null||v.call(y,[{entity:this,field:"property-data-type-field"}]),this.project.on(ti.PROJECT_INITIALIZED,this.onProjectInitialized),this}increaseVersion(i){if(i&&!B(i).isValid())throw new Error(`The shared timestamp '${i}' is not a valid ISO 8601 date string.`);return i&&B(i).isSame(B(this.createdAt))?this:(this.previousVersion=this.version,this.version=L.UUID.uuid(),this.createdAt=B(i).toISOString()||B().toISOString(),this)}captureVersion(){var r;const i=((r=this.knownVersions)==null?void 0:r.get(this.version))||new ii(this,this.project);return i.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,i):new Map([[this.version,i]]),i.defaultValue=this.defaultValue,i.dataType=this.dataType,i.implements=[...this.implements],i.extends=this.extends,i.parent=this.parent,this}recursiveCaptureUpstreamVersions(i){const r=[],l=[],c=[],e=[];if(this.parent&&this.parent.type!==o.PrimitiveEntity&&this.parent.type!==o.BuiltInBaseEntity){this.parent.increaseVersion(i);const y=this.parent.recursiveCaptureUpstreamVersions(i);r.push(this.parent,...y.updated),l.push(...y.added),c.push(...y.removed)}return{updated:O(r),added:O(l),removed:O(c),affected:O(e),self:this}}async restoreVersion(i){var v;const r=[],l=[],c=[],e=[];if(this.version===i)return{updated:O(r),added:O(l),removed:O(c),affected:O(e),self:this};if(!this.knownVersions){const b=new Map;for(const[A,E]of this.knownVersions||new Map){if(b.set(A,E),E.activeVersion=!1,E.knownVersions)for(const[w,P]of E.knownVersions)b.set(w,P);E.knownVersions=null}}let y=(v=this.knownVersions)==null?void 0:v.get(i);if(!y){const b=await this.APILoadVersion({},i);if(!b)throw new Error(`Version with id '${i}' for entity with id '${this.id}' not found.`);y=new ii(b,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.defaultValue=y.defaultValue,this.dataType=y.dataType,this.implements=[...y.implements],this.parent=y.parent,{updated:O(r),added:O(l),removed:O(c),affected:O(e),self:this}}updateWithShallowTransfer(i,r=this.project.addChangeSet(new H(this.project,L.sessionAuthor,B().toISOString(),this,!0,V.UpdateWithShallowTransfer))){if(!this.checkCanEdit(this,r))return ae.warn(`[updateWithShallowTransfer] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),r==null||r.attemptAutoclose(V.UpdateWithShallowTransfer,this.id),this;if(this.metaSync(i,r),this.version=i.version,this.createdAt=i.createdAt,this.author=i.author,this.deleted=i.deleted,this.previousVersion=i.previousVersion,this.unsubscribeFromDependencies(),i.parent){const l=ye(i.parent),c=this.project.get(l),e=this.parent;if(e&&e.id!==(c==null?void 0:c.id)&&this.removeFromParent(r),c)this.setParent(c,null);else throw r==null||r.attemptAutoclose(V.UpdateWithShallowTransfer,this.id),new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw r==null||r.attemptAutoclose(V.UpdateWithShallowTransfer,this.id),new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(i.implements.forEach(l=>{const c=ye(l),e=this.project.get(c);if(e)this.addImplementation(e,r);else throw new Error(`${Sn(this.type)} with id '${this.id}' has a 'implements' reference "${c}" which is missing in the project`)}),i.extends){const l=ye(i.extends),c=this.project.get(l);if(c)this.setExtends(c,r);else if(l)throw new Error(`${Sn(this.type)} with id '${this.id}' has a 'extends' reference "${l}" which is missing in the project`)}return this.captureVersion(),this.subscribeToDependencies(),r==null||r.attemptAutoclose(V.UpdateWithShallowTransfer,this.id),this}hydrateAncestors(){const i=[],r=[],l=[],c=[];if(this.initialData.parent){const e=ye(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.implements||[]).forEach(e=>{const y=ye(e),v=this.project.get(y);if(v)this.addImplementation(v,null),i.push(v);else throw new Error(`${Sn(this.type)} with id '${this.id}' has a 'implements' reference "${y}" which is missing in the project`)}),this.initialData.extends){const e=ye(this.initialData.extends),y=this.project.get(e);if(y)this.setExtends(y,null),i.push(y);else if(e)throw new Error(`${Sn(this.type)} with id '${this.id}' has a 'extends' reference "${e}" which is missing in the project`)}return{updated:O(i),added:O(r),removed:O(l),affected:O(c),self:this}}afterAllChildrenInitialized(i=this.project.addChangeSet(new H(this.project,L.sessionAuthor,B().toISOString(),this,!0,V.AfterAllChildrenInitialized))){if(!this.checkCanEdit(this,i))return ae.warn(`[afterAllChildrenInitialized] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(V.AfterAllChildrenInitialized,this.id),{updated:[],added:[],removed:[],affected:[],self:this};const r=[],l=[],c=[],e=[];if(this.initialized=!0,this.parent.type===o.DefinitionEntity&&this.parentRelationType!==Sp.AllPropertiesImplementationTarget){let M=this.index||0;const k=this.parent.properties.filter(Z=>!Z.deleted&&Z.id!==this.id);k.length&&(M>k.length+1?M=k.length:M<0&&(M=0)),k.find(Z=>(Z.index||0)===M&&!Z.deleted)&&k.filter(Z=>(Z.index||0)>=M&&!Z.deleted).forEach(Z=>{Z.metaSync({index:(Z.index||0)+1},i),i==null||i.add(Z,W.Updated),r.push(Z)}),this.metaSync({index:M},i)}const{updated:y,added:v,removed:b,affected:A}=this.syncWithImplementation(i);r.push(...y),l.push(...v),c.push(...b),e.push(...A);const{updated:E,added:w,removed:P,affected:x}=bxe(this,i);return r.push(...E),l.push(...w),c.push(...P),e.push(...x),this.captureVersion(),i==null||i.attemptAutoclose(V.AfterAllChildrenInitialized,this.id),{updated:O(r),added:O(l),removed:O(c),affected:O(e),self:this}}addSelfToProject(i=this.project.addChangeSet(new H(this.project,L.sessionAuthor,B().toISOString(),this,!0,"add-self-to-project"))){const r=[this],l=[],c=[],e=[];return this.parentRelationType===Sp.AllPropertiesImplementationTarget?this.parent.setAllPropertiesImplement(this,i):this.parent.addProperty(this,i),r.push(this.parent),this.subscribe(),this.subscribeToDependencies(),i==null||i.attemptAutoclose("add-self-to-project",this.id),{updated:O(r),added:O(l),removed:O(c),affected:O(e),self:this}}setParent(i,r=this.project.addChangeSet(new H(this.project,L.sessionAuthor,B().toISOString(),this,!0,V.SetParent))){var l;return this.checkCanEditWithCounterpartAndSideEffects(this,i,V.SetParent,r)?(((l=this.parent)==null?void 0:l.id)!==(i==null?void 0:i.id)&&(this.parent=i,r&&(r==null||r.add(this,W.Updated))),r==null||r.attemptAutoclose(V.SetParent,this.id),this):this}addImplementation(i,r=this.project.addChangeSet(new H(this.project,L.sessionAuthor,B().toISOString(),this,!0,V.AddImplementation))){return this.checkCanEdit(this,r)?(this.implements.includes(i)||(this.implements.push(i),r==null||r.add(this,W.Updated)),r==null||r.attemptAutoclose(V.AddImplementation,this.id),this):(ae.warn(`[addImplementation] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),r==null||r.attemptAutoclose(V.AddImplementation,this.id),this)}removeImplementation(i,r=this.project.addChangeSet(new H(this.project,L.sessionAuthor,B().toISOString(),this,!0,V.RemoveImplementation))){return this.checkCanEdit(this,r)?(this.implements.includes(i)&&(this.implements=this.implements.filter(l=>l.id!==i.id),r==null||r.add(this,W.Updated)),r==null||r.attemptAutoclose(V.RemoveImplementation,this.id),this):(ae.warn(`[removeImplementation] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),r==null||r.attemptAutoclose(V.RemoveImplementation,this.id),this)}setExtends(i,r=this.project.addChangeSet(new H(this.project,L.sessionAuthor,B().toISOString(),this,!0,V.SetExtends))){var l;return this.checkCanEdit(this,r)?(((l=this.extends)==null?void 0:l.id)!==(i==null?void 0:i.id)&&(this.extends=i,r&&(r==null||r.add(this,W.Updated))),r==null||r.attemptAutoclose(V.SetExtends,this.id),this):(ae.warn(`[setExtends] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),r==null||r.attemptAutoclose(V.SetExtends,this.id),this)}initChildren(i=this.project.addChangeSet(new H(this.project,L.sessionAuthor,B().toISOString(),this,!0,"init-children"))){if(this.initialized||this.startedInitialization)return this;if(this.startedInitialization=!0,this.initialData.defaultValue&&(this.defaultValue=me(this.initialData.defaultValue,this.project),this.defaultValue.setParent(this,null),this.defaultValue.initChildren(i)),this.initialData.dataType){const r=me(this.initialData.dataType,this.project);r.setParent(this,null),r.initChildren(i),this.dataType=r}if(this.implements=this.initialData.implements.map(r=>me(r,this.project)),this.initialData.extends){const r=me(this.initialData.extends,this.project);this.setExtends(r,null)}return this.subscribeToDependencies(),this.afterAllChildrenInitialized(i),i==null||i.attemptAutoclose("init-children",this.id),this}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(i,r=this.project.addChangeSet(new H(this.project,L.sessionAuthor,B().toISOString(),this,!0,"meta-sync"))){const l=$n(this,i,r),c=Nn(this,l),e=this.toMeta();return this.name=l.name!==void 0?l.name:e.name,this.codeName=l.codeName!==void 0?l.codeName:e.codeName,this.description=l.description!==void 0?l.description:e.description,this.abstract=l.abstract!==void 0?l.abstract:e.abstract,this.private=l.private!==void 0?l.private:e.private,this.index=l.index||(l.index!==0?e.index:0),this.static=l.static!==void 0?l.static:e.static,this.hidden=l.hidden!==void 0?l.hidden:e.hidden,this.constant=l.constant!==void 0?l.constant:e.constant,this.interactive=l.interactive!==void 0?l.interactive:e.interactive,this.required=l.required!==void 0?l.required:e.required,super.baseMetaSync(l,this,r),l.deleted===!0&&!e.deleted?r==null||r.add(this,W.Removed):l.deleted===!1&&e.deleted?r==null||r.add(this,W.Added):c&&(r==null||r.add(this,W.Updated)),r==null||r.attemptAutoclose("meta-sync",this.id),this}async APILoad(i=Be,...r){return await ii.repository.APILoad(this.id,...r),this}async APICreate(i=Be,...r){return await ii.repository.APICreate(this.toShallowJSON(),...r),this}async APIUpdate(i=Be,...r){return await ii.repository.APIUpdate(this.toShallowJSON(),...r),this}async APIDelete(i=Be,...r){return await ii.repository.APIDelete(this.toShallowJSON(),...r),this}async APIClone(i=Be,...r){return await ii.repository.APIClone(this.id,...r),this}async APILoadVersion(i=Be,r,...l){return await ii.repository.APILoadVersion(this.id,r,...l)}removeFromParent(i=this.project.addChangeSet(new H(this.project,L.sessionAuthor,B().toISOString(),this,!0,V.RemoveFromParent))){if(!this.checkCanEdit(this,i))return ae.warn(`[removeFromParent] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(V.RemoveFromParent,this.id),{added:[],updated:[],removed:[],affected:[],self:this};const r=[],l=[],c=[],e=[];return this.parent.type===o.DefinitionEntity&&(this.parentRelationType===Sp.AllPropertiesImplementationTarget?this.parent.removeAllPropertiesImplement(i):this.parent.removeProperty(this,i),e.push(this.parent)),i==null||i.attemptAutoclose(V.RemoveFromParent,this.id),{added:O(c),updated:O(r),removed:O(l),affected:O(e),self:this}}remove({ignoreUpstream:i}={ignoreUpstream:!1},r=this.project.addChangeSet(new H(this.project,L.sessionAuthor,B().toISOString(),this,!0,V.RemoveEntity))){var v;if(!this.checkCanDelete(this,r))return ae.warn(`[remove] User is not allowed to delete or edit this ${this.type} entity with id: ${this.id}`),r==null||r.event({id:`${V.RemoveEntity}-${this.id}`,action:V.RemoveEntity,owner:this,errorReason:tn.ActionOwnerEntityNonDeletable,rootAction:((v=r==null?void 0:r.self)==null?void 0:v.id)===this.id&&(r==null?void 0:r.autoCloseActionName)===V.RemoveEntity}),r==null||r.attemptAutoclose(V.RemoveEntity,this.id),{added:[],updated:[],removed:[],affected:[],self:this};const l=[],c=[],e=[],y=[];if(r!=null&&r.hasRemoved(this.id))return r==null||r.attemptAutoclose(V.RemoveEntity,this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(c.push(this),this.unsubscribe(),this.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},r),Object.values(this.detachedDependents).forEach(b=>{const{updated:A,removed:E,added:w}=b.entity.onDetachedDependencyRemoved(this,b.field,r);l.push(...A),c.push(...E),e.push(...w)}),this.defaultValue){const{updated:b,removed:A}=this.defaultValue.remove({ignoreUpstream:!0},r);l.push(...b),c.push(...A)}if(this.dataType){const{updated:b,removed:A}=this.dataType.remove({ignoreUpstream:!0},r);l.push(...b),c.push(...A)}if(!i){const b=this.removeFromParent(r);e.push(...b.added),l.push(...b.updated),c.push(...b.removed),y.push(...b.affected)}return r==null||r.attemptAutoclose(V.RemoveEntity,this.id),{added:O(e),updated:O(l),removed:O(c),affected:O(y),self:this}}restore({}={},i=this.project.addChangeSet(new H(this.project,L.sessionAuthor,B().toISOString(),this,!0,V.RestoreEntity))){if(!this.checkCanEdit(this,i))return ae.warn(`[restore] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(V.RestoreEntity,this.id),{added:[],updated:[],removed:[],affected:[],self:this};const r=[],l=[],c=[],e=[];if(i!=null&&i.hasAdded(this.id))return i==null||i.attemptAutoclose(V.RestoreEntity,this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},i),Object.values(this.detachedDependents).forEach(y=>{const{updated:v,removed:b,added:A}=y.entity.onDetachedDependencyRestored(this,y.field,i);l.push(...v),c.push(...b),r.push(...A)}),this.defaultValue){const{updated:y}=this.defaultValue.restore({},i);l.push(...y)}if(this.dataType){const{updated:y}=this.dataType.restore({},i);l.push(...y)}return this.parent.type===o.DefinitionEntity&&(this.parentRelationType===Sp.AllPropertiesImplementationTarget?this.parent.removeAllPropertiesImplement(i):this.parent.addProperty(this,i),e.push(this.parent)),i==null||i.attemptAutoclose(V.RestoreEntity,this.id),{added:O(r),updated:O(l),removed:O(c),affected:O(e),self:this}}toFlat(i=new Set){var l,c;return i.has(this.id)?[]:(i.add(this.id),[this,...((l=this.defaultValue)==null?void 0:l.toFlat(i))||[],...((c=this.dataType)==null?void 0:c.toFlat(i))||[],...this.parent.toFlat(i)])}toFlatIds(i=new Set){var l,c;if(i.has(this.id))return[];if(i.add(this.id),!this.parent)throw new Error(`Property with id '${this.id}' has no parent and cannot be flattened`);return[this.id,...((l=this.defaultValue)==null?void 0:l.toFlatIds(i))||[],...((c=this.dataType)==null?void 0:c.toFlatIds(i))||[],...this.parent.toFlatIds(i)]}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,codeName:this.codeName,description:this.description,index:this.index,hidden:this.hidden,private:this.private,abstract:this.abstract,required:this.required,unique:this.unique,constant:this.constant,interactive:this.interactive,static:this.static,type:this.type,editable:this.editable,deletable:this.deletable,name:this.name}}toJSON(i=new Set){var r,l,c;return i.has(this.id)?this.toReference():(i.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,editable:this.editable,deletable:this.deletable,name:this.name,codeName:this.codeName,description:this.description,index:this.index,private:this.private,unique:this.unique,required:this.required,static:this.static,constant:this.constant,interactive:this.interactive,abstract:this.abstract,hidden:this.hidden,parentRelationType:this.parentRelationType,defaultValue:((r=this.defaultValue)==null?void 0:r.toJSON(i))||null,dataType:((l=this.dataType)==null?void 0:l.toJSON(i))||null,implements:this.implements.map(e=>e.toJSON(i)),extends:((c=this.extends)==null?void 0:c.toJSON(i))||null,parent:this.parent.toReference()})}toJSONClone(i=dt){var l,c,e,y,v,b,A;let r;return(l=i.seenEntityMaps)!=null&&l.has(this.id)?r=i.seenEntityMaps.get(this.id):(r=i.newId||jn(this,this.project,i.uuidStrategy),i.seenEntityMaps&&i.seenEntityMaps.set(this.id,r)),(c=i.seenEntities)!=null&&c.has(r)||(e=i.seenEntities)!=null&&e.has(this.id)?this.toReference({seenEntityMaps:i.seenEntityMaps}):((y=i.seenEntities)==null||y.add(r),(v=i.seenEntities)==null||v.add(this.id),{id:r,version:L.UUID.uuid(),createdAt:i.timestamp||B().toISOString(),author:L.sessionAuthor,previousVersion:null,deleted:!1,type:this.type,editable:this.editable,deletable:this.deletable,name:this.name,codeName:this.codeName,description:this.description,index:this.index,unique:this.unique,private:this.private,required:this.required,static:this.static,constant:this.constant,interactive:this.interactive,abstract:this.abstract,hidden:this.hidden,parentRelationType:this.parentRelationType,defaultValue:((b=this.defaultValue)==null?void 0:b.toJSONClone({...i,newId:null}))||null,dataType:((A=this.dataType)==null?void 0:A.toJSONClone({...i,newId:null}))||null,implements:this.implements.map(E=>this.project.getBuiltIn(E.id)?E.toJSON(i.seenEntities):E.toJSONClone({...i,newId:null})),extends:(()=>{var E;return this.extends&&this.project.getBuiltIn(this.extends.id)?this.extends.toJSON():((E=this.extends)==null?void 0:E.toJSONClone({...i,newId:null}))||null})(),parent:this.parent.toReference({seenEntityMaps:i.seenEntityMaps})})}toReference(i=dt){var l;let r=this.id;return(l=i.seenEntityMaps)!=null&&l.has(this.id)&&(r=i.seenEntityMaps.get(this.id)),{id:r+"--"+L.UUID.uuid()+"--ref",type:o.GenericReference,entityId:r,version:this.version,entityType:this.type}}toShallowJSON(i=dt){var l,c,e,y;let r=this.id;return(l=i.seenEntityMaps)!=null&&l.has(this.id)&&(r=i.seenEntityMaps.get(this.id)),{id:r,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,name:this.name,codeName:this.codeName,description:this.description,type:this.type,editable:this.editable,deletable:this.deletable,index:this.index,private:this.private,required:this.required,unique:this.unique,abstract:this.abstract,static:this.static,constant:this.constant,interactive:this.interactive,hidden:this.hidden,parentRelationType:this.parentRelationType,defaultValue:((c=this.defaultValue)==null?void 0:c.toReference(i))||null,dataType:((e=this.dataType)==null?void 0:e.toReference(i))||null,implements:this.implements.map(v=>v.toReference(i)),extends:((y=this.extends)==null?void 0:y.toReference(i))||null,parent:this.parent.toReference(i)}}toFlatJSON(i=new Set){var l,c;return i.has(this.id)?[]:(i.add(this.id),[this.toShallowJSON(),...((l=this.defaultValue)==null?void 0:l.toFlatJSON(i))||[],...((c=this.dataType)==null?void 0:c.toFlatJSON(i))||[],...this.implements.flatMap(e=>e.toFlatJSON(i)),...this.parent.toFlatJSON(i)])}toGenerationTarget(){var i;return{id:this.id,name:this.name,description:this.description,type:this.type,private:this.private,required:this.required,abstract:this.abstract,static:this.static,parentRelationType:this.parentRelationType,implements:this.implements.map(r=>r.id),extends:(i=this.extends)==null?void 0:i.id,parent:this.parent.id}}toFlatGenerationTarget(i=new Set){var l,c;return i.has(this.id)?[]:(i.add(this.id),[this.toGenerationTarget(),...((l=this.defaultValue)==null?void 0:l.toFlatGenerationTarget(i))||[],...((c=this.dataType)==null?void 0:c.toFlatGenerationTarget(i))||[],...this.implements.flatMap(e=>e.toFlatGenerationTarget(i))])}clearErrors(){var i,r;return this.errors=[],(i=this.defaultValue)==null||i.clearErrors(),(r=this.dataType)==null||r.clearErrors(),this}validate(){return this.errors=mxe(this),{success:!0}}getErrors(){var r,l;return[...this.errors,...((r=this.defaultValue)==null?void 0:r.getErrors())||[],...((l=this.dataType)==null?void 0:l.getErrors())||[],...this.implements.flatMap(c=>c.getErrors())]}getShallowErrors(){return this.errors}implement(i,r=this.project.addChangeSet(new H(this.project,L.sessionAuthor,B().toISOString(),this,!0,"implement-self-as-property")),l=null){var b;const c=l||L.UUID.uuid(),e=ii.new(r);e.id=c,e.name=this.name,e.description=this.description,e.index=this.index,e.private=this.private,e.required=this.required,e.static=this.static,e.constant=this.constant,e.unique=this.unique,e.hidden=this.hidden,e.interactive=this.interactive,e.parent=i.toReference(),e.implements=[this.toJSON()];const y=me(e,this.project);y.hydrateAncestors(),y.addSelfToProject(r),r==null||r.add(y,W.Added),y.initChildren(r);const v=(b=this.defaultValue)==null?void 0:b.clone(r,y,L.UUID.uuid());return v&&(v.editable=!0,v.deletable=!0),y}clone(i=this.project.addChangeSet(new H(this.project,L.sessionAuthor,B().toISOString(),this,!0,V.CloneEntity)),r=null,l=null,c=!0){var w,P;const e=Vn(r,this),y=l||L.UUID.uuid(),v=r||this.parent,b=new Set([...this.project.getAllBuiltInIds(),...rn()]),A={hidden:!1,id:y,version:L.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||B().toISOString(),author:(i==null?void 0:i.author)||"1",previousVersion:null,deleted:!1,type:this.type,editable:!0,deletable:!0,name:this.name,codeName:this.codeName,description:this.description,index:this.index,private:this.private,constant:this.constant,unique:this.unique,interactive:this.interactive,required:this.required,abstract:this.abstract,static:this.static,parentRelationType:this.parentRelationType,defaultValue:null,dataType:null,implements:this.implements.map(x=>x.toJSON()),extends:this.extends,parent:v.toReference()},E=Ui(A,e);if(E.hydrateAncestors(),E.setParent(v,i),c&&(E.subscribe(),E.addSelfToProject(i)),E.initChildren(i),i==null||i.add(E,W.Added),this.dataType&&b.has(this.dataType.id))E.setDataType(e.getBuiltIn(this.dataType.id),i);else{const x=((w=this.dataType)==null?void 0:w.clone(i,E,L.UUID.uuid(),c))||null;x&&E.setDataType(x,i)}if(this.defaultValue){const x=(P=this.defaultValue)==null?void 0:P.clone(i,E,L.UUID.uuid(),c);E.setDefaultValue(x||null,i)}return this.implements.length&&this.implements.forEach(x=>{const M=e.get(x.id)||e.getBuiltIn(x.id);if(M){E.addImplementation(M,i);return}}),E.addSelfToProject(null),i==null||i.attemptAutoclose(V.CloneEntity,this.id),E}setDataType(i,r=this.project.addChangeSet(new H(this.project,L.sessionAuthor,B().toISOString(),this,!0,V.SetDataType))){if(!this.checkCanEdit(this,r))return ae.warn(`[setDataType] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),r==null||r.attemptAutoclose(V.SetDataType,this.id),this;const l=this.dataType;return(l==null?void 0:l.id)!==(i==null?void 0:i.id)&&(l==null||l.remove({ignoreUpstream:!0},r),this.dataType=i,this.subscribeToDependencies(),r==null||r.add(this,W.Affected)),r==null||r.attemptAutoclose(V.SetDataType,this.id),this}removeDataType(i=this.project.addChangeSet(new H(this.project,L.sessionAuthor,B().toISOString(),this,!0,V.RemoveDataType))){return this.checkCanEdit(this,i)?(this.dataType&&(this.dataType.remove({ignoreUpstream:!0},i),i==null||i.add(this,W.Affected),this.dataType=null),i==null||i.attemptAutoclose(V.RemoveDataType,this.id),this):(ae.warn(`[removeDataType] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(V.RemoveDataType,this.id),this)}getDataType(i=this.project.addChangeSet(new H(this.project,L.sessionAuthor,B().toISOString(),this,!0,"get-data-type"))){return i==null||i.attemptAutoclose("get-data-type",this.id),this.dataType}getDefaultValue(){var c;let i=null;for(const e of this.implements){const y=e.getDefaultValue();(!i||Kl(i))&&y&&(i=y)}let r=this.defaultValue;const l=(c=this.extends)==null?void 0:c.getDefaultValue();return Kl(r)&&l&&!Kl(l)&&(r=l),Kl(r)&&i&&!Kl(i)&&(r=i),r}setDefaultValue(i,r=this.project.addChangeSet(new H(this.project,L.sessionAuthor,B().toISOString(),this,!0,"set-default-value"))){if(!this.checkCanEdit(this,r))return ae.warn(`[setDefaultValue] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),r==null||r.attemptAutoclose("set-default-value",this.id),this;const l=this.defaultValue;return(l==null?void 0:l.id)!==(i==null?void 0:i.id)&&(l==null||l.remove({ignoreUpstream:!0},r),this.defaultValue=i,r==null||r.add(this,W.Affected)),r==null||r.attemptAutoclose("set-default-value",this.id),this}syncWithImplementation(i=this.project.addChangeSet(new H(this.project,L.sessionAuthor,B().toISOString(),this,!0,"sync-with-implementation"))){var x,M,k,q,Z,X,se,ee,he,de,fe;if(!this.checkCanEdit(this,i))return ae.warn(`[syncWithImplementation] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose("sync-with-implementation",this.id),{added:[],updated:[],removed:[],affected:[],self:this};const r=[],l=[],c=[],e=[];this.parent.type!==o.PrimitiveEntity&&this.interactive&&this.parent.getAllPropertiesImplements().forEach(ne=>{this.addImplementation(ne,i)});let y=null;const v=new Set([...this.project.getAllBuiltInIds(),...rn()]);for(const Te of this.implements)(x=Te.dataType)!=null&&x.isResolved&&(y?(M=Te.dataType.orChildrenGroup)!=null&&M.length&&Te.dataType.implementationChooseOne&&(y=Te.dataType):y=Te.dataType);const b=Rr(this.dataType,y);if(!this.dataType||!((k=this.dataType)!=null&&k.isResolved)||(q=this.dataType)!=null&&q.isResolved&&(y!=null&&y.isResolved)&&!b.compatible){if(y&&((Z=y.orChildrenGroup)!=null&&Z.length)&&y.implementationChooseOne){if(!this.dataType||this.dataType&&v.has(this.dataType.id)){const ne=dn.new(i);ne.parent=this.toReference();const ue=me(ne,this.project);ue.hydrateAncestors(),i==null||i.add(ue,W.Added),ue.addSelfToProject(i),ue.afterAllChildrenInitialized(i)}const Te=y.orChildrenGroup.some(ne=>ne.foreignKeyAllowed);if(((se=(X=this.dataType)==null?void 0:X.entity)==null?void 0:se.type)===o.DefinitionEntity&&qi(this.dataType.entity,De.PERSISTED_ENTITY)&&Te){const ne=nxe(this.dataType.entity);ne&&this.dataType.setForeignKeyRef(ne,i),(ee=this.dataType)==null||ee.setEntity(null,i)}else{const ne=y.orChildrenGroup.find(ue=>{var Pe;return((Pe=ue.entity)==null?void 0:Pe.id)===Q["primitive-entity"].string.id});if(ne)(he=this.dataType)==null||he.setEntity(ne.entity,i);else{const ue=y.orChildrenGroup.filter(Le=>Le.isResolved),Pe=ue.filter(Le=>{var Ue;return((Ue=Le.entity)==null?void 0:Ue.type)===o.PrimitiveEntity});Pe.length?(de=this.dataType)==null||de.setEntity(Pe[0].entity,i):ue.length&&((fe=this.dataType)==null||fe.setEntity(ue[0].entity,i))}}}else if(y&&v.has(y.id))this.setDataType(y,i);else if(y){const Te=y.clone(i,this,L.UUID.uuid(),!0);this.setDataType(Te,i),l.push(Te)}}if(!this.defaultValue){let Te=null;for(const ne of this.implements){const ue=ne.getDefaultValue();ue&&(Te=ue)}if(Te){const ne=Te.clone(i,this,L.UUID.uuid(),!0);this.setDefaultValue(ne,i),l.push(ne)}}let A=!1,E=!1,w=!1,P=!1;return this.implements.forEach(Te=>{Te.required&&(A=!0),Te.constant&&(w=!0),Te.unique&&(E=!0),Te.static&&(P=!0)}),this.metaSync({required:A||this.required,constant:w||this.constant,unique:E||this.unique,static:P||this.static},i),i==null||i.attemptAutoclose("sync-with-implementation",this.id),{updated:O(r),added:O(l),removed:O(c),affected:O(e),self:this}}implementAsInputMap(i=this.project.addChangeSet(new H(this.project,L.sessionAuthor,B().toISOString(),this,!0,"implement-as-return-declaration")),r,l){const c=hs.new(i);c.id=l||c.id,c.name=this.name,c.description=this.description,c.parent=r.toReference(),c.declaration=this.toJSON();const e=Ui(c,this.project);e.hydrateAncestors(),e.addSelfToProject(i),i==null||i.add(e,W.Added),e.initChildren(i);const y=new Set([...this.project.getAllBuiltInIds(),...rn()]);if(this.dataType)if(y.has(this.dataType.id))e.setDataType(this.dataType,i),i==null||i.add(e,W.Affected);else{const v=this.dataType.clone(i,e);e.setDataType(v,i)}if(this.defaultValue){const v=this.defaultValue.clone(i,e);e.setDefaultValue(v,i)}return i==null||i.attemptAutoclose("implement-as-return-declaration",this.id),e}};R(ii,"repository",{APICreate:async(i,...r)=>i,APIUpdate:async(i,...r)=>i,APIDelete:async(i,...r)=>i,APIClone:async(i,...r)=>{},APILoad:async(i,...r)=>null,APILoadVersion:async(i,r,...l)=>null}),R(ii,"type",o.Property),R(ii,"USER_MANAGED_PARENT_TYPES",[o.DefinitionEntity]),R(ii,"PARENT_TYPES",[...ii.USER_MANAGED_PARENT_TYPES,o.PrimitiveEntity,o.BuiltInBaseEntity]),R(ii,"MUTABLE_BASE_PROPERTIES",["name","codeName","description","private","abstract","static","required","constant","unique","interactive"]),R(ii,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),R(ii,"BASE_PROPERTIES",[...ii.MUTABLE_BASE_PROPERTIES,...ii.INMUTABLE_BASE_PROPERTIES]),R(ii,"MUTABLE_META_PROPERTIES",[...ii.MUTABLE_BASE_PROPERTIES,"index"]),R(ii,"INMUTABLE_META_PROPERTIES",[...ii.INMUTABLE_BASE_PROPERTIES]),R(ii,"META_PROPERTIES",[...ii.MUTABLE_META_PROPERTIES,...ii.INMUTABLE_META_PROPERTIES]),R(ii,"MUTABLE_UPSTREAM_PROPERTIES",[]),R(ii,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","implements","extends"]),R(ii,"UPSTREAM_PROPERTIES",[...ii.MUTABLE_UPSTREAM_PROPERTIES,...ii.INMUTABLE_UPSTREAM_PROPERTIES]),R(ii,"MUTABLE_DOWNSTREAM_PROPERTIES",["dataType"]),R(ii,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),R(ii,"DOWNSTREAM_PROPERTIES",[...ii.MUTABLE_DOWNSTREAM_PROPERTIES,...ii.INMUTABLE_DOWNSTREAM_PROPERTIES]),R(ii,"PROPERTIES",[...ii.META_PROPERTIES,...ii.UPSTREAM_PROPERTIES,...ii.DOWNSTREAM_PROPERTIES]);let Ga=ii;function Axe(d){var y,v;const p=d.implements.flatMap(b=>p2t(d,b)),i=c2t(d,d.extends),r=y2t(d),l=f2t(d);d.methods.flatMap(b=>b.validate()),d.abstractMethods.flatMap(b=>b.validate()),(y=d.allPropertiesImplement)==null||y.validate(),(v=d.additionalPropertiesDataType)==null||v.validate();const c=[...p,...i,...r,...l,...Rxe(d)];return nn(d.errors,c)}function gxe(d,p){const i=p.properties.filter(c=>c.abstract),r=[];let l=[...d.properties];return i.forEach(c=>{const e=l.find(y=>!!y.implements.find(v=>v.id===c.id));e?l=l.filter(y=>y.id!==e.id):r.push(c)}),r}function Ixe(d,p){const i=p.abstractMethods,r=[];let l=[...d.methods];return i.forEach(c=>{const e=l.find(y=>{var v;return((v=y.implements)==null?void 0:v.id)===c.id});e?l=l.filter(y=>y.id!==e.id):r.push(c)}),r}function p2t(d,p){const i=[];if(!p.abstract){const A=Ut({id:d.id+"--"+be.ImplementingNonAbstractEntity,message:`Entity "${d.name}" with id "${d.id}" is implementing a non-abstract entity "${p.name}" with id "${p.id}"`,severity:ce.Error,code:be.ImplementingNonAbstractEntity,entity:d});return i.push(A.error),i}const r=p.properties.filter(A=>A.abstract),l=[];let c=[...d.properties];r.forEach(A=>{const E=c.find(w=>!!w.implements.find(P=>P.id===A.id));E?c=c.filter(w=>w.id!==E.id):l.push(A)}),l.length&&l.forEach(A=>{const E=Ut({id:d.id+"--"+be.MissingPropertyImplementation+"--"+A.id,message:`Property "${A.name}" with id "${A.id}" of entity "${p.name}" with id "${p.id}" is not implemented when entity "${d.name}" with id "${d.id}" implements it`,severity:ce.Error,code:be.MissingPropertyImplementation,entity:d});i.push(E.error)});const e=[];let y=[...d.methods];p.abstractMethods.forEach(A=>{const E=y.find(w=>{var P;return((P=w.implements)==null?void 0:P.id)===A.id});E?y=y.filter(w=>w.id!==E.id):e.push(A)}),e.length&&e.forEach(A=>{const E=Ut({id:d.id+"--"+be.MissingMethodImplementation+"--"+A.id,message:`Method "${A.name}" with id "${A.id}" of entity "${p.name}" with id "${p.id}" is not implemented when entity "${d.name}" with id "${d.id}" implements it`,severity:ce.Error,code:be.MissingMethodImplementation,entity:d});i.push(E.error)});const v=[];p.properties.forEach(A=>{const E=c.find(w=>w.name===A.name);E&&v.push([E,A])}),v.length&&v.forEach(([A])=>{const E=Ut({id:d.id+"--"+Re.PropertyOverwritesOtherSiblingWithSameName+"--"+A.id,message:`Property "${A.name}" with id "${A.id}" of entity "${d.name}" with id "${d.id}" overwrites the property with the same name from the base entity "${p.name}" with id "${p.id}"`,severity:ce.Error,code:Re.PropertyOverwritesOtherSiblingWithSameName,entity:d});i.push(E.error)});const b=[];return p.methods.forEach(A=>{const E=y.find(w=>w.name===A.name);E&&b.push([E,A])}),b.length&&b.forEach(([A])=>{const E=Ut({id:d.id+"--"+Re.MethodOverwritesOtherSiblingWithSameName+"--"+A.id,message:`Method "${A.name}" with id "${A.id}" of entity "${d.name}" with id "${d.id}" overwrites the method with the same name from the base entity "${p.name}" with id "${p.id}"`,severity:ce.Error,code:Re.MethodOverwritesOtherSiblingWithSameName,entity:d});i.push(E.error)}),i}function c2t(d,p){const i=[];if(!p)return i;const r=[];if(!d.abstract&&p.abstract){const c=Ut({id:d.id+"--"+p.id+"--"+be.NonAbstractExtendingAbstractEntity,message:`Entity "${d.name}" with id "${d.id}" is not-abstract but is extending an abstract entity "${p.name}" with id "${p.id}"`,severity:ce.Error,code:be.NonAbstractExtendingAbstractEntity,entity:d,firstRelationship:p});return i.push(c.error),i}if(d.abstract&&!p.abstract){const c=Ut({id:d.id+"--"+p.id+"--"+be.AbstractExtendingNonAbstractEntity,message:`Entity "${d.name}" with id "${d.id}" is abstract but is extending an non-abstract entity "${p.name}" with id "${p.id}"`,severity:ce.Error,code:be.AbstractExtendingNonAbstractEntity,entity:d,firstRelationship:p});return i.push(c.error),i}d.properties.forEach(c=>{const e=p.properties.find(y=>{var v;return y.name===c.name&&((v=c.extends)==null?void 0:v.id)!==y.id});c.implements.find(y=>y.id===(e==null?void 0:e.id))||e&&r.push(c)}),r.length&&r.forEach(c=>{const e=Ut({id:d.id+"--"+Re.PropertyOverwritesOtherSiblingWithSameName,message:`Property "${c.name}" with id "${c.id}" of entity "${d.name}" with id "${d.id}" overwrites the property with the same name from the extended entity "${p.name}" with id "${p.id}"`,severity:ce.Error,code:Re.PropertyOverwritesOtherSiblingWithSameName,entity:d});i.push(e.error)});const l=[];return d.methods.forEach(c=>{var y;const e=p.methods.find(v=>{var b;return v.name===c.name&&((b=c.extends)==null?void 0:b.id)!==v.id});((y=c.implements)==null?void 0:y.id)!==(e==null?void 0:e.id)&&e&&l.push(c)}),l.length&&l.forEach(c=>{const e=Ut({id:d.id+"--"+Re.MethodOverwritesOtherSiblingWithSameName,message:`Method "${c.name}" with id "${c.id}" of entity "${d.name}" with id "${d.id}" overwrites the method with the same name from the extended entity "${p.name}" with id "${p.id}"`,severity:ce.Error,code:Re.MethodOverwritesOtherSiblingWithSameName,entity:d});i.push(e.error)}),i}function f2t(d){const p=[];if(!d.properties.length){const i=Ut({id:d.id+"--"+be.NoProperties,message:"No properties implemented",severity:ce.Warning,code:be.NoProperties,entity:d});p.push(i.error)}return d.properties.forEach(i=>{i.validate()}),p}function y2t(d){const p=[];if(d.abstract){if(d.methods.length){const i=Ut({id:d.id+"--"+be.AbstractEntityWithNonAbstractMethods,message:`Entity "${d.name}" with id "${d.id}" is marked as abstract but has non-abstract methods`,severity:ce.Error,code:be.AbstractEntityWithNonAbstractMethods,entity:d});p.push(i.error)}if(d.properties.some(i=>!i.abstract)){const i=Ut({id:d.id+"--"+be.AbstractEntityWithNonAbstractProperties,message:`Entity "${d.name}" with id "${d.id}" is marked as abstract but has non-abstract properties`,severity:ce.Error,code:be.AbstractEntityWithNonAbstractProperties,entity:d});p.push(i.error),d.properties.forEach(r=>{if(!r.abstract){const l=Ut({id:d.id+"--"+be.StaticEntityWithNonStaticProperties+"--"+r.id,message:`Property "${r.name}" with id "${r.id}" of entity "${d.name}" with id "${d.id}" is not marked as abstract but the entity is marked as abstract`,severity:ce.Error,code:be.StaticEntityWithNonStaticProperties,entity:d});p.push(l.error)}})}}else{if(d.abstractMethods.length){const i=Ut({id:d.id+"--"+be.AbstractPropertyInNonAbstractEntity,message:`Entity "${d.name}" with id "${d.id}" is not marked as abstract but has abstract methods`,severity:ce.Error,code:be.AbstractPropertyInNonAbstractEntity,entity:d});p.push(i.error)}d.properties.some(i=>i.abstract)&&d.properties.forEach(i=>{if(i.abstract){const r=Ut({id:d.id+"--"+be.AbstractPropertyInNonAbstractEntity+"--"+i.id,message:`Property "${i.name}" with id "${i.id}" of entity "${d.name}" with id "${d.id}" is marked as abstract but the entity is not marked as abstract`,severity:ce.Error,code:be.AbstractPropertyInNonAbstractEntity,entity:d,firstRelationship:i});p.push(r.error)}})}return d.static&&d.properties.some(i=>!i.static)&&d.properties.forEach(i=>{if(!i.static){const r=Ut({id:d.id+"--"+be.NonStaticPropertyInStaticEntity+"--"+i.id,message:`Property "${i.name}" with id "${i.id}" of entity "${d.name}" with id "${d.id}" is not marked as static but the entity is marked as static`,severity:ce.Error,code:be.NonStaticPropertyInStaticEntity,entity:d,firstRelationship:i});p.push(r.error)}}),p}function h2t(d,p){const i=[],r=Hr(p);if(!p.abstract){const e=new $i({id:d.id+"--"+p.id+"--"+be.ImplementingNonAbstractEntity,message:`Entity "${d.name}" with id "${d.id}" is implementing a non-abstract built-in entity "${p.name}" with id "${p.id}"`,severity:ce.Error,code:be.ImplementingNonAbstractEntity,entity:d,firstRelationship:p});i.push(e)}const l=d.implements.filter(e=>e.id!==p.id);if(d.abstract){const e=new $i({id:d.id+"--"+p.id+"--"+be.AbstractEntityImplements,message:`Entity "${d.name}" with id "${d.id}" is marked as abstract and cannot implement built-in entity "${p.name}" with id "${p.id}"`,severity:ce.Error,code:be.AbstractEntityImplements,entity:d,firstRelationship:p});i.push(e)}if(d.static&&!p.static){const e=new $i({id:d.id+"--"+p.id+"--"+be.StaticImplementingNonStaticEntity,message:`Entity "${d.name}" with id "${d.id}" is marked as static and cannot implement non-static built-in entity "${p.name}" with id "${p.id}"`,severity:ce.Error,code:be.StaticImplementingNonStaticEntity,entity:d,firstRelationship:p});i.push(e)}if(!d.static&&p.static){const e=new $i({id:d.id+"--"+p.id+"--"+be.NonStaticImplementingStaticEntity,message:`Entity "${d.name}" with id "${d.id}" is not marked as static and cannot implement static built-in entity "${p.name}" with id "${p.id}"`,severity:ce.Error,code:be.NonStaticImplementingStaticEntity,entity:d,firstRelationship:p});i.push(e)}return l.length&&l.forEach(e=>{if(e.type===o.BuiltInBaseEntity){const y=r.filter(v=>v.id!==e.id);y.length&&y.forEach(v=>{if(v.id!==e.id){const b=new $i({id:d.id+"--"+v.id+"--"+e.id+"--"+be.ImplementsIncompatibleEntities,message:`Entity "${d.name}" with id "${d.id}" is implementing built-in entity "${v.name}" with id "${v.id}" but also implements entity "${e.name}" with id "${e.id}" which is incompatible`,severity:ce.Error,code:be.ImplementsIncompatibleEntities,entity:d,firstRelationship:v,secondRelationship:e});i.push(b)}})}else{Hr(e).forEach(A=>{const E=r.filter(w=>w.id!==A.id);E.length&&E.forEach(w=>{if(w.id!==A.id){const P=new $i({id:d.id+"--"+w.id+"--"+A.id+"--"+be.ImplementsIncompatibleEntities,message:`Entity "${d.name}" with id "${d.id}" is implementing built-in entity "${w.name}" with id "${w.id}" but also implements entity "${A.name}" with id "${A.id}" which is incompatible`,severity:ce.Error,code:be.ImplementsIncompatibleEntities,entity:d,firstRelationship:w,secondRelationship:A});i.push(P)}})});const v=jd(p.ownDeclaredProperties,e.ownDeclaredProperties,Re.PropertyOverwritesOtherImplementedEntitysPropertyWithSameImplementation,Re.PropertyOverwritesOtherImplementedEntitysPropertyWithSameName);i.push(...v.errors);const b=jd(p.abstractMethods,[...e.abstractMethods,...e.methods],Re.MethodOverwritesOtherImplementedEntitysMethodWithSameImplementation,Re.MethodOverwritesOtherImplementedEntitysMethodWithSameName);i.push(...b.errors)}}),O(d.extends?Hr(d.extends):[]).forEach(e=>{if(!r.find(y=>y.id===e.id)){const y=new $i({id:d.id+"--"+p.id+"--"+e.id+"--"+be.ExtendsIncompatibleEntities,message:`Entity "${d.name}" with id "${d.id}" is implementing built-in entity "${p.name}" with id "${p.id}" but also extends entity "${e.name}" with id "${e.id}" which is incompatible`,severity:ce.Error,code:be.ExtendsIncompatibleEntities,entity:d,firstRelationship:p,secondRelationship:e});i.push(y)}}),i}function m2t(d,p,i=!1){var b,A;const r=[],l=Hr(p);if(!d.abstract&&p.abstract){const E=Ut({id:d.id+"--"+p.id+"--"+be.NonAbstractExtendingAbstractEntity,message:`Entity "${d.name}" with id "${d.id}" is not-abstract but is extending an abstract entity "${p.name}" with id "${p.id}"`,severity:ce.Error,code:be.NonAbstractExtendingAbstractEntity,entity:d,firstRelationship:p});r.push(E.error)}if(d.abstract&&!p.abstract){const E=Ut({id:d.id+"--"+p.id+"--"+be.AbstractExtendingNonAbstractEntity,message:`Entity "${d.name}" with id "${d.id}" is abstract but is extending an non-abstract entity "${p.name}" with id "${p.id}"`,severity:ce.Error,code:be.AbstractExtendingNonAbstractEntity,entity:d,firstRelationship:p});r.push(E.error)}if(!d.static&&p.static){const E=Ut({id:d.id+"--"+p.id+"--"+be.NonStaticExtendingStaticEntity,message:`Entity "${d.name}" with id "${d.id}" is not static but is extending a static entity "${p.name}" with id "${p.id}"`,severity:ce.Error,code:be.NonStaticExtendingStaticEntity,entity:d,firstRelationship:p});r.push(E.error)}if(d.static&&!p.static){const E=Ut({id:d.id+"--"+p.id+"--"+be.StaticExtendingNonStaticEntity,message:`Entity "${d.name}" with id "${d.id}" is static but is extending an non-static entity "${p.name}" with id "${p.id}"`,severity:ce.Error,code:be.StaticExtendingNonStaticEntity,entity:d,firstRelationship:p});r.push(E.error)}if(!Bc(p)){const E=Ut({id:d.id+"--"+p.id+"--"+be.ExtendingNonInteractiveEntity,message:`Entity "${d.name}" with id "${d.id}" is extending an non-interactive entity "${p.name}" with id "${p.id}"`,severity:ce.Error,code:be.ExtendingNonInteractiveEntity,entity:d,firstRelationship:p});r.push(E.error)}if(d.extends&&((b=d.extends)==null?void 0:b.id)!==p.id)if(((A=d.extends)==null?void 0:A.type)===o.BuiltInBaseEntity){const E=l.filter(w=>{var P;return w.id!==((P=d.extends)==null?void 0:P.id)});E.length&&E.forEach(w=>{var P,x,M,k;if(w.id!==((P=d.extends)==null?void 0:P.id)){const q=Ut({id:d.id+"--"+w.id+"--"+((x=d.extends)==null?void 0:x.id)+"--"+be.ExtendsIncompatibleEntities,message:`Entity "${d.name}" with id "${d.id}" is extending built-in entity "${w.name}" with id "${w.id}" but also extends entity "${(M=d.extends)==null?void 0:M.name}" with id "${(k=d.extends)==null?void 0:k.id}" which is incompatible`,severity:ce.Error,code:be.ExtendsIncompatibleEntities,entity:d,firstRelationship:w,secondRelationship:d.extends});r.push(q.error)}})}else{Hr(d.extends).forEach(q=>{const Z=l.filter(X=>X.id!==q.id);Z.length&&Z.forEach(X=>{if(X.id!==q.id){const se=new $i({id:d.id+"--"+X.id+"--"+q.id+"--"+be.ImplementsIncompatibleEntities,message:`Entity "${d.name}" with id "${d.id}" is extending built-in entity "${X.name}" with id "${X.id}" but also extends or implements entity "${q.name}" with id "${q.id}" which is incompatible`,severity:ce.Error,code:be.ImplementsIncompatibleEntities,entity:d,firstRelationship:X,secondRelationship:q});r.push(se)}})});const w=!!Hr(d.extends).find(q=>q.id===p.id);let P=[...d.extends.properties];w&&(P=P.filter(q=>!p.properties.find(Z=>Z.id===q.id||Z.name===q.name||!!q.implements.find(X=>X.id===Z.id))));let x=[...d.extends.methods];w&&(x=x.filter(q=>!p.methods.find(Z=>{var X;return Z.id===q.id||Z.name===q.name||Z.id===((X=q.implements)==null?void 0:X.id)})));const M=jd(p.ownDeclaredProperties,P,Re.PropertyOverwritesOtherExtendedEntitysPropertyWithSameImplementation,Re.PropertyOverwritesOtherExtendedEntitysPropertyWithSameName);r.push(...M.errors);const k=jd(p.abstractMethods,x,Re.MethodOverwritesOtherExtendedEntitysMethodWithSameImplementation,Re.MethodOverwritesOtherExtendedEntitysMethodWithSameName);r.push(...k.errors)}i&&ae.log("self.implements.length",d.implements.length),d.implements.length&&d.implements.forEach(E=>{if(E.type===o.BuiltInBaseEntity){const w=l.filter(P=>P.id!==E.id);w.length&&w.forEach(P=>{if(P.id!==E.id){const x=new $i({id:d.id+"--"+P.id+"--"+E.id+"--"+be.ImplementsIncompatibleEntities,message:`Entity "${d.name}" with id "${d.id}" is implementing built-in entity "${P.name}" with id "${P.id}" but also implements entity "${E.name}" with id "${E.id}" which is incompatible`,severity:ce.Error,code:be.ImplementsIncompatibleEntities,entity:d,firstRelationship:P,secondRelationship:E});r.push(x)}})}else{Hr(E).forEach(M=>{const k=l.filter(q=>q.id!==M.id);k.length&&k.forEach(q=>{if(q.id!==M.id){const Z=new $i({id:d.id+"--"+q.id+"--"+M.id+"--"+be.ImplementsIncompatibleEntities,message:`Entity "${d.name}" with id "${d.id}" is implementing built-in entity "${q.name}" with id "${q.id}" but also implements entity "${M.name}" with id "${M.id}" which is incompatible`,severity:ce.Error,code:be.ImplementsIncompatibleEntities,entity:d,firstRelationship:q,secondRelationship:M});r.push(Z)}})});const P=jd(p.ownDeclaredProperties,E.ownDeclaredProperties,Re.PropertyOverwritesOtherImplementedEntitysPropertyWithSameImplementation,Re.PropertyOverwritesOtherImplementedEntitysPropertyWithSameName);r.push(...P.errors);const x=jd(p.abstractMethods,[...E.abstractMethods,...E.methods],Re.MethodOverwritesOtherImplementedEntitysMethodWithSameImplementation,Re.MethodOverwritesOtherImplementedEntitysMethodWithSameName);r.push(...x.errors)}});const e=jd(d.ownDeclaredProperties,p.ownDeclaredProperties,Re.PropertyOverwritesOtherSiblingWithSameImplementation,Re.PropertyOverwritesOtherSiblingWithSameName);r.push(...e.errors);const y=jd(p.methods,p.abstractMethods,Re.MethodOverwritesOtherSiblingWithSameImplementation,Re.MethodOverwritesOtherSiblingWithSameName);return r.push(...y.errors),O(d.extends?Hr(d.extends):[]).forEach(E=>{if(!l.find(w=>w.id===E.id)){const w=new $i({id:d.id+"--"+p.id+"--"+E.id+"--"+be.ImplementsIncompatibleEntities,message:`Entity "${d.name}" with id "${d.id}" is extending built-in entity "${p.name}" with id "${p.id}" but also extends entity "${E.name}" with id "${E.id}" which is incompatible`,severity:ce.Error,code:be.ImplementsIncompatibleEntities,entity:d,firstRelationship:p,secondRelationship:E});r.push(w)}}),r}function T2t(d){const p=[];if(d.implements.forEach(i=>{if(!i.static){const r=new $i({id:d.id+"--"+i.id+"--"+be.StaticImplementingNonStaticEntity,message:`Entity "${d.name}" with id "${d.id}" is static but implements entity "${i.name}" with id "${i.id}" which is non-static`,severity:ce.Error,code:be.StaticImplementingNonStaticEntity,entity:d,firstRelationship:i});p.push(r)}}),d.extends&&!d.extends.static){const i=new $i({id:d.id+"--"+d.extends.id+"--"+be.StaticExtendingNonStaticEntity,message:`Entity "${d.name}" with id "${d.id}" is static but extends entity "${d.extends.name}" with id "${d.extends.id}" which is non-static`,severity:ce.Error,code:be.StaticExtendingNonStaticEntity,entity:d,firstRelationship:d.extends});p.push(i)}return p}function v2t(d){const p=[];if(d.implements.length){const i=new $i({id:d.id+"--"+be.AbstractEntityImplements,message:`Entity "${d.name}" with id "${d.id}" cannot be marked as abstract because it implements other entities`,severity:ce.Error,code:be.AbstractEntityImplements,entity:d});p.push(i)}if(d.extends&&!d.extends.abstract){const i=new $i({id:d.id+"--"+d.extends.id+"--"+be.AbstractExtendingNonAbstractEntity,message:`Entity "${d.name}" with id "${d.id}" is abstract but extends entity "${d.extends.name}" with id "${d.extends.id}" which is non-abstract`,severity:ce.Error,code:be.AbstractExtendingNonAbstractEntity,entity:d,firstRelationship:d.extends});p.push(i)}return p}function b2t(d){const p=[];if(d.extends&&d.extends.static){const i=new $i({id:d.id+"--"+d.extends.id+"--"+be.NonStaticExtendingStaticEntity,message:`Entity "${d.name}" with id "${d.id}" is non-static but extends entity "${d.extends.name}" with id "${d.extends.id}" which is static`,severity:ce.Error,code:be.NonStaticExtendingStaticEntity,entity:d,firstRelationship:d.extends});p.push(i)}return p}function E2t(d){const p=[];if(d.extends&&d.extends.abstract){const i=new $i({id:d.id+"--"+d.extends.id+"--"+be.NonAbstractExtendingAbstractEntity,message:`Entity "${d.name}" with id "${d.id}" is non-abstract but extends entity "${d.extends.name}" with id "${d.extends.id}" which is abstract`,severity:ce.Error,code:be.NonAbstractExtendingAbstractEntity,entity:d,firstRelationship:d.extends});p.push(i)}return p}function Rxe(d,p){const r=[...d.project.entities].filter(l=>l.id!==d.id);return xT(d,[Ji,Uc],r,p)}const A2t=Object.freeze(Object.defineProperty({__proto__:null,getBaseMethodsNotImplemented:Ixe,getBasePropertiesNotImplemented:gxe,validate:Axe,validateCanBecomeAbstract:v2t,validateCanBecomeNonAbstract:E2t,validateCanBecomeNonStatic:b2t,validateCanBecomeStatic:T2t,validateCanExtendEntity:m2t,validateCanImplementEntity:h2t,validateDefinitionEntityName:Rxe},Symbol.toStringTag,{value:"Module"}));function g2t(d,p){const i=[];if(d.parent)if(d.id===d.parent)i.push(new Oe({id:`${d.id}--${d.parent}--${re.SelfReference}`,code:re.SelfReference,severity:ce.Error,message:`Entity of type "${d.type}" with id "${d.id}", has a reference to itself at 'parent'. This is not allowed. Change the reference string or the 'entityId' property of the reference object.`}));else{const r=p.get(d.parent);r?[o.Project,o.DataType].includes(r.type)||i.push(new Oe({id:`${d.id}--${d.parent}--${re.InvalidParentReference}`,code:re.InvalidParentReference,severity:ce.Error,message:`Entity of type "${d.type}" with id "${d.id}", has a parent reference that isn't pointing to an entity of type 'project' or 'data-type'.`})):i.push(new Oe({id:`${d.id}--${d.parent}--${re.ReferencedEntityNotFound}`,code:re.ReferencedEntityNotFound,severity:ce.Error,message:`Entity of type "${d.type}" with id "${d.id}", is referencing an entity with id "${d.parent}" that isn't yet found in the project. Perhaps it should be created first. Or perhaps the ID is incorrect.`}))}return d.implements&&Array.isArray(d.implements)?d.implements.forEach(r=>{if(d.id===r){i.push(new Oe({id:`${d.id}--${r}--${re.SelfReference}`,code:re.SelfReference,severity:ce.Error,message:`Entity of type "${d.type}" with id "${d.id}", has a reference to itself at one of the 'implements' references. This is not allowed. Change the reference string or the 'entityId' property of the reference object.`}));return}const l=p.get(r);l?[o.DefinitionEntity,o.BuiltInBaseEntity].includes(l.type)?l.abstract||i.push(new Oe({id:`${d.id}--${r}--${re.InvalidImplementsReference}`,code:re.InvalidImplementsReference,severity:ce.Error,message:`Entity of type "${d.type}" with id "${d.id}", has an 'implements' reference that isn't pointing to an abstract entity.`})):i.push(new Oe({id:`${d.id}--${r}--${re.InvalidImplementsReference}`,code:re.InvalidImplementsReference,severity:ce.Error,message:`Entity of type "${d.type}" with id "${d.id}", has an 'implements' reference that isn't pointing to an entity of type 'definition-entity' or 'built-in-base-entity'.`})):i.push(new Oe({id:`${d.id}--${r}--${re.ReferencedEntityNotFound}`,code:re.ReferencedEntityNotFound,severity:ce.Error,message:`Entity of type "${d.type}" with id "${d.id}", is referencing an entity with id "${r}" that isn't yet found in the project. Perhaps it should be created first. Or perhaps the ID is incorrect.`}))}):i.push(new Oe({id:`${d.id}--${Re.InvalidObjectStructure}`,code:Re.InvalidObjectStructure,severity:ce.Error,message:`Entity of type "${d.type}" with id "${d.id}", has an 'implements' property that isn't an array.`})),d.extends&&Array.isArray(d.extends)&&d.extends.forEach(r=>{const l=p.get(r);l?[o.DefinitionEntity,o.BuiltInBaseEntity].includes(l.type)?l.abstract&&i.push(new Oe({id:`${d.id}--${r}--${re.InvalidExtendsReference}`,code:re.InvalidExtendsReference,severity:ce.Error,message:`Entity of type "${d.type}" with id "${d.id}", has an 'extends' reference that isn't pointing to a non-abstract entity. Did you want to use the property 'implements', which holds a list of references to absract entities, instead?`})):i.push(new Oe({id:`${d.id}--${r}--${re.InvalidExtendsReference}`,code:re.InvalidExtendsReference,severity:ce.Error,message:`Entity of type "${d.type}" with id "${d.id}", has an 'extends' reference that isn't pointing to an entity of type 'definition-entity' or 'built-in-base-entity'.`})):i.push(new Oe({id:`${d.id}--${r}--${re.ReferencedEntityNotFound}`,code:re.ReferencedEntityNotFound,severity:ce.Error,message:`Entity of type "${d.type}" with id "${d.id}", is referencing an entity with id "${r}" that isn't yet found in the project. Perhaps it should be created first. Or perhaps the ID is incorrect.`}))}),i}var qg=(d=>(d.Extends="extends",d.Implements="implements",d))(qg||{});const bi=class bi extends Un{constructor(i,r){super(i);R(this,"initialData");R(this,"id");R(this,"name");R(this,"codeName",null);R(this,"description",null);R(this,"x");R(this,"y");R(this,"static");R(this,"abstract");R(this,"type",o.DefinitionEntity);R(this,"additionalProperties",!1);R(this,"properties",[]);R(this,"allPropertiesImplement",null);R(this,"additionalPropertiesDataType",null);R(this,"methods",[]);R(this,"abstractMethods",[]);R(this,"extends",null);R(this,"implements",[]);R(this,"project");R(this,"errors",[]);R(this,"parent");R(this,"detachedDependents",{});R(this,"knownVersions",null);R(this,"activeVersion",!1);R(this,"initialized",!1);R(this,"startedInitialization",!1);R(this,"suggestedProperties",[]);R(this,"suggestedMethods",[]);this.initialData=i,this.project=r,this.id=i.id,this.name=i.name,this.description=i.description,this.x=i.x,this.y=i.y,this.codeName=i.codeName,this.static=i.static,this.abstract=i.abstract}static new(i=null){return{id:L.UUID.uuid(),version:L.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||B().toISOString(),author:(i==null?void 0:i.author)||L.sessionAuthor,previousVersion:null,deleted:!1,deletable:!0,editable:!0,type:o.DefinitionEntity,additionalProperties:!1,additionalPropertiesDataType:null,allPropertiesImplement:null,name:"",codeName:null,description:"",static:!1,abstract:!1,properties:[],methods:[],abstractMethods:[],extends:null,implements:[],x:0,y:0,parent:null}}static fromGenerationTarget(i,r){let l=r;if(i.parent){const b=ye(i.parent);l=r.get(b)}const c=[];i.implements&&i.implements.forEach(b=>{c.push(r.get(b)||r.getBuiltIn(b))});let e=null;i.extends&&(e=r.get(i.extends)||r.getBuiltIn(i.extends));const y={id:i.id,version:L.UUID.uuid(),createdAt:B().toISOString(),author:L.sessionAuthor,previousVersion:null,deleted:!1,name:i.name,deletable:!0,editable:!0,type:o.DefinitionEntity,codeName:i.codeName||null,description:i.description,static:i.static,abstract:i.abstract,additionalProperties:i.additionalProperties||!1,allPropertiesImplement:null,additionalPropertiesDataType:null,properties:[],methods:[],abstractMethods:[],extends:e,implements:c,x:0,y:0,parent:l},v=me(y,r);return v.setParent(l,null),v}static validateGenerationTarget(i,r){let l=JSON.parse(JSON.stringify(i));const c=[],e=g2t(l,r),y=lP(l,r);c.push(...e,...y,...Pn(l));const v=l.parent?r.get(l.parent):null;if(v&&v.type===o.DataType){const b=v;b.entity&&c.push(new Oe({id:`${i.id}--${re.NewEntityWouldOverriteExisting}`,code:re.NewEntityWouldOverriteExisting,severity:ce.Error,message:`The entity of type '${i.type}' with id '${i.id}' can't be added to the 'parent' entity with id '${b.id}' because it already has an 'entity' child. Data type entities can only have one 'entity' as children.
390
+ ${Ag}`})),{errors:r,modifiedData:i}}onProjectInitialized(i,r=this.project.addChangeSet(new H(this.project,L.sessionAuthor,new Date().toISOString(),this,!0,"on-property-received-project-initialized"))){return bxe(this,r),r==null||r.attemptAutoclose("on-property-received-project-initialized",this.id),this}subscribeDependents(i){return i.forEach(r=>{this.detachedDependents[r.entity.id]||(this.detachedDependents[r.entity.id]=r)}),this}unsubscribeDependents(i){return i.forEach(r=>{this.detachedDependents[r.entity.id]&&delete this.detachedDependents[r.entity.id]}),this}syncDependents(i=this.project.addChangeSet(new H(this.project,L.sessionAuthor,B().toISOString(),this,!0,"sync-dependents"))){const r=[],l=[],c=[],e=[];return Object.values(this.detachedDependents).forEach(y=>{const v=y.entity.afterAllChildrenInitialized(i);r.push(...v.updated),l.push(...v.added),c.push(...v.removed),e.push(...v.affected)}),i==null||i.attemptAutoclose("sync-dependents",this.id),{updated:O(r),added:O(l),removed:O(c),affected:O(e),self:this}}onDetachedDependencyRemoved(i,r,l){const c=[],e=[],y=[],v=[];if(r==="property-implements-field"&&(this.removeImplementation(i,l),c.push(this)),r==="property-extends-field"){const{updated:b,added:A,removed:E,affected:w}=this.remove({ignoreUpstream:!1},l);c.push(...b),e.push(...A),y.push(...E),v.push(...w)}return{updated:O(c),added:O(e),removed:O(y),affected:O(v),self:this}}onDetachedDependencyRestored(i,r,l){const c=[],e=[],y=[],v=[];if(r==="property-implements-field"&&(this.addImplementation(i,l),c.push(this)),r==="property-extends-field"){const{updated:b,added:A,removed:E,affected:w}=this.restore({},l);c.push(...b),e.push(...A),y.push(...E),v.push(...w)}return{updated:O(c),added:O(e),removed:O(y),affected:O(v),self:this}}unsubscribeFromDependencies(){var i,r,l,c,e,y,v;return this.implements.forEach(b=>{this.project.getBuiltIn(b.id)||b.unsubscribeDependents([{entity:this,field:"property-implements-field"}])}),(r=(i=this.extends)==null?void 0:i.unsubscribeDependents)==null||r.call(i,[{entity:this,field:"property-extends-field"}]),(e=(c=(l=this.dataType)==null?void 0:l.entity)==null?void 0:c.unsubscribeDependents)==null||e.call(c,[{entity:this,field:"property-data-type-entity-field"}]),(v=(y=this.dataType)==null?void 0:y.unsubscribeDependents)==null||v.call(y,[{entity:this,field:"property-data-type-field"}]),this.project.off(ti.PROJECT_INITIALIZED,this.onProjectInitialized),this}subscribeToDependencies(){var i,r,l,c,e,y,v;return this.implements.forEach(b=>{this.project.getBuiltIn(b.id)||b.subscribeDependents([{entity:this,field:"property-implements-field"}])}),(r=(i=this.extends)==null?void 0:i.subscribeDependents)==null||r.call(i,[{entity:this,field:"property-extends-field"}]),(e=(c=(l=this.dataType)==null?void 0:l.entity)==null?void 0:c.subscribeDependents)==null||e.call(c,[{entity:this,field:"property-data-type-entity-field"}]),(v=(y=this.dataType)==null?void 0:y.subscribeDependents)==null||v.call(y,[{entity:this,field:"property-data-type-field"}]),this.project.on(ti.PROJECT_INITIALIZED,this.onProjectInitialized),this}increaseVersion(i){if(i&&!B(i).isValid())throw new Error(`The shared timestamp '${i}' is not a valid ISO 8601 date string.`);return i&&B(i).isSame(B(this.createdAt))?this:(this.previousVersion=this.version,this.version=L.UUID.uuid(),this.createdAt=B(i).toISOString()||B().toISOString(),this)}captureVersion(){var r;const i=((r=this.knownVersions)==null?void 0:r.get(this.version))||new ii(this,this.project);return i.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,i):new Map([[this.version,i]]),i.defaultValue=this.defaultValue,i.dataType=this.dataType,i.implements=[...this.implements],i.extends=this.extends,i.parent=this.parent,this}recursiveCaptureUpstreamVersions(i){const r=[],l=[],c=[],e=[];if(this.parent&&this.parent.type!==o.PrimitiveEntity&&this.parent.type!==o.BuiltInBaseEntity){this.parent.increaseVersion(i);const y=this.parent.recursiveCaptureUpstreamVersions(i);r.push(this.parent,...y.updated),l.push(...y.added),c.push(...y.removed)}return{updated:O(r),added:O(l),removed:O(c),affected:O(e),self:this}}async restoreVersion(i){var v;const r=[],l=[],c=[],e=[];if(this.version===i)return{updated:O(r),added:O(l),removed:O(c),affected:O(e),self:this};if(!this.knownVersions){const b=new Map;for(const[A,E]of this.knownVersions||new Map){if(b.set(A,E),E.activeVersion=!1,E.knownVersions)for(const[w,P]of E.knownVersions)b.set(w,P);E.knownVersions=null}}let y=(v=this.knownVersions)==null?void 0:v.get(i);if(!y){const b=await this.APILoadVersion({},i);if(!b)throw new Error(`Version with id '${i}' for entity with id '${this.id}' not found.`);y=new ii(b,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.defaultValue=y.defaultValue,this.dataType=y.dataType,this.implements=[...y.implements],this.parent=y.parent,{updated:O(r),added:O(l),removed:O(c),affected:O(e),self:this}}updateWithShallowTransfer(i,r=this.project.addChangeSet(new H(this.project,L.sessionAuthor,B().toISOString(),this,!0,V.UpdateWithShallowTransfer))){if(!this.checkCanEdit(this,r))return ae.warn(`[updateWithShallowTransfer] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),r==null||r.attemptAutoclose(V.UpdateWithShallowTransfer,this.id),this;if(this.metaSync(i,r),this.version=i.version,this.createdAt=i.createdAt,this.author=i.author,this.deleted=i.deleted,this.previousVersion=i.previousVersion,this.unsubscribeFromDependencies(),i.parent){const l=ye(i.parent),c=this.project.get(l),e=this.parent;if(e&&e.id!==(c==null?void 0:c.id)&&this.removeFromParent(r),c)this.setParent(c,null);else throw r==null||r.attemptAutoclose(V.UpdateWithShallowTransfer,this.id),new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw r==null||r.attemptAutoclose(V.UpdateWithShallowTransfer,this.id),new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(i.implements.forEach(l=>{const c=ye(l),e=this.project.get(c);if(e)this.addImplementation(e,r);else throw new Error(`${Sn(this.type)} with id '${this.id}' has a 'implements' reference "${c}" which is missing in the project`)}),i.extends){const l=ye(i.extends),c=this.project.get(l);if(c)this.setExtends(c,r);else if(l)throw new Error(`${Sn(this.type)} with id '${this.id}' has a 'extends' reference "${l}" which is missing in the project`)}return this.captureVersion(),this.subscribeToDependencies(),r==null||r.attemptAutoclose(V.UpdateWithShallowTransfer,this.id),this}hydrateAncestors(){const i=[],r=[],l=[],c=[];if(this.initialData.parent){const e=ye(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.implements||[]).forEach(e=>{const y=ye(e),v=this.project.get(y);if(v)this.addImplementation(v,null),i.push(v);else throw new Error(`${Sn(this.type)} with id '${this.id}' has a 'implements' reference "${y}" which is missing in the project`)}),this.initialData.extends){const e=ye(this.initialData.extends),y=this.project.get(e);if(y)this.setExtends(y,null),i.push(y);else if(e)throw new Error(`${Sn(this.type)} with id '${this.id}' has a 'extends' reference "${e}" which is missing in the project`)}return{updated:O(i),added:O(r),removed:O(l),affected:O(c),self:this}}afterAllChildrenInitialized(i=this.project.addChangeSet(new H(this.project,L.sessionAuthor,B().toISOString(),this,!0,V.AfterAllChildrenInitialized))){if(!this.checkCanEdit(this,i))return ae.warn(`[afterAllChildrenInitialized] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(V.AfterAllChildrenInitialized,this.id),{updated:[],added:[],removed:[],affected:[],self:this};const r=[],l=[],c=[],e=[];if(this.initialized=!0,this.parent.type===o.DefinitionEntity&&this.parentRelationType!==Sp.AllPropertiesImplementationTarget){let M=this.index||0;const k=this.parent.properties.filter(Z=>!Z.deleted&&Z.id!==this.id);k.length&&(M>k.length+1?M=k.length:M<0&&(M=0)),k.find(Z=>(Z.index||0)===M&&!Z.deleted)&&k.filter(Z=>(Z.index||0)>=M&&!Z.deleted).forEach(Z=>{Z.metaSync({index:(Z.index||0)+1},i),i==null||i.add(Z,W.Updated),r.push(Z)}),this.metaSync({index:M},i)}const{updated:y,added:v,removed:b,affected:A}=this.syncWithImplementation(i);r.push(...y),l.push(...v),c.push(...b),e.push(...A);const{updated:E,added:w,removed:P,affected:x}=bxe(this,i);return r.push(...E),l.push(...w),c.push(...P),e.push(...x),this.captureVersion(),i==null||i.attemptAutoclose(V.AfterAllChildrenInitialized,this.id),{updated:O(r),added:O(l),removed:O(c),affected:O(e),self:this}}addSelfToProject(i=this.project.addChangeSet(new H(this.project,L.sessionAuthor,B().toISOString(),this,!0,"add-self-to-project"))){const r=[this],l=[],c=[],e=[];return this.parentRelationType===Sp.AllPropertiesImplementationTarget?this.parent.setAllPropertiesImplement(this,i):this.parent.addProperty(this,i),r.push(this.parent),this.subscribe(),this.subscribeToDependencies(),i==null||i.attemptAutoclose("add-self-to-project",this.id),{updated:O(r),added:O(l),removed:O(c),affected:O(e),self:this}}setParent(i,r=this.project.addChangeSet(new H(this.project,L.sessionAuthor,B().toISOString(),this,!0,V.SetParent))){var l;return this.checkCanEditWithCounterpartAndSideEffects(this,i,V.SetParent,r)?(((l=this.parent)==null?void 0:l.id)!==(i==null?void 0:i.id)&&(this.parent=i,r&&(r==null||r.add(this,W.Updated))),r==null||r.attemptAutoclose(V.SetParent,this.id),this):this}addImplementation(i,r=this.project.addChangeSet(new H(this.project,L.sessionAuthor,B().toISOString(),this,!0,V.AddImplementation))){return this.checkCanEdit(this,r)?(this.implements.includes(i)||(this.implements.push(i),r==null||r.add(this,W.Updated)),r==null||r.attemptAutoclose(V.AddImplementation,this.id),this):(ae.warn(`[addImplementation] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),r==null||r.attemptAutoclose(V.AddImplementation,this.id),this)}removeImplementation(i,r=this.project.addChangeSet(new H(this.project,L.sessionAuthor,B().toISOString(),this,!0,V.RemoveImplementation))){return this.checkCanEdit(this,r)?(this.implements.includes(i)&&(this.implements=this.implements.filter(l=>l.id!==i.id),r==null||r.add(this,W.Updated)),r==null||r.attemptAutoclose(V.RemoveImplementation,this.id),this):(ae.warn(`[removeImplementation] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),r==null||r.attemptAutoclose(V.RemoveImplementation,this.id),this)}setExtends(i,r=this.project.addChangeSet(new H(this.project,L.sessionAuthor,B().toISOString(),this,!0,V.SetExtends))){var l;return this.checkCanEdit(this,r)?(((l=this.extends)==null?void 0:l.id)!==(i==null?void 0:i.id)&&(this.extends=i,r&&(r==null||r.add(this,W.Updated))),r==null||r.attemptAutoclose(V.SetExtends,this.id),this):(ae.warn(`[setExtends] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),r==null||r.attemptAutoclose(V.SetExtends,this.id),this)}initChildren(i=this.project.addChangeSet(new H(this.project,L.sessionAuthor,B().toISOString(),this,!0,"init-children"))){if(this.initialized||this.startedInitialization)return this;if(this.startedInitialization=!0,this.initialData.defaultValue&&(this.defaultValue=me(this.initialData.defaultValue,this.project),this.defaultValue.setParent(this,null),this.defaultValue.initChildren(i)),this.initialData.dataType){const r=me(this.initialData.dataType,this.project);r.setParent(this,null),r.initChildren(i),this.dataType=r}if(this.implements=this.initialData.implements.map(r=>me(r,this.project)),this.initialData.extends){const r=me(this.initialData.extends,this.project);this.setExtends(r,null)}return this.subscribeToDependencies(),this.afterAllChildrenInitialized(i),i==null||i.attemptAutoclose("init-children",this.id),this}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(i,r=this.project.addChangeSet(new H(this.project,L.sessionAuthor,B().toISOString(),this,!0,"meta-sync"))){const l=$n(this,i,r),c=Nn(this,l),e=this.toMeta();return this.name=l.name!==void 0?l.name:e.name,this.codeName=l.codeName!==void 0?l.codeName:e.codeName,this.description=l.description!==void 0?l.description:e.description,this.abstract=l.abstract!==void 0?l.abstract:e.abstract,this.private=l.private!==void 0?l.private:e.private,this.index=l.index||(l.index!==0?e.index:0),this.static=l.static!==void 0?l.static:e.static,this.hidden=l.hidden!==void 0?l.hidden:e.hidden,this.constant=l.constant!==void 0?l.constant:e.constant,this.interactive=l.interactive!==void 0?l.interactive:e.interactive,this.required=l.required!==void 0?l.required:e.required,this.unique=l.unique!==void 0?l.unique:e.unique,super.baseMetaSync(l,this,r),l.deleted===!0&&!e.deleted?r==null||r.add(this,W.Removed):l.deleted===!1&&e.deleted?r==null||r.add(this,W.Added):c&&(r==null||r.add(this,W.Updated)),r==null||r.attemptAutoclose("meta-sync",this.id),this}async APILoad(i=Be,...r){return await ii.repository.APILoad(this.id,...r),this}async APICreate(i=Be,...r){return await ii.repository.APICreate(this.toShallowJSON(),...r),this}async APIUpdate(i=Be,...r){return await ii.repository.APIUpdate(this.toShallowJSON(),...r),this}async APIDelete(i=Be,...r){return await ii.repository.APIDelete(this.toShallowJSON(),...r),this}async APIClone(i=Be,...r){return await ii.repository.APIClone(this.id,...r),this}async APILoadVersion(i=Be,r,...l){return await ii.repository.APILoadVersion(this.id,r,...l)}removeFromParent(i=this.project.addChangeSet(new H(this.project,L.sessionAuthor,B().toISOString(),this,!0,V.RemoveFromParent))){if(!this.checkCanEdit(this,i))return ae.warn(`[removeFromParent] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(V.RemoveFromParent,this.id),{added:[],updated:[],removed:[],affected:[],self:this};const r=[],l=[],c=[],e=[];return this.parent.type===o.DefinitionEntity&&(this.parentRelationType===Sp.AllPropertiesImplementationTarget?this.parent.removeAllPropertiesImplement(i):this.parent.removeProperty(this,i),e.push(this.parent)),i==null||i.attemptAutoclose(V.RemoveFromParent,this.id),{added:O(c),updated:O(r),removed:O(l),affected:O(e),self:this}}remove({ignoreUpstream:i}={ignoreUpstream:!1},r=this.project.addChangeSet(new H(this.project,L.sessionAuthor,B().toISOString(),this,!0,V.RemoveEntity))){var v;if(!this.checkCanDelete(this,r))return ae.warn(`[remove] User is not allowed to delete or edit this ${this.type} entity with id: ${this.id}`),r==null||r.event({id:`${V.RemoveEntity}-${this.id}`,action:V.RemoveEntity,owner:this,errorReason:tn.ActionOwnerEntityNonDeletable,rootAction:((v=r==null?void 0:r.self)==null?void 0:v.id)===this.id&&(r==null?void 0:r.autoCloseActionName)===V.RemoveEntity}),r==null||r.attemptAutoclose(V.RemoveEntity,this.id),{added:[],updated:[],removed:[],affected:[],self:this};const l=[],c=[],e=[],y=[];if(r!=null&&r.hasRemoved(this.id))return r==null||r.attemptAutoclose(V.RemoveEntity,this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(c.push(this),this.unsubscribe(),this.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},r),Object.values(this.detachedDependents).forEach(b=>{const{updated:A,removed:E,added:w}=b.entity.onDetachedDependencyRemoved(this,b.field,r);l.push(...A),c.push(...E),e.push(...w)}),this.defaultValue){const{updated:b,removed:A}=this.defaultValue.remove({ignoreUpstream:!0},r);l.push(...b),c.push(...A)}if(this.dataType){const{updated:b,removed:A}=this.dataType.remove({ignoreUpstream:!0},r);l.push(...b),c.push(...A)}if(!i){const b=this.removeFromParent(r);e.push(...b.added),l.push(...b.updated),c.push(...b.removed),y.push(...b.affected)}return r==null||r.attemptAutoclose(V.RemoveEntity,this.id),{added:O(e),updated:O(l),removed:O(c),affected:O(y),self:this}}restore({}={},i=this.project.addChangeSet(new H(this.project,L.sessionAuthor,B().toISOString(),this,!0,V.RestoreEntity))){if(!this.checkCanEdit(this,i))return ae.warn(`[restore] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(V.RestoreEntity,this.id),{added:[],updated:[],removed:[],affected:[],self:this};const r=[],l=[],c=[],e=[];if(i!=null&&i.hasAdded(this.id))return i==null||i.attemptAutoclose(V.RestoreEntity,this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},i),Object.values(this.detachedDependents).forEach(y=>{const{updated:v,removed:b,added:A}=y.entity.onDetachedDependencyRestored(this,y.field,i);l.push(...v),c.push(...b),r.push(...A)}),this.defaultValue){const{updated:y}=this.defaultValue.restore({},i);l.push(...y)}if(this.dataType){const{updated:y}=this.dataType.restore({},i);l.push(...y)}return this.parent.type===o.DefinitionEntity&&(this.parentRelationType===Sp.AllPropertiesImplementationTarget?this.parent.removeAllPropertiesImplement(i):this.parent.addProperty(this,i),e.push(this.parent)),i==null||i.attemptAutoclose(V.RestoreEntity,this.id),{added:O(r),updated:O(l),removed:O(c),affected:O(e),self:this}}toFlat(i=new Set){var l,c;return i.has(this.id)?[]:(i.add(this.id),[this,...((l=this.defaultValue)==null?void 0:l.toFlat(i))||[],...((c=this.dataType)==null?void 0:c.toFlat(i))||[],...this.parent.toFlat(i)])}toFlatIds(i=new Set){var l,c;if(i.has(this.id))return[];if(i.add(this.id),!this.parent)throw new Error(`Property with id '${this.id}' has no parent and cannot be flattened`);return[this.id,...((l=this.defaultValue)==null?void 0:l.toFlatIds(i))||[],...((c=this.dataType)==null?void 0:c.toFlatIds(i))||[],...this.parent.toFlatIds(i)]}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,codeName:this.codeName,description:this.description,index:this.index,hidden:this.hidden,private:this.private,abstract:this.abstract,required:this.required,unique:this.unique,constant:this.constant,interactive:this.interactive,static:this.static,type:this.type,editable:this.editable,deletable:this.deletable,name:this.name}}toJSON(i=new Set){var r,l,c;return i.has(this.id)?this.toReference():(i.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,editable:this.editable,deletable:this.deletable,name:this.name,codeName:this.codeName,description:this.description,index:this.index,private:this.private,unique:this.unique,required:this.required,static:this.static,constant:this.constant,interactive:this.interactive,abstract:this.abstract,hidden:this.hidden,parentRelationType:this.parentRelationType,defaultValue:((r=this.defaultValue)==null?void 0:r.toJSON(i))||null,dataType:((l=this.dataType)==null?void 0:l.toJSON(i))||null,implements:this.implements.map(e=>e.toJSON(i)),extends:((c=this.extends)==null?void 0:c.toJSON(i))||null,parent:this.parent.toReference()})}toJSONClone(i=dt){var l,c,e,y,v,b,A;let r;return(l=i.seenEntityMaps)!=null&&l.has(this.id)?r=i.seenEntityMaps.get(this.id):(r=i.newId||jn(this,this.project,i.uuidStrategy),i.seenEntityMaps&&i.seenEntityMaps.set(this.id,r)),(c=i.seenEntities)!=null&&c.has(r)||(e=i.seenEntities)!=null&&e.has(this.id)?this.toReference({seenEntityMaps:i.seenEntityMaps}):((y=i.seenEntities)==null||y.add(r),(v=i.seenEntities)==null||v.add(this.id),{id:r,version:L.UUID.uuid(),createdAt:i.timestamp||B().toISOString(),author:L.sessionAuthor,previousVersion:null,deleted:!1,type:this.type,editable:this.editable,deletable:this.deletable,name:this.name,codeName:this.codeName,description:this.description,index:this.index,unique:this.unique,private:this.private,required:this.required,static:this.static,constant:this.constant,interactive:this.interactive,abstract:this.abstract,hidden:this.hidden,parentRelationType:this.parentRelationType,defaultValue:((b=this.defaultValue)==null?void 0:b.toJSONClone({...i,newId:null}))||null,dataType:((A=this.dataType)==null?void 0:A.toJSONClone({...i,newId:null}))||null,implements:this.implements.map(E=>this.project.getBuiltIn(E.id)?E.toJSON(i.seenEntities):E.toJSONClone({...i,newId:null})),extends:(()=>{var E;return this.extends&&this.project.getBuiltIn(this.extends.id)?this.extends.toJSON():((E=this.extends)==null?void 0:E.toJSONClone({...i,newId:null}))||null})(),parent:this.parent.toReference({seenEntityMaps:i.seenEntityMaps})})}toReference(i=dt){var l;let r=this.id;return(l=i.seenEntityMaps)!=null&&l.has(this.id)&&(r=i.seenEntityMaps.get(this.id)),{id:r+"--"+L.UUID.uuid()+"--ref",type:o.GenericReference,entityId:r,version:this.version,entityType:this.type}}toShallowJSON(i=dt){var l,c,e,y;let r=this.id;return(l=i.seenEntityMaps)!=null&&l.has(this.id)&&(r=i.seenEntityMaps.get(this.id)),{id:r,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,name:this.name,codeName:this.codeName,description:this.description,type:this.type,editable:this.editable,deletable:this.deletable,index:this.index,private:this.private,required:this.required,unique:this.unique,abstract:this.abstract,static:this.static,constant:this.constant,interactive:this.interactive,hidden:this.hidden,parentRelationType:this.parentRelationType,defaultValue:((c=this.defaultValue)==null?void 0:c.toReference(i))||null,dataType:((e=this.dataType)==null?void 0:e.toReference(i))||null,implements:this.implements.map(v=>v.toReference(i)),extends:((y=this.extends)==null?void 0:y.toReference(i))||null,parent:this.parent.toReference(i)}}toFlatJSON(i=new Set){var l,c;return i.has(this.id)?[]:(i.add(this.id),[this.toShallowJSON(),...((l=this.defaultValue)==null?void 0:l.toFlatJSON(i))||[],...((c=this.dataType)==null?void 0:c.toFlatJSON(i))||[],...this.implements.flatMap(e=>e.toFlatJSON(i)),...this.parent.toFlatJSON(i)])}toGenerationTarget(){var i;return{id:this.id,name:this.name,description:this.description,type:this.type,private:this.private,required:this.required,abstract:this.abstract,static:this.static,parentRelationType:this.parentRelationType,implements:this.implements.map(r=>r.id),extends:(i=this.extends)==null?void 0:i.id,parent:this.parent.id}}toFlatGenerationTarget(i=new Set){var l,c;return i.has(this.id)?[]:(i.add(this.id),[this.toGenerationTarget(),...((l=this.defaultValue)==null?void 0:l.toFlatGenerationTarget(i))||[],...((c=this.dataType)==null?void 0:c.toFlatGenerationTarget(i))||[],...this.implements.flatMap(e=>e.toFlatGenerationTarget(i))])}clearErrors(){var i,r;return this.errors=[],(i=this.defaultValue)==null||i.clearErrors(),(r=this.dataType)==null||r.clearErrors(),this}validate(){return this.errors=mxe(this),{success:!0}}getErrors(){var r,l;return[...this.errors,...((r=this.defaultValue)==null?void 0:r.getErrors())||[],...((l=this.dataType)==null?void 0:l.getErrors())||[],...this.implements.flatMap(c=>c.getErrors())]}getShallowErrors(){return this.errors}implement(i,r=this.project.addChangeSet(new H(this.project,L.sessionAuthor,B().toISOString(),this,!0,"implement-self-as-property")),l=null){var b;const c=l||L.UUID.uuid(),e=ii.new(r);e.id=c,e.name=this.name,e.description=this.description,e.index=this.index,e.private=this.private,e.required=this.required,e.static=this.static,e.constant=this.constant,e.unique=this.unique,e.hidden=this.hidden,e.interactive=this.interactive,e.parent=i.toReference(),e.implements=[this.toJSON()];const y=me(e,this.project);y.hydrateAncestors(),y.addSelfToProject(r),r==null||r.add(y,W.Added),y.initChildren(r);const v=(b=this.defaultValue)==null?void 0:b.clone(r,y,L.UUID.uuid());return v&&(v.editable=!0,v.deletable=!0),y}clone(i=this.project.addChangeSet(new H(this.project,L.sessionAuthor,B().toISOString(),this,!0,V.CloneEntity)),r=null,l=null,c=!0){var w,P;const e=Vn(r,this),y=l||L.UUID.uuid(),v=r||this.parent,b=new Set([...this.project.getAllBuiltInIds(),...rn()]),A={hidden:!1,id:y,version:L.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||B().toISOString(),author:(i==null?void 0:i.author)||"1",previousVersion:null,deleted:!1,type:this.type,editable:!0,deletable:!0,name:this.name,codeName:this.codeName,description:this.description,index:this.index,private:this.private,constant:this.constant,unique:this.unique,interactive:this.interactive,required:this.required,abstract:this.abstract,static:this.static,parentRelationType:this.parentRelationType,defaultValue:null,dataType:null,implements:this.implements.map(x=>x.toJSON()),extends:this.extends,parent:v.toReference()},E=Ui(A,e);if(E.hydrateAncestors(),E.setParent(v,i),c&&(E.subscribe(),E.addSelfToProject(i)),E.initChildren(i),i==null||i.add(E,W.Added),this.dataType&&b.has(this.dataType.id))E.setDataType(e.getBuiltIn(this.dataType.id),i);else{const x=((w=this.dataType)==null?void 0:w.clone(i,E,L.UUID.uuid(),c))||null;x&&E.setDataType(x,i)}if(this.defaultValue){const x=(P=this.defaultValue)==null?void 0:P.clone(i,E,L.UUID.uuid(),c);E.setDefaultValue(x||null,i)}return this.implements.length&&this.implements.forEach(x=>{const M=e.get(x.id)||e.getBuiltIn(x.id);if(M){E.addImplementation(M,i);return}}),E.addSelfToProject(null),i==null||i.attemptAutoclose(V.CloneEntity,this.id),E}setDataType(i,r=this.project.addChangeSet(new H(this.project,L.sessionAuthor,B().toISOString(),this,!0,V.SetDataType))){if(!this.checkCanEdit(this,r))return ae.warn(`[setDataType] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),r==null||r.attemptAutoclose(V.SetDataType,this.id),this;const l=this.dataType;return(l==null?void 0:l.id)!==(i==null?void 0:i.id)&&(l==null||l.remove({ignoreUpstream:!0},r),this.dataType=i,this.subscribeToDependencies(),r==null||r.add(this,W.Affected)),r==null||r.attemptAutoclose(V.SetDataType,this.id),this}removeDataType(i=this.project.addChangeSet(new H(this.project,L.sessionAuthor,B().toISOString(),this,!0,V.RemoveDataType))){return this.checkCanEdit(this,i)?(this.dataType&&(this.dataType.remove({ignoreUpstream:!0},i),i==null||i.add(this,W.Affected),this.dataType=null),i==null||i.attemptAutoclose(V.RemoveDataType,this.id),this):(ae.warn(`[removeDataType] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(V.RemoveDataType,this.id),this)}getDataType(i=this.project.addChangeSet(new H(this.project,L.sessionAuthor,B().toISOString(),this,!0,"get-data-type"))){return i==null||i.attemptAutoclose("get-data-type",this.id),this.dataType}getDefaultValue(){var c;let i=null;for(const e of this.implements){const y=e.getDefaultValue();(!i||Kl(i))&&y&&(i=y)}let r=this.defaultValue;const l=(c=this.extends)==null?void 0:c.getDefaultValue();return Kl(r)&&l&&!Kl(l)&&(r=l),Kl(r)&&i&&!Kl(i)&&(r=i),r}setDefaultValue(i,r=this.project.addChangeSet(new H(this.project,L.sessionAuthor,B().toISOString(),this,!0,"set-default-value"))){if(!this.checkCanEdit(this,r))return ae.warn(`[setDefaultValue] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),r==null||r.attemptAutoclose("set-default-value",this.id),this;const l=this.defaultValue;return(l==null?void 0:l.id)!==(i==null?void 0:i.id)&&(l==null||l.remove({ignoreUpstream:!0},r),this.defaultValue=i,r==null||r.add(this,W.Affected)),r==null||r.attemptAutoclose("set-default-value",this.id),this}syncWithImplementation(i=this.project.addChangeSet(new H(this.project,L.sessionAuthor,B().toISOString(),this,!0,"sync-with-implementation"))){var x,M,k,q,Z,X,se,ee,he,de,fe;if(!this.checkCanEdit(this,i))return ae.warn(`[syncWithImplementation] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose("sync-with-implementation",this.id),{added:[],updated:[],removed:[],affected:[],self:this};const r=[],l=[],c=[],e=[];this.parent.type!==o.PrimitiveEntity&&this.interactive&&this.parent.getAllPropertiesImplements().forEach(ne=>{this.addImplementation(ne,i)});let y=null;const v=new Set([...this.project.getAllBuiltInIds(),...rn()]);for(const Te of this.implements)(x=Te.dataType)!=null&&x.isResolved&&(y?(M=Te.dataType.orChildrenGroup)!=null&&M.length&&Te.dataType.implementationChooseOne&&(y=Te.dataType):y=Te.dataType);const b=Rr(this.dataType,y);if(!this.dataType||!((k=this.dataType)!=null&&k.isResolved)||(q=this.dataType)!=null&&q.isResolved&&(y!=null&&y.isResolved)&&!b.compatible){if(y&&((Z=y.orChildrenGroup)!=null&&Z.length)&&y.implementationChooseOne){if(!this.dataType||this.dataType&&v.has(this.dataType.id)){const ne=dn.new(i);ne.parent=this.toReference();const ue=me(ne,this.project);ue.hydrateAncestors(),i==null||i.add(ue,W.Added),ue.addSelfToProject(i),ue.afterAllChildrenInitialized(i)}const Te=y.orChildrenGroup.some(ne=>ne.foreignKeyAllowed);if(((se=(X=this.dataType)==null?void 0:X.entity)==null?void 0:se.type)===o.DefinitionEntity&&qi(this.dataType.entity,De.PERSISTED_ENTITY)&&Te){const ne=nxe(this.dataType.entity);ne&&this.dataType.setForeignKeyRef(ne,i),(ee=this.dataType)==null||ee.setEntity(null,i)}else{const ne=y.orChildrenGroup.find(ue=>{var Pe;return((Pe=ue.entity)==null?void 0:Pe.id)===Q["primitive-entity"].string.id});if(ne)(he=this.dataType)==null||he.setEntity(ne.entity,i);else{const ue=y.orChildrenGroup.filter(Le=>Le.isResolved),Pe=ue.filter(Le=>{var Ue;return((Ue=Le.entity)==null?void 0:Ue.type)===o.PrimitiveEntity});Pe.length?(de=this.dataType)==null||de.setEntity(Pe[0].entity,i):ue.length&&((fe=this.dataType)==null||fe.setEntity(ue[0].entity,i))}}}else if(y&&v.has(y.id))this.setDataType(y,i);else if(y){const Te=y.clone(i,this,L.UUID.uuid(),!0);this.setDataType(Te,i),l.push(Te)}}if(!this.defaultValue){let Te=null;for(const ne of this.implements){const ue=ne.getDefaultValue();ue&&(Te=ue)}if(Te){const ne=Te.clone(i,this,L.UUID.uuid(),!0);this.setDefaultValue(ne,i),l.push(ne)}}let A=!1,E=!1,w=!1,P=!1;return this.implements.forEach(Te=>{Te.required&&(A=!0),Te.constant&&(w=!0),Te.unique&&(E=!0),Te.static&&(P=!0)}),this.metaSync({required:A||this.required,constant:w||this.constant,unique:E||this.unique,static:P||this.static},i),i==null||i.attemptAutoclose("sync-with-implementation",this.id),{updated:O(r),added:O(l),removed:O(c),affected:O(e),self:this}}implementAsInputMap(i=this.project.addChangeSet(new H(this.project,L.sessionAuthor,B().toISOString(),this,!0,"implement-as-return-declaration")),r,l){const c=hs.new(i);c.id=l||c.id,c.name=this.name,c.description=this.description,c.parent=r.toReference(),c.declaration=this.toJSON();const e=Ui(c,this.project);e.hydrateAncestors(),e.addSelfToProject(i),i==null||i.add(e,W.Added),e.initChildren(i);const y=new Set([...this.project.getAllBuiltInIds(),...rn()]);if(this.dataType)if(y.has(this.dataType.id))e.setDataType(this.dataType,i),i==null||i.add(e,W.Affected);else{const v=this.dataType.clone(i,e);e.setDataType(v,i)}if(this.defaultValue){const v=this.defaultValue.clone(i,e);e.setDefaultValue(v,i)}return i==null||i.attemptAutoclose("implement-as-return-declaration",this.id),e}};R(ii,"repository",{APICreate:async(i,...r)=>i,APIUpdate:async(i,...r)=>i,APIDelete:async(i,...r)=>i,APIClone:async(i,...r)=>{},APILoad:async(i,...r)=>null,APILoadVersion:async(i,r,...l)=>null}),R(ii,"type",o.Property),R(ii,"USER_MANAGED_PARENT_TYPES",[o.DefinitionEntity]),R(ii,"PARENT_TYPES",[...ii.USER_MANAGED_PARENT_TYPES,o.PrimitiveEntity,o.BuiltInBaseEntity]),R(ii,"MUTABLE_BASE_PROPERTIES",["name","codeName","description","private","abstract","static","required","constant","unique","interactive"]),R(ii,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),R(ii,"BASE_PROPERTIES",[...ii.MUTABLE_BASE_PROPERTIES,...ii.INMUTABLE_BASE_PROPERTIES]),R(ii,"MUTABLE_META_PROPERTIES",[...ii.MUTABLE_BASE_PROPERTIES,"index"]),R(ii,"INMUTABLE_META_PROPERTIES",[...ii.INMUTABLE_BASE_PROPERTIES]),R(ii,"META_PROPERTIES",[...ii.MUTABLE_META_PROPERTIES,...ii.INMUTABLE_META_PROPERTIES]),R(ii,"MUTABLE_UPSTREAM_PROPERTIES",[]),R(ii,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","implements","extends"]),R(ii,"UPSTREAM_PROPERTIES",[...ii.MUTABLE_UPSTREAM_PROPERTIES,...ii.INMUTABLE_UPSTREAM_PROPERTIES]),R(ii,"MUTABLE_DOWNSTREAM_PROPERTIES",["dataType"]),R(ii,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),R(ii,"DOWNSTREAM_PROPERTIES",[...ii.MUTABLE_DOWNSTREAM_PROPERTIES,...ii.INMUTABLE_DOWNSTREAM_PROPERTIES]),R(ii,"PROPERTIES",[...ii.META_PROPERTIES,...ii.UPSTREAM_PROPERTIES,...ii.DOWNSTREAM_PROPERTIES]);let Ga=ii;function Axe(d){var y,v;const p=d.implements.flatMap(b=>p2t(d,b)),i=c2t(d,d.extends),r=y2t(d),l=f2t(d);d.methods.flatMap(b=>b.validate()),d.abstractMethods.flatMap(b=>b.validate()),(y=d.allPropertiesImplement)==null||y.validate(),(v=d.additionalPropertiesDataType)==null||v.validate();const c=[...p,...i,...r,...l,...Rxe(d)];return nn(d.errors,c)}function gxe(d,p){const i=p.properties.filter(c=>c.abstract),r=[];let l=[...d.properties];return i.forEach(c=>{const e=l.find(y=>!!y.implements.find(v=>v.id===c.id));e?l=l.filter(y=>y.id!==e.id):r.push(c)}),r}function Ixe(d,p){const i=p.abstractMethods,r=[];let l=[...d.methods];return i.forEach(c=>{const e=l.find(y=>{var v;return((v=y.implements)==null?void 0:v.id)===c.id});e?l=l.filter(y=>y.id!==e.id):r.push(c)}),r}function p2t(d,p){const i=[];if(!p.abstract){const A=Ut({id:d.id+"--"+be.ImplementingNonAbstractEntity,message:`Entity "${d.name}" with id "${d.id}" is implementing a non-abstract entity "${p.name}" with id "${p.id}"`,severity:ce.Error,code:be.ImplementingNonAbstractEntity,entity:d});return i.push(A.error),i}const r=p.properties.filter(A=>A.abstract),l=[];let c=[...d.properties];r.forEach(A=>{const E=c.find(w=>!!w.implements.find(P=>P.id===A.id));E?c=c.filter(w=>w.id!==E.id):l.push(A)}),l.length&&l.forEach(A=>{const E=Ut({id:d.id+"--"+be.MissingPropertyImplementation+"--"+A.id,message:`Property "${A.name}" with id "${A.id}" of entity "${p.name}" with id "${p.id}" is not implemented when entity "${d.name}" with id "${d.id}" implements it`,severity:ce.Error,code:be.MissingPropertyImplementation,entity:d});i.push(E.error)});const e=[];let y=[...d.methods];p.abstractMethods.forEach(A=>{const E=y.find(w=>{var P;return((P=w.implements)==null?void 0:P.id)===A.id});E?y=y.filter(w=>w.id!==E.id):e.push(A)}),e.length&&e.forEach(A=>{const E=Ut({id:d.id+"--"+be.MissingMethodImplementation+"--"+A.id,message:`Method "${A.name}" with id "${A.id}" of entity "${p.name}" with id "${p.id}" is not implemented when entity "${d.name}" with id "${d.id}" implements it`,severity:ce.Error,code:be.MissingMethodImplementation,entity:d});i.push(E.error)});const v=[];p.properties.forEach(A=>{const E=c.find(w=>w.name===A.name);E&&v.push([E,A])}),v.length&&v.forEach(([A])=>{const E=Ut({id:d.id+"--"+Re.PropertyOverwritesOtherSiblingWithSameName+"--"+A.id,message:`Property "${A.name}" with id "${A.id}" of entity "${d.name}" with id "${d.id}" overwrites the property with the same name from the base entity "${p.name}" with id "${p.id}"`,severity:ce.Error,code:Re.PropertyOverwritesOtherSiblingWithSameName,entity:d});i.push(E.error)});const b=[];return p.methods.forEach(A=>{const E=y.find(w=>w.name===A.name);E&&b.push([E,A])}),b.length&&b.forEach(([A])=>{const E=Ut({id:d.id+"--"+Re.MethodOverwritesOtherSiblingWithSameName+"--"+A.id,message:`Method "${A.name}" with id "${A.id}" of entity "${d.name}" with id "${d.id}" overwrites the method with the same name from the base entity "${p.name}" with id "${p.id}"`,severity:ce.Error,code:Re.MethodOverwritesOtherSiblingWithSameName,entity:d});i.push(E.error)}),i}function c2t(d,p){const i=[];if(!p)return i;const r=[];if(!d.abstract&&p.abstract){const c=Ut({id:d.id+"--"+p.id+"--"+be.NonAbstractExtendingAbstractEntity,message:`Entity "${d.name}" with id "${d.id}" is not-abstract but is extending an abstract entity "${p.name}" with id "${p.id}"`,severity:ce.Error,code:be.NonAbstractExtendingAbstractEntity,entity:d,firstRelationship:p});return i.push(c.error),i}if(d.abstract&&!p.abstract){const c=Ut({id:d.id+"--"+p.id+"--"+be.AbstractExtendingNonAbstractEntity,message:`Entity "${d.name}" with id "${d.id}" is abstract but is extending an non-abstract entity "${p.name}" with id "${p.id}"`,severity:ce.Error,code:be.AbstractExtendingNonAbstractEntity,entity:d,firstRelationship:p});return i.push(c.error),i}d.properties.forEach(c=>{const e=p.properties.find(y=>{var v;return y.name===c.name&&((v=c.extends)==null?void 0:v.id)!==y.id});c.implements.find(y=>y.id===(e==null?void 0:e.id))||e&&r.push(c)}),r.length&&r.forEach(c=>{const e=Ut({id:d.id+"--"+Re.PropertyOverwritesOtherSiblingWithSameName,message:`Property "${c.name}" with id "${c.id}" of entity "${d.name}" with id "${d.id}" overwrites the property with the same name from the extended entity "${p.name}" with id "${p.id}"`,severity:ce.Error,code:Re.PropertyOverwritesOtherSiblingWithSameName,entity:d});i.push(e.error)});const l=[];return d.methods.forEach(c=>{var y;const e=p.methods.find(v=>{var b;return v.name===c.name&&((b=c.extends)==null?void 0:b.id)!==v.id});((y=c.implements)==null?void 0:y.id)!==(e==null?void 0:e.id)&&e&&l.push(c)}),l.length&&l.forEach(c=>{const e=Ut({id:d.id+"--"+Re.MethodOverwritesOtherSiblingWithSameName,message:`Method "${c.name}" with id "${c.id}" of entity "${d.name}" with id "${d.id}" overwrites the method with the same name from the extended entity "${p.name}" with id "${p.id}"`,severity:ce.Error,code:Re.MethodOverwritesOtherSiblingWithSameName,entity:d});i.push(e.error)}),i}function f2t(d){const p=[];if(!d.properties.length){const i=Ut({id:d.id+"--"+be.NoProperties,message:"No properties implemented",severity:ce.Warning,code:be.NoProperties,entity:d});p.push(i.error)}return d.properties.forEach(i=>{i.validate()}),p}function y2t(d){const p=[];if(d.abstract){if(d.methods.length){const i=Ut({id:d.id+"--"+be.AbstractEntityWithNonAbstractMethods,message:`Entity "${d.name}" with id "${d.id}" is marked as abstract but has non-abstract methods`,severity:ce.Error,code:be.AbstractEntityWithNonAbstractMethods,entity:d});p.push(i.error)}if(d.properties.some(i=>!i.abstract)){const i=Ut({id:d.id+"--"+be.AbstractEntityWithNonAbstractProperties,message:`Entity "${d.name}" with id "${d.id}" is marked as abstract but has non-abstract properties`,severity:ce.Error,code:be.AbstractEntityWithNonAbstractProperties,entity:d});p.push(i.error),d.properties.forEach(r=>{if(!r.abstract){const l=Ut({id:d.id+"--"+be.StaticEntityWithNonStaticProperties+"--"+r.id,message:`Property "${r.name}" with id "${r.id}" of entity "${d.name}" with id "${d.id}" is not marked as abstract but the entity is marked as abstract`,severity:ce.Error,code:be.StaticEntityWithNonStaticProperties,entity:d});p.push(l.error)}})}}else{if(d.abstractMethods.length){const i=Ut({id:d.id+"--"+be.AbstractPropertyInNonAbstractEntity,message:`Entity "${d.name}" with id "${d.id}" is not marked as abstract but has abstract methods`,severity:ce.Error,code:be.AbstractPropertyInNonAbstractEntity,entity:d});p.push(i.error)}d.properties.some(i=>i.abstract)&&d.properties.forEach(i=>{if(i.abstract){const r=Ut({id:d.id+"--"+be.AbstractPropertyInNonAbstractEntity+"--"+i.id,message:`Property "${i.name}" with id "${i.id}" of entity "${d.name}" with id "${d.id}" is marked as abstract but the entity is not marked as abstract`,severity:ce.Error,code:be.AbstractPropertyInNonAbstractEntity,entity:d,firstRelationship:i});p.push(r.error)}})}return d.static&&d.properties.some(i=>!i.static)&&d.properties.forEach(i=>{if(!i.static){const r=Ut({id:d.id+"--"+be.NonStaticPropertyInStaticEntity+"--"+i.id,message:`Property "${i.name}" with id "${i.id}" of entity "${d.name}" with id "${d.id}" is not marked as static but the entity is marked as static`,severity:ce.Error,code:be.NonStaticPropertyInStaticEntity,entity:d,firstRelationship:i});p.push(r.error)}}),p}function h2t(d,p){const i=[],r=Hr(p);if(!p.abstract){const e=new $i({id:d.id+"--"+p.id+"--"+be.ImplementingNonAbstractEntity,message:`Entity "${d.name}" with id "${d.id}" is implementing a non-abstract built-in entity "${p.name}" with id "${p.id}"`,severity:ce.Error,code:be.ImplementingNonAbstractEntity,entity:d,firstRelationship:p});i.push(e)}const l=d.implements.filter(e=>e.id!==p.id);if(d.abstract){const e=new $i({id:d.id+"--"+p.id+"--"+be.AbstractEntityImplements,message:`Entity "${d.name}" with id "${d.id}" is marked as abstract and cannot implement built-in entity "${p.name}" with id "${p.id}"`,severity:ce.Error,code:be.AbstractEntityImplements,entity:d,firstRelationship:p});i.push(e)}if(d.static&&!p.static){const e=new $i({id:d.id+"--"+p.id+"--"+be.StaticImplementingNonStaticEntity,message:`Entity "${d.name}" with id "${d.id}" is marked as static and cannot implement non-static built-in entity "${p.name}" with id "${p.id}"`,severity:ce.Error,code:be.StaticImplementingNonStaticEntity,entity:d,firstRelationship:p});i.push(e)}if(!d.static&&p.static){const e=new $i({id:d.id+"--"+p.id+"--"+be.NonStaticImplementingStaticEntity,message:`Entity "${d.name}" with id "${d.id}" is not marked as static and cannot implement static built-in entity "${p.name}" with id "${p.id}"`,severity:ce.Error,code:be.NonStaticImplementingStaticEntity,entity:d,firstRelationship:p});i.push(e)}return l.length&&l.forEach(e=>{if(e.type===o.BuiltInBaseEntity){const y=r.filter(v=>v.id!==e.id);y.length&&y.forEach(v=>{if(v.id!==e.id){const b=new $i({id:d.id+"--"+v.id+"--"+e.id+"--"+be.ImplementsIncompatibleEntities,message:`Entity "${d.name}" with id "${d.id}" is implementing built-in entity "${v.name}" with id "${v.id}" but also implements entity "${e.name}" with id "${e.id}" which is incompatible`,severity:ce.Error,code:be.ImplementsIncompatibleEntities,entity:d,firstRelationship:v,secondRelationship:e});i.push(b)}})}else{Hr(e).forEach(A=>{const E=r.filter(w=>w.id!==A.id);E.length&&E.forEach(w=>{if(w.id!==A.id){const P=new $i({id:d.id+"--"+w.id+"--"+A.id+"--"+be.ImplementsIncompatibleEntities,message:`Entity "${d.name}" with id "${d.id}" is implementing built-in entity "${w.name}" with id "${w.id}" but also implements entity "${A.name}" with id "${A.id}" which is incompatible`,severity:ce.Error,code:be.ImplementsIncompatibleEntities,entity:d,firstRelationship:w,secondRelationship:A});i.push(P)}})});const v=jd(p.ownDeclaredProperties,e.ownDeclaredProperties,Re.PropertyOverwritesOtherImplementedEntitysPropertyWithSameImplementation,Re.PropertyOverwritesOtherImplementedEntitysPropertyWithSameName);i.push(...v.errors);const b=jd(p.abstractMethods,[...e.abstractMethods,...e.methods],Re.MethodOverwritesOtherImplementedEntitysMethodWithSameImplementation,Re.MethodOverwritesOtherImplementedEntitysMethodWithSameName);i.push(...b.errors)}}),O(d.extends?Hr(d.extends):[]).forEach(e=>{if(!r.find(y=>y.id===e.id)){const y=new $i({id:d.id+"--"+p.id+"--"+e.id+"--"+be.ExtendsIncompatibleEntities,message:`Entity "${d.name}" with id "${d.id}" is implementing built-in entity "${p.name}" with id "${p.id}" but also extends entity "${e.name}" with id "${e.id}" which is incompatible`,severity:ce.Error,code:be.ExtendsIncompatibleEntities,entity:d,firstRelationship:p,secondRelationship:e});i.push(y)}}),i}function m2t(d,p,i=!1){var b,A;const r=[],l=Hr(p);if(!d.abstract&&p.abstract){const E=Ut({id:d.id+"--"+p.id+"--"+be.NonAbstractExtendingAbstractEntity,message:`Entity "${d.name}" with id "${d.id}" is not-abstract but is extending an abstract entity "${p.name}" with id "${p.id}"`,severity:ce.Error,code:be.NonAbstractExtendingAbstractEntity,entity:d,firstRelationship:p});r.push(E.error)}if(d.abstract&&!p.abstract){const E=Ut({id:d.id+"--"+p.id+"--"+be.AbstractExtendingNonAbstractEntity,message:`Entity "${d.name}" with id "${d.id}" is abstract but is extending an non-abstract entity "${p.name}" with id "${p.id}"`,severity:ce.Error,code:be.AbstractExtendingNonAbstractEntity,entity:d,firstRelationship:p});r.push(E.error)}if(!d.static&&p.static){const E=Ut({id:d.id+"--"+p.id+"--"+be.NonStaticExtendingStaticEntity,message:`Entity "${d.name}" with id "${d.id}" is not static but is extending a static entity "${p.name}" with id "${p.id}"`,severity:ce.Error,code:be.NonStaticExtendingStaticEntity,entity:d,firstRelationship:p});r.push(E.error)}if(d.static&&!p.static){const E=Ut({id:d.id+"--"+p.id+"--"+be.StaticExtendingNonStaticEntity,message:`Entity "${d.name}" with id "${d.id}" is static but is extending an non-static entity "${p.name}" with id "${p.id}"`,severity:ce.Error,code:be.StaticExtendingNonStaticEntity,entity:d,firstRelationship:p});r.push(E.error)}if(!Bc(p)){const E=Ut({id:d.id+"--"+p.id+"--"+be.ExtendingNonInteractiveEntity,message:`Entity "${d.name}" with id "${d.id}" is extending an non-interactive entity "${p.name}" with id "${p.id}"`,severity:ce.Error,code:be.ExtendingNonInteractiveEntity,entity:d,firstRelationship:p});r.push(E.error)}if(d.extends&&((b=d.extends)==null?void 0:b.id)!==p.id)if(((A=d.extends)==null?void 0:A.type)===o.BuiltInBaseEntity){const E=l.filter(w=>{var P;return w.id!==((P=d.extends)==null?void 0:P.id)});E.length&&E.forEach(w=>{var P,x,M,k;if(w.id!==((P=d.extends)==null?void 0:P.id)){const q=Ut({id:d.id+"--"+w.id+"--"+((x=d.extends)==null?void 0:x.id)+"--"+be.ExtendsIncompatibleEntities,message:`Entity "${d.name}" with id "${d.id}" is extending built-in entity "${w.name}" with id "${w.id}" but also extends entity "${(M=d.extends)==null?void 0:M.name}" with id "${(k=d.extends)==null?void 0:k.id}" which is incompatible`,severity:ce.Error,code:be.ExtendsIncompatibleEntities,entity:d,firstRelationship:w,secondRelationship:d.extends});r.push(q.error)}})}else{Hr(d.extends).forEach(q=>{const Z=l.filter(X=>X.id!==q.id);Z.length&&Z.forEach(X=>{if(X.id!==q.id){const se=new $i({id:d.id+"--"+X.id+"--"+q.id+"--"+be.ImplementsIncompatibleEntities,message:`Entity "${d.name}" with id "${d.id}" is extending built-in entity "${X.name}" with id "${X.id}" but also extends or implements entity "${q.name}" with id "${q.id}" which is incompatible`,severity:ce.Error,code:be.ImplementsIncompatibleEntities,entity:d,firstRelationship:X,secondRelationship:q});r.push(se)}})});const w=!!Hr(d.extends).find(q=>q.id===p.id);let P=[...d.extends.properties];w&&(P=P.filter(q=>!p.properties.find(Z=>Z.id===q.id||Z.name===q.name||!!q.implements.find(X=>X.id===Z.id))));let x=[...d.extends.methods];w&&(x=x.filter(q=>!p.methods.find(Z=>{var X;return Z.id===q.id||Z.name===q.name||Z.id===((X=q.implements)==null?void 0:X.id)})));const M=jd(p.ownDeclaredProperties,P,Re.PropertyOverwritesOtherExtendedEntitysPropertyWithSameImplementation,Re.PropertyOverwritesOtherExtendedEntitysPropertyWithSameName);r.push(...M.errors);const k=jd(p.abstractMethods,x,Re.MethodOverwritesOtherExtendedEntitysMethodWithSameImplementation,Re.MethodOverwritesOtherExtendedEntitysMethodWithSameName);r.push(...k.errors)}i&&ae.log("self.implements.length",d.implements.length),d.implements.length&&d.implements.forEach(E=>{if(E.type===o.BuiltInBaseEntity){const w=l.filter(P=>P.id!==E.id);w.length&&w.forEach(P=>{if(P.id!==E.id){const x=new $i({id:d.id+"--"+P.id+"--"+E.id+"--"+be.ImplementsIncompatibleEntities,message:`Entity "${d.name}" with id "${d.id}" is implementing built-in entity "${P.name}" with id "${P.id}" but also implements entity "${E.name}" with id "${E.id}" which is incompatible`,severity:ce.Error,code:be.ImplementsIncompatibleEntities,entity:d,firstRelationship:P,secondRelationship:E});r.push(x)}})}else{Hr(E).forEach(M=>{const k=l.filter(q=>q.id!==M.id);k.length&&k.forEach(q=>{if(q.id!==M.id){const Z=new $i({id:d.id+"--"+q.id+"--"+M.id+"--"+be.ImplementsIncompatibleEntities,message:`Entity "${d.name}" with id "${d.id}" is implementing built-in entity "${q.name}" with id "${q.id}" but also implements entity "${M.name}" with id "${M.id}" which is incompatible`,severity:ce.Error,code:be.ImplementsIncompatibleEntities,entity:d,firstRelationship:q,secondRelationship:M});r.push(Z)}})});const P=jd(p.ownDeclaredProperties,E.ownDeclaredProperties,Re.PropertyOverwritesOtherImplementedEntitysPropertyWithSameImplementation,Re.PropertyOverwritesOtherImplementedEntitysPropertyWithSameName);r.push(...P.errors);const x=jd(p.abstractMethods,[...E.abstractMethods,...E.methods],Re.MethodOverwritesOtherImplementedEntitysMethodWithSameImplementation,Re.MethodOverwritesOtherImplementedEntitysMethodWithSameName);r.push(...x.errors)}});const e=jd(d.ownDeclaredProperties,p.ownDeclaredProperties,Re.PropertyOverwritesOtherSiblingWithSameImplementation,Re.PropertyOverwritesOtherSiblingWithSameName);r.push(...e.errors);const y=jd(p.methods,p.abstractMethods,Re.MethodOverwritesOtherSiblingWithSameImplementation,Re.MethodOverwritesOtherSiblingWithSameName);return r.push(...y.errors),O(d.extends?Hr(d.extends):[]).forEach(E=>{if(!l.find(w=>w.id===E.id)){const w=new $i({id:d.id+"--"+p.id+"--"+E.id+"--"+be.ImplementsIncompatibleEntities,message:`Entity "${d.name}" with id "${d.id}" is extending built-in entity "${p.name}" with id "${p.id}" but also extends entity "${E.name}" with id "${E.id}" which is incompatible`,severity:ce.Error,code:be.ImplementsIncompatibleEntities,entity:d,firstRelationship:p,secondRelationship:E});r.push(w)}}),r}function T2t(d){const p=[];if(d.implements.forEach(i=>{if(!i.static){const r=new $i({id:d.id+"--"+i.id+"--"+be.StaticImplementingNonStaticEntity,message:`Entity "${d.name}" with id "${d.id}" is static but implements entity "${i.name}" with id "${i.id}" which is non-static`,severity:ce.Error,code:be.StaticImplementingNonStaticEntity,entity:d,firstRelationship:i});p.push(r)}}),d.extends&&!d.extends.static){const i=new $i({id:d.id+"--"+d.extends.id+"--"+be.StaticExtendingNonStaticEntity,message:`Entity "${d.name}" with id "${d.id}" is static but extends entity "${d.extends.name}" with id "${d.extends.id}" which is non-static`,severity:ce.Error,code:be.StaticExtendingNonStaticEntity,entity:d,firstRelationship:d.extends});p.push(i)}return p}function v2t(d){const p=[];if(d.implements.length){const i=new $i({id:d.id+"--"+be.AbstractEntityImplements,message:`Entity "${d.name}" with id "${d.id}" cannot be marked as abstract because it implements other entities`,severity:ce.Error,code:be.AbstractEntityImplements,entity:d});p.push(i)}if(d.extends&&!d.extends.abstract){const i=new $i({id:d.id+"--"+d.extends.id+"--"+be.AbstractExtendingNonAbstractEntity,message:`Entity "${d.name}" with id "${d.id}" is abstract but extends entity "${d.extends.name}" with id "${d.extends.id}" which is non-abstract`,severity:ce.Error,code:be.AbstractExtendingNonAbstractEntity,entity:d,firstRelationship:d.extends});p.push(i)}return p}function b2t(d){const p=[];if(d.extends&&d.extends.static){const i=new $i({id:d.id+"--"+d.extends.id+"--"+be.NonStaticExtendingStaticEntity,message:`Entity "${d.name}" with id "${d.id}" is non-static but extends entity "${d.extends.name}" with id "${d.extends.id}" which is static`,severity:ce.Error,code:be.NonStaticExtendingStaticEntity,entity:d,firstRelationship:d.extends});p.push(i)}return p}function E2t(d){const p=[];if(d.extends&&d.extends.abstract){const i=new $i({id:d.id+"--"+d.extends.id+"--"+be.NonAbstractExtendingAbstractEntity,message:`Entity "${d.name}" with id "${d.id}" is non-abstract but extends entity "${d.extends.name}" with id "${d.extends.id}" which is abstract`,severity:ce.Error,code:be.NonAbstractExtendingAbstractEntity,entity:d,firstRelationship:d.extends});p.push(i)}return p}function Rxe(d,p){const r=[...d.project.entities].filter(l=>l.id!==d.id);return xT(d,[Ji,Uc],r,p)}const A2t=Object.freeze(Object.defineProperty({__proto__:null,getBaseMethodsNotImplemented:Ixe,getBasePropertiesNotImplemented:gxe,validate:Axe,validateCanBecomeAbstract:v2t,validateCanBecomeNonAbstract:E2t,validateCanBecomeNonStatic:b2t,validateCanBecomeStatic:T2t,validateCanExtendEntity:m2t,validateCanImplementEntity:h2t,validateDefinitionEntityName:Rxe},Symbol.toStringTag,{value:"Module"}));function g2t(d,p){const i=[];if(d.parent)if(d.id===d.parent)i.push(new Oe({id:`${d.id}--${d.parent}--${re.SelfReference}`,code:re.SelfReference,severity:ce.Error,message:`Entity of type "${d.type}" with id "${d.id}", has a reference to itself at 'parent'. This is not allowed. Change the reference string or the 'entityId' property of the reference object.`}));else{const r=p.get(d.parent);r?[o.Project,o.DataType].includes(r.type)||i.push(new Oe({id:`${d.id}--${d.parent}--${re.InvalidParentReference}`,code:re.InvalidParentReference,severity:ce.Error,message:`Entity of type "${d.type}" with id "${d.id}", has a parent reference that isn't pointing to an entity of type 'project' or 'data-type'.`})):i.push(new Oe({id:`${d.id}--${d.parent}--${re.ReferencedEntityNotFound}`,code:re.ReferencedEntityNotFound,severity:ce.Error,message:`Entity of type "${d.type}" with id "${d.id}", is referencing an entity with id "${d.parent}" that isn't yet found in the project. Perhaps it should be created first. Or perhaps the ID is incorrect.`}))}return d.implements&&Array.isArray(d.implements)?d.implements.forEach(r=>{if(d.id===r){i.push(new Oe({id:`${d.id}--${r}--${re.SelfReference}`,code:re.SelfReference,severity:ce.Error,message:`Entity of type "${d.type}" with id "${d.id}", has a reference to itself at one of the 'implements' references. This is not allowed. Change the reference string or the 'entityId' property of the reference object.`}));return}const l=p.get(r);l?[o.DefinitionEntity,o.BuiltInBaseEntity].includes(l.type)?l.abstract||i.push(new Oe({id:`${d.id}--${r}--${re.InvalidImplementsReference}`,code:re.InvalidImplementsReference,severity:ce.Error,message:`Entity of type "${d.type}" with id "${d.id}", has an 'implements' reference that isn't pointing to an abstract entity.`})):i.push(new Oe({id:`${d.id}--${r}--${re.InvalidImplementsReference}`,code:re.InvalidImplementsReference,severity:ce.Error,message:`Entity of type "${d.type}" with id "${d.id}", has an 'implements' reference that isn't pointing to an entity of type 'definition-entity' or 'built-in-base-entity'.`})):i.push(new Oe({id:`${d.id}--${r}--${re.ReferencedEntityNotFound}`,code:re.ReferencedEntityNotFound,severity:ce.Error,message:`Entity of type "${d.type}" with id "${d.id}", is referencing an entity with id "${r}" that isn't yet found in the project. Perhaps it should be created first. Or perhaps the ID is incorrect.`}))}):i.push(new Oe({id:`${d.id}--${Re.InvalidObjectStructure}`,code:Re.InvalidObjectStructure,severity:ce.Error,message:`Entity of type "${d.type}" with id "${d.id}", has an 'implements' property that isn't an array.`})),d.extends&&Array.isArray(d.extends)&&d.extends.forEach(r=>{const l=p.get(r);l?[o.DefinitionEntity,o.BuiltInBaseEntity].includes(l.type)?l.abstract&&i.push(new Oe({id:`${d.id}--${r}--${re.InvalidExtendsReference}`,code:re.InvalidExtendsReference,severity:ce.Error,message:`Entity of type "${d.type}" with id "${d.id}", has an 'extends' reference that isn't pointing to a non-abstract entity. Did you want to use the property 'implements', which holds a list of references to absract entities, instead?`})):i.push(new Oe({id:`${d.id}--${r}--${re.InvalidExtendsReference}`,code:re.InvalidExtendsReference,severity:ce.Error,message:`Entity of type "${d.type}" with id "${d.id}", has an 'extends' reference that isn't pointing to an entity of type 'definition-entity' or 'built-in-base-entity'.`})):i.push(new Oe({id:`${d.id}--${r}--${re.ReferencedEntityNotFound}`,code:re.ReferencedEntityNotFound,severity:ce.Error,message:`Entity of type "${d.type}" with id "${d.id}", is referencing an entity with id "${r}" that isn't yet found in the project. Perhaps it should be created first. Or perhaps the ID is incorrect.`}))}),i}var qg=(d=>(d.Extends="extends",d.Implements="implements",d))(qg||{});const bi=class bi extends Un{constructor(i,r){super(i);R(this,"initialData");R(this,"id");R(this,"name");R(this,"codeName",null);R(this,"description",null);R(this,"x");R(this,"y");R(this,"static");R(this,"abstract");R(this,"type",o.DefinitionEntity);R(this,"additionalProperties",!1);R(this,"properties",[]);R(this,"allPropertiesImplement",null);R(this,"additionalPropertiesDataType",null);R(this,"methods",[]);R(this,"abstractMethods",[]);R(this,"extends",null);R(this,"implements",[]);R(this,"project");R(this,"errors",[]);R(this,"parent");R(this,"detachedDependents",{});R(this,"knownVersions",null);R(this,"activeVersion",!1);R(this,"initialized",!1);R(this,"startedInitialization",!1);R(this,"suggestedProperties",[]);R(this,"suggestedMethods",[]);this.initialData=i,this.project=r,this.id=i.id,this.name=i.name,this.description=i.description,this.x=i.x,this.y=i.y,this.codeName=i.codeName,this.static=i.static,this.abstract=i.abstract}static new(i=null){return{id:L.UUID.uuid(),version:L.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||B().toISOString(),author:(i==null?void 0:i.author)||L.sessionAuthor,previousVersion:null,deleted:!1,deletable:!0,editable:!0,type:o.DefinitionEntity,additionalProperties:!1,additionalPropertiesDataType:null,allPropertiesImplement:null,name:"",codeName:null,description:"",static:!1,abstract:!1,properties:[],methods:[],abstractMethods:[],extends:null,implements:[],x:0,y:0,parent:null}}static fromGenerationTarget(i,r){let l=r;if(i.parent){const b=ye(i.parent);l=r.get(b)}const c=[];i.implements&&i.implements.forEach(b=>{c.push(r.get(b)||r.getBuiltIn(b))});let e=null;i.extends&&(e=r.get(i.extends)||r.getBuiltIn(i.extends));const y={id:i.id,version:L.UUID.uuid(),createdAt:B().toISOString(),author:L.sessionAuthor,previousVersion:null,deleted:!1,name:i.name,deletable:!0,editable:!0,type:o.DefinitionEntity,codeName:i.codeName||null,description:i.description,static:i.static,abstract:i.abstract,additionalProperties:i.additionalProperties||!1,allPropertiesImplement:null,additionalPropertiesDataType:null,properties:[],methods:[],abstractMethods:[],extends:e,implements:c,x:0,y:0,parent:l},v=me(y,r);return v.setParent(l,null),v}static validateGenerationTarget(i,r){let l=JSON.parse(JSON.stringify(i));const c=[],e=g2t(l,r),y=lP(l,r);c.push(...e,...y,...Pn(l));const v=l.parent?r.get(l.parent):null;if(v&&v.type===o.DataType){const b=v;b.entity&&c.push(new Oe({id:`${i.id}--${re.NewEntityWouldOverriteExisting}`,code:re.NewEntityWouldOverriteExisting,severity:ce.Error,message:`The entity of type '${i.type}' with id '${i.id}' can't be added to the 'parent' entity with id '${b.id}' because it already has an 'entity' child. Data type entities can only have one 'entity' as children.
391
391
  You can inspect the existing 'entity' field with the 'describe_entity' action. Like so:
392
392
  ${No({describe_entity:b.entity.id})}
393
393
  Alternatively you can update the parent data-type entity with 'update' action to remove the existing value of the field.`}))}return{errors:c,modifiedData:l}}get interactive(){return this.implements.length?this.implements.every(i=>i.interactive):!0}get allMethods(){return O([...this.ownDeclaredMethods,...this.allBaseMethodsFromOriginalParents])}get allProperties(){return O([...this.ownDeclaredProperties,...this.allBasePropertiesFromOriginalParents])}get allBaseMethodsFromOriginalParents(){var l;const i=((l=this.extends)==null?void 0:l.type)===o.DefinitionEntity?this.extends.allMethods:[],r=[...i].filter(c=>!i.some(e=>{var y,v;return e.id!==c.id&&(((y=e.implements)==null?void 0:y.id)===c.id||((v=e.extends)==null?void 0:v.id)===c.id)}));return O([...r,...this.implements.flatMap(c=>{const e=c.type===o.DefinitionEntity?[...c.allMethods]:[];return[...e].filter(v=>!e.some(b=>{var A,E;return b.id!==v.id&&(((A=b.implements)==null?void 0:A.id)===v.id||((E=b.extends)==null?void 0:E.id)===v.id)}))})])}get allBasePropertiesFromOriginalParents(){var c;const i=((c=this.extends)==null?void 0:c.allProperties)||[],r=[...i].filter(e=>!i.some(y=>{var v;return y.id!==e.id&&(!!y.implements.find(b=>b.id===e.id)||((v=y.extends)==null?void 0:v.id)===e.id)}));return O([...r,...this.implements.flatMap(e=>{const y=[...e.allProperties];return[...y].filter(b=>!y.some(A=>{var E;return A.id!==b.id&&(!!A.implements.find(w=>w.id===b.id)||((E=A.extends)==null?void 0:E.id)===b.id)}))})])}get allBasePropertiesFromExtendedAndImplementedEntities(){var c,e;const i=[...((c=this.extends)==null?void 0:c.ownDeclaredProperties)||[],...((e=this.extends)==null?void 0:e.allBasePropertiesFromExtendedAndImplementedEntities)||[]].filter(y=>!y.abstract),r=[...i].filter(y=>!i.some(v=>{var b;return v.id!==y.id&&(!!v.implements.find(A=>A.id===y.id)||((b=v.extends)==null?void 0:b.id)===y.id)})),l=this.implements.reduce((y,v)=>{const b=v.implementedPropertiesFromOriginalParents,A=[...v.ownDeclaredProperties].filter(P=>!P.abstract),E=[...b,...A,...y];return[...E].filter(P=>!!!E.find(M=>{var k;return!!M.implements.find(q=>q.id===P.id)||((k=M.extends)==null?void 0:k.id)===P.id}))},[]);return O([...r,...l])}get allBaseMethodsFromExtendedAndImplementedEntities(){return O([...(this.extends?[this.extends]:[]).reduce((i,r)=>r.type!==o.DefinitionEntity?[]:[...[...r.ownDeclaredMethods,...r.allBaseMethodsFromExtendedAndImplementedEntities].filter(c=>c.type!==o.ActionDescriptor),...i],[]),...this.implements.reduce((i,r)=>r.type!==o.DefinitionEntity?r.abstractMethods:[...[...r.ownDeclaredMethods,...r.allBaseMethodsFromExtendedAndImplementedEntities].filter(c=>c.type!==o.ActionDescriptor),...i],[])])}get extendedPropertiesFromOriginalParents(){var l,c;const i=[...((l=this.extends)==null?void 0:l.ownDeclaredProperties)||[],...((c=this.extends)==null?void 0:c.extendedPropertiesFromOriginalParents)||[]].filter(e=>!e.abstract),r=[...i].filter(e=>!i.some(y=>{var v;return y.id!==e.id&&(!!y.implements.find(b=>b.id===e.id)||((v=y.extends)==null?void 0:v.id)===e.id)}));return O(r)}get implementedPropertiesFromOriginalParents(){return O([...(this.extends?[this.extends]:[]).reduce((i,r)=>{const l=r.implementedPropertiesFromOriginalParents,c=[...r.ownDeclaredProperties].filter(v=>!!v.abstract),e=[...l,...c,...i];return[...e].filter(v=>!!!e.find(A=>{var E;return((E=A.extends)==null?void 0:E.id)===v.id||!!A.implements.find(w=>w.id===v.id)}))},[]),...this.implements.reduce((i,r)=>{const l=r.implementedPropertiesFromOriginalParents,c=[...r.ownDeclaredProperties].filter(v=>!!v.abstract),e=[...l,...c,...i];return[...e].filter(v=>!!!e.find(A=>{var E;return!!A.implements.find(w=>w.id===v.id)||((E=A.extends)==null?void 0:E.id)===v.id}))},[])].filter(i=>!!i.abstract))}get extendedMethodsFromOriginalParents(){return O((this.extends?[this.extends]:[]).reduce((i,r)=>{if(r.type!==o.DefinitionEntity)return[];const l=[...r.ownDeclaredMethods,...r.extendedMethodsFromOriginalParents].filter(c=>c.type!==o.ActionDescriptor);return[...i,...l]},[]))}get implementedMethodsFromOriginalParents(){return O([...(this.extends?[this.extends]:[]).reduce((i,r)=>{const l=r.type===o.DefinitionEntity?r.methods:[],c=[...r.abstractMethods].filter(e=>!l.find(y=>y.name===e.name));return[...l,...c,...i]},[]),...this.implements.reduce((i,r)=>[...r.abstractMethods,...i],[])].filter(i=>i.type===o.ActionDescriptor))}get extendedProperties(){return this.properties.filter(i=>i.isExtendedProperty)}get ownDeclaredProperties(){return this.properties.filter(r=>!r.isExtendedProperty)}get extendedMethods(){return this.methods.filter(i=>i.isExtendedMethod)}get ownDeclaredMethods(){return this.methods.filter(i=>!i.isExtendedMethod)}validateGeneratedUpdate(i){const r=[];return i.parent&&r.push(new Oe({id:`${this.id}--${re.InvalidParentUpdate}`,code:re.InvalidParentUpdate,severity:ce.Error,message:`Entity of type '${this.type}' with id '${this.id}' cannot have the 'parent' property updated. The 'parent' on an '${this.type}', must be the root project as it is a globally declared entity.`})),{errors:r,modifiedData:i}}subscribeDependents(i){return i.forEach(r=>{this.detachedDependents[r.entity.id]||(this.detachedDependents[r.entity.id]=r)}),this}unsubscribeDependents(i){return i.forEach(r=>{this.detachedDependents[r.entity.id]&&delete this.detachedDependents[r.entity.id]}),this}syncDependents(i=this.project.addChangeSet(new H(this.project,L.sessionAuthor,B().toISOString(),this,!0,"sync-dependents"))){const r=[],l=[],c=[],e=[];return Object.values(this.detachedDependents).forEach(y=>{const v=y.entity.afterAllChildrenInitialized(i);r.push(...v.updated),l.push(...v.added),c.push(...v.removed),e.push(...v.affected)}),i==null||i.attemptAutoclose("sync-dependents",this.id),{updated:O(r),added:O(l),removed:O(c),affected:O(e),self:this}}onDetachedDependencyRemoved(i,r,l){const c=[],e=[],y=[],v=[];return r==="implements"&&(this.removeImplementation(i,l),c.push(this)),r==="extends"&&(this.setExtension(null,l),c.push(this)),{updated:O(c),added:O(e),removed:O(y),affected:O(v),self:this}}onDetachedDependencyRestored(i,r,l){const c=[],e=[],y=[],v=[];return r==="implements"&&(this.addImplementation(i,l),c.push(this)),r==="extends"&&(this.setExtension(i,l),c.push(this)),{updated:O(c),added:O(e),removed:O(y),affected:O(v),self:this}}unsubscribeFromDependencies(){return this.implements.forEach(i=>{aa.includes(i.type)||i.unsubscribeDependents([{entity:this,field:"implements"}])}),this}subscribeToDependencies(){return this.implements.forEach(i=>{aa.includes(i.type)||i.subscribeDependents([{entity:this,field:"implements"}])}),this.extends&&(aa.includes(this.extends.type)||this.extends.subscribeDependents([{entity:this,field:"extends"}])),this}increaseVersion(i){if(i&&!B(i).isValid())throw new Error(`The shared timestamp '${i}' is not a valid ISO 8601 date string.`);return i&&B(i).isSame(B(this.createdAt))?this:(this.previousVersion=this.version,this.version=L.UUID.uuid(),this.createdAt=B(i).toISOString()||B().toISOString(),this)}captureVersion(){var r;const i=((r=this.knownVersions)==null?void 0:r.get(this.version))||new bi(this,this.project);return i.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,i):new Map([[this.version,i]]),i.properties=[...this.properties],i.methods=[...this.methods],i.abstractMethods=[...this.abstractMethods],i.extends=this.extends,i.implements=[...this.implements],i.allPropertiesImplement=this.allPropertiesImplement,i.additionalPropertiesDataType=this.additionalPropertiesDataType,i.parent=this.parent,this}recursiveCaptureUpstreamVersions(i){const r=[],l=[],c=[],e=[];if(this.parent){this.parent.increaseVersion(i);const y=this.parent.recursiveCaptureUpstreamVersions(i);r.push(this.parent,...y.updated),l.push(...y.added),c.push(...y.removed)}return{updated:O(r),added:O(l),removed:O(c),affected:O(e),self:this}}async restoreVersion(i){var v;const r=[],l=[],c=[],e=[];if(this.version===i)return{updated:O(r),added:O(l),removed:O(c),affected:O(e),self:this};if(!this.knownVersions){const b=new Map;for(const[A,E]of this.knownVersions||new Map){if(b.set(A,E),E.activeVersion=!1,E.knownVersions)for(const[w,P]of E.knownVersions)b.set(w,P);E.knownVersions=null}}let y=(v=this.knownVersions)==null?void 0:v.get(i);if(!y){const b=await this.APILoadVersion({},i);if(!b)throw new Error(`Version with id '${i}' for entity with id '${this.id}' not found.`);y=new bi(b,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.properties=[...y.properties],this.methods=[...y.methods],this.abstractMethods=[...y.abstractMethods],this.extends=y.extends,this.implements=[...y.implements],this.allPropertiesImplement=y.allPropertiesImplement,this.additionalPropertiesDataType=y.additionalPropertiesDataType,this.parent=y.parent,{updated:O(r),added:O(l),removed:O(c),affected:O(e),self:this}}updateWithShallowTransfer(i,r=this.project.addChangeSet(new H(this.project,L.sessionAuthor,B().toISOString(),this,!0,V.UpdateWithShallowTransfer))){if(!this.checkCanEdit(this,r))return ae.warn(`[updateWithShallowTransfer] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),r==null||r.attemptAutoclose(V.UpdateWithShallowTransfer,this.id),this;if(this.metaSync(i,r),this.version=i.version,this.createdAt=i.createdAt,this.author=i.author,this.deleted=i.deleted,this.previousVersion=i.previousVersion,this.unsubscribeFromDependencies(),i.parent){const l=ye(i.parent),c=this.project.get(l),e=this.parent;if(e&&e.id!==(c==null?void 0:c.id)&&this.removeFromParent(r),c)this.setParent(c,r);else throw r==null||r.attemptAutoclose(V.UpdateWithShallowTransfer,this.id),new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw r==null||r.attemptAutoclose(V.UpdateWithShallowTransfer,this.id),new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(i.extends){const l=ye(i.extends),c=this.project.get(l);c&&this.setExtension(c,r)}if(i.implements.forEach(l=>{const c=ye(l),e=this.project.get(c);if(e)this.addImplementation(e,r);else throw new Error(`${Sn(this.type)} with id '${this.id}' has a 'implements' reference "${c}" which is missing in the project`)}),i.allPropertiesImplement){const l=ye(i.allPropertiesImplement),c=this.project.get(l);c&&this.setAllPropertiesImplement(c,r)}if(i.additionalPropertiesDataType){const l=ye(i.additionalPropertiesDataType),c=this.project.get(l);c&&this.setAdditionalPropertiesDataType(c,r)}return this.captureVersion(),this.subscribeToDependencies(),r==null||r.attemptAutoclose(V.UpdateWithShallowTransfer,this.id),this}hydrateAncestors(){const i=[],r=[],l=[],c=[];if(this.initialData.parent){const e=ye(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.extends){const e=ye(this.initialData.extends),y=this.project.get(e);y&&(this.setExtension(y,null),y.type!==o.BuiltInBaseEntity&&i.push(y))}return this.initialData.implements.forEach(e=>{const y=ye(e),v=this.project.get(y);if(v)this.addImplementation(v,null),v.type!==o.BuiltInBaseEntity&&i.push(v);else throw new Error(`${Sn(this.type)} with id '${this.id}' has a 'implements' reference "${y}" which is missing in the project`)}),{updated:O(i),added:O(r),removed:O(l),affected:O(c),self:this}}afterAllChildrenInitialized(i=this.project.addChangeSet(new H(this.project,L.sessionAuthor,B().toISOString(),this,!0,V.AfterAllChildrenInitialized))){if(!this.checkCanEdit(this,i))return ae.warn(`[afterAllChildrenInitialized] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(V.AfterAllChildrenInitialized,this.id),{updated:[],added:[],removed:[],affected:[],self:this};const r=[],l=[],c=[],e=[];this.initialized=!0;const{updated:y,added:v,removed:b,affected:A}=this.syncImplementationProperties(i);r.push(...y),l.push(...v),c.push(...b),e.push(...A);const{updated:E,added:w,removed:P,affected:x}=this.addExtendedProperties(i);r.push(...E),l.push(...w),c.push(...P),e.push(...x);const{updated:M,added:k,removed:q}=this.removeUnrecognizedProperties(i);r.push(...M),l.push(...k),c.push(...q);const{updated:Z,added:X,removed:se,affected:ee}=this.syncImplementationMethods(i);r.push(...Z),l.push(...X),c.push(...se),e.push(...ee);const{updated:he,added:de,removed:fe,affected:Te}=this.addExtendedMethods(i);r.push(...he),l.push(...de),c.push(...fe),e.push(...Te);const{updated:ne,added:ue,removed:Pe}=this.removeUnrecognizedMethods(i);return r.push(...ne),l.push(...ue),c.push(...Pe),this.addSuggestions(),this.properties.sort((Le,Ue)=>Le.index-Ue.index),this.captureVersion(),i==null||i.attemptAutoclose(V.AfterAllChildrenInitialized,this.id),{updated:O(r),added:O(l),removed:O(c),affected:O(e),self:this}}addSelfToProject(i=this.project.addChangeSet(new H(this.project,L.sessionAuthor,B().toISOString(),this,!0,"add-self-to-project"))){const r=[this],l=[],c=[],e=[];if(this.parent.type===o.DataType){const y=this.parent;y.entity=this,r.push(y)}else this.project.addDefinitionEntity(this);return this.subscribe(),this.subscribeToDependencies(),i==null||i.attemptAutoclose("add-self-to-project",this.id),{updated:O(r),added:O(l),removed:O(c),affected:O(e),self:this}}setParent(i,r=this.project.addChangeSet(new H(this.project,L.sessionAuthor,B().toISOString(),this,!0,V.SetParent))){var l;return this.checkCanEditWithCounterpartAndSideEffects(this,i,V.SetParent,r)?(((l=this.parent)==null?void 0:l.id)!==(i==null?void 0:i.id)&&(this.parent=i,r&&(r==null||r.add(this,W.Updated))),r==null||r.attemptAutoclose(V.SetParent,this.id),this):this}setExtension(i,r=this.project.addChangeSet(new H(this.project,L.sessionAuthor,B().toISOString(),this,!0,V.SetExtension))){var l;return this.checkCanEdit(this,r)?(((l=this.extends)==null?void 0:l.id)!==(i==null?void 0:i.id)&&(this.extends=i,r&&(r==null||r.add(this,W.Updated))),r==null||r.attemptAutoclose(V.SetExtension,this.id),this):(ae.warn(`[setExtension] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),r==null||r.attemptAutoclose(V.SetExtension,this.id),this)}addImplementation(i,r=this.project.addChangeSet(new H(this.project,L.sessionAuthor,B().toISOString(),this,!0,V.AddImplementation))){return this.checkCanEdit(this,r)?(this.implements.includes(i)||(this.implements.push(i),r==null||r.add(this,W.Updated)),r==null||r.attemptAutoclose(V.AddImplementation,this.id),this):(ae.warn(`[addImplementation] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),r==null||r.attemptAutoclose(V.AddImplementation,this.id),this)}removeImplementation(i,r=this.project.addChangeSet(new H(this.project,L.sessionAuthor,B().toISOString(),this,!0,V.RemoveImplementation))){return this.checkCanEdit(this,r)?(this.implements.includes(i)&&(this.implements=this.implements.filter(l=>l.id!==i.id),r==null||r.add(this,W.Updated)),r==null||r.attemptAutoclose(V.RemoveImplementation,this.id),this):(ae.warn(`[removeImplementation] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),r==null||r.attemptAutoclose(V.RemoveImplementation,this.id),this)}removeProperty(i,r=this.project.addChangeSet(new H(this.project,L.sessionAuthor,B().toISOString(),this,!0,V.RemoveProperty))){return this.checkCanEdit(this,r)?(this.properties.includes(i)&&(this.properties=this.properties.filter(l=>l.id!==i.id),r==null||r.add(this,W.Updated)),r==null||r.attemptAutoclose(V.RemoveProperty,this.id),this):(ae.warn(`[removeProperty] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),r==null||r.attemptAutoclose(V.RemoveProperty,this.id),this)}addMethod(i,r=this.project.addChangeSet(new H(this.project,L.sessionAuthor,B().toISOString(),this,!0,V.AddMethod))){return this.checkCanEdit(this,r)?(this.methods.includes(i)||(this.methods.push(i),this.suggestedMethods=this.suggestedMethods.filter(l=>l.name!==i.name),r==null||r.add(this,W.Updated)),r==null||r.attemptAutoclose(V.AddMethod,this.id),this):(ae.warn(`[addMethod] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),r==null||r.attemptAutoclose(V.AddMethod,this.id),this)}removeMethod(i,r=this.project.addChangeSet(new H(this.project,L.sessionAuthor,B().toISOString(),this,!0,V.RemoveMethod))){return this.checkCanEdit(this,r)?(this.methods.includes(i)&&(this.methods=this.methods.filter(l=>l.id!==i.id),r==null||r.add(this,W.Updated)),r==null||r.attemptAutoclose(V.RemoveMethod,this.id),this):(ae.warn(`[removeMethod] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),r==null||r.attemptAutoclose(V.RemoveMethod,this.id),this)}addProperty(i,r=this.project.addChangeSet(new H(this.project,L.sessionAuthor,B().toISOString(),this,!0,V.AddProperty))){return this.checkCanEdit(this,r)?(this.properties.includes(i)||(this.properties.push(i),this.suggestedProperties=this.suggestedProperties.filter(l=>l.name!==i.name),r==null||r.add(this,W.Updated)),r==null||r.attemptAutoclose(V.AddProperty,this.id),this):(ae.warn(`[addProperty] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),r==null||r.attemptAutoclose(V.AddProperty,this.id),this)}addSuggestedProperty(i){return this.suggestedProperties.includes(i)||this.suggestedProperties.push(i),this}addSuggestedMethod(i){return this.suggestedMethods.includes(i)||this.suggestedMethods.push(i),this}removeSuggestedProperty(i){return this.suggestedProperties=this.suggestedProperties.filter(r=>r.id!==i.id),this}removeSuggestedMethod(i){return this.suggestedMethods=this.suggestedMethods.filter(r=>r.id!==i.id),this}addAbstractMethod(i,r=this.project.addChangeSet(new H(this.project,L.sessionAuthor,B().toISOString(),this,!0,V.AddAbstractMethod))){return this.checkCanEdit(this,r)?(this.abstractMethods.includes(i)||(this.abstractMethods.push(i),r==null||r.add(this,W.Updated)),r==null||r.attemptAutoclose(V.AddAbstractMethod,this.id),this):(ae.warn(`[addAbstractMethod] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),r==null||r.attemptAutoclose(V.AddAbstractMethod,this.id),this)}removeAbstractMethod(i,r=this.project.addChangeSet(new H(this.project,L.sessionAuthor,B().toISOString(),this,!0,V.RemoveAbstractMethod))){return this.checkCanEdit(this,r)?(this.abstractMethods.includes(i)&&(this.abstractMethods=this.abstractMethods.filter(l=>l.id!==i.id),r==null||r.add(this,W.Updated)),r==null||r.attemptAutoclose(V.RemoveAbstractMethod,this.id),this):(ae.warn(`[removeAbstractMethod] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),r==null||r.attemptAutoclose(V.RemoveAbstractMethod,this.id),this)}initChildren(i=this.project.addChangeSet(new H(this.project,L.sessionAuthor,B().toISOString(),this,!0,"init-children"))){if(this.initialized||this.startedInitialization)return this;if(this.startedInitialization=!0,this.properties=this.initialData.properties.map(r=>{const l=me(r,this.project);return l.setParent(this,null),l.initChildren(i),l}),this.methods=this.initialData.methods.map(r=>{const l=me(r,this.project);return l.setParent(this,null),l.initChildren(i),l}),this.abstractMethods=this.initialData.abstractMethods.map(r=>{const l=me(r,this.project);return l.setParent(this,null),l.initChildren(i),l}),this.initialData.extends&&(this.extends=me(this.initialData.extends,this.project)),this.implements=this.initialData.implements.map(r=>me(r,this.project)),this.initialData.allPropertiesImplement){const r=me(this.initialData.allPropertiesImplement,this.project);r.setParent(this,null),r.initChildren(null),this.setAllPropertiesImplement(r,i)}if(this.initialData.additionalPropertiesDataType){const r=me(this.initialData.additionalPropertiesDataType,this.project);r.setParent(this,null),r.initChildren(null),this.setAdditionalPropertiesDataType(r,i)}return this.subscribeToDependencies(),this.afterAllChildrenInitialized(i),i==null||i.attemptAutoclose("init-children",this.id),this}removeUnrecognizedProperties(i=this.project.addChangeSet(new H(this.project,L.sessionAuthor,B().toISOString(),this,!0,"remove-unrecognized-properties"))){const r=[],l=[],c=[],e=[];let y=[...this.properties];y=y.filter(E=>E.parent.id===this.id),y=y.filter(E=>!E.isExtendedProperty);const v=this.implementedPropertiesFromOriginalParents,b=this.getAllPropertiesImplements();return y.filter(E=>this.interactive&&!E.implements.length?!1:!E.implements.find(P=>!!v.find(x=>x.id===P.id)||!!b.find(x=>x.id===P.id))).forEach(E=>{const w=E.remove({ignoreUpstream:!1},i);c.push(...w.removed),r.push(...w.updated)}),i==null||i.attemptAutoclose("remove-unrecognized-properties",this.id),{updated:O(r),added:O(l),removed:O(c),affected:O(e),self:this}}removeUnrecognizedMethods(i=this.project.addChangeSet(new H(this.project,L.sessionAuthor,B().toISOString(),this,!0,"remove-unrecognized-methods"))){const r=[],l=[],c=[],e=[];let y=[...this.methods];y=y.filter(b=>b.parent.id===this.id),y=y.filter(b=>!b.isExtendedMethod);const v=this.implementedMethodsFromOriginalParents;return y=y.filter(b=>this.interactive&&!b.implements?!1:!v.find(A=>{var E;return A.id===((E=b.implements)==null?void 0:E.id)})),y.forEach(b=>{const A=b.remove({ignoreUpstream:!1},i);c.push(...A.removed),r.push(...A.updated)}),i==null||i.attemptAutoclose("remove-unrecognized-methods",this.id),{updated:O(r),added:O(l),removed:O(c),affected:O(e),self:this}}syncImplementationMethods(i=this.project.addChangeSet(new H(this.project,L.sessionAuthor,B().toISOString(),this,!0,"sync-implementation-methods"))){const r=[],l=[],c=[],e=[],y=this.methods,v=this.implementedMethodsFromOriginalParents,b=[...this.allBaseMethodsFromExtendedAndImplementedEntities,...y];return v.filter(E=>!b.find(P=>{var x;return((x=P.implements)==null?void 0:x.id)===E.id})).forEach(E=>{if(this.methods.find(M=>{var k;return((k=M.implements)==null?void 0:k.id)===E.id}))return;const P=this.methods.find(M=>{var se,ee;if(M.name===E.name&&!M.implements)return!0;const k=qi(this,De.CRON_JOB),q=qi(this,De.HTTP_ENDPOINT),Z=((se=M.implements)==null?void 0:se.id)===Q["built-in-base-entity"].BUILT_IN_HTTP_ENDPOINT_ENTITY.methods.handler.id,X=((ee=M.implements)==null?void 0:ee.id)===Q["built-in-base-entity"].BUILT_IN_CRON_JOB_ENTITY.methods.handler.id;return!!(k&&!X&&!q&&Z||q&&!Z&&!k&&X)});if(P&&P.type===o.FunctionDeclaration){P.setImplements(E,i),P.metaSync({name:E.name},i),i==null||i.add(P,W.Updated),i==null||i.add(this,W.Updated);return}const x=E.implementAsFunctionDeclaration(i,this);l.push(x),i==null||i.add(x,W.Added),this.addMethod(x,i)}),this.methods.sort((E,w)=>E.index-w.index).forEach(E=>{E.afterAllChildrenInitialized(i)}),i==null||i.attemptAutoclose("sync-implementation-methods",this.id),{updated:O(r),added:O(l),removed:O(c),affected:O(e),self:this}}syncImplementationProperties(i=this.project.addChangeSet(new H(this.project,L.sessionAuthor,B().toISOString(),this,!0,"sync-implementation-properties"))){const r=[],l=[],c=[],e=[],y=this.properties,v=this.implementedPropertiesFromOriginalParents.filter(A=>!this.allBasePropertiesFromExtendedAndImplementedEntities.find(w=>!!w.implements.find(P=>P.id===A.id))),b=[...this.allBasePropertiesFromExtendedAndImplementedEntities,...y];return v.forEach(A=>{const E=b.find(M=>!!M.implements.find(k=>k.id===A.id));if(E){const{updated:M,added:k,removed:q,affected:Z}=E.syncWithImplementation(i);r.push(...M),l.push(...k),c.push(...q),e.push(...Z);return}if(this.properties.find(M=>!!M.implements.find(k=>k.id===A.id)))return;const P=this.properties.find(M=>M.name===A.name&&!!M.abstract&&!M.implements);if(P){P.addImplementation(A,i),P.metaSync({abstract:!1},i),P.afterAllChildrenInitialized(i);return}const x=A.implement(this,i,L.UUID.uuid());l.push(x),i==null||i.add(x,W.Added)}),i==null||i.attemptAutoclose("sync-implementation-properties",this.id),{updated:O(r),added:O(l),removed:O(c),affected:O(e),self:this}}addExtendedMethods(i=this.project.addChangeSet(new H(this.project,L.sessionAuthor,B().toISOString(),this,!0,"add-extended-methods"))){const r=[],l=[],c=[],e=[],y=this.methods,b=this.extendedMethodsFromOriginalParents.filter(E=>E.type===o.FunctionDeclaration),A=new Set(y.filter(E=>{var w;return!!((w=E.extends)!=null&&w.id)}).map(E=>E.extends.id));return b.forEach(E=>{if(A.has(E.id))return;A.add(E.id);const w=E.clone(i,this,L.UUID.uuid());w.setExtends(E,i),w.initChildren(i),l.push(w),i==null||i.add(w,W.Added),this.addMethod(w,i)}),i==null||i.attemptAutoclose("add-extended-methods",this.id),{updated:O(r),added:O(l),removed:O(c),affected:O(e),self:this}}addExtendedProperties(i=this.project.addChangeSet(new H(this.project,L.sessionAuthor,B().toISOString(),this,!0,"add-extended-properties"))){const r=[],l=[],c=[],e=[],y=this.properties,v=this.extendedPropertiesFromOriginalParents,b=v.filter(E=>v.find(P=>!!P.implements.find(x=>x.id===E.id))?!1:!E.abstract),A=new Set(y.filter(E=>{var w;return!!((w=E.extends)!=null&&w.id)}).map(E=>E.extends.id));return b.forEach(E=>{if(A.has(E.id))return;A.add(E.id);const w=E.clone(i,this,L.UUID.uuid());w.setExtends(E,i),w.initChildren(i),l.push(w),i==null||i.add(w,W.Added),this.addProperty(w,i)}),i==null||i.attemptAutoclose("add-extended-properties",this.id),{updated:O(r),added:O(l),removed:O(c),affected:O(e),self:this}}addSuggestions(){return this.implements.forEach(i=>{gxe(this,i).forEach(c=>{const e=c.toJSON();e.id=`_suggestion--parent--${this.id}--${c.id}`;const y=me(e,this.project);y.suggestion=!0,y.setParent(this,null),y.initChildren(null),this.addSuggestedProperty(y)}),Ixe(this,i).forEach(c=>{const e=`_suggestion--parent--${this.id}--${c.id}`,y=c.implementAsFunctionDeclaration(null,this,e),v=me(y,this.project);if(v.suggestion=!0,v.setParent(this,null),v.initChildren(null),this.methods=this.methods.filter(b=>b.id!==e),v.inputs.forEach(b=>{b.suggestion=!0}),v.returnStatements.length){const b=v.returnStatements[0];b.suggestion=!0,b.outputs.forEach(A=>{A.suggestion=!0})}this.addSuggestedMethod(v)})}),this}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(i,r=this.project.addChangeSet(new H(this.project,L.sessionAuthor,B().toISOString(),this,!0,"meta-sync"))){const l=$n(this,i,r),c=Nn(this,l),e=this.toMeta();return this.name=l.name!==void 0?l.name:e.name,this.codeName=l.codeName!==void 0?l.codeName:e.codeName,this.description=l.description!==void 0?l.description:e.description,this.x=l.x||e.x,this.y=l.y||e.y,this.static=l.static!==void 0?l.static:this.static,this.abstract=l.abstract!==void 0?l.abstract:this.abstract,this.additionalProperties=l.additionalProperties!==void 0?l.additionalProperties:e.additionalProperties,super.baseMetaSync(l,this,r),l.deleted===!0&&!e.deleted?r==null||r.add(this,W.Removed):l.deleted===!1&&e.deleted?r==null||r.add(this,W.Added):c&&(r==null||r.add(this,W.Updated)),r==null||r.attemptAutoclose("meta-sync",this.id),this}async APILoad(i=Be,...r){return await bi.repository.APILoad(this.id,...r),this}async APICreate(i=Be,...r){return await bi.repository.APICreate(this.toShallowJSON(),...r),this}async APIUpdate(i=Be,...r){return await bi.repository.APIUpdate(this.toShallowJSON(),...r),this}async APIDelete(i=Be,...r){return await bi.repository.APIDelete(this.toShallowJSON(),...r),this}async APIClone(i=Be,...r){return await bi.repository.APIClone(this.id,...r),this}async APILoadVersion(i=Be,r,...l){return await bi.repository.APILoadVersion(this.id,r,...l)}removeFromParent(i=this.project.addChangeSet(new H(this.project,L.sessionAuthor,B().toISOString(),this,!0,V.RemoveFromParent))){if(!this.checkCanEdit(this,i))return ae.warn(`[removeFromParent] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(V.RemoveFromParent,this.id),{added:[],updated:[],removed:[],affected:[],self:this};const r=[],l=[],c=[],e=[];if(this.parent.type===o.Project)this.parent.removeDefinitionEntity(this);else if(this.parent.type===o.DataType&&this.parent.entity&&this.parent.entity.id===this.id){const y=this.parent.setEntity(null,i);r.push(y)}return i==null||i.attemptAutoclose(V.RemoveFromParent,this.id),{added:O(c),updated:O(r),removed:O(l),affected:O(e),self:this}}remove({ignoreUpstream:i}={ignoreUpstream:!1},r=this.project.addChangeSet(new H(this.project,L.sessionAuthor,B().toISOString(),this,!0,V.RemoveEntity))){var v;if(!this.checkCanDelete(this,r))return ae.warn(`[remove] User is not allowed to delete or edit this ${this.type} entity with id: ${this.id}`),r==null||r.event({id:`${V.RemoveEntity}-${this.id}`,action:V.RemoveEntity,owner:this,errorReason:tn.ActionOwnerEntityNonDeletable,rootAction:((v=r==null?void 0:r.self)==null?void 0:v.id)===this.id&&(r==null?void 0:r.autoCloseActionName)===V.RemoveEntity}),r==null||r.attemptAutoclose(V.RemoveEntity,this.id),{added:[],updated:[],removed:[],affected:[],self:this};const l=[],c=[],e=[],y=[];if(r!=null&&r.hasRemoved(this.id))return r==null||r.attemptAutoclose(V.RemoveEntity,this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(c.push(this),this.unsubscribe(),this.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},r),Object.values(this.detachedDependents).forEach(b=>{const{updated:A,removed:E,added:w}=b.entity.onDetachedDependencyRemoved(this,b.field,r);l.push(...A),c.push(...E),e.push(...w)}),this.properties.forEach(b=>{const{updated:A,removed:E}=b.remove({ignoreUpstream:!0},r);l.push(...A),c.push(...E)}),this.methods.forEach(b=>{const{updated:A,removed:E}=b.remove({ignoreUpstream:!0},r);l.push(...A),c.push(...E)}),this.abstractMethods.forEach(b=>{const{updated:A,removed:E}=b.remove({ignoreUpstream:!0},r);l.push(...A),c.push(...E)}),this.suggestedProperties.forEach(b=>{const{updated:A,removed:E}=b.remove({ignoreUpstream:!0},r);l.push(...A),c.push(...E)}),this.suggestedMethods.forEach(b=>{const{updated:A,removed:E}=b.remove({ignoreUpstream:!0},r);l.push(...A),c.push(...E)}),!i){const b=this.removeFromParent(r);e.push(...b.added),l.push(...b.updated),c.push(...b.removed),y.push(...b.affected)}return r==null||r.attemptAutoclose(V.RemoveEntity,this.id),{added:O(e),updated:O(l),removed:O(c),affected:O(y),self:this}}restore({}={},i=this.project.addChangeSet(new H(this.project,L.sessionAuthor,B().toISOString(),this,!0,V.RestoreEntity))){if(!this.checkCanEdit(this,i))return ae.warn(`[restore] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(V.RestoreEntity,this.id),{added:[],updated:[],removed:[],affected:[],self:this};const r=[],l=[],c=[],e=[];return i!=null&&i.hasAdded(this.id)?(i==null||i.attemptAutoclose(V.RestoreEntity,this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},i),Object.values(this.detachedDependents).forEach(y=>{const{updated:v,removed:b,added:A}=y.entity.onDetachedDependencyRestored(this,y.field,i);l.push(...v),c.push(...b),r.push(...A)}),this.properties.forEach(y=>{const{updated:v}=y.restore({},i);l.push(...v)}),this.methods.forEach(y=>{const{updated:v}=y.restore({},i);l.push(...v)}),this.abstractMethods.forEach(y=>{const{updated:v}=y.restore({},i);l.push(...v)}),this.suggestedProperties.forEach(y=>{const{updated:v}=y.restore({},i);l.push(...v)}),this.suggestedMethods.forEach(y=>{const{updated:v}=y.restore({},i);l.push(...v)}),i==null||i.attemptAutoclose(V.RestoreEntity,this.id),{added:O(r),updated:O(l),removed:O(c),affected:O(e),self:this})}toFlat(i=new Set){var l;return i.has(this.id)?[]:(i.add(this.id),[this,...((l=this.extends)==null?void 0:l.toFlat(i))||[],...this.implements.flatMap(c=>c.toFlat(i)),...this.properties.flatMap(c=>c.toFlat(i)),...this.methods.flatMap(c=>c.toFlat(i)),...this.abstractMethods.flatMap(c=>c.toFlat(i)),...this.parent.toFlat(i)])}toFlatIds(i=new Set){var l;return i.has(this.id)?[]:(i.add(this.id),[this.id,...((l=this.extends)==null?void 0:l.toFlatIds(i))||[],...this.implements.flatMap(c=>c.toFlatIds(i)),...this.properties.flatMap(c=>c.toFlatIds(i)),...this.methods.flatMap(c=>c.toFlatIds(i)),...this.abstractMethods.flatMap(c=>c.toFlatIds(i)),...this.parent.toFlatIds(i)])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,codeName:this.codeName,description:this.description,static:this.static,abstract:this.abstract,x:this.x,y:this.y,type:this.type,editable:this.editable,deletable:this.deletable,additionalProperties:this.additionalProperties,name:this.name}}toJSON(i=new Set){var r,l,c;return i.has(this.id)?this.toReference():(i.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,editable:this.editable,deletable:this.deletable,name:this.name,codeName:this.codeName,description:this.description,x:this.x,y:this.y,static:this.static,abstract:this.abstract,additionalProperties:this.additionalProperties,allPropertiesImplement:((r=this.allPropertiesImplement)==null?void 0:r.toJSON(i))||null,additionalPropertiesDataType:((l=this.additionalPropertiesDataType)==null?void 0:l.toJSON(i))||null,properties:this.properties.map(e=>e.toJSON(i)),methods:this.methods.map(e=>e.toJSON(i)),abstractMethods:this.abstractMethods.map(e=>e.toJSON(i)),implements:this.implements.map(e=>e.toJSON(i)),extends:((c=this.extends)==null?void 0:c.toJSON(i))||null,parent:this.parent.toReference()})}toJSONClone(i=dt){var l,c,e,y,v,b,A,E,w,P;let r;return(l=i.seenEntityMaps)!=null&&l.has(this.id)?r=i.seenEntityMaps.get(this.id):(r=i.newId||jn(this,this.project,i.uuidStrategy),i.seenEntityMaps&&i.seenEntityMaps.set(this.id,r)),(c=i.seenEntities)!=null&&c.has(r)||(e=i.seenEntities)!=null&&e.has(this.id)?this.toReference({seenEntityMaps:i.seenEntityMaps}):((y=i.seenEntities)==null||y.add(r),(v=i.seenEntities)==null||v.add(this.id),{id:r,version:L.UUID.uuid(),createdAt:i.timestamp||B().toISOString(),author:L.sessionAuthor,previousVersion:null,deleted:!1,type:this.type,editable:this.editable,deletable:this.deletable,name:this.name,codeName:this.codeName,description:this.description,x:this.x,y:this.y,static:this.static,abstract:this.abstract,additionalProperties:this.additionalProperties,allPropertiesImplement:((b=this.allPropertiesImplement)==null?void 0:b.toJSONClone(i))||null,additionalPropertiesDataType:((A=this.additionalPropertiesDataType)==null?void 0:A.toJSONClone(i))||null,properties:this.properties.map(x=>x.toJSONClone({...i,newId:null})),methods:this.methods.map(x=>x.toJSONClone({...i,newId:null})),abstractMethods:this.abstractMethods.map(x=>x.toJSONClone({...i,newId:null})),implements:this.implements.map(x=>x.type===o.BuiltInBaseEntity?x.toJSON(i.seenEntities):x.toJSONClone({...i,newId:null})),extends:((E=this.extends)==null?void 0:E.type)===o.BuiltInBaseEntity?(w=this.extends)==null?void 0:w.toJSON(i.seenEntities):(P=this.extends)==null?void 0:P.toJSONClone({...i,newId:null}),parent:this.parent.toReference({seenEntityMaps:i.seenEntityMaps})})}toReference(i=dt){var l;let r=this.id;return(l=i.seenEntityMaps)!=null&&l.has(this.id)&&(r=i.seenEntityMaps.get(this.id)),{id:r+"--"+L.UUID.uuid()+"--ref",type:o.GenericReference,entityId:r,version:this.version,entityType:this.type}}toShallowJSON(i=dt){var l,c,e,y;let r=this.id;return(l=i.seenEntityMaps)!=null&&l.has(this.id)&&(r=i.seenEntityMaps.get(this.id)),{id:r,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,name:this.name,codeName:this.codeName,description:this.description,type:this.type,editable:this.editable,deletable:this.deletable,x:this.x,y:this.y,static:this.static,abstract:this.abstract,additionalProperties:this.additionalProperties,allPropertiesImplement:((c=this.allPropertiesImplement)==null?void 0:c.toReference(i))||null,additionalPropertiesDataType:((e=this.additionalPropertiesDataType)==null?void 0:e.toReference(i))||null,properties:this.properties.map(v=>v.toReference(i)),methods:this.methods.map(v=>v.toReference(i)),abstractMethods:this.abstractMethods.map(v=>v.toReference(i)),implements:this.implements.map(v=>v.toReference(i)),extends:((y=this.extends)==null?void 0:y.toReference(i))||null,parent:this.parent.toReference(i)}}toFlatJSON(i=new Set){var l,c,e;return i.has(this.id)?[]:(i.add(this.id),[this.toShallowJSON(),...this.properties.flatMap(y=>y.toFlatJSON(i)),...this.methods.flatMap(y=>y.toFlatJSON(i)),...this.abstractMethods.flatMap(y=>y.toFlatJSON(i)),...this.implements.flatMap(y=>y.toFlatJSON(i)),...((l=this.extends)==null?void 0:l.toFlatJSON(i))||[],...this.parent.toFlatJSON(i),...((c=this.additionalPropertiesDataType)==null?void 0:c.toFlatJSON(i))||[],...((e=this.allPropertiesImplement)==null?void 0:e.toFlatJSON(i))||[]])}toGenerationTarget(){var r;const i=this.parent.type===o.Project?void 0:this.parent.id;return{id:this.id,name:this.name,description:this.description,type:this.type,static:this.static,abstract:this.abstract,extends:(r=this.extends)==null?void 0:r.id,additionalProperties:this.additionalProperties,implements:this.implements.map(l=>l.id),parent:i}}toFlatGenerationTarget(i=new Set){var l,c,e;return i.has(this.id)?[]:(i.add(this.id),[this.toGenerationTarget(),...this.properties.flatMap(y=>y.toFlatGenerationTarget(i)),...this.methods.flatMap(y=>y.toFlatGenerationTarget(i)),...this.abstractMethods.flatMap(y=>y.toFlatGenerationTarget(i)),...this.implements.filter(y=>y.type===o.DefinitionEntity).flatMap(y=>y.toFlatGenerationTarget(i)),...((l=this.extends)==null?void 0:l.toFlatGenerationTarget(i))||[],...this.parent.toFlatGenerationTarget(i),...((c=this.additionalPropertiesDataType)==null?void 0:c.toFlatGenerationTarget(i))||[],...((e=this.allPropertiesImplement)==null?void 0:e.toFlatGenerationTarget(i))||[]])}clearErrors(){var i,r;return this.errors=[],this.properties.forEach(l=>l.clearErrors()),this.methods.forEach(l=>l.clearErrors()),this.abstractMethods.forEach(l=>l.clearErrors()),(i=this.additionalPropertiesDataType)==null||i.clearErrors(),(r=this.allPropertiesImplement)==null||r.clearErrors(),this}validate(){return this.errors=Axe(this),{success:!0}}getErrors(){var r,l;return[...this.errors,...this.properties.flatMap(c=>c.getErrors()),...this.methods.flatMap(c=>c.getErrors()),...this.abstractMethods.flatMap(c=>c.getErrors()),...((r=this.additionalPropertiesDataType)==null?void 0:r.getErrors())||[],...((l=this.allPropertiesImplement)==null?void 0:l.getErrors())||[]]}getShallowErrors(){return this.errors}clone(i=this.project.addChangeSet(new H(this.project,L.sessionAuthor,B().toISOString(),this,!0,V.CloneEntity)),r=null,l=null,c=!0){var q,Z,X;const e=Vn(r,this),y=this.toJSON(),v=l||L.UUID.uuid(),b=r||this.parent,A=new Set([...this.project.getAllBuiltInIds(),...rn()]);y.properties=[],y.methods=[],y.abstractMethods=[];const E=v.split("-id"),w=E[E.length-1||0]||v;y.id=v,y.version=L.UUID.uuid(),y.createdAt=(i==null?void 0:i.timestamp)||B().toISOString(),y.author=(i==null?void 0:i.author)||"1",y.previousVersion=null,y.deleted=!1,y.editable=!0,y.deletable=!0,y.parent=b.toReference();const P=Ui(y,e);P.hydrateAncestors(),P.setParent(b,i),c&&(P.subscribe(),P.addSelfToProject(i)),P.initChildren(i),i==null||i.add(P,W.Added);const x=(q=this.properties)==null?void 0:q.map(se=>A.has(se.id)?e.getBuiltIn(se.id):se.clone(i,P,L.UUID.uuid(),c));P.properties=x;const M=(Z=this.methods)==null?void 0:Z.map((se,ee)=>A.has(se.id)?e.getBuiltIn(se.id):se.clone(i,P,w+"-method-"+ee+"-id",c));P.methods=M;const k=(X=this.abstractMethods)==null?void 0:X.map((se,ee)=>A.has(se.id)?e.getBuiltIn(se.id):se.clone(i,P,w+"-abstract-method-"+ee+"-id",c));if(P.abstractMethods=k,this.additionalPropertiesDataType)if(A.has(this.additionalPropertiesDataType.id))P.setAdditionalPropertiesDataType(this.project.getBuiltIn(this.additionalPropertiesDataType.id),i);else{const se=this.additionalPropertiesDataType.clone(i,P,L.UUID.uuid(),c);P.setAdditionalPropertiesDataType(se,i)}if(this.allPropertiesImplement)if(A.has(this.allPropertiesImplement.id))P.setAllPropertiesImplement(this.project.getBuiltIn(this.allPropertiesImplement.id),i);else{const se=this.allPropertiesImplement.clone(i,P,L.UUID.uuid(),c);P.setAllPropertiesImplement(se,i)}return i==null||i.attemptAutoclose(V.CloneEntity,this.id),P}getFunctionDeclaration(i){return this.methods.find(r=>r.id===i)}implement(i,r=this.project.addChangeSet(new H(this.project,L.sessionAuthor,B().toISOString(),this,!0,"implement-definition-entity")),l){const c=Og(this,i,r,l);return r==null||r.attemptAutoclose("implement-definition-entity",this.id),c}getAllPropertiesImplements(){var r;const i=[];return this.allPropertiesImplement&&i.push(this.allPropertiesImplement),i.push(...((r=this.extends)==null?void 0:r.getAllPropertiesImplements())||[],...this.implements.flatMap(l=>l.getAllPropertiesImplements())),i}getAllInteractiveMethods(){var e;const i=this.implements.filter(y=>y.type===o.DefinitionEntity||y.type===o.BuiltInBaseEntity&&y.interactive),r=((e=this.extends)==null?void 0:e.getAllInteractiveMethods())||[],l=i.flatMap(y=>y.getAllInteractiveMethods());return O([...this.methods,...r,...l])}inferFromInputs(i,r=this.project.addChangeSet(new H(this.project,L.sessionAuthor,B().toISOString(),this,!0,"infer-definition-entity-from-inputs"))){const l=[],c=[],e=[],y=[];if(this.parent.type!==o.DataType||!this.parent.inferred)return r==null||r.attemptAutoclose("infer-definition-entity-from-inputs",this.id),{added:[],updated:[],removed:[],affected:[],self:this};const v=[];i.forEach(E=>{v.find(P=>oe(P,this.project)===oe(E,this.project))||v.push(E)});const b=this.properties.filter(E=>!E.dataType);v.forEach(E=>{var Z,X,se;const w=b.find(ee=>oe(ee,this.project)===oe(E,this.project));if(!w)return;const x=Zr(E.parent).getMasterInputWithValueWritterFromAllInstances(E),M=Vo(x,r),k=M==null?void 0:M.clone(r,w,L.UUID.uuid(),!0);k&&((Z=w.dataType)==null||Z.merge(k,r),k.id!==((X=w.dataType)==null?void 0:X.id)&&k.remove({ignoreUpstream:!1},r),w.dataType&&(w.dataType.metaSync({inferred:!0,like:!0},r),w.setDataType(w.dataType,r),r==null||r.add(w,W.Affected)));let q=null;if(E.declaration&&w.id!==((se=E.declaration)==null?void 0:se.id)&&(q=E.declaration),E.setDeclaration(w,r),r==null||r.add(E,W.Updated),q){const{updated:ee,removed:he}=q.remove({ignoreUpstream:!1},r);c.push(...ee),e.push(...he)}});const A=[];return v.forEach(E=>{if(!E.declaration){A.push(E);return}}),A.length===0?(r==null||r.attemptAutoclose("infer-definition-entity-from-inputs",this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(A.forEach(E=>{var se,ee,he,de;const w=this.properties.find(fe=>oe(fe,this.project)===oe(E,this.project));if(w){if(E.setDeclaration(w,r),!w.getDataType(r)){const Te=Zr(E.parent).getMasterInputWithValueWritterFromAllInstances(E),ne=Vo(Te),ue=ne==null?void 0:ne.clone(r,w,L.UUID.uuid(),!0);ue&&((se=w.dataType)==null||se.merge(ue,r),ue.id!==((ee=w.dataType)==null?void 0:ee.id)&&ue.remove({ignoreUpstream:!1},r),w.dataType&&(w.dataType.metaSync({inferred:!0,like:!0},r),w.setDataType(w.dataType,r),r==null||r.add(w,W.Affected)))}return}const P=oe(E,this.project),x=E.codeName||Fg(E,this.project)||bc(Ji(P)),M=Ga.new(r);M.parent=this.toReference(),M.index=E.index,M.name=P,M.codeName=x,M.description=E.description;const k=me(M,this.project);k.hydrateAncestors(),r==null||r.add(k,W.Added),k.setParent(this,r),k.initChildren(r);const Z=Zr(E.parent).getMasterInputWithValueWritterFromAllInstances(E),X=Vo(Z);if(X)if(new Set([...this.project.getAllBuiltInIds(),...rn()]).has(X.id))k.setDataType(X,r),r==null||r.add(k,W.Affected);else{const Te=X==null?void 0:X.clone(r,k,L.UUID.uuid(),!0);Te&&((he=k.dataType)==null||he.merge(Te,r),Te.id!==((de=k.dataType)==null?void 0:de.id)&&Te.remove({ignoreUpstream:!1},r),k.dataType&&(k.dataType.metaSync({inferred:!0,like:!0},r),k.setDataType(k.dataType,r),r==null||r.add(k,W.Affected)))}return this.addProperty(k,r),E.setDeclaration(k,r),r==null||r.add(E,W.Updated),k}),r==null||r.attemptAutoclose("infer-definition-entity-from-inputs",this.id),{added:O(l),updated:O(c),removed:O(e),affected:O(y),self:this})}getRawDefaultValue(){const i={};return this.properties.forEach(r=>{var c;if(!rP(r))return;const l=Ji(r.name);i[l]=((c=r.getDefaultValue())==null?void 0:c.value)||null}),i}getActiveRawDefaultValue(){const i={};return this.properties.forEach(r=>{var e;if(!rP(r))return;const l=Ji(r.name),c=(e=this.project.requestActiveDynamicValue(r,!0))==null?void 0:e.value;i[l]=(c==null?void 0:c.value)||null}),i}setAdditionalPropertiesDataType(i,r=this.project.addChangeSet(new H(this.project,L.sessionAuthor,B().toISOString(),this,!0,V.SetAdditionalPropertiesDataType))){if(!this.checkCanEdit(this,r))return ae.warn(`[setAdditionalPropertiesDataType] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),r==null||r.attemptAutoclose(V.SetAdditionalPropertiesDataType,this.id),this;const l=this.additionalPropertiesDataType;return(l==null?void 0:l.id)!==(i==null?void 0:i.id)&&(l==null||l.remove({ignoreUpstream:!0},r),this.additionalPropertiesDataType=i,this.subscribeToDependencies(),r==null||r.add(this,W.Affected)),r==null||r.attemptAutoclose(V.SetAdditionalPropertiesDataType,this.id),this}removeAdditionalPropertiesDataType(i=this.project.addChangeSet(new H(this.project,L.sessionAuthor,B().toISOString(),this,!0,V.RemoveAllPropertiesImplement))){return this.checkCanEdit(this,i)?(this.additionalPropertiesDataType&&(this.additionalPropertiesDataType.remove({ignoreUpstream:!0},i),i==null||i.add(this,W.Affected),this.additionalPropertiesDataType=null),i==null||i.attemptAutoclose(V.RemoveAllPropertiesImplement,this.id),this):(ae.warn(`[removeAdditionalPropertiesDataType] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(V.RemoveAllPropertiesImplement,this.id),this)}setAllPropertiesImplement(i,r=this.project.addChangeSet(new H(this.project,L.sessionAuthor,B().toISOString(),this,!0,V.SetAllPropertiesImplement))){if(!this.checkCanEdit(this,r))return ae.warn(`[setAllPropertiesImplement] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),r==null||r.attemptAutoclose(V.SetAllPropertiesImplement,this.id),this;const l=this.allPropertiesImplement;return(l==null?void 0:l.id)!==(i==null?void 0:i.id)&&(l==null||l.remove({ignoreUpstream:!0},r),this.allPropertiesImplement=i,this.subscribeToDependencies(),r==null||r.add(this,W.Affected)),r==null||r.attemptAutoclose(V.SetAllPropertiesImplement,this.id),this}removeAllPropertiesImplement(i=this.project.addChangeSet(new H(this.project,L.sessionAuthor,B().toISOString(),this,!0,V.RemoveAllPropertiesImplement))){return this.checkCanEdit(this,i)?(this.allPropertiesImplement&&(this.allPropertiesImplement.remove({ignoreUpstream:!0},i),i==null||i.add(this,W.Affected),this.allPropertiesImplement=null),i==null||i.attemptAutoclose(V.RemoveAllPropertiesImplement,this.id),this):(ae.warn(`[removeAllPropertiesImplement] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(V.RemoveAllPropertiesImplement,this.id),this)}};R(bi,"repository",{APICreate:async(i,...r)=>i,APIUpdate:async(i,...r)=>i,APIDelete:async(i,...r)=>i,APIClone:async(i,...r)=>{},APILoad:async(i,...r)=>null,APILoadVersion:async(i,r,...l)=>null}),R(bi,"type",o.DefinitionEntity),R(bi,"USER_MANAGED_PARENT_TYPES",[o.Project,o.DataType]),R(bi,"PARENT_TYPES",[...bi.USER_MANAGED_PARENT_TYPES]),R(bi,"MUTABLE_BASE_PROPERTIES",["name","codeName","description","static","abstract","additionalProperties"]),R(bi,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),R(bi,"BASE_PROPERTIES",[...bi.MUTABLE_BASE_PROPERTIES,...bi.INMUTABLE_BASE_PROPERTIES]),R(bi,"MUTABLE_META_PROPERTIES",[...bi.MUTABLE_BASE_PROPERTIES,"x","y"]),R(bi,"INMUTABLE_META_PROPERTIES",[...bi.INMUTABLE_BASE_PROPERTIES]),R(bi,"META_PROPERTIES",[...bi.MUTABLE_META_PROPERTIES,...bi.INMUTABLE_META_PROPERTIES]),R(bi,"MUTABLE_UPSTREAM_PROPERTIES",["extends","implements"]),R(bi,"INMUTABLE_UPSTREAM_PROPERTIES",["parent"]),R(bi,"UPSTREAM_PROPERTIES",[...bi.MUTABLE_UPSTREAM_PROPERTIES,...bi.INMUTABLE_UPSTREAM_PROPERTIES]),R(bi,"MUTABLE_DOWNSTREAM_PROPERTIES",["properties","methods","abstractMethods","allPropertiesImplement","additionalPropertiesDataType"]),R(bi,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),R(bi,"DOWNSTREAM_PROPERTIES",[...bi.MUTABLE_DOWNSTREAM_PROPERTIES,...bi.INMUTABLE_DOWNSTREAM_PROPERTIES]),R(bi,"PROPERTIES",[...bi.META_PROPERTIES,...bi.UPSTREAM_PROPERTIES,...bi.DOWNSTREAM_PROPERTIES]);let vs=bi;function I2t(d){const p=[];return nn(d.errors,p)}const WT=class WT extends Zw{constructor(i,r){super(i);R(this,"initialData");R(this,"id");R(this,"version");R(this,"name");R(this,"description",null);R(this,"type",o.BuiltInBaseEntity);R(this,"abstract",!1);R(this,"static");R(this,"additionalProperties",!1);R(this,"properties",[]);R(this,"allPropertiesImplement",null);R(this,"additionalPropertiesDataType",null);R(this,"methods",[]);R(this,"abstractMethods",[]);R(this,"extends",null);R(this,"interactive",!1);R(this,"errors",[]);R(this,"project");if(this.initialData=this.initialData||i,this.project=this.project||r,this.id=this.id||i.id,this.version=this.version||i.version,this.name=this.name||i.name,this.static=this.static||i.static,this.interactive=this.interactive||i.interactive,this.abstract=i.abstract,this.additionalProperties=i.additionalProperties,this.properties=this.initialData.properties.map(l=>{const c=me(l,this.project);return c.setParent(this,null),c.initChildren(null),c}),this.methods=this.initialData.methods.map(l=>{const c=me(l,this.project);return c.setParent(this,null),c.initChildren(null),c}),this.abstractMethods=this.initialData.abstractMethods.map(l=>{const c=me(l,this.project);return c.setParent(this,null),c.initChildren(null),c}),this.initialData.allPropertiesImplement){const l=me(this.initialData.allPropertiesImplement,this.project);l.setParent(this,null),l.initChildren(null),this.allPropertiesImplement=l}if(this.initialData.additionalPropertiesDataType){const l=me(this.initialData.additionalPropertiesDataType,this.project);l.setParent(this,null),l.initChildren(null),this.additionalPropertiesDataType=l}this.initialData.extends&&(this.extends=me(this.initialData.extends,this.project))}get allMethods(){return O([...this.ownDeclaredMethods,...this.allBaseMethodsFromOriginalParents])}get allProperties(){return O([...this.ownDeclaredProperties,...this.allBasePropertiesFromOriginalParents])}get allBaseMethodsFromOriginalParents(){var l;const i=((l=this.extends)==null?void 0:l.allMethods)||[],r=[...i].filter(c=>!i.some(e=>e.id!==c.id));return O(r)}get allBasePropertiesFromOriginalParents(){var l;const i=((l=this.extends)==null?void 0:l.allProperties)||[],r=[...i].filter(c=>!i.some(e=>{var y;return e.id!==c.id&&(!!e.implements.find(v=>v.id===c.id)||((y=e.extends)==null?void 0:y.id)===c.id)}));return O(r)}get allBasePropertiesFromExtendedAndImplementedEntities(){var l,c;const i=[...((l=this.extends)==null?void 0:l.ownDeclaredProperties)||[],...((c=this.extends)==null?void 0:c.allBasePropertiesFromExtendedAndImplementedEntities)||[]].filter(e=>!e.abstract),r=[...i].filter(e=>!i.some(y=>{var v;return y.id!==e.id&&(!!y.implements.find(b=>b.id===e.id)||((v=y.extends)==null?void 0:v.id)===e.id)}));return O([...r])}get allBaseMethodsFromExtendedAndImplementedEntities(){return O([...(this.extends?[this.extends]:[]).reduce((i,r)=>r.type===o.PrimitiveEntity?i:[...[...r.ownDeclaredMethods,...r.allBaseMethodsFromExtendedAndImplementedEntities].filter(c=>c.type!==o.ActionDescriptor),...i],[])])}get extendedPropertiesFromOriginalParents(){var l,c;const i=[...((l=this.extends)==null?void 0:l.ownDeclaredProperties)||[],...((c=this.extends)==null?void 0:c.extendedPropertiesFromOriginalParents)||[]].filter(e=>!e.abstract),r=[...i].filter(e=>!i.some(y=>{var v;return y.id!==e.id&&(!!y.implements.find(b=>b.id===e.id)||((v=y.extends)==null?void 0:v.id)===e.id)}));return O(r)}get implementedPropertiesFromOriginalParents(){return O([...(this.extends?[this.extends]:[]).reduce((i,r)=>{const l=r.implementedPropertiesFromOriginalParents,c=[...r.ownDeclaredProperties].filter(v=>!!v.abstract),e=[...l,...c,...i];return[...e].filter(v=>!!!e.find(A=>{var E;return((E=A.extends)==null?void 0:E.id)===v.id||!!A.implements.find(w=>w.id===v.id)}))},[])].filter(i=>!!i.abstract))}get extendedProperties(){return this.properties.filter(i=>i.isExtendedProperty)}get ownDeclaredMethods(){return[...this.methods,...this.abstractMethods]}get ownDeclaredProperties(){return this.properties.filter(i=>!i.isExtendedProperty)}subscribe(){return this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}async APILoad(i=Be,...r){return await WT.repository.APILoad(this.id,...r),this}toFlat(i=new Set){var l;return i.has(this.id)?[]:(i.add(this.id),[this,...this.properties.flatMap(c=>c.toFlat(i)),...this.methods.flatMap(c=>c.toFlat(i)),...this.abstractMethods.flatMap(c=>c.toFlat(i)),...((l=this.extends)==null?void 0:l.toFlat(i))||[]])}toFlatIds(i=new Set){var l;return i.has(this.id)?[]:(i.add(this.id),[this.id,...this.properties.flatMap(c=>c.toFlatIds(i)),...this.methods.flatMap(c=>c.toFlatIds(i)),...this.abstractMethods.flatMap(c=>c.toFlatIds(i)),...((l=this.extends)==null?void 0:l.toFlatIds(i))||[]])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,description:this.description,interactive:this.interactive,additionalProperties:this.additionalProperties,abstract:this.abstract,static:this.static,type:this.type,name:this.name}}toJSON(i=new Set){var r,l,c;return i.has(this.id)?this.toReference():(i.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,abstract:this.abstract,static:this.static,additionalProperties:this.additionalProperties,interactive:this.interactive,additionalPropertiesDataType:((r=this.additionalPropertiesDataType)==null?void 0:r.toJSON(i))||null,allPropertiesImplement:((l=this.allPropertiesImplement)==null?void 0:l.toJSON(i))||null,properties:this.properties.map(e=>e.toJSON(i)),methods:this.methods.map(e=>e.toJSON(i)),abstractMethods:this.abstractMethods.map(e=>e.toJSON(i)),extends:((c=this.extends)==null?void 0:c.toJSON(i))||null})}toReference(i=dt){return{id:this.id+"--"+L.UUID.uuid()+"--ref",type:o.GenericReference,entityId:this.id,version:this.version,entityType:this.type}}toShallowJSON(i=dt){var r,l,c;return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,abstract:this.abstract,static:this.static,interactive:this.interactive,additionalProperties:this.additionalProperties,additionalPropertiesDataType:((r=this.additionalPropertiesDataType)==null?void 0:r.toReference())||null,allPropertiesImplement:((l=this.allPropertiesImplement)==null?void 0:l.toReference())||null,properties:this.properties.map(e=>e.toReference()),methods:this.methods.map(e=>e.toReference()),abstractMethods:this.abstractMethods.map(e=>e.toReference()),extends:((c=this.extends)==null?void 0:c.toReference())||null}}toFlatJSON(i=new Set){var l,c;return i.has(this.id)?[]:(i.add(this.id),[this.toShallowJSON(),...this.properties.flatMap(e=>e.toFlatJSON(i)),...this.methods.flatMap(e=>e.toFlatJSON(i)),...this.abstractMethods.flatMap(e=>e.toFlatJSON(i)),...((l=this.additionalPropertiesDataType)==null?void 0:l.toFlatJSON(i))||[],...((c=this.allPropertiesImplement)==null?void 0:c.toFlatJSON(i))||[]])}toGenerationTarget(){var i;return{id:this.id,type:this.type,name:this.name,description:this.description,static:this.static,abstract:this.abstract,interactive:this.interactive,additionalProperties:this.additionalProperties,extends:(i=this.extends)==null?void 0:i.id}}toFlatGenerationTarget(i=new Set){var l,c;return i.has(this.id)?[]:(i.add(this.id),[this.toGenerationTarget(),...this.properties.flatMap(e=>e.toFlatGenerationTarget(i)),...this.methods.flatMap(e=>e.toFlatGenerationTarget(i)),...this.abstractMethods.flatMap(e=>e.toFlatGenerationTarget(i)),...((l=this.additionalPropertiesDataType)==null?void 0:l.toFlatGenerationTarget(i))||[],...((c=this.allPropertiesImplement)==null?void 0:c.toFlatGenerationTarget(i))||[]])}clearErrors(){var i,r;return this.errors=[],this.properties.forEach(l=>l.clearErrors()),this.methods.forEach(l=>l.clearErrors()),this.abstractMethods.forEach(l=>l.clearErrors()),(i=this.additionalPropertiesDataType)==null||i.clearErrors(),(r=this.allPropertiesImplement)==null||r.clearErrors(),this}validate(){const i=I2t(this);return this.errors=i,{success:!0}}getErrors(){var r,l;return[...this.errors,...this.properties.flatMap(c=>c.getErrors()),...this.methods.flatMap(c=>c.getErrors()),...this.abstractMethods.flatMap(c=>c.getErrors()),...((r=this.additionalPropertiesDataType)==null?void 0:r.getErrors())||[],...((l=this.allPropertiesImplement)==null?void 0:l.getErrors())||[]]}getShallowErrors(){return this.errors}implement(i,r=this.project.addChangeSet(new H(this.project,L.sessionAuthor,B().toISOString(),null,!0,"implement-built-in-base-entity")),l){const c=Og(this,i,r,l);return r==null||r.attemptAutoclose("implement-built-in-base-entity",this.id),c}getAllPropertiesImplements(){var r;const i=[];return this.allPropertiesImplement&&i.push(this.allPropertiesImplement),((r=this.extends)==null?void 0:r.type)===o.BuiltInBaseEntity&&i.push(...this.extends.getAllPropertiesImplements()||[]),i}getAllInteractiveMethods(){const i=[];if(this.interactive){if(i.push(...this.methods,...this.abstractMethods),!this.extends||this.extends.type===o.BuiltInBaseEntity&&this.extends.interactive||this.extends.type===o.PrimitiveEntity)return i;this.extends instanceof WT&&i.push(...this.extends.getAllInteractiveMethods())}return O(i)}};R(WT,"repository",{APILoad:async(i,...r)=>null});let xo=WT;function R2t(d){const p=[];return nn(d.errors,p)}const Xg=class Xg extends Zw{constructor(i,r){super(i);R(this,"initialData");R(this,"id");R(this,"name");R(this,"description",null);R(this,"type",o.PrimitiveEntity);R(this,"static");R(this,"abstract");R(this,"properties",[]);R(this,"methods",[]);R(this,"abstractMethods",[]);R(this,"extends",null);R(this,"errors",[]);R(this,"project");this.initialData=i,this.project=r,this.id=i.id,this.name=i.name,this.static=i.static,this.abstract=i.abstract,this.properties=this.initialData.properties.map(l=>{const c=me(l,this.project);return c.setParent(this,null),c.initChildren(null),c}),this.methods=this.initialData.methods.map(l=>{const c=me(l,this.project);return c.parent=this,c}),this.abstractMethods=this.initialData.abstractMethods.map(l=>{const c=me(l,this.project);return c.parent=this,c}),this.initialData.extends&&(this.extends=me(this.initialData.extends,this.project))}get allMethods(){return O([...this.ownDeclaredMethods,...this.allBaseMethodsFromOriginalParents])}get allProperties(){return O([...this.ownDeclaredProperties,...this.allBasePropertiesFromOriginalParents])}get allBaseMethodsFromOriginalParents(){var l;const i=((l=this.extends)==null?void 0:l.allMethods)||[],r=[...i].filter(c=>!i.some(e=>e.id!==c.id));return O(r)}get allBasePropertiesFromOriginalParents(){var l;const i=((l=this.extends)==null?void 0:l.allProperties)||[],r=[...i].filter(c=>!i.some(e=>{var y;return e.id!==c.id&&(e.implements.find(v=>v.id===c.id)||((y=e.extends)==null?void 0:y.id)===c.id)}));return O(r)}get allBasePropertiesFromExtendedAndImplementedEntities(){var l,c;const i=[...((l=this.extends)==null?void 0:l.ownDeclaredProperties)||[],...((c=this.extends)==null?void 0:c.allBasePropertiesFromExtendedAndImplementedEntities)||[]].filter(e=>!e.abstract),r=[...i].filter(e=>!i.some(y=>{var v;return y.id!==e.id&&(y.implements.find(b=>b.id===e.id)||((v=y.extends)==null?void 0:v.id)===e.id)}));return O(r)}get extendedPropertiesFromOriginalParents(){var l,c;const i=[...((l=this.extends)==null?void 0:l.ownDeclaredProperties)||[],...((c=this.extends)==null?void 0:c.extendedPropertiesFromOriginalParents)||[]].filter(e=>!e.abstract),r=[...i].filter(e=>!i.some(y=>{var v;return y.id!==e.id&&(y.implements.find(b=>b.id===e.id)||((v=y.extends)==null?void 0:v.id)===e.id)}));return O(r)}get implementedPropertiesFromOriginalParents(){return O([...(this.extends?[this.extends]:[]).reduce((i,r)=>{const l=r.implementedPropertiesFromOriginalParents,c=[...r.ownDeclaredProperties].filter(v=>!!v.abstract),e=[...l,...c,...i];return[...e].filter(v=>!!!e.find(A=>{var E;return((E=A.extends)==null?void 0:E.id)===v.id||A.implements.find(w=>w.id===v.id)}))},[])])}get extendedProperties(){return this.properties.filter(i=>i.isExtendedProperty)}get ownDeclaredMethods(){return[...this.methods]}get ownDeclaredProperties(){return this.properties.filter(i=>!i.isExtendedProperty)}subscribe(){return this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}async APILoad(i=Be,...r){return await Xg.repository.APILoad(this.id,...r),this}toFlat(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this,...this.properties.flatMap(l=>l.toFlat(i)),...this.methods.flatMap(l=>l.toFlat(i)),...this.abstractMethods.flatMap(l=>l.toFlat(i))])}toFlatIds(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.id,...this.properties.flatMap(l=>l.toFlatIds(i)),...this.methods.flatMap(l=>l.toFlatIds(i)),...this.abstractMethods.flatMap(l=>l.toFlatIds(i))])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,description:this.description,static:this.static,abstract:this.abstract,type:this.type,name:this.name}}toJSON(i=new Set){var r;return i.has(this.id)?this.toReference():(i.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,static:this.static,abstract:this.abstract,properties:this.properties.map(l=>l.toJSON(i)),methods:this.methods.map(l=>l.toJSON(i)),abstractMethods:this.abstractMethods.map(l=>l.toJSON(i)),extends:((r=this.extends)==null?void 0:r.toJSON(i))||null})}toReference(i=dt){return{id:this.id+"--"+L.UUID.uuid()+"--ref",type:o.GenericReference,entityId:this.id,version:this.version,entityType:this.type}}toShallowJSON(i=dt){var r;return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,abstract:this.abstract,static:this.static,properties:this.properties.map(l=>l.toReference()),methods:this.methods.map(l=>l.toReference()),abstractMethods:this.abstractMethods.map(l=>l.toReference()),extends:((r=this.extends)==null?void 0:r.toReference())||null}}toFlatJSON(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.toShallowJSON(),...this.properties.flatMap(l=>l.toFlatJSON(i)),...this.methods.flatMap(l=>l.toFlatJSON(i)),...this.abstractMethods.flatMap(l=>l.toFlatJSON(i))])}toGenerationTarget(){var i;return{id:this.id,type:this.type,name:this.name,description:this.description,static:this.static,abstract:this.abstract,extends:(i=this.extends)==null?void 0:i.id}}toFlatGenerationTarget(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.toGenerationTarget(),...this.properties.flatMap(l=>l.toFlatGenerationTarget(i)),...this.methods.flatMap(l=>l.toFlatGenerationTarget(i)),...this.abstractMethods.flatMap(l=>l.toFlatGenerationTarget(i))])}clearErrors(){return this.errors=[],this.properties.forEach(i=>i.clearErrors()),this.methods.forEach(i=>i.clearErrors()),this.abstractMethods.forEach(i=>i.clearErrors()),this}validate(){const i=R2t(this);return this.errors=i,{success:!0}}getErrors(){return[...this.errors,...this.properties.flatMap(r=>r.getErrors()),...this.methods.flatMap(r=>r.getErrors()),...this.abstractMethods.flatMap(r=>r.getErrors())]}getShallowErrors(){return this.errors}getAllInteractiveMethods(){const i=[];return i.push(...this.methods),!this.extends||this.extends.type===o.BuiltInBaseEntity&&this.extends.interactive||this.extends.type===o.PrimitiveEntity?i:(this.extends instanceof xo&&i.push(...this.extends.getAllInteractiveMethods()),O(i))}};R(Xg,"repository",{APILoad:async(i,...r)=>null});let ha=Xg;function Ui(d,p){if(!d)throw new Error("Entity is null");const i=p.get(d.id);switch(d.type){case o.LiteralValue:return i||new Xn(d,p);case o.DefinitionEntity:return i||new vs(d,p);case o.PrimitiveEntity:return i||new ha(d,p);case o.FunctionDeclaration:return i||new Oo(d,p);case o.GlobalEvent:return i||new ip(d,p);case o.DataType:return i||new dn(d,p);case o.Property:return i||new Ga(d,p);case o.FunctionCall:return i||new gp(d,p);case o.Condition:return i||new rp(d,p);case o.Operation:return i||new tp(d,p);case o.VariableDeclaration:return i||new pp(d,p);case o.VariableInstance:return i||new up(d,p);case o.OutputMap:return i||new jl(d,p);case o.ArgumentDeclaration:return i||new fa(d,p);case o.InputMap:return i||new hs(d,p);case o.Project:return i||new L(d);case o.InstalledProject:return i||new fp(d,p);case o.ActionDescriptor:return i||new Pi(d,p);case o.ReturnStatement:return i||new $d(d,p);case o.Loop:return i||new np(d,p);case o.Search:return i||new cp(d,p);case o.ValueDescriptor:return i||new Md(d,p);case o.BuiltInBaseEntity:return i||new xo(d,p);case o.InternalCall:return i||new yp(d,p);case o.ContinueStatement:return i||new mp(d,p);case o.BreakStatement:return i||new hp(d,p);case o.GenericReference:return p.get(d.entityId);default:throw new Error("Invalid entity type: "+d.type)}}function me(d,p){if(!d)throw new Error("Entity is null");const i=Ui(d,p);return i.subscribe(),i}function D2t(d,p){if(!d)throw new Error("Entity is null");switch(d.type){case o.LiteralValue:return Xn.fromGenerationTarget(d,p);case o.DefinitionEntity:return vs.fromGenerationTarget(d,p);case o.FunctionDeclaration:return Oo.fromGenerationTarget(d,p);case o.GlobalEvent:return ip.fromGenerationTarget(d,p);case o.DataType:return dn.fromGenerationTarget(d,p);case o.Property:return Ga.fromGenerationTarget(d,p);case o.FunctionCall:return gp.fromGenerationTarget(d,p);case o.Condition:return rp.fromGenerationTarget(d,p);case o.Operation:return tp.fromGenerationTarget(d,p);case o.VariableDeclaration:return pp.fromGenerationTarget(d,p);case o.VariableInstance:return up.fromGenerationTarget(d,p);case o.OutputMap:return jl.fromGenerationTarget(d,p);case o.ArgumentDeclaration:return fa.fromGenerationTarget(d,p);case o.InputMap:return hs.fromGenerationTarget(d,p);case o.InstalledProject:return fp.fromGenerationTarget(d,p);case o.ReturnStatement:return $d.fromGenerationTarget(d,p);case o.Loop:return np.fromGenerationTarget(d,p);case o.Search:return cp.fromGenerationTarget(d,p);case o.ActionDescriptor:return Pi.fromGenerationTarget(d,p);case o.ValueDescriptor:return Md.fromGenerationTarget(d,p);case o.InternalCall:return yp.fromGenerationTarget(d,p);case o.ContinueStatement:return mp.fromGenerationTarget(d,p);case o.BreakStatement:return hp.fromGenerationTarget(d,p);default:throw new Error("Invalid entity type: "+d.type)}}const dt={seenEntityMaps:new Map,seenEntities:new Set,timestamp:B().toISOString()};class Dxe{constructor(){R(this,"initialData")}}const Be={cascade:!1},Oxe={APILoad:async(d,...p)=>null},O2t={APICreate:async(d,...p)=>d,APIUpdate:async(d,...p)=>d,APIDelete:async(d,...p)=>d,APIClone:async(d,...p)=>{},APILoadVersion:async(d,p,...i)=>null,...Oxe};class w2t{}class wxe extends Dxe{}class C2t extends wxe{}class _2t{}class P2t{}class V2t{}class mP{}class N2t extends mP{}class $2t extends mP{}class L2t{}class jc{static initReadsValue(p){if(p.initialData.readsValue&&p.initialData.readsValue.type!==o.GenericReference)p.readsValue=me(p.initialData.readsValue,p.project);else if(p.initialData.readsValue&&p.initialData.readsValue.type===o.GenericReference){const i=Wr(p.initialData.readsValue,p.project);i&&(p.readsValue=i)}if(p.readsValue){if(St.includes(p.readsValue.type)){let i=p.parent;!En.includes(i.type)&&i.type!==o.Project&&(i=i.parent);const r=p.type===o.InputMap&&p.parent.type===o.Loop;r&&(i=p.parent.parent),p.readsValue.setParent(i,null),p.readsValue.initChildren(null),i&&i.type!==o.Project&&!r&&i.detachedChildren.includes(p)?i.replaceDetachedChild(p,p.readsValue):i&&i.type!==o.Project&&!r&&i.subscribeDetachedChild(p.readsValue)}p.readsValue.addValueReader(p,null)}return p.readsValue}}class ZT{static initWritesValues(p,i){const r=p.initialData.writesValues.reduce((c,e)=>{if(e.type===o.GenericReference||p.writesValues.some(v=>v.id===e.id))return c;const y=me(e,p.project);return y.setValueWriter(p,null),St.includes(y.type)&&(y.setParent(i,null),y.initChildren(null)),[...c,y]},[]),l=[...p.writesValues];return p.writesValues=O([...l,...r]),p.writesValues}}class x2t{}var ti=(d=>(d.PROJECT_INITIALIZED="project-initialized",d.BEFORE_CHANGE_SET_CLOSE_BEFORE_SIDE_EFFECTS="before-change-set-close-before-side-effects",d.BEFORE_CHANGE_SET_CLOSE_AFTER_SIDE_EFFECTS="before-change-set-close-after-side-effects",d.CHANGE_SET_CLOSED_BEFORE_PERSIST="change-set-closed-before-persist",d.CHANGE_SET_PERSISTED="change-set-persisted",d.BEFORE_CHANGE_SET_PERSIST="before-change-set-persist",d.EXPLICIT_DEFINITION_ENTITY_ADDED="explicit-definition-entity-added",d.EXPLICIT_DEFINITION_ENTITY_REMOVED="explicit-definition-entity-removed",d.EXPLICIT_DEFINITION_ENTITY_UPDATED="explicit-definition-entity-updated",d.PERSISTED_DEFINITION_ENTITY_ADDED="persisted-definition-entity-added",d.PERSISTED_DEFINITION_ENTITY_REMOVED="persisted-definition-entity-removed",d.PERSISTED_DEFINITION_ENTITY_UPDATED="persisted-definition-entity-updated",d.RELATIONAL_DATABASE_DEFINITION_ENTITY_ADDED="relational-database-definition-entity-added",d.RELATIONAL_DATABASE_DEFINITION_ENTITY_REMOVED="relational-database-definition-entity-removed",d.RELATIONAL_DATABASE_DEFINITION_ENTITY_UPDATED="relational-database-definition-entity-updated",d))(ti||{});const TP={...LC,events:new _y},Cxe={requestActiveDynamicValue:(d,p=!1)=>null,...TP},Pt=class Pt extends Un{constructor(i,r={...Cxe,events:new _y}){super(i);R(this,"initialData");R(this,"id");R(this,"type",o.Project);R(this,"name",null);R(this,"description",null);R(this,"x");R(this,"y");R(this,"entities",[]);R(this,"projects",[]);R(this,"functions",[]);R(this,"events",[]);R(this,"variableDeclarations",[]);R(this,"variableInstances",[]);R(this,"conditions",[]);R(this,"operations",[]);R(this,"functionCalls",[]);R(this,"loops",[]);R(this,"searches",[]);R(this,"primitives",[]);R(this,"builtInBaseEntities",[]);R(this,"operationDeclarations",[]);R(this,"globalEventActionDescriptors",[]);R(this,"loopDeclarations",[]);R(this,"loopDeclarationsBodies",[]);R(this,"conditionDeclarations",[]);R(this,"valueDescriptors",[]);R(this,"dataTypes",[]);R(this,"project");R(this,"instances",{});R(this,"builtInInstances",{});R(this,"deletedInstances",{});R(this,"errors",[]);R(this,"references",[]);R(this,"history",[]);R(this,"undoableStackValueIndex",-1);R(this,"detachedDependents",{});R(this,"knownVersions",null);R(this,"activeVersion",!1);R(this,"initialized",!1);R(this,"startedInitialization",!1);R(this,"onPersistChangeSetSequentiallyCallback",null);R(this,"onPersistChangeSetInParallelCallback",null);R(this,"onAddChangeSetCallback",null);R(this,"onDiscardChangeSetCallback",null);if(this.parentContext=r,this.initialData=i,this.id=i.id,this.name=i.name,this.description=i.description,this.x=0,this.y=0,this.instances[this.id]=this,!Pt.UUID)throw new Error("UUID module is already initialized. Please inject a valid UUID module.")}static get UUID(){var i;return(i=this.parentContext.requestExtension("uuid"))==null?void 0:i.module}static new(i=null){return{id:Pt.UUID.uuid(),version:Pt.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||B().toISOString(),author:(i==null?void 0:i.author)||Pt.sessionAuthor,previousVersion:null,deleted:!1,deletable:!0,editable:!0,type:o.Project,name:"",description:"",entities:[],functions:[],events:[],projects:[],variableDeclarations:[],variableInstances:[],conditions:[],operations:[],functionCalls:[],loops:[],searches:[]}}static validateGenerationTarget(i,r){let l=JSON.parse(JSON.stringify(i));const c=[];return c.push(...Pn(l)),{errors:c,modifiedData:l}}get off(){return this.parentContext.events.off}get on(){return this.parentContext.events.on}get emit(){return this.parentContext.events.emit}get emitAsync(){return this.parentContext.events.emitAsync}get emitAsyncAll(){return this.parentContext.events.emitAsyncAll}get emitAsyncAllSettled(){return this.parentContext.events.emitAsyncAllSettled}get emitAsyncSequentially(){return this.parentContext.events.emitAsyncSequentially}get emitAsyncSequentiallyAll(){return this.parentContext.events.emitAsyncSequentiallyAll}get emitAsyncSequentiallyAllSettled(){return this.parentContext.events.emitAsyncSequentiallyAllSettled}async closePersistChangeSetsSequentially(){console.log("[ProjectState.closePersistChangeSetsSequentially] called");const i=this.history.find(r=>r.dirty&&!r.open&&!r.submitting);i&&(console.log(`[ProjectState.closePersistChangeSetsSequentially] closing pending change-set ${i.id} - ${i.autoCloseActionName}`),await this.persistChangeSetSequentially(i))}async onPersistChangeSetSequentially(i){this.onPersistChangeSetSequentiallyCallback=i,console.log("[ProjectState.onPersistChangeSetSequentially] onPersistChangeSetSequentiallyCallback has been set. Checking for pending change-sets."),await this.closePersistChangeSetsSequentially()}async onPersistChangeSetInParallel(i){this.onPersistChangeSetInParallelCallback=i,console.log("[ProjectState.onPersistChangeSetInParallel] onPersistChangeSetInParallelCallback has been set. Checking for pending change-sets.");for(const r of this.history)this.persistChangeSetInParallel(r),await new Promise(l=>setTimeout(l,27))}onAddChangeSet(i){this.onAddChangeSetCallback=i}onDiscardChangeSet(i){this.onDiscardChangeSetCallback=i}async persistChangeSetSequentially(i){if(console.log(`[ProjectState.persistChangeSetSequentially] called for change-set ${i.id} - ${i.autoCloseActionName}`),!i.dirty||i.open||i.submitting){console.log(`[ProjectState.persistChangeSetSequentially] change-set ${i.id} - ${i.autoCloseActionName} is not dirty, or is open, or is already being submitted, skipping.`);return}const r=this.history.findIndex(e=>e.id===i.id),l=this.history.slice(0,r),c=l[l.length-1];if(c!=null&&c.dirty){console.log(`[ProjectState.persistChangeSetSequentially] lastBeforeSelf is dirty: ${c.id} - ${c.autoCloseActionName}, closing it first.`);return}this.onPersistChangeSetSequentiallyCallback&&(console.log(`[ProjectState.persistChangeSetSequentially] invoking onPersistChangeSetSequentiallyCallback for change-set ${i.id} - ${i.autoCloseActionName}`),this.emit("before-change-set-persist",i),i.submitting=!0,(await this.onPersistChangeSetSequentiallyCallback(i)).success&&(i.dirty=!1,this.emit("change-set-persisted",i),console.log(`[ProjectState.persistChangeSetSequentially] change-set ${i.id} - ${i.autoCloseActionName} closed successfully, checking for pending change-sets to close.`),this.closePersistChangeSetsSequentially()))}async persistChangeSetInParallel(i){if(console.log(`[ProjectState.persistChangeSetInParallel] called for change-set ${i.id} - ${i.autoCloseActionName}`),!i.dirty||i.open||i.submitting){console.log(`[ProjectState.persistChangeSetInParallel] change-set ${i.id} - ${i.autoCloseActionName} is not dirty, or is open, or is already being submitted, skipping.`);return}this.onPersistChangeSetInParallelCallback&&(console.log(`[ProjectState.persistChangeSetInParallel] invoking onPersistChangeSetInParallelCallback for change-set ${i.id} - ${i.autoCloseActionName}`),this.emit("before-change-set-persist",i),i.submitting=!0,(await this.onPersistChangeSetInParallelCallback(i)).success&&(i.dirty=!1,this.emit("change-set-persisted",i)))}toLatestChangeSet(i,r,l,c=!1,e="here-this"){if(!this.history.length)return new H(this,i,r,l,c,e);const y=this.history[this.history.length-1];return y.open?y:this.addChangeSet(new H(this,i,r,l,c,e))}addChangeSet(i){var c,e;if(!this.history.length)return this.undoableStackValueIndex=qw(this.undoableStackValueIndex,this.history,i),(c=this.onAddChangeSetCallback)==null||c.call(this,i,this.undoableStackValueIndex),i;const r=this.history.find(y=>y.id===(i==null?void 0:i.id));if(r)return r;const l=this.history.find(y=>y.open);if(l)throw ae.warn("Previous still open: ",l),ae.warn("New change set: ",i),new Error(`There is already an open change-set with id '${l.id}'.`);return this.undoableStackValueIndex=qw(this.undoableStackValueIndex,this.history,i),(e=this.onAddChangeSetCallback)==null||e.call(this,i,this.undoableStackValueIndex),i}discardChangeSet(i){var l;console.log(`[ProjectState.discardChangeSet] called for change-set ${i.id} - ${i.autoCloseActionName}`);const r=this.history.findIndex(c=>c.id===(i==null?void 0:i.id));return r!==-1&&(this.history.splice(r,1),console.log(`[ProjectState.discardChangeSet] Removed change-set ${i.id} - ${i.autoCloseActionName} from history.`),this.undoableStackValueIndex=this.undoableStackValueIndex-1,(l=this.onDiscardChangeSetCallback)==null||l.call(this,i),i==null||i.teardown()),this}validateGeneratedUpdate(i){return{errors:[],modifiedData:i}}subscribeDependents(i){return i.forEach(r=>{this.detachedDependents[r.entity.id]||(this.detachedDependents[r.entity.id]=r)}),this}unsubscribeDependents(i){return i.forEach(r=>{this.detachedDependents[r.entity.id]&&delete this.detachedDependents[r.entity.id]}),this}syncDependents(i=this.project.addChangeSet(new H(this.project,Pt.sessionAuthor,B().toISOString(),this,!0,"sync-dependents"))){const r=[],l=[],c=[],e=[];return Object.values(this.detachedDependents).forEach(y=>{const v=y.entity.afterAllChildrenInitialized(i);r.push(...v.updated),l.push(...v.added),c.push(...v.removed),e.push(...v.affected)}),i==null||i.attemptAutoclose("sync-dependents",this.id),{updated:O(r),added:O(l),removed:O(c),affected:O(e),self:this}}onDetachedDependencyRemoved(i,r,l){const c=[],e=[],y=[],v=[];return{updated:O(c),added:O(e),removed:O(y),affected:O(v),self:this}}onDetachedDependencyRestored(i,r,l){const c=[],e=[],y=[],v=[];return{updated:O(c),added:O(e),removed:O(y),affected:O(v),self:this}}unsubscribeFromDependencies(){return this}subscribeToDependencies(){return this}increaseVersion(i){if(i&&!B(i).isValid())throw new Error(`The shared timestamp '${i}' is not a valid ISO 8601 date string.`);return i&&B(i).isSame(B(this.createdAt))?this:(this.previousVersion=this.version,this.version=Pt.UUID.uuid(),this.createdAt=B(i).toISOString()||B().toISOString(),this)}captureVersion(){var r;const i=((r=this.knownVersions)==null?void 0:r.get(this.version))||new Pt(this);return i.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,i):new Map([[this.version,i]]),i.entities=[...this.entities],i.projects=[...this.projects],i.functions=[...this.functions],i.events=[...this.events],i.variableDeclarations=[...this.variableDeclarations],i.variableInstances=[...this.variableInstances],i.conditions=[...this.conditions],i.operations=[...this.operations],i.functionCalls=[...this.functionCalls],i.loops=[...this.loops],i.searches=[...this.searches],this}recursiveCaptureUpstreamVersions(i){const r=[],l=[],c=[],e=[];return{updated:O(r),added:O(l),removed:O(c),affected:O(e),self:this}}async restoreVersion(i){var v;const r=[],l=[],c=[],e=[];if(this.version===i)return{updated:O(r),added:O(l),removed:O(c),affected:O(e),self:this};if(!this.knownVersions){const b=new Map;for(const[A,E]of this.knownVersions||new Map){if(b.set(A,E),E.activeVersion=!1,E.knownVersions)for(const[w,P]of E.knownVersions)b.set(w,P);E.knownVersions=null}}let y=(v=this.knownVersions)==null?void 0:v.get(i);if(!y){const b=await this.APILoadVersion({},i);if(!b)throw new Error(`Version with id '${i}' for entity with id '${this.id}' not found.`);y=new Pt(b)}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.entities=y.entities,this.projects=y.projects,this.functions=y.functions,this.events=y.events,this.variableDeclarations=y.variableDeclarations,this.variableInstances=y.variableInstances,this.conditions=y.conditions,this.operations=y.operations,this.functionCalls=y.functionCalls,this.loops=y.loops,this.searches=y.searches,{updated:O(r),added:O(l),removed:O(c),affected:O(e),self:this}}updateWithShallowTransfer(i,r=this.project.addChangeSet(new H(this.project,Pt.sessionAuthor,B().toISOString(),this,!0,V.UpdateWithShallowTransfer))){return this.checkCanEdit(this,r)?(this.metaSync(i,r),this.version=i.version,this.createdAt=i.createdAt,this.author=i.author,this.deleted=i.deleted,this.previousVersion=i.previousVersion,this.captureVersion(),this.subscribeToDependencies(),r==null||r.attemptAutoclose(V.UpdateWithShallowTransfer,this.id),this):(ae.warn(`[updateWithShallowTransfer] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),r==null||r.attemptAutoclose(V.UpdateWithShallowTransfer,this.id),this)}hydrateAncestors(){const i=[],r=[],l=[],c=[];return{updated:O(i),added:O(r),removed:O(l),affected:O(c),self:this}}afterAllChildrenInitialized(i=null){const r=[],l=[],c=[],e=[];return this.initialized||(this.initialized=!0,this.emit("project-initialized",this,i)),this.validate(),this.captureVersion(),{updated:O(r),added:O(l),removed:O(c),affected:O(e),self:this}}addSelfToProject(i){const r=[],l=[],c=[],e=[];return this.subscribe(),this.subscribeToDependencies(),{updated:O(r),added:O(l),removed:O(c),affected:O(e),self:this}}get instancesList(){return Object.values(this.instances)}isOperationDeclaration(i){return this.operationDeclarations.includes(i)}isGlobalEventActionDescriptor(i){return this.globalEventActionDescriptors.includes(i)}isLoopDeclaration(i){return this.loopDeclarations.includes(i)}isConditionDeclaration(i){return this.conditionDeclarations.includes(i)}initChildren(i=this.project.addChangeSet(new H(this.project,Pt.sessionAuthor,B().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.entities=this.initialData.entities.map(r=>{const l=me(r,this);return l.setParent(this,null),l.initChildren(i),l}),this.projects=this.initialData.projects.map(r=>{const l=me(r,this);return l.setParent(this,null),l.initChildren(i),l}),this.variableDeclarations=this.initialData.variableDeclarations.map(r=>{const l=me(r,this);return l.setParent(this,null),l.initChildren(i),l}),this.variableInstances=this.initialData.variableInstances.map(r=>{const l=me(r,this);return l.setParent(this,null),l.initChildren(i),l}),this.conditions=this.initialData.conditions.map(r=>{const l=me(r,this);return l.setParent(this,null),l.initChildren(i),l}),this.operations=this.initialData.operations.map(r=>{const l=me(r,this);return l.setParent(this,null),l.initChildren(i),l}),this.functions=this.initialData.functions.map(r=>{const l=me(r,this);return l.setParent(this,null),l.initChildren(i),l}),this.events=this.initialData.events.map(r=>{const l=me(r,this);return l.setParent(this,null),l.initChildren(i),l}),this.functionCalls=this.initialData.functionCalls.map(r=>{const l=me(r,this);return l.setParent(this,null),l.initChildren(i),l}),this.loops=this.initialData.loops.map(r=>{const l=me(r,this);return l.setParent(this,null),l.initChildren(i),l}),this.searches=this.initialData.searches.map(r=>{const l=me(r,this);return l.setParent(this,null),l.initChildren(i),l}),this.attachOrphanReferences(),this.subscribeToDependencies(),this.afterAllChildrenInitialized(i),i==null||i.attemptAutoclose("init-children",this.id),this)}subscribeInstance(i){return(!this.instances[i.id]||this.instances[i.id]!==i)&&(this.instances[i.id]=i),this}subscribeDeletedInstance(i){return(!this.deletedInstances[i.id]||this.deletedInstances[i.id]!==i)&&(this.deletedInstances[i.id]=i),this}subscribeBuiltInInstance(i){return(!this.builtInInstances[i.id]||this.builtInInstances[i.id]!==i)&&(this.builtInInstances[i.id]=i),this}subscribe(){return this}unsubscribe(){return this}unsubscribeInstance(i){return delete this.instances[i.id],this}unsubscribeDeletedInstance(i){return delete this.deletedInstances[i.id],this}findSubscribedBuiltInInstance(i){return this.builtInInstances[i.id]||null}get(i){return this.instances[i]||this.builtInInstances[i]||null}getDeleted(i){return this.deletedInstances[i]||null}getManaged(i){return this.getBuiltIn(i)?null:this.instances[i]||null}getBuiltIn(i){return this.builtInInstances[i]||null}findSubscribedInstanceFromReference(i){return this.instances[i.entityId]||null}findSubscribedBuiltInInstanceFromReference(i){return this.builtInInstances[i.entityId]||null}metaSync(i,r=this.project.addChangeSet(new H(this.project,Pt.sessionAuthor,B().toISOString(),this,!0,"meta-sync"))){const l=$n(this,i,r),c=Nn(this,l),e=this.toMeta();return this.name=l.name!==void 0?l.name:e.name,this.description=l.description!==void 0?l.description:e.description,this.x=l.x||e.x,this.y=l.y||e.y,super.baseMetaSync(l,this,r),l.deleted===!0&&!e.deleted?r==null||r.add(this,W.Removed):l.deleted===!1&&e.deleted?r==null||r.add(this,W.Added):c&&(r==null||r.add(this,W.Updated)),r==null||r.attemptAutoclose("meta-sync",this.id),this}async APILoad(i=Be,...r){return await Pt.repository.APILoad(this.id,...r),this}async APICreate(i=Be,...r){return await Pt.repository.APICreate(this.toShallowJSON(),...r),this}async APIUpdate(i=Be,...r){return await Pt.repository.APIUpdate(this.toShallowJSON(),...r),this}async APIDelete(i=Be,...r){return await Pt.repository.APIDelete(this.toShallowJSON(),...r),this}async APIClone(i=Be,...r){return await Pt.repository.APIClone(this.id,...r),this}async APILoadVersion(i=Be,r,...l){return await Pt.repository.APILoadVersion(this.id,r,...l)}remove({ignoreUpstream:i}={ignoreUpstream:!1},r=this.project.addChangeSet(new H(this.project,Pt.sessionAuthor,B().toISOString(),this,!0,V.RemoveEntity))){return{added:[],updated:[],removed:[],affected:[],self:this}}restore({}={},i=this.project.addChangeSet(new H(this.project,Pt.sessionAuthor,B().toISOString(),this,!0,V.RestoreEntity))){return{added:[],updated:[],removed:[],affected:[],self:this}}getAllBuiltInIds(){const i=new Set;return[...this.primitives.flatMap(r=>r.toFlatIds(i)),...this.builtInBaseEntities.flatMap(r=>r.toFlatIds(i)),...this.operationDeclarations.flatMap(r=>r.toFlatIds(i)),...this.globalEventActionDescriptors.flatMap(r=>r.toFlatIds(i)),...this.loopDeclarations.flatMap(r=>r.toFlatIds(i)),...this.conditionDeclarations.flatMap(r=>r.toFlatIds(i)),...this.valueDescriptors.flatMap(r=>r.toFlatIds(i)),...this.dataTypes.flatMap(r=>r.toFlatIds(i))]}getAllBuiltIn(){const i=new Set;return[...this.primitives.flatMap(r=>r.toFlat(i)),...this.builtInBaseEntities.flatMap(r=>r.toFlat(i)),...this.operationDeclarations.flatMap(r=>r.toFlat(i)),...this.globalEventActionDescriptors.flatMap(r=>r.toFlat(i)),...this.loopDeclarations.flatMap(r=>r.toFlat(i)),...this.conditionDeclarations.flatMap(r=>r.toFlat(i)),...this.valueDescriptors.flatMap(r=>r.toFlat(i)),...this.dataTypes.flatMap(r=>r.toFlat(i))]}toFlat(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this,...this.entities.flatMap(l=>l.toFlat(i)),...this.functions.flatMap(l=>l.toFlat(i)),...this.events.flatMap(l=>l.toFlat(i)),...this.projects.flatMap(l=>l.toFlat(i)),...this.variableDeclarations.flatMap(l=>l.toFlat(i)),...this.variableInstances.flatMap(l=>l.toFlat(i)),...this.conditions.flatMap(l=>l.toFlat(i)),...this.operations.flatMap(l=>l.toFlat(i)),...this.functionCalls.flatMap(l=>l.toFlat(i)),...this.loops.flatMap(l=>l.toFlat(i)),...this.searches.flatMap(l=>l.toFlat(i))])}toFlatIds(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.id,...this.entities.flatMap(l=>l.toFlatIds(i)),...this.functions.flatMap(l=>l.toFlatIds(i)),...this.events.flatMap(l=>l.toFlatIds(i)),...this.projects.flatMap(l=>l.toFlatIds(i)),...this.variableDeclarations.flatMap(l=>l.toFlatIds(i)),...this.variableInstances.flatMap(l=>l.toFlatIds(i)),...this.conditions.flatMap(l=>l.toFlatIds(i)),...this.operations.flatMap(l=>l.toFlatIds(i)),...this.functionCalls.flatMap(l=>l.toFlatIds(i)),...this.loops.flatMap(l=>l.toFlatIds(i)),...this.searches.flatMap(l=>l.toFlatIds(i))])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,description:this.description,type:this.type,editable:this.editable,deletable:this.deletable,name:this.name}}toJSON(i=new Set){return i.has(this.id)?this.toReference():(i.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,editable:this.editable,deletable:this.deletable,name:this.name,description:this.description,entities:this.entities.map(r=>r.toJSON(i)),variableDeclarations:this.variableDeclarations.map(r=>r.toJSON(i)),variableInstances:this.variableInstances.map(r=>r.toJSON(i)),conditions:this.conditions.map(r=>r.toJSON(i)),operations:this.operations.map(r=>r.toJSON(i)),loops:this.loops.map(r=>r.toJSON(i)),searches:this.searches.map(r=>r.toJSON(i)),functions:this.functions.map(r=>r.toJSON(i)),events:this.events.map(r=>r.toJSON(i)),projects:this.projects.map(r=>r.toJSON(i)),functionCalls:this.functionCalls.map(r=>r.toJSON(i))})}toJSONClone(i={uuidStrategy:"uuid"}){const r=new Map,l=new Set,c=this.getAllBuiltInIds();return Object.keys(this.instances).forEach(e=>{if(c.includes(e)){r.set(e,e);return}r.set(e,Pt.UUID.uuid())}),l.add(this.id),{id:r.get(this.id),version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,editable:this.editable,deletable:this.deletable,name:this.name,description:this.description,entities:this.entities.map(e=>e.toJSONClone({...i,seenEntityMaps:r,seenEntities:l,newId:null})),projects:this.projects.map(e=>e.toJSONClone({...i,seenEntityMaps:r,seenEntities:l,newId:null})),variableDeclarations:this.variableDeclarations.map(e=>e.toJSONClone({...i,seenEntityMaps:r,seenEntities:l,newId:null})),variableInstances:this.variableInstances.map(e=>e.toJSONClone({...i,seenEntityMaps:r,seenEntities:l,newId:null})),conditions:this.conditions.map(e=>e.toJSONClone({...i,seenEntityMaps:r,seenEntities:l,newId:null})),operations:this.operations.map(e=>e.toJSONClone({...i,seenEntityMaps:r,seenEntities:l,newId:null})),functions:this.functions.map(e=>e.toJSONClone({...i,seenEntityMaps:r,seenEntities:l,newId:null})),events:this.events.map(e=>e.toJSONClone({...i,seenEntityMaps:r,seenEntities:l,newId:null})),functionCalls:this.functionCalls.map(e=>e.toJSONClone({...i,seenEntityMaps:r,seenEntities:l,newId:null})),loops:this.loops.map(e=>e.toJSONClone({...i,seenEntityMaps:r,seenEntities:l,newId:null})),searches:this.searches.map(e=>e.toJSONClone({...i,seenEntityMaps:r,seenEntities:l,newId:null}))}}toReference(i=dt){var l;let r=this.id;return(l=i.seenEntityMaps)!=null&&l.has(this.id)&&(r=i.seenEntityMaps.get(this.id)),{id:r+"--"+Pt.UUID.uuid()+"--ref",type:o.GenericReference,entityId:r,version:this.version,entityType:this.type}}toShallowJSON(i=dt){var l;let r=this.id;return(l=i.seenEntityMaps)!=null&&l.has(this.id)&&(r=i.seenEntityMaps.get(this.id)),{id:r,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,editable:this.editable,deletable:this.deletable,name:this.name,description:this.description,entities:this.entities.map(c=>c.toReference(i)),functions:this.functions.map(c=>c.toReference(i)),events:this.events.map(c=>c.toReference(i)),projects:this.projects.map(c=>c.toReference(i)),variableDeclarations:this.variableDeclarations.map(c=>c.toReference(i)),variableInstances:this.variableInstances.map(c=>c.toReference(i)),conditions:this.conditions.map(c=>c.toReference(i)),operations:this.operations.map(c=>c.toReference(i)),functionCalls:this.functionCalls.map(c=>c.toReference(i)),loops:this.loops.map(c=>c.toReference(i)),searches:this.searches.map(c=>c.toReference(i))}}toFlatJSON(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.toShallowJSON(),...this.entities.flatMap(l=>l.toFlatJSON(i)),...this.functions.flatMap(l=>l.toFlatJSON(i)),...this.events.flatMap(l=>l.toFlatJSON(i)),...this.projects.flatMap(l=>l.toFlatJSON(i)),...this.variableDeclarations.flatMap(l=>l.toFlatJSON(i)),...this.variableInstances.flatMap(l=>l.toFlatJSON(i)),...this.conditions.flatMap(l=>l.toFlatJSON(i)),...this.operations.flatMap(l=>l.toFlatJSON(i)),...this.functionCalls.flatMap(l=>l.toFlatJSON(i)),...this.loops.flatMap(l=>l.toFlatJSON(i)),...this.searches.flatMap(l=>l.toFlatJSON(i))])}toGenerationTarget(){return{id:this.id,type:this.type,name:this.name,description:this.description}}toFlatGenerationTarget(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[...this.entities.flatMap(l=>l.toFlatGenerationTarget(i)),...this.functions.flatMap(l=>l.toFlatGenerationTarget(i)),...this.events.flatMap(l=>l.toFlatGenerationTarget(i)),...this.projects.flatMap(l=>l.toFlatGenerationTarget(i)),...this.variableDeclarations.flatMap(l=>l.toFlatGenerationTarget(i)),...this.variableInstances.flatMap(l=>l.toFlatGenerationTarget(i)),...this.conditions.flatMap(l=>l.toFlatGenerationTarget(i)),...this.operations.flatMap(l=>l.toFlatGenerationTarget(i)),...this.functionCalls.flatMap(l=>l.toFlatGenerationTarget(i)),...this.loops.flatMap(l=>l.toFlatGenerationTarget(i)),...this.searches.flatMap(l=>l.toFlatGenerationTarget(i))])}clearErrors(){return this.errors=[],this.entities.forEach(i=>i.clearErrors()),this.projects.forEach(i=>i.clearErrors()),this.functions.forEach(i=>i.clearErrors()),this.events.forEach(i=>i.clearErrors()),this.variableDeclarations.forEach(i=>i.clearErrors()),this.variableInstances.forEach(i=>i.clearErrors()),this.conditions.forEach(i=>i.clearErrors()),this.operations.forEach(i=>i.clearErrors()),this.functionCalls.forEach(i=>i.clearErrors()),this.loops.forEach(i=>i.clearErrors()),this.searches.forEach(i=>i.clearErrors()),this}validate(){return this.validateChildren(),om([...this.errors]),{success:!0}}validateChildren(){this.entities.forEach(i=>i.validate()),this.projects.forEach(i=>i.validate()),this.functions.forEach(i=>i.validate()),this.events.forEach(i=>i.validate()),this.variableDeclarations.forEach(i=>i.validate()),this.variableInstances.forEach(i=>i.validate()),this.conditions.forEach(i=>i.validate()),this.operations.forEach(i=>i.validate()),this.functionCalls.forEach(i=>i.validate()),this.loops.forEach(i=>i.validate()),this.searches.forEach(i=>i.validate())}getErrors(){return[...this.errors,...this.entities.flatMap(r=>r.getErrors()),...this.projects.flatMap(r=>r.getErrors()),...this.functions.flatMap(r=>r.getErrors()),...this.events.flatMap(r=>r.getErrors()),...this.variableDeclarations.flatMap(r=>r.getErrors()),...this.variableInstances.flatMap(r=>r.getErrors()),...this.conditions.flatMap(r=>r.getErrors()),...this.operations.flatMap(r=>r.getErrors()),...this.functionCalls.flatMap(r=>r.getErrors()),...this.loops.flatMap(r=>r.getErrors()),...this.searches.flatMap(r=>r.getErrors())]}getShallowErrors(){return this.errors}clone(){return this}getDefinitionEntity(i){return this.entities.find(r=>r.id===i)||null}addDefinitionEntity(i){return this.entities.includes(i)||this.entities.push(i),i}addFunctionDeclaration(i){return this.functions.includes(i)||this.functions.push(i),i}addFunctionCall(i){return this.functionCalls.includes(i)||this.functionCalls.push(i),i}addVariableDeclaration(i){return this.variableDeclarations.includes(i)||this.variableDeclarations.push(i),i}addVariableInstance(i){return this.variableInstances.includes(i)||this.variableInstances.push(i),i}addInstalledProject(i){return this.projects.includes(i)||this.projects.push(i),this}addGlobalEvent(i){return this.events.includes(i)||this.events.push(i),this}addCondition(i){return this.conditions.includes(i)||this.conditions.push(i),this}addOperation(i){return this.operations.includes(i)||this.operations.push(i),this}addLoop(i){return this.loops.includes(i)||this.loops.push(i),this}addSearch(i){return this.searches.includes(i)||this.searches.push(i),this}removeDefinitionEntity(i){const r=this.entities.findIndex(l=>l.id===i.id);if(r>-1){const l=this.entities[r];return this.entities.splice(r,1),l}return null}removeCondition(i){const r=this.conditions.findIndex(l=>l.id===i.id);if(r>-1){const l=this.conditions[r];return this.conditions.splice(r,1),l}return null}removeOperation(i){const r=this.operations.findIndex(l=>l.id===i.id);if(r>-1){const l=this.operations[r];return this.operations.splice(r,1),l}return null}removeLoop(i){const r=this.loops.findIndex(l=>l.id===i.id);if(r>-1){const l=this.loops[r];return this.loops.splice(r,1),l}return null}removeSearch(i){const r=this.searches.findIndex(l=>l.id===i.id);if(r>-1){const l=this.searches[r];return this.searches.splice(r,1),l}return null}removeFunctionCall(i){const r=this.functionCalls.findIndex(l=>l.id===i.id);if(r>-1){const l=this.functionCalls[r];return this.functionCalls.splice(r,1),l}return null}removeVariableInstance(i){const r=this.variableInstances.findIndex(l=>l.id===i.id);if(r>-1){const l=this.variableInstances[r];return this.variableInstances.splice(r,1),l}return null}removeVariableDeclaration(i){const r=this.variableDeclarations.findIndex(l=>l.id===i.id);if(r>-1){const l=this.variableDeclarations[r];return this.variableDeclarations.splice(r,1),l}return null}removeFunctionDeclaration(i){const r=this.functions.findIndex(l=>l.id===i.id);if(r>-1){const l=this.functions[r];return this.functions.splice(r,1),l}return null}removeInstalledProject(i){const r=this.projects.findIndex(l=>l.id===i.id);if(r>-1){const l=this.projects[r];return this.projects.splice(r,1),l}return null}removeGlobalEvent(i){const r=this.events.findIndex(l=>l.id===i.id);if(r>-1){const l=this.events[r];return this.events.splice(r,1),l}return null}removeTopLevelVariableDeclaration(i){if(i.type!==o.VariableDeclaration)return null;const r=this.variableDeclarations.findIndex(l=>l.id===i.id);if(r>-1){const l=this.variableDeclarations[r];return this.variableDeclarations.splice(r,1),l}return null}getEntryPoints(){return[...this.functions,...this.events,...this.entities.flatMap(r=>r.methods)]}getTerminationStatements(){return[...this.getEntryPoints().reduce((r,l)=>{const c=Ot(l);return[...r,...c.filter(e=>e.type===o.ReturnStatement||e.type===o.ContinueStatement||e.type===o.BreakStatement)]},[])]}getFunctionDeclaration(i){return this.functions.find(r=>r.id===i)||null}getConditions(){return[...this.conditions,...this.getEntryPoints().reduce((r,l)=>{const c=Ot(l);return[...r,...c.filter(e=>e.type===o.Condition)]},[]),...this.functionCalls.reduce((r,l)=>{const c=Ot(l);return[...r,...c.filter(e=>e.type===o.Condition)]},[]),...this.operations.reduce((r,l)=>{const c=Ot(l);return[...r,...c.filter(e=>e.type===o.Condition)]},[]),...this.loops.reduce((r,l)=>{const c=Ot(l);return[...r,...c.filter(e=>e.type===o.Condition)]},[]),...this.searches.reduce((r,l)=>{const c=Ot(l);return[...r,...c.filter(e=>e.type===o.Condition)]},[])]}getOperations(){return[...this.operations,...this.getEntryPoints().reduce((r,l)=>{const c=Ot(l);return[...r,...c.filter(e=>e.type===o.Operation)]},[]),...this.functionCalls.reduce((r,l)=>{const c=Ot(l);return[...r,...c.filter(e=>e.type===o.Operation)]},[]),...this.conditions.reduce((r,l)=>{const c=Ot(l);return[...r,...c.filter(e=>e.type===o.Operation)]},[]),...this.loops.reduce((r,l)=>{const c=Ot(l);return[...r,...c.filter(e=>e.type===o.Operation)]},[]),...this.searches.reduce((r,l)=>{const c=Ot(l);return[...r,...c.filter(e=>e.type===o.Operation)]},[])]}getFunctionCalls(){return[...this.functionCalls,...this.getEntryPoints().reduce((r,l)=>{const c=Ot(l);return[...r,...c.filter(e=>e.type===o.FunctionCall)]},[]),...this.conditions.reduce((r,l)=>{const c=Ot(l);return[...r,...c.filter(e=>e.type===o.FunctionCall)]},[]),...this.operations.reduce((r,l)=>{const c=Ot(l);return[...r,...c.filter(e=>e.type===o.FunctionCall)]},[]),...this.loops.reduce((r,l)=>{const c=Ot(l);return[...r,...c.filter(e=>e.type===o.FunctionCall)]},[]),...this.searches.reduce((r,l)=>{const c=Ot(l);return[...r,...c.filter(e=>e.type===o.FunctionCall)]},[])]}getVariables(){return[...this.variableDeclarations,...this.getEntryPoints().reduce((r,l)=>{const c=zi(l);return[...r,...c]},[]),...this.functionCalls.reduce((r,l)=>{const c=zi(l);return[...r,...c]},[]),...this.conditions.reduce((r,l)=>{const c=zi(l);return[...r,...c]},[]),...this.operations.reduce((r,l)=>{const c=zi(l);return[...r,...c]},[]),...this.loops.reduce((r,l)=>{const c=zi(l);return[...r,...c]},[]),...this.searches.reduce((r,l)=>{const c=zi(l);return[...r,...c]},[])]}getVariableInstances(){return[...this.variableInstances,...this.entities.reduce((r,l)=>[...r,...l.methods.flatMap(c=>{const y=Ot(c).filter(v=>v.type===o.VariableInstance);return[...r,...y]})],[]),...this.getEntryPoints().reduce((r,l)=>{const e=zi(l).filter(y=>y.type===o.VariableInstance);return[...r,...e]},[]),...this.functionCalls.reduce((r,l)=>{const e=zi(l).filter(y=>y.type===o.VariableInstance);return[...r,...e]},[]),...this.conditions.reduce((r,l)=>{const e=zi(l).filter(y=>y.type===o.VariableInstance);return[...r,...e]},[]),...this.operations.reduce((r,l)=>{const e=zi(l).filter(y=>y.type===o.VariableInstance);return[...r,...e]},[]),...this.loops.reduce((r,l)=>{const e=zi(l).filter(y=>y.type===o.VariableInstance);return[...r,...e]},[]),...this.searches.reduce((r,l)=>{const e=zi(l).filter(y=>y.type===o.VariableInstance);return[...r,...e]},[])]}getVariableDeclarations(){return O([...this.variableDeclarations,...this.entities.reduce((r,l)=>[...r,...l.methods.flatMap(c=>{const y=Ot(c).filter(v=>v.type===o.VariableDeclaration);return[...r,...y]})],[]),...this.getEntryPoints().reduce((r,l)=>{const e=zi(l).filter(y=>y.type===o.VariableDeclaration);return[...r,...e]},[]),...this.functionCalls.reduce((r,l)=>{const e=zi(l).filter(y=>y.type===o.VariableDeclaration);return[...r,...e]},[]),...this.conditions.reduce((r,l)=>{const e=zi(l).filter(y=>y.type===o.VariableDeclaration);return[...r,...e]},[]),...this.operations.reduce((r,l)=>{const e=zi(l).filter(y=>y.type===o.VariableDeclaration);return[...r,...e]},[]),...this.loops.reduce((r,l)=>{const e=zi(l).filter(y=>y.type===o.VariableDeclaration);return[...r,...e]},[]),...this.searches.reduce((r,l)=>{const e=zi(l).filter(y=>y.type===o.VariableDeclaration);return[...r,...e]},[])])}getLoops(){return[...this.loops,...this.getEntryPoints().reduce((r,l)=>{const c=Ot(l);return[...r,...c.filter(e=>e.type===o.Loop)]},[]),...this.functionCalls.reduce((r,l)=>{const c=Ot(l);return[...r,...c.filter(e=>e.type===o.Loop)]},[]),...this.conditions.reduce((r,l)=>{const c=Ot(l);return[...r,...c.filter(e=>e.type===o.Loop)]},[]),...this.operations.reduce((r,l)=>{const c=Ot(l);return[...r,...c.filter(e=>e.type===o.Loop)]},[]),...this.searches.reduce((r,l)=>{const c=Ot(l);return[...r,...c.filter(e=>e.type===o.Loop)]},[])]}getSearches(){return[...this.searches,...this.getEntryPoints().reduce((r,l)=>{const c=Ot(l);return[...r,...c.filter(e=>e.type===o.Search)]},[]),...this.functionCalls.reduce((r,l)=>{const c=Ot(l);return[...r,...c.filter(e=>e.type===o.Search)]},[]),...this.conditions.reduce((r,l)=>{const c=Ot(l);return[...r,...c.filter(e=>e.type===o.Search)]},[]),...this.operations.reduce((r,l)=>{const c=Ot(l);return[...r,...c.filter(e=>e.type===o.Search)]},[]),...this.loops.reduce((r,l)=>{const c=Ot(l);return[...r,...c.filter(e=>e.type===o.Search)]},[])]}attachOrphanReferences(){const i=this.getVariableInstances(),r=this.getVariableDeclarations();return i.forEach(l=>{if(!l.declaration){const c=l.initialData,e=c.declaration.entityId||c.declaration.id,y=r.find(v=>v.id===e);y&&l.setDeclaration(y)}}),this}getBuiltInPersistedEntity(){return this.builtInBaseEntities.find(i=>i.name===De.PERSISTED_ENTITY)||null}requestActiveDynamicValue(i,r=!1){var c,e;const l=(e=(c=this.parentContext).requestActiveDynamicValue)==null?void 0:e.call(c,i,r);if(!l&&Uv.includes(i.type)){const y=i.getDefaultValue();return y?{value:y,type:$e.DefaultValue,inheritanceLink:null,valueOwner:i}:null}return l||null}requestExtension(i){if(this.parentContext.requestExtension){const r=this.parentContext.requestExtension(i);if(r&&!r.module)throw new Error(`Module ${i} is not registered properly.`);return r.module||null}return null}undo(){ae.log("Undoing, from: ",this.undoableStackValueIndex),this.undoableStackValueIndex=this.undoableStackValueIndex-1,ae.log("To: ",this.undoableStackValueIndex);const i=this.history[this.undoableStackValueIndex+1],r=this.history[this.undoableStackValueIndex];return ae.log("Current change set: ",i==null?void 0:i.toJSON()),ae.log("Change set to restore: ",r==null?void 0:r.toJSON()),Sw(i||"initial",r||"initial",this)}redo(){ae.log("Undoing, from: ",this.undoableStackValueIndex),this.undoableStackValueIndex=this.undoableStackValueIndex+1,ae.log("To: ",this.undoableStackValueIndex);const i=this.history[this.undoableStackValueIndex-1],r=this.history[this.undoableStackValueIndex];return ae.log("Current change set: ",i==null?void 0:i.toJSON()),ae.log("Change set to restore: ",r.toJSON()),Sw(i||"initial",r||"initial",this)}applyExternalChangeSet(i){const r=i.payload,l=this.addChangeSet(new H(this,i.userAuthor,i.emittedAt,this));l.ignoreNonEditable=!0,l.ignoreNonDeletable=!0;const c=r.updated[this.id];if(!c)throw new Error("Project root not found in change set transfer. Cannot apply changes.");const e={...r.added,...r.updated,...r.removed},y=[...Object.keys(r.added),...Object.keys(r.updated),...Object.keys(r.removed)];y.forEach(b=>{var A;if(!e[b]){ae.warn(`Entity '${b}' not found in change set transfer. Cannot apply changes.`);const E=(A=this.get(b))==null?void 0:A.toShallowJSON();throw E?ae.warn("Entity in project: ",E):ae.warn("Entity not in project"),new Error(`Entity '${b}' not found in change set transfer. Cannot apply changes.`)}});const v=new Ma(c);return v.flatRecord=e,v.order=y,v.orderEntities(),ae.log("All entities: ",v.order.map((b,A)=>`${A+1}: ${e[b].type} - ${b}`).join(`,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elyx-code/project-logic-tree",
3
- "version": "0.0.6643",
3
+ "version": "0.0.6645",
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",