@elyx-code/project-logic-tree 0.0.6687 → 0.0.6689

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -384,7 +384,7 @@ ${Mu}`}))}}}const y=s.parent&&n.get(s.parent)||n.getBuiltIn(s.parent),m=y?ku(y):
384
384
  The entitities of type '${wt(b,"', '","' and '")}' can only have one 'data-type' child under the 'dataType' property so no 'parentRelationType' is needed.`})),y.dataType)){const w=(v=y.dataType)==null?void 0:v.id;c.push(new De({id:`${i.id}--${ne.NewEntityWouldOverriteExisting}`,code:ne.NewEntityWouldOverriteExisting,severity:pe.Error,message:`The entity with id '${i.id}' and type '${i.type}', cannot be added as a child to the entity with id '${s.parent}' and type '${E}', because it already has a 'data-type' child with id '${w}'.
385
385
  The entitities of type '${wt(b,"', '","' 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
  ${go({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.`}))}E===o.DataType&&(!s.parentRelationType||!(s.parentRelationType===qe.AndDataTypeGroup||s.parentRelationType===qe.OrDataTypeGroup))&&c.push(new De({id:`${i.id}--${ne.InvalidParentRelationType}`,code:ne.InvalidParentRelationType,severity:pe.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:s}}get isGroup(){const i=[...this.andChildrenGroup||[],...this.orChildrenGroup||[]];if(i.length>1){let n=0;for(const s of i)if(s.isResolved&&(n++,n>1))return!0}return!1}get isResolved(){return[o.BuiltInBaseEntity,o.ActionDescriptor].includes(this.parent.type)||ku(this.parent)?!0:!(!this.entity&&!this.isGroup&&!this.foreignKeyRef&&!this.foreignKeyAllowed)}validateGeneratedUpdate(i){return{errors:[],modifiedData:i}}subscribeDependents(i){return i.forEach(n=>{this.detachedDependents[n.entity.id]||(this.detachedDependents[n.entity.id]=n)}),this}unsubscribeDependents(i){return i.forEach(n=>{this.detachedDependents[n.entity.id]&&delete this.detachedDependents[n.entity.id]}),this}syncDependents(i=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,"sync-dependents"))){const n=[],s=[],c=[],e=[];return Object.values(this.detachedDependents).forEach(y=>{const m=y.entity.afterAllChildrenInitialized(i);n.push(...m.updated),s.push(...m.added),c.push(...m.removed),e.push(...m.affected)}),i==null||i.attemptAutoclose("sync-dependents",this.id),{updated:D(n),added:D(s),removed:D(c),affected:D(e),self:this}}onDetachedDependencyRemoved(i,n,s){const c=[],e=[],y=[],m=[];return n==="entity-field"&&this.setEntity(null,s),n==="foreign-key-ref-field"&&this.setForeignKeyRef(null,s),{updated:D(c),added:D(e),removed:D(y),affected:D(m),self:this}}onDetachedDependencyRestored(i,n,s){const c=[],e=[],y=[],m=[];return n==="entity-field"&&this.setEntity(i,s),n==="foreign-key-ref-field"&&this.setForeignKeyRef(i,s),{updated:D(c),added:D(e),removed:D(y),affected:D(m),self:this}}unsubscribeFromDependencies(){var i,n,s,c;return(n=(i=this.entity)==null?void 0:i.unsubscribeDependents)==null||n.call(i,[{entity:this,field:"entity-field"}]),(c=(s=this.foreignKeyRef)==null?void 0:s.unsubscribeDependents)==null||c.call(s,[{entity:this,field:"foreign-key-ref-field"}]),this}subscribeToDependencies(){var i,n,s,c;return(n=(i=this.entity)==null?void 0:i.subscribeDependents)==null||n.call(i,[{entity:this,field:"entity-field"}]),(c=(s=this.foreignKeyRef)==null?void 0:s.subscribeDependents)==null||c.call(s,[{entity:this,field:"foreign-key-ref-field"}]),this}increaseVersion(i){if(i&&!M(i).isValid())throw new Error(`The shared timestamp '${i}' is not a valid ISO 8601 date string.`);return i&&M(i).isSame(M(this.createdAt))?this:(this.previousVersion=this.version,this.version=x.UUID.uuid(),this.createdAt=M(i).toISOString()||M().toISOString(),this)}captureVersion(){var n;const i=((n=this.knownVersions)==null?void 0:n.get(this.version))||new Ei(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 n=[],s=[],c=[],e=[];if(this.parent&&this.parent.type!==o.BuiltInBaseEntity){this.parent.increaseVersion(i);const y=this.parent.recursiveCaptureUpstreamVersions(i);n.push(this.parent,...y.updated),s.push(...y.added),c.push(...y.removed)}return{updated:D(n),added:D(s),removed:D(c),affected:D(e),self:this}}async restoreVersion(i){var m;const n=[],s=[],c=[],e=[];if(this.version===i)return{updated:D(n),added:D(s),removed:D(c),affected:D(e),self:this};if(!this.knownVersions){const v=new Map;for(const[E,b]of this.knownVersions||new Map){if(v.set(E,b),b.activeVersion=!1,b.knownVersions)for(const[w,P]of b.knownVersions)v.set(w,P);b.knownVersions=null}}let y=(m=this.knownVersions)==null?void 0:m.get(i);if(!y){const v=await this.APILoadVersion({},i);if(!v)throw new Error(`Version with id '${i}' for entity with id '${this.id}' not found.`);y=new Ei(v,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:D(n),added:D(s),removed:D(c),affected:D(e),self:this}}updateWithShallowTransfer(i,n=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,_.UpdateWithShallowTransfer))){var s,c;if(!this.checkCanEdit(this,n))return J.Logger.warn(`[updateWithShallowTransfer] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),n==null||n.attemptAutoclose(_.UpdateWithShallowTransfer,this.id),this;if(this.metaSync(i,n),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=re(i.parent),y=this.project.get(e),m=this.parent;if(m&&m.id!==(y==null?void 0:y.id)&&this.removeFromParent(n),y)this.setParent(y,n),this.addSelfToProject(n);else throw n==null||n.attemptAutoclose(_.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 n==null||n.attemptAutoclose(_.UpdateWithShallowTransfer,this.id),new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(i.entity){const e=re(i.entity),y=this.project.get(e);y&&(y.type===o.DefinitionEntity&&y.parent===this||this.setEntity(y,n))}else this.setEntity(null,n);if(i.foreignKeyRef){const e=re(i.foreignKeyRef),y=this.project.get(e);y&&this.setForeignKeyRef(y,n)}else this.setForeignKeyRef(null,n);return(s=i.andChildrenGroup)==null||s.forEach(e=>{const y=re(e),m=this.project.get(y);m&&(this.addToAndGroup(m,n),m.setParent(this,n))}),[...this.andChildrenGroup||[]].forEach(e=>{var m;((m=i.andChildrenGroup)==null?void 0:m.find(v=>re(v)===e.id))||(this.removeChildGroup(e,n),e.removeFromParent(n))}),(c=i.orChildrenGroup)==null||c.forEach(e=>{const y=re(e),m=this.project.get(y);m&&(this.addToOrGroup(m,n),m.setParent(this,n))}),[...this.orChildrenGroup||[]].forEach(e=>{var m;((m=i.orChildrenGroup)==null?void 0:m.find(v=>re(v)===e.id))||(this.removeChildGroup(e,n),e.removeFromParent(n))}),this.captureVersion(),this.subscribeToDependencies(),n==null||n.attemptAutoclose(_.UpdateWithShallowTransfer,this.id),this}hydrateAncestors(){const i=[],n=[],s=[],c=[];if(this.initialData.parent){const e=re(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=re(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=re(this.initialData.foreignKeyRef),y=this.project.get(e);y&&this.setForeignKeyRef(y,null)}return{updated:D(i),added:D(n),removed:D(s),affected:D(c),self:this}}afterAllChildrenInitialized(i=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,_.AfterAllChildrenInitialized))){var y,m,v;if(!this.checkCanEdit(this,i))return J.Logger.warn(`[afterAllChildrenInitialized] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(_.AfterAllChildrenInitialized,this.id),{updated:[],added:[],removed:[],affected:[],self:this};const n=[],s=[],c=[],e=[];if(this.initialized=!0,((y=this.parent)==null?void 0:y.type)===o.DataType){let E=this.index||0;const b=(this.parentRelationType===qe.AndDataTypeGroup?this.parent.andChildrenGroup||[]:this.parent.orChildrenGroup||[]).filter(P=>!P.deleted&&P.id!==this.id);b.length&&(E>b.length+1?E=b.length:E<0&&(E=0)),b.find(P=>(P.index||0)===E&&!P.deleted)&&b.filter(P=>(P.index||0)>=E&&!P.deleted).forEach(P=>{P.metaSync({index:(P.index||0)+1},i),i==null||i.add(P,Z.Updated),n.push(P)}),this.metaSync({index:E},i)}return(m=this.andChildrenGroup)!=null&&m.length&&this.andChildrenGroup.sort((E,b)=>(E.index||0)-(b.index||0)),(v=this.orChildrenGroup)!=null&&v.length&&this.orChildrenGroup.sort((E,b)=>(E.index||0)-(b.index||0)),this.captureVersion(),i==null||i.attemptAutoclose(_.AfterAllChildrenInitialized,this.id),{updated:D(n),added:D(s),removed:D(c),affected:D(e),self:this}}addSelfToProject(i=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,"add-self-to-project"))){const n=[this],s=[],c=[],e=[];return this.parent.type===o.DataType?(this.parentRelationType===qe.AndDataTypeGroup?this.parent.addToAndGroup(this,i):this.parentRelationType===qe.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:D(n),added:D(s),removed:D(c),affected:D(e),self:this}}setParent(i,n=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,_.SetParent))){var s;return this.checkCanEditWithCounterpartAndSideEffects(this,i,_.SetParent,n)?(((s=this.parent)==null?void 0:s.id)!==(i==null?void 0:i.id)&&(this.parent=i,n&&(n==null||n.add(this,Z.Updated))),n==null||n.attemptAutoclose(_.SetParent,this.id),this):this}removeChildGroup(i,n=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,_.RemoveChildGroup))){if(!this.checkCanEdit(this,n))return J.Logger.warn(`[removeChildGroup] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),n==null||n.attemptAutoclose(_.RemoveChildGroup,this.id),this;if(this.andChildrenGroup){const s=this.andChildrenGroup.findIndex(c=>c.id===i.id);s!==-1&&(this.andChildrenGroup.splice(s,1),n==null||n.add(this,Z.Updated))}if(this.orChildrenGroup){const s=this.orChildrenGroup.findIndex(c=>c.id===i.id);s!==-1&&(this.orChildrenGroup.splice(s,1),n==null||n.add(this,Z.Updated))}return n==null||n.attemptAutoclose(_.RemoveChildGroup,this.id),this}initChildren(i=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,"init-children"))){var n,s,c,e,y,m,v,E,b,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=ye(this.initialData.entity,this.project),(((s=(n=this.initialData.entity)==null?void 0:n.parent)==null?void 0:s.id)===this.id||((e=(c=this.initialData.entity)==null?void 0:c.parent)==null?void 0:e.type)===o.GenericReference&&((m=(y=this.initialData.entity)==null?void 0:y.parent)==null?void 0:m.entityId)==this.id)&&this.entity.setParent(this,null),(E=(v=this.entity).initChildren)==null||E.call(v,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=ye(this.initialData.foreignKeyRef,this.project),(w=(b=this.foreignKeyRef).initChildren)==null||w.call(b,i);return this.initialData.andChildrenGroup&&(this.andChildrenGroup=this.initialData.andChildrenGroup.map(P=>{const $=ye(P,this.project);return $.setParent(this,null),$.initChildren(i),$})),this.initialData.orChildrenGroup&&(this.orChildrenGroup=this.initialData.orChildrenGroup.map(P=>{const $=ye(P,this.project);return $.setParent(this,null),$.initChildren(i),$})),this.subscribeToDependencies(),this.afterAllChildrenInitialized(i),i==null||i.attemptAutoclose("init-children",this.id),this}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(i,n=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,"meta-sync"))){const s=$r(this,i,n),c=xr(this,s),e=this.toMeta();return this.options=s.options||e.options,this.parentRelationType=s.parentRelationType||e.parentRelationType,this.isList=s.isList!==void 0?s.isList:e.isList,this.inferred=s.inferred!==void 0?s.inferred:e.inferred,this.like=s.like!==void 0?s.like:e.like,this.asType=s.asType!==void 0?s.asType:e.asType,this.index=s.index!==void 0?s.index:e.index,this.implementationChooseOne=s.implementationChooseOne!==void 0?s.implementationChooseOne:e.implementationChooseOne,this.staticEntities=s.staticEntities!==void 0?s.staticEntities:e.staticEntities,this.interactiveEntities=s.interactiveEntities!==void 0?s.interactiveEntities:e.interactiveEntities,this.actionEntities=s.actionEntities!==void 0?s.actionEntities:e.actionEntities,super.baseMetaSync(s,this,n),s.deleted===!0&&!e.deleted?n==null||n.add(this,Z.Removed):s.deleted===!1&&e.deleted?n==null||n.add(this,Z.Added):c&&(n==null||n.add(this,Z.Updated)),n==null||n.attemptAutoclose("meta-sync",this.id),this}async APILoad(i=Ge,...n){return await Ei.repository.APILoad(this.id,...n),this}async APICreate(i=Ge,...n){return await Ei.repository.APICreate(this.toShallowJSON(),...n),this}async APIUpdate(i=Ge,...n){return await Ei.repository.APIUpdate(this.toShallowJSON(),...n),this}async APIDelete(i=Ge,...n){return await Ei.repository.APIDelete(this.toShallowJSON(),...n),this}async APIClone(i=Ge,...n){return await Ei.repository.APIClone(this.id,...n),this}async APILoadVersion(i=Ge,n,...s){return await Ei.repository.APILoadVersion(this.id,n,...s)}removeFromParent(i=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,_.RemoveFromParent))){var y,m;if(!this.checkCanEdit(this,i))return J.Logger.warn(`[removeFromParent] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(_.RemoveFromParent,this.id),{added:[],updated:[],removed:[],affected:[],self:this};const n=[],s=[],c=[],e=[];if(((y=this.parent)==null?void 0:y.type)===o.DataType)this.parent.removeChildGroup(this,i);else if(((m=this.parent)==null?void 0:m.type)===o.DefinitionEntity)this.parent.removeAdditionalPropertiesDataType(i);else{const v=this.parent;v==null||v.removeDataType(i)}return this.parent&&this.parent.type!==o.BuiltInBaseEntity&&n.push(this.parent),i==null||i.attemptAutoclose(_.RemoveFromParent,this.id),{added:D(c),updated:D(n),removed:D(s),affected:D(e),self:this}}remove({ignoreUpstream:i}={ignoreUpstream:!1},n=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,_.RemoveEntity))){const s=[],c=[],e=[],y=[];if(n!=null&&n.hasRemoved(this.id))return n==null||n.attemptAutoclose(_.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},n),Object.values(this.detachedDependents).forEach(m=>{const{updated:v,removed:E,added:b}=m.entity.onDetachedDependencyRemoved(this,m.field,n);s.push(...v),c.push(...E),e.push(...b)}),this.entity&&this.entity.type===o.DefinitionEntity&&this.entity.parent===this){const{updated:m,removed:v}=this.entity.remove({ignoreUpstream:!0},n);s.push(...m),c.push(...v)}if(this.andChildrenGroup&&this.andChildrenGroup.forEach(m=>{const{removed:v,updated:E}=m.remove({ignoreUpstream:!0},n);c.push(...v),s.push(...E)}),this.orChildrenGroup&&this.orChildrenGroup.forEach(m=>{const{removed:v,updated:E}=m.remove({ignoreUpstream:!0},n);c.push(...v),s.push(...E)}),!i){const m=this.removeFromParent(n);e.push(...m.added),s.push(...m.updated),c.push(...m.removed),y.push(...m.affected)}return n==null||n.attemptAutoclose(_.RemoveEntity,this.id),{added:D(e),updated:D(s),removed:D(c),affected:D(y),self:this}}restore({}={},i=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,_.RestoreEntity))){if(!this.checkCanEdit(this,i))return J.Logger.warn(`[restore] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(_.RestoreEntity,this.id),{added:[],updated:[],removed:[],affected:[],self:this};const n=[],s=[],c=[],e=[];if(i!=null&&i.hasAdded(this.id))return i==null||i.attemptAutoclose(_.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:m,removed:v,added:E}=y.entity.onDetachedDependencyRestored(this,y.field,i);s.push(...m),c.push(...v),n.push(...E)}),this.entity&&this.entity.type===o.DefinitionEntity&&this.entity.parent===this){const{updated:y}=this.entity.restore({},i);s.push(...y)}if(this.andChildrenGroup&&this.andChildrenGroup.forEach(y=>{const{updated:m,added:v}=y.restore({},i);s.push(...m),n.push(...v)}),this.orChildrenGroup&&this.orChildrenGroup.forEach(y=>{const{updated:m,added:v}=y.restore({},i);s.push(...m),n.push(...v)}),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===qe.AndDataTypeGroup?Array.isArray(y.andChildrenGroup)&&y.andChildrenGroup.push(this):this.parentRelationType===qe.OrDataTypeGroup&&Array.isArray(y.orChildrenGroup)&&y.orChildrenGroup.push(this)}else if(this.parent.type===o.DefinitionEntity){const y=this.parent;y.setAdditionalPropertiesDataType(this,i),s.push(y)}else{const y=this.parent;y.setDataType(this,i),s.push(y)}return i==null||i.attemptAutoclose(_.RestoreEntity,this.id),{added:D(n),updated:D(s),removed:D(c),affected:D(e),self:this}}toFlat(i=new Set){var s,c,e,y;return i.has(this.id)?[]:(i.add(this.id),[this,...((s=this.andChildrenGroup)==null?void 0:s.flatMap(m=>m.toFlat(i)))||[],...((c=this.orChildrenGroup)==null?void 0:c.flatMap(m=>m.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 s,c,e,y;return i.has(this.id)?[]:(i.add(this.id),[this.id,...((s=this.andChildrenGroup)==null?void 0:s.flatMap(m=>m.toFlatIds(i)))||[],...((c=this.orChildrenGroup)==null?void 0:c.flatMap(m=>m.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 n,s,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:((n=this.foreignKeyRef)==null?void 0:n.toJSON(i))||null,andChildrenGroup:((s=this.andChildrenGroup)==null?void 0:s.map(m=>m.toJSON(i)))||null,orChildrenGroup:((c=this.orChildrenGroup)==null?void 0:c.map(m=>m.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=pt){var s,c,e,y,m,v,E,b,w,P;let n;return(s=i.seenEntityMaps)!=null&&s.has(this.id)?n=i.seenEntityMaps.get(this.id):(n=i.newId||jr(this,this.project,i.uuidStrategy),i.seenEntityMaps&&i.seenEntityMaps.set(this.id,n)),(c=i.seenEntities)!=null&&c.has(n)||(e=i.seenEntities)!=null&&e.has(this.id)?this.toReference({seenEntityMaps:i.seenEntityMaps}):((y=i.seenEntities)==null||y.add(n),(m=i.seenEntities)==null||m.add(this.id),{id:n,version:x.UUID.uuid(),createdAt:i.timestamp||M().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:((v=this.foreignKeyRef)==null?void 0:v.toJSONClone({...i,newId:null}))||null,andChildrenGroup:((E=this.andChildrenGroup)==null?void 0:E.map($=>$.toJSONClone({...i,newId:null})))||null,orChildrenGroup:((b=this.orChildrenGroup)==null?void 0:b.map($=>$.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=pt){var s;let n=this.id;return(s=i.seenEntityMaps)!=null&&s.has(this.id)&&(n=i.seenEntityMaps.get(this.id)),{id:n+"--"+x.UUID.uuid()+"--ref",type:o.GenericReference,entityId:n,version:this.version,entityType:this.type}}toShallowJSON(i=pt){var s,c,e,y,m;let n=this.id;return(s=i.seenEntityMaps)!=null&&s.has(this.id)&&(n=i.seenEntityMaps.get(this.id)),{id:n,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(v=>v.toReference(i)))||null,orChildrenGroup:((y=this.orChildrenGroup)==null?void 0:y.map(v=>v.toReference(i)))||null,entity:((m=this.entity)==null?void 0:m.toReference(i))||null,parent:this.parent.toReference(i)}}toFlatJSON(i=new Set){var s,c,e;return i.has(this.id)?[]:(i.add(this.id),[this.toShallowJSON(),...((s=this.andChildrenGroup)==null?void 0:s.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,n;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:((n=this.entity)==null?void 0:n.id)||null,parent:this.parent.id}}toFlatGenerationTarget(i=new Set){var s,c;return i.has(this.id)?[]:(i.add(this.id),[this.toGenerationTarget(),...((s=this.andChildrenGroup)==null?void 0:s.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,n,s,c;return this.errors=[],(i=this.andChildrenGroup)==null||i.forEach(e=>e.clearErrors()),(n=this.orChildrenGroup)==null||n.forEach(e=>e.clearErrors()),this.inferred&&this.entity&&this.entity.type===o.DefinitionEntity&&((s=this.entity)==null?void 0:s.parent)===this&&((c=this.entity)==null||c.clearErrors()),this}validate(){return this.errors=HUe(this),{success:!0}}async validateAsync(i={}){const n=J.YieldTracker.from(i);return this.errors=await ZUe(this,{tracker:n}),{success:!0}}getErrors(){var n,s;return[...this.errors,...((n=this.andChildrenGroup)==null?void 0:n.flatMap(c=>c.getErrors()))||[],...((s=this.orChildrenGroup)==null?void 0:s.flatMap(c=>c.getErrors()))||[]]}async getErrorsAsync(i={}){const n=J.YieldTracker.from(i),s=[...this.errors];await n.tick();for(const c of this.andChildrenGroup||[]){const e=await c.getErrorsAsync({tracker:n});s.push(...e)}for(const c of this.orChildrenGroup||[]){const e=await c.getErrorsAsync({tracker:n});s.push(...e)}return s}getShallowErrors(){return this.errors}clone(i=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,_.CloneEntity)),n=null,s=null,c=!0){var P,$,L,U;const e=Pr(n,this),y=n||this.parent,v={id:s||x.UUID.uuid(),version:x.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||M().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:((P=this.foreignKeyRef)==null?void 0:P.toReference())||null,andChildrenGroup:null,orChildrenGroup:null,entity:null,parent:y.toReference()},E=Ui(v,e);E.hydrateAncestors(),E.setParent(y,null),c&&(E.subscribe(),E.addSelfToProject(i)),E.initChildren(i),i==null||i.add(E,Z.Added);const b=($=this.andChildrenGroup)==null?void 0:$.map(K=>this.project.diggestedBuiltInBaseEntitiesIds.has(K.id)?e.getBuiltIn(K.id):K.clone(i,E,x.UUID.uuid(),c)),w=(L=this.orChildrenGroup)==null?void 0:L.map(K=>this.project.diggestedBuiltInBaseEntitiesIds.has(K.id)?e.getBuiltIn(K.id):K.clone(i,E,x.UUID.uuid(),c));if(E.andChildrenGroup=b||null,E.orChildrenGroup=w||null,this.entity&&this.entity.type===o.DefinitionEntity&&((U=this.entity)==null?void 0:U.parent)===this)if(this.project.diggestedBuiltInBaseEntitiesIds.has(this.entity.id))E.setEntity(e.getBuiltIn(this.entity.id),i);else{const K=this.entity.clone(i,E,x.UUID.uuid(),c);E.setEntity(K,i)}else if(this.entity){const K=e.get(this.entity.id)||e.getBuiltIn(this.entity.id);E.setEntity(K,i)}return i==null||i.attemptAutoclose(_.CloneEntity,this.id),E}merge(i,n=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,_.MergeDataTypes))){var m,v,E;const s=[],c=[],e=[],y=[];if(!this.checkCanEdit(this,n))return J.Logger.warn(`[${_.MergeDataTypes}] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),n==null||n.attemptAutoclose(_.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},n),n==null||n.add(this,Z.Updated),s.push(this)),this.index!==(i==null?void 0:i.index)&&(this.metaSync({index:i==null?void 0:i.index},n),n==null||n.add(this,Z.Updated),s.push(this)),this.foreignKeyAllowed!==(i==null?void 0:i.foreignKeyAllowed)&&(this.metaSync({foreignKeyAllowed:i==null?void 0:i.foreignKeyAllowed},n),n==null||n.add(this,Z.Updated),s.push(this)),this.isList!==(i==null?void 0:i.isList)&&(this.metaSync({isList:i==null?void 0:i.isList},n),n==null||n.add(this,Z.Updated),s.push(this)),this.like!==(i==null?void 0:i.like)&&(this.metaSync({like:i==null?void 0:i.like},n),n==null||n.add(this,Z.Updated),s.push(this)),((m=i==null?void 0:i.foreignKeyRef)==null?void 0:m.id)!==((v=this.foreignKeyRef)==null?void 0:v.id)&&(this.setForeignKeyRef((i==null?void 0:i.foreignKeyRef)||null,n),n==null||n.add(this,Z.Updated),s.push(this)),i!=null&&i.entity&&(i==null?void 0:i.entity.type)===o.DefinitionEntity&&(i==null?void 0:i.entity).parent===i)if(((E=this.entity)==null?void 0:E.type)===o.DefinitionEntity&&this.entity.parent===this)Km(this.entity,i.entity)||HN(this.entity,i.entity,n);else{const b=i.entity.clone(n,this,x.UUID.uuid(),!0);this.setEntity(b,n),c.push(b)}else i!=null&&i.entity&&(this.setEntity(i==null?void 0:i.entity,n),n==null||n.add(this,Z.Updated),s.push(this));return this.inferred!==(i==null?void 0:i.inferred)&&this.metaSync({inferred:(i==null?void 0:i.inferred)??!1},n),n==null||n.attemptAutoclose(_.MergeDataTypes,this.id),{updated:D(s),added:D(c),removed:D(e),affected:D(y),self:this}}addToAndGroup(i,n=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,_.AddToAndGroup))){return this.checkCanEdit(this,n)?(this.andChildrenGroup||(this.andChildrenGroup=[]),this.andChildrenGroup.includes(i)||(this.andChildrenGroup.push(i),n==null||n.add(i,Z.Affected)),n==null||n.attemptAutoclose(_.AddToAndGroup,this.id),this):(J.Logger.warn(`[${_.AddToAndGroup}] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),n==null||n.attemptAutoclose(_.AddToAndGroup,this.id),this)}addToOrGroup(i,n=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,_.AddToOrGroup))){return this.checkCanEdit(this,n)?(this.orChildrenGroup||(this.orChildrenGroup=[]),this.orChildrenGroup.includes(i)||(this.orChildrenGroup.push(i),n==null||n.add(i,Z.Affected)),n==null||n.attemptAutoclose(_.AddToOrGroup,this.id),this):(J.Logger.warn(`[${_.AddToOrGroup}] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),n==null||n.attemptAutoclose(_.AddToOrGroup,this.id),this)}setForeignKeyRef(i,n=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,_.SetDataTypeForeignKeyRef))){if(!this.checkCanEdit(this,n))return J.Logger.warn(`[${_.SetDataTypeForeignKeyRef}] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),n==null||n.attemptAutoclose(_.SetDataTypeForeignKeyRef,this.id),this;const s=this.foreignKeyRef;return(s==null?void 0:s.id)!==(i==null?void 0:i.id)&&(this.foreignKeyRef=i,n==null||n.add(this,Z.Updated)),n==null||n.attemptAutoclose(_.SetDataTypeForeignKeyRef,this.id),this}setEntity(i,n=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,_.SetDataTypeEntityValue))){var c;if(!this.checkCanEdit(this,n))return J.Logger.warn(`[${_.SetDataTypeEntityValue}] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),n==null||n.attemptAutoclose(_.SetDataTypeEntityValue,this.id),this;const s=this.entity;return(s==null?void 0:s.id)!==(i==null?void 0:i.id)&&(this.entity=i,n==null||n.add(this,Z.Updated),s&&s.type===o.DefinitionEntity&&((c=s.parent)==null?void 0:c.id)===this.id&&(s==null||s.remove({ignoreUpstream:!0},n))),n==null||n.attemptAutoclose(_.SetDataTypeEntityValue,this.id),this}isObject(){return!!this.entity&&(this.entity.type===o.DefinitionEntity||this.entity.type===o.BuiltInBaseEntity||this.entity.name===oe.KeyValue)&&!this.isList}canBeObject(){var n;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 s=(n=this.project.requestActiveDynamicValue(this.parent))==null?void 0:n.value;s?!s.valueAsType&&(s.value===""||s.value===null||aUi(s))&&(i=!0):i=!0}return(this.isObject()||!this.entity||this.entity.name===oe.Untyped)&&i}hasStrictObjectStructure(){var i;return this.isObject()&&((i=this.entity)==null?void 0:i.type)===o.DefinitionEntity}isInlineDeclaredEntity(){var i,n;return((i=this.entity)==null?void 0:i.type)===o.DefinitionEntity&&((n=this.entity.parent)==null?void 0:n.id)===(this==null?void 0:this.id)}isIndependentlyUserDeclaredEntity(){var i,n;return((i=this.entity)==null?void 0:i.type)===o.DefinitionEntity&&((n=this.entity)==null?void 0:n.parent)!==this}canModifyObjectStructure(){var n;const i=this.isIndependentlyUserDeclaredEntity();return(this.isInlineDeclaredEntity()||this.canBeObject()||((n=this.entity)==null?void 0:n.name)===oe.KeyValue)&&!i}inferFromInputs(i,n=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,"infer-data-type-from-inputs"))){var m;const s=[],c=[],e=[],y=[];if(!this.inferred)return n==null||n.attemptAutoclose("infer-data-type-from-inputs",this.id),{updated:[],added:[],removed:[],affected:[],self:this};if(!this.entity&&i.length){const v=le(this.parent,this.project)+" data type definition",E={id:x.UUID.uuid(),deletable:!0,editable:!0,type:o.DefinitionEntity,version:x.UUID.uuid(),createdAt:(n==null?void 0:n.timestamp)||M().toISOString(),author:x.sessionAuthor,previousVersion:null,deleted:!1,name:v,description:((m=this.parent)==null?void 0:m.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()},b=ye(E,this.project);b.hydrateAncestors(),b.setParent(this,n),b.initChildren(n),n==null||n.add(b,Z.Added),b.metaSync(E,n),this.setEntity(b,n),n==null||n.add(this,Z.Updated)}if(this.entity){const{updated:v,added:E,removed:b,affected:w}=this.entity.inferFromInputs(i,n);c.push(...v),s.push(...E),e.push(...b),y.push(...w)}return this.like||this.metaSync({like:!0},n),n==null||n.attemptAutoclose("infer-data-type-from-inputs",this.id),{updated:D(c),added:D(s),removed:D(e),affected:D(y),self:this}}};I(Ei,"repository",{APICreate:async(i,...n)=>i,APIUpdate:async(i,...n)=>i,APIDelete:async(i,...n)=>i,APIClone:async(i,...n)=>{},APILoad:async(i,...n)=>null,APILoadVersion:async(i,n,...s)=>null}),I(Ei,"type",o.DataType),I(Ei,"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]),I(Ei,"PARENT_TYPES",[...Ei.USER_MANAGED_PARENT_TYPES,o.BuiltInBaseEntity]),I(Ei,"MUTABLE_BASE_PROPERTIES",["isList","asType","options","foreignKeyAllowed","parentRelationType","like","implementationChooseOne","staticEntities","interactiveEntities","actionEntities"]),I(Ei,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","index","author","previousVersion"]),I(Ei,"BASE_PROPERTIES",[...Ei.MUTABLE_BASE_PROPERTIES,...Ei.INMUTABLE_BASE_PROPERTIES]),I(Ei,"MUTABLE_META_PROPERTIES",[...Ei.MUTABLE_BASE_PROPERTIES,"inferred"]),I(Ei,"INMUTABLE_META_PROPERTIES",[...Ei.INMUTABLE_BASE_PROPERTIES]),I(Ei,"META_PROPERTIES",[...Ei.MUTABLE_META_PROPERTIES,...Ei.INMUTABLE_META_PROPERTIES]),I(Ei,"MUTABLE_UPSTREAM_PROPERTIES",["entity","foreignKeyRef","parent"]),I(Ei,"INMUTABLE_UPSTREAM_PROPERTIES",[]),I(Ei,"UPSTREAM_PROPERTIES",[...Ei.MUTABLE_UPSTREAM_PROPERTIES,...Ei.INMUTABLE_UPSTREAM_PROPERTIES]),I(Ei,"MUTABLE_DOWNSTREAM_PROPERTIES",[]),I(Ei,"INMUTABLE_DOWNSTREAM_PROPERTIES",["andChildrenGroup","orChildrenGroup"]),I(Ei,"DOWNSTREAM_PROPERTIES",[...Ei.MUTABLE_DOWNSTREAM_PROPERTIES,...Ei.INMUTABLE_DOWNSTREAM_PROPERTIES]),I(Ei,"PROPERTIES",[...Ei.META_PROPERTIES,...Ei.UPSTREAM_PROPERTIES,...Ei.DOWNSTREAM_PROPERTIES]);let tr=Ei;async function WUe(d,p={}){var c;const i=J.YieldTracker.from(p),s=[...d.implements.flatMap(e=>Gx(d,e)),...Ds(d),...kx(d)];return await i.tick(),await((c=d.dataType)==null?void 0:c.validateAsync({tracker:i})),s}function zUe(d){var n;const p=d.implements.flatMap(s=>Gx(d,s));return(n=d.dataType)==null||n.validate(),[...p,...Ds(d),...kx(d)]}function Gx(d,p){const i=[];if(!d.implements)return i;if(!p.abstract){const s=$t({id:`${d.id}--${he.PropertyImplementsNonAbstact}`,message:`Property "${le(d,d.project)}" with id "${d.id}" implements a non-abstract property "${le(p,d.project)}" with id "${p.id}".`,severity:pe.Error,code:he.PropertyImplementsNonAbstact,entity:d});i.push(s.error)}if(d.static&&!p.static){const s=$t({id:`${d.id}--${he.NonStaticPropertyImplementsStatic}`,message:`Static property "${le(d,d.project)}" with id "${d.id}" implements a non-static property "${le(p,d.project)}" with id "${p.id}".`,severity:pe.Error,code:he.NonStaticPropertyImplementsStatic,entity:d});i.push(s.error)}if(!d.static&&p.static){const s=$t({id:`${d.id}--${he.StaticPropertyImplementsNonStatic}`,message:`Non-static property "${le(d,d.project)}" with id "${d.id}" implements a static property "${le(p,d.project)}" with id "${p.id}".`,severity:pe.Error,code:he.StaticPropertyImplementsNonStatic,entity:d});i.push(s.error)}if(!zr(d.dataType,p.dataType)){const s=$t({id:`${d.id}--${he.PropertyImplementsIncompatibleType}`,message:`Property "${le(d,d.project)}" with id "${d.id}" implements a property "${le(p,d.project)}" with id "${p.id}" that has an incompatible data type.`,severity:pe.Error,code:he.PropertyImplementsIncompatibleType,entity:d});i.push(s.error)}return Lt(d.errors,i)}function kx(d,p){const n=[...d.parent.allProperties].filter(s=>{var c;return s.id!==d.id&&!d.implements.find(e=>e.id===s.id)&&s.id!==((c=d.extends)==null?void 0:c.id)});return xv(d,[Ji],n,p)}const sUi=Object.freeze(Object.defineProperty({__proto__:null,validate:zUe,validateAsync:WUe,validateImplementation:Gx,validatePropertyEntityName:kx},Symbol.toStringTag,{value:"Module"}));function lUi(d,p){const i=[];if(d.parent){const s=p.get(d.parent);if(!s)i.push(new De({id:`${d.id}--${d.parent}--${ne.ReferencedEntityNotFound}`,code:ne.ReferencedEntityNotFound,severity:pe.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=ku(s);if(c){const e=s!==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}' (${le(c,s.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 De({id:`${d.id}--${ne.InvalidBuiltInEntityReference}`,code:ne.InvalidBuiltInEntityReference,severity:pe.Error,message:e}))}else if(![o.DefinitionEntity].includes(s.type))i.push(new De({id:`${d.id}--${d.parent}--${ne.InvalidParentReference}`,code:ne.InvalidParentReference,severity:pe.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=Zn(s).filter(m=>!m.interactive);if(y.length){let m=y.length>1?`The entity of type '${d.type}' with id '${d.id}' can't be added to the 'parent' entity with id '${s.id}' because it extends or implements multiple '${o.BuiltInBaseEntity}' entities that are non-interactive ("${wt(y.map(v=>le(v,v.project)),'", "','" and "')}").`:`The entity of type '${d.type}' with id '${d.id}' can't be added to the 'parent' entity with id '${s.id}' because it extends or implements a '${o.BuiltInBaseEntity}' entity that is non-interactive ("${le(y[0],y[0].project)}").`;m+=`
387
+ Alternatively you can update the entity with 'update' action. Or replace it by first removing it and then creating a new one.`}))}E===o.DataType&&(!s.parentRelationType||!(s.parentRelationType===qe.AndDataTypeGroup||s.parentRelationType===qe.OrDataTypeGroup))&&c.push(new De({id:`${i.id}--${ne.InvalidParentRelationType}`,code:ne.InvalidParentRelationType,severity:pe.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:s}}get isGroup(){const i=[...this.andChildrenGroup||[],...this.orChildrenGroup||[]];if(i.length>1){let n=0;for(const s of i)if(s.isResolved&&(n++,n>1))return!0}return!1}get isResolved(){return[o.BuiltInBaseEntity,o.ActionDescriptor].includes(this.parent.type)||ku(this.parent)?!0:!(!this.entity&&!this.isGroup&&!this.foreignKeyRef&&!this.foreignKeyAllowed)}validateGeneratedUpdate(i){return{errors:[],modifiedData:i}}subscribeDependents(i){return i.forEach(n=>{this.detachedDependents[n.entity.id]||(this.detachedDependents[n.entity.id]=n)}),this}unsubscribeDependents(i){return i.forEach(n=>{this.detachedDependents[n.entity.id]&&delete this.detachedDependents[n.entity.id]}),this}syncDependents(i=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,"sync-dependents"))){const n=[],s=[],c=[],e=[];return Object.values(this.detachedDependents).forEach(y=>{const m=y.entity.afterAllChildrenInitialized(i);n.push(...m.updated),s.push(...m.added),c.push(...m.removed),e.push(...m.affected)}),i==null||i.attemptAutoclose("sync-dependents",this.id),{updated:D(n),added:D(s),removed:D(c),affected:D(e),self:this}}onDetachedDependencyRemoved(i,n,s){const c=[],e=[],y=[],m=[];return n==="entity-field"&&this.setEntity(null,s),n==="foreign-key-ref-field"&&this.setForeignKeyRef(null,s),{updated:D(c),added:D(e),removed:D(y),affected:D(m),self:this}}onDetachedDependencyRestored(i,n,s){const c=[],e=[],y=[],m=[];return n==="entity-field"&&this.setEntity(i,s),n==="foreign-key-ref-field"&&this.setForeignKeyRef(i,s),{updated:D(c),added:D(e),removed:D(y),affected:D(m),self:this}}unsubscribeFromDependencies(){var i,n,s,c;return(n=(i=this.entity)==null?void 0:i.unsubscribeDependents)==null||n.call(i,[{entity:this,field:"entity-field"}]),(c=(s=this.foreignKeyRef)==null?void 0:s.unsubscribeDependents)==null||c.call(s,[{entity:this,field:"foreign-key-ref-field"}]),this}subscribeToDependencies(){var i,n,s,c;return(n=(i=this.entity)==null?void 0:i.subscribeDependents)==null||n.call(i,[{entity:this,field:"entity-field"}]),(c=(s=this.foreignKeyRef)==null?void 0:s.subscribeDependents)==null||c.call(s,[{entity:this,field:"foreign-key-ref-field"}]),this}increaseVersion(i){if(i&&!M(i).isValid())throw new Error(`The shared timestamp '${i}' is not a valid ISO 8601 date string.`);return i&&M(i).isSame(M(this.createdAt))?this:(this.previousVersion=this.version,this.version=x.UUID.uuid(),this.createdAt=M(i).toISOString()||M().toISOString(),this)}captureVersion(){var n;const i=((n=this.knownVersions)==null?void 0:n.get(this.version))||new Ei(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 n=[],s=[],c=[],e=[];if(this.parent&&this.parent.type!==o.BuiltInBaseEntity){this.parent.increaseVersion(i);const y=this.parent.recursiveCaptureUpstreamVersions(i);n.push(this.parent,...y.updated),s.push(...y.added),c.push(...y.removed)}return{updated:D(n),added:D(s),removed:D(c),affected:D(e),self:this}}async restoreVersion(i){var m;const n=[],s=[],c=[],e=[];if(this.version===i)return{updated:D(n),added:D(s),removed:D(c),affected:D(e),self:this};if(!this.knownVersions){const v=new Map;for(const[E,b]of this.knownVersions||new Map){if(v.set(E,b),b.activeVersion=!1,b.knownVersions)for(const[w,P]of b.knownVersions)v.set(w,P);b.knownVersions=null}}let y=(m=this.knownVersions)==null?void 0:m.get(i);if(!y){const v=await this.APILoadVersion({},i);if(!v)throw new Error(`Version with id '${i}' for entity with id '${this.id}' not found.`);y=new Ei(v,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:D(n),added:D(s),removed:D(c),affected:D(e),self:this}}updateWithShallowTransfer(i,n=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,_.UpdateWithShallowTransfer))){var s,c;if(!this.checkCanEdit(this,n))return J.Logger.warn(`[updateWithShallowTransfer] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),n==null||n.attemptAutoclose(_.UpdateWithShallowTransfer,this.id),this;if(this.metaSync(i,n),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=re(i.parent),y=this.project.get(e),m=this.parent;if(m&&m.id!==(y==null?void 0:y.id)&&this.removeFromParent(n),y)this.setParent(y,n),this.addSelfToProject(n);else throw n==null||n.attemptAutoclose(_.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 n==null||n.attemptAutoclose(_.UpdateWithShallowTransfer,this.id),new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(i.entity){const e=re(i.entity),y=this.project.get(e);y&&(y.type===o.DefinitionEntity&&y.parent===this||this.setEntity(y,n))}else this.setEntity(null,n);if(i.foreignKeyRef){const e=re(i.foreignKeyRef),y=this.project.get(e);y&&this.setForeignKeyRef(y,n)}else this.setForeignKeyRef(null,n);return(s=i.andChildrenGroup)==null||s.forEach(e=>{const y=re(e),m=this.project.get(y);m&&(this.addToAndGroup(m,n),m.setParent(this,n))}),[...this.andChildrenGroup||[]].forEach(e=>{var m;((m=i.andChildrenGroup)==null?void 0:m.find(v=>re(v)===e.id))||(this.removeChildGroup(e,n),e.removeFromParent(n))}),(c=i.orChildrenGroup)==null||c.forEach(e=>{const y=re(e),m=this.project.get(y);m&&(this.addToOrGroup(m,n),m.setParent(this,n))}),[...this.orChildrenGroup||[]].forEach(e=>{var m;((m=i.orChildrenGroup)==null?void 0:m.find(v=>re(v)===e.id))||(this.removeChildGroup(e,n),e.removeFromParent(n))}),this.captureVersion(),this.subscribeToDependencies(),n==null||n.attemptAutoclose(_.UpdateWithShallowTransfer,this.id),this}hydrateAncestors(){const i=[],n=[],s=[],c=[];if(this.initialData.parent){const e=re(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=re(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=re(this.initialData.foreignKeyRef),y=this.project.get(e);y&&this.setForeignKeyRef(y,null)}return{updated:D(i),added:D(n),removed:D(s),affected:D(c),self:this}}afterAllChildrenInitialized(i=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,_.AfterAllChildrenInitialized))){var y,m,v;if(!this.checkCanEdit(this,i))return J.Logger.warn(`[afterAllChildrenInitialized] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(_.AfterAllChildrenInitialized,this.id),{updated:[],added:[],removed:[],affected:[],self:this};const n=[],s=[],c=[],e=[];if(this.initialized=!0,((y=this.parent)==null?void 0:y.type)===o.DataType){let E=this.index||0;const b=(this.parentRelationType===qe.AndDataTypeGroup?this.parent.andChildrenGroup||[]:this.parent.orChildrenGroup||[]).filter(P=>!P.deleted&&P.id!==this.id);b.length&&(E>b.length+1?E=b.length:E<0&&(E=0)),b.find(P=>(P.index||0)===E&&!P.deleted)&&b.filter(P=>(P.index||0)>=E&&!P.deleted).forEach(P=>{P.metaSync({index:(P.index||0)+1},i),i==null||i.add(P,Z.Updated),n.push(P)}),this.metaSync({index:E},i)}return(m=this.andChildrenGroup)!=null&&m.length&&this.andChildrenGroup.sort((E,b)=>(E.index||0)-(b.index||0)),(v=this.orChildrenGroup)!=null&&v.length&&this.orChildrenGroup.sort((E,b)=>(E.index||0)-(b.index||0)),this.captureVersion(),i==null||i.attemptAutoclose(_.AfterAllChildrenInitialized,this.id),{updated:D(n),added:D(s),removed:D(c),affected:D(e),self:this}}addSelfToProject(i=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,"add-self-to-project"))){const n=[this],s=[],c=[],e=[];return this.parent.type===o.DataType?(this.parentRelationType===qe.AndDataTypeGroup?this.parent.addToAndGroup(this,i):this.parentRelationType===qe.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:D(n),added:D(s),removed:D(c),affected:D(e),self:this}}setParent(i,n=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,_.SetParent))){var s;return this.checkCanEditWithCounterpartAndSideEffects(this,i,_.SetParent,n)?(((s=this.parent)==null?void 0:s.id)!==(i==null?void 0:i.id)&&(this.parent=i,n&&(n==null||n.add(this,Z.Updated))),n==null||n.attemptAutoclose(_.SetParent,this.id),this):this}removeChildGroup(i,n=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,_.RemoveChildGroup))){if(!this.checkCanEdit(this,n))return J.Logger.warn(`[removeChildGroup] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),n==null||n.attemptAutoclose(_.RemoveChildGroup,this.id),this;if(this.andChildrenGroup){const s=this.andChildrenGroup.findIndex(c=>c.id===i.id);s!==-1&&(this.andChildrenGroup.splice(s,1),n==null||n.add(this,Z.Updated))}if(this.orChildrenGroup){const s=this.orChildrenGroup.findIndex(c=>c.id===i.id);s!==-1&&(this.orChildrenGroup.splice(s,1),n==null||n.add(this,Z.Updated))}return n==null||n.attemptAutoclose(_.RemoveChildGroup,this.id),this}initChildren(i=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,"init-children"))){var n,s,c,e,y,m,v,E,b,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=ye(this.initialData.entity,this.project),(((s=(n=this.initialData.entity)==null?void 0:n.parent)==null?void 0:s.id)===this.id||((e=(c=this.initialData.entity)==null?void 0:c.parent)==null?void 0:e.type)===o.GenericReference&&((m=(y=this.initialData.entity)==null?void 0:y.parent)==null?void 0:m.entityId)==this.id)&&this.entity.setParent(this,null),(E=(v=this.entity).initChildren)==null||E.call(v,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=ye(this.initialData.foreignKeyRef,this.project),(w=(b=this.foreignKeyRef).initChildren)==null||w.call(b,i);return this.initialData.andChildrenGroup&&(this.andChildrenGroup=this.initialData.andChildrenGroup.map(P=>{const $=ye(P,this.project);return $.setParent(this,null),$.initChildren(i),$})),this.initialData.orChildrenGroup&&(this.orChildrenGroup=this.initialData.orChildrenGroup.map(P=>{const $=ye(P,this.project);return $.setParent(this,null),$.initChildren(i),$})),this.subscribeToDependencies(),this.afterAllChildrenInitialized(i),i==null||i.attemptAutoclose("init-children",this.id),this}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(i,n=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,"meta-sync"))){const s=$r(this,i,n),c=xr(this,s),e=this.toMeta();return this.options=s.options||e.options,this.parentRelationType=s.parentRelationType||e.parentRelationType,this.isList=s.isList!==void 0?s.isList:e.isList,this.inferred=s.inferred!==void 0?s.inferred:e.inferred,this.like=s.like!==void 0?s.like:e.like,this.asType=s.asType!==void 0?s.asType:e.asType,this.index=s.index!==void 0?s.index:e.index,this.implementationChooseOne=s.implementationChooseOne!==void 0?s.implementationChooseOne:e.implementationChooseOne,this.staticEntities=s.staticEntities!==void 0?s.staticEntities:e.staticEntities,this.interactiveEntities=s.interactiveEntities!==void 0?s.interactiveEntities:e.interactiveEntities,this.actionEntities=s.actionEntities!==void 0?s.actionEntities:e.actionEntities,super.baseMetaSync(s,this,n),s.deleted===!0&&!e.deleted?n==null||n.add(this,Z.Removed):s.deleted===!1&&e.deleted?n==null||n.add(this,Z.Added):c&&(n==null||n.add(this,Z.Updated)),n==null||n.attemptAutoclose("meta-sync",this.id),this}async APILoad(i=Ge,...n){return await Ei.repository.APILoad(this.id,...n),this}async APICreate(i=Ge,...n){return await Ei.repository.APICreate(this.toShallowJSON(),...n),this}async APIUpdate(i=Ge,...n){return await Ei.repository.APIUpdate(this.toShallowJSON(),...n),this}async APIDelete(i=Ge,...n){return await Ei.repository.APIDelete(this.toShallowJSON(),...n),this}async APIClone(i=Ge,...n){return await Ei.repository.APIClone(this.id,...n),this}async APILoadVersion(i=Ge,n,...s){return await Ei.repository.APILoadVersion(this.id,n,...s)}removeFromParent(i=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,_.RemoveFromParent))){var y,m;if(!this.checkCanEdit(this,i))return J.Logger.warn(`[removeFromParent] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(_.RemoveFromParent,this.id),{added:[],updated:[],removed:[],affected:[],self:this};const n=[],s=[],c=[],e=[];if(((y=this.parent)==null?void 0:y.type)===o.DataType)this.parent.removeChildGroup(this,i);else if(((m=this.parent)==null?void 0:m.type)===o.DefinitionEntity)this.parent.removeAdditionalPropertiesDataType(i);else{const v=this.parent;v==null||v.removeDataType(i)}return this.parent&&this.parent.type!==o.BuiltInBaseEntity&&n.push(this.parent),i==null||i.attemptAutoclose(_.RemoveFromParent,this.id),{added:D(c),updated:D(n),removed:D(s),affected:D(e),self:this}}remove({ignoreUpstream:i}={ignoreUpstream:!1},n=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,_.RemoveEntity))){const s=[],c=[],e=[],y=[];if(n!=null&&n.hasRemoved(this.id))return n==null||n.attemptAutoclose(_.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},n),Object.values(this.detachedDependents).forEach(m=>{const{updated:v,removed:E,added:b}=m.entity.onDetachedDependencyRemoved(this,m.field,n);s.push(...v),c.push(...E),e.push(...b)}),this.entity&&this.entity.type===o.DefinitionEntity&&this.entity.parent===this){const{updated:m,removed:v}=this.entity.remove({ignoreUpstream:!0},n);s.push(...m),c.push(...v)}if(this.andChildrenGroup&&this.andChildrenGroup.forEach(m=>{const{removed:v,updated:E}=m.remove({ignoreUpstream:!0},n);c.push(...v),s.push(...E)}),this.orChildrenGroup&&this.orChildrenGroup.forEach(m=>{const{removed:v,updated:E}=m.remove({ignoreUpstream:!0},n);c.push(...v),s.push(...E)}),!i){const m=this.removeFromParent(n);e.push(...m.added),s.push(...m.updated),c.push(...m.removed),y.push(...m.affected)}return n==null||n.attemptAutoclose(_.RemoveEntity,this.id),{added:D(e),updated:D(s),removed:D(c),affected:D(y),self:this}}restore({}={},i=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,_.RestoreEntity))){if(!this.checkCanEdit(this,i))return J.Logger.warn(`[restore] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(_.RestoreEntity,this.id),{added:[],updated:[],removed:[],affected:[],self:this};const n=[],s=[],c=[],e=[];if(i!=null&&i.hasAdded(this.id))return i==null||i.attemptAutoclose(_.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:m,removed:v,added:E}=y.entity.onDetachedDependencyRestored(this,y.field,i);s.push(...m),c.push(...v),n.push(...E)}),this.entity&&this.entity.type===o.DefinitionEntity&&this.entity.parent===this){const{updated:y}=this.entity.restore({},i);s.push(...y)}if(this.andChildrenGroup&&this.andChildrenGroup.forEach(y=>{const{updated:m,added:v}=y.restore({},i);s.push(...m),n.push(...v)}),this.orChildrenGroup&&this.orChildrenGroup.forEach(y=>{const{updated:m,added:v}=y.restore({},i);s.push(...m),n.push(...v)}),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===qe.AndDataTypeGroup?Array.isArray(y.andChildrenGroup)&&y.andChildrenGroup.push(this):this.parentRelationType===qe.OrDataTypeGroup&&Array.isArray(y.orChildrenGroup)&&y.orChildrenGroup.push(this)}else if(this.parent.type===o.DefinitionEntity){const y=this.parent;y.setAdditionalPropertiesDataType(this,i),s.push(y)}else{const y=this.parent;y.setDataType(this,i),s.push(y)}return i==null||i.attemptAutoclose(_.RestoreEntity,this.id),{added:D(n),updated:D(s),removed:D(c),affected:D(e),self:this}}toFlat(i=new Set){var s,c,e,y;return i.has(this.id)?[]:(i.add(this.id),[this,...((s=this.andChildrenGroup)==null?void 0:s.flatMap(m=>m.toFlat(i)))||[],...((c=this.orChildrenGroup)==null?void 0:c.flatMap(m=>m.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 s,c,e,y;return i.has(this.id)?[]:(i.add(this.id),[this.id,...((s=this.andChildrenGroup)==null?void 0:s.flatMap(m=>m.toFlatIds(i)))||[],...((c=this.orChildrenGroup)==null?void 0:c.flatMap(m=>m.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 n,s,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:((n=this.foreignKeyRef)==null?void 0:n.toJSON(i))||null,andChildrenGroup:((s=this.andChildrenGroup)==null?void 0:s.map(m=>m.toJSON(i)))||null,orChildrenGroup:((c=this.orChildrenGroup)==null?void 0:c.map(m=>m.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=pt){var s,c,e,y,m,v,E,b,w,P;let n;return(s=i.seenEntityMaps)!=null&&s.has(this.id)?n=i.seenEntityMaps.get(this.id):(n=i.newId||jr(this,this.project,i.uuidStrategy),i.seenEntityMaps&&i.seenEntityMaps.set(this.id,n)),(c=i.seenEntities)!=null&&c.has(n)||(e=i.seenEntities)!=null&&e.has(this.id)?this.toReference({seenEntityMaps:i.seenEntityMaps}):((y=i.seenEntities)==null||y.add(n),(m=i.seenEntities)==null||m.add(this.id),{id:n,version:x.UUID.uuid(),createdAt:i.timestamp||M().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:((v=this.foreignKeyRef)==null?void 0:v.toJSONClone({...i,newId:null}))||null,andChildrenGroup:((E=this.andChildrenGroup)==null?void 0:E.map($=>$.toJSONClone({...i,newId:null})))||null,orChildrenGroup:((b=this.orChildrenGroup)==null?void 0:b.map($=>$.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=pt){var s;let n=this.id;return(s=i.seenEntityMaps)!=null&&s.has(this.id)&&(n=i.seenEntityMaps.get(this.id)),{id:n+"--"+x.UUID.uuid()+"--ref",type:o.GenericReference,entityId:n,version:this.version,entityType:this.type}}toShallowJSON(i=pt){var s,c,e,y,m;let n=this.id;return(s=i.seenEntityMaps)!=null&&s.has(this.id)&&(n=i.seenEntityMaps.get(this.id)),{id:n,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(v=>v.toReference(i)))||null,orChildrenGroup:((y=this.orChildrenGroup)==null?void 0:y.map(v=>v.toReference(i)))||null,entity:((m=this.entity)==null?void 0:m.toReference(i))||null,parent:this.parent.toReference(i)}}toFlatJSON(i=new Set){var s,c,e;return i.has(this.id)?[]:(i.add(this.id),[this.toShallowJSON(),...((s=this.andChildrenGroup)==null?void 0:s.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,n;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:((n=this.entity)==null?void 0:n.id)||null,parent:this.parent.id}}toFlatGenerationTarget(i=new Set){var s,c;return i.has(this.id)?[]:(i.add(this.id),[this.toGenerationTarget(),...((s=this.andChildrenGroup)==null?void 0:s.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,n,s,c;return this.errors=[],(i=this.andChildrenGroup)==null||i.forEach(e=>e.clearErrors()),(n=this.orChildrenGroup)==null||n.forEach(e=>e.clearErrors()),this.inferred&&this.entity&&this.entity.type===o.DefinitionEntity&&((s=this.entity)==null?void 0:s.parent)===this&&((c=this.entity)==null||c.clearErrors()),this}validate(){return this.errors=HUe(this),{success:!0}}async validateAsync(i={}){const n=J.YieldTracker.from(i);return this.errors=await ZUe(this,{tracker:n}),{success:!0}}getErrors(){var n,s;return[...this.errors,...((n=this.andChildrenGroup)==null?void 0:n.flatMap(c=>c.getErrors()))||[],...((s=this.orChildrenGroup)==null?void 0:s.flatMap(c=>c.getErrors()))||[]]}async getErrorsAsync(i={}){const n=J.YieldTracker.from(i),s=[...this.errors];await n.tick();for(const c of this.andChildrenGroup||[]){const e=await c.getErrorsAsync({tracker:n});s.push(...e)}for(const c of this.orChildrenGroup||[]){const e=await c.getErrorsAsync({tracker:n});s.push(...e)}return s}getShallowErrors(){return this.errors}clone(i=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,_.CloneEntity)),n=null,s=null,c=!0){var P,$,L,U;const e=Pr(n,this),y=n||this.parent,v={id:s||x.UUID.uuid(),version:x.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||M().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:((P=this.foreignKeyRef)==null?void 0:P.toReference())||null,andChildrenGroup:null,orChildrenGroup:null,entity:null,parent:y.toReference()},E=Ui(v,e);E.hydrateAncestors(),E.setParent(y,null),c&&(E.subscribe(),E.addSelfToProject(i)),E.initChildren(i),i==null||i.add(E,Z.Added);const b=($=this.andChildrenGroup)==null?void 0:$.map(K=>this.project.diggestedBuiltInBaseEntitiesIds.has(K.id)?e.getBuiltIn(K.id):K.clone(i,E,x.UUID.uuid(),c)),w=(L=this.orChildrenGroup)==null?void 0:L.map(K=>this.project.diggestedBuiltInBaseEntitiesIds.has(K.id)?e.getBuiltIn(K.id):K.clone(i,E,x.UUID.uuid(),c));if(E.andChildrenGroup=b||null,E.orChildrenGroup=w||null,this.entity&&this.entity.type===o.DefinitionEntity&&((U=this.entity)==null?void 0:U.parent)===this)if(this.project.diggestedBuiltInBaseEntitiesIds.has(this.entity.id))E.setEntity(e.getBuiltIn(this.entity.id),i);else{const K=this.entity.clone(i,E,x.UUID.uuid(),c);E.setEntity(K,i)}else if(this.entity){const K=e.get(this.entity.id)||e.getBuiltIn(this.entity.id);E.setEntity(K,i)}return i==null||i.attemptAutoclose(_.CloneEntity,this.id),E}merge(i,n=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,_.MergeDataTypes))){var m,v,E;const s=[],c=[],e=[],y=[];if(!this.checkCanEdit(this,n))return J.Logger.warn(`[${_.MergeDataTypes}] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),n==null||n.attemptAutoclose(_.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},n),n==null||n.add(this,Z.Updated),s.push(this)),this.index!==(i==null?void 0:i.index)&&(this.metaSync({index:i==null?void 0:i.index},n),n==null||n.add(this,Z.Updated),s.push(this)),this.options!==(i==null?void 0:i.options)&&(this.metaSync({options:i==null?void 0:i.options},n),n==null||n.add(this,Z.Updated),s.push(this)),this.foreignKeyAllowed!==(i==null?void 0:i.foreignKeyAllowed)&&(this.metaSync({foreignKeyAllowed:i==null?void 0:i.foreignKeyAllowed},n),n==null||n.add(this,Z.Updated),s.push(this)),this.isList!==(i==null?void 0:i.isList)&&(this.metaSync({isList:i==null?void 0:i.isList},n),n==null||n.add(this,Z.Updated),s.push(this)),this.like!==(i==null?void 0:i.like)&&(this.metaSync({like:i==null?void 0:i.like},n),n==null||n.add(this,Z.Updated),s.push(this)),((m=i==null?void 0:i.foreignKeyRef)==null?void 0:m.id)!==((v=this.foreignKeyRef)==null?void 0:v.id)&&(this.setForeignKeyRef((i==null?void 0:i.foreignKeyRef)||null,n),n==null||n.add(this,Z.Updated),s.push(this)),i!=null&&i.entity&&(i==null?void 0:i.entity.type)===o.DefinitionEntity&&(i==null?void 0:i.entity).parent===i)if(((E=this.entity)==null?void 0:E.type)===o.DefinitionEntity&&this.entity.parent===this)Km(this.entity,i.entity)||HN(this.entity,i.entity,n);else{const b=i.entity.clone(n,this,x.UUID.uuid(),!0);this.setEntity(b,n),c.push(b)}else i!=null&&i.entity&&(this.setEntity(i==null?void 0:i.entity,n),n==null||n.add(this,Z.Updated),s.push(this));return this.inferred!==(i==null?void 0:i.inferred)&&this.metaSync({inferred:(i==null?void 0:i.inferred)??!1},n),n==null||n.attemptAutoclose(_.MergeDataTypes,this.id),{updated:D(s),added:D(c),removed:D(e),affected:D(y),self:this}}addToAndGroup(i,n=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,_.AddToAndGroup))){return this.checkCanEdit(this,n)?(this.andChildrenGroup||(this.andChildrenGroup=[]),this.andChildrenGroup.includes(i)||(this.andChildrenGroup.push(i),n==null||n.add(i,Z.Affected)),n==null||n.attemptAutoclose(_.AddToAndGroup,this.id),this):(J.Logger.warn(`[${_.AddToAndGroup}] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),n==null||n.attemptAutoclose(_.AddToAndGroup,this.id),this)}addToOrGroup(i,n=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,_.AddToOrGroup))){return this.checkCanEdit(this,n)?(this.orChildrenGroup||(this.orChildrenGroup=[]),this.orChildrenGroup.includes(i)||(this.orChildrenGroup.push(i),n==null||n.add(i,Z.Affected)),n==null||n.attemptAutoclose(_.AddToOrGroup,this.id),this):(J.Logger.warn(`[${_.AddToOrGroup}] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),n==null||n.attemptAutoclose(_.AddToOrGroup,this.id),this)}setForeignKeyRef(i,n=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,_.SetDataTypeForeignKeyRef))){if(!this.checkCanEdit(this,n))return J.Logger.warn(`[${_.SetDataTypeForeignKeyRef}] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),n==null||n.attemptAutoclose(_.SetDataTypeForeignKeyRef,this.id),this;const s=this.foreignKeyRef;return(s==null?void 0:s.id)!==(i==null?void 0:i.id)&&(this.foreignKeyRef=i,n==null||n.add(this,Z.Updated)),n==null||n.attemptAutoclose(_.SetDataTypeForeignKeyRef,this.id),this}setEntity(i,n=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,_.SetDataTypeEntityValue))){var c;if(!this.checkCanEdit(this,n))return J.Logger.warn(`[${_.SetDataTypeEntityValue}] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),n==null||n.attemptAutoclose(_.SetDataTypeEntityValue,this.id),this;const s=this.entity;return(s==null?void 0:s.id)!==(i==null?void 0:i.id)&&(this.entity=i,n==null||n.add(this,Z.Updated),s&&s.type===o.DefinitionEntity&&((c=s.parent)==null?void 0:c.id)===this.id&&(s==null||s.remove({ignoreUpstream:!0},n))),n==null||n.attemptAutoclose(_.SetDataTypeEntityValue,this.id),this}isObject(){return!!this.entity&&(this.entity.type===o.DefinitionEntity||this.entity.type===o.BuiltInBaseEntity||this.entity.name===oe.KeyValue)&&!this.isList}canBeObject(){var n;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 s=(n=this.project.requestActiveDynamicValue(this.parent))==null?void 0:n.value;s?!s.valueAsType&&(s.value===""||s.value===null||aUi(s))&&(i=!0):i=!0}return(this.isObject()||!this.entity||this.entity.name===oe.Untyped)&&i}hasStrictObjectStructure(){var i;return this.isObject()&&((i=this.entity)==null?void 0:i.type)===o.DefinitionEntity}isInlineDeclaredEntity(){var i,n;return((i=this.entity)==null?void 0:i.type)===o.DefinitionEntity&&((n=this.entity.parent)==null?void 0:n.id)===(this==null?void 0:this.id)}isIndependentlyUserDeclaredEntity(){var i,n;return((i=this.entity)==null?void 0:i.type)===o.DefinitionEntity&&((n=this.entity)==null?void 0:n.parent)!==this}canModifyObjectStructure(){var n;const i=this.isIndependentlyUserDeclaredEntity();return(this.isInlineDeclaredEntity()||this.canBeObject()||((n=this.entity)==null?void 0:n.name)===oe.KeyValue)&&!i}inferFromInputs(i,n=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,"infer-data-type-from-inputs"))){var m;const s=[],c=[],e=[],y=[];if(!this.inferred)return n==null||n.attemptAutoclose("infer-data-type-from-inputs",this.id),{updated:[],added:[],removed:[],affected:[],self:this};if(!this.entity&&i.length){const v=le(this.parent,this.project)+" data type definition",E={id:x.UUID.uuid(),deletable:!0,editable:!0,type:o.DefinitionEntity,version:x.UUID.uuid(),createdAt:(n==null?void 0:n.timestamp)||M().toISOString(),author:x.sessionAuthor,previousVersion:null,deleted:!1,name:v,description:((m=this.parent)==null?void 0:m.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()},b=ye(E,this.project);b.hydrateAncestors(),b.setParent(this,n),b.initChildren(n),n==null||n.add(b,Z.Added),b.metaSync(E,n),this.setEntity(b,n),n==null||n.add(this,Z.Updated)}if(this.entity){const{updated:v,added:E,removed:b,affected:w}=this.entity.inferFromInputs(i,n);c.push(...v),s.push(...E),e.push(...b),y.push(...w)}return this.like||this.metaSync({like:!0},n),n==null||n.attemptAutoclose("infer-data-type-from-inputs",this.id),{updated:D(c),added:D(s),removed:D(e),affected:D(y),self:this}}};I(Ei,"repository",{APICreate:async(i,...n)=>i,APIUpdate:async(i,...n)=>i,APIDelete:async(i,...n)=>i,APIClone:async(i,...n)=>{},APILoad:async(i,...n)=>null,APILoadVersion:async(i,n,...s)=>null}),I(Ei,"type",o.DataType),I(Ei,"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]),I(Ei,"PARENT_TYPES",[...Ei.USER_MANAGED_PARENT_TYPES,o.BuiltInBaseEntity]),I(Ei,"MUTABLE_BASE_PROPERTIES",["isList","asType","options","foreignKeyAllowed","parentRelationType","like","implementationChooseOne","staticEntities","interactiveEntities","actionEntities"]),I(Ei,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","index","author","previousVersion"]),I(Ei,"BASE_PROPERTIES",[...Ei.MUTABLE_BASE_PROPERTIES,...Ei.INMUTABLE_BASE_PROPERTIES]),I(Ei,"MUTABLE_META_PROPERTIES",[...Ei.MUTABLE_BASE_PROPERTIES,"inferred"]),I(Ei,"INMUTABLE_META_PROPERTIES",[...Ei.INMUTABLE_BASE_PROPERTIES]),I(Ei,"META_PROPERTIES",[...Ei.MUTABLE_META_PROPERTIES,...Ei.INMUTABLE_META_PROPERTIES]),I(Ei,"MUTABLE_UPSTREAM_PROPERTIES",["entity","foreignKeyRef","parent"]),I(Ei,"INMUTABLE_UPSTREAM_PROPERTIES",[]),I(Ei,"UPSTREAM_PROPERTIES",[...Ei.MUTABLE_UPSTREAM_PROPERTIES,...Ei.INMUTABLE_UPSTREAM_PROPERTIES]),I(Ei,"MUTABLE_DOWNSTREAM_PROPERTIES",[]),I(Ei,"INMUTABLE_DOWNSTREAM_PROPERTIES",["andChildrenGroup","orChildrenGroup"]),I(Ei,"DOWNSTREAM_PROPERTIES",[...Ei.MUTABLE_DOWNSTREAM_PROPERTIES,...Ei.INMUTABLE_DOWNSTREAM_PROPERTIES]),I(Ei,"PROPERTIES",[...Ei.META_PROPERTIES,...Ei.UPSTREAM_PROPERTIES,...Ei.DOWNSTREAM_PROPERTIES]);let tr=Ei;async function WUe(d,p={}){var c;const i=J.YieldTracker.from(p),s=[...d.implements.flatMap(e=>Gx(d,e)),...Ds(d),...kx(d)];return await i.tick(),await((c=d.dataType)==null?void 0:c.validateAsync({tracker:i})),s}function zUe(d){var n;const p=d.implements.flatMap(s=>Gx(d,s));return(n=d.dataType)==null||n.validate(),[...p,...Ds(d),...kx(d)]}function Gx(d,p){const i=[];if(!d.implements)return i;if(!p.abstract){const s=$t({id:`${d.id}--${he.PropertyImplementsNonAbstact}`,message:`Property "${le(d,d.project)}" with id "${d.id}" implements a non-abstract property "${le(p,d.project)}" with id "${p.id}".`,severity:pe.Error,code:he.PropertyImplementsNonAbstact,entity:d});i.push(s.error)}if(d.static&&!p.static){const s=$t({id:`${d.id}--${he.NonStaticPropertyImplementsStatic}`,message:`Static property "${le(d,d.project)}" with id "${d.id}" implements a non-static property "${le(p,d.project)}" with id "${p.id}".`,severity:pe.Error,code:he.NonStaticPropertyImplementsStatic,entity:d});i.push(s.error)}if(!d.static&&p.static){const s=$t({id:`${d.id}--${he.StaticPropertyImplementsNonStatic}`,message:`Non-static property "${le(d,d.project)}" with id "${d.id}" implements a static property "${le(p,d.project)}" with id "${p.id}".`,severity:pe.Error,code:he.StaticPropertyImplementsNonStatic,entity:d});i.push(s.error)}if(!zr(d.dataType,p.dataType)){const s=$t({id:`${d.id}--${he.PropertyImplementsIncompatibleType}`,message:`Property "${le(d,d.project)}" with id "${d.id}" implements a property "${le(p,d.project)}" with id "${p.id}" that has an incompatible data type.`,severity:pe.Error,code:he.PropertyImplementsIncompatibleType,entity:d});i.push(s.error)}return Lt(d.errors,i)}function kx(d,p){const n=[...d.parent.allProperties].filter(s=>{var c;return s.id!==d.id&&!d.implements.find(e=>e.id===s.id)&&s.id!==((c=d.extends)==null?void 0:c.id)});return xv(d,[Ji],n,p)}const sUi=Object.freeze(Object.defineProperty({__proto__:null,validate:zUe,validateAsync:WUe,validateImplementation:Gx,validatePropertyEntityName:kx},Symbol.toStringTag,{value:"Module"}));function lUi(d,p){const i=[];if(d.parent){const s=p.get(d.parent);if(!s)i.push(new De({id:`${d.id}--${d.parent}--${ne.ReferencedEntityNotFound}`,code:ne.ReferencedEntityNotFound,severity:pe.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=ku(s);if(c){const e=s!==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}' (${le(c,s.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 De({id:`${d.id}--${ne.InvalidBuiltInEntityReference}`,code:ne.InvalidBuiltInEntityReference,severity:pe.Error,message:e}))}else if(![o.DefinitionEntity].includes(s.type))i.push(new De({id:`${d.id}--${d.parent}--${ne.InvalidParentReference}`,code:ne.InvalidParentReference,severity:pe.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=Zn(s).filter(m=>!m.interactive);if(y.length){let m=y.length>1?`The entity of type '${d.type}' with id '${d.id}' can't be added to the 'parent' entity with id '${s.id}' because it extends or implements multiple '${o.BuiltInBaseEntity}' entities that are non-interactive ("${wt(y.map(v=>le(v,v.project)),'", "','" and "')}").`:`The entity of type '${d.type}' with id '${d.id}' can't be added to the 'parent' entity with id '${s.id}' because it extends or implements a '${o.BuiltInBaseEntity}' entity that is non-interactive ("${le(y[0],y[0].project)}").`;m+=`
388
388
  ${Mu}`,i.push(new De({id:`${d.id}--${ne.NonInteractiveEntityReferenced}`,code:ne.NonInteractiveEntityReferenced,severity:pe.Error,message:m}))}else d.implements&&d.implements.forEach(m=>{const v=p.get(m);if(m===d.id)return i.push(new De({id:`${d.id}--${d.implements}--${ne.SelfReference}`,code:ne.SelfReference,severity:pe.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(!v)i.push(new De({id:`${d.id}--${d.implements}--${ne.ReferencedEntityNotFound}`,code:ne.ReferencedEntityNotFound,severity:pe.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 E=s.properties.find(b=>b.implements.find(w=>{var P;return(P=d.implements)==null?void 0:P.includes(w.id)}));E?i.push(new De({id:`${d.id}--${Ie.PropertyOverwritesOtherSiblingWithSameImplementation}`,code:Ie.PropertyOverwritesOtherSiblingWithSameImplementation,severity:pe.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 '${E.id}' that implements the same base property.`})):[o.Property].includes(v.type)?v.abstract||i.push(new De({id:`${d.id}--${d.implements}--${ne.InvalidImplementsReference}`,code:ne.InvalidImplementsReference,severity:pe.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 De({id:`${d.id}--${d.implements}--${ne.InvalidImplementsReference}`,code:ne.InvalidImplementsReference,severity:pe.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 n=vn(d,{},p);return i.push(...n.errors),i}function oUi(d){return!!d.implements.find(p=>p.id===Q["built-in-base-entity"].BUILT_IN_PERSISTED_ENTITY_ENTITY.properties.database.id)}function Pk(d,p){const i=[],n=[],s=[],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=Yr.new(p);y.name=oe.EntityTemplate,y.parent=d.toReference();const m=ye(y,d.project);m.hydrateAncestors(),m.addSelfToProject(p),p==null||p.add(m,Z.Added),n.push(m),m.initChildren(p),e=m}if(!e.valueAsTypeSingle){const y=MUe(d.project);y&&e.setValueAsTypeSingle(y,p)}}return{updated:D(i),added:D(n),removed:D(s),affected:D(c),self:d}}var JUe=(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))(JUe||{});const ti=class ti extends kr{constructor(i,n){super(i);I(this,"initialData");I(this,"id");I(this,"name");I(this,"codeName",null);I(this,"description",null);I(this,"private");I(this,"abstract");I(this,"index");I(this,"static");I(this,"unique");I(this,"required");I(this,"constant",!1);I(this,"interactive",!1);I(this,"type",o.Property);I(this,"hidden",!1);I(this,"parentRelationType",null);I(this,"defaultValue",null);I(this,"dataType",null);I(this,"implements",[]);I(this,"extends",null);I(this,"project");I(this,"errors",[]);I(this,"parent");I(this,"detachedDependents",{});I(this,"knownVersions",null);I(this,"activeVersion",!1);I(this,"initialized",!1);I(this,"startedInitialization",!1);I(this,"suggestion",!1);I(this,"_codeNativeValueValidation",null);this.initialData=i,this.project=n,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:x.UUID.uuid(),version:x.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||M().toISOString(),author:(i==null?void 0:i.author)||x.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,n){const s=re(i.parent),c=n.get(s),e=[];i.implements&&i.implements.forEach(E=>{e.push(n.get(E)||n.getBuiltIn(E))});let y=null;if(i.extends){const E=re(i.extends);y=n.get(E)}const m={id:i.id,version:x.UUID.uuid(),createdAt:M().toISOString(),author:x.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},v=ye(m,n);return v.setParent(c,null),v}static validateGenerationTarget(i,n){let s=JSON.parse(JSON.stringify(i));const c=[],e=lUi(s,n),y=xx(s,n);return c.push(...e,...y,...Nr(s)),{errors:c,modifiedData:s}}get isExtendedProperty(){const i=this.parent.allBasePropertiesFromExtendedAndImplementedEntities.find(n=>{var s;return n.id===((s=this.extends)==null?void 0:s.id)});return!!i&&i.id!==this.id&&!i.abstract}get codeNativeValueValidation(){const i=[...this.implements].filter(s=>!this.implements.filter(y=>y.id!==s.id).some(y=>!!y.implements.find(m=>m.id===s.id)));return this._codeNativeValueValidation||(i==null?void 0:i.some(s=>s.codeNativeValueValidation))?(s,c)=>{const e=[];let y=c;if(this._codeNativeValueValidation){const m=this._codeNativeValueValidation(s,c);m&&(e.push(...m.errors),y=m.override)}return i.forEach(m=>{const v=m.codeNativeValueValidation;if(v){const E=v(s,c);E&&(e.push(...E.errors),y=E.override)}}),{errors:sv(e),override:y}}:null}validateGeneratedUpdate(i){const n=[];return i.parent&&n.push(new De({id:`${this.id}--${ne.InvalidParentUpdate}`,code:ne.InvalidParentUpdate,severity:pe.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)&&n.push(new De({id:`${this.id}--${Ie.InvalidObjectStructure}`,code:Ie.InvalidObjectStructure,severity:pe.Error,message:`Entity of type '${this.type}' with id '${this.id}' is not a value reading or writing entity.
390
390
  ${cA}`})),{errors:n,modifiedData:i}}onProjectInitialized(i,n=this.project.addChangeSet(new q(this.project,x.sessionAuthor,new Date().toISOString(),this,!0,"on-property-received-project-initialized"))){return Pk(this,n),n==null||n.attemptAutoclose("on-property-received-project-initialized",this.id),this}subscribeDependents(i){return i.forEach(n=>{this.detachedDependents[n.entity.id]||(this.detachedDependents[n.entity.id]=n)}),this}unsubscribeDependents(i){return i.forEach(n=>{this.detachedDependents[n.entity.id]&&delete this.detachedDependents[n.entity.id]}),this}syncDependents(i=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,"sync-dependents"))){const n=[],s=[],c=[],e=[];return Object.values(this.detachedDependents).forEach(y=>{const m=y.entity.afterAllChildrenInitialized(i);n.push(...m.updated),s.push(...m.added),c.push(...m.removed),e.push(...m.affected)}),i==null||i.attemptAutoclose("sync-dependents",this.id),{updated:D(n),added:D(s),removed:D(c),affected:D(e),self:this}}onDetachedDependencyRemoved(i,n,s){const c=[],e=[],y=[],m=[];if(n==="property-implements-field"&&(this.removeImplementation(i,s),c.push(this)),n==="property-extends-field"){const{updated:v,added:E,removed:b,affected:w}=this.remove({ignoreUpstream:!1},s);c.push(...v),e.push(...E),y.push(...b),m.push(...w)}return{updated:D(c),added:D(e),removed:D(y),affected:D(m),self:this}}onDetachedDependencyRestored(i,n,s){const c=[],e=[],y=[],m=[];if(n==="property-implements-field"&&(this.addImplementation(i,s),c.push(this)),n==="property-extends-field"){const{updated:v,added:E,removed:b,affected:w}=this.restore({},s);c.push(...v),e.push(...E),y.push(...b),m.push(...w)}return{updated:D(c),added:D(e),removed:D(y),affected:D(m),self:this}}unsubscribeFromDependencies(){var i,n,s,c,e,y,m;return this.implements.forEach(v=>{this.project.getBuiltIn(v.id)||v.unsubscribeDependents([{entity:this,field:"property-implements-field"}])}),(n=(i=this.extends)==null?void 0:i.unsubscribeDependents)==null||n.call(i,[{entity:this,field:"property-extends-field"}]),(e=(c=(s=this.dataType)==null?void 0:s.entity)==null?void 0:c.unsubscribeDependents)==null||e.call(c,[{entity:this,field:"property-data-type-entity-field"}]),(m=(y=this.dataType)==null?void 0:y.unsubscribeDependents)==null||m.call(y,[{entity:this,field:"property-data-type-field"}]),this.project.off(ii.PROJECT_INITIALIZED,this.onProjectInitialized),this}subscribeToDependencies(){var i,n,s,c,e,y,m;return this.implements.forEach(v=>{this.project.getBuiltIn(v.id)||v.subscribeDependents([{entity:this,field:"property-implements-field"}])}),(n=(i=this.extends)==null?void 0:i.subscribeDependents)==null||n.call(i,[{entity:this,field:"property-extends-field"}]),(e=(c=(s=this.dataType)==null?void 0:s.entity)==null?void 0:c.subscribeDependents)==null||e.call(c,[{entity:this,field:"property-data-type-entity-field"}]),(m=(y=this.dataType)==null?void 0:y.subscribeDependents)==null||m.call(y,[{entity:this,field:"property-data-type-field"}]),oUi(this)&&this.project.on(ii.PROJECT_INITIALIZED,this.onProjectInitialized),this}increaseVersion(i){if(i&&!M(i).isValid())throw new Error(`The shared timestamp '${i}' is not a valid ISO 8601 date string.`);return i&&M(i).isSame(M(this.createdAt))?this:(this.previousVersion=this.version,this.version=x.UUID.uuid(),this.createdAt=M(i).toISOString()||M().toISOString(),this)}captureVersion(){var n;const i=((n=this.knownVersions)==null?void 0:n.get(this.version))||new ti(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 n=[],s=[],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);n.push(this.parent,...y.updated),s.push(...y.added),c.push(...y.removed)}return{updated:D(n),added:D(s),removed:D(c),affected:D(e),self:this}}async restoreVersion(i){var m;const n=[],s=[],c=[],e=[];if(this.version===i)return{updated:D(n),added:D(s),removed:D(c),affected:D(e),self:this};if(!this.knownVersions){const v=new Map;for(const[E,b]of this.knownVersions||new Map){if(v.set(E,b),b.activeVersion=!1,b.knownVersions)for(const[w,P]of b.knownVersions)v.set(w,P);b.knownVersions=null}}let y=(m=this.knownVersions)==null?void 0:m.get(i);if(!y){const v=await this.APILoadVersion({},i);if(!v)throw new Error(`Version with id '${i}' for entity with id '${this.id}' not found.`);y=new ti(v,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:D(n),added:D(s),removed:D(c),affected:D(e),self:this}}updateWithShallowTransfer(i,n=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,_.UpdateWithShallowTransfer))){if(!this.checkCanEdit(this,n))return J.Logger.warn(`[updateWithShallowTransfer] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),n==null||n.attemptAutoclose(_.UpdateWithShallowTransfer,this.id),this;if(this.metaSync(i,n),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 c=re(i.parent),e=this.project.get(c),y=this.parent;if(y&&y.id!==(e==null?void 0:e.id)&&this.removeFromParent(n),e)this.setParent(e,n),this.addSelfToProject(n);else throw n==null||n.attemptAutoclose(_.UpdateWithShallowTransfer,this.id),new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${c}' that isn't found in the project`)}else throw n==null||n.attemptAutoclose(_.UpdateWithShallowTransfer,this.id),new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(i.implements.forEach(c=>{const e=re(c),y=this.project.get(e);if(y)this.addImplementation(y,n);else throw new Error(`${Fr(this.type)} with id '${this.id}' has a 'implements' reference "${e}" which is missing in the project`)}),this.implements.filter(c=>{const e=re(c);return!i.implements.find(y=>re(y)===e)}).forEach(c=>{this.removeImplementation(c,n)}),i.extends){const c=re(i.extends),e=this.project.get(c);if(e)this.setExtends(e,n);else if(c)throw new Error(`${Fr(this.type)} with id '${this.id}' has a 'extends' reference "${c}" which is missing in the project`)}else this.setExtends(null,n);if(i.dataType){const c=re(i.dataType),e=this.project.get(c);e&&this.setDataType(e,n)}else this.setDataType(null,n);if(i.defaultValue){const c=re(i.defaultValue),e=this.project.get(c);e&&this.setDefaultValue(e,n)}else this.setDefaultValue(null,n);return this.captureVersion(),this.subscribeToDependencies(),n==null||n.attemptAutoclose(_.UpdateWithShallowTransfer,this.id),this}hydrateAncestors(){const i=[],n=[],s=[],c=[];if(this.initialData.parent){const e=re(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=re(e),m=this.project.get(y);if(m)this.addImplementation(m,null),i.push(m);else throw new Error(`${Fr(this.type)} with id '${this.id}' has a 'implements' reference "${y}" which is missing in the project`)}),this.initialData.extends){const e=re(this.initialData.extends),y=this.project.get(e);if(y)this.setExtends(y,null),i.push(y);else if(e)throw new Error(`${Fr(this.type)} with id '${this.id}' has a 'extends' reference "${e}" which is missing in the project`)}return{updated:D(i),added:D(n),removed:D(s),affected:D(c),self:this}}afterAllChildrenInitialized(i=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,_.AfterAllChildrenInitialized))){if(!this.checkCanEdit(this,i))return J.Logger.warn(`[afterAllChildrenInitialized] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(_.AfterAllChildrenInitialized,this.id),{updated:[],added:[],removed:[],affected:[],self:this};const n=[],s=[],c=[],e=[];if(this.initialized=!0,this.parent.type===o.DefinitionEntity&&this.parentRelationType!==yc.AllPropertiesImplementationTarget){let X=this.index||0;const se=this.parent.properties.filter(fe=>!fe.deleted&&fe.id!==this.id);se.length&&(X>se.length+1?X=se.length:X<0&&(X=0)),se.find(fe=>(fe.index||0)===X&&!fe.deleted)&&se.filter(fe=>(fe.index||0)>=X&&!fe.deleted).forEach(fe=>{fe.metaSync({index:(fe.index||0)+1},i),i==null||i.add(fe,Z.Updated),n.push(fe)}),this.metaSync({index:X},i)}const{updated:y,added:m,removed:v,affected:E}=this.syncWithImplementation(i);n.push(...y),s.push(...m),c.push(...v),e.push(...E);const{updated:b,added:w,removed:P,affected:$}=Pk(this,i);n.push(...b),s.push(...w),c.push(...P),e.push(...$);const{updated:L,added:U,removed:K,affected:H}=this.syncWithExtension(i);return n.push(...L),s.push(...U),c.push(...K),e.push(...H),this.captureVersion(),i==null||i.attemptAutoclose(_.AfterAllChildrenInitialized,this.id),{updated:D(n),added:D(s),removed:D(c),affected:D(e),self:this}}addSelfToProject(i=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,"add-self-to-project"))){const n=[this],s=[],c=[],e=[];return this.parentRelationType===yc.AllPropertiesImplementationTarget?this.parent.setAllPropertiesImplement(this,i):this.parent.addProperty(this,i),n.push(this.parent),this.subscribe(),this.subscribeToDependencies(),i==null||i.attemptAutoclose("add-self-to-project",this.id),{updated:D(n),added:D(s),removed:D(c),affected:D(e),self:this}}setParent(i,n=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,_.SetParent))){var s;return this.checkCanEditWithCounterpartAndSideEffects(this,i,_.SetParent,n)?(((s=this.parent)==null?void 0:s.id)!==(i==null?void 0:i.id)&&(this.parent=i,n&&(n==null||n.add(this,Z.Updated))),n==null||n.attemptAutoclose(_.SetParent,this.id),this):this}addImplementation(i,n=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,_.AddImplementation))){return this.checkCanEdit(this,n)?(this.implements.includes(i)||(this.implements.push(i),n==null||n.add(this,Z.Updated)),n==null||n.attemptAutoclose(_.AddImplementation,this.id),this):(J.Logger.warn(`[addImplementation] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),n==null||n.attemptAutoclose(_.AddImplementation,this.id),this)}removeImplementation(i,n=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,_.RemoveImplementation))){return this.checkCanEdit(this,n)?(this.implements.includes(i)&&(this.implements=this.implements.filter(s=>s.id!==i.id),n==null||n.add(this,Z.Updated)),n==null||n.attemptAutoclose(_.RemoveImplementation,this.id),this):(J.Logger.warn(`[removeImplementation] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),n==null||n.attemptAutoclose(_.RemoveImplementation,this.id),this)}setExtends(i,n=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,_.SetExtends))){var s;return this.checkCanEdit(this,n)?(((s=this.extends)==null?void 0:s.id)!==(i==null?void 0:i.id)&&(this.extends=i,this.subscribeToDependencies(),n&&(n==null||n.add(this,Z.Updated))),n==null||n.attemptAutoclose(_.SetExtends,this.id),this):(J.Logger.warn(`[setExtends] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),n==null||n.attemptAutoclose(_.SetExtends,this.id),this)}initChildren(i=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,"init-children"))){if(this.initialized||this.startedInitialization)return this;if(this.startedInitialization=!0,this.initialData.defaultValue&&(this.defaultValue=ye(this.initialData.defaultValue,this.project),this.defaultValue.setParent(this,null),this.defaultValue.initChildren(i)),this.initialData.dataType){const n=ye(this.initialData.dataType,this.project);n.setParent(this,null),n.initChildren(i),this.dataType=n}if(this.implements=this.initialData.implements.map(n=>ye(n,this.project)),this.initialData.extends){const n=ye(this.initialData.extends,this.project);this.setExtends(n,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,n=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,"meta-sync"))){const s=$r(this,i,n),c=xr(this,s),e=this.toMeta();return this.name=s.name!==void 0?s.name:e.name,this.codeName=s.codeName!==void 0?s.codeName:e.codeName,this.description=s.description!==void 0?s.description:e.description,this.abstract=s.abstract!==void 0?s.abstract:e.abstract,this.private=s.private!==void 0?s.private:e.private,this.index=s.index||(s.index!==0?e.index:0),this.static=s.static!==void 0?s.static:e.static,this.hidden=s.hidden!==void 0?s.hidden:e.hidden,this.constant=s.constant!==void 0?s.constant:e.constant,this.interactive=s.interactive!==void 0?s.interactive:e.interactive,this.required=s.required!==void 0?s.required:e.required,this.unique=s.unique!==void 0?s.unique:e.unique,super.baseMetaSync(s,this,n),s.deleted===!0&&!e.deleted?n==null||n.add(this,Z.Removed):s.deleted===!1&&e.deleted?n==null||n.add(this,Z.Added):c&&(n==null||n.add(this,Z.Updated)),n==null||n.attemptAutoclose("meta-sync",this.id),this}async APILoad(i=Ge,...n){return await ti.repository.APILoad(this.id,...n),this}async APICreate(i=Ge,...n){return await ti.repository.APICreate(this.toShallowJSON(),...n),this}async APIUpdate(i=Ge,...n){return await ti.repository.APIUpdate(this.toShallowJSON(),...n),this}async APIDelete(i=Ge,...n){return await ti.repository.APIDelete(this.toShallowJSON(),...n),this}async APIClone(i=Ge,...n){return await ti.repository.APIClone(this.id,...n),this}async APILoadVersion(i=Ge,n,...s){return await ti.repository.APILoadVersion(this.id,n,...s)}removeFromParent(i=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,_.RemoveFromParent))){if(!this.checkCanEdit(this,i))return J.Logger.warn(`[removeFromParent] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(_.RemoveFromParent,this.id),{added:[],updated:[],removed:[],affected:[],self:this};const n=[],s=[],c=[],e=[];return this.parent.type===o.DefinitionEntity&&(this.parentRelationType===yc.AllPropertiesImplementationTarget?this.parent.removeAllPropertiesImplement(i):this.parent.removeProperty(this,i),e.push(this.parent)),i==null||i.attemptAutoclose(_.RemoveFromParent,this.id),{added:D(c),updated:D(n),removed:D(s),affected:D(e),self:this}}remove({ignoreUpstream:i}={ignoreUpstream:!1},n=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,_.RemoveEntity))){var m;if(!this.checkCanDelete(this,n))return J.Logger.warn(`[remove] User is not allowed to delete or edit this ${this.type} entity with id: ${this.id}`),n==null||n.event({id:`${_.RemoveEntity}-${this.id}`,action:_.RemoveEntity,owner:this,errorReason:ir.ActionOwnerEntityNonDeletable,rootAction:((m=n==null?void 0:n.self)==null?void 0:m.id)===this.id&&(n==null?void 0:n.autoCloseActionName)===_.RemoveEntity}),n==null||n.attemptAutoclose(_.RemoveEntity,this.id),{added:[],updated:[],removed:[],affected:[],self:this};const s=[],c=[],e=[],y=[];if(n!=null&&n.hasRemoved(this.id))return n==null||n.attemptAutoclose(_.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},n),Object.values(this.detachedDependents).forEach(v=>{const{updated:E,removed:b,added:w}=v.entity.onDetachedDependencyRemoved(this,v.field,n);s.push(...E),c.push(...b),e.push(...w)}),this.defaultValue){const{updated:v,removed:E}=this.defaultValue.remove({ignoreUpstream:!0},n);s.push(...v),c.push(...E)}if(this.dataType){const{updated:v,removed:E}=this.dataType.remove({ignoreUpstream:!0},n);s.push(...v),c.push(...E)}if(!i){const v=this.removeFromParent(n);e.push(...v.added),s.push(...v.updated),c.push(...v.removed),y.push(...v.affected)}return n==null||n.attemptAutoclose(_.RemoveEntity,this.id),{added:D(e),updated:D(s),removed:D(c),affected:D(y),self:this}}restore({}={},i=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,_.RestoreEntity))){if(!this.checkCanEdit(this,i))return J.Logger.warn(`[restore] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(_.RestoreEntity,this.id),{added:[],updated:[],removed:[],affected:[],self:this};const n=[],s=[],c=[],e=[];if(i!=null&&i.hasAdded(this.id))return i==null||i.attemptAutoclose(_.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:m,removed:v,added:E}=y.entity.onDetachedDependencyRestored(this,y.field,i);s.push(...m),c.push(...v),n.push(...E)}),this.defaultValue){const{updated:y}=this.defaultValue.restore({},i);s.push(...y)}if(this.dataType){const{updated:y}=this.dataType.restore({},i);s.push(...y)}return this.parent.type===o.DefinitionEntity&&(this.parentRelationType===yc.AllPropertiesImplementationTarget?this.parent.removeAllPropertiesImplement(i):this.parent.addProperty(this,i),e.push(this.parent)),i==null||i.attemptAutoclose(_.RestoreEntity,this.id),{added:D(n),updated:D(s),removed:D(c),affected:D(e),self:this}}toFlat(i=new Set){var s,c;return i.has(this.id)?[]:(i.add(this.id),[this,...((s=this.defaultValue)==null?void 0:s.toFlat(i))||[],...((c=this.dataType)==null?void 0:c.toFlat(i))||[],...this.parent.toFlat(i)])}toFlatIds(i=new Set){var s,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,...((s=this.defaultValue)==null?void 0:s.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 n,s,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:((n=this.defaultValue)==null?void 0:n.toJSON(i))||null,dataType:((s=this.dataType)==null?void 0:s.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=pt){var s,c,e,y,m,v,E;let n;return(s=i.seenEntityMaps)!=null&&s.has(this.id)?n=i.seenEntityMaps.get(this.id):(n=i.newId||jr(this,this.project,i.uuidStrategy),i.seenEntityMaps&&i.seenEntityMaps.set(this.id,n)),(c=i.seenEntities)!=null&&c.has(n)||(e=i.seenEntities)!=null&&e.has(this.id)?this.toReference({seenEntityMaps:i.seenEntityMaps}):((y=i.seenEntities)==null||y.add(n),(m=i.seenEntities)==null||m.add(this.id),{id:n,version:x.UUID.uuid(),createdAt:i.timestamp||M().toISOString(),author:x.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:((v=this.defaultValue)==null?void 0:v.toJSONClone({...i,newId:null}))||null,dataType:((E=this.dataType)==null?void 0:E.toJSONClone({...i,newId:null}))||null,implements:this.implements.map(b=>this.project.getBuiltIn(b.id)?b.toJSON(i.seenEntities):b.toJSONClone({...i,newId:null})),extends:(()=>{var b;return this.extends&&this.project.getBuiltIn(this.extends.id)?this.extends.toJSON():((b=this.extends)==null?void 0:b.toJSONClone({...i,newId:null}))||null})(),parent:this.parent.toReference({seenEntityMaps:i.seenEntityMaps})})}toReference(i=pt){var s;let n=this.id;return(s=i.seenEntityMaps)!=null&&s.has(this.id)&&(n=i.seenEntityMaps.get(this.id)),{id:n+"--"+x.UUID.uuid()+"--ref",type:o.GenericReference,entityId:n,version:this.version,entityType:this.type}}toShallowJSON(i=pt){var s,c,e,y;let n=this.id;return(s=i.seenEntityMaps)!=null&&s.has(this.id)&&(n=i.seenEntityMaps.get(this.id)),{id:n,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(m=>m.toReference(i)),extends:((y=this.extends)==null?void 0:y.toReference(i))||null,parent:this.parent.toReference(i)}}toFlatJSON(i=new Set){var s,c;return i.has(this.id)?[]:(i.add(this.id),[this.toShallowJSON(),...((s=this.defaultValue)==null?void 0:s.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(n=>n.id),extends:(i=this.extends)==null?void 0:i.id,parent:this.parent.id}}toFlatGenerationTarget(i=new Set){var s,c;return i.has(this.id)?[]:(i.add(this.id),[this.toGenerationTarget(),...((s=this.defaultValue)==null?void 0:s.toFlatGenerationTarget(i))||[],...((c=this.dataType)==null?void 0:c.toFlatGenerationTarget(i))||[],...this.implements.flatMap(e=>e.toFlatGenerationTarget(i))])}clearErrors(){var i,n;return this.errors=[],(i=this.defaultValue)==null||i.clearErrors(),(n=this.dataType)==null||n.clearErrors(),this}validate(){return this.errors=zUe(this),{success:!0}}async validateAsync(i={}){const n=J.YieldTracker.from(i);return this.errors=await WUe(this,{tracker:n}),{success:!0}}getErrors(){var n,s;return[...this.errors,...((n=this.defaultValue)==null?void 0:n.getErrors())||[],...((s=this.dataType)==null?void 0:s.getErrors())||[]]}async getErrorsAsync(i={}){const n=J.YieldTracker.from(i),s=[...this.errors];if(await n.tick(),this.defaultValue){const c=await this.defaultValue.getErrorsAsync({tracker:n});s.push(...c)}if(this.dataType){const c=await this.dataType.getErrorsAsync({tracker:n});s.push(...c)}return s}getShallowErrors(){return this.errors}implement(i,n=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,"implement-self-as-property")),s=null){var v;const c=s||x.UUID.uuid(),e=ti.new(n);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=ye(e,this.project);y.hydrateAncestors(),y.addSelfToProject(n),n==null||n.add(y,Z.Added),y.initChildren(n);const m=(v=this.defaultValue)==null?void 0:v.clone(n,y,x.UUID.uuid());return m&&(m.editable=!0,m.deletable=!0),y}clone(i=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,_.CloneEntity)),n=null,s=null,c=!0){var b,w;const e=Pr(n,this),y=s||x.UUID.uuid(),m=n||this.parent,v={hidden:!1,id:y,version:x.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||M().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(P=>P.toJSON()),extends:this.extends,parent:m.toReference()},E=Ui(v,e);if(E.hydrateAncestors(),E.setParent(m,i),c&&(E.subscribe(),E.addSelfToProject(i)),E.initChildren(i),i==null||i.add(E,Z.Added),this.dataType&&this.project.diggestedBuiltInBaseEntitiesIds.has(this.dataType.id))E.setDataType(e.getBuiltIn(this.dataType.id),i);else{const P=((b=this.dataType)==null?void 0:b.clone(i,E,x.UUID.uuid(),c))||null;P&&E.setDataType(P,i)}if(this.defaultValue){const P=(w=this.defaultValue)==null?void 0:w.clone(i,E,x.UUID.uuid(),c);E.setDefaultValue(P||null,i)}return this.implements.length&&this.implements.forEach(P=>{const $=e.get(P.id)||e.getBuiltIn(P.id);if($){E.addImplementation($,i);return}}),E.addSelfToProject(null),i==null||i.attemptAutoclose(_.CloneEntity,this.id),E}setDataType(i,n=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,_.SetDataType))){if(!this.checkCanEdit(this,n))return J.Logger.warn(`[setDataType] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),n==null||n.attemptAutoclose(_.SetDataType,this.id),this;const s=this.dataType;return(s==null?void 0:s.id)!==(i==null?void 0:i.id)&&(s==null||s.remove({ignoreUpstream:!0},n),this.dataType=i,this.subscribeToDependencies(),n==null||n.add(this,Z.Affected)),n==null||n.attemptAutoclose(_.SetDataType,this.id),this}removeDataType(i=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,_.RemoveDataType))){return this.checkCanEdit(this,i)?(this.dataType&&(this.dataType.remove({ignoreUpstream:!0},i),i==null||i.add(this,Z.Affected),this.dataType=null),i==null||i.attemptAutoclose(_.RemoveDataType,this.id),this):(J.Logger.warn(`[removeDataType] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(_.RemoveDataType,this.id),this)}getDataType(i=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().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||qn(i))&&y&&(i=y)}let n=this.defaultValue;const s=(c=this.extends)==null?void 0:c.getDefaultValue();return qn(n)&&s&&!qn(s)&&(n=s),qn(n)&&i&&!qn(i)&&(n=i),n}setDefaultValue(i,n=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,"set-default-value"))){if(!this.checkCanEdit(this,n))return J.Logger.warn(`[setDefaultValue] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),n==null||n.attemptAutoclose("set-default-value",this.id),this;const s=this.defaultValue;return(s==null?void 0:s.id)!==(i==null?void 0:i.id)&&(s==null||s.remove({ignoreUpstream:!0},n),this.defaultValue=i,n==null||n.add(this,Z.Affected)),n==null||n.attemptAutoclose("set-default-value",this.id),this}syncWithImplementation(i=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,"sync-with-implementation"))){var P,$,L,U,K,H,X,se,ee,fe,de;if(!this.checkCanEdit(this,i))return J.Logger.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 n=[],s=[],c=[],e=[];this.parent.type!==o.PrimitiveEntity&&this.interactive&&this.parent.getAllPropertiesImplements().forEach(ve=>{this.addImplementation(ve,i)});let y=null;for(const ce of this.implements)(P=ce.dataType)!=null&&P.isResolved&&(y?($=ce.dataType.orChildrenGroup)!=null&&$.length&&ce.dataType.implementationChooseOne&&(y=ce.dataType):y=ce.dataType);const m=zr(this.dataType,y);if(!this.dataType||!((L=this.dataType)!=null&&L.isResolved)||(U=this.dataType)!=null&&U.isResolved&&(y!=null&&y.isResolved)&&!m.compatible){if(y&&((K=y.orChildrenGroup)!=null&&K.length)&&y.implementationChooseOne){if(!this.dataType||this.dataType&&this.project.diggestedBuiltInBaseEntitiesIds.has(this.dataType.id)){const ve=tr.new(i);ve.parent=this.toReference();const ae=ye(ve,this.project);ae.hydrateAncestors(),i==null||i.add(ae,Z.Added),ae.addSelfToProject(i),ae.afterAllChildrenInitialized(i)}const ce=y.orChildrenGroup.some(ve=>ve.foreignKeyAllowed);if(((X=(H=this.dataType)==null?void 0:H.entity)==null?void 0:X.type)===o.DefinitionEntity&&Si(this.dataType.entity,Re.PERSISTED_ENTITY)&&ce){const ve=$Ue(this.dataType.entity);ve&&this.dataType.setForeignKeyRef(ve,i),(se=this.dataType)==null||se.setEntity(null,i)}else{const ve=y.orChildrenGroup.find(ae=>{var me;return((me=ae.entity)==null?void 0:me.id)===Q["primitive-entity"].string.id});if(ve)(ee=this.dataType)==null||ee.setEntity(ve.entity,i);else{const ae=y.orChildrenGroup.filter(_e=>_e.isResolved),me=ae.filter(_e=>{var Ne;return((Ne=_e.entity)==null?void 0:Ne.type)===o.PrimitiveEntity});me.length?(fe=this.dataType)==null||fe.setEntity(me[0].entity,i):ae.length&&((de=this.dataType)==null||de.setEntity(ae[0].entity,i))}}}else if(y&&this.project.diggestedBuiltInBaseEntitiesIds.has(y.id))this.setDataType(y,i);else if(y){const ce=y.clone(i,this,x.UUID.uuid(),!0);this.setDataType(ce,i),s.push(ce)}}if(!this.defaultValue){let ce=null;for(const ve of this.implements){const ae=ve.getDefaultValue();ae&&(ce=ae)}if(ce){const ve=ce.clone(i,this,x.UUID.uuid(),!0);this.setDefaultValue(ve,i),s.push(ve)}}let v=!1,E=!1,b=!1,w=!1;return this.implements.forEach(ce=>{ce.required&&(v=!0),ce.constant&&(b=!0),ce.unique&&(E=!0),ce.static&&(w=!0)}),this.metaSync({required:v||this.required,constant:b||this.constant,unique:E||this.unique,static:w||this.static},i),i==null||i.attemptAutoclose("sync-with-implementation",this.id),{updated:D(n),added:D(s),removed:D(c),affected:D(e),self:this}}syncWithExtension(i=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,"sync-with-extension"))){var v,E;if(!this.checkCanEdit(this,i))return J.Logger.warn(`[syncWithExtension] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose("sync-with-extension",this.id),{added:[],updated:[],removed:[],affected:[],self:this};const n=[],s=[],c=[],e=[];if(!this.extends)return i==null||i.attemptAutoclose("sync-with-extension",this.id),{added:[],updated:[],removed:[],affected:[],self:this};const y={...this.extends.toMeta()};if(delete y.id,delete y.version,delete y.createdAt,delete y.previousVersion,delete y.author,delete y.index,this.metaSync(y,i),n.push(this),!this.extends.dataType)return i==null||i.attemptAutoclose("sync-with-extension",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(!this.dataType){const b=tr.new(i);b.parent=this.toReference();const w=ye(b,this.project);w.hydrateAncestors(),i==null||i.add(w,Z.Added),w.addSelfToProject(i),w.afterAllChildrenInitialized(i)}if(zr(this.dataType,this.extends.dataType).compatible||(v=this.dataType)==null||v.merge(this.extends.dataType,i),this.extends.defaultValue&&!this.defaultValue){const b=this.extends.defaultValue.clone(i,this,x.UUID.uuid(),!0);this.setDefaultValue(b,i),s.push(b)}else this.extends.defaultValue?this.extends.defaultValue&&this.defaultValue&&!Wke(this.defaultValue,this.extends.defaultValue)&&(this.defaultValue.merge(this.extends.defaultValue,i),n.push(this.defaultValue)):((E=this.defaultValue)==null||E.remove({ignoreUpstream:!0},i),this.defaultValue=null,e.push(this));return i==null||i.attemptAutoclose("sync-with-extension",this.id),{updated:D(n),added:D(s),removed:D(c),affected:D(e),self:this}}implementAsInputMap(i=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,"implement-as-return-declaration")),n,s){const c=ds.new(i);c.id=s||c.id,c.name=this.name,c.description=this.description,c.parent=n.toReference(),c.declaration=this.toJSON();const e=Ui(c,this.project);if(e.hydrateAncestors(),e.addSelfToProject(i),i==null||i.add(e,Z.Added),e.initChildren(i),this.dataType)if(this.project.diggestedBuiltInBaseEntitiesIds.has(this.dataType.id))e.setDataType(this.dataType,i),i==null||i.add(e,Z.Affected);else{const y=this.dataType.clone(i,e);e.setDataType(y,i)}if(this.defaultValue){const y=this.defaultValue.clone(i,e);e.setDefaultValue(y,i)}return i==null||i.attemptAutoclose("implement-as-return-declaration",this.id),e}};I(ti,"repository",{APICreate:async(i,...n)=>i,APIUpdate:async(i,...n)=>i,APIDelete:async(i,...n)=>i,APIClone:async(i,...n)=>{},APILoad:async(i,...n)=>null,APILoadVersion:async(i,n,...s)=>null}),I(ti,"type",o.Property),I(ti,"USER_MANAGED_PARENT_TYPES",[o.DefinitionEntity]),I(ti,"PARENT_TYPES",[...ti.USER_MANAGED_PARENT_TYPES,o.PrimitiveEntity,o.BuiltInBaseEntity]),I(ti,"MUTABLE_BASE_PROPERTIES",["name","codeName","description","private","abstract","static","required","constant","unique","interactive"]),I(ti,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),I(ti,"BASE_PROPERTIES",[...ti.MUTABLE_BASE_PROPERTIES,...ti.INMUTABLE_BASE_PROPERTIES]),I(ti,"MUTABLE_META_PROPERTIES",[...ti.MUTABLE_BASE_PROPERTIES,"index"]),I(ti,"INMUTABLE_META_PROPERTIES",[...ti.INMUTABLE_BASE_PROPERTIES]),I(ti,"META_PROPERTIES",[...ti.MUTABLE_META_PROPERTIES,...ti.INMUTABLE_META_PROPERTIES]),I(ti,"MUTABLE_UPSTREAM_PROPERTIES",[]),I(ti,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","implements","extends"]),I(ti,"UPSTREAM_PROPERTIES",[...ti.MUTABLE_UPSTREAM_PROPERTIES,...ti.INMUTABLE_UPSTREAM_PROPERTIES]),I(ti,"MUTABLE_DOWNSTREAM_PROPERTIES",["dataType"]),I(ti,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),I(ti,"DOWNSTREAM_PROPERTIES",[...ti.MUTABLE_DOWNSTREAM_PROPERTIES,...ti.INMUTABLE_DOWNSTREAM_PROPERTIES]),I(ti,"PROPERTIES",[...ti.META_PROPERTIES,...ti.UPSTREAM_PROPERTIES,...ti.DOWNSTREAM_PROPERTIES]);let ka=ti;async function YUe(d,p={}){var E,b;const i=J.YieldTracker.from(p),n=d.implements.flatMap(w=>tKe(d,w)),s=iKe(d,d.extends),c=nKe(d),e=rKe(d),y=jx(d),m=[...n,...s,...c,...e,...y],v=Lt(d.errors,m);await i.tick();for(const w of d.properties)await w.validateAsync({tracker:i});for(const w of d.methods)await w.validateAsync({tracker:i});for(const w of d.abstractMethods)await w.validateAsync({tracker:i});return await((E=d.allPropertiesImplement)==null?void 0:E.validateAsync({tracker:i})),await((b=d.additionalPropertiesDataType)==null?void 0:b.validateAsync({tracker:i})),v}function XUe(d){var m,v;const p=d.implements.flatMap(E=>tKe(d,E)),i=iKe(d,d.extends),n=nKe(d),s=rKe(d),c=jx(d);d.properties.forEach(E=>{E.validate()}),d.methods.flatMap(E=>E.validate()),d.abstractMethods.flatMap(E=>E.validate()),(m=d.allPropertiesImplement)==null||m.validate(),(v=d.additionalPropertiesDataType)==null||v.validate();const e=[...p,...i,...n,...s,...c];return Lt(d.errors,e)}function QUe(d,p){const i=p.properties.filter(c=>c.abstract),n=[];let s=[...d.properties];return i.forEach(c=>{const e=s.find(y=>!!y.implements.find(m=>m.id===c.id));e?s=s.filter(y=>y.id!==e.id):n.push(c)}),n}function eKe(d,p){const i=p.abstractMethods,n=[];let s=[...d.methods];return i.forEach(c=>{const e=s.find(y=>{var m;return((m=y.implements)==null?void 0:m.id)===c.id});e?s=s.filter(y=>y.id!==e.id):n.push(c)}),n}function tKe(d,p){const i=[];if(!p.abstract){const E=$t({id:d.id+"--"+he.ImplementingNonAbstractEntity,message:`Entity "${d.name}" with id "${d.id}" is implementing a non-abstract entity "${p.name}" with id "${p.id}"`,severity:pe.Error,code:he.ImplementingNonAbstractEntity,entity:d});return i.push(E.error),i}const n=p.properties.filter(E=>E.abstract),s=[];let c=[...d.properties];n.forEach(E=>{const b=c.find(w=>!!w.implements.find(P=>P.id===E.id));b?c=c.filter(w=>w.id!==b.id):s.push(E)}),s.length&&s.forEach(E=>{const b=$t({id:d.id+"--"+he.MissingPropertyImplementation+"--"+E.id,message:`Property "${E.name}" with id "${E.id}" of entity "${p.name}" with id "${p.id}" is not implemented when entity "${d.name}" with id "${d.id}" implements it`,severity:pe.Error,code:he.MissingPropertyImplementation,entity:d});i.push(b.error)});const e=[];let y=[...d.methods];p.abstractMethods.forEach(E=>{const b=y.find(w=>{var P;return((P=w.implements)==null?void 0:P.id)===E.id});b?y=y.filter(w=>w.id!==b.id):e.push(E)}),e.length&&e.forEach(E=>{const b=$t({id:d.id+"--"+he.MissingMethodImplementation+"--"+E.id,message:`Method "${E.name}" with id "${E.id}" of entity "${p.name}" with id "${p.id}" is not implemented when entity "${d.name}" with id "${d.id}" implements it`,severity:pe.Error,code:he.MissingMethodImplementation,entity:d});i.push(b.error)});const m=[];p.properties.forEach(E=>{const b=c.find(w=>w.name===E.name);b&&m.push([b,E])}),m.length&&m.forEach(([E])=>{const b=$t({id:d.id+"--"+Ie.PropertyOverwritesOtherSiblingWithSameName+"--"+E.id,message:`Property "${E.name}" with id "${E.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:pe.Error,code:Ie.PropertyOverwritesOtherSiblingWithSameName,entity:d});i.push(b.error)});const v=[];return p.methods.forEach(E=>{const b=y.find(w=>w.name===E.name);b&&v.push([b,E])}),v.length&&v.forEach(([E])=>{const b=$t({id:d.id+"--"+Ie.MethodOverwritesOtherSiblingWithSameName+"--"+E.id,message:`Method "${E.name}" with id "${E.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:pe.Error,code:Ie.MethodOverwritesOtherSiblingWithSameName,entity:d});i.push(b.error)}),i}function iKe(d,p){const i=[];if(!p)return i;const n=[];if(!d.abstract&&p.abstract){const c=$t({id:d.id+"--"+p.id+"--"+he.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:pe.Error,code:he.NonAbstractExtendingAbstractEntity,entity:d,firstRelationship:p});return i.push(c.error),i}if(d.abstract&&!p.abstract){const c=$t({id:d.id+"--"+p.id+"--"+he.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:pe.Error,code:he.AbstractExtendingNonAbstractEntity,entity:d,firstRelationship:p});return i.push(c.error),i}d.properties.forEach(c=>{const e=p.properties.find(y=>{var m;return y.name===c.name&&((m=c.extends)==null?void 0:m.id)!==y.id});c.implements.find(y=>y.id===(e==null?void 0:e.id))||e&&n.push(c)}),n.length&&n.forEach(c=>{const e=$t({id:d.id+"--"+Ie.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:pe.Error,code:Ie.PropertyOverwritesOtherSiblingWithSameName,entity:d});i.push(e.error)});const s=[];return d.methods.forEach(c=>{var y;const e=p.methods.find(m=>{var v;return m.name===c.name&&((v=c.extends)==null?void 0:v.id)!==m.id});((y=c.implements)==null?void 0:y.id)!==(e==null?void 0:e.id)&&e&&s.push(c)}),s.length&&s.forEach(c=>{const e=$t({id:d.id+"--"+Ie.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:pe.Error,code:Ie.MethodOverwritesOtherSiblingWithSameName,entity:d});i.push(e.error)}),i}function rKe(d){const p=[];if(!d.properties.length){const i=$t({id:d.id+"--"+he.NoProperties,message:"No properties implemented",severity:pe.Warning,code:he.NoProperties,entity:d});p.push(i.error)}return p}function nKe(d){const p=[];if(d.abstract){if(d.methods.length){const i=$t({id:d.id+"--"+he.AbstractEntityWithNonAbstractMethods,message:`Entity "${d.name}" with id "${d.id}" is marked as abstract but has non-abstract methods`,severity:pe.Error,code:he.AbstractEntityWithNonAbstractMethods,entity:d});p.push(i.error)}if(d.properties.some(i=>!i.abstract)){const i=$t({id:d.id+"--"+he.AbstractEntityWithNonAbstractProperties,message:`Entity "${d.name}" with id "${d.id}" is marked as abstract but has non-abstract properties`,severity:pe.Error,code:he.AbstractEntityWithNonAbstractProperties,entity:d});p.push(i.error),d.properties.forEach(n=>{if(!n.abstract){const s=$t({id:d.id+"--"+he.StaticEntityWithNonStaticProperties+"--"+n.id,message:`Property "${n.name}" with id "${n.id}" of entity "${d.name}" with id "${d.id}" is not marked as abstract but the entity is marked as abstract`,severity:pe.Error,code:he.StaticEntityWithNonStaticProperties,entity:d});p.push(s.error)}})}}else{if(d.abstractMethods.length){const i=$t({id:d.id+"--"+he.AbstractPropertyInNonAbstractEntity,message:`Entity "${d.name}" with id "${d.id}" is not marked as abstract but has abstract methods`,severity:pe.Error,code:he.AbstractPropertyInNonAbstractEntity,entity:d});p.push(i.error)}d.properties.some(i=>i.abstract)&&d.properties.forEach(i=>{if(i.abstract){const n=$t({id:d.id+"--"+he.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:pe.Error,code:he.AbstractPropertyInNonAbstractEntity,entity:d,firstRelationship:i});p.push(n.error)}})}return d.static&&d.properties.some(i=>!i.static)&&d.properties.forEach(i=>{if(!i.static){const n=$t({id:d.id+"--"+he.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:pe.Error,code:he.NonStaticPropertyInStaticEntity,entity:d,firstRelationship:i});p.push(n.error)}}),p}function dUi(d,p){const i=[],n=Zn(p);if(!p.abstract){const e=new Mi({id:d.id+"--"+p.id+"--"+he.ImplementingNonAbstractEntity,message:`Entity "${d.name}" with id "${d.id}" is implementing a non-abstract built-in entity "${p.name}" with id "${p.id}"`,severity:pe.Error,code:he.ImplementingNonAbstractEntity,entity:d,firstRelationship:p});i.push(e)}const s=d.implements.filter(e=>e.id!==p.id);if(d.abstract){const e=new Mi({id:d.id+"--"+p.id+"--"+he.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:pe.Error,code:he.AbstractEntityImplements,entity:d,firstRelationship:p});i.push(e)}if(d.static&&!p.static){const e=new Mi({id:d.id+"--"+p.id+"--"+he.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:pe.Error,code:he.StaticImplementingNonStaticEntity,entity:d,firstRelationship:p});i.push(e)}if(!d.static&&p.static){const e=new Mi({id:d.id+"--"+p.id+"--"+he.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:pe.Error,code:he.NonStaticImplementingStaticEntity,entity:d,firstRelationship:p});i.push(e)}return s.length&&s.forEach(e=>{if(e.type===o.BuiltInBaseEntity){const y=n.filter(m=>m.id!==e.id);y.length&&y.forEach(m=>{if(m.id!==e.id){const v=new Mi({id:d.id+"--"+m.id+"--"+e.id+"--"+he.ImplementsIncompatibleEntities,message:`Entity "${d.name}" with id "${d.id}" is implementing built-in entity "${m.name}" with id "${m.id}" but also implements entity "${e.name}" with id "${e.id}" which is incompatible`,severity:pe.Error,code:he.ImplementsIncompatibleEntities,entity:d,firstRelationship:m,secondRelationship:e});i.push(v)}})}else{Zn(e).forEach(E=>{const b=n.filter(w=>w.id!==E.id);b.length&&b.forEach(w=>{if(w.id!==E.id){const P=new Mi({id:d.id+"--"+w.id+"--"+E.id+"--"+he.ImplementsIncompatibleEntities,message:`Entity "${d.name}" with id "${d.id}" is implementing built-in entity "${w.name}" with id "${w.id}" but also implements entity "${E.name}" with id "${E.id}" which is incompatible`,severity:pe.Error,code:he.ImplementsIncompatibleEntities,entity:d,firstRelationship:w,secondRelationship:E});i.push(P)}})});const m=od(p.ownDeclaredProperties,e.ownDeclaredProperties,Ie.PropertyOverwritesOtherImplementedEntitysPropertyWithSameImplementation,Ie.PropertyOverwritesOtherImplementedEntitysPropertyWithSameName);i.push(...m.errors);const v=od(p.abstractMethods,[...e.abstractMethods,...e.methods],Ie.MethodOverwritesOtherImplementedEntitysMethodWithSameImplementation,Ie.MethodOverwritesOtherImplementedEntitysMethodWithSameName);i.push(...v.errors)}}),D(d.extends?Zn(d.extends):[]).forEach(e=>{if(!n.find(y=>y.id===e.id)){const y=new Mi({id:d.id+"--"+p.id+"--"+e.id+"--"+he.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:pe.Error,code:he.ExtendsIncompatibleEntities,entity:d,firstRelationship:p,secondRelationship:e});i.push(y)}}),i}function uUi(d,p,i=!1){var v,E;const n=[],s=Zn(p);if(!d.abstract&&p.abstract){const b=$t({id:d.id+"--"+p.id+"--"+he.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:pe.Error,code:he.NonAbstractExtendingAbstractEntity,entity:d,firstRelationship:p});n.push(b.error)}if(d.abstract&&!p.abstract){const b=$t({id:d.id+"--"+p.id+"--"+he.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:pe.Error,code:he.AbstractExtendingNonAbstractEntity,entity:d,firstRelationship:p});n.push(b.error)}if(!d.static&&p.static){const b=$t({id:d.id+"--"+p.id+"--"+he.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:pe.Error,code:he.NonStaticExtendingStaticEntity,entity:d,firstRelationship:p});n.push(b.error)}if(d.static&&!p.static){const b=$t({id:d.id+"--"+p.id+"--"+he.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:pe.Error,code:he.StaticExtendingNonStaticEntity,entity:d,firstRelationship:p});n.push(b.error)}if(!lf(p)){const b=$t({id:d.id+"--"+p.id+"--"+he.ExtendingNonInteractiveEntity,message:`Entity "${d.name}" with id "${d.id}" is extending an non-interactive entity "${p.name}" with id "${p.id}"`,severity:pe.Error,code:he.ExtendingNonInteractiveEntity,entity:d,firstRelationship:p});n.push(b.error)}if(d.extends&&((v=d.extends)==null?void 0:v.id)!==p.id)if(((E=d.extends)==null?void 0:E.type)===o.BuiltInBaseEntity){const b=s.filter(w=>{var P;return w.id!==((P=d.extends)==null?void 0:P.id)});b.length&&b.forEach(w=>{var P,$,L,U;if(w.id!==((P=d.extends)==null?void 0:P.id)){const K=$t({id:d.id+"--"+w.id+"--"+(($=d.extends)==null?void 0:$.id)+"--"+he.ExtendsIncompatibleEntities,message:`Entity "${d.name}" with id "${d.id}" is extending built-in entity "${w.name}" with id "${w.id}" but also extends entity "${(L=d.extends)==null?void 0:L.name}" with id "${(U=d.extends)==null?void 0:U.id}" which is incompatible`,severity:pe.Error,code:he.ExtendsIncompatibleEntities,entity:d,firstRelationship:w,secondRelationship:d.extends});n.push(K.error)}})}else{Zn(d.extends).forEach(K=>{const H=s.filter(X=>X.id!==K.id);H.length&&H.forEach(X=>{if(X.id!==K.id){const se=new Mi({id:d.id+"--"+X.id+"--"+K.id+"--"+he.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 "${K.name}" with id "${K.id}" which is incompatible`,severity:pe.Error,code:he.ImplementsIncompatibleEntities,entity:d,firstRelationship:X,secondRelationship:K});n.push(se)}})});const w=!!Zn(d.extends).find(K=>K.id===p.id);let P=[...d.extends.properties];w&&(P=P.filter(K=>!p.properties.find(H=>H.id===K.id||H.name===K.name||!!K.implements.find(X=>X.id===H.id))));let $=[...d.extends.methods];w&&($=$.filter(K=>!p.methods.find(H=>{var X;return H.id===K.id||H.name===K.name||H.id===((X=K.implements)==null?void 0:X.id)})));const L=od(p.ownDeclaredProperties,P,Ie.PropertyOverwritesOtherExtendedEntitysPropertyWithSameImplementation,Ie.PropertyOverwritesOtherExtendedEntitysPropertyWithSameName);n.push(...L.errors);const U=od(p.abstractMethods,$,Ie.MethodOverwritesOtherExtendedEntitysMethodWithSameImplementation,Ie.MethodOverwritesOtherExtendedEntitysMethodWithSameName);n.push(...U.errors)}i&&J.Logger.log("self.implements.length",d.implements.length),d.implements.length&&d.implements.forEach(b=>{if(b.type===o.BuiltInBaseEntity){const w=s.filter(P=>P.id!==b.id);w.length&&w.forEach(P=>{if(P.id!==b.id){const $=new Mi({id:d.id+"--"+P.id+"--"+b.id+"--"+he.ImplementsIncompatibleEntities,message:`Entity "${d.name}" with id "${d.id}" is implementing built-in entity "${P.name}" with id "${P.id}" but also implements entity "${b.name}" with id "${b.id}" which is incompatible`,severity:pe.Error,code:he.ImplementsIncompatibleEntities,entity:d,firstRelationship:P,secondRelationship:b});n.push($)}})}else{Zn(b).forEach(L=>{const U=s.filter(K=>K.id!==L.id);U.length&&U.forEach(K=>{if(K.id!==L.id){const H=new Mi({id:d.id+"--"+K.id+"--"+L.id+"--"+he.ImplementsIncompatibleEntities,message:`Entity "${d.name}" with id "${d.id}" is implementing built-in entity "${K.name}" with id "${K.id}" but also implements entity "${L.name}" with id "${L.id}" which is incompatible`,severity:pe.Error,code:he.ImplementsIncompatibleEntities,entity:d,firstRelationship:K,secondRelationship:L});n.push(H)}})});const P=od(p.ownDeclaredProperties,b.ownDeclaredProperties,Ie.PropertyOverwritesOtherImplementedEntitysPropertyWithSameImplementation,Ie.PropertyOverwritesOtherImplementedEntitysPropertyWithSameName);n.push(...P.errors);const $=od(p.abstractMethods,[...b.abstractMethods,...b.methods],Ie.MethodOverwritesOtherImplementedEntitysMethodWithSameImplementation,Ie.MethodOverwritesOtherImplementedEntitysMethodWithSameName);n.push(...$.errors)}});const e=od(d.ownDeclaredProperties,p.ownDeclaredProperties,Ie.PropertyOverwritesOtherSiblingWithSameImplementation,Ie.PropertyOverwritesOtherSiblingWithSameName);n.push(...e.errors);const y=od(p.methods,p.abstractMethods,Ie.MethodOverwritesOtherSiblingWithSameImplementation,Ie.MethodOverwritesOtherSiblingWithSameName);return n.push(...y.errors),D(d.extends?Zn(d.extends):[]).forEach(b=>{if(!s.find(w=>w.id===b.id)){const w=new Mi({id:d.id+"--"+p.id+"--"+b.id+"--"+he.ImplementsIncompatibleEntities,message:`Entity "${d.name}" with id "${d.id}" is extending built-in entity "${p.name}" with id "${p.id}" but also extends entity "${b.name}" with id "${b.id}" which is incompatible`,severity:pe.Error,code:he.ImplementsIncompatibleEntities,entity:d,firstRelationship:p,secondRelationship:b});n.push(w)}}),n}function pUi(d){const p=[];if(d.implements.forEach(i=>{if(!i.static){const n=new Mi({id:d.id+"--"+i.id+"--"+he.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:pe.Error,code:he.StaticImplementingNonStaticEntity,entity:d,firstRelationship:i});p.push(n)}}),d.extends&&!d.extends.static){const i=new Mi({id:d.id+"--"+d.extends.id+"--"+he.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:pe.Error,code:he.StaticExtendingNonStaticEntity,entity:d,firstRelationship:d.extends});p.push(i)}return p}function cUi(d){const p=[];if(d.implements.length){const i=new Mi({id:d.id+"--"+he.AbstractEntityImplements,message:`Entity "${d.name}" with id "${d.id}" cannot be marked as abstract because it implements other entities`,severity:pe.Error,code:he.AbstractEntityImplements,entity:d});p.push(i)}if(d.extends&&!d.extends.abstract){const i=new Mi({id:d.id+"--"+d.extends.id+"--"+he.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:pe.Error,code:he.AbstractExtendingNonAbstractEntity,entity:d,firstRelationship:d.extends});p.push(i)}return p}function fUi(d){const p=[];if(d.extends&&d.extends.static){const i=new Mi({id:d.id+"--"+d.extends.id+"--"+he.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:pe.Error,code:he.NonStaticExtendingStaticEntity,entity:d,firstRelationship:d.extends});p.push(i)}return p}function yUi(d){const p=[];if(d.extends&&d.extends.abstract){const i=new Mi({id:d.id+"--"+d.extends.id+"--"+he.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:pe.Error,code:he.NonAbstractExtendingAbstractEntity,entity:d,firstRelationship:d.extends});p.push(i)}return p}function jx(d,p){const n=[...d.project.entities].filter(s=>s.id!==d.id);return xv(d,[Ji,wc],n,p)}const hUi=Object.freeze(Object.defineProperty({__proto__:null,getBaseMethodsNotImplemented:eKe,getBasePropertiesNotImplemented:QUe,validate:XUe,validateAsync:YUe,validateCanBecomeAbstract:cUi,validateCanBecomeNonAbstract:yUi,validateCanBecomeNonStatic:fUi,validateCanBecomeStatic:pUi,validateCanExtendEntity:uUi,validateCanImplementEntity:dUi,validateDefinitionEntityName:jx},Symbol.toStringTag,{value:"Module"}));function mUi(d,p){const i=[];if(d.parent)if(d.id===d.parent)i.push(new De({id:`${d.id}--${d.parent}--${ne.SelfReference}`,code:ne.SelfReference,severity:pe.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 n=p.get(d.parent);n?[o.Project,o.DataType].includes(n.type)||i.push(new De({id:`${d.id}--${d.parent}--${ne.InvalidParentReference}`,code:ne.InvalidParentReference,severity:pe.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 De({id:`${d.id}--${d.parent}--${ne.ReferencedEntityNotFound}`,code:ne.ReferencedEntityNotFound,severity:pe.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(n=>{if(d.id===n){i.push(new De({id:`${d.id}--${n}--${ne.SelfReference}`,code:ne.SelfReference,severity:pe.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 s=p.get(n);s?[o.DefinitionEntity,o.BuiltInBaseEntity].includes(s.type)?s.abstract||i.push(new De({id:`${d.id}--${n}--${ne.InvalidImplementsReference}`,code:ne.InvalidImplementsReference,severity:pe.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 De({id:`${d.id}--${n}--${ne.InvalidImplementsReference}`,code:ne.InvalidImplementsReference,severity:pe.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 De({id:`${d.id}--${n}--${ne.ReferencedEntityNotFound}`,code:ne.ReferencedEntityNotFound,severity:pe.Error,message:`Entity of type "${d.type}" with id "${d.id}", is referencing an entity with id "${n}" that isn't yet found in the project. Perhaps it should be created first. Or perhaps the ID is incorrect.`}))}):i.push(new De({id:`${d.id}--${Ie.InvalidObjectStructure}`,code:Ie.InvalidObjectStructure,severity:pe.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(n=>{const s=p.get(n);s?[o.DefinitionEntity,o.BuiltInBaseEntity].includes(s.type)?s.abstract&&i.push(new De({id:`${d.id}--${n}--${ne.InvalidExtendsReference}`,code:ne.InvalidExtendsReference,severity:pe.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 De({id:`${d.id}--${n}--${ne.InvalidExtendsReference}`,code:ne.InvalidExtendsReference,severity:pe.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 De({id:`${d.id}--${n}--${ne.ReferencedEntityNotFound}`,code:ne.ReferencedEntityNotFound,severity:pe.Error,message:`Entity of type "${d.type}" with id "${d.id}", is referencing an entity with id "${n}" that isn't yet found in the project. Perhaps it should be created first. Or perhaps the ID is incorrect.`}))}),i}var IA=(d=>(d.Extends="extends",d.Implements="implements",d))(IA||{});const bi=class bi extends kr{constructor(i,n){super(i);I(this,"initialData");I(this,"id");I(this,"name");I(this,"codeName",null);I(this,"description",null);I(this,"x");I(this,"y");I(this,"static");I(this,"abstract");I(this,"type",o.DefinitionEntity);I(this,"additionalProperties",!1);I(this,"properties",[]);I(this,"allPropertiesImplement",null);I(this,"additionalPropertiesDataType",null);I(this,"methods",[]);I(this,"abstractMethods",[]);I(this,"extends",null);I(this,"implements",[]);I(this,"project");I(this,"errors",[]);I(this,"parent");I(this,"detachedDependents",{});I(this,"knownVersions",null);I(this,"activeVersion",!1);I(this,"initialized",!1);I(this,"startedInitialization",!1);I(this,"suggestedProperties",[]);I(this,"suggestedMethods",[]);this.initialData=i,this.project=n,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:x.UUID.uuid(),version:x.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||M().toISOString(),author:(i==null?void 0:i.author)||x.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,n){let s=n;if(i.parent){const v=re(i.parent);s=n.get(v)}const c=[];i.implements&&i.implements.forEach(v=>{c.push(n.get(v)||n.getBuiltIn(v))});let e=null;i.extends&&(e=n.get(i.extends)||n.getBuiltIn(i.extends));const y={id:i.id,version:x.UUID.uuid(),createdAt:M().toISOString(),author:x.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:s},m=ye(y,n);return m.setParent(s,null),m}static validateGenerationTarget(i,n){let s=JSON.parse(JSON.stringify(i));const c=[],e=mUi(s,n),y=Px(s,n);c.push(...e,...y,...Nr(s));const m=s.parent?n.get(s.parent):null;if(m&&m.type===o.DataType){const v=m;v.entity&&c.push(new De({id:`${i.id}--${ne.NewEntityWouldOverriteExisting}`,code:ne.NewEntityWouldOverriteExisting,severity:pe.Error,message:`The entity of type '${i.type}' with id '${i.id}' can't be added to the 'parent' entity with id '${v.id}' because it already has an 'entity' child. Data type entities can only have one 'entity' as children.