@elyx-code/project-logic-tree 0.0.6896 → 0.0.6897

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
@@ -531,7 +531,7 @@ Some of which might require an explicit 'parentRelationType' property to go alon
531
531
  The entities of type '${vt(_,"', '","' and '")}' can only have one 'data-type' child under the 'dataType' property so no 'parentRelationType' is needed.`})),m.dataType)){const P=(b=m.dataType)==null?void 0:b.id;e.push(new De({id:`${i.id}--${he.NewEntityWouldOverriteExisting}`,code:he.NewEntityWouldOverriteExisting,severity:Te.Error,message:`The entity with id '${i.id}' and type '${i.type}', cannot be added as a child to the entity with id '${a.parent}' and type '${A}', because it already has a 'data-type' child with id '${P}'.
532
532
  The entities of type '${vt(_,"', '","' 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:
533
533
  ${cp({describe_entity:P})}
534
- Alternatively you can update the entity with 'update' action. Or replace it by first removing it and then creating a new one.`}))}A===d.DataType&&(!a.parentRelationType||!(a.parentRelationType===ze.AndDataTypeGroup||a.parentRelationType===ze.OrDataTypeGroup))&&e.push(new De({id:`${i.id}--${he.InvalidParentRelationType}`,code:he.InvalidParentRelationType,severity:Te.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:e,explanations:c,modifiedData:a}}get isGroup(){const i=[...this.andChildrenGroup||[],...this.orChildrenGroup||[]];if(i.length>1){let r=0;for(const a of i)if(a.isResolved&&(r++,r>1))return!0}return!1}get isResolved(){return[d.BuiltInBaseEntity,d.ActionDescriptor].includes(this.parent.type)||du(this.parent)?!0:!(!this.entity&&!this.isGroup&&!this.foreignKeyRef&&!this.foreignKeyAllowed)}validateGeneratedUpdate(i){return{errors:[],explanations:[],modifiedData:i}}subscribeDependents(i){return i.forEach(r=>{this.detachedDependents[r.entity.id]||(this.detachedDependents[r.entity.id]=r)}),this}unsubscribeDependents(i){return i.forEach(r=>{this.detachedDependents[r.entity.id]&&delete this.detachedDependents[r.entity.id]}),this}syncDependents(i=this.project.addChangeSet(new S(this.project,x.sessionAuthor,B().toISOString(),this,!0,"sync-dependents"))){const r=[],a=[],c=[],e=[];return Object.values(this.detachedDependents).forEach(f=>{const h=f.entity.afterAllChildrenInitialized(i);r.push(...h.updated),a.push(...h.added),c.push(...h.removed),e.push(...h.affected)}),i==null||i.attemptAutoclose("sync-dependents",this.id),{updated:C(r),added:C(a),removed:C(c),affected:C(e),self:this}}onDetachedDependencyRemoved(i,r,a){const c=[],e=[],f=[],h=[];return r==="entity-field"&&this.setEntity(null,a),r==="foreign-key-ref-field"&&this.setForeignKeyRef(null,a),{updated:C(c),added:C(e),removed:C(f),affected:C(h),self:this}}onDetachedDependencyRestored(i,r,a){const c=[],e=[],f=[],h=[];return r==="entity-field"&&this.setEntity(i,a),r==="foreign-key-ref-field"&&this.setForeignKeyRef(i,a),{updated:C(c),added:C(e),removed:C(f),affected:C(h),self:this}}unsubscribeFromDependencies(){var i,r,a,c;return(r=(i=this.entity)==null?void 0:i.unsubscribeDependents)==null||r.call(i,[{entity:this,field:"entity-field"}]),(c=(a=this.foreignKeyRef)==null?void 0:a.unsubscribeDependents)==null||c.call(a,[{entity:this,field:"foreign-key-ref-field"}]),this}subscribeToDependencies(){var i,r,a,c;return(r=(i=this.entity)==null?void 0:i.subscribeDependents)==null||r.call(i,[{entity:this,field:"entity-field"}]),(c=(a=this.foreignKeyRef)==null?void 0:a.subscribeDependents)==null||c.call(a,[{entity:this,field:"foreign-key-ref-field"}]),this}increaseVersion(i){var r;if(this.project.diggestedBuiltInBaseEntitiesIds.has(this.id))return this;if(i&&!B(i).isValid())throw new Error(`The shared timestamp '${i}' is not a valid ISO 8601 date string.`);if(i&&B(i).isSame(B(this.createdAt)))return this;if(!((r=this.knownVersions)!=null&&r.has(this.version))&&this.project.initialized)throw new Error(`The current ${this.type} ${this.id} version '${this.version}' is not captured in the 'knownVersions' map. Capture the current version before increasing it to avoid losing data.`);if(!this.activeVersion)throw new Error(`Only active versions can be increased. Entity with id '${this.id}' and version '${this.version}' is not active.`);return this.previousVersion=this.version,this.version=x.UUID.uuid(),this.createdAt=B(i).toISOString()||B().toISOString(),this}captureVersion(){var r;const i=((r=this.knownVersions)==null?void 0:r.get(this.version))||new Vi(this,this.project);if(!this.activeVersion)throw new Error(`Only active versions can be captured. Entity of type ${this.type} with id '${this.id}' and version '${this.version}' is not active.`);if(this.version!==i.version)throw new Error(`Captured ${this.type} with id '${this.id}', version '${i.version}' does not match current entity version '${this.version}'.`);return this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,i):new Map().set(this.version,i),this.apply(i),this}snapshot(){const i=new Vi(this,this.project);return this.apply(i)}apply(i){const r=this.toMeta();return i.metaSync(r,null),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,i}recursiveCaptureUpstreamVersions(i){const r=[],a=[],c=[],e=[];if(this.parent&&this.parent.type!==d.BuiltInBaseEntity){this.parent.increaseVersion(i);const f=this.parent.recursiveCaptureUpstreamVersions(i);r.push(this.parent,...f.updated),a.push(...f.added),c.push(...f.removed)}return{updated:C(r),added:C(a),removed:C(c),affected:C(e),self:this}}async restoreVersion(i,r){var m;const a=[],c=[],e=[],f=[];if(this.version===i&&(r!=null&&r.skipIfSameVersion))return{updated:C(a),added:C(c),removed:C(e),affected:C(f),self:this};if(!this.knownVersions){const E=new Map;for(const[b,A]of this.knownVersions||new Map){if(E.set(b,A),A.activeVersion=!1,A.knownVersions)for(const[_,P]of A.knownVersions)E.set(_,P);A.knownVersions=null}}let h=(m=this.knownVersions)==null?void 0:m.get(i);if(!h){const E=await this.APILoadVersion({},i);if(!E)throw new Error(`Version with id '${i}' for entity with id '${this.id}' not found.`);h=new Vi(E,this.project)}return this.metaSync(h.toShallowJSON(),null),this.previousVersion=h.previousVersion,this.version=h.version,this.createdAt=h.createdAt,this.author=h.author,this.deleted=h.deleted,this.entity=h.entity,this.foreignKeyRef=h.foreignKeyRef,this.andChildrenGroup=h.andChildrenGroup?[...h.andChildrenGroup]:null,this.orChildrenGroup=h.orChildrenGroup?[...h.orChildrenGroup]:null,this.parent=h.parent,{updated:C(a),added:C(c),removed:C(e),affected:C(f),self:this}}updateWithShallowTransfer(i,r=this.project.addChangeSet(new S(this.project,x.sessionAuthor,B().toISOString(),this,!0,w.UpdateWithShallowTransfer))){var a,c;if(!this.checkCanEdit(this,r))return Y.Logger.warn(`[updateWithShallowTransfer] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),r==null||r.attemptAutoclose(w.UpdateWithShallowTransfer,this.id),this;if(this.metaSync(i,r),this.version=i.version,this.createdAt=i.createdAt,this.author=i.author,this.deleted=i.deleted,this.previousVersion=i.previousVersion,this.unsubscribeFromDependencies(),i.parent){const e=ie(i.parent),f=this.project.get(e),h=this.parent;if(h&&h.id!==(f==null?void 0:f.id)&&this.removeFromParent(r),f)this.setParent(f,r),this.addSelfToProject(r);else throw r==null||r.attemptAutoclose(w.UpdateWithShallowTransfer,this.id),new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${e}' that isn't found in the project`)}else throw r==null||r.attemptAutoclose(w.UpdateWithShallowTransfer,this.id),new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(i.entity){const e=ie(i.entity),f=this.project.get(e);f&&(this.setEntity(f,r),this.metaSync({inferred:!1},r))}else this.setEntity(null,r);if(i.foreignKeyRef){const e=ie(i.foreignKeyRef),f=this.project.get(e);f&&this.setForeignKeyRef(f,r)}else this.setForeignKeyRef(null,r);return(a=i.andChildrenGroup)==null||a.forEach(e=>{const f=ie(e),h=this.project.get(f);h&&(this.addToAndGroup(h,r),h.setParent(this,r))}),[...this.andChildrenGroup||[]].forEach(e=>{var h;((h=i.andChildrenGroup)==null?void 0:h.find(m=>ie(m)===e.id))||(this.removeChildGroup(e,r),e.removeFromParent(r))}),(c=i.orChildrenGroup)==null||c.forEach(e=>{const f=ie(e),h=this.project.get(f);h&&(this.addToOrGroup(h,r),h.setParent(this,r))}),[...this.orChildrenGroup||[]].forEach(e=>{var h;((h=i.orChildrenGroup)==null?void 0:h.find(m=>ie(m)===e.id))||(this.removeChildGroup(e,r),e.removeFromParent(r))}),this.captureVersion(),this.subscribeToDependencies(),r==null||r.attemptAutoclose(w.UpdateWithShallowTransfer,this.id),this}updateWithGenerationTarget(i,r=this.project.addChangeSet(new S(this.project,x.sessionAuthor,B().toISOString(),this,!0,w.UpdateWithGenerationTarget))){if(!this.checkCanEdit(this,r))return Y.Logger.warn(`[updateWithGenerationTarget] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),r==null||r.attemptAutoclose(w.UpdateWithGenerationTarget,this.id),this;if(this.metaSync(i,r),i.parent){const a=ie(i.parent),c=this.project.get(a),e=this.parent;if(e&&e.id!==(c==null?void 0:c.id)&&this.removeFromParent(r),c)this.setParent(c,r),this.addSelfToProject(r);else throw r==null||r.attemptAutoclose(w.UpdateWithGenerationTarget,this.id),new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${a}' that isn't found in the project`)}if(i.entity){const a=ie(i.entity),c=this.project.get(a);if(c)this.setEntity(c,r),this.metaSync({inferred:!1},r);else throw new Error(`${this.type} with id '${this.id}' has an 'entity' reference '${a}' that isn't found in the project`)}else i.entity==null&&this.setEntity(null,r);if(i.foreignKeyRef){const a=ie(i.foreignKeyRef),c=this.project.get(a);if(c)this.setForeignKeyRef(c,r);else throw new Error(`${this.type} with id '${this.id}' has a 'foreignKeyRef' reference '${a}' that isn't found in the project`)}else i.foreignKeyRef==null&&this.setForeignKeyRef(null,r);return this.captureVersion(),this.subscribeToDependencies(),r==null||r.attemptAutoclose(w.UpdateWithGenerationTarget,this.id),this}hydrateAncestors(){const i=[],r=[],a=[],c=[];if(this.initialData.parent){const e=ie(this.initialData.parent),f=this.project.get(e);if(f)this.setParent(f,null),i.push(f);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${e}' that isn't found in the project`)}else throw new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(this.initialData.entity){const e=ie(this.initialData.entity),f=this.project.get(e);f&&(f.type===d.DefinitionEntity&&f.parent===this||(this.setEntity(f,null),f.type!==d.BuiltInBaseEntity&&f.type!==d.PrimitiveEntity&&i.push(f)))}if(this.initialData.foreignKeyRef){const e=ie(this.initialData.foreignKeyRef),f=this.project.get(e);f&&this.setForeignKeyRef(f,null)}return{updated:C(i),added:C(r),removed:C(a),affected:C(c),self:this}}afterAllChildrenInitialized(i=this.project.addChangeSet(new S(this.project,x.sessionAuthor,B().toISOString(),this,!0,w.AfterAllChildrenInitialized))){var f,h,m,E,b;if(!this.checkCanEdit(this,i))return Y.Logger.warn(`[afterAllChildrenInitialized] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(w.AfterAllChildrenInitialized,this.id),{updated:[],added:[],removed:[],affected:[],self:this};const r=[],a=[],c=[],e=[];if(this.initialized=!0,((f=this.parent)==null?void 0:f.type)===d.DataType){let A=this.index||0;const _=(this.parentRelationType===ze.AndDataTypeGroup?this.parent.andChildrenGroup||[]:this.parent.orChildrenGroup||[]).filter(V=>!V.deleted&&V.id!==this.id);_.length&&(A>_.length+1?A=_.length:A<0&&(A=0)),_.find(V=>(V.index||0)===A&&!V.deleted)&&_.filter(V=>(V.index||0)>=A&&!V.deleted).forEach(V=>{V.metaSync({index:(V.index||0)+1},i),i==null||i.add(V,W.Updated),r.push(V)}),this.metaSync({index:A},i)}return(h=this.andChildrenGroup)!=null&&h.length&&this.andChildrenGroup.sort((A,_)=>(A.index||0)-(_.index||0)),(m=this.orChildrenGroup)!=null&&m.length&&this.orChildrenGroup.sort((A,_)=>(A.index||0)-(_.index||0)),this.entity&&this.entity.type===d.DefinitionEntity&&((E=this.entity.parent)==null?void 0:E.id)!==this.id&&this.metaSync({inferred:!1},i),this.bestEffortClearIncompatibleProperties(i),this.entity&&this.entity.type===d.DefinitionEntity&&((b=this.entity.parent)==null?void 0:b.id)===this.id&&this.entity.afterAllChildrenInitialized(i),i==null||i.attemptAutoclose(w.AfterAllChildrenInitialized,this.id),{updated:C(r),added:C(a),removed:C(c),affected:C(e),self:this}}addSelfToProject(i=this.project.addChangeSet(new S(this.project,x.sessionAuthor,B().toISOString(),this,!0,"add-self-to-project"))){const r=[this],a=[],c=[],e=[];return this.parent.type===d.DataType?(this.parentRelationType===ze.AndDataTypeGroup?this.parent.addToAndGroup(this,i):this.parentRelationType===ze.OrDataTypeGroup&&this.parent.addToOrGroup(this,i),e.push(this.parent)):this.parent.type===d.DefinitionEntity?(this.parent.setAdditionalPropertiesDataType(this,i),e.push(this.parent)):this.parent.type!==d.BuiltInBaseEntity&&this.parent.setDataType(this,i),this.subscribe(),this.subscribeToDependencies(),i==null||i.attemptAutoclose("add-self-to-project",this.id),{updated:C(r),added:C(a),removed:C(c),affected:C(e),self:this}}setParent(i,r=this.project.addChangeSet(new S(this.project,x.sessionAuthor,B().toISOString(),this,!0,w.SetParent))){var a;return this.checkCanEditWithCounterpartAndSideEffects(this,i,w.SetParent,r)?(((a=this.parent)==null?void 0:a.id)!==(i==null?void 0:i.id)&&(this.parent=i,r&&(r==null||r.add(this,W.Updated))),r==null||r.attemptAutoclose(w.SetParent,this.id),this):this}removeChildGroup(i,r=this.project.addChangeSet(new S(this.project,x.sessionAuthor,B().toISOString(),this,!0,w.RemoveChildGroup))){if(!this.checkCanEdit(this,r))return Y.Logger.warn(`[removeChildGroup] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),r==null||r.attemptAutoclose(w.RemoveChildGroup,this.id),this;if(this.andChildrenGroup){const a=this.andChildrenGroup.findIndex(c=>c.id===i.id);a!==-1&&(this.andChildrenGroup.splice(a,1),r==null||r.add(this,W.Updated))}if(this.orChildrenGroup){const a=this.orChildrenGroup.findIndex(c=>c.id===i.id);a!==-1&&(this.orChildrenGroup.splice(a,1),r==null||r.add(this,W.Updated))}return r==null||r.attemptAutoclose(w.RemoveChildGroup,this.id),this}initChildren(i=this.project.addChangeSet(new S(this.project,x.sessionAuthor,B().toISOString(),this,!0,"init-children"))){var r,a,c,e,f,h,m,E,b,A;if(this.initialized||this.startedInitialization)return this;if(this.startedInitialization=!0,this.initialData.entity)if(this.initialData.entity.type===d.GenericReference){const _=this.project.findSubscribedInstanceFromReference(this.initialData.entity);this.entity=_}else this.entity=ge(this.initialData.entity,this.project),(((a=(r=this.initialData.entity)==null?void 0:r.parent)==null?void 0:a.id)===this.id||((e=(c=this.initialData.entity)==null?void 0:c.parent)==null?void 0:e.type)===d.GenericReference&&((h=(f=this.initialData.entity)==null?void 0:f.parent)==null?void 0:h.entityId)==this.id)&&this.entity.setParent(this,null),(E=(m=this.entity).initChildren)==null||E.call(m,i);if(this.initialData.foreignKeyRef)if(this.initialData.foreignKeyRef.type===d.GenericReference){const _=this.project.findSubscribedInstanceFromReference(this.initialData.foreignKeyRef);this.foreignKeyRef=_}else this.foreignKeyRef=ge(this.initialData.foreignKeyRef,this.project),(A=(b=this.foreignKeyRef).initChildren)==null||A.call(b,i);return this.initialData.andChildrenGroup&&(this.andChildrenGroup=this.initialData.andChildrenGroup.map(_=>{const P=ge(_,this.project);return P.setParent(this,null),P.initChildren(i),P})),this.initialData.orChildrenGroup&&(this.orChildrenGroup=this.initialData.orChildrenGroup.map(_=>{const P=ge(_,this.project);return P.setParent(this,null),P.initChildren(i),P})),this.subscribeToDependencies(),this.afterAllChildrenInitialized(i),i==null||i.attemptAutoclose("init-children",this.id),this}subscribe(){var i;return this.activeVersion=!0,(i=this.knownVersions)==null||i.forEach(r=>{r.version!==this.version&&(r.activeVersion=!1)}),this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(i,r=this.project.addChangeSet(new S(this.project,x.sessionAuthor,B().toISOString(),this,!0,"meta-sync"))){const a=en(this,i,r),c=Xr(this,a),e=this.toMeta();return this.options=a.options||e.options,this.parentRelationType=a.parentRelationType||e.parentRelationType,this.isList=a.isList!==void 0?a.isList:e.isList,this.inferred=a.inferred!==void 0?a.inferred:e.inferred,this.like=a.like!==void 0?a.like:e.like,this.asType=a.asType!==void 0?a.asType:e.asType,this.index=a.index!==void 0?a.index:e.index,this.implementationChooseOne=a.implementationChooseOne!==void 0?a.implementationChooseOne:e.implementationChooseOne,this.staticEntities=a.staticEntities!==void 0?a.staticEntities:e.staticEntities,this.interactiveEntities=a.interactiveEntities!==void 0?a.interactiveEntities:e.interactiveEntities,this.actionEntities=a.actionEntities!==void 0?a.actionEntities:e.actionEntities,super.baseMetaSync(a,this,r),a.deleted===!0&&!e.deleted?r==null||r.add(this,W.Removed):a.deleted===!1&&e.deleted?r==null||r.add(this,W.Added):c&&(r==null||r.add(this,W.Updated)),r==null||r.attemptAutoclose("meta-sync",this.id),this}async APILoad(i=Ke,...r){return await Vi.repository.APILoad(this.id,...r),this}async APICreate(i=Ke,...r){return await Vi.repository.APICreate(this.toShallowJSON(),...r),this}async APIUpdate(i=Ke,...r){return await Vi.repository.APIUpdate(this.toShallowJSON(),...r),this}async APIDelete(i=Ke,...r){return await Vi.repository.APIDelete(this.toShallowJSON(),...r),this}async APIClone(i=Ke,...r){return await Vi.repository.APIClone(this.id,...r),this}async APILoadVersion(i=Ke,r,...a){return await Vi.repository.APILoadVersion(this.id,r,...a)}removeFromParent(i=this.project.addChangeSet(new S(this.project,x.sessionAuthor,B().toISOString(),this,!0,w.RemoveFromParent))){var f,h;if(!this.checkCanEdit(this,i))return Y.Logger.warn(`[removeFromParent] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(w.RemoveFromParent,this.id),{added:[],updated:[],removed:[],affected:[],self:this};const r=[],a=[],c=[],e=[];if(((f=this.parent)==null?void 0:f.type)===d.DataType)this.parent.removeChildGroup(this,i);else if(((h=this.parent)==null?void 0:h.type)===d.DefinitionEntity)this.parent.removeAdditionalPropertiesDataType(i);else{const m=this.parent;m==null||m.removeDataType(i)}return this.parent&&this.parent.type!==d.BuiltInBaseEntity&&r.push(this.parent),i==null||i.attemptAutoclose(w.RemoveFromParent,this.id),{added:C(c),updated:C(r),removed:C(a),affected:C(e),self:this}}remove({ignoreUpstream:i}={ignoreUpstream:!1},r=this.project.addChangeSet(new S(this.project,x.sessionAuthor,B().toISOString(),this,!0,w.RemoveEntity))){const a=[],c=[],e=[],f=[];if(r!=null&&r.hasRemoved(this.id))return r==null||r.attemptAutoclose(w.RemoveEntity,this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(c.push(this),this.unsubscribe(),this.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},r),Object.values(this.detachedDependents).forEach(h=>{const{updated:m,removed:E,added:b}=h.entity.onDetachedDependencyRemoved(this,h.field,r);a.push(...m),c.push(...E),e.push(...b)}),this.entity&&this.entity.type===d.DefinitionEntity&&this.entity.parent===this){const{updated:h,removed:m}=this.entity.remove({ignoreUpstream:!0},r);a.push(...h),c.push(...m)}if(this.andChildrenGroup&&this.andChildrenGroup.forEach(h=>{const{removed:m,updated:E}=h.remove({ignoreUpstream:!0},r);c.push(...m),a.push(...E)}),this.orChildrenGroup&&this.orChildrenGroup.forEach(h=>{const{removed:m,updated:E}=h.remove({ignoreUpstream:!0},r);c.push(...m),a.push(...E)}),!i){const h=this.removeFromParent(r);e.push(...h.added),a.push(...h.updated),c.push(...h.removed),f.push(...h.affected)}return r==null||r.attemptAutoclose(w.RemoveEntity,this.id),{added:C(e),updated:C(a),removed:C(c),affected:C(f),self:this}}restore({}={},i=this.project.addChangeSet(new S(this.project,x.sessionAuthor,B().toISOString(),this,!0,w.RestoreEntity))){if(!this.checkCanEdit(this,i))return Y.Logger.warn(`[restore] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(w.RestoreEntity,this.id),{added:[],updated:[],removed:[],affected:[],self:this};const r=[],a=[],c=[],e=[];if(i!=null&&i.hasAdded(this.id))return i==null||i.attemptAutoclose(w.RestoreEntity,this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},i),Object.values(this.detachedDependents).forEach(f=>{const{updated:h,removed:m,added:E}=f.entity.onDetachedDependencyRestored(this,f.field,i);a.push(...h),c.push(...m),r.push(...E)}),this.entity&&this.entity.type===d.DefinitionEntity&&this.entity.parent===this){const{updated:f}=this.entity.restore({},i);a.push(...f)}if(this.andChildrenGroup&&this.andChildrenGroup.forEach(f=>{const{updated:h,added:m}=f.restore({},i);a.push(...h),r.push(...m)}),this.orChildrenGroup&&this.orChildrenGroup.forEach(f=>{const{updated:h,added:m}=f.restore({},i);a.push(...h),r.push(...m)}),this.parent.type===d.DataType){const f=this.parent;Array.isArray(f.andChildrenGroup)&&f.andChildrenGroup.push(this)}if(this.parent.type===d.DataType){const f=this.parent;this.parentRelationType===ze.AndDataTypeGroup?Array.isArray(f.andChildrenGroup)&&f.andChildrenGroup.push(this):this.parentRelationType===ze.OrDataTypeGroup&&Array.isArray(f.orChildrenGroup)&&f.orChildrenGroup.push(this)}else if(this.parent.type===d.DefinitionEntity){const f=this.parent;f.setAdditionalPropertiesDataType(this,i),a.push(f)}else{const f=this.parent;f.setDataType(this,i),a.push(f)}return i==null||i.attemptAutoclose(w.RestoreEntity,this.id),{added:C(r),updated:C(a),removed:C(c),affected:C(e),self:this}}toFlat(i=new Set){var a,c,e,f;return i.has(this.id)?[]:(i.add(this.id),[this,...((a=this.andChildrenGroup)==null?void 0:a.flatMap(h=>h.toFlat(i)))||[],...((c=this.orChildrenGroup)==null?void 0:c.flatMap(h=>h.toFlat(i)))||[],...((e=this.entity)==null?void 0:e.toFlat(i))||[],...((f=this.foreignKeyRef)==null?void 0:f.toFlat(i))||[]])}toFlatIds(i=new Set){var a,c,e,f;return i.has(this.id)?[]:(i.add(this.id),[this.id,...((a=this.andChildrenGroup)==null?void 0:a.flatMap(h=>h.toFlatIds(i)))||[],...((c=this.orChildrenGroup)==null?void 0:c.flatMap(h=>h.toFlatIds(i)))||[],...((e=this.entity)==null?void 0:e.toFlatIds(i))||[],...((f=this.foreignKeyRef)==null?void 0:f.toFlatIds(i))||[]])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,like:this.like,isList:this.isList,inferred:this.inferred,index:this.index,foreignKeyAllowed:this.foreignKeyAllowed,parentRelationType:this.parentRelationType,implementationChooseOne:this.implementationChooseOne,staticEntities:this.staticEntities,interactiveEntities:this.interactiveEntities,actionEntities:this.actionEntities,options:this.options,asType:this.asType,type:this.type,editable:this.editable,deletable:this.deletable}}toJSON(i=new Set){var r,a,c,e,f;return i.has(this.id)?this.toReference():(i.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,editable:this.editable,deletable:this.deletable,options:this.options,isList:this.isList,asType:this.asType,index:this.index,like:this.like,foreignKeyAllowed:this.foreignKeyAllowed,inferred:this.inferred,parentRelationType:this.parentRelationType,implementationChooseOne:this.implementationChooseOne,staticEntities:this.staticEntities,interactiveEntities:this.interactiveEntities,actionEntities:this.actionEntities,foreignKeyRef:((r=this.foreignKeyRef)==null?void 0:r.toJSON(i))||null,andChildrenGroup:((a=this.andChildrenGroup)==null?void 0:a.map(h=>h.toJSON(i)))||null,orChildrenGroup:((c=this.orChildrenGroup)==null?void 0:c.map(h=>h.toJSON(i)))||null,entity:((e=this.entity)==null?void 0:e.parent)===this?this.entity.toJSON(i):((f=this.entity)==null?void 0:f.toReference())||null,parent:this.parent.toReference()})}toJSONClone(i=at){var a,c,e,f,h,m,E,b,A,_;let r;return(a=i.seenEntityMaps)!=null&&a.has(this.id)?r=i.seenEntityMaps.get(this.id):(r=i.newId||on(this,this.project,i.uuidStrategy),i.seenEntityMaps&&i.seenEntityMaps.set(this.id,r)),(c=i.seenEntities)!=null&&c.has(r)||(e=i.seenEntities)!=null&&e.has(this.id)?this.toReference({seenEntityMaps:i.seenEntityMaps}):((f=i.seenEntities)==null||f.add(r),(h=i.seenEntities)==null||h.add(this.id),{id:r,version:x.UUID.uuid(),createdAt:i.timestamp||B().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,editable:this.editable,deletable:this.deletable,options:this.options,isList:this.isList,asType:this.asType,like:this.like,index:this.index,inferred:this.inferred,foreignKeyAllowed:this.foreignKeyAllowed,parentRelationType:this.parentRelationType,implementationChooseOne:this.implementationChooseOne,staticEntities:this.staticEntities,interactiveEntities:this.interactiveEntities,actionEntities:this.actionEntities,foreignKeyRef:((m=this.foreignKeyRef)==null?void 0:m.toJSONClone({...i,newId:null}))||null,andChildrenGroup:((E=this.andChildrenGroup)==null?void 0:E.map(P=>P.toJSONClone({...i,newId:null})))||null,orChildrenGroup:((b=this.orChildrenGroup)==null?void 0:b.map(P=>P.toJSONClone({...i,newId:null})))||null,entity:((A=this.entity)==null?void 0:A.parent)===this?this.entity.toJSONClone({...i,newId:null}):((_=this.entity)==null?void 0:_.toReference({seenEntityMaps:i.seenEntityMaps}))||null,parent:this.parent.toReference({seenEntityMaps:i.seenEntityMaps})})}toReference(i=at){var a;let r=this.id;return(a=i.seenEntityMaps)!=null&&a.has(this.id)&&(r=i.seenEntityMaps.get(this.id)),{id:r+"--"+x.UUID.uuid()+"--ref",type:d.GenericReference,entityId:r,version:this.version,entityType:this.type}}toShallowJSON(i=at){var a,c,e,f,h;let r=this.id;return(a=i.seenEntityMaps)!=null&&a.has(this.id)&&(r=i.seenEntityMaps.get(this.id)),{id:r,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,editable:this.editable,deletable:this.deletable,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(m=>m.toReference(i)))||null,orChildrenGroup:((f=this.orChildrenGroup)==null?void 0:f.map(m=>m.toReference(i)))||null,entity:((h=this.entity)==null?void 0:h.toReference(i))||null,parent:this.parent.toReference(i)}}toFlatJSON(i=new Set){var a,c,e;return i.has(this.id)?[]:(i.add(this.id),[this.toShallowJSON(),...((a=this.andChildrenGroup)==null?void 0:a.flatMap(f=>f.toFlatJSON(i)))||[],...((c=this.orChildrenGroup)==null?void 0:c.flatMap(f=>f.toFlatJSON(i)))||[],...((e=this.entity)==null?void 0:e.toFlatJSON(i))||[]])}toGenerationTarget(i=at){var a,c,e;let r=this.id;return(a=i.seenEntityMaps)!=null&&a.has(this.id)&&(r=i.seenEntityMaps.get(this.id)),{id:r,type:this.type,options:this.options||void 0,isList:this.isList,like:this.like,parentRelationType:this.parentRelationType||void 0,foreignKeyRef:((c=this.foreignKeyRef)==null?void 0:c.id)||null,asType:this.asType,entity:((e=this.entity)==null?void 0:e.id)||null,parent:this.parent.id}}toFlatGenerationTarget(i=new Set){var a,c;return i.has(this.id)?[]:(i.add(this.id),[this.toGenerationTarget(),...((a=this.andChildrenGroup)==null?void 0:a.flatMap(e=>e.toFlatGenerationTarget(i)))||[],...((c=this.orChildrenGroup)==null?void 0:c.flatMap(e=>e.toFlatGenerationTarget(i)))||[],...this.entity&&this.entity.type==d.DefinitionEntity&&this.entity.parent===this&&this.entity.toFlatGenerationTarget(i)||[]])}clearErrors(){var i,r,a,c;return this.errors=[],(i=this.andChildrenGroup)==null||i.forEach(e=>e.clearErrors()),(r=this.orChildrenGroup)==null||r.forEach(e=>e.clearErrors()),this.inferred&&this.entity&&this.entity.type===d.DefinitionEntity&&((a=this.entity)==null?void 0:a.parent)===this&&((c=this.entity)==null||c.clearErrors()),this}validate(){return this.errors=Gke(this),{success:!0}}async validateAsync(i={}){const r=Y.YieldTracker.from(i);return this.errors=await Mke(this,{tracker:r}),{success:!0}}getErrors(){var r,a;return[...this.errors,...((r=this.andChildrenGroup)==null?void 0:r.flatMap(c=>c.getErrors()))||[],...((a=this.orChildrenGroup)==null?void 0:a.flatMap(c=>c.getErrors()))||[]]}async getErrorsAsync(i={}){const r=Y.YieldTracker.from(i),a=[...this.errors];await r.tick();for(const c of this.andChildrenGroup||[]){const e=await c.getErrorsAsync({tracker:r});a.push(...e)}for(const c of this.orChildrenGroup||[]){const e=await c.getErrorsAsync({tracker:r});a.push(...e)}return a}getShallowErrors(){return this.errors}clone(i=this.project.addChangeSet(new S(this.project,x.sessionAuthor,B().toISOString(),this,!0,w.CloneEntity)),r=null,a=null,c=!0){var _,P,V,j;const e=Ur(r,this),f=r||this.parent,m={id:a||x.UUID.uuid(),version:x.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||B().toISOString(),author:(i==null?void 0:i.author)||"1",previousVersion:null,deleted:!1,deletable:!0,editable:!0,type:d.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:((_=this.foreignKeyRef)==null?void 0:_.toReference())||null,andChildrenGroup:null,orChildrenGroup:null,entity:null,parent:f.toReference()},E=nr(m,e);E.hydrateAncestors(),E.setParent(f,null),c&&(E.subscribe(),E.addSelfToProject(i)),E.initChildren(i),i==null||i.add(E,W.Added);const b=(P=this.andChildrenGroup)==null?void 0:P.map(M=>this.project.diggestedBuiltInBaseEntitiesIds.has(M.id)?e.getBuiltIn(M.id):M.clone(i,E,x.UUID.uuid(),c)),A=(V=this.orChildrenGroup)==null?void 0:V.map(M=>this.project.diggestedBuiltInBaseEntitiesIds.has(M.id)?e.getBuiltIn(M.id):M.clone(i,E,x.UUID.uuid(),c));if(E.andChildrenGroup=b||null,E.orChildrenGroup=A||null,this.entity&&this.entity.type===d.DefinitionEntity&&((j=this.entity)==null?void 0:j.parent)===this)if(this.project.diggestedBuiltInBaseEntitiesIds.has(this.entity.id))E.setEntity(this.entity,i);else{const M=this.entity.clone(i,E,x.UUID.uuid(),c);E.setEntity(M,i)}else if(this.entity){const M=e.get(this.entity.id)||e.getBuiltIn(this.entity.id);E.setEntity(M,i)}return i||E.captureVersion(),i==null||i.attemptAutoclose(w.CloneEntity,this.id),E}merge(i,r=this.project.addChangeSet(new S(this.project,x.sessionAuthor,B().toISOString(),this,!0,w.MergeDataTypes)),a){var b,A,_,P,V,j,M;const c=[],e=[],f=[],h=[],m={implementSource:!1,...a};if(!this.checkCanEdit(this,r))return Y.Logger.warn(`[${w.MergeDataTypes}] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),r==null||r.attemptAutoclose(w.MergeDataTypes,this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.asType!==(i==null?void 0:i.asType)&&(m.implementSource?(i==null?void 0:i.asType)!==null&&this.metaSync({asType:i==null?void 0:i.asType},r):this.metaSync({asType:i==null?void 0:i.asType},r),c.push(this)),this.index!==(i==null?void 0:i.index)&&!m.implementSource&&(this.metaSync({index:i==null?void 0:i.index},r),r==null||r.add(this,W.Updated),c.push(this)),this.options&&!(i!=null&&i.options)||!this.options&&(i!=null&&i.options)||!((b=i==null?void 0:i.options)!=null&&b.every(G=>{var q;return(q=this.options)==null?void 0:q.includes(G)}))){if(m.implementSource){if(((A=i==null?void 0:i.entity)==null?void 0:A.id)===ne["primitive-entity"].enum.id){const G=new Set(this.options||[]);((i==null?void 0:i.options)||[]).forEach(q=>G.add(q)),this.metaSync({options:Array.from(G)},r)}}else this.metaSync({options:i==null?void 0:i.options},r);r==null||r.add(this,W.Updated),c.push(this)}if(this.foreignKeyAllowed!==(i==null?void 0:i.foreignKeyAllowed)&&(m.implementSource?(i==null?void 0:i.foreignKeyAllowed)!==null&&(this.metaSync({foreignKeyAllowed:i==null?void 0:i.foreignKeyAllowed},r),c.push(this)):(this.metaSync({foreignKeyAllowed:i==null?void 0:i.foreignKeyAllowed},r),c.push(this))),this.isList!==(i==null?void 0:i.isList)&&(m.implementSource?(i==null?void 0:i.isList)!==null&&(this.metaSync({isList:i==null?void 0:i.isList},r),c.push(this)):(this.metaSync({isList:i==null?void 0:i.isList},r),c.push(this))),this.like!==(i==null?void 0:i.like)&&(m.implementSource?(i==null?void 0:i.like)!==null&&(this.metaSync({like:i==null?void 0:i.like},r),c.push(this)):(this.metaSync({like:i==null?void 0:i.like},r),c.push(this))),((_=i==null?void 0:i.foreignKeyRef)==null?void 0:_.id)!==((P=this.foreignKeyRef)==null?void 0:P.id)&&(m.implementSource&&this.foreignKeyRef?di(this,i).compatible||(this.setForeignKeyRef((i==null?void 0:i.foreignKeyRef)||null,r),r==null||r.add(this,W.Updated),c.push(this),[...this.andChildrenGroup||[],...this.orChildrenGroup||[]].forEach(q=>{this.removeChildGroup(q,r),f.push(q)}),this.setEntity(null,r)):(this.setForeignKeyRef((i==null?void 0:i.foreignKeyRef)||null,r),r==null||r.add(this,W.Updated),c.push(this),[...this.andChildrenGroup||[],...this.orChildrenGroup||[]].forEach(G=>{this.removeChildGroup(G,r),f.push(G)}),this.setEntity(null,r))),i!=null&&i.entity&&(i==null?void 0:i.entity.type)===d.DefinitionEntity&&(i==null?void 0:i.entity).parent===i)if(((V=this.entity)==null?void 0:V.type)===d.DefinitionEntity&&this.entity.parent===this)XT(this.entity,i.entity)||(Rx(this.entity,i.entity,r),c.push(this.entity),[...this.andChildrenGroup||[],...this.orChildrenGroup||[]].forEach(G=>{this.removeChildGroup(G,r),f.push(G)}),this.andChildrenGroup=null,this.orChildrenGroup=null,this.setForeignKeyRef(null,r));else{const G=i.entity.clone(r,this,x.UUID.uuid(),!0);this.setEntity(G,r),e.push(G),[...this.andChildrenGroup||[],...this.orChildrenGroup||[]].forEach(q=>{this.removeChildGroup(q,r),f.push(q)}),this.andChildrenGroup=null,this.orChildrenGroup=null,this.setForeignKeyRef(null,r)}else((j=i==null?void 0:i.entity)==null?void 0:j.id)!==((M=this.entity)==null?void 0:M.id)&&(m.implementSource&&this.entity?di(this,i).compatible||(this.setEntity((i==null?void 0:i.entity)||null,r),r==null||r.add(this,W.Updated),c.push(this),[...this.andChildrenGroup||[],...this.orChildrenGroup||[]].forEach(q=>{this.removeChildGroup(q,r),f.push(q)}),this.andChildrenGroup=null,this.orChildrenGroup=null,this.setForeignKeyRef(null,r)):(this.setEntity((i==null?void 0:i.entity)||null,r),r==null||r.add(this,W.Updated),c.push(this),[...this.andChildrenGroup||[],...this.orChildrenGroup||[]].forEach(G=>{this.removeChildGroup(G,r),f.push(G)}),this.andChildrenGroup=null,this.orChildrenGroup=null,this.setForeignKeyRef(null,r)));this.inferred!==(i==null?void 0:i.inferred)&&(m.implementSource?(i==null?void 0:i.inferred)!==null&&(this.metaSync({inferred:(i==null?void 0:i.inferred)??!1},r),c.push(this)):(this.metaSync({inferred:(i==null?void 0:i.inferred)??!1},r),c.push(this)));const E=di(this,i);if(m.implementSource&&E.compatible&&(this.entity||this.foreignKeyRef))return r==null||r.attemptAutoclose(w.MergeDataTypes,this.id),{added:C(e),updated:C(c),removed:C(f),affected:C(h),self:this};if(i!=null&&i.orChildrenGroup&&Array.isArray(i==null?void 0:i.orChildrenGroup)&&!this.entity){let G=!1;if(m.implementSource&&i!=null&&i.implementationChooseOne&&(this.metaSync({implementationChooseOne:!1},r),G=!0,i.orChildrenGroup.find(re=>di(this,re).exact)||(this.orChildrenGroup=null,this.chooseOneFromOrGroupAndApply(i,r))),!G){const q=[...i==null?void 0:i.orChildrenGroup];this.orChildrenGroup=this.orChildrenGroup||[];const re=[...this.orChildrenGroup||[]];for(;q.length>0;){const ee=q.shift();let se=re==null?void 0:re.find(te=>di(te,ee).exact);if(se||(se=re==null?void 0:re.find(te=>di(te,ee))),!se){const te=q.findIndex(le=>re==null?void 0:re.some(ue=>di(ue,le).exact));if(te!==-1){const[le]=q.splice(te,1);se=re==null?void 0:re.find(ue=>di(ue,le).exact)}}if(se){const te=re.indexOf(se);te!==-1&&re.splice(te,1);const le=se.merge(ee,r,{implementSource:m.implementSource});c.push(...le.updated),e.push(...le.added),f.push(...le.removed),h.push(...le.affected)}else if(m.implementSource){const te=ee.implement(this,r,x.UUID.uuid(),ze.OrDataTypeGroup);this.addToOrGroup(te,r),e.push(te)}else{const te=ee.clone(r,this,x.UUID.uuid(),!0);this.addToOrGroup(te,r),e.push(te)}}[...this.orChildrenGroup||[]].forEach(ee=>{((i==null?void 0:i.orChildrenGroup)||[]).find(te=>di(ee,te))||(ee.remove({ignoreUpstream:!1},r),f.push(ee))})}}return i!=null&&i.andChildrenGroup&&Array.isArray(i==null?void 0:i.andChildrenGroup)&&!this.entity&&(i==null||i.andChildrenGroup.forEach(G=>{var re;if(!((re=this.andChildrenGroup)==null?void 0:re.find(ee=>di(ee,G)))){const ee=G.clone(r,this,x.UUID.uuid(),!0);this.addToAndGroup(ee,r),e.push(ee)}}),[...this.andChildrenGroup||[]].forEach(G=>{((i==null?void 0:i.andChildrenGroup)||[]).find(re=>di(G,re))||(G.remove({ignoreUpstream:!1},r),f.push(G))})),r==null||r.attemptAutoclose(w.MergeDataTypes,this.id),{updated:C(c),added:C(e),removed:C(f),affected:C(h),self:this}}addToAndGroup(i,r=this.project.addChangeSet(new S(this.project,x.sessionAuthor,B().toISOString(),this,!0,w.AddToAndGroup))){return this.checkCanEdit(this,r)?(this.andChildrenGroup||(this.andChildrenGroup=[]),this.andChildrenGroup.includes(i)||(this.andChildrenGroup.push(i),r==null||r.add(i,W.Affected),this.entity&&this.setEntity(null,r)),r==null||r.attemptAutoclose(w.AddToAndGroup,this.id),this):(Y.Logger.warn(`[${w.AddToAndGroup}] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),r==null||r.attemptAutoclose(w.AddToAndGroup,this.id),this)}addToOrGroup(i,r=this.project.addChangeSet(new S(this.project,x.sessionAuthor,B().toISOString(),this,!0,w.AddToOrGroup))){return this.checkCanEdit(this,r)?(this.orChildrenGroup||(this.orChildrenGroup=[]),this.orChildrenGroup.includes(i)||(this.orChildrenGroup.push(i),r==null||r.add(i,W.Affected),this.entity&&this.setEntity(null,r)),r==null||r.attemptAutoclose(w.AddToOrGroup,this.id),this):(Y.Logger.warn(`[${w.AddToOrGroup}] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),r==null||r.attemptAutoclose(w.AddToOrGroup,this.id),this)}setForeignKeyRef(i,r=this.project.addChangeSet(new S(this.project,x.sessionAuthor,B().toISOString(),this,!0,w.SetDataTypeForeignKeyRef))){if(!this.checkCanEdit(this,r))return Y.Logger.warn(`[${w.SetDataTypeForeignKeyRef}] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),r==null||r.attemptAutoclose(w.SetDataTypeForeignKeyRef,this.id),this;const a=this.foreignKeyRef;return(a==null?void 0:a.id)!==(i==null?void 0:i.id)&&(this.foreignKeyRef=i,r==null||r.add(this,W.Updated)),r==null||r.attemptAutoclose(w.SetDataTypeForeignKeyRef,this.id),this}setEntity(i,r=this.project.addChangeSet(new S(this.project,x.sessionAuthor,B().toISOString(),this,!0,w.SetDataTypeEntityValue))){var c,e,f;if(!this.checkCanEdit(this,r))return Y.Logger.warn(`[${w.SetDataTypeEntityValue}] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),r==null||r.attemptAutoclose(w.SetDataTypeEntityValue,this.id),this;const a=this.entity;return(a==null?void 0:a.id)!==(i==null?void 0:i.id)&&(this.entity=i,r==null||r.add(this,W.Updated),a&&(a.type===d.DefinitionEntity||a.type===d.LiteralValue||a.type===d.ActionDescriptor)&&((c=a.parent)==null?void 0:c.id)===this.id&&(a==null||a.remove({ignoreUpstream:!0},r)),(e=this.orChildrenGroup)!=null&&e.length&&this.entity&&(this.orChildrenGroup.forEach(h=>{this.removeChildGroup(h,r)}),this.orChildrenGroup=null),(f=this.andChildrenGroup)!=null&&f.length&&this.entity&&(this.andChildrenGroup.forEach(h=>{this.removeChildGroup(h,r)}),this.andChildrenGroup=null)),r==null||r.attemptAutoclose(w.SetDataTypeEntityValue,this.id),this}isObject(){return!!this.entity&&(this.entity.type===d.DefinitionEntity||this.entity.type===d.BuiltInBaseEntity||this.entity.name===fe.KeyValue)&&!this.isList}canBeObject(){var r;let i=!1;if(this.parent.type!==d.DataType&&this.parent.type!==d.ActionDescriptor&&this.parent.type!==d.BuiltInBaseEntity&&this.parent.type!==d.DefinitionEntity&&this.parent.type!==d.FunctionDeclaration){const a=(r=this.project.requestActiveDynamicValue(this.parent))==null?void 0:r.value;a?!a.valueAsType&&(a.value===""||a.value===null||br(a))&&(i=!0):i=!0}return(this.isObject()||!this.entity||this.entity.name===fe.Untyped)&&i}hasStrictObjectStructure(){var i;return this.isObject()&&((i=this.entity)==null?void 0:i.type)===d.DefinitionEntity}isInlineDeclaredEntity(){var i,r;return((i=this.entity)==null?void 0:i.type)===d.DefinitionEntity&&((r=this.entity.parent)==null?void 0:r.id)===(this==null?void 0:this.id)}isIndependentlyUserDeclaredEntity(){var i,r;return((i=this.entity)==null?void 0:i.type)===d.DefinitionEntity&&((r=this.entity)==null?void 0:r.parent)!==this}canModifyObjectStructure(){var r;const i=this.isIndependentlyUserDeclaredEntity();return(this.isInlineDeclaredEntity()||this.canBeObject()||((r=this.entity)==null?void 0:r.name)===fe.KeyValue)&&!i}inferFromInputs(i,r=this.project.addChangeSet(new S(this.project,x.sessionAuthor,B().toISOString(),this,!0,"infer-data-type-from-inputs"))){var m;const a=[],c=[],e=[],f=[];if(!this.inferred)return r==null||r.attemptAutoclose("infer-data-type-from-inputs",this.id),{updated:[],added:[],removed:[],affected:[],self:this};let h=!1;if(!this.entity&&i.length){const E=oe(this.parent,this.project)+" data type definition",b={id:x.UUID.uuid(),deletable:!0,editable:!0,type:d.DefinitionEntity,version:x.UUID.uuid(),createdAt:(r==null?void 0:r.timestamp)||B().toISOString(),author:x.sessionAuthor,previousVersion:null,deleted:!1,name:E,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()},A=ge(b,this.project);A.hydrateAncestors(),A.setParent(this,r),A.initChildren(r),r==null||r.add(A,W.Added),A.metaSync(b,r),this.setEntity(A,r),r||A.captureVersion(),r==null||r.add(this,W.Updated),h=!0}if(this.entity){const{updated:E,added:b,removed:A,affected:_}=this.entity.inferFromInputs(i,r);c.push(...E),a.push(...b),e.push(...A),f.push(..._),h&&(r||this.entity.captureVersion())}return this.like||this.metaSync({like:!0},r),r==null||r.attemptAutoclose("infer-data-type-from-inputs",this.id),{updated:C(c),added:C(a),removed:C(e),affected:C(f),self:this}}bestEffortClearIncompatibleProperties(i=this.project.addChangeSet(new S(this.project,x.sessionAuthor,B().toISOString(),this,!0,"best-effort-clear-incompatible-properties"))){var f,h,m,E;const r=[],a=[],c=[],e=[];if(this.entity&&this.andChildrenGroup&&this.andChildrenGroup.length===0&&this.orChildrenGroup&&this.orChildrenGroup.length===0?(this.andChildrenGroup=null,this.orChildrenGroup=null,i==null||i.add(this,W.Updated),a.push(this)):!this.entity&&this.andChildrenGroup&&this.orChildrenGroup&&(((f=this.andChildrenGroup)==null?void 0:f.length)>0&&((h=this.orChildrenGroup)==null?void 0:h.length)===0?this.andChildrenGroup=null:((m=this.orChildrenGroup)==null?void 0:m.length)>0&&((E=this.andChildrenGroup)==null?void 0:E.length)===0&&(this.orChildrenGroup=null)),this.entity&&this.foreignKeyRef)return i==null||i.attemptAutoclose("best-effort-clear-incompatible-properties",this.id),{updated:C(a),added:C(r),removed:C(c),affected:C(e),self:this};if((this.entity||this.foreignKeyRef)&&this.orChildrenGroup&&this.orChildrenGroup.length>0){for(const b of this.orChildrenGroup)if(di(this,b).compatible){this.orChildrenGroup=null,i==null||i.add(this,W.Updated),a.push(this);break}}return i==null||i.attemptAutoclose("best-effort-clear-incompatible-properties",this.id),{updated:C(a),added:C(r),removed:C(c),affected:C(e),self:this}}chooseOneFromOrGroupAndApply(i,r=this.project.addChangeSet(new S(this.project,x.sessionAuthor,B().toISOString(),this,!0,"choose-one-from-or-group-and-apply"))){var c;if(!i.orChildrenGroup||!Array.isArray(i.orChildrenGroup)||i.orChildrenGroup.length===0)return r==null||r.attemptAutoclose("choose-one-from-or-group-and-apply",this.id),null;const a=i.orChildrenGroup.some(e=>e.foreignKeyAllowed);if(((c=this.entity)==null?void 0:c.type)===d.DefinitionEntity&&si(this.entity,Ae.PERSISTED_ENTITY)&&a){const e=cKe(this.entity);e&&this.setForeignKeyRef(e,r),this.setEntity(null,r)}else{const e=i.orChildrenGroup.find(f=>{var h;return((h=f.entity)==null?void 0:h.id)===ne["primitive-entity"].string.id});if(e)this.setEntity(e.entity,r);else{const f=i.orChildrenGroup.filter(m=>m.isResolved),h=f.filter(m=>{var E;return((E=m.entity)==null?void 0:E.type)===d.PrimitiveEntity});h.length?this.setEntity(h[0].entity,r):f.length&&this.setEntity(f[0].entity,r)}}return r==null||r.attemptAutoclose("choose-one-from-or-group-and-apply",this.id),this}implement(i,r=this.project.addChangeSet(new S(this.project,x.sessionAuthor,B().toISOString(),this,!0,"implement-self-as-data-type")),a=null,c=null){const e=Ur(i,this),f=a||x.UUID.uuid(),h=Vi.new(r);h.id=f,h.like=this.like,h.asType=this.asType,h.isList=this.isList,h.options=this.options,h.parentRelationType=this.parentRelationType,h.foreignKeyAllowed=this.foreignKeyAllowed,h.staticEntities=this.staticEntities,h.interactiveEntities=this.interactiveEntities,h.actionEntities=this.actionEntities,h.parent=i.toReference(),h.parentRelationType=c;const m=ge(h,e);return m.hydrateAncestors(),m.addSelfToProject(r),r==null||r.add(m,W.Added),m.initChildren(r),m.merge(this,r,{implementSource:!0}),r||m.captureVersion(),r==null||r.attemptAutoclose("implement-self-as-data-type",this.id),m}};R(Vi,"repository",{APICreate:async(i,...r)=>i,APIUpdate:async(i,...r)=>i,APIDelete:async(i,...r)=>i,APIClone:async(i,...r)=>{},APILoad:async(i,...r)=>null,APILoadVersion:async(i,r,...a)=>null}),R(Vi,"type",d.DataType),R(Vi,"USER_MANAGED_PARENT_TYPES",[...RV]),R(Vi,"PARENT_TYPES",[..._F]),R(Vi,"MUTABLE_BASE_PROPERTIES",["isList","asType","options","foreignKeyAllowed","like","implementationChooseOne","staticEntities","interactiveEntities","actionEntities"]),R(Vi,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","index","author","previousVersion","parentRelationType"]),R(Vi,"BASE_PROPERTIES",[...Vi.MUTABLE_BASE_PROPERTIES,...Vi.INMUTABLE_BASE_PROPERTIES]),R(Vi,"MUTABLE_META_PROPERTIES",[...Vi.MUTABLE_BASE_PROPERTIES,"inferred"]),R(Vi,"INMUTABLE_META_PROPERTIES",[...Vi.INMUTABLE_BASE_PROPERTIES]),R(Vi,"META_PROPERTIES",[...Vi.MUTABLE_META_PROPERTIES,...Vi.INMUTABLE_META_PROPERTIES]),R(Vi,"MUTABLE_UPSTREAM_PROPERTIES",["entity","foreignKeyRef","parent"]),R(Vi,"INMUTABLE_UPSTREAM_PROPERTIES",[]),R(Vi,"UPSTREAM_PROPERTIES",[...Vi.MUTABLE_UPSTREAM_PROPERTIES,...Vi.INMUTABLE_UPSTREAM_PROPERTIES]),R(Vi,"MUTABLE_DOWNSTREAM_PROPERTIES",[]),R(Vi,"INMUTABLE_DOWNSTREAM_PROPERTIES",["andChildrenGroup","orChildrenGroup"]),R(Vi,"DOWNSTREAM_PROPERTIES",[...Vi.MUTABLE_DOWNSTREAM_PROPERTIES,...Vi.INMUTABLE_DOWNSTREAM_PROPERTIES]),R(Vi,"PROPERTIES",[...Vi.META_PROPERTIES,...Vi.UPSTREAM_PROPERTIES,...Vi.DOWNSTREAM_PROPERTIES]);let mr=Vi;async function jke(s,p={}){var c;const i=Y.YieldTracker.from(p),a=[...s.implements.flatMap(e=>bL(s,e)),...In(s),...AL(s),...Ja(s)];return await i.tick(),await((c=s.dataType)==null?void 0:c.validateAsync({tracker:i})),a}function kke(s){var r;const p=s.implements.flatMap(a=>bL(s,a));return(r=s.dataType)==null||r.validate(),[...p,...In(s),...AL(s),...Ja(s)]}function bL(s,p){const i=[];if(!s.implements)return i;if(!p.abstract){const a=gt({id:`${s.id}--${be.PropertyImplementsNonAbstact}`,message:`Property "${oe(s,s.project)}" with id "${s.id}" implements a non-abstract property "${oe(p,s.project)}" with id "${p.id}".`,severity:Te.Error,code:be.PropertyImplementsNonAbstact,entity:s,firstRelationship:p});i.push(a.error)}if(s.static&&!p.static){const a=gt({id:`${s.id}--${be.NonStaticPropertyImplementsStatic}`,message:`Static property "${oe(s,s.project)}" with id "${s.id}" implements a non-static property "${oe(p,s.project)}" with id "${p.id}".`,severity:Te.Error,code:be.NonStaticPropertyImplementsStatic,entity:s,firstRelationship:p});i.push(a.error)}if(!s.static&&p.static){const a=gt({id:`${s.id}--${be.StaticPropertyImplementsNonStatic}`,message:`Non-static property "${oe(s,s.project)}" with id "${s.id}" implements a static property "${oe(p,s.project)}" with id "${p.id}".`,severity:Te.Error,code:be.StaticPropertyImplementsNonStatic,entity:s,firstRelationship:p});i.push(a.error)}if(!di(s.dataType,p.dataType)){const a=gt({id:`${s.id}--${be.PropertyImplementsIncompatibleType}`,message:`Property "${oe(s,s.project)}" with id "${s.id}" implements a property "${oe(p,s.project)}" with id "${p.id}" that has an incompatible data type.`,severity:Te.Error,code:be.PropertyImplementsIncompatibleType,entity:s,firstRelationship:p});i.push(a.error)}return St(s.errors,i)}function AL(s,p){const r=[...s.parent.allProperties].filter(a=>{var c;return a.id!==s.id&&!s.implements.find(e=>e.id===a.id)&&a.id!==((c=s.extends)==null?void 0:c.id)});return QE(s,[Xi],r,p)}const gVi=Object.freeze(Object.defineProperty({__proto__:null,validate:kke,validateAsync:jke,validateImplementation:bL,validatePropertyEntityName:AL},Symbol.toStringTag,{value:"Module"}));function IVi(s,p){const i=[],r=[],a=Vke(s,p);if(s.parent){const e=p.get(s.parent);if(!e)r.push(new De({id:`${s.id}--${s.parent}--${he.ReferencedEntityNotFound}`,code:he.ReferencedEntityNotFound,severity:Te.Error,message:`Entity of type "${s.type}" with id "${s.id}", is referencing an entity with id "${s.parent}" at 'parent' that isn't yet found in the project. Perhaps it should be created first. Or perhaps the ID is incorrect.`}));else{const f=du(e);if(f){const h=e!==f?`The entity of type '${s.type}' with id '${s.id}' have 'parent' with id '${s.parent}' because the entity belongs to a built-in '${f.type}' entity with id '${f.id}' (${oe(f,e.project)}) higher up in the tree.`:`The entity of type '${s.type}' with id '${s.id}' have 'parent' with id '${s.parent}' because it is a built-in entity of type ${f.type}.`;r.push(new De({id:`${s.id}--${he.InvalidBuiltInEntityReference}`,code:he.InvalidBuiltInEntityReference,severity:Te.Error,message:h}))}else if(![d.DefinitionEntity].includes(e.type))r.push(new De({id:`${s.id}--${s.parent}--${he.InvalidParentReference}`,code:he.InvalidParentReference,severity:Te.Error,message:`Entity of type "${s.type}" with id "${s.id}", has a parent reference which is of type ${e.type}, and therefore that isn't pointing to the following valid types for this reference: 'definition-entity'.`}));else{const m=Xn(e).filter(E=>!E.interactive);if(m.length){let E=m.length>1?`The entity of type '${s.type}' with id '${s.id}' can't be added to the 'parent' entity with id '${e.id}' because it extends or implements multiple '${d.BuiltInBaseEntity}' entities that are non-interactive ("${vt(m.map(b=>oe(b,b.project)),'", "','" and "')}").`:`The entity of type '${s.type}' with id '${s.id}' can't be added to the 'parent' entity with id '${e.id}' because it extends or implements a '${d.BuiltInBaseEntity}' entity that is non-interactive ("${oe(m[0],m[0].project)}").`;i.push({id:Yi.NonInteractiveBaseEntities,message:lu}),r.push(new De({id:`${s.id}--${he.NonInteractiveEntityReferenced}`,code:he.NonInteractiveEntityReferenced,severity:Te.Error,message:E}))}else s.implements&&s.implements.forEach(E=>{const b=p.get(E);if(E===s.id)return r.push(new De({id:`${s.id}--${E}--${he.SelfReference}`,code:he.SelfReference,severity:Te.Error,message:`Entity of type "${s.type}" with id "${s.id}", has a reference to itself at 'implements'. This is not allowed. Change the reference string or the 'entityId' property of the reference object.`})),r;b?[d.Property].includes(b.type)?b.abstract||r.push(new De({id:`${s.id}--${E}--${he.InvalidImplementsReference}`,code:he.InvalidImplementsReference,severity:Te.Error,message:`Entity of type "${s.type}" with id "${s.id}", has an 'implements' reference that isn't pointing to an abstract entity.`})):r.push(new De({id:`${s.id}--${E}--${he.InvalidImplementsReference}`,code:he.InvalidImplementsReference,severity:Te.Error,message:`Entity of type "${s.type}" with id "${s.id}", has an 'implements' reference which is of type ${b.type}, and therefore that isn't pointing to the following valid types for this reference: 'property'.`})):r.push(new De({id:`${s.id}--${E}--${he.ReferencedEntityNotFound}`,code:he.ReferencedEntityNotFound,severity:Te.Error,message:`Entity of type "${s.type}" with id "${s.id}", is referencing an entity with id "${E}" at 'implements' that isn't yet found in the project. Perhaps it should be created first. Or perhaps the ID is incorrect.`}))})}}}else r.push(new De({id:`${s.id}--${Ce.InvalidObjectStructure}`,code:Ce.InvalidObjectStructure,severity:Te.Error,message:`Entity of type "${s.type}" with id "${s.id}" is missing a 'parent' reference. The 'parent' of a 'property' entity must be a reference to an entity of type 'definition-entity'.`}));const c=Ln(s,{},p);return i.push(...c.explanations),r.length>0&&i.push(...a.explanations),r.push(...c.errors),{errors:r,explanations:i}}function yF(s){var p,i,r,a,c,e,f,h,m,E,b,A;if(((i=(p=s.dataType)==null?void 0:p.entity)==null?void 0:i.type)===d.PrimitiveEntity&&((a=(r=s.dataType)==null?void 0:r.entity)==null?void 0:a.id)===((c=ne["primitive-entity"].enum)==null?void 0:c.id)){if(((e=s.dataType.options)==null?void 0:e.length)===1){const _=s.dataType.options[0];if(_)return{result:!0,value:_,name:fe.String}}}else if(((h=(f=s.dataType)==null?void 0:f.entity)==null?void 0:h.type)===d.LiteralValue&&[fe.String,fe.Number,fe.UUID,fe.Boolean,fe.Date,fe.Bytes].includes((E=(m=s.dataType)==null?void 0:m.entity)==null?void 0:E.name)&&typeof((A=(b=s.dataType)==null?void 0:b.entity)==null?void 0:A.value)=="string")return{result:!0,value:s.dataType.entity.value,name:s.dataType.entity.name};return{result:!1,value:null,name:null}}function RVi(s){return!!s.implements.find(p=>p.id===ne["built-in-base-entity"].BUILT_IN_PERSISTED_ENTITY_ENTITY.properties.database.id)}function hF(s,p){const i=[],r=[],a=[],c=[];let e=!1;if(s.implements.find(f=>f.id===ne["built-in-base-entity"].BUILT_IN_PERSISTED_ENTITY_ENTITY.properties.database.id)){let f=s.defaultValue;if(!s.defaultValue){const h=Nr.new(p);h.name=fe.EntityTemplate,h.parent=s.toReference();const m=ge(h,s.project);m.hydrateAncestors(),m.addSelfToProject(p),p==null||p.add(m,W.Added),r.push(m),m.initChildren(p),f=m,e=!0}if(!f.valueAsTypeSingle){const h=hKe(s.project);h&&f.setValueAsTypeSingle(h,p)}e&&(p||f==null||f.captureVersion())}return{updated:C(i),added:C(r),removed:C(a),affected:C(c),self:s}}var Uke=(s=>(s.PropertyImplements="property-implements-field",s.PropertyExtends="property-extends-field",s.PropertyDataTypeEntity="property-data-type-entity-field",s.PropertyDataType="property-data-type-field",s))(Uke||{});const yi=class yi extends dn{constructor(i,r){super(i);R(this,"initialData");R(this,"id");R(this,"name");R(this,"codeName",null);R(this,"description",null);R(this,"private");R(this,"abstract");R(this,"index");R(this,"static");R(this,"unique");R(this,"required");R(this,"constant",!1);R(this,"interactive",!1);R(this,"type",d.Property);R(this,"hidden",!1);R(this,"parentRelationType",null);R(this,"defaultValue",null);R(this,"dataType",null);R(this,"implements",[]);R(this,"extends",null);R(this,"project");R(this,"errors",[]);R(this,"parent");R(this,"detachedDependents",{});R(this,"knownVersions",null);R(this,"activeVersion",!1);R(this,"initialized",!1);R(this,"startedInitialization",!1);R(this,"suggestion",!1);R(this,"_codeNativeValueValidation",null);this.initialData=i,this.project=r,this.id=i.id,this.name=i.name,this.description=i.description,this.private=i.private,this.abstract=i.abstract,this.index=i.index,this.static=i.static,this.required=i.required||!1,this.unique=i.unique||!1,this.codeName=i.codeName,this.hidden=i.hidden||!1,this.constant=i.constant||!1,this.interactive=i.interactive||!1,this.onProjectInitialized=this.onProjectInitialized.bind(this)}static new(i=null){return{id:x.UUID.uuid(),version:x.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||B().toISOString(),author:(i==null?void 0:i.author)||x.sessionAuthor,previousVersion:null,deleted:!1,deletable:!0,editable:!0,unique:!1,type:d.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:!0,defaultValue:null,parent:null}}static fromGenerationTarget(i,r,a){const c=a===void 0?r.addChangeSet(new S(r,x.sessionAuthor,B().toISOString(),r,!0,w.CreateFromGenerationTarget)):a,e=ie(i.parent),f=r.get(e),h=[];i.implements&&i.implements.forEach(A=>{h.push(r.get(A)||r.getBuiltIn(A))});let m=null;if(i.extends){const A=ie(i.extends);m=r.get(A)}const E={id:i.id,version:x.UUID.uuid(),createdAt:(c==null?void 0:c.timestamp)||B().toISOString(),author:(c==null?void 0:c.author)||x.sessionAuthor,previousVersion:null,deleted:!1,name:i.name,deletable:!0,editable:!0,type:d.Property,index:f.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??!0,hidden:!1,codeName:i.codeName||null,description:i.description||null,defaultValue:null,implements:h,extends:(m==null?void 0:m.toShallowJSON())||null,dataType:null,parent:f.toReference()},b=ge(E,r);return b.hydrateAncestors(),b.setParent(f,c),b.addSelfToProject(c),c==null||c.add(b,W.Added),b.initChildren(c),c||b.captureVersion(),b}static validateGenerationTarget(i,r){let a=JSON.parse(JSON.stringify(i));const c=[],e=[],f=IVi(a,r),h=xx(a,r),m=Qr(a);return e.push(...f.errors,...h,...m.errors),c.push(...f.explanations,...m.explanations),{errors:e,explanations:c,modifiedData:a}}get isExtendedProperty(){const i=this.parent.allBasePropertiesFromExtendedAndImplementedEntities.find(r=>{var a;return r.id===((a=this.extends)==null?void 0:a.id)});return!!i&&i.id!==this.id&&!i.abstract}get codeNativeValueValidation(){const i=[...this.implements].filter(a=>!this.implements.filter(f=>f.id!==a.id).some(f=>!!f.implements.find(h=>h.id===a.id)));return this._codeNativeValueValidation||(i==null?void 0:i.some(a=>a.codeNativeValueValidation))?(a,c)=>{const e=[];let f=c;if(this._codeNativeValueValidation){const h=this._codeNativeValueValidation(a,c);h&&(e.push(...h.errors),f=h.override)}return i.forEach(h=>{const m=h.codeNativeValueValidation;if(m){const E=m(a,c);E&&(e.push(...E.errors),f=E.override)}}),{errors:AE(e),override:f}}:null}validateGeneratedUpdate(i){const r=[],a=[];return i.parent&&r.push(new De({id:`${this.id}--${he.InvalidParentUpdate}`,code:he.InvalidParentUpdate,severity:Te.Error,message:`Entity of type '${this.type}' with id '${this.id}' cannot have the 'parent' property updated, as it would mean moving the '${this.type}' entity to another parent entity.
534
+ Alternatively you can update the entity with 'update' action. Or replace it by first removing it and then creating a new one.`}))}A===d.DataType&&(!a.parentRelationType||!(a.parentRelationType===ze.AndDataTypeGroup||a.parentRelationType===ze.OrDataTypeGroup))&&e.push(new De({id:`${i.id}--${he.InvalidParentRelationType}`,code:he.InvalidParentRelationType,severity:Te.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:e,explanations:c,modifiedData:a}}get isGroup(){const i=[...this.andChildrenGroup||[],...this.orChildrenGroup||[]];if(i.length>1){let r=0;for(const a of i)if(a.isResolved&&(r++,r>1))return!0}return!1}get isResolved(){return[d.BuiltInBaseEntity,d.ActionDescriptor].includes(this.parent.type)||du(this.parent)?!0:!(!this.entity&&!this.isGroup&&!this.foreignKeyRef&&!this.foreignKeyAllowed)}validateGeneratedUpdate(i){return{errors:[],explanations:[],modifiedData:i}}subscribeDependents(i){return i.forEach(r=>{this.detachedDependents[r.entity.id]||(this.detachedDependents[r.entity.id]=r)}),this}unsubscribeDependents(i){return i.forEach(r=>{this.detachedDependents[r.entity.id]&&delete this.detachedDependents[r.entity.id]}),this}syncDependents(i=this.project.addChangeSet(new S(this.project,x.sessionAuthor,B().toISOString(),this,!0,"sync-dependents"))){const r=[],a=[],c=[],e=[];return Object.values(this.detachedDependents).forEach(f=>{const h=f.entity.afterAllChildrenInitialized(i);r.push(...h.updated),a.push(...h.added),c.push(...h.removed),e.push(...h.affected)}),i==null||i.attemptAutoclose("sync-dependents",this.id),{updated:C(r),added:C(a),removed:C(c),affected:C(e),self:this}}onDetachedDependencyRemoved(i,r,a){const c=[],e=[],f=[],h=[];return r==="entity-field"&&this.setEntity(null,a),r==="foreign-key-ref-field"&&this.setForeignKeyRef(null,a),{updated:C(c),added:C(e),removed:C(f),affected:C(h),self:this}}onDetachedDependencyRestored(i,r,a){const c=[],e=[],f=[],h=[];return r==="entity-field"&&this.setEntity(i,a),r==="foreign-key-ref-field"&&this.setForeignKeyRef(i,a),{updated:C(c),added:C(e),removed:C(f),affected:C(h),self:this}}unsubscribeFromDependencies(){var i,r,a,c;return(r=(i=this.entity)==null?void 0:i.unsubscribeDependents)==null||r.call(i,[{entity:this,field:"entity-field"}]),(c=(a=this.foreignKeyRef)==null?void 0:a.unsubscribeDependents)==null||c.call(a,[{entity:this,field:"foreign-key-ref-field"}]),this}subscribeToDependencies(){var i,r,a,c;return(r=(i=this.entity)==null?void 0:i.subscribeDependents)==null||r.call(i,[{entity:this,field:"entity-field"}]),(c=(a=this.foreignKeyRef)==null?void 0:a.subscribeDependents)==null||c.call(a,[{entity:this,field:"foreign-key-ref-field"}]),this}increaseVersion(i){var r;if(this.project.diggestedBuiltInBaseEntitiesIds.has(this.id))return this;if(i&&!B(i).isValid())throw new Error(`The shared timestamp '${i}' is not a valid ISO 8601 date string.`);if(i&&B(i).isSame(B(this.createdAt)))return this;if(!((r=this.knownVersions)!=null&&r.has(this.version))&&this.project.initialized)throw new Error(`The current ${this.type} ${this.id} version '${this.version}' is not captured in the 'knownVersions' map. Capture the current version before increasing it to avoid losing data.`);if(!this.activeVersion)throw new Error(`Only active versions can be increased. Entity with id '${this.id}' and version '${this.version}' is not active.`);return this.previousVersion=this.version,this.version=x.UUID.uuid(),this.createdAt=B(i).toISOString()||B().toISOString(),this}captureVersion(){var r;const i=((r=this.knownVersions)==null?void 0:r.get(this.version))||new Vi(this,this.project);if(!this.activeVersion)throw new Error(`Only active versions can be captured. Entity of type ${this.type} with id '${this.id}' and version '${this.version}' is not active.`);if(this.version!==i.version)throw new Error(`Captured ${this.type} with id '${this.id}', version '${i.version}' does not match current entity version '${this.version}'.`);return this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,i):new Map().set(this.version,i),this.apply(i),this}snapshot(){const i=new Vi(this,this.project);return this.apply(i)}apply(i){const r=this.toMeta();return i.metaSync(r,null),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,i}recursiveCaptureUpstreamVersions(i){const r=[],a=[],c=[],e=[];if(this.parent&&this.parent.type!==d.BuiltInBaseEntity){this.parent.increaseVersion(i);const f=this.parent.recursiveCaptureUpstreamVersions(i);r.push(this.parent,...f.updated),a.push(...f.added),c.push(...f.removed)}return{updated:C(r),added:C(a),removed:C(c),affected:C(e),self:this}}async restoreVersion(i,r){var m;const a=[],c=[],e=[],f=[];if(this.version===i&&(r!=null&&r.skipIfSameVersion))return{updated:C(a),added:C(c),removed:C(e),affected:C(f),self:this};if(!this.knownVersions){const E=new Map;for(const[b,A]of this.knownVersions||new Map){if(E.set(b,A),A.activeVersion=!1,A.knownVersions)for(const[_,P]of A.knownVersions)E.set(_,P);A.knownVersions=null}}let h=(m=this.knownVersions)==null?void 0:m.get(i);if(!h){const E=await this.APILoadVersion({},i);if(!E)throw new Error(`Version with id '${i}' for entity with id '${this.id}' not found.`);h=new Vi(E,this.project)}return this.metaSync(h.toShallowJSON(),null),this.previousVersion=h.previousVersion,this.version=h.version,this.createdAt=h.createdAt,this.author=h.author,this.deleted=h.deleted,this.entity=h.entity,this.foreignKeyRef=h.foreignKeyRef,this.andChildrenGroup=h.andChildrenGroup?[...h.andChildrenGroup]:null,this.orChildrenGroup=h.orChildrenGroup?[...h.orChildrenGroup]:null,this.parent=h.parent,{updated:C(a),added:C(c),removed:C(e),affected:C(f),self:this}}updateWithShallowTransfer(i,r=this.project.addChangeSet(new S(this.project,x.sessionAuthor,B().toISOString(),this,!0,w.UpdateWithShallowTransfer))){var a,c;if(!this.checkCanEdit(this,r))return Y.Logger.warn(`[updateWithShallowTransfer] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),r==null||r.attemptAutoclose(w.UpdateWithShallowTransfer,this.id),this;if(this.metaSync(i,r),this.version=i.version,this.createdAt=i.createdAt,this.author=i.author,this.deleted=i.deleted,this.previousVersion=i.previousVersion,this.unsubscribeFromDependencies(),i.parent){const e=ie(i.parent),f=this.project.get(e),h=this.parent;if(h&&h.id!==(f==null?void 0:f.id)&&this.removeFromParent(r),f)this.setParent(f,r),this.addSelfToProject(r);else throw r==null||r.attemptAutoclose(w.UpdateWithShallowTransfer,this.id),new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${e}' that isn't found in the project`)}else throw r==null||r.attemptAutoclose(w.UpdateWithShallowTransfer,this.id),new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(i.entity){const e=ie(i.entity),f=this.project.get(e);f&&(this.setEntity(f,r),this.metaSync({inferred:!1},r))}else this.setEntity(null,r);if(i.foreignKeyRef){const e=ie(i.foreignKeyRef),f=this.project.get(e);f&&this.setForeignKeyRef(f,r)}else this.setForeignKeyRef(null,r);return(a=i.andChildrenGroup)==null||a.forEach(e=>{const f=ie(e),h=this.project.get(f);h&&(this.addToAndGroup(h,r),h.setParent(this,r))}),[...this.andChildrenGroup||[]].forEach(e=>{var h;((h=i.andChildrenGroup)==null?void 0:h.find(m=>ie(m)===e.id))||(this.removeChildGroup(e,r),e.removeFromParent(r))}),(c=i.orChildrenGroup)==null||c.forEach(e=>{const f=ie(e),h=this.project.get(f);h&&(this.addToOrGroup(h,r),h.setParent(this,r))}),[...this.orChildrenGroup||[]].forEach(e=>{var h;((h=i.orChildrenGroup)==null?void 0:h.find(m=>ie(m)===e.id))||(this.removeChildGroup(e,r),e.removeFromParent(r))}),this.captureVersion(),this.subscribeToDependencies(),r==null||r.attemptAutoclose(w.UpdateWithShallowTransfer,this.id),this}updateWithGenerationTarget(i,r=this.project.addChangeSet(new S(this.project,x.sessionAuthor,B().toISOString(),this,!0,w.UpdateWithGenerationTarget))){if(!this.checkCanEdit(this,r))return Y.Logger.warn(`[updateWithGenerationTarget] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),r==null||r.attemptAutoclose(w.UpdateWithGenerationTarget,this.id),this;if(this.metaSync(i,r),i.parent){const a=ie(i.parent),c=this.project.get(a),e=this.parent;if(e&&e.id!==(c==null?void 0:c.id)&&this.removeFromParent(r),c)this.setParent(c,r),this.addSelfToProject(r);else throw r==null||r.attemptAutoclose(w.UpdateWithGenerationTarget,this.id),new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${a}' that isn't found in the project`)}if(i.entity){const a=ie(i.entity),c=this.project.get(a);if(c)this.setEntity(c,r),this.metaSync({inferred:!1},r);else throw new Error(`${this.type} with id '${this.id}' has an 'entity' reference '${a}' that isn't found in the project`)}else i.entity==null&&this.setEntity(null,r);if(i.foreignKeyRef){const a=ie(i.foreignKeyRef),c=this.project.get(a);if(c)this.setForeignKeyRef(c,r);else throw new Error(`${this.type} with id '${this.id}' has a 'foreignKeyRef' reference '${a}' that isn't found in the project`)}else i.foreignKeyRef==null&&this.setForeignKeyRef(null,r);return this.captureVersion(),this.subscribeToDependencies(),r==null||r.attemptAutoclose(w.UpdateWithGenerationTarget,this.id),this}hydrateAncestors(){const i=[],r=[],a=[],c=[];if(this.initialData.parent){const e=ie(this.initialData.parent),f=this.project.get(e);if(f)this.setParent(f,null),i.push(f);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${e}' that isn't found in the project`)}else throw new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(this.initialData.entity){const e=ie(this.initialData.entity),f=this.project.get(e);f&&(f.type===d.DefinitionEntity&&f.parent===this||(this.setEntity(f,null),f.type!==d.BuiltInBaseEntity&&f.type!==d.PrimitiveEntity&&i.push(f)))}if(this.initialData.foreignKeyRef){const e=ie(this.initialData.foreignKeyRef),f=this.project.get(e);f&&this.setForeignKeyRef(f,null)}return{updated:C(i),added:C(r),removed:C(a),affected:C(c),self:this}}afterAllChildrenInitialized(i=this.project.addChangeSet(new S(this.project,x.sessionAuthor,B().toISOString(),this,!0,w.AfterAllChildrenInitialized))){var f,h,m,E,b;if(!this.checkCanEdit(this,i))return Y.Logger.warn(`[afterAllChildrenInitialized] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(w.AfterAllChildrenInitialized,this.id),{updated:[],added:[],removed:[],affected:[],self:this};const r=[],a=[],c=[],e=[];if(this.initialized=!0,((f=this.parent)==null?void 0:f.type)===d.DataType){let A=this.index||0;const _=(this.parentRelationType===ze.AndDataTypeGroup?this.parent.andChildrenGroup||[]:this.parent.orChildrenGroup||[]).filter(V=>!V.deleted&&V.id!==this.id);_.length&&(A>_.length+1?A=_.length:A<0&&(A=0)),_.find(V=>(V.index||0)===A&&!V.deleted)&&_.filter(V=>(V.index||0)>=A&&!V.deleted).forEach(V=>{V.metaSync({index:(V.index||0)+1},i),i==null||i.add(V,W.Updated),r.push(V)}),this.metaSync({index:A},i)}return(h=this.andChildrenGroup)!=null&&h.length&&this.andChildrenGroup.sort((A,_)=>(A.index||0)-(_.index||0)),(m=this.orChildrenGroup)!=null&&m.length&&this.orChildrenGroup.sort((A,_)=>(A.index||0)-(_.index||0)),this.entity&&this.entity.type===d.DefinitionEntity&&((E=this.entity.parent)==null?void 0:E.id)!==this.id&&this.metaSync({inferred:!1},i),this.bestEffortClearIncompatibleProperties(i),this.entity&&this.entity.type===d.DefinitionEntity&&((b=this.entity.parent)==null?void 0:b.id)===this.id&&this.entity.afterAllChildrenInitialized(i),i==null||i.attemptAutoclose(w.AfterAllChildrenInitialized,this.id),{updated:C(r),added:C(a),removed:C(c),affected:C(e),self:this}}addSelfToProject(i=this.project.addChangeSet(new S(this.project,x.sessionAuthor,B().toISOString(),this,!0,"add-self-to-project"))){const r=[this],a=[],c=[],e=[];return this.parent.type===d.DataType?(this.parentRelationType===ze.AndDataTypeGroup?this.parent.addToAndGroup(this,i):this.parentRelationType===ze.OrDataTypeGroup&&this.parent.addToOrGroup(this,i),e.push(this.parent)):this.parent.type===d.DefinitionEntity?(this.parent.setAdditionalPropertiesDataType(this,i),e.push(this.parent)):this.parent.type!==d.BuiltInBaseEntity&&this.parent.setDataType(this,i),this.subscribe(),this.subscribeToDependencies(),i==null||i.attemptAutoclose("add-self-to-project",this.id),{updated:C(r),added:C(a),removed:C(c),affected:C(e),self:this}}setParent(i,r=this.project.addChangeSet(new S(this.project,x.sessionAuthor,B().toISOString(),this,!0,w.SetParent))){var a;return this.checkCanEditWithCounterpartAndSideEffects(this,i,w.SetParent,r)?(((a=this.parent)==null?void 0:a.id)!==(i==null?void 0:i.id)&&(this.parent=i,r&&(r==null||r.add(this,W.Updated))),r==null||r.attemptAutoclose(w.SetParent,this.id),this):this}removeChildGroup(i,r=this.project.addChangeSet(new S(this.project,x.sessionAuthor,B().toISOString(),this,!0,w.RemoveChildGroup))){if(!this.checkCanEdit(this,r))return Y.Logger.warn(`[removeChildGroup] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),r==null||r.attemptAutoclose(w.RemoveChildGroup,this.id),this;if(this.andChildrenGroup){const a=this.andChildrenGroup.findIndex(c=>c.id===i.id);a!==-1&&(this.andChildrenGroup.splice(a,1),r==null||r.add(this,W.Updated))}if(this.orChildrenGroup){const a=this.orChildrenGroup.findIndex(c=>c.id===i.id);a!==-1&&(this.orChildrenGroup.splice(a,1),r==null||r.add(this,W.Updated))}return r==null||r.attemptAutoclose(w.RemoveChildGroup,this.id),this}initChildren(i=this.project.addChangeSet(new S(this.project,x.sessionAuthor,B().toISOString(),this,!0,"init-children"))){var r,a,c,e,f,h,m,E,b,A;if(this.initialized||this.startedInitialization)return this;if(this.startedInitialization=!0,this.initialData.entity)if(this.initialData.entity.type===d.GenericReference){const _=this.project.findSubscribedInstanceFromReference(this.initialData.entity);this.entity=_}else this.entity=ge(this.initialData.entity,this.project),(((a=(r=this.initialData.entity)==null?void 0:r.parent)==null?void 0:a.id)===this.id||((e=(c=this.initialData.entity)==null?void 0:c.parent)==null?void 0:e.type)===d.GenericReference&&((h=(f=this.initialData.entity)==null?void 0:f.parent)==null?void 0:h.entityId)==this.id)&&this.entity.setParent(this,null),(E=(m=this.entity).initChildren)==null||E.call(m,i);if(this.initialData.foreignKeyRef)if(this.initialData.foreignKeyRef.type===d.GenericReference){const _=this.project.findSubscribedInstanceFromReference(this.initialData.foreignKeyRef);this.foreignKeyRef=_}else this.foreignKeyRef=ge(this.initialData.foreignKeyRef,this.project),(A=(b=this.foreignKeyRef).initChildren)==null||A.call(b,i);return this.initialData.andChildrenGroup&&(this.andChildrenGroup=this.initialData.andChildrenGroup.map(_=>{const P=ge(_,this.project);return P.setParent(this,null),P.initChildren(i),P})),this.initialData.orChildrenGroup&&(this.orChildrenGroup=this.initialData.orChildrenGroup.map(_=>{const P=ge(_,this.project);return P.setParent(this,null),P.initChildren(i),P})),this.subscribeToDependencies(),this.afterAllChildrenInitialized(i),i==null||i.attemptAutoclose("init-children",this.id),this}subscribe(){var i;return this.activeVersion=!0,(i=this.knownVersions)==null||i.forEach(r=>{r.version!==this.version&&(r.activeVersion=!1)}),this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(i,r=this.project.addChangeSet(new S(this.project,x.sessionAuthor,B().toISOString(),this,!0,"meta-sync"))){const a=en(this,i,r),c=Xr(this,a),e=this.toMeta();return this.options=a.options||e.options,this.parentRelationType=a.parentRelationType||e.parentRelationType,this.isList=a.isList!==void 0?a.isList:e.isList,this.inferred=a.inferred!==void 0?a.inferred:e.inferred,this.like=a.like!==void 0?a.like:e.like,this.asType=a.asType!==void 0?a.asType:e.asType,this.index=a.index!==void 0?a.index:e.index,this.implementationChooseOne=a.implementationChooseOne!==void 0?a.implementationChooseOne:e.implementationChooseOne,this.staticEntities=a.staticEntities!==void 0?a.staticEntities:e.staticEntities,this.interactiveEntities=a.interactiveEntities!==void 0?a.interactiveEntities:e.interactiveEntities,this.actionEntities=a.actionEntities!==void 0?a.actionEntities:e.actionEntities,super.baseMetaSync(a,this,r),a.deleted===!0&&!e.deleted?r==null||r.add(this,W.Removed):a.deleted===!1&&e.deleted?r==null||r.add(this,W.Added):c&&(r==null||r.add(this,W.Updated)),r==null||r.attemptAutoclose("meta-sync",this.id),this}async APILoad(i=Ke,...r){return await Vi.repository.APILoad(this.id,...r),this}async APICreate(i=Ke,...r){return await Vi.repository.APICreate(this.toShallowJSON(),...r),this}async APIUpdate(i=Ke,...r){return await Vi.repository.APIUpdate(this.toShallowJSON(),...r),this}async APIDelete(i=Ke,...r){return await Vi.repository.APIDelete(this.toShallowJSON(),...r),this}async APIClone(i=Ke,...r){return await Vi.repository.APIClone(this.id,...r),this}async APILoadVersion(i=Ke,r,...a){return await Vi.repository.APILoadVersion(this.id,r,...a)}removeFromParent(i=this.project.addChangeSet(new S(this.project,x.sessionAuthor,B().toISOString(),this,!0,w.RemoveFromParent))){var f,h;if(!this.checkCanEdit(this,i))return Y.Logger.warn(`[removeFromParent] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(w.RemoveFromParent,this.id),{added:[],updated:[],removed:[],affected:[],self:this};const r=[],a=[],c=[],e=[];if(((f=this.parent)==null?void 0:f.type)===d.DataType)this.parent.removeChildGroup(this,i);else if(((h=this.parent)==null?void 0:h.type)===d.DefinitionEntity)this.parent.removeAdditionalPropertiesDataType(i);else{const m=this.parent;m==null||m.removeDataType(i)}return this.parent&&this.parent.type!==d.BuiltInBaseEntity&&r.push(this.parent),i==null||i.attemptAutoclose(w.RemoveFromParent,this.id),{added:C(c),updated:C(r),removed:C(a),affected:C(e),self:this}}remove({ignoreUpstream:i}={ignoreUpstream:!1},r=this.project.addChangeSet(new S(this.project,x.sessionAuthor,B().toISOString(),this,!0,w.RemoveEntity))){const a=[],c=[],e=[],f=[];if(r!=null&&r.hasRemoved(this.id))return r==null||r.attemptAutoclose(w.RemoveEntity,this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(c.push(this),this.unsubscribe(),this.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},r),Object.values(this.detachedDependents).forEach(h=>{const{updated:m,removed:E,added:b}=h.entity.onDetachedDependencyRemoved(this,h.field,r);a.push(...m),c.push(...E),e.push(...b)}),this.entity&&this.entity.type===d.DefinitionEntity&&this.entity.parent===this){const{updated:h,removed:m}=this.entity.remove({ignoreUpstream:!0},r);a.push(...h),c.push(...m)}if(this.andChildrenGroup&&this.andChildrenGroup.forEach(h=>{const{removed:m,updated:E}=h.remove({ignoreUpstream:!0},r);c.push(...m),a.push(...E)}),this.orChildrenGroup&&this.orChildrenGroup.forEach(h=>{const{removed:m,updated:E}=h.remove({ignoreUpstream:!0},r);c.push(...m),a.push(...E)}),!i){const h=this.removeFromParent(r);e.push(...h.added),a.push(...h.updated),c.push(...h.removed),f.push(...h.affected)}return r==null||r.attemptAutoclose(w.RemoveEntity,this.id),{added:C(e),updated:C(a),removed:C(c),affected:C(f),self:this}}restore({}={},i=this.project.addChangeSet(new S(this.project,x.sessionAuthor,B().toISOString(),this,!0,w.RestoreEntity))){if(!this.checkCanEdit(this,i))return Y.Logger.warn(`[restore] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(w.RestoreEntity,this.id),{added:[],updated:[],removed:[],affected:[],self:this};const r=[],a=[],c=[],e=[];if(i!=null&&i.hasAdded(this.id))return i==null||i.attemptAutoclose(w.RestoreEntity,this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},i),Object.values(this.detachedDependents).forEach(f=>{const{updated:h,removed:m,added:E}=f.entity.onDetachedDependencyRestored(this,f.field,i);a.push(...h),c.push(...m),r.push(...E)}),this.entity&&this.entity.type===d.DefinitionEntity&&this.entity.parent===this){const{updated:f}=this.entity.restore({},i);a.push(...f)}if(this.andChildrenGroup&&this.andChildrenGroup.forEach(f=>{const{updated:h,added:m}=f.restore({},i);a.push(...h),r.push(...m)}),this.orChildrenGroup&&this.orChildrenGroup.forEach(f=>{const{updated:h,added:m}=f.restore({},i);a.push(...h),r.push(...m)}),this.parent.type===d.DataType){const f=this.parent;Array.isArray(f.andChildrenGroup)&&f.andChildrenGroup.push(this)}if(this.parent.type===d.DataType){const f=this.parent;this.parentRelationType===ze.AndDataTypeGroup?Array.isArray(f.andChildrenGroup)&&f.andChildrenGroup.push(this):this.parentRelationType===ze.OrDataTypeGroup&&Array.isArray(f.orChildrenGroup)&&f.orChildrenGroup.push(this)}else if(this.parent.type===d.DefinitionEntity){const f=this.parent;f.setAdditionalPropertiesDataType(this,i),a.push(f)}else{const f=this.parent;f.setDataType(this,i),a.push(f)}return i==null||i.attemptAutoclose(w.RestoreEntity,this.id),{added:C(r),updated:C(a),removed:C(c),affected:C(e),self:this}}toFlat(i=new Set){var a,c,e,f;return i.has(this.id)?[]:(i.add(this.id),[this,...((a=this.andChildrenGroup)==null?void 0:a.flatMap(h=>h.toFlat(i)))||[],...((c=this.orChildrenGroup)==null?void 0:c.flatMap(h=>h.toFlat(i)))||[],...((e=this.entity)==null?void 0:e.toFlat(i))||[],...((f=this.foreignKeyRef)==null?void 0:f.toFlat(i))||[]])}toFlatIds(i=new Set){var a,c,e,f;return i.has(this.id)?[]:(i.add(this.id),[this.id,...((a=this.andChildrenGroup)==null?void 0:a.flatMap(h=>h.toFlatIds(i)))||[],...((c=this.orChildrenGroup)==null?void 0:c.flatMap(h=>h.toFlatIds(i)))||[],...((e=this.entity)==null?void 0:e.toFlatIds(i))||[],...((f=this.foreignKeyRef)==null?void 0:f.toFlatIds(i))||[]])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,like:this.like,isList:this.isList,inferred:this.inferred,index:this.index,foreignKeyAllowed:this.foreignKeyAllowed,parentRelationType:this.parentRelationType,implementationChooseOne:this.implementationChooseOne,staticEntities:this.staticEntities,interactiveEntities:this.interactiveEntities,actionEntities:this.actionEntities,options:this.options,asType:this.asType,type:this.type,editable:this.editable,deletable:this.deletable}}toJSON(i=new Set){var r,a,c,e,f;return i.has(this.id)?this.toReference():(i.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,editable:this.editable,deletable:this.deletable,options:this.options,isList:this.isList,asType:this.asType,index:this.index,like:this.like,foreignKeyAllowed:this.foreignKeyAllowed,inferred:this.inferred,parentRelationType:this.parentRelationType,implementationChooseOne:this.implementationChooseOne,staticEntities:this.staticEntities,interactiveEntities:this.interactiveEntities,actionEntities:this.actionEntities,foreignKeyRef:((r=this.foreignKeyRef)==null?void 0:r.toJSON(i))||null,andChildrenGroup:((a=this.andChildrenGroup)==null?void 0:a.map(h=>h.toJSON(i)))||null,orChildrenGroup:((c=this.orChildrenGroup)==null?void 0:c.map(h=>h.toJSON(i)))||null,entity:((e=this.entity)==null?void 0:e.parent)===this?this.entity.toJSON(i):((f=this.entity)==null?void 0:f.toReference())||null,parent:this.parent.toReference()})}toJSONClone(i=at){var a,c,e,f,h,m,E,b,A,_;let r;return(a=i.seenEntityMaps)!=null&&a.has(this.id)?r=i.seenEntityMaps.get(this.id):(r=i.newId||on(this,this.project,i.uuidStrategy),i.seenEntityMaps&&i.seenEntityMaps.set(this.id,r)),(c=i.seenEntities)!=null&&c.has(r)||(e=i.seenEntities)!=null&&e.has(this.id)?this.toReference({seenEntityMaps:i.seenEntityMaps}):((f=i.seenEntities)==null||f.add(r),(h=i.seenEntities)==null||h.add(this.id),{id:r,version:x.UUID.uuid(),createdAt:i.timestamp||B().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,editable:this.editable,deletable:this.deletable,options:this.options,isList:this.isList,asType:this.asType,like:this.like,index:this.index,inferred:this.inferred,foreignKeyAllowed:this.foreignKeyAllowed,parentRelationType:this.parentRelationType,implementationChooseOne:this.implementationChooseOne,staticEntities:this.staticEntities,interactiveEntities:this.interactiveEntities,actionEntities:this.actionEntities,foreignKeyRef:((m=this.foreignKeyRef)==null?void 0:m.toJSONClone({...i,newId:null}))||null,andChildrenGroup:((E=this.andChildrenGroup)==null?void 0:E.map(P=>P.toJSONClone({...i,newId:null})))||null,orChildrenGroup:((b=this.orChildrenGroup)==null?void 0:b.map(P=>P.toJSONClone({...i,newId:null})))||null,entity:((A=this.entity)==null?void 0:A.parent)===this?this.entity.toJSONClone({...i,newId:null}):((_=this.entity)==null?void 0:_.toReference({seenEntityMaps:i.seenEntityMaps}))||null,parent:this.parent.toReference({seenEntityMaps:i.seenEntityMaps})})}toReference(i=at){var a;let r=this.id;return(a=i.seenEntityMaps)!=null&&a.has(this.id)&&(r=i.seenEntityMaps.get(this.id)),{id:r+"--"+x.UUID.uuid()+"--ref",type:d.GenericReference,entityId:r,version:this.version,entityType:this.type}}toShallowJSON(i=at){var a,c,e,f,h;let r=this.id;return(a=i.seenEntityMaps)!=null&&a.has(this.id)&&(r=i.seenEntityMaps.get(this.id)),{id:r,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,editable:this.editable,deletable:this.deletable,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(m=>m.toReference(i)))||null,orChildrenGroup:((f=this.orChildrenGroup)==null?void 0:f.map(m=>m.toReference(i)))||null,entity:((h=this.entity)==null?void 0:h.toReference(i))||null,parent:this.parent.toReference(i)}}toFlatJSON(i=new Set){var a,c,e;return i.has(this.id)?[]:(i.add(this.id),[this.toShallowJSON(),...((a=this.andChildrenGroup)==null?void 0:a.flatMap(f=>f.toFlatJSON(i)))||[],...((c=this.orChildrenGroup)==null?void 0:c.flatMap(f=>f.toFlatJSON(i)))||[],...((e=this.entity)==null?void 0:e.toFlatJSON(i))||[]])}toGenerationTarget(i=at){var a,c,e;let r=this.id;return(a=i.seenEntityMaps)!=null&&a.has(this.id)&&(r=i.seenEntityMaps.get(this.id)),{id:r,type:this.type,options:this.options||void 0,isList:this.isList,like:this.like,parentRelationType:this.parentRelationType||void 0,foreignKeyRef:((c=this.foreignKeyRef)==null?void 0:c.id)||null,asType:this.asType,entity:((e=this.entity)==null?void 0:e.id)||null,parent:this.parent.id}}toFlatGenerationTarget(i=new Set){var a,c;return i.has(this.id)?[]:(i.add(this.id),[this.toGenerationTarget(),...((a=this.andChildrenGroup)==null?void 0:a.flatMap(e=>e.toFlatGenerationTarget(i)))||[],...((c=this.orChildrenGroup)==null?void 0:c.flatMap(e=>e.toFlatGenerationTarget(i)))||[],...this.entity&&this.entity.type==d.DefinitionEntity&&this.entity.parent===this&&this.entity.toFlatGenerationTarget(i)||[]])}clearErrors(){var i,r,a,c;return this.errors=[],(i=this.andChildrenGroup)==null||i.forEach(e=>e.clearErrors()),(r=this.orChildrenGroup)==null||r.forEach(e=>e.clearErrors()),this.inferred&&this.entity&&this.entity.type===d.DefinitionEntity&&((a=this.entity)==null?void 0:a.parent)===this&&((c=this.entity)==null||c.clearErrors()),this}validate(){return this.errors=Gke(this),{success:!0}}async validateAsync(i={}){const r=Y.YieldTracker.from(i);return this.errors=await Mke(this,{tracker:r}),{success:!0}}getErrors(){var r,a;return[...this.errors,...((r=this.andChildrenGroup)==null?void 0:r.flatMap(c=>c.getErrors()))||[],...((a=this.orChildrenGroup)==null?void 0:a.flatMap(c=>c.getErrors()))||[]]}async getErrorsAsync(i={}){const r=Y.YieldTracker.from(i),a=[...this.errors];await r.tick();for(const c of this.andChildrenGroup||[]){const e=await c.getErrorsAsync({tracker:r});a.push(...e)}for(const c of this.orChildrenGroup||[]){const e=await c.getErrorsAsync({tracker:r});a.push(...e)}return a}getShallowErrors(){return this.errors}clone(i=this.project.addChangeSet(new S(this.project,x.sessionAuthor,B().toISOString(),this,!0,w.CloneEntity)),r=null,a=null,c=!0){var _,P,V,j;const e=Ur(r,this),f=r||this.parent,m={id:a||x.UUID.uuid(),version:x.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||B().toISOString(),author:(i==null?void 0:i.author)||"1",previousVersion:null,deleted:!1,deletable:!0,editable:!0,type:d.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:((_=this.foreignKeyRef)==null?void 0:_.toReference())||null,andChildrenGroup:null,orChildrenGroup:null,entity:null,parent:f.toReference()},E=nr(m,e);E.hydrateAncestors(),E.setParent(f,null),c&&(E.subscribe(),E.addSelfToProject(i)),E.initChildren(i),i==null||i.add(E,W.Added);const b=(P=this.andChildrenGroup)==null?void 0:P.map(M=>this.project.diggestedBuiltInBaseEntitiesIds.has(M.id)?e.getBuiltIn(M.id):M.clone(i,E,x.UUID.uuid(),c)),A=(V=this.orChildrenGroup)==null?void 0:V.map(M=>this.project.diggestedBuiltInBaseEntitiesIds.has(M.id)?e.getBuiltIn(M.id):M.clone(i,E,x.UUID.uuid(),c));if(E.andChildrenGroup=b||null,E.orChildrenGroup=A||null,this.entity&&this.entity.type===d.DefinitionEntity&&((j=this.entity)==null?void 0:j.parent)===this)if(this.project.diggestedBuiltInBaseEntitiesIds.has(this.entity.id))E.setEntity(this.entity,i);else{const M=this.entity.clone(i,E,x.UUID.uuid(),c);E.setEntity(M,i)}else if(this.entity){const M=e.get(this.entity.id)||e.getBuiltIn(this.entity.id);E.setEntity(M,i)}return i||E.captureVersion(),i==null||i.attemptAutoclose(w.CloneEntity,this.id),E}merge(i,r=this.project.addChangeSet(new S(this.project,x.sessionAuthor,B().toISOString(),this,!0,w.MergeDataTypes)),a){var b,A,_,P,V,j,M;const c=[],e=[],f=[],h=[],m={implementSource:!1,...a};if(!this.checkCanEdit(this,r))return Y.Logger.warn(`[${w.MergeDataTypes}] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),r==null||r.attemptAutoclose(w.MergeDataTypes,this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.asType!==(i==null?void 0:i.asType)&&(m.implementSource?(i==null?void 0:i.asType)!==null&&this.metaSync({asType:i==null?void 0:i.asType},r):this.metaSync({asType:i==null?void 0:i.asType},r),c.push(this)),this.index!==(i==null?void 0:i.index)&&!m.implementSource&&(this.metaSync({index:i==null?void 0:i.index},r),r==null||r.add(this,W.Updated),c.push(this)),this.options&&!(i!=null&&i.options)||!this.options&&(i!=null&&i.options)||!((b=i==null?void 0:i.options)!=null&&b.every(G=>{var q;return(q=this.options)==null?void 0:q.includes(G)}))){if(m.implementSource){if(((A=i==null?void 0:i.entity)==null?void 0:A.id)===ne["primitive-entity"].enum.id){const G=new Set(this.options||[]);((i==null?void 0:i.options)||[]).forEach(q=>G.add(q)),this.metaSync({options:Array.from(G)},r)}}else this.metaSync({options:i==null?void 0:i.options},r);r==null||r.add(this,W.Updated),c.push(this)}if(this.foreignKeyAllowed!==(i==null?void 0:i.foreignKeyAllowed)&&(m.implementSource?(i==null?void 0:i.foreignKeyAllowed)!==null&&(this.metaSync({foreignKeyAllowed:i==null?void 0:i.foreignKeyAllowed},r),c.push(this)):(this.metaSync({foreignKeyAllowed:i==null?void 0:i.foreignKeyAllowed},r),c.push(this))),this.isList!==(i==null?void 0:i.isList)&&(m.implementSource?(i==null?void 0:i.isList)!==null&&(this.metaSync({isList:i==null?void 0:i.isList},r),c.push(this)):(this.metaSync({isList:i==null?void 0:i.isList},r),c.push(this))),this.like!==(i==null?void 0:i.like)&&(m.implementSource?(i==null?void 0:i.like)!==null&&(this.metaSync({like:i==null?void 0:i.like},r),c.push(this)):(this.metaSync({like:i==null?void 0:i.like},r),c.push(this))),((_=i==null?void 0:i.foreignKeyRef)==null?void 0:_.id)!==((P=this.foreignKeyRef)==null?void 0:P.id)&&(m.implementSource&&this.foreignKeyRef?di(this,i).compatible||(this.setForeignKeyRef((i==null?void 0:i.foreignKeyRef)||null,r),r==null||r.add(this,W.Updated),c.push(this),[...this.andChildrenGroup||[],...this.orChildrenGroup||[]].forEach(q=>{this.removeChildGroup(q,r),f.push(q)}),this.setEntity(null,r)):(this.setForeignKeyRef((i==null?void 0:i.foreignKeyRef)||null,r),r==null||r.add(this,W.Updated),c.push(this),[...this.andChildrenGroup||[],...this.orChildrenGroup||[]].forEach(G=>{this.removeChildGroup(G,r),f.push(G)}),this.setEntity(null,r))),i!=null&&i.entity&&(i==null?void 0:i.entity.type)===d.DefinitionEntity&&(i==null?void 0:i.entity).parent===i)if(((V=this.entity)==null?void 0:V.type)===d.DefinitionEntity&&this.entity.parent===this)XT(this.entity,i.entity)||(Rx(this.entity,i.entity,r),c.push(this.entity),[...this.andChildrenGroup||[],...this.orChildrenGroup||[]].forEach(G=>{this.removeChildGroup(G,r),f.push(G)}),this.andChildrenGroup=null,this.orChildrenGroup=null,this.setForeignKeyRef(null,r));else{const G=i.entity.clone(r,this,x.UUID.uuid(),!0);this.setEntity(G,r),e.push(G),[...this.andChildrenGroup||[],...this.orChildrenGroup||[]].forEach(q=>{this.removeChildGroup(q,r),f.push(q)}),this.andChildrenGroup=null,this.orChildrenGroup=null,this.setForeignKeyRef(null,r)}else((j=i==null?void 0:i.entity)==null?void 0:j.id)!==((M=this.entity)==null?void 0:M.id)&&(m.implementSource&&this.entity?di(this,i).compatible||(this.setEntity((i==null?void 0:i.entity)||null,r),r==null||r.add(this,W.Updated),c.push(this),[...this.andChildrenGroup||[],...this.orChildrenGroup||[]].forEach(q=>{this.removeChildGroup(q,r),f.push(q)}),this.andChildrenGroup=null,this.orChildrenGroup=null,this.setForeignKeyRef(null,r)):(this.setEntity((i==null?void 0:i.entity)||null,r),r==null||r.add(this,W.Updated),c.push(this),[...this.andChildrenGroup||[],...this.orChildrenGroup||[]].forEach(G=>{this.removeChildGroup(G,r),f.push(G)}),this.andChildrenGroup=null,this.orChildrenGroup=null,this.setForeignKeyRef(null,r)));this.inferred!==(i==null?void 0:i.inferred)&&(m.implementSource?(i==null?void 0:i.inferred)!==null&&(this.metaSync({inferred:(i==null?void 0:i.inferred)??!1},r),c.push(this)):(this.metaSync({inferred:(i==null?void 0:i.inferred)??!1},r),c.push(this)));const E=di(this,i);if(m.implementSource&&E.compatible&&(this.entity||this.foreignKeyRef))return r==null||r.attemptAutoclose(w.MergeDataTypes,this.id),{added:C(e),updated:C(c),removed:C(f),affected:C(h),self:this};if(i!=null&&i.orChildrenGroup&&Array.isArray(i==null?void 0:i.orChildrenGroup)&&!this.entity){let G=!1;if(m.implementSource&&i!=null&&i.implementationChooseOne&&(this.metaSync({implementationChooseOne:!1},r),G=!0,i.orChildrenGroup.find(re=>di(this,re).exact)||(this.orChildrenGroup=null,this.chooseOneFromOrGroupAndApply(i,r))),!G){const q=[...i==null?void 0:i.orChildrenGroup];this.orChildrenGroup=this.orChildrenGroup||[];const re=[...this.orChildrenGroup||[]];for(;q.length>0;){const ee=q.shift();let se=re==null?void 0:re.find(te=>di(te,ee).exact);if(se||(se=re==null?void 0:re.find(te=>di(te,ee))),!se){const te=q.findIndex(le=>re==null?void 0:re.some(ue=>di(ue,le).exact));if(te!==-1){const[le]=q.splice(te,1);se=re==null?void 0:re.find(ue=>di(ue,le).exact)}}if(se){const te=re.indexOf(se);te!==-1&&re.splice(te,1);const le=se.merge(ee,r,{implementSource:m.implementSource});c.push(...le.updated),e.push(...le.added),f.push(...le.removed),h.push(...le.affected)}else if(m.implementSource){const te=ee.implement(this,r,x.UUID.uuid(),ze.OrDataTypeGroup);this.addToOrGroup(te,r),e.push(te)}else{const te=ee.clone(r,this,x.UUID.uuid(),!0);this.addToOrGroup(te,r),e.push(te)}}[...this.orChildrenGroup||[]].forEach(ee=>{((i==null?void 0:i.orChildrenGroup)||[]).find(te=>di(ee,te))||(ee.remove({ignoreUpstream:!1},r),f.push(ee))})}}return i!=null&&i.andChildrenGroup&&Array.isArray(i==null?void 0:i.andChildrenGroup)&&!this.entity&&(i==null||i.andChildrenGroup.forEach(G=>{var re;if(!((re=this.andChildrenGroup)==null?void 0:re.find(ee=>di(ee,G)))){const ee=G.clone(r,this,x.UUID.uuid(),!0);this.addToAndGroup(ee,r),e.push(ee)}}),[...this.andChildrenGroup||[]].forEach(G=>{((i==null?void 0:i.andChildrenGroup)||[]).find(re=>di(G,re))||(G.remove({ignoreUpstream:!1},r),f.push(G))})),r==null||r.attemptAutoclose(w.MergeDataTypes,this.id),{updated:C(c),added:C(e),removed:C(f),affected:C(h),self:this}}addToAndGroup(i,r=this.project.addChangeSet(new S(this.project,x.sessionAuthor,B().toISOString(),this,!0,w.AddToAndGroup))){return this.checkCanEdit(this,r)?(this.andChildrenGroup||(this.andChildrenGroup=[]),this.andChildrenGroup.includes(i)||(this.andChildrenGroup.push(i),r==null||r.add(i,W.Affected),this.entity&&this.setEntity(null,r)),r==null||r.attemptAutoclose(w.AddToAndGroup,this.id),this):(Y.Logger.warn(`[${w.AddToAndGroup}] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),r==null||r.attemptAutoclose(w.AddToAndGroup,this.id),this)}addToOrGroup(i,r=this.project.addChangeSet(new S(this.project,x.sessionAuthor,B().toISOString(),this,!0,w.AddToOrGroup))){return this.checkCanEdit(this,r)?(this.orChildrenGroup||(this.orChildrenGroup=[]),this.orChildrenGroup.includes(i)||(this.orChildrenGroup.push(i),r==null||r.add(i,W.Affected),this.entity&&this.setEntity(null,r)),r==null||r.attemptAutoclose(w.AddToOrGroup,this.id),this):(Y.Logger.warn(`[${w.AddToOrGroup}] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),r==null||r.attemptAutoclose(w.AddToOrGroup,this.id),this)}setForeignKeyRef(i,r=this.project.addChangeSet(new S(this.project,x.sessionAuthor,B().toISOString(),this,!0,w.SetDataTypeForeignKeyRef))){if(!this.checkCanEdit(this,r))return Y.Logger.warn(`[${w.SetDataTypeForeignKeyRef}] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),r==null||r.attemptAutoclose(w.SetDataTypeForeignKeyRef,this.id),this;const a=this.foreignKeyRef;return(a==null?void 0:a.id)!==(i==null?void 0:i.id)&&(this.foreignKeyRef=i,r==null||r.add(this,W.Updated)),r==null||r.attemptAutoclose(w.SetDataTypeForeignKeyRef,this.id),this}setEntity(i,r=this.project.addChangeSet(new S(this.project,x.sessionAuthor,B().toISOString(),this,!0,w.SetDataTypeEntityValue))){var c,e,f;if(!this.checkCanEdit(this,r))return Y.Logger.warn(`[${w.SetDataTypeEntityValue}] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),r==null||r.attemptAutoclose(w.SetDataTypeEntityValue,this.id),this;const a=this.entity;return(a==null?void 0:a.id)!==(i==null?void 0:i.id)&&(this.entity=i,r==null||r.add(this,W.Updated),a&&(a.type===d.DefinitionEntity||a.type===d.LiteralValue||a.type===d.ActionDescriptor)&&((c=a.parent)==null?void 0:c.id)===this.id&&(a==null||a.remove({ignoreUpstream:!0},r)),(e=this.orChildrenGroup)!=null&&e.length&&this.entity&&(this.orChildrenGroup.forEach(h=>{this.removeChildGroup(h,r)}),this.orChildrenGroup=null),(f=this.andChildrenGroup)!=null&&f.length&&this.entity&&(this.andChildrenGroup.forEach(h=>{this.removeChildGroup(h,r)}),this.andChildrenGroup=null)),r==null||r.attemptAutoclose(w.SetDataTypeEntityValue,this.id),this}isObject(){return!!this.entity&&(this.entity.type===d.DefinitionEntity||this.entity.type===d.BuiltInBaseEntity||this.entity.name===fe.KeyValue)&&!this.isList}canBeObject(){var a;let i=!1,r=!1;if(this.parent.type!==d.DataType&&this.parent.type!==d.ActionDescriptor&&this.parent.type!==d.BuiltInBaseEntity&&this.parent.type!==d.DefinitionEntity&&this.parent.type!==d.FunctionDeclaration){r=!0;const c=(a=this.project.requestActiveDynamicValue(this.parent))==null?void 0:a.value;c?!c.valueAsType&&(c.value===""||c.value===null||br(c))&&(i=!0):i=!0}return(this.isObject()||!this.entity||this.entity.name===fe.Untyped)&&(!r||r&&i)}hasStrictObjectStructure(){var i;return this.isObject()&&((i=this.entity)==null?void 0:i.type)===d.DefinitionEntity}isInlineDeclaredEntity(){var i,r;return((i=this.entity)==null?void 0:i.type)===d.DefinitionEntity&&((r=this.entity.parent)==null?void 0:r.id)===(this==null?void 0:this.id)}isIndependentlyUserDeclaredEntity(){var i,r;return((i=this.entity)==null?void 0:i.type)===d.DefinitionEntity&&((r=this.entity)==null?void 0:r.parent)!==this}canModifyObjectStructure(){var r;const i=this.isIndependentlyUserDeclaredEntity();return(this.isInlineDeclaredEntity()||this.canBeObject()||((r=this.entity)==null?void 0:r.name)===fe.KeyValue)&&!i}inferFromInputs(i,r=this.project.addChangeSet(new S(this.project,x.sessionAuthor,B().toISOString(),this,!0,"infer-data-type-from-inputs"))){var m;const a=[],c=[],e=[],f=[];if(!this.inferred)return r==null||r.attemptAutoclose("infer-data-type-from-inputs",this.id),{updated:[],added:[],removed:[],affected:[],self:this};let h=!1;if(!this.entity&&i.length){const E=oe(this.parent,this.project)+" data type definition",b={id:x.UUID.uuid(),deletable:!0,editable:!0,type:d.DefinitionEntity,version:x.UUID.uuid(),createdAt:(r==null?void 0:r.timestamp)||B().toISOString(),author:x.sessionAuthor,previousVersion:null,deleted:!1,name:E,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()},A=ge(b,this.project);A.hydrateAncestors(),A.setParent(this,r),A.initChildren(r),r==null||r.add(A,W.Added),A.metaSync(b,r),this.setEntity(A,r),r||A.captureVersion(),r==null||r.add(this,W.Updated),h=!0}if(this.entity){const{updated:E,added:b,removed:A,affected:_}=this.entity.inferFromInputs(i,r);c.push(...E),a.push(...b),e.push(...A),f.push(..._),h&&(r||this.entity.captureVersion())}return this.like||this.metaSync({like:!0},r),r==null||r.attemptAutoclose("infer-data-type-from-inputs",this.id),{updated:C(c),added:C(a),removed:C(e),affected:C(f),self:this}}bestEffortClearIncompatibleProperties(i=this.project.addChangeSet(new S(this.project,x.sessionAuthor,B().toISOString(),this,!0,"best-effort-clear-incompatible-properties"))){var f,h,m,E;const r=[],a=[],c=[],e=[];if(this.entity&&this.andChildrenGroup&&this.andChildrenGroup.length===0&&this.orChildrenGroup&&this.orChildrenGroup.length===0?(this.andChildrenGroup=null,this.orChildrenGroup=null,i==null||i.add(this,W.Updated),a.push(this)):!this.entity&&this.andChildrenGroup&&this.orChildrenGroup&&(((f=this.andChildrenGroup)==null?void 0:f.length)>0&&((h=this.orChildrenGroup)==null?void 0:h.length)===0?this.andChildrenGroup=null:((m=this.orChildrenGroup)==null?void 0:m.length)>0&&((E=this.andChildrenGroup)==null?void 0:E.length)===0&&(this.orChildrenGroup=null)),this.entity&&this.foreignKeyRef)return i==null||i.attemptAutoclose("best-effort-clear-incompatible-properties",this.id),{updated:C(a),added:C(r),removed:C(c),affected:C(e),self:this};if((this.entity||this.foreignKeyRef)&&this.orChildrenGroup&&this.orChildrenGroup.length>0){for(const b of this.orChildrenGroup)if(di(this,b).compatible){this.orChildrenGroup=null,i==null||i.add(this,W.Updated),a.push(this);break}}return i==null||i.attemptAutoclose("best-effort-clear-incompatible-properties",this.id),{updated:C(a),added:C(r),removed:C(c),affected:C(e),self:this}}chooseOneFromOrGroupAndApply(i,r=this.project.addChangeSet(new S(this.project,x.sessionAuthor,B().toISOString(),this,!0,"choose-one-from-or-group-and-apply"))){var c;if(!i.orChildrenGroup||!Array.isArray(i.orChildrenGroup)||i.orChildrenGroup.length===0)return r==null||r.attemptAutoclose("choose-one-from-or-group-and-apply",this.id),null;const a=i.orChildrenGroup.some(e=>e.foreignKeyAllowed);if(((c=this.entity)==null?void 0:c.type)===d.DefinitionEntity&&si(this.entity,Ae.PERSISTED_ENTITY)&&a){const e=cKe(this.entity);e&&this.setForeignKeyRef(e,r),this.setEntity(null,r)}else{const e=i.orChildrenGroup.find(f=>{var h;return((h=f.entity)==null?void 0:h.id)===ne["primitive-entity"].string.id});if(e)this.setEntity(e.entity,r);else{const f=i.orChildrenGroup.filter(m=>m.isResolved),h=f.filter(m=>{var E;return((E=m.entity)==null?void 0:E.type)===d.PrimitiveEntity});h.length?this.setEntity(h[0].entity,r):f.length&&this.setEntity(f[0].entity,r)}}return r==null||r.attemptAutoclose("choose-one-from-or-group-and-apply",this.id),this}implement(i,r=this.project.addChangeSet(new S(this.project,x.sessionAuthor,B().toISOString(),this,!0,"implement-self-as-data-type")),a=null,c=null){const e=Ur(i,this),f=a||x.UUID.uuid(),h=Vi.new(r);h.id=f,h.like=this.like,h.asType=this.asType,h.isList=this.isList,h.options=this.options,h.parentRelationType=this.parentRelationType,h.foreignKeyAllowed=this.foreignKeyAllowed,h.staticEntities=this.staticEntities,h.interactiveEntities=this.interactiveEntities,h.actionEntities=this.actionEntities,h.parent=i.toReference(),h.parentRelationType=c;const m=ge(h,e);return m.hydrateAncestors(),m.addSelfToProject(r),r==null||r.add(m,W.Added),m.initChildren(r),m.merge(this,r,{implementSource:!0}),r||m.captureVersion(),r==null||r.attemptAutoclose("implement-self-as-data-type",this.id),m}};R(Vi,"repository",{APICreate:async(i,...r)=>i,APIUpdate:async(i,...r)=>i,APIDelete:async(i,...r)=>i,APIClone:async(i,...r)=>{},APILoad:async(i,...r)=>null,APILoadVersion:async(i,r,...a)=>null}),R(Vi,"type",d.DataType),R(Vi,"USER_MANAGED_PARENT_TYPES",[...RV]),R(Vi,"PARENT_TYPES",[..._F]),R(Vi,"MUTABLE_BASE_PROPERTIES",["isList","asType","options","foreignKeyAllowed","like","implementationChooseOne","staticEntities","interactiveEntities","actionEntities"]),R(Vi,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","index","author","previousVersion","parentRelationType"]),R(Vi,"BASE_PROPERTIES",[...Vi.MUTABLE_BASE_PROPERTIES,...Vi.INMUTABLE_BASE_PROPERTIES]),R(Vi,"MUTABLE_META_PROPERTIES",[...Vi.MUTABLE_BASE_PROPERTIES,"inferred"]),R(Vi,"INMUTABLE_META_PROPERTIES",[...Vi.INMUTABLE_BASE_PROPERTIES]),R(Vi,"META_PROPERTIES",[...Vi.MUTABLE_META_PROPERTIES,...Vi.INMUTABLE_META_PROPERTIES]),R(Vi,"MUTABLE_UPSTREAM_PROPERTIES",["entity","foreignKeyRef","parent"]),R(Vi,"INMUTABLE_UPSTREAM_PROPERTIES",[]),R(Vi,"UPSTREAM_PROPERTIES",[...Vi.MUTABLE_UPSTREAM_PROPERTIES,...Vi.INMUTABLE_UPSTREAM_PROPERTIES]),R(Vi,"MUTABLE_DOWNSTREAM_PROPERTIES",[]),R(Vi,"INMUTABLE_DOWNSTREAM_PROPERTIES",["andChildrenGroup","orChildrenGroup"]),R(Vi,"DOWNSTREAM_PROPERTIES",[...Vi.MUTABLE_DOWNSTREAM_PROPERTIES,...Vi.INMUTABLE_DOWNSTREAM_PROPERTIES]),R(Vi,"PROPERTIES",[...Vi.META_PROPERTIES,...Vi.UPSTREAM_PROPERTIES,...Vi.DOWNSTREAM_PROPERTIES]);let mr=Vi;async function jke(s,p={}){var c;const i=Y.YieldTracker.from(p),a=[...s.implements.flatMap(e=>bL(s,e)),...In(s),...AL(s),...Ja(s)];return await i.tick(),await((c=s.dataType)==null?void 0:c.validateAsync({tracker:i})),a}function kke(s){var r;const p=s.implements.flatMap(a=>bL(s,a));return(r=s.dataType)==null||r.validate(),[...p,...In(s),...AL(s),...Ja(s)]}function bL(s,p){const i=[];if(!s.implements)return i;if(!p.abstract){const a=gt({id:`${s.id}--${be.PropertyImplementsNonAbstact}`,message:`Property "${oe(s,s.project)}" with id "${s.id}" implements a non-abstract property "${oe(p,s.project)}" with id "${p.id}".`,severity:Te.Error,code:be.PropertyImplementsNonAbstact,entity:s,firstRelationship:p});i.push(a.error)}if(s.static&&!p.static){const a=gt({id:`${s.id}--${be.NonStaticPropertyImplementsStatic}`,message:`Static property "${oe(s,s.project)}" with id "${s.id}" implements a non-static property "${oe(p,s.project)}" with id "${p.id}".`,severity:Te.Error,code:be.NonStaticPropertyImplementsStatic,entity:s,firstRelationship:p});i.push(a.error)}if(!s.static&&p.static){const a=gt({id:`${s.id}--${be.StaticPropertyImplementsNonStatic}`,message:`Non-static property "${oe(s,s.project)}" with id "${s.id}" implements a static property "${oe(p,s.project)}" with id "${p.id}".`,severity:Te.Error,code:be.StaticPropertyImplementsNonStatic,entity:s,firstRelationship:p});i.push(a.error)}if(!di(s.dataType,p.dataType)){const a=gt({id:`${s.id}--${be.PropertyImplementsIncompatibleType}`,message:`Property "${oe(s,s.project)}" with id "${s.id}" implements a property "${oe(p,s.project)}" with id "${p.id}" that has an incompatible data type.`,severity:Te.Error,code:be.PropertyImplementsIncompatibleType,entity:s,firstRelationship:p});i.push(a.error)}return St(s.errors,i)}function AL(s,p){const r=[...s.parent.allProperties].filter(a=>{var c;return a.id!==s.id&&!s.implements.find(e=>e.id===a.id)&&a.id!==((c=s.extends)==null?void 0:c.id)});return QE(s,[Xi],r,p)}const gVi=Object.freeze(Object.defineProperty({__proto__:null,validate:kke,validateAsync:jke,validateImplementation:bL,validatePropertyEntityName:AL},Symbol.toStringTag,{value:"Module"}));function IVi(s,p){const i=[],r=[],a=Vke(s,p);if(s.parent){const e=p.get(s.parent);if(!e)r.push(new De({id:`${s.id}--${s.parent}--${he.ReferencedEntityNotFound}`,code:he.ReferencedEntityNotFound,severity:Te.Error,message:`Entity of type "${s.type}" with id "${s.id}", is referencing an entity with id "${s.parent}" at 'parent' that isn't yet found in the project. Perhaps it should be created first. Or perhaps the ID is incorrect.`}));else{const f=du(e);if(f){const h=e!==f?`The entity of type '${s.type}' with id '${s.id}' have 'parent' with id '${s.parent}' because the entity belongs to a built-in '${f.type}' entity with id '${f.id}' (${oe(f,e.project)}) higher up in the tree.`:`The entity of type '${s.type}' with id '${s.id}' have 'parent' with id '${s.parent}' because it is a built-in entity of type ${f.type}.`;r.push(new De({id:`${s.id}--${he.InvalidBuiltInEntityReference}`,code:he.InvalidBuiltInEntityReference,severity:Te.Error,message:h}))}else if(![d.DefinitionEntity].includes(e.type))r.push(new De({id:`${s.id}--${s.parent}--${he.InvalidParentReference}`,code:he.InvalidParentReference,severity:Te.Error,message:`Entity of type "${s.type}" with id "${s.id}", has a parent reference which is of type ${e.type}, and therefore that isn't pointing to the following valid types for this reference: 'definition-entity'.`}));else{const m=Xn(e).filter(E=>!E.interactive);if(m.length){let E=m.length>1?`The entity of type '${s.type}' with id '${s.id}' can't be added to the 'parent' entity with id '${e.id}' because it extends or implements multiple '${d.BuiltInBaseEntity}' entities that are non-interactive ("${vt(m.map(b=>oe(b,b.project)),'", "','" and "')}").`:`The entity of type '${s.type}' with id '${s.id}' can't be added to the 'parent' entity with id '${e.id}' because it extends or implements a '${d.BuiltInBaseEntity}' entity that is non-interactive ("${oe(m[0],m[0].project)}").`;i.push({id:Yi.NonInteractiveBaseEntities,message:lu}),r.push(new De({id:`${s.id}--${he.NonInteractiveEntityReferenced}`,code:he.NonInteractiveEntityReferenced,severity:Te.Error,message:E}))}else s.implements&&s.implements.forEach(E=>{const b=p.get(E);if(E===s.id)return r.push(new De({id:`${s.id}--${E}--${he.SelfReference}`,code:he.SelfReference,severity:Te.Error,message:`Entity of type "${s.type}" with id "${s.id}", has a reference to itself at 'implements'. This is not allowed. Change the reference string or the 'entityId' property of the reference object.`})),r;b?[d.Property].includes(b.type)?b.abstract||r.push(new De({id:`${s.id}--${E}--${he.InvalidImplementsReference}`,code:he.InvalidImplementsReference,severity:Te.Error,message:`Entity of type "${s.type}" with id "${s.id}", has an 'implements' reference that isn't pointing to an abstract entity.`})):r.push(new De({id:`${s.id}--${E}--${he.InvalidImplementsReference}`,code:he.InvalidImplementsReference,severity:Te.Error,message:`Entity of type "${s.type}" with id "${s.id}", has an 'implements' reference which is of type ${b.type}, and therefore that isn't pointing to the following valid types for this reference: 'property'.`})):r.push(new De({id:`${s.id}--${E}--${he.ReferencedEntityNotFound}`,code:he.ReferencedEntityNotFound,severity:Te.Error,message:`Entity of type "${s.type}" with id "${s.id}", is referencing an entity with id "${E}" at 'implements' that isn't yet found in the project. Perhaps it should be created first. Or perhaps the ID is incorrect.`}))})}}}else r.push(new De({id:`${s.id}--${Ce.InvalidObjectStructure}`,code:Ce.InvalidObjectStructure,severity:Te.Error,message:`Entity of type "${s.type}" with id "${s.id}" is missing a 'parent' reference. The 'parent' of a 'property' entity must be a reference to an entity of type 'definition-entity'.`}));const c=Ln(s,{},p);return i.push(...c.explanations),r.length>0&&i.push(...a.explanations),r.push(...c.errors),{errors:r,explanations:i}}function yF(s){var p,i,r,a,c,e,f,h,m,E,b,A;if(((i=(p=s.dataType)==null?void 0:p.entity)==null?void 0:i.type)===d.PrimitiveEntity&&((a=(r=s.dataType)==null?void 0:r.entity)==null?void 0:a.id)===((c=ne["primitive-entity"].enum)==null?void 0:c.id)){if(((e=s.dataType.options)==null?void 0:e.length)===1){const _=s.dataType.options[0];if(_)return{result:!0,value:_,name:fe.String}}}else if(((h=(f=s.dataType)==null?void 0:f.entity)==null?void 0:h.type)===d.LiteralValue&&[fe.String,fe.Number,fe.UUID,fe.Boolean,fe.Date,fe.Bytes].includes((E=(m=s.dataType)==null?void 0:m.entity)==null?void 0:E.name)&&typeof((A=(b=s.dataType)==null?void 0:b.entity)==null?void 0:A.value)=="string")return{result:!0,value:s.dataType.entity.value,name:s.dataType.entity.name};return{result:!1,value:null,name:null}}function RVi(s){return!!s.implements.find(p=>p.id===ne["built-in-base-entity"].BUILT_IN_PERSISTED_ENTITY_ENTITY.properties.database.id)}function hF(s,p){const i=[],r=[],a=[],c=[];let e=!1;if(s.implements.find(f=>f.id===ne["built-in-base-entity"].BUILT_IN_PERSISTED_ENTITY_ENTITY.properties.database.id)){let f=s.defaultValue;if(!s.defaultValue){const h=Nr.new(p);h.name=fe.EntityTemplate,h.parent=s.toReference();const m=ge(h,s.project);m.hydrateAncestors(),m.addSelfToProject(p),p==null||p.add(m,W.Added),r.push(m),m.initChildren(p),f=m,e=!0}if(!f.valueAsTypeSingle){const h=hKe(s.project);h&&f.setValueAsTypeSingle(h,p)}e&&(p||f==null||f.captureVersion())}return{updated:C(i),added:C(r),removed:C(a),affected:C(c),self:s}}var Uke=(s=>(s.PropertyImplements="property-implements-field",s.PropertyExtends="property-extends-field",s.PropertyDataTypeEntity="property-data-type-entity-field",s.PropertyDataType="property-data-type-field",s))(Uke||{});const yi=class yi extends dn{constructor(i,r){super(i);R(this,"initialData");R(this,"id");R(this,"name");R(this,"codeName",null);R(this,"description",null);R(this,"private");R(this,"abstract");R(this,"index");R(this,"static");R(this,"unique");R(this,"required");R(this,"constant",!1);R(this,"interactive",!1);R(this,"type",d.Property);R(this,"hidden",!1);R(this,"parentRelationType",null);R(this,"defaultValue",null);R(this,"dataType",null);R(this,"implements",[]);R(this,"extends",null);R(this,"project");R(this,"errors",[]);R(this,"parent");R(this,"detachedDependents",{});R(this,"knownVersions",null);R(this,"activeVersion",!1);R(this,"initialized",!1);R(this,"startedInitialization",!1);R(this,"suggestion",!1);R(this,"_codeNativeValueValidation",null);this.initialData=i,this.project=r,this.id=i.id,this.name=i.name,this.description=i.description,this.private=i.private,this.abstract=i.abstract,this.index=i.index,this.static=i.static,this.required=i.required||!1,this.unique=i.unique||!1,this.codeName=i.codeName,this.hidden=i.hidden||!1,this.constant=i.constant||!1,this.interactive=i.interactive||!1,this.onProjectInitialized=this.onProjectInitialized.bind(this)}static new(i=null){return{id:x.UUID.uuid(),version:x.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||B().toISOString(),author:(i==null?void 0:i.author)||x.sessionAuthor,previousVersion:null,deleted:!1,deletable:!0,editable:!0,unique:!1,type:d.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:!0,defaultValue:null,parent:null}}static fromGenerationTarget(i,r,a){const c=a===void 0?r.addChangeSet(new S(r,x.sessionAuthor,B().toISOString(),r,!0,w.CreateFromGenerationTarget)):a,e=ie(i.parent),f=r.get(e),h=[];i.implements&&i.implements.forEach(A=>{h.push(r.get(A)||r.getBuiltIn(A))});let m=null;if(i.extends){const A=ie(i.extends);m=r.get(A)}const E={id:i.id,version:x.UUID.uuid(),createdAt:(c==null?void 0:c.timestamp)||B().toISOString(),author:(c==null?void 0:c.author)||x.sessionAuthor,previousVersion:null,deleted:!1,name:i.name,deletable:!0,editable:!0,type:d.Property,index:f.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??!0,hidden:!1,codeName:i.codeName||null,description:i.description||null,defaultValue:null,implements:h,extends:(m==null?void 0:m.toShallowJSON())||null,dataType:null,parent:f.toReference()},b=ge(E,r);return b.hydrateAncestors(),b.setParent(f,c),b.addSelfToProject(c),c==null||c.add(b,W.Added),b.initChildren(c),c||b.captureVersion(),b}static validateGenerationTarget(i,r){let a=JSON.parse(JSON.stringify(i));const c=[],e=[],f=IVi(a,r),h=xx(a,r),m=Qr(a);return e.push(...f.errors,...h,...m.errors),c.push(...f.explanations,...m.explanations),{errors:e,explanations:c,modifiedData:a}}get isExtendedProperty(){const i=this.parent.allBasePropertiesFromExtendedAndImplementedEntities.find(r=>{var a;return r.id===((a=this.extends)==null?void 0:a.id)});return!!i&&i.id!==this.id&&!i.abstract}get codeNativeValueValidation(){const i=[...this.implements].filter(a=>!this.implements.filter(f=>f.id!==a.id).some(f=>!!f.implements.find(h=>h.id===a.id)));return this._codeNativeValueValidation||(i==null?void 0:i.some(a=>a.codeNativeValueValidation))?(a,c)=>{const e=[];let f=c;if(this._codeNativeValueValidation){const h=this._codeNativeValueValidation(a,c);h&&(e.push(...h.errors),f=h.override)}return i.forEach(h=>{const m=h.codeNativeValueValidation;if(m){const E=m(a,c);E&&(e.push(...E.errors),f=E.override)}}),{errors:AE(e),override:f}}:null}validateGeneratedUpdate(i){const r=[],a=[];return i.parent&&r.push(new De({id:`${this.id}--${he.InvalidParentUpdate}`,code:he.InvalidParentUpdate,severity:Te.Error,message:`Entity of type '${this.type}' with id '${this.id}' cannot have the 'parent' property updated, as it would mean moving the '${this.type}' entity to another parent entity.
535
535
  This is likely an incorrect strategy, either the '${this.type}' entity doesn't need to be updated or it should be deleted and a new one created in the desired parent.`})),(i.readsValue||i.writesValue)&&(r.push(new De({id:`${this.id}--${Ce.InvalidObjectStructure}`,code:Ce.InvalidObjectStructure,severity:Te.Error,message:`Entity of type '${this.type}' with id '${this.id}' is not a value reading or writing entity.`})),a.push({id:Yi.EntitiesWithValues,message:_h})),{errors:r,explanations:a,modifiedData:i}}onProjectInitialized(i,r=this.project.addChangeSet(new S(this.project,x.sessionAuthor,new Date().toISOString(),this,!0,"on-property-received-project-initialized"))){return r?(hF(this,r),r==null||r.attemptAutoclose("on-property-received-project-initialized",this.id),this):this}subscribeDependents(i){return i.forEach(r=>{this.detachedDependents[r.entity.id]||(this.detachedDependents[r.entity.id]=r)}),this}unsubscribeDependents(i){return i.forEach(r=>{this.detachedDependents[r.entity.id]&&delete this.detachedDependents[r.entity.id]}),this}syncDependents(i=this.project.addChangeSet(new S(this.project,x.sessionAuthor,B().toISOString(),this,!0,"sync-dependents"))){const r=[],a=[],c=[],e=[];return Object.values(this.detachedDependents).forEach(f=>{const h=f.entity.afterAllChildrenInitialized(i);r.push(...h.updated),a.push(...h.added),c.push(...h.removed),e.push(...h.affected)}),i==null||i.attemptAutoclose("sync-dependents",this.id),{updated:C(r),added:C(a),removed:C(c),affected:C(e),self:this}}onDetachedDependencyRemoved(i,r,a){const c=[],e=[],f=[],h=[];if(r==="property-implements-field"&&(this.removeImplementation(i,a),c.push(this)),r==="property-extends-field"){const{updated:m,added:E,removed:b,affected:A}=this.remove({ignoreUpstream:!1},a);c.push(...m),e.push(...E),f.push(...b),h.push(...A)}return{updated:C(c),added:C(e),removed:C(f),affected:C(h),self:this}}onDetachedDependencyRestored(i,r,a){const c=[],e=[],f=[],h=[];if(r==="property-implements-field"&&(this.addImplementation(i,a),c.push(this)),r==="property-extends-field"){const{updated:m,added:E,removed:b,affected:A}=this.restore({},a);c.push(...m),e.push(...E),f.push(...b),h.push(...A)}return{updated:C(c),added:C(e),removed:C(f),affected:C(h),self:this}}unsubscribeFromDependencies(){var i,r,a,c,e,f,h;return this.implements.forEach(m=>{this.project.getBuiltIn(m.id)||m.unsubscribeDependents([{entity:this,field:"property-implements-field"}])}),(r=(i=this.extends)==null?void 0:i.unsubscribeDependents)==null||r.call(i,[{entity:this,field:"property-extends-field"}]),(e=(c=(a=this.dataType)==null?void 0:a.entity)==null?void 0:c.unsubscribeDependents)==null||e.call(c,[{entity:this,field:"property-data-type-entity-field"}]),(h=(f=this.dataType)==null?void 0:f.unsubscribeDependents)==null||h.call(f,[{entity:this,field:"property-data-type-field"}]),this.project.off(li.PROJECT_INITIALIZED,this.onProjectInitialized),this}subscribeToDependencies(){var i,r,a,c,e,f,h;return this.implements.forEach(m=>{this.project.getBuiltIn(m.id)||m.subscribeDependents([{entity:this,field:"property-implements-field"}])}),(r=(i=this.extends)==null?void 0:i.subscribeDependents)==null||r.call(i,[{entity:this,field:"property-extends-field"}]),(e=(c=(a=this.dataType)==null?void 0:a.entity)==null?void 0:c.subscribeDependents)==null||e.call(c,[{entity:this,field:"property-data-type-entity-field"}]),(h=(f=this.dataType)==null?void 0:f.subscribeDependents)==null||h.call(f,[{entity:this,field:"property-data-type-field"}]),RVi(this)&&this.project.on(li.PROJECT_INITIALIZED,this.onProjectInitialized),this}increaseVersion(i){var r;if(this.project.diggestedBuiltInBaseEntitiesIds.has(this.id))return this;if(i&&!B(i).isValid())throw new Error(`The shared timestamp '${i}' is not a valid ISO 8601 date string.`);if(i&&B(i).isSame(B(this.createdAt)))return this;if(!((r=this.knownVersions)!=null&&r.has(this.version))&&this.project.initialized)throw new Error(`The current ${this.type} ${this.id} version '${this.version}' is not captured in the 'knownVersions' map. Capture the current version before increasing it to avoid losing data.`);if(!this.activeVersion)throw new Error(`Only active versions can be increased. Entity with id '${this.id}' and version '${this.version}' is not active.`);return this.previousVersion=this.version,this.version=x.UUID.uuid(),this.createdAt=B(i).toISOString()||B().toISOString(),this}captureVersion(){var r;const i=((r=this.knownVersions)==null?void 0:r.get(this.version))||new yi(this,this.project);if(!this.activeVersion)throw new Error(`Only active versions can be captured. Entity of type ${this.type} with id '${this.id}' and version '${this.version}' is not active.`);if(this.version!==i.version)throw new Error(`Captured ${this.type} with id '${this.id}', version '${i.version}' does not match current entity version '${this.version}'.`);return this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,i):new Map().set(this.version,i),this.apply(i),this}snapshot(){const i=new yi(this,this.project);return this.apply(i)}apply(i){const r=this.toMeta();return i.metaSync(r,null),i.defaultValue=this.defaultValue,i.dataType=this.dataType,i.implements=[...this.implements],i.extends=this.extends,i.parent=this.parent,i}recursiveCaptureUpstreamVersions(i){const r=[],a=[],c=[],e=[];if(this.parent&&this.parent.type!==d.PrimitiveEntity&&this.parent.type!==d.BuiltInBaseEntity){this.parent.increaseVersion(i);const f=this.parent.recursiveCaptureUpstreamVersions(i);r.push(this.parent,...f.updated),a.push(...f.added),c.push(...f.removed)}return{updated:C(r),added:C(a),removed:C(c),affected:C(e),self:this}}async restoreVersion(i,r){var m;const a=[],c=[],e=[],f=[];if(this.version===i&&(r!=null&&r.skipIfSameVersion))return{updated:C(a),added:C(c),removed:C(e),affected:C(f),self:this};if(!this.knownVersions){const E=new Map;for(const[b,A]of this.knownVersions||new Map){if(E.set(b,A),A.activeVersion=!1,A.knownVersions)for(const[_,P]of A.knownVersions)E.set(_,P);A.knownVersions=null}}let h=(m=this.knownVersions)==null?void 0:m.get(i);if(!h){const E=await this.APILoadVersion({},i);if(!E)throw new Error(`Version with id '${i}' for entity with id '${this.id}' not found.`);h=new yi(E,this.project)}return this.metaSync(h.toShallowJSON(),null),this.previousVersion=h.previousVersion,this.version=h.version,this.createdAt=h.createdAt,this.author=h.author,this.deleted=h.deleted,this.defaultValue=h.defaultValue,this.dataType=h.dataType,this.implements=[...h.implements],this.parent=h.parent,{updated:C(a),added:C(c),removed:C(e),affected:C(f),self:this}}updateWithShallowTransfer(i,r=this.project.addChangeSet(new S(this.project,x.sessionAuthor,B().toISOString(),this,!0,w.UpdateWithShallowTransfer))){if(!this.checkCanEdit(this,r))return Y.Logger.warn(`[updateWithShallowTransfer] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),r==null||r.attemptAutoclose(w.UpdateWithShallowTransfer,this.id),this;if(this.metaSync(i,r),this.version=i.version,this.createdAt=i.createdAt,this.author=i.author,this.deleted=i.deleted,this.previousVersion=i.previousVersion,this.unsubscribeFromDependencies(),i.parent){const c=ie(i.parent),e=this.project.get(c),f=this.parent;if(f&&f.id!==(e==null?void 0:e.id)&&this.removeFromParent(r),e)this.setParent(e,r),this.addSelfToProject(r);else throw r==null||r.attemptAutoclose(w.UpdateWithShallowTransfer,this.id),new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${c}' that isn't found in the project`)}else throw r==null||r.attemptAutoclose(w.UpdateWithShallowTransfer,this.id),new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(i.implements.forEach(c=>{const e=ie(c),f=this.project.get(e);if(f)this.addImplementation(f,r);else throw new Error(`${pr(this.type)} with id '${this.id}' has a 'implements' reference "${e}" which is missing in the project`)}),this.implements.filter(c=>{const e=ie(c);return!i.implements.find(f=>ie(f)===e)}).forEach(c=>{this.removeImplementation(c,r)}),i.extends){const c=ie(i.extends),e=this.project.get(c);if(e)this.setExtends(e,r);else if(c)throw new Error(`${pr(this.type)} with id '${this.id}' has a 'extends' reference "${c}" which is missing in the project`)}else this.setExtends(null,r);if(i.dataType){const c=ie(i.dataType),e=this.project.get(c);e&&this.setDataType(e,r)}else this.setDataType(null,r);if(i.defaultValue){const c=ie(i.defaultValue),e=this.project.get(c);e&&this.setDefaultValue(e,r)}else this.setDefaultValue(null,r);return this.captureVersion(),this.subscribeToDependencies(),r==null||r.attemptAutoclose(w.UpdateWithShallowTransfer,this.id),this}updateWithGenerationTarget(i,r=this.project.addChangeSet(new S(this.project,x.sessionAuthor,B().toISOString(),this,!0,w.UpdateWithGenerationTarget))){var a;if(!this.checkCanEdit(this,r))return Y.Logger.warn(`[updateWithGenerationTarget] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),r==null||r.attemptAutoclose(w.UpdateWithGenerationTarget,this.id),this;if(this.metaSync(i,r),i.parent){const c=ie(i.parent),e=this.project.get(c),f=this.parent;if(f&&f.id!==(e==null?void 0:e.id)&&this.removeFromParent(r),e)this.setParent(e,r),this.addSelfToProject(r);else throw r==null||r.attemptAutoclose(w.UpdateWithGenerationTarget,this.id),new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${c}' that isn't found in the project`)}if((a=i.implements)==null||a.forEach(c=>{const e=ie(c),f=this.project.get(e);if(f)this.addImplementation(f,r);else throw new Error(`${pr(this.type)} with id '${this.id}' has a 'implements' reference "${e}" which is missing in the project`)}),i.implements&&this.implements.filter(e=>{const f=ie(e);return!(i.implements||[]).find(h=>ie(h)===f)}).forEach(e=>{this.removeImplementation(e,r)}),i.extends){const c=ie(i.extends),e=this.project.get(c);if(e)this.setExtends(e,r);else if(c)throw new Error(`${pr(this.type)} with id '${this.id}' has a 'extends' reference "${c}" which is missing in the project`)}else i.extends===null&&this.setExtends(null,r);return this.captureVersion(),this.subscribeToDependencies(),r==null||r.attemptAutoclose(w.UpdateWithGenerationTarget,this.id),this}hydrateAncestors(){const i=[],r=[],a=[],c=[];if(this.initialData.parent){const e=ie(this.initialData.parent),f=this.project.get(e);if(f)this.setParent(f,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 f=ie(e),h=this.project.get(f);if(h)this.addImplementation(h,null),i.push(h);else throw new Error(`${pr(this.type)} with id '${this.id}' has a 'implements' reference "${f}" which is missing in the project`)}),this.initialData.extends){const e=ie(this.initialData.extends),f=this.project.get(e);if(f)this.setExtends(f,null),i.push(f);else if(e)throw new Error(`${pr(this.type)} with id '${this.id}' has a 'extends' reference "${e}" which is missing in the project`)}return{updated:C(i),added:C(r),removed:C(a),affected:C(c),self:this}}afterAllChildrenInitialized(i=this.project.addChangeSet(new S(this.project,x.sessionAuthor,B().toISOString(),this,!0,w.AfterAllChildrenInitialized))){var q;if(!this.checkCanEdit(this,i))return Y.Logger.warn(`[afterAllChildrenInitialized] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(w.AfterAllChildrenInitialized,this.id),{updated:[],added:[],removed:[],affected:[],self:this};const r=[],a=[],c=[],e=[];if(this.initialized=!0,this.parent.type===d.DefinitionEntity&&this.parentRelationType!==Jd.AllPropertiesImplementationTarget){let re=this.index||0;const ee=this.parent.properties.filter(te=>!te.deleted&&te.id!==this.id);ee.length&&(re>ee.length+1?re=ee.length:re<0&&(re=0)),ee.find(te=>(te.index||0)===re&&!te.deleted)&&ee.filter(te=>(te.index||0)>=re&&!te.deleted).forEach(te=>{te.metaSync({index:(te.index||0)+1},i),i==null||i.add(te,W.Updated),r.push(te)}),this.metaSync({index:re},i)}if(this.defaultValue&&!this.project.diggestedBuiltInBaseEntitiesIds.has(this.id)&&this.project.diggestedBuiltInBaseEntitiesIds.has(this.defaultValue.id)){const re=this.defaultValue.clone(i,this);this.setDefaultValue(re,i)}const{updated:f,added:h,removed:m,affected:E}=this.syncWithImplementation(i);r.push(...f),a.push(...h),c.push(...m),e.push(...E);const{updated:b,added:A,removed:_,affected:P}=hF(this,i);r.push(...b),a.push(...A),c.push(..._),e.push(...P);const{updated:V,added:j,removed:M,affected:G}=this.syncWithExtension(i);return r.push(...V),a.push(...j),c.push(...M),e.push(...G),!this.project.diggestedBuiltInBaseEntitiesIds.has(this.id)&&this.project.initialized&&(this.extends&&((q=this.extends)==null?void 0:q.interactive)===!0&&(this.interactive||(this.metaSync({interactive:!0},i),r.push(this))),this.implements.every(re=>re.interactive===!0)&&(this.interactive||(this.metaSync({interactive:!0},i),r.push(this)))),i==null||i.attemptAutoclose(w.AfterAllChildrenInitialized,this.id),{updated:C(r),added:C(a),removed:C(c),affected:C(e),self:this}}addSelfToProject(i=this.project.addChangeSet(new S(this.project,x.sessionAuthor,B().toISOString(),this,!0,"add-self-to-project"))){const r=[this],a=[],c=[],e=[];return this.parentRelationType===Jd.AllPropertiesImplementationTarget?this.parent.setAllPropertiesImplement(this,i):this.parent.addProperty(this,i),r.push(this.parent),this.subscribe(),this.subscribeToDependencies(),i==null||i.attemptAutoclose("add-self-to-project",this.id),{updated:C(r),added:C(a),removed:C(c),affected:C(e),self:this}}setParent(i,r=this.project.addChangeSet(new S(this.project,x.sessionAuthor,B().toISOString(),this,!0,w.SetParent))){var a;return this.checkCanEditWithCounterpartAndSideEffects(this,i,w.SetParent,r)?(((a=this.parent)==null?void 0:a.id)!==(i==null?void 0:i.id)&&(this.parent=i,r&&(r==null||r.add(this,W.Updated))),r==null||r.attemptAutoclose(w.SetParent,this.id),this):this}addImplementation(i,r=this.project.addChangeSet(new S(this.project,x.sessionAuthor,B().toISOString(),this,!0,w.AddImplementation))){return this.checkCanEdit(this,r)?(this.implements.includes(i)||(this.implements.push(i),r==null||r.add(this,W.Updated)),r==null||r.attemptAutoclose(w.AddImplementation,this.id),this):(Y.Logger.warn(`[addImplementation] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),r==null||r.attemptAutoclose(w.AddImplementation,this.id),this)}removeImplementation(i,r=this.project.addChangeSet(new S(this.project,x.sessionAuthor,B().toISOString(),this,!0,w.RemoveImplementation))){return this.checkCanEdit(this,r)?(this.implements.includes(i)&&(this.implements=this.implements.filter(a=>a.id!==i.id),r==null||r.add(this,W.Updated)),r==null||r.attemptAutoclose(w.RemoveImplementation,this.id),this):(Y.Logger.warn(`[removeImplementation] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),r==null||r.attemptAutoclose(w.RemoveImplementation,this.id),this)}setExtends(i,r=this.project.addChangeSet(new S(this.project,x.sessionAuthor,B().toISOString(),this,!0,w.SetExtends))){var a;return this.checkCanEdit(this,r)?(((a=this.extends)==null?void 0:a.id)!==(i==null?void 0:i.id)&&(this.extends=i,this.subscribeToDependencies(),r&&(r==null||r.add(this,W.Updated))),r==null||r.attemptAutoclose(w.SetExtends,this.id),this):(Y.Logger.warn(`[setExtends] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),r==null||r.attemptAutoclose(w.SetExtends,this.id),this)}initChildren(i=this.project.addChangeSet(new S(this.project,x.sessionAuthor,B().toISOString(),this,!0,"init-children"))){if(this.initialized||this.startedInitialization)return this;if(this.startedInitialization=!0,this.initialData.defaultValue&&(this.defaultValue=ge(this.initialData.defaultValue,this.project),this.defaultValue.setParent(this,null),this.defaultValue.initChildren(i)),this.initialData.dataType){const r=ge(this.initialData.dataType,this.project);r.setParent(this,null),r.initChildren(i),this.dataType=r}if(this.implements=this.initialData.implements.map(r=>ge(r,this.project)),this.initialData.extends){const r=ge(this.initialData.extends,this.project);this.setExtends(r,null)}return this.subscribeToDependencies(),this.afterAllChildrenInitialized(i),i==null||i.attemptAutoclose("init-children",this.id),this}subscribe(){var i;return this.activeVersion=!0,(i=this.knownVersions)==null||i.forEach(r=>{r.version!==this.version&&(r.activeVersion=!1)}),this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(i,r=this.project.addChangeSet(new S(this.project,x.sessionAuthor,B().toISOString(),this,!0,"meta-sync"))){const a=en(this,i,r),c=Xr(this,a),e=this.toMeta();return this.name=a.name!==void 0?a.name:e.name,this.codeName=a.codeName!==void 0?a.codeName:e.codeName,this.description=a.description!==void 0?a.description:e.description,this.abstract=a.abstract!==void 0?a.abstract:e.abstract,this.private=a.private!==void 0?a.private:e.private,this.index=a.index||(a.index!==0?e.index:0),this.static=a.static!==void 0?a.static:e.static,this.hidden=a.hidden!==void 0?a.hidden:e.hidden,this.constant=a.constant!==void 0?a.constant:e.constant,this.interactive=a.interactive!==void 0?a.interactive:e.interactive,this.required=a.required!==void 0?a.required:e.required,this.unique=a.unique!==void 0?a.unique:e.unique,super.baseMetaSync(a,this,r),a.deleted===!0&&!e.deleted?r==null||r.add(this,W.Removed):a.deleted===!1&&e.deleted?r==null||r.add(this,W.Added):c&&(r==null||r.add(this,W.Updated)),r==null||r.attemptAutoclose("meta-sync",this.id),this}async APILoad(i=Ke,...r){return await yi.repository.APILoad(this.id,...r),this}async APICreate(i=Ke,...r){return await yi.repository.APICreate(this.toShallowJSON(),...r),this}async APIUpdate(i=Ke,...r){return await yi.repository.APIUpdate(this.toShallowJSON(),...r),this}async APIDelete(i=Ke,...r){return await yi.repository.APIDelete(this.toShallowJSON(),...r),this}async APIClone(i=Ke,...r){return await yi.repository.APIClone(this.id,...r),this}async APILoadVersion(i=Ke,r,...a){return await yi.repository.APILoadVersion(this.id,r,...a)}removeFromParent(i=this.project.addChangeSet(new S(this.project,x.sessionAuthor,B().toISOString(),this,!0,w.RemoveFromParent))){if(!this.checkCanEdit(this,i))return Y.Logger.warn(`[removeFromParent] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(w.RemoveFromParent,this.id),{added:[],updated:[],removed:[],affected:[],self:this};const r=[],a=[],c=[],e=[];return this.parent.type===d.DefinitionEntity&&(this.parentRelationType===Jd.AllPropertiesImplementationTarget?this.parent.removeAllPropertiesImplement(i):this.parent.removeProperty(this,i),e.push(this.parent)),i==null||i.attemptAutoclose(w.RemoveFromParent,this.id),{added:C(c),updated:C(r),removed:C(a),affected:C(e),self:this}}remove({ignoreUpstream:i}={ignoreUpstream:!1},r=this.project.addChangeSet(new S(this.project,x.sessionAuthor,B().toISOString(),this,!0,w.RemoveEntity))){var h;if(!this.checkCanDelete(this,r))return Y.Logger.warn(`[remove] User is not allowed to delete or edit this ${this.type} entity with id: ${this.id}`),r==null||r.event({id:`${w.RemoveEntity}-${this.id}--${Be.ActionOwnerEntityNonDeletable}`,action:w.RemoveEntity,owner:this,errorReason:Be.ActionOwnerEntityNonDeletable,rootAction:((h=r==null?void 0:r.self)==null?void 0:h.id)===this.id&&(r==null?void 0:r.autoCloseActionName)===w.RemoveEntity}),r==null||r.attemptAutoclose(w.RemoveEntity,this.id),{added:[],updated:[],removed:[],affected:[],self:this};const a=[],c=[],e=[],f=[];if(r!=null&&r.hasRemoved(this.id))return r==null||r.attemptAutoclose(w.RemoveEntity,this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(c.push(this),this.unsubscribe(),this.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},r),Object.values(this.detachedDependents).forEach(m=>{const{updated:E,removed:b,added:A}=m.entity.onDetachedDependencyRemoved(this,m.field,r);a.push(...E),c.push(...b),e.push(...A)}),this.defaultValue){const{updated:m,removed:E}=this.defaultValue.remove({ignoreUpstream:!0},r);a.push(...m),c.push(...E)}if(this.dataType){const{updated:m,removed:E}=this.dataType.remove({ignoreUpstream:!0},r);a.push(...m),c.push(...E)}if(!i){const m=this.removeFromParent(r);e.push(...m.added),a.push(...m.updated),c.push(...m.removed),f.push(...m.affected)}return r==null||r.attemptAutoclose(w.RemoveEntity,this.id),{added:C(e),updated:C(a),removed:C(c),affected:C(f),self:this}}restore({}={},i=this.project.addChangeSet(new S(this.project,x.sessionAuthor,B().toISOString(),this,!0,w.RestoreEntity))){if(!this.checkCanEdit(this,i))return Y.Logger.warn(`[restore] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(w.RestoreEntity,this.id),{added:[],updated:[],removed:[],affected:[],self:this};const r=[],a=[],c=[],e=[];if(i!=null&&i.hasAdded(this.id))return i==null||i.attemptAutoclose(w.RestoreEntity,this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},i),Object.values(this.detachedDependents).forEach(f=>{const{updated:h,removed:m,added:E}=f.entity.onDetachedDependencyRestored(this,f.field,i);a.push(...h),c.push(...m),r.push(...E)}),this.defaultValue){const{updated:f}=this.defaultValue.restore({},i);a.push(...f)}if(this.dataType){const{updated:f}=this.dataType.restore({},i);a.push(...f)}return this.parent.type===d.DefinitionEntity&&(this.parentRelationType===Jd.AllPropertiesImplementationTarget?this.parent.removeAllPropertiesImplement(i):this.parent.addProperty(this,i),e.push(this.parent)),i==null||i.attemptAutoclose(w.RestoreEntity,this.id),{added:C(r),updated:C(a),removed:C(c),affected:C(e),self:this}}toFlat(i=new Set){var a,c;return i.has(this.id)?[]:(i.add(this.id),[this,...((a=this.defaultValue)==null?void 0:a.toFlat(i))||[],...((c=this.dataType)==null?void 0:c.toFlat(i))||[],...this.parent.toFlat(i)])}toFlatIds(i=new Set){var a,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,...((a=this.defaultValue)==null?void 0:a.toFlatIds(i))||[],...((c=this.dataType)==null?void 0:c.toFlatIds(i))||[],...this.parent.toFlatIds(i)]}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,codeName:this.codeName,description:this.description,index:this.index,hidden:this.hidden,private:this.private,abstract:this.abstract,required:this.required,unique:this.unique,constant:this.constant,interactive:this.interactive,static:this.static,type:this.type,editable:this.editable,deletable:this.deletable,name:this.name}}toJSON(i=new Set){var r,a,c;return i.has(this.id)?this.toReference():(i.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,editable:this.editable,deletable:this.deletable,name:this.name,codeName:this.codeName,description:this.description,index:this.index,private:this.private,unique:this.unique,required:this.required,static:this.static,constant:this.constant,interactive:this.interactive,abstract:this.abstract,hidden:this.hidden,parentRelationType:this.parentRelationType,defaultValue:((r=this.defaultValue)==null?void 0:r.toJSON(i))||null,dataType:((a=this.dataType)==null?void 0:a.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=at){var a,c,e,f,h,m,E;let r;return(a=i.seenEntityMaps)!=null&&a.has(this.id)?r=i.seenEntityMaps.get(this.id):(r=i.newId||on(this,this.project,i.uuidStrategy),i.seenEntityMaps&&i.seenEntityMaps.set(this.id,r)),(c=i.seenEntities)!=null&&c.has(r)||(e=i.seenEntities)!=null&&e.has(this.id)?this.toReference({seenEntityMaps:i.seenEntityMaps}):((f=i.seenEntities)==null||f.add(r),(h=i.seenEntities)==null||h.add(this.id),{id:r,version:x.UUID.uuid(),createdAt:i.timestamp||B().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:((m=this.defaultValue)==null?void 0:m.toJSONClone({...i,newId:null}))||null,dataType:((E=this.dataType)==null?void 0:E.toJSONClone({...i,newId:null}))||null,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=at){var a;let r=this.id;return(a=i.seenEntityMaps)!=null&&a.has(this.id)&&(r=i.seenEntityMaps.get(this.id)),{id:r+"--"+x.UUID.uuid()+"--ref",type:d.GenericReference,entityId:r,version:this.version,entityType:this.type}}toShallowJSON(i=at){var a,c,e,f;let r=this.id;return(a=i.seenEntityMaps)!=null&&a.has(this.id)&&(r=i.seenEntityMaps.get(this.id)),{id:r,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,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(h=>h.toReference(i)),extends:((f=this.extends)==null?void 0:f.toReference(i))||null,parent:this.parent.toReference(i)}}toFlatJSON(i=new Set){var a,c;return i.has(this.id)?[]:(i.add(this.id),[this.toShallowJSON(),...((a=this.defaultValue)==null?void 0:a.toFlatJSON(i))||[],...((c=this.dataType)==null?void 0:c.toFlatJSON(i))||[],...this.implements.flatMap(e=>e.toFlatJSON(i)),...this.parent.toFlatJSON(i)])}toGenerationTarget(i=at){var a,c;let r=this.id;return(a=i.seenEntityMaps)!=null&&a.has(this.id)&&(r=i.seenEntityMaps.get(this.id)),{id:r,name:this.name,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(e=>e.id),extends:(c=this.extends)==null?void 0:c.id,parent:this.parent.id}}toFlatGenerationTarget(i=new Set){var a,c;return i.has(this.id)?[]:(i.add(this.id),[this.toGenerationTarget(),...((a=this.defaultValue)==null?void 0:a.toFlatGenerationTarget(i))||[],...((c=this.dataType)==null?void 0:c.toFlatGenerationTarget(i))||[],...this.implements.flatMap(e=>e.toFlatGenerationTarget(i))])}clearErrors(){var i,r;return this.errors=[],(i=this.defaultValue)==null||i.clearErrors(),(r=this.dataType)==null||r.clearErrors(),this}validate(){return this.errors=kke(this),{success:!0}}async validateAsync(i={}){const r=Y.YieldTracker.from(i);return this.errors=await jke(this,{tracker:r}),{success:!0}}getErrors(){var r,a;return[...this.errors,...((r=this.defaultValue)==null?void 0:r.getErrors())||[],...((a=this.dataType)==null?void 0:a.getErrors())||[]]}async getErrorsAsync(i={}){const r=Y.YieldTracker.from(i),a=[...this.errors];if(await r.tick(),this.defaultValue){const c=await this.defaultValue.getErrorsAsync({tracker:r});a.push(...c)}if(this.dataType){const c=await this.dataType.getErrorsAsync({tracker:r});a.push(...c)}return a}getShallowErrors(){return this.errors}implement(i,r=this.project.addChangeSet(new S(this.project,x.sessionAuthor,B().toISOString(),this,!0,"implement-self-as-property")),a=null){var E,b,A;const c=a||x.UUID.uuid(),e=yi.new(r);e.id=c,e.name=this.name,e.description=this.description,e.index=this.index,e.private=this.private,e.required=this.required,e.static=this.static,e.constant=this.constant,e.unique=this.unique,e.hidden=this.hidden,e.interactive=this.interactive,e.parent=i.toReference(),e.implements=[this.toJSON()];const f=ge(e,this.project);f.hydrateAncestors(),f.addSelfToProject(r),r==null||r.add(f,W.Added),f.initChildren(r);const h=(E=this.defaultValue)==null?void 0:E.clone(r,f,x.UUID.uuid());h&&(h.editable=!0,h.deletable=!0);const m=yF(this);if(m.result){let _=!1;if(!f.defaultValue){const P=Nr.new(r);P.value=m.value,P.name=m.name,P.parent=f.toReference();const V=ge(P,this.project);V.hydrateAncestors(),V.addSelfToProject(r),V.initChildren(r),f.setDefaultValue(V,r),_=!0}(b=this.defaultValue)==null||b.metaSync({value:m.value},r),_&&(r||(A=this.defaultValue)==null||A.captureVersion())}return r||f.captureVersion(),f}clone(i=this.project.addChangeSet(new S(this.project,x.sessionAuthor,B().toISOString(),this,!0,w.CloneEntity)),r=null,a=null,c=!0){var b,A;const e=Ur(r,this),f=a||x.UUID.uuid(),h=r||this.parent,m={hidden:!1,id:f,version:x.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||B().toISOString(),author:(i==null?void 0:i.author)||"1",previousVersion:null,deleted:!1,type:this.type,editable:!0,deletable:!0,name:this.name,codeName:this.codeName,description:this.description,index:this.index,private:this.private,constant:this.constant,unique:this.unique,interactive:this.interactive,required:this.required,abstract:this.abstract,static:this.static,parentRelationType:this.parentRelationType,defaultValue:null,dataType:null,implements:this.implements.map(_=>_.toJSON()),extends:this.extends,parent:h.toReference()},E=nr(m,e);if(E.hydrateAncestors(),E.setParent(h,i),c&&(E.subscribe(),E.addSelfToProject(i)),E.initChildren(i),i==null||i.add(E,W.Added),this.dataType&&this.project.diggestedBuiltInBaseEntitiesIds.has(this.dataType.id))E.setDataType(e.getBuiltIn(this.dataType.id),i);else{const _=((b=this.dataType)==null?void 0:b.implement(E,i,x.UUID.uuid()))||null;_&&E.setDataType(_,i)}if(this.defaultValue){const _=(A=this.defaultValue)==null?void 0:A.clone(i,E,x.UUID.uuid(),c);E.setDefaultValue(_||null,i)}return this.implements.length&&this.implements.forEach(_=>{const P=e.get(_.id)||e.getBuiltIn(_.id);if(P){E.addImplementation(P,i);return}}),E.addSelfToProject(null),i||E.captureVersion(),i==null||i.attemptAutoclose(w.CloneEntity,this.id),E}setDataType(i,r=this.project.addChangeSet(new S(this.project,x.sessionAuthor,B().toISOString(),this,!0,w.SetDataType))){if(!this.checkCanEdit(this,r))return Y.Logger.warn(`[setDataType] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),r==null||r.attemptAutoclose(w.SetDataType,this.id),this;const a=this.dataType;return(a==null?void 0:a.id)!==(i==null?void 0:i.id)&&(a==null||a.remove({ignoreUpstream:!0},r),this.dataType=i,this.subscribeToDependencies(),r==null||r.add(this,W.Affected)),r==null||r.attemptAutoclose(w.SetDataType,this.id),this}removeDataType(i=this.project.addChangeSet(new S(this.project,x.sessionAuthor,B().toISOString(),this,!0,w.RemoveDataType))){return this.checkCanEdit(this,i)?(this.dataType&&(this.dataType.remove({ignoreUpstream:!0},i),i==null||i.add(this,W.Affected),this.dataType=null),i==null||i.attemptAutoclose(w.RemoveDataType,this.id),this):(Y.Logger.warn(`[removeDataType] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(w.RemoveDataType,this.id),this)}getDataType(i=this.project.addChangeSet(new S(this.project,x.sessionAuthor,B().toISOString(),this,!0,"get-data-type"))){return i==null||i.attemptAutoclose("get-data-type",this.id),this.dataType}getDefaultValue(){var c;let i=null;for(const e of this.implements){const f=e.getDefaultValue();(!i||kn(i))&&f&&(i=f)}let r=this.defaultValue;const a=(c=this.extends)==null?void 0:c.getDefaultValue();return kn(r)&&a&&!kn(a)&&(r=a),kn(r)&&i&&!kn(i)&&(r=i),r}setDefaultValue(i,r=this.project.addChangeSet(new S(this.project,x.sessionAuthor,B().toISOString(),this,!0,"set-default-value"))){if(!this.checkCanEdit(this,r))return Y.Logger.warn(`[setDefaultValue] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),r==null||r.attemptAutoclose("set-default-value",this.id),this;const a=this.defaultValue;return(a==null?void 0:a.id)!==(i==null?void 0:i.id)&&(a==null||a.remove({ignoreUpstream:!0},r),this.defaultValue=i,r==null||r.add(this,W.Affected)),r==null||r.attemptAutoclose("set-default-value",this.id),this}syncWithImplementation(i=this.project.addChangeSet(new S(this.project,x.sessionAuthor,B().toISOString(),this,!0,"sync-with-implementation"))){var _,P,V,j;if(!this.checkCanEdit(this,i))return Y.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 r=[],a=[],c=[],e=[];this.parent.type!==d.PrimitiveEntity&&this.interactive&&this.parent.getAllPropertiesImplements().filter(G=>G.id!==this.id).forEach(G=>{this.addImplementation(G,i)}),this.implements.find(M=>M.id===this.id)&&this.removeImplementation(this,i);let f=null,h=this.implements.filter(M=>{var ee;if(!M.dataType||!((ee=M.dataType)!=null&&ee.isResolved))return!1;const G=this.implements.filter(se=>se.id!==M.id);if(!G.length)return!0;const q=vl(Ka(M.dataType),{removeDuplicates:!0,removeNulls:!0}).filter(se=>se.isResolved);return!!G.every(se=>!se.dataType||!se.dataType.isResolved?!0:vl(Ka(se.dataType),{removeDuplicates:!0,removeNulls:!0}).filter(le=>le.isResolved).length>q.length)});if(h.length>1&&this.parent.type!==d.PrimitiveEntity){const M=this.parent.getAllPropertiesImplements()[0]||null;h=h.filter(G=>G.id!==(M==null?void 0:M.id))}if(!h.length&&this.parent.type!==d.PrimitiveEntity){const M=this.parent.getAllPropertiesImplements()[0]||null;M&&h.push(M)}for(const M of h)(_=M.dataType)!=null&&_.isResolved&&(f?((P=M.dataType.orChildrenGroup)!=null&&P.length&&M.dataType.implementationChooseOne||(V=M.dataType.orChildrenGroup)!=null&&V.length&&!M.dataType.implementationChooseOne)&&(f=M.dataType):f=M.dataType);if(f||this.parent.type!==d.PrimitiveEntity&&this.parent.additionalPropertiesDataType&&(f=this.parent.additionalPropertiesDataType),f&&!this.dataType){const M=f.implement(this,i,x.UUID.uuid());this.setDataType(M,i),a.push(M)}if((j=this.dataType)==null||j.merge(f,i,{implementSource:!0}),!this.defaultValue){let M=null;for(const G of this.implements){const q=G.getDefaultValue();q&&(M=q)}if(M){const G=M.clone(i,this,x.UUID.uuid(),!0);this.setDefaultValue(G,i),a.push(G)}}if(!this.defaultValue){const M=yF(this);if(M.result){const G=Nr.new(i);G.name=M.name,G.value=M.value,G.parent=this.toReference();const q=ge(G,this.project);q.hydrateAncestors(),q.addSelfToProject(i),q.initChildren(i),i==null||i.add(q,W.Added),i||q.captureVersion(),this.setDefaultValue(q,i),a.push(q)}}let m=!1,E=!1,b=!1,A=!1;return this.implements.forEach(M=>{M.required&&(m=!0),M.constant&&(b=!0),M.unique&&(E=!0),M.static&&(A=!0)}),this.metaSync({required:m||this.required,constant:b||this.constant,unique:E||this.unique,static:A||this.static},i),i==null||i.attemptAutoclose("sync-with-implementation",this.id),{updated:C(r),added:C(a),removed:C(c),affected:C(e),self:this}}syncWithExtension(i=this.project.addChangeSet(new S(this.project,x.sessionAuthor,B().toISOString(),this,!0,"sync-with-extension"))){var E,b,A;if(!this.checkCanEdit(this,i))return Y.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 r=[],a=[],c=[],e=[];if(!this.extends)return i==null||i.attemptAutoclose("sync-with-extension",this.id),{added:[],updated:[],removed:[],affected:[],self:this};const f={...this.extends.toMeta()};if(delete f.id,delete f.version,delete f.createdAt,delete f.previousVersion,delete f.author,delete f.index,this.metaSync(f,i),r.push(this),!this.extends.dataType)return i==null||i.attemptAutoclose("sync-with-extension",this.id),{added:[],updated:[],removed:[],affected:[],self:this};let h=!1;if(!this.dataType){const _=mr.new(i);_.parent=this.toReference();const P=ge(_,this.project);P.hydrateAncestors(),P.addSelfToProject(i),i==null||i.add(P,W.Added),P.afterAllChildrenInitialized(i),h=!0}if(di(this.dataType,this.extends.dataType).compatible||(E=this.dataType)==null||E.merge(this.extends.dataType,i),h&&(i||(b=this.dataType)==null||b.captureVersion()),this.extends.defaultValue&&!this.defaultValue){const _=this.extends.defaultValue.clone(i,this,x.UUID.uuid(),!0);this.setDefaultValue(_,i),a.push(_)}else this.extends.defaultValue?this.extends.defaultValue&&this.defaultValue&&!RFe(this.defaultValue,this.extends.defaultValue)&&(this.defaultValue.merge(this.extends.defaultValue,i),r.push(this.defaultValue)):((A=this.defaultValue)==null||A.remove({ignoreUpstream:!0},i),this.defaultValue=null,e.push(this));return i==null||i.attemptAutoclose("sync-with-extension",this.id),{updated:C(r),added:C(a),removed:C(c),affected:C(e),self:this}}implementAsInputMap(i=this.project.addChangeSet(new S(this.project,x.sessionAuthor,B().toISOString(),this,!0,"implement-as-input-map")),r,a){const c=ms.new(i);c.id=a||c.id,c.name=this.name,c.description=this.description,c.parent=r.toReference(),c.declaration=this.toJSON();const e=nr(c,this.project);if(e.hydrateAncestors(),e.addSelfToProject(i),i==null||i.add(e,W.Added),e.initChildren(i),this.dataType)if(this.project.diggestedBuiltInBaseEntitiesIds.has(this.dataType.id))e.setDataType(this.dataType,i),i==null||i.add(e,W.Affected);else{const f=this.dataType.clone(i,e);e.setDataType(f,i)}if(this.defaultValue){const f=this.defaultValue.clone(i,e);e.setDefaultValue(f,i)}return i||e.captureVersion(),i==null||i.attemptAutoclose("implement-as-input-map",this.id),e}};R(yi,"repository",{APICreate:async(i,...r)=>i,APIUpdate:async(i,...r)=>i,APIDelete:async(i,...r)=>i,APIClone:async(i,...r)=>{},APILoad:async(i,...r)=>null,APILoadVersion:async(i,r,...a)=>null}),R(yi,"type",d.Property),R(yi,"USER_MANAGED_PARENT_TYPES",[d.DefinitionEntity]),R(yi,"PARENT_TYPES",[...yi.USER_MANAGED_PARENT_TYPES,d.PrimitiveEntity,d.BuiltInBaseEntity]),R(yi,"MUTABLE_BASE_PROPERTIES",["name","codeName","description","private","abstract","static","required","constant","unique","interactive"]),R(yi,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion","parentRelationType"]),R(yi,"BASE_PROPERTIES",[...yi.MUTABLE_BASE_PROPERTIES,...yi.INMUTABLE_BASE_PROPERTIES]),R(yi,"MUTABLE_META_PROPERTIES",[...yi.MUTABLE_BASE_PROPERTIES,"index"]),R(yi,"INMUTABLE_META_PROPERTIES",[...yi.INMUTABLE_BASE_PROPERTIES]),R(yi,"META_PROPERTIES",[...yi.MUTABLE_META_PROPERTIES,...yi.INMUTABLE_META_PROPERTIES]),R(yi,"MUTABLE_UPSTREAM_PROPERTIES",[]),R(yi,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","implements","extends"]),R(yi,"UPSTREAM_PROPERTIES",[...yi.MUTABLE_UPSTREAM_PROPERTIES,...yi.INMUTABLE_UPSTREAM_PROPERTIES]),R(yi,"MUTABLE_DOWNSTREAM_PROPERTIES",["dataType","defaultValue"]),R(yi,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),R(yi,"DOWNSTREAM_PROPERTIES",[...yi.MUTABLE_DOWNSTREAM_PROPERTIES,...yi.INMUTABLE_DOWNSTREAM_PROPERTIES]),R(yi,"PROPERTIES",[...yi.META_PROPERTIES,...yi.UPSTREAM_PROPERTIES,...yi.DOWNSTREAM_PROPERTIES]);let vs=yi;async function Fke(s,p={}){var E,b;const i=Y.YieldTracker.from(p),r=s.implements.flatMap(A=>Zke(s,A)),a=Hke(s,s.extends),c=zke(s),e=Wke(s),f=gL(s),h=[...r,...a,...c,...e,...f],m=St(s.errors,h);await i.tick();for(const A of s.properties)await A.validateAsync({tracker:i});for(const A of s.methods)await A.validateAsync({tracker:i});for(const A of s.abstractMethods)await A.validateAsync({tracker:i});return await((E=s.allPropertiesImplement)==null?void 0:E.validateAsync({tracker:i})),await((b=s.additionalPropertiesDataType)==null?void 0:b.validateAsync({tracker:i})),m}function Kke(s){var h,m;const p=s.implements.flatMap(E=>Zke(s,E)),i=Hke(s,s.extends),r=zke(s),a=Wke(s),c=gL(s);s.properties.forEach(E=>{E.validate()}),s.methods.flatMap(E=>E.validate()),s.abstractMethods.flatMap(E=>E.validate()),(h=s.allPropertiesImplement)==null||h.validate(),(m=s.additionalPropertiesDataType)==null||m.validate();const e=[...p,...i,...r,...a,...c];return St(s.errors,e)}function qke(s,p){const i=p.properties.filter(c=>c.abstract),r=[];let a=[...s.properties];return i.forEach(c=>{const e=a.find(f=>!!f.implements.find(h=>h.id===c.id));e?a=a.filter(f=>f.id!==e.id):r.push(c)}),r}function Ske(s,p){const i=p.abstractMethods,r=[];let a=[...s.methods];return i.forEach(c=>{const e=a.find(f=>{var h;return((h=f.implements)==null?void 0:h.id)===c.id});e?a=a.filter(f=>f.id!==e.id):r.push(c)}),r}function Zke(s,p){const i=[];if(!p.abstract){const E=gt({id:s.id+"--"+be.ImplementingNonAbstractEntity,message:`Entity "${s.name}" with id "${s.id}" is implementing a non-abstract entity "${p.name}" with id "${p.id}"`,severity:Te.Error,code:be.ImplementingNonAbstractEntity,entity:s});return i.push(E.error),i}const r=p.properties.filter(E=>E.abstract),a=[];let c=[...s.properties];r.forEach(E=>{const b=c.find(A=>!!A.implements.find(_=>_.id===E.id));b?c=c.filter(A=>A.id!==b.id):a.push(E)}),a.length&&a.forEach(E=>{const b=gt({id:s.id+"--"+be.MissingPropertyImplementation+"--"+E.id,message:`Property "${E.name}" with id "${E.id}" of entity "${p.name}" with id "${p.id}" is not implemented when entity "${s.name}" with id "${s.id}" implements it`,severity:Te.Error,code:be.MissingPropertyImplementation,entity:s});i.push(b.error)});const e=[];let f=[...s.methods];p.abstractMethods.forEach(E=>{const b=f.find(A=>{var _;return((_=A.implements)==null?void 0:_.id)===E.id});b?f=f.filter(A=>A.id!==b.id):e.push(E)}),e.length&&e.forEach(E=>{const b=gt({id:s.id+"--"+be.MissingMethodImplementation+"--"+E.id,message:`Method "${E.name}" with id "${E.id}" of entity "${p.name}" with id "${p.id}" is not implemented when entity "${s.name}" with id "${s.id}" implements it`,severity:Te.Error,code:be.MissingMethodImplementation,entity:s});i.push(b.error)});const h=[];p.properties.forEach(E=>{const b=c.find(A=>A.name===E.name);b&&h.push([b,E])}),h.length&&h.forEach(([E])=>{const b=gt({id:s.id+"--"+Ce.PropertyOverwritesOtherSiblingWithSameName+"--"+E.id,message:`Property "${E.name}" with id "${E.id}" of entity "${s.name}" with id "${s.id}" overwrites the property with the same name from the base entity "${p.name}" with id "${p.id}"`,severity:Te.Error,code:Ce.PropertyOverwritesOtherSiblingWithSameName,entity:s});i.push(b.error)});const m=[];return p.methods.forEach(E=>{const b=f.find(A=>A.name===E.name);b&&m.push([b,E])}),m.length&&m.forEach(([E])=>{const b=gt({id:s.id+"--"+Ce.MethodOverwritesOtherSiblingWithSameName+"--"+E.id,message:`Method "${E.name}" with id "${E.id}" of entity "${s.name}" with id "${s.id}" overwrites the method with the same name from the base entity "${p.name}" with id "${p.id}"`,severity:Te.Error,code:Ce.MethodOverwritesOtherSiblingWithSameName,entity:s});i.push(b.error)}),i}function Hke(s,p){const i=[];if(!p)return i;const r=[];if(!s.abstract&&p.abstract){const c=gt({id:s.id+"--"+p.id+"--"+be.NonAbstractExtendingAbstractEntity,message:`Entity "${s.name}" with id "${s.id}" is not-abstract but is extending an abstract entity "${p.name}" with id "${p.id}"`,severity:Te.Error,code:be.NonAbstractExtendingAbstractEntity,entity:s,firstRelationship:p});return i.push(c.error),i}if(s.abstract&&!p.abstract){const c=gt({id:s.id+"--"+p.id+"--"+be.AbstractExtendingNonAbstractEntity,message:`Entity "${s.name}" with id "${s.id}" is abstract but is extending an non-abstract entity "${p.name}" with id "${p.id}"`,severity:Te.Error,code:be.AbstractExtendingNonAbstractEntity,entity:s,firstRelationship:p});return i.push(c.error),i}s.properties.forEach(c=>{const e=p.properties.find(f=>{var h;return f.name===c.name&&((h=c.extends)==null?void 0:h.id)!==f.id});c.implements.find(f=>f.id===(e==null?void 0:e.id))||e&&r.push(c)}),r.length&&r.forEach(c=>{const e=gt({id:s.id+"--"+Ce.PropertyOverwritesOtherSiblingWithSameName,message:`Property "${c.name}" with id "${c.id}" of entity "${s.name}" with id "${s.id}" overwrites the property with the same name from the extended entity "${p.name}" with id "${p.id}"`,severity:Te.Error,code:Ce.PropertyOverwritesOtherSiblingWithSameName,entity:s});i.push(e.error)});const a=[];return s.methods.forEach(c=>{var f;const e=p.methods.find(h=>{var m;return h.name===c.name&&((m=c.extends)==null?void 0:m.id)!==h.id});((f=c.implements)==null?void 0:f.id)!==(e==null?void 0:e.id)&&e&&a.push(c)}),a.length&&a.forEach(c=>{const e=gt({id:s.id+"--"+Ce.MethodOverwritesOtherSiblingWithSameName,message:`Method "${c.name}" with id "${c.id}" of entity "${s.name}" with id "${s.id}" overwrites the method with the same name from the extended entity "${p.name}" with id "${p.id}"`,severity:Te.Error,code:Ce.MethodOverwritesOtherSiblingWithSameName,entity:s});i.push(e.error)}),i}function Wke(s){const p=[];if(!s.properties.length){const i=gt({id:s.id+"--"+be.NoProperties,message:"No properties implemented",severity:Te.Warning,code:be.NoProperties,entity:s});p.push(i.error)}return p}function zke(s){const p=[];if(s.abstract){if(s.methods.length){const i=gt({id:s.id+"--"+be.AbstractEntityWithNonAbstractMethods,message:`Entity "${s.name}" with id "${s.id}" is marked as abstract but has non-abstract methods`,severity:Te.Error,code:be.AbstractEntityWithNonAbstractMethods,entity:s});p.push(i.error)}if(s.properties.some(i=>!i.abstract)){const i=gt({id:s.id+"--"+be.AbstractEntityWithNonAbstractProperties,message:`Entity "${s.name}" with id "${s.id}" is marked as abstract but has non-abstract properties`,severity:Te.Error,code:be.AbstractEntityWithNonAbstractProperties,entity:s});p.push(i.error),s.properties.forEach(r=>{if(!r.abstract){const a=gt({id:s.id+"--"+be.StaticEntityWithNonStaticProperties+"--"+r.id,message:`Property "${r.name}" with id "${r.id}" of entity "${s.name}" with id "${s.id}" is not marked as abstract but the entity is marked as abstract`,severity:Te.Error,code:be.StaticEntityWithNonStaticProperties,entity:s});p.push(a.error)}})}}else{if(s.abstractMethods.length){const i=gt({id:s.id+"--"+be.AbstractPropertyInNonAbstractEntity,message:`Entity "${s.name}" with id "${s.id}" is not marked as abstract but has abstract methods`,severity:Te.Error,code:be.AbstractPropertyInNonAbstractEntity,entity:s});p.push(i.error)}s.properties.some(i=>i.abstract)&&s.properties.forEach(i=>{if(i.abstract){const r=gt({id:s.id+"--"+be.AbstractPropertyInNonAbstractEntity+"--"+i.id,message:`Property "${i.name}" with id "${i.id}" of entity "${s.name}" with id "${s.id}" is marked as abstract but the entity is not marked as abstract`,severity:Te.Error,code:be.AbstractPropertyInNonAbstractEntity,entity:s,firstRelationship:i});p.push(r.error)}})}return s.static&&s.properties.some(i=>!i.static)&&s.properties.forEach(i=>{if(!i.static){const r=gt({id:s.id+"--"+be.NonStaticPropertyInStaticEntity+"--"+i.id,message:`Property "${i.name}" with id "${i.id}" of entity "${s.name}" with id "${s.id}" is not marked as static but the entity is marked as static`,severity:Te.Error,code:be.NonStaticPropertyInStaticEntity,entity:s,firstRelationship:i});p.push(r.error)}}),p}function DVi(s,p){const i=[],r=Xn(p);if(!p.abstract){const e=new Fi({id:s.id+"--"+p.id+"--"+be.ImplementingNonAbstractEntity,message:`Entity "${s.name}" with id "${s.id}" is implementing a non-abstract built-in entity "${p.name}" with id "${p.id}"`,severity:Te.Error,code:be.ImplementingNonAbstractEntity,entity:s,firstRelationship:p});i.push(e)}const a=s.implements.filter(e=>e.id!==p.id);if(s.abstract){const e=new Fi({id:s.id+"--"+p.id+"--"+be.AbstractEntityImplements,message:`Entity "${s.name}" with id "${s.id}" is marked as abstract and cannot implement built-in entity "${p.name}" with id "${p.id}"`,severity:Te.Error,code:be.AbstractEntityImplements,entity:s,firstRelationship:p});i.push(e)}if(s.static&&!p.static){const e=new Fi({id:s.id+"--"+p.id+"--"+be.StaticImplementingNonStaticEntity,message:`Entity "${s.name}" with id "${s.id}" is marked as static and cannot implement non-static built-in entity "${p.name}" with id "${p.id}"`,severity:Te.Error,code:be.StaticImplementingNonStaticEntity,entity:s,firstRelationship:p});i.push(e)}if(!s.static&&p.static){const e=new Fi({id:s.id+"--"+p.id+"--"+be.NonStaticImplementingStaticEntity,message:`Entity "${s.name}" with id "${s.id}" is not marked as static and cannot implement static built-in entity "${p.name}" with id "${p.id}"`,severity:Te.Error,code:be.NonStaticImplementingStaticEntity,entity:s,firstRelationship:p});i.push(e)}return a.length&&a.forEach(e=>{if(e.type===d.BuiltInBaseEntity){const f=r.filter(h=>h.id!==e.id);f.length&&f.forEach(h=>{if(h.id!==e.id){const m=new Fi({id:s.id+"--"+h.id+"--"+e.id+"--"+be.ImplementsIncompatibleEntities,message:`Entity "${s.name}" with id "${s.id}" is implementing built-in entity "${h.name}" with id "${h.id}" but also implements entity "${e.name}" with id "${e.id}" which is incompatible`,severity:Te.Error,code:be.ImplementsIncompatibleEntities,entity:s,firstRelationship:h,secondRelationship:e});i.push(m)}})}else{Xn(e).forEach(E=>{const b=r.filter(A=>A.id!==E.id);b.length&&b.forEach(A=>{if(A.id!==E.id){const _=new Fi({id:s.id+"--"+A.id+"--"+E.id+"--"+be.ImplementsIncompatibleEntities,message:`Entity "${s.name}" with id "${s.id}" is implementing built-in entity "${A.name}" with id "${A.id}" but also implements entity "${E.name}" with id "${E.id}" which is incompatible`,severity:Te.Error,code:be.ImplementsIncompatibleEntities,entity:s,firstRelationship:A,secondRelationship:E});i.push(_)}})});const h=zd(p.ownDeclaredProperties,e.ownDeclaredProperties,Ce.PropertyOverwritesOtherImplementedEntitysPropertyWithSameImplementation,Ce.PropertyOverwritesOtherImplementedEntitysPropertyWithSameName);i.push(...h.errors);const m=zd(p.abstractMethods,[...e.abstractMethods,...e.methods],Ce.MethodOverwritesOtherImplementedEntitysMethodWithSameImplementation,Ce.MethodOverwritesOtherImplementedEntitysMethodWithSameName);i.push(...m.errors)}}),C(s.extends?Xn(s.extends):[]).forEach(e=>{if(!r.find(f=>f.id===e.id)){const f=new Fi({id:s.id+"--"+p.id+"--"+e.id+"--"+be.ExtendsIncompatibleEntities,message:`Entity "${s.name}" with id "${s.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:Te.Error,code:be.ExtendsIncompatibleEntities,entity:s,firstRelationship:p,secondRelationship:e});i.push(f)}}),i}function wVi(s,p,i=!1){var m,E;const r=[],a=Xn(p);if(!s.abstract&&p.abstract){const b=gt({id:s.id+"--"+p.id+"--"+be.NonAbstractExtendingAbstractEntity,message:`Entity "${s.name}" with id "${s.id}" is not-abstract but is extending an abstract entity "${p.name}" with id "${p.id}"`,severity:Te.Error,code:be.NonAbstractExtendingAbstractEntity,entity:s,firstRelationship:p});r.push(b.error)}if(s.abstract&&!p.abstract){const b=gt({id:s.id+"--"+p.id+"--"+be.AbstractExtendingNonAbstractEntity,message:`Entity "${s.name}" with id "${s.id}" is abstract but is extending an non-abstract entity "${p.name}" with id "${p.id}"`,severity:Te.Error,code:be.AbstractExtendingNonAbstractEntity,entity:s,firstRelationship:p});r.push(b.error)}if(!s.static&&p.static){const b=gt({id:s.id+"--"+p.id+"--"+be.NonStaticExtendingStaticEntity,message:`Entity "${s.name}" with id "${s.id}" is not static but is extending a static entity "${p.name}" with id "${p.id}"`,severity:Te.Error,code:be.NonStaticExtendingStaticEntity,entity:s,firstRelationship:p});r.push(b.error)}if(s.static&&!p.static){const b=gt({id:s.id+"--"+p.id+"--"+be.StaticExtendingNonStaticEntity,message:`Entity "${s.name}" with id "${s.id}" is static but is extending an non-static entity "${p.name}" with id "${p.id}"`,severity:Te.Error,code:be.StaticExtendingNonStaticEntity,entity:s,firstRelationship:p});r.push(b.error)}if(!El(p)){const b=gt({id:s.id+"--"+p.id+"--"+be.ExtendingNonInteractiveEntity,message:`Entity "${s.name}" with id "${s.id}" is extending an non-interactive entity "${p.name}" with id "${p.id}"`,severity:Te.Error,code:be.ExtendingNonInteractiveEntity,entity:s,firstRelationship:p});r.push(b.error)}if(s.extends&&((m=s.extends)==null?void 0:m.id)!==p.id)if(((E=s.extends)==null?void 0:E.type)===d.BuiltInBaseEntity){const b=a.filter(A=>{var _;return A.id!==((_=s.extends)==null?void 0:_.id)});b.length&&b.forEach(A=>{var _,P,V,j;if(A.id!==((_=s.extends)==null?void 0:_.id)){const M=gt({id:s.id+"--"+A.id+"--"+((P=s.extends)==null?void 0:P.id)+"--"+be.ExtendsIncompatibleEntities,message:`Entity "${s.name}" with id "${s.id}" is extending built-in entity "${A.name}" with id "${A.id}" but also extends entity "${(V=s.extends)==null?void 0:V.name}" with id "${(j=s.extends)==null?void 0:j.id}" which is incompatible`,severity:Te.Error,code:be.ExtendsIncompatibleEntities,entity:s,firstRelationship:A,secondRelationship:s.extends});r.push(M.error)}})}else{Xn(s.extends).forEach(M=>{const G=a.filter(q=>q.id!==M.id);G.length&&G.forEach(q=>{if(q.id!==M.id){const re=new Fi({id:s.id+"--"+q.id+"--"+M.id+"--"+be.ImplementsIncompatibleEntities,message:`Entity "${s.name}" with id "${s.id}" is extending built-in entity "${q.name}" with id "${q.id}" but also extends or implements entity "${M.name}" with id "${M.id}" which is incompatible`,severity:Te.Error,code:be.ImplementsIncompatibleEntities,entity:s,firstRelationship:q,secondRelationship:M});r.push(re)}})});const A=!!Xn(s.extends).find(M=>M.id===p.id);let _=[...s.extends.properties];A&&(_=_.filter(M=>!p.properties.find(G=>G.id===M.id||G.name===M.name||!!M.implements.find(q=>q.id===G.id))));let P=[...s.extends.methods];A&&(P=P.filter(M=>!p.methods.find(G=>{var q;return G.id===M.id||G.name===M.name||G.id===((q=M.implements)==null?void 0:q.id)})));const V=zd(p.ownDeclaredProperties,_,Ce.PropertyOverwritesOtherExtendedEntitysPropertyWithSameImplementation,Ce.PropertyOverwritesOtherExtendedEntitysPropertyWithSameName);r.push(...V.errors);const j=zd(p.abstractMethods,P,Ce.MethodOverwritesOtherExtendedEntitysMethodWithSameImplementation,Ce.MethodOverwritesOtherExtendedEntitysMethodWithSameName);r.push(...j.errors)}i&&Y.Logger.log("self.implements.length",s.implements.length),s.implements.length&&s.implements.forEach(b=>{if(b.type===d.BuiltInBaseEntity){const A=a.filter(_=>_.id!==b.id);A.length&&A.forEach(_=>{if(_.id!==b.id){const P=new Fi({id:s.id+"--"+_.id+"--"+b.id+"--"+be.ImplementsIncompatibleEntities,message:`Entity "${s.name}" with id "${s.id}" is implementing built-in entity "${_.name}" with id "${_.id}" but also implements entity "${b.name}" with id "${b.id}" which is incompatible`,severity:Te.Error,code:be.ImplementsIncompatibleEntities,entity:s,firstRelationship:_,secondRelationship:b});r.push(P)}})}else{Xn(b).forEach(V=>{const j=a.filter(M=>M.id!==V.id);j.length&&j.forEach(M=>{if(M.id!==V.id){const G=new Fi({id:s.id+"--"+M.id+"--"+V.id+"--"+be.ImplementsIncompatibleEntities,message:`Entity "${s.name}" with id "${s.id}" is implementing built-in entity "${M.name}" with id "${M.id}" but also implements entity "${V.name}" with id "${V.id}" which is incompatible`,severity:Te.Error,code:be.ImplementsIncompatibleEntities,entity:s,firstRelationship:M,secondRelationship:V});r.push(G)}})});const _=zd(p.ownDeclaredProperties,b.ownDeclaredProperties,Ce.PropertyOverwritesOtherImplementedEntitysPropertyWithSameImplementation,Ce.PropertyOverwritesOtherImplementedEntitysPropertyWithSameName);r.push(..._.errors);const P=zd(p.abstractMethods,[...b.abstractMethods,...b.methods],Ce.MethodOverwritesOtherImplementedEntitysMethodWithSameImplementation,Ce.MethodOverwritesOtherImplementedEntitysMethodWithSameName);r.push(...P.errors)}});const e=zd(s.ownDeclaredProperties,p.ownDeclaredProperties,Ce.PropertyOverwritesOtherSiblingWithSameImplementation,Ce.PropertyOverwritesOtherSiblingWithSameName);r.push(...e.errors);const f=zd(p.methods,p.abstractMethods,Ce.MethodOverwritesOtherSiblingWithSameImplementation,Ce.MethodOverwritesOtherSiblingWithSameName);return r.push(...f.errors),C(s.extends?Xn(s.extends):[]).forEach(b=>{if(!a.find(A=>A.id===b.id)){const A=new Fi({id:s.id+"--"+p.id+"--"+b.id+"--"+be.ImplementsIncompatibleEntities,message:`Entity "${s.name}" with id "${s.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:Te.Error,code:be.ImplementsIncompatibleEntities,entity:s,firstRelationship:p,secondRelationship:b});r.push(A)}}),r}function CVi(s){const p=[];if(s.implements.forEach(i=>{if(!i.static){const r=new Fi({id:s.id+"--"+i.id+"--"+be.StaticImplementingNonStaticEntity,message:`Entity "${s.name}" with id "${s.id}" is static but implements entity "${i.name}" with id "${i.id}" which is non-static`,severity:Te.Error,code:be.StaticImplementingNonStaticEntity,entity:s,firstRelationship:i});p.push(r)}}),s.extends&&!s.extends.static){const i=new Fi({id:s.id+"--"+s.extends.id+"--"+be.StaticExtendingNonStaticEntity,message:`Entity "${s.name}" with id "${s.id}" is static but extends entity "${s.extends.name}" with id "${s.extends.id}" which is non-static`,severity:Te.Error,code:be.StaticExtendingNonStaticEntity,entity:s,firstRelationship:s.extends});p.push(i)}return p}function OVi(s){const p=[];if(s.implements.length){const i=new Fi({id:s.id+"--"+be.AbstractEntityImplements,message:`Entity "${s.name}" with id "${s.id}" cannot be marked as abstract because it implements other entities`,severity:Te.Error,code:be.AbstractEntityImplements,entity:s});p.push(i)}if(s.extends&&!s.extends.abstract){const i=new Fi({id:s.id+"--"+s.extends.id+"--"+be.AbstractExtendingNonAbstractEntity,message:`Entity "${s.name}" with id "${s.id}" is abstract but extends entity "${s.extends.name}" with id "${s.extends.id}" which is non-abstract`,severity:Te.Error,code:be.AbstractExtendingNonAbstractEntity,entity:s,firstRelationship:s.extends});p.push(i)}return p}function _Vi(s){const p=[];if(s.extends&&s.extends.static){const i=new Fi({id:s.id+"--"+s.extends.id+"--"+be.NonStaticExtendingStaticEntity,message:`Entity "${s.name}" with id "${s.id}" is non-static but extends entity "${s.extends.name}" with id "${s.extends.id}" which is static`,severity:Te.Error,code:be.NonStaticExtendingStaticEntity,entity:s,firstRelationship:s.extends});p.push(i)}return p}function VVi(s){const p=[];if(s.extends&&s.extends.abstract){const i=new Fi({id:s.id+"--"+s.extends.id+"--"+be.NonAbstractExtendingAbstractEntity,message:`Entity "${s.name}" with id "${s.id}" is non-abstract but extends entity "${s.extends.name}" with id "${s.extends.id}" which is abstract`,severity:Te.Error,code:be.NonAbstractExtendingAbstractEntity,entity:s,firstRelationship:s.extends});p.push(i)}return p}function gL(s,p){const r=[...s.project.entities].filter(a=>a.id!==s.id);return QE(s,[Xi,yd],r,p)}const PVi=Object.freeze(Object.defineProperty({__proto__:null,getBaseMethodsNotImplemented:Ske,getBasePropertiesNotImplemented:qke,validate:Kke,validateAsync:Fke,validateCanBecomeAbstract:OVi,validateCanBecomeNonAbstract:VVi,validateCanBecomeNonStatic:_Vi,validateCanBecomeStatic:CVi,validateCanExtendEntity:wVi,validateCanImplementEntity:DVi,validateDefinitionEntityName:gL},Symbol.toStringTag,{value:"Module"}));function NVi(s,p){const i=[],r=[];if(s.parent)if(s.id===s.parent)r.push(new De({id:`${s.id}--${s.parent}--${he.SelfReference}`,code:he.SelfReference,severity:Te.Error,message:`Entity of type "${s.type}" with id "${s.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 a=p.get(s.parent);a?[d.Project,d.DataType].includes(a.type)||r.push(new De({id:`${s.id}--${s.parent}--${he.InvalidParentReference}`,code:he.InvalidParentReference,severity:Te.Error,message:`Entity of type "${s.type}" with id "${s.id}", has a parent reference which is of type ${a.type}, and therefore that isn't pointing to the following valid types for this reference: 'project' or 'data-type'.`})):r.push(new De({id:`${s.id}--${s.parent}--${he.ReferencedEntityNotFound}`,code:he.ReferencedEntityNotFound,severity:Te.Error,message:`Entity of type "${s.type}" with id "${s.id}", is referencing an entity with id "${s.parent}" at 'parent' that isn't yet found in the project. Perhaps it should be created first. Or perhaps the ID is incorrect.`}))}return s.implements&&Array.isArray(s.implements)?s.implements.forEach(a=>{if(s.id===a){r.push(new De({id:`${s.id}--${a}--${he.SelfReference}`,code:he.SelfReference,severity:Te.Error,message:`Entity of type "${s.type}" with id "${s.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 c=p.get(a);c?[d.DefinitionEntity,d.BuiltInBaseEntity].includes(c.type)?c.abstract||r.push(new De({id:`${s.id}--${a}--${he.InvalidImplementsReference}`,code:he.InvalidImplementsReference,severity:Te.Error,message:`Entity of type "${s.type}" with id "${s.id}", has an 'implements' reference that isn't pointing to an abstract entity.`})):r.push(new De({id:`${s.id}--${a}--${he.InvalidImplementsReference}`,code:he.InvalidImplementsReference,severity:Te.Error,message:`Entity of type "${s.type}" with id "${s.id}", has an 'implements' reference which is of type ${c.type}, and therefore that isn't pointing to the following valid types for this reference: 'definition-entity' or 'built-in-base-entity'.`})):r.push(new De({id:`${s.id}--${a}--${he.ReferencedEntityNotFound}`,code:he.ReferencedEntityNotFound,severity:Te.Error,message:`Entity of type "${s.type}" with id "${s.id}", is referencing an entity with id "${a}" at 'implements' that isn't yet found in the project. Perhaps it should be created first. Or perhaps the ID is incorrect.`}))}):r.push(new De({id:`${s.id}--${Ce.InvalidObjectStructure}`,code:Ce.InvalidObjectStructure,severity:Te.Error,message:`Entity of type "${s.type}" with id "${s.id}", has an 'implements' property that isn't an array.`})),s.extends&&Array.isArray(s.extends)&&s.extends.forEach(a=>{const c=p.get(a);c?[d.DefinitionEntity,d.BuiltInBaseEntity].includes(c.type)?c.abstract&&r.push(new De({id:`${s.id}--${a}--${he.InvalidExtendsReference}`,code:he.InvalidExtendsReference,severity:Te.Error,message:`Entity of type "${s.type}" with id "${s.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?`})):r.push(new De({id:`${s.id}--${a}--${he.InvalidExtendsReference}`,code:he.InvalidExtendsReference,severity:Te.Error,message:`Entity of type "${s.type}" with id "${s.id}", has an 'extends' reference which is of type ${c.type}, and therefore that isn't pointing to the following valid types for this reference: 'definition-entity' or 'built-in-base-entity'.`})):r.push(new De({id:`${s.id}--${a}--${he.ReferencedEntityNotFound}`,code:he.ReferencedEntityNotFound,severity:Te.Error,message:`Entity of type "${s.type}" with id "${s.id}", is referencing an entity with id "${a}" at 'extends' that isn't yet found in the project. Perhaps it should be created first. Or perhaps the ID is incorrect.`}))}),{errors:r,explanations:i}}var zg=(s=>(s.Extends="extends",s.Implements="implements",s))(zg||{});const Pi=class Pi extends dn{constructor(i,r){super(i);R(this,"initialData");R(this,"id");R(this,"name");R(this,"codeName",null);R(this,"description",null);R(this,"x");R(this,"y");R(this,"static");R(this,"abstract");R(this,"type",d.DefinitionEntity);R(this,"additionalProperties",!1);R(this,"properties",[]);R(this,"allPropertiesImplement",null);R(this,"additionalPropertiesDataType",null);R(this,"methods",[]);R(this,"abstractMethods",[]);R(this,"extends",null);R(this,"implements",[]);R(this,"project");R(this,"errors",[]);R(this,"parent");R(this,"detachedDependents",{});R(this,"knownVersions",null);R(this,"activeVersion",!1);R(this,"initialized",!1);R(this,"startedInitialization",!1);R(this,"suggestedProperties",[]);R(this,"suggestedMethods",[]);this.initialData=i,this.project=r,this.id=i.id,this.name=i.name,this.description=i.description,this.x=i.x,this.y=i.y,this.codeName=i.codeName,this.static=i.static,this.abstract=i.abstract}static new(i=null){return{id:x.UUID.uuid(),version:x.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||B().toISOString(),author:(i==null?void 0:i.author)||x.sessionAuthor,previousVersion:null,deleted:!1,deletable:!0,editable:!0,type:d.DefinitionEntity,additionalProperties:!1,additionalPropertiesDataType:null,allPropertiesImplement:null,name:"",codeName:null,description:"",static:!1,abstract:!1,properties:[],methods:[],abstractMethods:[],extends:null,implements:[],x:0,y:0,parent:null}}static fromGenerationTarget(i,r,a){const c=a===void 0?r.addChangeSet(new S(r,x.sessionAuthor,B().toISOString(),r,!0,w.CreateFromGenerationTarget)):a;let e=r;if(i.parent){const b=ie(i.parent);e=r.get(b)}const f=[];i.implements&&i.implements.forEach(b=>{f.push(r.get(b)||r.getBuiltIn(b))});let h=null;i.extends&&(h=r.get(i.extends)||r.getBuiltIn(i.extends));const m={id:i.id,version:x.UUID.uuid(),createdAt:(c==null?void 0:c.timestamp)||B().toISOString(),author:(c==null?void 0:c.author)||x.sessionAuthor,previousVersion:null,deleted:!1,name:i.name,deletable:!0,editable:!0,type:d.DefinitionEntity,codeName:i.codeName||null,description:i.description||null,static:i.static??!1,abstract:i.abstract??!1,additionalProperties:i.additionalProperties??!1,allPropertiesImplement:null,additionalPropertiesDataType:null,properties:[],methods:[],abstractMethods:[],extends:h,implements:f,x:0,y:0,parent:e.toReference()},E=ge(m,r);return E.hydrateAncestors(),E.setParent(e,c),E.addSelfToProject(c),c==null||c.add(E,W.Added),E.initChildren(c),c||E.captureVersion(),E}static validateGenerationTarget(i,r){var b;let a=JSON.parse(JSON.stringify(i));const c=[],e=[],f=NVi(a,r),h=Vx(a,r),m=Qr(a);e.push(...f.errors,...h,...m.errors),c.push(...f.explanations,...m.explanations);const E=a.parent?r.get(a.parent):null;if(E&&E.type===d.DataType){const A=E;A.entity&&A.entity.type===d.DefinitionEntity&&((b=A.entity.parent)==null?void 0:b.id)!==A.id&&e.push(new De({id:`${i.id}--${he.NewEntityWouldOverriteExisting}`,code:he.NewEntityWouldOverriteExisting,severity:Te.Error,message:`The entity of type '${i.type}' with id '${i.id}' can't be added to the 'parent' entity with id '${A.id}' because it already has an 'entity' child. Data type entities can only have one 'entity' as children.
536
536
  You can inspect the existing 'entity' field with the 'describe_entity' action. Like so:
537
537
  ${cp({describe_entity:A.entity.id})}
package/dist/index.js CHANGED
@@ -181420,15 +181420,16 @@ Alternatively you can update the entity with 'update' action. Or replace it by f
181420
181420
  return !!this.entity && (this.entity.type === d.DefinitionEntity || this.entity.type === d.BuiltInBaseEntity || this.entity.name === fe.KeyValue) && !this.isList;
181421
181421
  }
181422
181422
  canBeObject() {
181423
- var r;
181424
- let i = !1;
181423
+ var a;
181424
+ let i = !1, r = !1;
181425
181425
  if (this.parent.type !== d.DataType && this.parent.type !== d.ActionDescriptor && this.parent.type !== d.BuiltInBaseEntity && this.parent.type !== d.DefinitionEntity && this.parent.type !== d.FunctionDeclaration) {
181426
- const a = (r = this.project.requestActiveDynamicValue(
181426
+ r = !0;
181427
+ const c = (a = this.project.requestActiveDynamicValue(
181427
181428
  this.parent
181428
- )) == null ? void 0 : r.value;
181429
- a ? !a.valueAsType && (a.value === "" || a.value === null || Dr(a)) && (i = !0) : i = !0;
181429
+ )) == null ? void 0 : a.value;
181430
+ c ? !c.valueAsType && (c.value === "" || c.value === null || Dr(c)) && (i = !0) : i = !0;
181430
181431
  }
181431
- return (this.isObject() || !this.entity || this.entity.name === fe.Untyped) && i;
181432
+ return (this.isObject() || !this.entity || this.entity.name === fe.Untyped) && (!r || r && i);
181432
181433
  }
181433
181434
  hasStrictObjectStructure() {
181434
181435
  var i;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elyx-code/project-logic-tree",
3
- "version": "0.0.6896",
3
+ "version": "0.0.6897",
4
4
  "author": "Sergio Herrero",
5
5
  "license": "UNLICENSED",
6
6
  "description": "An installable module which contains the type definitions and ephemeral state management for a projects' logic tree data structure",