@elyx-code/project-logic-tree 0.0.6691 → 0.0.6692

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -387,7 +387,9 @@ ${go({describe_entity:w})}
387
387
  Alternatively you can update the entity with 'update' action. Or replace it by first removing it and then creating a new one.`}))}E===o.DataType&&(!s.parentRelationType||!(s.parentRelationType===qe.AndDataTypeGroup||s.parentRelationType===qe.OrDataTypeGroup))&&c.push(new De({id:`${i.id}--${ne.InvalidParentRelationType}`,code:ne.InvalidParentRelationType,severity:pe.Error,message:`The entity with id '${i.id}' and type '${i.type}', must have a 'parentRelationType' property set to either 'or-data-type-group' or 'and-data-type-group' when being added as a child to an entity of type 'data-type'.`}))}return{errors:c,modifiedData:s}}get isGroup(){const i=[...this.andChildrenGroup||[],...this.orChildrenGroup||[]];if(i.length>1){let n=0;for(const s of i)if(s.isResolved&&(n++,n>1))return!0}return!1}get isResolved(){return[o.BuiltInBaseEntity,o.ActionDescriptor].includes(this.parent.type)||ku(this.parent)?!0:!(!this.entity&&!this.isGroup&&!this.foreignKeyRef&&!this.foreignKeyAllowed)}validateGeneratedUpdate(i){return{errors:[],modifiedData:i}}subscribeDependents(i){return i.forEach(n=>{this.detachedDependents[n.entity.id]||(this.detachedDependents[n.entity.id]=n)}),this}unsubscribeDependents(i){return i.forEach(n=>{this.detachedDependents[n.entity.id]&&delete this.detachedDependents[n.entity.id]}),this}syncDependents(i=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,"sync-dependents"))){const n=[],s=[],c=[],e=[];return Object.values(this.detachedDependents).forEach(y=>{const m=y.entity.afterAllChildrenInitialized(i);n.push(...m.updated),s.push(...m.added),c.push(...m.removed),e.push(...m.affected)}),i==null||i.attemptAutoclose("sync-dependents",this.id),{updated:D(n),added:D(s),removed:D(c),affected:D(e),self:this}}onDetachedDependencyRemoved(i,n,s){const c=[],e=[],y=[],m=[];return n==="entity-field"&&this.setEntity(null,s),n==="foreign-key-ref-field"&&this.setForeignKeyRef(null,s),{updated:D(c),added:D(e),removed:D(y),affected:D(m),self:this}}onDetachedDependencyRestored(i,n,s){const c=[],e=[],y=[],m=[];return n==="entity-field"&&this.setEntity(i,s),n==="foreign-key-ref-field"&&this.setForeignKeyRef(i,s),{updated:D(c),added:D(e),removed:D(y),affected:D(m),self:this}}unsubscribeFromDependencies(){var i,n,s,c;return(n=(i=this.entity)==null?void 0:i.unsubscribeDependents)==null||n.call(i,[{entity:this,field:"entity-field"}]),(c=(s=this.foreignKeyRef)==null?void 0:s.unsubscribeDependents)==null||c.call(s,[{entity:this,field:"foreign-key-ref-field"}]),this}subscribeToDependencies(){var i,n,s,c;return(n=(i=this.entity)==null?void 0:i.subscribeDependents)==null||n.call(i,[{entity:this,field:"entity-field"}]),(c=(s=this.foreignKeyRef)==null?void 0:s.subscribeDependents)==null||c.call(s,[{entity:this,field:"foreign-key-ref-field"}]),this}increaseVersion(i){if(i&&!M(i).isValid())throw new Error(`The shared timestamp '${i}' is not a valid ISO 8601 date string.`);return i&&M(i).isSame(M(this.createdAt))?this:(this.previousVersion=this.version,this.version=x.UUID.uuid(),this.createdAt=M(i).toISOString()||M().toISOString(),this)}captureVersion(){var n;const i=((n=this.knownVersions)==null?void 0:n.get(this.version))||new Ei(this,this.project);return i.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,i):new Map([[this.version,i]]),i.entity=this.entity,i.foreignKeyRef=this.foreignKeyRef,i.andChildrenGroup=this.andChildrenGroup?[...this.andChildrenGroup]:this.andChildrenGroup,i.orChildrenGroup=this.orChildrenGroup?[...this.orChildrenGroup]:this.orChildrenGroup,i.parent=this.parent,this}recursiveCaptureUpstreamVersions(i){const n=[],s=[],c=[],e=[];if(this.parent&&this.parent.type!==o.BuiltInBaseEntity){this.parent.increaseVersion(i);const y=this.parent.recursiveCaptureUpstreamVersions(i);n.push(this.parent,...y.updated),s.push(...y.added),c.push(...y.removed)}return{updated:D(n),added:D(s),removed:D(c),affected:D(e),self:this}}async restoreVersion(i){var m;const n=[],s=[],c=[],e=[];if(this.version===i)return{updated:D(n),added:D(s),removed:D(c),affected:D(e),self:this};if(!this.knownVersions){const v=new Map;for(const[E,b]of this.knownVersions||new Map){if(v.set(E,b),b.activeVersion=!1,b.knownVersions)for(const[w,P]of b.knownVersions)v.set(w,P);b.knownVersions=null}}let y=(m=this.knownVersions)==null?void 0:m.get(i);if(!y){const v=await this.APILoadVersion({},i);if(!v)throw new Error(`Version with id '${i}' for entity with id '${this.id}' not found.`);y=new Ei(v,this.project)}return this.metaSync(y.toShallowJSON(),null),this.previousVersion=y.previousVersion,this.version=y.version,this.createdAt=y.createdAt,this.author=y.author,this.deleted=y.deleted,this.entity=y.entity,this.foreignKeyRef=y.foreignKeyRef,this.andChildrenGroup=y.andChildrenGroup?[...y.andChildrenGroup]:null,this.orChildrenGroup=y.orChildrenGroup?[...y.orChildrenGroup]:null,this.parent=y.parent,{updated:D(n),added:D(s),removed:D(c),affected:D(e),self:this}}updateWithShallowTransfer(i,n=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,_.UpdateWithShallowTransfer))){var s,c;if(!this.checkCanEdit(this,n))return J.Logger.warn(`[updateWithShallowTransfer] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),n==null||n.attemptAutoclose(_.UpdateWithShallowTransfer,this.id),this;if(this.metaSync(i,n),this.version=i.version,this.createdAt=i.createdAt,this.author=i.author,this.deleted=i.deleted,this.previousVersion=i.previousVersion,this.unsubscribeFromDependencies(),i.parent){const e=re(i.parent),y=this.project.get(e),m=this.parent;if(m&&m.id!==(y==null?void 0:y.id)&&this.removeFromParent(n),y)this.setParent(y,n),this.addSelfToProject(n);else throw n==null||n.attemptAutoclose(_.UpdateWithShallowTransfer,this.id),new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${e}' that isn't found in the project`)}else throw n==null||n.attemptAutoclose(_.UpdateWithShallowTransfer,this.id),new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(i.entity){const e=re(i.entity),y=this.project.get(e);y&&(y.type===o.DefinitionEntity&&y.parent===this||this.setEntity(y,n))}else this.setEntity(null,n);if(i.foreignKeyRef){const e=re(i.foreignKeyRef),y=this.project.get(e);y&&this.setForeignKeyRef(y,n)}else this.setForeignKeyRef(null,n);return(s=i.andChildrenGroup)==null||s.forEach(e=>{const y=re(e),m=this.project.get(y);m&&(this.addToAndGroup(m,n),m.setParent(this,n))}),[...this.andChildrenGroup||[]].forEach(e=>{var m;((m=i.andChildrenGroup)==null?void 0:m.find(v=>re(v)===e.id))||(this.removeChildGroup(e,n),e.removeFromParent(n))}),(c=i.orChildrenGroup)==null||c.forEach(e=>{const y=re(e),m=this.project.get(y);m&&(this.addToOrGroup(m,n),m.setParent(this,n))}),[...this.orChildrenGroup||[]].forEach(e=>{var m;((m=i.orChildrenGroup)==null?void 0:m.find(v=>re(v)===e.id))||(this.removeChildGroup(e,n),e.removeFromParent(n))}),this.captureVersion(),this.subscribeToDependencies(),n==null||n.attemptAutoclose(_.UpdateWithShallowTransfer,this.id),this}hydrateAncestors(){const i=[],n=[],s=[],c=[];if(this.initialData.parent){const e=re(this.initialData.parent),y=this.project.get(e);if(y)this.setParent(y,null),i.push(y);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${e}' that isn't found in the project`)}else throw new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(this.initialData.entity){const e=re(this.initialData.entity),y=this.project.get(e);y&&(y.type===o.DefinitionEntity&&y.parent===this||(this.setEntity(y,null),y.type!==o.BuiltInBaseEntity&&y.type!==o.PrimitiveEntity&&i.push(y)))}if(this.initialData.foreignKeyRef){const e=re(this.initialData.foreignKeyRef),y=this.project.get(e);y&&this.setForeignKeyRef(y,null)}return{updated:D(i),added:D(n),removed:D(s),affected:D(c),self:this}}afterAllChildrenInitialized(i=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,_.AfterAllChildrenInitialized))){var y,m,v;if(!this.checkCanEdit(this,i))return J.Logger.warn(`[afterAllChildrenInitialized] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(_.AfterAllChildrenInitialized,this.id),{updated:[],added:[],removed:[],affected:[],self:this};const n=[],s=[],c=[],e=[];if(this.initialized=!0,((y=this.parent)==null?void 0:y.type)===o.DataType){let E=this.index||0;const b=(this.parentRelationType===qe.AndDataTypeGroup?this.parent.andChildrenGroup||[]:this.parent.orChildrenGroup||[]).filter(P=>!P.deleted&&P.id!==this.id);b.length&&(E>b.length+1?E=b.length:E<0&&(E=0)),b.find(P=>(P.index||0)===E&&!P.deleted)&&b.filter(P=>(P.index||0)>=E&&!P.deleted).forEach(P=>{P.metaSync({index:(P.index||0)+1},i),i==null||i.add(P,Z.Updated),n.push(P)}),this.metaSync({index:E},i)}return(m=this.andChildrenGroup)!=null&&m.length&&this.andChildrenGroup.sort((E,b)=>(E.index||0)-(b.index||0)),(v=this.orChildrenGroup)!=null&&v.length&&this.orChildrenGroup.sort((E,b)=>(E.index||0)-(b.index||0)),this.captureVersion(),i==null||i.attemptAutoclose(_.AfterAllChildrenInitialized,this.id),{updated:D(n),added:D(s),removed:D(c),affected:D(e),self:this}}addSelfToProject(i=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,"add-self-to-project"))){const n=[this],s=[],c=[],e=[];return this.parent.type===o.DataType?(this.parentRelationType===qe.AndDataTypeGroup?this.parent.addToAndGroup(this,i):this.parentRelationType===qe.OrDataTypeGroup&&this.parent.addToOrGroup(this,i),e.push(this.parent)):this.parent.type===o.DefinitionEntity?(this.parent.setAdditionalPropertiesDataType(this,i),e.push(this.parent)):this.parent.type!==o.BuiltInBaseEntity&&this.parent.setDataType(this,i),this.subscribe(),this.subscribeToDependencies(),i==null||i.attemptAutoclose("add-self-to-project",this.id),{updated:D(n),added:D(s),removed:D(c),affected:D(e),self:this}}setParent(i,n=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,_.SetParent))){var s;return this.checkCanEditWithCounterpartAndSideEffects(this,i,_.SetParent,n)?(((s=this.parent)==null?void 0:s.id)!==(i==null?void 0:i.id)&&(this.parent=i,n&&(n==null||n.add(this,Z.Updated))),n==null||n.attemptAutoclose(_.SetParent,this.id),this):this}removeChildGroup(i,n=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,_.RemoveChildGroup))){if(!this.checkCanEdit(this,n))return J.Logger.warn(`[removeChildGroup] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),n==null||n.attemptAutoclose(_.RemoveChildGroup,this.id),this;if(this.andChildrenGroup){const s=this.andChildrenGroup.findIndex(c=>c.id===i.id);s!==-1&&(this.andChildrenGroup.splice(s,1),n==null||n.add(this,Z.Updated))}if(this.orChildrenGroup){const s=this.orChildrenGroup.findIndex(c=>c.id===i.id);s!==-1&&(this.orChildrenGroup.splice(s,1),n==null||n.add(this,Z.Updated))}return n==null||n.attemptAutoclose(_.RemoveChildGroup,this.id),this}initChildren(i=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,"init-children"))){var n,s,c,e,y,m,v,E,b,w;if(this.initialized||this.startedInitialization)return this;if(this.startedInitialization=!0,this.initialData.entity)if(this.initialData.entity.type===o.GenericReference){const P=this.project.findSubscribedInstanceFromReference(this.initialData.entity);this.entity=P}else this.entity=ye(this.initialData.entity,this.project),(((s=(n=this.initialData.entity)==null?void 0:n.parent)==null?void 0:s.id)===this.id||((e=(c=this.initialData.entity)==null?void 0:c.parent)==null?void 0:e.type)===o.GenericReference&&((m=(y=this.initialData.entity)==null?void 0:y.parent)==null?void 0:m.entityId)==this.id)&&this.entity.setParent(this,null),(E=(v=this.entity).initChildren)==null||E.call(v,i);if(this.initialData.foreignKeyRef)if(this.initialData.foreignKeyRef.type===o.GenericReference){const P=this.project.findSubscribedInstanceFromReference(this.initialData.foreignKeyRef);this.foreignKeyRef=P}else this.foreignKeyRef=ye(this.initialData.foreignKeyRef,this.project),(w=(b=this.foreignKeyRef).initChildren)==null||w.call(b,i);return this.initialData.andChildrenGroup&&(this.andChildrenGroup=this.initialData.andChildrenGroup.map(P=>{const $=ye(P,this.project);return $.setParent(this,null),$.initChildren(i),$})),this.initialData.orChildrenGroup&&(this.orChildrenGroup=this.initialData.orChildrenGroup.map(P=>{const $=ye(P,this.project);return $.setParent(this,null),$.initChildren(i),$})),this.subscribeToDependencies(),this.afterAllChildrenInitialized(i),i==null||i.attemptAutoclose("init-children",this.id),this}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(i,n=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,"meta-sync"))){const s=$r(this,i,n),c=xr(this,s),e=this.toMeta();return this.options=s.options||e.options,this.parentRelationType=s.parentRelationType||e.parentRelationType,this.isList=s.isList!==void 0?s.isList:e.isList,this.inferred=s.inferred!==void 0?s.inferred:e.inferred,this.like=s.like!==void 0?s.like:e.like,this.asType=s.asType!==void 0?s.asType:e.asType,this.index=s.index!==void 0?s.index:e.index,this.implementationChooseOne=s.implementationChooseOne!==void 0?s.implementationChooseOne:e.implementationChooseOne,this.staticEntities=s.staticEntities!==void 0?s.staticEntities:e.staticEntities,this.interactiveEntities=s.interactiveEntities!==void 0?s.interactiveEntities:e.interactiveEntities,this.actionEntities=s.actionEntities!==void 0?s.actionEntities:e.actionEntities,super.baseMetaSync(s,this,n),s.deleted===!0&&!e.deleted?n==null||n.add(this,Z.Removed):s.deleted===!1&&e.deleted?n==null||n.add(this,Z.Added):c&&(n==null||n.add(this,Z.Updated)),n==null||n.attemptAutoclose("meta-sync",this.id),this}async APILoad(i=Ge,...n){return await Ei.repository.APILoad(this.id,...n),this}async APICreate(i=Ge,...n){return await Ei.repository.APICreate(this.toShallowJSON(),...n),this}async APIUpdate(i=Ge,...n){return await Ei.repository.APIUpdate(this.toShallowJSON(),...n),this}async APIDelete(i=Ge,...n){return await Ei.repository.APIDelete(this.toShallowJSON(),...n),this}async APIClone(i=Ge,...n){return await Ei.repository.APIClone(this.id,...n),this}async APILoadVersion(i=Ge,n,...s){return await Ei.repository.APILoadVersion(this.id,n,...s)}removeFromParent(i=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,_.RemoveFromParent))){var y,m;if(!this.checkCanEdit(this,i))return J.Logger.warn(`[removeFromParent] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(_.RemoveFromParent,this.id),{added:[],updated:[],removed:[],affected:[],self:this};const n=[],s=[],c=[],e=[];if(((y=this.parent)==null?void 0:y.type)===o.DataType)this.parent.removeChildGroup(this,i);else if(((m=this.parent)==null?void 0:m.type)===o.DefinitionEntity)this.parent.removeAdditionalPropertiesDataType(i);else{const v=this.parent;v==null||v.removeDataType(i)}return this.parent&&this.parent.type!==o.BuiltInBaseEntity&&n.push(this.parent),i==null||i.attemptAutoclose(_.RemoveFromParent,this.id),{added:D(c),updated:D(n),removed:D(s),affected:D(e),self:this}}remove({ignoreUpstream:i}={ignoreUpstream:!1},n=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,_.RemoveEntity))){const s=[],c=[],e=[],y=[];if(n!=null&&n.hasRemoved(this.id))return n==null||n.attemptAutoclose(_.RemoveEntity,this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(c.push(this),this.unsubscribe(),this.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},n),Object.values(this.detachedDependents).forEach(m=>{const{updated:v,removed:E,added:b}=m.entity.onDetachedDependencyRemoved(this,m.field,n);s.push(...v),c.push(...E),e.push(...b)}),this.entity&&this.entity.type===o.DefinitionEntity&&this.entity.parent===this){const{updated:m,removed:v}=this.entity.remove({ignoreUpstream:!0},n);s.push(...m),c.push(...v)}if(this.andChildrenGroup&&this.andChildrenGroup.forEach(m=>{const{removed:v,updated:E}=m.remove({ignoreUpstream:!0},n);c.push(...v),s.push(...E)}),this.orChildrenGroup&&this.orChildrenGroup.forEach(m=>{const{removed:v,updated:E}=m.remove({ignoreUpstream:!0},n);c.push(...v),s.push(...E)}),!i){const m=this.removeFromParent(n);e.push(...m.added),s.push(...m.updated),c.push(...m.removed),y.push(...m.affected)}return n==null||n.attemptAutoclose(_.RemoveEntity,this.id),{added:D(e),updated:D(s),removed:D(c),affected:D(y),self:this}}restore({}={},i=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,_.RestoreEntity))){if(!this.checkCanEdit(this,i))return J.Logger.warn(`[restore] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(_.RestoreEntity,this.id),{added:[],updated:[],removed:[],affected:[],self:this};const n=[],s=[],c=[],e=[];if(i!=null&&i.hasAdded(this.id))return i==null||i.attemptAutoclose(_.RestoreEntity,this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},i),Object.values(this.detachedDependents).forEach(y=>{const{updated:m,removed:v,added:E}=y.entity.onDetachedDependencyRestored(this,y.field,i);s.push(...m),c.push(...v),n.push(...E)}),this.entity&&this.entity.type===o.DefinitionEntity&&this.entity.parent===this){const{updated:y}=this.entity.restore({},i);s.push(...y)}if(this.andChildrenGroup&&this.andChildrenGroup.forEach(y=>{const{updated:m,added:v}=y.restore({},i);s.push(...m),n.push(...v)}),this.orChildrenGroup&&this.orChildrenGroup.forEach(y=>{const{updated:m,added:v}=y.restore({},i);s.push(...m),n.push(...v)}),this.parent.type===o.DataType){const y=this.parent;Array.isArray(y.andChildrenGroup)&&y.andChildrenGroup.push(this)}if(this.parent.type===o.DataType){const y=this.parent;this.parentRelationType===qe.AndDataTypeGroup?Array.isArray(y.andChildrenGroup)&&y.andChildrenGroup.push(this):this.parentRelationType===qe.OrDataTypeGroup&&Array.isArray(y.orChildrenGroup)&&y.orChildrenGroup.push(this)}else if(this.parent.type===o.DefinitionEntity){const y=this.parent;y.setAdditionalPropertiesDataType(this,i),s.push(y)}else{const y=this.parent;y.setDataType(this,i),s.push(y)}return i==null||i.attemptAutoclose(_.RestoreEntity,this.id),{added:D(n),updated:D(s),removed:D(c),affected:D(e),self:this}}toFlat(i=new Set){var s,c,e,y;return i.has(this.id)?[]:(i.add(this.id),[this,...((s=this.andChildrenGroup)==null?void 0:s.flatMap(m=>m.toFlat(i)))||[],...((c=this.orChildrenGroup)==null?void 0:c.flatMap(m=>m.toFlat(i)))||[],...((e=this.entity)==null?void 0:e.toFlat(i))||[],...((y=this.foreignKeyRef)==null?void 0:y.toFlat(i))||[]])}toFlatIds(i=new Set){var s,c,e,y;return i.has(this.id)?[]:(i.add(this.id),[this.id,...((s=this.andChildrenGroup)==null?void 0:s.flatMap(m=>m.toFlatIds(i)))||[],...((c=this.orChildrenGroup)==null?void 0:c.flatMap(m=>m.toFlatIds(i)))||[],...((e=this.entity)==null?void 0:e.toFlatIds(i))||[],...((y=this.foreignKeyRef)==null?void 0:y.toFlatIds(i))||[]])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,like:this.like,isList:this.isList,inferred:this.inferred,index:this.index,foreignKeyAllowed:this.foreignKeyAllowed,parentRelationType:this.parentRelationType,implementationChooseOne:this.implementationChooseOne,staticEntities:this.staticEntities,interactiveEntities:this.interactiveEntities,actionEntities:this.actionEntities,options:this.options,asType:this.asType,type:this.type,editable:this.editable,deletable:this.deletable}}toJSON(i=new Set){var n,s,c,e,y;return i.has(this.id)?this.toReference():(i.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,editable:this.editable,deletable:this.deletable,options:this.options,isList:this.isList,asType:this.asType,index:this.index,like:this.like,foreignKeyAllowed:this.foreignKeyAllowed,inferred:this.inferred,parentRelationType:this.parentRelationType,implementationChooseOne:this.implementationChooseOne,staticEntities:this.staticEntities,interactiveEntities:this.interactiveEntities,actionEntities:this.actionEntities,foreignKeyRef:((n=this.foreignKeyRef)==null?void 0:n.toJSON(i))||null,andChildrenGroup:((s=this.andChildrenGroup)==null?void 0:s.map(m=>m.toJSON(i)))||null,orChildrenGroup:((c=this.orChildrenGroup)==null?void 0:c.map(m=>m.toJSON(i)))||null,entity:((e=this.entity)==null?void 0:e.parent)===this?this.entity.toJSON(i):((y=this.entity)==null?void 0:y.toReference())||null,parent:this.parent.toReference()})}toJSONClone(i=pt){var s,c,e,y,m,v,E,b,w,P;let n;return(s=i.seenEntityMaps)!=null&&s.has(this.id)?n=i.seenEntityMaps.get(this.id):(n=i.newId||jr(this,this.project,i.uuidStrategy),i.seenEntityMaps&&i.seenEntityMaps.set(this.id,n)),(c=i.seenEntities)!=null&&c.has(n)||(e=i.seenEntities)!=null&&e.has(this.id)?this.toReference({seenEntityMaps:i.seenEntityMaps}):((y=i.seenEntities)==null||y.add(n),(m=i.seenEntities)==null||m.add(this.id),{id:n,version:x.UUID.uuid(),createdAt:i.timestamp||M().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,editable:this.editable,deletable:this.deletable,options:this.options,isList:this.isList,asType:this.asType,like:this.like,index:this.index,inferred:this.inferred,foreignKeyAllowed:this.foreignKeyAllowed,parentRelationType:this.parentRelationType,implementationChooseOne:this.implementationChooseOne,staticEntities:this.staticEntities,interactiveEntities:this.interactiveEntities,actionEntities:this.actionEntities,foreignKeyRef:((v=this.foreignKeyRef)==null?void 0:v.toJSONClone({...i,newId:null}))||null,andChildrenGroup:((E=this.andChildrenGroup)==null?void 0:E.map($=>$.toJSONClone({...i,newId:null})))||null,orChildrenGroup:((b=this.orChildrenGroup)==null?void 0:b.map($=>$.toJSONClone({...i,newId:null})))||null,entity:((w=this.entity)==null?void 0:w.parent)===this?this.entity.toJSONClone({...i,newId:null}):((P=this.entity)==null?void 0:P.toReference({seenEntityMaps:i.seenEntityMaps}))||null,parent:this.parent.toReference({seenEntityMaps:i.seenEntityMaps})})}toReference(i=pt){var s;let n=this.id;return(s=i.seenEntityMaps)!=null&&s.has(this.id)&&(n=i.seenEntityMaps.get(this.id)),{id:n+"--"+x.UUID.uuid()+"--ref",type:o.GenericReference,entityId:n,version:this.version,entityType:this.type}}toShallowJSON(i=pt){var s,c,e,y,m;let n=this.id;return(s=i.seenEntityMaps)!=null&&s.has(this.id)&&(n=i.seenEntityMaps.get(this.id)),{id:n,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,editable:this.editable,deletable:this.deletable,isList:this.isList,options:this.options,asType:this.asType,index:this.index,parentRelationType:this.parentRelationType,like:this.like,inferred:this.inferred,foreignKeyAllowed:this.foreignKeyAllowed,implementationChooseOne:this.implementationChooseOne,staticEntities:this.staticEntities,interactiveEntities:this.interactiveEntities,actionEntities:this.actionEntities,foreignKeyRef:((c=this.foreignKeyRef)==null?void 0:c.toReference(i))||null,andChildrenGroup:((e=this.andChildrenGroup)==null?void 0:e.map(v=>v.toReference(i)))||null,orChildrenGroup:((y=this.orChildrenGroup)==null?void 0:y.map(v=>v.toReference(i)))||null,entity:((m=this.entity)==null?void 0:m.toReference(i))||null,parent:this.parent.toReference(i)}}toFlatJSON(i=new Set){var s,c,e;return i.has(this.id)?[]:(i.add(this.id),[this.toShallowJSON(),...((s=this.andChildrenGroup)==null?void 0:s.flatMap(y=>y.toFlatJSON(i)))||[],...((c=this.orChildrenGroup)==null?void 0:c.flatMap(y=>y.toFlatJSON(i)))||[],...((e=this.entity)==null?void 0:e.toFlatJSON(i))||[]])}toGenerationTarget(){var i,n;return{id:this.id,type:this.type,options:this.options||void 0,isList:this.isList,like:this.like,parentRelationType:this.parentRelationType||void 0,foreignKeyRef:((i=this.foreignKeyRef)==null?void 0:i.id)||null,asType:this.asType,entity:((n=this.entity)==null?void 0:n.id)||null,parent:this.parent.id}}toFlatGenerationTarget(i=new Set){var s,c;return i.has(this.id)?[]:(i.add(this.id),[this.toGenerationTarget(),...((s=this.andChildrenGroup)==null?void 0:s.flatMap(e=>e.toFlatGenerationTarget(i)))||[],...((c=this.orChildrenGroup)==null?void 0:c.flatMap(e=>e.toFlatGenerationTarget(i)))||[],...this.entity&&this.entity.type==o.DefinitionEntity&&this.entity.parent===this&&this.entity.toFlatGenerationTarget(i)||[]])}clearErrors(){var i,n,s,c;return this.errors=[],(i=this.andChildrenGroup)==null||i.forEach(e=>e.clearErrors()),(n=this.orChildrenGroup)==null||n.forEach(e=>e.clearErrors()),this.inferred&&this.entity&&this.entity.type===o.DefinitionEntity&&((s=this.entity)==null?void 0:s.parent)===this&&((c=this.entity)==null||c.clearErrors()),this}validate(){return this.errors=HUe(this),{success:!0}}async validateAsync(i={}){const n=J.YieldTracker.from(i);return this.errors=await ZUe(this,{tracker:n}),{success:!0}}getErrors(){var n,s;return[...this.errors,...((n=this.andChildrenGroup)==null?void 0:n.flatMap(c=>c.getErrors()))||[],...((s=this.orChildrenGroup)==null?void 0:s.flatMap(c=>c.getErrors()))||[]]}async getErrorsAsync(i={}){const n=J.YieldTracker.from(i),s=[...this.errors];await n.tick();for(const c of this.andChildrenGroup||[]){const e=await c.getErrorsAsync({tracker:n});s.push(...e)}for(const c of this.orChildrenGroup||[]){const e=await c.getErrorsAsync({tracker:n});s.push(...e)}return s}getShallowErrors(){return this.errors}clone(i=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,_.CloneEntity)),n=null,s=null,c=!0){var P,$,L,U;const e=Pr(n,this),y=n||this.parent,v={id:s||x.UUID.uuid(),version:x.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||M().toISOString(),author:(i==null?void 0:i.author)||"1",previousVersion:null,deleted:!1,deletable:!0,editable:!0,type:o.DataType,isList:this.isList,asType:this.asType,options:this.options,index:this.index,parentRelationType:this.parentRelationType,staticEntities:this.staticEntities,foreignKeyAllowed:this.foreignKeyAllowed,interactiveEntities:this.interactiveEntities,actionEntities:this.actionEntities,like:this.like,inferred:this.inferred,implementationChooseOne:this.implementationChooseOne,foreignKeyRef:((P=this.foreignKeyRef)==null?void 0:P.toReference())||null,andChildrenGroup:null,orChildrenGroup:null,entity:null,parent:y.toReference()},E=Ui(v,e);E.hydrateAncestors(),E.setParent(y,null),c&&(E.subscribe(),E.addSelfToProject(i)),E.initChildren(i),i==null||i.add(E,Z.Added);const b=($=this.andChildrenGroup)==null?void 0:$.map(K=>this.project.diggestedBuiltInBaseEntitiesIds.has(K.id)?e.getBuiltIn(K.id):K.clone(i,E,x.UUID.uuid(),c)),w=(L=this.orChildrenGroup)==null?void 0:L.map(K=>this.project.diggestedBuiltInBaseEntitiesIds.has(K.id)?e.getBuiltIn(K.id):K.clone(i,E,x.UUID.uuid(),c));if(E.andChildrenGroup=b||null,E.orChildrenGroup=w||null,this.entity&&this.entity.type===o.DefinitionEntity&&((U=this.entity)==null?void 0:U.parent)===this)if(this.project.diggestedBuiltInBaseEntitiesIds.has(this.entity.id))E.setEntity(e.getBuiltIn(this.entity.id),i);else{const K=this.entity.clone(i,E,x.UUID.uuid(),c);E.setEntity(K,i)}else if(this.entity){const K=e.get(this.entity.id)||e.getBuiltIn(this.entity.id);E.setEntity(K,i)}return i==null||i.attemptAutoclose(_.CloneEntity,this.id),E}merge(i,n=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,_.MergeDataTypes))){var m,v,E;const s=[],c=[],e=[],y=[];if(!this.checkCanEdit(this,n))return J.Logger.warn(`[${_.MergeDataTypes}] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),n==null||n.attemptAutoclose(_.MergeDataTypes,this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.asType!==(i==null?void 0:i.asType)&&(this.metaSync({asType:i==null?void 0:i.asType},n),n==null||n.add(this,Z.Updated),s.push(this)),this.index!==(i==null?void 0:i.index)&&(this.metaSync({index:i==null?void 0:i.index},n),n==null||n.add(this,Z.Updated),s.push(this)),this.options!==(i==null?void 0:i.options)&&(this.metaSync({options:i==null?void 0:i.options},n),n==null||n.add(this,Z.Updated),s.push(this)),this.foreignKeyAllowed!==(i==null?void 0:i.foreignKeyAllowed)&&(this.metaSync({foreignKeyAllowed:i==null?void 0:i.foreignKeyAllowed},n),n==null||n.add(this,Z.Updated),s.push(this)),this.isList!==(i==null?void 0:i.isList)&&(this.metaSync({isList:i==null?void 0:i.isList},n),n==null||n.add(this,Z.Updated),s.push(this)),this.like!==(i==null?void 0:i.like)&&(this.metaSync({like:i==null?void 0:i.like},n),n==null||n.add(this,Z.Updated),s.push(this)),((m=i==null?void 0:i.foreignKeyRef)==null?void 0:m.id)!==((v=this.foreignKeyRef)==null?void 0:v.id)&&(this.setForeignKeyRef((i==null?void 0:i.foreignKeyRef)||null,n),n==null||n.add(this,Z.Updated),s.push(this)),i!=null&&i.entity&&(i==null?void 0:i.entity.type)===o.DefinitionEntity&&(i==null?void 0:i.entity).parent===i)if(((E=this.entity)==null?void 0:E.type)===o.DefinitionEntity&&this.entity.parent===this)Km(this.entity,i.entity)||HN(this.entity,i.entity,n);else{const b=i.entity.clone(n,this,x.UUID.uuid(),!0);this.setEntity(b,n),c.push(b)}else i!=null&&i.entity&&(this.setEntity(i==null?void 0:i.entity,n),n==null||n.add(this,Z.Updated),s.push(this));return this.inferred!==(i==null?void 0:i.inferred)&&this.metaSync({inferred:(i==null?void 0:i.inferred)??!1},n),n==null||n.attemptAutoclose(_.MergeDataTypes,this.id),{updated:D(s),added:D(c),removed:D(e),affected:D(y),self:this}}addToAndGroup(i,n=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,_.AddToAndGroup))){return this.checkCanEdit(this,n)?(this.andChildrenGroup||(this.andChildrenGroup=[]),this.andChildrenGroup.includes(i)||(this.andChildrenGroup.push(i),n==null||n.add(i,Z.Affected)),n==null||n.attemptAutoclose(_.AddToAndGroup,this.id),this):(J.Logger.warn(`[${_.AddToAndGroup}] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),n==null||n.attemptAutoclose(_.AddToAndGroup,this.id),this)}addToOrGroup(i,n=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,_.AddToOrGroup))){return this.checkCanEdit(this,n)?(this.orChildrenGroup||(this.orChildrenGroup=[]),this.orChildrenGroup.includes(i)||(this.orChildrenGroup.push(i),n==null||n.add(i,Z.Affected)),n==null||n.attemptAutoclose(_.AddToOrGroup,this.id),this):(J.Logger.warn(`[${_.AddToOrGroup}] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),n==null||n.attemptAutoclose(_.AddToOrGroup,this.id),this)}setForeignKeyRef(i,n=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,_.SetDataTypeForeignKeyRef))){if(!this.checkCanEdit(this,n))return J.Logger.warn(`[${_.SetDataTypeForeignKeyRef}] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),n==null||n.attemptAutoclose(_.SetDataTypeForeignKeyRef,this.id),this;const s=this.foreignKeyRef;return(s==null?void 0:s.id)!==(i==null?void 0:i.id)&&(this.foreignKeyRef=i,n==null||n.add(this,Z.Updated)),n==null||n.attemptAutoclose(_.SetDataTypeForeignKeyRef,this.id),this}setEntity(i,n=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,_.SetDataTypeEntityValue))){var c;if(!this.checkCanEdit(this,n))return J.Logger.warn(`[${_.SetDataTypeEntityValue}] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),n==null||n.attemptAutoclose(_.SetDataTypeEntityValue,this.id),this;const s=this.entity;return(s==null?void 0:s.id)!==(i==null?void 0:i.id)&&(this.entity=i,n==null||n.add(this,Z.Updated),s&&s.type===o.DefinitionEntity&&((c=s.parent)==null?void 0:c.id)===this.id&&(s==null||s.remove({ignoreUpstream:!0},n))),n==null||n.attemptAutoclose(_.SetDataTypeEntityValue,this.id),this}isObject(){return!!this.entity&&(this.entity.type===o.DefinitionEntity||this.entity.type===o.BuiltInBaseEntity||this.entity.name===oe.KeyValue)&&!this.isList}canBeObject(){var n;let i=!1;if(this.parent.type!==o.DataType&&this.parent.type!==o.ActionDescriptor&&this.parent.type!==o.BuiltInBaseEntity&&this.parent.type!==o.DefinitionEntity&&this.parent.type!==o.FunctionDeclaration){const s=(n=this.project.requestActiveDynamicValue(this.parent))==null?void 0:n.value;s?!s.valueAsType&&(s.value===""||s.value===null||aUi(s))&&(i=!0):i=!0}return(this.isObject()||!this.entity||this.entity.name===oe.Untyped)&&i}hasStrictObjectStructure(){var i;return this.isObject()&&((i=this.entity)==null?void 0:i.type)===o.DefinitionEntity}isInlineDeclaredEntity(){var i,n;return((i=this.entity)==null?void 0:i.type)===o.DefinitionEntity&&((n=this.entity.parent)==null?void 0:n.id)===(this==null?void 0:this.id)}isIndependentlyUserDeclaredEntity(){var i,n;return((i=this.entity)==null?void 0:i.type)===o.DefinitionEntity&&((n=this.entity)==null?void 0:n.parent)!==this}canModifyObjectStructure(){var n;const i=this.isIndependentlyUserDeclaredEntity();return(this.isInlineDeclaredEntity()||this.canBeObject()||((n=this.entity)==null?void 0:n.name)===oe.KeyValue)&&!i}inferFromInputs(i,n=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,"infer-data-type-from-inputs"))){var m;const s=[],c=[],e=[],y=[];if(!this.inferred)return n==null||n.attemptAutoclose("infer-data-type-from-inputs",this.id),{updated:[],added:[],removed:[],affected:[],self:this};if(!this.entity&&i.length){const v=le(this.parent,this.project)+" data type definition",E={id:x.UUID.uuid(),deletable:!0,editable:!0,type:o.DefinitionEntity,version:x.UUID.uuid(),createdAt:(n==null?void 0:n.timestamp)||M().toISOString(),author:x.sessionAuthor,previousVersion:null,deleted:!1,name:v,description:((m=this.parent)==null?void 0:m.description)||null,codeName:null,static:!0,abstract:!1,properties:[],methods:[],extends:null,implements:[],abstractMethods:[],allPropertiesImplement:null,additionalPropertiesDataType:null,additionalProperties:!0,x:0,y:0,parent:this.toReference()},b=ye(E,this.project);b.hydrateAncestors(),b.setParent(this,n),b.initChildren(n),n==null||n.add(b,Z.Added),b.metaSync(E,n),this.setEntity(b,n),n==null||n.add(this,Z.Updated)}if(this.entity){const{updated:v,added:E,removed:b,affected:w}=this.entity.inferFromInputs(i,n);c.push(...v),s.push(...E),e.push(...b),y.push(...w)}return this.like||this.metaSync({like:!0},n),n==null||n.attemptAutoclose("infer-data-type-from-inputs",this.id),{updated:D(c),added:D(s),removed:D(e),affected:D(y),self:this}}};I(Ei,"repository",{APICreate:async(i,...n)=>i,APIUpdate:async(i,...n)=>i,APIDelete:async(i,...n)=>i,APIClone:async(i,...n)=>{},APILoad:async(i,...n)=>null,APILoadVersion:async(i,n,...s)=>null}),I(Ei,"type",o.DataType),I(Ei,"USER_MANAGED_PARENT_TYPES",[o.Property,o.ArgumentDeclaration,o.ReturnStatement,o.BreakStatement,o.ContinueStatement,o.VariableDeclaration,o.ValueDescriptor,o.InputMap,o.OutputMap,o.DataType,o.FunctionDeclaration,o.ActionDescriptor,o.Loop,o.Search,o.DefinitionEntity]),I(Ei,"PARENT_TYPES",[...Ei.USER_MANAGED_PARENT_TYPES,o.BuiltInBaseEntity]),I(Ei,"MUTABLE_BASE_PROPERTIES",["isList","asType","options","foreignKeyAllowed","parentRelationType","like","implementationChooseOne","staticEntities","interactiveEntities","actionEntities"]),I(Ei,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","index","author","previousVersion"]),I(Ei,"BASE_PROPERTIES",[...Ei.MUTABLE_BASE_PROPERTIES,...Ei.INMUTABLE_BASE_PROPERTIES]),I(Ei,"MUTABLE_META_PROPERTIES",[...Ei.MUTABLE_BASE_PROPERTIES,"inferred"]),I(Ei,"INMUTABLE_META_PROPERTIES",[...Ei.INMUTABLE_BASE_PROPERTIES]),I(Ei,"META_PROPERTIES",[...Ei.MUTABLE_META_PROPERTIES,...Ei.INMUTABLE_META_PROPERTIES]),I(Ei,"MUTABLE_UPSTREAM_PROPERTIES",["entity","foreignKeyRef","parent"]),I(Ei,"INMUTABLE_UPSTREAM_PROPERTIES",[]),I(Ei,"UPSTREAM_PROPERTIES",[...Ei.MUTABLE_UPSTREAM_PROPERTIES,...Ei.INMUTABLE_UPSTREAM_PROPERTIES]),I(Ei,"MUTABLE_DOWNSTREAM_PROPERTIES",[]),I(Ei,"INMUTABLE_DOWNSTREAM_PROPERTIES",["andChildrenGroup","orChildrenGroup"]),I(Ei,"DOWNSTREAM_PROPERTIES",[...Ei.MUTABLE_DOWNSTREAM_PROPERTIES,...Ei.INMUTABLE_DOWNSTREAM_PROPERTIES]),I(Ei,"PROPERTIES",[...Ei.META_PROPERTIES,...Ei.UPSTREAM_PROPERTIES,...Ei.DOWNSTREAM_PROPERTIES]);let tr=Ei;async function WUe(d,p={}){var c;const i=J.YieldTracker.from(p),s=[...d.implements.flatMap(e=>Gx(d,e)),...Ds(d),...kx(d)];return await i.tick(),await((c=d.dataType)==null?void 0:c.validateAsync({tracker:i})),s}function zUe(d){var n;const p=d.implements.flatMap(s=>Gx(d,s));return(n=d.dataType)==null||n.validate(),[...p,...Ds(d),...kx(d)]}function Gx(d,p){const i=[];if(!d.implements)return i;if(!p.abstract){const s=$t({id:`${d.id}--${he.PropertyImplementsNonAbstact}`,message:`Property "${le(d,d.project)}" with id "${d.id}" implements a non-abstract property "${le(p,d.project)}" with id "${p.id}".`,severity:pe.Error,code:he.PropertyImplementsNonAbstact,entity:d});i.push(s.error)}if(d.static&&!p.static){const s=$t({id:`${d.id}--${he.NonStaticPropertyImplementsStatic}`,message:`Static property "${le(d,d.project)}" with id "${d.id}" implements a non-static property "${le(p,d.project)}" with id "${p.id}".`,severity:pe.Error,code:he.NonStaticPropertyImplementsStatic,entity:d});i.push(s.error)}if(!d.static&&p.static){const s=$t({id:`${d.id}--${he.StaticPropertyImplementsNonStatic}`,message:`Non-static property "${le(d,d.project)}" with id "${d.id}" implements a static property "${le(p,d.project)}" with id "${p.id}".`,severity:pe.Error,code:he.StaticPropertyImplementsNonStatic,entity:d});i.push(s.error)}if(!zr(d.dataType,p.dataType)){const s=$t({id:`${d.id}--${he.PropertyImplementsIncompatibleType}`,message:`Property "${le(d,d.project)}" with id "${d.id}" implements a property "${le(p,d.project)}" with id "${p.id}" that has an incompatible data type.`,severity:pe.Error,code:he.PropertyImplementsIncompatibleType,entity:d});i.push(s.error)}return Lt(d.errors,i)}function kx(d,p){const n=[...d.parent.allProperties].filter(s=>{var c;return s.id!==d.id&&!d.implements.find(e=>e.id===s.id)&&s.id!==((c=d.extends)==null?void 0:c.id)});return xv(d,[Ji],n,p)}const sUi=Object.freeze(Object.defineProperty({__proto__:null,validate:zUe,validateAsync:WUe,validateImplementation:Gx,validatePropertyEntityName:kx},Symbol.toStringTag,{value:"Module"}));function lUi(d,p){const i=[];if(d.parent){const s=p.get(d.parent);if(!s)i.push(new De({id:`${d.id}--${d.parent}--${ne.ReferencedEntityNotFound}`,code:ne.ReferencedEntityNotFound,severity:pe.Error,message:`Entity of type "${d.type}" with id "${d.id}", is referencing an entity with id "${d.parent}" that isn't yet found in the project. Perhaps it should be created first. Or perhaps the ID is incorrect.`}));else{const c=ku(s);if(c){const e=s!==c?`The entity of type '${d.type}' with id '${d.id}' have 'parent' with id '${d.parent}' because the entity belongs to a built-in '${c.type}' entity with id '${c.id}' (${le(c,s.project)}) higher up in the tree.`:`The entity of type '${d.type}' with id '${d.id}' have 'parent' with id '${d.parent}' because it is a built-in entity of type ${c.type}.`;i.push(new De({id:`${d.id}--${ne.InvalidBuiltInEntityReference}`,code:ne.InvalidBuiltInEntityReference,severity:pe.Error,message:e}))}else if(![o.DefinitionEntity].includes(s.type))i.push(new De({id:`${d.id}--${d.parent}--${ne.InvalidParentReference}`,code:ne.InvalidParentReference,severity:pe.Error,message:`Entity of type "${d.type}" with id "${d.id}", has a parent reference that isn't pointing to an entity of type 'definition-entity'.`}));else{const y=Zn(s).filter(m=>!m.interactive);if(y.length){let m=y.length>1?`The entity of type '${d.type}' with id '${d.id}' can't be added to the 'parent' entity with id '${s.id}' because it extends or implements multiple '${o.BuiltInBaseEntity}' entities that are non-interactive ("${wt(y.map(v=>le(v,v.project)),'", "','" and "')}").`:`The entity of type '${d.type}' with id '${d.id}' can't be added to the 'parent' entity with id '${s.id}' because it extends or implements a '${o.BuiltInBaseEntity}' entity that is non-interactive ("${le(y[0],y[0].project)}").`;m+=`
388
388
  ${Mu}`,i.push(new De({id:`${d.id}--${ne.NonInteractiveEntityReferenced}`,code:ne.NonInteractiveEntityReferenced,severity:pe.Error,message:m}))}else d.implements&&d.implements.forEach(m=>{const v=p.get(m);if(m===d.id)return i.push(new De({id:`${d.id}--${d.implements}--${ne.SelfReference}`,code:ne.SelfReference,severity:pe.Error,message:`Entity of type "${d.type}" with id "${d.id}", has a reference to itself at 'implements'. This is not allowed. Change the reference string or the 'entityId' property of the reference object.`})),i;if(!v)i.push(new De({id:`${d.id}--${d.implements}--${ne.ReferencedEntityNotFound}`,code:ne.ReferencedEntityNotFound,severity:pe.Error,message:`Entity of type "${d.type}" with id "${d.id}", is referencing an entity with id "${d.implements}" that isn't yet found in the project. Perhaps it should be created first. Or perhaps the ID is incorrect.`}));else{const E=s.properties.find(b=>b.implements.find(w=>{var P;return(P=d.implements)==null?void 0:P.includes(w.id)}));E?i.push(new De({id:`${d.id}--${Ie.PropertyOverwritesOtherSiblingWithSameImplementation}`,code:Ie.PropertyOverwritesOtherSiblingWithSameImplementation,severity:pe.Error,message:`The property with id "${d.id}" is trying to implement the property with id "${d.implements}", but the parent entity already has a property with id '${E.id}' that implements the same base property.`})):[o.Property].includes(v.type)?v.abstract||i.push(new De({id:`${d.id}--${d.implements}--${ne.InvalidImplementsReference}`,code:ne.InvalidImplementsReference,severity:pe.Error,message:`Entity of type "${d.type}" with id "${d.id}", has an 'implements' reference that isn't pointing to an abstract entity.`})):i.push(new De({id:`${d.id}--${d.implements}--${ne.InvalidImplementsReference}`,code:ne.InvalidImplementsReference,severity:pe.Error,message:`Entity of type "${d.type}" with id "${d.id}", has an 'implements' reference that isn't pointing to an entity of type 'property'.`}))}})}}}const n=vn(d,{},p);return i.push(...n.errors),i}function oUi(d){return!!d.implements.find(p=>p.id===Q["built-in-base-entity"].BUILT_IN_PERSISTED_ENTITY_ENTITY.properties.database.id)}function Pk(d,p){const i=[],n=[],s=[],c=[];if(d.implements.find(e=>e.id===Q["built-in-base-entity"].BUILT_IN_PERSISTED_ENTITY_ENTITY.properties.database.id)){let e=d.defaultValue;if(!d.defaultValue){const y=Yr.new(p);y.name=oe.EntityTemplate,y.parent=d.toReference();const m=ye(y,d.project);m.hydrateAncestors(),m.addSelfToProject(p),p==null||p.add(m,Z.Added),n.push(m),m.initChildren(p),e=m}if(!e.valueAsTypeSingle){const y=MUe(d.project);y&&e.setValueAsTypeSingle(y,p)}}return{updated:D(i),added:D(n),removed:D(s),affected:D(c),self:d}}var JUe=(d=>(d.PropertyImplements="property-implements-field",d.PropertyExtends="property-extends-field",d.PropertyDataTypeEntity="property-data-type-entity-field",d.PropertyDataType="property-data-type-field",d))(JUe||{});const ti=class ti extends kr{constructor(i,n){super(i);I(this,"initialData");I(this,"id");I(this,"name");I(this,"codeName",null);I(this,"description",null);I(this,"private");I(this,"abstract");I(this,"index");I(this,"static");I(this,"unique");I(this,"required");I(this,"constant",!1);I(this,"interactive",!1);I(this,"type",o.Property);I(this,"hidden",!1);I(this,"parentRelationType",null);I(this,"defaultValue",null);I(this,"dataType",null);I(this,"implements",[]);I(this,"extends",null);I(this,"project");I(this,"errors",[]);I(this,"parent");I(this,"detachedDependents",{});I(this,"knownVersions",null);I(this,"activeVersion",!1);I(this,"initialized",!1);I(this,"startedInitialization",!1);I(this,"suggestion",!1);I(this,"_codeNativeValueValidation",null);this.initialData=i,this.project=n,this.id=i.id,this.name=i.name,this.description=i.description,this.private=i.private,this.abstract=i.abstract,this.index=i.index,this.static=i.static,this.required=i.required||!1,this.unique=i.unique||!1,this.codeName=i.codeName,this.hidden=i.hidden||!1,this.constant=i.constant||!1,this.interactive=i.interactive||!1,this.onProjectInitialized=this.onProjectInitialized.bind(this)}static new(i=null){return{id:x.UUID.uuid(),version:x.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||M().toISOString(),author:(i==null?void 0:i.author)||x.sessionAuthor,previousVersion:null,deleted:!1,deletable:!0,editable:!0,unique:!1,type:o.Property,parentRelationType:null,name:"",codeName:null,description:"",dataType:null,implements:[],extends:null,private:!1,abstract:!1,static:!1,constant:!1,interactive:!0,hidden:!1,index:0,required:!1,defaultValue:null,parent:null}}static fromGenerationTarget(i,n){const s=re(i.parent),c=n.get(s),e=[];i.implements&&i.implements.forEach(E=>{e.push(n.get(E)||n.getBuiltIn(E))});let y=null;if(i.extends){const E=re(i.extends);y=n.get(E)}const m={id:i.id,version:x.UUID.uuid(),createdAt:M().toISOString(),author:x.sessionAuthor,previousVersion:null,deleted:!1,name:i.name,deletable:!0,editable:!0,type:o.Property,index:c.properties.length,unique:i.unique||!1,parentRelationType:i.parentRelationType||null,private:i.private||!1,abstract:i.abstract||!1,static:i.static||!1,required:i.required||!1,constant:i.constant||!1,interactive:i.interactive||!1,hidden:!1,codeName:i.codeName||null,description:i.description||null,defaultValue:null,implements:e,extends:y,dataType:null,parent:c},v=ye(m,n);return v.setParent(c,null),v}static validateGenerationTarget(i,n){let s=JSON.parse(JSON.stringify(i));const c=[],e=lUi(s,n),y=xx(s,n);return c.push(...e,...y,...Nr(s)),{errors:c,modifiedData:s}}get isExtendedProperty(){const i=this.parent.allBasePropertiesFromExtendedAndImplementedEntities.find(n=>{var s;return n.id===((s=this.extends)==null?void 0:s.id)});return!!i&&i.id!==this.id&&!i.abstract}get codeNativeValueValidation(){const i=[...this.implements].filter(s=>!this.implements.filter(y=>y.id!==s.id).some(y=>!!y.implements.find(m=>m.id===s.id)));return this._codeNativeValueValidation||(i==null?void 0:i.some(s=>s.codeNativeValueValidation))?(s,c)=>{const e=[];let y=c;if(this._codeNativeValueValidation){const m=this._codeNativeValueValidation(s,c);m&&(e.push(...m.errors),y=m.override)}return i.forEach(m=>{const v=m.codeNativeValueValidation;if(v){const E=v(s,c);E&&(e.push(...E.errors),y=E.override)}}),{errors:sv(e),override:y}}:null}validateGeneratedUpdate(i){const n=[];return i.parent&&n.push(new De({id:`${this.id}--${ne.InvalidParentUpdate}`,code:ne.InvalidParentUpdate,severity:pe.Error,message:`Entity of type '${this.type}' with id '${this.id}' cannot have the 'parent' property updated, as it would mean moving the '${this.type}' entity to another parent entity.
389
389
  This is likely an incorrect strategy, either the '${this.type}' entity doesn't need to be updated or it should be deleted and a new one created in the desired parent.`})),(i.readsValue||i.writesValue)&&n.push(new De({id:`${this.id}--${Ie.InvalidObjectStructure}`,code:Ie.InvalidObjectStructure,severity:pe.Error,message:`Entity of type '${this.type}' with id '${this.id}' is not a value reading or writing entity.
390
- ${cA}`})),{errors:n,modifiedData:i}}onProjectInitialized(i,n=this.project.addChangeSet(new q(this.project,x.sessionAuthor,new Date().toISOString(),this,!0,"on-property-received-project-initialized"))){return Pk(this,n),n==null||n.attemptAutoclose("on-property-received-project-initialized",this.id),this}subscribeDependents(i){return i.forEach(n=>{this.detachedDependents[n.entity.id]||(this.detachedDependents[n.entity.id]=n)}),this}unsubscribeDependents(i){return i.forEach(n=>{this.detachedDependents[n.entity.id]&&delete this.detachedDependents[n.entity.id]}),this}syncDependents(i=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,"sync-dependents"))){const n=[],s=[],c=[],e=[];return Object.values(this.detachedDependents).forEach(y=>{const m=y.entity.afterAllChildrenInitialized(i);n.push(...m.updated),s.push(...m.added),c.push(...m.removed),e.push(...m.affected)}),i==null||i.attemptAutoclose("sync-dependents",this.id),{updated:D(n),added:D(s),removed:D(c),affected:D(e),self:this}}onDetachedDependencyRemoved(i,n,s){const c=[],e=[],y=[],m=[];if(n==="property-implements-field"&&(this.removeImplementation(i,s),c.push(this)),n==="property-extends-field"){const{updated:v,added:E,removed:b,affected:w}=this.remove({ignoreUpstream:!1},s);c.push(...v),e.push(...E),y.push(...b),m.push(...w)}return{updated:D(c),added:D(e),removed:D(y),affected:D(m),self:this}}onDetachedDependencyRestored(i,n,s){const c=[],e=[],y=[],m=[];if(n==="property-implements-field"&&(this.addImplementation(i,s),c.push(this)),n==="property-extends-field"){const{updated:v,added:E,removed:b,affected:w}=this.restore({},s);c.push(...v),e.push(...E),y.push(...b),m.push(...w)}return{updated:D(c),added:D(e),removed:D(y),affected:D(m),self:this}}unsubscribeFromDependencies(){var i,n,s,c,e,y,m;return this.implements.forEach(v=>{this.project.getBuiltIn(v.id)||v.unsubscribeDependents([{entity:this,field:"property-implements-field"}])}),(n=(i=this.extends)==null?void 0:i.unsubscribeDependents)==null||n.call(i,[{entity:this,field:"property-extends-field"}]),(e=(c=(s=this.dataType)==null?void 0:s.entity)==null?void 0:c.unsubscribeDependents)==null||e.call(c,[{entity:this,field:"property-data-type-entity-field"}]),(m=(y=this.dataType)==null?void 0:y.unsubscribeDependents)==null||m.call(y,[{entity:this,field:"property-data-type-field"}]),this.project.off(ii.PROJECT_INITIALIZED,this.onProjectInitialized),this}subscribeToDependencies(){var i,n,s,c,e,y,m;return this.implements.forEach(v=>{this.project.getBuiltIn(v.id)||v.subscribeDependents([{entity:this,field:"property-implements-field"}])}),(n=(i=this.extends)==null?void 0:i.subscribeDependents)==null||n.call(i,[{entity:this,field:"property-extends-field"}]),(e=(c=(s=this.dataType)==null?void 0:s.entity)==null?void 0:c.subscribeDependents)==null||e.call(c,[{entity:this,field:"property-data-type-entity-field"}]),(m=(y=this.dataType)==null?void 0:y.subscribeDependents)==null||m.call(y,[{entity:this,field:"property-data-type-field"}]),oUi(this)&&this.project.on(ii.PROJECT_INITIALIZED,this.onProjectInitialized),this}increaseVersion(i){if(i&&!M(i).isValid())throw new Error(`The shared timestamp '${i}' is not a valid ISO 8601 date string.`);return i&&M(i).isSame(M(this.createdAt))?this:(this.previousVersion=this.version,this.version=x.UUID.uuid(),this.createdAt=M(i).toISOString()||M().toISOString(),this)}captureVersion(){var n;const i=((n=this.knownVersions)==null?void 0:n.get(this.version))||new ti(this,this.project);return i.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,i):new Map([[this.version,i]]),i.defaultValue=this.defaultValue,i.dataType=this.dataType,i.implements=[...this.implements],i.extends=this.extends,i.parent=this.parent,this}recursiveCaptureUpstreamVersions(i){const n=[],s=[],c=[],e=[];if(this.parent&&this.parent.type!==o.PrimitiveEntity&&this.parent.type!==o.BuiltInBaseEntity){this.parent.increaseVersion(i);const y=this.parent.recursiveCaptureUpstreamVersions(i);n.push(this.parent,...y.updated),s.push(...y.added),c.push(...y.removed)}return{updated:D(n),added:D(s),removed:D(c),affected:D(e),self:this}}async restoreVersion(i){var m;const n=[],s=[],c=[],e=[];if(this.version===i)return{updated:D(n),added:D(s),removed:D(c),affected:D(e),self:this};if(!this.knownVersions){const v=new Map;for(const[E,b]of this.knownVersions||new Map){if(v.set(E,b),b.activeVersion=!1,b.knownVersions)for(const[w,P]of b.knownVersions)v.set(w,P);b.knownVersions=null}}let y=(m=this.knownVersions)==null?void 0:m.get(i);if(!y){const v=await this.APILoadVersion({},i);if(!v)throw new Error(`Version with id '${i}' for entity with id '${this.id}' not found.`);y=new ti(v,this.project)}return this.metaSync(y.toShallowJSON(),null),this.previousVersion=y.previousVersion,this.version=y.version,this.createdAt=y.createdAt,this.author=y.author,this.deleted=y.deleted,this.defaultValue=y.defaultValue,this.dataType=y.dataType,this.implements=[...y.implements],this.parent=y.parent,{updated:D(n),added:D(s),removed:D(c),affected:D(e),self:this}}updateWithShallowTransfer(i,n=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,_.UpdateWithShallowTransfer))){if(!this.checkCanEdit(this,n))return J.Logger.warn(`[updateWithShallowTransfer] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),n==null||n.attemptAutoclose(_.UpdateWithShallowTransfer,this.id),this;if(this.metaSync(i,n),this.version=i.version,this.createdAt=i.createdAt,this.author=i.author,this.deleted=i.deleted,this.previousVersion=i.previousVersion,this.unsubscribeFromDependencies(),i.parent){const c=re(i.parent),e=this.project.get(c),y=this.parent;if(y&&y.id!==(e==null?void 0:e.id)&&this.removeFromParent(n),e)this.setParent(e,n),this.addSelfToProject(n);else throw n==null||n.attemptAutoclose(_.UpdateWithShallowTransfer,this.id),new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${c}' that isn't found in the project`)}else throw n==null||n.attemptAutoclose(_.UpdateWithShallowTransfer,this.id),new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(i.implements.forEach(c=>{const e=re(c),y=this.project.get(e);if(y)this.addImplementation(y,n);else throw new Error(`${Fr(this.type)} with id '${this.id}' has a 'implements' reference "${e}" which is missing in the project`)}),this.implements.filter(c=>{const e=re(c);return!i.implements.find(y=>re(y)===e)}).forEach(c=>{this.removeImplementation(c,n)}),i.extends){const c=re(i.extends),e=this.project.get(c);if(e)this.setExtends(e,n);else if(c)throw new Error(`${Fr(this.type)} with id '${this.id}' has a 'extends' reference "${c}" which is missing in the project`)}else this.setExtends(null,n);if(i.dataType){const c=re(i.dataType),e=this.project.get(c);e&&this.setDataType(e,n)}else this.setDataType(null,n);if(i.defaultValue){const c=re(i.defaultValue),e=this.project.get(c);e&&this.setDefaultValue(e,n)}else this.setDefaultValue(null,n);return this.captureVersion(),this.subscribeToDependencies(),n==null||n.attemptAutoclose(_.UpdateWithShallowTransfer,this.id),this}hydrateAncestors(){const i=[],n=[],s=[],c=[];if(this.initialData.parent){const e=re(this.initialData.parent),y=this.project.get(e);if(y)this.setParent(y,null);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${e}' that isn't found in the project`)}else throw new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if((this.initialData.implements||[]).forEach(e=>{const y=re(e),m=this.project.get(y);if(m)this.addImplementation(m,null),i.push(m);else throw new Error(`${Fr(this.type)} with id '${this.id}' has a 'implements' reference "${y}" which is missing in the project`)}),this.initialData.extends){const e=re(this.initialData.extends),y=this.project.get(e);if(y)this.setExtends(y,null),i.push(y);else if(e)throw new Error(`${Fr(this.type)} with id '${this.id}' has a 'extends' reference "${e}" which is missing in the project`)}return{updated:D(i),added:D(n),removed:D(s),affected:D(c),self:this}}afterAllChildrenInitialized(i=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,_.AfterAllChildrenInitialized))){if(!this.checkCanEdit(this,i))return J.Logger.warn(`[afterAllChildrenInitialized] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(_.AfterAllChildrenInitialized,this.id),{updated:[],added:[],removed:[],affected:[],self:this};const n=[],s=[],c=[],e=[];if(this.initialized=!0,this.parent.type===o.DefinitionEntity&&this.parentRelationType!==yc.AllPropertiesImplementationTarget){let X=this.index||0;const se=this.parent.properties.filter(fe=>!fe.deleted&&fe.id!==this.id);se.length&&(X>se.length+1?X=se.length:X<0&&(X=0)),se.find(fe=>(fe.index||0)===X&&!fe.deleted)&&se.filter(fe=>(fe.index||0)>=X&&!fe.deleted).forEach(fe=>{fe.metaSync({index:(fe.index||0)+1},i),i==null||i.add(fe,Z.Updated),n.push(fe)}),this.metaSync({index:X},i)}const{updated:y,added:m,removed:v,affected:E}=this.syncWithImplementation(i);n.push(...y),s.push(...m),c.push(...v),e.push(...E);const{updated:b,added:w,removed:P,affected:$}=Pk(this,i);n.push(...b),s.push(...w),c.push(...P),e.push(...$);const{updated:L,added:U,removed:K,affected:H}=this.syncWithExtension(i);return n.push(...L),s.push(...U),c.push(...K),e.push(...H),this.captureVersion(),i==null||i.attemptAutoclose(_.AfterAllChildrenInitialized,this.id),{updated:D(n),added:D(s),removed:D(c),affected:D(e),self:this}}addSelfToProject(i=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,"add-self-to-project"))){const n=[this],s=[],c=[],e=[];return this.parentRelationType===yc.AllPropertiesImplementationTarget?this.parent.setAllPropertiesImplement(this,i):this.parent.addProperty(this,i),n.push(this.parent),this.subscribe(),this.subscribeToDependencies(),i==null||i.attemptAutoclose("add-self-to-project",this.id),{updated:D(n),added:D(s),removed:D(c),affected:D(e),self:this}}setParent(i,n=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,_.SetParent))){var s;return this.checkCanEditWithCounterpartAndSideEffects(this,i,_.SetParent,n)?(((s=this.parent)==null?void 0:s.id)!==(i==null?void 0:i.id)&&(this.parent=i,n&&(n==null||n.add(this,Z.Updated))),n==null||n.attemptAutoclose(_.SetParent,this.id),this):this}addImplementation(i,n=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,_.AddImplementation))){return this.checkCanEdit(this,n)?(this.implements.includes(i)||(this.implements.push(i),n==null||n.add(this,Z.Updated)),n==null||n.attemptAutoclose(_.AddImplementation,this.id),this):(J.Logger.warn(`[addImplementation] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),n==null||n.attemptAutoclose(_.AddImplementation,this.id),this)}removeImplementation(i,n=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,_.RemoveImplementation))){return this.checkCanEdit(this,n)?(this.implements.includes(i)&&(this.implements=this.implements.filter(s=>s.id!==i.id),n==null||n.add(this,Z.Updated)),n==null||n.attemptAutoclose(_.RemoveImplementation,this.id),this):(J.Logger.warn(`[removeImplementation] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),n==null||n.attemptAutoclose(_.RemoveImplementation,this.id),this)}setExtends(i,n=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,_.SetExtends))){var s;return this.checkCanEdit(this,n)?(((s=this.extends)==null?void 0:s.id)!==(i==null?void 0:i.id)&&(this.extends=i,this.subscribeToDependencies(),n&&(n==null||n.add(this,Z.Updated))),n==null||n.attemptAutoclose(_.SetExtends,this.id),this):(J.Logger.warn(`[setExtends] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),n==null||n.attemptAutoclose(_.SetExtends,this.id),this)}initChildren(i=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,"init-children"))){if(this.initialized||this.startedInitialization)return this;if(this.startedInitialization=!0,this.initialData.defaultValue&&(this.defaultValue=ye(this.initialData.defaultValue,this.project),this.defaultValue.setParent(this,null),this.defaultValue.initChildren(i)),this.initialData.dataType){const n=ye(this.initialData.dataType,this.project);n.setParent(this,null),n.initChildren(i),this.dataType=n}if(this.implements=this.initialData.implements.map(n=>ye(n,this.project)),this.initialData.extends){const n=ye(this.initialData.extends,this.project);this.setExtends(n,null)}return this.subscribeToDependencies(),this.afterAllChildrenInitialized(i),i==null||i.attemptAutoclose("init-children",this.id),this}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(i,n=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,"meta-sync"))){const s=$r(this,i,n),c=xr(this,s),e=this.toMeta();return this.name=s.name!==void 0?s.name:e.name,this.codeName=s.codeName!==void 0?s.codeName:e.codeName,this.description=s.description!==void 0?s.description:e.description,this.abstract=s.abstract!==void 0?s.abstract:e.abstract,this.private=s.private!==void 0?s.private:e.private,this.index=s.index||(s.index!==0?e.index:0),this.static=s.static!==void 0?s.static:e.static,this.hidden=s.hidden!==void 0?s.hidden:e.hidden,this.constant=s.constant!==void 0?s.constant:e.constant,this.interactive=s.interactive!==void 0?s.interactive:e.interactive,this.required=s.required!==void 0?s.required:e.required,this.unique=s.unique!==void 0?s.unique:e.unique,super.baseMetaSync(s,this,n),s.deleted===!0&&!e.deleted?n==null||n.add(this,Z.Removed):s.deleted===!1&&e.deleted?n==null||n.add(this,Z.Added):c&&(n==null||n.add(this,Z.Updated)),n==null||n.attemptAutoclose("meta-sync",this.id),this}async APILoad(i=Ge,...n){return await ti.repository.APILoad(this.id,...n),this}async APICreate(i=Ge,...n){return await ti.repository.APICreate(this.toShallowJSON(),...n),this}async APIUpdate(i=Ge,...n){return await ti.repository.APIUpdate(this.toShallowJSON(),...n),this}async APIDelete(i=Ge,...n){return await ti.repository.APIDelete(this.toShallowJSON(),...n),this}async APIClone(i=Ge,...n){return await ti.repository.APIClone(this.id,...n),this}async APILoadVersion(i=Ge,n,...s){return await ti.repository.APILoadVersion(this.id,n,...s)}removeFromParent(i=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,_.RemoveFromParent))){if(!this.checkCanEdit(this,i))return J.Logger.warn(`[removeFromParent] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(_.RemoveFromParent,this.id),{added:[],updated:[],removed:[],affected:[],self:this};const n=[],s=[],c=[],e=[];return this.parent.type===o.DefinitionEntity&&(this.parentRelationType===yc.AllPropertiesImplementationTarget?this.parent.removeAllPropertiesImplement(i):this.parent.removeProperty(this,i),e.push(this.parent)),i==null||i.attemptAutoclose(_.RemoveFromParent,this.id),{added:D(c),updated:D(n),removed:D(s),affected:D(e),self:this}}remove({ignoreUpstream:i}={ignoreUpstream:!1},n=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,_.RemoveEntity))){var m;if(!this.checkCanDelete(this,n))return J.Logger.warn(`[remove] User is not allowed to delete or edit this ${this.type} entity with id: ${this.id}`),n==null||n.event({id:`${_.RemoveEntity}-${this.id}`,action:_.RemoveEntity,owner:this,errorReason:ir.ActionOwnerEntityNonDeletable,rootAction:((m=n==null?void 0:n.self)==null?void 0:m.id)===this.id&&(n==null?void 0:n.autoCloseActionName)===_.RemoveEntity}),n==null||n.attemptAutoclose(_.RemoveEntity,this.id),{added:[],updated:[],removed:[],affected:[],self:this};const s=[],c=[],e=[],y=[];if(n!=null&&n.hasRemoved(this.id))return n==null||n.attemptAutoclose(_.RemoveEntity,this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(c.push(this),this.unsubscribe(),this.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},n),Object.values(this.detachedDependents).forEach(v=>{const{updated:E,removed:b,added:w}=v.entity.onDetachedDependencyRemoved(this,v.field,n);s.push(...E),c.push(...b),e.push(...w)}),this.defaultValue){const{updated:v,removed:E}=this.defaultValue.remove({ignoreUpstream:!0},n);s.push(...v),c.push(...E)}if(this.dataType){const{updated:v,removed:E}=this.dataType.remove({ignoreUpstream:!0},n);s.push(...v),c.push(...E)}if(!i){const v=this.removeFromParent(n);e.push(...v.added),s.push(...v.updated),c.push(...v.removed),y.push(...v.affected)}return n==null||n.attemptAutoclose(_.RemoveEntity,this.id),{added:D(e),updated:D(s),removed:D(c),affected:D(y),self:this}}restore({}={},i=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,_.RestoreEntity))){if(!this.checkCanEdit(this,i))return J.Logger.warn(`[restore] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(_.RestoreEntity,this.id),{added:[],updated:[],removed:[],affected:[],self:this};const n=[],s=[],c=[],e=[];if(i!=null&&i.hasAdded(this.id))return i==null||i.attemptAutoclose(_.RestoreEntity,this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},i),Object.values(this.detachedDependents).forEach(y=>{const{updated:m,removed:v,added:E}=y.entity.onDetachedDependencyRestored(this,y.field,i);s.push(...m),c.push(...v),n.push(...E)}),this.defaultValue){const{updated:y}=this.defaultValue.restore({},i);s.push(...y)}if(this.dataType){const{updated:y}=this.dataType.restore({},i);s.push(...y)}return this.parent.type===o.DefinitionEntity&&(this.parentRelationType===yc.AllPropertiesImplementationTarget?this.parent.removeAllPropertiesImplement(i):this.parent.addProperty(this,i),e.push(this.parent)),i==null||i.attemptAutoclose(_.RestoreEntity,this.id),{added:D(n),updated:D(s),removed:D(c),affected:D(e),self:this}}toFlat(i=new Set){var s,c;return i.has(this.id)?[]:(i.add(this.id),[this,...((s=this.defaultValue)==null?void 0:s.toFlat(i))||[],...((c=this.dataType)==null?void 0:c.toFlat(i))||[],...this.parent.toFlat(i)])}toFlatIds(i=new Set){var s,c;if(i.has(this.id))return[];if(i.add(this.id),!this.parent)throw new Error(`Property with id '${this.id}' has no parent and cannot be flattened`);return[this.id,...((s=this.defaultValue)==null?void 0:s.toFlatIds(i))||[],...((c=this.dataType)==null?void 0:c.toFlatIds(i))||[],...this.parent.toFlatIds(i)]}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,codeName:this.codeName,description:this.description,index:this.index,hidden:this.hidden,private:this.private,abstract:this.abstract,required:this.required,unique:this.unique,constant:this.constant,interactive:this.interactive,static:this.static,type:this.type,editable:this.editable,deletable:this.deletable,name:this.name}}toJSON(i=new Set){var n,s,c;return i.has(this.id)?this.toReference():(i.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,editable:this.editable,deletable:this.deletable,name:this.name,codeName:this.codeName,description:this.description,index:this.index,private:this.private,unique:this.unique,required:this.required,static:this.static,constant:this.constant,interactive:this.interactive,abstract:this.abstract,hidden:this.hidden,parentRelationType:this.parentRelationType,defaultValue:((n=this.defaultValue)==null?void 0:n.toJSON(i))||null,dataType:((s=this.dataType)==null?void 0:s.toJSON(i))||null,implements:this.implements.map(e=>e.toJSON(i)),extends:((c=this.extends)==null?void 0:c.toJSON(i))||null,parent:this.parent.toReference()})}toJSONClone(i=pt){var s,c,e,y,m,v,E;let n;return(s=i.seenEntityMaps)!=null&&s.has(this.id)?n=i.seenEntityMaps.get(this.id):(n=i.newId||jr(this,this.project,i.uuidStrategy),i.seenEntityMaps&&i.seenEntityMaps.set(this.id,n)),(c=i.seenEntities)!=null&&c.has(n)||(e=i.seenEntities)!=null&&e.has(this.id)?this.toReference({seenEntityMaps:i.seenEntityMaps}):((y=i.seenEntities)==null||y.add(n),(m=i.seenEntities)==null||m.add(this.id),{id:n,version:x.UUID.uuid(),createdAt:i.timestamp||M().toISOString(),author:x.sessionAuthor,previousVersion:null,deleted:!1,type:this.type,editable:this.editable,deletable:this.deletable,name:this.name,codeName:this.codeName,description:this.description,index:this.index,unique:this.unique,private:this.private,required:this.required,static:this.static,constant:this.constant,interactive:this.interactive,abstract:this.abstract,hidden:this.hidden,parentRelationType:this.parentRelationType,defaultValue:((v=this.defaultValue)==null?void 0:v.toJSONClone({...i,newId:null}))||null,dataType:((E=this.dataType)==null?void 0:E.toJSONClone({...i,newId:null}))||null,implements:this.implements.map(b=>this.project.getBuiltIn(b.id)?b.toJSON(i.seenEntities):b.toJSONClone({...i,newId:null})),extends:(()=>{var b;return this.extends&&this.project.getBuiltIn(this.extends.id)?this.extends.toJSON():((b=this.extends)==null?void 0:b.toJSONClone({...i,newId:null}))||null})(),parent:this.parent.toReference({seenEntityMaps:i.seenEntityMaps})})}toReference(i=pt){var s;let n=this.id;return(s=i.seenEntityMaps)!=null&&s.has(this.id)&&(n=i.seenEntityMaps.get(this.id)),{id:n+"--"+x.UUID.uuid()+"--ref",type:o.GenericReference,entityId:n,version:this.version,entityType:this.type}}toShallowJSON(i=pt){var s,c,e,y;let n=this.id;return(s=i.seenEntityMaps)!=null&&s.has(this.id)&&(n=i.seenEntityMaps.get(this.id)),{id:n,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,name:this.name,codeName:this.codeName,description:this.description,type:this.type,editable:this.editable,deletable:this.deletable,index:this.index,private:this.private,required:this.required,unique:this.unique,abstract:this.abstract,static:this.static,constant:this.constant,interactive:this.interactive,hidden:this.hidden,parentRelationType:this.parentRelationType,defaultValue:((c=this.defaultValue)==null?void 0:c.toReference(i))||null,dataType:((e=this.dataType)==null?void 0:e.toReference(i))||null,implements:this.implements.map(m=>m.toReference(i)),extends:((y=this.extends)==null?void 0:y.toReference(i))||null,parent:this.parent.toReference(i)}}toFlatJSON(i=new Set){var s,c;return i.has(this.id)?[]:(i.add(this.id),[this.toShallowJSON(),...((s=this.defaultValue)==null?void 0:s.toFlatJSON(i))||[],...((c=this.dataType)==null?void 0:c.toFlatJSON(i))||[],...this.implements.flatMap(e=>e.toFlatJSON(i)),...this.parent.toFlatJSON(i)])}toGenerationTarget(){var i;return{id:this.id,name:this.name,description:this.description,type:this.type,private:this.private,required:this.required,abstract:this.abstract,static:this.static,parentRelationType:this.parentRelationType,implements:this.implements.map(n=>n.id),extends:(i=this.extends)==null?void 0:i.id,parent:this.parent.id}}toFlatGenerationTarget(i=new Set){var s,c;return i.has(this.id)?[]:(i.add(this.id),[this.toGenerationTarget(),...((s=this.defaultValue)==null?void 0:s.toFlatGenerationTarget(i))||[],...((c=this.dataType)==null?void 0:c.toFlatGenerationTarget(i))||[],...this.implements.flatMap(e=>e.toFlatGenerationTarget(i))])}clearErrors(){var i,n;return this.errors=[],(i=this.defaultValue)==null||i.clearErrors(),(n=this.dataType)==null||n.clearErrors(),this}validate(){return this.errors=zUe(this),{success:!0}}async validateAsync(i={}){const n=J.YieldTracker.from(i);return this.errors=await WUe(this,{tracker:n}),{success:!0}}getErrors(){var n,s;return[...this.errors,...((n=this.defaultValue)==null?void 0:n.getErrors())||[],...((s=this.dataType)==null?void 0:s.getErrors())||[]]}async getErrorsAsync(i={}){const n=J.YieldTracker.from(i),s=[...this.errors];if(await n.tick(),this.defaultValue){const c=await this.defaultValue.getErrorsAsync({tracker:n});s.push(...c)}if(this.dataType){const c=await this.dataType.getErrorsAsync({tracker:n});s.push(...c)}return s}getShallowErrors(){return this.errors}implement(i,n=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,"implement-self-as-property")),s=null){var v;const c=s||x.UUID.uuid(),e=ti.new(n);e.id=c,e.name=this.name,e.description=this.description,e.index=this.index,e.private=this.private,e.required=this.required,e.static=this.static,e.constant=this.constant,e.unique=this.unique,e.hidden=this.hidden,e.interactive=this.interactive,e.parent=i.toReference(),e.implements=[this.toJSON()];const y=ye(e,this.project);y.hydrateAncestors(),y.addSelfToProject(n),n==null||n.add(y,Z.Added),y.initChildren(n);const m=(v=this.defaultValue)==null?void 0:v.clone(n,y,x.UUID.uuid());return m&&(m.editable=!0,m.deletable=!0),y}clone(i=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,_.CloneEntity)),n=null,s=null,c=!0){var b,w;const e=Pr(n,this),y=s||x.UUID.uuid(),m=n||this.parent,v={hidden:!1,id:y,version:x.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||M().toISOString(),author:(i==null?void 0:i.author)||"1",previousVersion:null,deleted:!1,type:this.type,editable:!0,deletable:!0,name:this.name,codeName:this.codeName,description:this.description,index:this.index,private:this.private,constant:this.constant,unique:this.unique,interactive:this.interactive,required:this.required,abstract:this.abstract,static:this.static,parentRelationType:this.parentRelationType,defaultValue:null,dataType:null,implements:this.implements.map(P=>P.toJSON()),extends:this.extends,parent:m.toReference()},E=Ui(v,e);if(E.hydrateAncestors(),E.setParent(m,i),c&&(E.subscribe(),E.addSelfToProject(i)),E.initChildren(i),i==null||i.add(E,Z.Added),this.dataType&&this.project.diggestedBuiltInBaseEntitiesIds.has(this.dataType.id))E.setDataType(e.getBuiltIn(this.dataType.id),i);else{const P=((b=this.dataType)==null?void 0:b.clone(i,E,x.UUID.uuid(),c))||null;P&&E.setDataType(P,i)}if(this.defaultValue){const P=(w=this.defaultValue)==null?void 0:w.clone(i,E,x.UUID.uuid(),c);E.setDefaultValue(P||null,i)}return this.implements.length&&this.implements.forEach(P=>{const $=e.get(P.id)||e.getBuiltIn(P.id);if($){E.addImplementation($,i);return}}),E.addSelfToProject(null),i==null||i.attemptAutoclose(_.CloneEntity,this.id),E}setDataType(i,n=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,_.SetDataType))){if(!this.checkCanEdit(this,n))return J.Logger.warn(`[setDataType] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),n==null||n.attemptAutoclose(_.SetDataType,this.id),this;const s=this.dataType;return(s==null?void 0:s.id)!==(i==null?void 0:i.id)&&(s==null||s.remove({ignoreUpstream:!0},n),this.dataType=i,this.subscribeToDependencies(),n==null||n.add(this,Z.Affected)),n==null||n.attemptAutoclose(_.SetDataType,this.id),this}removeDataType(i=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,_.RemoveDataType))){return this.checkCanEdit(this,i)?(this.dataType&&(this.dataType.remove({ignoreUpstream:!0},i),i==null||i.add(this,Z.Affected),this.dataType=null),i==null||i.attemptAutoclose(_.RemoveDataType,this.id),this):(J.Logger.warn(`[removeDataType] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(_.RemoveDataType,this.id),this)}getDataType(i=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,"get-data-type"))){return i==null||i.attemptAutoclose("get-data-type",this.id),this.dataType}getDefaultValue(){var c;let i=null;for(const e of this.implements){const y=e.getDefaultValue();(!i||qn(i))&&y&&(i=y)}let n=this.defaultValue;const s=(c=this.extends)==null?void 0:c.getDefaultValue();return qn(n)&&s&&!qn(s)&&(n=s),qn(n)&&i&&!qn(i)&&(n=i),n}setDefaultValue(i,n=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,"set-default-value"))){if(!this.checkCanEdit(this,n))return J.Logger.warn(`[setDefaultValue] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),n==null||n.attemptAutoclose("set-default-value",this.id),this;const s=this.defaultValue;return(s==null?void 0:s.id)!==(i==null?void 0:i.id)&&(s==null||s.remove({ignoreUpstream:!0},n),this.defaultValue=i,n==null||n.add(this,Z.Affected)),n==null||n.attemptAutoclose("set-default-value",this.id),this}syncWithImplementation(i=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,"sync-with-implementation"))){var P,$,L,U,K,H,X,se,ee,fe,de;if(!this.checkCanEdit(this,i))return J.Logger.warn(`[syncWithImplementation] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose("sync-with-implementation",this.id),{added:[],updated:[],removed:[],affected:[],self:this};const n=[],s=[],c=[],e=[];this.parent.type!==o.PrimitiveEntity&&this.interactive&&this.parent.getAllPropertiesImplements().forEach(ve=>{this.addImplementation(ve,i)});let y=null;for(const ce of this.implements)(P=ce.dataType)!=null&&P.isResolved&&(y?($=ce.dataType.orChildrenGroup)!=null&&$.length&&ce.dataType.implementationChooseOne&&(y=ce.dataType):y=ce.dataType);const m=zr(this.dataType,y);if(!this.dataType||!((L=this.dataType)!=null&&L.isResolved)||(U=this.dataType)!=null&&U.isResolved&&(y!=null&&y.isResolved)&&!m.compatible){if(y&&((K=y.orChildrenGroup)!=null&&K.length)&&y.implementationChooseOne){if(!this.dataType||this.dataType&&this.project.diggestedBuiltInBaseEntitiesIds.has(this.dataType.id)){const ve=tr.new(i);ve.parent=this.toReference();const ae=ye(ve,this.project);ae.hydrateAncestors(),i==null||i.add(ae,Z.Added),ae.addSelfToProject(i),ae.afterAllChildrenInitialized(i)}const ce=y.orChildrenGroup.some(ve=>ve.foreignKeyAllowed);if(((X=(H=this.dataType)==null?void 0:H.entity)==null?void 0:X.type)===o.DefinitionEntity&&Si(this.dataType.entity,Re.PERSISTED_ENTITY)&&ce){const ve=$Ue(this.dataType.entity);ve&&this.dataType.setForeignKeyRef(ve,i),(se=this.dataType)==null||se.setEntity(null,i)}else{const ve=y.orChildrenGroup.find(ae=>{var me;return((me=ae.entity)==null?void 0:me.id)===Q["primitive-entity"].string.id});if(ve)(ee=this.dataType)==null||ee.setEntity(ve.entity,i);else{const ae=y.orChildrenGroup.filter(_e=>_e.isResolved),me=ae.filter(_e=>{var Ne;return((Ne=_e.entity)==null?void 0:Ne.type)===o.PrimitiveEntity});me.length?(fe=this.dataType)==null||fe.setEntity(me[0].entity,i):ae.length&&((de=this.dataType)==null||de.setEntity(ae[0].entity,i))}}}else if(y&&this.project.diggestedBuiltInBaseEntitiesIds.has(y.id))this.setDataType(y,i);else if(y){const ce=y.clone(i,this,x.UUID.uuid(),!0);this.setDataType(ce,i),s.push(ce)}}if(!this.defaultValue){let ce=null;for(const ve of this.implements){const ae=ve.getDefaultValue();ae&&(ce=ae)}if(ce){const ve=ce.clone(i,this,x.UUID.uuid(),!0);this.setDefaultValue(ve,i),s.push(ve)}}let v=!1,E=!1,b=!1,w=!1;return this.implements.forEach(ce=>{ce.required&&(v=!0),ce.constant&&(b=!0),ce.unique&&(E=!0),ce.static&&(w=!0)}),this.metaSync({required:v||this.required,constant:b||this.constant,unique:E||this.unique,static:w||this.static},i),i==null||i.attemptAutoclose("sync-with-implementation",this.id),{updated:D(n),added:D(s),removed:D(c),affected:D(e),self:this}}syncWithExtension(i=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,"sync-with-extension"))){var v,E;if(!this.checkCanEdit(this,i))return J.Logger.warn(`[syncWithExtension] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose("sync-with-extension",this.id),{added:[],updated:[],removed:[],affected:[],self:this};const n=[],s=[],c=[],e=[];if(!this.extends)return i==null||i.attemptAutoclose("sync-with-extension",this.id),{added:[],updated:[],removed:[],affected:[],self:this};const y={...this.extends.toMeta()};if(delete y.id,delete y.version,delete y.createdAt,delete y.previousVersion,delete y.author,delete y.index,this.metaSync(y,i),n.push(this),!this.extends.dataType)return i==null||i.attemptAutoclose("sync-with-extension",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(!this.dataType){const b=tr.new(i);b.parent=this.toReference();const w=ye(b,this.project);w.hydrateAncestors(),i==null||i.add(w,Z.Added),w.addSelfToProject(i),w.afterAllChildrenInitialized(i)}if(zr(this.dataType,this.extends.dataType).compatible||(v=this.dataType)==null||v.merge(this.extends.dataType,i),this.extends.defaultValue&&!this.defaultValue){const b=this.extends.defaultValue.clone(i,this,x.UUID.uuid(),!0);this.setDefaultValue(b,i),s.push(b)}else this.extends.defaultValue?this.extends.defaultValue&&this.defaultValue&&!Wke(this.defaultValue,this.extends.defaultValue)&&(this.defaultValue.merge(this.extends.defaultValue,i),n.push(this.defaultValue)):((E=this.defaultValue)==null||E.remove({ignoreUpstream:!0},i),this.defaultValue=null,e.push(this));return i==null||i.attemptAutoclose("sync-with-extension",this.id),{updated:D(n),added:D(s),removed:D(c),affected:D(e),self:this}}implementAsInputMap(i=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,"implement-as-return-declaration")),n,s){const c=ds.new(i);c.id=s||c.id,c.name=this.name,c.description=this.description,c.parent=n.toReference(),c.declaration=this.toJSON();const e=Ui(c,this.project);if(e.hydrateAncestors(),e.addSelfToProject(i),i==null||i.add(e,Z.Added),e.initChildren(i),this.dataType)if(this.project.diggestedBuiltInBaseEntitiesIds.has(this.dataType.id))e.setDataType(this.dataType,i),i==null||i.add(e,Z.Affected);else{const y=this.dataType.clone(i,e);e.setDataType(y,i)}if(this.defaultValue){const y=this.defaultValue.clone(i,e);e.setDefaultValue(y,i)}return i==null||i.attemptAutoclose("implement-as-return-declaration",this.id),e}};I(ti,"repository",{APICreate:async(i,...n)=>i,APIUpdate:async(i,...n)=>i,APIDelete:async(i,...n)=>i,APIClone:async(i,...n)=>{},APILoad:async(i,...n)=>null,APILoadVersion:async(i,n,...s)=>null}),I(ti,"type",o.Property),I(ti,"USER_MANAGED_PARENT_TYPES",[o.DefinitionEntity]),I(ti,"PARENT_TYPES",[...ti.USER_MANAGED_PARENT_TYPES,o.PrimitiveEntity,o.BuiltInBaseEntity]),I(ti,"MUTABLE_BASE_PROPERTIES",["name","codeName","description","private","abstract","static","required","constant","unique","interactive"]),I(ti,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),I(ti,"BASE_PROPERTIES",[...ti.MUTABLE_BASE_PROPERTIES,...ti.INMUTABLE_BASE_PROPERTIES]),I(ti,"MUTABLE_META_PROPERTIES",[...ti.MUTABLE_BASE_PROPERTIES,"index"]),I(ti,"INMUTABLE_META_PROPERTIES",[...ti.INMUTABLE_BASE_PROPERTIES]),I(ti,"META_PROPERTIES",[...ti.MUTABLE_META_PROPERTIES,...ti.INMUTABLE_META_PROPERTIES]),I(ti,"MUTABLE_UPSTREAM_PROPERTIES",[]),I(ti,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","implements","extends"]),I(ti,"UPSTREAM_PROPERTIES",[...ti.MUTABLE_UPSTREAM_PROPERTIES,...ti.INMUTABLE_UPSTREAM_PROPERTIES]),I(ti,"MUTABLE_DOWNSTREAM_PROPERTIES",["dataType"]),I(ti,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),I(ti,"DOWNSTREAM_PROPERTIES",[...ti.MUTABLE_DOWNSTREAM_PROPERTIES,...ti.INMUTABLE_DOWNSTREAM_PROPERTIES]),I(ti,"PROPERTIES",[...ti.META_PROPERTIES,...ti.UPSTREAM_PROPERTIES,...ti.DOWNSTREAM_PROPERTIES]);let ka=ti;async function YUe(d,p={}){var E,b;const i=J.YieldTracker.from(p),n=d.implements.flatMap(w=>tKe(d,w)),s=iKe(d,d.extends),c=nKe(d),e=rKe(d),y=jx(d),m=[...n,...s,...c,...e,...y],v=Lt(d.errors,m);await i.tick();for(const w of d.properties)await w.validateAsync({tracker:i});for(const w of d.methods)await w.validateAsync({tracker:i});for(const w of d.abstractMethods)await w.validateAsync({tracker:i});return await((E=d.allPropertiesImplement)==null?void 0:E.validateAsync({tracker:i})),await((b=d.additionalPropertiesDataType)==null?void 0:b.validateAsync({tracker:i})),v}function XUe(d){var m,v;const p=d.implements.flatMap(E=>tKe(d,E)),i=iKe(d,d.extends),n=nKe(d),s=rKe(d),c=jx(d);d.properties.forEach(E=>{E.validate()}),d.methods.flatMap(E=>E.validate()),d.abstractMethods.flatMap(E=>E.validate()),(m=d.allPropertiesImplement)==null||m.validate(),(v=d.additionalPropertiesDataType)==null||v.validate();const e=[...p,...i,...n,...s,...c];return Lt(d.errors,e)}function QUe(d,p){const i=p.properties.filter(c=>c.abstract),n=[];let s=[...d.properties];return i.forEach(c=>{const e=s.find(y=>!!y.implements.find(m=>m.id===c.id));e?s=s.filter(y=>y.id!==e.id):n.push(c)}),n}function eKe(d,p){const i=p.abstractMethods,n=[];let s=[...d.methods];return i.forEach(c=>{const e=s.find(y=>{var m;return((m=y.implements)==null?void 0:m.id)===c.id});e?s=s.filter(y=>y.id!==e.id):n.push(c)}),n}function tKe(d,p){const i=[];if(!p.abstract){const E=$t({id:d.id+"--"+he.ImplementingNonAbstractEntity,message:`Entity "${d.name}" with id "${d.id}" is implementing a non-abstract entity "${p.name}" with id "${p.id}"`,severity:pe.Error,code:he.ImplementingNonAbstractEntity,entity:d});return i.push(E.error),i}const n=p.properties.filter(E=>E.abstract),s=[];let c=[...d.properties];n.forEach(E=>{const b=c.find(w=>!!w.implements.find(P=>P.id===E.id));b?c=c.filter(w=>w.id!==b.id):s.push(E)}),s.length&&s.forEach(E=>{const b=$t({id:d.id+"--"+he.MissingPropertyImplementation+"--"+E.id,message:`Property "${E.name}" with id "${E.id}" of entity "${p.name}" with id "${p.id}" is not implemented when entity "${d.name}" with id "${d.id}" implements it`,severity:pe.Error,code:he.MissingPropertyImplementation,entity:d});i.push(b.error)});const e=[];let y=[...d.methods];p.abstractMethods.forEach(E=>{const b=y.find(w=>{var P;return((P=w.implements)==null?void 0:P.id)===E.id});b?y=y.filter(w=>w.id!==b.id):e.push(E)}),e.length&&e.forEach(E=>{const b=$t({id:d.id+"--"+he.MissingMethodImplementation+"--"+E.id,message:`Method "${E.name}" with id "${E.id}" of entity "${p.name}" with id "${p.id}" is not implemented when entity "${d.name}" with id "${d.id}" implements it`,severity:pe.Error,code:he.MissingMethodImplementation,entity:d});i.push(b.error)});const m=[];p.properties.forEach(E=>{const b=c.find(w=>w.name===E.name);b&&m.push([b,E])}),m.length&&m.forEach(([E])=>{const b=$t({id:d.id+"--"+Ie.PropertyOverwritesOtherSiblingWithSameName+"--"+E.id,message:`Property "${E.name}" with id "${E.id}" of entity "${d.name}" with id "${d.id}" overwrites the property with the same name from the base entity "${p.name}" with id "${p.id}"`,severity:pe.Error,code:Ie.PropertyOverwritesOtherSiblingWithSameName,entity:d});i.push(b.error)});const v=[];return p.methods.forEach(E=>{const b=y.find(w=>w.name===E.name);b&&v.push([b,E])}),v.length&&v.forEach(([E])=>{const b=$t({id:d.id+"--"+Ie.MethodOverwritesOtherSiblingWithSameName+"--"+E.id,message:`Method "${E.name}" with id "${E.id}" of entity "${d.name}" with id "${d.id}" overwrites the method with the same name from the base entity "${p.name}" with id "${p.id}"`,severity:pe.Error,code:Ie.MethodOverwritesOtherSiblingWithSameName,entity:d});i.push(b.error)}),i}function iKe(d,p){const i=[];if(!p)return i;const n=[];if(!d.abstract&&p.abstract){const c=$t({id:d.id+"--"+p.id+"--"+he.NonAbstractExtendingAbstractEntity,message:`Entity "${d.name}" with id "${d.id}" is not-abstract but is extending an abstract entity "${p.name}" with id "${p.id}"`,severity:pe.Error,code:he.NonAbstractExtendingAbstractEntity,entity:d,firstRelationship:p});return i.push(c.error),i}if(d.abstract&&!p.abstract){const c=$t({id:d.id+"--"+p.id+"--"+he.AbstractExtendingNonAbstractEntity,message:`Entity "${d.name}" with id "${d.id}" is abstract but is extending an non-abstract entity "${p.name}" with id "${p.id}"`,severity:pe.Error,code:he.AbstractExtendingNonAbstractEntity,entity:d,firstRelationship:p});return i.push(c.error),i}d.properties.forEach(c=>{const e=p.properties.find(y=>{var m;return y.name===c.name&&((m=c.extends)==null?void 0:m.id)!==y.id});c.implements.find(y=>y.id===(e==null?void 0:e.id))||e&&n.push(c)}),n.length&&n.forEach(c=>{const e=$t({id:d.id+"--"+Ie.PropertyOverwritesOtherSiblingWithSameName,message:`Property "${c.name}" with id "${c.id}" of entity "${d.name}" with id "${d.id}" overwrites the property with the same name from the extended entity "${p.name}" with id "${p.id}"`,severity:pe.Error,code:Ie.PropertyOverwritesOtherSiblingWithSameName,entity:d});i.push(e.error)});const s=[];return d.methods.forEach(c=>{var y;const e=p.methods.find(m=>{var v;return m.name===c.name&&((v=c.extends)==null?void 0:v.id)!==m.id});((y=c.implements)==null?void 0:y.id)!==(e==null?void 0:e.id)&&e&&s.push(c)}),s.length&&s.forEach(c=>{const e=$t({id:d.id+"--"+Ie.MethodOverwritesOtherSiblingWithSameName,message:`Method "${c.name}" with id "${c.id}" of entity "${d.name}" with id "${d.id}" overwrites the method with the same name from the extended entity "${p.name}" with id "${p.id}"`,severity:pe.Error,code:Ie.MethodOverwritesOtherSiblingWithSameName,entity:d});i.push(e.error)}),i}function rKe(d){const p=[];if(!d.properties.length){const i=$t({id:d.id+"--"+he.NoProperties,message:"No properties implemented",severity:pe.Warning,code:he.NoProperties,entity:d});p.push(i.error)}return p}function nKe(d){const p=[];if(d.abstract){if(d.methods.length){const i=$t({id:d.id+"--"+he.AbstractEntityWithNonAbstractMethods,message:`Entity "${d.name}" with id "${d.id}" is marked as abstract but has non-abstract methods`,severity:pe.Error,code:he.AbstractEntityWithNonAbstractMethods,entity:d});p.push(i.error)}if(d.properties.some(i=>!i.abstract)){const i=$t({id:d.id+"--"+he.AbstractEntityWithNonAbstractProperties,message:`Entity "${d.name}" with id "${d.id}" is marked as abstract but has non-abstract properties`,severity:pe.Error,code:he.AbstractEntityWithNonAbstractProperties,entity:d});p.push(i.error),d.properties.forEach(n=>{if(!n.abstract){const s=$t({id:d.id+"--"+he.StaticEntityWithNonStaticProperties+"--"+n.id,message:`Property "${n.name}" with id "${n.id}" of entity "${d.name}" with id "${d.id}" is not marked as abstract but the entity is marked as abstract`,severity:pe.Error,code:he.StaticEntityWithNonStaticProperties,entity:d});p.push(s.error)}})}}else{if(d.abstractMethods.length){const i=$t({id:d.id+"--"+he.AbstractPropertyInNonAbstractEntity,message:`Entity "${d.name}" with id "${d.id}" is not marked as abstract but has abstract methods`,severity:pe.Error,code:he.AbstractPropertyInNonAbstractEntity,entity:d});p.push(i.error)}d.properties.some(i=>i.abstract)&&d.properties.forEach(i=>{if(i.abstract){const n=$t({id:d.id+"--"+he.AbstractPropertyInNonAbstractEntity+"--"+i.id,message:`Property "${i.name}" with id "${i.id}" of entity "${d.name}" with id "${d.id}" is marked as abstract but the entity is not marked as abstract`,severity:pe.Error,code:he.AbstractPropertyInNonAbstractEntity,entity:d,firstRelationship:i});p.push(n.error)}})}return d.static&&d.properties.some(i=>!i.static)&&d.properties.forEach(i=>{if(!i.static){const n=$t({id:d.id+"--"+he.NonStaticPropertyInStaticEntity+"--"+i.id,message:`Property "${i.name}" with id "${i.id}" of entity "${d.name}" with id "${d.id}" is not marked as static but the entity is marked as static`,severity:pe.Error,code:he.NonStaticPropertyInStaticEntity,entity:d,firstRelationship:i});p.push(n.error)}}),p}function dUi(d,p){const i=[],n=Zn(p);if(!p.abstract){const e=new Mi({id:d.id+"--"+p.id+"--"+he.ImplementingNonAbstractEntity,message:`Entity "${d.name}" with id "${d.id}" is implementing a non-abstract built-in entity "${p.name}" with id "${p.id}"`,severity:pe.Error,code:he.ImplementingNonAbstractEntity,entity:d,firstRelationship:p});i.push(e)}const s=d.implements.filter(e=>e.id!==p.id);if(d.abstract){const e=new Mi({id:d.id+"--"+p.id+"--"+he.AbstractEntityImplements,message:`Entity "${d.name}" with id "${d.id}" is marked as abstract and cannot implement built-in entity "${p.name}" with id "${p.id}"`,severity:pe.Error,code:he.AbstractEntityImplements,entity:d,firstRelationship:p});i.push(e)}if(d.static&&!p.static){const e=new Mi({id:d.id+"--"+p.id+"--"+he.StaticImplementingNonStaticEntity,message:`Entity "${d.name}" with id "${d.id}" is marked as static and cannot implement non-static built-in entity "${p.name}" with id "${p.id}"`,severity:pe.Error,code:he.StaticImplementingNonStaticEntity,entity:d,firstRelationship:p});i.push(e)}if(!d.static&&p.static){const e=new Mi({id:d.id+"--"+p.id+"--"+he.NonStaticImplementingStaticEntity,message:`Entity "${d.name}" with id "${d.id}" is not marked as static and cannot implement static built-in entity "${p.name}" with id "${p.id}"`,severity:pe.Error,code:he.NonStaticImplementingStaticEntity,entity:d,firstRelationship:p});i.push(e)}return s.length&&s.forEach(e=>{if(e.type===o.BuiltInBaseEntity){const y=n.filter(m=>m.id!==e.id);y.length&&y.forEach(m=>{if(m.id!==e.id){const v=new Mi({id:d.id+"--"+m.id+"--"+e.id+"--"+he.ImplementsIncompatibleEntities,message:`Entity "${d.name}" with id "${d.id}" is implementing built-in entity "${m.name}" with id "${m.id}" but also implements entity "${e.name}" with id "${e.id}" which is incompatible`,severity:pe.Error,code:he.ImplementsIncompatibleEntities,entity:d,firstRelationship:m,secondRelationship:e});i.push(v)}})}else{Zn(e).forEach(E=>{const b=n.filter(w=>w.id!==E.id);b.length&&b.forEach(w=>{if(w.id!==E.id){const P=new Mi({id:d.id+"--"+w.id+"--"+E.id+"--"+he.ImplementsIncompatibleEntities,message:`Entity "${d.name}" with id "${d.id}" is implementing built-in entity "${w.name}" with id "${w.id}" but also implements entity "${E.name}" with id "${E.id}" which is incompatible`,severity:pe.Error,code:he.ImplementsIncompatibleEntities,entity:d,firstRelationship:w,secondRelationship:E});i.push(P)}})});const m=od(p.ownDeclaredProperties,e.ownDeclaredProperties,Ie.PropertyOverwritesOtherImplementedEntitysPropertyWithSameImplementation,Ie.PropertyOverwritesOtherImplementedEntitysPropertyWithSameName);i.push(...m.errors);const v=od(p.abstractMethods,[...e.abstractMethods,...e.methods],Ie.MethodOverwritesOtherImplementedEntitysMethodWithSameImplementation,Ie.MethodOverwritesOtherImplementedEntitysMethodWithSameName);i.push(...v.errors)}}),D(d.extends?Zn(d.extends):[]).forEach(e=>{if(!n.find(y=>y.id===e.id)){const y=new Mi({id:d.id+"--"+p.id+"--"+e.id+"--"+he.ExtendsIncompatibleEntities,message:`Entity "${d.name}" with id "${d.id}" is implementing built-in entity "${p.name}" with id "${p.id}" but also extends entity "${e.name}" with id "${e.id}" which is incompatible`,severity:pe.Error,code:he.ExtendsIncompatibleEntities,entity:d,firstRelationship:p,secondRelationship:e});i.push(y)}}),i}function uUi(d,p,i=!1){var v,E;const n=[],s=Zn(p);if(!d.abstract&&p.abstract){const b=$t({id:d.id+"--"+p.id+"--"+he.NonAbstractExtendingAbstractEntity,message:`Entity "${d.name}" with id "${d.id}" is not-abstract but is extending an abstract entity "${p.name}" with id "${p.id}"`,severity:pe.Error,code:he.NonAbstractExtendingAbstractEntity,entity:d,firstRelationship:p});n.push(b.error)}if(d.abstract&&!p.abstract){const b=$t({id:d.id+"--"+p.id+"--"+he.AbstractExtendingNonAbstractEntity,message:`Entity "${d.name}" with id "${d.id}" is abstract but is extending an non-abstract entity "${p.name}" with id "${p.id}"`,severity:pe.Error,code:he.AbstractExtendingNonAbstractEntity,entity:d,firstRelationship:p});n.push(b.error)}if(!d.static&&p.static){const b=$t({id:d.id+"--"+p.id+"--"+he.NonStaticExtendingStaticEntity,message:`Entity "${d.name}" with id "${d.id}" is not static but is extending a static entity "${p.name}" with id "${p.id}"`,severity:pe.Error,code:he.NonStaticExtendingStaticEntity,entity:d,firstRelationship:p});n.push(b.error)}if(d.static&&!p.static){const b=$t({id:d.id+"--"+p.id+"--"+he.StaticExtendingNonStaticEntity,message:`Entity "${d.name}" with id "${d.id}" is static but is extending an non-static entity "${p.name}" with id "${p.id}"`,severity:pe.Error,code:he.StaticExtendingNonStaticEntity,entity:d,firstRelationship:p});n.push(b.error)}if(!lf(p)){const b=$t({id:d.id+"--"+p.id+"--"+he.ExtendingNonInteractiveEntity,message:`Entity "${d.name}" with id "${d.id}" is extending an non-interactive entity "${p.name}" with id "${p.id}"`,severity:pe.Error,code:he.ExtendingNonInteractiveEntity,entity:d,firstRelationship:p});n.push(b.error)}if(d.extends&&((v=d.extends)==null?void 0:v.id)!==p.id)if(((E=d.extends)==null?void 0:E.type)===o.BuiltInBaseEntity){const b=s.filter(w=>{var P;return w.id!==((P=d.extends)==null?void 0:P.id)});b.length&&b.forEach(w=>{var P,$,L,U;if(w.id!==((P=d.extends)==null?void 0:P.id)){const K=$t({id:d.id+"--"+w.id+"--"+(($=d.extends)==null?void 0:$.id)+"--"+he.ExtendsIncompatibleEntities,message:`Entity "${d.name}" with id "${d.id}" is extending built-in entity "${w.name}" with id "${w.id}" but also extends entity "${(L=d.extends)==null?void 0:L.name}" with id "${(U=d.extends)==null?void 0:U.id}" which is incompatible`,severity:pe.Error,code:he.ExtendsIncompatibleEntities,entity:d,firstRelationship:w,secondRelationship:d.extends});n.push(K.error)}})}else{Zn(d.extends).forEach(K=>{const H=s.filter(X=>X.id!==K.id);H.length&&H.forEach(X=>{if(X.id!==K.id){const se=new Mi({id:d.id+"--"+X.id+"--"+K.id+"--"+he.ImplementsIncompatibleEntities,message:`Entity "${d.name}" with id "${d.id}" is extending built-in entity "${X.name}" with id "${X.id}" but also extends or implements entity "${K.name}" with id "${K.id}" which is incompatible`,severity:pe.Error,code:he.ImplementsIncompatibleEntities,entity:d,firstRelationship:X,secondRelationship:K});n.push(se)}})});const w=!!Zn(d.extends).find(K=>K.id===p.id);let P=[...d.extends.properties];w&&(P=P.filter(K=>!p.properties.find(H=>H.id===K.id||H.name===K.name||!!K.implements.find(X=>X.id===H.id))));let $=[...d.extends.methods];w&&($=$.filter(K=>!p.methods.find(H=>{var X;return H.id===K.id||H.name===K.name||H.id===((X=K.implements)==null?void 0:X.id)})));const L=od(p.ownDeclaredProperties,P,Ie.PropertyOverwritesOtherExtendedEntitysPropertyWithSameImplementation,Ie.PropertyOverwritesOtherExtendedEntitysPropertyWithSameName);n.push(...L.errors);const U=od(p.abstractMethods,$,Ie.MethodOverwritesOtherExtendedEntitysMethodWithSameImplementation,Ie.MethodOverwritesOtherExtendedEntitysMethodWithSameName);n.push(...U.errors)}i&&J.Logger.log("self.implements.length",d.implements.length),d.implements.length&&d.implements.forEach(b=>{if(b.type===o.BuiltInBaseEntity){const w=s.filter(P=>P.id!==b.id);w.length&&w.forEach(P=>{if(P.id!==b.id){const $=new Mi({id:d.id+"--"+P.id+"--"+b.id+"--"+he.ImplementsIncompatibleEntities,message:`Entity "${d.name}" with id "${d.id}" is implementing built-in entity "${P.name}" with id "${P.id}" but also implements entity "${b.name}" with id "${b.id}" which is incompatible`,severity:pe.Error,code:he.ImplementsIncompatibleEntities,entity:d,firstRelationship:P,secondRelationship:b});n.push($)}})}else{Zn(b).forEach(L=>{const U=s.filter(K=>K.id!==L.id);U.length&&U.forEach(K=>{if(K.id!==L.id){const H=new Mi({id:d.id+"--"+K.id+"--"+L.id+"--"+he.ImplementsIncompatibleEntities,message:`Entity "${d.name}" with id "${d.id}" is implementing built-in entity "${K.name}" with id "${K.id}" but also implements entity "${L.name}" with id "${L.id}" which is incompatible`,severity:pe.Error,code:he.ImplementsIncompatibleEntities,entity:d,firstRelationship:K,secondRelationship:L});n.push(H)}})});const P=od(p.ownDeclaredProperties,b.ownDeclaredProperties,Ie.PropertyOverwritesOtherImplementedEntitysPropertyWithSameImplementation,Ie.PropertyOverwritesOtherImplementedEntitysPropertyWithSameName);n.push(...P.errors);const $=od(p.abstractMethods,[...b.abstractMethods,...b.methods],Ie.MethodOverwritesOtherImplementedEntitysMethodWithSameImplementation,Ie.MethodOverwritesOtherImplementedEntitysMethodWithSameName);n.push(...$.errors)}});const e=od(d.ownDeclaredProperties,p.ownDeclaredProperties,Ie.PropertyOverwritesOtherSiblingWithSameImplementation,Ie.PropertyOverwritesOtherSiblingWithSameName);n.push(...e.errors);const y=od(p.methods,p.abstractMethods,Ie.MethodOverwritesOtherSiblingWithSameImplementation,Ie.MethodOverwritesOtherSiblingWithSameName);return n.push(...y.errors),D(d.extends?Zn(d.extends):[]).forEach(b=>{if(!s.find(w=>w.id===b.id)){const w=new Mi({id:d.id+"--"+p.id+"--"+b.id+"--"+he.ImplementsIncompatibleEntities,message:`Entity "${d.name}" with id "${d.id}" is extending built-in entity "${p.name}" with id "${p.id}" but also extends entity "${b.name}" with id "${b.id}" which is incompatible`,severity:pe.Error,code:he.ImplementsIncompatibleEntities,entity:d,firstRelationship:p,secondRelationship:b});n.push(w)}}),n}function pUi(d){const p=[];if(d.implements.forEach(i=>{if(!i.static){const n=new Mi({id:d.id+"--"+i.id+"--"+he.StaticImplementingNonStaticEntity,message:`Entity "${d.name}" with id "${d.id}" is static but implements entity "${i.name}" with id "${i.id}" which is non-static`,severity:pe.Error,code:he.StaticImplementingNonStaticEntity,entity:d,firstRelationship:i});p.push(n)}}),d.extends&&!d.extends.static){const i=new Mi({id:d.id+"--"+d.extends.id+"--"+he.StaticExtendingNonStaticEntity,message:`Entity "${d.name}" with id "${d.id}" is static but extends entity "${d.extends.name}" with id "${d.extends.id}" which is non-static`,severity:pe.Error,code:he.StaticExtendingNonStaticEntity,entity:d,firstRelationship:d.extends});p.push(i)}return p}function cUi(d){const p=[];if(d.implements.length){const i=new Mi({id:d.id+"--"+he.AbstractEntityImplements,message:`Entity "${d.name}" with id "${d.id}" cannot be marked as abstract because it implements other entities`,severity:pe.Error,code:he.AbstractEntityImplements,entity:d});p.push(i)}if(d.extends&&!d.extends.abstract){const i=new Mi({id:d.id+"--"+d.extends.id+"--"+he.AbstractExtendingNonAbstractEntity,message:`Entity "${d.name}" with id "${d.id}" is abstract but extends entity "${d.extends.name}" with id "${d.extends.id}" which is non-abstract`,severity:pe.Error,code:he.AbstractExtendingNonAbstractEntity,entity:d,firstRelationship:d.extends});p.push(i)}return p}function fUi(d){const p=[];if(d.extends&&d.extends.static){const i=new Mi({id:d.id+"--"+d.extends.id+"--"+he.NonStaticExtendingStaticEntity,message:`Entity "${d.name}" with id "${d.id}" is non-static but extends entity "${d.extends.name}" with id "${d.extends.id}" which is static`,severity:pe.Error,code:he.NonStaticExtendingStaticEntity,entity:d,firstRelationship:d.extends});p.push(i)}return p}function yUi(d){const p=[];if(d.extends&&d.extends.abstract){const i=new Mi({id:d.id+"--"+d.extends.id+"--"+he.NonAbstractExtendingAbstractEntity,message:`Entity "${d.name}" with id "${d.id}" is non-abstract but extends entity "${d.extends.name}" with id "${d.extends.id}" which is abstract`,severity:pe.Error,code:he.NonAbstractExtendingAbstractEntity,entity:d,firstRelationship:d.extends});p.push(i)}return p}function jx(d,p){const n=[...d.project.entities].filter(s=>s.id!==d.id);return xv(d,[Ji,wc],n,p)}const hUi=Object.freeze(Object.defineProperty({__proto__:null,getBaseMethodsNotImplemented:eKe,getBasePropertiesNotImplemented:QUe,validate:XUe,validateAsync:YUe,validateCanBecomeAbstract:cUi,validateCanBecomeNonAbstract:yUi,validateCanBecomeNonStatic:fUi,validateCanBecomeStatic:pUi,validateCanExtendEntity:uUi,validateCanImplementEntity:dUi,validateDefinitionEntityName:jx},Symbol.toStringTag,{value:"Module"}));function mUi(d,p){const i=[];if(d.parent)if(d.id===d.parent)i.push(new De({id:`${d.id}--${d.parent}--${ne.SelfReference}`,code:ne.SelfReference,severity:pe.Error,message:`Entity of type "${d.type}" with id "${d.id}", has a reference to itself at 'parent'. This is not allowed. Change the reference string or the 'entityId' property of the reference object.`}));else{const n=p.get(d.parent);n?[o.Project,o.DataType].includes(n.type)||i.push(new De({id:`${d.id}--${d.parent}--${ne.InvalidParentReference}`,code:ne.InvalidParentReference,severity:pe.Error,message:`Entity of type "${d.type}" with id "${d.id}", has a parent reference that isn't pointing to an entity of type 'project' or 'data-type'.`})):i.push(new De({id:`${d.id}--${d.parent}--${ne.ReferencedEntityNotFound}`,code:ne.ReferencedEntityNotFound,severity:pe.Error,message:`Entity of type "${d.type}" with id "${d.id}", is referencing an entity with id "${d.parent}" that isn't yet found in the project. Perhaps it should be created first. Or perhaps the ID is incorrect.`}))}return d.implements&&Array.isArray(d.implements)?d.implements.forEach(n=>{if(d.id===n){i.push(new De({id:`${d.id}--${n}--${ne.SelfReference}`,code:ne.SelfReference,severity:pe.Error,message:`Entity of type "${d.type}" with id "${d.id}", has a reference to itself at one of the 'implements' references. This is not allowed. Change the reference string or the 'entityId' property of the reference object.`}));return}const s=p.get(n);s?[o.DefinitionEntity,o.BuiltInBaseEntity].includes(s.type)?s.abstract||i.push(new De({id:`${d.id}--${n}--${ne.InvalidImplementsReference}`,code:ne.InvalidImplementsReference,severity:pe.Error,message:`Entity of type "${d.type}" with id "${d.id}", has an 'implements' reference that isn't pointing to an abstract entity.`})):i.push(new De({id:`${d.id}--${n}--${ne.InvalidImplementsReference}`,code:ne.InvalidImplementsReference,severity:pe.Error,message:`Entity of type "${d.type}" with id "${d.id}", has an 'implements' reference that isn't pointing to an entity of type 'definition-entity' or 'built-in-base-entity'.`})):i.push(new De({id:`${d.id}--${n}--${ne.ReferencedEntityNotFound}`,code:ne.ReferencedEntityNotFound,severity:pe.Error,message:`Entity of type "${d.type}" with id "${d.id}", is referencing an entity with id "${n}" that isn't yet found in the project. Perhaps it should be created first. Or perhaps the ID is incorrect.`}))}):i.push(new De({id:`${d.id}--${Ie.InvalidObjectStructure}`,code:Ie.InvalidObjectStructure,severity:pe.Error,message:`Entity of type "${d.type}" with id "${d.id}", has an 'implements' property that isn't an array.`})),d.extends&&Array.isArray(d.extends)&&d.extends.forEach(n=>{const s=p.get(n);s?[o.DefinitionEntity,o.BuiltInBaseEntity].includes(s.type)?s.abstract&&i.push(new De({id:`${d.id}--${n}--${ne.InvalidExtendsReference}`,code:ne.InvalidExtendsReference,severity:pe.Error,message:`Entity of type "${d.type}" with id "${d.id}", has an 'extends' reference that isn't pointing to a non-abstract entity. Did you want to use the property 'implements', which holds a list of references to absract entities, instead?`})):i.push(new De({id:`${d.id}--${n}--${ne.InvalidExtendsReference}`,code:ne.InvalidExtendsReference,severity:pe.Error,message:`Entity of type "${d.type}" with id "${d.id}", has an 'extends' reference that isn't pointing to an entity of type 'definition-entity' or 'built-in-base-entity'.`})):i.push(new De({id:`${d.id}--${n}--${ne.ReferencedEntityNotFound}`,code:ne.ReferencedEntityNotFound,severity:pe.Error,message:`Entity of type "${d.type}" with id "${d.id}", is referencing an entity with id "${n}" that isn't yet found in the project. Perhaps it should be created first. Or perhaps the ID is incorrect.`}))}),i}var IA=(d=>(d.Extends="extends",d.Implements="implements",d))(IA||{});const bi=class bi extends kr{constructor(i,n){super(i);I(this,"initialData");I(this,"id");I(this,"name");I(this,"codeName",null);I(this,"description",null);I(this,"x");I(this,"y");I(this,"static");I(this,"abstract");I(this,"type",o.DefinitionEntity);I(this,"additionalProperties",!1);I(this,"properties",[]);I(this,"allPropertiesImplement",null);I(this,"additionalPropertiesDataType",null);I(this,"methods",[]);I(this,"abstractMethods",[]);I(this,"extends",null);I(this,"implements",[]);I(this,"project");I(this,"errors",[]);I(this,"parent");I(this,"detachedDependents",{});I(this,"knownVersions",null);I(this,"activeVersion",!1);I(this,"initialized",!1);I(this,"startedInitialization",!1);I(this,"suggestedProperties",[]);I(this,"suggestedMethods",[]);this.initialData=i,this.project=n,this.id=i.id,this.name=i.name,this.description=i.description,this.x=i.x,this.y=i.y,this.codeName=i.codeName,this.static=i.static,this.abstract=i.abstract}static new(i=null){return{id:x.UUID.uuid(),version:x.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||M().toISOString(),author:(i==null?void 0:i.author)||x.sessionAuthor,previousVersion:null,deleted:!1,deletable:!0,editable:!0,type:o.DefinitionEntity,additionalProperties:!1,additionalPropertiesDataType:null,allPropertiesImplement:null,name:"",codeName:null,description:"",static:!1,abstract:!1,properties:[],methods:[],abstractMethods:[],extends:null,implements:[],x:0,y:0,parent:null}}static fromGenerationTarget(i,n){let s=n;if(i.parent){const v=re(i.parent);s=n.get(v)}const c=[];i.implements&&i.implements.forEach(v=>{c.push(n.get(v)||n.getBuiltIn(v))});let e=null;i.extends&&(e=n.get(i.extends)||n.getBuiltIn(i.extends));const y={id:i.id,version:x.UUID.uuid(),createdAt:M().toISOString(),author:x.sessionAuthor,previousVersion:null,deleted:!1,name:i.name,deletable:!0,editable:!0,type:o.DefinitionEntity,codeName:i.codeName||null,description:i.description,static:i.static,abstract:i.abstract,additionalProperties:i.additionalProperties||!1,allPropertiesImplement:null,additionalPropertiesDataType:null,properties:[],methods:[],abstractMethods:[],extends:e,implements:c,x:0,y:0,parent:s},m=ye(y,n);return m.setParent(s,null),m}static validateGenerationTarget(i,n){let s=JSON.parse(JSON.stringify(i));const c=[],e=mUi(s,n),y=Px(s,n);c.push(...e,...y,...Nr(s));const m=s.parent?n.get(s.parent):null;if(m&&m.type===o.DataType){const v=m;v.entity&&c.push(new De({id:`${i.id}--${ne.NewEntityWouldOverriteExisting}`,code:ne.NewEntityWouldOverriteExisting,severity:pe.Error,message:`The entity of type '${i.type}' with id '${i.id}' can't be added to the 'parent' entity with id '${v.id}' because it already has an 'entity' child. Data type entities can only have one 'entity' as children.
390
+ ${cA}`})),{errors:n,modifiedData:i}}onProjectInitialized(i,n=this.project.addChangeSet(new q(this.project,x.sessionAuthor,new Date().toISOString(),this,!0,"on-property-received-project-initialized"))){return Pk(this,n),n==null||n.attemptAutoclose("on-property-received-project-initialized",this.id),this}subscribeDependents(i){return i.forEach(n=>{this.detachedDependents[n.entity.id]||(this.detachedDependents[n.entity.id]=n)}),this}unsubscribeDependents(i){return i.forEach(n=>{this.detachedDependents[n.entity.id]&&delete this.detachedDependents[n.entity.id]}),this}syncDependents(i=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,"sync-dependents"))){const n=[],s=[],c=[],e=[];return Object.values(this.detachedDependents).forEach(y=>{const m=y.entity.afterAllChildrenInitialized(i);n.push(...m.updated),s.push(...m.added),c.push(...m.removed),e.push(...m.affected)}),i==null||i.attemptAutoclose("sync-dependents",this.id),{updated:D(n),added:D(s),removed:D(c),affected:D(e),self:this}}onDetachedDependencyRemoved(i,n,s){const c=[],e=[],y=[],m=[];if(n==="property-implements-field"&&(this.removeImplementation(i,s),c.push(this)),n==="property-extends-field"){const{updated:v,added:E,removed:b,affected:w}=this.remove({ignoreUpstream:!1},s);c.push(...v),e.push(...E),y.push(...b),m.push(...w)}return{updated:D(c),added:D(e),removed:D(y),affected:D(m),self:this}}onDetachedDependencyRestored(i,n,s){const c=[],e=[],y=[],m=[];if(n==="property-implements-field"&&(this.addImplementation(i,s),c.push(this)),n==="property-extends-field"){const{updated:v,added:E,removed:b,affected:w}=this.restore({},s);c.push(...v),e.push(...E),y.push(...b),m.push(...w)}return{updated:D(c),added:D(e),removed:D(y),affected:D(m),self:this}}unsubscribeFromDependencies(){var i,n,s,c,e,y,m;return this.implements.forEach(v=>{this.project.getBuiltIn(v.id)||v.unsubscribeDependents([{entity:this,field:"property-implements-field"}])}),(n=(i=this.extends)==null?void 0:i.unsubscribeDependents)==null||n.call(i,[{entity:this,field:"property-extends-field"}]),(e=(c=(s=this.dataType)==null?void 0:s.entity)==null?void 0:c.unsubscribeDependents)==null||e.call(c,[{entity:this,field:"property-data-type-entity-field"}]),(m=(y=this.dataType)==null?void 0:y.unsubscribeDependents)==null||m.call(y,[{entity:this,field:"property-data-type-field"}]),this.project.off(ii.PROJECT_INITIALIZED,this.onProjectInitialized),this}subscribeToDependencies(){var i,n,s,c,e,y,m;return this.implements.forEach(v=>{this.project.getBuiltIn(v.id)||v.subscribeDependents([{entity:this,field:"property-implements-field"}])}),(n=(i=this.extends)==null?void 0:i.subscribeDependents)==null||n.call(i,[{entity:this,field:"property-extends-field"}]),(e=(c=(s=this.dataType)==null?void 0:s.entity)==null?void 0:c.subscribeDependents)==null||e.call(c,[{entity:this,field:"property-data-type-entity-field"}]),(m=(y=this.dataType)==null?void 0:y.subscribeDependents)==null||m.call(y,[{entity:this,field:"property-data-type-field"}]),oUi(this)&&this.project.on(ii.PROJECT_INITIALIZED,this.onProjectInitialized),this}increaseVersion(i){if(i&&!M(i).isValid())throw new Error(`The shared timestamp '${i}' is not a valid ISO 8601 date string.`);return i&&M(i).isSame(M(this.createdAt))?this:(this.previousVersion=this.version,this.version=x.UUID.uuid(),this.createdAt=M(i).toISOString()||M().toISOString(),this)}captureVersion(){var n;const i=((n=this.knownVersions)==null?void 0:n.get(this.version))||new ti(this,this.project);return i.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,i):new Map([[this.version,i]]),i.defaultValue=this.defaultValue,i.dataType=this.dataType,i.implements=[...this.implements],i.extends=this.extends,i.parent=this.parent,this}recursiveCaptureUpstreamVersions(i){const n=[],s=[],c=[],e=[];if(this.parent&&this.parent.type!==o.PrimitiveEntity&&this.parent.type!==o.BuiltInBaseEntity){this.parent.increaseVersion(i);const y=this.parent.recursiveCaptureUpstreamVersions(i);n.push(this.parent,...y.updated),s.push(...y.added),c.push(...y.removed)}return{updated:D(n),added:D(s),removed:D(c),affected:D(e),self:this}}async restoreVersion(i){var m;const n=[],s=[],c=[],e=[];if(this.version===i)return{updated:D(n),added:D(s),removed:D(c),affected:D(e),self:this};if(!this.knownVersions){const v=new Map;for(const[E,b]of this.knownVersions||new Map){if(v.set(E,b),b.activeVersion=!1,b.knownVersions)for(const[w,P]of b.knownVersions)v.set(w,P);b.knownVersions=null}}let y=(m=this.knownVersions)==null?void 0:m.get(i);if(!y){const v=await this.APILoadVersion({},i);if(!v)throw new Error(`Version with id '${i}' for entity with id '${this.id}' not found.`);y=new ti(v,this.project)}return this.metaSync(y.toShallowJSON(),null),this.previousVersion=y.previousVersion,this.version=y.version,this.createdAt=y.createdAt,this.author=y.author,this.deleted=y.deleted,this.defaultValue=y.defaultValue,this.dataType=y.dataType,this.implements=[...y.implements],this.parent=y.parent,{updated:D(n),added:D(s),removed:D(c),affected:D(e),self:this}}updateWithShallowTransfer(i,n=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,_.UpdateWithShallowTransfer))){if(!this.checkCanEdit(this,n))return J.Logger.warn(`[updateWithShallowTransfer] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),n==null||n.attemptAutoclose(_.UpdateWithShallowTransfer,this.id),this;if(this.metaSync(i,n),this.version=i.version,this.createdAt=i.createdAt,this.author=i.author,this.deleted=i.deleted,this.previousVersion=i.previousVersion,this.unsubscribeFromDependencies(),i.parent){const c=re(i.parent),e=this.project.get(c),y=this.parent;if(y&&y.id!==(e==null?void 0:e.id)&&this.removeFromParent(n),e)this.setParent(e,n),this.addSelfToProject(n);else throw n==null||n.attemptAutoclose(_.UpdateWithShallowTransfer,this.id),new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${c}' that isn't found in the project`)}else throw n==null||n.attemptAutoclose(_.UpdateWithShallowTransfer,this.id),new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(i.implements.forEach(c=>{const e=re(c),y=this.project.get(e);if(y)this.addImplementation(y,n);else throw new Error(`${Fr(this.type)} with id '${this.id}' has a 'implements' reference "${e}" which is missing in the project`)}),this.implements.filter(c=>{const e=re(c);return!i.implements.find(y=>re(y)===e)}).forEach(c=>{this.removeImplementation(c,n)}),i.extends){const c=re(i.extends),e=this.project.get(c);if(e)this.setExtends(e,n);else if(c)throw new Error(`${Fr(this.type)} with id '${this.id}' has a 'extends' reference "${c}" which is missing in the project`)}else this.setExtends(null,n);if(i.dataType){const c=re(i.dataType),e=this.project.get(c);e&&this.setDataType(e,n)}else this.setDataType(null,n);if(i.defaultValue){const c=re(i.defaultValue),e=this.project.get(c);e&&this.setDefaultValue(e,n)}else this.setDefaultValue(null,n);return this.captureVersion(),this.subscribeToDependencies(),n==null||n.attemptAutoclose(_.UpdateWithShallowTransfer,this.id),this}hydrateAncestors(){const i=[],n=[],s=[],c=[];if(this.initialData.parent){const e=re(this.initialData.parent),y=this.project.get(e);if(y)this.setParent(y,null);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${e}' that isn't found in the project`)}else throw new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if((this.initialData.implements||[]).forEach(e=>{const y=re(e),m=this.project.get(y);if(m)this.addImplementation(m,null),i.push(m);else throw new Error(`${Fr(this.type)} with id '${this.id}' has a 'implements' reference "${y}" which is missing in the project`)}),this.initialData.extends){const e=re(this.initialData.extends),y=this.project.get(e);if(y)this.setExtends(y,null),i.push(y);else if(e)throw new Error(`${Fr(this.type)} with id '${this.id}' has a 'extends' reference "${e}" which is missing in the project`)}return{updated:D(i),added:D(n),removed:D(s),affected:D(c),self:this}}afterAllChildrenInitialized(i=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,_.AfterAllChildrenInitialized))){if(!this.checkCanEdit(this,i))return J.Logger.warn(`[afterAllChildrenInitialized] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(_.AfterAllChildrenInitialized,this.id),{updated:[],added:[],removed:[],affected:[],self:this};const n=[],s=[],c=[],e=[];if(this.initialized=!0,this.parent.type===o.DefinitionEntity&&this.parentRelationType!==yc.AllPropertiesImplementationTarget){let X=this.index||0;const se=this.parent.properties.filter(fe=>!fe.deleted&&fe.id!==this.id);se.length&&(X>se.length+1?X=se.length:X<0&&(X=0)),se.find(fe=>(fe.index||0)===X&&!fe.deleted)&&se.filter(fe=>(fe.index||0)>=X&&!fe.deleted).forEach(fe=>{fe.metaSync({index:(fe.index||0)+1},i),i==null||i.add(fe,Z.Updated),n.push(fe)}),this.metaSync({index:X},i)}const{updated:y,added:m,removed:v,affected:E}=this.syncWithImplementation(i);n.push(...y),s.push(...m),c.push(...v),e.push(...E);const{updated:b,added:w,removed:P,affected:$}=Pk(this,i);n.push(...b),s.push(...w),c.push(...P),e.push(...$);const{updated:L,added:U,removed:K,affected:H}=this.syncWithExtension(i);return n.push(...L),s.push(...U),c.push(...K),e.push(...H),this.captureVersion(),i==null||i.attemptAutoclose(_.AfterAllChildrenInitialized,this.id),{updated:D(n),added:D(s),removed:D(c),affected:D(e),self:this}}addSelfToProject(i=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,"add-self-to-project"))){const n=[this],s=[],c=[],e=[];return this.parentRelationType===yc.AllPropertiesImplementationTarget?this.parent.setAllPropertiesImplement(this,i):this.parent.addProperty(this,i),n.push(this.parent),this.subscribe(),this.subscribeToDependencies(),i==null||i.attemptAutoclose("add-self-to-project",this.id),{updated:D(n),added:D(s),removed:D(c),affected:D(e),self:this}}setParent(i,n=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,_.SetParent))){var s;return this.checkCanEditWithCounterpartAndSideEffects(this,i,_.SetParent,n)?(((s=this.parent)==null?void 0:s.id)!==(i==null?void 0:i.id)&&(this.parent=i,n&&(n==null||n.add(this,Z.Updated))),n==null||n.attemptAutoclose(_.SetParent,this.id),this):this}addImplementation(i,n=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,_.AddImplementation))){return this.checkCanEdit(this,n)?(this.implements.includes(i)||(this.implements.push(i),n==null||n.add(this,Z.Updated)),n==null||n.attemptAutoclose(_.AddImplementation,this.id),this):(J.Logger.warn(`[addImplementation] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),n==null||n.attemptAutoclose(_.AddImplementation,this.id),this)}removeImplementation(i,n=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,_.RemoveImplementation))){return this.checkCanEdit(this,n)?(this.implements.includes(i)&&(this.implements=this.implements.filter(s=>s.id!==i.id),n==null||n.add(this,Z.Updated)),n==null||n.attemptAutoclose(_.RemoveImplementation,this.id),this):(J.Logger.warn(`[removeImplementation] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),n==null||n.attemptAutoclose(_.RemoveImplementation,this.id),this)}setExtends(i,n=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,_.SetExtends))){var s;return this.checkCanEdit(this,n)?(((s=this.extends)==null?void 0:s.id)!==(i==null?void 0:i.id)&&(this.extends=i,this.subscribeToDependencies(),n&&(n==null||n.add(this,Z.Updated))),n==null||n.attemptAutoclose(_.SetExtends,this.id),this):(J.Logger.warn(`[setExtends] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),n==null||n.attemptAutoclose(_.SetExtends,this.id),this)}initChildren(i=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,"init-children"))){if(this.initialized||this.startedInitialization)return this;if(this.startedInitialization=!0,this.initialData.defaultValue&&(this.defaultValue=ye(this.initialData.defaultValue,this.project),this.defaultValue.setParent(this,null),this.defaultValue.initChildren(i)),this.initialData.dataType){const n=ye(this.initialData.dataType,this.project);n.setParent(this,null),n.initChildren(i),this.dataType=n}if(this.implements=this.initialData.implements.map(n=>ye(n,this.project)),this.initialData.extends){const n=ye(this.initialData.extends,this.project);this.setExtends(n,null)}return this.subscribeToDependencies(),this.afterAllChildrenInitialized(i),i==null||i.attemptAutoclose("init-children",this.id),this}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(i,n=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,"meta-sync"))){const s=$r(this,i,n),c=xr(this,s),e=this.toMeta();return this.name=s.name!==void 0?s.name:e.name,this.codeName=s.codeName!==void 0?s.codeName:e.codeName,this.description=s.description!==void 0?s.description:e.description,this.abstract=s.abstract!==void 0?s.abstract:e.abstract,this.private=s.private!==void 0?s.private:e.private,this.index=s.index||(s.index!==0?e.index:0),this.static=s.static!==void 0?s.static:e.static,this.hidden=s.hidden!==void 0?s.hidden:e.hidden,this.constant=s.constant!==void 0?s.constant:e.constant,this.interactive=s.interactive!==void 0?s.interactive:e.interactive,this.required=s.required!==void 0?s.required:e.required,this.unique=s.unique!==void 0?s.unique:e.unique,super.baseMetaSync(s,this,n),s.deleted===!0&&!e.deleted?n==null||n.add(this,Z.Removed):s.deleted===!1&&e.deleted?n==null||n.add(this,Z.Added):c&&(n==null||n.add(this,Z.Updated)),n==null||n.attemptAutoclose("meta-sync",this.id),this}async APILoad(i=Ge,...n){return await ti.repository.APILoad(this.id,...n),this}async APICreate(i=Ge,...n){return await ti.repository.APICreate(this.toShallowJSON(),...n),this}async APIUpdate(i=Ge,...n){return await ti.repository.APIUpdate(this.toShallowJSON(),...n),this}async APIDelete(i=Ge,...n){return await ti.repository.APIDelete(this.toShallowJSON(),...n),this}async APIClone(i=Ge,...n){return await ti.repository.APIClone(this.id,...n),this}async APILoadVersion(i=Ge,n,...s){return await ti.repository.APILoadVersion(this.id,n,...s)}removeFromParent(i=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,_.RemoveFromParent))){if(!this.checkCanEdit(this,i))return J.Logger.warn(`[removeFromParent] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(_.RemoveFromParent,this.id),{added:[],updated:[],removed:[],affected:[],self:this};const n=[],s=[],c=[],e=[];return this.parent.type===o.DefinitionEntity&&(this.parentRelationType===yc.AllPropertiesImplementationTarget?this.parent.removeAllPropertiesImplement(i):this.parent.removeProperty(this,i),e.push(this.parent)),i==null||i.attemptAutoclose(_.RemoveFromParent,this.id),{added:D(c),updated:D(n),removed:D(s),affected:D(e),self:this}}remove({ignoreUpstream:i}={ignoreUpstream:!1},n=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,_.RemoveEntity))){var m;if(!this.checkCanDelete(this,n))return J.Logger.warn(`[remove] User is not allowed to delete or edit this ${this.type} entity with id: ${this.id}`),n==null||n.event({id:`${_.RemoveEntity}-${this.id}`,action:_.RemoveEntity,owner:this,errorReason:ir.ActionOwnerEntityNonDeletable,rootAction:((m=n==null?void 0:n.self)==null?void 0:m.id)===this.id&&(n==null?void 0:n.autoCloseActionName)===_.RemoveEntity}),n==null||n.attemptAutoclose(_.RemoveEntity,this.id),{added:[],updated:[],removed:[],affected:[],self:this};const s=[],c=[],e=[],y=[];if(n!=null&&n.hasRemoved(this.id))return n==null||n.attemptAutoclose(_.RemoveEntity,this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(c.push(this),this.unsubscribe(),this.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},n),Object.values(this.detachedDependents).forEach(v=>{const{updated:E,removed:b,added:w}=v.entity.onDetachedDependencyRemoved(this,v.field,n);s.push(...E),c.push(...b),e.push(...w)}),this.defaultValue){const{updated:v,removed:E}=this.defaultValue.remove({ignoreUpstream:!0},n);s.push(...v),c.push(...E)}if(this.dataType){const{updated:v,removed:E}=this.dataType.remove({ignoreUpstream:!0},n);s.push(...v),c.push(...E)}if(!i){const v=this.removeFromParent(n);e.push(...v.added),s.push(...v.updated),c.push(...v.removed),y.push(...v.affected)}return n==null||n.attemptAutoclose(_.RemoveEntity,this.id),{added:D(e),updated:D(s),removed:D(c),affected:D(y),self:this}}restore({}={},i=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,_.RestoreEntity))){if(!this.checkCanEdit(this,i))return J.Logger.warn(`[restore] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(_.RestoreEntity,this.id),{added:[],updated:[],removed:[],affected:[],self:this};const n=[],s=[],c=[],e=[];if(i!=null&&i.hasAdded(this.id))return i==null||i.attemptAutoclose(_.RestoreEntity,this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},i),Object.values(this.detachedDependents).forEach(y=>{const{updated:m,removed:v,added:E}=y.entity.onDetachedDependencyRestored(this,y.field,i);s.push(...m),c.push(...v),n.push(...E)}),this.defaultValue){const{updated:y}=this.defaultValue.restore({},i);s.push(...y)}if(this.dataType){const{updated:y}=this.dataType.restore({},i);s.push(...y)}return this.parent.type===o.DefinitionEntity&&(this.parentRelationType===yc.AllPropertiesImplementationTarget?this.parent.removeAllPropertiesImplement(i):this.parent.addProperty(this,i),e.push(this.parent)),i==null||i.attemptAutoclose(_.RestoreEntity,this.id),{added:D(n),updated:D(s),removed:D(c),affected:D(e),self:this}}toFlat(i=new Set){var s,c;return i.has(this.id)?[]:(i.add(this.id),[this,...((s=this.defaultValue)==null?void 0:s.toFlat(i))||[],...((c=this.dataType)==null?void 0:c.toFlat(i))||[],...this.parent.toFlat(i)])}toFlatIds(i=new Set){var s,c;if(i.has(this.id))return[];if(i.add(this.id),!this.parent)throw new Error(`Property with id '${this.id}' has no parent and cannot be flattened`);return[this.id,...((s=this.defaultValue)==null?void 0:s.toFlatIds(i))||[],...((c=this.dataType)==null?void 0:c.toFlatIds(i))||[],...this.parent.toFlatIds(i)]}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,codeName:this.codeName,description:this.description,index:this.index,hidden:this.hidden,private:this.private,abstract:this.abstract,required:this.required,unique:this.unique,constant:this.constant,interactive:this.interactive,static:this.static,type:this.type,editable:this.editable,deletable:this.deletable,name:this.name}}toJSON(i=new Set){var n,s,c;return i.has(this.id)?this.toReference():(i.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,editable:this.editable,deletable:this.deletable,name:this.name,codeName:this.codeName,description:this.description,index:this.index,private:this.private,unique:this.unique,required:this.required,static:this.static,constant:this.constant,interactive:this.interactive,abstract:this.abstract,hidden:this.hidden,parentRelationType:this.parentRelationType,defaultValue:((n=this.defaultValue)==null?void 0:n.toJSON(i))||null,dataType:((s=this.dataType)==null?void 0:s.toJSON(i))||null,implements:this.implements.map(e=>e.toJSON(i)),extends:((c=this.extends)==null?void 0:c.toJSON(i))||null,parent:this.parent.toReference()})}toJSONClone(i=pt){var s,c,e,y,m,v,E;let n;return(s=i.seenEntityMaps)!=null&&s.has(this.id)?n=i.seenEntityMaps.get(this.id):(n=i.newId||jr(this,this.project,i.uuidStrategy),i.seenEntityMaps&&i.seenEntityMaps.set(this.id,n)),(c=i.seenEntities)!=null&&c.has(n)||(e=i.seenEntities)!=null&&e.has(this.id)?this.toReference({seenEntityMaps:i.seenEntityMaps}):((y=i.seenEntities)==null||y.add(n),(m=i.seenEntities)==null||m.add(this.id),{id:n,version:x.UUID.uuid(),createdAt:i.timestamp||M().toISOString(),author:x.sessionAuthor,previousVersion:null,deleted:!1,type:this.type,editable:this.editable,deletable:this.deletable,name:this.name,codeName:this.codeName,description:this.description,index:this.index,unique:this.unique,private:this.private,required:this.required,static:this.static,constant:this.constant,interactive:this.interactive,abstract:this.abstract,hidden:this.hidden,parentRelationType:this.parentRelationType,defaultValue:((v=this.defaultValue)==null?void 0:v.toJSONClone({...i,newId:null}))||null,dataType:((E=this.dataType)==null?void 0:E.toJSONClone({...i,newId:null}))||null,implements:this.implements.map(b=>this.project.getBuiltIn(b.id)?b.toJSON(i.seenEntities):b.toJSONClone({...i,newId:null})),extends:(()=>{var b;return this.extends&&this.project.getBuiltIn(this.extends.id)?this.extends.toJSON():((b=this.extends)==null?void 0:b.toJSONClone({...i,newId:null}))||null})(),parent:this.parent.toReference({seenEntityMaps:i.seenEntityMaps})})}toReference(i=pt){var s;let n=this.id;return(s=i.seenEntityMaps)!=null&&s.has(this.id)&&(n=i.seenEntityMaps.get(this.id)),{id:n+"--"+x.UUID.uuid()+"--ref",type:o.GenericReference,entityId:n,version:this.version,entityType:this.type}}toShallowJSON(i=pt){var s,c,e,y;let n=this.id;return(s=i.seenEntityMaps)!=null&&s.has(this.id)&&(n=i.seenEntityMaps.get(this.id)),{id:n,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,name:this.name,codeName:this.codeName,description:this.description,type:this.type,editable:this.editable,deletable:this.deletable,index:this.index,private:this.private,required:this.required,unique:this.unique,abstract:this.abstract,static:this.static,constant:this.constant,interactive:this.interactive,hidden:this.hidden,parentRelationType:this.parentRelationType,defaultValue:((c=this.defaultValue)==null?void 0:c.toReference(i))||null,dataType:((e=this.dataType)==null?void 0:e.toReference(i))||null,implements:this.implements.map(m=>m.toReference(i)),extends:((y=this.extends)==null?void 0:y.toReference(i))||null,parent:this.parent.toReference(i)}}toFlatJSON(i=new Set){var s,c;return i.has(this.id)?[]:(i.add(this.id),[this.toShallowJSON(),...((s=this.defaultValue)==null?void 0:s.toFlatJSON(i))||[],...((c=this.dataType)==null?void 0:c.toFlatJSON(i))||[],...this.implements.flatMap(e=>e.toFlatJSON(i)),...this.parent.toFlatJSON(i)])}toGenerationTarget(){var i;return{id:this.id,name:this.name,description:this.description,type:this.type,private:this.private,required:this.required,abstract:this.abstract,static:this.static,parentRelationType:this.parentRelationType,implements:this.implements.map(n=>n.id),extends:(i=this.extends)==null?void 0:i.id,parent:this.parent.id}}toFlatGenerationTarget(i=new Set){var s,c;return i.has(this.id)?[]:(i.add(this.id),[this.toGenerationTarget(),...((s=this.defaultValue)==null?void 0:s.toFlatGenerationTarget(i))||[],...((c=this.dataType)==null?void 0:c.toFlatGenerationTarget(i))||[],...this.implements.flatMap(e=>e.toFlatGenerationTarget(i))])}clearErrors(){var i,n;return this.errors=[],(i=this.defaultValue)==null||i.clearErrors(),(n=this.dataType)==null||n.clearErrors(),this}validate(){return this.errors=zUe(this),{success:!0}}async validateAsync(i={}){const n=J.YieldTracker.from(i);return this.errors=await WUe(this,{tracker:n}),{success:!0}}getErrors(){var n,s;return[...this.errors,...((n=this.defaultValue)==null?void 0:n.getErrors())||[],...((s=this.dataType)==null?void 0:s.getErrors())||[]]}async getErrorsAsync(i={}){const n=J.YieldTracker.from(i),s=[...this.errors];if(await n.tick(),this.defaultValue){const c=await this.defaultValue.getErrorsAsync({tracker:n});s.push(...c)}if(this.dataType){const c=await this.dataType.getErrorsAsync({tracker:n});s.push(...c)}return s}getShallowErrors(){return this.errors}implement(i,n=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,"implement-self-as-property")),s=null){var v;const c=s||x.UUID.uuid(),e=ti.new(n);e.id=c,e.name=this.name,e.description=this.description,e.index=this.index,e.private=this.private,e.required=this.required,e.static=this.static,e.constant=this.constant,e.unique=this.unique,e.hidden=this.hidden,e.interactive=this.interactive,e.parent=i.toReference(),e.implements=[this.toJSON()];const y=ye(e,this.project);y.hydrateAncestors(),y.addSelfToProject(n),n==null||n.add(y,Z.Added),y.initChildren(n);const m=(v=this.defaultValue)==null?void 0:v.clone(n,y,x.UUID.uuid());return m&&(m.editable=!0,m.deletable=!0),y}clone(i=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,_.CloneEntity)),n=null,s=null,c=!0){var b,w;const e=Pr(n,this),y=s||x.UUID.uuid(),m=n||this.parent,v={hidden:!1,id:y,version:x.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||M().toISOString(),author:(i==null?void 0:i.author)||"1",previousVersion:null,deleted:!1,type:this.type,editable:!0,deletable:!0,name:this.name,codeName:this.codeName,description:this.description,index:this.index,private:this.private,constant:this.constant,unique:this.unique,interactive:this.interactive,required:this.required,abstract:this.abstract,static:this.static,parentRelationType:this.parentRelationType,defaultValue:null,dataType:null,implements:this.implements.map(P=>P.toJSON()),extends:this.extends,parent:m.toReference()},E=Ui(v,e);if(E.hydrateAncestors(),E.setParent(m,i),c&&(E.subscribe(),E.addSelfToProject(i)),E.initChildren(i),i==null||i.add(E,Z.Added),this.dataType&&this.project.diggestedBuiltInBaseEntitiesIds.has(this.dataType.id))E.setDataType(e.getBuiltIn(this.dataType.id),i);else{const P=((b=this.dataType)==null?void 0:b.clone(i,E,x.UUID.uuid(),c))||null;P&&E.setDataType(P,i)}if(this.defaultValue){const P=(w=this.defaultValue)==null?void 0:w.clone(i,E,x.UUID.uuid(),c);E.setDefaultValue(P||null,i)}return this.implements.length&&this.implements.forEach(P=>{const $=e.get(P.id)||e.getBuiltIn(P.id);if($){E.addImplementation($,i);return}}),E.addSelfToProject(null),i==null||i.attemptAutoclose(_.CloneEntity,this.id),E}setDataType(i,n=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,_.SetDataType))){if(!this.checkCanEdit(this,n))return J.Logger.warn(`[setDataType] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),n==null||n.attemptAutoclose(_.SetDataType,this.id),this;const s=this.dataType;return(s==null?void 0:s.id)!==(i==null?void 0:i.id)&&(s==null||s.remove({ignoreUpstream:!0},n),this.dataType=i,this.subscribeToDependencies(),n==null||n.add(this,Z.Affected)),n==null||n.attemptAutoclose(_.SetDataType,this.id),this}removeDataType(i=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,_.RemoveDataType))){return this.checkCanEdit(this,i)?(this.dataType&&(this.dataType.remove({ignoreUpstream:!0},i),i==null||i.add(this,Z.Affected),this.dataType=null),i==null||i.attemptAutoclose(_.RemoveDataType,this.id),this):(J.Logger.warn(`[removeDataType] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(_.RemoveDataType,this.id),this)}getDataType(i=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,"get-data-type"))){return i==null||i.attemptAutoclose("get-data-type",this.id),this.dataType}getDefaultValue(){var c;console.log("[getDefaultValue] Resolving default value for property",this.id," name:",this.name),console.log(`[getDefaultValue] implements:
391
+ - ${this.implements.map(e=>e.id+" name: "+e.name).join(`
392
+ - `)}`);let i=null;for(const e of this.implements){const y=e.getDefaultValue();(!i||qn(i))&&y&&(i=y)}let n=this.defaultValue;const s=(c=this.extends)==null?void 0:c.getDefaultValue();return qn(n)&&s&&!qn(s)&&(n=s),qn(n)&&i&&!qn(i)&&(n=i),n}setDefaultValue(i,n=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,"set-default-value"))){if(!this.checkCanEdit(this,n))return J.Logger.warn(`[setDefaultValue] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),n==null||n.attemptAutoclose("set-default-value",this.id),this;const s=this.defaultValue;return(s==null?void 0:s.id)!==(i==null?void 0:i.id)&&(s==null||s.remove({ignoreUpstream:!0},n),this.defaultValue=i,n==null||n.add(this,Z.Affected)),n==null||n.attemptAutoclose("set-default-value",this.id),this}syncWithImplementation(i=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,"sync-with-implementation"))){var P,$,L,U,K,H,X,se,ee,fe,de;if(!this.checkCanEdit(this,i))return J.Logger.warn(`[syncWithImplementation] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose("sync-with-implementation",this.id),{added:[],updated:[],removed:[],affected:[],self:this};const n=[],s=[],c=[],e=[];this.parent.type!==o.PrimitiveEntity&&this.interactive&&this.parent.getAllPropertiesImplements().forEach(ve=>{this.addImplementation(ve,i)});let y=null;for(const ce of this.implements)(P=ce.dataType)!=null&&P.isResolved&&(y?($=ce.dataType.orChildrenGroup)!=null&&$.length&&ce.dataType.implementationChooseOne&&(y=ce.dataType):y=ce.dataType);const m=zr(this.dataType,y);if(!this.dataType||!((L=this.dataType)!=null&&L.isResolved)||(U=this.dataType)!=null&&U.isResolved&&(y!=null&&y.isResolved)&&!m.compatible){if(y&&((K=y.orChildrenGroup)!=null&&K.length)&&y.implementationChooseOne){if(!this.dataType||this.dataType&&this.project.diggestedBuiltInBaseEntitiesIds.has(this.dataType.id)){const ve=tr.new(i);ve.parent=this.toReference();const ae=ye(ve,this.project);ae.hydrateAncestors(),i==null||i.add(ae,Z.Added),ae.addSelfToProject(i),ae.afterAllChildrenInitialized(i)}const ce=y.orChildrenGroup.some(ve=>ve.foreignKeyAllowed);if(((X=(H=this.dataType)==null?void 0:H.entity)==null?void 0:X.type)===o.DefinitionEntity&&Si(this.dataType.entity,Re.PERSISTED_ENTITY)&&ce){const ve=$Ue(this.dataType.entity);ve&&this.dataType.setForeignKeyRef(ve,i),(se=this.dataType)==null||se.setEntity(null,i)}else{const ve=y.orChildrenGroup.find(ae=>{var me;return((me=ae.entity)==null?void 0:me.id)===Q["primitive-entity"].string.id});if(ve)(ee=this.dataType)==null||ee.setEntity(ve.entity,i);else{const ae=y.orChildrenGroup.filter(_e=>_e.isResolved),me=ae.filter(_e=>{var Ne;return((Ne=_e.entity)==null?void 0:Ne.type)===o.PrimitiveEntity});me.length?(fe=this.dataType)==null||fe.setEntity(me[0].entity,i):ae.length&&((de=this.dataType)==null||de.setEntity(ae[0].entity,i))}}}else if(y&&this.project.diggestedBuiltInBaseEntitiesIds.has(y.id))this.setDataType(y,i);else if(y){const ce=y.clone(i,this,x.UUID.uuid(),!0);this.setDataType(ce,i),s.push(ce)}}if(!this.defaultValue){let ce=null;for(const ve of this.implements){const ae=ve.getDefaultValue();ae&&(ce=ae)}if(ce){const ve=ce.clone(i,this,x.UUID.uuid(),!0);this.setDefaultValue(ve,i),s.push(ve)}}let v=!1,E=!1,b=!1,w=!1;return this.implements.forEach(ce=>{ce.required&&(v=!0),ce.constant&&(b=!0),ce.unique&&(E=!0),ce.static&&(w=!0)}),this.metaSync({required:v||this.required,constant:b||this.constant,unique:E||this.unique,static:w||this.static},i),i==null||i.attemptAutoclose("sync-with-implementation",this.id),{updated:D(n),added:D(s),removed:D(c),affected:D(e),self:this}}syncWithExtension(i=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,"sync-with-extension"))){var v,E;if(!this.checkCanEdit(this,i))return J.Logger.warn(`[syncWithExtension] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose("sync-with-extension",this.id),{added:[],updated:[],removed:[],affected:[],self:this};const n=[],s=[],c=[],e=[];if(!this.extends)return i==null||i.attemptAutoclose("sync-with-extension",this.id),{added:[],updated:[],removed:[],affected:[],self:this};const y={...this.extends.toMeta()};if(delete y.id,delete y.version,delete y.createdAt,delete y.previousVersion,delete y.author,delete y.index,this.metaSync(y,i),n.push(this),!this.extends.dataType)return i==null||i.attemptAutoclose("sync-with-extension",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(!this.dataType){const b=tr.new(i);b.parent=this.toReference();const w=ye(b,this.project);w.hydrateAncestors(),i==null||i.add(w,Z.Added),w.addSelfToProject(i),w.afterAllChildrenInitialized(i)}if(zr(this.dataType,this.extends.dataType).compatible||(v=this.dataType)==null||v.merge(this.extends.dataType,i),this.extends.defaultValue&&!this.defaultValue){const b=this.extends.defaultValue.clone(i,this,x.UUID.uuid(),!0);this.setDefaultValue(b,i),s.push(b)}else this.extends.defaultValue?this.extends.defaultValue&&this.defaultValue&&!Wke(this.defaultValue,this.extends.defaultValue)&&(this.defaultValue.merge(this.extends.defaultValue,i),n.push(this.defaultValue)):((E=this.defaultValue)==null||E.remove({ignoreUpstream:!0},i),this.defaultValue=null,e.push(this));return i==null||i.attemptAutoclose("sync-with-extension",this.id),{updated:D(n),added:D(s),removed:D(c),affected:D(e),self:this}}implementAsInputMap(i=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,"implement-as-return-declaration")),n,s){const c=ds.new(i);c.id=s||c.id,c.name=this.name,c.description=this.description,c.parent=n.toReference(),c.declaration=this.toJSON();const e=Ui(c,this.project);if(e.hydrateAncestors(),e.addSelfToProject(i),i==null||i.add(e,Z.Added),e.initChildren(i),this.dataType)if(this.project.diggestedBuiltInBaseEntitiesIds.has(this.dataType.id))e.setDataType(this.dataType,i),i==null||i.add(e,Z.Affected);else{const y=this.dataType.clone(i,e);e.setDataType(y,i)}if(this.defaultValue){const y=this.defaultValue.clone(i,e);e.setDefaultValue(y,i)}return i==null||i.attemptAutoclose("implement-as-return-declaration",this.id),e}};I(ti,"repository",{APICreate:async(i,...n)=>i,APIUpdate:async(i,...n)=>i,APIDelete:async(i,...n)=>i,APIClone:async(i,...n)=>{},APILoad:async(i,...n)=>null,APILoadVersion:async(i,n,...s)=>null}),I(ti,"type",o.Property),I(ti,"USER_MANAGED_PARENT_TYPES",[o.DefinitionEntity]),I(ti,"PARENT_TYPES",[...ti.USER_MANAGED_PARENT_TYPES,o.PrimitiveEntity,o.BuiltInBaseEntity]),I(ti,"MUTABLE_BASE_PROPERTIES",["name","codeName","description","private","abstract","static","required","constant","unique","interactive"]),I(ti,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),I(ti,"BASE_PROPERTIES",[...ti.MUTABLE_BASE_PROPERTIES,...ti.INMUTABLE_BASE_PROPERTIES]),I(ti,"MUTABLE_META_PROPERTIES",[...ti.MUTABLE_BASE_PROPERTIES,"index"]),I(ti,"INMUTABLE_META_PROPERTIES",[...ti.INMUTABLE_BASE_PROPERTIES]),I(ti,"META_PROPERTIES",[...ti.MUTABLE_META_PROPERTIES,...ti.INMUTABLE_META_PROPERTIES]),I(ti,"MUTABLE_UPSTREAM_PROPERTIES",[]),I(ti,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","implements","extends"]),I(ti,"UPSTREAM_PROPERTIES",[...ti.MUTABLE_UPSTREAM_PROPERTIES,...ti.INMUTABLE_UPSTREAM_PROPERTIES]),I(ti,"MUTABLE_DOWNSTREAM_PROPERTIES",["dataType"]),I(ti,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),I(ti,"DOWNSTREAM_PROPERTIES",[...ti.MUTABLE_DOWNSTREAM_PROPERTIES,...ti.INMUTABLE_DOWNSTREAM_PROPERTIES]),I(ti,"PROPERTIES",[...ti.META_PROPERTIES,...ti.UPSTREAM_PROPERTIES,...ti.DOWNSTREAM_PROPERTIES]);let ka=ti;async function YUe(d,p={}){var E,b;const i=J.YieldTracker.from(p),n=d.implements.flatMap(w=>tKe(d,w)),s=iKe(d,d.extends),c=nKe(d),e=rKe(d),y=jx(d),m=[...n,...s,...c,...e,...y],v=Lt(d.errors,m);await i.tick();for(const w of d.properties)await w.validateAsync({tracker:i});for(const w of d.methods)await w.validateAsync({tracker:i});for(const w of d.abstractMethods)await w.validateAsync({tracker:i});return await((E=d.allPropertiesImplement)==null?void 0:E.validateAsync({tracker:i})),await((b=d.additionalPropertiesDataType)==null?void 0:b.validateAsync({tracker:i})),v}function XUe(d){var m,v;const p=d.implements.flatMap(E=>tKe(d,E)),i=iKe(d,d.extends),n=nKe(d),s=rKe(d),c=jx(d);d.properties.forEach(E=>{E.validate()}),d.methods.flatMap(E=>E.validate()),d.abstractMethods.flatMap(E=>E.validate()),(m=d.allPropertiesImplement)==null||m.validate(),(v=d.additionalPropertiesDataType)==null||v.validate();const e=[...p,...i,...n,...s,...c];return Lt(d.errors,e)}function QUe(d,p){const i=p.properties.filter(c=>c.abstract),n=[];let s=[...d.properties];return i.forEach(c=>{const e=s.find(y=>!!y.implements.find(m=>m.id===c.id));e?s=s.filter(y=>y.id!==e.id):n.push(c)}),n}function eKe(d,p){const i=p.abstractMethods,n=[];let s=[...d.methods];return i.forEach(c=>{const e=s.find(y=>{var m;return((m=y.implements)==null?void 0:m.id)===c.id});e?s=s.filter(y=>y.id!==e.id):n.push(c)}),n}function tKe(d,p){const i=[];if(!p.abstract){const E=$t({id:d.id+"--"+he.ImplementingNonAbstractEntity,message:`Entity "${d.name}" with id "${d.id}" is implementing a non-abstract entity "${p.name}" with id "${p.id}"`,severity:pe.Error,code:he.ImplementingNonAbstractEntity,entity:d});return i.push(E.error),i}const n=p.properties.filter(E=>E.abstract),s=[];let c=[...d.properties];n.forEach(E=>{const b=c.find(w=>!!w.implements.find(P=>P.id===E.id));b?c=c.filter(w=>w.id!==b.id):s.push(E)}),s.length&&s.forEach(E=>{const b=$t({id:d.id+"--"+he.MissingPropertyImplementation+"--"+E.id,message:`Property "${E.name}" with id "${E.id}" of entity "${p.name}" with id "${p.id}" is not implemented when entity "${d.name}" with id "${d.id}" implements it`,severity:pe.Error,code:he.MissingPropertyImplementation,entity:d});i.push(b.error)});const e=[];let y=[...d.methods];p.abstractMethods.forEach(E=>{const b=y.find(w=>{var P;return((P=w.implements)==null?void 0:P.id)===E.id});b?y=y.filter(w=>w.id!==b.id):e.push(E)}),e.length&&e.forEach(E=>{const b=$t({id:d.id+"--"+he.MissingMethodImplementation+"--"+E.id,message:`Method "${E.name}" with id "${E.id}" of entity "${p.name}" with id "${p.id}" is not implemented when entity "${d.name}" with id "${d.id}" implements it`,severity:pe.Error,code:he.MissingMethodImplementation,entity:d});i.push(b.error)});const m=[];p.properties.forEach(E=>{const b=c.find(w=>w.name===E.name);b&&m.push([b,E])}),m.length&&m.forEach(([E])=>{const b=$t({id:d.id+"--"+Ie.PropertyOverwritesOtherSiblingWithSameName+"--"+E.id,message:`Property "${E.name}" with id "${E.id}" of entity "${d.name}" with id "${d.id}" overwrites the property with the same name from the base entity "${p.name}" with id "${p.id}"`,severity:pe.Error,code:Ie.PropertyOverwritesOtherSiblingWithSameName,entity:d});i.push(b.error)});const v=[];return p.methods.forEach(E=>{const b=y.find(w=>w.name===E.name);b&&v.push([b,E])}),v.length&&v.forEach(([E])=>{const b=$t({id:d.id+"--"+Ie.MethodOverwritesOtherSiblingWithSameName+"--"+E.id,message:`Method "${E.name}" with id "${E.id}" of entity "${d.name}" with id "${d.id}" overwrites the method with the same name from the base entity "${p.name}" with id "${p.id}"`,severity:pe.Error,code:Ie.MethodOverwritesOtherSiblingWithSameName,entity:d});i.push(b.error)}),i}function iKe(d,p){const i=[];if(!p)return i;const n=[];if(!d.abstract&&p.abstract){const c=$t({id:d.id+"--"+p.id+"--"+he.NonAbstractExtendingAbstractEntity,message:`Entity "${d.name}" with id "${d.id}" is not-abstract but is extending an abstract entity "${p.name}" with id "${p.id}"`,severity:pe.Error,code:he.NonAbstractExtendingAbstractEntity,entity:d,firstRelationship:p});return i.push(c.error),i}if(d.abstract&&!p.abstract){const c=$t({id:d.id+"--"+p.id+"--"+he.AbstractExtendingNonAbstractEntity,message:`Entity "${d.name}" with id "${d.id}" is abstract but is extending an non-abstract entity "${p.name}" with id "${p.id}"`,severity:pe.Error,code:he.AbstractExtendingNonAbstractEntity,entity:d,firstRelationship:p});return i.push(c.error),i}d.properties.forEach(c=>{const e=p.properties.find(y=>{var m;return y.name===c.name&&((m=c.extends)==null?void 0:m.id)!==y.id});c.implements.find(y=>y.id===(e==null?void 0:e.id))||e&&n.push(c)}),n.length&&n.forEach(c=>{const e=$t({id:d.id+"--"+Ie.PropertyOverwritesOtherSiblingWithSameName,message:`Property "${c.name}" with id "${c.id}" of entity "${d.name}" with id "${d.id}" overwrites the property with the same name from the extended entity "${p.name}" with id "${p.id}"`,severity:pe.Error,code:Ie.PropertyOverwritesOtherSiblingWithSameName,entity:d});i.push(e.error)});const s=[];return d.methods.forEach(c=>{var y;const e=p.methods.find(m=>{var v;return m.name===c.name&&((v=c.extends)==null?void 0:v.id)!==m.id});((y=c.implements)==null?void 0:y.id)!==(e==null?void 0:e.id)&&e&&s.push(c)}),s.length&&s.forEach(c=>{const e=$t({id:d.id+"--"+Ie.MethodOverwritesOtherSiblingWithSameName,message:`Method "${c.name}" with id "${c.id}" of entity "${d.name}" with id "${d.id}" overwrites the method with the same name from the extended entity "${p.name}" with id "${p.id}"`,severity:pe.Error,code:Ie.MethodOverwritesOtherSiblingWithSameName,entity:d});i.push(e.error)}),i}function rKe(d){const p=[];if(!d.properties.length){const i=$t({id:d.id+"--"+he.NoProperties,message:"No properties implemented",severity:pe.Warning,code:he.NoProperties,entity:d});p.push(i.error)}return p}function nKe(d){const p=[];if(d.abstract){if(d.methods.length){const i=$t({id:d.id+"--"+he.AbstractEntityWithNonAbstractMethods,message:`Entity "${d.name}" with id "${d.id}" is marked as abstract but has non-abstract methods`,severity:pe.Error,code:he.AbstractEntityWithNonAbstractMethods,entity:d});p.push(i.error)}if(d.properties.some(i=>!i.abstract)){const i=$t({id:d.id+"--"+he.AbstractEntityWithNonAbstractProperties,message:`Entity "${d.name}" with id "${d.id}" is marked as abstract but has non-abstract properties`,severity:pe.Error,code:he.AbstractEntityWithNonAbstractProperties,entity:d});p.push(i.error),d.properties.forEach(n=>{if(!n.abstract){const s=$t({id:d.id+"--"+he.StaticEntityWithNonStaticProperties+"--"+n.id,message:`Property "${n.name}" with id "${n.id}" of entity "${d.name}" with id "${d.id}" is not marked as abstract but the entity is marked as abstract`,severity:pe.Error,code:he.StaticEntityWithNonStaticProperties,entity:d});p.push(s.error)}})}}else{if(d.abstractMethods.length){const i=$t({id:d.id+"--"+he.AbstractPropertyInNonAbstractEntity,message:`Entity "${d.name}" with id "${d.id}" is not marked as abstract but has abstract methods`,severity:pe.Error,code:he.AbstractPropertyInNonAbstractEntity,entity:d});p.push(i.error)}d.properties.some(i=>i.abstract)&&d.properties.forEach(i=>{if(i.abstract){const n=$t({id:d.id+"--"+he.AbstractPropertyInNonAbstractEntity+"--"+i.id,message:`Property "${i.name}" with id "${i.id}" of entity "${d.name}" with id "${d.id}" is marked as abstract but the entity is not marked as abstract`,severity:pe.Error,code:he.AbstractPropertyInNonAbstractEntity,entity:d,firstRelationship:i});p.push(n.error)}})}return d.static&&d.properties.some(i=>!i.static)&&d.properties.forEach(i=>{if(!i.static){const n=$t({id:d.id+"--"+he.NonStaticPropertyInStaticEntity+"--"+i.id,message:`Property "${i.name}" with id "${i.id}" of entity "${d.name}" with id "${d.id}" is not marked as static but the entity is marked as static`,severity:pe.Error,code:he.NonStaticPropertyInStaticEntity,entity:d,firstRelationship:i});p.push(n.error)}}),p}function dUi(d,p){const i=[],n=Zn(p);if(!p.abstract){const e=new Mi({id:d.id+"--"+p.id+"--"+he.ImplementingNonAbstractEntity,message:`Entity "${d.name}" with id "${d.id}" is implementing a non-abstract built-in entity "${p.name}" with id "${p.id}"`,severity:pe.Error,code:he.ImplementingNonAbstractEntity,entity:d,firstRelationship:p});i.push(e)}const s=d.implements.filter(e=>e.id!==p.id);if(d.abstract){const e=new Mi({id:d.id+"--"+p.id+"--"+he.AbstractEntityImplements,message:`Entity "${d.name}" with id "${d.id}" is marked as abstract and cannot implement built-in entity "${p.name}" with id "${p.id}"`,severity:pe.Error,code:he.AbstractEntityImplements,entity:d,firstRelationship:p});i.push(e)}if(d.static&&!p.static){const e=new Mi({id:d.id+"--"+p.id+"--"+he.StaticImplementingNonStaticEntity,message:`Entity "${d.name}" with id "${d.id}" is marked as static and cannot implement non-static built-in entity "${p.name}" with id "${p.id}"`,severity:pe.Error,code:he.StaticImplementingNonStaticEntity,entity:d,firstRelationship:p});i.push(e)}if(!d.static&&p.static){const e=new Mi({id:d.id+"--"+p.id+"--"+he.NonStaticImplementingStaticEntity,message:`Entity "${d.name}" with id "${d.id}" is not marked as static and cannot implement static built-in entity "${p.name}" with id "${p.id}"`,severity:pe.Error,code:he.NonStaticImplementingStaticEntity,entity:d,firstRelationship:p});i.push(e)}return s.length&&s.forEach(e=>{if(e.type===o.BuiltInBaseEntity){const y=n.filter(m=>m.id!==e.id);y.length&&y.forEach(m=>{if(m.id!==e.id){const v=new Mi({id:d.id+"--"+m.id+"--"+e.id+"--"+he.ImplementsIncompatibleEntities,message:`Entity "${d.name}" with id "${d.id}" is implementing built-in entity "${m.name}" with id "${m.id}" but also implements entity "${e.name}" with id "${e.id}" which is incompatible`,severity:pe.Error,code:he.ImplementsIncompatibleEntities,entity:d,firstRelationship:m,secondRelationship:e});i.push(v)}})}else{Zn(e).forEach(E=>{const b=n.filter(w=>w.id!==E.id);b.length&&b.forEach(w=>{if(w.id!==E.id){const P=new Mi({id:d.id+"--"+w.id+"--"+E.id+"--"+he.ImplementsIncompatibleEntities,message:`Entity "${d.name}" with id "${d.id}" is implementing built-in entity "${w.name}" with id "${w.id}" but also implements entity "${E.name}" with id "${E.id}" which is incompatible`,severity:pe.Error,code:he.ImplementsIncompatibleEntities,entity:d,firstRelationship:w,secondRelationship:E});i.push(P)}})});const m=od(p.ownDeclaredProperties,e.ownDeclaredProperties,Ie.PropertyOverwritesOtherImplementedEntitysPropertyWithSameImplementation,Ie.PropertyOverwritesOtherImplementedEntitysPropertyWithSameName);i.push(...m.errors);const v=od(p.abstractMethods,[...e.abstractMethods,...e.methods],Ie.MethodOverwritesOtherImplementedEntitysMethodWithSameImplementation,Ie.MethodOverwritesOtherImplementedEntitysMethodWithSameName);i.push(...v.errors)}}),D(d.extends?Zn(d.extends):[]).forEach(e=>{if(!n.find(y=>y.id===e.id)){const y=new Mi({id:d.id+"--"+p.id+"--"+e.id+"--"+he.ExtendsIncompatibleEntities,message:`Entity "${d.name}" with id "${d.id}" is implementing built-in entity "${p.name}" with id "${p.id}" but also extends entity "${e.name}" with id "${e.id}" which is incompatible`,severity:pe.Error,code:he.ExtendsIncompatibleEntities,entity:d,firstRelationship:p,secondRelationship:e});i.push(y)}}),i}function uUi(d,p,i=!1){var v,E;const n=[],s=Zn(p);if(!d.abstract&&p.abstract){const b=$t({id:d.id+"--"+p.id+"--"+he.NonAbstractExtendingAbstractEntity,message:`Entity "${d.name}" with id "${d.id}" is not-abstract but is extending an abstract entity "${p.name}" with id "${p.id}"`,severity:pe.Error,code:he.NonAbstractExtendingAbstractEntity,entity:d,firstRelationship:p});n.push(b.error)}if(d.abstract&&!p.abstract){const b=$t({id:d.id+"--"+p.id+"--"+he.AbstractExtendingNonAbstractEntity,message:`Entity "${d.name}" with id "${d.id}" is abstract but is extending an non-abstract entity "${p.name}" with id "${p.id}"`,severity:pe.Error,code:he.AbstractExtendingNonAbstractEntity,entity:d,firstRelationship:p});n.push(b.error)}if(!d.static&&p.static){const b=$t({id:d.id+"--"+p.id+"--"+he.NonStaticExtendingStaticEntity,message:`Entity "${d.name}" with id "${d.id}" is not static but is extending a static entity "${p.name}" with id "${p.id}"`,severity:pe.Error,code:he.NonStaticExtendingStaticEntity,entity:d,firstRelationship:p});n.push(b.error)}if(d.static&&!p.static){const b=$t({id:d.id+"--"+p.id+"--"+he.StaticExtendingNonStaticEntity,message:`Entity "${d.name}" with id "${d.id}" is static but is extending an non-static entity "${p.name}" with id "${p.id}"`,severity:pe.Error,code:he.StaticExtendingNonStaticEntity,entity:d,firstRelationship:p});n.push(b.error)}if(!lf(p)){const b=$t({id:d.id+"--"+p.id+"--"+he.ExtendingNonInteractiveEntity,message:`Entity "${d.name}" with id "${d.id}" is extending an non-interactive entity "${p.name}" with id "${p.id}"`,severity:pe.Error,code:he.ExtendingNonInteractiveEntity,entity:d,firstRelationship:p});n.push(b.error)}if(d.extends&&((v=d.extends)==null?void 0:v.id)!==p.id)if(((E=d.extends)==null?void 0:E.type)===o.BuiltInBaseEntity){const b=s.filter(w=>{var P;return w.id!==((P=d.extends)==null?void 0:P.id)});b.length&&b.forEach(w=>{var P,$,L,U;if(w.id!==((P=d.extends)==null?void 0:P.id)){const K=$t({id:d.id+"--"+w.id+"--"+(($=d.extends)==null?void 0:$.id)+"--"+he.ExtendsIncompatibleEntities,message:`Entity "${d.name}" with id "${d.id}" is extending built-in entity "${w.name}" with id "${w.id}" but also extends entity "${(L=d.extends)==null?void 0:L.name}" with id "${(U=d.extends)==null?void 0:U.id}" which is incompatible`,severity:pe.Error,code:he.ExtendsIncompatibleEntities,entity:d,firstRelationship:w,secondRelationship:d.extends});n.push(K.error)}})}else{Zn(d.extends).forEach(K=>{const H=s.filter(X=>X.id!==K.id);H.length&&H.forEach(X=>{if(X.id!==K.id){const se=new Mi({id:d.id+"--"+X.id+"--"+K.id+"--"+he.ImplementsIncompatibleEntities,message:`Entity "${d.name}" with id "${d.id}" is extending built-in entity "${X.name}" with id "${X.id}" but also extends or implements entity "${K.name}" with id "${K.id}" which is incompatible`,severity:pe.Error,code:he.ImplementsIncompatibleEntities,entity:d,firstRelationship:X,secondRelationship:K});n.push(se)}})});const w=!!Zn(d.extends).find(K=>K.id===p.id);let P=[...d.extends.properties];w&&(P=P.filter(K=>!p.properties.find(H=>H.id===K.id||H.name===K.name||!!K.implements.find(X=>X.id===H.id))));let $=[...d.extends.methods];w&&($=$.filter(K=>!p.methods.find(H=>{var X;return H.id===K.id||H.name===K.name||H.id===((X=K.implements)==null?void 0:X.id)})));const L=od(p.ownDeclaredProperties,P,Ie.PropertyOverwritesOtherExtendedEntitysPropertyWithSameImplementation,Ie.PropertyOverwritesOtherExtendedEntitysPropertyWithSameName);n.push(...L.errors);const U=od(p.abstractMethods,$,Ie.MethodOverwritesOtherExtendedEntitysMethodWithSameImplementation,Ie.MethodOverwritesOtherExtendedEntitysMethodWithSameName);n.push(...U.errors)}i&&J.Logger.log("self.implements.length",d.implements.length),d.implements.length&&d.implements.forEach(b=>{if(b.type===o.BuiltInBaseEntity){const w=s.filter(P=>P.id!==b.id);w.length&&w.forEach(P=>{if(P.id!==b.id){const $=new Mi({id:d.id+"--"+P.id+"--"+b.id+"--"+he.ImplementsIncompatibleEntities,message:`Entity "${d.name}" with id "${d.id}" is implementing built-in entity "${P.name}" with id "${P.id}" but also implements entity "${b.name}" with id "${b.id}" which is incompatible`,severity:pe.Error,code:he.ImplementsIncompatibleEntities,entity:d,firstRelationship:P,secondRelationship:b});n.push($)}})}else{Zn(b).forEach(L=>{const U=s.filter(K=>K.id!==L.id);U.length&&U.forEach(K=>{if(K.id!==L.id){const H=new Mi({id:d.id+"--"+K.id+"--"+L.id+"--"+he.ImplementsIncompatibleEntities,message:`Entity "${d.name}" with id "${d.id}" is implementing built-in entity "${K.name}" with id "${K.id}" but also implements entity "${L.name}" with id "${L.id}" which is incompatible`,severity:pe.Error,code:he.ImplementsIncompatibleEntities,entity:d,firstRelationship:K,secondRelationship:L});n.push(H)}})});const P=od(p.ownDeclaredProperties,b.ownDeclaredProperties,Ie.PropertyOverwritesOtherImplementedEntitysPropertyWithSameImplementation,Ie.PropertyOverwritesOtherImplementedEntitysPropertyWithSameName);n.push(...P.errors);const $=od(p.abstractMethods,[...b.abstractMethods,...b.methods],Ie.MethodOverwritesOtherImplementedEntitysMethodWithSameImplementation,Ie.MethodOverwritesOtherImplementedEntitysMethodWithSameName);n.push(...$.errors)}});const e=od(d.ownDeclaredProperties,p.ownDeclaredProperties,Ie.PropertyOverwritesOtherSiblingWithSameImplementation,Ie.PropertyOverwritesOtherSiblingWithSameName);n.push(...e.errors);const y=od(p.methods,p.abstractMethods,Ie.MethodOverwritesOtherSiblingWithSameImplementation,Ie.MethodOverwritesOtherSiblingWithSameName);return n.push(...y.errors),D(d.extends?Zn(d.extends):[]).forEach(b=>{if(!s.find(w=>w.id===b.id)){const w=new Mi({id:d.id+"--"+p.id+"--"+b.id+"--"+he.ImplementsIncompatibleEntities,message:`Entity "${d.name}" with id "${d.id}" is extending built-in entity "${p.name}" with id "${p.id}" but also extends entity "${b.name}" with id "${b.id}" which is incompatible`,severity:pe.Error,code:he.ImplementsIncompatibleEntities,entity:d,firstRelationship:p,secondRelationship:b});n.push(w)}}),n}function pUi(d){const p=[];if(d.implements.forEach(i=>{if(!i.static){const n=new Mi({id:d.id+"--"+i.id+"--"+he.StaticImplementingNonStaticEntity,message:`Entity "${d.name}" with id "${d.id}" is static but implements entity "${i.name}" with id "${i.id}" which is non-static`,severity:pe.Error,code:he.StaticImplementingNonStaticEntity,entity:d,firstRelationship:i});p.push(n)}}),d.extends&&!d.extends.static){const i=new Mi({id:d.id+"--"+d.extends.id+"--"+he.StaticExtendingNonStaticEntity,message:`Entity "${d.name}" with id "${d.id}" is static but extends entity "${d.extends.name}" with id "${d.extends.id}" which is non-static`,severity:pe.Error,code:he.StaticExtendingNonStaticEntity,entity:d,firstRelationship:d.extends});p.push(i)}return p}function cUi(d){const p=[];if(d.implements.length){const i=new Mi({id:d.id+"--"+he.AbstractEntityImplements,message:`Entity "${d.name}" with id "${d.id}" cannot be marked as abstract because it implements other entities`,severity:pe.Error,code:he.AbstractEntityImplements,entity:d});p.push(i)}if(d.extends&&!d.extends.abstract){const i=new Mi({id:d.id+"--"+d.extends.id+"--"+he.AbstractExtendingNonAbstractEntity,message:`Entity "${d.name}" with id "${d.id}" is abstract but extends entity "${d.extends.name}" with id "${d.extends.id}" which is non-abstract`,severity:pe.Error,code:he.AbstractExtendingNonAbstractEntity,entity:d,firstRelationship:d.extends});p.push(i)}return p}function fUi(d){const p=[];if(d.extends&&d.extends.static){const i=new Mi({id:d.id+"--"+d.extends.id+"--"+he.NonStaticExtendingStaticEntity,message:`Entity "${d.name}" with id "${d.id}" is non-static but extends entity "${d.extends.name}" with id "${d.extends.id}" which is static`,severity:pe.Error,code:he.NonStaticExtendingStaticEntity,entity:d,firstRelationship:d.extends});p.push(i)}return p}function yUi(d){const p=[];if(d.extends&&d.extends.abstract){const i=new Mi({id:d.id+"--"+d.extends.id+"--"+he.NonAbstractExtendingAbstractEntity,message:`Entity "${d.name}" with id "${d.id}" is non-abstract but extends entity "${d.extends.name}" with id "${d.extends.id}" which is abstract`,severity:pe.Error,code:he.NonAbstractExtendingAbstractEntity,entity:d,firstRelationship:d.extends});p.push(i)}return p}function jx(d,p){const n=[...d.project.entities].filter(s=>s.id!==d.id);return xv(d,[Ji,wc],n,p)}const hUi=Object.freeze(Object.defineProperty({__proto__:null,getBaseMethodsNotImplemented:eKe,getBasePropertiesNotImplemented:QUe,validate:XUe,validateAsync:YUe,validateCanBecomeAbstract:cUi,validateCanBecomeNonAbstract:yUi,validateCanBecomeNonStatic:fUi,validateCanBecomeStatic:pUi,validateCanExtendEntity:uUi,validateCanImplementEntity:dUi,validateDefinitionEntityName:jx},Symbol.toStringTag,{value:"Module"}));function mUi(d,p){const i=[];if(d.parent)if(d.id===d.parent)i.push(new De({id:`${d.id}--${d.parent}--${ne.SelfReference}`,code:ne.SelfReference,severity:pe.Error,message:`Entity of type "${d.type}" with id "${d.id}", has a reference to itself at 'parent'. This is not allowed. Change the reference string or the 'entityId' property of the reference object.`}));else{const n=p.get(d.parent);n?[o.Project,o.DataType].includes(n.type)||i.push(new De({id:`${d.id}--${d.parent}--${ne.InvalidParentReference}`,code:ne.InvalidParentReference,severity:pe.Error,message:`Entity of type "${d.type}" with id "${d.id}", has a parent reference that isn't pointing to an entity of type 'project' or 'data-type'.`})):i.push(new De({id:`${d.id}--${d.parent}--${ne.ReferencedEntityNotFound}`,code:ne.ReferencedEntityNotFound,severity:pe.Error,message:`Entity of type "${d.type}" with id "${d.id}", is referencing an entity with id "${d.parent}" that isn't yet found in the project. Perhaps it should be created first. Or perhaps the ID is incorrect.`}))}return d.implements&&Array.isArray(d.implements)?d.implements.forEach(n=>{if(d.id===n){i.push(new De({id:`${d.id}--${n}--${ne.SelfReference}`,code:ne.SelfReference,severity:pe.Error,message:`Entity of type "${d.type}" with id "${d.id}", has a reference to itself at one of the 'implements' references. This is not allowed. Change the reference string or the 'entityId' property of the reference object.`}));return}const s=p.get(n);s?[o.DefinitionEntity,o.BuiltInBaseEntity].includes(s.type)?s.abstract||i.push(new De({id:`${d.id}--${n}--${ne.InvalidImplementsReference}`,code:ne.InvalidImplementsReference,severity:pe.Error,message:`Entity of type "${d.type}" with id "${d.id}", has an 'implements' reference that isn't pointing to an abstract entity.`})):i.push(new De({id:`${d.id}--${n}--${ne.InvalidImplementsReference}`,code:ne.InvalidImplementsReference,severity:pe.Error,message:`Entity of type "${d.type}" with id "${d.id}", has an 'implements' reference that isn't pointing to an entity of type 'definition-entity' or 'built-in-base-entity'.`})):i.push(new De({id:`${d.id}--${n}--${ne.ReferencedEntityNotFound}`,code:ne.ReferencedEntityNotFound,severity:pe.Error,message:`Entity of type "${d.type}" with id "${d.id}", is referencing an entity with id "${n}" that isn't yet found in the project. Perhaps it should be created first. Or perhaps the ID is incorrect.`}))}):i.push(new De({id:`${d.id}--${Ie.InvalidObjectStructure}`,code:Ie.InvalidObjectStructure,severity:pe.Error,message:`Entity of type "${d.type}" with id "${d.id}", has an 'implements' property that isn't an array.`})),d.extends&&Array.isArray(d.extends)&&d.extends.forEach(n=>{const s=p.get(n);s?[o.DefinitionEntity,o.BuiltInBaseEntity].includes(s.type)?s.abstract&&i.push(new De({id:`${d.id}--${n}--${ne.InvalidExtendsReference}`,code:ne.InvalidExtendsReference,severity:pe.Error,message:`Entity of type "${d.type}" with id "${d.id}", has an 'extends' reference that isn't pointing to a non-abstract entity. Did you want to use the property 'implements', which holds a list of references to absract entities, instead?`})):i.push(new De({id:`${d.id}--${n}--${ne.InvalidExtendsReference}`,code:ne.InvalidExtendsReference,severity:pe.Error,message:`Entity of type "${d.type}" with id "${d.id}", has an 'extends' reference that isn't pointing to an entity of type 'definition-entity' or 'built-in-base-entity'.`})):i.push(new De({id:`${d.id}--${n}--${ne.ReferencedEntityNotFound}`,code:ne.ReferencedEntityNotFound,severity:pe.Error,message:`Entity of type "${d.type}" with id "${d.id}", is referencing an entity with id "${n}" that isn't yet found in the project. Perhaps it should be created first. Or perhaps the ID is incorrect.`}))}),i}var IA=(d=>(d.Extends="extends",d.Implements="implements",d))(IA||{});const bi=class bi extends kr{constructor(i,n){super(i);I(this,"initialData");I(this,"id");I(this,"name");I(this,"codeName",null);I(this,"description",null);I(this,"x");I(this,"y");I(this,"static");I(this,"abstract");I(this,"type",o.DefinitionEntity);I(this,"additionalProperties",!1);I(this,"properties",[]);I(this,"allPropertiesImplement",null);I(this,"additionalPropertiesDataType",null);I(this,"methods",[]);I(this,"abstractMethods",[]);I(this,"extends",null);I(this,"implements",[]);I(this,"project");I(this,"errors",[]);I(this,"parent");I(this,"detachedDependents",{});I(this,"knownVersions",null);I(this,"activeVersion",!1);I(this,"initialized",!1);I(this,"startedInitialization",!1);I(this,"suggestedProperties",[]);I(this,"suggestedMethods",[]);this.initialData=i,this.project=n,this.id=i.id,this.name=i.name,this.description=i.description,this.x=i.x,this.y=i.y,this.codeName=i.codeName,this.static=i.static,this.abstract=i.abstract}static new(i=null){return{id:x.UUID.uuid(),version:x.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||M().toISOString(),author:(i==null?void 0:i.author)||x.sessionAuthor,previousVersion:null,deleted:!1,deletable:!0,editable:!0,type:o.DefinitionEntity,additionalProperties:!1,additionalPropertiesDataType:null,allPropertiesImplement:null,name:"",codeName:null,description:"",static:!1,abstract:!1,properties:[],methods:[],abstractMethods:[],extends:null,implements:[],x:0,y:0,parent:null}}static fromGenerationTarget(i,n){let s=n;if(i.parent){const v=re(i.parent);s=n.get(v)}const c=[];i.implements&&i.implements.forEach(v=>{c.push(n.get(v)||n.getBuiltIn(v))});let e=null;i.extends&&(e=n.get(i.extends)||n.getBuiltIn(i.extends));const y={id:i.id,version:x.UUID.uuid(),createdAt:M().toISOString(),author:x.sessionAuthor,previousVersion:null,deleted:!1,name:i.name,deletable:!0,editable:!0,type:o.DefinitionEntity,codeName:i.codeName||null,description:i.description,static:i.static,abstract:i.abstract,additionalProperties:i.additionalProperties||!1,allPropertiesImplement:null,additionalPropertiesDataType:null,properties:[],methods:[],abstractMethods:[],extends:e,implements:c,x:0,y:0,parent:s},m=ye(y,n);return m.setParent(s,null),m}static validateGenerationTarget(i,n){let s=JSON.parse(JSON.stringify(i));const c=[],e=mUi(s,n),y=Px(s,n);c.push(...e,...y,...Nr(s));const m=s.parent?n.get(s.parent):null;if(m&&m.type===o.DataType){const v=m;v.entity&&c.push(new De({id:`${i.id}--${ne.NewEntityWouldOverriteExisting}`,code:ne.NewEntityWouldOverriteExisting,severity:pe.Error,message:`The entity of type '${i.type}' with id '${i.id}' can't be added to the 'parent' entity with id '${v.id}' because it already has an 'entity' child. Data type entities can only have one 'entity' as children.
391
393
  You can inspect the existing 'entity' field with the 'describe_entity' action. Like so:
392
394
  ${go({describe_entity:v.entity.id})}
393
395
  Alternatively you can update the parent data-type entity with 'update' action to remove the existing value of the field.`}))}return{errors:c,modifiedData:s}}get interactive(){return this.implements.length?this.implements.every(i=>i.interactive):!0}get allMethods(){return D([...this.ownDeclaredMethods,...this.allBaseMethodsFromOriginalParents])}get allProperties(){return D([...this.ownDeclaredProperties,...this.allBasePropertiesFromOriginalParents])}get allBaseMethodsFromOriginalParents(){var s;const i=((s=this.extends)==null?void 0:s.type)===o.DefinitionEntity?this.extends.allMethods:[],n=[...i].filter(c=>!i.some(e=>{var y,m;return e.id!==c.id&&(((y=e.implements)==null?void 0:y.id)===c.id||((m=e.extends)==null?void 0:m.id)===c.id)}));return D([...n,...this.implements.flatMap(c=>{const e=c.type===o.DefinitionEntity?[...c.allMethods]:[];return[...e].filter(m=>!e.some(v=>{var E,b;return v.id!==m.id&&(((E=v.implements)==null?void 0:E.id)===m.id||((b=v.extends)==null?void 0:b.id)===m.id)}))})])}get allBasePropertiesFromOriginalParents(){var c;const i=((c=this.extends)==null?void 0:c.allProperties)||[],n=[...i].filter(e=>!i.some(y=>{var m;return y.id!==e.id&&(!!y.implements.find(v=>v.id===e.id)||((m=y.extends)==null?void 0:m.id)===e.id)}));return D([...n,...this.implements.flatMap(e=>{const y=[...e.allProperties];return[...y].filter(v=>!y.some(E=>{var b;return E.id!==v.id&&(!!E.implements.find(w=>w.id===v.id)||((b=E.extends)==null?void 0:b.id)===v.id)}))})])}get allBasePropertiesFromExtendedAndImplementedEntities(){var c,e;const i=[...((c=this.extends)==null?void 0:c.ownDeclaredProperties)||[],...((e=this.extends)==null?void 0:e.allBasePropertiesFromExtendedAndImplementedEntities)||[]].filter(y=>!y.abstract),n=[...i].filter(y=>!i.some(m=>{var v;return m.id!==y.id&&(!!m.implements.find(E=>E.id===y.id)||((v=m.extends)==null?void 0:v.id)===y.id)})),s=this.implements.reduce((y,m)=>{const v=m.implementedPropertiesFromOriginalParents,E=[...m.ownDeclaredProperties].filter(P=>!P.abstract),b=[...v,...E,...y];return[...b].filter(P=>!!!b.find(L=>{var U;return!!L.implements.find(K=>K.id===P.id)||((U=L.extends)==null?void 0:U.id)===P.id}))},[]);return D([...n,...s])}get allBaseMethodsFromExtendedAndImplementedEntities(){return D([...(this.extends?[this.extends]:[]).reduce((i,n)=>n.type!==o.DefinitionEntity?[]:[...[...n.ownDeclaredMethods,...n.allBaseMethodsFromExtendedAndImplementedEntities].filter(c=>c.type!==o.ActionDescriptor),...i],[]),...this.implements.reduce((i,n)=>n.type!==o.DefinitionEntity?n.abstractMethods:[...[...n.ownDeclaredMethods,...n.allBaseMethodsFromExtendedAndImplementedEntities].filter(c=>c.type!==o.ActionDescriptor),...i],[])])}get extendedPropertiesFromOriginalParents(){var s,c;const i=[...((s=this.extends)==null?void 0:s.ownDeclaredProperties)||[],...((c=this.extends)==null?void 0:c.extendedPropertiesFromOriginalParents)||[]].filter(e=>!e.abstract),n=[...i].filter(e=>!i.some(y=>{var m;return y.id!==e.id&&(!!y.implements.find(v=>v.id===e.id)||((m=y.extends)==null?void 0:m.id)===e.id)}));return D(n)}get implementedPropertiesFromOriginalParents(){return D([...(this.extends?[this.extends]:[]).reduce((i,n)=>{const s=n.implementedPropertiesFromOriginalParents,c=[...n.ownDeclaredProperties].filter(m=>!!m.abstract),e=[...s,...c,...i];return[...e].filter(m=>!!!e.find(E=>{var b;return((b=E.extends)==null?void 0:b.id)===m.id||!!E.implements.find(w=>w.id===m.id)}))},[]),...this.implements.reduce((i,n)=>{const s=n.implementedPropertiesFromOriginalParents,c=[...n.ownDeclaredProperties].filter(m=>!!m.abstract),e=[...s,...c,...i];return[...e].filter(m=>!!!e.find(E=>{var b;return!!E.implements.find(w=>w.id===m.id)||((b=E.extends)==null?void 0:b.id)===m.id}))},[])].filter(i=>!!i.abstract))}get extendedMethodsFromOriginalParents(){return D((this.extends?[this.extends]:[]).reduce((i,n)=>{if(n.type!==o.DefinitionEntity)return[];const s=[...n.ownDeclaredMethods,...n.extendedMethodsFromOriginalParents].filter(c=>c.type!==o.ActionDescriptor);return[...i,...s]},[]))}get implementedMethodsFromOriginalParents(){return D([...(this.extends?[this.extends]:[]).reduce((i,n)=>{const s=n.type===o.DefinitionEntity?n.methods:[],c=[...n.abstractMethods].filter(e=>!s.find(y=>y.name===e.name));return[...s,...c,...i]},[]),...this.implements.reduce((i,n)=>[...n.abstractMethods,...i],[])].filter(i=>i.type===o.ActionDescriptor))}get extendedProperties(){return this.properties.filter(i=>i.isExtendedProperty)}get ownDeclaredProperties(){return this.properties.filter(n=>!n.isExtendedProperty)}get extendedMethods(){return this.methods.filter(i=>i.isExtendedMethod)}get ownDeclaredMethods(){return this.methods.filter(i=>!i.isExtendedMethod)}validateGeneratedUpdate(i){const n=[];return i.parent&&n.push(new De({id:`${this.id}--${ne.InvalidParentUpdate}`,code:ne.InvalidParentUpdate,severity:pe.Error,message:`Entity of type '${this.type}' with id '${this.id}' cannot have the 'parent' property updated. The 'parent' on an '${this.type}', must be the root project as it is a globally declared entity.`})),{errors:n,modifiedData:i}}subscribeDependents(i){return i.forEach(n=>{this.detachedDependents[n.entity.id]||(this.detachedDependents[n.entity.id]=n)}),this}unsubscribeDependents(i){return i.forEach(n=>{this.detachedDependents[n.entity.id]&&delete this.detachedDependents[n.entity.id]}),this}syncDependents(i=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,"sync-dependents"))){const n=[],s=[],c=[],e=[];return Object.values(this.detachedDependents).forEach(y=>{const m=y.entity.afterAllChildrenInitialized(i);n.push(...m.updated),s.push(...m.added),c.push(...m.removed),e.push(...m.affected)}),i==null||i.attemptAutoclose("sync-dependents",this.id),{updated:D(n),added:D(s),removed:D(c),affected:D(e),self:this}}onDetachedDependencyRemoved(i,n,s){const c=[],e=[],y=[],m=[];return n==="implements"&&(this.removeImplementation(i,s),c.push(this)),n==="extends"&&(this.setExtension(null,s),c.push(this)),{updated:D(c),added:D(e),removed:D(y),affected:D(m),self:this}}onDetachedDependencyRestored(i,n,s){const c=[],e=[],y=[],m=[];return n==="implements"&&(this.addImplementation(i,s),c.push(this)),n==="extends"&&(this.setExtension(i,s),c.push(this)),{updated:D(c),added:D(e),removed:D(y),affected:D(m),self:this}}unsubscribeFromDependencies(){return this.implements.forEach(i=>{Hn.includes(i.type)||i.unsubscribeDependents([{entity:this,field:"implements"}])}),this.extends&&(Hn.includes(this.extends.type)||this.extends.unsubscribeDependents([{entity:this,field:"extends"}])),this}subscribeToDependencies(){return this.implements.forEach(i=>{Hn.includes(i.type)||i.subscribeDependents([{entity:this,field:"implements"}])}),this.extends&&(Hn.includes(this.extends.type)||this.extends.subscribeDependents([{entity:this,field:"extends"}])),this}increaseVersion(i){if(i&&!M(i).isValid())throw new Error(`The shared timestamp '${i}' is not a valid ISO 8601 date string.`);return i&&M(i).isSame(M(this.createdAt))?this:(this.previousVersion=this.version,this.version=x.UUID.uuid(),this.createdAt=M(i).toISOString()||M().toISOString(),this)}captureVersion(){var n;const i=((n=this.knownVersions)==null?void 0:n.get(this.version))||new bi(this,this.project);return i.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,i):new Map([[this.version,i]]),i.properties=[...this.properties],i.methods=[...this.methods],i.abstractMethods=[...this.abstractMethods],i.extends=this.extends,i.implements=[...this.implements],i.allPropertiesImplement=this.allPropertiesImplement,i.additionalPropertiesDataType=this.additionalPropertiesDataType,i.parent=this.parent,this}recursiveCaptureUpstreamVersions(i){const n=[],s=[],c=[],e=[];if(this.parent){this.parent.increaseVersion(i);const y=this.parent.recursiveCaptureUpstreamVersions(i);n.push(this.parent,...y.updated),s.push(...y.added),c.push(...y.removed)}return{updated:D(n),added:D(s),removed:D(c),affected:D(e),self:this}}async restoreVersion(i){var m;const n=[],s=[],c=[],e=[];if(this.version===i)return{updated:D(n),added:D(s),removed:D(c),affected:D(e),self:this};if(!this.knownVersions){const v=new Map;for(const[E,b]of this.knownVersions||new Map){if(v.set(E,b),b.activeVersion=!1,b.knownVersions)for(const[w,P]of b.knownVersions)v.set(w,P);b.knownVersions=null}}let y=(m=this.knownVersions)==null?void 0:m.get(i);if(!y){const v=await this.APILoadVersion({},i);if(!v)throw new Error(`Version with id '${i}' for entity with id '${this.id}' not found.`);y=new bi(v,this.project)}return this.metaSync(y.toShallowJSON(),null),this.previousVersion=y.previousVersion,this.version=y.version,this.createdAt=y.createdAt,this.author=y.author,this.deleted=y.deleted,this.properties=[...y.properties],this.methods=[...y.methods],this.abstractMethods=[...y.abstractMethods],this.extends=y.extends,this.implements=[...y.implements],this.allPropertiesImplement=y.allPropertiesImplement,this.additionalPropertiesDataType=y.additionalPropertiesDataType,this.parent=y.parent,{updated:D(n),added:D(s),removed:D(c),affected:D(e),self:this}}updateWithShallowTransfer(i,n=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,_.UpdateWithShallowTransfer))){if(!this.checkCanEdit(this,n))return J.Logger.warn(`[updateWithShallowTransfer] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),n==null||n.attemptAutoclose(_.UpdateWithShallowTransfer,this.id),this;if(this.metaSync(i,n),this.version=i.version,this.createdAt=i.createdAt,this.author=i.author,this.deleted=i.deleted,this.previousVersion=i.previousVersion,this.unsubscribeFromDependencies(),i.parent){const y=re(i.parent),m=this.project.get(y),v=this.parent;if(v&&v.id!==(m==null?void 0:m.id)&&this.removeFromParent(n),m)this.setParent(m,n),this.addSelfToProject(n);else throw n==null||n.attemptAutoclose(_.UpdateWithShallowTransfer,this.id),new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${y}' that isn't found in the project`)}else throw n==null||n.attemptAutoclose(_.UpdateWithShallowTransfer,this.id),new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(i.extends){const y=re(i.extends),m=this.project.get(y);m&&this.setExtension(m,n)}else this.setExtension(null,n);if(i.implements.forEach(y=>{const m=re(y),v=this.project.get(m);if(v)this.addImplementation(v,n);else throw new Error(`${Fr(this.type)} with id '${this.id}' has a 'implements' reference "${m}" which is missing in the project`)}),this.implements.filter(y=>{const m=re(y);return!i.implements.find(v=>re(v)===m)}).forEach(y=>{this.removeImplementation(y,n)}),i.methods.forEach(y=>{const m=re(y),v=this.project.get(m);v&&this.addMethod(v,n)}),this.methods.filter(y=>{const m=re(y);return!i.methods.find(v=>re(v)===m)}).forEach(y=>{this.removeMethod(y,n)}),i.properties.forEach(y=>{const m=re(y),v=this.project.get(m);v&&this.addProperty(v,n)}),this.properties.filter(y=>{const m=re(y);return!i.properties.find(v=>re(v)===m)}).forEach(y=>{this.removeProperty(y,n)}),i.allPropertiesImplement){const y=re(i.allPropertiesImplement),m=this.project.get(y);m&&this.setAllPropertiesImplement(m,n)}else this.setAllPropertiesImplement(null,n);if(i.additionalPropertiesDataType){const y=re(i.additionalPropertiesDataType),m=this.project.get(y);m&&this.setAdditionalPropertiesDataType(m,n)}else this.setAdditionalPropertiesDataType(null,n);return this.captureVersion(),this.subscribeToDependencies(),n==null||n.attemptAutoclose(_.UpdateWithShallowTransfer,this.id),this}hydrateAncestors(){const i=[],n=[],s=[],c=[];if(this.initialData.parent){const e=re(this.initialData.parent),y=this.project.get(e);if(y)this.setParent(y,null),i.push(y);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${e}' that isn't found in the project`)}else throw new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(this.initialData.extends){const e=re(this.initialData.extends),y=this.project.get(e);y&&(this.setExtension(y,null),y.type!==o.BuiltInBaseEntity&&i.push(y))}return this.initialData.implements.forEach(e=>{const y=re(e),m=this.project.get(y);if(m)this.addImplementation(m,null),m.type!==o.BuiltInBaseEntity&&i.push(m);else throw new Error(`${Fr(this.type)} with id '${this.id}' has a 'implements' reference "${y}" which is missing in the project`)}),{updated:D(i),added:D(n),removed:D(s),affected:D(c),self:this}}afterAllChildrenInitialized(i=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,_.AfterAllChildrenInitialized))){if(!this.checkCanEdit(this,i))return J.Logger.warn(`[afterAllChildrenInitialized] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(_.AfterAllChildrenInitialized,this.id),{updated:[],added:[],removed:[],affected:[],self:this};const n=[],s=[],c=[],e=[];this.initialized=!0;const{updated:y,added:m,removed:v,affected:E}=this.syncImplementationProperties(i);n.push(...y),s.push(...m),c.push(...v),e.push(...E);const{updated:b,added:w,removed:P,affected:$}=this.addExtendedProperties(i);n.push(...b),s.push(...w),c.push(...P),e.push(...$);const{updated:L,added:U,removed:K}=this.removeUnrecognizedProperties(i);n.push(...L),s.push(...U),c.push(...K);const{updated:H,added:X,removed:se,affected:ee}=this.syncImplementationMethods(i);n.push(...H),s.push(...X),c.push(...se),e.push(...ee);const{updated:fe,added:de,removed:ce,affected:ve}=this.addExtendedMethods(i);n.push(...fe),s.push(...de),c.push(...ce),e.push(...ve);const{updated:ae,added:me,removed:_e}=this.removeUnrecognizedMethods(i);return n.push(...ae),s.push(...me),c.push(..._e),this.addSuggestions(),this.properties.sort((Ne,ke)=>Ne.index-ke.index),this.captureVersion(),i==null||i.attemptAutoclose(_.AfterAllChildrenInitialized,this.id),{updated:D(n),added:D(s),removed:D(c),affected:D(e),self:this}}addSelfToProject(i=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,"add-self-to-project"))){const n=[this],s=[],c=[],e=[];if(this.parent.type===o.DataType){const y=this.parent;y.entity=this,n.push(y)}else this.project.addDefinitionEntity(this);return this.subscribe(),this.subscribeToDependencies(),i==null||i.attemptAutoclose("add-self-to-project",this.id),{updated:D(n),added:D(s),removed:D(c),affected:D(e),self:this}}setParent(i,n=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,_.SetParent))){var s;return this.checkCanEditWithCounterpartAndSideEffects(this,i,_.SetParent,n)?(((s=this.parent)==null?void 0:s.id)!==(i==null?void 0:i.id)&&(this.parent=i,n&&(n==null||n.add(this,Z.Updated))),n==null||n.attemptAutoclose(_.SetParent,this.id),this):this}setExtension(i,n=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,_.SetExtension))){var s;return this.checkCanEdit(this,n)?(((s=this.extends)==null?void 0:s.id)!==(i==null?void 0:i.id)&&(this.extends=i,this.subscribeToDependencies(),n&&(n==null||n.add(this,Z.Updated))),n==null||n.attemptAutoclose(_.SetExtension,this.id),this):(J.Logger.warn(`[setExtension] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),n==null||n.attemptAutoclose(_.SetExtension,this.id),this)}addImplementation(i,n=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,_.AddImplementation))){return this.checkCanEdit(this,n)?(this.implements.includes(i)||(this.implements.push(i),this.subscribeToDependencies(),n==null||n.add(this,Z.Updated)),n==null||n.attemptAutoclose(_.AddImplementation,this.id),this):(J.Logger.warn(`[addImplementation] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),n==null||n.attemptAutoclose(_.AddImplementation,this.id),this)}removeImplementation(i,n=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,_.RemoveImplementation))){return this.checkCanEdit(this,n)?(this.implements.includes(i)&&(this.implements=this.implements.filter(s=>s.id!==i.id),n==null||n.add(this,Z.Updated)),n==null||n.attemptAutoclose(_.RemoveImplementation,this.id),this):(J.Logger.warn(`[removeImplementation] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),n==null||n.attemptAutoclose(_.RemoveImplementation,this.id),this)}removeProperty(i,n=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,_.RemoveProperty))){return this.checkCanEdit(this,n)?(this.properties.includes(i)&&(this.properties=this.properties.filter(s=>s.id!==i.id),n==null||n.add(this,Z.Updated)),n==null||n.attemptAutoclose(_.RemoveProperty,this.id),this):(J.Logger.warn(`[removeProperty] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),n==null||n.attemptAutoclose(_.RemoveProperty,this.id),this)}addMethod(i,n=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,_.AddMethod))){return this.checkCanEdit(this,n)?(this.methods.includes(i)||(this.methods.push(i),this.suggestedMethods=this.suggestedMethods.filter(s=>s.name!==i.name),n==null||n.add(this,Z.Updated)),n==null||n.attemptAutoclose(_.AddMethod,this.id),this):(J.Logger.warn(`[addMethod] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),n==null||n.attemptAutoclose(_.AddMethod,this.id),this)}removeMethod(i,n=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,_.RemoveMethod))){return this.checkCanEdit(this,n)?(this.methods.includes(i)&&(this.methods=this.methods.filter(s=>s.id!==i.id),n==null||n.add(this,Z.Updated)),n==null||n.attemptAutoclose(_.RemoveMethod,this.id),this):(J.Logger.warn(`[removeMethod] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),n==null||n.attemptAutoclose(_.RemoveMethod,this.id),this)}addProperty(i,n=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,_.AddProperty))){return this.checkCanEdit(this,n)?(this.properties.includes(i)||(this.properties.push(i),this.suggestedProperties=this.suggestedProperties.filter(s=>s.name!==i.name),n==null||n.add(this,Z.Updated)),n==null||n.attemptAutoclose(_.AddProperty,this.id),this):(J.Logger.warn(`[addProperty] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),n==null||n.attemptAutoclose(_.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(n=>n.id!==i.id),this}removeSuggestedMethod(i){return this.suggestedMethods=this.suggestedMethods.filter(n=>n.id!==i.id),this}addAbstractMethod(i,n=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,_.AddAbstractMethod))){return this.checkCanEdit(this,n)?(this.abstractMethods.includes(i)||(this.abstractMethods.push(i),n==null||n.add(this,Z.Updated)),n==null||n.attemptAutoclose(_.AddAbstractMethod,this.id),this):(J.Logger.warn(`[addAbstractMethod] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),n==null||n.attemptAutoclose(_.AddAbstractMethod,this.id),this)}removeAbstractMethod(i,n=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,_.RemoveAbstractMethod))){return this.checkCanEdit(this,n)?(this.abstractMethods.includes(i)&&(this.abstractMethods=this.abstractMethods.filter(s=>s.id!==i.id),n==null||n.add(this,Z.Updated)),n==null||n.attemptAutoclose(_.RemoveAbstractMethod,this.id),this):(J.Logger.warn(`[removeAbstractMethod] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),n==null||n.attemptAutoclose(_.RemoveAbstractMethod,this.id),this)}initChildren(i=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,"init-children"))){if(this.initialized||this.startedInitialization)return this;if(this.startedInitialization=!0,this.properties=this.initialData.properties.map(n=>{const s=ye(n,this.project);return s.setParent(this,null),s.initChildren(i),s}),this.methods=this.initialData.methods.map(n=>{const s=ye(n,this.project);return s.setParent(this,null),s.initChildren(i),s}),this.abstractMethods=this.initialData.abstractMethods.map(n=>{const s=ye(n,this.project);return s.setParent(this,null),s.initChildren(i),s}),this.initialData.extends&&(this.extends=ye(this.initialData.extends,this.project)),this.implements=this.initialData.implements.map(n=>ye(n,this.project)),this.initialData.allPropertiesImplement){const n=ye(this.initialData.allPropertiesImplement,this.project);n.setParent(this,null),n.initChildren(null),this.setAllPropertiesImplement(n,i)}if(this.initialData.additionalPropertiesDataType){const n=ye(this.initialData.additionalPropertiesDataType,this.project);n.setParent(this,null),n.initChildren(null),this.setAdditionalPropertiesDataType(n,i)}return this.subscribeToDependencies(),this.afterAllChildrenInitialized(i),i==null||i.attemptAutoclose("init-children",this.id),this}removeUnrecognizedProperties(i=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,"remove-unrecognized-properties"))){const n=[],s=[],c=[],e=[];let y=[...this.properties];y=y.filter(b=>b.parent.id===this.id),y=y.filter(b=>!b.isExtendedProperty);const m=this.implementedPropertiesFromOriginalParents,v=this.getAllPropertiesImplements();return y.filter(b=>this.interactive&&!b.implements.length?!1:!b.implements.find(P=>!!m.find($=>$.id===P.id)||!!v.find($=>$.id===P.id))).forEach(b=>{const w=b.remove({ignoreUpstream:!1},i);c.push(...w.removed),n.push(...w.updated)}),i==null||i.attemptAutoclose("remove-unrecognized-properties",this.id),{updated:D(n),added:D(s),removed:D(c),affected:D(e),self:this}}removeUnrecognizedMethods(i=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,"remove-unrecognized-methods"))){const n=[],s=[],c=[],e=[];let y=[...this.methods];y=y.filter(v=>v.parent.id===this.id),y=y.filter(v=>!v.isExtendedMethod);const m=this.implementedMethodsFromOriginalParents;return y=y.filter(v=>this.interactive&&!v.implements?!1:!m.find(E=>{var b;return E.id===((b=v.implements)==null?void 0:b.id)})),y.forEach(v=>{const E=v.remove({ignoreUpstream:!1},i);c.push(...E.removed),n.push(...E.updated)}),i==null||i.attemptAutoclose("remove-unrecognized-methods",this.id),{updated:D(n),added:D(s),removed:D(c),affected:D(e),self:this}}syncImplementationMethods(i=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,"sync-implementation-methods"))){const n=[],s=[],c=[],e=[],y=this.methods,m=this.implementedMethodsFromOriginalParents,v=[...this.allBaseMethodsFromExtendedAndImplementedEntities,...y];return m.filter(b=>!v.find(P=>{var $;return(($=P.implements)==null?void 0:$.id)===b.id})).forEach(b=>{if(this.methods.find(L=>{var U;return((U=L.implements)==null?void 0:U.id)===b.id}))return;const P=this.methods.find(L=>{var se,ee;if(L.name===b.name&&!L.implements)return!0;const U=Si(this,Re.CRON_JOB),K=Si(this,Re.HTTP_ENDPOINT),H=((se=L.implements)==null?void 0:se.id)===Q["built-in-base-entity"].BUILT_IN_HTTP_ENDPOINT_ENTITY.methods.handler.id,X=((ee=L.implements)==null?void 0:ee.id)===Q["built-in-base-entity"].BUILT_IN_CRON_JOB_ENTITY.methods.handler.id;return!!(U&&!X&&!K&&H||K&&!H&&!U&&X)});if(P&&P.type===o.FunctionDeclaration){P.setImplements(b,i),P.metaSync({name:b.name},i),i==null||i.add(P,Z.Updated),i==null||i.add(this,Z.Updated);return}const $=b.implementAsFunctionDeclaration(i,this);s.push($),i==null||i.add($,Z.Added),this.addMethod($,i)}),this.methods.sort((b,w)=>b.index-w.index).forEach(b=>{b.afterAllChildrenInitialized(i)}),i==null||i.attemptAutoclose("sync-implementation-methods",this.id),{updated:D(n),added:D(s),removed:D(c),affected:D(e),self:this}}syncImplementationProperties(i=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,"sync-implementation-properties"))){const n=[],s=[],c=[],e=[],y=this.properties,m=this.implementedPropertiesFromOriginalParents.filter(E=>!this.allBasePropertiesFromExtendedAndImplementedEntities.find(w=>!!w.implements.find(P=>P.id===E.id))),v=[...this.allBasePropertiesFromExtendedAndImplementedEntities,...y];return m.forEach(E=>{const b=v.find(L=>!!L.implements.find(U=>U.id===E.id));if(b){const{updated:L,added:U,removed:K,affected:H}=b.syncWithImplementation(i);n.push(...L),s.push(...U),c.push(...K),e.push(...H);return}if(this.properties.find(L=>!!L.implements.find(U=>U.id===E.id)))return;const P=this.properties.find(L=>L.name===E.name&&!!L.abstract&&!L.implements);if(P){P.addImplementation(E,i),P.metaSync({abstract:!1},i),P.afterAllChildrenInitialized(i);return}const $=E.implement(this,i,x.UUID.uuid());s.push($),i==null||i.add($,Z.Added)}),i==null||i.attemptAutoclose("sync-implementation-properties",this.id),{updated:D(n),added:D(s),removed:D(c),affected:D(e),self:this}}addExtendedMethods(i=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,"add-extended-methods"))){const n=[],s=[],c=[],e=[],y=this.methods,v=this.extendedMethodsFromOriginalParents.filter(b=>b.type===o.FunctionDeclaration),E=new Set(y.filter(b=>{var w;return!!((w=b.extends)!=null&&w.id)}).map(b=>b.extends.id));return v.forEach(b=>{if(E.has(b.id))return;E.add(b.id);const w=b.clone(i,this,x.UUID.uuid());w.setExtends(b,i),w.initChildren(i),s.push(w),i==null||i.add(w,Z.Added),this.addMethod(w,i)}),i==null||i.attemptAutoclose("add-extended-methods",this.id),{updated:D(n),added:D(s),removed:D(c),affected:D(e),self:this}}addExtendedProperties(i=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,"add-extended-properties"))){const n=[],s=[],c=[],e=[],y=this.properties,m=this.extendedPropertiesFromOriginalParents,v=m.filter(b=>m.find(P=>!!P.implements.find($=>$.id===b.id))?!1:!b.abstract),E=new Set(y.filter(b=>{var w;return!!((w=b.extends)!=null&&w.id)}).map(b=>b.extends.id));return v.forEach(b=>{if(E.has(b.id))return;E.add(b.id);const w=b.clone(i,this,x.UUID.uuid());w.setExtends(b,i),w.initChildren(i),s.push(w),i==null||i.add(w,Z.Added),this.addProperty(w,i)}),[...this.properties].forEach(b=>{if(b.extends)return;if(v.find(P=>P.name===b.name&&P.implements.every($=>!!b.implements.find(L=>L.id===$.id)))){const P=b.remove({ignoreUpstream:!1},i);c.push(...P.removed),n.push(...P.updated)}}),this.properties.forEach(b=>{const w=b.afterAllChildrenInitialized(i);n.push(...w.updated),e.push(...w.affected),s.push(...w.added),c.push(...w.removed)}),i==null||i.attemptAutoclose("add-extended-properties",this.id),{updated:D(n),added:D(s),removed:D(c),affected:D(e),self:this}}addSuggestions(){return this.implements.forEach(i=>{QUe(this,i).forEach(c=>{const e=c.toJSON();e.id=`_suggestion--parent--${this.id}--${c.id}`;const y=ye(e,this.project);y.suggestion=!0,y.setParent(this,null),y.initChildren(null),this.addSuggestedProperty(y)}),eKe(this,i).forEach(c=>{const e=`_suggestion--parent--${this.id}--${c.id}`,y=c.implementAsFunctionDeclaration(null,this,e),m=ye(y,this.project);if(m.suggestion=!0,m.setParent(this,null),m.initChildren(null),this.methods=this.methods.filter(v=>v.id!==e),m.inputs.forEach(v=>{v.suggestion=!0}),m.returnStatements.length){const v=m.returnStatements[0];v.suggestion=!0,v.outputs.forEach(E=>{E.suggestion=!0})}this.addSuggestedMethod(m)})}),this}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(i,n=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,"meta-sync"))){const s=$r(this,i,n),c=xr(this,s),e=this.toMeta();return this.name=s.name!==void 0?s.name:e.name,this.codeName=s.codeName!==void 0?s.codeName:e.codeName,this.description=s.description!==void 0?s.description:e.description,this.x=s.x||e.x,this.y=s.y||e.y,this.static=s.static!==void 0?s.static:this.static,this.abstract=s.abstract!==void 0?s.abstract:this.abstract,this.additionalProperties=s.additionalProperties!==void 0?s.additionalProperties:e.additionalProperties,super.baseMetaSync(s,this,n),s.deleted===!0&&!e.deleted?n==null||n.add(this,Z.Removed):s.deleted===!1&&e.deleted?n==null||n.add(this,Z.Added):c&&(n==null||n.add(this,Z.Updated)),n==null||n.attemptAutoclose("meta-sync",this.id),this}async APILoad(i=Ge,...n){return await bi.repository.APILoad(this.id,...n),this}async APICreate(i=Ge,...n){return await bi.repository.APICreate(this.toShallowJSON(),...n),this}async APIUpdate(i=Ge,...n){return await bi.repository.APIUpdate(this.toShallowJSON(),...n),this}async APIDelete(i=Ge,...n){return await bi.repository.APIDelete(this.toShallowJSON(),...n),this}async APIClone(i=Ge,...n){return await bi.repository.APIClone(this.id,...n),this}async APILoadVersion(i=Ge,n,...s){return await bi.repository.APILoadVersion(this.id,n,...s)}removeFromParent(i=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,_.RemoveFromParent))){if(!this.checkCanEdit(this,i))return J.Logger.warn(`[removeFromParent] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(_.RemoveFromParent,this.id),{added:[],updated:[],removed:[],affected:[],self:this};const n=[],s=[],c=[],e=[];if(this.parent.type===o.Project)this.parent.removeDefinitionEntity(this);else if(this.parent.type===o.DataType&&this.parent.entity&&this.parent.entity.id===this.id){const y=this.parent.setEntity(null,i);n.push(y)}return i==null||i.attemptAutoclose(_.RemoveFromParent,this.id),{added:D(c),updated:D(n),removed:D(s),affected:D(e),self:this}}remove({ignoreUpstream:i}={ignoreUpstream:!1},n=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,_.RemoveEntity))){var m;if(!this.checkCanDelete(this,n))return J.Logger.warn(`[remove] User is not allowed to delete or edit this ${this.type} entity with id: ${this.id}`),n==null||n.event({id:`${_.RemoveEntity}-${this.id}`,action:_.RemoveEntity,owner:this,errorReason:ir.ActionOwnerEntityNonDeletable,rootAction:((m=n==null?void 0:n.self)==null?void 0:m.id)===this.id&&(n==null?void 0:n.autoCloseActionName)===_.RemoveEntity}),n==null||n.attemptAutoclose(_.RemoveEntity,this.id),{added:[],updated:[],removed:[],affected:[],self:this};const s=[],c=[],e=[],y=[];if(n!=null&&n.hasRemoved(this.id))return n==null||n.attemptAutoclose(_.RemoveEntity,this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(c.push(this),this.unsubscribe(),this.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},n),Object.values(this.detachedDependents).forEach(v=>{const{updated:E,removed:b,added:w}=v.entity.onDetachedDependencyRemoved(this,v.field,n);s.push(...E),c.push(...b),e.push(...w)}),this.properties.forEach(v=>{const{updated:E,removed:b}=v.remove({ignoreUpstream:!0},n);s.push(...E),c.push(...b)}),this.methods.forEach(v=>{const{updated:E,removed:b}=v.remove({ignoreUpstream:!0},n);s.push(...E),c.push(...b)}),this.abstractMethods.forEach(v=>{const{updated:E,removed:b}=v.remove({ignoreUpstream:!0},n);s.push(...E),c.push(...b)}),this.suggestedProperties.forEach(v=>{const{updated:E,removed:b}=v.remove({ignoreUpstream:!0},n);s.push(...E),c.push(...b)}),this.suggestedMethods.forEach(v=>{const{updated:E,removed:b}=v.remove({ignoreUpstream:!0},n);s.push(...E),c.push(...b)}),!i){const v=this.removeFromParent(n);e.push(...v.added),s.push(...v.updated),c.push(...v.removed),y.push(...v.affected)}return n==null||n.attemptAutoclose(_.RemoveEntity,this.id),{added:D(e),updated:D(s),removed:D(c),affected:D(y),self:this}}restore({}={},i=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,_.RestoreEntity))){if(!this.checkCanEdit(this,i))return J.Logger.warn(`[restore] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(_.RestoreEntity,this.id),{added:[],updated:[],removed:[],affected:[],self:this};const n=[],s=[],c=[],e=[];return i!=null&&i.hasAdded(this.id)?(i==null||i.attemptAutoclose(_.RestoreEntity,this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},i),Object.values(this.detachedDependents).forEach(y=>{const{updated:m,removed:v,added:E}=y.entity.onDetachedDependencyRestored(this,y.field,i);s.push(...m),c.push(...v),n.push(...E)}),this.properties.forEach(y=>{const{updated:m}=y.restore({},i);s.push(...m)}),this.methods.forEach(y=>{const{updated:m}=y.restore({},i);s.push(...m)}),this.abstractMethods.forEach(y=>{const{updated:m}=y.restore({},i);s.push(...m)}),this.suggestedProperties.forEach(y=>{const{updated:m}=y.restore({},i);s.push(...m)}),this.suggestedMethods.forEach(y=>{const{updated:m}=y.restore({},i);s.push(...m)}),i==null||i.attemptAutoclose(_.RestoreEntity,this.id),{added:D(n),updated:D(s),removed:D(c),affected:D(e),self:this})}toFlat(i=new Set){var s;return i.has(this.id)?[]:(i.add(this.id),[this,...((s=this.extends)==null?void 0:s.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 s;return i.has(this.id)?[]:(i.add(this.id),[this.id,...((s=this.extends)==null?void 0:s.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 n,s,c;return i.has(this.id)?this.toReference():(i.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,editable:this.editable,deletable:this.deletable,name:this.name,codeName:this.codeName,description:this.description,x:this.x,y:this.y,static:this.static,abstract:this.abstract,additionalProperties:this.additionalProperties,allPropertiesImplement:((n=this.allPropertiesImplement)==null?void 0:n.toJSON(i))||null,additionalPropertiesDataType:((s=this.additionalPropertiesDataType)==null?void 0:s.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=pt){var s,c,e,y,m,v,E,b,w,P;let n;return(s=i.seenEntityMaps)!=null&&s.has(this.id)?n=i.seenEntityMaps.get(this.id):(n=i.newId||jr(this,this.project,i.uuidStrategy),i.seenEntityMaps&&i.seenEntityMaps.set(this.id,n)),(c=i.seenEntities)!=null&&c.has(n)||(e=i.seenEntities)!=null&&e.has(this.id)?this.toReference({seenEntityMaps:i.seenEntityMaps}):((y=i.seenEntities)==null||y.add(n),(m=i.seenEntities)==null||m.add(this.id),{id:n,version:x.UUID.uuid(),createdAt:i.timestamp||M().toISOString(),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:((v=this.allPropertiesImplement)==null?void 0:v.toJSONClone(i))||null,additionalPropertiesDataType:((E=this.additionalPropertiesDataType)==null?void 0:E.toJSONClone(i))||null,properties:this.properties.map($=>$.toJSONClone({...i,newId:null})),methods:this.methods.map($=>$.toJSONClone({...i,newId:null})),abstractMethods:this.abstractMethods.map($=>$.toJSONClone({...i,newId:null})),implements:this.implements.map($=>$.type===o.BuiltInBaseEntity?$.toJSON(i.seenEntities):$.toJSONClone({...i,newId:null})),extends:((b=this.extends)==null?void 0:b.type)===o.BuiltInBaseEntity?(w=this.extends)==null?void 0:w.toJSON(i.seenEntities):(P=this.extends)==null?void 0:P.toJSONClone({...i,newId:null}),parent:this.parent.toReference({seenEntityMaps:i.seenEntityMaps})})}toReference(i=pt){var s;let n=this.id;return(s=i.seenEntityMaps)!=null&&s.has(this.id)&&(n=i.seenEntityMaps.get(this.id)),{id:n+"--"+x.UUID.uuid()+"--ref",type:o.GenericReference,entityId:n,version:this.version,entityType:this.type}}toShallowJSON(i=pt){var s,c,e,y;let n=this.id;return(s=i.seenEntityMaps)!=null&&s.has(this.id)&&(n=i.seenEntityMaps.get(this.id)),{id:n,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,name:this.name,codeName:this.codeName,description:this.description,type:this.type,editable:this.editable,deletable:this.deletable,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(m=>m.toReference(i)),methods:this.methods.map(m=>m.toReference(i)),abstractMethods:this.abstractMethods.map(m=>m.toReference(i)),implements:this.implements.map(m=>m.toReference(i)),extends:((y=this.extends)==null?void 0:y.toReference(i))||null,parent:this.parent.toReference(i)}}toFlatJSON(i=new Set){var s,c,e;return i.has(this.id)?[]:(i.add(this.id),[this.toShallowJSON(),...this.properties.flatMap(y=>y.toFlatJSON(i)),...this.methods.flatMap(y=>y.toFlatJSON(i)),...this.abstractMethods.flatMap(y=>y.toFlatJSON(i)),...this.implements.flatMap(y=>y.toFlatJSON(i)),...((s=this.extends)==null?void 0:s.toFlatJSON(i))||[],...this.parent.toFlatJSON(i),...((c=this.additionalPropertiesDataType)==null?void 0:c.toFlatJSON(i))||[],...((e=this.allPropertiesImplement)==null?void 0:e.toFlatJSON(i))||[]])}toGenerationTarget(){var n;const i=this.parent.type===o.Project?void 0:this.parent.id;return{id:this.id,name:this.name,description:this.description,type:this.type,static:this.static,abstract:this.abstract,extends:(n=this.extends)==null?void 0:n.id,additionalProperties:this.additionalProperties,implements:this.implements.map(s=>s.id),parent:i}}toFlatGenerationTarget(i=new Set){var s,c,e;return i.has(this.id)?[]:(i.add(this.id),[this.toGenerationTarget(),...this.properties.flatMap(y=>y.toFlatGenerationTarget(i)),...this.methods.flatMap(y=>y.toFlatGenerationTarget(i)),...this.abstractMethods.flatMap(y=>y.toFlatGenerationTarget(i)),...this.implements.filter(y=>y.type===o.DefinitionEntity).flatMap(y=>y.toFlatGenerationTarget(i)),...((s=this.extends)==null?void 0:s.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,n;return this.errors=[],this.properties.forEach(s=>s.clearErrors()),this.methods.forEach(s=>s.clearErrors()),this.abstractMethods.forEach(s=>s.clearErrors()),(i=this.additionalPropertiesDataType)==null||i.clearErrors(),(n=this.allPropertiesImplement)==null||n.clearErrors(),this}validate(){return this.errors=XUe(this),{success:!0}}async validateAsync(i={}){const n=J.YieldTracker.from(i);return this.errors=await YUe(this,{tracker:n}),{success:!0}}getErrors(){var n,s;return[...this.errors,...this.properties.flatMap(c=>c.getErrors()),...this.methods.flatMap(c=>c.getErrors()),...this.abstractMethods.flatMap(c=>c.getErrors()),...((n=this.additionalPropertiesDataType)==null?void 0:n.getErrors())||[],...((s=this.allPropertiesImplement)==null?void 0:s.getErrors())||[]]}async getErrorsAsync(i={}){const n=J.YieldTracker.from(i),s=[...this.errors];await n.tick();for(const c of this.properties)s.push(...await c.getErrorsAsync({tracker:n}));for(const c of this.methods)s.push(...await c.getErrorsAsync({tracker:n}));for(const c of this.abstractMethods)s.push(...await c.getErrorsAsync({tracker:n}));return this.additionalPropertiesDataType&&s.push(...await this.additionalPropertiesDataType.getErrorsAsync({tracker:n})),this.allPropertiesImplement&&s.push(...await this.allPropertiesImplement.getErrorsAsync({tracker:n})),s}getShallowErrors(){return this.errors}clone(i=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,_.CloneEntity)),n=null,s=null,c=!0){var U,K,H;const e=Pr(n,this),y=this.toJSON(),m=s||x.UUID.uuid(),v=n||this.parent;y.properties=[],y.methods=[],y.abstractMethods=[];const E=m.split("-id"),b=E[E.length-1||0]||m;y.id=m,y.version=x.UUID.uuid(),y.createdAt=(i==null?void 0:i.timestamp)||M().toISOString(),y.author=(i==null?void 0:i.author)||"1",y.previousVersion=null,y.deleted=!1,y.editable=!0,y.deletable=!0,y.parent=v.toReference();const w=Ui(y,e);w.hydrateAncestors(),w.setParent(v,i),c&&(w.subscribe(),w.addSelfToProject(i)),w.initChildren(i),i==null||i.add(w,Z.Added);const P=(U=this.properties)==null?void 0:U.map(X=>this.project.diggestedBuiltInBaseEntitiesIds.has(X.id)?e.getBuiltIn(X.id):X.clone(i,w,x.UUID.uuid(),c));w.properties=P;const $=(K=this.methods)==null?void 0:K.map((X,se)=>this.project.diggestedBuiltInBaseEntitiesIds.has(X.id)?e.getBuiltIn(X.id):X.clone(i,w,b+"-method-"+se+"-id",c));w.methods=$;const L=(H=this.abstractMethods)==null?void 0:H.map((X,se)=>this.project.diggestedBuiltInBaseEntitiesIds.has(X.id)?e.getBuiltIn(X.id):X.clone(i,w,b+"-abstract-method-"+se+"-id",c));if(w.abstractMethods=L,this.additionalPropertiesDataType)if(this.project.diggestedBuiltInBaseEntitiesIds.has(this.additionalPropertiesDataType.id))w.setAdditionalPropertiesDataType(this.project.getBuiltIn(this.additionalPropertiesDataType.id),i);else{const X=this.additionalPropertiesDataType.clone(i,w,x.UUID.uuid(),c);w.setAdditionalPropertiesDataType(X,i)}if(this.allPropertiesImplement)if(this.project.diggestedBuiltInBaseEntitiesIds.has(this.allPropertiesImplement.id))w.setAllPropertiesImplement(this.project.getBuiltIn(this.allPropertiesImplement.id),i);else{const X=this.allPropertiesImplement.clone(i,w,x.UUID.uuid(),c);w.setAllPropertiesImplement(X,i)}return i==null||i.attemptAutoclose(_.CloneEntity,this.id),w}getFunctionDeclaration(i){return this.methods.find(n=>n.id===i)}implement(i,n=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,"implement-definition-entity")),s){const c=x1(this,i,n,s);return n==null||n.attemptAutoclose("implement-definition-entity",this.id),c}getAllPropertiesImplements(){var n;const i=[];return this.allPropertiesImplement&&i.push(this.allPropertiesImplement),i.push(...((n=this.extends)==null?void 0:n.getAllPropertiesImplements())||[],...this.implements.flatMap(s=>s.getAllPropertiesImplements())),i}getAllInteractiveMethods(){var e;const i=this.implements.filter(y=>y.type===o.DefinitionEntity||y.type===o.BuiltInBaseEntity&&y.interactive),n=((e=this.extends)==null?void 0:e.getAllInteractiveMethods())||[],s=i.flatMap(y=>y.getAllInteractiveMethods());return D([...this.methods,...n,...s])}inferFromInputs(i,n=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,"infer-definition-entity-from-inputs"))){const s=[],c=[],e=[],y=[];if(this.parent.type!==o.DataType||!this.parent.inferred)return n==null||n.attemptAutoclose("infer-definition-entity-from-inputs",this.id),{added:[],updated:[],removed:[],affected:[],self:this};const m=[];i.forEach(b=>{m.find(P=>le(P,this.project)===le(b,this.project))||m.push(b)});const v=this.properties.filter(b=>!b.dataType);m.forEach(b=>{var H,X,se;const w=v.find(ee=>le(ee,this.project)===le(b,this.project));if(!w)return;const $=Wn(b.parent).getMasterInputWithValueWritterFromAllInstances(b),L=Do($,n),U=L==null?void 0:L.clone(n,w,x.UUID.uuid(),!0);U&&((H=w.dataType)==null||H.merge(U,n),U.id!==((X=w.dataType)==null?void 0:X.id)&&U.remove({ignoreUpstream:!1},n),w.dataType&&(w.dataType.metaSync({inferred:!0,like:!0},n),w.setDataType(w.dataType,n),n==null||n.add(w,Z.Affected)));let K=null;if(b.declaration&&w.id!==((se=b.declaration)==null?void 0:se.id)&&(K=b.declaration),b.setDeclaration(w,n),n==null||n.add(b,Z.Updated),K){const{updated:ee,removed:fe}=K.remove({ignoreUpstream:!1},n);c.push(...ee),e.push(...fe)}});const E=[];return m.forEach(b=>{if(!b.declaration){E.push(b);return}}),E.length===0?(n==null||n.attemptAutoclose("infer-definition-entity-from-inputs",this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(E.forEach(b=>{var se,ee,fe,de;const w=this.properties.find(ce=>le(ce,this.project)===le(b,this.project));if(w){if(b.setDeclaration(w,n),!w.getDataType(n)){const ve=Wn(b.parent).getMasterInputWithValueWritterFromAllInstances(b),ae=Do(ve),me=ae==null?void 0:ae.clone(n,w,x.UUID.uuid(),!0);me&&((se=w.dataType)==null||se.merge(me,n),me.id!==((ee=w.dataType)==null?void 0:ee.id)&&me.remove({ignoreUpstream:!1},n),w.dataType&&(w.dataType.metaSync({inferred:!0,like:!0},n),w.setDataType(w.dataType,n),n==null||n.add(w,Z.Affected)))}return}const P=le(b,this.project),$=b.codeName||k1(b,this.project)||Tc(Ji(P)),L=ka.new(n);L.parent=this.toReference(),L.index=b.index,L.name=P,L.codeName=$,L.description=b.description;const U=ye(L,this.project);U.hydrateAncestors(),n==null||n.add(U,Z.Added),U.setParent(this,n),U.initChildren(n);const H=Wn(b.parent).getMasterInputWithValueWritterFromAllInstances(b),X=Do(H);if(X)if(this.project.diggestedBuiltInBaseEntitiesIds.has(X.id))U.setDataType(X,n),n==null||n.add(U,Z.Affected);else{const ce=X==null?void 0:X.clone(n,U,x.UUID.uuid(),!0);ce&&((fe=U.dataType)==null||fe.merge(ce,n),ce.id!==((de=U.dataType)==null?void 0:de.id)&&ce.remove({ignoreUpstream:!1},n),U.dataType&&(U.dataType.metaSync({inferred:!0,like:!0},n),U.setDataType(U.dataType,n),n==null||n.add(U,Z.Affected)))}return this.addProperty(U,n),b.setDeclaration(U,n),n==null||n.add(b,Z.Updated),U}),n==null||n.attemptAutoclose("infer-definition-entity-from-inputs",this.id),{added:D(s),updated:D(c),removed:D(e),affected:D(y),self:this})}getRawDefaultValue(){const i={};return this.properties.forEach(n=>{var c;if(!uC(n))return;const s=Ji(n.name);i[s]=((c=n.getDefaultValue())==null?void 0:c.value)||null}),i}getActiveRawDefaultValue(){const i={};return this.properties.forEach(n=>{var e;if(!uC(n))return;const s=Ji(n.name),c=(e=this.project.requestActiveDynamicValue(n,!0))==null?void 0:e.value;i[s]=(c==null?void 0:c.value)||null}),i}setAdditionalPropertiesDataType(i,n=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,_.SetAdditionalPropertiesDataType))){if(!this.checkCanEdit(this,n))return J.Logger.warn(`[setAdditionalPropertiesDataType] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),n==null||n.attemptAutoclose(_.SetAdditionalPropertiesDataType,this.id),this;const s=this.additionalPropertiesDataType;return(s==null?void 0:s.id)!==(i==null?void 0:i.id)&&(s==null||s.remove({ignoreUpstream:!0},n),this.additionalPropertiesDataType=i,this.subscribeToDependencies(),n==null||n.add(this,Z.Affected)),n==null||n.attemptAutoclose(_.SetAdditionalPropertiesDataType,this.id),this}removeAdditionalPropertiesDataType(i=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,_.RemoveAllPropertiesImplement))){return this.checkCanEdit(this,i)?(this.additionalPropertiesDataType&&(this.additionalPropertiesDataType.remove({ignoreUpstream:!0},i),i==null||i.add(this,Z.Affected),this.additionalPropertiesDataType=null),i==null||i.attemptAutoclose(_.RemoveAllPropertiesImplement,this.id),this):(J.Logger.warn(`[removeAdditionalPropertiesDataType] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(_.RemoveAllPropertiesImplement,this.id),this)}setAllPropertiesImplement(i,n=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,_.SetAllPropertiesImplement))){if(!this.checkCanEdit(this,n))return J.Logger.warn(`[setAllPropertiesImplement] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),n==null||n.attemptAutoclose(_.SetAllPropertiesImplement,this.id),this;const s=this.allPropertiesImplement;return(s==null?void 0:s.id)!==(i==null?void 0:i.id)&&(s==null||s.remove({ignoreUpstream:!0},n),this.allPropertiesImplement=i,this.subscribeToDependencies(),n==null||n.add(this,Z.Affected)),n==null||n.attemptAutoclose(_.SetAllPropertiesImplement,this.id),this}removeAllPropertiesImplement(i=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),this,!0,_.RemoveAllPropertiesImplement))){return this.checkCanEdit(this,i)?(this.allPropertiesImplement&&(this.allPropertiesImplement.remove({ignoreUpstream:!0},i),i==null||i.add(this,Z.Affected),this.allPropertiesImplement=null),i==null||i.attemptAutoclose(_.RemoveAllPropertiesImplement,this.id),this):(J.Logger.warn(`[removeAllPropertiesImplement] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(_.RemoveAllPropertiesImplement,this.id),this)}};I(bi,"repository",{APICreate:async(i,...n)=>i,APIUpdate:async(i,...n)=>i,APIDelete:async(i,...n)=>i,APIClone:async(i,...n)=>{},APILoad:async(i,...n)=>null,APILoadVersion:async(i,n,...s)=>null}),I(bi,"type",o.DefinitionEntity),I(bi,"USER_MANAGED_PARENT_TYPES",[o.Project,o.DataType]),I(bi,"PARENT_TYPES",[...bi.USER_MANAGED_PARENT_TYPES]),I(bi,"MUTABLE_BASE_PROPERTIES",["name","codeName","description","static","abstract","additionalProperties"]),I(bi,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),I(bi,"BASE_PROPERTIES",[...bi.MUTABLE_BASE_PROPERTIES,...bi.INMUTABLE_BASE_PROPERTIES]),I(bi,"MUTABLE_META_PROPERTIES",[...bi.MUTABLE_BASE_PROPERTIES,"x","y"]),I(bi,"INMUTABLE_META_PROPERTIES",[...bi.INMUTABLE_BASE_PROPERTIES]),I(bi,"META_PROPERTIES",[...bi.MUTABLE_META_PROPERTIES,...bi.INMUTABLE_META_PROPERTIES]),I(bi,"MUTABLE_UPSTREAM_PROPERTIES",["extends","implements"]),I(bi,"INMUTABLE_UPSTREAM_PROPERTIES",["parent"]),I(bi,"UPSTREAM_PROPERTIES",[...bi.MUTABLE_UPSTREAM_PROPERTIES,...bi.INMUTABLE_UPSTREAM_PROPERTIES]),I(bi,"MUTABLE_DOWNSTREAM_PROPERTIES",["properties","methods","abstractMethods","allPropertiesImplement","additionalPropertiesDataType"]),I(bi,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),I(bi,"DOWNSTREAM_PROPERTIES",[...bi.MUTABLE_DOWNSTREAM_PROPERTIES,...bi.INMUTABLE_DOWNSTREAM_PROPERTIES]),I(bi,"PROPERTIES",[...bi.META_PROPERTIES,...bi.UPSTREAM_PROPERTIES,...bi.DOWNSTREAM_PROPERTIES]);let us=bi;async function TUi(d,p={}){const i=J.YieldTracker.from(p),n=[],s=Lt(d.errors,n);return await i.tick(),s}function vUi(d){const p=[];return Lt(d.errors,p)}const xm=class xm extends YV{constructor(i,n){super(i);I(this,"initialData");I(this,"id");I(this,"version");I(this,"name");I(this,"description",null);I(this,"type",o.BuiltInBaseEntity);I(this,"abstract",!1);I(this,"static");I(this,"additionalProperties",!1);I(this,"properties",[]);I(this,"allPropertiesImplement",null);I(this,"additionalPropertiesDataType",null);I(this,"methods",[]);I(this,"abstractMethods",[]);I(this,"extends",null);I(this,"interactive",!1);I(this,"errors",[]);I(this,"project");if(this.initialData=this.initialData||i,this.project=this.project||n,this.id=this.id||i.id,this.version=this.version||i.version,this.name=this.name||i.name,this.static=this.static||i.static,this.interactive=this.interactive||i.interactive,this.abstract=i.abstract,this.additionalProperties=i.additionalProperties,this.properties=this.initialData.properties.map(s=>{const c=ye(s,this.project);return c.setParent(this,null),c.initChildren(null),c}),this.methods=this.initialData.methods.map(s=>{const c=ye(s,this.project);return c.setParent(this,null),c.initChildren(null),c}),this.abstractMethods=this.initialData.abstractMethods.map(s=>{const c=ye(s,this.project);return c.setParent(this,null),c.initChildren(null),c}),this.initialData.allPropertiesImplement){const s=ye(this.initialData.allPropertiesImplement,this.project);s.setParent(this,null),s.initChildren(null),this.allPropertiesImplement=s}if(this.initialData.additionalPropertiesDataType){const s=ye(this.initialData.additionalPropertiesDataType,this.project);s.setParent(this,null),s.initChildren(null),this.additionalPropertiesDataType=s}this.initialData.extends&&(this.extends=ye(this.initialData.extends,this.project))}get allMethods(){return D([...this.ownDeclaredMethods,...this.allBaseMethodsFromOriginalParents])}get allProperties(){return D([...this.ownDeclaredProperties,...this.allBasePropertiesFromOriginalParents])}get allBaseMethodsFromOriginalParents(){var s;const i=((s=this.extends)==null?void 0:s.allMethods)||[],n=[...i].filter(c=>!i.some(e=>e.id!==c.id));return D(n)}get allBasePropertiesFromOriginalParents(){var s;const i=((s=this.extends)==null?void 0:s.allProperties)||[],n=[...i].filter(c=>!i.some(e=>{var y;return e.id!==c.id&&(!!e.implements.find(m=>m.id===c.id)||((y=e.extends)==null?void 0:y.id)===c.id)}));return D(n)}get allBasePropertiesFromExtendedAndImplementedEntities(){var s,c;const i=[...((s=this.extends)==null?void 0:s.ownDeclaredProperties)||[],...((c=this.extends)==null?void 0:c.allBasePropertiesFromExtendedAndImplementedEntities)||[]].filter(e=>!e.abstract),n=[...i].filter(e=>!i.some(y=>{var m;return y.id!==e.id&&(!!y.implements.find(v=>v.id===e.id)||((m=y.extends)==null?void 0:m.id)===e.id)}));return D([...n])}get allBaseMethodsFromExtendedAndImplementedEntities(){return D([...(this.extends?[this.extends]:[]).reduce((i,n)=>n.type===o.PrimitiveEntity?i:[...[...n.ownDeclaredMethods,...n.allBaseMethodsFromExtendedAndImplementedEntities].filter(c=>c.type!==o.ActionDescriptor),...i],[])])}get extendedPropertiesFromOriginalParents(){var s,c;const i=[...((s=this.extends)==null?void 0:s.ownDeclaredProperties)||[],...((c=this.extends)==null?void 0:c.extendedPropertiesFromOriginalParents)||[]].filter(e=>!e.abstract),n=[...i].filter(e=>!i.some(y=>{var m;return y.id!==e.id&&(!!y.implements.find(v=>v.id===e.id)||((m=y.extends)==null?void 0:m.id)===e.id)}));return D(n)}get implementedPropertiesFromOriginalParents(){return D([...(this.extends?[this.extends]:[]).reduce((i,n)=>{const s=n.implementedPropertiesFromOriginalParents,c=[...n.ownDeclaredProperties].filter(m=>!!m.abstract),e=[...s,...c,...i];return[...e].filter(m=>!!!e.find(E=>{var b;return((b=E.extends)==null?void 0:b.id)===m.id||!!E.implements.find(w=>w.id===m.id)}))},[])].filter(i=>!!i.abstract))}get extendedProperties(){return this.properties.filter(i=>i.isExtendedProperty)}get ownDeclaredMethods(){return[...this.methods,...this.abstractMethods]}get ownDeclaredProperties(){return this.properties.filter(i=>!i.isExtendedProperty)}subscribe(){return this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}async APILoad(i=Ge,...n){return await xm.repository.APILoad(this.id,...n),this}toFlat(i=new Set){var s;return i.has(this.id)?[]:(i.add(this.id),[this,...this.properties.flatMap(c=>c.toFlat(i)),...this.methods.flatMap(c=>c.toFlat(i)),...this.abstractMethods.flatMap(c=>c.toFlat(i)),...((s=this.extends)==null?void 0:s.toFlat(i))||[]])}toFlatIds(i=new Set){var s;return i.has(this.id)?[]:(i.add(this.id),[this.id,...this.properties.flatMap(c=>c.toFlatIds(i)),...this.methods.flatMap(c=>c.toFlatIds(i)),...this.abstractMethods.flatMap(c=>c.toFlatIds(i)),...((s=this.extends)==null?void 0:s.toFlatIds(i))||[]])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,description:this.description,interactive:this.interactive,additionalProperties:this.additionalProperties,abstract:this.abstract,static:this.static,type:this.type,name:this.name}}toJSON(i=new Set){var n,s,c;return i.has(this.id)?this.toReference():(i.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,abstract:this.abstract,static:this.static,additionalProperties:this.additionalProperties,interactive:this.interactive,additionalPropertiesDataType:((n=this.additionalPropertiesDataType)==null?void 0:n.toJSON(i))||null,allPropertiesImplement:((s=this.allPropertiesImplement)==null?void 0:s.toJSON(i))||null,properties:this.properties.map(e=>e.toJSON(i)),methods:this.methods.map(e=>e.toJSON(i)),abstractMethods:this.abstractMethods.map(e=>e.toJSON(i)),extends:((c=this.extends)==null?void 0:c.toJSON(i))||null})}toReference(i=pt){return{id:this.id+"--"+x.UUID.uuid()+"--ref",type:o.GenericReference,entityId:this.id,version:this.version,entityType:this.type}}toShallowJSON(i=pt){var n,s,c;return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,abstract:this.abstract,static:this.static,interactive:this.interactive,additionalProperties:this.additionalProperties,additionalPropertiesDataType:((n=this.additionalPropertiesDataType)==null?void 0:n.toReference())||null,allPropertiesImplement:((s=this.allPropertiesImplement)==null?void 0:s.toReference())||null,properties:this.properties.map(e=>e.toReference()),methods:this.methods.map(e=>e.toReference()),abstractMethods:this.abstractMethods.map(e=>e.toReference()),extends:((c=this.extends)==null?void 0:c.toReference())||null}}toFlatJSON(i=new Set){var s,c;return i.has(this.id)?[]:(i.add(this.id),[this.toShallowJSON(),...this.properties.flatMap(e=>e.toFlatJSON(i)),...this.methods.flatMap(e=>e.toFlatJSON(i)),...this.abstractMethods.flatMap(e=>e.toFlatJSON(i)),...((s=this.additionalPropertiesDataType)==null?void 0:s.toFlatJSON(i))||[],...((c=this.allPropertiesImplement)==null?void 0:c.toFlatJSON(i))||[]])}toGenerationTarget(){var i;return{id:this.id,type:this.type,name:this.name,description:this.description,static:this.static,abstract:this.abstract,interactive:this.interactive,additionalProperties:this.additionalProperties,extends:(i=this.extends)==null?void 0:i.id}}toFlatGenerationTarget(i=new Set){var s,c;return i.has(this.id)?[]:(i.add(this.id),[this.toGenerationTarget(),...this.properties.flatMap(e=>e.toFlatGenerationTarget(i)),...this.methods.flatMap(e=>e.toFlatGenerationTarget(i)),...this.abstractMethods.flatMap(e=>e.toFlatGenerationTarget(i)),...((s=this.additionalPropertiesDataType)==null?void 0:s.toFlatGenerationTarget(i))||[],...((c=this.allPropertiesImplement)==null?void 0:c.toFlatGenerationTarget(i))||[]])}clearErrors(){var i,n;return this.errors=[],this.properties.forEach(s=>s.clearErrors()),this.methods.forEach(s=>s.clearErrors()),this.abstractMethods.forEach(s=>s.clearErrors()),(i=this.additionalPropertiesDataType)==null||i.clearErrors(),(n=this.allPropertiesImplement)==null||n.clearErrors(),this}validate(){return this.errors=vUi(this),{success:!0}}async validateAsync(i={}){const n=J.YieldTracker.from(i);return this.errors=await TUi(this,{tracker:n}),{success:!0}}getErrors(){var n,s;return[...this.errors,...this.properties.flatMap(c=>c.getErrors()),...this.methods.flatMap(c=>c.getErrors()),...this.abstractMethods.flatMap(c=>c.getErrors()),...((n=this.additionalPropertiesDataType)==null?void 0:n.getErrors())||[],...((s=this.allPropertiesImplement)==null?void 0:s.getErrors())||[]]}async getErrorsAsync(i={}){const n=J.YieldTracker.from(i),s=[...this.errors];await n.tick();for(const c of this.properties){const e=await c.getErrorsAsync({tracker:n});s.push(...e)}for(const c of this.methods){const e=await c.getErrorsAsync({tracker:n});s.push(...e)}for(const c of this.abstractMethods){const e=await c.getErrorsAsync({tracker:n});s.push(...e)}if(this.additionalPropertiesDataType){const c=await this.additionalPropertiesDataType.getErrorsAsync({tracker:n});s.push(...c)}if(this.allPropertiesImplement){const c=await this.allPropertiesImplement.getErrorsAsync({tracker:n});s.push(...c)}return s}getShallowErrors(){return this.errors}implement(i,n=this.project.addChangeSet(new q(this.project,x.sessionAuthor,M().toISOString(),null,!0,"implement-built-in-base-entity")),s){const c=x1(this,i,n,s);return n==null||n.attemptAutoclose("implement-built-in-base-entity",this.id),c}getAllPropertiesImplements(){var n;const i=[];return this.allPropertiesImplement&&i.push(this.allPropertiesImplement),((n=this.extends)==null?void 0:n.type)===o.BuiltInBaseEntity&&i.push(...this.extends.getAllPropertiesImplements()||[]),i}getAllInteractiveMethods(){const i=[];if(this.interactive){if(i.push(...this.methods,...this.abstractMethods),!this.extends||this.extends.type===o.BuiltInBaseEntity&&this.extends.interactive||this.extends.type===o.PrimitiveEntity)return i;this.extends instanceof xm&&i.push(...this.extends.getAllInteractiveMethods())}return D(i)}};I(xm,"repository",{APILoad:async(i,...n)=>null});let Po=xm;async function EUi(d,p={}){const i=J.YieldTracker.from(p),n=[],s=Lt(d.errors,n);return await i.tick(),s}function bUi(d){const p=[];return Lt(d.errors,p)}const OA=class OA extends YV{constructor(i,n){super(i);I(this,"initialData");I(this,"id");I(this,"name");I(this,"description",null);I(this,"type",o.PrimitiveEntity);I(this,"static");I(this,"abstract");I(this,"properties",[]);I(this,"methods",[]);I(this,"abstractMethods",[]);I(this,"extends",null);I(this,"errors",[]);I(this,"project");this.initialData=i,this.project=n,this.id=i.id,this.name=i.name,this.static=i.static,this.abstract=i.abstract,this.properties=this.initialData.properties.map(s=>{const c=ye(s,this.project);return c.setParent(this,null),c.initChildren(null),c}),this.methods=this.initialData.methods.map(s=>{const c=ye(s,this.project);return c.parent=this,c}),this.abstractMethods=this.initialData.abstractMethods.map(s=>{const c=ye(s,this.project);return c.parent=this,c}),this.initialData.extends&&(this.extends=ye(this.initialData.extends,this.project))}get allMethods(){return D([...this.ownDeclaredMethods,...this.allBaseMethodsFromOriginalParents])}get allProperties(){return D([...this.ownDeclaredProperties,...this.allBasePropertiesFromOriginalParents])}get allBaseMethodsFromOriginalParents(){var s;const i=((s=this.extends)==null?void 0:s.allMethods)||[],n=[...i].filter(c=>!i.some(e=>e.id!==c.id));return D(n)}get allBasePropertiesFromOriginalParents(){var s;const i=((s=this.extends)==null?void 0:s.allProperties)||[],n=[...i].filter(c=>!i.some(e=>{var y;return e.id!==c.id&&(e.implements.find(m=>m.id===c.id)||((y=e.extends)==null?void 0:y.id)===c.id)}));return D(n)}get allBasePropertiesFromExtendedAndImplementedEntities(){var s,c;const i=[...((s=this.extends)==null?void 0:s.ownDeclaredProperties)||[],...((c=this.extends)==null?void 0:c.allBasePropertiesFromExtendedAndImplementedEntities)||[]].filter(e=>!e.abstract),n=[...i].filter(e=>!i.some(y=>{var m;return y.id!==e.id&&(y.implements.find(v=>v.id===e.id)||((m=y.extends)==null?void 0:m.id)===e.id)}));return D(n)}get extendedPropertiesFromOriginalParents(){var s,c;const i=[...((s=this.extends)==null?void 0:s.ownDeclaredProperties)||[],...((c=this.extends)==null?void 0:c.extendedPropertiesFromOriginalParents)||[]].filter(e=>!e.abstract),n=[...i].filter(e=>!i.some(y=>{var m;return y.id!==e.id&&(y.implements.find(v=>v.id===e.id)||((m=y.extends)==null?void 0:m.id)===e.id)}));return D(n)}get implementedPropertiesFromOriginalParents(){return D([...(this.extends?[this.extends]:[]).reduce((i,n)=>{const s=n.implementedPropertiesFromOriginalParents,c=[...n.ownDeclaredProperties].filter(m=>!!m.abstract),e=[...s,...c,...i];return[...e].filter(m=>!!!e.find(E=>{var b;return((b=E.extends)==null?void 0:b.id)===m.id||E.implements.find(w=>w.id===m.id)}))},[])])}get extendedProperties(){return this.properties.filter(i=>i.isExtendedProperty)}get ownDeclaredMethods(){return[...this.methods]}get ownDeclaredProperties(){return this.properties.filter(i=>!i.isExtendedProperty)}subscribe(){return this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}async APILoad(i=Ge,...n){return await OA.repository.APILoad(this.id,...n),this}toFlat(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this,...this.properties.flatMap(s=>s.toFlat(i)),...this.methods.flatMap(s=>s.toFlat(i)),...this.abstractMethods.flatMap(s=>s.toFlat(i))])}toFlatIds(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.id,...this.properties.flatMap(s=>s.toFlatIds(i)),...this.methods.flatMap(s=>s.toFlatIds(i)),...this.abstractMethods.flatMap(s=>s.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 n;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(s=>s.toJSON(i)),methods:this.methods.map(s=>s.toJSON(i)),abstractMethods:this.abstractMethods.map(s=>s.toJSON(i)),extends:((n=this.extends)==null?void 0:n.toJSON(i))||null})}toReference(i=pt){return{id:this.id+"--"+x.UUID.uuid()+"--ref",type:o.GenericReference,entityId:this.id,version:this.version,entityType:this.type}}toShallowJSON(i=pt){var n;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(s=>s.toReference()),methods:this.methods.map(s=>s.toReference()),abstractMethods:this.abstractMethods.map(s=>s.toReference()),extends:((n=this.extends)==null?void 0:n.toReference())||null}}toFlatJSON(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.toShallowJSON(),...this.properties.flatMap(s=>s.toFlatJSON(i)),...this.methods.flatMap(s=>s.toFlatJSON(i)),...this.abstractMethods.flatMap(s=>s.toFlatJSON(i))])}toGenerationTarget(){var i;return{id:this.id,type:this.type,name:this.name,description:this.description,static:this.static,abstract:this.abstract,extends:(i=this.extends)==null?void 0:i.id}}toFlatGenerationTarget(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.toGenerationTarget(),...this.properties.flatMap(s=>s.toFlatGenerationTarget(i)),...this.methods.flatMap(s=>s.toFlatGenerationTarget(i)),...this.abstractMethods.flatMap(s=>s.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=bUi(this),{success:!0}}async validateAsync(i={}){const n=J.YieldTracker.from(i);return this.errors=await EUi(this,{tracker:n}),{success:!0}}getErrors(){return[...this.errors,...this.properties.flatMap(n=>n.getErrors()),...this.methods.flatMap(n=>n.getErrors()),...this.abstractMethods.flatMap(n=>n.getErrors())]}async getErrorsAsync(i={}){const n=J.YieldTracker.from(i),s=[...this.errors];await n.tick();for(const c of this.properties){const e=await c.getErrorsAsync({tracker:n});s.push(...e)}for(const c of this.methods){const e=await c.getErrorsAsync({tracker:n});s.push(...e)}for(const c of this.abstractMethods){const e=await c.getErrorsAsync({tracker:n});s.push(...e)}return s}getShallowErrors(){return this.errors}getAllInteractiveMethods(){const i=[];return i.push(...this.methods),!this.extends||this.extends.type===o.BuiltInBaseEntity&&this.extends.interactive||this.extends.type===o.PrimitiveEntity?i:(this.extends instanceof Po&&i.push(...this.extends.getAllInteractiveMethods()),D(i))}};I(OA,"repository",{APILoad:async(i,...n)=>null});let ma=OA;function Ui(d,p){if(!d)throw new Error("Entity is null");const i=p.get(d.id);switch(d.type){case o.LiteralValue:return i||new Yr(d,p);case o.DefinitionEntity:return i||new us(d,p);case o.PrimitiveEntity:return i||new ma(d,p);case o.FunctionDeclaration:return i||new _o(d,p);case o.GlobalEvent:return i||new Ru(d,p);case o.DataType:return i||new tr(d,p);case o.Property:return i||new ka(d,p);case o.FunctionCall:return i||new Bu(d,p);case o.Condition:return i||new wu(d,p);case o.Operation:return i||new Iu(d,p);case o.VariableDeclaration:return i||new _u(d,p);case o.VariableInstance:return i||new Cu(d,p);case o.OutputMap:return i||new gl(d,p);case o.ArgumentDeclaration:return i||new Ea(d,p);case o.InputMap:return i||new ds(d,p);case o.Project:return i||new x(d);case o.InstalledProject:return i||new Vu(d,p);case o.ActionDescriptor:return i||new $i(d,p);case o.ReturnStatement:return i||new md(d,p);case o.Loop:return i||new Du(d,p);case o.Search:return i||new Pu(d,p);case o.ValueDescriptor:return i||new Td(d,p);case o.BuiltInBaseEntity:return i||new Po(d,p);case o.InternalCall:return i||new Nu(d,p);case o.ContinueStatement:return i||new $u(d,p);case o.BreakStatement:return i||new xu(d,p);case o.GenericReference:return p.get(d.entityId);default:throw new Error("Invalid entity type: "+d.type)}}function ye(d,p){if(!d)throw new Error("Entity is null");const i=Ui(d,p);return i.subscribe(),i}function AUi(d,p){if(!d)throw new Error("Entity is null");switch(d.type){case o.LiteralValue:return Yr.fromGenerationTarget(d,p);case o.DefinitionEntity:return us.fromGenerationTarget(d,p);case o.FunctionDeclaration:return _o.fromGenerationTarget(d,p);case o.GlobalEvent:return Ru.fromGenerationTarget(d,p);case o.DataType:return tr.fromGenerationTarget(d,p);case o.Property:return ka.fromGenerationTarget(d,p);case o.FunctionCall:return Bu.fromGenerationTarget(d,p);case o.Condition:return wu.fromGenerationTarget(d,p);case o.Operation:return Iu.fromGenerationTarget(d,p);case o.VariableDeclaration:return _u.fromGenerationTarget(d,p);case o.VariableInstance:return Cu.fromGenerationTarget(d,p);case o.OutputMap:return gl.fromGenerationTarget(d,p);case o.ArgumentDeclaration:return Ea.fromGenerationTarget(d,p);case o.InputMap:return ds.fromGenerationTarget(d,p);case o.InstalledProject:return Vu.fromGenerationTarget(d,p);case o.ReturnStatement:return md.fromGenerationTarget(d,p);case o.Loop:return Du.fromGenerationTarget(d,p);case o.Search:return Pu.fromGenerationTarget(d,p);case o.ActionDescriptor:return $i.fromGenerationTarget(d,p);case o.ValueDescriptor:return Td.fromGenerationTarget(d,p);case o.InternalCall:return Nu.fromGenerationTarget(d,p);case o.ContinueStatement:return $u.fromGenerationTarget(d,p);case o.BreakStatement:return xu.fromGenerationTarget(d,p);default:throw new Error("Invalid entity type: "+d.type)}}const pt={seenEntityMaps:new Map,seenEntities:new Set,timestamp:M().toISOString()};class aKe{constructor(){I(this,"initialData")}}const Ge={cascade:!1},sKe={APILoad:async(d,...p)=>null},gUi={APICreate:async(d,...p)=>d,APIUpdate:async(d,...p)=>d,APIDelete:async(d,...p)=>d,APIClone:async(d,...p)=>{},APILoadVersion:async(d,p,...i)=>null,...sKe};class IUi{}class lKe extends aKe{}class RUi extends lKe{}class DUi{}class wUi{}class OUi{}class Ux{}class CUi extends Ux{}class _Ui extends Ux{}class PUi{}class of{static initReadsValue(p){if(p.initialData.readsValue&&p.initialData.readsValue.type!==o.GenericReference)p.readsValue=ye(p.initialData.readsValue,p.project);else if(p.initialData.readsValue&&p.initialData.readsValue.type===o.GenericReference){const i=Sn(p.initialData.readsValue,p.project);i&&(p.readsValue=i)}if(p.readsValue){if(qt.includes(p.readsValue.type)){let i=p.parent;!dr.includes(i.type)&&i.type!==o.Project&&(i=i.parent);const n=p.type===o.InputMap&&p.parent.type===o.Loop;n&&(i=p.parent.parent),p.readsValue.setParent(i,null),p.readsValue.initChildren(null),i&&i.type!==o.Project&&!n&&i.detachedChildren.includes(p)?i.replaceDetachedChild(p,p.readsValue):i&&i.type!==o.Project&&!n&&i.subscribeDetachedChild(p.readsValue)}p.readsValue.addValueReader(p,null)}return p.readsValue}}class Bv{static initWritesValues(p,i){const n=p.initialData.writesValues.reduce((c,e)=>{if(e.type===o.GenericReference||p.writesValues.some(m=>m.id===e.id))return c;const y=ye(e,p.project);return y.setValueWriter(p,null),qt.includes(y.type)&&(y.setParent(i,null),y.initChildren(null)),[...c,y]},[]),s=[...p.writesValues];return p.writesValues=D([...s,...n]),p.writesValues}}class VUi{}var ii=(d=>(d.PROJECT_INITIALIZED="project-initialized",d.BEFORE_CHANGE_SET_CLOSE_BEFORE_SIDE_EFFECTS="before-change-set-close-before-side-effects",d.BEFORE_CHANGE_SET_CLOSE_AFTER_SIDE_EFFECTS="before-change-set-close-after-side-effects",d.CHANGE_SET_CLOSED_BEFORE_PERSIST="change-set-closed-before-persist",d.CHANGE_SET_PERSISTED="change-set-persisted",d.BEFORE_CHANGE_SET_PERSIST="before-change-set-persist",d.EXPLICIT_DEFINITION_ENTITY_ADDED="explicit-definition-entity-added",d.EXPLICIT_DEFINITION_ENTITY_REMOVED="explicit-definition-entity-removed",d.EXPLICIT_DEFINITION_ENTITY_UPDATED="explicit-definition-entity-updated",d.PERSISTED_DEFINITION_ENTITY_ADDED="persisted-definition-entity-added",d.PERSISTED_DEFINITION_ENTITY_REMOVED="persisted-definition-entity-removed",d.PERSISTED_DEFINITION_ENTITY_UPDATED="persisted-definition-entity-updated",d.RELATIONAL_DATABASE_DEFINITION_ENTITY_ADDED="relational-database-definition-entity-added",d.RELATIONAL_DATABASE_DEFINITION_ENTITY_REMOVED="relational-database-definition-entity-removed",d.RELATIONAL_DATABASE_DEFINITION_ENTITY_UPDATED="relational-database-definition-entity-updated",d))(ii||{});const Kx={...IN,events:new J.Events("def-proj-static-p-ctx-events")},oKe={requestActiveDynamicValue:(d,p=!1)=>null,...Kx},_t=class _t extends kr{constructor(i,n={...oKe,events:new J.Events("def-proj-inst-p-ctx-events")}){super(i);I(this,"initialData");I(this,"id");I(this,"type",o.Project);I(this,"name",null);I(this,"description",null);I(this,"x");I(this,"y");I(this,"entities",[]);I(this,"projects",[]);I(this,"functions",[]);I(this,"events",[]);I(this,"variableDeclarations",[]);I(this,"variableInstances",[]);I(this,"conditions",[]);I(this,"operations",[]);I(this,"functionCalls",[]);I(this,"loops",[]);I(this,"searches",[]);I(this,"primitives",[]);I(this,"builtInBaseEntities",[]);I(this,"operationDeclarations",[]);I(this,"globalEventActionDescriptors",[]);I(this,"loopDeclarations",[]);I(this,"loopDeclarationsBodies",[]);I(this,"conditionDeclarations",[]);I(this,"valueDescriptors",[]);I(this,"dataTypes",[]);I(this,"project");I(this,"instances",{});I(this,"builtInInstances",{});I(this,"deletedInstances",{});I(this,"errors",[]);I(this,"references",[]);I(this,"history",[]);I(this,"undoableStackValueIndex",-1);I(this,"detachedDependents",{});I(this,"knownVersions",null);I(this,"activeVersion",!1);I(this,"initialized",!1);I(this,"startedInitialization",!1);I(this,"diggestedBuiltInBaseEntitiesIds",new Set);I(this,"rejectParallelCS",!1);I(this,"onPersistChangeSetSequentiallyCallback",null);I(this,"onPersistChangeSetInParallelCallback",null);I(this,"onAddChangeSetCallback",null);I(this,"onDiscardChangeSetCallback",null);if(this.parentContext=n,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)||M().toISOString(),author:(i==null?void 0:i.author)||_t.sessionAuthor,previousVersion:null,deleted:!1,deletable:!0,editable:!0,type:o.Project,name:"",description:"",entities:[],functions:[],events:[],projects:[],variableDeclarations:[],variableInstances:[],conditions:[],operations:[],functionCalls:[],loops:[],searches:[]}}static validateGenerationTarget(i,n){let s=JSON.parse(JSON.stringify(i));const c=[];return c.push(...Nr(s)),{errors:c,modifiedData:s}}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(){J.Logger.log("[ProjectState.closePersistChangeSetsSequentially] called");const i=this.history.find(n=>n.dirty&&!n.open&&!n.submitting);i&&(J.Logger.log(`[ProjectState.closePersistChangeSetsSequentially] closing pending change-set ${i.id} - ${i.autoCloseActionName}`),await this.persistChangeSetSequentially(i))}async onPersistChangeSetSequentially(i){this.onPersistChangeSetSequentiallyCallback=i,J.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,J.Logger.log("[ProjectState.onPersistChangeSetInParallel] onPersistChangeSetInParallelCallback has been set. Checking for pending change-sets.");for(const n of this.history)this.persistChangeSetInParallel(n),await new Promise(s=>setTimeout(s,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(J.Logger.log(`[ProjectState.persistChangeSetSequentially] called for change-set ${i.id} - ${i.autoCloseActionName}`),!i.dirty||i.open||i.submitting){J.Logger.log(`[ProjectState.persistChangeSetSequentially] change-set ${i.id} - ${i.autoCloseActionName} is not dirty, or is open, or is already being submitted, skipping.`);return}const n=this.history.findIndex(e=>e.id===i.id),s=this.history.slice(0,n),c=s[s.length-1];if(c!=null&&c.dirty){J.Logger.log(`[ProjectState.persistChangeSetSequentially] lastBeforeSelf is dirty: ${c.id} - ${c.autoCloseActionName}, closing it first.`);return}this.onPersistChangeSetSequentiallyCallback&&(J.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),J.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(J.Logger.log(`[ProjectState.persistChangeSetInParallel] called for change-set ${i.id} - ${i.autoCloseActionName}`),!i.dirty||i.open||i.submitting){J.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&&(J.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,n,s,c=!1,e="here-this"){if(!this.history.length)return new q(this,i,n,s,c,e);const y=this.history[this.history.length-1];return y.open?y:this.addChangeSet(new q(this,i,n,s,c,e))}addChangeSet(i){var s,c;if(!this.history.length)return this.undoableStackValueIndex=$O(this.undoableStackValueIndex,this.history,i),(s=this.onAddChangeSetCallback)==null||s.call(this,i,this.undoableStackValueIndex),i;const n=this.history.find(e=>e.id===(i==null?void 0:i.id));if(n)return n;if(this.rejectParallelCS){const e=this.history.find(y=>y.open);if(e)throw J.Logger.warn("Previous still open: ",e),J.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=$O(this.undoableStackValueIndex,this.history,i),(c=this.onAddChangeSetCallback)==null||c.call(this,i,this.undoableStackValueIndex),i}discardChangeSet(i){var s;J.Logger.log(`[ProjectState.discardChangeSet] called for change-set ${i.id} - ${i.autoCloseActionName}`);const n=this.history.findIndex(c=>c.id===(i==null?void 0:i.id));return n!==-1&&(this.history.splice(n,1),J.Logger.log(`[ProjectState.discardChangeSet] Removed change-set ${i.id} - ${i.autoCloseActionName} from history.`),this.undoableStackValueIndex=this.undoableStackValueIndex-1,(s=this.onDiscardChangeSetCallback)==null||s.call(this,i),i==null||i.teardown()),this}validateGeneratedUpdate(i){return{errors:[],modifiedData:i}}subscribeDependents(i){return i.forEach(n=>{this.detachedDependents[n.entity.id]||(this.detachedDependents[n.entity.id]=n)}),this}unsubscribeDependents(i){return i.forEach(n=>{this.detachedDependents[n.entity.id]&&delete this.detachedDependents[n.entity.id]}),this}syncDependents(i=this.project.addChangeSet(new q(this.project,_t.sessionAuthor,M().toISOString(),this,!0,"sync-dependents"))){const n=[],s=[],c=[],e=[];return Object.values(this.detachedDependents).forEach(y=>{const m=y.entity.afterAllChildrenInitialized(i);n.push(...m.updated),s.push(...m.added),c.push(...m.removed),e.push(...m.affected)}),i==null||i.attemptAutoclose("sync-dependents",this.id),{updated:D(n),added:D(s),removed:D(c),affected:D(e),self:this}}onDetachedDependencyRemoved(i,n,s){const c=[],e=[],y=[],m=[];return{updated:D(c),added:D(e),removed:D(y),affected:D(m),self:this}}onDetachedDependencyRestored(i,n,s){const c=[],e=[],y=[],m=[];return{updated:D(c),added:D(e),removed:D(y),affected:D(m),self:this}}unsubscribeFromDependencies(){return this}subscribeToDependencies(){return this}increaseVersion(i){if(i&&!M(i).isValid())throw new Error(`The shared timestamp '${i}' is not a valid ISO 8601 date string.`);return i&&M(i).isSame(M(this.createdAt))?this:(this.previousVersion=this.version,this.version=_t.UUID.uuid(),this.createdAt=M(i).toISOString()||M().toISOString(),this)}captureVersion(){var n;const i=((n=this.knownVersions)==null?void 0:n.get(this.version))||new _t(this);return i.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,i):new Map([[this.version,i]]),i.entities=[...this.entities],i.projects=[...this.projects],i.functions=[...this.functions],i.events=[...this.events],i.variableDeclarations=[...this.variableDeclarations],i.variableInstances=[...this.variableInstances],i.conditions=[...this.conditions],i.operations=[...this.operations],i.functionCalls=[...this.functionCalls],i.loops=[...this.loops],i.searches=[...this.searches],this}recursiveCaptureUpstreamVersions(i){const n=[],s=[],c=[],e=[];return{updated:D(n),added:D(s),removed:D(c),affected:D(e),self:this}}async restoreVersion(i){var m;const n=[],s=[],c=[],e=[];if(this.version===i)return{updated:D(n),added:D(s),removed:D(c),affected:D(e),self:this};if(!this.knownVersions){const v=new Map;for(const[E,b]of this.knownVersions||new Map){if(v.set(E,b),b.activeVersion=!1,b.knownVersions)for(const[w,P]of b.knownVersions)v.set(w,P);b.knownVersions=null}}let y=(m=this.knownVersions)==null?void 0:m.get(i);if(!y){const v=await this.APILoadVersion({},i);if(!v)throw new Error(`Version with id '${i}' for entity with id '${this.id}' not found.`);y=new _t(v)}return this.metaSync(y.toShallowJSON(),null),this.previousVersion=y.previousVersion,this.version=y.version,this.createdAt=y.createdAt,this.author=y.author,this.deleted=y.deleted,this.entities=y.entities,this.projects=y.projects,this.functions=y.functions,this.events=y.events,this.variableDeclarations=y.variableDeclarations,this.variableInstances=y.variableInstances,this.conditions=y.conditions,this.operations=y.operations,this.functionCalls=y.functionCalls,this.loops=y.loops,this.searches=y.searches,{updated:D(n),added:D(s),removed:D(c),affected:D(e),self:this}}updateWithShallowTransfer(i,n=this.project.addChangeSet(new q(this.project,_t.sessionAuthor,M().toISOString(),this,!0,_.UpdateWithShallowTransfer))){return this.checkCanEdit(this,n)?(this.metaSync(i,n),this.version=i.version,this.createdAt=i.createdAt,this.author=i.author,this.deleted=i.deleted,this.previousVersion=i.previousVersion,this.captureVersion(),this.subscribeToDependencies(),n==null||n.attemptAutoclose(_.UpdateWithShallowTransfer,this.id),this):(J.Logger.warn(`[updateWithShallowTransfer] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),n==null||n.attemptAutoclose(_.UpdateWithShallowTransfer,this.id),this)}hydrateAncestors(){const i=[],n=[],s=[],c=[];return{updated:D(i),added:D(n),removed:D(s),affected:D(c),self:this}}afterAllChildrenInitialized(i=null){const n=[],s=[],c=[],e=[];return this.initialized||(this.initialized=!0,this.emit("project-initialized",this,i)),this.validate(),this.captureVersion(),{updated:D(n),added:D(s),removed:D(c),affected:D(e),self:this}}addSelfToProject(i){const n=[],s=[],c=[],e=[];return this.subscribe(),this.subscribeToDependencies(),{updated:D(n),added:D(s),removed:D(c),affected:D(e),self:this}}get instancesList(){return Object.values(this.instances)}isOperationDeclaration(i){return this.operationDeclarations.includes(i)}isGlobalEventActionDescriptor(i){return this.globalEventActionDescriptors.includes(i)}isLoopDeclaration(i){return this.loopDeclarations.includes(i)}isConditionDeclaration(i){return this.conditionDeclarations.includes(i)}initChildren(i=this.project.addChangeSet(new q(this.project,_t.sessionAuthor,M().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.entities=this.initialData.entities.map(n=>{const s=ye(n,this);return s.setParent(this,null),s.initChildren(i),s}),this.projects=this.initialData.projects.map(n=>{const s=ye(n,this);return s.setParent(this,null),s.initChildren(i),s}),this.variableDeclarations=this.initialData.variableDeclarations.map(n=>{const s=ye(n,this);return s.setParent(this,null),s.initChildren(i),s}),this.variableInstances=this.initialData.variableInstances.map(n=>{const s=ye(n,this);return s.setParent(this,null),s.initChildren(i),s}),this.conditions=this.initialData.conditions.map(n=>{const s=ye(n,this);return s.setParent(this,null),s.initChildren(i),s}),this.operations=this.initialData.operations.map(n=>{const s=ye(n,this);return s.setParent(this,null),s.initChildren(i),s}),this.functions=this.initialData.functions.map(n=>{const s=ye(n,this);return s.setParent(this,null),s.initChildren(i),s}),this.events=this.initialData.events.map(n=>{const s=ye(n,this);return s.setParent(this,null),s.initChildren(i),s}),this.functionCalls=this.initialData.functionCalls.map(n=>{const s=ye(n,this);return s.setParent(this,null),s.initChildren(i),s}),this.loops=this.initialData.loops.map(n=>{const s=ye(n,this);return s.setParent(this,null),s.initChildren(i),s}),this.searches=this.initialData.searches.map(n=>{const s=ye(n,this);return s.setParent(this,null),s.initChildren(i),s}),this.attachOrphanReferences(),this.subscribeToDependencies(),this.afterAllChildrenInitialized(i),i==null||i.attemptAutoclose("init-children",this.id),this)}subscribeInstance(i){return(!this.instances[i.id]||this.instances[i.id]!==i)&&(this.instances[i.id]=i),this}subscribeDeletedInstance(i){return(!this.deletedInstances[i.id]||this.deletedInstances[i.id]!==i)&&(this.deletedInstances[i.id]=i),this}subscribeBuiltInInstance(i){return(!this.builtInInstances[i.id]||this.builtInInstances[i.id]!==i)&&(this.builtInInstances[i.id]=i),this}subscribe(){return this}unsubscribe(){return this}unsubscribeInstance(i){return delete this.instances[i.id],this}unsubscribeDeletedInstance(i){return delete this.deletedInstances[i.id],this}findSubscribedBuiltInInstance(i){return this.builtInInstances[i.id]||null}get(i){return this.instances[i]||this.builtInInstances[i]||null}getDeleted(i){return this.deletedInstances[i]||null}getManaged(i){return this.getBuiltIn(i)?null:this.instances[i]||null}getBuiltIn(i){return this.builtInInstances[i]||null}findSubscribedInstanceFromReference(i){return this.instances[i.entityId]||null}findSubscribedBuiltInInstanceFromReference(i){return this.builtInInstances[i.entityId]||null}metaSync(i,n=this.project.addChangeSet(new q(this.project,_t.sessionAuthor,M().toISOString(),this,!0,"meta-sync"))){const s=$r(this,i,n),c=xr(this,s),e=this.toMeta();return this.name=s.name!==void 0?s.name:e.name,this.description=s.description!==void 0?s.description:e.description,this.x=s.x||e.x,this.y=s.y||e.y,super.baseMetaSync(s,this,n),s.deleted===!0&&!e.deleted?n==null||n.add(this,Z.Removed):s.deleted===!1&&e.deleted?n==null||n.add(this,Z.Added):c&&(n==null||n.add(this,Z.Updated)),n==null||n.attemptAutoclose("meta-sync",this.id),this}async APILoad(i=Ge,...n){return await _t.repository.APILoad(this.id,...n),this}async APICreate(i=Ge,...n){return await _t.repository.APICreate(this.toShallowJSON(),...n),this}async APIUpdate(i=Ge,...n){return await _t.repository.APIUpdate(this.toShallowJSON(),...n),this}async APIDelete(i=Ge,...n){return await _t.repository.APIDelete(this.toShallowJSON(),...n),this}async APIClone(i=Ge,...n){return await _t.repository.APIClone(this.id,...n),this}async APILoadVersion(i=Ge,n,...s){return await _t.repository.APILoadVersion(this.id,n,...s)}remove({ignoreUpstream:i}={ignoreUpstream:!1},n=this.project.addChangeSet(new q(this.project,_t.sessionAuthor,M().toISOString(),this,!0,_.RemoveEntity))){return{added:[],updated:[],removed:[],affected:[],self:this}}restore({}={},i=this.project.addChangeSet(new q(this.project,_t.sessionAuthor,M().toISOString(),this,!0,_.RestoreEntity))){return{added:[],updated:[],removed:[],affected:[],self:this}}getAllBuiltInIds(){const i=new Set;return[...this.primitives.flatMap(n=>n.toFlatIds(i)),...this.builtInBaseEntities.flatMap(n=>n.toFlatIds(i)),...this.operationDeclarations.flatMap(n=>n.toFlatIds(i)),...this.globalEventActionDescriptors.flatMap(n=>n.toFlatIds(i)),...this.loopDeclarations.flatMap(n=>n.toFlatIds(i)),...this.conditionDeclarations.flatMap(n=>n.toFlatIds(i)),...this.valueDescriptors.flatMap(n=>n.toFlatIds(i)),...this.dataTypes.flatMap(n=>n.toFlatIds(i))]}getAllBuiltIn(){const i=new Set;return[...this.primitives.flatMap(n=>n.toFlat(i)),...this.builtInBaseEntities.flatMap(n=>n.toFlat(i)),...this.operationDeclarations.flatMap(n=>n.toFlat(i)),...this.globalEventActionDescriptors.flatMap(n=>n.toFlat(i)),...this.loopDeclarations.flatMap(n=>n.toFlat(i)),...this.conditionDeclarations.flatMap(n=>n.toFlat(i)),...this.valueDescriptors.flatMap(n=>n.toFlat(i)),...this.dataTypes.flatMap(n=>n.toFlat(i))]}toFlat(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this,...this.entities.flatMap(s=>s.toFlat(i)),...this.functions.flatMap(s=>s.toFlat(i)),...this.events.flatMap(s=>s.toFlat(i)),...this.projects.flatMap(s=>s.toFlat(i)),...this.variableDeclarations.flatMap(s=>s.toFlat(i)),...this.variableInstances.flatMap(s=>s.toFlat(i)),...this.conditions.flatMap(s=>s.toFlat(i)),...this.operations.flatMap(s=>s.toFlat(i)),...this.functionCalls.flatMap(s=>s.toFlat(i)),...this.loops.flatMap(s=>s.toFlat(i)),...this.searches.flatMap(s=>s.toFlat(i))])}toFlatIds(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.id,...this.entities.flatMap(s=>s.toFlatIds(i)),...this.functions.flatMap(s=>s.toFlatIds(i)),...this.events.flatMap(s=>s.toFlatIds(i)),...this.projects.flatMap(s=>s.toFlatIds(i)),...this.variableDeclarations.flatMap(s=>s.toFlatIds(i)),...this.variableInstances.flatMap(s=>s.toFlatIds(i)),...this.conditions.flatMap(s=>s.toFlatIds(i)),...this.operations.flatMap(s=>s.toFlatIds(i)),...this.functionCalls.flatMap(s=>s.toFlatIds(i)),...this.loops.flatMap(s=>s.toFlatIds(i)),...this.searches.flatMap(s=>s.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(n=>n.toJSON(i)),variableDeclarations:this.variableDeclarations.map(n=>n.toJSON(i)),variableInstances:this.variableInstances.map(n=>n.toJSON(i)),conditions:this.conditions.map(n=>n.toJSON(i)),operations:this.operations.map(n=>n.toJSON(i)),loops:this.loops.map(n=>n.toJSON(i)),searches:this.searches.map(n=>n.toJSON(i)),functions:this.functions.map(n=>n.toJSON(i)),events:this.events.map(n=>n.toJSON(i)),projects:this.projects.map(n=>n.toJSON(i)),functionCalls:this.functionCalls.map(n=>n.toJSON(i))})}toJSONClone(i={uuidStrategy:"uuid"}){const n=new Map,s=new Set,c=this.getAllBuiltInIds();return Object.keys(this.instances).forEach(e=>{if(c.includes(e)){n.set(e,e);return}n.set(e,_t.UUID.uuid())}),s.add(this.id),{id:n.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:n,seenEntities:s,newId:null})),projects:this.projects.map(e=>e.toJSONClone({...i,seenEntityMaps:n,seenEntities:s,newId:null})),variableDeclarations:this.variableDeclarations.map(e=>e.toJSONClone({...i,seenEntityMaps:n,seenEntities:s,newId:null})),variableInstances:this.variableInstances.map(e=>e.toJSONClone({...i,seenEntityMaps:n,seenEntities:s,newId:null})),conditions:this.conditions.map(e=>e.toJSONClone({...i,seenEntityMaps:n,seenEntities:s,newId:null})),operations:this.operations.map(e=>e.toJSONClone({...i,seenEntityMaps:n,seenEntities:s,newId:null})),functions:this.functions.map(e=>e.toJSONClone({...i,seenEntityMaps:n,seenEntities:s,newId:null})),events:this.events.map(e=>e.toJSONClone({...i,seenEntityMaps:n,seenEntities:s,newId:null})),functionCalls:this.functionCalls.map(e=>e.toJSONClone({...i,seenEntityMaps:n,seenEntities:s,newId:null})),loops:this.loops.map(e=>e.toJSONClone({...i,seenEntityMaps:n,seenEntities:s,newId:null})),searches:this.searches.map(e=>e.toJSONClone({...i,seenEntityMaps:n,seenEntities:s,newId:null}))}}toReference(i=pt){var s;let n=this.id;return(s=i.seenEntityMaps)!=null&&s.has(this.id)&&(n=i.seenEntityMaps.get(this.id)),{id:n+"--"+_t.UUID.uuid()+"--ref",type:o.GenericReference,entityId:n,version:this.version,entityType:this.type}}toShallowJSON(i=pt){var s;let n=this.id;return(s=i.seenEntityMaps)!=null&&s.has(this.id)&&(n=i.seenEntityMaps.get(this.id)),{id:n,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(s=>s.toFlatJSON(i)),...this.functions.flatMap(s=>s.toFlatJSON(i)),...this.events.flatMap(s=>s.toFlatJSON(i)),...this.projects.flatMap(s=>s.toFlatJSON(i)),...this.variableDeclarations.flatMap(s=>s.toFlatJSON(i)),...this.variableInstances.flatMap(s=>s.toFlatJSON(i)),...this.conditions.flatMap(s=>s.toFlatJSON(i)),...this.operations.flatMap(s=>s.toFlatJSON(i)),...this.functionCalls.flatMap(s=>s.toFlatJSON(i)),...this.loops.flatMap(s=>s.toFlatJSON(i)),...this.searches.flatMap(s=>s.toFlatJSON(i))])}toGenerationTarget(){return{id:this.id,type:this.type,name:this.name,description:this.description}}toFlatGenerationTarget(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[...this.entities.flatMap(s=>s.toFlatGenerationTarget(i)),...this.functions.flatMap(s=>s.toFlatGenerationTarget(i)),...this.events.flatMap(s=>s.toFlatGenerationTarget(i)),...this.projects.flatMap(s=>s.toFlatGenerationTarget(i)),...this.variableDeclarations.flatMap(s=>s.toFlatGenerationTarget(i)),...this.variableInstances.flatMap(s=>s.toFlatGenerationTarget(i)),...this.conditions.flatMap(s=>s.toFlatGenerationTarget(i)),...this.operations.flatMap(s=>s.toFlatGenerationTarget(i)),...this.functionCalls.flatMap(s=>s.toFlatGenerationTarget(i)),...this.loops.flatMap(s=>s.toFlatGenerationTarget(i)),...this.searches.flatMap(s=>s.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(),sv([...this.errors]),{success:!0}}async validateAsync(i={}){const n=J.YieldTracker.from(i);return await this.validateChildrenAsync({tracker:n}),await B_e([...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 n=J.YieldTracker.from(i);for(let s=0;s<this.entities.length;s++)await this.entities[s].validateAsync({tracker:n});for(let s=0;s<this.projects.length;s++)await this.projects[s].validateAsync({tracker:n});for(let s=0;s<this.functions.length;s++)await this.functions[s].validateAsync({tracker:n});for(let s=0;s<this.events.length;s++)await this.events[s].validateAsync({tracker:n});for(let s=0;s<this.variableDeclarations.length;s++)await this.variableDeclarations[s].validateAsync({tracker:n});for(let s=0;s<this.variableInstances.length;s++)await this.variableInstances[s].validateAsync({tracker:n});for(let s=0;s<this.conditions.length;s++)await this.conditions[s].validateAsync({tracker:n});for(let s=0;s<this.operations.length;s++)await this.operations[s].validateAsync({tracker:n});for(let s=0;s<this.functionCalls.length;s++)await this.functionCalls[s].validateAsync({tracker:n});for(let s=0;s<this.loops.length;s++)await this.loops[s].validateAsync({tracker:n});for(let s=0;s<this.searches.length;s++)await this.searches[s].validateAsync({tracker:n})}getErrors(){return[...this.errors,...this.entities.flatMap(n=>n.getErrors()),...this.projects.flatMap(n=>n.getErrors()),...this.functions.flatMap(n=>n.getErrors()),...this.events.flatMap(n=>n.getErrors()),...this.variableDeclarations.flatMap(n=>n.getErrors()),...this.variableInstances.flatMap(n=>n.getErrors()),...this.conditions.flatMap(n=>n.getErrors()),...this.operations.flatMap(n=>n.getErrors()),...this.functionCalls.flatMap(n=>n.getErrors()),...this.loops.flatMap(n=>n.getErrors()),...this.searches.flatMap(n=>n.getErrors())]}async getErrorsAsync(i={}){const n=J.YieldTracker.from(i),s=[...this.errors];await n.tick();for(let c=0;c<this.entities.length;c++){const e=await this.entities[c].getErrorsAsync({tracker:n});s.push(...e)}for(let c=0;c<this.projects.length;c++){const e=await this.projects[c].getErrorsAsync({tracker:n});s.push(...e)}for(let c=0;c<this.functions.length;c++){const e=await this.functions[c].getErrorsAsync({tracker:n});s.push(...e)}for(let c=0;c<this.events.length;c++){const e=await this.events[c].getErrorsAsync({tracker:n});s.push(...e)}for(let c=0;c<this.variableDeclarations.length;c++){const e=await this.variableDeclarations[c].getErrorsAsync({tracker:n});s.push(...e)}for(let c=0;c<this.variableInstances.length;c++){const e=await this.variableInstances[c].getErrorsAsync({tracker:n});s.push(...e)}for(let c=0;c<this.conditions.length;c++){const e=await this.conditions[c].getErrorsAsync({tracker:n});s.push(...e)}for(let c=0;c<this.operations.length;c++){const e=await this.operations[c].getErrorsAsync({tracker:n});s.push(...e)}for(let c=0;c<this.functionCalls.length;c++){const e=await this.functionCalls[c].getErrorsAsync({tracker:n});s.push(...e)}for(let c=0;c<this.loops.length;c++){const e=await this.loops[c].getErrorsAsync({tracker:n});s.push(...e)}for(let c=0;c<this.searches.length;c++){const e=await this.searches[c].getErrorsAsync({tracker:n});s.push(...e)}return s}getShallowErrors(){return this.errors}clone(){return this}getDefinitionEntity(i){return this.entities.find(n=>n.id===i)||null}addDefinitionEntity(i){return this.entities.includes(i)||this.entities.push(i),i}addFunctionDeclaration(i){return this.functions.includes(i)||this.functions.push(i),i}addFunctionCall(i){return this.functionCalls.includes(i)||this.functionCalls.push(i),i}addVariableDeclaration(i){return this.variableDeclarations.includes(i)||this.variableDeclarations.push(i),i}addVariableInstance(i){return this.variableInstances.includes(i)||this.variableInstances.push(i),i}addInstalledProject(i){return this.projects.includes(i)||this.projects.push(i),this}addGlobalEvent(i){return this.events.includes(i)||this.events.push(i),this}addCondition(i){return this.conditions.includes(i)||this.conditions.push(i),this}addOperation(i){return this.operations.includes(i)||this.operations.push(i),this}addLoop(i){return this.loops.includes(i)||this.loops.push(i),this}addSearch(i){return this.searches.includes(i)||this.searches.push(i),this}removeDefinitionEntity(i){const n=this.entities.findIndex(s=>s.id===i.id);if(n>-1){const s=this.entities[n];return this.entities.splice(n,1),s}return null}removeCondition(i){const n=this.conditions.findIndex(s=>s.id===i.id);if(n>-1){const s=this.conditions[n];return this.conditions.splice(n,1),s}return null}removeOperation(i){const n=this.operations.findIndex(s=>s.id===i.id);if(n>-1){const s=this.operations[n];return this.operations.splice(n,1),s}return null}removeLoop(i){const n=this.loops.findIndex(s=>s.id===i.id);if(n>-1){const s=this.loops[n];return this.loops.splice(n,1),s}return null}removeSearch(i){const n=this.searches.findIndex(s=>s.id===i.id);if(n>-1){const s=this.searches[n];return this.searches.splice(n,1),s}return null}removeFunctionCall(i){const n=this.functionCalls.findIndex(s=>s.id===i.id);if(n>-1){const s=this.functionCalls[n];return this.functionCalls.splice(n,1),s}return null}removeVariableInstance(i){const n=this.variableInstances.findIndex(s=>s.id===i.id);if(n>-1){const s=this.variableInstances[n];return this.variableInstances.splice(n,1),s}return null}removeVariableDeclaration(i){const n=this.variableDeclarations.findIndex(s=>s.id===i.id);if(n>-1){const s=this.variableDeclarations[n];return this.variableDeclarations.splice(n,1),s}return null}removeFunctionDeclaration(i){const n=this.functions.findIndex(s=>s.id===i.id);if(n>-1){const s=this.functions[n];return this.functions.splice(n,1),s}return null}removeInstalledProject(i){const n=this.projects.findIndex(s=>s.id===i.id);if(n>-1){const s=this.projects[n];return this.projects.splice(n,1),s}return null}removeGlobalEvent(i){const n=this.events.findIndex(s=>s.id===i.id);if(n>-1){const s=this.events[n];return this.events.splice(n,1),s}return null}removeTopLevelVariableDeclaration(i){if(i.type!==o.VariableDeclaration)return null;const n=this.variableDeclarations.findIndex(s=>s.id===i.id);if(n>-1){const s=this.variableDeclarations[n];return this.variableDeclarations.splice(n,1),s}return null}getEntryPoints(){return[...this.functions,...this.events,...this.entities.flatMap(n=>n.methods)]}getTerminationStatements(){return[...this.getEntryPoints().reduce((n,s)=>{const c=Dt(s);return[...n,...c.filter(e=>e.type===o.ReturnStatement||e.type===o.ContinueStatement||e.type===o.BreakStatement)]},[])]}getFunctionDeclaration(i){return this.functions.find(n=>n.id===i)||null}getConditions(){return[...this.conditions,...this.getEntryPoints().reduce((n,s)=>{const c=Dt(s);return[...n,...c.filter(e=>e.type===o.Condition)]},[]),...this.functionCalls.reduce((n,s)=>{const c=Dt(s);return[...n,...c.filter(e=>e.type===o.Condition)]},[]),...this.operations.reduce((n,s)=>{const c=Dt(s);return[...n,...c.filter(e=>e.type===o.Condition)]},[]),...this.loops.reduce((n,s)=>{const c=Dt(s);return[...n,...c.filter(e=>e.type===o.Condition)]},[]),...this.searches.reduce((n,s)=>{const c=Dt(s);return[...n,...c.filter(e=>e.type===o.Condition)]},[])]}getOperations(){return[...this.operations,...this.getEntryPoints().reduce((n,s)=>{const c=Dt(s);return[...n,...c.filter(e=>e.type===o.Operation)]},[]),...this.functionCalls.reduce((n,s)=>{const c=Dt(s);return[...n,...c.filter(e=>e.type===o.Operation)]},[]),...this.conditions.reduce((n,s)=>{const c=Dt(s);return[...n,...c.filter(e=>e.type===o.Operation)]},[]),...this.loops.reduce((n,s)=>{const c=Dt(s);return[...n,...c.filter(e=>e.type===o.Operation)]},[]),...this.searches.reduce((n,s)=>{const c=Dt(s);return[...n,...c.filter(e=>e.type===o.Operation)]},[])]}getFunctionCalls(){return[...this.functionCalls,...this.getEntryPoints().reduce((n,s)=>{const c=Dt(s);return[...n,...c.filter(e=>e.type===o.FunctionCall)]},[]),...this.conditions.reduce((n,s)=>{const c=Dt(s);return[...n,...c.filter(e=>e.type===o.FunctionCall)]},[]),...this.operations.reduce((n,s)=>{const c=Dt(s);return[...n,...c.filter(e=>e.type===o.FunctionCall)]},[]),...this.loops.reduce((n,s)=>{const c=Dt(s);return[...n,...c.filter(e=>e.type===o.FunctionCall)]},[]),...this.searches.reduce((n,s)=>{const c=Dt(s);return[...n,...c.filter(e=>e.type===o.FunctionCall)]},[])]}getVariables(){return[...this.variableDeclarations,...this.getEntryPoints().reduce((n,s)=>{const c=Wi(s);return[...n,...c]},[]),...this.functionCalls.reduce((n,s)=>{const c=Wi(s);return[...n,...c]},[]),...this.conditions.reduce((n,s)=>{const c=Wi(s);return[...n,...c]},[]),...this.operations.reduce((n,s)=>{const c=Wi(s);return[...n,...c]},[]),...this.loops.reduce((n,s)=>{const c=Wi(s);return[...n,...c]},[]),...this.searches.reduce((n,s)=>{const c=Wi(s);return[...n,...c]},[])]}getVariableInstances(){return[...this.variableInstances,...this.entities.reduce((n,s)=>[...n,...s.methods.flatMap(c=>{const y=Dt(c).filter(m=>m.type===o.VariableInstance);return[...n,...y]})],[]),...this.getEntryPoints().reduce((n,s)=>{const e=Wi(s).filter(y=>y.type===o.VariableInstance);return[...n,...e]},[]),...this.functionCalls.reduce((n,s)=>{const e=Wi(s).filter(y=>y.type===o.VariableInstance);return[...n,...e]},[]),...this.conditions.reduce((n,s)=>{const e=Wi(s).filter(y=>y.type===o.VariableInstance);return[...n,...e]},[]),...this.operations.reduce((n,s)=>{const e=Wi(s).filter(y=>y.type===o.VariableInstance);return[...n,...e]},[]),...this.loops.reduce((n,s)=>{const e=Wi(s).filter(y=>y.type===o.VariableInstance);return[...n,...e]},[]),...this.searches.reduce((n,s)=>{const e=Wi(s).filter(y=>y.type===o.VariableInstance);return[...n,...e]},[])]}getVariableDeclarations(){return D([...this.variableDeclarations,...this.entities.reduce((n,s)=>[...n,...s.methods.flatMap(c=>{const y=Dt(c).filter(m=>m.type===o.VariableDeclaration);return[...n,...y]})],[]),...this.getEntryPoints().reduce((n,s)=>{const e=Wi(s).filter(y=>y.type===o.VariableDeclaration);return[...n,...e]},[]),...this.functionCalls.reduce((n,s)=>{const e=Wi(s).filter(y=>y.type===o.VariableDeclaration);return[...n,...e]},[]),...this.conditions.reduce((n,s)=>{const e=Wi(s).filter(y=>y.type===o.VariableDeclaration);return[...n,...e]},[]),...this.operations.reduce((n,s)=>{const e=Wi(s).filter(y=>y.type===o.VariableDeclaration);return[...n,...e]},[]),...this.loops.reduce((n,s)=>{const e=Wi(s).filter(y=>y.type===o.VariableDeclaration);return[...n,...e]},[]),...this.searches.reduce((n,s)=>{const e=Wi(s).filter(y=>y.type===o.VariableDeclaration);return[...n,...e]},[])])}getLoops(){return[...this.loops,...this.getEntryPoints().reduce((n,s)=>{const c=Dt(s);return[...n,...c.filter(e=>e.type===o.Loop)]},[]),...this.functionCalls.reduce((n,s)=>{const c=Dt(s);return[...n,...c.filter(e=>e.type===o.Loop)]},[]),...this.conditions.reduce((n,s)=>{const c=Dt(s);return[...n,...c.filter(e=>e.type===o.Loop)]},[]),...this.operations.reduce((n,s)=>{const c=Dt(s);return[...n,...c.filter(e=>e.type===o.Loop)]},[]),...this.searches.reduce((n,s)=>{const c=Dt(s);return[...n,...c.filter(e=>e.type===o.Loop)]},[])]}getSearches(){return[...this.searches,...this.getEntryPoints().reduce((n,s)=>{const c=Dt(s);return[...n,...c.filter(e=>e.type===o.Search)]},[]),...this.functionCalls.reduce((n,s)=>{const c=Dt(s);return[...n,...c.filter(e=>e.type===o.Search)]},[]),...this.conditions.reduce((n,s)=>{const c=Dt(s);return[...n,...c.filter(e=>e.type===o.Search)]},[]),...this.operations.reduce((n,s)=>{const c=Dt(s);return[...n,...c.filter(e=>e.type===o.Search)]},[]),...this.loops.reduce((n,s)=>{const c=Dt(s);return[...n,...c.filter(e=>e.type===o.Search)]},[])]}attachOrphanReferences(){const i=this.getVariableInstances(),n=this.getVariableDeclarations();return i.forEach(s=>{if(!s.declaration){const c=s.initialData,e=c.declaration.entityId||c.declaration.id,y=n.find(m=>m.id===e);y&&s.setDeclaration(y)}}),this}getBuiltInPersistedEntity(){return this.builtInBaseEntities.find(i=>i.name===Re.PERSISTED_ENTITY)||null}requestActiveDynamicValue(i,n=!1){var c,e;const s=(e=(c=this.parentContext).requestActiveDynamicValue)==null?void 0:e.call(c,i,n);if(!s&&_A.includes(i.type)){const y=i.getDefaultValue();return y?{value:y,type:Le.DefaultValue,inheritanceLink:null,valueOwner:i}:null}return s||null}requestExtension(i){if(this.parentContext.requestExtension){const n=this.parentContext.requestExtension(i);if(n&&!n.module)throw new Error(`Module ${i} is not registered properly.`);return n.module||null}return null}undo(){J.Logger.log("Undoing, from: ",this.undoableStackValueIndex),this.undoableStackValueIndex=this.undoableStackValueIndex-1,J.Logger.log("To: ",this.undoableStackValueIndex);const i=this.history[this.undoableStackValueIndex+1],n=this.history[this.undoableStackValueIndex];return J.Logger.log("Current change set: ",i==null?void 0:i.toJSON()),J.Logger.log("Change set to restore: ",n==null?void 0:n.toJSON()),NO(i||"initial",n||"initial",this)}redo(){J.Logger.log("Undoing, from: ",this.undoableStackValueIndex),this.undoableStackValueIndex=this.undoableStackValueIndex+1,J.Logger.log("To: ",this.undoableStackValueIndex);const i=this.history[this.undoableStackValueIndex-1],n=this.history[this.undoableStackValueIndex];return J.Logger.log("Current change set: ",i==null?void 0:i.toJSON()),J.Logger.log("Change set to restore: ",n.toJSON()),NO(i||"initial",n||"initial",this)}applyExternalChangeSet(i){const n=i.payload,s=this.addChangeSet(new q(this,i.userAuthor,i.emittedAt,this));s.ignoreNonEditable=!0,s.ignoreNonDeletable=!0;const c=n.updated[this.id];if(!c)throw new Error("Project root not found in change set transfer. Cannot apply changes.");const e={...n.added,...n.updated,...n.removed},y=[...Object.keys(n.added),...Object.keys(n.updated),...Object.keys(n.removed)];y.forEach(v=>{var E;if(!e[v]){J.Logger.warn(`Entity '${v}' not found in change set transfer. Cannot apply changes.`);const b=(E=this.get(v))==null?void 0:E.toShallowJSON();throw b?J.Logger.warn("Entity in project: ",b):J.Logger.warn("Entity not in project"),new Error(`Entity '${v}' not found in change set transfer. Cannot apply changes.`)}});const m=new Yn(c,{allBuiltInEntityIds:this.diggestedBuiltInBaseEntitiesIds});return m.flatRecord=e,m.order=y,m.orderEntities(),J.Logger.log("All entities: ",m.order.map((v,E)=>`${E+1}: ${e[v].type} - ${v}`).join(`,
package/dist/index.js CHANGED
@@ -194046,6 +194046,9 @@ ${CD}`
194046
194046
  }
194047
194047
  getDefaultValue() {
194048
194048
  var c;
194049
+ console.log("[getDefaultValue] Resolving default value for property", this.id, " name:", this.name), console.log(`[getDefaultValue] implements:
194050
+ - ${this.implements.map((e) => e.id + " name: " + e.name).join(`
194051
+ - `)}`);
194049
194052
  let i = null;
194050
194053
  for (const e of this.implements) {
194051
194054
  const y = e.getDefaultValue();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elyx-code/project-logic-tree",
3
- "version": "0.0.6691",
3
+ "version": "0.0.6692",
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",