@elyx-code/project-logic-tree 0.0.6877 → 0.0.6878
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 +1 -1
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -532,7 +532,7 @@ The entities of type '${vt(_,"', '","' and '")}' can only have one 'data-type' c
|
|
|
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
|
${rp({describe_entity:N})}
|
|
534
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)||eu(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 Oi(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 Oi(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[_,N]of A.knownVersions)E.set(_,N);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 Oi(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=te(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=te(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=te(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=te(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=>te(m)===e.id))||(this.removeChildGroup(e,r),e.removeFromParent(r))}),(c=i.orChildrenGroup)==null||c.forEach(e=>{const f=te(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=>te(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=te(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=te(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=te(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=te(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=te(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=te(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(P=>!P.deleted&&P.id!==this.id);_.length&&(A>_.length+1?A=_.length:A<0&&(A=0)),_.find(P=>(P.index||0)===A&&!P.deleted)&&_.filter(P=>(P.index||0)>=A&&!P.deleted).forEach(P=>{P.metaSync({index:(P.index||0)+1},i),i==null||i.add(P,W.Updated),r.push(P)}),this.metaSync({index:A},i)}return(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=Ae(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=Ae(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 N=Ae(_,this.project);return N.setParent(this,null),N.initChildren(i),N})),this.initialData.orChildrenGroup&&(this.orChildrenGroup=this.initialData.orChildrenGroup.map(_=>{const N=Ae(_,this.project);return N.setParent(this,null),N.initChildren(i),N})),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=Yr(this,i,r),c=zr(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 Oi.repository.APILoad(this.id,...r),this}async APICreate(i=Ke,...r){return await Oi.repository.APICreate(this.toShallowJSON(),...r),this}async APIUpdate(i=Ke,...r){return await Oi.repository.APIUpdate(this.toShallowJSON(),...r),this}async APIDelete(i=Ke,...r){return await Oi.repository.APIDelete(this.toShallowJSON(),...r),this}async APIClone(i=Ke,...r){return await Oi.repository.APIClone(this.id,...r),this}async APILoadVersion(i=Ke,r,...a){return await Oi.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||rn(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(N=>N.toJSONClone({...i,newId:null})))||null,orChildrenGroup:((b=this.orChildrenGroup)==null?void 0:b.map(N=>N.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=qje(this),{success:!0}}async validateAsync(i={}){const r=Y.YieldTracker.from(i);return this.errors=await Kje(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 _,N,P,j;const e=Mr(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=tr(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=(N=this.andChildrenGroup)==null?void 0:N.map(M=>this.project.diggestedBuiltInBaseEntitiesIds.has(M.id)?e.getBuiltIn(M.id):M.clone(i,E,x.UUID.uuid(),c)),A=(P=this.orChildrenGroup)==null?void 0:P.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,_,N,P,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)!==((N=this.foreignKeyRef)==null?void 0:N.id)&&(m.implementSource&&this.foreignKeyRef?oi(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(((P=this.entity)==null?void 0:P.type)===d.DefinitionEntity&&this.entity.parent===this)FT(this.entity,i.entity)||(lx(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?oi(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=oi(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=>oi(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 de=re==null?void 0:re.find(ie=>oi(ie,ee).exact);if(de||(de=re==null?void 0:re.find(ie=>oi(ie,ee))),!de){const ie=q.findIndex(se=>re==null?void 0:re.some(ue=>oi(ue,se).exact));if(ie!==-1){const[se]=q.splice(ie,1);de=re==null?void 0:re.find(ue=>oi(ue,se).exact)}}if(de){const ie=re.indexOf(de);ie!==-1&&re.splice(ie,1);const se=de.merge(ee,r,{implementSource:m.implementSource});c.push(...se.updated),e.push(...se.added),f.push(...se.removed),h.push(...se.affected)}else if(m.implementSource){const ie=ee.implement(this,r,x.UUID.uuid(),ze.OrDataTypeGroup);this.addToOrGroup(ie,r),e.push(ie)}else{const ie=ee.clone(r,this,x.UUID.uuid(),!0);this.addToOrGroup(ie,r),e.push(ie)}}[...this.orChildrenGroup||[]].forEach(ee=>{((i==null?void 0:i.orChildrenGroup)||[]).find(ie=>oi(ee,ie))||(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=>oi(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=>oi(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||Rr(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=le(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=Ae(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(oi(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&&ai(this.entity,Ie.PERSISTED_ENTITY)&&a){const e=vFe(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=Mr(i,this),f=a||x.UUID.uuid(),h=Oi.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=Ae(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(Oi,"repository",{APICreate:async(i,...r)=>i,APIUpdate:async(i,...r)=>i,APIDelete:async(i,...r)=>i,APIClone:async(i,...r)=>{},APILoad:async(i,...r)=>null,APILoadVersion:async(i,r,...a)=>null}),R(Oi,"type",d.DataType),R(Oi,"USER_MANAGED_PARENT_TYPES",[...pV]),R(Oi,"PARENT_TYPES",[...pF]),R(Oi,"MUTABLE_BASE_PROPERTIES",["isList","asType","options","foreignKeyAllowed","like","implementationChooseOne","staticEntities","interactiveEntities","actionEntities"]),R(Oi,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","index","author","previousVersion","parentRelationType"]),R(Oi,"BASE_PROPERTIES",[...Oi.MUTABLE_BASE_PROPERTIES,...Oi.INMUTABLE_BASE_PROPERTIES]),R(Oi,"MUTABLE_META_PROPERTIES",[...Oi.MUTABLE_BASE_PROPERTIES,"inferred"]),R(Oi,"INMUTABLE_META_PROPERTIES",[...Oi.INMUTABLE_BASE_PROPERTIES]),R(Oi,"META_PROPERTIES",[...Oi.MUTABLE_META_PROPERTIES,...Oi.INMUTABLE_META_PROPERTIES]),R(Oi,"MUTABLE_UPSTREAM_PROPERTIES",["entity","foreignKeyRef","parent"]),R(Oi,"INMUTABLE_UPSTREAM_PROPERTIES",[]),R(Oi,"UPSTREAM_PROPERTIES",[...Oi.MUTABLE_UPSTREAM_PROPERTIES,...Oi.INMUTABLE_UPSTREAM_PROPERTIES]),R(Oi,"MUTABLE_DOWNSTREAM_PROPERTIES",[]),R(Oi,"INMUTABLE_DOWNSTREAM_PROPERTIES",["andChildrenGroup","orChildrenGroup"]),R(Oi,"DOWNSTREAM_PROPERTIES",[...Oi.MUTABLE_DOWNSTREAM_PROPERTIES,...Oi.INMUTABLE_DOWNSTREAM_PROPERTIES]),R(Oi,"PROPERTIES",[...Oi.META_PROPERTIES,...Oi.UPSTREAM_PROPERTIES,...Oi.DOWNSTREAM_PROPERTIES]);let yr=Oi;async function Sje(l,p={}){var c;const i=Y.YieldTracker.from(p),a=[...l.implements.flatMap(e=>iL(l,e)),...vn(l),...rL(l),...qa(l)];return await i.tick(),await((c=l.dataType)==null?void 0:c.validateAsync({tracker:i})),a}function Zje(l){var r;const p=l.implements.flatMap(a=>iL(l,a));return(r=l.dataType)==null||r.validate(),[...p,...vn(l),...rL(l),...qa(l)]}function iL(l,p){const i=[];if(!l.implements)return i;if(!p.abstract){const a=It({id:`${l.id}--${be.PropertyImplementsNonAbstact}`,message:`Property "${le(l,l.project)}" with id "${l.id}" implements a non-abstract property "${le(p,l.project)}" with id "${p.id}".`,severity:Te.Error,code:be.PropertyImplementsNonAbstact,entity:l,firstRelationship:p});i.push(a.error)}if(l.static&&!p.static){const a=It({id:`${l.id}--${be.NonStaticPropertyImplementsStatic}`,message:`Static property "${le(l,l.project)}" with id "${l.id}" implements a non-static property "${le(p,l.project)}" with id "${p.id}".`,severity:Te.Error,code:be.NonStaticPropertyImplementsStatic,entity:l,firstRelationship:p});i.push(a.error)}if(!l.static&&p.static){const a=It({id:`${l.id}--${be.StaticPropertyImplementsNonStatic}`,message:`Non-static property "${le(l,l.project)}" with id "${l.id}" implements a static property "${le(p,l.project)}" with id "${p.id}".`,severity:Te.Error,code:be.StaticPropertyImplementsNonStatic,entity:l,firstRelationship:p});i.push(a.error)}if(!oi(l.dataType,p.dataType)){const a=It({id:`${l.id}--${be.PropertyImplementsIncompatibleType}`,message:`Property "${le(l,l.project)}" with id "${l.id}" implements a property "${le(p,l.project)}" with id "${p.id}" that has an incompatible data type.`,severity:Te.Error,code:be.PropertyImplementsIncompatibleType,entity:l,firstRelationship:p});i.push(a.error)}return qt(l.errors,i)}function rL(l,p){const r=[...l.parent.allProperties].filter(a=>{var c;return a.id!==l.id&&!l.implements.find(e=>e.id===a.id)&&a.id!==((c=l.extends)==null?void 0:c.id)});return jE(l,[Qi],r,p)}const r_i=Object.freeze(Object.defineProperty({__proto__:null,validate:Zje,validateAsync:Sje,validateImplementation:iL,validatePropertyEntityName:rL},Symbol.toStringTag,{value:"Module"}));function n_i(l,p){const i=[],r=[],a=Bje(l,p);if(l.parent){const e=p.get(l.parent);if(!e)r.push(new De({id:`${l.id}--${l.parent}--${he.ReferencedEntityNotFound}`,code:he.ReferencedEntityNotFound,severity:Te.Error,message:`Entity of type "${l.type}" with id "${l.id}", is referencing an entity with id "${l.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=eu(e);if(f){const h=e!==f?`The entity of type '${l.type}' with id '${l.id}' have 'parent' with id '${l.parent}' because the entity belongs to a built-in '${f.type}' entity with id '${f.id}' (${le(f,e.project)}) higher up in the tree.`:`The entity of type '${l.type}' with id '${l.id}' have 'parent' with id '${l.parent}' because it is a built-in entity of type ${f.type}.`;r.push(new De({id:`${l.id}--${he.InvalidBuiltInEntityReference}`,code:he.InvalidBuiltInEntityReference,severity:Te.Error,message:h}))}else if(![d.DefinitionEntity].includes(e.type))r.push(new De({id:`${l.id}--${l.parent}--${he.InvalidParentReference}`,code:he.InvalidParentReference,severity:Te.Error,message:`Entity of type "${l.type}" with id "${l.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=Zn(e).filter(E=>!E.interactive);if(m.length){let E=m.length>1?`The entity of type '${l.type}' with id '${l.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=>le(b,b.project)),'", "','" and "')}").`:`The entity of type '${l.type}' with id '${l.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 ("${le(m[0],m[0].project)}").`;i.push({id:Zi.NonInteractiveBaseEntities,message:Qd}),r.push(new De({id:`${l.id}--${he.NonInteractiveEntityReferenced}`,code:he.NonInteractiveEntityReferenced,severity:Te.Error,message:E}))}else l.implements&&l.implements.forEach(E=>{const b=p.get(E);if(E===l.id)return r.push(new De({id:`${l.id}--${E}--${he.SelfReference}`,code:he.SelfReference,severity:Te.Error,message:`Entity of type "${l.type}" with id "${l.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:`${l.id}--${E}--${he.InvalidImplementsReference}`,code:he.InvalidImplementsReference,severity:Te.Error,message:`Entity of type "${l.type}" with id "${l.id}", has an 'implements' reference that isn't pointing to an abstract entity.`})):r.push(new De({id:`${l.id}--${E}--${he.InvalidImplementsReference}`,code:he.InvalidImplementsReference,severity:Te.Error,message:`Entity of type "${l.type}" with id "${l.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:`${l.id}--${E}--${he.ReferencedEntityNotFound}`,code:he.ReferencedEntityNotFound,severity:Te.Error,message:`Entity of type "${l.type}" with id "${l.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:`${l.id}--${Ce.InvalidObjectStructure}`,code:Ce.InvalidObjectStructure,severity:Te.Error,message:`Entity of type "${l.type}" with id "${l.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=Vn(l,{},p);return i.push(...c.explanations),r.length>0&&i.push(...a.explanations),r.push(...c.errors),{errors:r,explanations:i}}function YU(l){var p,i,r,a,c,e,f,h,m,E,b,A;if(((i=(p=l.dataType)==null?void 0:p.entity)==null?void 0:i.type)===d.PrimitiveEntity&&((a=(r=l.dataType)==null?void 0:r.entity)==null?void 0:a.id)===((c=ne["primitive-entity"].enum)==null?void 0:c.id)){if(((e=l.dataType.options)==null?void 0:e.length)===1){const _=l.dataType.options[0];if(_)return{result:!0,value:_,name:fe.String}}}else if(((h=(f=l.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=l.dataType)==null?void 0:m.entity)==null?void 0:E.name)&&typeof((A=(b=l.dataType)==null?void 0:b.entity)==null?void 0:A.value)=="string")return{result:!0,value:l.dataType.entity.value,name:l.dataType.entity.name};return{result:!1,value:null,name:null}}function a_i(l){return!!l.implements.find(p=>p.id===ne["built-in-base-entity"].BUILT_IN_PERSISTED_ENTITY_ENTITY.properties.database.id)}function JU(l,p){const i=[],r=[],a=[],c=[];let e=!1;if(l.implements.find(f=>f.id===ne["built-in-base-entity"].BUILT_IN_PERSISTED_ENTITY_ENTITY.properties.database.id)){let f=l.defaultValue;if(!l.defaultValue){const h=Vr.new(p);h.name=fe.EntityTemplate,h.parent=l.toReference();const m=Ae(h,l.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=AFe(l.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:l}}var Hje=(l=>(l.PropertyImplements="property-implements-field",l.PropertyExtends="property-extends-field",l.PropertyDataTypeEntity="property-data-type-entity-field",l.PropertyDataType="property-data-type-field",l))(Hje||{});const ci=class ci extends nn{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=te(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=te(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=Ae(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=n_i(a,r),h=mx(a,r),m=Wr(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:oE(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
|
-
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:Zi.EntitiesWithValues,message:Ah})),{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?(JU(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(si.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"}]),a_i(this)&&this.project.on(si.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 ci(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 ci(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[_,N]of A.knownVersions)E.set(_,N);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 ci(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=te(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=te(c),f=this.project.get(e);if(f)this.addImplementation(f,r);else throw new Error(`${dr(this.type)} with id '${this.id}' has a 'implements' reference "${e}" which is missing in the project`)}),this.implements.filter(c=>{const e=te(c);return!i.implements.find(f=>te(f)===e)}).forEach(c=>{this.removeImplementation(c,r)}),i.extends){const c=te(i.extends),e=this.project.get(c);if(e)this.setExtends(e,r);else if(c)throw new Error(`${dr(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=te(i.dataType),e=this.project.get(c);e&&this.setDataType(e,r)}else this.setDataType(null,r);if(i.defaultValue){const c=te(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=te(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=te(c),f=this.project.get(e);if(f)this.addImplementation(f,r);else throw new Error(`${dr(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=te(e);return!(i.implements||[]).find(h=>te(h)===f)}).forEach(e=>{this.removeImplementation(e,r)}),i.extends){const c=te(i.extends),e=this.project.get(c);if(e)this.setExtends(e,r);else if(c)throw new Error(`${dr(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=te(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=te(e),h=this.project.get(f);if(h)this.addImplementation(h,null),i.push(h);else throw new Error(`${dr(this.type)} with id '${this.id}' has a 'implements' reference "${f}" which is missing in the project`)}),this.initialData.extends){const e=te(this.initialData.extends),f=this.project.get(e);if(f)this.setExtends(f,null),i.push(f);else if(e)throw new Error(`${dr(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!==Ud.AllPropertiesImplementationTarget){let re=this.index||0;const ee=this.parent.properties.filter(ie=>!ie.deleted&&ie.id!==this.id);ee.length&&(re>ee.length+1?re=ee.length:re<0&&(re=0)),ee.find(ie=>(ie.index||0)===re&&!ie.deleted)&&ee.filter(ie=>(ie.index||0)>=re&&!ie.deleted).forEach(ie=>{ie.metaSync({index:(ie.index||0)+1},i),i==null||i.add(ie,W.Updated),r.push(ie)}),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:N}=JU(this,i);r.push(...b),a.push(...A),c.push(..._),e.push(...N);const{updated:P,added:j,removed:M,affected:G}=this.syncWithExtension(i);return r.push(...P),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===Ud.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=Ae(this.initialData.defaultValue,this.project),this.defaultValue.setParent(this,null),this.defaultValue.initChildren(i)),this.initialData.dataType){const r=Ae(this.initialData.dataType,this.project);r.setParent(this,null),r.initChildren(i),this.dataType=r}if(this.implements=this.initialData.implements.map(r=>Ae(r,this.project)),this.initialData.extends){const r=Ae(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=Yr(this,i,r),c=zr(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 ci.repository.APILoad(this.id,...r),this}async APICreate(i=Ke,...r){return await ci.repository.APICreate(this.toShallowJSON(),...r),this}async APIUpdate(i=Ke,...r){return await ci.repository.APIUpdate(this.toShallowJSON(),...r),this}async APIDelete(i=Ke,...r){return await ci.repository.APIDelete(this.toShallowJSON(),...r),this}async APIClone(i=Ke,...r){return await ci.repository.APIClone(this.id,...r),this}async APILoadVersion(i=Ke,r,...a){return await ci.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===Ud.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===Ud.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||rn(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=Zje(this),{success:!0}}async validateAsync(i={}){const r=Y.YieldTracker.from(i);return this.errors=await Sje(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=ci.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=Ae(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=YU(this);if(m.result){let _=!1;if(!this.defaultValue){const N=Vr.new(r);N.value=m.value,N.name=m.name,N.parent=f.toReference();const P=Ae(N,this.project);P.hydrateAncestors(),P.addSelfToProject(r),P.initChildren(r),f.setDefaultValue(P,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=Mr(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=tr(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 N=e.get(_.id)||e.getBuiltIn(_.id);if(N){E.addImplementation(N,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||Ln(i))&&f&&(i=f)}let r=this.defaultValue;const a=(c=this.extends)==null?void 0:c.getDefaultValue();return Ln(r)&&a&&!Ln(a)&&(r=a),Ln(r)&&i&&!Ln(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 _,N,P,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(de=>de.id!==M.id);if(!G.length)return!0;const q=pl(Ma(M.dataType),{removeDuplicates:!0,removeNulls:!0}).filter(de=>de.isResolved);return!!G.every(de=>!de.dataType||!de.dataType.isResolved?!0:pl(Ma(de.dataType),{removeDuplicates:!0,removeNulls:!0}).filter(se=>se.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?((N=M.dataType.orChildrenGroup)!=null&&N.length&&M.dataType.implementationChooseOne||(P=M.dataType.orChildrenGroup)!=null&&P.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=YU(this);if(M.result){const G=Vr.new(i);G.name=M.name,G.value=M.value,G.parent=this.toReference();const q=Ae(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 _=yr.new(i);_.parent=this.toReference();const N=Ae(_,this.project);N.hydrateAncestors(),N.addSelfToProject(i),i==null||i.add(N,W.Added),N.afterAllChildrenInitialized(i),h=!0}if(oi(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&&!VUe(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=ds.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=tr(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(ci,"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(ci,"type",d.Property),R(ci,"USER_MANAGED_PARENT_TYPES",[d.DefinitionEntity]),R(ci,"PARENT_TYPES",[...ci.USER_MANAGED_PARENT_TYPES,d.PrimitiveEntity,d.BuiltInBaseEntity]),R(ci,"MUTABLE_BASE_PROPERTIES",["name","codeName","description","private","abstract","static","required","constant","unique","interactive"]),R(ci,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion","parentRelationType"]),R(ci,"BASE_PROPERTIES",[...ci.MUTABLE_BASE_PROPERTIES,...ci.INMUTABLE_BASE_PROPERTIES]),R(ci,"MUTABLE_META_PROPERTIES",[...ci.MUTABLE_BASE_PROPERTIES,"index"]),R(ci,"INMUTABLE_META_PROPERTIES",[...ci.INMUTABLE_BASE_PROPERTIES]),R(ci,"META_PROPERTIES",[...ci.MUTABLE_META_PROPERTIES,...ci.INMUTABLE_META_PROPERTIES]),R(ci,"MUTABLE_UPSTREAM_PROPERTIES",[]),R(ci,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","implements","extends"]),R(ci,"UPSTREAM_PROPERTIES",[...ci.MUTABLE_UPSTREAM_PROPERTIES,...ci.INMUTABLE_UPSTREAM_PROPERTIES]),R(ci,"MUTABLE_DOWNSTREAM_PROPERTIES",["dataType","defaultValue"]),R(ci,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),R(ci,"DOWNSTREAM_PROPERTIES",[...ci.MUTABLE_DOWNSTREAM_PROPERTIES,...ci.INMUTABLE_DOWNSTREAM_PROPERTIES]),R(ci,"PROPERTIES",[...ci.META_PROPERTIES,...ci.UPSTREAM_PROPERTIES,...ci.DOWNSTREAM_PROPERTIES]);let ps=ci;async function Wje(l,p={}){var E,b;const i=Y.YieldTracker.from(p),r=l.implements.flatMap(A=>Qje(l,A)),a=Xje(l,l.extends),c=tke(l),e=eke(l),f=nL(l),h=[...r,...a,...c,...e,...f],m=qt(l.errors,h);await i.tick();for(const A of l.properties)await A.validateAsync({tracker:i});for(const A of l.methods)await A.validateAsync({tracker:i});for(const A of l.abstractMethods)await A.validateAsync({tracker:i});return await((E=l.allPropertiesImplement)==null?void 0:E.validateAsync({tracker:i})),await((b=l.additionalPropertiesDataType)==null?void 0:b.validateAsync({tracker:i})),m}function zje(l){var h,m;const p=l.implements.flatMap(E=>Qje(l,E)),i=Xje(l,l.extends),r=tke(l),a=eke(l),c=nL(l);l.properties.forEach(E=>{E.validate()}),l.methods.flatMap(E=>E.validate()),l.abstractMethods.flatMap(E=>E.validate()),(h=l.allPropertiesImplement)==null||h.validate(),(m=l.additionalPropertiesDataType)==null||m.validate();const e=[...p,...i,...r,...a,...c];return qt(l.errors,e)}function Yje(l,p){const i=p.properties.filter(c=>c.abstract),r=[];let a=[...l.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 Jje(l,p){const i=p.abstractMethods,r=[];let a=[...l.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 Qje(l,p){const i=[];if(!p.abstract){const E=It({id:l.id+"--"+be.ImplementingNonAbstractEntity,message:`Entity "${l.name}" with id "${l.id}" is implementing a non-abstract entity "${p.name}" with id "${p.id}"`,severity:Te.Error,code:be.ImplementingNonAbstractEntity,entity:l});return i.push(E.error),i}const r=p.properties.filter(E=>E.abstract),a=[];let c=[...l.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=It({id:l.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 "${l.name}" with id "${l.id}" implements it`,severity:Te.Error,code:be.MissingPropertyImplementation,entity:l});i.push(b.error)});const e=[];let f=[...l.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=It({id:l.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 "${l.name}" with id "${l.id}" implements it`,severity:Te.Error,code:be.MissingMethodImplementation,entity:l});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=It({id:l.id+"--"+Ce.PropertyOverwritesOtherSiblingWithSameName+"--"+E.id,message:`Property "${E.name}" with id "${E.id}" of entity "${l.name}" with id "${l.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:l});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=It({id:l.id+"--"+Ce.MethodOverwritesOtherSiblingWithSameName+"--"+E.id,message:`Method "${E.name}" with id "${E.id}" of entity "${l.name}" with id "${l.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:l});i.push(b.error)}),i}function Xje(l,p){const i=[];if(!p)return i;const r=[];if(!l.abstract&&p.abstract){const c=It({id:l.id+"--"+p.id+"--"+be.NonAbstractExtendingAbstractEntity,message:`Entity "${l.name}" with id "${l.id}" is not-abstract but is extending an abstract entity "${p.name}" with id "${p.id}"`,severity:Te.Error,code:be.NonAbstractExtendingAbstractEntity,entity:l,firstRelationship:p});return i.push(c.error),i}if(l.abstract&&!p.abstract){const c=It({id:l.id+"--"+p.id+"--"+be.AbstractExtendingNonAbstractEntity,message:`Entity "${l.name}" with id "${l.id}" is abstract but is extending an non-abstract entity "${p.name}" with id "${p.id}"`,severity:Te.Error,code:be.AbstractExtendingNonAbstractEntity,entity:l,firstRelationship:p});return i.push(c.error),i}l.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=It({id:l.id+"--"+Ce.PropertyOverwritesOtherSiblingWithSameName,message:`Property "${c.name}" with id "${c.id}" of entity "${l.name}" with id "${l.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:l});i.push(e.error)});const a=[];return l.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=It({id:l.id+"--"+Ce.MethodOverwritesOtherSiblingWithSameName,message:`Method "${c.name}" with id "${c.id}" of entity "${l.name}" with id "${l.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:l});i.push(e.error)}),i}function eke(l){const p=[];if(!l.properties.length){const i=It({id:l.id+"--"+be.NoProperties,message:"No properties implemented",severity:Te.Warning,code:be.NoProperties,entity:l});p.push(i.error)}return p}function tke(l){const p=[];if(l.abstract){if(l.methods.length){const i=It({id:l.id+"--"+be.AbstractEntityWithNonAbstractMethods,message:`Entity "${l.name}" with id "${l.id}" is marked as abstract but has non-abstract methods`,severity:Te.Error,code:be.AbstractEntityWithNonAbstractMethods,entity:l});p.push(i.error)}if(l.properties.some(i=>!i.abstract)){const i=It({id:l.id+"--"+be.AbstractEntityWithNonAbstractProperties,message:`Entity "${l.name}" with id "${l.id}" is marked as abstract but has non-abstract properties`,severity:Te.Error,code:be.AbstractEntityWithNonAbstractProperties,entity:l});p.push(i.error),l.properties.forEach(r=>{if(!r.abstract){const a=It({id:l.id+"--"+be.StaticEntityWithNonStaticProperties+"--"+r.id,message:`Property "${r.name}" with id "${r.id}" of entity "${l.name}" with id "${l.id}" is not marked as abstract but the entity is marked as abstract`,severity:Te.Error,code:be.StaticEntityWithNonStaticProperties,entity:l});p.push(a.error)}})}}else{if(l.abstractMethods.length){const i=It({id:l.id+"--"+be.AbstractPropertyInNonAbstractEntity,message:`Entity "${l.name}" with id "${l.id}" is not marked as abstract but has abstract methods`,severity:Te.Error,code:be.AbstractPropertyInNonAbstractEntity,entity:l});p.push(i.error)}l.properties.some(i=>i.abstract)&&l.properties.forEach(i=>{if(i.abstract){const r=It({id:l.id+"--"+be.AbstractPropertyInNonAbstractEntity+"--"+i.id,message:`Property "${i.name}" with id "${i.id}" of entity "${l.name}" with id "${l.id}" is marked as abstract but the entity is not marked as abstract`,severity:Te.Error,code:be.AbstractPropertyInNonAbstractEntity,entity:l,firstRelationship:i});p.push(r.error)}})}return l.static&&l.properties.some(i=>!i.static)&&l.properties.forEach(i=>{if(!i.static){const r=It({id:l.id+"--"+be.NonStaticPropertyInStaticEntity+"--"+i.id,message:`Property "${i.name}" with id "${i.id}" of entity "${l.name}" with id "${l.id}" is not marked as static but the entity is marked as static`,severity:Te.Error,code:be.NonStaticPropertyInStaticEntity,entity:l,firstRelationship:i});p.push(r.error)}}),p}function s_i(l,p){const i=[],r=Zn(p);if(!p.abstract){const e=new ki({id:l.id+"--"+p.id+"--"+be.ImplementingNonAbstractEntity,message:`Entity "${l.name}" with id "${l.id}" is implementing a non-abstract built-in entity "${p.name}" with id "${p.id}"`,severity:Te.Error,code:be.ImplementingNonAbstractEntity,entity:l,firstRelationship:p});i.push(e)}const a=l.implements.filter(e=>e.id!==p.id);if(l.abstract){const e=new ki({id:l.id+"--"+p.id+"--"+be.AbstractEntityImplements,message:`Entity "${l.name}" with id "${l.id}" is marked as abstract and cannot implement built-in entity "${p.name}" with id "${p.id}"`,severity:Te.Error,code:be.AbstractEntityImplements,entity:l,firstRelationship:p});i.push(e)}if(l.static&&!p.static){const e=new ki({id:l.id+"--"+p.id+"--"+be.StaticImplementingNonStaticEntity,message:`Entity "${l.name}" with id "${l.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:l,firstRelationship:p});i.push(e)}if(!l.static&&p.static){const e=new ki({id:l.id+"--"+p.id+"--"+be.NonStaticImplementingStaticEntity,message:`Entity "${l.name}" with id "${l.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:l,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 ki({id:l.id+"--"+h.id+"--"+e.id+"--"+be.ImplementsIncompatibleEntities,message:`Entity "${l.name}" with id "${l.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:l,firstRelationship:h,secondRelationship:e});i.push(m)}})}else{Zn(e).forEach(E=>{const b=r.filter(A=>A.id!==E.id);b.length&&b.forEach(A=>{if(A.id!==E.id){const _=new ki({id:l.id+"--"+A.id+"--"+E.id+"--"+be.ImplementsIncompatibleEntities,message:`Entity "${l.name}" with id "${l.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:l,firstRelationship:A,secondRelationship:E});i.push(_)}})});const h=jd(p.ownDeclaredProperties,e.ownDeclaredProperties,Ce.PropertyOverwritesOtherImplementedEntitysPropertyWithSameImplementation,Ce.PropertyOverwritesOtherImplementedEntitysPropertyWithSameName);i.push(...h.errors);const m=jd(p.abstractMethods,[...e.abstractMethods,...e.methods],Ce.MethodOverwritesOtherImplementedEntitysMethodWithSameImplementation,Ce.MethodOverwritesOtherImplementedEntitysMethodWithSameName);i.push(...m.errors)}}),C(l.extends?Zn(l.extends):[]).forEach(e=>{if(!r.find(f=>f.id===e.id)){const f=new ki({id:l.id+"--"+p.id+"--"+e.id+"--"+be.ExtendsIncompatibleEntities,message:`Entity "${l.name}" with id "${l.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:l,firstRelationship:p,secondRelationship:e});i.push(f)}}),i}function l_i(l,p,i=!1){var m,E;const r=[],a=Zn(p);if(!l.abstract&&p.abstract){const b=It({id:l.id+"--"+p.id+"--"+be.NonAbstractExtendingAbstractEntity,message:`Entity "${l.name}" with id "${l.id}" is not-abstract but is extending an abstract entity "${p.name}" with id "${p.id}"`,severity:Te.Error,code:be.NonAbstractExtendingAbstractEntity,entity:l,firstRelationship:p});r.push(b.error)}if(l.abstract&&!p.abstract){const b=It({id:l.id+"--"+p.id+"--"+be.AbstractExtendingNonAbstractEntity,message:`Entity "${l.name}" with id "${l.id}" is abstract but is extending an non-abstract entity "${p.name}" with id "${p.id}"`,severity:Te.Error,code:be.AbstractExtendingNonAbstractEntity,entity:l,firstRelationship:p});r.push(b.error)}if(!l.static&&p.static){const b=It({id:l.id+"--"+p.id+"--"+be.NonStaticExtendingStaticEntity,message:`Entity "${l.name}" with id "${l.id}" is not static but is extending a static entity "${p.name}" with id "${p.id}"`,severity:Te.Error,code:be.NonStaticExtendingStaticEntity,entity:l,firstRelationship:p});r.push(b.error)}if(l.static&&!p.static){const b=It({id:l.id+"--"+p.id+"--"+be.StaticExtendingNonStaticEntity,message:`Entity "${l.name}" with id "${l.id}" is static but is extending an non-static entity "${p.name}" with id "${p.id}"`,severity:Te.Error,code:be.StaticExtendingNonStaticEntity,entity:l,firstRelationship:p});r.push(b.error)}if(!cl(p)){const b=It({id:l.id+"--"+p.id+"--"+be.ExtendingNonInteractiveEntity,message:`Entity "${l.name}" with id "${l.id}" is extending an non-interactive entity "${p.name}" with id "${p.id}"`,severity:Te.Error,code:be.ExtendingNonInteractiveEntity,entity:l,firstRelationship:p});r.push(b.error)}if(l.extends&&((m=l.extends)==null?void 0:m.id)!==p.id)if(((E=l.extends)==null?void 0:E.type)===d.BuiltInBaseEntity){const b=a.filter(A=>{var _;return A.id!==((_=l.extends)==null?void 0:_.id)});b.length&&b.forEach(A=>{var _,N,P,j;if(A.id!==((_=l.extends)==null?void 0:_.id)){const M=It({id:l.id+"--"+A.id+"--"+((N=l.extends)==null?void 0:N.id)+"--"+be.ExtendsIncompatibleEntities,message:`Entity "${l.name}" with id "${l.id}" is extending built-in entity "${A.name}" with id "${A.id}" but also extends entity "${(P=l.extends)==null?void 0:P.name}" with id "${(j=l.extends)==null?void 0:j.id}" which is incompatible`,severity:Te.Error,code:be.ExtendsIncompatibleEntities,entity:l,firstRelationship:A,secondRelationship:l.extends});r.push(M.error)}})}else{Zn(l.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 ki({id:l.id+"--"+q.id+"--"+M.id+"--"+be.ImplementsIncompatibleEntities,message:`Entity "${l.name}" with id "${l.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:l,firstRelationship:q,secondRelationship:M});r.push(re)}})});const A=!!Zn(l.extends).find(M=>M.id===p.id);let _=[...l.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 N=[...l.extends.methods];A&&(N=N.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 P=jd(p.ownDeclaredProperties,_,Ce.PropertyOverwritesOtherExtendedEntitysPropertyWithSameImplementation,Ce.PropertyOverwritesOtherExtendedEntitysPropertyWithSameName);r.push(...P.errors);const j=jd(p.abstractMethods,N,Ce.MethodOverwritesOtherExtendedEntitysMethodWithSameImplementation,Ce.MethodOverwritesOtherExtendedEntitysMethodWithSameName);r.push(...j.errors)}i&&Y.Logger.log("self.implements.length",l.implements.length),l.implements.length&&l.implements.forEach(b=>{if(b.type===d.BuiltInBaseEntity){const A=a.filter(_=>_.id!==b.id);A.length&&A.forEach(_=>{if(_.id!==b.id){const N=new ki({id:l.id+"--"+_.id+"--"+b.id+"--"+be.ImplementsIncompatibleEntities,message:`Entity "${l.name}" with id "${l.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:l,firstRelationship:_,secondRelationship:b});r.push(N)}})}else{Zn(b).forEach(P=>{const j=a.filter(M=>M.id!==P.id);j.length&&j.forEach(M=>{if(M.id!==P.id){const G=new ki({id:l.id+"--"+M.id+"--"+P.id+"--"+be.ImplementsIncompatibleEntities,message:`Entity "${l.name}" with id "${l.id}" is implementing built-in entity "${M.name}" with id "${M.id}" but also implements entity "${P.name}" with id "${P.id}" which is incompatible`,severity:Te.Error,code:be.ImplementsIncompatibleEntities,entity:l,firstRelationship:M,secondRelationship:P});r.push(G)}})});const _=jd(p.ownDeclaredProperties,b.ownDeclaredProperties,Ce.PropertyOverwritesOtherImplementedEntitysPropertyWithSameImplementation,Ce.PropertyOverwritesOtherImplementedEntitysPropertyWithSameName);r.push(..._.errors);const N=jd(p.abstractMethods,[...b.abstractMethods,...b.methods],Ce.MethodOverwritesOtherImplementedEntitysMethodWithSameImplementation,Ce.MethodOverwritesOtherImplementedEntitysMethodWithSameName);r.push(...N.errors)}});const e=jd(l.ownDeclaredProperties,p.ownDeclaredProperties,Ce.PropertyOverwritesOtherSiblingWithSameImplementation,Ce.PropertyOverwritesOtherSiblingWithSameName);r.push(...e.errors);const f=jd(p.methods,p.abstractMethods,Ce.MethodOverwritesOtherSiblingWithSameImplementation,Ce.MethodOverwritesOtherSiblingWithSameName);return r.push(...f.errors),C(l.extends?Zn(l.extends):[]).forEach(b=>{if(!a.find(A=>A.id===b.id)){const A=new ki({id:l.id+"--"+p.id+"--"+b.id+"--"+be.ImplementsIncompatibleEntities,message:`Entity "${l.name}" with id "${l.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:l,firstRelationship:p,secondRelationship:b});r.push(A)}}),r}function o_i(l){const p=[];if(l.implements.forEach(i=>{if(!i.static){const r=new ki({id:l.id+"--"+i.id+"--"+be.StaticImplementingNonStaticEntity,message:`Entity "${l.name}" with id "${l.id}" is static but implements entity "${i.name}" with id "${i.id}" which is non-static`,severity:Te.Error,code:be.StaticImplementingNonStaticEntity,entity:l,firstRelationship:i});p.push(r)}}),l.extends&&!l.extends.static){const i=new ki({id:l.id+"--"+l.extends.id+"--"+be.StaticExtendingNonStaticEntity,message:`Entity "${l.name}" with id "${l.id}" is static but extends entity "${l.extends.name}" with id "${l.extends.id}" which is non-static`,severity:Te.Error,code:be.StaticExtendingNonStaticEntity,entity:l,firstRelationship:l.extends});p.push(i)}return p}function d_i(l){const p=[];if(l.implements.length){const i=new ki({id:l.id+"--"+be.AbstractEntityImplements,message:`Entity "${l.name}" with id "${l.id}" cannot be marked as abstract because it implements other entities`,severity:Te.Error,code:be.AbstractEntityImplements,entity:l});p.push(i)}if(l.extends&&!l.extends.abstract){const i=new ki({id:l.id+"--"+l.extends.id+"--"+be.AbstractExtendingNonAbstractEntity,message:`Entity "${l.name}" with id "${l.id}" is abstract but extends entity "${l.extends.name}" with id "${l.extends.id}" which is non-abstract`,severity:Te.Error,code:be.AbstractExtendingNonAbstractEntity,entity:l,firstRelationship:l.extends});p.push(i)}return p}function u_i(l){const p=[];if(l.extends&&l.extends.static){const i=new ki({id:l.id+"--"+l.extends.id+"--"+be.NonStaticExtendingStaticEntity,message:`Entity "${l.name}" with id "${l.id}" is non-static but extends entity "${l.extends.name}" with id "${l.extends.id}" which is static`,severity:Te.Error,code:be.NonStaticExtendingStaticEntity,entity:l,firstRelationship:l.extends});p.push(i)}return p}function p_i(l){const p=[];if(l.extends&&l.extends.abstract){const i=new ki({id:l.id+"--"+l.extends.id+"--"+be.NonAbstractExtendingAbstractEntity,message:`Entity "${l.name}" with id "${l.id}" is non-abstract but extends entity "${l.extends.name}" with id "${l.extends.id}" which is abstract`,severity:Te.Error,code:be.NonAbstractExtendingAbstractEntity,entity:l,firstRelationship:l.extends});p.push(i)}return p}function nL(l,p){const r=[...l.project.entities].filter(a=>a.id!==l.id);return jE(l,[Qi,sd],r,p)}const c_i=Object.freeze(Object.defineProperty({__proto__:null,getBaseMethodsNotImplemented:Jje,getBasePropertiesNotImplemented:Yje,validate:zje,validateAsync:Wje,validateCanBecomeAbstract:d_i,validateCanBecomeNonAbstract:p_i,validateCanBecomeNonStatic:u_i,validateCanBecomeStatic:o_i,validateCanExtendEntity:l_i,validateCanImplementEntity:s_i,validateDefinitionEntityName:nL},Symbol.toStringTag,{value:"Module"}));function f_i(l,p){const i=[],r=[];if(l.parent)if(l.id===l.parent)r.push(new De({id:`${l.id}--${l.parent}--${he.SelfReference}`,code:he.SelfReference,severity:Te.Error,message:`Entity of type "${l.type}" with id "${l.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(l.parent);a?[d.Project,d.DataType].includes(a.type)||r.push(new De({id:`${l.id}--${l.parent}--${he.InvalidParentReference}`,code:he.InvalidParentReference,severity:Te.Error,message:`Entity of type "${l.type}" with id "${l.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:`${l.id}--${l.parent}--${he.ReferencedEntityNotFound}`,code:he.ReferencedEntityNotFound,severity:Te.Error,message:`Entity of type "${l.type}" with id "${l.id}", is referencing an entity with id "${l.parent}" at 'parent' that isn't yet found in the project. Perhaps it should be created first. Or perhaps the ID is incorrect.`}))}return l.implements&&Array.isArray(l.implements)?l.implements.forEach(a=>{if(l.id===a){r.push(new De({id:`${l.id}--${a}--${he.SelfReference}`,code:he.SelfReference,severity:Te.Error,message:`Entity of type "${l.type}" with id "${l.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:`${l.id}--${a}--${he.InvalidImplementsReference}`,code:he.InvalidImplementsReference,severity:Te.Error,message:`Entity of type "${l.type}" with id "${l.id}", has an 'implements' reference that isn't pointing to an abstract entity.`})):r.push(new De({id:`${l.id}--${a}--${he.InvalidImplementsReference}`,code:he.InvalidImplementsReference,severity:Te.Error,message:`Entity of type "${l.type}" with id "${l.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:`${l.id}--${a}--${he.ReferencedEntityNotFound}`,code:he.ReferencedEntityNotFound,severity:Te.Error,message:`Entity of type "${l.type}" with id "${l.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:`${l.id}--${Ce.InvalidObjectStructure}`,code:Ce.InvalidObjectStructure,severity:Te.Error,message:`Entity of type "${l.type}" with id "${l.id}", has an 'implements' property that isn't an array.`})),l.extends&&Array.isArray(l.extends)&&l.extends.forEach(a=>{const c=p.get(a);c?[d.DefinitionEntity,d.BuiltInBaseEntity].includes(c.type)?c.abstract&&r.push(new De({id:`${l.id}--${a}--${he.InvalidExtendsReference}`,code:he.InvalidExtendsReference,severity:Te.Error,message:`Entity of type "${l.type}" with id "${l.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:`${l.id}--${a}--${he.InvalidExtendsReference}`,code:he.InvalidExtendsReference,severity:Te.Error,message:`Entity of type "${l.type}" with id "${l.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:`${l.id}--${a}--${he.ReferencedEntityNotFound}`,code:he.ReferencedEntityNotFound,severity:Te.Error,message:`Entity of type "${l.type}" with id "${l.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 jI=(l=>(l.Extends="extends",l.Implements="implements",l))(jI||{});const _i=class _i extends nn{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=te(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=Ae(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=f_i(a,r),h=fx(a,r),m=Wr(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.
|
|
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:Zi.EntitiesWithValues,message:Ah})),{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?(JU(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(si.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"}]),a_i(this)&&this.project.on(si.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 ci(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 ci(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[_,N]of A.knownVersions)E.set(_,N);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 ci(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=te(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=te(c),f=this.project.get(e);if(f)this.addImplementation(f,r);else throw new Error(`${dr(this.type)} with id '${this.id}' has a 'implements' reference "${e}" which is missing in the project`)}),this.implements.filter(c=>{const e=te(c);return!i.implements.find(f=>te(f)===e)}).forEach(c=>{this.removeImplementation(c,r)}),i.extends){const c=te(i.extends),e=this.project.get(c);if(e)this.setExtends(e,r);else if(c)throw new Error(`${dr(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=te(i.dataType),e=this.project.get(c);e&&this.setDataType(e,r)}else this.setDataType(null,r);if(i.defaultValue){const c=te(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=te(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=te(c),f=this.project.get(e);if(f)this.addImplementation(f,r);else throw new Error(`${dr(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=te(e);return!(i.implements||[]).find(h=>te(h)===f)}).forEach(e=>{this.removeImplementation(e,r)}),i.extends){const c=te(i.extends),e=this.project.get(c);if(e)this.setExtends(e,r);else if(c)throw new Error(`${dr(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=te(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=te(e),h=this.project.get(f);if(h)this.addImplementation(h,null),i.push(h);else throw new Error(`${dr(this.type)} with id '${this.id}' has a 'implements' reference "${f}" which is missing in the project`)}),this.initialData.extends){const e=te(this.initialData.extends),f=this.project.get(e);if(f)this.setExtends(f,null),i.push(f);else if(e)throw new Error(`${dr(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!==Ud.AllPropertiesImplementationTarget){let re=this.index||0;const ee=this.parent.properties.filter(ie=>!ie.deleted&&ie.id!==this.id);ee.length&&(re>ee.length+1?re=ee.length:re<0&&(re=0)),ee.find(ie=>(ie.index||0)===re&&!ie.deleted)&&ee.filter(ie=>(ie.index||0)>=re&&!ie.deleted).forEach(ie=>{ie.metaSync({index:(ie.index||0)+1},i),i==null||i.add(ie,W.Updated),r.push(ie)}),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:N}=JU(this,i);r.push(...b),a.push(...A),c.push(..._),e.push(...N);const{updated:P,added:j,removed:M,affected:G}=this.syncWithExtension(i);return r.push(...P),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===Ud.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=Ae(this.initialData.defaultValue,this.project),this.defaultValue.setParent(this,null),this.defaultValue.initChildren(i)),this.initialData.dataType){const r=Ae(this.initialData.dataType,this.project);r.setParent(this,null),r.initChildren(i),this.dataType=r}if(this.implements=this.initialData.implements.map(r=>Ae(r,this.project)),this.initialData.extends){const r=Ae(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=Yr(this,i,r),c=zr(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 ci.repository.APILoad(this.id,...r),this}async APICreate(i=Ke,...r){return await ci.repository.APICreate(this.toShallowJSON(),...r),this}async APIUpdate(i=Ke,...r){return await ci.repository.APIUpdate(this.toShallowJSON(),...r),this}async APIDelete(i=Ke,...r){return await ci.repository.APIDelete(this.toShallowJSON(),...r),this}async APIClone(i=Ke,...r){return await ci.repository.APIClone(this.id,...r),this}async APILoadVersion(i=Ke,r,...a){return await ci.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===Ud.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===Ud.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||rn(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=Zje(this),{success:!0}}async validateAsync(i={}){const r=Y.YieldTracker.from(i);return this.errors=await Sje(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=ci.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=Ae(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=YU(this);if(m.result){let _=!1;if(!f.defaultValue){const N=Vr.new(r);N.value=m.value,N.name=m.name,N.parent=f.toReference();const P=Ae(N,this.project);P.hydrateAncestors(),P.addSelfToProject(r),P.initChildren(r),f.setDefaultValue(P,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=Mr(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=tr(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 N=e.get(_.id)||e.getBuiltIn(_.id);if(N){E.addImplementation(N,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||Ln(i))&&f&&(i=f)}let r=this.defaultValue;const a=(c=this.extends)==null?void 0:c.getDefaultValue();return Ln(r)&&a&&!Ln(a)&&(r=a),Ln(r)&&i&&!Ln(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 _,N,P,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(de=>de.id!==M.id);if(!G.length)return!0;const q=pl(Ma(M.dataType),{removeDuplicates:!0,removeNulls:!0}).filter(de=>de.isResolved);return!!G.every(de=>!de.dataType||!de.dataType.isResolved?!0:pl(Ma(de.dataType),{removeDuplicates:!0,removeNulls:!0}).filter(se=>se.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?((N=M.dataType.orChildrenGroup)!=null&&N.length&&M.dataType.implementationChooseOne||(P=M.dataType.orChildrenGroup)!=null&&P.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=YU(this);if(M.result){const G=Vr.new(i);G.name=M.name,G.value=M.value,G.parent=this.toReference();const q=Ae(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 _=yr.new(i);_.parent=this.toReference();const N=Ae(_,this.project);N.hydrateAncestors(),N.addSelfToProject(i),i==null||i.add(N,W.Added),N.afterAllChildrenInitialized(i),h=!0}if(oi(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&&!VUe(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=ds.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=tr(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(ci,"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(ci,"type",d.Property),R(ci,"USER_MANAGED_PARENT_TYPES",[d.DefinitionEntity]),R(ci,"PARENT_TYPES",[...ci.USER_MANAGED_PARENT_TYPES,d.PrimitiveEntity,d.BuiltInBaseEntity]),R(ci,"MUTABLE_BASE_PROPERTIES",["name","codeName","description","private","abstract","static","required","constant","unique","interactive"]),R(ci,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion","parentRelationType"]),R(ci,"BASE_PROPERTIES",[...ci.MUTABLE_BASE_PROPERTIES,...ci.INMUTABLE_BASE_PROPERTIES]),R(ci,"MUTABLE_META_PROPERTIES",[...ci.MUTABLE_BASE_PROPERTIES,"index"]),R(ci,"INMUTABLE_META_PROPERTIES",[...ci.INMUTABLE_BASE_PROPERTIES]),R(ci,"META_PROPERTIES",[...ci.MUTABLE_META_PROPERTIES,...ci.INMUTABLE_META_PROPERTIES]),R(ci,"MUTABLE_UPSTREAM_PROPERTIES",[]),R(ci,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","implements","extends"]),R(ci,"UPSTREAM_PROPERTIES",[...ci.MUTABLE_UPSTREAM_PROPERTIES,...ci.INMUTABLE_UPSTREAM_PROPERTIES]),R(ci,"MUTABLE_DOWNSTREAM_PROPERTIES",["dataType","defaultValue"]),R(ci,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),R(ci,"DOWNSTREAM_PROPERTIES",[...ci.MUTABLE_DOWNSTREAM_PROPERTIES,...ci.INMUTABLE_DOWNSTREAM_PROPERTIES]),R(ci,"PROPERTIES",[...ci.META_PROPERTIES,...ci.UPSTREAM_PROPERTIES,...ci.DOWNSTREAM_PROPERTIES]);let ps=ci;async function Wje(l,p={}){var E,b;const i=Y.YieldTracker.from(p),r=l.implements.flatMap(A=>Qje(l,A)),a=Xje(l,l.extends),c=tke(l),e=eke(l),f=nL(l),h=[...r,...a,...c,...e,...f],m=qt(l.errors,h);await i.tick();for(const A of l.properties)await A.validateAsync({tracker:i});for(const A of l.methods)await A.validateAsync({tracker:i});for(const A of l.abstractMethods)await A.validateAsync({tracker:i});return await((E=l.allPropertiesImplement)==null?void 0:E.validateAsync({tracker:i})),await((b=l.additionalPropertiesDataType)==null?void 0:b.validateAsync({tracker:i})),m}function zje(l){var h,m;const p=l.implements.flatMap(E=>Qje(l,E)),i=Xje(l,l.extends),r=tke(l),a=eke(l),c=nL(l);l.properties.forEach(E=>{E.validate()}),l.methods.flatMap(E=>E.validate()),l.abstractMethods.flatMap(E=>E.validate()),(h=l.allPropertiesImplement)==null||h.validate(),(m=l.additionalPropertiesDataType)==null||m.validate();const e=[...p,...i,...r,...a,...c];return qt(l.errors,e)}function Yje(l,p){const i=p.properties.filter(c=>c.abstract),r=[];let a=[...l.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 Jje(l,p){const i=p.abstractMethods,r=[];let a=[...l.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 Qje(l,p){const i=[];if(!p.abstract){const E=It({id:l.id+"--"+be.ImplementingNonAbstractEntity,message:`Entity "${l.name}" with id "${l.id}" is implementing a non-abstract entity "${p.name}" with id "${p.id}"`,severity:Te.Error,code:be.ImplementingNonAbstractEntity,entity:l});return i.push(E.error),i}const r=p.properties.filter(E=>E.abstract),a=[];let c=[...l.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=It({id:l.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 "${l.name}" with id "${l.id}" implements it`,severity:Te.Error,code:be.MissingPropertyImplementation,entity:l});i.push(b.error)});const e=[];let f=[...l.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=It({id:l.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 "${l.name}" with id "${l.id}" implements it`,severity:Te.Error,code:be.MissingMethodImplementation,entity:l});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=It({id:l.id+"--"+Ce.PropertyOverwritesOtherSiblingWithSameName+"--"+E.id,message:`Property "${E.name}" with id "${E.id}" of entity "${l.name}" with id "${l.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:l});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=It({id:l.id+"--"+Ce.MethodOverwritesOtherSiblingWithSameName+"--"+E.id,message:`Method "${E.name}" with id "${E.id}" of entity "${l.name}" with id "${l.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:l});i.push(b.error)}),i}function Xje(l,p){const i=[];if(!p)return i;const r=[];if(!l.abstract&&p.abstract){const c=It({id:l.id+"--"+p.id+"--"+be.NonAbstractExtendingAbstractEntity,message:`Entity "${l.name}" with id "${l.id}" is not-abstract but is extending an abstract entity "${p.name}" with id "${p.id}"`,severity:Te.Error,code:be.NonAbstractExtendingAbstractEntity,entity:l,firstRelationship:p});return i.push(c.error),i}if(l.abstract&&!p.abstract){const c=It({id:l.id+"--"+p.id+"--"+be.AbstractExtendingNonAbstractEntity,message:`Entity "${l.name}" with id "${l.id}" is abstract but is extending an non-abstract entity "${p.name}" with id "${p.id}"`,severity:Te.Error,code:be.AbstractExtendingNonAbstractEntity,entity:l,firstRelationship:p});return i.push(c.error),i}l.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=It({id:l.id+"--"+Ce.PropertyOverwritesOtherSiblingWithSameName,message:`Property "${c.name}" with id "${c.id}" of entity "${l.name}" with id "${l.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:l});i.push(e.error)});const a=[];return l.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=It({id:l.id+"--"+Ce.MethodOverwritesOtherSiblingWithSameName,message:`Method "${c.name}" with id "${c.id}" of entity "${l.name}" with id "${l.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:l});i.push(e.error)}),i}function eke(l){const p=[];if(!l.properties.length){const i=It({id:l.id+"--"+be.NoProperties,message:"No properties implemented",severity:Te.Warning,code:be.NoProperties,entity:l});p.push(i.error)}return p}function tke(l){const p=[];if(l.abstract){if(l.methods.length){const i=It({id:l.id+"--"+be.AbstractEntityWithNonAbstractMethods,message:`Entity "${l.name}" with id "${l.id}" is marked as abstract but has non-abstract methods`,severity:Te.Error,code:be.AbstractEntityWithNonAbstractMethods,entity:l});p.push(i.error)}if(l.properties.some(i=>!i.abstract)){const i=It({id:l.id+"--"+be.AbstractEntityWithNonAbstractProperties,message:`Entity "${l.name}" with id "${l.id}" is marked as abstract but has non-abstract properties`,severity:Te.Error,code:be.AbstractEntityWithNonAbstractProperties,entity:l});p.push(i.error),l.properties.forEach(r=>{if(!r.abstract){const a=It({id:l.id+"--"+be.StaticEntityWithNonStaticProperties+"--"+r.id,message:`Property "${r.name}" with id "${r.id}" of entity "${l.name}" with id "${l.id}" is not marked as abstract but the entity is marked as abstract`,severity:Te.Error,code:be.StaticEntityWithNonStaticProperties,entity:l});p.push(a.error)}})}}else{if(l.abstractMethods.length){const i=It({id:l.id+"--"+be.AbstractPropertyInNonAbstractEntity,message:`Entity "${l.name}" with id "${l.id}" is not marked as abstract but has abstract methods`,severity:Te.Error,code:be.AbstractPropertyInNonAbstractEntity,entity:l});p.push(i.error)}l.properties.some(i=>i.abstract)&&l.properties.forEach(i=>{if(i.abstract){const r=It({id:l.id+"--"+be.AbstractPropertyInNonAbstractEntity+"--"+i.id,message:`Property "${i.name}" with id "${i.id}" of entity "${l.name}" with id "${l.id}" is marked as abstract but the entity is not marked as abstract`,severity:Te.Error,code:be.AbstractPropertyInNonAbstractEntity,entity:l,firstRelationship:i});p.push(r.error)}})}return l.static&&l.properties.some(i=>!i.static)&&l.properties.forEach(i=>{if(!i.static){const r=It({id:l.id+"--"+be.NonStaticPropertyInStaticEntity+"--"+i.id,message:`Property "${i.name}" with id "${i.id}" of entity "${l.name}" with id "${l.id}" is not marked as static but the entity is marked as static`,severity:Te.Error,code:be.NonStaticPropertyInStaticEntity,entity:l,firstRelationship:i});p.push(r.error)}}),p}function s_i(l,p){const i=[],r=Zn(p);if(!p.abstract){const e=new ki({id:l.id+"--"+p.id+"--"+be.ImplementingNonAbstractEntity,message:`Entity "${l.name}" with id "${l.id}" is implementing a non-abstract built-in entity "${p.name}" with id "${p.id}"`,severity:Te.Error,code:be.ImplementingNonAbstractEntity,entity:l,firstRelationship:p});i.push(e)}const a=l.implements.filter(e=>e.id!==p.id);if(l.abstract){const e=new ki({id:l.id+"--"+p.id+"--"+be.AbstractEntityImplements,message:`Entity "${l.name}" with id "${l.id}" is marked as abstract and cannot implement built-in entity "${p.name}" with id "${p.id}"`,severity:Te.Error,code:be.AbstractEntityImplements,entity:l,firstRelationship:p});i.push(e)}if(l.static&&!p.static){const e=new ki({id:l.id+"--"+p.id+"--"+be.StaticImplementingNonStaticEntity,message:`Entity "${l.name}" with id "${l.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:l,firstRelationship:p});i.push(e)}if(!l.static&&p.static){const e=new ki({id:l.id+"--"+p.id+"--"+be.NonStaticImplementingStaticEntity,message:`Entity "${l.name}" with id "${l.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:l,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 ki({id:l.id+"--"+h.id+"--"+e.id+"--"+be.ImplementsIncompatibleEntities,message:`Entity "${l.name}" with id "${l.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:l,firstRelationship:h,secondRelationship:e});i.push(m)}})}else{Zn(e).forEach(E=>{const b=r.filter(A=>A.id!==E.id);b.length&&b.forEach(A=>{if(A.id!==E.id){const _=new ki({id:l.id+"--"+A.id+"--"+E.id+"--"+be.ImplementsIncompatibleEntities,message:`Entity "${l.name}" with id "${l.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:l,firstRelationship:A,secondRelationship:E});i.push(_)}})});const h=jd(p.ownDeclaredProperties,e.ownDeclaredProperties,Ce.PropertyOverwritesOtherImplementedEntitysPropertyWithSameImplementation,Ce.PropertyOverwritesOtherImplementedEntitysPropertyWithSameName);i.push(...h.errors);const m=jd(p.abstractMethods,[...e.abstractMethods,...e.methods],Ce.MethodOverwritesOtherImplementedEntitysMethodWithSameImplementation,Ce.MethodOverwritesOtherImplementedEntitysMethodWithSameName);i.push(...m.errors)}}),C(l.extends?Zn(l.extends):[]).forEach(e=>{if(!r.find(f=>f.id===e.id)){const f=new ki({id:l.id+"--"+p.id+"--"+e.id+"--"+be.ExtendsIncompatibleEntities,message:`Entity "${l.name}" with id "${l.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:l,firstRelationship:p,secondRelationship:e});i.push(f)}}),i}function l_i(l,p,i=!1){var m,E;const r=[],a=Zn(p);if(!l.abstract&&p.abstract){const b=It({id:l.id+"--"+p.id+"--"+be.NonAbstractExtendingAbstractEntity,message:`Entity "${l.name}" with id "${l.id}" is not-abstract but is extending an abstract entity "${p.name}" with id "${p.id}"`,severity:Te.Error,code:be.NonAbstractExtendingAbstractEntity,entity:l,firstRelationship:p});r.push(b.error)}if(l.abstract&&!p.abstract){const b=It({id:l.id+"--"+p.id+"--"+be.AbstractExtendingNonAbstractEntity,message:`Entity "${l.name}" with id "${l.id}" is abstract but is extending an non-abstract entity "${p.name}" with id "${p.id}"`,severity:Te.Error,code:be.AbstractExtendingNonAbstractEntity,entity:l,firstRelationship:p});r.push(b.error)}if(!l.static&&p.static){const b=It({id:l.id+"--"+p.id+"--"+be.NonStaticExtendingStaticEntity,message:`Entity "${l.name}" with id "${l.id}" is not static but is extending a static entity "${p.name}" with id "${p.id}"`,severity:Te.Error,code:be.NonStaticExtendingStaticEntity,entity:l,firstRelationship:p});r.push(b.error)}if(l.static&&!p.static){const b=It({id:l.id+"--"+p.id+"--"+be.StaticExtendingNonStaticEntity,message:`Entity "${l.name}" with id "${l.id}" is static but is extending an non-static entity "${p.name}" with id "${p.id}"`,severity:Te.Error,code:be.StaticExtendingNonStaticEntity,entity:l,firstRelationship:p});r.push(b.error)}if(!cl(p)){const b=It({id:l.id+"--"+p.id+"--"+be.ExtendingNonInteractiveEntity,message:`Entity "${l.name}" with id "${l.id}" is extending an non-interactive entity "${p.name}" with id "${p.id}"`,severity:Te.Error,code:be.ExtendingNonInteractiveEntity,entity:l,firstRelationship:p});r.push(b.error)}if(l.extends&&((m=l.extends)==null?void 0:m.id)!==p.id)if(((E=l.extends)==null?void 0:E.type)===d.BuiltInBaseEntity){const b=a.filter(A=>{var _;return A.id!==((_=l.extends)==null?void 0:_.id)});b.length&&b.forEach(A=>{var _,N,P,j;if(A.id!==((_=l.extends)==null?void 0:_.id)){const M=It({id:l.id+"--"+A.id+"--"+((N=l.extends)==null?void 0:N.id)+"--"+be.ExtendsIncompatibleEntities,message:`Entity "${l.name}" with id "${l.id}" is extending built-in entity "${A.name}" with id "${A.id}" but also extends entity "${(P=l.extends)==null?void 0:P.name}" with id "${(j=l.extends)==null?void 0:j.id}" which is incompatible`,severity:Te.Error,code:be.ExtendsIncompatibleEntities,entity:l,firstRelationship:A,secondRelationship:l.extends});r.push(M.error)}})}else{Zn(l.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 ki({id:l.id+"--"+q.id+"--"+M.id+"--"+be.ImplementsIncompatibleEntities,message:`Entity "${l.name}" with id "${l.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:l,firstRelationship:q,secondRelationship:M});r.push(re)}})});const A=!!Zn(l.extends).find(M=>M.id===p.id);let _=[...l.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 N=[...l.extends.methods];A&&(N=N.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 P=jd(p.ownDeclaredProperties,_,Ce.PropertyOverwritesOtherExtendedEntitysPropertyWithSameImplementation,Ce.PropertyOverwritesOtherExtendedEntitysPropertyWithSameName);r.push(...P.errors);const j=jd(p.abstractMethods,N,Ce.MethodOverwritesOtherExtendedEntitysMethodWithSameImplementation,Ce.MethodOverwritesOtherExtendedEntitysMethodWithSameName);r.push(...j.errors)}i&&Y.Logger.log("self.implements.length",l.implements.length),l.implements.length&&l.implements.forEach(b=>{if(b.type===d.BuiltInBaseEntity){const A=a.filter(_=>_.id!==b.id);A.length&&A.forEach(_=>{if(_.id!==b.id){const N=new ki({id:l.id+"--"+_.id+"--"+b.id+"--"+be.ImplementsIncompatibleEntities,message:`Entity "${l.name}" with id "${l.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:l,firstRelationship:_,secondRelationship:b});r.push(N)}})}else{Zn(b).forEach(P=>{const j=a.filter(M=>M.id!==P.id);j.length&&j.forEach(M=>{if(M.id!==P.id){const G=new ki({id:l.id+"--"+M.id+"--"+P.id+"--"+be.ImplementsIncompatibleEntities,message:`Entity "${l.name}" with id "${l.id}" is implementing built-in entity "${M.name}" with id "${M.id}" but also implements entity "${P.name}" with id "${P.id}" which is incompatible`,severity:Te.Error,code:be.ImplementsIncompatibleEntities,entity:l,firstRelationship:M,secondRelationship:P});r.push(G)}})});const _=jd(p.ownDeclaredProperties,b.ownDeclaredProperties,Ce.PropertyOverwritesOtherImplementedEntitysPropertyWithSameImplementation,Ce.PropertyOverwritesOtherImplementedEntitysPropertyWithSameName);r.push(..._.errors);const N=jd(p.abstractMethods,[...b.abstractMethods,...b.methods],Ce.MethodOverwritesOtherImplementedEntitysMethodWithSameImplementation,Ce.MethodOverwritesOtherImplementedEntitysMethodWithSameName);r.push(...N.errors)}});const e=jd(l.ownDeclaredProperties,p.ownDeclaredProperties,Ce.PropertyOverwritesOtherSiblingWithSameImplementation,Ce.PropertyOverwritesOtherSiblingWithSameName);r.push(...e.errors);const f=jd(p.methods,p.abstractMethods,Ce.MethodOverwritesOtherSiblingWithSameImplementation,Ce.MethodOverwritesOtherSiblingWithSameName);return r.push(...f.errors),C(l.extends?Zn(l.extends):[]).forEach(b=>{if(!a.find(A=>A.id===b.id)){const A=new ki({id:l.id+"--"+p.id+"--"+b.id+"--"+be.ImplementsIncompatibleEntities,message:`Entity "${l.name}" with id "${l.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:l,firstRelationship:p,secondRelationship:b});r.push(A)}}),r}function o_i(l){const p=[];if(l.implements.forEach(i=>{if(!i.static){const r=new ki({id:l.id+"--"+i.id+"--"+be.StaticImplementingNonStaticEntity,message:`Entity "${l.name}" with id "${l.id}" is static but implements entity "${i.name}" with id "${i.id}" which is non-static`,severity:Te.Error,code:be.StaticImplementingNonStaticEntity,entity:l,firstRelationship:i});p.push(r)}}),l.extends&&!l.extends.static){const i=new ki({id:l.id+"--"+l.extends.id+"--"+be.StaticExtendingNonStaticEntity,message:`Entity "${l.name}" with id "${l.id}" is static but extends entity "${l.extends.name}" with id "${l.extends.id}" which is non-static`,severity:Te.Error,code:be.StaticExtendingNonStaticEntity,entity:l,firstRelationship:l.extends});p.push(i)}return p}function d_i(l){const p=[];if(l.implements.length){const i=new ki({id:l.id+"--"+be.AbstractEntityImplements,message:`Entity "${l.name}" with id "${l.id}" cannot be marked as abstract because it implements other entities`,severity:Te.Error,code:be.AbstractEntityImplements,entity:l});p.push(i)}if(l.extends&&!l.extends.abstract){const i=new ki({id:l.id+"--"+l.extends.id+"--"+be.AbstractExtendingNonAbstractEntity,message:`Entity "${l.name}" with id "${l.id}" is abstract but extends entity "${l.extends.name}" with id "${l.extends.id}" which is non-abstract`,severity:Te.Error,code:be.AbstractExtendingNonAbstractEntity,entity:l,firstRelationship:l.extends});p.push(i)}return p}function u_i(l){const p=[];if(l.extends&&l.extends.static){const i=new ki({id:l.id+"--"+l.extends.id+"--"+be.NonStaticExtendingStaticEntity,message:`Entity "${l.name}" with id "${l.id}" is non-static but extends entity "${l.extends.name}" with id "${l.extends.id}" which is static`,severity:Te.Error,code:be.NonStaticExtendingStaticEntity,entity:l,firstRelationship:l.extends});p.push(i)}return p}function p_i(l){const p=[];if(l.extends&&l.extends.abstract){const i=new ki({id:l.id+"--"+l.extends.id+"--"+be.NonAbstractExtendingAbstractEntity,message:`Entity "${l.name}" with id "${l.id}" is non-abstract but extends entity "${l.extends.name}" with id "${l.extends.id}" which is abstract`,severity:Te.Error,code:be.NonAbstractExtendingAbstractEntity,entity:l,firstRelationship:l.extends});p.push(i)}return p}function nL(l,p){const r=[...l.project.entities].filter(a=>a.id!==l.id);return jE(l,[Qi,sd],r,p)}const c_i=Object.freeze(Object.defineProperty({__proto__:null,getBaseMethodsNotImplemented:Jje,getBasePropertiesNotImplemented:Yje,validate:zje,validateAsync:Wje,validateCanBecomeAbstract:d_i,validateCanBecomeNonAbstract:p_i,validateCanBecomeNonStatic:u_i,validateCanBecomeStatic:o_i,validateCanExtendEntity:l_i,validateCanImplementEntity:s_i,validateDefinitionEntityName:nL},Symbol.toStringTag,{value:"Module"}));function f_i(l,p){const i=[],r=[];if(l.parent)if(l.id===l.parent)r.push(new De({id:`${l.id}--${l.parent}--${he.SelfReference}`,code:he.SelfReference,severity:Te.Error,message:`Entity of type "${l.type}" with id "${l.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(l.parent);a?[d.Project,d.DataType].includes(a.type)||r.push(new De({id:`${l.id}--${l.parent}--${he.InvalidParentReference}`,code:he.InvalidParentReference,severity:Te.Error,message:`Entity of type "${l.type}" with id "${l.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:`${l.id}--${l.parent}--${he.ReferencedEntityNotFound}`,code:he.ReferencedEntityNotFound,severity:Te.Error,message:`Entity of type "${l.type}" with id "${l.id}", is referencing an entity with id "${l.parent}" at 'parent' that isn't yet found in the project. Perhaps it should be created first. Or perhaps the ID is incorrect.`}))}return l.implements&&Array.isArray(l.implements)?l.implements.forEach(a=>{if(l.id===a){r.push(new De({id:`${l.id}--${a}--${he.SelfReference}`,code:he.SelfReference,severity:Te.Error,message:`Entity of type "${l.type}" with id "${l.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:`${l.id}--${a}--${he.InvalidImplementsReference}`,code:he.InvalidImplementsReference,severity:Te.Error,message:`Entity of type "${l.type}" with id "${l.id}", has an 'implements' reference that isn't pointing to an abstract entity.`})):r.push(new De({id:`${l.id}--${a}--${he.InvalidImplementsReference}`,code:he.InvalidImplementsReference,severity:Te.Error,message:`Entity of type "${l.type}" with id "${l.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:`${l.id}--${a}--${he.ReferencedEntityNotFound}`,code:he.ReferencedEntityNotFound,severity:Te.Error,message:`Entity of type "${l.type}" with id "${l.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:`${l.id}--${Ce.InvalidObjectStructure}`,code:Ce.InvalidObjectStructure,severity:Te.Error,message:`Entity of type "${l.type}" with id "${l.id}", has an 'implements' property that isn't an array.`})),l.extends&&Array.isArray(l.extends)&&l.extends.forEach(a=>{const c=p.get(a);c?[d.DefinitionEntity,d.BuiltInBaseEntity].includes(c.type)?c.abstract&&r.push(new De({id:`${l.id}--${a}--${he.InvalidExtendsReference}`,code:he.InvalidExtendsReference,severity:Te.Error,message:`Entity of type "${l.type}" with id "${l.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:`${l.id}--${a}--${he.InvalidExtendsReference}`,code:he.InvalidExtendsReference,severity:Te.Error,message:`Entity of type "${l.type}" with id "${l.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:`${l.id}--${a}--${he.ReferencedEntityNotFound}`,code:he.ReferencedEntityNotFound,severity:Te.Error,message:`Entity of type "${l.type}" with id "${l.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 jI=(l=>(l.Extends="extends",l.Implements="implements",l))(jI||{});const _i=class _i extends nn{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=te(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=Ae(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=f_i(a,r),h=fx(a,r),m=Wr(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
|
${rp({describe_entity:A.entity.id})}
|
|
538
538
|
Alternatively you can update the parent data-type entity with 'update' action to remove the existing value of the field.`}))}return{errors:e,explanations:c,modifiedData:a}}get interactive(){return this.implements.length?this.implements.every(i=>i.interactive):!0}get allMethods(){return C([...this.ownDeclaredMethods,...this.allBaseMethodsFromOriginalParents])}get allProperties(){return C([...this.ownDeclaredProperties,...this.allBasePropertiesFromOriginalParents])}get allBaseMethodsFromOriginalParents(){var a;const i=((a=this.extends)==null?void 0:a.type)===d.DefinitionEntity?this.extends.allMethods:[],r=[...i].filter(c=>!i.some(e=>{var f,h;return e.id!==c.id&&(((f=e.implements)==null?void 0:f.id)===c.id||((h=e.extends)==null?void 0:h.id)===c.id)}));return C([...r,...this.implements.flatMap(c=>{const e=c.type===d.DefinitionEntity?[...c.allMethods]:[];return[...e].filter(h=>!e.some(m=>{var E,b;return m.id!==h.id&&(((E=m.implements)==null?void 0:E.id)===h.id||((b=m.extends)==null?void 0:b.id)===h.id)}))})])}get allBasePropertiesFromOriginalParents(){var c;const i=((c=this.extends)==null?void 0:c.allProperties)||[],r=[...i].filter(e=>!i.some(f=>{var h;return f.id!==e.id&&(!!f.implements.find(m=>m.id===e.id)||((h=f.extends)==null?void 0:h.id)===e.id)}));return C([...r,...this.implements.flatMap(e=>{const f=[...e.allProperties];return[...f].filter(m=>!f.some(E=>{var b;return E.id!==m.id&&(!!E.implements.find(A=>A.id===m.id)||((b=E.extends)==null?void 0:b.id)===m.id)}))})])}get allBasePropertiesFromExtendedAndImplementedEntities(){var c,e;const i=[...((c=this.extends)==null?void 0:c.ownDeclaredProperties)||[],...((e=this.extends)==null?void 0:e.allBasePropertiesFromExtendedAndImplementedEntities)||[]].filter(f=>!f.abstract),r=[...i].filter(f=>!i.some(h=>{var m;return h.id!==f.id&&(!!h.implements.find(E=>E.id===f.id)||((m=h.extends)==null?void 0:m.id)===f.id)})),a=this.implements.reduce((f,h)=>{const m=h.implementedPropertiesFromOriginalParents,E=[...h.ownDeclaredProperties].filter(_=>!_.abstract),b=[...m,...E,...f];return[...b].filter(_=>!!!b.find(P=>{var j;return!!P.implements.find(M=>M.id===_.id)||((j=P.extends)==null?void 0:j.id)===_.id}))},[]);return C([...r,...a])}get allBaseMethodsFromExtendedAndImplementedEntities(){return C([...(this.extends?[this.extends]:[]).reduce((i,r)=>r.type!==d.DefinitionEntity?[]:[...[...r.ownDeclaredMethods,...r.allBaseMethodsFromExtendedAndImplementedEntities].filter(c=>c.type!==d.ActionDescriptor),...i],[]),...this.implements.reduce((i,r)=>r.type!==d.DefinitionEntity?r.abstractMethods:[...[...r.ownDeclaredMethods,...r.allBaseMethodsFromExtendedAndImplementedEntities].filter(c=>c.type!==d.ActionDescriptor),...i],[])])}get extendedPropertiesFromOriginalParents(){var a,c;const i=[...((a=this.extends)==null?void 0:a.ownDeclaredProperties)||[],...((c=this.extends)==null?void 0:c.extendedPropertiesFromOriginalParents)||[]].filter(e=>!e.abstract),r=[...i].filter(e=>!i.some(f=>{var h;return f.id!==e.id&&(!!f.implements.find(m=>m.id===e.id)||((h=f.extends)==null?void 0:h.id)===e.id)}));return C(r)}get implementedPropertiesFromOriginalParents(){return C([...(this.extends?[this.extends]:[]).reduce((i,r)=>{const a=r.implementedPropertiesFromOriginalParents,c=[...r.ownDeclaredProperties].filter(h=>!!h.abstract),e=[...a,...c,...i];return[...e].filter(h=>!!!e.find(E=>{var b;return((b=E.extends)==null?void 0:b.id)===h.id||!!E.implements.find(A=>A.id===h.id)}))},[]),...this.implements.reduce((i,r)=>{const a=r.implementedPropertiesFromOriginalParents,c=[...r.ownDeclaredProperties].filter(h=>!!h.abstract),e=[...a,...c,...i];return[...e].filter(h=>!!!e.find(E=>{var b;return!!E.implements.find(A=>A.id===h.id)||((b=E.extends)==null?void 0:b.id)===h.id}))},[])].filter(i=>!!i.abstract))}get extendedMethodsFromOriginalParents(){return C((this.extends?[this.extends]:[]).reduce((i,r)=>{if(r.type!==d.DefinitionEntity)return[];const a=[...r.ownDeclaredMethods,...r.extendedMethodsFromOriginalParents].filter(c=>c.type!==d.ActionDescriptor);return[...i,...a]},[]))}get implementedMethodsFromOriginalParents(){return C([...(this.extends?[this.extends]:[]).reduce((i,r)=>{const a=r.type===d.DefinitionEntity?r.methods:[],c=[...r.abstractMethods].filter(e=>!a.find(f=>f.name===e.name));return[...a,...c,...i]},[]),...this.implements.reduce((i,r)=>[...r.abstractMethods,...i],[])].filter(i=>i.type===d.ActionDescriptor))}get extendedProperties(){return this.properties.filter(i=>i.isExtendedProperty)}get ownDeclaredProperties(){return this.properties.filter(r=>!r.isExtendedProperty)}get extendedMethods(){return this.methods.filter(i=>i.isExtendedMethod)}get ownDeclaredMethods(){return this.methods.filter(i=>!i.isExtendedMethod)}validateGeneratedUpdate(i){const r=[],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. The 'parent' on an '${this.type}', must be the root project as it is a globally declared entity.`})),{errors:r,explanations:a,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==="implements"&&(this.removeImplementation(i,a),c.push(this)),r==="extends"&&(this.setExtension(null,a),c.push(this)),{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==="implements"&&(this.addImplementation(i,a),c.push(this)),r==="extends"&&(this.setExtension(i,a),c.push(this)),{updated:C(c),added:C(e),removed:C(f),affected:C(h),self:this}}unsubscribeFromDependencies(){return this.implements.forEach(i=>{oa.includes(i.type)||i.unsubscribeDependents([{entity:this,field:"implements"}])}),this.extends&&(oa.includes(this.extends.type)||this.extends.unsubscribeDependents([{entity:this,field:"extends"}])),this}subscribeToDependencies(){return this.implements.forEach(i=>{oa.includes(i.type)||i.subscribeDependents([{entity:this,field:"implements"}])}),this.extends&&(oa.includes(this.extends.type)||this.extends.subscribeDependents([{entity:this,field:"extends"}])),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 _i(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 _i(this,this.project);return this.apply(i)}apply(i){const r=this.toMeta();return i.metaSync(r,null),i.properties=[...this.properties],i.methods=[...this.methods],i.abstractMethods=[...this.abstractMethods],i.extends=this.extends,i.implements=[...this.implements],i.allPropertiesImplement=this.allPropertiesImplement,i.additionalPropertiesDataType=this.additionalPropertiesDataType,i.parent=this.parent,i}recursiveCaptureUpstreamVersions(i){const r=[],a=[],c=[],e=[];if(this.parent){this.parent.increaseVersion(i);const f=this.parent.recursiveCaptureUpstreamVersions(i);r.push(this.parent,...f.updated),a.push(...f.added),c.push(...f.removed)}return{updated:C(r),added:C(a),removed:C(c),affected:C(e),self:this}}async restoreVersion(i,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[_,N]of A.knownVersions)E.set(_,N);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 _i(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.properties=[...h.properties],this.methods=[...h.methods],this.abstractMethods=[...h.abstractMethods],this.extends=h.extends,this.implements=[...h.implements],this.allPropertiesImplement=h.allPropertiesImplement,this.additionalPropertiesDataType=h.additionalPropertiesDataType,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 f=te(i.parent),h=this.project.get(f),m=this.parent;if(m&&m.id!==(h==null?void 0:h.id)&&this.removeFromParent(r),h)this.setParent(h,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 '${f}' 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.extends){const f=te(i.extends),h=this.project.get(f);h&&this.setExtension(h,r)}else this.setExtension(null,r);if(i.implements.forEach(f=>{const h=te(f),m=this.project.get(h);if(m)this.addImplementation(m,r);else throw new Error(`${dr(this.type)} with id '${this.id}' has a 'implements' reference "${h}" which is missing in the project`)}),this.implements.filter(f=>{const h=te(f);return!i.implements.find(m=>te(m)===h)}).forEach(f=>{this.removeImplementation(f,r)}),i.methods.forEach(f=>{const h=te(f),m=this.project.get(h);m&&this.addMethod(m,r)}),this.methods.filter(f=>{const h=te(f);return!i.methods.find(m=>te(m)===h)}).forEach(f=>{this.removeMethod(f,r)}),i.properties.forEach(f=>{const h=te(f),m=this.project.get(h);m&&this.addProperty(m,r)}),this.properties.filter(f=>{const h=te(f);return!i.properties.find(m=>te(m)===h)}).forEach(f=>{this.removeProperty(f,r)}),i.allPropertiesImplement){const f=te(i.allPropertiesImplement),h=this.project.get(f);h&&this.setAllPropertiesImplement(h,r)}else this.setAllPropertiesImplement(null,r);if(i.additionalPropertiesDataType){const f=te(i.additionalPropertiesDataType),h=this.project.get(f);h&&this.setAdditionalPropertiesDataType(h,r)}else this.setAdditionalPropertiesDataType(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=te(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(i.extends){const c=te(i.extends),e=this.project.get(c);if(e)this.setExtension(e,r);else throw new Error(`${dr(this.type)} with id '${this.id}' has an 'extends' reference "${c}" which is missing in the project`)}else i.extends===null&&this.setExtension(null,r);return(a=i.implements)==null||a.forEach(c=>{const e=te(c),f=this.project.get(e);if(f)this.addImplementation(f,r);else throw new Error(`${dr(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=te(e);return!(i.implements||[]).find(h=>te(h)===f)}).forEach(e=>{this.removeImplementation(e,r)}),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=te(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.extends){const e=te(this.initialData.extends),f=this.project.get(e);f&&(this.setExtension(f,null),f.type!==d.BuiltInBaseEntity&&i.push(f))}return this.initialData.implements.forEach(e=>{const f=te(e),h=this.project.get(f);if(h)this.addImplementation(h,null),h.type!==d.BuiltInBaseEntity&&i.push(h);else throw new Error(`${dr(this.type)} with id '${this.id}' has a 'implements' reference "${f}" which is missing in the project`)}),{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))){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=[];this.initialized=!0;const{updated:f,added:h,removed:m,affected:E}=this.syncImplementationProperties(i);r.push(...f),a.push(...h),c.push(...m),e.push(...E);const{updated:b,added:A,removed:_,affected:N}=this.addExtendedProperties(i);r.push(...b),a.push(...A),c.push(..._),e.push(...N);const{updated:P,added:j,removed:M}=this.removeUnrecognizedProperties(i);r.push(...P),a.push(...j),c.push(...M);const{updated:G,added:q,removed:re,affected:ee}=this.syncImplementationMethods(i);r.push(...G),a.push(...q),c.push(...re),e.push(...ee);const{updated:de,added:ie,removed:se,affected:ue}=this.addExtendedMethods(i);r.push(...de),a.push(...ie),c.push(...se),e.push(...ue);const{updated:z,added:X,removed:ce}=this.removeUnrecognizedMethods(i);r.push(...z),a.push(...X),c.push(...ce),this.addSuggestions(),this.properties.sort((me,ve)=>me.index-ve.index);const oe=this.project.getDefinitionEntities(new Set([this.id]));if(oe.some(me=>me.id!==this.id&&me.name.toLowerCase()===this.name.toLowerCase())){const me=hh(this.name,oe);this.metaSync({name:me},i)}return 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=[];if(this.parent.type===d.DataType){const f=this.parent;f.entity=this,r.push(f)}else this.project.addDefinitionEntity(this);return 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}setExtension(i,r=this.project.addChangeSet(new S(this.project,x.sessionAuthor,B().toISOString(),this,!0,w.SetExtension))){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.SetExtension,this.id),this):(Y.Logger.warn(`[setExtension] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),r==null||r.attemptAutoclose(w.SetExtension,this.id),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),this.subscribeToDependencies(),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)}removeProperty(i,r=this.project.addChangeSet(new S(this.project,x.sessionAuthor,B().toISOString(),this,!0,w.RemoveProperty))){return this.checkCanEdit(this,r)?(this.properties.includes(i)&&(this.properties=this.properties.filter(a=>a.id!==i.id),r==null||r.add(this,W.Updated)),r==null||r.attemptAutoclose(w.RemoveProperty,this.id),this):(Y.Logger.warn(`[removeProperty] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),r==null||r.attemptAutoclose(w.RemoveProperty,this.id),this)}addMethod(i,r=this.project.addChangeSet(new S(this.project,x.sessionAuthor,B().toISOString(),this,!0,w.AddMethod))){return this.checkCanEdit(this,r)?(this.methods.includes(i)||(this.methods.push(i),this.suggestedMethods=this.suggestedMethods.filter(a=>a.name!==i.name),r==null||r.add(this,W.Updated)),r==null||r.attemptAutoclose(w.AddMethod,this.id),this):(Y.Logger.warn(`[addMethod] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),r==null||r.attemptAutoclose(w.AddMethod,this.id),this)}removeMethod(i,r=this.project.addChangeSet(new S(this.project,x.sessionAuthor,B().toISOString(),this,!0,w.RemoveMethod))){return this.checkCanEdit(this,r)?(this.methods.includes(i)&&(this.methods=this.methods.filter(a=>a.id!==i.id),r==null||r.add(this,W.Updated)),r==null||r.attemptAutoclose(w.RemoveMethod,this.id),this):(Y.Logger.warn(`[removeMethod] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),r==null||r.attemptAutoclose(w.RemoveMethod,this.id),this)}addProperty(i,r=this.project.addChangeSet(new S(this.project,x.sessionAuthor,B().toISOString(),this,!0,w.AddProperty))){return this.checkCanEdit(this,r)?(this.properties.includes(i)||(this.properties.push(i),this.suggestedProperties=this.suggestedProperties.filter(a=>a.name!==i.name),r==null||r.add(this,W.Updated)),r==null||r.attemptAutoclose(w.AddProperty,this.id),this):(Y.Logger.warn(`[addProperty] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),r==null||r.attemptAutoclose(w.AddProperty,this.id),this)}addSuggestedProperty(i){return this.suggestedProperties.includes(i)||this.suggestedProperties.push(i),this}addSuggestedMethod(i){return this.suggestedMethods.includes(i)||this.suggestedMethods.push(i),this}removeSuggestedProperty(i){return this.suggestedProperties=this.suggestedProperties.filter(r=>r.id!==i.id),this}removeSuggestedMethod(i){return this.suggestedMethods=this.suggestedMethods.filter(r=>r.id!==i.id),this}addAbstractMethod(i,r=this.project.addChangeSet(new S(this.project,x.sessionAuthor,B().toISOString(),this,!0,w.AddAbstractMethod))){return this.checkCanEdit(this,r)?(this.abstractMethods.includes(i)||(this.abstractMethods.push(i),r==null||r.add(this,W.Updated)),r==null||r.attemptAutoclose(w.AddAbstractMethod,this.id),this):(Y.Logger.warn(`[addAbstractMethod] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),r==null||r.attemptAutoclose(w.AddAbstractMethod,this.id),this)}removeAbstractMethod(i,r=this.project.addChangeSet(new S(this.project,x.sessionAuthor,B().toISOString(),this,!0,w.RemoveAbstractMethod))){return this.checkCanEdit(this,r)?(this.abstractMethods.includes(i)&&(this.abstractMethods=this.abstractMethods.filter(a=>a.id!==i.id),r==null||r.add(this,W.Updated)),r==null||r.attemptAutoclose(w.RemoveAbstractMethod,this.id),this):(Y.Logger.warn(`[removeAbstractMethod] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),r==null||r.attemptAutoclose(w.RemoveAbstractMethod,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.properties=this.initialData.properties.map(r=>{const a=Ae(r,this.project);return a.setParent(this,null),a.initChildren(i),a}),this.methods=this.initialData.methods.map(r=>{const a=Ae(r,this.project);return a.setParent(this,null),a.initChildren(i),a}),this.abstractMethods=this.initialData.abstractMethods.map(r=>{const a=Ae(r,this.project);return a.setParent(this,null),a.initChildren(i),a}),this.initialData.extends&&(this.extends=Ae(this.initialData.extends,this.project)),this.implements=this.initialData.implements.map(r=>Ae(r,this.project)),this.initialData.allPropertiesImplement){const r=Ae(this.initialData.allPropertiesImplement,this.project);r.setParent(this,null),r.initChildren(null),this.setAllPropertiesImplement(r,i)}if(this.initialData.additionalPropertiesDataType){const r=Ae(this.initialData.additionalPropertiesDataType,this.project);r.setParent(this,null),r.initChildren(null),this.setAdditionalPropertiesDataType(r,i)}return this.subscribeToDependencies(),this.afterAllChildrenInitialized(i),i==null||i.attemptAutoclose("init-children",this.id),this}removeUnrecognizedProperties(i=this.project.addChangeSet(new S(this.project,x.sessionAuthor,B().toISOString(),this,!0,"remove-unrecognized-properties"))){const r=[],a=[],c=[],e=[];let f=[...this.properties];f=f.filter(b=>b.parent.id===this.id),f=f.filter(b=>!b.isExtendedProperty);const h=this.implementedPropertiesFromOriginalParents,m=this.getAllPropertiesImplements();return f.filter(b=>this.interactive&&!b.implements.length?!1:!b.implements.find(_=>!!h.find(N=>N.id===_.id)||!!m.find(N=>N.id===_.id))).forEach(b=>{const A=b.remove({ignoreUpstream:!1},i);c.push(...A.removed),r.push(...A.updated)}),i==null||i.attemptAutoclose("remove-unrecognized-properties",this.id),{updated:C(r),added:C(a),removed:C(c),affected:C(e),self:this}}removeUnrecognizedMethods(i=this.project.addChangeSet(new S(this.project,x.sessionAuthor,B().toISOString(),this,!0,"remove-unrecognized-methods"))){const r=[],a=[],c=[],e=[];let f=[...this.methods];f=f.filter(m=>m.parent.id===this.id),f=f.filter(m=>!m.isExtendedMethod);const h=this.implementedMethodsFromOriginalParents;return f=f.filter(m=>this.interactive&&!m.implements?!1:!h.find(E=>{var b;return E.id===((b=m.implements)==null?void 0:b.id)})),f.forEach(m=>{const E=m.remove({ignoreUpstream:!1},i);c.push(...E.removed),r.push(...E.updated)}),i==null||i.attemptAutoclose("remove-unrecognized-methods",this.id),{updated:C(r),added:C(a),removed:C(c),affected:C(e),self:this}}syncImplementationMethods(i=this.project.addChangeSet(new S(this.project,x.sessionAuthor,B().toISOString(),this,!0,"sync-implementation-methods"))){const r=[],a=[],c=[],e=[],f=this.methods,h=this.implementedMethodsFromOriginalParents,m=[...this.allBaseMethodsFromExtendedAndImplementedEntities,...f];return h.filter(b=>!m.find(_=>{var N;return((N=_.implements)==null?void 0:N.id)===b.id})).forEach(b=>{if(this.methods.find(P=>{var j;return((j=P.implements)==null?void 0:j.id)===b.id}))return;const _=this.methods.find(P=>{var re,ee;if(P.name===b.name&&!P.implements)return!0;const j=ai(this,Ie.CRON_JOB),M=ai(this,Ie.HTTP_ENDPOINT),G=((re=P.implements)==null?void 0:re.id)===ne["built-in-base-entity"].BUILT_IN_HTTP_ENDPOINT_ENTITY.methods.handler.id,q=((ee=P.implements)==null?void 0:ee.id)===ne["built-in-base-entity"].BUILT_IN_CRON_JOB_ENTITY.methods.handler.id;return!!(j&&!q&&!M&&G||M&&!G&&!j&&q)});if(_&&_.type===d.FunctionDeclaration){_.setImplements(b,i),_.metaSync({name:b.name},i),i==null||i.add(_,W.Updated),i==null||i.add(this,W.Updated);return}const N=b.implementAsFunctionDeclaration(i,this);a.push(N),i==null||i.add(N,W.Added),this.addMethod(N,i)}),this.methods.sort((b,A)=>b.index-A.index).forEach(b=>{b.afterAllChildrenInitialized(i)}),i==null||i.attemptAutoclose("sync-implementation-methods",this.id),{updated:C(r),added:C(a),removed:C(c),affected:C(e),self:this}}syncImplementationProperties(i=this.project.addChangeSet(new S(this.project,x.sessionAuthor,B().toISOString(),this,!0,"sync-implementation-properties"))){const r=[],a=[],c=[],e=[],f=this.properties,h=this.implementedPropertiesFromOriginalParents.filter(E=>!this.allBasePropertiesFromExtendedAndImplementedEntities.find(A=>!!A.implements.find(_=>_.id===E.id))),m=[...this.allBasePropertiesFromExtendedAndImplementedEntities,...f];return h.forEach(E=>{const b=m.find(P=>!!P.implements.find(j=>j.id===E.id));if(b){const{updated:P,added:j,removed:M,affected:G}=b.syncWithImplementation(i);r.push(...P),a.push(...j),c.push(...M),e.push(...G);return}if(this.properties.find(P=>!!P.implements.find(j=>j.id===E.id)))return;const _=this.properties.find(P=>P.name===E.name&&!!P.abstract&&!P.implements);if(_){_.addImplementation(E,i),_.metaSync({abstract:!1},i),_.afterAllChildrenInitialized(i);return}const N=E.implement(this,i,x.UUID.uuid());a.push(N),i==null||i.add(N,W.Added)}),this.properties.find(E=>{var b;return E.id===((b=this.allPropertiesImplement)==null?void 0:b.id)})&&this.removeAllPropertiesImplement(i),i==null||i.attemptAutoclose("sync-implementation-properties",this.id),{updated:C(r),added:C(a),removed:C(c),affected:C(e),self:this}}addExtendedMethods(i=this.project.addChangeSet(new S(this.project,x.sessionAuthor,B().toISOString(),this,!0,"add-extended-methods"))){const r=[],a=[],c=[],e=[],f=this.methods,m=this.extendedMethodsFromOriginalParents.filter(b=>b.type===d.FunctionDeclaration),E=new Set(f.filter(b=>{var A;return!!((A=b.extends)!=null&&A.id)}).map(b=>b.extends.id));return m.forEach(b=>{if(E.has(b.id))return;E.add(b.id);const A=b.clone(i,this,x.UUID.uuid());A.setExtends(b,i),A.initChildren(i),a.push(A),i==null||i.add(A,W.Added),this.addMethod(A,i)}),i==null||i.attemptAutoclose("add-extended-methods",this.id),{updated:C(r),added:C(a),removed:C(c),affected:C(e),self:this}}addExtendedProperties(i=this.project.addChangeSet(new S(this.project,x.sessionAuthor,B().toISOString(),this,!0,"add-extended-properties"))){const r=[],a=[],c=[],e=[],f=this.properties,h=this.extendedPropertiesFromOriginalParents,m=h.filter(b=>h.find(_=>!!_.implements.find(N=>N.id===b.id))?!1:!b.abstract),E=new Set(f.filter(b=>{var A;return!!((A=b.extends)!=null&&A.id)}).map(b=>b.extends.id));return m.forEach(b=>{if(E.has(b.id))return;E.add(b.id);const A=b.clone(i,this,x.UUID.uuid());A.setExtends(b,i),A.initChildren(i),a.push(A),i==null||i.add(A,W.Added),this.addProperty(A,i)}),[...this.properties].forEach(b=>{if(b.extends)return;if(m.find(_=>_.name===b.name&&_.implements.every(N=>!!b.implements.find(P=>P.id===N.id)))){const _=b.remove({ignoreUpstream:!1},i);c.push(..._.removed),r.push(..._.updated)}}),this.properties.forEach(b=>{const A=b.afterAllChildrenInitialized(i);r.push(...A.updated),e.push(...A.affected),a.push(...A.added),c.push(...A.removed)}),i==null||i.attemptAutoclose("add-extended-properties",this.id),{updated:C(r),added:C(a),removed:C(c),affected:C(e),self:this}}addSuggestions(){return this.implements.forEach(i=>{Yje(this,i).forEach(c=>{const e=c.toJSON();e.id=`_suggestion--parent--${this.id}--${c.id}`;const f=Ae(e,this.project);f.suggestion=!0,f.setParent(this,null),f.initChildren(null),this.addSuggestedProperty(f)}),Jje(this,i).forEach(c=>{const e=`_suggestion--parent--${this.id}--${c.id}`,f=c.implementAsFunctionDeclaration(null,this,e),h=Ae(f,this.project);if(h.suggestion=!0,h.setParent(this,null),h.initChildren(null),this.methods=this.methods.filter(m=>m.id!==e),h.inputs.forEach(m=>{m.suggestion=!0}),h.returnStatements.length){const m=h.returnStatements[0];m.suggestion=!0,m.outputs.forEach(E=>{E.suggestion=!0})}this.addSuggestedMethod(h)})}),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.project.subscribedDefinitionEntities.add(this.id),this}unsubscribe(){return this.project.unsubscribeInstance(this),this.project.subscribedDefinitionEntities.delete(this.id),this}metaSync(i,r=this.project.addChangeSet(new S(this.project,x.sessionAuthor,B().toISOString(),this,!0,"meta-sync"))){const a=Yr(this,i,r),c=zr(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.x=a.x||e.x,this.y=a.y||e.y,this.static=a.static!==void 0?a.static:this.static,this.abstract=a.abstract!==void 0?a.abstract:this.abstract,this.additionalProperties=a.additionalProperties!==void 0?a.additionalProperties:e.additionalProperties,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 _i.repository.APILoad(this.id,...r),this}async APICreate(i=Ke,...r){return await _i.repository.APICreate(this.toShallowJSON(),...r),this}async APIUpdate(i=Ke,...r){return await _i.repository.APIUpdate(this.toShallowJSON(),...r),this}async APIDelete(i=Ke,...r){return await _i.repository.APIDelete(this.toShallowJSON(),...r),this}async APIClone(i=Ke,...r){return await _i.repository.APIClone(this.id,...r),this}async APILoadVersion(i=Ke,r,...a){return await _i.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=[];if(this.parent.type===d.Project)this.parent.removeDefinitionEntity(this);else if(this.parent.type===d.DataType&&this.parent.entity&&this.parent.entity.id===this.id){const f=this.parent.setEntity(null,i);r.push(f)}return 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.properties.forEach(m=>{const{updated:E,removed:b}=m.remove({ignoreUpstream:!0},r);a.push(...E),c.push(...b)}),this.methods.forEach(m=>{const{updated:E,removed:b}=m.remove({ignoreUpstream:!0},r);a.push(...E),c.push(...b)}),this.abstractMethods.forEach(m=>{const{updated:E,removed:b}=m.remove({ignoreUpstream:!0},r);a.push(...E),c.push(...b)}),this.suggestedProperties.forEach(m=>{const{updated:E,removed:b}=m.remove({ignoreUpstream:!0},r);a.push(...E),c.push(...b)}),this.suggestedMethods.forEach(m=>{const{updated:E,removed:b}=m.remove({ignoreUpstream:!0},r);a.push(...E),c.push(...b)}),!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=[];return i!=null&&i.hasAdded(this.id)?(i==null||i.attemptAutoclose(w.RestoreEntity,this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},i),Object.values(this.detachedDependents).forEach(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.properties.forEach(f=>{const{updated:h}=f.restore({},i);a.push(...h)}),this.methods.forEach(f=>{const{updated:h}=f.restore({},i);a.push(...h)}),this.abstractMethods.forEach(f=>{const{updated:h}=f.restore({},i);a.push(...h)}),this.suggestedProperties.forEach(f=>{const{updated:h}=f.restore({},i);a.push(...h)}),this.suggestedMethods.forEach(f=>{const{updated:h}=f.restore({},i);a.push(...h)}),i==null||i.attemptAutoclose(w.RestoreEntity,this.id),{added:C(r),updated:C(a),removed:C(c),affected:C(e),self:this})}toFlat(i=new Set){var a;return i.has(this.id)?[]:(i.add(this.id),[this,...((a=this.extends)==null?void 0:a.toFlat(i))||[],...this.implements.flatMap(c=>c.toFlat(i)),...this.properties.flatMap(c=>c.toFlat(i)),...this.methods.flatMap(c=>c.toFlat(i)),...this.abstractMethods.flatMap(c=>c.toFlat(i)),...this.parent.toFlat(i)])}toFlatIds(i=new Set){var a;return i.has(this.id)?[]:(i.add(this.id),[this.id,...((a=this.extends)==null?void 0:a.toFlatIds(i))||[],...this.implements.flatMap(c=>c.toFlatIds(i)),...this.properties.flatMap(c=>c.toFlatIds(i)),...this.methods.flatMap(c=>c.toFlatIds(i)),...this.abstractMethods.flatMap(c=>c.toFlatIds(i)),...this.parent.toFlatIds(i)])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,codeName:this.codeName,description:this.description,static:this.static,abstract:this.abstract,x:this.x,y:this.y,type:this.type,editable:this.editable,deletable:this.deletable,additionalProperties:this.additionalProperties,name:this.name}}toJSON(i=new Set){var r,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,x:this.x,y:this.y,static:this.static,abstract:this.abstract,additionalProperties:this.additionalProperties,allPropertiesImplement:((r=this.allPropertiesImplement)==null?void 0:r.toJSON(i))||null,additionalPropertiesDataType:((a=this.additionalPropertiesDataType)==null?void 0:a.toJSON(i))||null,properties:this.properties.map(e=>e.toJSON(i)),methods:this.methods.map(e=>e.toJSON(i)),abstractMethods:this.abstractMethods.map(e=>e.toJSON(i)),implements:this.implements.map(e=>e.toJSON(i)),extends:((c=this.extends)==null?void 0:c.toJSON(i))||null,parent:this.parent.toReference()})}toJSONClone(i=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||rn(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,x:this.x,y:this.y,static:this.static,abstract:this.abstract,additionalProperties:this.additionalProperties,allPropertiesImplement:((m=this.allPropertiesImplement)==null?void 0:m.toJSONClone(i))||null,additionalPropertiesDataType:((E=this.additionalPropertiesDataType)==null?void 0:E.toJSONClone(i))||null,properties:this.properties.map(N=>N.toJSONClone({...i,newId:null})),methods:this.methods.map(N=>N.toJSONClone({...i,newId:null})),abstractMethods:this.abstractMethods.map(N=>N.toJSONClone({...i,newId:null})),implements:this.implements.map(N=>N.type===d.BuiltInBaseEntity?N.toJSON(i.seenEntities):N.toJSONClone({...i,newId:null})),extends:((b=this.extends)==null?void 0:b.type)===d.BuiltInBaseEntity?(A=this.extends)==null?void 0:A.toJSON(i.seenEntities):(_=this.extends)==null?void 0:_.toJSONClone({...i,newId: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,x:this.x,y:this.y,static:this.static,abstract:this.abstract,additionalProperties:this.additionalProperties,allPropertiesImplement:((c=this.allPropertiesImplement)==null?void 0:c.toReference(i))||null,additionalPropertiesDataType:((e=this.additionalPropertiesDataType)==null?void 0:e.toReference(i))||null,properties:this.properties.map(h=>h.toReference(i)),methods:this.methods.map(h=>h.toReference(i)),abstractMethods:this.abstractMethods.map(h=>h.toReference(i)),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,e;return i.has(this.id)?[]:(i.add(this.id),[this.toShallowJSON(),...this.properties.flatMap(f=>f.toFlatJSON(i)),...this.methods.flatMap(f=>f.toFlatJSON(i)),...this.abstractMethods.flatMap(f=>f.toFlatJSON(i)),...this.implements.flatMap(f=>f.toFlatJSON(i)),...((a=this.extends)==null?void 0:a.toFlatJSON(i))||[],...this.parent.toFlatJSON(i),...((c=this.additionalPropertiesDataType)==null?void 0:c.toFlatJSON(i))||[],...((e=this.allPropertiesImplement)==null?void 0:e.toFlatJSON(i))||[]])}toGenerationTarget(i=at){var c,e,f;const r=this.parent.type===d.Project?void 0:(c=i.seenEntityMaps)!=null&&c.has(this.parent.id)?i.seenEntityMaps.get(this.parent.id):this.parent.id;let a=this.id;return(e=i.seenEntityMaps)!=null&&e.has(this.id)&&(a=i.seenEntityMaps.get(this.id)),{id:a,name:this.name,description:this.description,type:this.type,static:this.static,abstract:this.abstract,extends:(f=this.extends)==null?void 0:f.id,additionalProperties:this.additionalProperties,implements:this.implements.map(h=>h.id),parent:r}}toFlatGenerationTarget(i=new Set){var a,c,e;return i.has(this.id)?[]:(i.add(this.id),[this.toGenerationTarget(),...this.properties.flatMap(f=>f.toFlatGenerationTarget(i)),...this.methods.flatMap(f=>f.toFlatGenerationTarget(i)),...this.abstractMethods.flatMap(f=>f.toFlatGenerationTarget(i)),...this.implements.filter(f=>f.type===d.DefinitionEntity).flatMap(f=>f.toFlatGenerationTarget(i)),...((a=this.extends)==null?void 0:a.toFlatGenerationTarget(i))||[],...this.parent.toFlatGenerationTarget(i),...((c=this.additionalPropertiesDataType)==null?void 0:c.toFlatGenerationTarget(i))||[],...((e=this.allPropertiesImplement)==null?void 0:e.toFlatGenerationTarget(i))||[]])}clearErrors(){var i,r;return this.errors=[],this.properties.forEach(a=>a.clearErrors()),this.methods.forEach(a=>a.clearErrors()),this.abstractMethods.forEach(a=>a.clearErrors()),(i=this.additionalPropertiesDataType)==null||i.clearErrors(),(r=this.allPropertiesImplement)==null||r.clearErrors(),this}validate(){return this.errors=zje(this),{success:!0}}async validateAsync(i={}){const r=Y.YieldTracker.from(i);return this.errors=await Wje(this,{tracker:r}),{success:!0}}getErrors(){var r,a;return[...this.errors,...this.properties.flatMap(c=>c.getErrors()),...this.methods.flatMap(c=>c.getErrors()),...this.abstractMethods.flatMap(c=>c.getErrors()),...((r=this.additionalPropertiesDataType)==null?void 0:r.getErrors())||[],...((a=this.allPropertiesImplement)==null?void 0:a.getErrors())||[]]}async getErrorsAsync(i={}){const r=Y.YieldTracker.from(i),a=[...this.errors];await r.tick();for(const c of this.properties)a.push(...await c.getErrorsAsync({tracker:r}));for(const c of this.methods)a.push(...await c.getErrorsAsync({tracker:r}));for(const c of this.abstractMethods)a.push(...await c.getErrorsAsync({tracker:r}));return this.additionalPropertiesDataType&&a.push(...await this.additionalPropertiesDataType.getErrorsAsync({tracker:r})),this.allPropertiesImplement&&a.push(...await this.allPropertiesImplement.getErrorsAsync({tracker:r})),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 j,M,G;const e=Mr(r,this),f=this.toJSON(),h=a||x.UUID.uuid(),m=r||this.parent;f.properties=[],f.methods=[],f.abstractMethods=[];const E=h.split("-id"),b=E[E.length-1||0]||h;f.id=h,f.version=x.UUID.uuid(),f.createdAt=(i==null?void 0:i.timestamp)||B().toISOString(),f.author=(i==null?void 0:i.author)||"1",f.previousVersion=null,f.deleted=!1,f.editable=!0,f.deletable=!0,f.parent=m.toReference();const A=tr(f,e);A.hydrateAncestors(),A.setParent(m,i),c&&(A.subscribe(),A.addSelfToProject(i)),A.initChildren(i),i==null||i.add(A,W.Added);const _=(j=this.properties)==null?void 0:j.map(q=>this.project.diggestedBuiltInBaseEntitiesIds.has(q.id)?q:q.clone(i,A,x.UUID.uuid(),c));A.properties=_;const N=(M=this.methods)==null?void 0:M.map((q,re)=>this.project.diggestedBuiltInBaseEntitiesIds.has(q.id)?q:q.clone(i,A,b+"-method-"+re+"-id",c));A.methods=N;const P=(G=this.abstractMethods)==null?void 0:G.map((q,re)=>this.project.diggestedBuiltInBaseEntitiesIds.has(q.id)?q:q.clone(i,A,b+"-abstract-method-"+re+"-id",c));if(A.abstractMethods=P,this.additionalPropertiesDataType)if(this.project.diggestedBuiltInBaseEntitiesIds.has(this.additionalPropertiesDataType.id))A.setAdditionalPropertiesDataType(this.additionalPropertiesDataType,i);else{const q=this.additionalPropertiesDataType.clone(i,A,x.UUID.uuid(),c);A.setAdditionalPropertiesDataType(q,i)}if(this.allPropertiesImplement)if(this.project.diggestedBuiltInBaseEntitiesIds.has(this.allPropertiesImplement.id))A.setAllPropertiesImplement(this.allPropertiesImplement,i);else{const q=this.allPropertiesImplement.clone(i,A,x.UUID.uuid(),c);A.setAllPropertiesImplement(q,i)}return i||A.captureVersion(),i==null||i.attemptAutoclose(w.CloneEntity,this.id),A}getFunctionDeclaration(i){return this.methods.find(r=>r.id===i)}implement(i,r=this.project.addChangeSet(new S(this.project,x.sessionAuthor,B().toISOString(),this,!0,"implement-definition-entity")),a){const c=a1(this,i,r,a);return r==null||r.attemptAutoclose("implement-definition-entity",this.id),c}getAllPropertiesImplements(){var r;const i=[];return this.allPropertiesImplement&&i.push(this.allPropertiesImplement),i.push(...((r=this.extends)==null?void 0:r.getAllPropertiesImplements())||[],...this.implements.flatMap(a=>a.getAllPropertiesImplements())),i}getAllInteractiveMethods(){var e;const i=this.implements.filter(f=>f.type===d.DefinitionEntity||f.type===d.BuiltInBaseEntity&&f.interactive),r=((e=this.extends)==null?void 0:e.getAllInteractiveMethods())||[],a=i.flatMap(f=>f.getAllInteractiveMethods());return C([...this.methods,...r,...a])}inferFromInputs(i,r=this.project.addChangeSet(new S(this.project,x.sessionAuthor,B().toISOString(),this,!0,"infer-definition-entity-from-inputs"))){const a=[],c=[],e=[],f=[];if(this.parent.type!==d.DataType||!this.parent.inferred)return r==null||r.attemptAutoclose("infer-definition-entity-from-inputs",this.id),{added:[],updated:[],removed:[],affected:[],self:this};const h=[];i.forEach(b=>{h.find(_=>le(_,this.project)===le(b,this.project))||h.push(b)});const m=this.properties.filter(b=>!b.dataType);h.forEach(b=>{var G,q,re;const A=m.find(ee=>le(ee,this.project)===le(b,this.project));if(!A)return;const N=Tr(b.parent).getMasterInputWithValueWriterFromAllInstances(b),P=Sd(N,r),j=P==null?void 0:P.clone(r,A,x.UUID.uuid(),!0);j&&((G=A.dataType)==null||G.merge(j,r),j.id!==((q=A.dataType)==null?void 0:q.id)&&j.remove({ignoreUpstream:!1},r),A.dataType&&(A.dataType.metaSync({inferred:!0,like:!0},r),A.setDataType(A.dataType,r),r==null||r.add(A,W.Affected)));let M=null;if(b.declaration&&A.id!==((re=b.declaration)==null?void 0:re.id)&&(M=b.declaration),b.setDeclaration(A,r),r==null||r.add(b,W.Updated),M){const{updated:ee,removed:de}=M.remove({ignoreUpstream:!1},r);c.push(...ee),e.push(...de)}});const E=[];return h.forEach(b=>{if(!b.declaration){E.push(b);return}}),E.length===0?(r==null||r.attemptAutoclose("infer-definition-entity-from-inputs",this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(E.forEach(b=>{var re,ee,de,ie,se;const A=this.properties.find(ue=>le(ue,this.project)===le(b,this.project));if(A){if(b.setDeclaration(A,r),!A.getDataType(r)){const z=Tr(b.parent).getMasterInputWithValueWriterFromAllInstances(b),X=Sd(z),ce=X==null?void 0:X.clone(r,A,x.UUID.uuid(),!0);ce&&((re=A.dataType)==null||re.merge(ce,r),ce.id!==((ee=A.dataType)==null?void 0:ee.id)&&ce.remove({ignoreUpstream:!1},r),A.dataType&&(A.dataType.metaSync({inferred:!0,like:!0},r),A.setDataType(A.dataType,r),r==null||r.add(A,W.Affected)))}return}const _=le(b,this.project),N=b.codeName||pf(b,this.project)||Ps(Qi(_)),P=ps.new(r);P.parent=this.toReference(),P.index=b.index,P.name=_,P.codeName=N,P.description=b.description;const j=Ae(P,this.project);j.hydrateAncestors(),j.addSelfToProject(r),r==null||r.add(j,W.Added),j.setParent(this,r),j.initChildren(r),r||j.captureVersion();const G=Tr(b.parent).getMasterInputWithValueWriterFromAllInstances(b),q=Sd(G);if(q&&q.id!==((de=j.dataType)==null?void 0:de.id)){const ue=q==null?void 0:q.clone(r,j,x.UUID.uuid(),!0);ue&&((ie=j.dataType)==null||ie.merge(ue,r),ue.id!==((se=j.dataType)==null?void 0:se.id)&&ue.remove({ignoreUpstream:!1},r),j.dataType&&(j.dataType.metaSync({inferred:!0,like:!0},r),j.setDataType(j.dataType,r),r==null||r.add(j,W.Affected)))}return this.addProperty(j,r),b.setDeclaration(j,r),r==null||r.add(b,W.Updated),j}),r==null||r.attemptAutoclose("infer-definition-entity-from-inputs",this.id),{added:C(a),updated:C(c),removed:C(e),affected:C(f),self:this})}getRawDefaultValue(){const i={};return this.properties.forEach(r=>{var e;if(!HI(r))return;const a=le(r,this.project),c=r.codeName||pf(r,this.project)||Ps(Qi(a));i[c]=((e=r.getDefaultValue())==null?void 0:e.value)||null}),i}getActiveRawDefaultValue(){const i={};return this.properties.forEach(r=>{var f;if(!HI(r))return;const a=le(r,this.project),c=r.codeName||pf(r,this.project)||Ps(Qi(a)),e=(f=this.project.requestActiveDynamicValue(r,!0))==null?void 0:f.value;i[c]=(e==null?void 0:e.value)||null}),i}setAdditionalPropertiesDataType(i,r=this.project.addChangeSet(new S(this.project,x.sessionAuthor,B().toISOString(),this,!0,w.SetAdditionalPropertiesDataType))){if(!this.checkCanEdit(this,r))return Y.Logger.warn(`[setAdditionalPropertiesDataType] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),r==null||r.attemptAutoclose(w.SetAdditionalPropertiesDataType,this.id),this;const a=this.additionalPropertiesDataType;return(a==null?void 0:a.id)!==(i==null?void 0:i.id)&&(a==null||a.remove({ignoreUpstream:!0},r),this.additionalPropertiesDataType=i,this.subscribeToDependencies(),r==null||r.add(this,W.Affected)),r==null||r.attemptAutoclose(w.SetAdditionalPropertiesDataType,this.id),this}removeAdditionalPropertiesDataType(i=this.project.addChangeSet(new S(this.project,x.sessionAuthor,B().toISOString(),this,!0,w.RemoveAllPropertiesImplement))){return this.checkCanEdit(this,i)?(this.additionalPropertiesDataType&&(this.additionalPropertiesDataType.remove({ignoreUpstream:!0},i),i==null||i.add(this,W.Affected),this.additionalPropertiesDataType=null),i==null||i.attemptAutoclose(w.RemoveAllPropertiesImplement,this.id),this):(Y.Logger.warn(`[removeAdditionalPropertiesDataType] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(w.RemoveAllPropertiesImplement,this.id),this)}setAllPropertiesImplement(i,r=this.project.addChangeSet(new S(this.project,x.sessionAuthor,B().toISOString(),this,!0,w.SetAllPropertiesImplement))){if(!this.checkCanEdit(this,r))return Y.Logger.warn(`[setAllPropertiesImplement] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),r==null||r.attemptAutoclose(w.SetAllPropertiesImplement,this.id),this;const a=this.allPropertiesImplement;return(a==null?void 0:a.id)!==(i==null?void 0:i.id)&&(a==null||a.remove({ignoreUpstream:!0},r),this.allPropertiesImplement=i,this.subscribeToDependencies(),r==null||r.add(this,W.Affected)),r==null||r.attemptAutoclose(w.SetAllPropertiesImplement,this.id),this}removeAllPropertiesImplement(i=this.project.addChangeSet(new S(this.project,x.sessionAuthor,B().toISOString(),this,!0,w.RemoveAllPropertiesImplement))){return this.checkCanEdit(this,i)?(this.allPropertiesImplement&&(this.properties.find(r=>{var a;return r.id===((a=this.allPropertiesImplement)==null?void 0:a.id)})||this.allPropertiesImplement.remove({ignoreUpstream:!0},i),i==null||i.add(this,W.Affected),this.allPropertiesImplement=null),i==null||i.attemptAutoclose(w.RemoveAllPropertiesImplement,this.id),this):(Y.Logger.warn(`[removeAllPropertiesImplement] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(w.RemoveAllPropertiesImplement,this.id),this)}};R(_i,"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(_i,"type",d.DefinitionEntity),R(_i,"USER_MANAGED_PARENT_TYPES",[d.Project,d.DataType]),R(_i,"PARENT_TYPES",[..._i.USER_MANAGED_PARENT_TYPES]),R(_i,"MUTABLE_BASE_PROPERTIES",["name","codeName","description","static","abstract","additionalProperties"]),R(_i,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),R(_i,"BASE_PROPERTIES",[..._i.MUTABLE_BASE_PROPERTIES,..._i.INMUTABLE_BASE_PROPERTIES]),R(_i,"MUTABLE_META_PROPERTIES",[..._i.MUTABLE_BASE_PROPERTIES,"x","y"]),R(_i,"INMUTABLE_META_PROPERTIES",[..._i.INMUTABLE_BASE_PROPERTIES]),R(_i,"META_PROPERTIES",[..._i.MUTABLE_META_PROPERTIES,..._i.INMUTABLE_META_PROPERTIES]),R(_i,"MUTABLE_UPSTREAM_PROPERTIES",["extends","implements"]),R(_i,"INMUTABLE_UPSTREAM_PROPERTIES",["parent"]),R(_i,"UPSTREAM_PROPERTIES",[..._i.MUTABLE_UPSTREAM_PROPERTIES,..._i.INMUTABLE_UPSTREAM_PROPERTIES]),R(_i,"MUTABLE_DOWNSTREAM_PROPERTIES",["properties","methods","abstractMethods","allPropertiesImplement","additionalPropertiesDataType"]),R(_i,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),R(_i,"DOWNSTREAM_PROPERTIES",[..._i.MUTABLE_DOWNSTREAM_PROPERTIES,..._i.INMUTABLE_DOWNSTREAM_PROPERTIES]),R(_i,"PROPERTIES",[..._i.META_PROPERTIES,..._i.UPSTREAM_PROPERTIES,..._i.DOWNSTREAM_PROPERTIES]);let Ls=_i;async function y_i(l,p={}){const i=Y.YieldTracker.from(p),r=[],a=qt(l.errors,r);return await i.tick(),a}function h_i(l){const p=[];return qt(l.errors,p)}const QI=class QI extends Ex{constructor(i,r){super(i);R(this,"initialData");R(this,"id");R(this,"name");R(this,"description",null);R(this,"type",d.PrimitiveEntity);R(this,"static");R(this,"abstract");R(this,"properties",[]);R(this,"methods",[]);R(this,"abstractMethods",[]);R(this,"extends",null);R(this,"errors",[]);R(this,"project");this.initialData=i,this.project=r,this.id=i.id,this.name=i.name,this.description=i.description,this.static=i.static,this.abstract=i.abstract,this.properties=this.initialData.properties.map(a=>{const c=Ae(a,this.project);return c.setParent(this,null),c.initChildren(null),c}),this.methods=this.initialData.methods.map(a=>{const c=Ae(a,this.project);return c.parent=this,c}),this.abstractMethods=this.initialData.abstractMethods.map(a=>{const c=Ae(a,this.project);return c.parent=this,c}),this.initialData.extends&&(this.extends=Ae(this.initialData.extends,this.project))}get allMethods(){return C([...this.ownDeclaredMethods,...this.allBaseMethodsFromOriginalParents])}get allProperties(){return C([...this.ownDeclaredProperties,...this.allBasePropertiesFromOriginalParents])}get allBaseMethodsFromOriginalParents(){var a;const i=((a=this.extends)==null?void 0:a.allMethods)||[],r=[...i].filter(c=>!i.some(e=>e.id!==c.id));return C(r)}get allBasePropertiesFromOriginalParents(){var a;const i=((a=this.extends)==null?void 0:a.allProperties)||[],r=[...i].filter(c=>!i.some(e=>{var f;return e.id!==c.id&&(e.implements.find(h=>h.id===c.id)||((f=e.extends)==null?void 0:f.id)===c.id)}));return C(r)}get allBasePropertiesFromExtendedAndImplementedEntities(){var a,c;const i=[...((a=this.extends)==null?void 0:a.ownDeclaredProperties)||[],...((c=this.extends)==null?void 0:c.allBasePropertiesFromExtendedAndImplementedEntities)||[]].filter(e=>!e.abstract),r=[...i].filter(e=>!i.some(f=>{var h;return f.id!==e.id&&(f.implements.find(m=>m.id===e.id)||((h=f.extends)==null?void 0:h.id)===e.id)}));return C(r)}get extendedPropertiesFromOriginalParents(){var a,c;const i=[...((a=this.extends)==null?void 0:a.ownDeclaredProperties)||[],...((c=this.extends)==null?void 0:c.extendedPropertiesFromOriginalParents)||[]].filter(e=>!e.abstract),r=[...i].filter(e=>!i.some(f=>{var h;return f.id!==e.id&&(f.implements.find(m=>m.id===e.id)||((h=f.extends)==null?void 0:h.id)===e.id)}));return C(r)}get implementedPropertiesFromOriginalParents(){return C([...(this.extends?[this.extends]:[]).reduce((i,r)=>{const a=r.implementedPropertiesFromOriginalParents,c=[...r.ownDeclaredProperties].filter(h=>!!h.abstract),e=[...a,...c,...i];return[...e].filter(h=>!!!e.find(E=>{var b;return((b=E.extends)==null?void 0:b.id)===h.id||E.implements.find(A=>A.id===h.id)}))},[])])}get extendedProperties(){return this.properties.filter(i=>i.isExtendedProperty)}get ownDeclaredMethods(){return[...this.methods]}get ownDeclaredProperties(){return this.properties.filter(i=>!i.isExtendedProperty)}subscribe(){return this.project.subscribeBuiltInInstance(this),this}unsubscribe(){return this.project.unsubscribeBuiltInInstance(this),this}async APILoad(i=Ke,...r){return await QI.repository.APILoad(this.id,...r),this}toFlat(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this,...this.properties.flatMap(a=>a.toFlat(i)),...this.methods.flatMap(a=>a.toFlat(i)),...this.abstractMethods.flatMap(a=>a.toFlat(i))])}toFlatIds(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.id,...this.properties.flatMap(a=>a.toFlatIds(i)),...this.methods.flatMap(a=>a.toFlatIds(i)),...this.abstractMethods.flatMap(a=>a.toFlatIds(i))])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,description:this.description,static:this.static,abstract:this.abstract,type:this.type,name:this.name}}toJSON(i=new Set){var r;return i.has(this.id)?this.toReference():(i.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,static:this.static,abstract:this.abstract,properties:this.properties.map(a=>a.toJSON(i)),methods:this.methods.map(a=>a.toJSON(i)),abstractMethods:this.abstractMethods.map(a=>a.toJSON(i)),extends:((r=this.extends)==null?void 0:r.toJSON(i))||null})}toReference(i=at){return{id:this.id+"--"+x.UUID.uuid()+"--ref",type:d.GenericReference,entityId:this.id,version:this.version,entityType:this.type}}toShallowJSON(i=at){var r;return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,abstract:this.abstract,static:this.static,properties:this.properties.map(a=>a.toReference()),methods:this.methods.map(a=>a.toReference()),abstractMethods:this.abstractMethods.map(a=>a.toReference()),extends:((r=this.extends)==null?void 0:r.toReference())||null}}toFlatJSON(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.toShallowJSON(),...this.properties.flatMap(a=>a.toFlatJSON(i)),...this.methods.flatMap(a=>a.toFlatJSON(i)),...this.abstractMethods.flatMap(a=>a.toFlatJSON(i))])}toGenerationTarget(i=at){var r;return{id:this.id,type:this.type,name:this.name,description:this.description,static:this.static,abstract:this.abstract,extends:(r=this.extends)==null?void 0:r.id}}toFlatGenerationTarget(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.toGenerationTarget(),...this.properties.flatMap(a=>a.toFlatGenerationTarget(i)),...this.methods.flatMap(a=>a.toFlatGenerationTarget(i)),...this.abstractMethods.flatMap(a=>a.toFlatGenerationTarget(i))])}clearErrors(){return this.errors=[],this.properties.forEach(i=>i.clearErrors()),this.methods.forEach(i=>i.clearErrors()),this.abstractMethods.forEach(i=>i.clearErrors()),this}validate(){return this.errors=h_i(this),{success:!0}}async validateAsync(i={}){const r=Y.YieldTracker.from(i);return this.errors=await y_i(this,{tracker:r}),{success:!0}}getErrors(){return[...this.errors,...this.properties.flatMap(r=>r.getErrors()),...this.methods.flatMap(r=>r.getErrors()),...this.abstractMethods.flatMap(r=>r.getErrors())]}async getErrorsAsync(i={}){const r=Y.YieldTracker.from(i),a=[...this.errors];await r.tick();for(const c of this.properties){const e=await c.getErrorsAsync({tracker:r});a.push(...e)}for(const c of this.methods){const e=await c.getErrorsAsync({tracker:r});a.push(...e)}for(const c of this.abstractMethods){const e=await c.getErrorsAsync({tracker:r});a.push(...e)}return a}getShallowErrors(){return this.errors}getAllInteractiveMethods(){const i=[];return i.push(...this.methods),!this.extends||this.extends.type===d.PrimitiveEntity?i:C(i)}};R(QI,"repository",{APILoad:async(i,...r)=>null});let xa=QI;function tr(l,p){if(!l)throw new Error("Entity is null");const i=p.get(l.id);switch(l.type){case d.LiteralValue:return i||new Vr(l,p);case d.DefinitionEntity:return i||new Ls(l,p);case d.PrimitiveEntity:return i||new xa(l,p);case d.FunctionDeclaration:return i||new ld(l,p);case d.GlobalEvent:return i||new Tp(l,p);case d.DataType:return i||new yr(l,p);case d.Property:return i||new ps(l,p);case d.FunctionCall:return i||new hp(l,p);case d.Condition:return i||new Ep(l,p);case d.Operation:return i||new mp(l,p);case d.VariableDeclaration:return i||new Ap(l,p);case d.VariableInstance:return i||new bp(l,p);case d.OutputMap:return i||new eo(l,p);case d.ArgumentDeclaration:return i||new Ga(l,p);case d.InputMap:return i||new ds(l,p);case d.Project:return i||new x(l);case d.InstalledProject:return i||new gp(l,p);case d.ActionDescriptor:return i||new Hi(l,p);case d.ReturnStatement:return i||new zd(l,p);case d.Loop:return i||new vp(l,p);case d.Search:return i||new Ip(l,p);case d.ValueDescriptor:return i||new ud(l,p);case d.BuiltInBaseEntity:return i||new od(l,p);case d.InternalCall:return i||new Rp(l,p);case d.ContinueStatement:return i||new wp(l,p);case d.BreakStatement:return i||new Dp(l,p);case d.GenericReference:return p.get(l.entityId);default:throw new Error("Invalid entity type: "+l.type)}}function Ae(l,p){if(!l)throw new Error("Entity is null");const i=tr(l,p);return i.subscribe(),i}function m_i(l,p,i){if(!l)throw new Error("Entity is null");switch(l.type){case d.LiteralValue:return Vr.fromGenerationTarget(l,p,i);case d.DefinitionEntity:return Ls.fromGenerationTarget(l,p,i);case d.FunctionDeclaration:return ld.fromGenerationTarget(l,p,i);case d.GlobalEvent:return Tp.fromGenerationTarget(l,p,i);case d.DataType:return yr.fromGenerationTarget(l,p,i);case d.Property:return ps.fromGenerationTarget(l,p,i);case d.FunctionCall:return hp.fromGenerationTarget(l,p,i);case d.Condition:return Ep.fromGenerationTarget(l,p,i);case d.Operation:return mp.fromGenerationTarget(l,p,i);case d.VariableDeclaration:return Ap.fromGenerationTarget(l,p,i);case d.VariableInstance:return bp.fromGenerationTarget(l,p,i);case d.OutputMap:return eo.fromGenerationTarget(l,p,i);case d.ArgumentDeclaration:return Ga.fromGenerationTarget(l,p,i);case d.InputMap:return ds.fromGenerationTarget(l,p,i);case d.InstalledProject:return gp.fromGenerationTarget(l,p,i);case d.ReturnStatement:return zd.fromGenerationTarget(l,p,i);case d.Loop:return vp.fromGenerationTarget(l,p,i);case d.Search:return Ip.fromGenerationTarget(l,p,i);case d.ActionDescriptor:return Hi.fromGenerationTarget(l,p,i);case d.ValueDescriptor:return ud.fromGenerationTarget(l,p,i);case d.InternalCall:return Rp.fromGenerationTarget(l,p,i);case d.ContinueStatement:return wp.fromGenerationTarget(l,p,i);case d.BreakStatement:return Dp.fromGenerationTarget(l,p,i);default:throw new Error("Invalid entity type: "+l.type)}}const at={seenEntityMaps:new Map,seenEntities:new Set,timestamp:B().toISOString()};class ike{constructor(){R(this,"initialData")}}const Ke={cascade:!1},rke={APILoad:async(l,...p)=>null},T_i={APICreate:async(l,...p)=>l,APIUpdate:async(l,...p)=>l,APIDelete:async(l,...p)=>l,APIClone:async(l,...p)=>{},APILoadVersion:async(l,p,...i)=>null,...rke};class v_i{}class nke extends ike{}class E_i extends nke{}class b_i{}class A_i{}class I_i{}class aL{}class g_i extends aL{}class R_i extends aL{}class D_i{}class Jf{static initReadsValue(p){if(p.initialData.readsValue&&p.initialData.readsValue.type!==d.GenericReference)p.readsValue=Ae(p.initialData.readsValue,p.project);else if(p.initialData.readsValue&&p.initialData.readsValue.type===d.GenericReference){const i=ma(p.initialData.readsValue,p.project);i&&(p.readsValue=i)}if(p.readsValue){if(xt.includes(p.readsValue.type)){let i=p.parent;!br.includes(i.type)&&i.type!==d.Project&&(i=i.parent);const r=p.type===d.InputMap&&p.parent.type===d.Loop;r&&(i=p.parent.parent),p.readsValue.setParent(i,null),p.readsValue.initChildren(null),i&&i.type!==d.Project&&!r&&i.detachedChildren.includes(p)?i.replaceDetachedChild(p,p.readsValue):i&&i.type!==d.Project&&!r&&i.subscribeDetachedChild(p.readsValue)}p.readsValue.addValueReader(p,null)}return p.readsValue}}class kE{static initWritesValues(p,i){const r=p.initialData.writesValues.reduce((c,e)=>{if(e.type===d.GenericReference||p.writesValues.some(h=>h.id===e.id))return c;const f=Ae(e,p.project);return f.setValueWriter(p,null),xt.includes(f.type)&&(f.setParent(i,null),f.initChildren(null)),[...c,f]},[]),a=[...p.writesValues];return p.writesValues=C([...a,...r]),p.writesValues}}class w_i{}var si=(l=>(l.PROJECT_INITIALIZED="project-initialized",l.BEFORE_CHANGE_SET_CLOSE_BEFORE_SIDE_EFFECTS="before-change-set-close-before-side-effects",l.BEFORE_CHANGE_SET_CLOSE_AFTER_SIDE_EFFECTS="before-change-set-close-after-side-effects",l.CHANGE_SET_CLOSED_BEFORE_PERSIST="change-set-closed-before-persist",l.CHANGE_SET_PERSISTED="change-set-persisted",l.BEFORE_CHANGE_SET_PERSIST="before-change-set-persist",l.EXPLICIT_DEFINITION_ENTITY_ADDED="explicit-definition-entity-added",l.EXPLICIT_DEFINITION_ENTITY_REMOVED="explicit-definition-entity-removed",l.EXPLICIT_DEFINITION_ENTITY_UPDATED="explicit-definition-entity-updated",l.PERSISTED_DEFINITION_ENTITY_ADDED="persisted-definition-entity-added",l.PERSISTED_DEFINITION_ENTITY_REMOVED="persisted-definition-entity-removed",l.PERSISTED_DEFINITION_ENTITY_UPDATED="persisted-definition-entity-updated",l.RELATIONAL_DATABASE_DEFINITION_ENTITY_ADDED="relational-database-definition-entity-added",l.RELATIONAL_DATABASE_DEFINITION_ENTITY_REMOVED="relational-database-definition-entity-removed",l.RELATIONAL_DATABASE_DEFINITION_ENTITY_UPDATED="relational-database-definition-entity-updated",l))(si||{});const sL={...Jx,events:new Y.Events("def-proj-static-p-ctx-events")},ake={requestActiveDynamicValue:(l,p=!1)=>null,...sL},$t=class $t extends nn{constructor(i,r={...ake,events:new Y.Events("def-proj-inst-p-ctx-events")}){super(i);R(this,"initialData");R(this,"id");R(this,"type",d.Project);R(this,"name",null);R(this,"description",null);R(this,"x");R(this,"y");R(this,"entities",[]);R(this,"projects",[]);R(this,"functions",[]);R(this,"events",[]);R(this,"variableDeclarations",[]);R(this,"variableInstances",[]);R(this,"conditions",[]);R(this,"operations",[]);R(this,"functionCalls",[]);R(this,"loops",[]);R(this,"searches",[]);R(this,"primitives",[]);R(this,"builtInBaseEntities",[]);R(this,"operationDeclarations",[]);R(this,"globalEventActionDescriptors",[]);R(this,"loopDeclarations",[]);R(this,"loopDeclarationsBodies",[]);R(this,"conditionDeclarations",[]);R(this,"valueDescriptors",[]);R(this,"dataTypes",[]);R(this,"project");R(this,"instances",{});R(this,"builtInInstances",{});R(this,"deletedInstances",{});R(this,"subscribedDefinitionEntities",new Set);R(this,"errors",[]);R(this,"references",[]);R(this,"history",[]);R(this,"undoableStackValueIndex",-1);R(this,"detachedDependents",{});R(this,"knownVersions",null);R(this,"activeVersion",!1);R(this,"initialized",!1);R(this,"startedInitialization",!1);R(this,"diggestedBuiltInBaseEntitiesIds",new Set);R(this,"rejectParallelCS",!1);R(this,"onPersistChangeSetSequentiallyCallback",null);R(this,"onPersistChangeSetInParallelCallback",null);R(this,"onAddChangeSetCallback",null);R(this,"onDiscardChangeSetCallback",null);if(this.parentContext=r,this.initialData=i,this.id=i.id,this.name=i.name,this.description=i.description,this.x=0,this.y=0,this.instances[this.id]=this,!$t.UUID)throw new Error("UUID module is already initialized. Please inject a valid UUID module.")}static get UUID(){var i;return(i=this.parentContext.requestExtension("uuid"))==null?void 0:i.module}static new(i=null){return{id:$t.UUID.uuid(),version:$t.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||B().toISOString(),author:(i==null?void 0:i.author)||$t.sessionAuthor,previousVersion:null,deleted:!1,deletable:!0,editable:!0,type:d.Project,name:"",description:"",entities:[],functions:[],events:[],projects:[],variableDeclarations:[],variableInstances:[],conditions:[],operations:[],functionCalls:[],loops:[],searches:[]}}static validateGenerationTarget(i,r){let a=JSON.parse(JSON.stringify(i));const c=[],e=[],f=Wr(a);return e.push(...f.errors),c.push(...f.explanations),{errors:e,explanations:c,modifiedData:a}}get off(){return this.parentContext.events.off}get on(){return this.parentContext.events.on}get emit(){return this.parentContext.events.emit}get emitAsync(){return this.parentContext.events.emitAsync}get emitAsyncAll(){return this.parentContext.events.emitAsyncAll}get emitAsyncAllSettled(){return this.parentContext.events.emitAsyncAllSettled}get emitAsyncSequentially(){return this.parentContext.events.emitAsyncSequentially}get emitAsyncSequentiallyAll(){return this.parentContext.events.emitAsyncSequentiallyAll}get emitAsyncSequentiallyAllSettled(){return this.parentContext.events.emitAsyncSequentiallyAllSettled}async closePersistChangeSetsSequentially(){Y.Logger.log("[ProjectState.closePersistChangeSetsSequentially] called");const i=this.history.find(r=>r.dirty&&!r.open&&!r.submitting);i&&(Y.Logger.log(`[ProjectState.closePersistChangeSetsSequentially] closing pending change-set ${i.id} - ${i.autoCloseActionName}`),await this.persistChangeSetSequentially(i))}async onPersistChangeSetSequentially(i){this.onPersistChangeSetSequentiallyCallback=i,Y.Logger.log("[ProjectState.onPersistChangeSetSequentially] onPersistChangeSetSequentiallyCallback has been set. Checking for pending change-sets."),await this.closePersistChangeSetsSequentially()}offPersistChangeSetSequentially(){this.onPersistChangeSetSequentiallyCallback=null}async onPersistChangeSetInParallel(i){this.onPersistChangeSetInParallelCallback=i,Y.Logger.log("[ProjectState.onPersistChangeSetInParallel] onPersistChangeSetInParallelCallback has been set. Checking for pending change-sets.");for(const r of this.history)this.persistChangeSetInParallel(r),await new Promise(a=>setTimeout(a,27))}offPersistChangeSetInParallel(){this.onPersistChangeSetInParallelCallback=null}onAddChangeSet(i){this.onAddChangeSetCallback=i}offAddChangeSet(){this.onAddChangeSetCallback=null}onDiscardChangeSet(i){this.onDiscardChangeSetCallback=i}offDiscardChangeSet(){this.onDiscardChangeSetCallback=null}async persistChangeSetSequentially(i){if(Y.Logger.log(`[ProjectState.persistChangeSetSequentially] called for change-set ${i.id} - ${i.autoCloseActionName}`),!i.dirty||i.open||i.submitting){Y.Logger.log(`[ProjectState.persistChangeSetSequentially] change-set ${i.id} - ${i.autoCloseActionName} is not dirty, or is open, or is already being submitted, skipping.`);return}const r=this.history.findIndex(e=>e.id===i.id),a=this.history.slice(0,r),c=a[a.length-1];if(c!=null&&c.dirty){Y.Logger.log(`[ProjectState.persistChangeSetSequentially] lastBeforeSelf is dirty: ${c.id} - ${c.autoCloseActionName}, closing it first.`);return}this.onPersistChangeSetSequentiallyCallback&&(Y.Logger.log(`[ProjectState.persistChangeSetSequentially] invoking onPersistChangeSetSequentiallyCallback for change-set ${i.id} - ${i.autoCloseActionName}`),this.emit("before-change-set-persist",i),i.submitting=!0,(await this.onPersistChangeSetSequentiallyCallback(i)).success&&(i.dirty=!1,this.emit("change-set-persisted",i),Y.Logger.log(`[ProjectState.persistChangeSetSequentially] change-set ${i.id} - ${i.autoCloseActionName} closed successfully, checking for pending change-sets to close.`),this.closePersistChangeSetsSequentially()))}async persistChangeSetInParallel(i){if(Y.Logger.log(`[ProjectState.persistChangeSetInParallel] called for change-set ${i.id} - ${i.autoCloseActionName}`),!i.dirty||i.open||i.submitting){Y.Logger.log(`[ProjectState.persistChangeSetInParallel] change-set ${i.id} - ${i.autoCloseActionName} is not dirty, or is open, or is already being submitted, skipping.`);return}this.onPersistChangeSetInParallelCallback&&(Y.Logger.log(`[ProjectState.persistChangeSetInParallel] invoking onPersistChangeSetInParallelCallback for change-set ${i.id} - ${i.autoCloseActionName}`),this.emit("before-change-set-persist",i),i.submitting=!0,(await this.onPersistChangeSetInParallelCallback(i)).success&&(i.dirty=!1,this.emit("change-set-persisted",i)))}toLatestChangeSet(i,r,a,c=!1,e="here-this"){if(!this.history.length)return new S(this,i,r,a,c,e);const f=this.history[this.history.length-1];return f.open?f:this.addChangeSet(new S(this,i,r,a,c,e))}addChangeSet(i){var a,c;if(!this.history.length)return this.undoableStackValueIndex=I_(this.undoableStackValueIndex,this.history,i),(a=this.onAddChangeSetCallback)==null||a.call(this,i,this.undoableStackValueIndex),i;const r=this.history.find(e=>e.id===(i==null?void 0:i.id));if(r)return r;if(this.rejectParallelCS){const e=this.history.find(f=>f.open);if(e)throw Y.Logger.warn("Previous still open: ",e),Y.Logger.warn("New change set: ",i),new Error(`There is already an open change-set with id '${e.id}'${e.autoCloseActionName?` auto-close: ${e.autoCloseActionName}`:""}${e.self?` root: ${e.self.type} ${le(e.self,this)}`:""}.`)}return this.undoableStackValueIndex=I_(this.undoableStackValueIndex,this.history,i),(c=this.onAddChangeSetCallback)==null||c.call(this,i,this.undoableStackValueIndex),i}discardChangeSet(i){var a;Y.Logger.log(`[ProjectState.discardChangeSet] called for change-set ${i.id} - ${i.autoCloseActionName}`);const r=this.history.findIndex(c=>c.id===(i==null?void 0:i.id));return r!==-1&&(this.history.splice(r,1),Y.Logger.log(`[ProjectState.discardChangeSet] Removed change-set ${i.id} - ${i.autoCloseActionName} from history.`),this.undoableStackValueIndex=this.undoableStackValueIndex-1,(a=this.onDiscardChangeSetCallback)==null||a.call(this,i),i==null||i.teardown()),this}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,$t.sessionAuthor,B().toISOString(),this,!0,"sync-dependents"))){const r=[],a=[],c=[],e=[];return Object.values(this.detachedDependents).forEach(f=>{const h=f.entity.afterAllChildrenInitialized(i);r.push(...h.updated),a.push(...h.added),c.push(...h.removed),e.push(...h.affected)}),i==null||i.attemptAutoclose("sync-dependents",this.id),{updated:C(r),added:C(a),removed:C(c),affected:C(e),self:this}}onDetachedDependencyRemoved(i,r,a){const c=[],e=[],f=[],h=[];return{updated:C(c),added:C(e),removed:C(f),affected:C(h),self:this}}onDetachedDependencyRestored(i,r,a){const c=[],e=[],f=[],h=[];return{updated:C(c),added:C(e),removed:C(f),affected:C(h),self:this}}unsubscribeFromDependencies(){return this}subscribeToDependencies(){return this}increaseVersion(i){var r;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.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=$t.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 $t(this);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 $t(this);return this.apply(i)}apply(i){const r=this.toMeta();return i.metaSync(r,null),i.entities=[...this.entities],i.projects=[...this.projects],i.functions=[...this.functions],i.events=[...this.events],i.variableDeclarations=[...this.variableDeclarations],i.variableInstances=[...this.variableInstances],i.conditions=[...this.conditions],i.operations=[...this.operations],i.functionCalls=[...this.functionCalls],i.loops=[...this.loops],i.searches=[...this.searches],i}recursiveCaptureUpstreamVersions(i){const r=[],a=[],c=[],e=[];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[_,N]of A.knownVersions)E.set(_,N);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 $t(E)}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.entities=[...h.entities],this.projects=[...h.projects],this.functions=[...h.functions],this.events=[...h.events],this.variableDeclarations=[...h.variableDeclarations],this.variableInstances=[...h.variableInstances],this.conditions=[...h.conditions],this.operations=[...h.operations],this.functionCalls=[...h.functionCalls],this.loops=[...h.loops],this.searches=[...h.searches],{updated:C(a),added:C(c),removed:C(e),affected:C(f),self:this}}updateWithShallowTransfer(i,r=this.project.addChangeSet(new S(this.project,$t.sessionAuthor,B().toISOString(),this,!0,w.UpdateWithShallowTransfer))){return this.checkCanEdit(this,r)?(this.metaSync(i,r),this.version=i.version,this.createdAt=i.createdAt,this.author=i.author,this.deleted=i.deleted,this.previousVersion=i.previousVersion,this.captureVersion(),this.subscribeToDependencies(),r==null||r.attemptAutoclose(w.UpdateWithShallowTransfer,this.id),this):(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)}updateWithGenerationTarget(i,r=this.project.addChangeSet(new S(this.project,$t.sessionAuthor,B().toISOString(),this,!0,w.UpdateWithGenerationTarget))){return this.checkCanEdit(this,r)?(this.metaSync(i,r),this.captureVersion(),this.subscribeToDependencies(),r==null||r.attemptAutoclose(w.UpdateWithGenerationTarget,this.id),this):(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)}hydrateAncestors(){const i=[],r=[],a=[],c=[];return{updated:C(i),added:C(r),removed:C(a),affected:C(c),self:this}}afterAllChildrenInitialized(i=null){const r=[],a=[],c=[],e=[];return this.initialized||(this.initialized=!0,this.emit("project-initialized",this,i)),this.validate(),{updated:C(r),added:C(a),removed:C(c),affected:C(e),self:this}}addSelfToProject(i){const r=[],a=[],c=[],e=[];return this.subscribe(),this.subscribeToDependencies(),{updated:C(r),added:C(a),removed:C(c),affected:C(e),self:this}}get instancesList(){return Object.values(this.instances)}get builtInInstancesList(){return Object.values(this.builtInInstances)}isOperationDeclaration(i){return this.operationDeclarations.includes(i)}isGlobalEventActionDescriptor(i){return this.globalEventActionDescriptors.includes(i)}isLoopDeclaration(i){return this.loopDeclarations.includes(i)}isConditionDeclaration(i){return this.conditionDeclarations.includes(i)}initChildren(i=this.project.addChangeSet(new S(this.project,$t.sessionAuthor,B().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.entities=this.initialData.entities.map(r=>{const a=Ae(r,this);return a.setParent(this,null),a.initChildren(i),a}),this.projects=this.initialData.projects.map(r=>{const a=Ae(r,this);return a.setParent(this,null),a.initChildren(i),a}),this.variableDeclarations=this.initialData.variableDeclarations.map(r=>{const a=Ae(r,this);return a.setParent(this,null),a.initChildren(i),a}),this.variableInstances=this.initialData.variableInstances.map(r=>{const a=Ae(r,this);return a.setParent(this,null),a.initChildren(i),a}),this.conditions=this.initialData.conditions.map(r=>{const a=Ae(r,this);return a.setParent(this,null),a.initChildren(i),a}),this.operations=this.initialData.operations.map(r=>{const a=Ae(r,this);return a.setParent(this,null),a.initChildren(i),a}),this.functions=this.initialData.functions.map(r=>{const a=Ae(r,this);return a.setParent(this,null),a.initChildren(i),a}),this.events=this.initialData.events.map(r=>{const a=Ae(r,this);return a.setParent(this,null),a.initChildren(i),a}),this.functionCalls=this.initialData.functionCalls.map(r=>{const a=Ae(r,this);return a.setParent(this,null),a.initChildren(i),a}),this.loops=this.initialData.loops.map(r=>{const a=Ae(r,this);return a.setParent(this,null),a.initChildren(i),a}),this.searches=this.initialData.searches.map(r=>{const a=Ae(r,this);return a.setParent(this,null),a.initChildren(i),a}),this.attachOrphanReferences(),this.subscribeToDependencies(),this.afterAllChildrenInitialized(i),i==null||i.attemptAutoclose("init-children",this.id),this)}subscribeInstance(i){return(!this.instances[i.id]||this.instances[i.id]!==i)&&(this.instances[i.id]=i),this}subscribeDeletedInstance(i){return(!this.deletedInstances[i.id]||this.deletedInstances[i.id]!==i)&&(this.deletedInstances[i.id]=i),this}subscribeBuiltInInstance(i){return(!this.builtInInstances[i.id]||this.builtInInstances[i.id]!==i)&&(this.builtInInstances[i.id]=i),this}subscribe(){var i;return this.activeVersion=!0,(i=this.knownVersions)==null||i.forEach(r=>{r.version!==this.version&&(r.activeVersion=!1)}),this.subscribeInstance(this),this}unsubscribe(){return this}unsubscribeInstance(i){return delete this.instances[i.id],this}unsubscribeDeletedInstance(i){return delete this.deletedInstances[i.id],this}unsubscribeBuiltInInstance(i){return delete this.builtInInstances[i.id],this}findSubscribedBuiltInInstance(i){return this.builtInInstances[i.id]||null}get(i){return this.instances[i]||this.builtInInstances[i]||null}getDeleted(i){return this.deletedInstances[i]||null}getManaged(i){return this.getBuiltIn(i)?null:this.instances[i]||null}getBuiltIn(i){return this.builtInInstances[i]||null}findSubscribedInstanceFromReference(i){return this.instances[i.entityId]||null}findSubscribedBuiltInInstanceFromReference(i){return this.builtInInstances[i.entityId]||null}metaSync(i,r=this.project.addChangeSet(new S(this.project,$t.sessionAuthor,B().toISOString(),this,!0,"meta-sync"))){const a=Yr(this,i,r),c=zr(this,a),e=this.toMeta();return this.name=a.name!==void 0?a.name:e.name,this.description=a.description!==void 0?a.description:e.description,this.x=a.x||e.x,this.y=a.y||e.y,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 $t.repository.APILoad(this.id,...r),this}async APICreate(i=Ke,...r){return await $t.repository.APICreate(this.toShallowJSON(),...r),this}async APIUpdate(i=Ke,...r){return await $t.repository.APIUpdate(this.toShallowJSON(),...r),this}async APIDelete(i=Ke,...r){return await $t.repository.APIDelete(this.toShallowJSON(),...r),this}async APIClone(i=Ke,...r){return await $t.repository.APIClone(this.id,...r),this}async APILoadVersion(i=Ke,r,...a){return await $t.repository.APILoadVersion(this.id,r,...a)}remove({ignoreUpstream:i}={ignoreUpstream:!1},r=this.project.addChangeSet(new S(this.project,$t.sessionAuthor,B().toISOString(),this,!0,w.RemoveEntity))){return{added:[],updated:[],removed:[],affected:[],self:this}}restore({}={},i=this.project.addChangeSet(new S(this.project,$t.sessionAuthor,B().toISOString(),this,!0,w.RestoreEntity))){return{added:[],updated:[],removed:[],affected:[],self:this}}getAllBuiltInIds(){const i=new Set;return[...this.primitives.flatMap(r=>r.toFlatIds(i)),...this.builtInBaseEntities.flatMap(r=>r.toFlatIds(i)),...this.operationDeclarations.flatMap(r=>r.toFlatIds(i)),...this.globalEventActionDescriptors.flatMap(r=>r.toFlatIds(i)),...this.loopDeclarations.flatMap(r=>r.toFlatIds(i)),...this.conditionDeclarations.flatMap(r=>r.toFlatIds(i)),...this.valueDescriptors.flatMap(r=>r.toFlatIds(i)),...this.dataTypes.flatMap(r=>r.toFlatIds(i))]}getAllBuiltIn(){const i=new Set;return[...this.primitives.flatMap(r=>r.toFlat(i)),...this.builtInBaseEntities.flatMap(r=>r.toFlat(i)),...this.operationDeclarations.flatMap(r=>r.toFlat(i)),...this.globalEventActionDescriptors.flatMap(r=>r.toFlat(i)),...this.loopDeclarations.flatMap(r=>r.toFlat(i)),...this.conditionDeclarations.flatMap(r=>r.toFlat(i)),...this.valueDescriptors.flatMap(r=>r.toFlat(i)),...this.dataTypes.flatMap(r=>r.toFlat(i))]}toFlat(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this,...this.entities.flatMap(a=>a.toFlat(i)),...this.functions.flatMap(a=>a.toFlat(i)),...this.events.flatMap(a=>a.toFlat(i)),...this.projects.flatMap(a=>a.toFlat(i)),...this.variableDeclarations.flatMap(a=>a.toFlat(i)),...this.variableInstances.flatMap(a=>a.toFlat(i)),...this.conditions.flatMap(a=>a.toFlat(i)),...this.operations.flatMap(a=>a.toFlat(i)),...this.functionCalls.flatMap(a=>a.toFlat(i)),...this.loops.flatMap(a=>a.toFlat(i)),...this.searches.flatMap(a=>a.toFlat(i))])}toFlatIds(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.id,...this.entities.flatMap(a=>a.toFlatIds(i)),...this.functions.flatMap(a=>a.toFlatIds(i)),...this.events.flatMap(a=>a.toFlatIds(i)),...this.projects.flatMap(a=>a.toFlatIds(i)),...this.variableDeclarations.flatMap(a=>a.toFlatIds(i)),...this.variableInstances.flatMap(a=>a.toFlatIds(i)),...this.conditions.flatMap(a=>a.toFlatIds(i)),...this.operations.flatMap(a=>a.toFlatIds(i)),...this.functionCalls.flatMap(a=>a.toFlatIds(i)),...this.loops.flatMap(a=>a.toFlatIds(i)),...this.searches.flatMap(a=>a.toFlatIds(i))])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,description:this.description,type:this.type,editable:this.editable,deletable:this.deletable,name:this.name}}toJSON(i=new Set){return i.has(this.id)?this.toReference():(i.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,editable:this.editable,deletable:this.deletable,name:this.name,description:this.description,entities:this.entities.map(r=>r.toJSON(i)),variableDeclarations:this.variableDeclarations.map(r=>r.toJSON(i)),variableInstances:this.variableInstances.map(r=>r.toJSON(i)),conditions:this.conditions.map(r=>r.toJSON(i)),operations:this.operations.map(r=>r.toJSON(i)),loops:this.loops.map(r=>r.toJSON(i)),searches:this.searches.map(r=>r.toJSON(i)),functions:this.functions.map(r=>r.toJSON(i)),events:this.events.map(r=>r.toJSON(i)),projects:this.projects.map(r=>r.toJSON(i)),functionCalls:this.functionCalls.map(r=>r.toJSON(i))})}toJSONClone(i={uuidStrategy:"uuid"}){const r=new Map,a=new Set,c=this.getAllBuiltInIds();return Object.keys(this.instances).forEach(e=>{if(c.includes(e)){r.set(e,e);return}r.set(e,$t.UUID.uuid())}),a.add(this.id),{id:r.get(this.id),version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,editable:this.editable,deletable:this.deletable,name:this.name,description:this.description,entities:this.entities.map(e=>e.toJSONClone({...i,seenEntityMaps:r,seenEntities:a,newId:null})),projects:this.projects.map(e=>e.toJSONClone({...i,seenEntityMaps:r,seenEntities:a,newId:null})),variableDeclarations:this.variableDeclarations.map(e=>e.toJSONClone({...i,seenEntityMaps:r,seenEntities:a,newId:null})),variableInstances:this.variableInstances.map(e=>e.toJSONClone({...i,seenEntityMaps:r,seenEntities:a,newId:null})),conditions:this.conditions.map(e=>e.toJSONClone({...i,seenEntityMaps:r,seenEntities:a,newId:null})),operations:this.operations.map(e=>e.toJSONClone({...i,seenEntityMaps:r,seenEntities:a,newId:null})),functions:this.functions.map(e=>e.toJSONClone({...i,seenEntityMaps:r,seenEntities:a,newId:null})),events:this.events.map(e=>e.toJSONClone({...i,seenEntityMaps:r,seenEntities:a,newId:null})),functionCalls:this.functionCalls.map(e=>e.toJSONClone({...i,seenEntityMaps:r,seenEntities:a,newId:null})),loops:this.loops.map(e=>e.toJSONClone({...i,seenEntityMaps:r,seenEntities:a,newId:null})),searches:this.searches.map(e=>e.toJSONClone({...i,seenEntityMaps:r,seenEntities:a,newId:null}))}}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+"--"+$t.UUID.uuid()+"--ref",type:d.GenericReference,entityId:r,version:this.version,entityType:this.type}}toShallowJSON(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,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,editable:this.editable,deletable:this.deletable,name:this.name,description:this.description,entities:this.entities.map(c=>c.toReference(i)),functions:this.functions.map(c=>c.toReference(i)),events:this.events.map(c=>c.toReference(i)),projects:this.projects.map(c=>c.toReference(i)),variableDeclarations:this.variableDeclarations.map(c=>c.toReference(i)),variableInstances:this.variableInstances.map(c=>c.toReference(i)),conditions:this.conditions.map(c=>c.toReference(i)),operations:this.operations.map(c=>c.toReference(i)),functionCalls:this.functionCalls.map(c=>c.toReference(i)),loops:this.loops.map(c=>c.toReference(i)),searches:this.searches.map(c=>c.toReference(i))}}toFlatJSON(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.toShallowJSON(),...this.entities.flatMap(a=>a.toFlatJSON(i)),...this.functions.flatMap(a=>a.toFlatJSON(i)),...this.events.flatMap(a=>a.toFlatJSON(i)),...this.projects.flatMap(a=>a.toFlatJSON(i)),...this.variableDeclarations.flatMap(a=>a.toFlatJSON(i)),...this.variableInstances.flatMap(a=>a.toFlatJSON(i)),...this.conditions.flatMap(a=>a.toFlatJSON(i)),...this.operations.flatMap(a=>a.toFlatJSON(i)),...this.functionCalls.flatMap(a=>a.toFlatJSON(i)),...this.loops.flatMap(a=>a.toFlatJSON(i)),...this.searches.flatMap(a=>a.toFlatJSON(i))])}toGenerationTarget(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,type:this.type,name:this.name,description:this.description}}toFlatGenerationTarget(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[...this.entities.flatMap(a=>a.toFlatGenerationTarget(i)),...this.functions.flatMap(a=>a.toFlatGenerationTarget(i)),...this.events.flatMap(a=>a.toFlatGenerationTarget(i)),...this.projects.flatMap(a=>a.toFlatGenerationTarget(i)),...this.variableDeclarations.flatMap(a=>a.toFlatGenerationTarget(i)),...this.variableInstances.flatMap(a=>a.toFlatGenerationTarget(i)),...this.conditions.flatMap(a=>a.toFlatGenerationTarget(i)),...this.operations.flatMap(a=>a.toFlatGenerationTarget(i)),...this.functionCalls.flatMap(a=>a.toFlatGenerationTarget(i)),...this.loops.flatMap(a=>a.toFlatGenerationTarget(i)),...this.searches.flatMap(a=>a.toFlatGenerationTarget(i))])}clearErrors(){return this.errors=[],this.entities.forEach(i=>i.clearErrors()),this.projects.forEach(i=>i.clearErrors()),this.functions.forEach(i=>i.clearErrors()),this.events.forEach(i=>i.clearErrors()),this.variableDeclarations.forEach(i=>i.clearErrors()),this.variableInstances.forEach(i=>i.clearErrors()),this.conditions.forEach(i=>i.clearErrors()),this.operations.forEach(i=>i.clearErrors()),this.functionCalls.forEach(i=>i.clearErrors()),this.loops.forEach(i=>i.clearErrors()),this.searches.forEach(i=>i.clearErrors()),this}validate(){return this.validateChildren(),oE([...this.errors]),{success:!0}}async validateAsync(i={}){const r=Y.YieldTracker.from(i);return await this.validateChildrenAsync({tracker:r}),await xOe([...this.errors]),{success:!0}}validateChildren(){this.entities.forEach(i=>i.validate()),this.projects.forEach(i=>i.validate()),this.functions.forEach(i=>i.validate()),this.events.forEach(i=>i.validate()),this.variableDeclarations.forEach(i=>i.validate()),this.variableInstances.forEach(i=>i.validate()),this.conditions.forEach(i=>i.validate()),this.operations.forEach(i=>i.validate()),this.functionCalls.forEach(i=>i.validate()),this.loops.forEach(i=>i.validate()),this.searches.forEach(i=>i.validate())}async validateChildrenAsync(i={}){const r=Y.YieldTracker.from(i);for(let a=0;a<this.entities.length;a++)await this.entities[a].validateAsync({tracker:r});for(let a=0;a<this.projects.length;a++)await this.projects[a].validateAsync({tracker:r});for(let a=0;a<this.functions.length;a++)await this.functions[a].validateAsync({tracker:r});for(let a=0;a<this.events.length;a++)await this.events[a].validateAsync({tracker:r});for(let a=0;a<this.variableDeclarations.length;a++)await this.variableDeclarations[a].validateAsync({tracker:r});for(let a=0;a<this.variableInstances.length;a++)await this.variableInstances[a].validateAsync({tracker:r});for(let a=0;a<this.conditions.length;a++)await this.conditions[a].validateAsync({tracker:r});for(let a=0;a<this.operations.length;a++)await this.operations[a].validateAsync({tracker:r});for(let a=0;a<this.functionCalls.length;a++)await this.functionCalls[a].validateAsync({tracker:r});for(let a=0;a<this.loops.length;a++)await this.loops[a].validateAsync({tracker:r});for(let a=0;a<this.searches.length;a++)await this.searches[a].validateAsync({tracker:r})}getErrors(){return[...this.errors,...this.entities.flatMap(r=>r.getErrors()),...this.projects.flatMap(r=>r.getErrors()),...this.functions.flatMap(r=>r.getErrors()),...this.events.flatMap(r=>r.getErrors()),...this.variableDeclarations.flatMap(r=>r.getErrors()),...this.variableInstances.flatMap(r=>r.getErrors()),...this.conditions.flatMap(r=>r.getErrors()),...this.operations.flatMap(r=>r.getErrors()),...this.functionCalls.flatMap(r=>r.getErrors()),...this.loops.flatMap(r=>r.getErrors()),...this.searches.flatMap(r=>r.getErrors())]}async getErrorsAsync(i={}){const r=Y.YieldTracker.from(i),a=[...this.errors];await r.tick();for(let c=0;c<this.entities.length;c++){const e=await this.entities[c].getErrorsAsync({tracker:r});a.push(...e)}for(let c=0;c<this.projects.length;c++){const e=await this.projects[c].getErrorsAsync({tracker:r});a.push(...e)}for(let c=0;c<this.functions.length;c++){const e=await this.functions[c].getErrorsAsync({tracker:r});a.push(...e)}for(let c=0;c<this.events.length;c++){const e=await this.events[c].getErrorsAsync({tracker:r});a.push(...e)}for(let c=0;c<this.variableDeclarations.length;c++){const e=await this.variableDeclarations[c].getErrorsAsync({tracker:r});a.push(...e)}for(let c=0;c<this.variableInstances.length;c++){const e=await this.variableInstances[c].getErrorsAsync({tracker:r});a.push(...e)}for(let c=0;c<this.conditions.length;c++){const e=await this.conditions[c].getErrorsAsync({tracker:r});a.push(...e)}for(let c=0;c<this.operations.length;c++){const e=await this.operations[c].getErrorsAsync({tracker:r});a.push(...e)}for(let c=0;c<this.functionCalls.length;c++){const e=await this.functionCalls[c].getErrorsAsync({tracker:r});a.push(...e)}for(let c=0;c<this.loops.length;c++){const e=await this.loops[c].getErrorsAsync({tracker:r});a.push(...e)}for(let c=0;c<this.searches.length;c++){const e=await this.searches[c].getErrorsAsync({tracker:r});a.push(...e)}return a}getShallowErrors(){return this.errors}clone(){return this}addDefinitionEntity(i){return this.entities.includes(i)||this.entities.push(i),i}addFunctionDeclaration(i){return this.functions.includes(i)||this.functions.push(i),i}addFunctionCall(i){return this.functionCalls.includes(i)||this.functionCalls.push(i),i}addVariableDeclaration(i){return this.variableDeclarations.includes(i)||this.variableDeclarations.push(i),i}addVariableInstance(i){return this.variableInstances.includes(i)||this.variableInstances.push(i),i}addInstalledProject(i){return this.projects.includes(i)||this.projects.push(i),this}addGlobalEvent(i){return this.events.includes(i)||this.events.push(i),this}addCondition(i){return this.conditions.includes(i)||this.conditions.push(i),this}addOperation(i){return this.operations.includes(i)||this.operations.push(i),this}addLoop(i){return this.loops.includes(i)||this.loops.push(i),this}addSearch(i){return this.searches.includes(i)||this.searches.push(i),this}removeDefinitionEntity(i){const r=this.entities.findIndex(a=>a.id===i.id);if(r>-1){const a=this.entities[r];return this.entities.splice(r,1),a}return null}removeCondition(i){const r=this.conditions.findIndex(a=>a.id===i.id);if(r>-1){const a=this.conditions[r];return this.conditions.splice(r,1),a}return null}removeOperation(i){const r=this.operations.findIndex(a=>a.id===i.id);if(r>-1){const a=this.operations[r];return this.operations.splice(r,1),a}return null}removeLoop(i){const r=this.loops.findIndex(a=>a.id===i.id);if(r>-1){const a=this.loops[r];return this.loops.splice(r,1),a}return null}removeSearch(i){const r=this.searches.findIndex(a=>a.id===i.id);if(r>-1){const a=this.searches[r];return this.searches.splice(r,1),a}return null}removeFunctionCall(i){const r=this.functionCalls.findIndex(a=>a.id===i.id);if(r>-1){const a=this.functionCalls[r];return this.functionCalls.splice(r,1),a}return null}removeVariableInstance(i){const r=this.variableInstances.findIndex(a=>a.id===i.id);if(r>-1){const a=this.variableInstances[r];return this.variableInstances.splice(r,1),a}return null}removeVariableDeclaration(i){const r=this.variableDeclarations.findIndex(a=>a.id===i.id);if(r>-1){const a=this.variableDeclarations[r];return this.variableDeclarations.splice(r,1),a}return null}removeFunctionDeclaration(i){const r=this.functions.findIndex(a=>a.id===i.id);if(r>-1){const a=this.functions[r];return this.functions.splice(r,1),a}return null}removeInstalledProject(i){const r=this.projects.findIndex(a=>a.id===i.id);if(r>-1){const a=this.projects[r];return this.projects.splice(r,1),a}return null}removeGlobalEvent(i){const r=this.events.findIndex(a=>a.id===i.id);if(r>-1){const a=this.events[r];return this.events.splice(r,1),a}return null}removeTopLevelVariableDeclaration(i){if(i.type!==d.VariableDeclaration)return null;const r=this.variableDeclarations.findIndex(a=>a.id===i.id);if(r>-1){const a=this.variableDeclarations[r];return this.variableDeclarations.splice(r,1),a}return null}getEntryPoints(){return[...this.functions,...this.events,...this.entities.flatMap(r=>r.methods)]}getTerminationStatements(){return[...this.getEntryPoints().reduce((r,a)=>{const c=pt(a);return[...r,...c.filter(e=>e.type===d.ReturnStatement||e.type===d.ContinueStatement||e.type===d.BreakStatement)]},[])]}getFunctionDeclaration(i){return this.functions.find(r=>r.id===i)||null}getConditions(){return[...this.conditions,...this.getEntryPoints().reduce((r,a)=>{const c=pt(a);return[...r,...c.filter(e=>e.type===d.Condition)]},[]),...this.functionCalls.reduce((r,a)=>{const c=pt(a);return[...r,...c.filter(e=>e.type===d.Condition)]},[]),...this.operations.reduce((r,a)=>{const c=pt(a);return[...r,...c.filter(e=>e.type===d.Condition)]},[]),...this.loops.reduce((r,a)=>{const c=pt(a);return[...r,...c.filter(e=>e.type===d.Condition)]},[]),...this.searches.reduce((r,a)=>{const c=pt(a);return[...r,...c.filter(e=>e.type===d.Condition)]},[])]}getOperations(){return[...this.operations,...this.getEntryPoints().reduce((r,a)=>{const c=pt(a);return[...r,...c.filter(e=>e.type===d.Operation)]},[]),...this.functionCalls.reduce((r,a)=>{const c=pt(a);return[...r,...c.filter(e=>e.type===d.Operation)]},[]),...this.conditions.reduce((r,a)=>{const c=pt(a);return[...r,...c.filter(e=>e.type===d.Operation)]},[]),...this.loops.reduce((r,a)=>{const c=pt(a);return[...r,...c.filter(e=>e.type===d.Operation)]},[]),...this.searches.reduce((r,a)=>{const c=pt(a);return[...r,...c.filter(e=>e.type===d.Operation)]},[])]}getFunctionCalls(){return[...this.functionCalls,...this.getEntryPoints().reduce((r,a)=>{const c=pt(a);return[...r,...c.filter(e=>e.type===d.FunctionCall)]},[]),...this.conditions.reduce((r,a)=>{const c=pt(a);return[...r,...c.filter(e=>e.type===d.FunctionCall)]},[]),...this.operations.reduce((r,a)=>{const c=pt(a);return[...r,...c.filter(e=>e.type===d.FunctionCall)]},[]),...this.loops.reduce((r,a)=>{const c=pt(a);return[...r,...c.filter(e=>e.type===d.FunctionCall)]},[]),...this.searches.reduce((r,a)=>{const c=pt(a);return[...r,...c.filter(e=>e.type===d.FunctionCall)]},[])]}getDefinitionEntities(i=new Set){return Array.from(this.subscribedDefinitionEntities).filter(a=>!i.has(a)).map(a=>this.get(a))}getVariables(){return[...this.variableDeclarations,...this.getEntryPoints().reduce((r,a)=>{const c=lr(a);return[...r,...c]},[]),...this.functionCalls.reduce((r,a)=>{const c=lr(a);return[...r,...c]},[]),...this.conditions.reduce((r,a)=>{const c=lr(a);return[...r,...c]},[]),...this.operations.reduce((r,a)=>{const c=lr(a);return[...r,...c]},[]),...this.loops.reduce((r,a)=>{const c=lr(a);return[...r,...c]},[]),...this.searches.reduce((r,a)=>{const c=lr(a);return[...r,...c]},[])]}getVariableInstances(){return[...this.variableInstances,...this.entities.reduce((r,a)=>[...r,...a.methods.flatMap(c=>{const f=pt(c).filter(h=>h.type===d.VariableInstance);return[...r,...f]})],[]),...this.getEntryPoints().reduce((r,a)=>{const e=lr(a).filter(f=>f.type===d.VariableInstance);return[...r,...e]},[]),...this.functionCalls.reduce((r,a)=>{const e=lr(a).filter(f=>f.type===d.VariableInstance);return[...r,...e]},[]),...this.conditions.reduce((r,a)=>{const e=lr(a).filter(f=>f.type===d.VariableInstance);return[...r,...e]},[]),...this.operations.reduce((r,a)=>{const e=lr(a).filter(f=>f.type===d.VariableInstance);return[...r,...e]},[]),...this.loops.reduce((r,a)=>{const e=lr(a).filter(f=>f.type===d.VariableInstance);return[...r,...e]},[]),...this.searches.reduce((r,a)=>{const e=lr(a).filter(f=>f.type===d.VariableInstance);return[...r,...e]},[])]}getVariableDeclarations(){return C([...this.variableDeclarations,...this.entities.reduce((r,a)=>[...r,...a.methods.flatMap(c=>{const f=pt(c).filter(h=>h.type===d.VariableDeclaration);return[...r,...f]})],[]),...this.getEntryPoints().reduce((r,a)=>{const e=lr(a).filter(f=>f.type===d.VariableDeclaration);return[...r,...e]},[]),...this.functionCalls.reduce((r,a)=>{const e=lr(a).filter(f=>f.type===d.VariableDeclaration);return[...r,...e]},[]),...this.conditions.reduce((r,a)=>{const e=lr(a).filter(f=>f.type===d.VariableDeclaration);return[...r,...e]},[]),...this.operations.reduce((r,a)=>{const e=lr(a).filter(f=>f.type===d.VariableDeclaration);return[...r,...e]},[]),...this.loops.reduce((r,a)=>{const e=lr(a).filter(f=>f.type===d.VariableDeclaration);return[...r,...e]},[]),...this.searches.reduce((r,a)=>{const e=lr(a).filter(f=>f.type===d.VariableDeclaration);return[...r,...e]},[])])}getLoops(){return[...this.loops,...this.getEntryPoints().reduce((r,a)=>{const c=pt(a);return[...r,...c.filter(e=>e.type===d.Loop)]},[]),...this.functionCalls.reduce((r,a)=>{const c=pt(a);return[...r,...c.filter(e=>e.type===d.Loop)]},[]),...this.conditions.reduce((r,a)=>{const c=pt(a);return[...r,...c.filter(e=>e.type===d.Loop)]},[]),...this.operations.reduce((r,a)=>{const c=pt(a);return[...r,...c.filter(e=>e.type===d.Loop)]},[]),...this.searches.reduce((r,a)=>{const c=pt(a);return[...r,...c.filter(e=>e.type===d.Loop)]},[])]}getSearches(){return[...this.searches,...this.getEntryPoints().reduce((r,a)=>{const c=pt(a);return[...r,...c.filter(e=>e.type===d.Search)]},[]),...this.functionCalls.reduce((r,a)=>{const c=pt(a);return[...r,...c.filter(e=>e.type===d.Search)]},[]),...this.conditions.reduce((r,a)=>{const c=pt(a);return[...r,...c.filter(e=>e.type===d.Search)]},[]),...this.operations.reduce((r,a)=>{const c=pt(a);return[...r,...c.filter(e=>e.type===d.Search)]},[]),...this.loops.reduce((r,a)=>{const c=pt(a);return[...r,...c.filter(e=>e.type===d.Search)]},[])]}attachOrphanReferences(){const i=this.getVariableInstances(),r=this.getVariableDeclarations();return i.forEach(a=>{if(!a.declaration){const c=a.initialData,e=c.declaration.entityId||c.declaration.id,f=r.find(h=>h.id===e);f&&a.setDeclaration(f)}}),this}getBuiltInPersistedEntity(){return this.builtInBaseEntities.find(i=>i.name===Ie.PERSISTED_ENTITY)||null}requestActiveDynamicValue(i,r=!1){var c,e;const a=(e=(c=this.parentContext).requestActiveDynamicValue)==null?void 0:e.call(c,i,r);if(!a&&ig.includes(i.type)){const f=i.getDefaultValue();return f?{value:f,type:Me.DefaultValue,inheritanceLink:null,valueOwner:i}:null}return a||null}requestExtension(i){if(this.parentContext.requestExtension){const r=this.parentContext.requestExtension(i);if(r&&!r.module)throw new Error(`Module ${i} is not registered properly.`);return r.module||null}return null}undo(){Y.Logger.log("Undoing, from: ",this.undoableStackValueIndex),this.undoableStackValueIndex=this.undoableStackValueIndex-1,Y.Logger.log("To: ",this.undoableStackValueIndex);const i=this.history[this.undoableStackValueIndex+1],r=this.history[this.undoableStackValueIndex];return Y.Logger.log("Current change set: ",i==null?void 0:i.toJSON()),Y.Logger.log("Change set to restore: ",r==null?void 0:r.toJSON()),b_(i||"initial",r||"initial",this)}redo(){Y.Logger.log("Undoing, from: ",this.undoableStackValueIndex),this.undoableStackValueIndex=this.undoableStackValueIndex+1,Y.Logger.log("To: ",this.undoableStackValueIndex);const i=this.history[this.undoableStackValueIndex-1],r=this.history[this.undoableStackValueIndex];return Y.Logger.log("Current change set: ",i==null?void 0:i.toJSON()),Y.Logger.log("Change set to restore: ",r.toJSON()),b_(i||"initial",r||"initial",this)}applyExternalChangeSet(i){const r=i.payload,a=this.addChangeSet(new S(this,i.userAuthor,i.emittedAt,this));a.ignoreNonEditable=!0,a.ignoreNonDeletable=!0;const c=r.updated[this.id];if(!c)throw new Error("Project root not found in change set transfer. Cannot apply changes.");const e={...r.added,...r.updated,...r.removed},f=[...Object.keys(r.added),...Object.keys(r.updated),...Object.keys(r.removed)];f.forEach(m=>{var E;if(!e[m]){Y.Logger.warn(`Entity '${m}' not found in change set transfer. Cannot apply changes.`);const b=(E=this.get(m))==null?void 0:E.toShallowJSON();throw b?Y.Logger.warn("Entity in project: ",b):Y.Logger.warn("Entity not in project"),new Error(`Entity '${m}' not found in change set transfer. Cannot apply changes.`)}});const h=new Bn(c,{allBuiltInEntityIds:this.diggestedBuiltInBaseEntitiesIds});return h.flatRecord=e,h.order=f,h.orderEntities(),Y.Logger.log("All entities: ",h.order.map((m,E)=>`${E+1}: ${e[m].type} - ${m}`).join(`,
|
package/dist/index.js
CHANGED
|
@@ -181477,7 +181477,7 @@ This is likely an incorrect strategy, either the '${this.type}' entity doesn't n
|
|
|
181477
181477
|
const m = f4(this);
|
|
181478
181478
|
if (m.result) {
|
|
181479
181479
|
let _ = !1;
|
|
181480
|
-
if (!
|
|
181480
|
+
if (!f.defaultValue) {
|
|
181481
181481
|
const N = xr.new(r);
|
|
181482
181482
|
N.value = m.value, N.name = m.name, N.parent = f.toReference();
|
|
181483
181483
|
const P = Ae(
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@elyx-code/project-logic-tree",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.6878",
|
|
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",
|