@elyx-code/project-logic-tree 0.0.6719 → 0.0.6720
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +1 -1
- package/dist/index.js +4 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -383,7 +383,7 @@ This is likely an incorrect strategy, either the '${this.type}' entity doesn't n
|
|
|
383
383
|
${EA}`})),{errors:n,modifiedData:i}}onProjectInitialized(i,n=this.project.addChangeSet(new Z(this.project,x.sessionAuthor,new Date().toISOString(),this,!0,"on-property-received-project-initialized"))){return n?(Ck(this,n),n==null||n.attemptAutoclose("on-property-received-project-initialized",this.id),this):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 Z(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(zt.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"}]),H1i(this)&&this.project.on(zt.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 ri(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!==d.PrimitiveEntity&&this.parent.type!==d.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 ri(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 Z(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(`${Sr(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(`${Sr(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(`${Sr(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(`${Sr(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 Z(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===d.DefinitionEntity&&this.parentRelationType!==vc.AllPropertiesImplementationTarget){let X=this.index||0;const ae=this.parent.properties.filter(fe=>!fe.deleted&&fe.id!==this.id);ae.length&&(X>ae.length+1?X=ae.length:X<0&&(X=0)),ae.find(fe=>(fe.index||0)===X&&!fe.deleted)&&ae.filter(fe=>(fe.index||0)>=X&&!fe.deleted).forEach(fe=>{fe.metaSync({index:(fe.index||0)+1},i),i==null||i.add(fe,H.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:$}=Ck(this,i);n.push(...b),s.push(...w),c.push(...P),e.push(...$);const{updated:L,added:j,removed:F,affected:q}=this.syncWithExtension(i);return n.push(...L),s.push(...j),c.push(...F),e.push(...q),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 Z(this.project,x.sessionAuthor,M().toISOString(),this,!0,"add-self-to-project"))){const n=[this],s=[],c=[],e=[];return this.parentRelationType===vc.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 Z(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,H.Updated))),n==null||n.attemptAutoclose(_.SetParent,this.id),this):this}addImplementation(i,n=this.project.addChangeSet(new Z(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,H.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 Z(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,H.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 Z(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,H.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 Z(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=he(this.initialData.defaultValue,this.project),this.defaultValue.setParent(this,null),this.defaultValue.initChildren(i)),this.initialData.dataType){const n=he(this.initialData.dataType,this.project);n.setParent(this,null),n.initChildren(i),this.dataType=n}if(this.implements=this.initialData.implements.map(n=>he(n,this.project)),this.initialData.extends){const n=he(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(){if(this.id==="3bdd91d6-fa96-403f-af98-532a1110b28a")throw console.log("[PropertyState.unsubscribe] debug"),new Error("[PropertyState.unsubscribe] debug");return this.project.unsubscribeInstance(this),this}metaSync(i,n=this.project.addChangeSet(new Z(this.project,x.sessionAuthor,M().toISOString(),this,!0,"meta-sync"))){const s=Lr(this,i,n),c=$r(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,H.Removed):s.deleted===!1&&e.deleted?n==null||n.add(this,H.Added):c&&(n==null||n.add(this,H.Updated)),n==null||n.attemptAutoclose("meta-sync",this.id),this}async APILoad(i=ke,...n){return await ri.repository.APILoad(this.id,...n),this}async APICreate(i=ke,...n){return await ri.repository.APICreate(this.toShallowJSON(),...n),this}async APIUpdate(i=ke,...n){return await ri.repository.APIUpdate(this.toShallowJSON(),...n),this}async APIDelete(i=ke,...n){return await ri.repository.APIDelete(this.toShallowJSON(),...n),this}async APIClone(i=ke,...n){return await ri.repository.APIClone(this.id,...n),this}async APILoadVersion(i=ke,n,...s){return await ri.repository.APILoadVersion(this.id,n,...s)}removeFromParent(i=this.project.addChangeSet(new Z(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===d.DefinitionEntity&&(this.parentRelationType===vc.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 Z(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:rr.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 Z(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===d.DefinitionEntity&&(this.parentRelationType===vc.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=ct){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=ct){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:d.GenericReference,entityId:n,version:this.version,entityType:this.type}}toShallowJSON(i=ct){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=KBe(this),{success:!0}}async validateAsync(i={}){const n=J.YieldTracker.from(i);return this.errors=await UBe(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 Z(this.project,x.sessionAuthor,M().toISOString(),this,!0,"implement-self-as-property")),s=null){var v;const c=s||x.UUID.uuid(),e=ri.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=he(e,this.project);y.hydrateAncestors(),y.addSelfToProject(n),n==null||n.add(y,H.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 Z(this.project,x.sessionAuthor,M().toISOString(),this,!0,_.CloneEntity)),n=null,s=null,c=!0){var b,w;const e=Vr(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=Ki(v,e);if(E.hydrateAncestors(),E.setParent(m,i),c&&(E.subscribe(),E.addSelfToProject(i)),E.initChildren(i),i==null||i.add(E,H.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 Z(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,H.Affected)),n==null||n.attemptAutoclose(_.SetDataType,this.id),this}removeDataType(i=this.project.addChangeSet(new Z(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,H.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 Z(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||_r(i))&&y&&(i=y)}let n=this.defaultValue;const s=(c=this.extends)==null?void 0:c.getDefaultValue();return _r(n)&&s&&!_r(s)&&(n=s),_r(n)&&i&&!_r(i)&&(n=i),n}setDefaultValue(i,n=this.project.addChangeSet(new Z(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,H.Affected)),n==null||n.attemptAutoclose("set-default-value",this.id),this}syncWithImplementation(i=this.project.addChangeSet(new Z(this.project,x.sessionAuthor,M().toISOString(),this,!0,"sync-with-implementation"))){var P,$,L,j,F,q,X,ae,ee,fe,oe;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!==d.PrimitiveEntity&&this.interactive&&this.parent.getAllPropertiesImplements().filter(Te=>Te.id!==this.id).forEach(Te=>{this.addImplementation(Te,i)}),this.implements.find(ce=>ce.id===this.id)&&this.removeImplementation(this,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=Yr(this.dataType,y);if(!this.dataType||!((L=this.dataType)!=null&&L.isResolved)||(j=this.dataType)!=null&&j.isResolved&&(y!=null&&y.isResolved)&&!m.compatible){if(y&&((F=y.orChildrenGroup)!=null&&F.length)&&y.implementationChooseOne){if(!this.dataType||this.dataType&&this.project.diggestedBuiltInBaseEntitiesIds.has(this.dataType.id)){const Te=ir.new(i);Te.parent=this.toReference();const de=he(Te,this.project);de.hydrateAncestors(),i==null||i.add(de,H.Added),de.addSelfToProject(i),de.afterAllChildrenInitialized(i)}const ce=y.orChildrenGroup.some(Te=>Te.foreignKeyAllowed);if(((X=(q=this.dataType)==null?void 0:q.entity)==null?void 0:X.type)===d.DefinitionEntity&&Zi(this.dataType.entity,Re.PERSISTED_ENTITY)&&ce){const Te=J4e(this.dataType.entity);Te&&this.dataType.setForeignKeyRef(Te,i),(ae=this.dataType)==null||ae.setEntity(null,i)}else{const Te=y.orChildrenGroup.find(de=>{var ye;return((ye=de.entity)==null?void 0:ye.id)===Q["primitive-entity"].string.id});if(Te)(ee=this.dataType)==null||ee.setEntity(Te.entity,i);else{const de=y.orChildrenGroup.filter(_e=>_e.isResolved),ye=de.filter(_e=>{var Pe;return((Pe=_e.entity)==null?void 0:Pe.type)===d.PrimitiveEntity});ye.length?(fe=this.dataType)==null||fe.setEntity(ye[0].entity,i):de.length&&((oe=this.dataType)==null||oe.setEntity(de[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 Te of this.implements){const de=Te.getDefaultValue();de&&(ce=de)}if(ce){const Te=ce.clone(i,this,x.UUID.uuid(),!0);this.setDefaultValue(Te,i),s.push(Te)}}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 Z(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=ir.new(i);b.parent=this.toReference();const w=he(b,this.project);w.hydrateAncestors(),i==null||i.add(w,H.Added),w.addSelfToProject(i),w.afterAllChildrenInitialized(i)}if(Yr(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&&!pGe(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 Z(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=Ki(c,this.project);if(e.hydrateAncestors(),e.addSelfToProject(i),i==null||i.add(e,H.Added),e.initChildren(i),this.dataType)if(this.project.diggestedBuiltInBaseEntitiesIds.has(this.dataType.id))e.setDataType(this.dataType,i),i==null||i.add(e,H.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(ri,"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(ri,"type",d.Property),I(ri,"USER_MANAGED_PARENT_TYPES",[d.DefinitionEntity]),I(ri,"PARENT_TYPES",[...ri.USER_MANAGED_PARENT_TYPES,d.PrimitiveEntity,d.BuiltInBaseEntity]),I(ri,"MUTABLE_BASE_PROPERTIES",["name","codeName","description","private","abstract","static","required","constant","unique","interactive"]),I(ri,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),I(ri,"BASE_PROPERTIES",[...ri.MUTABLE_BASE_PROPERTIES,...ri.INMUTABLE_BASE_PROPERTIES]),I(ri,"MUTABLE_META_PROPERTIES",[...ri.MUTABLE_BASE_PROPERTIES,"index"]),I(ri,"INMUTABLE_META_PROPERTIES",[...ri.INMUTABLE_BASE_PROPERTIES]),I(ri,"META_PROPERTIES",[...ri.MUTABLE_META_PROPERTIES,...ri.INMUTABLE_META_PROPERTIES]),I(ri,"MUTABLE_UPSTREAM_PROPERTIES",[]),I(ri,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","implements","extends"]),I(ri,"UPSTREAM_PROPERTIES",[...ri.MUTABLE_UPSTREAM_PROPERTIES,...ri.INMUTABLE_UPSTREAM_PROPERTIES]),I(ri,"MUTABLE_DOWNSTREAM_PROPERTIES",["dataType"]),I(ri,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),I(ri,"DOWNSTREAM_PROPERTIES",[...ri.MUTABLE_DOWNSTREAM_PROPERTIES,...ri.INMUTABLE_DOWNSTREAM_PROPERTIES]),I(ri,"PROPERTIES",[...ri.META_PROPERTIES,...ri.UPSTREAM_PROPERTIES,...ri.DOWNSTREAM_PROPERTIES]);let ja=ri;async function SBe(o,p={}){var E,b;const i=J.YieldTracker.from(p),n=o.implements.flatMap(w=>WBe(o,w)),s=zBe(o,o.extends),c=YBe(o),e=JBe(o),y=ZN(o),m=[...n,...s,...c,...e,...y],v=Mt(o.errors,m);await i.tick();for(const w of o.properties)await w.validateAsync({tracker:i});for(const w of o.methods)await w.validateAsync({tracker:i});for(const w of o.abstractMethods)await w.validateAsync({tracker:i});return await((E=o.allPropertiesImplement)==null?void 0:E.validateAsync({tracker:i})),await((b=o.additionalPropertiesDataType)==null?void 0:b.validateAsync({tracker:i})),v}function qBe(o){var m,v;const p=o.implements.flatMap(E=>WBe(o,E)),i=zBe(o,o.extends),n=YBe(o),s=JBe(o),c=ZN(o);o.properties.forEach(E=>{E.validate()}),o.methods.flatMap(E=>E.validate()),o.abstractMethods.flatMap(E=>E.validate()),(m=o.allPropertiesImplement)==null||m.validate(),(v=o.additionalPropertiesDataType)==null||v.validate();const e=[...p,...i,...n,...s,...c];return Mt(o.errors,e)}function ZBe(o,p){const i=p.properties.filter(c=>c.abstract),n=[];let s=[...o.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 HBe(o,p){const i=p.abstractMethods,n=[];let s=[...o.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 WBe(o,p){const i=[];if(!p.abstract){const E=Lt({id:o.id+"--"+me.ImplementingNonAbstractEntity,message:`Entity "${o.name}" with id "${o.id}" is implementing a non-abstract entity "${p.name}" with id "${p.id}"`,severity:pe.Error,code:me.ImplementingNonAbstractEntity,entity:o});return i.push(E.error),i}const n=p.properties.filter(E=>E.abstract),s=[];let c=[...o.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=Lt({id:o.id+"--"+me.MissingPropertyImplementation+"--"+E.id,message:`Property "${E.name}" with id "${E.id}" of entity "${p.name}" with id "${p.id}" is not implemented when entity "${o.name}" with id "${o.id}" implements it`,severity:pe.Error,code:me.MissingPropertyImplementation,entity:o});i.push(b.error)});const e=[];let y=[...o.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=Lt({id:o.id+"--"+me.MissingMethodImplementation+"--"+E.id,message:`Method "${E.name}" with id "${E.id}" of entity "${p.name}" with id "${p.id}" is not implemented when entity "${o.name}" with id "${o.id}" implements it`,severity:pe.Error,code:me.MissingMethodImplementation,entity:o});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=Lt({id:o.id+"--"+Ie.PropertyOverwritesOtherSiblingWithSameName+"--"+E.id,message:`Property "${E.name}" with id "${E.id}" of entity "${o.name}" with id "${o.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:o});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=Lt({id:o.id+"--"+Ie.MethodOverwritesOtherSiblingWithSameName+"--"+E.id,message:`Method "${E.name}" with id "${E.id}" of entity "${o.name}" with id "${o.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:o});i.push(b.error)}),i}function zBe(o,p){const i=[];if(!p)return i;const n=[];if(!o.abstract&&p.abstract){const c=Lt({id:o.id+"--"+p.id+"--"+me.NonAbstractExtendingAbstractEntity,message:`Entity "${o.name}" with id "${o.id}" is not-abstract but is extending an abstract entity "${p.name}" with id "${p.id}"`,severity:pe.Error,code:me.NonAbstractExtendingAbstractEntity,entity:o,firstRelationship:p});return i.push(c.error),i}if(o.abstract&&!p.abstract){const c=Lt({id:o.id+"--"+p.id+"--"+me.AbstractExtendingNonAbstractEntity,message:`Entity "${o.name}" with id "${o.id}" is abstract but is extending an non-abstract entity "${p.name}" with id "${p.id}"`,severity:pe.Error,code:me.AbstractExtendingNonAbstractEntity,entity:o,firstRelationship:p});return i.push(c.error),i}o.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=Lt({id:o.id+"--"+Ie.PropertyOverwritesOtherSiblingWithSameName,message:`Property "${c.name}" with id "${c.id}" of entity "${o.name}" with id "${o.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:o});i.push(e.error)});const s=[];return o.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=Lt({id:o.id+"--"+Ie.MethodOverwritesOtherSiblingWithSameName,message:`Method "${c.name}" with id "${c.id}" of entity "${o.name}" with id "${o.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:o});i.push(e.error)}),i}function JBe(o){const p=[];if(!o.properties.length){const i=Lt({id:o.id+"--"+me.NoProperties,message:"No properties implemented",severity:pe.Warning,code:me.NoProperties,entity:o});p.push(i.error)}return p}function YBe(o){const p=[];if(o.abstract){if(o.methods.length){const i=Lt({id:o.id+"--"+me.AbstractEntityWithNonAbstractMethods,message:`Entity "${o.name}" with id "${o.id}" is marked as abstract but has non-abstract methods`,severity:pe.Error,code:me.AbstractEntityWithNonAbstractMethods,entity:o});p.push(i.error)}if(o.properties.some(i=>!i.abstract)){const i=Lt({id:o.id+"--"+me.AbstractEntityWithNonAbstractProperties,message:`Entity "${o.name}" with id "${o.id}" is marked as abstract but has non-abstract properties`,severity:pe.Error,code:me.AbstractEntityWithNonAbstractProperties,entity:o});p.push(i.error),o.properties.forEach(n=>{if(!n.abstract){const s=Lt({id:o.id+"--"+me.StaticEntityWithNonStaticProperties+"--"+n.id,message:`Property "${n.name}" with id "${n.id}" of entity "${o.name}" with id "${o.id}" is not marked as abstract but the entity is marked as abstract`,severity:pe.Error,code:me.StaticEntityWithNonStaticProperties,entity:o});p.push(s.error)}})}}else{if(o.abstractMethods.length){const i=Lt({id:o.id+"--"+me.AbstractPropertyInNonAbstractEntity,message:`Entity "${o.name}" with id "${o.id}" is not marked as abstract but has abstract methods`,severity:pe.Error,code:me.AbstractPropertyInNonAbstractEntity,entity:o});p.push(i.error)}o.properties.some(i=>i.abstract)&&o.properties.forEach(i=>{if(i.abstract){const n=Lt({id:o.id+"--"+me.AbstractPropertyInNonAbstractEntity+"--"+i.id,message:`Property "${i.name}" with id "${i.id}" of entity "${o.name}" with id "${o.id}" is marked as abstract but the entity is not marked as abstract`,severity:pe.Error,code:me.AbstractPropertyInNonAbstractEntity,entity:o,firstRelationship:i});p.push(n.error)}})}return o.static&&o.properties.some(i=>!i.static)&&o.properties.forEach(i=>{if(!i.static){const n=Lt({id:o.id+"--"+me.NonStaticPropertyInStaticEntity+"--"+i.id,message:`Property "${i.name}" with id "${i.id}" of entity "${o.name}" with id "${o.id}" is not marked as static but the entity is marked as static`,severity:pe.Error,code:me.NonStaticPropertyInStaticEntity,entity:o,firstRelationship:i});p.push(n.error)}}),p}function W1i(o,p){const i=[],n=Zn(p);if(!p.abstract){const e=new Bi({id:o.id+"--"+p.id+"--"+me.ImplementingNonAbstractEntity,message:`Entity "${o.name}" with id "${o.id}" is implementing a non-abstract built-in entity "${p.name}" with id "${p.id}"`,severity:pe.Error,code:me.ImplementingNonAbstractEntity,entity:o,firstRelationship:p});i.push(e)}const s=o.implements.filter(e=>e.id!==p.id);if(o.abstract){const e=new Bi({id:o.id+"--"+p.id+"--"+me.AbstractEntityImplements,message:`Entity "${o.name}" with id "${o.id}" is marked as abstract and cannot implement built-in entity "${p.name}" with id "${p.id}"`,severity:pe.Error,code:me.AbstractEntityImplements,entity:o,firstRelationship:p});i.push(e)}if(o.static&&!p.static){const e=new Bi({id:o.id+"--"+p.id+"--"+me.StaticImplementingNonStaticEntity,message:`Entity "${o.name}" with id "${o.id}" is marked as static and cannot implement non-static built-in entity "${p.name}" with id "${p.id}"`,severity:pe.Error,code:me.StaticImplementingNonStaticEntity,entity:o,firstRelationship:p});i.push(e)}if(!o.static&&p.static){const e=new Bi({id:o.id+"--"+p.id+"--"+me.NonStaticImplementingStaticEntity,message:`Entity "${o.name}" with id "${o.id}" is not marked as static and cannot implement static built-in entity "${p.name}" with id "${p.id}"`,severity:pe.Error,code:me.NonStaticImplementingStaticEntity,entity:o,firstRelationship:p});i.push(e)}return s.length&&s.forEach(e=>{if(e.type===d.BuiltInBaseEntity){const y=n.filter(m=>m.id!==e.id);y.length&&y.forEach(m=>{if(m.id!==e.id){const v=new Bi({id:o.id+"--"+m.id+"--"+e.id+"--"+me.ImplementsIncompatibleEntities,message:`Entity "${o.name}" with id "${o.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:me.ImplementsIncompatibleEntities,entity:o,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 Bi({id:o.id+"--"+w.id+"--"+E.id+"--"+me.ImplementsIncompatibleEntities,message:`Entity "${o.name}" with id "${o.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:me.ImplementsIncompatibleEntities,entity:o,firstRelationship:w,secondRelationship:E});i.push(P)}})});const m=ud(p.ownDeclaredProperties,e.ownDeclaredProperties,Ie.PropertyOverwritesOtherImplementedEntitysPropertyWithSameImplementation,Ie.PropertyOverwritesOtherImplementedEntitysPropertyWithSameName);i.push(...m.errors);const v=ud(p.abstractMethods,[...e.abstractMethods,...e.methods],Ie.MethodOverwritesOtherImplementedEntitysMethodWithSameImplementation,Ie.MethodOverwritesOtherImplementedEntitysMethodWithSameName);i.push(...v.errors)}}),D(o.extends?Zn(o.extends):[]).forEach(e=>{if(!n.find(y=>y.id===e.id)){const y=new Bi({id:o.id+"--"+p.id+"--"+e.id+"--"+me.ExtendsIncompatibleEntities,message:`Entity "${o.name}" with id "${o.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:me.ExtendsIncompatibleEntities,entity:o,firstRelationship:p,secondRelationship:e});i.push(y)}}),i}function z1i(o,p,i=!1){var v,E;const n=[],s=Zn(p);if(!o.abstract&&p.abstract){const b=Lt({id:o.id+"--"+p.id+"--"+me.NonAbstractExtendingAbstractEntity,message:`Entity "${o.name}" with id "${o.id}" is not-abstract but is extending an abstract entity "${p.name}" with id "${p.id}"`,severity:pe.Error,code:me.NonAbstractExtendingAbstractEntity,entity:o,firstRelationship:p});n.push(b.error)}if(o.abstract&&!p.abstract){const b=Lt({id:o.id+"--"+p.id+"--"+me.AbstractExtendingNonAbstractEntity,message:`Entity "${o.name}" with id "${o.id}" is abstract but is extending an non-abstract entity "${p.name}" with id "${p.id}"`,severity:pe.Error,code:me.AbstractExtendingNonAbstractEntity,entity:o,firstRelationship:p});n.push(b.error)}if(!o.static&&p.static){const b=Lt({id:o.id+"--"+p.id+"--"+me.NonStaticExtendingStaticEntity,message:`Entity "${o.name}" with id "${o.id}" is not static but is extending a static entity "${p.name}" with id "${p.id}"`,severity:pe.Error,code:me.NonStaticExtendingStaticEntity,entity:o,firstRelationship:p});n.push(b.error)}if(o.static&&!p.static){const b=Lt({id:o.id+"--"+p.id+"--"+me.StaticExtendingNonStaticEntity,message:`Entity "${o.name}" with id "${o.id}" is static but is extending an non-static entity "${p.name}" with id "${p.id}"`,severity:pe.Error,code:me.StaticExtendingNonStaticEntity,entity:o,firstRelationship:p});n.push(b.error)}if(!lf(p)){const b=Lt({id:o.id+"--"+p.id+"--"+me.ExtendingNonInteractiveEntity,message:`Entity "${o.name}" with id "${o.id}" is extending an non-interactive entity "${p.name}" with id "${p.id}"`,severity:pe.Error,code:me.ExtendingNonInteractiveEntity,entity:o,firstRelationship:p});n.push(b.error)}if(o.extends&&((v=o.extends)==null?void 0:v.id)!==p.id)if(((E=o.extends)==null?void 0:E.type)===d.BuiltInBaseEntity){const b=s.filter(w=>{var P;return w.id!==((P=o.extends)==null?void 0:P.id)});b.length&&b.forEach(w=>{var P,$,L,j;if(w.id!==((P=o.extends)==null?void 0:P.id)){const F=Lt({id:o.id+"--"+w.id+"--"+(($=o.extends)==null?void 0:$.id)+"--"+me.ExtendsIncompatibleEntities,message:`Entity "${o.name}" with id "${o.id}" is extending built-in entity "${w.name}" with id "${w.id}" but also extends entity "${(L=o.extends)==null?void 0:L.name}" with id "${(j=o.extends)==null?void 0:j.id}" which is incompatible`,severity:pe.Error,code:me.ExtendsIncompatibleEntities,entity:o,firstRelationship:w,secondRelationship:o.extends});n.push(F.error)}})}else{Zn(o.extends).forEach(F=>{const q=s.filter(X=>X.id!==F.id);q.length&&q.forEach(X=>{if(X.id!==F.id){const ae=new Bi({id:o.id+"--"+X.id+"--"+F.id+"--"+me.ImplementsIncompatibleEntities,message:`Entity "${o.name}" with id "${o.id}" is extending built-in entity "${X.name}" with id "${X.id}" but also extends or implements entity "${F.name}" with id "${F.id}" which is incompatible`,severity:pe.Error,code:me.ImplementsIncompatibleEntities,entity:o,firstRelationship:X,secondRelationship:F});n.push(ae)}})});const w=!!Zn(o.extends).find(F=>F.id===p.id);let P=[...o.extends.properties];w&&(P=P.filter(F=>!p.properties.find(q=>q.id===F.id||q.name===F.name||!!F.implements.find(X=>X.id===q.id))));let $=[...o.extends.methods];w&&($=$.filter(F=>!p.methods.find(q=>{var X;return q.id===F.id||q.name===F.name||q.id===((X=F.implements)==null?void 0:X.id)})));const L=ud(p.ownDeclaredProperties,P,Ie.PropertyOverwritesOtherExtendedEntitysPropertyWithSameImplementation,Ie.PropertyOverwritesOtherExtendedEntitysPropertyWithSameName);n.push(...L.errors);const j=ud(p.abstractMethods,$,Ie.MethodOverwritesOtherExtendedEntitysMethodWithSameImplementation,Ie.MethodOverwritesOtherExtendedEntitysMethodWithSameName);n.push(...j.errors)}i&&J.Logger.log("self.implements.length",o.implements.length),o.implements.length&&o.implements.forEach(b=>{if(b.type===d.BuiltInBaseEntity){const w=s.filter(P=>P.id!==b.id);w.length&&w.forEach(P=>{if(P.id!==b.id){const $=new Bi({id:o.id+"--"+P.id+"--"+b.id+"--"+me.ImplementsIncompatibleEntities,message:`Entity "${o.name}" with id "${o.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:me.ImplementsIncompatibleEntities,entity:o,firstRelationship:P,secondRelationship:b});n.push($)}})}else{Zn(b).forEach(L=>{const j=s.filter(F=>F.id!==L.id);j.length&&j.forEach(F=>{if(F.id!==L.id){const q=new Bi({id:o.id+"--"+F.id+"--"+L.id+"--"+me.ImplementsIncompatibleEntities,message:`Entity "${o.name}" with id "${o.id}" is implementing built-in entity "${F.name}" with id "${F.id}" but also implements entity "${L.name}" with id "${L.id}" which is incompatible`,severity:pe.Error,code:me.ImplementsIncompatibleEntities,entity:o,firstRelationship:F,secondRelationship:L});n.push(q)}})});const P=ud(p.ownDeclaredProperties,b.ownDeclaredProperties,Ie.PropertyOverwritesOtherImplementedEntitysPropertyWithSameImplementation,Ie.PropertyOverwritesOtherImplementedEntitysPropertyWithSameName);n.push(...P.errors);const $=ud(p.abstractMethods,[...b.abstractMethods,...b.methods],Ie.MethodOverwritesOtherImplementedEntitysMethodWithSameImplementation,Ie.MethodOverwritesOtherImplementedEntitysMethodWithSameName);n.push(...$.errors)}});const e=ud(o.ownDeclaredProperties,p.ownDeclaredProperties,Ie.PropertyOverwritesOtherSiblingWithSameImplementation,Ie.PropertyOverwritesOtherSiblingWithSameName);n.push(...e.errors);const y=ud(p.methods,p.abstractMethods,Ie.MethodOverwritesOtherSiblingWithSameImplementation,Ie.MethodOverwritesOtherSiblingWithSameName);return n.push(...y.errors),D(o.extends?Zn(o.extends):[]).forEach(b=>{if(!s.find(w=>w.id===b.id)){const w=new Bi({id:o.id+"--"+p.id+"--"+b.id+"--"+me.ImplementsIncompatibleEntities,message:`Entity "${o.name}" with id "${o.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:me.ImplementsIncompatibleEntities,entity:o,firstRelationship:p,secondRelationship:b});n.push(w)}}),n}function J1i(o){const p=[];if(o.implements.forEach(i=>{if(!i.static){const n=new Bi({id:o.id+"--"+i.id+"--"+me.StaticImplementingNonStaticEntity,message:`Entity "${o.name}" with id "${o.id}" is static but implements entity "${i.name}" with id "${i.id}" which is non-static`,severity:pe.Error,code:me.StaticImplementingNonStaticEntity,entity:o,firstRelationship:i});p.push(n)}}),o.extends&&!o.extends.static){const i=new Bi({id:o.id+"--"+o.extends.id+"--"+me.StaticExtendingNonStaticEntity,message:`Entity "${o.name}" with id "${o.id}" is static but extends entity "${o.extends.name}" with id "${o.extends.id}" which is non-static`,severity:pe.Error,code:me.StaticExtendingNonStaticEntity,entity:o,firstRelationship:o.extends});p.push(i)}return p}function Y1i(o){const p=[];if(o.implements.length){const i=new Bi({id:o.id+"--"+me.AbstractEntityImplements,message:`Entity "${o.name}" with id "${o.id}" cannot be marked as abstract because it implements other entities`,severity:pe.Error,code:me.AbstractEntityImplements,entity:o});p.push(i)}if(o.extends&&!o.extends.abstract){const i=new Bi({id:o.id+"--"+o.extends.id+"--"+me.AbstractExtendingNonAbstractEntity,message:`Entity "${o.name}" with id "${o.id}" is abstract but extends entity "${o.extends.name}" with id "${o.extends.id}" which is non-abstract`,severity:pe.Error,code:me.AbstractExtendingNonAbstractEntity,entity:o,firstRelationship:o.extends});p.push(i)}return p}function X1i(o){const p=[];if(o.extends&&o.extends.static){const i=new Bi({id:o.id+"--"+o.extends.id+"--"+me.NonStaticExtendingStaticEntity,message:`Entity "${o.name}" with id "${o.id}" is non-static but extends entity "${o.extends.name}" with id "${o.extends.id}" which is static`,severity:pe.Error,code:me.NonStaticExtendingStaticEntity,entity:o,firstRelationship:o.extends});p.push(i)}return p}function Q1i(o){const p=[];if(o.extends&&o.extends.abstract){const i=new Bi({id:o.id+"--"+o.extends.id+"--"+me.NonAbstractExtendingAbstractEntity,message:`Entity "${o.name}" with id "${o.id}" is non-abstract but extends entity "${o.extends.name}" with id "${o.extends.id}" which is abstract`,severity:pe.Error,code:me.NonAbstractExtendingAbstractEntity,entity:o,firstRelationship:o.extends});p.push(i)}return p}function ZN(o,p){const n=[...o.project.entities].filter(s=>s.id!==o.id);return Cv(o,[qi,Dc],n,p)}const eRi=Object.freeze(Object.defineProperty({__proto__:null,getBaseMethodsNotImplemented:HBe,getBasePropertiesNotImplemented:ZBe,validate:qBe,validateAsync:SBe,validateCanBecomeAbstract:Y1i,validateCanBecomeNonAbstract:Q1i,validateCanBecomeNonStatic:X1i,validateCanBecomeStatic:J1i,validateCanExtendEntity:z1i,validateCanImplementEntity:W1i,validateDefinitionEntityName:ZN},Symbol.toStringTag,{value:"Module"}));function tRi(o,p){const i=[];if(o.parent)if(o.id===o.parent)i.push(new De({id:`${o.id}--${o.parent}--${ne.SelfReference}`,code:ne.SelfReference,severity:pe.Error,message:`Entity of type "${o.type}" with id "${o.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(o.parent);n?[d.Project,d.DataType].includes(n.type)||i.push(new De({id:`${o.id}--${o.parent}--${ne.InvalidParentReference}`,code:ne.InvalidParentReference,severity:pe.Error,message:`Entity of type "${o.type}" with id "${o.id}", has a parent reference that isn't pointing to an entity of type 'project' or 'data-type'.`})):i.push(new De({id:`${o.id}--${o.parent}--${ne.ReferencedEntityNotFound}`,code:ne.ReferencedEntityNotFound,severity:pe.Error,message:`Entity of type "${o.type}" with id "${o.id}", is referencing an entity with id "${o.parent}" that isn't yet found in the project. Perhaps it should be created first. Or perhaps the ID is incorrect.`}))}return o.implements&&Array.isArray(o.implements)?o.implements.forEach(n=>{if(o.id===n){i.push(new De({id:`${o.id}--${n}--${ne.SelfReference}`,code:ne.SelfReference,severity:pe.Error,message:`Entity of type "${o.type}" with id "${o.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?[d.DefinitionEntity,d.BuiltInBaseEntity].includes(s.type)?s.abstract||i.push(new De({id:`${o.id}--${n}--${ne.InvalidImplementsReference}`,code:ne.InvalidImplementsReference,severity:pe.Error,message:`Entity of type "${o.type}" with id "${o.id}", has an 'implements' reference that isn't pointing to an abstract entity.`})):i.push(new De({id:`${o.id}--${n}--${ne.InvalidImplementsReference}`,code:ne.InvalidImplementsReference,severity:pe.Error,message:`Entity of type "${o.type}" with id "${o.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:`${o.id}--${n}--${ne.ReferencedEntityNotFound}`,code:ne.ReferencedEntityNotFound,severity:pe.Error,message:`Entity of type "${o.type}" with id "${o.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:`${o.id}--${Ie.InvalidObjectStructure}`,code:Ie.InvalidObjectStructure,severity:pe.Error,message:`Entity of type "${o.type}" with id "${o.id}", has an 'implements' property that isn't an array.`})),o.extends&&Array.isArray(o.extends)&&o.extends.forEach(n=>{const s=p.get(n);s?[d.DefinitionEntity,d.BuiltInBaseEntity].includes(s.type)?s.abstract&&i.push(new De({id:`${o.id}--${n}--${ne.InvalidExtendsReference}`,code:ne.InvalidExtendsReference,severity:pe.Error,message:`Entity of type "${o.type}" with id "${o.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:`${o.id}--${n}--${ne.InvalidExtendsReference}`,code:ne.InvalidExtendsReference,severity:pe.Error,message:`Entity of type "${o.type}" with id "${o.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:`${o.id}--${n}--${ne.ReferencedEntityNotFound}`,code:ne.ReferencedEntityNotFound,severity:pe.Error,message:`Entity of type "${o.type}" with id "${o.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 bA=(o=>(o.Extends="extends",o.Implements="implements",o))(bA||{});const gi=class gi extends Ur{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",d.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:d.DefinitionEntity,additionalProperties:!1,additionalPropertiesDataType:null,allPropertiesImplement:null,name:"",codeName:null,description:"",static:!1,abstract:!1,properties:[],methods:[],abstractMethods:[],extends:null,implements:[],x:0,y:0,parent:null}}static fromGenerationTarget(i,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:d.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=he(y,n);return m.setParent(s,null),m}static validateGenerationTarget(i,n){let s=JSON.parse(JSON.stringify(i));const c=[],e=tRi(s,n),y=gV(s,n);c.push(...e,...y,...xr(s));const m=s.parent?n.get(s.parent):null;if(m&&m.type===d.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.
|
|
384
384
|
You can inspect the existing 'entity' field with the 'describe_entity' action. Like so:
|
|
385
385
|
${Io({describe_entity:v.entity.id})}
|
|
386
|
-
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)===d.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===d.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 j;return!!L.implements.find(F=>F.id===P.id)||((j=L.extends)==null?void 0:j.id)===P.id}))},[]);return D([...n,...s])}get allBaseMethodsFromExtendedAndImplementedEntities(){return D([...(this.extends?[this.extends]:[]).reduce((i,n)=>n.type!==d.DefinitionEntity?[]:[...[...n.ownDeclaredMethods,...n.allBaseMethodsFromExtendedAndImplementedEntities].filter(c=>c.type!==d.ActionDescriptor),...i],[]),...this.implements.reduce((i,n)=>n.type!==d.DefinitionEntity?n.abstractMethods:[...[...n.ownDeclaredMethods,...n.allBaseMethodsFromExtendedAndImplementedEntities].filter(c=>c.type!==d.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!==d.DefinitionEntity)return[];const s=[...n.ownDeclaredMethods,...n.extendedMethodsFromOriginalParents].filter(c=>c.type!==d.ActionDescriptor);return[...i,...s]},[]))}get implementedMethodsFromOriginalParents(){return D([...(this.extends?[this.extends]:[]).reduce((i,n)=>{const s=n.type===d.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===d.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 Z(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 gi(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 gi(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 Z(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(`${Sr(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!==d.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!==d.BuiltInBaseEntity&&i.push(m);else throw new Error(`${Sr(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 Z(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:j,removed:F}=this.removeUnrecognizedProperties(i);n.push(...L),s.push(...j),c.push(...F);const{updated:q,added:X,removed:ae,affected:ee}=this.syncImplementationMethods(i);n.push(...q),s.push(...X),c.push(...ae),e.push(...ee);const{updated:fe,added:oe,removed:ce,affected:Te}=this.addExtendedMethods(i);n.push(...fe),s.push(...oe),c.push(...ce),e.push(...Te);const{updated:de,added:ye,removed:_e}=this.removeUnrecognizedMethods(i);return n.push(...de),s.push(...ye),c.push(..._e),this.addSuggestions(),this.properties.sort((Pe,Ge)=>Pe.index-Ge.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 Z(this.project,x.sessionAuthor,M().toISOString(),this,!0,"add-self-to-project"))){const n=[this],s=[],c=[],e=[];if(this.parent.type===d.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 Z(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,H.Updated))),n==null||n.attemptAutoclose(_.SetParent,this.id),this):this}setExtension(i,n=this.project.addChangeSet(new Z(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,H.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 Z(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,H.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 Z(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,H.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 Z(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,H.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 Z(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,H.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 Z(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,H.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 Z(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,H.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 Z(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,H.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 Z(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,H.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 Z(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=he(n,this.project);return s.setParent(this,null),s.initChildren(i),s}),this.methods=this.initialData.methods.map(n=>{const s=he(n,this.project);return s.setParent(this,null),s.initChildren(i),s}),this.abstractMethods=this.initialData.abstractMethods.map(n=>{const s=he(n,this.project);return s.setParent(this,null),s.initChildren(i),s}),this.initialData.extends&&(this.extends=he(this.initialData.extends,this.project)),this.implements=this.initialData.implements.map(n=>he(n,this.project)),this.initialData.allPropertiesImplement){const n=he(this.initialData.allPropertiesImplement,this.project);n.setParent(this,null),n.initChildren(null),this.setAllPropertiesImplement(n,i)}if(this.initialData.additionalPropertiesDataType){const n=he(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 Z(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 Z(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 Z(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 j;return((j=L.implements)==null?void 0:j.id)===b.id}))return;const P=this.methods.find(L=>{var ae,ee;if(L.name===b.name&&!L.implements)return!0;const j=Zi(this,Re.CRON_JOB),F=Zi(this,Re.HTTP_ENDPOINT),q=((ae=L.implements)==null?void 0:ae.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!!(j&&!X&&!F&&q||F&&!q&&!j&&X)});if(P&&P.type===d.FunctionDeclaration){P.setImplements(b,i),P.metaSync({name:b.name},i),i==null||i.add(P,H.Updated),i==null||i.add(this,H.Updated);return}const $=b.implementAsFunctionDeclaration(i,this);s.push($),i==null||i.add($,H.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 Z(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(j=>j.id===E.id));if(b){const{updated:L,added:j,removed:F,affected:q}=b.syncWithImplementation(i);n.push(...L),s.push(...j),c.push(...F),e.push(...q);return}if(this.properties.find(L=>!!L.implements.find(j=>j.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($,H.Added)}),this.properties.find(E=>{var b;return E.id===((b=this.allPropertiesImplement)==null?void 0:b.id)})&&this.removeAllPropertiesImplement(i),i==null||i.attemptAutoclose("sync-implementation-properties",this.id),{updated:D(n),added:D(s),removed:D(c),affected:D(e),self:this}}addExtendedMethods(i=this.project.addChangeSet(new Z(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===d.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,H.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 Z(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,H.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=>{ZBe(this,i).forEach(c=>{const e=c.toJSON();e.id=`_suggestion--parent--${this.id}--${c.id}`;const y=he(e,this.project);y.suggestion=!0,y.setParent(this,null),y.initChildren(null),this.addSuggestedProperty(y)}),HBe(this,i).forEach(c=>{const e=`_suggestion--parent--${this.id}--${c.id}`,y=c.implementAsFunctionDeclaration(null,this,e),m=he(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 Z(this.project,x.sessionAuthor,M().toISOString(),this,!0,"meta-sync"))){const s=Lr(this,i,n),c=$r(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,H.Removed):s.deleted===!1&&e.deleted?n==null||n.add(this,H.Added):c&&(n==null||n.add(this,H.Updated)),n==null||n.attemptAutoclose("meta-sync",this.id),this}async APILoad(i=ke,...n){return await gi.repository.APILoad(this.id,...n),this}async APICreate(i=ke,...n){return await gi.repository.APICreate(this.toShallowJSON(),...n),this}async APIUpdate(i=ke,...n){return await gi.repository.APIUpdate(this.toShallowJSON(),...n),this}async APIDelete(i=ke,...n){return await gi.repository.APIDelete(this.toShallowJSON(),...n),this}async APIClone(i=ke,...n){return await gi.repository.APIClone(this.id,...n),this}async APILoadVersion(i=ke,n,...s){return await gi.repository.APILoadVersion(this.id,n,...s)}removeFromParent(i=this.project.addChangeSet(new Z(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===d.Project)this.parent.removeDefinitionEntity(this);else if(this.parent.type===d.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 Z(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:rr.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 Z(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=ct){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===d.BuiltInBaseEntity?$.toJSON(i.seenEntities):$.toJSONClone({...i,newId:null})),extends:((b=this.extends)==null?void 0:b.type)===d.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=ct){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:d.GenericReference,entityId:n,version:this.version,entityType:this.type}}toShallowJSON(i=ct){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===d.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===d.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=qBe(this),{success:!0}}async validateAsync(i={}){const n=J.YieldTracker.from(i);return this.errors=await SBe(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 Z(this.project,x.sessionAuthor,M().toISOString(),this,!0,_.CloneEntity)),n=null,s=null,c=!0){var j,F,q;const e=Vr(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=Ki(y,e);w.hydrateAncestors(),w.setParent(v,i),c&&(w.subscribe(),w.addSelfToProject(i)),w.initChildren(i),i==null||i.add(w,H.Added);const P=(j=this.properties)==null?void 0:j.map(X=>this.project.diggestedBuiltInBaseEntitiesIds.has(X.id)?e.getBuiltIn(X.id):X.clone(i,w,x.UUID.uuid(),c));w.properties=P;const $=(F=this.methods)==null?void 0:F.map((X,ae)=>this.project.diggestedBuiltInBaseEntitiesIds.has(X.id)?e.getBuiltIn(X.id):X.clone(i,w,b+"-method-"+ae+"-id",c));w.methods=$;const L=(q=this.abstractMethods)==null?void 0:q.map((X,ae)=>this.project.diggestedBuiltInBaseEntitiesIds.has(X.id)?e.getBuiltIn(X.id):X.clone(i,w,b+"-abstract-method-"+ae+"-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 Z(this.project,x.sessionAuthor,M().toISOString(),this,!0,"implement-definition-entity")),s){const c=kI(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===d.DefinitionEntity||y.type===d.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 Z(this.project,x.sessionAuthor,M().toISOString(),this,!0,"infer-definition-entity-from-inputs"))){const s=[],c=[],e=[],y=[];if(this.parent.type!==d.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=>se(P,this.project)===se(b,this.project))||m.push(b)});const v=this.properties.filter(b=>!b.dataType);m.forEach(b=>{var q,X,ae;const w=v.find(ee=>se(ee,this.project)===se(b,this.project));if(!w)return;const $=Wn(b.parent).getMasterInputWithValueWritterFromAllInstances(b),L=hd($,n),j=L==null?void 0:L.clone(n,w,x.UUID.uuid(),!0);j&&((q=w.dataType)==null||q.merge(j,n),j.id!==((X=w.dataType)==null?void 0:X.id)&&j.remove({ignoreUpstream:!1},n),w.dataType&&(w.dataType.metaSync({inferred:!0,like:!0},n),w.setDataType(w.dataType,n),n==null||n.add(w,H.Affected)));let F=null;if(b.declaration&&w.id!==((ae=b.declaration)==null?void 0:ae.id)&&(F=b.declaration),b.setDeclaration(w,n),n==null||n.add(b,H.Updated),F){const{updated:ee,removed:fe}=F.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 ae,ee,fe,oe;const w=this.properties.find(ce=>se(ce,this.project)===se(b,this.project));if(w){if(b.setDeclaration(w,n),!w.getDataType(n)){const Te=Wn(b.parent).getMasterInputWithValueWritterFromAllInstances(b),de=hd(Te),ye=de==null?void 0:de.clone(n,w,x.UUID.uuid(),!0);ye&&((ae=w.dataType)==null||ae.merge(ye,n),ye.id!==((ee=w.dataType)==null?void 0:ee.id)&&ye.remove({ignoreUpstream:!1},n),w.dataType&&(w.dataType.metaSync({inferred:!0,like:!0},n),w.setDataType(w.dataType,n),n==null||n.add(w,H.Affected)))}return}const P=se(b,this.project),$=b.codeName||Ac(b,this.project)||wo(qi(P)),L=ja.new(n);L.parent=this.toReference(),L.index=b.index,L.name=P,L.codeName=$,L.description=b.description;const j=he(L,this.project);j.hydrateAncestors(),n==null||n.add(j,H.Added),j.setParent(this,n),j.initChildren(n);const q=Wn(b.parent).getMasterInputWithValueWritterFromAllInstances(b),X=hd(q);if(X)if(this.project.diggestedBuiltInBaseEntitiesIds.has(X.id))j.setDataType(X,n),n==null||n.add(j,H.Affected);else{const ce=X==null?void 0:X.clone(n,j,x.UUID.uuid(),!0);ce&&((fe=j.dataType)==null||fe.merge(ce,n),ce.id!==((oe=j.dataType)==null?void 0:oe.id)&&ce.remove({ignoreUpstream:!1},n),j.dataType&&(j.dataType.metaSync({inferred:!0,like:!0},n),j.setDataType(j.dataType,n),n==null||n.add(j,H.Affected)))}return this.addProperty(j,n),b.setDeclaration(j,n),n==null||n.add(b,H.Updated),j}),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 e;if(!_A(n))return;const s=se(n,this.project),c=n.codeName||Ac(n,this.project)||wo(qi(s));i[c]=((e=n.getDefaultValue())==null?void 0:e.value)||null}),i}getActiveRawDefaultValue(){const i={};return this.properties.forEach(n=>{var y;if(!_A(n))return;const s=se(n,this.project),c=n.codeName||Ac(n,this.project)||wo(qi(s)),e=(y=this.project.requestActiveDynamicValue(n,!0))==null?void 0:y.value;i[c]=(e==null?void 0:e.value)||null}),i}setAdditionalPropertiesDataType(i,n=this.project.addChangeSet(new Z(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,H.Affected)),n==null||n.attemptAutoclose(_.SetAdditionalPropertiesDataType,this.id),this}removeAdditionalPropertiesDataType(i=this.project.addChangeSet(new Z(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,H.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 Z(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,H.Affected)),n==null||n.attemptAutoclose(_.SetAllPropertiesImplement,this.id),this}removeAllPropertiesImplement(i=this.project.addChangeSet(new Z(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,H.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(gi,"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(gi,"type",d.DefinitionEntity),I(gi,"USER_MANAGED_PARENT_TYPES",[d.Project,d.DataType]),I(gi,"PARENT_TYPES",[...gi.USER_MANAGED_PARENT_TYPES]),I(gi,"MUTABLE_BASE_PROPERTIES",["name","codeName","description","static","abstract","additionalProperties"]),I(gi,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),I(gi,"BASE_PROPERTIES",[...gi.MUTABLE_BASE_PROPERTIES,...gi.INMUTABLE_BASE_PROPERTIES]),I(gi,"MUTABLE_META_PROPERTIES",[...gi.MUTABLE_BASE_PROPERTIES,"x","y"]),I(gi,"INMUTABLE_META_PROPERTIES",[...gi.INMUTABLE_BASE_PROPERTIES]),I(gi,"META_PROPERTIES",[...gi.MUTABLE_META_PROPERTIES,...gi.INMUTABLE_META_PROPERTIES]),I(gi,"MUTABLE_UPSTREAM_PROPERTIES",["extends","implements"]),I(gi,"INMUTABLE_UPSTREAM_PROPERTIES",["parent"]),I(gi,"UPSTREAM_PROPERTIES",[...gi.MUTABLE_UPSTREAM_PROPERTIES,...gi.INMUTABLE_UPSTREAM_PROPERTIES]),I(gi,"MUTABLE_DOWNSTREAM_PROPERTIES",["properties","methods","abstractMethods","allPropertiesImplement","additionalPropertiesDataType"]),I(gi,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),I(gi,"DOWNSTREAM_PROPERTIES",[...gi.MUTABLE_DOWNSTREAM_PROPERTIES,...gi.INMUTABLE_DOWNSTREAM_PROPERTIES]),I(gi,"PROPERTIES",[...gi.META_PROPERTIES,...gi.UPSTREAM_PROPERTIES,...gi.DOWNSTREAM_PROPERTIES]);let us=gi;async function iRi(o,p={}){const i=J.YieldTracker.from(p),n=[],s=Mt(o.errors,n);return await i.tick(),s}function rRi(o){const p=[];return Mt(o.errors,p)}const xA=class xA extends _V{constructor(i,n){super(i);I(this,"initialData");I(this,"id");I(this,"name");I(this,"description",null);I(this,"type",d.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=he(s,this.project);return c.setParent(this,null),c.initChildren(null),c}),this.methods=this.initialData.methods.map(s=>{const c=he(s,this.project);return c.parent=this,c}),this.abstractMethods=this.initialData.abstractMethods.map(s=>{const c=he(s,this.project);return c.parent=this,c}),this.initialData.extends&&(this.extends=he(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=ke,...n){return await xA.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=ct){return{id:this.id+"--"+x.UUID.uuid()+"--ref",type:d.GenericReference,entityId:this.id,version:this.version,entityType:this.type}}toShallowJSON(i=ct){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=rRi(this),{success:!0}}async validateAsync(i={}){const n=J.YieldTracker.from(i);return this.errors=await iRi(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===d.BuiltInBaseEntity&&this.extends.interactive||this.extends.type===d.PrimitiveEntity?i:(this.extends instanceof No&&i.push(...this.extends.getAllInteractiveMethods()),D(i))}};I(xA,"repository",{APILoad:async(i,...n)=>null});let ma=xA;function Ki(o,p){if(!o)throw new Error("Entity is null");const i=p.get(o.id);switch(o.type){case d.LiteralValue:return i||new Xr(o,p);case d.DefinitionEntity:return i||new us(o,p);case d.PrimitiveEntity:return i||new ma(o,p);case d.FunctionDeclaration:return i||new Vo(o,p);case d.GlobalEvent:return i||new Vu(o,p);case d.DataType:return i||new ir(o,p);case d.Property:return i||new ja(o,p);case d.FunctionCall:return i||new _u(o,p);case d.Condition:return i||new xu(o,p);case d.Operation:return i||new Pu(o,p);case d.VariableDeclaration:return i||new Mu(o,p);case d.VariableInstance:return i||new Lu(o,p);case d.OutputMap:return i||new Il(o,p);case d.ArgumentDeclaration:return i||new Ea(o,p);case d.InputMap:return i||new ds(o,p);case d.Project:return i||new x(o);case d.InstalledProject:return i||new Gu(o,p);case d.ActionDescriptor:return i||new Li(o,p);case d.ReturnStatement:return i||new Ed(o,p);case d.Loop:return i||new Nu(o,p);case d.Search:return i||new Bu(o,p);case d.ValueDescriptor:return i||new Ad(o,p);case d.BuiltInBaseEntity:return i||new No(o,p);case d.InternalCall:return i||new ku(o,p);case d.ContinueStatement:return i||new Uu(o,p);case d.BreakStatement:return i||new ju(o,p);case d.GenericReference:return p.get(o.entityId);default:throw new Error("Invalid entity type: "+o.type)}}function he(o,p){if(!o)throw new Error("Entity is null");const i=Ki(o,p);return i.subscribe(),i}function nRi(o,p){if(!o)throw new Error("Entity is null");switch(o.type){case d.LiteralValue:return Xr.fromGenerationTarget(o,p);case d.DefinitionEntity:return us.fromGenerationTarget(o,p);case d.FunctionDeclaration:return Vo.fromGenerationTarget(o,p);case d.GlobalEvent:return Vu.fromGenerationTarget(o,p);case d.DataType:return ir.fromGenerationTarget(o,p);case d.Property:return ja.fromGenerationTarget(o,p);case d.FunctionCall:return _u.fromGenerationTarget(o,p);case d.Condition:return xu.fromGenerationTarget(o,p);case d.Operation:return Pu.fromGenerationTarget(o,p);case d.VariableDeclaration:return Mu.fromGenerationTarget(o,p);case d.VariableInstance:return Lu.fromGenerationTarget(o,p);case d.OutputMap:return Il.fromGenerationTarget(o,p);case d.ArgumentDeclaration:return Ea.fromGenerationTarget(o,p);case d.InputMap:return ds.fromGenerationTarget(o,p);case d.InstalledProject:return Gu.fromGenerationTarget(o,p);case d.ReturnStatement:return Ed.fromGenerationTarget(o,p);case d.Loop:return Nu.fromGenerationTarget(o,p);case d.Search:return Bu.fromGenerationTarget(o,p);case d.ActionDescriptor:return Li.fromGenerationTarget(o,p);case d.ValueDescriptor:return Ad.fromGenerationTarget(o,p);case d.InternalCall:return ku.fromGenerationTarget(o,p);case d.ContinueStatement:return Uu.fromGenerationTarget(o,p);case d.BreakStatement:return ju.fromGenerationTarget(o,p);default:throw new Error("Invalid entity type: "+o.type)}}const ct={seenEntityMaps:new Map,seenEntities:new Set,timestamp:M().toISOString()};class XBe{constructor(){I(this,"initialData")}}const ke={cascade:!1},QBe={APILoad:async(o,...p)=>null},aRi={APICreate:async(o,...p)=>o,APIUpdate:async(o,...p)=>o,APIDelete:async(o,...p)=>o,APIClone:async(o,...p)=>{},APILoadVersion:async(o,p,...i)=>null,...QBe};class sRi{}class eGe extends XBe{}class lRi extends eGe{}class oRi{}class dRi{}class uRi{}class HN{}class pRi extends HN{}class cRi extends HN{}class fRi{}class af{static initReadsValue(p){if(p.initialData.readsValue&&p.initialData.readsValue.type!==d.GenericReference)p.readsValue=he(p.initialData.readsValue,p.project);else if(p.initialData.readsValue&&p.initialData.readsValue.type===d.GenericReference){const i=qn(p.initialData.readsValue,p.project);i&&(p.readsValue=i)}if(p.readsValue){if(qt.includes(p.readsValue.type)){let i=p.parent;!nr.includes(i.type)&&i.type!==d.Project&&(i=i.parent);const n=p.type===d.InputMap&&p.parent.type===d.Loop;n&&(i=p.parent.parent),p.readsValue.setParent(i,null),p.readsValue.initChildren(null),i&&i.type!==d.Project&&!n&&i.detachedChildren.includes(p)?i.replaceDetachedChild(p,p.readsValue):i&&i.type!==d.Project&&!n&&i.subscribeDetachedChild(p.readsValue)}p.readsValue.addValueReader(p,null)}return p.readsValue}}class _v{static initWritesValues(p,i){const n=p.initialData.writesValues.reduce((c,e)=>{if(e.type===d.GenericReference||p.writesValues.some(m=>m.id===e.id))return c;const y=he(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 yRi{}var zt=(o=>(o.PROJECT_INITIALIZED="project-initialized",o.BEFORE_CHANGE_SET_CLOSE_BEFORE_SIDE_EFFECTS="before-change-set-close-before-side-effects",o.BEFORE_CHANGE_SET_CLOSE_AFTER_SIDE_EFFECTS="before-change-set-close-after-side-effects",o.CHANGE_SET_CLOSED_BEFORE_PERSIST="change-set-closed-before-persist",o.CHANGE_SET_PERSISTED="change-set-persisted",o.BEFORE_CHANGE_SET_PERSIST="before-change-set-persist",o.EXPLICIT_DEFINITION_ENTITY_ADDED="explicit-definition-entity-added",o.EXPLICIT_DEFINITION_ENTITY_REMOVED="explicit-definition-entity-removed",o.EXPLICIT_DEFINITION_ENTITY_UPDATED="explicit-definition-entity-updated",o.PERSISTED_DEFINITION_ENTITY_ADDED="persisted-definition-entity-added",o.PERSISTED_DEFINITION_ENTITY_REMOVED="persisted-definition-entity-removed",o.PERSISTED_DEFINITION_ENTITY_UPDATED="persisted-definition-entity-updated",o.RELATIONAL_DATABASE_DEFINITION_ENTITY_ADDED="relational-database-definition-entity-added",o.RELATIONAL_DATABASE_DEFINITION_ENTITY_REMOVED="relational-database-definition-entity-removed",o.RELATIONAL_DATABASE_DEFINITION_ENTITY_UPDATED="relational-database-definition-entity-updated",o))(zt||{});const WN={...sN,events:new J.Events("def-proj-static-p-ctx-events")},tGe={requestActiveDynamicValue:(o,p=!1)=>null,...WN},Pt=class Pt extends Ur{constructor(i,n={...tGe,events:new J.Events("def-proj-inst-p-ctx-events")}){super(i);I(this,"initialData");I(this,"id");I(this,"type",d.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,!Pt.UUID)throw new Error("UUID module is already initialized. Please inject a valid UUID module.")}static get UUID(){var i;return(i=this.parentContext.requestExtension("uuid"))==null?void 0:i.module}static new(i=null){return{id:Pt.UUID.uuid(),version:Pt.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||M().toISOString(),author:(i==null?void 0:i.author)||Pt.sessionAuthor,previousVersion:null,deleted:!1,deletable:!0,editable:!0,type:d.Project,name:"",description:"",entities:[],functions:[],events:[],projects:[],variableDeclarations:[],variableInstances:[],conditions:[],operations:[],functionCalls:[],loops:[],searches:[]}}static validateGenerationTarget(i,n){let s=JSON.parse(JSON.stringify(i));const c=[];return c.push(...xr(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 Z(this,i,n,s,c,e);const y=this.history[this.history.length-1];return y.open?y:this.addChangeSet(new Z(this,i,n,s,c,e))}addChangeSet(i){var s,c;if(!this.history.length)return this.undoableStackValueIndex=jO(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} ${se(e.self,this)}`:""}.`)}return this.undoableStackValueIndex=jO(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 Z(this.project,Pt.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=Pt.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 Pt(this);return i.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,i):new Map([[this.version,i]]),i.entities=[...this.entities],i.projects=[...this.projects],i.functions=[...this.functions],i.events=[...this.events],i.variableDeclarations=[...this.variableDeclarations],i.variableInstances=[...this.variableInstances],i.conditions=[...this.conditions],i.operations=[...this.operations],i.functionCalls=[...this.functionCalls],i.loops=[...this.loops],i.searches=[...this.searches],this}recursiveCaptureUpstreamVersions(i){const 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 Pt(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 Z(this.project,Pt.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 Z(this.project,Pt.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=he(n,this);return s.setParent(this,null),s.initChildren(i),s}),this.projects=this.initialData.projects.map(n=>{const s=he(n,this);return s.setParent(this,null),s.initChildren(i),s}),this.variableDeclarations=this.initialData.variableDeclarations.map(n=>{const s=he(n,this);return s.setParent(this,null),s.initChildren(i),s}),this.variableInstances=this.initialData.variableInstances.map(n=>{const s=he(n,this);return s.setParent(this,null),s.initChildren(i),s}),this.conditions=this.initialData.conditions.map(n=>{const s=he(n,this);return s.setParent(this,null),s.initChildren(i),s}),this.operations=this.initialData.operations.map(n=>{const s=he(n,this);return s.setParent(this,null),s.initChildren(i),s}),this.functions=this.initialData.functions.map(n=>{const s=he(n,this);return s.setParent(this,null),s.initChildren(i),s}),this.events=this.initialData.events.map(n=>{const s=he(n,this);return s.setParent(this,null),s.initChildren(i),s}),this.functionCalls=this.initialData.functionCalls.map(n=>{const s=he(n,this);return s.setParent(this,null),s.initChildren(i),s}),this.loops=this.initialData.loops.map(n=>{const s=he(n,this);return s.setParent(this,null),s.initChildren(i),s}),this.searches=this.initialData.searches.map(n=>{const s=he(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){if(i.id==="3bdd91d6-fa96-403f-af98-532a1110b28a")throw console.log("[ProjectState.subscribeDeletedInstance] Debug"),new Error("[ProjectState.subscribeDeletedInstance] Debug");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){if(i.id==="3bdd91d6-fa96-403f-af98-532a1110b28a")throw console.log("[ProjectState.unsubscribeInstance] debug"),new Error("[ProjectState.unsubscribeInstance] debug");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 Z(this.project,Pt.sessionAuthor,M().toISOString(),this,!0,"meta-sync"))){const s=Lr(this,i,n),c=$r(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,H.Removed):s.deleted===!1&&e.deleted?n==null||n.add(this,H.Added):c&&(n==null||n.add(this,H.Updated)),n==null||n.attemptAutoclose("meta-sync",this.id),this}async APILoad(i=ke,...n){return await Pt.repository.APILoad(this.id,...n),this}async APICreate(i=ke,...n){return await Pt.repository.APICreate(this.toShallowJSON(),...n),this}async APIUpdate(i=ke,...n){return await Pt.repository.APIUpdate(this.toShallowJSON(),...n),this}async APIDelete(i=ke,...n){return await Pt.repository.APIDelete(this.toShallowJSON(),...n),this}async APIClone(i=ke,...n){return await Pt.repository.APIClone(this.id,...n),this}async APILoadVersion(i=ke,n,...s){return await Pt.repository.APILoadVersion(this.id,n,...s)}remove({ignoreUpstream:i}={ignoreUpstream:!1},n=this.project.addChangeSet(new Z(this.project,Pt.sessionAuthor,M().toISOString(),this,!0,_.RemoveEntity))){return{added:[],updated:[],removed:[],affected:[],self:this}}restore({}={},i=this.project.addChangeSet(new Z(this.project,Pt.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,Pt.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=ct){var s;let n=this.id;return(s=i.seenEntityMaps)!=null&&s.has(this.id)&&(n=i.seenEntityMaps.get(this.id)),{id:n+"--"+Pt.UUID.uuid()+"--ref",type:d.GenericReference,entityId:n,version:this.version,entityType:this.type}}toShallowJSON(i=ct){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(),ev([...this.errors]),{success:!0}}async validateAsync(i={}){const n=J.YieldTracker.from(i);return await this.validateChildrenAsync({tracker:n}),await gwe([...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!==d.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=wt(s);return[...n,...c.filter(e=>e.type===d.ReturnStatement||e.type===d.ContinueStatement||e.type===d.BreakStatement)]},[])]}getFunctionDeclaration(i){return this.functions.find(n=>n.id===i)||null}getConditions(){return[...this.conditions,...this.getEntryPoints().reduce((n,s)=>{const c=wt(s);return[...n,...c.filter(e=>e.type===d.Condition)]},[]),...this.functionCalls.reduce((n,s)=>{const c=wt(s);return[...n,...c.filter(e=>e.type===d.Condition)]},[]),...this.operations.reduce((n,s)=>{const c=wt(s);return[...n,...c.filter(e=>e.type===d.Condition)]},[]),...this.loops.reduce((n,s)=>{const c=wt(s);return[...n,...c.filter(e=>e.type===d.Condition)]},[]),...this.searches.reduce((n,s)=>{const c=wt(s);return[...n,...c.filter(e=>e.type===d.Condition)]},[])]}getOperations(){return[...this.operations,...this.getEntryPoints().reduce((n,s)=>{const c=wt(s);return[...n,...c.filter(e=>e.type===d.Operation)]},[]),...this.functionCalls.reduce((n,s)=>{const c=wt(s);return[...n,...c.filter(e=>e.type===d.Operation)]},[]),...this.conditions.reduce((n,s)=>{const c=wt(s);return[...n,...c.filter(e=>e.type===d.Operation)]},[]),...this.loops.reduce((n,s)=>{const c=wt(s);return[...n,...c.filter(e=>e.type===d.Operation)]},[]),...this.searches.reduce((n,s)=>{const c=wt(s);return[...n,...c.filter(e=>e.type===d.Operation)]},[])]}getFunctionCalls(){return[...this.functionCalls,...this.getEntryPoints().reduce((n,s)=>{const c=wt(s);return[...n,...c.filter(e=>e.type===d.FunctionCall)]},[]),...this.conditions.reduce((n,s)=>{const c=wt(s);return[...n,...c.filter(e=>e.type===d.FunctionCall)]},[]),...this.operations.reduce((n,s)=>{const c=wt(s);return[...n,...c.filter(e=>e.type===d.FunctionCall)]},[]),...this.loops.reduce((n,s)=>{const c=wt(s);return[...n,...c.filter(e=>e.type===d.FunctionCall)]},[]),...this.searches.reduce((n,s)=>{const c=wt(s);return[...n,...c.filter(e=>e.type===d.FunctionCall)]},[])]}getVariables(){return[...this.variableDeclarations,...this.getEntryPoints().reduce((n,s)=>{const c=Ji(s);return[...n,...c]},[]),...this.functionCalls.reduce((n,s)=>{const c=Ji(s);return[...n,...c]},[]),...this.conditions.reduce((n,s)=>{const c=Ji(s);return[...n,...c]},[]),...this.operations.reduce((n,s)=>{const c=Ji(s);return[...n,...c]},[]),...this.loops.reduce((n,s)=>{const c=Ji(s);return[...n,...c]},[]),...this.searches.reduce((n,s)=>{const c=Ji(s);return[...n,...c]},[])]}getVariableInstances(){return[...this.variableInstances,...this.entities.reduce((n,s)=>[...n,...s.methods.flatMap(c=>{const y=wt(c).filter(m=>m.type===d.VariableInstance);return[...n,...y]})],[]),...this.getEntryPoints().reduce((n,s)=>{const e=Ji(s).filter(y=>y.type===d.VariableInstance);return[...n,...e]},[]),...this.functionCalls.reduce((n,s)=>{const e=Ji(s).filter(y=>y.type===d.VariableInstance);return[...n,...e]},[]),...this.conditions.reduce((n,s)=>{const e=Ji(s).filter(y=>y.type===d.VariableInstance);return[...n,...e]},[]),...this.operations.reduce((n,s)=>{const e=Ji(s).filter(y=>y.type===d.VariableInstance);return[...n,...e]},[]),...this.loops.reduce((n,s)=>{const e=Ji(s).filter(y=>y.type===d.VariableInstance);return[...n,...e]},[]),...this.searches.reduce((n,s)=>{const e=Ji(s).filter(y=>y.type===d.VariableInstance);return[...n,...e]},[])]}getVariableDeclarations(){return D([...this.variableDeclarations,...this.entities.reduce((n,s)=>[...n,...s.methods.flatMap(c=>{const y=wt(c).filter(m=>m.type===d.VariableDeclaration);return[...n,...y]})],[]),...this.getEntryPoints().reduce((n,s)=>{const e=Ji(s).filter(y=>y.type===d.VariableDeclaration);return[...n,...e]},[]),...this.functionCalls.reduce((n,s)=>{const e=Ji(s).filter(y=>y.type===d.VariableDeclaration);return[...n,...e]},[]),...this.conditions.reduce((n,s)=>{const e=Ji(s).filter(y=>y.type===d.VariableDeclaration);return[...n,...e]},[]),...this.operations.reduce((n,s)=>{const e=Ji(s).filter(y=>y.type===d.VariableDeclaration);return[...n,...e]},[]),...this.loops.reduce((n,s)=>{const e=Ji(s).filter(y=>y.type===d.VariableDeclaration);return[...n,...e]},[]),...this.searches.reduce((n,s)=>{const e=Ji(s).filter(y=>y.type===d.VariableDeclaration);return[...n,...e]},[])])}getLoops(){return[...this.loops,...this.getEntryPoints().reduce((n,s)=>{const c=wt(s);return[...n,...c.filter(e=>e.type===d.Loop)]},[]),...this.functionCalls.reduce((n,s)=>{const c=wt(s);return[...n,...c.filter(e=>e.type===d.Loop)]},[]),...this.conditions.reduce((n,s)=>{const c=wt(s);return[...n,...c.filter(e=>e.type===d.Loop)]},[]),...this.operations.reduce((n,s)=>{const c=wt(s);return[...n,...c.filter(e=>e.type===d.Loop)]},[]),...this.searches.reduce((n,s)=>{const c=wt(s);return[...n,...c.filter(e=>e.type===d.Loop)]},[])]}getSearches(){return[...this.searches,...this.getEntryPoints().reduce((n,s)=>{const c=wt(s);return[...n,...c.filter(e=>e.type===d.Search)]},[]),...this.functionCalls.reduce((n,s)=>{const c=wt(s);return[...n,...c.filter(e=>e.type===d.Search)]},[]),...this.conditions.reduce((n,s)=>{const c=wt(s);return[...n,...c.filter(e=>e.type===d.Search)]},[]),...this.operations.reduce((n,s)=>{const c=wt(s);return[...n,...c.filter(e=>e.type===d.Search)]},[]),...this.loops.reduce((n,s)=>{const c=wt(s);return[...n,...c.filter(e=>e.type===d.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&&LA.includes(i.type)){const y=i.getDefaultValue();return y?{value:y,type:Ve.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()),GO(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()),GO(i||"initial",n||"initial",this)}applyExternalChangeSet(i){const n=i.payload,s=this.addChangeSet(new Z(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(`,
|
|
386
|
+
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)===d.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===d.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 j;return!!L.implements.find(F=>F.id===P.id)||((j=L.extends)==null?void 0:j.id)===P.id}))},[]);return D([...n,...s])}get allBaseMethodsFromExtendedAndImplementedEntities(){return D([...(this.extends?[this.extends]:[]).reduce((i,n)=>n.type!==d.DefinitionEntity?[]:[...[...n.ownDeclaredMethods,...n.allBaseMethodsFromExtendedAndImplementedEntities].filter(c=>c.type!==d.ActionDescriptor),...i],[]),...this.implements.reduce((i,n)=>n.type!==d.DefinitionEntity?n.abstractMethods:[...[...n.ownDeclaredMethods,...n.allBaseMethodsFromExtendedAndImplementedEntities].filter(c=>c.type!==d.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!==d.DefinitionEntity)return[];const s=[...n.ownDeclaredMethods,...n.extendedMethodsFromOriginalParents].filter(c=>c.type!==d.ActionDescriptor);return[...i,...s]},[]))}get implementedMethodsFromOriginalParents(){return D([...(this.extends?[this.extends]:[]).reduce((i,n)=>{const s=n.type===d.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===d.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 Z(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 gi(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 gi(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 Z(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(`${Sr(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!==d.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!==d.BuiltInBaseEntity&&i.push(m);else throw new Error(`${Sr(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 Z(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:j,removed:F}=this.removeUnrecognizedProperties(i);n.push(...L),s.push(...j),c.push(...F);const{updated:q,added:X,removed:ae,affected:ee}=this.syncImplementationMethods(i);n.push(...q),s.push(...X),c.push(...ae),e.push(...ee);const{updated:fe,added:oe,removed:ce,affected:Te}=this.addExtendedMethods(i);n.push(...fe),s.push(...oe),c.push(...ce),e.push(...Te);const{updated:de,added:ye,removed:_e}=this.removeUnrecognizedMethods(i);return n.push(...de),s.push(...ye),c.push(..._e),this.addSuggestions(),this.properties.sort((Pe,Ge)=>Pe.index-Ge.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 Z(this.project,x.sessionAuthor,M().toISOString(),this,!0,"add-self-to-project"))){const n=[this],s=[],c=[],e=[];if(this.parent.type===d.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 Z(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,H.Updated))),n==null||n.attemptAutoclose(_.SetParent,this.id),this):this}setExtension(i,n=this.project.addChangeSet(new Z(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,H.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 Z(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,H.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 Z(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,H.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 Z(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,H.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 Z(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,H.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 Z(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,H.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 Z(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,H.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 Z(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,H.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 Z(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,H.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 Z(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=he(n,this.project);return s.setParent(this,null),s.initChildren(i),s}),this.methods=this.initialData.methods.map(n=>{const s=he(n,this.project);return s.setParent(this,null),s.initChildren(i),s}),this.abstractMethods=this.initialData.abstractMethods.map(n=>{const s=he(n,this.project);return s.setParent(this,null),s.initChildren(i),s}),this.initialData.extends&&(this.extends=he(this.initialData.extends,this.project)),this.implements=this.initialData.implements.map(n=>he(n,this.project)),this.initialData.allPropertiesImplement){const n=he(this.initialData.allPropertiesImplement,this.project);n.setParent(this,null),n.initChildren(null),this.setAllPropertiesImplement(n,i)}if(this.initialData.additionalPropertiesDataType){const n=he(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 Z(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 Z(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 Z(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 j;return((j=L.implements)==null?void 0:j.id)===b.id}))return;const P=this.methods.find(L=>{var ae,ee;if(L.name===b.name&&!L.implements)return!0;const j=Zi(this,Re.CRON_JOB),F=Zi(this,Re.HTTP_ENDPOINT),q=((ae=L.implements)==null?void 0:ae.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!!(j&&!X&&!F&&q||F&&!q&&!j&&X)});if(P&&P.type===d.FunctionDeclaration){P.setImplements(b,i),P.metaSync({name:b.name},i),i==null||i.add(P,H.Updated),i==null||i.add(this,H.Updated);return}const $=b.implementAsFunctionDeclaration(i,this);s.push($),i==null||i.add($,H.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 Z(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(j=>j.id===E.id));if(b){const{updated:L,added:j,removed:F,affected:q}=b.syncWithImplementation(i);n.push(...L),s.push(...j),c.push(...F),e.push(...q);return}if(this.properties.find(L=>!!L.implements.find(j=>j.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($,H.Added)}),this.properties.find(E=>{var b;return E.id===((b=this.allPropertiesImplement)==null?void 0:b.id)})&&this.removeAllPropertiesImplement(i),i==null||i.attemptAutoclose("sync-implementation-properties",this.id),{updated:D(n),added:D(s),removed:D(c),affected:D(e),self:this}}addExtendedMethods(i=this.project.addChangeSet(new Z(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===d.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,H.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 Z(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,H.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=>{ZBe(this,i).forEach(c=>{const e=c.toJSON();e.id=`_suggestion--parent--${this.id}--${c.id}`;const y=he(e,this.project);y.suggestion=!0,y.setParent(this,null),y.initChildren(null),this.addSuggestedProperty(y)}),HBe(this,i).forEach(c=>{const e=`_suggestion--parent--${this.id}--${c.id}`,y=c.implementAsFunctionDeclaration(null,this,e),m=he(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 Z(this.project,x.sessionAuthor,M().toISOString(),this,!0,"meta-sync"))){const s=Lr(this,i,n),c=$r(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,H.Removed):s.deleted===!1&&e.deleted?n==null||n.add(this,H.Added):c&&(n==null||n.add(this,H.Updated)),n==null||n.attemptAutoclose("meta-sync",this.id),this}async APILoad(i=ke,...n){return await gi.repository.APILoad(this.id,...n),this}async APICreate(i=ke,...n){return await gi.repository.APICreate(this.toShallowJSON(),...n),this}async APIUpdate(i=ke,...n){return await gi.repository.APIUpdate(this.toShallowJSON(),...n),this}async APIDelete(i=ke,...n){return await gi.repository.APIDelete(this.toShallowJSON(),...n),this}async APIClone(i=ke,...n){return await gi.repository.APIClone(this.id,...n),this}async APILoadVersion(i=ke,n,...s){return await gi.repository.APILoadVersion(this.id,n,...s)}removeFromParent(i=this.project.addChangeSet(new Z(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===d.Project)this.parent.removeDefinitionEntity(this);else if(this.parent.type===d.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 Z(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:rr.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 Z(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=ct){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===d.BuiltInBaseEntity?$.toJSON(i.seenEntities):$.toJSONClone({...i,newId:null})),extends:((b=this.extends)==null?void 0:b.type)===d.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=ct){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:d.GenericReference,entityId:n,version:this.version,entityType:this.type}}toShallowJSON(i=ct){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===d.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===d.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=qBe(this),{success:!0}}async validateAsync(i={}){const n=J.YieldTracker.from(i);return this.errors=await SBe(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 Z(this.project,x.sessionAuthor,M().toISOString(),this,!0,_.CloneEntity)),n=null,s=null,c=!0){var j,F,q;const e=Vr(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=Ki(y,e);w.hydrateAncestors(),w.setParent(v,i),c&&(w.subscribe(),w.addSelfToProject(i)),w.initChildren(i),i==null||i.add(w,H.Added);const P=(j=this.properties)==null?void 0:j.map(X=>this.project.diggestedBuiltInBaseEntitiesIds.has(X.id)?e.getBuiltIn(X.id):X.clone(i,w,x.UUID.uuid(),c));w.properties=P;const $=(F=this.methods)==null?void 0:F.map((X,ae)=>this.project.diggestedBuiltInBaseEntitiesIds.has(X.id)?e.getBuiltIn(X.id):X.clone(i,w,b+"-method-"+ae+"-id",c));w.methods=$;const L=(q=this.abstractMethods)==null?void 0:q.map((X,ae)=>this.project.diggestedBuiltInBaseEntitiesIds.has(X.id)?e.getBuiltIn(X.id):X.clone(i,w,b+"-abstract-method-"+ae+"-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 Z(this.project,x.sessionAuthor,M().toISOString(),this,!0,"implement-definition-entity")),s){const c=kI(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===d.DefinitionEntity||y.type===d.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 Z(this.project,x.sessionAuthor,M().toISOString(),this,!0,"infer-definition-entity-from-inputs"))){const s=[],c=[],e=[],y=[];if(this.parent.type!==d.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=>se(P,this.project)===se(b,this.project))||m.push(b)});const v=this.properties.filter(b=>!b.dataType);m.forEach(b=>{var q,X,ae;const w=v.find(ee=>se(ee,this.project)===se(b,this.project));if(!w)return;const $=Wn(b.parent).getMasterInputWithValueWritterFromAllInstances(b),L=hd($,n),j=L==null?void 0:L.clone(n,w,x.UUID.uuid(),!0);j&&((q=w.dataType)==null||q.merge(j,n),j.id!==((X=w.dataType)==null?void 0:X.id)&&j.remove({ignoreUpstream:!1},n),w.dataType&&(w.dataType.metaSync({inferred:!0,like:!0},n),w.setDataType(w.dataType,n),n==null||n.add(w,H.Affected)));let F=null;if(b.declaration&&w.id!==((ae=b.declaration)==null?void 0:ae.id)&&(F=b.declaration),b.setDeclaration(w,n),n==null||n.add(b,H.Updated),F){const{updated:ee,removed:fe}=F.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 ae,ee,fe,oe;const w=this.properties.find(ce=>se(ce,this.project)===se(b,this.project));if(w){if(b.setDeclaration(w,n),!w.getDataType(n)){const Te=Wn(b.parent).getMasterInputWithValueWritterFromAllInstances(b),de=hd(Te),ye=de==null?void 0:de.clone(n,w,x.UUID.uuid(),!0);ye&&((ae=w.dataType)==null||ae.merge(ye,n),ye.id!==((ee=w.dataType)==null?void 0:ee.id)&&ye.remove({ignoreUpstream:!1},n),w.dataType&&(w.dataType.metaSync({inferred:!0,like:!0},n),w.setDataType(w.dataType,n),n==null||n.add(w,H.Affected)))}return}const P=se(b,this.project),$=b.codeName||Ac(b,this.project)||wo(qi(P)),L=ja.new(n);L.parent=this.toReference(),L.index=b.index,L.name=P,L.codeName=$,L.description=b.description;const j=he(L,this.project);j.hydrateAncestors(),n==null||n.add(j,H.Added),j.setParent(this,n),j.initChildren(n);const q=Wn(b.parent).getMasterInputWithValueWritterFromAllInstances(b),X=hd(q);if(X)if(this.project.diggestedBuiltInBaseEntitiesIds.has(X.id))j.setDataType(X,n),n==null||n.add(j,H.Affected);else{const ce=X==null?void 0:X.clone(n,j,x.UUID.uuid(),!0);ce&&((fe=j.dataType)==null||fe.merge(ce,n),ce.id!==((oe=j.dataType)==null?void 0:oe.id)&&ce.remove({ignoreUpstream:!1},n),j.dataType&&(j.dataType.metaSync({inferred:!0,like:!0},n),j.setDataType(j.dataType,n),n==null||n.add(j,H.Affected)))}return this.addProperty(j,n),b.setDeclaration(j,n),n==null||n.add(b,H.Updated),j}),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 e;if(!_A(n))return;const s=se(n,this.project),c=n.codeName||Ac(n,this.project)||wo(qi(s));i[c]=((e=n.getDefaultValue())==null?void 0:e.value)||null}),i}getActiveRawDefaultValue(){const i={};return this.properties.forEach(n=>{var y;if(!_A(n))return;const s=se(n,this.project),c=n.codeName||Ac(n,this.project)||wo(qi(s)),e=(y=this.project.requestActiveDynamicValue(n,!0))==null?void 0:y.value;i[c]=(e==null?void 0:e.value)||null}),i}setAdditionalPropertiesDataType(i,n=this.project.addChangeSet(new Z(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,H.Affected)),n==null||n.attemptAutoclose(_.SetAdditionalPropertiesDataType,this.id),this}removeAdditionalPropertiesDataType(i=this.project.addChangeSet(new Z(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,H.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 Z(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,H.Affected)),n==null||n.attemptAutoclose(_.SetAllPropertiesImplement,this.id),this}removeAllPropertiesImplement(i=this.project.addChangeSet(new Z(this.project,x.sessionAuthor,M().toISOString(),this,!0,_.RemoveAllPropertiesImplement))){return this.checkCanEdit(this,i)?(this.allPropertiesImplement&&(this.properties.find(n=>{var s;return n.id===((s=this.allPropertiesImplement)==null?void 0:s.id)})||this.allPropertiesImplement.remove({ignoreUpstream:!0},i),i==null||i.add(this,H.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(gi,"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(gi,"type",d.DefinitionEntity),I(gi,"USER_MANAGED_PARENT_TYPES",[d.Project,d.DataType]),I(gi,"PARENT_TYPES",[...gi.USER_MANAGED_PARENT_TYPES]),I(gi,"MUTABLE_BASE_PROPERTIES",["name","codeName","description","static","abstract","additionalProperties"]),I(gi,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),I(gi,"BASE_PROPERTIES",[...gi.MUTABLE_BASE_PROPERTIES,...gi.INMUTABLE_BASE_PROPERTIES]),I(gi,"MUTABLE_META_PROPERTIES",[...gi.MUTABLE_BASE_PROPERTIES,"x","y"]),I(gi,"INMUTABLE_META_PROPERTIES",[...gi.INMUTABLE_BASE_PROPERTIES]),I(gi,"META_PROPERTIES",[...gi.MUTABLE_META_PROPERTIES,...gi.INMUTABLE_META_PROPERTIES]),I(gi,"MUTABLE_UPSTREAM_PROPERTIES",["extends","implements"]),I(gi,"INMUTABLE_UPSTREAM_PROPERTIES",["parent"]),I(gi,"UPSTREAM_PROPERTIES",[...gi.MUTABLE_UPSTREAM_PROPERTIES,...gi.INMUTABLE_UPSTREAM_PROPERTIES]),I(gi,"MUTABLE_DOWNSTREAM_PROPERTIES",["properties","methods","abstractMethods","allPropertiesImplement","additionalPropertiesDataType"]),I(gi,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),I(gi,"DOWNSTREAM_PROPERTIES",[...gi.MUTABLE_DOWNSTREAM_PROPERTIES,...gi.INMUTABLE_DOWNSTREAM_PROPERTIES]),I(gi,"PROPERTIES",[...gi.META_PROPERTIES,...gi.UPSTREAM_PROPERTIES,...gi.DOWNSTREAM_PROPERTIES]);let us=gi;async function iRi(o,p={}){const i=J.YieldTracker.from(p),n=[],s=Mt(o.errors,n);return await i.tick(),s}function rRi(o){const p=[];return Mt(o.errors,p)}const xA=class xA extends _V{constructor(i,n){super(i);I(this,"initialData");I(this,"id");I(this,"name");I(this,"description",null);I(this,"type",d.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=he(s,this.project);return c.setParent(this,null),c.initChildren(null),c}),this.methods=this.initialData.methods.map(s=>{const c=he(s,this.project);return c.parent=this,c}),this.abstractMethods=this.initialData.abstractMethods.map(s=>{const c=he(s,this.project);return c.parent=this,c}),this.initialData.extends&&(this.extends=he(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=ke,...n){return await xA.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=ct){return{id:this.id+"--"+x.UUID.uuid()+"--ref",type:d.GenericReference,entityId:this.id,version:this.version,entityType:this.type}}toShallowJSON(i=ct){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=rRi(this),{success:!0}}async validateAsync(i={}){const n=J.YieldTracker.from(i);return this.errors=await iRi(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===d.BuiltInBaseEntity&&this.extends.interactive||this.extends.type===d.PrimitiveEntity?i:(this.extends instanceof No&&i.push(...this.extends.getAllInteractiveMethods()),D(i))}};I(xA,"repository",{APILoad:async(i,...n)=>null});let ma=xA;function Ki(o,p){if(!o)throw new Error("Entity is null");const i=p.get(o.id);switch(o.type){case d.LiteralValue:return i||new Xr(o,p);case d.DefinitionEntity:return i||new us(o,p);case d.PrimitiveEntity:return i||new ma(o,p);case d.FunctionDeclaration:return i||new Vo(o,p);case d.GlobalEvent:return i||new Vu(o,p);case d.DataType:return i||new ir(o,p);case d.Property:return i||new ja(o,p);case d.FunctionCall:return i||new _u(o,p);case d.Condition:return i||new xu(o,p);case d.Operation:return i||new Pu(o,p);case d.VariableDeclaration:return i||new Mu(o,p);case d.VariableInstance:return i||new Lu(o,p);case d.OutputMap:return i||new Il(o,p);case d.ArgumentDeclaration:return i||new Ea(o,p);case d.InputMap:return i||new ds(o,p);case d.Project:return i||new x(o);case d.InstalledProject:return i||new Gu(o,p);case d.ActionDescriptor:return i||new Li(o,p);case d.ReturnStatement:return i||new Ed(o,p);case d.Loop:return i||new Nu(o,p);case d.Search:return i||new Bu(o,p);case d.ValueDescriptor:return i||new Ad(o,p);case d.BuiltInBaseEntity:return i||new No(o,p);case d.InternalCall:return i||new ku(o,p);case d.ContinueStatement:return i||new Uu(o,p);case d.BreakStatement:return i||new ju(o,p);case d.GenericReference:return p.get(o.entityId);default:throw new Error("Invalid entity type: "+o.type)}}function he(o,p){if(!o)throw new Error("Entity is null");const i=Ki(o,p);return i.subscribe(),i}function nRi(o,p){if(!o)throw new Error("Entity is null");switch(o.type){case d.LiteralValue:return Xr.fromGenerationTarget(o,p);case d.DefinitionEntity:return us.fromGenerationTarget(o,p);case d.FunctionDeclaration:return Vo.fromGenerationTarget(o,p);case d.GlobalEvent:return Vu.fromGenerationTarget(o,p);case d.DataType:return ir.fromGenerationTarget(o,p);case d.Property:return ja.fromGenerationTarget(o,p);case d.FunctionCall:return _u.fromGenerationTarget(o,p);case d.Condition:return xu.fromGenerationTarget(o,p);case d.Operation:return Pu.fromGenerationTarget(o,p);case d.VariableDeclaration:return Mu.fromGenerationTarget(o,p);case d.VariableInstance:return Lu.fromGenerationTarget(o,p);case d.OutputMap:return Il.fromGenerationTarget(o,p);case d.ArgumentDeclaration:return Ea.fromGenerationTarget(o,p);case d.InputMap:return ds.fromGenerationTarget(o,p);case d.InstalledProject:return Gu.fromGenerationTarget(o,p);case d.ReturnStatement:return Ed.fromGenerationTarget(o,p);case d.Loop:return Nu.fromGenerationTarget(o,p);case d.Search:return Bu.fromGenerationTarget(o,p);case d.ActionDescriptor:return Li.fromGenerationTarget(o,p);case d.ValueDescriptor:return Ad.fromGenerationTarget(o,p);case d.InternalCall:return ku.fromGenerationTarget(o,p);case d.ContinueStatement:return Uu.fromGenerationTarget(o,p);case d.BreakStatement:return ju.fromGenerationTarget(o,p);default:throw new Error("Invalid entity type: "+o.type)}}const ct={seenEntityMaps:new Map,seenEntities:new Set,timestamp:M().toISOString()};class XBe{constructor(){I(this,"initialData")}}const ke={cascade:!1},QBe={APILoad:async(o,...p)=>null},aRi={APICreate:async(o,...p)=>o,APIUpdate:async(o,...p)=>o,APIDelete:async(o,...p)=>o,APIClone:async(o,...p)=>{},APILoadVersion:async(o,p,...i)=>null,...QBe};class sRi{}class eGe extends XBe{}class lRi extends eGe{}class oRi{}class dRi{}class uRi{}class HN{}class pRi extends HN{}class cRi extends HN{}class fRi{}class af{static initReadsValue(p){if(p.initialData.readsValue&&p.initialData.readsValue.type!==d.GenericReference)p.readsValue=he(p.initialData.readsValue,p.project);else if(p.initialData.readsValue&&p.initialData.readsValue.type===d.GenericReference){const i=qn(p.initialData.readsValue,p.project);i&&(p.readsValue=i)}if(p.readsValue){if(qt.includes(p.readsValue.type)){let i=p.parent;!nr.includes(i.type)&&i.type!==d.Project&&(i=i.parent);const n=p.type===d.InputMap&&p.parent.type===d.Loop;n&&(i=p.parent.parent),p.readsValue.setParent(i,null),p.readsValue.initChildren(null),i&&i.type!==d.Project&&!n&&i.detachedChildren.includes(p)?i.replaceDetachedChild(p,p.readsValue):i&&i.type!==d.Project&&!n&&i.subscribeDetachedChild(p.readsValue)}p.readsValue.addValueReader(p,null)}return p.readsValue}}class _v{static initWritesValues(p,i){const n=p.initialData.writesValues.reduce((c,e)=>{if(e.type===d.GenericReference||p.writesValues.some(m=>m.id===e.id))return c;const y=he(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 yRi{}var zt=(o=>(o.PROJECT_INITIALIZED="project-initialized",o.BEFORE_CHANGE_SET_CLOSE_BEFORE_SIDE_EFFECTS="before-change-set-close-before-side-effects",o.BEFORE_CHANGE_SET_CLOSE_AFTER_SIDE_EFFECTS="before-change-set-close-after-side-effects",o.CHANGE_SET_CLOSED_BEFORE_PERSIST="change-set-closed-before-persist",o.CHANGE_SET_PERSISTED="change-set-persisted",o.BEFORE_CHANGE_SET_PERSIST="before-change-set-persist",o.EXPLICIT_DEFINITION_ENTITY_ADDED="explicit-definition-entity-added",o.EXPLICIT_DEFINITION_ENTITY_REMOVED="explicit-definition-entity-removed",o.EXPLICIT_DEFINITION_ENTITY_UPDATED="explicit-definition-entity-updated",o.PERSISTED_DEFINITION_ENTITY_ADDED="persisted-definition-entity-added",o.PERSISTED_DEFINITION_ENTITY_REMOVED="persisted-definition-entity-removed",o.PERSISTED_DEFINITION_ENTITY_UPDATED="persisted-definition-entity-updated",o.RELATIONAL_DATABASE_DEFINITION_ENTITY_ADDED="relational-database-definition-entity-added",o.RELATIONAL_DATABASE_DEFINITION_ENTITY_REMOVED="relational-database-definition-entity-removed",o.RELATIONAL_DATABASE_DEFINITION_ENTITY_UPDATED="relational-database-definition-entity-updated",o))(zt||{});const WN={...sN,events:new J.Events("def-proj-static-p-ctx-events")},tGe={requestActiveDynamicValue:(o,p=!1)=>null,...WN},Pt=class Pt extends Ur{constructor(i,n={...tGe,events:new J.Events("def-proj-inst-p-ctx-events")}){super(i);I(this,"initialData");I(this,"id");I(this,"type",d.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,!Pt.UUID)throw new Error("UUID module is already initialized. Please inject a valid UUID module.")}static get UUID(){var i;return(i=this.parentContext.requestExtension("uuid"))==null?void 0:i.module}static new(i=null){return{id:Pt.UUID.uuid(),version:Pt.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||M().toISOString(),author:(i==null?void 0:i.author)||Pt.sessionAuthor,previousVersion:null,deleted:!1,deletable:!0,editable:!0,type:d.Project,name:"",description:"",entities:[],functions:[],events:[],projects:[],variableDeclarations:[],variableInstances:[],conditions:[],operations:[],functionCalls:[],loops:[],searches:[]}}static validateGenerationTarget(i,n){let s=JSON.parse(JSON.stringify(i));const c=[];return c.push(...xr(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 Z(this,i,n,s,c,e);const y=this.history[this.history.length-1];return y.open?y:this.addChangeSet(new Z(this,i,n,s,c,e))}addChangeSet(i){var s,c;if(!this.history.length)return this.undoableStackValueIndex=jO(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} ${se(e.self,this)}`:""}.`)}return this.undoableStackValueIndex=jO(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 Z(this.project,Pt.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=Pt.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 Pt(this);return i.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,i):new Map([[this.version,i]]),i.entities=[...this.entities],i.projects=[...this.projects],i.functions=[...this.functions],i.events=[...this.events],i.variableDeclarations=[...this.variableDeclarations],i.variableInstances=[...this.variableInstances],i.conditions=[...this.conditions],i.operations=[...this.operations],i.functionCalls=[...this.functionCalls],i.loops=[...this.loops],i.searches=[...this.searches],this}recursiveCaptureUpstreamVersions(i){const 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 Pt(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 Z(this.project,Pt.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 Z(this.project,Pt.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=he(n,this);return s.setParent(this,null),s.initChildren(i),s}),this.projects=this.initialData.projects.map(n=>{const s=he(n,this);return s.setParent(this,null),s.initChildren(i),s}),this.variableDeclarations=this.initialData.variableDeclarations.map(n=>{const s=he(n,this);return s.setParent(this,null),s.initChildren(i),s}),this.variableInstances=this.initialData.variableInstances.map(n=>{const s=he(n,this);return s.setParent(this,null),s.initChildren(i),s}),this.conditions=this.initialData.conditions.map(n=>{const s=he(n,this);return s.setParent(this,null),s.initChildren(i),s}),this.operations=this.initialData.operations.map(n=>{const s=he(n,this);return s.setParent(this,null),s.initChildren(i),s}),this.functions=this.initialData.functions.map(n=>{const s=he(n,this);return s.setParent(this,null),s.initChildren(i),s}),this.events=this.initialData.events.map(n=>{const s=he(n,this);return s.setParent(this,null),s.initChildren(i),s}),this.functionCalls=this.initialData.functionCalls.map(n=>{const s=he(n,this);return s.setParent(this,null),s.initChildren(i),s}),this.loops=this.initialData.loops.map(n=>{const s=he(n,this);return s.setParent(this,null),s.initChildren(i),s}),this.searches=this.initialData.searches.map(n=>{const s=he(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){if(i.id==="3bdd91d6-fa96-403f-af98-532a1110b28a")throw console.log("[ProjectState.subscribeDeletedInstance] Debug"),new Error("[ProjectState.subscribeDeletedInstance] Debug");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){if(i.id==="3bdd91d6-fa96-403f-af98-532a1110b28a")throw console.log("[ProjectState.unsubscribeInstance] debug"),new Error("[ProjectState.unsubscribeInstance] debug");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 Z(this.project,Pt.sessionAuthor,M().toISOString(),this,!0,"meta-sync"))){const s=Lr(this,i,n),c=$r(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,H.Removed):s.deleted===!1&&e.deleted?n==null||n.add(this,H.Added):c&&(n==null||n.add(this,H.Updated)),n==null||n.attemptAutoclose("meta-sync",this.id),this}async APILoad(i=ke,...n){return await Pt.repository.APILoad(this.id,...n),this}async APICreate(i=ke,...n){return await Pt.repository.APICreate(this.toShallowJSON(),...n),this}async APIUpdate(i=ke,...n){return await Pt.repository.APIUpdate(this.toShallowJSON(),...n),this}async APIDelete(i=ke,...n){return await Pt.repository.APIDelete(this.toShallowJSON(),...n),this}async APIClone(i=ke,...n){return await Pt.repository.APIClone(this.id,...n),this}async APILoadVersion(i=ke,n,...s){return await Pt.repository.APILoadVersion(this.id,n,...s)}remove({ignoreUpstream:i}={ignoreUpstream:!1},n=this.project.addChangeSet(new Z(this.project,Pt.sessionAuthor,M().toISOString(),this,!0,_.RemoveEntity))){return{added:[],updated:[],removed:[],affected:[],self:this}}restore({}={},i=this.project.addChangeSet(new Z(this.project,Pt.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,Pt.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=ct){var s;let n=this.id;return(s=i.seenEntityMaps)!=null&&s.has(this.id)&&(n=i.seenEntityMaps.get(this.id)),{id:n+"--"+Pt.UUID.uuid()+"--ref",type:d.GenericReference,entityId:n,version:this.version,entityType:this.type}}toShallowJSON(i=ct){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(),ev([...this.errors]),{success:!0}}async validateAsync(i={}){const n=J.YieldTracker.from(i);return await this.validateChildrenAsync({tracker:n}),await gwe([...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!==d.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=wt(s);return[...n,...c.filter(e=>e.type===d.ReturnStatement||e.type===d.ContinueStatement||e.type===d.BreakStatement)]},[])]}getFunctionDeclaration(i){return this.functions.find(n=>n.id===i)||null}getConditions(){return[...this.conditions,...this.getEntryPoints().reduce((n,s)=>{const c=wt(s);return[...n,...c.filter(e=>e.type===d.Condition)]},[]),...this.functionCalls.reduce((n,s)=>{const c=wt(s);return[...n,...c.filter(e=>e.type===d.Condition)]},[]),...this.operations.reduce((n,s)=>{const c=wt(s);return[...n,...c.filter(e=>e.type===d.Condition)]},[]),...this.loops.reduce((n,s)=>{const c=wt(s);return[...n,...c.filter(e=>e.type===d.Condition)]},[]),...this.searches.reduce((n,s)=>{const c=wt(s);return[...n,...c.filter(e=>e.type===d.Condition)]},[])]}getOperations(){return[...this.operations,...this.getEntryPoints().reduce((n,s)=>{const c=wt(s);return[...n,...c.filter(e=>e.type===d.Operation)]},[]),...this.functionCalls.reduce((n,s)=>{const c=wt(s);return[...n,...c.filter(e=>e.type===d.Operation)]},[]),...this.conditions.reduce((n,s)=>{const c=wt(s);return[...n,...c.filter(e=>e.type===d.Operation)]},[]),...this.loops.reduce((n,s)=>{const c=wt(s);return[...n,...c.filter(e=>e.type===d.Operation)]},[]),...this.searches.reduce((n,s)=>{const c=wt(s);return[...n,...c.filter(e=>e.type===d.Operation)]},[])]}getFunctionCalls(){return[...this.functionCalls,...this.getEntryPoints().reduce((n,s)=>{const c=wt(s);return[...n,...c.filter(e=>e.type===d.FunctionCall)]},[]),...this.conditions.reduce((n,s)=>{const c=wt(s);return[...n,...c.filter(e=>e.type===d.FunctionCall)]},[]),...this.operations.reduce((n,s)=>{const c=wt(s);return[...n,...c.filter(e=>e.type===d.FunctionCall)]},[]),...this.loops.reduce((n,s)=>{const c=wt(s);return[...n,...c.filter(e=>e.type===d.FunctionCall)]},[]),...this.searches.reduce((n,s)=>{const c=wt(s);return[...n,...c.filter(e=>e.type===d.FunctionCall)]},[])]}getVariables(){return[...this.variableDeclarations,...this.getEntryPoints().reduce((n,s)=>{const c=Ji(s);return[...n,...c]},[]),...this.functionCalls.reduce((n,s)=>{const c=Ji(s);return[...n,...c]},[]),...this.conditions.reduce((n,s)=>{const c=Ji(s);return[...n,...c]},[]),...this.operations.reduce((n,s)=>{const c=Ji(s);return[...n,...c]},[]),...this.loops.reduce((n,s)=>{const c=Ji(s);return[...n,...c]},[]),...this.searches.reduce((n,s)=>{const c=Ji(s);return[...n,...c]},[])]}getVariableInstances(){return[...this.variableInstances,...this.entities.reduce((n,s)=>[...n,...s.methods.flatMap(c=>{const y=wt(c).filter(m=>m.type===d.VariableInstance);return[...n,...y]})],[]),...this.getEntryPoints().reduce((n,s)=>{const e=Ji(s).filter(y=>y.type===d.VariableInstance);return[...n,...e]},[]),...this.functionCalls.reduce((n,s)=>{const e=Ji(s).filter(y=>y.type===d.VariableInstance);return[...n,...e]},[]),...this.conditions.reduce((n,s)=>{const e=Ji(s).filter(y=>y.type===d.VariableInstance);return[...n,...e]},[]),...this.operations.reduce((n,s)=>{const e=Ji(s).filter(y=>y.type===d.VariableInstance);return[...n,...e]},[]),...this.loops.reduce((n,s)=>{const e=Ji(s).filter(y=>y.type===d.VariableInstance);return[...n,...e]},[]),...this.searches.reduce((n,s)=>{const e=Ji(s).filter(y=>y.type===d.VariableInstance);return[...n,...e]},[])]}getVariableDeclarations(){return D([...this.variableDeclarations,...this.entities.reduce((n,s)=>[...n,...s.methods.flatMap(c=>{const y=wt(c).filter(m=>m.type===d.VariableDeclaration);return[...n,...y]})],[]),...this.getEntryPoints().reduce((n,s)=>{const e=Ji(s).filter(y=>y.type===d.VariableDeclaration);return[...n,...e]},[]),...this.functionCalls.reduce((n,s)=>{const e=Ji(s).filter(y=>y.type===d.VariableDeclaration);return[...n,...e]},[]),...this.conditions.reduce((n,s)=>{const e=Ji(s).filter(y=>y.type===d.VariableDeclaration);return[...n,...e]},[]),...this.operations.reduce((n,s)=>{const e=Ji(s).filter(y=>y.type===d.VariableDeclaration);return[...n,...e]},[]),...this.loops.reduce((n,s)=>{const e=Ji(s).filter(y=>y.type===d.VariableDeclaration);return[...n,...e]},[]),...this.searches.reduce((n,s)=>{const e=Ji(s).filter(y=>y.type===d.VariableDeclaration);return[...n,...e]},[])])}getLoops(){return[...this.loops,...this.getEntryPoints().reduce((n,s)=>{const c=wt(s);return[...n,...c.filter(e=>e.type===d.Loop)]},[]),...this.functionCalls.reduce((n,s)=>{const c=wt(s);return[...n,...c.filter(e=>e.type===d.Loop)]},[]),...this.conditions.reduce((n,s)=>{const c=wt(s);return[...n,...c.filter(e=>e.type===d.Loop)]},[]),...this.operations.reduce((n,s)=>{const c=wt(s);return[...n,...c.filter(e=>e.type===d.Loop)]},[]),...this.searches.reduce((n,s)=>{const c=wt(s);return[...n,...c.filter(e=>e.type===d.Loop)]},[])]}getSearches(){return[...this.searches,...this.getEntryPoints().reduce((n,s)=>{const c=wt(s);return[...n,...c.filter(e=>e.type===d.Search)]},[]),...this.functionCalls.reduce((n,s)=>{const c=wt(s);return[...n,...c.filter(e=>e.type===d.Search)]},[]),...this.conditions.reduce((n,s)=>{const c=wt(s);return[...n,...c.filter(e=>e.type===d.Search)]},[]),...this.operations.reduce((n,s)=>{const c=wt(s);return[...n,...c.filter(e=>e.type===d.Search)]},[]),...this.loops.reduce((n,s)=>{const c=wt(s);return[...n,...c.filter(e=>e.type===d.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&&LA.includes(i.type)){const y=i.getDefaultValue();return y?{value:y,type:Ve.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()),GO(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()),GO(i||"initial",n||"initial",this)}applyExternalChangeSet(i){const n=i.payload,s=this.addChangeSet(new Z(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(`,
|
|
387
387
|
`)),J.Logger.log("Persisting new additions"),m.visit(async(v,E)=>{if(n.added[v.id]){J.Logger.log("Adding: ",v.id);try{const b=he(v,this);if(b.hydrateAncestors(),b.addSelfToProject(s),s.add(b,H.Added),!this.get(v.id))throw new Error(`Entity ${v.id} was not added to the project`)}catch(b){J.Logger.error("Error: ",b),J.Logger.error("Errored entity: ",v)}}}),J.Logger.log("Persisting updates"),m.visit(async(v,E)=>{if(n.updated[v.id]){J.Logger.log("Updating: ",v.id);try{const b=this.get(v.id);b?(b.updateWithShallowTransfer(v,s),s.add(b,H.Updated)):J.Logger.warn(`Active version of ${v.id} not found when applying external changes`)}catch(b){J.Logger.error("Error: ",b),J.Logger.error("Errored entity: ",v)}}}),J.Logger.log("Persisting removals"),m.visit(async(v,E)=>{if(n.removed[v.id]){J.Logger.log("Removing: ",v.id);try{const b=this.get(v.id);b&&b.remove({ignoreUpstream:!1},s)}catch(b){J.Logger.error("Error: ",b),J.Logger.error("Errored entity: ",v)}}}),s.open=!1,s}toBuiltInShallowRecord(){const i={};return Object.values(this.builtInInstances).forEach(n=>{const s=n.toShallowJSON();i[n.id]=s}),i}toShallowRecord(){const i={};return Object.values(this.instances).forEach(n=>{const s=n.toShallowJSON();i[n.id]=s}),i}toFullProjectTransfer(){const i=new Yn(this,{allBuiltInEntityIds:this.diggestedBuiltInBaseEntitiesIds}),n={};return i.visit(s=>{const c=s.toShallowJSON();n[s.id]=c}),{order:i.order,size:i.order.length,record:n}}};I(Pt,"parentContext",WN),I(Pt,"sessionAuthor","1"),I(Pt,"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(Pt,"type",d.Project),I(Pt,"USER_MANAGED_PARENT_TYPES",[]),I(Pt,"PARENT_TYPES",[...Pt.USER_MANAGED_PARENT_TYPES]),I(Pt,"MUTABLE_BASE_PROPERTIES",["name","description"]),I(Pt,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),I(Pt,"BASE_PROPERTIES",[...Pt.MUTABLE_BASE_PROPERTIES,...Pt.INMUTABLE_BASE_PROPERTIES]),I(Pt,"MUTABLE_META_PROPERTIES",[...Pt.MUTABLE_BASE_PROPERTIES,"x","y"]),I(Pt,"INMUTABLE_META_PROPERTIES",[...Pt.INMUTABLE_BASE_PROPERTIES]),I(Pt,"META_PROPERTIES",[...Pt.MUTABLE_META_PROPERTIES,...Pt.INMUTABLE_META_PROPERTIES]),I(Pt,"MUTABLE_UPSTREAM_PROPERTIES",[]),I(Pt,"INMUTABLE_UPSTREAM_PROPERTIES",["primitives","builtInBaseEntities","operationDeclarations","globalEventActionDescriptors","loopDeclarations","builtInInstances"]),I(Pt,"UPSTREAM_PROPERTIES",[...Pt.MUTABLE_UPSTREAM_PROPERTIES,...Pt.INMUTABLE_UPSTREAM_PROPERTIES]),I(Pt,"MUTABLE_DOWNSTREAM_PROPERTIES",["entities","projects","functions","events","variableDeclarations","variableInstances","conditions","operations","functionCalls","loops","searches"]),I(Pt,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),I(Pt,"DOWNSTREAM_PROPERTIES",[...Pt.MUTABLE_DOWNSTREAM_PROPERTIES,...Pt.INMUTABLE_DOWNSTREAM_PROPERTIES]),I(Pt,"PROPERTIES",[...Pt.META_PROPERTIES,...Pt.UPSTREAM_PROPERTIES,...Pt.DOWNSTREAM_PROPERTIES]);let x=Pt;class hRi extends Li{constructor(p){super(KT,p)}}class mRi extends Li{constructor(i){super(ih,i);I(this,"autoexecutable",!0)}getEntityToMatchInputMap(i){return i.inputs.find(n=>{var s;return((s=n.declaration)==null?void 0:s.id)===Q.operation[Ce.Validate].inputs.entityToMatch.id})||null}getDataToValidateInputMap(i){return i.inputs.find(n=>{var s;return((s=n.declaration)==null?void 0:s.id)===Q.operation[Ce.Validate].inputs.dataToValidate.id})||null}getOutputDataOutputMap(i){return i.outputs.find(n=>{var s;return((s=n.declaration)==null?void 0:s.id)===Q.operation[Ce.Validate].dataType.entity.properties.outputEntity.id})||null}getEntityToMatch(i,n=this.project.addChangeSet(new Z(this.project,x.sessionAuthor,M().toISOString(),this,!0,"get-entity-to-match-validate-data"))){var e;const s=((e=this.project.requestActiveDynamicValue(i))==null?void 0:e.value)||null,c=s==null?void 0:s.valueAsTypeSingle;return n==null||n.attemptAutoclose("get-entity-to-match-validate-data",this.id),c}syncOperationInstance(i,n=this.project.addChangeSet(new Z(this.project,x.sessionAuthor,M().toISOString(),this,!0,"sync-operation-instance-validate-data"))){const s=[],c=[],e=[],y=[],m=this.getEntityToMatchInputMap(i);if(m){const{added:b,updated:w,removed:P,affected:$}=this.syncEntityToMatchInputMapDataType(m,n);s.push(...w),c.push(...b),e.push(...P),y.push(...$)}const v=this.getDataToValidateInputMap(i);if(v){const{added:b,updated:w,removed:P,affected:$}=this.syncDataToValidateInputMapDataType(v,n);s.push(...w),c.push(...b),e.push(...P),y.push(...$)}const E=this.getOutputDataOutputMap(i);if(E){const{added:b,updated:w,removed:P,affected:$}=this.syncOutputDataOutputMapDataType(E,n);s.push(...w),c.push(...b),e.push(...P),y.push(...$)}return n==null||n.attemptAutoclose("sync-operation-instance-validate-data",this.id),{updated:D(s),added:D(c),removed:D(e),affected:D(y),self:i}}syncEntityToMatchInputMapDataType(i,n=this.project.addChangeSet(new Z(this.project,x.sessionAuthor,M().toISOString(),this,!0,"sync-entity-to-match-input-map-data-type"))){var E,b,w,P,$,L,j,F,q,X,ae,ee,fe,oe,ce,Te,de,ye;const s=[],c=[],e=[],y=[];if(((E=i.declaration)==null?void 0:E.id)!==Q.operation[Ce.Validate].inputs.entityToMatch.id)return n==null||n.attemptAutoclose("sync-entity-to-match-input-map-data-type",this.id),{updated:[],added:[],removed:[],affected:[],self:null};const m=((b=this.project.requestActiveDynamicValue(i))==null?void 0:b.value)||null,v=m==null?void 0:m.valueAsTypeSingle;if(!i.dataType){const _e={id:x.UUID.uuid(),version:x.UUID.uuid(),createdAt:(n==null?void 0:n.timestamp)||new Date().toISOString(),author:(n==null?void 0:n.author)||x.sessionAuthor,previousVersion:null,deleted:!1,deletable:!0,editable:!0,type:d.DataType,parentRelationType:null,options:((w=i.declaration.dataType)==null?void 0:w.options)||null,implementationChooseOne:((P=i.declaration.dataType)==null?void 0:P.implementationChooseOne)||!1,staticEntities:(($=i.declaration.dataType)==null?void 0:$.staticEntities)??null,interactiveEntities:((L=i.declaration.dataType)==null?void 0:L.interactiveEntities)??null,actionEntities:((j=i.declaration.dataType)==null?void 0:j.actionEntities)??null,index:((F=i.declaration.dataType)==null?void 0:F.index)??null,isList:((q=i.declaration.dataType)==null?void 0:q.isList)||!1,foreignKeyAllowed:((X=i.declaration.dataType)==null?void 0:X.foreignKeyAllowed)??null,andChildrenGroup:null,orChildrenGroup:null,foreignKeyRef:null,asType:!0,entity:(v==null?void 0:v.toJSON())||null,like:!0,inferred:!0,parent:i.toReference()},Pe=he(_e,i.project);Pe.hydrateAncestors(),Pe.setParent(i,n),Pe.initChildren(n),Pe.setEntity(v,n),n==null||n.add(Pe,H.Added),s.push(Pe),i.setDataType(Pe,n)}return(de=i.dataType)==null||de.metaSync({inferred:!0,like:!1,asType:!0,options:((ae=i.declaration.dataType)==null?void 0:ae.options)||null,implementationChooseOne:((ee=i.declaration.dataType)==null?void 0:ee.implementationChooseOne)||!1,staticEntities:((fe=i.declaration.dataType)==null?void 0:fe.staticEntities)??null,interactiveEntities:((oe=i.declaration.dataType)==null?void 0:oe.interactiveEntities)??null,actionEntities:((ce=i.declaration.dataType)==null?void 0:ce.actionEntities)??null,isList:((Te=i.declaration.dataType)==null?void 0:Te.isList)||!1},n),(ye=i.dataType)==null||ye.setEntity(v,n),i.dataType&&c.push(i.dataType),n==null||n.attemptAutoclose("sync-entity-to-match-input-map-data-type",this.id),{updated:D(c),added:D(s),removed:D(e),affected:D(y),self:i.dataType}}syncDataToValidateInputMapDataType(i,n=this.project.addChangeSet(new Z(this.project,x.sessionAuthor,M().toISOString(),this,!0,"sync-data-to-validate-input-map-data-type"))){var b,w,P;const s=[],c=[],e=[],y=[];if(((b=i.declaration)==null?void 0:b.id)!==Q.operation[Ce.Validate].inputs.dataToValidate.id)return n==null||n.attemptAutoclose("sync-data-to-validate-input-map-data-type",this.id),{updated:[],added:[],removed:[],affected:[],self:null};const m=this.getEntityToMatchInputMap(i.parent);if(!m)return n==null||n.attemptAutoclose("sync-data-to-validate-input-map-data-type",this.id),{updated:[],added:[],removed:[],affected:[],self:null};if(!this.getEntityToMatch(m,n))return n==null||n.attemptAutoclose("sync-data-to-validate-input-map-data-type",this.id),{updated:[],added:[],removed:[],affected:[],self:null};if(!i.dataType){const $={id:x.UUID.uuid(),version:x.UUID.uuid(),createdAt:(n==null?void 0:n.timestamp)||new Date().toISOString(),author:(n==null?void 0:n.author)||x.sessionAuthor,previousVersion:null,deleted:!1,deletable:!0,editable:!0,type:d.DataType,index:null,parentRelationType:null,options:null,implementationChooseOne:!1,foreignKeyAllowed:null,isList:!1,foreignKeyRef:null,andChildrenGroup:null,orChildrenGroup:null,staticEntities:null,interactiveEntities:null,actionEntities:null,asType:!1,entity:null,like:!0,inferred:!0,parent:i.toReference()},L=he($,i.project);L.setParent(i,n),L.initChildren(n),n==null||n.add(L,H.Added),s.push(L),i.setDataType(L,n)}(w=i.dataType)==null||w.metaSync({inferred:!0,like:!0,asType:!1},n);const E=this.getEntityToMatch(m,n);return(P=i.dataType)==null||P.setEntity(E,n),i.dataType&&c.push(i.dataType),n==null||n.attemptAutoclose("sync-data-to-validate-input-map-data-type",this.id),{updated:D(c),added:D(s),removed:D(e),affected:D(y),self:i.dataType}}syncOutputDataOutputMapDataType(i,n=this.project.addChangeSet(new Z(this.project,x.sessionAuthor,M().toISOString(),this,!0,"sync-output-data-output-map-data-type"))){var w,P,$,L;const s=[],c=[],e=[],y=[];if(((w=i.declaration)==null?void 0:w.id)!==Q.operation[Ce.Validate].dataType.entity.properties.outputEntity.id)return n==null||n.attemptAutoclose("sync-output-data-output-map-data-type",this.id),{updated:[],added:[],removed:[],affected:[],self:null};const m=this.getEntityToMatchInputMap(i.parent);if(!m)return n==null||n.attemptAutoclose("sync-output-data-output-map-data-type",this.id),{updated:[],added:[],removed:[],affected:[],self:null};if(!this.getEntityToMatch(m,n))return n==null||n.attemptAutoclose("sync-output-data-output-map-data-type",this.id),{updated:[],added:[],removed:[],affected:[],self:null};const E=((P=this.project.requestActiveDynamicValue(m))==null?void 0:P.value)||null,b=(E==null?void 0:E.valueAsTypeSingle)||null;if(!i.dataType){const j={id:x.UUID.uuid(),version:x.UUID.uuid(),createdAt:(n==null?void 0:n.timestamp)||new Date().toISOString(),author:(n==null?void 0:n.author)||x.sessionAuthor,previousVersion:null,deleted:!1,deletable:!0,editable:!0,type:d.DataType,parentRelationType:null,options:null,foreignKeyRef:null,implementationChooseOne:!1,foreignKeyAllowed:null,staticEntities:null,interactiveEntities:null,index:null,actionEntities:null,isList:!1,andChildrenGroup:null,orChildrenGroup:null,asType:!1,entity:(b==null?void 0:b.toJSON())||null,like:!0,inferred:!0,parent:i.toReference()},F=he(j,i.project);F.hydrateAncestors(),F.setParent(i,n),F.initChildren(n),F.setEntity(b,n),n==null||n.add(F,H.Added),s.push(F),i.setDataType(F,n)}return($=i.dataType)==null||$.metaSync({inferred:!0,like:!0,asType:!1},n),(L=i.dataType)==null||L.setEntity(b,n),i.dataType&&c.push(i.dataType),n==null||n.attemptAutoclose("sync-output-data-output-map-data-type",this.id),{updated:D(c),added:D(s),removed:D(e),affected:D(y),self:i.dataType}}inferInputMapDataType(i,n=this.project.addChangeSet(new Z(this.project,x.sessionAuthor,M().toISOString(),this,!0,"infer-input-map-data-type-validate-data"))){var c,e,y;if(((c=i.declaration)==null?void 0:c.id)===Q.operation[Ce.Validate].inputs.entityToMatch.id){const{added:m,updated:v,removed:E,affected:b}=this.syncEntityToMatchInputMapDataType(i,n);return n==null||n.attemptAutoclose("infer-input-map-data-type",this.id),{updated:D(v),added:D(m),removed:D(E),affected:D(b),self:i.dataType}}if(((e=i.declaration)==null?void 0:e.id)===Q.operation[Ce.Validate].inputs.dataToValidate.id){const{added:m,updated:v,removed:E,affected:b}=this.syncDataToValidateInputMapDataType(i,n);return n==null||n.attemptAutoclose("infer-input-map-data-type",this.id),{updated:D(v),added:D(m),removed:D(E),affected:D(b),self:i.dataType}}const s=(y=i.declaration)==null?void 0:y.getDataType(n);if(s&&s.isResolved)return n==null||n.attemptAutoclose("infer-input-map-data-type-validate-data",this.id),{updated:[],added:[],removed:[],affected:[],self:s};if(i.readsValue){const m=hd(i.readsValue,n);return n==null||n.attemptAutoclose("infer-input-map-data-type-validate-data",this.id),{updated:[],added:[],removed:[],affected:[],self:m}}return n==null||n.attemptAutoclose("infer-input-map-data-type-validate-data",this.id),{updated:[],added:[],removed:[],affected:[],self:null}}inferOutputMapDataType(i,n=this.project.addChangeSet(new Z(this.project,x.sessionAuthor,M().toISOString(),this,!0,"infer-output-map-data-type-validate-data"))){var s;if(((s=i.declaration)==null?void 0:s.id)===Q.operation[Ce.Validate].dataType.entity.properties.outputEntity.id){const{added:c,updated:e,removed:y,affected:m}=this.syncOutputDataOutputMapDataType(i,n);return n==null||n.attemptAutoclose("infer-output-map-data-type-validate-data",this.id),{updated:D(e),added:D(c),removed:D(y),affected:D(m),self:i.dataType}}return{updated:[],added:[],removed:[],affected:[],self:null}}}class TRi extends Li{constructor(p){super(o_,p)}}class vRi extends Li{constructor(p){super(d_,p)}}class ERi extends Li{constructor(p){super(u_,p)}}class bRi extends Li{constructor(p){super(Eg,p)}}class ARi extends Li{constructor(p){super(GA,p)}}class gRi extends Li{constructor(p){super(rT,p)}}function iGe(o){const p=[new ROe(o),new gOe(o),new IOe(o),new hRi(o),new mRi(o),new bRi(o),new TRi(o),new ERi(o),new vRi(o),new ARi(o),new gRi(o)];return LP.forEach(i=>{p.some(n=>n.id===i.id)||p.push(new Li(i,o))}),p.forEach(i=>{i.initChildren(null),o.subscribeBuiltInInstance(i)}),o.operationDeclarations=p,p}class IRi extends No{constructor(i){super(In,i);I(this,"initialData");I(this,"id",Re.PERSISTED_ENTITY);I(this,"version","1");I(this,"name",Re.PERSISTED_ENTITY);I(this,"description",In.description);I(this,"type",d.BuiltInBaseEntity);I(this,"abstract",In.abstract);I(this,"static",In.static);I(this,"properties",[]);I(this,"methods",[]);I(this,"abstractMethods",[]);I(this,"extends",null);I(this,"errors",[]);I(this,"project");this.initialData=In,this.project=i,this.id=In.id,this.version=In.version,this.name=In.name,this.static=In.static,this.abstract=In.abstract,this.properties=this.initialData.properties.map(s=>{const c=he(s,this.project);return c.setParent(this,null),c.initChildren(null),c}),this.methods=this.initialData.methods.map(s=>{const c=he(s,this.project);return c.parent=this,c}),this.abstractMethods=this.initialData.abstractMethods.map(s=>{const c=he(s,this.project);return c.parent=this,c}),this.initialData.extends&&(this.extends=he(this.initialData.extends,this.project));const n=this.properties.find(s=>s.id===Q["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.identifier.id);if(!n)throw new Error("Path property not found in endpoint entity");n._codeNativeValueValidation=(s,c)=>EOe(s,c)}}const RRi=[];function rGe(o){const p=[new vOe(o),new AOe(o),new IRi(o)];return lV.forEach(i=>{!p.some(n=>n.id===i.id)&&!RRi.includes(i.id)&&p.push(new No(i,o))}),p.forEach(i=>{o.subscribeBuiltInInstance(i)}),o.builtInBaseEntities=p,p}function nGe(o){const p=[new ma(ue,o),new ma(st,o),new ma(we,o),new ma(ba,o),new ma(ht,o),new ma(It,o),new ma(at,o),new ma(Rl,o),new ma(Hi,o)];return p.forEach(i=>{o.subscribeBuiltInInstance(i)}),o.primitives=p,p}function aGe(o){const p=[new Li($I,o)];return p.forEach(i=>{i.initChildren(null),o.subscribeBuiltInInstance(i)}),o.globalEventActionDescriptors=p,p}function sGe(o){const p=[new Li(QT,o),new Li(Jc,o),new Li(YT,o),new Li(Dh,o),new Li(wh,o),new Li(hI,o)];p.forEach(n=>{n.initChildren(null),o.subscribeBuiltInInstance(n)}),o.loopDeclarations=p;const i=[new Li(DI,o),new Li(XT,o),new Li(EI,o),new Li(UP,o),new Li(SP,o),new Li(mI,o)];return i.forEach(n=>{n.initChildren(null),o.subscribeBuiltInInstance(n)}),o.loopDeclarationsBodies=i,p}function lGe(o){const p=[new Ad(yV,o)];return p.forEach(i=>{i.initChildren(null),o.subscribeBuiltInInstance(i)}),o.valueDescriptors=p,p}function oGe(o){const p=[new Li(dV,o),new Li(oV,o),new Li(uV,o),new Li(pV,o)];return cV.forEach(i=>{p.some(n=>n.id===i.id)||p.push(new Li(i,o))}),p.forEach(i=>{i.initChildren(null),o.subscribeBuiltInInstance(i)}),o.conditionDeclarations=p,p}function Vm(o){return o&&typeof o.then=="function"}function DRi(o,p){const i=new Yn(o[0],{allBuiltInEntityIds:p.allBuiltInEntityIds}),n=o.map(c=>c.id),s={};return o.forEach(c=>{s[c.id]=c}),i.order=n,i.flatRecord=s,i.orderEntities(),i.order.map(c=>i.flatRecord[c])}function wRi(o,p){const i=new Yn(Object.values(o)[0],{allBuiltInEntityIds:p.allBuiltInEntityIds}),n=Object.keys(o);return i.order=n,i.flatRecord=o,i.orderEntities(),i.order}async function ORi(o,p){const i=J.YieldTracker.from(p),n=new Yn(o[0],{allBuiltInEntityIds:p.allBuiltInEntityIds}),s=o.map(e=>e.id),c={};for(const e of o)c[e.id]=e,await i.tick();return n.order=s,n.flatRecord=c,await n.orderEntitiesAsync({tracker:i}),n.order.map(e=>n.flatRecord[e])}async function CRi(o,p){const i=J.YieldTracker.from(p),n=new Yn(Object.values(o)[0],{allBuiltInEntityIds:p.allBuiltInEntityIds}),s=Object.keys(o);return n.order=s,n.flatRecord=o,await n.orderEntitiesAsync({tracker:i}),n.order}class Yn{constructor(p,i={}){I(this,"order",[]);I(this,"flatRecord",{});I(this,"allBuiltInEntityIds");I(this,"onGoingVisits",{});I(this,"cachedReferences",{});if(i.allBuiltInEntityIds&&(this.allBuiltInEntityIds=i.allBuiltInEntityIds),!p)return;const n={asyncInitialOrder:!1,...i};n.asyncInitialOrder?this.flattenAsync(p).then(()=>{this.orderEntitiesAsync({...n}).then(()=>{var s;(s=n.onOrdered)==null||s.call(n)})}):(this.flatten(p),this.orderEntities())}flatten(p){this.allBuiltInEntityIds||(this.allBuiltInEntityIds=new Set(I1()));const i=D(Le(p,new Set(this.allBuiltInEntityIds),{ignoreBuiltInBaseEntities:!0,diggestedBuiltInBaseEntitiesIds:this.allBuiltInEntityIds})),n=new Set;for(const s of i)this.flatRecord[s.id]=s,n.add(s.id);this.order=Array.from(n)}async flattenAsync(p,i={}){const n=J.YieldTracker.from(i);this.allBuiltInEntityIds||(this.allBuiltInEntityIds=await R1({tracker:n}));const s=await wu(await $e(p,new Set(this.allBuiltInEntityIds),{ignoreBuiltInBaseEntities:!0,diggestedBuiltInBaseEntitiesIds:this.allBuiltInEntityIds,tracker:n}),{tracker:n}),c=new Set;for(const e of s)this.flatRecord[e.id]=e,c.add(e.id),await n.tick();this.order=Array.from(c)}moveEntityAfterDependencies(p){const i=this.cachedReferences[p.id]||md(p,this.flatRecord,{ignoreBuiltInBaseEntities:!0,allBuiltInEntityIds:this.allBuiltInEntityIds});this.cachedReferences[p.id]=i;const{upstream:n}=i;for(const s of Object.keys(n)){const c=this.order.indexOf(s),e=this.order.indexOf(p.id);if(c>e)return this.order.splice(e,1),this.order.splice(c,0,p.id),!0}return!1}orderEntities(){let p=!1;for(let i=0;i<this.order.length;i++){const n=this.order[i],s=this.flatRecord[n];if(s||J.Logger.warn(`Entity with id ${n} not found in flatRecord. Skipping...`),this.moveEntityAfterDependencies(s)){p=!0;break}}p&&this.orderEntities()}async orderEntitiesAsync(p={}){let i=!1;const n=J.YieldTracker.from(p);for(let s=0;s<this.order.length;s++){const c=this.order[s],e=this.flatRecord[c];if(e||J.Logger.warn(`Entity with id ${c} not found in flatRecord. Skipping...`),this.moveEntityAfterDependencies(e)){i=!0;break}await n.tick()}i&&await this.orderEntitiesAsync({tracker:n})}getUpstreamOngoingDependenciesVisits(p,i){const n=this.cachedReferences[p]||md(this.flatRecord[p],this.flatRecord,{ignoreBuiltInBaseEntities:!0,allBuiltInEntityIds:this.allBuiltInEntityIds});this.cachedReferences[p]=n;const{upstream:s}=n,c={};return Object.entries(this.onGoingVisits[i]||{}).forEach(([e,y])=>{Object.keys(s).includes(e)&&(c[e]=y)}),c}getDownstreamOngoingDependenciesVisits(p,i){const n=Object.keys(this.onGoingVisits[i]||{}),s=new Set(n.flatMap(e=>{const y=this.cachedReferences[e]||md(this.flatRecord[e],this.flatRecord,{ignoreBuiltInBaseEntities:!0,allBuiltInEntityIds:this.allBuiltInEntityIds});return this.cachedReferences[e]=y,Object.keys(y.downstream)})),c={};return Array.from(s).forEach(e=>{e===p&&(c[e]=this.onGoingVisits[i][e])}),c}async settlePromises(p,i){const n=Object.values(p);n.length&&await Promise.all(n),Object.keys(p).forEach(s=>{delete this.onGoingVisits[i][s]})}visit(p){const i=this.order;for(const n of i)p(this.flatRecord[n],this.flatRecord);return this}reverseVisit(p){const i=this.order.slice().reverse();for(const n of i)p(this.flatRecord[n],this.flatRecord);return this}async visitAsync(p,i={}){const{parallelise:n}={parallelise:!0,...i},s=J.YieldTracker.from(i),c=this.order;if(!n){for(const y of c){const m=p(this.flatRecord[y],this.flatRecord);Vm(m)&&await m,await s.tick()}return this}const e=Math.random().toString(36).substring(7);this.onGoingVisits[e]={};for(const y of c){const m=this.getUpstreamOngoingDependenciesVisits(y,e);Object.keys(m).length&&await this.settlePromises(m,e);const v=p(this.flatRecord[y],this.flatRecord);Vm(v)&&(this.onGoingVisits[e][y]=v),await s.tick()}return await this.settlePromises(this.onGoingVisits[e],e),this.onGoingVisits[e]={},this}async reverseVisitAsync(p,i={}){const{parallelise:n}={parallelise:!0,...i},s=J.YieldTracker.from(i),c=this.order.slice().reverse();if(!n){for(const y of c){const m=p(this.flatRecord[y],this.flatRecord);Vm(m)&&await m,await s.tick()}return this}const e=Math.random().toString(36).substring(7);this.onGoingVisits[e]={};for(const y of c){const m=this.getDownstreamOngoingDependenciesVisits(y,e);Object.keys(m).length&&await this.settlePromises(m,e);const v=p(this.flatRecord[y],this.flatRecord);Vm(v)&&(this.onGoingVisits[e][y]=v),await s.tick()}return await this.settlePromises(this.onGoingVisits[e],e),this.onGoingVisits[e]={},this}}const bc={},xb={},zm={empty:!1,enrich:!0,mock:!1,ignoreCache:!1,onFetch:async()=>null,manuallyInit:!1};function dGe(o,p={enrich:!0,shallowErrors:!1},i){const n={enrich:!0,shallowErrors:!1,...p},{enrich:s,shallowErrors:c}=n,e=o.project,y=o.record,m=A1(o.project,{shallowErrors:c},i);m.instances[e.id]=m;const v=new Yn(e,{allBuiltInEntityIds:m.diggestedBuiltInBaseEntitiesIds}),E=new Set;y[e.id]=e,E.add(e.id);const b=M().toISOString();Object.values(y).forEach(P=>{!P||v.allBuiltInEntityIds.has(P.id)||E.add(P.id)}),v.order=Array.from(E),v.flatRecord=y,v.orderEntities();const w=s?m.addChangeSet(new Z(m,x.sessionAuthor,b,m,!0,"project-init-from-fetch-result")):null;return v.visit(P=>{if(P.id===m.id)return;const $=he(P,m);try{$.hydrateAncestors(),$.addSelfToProject(null);const L=md(P);Object.keys(L.downstream).forEach(j=>{const F=m.get(j);F&&F.hydrateAncestors()})}catch(L){if(c)J.Logger.error("Error hydrating ancestors: ",L);else throw L}}),s?(v.visit(P=>{if(P.id===m.id)return;const $=m.get(P.id);$&&$.afterAllChildrenInitialized(w)}),m.afterAllChildrenInitialized(w)):sf(m,b).forEach($=>{$.remove({ignoreUpstream:!0},null)}),m.instancesList.forEach(P=>{P.previousVersion=null}),m.initialized=!0,m.emit(zt.PROJECT_INITIALIZED,m,w),w==null||w.attemptAutoclose("project-init-from-fetch-result",m.id),m}async function _Ri(o,p={enrich:!0,shallowErrors:!1,yieldEvery:100},i){const n={enrich:!0,shallowErrors:!1,yieldEvery:100,...p},{enrich:s,shallowErrors:c,yieldEvery:e}=n,y=o.project,m=o.record,v=await g1(o.project,{shallowErrors:c,yieldEvery:e},i);v.instances[y.id]=v;const E=new Yn(void 0,{allBuiltInEntityIds:v.diggestedBuiltInBaseEntitiesIds});await E.flattenAsync(y,{yieldEvery:e}),await E.orderEntitiesAsync({yieldEvery:e});const b=new Set;m[y.id]=y,b.add(y.id);const w=M().toISOString();let P=0;for(const[j,F]of Object.entries(m))!F||E.allBuiltInEntityIds.has(F.id)||(b.add(F.id),++P%e===0&&await J.yieldToEventLoop());E.order=Array.from(b),E.flatRecord=m,await E.orderEntitiesAsync();const $=s?v.addChangeSet(new Z(v,x.sessionAuthor,w,v,!0,"project-init-from-fetch-result")):null;await E.visitAsync(j=>{if(j.id===v.id)return;const F=he(j,v);try{F.hydrateAncestors(),F.addSelfToProject(null);const q=md(j);Object.keys(q.downstream).forEach(X=>{const ae=v.get(X);ae&&ae.hydrateAncestors()})}catch(q){if(c)J.Logger.error("Error hydrating ancestors: ",q);else throw console.log("Error hydrating ancestors: ",q),q}},{yieldEvery:e}),s?(await E.visitAsync(j=>{if(j.id===v.id)return;const F=v.get(j.id);F&&F.afterAllChildrenInitialized($)},{yieldEvery:e}),v.afterAllChildrenInitialized($)):sf(v,w).forEach(F=>{F.remove({ignoreUpstream:!0},null)});let L=0;for(const j of v.instancesList)j.previousVersion=null,++L%e===0&&await J.yieldToEventLoop();return v.initialized=!0,v.emit(zt.PROJECT_INITIALIZED,v,$),$==null||$.attemptAutoclose("project-init-from-fetch-result",v.id),v}async function PRi(o,p=zm){const i={...zm,...p};if(i.empty)return{data:{project:{id:o.id,deletable:!0,editable:!0,type:d.Project,version:x.UUID.uuid(),createdAt:M().toISOString(),author:x.sessionAuthor,previousVersion:null,deleted:!1,name:null,description:null,projects:[],entities:[],operations:[],functions:[],variableDeclarations:[],variableInstances:[],functionCalls:[],conditions:[],loops:[],searches:[],events:[]},record:{}}};if(i.mock){const s={...Hx};return s.id=o.id,{data:{project:s,record:{}}}}return J.Logger.log("Fetching project from external API"),new Promise(async s=>{try{if(i.onFetch){const c=await i.onFetch(o.id);if(c){s({data:c});return}}else s({data:null})}catch(c){J.Logger.error("Error fetching project: ",c),s({data:null})}})}function A1(o,p={shallowErrors:!1},i){const n=new x(o,i);nGe(n),rGe(n),iGe(n),aGe(n),sGe(n),lGe(n),oGe(n);const s=p.allBuiltInIds??new Set([...n.getAllBuiltInIds(),...I1()]);return n.diggestedBuiltInBaseEntitiesIds=s,s.forEach(c=>{if(!n.builtInInstances[c]&&n.instances[c])n.builtInInstances[c]=n.instances[c],delete n.instances[c];else if(!n.builtInInstances[c]&&!p.shallowErrors)throw new Error(`Built in entity was not properly initialized: ${c}`)}),n.instances[n.id]=n,n}async function g1(o,p={shallowErrors:!1,yieldEvery:100},i){const n=new x(o,i);nGe(n),rGe(n),await J.yieldToEventLoop(),iGe(n),await J.yieldToEventLoop(),aGe(n),sGe(n),lGe(n),oGe(n),await J.yieldToEventLoop();const s=p.allBuiltInIds??new Set([...n.getAllBuiltInIds(),...await R1()]);if(n.diggestedBuiltInBaseEntitiesIds=s,s.has("change-bank-account-owner-function-return-statement-id"))throw new Error("Debug 3");let c=0;const{yieldEvery:e=100}=p;for(const y of s){if(!n.builtInInstances[y]&&n.instances[y])n.builtInInstances[y]=n.instances[y],delete n.instances[y];else if(!n.builtInInstances[y]&&!p.shallowErrors)throw new Error(`Built in entity was not properly initialized: ${y}`);++c%e===0&&await J.yieldToEventLoop()}return n.instances[n.id]=n,n}function sf(o,p){return o.instancesList.filter(n=>M(n.createdAt).isAfter(M(p)||!!n.previousVersion))}function VRi(o,{enrich:p,shallowErrors:i}={enrich:!0,shallowErrors:!1},n){const s=new Map,c=new Map;Object.keys(o.instances).forEach(b=>{if(o.diggestedBuiltInBaseEntitiesIds.has(b)){s.set(b,b),c.set(b,b);return}const w=o.get(b);if(!dx(w,{...o.instances,...o.builtInInstances}).every(j=>!o.diggestedBuiltInBaseEntitiesIds.has(j))){s.set(b,b),c.set(b,b);return}const L=x.UUID.uuid();s.set(b,L),c.set(L,b)});const e=M().toISOString(),y=o.toShallowJSON({seenEntityMaps:s});y.previousVersion=null,y.createdAt=e,y.version=x.UUID.uuid();const m=A1(y,{shallowErrors:i,allBuiltInIds:o.diggestedBuiltInBaseEntitiesIds},n);m.instances[m.id]=m;const v=p?m.addChangeSet(new Z(m,x.sessionAuthor,e,m,!0,"project-clone")):null,E=new Yn(o,{allBuiltInEntityIds:o.diggestedBuiltInBaseEntitiesIds});return E.visit(b=>{const w=b.toShallowJSON({seenEntityMaps:s});w.previousVersion=null,w.createdAt=e,w.version=x.UUID.uuid();const P=md(w,ex(E.flatRecord,s));if(Object.keys(P.upstream).length){let L=!1;if(Object.keys(P.upstream).forEach(j=>{if(!L&&(!m.get(j)||m.getDeleted(j))){L=!0;return}}),L)return}const $=he(w,m);$.hydrateAncestors(),$.addSelfToProject(v),v==null||v.add($,H.Added)}),p?(E.visit(b=>{if(b.id===m.id)return;const w=m.get(s.get(b.id));w&&w.afterAllChildrenInitialized(v)}),m.afterAllChildrenInitialized(v)):sf(m,e).forEach(w=>{w.remove({ignoreUpstream:!0},null)}),m.instancesList.forEach(b=>{b.previousVersion=null}),v==null||v.attemptAutoclose("project-clone",m.id),m}async function NRi(o,{enrich:p,shallowErrors:i,...n}={enrich:!0,shallowErrors:!1,yieldEvery:100},s){const c=new Map,e=new Map,{yieldEvery:y=100}=n;Object.keys(o.instances).forEach($=>{if(o.diggestedBuiltInBaseEntitiesIds.has($)){c.set($,$),e.set($,$);return}const L=x.UUID.uuid();c.set($,L),e.set(L,$)});const m=M().toISOString(),v=o.toShallowJSON({seenEntityMaps:c});v.previousVersion=null,v.createdAt=m,v.version=x.UUID.uuid();const E=await g1(v,{shallowErrors:i,yieldEvery:y},s);E.diggestedBuiltInBaseEntitiesIds=o.diggestedBuiltInBaseEntitiesIds,E.instances[E.id]=E;const b=p?E.addChangeSet(new Z(E,x.sessionAuthor,m,E,!0,"project-clone")):null,w=new Yn(void 0,{allBuiltInEntityIds:o.diggestedBuiltInBaseEntitiesIds});await w.flattenAsync(o,{yieldEvery:y}),await w.orderEntitiesAsync({yieldEvery:y}),await w.visitAsync($=>{const L=$.toShallowJSON({seenEntityMaps:c});L.previousVersion=null,L.createdAt=m,L.version=x.UUID.uuid();const j=md(L,ex(w.flatRecord,c));if(Object.keys(j.upstream).length){let q=!1;if(Object.keys(j.upstream).forEach(X=>{if(!q&&(!E.get(X)||E.getDeleted(X))){q=!0;return}}),q)return}const F=he(L,E);F.hydrateAncestors(),F.addSelfToProject(b),b==null||b.add(F,H.Added)},{yieldEvery:y}),p?(await w.visitAsync($=>{if($.id===E.id)return;const L=E.get(c.get($.id));L&&L.afterAllChildrenInitialized(b)},{yieldEvery:y}),E.afterAllChildrenInitialized(b)):sf(E,m).forEach(L=>{L.remove({ignoreUpstream:!0},null)});let P=0;for(const $ of E.instancesList)$.previousVersion=null,++P%y===0&&await J.yieldToEventLoop();return b==null||b.attemptAutoclose("project-clone",E.id),E}function uGe(o,{enrich:p,shallowErrors:i}={enrich:!0,shallowErrors:!1},n){const s=A1(o,{shallowErrors:i},n),c=M().toISOString(),e=p?s.addChangeSet(new Z(s,x.sessionAuthor,c,s,!0,"project-init")):null;e&&(e.type=BI.Automatic);const y=new Yn(o,{allBuiltInEntityIds:s.diggestedBuiltInBaseEntitiesIds});return y.visit(m=>{const v=he(m,s);v.hydrateAncestors(),v.addSelfToProject(e)}),p?(y.visit(m=>{if(m.id===s.id)return;const v=s.get(m.id);v&&v.afterAllChildrenInitialized(e)}),s.afterAllChildrenInitialized(e)):(sf(s,c).forEach(E=>{E.remove({ignoreUpstream:!0},null)}),new Yn(s,{allBuiltInEntityIds:s.diggestedBuiltInBaseEntitiesIds}).visit(E=>{E.initialized=!0,E.captureVersion()})),s.initialized=!0,s.emit(zt.PROJECT_INITIALIZED,s,e),e==null||e.attemptAutoclose("project-init",s.id),s}async function xRi(o,{enrich:p,shallowErrors:i,yieldEvery:n}={enrich:!0,shallowErrors:!1,yieldEvery:100},s){const c=await g1(o,{shallowErrors:i,yieldEvery:n},s),e=M().toISOString(),y=p?c.addChangeSet(new Z(c,x.sessionAuthor,e,c,!0,"project-init")):null;y&&(y.type=BI.Automatic);const m=new Yn(void 0,{allBuiltInEntityIds:c.diggestedBuiltInBaseEntitiesIds});if(await m.flattenAsync(o,{yieldEvery:n}),await m.orderEntitiesAsync({yieldEvery:n}),await m.visitAsync(v=>{const E=he(v,c);E.hydrateAncestors(),E.addSelfToProject(y)},{yieldEvery:n}),p)await m.visitAsync(v=>{if(v.id===c.id)return;const E=c.get(v.id);E&&E.afterAllChildrenInitialized(y)},{yieldEvery:n}),c.afterAllChildrenInitialized(y);else{sf(c,e).forEach(b=>{b.remove({ignoreUpstream:!0},null)});const E=new Yn(void 0,{allBuiltInEntityIds:c.diggestedBuiltInBaseEntitiesIds});await E.flattenAsync(c,{yieldEvery:n}),await E.orderEntitiesAsync({yieldEvery:n}),await E.visitAsync(b=>{b.initialized=!0,b.captureVersion()},{yieldEvery:n})}return c.initialized=!0,c.emit(zt.PROJECT_INITIALIZED,c,y),y==null||y.attemptAutoclose("project-init",c.id),c}async function $Ri(o,p=zm,i){const n={...zm,...p};if(o.id&&bc[o.id]&&!n.ignoreCache)return bc[o.id];if(o.id&&xb[o.id]&&!n.ignoreCache)return await xb[o.id],bc[o.id];const s=PRi(o,n);o.id&&(xb[o.id]=s);const c=await s;if(c.data){let e;return n.mock?e=uGe(Hx,{enrich:!!n.enrich},i):c.data instanceof x?e=c.data:e=dGe(c.data,{enrich:!!n.enrich},i),bc[o.id]=e,o.id&&delete xb[o.id],e}return null}function LRi(o){return bc[o.id]&&delete bc[o.id],null}function zN(o){return o==null||o===""}function _r(o){return o?o.valueAsType?!1:zN(o.value):!0}function pGe(o,p){if(o===p||!o&&!p)return!0;if(!o||!p||o.name===le.EntityTemplate&&p.name!==le.EntityTemplate||p.name===le.EntityTemplate&&o.name!==le.EntityTemplate)return!1;if(o.name===le.ActionDescriptor&&p.name!==le.ActionDescriptor||p.name===le.ActionDescriptor&&o.name!==le.ActionDescriptor)return!1;if(o.valueAsTypeSingle&&!p.valueAsTypeSingle||p.valueAsTypeSingle&&!o.valueAsTypeSingle)return!1;if(o.valueAsTypeList&&!p.valueAsTypeList||p.valueAsTypeList&&!o.valueAsTypeList)return!1;if(o.valueAsTypeSingle&&p.valueAsTypeSingle){if(o.valueAsTypeSingle.id!==p.valueAsTypeSingle.id)return!1}else if(o.valueAsTypeList&&p.valueAsTypeList){if(o.valueAsTypeList.length!==p.valueAsTypeList.length)return!1;for(let i=0;i<o.valueAsTypeList.length;i++)if(o.valueAsTypeList[i].id!==p.valueAsTypeList[i].id)return!1}else if(!o.valueAsType&&!p.valueAsType&&o.value!==p.value)return!1;return!0}function I1(){const o=new Set;return new Set(hV.flatMap(i=>Le(i,o)).map(i=>i.id))}function eo(o){return[...o.calledByEntry||[],...o.calledByError||[],...o.calledBySuccess||[]].filter(p=>p.type!==d.GenericReference)}function cGe(o,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(o.id))return[];if(p.add(o.id),o.type!==d.ActionDescriptor)throw new Error("Entity must be an action descriptor to be flattened");return[o,...o.inputs.flatMap(n=>Le(n,p,i)),...o.dataType?Le(o.dataType,p,i):[],...o.error?Le(o.error,p,i):[],...o.parent?Le(o.parent,p,i):[]]}function fGe(o,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(o.id))return[];if(p.add(o.id),o.type!==d.ArgumentDeclaration)throw new Error("Entity must be an argument declaration to be flattened");return[o,...o.defaultValue?Le(o.defaultValue,p):[],...o.writesValues.flatMap(n=>Le(n,p,i)),...o.implements.flatMap(n=>Le(n,p,i)),...o.dataType?Le(o.dataType,p,i):[],...o.parent?Le(o.parent,p,i):[]]}function yGe(o,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(o.id))return[];if(p.add(o.id),o.type!==d.BreakStatement)throw new Error("Entity must be a break statement to be flattened");return[o,...o.outputs.flatMap(n=>Le(n,p,i)),...o.throws?Le(o.throws,p,i):[],...o.dataType?Le(o.dataType,p,i):[],...o.readsValue?Le(o.readsValue,p,i):[],...(eo(o)||[]).flatMap(n=>Le(n,p,i)),...o.parent?Le(o.parent,p,i):[]]}function hGe(o,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(o.id))return[];if(p.add(o.id),o.type!==d.BuiltInBaseEntity)throw new Error("Entity must be a built-in base entity to be flattened");return[o,...(o.properties||[]).flatMap(n=>Le(n,p,i)),...(o.methods||[]).flatMap(n=>Le(n,p,i)),...(o.abstractMethods||[]).flatMap(n=>Le(n,p,i)),...o.allPropertiesImplement?Le(o.allPropertiesImplement,p,i):[],...o.additionalPropertiesDataType?Le(o.additionalPropertiesDataType,p,i):[],...o.extends?Le(o.extends,p,i):[]]}function mGe(o,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(o.id))return[];if(p.add(o.id),o.type!==d.Condition)throw new Error("Entity must be a condition to be flattened");return[o,...(o.andChildrenGroup||[]).flatMap(n=>Le(n,p,i)),...(o.orChildrenGroup||[]).flatMap(n=>Le(n,p,i)),...(o.inputs||[]).flatMap(n=>Le(n,p,i)),...(o.successCalls||[]).flatMap(n=>Le(n,p,i)),...(o.errorCalls||[]).flatMap(n=>Le(n,p,i)),...(eo(o)||[]).flatMap(n=>Le(n,p,i)),...o.parent?Le(o.parent,p,i):[]]}function TGe(o,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(o.id))return[];if(p.add(o.id),o.type!==d.ContinueStatement)throw new Error("Entity must be a continue statement to be flattened");return[o,...o.outputs.flatMap(n=>Le(n,p,i)),...o.readsValue?Le(o.readsValue,p,i):[],...o.throws?Le(o.throws,p,i):[],...o.dataType?Le(o.dataType,p,i):[],...(eo(o)||[]).flatMap(n=>Le(n,p,i)),...o.parent?Le(o.parent,p,i):[]]}function vGe(o,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(o.id))return[];if(p.add(o.id),o.type!==d.DefinitionEntity)throw new Error("Entity must be a definition entity to be flattened");return[o,...o.extends?Le(o.extends,p,i):[],...(o.implements||[]).flatMap(n=>Le(n,p,i)),...(o.properties||[]).flatMap(n=>Le(n,p,i)),...(o.methods||[]).flatMap(n=>Le(n,p,i)),...(o.abstractMethods||[]).flatMap(n=>Le(n,p,i)),...o.allPropertiesImplement?Le(o.allPropertiesImplement,p,i):[],...o.additionalPropertiesDataType?Le(o.additionalPropertiesDataType,p,i):[],...o.parent?Le(o.parent,p,i):[]]}function EGe(o,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(o.id))return[];if(p.add(o.id),o.type!==d.DataType)throw new Error("Entity must be a data type to be flattened");return[o,...(o.andChildrenGroup||[]).flatMap(n=>Le(n,p,i)),...(o.orChildrenGroup||[]).flatMap(n=>Le(n,p,i)),...o.entity?Le(o.entity,p,i):[],...o.foreignKeyRef?Le(o.foreignKeyRef,p,i):[],...o.parent?Le(o.parent,p,i):[]]}function bGe(o,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(o.id))return[];if(p.add(o.id),o.type!==d.FunctionCall)throw new Error("Entity must be a function call to be flattened");return[o,...(o.inputs||[]).flatMap(n=>Le(n,p,i)),...(o.outputs||[]).flatMap(n=>Le(n,p,i)),...o.error?Le(o.error,p,i):[],...(eo(o)||[]).flatMap(n=>Le(n,p,i)),...(o.successCalls||[]).flatMap(n=>Le(n,p,i)),...(o.errorCalls||[]).flatMap(n=>Le(n,p,i)),...(o.writesValues||[]).flatMap(n=>Le(n,p,i)),...o.parent?Le(o.parent,p,i):[]]}function AGe(o,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(o.id))return[];if(p.add(o.id),o.type!==d.FunctionDeclaration)throw new Error("Entity must be a function declaration to be flattened");return[o,...(o.inputs||[]).flatMap(n=>Le(n,p,i)),...(o.calls||[]).flatMap(n=>Le(n,p,i)),...o.dataType?Le(o.dataType,p,i):[],...o.implements?Le(o.implements,p,i):[],...o.parent?Le(o.parent,p,i):[]]}function gGe(o,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(o.id))return[];if(p.add(o.id),o.type!==d.GlobalEvent)throw new Error("Entity must be a global event to be flattened");return[o,...(o.inputs||[]).flatMap(n=>Le(n,p,i)),...(o.calls||[]).flatMap(n=>Le(n,p,i)),...o.implements?Le(o.implements,p,i):[],...o.parent?Le(o.parent,p,i):[]]}function IGe(o,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(o.id))return[];if(p.add(o.id),o.type!==d.InputMap)throw new Error("Entity must be an input map to be flattened");return[o,...o.readsValue?Le(o.readsValue,p,i):[],...o.declaration?Le(o.declaration,p,i):[],...o.defaultValue?Le(o.defaultValue,p,i):[],...o.parent?Le(o.parent,p,i):[]]}function RGe(o,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(o.id))return[];if(p.add(o.id),o.type!==d.InstalledProject)throw new Error("Entity must be an installed project to be flattened");return[o,...(o.functions||[]).flatMap(n=>Le(n,p,i)),...(o.events||[]).flatMap(n=>Le(n,p,i)),...o.parent?Le(o.parent,p,i):[]]}function DGe(o,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(o.id))return[];if(p.add(o.id),o.type!==d.InternalCall)throw new Error("Entity must be an internal call to be flattened");return[o,...(o.successCalls||[]).flatMap(n=>Le(n,p,i)),...(o.errorCalls||[]).flatMap(n=>Le(n,p,i)),...(o.inputs||[]).flatMap(n=>Le(n,p,i)),...(o.outputs||[]).flatMap(n=>Le(n,p,i)),...(eo(o)||[]).flatMap(n=>Le(n,p,i)),...o.error?Le(o.error,p,i):[],...(o.writesValues||[]).flatMap(n=>Le(n,p,i)),...o.parent?Le(o.parent,p,i):[]]}function wGe(o,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(o.id))return[];if(p.add(o.id),o.type!==d.LiteralValue)throw new Error("Entity must be a literal value to be flattened");return[o,...o.valueAsTypeSingle?Le(o.valueAsTypeSingle,p,i):[],...o.valueAsTypeList&&Array.isArray(o.valueAsTypeList)?o.valueAsTypeList.flatMap(n=>Le(n,p,i)):[],...o.parent?Le(o.parent,p,i):[]]}function OGe(o,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(o.id))return[];if(p.add(o.id),o.type!==d.Loop)throw new Error("Entity must be a loop to be flattened");return[o,...(o.inputs||[]).flatMap(n=>Le(n,p,i)),...(o.outputs||[]).flatMap(n=>Le(n,p,i)),...(o.successCalls||[]).flatMap(n=>Le(n,p,i)),...(o.errorCalls||[]).flatMap(n=>Le(n,p,i)),...o.error?Le(o.error,p,i):[],...o.dataType?Le(o.dataType,p,i):[],...o.body?Le(o.body,p,i):[],...(eo(o)||[]).flatMap(n=>Le(n,p,i)),...(o.writesValues||[]).flatMap(n=>Le(n,p,i)),...o.parent?Le(o.parent,p,i):[]]}function CGe(o,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(o.id))return[];if(p.add(o.id),o.type!==d.Operation)throw new Error("Entity must be an operation to be flattened");return[o,...(o.successCalls||[]).flatMap(n=>Le(n,p,i)),...(o.errorCalls||[]).flatMap(n=>Le(n,p,i)),...(o.inputs||[]).flatMap(n=>Le(n,p,i)),...(o.outputs||[]).flatMap(n=>Le(n,p,i)),...(o.writesValues||[]).flatMap(n=>Le(n,p,i)),...o.error?Le(o.error,p,i):[],...(eo(o)||[]).flatMap(n=>Le(n,p,i)),...o.parent?Le(o.parent,p,i):[]]}function _Ge(o,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(o.id))return[];if(p.add(o.id),o.type!==d.OutputMap)throw new Error("Entity must be an output map to be flattened");return[o,...(o.writesValues||[]).flatMap(n=>Le(n,p,i)),...o.declaration?Le(o.declaration,p,i):[],...o.parent?Le(o.parent,p,i):[]]}function PGe(o,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(o.id))return[];if(p.add(o.id),o.type!==d.PrimitiveEntity)throw new Error("Entity must be a primitive entity to be flattened");return[o,...(o.properties||[]).flatMap(n=>Le(n,p,i)),...(o.methods||[]).flatMap(n=>Le(n,p,i)),...(o.abstractMethods||[]).flatMap(n=>Le(n,p,i))]}function VGe(o,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(o.id))return[];if(p.add(o.id),o.type!==d.Project)throw new Error("Entity must be a project to be flattened");return[o,...(o.entities||[]).flatMap(n=>Le(n,p,i)),...(o.functions||[]).flatMap(n=>Le(n,p,i)),...(o.events||[]).flatMap(n=>Le(n,p,i)),...(o.projects||[]).flatMap(n=>Le(n,p,i)),...(o.variableDeclarations||[]).flatMap(n=>Le(n,p,i)),...(o.variableInstances||[]).flatMap(n=>Le(n,p,i)),...(o.operations||[]).flatMap(n=>Le(n,p,i)),...(o.conditions||[]).flatMap(n=>Le(n,p,i)),...(o.functionCalls||[]).flatMap(n=>Le(n,p,i)),...(o.projects||[]).flatMap(n=>Le(n,p,i)),...(o.loops||[]).flatMap(n=>Le(n,p,i)),...(o.searches||[]).flatMap(n=>Le(n,p,i))]}function NGe(o,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(o.id))return[];if(p.add(o.id),o.type!==d.Property)throw new Error("Entity must be a property to be flattened");return[o,...o.defaultValue?Le(o.defaultValue,p,i):[],...o.dataType?Le(o.dataType,p,i):[],...o.parent?Le(o.parent,p,i):[]]}function xGe(o,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(o.id))return[];if(p.add(o.id),o.type!==d.ReturnStatement)throw new Error("Entity must be a return statement to be flattened");return[o,...(o.outputs||[]).flatMap(n=>Le(n,p,i)),...o.throws?Le(o.throws,p,i):[],...o.readsValue?Le(o.readsValue,p,i):[],...o.dataType?Le(o.dataType,p,i):[],...(eo(o)||[]).flatMap(n=>Le(n,p,i)),...o.parent?Le(o.parent,p,i):[]]}function $Ge(o,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(o.id))return[];if(p.add(o.id),o.type!==d.Search)throw new Error("Entity must be a search to be flattened");return[o,...(o.successCalls||[]).flatMap(n=>Le(n,p,i)),...(o.errorCalls||[]).flatMap(n=>Le(n,p,i)),...(o.inputsDeclarations||[]).flatMap(n=>Le(n,p,i)),...(o.inputs||[]).flatMap(n=>Le(n,p,i)),...(o.writesValues||[]).flatMap(n=>Le(n,p,i)),...(o.outputs||[]).flatMap(n=>Le(n,p,i)),...o.error?Le(o.error,p,i):[],...o.dataType?Le(o.dataType,p,i):[],...(eo(o)||[]).flatMap(n=>Le(n,p,i)),...o.parent?Le(o.parent,p,i):[]]}function LGe(o,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(o.id))return[];if(p.add(o.id),o.type!==d.ValueDescriptor)throw new Error("Entity must be a value descriptor to be flattened");return[o,...o.defaultValue?Le(o.defaultValue,p,i):[],...o.dataType?Le(o.dataType,p,i):[],...o.parent?Le(o.parent,p,i):[]]}function MGe(o,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(o.id))return[];if(p.add(o.id),o.type!==d.VariableDeclaration)throw new Error("Entity must be a variable declaration to be flattened");return[o,...(o.successCalls||[]).flatMap(n=>Le(n,p,i)),...(o.errorCalls||[]).flatMap(n=>Le(n,p,i)),...(o.inputs||[]).flatMap(n=>Le(n,p,i)),...(o.outputs||[]).flatMap(n=>Le(n,p,i)),...(o.internalCalls||[]).flatMap(n=>Le(n,p,i)),...(o.writesValues||[]).flatMap(n=>Le(n,p,i)),...o.readsValue?Le(o.readsValue,p,i):[],...o.defaultValue?Le(o.defaultValue,p,i):[],...(eo(o)||[]).flatMap(n=>Le(n,p,i)),...o.dataType?Le(o.dataType,p,i):[],...o.parent?Le(o.parent,p,i):[]]}function BGe(o,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(o.id))return[];if(p.add(o.id),o.type!==d.VariableInstance)throw new Error("Entity must be a variable instance to be flattened");return[o,...(o.successCalls||[]).flatMap(n=>Le(n,p,i)),...(o.errorCalls||[]).flatMap(n=>Le(n,p,i)),...(o.inputs||[]).flatMap(n=>Le(n,p,i)),...(o.outputs||[]).flatMap(n=>Le(n,p,i)),...(o.internalCalls||[]).flatMap(n=>Le(n,p,i)),...(o.writesValues||[]).flatMap(n=>Le(n,p,i)),...o.readsValue?Le(o.readsValue,p,i):[],...o.defaultValue?Le(o.defaultValue,p,i):[],...(eo(o)||[]).flatMap(n=>Le(n,p,i)),...o.declaration?Le(o.declaration,p,i):[],...o.parent?Le(o.parent,p,i):[]]}function Le(o,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(!o)throw new Error("Entity must be defined to be flattened");if(o.type===d.GenericReference)return[];const n=i.ignoreBuiltInBaseEntities?i.diggestedBuiltInBaseEntitiesIds??new Set(I1()):new Set;if(i.diggestedBuiltInBaseEntitiesIds=n,i.ignoreBuiltInBaseEntities&&(Hn.includes(o.type)||n.has(o.id)))return[];if(p.has(o.id))return[];switch(o.type){case d.FunctionCall:return bGe(o,p,i);case d.Operation:return CGe(o,p,i);case d.Condition:return mGe(o,p,i);case d.Loop:return OGe(o,p,i);case d.Search:return $Ge(o,p,i);case d.GlobalEvent:return gGe(o,p,i);case d.ReturnStatement:return xGe(o,p,i);case d.ContinueStatement:return TGe(o,p,i);case d.BreakStatement:return yGe(o,p,i);case d.VariableDeclaration:return MGe(o,p,i);case d.DefinitionEntity:return vGe(o,p,i);case d.FunctionDeclaration:return AGe(o,p,i);case d.Project:return VGe(o,p,i);case d.ActionDescriptor:return cGe(o,p,i);case d.ArgumentDeclaration:return fGe(o,p,i);case d.ValueDescriptor:return LGe(o,p,i);case d.InputMap:return IGe(o,p,i);case d.OutputMap:return _Ge(o,p,i);case d.DataType:return EGe(o,p,i);case d.InstalledProject:return RGe(o,p,i);case d.InternalCall:return DGe(o,p,i);case d.LiteralValue:return wGe(o,p,i);case d.Property:return NGe(o,p,i);case d.VariableInstance:return BGe(o,p,i);case d.BuiltInBaseEntity:return i.ignoreBuiltInBaseEntities?[]:hGe(o,p,i);case d.PrimitiveEntity:return i.ignoreBuiltInBaseEntities?[]:PGe(o,p,i)}return[]}async function R1(o={}){const p=new Set,i=J.YieldTracker.from(o),n=new Set;for(const s of hV){const c=await $e(s,p,{ignoreBuiltInBaseEntities:!1,tracker:i});for(const e of c)n.add(e.id),await i.tick()}return n}function to(o){return[...o.calledByEntry||[],...o.calledByError||[],...o.calledBySuccess||[]].filter(p=>p.type!==d.GenericReference)}async function GGe(o,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(o.id))return[];if(p.add(o.id),o.type!==d.ActionDescriptor)throw new Error("Entity must be an action descriptor to be flattened");const n=J.YieldTracker.from(i),s=[o];await n.tick();const c={...i,tracker:n};delete c.yieldEvery;for(const e of o.inputs)s.push(...await $e(e,p,c));return o.dataType&&s.push(...await $e(o.dataType,p,c)),o.error&&s.push(...await $e(o.error,p,c)),o.parent&&s.push(...await $e(o.parent,p,c)),s}async function kGe(o,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(o.id))return[];if(p.add(o.id),o.type!==d.ArgumentDeclaration)throw new Error("Entity must be an argument declaration to be flattened");const n=J.YieldTracker.from(i),s=[o];await n.tick();const c={...i,tracker:n};delete c.yieldEvery,o.dataType&&s.push(...await $e(o.dataType,p,c)),o.parent&&s.push(...await $e(o.parent,p,c)),o.defaultValue&&s.push(...await $e(o.defaultValue,p,c));for(const e of o.writesValues||[])s.push(...await $e(e,p,c));for(const e of o.implements||[])s.push(...await $e(e,p,c));return s}async function jGe(o,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(o.id))return[];if(p.add(o.id),o.type!==d.BreakStatement)throw new Error("Entity must be a break statement to be flattened");const n=J.YieldTracker.from(i),s=[o];await n.tick();const c={...i,tracker:n};delete c.yieldEvery;for(const y of o.outputs)s.push(...await $e(y,p,c));o.parent&&s.push(...await $e(o.parent,p,c)),o.throws&&s.push(...await $e(o.throws,p,c)),o.dataType&&s.push(...await $e(o.dataType,p,c)),o.readsValue&&s.push(...await $e(o.readsValue,p,c));const e=to(o);for(const y of e)s.push(...await $e(y,p,c));return s}async function UGe(o,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(o.id))return[];if(p.add(o.id),o.type!==d.BuiltInBaseEntity)throw new Error("Entity must be a built-in base entity to be flattened");const n=J.YieldTracker.from(i),s=[o];await n.tick();const c={...i,tracker:n};delete c.yieldEvery;for(const e of o.properties||[])s.push(...await $e(e,p,c));for(const e of o.methods||[])s.push(...await $e(e,p,c));for(const e of o.abstractMethods||[])s.push(...await $e(e,p,c));return o.allPropertiesImplement&&s.push(...await $e(o.allPropertiesImplement,p,c)),o.additionalPropertiesDataType&&s.push(...await $e(o.additionalPropertiesDataType,p,c)),o.extends&&s.push(...await $e(o.extends,p,c)),s}async function KGe(o,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(o.id))return[];if(p.add(o.id),o.type!==d.Condition)throw new Error("Entity must be a condition to be flattened");const n=J.YieldTracker.from(i),s=[o];await n.tick();const c={...i,tracker:n};if(delete c.yieldEvery,o.andChildrenGroup&&Array.isArray(o.andChildrenGroup))for(const y of o.andChildrenGroup)s.push(...await $e(y,p,c));if(o.orChildrenGroup&&Array.isArray(o.orChildrenGroup))for(const y of o.orChildrenGroup)s.push(...await $e(y,p,c));for(const y of o.inputs)s.push(...await $e(y,p,c));for(const y of o.successCalls)s.push(...await $e(y,p,c));for(const y of o.errorCalls)s.push(...await $e(y,p,c));const e=to(o);for(const y of e)s.push(...await $e(y,p,c));return o.parent&&s.push(...await $e(o.parent,p,c)),s}async function FGe(o,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(o.id))return[];if(p.add(o.id),o.type!==d.ContinueStatement)throw new Error("Entity must be a continue statement to be flattened");const n=J.YieldTracker.from(i),s=[o];await n.tick();const c={...i,tracker:n};delete c.yieldEvery;for(const y of o.outputs)s.push(...await $e(y,p,c));const e=to(o);for(const y of e)s.push(...await $e(y,p,c));return o.parent&&s.push(...await $e(o.parent,p,c)),o.throws&&s.push(...await $e(o.throws,p,c)),o.dataType&&s.push(...await $e(o.dataType,p,c)),o.readsValue&&s.push(...await $e(o.readsValue,p,c)),s}async function SGe(o,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(o.id))return[];if(p.add(o.id),o.type!==d.DefinitionEntity)throw new Error("Entity must be a definition entity to be flattened");const n=J.YieldTracker.from(i),s=[o];await n.tick();const c={...i,tracker:n};delete c.yieldEvery;for(const e of o.properties)s.push(...await $e(e,p,c));for(const e of o.methods)s.push(...await $e(e,p,c));for(const e of o.abstractMethods)s.push(...await $e(e,p,c));for(const e of o.implements)s.push(...await $e(e,p,c));return o.extends&&s.push(...await $e(o.extends,p,c)),o.parent&&s.push(...await $e(o.parent,p,c)),o.additionalPropertiesDataType&&s.push(...await $e(o.additionalPropertiesDataType,p,c)),o.allPropertiesImplement&&s.push(...await $e(o.allPropertiesImplement,p,c)),s}async function qGe(o,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(o.id))return[];if(p.add(o.id),o.type!==d.DataType)throw new Error("Entity must be a data type to be flattened");const n=J.YieldTracker.from(i),s=[o];await n.tick();const c={...i,tracker:n};if(delete c.yieldEvery,o.parent&&s.push(...await $e(o.parent,p,c)),o.foreignKeyRef&&s.push(...await $e(o.foreignKeyRef,p,c)),o.entity&&s.push(...await $e(o.entity,p,c)),o.orChildrenGroup)for(const e of o.orChildrenGroup)s.push(...await $e(e,p,c));if(o.andChildrenGroup)for(const e of o.andChildrenGroup)s.push(...await $e(e,p,c));return s}async function ZGe(o,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(o.id))return[];if(p.add(o.id),o.type!==d.FunctionCall)throw new Error("Entity must be a function call to be flattened");const n=J.YieldTracker.from(i),s=[o];await n.tick();const c={...i,tracker:n};delete c.yieldEvery;for(const y of o.inputs)s.push(...await $e(y,p,c));for(const y of o.outputs)s.push(...await $e(y,p,c));o.error&&s.push(...await $e(o.error,p,c));const e=to(o);for(const y of e)s.push(...await $e(y,p,c));for(const y of o.successCalls)s.push(...await $e(y,p,c));for(const y of o.errorCalls)s.push(...await $e(y,p,c));for(const y of o.writesValues)s.push(...await $e(y,p,c));return o.parent&&s.push(...await $e(o.parent,p,c)),s}async function HGe(o,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(o.id))return[];if(p.add(o.id),o.type!==d.FunctionDeclaration)throw new Error("Entity must be a function declaration to be flattened");const n=J.YieldTracker.from(i),s=[o];await n.tick();const c={...i,tracker:n};delete c.yieldEvery,o.parent&&s.push(...await $e(o.parent,p,c)),o.implements&&s.push(...await $e(o.implements,p,c)),o.dataType&&s.push(...await $e(o.dataType,p,c));for(const e of o.inputs)s.push(...await $e(e,p,c));for(const e of o.calls)s.push(...await $e(e,p,c));return s}async function WGe(o,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(o.id))return[];if(p.add(o.id),o.type!==d.GlobalEvent)throw new Error("Entity must be a global event to be flattened");const n=J.YieldTracker.from(i),s=[o];await n.tick();const c={...i,tracker:n};delete c.yieldEvery,o.parent&&s.push(...await $e(o.parent,p,c)),o.implements&&s.push(...await $e(o.implements,p,c));for(const e of o.inputs)s.push(...await $e(e,p,c));for(const e of o.calls)s.push(...await $e(e,p,c));return s}async function zGe(o,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(o.id))return[];if(p.add(o.id),o.type!==d.InputMap)throw new Error("Entity must be an input map to be flattened");const n=J.YieldTracker.from(i),s=[o];await n.tick();const c={...i,tracker:n};return delete c.yieldEvery,o.parent&&s.push(...await $e(o.parent,p,c)),o.declaration&&s.push(...await $e(o.declaration,p,c)),o.readsValue&&s.push(...await $e(o.readsValue,p,c)),o.defaultValue&&s.push(...await $e(o.defaultValue,p,c)),s}async function JGe(o,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(o.id))return[];if(p.add(o.id),o.type!==d.InstalledProject)throw new Error("Entity must be an installed project to be flattened");const n=J.YieldTracker.from(i),s=[o];await n.tick();const c={...i,tracker:n};delete c.yieldEvery;for(const e of o.functions)s.push(...await $e(e,p,c));for(const e of o.events)s.push(...await $e(e,p,c));return o.parent&&s.push(...await $e(o.parent,p,c)),s}async function YGe(o,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(o.id))return[];if(p.add(o.id),o.type!==d.InternalCall)throw new Error("Entity must be an internal call to be flattened");const n=J.YieldTracker.from(i),s=[o];await n.tick();const c={...i,tracker:n};delete c.yieldEvery;for(const y of o.inputs)s.push(...await $e(y,p,c));for(const y of o.outputs)s.push(...await $e(y,p,c));o.error&&s.push(...await $e(o.error,p,c));const e=to(o);for(const y of e)s.push(...await $e(y,p,c));for(const y of o.successCalls)s.push(...await $e(y,p,c));for(const y of o.errorCalls)s.push(...await $e(y,p,c));for(const y of o.writesValues)s.push(...await $e(y,p,c));return o.parent&&s.push(...await $e(o.parent,p,c)),s}async function XGe(o,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(o.id))return[];if(p.add(o.id),o.type!==d.LiteralValue)throw new Error("Entity must be a literal value to be flattened");const n=J.YieldTracker.from(i),s=[o];await n.tick();const c={...i,tracker:n};if(delete c.yieldEvery,o.valueAsTypeSingle&&s.push(...await $e(o.valueAsTypeSingle,p,c)),o.valueAsTypeList&&Array.isArray(o.valueAsTypeList))for(const e of o.valueAsTypeList)s.push(...await $e(e,p,c));return o.parent&&s.push(...await $e(o.parent,p,c)),s}async function QGe(o,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(o.id))return[];if(p.add(o.id),o.type!==d.Loop)throw new Error("Entity must be a loop to be flattened");const n=J.YieldTracker.from(i),s=[o];await n.tick();const c={...i,tracker:n};delete c.yieldEvery;for(const y of o.inputs)s.push(...await $e(y,p,c));for(const y of o.outputs)s.push(...await $e(y,p,c));o.error&&s.push(...await $e(o.error,p,c));const e=to(o);for(const y of e)s.push(...await $e(y,p,c));for(const y of o.successCalls)s.push(...await $e(y,p,c));for(const y of o.errorCalls)s.push(...await $e(y,p,c));for(const y of o.writesValues)s.push(...await $e(y,p,c));return o.parent&&s.push(...await $e(o.parent,p,c)),o.body&&s.push(...await $e(o.body,p,c)),o.dataType&&s.push(...await $e(o.dataType,p,c)),s}async function e4e(o,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(o.id))return[];if(p.add(o.id),o.type!==d.Operation)throw new Error("Entity must be an operation to be flattened");const n=J.YieldTracker.from(i),s=[o];await n.tick();const c={...i,tracker:n};delete c.yieldEvery;for(const y of o.inputs)s.push(...await $e(y,p,c));for(const y of o.outputs)s.push(...await $e(y,p,c));o.error&&s.push(...await $e(o.error,p,c));const e=to(o);for(const y of e)s.push(...await $e(y,p,c));for(const y of o.successCalls)s.push(...await $e(y,p,c));for(const y of o.errorCalls)s.push(...await $e(y,p,c));for(const y of o.writesValues)s.push(...await $e(y,p,c));return o.parent&&s.push(...await $e(o.parent,p,c)),s}async function t4e(o,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(o.id))return[];if(p.add(o.id),o.type!==d.OutputMap)throw new Error("Entity must be an output map to be flattened");const n=J.YieldTracker.from(i),s=[o];await n.tick();const c={...i,tracker:n};delete c.yieldEvery;for(const e of o.writesValues)s.push(...await $e(e,p,c));return o.declaration&&s.push(...await $e(o.declaration,p,c)),o.parent&&s.push(...await $e(o.parent,p,c)),s}async function i4e(o,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(o.id))return[];if(p.add(o.id),o.type!==d.PrimitiveEntity)throw new Error("Entity must be a primitive entity to be flattened");const n=J.YieldTracker.from(i),s=[o];await n.tick();const c={...i,tracker:n};delete c.yieldEvery;for(const e of o.properties)s.push(...await $e(e,p,c));for(const e of o.methods)s.push(...await $e(e,p,c));for(const e of o.abstractMethods)s.push(...await $e(e,p,c));return s}async function r4e(o,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(o.id))return[];if(p.add(o.id),o.type!==d.Project)throw new Error("Entity must be a project to be flattened");const n=J.YieldTracker.from(i),s=[o];await n.tick();const c={...i,tracker:n};delete c.yieldEvery;for(const e of o.entities)s.push(...await $e(e,p,c));for(const e of o.functions)s.push(...await $e(e,p,c));for(const e of o.events)s.push(...await $e(e,p,c));for(const e of o.projects)s.push(...await $e(e,p,c));for(const e of o.variableDeclarations)s.push(...await $e(e,p,c));for(const e of o.variableInstances)s.push(...await $e(e,p,c));for(const e of o.operations)s.push(...await $e(e,p,c));for(const e of o.conditions)s.push(...await $e(e,p,c));for(const e of o.functionCalls)s.push(...await $e(e,p,c));for(const e of o.projects)s.push(...await $e(e,p,c));for(const e of o.loops)s.push(...await $e(e,p,c));for(const e of o.searches)s.push(...await $e(e,p,c));return s}async function n4e(o,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(o.id))return[];if(p.add(o.id),o.type!==d.Property)throw new Error("Entity must be a property to be flattened");const n=J.YieldTracker.from(i),s=[o];await n.tick();const c={...i,tracker:n};return delete c.yieldEvery,o.defaultValue&&s.push(...await $e(o.defaultValue,p,c)),o.dataType&&s.push(...await $e(o.dataType,p,c)),o.parent&&s.push(...await $e(o.parent,p,c)),s}async function a4e(o,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(o.id))return[];if(p.add(o.id),o.type!==d.ReturnStatement)throw new Error("Entity must be a return statement to be flattened");const n=J.YieldTracker.from(i),s=[o];await n.tick();const c={...i,tracker:n};delete c.yieldEvery;for(const y of o.outputs)s.push(...await $e(y,p,c));for(const y of o.outputs)s.push(...await $e(y,p,c));o.throws&&s.push(...await $e(o.throws,p,c)),o.readsValue&&s.push(...await $e(o.readsValue,p,c)),o.dataType&&s.push(...await $e(o.dataType,p,c));const e=to(o);for(const y of e)s.push(...await $e(y,p,c));return o.parent&&s.push(...await $e(o.parent,p,c)),s}async function s4e(o,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(o.id))return[];if(p.add(o.id),o.type!==d.Search)throw new Error("Entity must be a search to be flattened");const n=J.YieldTracker.from(i),s=[o];await n.tick();const c={...i,tracker:n};delete c.yieldEvery;for(const y of o.inputs)s.push(...await $e(y,p,c));for(const y of o.outputs)s.push(...await $e(y,p,c));o.error&&s.push(...await $e(o.error,p,c)),o.dataType&&s.push(...await $e(o.dataType,p,c));for(const y of o.inputsDeclarations)s.push(...await $e(y,p,c));const e=to(o);for(const y of e)s.push(...await $e(y,p,c));for(const y of o.successCalls)s.push(...await $e(y,p,c));for(const y of o.errorCalls)s.push(...await $e(y,p,c));for(const y of o.writesValues)s.push(...await $e(y,p,c));return o.parent&&s.push(...await $e(o.parent,p,c)),s}async function l4e(o,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(o.id))return[];if(p.add(o.id),o.type!==d.ValueDescriptor)throw new Error("Entity must be a value descriptor to be flattened");const n=J.YieldTracker.from(i),s=[o];await n.tick();const c={...i,tracker:n};return delete c.yieldEvery,o.defaultValue&&s.push(...await $e(o.defaultValue,p,c)),o.dataType&&s.push(...await $e(o.dataType,p,c)),o.parent&&s.push(...await $e(o.parent,p,c)),s}async function o4e(o,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(o.id))return[];if(p.add(o.id),o.type!==d.VariableDeclaration)throw new Error("Entity must be a variable declaration to be flattened");const n=J.YieldTracker.from(i),s=[o];await n.tick();const c={...i,tracker:n};delete c.yieldEvery;for(const y of o.inputs)s.push(...await $e(y,p,c));for(const y of o.outputs)s.push(...await $e(y,p,c));o.error&&s.push(...await $e(o.error,p,c)),o.dataType&&s.push(...await $e(o.dataType,p,c)),o.readsValue&&s.push(...await $e(o.readsValue,p,c)),o.defaultValue&&s.push(...await $e(o.defaultValue,p,c));const e=to(o);for(const y of e)s.push(...await $e(y,p,c));for(const y of o.successCalls)s.push(...await $e(y,p,c));for(const y of o.errorCalls)s.push(...await $e(y,p,c));for(const y of o.writesValues)s.push(...await $e(y,p,c));for(const y of o.internalCalls)s.push(...await $e(y,p,c));return o.parent&&s.push(...await $e(o.parent,p,c)),s}async function d4e(o,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(o.id))return[];if(p.add(o.id),o.type!==d.VariableInstance)throw new Error("Entity must be a variable instance to be flattened");const n=J.YieldTracker.from(i),s=[o];await n.tick();const c={...i,tracker:n};delete c.yieldEvery;for(const y of o.inputs)s.push(...await $e(y,p,c));for(const y of o.outputs)s.push(...await $e(y,p,c));o.error&&s.push(...await $e(o.error,p,c)),o.readsValue&&s.push(...await $e(o.readsValue,p,c)),o.defaultValue&&s.push(...await $e(o.defaultValue,p,c));const e=to(o);for(const y of e)s.push(...await $e(y,p,c));for(const y of o.successCalls)s.push(...await $e(y,p,c));for(const y of o.errorCalls)s.push(...await $e(y,p,c));for(const y of o.writesValues)s.push(...await $e(y,p,c));for(const y of o.internalCalls)s.push(...await $e(y,p,c));return o.parent&&s.push(...await $e(o.parent,p,c)),o.declaration&&s.push(...await $e(o.declaration,p,c)),s}async function $e(o,p=new Set,i={ignoreBuiltInBaseEntities:!1,yieldEvery:100}){const n={...i,ignoreBuiltInBaseEntities:i.ignoreBuiltInBaseEntities??!1};if(!o)throw new Error("Entity must be defined to be flattened");if(o.type===d.GenericReference)return[];const s=J.YieldTracker.from(n);n.tracker=s,n.yieldEvery!==void 0&&delete n.yieldEvery;const c=n.ignoreBuiltInBaseEntities?n.diggestedBuiltInBaseEntitiesIds??new Set(await R1(n)):new Set;if(n.diggestedBuiltInBaseEntitiesIds=c,n.ignoreBuiltInBaseEntities&&(Hn.includes(o.type)||c.has(o.id)))return[];if(p.has(o.id))return[];switch(o.type){case d.FunctionCall:return ZGe(o,p,n);case d.Operation:return e4e(o,p,n);case d.Condition:return KGe(o,p,n);case d.Loop:return QGe(o,p,n);case d.Search:return s4e(o,p,n);case d.GlobalEvent:return WGe(o,p,n);case d.ReturnStatement:return a4e(o,p,n);case d.ContinueStatement:return FGe(o,p,n);case d.BreakStatement:return jGe(o,p,n);case d.VariableDeclaration:return o4e(o,p,n);case d.DefinitionEntity:return SGe(o,p,n);case d.FunctionDeclaration:return HGe(o,p,n);case d.Project:return r4e(o,p,n);case d.ActionDescriptor:return GGe(o,p,n);case d.ArgumentDeclaration:return kGe(o,p,n);case d.ValueDescriptor:return l4e(o,p,n);case d.InputMap:return zGe(o,p,n);case d.OutputMap:return t4e(o,p,n);case d.DataType:return qGe(o,p,n);case d.InstalledProject:return JGe(o,p,n);case d.InternalCall:return YGe(o,p,n);case d.LiteralValue:return XGe(o,p,n);case d.Property:return n4e(o,p,n);case d.VariableInstance:return d4e(o,p,n);case d.BuiltInBaseEntity:return n.ignoreBuiltInBaseEntities?[]:UGe(o,p,n);case d.PrimitiveEntity:return n.ignoreBuiltInBaseEntities?[]:i4e(o,p,n)}return[]}function u4e(o,p,i){if(!i)throw new Error("[checkIsRowTransformerUpToDate] 'lastPublishedEntityVersion' argument is required");if(!p)throw new Error("[checkIsRowTransformerUpToDate] 'entity' argument is required");if(!o)throw new Error("[checkIsRowTransformerUpToDate] 'newestOpenRowTransformer' argument is required");let n=!0;const s=o.methods.find(c=>{var e;return((e=c.implements)==null?void 0:e.id)===Q["built-in-base-entity"].BUILT_IN_SQL_ROW_TRANSFORMER_ENTITY.methods.up.id});if(s?(vn(i).forEach(c=>{const e=s.inputs.find(y=>y.name===c.name);e&&Yr(e.getDataType(null),c.getDataType(null)).compatible||(n=!1)}),s.returnStatements.forEach(c=>{!c.dataType||!c.dataType.entity||c.dataType.entity.type!==d.DefinitionEntity?n=!1:jm(c.dataType.entity,p)||(n=!1)})):n=!1,n===null||n){const c=o.methods.find(e=>{var y;return((y=e.implements)==null?void 0:y.id)===Q["built-in-base-entity"].BUILT_IN_SQL_ROW_TRANSFORMER_ENTITY.methods.down.id});c?(vn(p).forEach(e=>{const y=c.inputs.find(m=>m.name===e.name);y&&Yr(y.getDataType(null),e.getDataType(null)).compatible||(n=!1)}),c.returnStatements.forEach(e=>{!e.dataType||!e.dataType.entity||e.dataType.entity.type!==d.DefinitionEntity?n=!1:jm(e.dataType.entity,i)||(n=!1)})):n=!1}return{isPreexistingRowTransformerUpToDate:n}}function p4e(o,p,i){const n={changesSinceLastPublication:!1,rowTransformerNeeded:!1,newRowTransformerNeeded:!1,newestOpenRowTransformer:null,newRequiredProperties:[],newNonRequiredProperties:[],deletedProperties:[],lastPublishedEntityVersion:null,updatedEntityVersion:i,propChanges:new Map,isPreexistingRowTransformerUpToDate:null,extendedEntities:[]},c=o.entities.filter(F=>{var ae;if(F.id===i.id)return!1;let q=!1,X=F;for(;X;){if(((ae=X.extends)==null?void 0:ae.id)===i.id){q=!0;break}if(X.extends&&X.extends.type===d.DefinitionEntity)X=X.extends;else break}return q}).map(F=>p4e(o,p,F));if(!p)return{...n,changesSinceLastPublication:!0,extendedEntities:c};const e=p.get(i.id);if(!e)return{...n,changesSinceLastPublication:!0,extendedEntities:c};const y=p.entities.filter(F=>Zi(F,Re.SQL_ROW_TRANSFORMER)),v=o.entities.filter(F=>{var ee;if(!Zi(F,Re.SQL_ROW_TRANSFORMER)||y.find(fe=>fe.id===F.id))return!1;const X=F.properties.find(fe=>!!fe.implements.find(oe=>Q["built-in-base-entity"].BUILT_IN_SQL_ROW_TRANSFORMER_ENTITY.properties.definition.id===oe.id));if(!X)return!1;const ae=(ee=X.defaultValue)==null?void 0:ee.valueAsType;return ae?ae.id===i.id:!1}).sort((F,q)=>M(F.createdAt).isAfter(M(q.createdAt))?-1:1)[0]||null,E=new Map;let b=!1;const w=vn(i).filter(F=>vn(e).find(X=>X.id===F.id)?!1:!!F.required),P=vn(i).filter(F=>vn(e).find(X=>X.id===F.id)?!1:!F.required),$=vn(e).filter(F=>!vn(i).find(X=>X.id===F.id));vn(i).filter(F=>{var ae,ee,fe,oe,ce,Te,de,ye,_e,Pe,Ge,xe,Me,Se,je,Ze,Ye,lt,ot,Rt,_t,Ri,sr,hr;const q=vn(e).find(_n=>_n.id===F.id);let X=!1;if(!q)return!1;if(((ee=(ae=F.dataType)==null?void 0:ae.entity)==null?void 0:ee.id)!==((oe=(fe=q==null?void 0:q.dataType)==null?void 0:fe.entity)==null?void 0:oe.id)&&(((Te=(ce=F.dataType)==null?void 0:ce.entity)==null?void 0:Te.id)===Q["primitive-entity"].string.id||((ye=(de=q==null?void 0:q.dataType)==null?void 0:de.entity)==null?void 0:ye.id)===Q["primitive-entity"].date.id&&((Pe=(_e=F.dataType)==null?void 0:_e.entity)==null?void 0:Pe.id)===Q["primitive-entity"].number.id?E.set(F.id,{...E.get(F.id)||{},castableDataTypeEntity:{fromId:((xe=(Ge=q==null?void 0:q.dataType)==null?void 0:Ge.entity)==null?void 0:xe.id)||"",toId:((Se=(Me=F.dataType)==null?void 0:Me.entity)==null?void 0:Se.id)||""},property:F,oldProperty:q}):(E.set(F.id,{...E.get(F.id)||{property:F},nonCastableDataTypeEntity:{fromId:((Ze=(je=q==null?void 0:q.dataType)==null?void 0:je.entity)==null?void 0:Ze.id)||"",toId:((lt=(Ye=F.dataType)==null?void 0:Ye.entity)==null?void 0:lt.id)||""},property:F,oldProperty:q}),b=!0),X=!0),((Rt=(ot=F.dataType)==null?void 0:ot.foreignKeyRef)==null?void 0:Rt.id)!==((Ri=(_t=q==null?void 0:q.dataType)==null?void 0:_t.foreignKeyRef)==null?void 0:Ri.id)){const _n=(sr=F.dataType)==null?void 0:sr.foreignKeyRef,an=(hr=q==null?void 0:q.dataType)==null?void 0:hr.foreignKeyRef;E.set(F.id,{...E.get(F.id)||{},newForeignKeyRef:_n||void 0,oldForeignKeyRef:an||void 0,property:F,oldProperty:q}),X=!0,b=!0}return F.name!==(q==null?void 0:q.name)&&(E.set(F.id,{...E.get(F.id)||{},nameChange:{from:(q==null?void 0:q.name)||"",to:F.name},property:F,oldProperty:q}),X=!0),F.required!==(q==null?void 0:q.required)&&(E.set(F.id,{...E.get(F.id)||{},requiredChange:{from:(q==null?void 0:q.required)||!1,to:F.required},property:F,oldProperty:q}),F.required&&(b=!0),X=!0),X}),w.length>0&&(b=!0);const L=!!v&&u4e(v,i,e).isPreexistingRowTransformerUpToDate||null,j=i.name!==e.name?{from:e.name,to:i.name}:void 0;return{...n,changesSinceLastPublication:E.size>0||!!$.length||!!w.length||!!P.length||b,rowTransformerNeeded:b,newestOpenRowTransformer:v,nameChange:j,newRequiredProperties:w,newNonRequiredProperties:P,deletedProperties:$,lastPublishedEntityVersion:e,propChanges:E,newRowTransformerNeeded:b&&!v,isPreexistingRowTransformerUpToDate:L,extendedEntities:c}}function JN(o,p,i,n,s){if(!o)throw new Error("[addDifferencesToRowTransformer] 'project' argument is required");if(!p)throw new Error("[addDifferencesToRowTransformer] 'transformer' argument is required");if(!i)throw new Error("[addDifferencesToRowTransformer] 'newEntityState' argument is required");if(!n)throw new Error("[addDifferencesToRowTransformer] 'oldEntityState' argument is required");const c=vn(i),e=vn(n);p.afterAllChildrenInitialized(s);const y=p.methods.find(v=>{var E;return((E=v.implements)==null?void 0:E.id)===Q["built-in-base-entity"].BUILT_IN_SQL_ROW_TRANSFORMER_ENTITY.methods.up.id}),m=p.methods.find(v=>{var E;return((E=v.implements)==null?void 0:E.id)===Q["built-in-base-entity"].BUILT_IN_SQL_ROW_TRANSFORMER_ENTITY.methods.down.id});if(!y)throw new Error("[addDifferencesToRowTransformer] The 'up' transformer trigger is missing from the parent");if(!m)throw new Error("[addDifferencesToRowTransformer] The 'down' transformer trigger is missing from the parent");e.forEach(v=>{const E=y.inputs.find($=>$.name===v.name),b=v.getDataType(null);let w=E,P;if(E)w.editable=!0;else{const $=Ea.new(s);$.parent=y.toReference(),$.name=v.name,$.index=v.index,$.implements=[...v.implements.map(j=>j.toJSON())];const L=he($,o);L.hydrateAncestors(),s.add(L,H.Added),L.addSelfToProject(s),L.initChildren(s),w=L}if(!w.dataType||w.dataType&&o.diggestedBuiltInBaseEntitiesIds.has(w.dataType.id)){const $=ir.new(s);$.parent=w.toReference();const L=he($,o);L.hydrateAncestors(),s.add(L,H.Added),L.addSelfToProject(s),L.initChildren(s),P=L}else P=w.dataType,P.editable=!0;b&&P.merge(v.getDataType(null),s),P.metaSync({editable:!1,deletable:!1},s),w.metaSync({editable:!1,deletable:!1},s)}),[...y.inputs].forEach(v=>{e.find(b=>b.name===v.name)||(v.editable=!0,v.remove({ignoreUpstream:!1},s),v.editable=!1)}),[...y.returnStatements].forEach(v=>{var E,b;if(!v.dataType||v.dataType&&o.diggestedBuiltInBaseEntitiesIds.has(v.dataType.id)){const w=ir.new(s);w.entity=i.toReference(),w.parent=v.toReference();const P=he(w,o);P.hydrateAncestors(),s.add(P,H.Added),P.addSelfToProject(s),P.initChildren(s)}(!((E=v.dataType)!=null&&E.entity)||v.dataType.entity.type!==d.DefinitionEntity||v.dataType.entity.parent.id!==v.dataType.id)&&i.clone(s,v.dataType),TV((b=v.dataType)==null?void 0:b.entity,i,s),v.afterAllChildrenInitialized(s),v.outputs.forEach(w=>{const P=y.inputs.find($=>se(w,o)===se($,o));w.setValueWriter(P,s),P==null||P.addValueReader(w,s)})}),c.forEach(v=>{var L;const E=(L=v.knownVersions)==null?void 0:L.get(v.previousVersion),b=m.inputs.find(j=>j.name===v.name||!!E&&E.name===j.name),w=v.getDataType(null);let P=b,$;if(b)P.editable=!0,P.metaSync({name:v.name,codeName:v.codeName,description:v.description},s);else{const j=Ea.new(s);j.parent=m.toReference(),j.name=v.name,j.codeName=v.codeName,j.description=v.description,j.index=v.index,j.implements=[v.toJSON(),...v.implements.map(q=>q.toJSON())];const F=he(j,o);F.hydrateAncestors(),s.add(F,H.Added),F.addSelfToProject(s),F.initChildren(s),P=F}if(P.dataType)$=P.dataType,$.editable=!0,$.merge(P.dataType,s);else{const j=ir.new(s);j.parent=P.toReference();const F=he(j,o);F.hydrateAncestors(),s.add(F,H.Added),F.addSelfToProject(s),F.initChildren(s),$=F}w&&$.merge(v.getDataType(null),s),$.metaSync({editable:!1,deletable:!1},s),P.metaSync({editable:!1,deletable:!1},s)}),[...m.inputs].forEach(v=>{c.find(b=>{var P;if(b.name===v.name)return!0;const w=(P=b.knownVersions)==null?void 0:P.get(b.previousVersion);if(w&&w.name===v.name)return!0})||(v.editable=!0,v.remove({ignoreUpstream:!1},s),v.editable=!1)}),[...m.returnStatements].forEach(v=>{var b,w,P,$;if(!v.dataType||v.dataType&&o.diggestedBuiltInBaseEntitiesIds.has(v.dataType.id)){const L=ir.new(s);L.parent=v.toReference();const j=he(L,o);j.hydrateAncestors(),s.add(j,H.Added),j.addSelfToProject(s),j.initChildren(s)}let E=(b=v.dataType)==null?void 0:b.entity;(!E||(E==null?void 0:E.id)===Q["built-in-base-entity"].BUILT_IN_PERSISTED_ENTITY_ENTITY.id)&&(J.Logger.log("Cloning old entity state into new project with data-ype as parent: ",(w=v.dataType)==null?void 0:w.id," from new project: ",((P=v.dataType)==null?void 0:P.project.version)===o.version&&(($=v.dataType)==null?void 0:$.project.entities.length)===3),E=n.clone(s,v.dataType)),v.dataType.setEntity(E,s),v.afterAllChildrenInitialized(s),v.outputs.forEach(L=>{const j=m.inputs.find(F=>se(L,o)===se(F,o));L.setValueWriter(j,s),j==null||j.addValueReader(L,s)})})}function c4e(o,p,i,n){var $;const s=o.getBuiltIn(Re.SQL_ROW_TRANSFORMER),c=OV(se(p,o)+" row transformer",o.entities),e=s.implement(c,n),y=e.ownDeclaredProperties.find(L=>{var j;return(j=L.implements)==null?void 0:j.find(F=>F.id===Q["built-in-base-entity"].BUILT_IN_SQL_ROW_TRANSFORMER_ENTITY.properties.definition.id)}),m=e.methods.find(L=>{var j;return((j=L.implements)==null?void 0:j.id)===Q["built-in-base-entity"].BUILT_IN_SQL_ROW_TRANSFORMER_ENTITY.methods.up.id}),v=e.methods.find(L=>{var j;return((j=L.implements)==null?void 0:j.id)===Q["built-in-base-entity"].BUILT_IN_SQL_ROW_TRANSFORMER_ENTITY.methods.down.id});if(!y||!m||!v)throw new Error("Cannot find definition property on the new row transformer entity");if(y.defaultValue)y.defaultValue.setValueAsTypeSingle(p,n);else{const L=Xr.new(n);L.name=le.EntityTemplate,L.valueAsTypeSingle=p.toJSON(),L.parent=y.toReference();const j=he(L,o);j.hydrateAncestors(),n.add(j,H.Added),j.addSelfToProject(n),j.initChildren(n)}JN(o,e,p,i,n),J.Logger.log("BEFORE - changeSet.listAdded",n.listAdded.map(L=>{var F,q,X,ae,ee,fe,oe;const j=o.get(L.id);return j?se(j,o):L.type===d.InputMap?"(not found) "+L.type+" "+L.id+" - declaration: "+((F=L.declaration)==null?void 0:F.type)+" "+((q=L.declaration)==null?void 0:q.id)+' "'+((X=L.declaration)==null?void 0:X.name)+`"
|
|
388
388
|
parent: `+((ee=(ae=L.parent)==null?void 0:ae.parent)==null?void 0:ee.id)+" - "+((oe=(fe=L.parent)==null?void 0:fe.parent)==null?void 0:oe.name):"(not found) "+L.type+" "+L.id})),J.Logger.log("AFTER - changeSet.listAdded",n.listAdded.map(L=>{var F,q,X,ae,ee,fe,oe;const j=o.get(L.id);return j?j.type+' "'+se(j,o)+'" ('+j.id+")":L.type===d.InputMap?"(not found) "+L.type+" ("+L.id+") - declaration: "+((F=L.declaration)==null?void 0:F.type)+" ("+((q=L.declaration)==null?void 0:q.id)+') "'+((X=L.declaration)==null?void 0:X.name)+`"
|
|
389
389
|
parent: "`+((ee=(ae=L.parent)==null?void 0:ae.parent)==null?void 0:ee.name)+'" ('+((oe=(fe=L.parent)==null?void 0:fe.parent)==null?void 0:oe.id)+")":"(not found) "+L.type+" "+L.id})),J.Logger.log("-----------------"),J.Logger.log("Old properties: ",vn(i).map(L=>L.name+" ("+L.id+")")),J.Logger.log("New properties: ",vn(p).map(L=>L.name+" ("+L.id+")"));const E=e.methods.find(L=>{var j;return((j=L.implements)==null?void 0:j.id)===Q["built-in-base-entity"].BUILT_IN_SQL_ROW_TRANSFORMER_ENTITY.methods.up.id}),b=e.methods.find(L=>{var j;return((j=L.implements)==null?void 0:j.id)===Q["built-in-base-entity"].BUILT_IN_SQL_ROW_TRANSFORMER_ENTITY.methods.down.id});J.Logger.log(`
|
package/dist/index.js
CHANGED
|
@@ -175041,7 +175041,10 @@ Alternatively you can update the parent data-type entity with 'update' action to
|
|
|
175041
175041
|
_.RemoveAllPropertiesImplement
|
|
175042
175042
|
)
|
|
175043
175043
|
)) {
|
|
175044
|
-
return this.checkCanEdit(this, i) ? (this.allPropertiesImplement && (this.
|
|
175044
|
+
return this.checkCanEdit(this, i) ? (this.allPropertiesImplement && (this.properties.find((n) => {
|
|
175045
|
+
var s;
|
|
175046
|
+
return n.id === ((s = this.allPropertiesImplement) == null ? void 0 : s.id);
|
|
175047
|
+
}) || this.allPropertiesImplement.remove({ ignoreUpstream: !0 }, i), i == null || i.add(this, H.Affected), this.allPropertiesImplement = null), i == null || i.attemptAutoclose(
|
|
175045
175048
|
_.RemoveAllPropertiesImplement,
|
|
175046
175049
|
this.id
|
|
175047
175050
|
), this) : (ie.warn(
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@elyx-code/project-logic-tree",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.6720",
|
|
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",
|