@elyx-code/project-logic-tree 0.0.6843 → 0.0.6844

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -476,7 +476,7 @@ This is likely an incorrect strategy, either the '${this.type}' entity doesn't n
476
476
  You can inspect the existing 'entity' field with the 'describe_entity' action. Like so:
477
477
  ${Qu({describe_entity:g.entity.id})}
478
478
  Alternatively you can update the parent data-type entity with 'update' action to remove the existing value of the field.`}))}return{errors:e,explanations:c,modifiedData:a}}get interactive(){return this.implements.length?this.implements.every(i=>i.interactive):!0}get allMethods(){return C([...this.ownDeclaredMethods,...this.allBaseMethodsFromOriginalParents])}get allProperties(){return C([...this.ownDeclaredProperties,...this.allBasePropertiesFromOriginalParents])}get allBaseMethodsFromOriginalParents(){var a;const i=((a=this.extends)==null?void 0:a.type)===d.DefinitionEntity?this.extends.allMethods:[],r=[...i].filter(c=>!i.some(e=>{var f,h;return e.id!==c.id&&(((f=e.implements)==null?void 0:f.id)===c.id||((h=e.extends)==null?void 0:h.id)===c.id)}));return C([...r,...this.implements.flatMap(c=>{const e=c.type===d.DefinitionEntity?[...c.allMethods]:[];return[...e].filter(h=>!e.some(m=>{var E,b;return m.id!==h.id&&(((E=m.implements)==null?void 0:E.id)===h.id||((b=m.extends)==null?void 0:b.id)===h.id)}))})])}get allBasePropertiesFromOriginalParents(){var c;const i=((c=this.extends)==null?void 0:c.allProperties)||[],r=[...i].filter(e=>!i.some(f=>{var h;return f.id!==e.id&&(!!f.implements.find(m=>m.id===e.id)||((h=f.extends)==null?void 0:h.id)===e.id)}));return C([...r,...this.implements.flatMap(e=>{const f=[...e.allProperties];return[...f].filter(m=>!f.some(E=>{var b;return E.id!==m.id&&(!!E.implements.find(g=>g.id===m.id)||((b=E.extends)==null?void 0:b.id)===m.id)}))})])}get allBasePropertiesFromExtendedAndImplementedEntities(){var c,e;const i=[...((c=this.extends)==null?void 0:c.ownDeclaredProperties)||[],...((e=this.extends)==null?void 0:e.allBasePropertiesFromExtendedAndImplementedEntities)||[]].filter(f=>!f.abstract),r=[...i].filter(f=>!i.some(h=>{var m;return h.id!==f.id&&(!!h.implements.find(E=>E.id===f.id)||((m=h.extends)==null?void 0:m.id)===f.id)})),a=this.implements.reduce((f,h)=>{const m=h.implementedPropertiesFromOriginalParents,E=[...h.ownDeclaredProperties].filter(_=>!_.abstract),b=[...m,...E,...f];return[...b].filter(_=>!!!b.find(L=>{var j;return!!L.implements.find(k=>k.id===_.id)||((j=L.extends)==null?void 0:j.id)===_.id}))},[]);return C([...r,...a])}get allBaseMethodsFromExtendedAndImplementedEntities(){return C([...(this.extends?[this.extends]:[]).reduce((i,r)=>r.type!==d.DefinitionEntity?[]:[...[...r.ownDeclaredMethods,...r.allBaseMethodsFromExtendedAndImplementedEntities].filter(c=>c.type!==d.ActionDescriptor),...i],[]),...this.implements.reduce((i,r)=>r.type!==d.DefinitionEntity?r.abstractMethods:[...[...r.ownDeclaredMethods,...r.allBaseMethodsFromExtendedAndImplementedEntities].filter(c=>c.type!==d.ActionDescriptor),...i],[])])}get extendedPropertiesFromOriginalParents(){var a,c;const i=[...((a=this.extends)==null?void 0:a.ownDeclaredProperties)||[],...((c=this.extends)==null?void 0:c.extendedPropertiesFromOriginalParents)||[]].filter(e=>!e.abstract),r=[...i].filter(e=>!i.some(f=>{var h;return f.id!==e.id&&(!!f.implements.find(m=>m.id===e.id)||((h=f.extends)==null?void 0:h.id)===e.id)}));return C(r)}get implementedPropertiesFromOriginalParents(){return C([...(this.extends?[this.extends]:[]).reduce((i,r)=>{const a=r.implementedPropertiesFromOriginalParents,c=[...r.ownDeclaredProperties].filter(h=>!!h.abstract),e=[...a,...c,...i];return[...e].filter(h=>!!!e.find(E=>{var b;return((b=E.extends)==null?void 0:b.id)===h.id||!!E.implements.find(g=>g.id===h.id)}))},[]),...this.implements.reduce((i,r)=>{const a=r.implementedPropertiesFromOriginalParents,c=[...r.ownDeclaredProperties].filter(h=>!!h.abstract),e=[...a,...c,...i];return[...e].filter(h=>!!!e.find(E=>{var b;return!!E.implements.find(g=>g.id===h.id)||((b=E.extends)==null?void 0:b.id)===h.id}))},[])].filter(i=>!!i.abstract))}get extendedMethodsFromOriginalParents(){return C((this.extends?[this.extends]:[]).reduce((i,r)=>{if(r.type!==d.DefinitionEntity)return[];const a=[...r.ownDeclaredMethods,...r.extendedMethodsFromOriginalParents].filter(c=>c.type!==d.ActionDescriptor);return[...i,...a]},[]))}get implementedMethodsFromOriginalParents(){return C([...(this.extends?[this.extends]:[]).reduce((i,r)=>{const a=r.type===d.DefinitionEntity?r.methods:[],c=[...r.abstractMethods].filter(e=>!a.find(f=>f.name===e.name));return[...a,...c,...i]},[]),...this.implements.reduce((i,r)=>[...r.abstractMethods,...i],[])].filter(i=>i.type===d.ActionDescriptor))}get extendedProperties(){return this.properties.filter(i=>i.isExtendedProperty)}get ownDeclaredProperties(){return this.properties.filter(r=>!r.isExtendedProperty)}get extendedMethods(){return this.methods.filter(i=>i.isExtendedMethod)}get ownDeclaredMethods(){return this.methods.filter(i=>!i.isExtendedMethod)}validateGeneratedUpdate(i){const r=[],a=[];return i.parent&&r.push(new Re({id:`${this.id}--${he.InvalidParentUpdate}`,code:he.InvalidParentUpdate,severity:me.Error,message:`Entity of type '${this.type}' with id '${this.id}' cannot have the 'parent' property updated. The 'parent' on an '${this.type}', must be the root project as it is a globally declared entity.`})),{errors:r,explanations:a,modifiedData:i}}subscribeDependents(i){return i.forEach(r=>{this.detachedDependents[r.entity.id]||(this.detachedDependents[r.entity.id]=r)}),this}unsubscribeDependents(i){return i.forEach(r=>{this.detachedDependents[r.entity.id]&&delete this.detachedDependents[r.entity.id]}),this}syncDependents(i=this.project.addChangeSet(new q(this.project,N.sessionAuthor,B().toISOString(),this,!0,"sync-dependents"))){const r=[],a=[],c=[],e=[];return Object.values(this.detachedDependents).forEach(f=>{const h=f.entity.afterAllChildrenInitialized(i);r.push(...h.updated),a.push(...h.added),c.push(...h.removed),e.push(...h.affected)}),i==null||i.attemptAutoclose("sync-dependents",this.id),{updated:C(r),added:C(a),removed:C(c),affected:C(e),self:this}}onDetachedDependencyRemoved(i,r,a){const c=[],e=[],f=[],h=[];return r==="implements"&&(this.removeImplementation(i,a),c.push(this)),r==="extends"&&(this.setExtension(null,a),c.push(this)),{updated:C(c),added:C(e),removed:C(f),affected:C(h),self:this}}onDetachedDependencyRestored(i,r,a){const c=[],e=[],f=[],h=[];return r==="implements"&&(this.addImplementation(i,a),c.push(this)),r==="extends"&&(this.setExtension(i,a),c.push(this)),{updated:C(c),added:C(e),removed:C(f),affected:C(h),self:this}}unsubscribeFromDependencies(){return this.implements.forEach(i=>{ra.includes(i.type)||i.unsubscribeDependents([{entity:this,field:"implements"}])}),this.extends&&(ra.includes(this.extends.type)||this.extends.unsubscribeDependents([{entity:this,field:"extends"}])),this}subscribeToDependencies(){return this.implements.forEach(i=>{ra.includes(i.type)||i.subscribeDependents([{entity:this,field:"implements"}])}),this.extends&&(ra.includes(this.extends.type)||this.extends.subscribeDependents([{entity:this,field:"extends"}])),this}increaseVersion(i){if(i&&!B(i).isValid())throw new Error(`The shared timestamp '${i}' is not a valid ISO 8601 date string.`);return i&&B(i).isSame(B(this.createdAt))?this:(this.previousVersion=this.version,this.version=N.UUID.uuid(),this.createdAt=B(i).toISOString()||B().toISOString(),this)}captureVersion(){var r;const i=((r=this.knownVersions)==null?void 0:r.get(this.version))||new _i(this,this.project);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 r=[],a=[],c=[],e=[];if(this.parent){this.parent.increaseVersion(i);const f=this.parent.recursiveCaptureUpstreamVersions(i);r.push(this.parent,...f.updated),a.push(...f.added),c.push(...f.removed)}return{updated:C(r),added:C(a),removed:C(c),affected:C(e),self:this}}async restoreVersion(i){var h;const r=[],a=[],c=[],e=[];if(this.version===i)return{updated:C(r),added:C(a),removed:C(c),affected:C(e),self:this};if(!this.knownVersions){const m=new Map;for(const[E,b]of this.knownVersions||new Map){if(m.set(E,b),b.activeVersion=!1,b.knownVersions)for(const[g,_]of b.knownVersions)m.set(g,_);b.knownVersions=null}}let f=(h=this.knownVersions)==null?void 0:h.get(i);if(!f){const m=await this.APILoadVersion({},i);if(!m)throw new Error(`Version with id '${i}' for entity with id '${this.id}' not found.`);f=new _i(m,this.project)}return this.metaSync(f.toShallowJSON(),null),this.previousVersion=f.previousVersion,this.version=f.version,this.createdAt=f.createdAt,this.author=f.author,this.deleted=f.deleted,this.properties=[...f.properties],this.methods=[...f.methods],this.abstractMethods=[...f.abstractMethods],this.extends=f.extends,this.implements=[...f.implements],this.allPropertiesImplement=f.allPropertiesImplement,this.additionalPropertiesDataType=f.additionalPropertiesDataType,this.parent=f.parent,{updated:C(r),added:C(a),removed:C(c),affected:C(e),self:this}}updateWithShallowTransfer(i,r=this.project.addChangeSet(new q(this.project,N.sessionAuthor,B().toISOString(),this,!0,w.UpdateWithShallowTransfer))){if(!this.checkCanEdit(this,r))return z.Logger.warn(`[updateWithShallowTransfer] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),r==null||r.attemptAutoclose(w.UpdateWithShallowTransfer,this.id),this;if(this.metaSync(i,r),this.version=i.version,this.createdAt=i.createdAt,this.author=i.author,this.deleted=i.deleted,this.previousVersion=i.previousVersion,this.unsubscribeFromDependencies(),i.parent){const f=X(i.parent),h=this.project.get(f),m=this.parent;if(m&&m.id!==(h==null?void 0:h.id)&&this.removeFromParent(r),h)this.setParent(h,r),this.addSelfToProject(r);else throw r==null||r.attemptAutoclose(w.UpdateWithShallowTransfer,this.id),new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${f}' that isn't found in the project`)}else throw r==null||r.attemptAutoclose(w.UpdateWithShallowTransfer,this.id),new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(i.extends){const f=X(i.extends),h=this.project.get(f);h&&this.setExtension(h,r)}else this.setExtension(null,r);if(i.implements.forEach(f=>{const h=X(f),m=this.project.get(h);if(m)this.addImplementation(m,r);else throw new Error(`${or(this.type)} with id '${this.id}' has a 'implements' reference "${h}" which is missing in the project`)}),this.implements.filter(f=>{const h=X(f);return!i.implements.find(m=>X(m)===h)}).forEach(f=>{this.removeImplementation(f,r)}),i.methods.forEach(f=>{const h=X(f),m=this.project.get(h);m&&this.addMethod(m,r)}),this.methods.filter(f=>{const h=X(f);return!i.methods.find(m=>X(m)===h)}).forEach(f=>{this.removeMethod(f,r)}),i.properties.forEach(f=>{const h=X(f),m=this.project.get(h);m&&this.addProperty(m,r)}),this.properties.filter(f=>{const h=X(f);return!i.properties.find(m=>X(m)===h)}).forEach(f=>{this.removeProperty(f,r)}),i.allPropertiesImplement){const f=X(i.allPropertiesImplement),h=this.project.get(f);h&&this.setAllPropertiesImplement(h,r)}else this.setAllPropertiesImplement(null,r);if(i.additionalPropertiesDataType){const f=X(i.additionalPropertiesDataType),h=this.project.get(f);h&&this.setAdditionalPropertiesDataType(h,r)}else this.setAdditionalPropertiesDataType(null,r);return this.captureVersion(),this.subscribeToDependencies(),r==null||r.attemptAutoclose(w.UpdateWithShallowTransfer,this.id),this}updateWithGenerationTarget(i,r=this.project.addChangeSet(new q(this.project,N.sessionAuthor,B().toISOString(),this,!0,w.UpdateWithGenerationTarget))){var a;if(!this.checkCanEdit(this,r))return z.Logger.warn(`[updateWithGenerationTarget] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),r==null||r.attemptAutoclose(w.UpdateWithGenerationTarget,this.id),this;if(this.metaSync(i,r),i.parent){const c=X(i.parent),e=this.project.get(c),f=this.parent;if(f&&f.id!==(e==null?void 0:e.id)&&this.removeFromParent(r),e)this.setParent(e,r),this.addSelfToProject(r);else throw r==null||r.attemptAutoclose(w.UpdateWithGenerationTarget,this.id),new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${c}' that isn't found in the project`)}if(i.extends){const c=X(i.extends),e=this.project.get(c);if(e)this.setExtension(e,r);else throw new Error(`${or(this.type)} with id '${this.id}' has an 'extends' reference "${c}" which is missing in the project`)}else i.extends===null&&this.setExtension(null,r);return(a=i.implements)==null||a.forEach(c=>{const e=X(c),f=this.project.get(e);if(f)this.addImplementation(f,r);else throw new Error(`${or(this.type)} with id '${this.id}' has a 'implements' reference "${e}" which is missing in the project`)}),i.implements&&this.implements.filter(e=>{const f=X(e);return!(i.implements||[]).find(h=>X(h)===f)}).forEach(e=>{this.removeImplementation(e,r)}),this.captureVersion(),this.subscribeToDependencies(),r==null||r.attemptAutoclose(w.UpdateWithGenerationTarget,this.id),this}hydrateAncestors(){const i=[],r=[],a=[],c=[];if(this.initialData.parent){const e=X(this.initialData.parent),f=this.project.get(e);if(f)this.setParent(f,null),i.push(f);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${e}' that isn't found in the project`)}else throw new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(this.initialData.extends){const e=X(this.initialData.extends),f=this.project.get(e);f&&(this.setExtension(f,null),f.type!==d.BuiltInBaseEntity&&i.push(f))}return this.initialData.implements.forEach(e=>{const f=X(e),h=this.project.get(f);if(h)this.addImplementation(h,null),h.type!==d.BuiltInBaseEntity&&i.push(h);else throw new Error(`${or(this.type)} with id '${this.id}' has a 'implements' reference "${f}" which is missing in the project`)}),{updated:C(i),added:C(r),removed:C(a),affected:C(c),self:this}}afterAllChildrenInitialized(i=this.project.addChangeSet(new q(this.project,N.sessionAuthor,B().toISOString(),this,!0,w.AfterAllChildrenInitialized))){if(!this.checkCanEdit(this,i))return z.Logger.warn(`[afterAllChildrenInitialized] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(w.AfterAllChildrenInitialized,this.id),{updated:[],added:[],removed:[],affected:[],self:this};const r=[],a=[],c=[],e=[];this.initialized=!0;const{updated:f,added:h,removed:m,affected:E}=this.syncImplementationProperties(i);r.push(...f),a.push(...h),c.push(...m),e.push(...E);const{updated:b,added:g,removed:_,affected:$}=this.addExtendedProperties(i);r.push(...b),a.push(...g),c.push(..._),e.push(...$);const{updated:L,added:j,removed:k}=this.removeUnrecognizedProperties(i);r.push(...L),a.push(...j),c.push(...k);const{updated:G,added:H,removed:ie,affected:ee}=this.syncImplementationMethods(i);r.push(...G),a.push(...H),c.push(...ie),e.push(...ee);const{updated:ue,added:ae,removed:de,affected:ce}=this.addExtendedMethods(i);r.push(...ue),a.push(...ae),c.push(...de),e.push(...ce);const{updated:ne,added:le,removed:Q}=this.removeUnrecognizedMethods(i);r.push(...ne),a.push(...le),c.push(...Q),this.addSuggestions(),this.properties.sort((Ee,Te)=>Ee.index-Te.index);const oe=this.project.getDefinitionEntities(new Set([this.id]));if(oe.some(Ee=>Ee.id!==this.id&&Ee.name.toLowerCase()===this.name.toLowerCase())){const Ee=HR(this.name,oe);this.metaSync({name:Ee},i)}return this.captureVersion(),i==null||i.attemptAutoclose(w.AfterAllChildrenInitialized,this.id),{updated:C(r),added:C(a),removed:C(c),affected:C(e),self:this}}addSelfToProject(i=this.project.addChangeSet(new q(this.project,N.sessionAuthor,B().toISOString(),this,!0,"add-self-to-project"))){const r=[this],a=[],c=[],e=[];if(this.parent.type===d.DataType){const f=this.parent;f.entity=this,r.push(f)}else this.project.addDefinitionEntity(this);return this.subscribe(),this.subscribeToDependencies(),i==null||i.attemptAutoclose("add-self-to-project",this.id),{updated:C(r),added:C(a),removed:C(c),affected:C(e),self:this}}setParent(i,r=this.project.addChangeSet(new q(this.project,N.sessionAuthor,B().toISOString(),this,!0,w.SetParent))){var a;return this.checkCanEditWithCounterpartAndSideEffects(this,i,w.SetParent,r)?(((a=this.parent)==null?void 0:a.id)!==(i==null?void 0:i.id)&&(this.parent=i,r&&(r==null||r.add(this,W.Updated))),r==null||r.attemptAutoclose(w.SetParent,this.id),this):this}setExtension(i,r=this.project.addChangeSet(new q(this.project,N.sessionAuthor,B().toISOString(),this,!0,w.SetExtension))){var a;return this.checkCanEdit(this,r)?(((a=this.extends)==null?void 0:a.id)!==(i==null?void 0:i.id)&&(this.extends=i,this.subscribeToDependencies(),r&&(r==null||r.add(this,W.Updated))),r==null||r.attemptAutoclose(w.SetExtension,this.id),this):(z.Logger.warn(`[setExtension] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),r==null||r.attemptAutoclose(w.SetExtension,this.id),this)}addImplementation(i,r=this.project.addChangeSet(new q(this.project,N.sessionAuthor,B().toISOString(),this,!0,w.AddImplementation))){return this.checkCanEdit(this,r)?(this.implements.includes(i)||(this.implements.push(i),this.subscribeToDependencies(),r==null||r.add(this,W.Updated)),r==null||r.attemptAutoclose(w.AddImplementation,this.id),this):(z.Logger.warn(`[addImplementation] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),r==null||r.attemptAutoclose(w.AddImplementation,this.id),this)}removeImplementation(i,r=this.project.addChangeSet(new q(this.project,N.sessionAuthor,B().toISOString(),this,!0,w.RemoveImplementation))){return this.checkCanEdit(this,r)?(this.implements.includes(i)&&(this.implements=this.implements.filter(a=>a.id!==i.id),r==null||r.add(this,W.Updated)),r==null||r.attemptAutoclose(w.RemoveImplementation,this.id),this):(z.Logger.warn(`[removeImplementation] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),r==null||r.attemptAutoclose(w.RemoveImplementation,this.id),this)}removeProperty(i,r=this.project.addChangeSet(new q(this.project,N.sessionAuthor,B().toISOString(),this,!0,w.RemoveProperty))){return this.checkCanEdit(this,r)?(this.properties.includes(i)&&(this.properties=this.properties.filter(a=>a.id!==i.id),r==null||r.add(this,W.Updated)),r==null||r.attemptAutoclose(w.RemoveProperty,this.id),this):(z.Logger.warn(`[removeProperty] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),r==null||r.attemptAutoclose(w.RemoveProperty,this.id),this)}addMethod(i,r=this.project.addChangeSet(new q(this.project,N.sessionAuthor,B().toISOString(),this,!0,w.AddMethod))){return this.checkCanEdit(this,r)?(this.methods.includes(i)||(this.methods.push(i),this.suggestedMethods=this.suggestedMethods.filter(a=>a.name!==i.name),r==null||r.add(this,W.Updated)),r==null||r.attemptAutoclose(w.AddMethod,this.id),this):(z.Logger.warn(`[addMethod] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),r==null||r.attemptAutoclose(w.AddMethod,this.id),this)}removeMethod(i,r=this.project.addChangeSet(new q(this.project,N.sessionAuthor,B().toISOString(),this,!0,w.RemoveMethod))){return this.checkCanEdit(this,r)?(this.methods.includes(i)&&(this.methods=this.methods.filter(a=>a.id!==i.id),r==null||r.add(this,W.Updated)),r==null||r.attemptAutoclose(w.RemoveMethod,this.id),this):(z.Logger.warn(`[removeMethod] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),r==null||r.attemptAutoclose(w.RemoveMethod,this.id),this)}addProperty(i,r=this.project.addChangeSet(new q(this.project,N.sessionAuthor,B().toISOString(),this,!0,w.AddProperty))){return this.checkCanEdit(this,r)?(this.properties.includes(i)||(this.properties.push(i),this.suggestedProperties=this.suggestedProperties.filter(a=>a.name!==i.name),r==null||r.add(this,W.Updated)),r==null||r.attemptAutoclose(w.AddProperty,this.id),this):(z.Logger.warn(`[addProperty] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),r==null||r.attemptAutoclose(w.AddProperty,this.id),this)}addSuggestedProperty(i){return this.suggestedProperties.includes(i)||this.suggestedProperties.push(i),this}addSuggestedMethod(i){return this.suggestedMethods.includes(i)||this.suggestedMethods.push(i),this}removeSuggestedProperty(i){return this.suggestedProperties=this.suggestedProperties.filter(r=>r.id!==i.id),this}removeSuggestedMethod(i){return this.suggestedMethods=this.suggestedMethods.filter(r=>r.id!==i.id),this}addAbstractMethod(i,r=this.project.addChangeSet(new q(this.project,N.sessionAuthor,B().toISOString(),this,!0,w.AddAbstractMethod))){return this.checkCanEdit(this,r)?(this.abstractMethods.includes(i)||(this.abstractMethods.push(i),r==null||r.add(this,W.Updated)),r==null||r.attemptAutoclose(w.AddAbstractMethod,this.id),this):(z.Logger.warn(`[addAbstractMethod] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),r==null||r.attemptAutoclose(w.AddAbstractMethod,this.id),this)}removeAbstractMethod(i,r=this.project.addChangeSet(new q(this.project,N.sessionAuthor,B().toISOString(),this,!0,w.RemoveAbstractMethod))){return this.checkCanEdit(this,r)?(this.abstractMethods.includes(i)&&(this.abstractMethods=this.abstractMethods.filter(a=>a.id!==i.id),r==null||r.add(this,W.Updated)),r==null||r.attemptAutoclose(w.RemoveAbstractMethod,this.id),this):(z.Logger.warn(`[removeAbstractMethod] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),r==null||r.attemptAutoclose(w.RemoveAbstractMethod,this.id),this)}initChildren(i=this.project.addChangeSet(new q(this.project,N.sessionAuthor,B().toISOString(),this,!0,"init-children"))){if(this.initialized||this.startedInitialization)return this;if(this.startedInitialization=!0,this.properties=this.initialData.properties.map(r=>{const a=Ae(r,this.project);return a.setParent(this,null),a.initChildren(i),a}),this.methods=this.initialData.methods.map(r=>{const a=Ae(r,this.project);return a.setParent(this,null),a.initChildren(i),a}),this.abstractMethods=this.initialData.abstractMethods.map(r=>{const a=Ae(r,this.project);return a.setParent(this,null),a.initChildren(i),a}),this.initialData.extends&&(this.extends=Ae(this.initialData.extends,this.project)),this.implements=this.initialData.implements.map(r=>Ae(r,this.project)),this.initialData.allPropertiesImplement){const r=Ae(this.initialData.allPropertiesImplement,this.project);r.setParent(this,null),r.initChildren(null),this.setAllPropertiesImplement(r,i)}if(this.initialData.additionalPropertiesDataType){const r=Ae(this.initialData.additionalPropertiesDataType,this.project);r.setParent(this,null),r.initChildren(null),this.setAdditionalPropertiesDataType(r,i)}return this.subscribeToDependencies(),this.afterAllChildrenInitialized(i),i==null||i.attemptAutoclose("init-children",this.id),this}removeUnrecognizedProperties(i=this.project.addChangeSet(new q(this.project,N.sessionAuthor,B().toISOString(),this,!0,"remove-unrecognized-properties"))){const r=[],a=[],c=[],e=[];let f=[...this.properties];f=f.filter(b=>b.parent.id===this.id),f=f.filter(b=>!b.isExtendedProperty);const h=this.implementedPropertiesFromOriginalParents,m=this.getAllPropertiesImplements();return f.filter(b=>this.interactive&&!b.implements.length?!1:!b.implements.find(_=>!!h.find($=>$.id===_.id)||!!m.find($=>$.id===_.id))).forEach(b=>{const g=b.remove({ignoreUpstream:!1},i);c.push(...g.removed),r.push(...g.updated)}),i==null||i.attemptAutoclose("remove-unrecognized-properties",this.id),{updated:C(r),added:C(a),removed:C(c),affected:C(e),self:this}}removeUnrecognizedMethods(i=this.project.addChangeSet(new q(this.project,N.sessionAuthor,B().toISOString(),this,!0,"remove-unrecognized-methods"))){const r=[],a=[],c=[],e=[];let f=[...this.methods];f=f.filter(m=>m.parent.id===this.id),f=f.filter(m=>!m.isExtendedMethod);const h=this.implementedMethodsFromOriginalParents;return f=f.filter(m=>this.interactive&&!m.implements?!1:!h.find(E=>{var b;return E.id===((b=m.implements)==null?void 0:b.id)})),f.forEach(m=>{const E=m.remove({ignoreUpstream:!1},i);c.push(...E.removed),r.push(...E.updated)}),i==null||i.attemptAutoclose("remove-unrecognized-methods",this.id),{updated:C(r),added:C(a),removed:C(c),affected:C(e),self:this}}syncImplementationMethods(i=this.project.addChangeSet(new q(this.project,N.sessionAuthor,B().toISOString(),this,!0,"sync-implementation-methods"))){const r=[],a=[],c=[],e=[],f=this.methods,h=this.implementedMethodsFromOriginalParents,m=[...this.allBaseMethodsFromExtendedAndImplementedEntities,...f];return h.filter(b=>!m.find(_=>{var $;return(($=_.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 _=this.methods.find(L=>{var ie,ee;if(L.name===b.name&&!L.implements)return!0;const j=Wi(this,Ie.CRON_JOB),k=Wi(this,Ie.HTTP_ENDPOINT),G=((ie=L.implements)==null?void 0:ie.id)===re["built-in-base-entity"].BUILT_IN_HTTP_ENDPOINT_ENTITY.methods.handler.id,H=((ee=L.implements)==null?void 0:ee.id)===re["built-in-base-entity"].BUILT_IN_CRON_JOB_ENTITY.methods.handler.id;return!!(j&&!H&&!k&&G||k&&!G&&!j&&H)});if(_&&_.type===d.FunctionDeclaration){_.setImplements(b,i),_.metaSync({name:b.name},i),i==null||i.add(_,W.Updated),i==null||i.add(this,W.Updated);return}const $=b.implementAsFunctionDeclaration(i,this);a.push($),i==null||i.add($,W.Added),this.addMethod($,i)}),this.methods.sort((b,g)=>b.index-g.index).forEach(b=>{b.afterAllChildrenInitialized(i)}),i==null||i.attemptAutoclose("sync-implementation-methods",this.id),{updated:C(r),added:C(a),removed:C(c),affected:C(e),self:this}}syncImplementationProperties(i=this.project.addChangeSet(new q(this.project,N.sessionAuthor,B().toISOString(),this,!0,"sync-implementation-properties"))){const r=[],a=[],c=[],e=[],f=this.properties,h=this.implementedPropertiesFromOriginalParents.filter(E=>!this.allBasePropertiesFromExtendedAndImplementedEntities.find(g=>!!g.implements.find(_=>_.id===E.id))),m=[...this.allBasePropertiesFromExtendedAndImplementedEntities,...f];return h.forEach(E=>{const b=m.find(L=>!!L.implements.find(j=>j.id===E.id));if(b){const{updated:L,added:j,removed:k,affected:G}=b.syncWithImplementation(i);r.push(...L),a.push(...j),c.push(...k),e.push(...G);return}if(this.properties.find(L=>!!L.implements.find(j=>j.id===E.id)))return;const _=this.properties.find(L=>L.name===E.name&&!!L.abstract&&!L.implements);if(_){_.addImplementation(E,i),_.metaSync({abstract:!1},i),_.afterAllChildrenInitialized(i);return}const $=E.implement(this,i,N.UUID.uuid());a.push($),i==null||i.add($,W.Added)}),this.properties.find(E=>{var b;return E.id===((b=this.allPropertiesImplement)==null?void 0:b.id)})&&this.removeAllPropertiesImplement(i),i==null||i.attemptAutoclose("sync-implementation-properties",this.id),{updated:C(r),added:C(a),removed:C(c),affected:C(e),self:this}}addExtendedMethods(i=this.project.addChangeSet(new q(this.project,N.sessionAuthor,B().toISOString(),this,!0,"add-extended-methods"))){const r=[],a=[],c=[],e=[],f=this.methods,m=this.extendedMethodsFromOriginalParents.filter(b=>b.type===d.FunctionDeclaration),E=new Set(f.filter(b=>{var g;return!!((g=b.extends)!=null&&g.id)}).map(b=>b.extends.id));return m.forEach(b=>{if(E.has(b.id))return;E.add(b.id);const g=b.clone(i,this,N.UUID.uuid());g.setExtends(b,i),g.initChildren(i),a.push(g),i==null||i.add(g,W.Added),this.addMethod(g,i)}),i==null||i.attemptAutoclose("add-extended-methods",this.id),{updated:C(r),added:C(a),removed:C(c),affected:C(e),self:this}}addExtendedProperties(i=this.project.addChangeSet(new q(this.project,N.sessionAuthor,B().toISOString(),this,!0,"add-extended-properties"))){const r=[],a=[],c=[],e=[],f=this.properties,h=this.extendedPropertiesFromOriginalParents,m=h.filter(b=>h.find(_=>!!_.implements.find($=>$.id===b.id))?!1:!b.abstract),E=new Set(f.filter(b=>{var g;return!!((g=b.extends)!=null&&g.id)}).map(b=>b.extends.id));return m.forEach(b=>{if(E.has(b.id))return;E.add(b.id);const g=b.clone(i,this,N.UUID.uuid());g.setExtends(b,i),g.initChildren(i),a.push(g),i==null||i.add(g,W.Added),this.addProperty(g,i)}),[...this.properties].forEach(b=>{if(b.extends)return;if(m.find(_=>_.name===b.name&&_.implements.every($=>!!b.implements.find(L=>L.id===$.id)))){const _=b.remove({ignoreUpstream:!1},i);c.push(..._.removed),r.push(..._.updated)}}),this.properties.forEach(b=>{const g=b.afterAllChildrenInitialized(i);r.push(...g.updated),e.push(...g.affected),a.push(...g.added),c.push(...g.removed)}),i==null||i.attemptAutoclose("add-extended-properties",this.id),{updated:C(r),added:C(a),removed:C(c),affected:C(e),self:this}}addSuggestions(){return this.implements.forEach(i=>{dUe(this,i).forEach(c=>{const e=c.toJSON();e.id=`_suggestion--parent--${this.id}--${c.id}`;const f=Ae(e,this.project);f.suggestion=!0,f.setParent(this,null),f.initChildren(null),this.addSuggestedProperty(f)}),uUe(this,i).forEach(c=>{const e=`_suggestion--parent--${this.id}--${c.id}`,f=c.implementAsFunctionDeclaration(null,this,e),h=Ae(f,this.project);if(h.suggestion=!0,h.setParent(this,null),h.initChildren(null),this.methods=this.methods.filter(m=>m.id!==e),h.inputs.forEach(m=>{m.suggestion=!0}),h.returnStatements.length){const m=h.returnStatements[0];m.suggestion=!0,m.outputs.forEach(E=>{E.suggestion=!0})}this.addSuggestedMethod(h)})}),this}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this.project.subscribedDefinitionEntities.add(this.id),this}unsubscribe(){return this.project.unsubscribeInstance(this),this.project.subscribedDefinitionEntities.delete(this.id),this}metaSync(i,r=this.project.addChangeSet(new q(this.project,N.sessionAuthor,B().toISOString(),this,!0,"meta-sync"))){const a=Wr(this,i,r),c=Hr(this,a),e=this.toMeta();return this.name=a.name!==void 0?a.name:e.name,this.codeName=a.codeName!==void 0?a.codeName:e.codeName,this.description=a.description!==void 0?a.description:e.description,this.x=a.x||e.x,this.y=a.y||e.y,this.static=a.static!==void 0?a.static:this.static,this.abstract=a.abstract!==void 0?a.abstract:this.abstract,this.additionalProperties=a.additionalProperties!==void 0?a.additionalProperties:e.additionalProperties,super.baseMetaSync(a,this,r),a.deleted===!0&&!e.deleted?r==null||r.add(this,W.Removed):a.deleted===!1&&e.deleted?r==null||r.add(this,W.Added):c&&(r==null||r.add(this,W.Updated)),r==null||r.attemptAutoclose("meta-sync",this.id),this}async APILoad(i=Se,...r){return await _i.repository.APILoad(this.id,...r),this}async APICreate(i=Se,...r){return await _i.repository.APICreate(this.toShallowJSON(),...r),this}async APIUpdate(i=Se,...r){return await _i.repository.APIUpdate(this.toShallowJSON(),...r),this}async APIDelete(i=Se,...r){return await _i.repository.APIDelete(this.toShallowJSON(),...r),this}async APIClone(i=Se,...r){return await _i.repository.APIClone(this.id,...r),this}async APILoadVersion(i=Se,r,...a){return await _i.repository.APILoadVersion(this.id,r,...a)}removeFromParent(i=this.project.addChangeSet(new q(this.project,N.sessionAuthor,B().toISOString(),this,!0,w.RemoveFromParent))){if(!this.checkCanEdit(this,i))return z.Logger.warn(`[removeFromParent] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(w.RemoveFromParent,this.id),{added:[],updated:[],removed:[],affected:[],self:this};const r=[],a=[],c=[],e=[];if(this.parent.type===d.Project)this.parent.removeDefinitionEntity(this);else if(this.parent.type===d.DataType&&this.parent.entity&&this.parent.entity.id===this.id){const f=this.parent.setEntity(null,i);r.push(f)}return i==null||i.attemptAutoclose(w.RemoveFromParent,this.id),{added:C(c),updated:C(r),removed:C(a),affected:C(e),self:this}}remove({ignoreUpstream:i}={ignoreUpstream:!1},r=this.project.addChangeSet(new q(this.project,N.sessionAuthor,B().toISOString(),this,!0,w.RemoveEntity))){var h;if(!this.checkCanDelete(this,r))return z.Logger.warn(`[remove] User is not allowed to delete or edit this ${this.type} entity with id: ${this.id}`),r==null||r.event({id:`${w.RemoveEntity}-${this.id}--${Be.ActionOwnerEntityNonDeletable}`,action:w.RemoveEntity,owner:this,errorReason:Be.ActionOwnerEntityNonDeletable,rootAction:((h=r==null?void 0:r.self)==null?void 0:h.id)===this.id&&(r==null?void 0:r.autoCloseActionName)===w.RemoveEntity}),r==null||r.attemptAutoclose(w.RemoveEntity,this.id),{added:[],updated:[],removed:[],affected:[],self:this};const a=[],c=[],e=[],f=[];if(r!=null&&r.hasRemoved(this.id))return r==null||r.attemptAutoclose(w.RemoveEntity,this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(c.push(this),this.unsubscribe(),this.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},r),Object.values(this.detachedDependents).forEach(m=>{const{updated:E,removed:b,added:g}=m.entity.onDetachedDependencyRemoved(this,m.field,r);a.push(...E),c.push(...b),e.push(...g)}),this.properties.forEach(m=>{const{updated:E,removed:b}=m.remove({ignoreUpstream:!0},r);a.push(...E),c.push(...b)}),this.methods.forEach(m=>{const{updated:E,removed:b}=m.remove({ignoreUpstream:!0},r);a.push(...E),c.push(...b)}),this.abstractMethods.forEach(m=>{const{updated:E,removed:b}=m.remove({ignoreUpstream:!0},r);a.push(...E),c.push(...b)}),this.suggestedProperties.forEach(m=>{const{updated:E,removed:b}=m.remove({ignoreUpstream:!0},r);a.push(...E),c.push(...b)}),this.suggestedMethods.forEach(m=>{const{updated:E,removed:b}=m.remove({ignoreUpstream:!0},r);a.push(...E),c.push(...b)}),!i){const m=this.removeFromParent(r);e.push(...m.added),a.push(...m.updated),c.push(...m.removed),f.push(...m.affected)}return r==null||r.attemptAutoclose(w.RemoveEntity,this.id),{added:C(e),updated:C(a),removed:C(c),affected:C(f),self:this}}restore({}={},i=this.project.addChangeSet(new q(this.project,N.sessionAuthor,B().toISOString(),this,!0,w.RestoreEntity))){if(!this.checkCanEdit(this,i))return z.Logger.warn(`[restore] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(w.RestoreEntity,this.id),{added:[],updated:[],removed:[],affected:[],self:this};const r=[],a=[],c=[],e=[];return i!=null&&i.hasAdded(this.id)?(i==null||i.attemptAutoclose(w.RestoreEntity,this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},i),Object.values(this.detachedDependents).forEach(f=>{const{updated:h,removed:m,added:E}=f.entity.onDetachedDependencyRestored(this,f.field,i);a.push(...h),c.push(...m),r.push(...E)}),this.properties.forEach(f=>{const{updated:h}=f.restore({},i);a.push(...h)}),this.methods.forEach(f=>{const{updated:h}=f.restore({},i);a.push(...h)}),this.abstractMethods.forEach(f=>{const{updated:h}=f.restore({},i);a.push(...h)}),this.suggestedProperties.forEach(f=>{const{updated:h}=f.restore({},i);a.push(...h)}),this.suggestedMethods.forEach(f=>{const{updated:h}=f.restore({},i);a.push(...h)}),i==null||i.attemptAutoclose(w.RestoreEntity,this.id),{added:C(r),updated:C(a),removed:C(c),affected:C(e),self:this})}toFlat(i=new Set){var a;return i.has(this.id)?[]:(i.add(this.id),[this,...((a=this.extends)==null?void 0:a.toFlat(i))||[],...this.implements.flatMap(c=>c.toFlat(i)),...this.properties.flatMap(c=>c.toFlat(i)),...this.methods.flatMap(c=>c.toFlat(i)),...this.abstractMethods.flatMap(c=>c.toFlat(i)),...this.parent.toFlat(i)])}toFlatIds(i=new Set){var a;return i.has(this.id)?[]:(i.add(this.id),[this.id,...((a=this.extends)==null?void 0:a.toFlatIds(i))||[],...this.implements.flatMap(c=>c.toFlatIds(i)),...this.properties.flatMap(c=>c.toFlatIds(i)),...this.methods.flatMap(c=>c.toFlatIds(i)),...this.abstractMethods.flatMap(c=>c.toFlatIds(i)),...this.parent.toFlatIds(i)])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,codeName:this.codeName,description:this.description,static:this.static,abstract:this.abstract,x:this.x,y:this.y,type:this.type,editable:this.editable,deletable:this.deletable,additionalProperties:this.additionalProperties,name:this.name}}toJSON(i=new Set){var r,a,c;return i.has(this.id)?this.toReference():(i.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,editable:this.editable,deletable:this.deletable,name:this.name,codeName:this.codeName,description:this.description,x:this.x,y:this.y,static:this.static,abstract:this.abstract,additionalProperties:this.additionalProperties,allPropertiesImplement:((r=this.allPropertiesImplement)==null?void 0:r.toJSON(i))||null,additionalPropertiesDataType:((a=this.additionalPropertiesDataType)==null?void 0:a.toJSON(i))||null,properties:this.properties.map(e=>e.toJSON(i)),methods:this.methods.map(e=>e.toJSON(i)),abstractMethods:this.abstractMethods.map(e=>e.toJSON(i)),implements:this.implements.map(e=>e.toJSON(i)),extends:((c=this.extends)==null?void 0:c.toJSON(i))||null,parent:this.parent.toReference()})}toJSONClone(i=nt){var a,c,e,f,h,m,E,b,g,_;let r;return(a=i.seenEntityMaps)!=null&&a.has(this.id)?r=i.seenEntityMaps.get(this.id):(r=i.newId||Xr(this,this.project,i.uuidStrategy),i.seenEntityMaps&&i.seenEntityMaps.set(this.id,r)),(c=i.seenEntities)!=null&&c.has(r)||(e=i.seenEntities)!=null&&e.has(this.id)?this.toReference({seenEntityMaps:i.seenEntityMaps}):((f=i.seenEntities)==null||f.add(r),(h=i.seenEntities)==null||h.add(this.id),{id:r,version:N.UUID.uuid(),createdAt:i.timestamp||B().toISOString(),author:N.sessionAuthor,previousVersion:null,deleted:!1,type:this.type,editable:this.editable,deletable:this.deletable,name:this.name,codeName:this.codeName,description:this.description,x:this.x,y:this.y,static:this.static,abstract:this.abstract,additionalProperties:this.additionalProperties,allPropertiesImplement:((m=this.allPropertiesImplement)==null?void 0:m.toJSONClone(i))||null,additionalPropertiesDataType:((E=this.additionalPropertiesDataType)==null?void 0:E.toJSONClone(i))||null,properties:this.properties.map($=>$.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?(g=this.extends)==null?void 0:g.toJSON(i.seenEntities):(_=this.extends)==null?void 0:_.toJSONClone({...i,newId:null}),parent:this.parent.toReference({seenEntityMaps:i.seenEntityMaps})})}toReference(i=nt){var a;let r=this.id;return(a=i.seenEntityMaps)!=null&&a.has(this.id)&&(r=i.seenEntityMaps.get(this.id)),{id:r+"--"+N.UUID.uuid()+"--ref",type:d.GenericReference,entityId:r,version:this.version,entityType:this.type}}toShallowJSON(i=nt){var a,c,e,f;let r=this.id;return(a=i.seenEntityMaps)!=null&&a.has(this.id)&&(r=i.seenEntityMaps.get(this.id)),{id:r,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,name:this.name,codeName:this.codeName,description:this.description,type:this.type,editable:this.editable,deletable:this.deletable,x:this.x,y:this.y,static:this.static,abstract:this.abstract,additionalProperties:this.additionalProperties,allPropertiesImplement:((c=this.allPropertiesImplement)==null?void 0:c.toReference(i))||null,additionalPropertiesDataType:((e=this.additionalPropertiesDataType)==null?void 0:e.toReference(i))||null,properties:this.properties.map(h=>h.toReference(i)),methods:this.methods.map(h=>h.toReference(i)),abstractMethods:this.abstractMethods.map(h=>h.toReference(i)),implements:this.implements.map(h=>h.toReference(i)),extends:((f=this.extends)==null?void 0:f.toReference(i))||null,parent:this.parent.toReference(i)}}toFlatJSON(i=new Set){var a,c,e;return i.has(this.id)?[]:(i.add(this.id),[this.toShallowJSON(),...this.properties.flatMap(f=>f.toFlatJSON(i)),...this.methods.flatMap(f=>f.toFlatJSON(i)),...this.abstractMethods.flatMap(f=>f.toFlatJSON(i)),...this.implements.flatMap(f=>f.toFlatJSON(i)),...((a=this.extends)==null?void 0:a.toFlatJSON(i))||[],...this.parent.toFlatJSON(i),...((c=this.additionalPropertiesDataType)==null?void 0:c.toFlatJSON(i))||[],...((e=this.allPropertiesImplement)==null?void 0:e.toFlatJSON(i))||[]])}toGenerationTarget(i=nt){var c,e,f;const r=this.parent.type===d.Project?void 0:(c=i.seenEntityMaps)!=null&&c.has(this.parent.id)?i.seenEntityMaps.get(this.parent.id):this.parent.id;let a=this.id;return(e=i.seenEntityMaps)!=null&&e.has(this.id)&&(a=i.seenEntityMaps.get(this.id)),{id:a,name:this.name,description:this.description,type:this.type,static:this.static,abstract:this.abstract,extends:(f=this.extends)==null?void 0:f.id,additionalProperties:this.additionalProperties,implements:this.implements.map(h=>h.id),parent:r}}toFlatGenerationTarget(i=new Set){var a,c,e;return i.has(this.id)?[]:(i.add(this.id),[this.toGenerationTarget(),...this.properties.flatMap(f=>f.toFlatGenerationTarget(i)),...this.methods.flatMap(f=>f.toFlatGenerationTarget(i)),...this.abstractMethods.flatMap(f=>f.toFlatGenerationTarget(i)),...this.implements.filter(f=>f.type===d.DefinitionEntity).flatMap(f=>f.toFlatGenerationTarget(i)),...((a=this.extends)==null?void 0:a.toFlatGenerationTarget(i))||[],...this.parent.toFlatGenerationTarget(i),...((c=this.additionalPropertiesDataType)==null?void 0:c.toFlatGenerationTarget(i))||[],...((e=this.allPropertiesImplement)==null?void 0:e.toFlatGenerationTarget(i))||[]])}clearErrors(){var i,r;return this.errors=[],this.properties.forEach(a=>a.clearErrors()),this.methods.forEach(a=>a.clearErrors()),this.abstractMethods.forEach(a=>a.clearErrors()),(i=this.additionalPropertiesDataType)==null||i.clearErrors(),(r=this.allPropertiesImplement)==null||r.clearErrors(),this}validate(){return this.errors=oUe(this),{success:!0}}async validateAsync(i={}){const r=z.YieldTracker.from(i);return this.errors=await lUe(this,{tracker:r}),{success:!0}}getErrors(){var r,a;return[...this.errors,...this.properties.flatMap(c=>c.getErrors()),...this.methods.flatMap(c=>c.getErrors()),...this.abstractMethods.flatMap(c=>c.getErrors()),...((r=this.additionalPropertiesDataType)==null?void 0:r.getErrors())||[],...((a=this.allPropertiesImplement)==null?void 0:a.getErrors())||[]]}async getErrorsAsync(i={}){const r=z.YieldTracker.from(i),a=[...this.errors];await r.tick();for(const c of this.properties)a.push(...await c.getErrorsAsync({tracker:r}));for(const c of this.methods)a.push(...await c.getErrorsAsync({tracker:r}));for(const c of this.abstractMethods)a.push(...await c.getErrorsAsync({tracker:r}));return this.additionalPropertiesDataType&&a.push(...await this.additionalPropertiesDataType.getErrorsAsync({tracker:r})),this.allPropertiesImplement&&a.push(...await this.allPropertiesImplement.getErrorsAsync({tracker:r})),a}getShallowErrors(){return this.errors}clone(i=this.project.addChangeSet(new q(this.project,N.sessionAuthor,B().toISOString(),this,!0,w.CloneEntity)),r=null,a=null,c=!0){var j,k,G;const e=Br(r,this),f=this.toJSON(),h=a||N.UUID.uuid(),m=r||this.parent;f.properties=[],f.methods=[],f.abstractMethods=[];const E=h.split("-id"),b=E[E.length-1||0]||h;f.id=h,f.version=N.UUID.uuid(),f.createdAt=(i==null?void 0:i.timestamp)||B().toISOString(),f.author=(i==null?void 0:i.author)||"1",f.previousVersion=null,f.deleted=!1,f.editable=!0,f.deletable=!0,f.parent=m.toReference();const g=Yi(f,e);g.hydrateAncestors(),g.setParent(m,i),c&&(g.subscribe(),g.addSelfToProject(i)),g.initChildren(i),i==null||i.add(g,W.Added);const _=(j=this.properties)==null?void 0:j.map(H=>this.project.diggestedBuiltInBaseEntitiesIds.has(H.id)?H:H.clone(i,g,N.UUID.uuid(),c));g.properties=_;const $=(k=this.methods)==null?void 0:k.map((H,ie)=>this.project.diggestedBuiltInBaseEntitiesIds.has(H.id)?H:H.clone(i,g,b+"-method-"+ie+"-id",c));g.methods=$;const L=(G=this.abstractMethods)==null?void 0:G.map((H,ie)=>this.project.diggestedBuiltInBaseEntitiesIds.has(H.id)?H:H.clone(i,g,b+"-abstract-method-"+ie+"-id",c));if(g.abstractMethods=L,this.additionalPropertiesDataType)if(this.project.diggestedBuiltInBaseEntitiesIds.has(this.additionalPropertiesDataType.id))g.setAdditionalPropertiesDataType(this.additionalPropertiesDataType,i);else{const H=this.additionalPropertiesDataType.clone(i,g,N.UUID.uuid(),c);g.setAdditionalPropertiesDataType(H,i)}if(this.allPropertiesImplement)if(this.project.diggestedBuiltInBaseEntitiesIds.has(this.allPropertiesImplement.id))g.setAllPropertiesImplement(this.allPropertiesImplement,i);else{const H=this.allPropertiesImplement.clone(i,g,N.UUID.uuid(),c);g.setAllPropertiesImplement(H,i)}return i==null||i.attemptAutoclose(w.CloneEntity,this.id),g}getFunctionDeclaration(i){return this.methods.find(r=>r.id===i)}implement(i,r=this.project.addChangeSet(new q(this.project,N.sessionAuthor,B().toISOString(),this,!0,"implement-definition-entity")),a){const c=YR(this,i,r,a);return r==null||r.attemptAutoclose("implement-definition-entity",this.id),c}getAllPropertiesImplements(){var r;const i=[];return this.allPropertiesImplement&&i.push(this.allPropertiesImplement),i.push(...((r=this.extends)==null?void 0:r.getAllPropertiesImplements())||[],...this.implements.flatMap(a=>a.getAllPropertiesImplements())),i}getAllInteractiveMethods(){var e;const i=this.implements.filter(f=>f.type===d.DefinitionEntity||f.type===d.BuiltInBaseEntity&&f.interactive),r=((e=this.extends)==null?void 0:e.getAllInteractiveMethods())||[],a=i.flatMap(f=>f.getAllInteractiveMethods());return C([...this.methods,...r,...a])}inferFromInputs(i,r=this.project.addChangeSet(new q(this.project,N.sessionAuthor,B().toISOString(),this,!0,"infer-definition-entity-from-inputs"))){const a=[],c=[],e=[],f=[];if(this.parent.type!==d.DataType||!this.parent.inferred)return r==null||r.attemptAutoclose("infer-definition-entity-from-inputs",this.id),{added:[],updated:[],removed:[],affected:[],self:this};const h=[];i.forEach(b=>{h.find(_=>se(_,this.project)===se(b,this.project))||h.push(b)});const m=this.properties.filter(b=>!b.dataType);h.forEach(b=>{var G,H,ie;const g=m.find(ee=>se(ee,this.project)===se(b,this.project));if(!g)return;const $=yr(b.parent).getMasterInputWithValueWriterFromAllInstances(b),L=jd($,r),j=L==null?void 0:L.clone(r,g,N.UUID.uuid(),!0);j&&((G=g.dataType)==null||G.merge(j,r),j.id!==((H=g.dataType)==null?void 0:H.id)&&j.remove({ignoreUpstream:!1},r),g.dataType&&(g.dataType.metaSync({inferred:!0,like:!0},r),g.setDataType(g.dataType,r),r==null||r.add(g,W.Affected)));let k=null;if(b.declaration&&g.id!==((ie=b.declaration)==null?void 0:ie.id)&&(k=b.declaration),b.setDeclaration(g,r),r==null||r.add(b,W.Updated),k){const{updated:ee,removed:ue}=k.remove({ignoreUpstream:!1},r);c.push(...ee),e.push(...ue)}});const E=[];return h.forEach(b=>{if(!b.declaration){E.push(b);return}}),E.length===0?(r==null||r.attemptAutoclose("infer-definition-entity-from-inputs",this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(E.forEach(b=>{var ie,ee,ue,ae,de;const g=this.properties.find(ce=>se(ce,this.project)===se(b,this.project));if(g){if(b.setDeclaration(g,r),!g.getDataType(r)){const ne=yr(b.parent).getMasterInputWithValueWriterFromAllInstances(b),le=jd(ne),Q=le==null?void 0:le.clone(r,g,N.UUID.uuid(),!0);Q&&((ie=g.dataType)==null||ie.merge(Q,r),Q.id!==((ee=g.dataType)==null?void 0:ee.id)&&Q.remove({ignoreUpstream:!1},r),g.dataType&&(g.dataType.metaSync({inferred:!0,like:!0},r),g.setDataType(g.dataType,r),r==null||r.add(g,W.Affected)))}return}const _=se(b,this.project),$=b.codeName||ef(b,this.project)||Yo(ir(_)),L=ts.new(r);L.parent=this.toReference(),L.index=b.index,L.name=_,L.codeName=$,L.description=b.description;const j=Ae(L,this.project);j.hydrateAncestors(),r==null||r.add(j,W.Added),j.setParent(this,r),j.initChildren(r);const G=yr(b.parent).getMasterInputWithValueWriterFromAllInstances(b),H=jd(G);if(H&&H.id!==((ue=j.dataType)==null?void 0:ue.id)){const ce=H==null?void 0:H.clone(r,j,N.UUID.uuid(),!0);ce&&((ae=j.dataType)==null||ae.merge(ce,r),ce.id!==((de=j.dataType)==null?void 0:de.id)&&ce.remove({ignoreUpstream:!1},r),j.dataType&&(j.dataType.metaSync({inferred:!0,like:!0},r),j.setDataType(j.dataType,r),r==null||r.add(j,W.Affected)))}return this.addProperty(j,r),b.setDeclaration(j,r),r==null||r.add(b,W.Updated),j}),r==null||r.attemptAutoclose("infer-definition-entity-from-inputs",this.id),{added:C(a),updated:C(c),removed:C(e),affected:C(f),self:this})}getRawDefaultValue(){const i={};return this.properties.forEach(r=>{var e;if(!Gg(r))return;const a=se(r,this.project),c=r.codeName||ef(r,this.project)||Yo(ir(a));i[c]=((e=r.getDefaultValue())==null?void 0:e.value)||null}),i}getActiveRawDefaultValue(){const i={};return this.properties.forEach(r=>{var f;if(!Gg(r))return;const a=se(r,this.project),c=r.codeName||ef(r,this.project)||Yo(ir(a)),e=(f=this.project.requestActiveDynamicValue(r,!0))==null?void 0:f.value;i[c]=(e==null?void 0:e.value)||null}),i}setAdditionalPropertiesDataType(i,r=this.project.addChangeSet(new q(this.project,N.sessionAuthor,B().toISOString(),this,!0,w.SetAdditionalPropertiesDataType))){if(!this.checkCanEdit(this,r))return z.Logger.warn(`[setAdditionalPropertiesDataType] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),r==null||r.attemptAutoclose(w.SetAdditionalPropertiesDataType,this.id),this;const a=this.additionalPropertiesDataType;return(a==null?void 0:a.id)!==(i==null?void 0:i.id)&&(a==null||a.remove({ignoreUpstream:!0},r),this.additionalPropertiesDataType=i,this.subscribeToDependencies(),r==null||r.add(this,W.Affected)),r==null||r.attemptAutoclose(w.SetAdditionalPropertiesDataType,this.id),this}removeAdditionalPropertiesDataType(i=this.project.addChangeSet(new q(this.project,N.sessionAuthor,B().toISOString(),this,!0,w.RemoveAllPropertiesImplement))){return this.checkCanEdit(this,i)?(this.additionalPropertiesDataType&&(this.additionalPropertiesDataType.remove({ignoreUpstream:!0},i),i==null||i.add(this,W.Affected),this.additionalPropertiesDataType=null),i==null||i.attemptAutoclose(w.RemoveAllPropertiesImplement,this.id),this):(z.Logger.warn(`[removeAdditionalPropertiesDataType] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(w.RemoveAllPropertiesImplement,this.id),this)}setAllPropertiesImplement(i,r=this.project.addChangeSet(new q(this.project,N.sessionAuthor,B().toISOString(),this,!0,w.SetAllPropertiesImplement))){if(!this.checkCanEdit(this,r))return z.Logger.warn(`[setAllPropertiesImplement] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),r==null||r.attemptAutoclose(w.SetAllPropertiesImplement,this.id),this;const a=this.allPropertiesImplement;return(a==null?void 0:a.id)!==(i==null?void 0:i.id)&&(a==null||a.remove({ignoreUpstream:!0},r),this.allPropertiesImplement=i,this.subscribeToDependencies(),r==null||r.add(this,W.Affected)),r==null||r.attemptAutoclose(w.SetAllPropertiesImplement,this.id),this}removeAllPropertiesImplement(i=this.project.addChangeSet(new q(this.project,N.sessionAuthor,B().toISOString(),this,!0,w.RemoveAllPropertiesImplement))){return this.checkCanEdit(this,i)?(this.allPropertiesImplement&&(this.properties.find(r=>{var a;return r.id===((a=this.allPropertiesImplement)==null?void 0:a.id)})||this.allPropertiesImplement.remove({ignoreUpstream:!0},i),i==null||i.add(this,W.Affected),this.allPropertiesImplement=null),i==null||i.attemptAutoclose(w.RemoveAllPropertiesImplement,this.id),this):(z.Logger.warn(`[removeAllPropertiesImplement] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(w.RemoveAllPropertiesImplement,this.id),this)}};R(_i,"repository",{APICreate:async(i,...r)=>i,APIUpdate:async(i,...r)=>i,APIDelete:async(i,...r)=>i,APIClone:async(i,...r)=>{},APILoad:async(i,...r)=>null,APILoadVersion:async(i,r,...a)=>null}),R(_i,"type",d.DefinitionEntity),R(_i,"USER_MANAGED_PARENT_TYPES",[d.Project,d.DataType]),R(_i,"PARENT_TYPES",[..._i.USER_MANAGED_PARENT_TYPES]),R(_i,"MUTABLE_BASE_PROPERTIES",["name","codeName","description","static","abstract","additionalProperties"]),R(_i,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),R(_i,"BASE_PROPERTIES",[..._i.MUTABLE_BASE_PROPERTIES,..._i.INMUTABLE_BASE_PROPERTIES]),R(_i,"MUTABLE_META_PROPERTIES",[..._i.MUTABLE_BASE_PROPERTIES,"x","y"]),R(_i,"INMUTABLE_META_PROPERTIES",[..._i.INMUTABLE_BASE_PROPERTIES]),R(_i,"META_PROPERTIES",[..._i.MUTABLE_META_PROPERTIES,..._i.INMUTABLE_META_PROPERTIES]),R(_i,"MUTABLE_UPSTREAM_PROPERTIES",["extends","implements"]),R(_i,"INMUTABLE_UPSTREAM_PROPERTIES",["parent"]),R(_i,"UPSTREAM_PROPERTIES",[..._i.MUTABLE_UPSTREAM_PROPERTIES,..._i.INMUTABLE_UPSTREAM_PROPERTIES]),R(_i,"MUTABLE_DOWNSTREAM_PROPERTIES",["properties","methods","abstractMethods","allPropertiesImplement","additionalPropertiesDataType"]),R(_i,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),R(_i,"DOWNSTREAM_PROPERTIES",[..._i.MUTABLE_DOWNSTREAM_PROPERTIES,..._i.INMUTABLE_DOWNSTREAM_PROPERTIES]),R(_i,"PROPERTIES",[..._i.META_PROPERTIES,..._i.UPSTREAM_PROPERTIES,..._i.DOWNSTREAM_PROPERTIES]);let Ds=_i;async function b_i(l,p={}){const i=z.YieldTracker.from(p),r=[],a=kt(l.errors,r);return await i.tick(),a}function A_i(l){const p=[];return kt(l.errors,p)}const Fg=class Fg extends cx{constructor(i,r){super(i);R(this,"initialData");R(this,"id");R(this,"name");R(this,"description",null);R(this,"type",d.PrimitiveEntity);R(this,"static");R(this,"abstract");R(this,"properties",[]);R(this,"methods",[]);R(this,"abstractMethods",[]);R(this,"extends",null);R(this,"errors",[]);R(this,"project");this.initialData=i,this.project=r,this.id=i.id,this.name=i.name,this.description=i.description,this.static=i.static,this.abstract=i.abstract,this.properties=this.initialData.properties.map(a=>{const c=Ae(a,this.project);return c.setParent(this,null),c.initChildren(null),c}),this.methods=this.initialData.methods.map(a=>{const c=Ae(a,this.project);return c.parent=this,c}),this.abstractMethods=this.initialData.abstractMethods.map(a=>{const c=Ae(a,this.project);return c.parent=this,c}),this.initialData.extends&&(this.extends=Ae(this.initialData.extends,this.project))}get allMethods(){return C([...this.ownDeclaredMethods,...this.allBaseMethodsFromOriginalParents])}get allProperties(){return C([...this.ownDeclaredProperties,...this.allBasePropertiesFromOriginalParents])}get allBaseMethodsFromOriginalParents(){var a;const i=((a=this.extends)==null?void 0:a.allMethods)||[],r=[...i].filter(c=>!i.some(e=>e.id!==c.id));return C(r)}get allBasePropertiesFromOriginalParents(){var a;const i=((a=this.extends)==null?void 0:a.allProperties)||[],r=[...i].filter(c=>!i.some(e=>{var f;return e.id!==c.id&&(e.implements.find(h=>h.id===c.id)||((f=e.extends)==null?void 0:f.id)===c.id)}));return C(r)}get allBasePropertiesFromExtendedAndImplementedEntities(){var a,c;const i=[...((a=this.extends)==null?void 0:a.ownDeclaredProperties)||[],...((c=this.extends)==null?void 0:c.allBasePropertiesFromExtendedAndImplementedEntities)||[]].filter(e=>!e.abstract),r=[...i].filter(e=>!i.some(f=>{var h;return f.id!==e.id&&(f.implements.find(m=>m.id===e.id)||((h=f.extends)==null?void 0:h.id)===e.id)}));return C(r)}get extendedPropertiesFromOriginalParents(){var a,c;const i=[...((a=this.extends)==null?void 0:a.ownDeclaredProperties)||[],...((c=this.extends)==null?void 0:c.extendedPropertiesFromOriginalParents)||[]].filter(e=>!e.abstract),r=[...i].filter(e=>!i.some(f=>{var h;return f.id!==e.id&&(f.implements.find(m=>m.id===e.id)||((h=f.extends)==null?void 0:h.id)===e.id)}));return C(r)}get implementedPropertiesFromOriginalParents(){return C([...(this.extends?[this.extends]:[]).reduce((i,r)=>{const a=r.implementedPropertiesFromOriginalParents,c=[...r.ownDeclaredProperties].filter(h=>!!h.abstract),e=[...a,...c,...i];return[...e].filter(h=>!!!e.find(E=>{var b;return((b=E.extends)==null?void 0:b.id)===h.id||E.implements.find(g=>g.id===h.id)}))},[])])}get extendedProperties(){return this.properties.filter(i=>i.isExtendedProperty)}get ownDeclaredMethods(){return[...this.methods]}get ownDeclaredProperties(){return this.properties.filter(i=>!i.isExtendedProperty)}subscribe(){return this.project.subscribeBuiltInInstance(this),this}unsubscribe(){return this.project.unsubscribeBuiltInInstance(this),this}async APILoad(i=Se,...r){return await Fg.repository.APILoad(this.id,...r),this}toFlat(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this,...this.properties.flatMap(a=>a.toFlat(i)),...this.methods.flatMap(a=>a.toFlat(i)),...this.abstractMethods.flatMap(a=>a.toFlat(i))])}toFlatIds(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.id,...this.properties.flatMap(a=>a.toFlatIds(i)),...this.methods.flatMap(a=>a.toFlatIds(i)),...this.abstractMethods.flatMap(a=>a.toFlatIds(i))])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,description:this.description,static:this.static,abstract:this.abstract,type:this.type,name:this.name}}toJSON(i=new Set){var r;return i.has(this.id)?this.toReference():(i.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,static:this.static,abstract:this.abstract,properties:this.properties.map(a=>a.toJSON(i)),methods:this.methods.map(a=>a.toJSON(i)),abstractMethods:this.abstractMethods.map(a=>a.toJSON(i)),extends:((r=this.extends)==null?void 0:r.toJSON(i))||null})}toReference(i=nt){return{id:this.id+"--"+N.UUID.uuid()+"--ref",type:d.GenericReference,entityId:this.id,version:this.version,entityType:this.type}}toShallowJSON(i=nt){var r;return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,abstract:this.abstract,static:this.static,properties:this.properties.map(a=>a.toReference()),methods:this.methods.map(a=>a.toReference()),abstractMethods:this.abstractMethods.map(a=>a.toReference()),extends:((r=this.extends)==null?void 0:r.toReference())||null}}toFlatJSON(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.toShallowJSON(),...this.properties.flatMap(a=>a.toFlatJSON(i)),...this.methods.flatMap(a=>a.toFlatJSON(i)),...this.abstractMethods.flatMap(a=>a.toFlatJSON(i))])}toGenerationTarget(i=nt){var r;return{id:this.id,type:this.type,name:this.name,description:this.description,static:this.static,abstract:this.abstract,extends:(r=this.extends)==null?void 0:r.id}}toFlatGenerationTarget(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.toGenerationTarget(),...this.properties.flatMap(a=>a.toFlatGenerationTarget(i)),...this.methods.flatMap(a=>a.toFlatGenerationTarget(i)),...this.abstractMethods.flatMap(a=>a.toFlatGenerationTarget(i))])}clearErrors(){return this.errors=[],this.properties.forEach(i=>i.clearErrors()),this.methods.forEach(i=>i.clearErrors()),this.abstractMethods.forEach(i=>i.clearErrors()),this}validate(){return this.errors=A_i(this),{success:!0}}async validateAsync(i={}){const r=z.YieldTracker.from(i);return this.errors=await b_i(this,{tracker:r}),{success:!0}}getErrors(){return[...this.errors,...this.properties.flatMap(r=>r.getErrors()),...this.methods.flatMap(r=>r.getErrors()),...this.abstractMethods.flatMap(r=>r.getErrors())]}async getErrorsAsync(i={}){const r=z.YieldTracker.from(i),a=[...this.errors];await r.tick();for(const c of this.properties){const e=await c.getErrorsAsync({tracker:r});a.push(...e)}for(const c of this.methods){const e=await c.getErrorsAsync({tracker:r});a.push(...e)}for(const c of this.abstractMethods){const e=await c.getErrorsAsync({tracker:r});a.push(...e)}return a}getShallowErrors(){return this.errors}getAllInteractiveMethods(){const i=[];return i.push(...this.methods),!this.extends||this.extends.type===d.PrimitiveEntity?i:C(i)}};R(Fg,"repository",{APILoad:async(i,...r)=>null});let Ca=Fg;function Yi(l,p){if(!l)throw new Error("Entity is null");const i=p.get(l.id);switch(l.type){case d.LiteralValue:return i||new Nr(l,p);case d.DefinitionEntity:return i||new Ds(l,p);case d.PrimitiveEntity:return i||new Ca(l,p);case d.FunctionDeclaration:return i||new td(l,p);case d.GlobalEvent:return i||new cp(l,p);case d.DataType:return i||new mr(l,p);case d.Property:return i||new ts(l,p);case d.FunctionCall:return i||new up(l,p);case d.Condition:return i||new yp(l,p);case d.Operation:return i||new pp(l,p);case d.VariableDeclaration:return i||new mp(l,p);case d.VariableInstance:return i||new hp(l,p);case d.OutputMap:return i||new Kl(l,p);case d.ArgumentDeclaration:return i||new Na(l,p);case d.InputMap:return i||new Rs(l,p);case d.Project:return i||new N(l);case d.InstalledProject:return i||new vp(l,p);case d.ActionDescriptor:return i||new ki(l,p);case d.ReturnStatement:return i||new Sd(l,p);case d.Loop:return i||new fp(l,p);case d.Search:return i||new Tp(l,p);case d.ValueDescriptor:return i||new Hd(l,p);case d.BuiltInBaseEntity:return i||new qd(l,p);case d.InternalCall:return i||new Ep(l,p);case d.ContinueStatement:return i||new Ap(l,p);case d.BreakStatement:return i||new bp(l,p);case d.GenericReference:return p.get(l.entityId);default:throw new Error("Invalid entity type: "+l.type)}}function Ae(l,p){if(!l)throw new Error("Entity is null");const i=Yi(l,p);return i.subscribe(),i}function g_i(l,p){if(!l)throw new Error("Entity is null");switch(l.type){case d.LiteralValue:return Nr.fromGenerationTarget(l,p);case d.DefinitionEntity:return Ds.fromGenerationTarget(l,p);case d.FunctionDeclaration:return td.fromGenerationTarget(l,p);case d.GlobalEvent:return cp.fromGenerationTarget(l,p);case d.DataType:return mr.fromGenerationTarget(l,p);case d.Property:return ts.fromGenerationTarget(l,p);case d.FunctionCall:return up.fromGenerationTarget(l,p);case d.Condition:return yp.fromGenerationTarget(l,p);case d.Operation:return pp.fromGenerationTarget(l,p);case d.VariableDeclaration:return mp.fromGenerationTarget(l,p);case d.VariableInstance:return hp.fromGenerationTarget(l,p);case d.OutputMap:return Kl.fromGenerationTarget(l,p);case d.ArgumentDeclaration:return Na.fromGenerationTarget(l,p);case d.InputMap:return Rs.fromGenerationTarget(l,p);case d.InstalledProject:return vp.fromGenerationTarget(l,p);case d.ReturnStatement:return Sd.fromGenerationTarget(l,p);case d.Loop:return fp.fromGenerationTarget(l,p);case d.Search:return Tp.fromGenerationTarget(l,p);case d.ActionDescriptor:return ki.fromGenerationTarget(l,p);case d.ValueDescriptor:return Hd.fromGenerationTarget(l,p);case d.InternalCall:return Ep.fromGenerationTarget(l,p);case d.ContinueStatement:return Ap.fromGenerationTarget(l,p);case d.BreakStatement:return bp.fromGenerationTarget(l,p);default:throw new Error("Invalid entity type: "+l.type)}}const nt={seenEntityMaps:new Map,seenEntities:new Set,timestamp:B().toISOString()};class hUe{constructor(){R(this,"initialData")}}const Se={cascade:!1},mUe={APILoad:async(l,...p)=>null},I_i={APICreate:async(l,...p)=>l,APIUpdate:async(l,...p)=>l,APIDelete:async(l,...p)=>l,APIClone:async(l,...p)=>{},APILoadVersion:async(l,p,...i)=>null,...mUe};class R_i{}class TUe extends hUe{}class D_i extends TUe{}class w_i{}class C_i{}class O_i{}class Y${}class __i extends Y${}class V_i extends Y${}class P_i{}class qf{static initReadsValue(p){if(p.initialData.readsValue&&p.initialData.readsValue.type!==d.GenericReference)p.readsValue=Ae(p.initialData.readsValue,p.project);else if(p.initialData.readsValue&&p.initialData.readsValue.type===d.GenericReference){const i=pa(p.initialData.readsValue,p.project);i&&(p.readsValue=i)}if(p.readsValue){if(_t.includes(p.readsValue.type)){let i=p.parent;!vr.includes(i.type)&&i.type!==d.Project&&(i=i.parent);const r=p.type===d.InputMap&&p.parent.type===d.Loop;r&&(i=p.parent.parent),p.readsValue.setParent(i,null),p.readsValue.initChildren(null),i&&i.type!==d.Project&&!r&&i.detachedChildren.includes(p)?i.replaceDetachedChild(p,p.readsValue):i&&i.type!==d.Project&&!r&&i.subscribeDetachedChild(p.readsValue)}p.readsValue.addValueReader(p,null)}return p.readsValue}}class VE{static initWritesValues(p,i){const r=p.initialData.writesValues.reduce((c,e)=>{if(e.type===d.GenericReference||p.writesValues.some(h=>h.id===e.id))return c;const f=Ae(e,p.project);return f.setValueWriter(p,null),_t.includes(f.type)&&(f.setParent(i,null),f.initChildren(null)),[...c,f]},[]),a=[...p.writesValues];return p.writesValues=C([...a,...r]),p.writesValues}}class N_i{}var ri=(l=>(l.PROJECT_INITIALIZED="project-initialized",l.BEFORE_CHANGE_SET_CLOSE_BEFORE_SIDE_EFFECTS="before-change-set-close-before-side-effects",l.BEFORE_CHANGE_SET_CLOSE_AFTER_SIDE_EFFECTS="before-change-set-close-after-side-effects",l.CHANGE_SET_CLOSED_BEFORE_PERSIST="change-set-closed-before-persist",l.CHANGE_SET_PERSISTED="change-set-persisted",l.BEFORE_CHANGE_SET_PERSIST="before-change-set-persist",l.EXPLICIT_DEFINITION_ENTITY_ADDED="explicit-definition-entity-added",l.EXPLICIT_DEFINITION_ENTITY_REMOVED="explicit-definition-entity-removed",l.EXPLICIT_DEFINITION_ENTITY_UPDATED="explicit-definition-entity-updated",l.PERSISTED_DEFINITION_ENTITY_ADDED="persisted-definition-entity-added",l.PERSISTED_DEFINITION_ENTITY_REMOVED="persisted-definition-entity-removed",l.PERSISTED_DEFINITION_ENTITY_UPDATED="persisted-definition-entity-updated",l.RELATIONAL_DATABASE_DEFINITION_ENTITY_ADDED="relational-database-definition-entity-added",l.RELATIONAL_DATABASE_DEFINITION_ENTITY_REMOVED="relational-database-definition-entity-removed",l.RELATIONAL_DATABASE_DEFINITION_ENTITY_UPDATED="relational-database-definition-entity-updated",l))(ri||{});const J$={...Kx,events:new z.Events("def-proj-static-p-ctx-events")},vUe={requestActiveDynamicValue:(l,p=!1)=>null,...J$},Lt=class Lt extends Qr{constructor(i,r={...vUe,events:new z.Events("def-proj-inst-p-ctx-events")}){super(i);R(this,"initialData");R(this,"id");R(this,"type",d.Project);R(this,"name",null);R(this,"description",null);R(this,"x");R(this,"y");R(this,"entities",[]);R(this,"projects",[]);R(this,"functions",[]);R(this,"events",[]);R(this,"variableDeclarations",[]);R(this,"variableInstances",[]);R(this,"conditions",[]);R(this,"operations",[]);R(this,"functionCalls",[]);R(this,"loops",[]);R(this,"searches",[]);R(this,"primitives",[]);R(this,"builtInBaseEntities",[]);R(this,"operationDeclarations",[]);R(this,"globalEventActionDescriptors",[]);R(this,"loopDeclarations",[]);R(this,"loopDeclarationsBodies",[]);R(this,"conditionDeclarations",[]);R(this,"valueDescriptors",[]);R(this,"dataTypes",[]);R(this,"project");R(this,"instances",{});R(this,"builtInInstances",{});R(this,"deletedInstances",{});R(this,"subscribedDefinitionEntities",new Set);R(this,"errors",[]);R(this,"references",[]);R(this,"history",[]);R(this,"undoableStackValueIndex",-1);R(this,"detachedDependents",{});R(this,"knownVersions",null);R(this,"activeVersion",!1);R(this,"initialized",!1);R(this,"startedInitialization",!1);R(this,"diggestedBuiltInBaseEntitiesIds",new Set);R(this,"rejectParallelCS",!1);R(this,"onPersistChangeSetSequentiallyCallback",null);R(this,"onPersistChangeSetInParallelCallback",null);R(this,"onAddChangeSetCallback",null);R(this,"onDiscardChangeSetCallback",null);if(this.parentContext=r,this.initialData=i,this.id=i.id,this.name=i.name,this.description=i.description,this.x=0,this.y=0,this.instances[this.id]=this,!Lt.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:Lt.UUID.uuid(),version:Lt.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||B().toISOString(),author:(i==null?void 0:i.author)||Lt.sessionAuthor,previousVersion:null,deleted:!1,deletable:!0,editable:!0,type:d.Project,name:"",description:"",entities:[],functions:[],events:[],projects:[],variableDeclarations:[],variableInstances:[],conditions:[],operations:[],functionCalls:[],loops:[],searches:[]}}static validateGenerationTarget(i,r){let a=JSON.parse(JSON.stringify(i));const c=[],e=[],f=Zr(a);return e.push(...f.errors),c.push(...f.explanations),{errors:e,explanations:c,modifiedData:a}}get off(){return this.parentContext.events.off}get on(){return this.parentContext.events.on}get emit(){return this.parentContext.events.emit}get emitAsync(){return this.parentContext.events.emitAsync}get emitAsyncAll(){return this.parentContext.events.emitAsyncAll}get emitAsyncAllSettled(){return this.parentContext.events.emitAsyncAllSettled}get emitAsyncSequentially(){return this.parentContext.events.emitAsyncSequentially}get emitAsyncSequentiallyAll(){return this.parentContext.events.emitAsyncSequentiallyAll}get emitAsyncSequentiallyAllSettled(){return this.parentContext.events.emitAsyncSequentiallyAllSettled}async closePersistChangeSetsSequentially(){z.Logger.log("[ProjectState.closePersistChangeSetsSequentially] called");const i=this.history.find(r=>r.dirty&&!r.open&&!r.submitting);i&&(z.Logger.log(`[ProjectState.closePersistChangeSetsSequentially] closing pending change-set ${i.id} - ${i.autoCloseActionName}`),await this.persistChangeSetSequentially(i))}async onPersistChangeSetSequentially(i){this.onPersistChangeSetSequentiallyCallback=i,z.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,z.Logger.log("[ProjectState.onPersistChangeSetInParallel] onPersistChangeSetInParallelCallback has been set. Checking for pending change-sets.");for(const r of this.history)this.persistChangeSetInParallel(r),await new Promise(a=>setTimeout(a,27))}offPersistChangeSetInParallel(){this.onPersistChangeSetInParallelCallback=null}onAddChangeSet(i){this.onAddChangeSetCallback=i}offAddChangeSet(){this.onAddChangeSetCallback=null}onDiscardChangeSet(i){this.onDiscardChangeSetCallback=i}offDiscardChangeSet(){this.onDiscardChangeSetCallback=null}async persistChangeSetSequentially(i){if(z.Logger.log(`[ProjectState.persistChangeSetSequentially] called for change-set ${i.id} - ${i.autoCloseActionName}`),!i.dirty||i.open||i.submitting){z.Logger.log(`[ProjectState.persistChangeSetSequentially] change-set ${i.id} - ${i.autoCloseActionName} is not dirty, or is open, or is already being submitted, skipping.`);return}const r=this.history.findIndex(e=>e.id===i.id),a=this.history.slice(0,r),c=a[a.length-1];if(c!=null&&c.dirty){z.Logger.log(`[ProjectState.persistChangeSetSequentially] lastBeforeSelf is dirty: ${c.id} - ${c.autoCloseActionName}, closing it first.`);return}this.onPersistChangeSetSequentiallyCallback&&(z.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),z.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(z.Logger.log(`[ProjectState.persistChangeSetInParallel] called for change-set ${i.id} - ${i.autoCloseActionName}`),!i.dirty||i.open||i.submitting){z.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&&(z.Logger.log(`[ProjectState.persistChangeSetInParallel] invoking onPersistChangeSetInParallelCallback for change-set ${i.id} - ${i.autoCloseActionName}`),this.emit("before-change-set-persist",i),i.submitting=!0,(await this.onPersistChangeSetInParallelCallback(i)).success&&(i.dirty=!1,this.emit("change-set-persisted",i)))}toLatestChangeSet(i,r,a,c=!1,e="here-this"){if(!this.history.length)return new q(this,i,r,a,c,e);const f=this.history[this.history.length-1];return f.open?f:this.addChangeSet(new q(this,i,r,a,c,e))}addChangeSet(i){var a,c;if(!this.history.length)return this.undoableStackValueIndex=p_(this.undoableStackValueIndex,this.history,i),(a=this.onAddChangeSetCallback)==null||a.call(this,i,this.undoableStackValueIndex),i;const r=this.history.find(e=>e.id===(i==null?void 0:i.id));if(r)return r;if(this.rejectParallelCS){const e=this.history.find(f=>f.open);if(e)throw z.Logger.warn("Previous still open: ",e),z.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=p_(this.undoableStackValueIndex,this.history,i),(c=this.onAddChangeSetCallback)==null||c.call(this,i,this.undoableStackValueIndex),i}discardChangeSet(i){var a;z.Logger.log(`[ProjectState.discardChangeSet] called for change-set ${i.id} - ${i.autoCloseActionName}`);const r=this.history.findIndex(c=>c.id===(i==null?void 0:i.id));return r!==-1&&(this.history.splice(r,1),z.Logger.log(`[ProjectState.discardChangeSet] Removed change-set ${i.id} - ${i.autoCloseActionName} from history.`),this.undoableStackValueIndex=this.undoableStackValueIndex-1,(a=this.onDiscardChangeSetCallback)==null||a.call(this,i),i==null||i.teardown()),this}validateGeneratedUpdate(i){return{errors:[],explanations:[],modifiedData:i}}subscribeDependents(i){return i.forEach(r=>{this.detachedDependents[r.entity.id]||(this.detachedDependents[r.entity.id]=r)}),this}unsubscribeDependents(i){return i.forEach(r=>{this.detachedDependents[r.entity.id]&&delete this.detachedDependents[r.entity.id]}),this}syncDependents(i=this.project.addChangeSet(new q(this.project,Lt.sessionAuthor,B().toISOString(),this,!0,"sync-dependents"))){const r=[],a=[],c=[],e=[];return Object.values(this.detachedDependents).forEach(f=>{const h=f.entity.afterAllChildrenInitialized(i);r.push(...h.updated),a.push(...h.added),c.push(...h.removed),e.push(...h.affected)}),i==null||i.attemptAutoclose("sync-dependents",this.id),{updated:C(r),added:C(a),removed:C(c),affected:C(e),self:this}}onDetachedDependencyRemoved(i,r,a){const c=[],e=[],f=[],h=[];return{updated:C(c),added:C(e),removed:C(f),affected:C(h),self:this}}onDetachedDependencyRestored(i,r,a){const c=[],e=[],f=[],h=[];return{updated:C(c),added:C(e),removed:C(f),affected:C(h),self:this}}unsubscribeFromDependencies(){return this}subscribeToDependencies(){return this}increaseVersion(i){if(i&&!B(i).isValid())throw new Error(`The shared timestamp '${i}' is not a valid ISO 8601 date string.`);return i&&B(i).isSame(B(this.createdAt))?this:(this.previousVersion=this.version,this.version=Lt.UUID.uuid(),this.createdAt=B(i).toISOString()||B().toISOString(),this)}captureVersion(){var r;const i=((r=this.knownVersions)==null?void 0:r.get(this.version))||new Lt(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 r=[],a=[],c=[],e=[];return{updated:C(r),added:C(a),removed:C(c),affected:C(e),self:this}}async restoreVersion(i){var h;const r=[],a=[],c=[],e=[];if(this.version===i)return{updated:C(r),added:C(a),removed:C(c),affected:C(e),self:this};if(!this.knownVersions){const m=new Map;for(const[E,b]of this.knownVersions||new Map){if(m.set(E,b),b.activeVersion=!1,b.knownVersions)for(const[g,_]of b.knownVersions)m.set(g,_);b.knownVersions=null}}let f=(h=this.knownVersions)==null?void 0:h.get(i);if(!f){const m=await this.APILoadVersion({},i);if(!m)throw new Error(`Version with id '${i}' for entity with id '${this.id}' not found.`);f=new Lt(m)}return this.metaSync(f.toShallowJSON(),null),this.previousVersion=f.previousVersion,this.version=f.version,this.createdAt=f.createdAt,this.author=f.author,this.deleted=f.deleted,this.entities=f.entities,this.projects=f.projects,this.functions=f.functions,this.events=f.events,this.variableDeclarations=f.variableDeclarations,this.variableInstances=f.variableInstances,this.conditions=f.conditions,this.operations=f.operations,this.functionCalls=f.functionCalls,this.loops=f.loops,this.searches=f.searches,{updated:C(r),added:C(a),removed:C(c),affected:C(e),self:this}}updateWithShallowTransfer(i,r=this.project.addChangeSet(new q(this.project,Lt.sessionAuthor,B().toISOString(),this,!0,w.UpdateWithShallowTransfer))){return this.checkCanEdit(this,r)?(this.metaSync(i,r),this.version=i.version,this.createdAt=i.createdAt,this.author=i.author,this.deleted=i.deleted,this.previousVersion=i.previousVersion,this.captureVersion(),this.subscribeToDependencies(),r==null||r.attemptAutoclose(w.UpdateWithShallowTransfer,this.id),this):(z.Logger.warn(`[updateWithShallowTransfer] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),r==null||r.attemptAutoclose(w.UpdateWithShallowTransfer,this.id),this)}updateWithGenerationTarget(i,r=this.project.addChangeSet(new q(this.project,Lt.sessionAuthor,B().toISOString(),this,!0,w.UpdateWithGenerationTarget))){return this.checkCanEdit(this,r)?(this.metaSync(i,r),this.captureVersion(),this.subscribeToDependencies(),r==null||r.attemptAutoclose(w.UpdateWithGenerationTarget,this.id),this):(z.Logger.warn(`[updateWithGenerationTarget] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),r==null||r.attemptAutoclose(w.UpdateWithGenerationTarget,this.id),this)}hydrateAncestors(){const i=[],r=[],a=[],c=[];return{updated:C(i),added:C(r),removed:C(a),affected:C(c),self:this}}afterAllChildrenInitialized(i=null){const r=[],a=[],c=[],e=[];return this.initialized||(this.initialized=!0,this.emit("project-initialized",this,i)),this.validate(),this.captureVersion(),{updated:C(r),added:C(a),removed:C(c),affected:C(e),self:this}}addSelfToProject(i){const r=[],a=[],c=[],e=[];return this.subscribe(),this.subscribeToDependencies(),{updated:C(r),added:C(a),removed:C(c),affected:C(e),self:this}}get instancesList(){return Object.values(this.instances)}get builtInInstancesList(){return Object.values(this.builtInInstances)}isOperationDeclaration(i){return this.operationDeclarations.includes(i)}isGlobalEventActionDescriptor(i){return this.globalEventActionDescriptors.includes(i)}isLoopDeclaration(i){return this.loopDeclarations.includes(i)}isConditionDeclaration(i){return this.conditionDeclarations.includes(i)}initChildren(i=this.project.addChangeSet(new q(this.project,Lt.sessionAuthor,B().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.entities=this.initialData.entities.map(r=>{const a=Ae(r,this);return a.setParent(this,null),a.initChildren(i),a}),this.projects=this.initialData.projects.map(r=>{const a=Ae(r,this);return a.setParent(this,null),a.initChildren(i),a}),this.variableDeclarations=this.initialData.variableDeclarations.map(r=>{const a=Ae(r,this);return a.setParent(this,null),a.initChildren(i),a}),this.variableInstances=this.initialData.variableInstances.map(r=>{const a=Ae(r,this);return a.setParent(this,null),a.initChildren(i),a}),this.conditions=this.initialData.conditions.map(r=>{const a=Ae(r,this);return a.setParent(this,null),a.initChildren(i),a}),this.operations=this.initialData.operations.map(r=>{const a=Ae(r,this);return a.setParent(this,null),a.initChildren(i),a}),this.functions=this.initialData.functions.map(r=>{const a=Ae(r,this);return a.setParent(this,null),a.initChildren(i),a}),this.events=this.initialData.events.map(r=>{const a=Ae(r,this);return a.setParent(this,null),a.initChildren(i),a}),this.functionCalls=this.initialData.functionCalls.map(r=>{const a=Ae(r,this);return a.setParent(this,null),a.initChildren(i),a}),this.loops=this.initialData.loops.map(r=>{const a=Ae(r,this);return a.setParent(this,null),a.initChildren(i),a}),this.searches=this.initialData.searches.map(r=>{const a=Ae(r,this);return a.setParent(this,null),a.initChildren(i),a}),this.attachOrphanReferences(),this.subscribeToDependencies(),this.afterAllChildrenInitialized(i),i==null||i.attemptAutoclose("init-children",this.id),this)}subscribeInstance(i){return(!this.instances[i.id]||this.instances[i.id]!==i)&&(this.instances[i.id]=i),this}subscribeDeletedInstance(i){return(!this.deletedInstances[i.id]||this.deletedInstances[i.id]!==i)&&(this.deletedInstances[i.id]=i),this}subscribeBuiltInInstance(i){return(!this.builtInInstances[i.id]||this.builtInInstances[i.id]!==i)&&(this.builtInInstances[i.id]=i),this}subscribe(){return this}unsubscribe(){return this}unsubscribeInstance(i){return delete this.instances[i.id],this}unsubscribeDeletedInstance(i){return delete this.deletedInstances[i.id],this}unsubscribeBuiltInInstance(i){return delete this.builtInInstances[i.id],this}findSubscribedBuiltInInstance(i){return this.builtInInstances[i.id]||null}get(i){return this.instances[i]||this.builtInInstances[i]||null}getDeleted(i){return this.deletedInstances[i]||null}getManaged(i){return this.getBuiltIn(i)?null:this.instances[i]||null}getBuiltIn(i){return this.builtInInstances[i]||null}findSubscribedInstanceFromReference(i){return this.instances[i.entityId]||null}findSubscribedBuiltInInstanceFromReference(i){return this.builtInInstances[i.entityId]||null}metaSync(i,r=this.project.addChangeSet(new q(this.project,Lt.sessionAuthor,B().toISOString(),this,!0,"meta-sync"))){const a=Wr(this,i,r),c=Hr(this,a),e=this.toMeta();return this.name=a.name!==void 0?a.name:e.name,this.description=a.description!==void 0?a.description:e.description,this.x=a.x||e.x,this.y=a.y||e.y,super.baseMetaSync(a,this,r),a.deleted===!0&&!e.deleted?r==null||r.add(this,W.Removed):a.deleted===!1&&e.deleted?r==null||r.add(this,W.Added):c&&(r==null||r.add(this,W.Updated)),r==null||r.attemptAutoclose("meta-sync",this.id),this}async APILoad(i=Se,...r){return await Lt.repository.APILoad(this.id,...r),this}async APICreate(i=Se,...r){return await Lt.repository.APICreate(this.toShallowJSON(),...r),this}async APIUpdate(i=Se,...r){return await Lt.repository.APIUpdate(this.toShallowJSON(),...r),this}async APIDelete(i=Se,...r){return await Lt.repository.APIDelete(this.toShallowJSON(),...r),this}async APIClone(i=Se,...r){return await Lt.repository.APIClone(this.id,...r),this}async APILoadVersion(i=Se,r,...a){return await Lt.repository.APILoadVersion(this.id,r,...a)}remove({ignoreUpstream:i}={ignoreUpstream:!1},r=this.project.addChangeSet(new q(this.project,Lt.sessionAuthor,B().toISOString(),this,!0,w.RemoveEntity))){return{added:[],updated:[],removed:[],affected:[],self:this}}restore({}={},i=this.project.addChangeSet(new q(this.project,Lt.sessionAuthor,B().toISOString(),this,!0,w.RestoreEntity))){return{added:[],updated:[],removed:[],affected:[],self:this}}getAllBuiltInIds(){const i=new Set;return[...this.primitives.flatMap(r=>r.toFlatIds(i)),...this.builtInBaseEntities.flatMap(r=>r.toFlatIds(i)),...this.operationDeclarations.flatMap(r=>r.toFlatIds(i)),...this.globalEventActionDescriptors.flatMap(r=>r.toFlatIds(i)),...this.loopDeclarations.flatMap(r=>r.toFlatIds(i)),...this.conditionDeclarations.flatMap(r=>r.toFlatIds(i)),...this.valueDescriptors.flatMap(r=>r.toFlatIds(i)),...this.dataTypes.flatMap(r=>r.toFlatIds(i))]}getAllBuiltIn(){const i=new Set;return[...this.primitives.flatMap(r=>r.toFlat(i)),...this.builtInBaseEntities.flatMap(r=>r.toFlat(i)),...this.operationDeclarations.flatMap(r=>r.toFlat(i)),...this.globalEventActionDescriptors.flatMap(r=>r.toFlat(i)),...this.loopDeclarations.flatMap(r=>r.toFlat(i)),...this.conditionDeclarations.flatMap(r=>r.toFlat(i)),...this.valueDescriptors.flatMap(r=>r.toFlat(i)),...this.dataTypes.flatMap(r=>r.toFlat(i))]}toFlat(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this,...this.entities.flatMap(a=>a.toFlat(i)),...this.functions.flatMap(a=>a.toFlat(i)),...this.events.flatMap(a=>a.toFlat(i)),...this.projects.flatMap(a=>a.toFlat(i)),...this.variableDeclarations.flatMap(a=>a.toFlat(i)),...this.variableInstances.flatMap(a=>a.toFlat(i)),...this.conditions.flatMap(a=>a.toFlat(i)),...this.operations.flatMap(a=>a.toFlat(i)),...this.functionCalls.flatMap(a=>a.toFlat(i)),...this.loops.flatMap(a=>a.toFlat(i)),...this.searches.flatMap(a=>a.toFlat(i))])}toFlatIds(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.id,...this.entities.flatMap(a=>a.toFlatIds(i)),...this.functions.flatMap(a=>a.toFlatIds(i)),...this.events.flatMap(a=>a.toFlatIds(i)),...this.projects.flatMap(a=>a.toFlatIds(i)),...this.variableDeclarations.flatMap(a=>a.toFlatIds(i)),...this.variableInstances.flatMap(a=>a.toFlatIds(i)),...this.conditions.flatMap(a=>a.toFlatIds(i)),...this.operations.flatMap(a=>a.toFlatIds(i)),...this.functionCalls.flatMap(a=>a.toFlatIds(i)),...this.loops.flatMap(a=>a.toFlatIds(i)),...this.searches.flatMap(a=>a.toFlatIds(i))])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,description:this.description,type:this.type,editable:this.editable,deletable:this.deletable,name:this.name}}toJSON(i=new Set){return i.has(this.id)?this.toReference():(i.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,editable:this.editable,deletable:this.deletable,name:this.name,description:this.description,entities:this.entities.map(r=>r.toJSON(i)),variableDeclarations:this.variableDeclarations.map(r=>r.toJSON(i)),variableInstances:this.variableInstances.map(r=>r.toJSON(i)),conditions:this.conditions.map(r=>r.toJSON(i)),operations:this.operations.map(r=>r.toJSON(i)),loops:this.loops.map(r=>r.toJSON(i)),searches:this.searches.map(r=>r.toJSON(i)),functions:this.functions.map(r=>r.toJSON(i)),events:this.events.map(r=>r.toJSON(i)),projects:this.projects.map(r=>r.toJSON(i)),functionCalls:this.functionCalls.map(r=>r.toJSON(i))})}toJSONClone(i={uuidStrategy:"uuid"}){const r=new Map,a=new Set,c=this.getAllBuiltInIds();return Object.keys(this.instances).forEach(e=>{if(c.includes(e)){r.set(e,e);return}r.set(e,Lt.UUID.uuid())}),a.add(this.id),{id:r.get(this.id),version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,editable:this.editable,deletable:this.deletable,name:this.name,description:this.description,entities:this.entities.map(e=>e.toJSONClone({...i,seenEntityMaps:r,seenEntities:a,newId:null})),projects:this.projects.map(e=>e.toJSONClone({...i,seenEntityMaps:r,seenEntities:a,newId:null})),variableDeclarations:this.variableDeclarations.map(e=>e.toJSONClone({...i,seenEntityMaps:r,seenEntities:a,newId:null})),variableInstances:this.variableInstances.map(e=>e.toJSONClone({...i,seenEntityMaps:r,seenEntities:a,newId:null})),conditions:this.conditions.map(e=>e.toJSONClone({...i,seenEntityMaps:r,seenEntities:a,newId:null})),operations:this.operations.map(e=>e.toJSONClone({...i,seenEntityMaps:r,seenEntities:a,newId:null})),functions:this.functions.map(e=>e.toJSONClone({...i,seenEntityMaps:r,seenEntities:a,newId:null})),events:this.events.map(e=>e.toJSONClone({...i,seenEntityMaps:r,seenEntities:a,newId:null})),functionCalls:this.functionCalls.map(e=>e.toJSONClone({...i,seenEntityMaps:r,seenEntities:a,newId:null})),loops:this.loops.map(e=>e.toJSONClone({...i,seenEntityMaps:r,seenEntities:a,newId:null})),searches:this.searches.map(e=>e.toJSONClone({...i,seenEntityMaps:r,seenEntities:a,newId:null}))}}toReference(i=nt){var a;let r=this.id;return(a=i.seenEntityMaps)!=null&&a.has(this.id)&&(r=i.seenEntityMaps.get(this.id)),{id:r+"--"+Lt.UUID.uuid()+"--ref",type:d.GenericReference,entityId:r,version:this.version,entityType:this.type}}toShallowJSON(i=nt){var a;let r=this.id;return(a=i.seenEntityMaps)!=null&&a.has(this.id)&&(r=i.seenEntityMaps.get(this.id)),{id:r,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,editable:this.editable,deletable:this.deletable,name:this.name,description:this.description,entities:this.entities.map(c=>c.toReference(i)),functions:this.functions.map(c=>c.toReference(i)),events:this.events.map(c=>c.toReference(i)),projects:this.projects.map(c=>c.toReference(i)),variableDeclarations:this.variableDeclarations.map(c=>c.toReference(i)),variableInstances:this.variableInstances.map(c=>c.toReference(i)),conditions:this.conditions.map(c=>c.toReference(i)),operations:this.operations.map(c=>c.toReference(i)),functionCalls:this.functionCalls.map(c=>c.toReference(i)),loops:this.loops.map(c=>c.toReference(i)),searches:this.searches.map(c=>c.toReference(i))}}toFlatJSON(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.toShallowJSON(),...this.entities.flatMap(a=>a.toFlatJSON(i)),...this.functions.flatMap(a=>a.toFlatJSON(i)),...this.events.flatMap(a=>a.toFlatJSON(i)),...this.projects.flatMap(a=>a.toFlatJSON(i)),...this.variableDeclarations.flatMap(a=>a.toFlatJSON(i)),...this.variableInstances.flatMap(a=>a.toFlatJSON(i)),...this.conditions.flatMap(a=>a.toFlatJSON(i)),...this.operations.flatMap(a=>a.toFlatJSON(i)),...this.functionCalls.flatMap(a=>a.toFlatJSON(i)),...this.loops.flatMap(a=>a.toFlatJSON(i)),...this.searches.flatMap(a=>a.toFlatJSON(i))])}toGenerationTarget(i=nt){var a;let r=this.id;return(a=i.seenEntityMaps)!=null&&a.has(this.id)&&(r=i.seenEntityMaps.get(this.id)),{id:r,type:this.type,name:this.name,description:this.description}}toFlatGenerationTarget(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[...this.entities.flatMap(a=>a.toFlatGenerationTarget(i)),...this.functions.flatMap(a=>a.toFlatGenerationTarget(i)),...this.events.flatMap(a=>a.toFlatGenerationTarget(i)),...this.projects.flatMap(a=>a.toFlatGenerationTarget(i)),...this.variableDeclarations.flatMap(a=>a.toFlatGenerationTarget(i)),...this.variableInstances.flatMap(a=>a.toFlatGenerationTarget(i)),...this.conditions.flatMap(a=>a.toFlatGenerationTarget(i)),...this.operations.flatMap(a=>a.toFlatGenerationTarget(i)),...this.functionCalls.flatMap(a=>a.toFlatGenerationTarget(i)),...this.loops.flatMap(a=>a.toFlatGenerationTarget(i)),...this.searches.flatMap(a=>a.toFlatGenerationTarget(i))])}clearErrors(){return this.errors=[],this.entities.forEach(i=>i.clearErrors()),this.projects.forEach(i=>i.clearErrors()),this.functions.forEach(i=>i.clearErrors()),this.events.forEach(i=>i.clearErrors()),this.variableDeclarations.forEach(i=>i.clearErrors()),this.variableInstances.forEach(i=>i.clearErrors()),this.conditions.forEach(i=>i.clearErrors()),this.operations.forEach(i=>i.clearErrors()),this.functionCalls.forEach(i=>i.clearErrors()),this.loops.forEach(i=>i.clearErrors()),this.searches.forEach(i=>i.clearErrors()),this}validate(){return this.validateChildren(),eE([...this.errors]),{success:!0}}async validateAsync(i={}){const r=z.YieldTracker.from(i);return await this.validateChildrenAsync({tracker:r}),await jOe([...this.errors]),{success:!0}}validateChildren(){this.entities.forEach(i=>i.validate()),this.projects.forEach(i=>i.validate()),this.functions.forEach(i=>i.validate()),this.events.forEach(i=>i.validate()),this.variableDeclarations.forEach(i=>i.validate()),this.variableInstances.forEach(i=>i.validate()),this.conditions.forEach(i=>i.validate()),this.operations.forEach(i=>i.validate()),this.functionCalls.forEach(i=>i.validate()),this.loops.forEach(i=>i.validate()),this.searches.forEach(i=>i.validate())}async validateChildrenAsync(i={}){const r=z.YieldTracker.from(i);for(let a=0;a<this.entities.length;a++)await this.entities[a].validateAsync({tracker:r});for(let a=0;a<this.projects.length;a++)await this.projects[a].validateAsync({tracker:r});for(let a=0;a<this.functions.length;a++)await this.functions[a].validateAsync({tracker:r});for(let a=0;a<this.events.length;a++)await this.events[a].validateAsync({tracker:r});for(let a=0;a<this.variableDeclarations.length;a++)await this.variableDeclarations[a].validateAsync({tracker:r});for(let a=0;a<this.variableInstances.length;a++)await this.variableInstances[a].validateAsync({tracker:r});for(let a=0;a<this.conditions.length;a++)await this.conditions[a].validateAsync({tracker:r});for(let a=0;a<this.operations.length;a++)await this.operations[a].validateAsync({tracker:r});for(let a=0;a<this.functionCalls.length;a++)await this.functionCalls[a].validateAsync({tracker:r});for(let a=0;a<this.loops.length;a++)await this.loops[a].validateAsync({tracker:r});for(let a=0;a<this.searches.length;a++)await this.searches[a].validateAsync({tracker:r})}getErrors(){return[...this.errors,...this.entities.flatMap(r=>r.getErrors()),...this.projects.flatMap(r=>r.getErrors()),...this.functions.flatMap(r=>r.getErrors()),...this.events.flatMap(r=>r.getErrors()),...this.variableDeclarations.flatMap(r=>r.getErrors()),...this.variableInstances.flatMap(r=>r.getErrors()),...this.conditions.flatMap(r=>r.getErrors()),...this.operations.flatMap(r=>r.getErrors()),...this.functionCalls.flatMap(r=>r.getErrors()),...this.loops.flatMap(r=>r.getErrors()),...this.searches.flatMap(r=>r.getErrors())]}async getErrorsAsync(i={}){const r=z.YieldTracker.from(i),a=[...this.errors];await r.tick();for(let c=0;c<this.entities.length;c++){const e=await this.entities[c].getErrorsAsync({tracker:r});a.push(...e)}for(let c=0;c<this.projects.length;c++){const e=await this.projects[c].getErrorsAsync({tracker:r});a.push(...e)}for(let c=0;c<this.functions.length;c++){const e=await this.functions[c].getErrorsAsync({tracker:r});a.push(...e)}for(let c=0;c<this.events.length;c++){const e=await this.events[c].getErrorsAsync({tracker:r});a.push(...e)}for(let c=0;c<this.variableDeclarations.length;c++){const e=await this.variableDeclarations[c].getErrorsAsync({tracker:r});a.push(...e)}for(let c=0;c<this.variableInstances.length;c++){const e=await this.variableInstances[c].getErrorsAsync({tracker:r});a.push(...e)}for(let c=0;c<this.conditions.length;c++){const e=await this.conditions[c].getErrorsAsync({tracker:r});a.push(...e)}for(let c=0;c<this.operations.length;c++){const e=await this.operations[c].getErrorsAsync({tracker:r});a.push(...e)}for(let c=0;c<this.functionCalls.length;c++){const e=await this.functionCalls[c].getErrorsAsync({tracker:r});a.push(...e)}for(let c=0;c<this.loops.length;c++){const e=await this.loops[c].getErrorsAsync({tracker:r});a.push(...e)}for(let c=0;c<this.searches.length;c++){const e=await this.searches[c].getErrorsAsync({tracker:r});a.push(...e)}return a}getShallowErrors(){return this.errors}clone(){return this}addDefinitionEntity(i){return this.entities.includes(i)||this.entities.push(i),i}addFunctionDeclaration(i){return this.functions.includes(i)||this.functions.push(i),i}addFunctionCall(i){return this.functionCalls.includes(i)||this.functionCalls.push(i),i}addVariableDeclaration(i){return this.variableDeclarations.includes(i)||this.variableDeclarations.push(i),i}addVariableInstance(i){return this.variableInstances.includes(i)||this.variableInstances.push(i),i}addInstalledProject(i){return this.projects.includes(i)||this.projects.push(i),this}addGlobalEvent(i){return this.events.includes(i)||this.events.push(i),this}addCondition(i){return this.conditions.includes(i)||this.conditions.push(i),this}addOperation(i){return this.operations.includes(i)||this.operations.push(i),this}addLoop(i){return this.loops.includes(i)||this.loops.push(i),this}addSearch(i){return this.searches.includes(i)||this.searches.push(i),this}removeDefinitionEntity(i){const r=this.entities.findIndex(a=>a.id===i.id);if(r>-1){const a=this.entities[r];return this.entities.splice(r,1),a}return null}removeCondition(i){const r=this.conditions.findIndex(a=>a.id===i.id);if(r>-1){const a=this.conditions[r];return this.conditions.splice(r,1),a}return null}removeOperation(i){const r=this.operations.findIndex(a=>a.id===i.id);if(r>-1){const a=this.operations[r];return this.operations.splice(r,1),a}return null}removeLoop(i){const r=this.loops.findIndex(a=>a.id===i.id);if(r>-1){const a=this.loops[r];return this.loops.splice(r,1),a}return null}removeSearch(i){const r=this.searches.findIndex(a=>a.id===i.id);if(r>-1){const a=this.searches[r];return this.searches.splice(r,1),a}return null}removeFunctionCall(i){const r=this.functionCalls.findIndex(a=>a.id===i.id);if(r>-1){const a=this.functionCalls[r];return this.functionCalls.splice(r,1),a}return null}removeVariableInstance(i){const r=this.variableInstances.findIndex(a=>a.id===i.id);if(r>-1){const a=this.variableInstances[r];return this.variableInstances.splice(r,1),a}return null}removeVariableDeclaration(i){const r=this.variableDeclarations.findIndex(a=>a.id===i.id);if(r>-1){const a=this.variableDeclarations[r];return this.variableDeclarations.splice(r,1),a}return null}removeFunctionDeclaration(i){const r=this.functions.findIndex(a=>a.id===i.id);if(r>-1){const a=this.functions[r];return this.functions.splice(r,1),a}return null}removeInstalledProject(i){const r=this.projects.findIndex(a=>a.id===i.id);if(r>-1){const a=this.projects[r];return this.projects.splice(r,1),a}return null}removeGlobalEvent(i){const r=this.events.findIndex(a=>a.id===i.id);if(r>-1){const a=this.events[r];return this.events.splice(r,1),a}return null}removeTopLevelVariableDeclaration(i){if(i.type!==d.VariableDeclaration)return null;const r=this.variableDeclarations.findIndex(a=>a.id===i.id);if(r>-1){const a=this.variableDeclarations[r];return this.variableDeclarations.splice(r,1),a}return null}getEntryPoints(){return[...this.functions,...this.events,...this.entities.flatMap(r=>r.methods)]}getTerminationStatements(){return[...this.getEntryPoints().reduce((r,a)=>{const c=yt(a);return[...r,...c.filter(e=>e.type===d.ReturnStatement||e.type===d.ContinueStatement||e.type===d.BreakStatement)]},[])]}getFunctionDeclaration(i){return this.functions.find(r=>r.id===i)||null}getConditions(){return[...this.conditions,...this.getEntryPoints().reduce((r,a)=>{const c=yt(a);return[...r,...c.filter(e=>e.type===d.Condition)]},[]),...this.functionCalls.reduce((r,a)=>{const c=yt(a);return[...r,...c.filter(e=>e.type===d.Condition)]},[]),...this.operations.reduce((r,a)=>{const c=yt(a);return[...r,...c.filter(e=>e.type===d.Condition)]},[]),...this.loops.reduce((r,a)=>{const c=yt(a);return[...r,...c.filter(e=>e.type===d.Condition)]},[]),...this.searches.reduce((r,a)=>{const c=yt(a);return[...r,...c.filter(e=>e.type===d.Condition)]},[])]}getOperations(){return[...this.operations,...this.getEntryPoints().reduce((r,a)=>{const c=yt(a);return[...r,...c.filter(e=>e.type===d.Operation)]},[]),...this.functionCalls.reduce((r,a)=>{const c=yt(a);return[...r,...c.filter(e=>e.type===d.Operation)]},[]),...this.conditions.reduce((r,a)=>{const c=yt(a);return[...r,...c.filter(e=>e.type===d.Operation)]},[]),...this.loops.reduce((r,a)=>{const c=yt(a);return[...r,...c.filter(e=>e.type===d.Operation)]},[]),...this.searches.reduce((r,a)=>{const c=yt(a);return[...r,...c.filter(e=>e.type===d.Operation)]},[])]}getFunctionCalls(){return[...this.functionCalls,...this.getEntryPoints().reduce((r,a)=>{const c=yt(a);return[...r,...c.filter(e=>e.type===d.FunctionCall)]},[]),...this.conditions.reduce((r,a)=>{const c=yt(a);return[...r,...c.filter(e=>e.type===d.FunctionCall)]},[]),...this.operations.reduce((r,a)=>{const c=yt(a);return[...r,...c.filter(e=>e.type===d.FunctionCall)]},[]),...this.loops.reduce((r,a)=>{const c=yt(a);return[...r,...c.filter(e=>e.type===d.FunctionCall)]},[]),...this.searches.reduce((r,a)=>{const c=yt(a);return[...r,...c.filter(e=>e.type===d.FunctionCall)]},[])]}getDefinitionEntities(i=new Set){return Array.from(this.subscribedDefinitionEntities).filter(a=>!i.has(a)).map(a=>this.get(a))}getVariables(){return[...this.variableDeclarations,...this.getEntryPoints().reduce((r,a)=>{const c=sr(a);return[...r,...c]},[]),...this.functionCalls.reduce((r,a)=>{const c=sr(a);return[...r,...c]},[]),...this.conditions.reduce((r,a)=>{const c=sr(a);return[...r,...c]},[]),...this.operations.reduce((r,a)=>{const c=sr(a);return[...r,...c]},[]),...this.loops.reduce((r,a)=>{const c=sr(a);return[...r,...c]},[]),...this.searches.reduce((r,a)=>{const c=sr(a);return[...r,...c]},[])]}getVariableInstances(){return[...this.variableInstances,...this.entities.reduce((r,a)=>[...r,...a.methods.flatMap(c=>{const f=yt(c).filter(h=>h.type===d.VariableInstance);return[...r,...f]})],[]),...this.getEntryPoints().reduce((r,a)=>{const e=sr(a).filter(f=>f.type===d.VariableInstance);return[...r,...e]},[]),...this.functionCalls.reduce((r,a)=>{const e=sr(a).filter(f=>f.type===d.VariableInstance);return[...r,...e]},[]),...this.conditions.reduce((r,a)=>{const e=sr(a).filter(f=>f.type===d.VariableInstance);return[...r,...e]},[]),...this.operations.reduce((r,a)=>{const e=sr(a).filter(f=>f.type===d.VariableInstance);return[...r,...e]},[]),...this.loops.reduce((r,a)=>{const e=sr(a).filter(f=>f.type===d.VariableInstance);return[...r,...e]},[]),...this.searches.reduce((r,a)=>{const e=sr(a).filter(f=>f.type===d.VariableInstance);return[...r,...e]},[])]}getVariableDeclarations(){return C([...this.variableDeclarations,...this.entities.reduce((r,a)=>[...r,...a.methods.flatMap(c=>{const f=yt(c).filter(h=>h.type===d.VariableDeclaration);return[...r,...f]})],[]),...this.getEntryPoints().reduce((r,a)=>{const e=sr(a).filter(f=>f.type===d.VariableDeclaration);return[...r,...e]},[]),...this.functionCalls.reduce((r,a)=>{const e=sr(a).filter(f=>f.type===d.VariableDeclaration);return[...r,...e]},[]),...this.conditions.reduce((r,a)=>{const e=sr(a).filter(f=>f.type===d.VariableDeclaration);return[...r,...e]},[]),...this.operations.reduce((r,a)=>{const e=sr(a).filter(f=>f.type===d.VariableDeclaration);return[...r,...e]},[]),...this.loops.reduce((r,a)=>{const e=sr(a).filter(f=>f.type===d.VariableDeclaration);return[...r,...e]},[]),...this.searches.reduce((r,a)=>{const e=sr(a).filter(f=>f.type===d.VariableDeclaration);return[...r,...e]},[])])}getLoops(){return[...this.loops,...this.getEntryPoints().reduce((r,a)=>{const c=yt(a);return[...r,...c.filter(e=>e.type===d.Loop)]},[]),...this.functionCalls.reduce((r,a)=>{const c=yt(a);return[...r,...c.filter(e=>e.type===d.Loop)]},[]),...this.conditions.reduce((r,a)=>{const c=yt(a);return[...r,...c.filter(e=>e.type===d.Loop)]},[]),...this.operations.reduce((r,a)=>{const c=yt(a);return[...r,...c.filter(e=>e.type===d.Loop)]},[]),...this.searches.reduce((r,a)=>{const c=yt(a);return[...r,...c.filter(e=>e.type===d.Loop)]},[])]}getSearches(){return[...this.searches,...this.getEntryPoints().reduce((r,a)=>{const c=yt(a);return[...r,...c.filter(e=>e.type===d.Search)]},[]),...this.functionCalls.reduce((r,a)=>{const c=yt(a);return[...r,...c.filter(e=>e.type===d.Search)]},[]),...this.conditions.reduce((r,a)=>{const c=yt(a);return[...r,...c.filter(e=>e.type===d.Search)]},[]),...this.operations.reduce((r,a)=>{const c=yt(a);return[...r,...c.filter(e=>e.type===d.Search)]},[]),...this.loops.reduce((r,a)=>{const c=yt(a);return[...r,...c.filter(e=>e.type===d.Search)]},[])]}attachOrphanReferences(){const i=this.getVariableInstances(),r=this.getVariableDeclarations();return i.forEach(a=>{if(!a.declaration){const c=a.initialData,e=c.declaration.entityId||c.declaration.id,f=r.find(h=>h.id===e);f&&a.setDeclaration(f)}}),this}getBuiltInPersistedEntity(){return this.builtInBaseEntities.find(i=>i.name===Ie.PERSISTED_ENTITY)||null}requestActiveDynamicValue(i,r=!1){var c,e;const a=(e=(c=this.parentContext).requestActiveDynamicValue)==null?void 0:e.call(c,i,r);if(!a&&Zg.includes(i.type)){const f=i.getDefaultValue();return f?{value:f,type:Me.DefaultValue,inheritanceLink:null,valueOwner:i}:null}return a||null}requestExtension(i){if(this.parentContext.requestExtension){const r=this.parentContext.requestExtension(i);if(r&&!r.module)throw new Error(`Module ${i} is not registered properly.`);return r.module||null}return null}undo(){z.Logger.log("Undoing, from: ",this.undoableStackValueIndex),this.undoableStackValueIndex=this.undoableStackValueIndex-1,z.Logger.log("To: ",this.undoableStackValueIndex);const i=this.history[this.undoableStackValueIndex+1],r=this.history[this.undoableStackValueIndex];return z.Logger.log("Current change set: ",i==null?void 0:i.toJSON()),z.Logger.log("Change set to restore: ",r==null?void 0:r.toJSON()),d_(i||"initial",r||"initial",this)}redo(){z.Logger.log("Undoing, from: ",this.undoableStackValueIndex),this.undoableStackValueIndex=this.undoableStackValueIndex+1,z.Logger.log("To: ",this.undoableStackValueIndex);const i=this.history[this.undoableStackValueIndex-1],r=this.history[this.undoableStackValueIndex];return z.Logger.log("Current change set: ",i==null?void 0:i.toJSON()),z.Logger.log("Change set to restore: ",r.toJSON()),d_(i||"initial",r||"initial",this)}applyExternalChangeSet(i){const r=i.payload,a=this.addChangeSet(new q(this,i.userAuthor,i.emittedAt,this));a.ignoreNonEditable=!0,a.ignoreNonDeletable=!0;const c=r.updated[this.id];if(!c)throw new Error("Project root not found in change set transfer. Cannot apply changes.");const e={...r.added,...r.updated,...r.removed},f=[...Object.keys(r.added),...Object.keys(r.updated),...Object.keys(r.removed)];f.forEach(m=>{var E;if(!e[m]){z.Logger.warn(`Entity '${m}' not found in change set transfer. Cannot apply changes.`);const b=(E=this.get(m))==null?void 0:E.toShallowJSON();throw b?z.Logger.warn("Entity in project: ",b):z.Logger.warn("Entity not in project"),new Error(`Entity '${m}' not found in change set transfer. Cannot apply changes.`)}});const h=new cn(c,{allBuiltInEntityIds:this.diggestedBuiltInBaseEntitiesIds});return h.flatRecord=e,h.order=f,h.orderEntities(),z.Logger.log("All entities: ",h.order.map((m,E)=>`${E+1}: ${e[m].type} - ${m}`).join(`,
479
- `)),z.Logger.log("Persisting new additions"),h.visit(async(m,E)=>{if(r.added[m.id]){z.Logger.log("Adding: ",m.id);try{const b=Ae(m,this);if(b.hydrateAncestors(),b.addSelfToProject(a),a.add(b,W.Added),!this.get(m.id))throw new Error(`Entity ${m.id} was not added to the project`)}catch(b){z.Logger.error("Error: ",b),z.Logger.error("Errored entity: ",m)}}}),z.Logger.log("Persisting updates"),h.visit(async(m,E)=>{if(r.updated[m.id]){z.Logger.log("Updating: ",m.id);try{const b=this.get(m.id);b?(b.updateWithShallowTransfer(m,a),a.add(b,W.Updated)):z.Logger.warn(`Active version of ${m.id} not found when applying external changes`)}catch(b){z.Logger.error("Error: ",b),z.Logger.error("Errored entity: ",m)}}}),z.Logger.log("Persisting removals"),h.visit(async(m,E)=>{if(r.removed[m.id]){z.Logger.log("Removing: ",m.id);try{const b=this.get(m.id);b&&b.remove({ignoreUpstream:!1},a)}catch(b){z.Logger.error("Error: ",b),z.Logger.error("Errored entity: ",m)}}}),a.open=!1,a}toBuiltInShallowRecord(){const i={};return Object.values(this.builtInInstances).forEach(r=>{const a=r.toShallowJSON();i[r.id]=a}),i}toShallowRecord(){const i={};return Object.values(this.instances).forEach(r=>{const a=r.toShallowJSON();i[r.id]=a}),i}toFullProjectTransfer(i){const r={shallowErrors:!1,...i},a=new cn(void 0,{allBuiltInEntityIds:this.diggestedBuiltInBaseEntitiesIds});a.flatRecord=this.instances,a.order=Object.keys(a.flatRecord),a.orderEntities();const c={},e=[];return a.visit(f=>{try{const h=f.toShallowJSON();c[f.id]=h,e.push(f.id)}catch(h){if(z.Logger.error(`[toFullProjectTransfer] Error serializing ${f.type} ${f.id}`,h),!r.shallowErrors)throw h}}),{order:e,size:e.length,record:c}}async toFullProjectTransferAsync(i={}){const r={shallowErrors:!1,...i},a=z.YieldTracker.from(r),c=new cn(void 0,{allBuiltInEntityIds:this.diggestedBuiltInBaseEntitiesIds});c.flatRecord=this.instances,c.order=Object.keys(c.flatRecord);const e=[];if(r.seenEntityMaps)for(const h of c.order){const m=r.seenEntityMaps.get(h)??h;this.diggestedBuiltInBaseEntitiesIds.has(m)}await c.orderEntitiesAsync({tracker:a});const f={};return await c.visitAsync(async h=>{try{if(this.diggestedBuiltInBaseEntitiesIds.has(h.id))return;const m=h.toShallowJSON({seenEntityMaps:r.seenEntityMaps});r.resetVersionOptions&&(m.version=Lt.UUID.uuid(),m.createdAt=r.resetVersionOptions.commonTimestamp||B().toISOString(),m.author=r.resetVersionOptions.author||Lt.sessionAuthor||"1",m.previousVersion=null),f[m.id]=m,e.push(m.id),r!=null&&r.onVisit&&await r.onVisit(m)}catch(m){if(z.Logger.error(`[toFullProjectTransferAsync] Error serializing ${h.type} ${h.id}`,m),!r.shallowErrors)throw m}},{tracker:a}),{order:e,size:e.length,record:f}}async toFullProjectGenerationTargetAsync(i={}){const r={shallowErrors:!1,...i},a=z.YieldTracker.from(r),c=new cn(void 0,{allBuiltInEntityIds:this.diggestedBuiltInBaseEntitiesIds});c.flatRecord=this.instances,c.order=Object.keys(c.flatRecord);const e=[];if(r.seenEntityMaps)for(const h of c.order){const m=r.seenEntityMaps.get(h)??h;this.diggestedBuiltInBaseEntitiesIds.has(m)}await c.orderEntitiesAsync({tracker:a});const f={};return await c.visitAsync(async h=>{try{if(this.diggestedBuiltInBaseEntitiesIds.has(h.id))return;const m=h.toGenerationTarget({seenEntityMaps:r.seenEntityMaps});f[m.id]=m,e.push(m.id),r!=null&&r.onVisit&&await r.onVisit(m)}catch(m){if(z.Logger.error(`[toFullProjectTransferAsync] Error serializing ${h.type} ${h.id}`,m),!r.shallowErrors)throw m}},{tracker:a}),{order:e,size:e.length,record:f}}};R(Lt,"parentContext",J$),R(Lt,"sessionAuthor","1"),R(Lt,"repository",{APICreate:async(i,...r)=>i,APIUpdate:async(i,...r)=>i,APIDelete:async(i,...r)=>i,APIClone:async(i,...r)=>{},APILoad:async(i,...r)=>null,APILoadVersion:async(i,r,...a)=>null}),R(Lt,"type",d.Project),R(Lt,"USER_MANAGED_PARENT_TYPES",[]),R(Lt,"PARENT_TYPES",[...Lt.USER_MANAGED_PARENT_TYPES]),R(Lt,"MUTABLE_BASE_PROPERTIES",["name","description"]),R(Lt,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),R(Lt,"BASE_PROPERTIES",[...Lt.MUTABLE_BASE_PROPERTIES,...Lt.INMUTABLE_BASE_PROPERTIES]),R(Lt,"MUTABLE_META_PROPERTIES",[...Lt.MUTABLE_BASE_PROPERTIES,"x","y"]),R(Lt,"INMUTABLE_META_PROPERTIES",[...Lt.INMUTABLE_BASE_PROPERTIES]),R(Lt,"META_PROPERTIES",[...Lt.MUTABLE_META_PROPERTIES,...Lt.INMUTABLE_META_PROPERTIES]),R(Lt,"MUTABLE_UPSTREAM_PROPERTIES",[]),R(Lt,"INMUTABLE_UPSTREAM_PROPERTIES",["primitives","builtInBaseEntities","operationDeclarations","globalEventActionDescriptors","loopDeclarations","builtInInstances"]),R(Lt,"UPSTREAM_PROPERTIES",[...Lt.MUTABLE_UPSTREAM_PROPERTIES,...Lt.INMUTABLE_UPSTREAM_PROPERTIES]),R(Lt,"MUTABLE_DOWNSTREAM_PROPERTIES",["entities","projects","functions","events","variableDeclarations","variableInstances","conditions","operations","functionCalls","loops","searches"]),R(Lt,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),R(Lt,"DOWNSTREAM_PROPERTIES",[...Lt.MUTABLE_DOWNSTREAM_PROPERTIES,...Lt.INMUTABLE_DOWNSTREAM_PROPERTIES]),R(Lt,"PROPERTIES",[...Lt.META_PROPERTIES,...Lt.UPSTREAM_PROPERTIES,...Lt.DOWNSTREAM_PROPERTIES]);let N=Lt;class x_i extends ki{constructor(p){super(kv,p)}}class $_i extends ki{constructor(i){super(Kh,i);R(this,"autoexecutable",!0)}getEntityToMatchInputMap(i){return i.inputs.find(r=>{var a;return((a=r.declaration)==null?void 0:a.id)===re.operation[xe.Validate].inputs.entityToMatch.id})||null}getDataToValidateInputMap(i){return i.inputs.find(r=>{var a;return((a=r.declaration)==null?void 0:a.id)===re.operation[xe.Validate].inputs.dataToValidate.id})||null}getOutputDataOutputMap(i){return i.outputs.find(r=>{var a;return((a=r.declaration)==null?void 0:a.id)===re.operation[xe.Validate].dataType.entity.properties.outputEntity.id})||null}getEntityToMatch(i,r=this.project.addChangeSet(new q(this.project,N.sessionAuthor,B().toISOString(),this,!0,"get-entity-to-match-validate-data"))){var e;const a=((e=this.project.requestActiveDynamicValue(i))==null?void 0:e.value)||null,c=a==null?void 0:a.valueAsTypeSingle;return r==null||r.attemptAutoclose("get-entity-to-match-validate-data",this.id),c}syncOperationInstance(i,r=this.project.addChangeSet(new q(this.project,N.sessionAuthor,B().toISOString(),this,!0,"sync-operation-instance-validate-data"))){const a=[],c=[],e=[],f=[],h=this.getEntityToMatchInputMap(i);if(h){const{added:b,updated:g,removed:_,affected:$}=this.syncEntityToMatchInputMapDataType(h,r);a.push(...g),c.push(...b),e.push(..._),f.push(...$)}const m=this.getDataToValidateInputMap(i);if(m){const{added:b,updated:g,removed:_,affected:$}=this.syncDataToValidateInputMapDataType(m,r);a.push(...g),c.push(...b),e.push(..._),f.push(...$)}const E=this.getOutputDataOutputMap(i);if(E){const{added:b,updated:g,removed:_,affected:$}=this.syncOutputDataOutputMapDataType(E,r);a.push(...g),c.push(...b),e.push(..._),f.push(...$)}return r==null||r.attemptAutoclose("sync-operation-instance-validate-data",this.id),{updated:C(a),added:C(c),removed:C(e),affected:C(f),self:i}}syncEntityToMatchInputMapDataType(i,r=this.project.addChangeSet(new q(this.project,N.sessionAuthor,B().toISOString(),this,!0,"sync-entity-to-match-input-map-data-type"))){var E,b,g,_,$,L,j,k,G,H,ie,ee,ue,ae,de,ce,ne,le;const a=[],c=[],e=[],f=[];if(((E=i.declaration)==null?void 0:E.id)!==re.operation[xe.Validate].inputs.entityToMatch.id)return r==null||r.attemptAutoclose("sync-entity-to-match-input-map-data-type",this.id),{updated:[],added:[],removed:[],affected:[],self:null};const h=((b=this.project.requestActiveDynamicValue(i))==null?void 0:b.value)||null,m=h==null?void 0:h.valueAsTypeSingle;if(!i.dataType){const Q={id:N.UUID.uuid(),version:N.UUID.uuid(),createdAt:(r==null?void 0:r.timestamp)||new Date().toISOString(),author:(r==null?void 0:r.author)||N.sessionAuthor,previousVersion:null,deleted:!1,deletable:!0,editable:!0,type:d.DataType,parentRelationType:null,options:((g=i.declaration.dataType)==null?void 0:g.options)||null,implementationChooseOne:((_=i.declaration.dataType)==null?void 0:_.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:((k=i.declaration.dataType)==null?void 0:k.index)??null,isList:((G=i.declaration.dataType)==null?void 0:G.isList)||!1,foreignKeyAllowed:((H=i.declaration.dataType)==null?void 0:H.foreignKeyAllowed)??null,andChildrenGroup:null,orChildrenGroup:null,foreignKeyRef:null,asType:!0,entity:(m==null?void 0:m.toJSON())||null,like:!0,inferred:!0,parent:i.toReference()},oe=Ae(Q,i.project);oe.hydrateAncestors(),oe.setParent(i,r),oe.initChildren(r),oe.setEntity(m,r),r==null||r.add(oe,W.Added),a.push(oe),i.setDataType(oe,r)}return(ne=i.dataType)==null||ne.metaSync({inferred:!0,like:!1,asType:!0,options:((ie=i.declaration.dataType)==null?void 0:ie.options)||null,implementationChooseOne:((ee=i.declaration.dataType)==null?void 0:ee.implementationChooseOne)||!1,staticEntities:((ue=i.declaration.dataType)==null?void 0:ue.staticEntities)??null,interactiveEntities:((ae=i.declaration.dataType)==null?void 0:ae.interactiveEntities)??null,actionEntities:((de=i.declaration.dataType)==null?void 0:de.actionEntities)??null,isList:((ce=i.declaration.dataType)==null?void 0:ce.isList)||!1},r),(le=i.dataType)==null||le.setEntity(m,r),i.dataType&&c.push(i.dataType),r==null||r.attemptAutoclose("sync-entity-to-match-input-map-data-type",this.id),{updated:C(c),added:C(a),removed:C(e),affected:C(f),self:i.dataType}}syncDataToValidateInputMapDataType(i,r=this.project.addChangeSet(new q(this.project,N.sessionAuthor,B().toISOString(),this,!0,"sync-data-to-validate-input-map-data-type"))){var b,g,_;const a=[],c=[],e=[],f=[];if(((b=i.declaration)==null?void 0:b.id)!==re.operation[xe.Validate].inputs.dataToValidate.id)return r==null||r.attemptAutoclose("sync-data-to-validate-input-map-data-type",this.id),{updated:[],added:[],removed:[],affected:[],self:null};const h=this.getEntityToMatchInputMap(i.parent);if(!h)return r==null||r.attemptAutoclose("sync-data-to-validate-input-map-data-type",this.id),{updated:[],added:[],removed:[],affected:[],self:null};if(!this.getEntityToMatch(h,r))return r==null||r.attemptAutoclose("sync-data-to-validate-input-map-data-type",this.id),{updated:[],added:[],removed:[],affected:[],self:null};if(!i.dataType){const $={id:N.UUID.uuid(),version:N.UUID.uuid(),createdAt:(r==null?void 0:r.timestamp)||new Date().toISOString(),author:(r==null?void 0:r.author)||N.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=Ae($,i.project);L.setParent(i,r),L.initChildren(r),r==null||r.add(L,W.Added),a.push(L),i.setDataType(L,r)}(g=i.dataType)==null||g.metaSync({inferred:!0,like:!0,asType:!1},r);const E=this.getEntityToMatch(h,r);return(_=i.dataType)==null||_.setEntity(E,r),i.dataType&&c.push(i.dataType),r==null||r.attemptAutoclose("sync-data-to-validate-input-map-data-type",this.id),{updated:C(c),added:C(a),removed:C(e),affected:C(f),self:i.dataType}}syncOutputDataOutputMapDataType(i,r=this.project.addChangeSet(new q(this.project,N.sessionAuthor,B().toISOString(),this,!0,"sync-output-data-output-map-data-type"))){var g,_,$,L;const a=[],c=[],e=[],f=[];if(((g=i.declaration)==null?void 0:g.id)!==re.operation[xe.Validate].dataType.entity.properties.outputEntity.id)return r==null||r.attemptAutoclose("sync-output-data-output-map-data-type",this.id),{updated:[],added:[],removed:[],affected:[],self:null};const h=this.getEntityToMatchInputMap(i.parent);if(!h)return r==null||r.attemptAutoclose("sync-output-data-output-map-data-type",this.id),{updated:[],added:[],removed:[],affected:[],self:null};if(!this.getEntityToMatch(h,r))return r==null||r.attemptAutoclose("sync-output-data-output-map-data-type",this.id),{updated:[],added:[],removed:[],affected:[],self:null};const E=((_=this.project.requestActiveDynamicValue(h))==null?void 0:_.value)||null,b=(E==null?void 0:E.valueAsTypeSingle)||null;if(!i.dataType){const j={id:N.UUID.uuid(),version:N.UUID.uuid(),createdAt:(r==null?void 0:r.timestamp)||new Date().toISOString(),author:(r==null?void 0:r.author)||N.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()},k=Ae(j,i.project);k.hydrateAncestors(),k.setParent(i,r),k.initChildren(r),k.setEntity(b,r),r==null||r.add(k,W.Added),a.push(k),i.setDataType(k,r)}return($=i.dataType)==null||$.metaSync({inferred:!0,like:!0,asType:!1},r),(L=i.dataType)==null||L.setEntity(b,r),i.dataType&&c.push(i.dataType),r==null||r.attemptAutoclose("sync-output-data-output-map-data-type",this.id),{updated:C(c),added:C(a),removed:C(e),affected:C(f),self:i.dataType}}inferInputMapDataType(i,r=this.project.addChangeSet(new q(this.project,N.sessionAuthor,B().toISOString(),this,!0,"infer-input-map-data-type-validate-data"))){var c,e,f;if(((c=i.declaration)==null?void 0:c.id)===re.operation[xe.Validate].inputs.entityToMatch.id){const{added:h,updated:m,removed:E,affected:b}=r?this.syncEntityToMatchInputMapDataType(i,r):{added:[],updated:[],removed:[],affected:[]};return r==null||r.attemptAutoclose("infer-input-map-data-type",this.id),{updated:C(m),added:C(h),removed:C(E),affected:C(b),self:i.dataType}}if(((e=i.declaration)==null?void 0:e.id)===re.operation[xe.Validate].inputs.dataToValidate.id){const{added:h,updated:m,removed:E,affected:b}=this.syncDataToValidateInputMapDataType(i,r);return r==null||r.attemptAutoclose("infer-input-map-data-type",this.id),{updated:C(m),added:C(h),removed:C(E),affected:C(b),self:i.dataType}}const a=(f=i.declaration)==null?void 0:f.getDataType(r);if(a&&a.isResolved)return r==null||r.attemptAutoclose("infer-input-map-data-type-validate-data",this.id),{updated:[],added:[],removed:[],affected:[],self:a};if(i.readsValue){const h=jd(i.readsValue,r);return r==null||r.attemptAutoclose("infer-input-map-data-type-validate-data",this.id),{updated:[],added:[],removed:[],affected:[],self:h}}return r==null||r.attemptAutoclose("infer-input-map-data-type-validate-data",this.id),{updated:[],added:[],removed:[],affected:[],self:null}}inferOutputMapDataType(i,r=this.project.addChangeSet(new q(this.project,N.sessionAuthor,B().toISOString(),this,!0,"infer-output-map-data-type-validate-data"))){var a;if(((a=i.declaration)==null?void 0:a.id)===re.operation[xe.Validate].dataType.entity.properties.outputEntity.id){const{added:c,updated:e,removed:f,affected:h}=this.syncOutputDataOutputMapDataType(i,r);return r==null||r.attemptAutoclose("infer-output-map-data-type-validate-data",this.id),{updated:C(e),added:C(c),removed:C(f),affected:C(h),self:i.dataType}}return{updated:[],added:[],removed:[],affected:[],self:null}}}class L_i extends ki{constructor(p){super(SV,p)}}class B_i extends ki{constructor(p){super(qV,p)}}class M_i extends ki{constructor(p){super(ZV,p)}}class G_i extends ki{constructor(p){super(VI,p)}}class j_i extends ki{constructor(p){super(zg,p)}}class U_i extends ki{constructor(p){super(iv,p)}}function EUe(l){const p=[new j_e(l),new M_e(l),new G_e(l),new x_i(l),new $_i(l),new G_i(l),new L_i(l),new M_i(l),new B_i(l),new j_i(l),new U_i(l)];return TN.forEach(i=>{p.some(r=>r.id===i.id)||p.push(new ki(i,l))}),p.forEach(i=>{i.initChildren(null),l.subscribeBuiltInInstance(i)}),l.operationDeclarations=p,p}class k_i extends qd{constructor(i){super($n,i);R(this,"initialData");R(this,"id",Ie.PERSISTED_ENTITY);R(this,"version","1");R(this,"name",Ie.PERSISTED_ENTITY);R(this,"description",$n.description);R(this,"type",d.BuiltInBaseEntity);R(this,"abstract",$n.abstract);R(this,"static",$n.static);R(this,"properties",[]);R(this,"methods",[]);R(this,"abstractMethods",[]);R(this,"extends",null);R(this,"errors",[]);R(this,"project");this.initialData=$n,this.project=i,this.id=$n.id,this.version=$n.version,this.name=$n.name,this.static=$n.static,this.abstract=$n.abstract,this.properties=this.initialData.properties.map(a=>{const c=Ae(a,this.project);return c.setParent(this,null),c.initChildren(null),c}),this.methods=this.initialData.methods.map(a=>{const c=Ae(a,this.project);return c.parent=this,c}),this.abstractMethods=this.initialData.abstractMethods.map(a=>{const c=Ae(a,this.project);return c.parent=this,c}),this.initialData.extends&&(this.extends=Ae(this.initialData.extends,this.project));const r=this.properties.find(a=>a.id===re["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.identifier.id);if(!r)throw new Error("Path property not found in endpoint entity");r._codeNativeValueValidation=(a,c)=>$_e(a,c)}}const F_i=[];function bUe(l){const p=[new x_e(l),new B_e(l),new k_i(l)];return KN.forEach(i=>{!p.some(r=>r.id===i.id)&&!F_i.includes(i.id)&&p.push(new qd(i,l))}),p.forEach(i=>{l.subscribeBuiltInInstance(i)}),l.builtInBaseEntities=p,p}function AUe(l){const p=[new Ca(ve,l),new Ca(ut,l),new Ca(Pe,l),new Ca(ma,l),new Ca(It,l),new Ca(Pt,l),new Ca(dt,l),new Ca(ql,l),new Ca(er,l)];return p.forEach(i=>{l.subscribeBuiltInInstance(i)}),l.primitives=p,p}function gUe(l){const p=[new ki(ZR,l)];return p.forEach(i=>{i.initChildren(null),l.subscribeBuiltInInstance(i)}),l.globalEventActionDescriptors=p,p}function IUe(l){const p=[new ki(Xv,l),new ki(xf,l),new ki(Yv,l),new ki(cm,l),new ki(fm,l),new ki(wR,l)];p.forEach(r=>{r.initChildren(null),l.subscribeBuiltInInstance(r)}),l.loopDeclarations=p;const i=[new ki(BR,l),new ki(Jv,l),new ki(VR,l),new ki(IN,l),new ki(wN,l),new ki(CR,l)];return i.forEach(r=>{r.initChildren(null),l.subscribeBuiltInInstance(r)}),l.loopDeclarationsBodies=i,p}function RUe(l){const p=[new Hd(YN,l)];return p.forEach(i=>{i.initChildren(null),l.subscribeBuiltInInstance(i)}),l.valueDescriptors=p,p}function DUe(l){const p=[new ki(qN,l),new ki(SN,l),new ki(ZN,l),new ki(HN,l)];return WN.forEach(i=>{p.some(r=>r.id===i.id)||p.push(new ki(i,l))}),p.forEach(i=>{i.initChildren(null),l.subscribeBuiltInInstance(i)}),l.conditionDeclarations=p,p}function AT(l){return l&&typeof l.then=="function"}function K_i(l,p){const i=new cn(l[0],{allBuiltInEntityIds:p.allBuiltInEntityIds}),r=l.map(c=>c.id),a={};return l.forEach(c=>{a[c.id]=c}),i.order=r,i.flatRecord=a,i.orderEntities(),i.order.map(c=>i.flatRecord[c])}function S_i(l,p){const i=new cn(Object.values(l)[0],{allBuiltInEntityIds:p.allBuiltInEntityIds}),r=Object.keys(l);return i.order=r,i.flatRecord=l,i.orderEntities(),i.order}async function q_i(l,p){const i=z.YieldTracker.from(p),r=new cn(l[0],{allBuiltInEntityIds:p.allBuiltInEntityIds}),a=l.map(e=>e.id),c={};for(const e of l)c[e.id]=e,await i.tick();return r.order=a,r.flatRecord=c,await r.orderEntitiesAsync({tracker:i}),r.order.map(e=>r.flatRecord[e])}async function Z_i(l,p){const i=z.YieldTracker.from(p),r=new cn(Object.values(l)[0],{allBuiltInEntityIds:p.allBuiltInEntityIds}),a=Object.keys(l);return r.order=a,r.flatRecord=l,await r.orderEntitiesAsync({tracker:i}),r.order}class cn{constructor(p,i={}){R(this,"order",[]);R(this,"flatRecord",{});R(this,"allBuiltInEntityIds");R(this,"onGoingVisits",{});R(this,"cachedReferences",{});if(i.allBuiltInEntityIds&&(this.allBuiltInEntityIds=i.allBuiltInEntityIds),!p)return;const r={asyncInitialOrder:!1,...i};r.asyncInitialOrder?this.flattenAsync(p).then(()=>{this.orderEntitiesAsync({...r}).then(()=>{var a;(a=r.onOrdered)==null||a.call(r)})}):(this.flatten(p),this.orderEntities())}flatten(p){this.allBuiltInEntityIds||(this.allBuiltInEntityIds=new Set(j1()));const i=C(Ue(p,new Set(this.allBuiltInEntityIds),{ignoreBuiltInBaseEntities:!0,diggestedBuiltInBaseEntitiesIds:this.allBuiltInEntityIds})),r=new Set;for(const a of i)this.flatRecord[a.id]=a,r.add(a.id);this.order=Array.from(r)}async flattenAsync(p,i={}){const r=z.YieldTracker.from(i);this.allBuiltInEntityIds||(this.allBuiltInEntityIds=await U1({tracker:r}));const a=await kd(await je(p,new Set(this.allBuiltInEntityIds),{ignoreBuiltInBaseEntities:!0,diggestedBuiltInBaseEntitiesIds:this.allBuiltInEntityIds,tracker:r}),{tracker:r}),c=new Set;for(const e of a)this.flatRecord[e.id]=e,c.add(e.id),await r.tick();this.order=Array.from(c)}moveEntityAfterDependencies(p){const i=this.cachedReferences[p.id]||Ul(p,this.flatRecord,{ignoreBuiltInBaseEntities:!0,allBuiltInEntityIds:this.allBuiltInEntityIds});this.cachedReferences[p.id]=i;const{upstream:r}=i;for(const a of Object.keys(r)){const c=this.order.indexOf(a),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 r=this.order[i],a=this.flatRecord[r];if(a||z.Logger.warn(`Entity with id ${r} not found in flatRecord. Skipping...`),this.moveEntityAfterDependencies(a)){p=!0;break}}p&&this.orderEntities()}async orderEntitiesAsync(p={}){let i=!1;const r=z.YieldTracker.from(p);for(let a=0;a<this.order.length;a++){const c=this.order[a],e=this.flatRecord[c];if(e||z.Logger.warn(`Entity with id ${c} not found in flatRecord. Skipping...`),this.moveEntityAfterDependencies(e)){i=!0;break}await r.tick()}i&&await this.orderEntitiesAsync({tracker:r})}getUpstreamOngoingDependenciesVisits(p,i){const r=this.cachedReferences[p]||Ul(this.flatRecord[p],this.flatRecord,{ignoreBuiltInBaseEntities:!0,allBuiltInEntityIds:this.allBuiltInEntityIds});this.cachedReferences[p]=r;const{upstream:a}=r,c={};return Object.entries(this.onGoingVisits[i]||{}).forEach(([e,f])=>{Object.keys(a).includes(e)&&(c[e]=f)}),c}getDownstreamOngoingDependenciesVisits(p,i){const r=Object.keys(this.onGoingVisits[i]||{}),a=new Set(r.flatMap(e=>{const f=this.cachedReferences[e]||Ul(this.flatRecord[e],this.flatRecord,{ignoreBuiltInBaseEntities:!0,allBuiltInEntityIds:this.allBuiltInEntityIds});return this.cachedReferences[e]=f,Object.keys(f.downstream)})),c={};return Array.from(a).forEach(e=>{e===p&&(c[e]=this.onGoingVisits[i][e])}),c}async settlePromises(p,i){const r=Object.values(p);r.length&&await Promise.all(r),Object.keys(p).forEach(a=>{delete this.onGoingVisits[i][a]})}visit(p){const i=this.order;for(const r of i)p(this.flatRecord[r],this.flatRecord);return this}reverseVisit(p){const i=this.order.slice().reverse();for(const r of i)p(this.flatRecord[r],this.flatRecord);return this}async visitAsync(p,i={}){const{parallelise:r}={parallelise:!0,...i},a=z.YieldTracker.from(i),c=this.order;if(!r){for(const f of c){const h=p(this.flatRecord[f],this.flatRecord);AT(h)&&await h,await a.tick()}return this}const e=Math.random().toString(36).substring(7);this.onGoingVisits[e]={};for(const f of c){const h=this.getUpstreamOngoingDependenciesVisits(f,e);Object.keys(h).length&&await this.settlePromises(h,e);const m=p(this.flatRecord[f],this.flatRecord);AT(m)&&(this.onGoingVisits[e][f]=m),await a.tick()}return await this.settlePromises(this.onGoingVisits[e],e),this.onGoingVisits[e]={},this}async reverseVisitAsync(p,i={}){const{parallelise:r}={parallelise:!0,...i},a=z.YieldTracker.from(i),c=this.order.slice().reverse();if(!r){for(const f of c){const h=p(this.flatRecord[f],this.flatRecord);AT(h)&&await h,await a.tick()}return this}const e=Math.random().toString(36).substring(7);this.onGoingVisits[e]={};for(const f of c){const h=this.getDownstreamOngoingDependenciesVisits(f,e);Object.keys(h).length&&await this.settlePromises(h,e);const m=p(this.flatRecord[f],this.flatRecord);AT(m)&&(this.onGoingVisits[e][f]=m),await a.tick()}return await this.settlePromises(this.onGoingVisits[e],e),this.onGoingVisits[e]={},this}}const Qc={},BA={},HT={empty:!1,enrich:!0,mock:!1,ignoreCache:!1,onFetch:async()=>null,manuallyInit:!1};function wUe(l,p={enrich:!0,shallowErrors:!1},i){const r={enrich:!0,shallowErrors:!1,...p},{enrich:a,shallowErrors:c}=r,e=l.project,f=l.record,h=x1(l.project,{shallowErrors:c},i);h.instances[e.id]=h;const m=new cn(e,{allBuiltInEntityIds:h.diggestedBuiltInBaseEntitiesIds}),E=new Set;f[e.id]=e,E.add(e.id);const b=B().toISOString();Object.values(f).forEach(_=>{!_||m.allBuiltInEntityIds.has(_.id)||E.add(_.id)}),m.order=Array.from(E),m.flatRecord=f,m.orderEntities();const g=a?h.addChangeSet(new q(h,N.sessionAuthor,b,h,!0,"project-init-from-fetch-result")):null;return m.visit(_=>{if(_.id===h.id)return;const $=Ae(_,h);try{$.hydrateAncestors(),$.addSelfToProject(null);const L=Ul(_);Object.keys(L.downstream).forEach(j=>{const k=h.get(j);k&&k.hydrateAncestors()})}catch(L){if(c)z.Logger.error("Error hydrating ancestors: ",L);else throw L}}),a?(m.visit(_=>{if(_.id===h.id)return;const $=h.get(_.id);if($)try{$.afterAllChildrenInitialized(g)}catch(L){if(c)z.Logger.error("Error in afterAllChildrenInitialized: ",L);else throw L}}),h.afterAllChildrenInitialized(g)):Cu(h,b).forEach($=>{$.remove({ignoreUpstream:!0},null)}),h.instancesList.forEach(_=>{_.previousVersion=null}),h.initialized=!0,h.emit(ri.PROJECT_INITIALIZED,h,g),g==null||g.attemptAutoclose("project-init-from-fetch-result",h.id),h}async function H_i(l,p={enrich:!0,shallowErrors:!1,yieldEvery:100},i){const r={enrich:!0,shallowErrors:!1,yieldEvery:100,...p},{enrich:a,shallowErrors:c,yieldEvery:e}=r,f=l.project,h=l.record,m=await $1(l.project,{shallowErrors:c,yieldEvery:e},i);m.instances[f.id]=m;const E=new cn(void 0,{allBuiltInEntityIds:m.diggestedBuiltInBaseEntitiesIds});await E.flattenAsync(f,{yieldEvery:e}),await E.orderEntitiesAsync({yieldEvery:e});const b=new Set;h[f.id]=f,b.add(f.id);const g=B().toISOString();let _=0;for(const[j,k]of Object.entries(h))!k||E.allBuiltInEntityIds.has(k.id)||(b.add(k.id),++_%e===0&&await z.yieldToEventLoop());E.order=Array.from(b),E.flatRecord=h,await E.orderEntitiesAsync();const $=a?m.addChangeSet(new q(m,N.sessionAuthor,g,m,!0,"project-init-from-fetch-result")):null;if(await E.visitAsync(j=>{if(j.id===m.id)return;const k=Ae(j,m);try{k.hydrateAncestors(),k.addSelfToProject(null);const G=Ul(j);Object.keys(G.downstream).forEach(H=>{const ie=m.get(H);ie&&ie.hydrateAncestors()})}catch(G){if(c)z.Logger.error("Error hydrating ancestors: ",G);else throw console.log("Error hydrating ancestors: ",G),G}},{yieldEvery:e}),a){try{await E.visitAsync(j=>{if(j.id===m.id)return;const k=m.get(j.id);k&&k.afterAllChildrenInitialized($)},{yieldEvery:e})}catch(j){if(c)z.Logger.error("Error in afterAllChildrenInitialized: ",j);else throw console.log("Error in afterAllChildrenInitialized: ",j),j}m.afterAllChildrenInitialized($)}else Cu(m,g).forEach(k=>{k.remove({ignoreUpstream:!0},null)});let L=0;for(const j of m.instancesList)j.previousVersion=null,++L%e===0&&await z.yieldToEventLoop();return m.initialized=!0,m.emit(ri.PROJECT_INITIALIZED,m,$),$==null||$.attemptAutoclose("project-init-from-fetch-result",m.id),m}async function W_i(l,p=HT){const i={...HT,...p};if(i.empty)return{data:{project:{id:l.id,deletable:!0,editable:!0,type:d.Project,version:N.UUID.uuid(),createdAt:B().toISOString(),author:N.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 a={...YL};return a.id=l.id,{data:{project:a,record:{}}}}return z.Logger.log("Fetching project from external API"),new Promise(async a=>{try{if(i.onFetch){const c=await i.onFetch(l.id);if(c){a({data:c});return}}else a({data:null})}catch(c){z.Logger.error("Error fetching project: ",c),a({data:null})}})}function x1(l,p={shallowErrors:!1},i){const r=new N(l,i);AUe(r),bUe(r),EUe(r),gUe(r),IUe(r),RUe(r),DUe(r);const a=p.allBuiltInIds??new Set([...r.getAllBuiltInIds(),...j1()]);return r.diggestedBuiltInBaseEntitiesIds=a,a.forEach(c=>{if(!r.builtInInstances[c]&&r.instances[c])r.builtInInstances[c]=r.instances[c],delete r.instances[c];else if(!r.builtInInstances[c]&&!p.shallowErrors)throw new Error(`Built in entity was not properly initialized: ${c}`)}),r.instances[r.id]=r,r}async function $1(l,p={shallowErrors:!1},i){const r=z.YieldTracker.from(p),a=new N(l,i);AUe(a),bUe(a),await z.yieldToEventLoop(),EUe(a),await z.yieldToEventLoop(),gUe(a),IUe(a),RUe(a),DUe(a),await z.yieldToEventLoop();const c=p.allBuiltInIds??new Set([...a.getAllBuiltInIds(),...await U1()]);a.diggestedBuiltInBaseEntitiesIds=c;for(const e of c){if(!a.builtInInstances[e]&&a.instances[e])a.builtInInstances[e]=a.instances[e],delete a.instances[e];else if(!a.builtInInstances[e]&&!p.shallowErrors)throw new Error(`Built in entity was not properly initialized: ${e}`);a.instances[e]&&delete a.instances[e],await r.tick()}return a.instances[a.id]=a,a}function Cu(l,p){return l.instancesList.filter(r=>B(r.createdAt).isAfter(B(p)||!!r.previousVersion))}function z_i(l,{enrich:p,shallowErrors:i,...r}={enrich:!0,shallowErrors:!1},a){var _,$;const c=new Map,e=new Map;Object.keys(l.instances).forEach(L=>{if(l.diggestedBuiltInBaseEntitiesIds.has(L)){c.set(L,L),e.set(L,L);return}const j=l.get(L);if(!W1(j,{...l.instances,...l.builtInInstances}).every(ie=>!l.diggestedBuiltInBaseEntitiesIds.has(ie))){c.set(L,L),e.set(L,L);return}const H=N.UUID.uuid();c.set(L,H),e.set(H,L)});const f=((_=r.resetVersionOptions)==null?void 0:_.commonTimestamp)??B().toISOString(),h=l.toShallowJSON({seenEntityMaps:c});h.previousVersion=null,h.createdAt=f,h.version=N.UUID.uuid(),h.author=(($=r.resetVersionOptions)==null?void 0:$.author)??(N.sessionAuthor||"1");const m=x1(h,{shallowErrors:i,allBuiltInIds:l.diggestedBuiltInBaseEntitiesIds},a);m.instances[m.id]=m;const E=p?m.addChangeSet(new q(m,N.sessionAuthor,f,m,!0,"project-clone")):null,b=new cn(l,{allBuiltInEntityIds:l.diggestedBuiltInBaseEntitiesIds}),g=iL(b.flatRecord,c);return b.visit(L=>{var H;const j=L.toShallowJSON({seenEntityMaps:c});j.previousVersion=null,j.createdAt=f,j.version=N.UUID.uuid(),j.author=((H=r.resetVersionOptions)==null?void 0:H.author)??(N.sessionAuthor||"1");const k=Ul(j,g);if(Object.keys(k.upstream).length){let ie=!1;if(Object.keys(k.upstream).forEach(ee=>{if(!ie&&(!m.get(ee)||m.getDeleted(ee))){ie=!0;return}}),ie)return}const G=Ae(j,m);G.hydrateAncestors(),G.addSelfToProject(E),E==null||E.add(G,W.Added),r.onVisit&&r.onVisit(j)}),p?(b.visit(L=>{if(L.id===m.id)return;const j=m.get(c.get(L.id));j&&j.afterAllChildrenInitialized(E)}),m.afterAllChildrenInitialized(E)):Cu(m,f).forEach(j=>{j.remove({ignoreUpstream:!0},null)}),m.instancesList.forEach(L=>{L.previousVersion=null}),E==null||E.attemptAutoclose("project-clone",m.id),{project:m,maps:c}}async function Y_i(l,{shallowErrors:p,...i}={shallowErrors:!1,yieldEvery:100}){var m,E;const r=z.YieldTracker.from(i),a=new Map,c=new Map;Object.keys(l.instances).forEach(b=>{if(l.diggestedBuiltInBaseEntitiesIds.has(b)){a.set(b,b),c.set(b,b);return}const g=N.UUID.uuid();a.set(b,g),c.set(g,b)});const e=((m=i.resetVersionOptions)==null?void 0:m.commonTimestamp)??B().toISOString(),f=l.toShallowJSON({seenEntityMaps:a});f.previousVersion=null,f.createdAt=e,f.version=N.UUID.uuid(),f.author=((E=i.resetVersionOptions)==null?void 0:E.author)??(N.sessionAuthor||"1");const h=await l.toFullProjectTransferAsync({tracker:r,seenEntityMaps:a,resetVersionOptions:i.resetVersionOptions,onVisit:i.onVisit});return{project:f,record:h.record,order:h.order,maps:a}}async function J_i(l,{enrich:p,shallowErrors:i,...r}={enrich:!0,shallowErrors:!1,yieldEvery:100},a){var $,L;const c=z.YieldTracker.from(r),e=new Map,f=new Map;for(const j of Object.keys(l.instances)){if(l.diggestedBuiltInBaseEntitiesIds.has(j)){e.set(j,j),f.set(j,j),await c.tick();continue}const k=N.UUID.uuid();e.set(j,k),f.set(k,j),await c.tick()}const h=(($=r.resetVersionOptions)==null?void 0:$.commonTimestamp)??B().toISOString(),m=l.toShallowJSON({seenEntityMaps:e});m.previousVersion=null,m.createdAt=h,m.version=N.UUID.uuid(),m.author=((L=r.resetVersionOptions)==null?void 0:L.author)??(N.sessionAuthor||"1");const E=await $1(m,{shallowErrors:i,tracker:c},a);E.diggestedBuiltInBaseEntitiesIds=l.diggestedBuiltInBaseEntitiesIds,E.instances[E.id]=E;const b=p?E.addChangeSet(new q(E,N.sessionAuthor,h,E,!0,"project-clone")):null,g=new cn(void 0,{allBuiltInEntityIds:l.diggestedBuiltInBaseEntitiesIds}),_=await l.toFullProjectTransferAsync({tracker:c,seenEntityMaps:e,resetVersionOptions:r.resetVersionOptions,onVisit:r.onVisit});g.flatRecord=_.record,g.order=_.order,await g.visitAsync(j=>{var ie;if(l.diggestedBuiltInBaseEntitiesIds.has(j.id))return;const k=j;k.previousVersion=null,k.createdAt=h,k.version=N.UUID.uuid(),k.author=((ie=r.resetVersionOptions)==null?void 0:ie.author)??(N.sessionAuthor||"1");const G=Ul(k,g.flatRecord);if(Object.keys(G.upstream).length){let ee=!1;if(Object.keys(G.upstream).forEach(ue=>{if(!ee&&(!E.get(ue)||E.getDeleted(ue))){ee=!0;return}}),ee)return}const H=Ae(k,E);H.hydrateAncestors(),H.addSelfToProject(b),b==null||b.add(H,W.Added)},{tracker:c}),p?(await g.visitAsync(j=>{if(j.id===E.id||l.diggestedBuiltInBaseEntitiesIds.has(j.id))return;const k=E.get(e.get(j.id));k&&k.afterAllChildrenInitialized(b)},{tracker:c}),E.afterAllChildrenInitialized(b)):Cu(E,h).forEach(k=>{k.remove({ignoreUpstream:!0},null)});for(const j of E.instancesList)j.previousVersion=null,await c.tick();return b==null||b.attemptAutoclose("project-clone",E.id),{project:E,maps:e}}function X_i(l,p,i=p.addChangeSet(new q(p,N.sessionAuthor,B().toISOString(),p,!0,w.AfterAllChildrenInitialized)),{enrich:r,shallowErrors:a,...c}={shallowErrors:!1,enrich:!0}){var g,_;const e=new Map,f=new Map;Object.keys(l.instances).forEach($=>{if(l.diggestedBuiltInBaseEntitiesIds.has($)){e.set($,$),f.set($,$);return}if($===l.id){e.set($,p.id),f.set(p.id,$);return}const L=l.get($);if(!W1(L,{...l.instances,...l.builtInInstances}).every(H=>!l.diggestedBuiltInBaseEntitiesIds.has(H))){e.set($,$),f.set($,$);return}const G=N.UUID.uuid();e.set($,G),f.set(G,$)});const h=((g=c.resetVersionOptions)==null?void 0:g.commonTimestamp)??B().toISOString(),m=l.toShallowJSON({seenEntityMaps:e});m.previousVersion=null,m.createdAt=h,m.version=N.UUID.uuid(),m.author=((_=c.resetVersionOptions)==null?void 0:_.author)??(N.sessionAuthor||"1");const E=new cn(l,{allBuiltInEntityIds:l.diggestedBuiltInBaseEntitiesIds}),b=iL(E.flatRecord,e);return E.visit($=>{var k;if($.id===p.id)return;const L=$.toShallowJSON({seenEntityMaps:e});L.previousVersion=null,L.createdAt=h,L.version=N.UUID.uuid(),L.author=((k=c.resetVersionOptions)==null?void 0:k.author)??(N.sessionAuthor||"1");const j=Ul(L,b);if(Object.keys(j.upstream).length){let G=!1;if(Object.keys(j.upstream).forEach(H=>{if(!G&&(!p.get(H)||p.getDeleted(H))){G=!0;return}}),G)return}try{const G=Ae(L,p);G.hydrateAncestors(),G.addSelfToProject(i),i==null||i.add(G,W.Added),c.onVisit&&c.onVisit(L)}catch(G){if(a)z.Logger.error("Error cloning entity onto existing project: ",G);else throw console.log("Error cloning entity onto existing project: ",G),G}}),r?E.visit($=>{if($.id===p.id)return;const L=p.get(e.get($.id));L&&L.afterAllChildrenInitialized(i)}):Cu(p,h).forEach(L=>{L.remove({ignoreUpstream:!0},null)}),p.afterAllChildrenInitialized(i),p.instancesList.forEach($=>{$.previousVersion=null}),{project:p,maps:e,changeSet:i}}async function Q_i(l,p,i=p.addChangeSet(new q(p,N.sessionAuthor,B().toISOString(),p,!0,w.AfterAllChildrenInitialized)),{enrich:r,shallowErrors:a,...c}={enrich:!0,shallowErrors:!1,yieldEvery:100}){var _,$;const e=z.YieldTracker.from(c),f=new Map,h=new Map;for(const L of Object.keys(l.instances)){if(l.diggestedBuiltInBaseEntitiesIds.has(L)){f.set(L,L),h.set(L,L),await e.tick();continue}if(L===l.id){f.set(L,p.id),h.set(p.id,L),await e.tick();continue}const j=N.UUID.uuid();f.set(L,j),h.set(j,L),await e.tick()}const m=((_=c.resetVersionOptions)==null?void 0:_.commonTimestamp)??B().toISOString(),E=l.toShallowJSON({seenEntityMaps:f});E.previousVersion=null,E.createdAt=m,E.version=N.UUID.uuid(),E.author=(($=c.resetVersionOptions)==null?void 0:$.author)??(N.sessionAuthor||"1"),p.diggestedBuiltInBaseEntitiesIds=l.diggestedBuiltInBaseEntitiesIds;const b=new cn(void 0,{allBuiltInEntityIds:l.diggestedBuiltInBaseEntitiesIds}),g=await l.toFullProjectTransferAsync({tracker:e,seenEntityMaps:f,resetVersionOptions:c.resetVersionOptions,onVisit:c.onVisit,shallowErrors:a});b.flatRecord=g.record,b.order=g.order,await b.visitAsync(L=>{var G;if(l.diggestedBuiltInBaseEntitiesIds.has(L.id)||L.id===p.id)return;const j=L;j.previousVersion=null,j.createdAt=m,j.version=N.UUID.uuid(),j.author=((G=c.resetVersionOptions)==null?void 0:G.author)??(N.sessionAuthor||"1");const k=Ul(j,b.flatRecord);if(Object.keys(k.upstream).length){let H=!1;if(Object.keys(k.upstream).forEach(ie=>{if(!H&&(!p.get(ie)||p.getDeleted(ie))){H=!0;return}}),H)return}try{const H=Ae(j,p);H.hydrateAncestors(),H.addSelfToProject(i),i==null||i.add(H,W.Added)}catch(H){if(a)z.Logger.error("Error cloning entity onto existing project: ",H);else throw console.log("Error cloning entity onto existing project: ",H),H}},{tracker:e}),r?await b.visitAsync(L=>{if(L.id===p.id||l.diggestedBuiltInBaseEntitiesIds.has(L.id))return;const j=p.get(f.get(L.id));j&&j.afterAllChildrenInitialized(i)},{tracker:e}):Cu(p,m).forEach(j=>{j.remove({ignoreUpstream:!0},null)}),p.afterAllChildrenInitialized(i);for(const L of p.instancesList)L.previousVersion=null,await e.tick();return{project:p,maps:f,changeSet:i}}function CUe(l,{enrich:p,shallowErrors:i}={enrich:!0,shallowErrors:!1},r){const a=x1(l,{shallowErrors:i},r),c=B().toISOString(),e=p?a.addChangeSet(new q(a,N.sessionAuthor,c,a,!0,"project-init")):null;e&&(e.type=WR.Automatic);const f=new cn(l,{allBuiltInEntityIds:a.diggestedBuiltInBaseEntitiesIds});return f.visit(h=>{const m=Ae(h,a);m.hydrateAncestors(),m.addSelfToProject(e)}),p?(f.visit(h=>{if(h.id===a.id)return;const m=a.get(h.id);m&&m.afterAllChildrenInitialized(e)}),a.afterAllChildrenInitialized(e)):(Cu(a,c).forEach(E=>{E.remove({ignoreUpstream:!0},null)}),new cn(a,{allBuiltInEntityIds:a.diggestedBuiltInBaseEntitiesIds}).visit(E=>{E.initialized=!0,E.captureVersion()})),a.initialized=!0,a.emit(ri.PROJECT_INITIALIZED,a,e),e==null||e.attemptAutoclose("project-init",a.id),a}async function eVi(l,{enrich:p,shallowErrors:i,yieldEvery:r}={enrich:!0,shallowErrors:!1,yieldEvery:100},a){const c=await $1(l,{shallowErrors:i,yieldEvery:r},a),e=B().toISOString(),f=p?c.addChangeSet(new q(c,N.sessionAuthor,e,c,!0,"project-init")):null;f&&(f.type=WR.Automatic);const h=new cn(void 0,{allBuiltInEntityIds:c.diggestedBuiltInBaseEntitiesIds});if(await h.flattenAsync(l,{yieldEvery:r}),await h.orderEntitiesAsync({yieldEvery:r}),await h.visitAsync(m=>{const E=Ae(m,c);E.hydrateAncestors(),E.addSelfToProject(f)},{yieldEvery:r}),p)await h.visitAsync(m=>{if(m.id===c.id)return;const E=c.get(m.id);E&&E.afterAllChildrenInitialized(f)},{yieldEvery:r}),c.afterAllChildrenInitialized(f);else{Cu(c,e).forEach(b=>{b.remove({ignoreUpstream:!0},null)});const E=new cn(void 0,{allBuiltInEntityIds:c.diggestedBuiltInBaseEntitiesIds});await E.flattenAsync(c,{yieldEvery:r}),await E.orderEntitiesAsync({yieldEvery:r}),await E.visitAsync(b=>{b.initialized=!0,b.captureVersion()},{yieldEvery:r})}return c.initialized=!0,c.emit(ri.PROJECT_INITIALIZED,c,f),f==null||f.attemptAutoclose("project-init",c.id),c}async function tVi(l,p=HT,i){const r={...HT,...p};if(l.id&&Qc[l.id]&&!r.ignoreCache)return Qc[l.id];if(l.id&&BA[l.id]&&!r.ignoreCache)return await BA[l.id],Qc[l.id];const a=W_i(l,r);l.id&&(BA[l.id]=a);const c=await a;if(c.data){let e;return r.mock?e=CUe(YL,{enrich:!!r.enrich},i):c.data instanceof N?e=c.data:e=wUe(c.data,{enrich:!!r.enrich},i),Qc[l.id]=e,l.id&&delete BA[l.id],e}return null}function iVi(l){return Qc[l.id]&&delete Qc[l.id],null}const WT=mt([Ze(),ha(),pr(),Fd()]),OUe=Qv([Yr.CurrentDateAndTime,Yr.Random,Yr.Unique]),L1=at({type:OUe,rangeStart:WT.nullable(),rangeEnd:WT.nullable()}),PE=L1.extend({type:tt(Yr.Random),rangeStart:WT,rangeEnd:WT}),_Ue=L1.extend({type:tt(Yr.Unique),rangeStart:Xa(),rangeEnd:Xa()}),VUe=L1.extend({type:tt(Yr.CurrentDateAndTime),rangeStart:Xa(),rangeEnd:Xa()}),B1=PE.extend({rangeStart:ha().nullable(),rangeEnd:ha().nullable()}),PUe=B1.extend({rangeStart:ha(),rangeEnd:Xa()}),NUe=B1.extend({rangeStart:Xa(),rangeEnd:ha()}),xUe=B1.extend({rangeStart:ha(),rangeEnd:ha()}),M1=PE.extend({rangeStart:ha().nullable(),rangeEnd:ha().nullable()}),$Ue=M1.extend({rangeStart:ha(),rangeEnd:Xa()}),LUe=M1.extend({rangeStart:Xa(),rangeEnd:ha()}),BUe=M1.extend({rangeStart:ha(),rangeEnd:ha()}),G1=PE.extend({rangeStart:Fd().nullable(),rangeEnd:Fd().nullable()}),MUe=G1.extend({rangeStart:Fd(),rangeEnd:Xa()}),GUe=G1.extend({rangeStart:Xa(),rangeEnd:Fd()}),jUe=G1.extend({rangeStart:Fd(),rangeEnd:Fd()}),UUe=PE.extend({rangeStart:Xa(),rangeEnd:Xa()}),kUe=mt([$Ue,LUe,BUe]),FUe=mt([PUe,NUe,xUe]),KUe=mt([MUe,GUe,jUe,VUe]),rVi=mt([kUe,FUe,KUe,_Ue,UUe]);function j1(){const l=new Set;return new Set(JN.flatMap(i=>Ue(i,l)).map(i=>i.id))}function Ao(l){return[...l.calledByEntry||[],...l.calledByError||[],...l.calledBySuccess||[]].filter(p=>p.type!==d.GenericReference)}function SUe(l,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(l.id))return[];if(p.add(l.id),l.type!==d.ActionDescriptor)throw new Error("Entity must be an action descriptor to be flattened");return[l,...l.inputs.flatMap(r=>Ue(r,p,i)),...l.dataType?Ue(l.dataType,p,i):[],...l.error?Ue(l.error,p,i):[],...l.parent?Ue(l.parent,p,i):[]]}function qUe(l,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(l.id))return[];if(p.add(l.id),l.type!==d.ArgumentDeclaration)throw new Error("Entity must be an argument declaration to be flattened");return[l,...l.defaultValue?Ue(l.defaultValue,p):[],...l.writesValues.flatMap(r=>Ue(r,p,i)),...l.implements.flatMap(r=>Ue(r,p,i)),...l.dataType?Ue(l.dataType,p,i):[],...l.parent?Ue(l.parent,p,i):[]]}function ZUe(l,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(l.id))return[];if(p.add(l.id),l.type!==d.BreakStatement)throw new Error("Entity must be a break statement to be flattened");return[l,...l.outputs.flatMap(r=>Ue(r,p,i)),...l.throws?Ue(l.throws,p,i):[],...l.dataType?Ue(l.dataType,p,i):[],...l.readsValue?Ue(l.readsValue,p,i):[],...(Ao(l)||[]).flatMap(r=>Ue(r,p,i)),...l.parent?Ue(l.parent,p,i):[]]}function HUe(l,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(l.id))return[];if(p.add(l.id),l.type!==d.BuiltInBaseEntity)throw new Error("Entity must be a built-in base entity to be flattened");return[l,...(l.properties||[]).flatMap(r=>Ue(r,p,i)),...(l.methods||[]).flatMap(r=>Ue(r,p,i)),...(l.abstractMethods||[]).flatMap(r=>Ue(r,p,i)),...l.allPropertiesImplement?Ue(l.allPropertiesImplement,p,i):[],...l.additionalPropertiesDataType?Ue(l.additionalPropertiesDataType,p,i):[],...l.extends?Ue(l.extends,p,i):[]]}function WUe(l,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(l.id))return[];if(p.add(l.id),l.type!==d.Condition)throw new Error("Entity must be a condition to be flattened");return[l,...(l.andChildrenGroup||[]).flatMap(r=>Ue(r,p,i)),...(l.orChildrenGroup||[]).flatMap(r=>Ue(r,p,i)),...(l.inputs||[]).flatMap(r=>Ue(r,p,i)),...(l.successCalls||[]).flatMap(r=>Ue(r,p,i)),...(l.errorCalls||[]).flatMap(r=>Ue(r,p,i)),...(Ao(l)||[]).flatMap(r=>Ue(r,p,i)),...l.parent?Ue(l.parent,p,i):[]]}function zUe(l,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(l.id))return[];if(p.add(l.id),l.type!==d.ContinueStatement)throw new Error("Entity must be a continue statement to be flattened");return[l,...l.outputs.flatMap(r=>Ue(r,p,i)),...l.readsValue?Ue(l.readsValue,p,i):[],...l.throws?Ue(l.throws,p,i):[],...l.dataType?Ue(l.dataType,p,i):[],...(Ao(l)||[]).flatMap(r=>Ue(r,p,i)),...l.parent?Ue(l.parent,p,i):[]]}function YUe(l,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(l.id))return[];if(p.add(l.id),l.type!==d.DefinitionEntity)throw new Error("Entity must be a definition entity to be flattened");return[l,...l.extends?Ue(l.extends,p,i):[],...(l.implements||[]).flatMap(r=>Ue(r,p,i)),...(l.properties||[]).flatMap(r=>Ue(r,p,i)),...(l.methods||[]).flatMap(r=>Ue(r,p,i)),...(l.abstractMethods||[]).flatMap(r=>Ue(r,p,i)),...l.allPropertiesImplement?Ue(l.allPropertiesImplement,p,i):[],...l.additionalPropertiesDataType?Ue(l.additionalPropertiesDataType,p,i):[],...l.parent?Ue(l.parent,p,i):[]]}function JUe(l,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(l.id))return[];if(p.add(l.id),l.type!==d.DataType)throw new Error("Entity must be a data type to be flattened");return[l,...(l.andChildrenGroup||[]).flatMap(r=>Ue(r,p,i)),...(l.orChildrenGroup||[]).flatMap(r=>Ue(r,p,i)),...l.entity?Ue(l.entity,p,i):[],...l.foreignKeyRef?Ue(l.foreignKeyRef,p,i):[],...l.parent?Ue(l.parent,p,i):[]]}function XUe(l,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(l.id))return[];if(p.add(l.id),l.type!==d.FunctionCall)throw new Error("Entity must be a function call to be flattened");return[l,...(l.inputs||[]).flatMap(r=>Ue(r,p,i)),...(l.outputs||[]).flatMap(r=>Ue(r,p,i)),...l.error?Ue(l.error,p,i):[],...(Ao(l)||[]).flatMap(r=>Ue(r,p,i)),...(l.successCalls||[]).flatMap(r=>Ue(r,p,i)),...(l.errorCalls||[]).flatMap(r=>Ue(r,p,i)),...(l.writesValues||[]).flatMap(r=>Ue(r,p,i)),...l.parent?Ue(l.parent,p,i):[]]}function QUe(l,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(l.id))return[];if(p.add(l.id),l.type!==d.FunctionDeclaration)throw new Error("Entity must be a function declaration to be flattened");return[l,...(l.inputs||[]).flatMap(r=>Ue(r,p,i)),...(l.calls||[]).flatMap(r=>Ue(r,p,i)),...l.dataType?Ue(l.dataType,p,i):[],...l.implements?Ue(l.implements,p,i):[],...l.parent?Ue(l.parent,p,i):[]]}function eke(l,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(l.id))return[];if(p.add(l.id),l.type!==d.GlobalEvent)throw new Error("Entity must be a global event to be flattened");return[l,...(l.inputs||[]).flatMap(r=>Ue(r,p,i)),...(l.calls||[]).flatMap(r=>Ue(r,p,i)),...l.implements?Ue(l.implements,p,i):[],...l.parent?Ue(l.parent,p,i):[]]}function tke(l,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(l.id))return[];if(p.add(l.id),l.type!==d.InputMap)throw new Error("Entity must be an input map to be flattened");return[l,...l.readsValue?Ue(l.readsValue,p,i):[],...l.declaration?Ue(l.declaration,p,i):[],...l.defaultValue?Ue(l.defaultValue,p,i):[],...l.parent?Ue(l.parent,p,i):[]]}function ike(l,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(l.id))return[];if(p.add(l.id),l.type!==d.InstalledProject)throw new Error("Entity must be an installed project to be flattened");return[l,...(l.functions||[]).flatMap(r=>Ue(r,p,i)),...(l.events||[]).flatMap(r=>Ue(r,p,i)),...l.parent?Ue(l.parent,p,i):[]]}function rke(l,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(l.id))return[];if(p.add(l.id),l.type!==d.InternalCall)throw new Error("Entity must be an internal call to be flattened");return[l,...(l.successCalls||[]).flatMap(r=>Ue(r,p,i)),...(l.errorCalls||[]).flatMap(r=>Ue(r,p,i)),...(l.inputs||[]).flatMap(r=>Ue(r,p,i)),...(l.outputs||[]).flatMap(r=>Ue(r,p,i)),...(Ao(l)||[]).flatMap(r=>Ue(r,p,i)),...l.error?Ue(l.error,p,i):[],...(l.writesValues||[]).flatMap(r=>Ue(r,p,i)),...l.parent?Ue(l.parent,p,i):[]]}function nke(l,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(l.id))return[];if(p.add(l.id),l.type!==d.LiteralValue)throw new Error("Entity must be a literal value to be flattened");return[l,...l.valueAsTypeSingle?Ue(l.valueAsTypeSingle,p,i):[],...l.valueAsTypeList&&Array.isArray(l.valueAsTypeList)?l.valueAsTypeList.flatMap(r=>Ue(r,p,i)):[],...l.parent?Ue(l.parent,p,i):[]]}function ake(l,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(l.id))return[];if(p.add(l.id),l.type!==d.Loop)throw new Error("Entity must be a loop to be flattened");return[l,...(l.inputs||[]).flatMap(r=>Ue(r,p,i)),...(l.outputs||[]).flatMap(r=>Ue(r,p,i)),...(l.successCalls||[]).flatMap(r=>Ue(r,p,i)),...(l.errorCalls||[]).flatMap(r=>Ue(r,p,i)),...l.error?Ue(l.error,p,i):[],...l.dataType?Ue(l.dataType,p,i):[],...l.body?Ue(l.body,p,i):[],...(Ao(l)||[]).flatMap(r=>Ue(r,p,i)),...(l.writesValues||[]).flatMap(r=>Ue(r,p,i)),...l.parent?Ue(l.parent,p,i):[]]}function ske(l,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(l.id))return[];if(p.add(l.id),l.type!==d.Operation)throw new Error("Entity must be an operation to be flattened");return[l,...(l.successCalls||[]).flatMap(r=>Ue(r,p,i)),...(l.errorCalls||[]).flatMap(r=>Ue(r,p,i)),...(l.inputs||[]).flatMap(r=>Ue(r,p,i)),...(l.outputs||[]).flatMap(r=>Ue(r,p,i)),...(l.writesValues||[]).flatMap(r=>Ue(r,p,i)),...l.error?Ue(l.error,p,i):[],...(Ao(l)||[]).flatMap(r=>Ue(r,p,i)),...l.parent?Ue(l.parent,p,i):[]]}function lke(l,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(l.id))return[];if(p.add(l.id),l.type!==d.OutputMap)throw new Error("Entity must be an output map to be flattened");return[l,...(l.writesValues||[]).flatMap(r=>Ue(r,p,i)),...l.declaration?Ue(l.declaration,p,i):[],...l.parent?Ue(l.parent,p,i):[]]}function oke(l,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(l.id))return[];if(p.add(l.id),l.type!==d.PrimitiveEntity)throw new Error("Entity must be a primitive entity to be flattened");return[l,...(l.properties||[]).flatMap(r=>Ue(r,p,i)),...(l.methods||[]).flatMap(r=>Ue(r,p,i)),...(l.abstractMethods||[]).flatMap(r=>Ue(r,p,i))]}function dke(l,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(l.id))return[];if(p.add(l.id),l.type!==d.Project)throw new Error("Entity must be a project to be flattened");return[l,...(l.entities||[]).flatMap(r=>Ue(r,p,i)),...(l.functions||[]).flatMap(r=>Ue(r,p,i)),...(l.events||[]).flatMap(r=>Ue(r,p,i)),...(l.projects||[]).flatMap(r=>Ue(r,p,i)),...(l.variableDeclarations||[]).flatMap(r=>Ue(r,p,i)),...(l.variableInstances||[]).flatMap(r=>Ue(r,p,i)),...(l.operations||[]).flatMap(r=>Ue(r,p,i)),...(l.conditions||[]).flatMap(r=>Ue(r,p,i)),...(l.functionCalls||[]).flatMap(r=>Ue(r,p,i)),...(l.projects||[]).flatMap(r=>Ue(r,p,i)),...(l.loops||[]).flatMap(r=>Ue(r,p,i)),...(l.searches||[]).flatMap(r=>Ue(r,p,i))]}function uke(l,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(l.id))return[];if(p.add(l.id),l.type!==d.Property)throw new Error("Entity must be a property to be flattened");return[l,...l.defaultValue?Ue(l.defaultValue,p,i):[],...l.dataType?Ue(l.dataType,p,i):[],...l.parent?Ue(l.parent,p,i):[]]}function pke(l,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(l.id))return[];if(p.add(l.id),l.type!==d.ReturnStatement)throw new Error("Entity must be a return statement to be flattened");return[l,...(l.outputs||[]).flatMap(r=>Ue(r,p,i)),...l.throws?Ue(l.throws,p,i):[],...l.readsValue?Ue(l.readsValue,p,i):[],...l.dataType?Ue(l.dataType,p,i):[],...(Ao(l)||[]).flatMap(r=>Ue(r,p,i)),...l.parent?Ue(l.parent,p,i):[]]}function cke(l,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(l.id))return[];if(p.add(l.id),l.type!==d.Search)throw new Error("Entity must be a search to be flattened");return[l,...(l.successCalls||[]).flatMap(r=>Ue(r,p,i)),...(l.errorCalls||[]).flatMap(r=>Ue(r,p,i)),...(l.inputsDeclarations||[]).flatMap(r=>Ue(r,p,i)),...(l.inputs||[]).flatMap(r=>Ue(r,p,i)),...(l.writesValues||[]).flatMap(r=>Ue(r,p,i)),...(l.outputs||[]).flatMap(r=>Ue(r,p,i)),...l.error?Ue(l.error,p,i):[],...l.dataType?Ue(l.dataType,p,i):[],...(Ao(l)||[]).flatMap(r=>Ue(r,p,i)),...l.parent?Ue(l.parent,p,i):[]]}function fke(l,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(l.id))return[];if(p.add(l.id),l.type!==d.ValueDescriptor)throw new Error("Entity must be a value descriptor to be flattened");return[l,...l.defaultValue?Ue(l.defaultValue,p,i):[],...l.dataType?Ue(l.dataType,p,i):[],...l.parent?Ue(l.parent,p,i):[]]}function yke(l,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(l.id))return[];if(p.add(l.id),l.type!==d.VariableDeclaration)throw new Error("Entity must be a variable declaration to be flattened");return[l,...(l.successCalls||[]).flatMap(r=>Ue(r,p,i)),...(l.errorCalls||[]).flatMap(r=>Ue(r,p,i)),...(l.inputs||[]).flatMap(r=>Ue(r,p,i)),...(l.outputs||[]).flatMap(r=>Ue(r,p,i)),...(l.internalCalls||[]).flatMap(r=>Ue(r,p,i)),...(l.writesValues||[]).flatMap(r=>Ue(r,p,i)),...l.readsValue?Ue(l.readsValue,p,i):[],...l.defaultValue?Ue(l.defaultValue,p,i):[],...(Ao(l)||[]).flatMap(r=>Ue(r,p,i)),...l.dataType?Ue(l.dataType,p,i):[],...l.parent?Ue(l.parent,p,i):[]]}function hke(l,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(l.id))return[];if(p.add(l.id),l.type!==d.VariableInstance)throw new Error("Entity must be a variable instance to be flattened");return[l,...(l.successCalls||[]).flatMap(r=>Ue(r,p,i)),...(l.errorCalls||[]).flatMap(r=>Ue(r,p,i)),...(l.inputs||[]).flatMap(r=>Ue(r,p,i)),...(l.outputs||[]).flatMap(r=>Ue(r,p,i)),...(l.internalCalls||[]).flatMap(r=>Ue(r,p,i)),...(l.writesValues||[]).flatMap(r=>Ue(r,p,i)),...l.readsValue?Ue(l.readsValue,p,i):[],...l.defaultValue?Ue(l.defaultValue,p,i):[],...(Ao(l)||[]).flatMap(r=>Ue(r,p,i)),...l.declaration?Ue(l.declaration,p,i):[],...l.parent?Ue(l.parent,p,i):[]]}function Ue(l,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(!l)throw new Error("Entity must be defined to be flattened");if(l.type===d.GenericReference)return[];const r=i.ignoreBuiltInBaseEntities?i.diggestedBuiltInBaseEntitiesIds??new Set(j1()):new Set;if(i.diggestedBuiltInBaseEntitiesIds=r,i.ignoreBuiltInBaseEntities&&(ra.includes(l.type)||r.has(l.id)))return[];if(p.has(l.id))return[];switch(l.type){case d.FunctionCall:return XUe(l,p,i);case d.Operation:return ske(l,p,i);case d.Condition:return WUe(l,p,i);case d.Loop:return ake(l,p,i);case d.Search:return cke(l,p,i);case d.GlobalEvent:return eke(l,p,i);case d.ReturnStatement:return pke(l,p,i);case d.ContinueStatement:return zUe(l,p,i);case d.BreakStatement:return ZUe(l,p,i);case d.VariableDeclaration:return yke(l,p,i);case d.DefinitionEntity:return YUe(l,p,i);case d.FunctionDeclaration:return QUe(l,p,i);case d.Project:return dke(l,p,i);case d.ActionDescriptor:return SUe(l,p,i);case d.ArgumentDeclaration:return qUe(l,p,i);case d.ValueDescriptor:return fke(l,p,i);case d.InputMap:return tke(l,p,i);case d.OutputMap:return lke(l,p,i);case d.DataType:return JUe(l,p,i);case d.InstalledProject:return ike(l,p,i);case d.InternalCall:return rke(l,p,i);case d.LiteralValue:return nke(l,p,i);case d.Property:return uke(l,p,i);case d.VariableInstance:return hke(l,p,i);case d.BuiltInBaseEntity:return i.ignoreBuiltInBaseEntities?[]:HUe(l,p,i);case d.PrimitiveEntity:return i.ignoreBuiltInBaseEntities?[]:oke(l,p,i)}return[]}async function U1(l={}){const p=new Set,i=z.YieldTracker.from(l),r=new Set;for(const a of JN){const c=await je(a,p,{ignoreBuiltInBaseEntities:!1,tracker:i});for(const e of c)r.add(e.id),await i.tick()}return r}function go(l){return[...l.calledByEntry||[],...l.calledByError||[],...l.calledBySuccess||[]].filter(p=>p.type!==d.GenericReference)}async function mke(l,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(l.id))return[];if(p.add(l.id),l.type!==d.ActionDescriptor)throw new Error("Entity must be an action descriptor to be flattened");const r=z.YieldTracker.from(i),a=[l];await r.tick();const c={...i,tracker:r};delete c.yieldEvery;for(const e of l.inputs)a.push(...await je(e,p,c));return l.dataType&&a.push(...await je(l.dataType,p,c)),l.error&&a.push(...await je(l.error,p,c)),l.parent&&a.push(...await je(l.parent,p,c)),a}async function Tke(l,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(l.id))return[];if(p.add(l.id),l.type!==d.ArgumentDeclaration)throw new Error("Entity must be an argument declaration to be flattened");const r=z.YieldTracker.from(i),a=[l];await r.tick();const c={...i,tracker:r};delete c.yieldEvery,l.dataType&&a.push(...await je(l.dataType,p,c)),l.parent&&a.push(...await je(l.parent,p,c)),l.defaultValue&&a.push(...await je(l.defaultValue,p,c));for(const e of l.writesValues||[])a.push(...await je(e,p,c));for(const e of l.implements||[])a.push(...await je(e,p,c));return a}async function vke(l,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(l.id))return[];if(p.add(l.id),l.type!==d.BreakStatement)throw new Error("Entity must be a break statement to be flattened");const r=z.YieldTracker.from(i),a=[l];await r.tick();const c={...i,tracker:r};delete c.yieldEvery;for(const f of l.outputs)a.push(...await je(f,p,c));l.parent&&a.push(...await je(l.parent,p,c)),l.throws&&a.push(...await je(l.throws,p,c)),l.dataType&&a.push(...await je(l.dataType,p,c)),l.readsValue&&a.push(...await je(l.readsValue,p,c));const e=go(l);for(const f of e)a.push(...await je(f,p,c));return a}async function Eke(l,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(l.id))return[];if(p.add(l.id),l.type!==d.BuiltInBaseEntity)throw new Error("Entity must be a built-in base entity to be flattened");const r=z.YieldTracker.from(i),a=[l];await r.tick();const c={...i,tracker:r};delete c.yieldEvery;for(const e of l.properties||[])a.push(...await je(e,p,c));for(const e of l.methods||[])a.push(...await je(e,p,c));for(const e of l.abstractMethods||[])a.push(...await je(e,p,c));return l.allPropertiesImplement&&a.push(...await je(l.allPropertiesImplement,p,c)),l.additionalPropertiesDataType&&a.push(...await je(l.additionalPropertiesDataType,p,c)),l.extends&&a.push(...await je(l.extends,p,c)),a}async function bke(l,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(l.id))return[];if(p.add(l.id),l.type!==d.Condition)throw new Error("Entity must be a condition to be flattened");const r=z.YieldTracker.from(i),a=[l];await r.tick();const c={...i,tracker:r};if(delete c.yieldEvery,l.andChildrenGroup&&Array.isArray(l.andChildrenGroup))for(const f of l.andChildrenGroup)a.push(...await je(f,p,c));if(l.orChildrenGroup&&Array.isArray(l.orChildrenGroup))for(const f of l.orChildrenGroup)a.push(...await je(f,p,c));for(const f of l.inputs)a.push(...await je(f,p,c));for(const f of l.successCalls)a.push(...await je(f,p,c));for(const f of l.errorCalls)a.push(...await je(f,p,c));const e=go(l);for(const f of e)a.push(...await je(f,p,c));return l.parent&&a.push(...await je(l.parent,p,c)),a}async function Ake(l,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(l.id))return[];if(p.add(l.id),l.type!==d.ContinueStatement)throw new Error("Entity must be a continue statement to be flattened");const r=z.YieldTracker.from(i),a=[l];await r.tick();const c={...i,tracker:r};delete c.yieldEvery;for(const f of l.outputs)a.push(...await je(f,p,c));const e=go(l);for(const f of e)a.push(...await je(f,p,c));return l.parent&&a.push(...await je(l.parent,p,c)),l.throws&&a.push(...await je(l.throws,p,c)),l.dataType&&a.push(...await je(l.dataType,p,c)),l.readsValue&&a.push(...await je(l.readsValue,p,c)),a}async function gke(l,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(l.id))return[];if(p.add(l.id),l.type!==d.DefinitionEntity)throw new Error("Entity must be a definition entity to be flattened");const r=z.YieldTracker.from(i),a=[l];await r.tick();const c={...i,tracker:r};delete c.yieldEvery;for(const e of l.properties)a.push(...await je(e,p,c));for(const e of l.methods)a.push(...await je(e,p,c));for(const e of l.abstractMethods)a.push(...await je(e,p,c));for(const e of l.implements)a.push(...await je(e,p,c));return l.extends&&a.push(...await je(l.extends,p,c)),l.parent&&a.push(...await je(l.parent,p,c)),l.additionalPropertiesDataType&&a.push(...await je(l.additionalPropertiesDataType,p,c)),l.allPropertiesImplement&&a.push(...await je(l.allPropertiesImplement,p,c)),a}async function Ike(l,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(l.id))return[];if(p.add(l.id),l.type!==d.DataType)throw new Error("Entity must be a data type to be flattened");const r=z.YieldTracker.from(i),a=[l];await r.tick();const c={...i,tracker:r};if(delete c.yieldEvery,l.parent&&a.push(...await je(l.parent,p,c)),l.foreignKeyRef&&a.push(...await je(l.foreignKeyRef,p,c)),l.entity&&a.push(...await je(l.entity,p,c)),l.orChildrenGroup)for(const e of l.orChildrenGroup)a.push(...await je(e,p,c));if(l.andChildrenGroup)for(const e of l.andChildrenGroup)a.push(...await je(e,p,c));return a}async function Rke(l,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(l.id))return[];if(p.add(l.id),l.type!==d.FunctionCall)throw new Error("Entity must be a function call to be flattened");const r=z.YieldTracker.from(i),a=[l];await r.tick();const c={...i,tracker:r};delete c.yieldEvery;for(const f of l.inputs)a.push(...await je(f,p,c));for(const f of l.outputs)a.push(...await je(f,p,c));l.error&&a.push(...await je(l.error,p,c));const e=go(l);for(const f of e)a.push(...await je(f,p,c));for(const f of l.successCalls)a.push(...await je(f,p,c));for(const f of l.errorCalls)a.push(...await je(f,p,c));for(const f of l.writesValues)a.push(...await je(f,p,c));return l.parent&&a.push(...await je(l.parent,p,c)),a}async function Dke(l,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(l.id))return[];if(p.add(l.id),l.type!==d.FunctionDeclaration)throw new Error("Entity must be a function declaration to be flattened");const r=z.YieldTracker.from(i),a=[l];await r.tick();const c={...i,tracker:r};delete c.yieldEvery,l.parent&&a.push(...await je(l.parent,p,c)),l.implements&&a.push(...await je(l.implements,p,c)),l.dataType&&a.push(...await je(l.dataType,p,c));for(const e of l.inputs)a.push(...await je(e,p,c));for(const e of l.calls)a.push(...await je(e,p,c));return a}async function wke(l,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(l.id))return[];if(p.add(l.id),l.type!==d.GlobalEvent)throw new Error("Entity must be a global event to be flattened");const r=z.YieldTracker.from(i),a=[l];await r.tick();const c={...i,tracker:r};delete c.yieldEvery,l.parent&&a.push(...await je(l.parent,p,c)),l.implements&&a.push(...await je(l.implements,p,c));for(const e of l.inputs)a.push(...await je(e,p,c));for(const e of l.calls)a.push(...await je(e,p,c));return a}async function Cke(l,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(l.id))return[];if(p.add(l.id),l.type!==d.InputMap)throw new Error("Entity must be an input map to be flattened");const r=z.YieldTracker.from(i),a=[l];await r.tick();const c={...i,tracker:r};return delete c.yieldEvery,l.parent&&a.push(...await je(l.parent,p,c)),l.declaration&&a.push(...await je(l.declaration,p,c)),l.readsValue&&a.push(...await je(l.readsValue,p,c)),l.dataType&&a.push(...await je(l.dataType,p,c)),l.defaultValue&&a.push(...await je(l.defaultValue,p,c)),a}async function Oke(l,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(l.id))return[];if(p.add(l.id),l.type!==d.InstalledProject)throw new Error("Entity must be an installed project to be flattened");const r=z.YieldTracker.from(i),a=[l];await r.tick();const c={...i,tracker:r};delete c.yieldEvery;for(const e of l.functions)a.push(...await je(e,p,c));for(const e of l.events)a.push(...await je(e,p,c));return l.parent&&a.push(...await je(l.parent,p,c)),a}async function _ke(l,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(l.id))return[];if(p.add(l.id),l.type!==d.InternalCall)throw new Error("Entity must be an internal call to be flattened");const r=z.YieldTracker.from(i),a=[l];await r.tick();const c={...i,tracker:r};delete c.yieldEvery;for(const f of l.inputs)a.push(...await je(f,p,c));for(const f of l.outputs)a.push(...await je(f,p,c));l.error&&a.push(...await je(l.error,p,c));const e=go(l);for(const f of e)a.push(...await je(f,p,c));for(const f of l.successCalls)a.push(...await je(f,p,c));for(const f of l.errorCalls)a.push(...await je(f,p,c));for(const f of l.writesValues)a.push(...await je(f,p,c));return l.parent&&a.push(...await je(l.parent,p,c)),a}async function Vke(l,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(l.id))return[];if(p.add(l.id),l.type!==d.LiteralValue)throw new Error("Entity must be a literal value to be flattened");const r=z.YieldTracker.from(i),a=[l];await r.tick();const c={...i,tracker:r};if(delete c.yieldEvery,l.valueAsTypeSingle&&a.push(...await je(l.valueAsTypeSingle,p,c)),l.valueAsTypeList&&Array.isArray(l.valueAsTypeList))for(const e of l.valueAsTypeList)a.push(...await je(e,p,c));return l.parent&&a.push(...await je(l.parent,p,c)),a}async function Pke(l,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(l.id))return[];if(p.add(l.id),l.type!==d.Loop)throw new Error("Entity must be a loop to be flattened");const r=z.YieldTracker.from(i),a=[l];await r.tick();const c={...i,tracker:r};delete c.yieldEvery;for(const f of l.inputs)a.push(...await je(f,p,c));for(const f of l.outputs)a.push(...await je(f,p,c));l.error&&a.push(...await je(l.error,p,c));const e=go(l);for(const f of e)a.push(...await je(f,p,c));for(const f of l.successCalls)a.push(...await je(f,p,c));for(const f of l.errorCalls)a.push(...await je(f,p,c));for(const f of l.writesValues)a.push(...await je(f,p,c));return l.parent&&a.push(...await je(l.parent,p,c)),l.body&&a.push(...await je(l.body,p,c)),l.dataType&&a.push(...await je(l.dataType,p,c)),a}async function Nke(l,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(l.id))return[];if(p.add(l.id),l.type!==d.Operation)throw new Error("Entity must be an operation to be flattened");const r=z.YieldTracker.from(i),a=[l];await r.tick();const c={...i,tracker:r};delete c.yieldEvery;for(const f of l.inputs)a.push(...await je(f,p,c));for(const f of l.outputs)a.push(...await je(f,p,c));l.error&&a.push(...await je(l.error,p,c));const e=go(l);for(const f of e)a.push(...await je(f,p,c));for(const f of l.successCalls)a.push(...await je(f,p,c));for(const f of l.errorCalls)a.push(...await je(f,p,c));for(const f of l.writesValues)a.push(...await je(f,p,c));return l.parent&&a.push(...await je(l.parent,p,c)),a}async function xke(l,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(l.id))return[];if(p.add(l.id),l.type!==d.OutputMap)throw new Error("Entity must be an output map to be flattened");const r=z.YieldTracker.from(i),a=[l];await r.tick();const c={...i,tracker:r};delete c.yieldEvery;for(const e of l.writesValues)a.push(...await je(e,p,c));return l.declaration&&a.push(...await je(l.declaration,p,c)),l.dataType&&a.push(...await je(l.dataType,p,c)),l.parent&&a.push(...await je(l.parent,p,c)),a}async function $ke(l,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(l.id))return[];if(p.add(l.id),l.type!==d.PrimitiveEntity)throw new Error("Entity must be a primitive entity to be flattened");const r=z.YieldTracker.from(i),a=[l];await r.tick();const c={...i,tracker:r};delete c.yieldEvery;for(const e of l.properties)a.push(...await je(e,p,c));for(const e of l.methods)a.push(...await je(e,p,c));for(const e of l.abstractMethods)a.push(...await je(e,p,c));return a}async function Lke(l,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(l.id))return[];if(p.add(l.id),l.type!==d.Project)throw new Error("Entity must be a project to be flattened");const r=z.YieldTracker.from(i),a=[l];await r.tick();const c={...i,tracker:r};delete c.yieldEvery;for(const e of l.entities)a.push(...await je(e,p,c));for(const e of l.functions)a.push(...await je(e,p,c));for(const e of l.events)a.push(...await je(e,p,c));for(const e of l.projects)a.push(...await je(e,p,c));for(const e of l.variableDeclarations)a.push(...await je(e,p,c));for(const e of l.variableInstances)a.push(...await je(e,p,c));for(const e of l.operations)a.push(...await je(e,p,c));for(const e of l.conditions)a.push(...await je(e,p,c));for(const e of l.functionCalls)a.push(...await je(e,p,c));for(const e of l.projects)a.push(...await je(e,p,c));for(const e of l.loops)a.push(...await je(e,p,c));for(const e of l.searches)a.push(...await je(e,p,c));return a}async function Bke(l,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(l.id))return[];if(p.add(l.id),l.type!==d.Property)throw new Error("Entity must be a property to be flattened");const r=z.YieldTracker.from(i),a=[l];await r.tick();const c={...i,tracker:r};return delete c.yieldEvery,l.defaultValue&&a.push(...await je(l.defaultValue,p,c)),l.dataType&&a.push(...await je(l.dataType,p,c)),l.parent&&a.push(...await je(l.parent,p,c)),a}async function Mke(l,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(l.id))return[];if(p.add(l.id),l.type!==d.ReturnStatement)throw new Error("Entity must be a return statement to be flattened");const r=z.YieldTracker.from(i),a=[l];await r.tick();const c={...i,tracker:r};delete c.yieldEvery;for(const f of l.outputs)a.push(...await je(f,p,c));for(const f of l.outputs)a.push(...await je(f,p,c));l.throws&&a.push(...await je(l.throws,p,c)),l.readsValue&&a.push(...await je(l.readsValue,p,c)),l.dataType&&a.push(...await je(l.dataType,p,c));const e=go(l);for(const f of e)a.push(...await je(f,p,c));return l.parent&&a.push(...await je(l.parent,p,c)),a}async function Gke(l,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(l.id))return[];if(p.add(l.id),l.type!==d.Search)throw new Error("Entity must be a search to be flattened");const r=z.YieldTracker.from(i),a=[l];await r.tick();const c={...i,tracker:r};delete c.yieldEvery;for(const f of l.inputs)a.push(...await je(f,p,c));for(const f of l.outputs)a.push(...await je(f,p,c));l.error&&a.push(...await je(l.error,p,c)),l.dataType&&a.push(...await je(l.dataType,p,c));for(const f of l.inputsDeclarations)a.push(...await je(f,p,c));const e=go(l);for(const f of e)a.push(...await je(f,p,c));for(const f of l.successCalls)a.push(...await je(f,p,c));for(const f of l.errorCalls)a.push(...await je(f,p,c));for(const f of l.writesValues)a.push(...await je(f,p,c));return l.parent&&a.push(...await je(l.parent,p,c)),a}async function jke(l,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(l.id))return[];if(p.add(l.id),l.type!==d.ValueDescriptor)throw new Error("Entity must be a value descriptor to be flattened");const r=z.YieldTracker.from(i),a=[l];await r.tick();const c={...i,tracker:r};return delete c.yieldEvery,l.defaultValue&&a.push(...await je(l.defaultValue,p,c)),l.dataType&&a.push(...await je(l.dataType,p,c)),l.parent&&a.push(...await je(l.parent,p,c)),a}async function Uke(l,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(l.id))return[];if(p.add(l.id),l.type!==d.VariableDeclaration)throw new Error("Entity must be a variable declaration to be flattened");const r=z.YieldTracker.from(i),a=[l];await r.tick();const c={...i,tracker:r};delete c.yieldEvery;for(const f of l.inputs)a.push(...await je(f,p,c));for(const f of l.outputs)a.push(...await je(f,p,c));l.error&&a.push(...await je(l.error,p,c)),l.dataType&&a.push(...await je(l.dataType,p,c)),l.readsValue&&a.push(...await je(l.readsValue,p,c)),l.defaultValue&&a.push(...await je(l.defaultValue,p,c));const e=go(l);for(const f of e)a.push(...await je(f,p,c));for(const f of l.successCalls)a.push(...await je(f,p,c));for(const f of l.errorCalls)a.push(...await je(f,p,c));for(const f of l.writesValues)a.push(...await je(f,p,c));for(const f of l.internalCalls)a.push(...await je(f,p,c));return l.parent&&a.push(...await je(l.parent,p,c)),a}async function kke(l,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(l.id))return[];if(p.add(l.id),l.type!==d.VariableInstance)throw new Error("Entity must be a variable instance to be flattened");const r=z.YieldTracker.from(i),a=[l];await r.tick();const c={...i,tracker:r};delete c.yieldEvery;for(const f of l.inputs)a.push(...await je(f,p,c));for(const f of l.outputs)a.push(...await je(f,p,c));l.error&&a.push(...await je(l.error,p,c)),l.readsValue&&a.push(...await je(l.readsValue,p,c)),l.defaultValue&&a.push(...await je(l.defaultValue,p,c));const e=go(l);for(const f of e)a.push(...await je(f,p,c));for(const f of l.successCalls)a.push(...await je(f,p,c));for(const f of l.errorCalls)a.push(...await je(f,p,c));for(const f of l.writesValues)a.push(...await je(f,p,c));for(const f of l.internalCalls)a.push(...await je(f,p,c));return l.parent&&a.push(...await je(l.parent,p,c)),l.declaration&&a.push(...await je(l.declaration,p,c)),a}async function je(l,p=new Set,i={ignoreBuiltInBaseEntities:!1,yieldEvery:100}){const r={...i,ignoreBuiltInBaseEntities:i.ignoreBuiltInBaseEntities??!1};if(!l)throw new Error("Entity must be defined to be flattened");if(l.type===d.GenericReference)return[];const a=z.YieldTracker.from(r);r.tracker=a,r.yieldEvery!==void 0&&delete r.yieldEvery;const c=r.ignoreBuiltInBaseEntities?r.diggestedBuiltInBaseEntitiesIds??new Set(await U1(r)):new Set;if(r.diggestedBuiltInBaseEntitiesIds=c,r.ignoreBuiltInBaseEntities&&(ra.includes(l.type)||c.has(l.id)))return[];if(p.has(l.id))return[];switch(l.type){case d.FunctionCall:return Rke(l,p,r);case d.Operation:return Nke(l,p,r);case d.Condition:return bke(l,p,r);case d.Loop:return Pke(l,p,r);case d.Search:return Gke(l,p,r);case d.GlobalEvent:return wke(l,p,r);case d.ReturnStatement:return Mke(l,p,r);case d.ContinueStatement:return Ake(l,p,r);case d.BreakStatement:return vke(l,p,r);case d.VariableDeclaration:return Uke(l,p,r);case d.DefinitionEntity:return gke(l,p,r);case d.FunctionDeclaration:return Dke(l,p,r);case d.Project:return Lke(l,p,r);case d.ActionDescriptor:return mke(l,p,r);case d.ArgumentDeclaration:return Tke(l,p,r);case d.ValueDescriptor:return jke(l,p,r);case d.InputMap:return Cke(l,p,r);case d.OutputMap:return xke(l,p,r);case d.DataType:return Ike(l,p,r);case d.InstalledProject:return Oke(l,p,r);case d.InternalCall:return _ke(l,p,r);case d.LiteralValue:return Vke(l,p,r);case d.Property:return Bke(l,p,r);case d.VariableInstance:return kke(l,p,r);case d.BuiltInBaseEntity:return r.ignoreBuiltInBaseEntities?[]:Eke(l,p,r);case d.PrimitiveEntity:return r.ignoreBuiltInBaseEntities?[]:$ke(l,p,r)}return[]}function Fke(l){return l==null||l===""}function nVi(l){return l===null}function Pn(l){return l!=null&&l.valueAsType?!1:Fke(l==null?void 0:l.value)}function rd(l){return l?l.valueAsType===null&&l.value===null:!1}function Kke(l,p){if(l===p||!l&&!p)return!0;if(!l||!p||l.name===ye.EntityTemplate&&p.name!==ye.EntityTemplate||p.name===ye.EntityTemplate&&l.name!==ye.EntityTemplate)return!1;if(l.name===ye.ActionDescriptor&&p.name!==ye.ActionDescriptor||p.name===ye.ActionDescriptor&&l.name!==ye.ActionDescriptor)return!1;if(l.valueAsTypeSingle&&!p.valueAsTypeSingle||p.valueAsTypeSingle&&!l.valueAsTypeSingle)return!1;if(l.valueAsTypeList&&!p.valueAsTypeList||p.valueAsTypeList&&!l.valueAsTypeList)return!1;if(l.valueAsTypeSingle&&p.valueAsTypeSingle){if(l.valueAsTypeSingle.id!==p.valueAsTypeSingle.id)return!1}else if(l.valueAsTypeList&&p.valueAsTypeList){if(l.valueAsTypeList.length!==p.valueAsTypeList.length)return!1;for(let i=0;i<l.valueAsTypeList.length;i++)if(l.valueAsTypeList[i].id!==p.valueAsTypeList[i].id)return!1}else if(!l.valueAsType&&!p.valueAsType&&l.value!==p.value)return!1;return!0}function Ske(l,p,i){if(!i)throw new Error("[checkIsRowTransformerUpToDate] 'lastPublishedEntityVersion' argument is required");if(!p)throw new Error("[checkIsRowTransformerUpToDate] 'entity' argument is required");if(!l)throw new Error("[checkIsRowTransformerUpToDate] 'newestOpenRowTransformer' argument is required");let r=!0;const a=l.methods.find(c=>{var e;return((e=c.implements)==null?void 0:e.id)===re["built-in-base-entity"].BUILT_IN_SQL_ROW_TRANSFORMER_ENTITY.methods.up.id});if(a?(Vn(i).forEach(c=>{const e=a.inputs.find(f=>f.name===c.name);e&&si(e.getDataType(null),c.getDataType(null)).compatible||(r=!1)}),a.returnStatements.forEach(c=>{!c.dataType||!c.dataType.entity||c.dataType.entity.type!==d.DefinitionEntity?r=!1:LT(c.dataType.entity,p)||(r=!1)})):r=!1,r===null||r){const c=l.methods.find(e=>{var f;return((f=e.implements)==null?void 0:f.id)===re["built-in-base-entity"].BUILT_IN_SQL_ROW_TRANSFORMER_ENTITY.methods.down.id});c?(Vn(p).forEach(e=>{const f=c.inputs.find(h=>h.name===e.name);f&&si(f.getDataType(null),e.getDataType(null)).compatible||(r=!1)}),c.returnStatements.forEach(e=>{!e.dataType||!e.dataType.entity||e.dataType.entity.type!==d.DefinitionEntity?r=!1:LT(e.dataType.entity,i)||(r=!1)})):r=!1}return{isPreexistingRowTransformerUpToDate:r}}function qke(l,p,i){const r={changesSinceLastPublication:!1,rowTransformerNeeded:!1,newRowTransformerNeeded:!1,newestOpenRowTransformer:null,newRequiredProperties:[],newNonRequiredProperties:[],deletedProperties:[],lastPublishedEntityVersion:null,updatedEntityVersion:i,propChanges:new Map,isPreexistingRowTransformerUpToDate:null,extendedEntities:[]},c=l.entities.filter(k=>{var ie;if(k.id===i.id)return!1;let G=!1,H=k;for(;H;){if(((ie=H.extends)==null?void 0:ie.id)===i.id){G=!0;break}if(H.extends&&H.extends.type===d.DefinitionEntity)H=H.extends;else break}return G}).map(k=>qke(l,p,k));if(!p)return{...r,changesSinceLastPublication:!0,extendedEntities:c};const e=p.get(i.id);if(!e)return{...r,changesSinceLastPublication:!0,extendedEntities:c};const f=p.entities.filter(k=>Wi(k,Ie.SQL_ROW_TRANSFORMER)),m=l.entities.filter(k=>{var ee;if(!Wi(k,Ie.SQL_ROW_TRANSFORMER)||f.find(ue=>ue.id===k.id))return!1;const H=k.properties.find(ue=>!!ue.implements.find(ae=>re["built-in-base-entity"].BUILT_IN_SQL_ROW_TRANSFORMER_ENTITY.properties.definition.id===ae.id));if(!H)return!1;const ie=(ee=H.defaultValue)==null?void 0:ee.valueAsType;return ie?ie.id===i.id:!1}).sort((k,G)=>B(k.createdAt).isAfter(B(G.createdAt))?-1:1)[0]||null,E=new Map;let b=!1;const g=Vn(i).filter(k=>Vn(e).find(ie=>ie.id===k.id)?!1:!_a(k.getDataType(null))),_=Vn(i).filter(k=>Vn(e).find(ie=>ie.id===k.id)?!1:!!_a(k.getDataType(null))),$=Vn(e).filter(k=>!Vn(i).find(H=>H.id===k.id));Vn(i).filter(k=>{var ne,le,Q,oe,Ee,Te,Ve,Le,$e,ke,Ke;const G=Vn(e).find(Je=>Je.id===k.id);let H=!1;if(!G)return!1;const ie=el(k.dataType,!0,`[resolveSQLMigrationsDiffs] Unsupported data-type structure on current property '${k.name}' (${k.id}). 'andChildrenGroup' with more than one child is not supported for SQL column properties.`),ee=el(G.dataType,!0,`[resolveSQLMigrationsDiffs] Unsupported data-type structure on last published property '${k.name}' (${k.id}). 'andChildrenGroup' with more than one child is not supported for SQL column properties.`),ue=lg(ie,!0,`[resolveSQLMigrationsDiffs] Unsupported data-type structure on current property '${k.name}' (${k.id}). 'orChildrenGroup' with multiple non-null children is not supported for SQL column properties.`),ae=lg(ee,!0,`[resolveSQLMigrationsDiffs] Unsupported data-type structure on last published property '${k.name}' (${k.id}). 'orChildrenGroup' with multiple non-null children is not supported for SQL column properties.`);if(((ne=ue==null?void 0:ue.foreignKeyRef)==null?void 0:ne.id)!==((le=ae==null?void 0:ae.foreignKeyRef)==null?void 0:le.id)){const Je=ue==null?void 0:ue.foreignKeyRef,rt=ae==null?void 0:ae.foreignKeyRef;E.set(k.id,{...E.get(k.id)||{},newForeignKeyRef:Je||void 0,oldForeignKeyRef:rt||void 0,property:k,oldProperty:G}),H=!0,b=!0}else((Q=ue==null?void 0:ue.entity)==null?void 0:Q.id)!==((oe=ae==null?void 0:ae.entity)==null?void 0:oe.id)&&(((Ee=ue==null?void 0:ue.entity)==null?void 0:Ee.id)===re["primitive-entity"].string.id||((Te=ae==null?void 0:ae.entity)==null?void 0:Te.id)===re["primitive-entity"].date.id&&((Ve=ue==null?void 0:ue.entity)==null?void 0:Ve.id)===re["primitive-entity"].number.id?E.set(k.id,{...E.get(k.id)||{},castableDataTypeEntity:{fromId:((Le=ae==null?void 0:ae.entity)==null?void 0:Le.id)||"",toId:(($e=ue==null?void 0:ue.entity)==null?void 0:$e.id)||""},property:k,oldProperty:G}):(E.set(k.id,{...E.get(k.id)||{property:k},nonCastableDataTypeEntity:{fromId:((ke=ae==null?void 0:ae.entity)==null?void 0:ke.id)||"",toId:((Ke=ue==null?void 0:ue.entity)==null?void 0:Ke.id)||""},property:k,oldProperty:G}),b=!0),H=!0);k.name!==(G==null?void 0:G.name)&&(E.set(k.id,{...E.get(k.id)||{},nameChange:{from:(G==null?void 0:G.name)||"",to:k.name},property:k,oldProperty:G}),H=!0);const de=_a(G.getDataType(null)),ce=_a(k.getDataType(null));return ce!==de&&(E.set(k.id,{...E.get(k.id)||{},requiredChange:{from:!de,to:!ce},property:k,oldProperty:G}),ce||(b=!0),H=!0),H}),g.length>0&&(b=!0);let L=null;m&&b&&(L=Ske(m,i,e).isPreexistingRowTransformerUpToDate);const j=i.name!==e.name?{from:e.name,to:i.name}:void 0;return{...r,changesSinceLastPublication:E.size>0||!!$.length||!!g.length||!!_.length||b,rowTransformerNeeded:b,newestOpenRowTransformer:m,nameChange:j,newRequiredProperties:g,newNonRequiredProperties:_,deletedProperties:$,lastPublishedEntityVersion:e,propChanges:E,newRowTransformerNeeded:b&&!m,isPreexistingRowTransformerUpToDate:L,extendedEntities:c}}function X$(l,p,i,r,a){if(!l)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(!r)throw new Error("[addDifferencesToRowTransformer] 'oldEntityState' argument is required");const c=Vn(i),e=Vn(r);p.afterAllChildrenInitialized(a);const f=p.methods.find(m=>{var E;return((E=m.implements)==null?void 0:E.id)===re["built-in-base-entity"].BUILT_IN_SQL_ROW_TRANSFORMER_ENTITY.methods.up.id}),h=p.methods.find(m=>{var E;return((E=m.implements)==null?void 0:E.id)===re["built-in-base-entity"].BUILT_IN_SQL_ROW_TRANSFORMER_ENTITY.methods.down.id});if(!f)throw new Error("[addDifferencesToRowTransformer] The 'up' transformer trigger is missing from the parent");if(!h)throw new Error("[addDifferencesToRowTransformer] The 'down' transformer trigger is missing from the parent");e.forEach(m=>{const E=f.inputs.find($=>$.name===m.name),b=m.getDataType(null);let g=E,_;if(E)g.editable=!0;else{const $=Na.new(a);$.parent=f.toReference(),$.name=m.name,$.index=m.index,$.implements=[...m.implements.map(j=>j.toJSON())];const L=Ae($,l);L.hydrateAncestors(),a.add(L,W.Added),L.addSelfToProject(a),L.initChildren(a),g=L}if(!g.dataType||g.dataType&&l.diggestedBuiltInBaseEntitiesIds.has(g.dataType.id)){const $=mr.new(a);$.parent=g.toReference();const L=Ae($,l);L.hydrateAncestors(),a.add(L,W.Added),L.addSelfToProject(a),L.initChildren(a),_=L}else _=g.dataType,_.editable=!0;b&&_.merge(m.getDataType(null),a),_.metaSync({editable:!1,deletable:!1},a),g.metaSync({editable:!1,deletable:!1},a)}),[...f.inputs].forEach(m=>{e.find(b=>b.name===m.name)||(m.editable=!0,m.remove({ignoreUpstream:!1},a),m.editable=!1)}),[...f.returnStatements].forEach(m=>{var E,b;if(!m.dataType||m.dataType&&l.diggestedBuiltInBaseEntitiesIds.has(m.dataType.id)){const g=mr.new(a);g.entity=i.toReference(),g.parent=m.toReference();const _=Ae(g,l);_.hydrateAncestors(),a.add(_,W.Added),_.addSelfToProject(a),_.initChildren(a)}(!((E=m.dataType)!=null&&E.entity)||m.dataType.entity.type!==d.DefinitionEntity||m.dataType.entity.parent.id!==m.dataType.id)&&i.clone(a,m.dataType),ex((b=m.dataType)==null?void 0:b.entity,i,a),m.afterAllChildrenInitialized(a),m.outputs.forEach(g=>{const _=f.inputs.find($=>se(g,l)===se($,l));g.setValueWriter(_,a),_==null||_.addValueReader(g,a)})}),c.forEach(m=>{var L;const E=(L=m.knownVersions)==null?void 0:L.get(m.previousVersion),b=h.inputs.find(j=>j.name===m.name||!!E&&E.name===j.name),g=m.getDataType(null);let _=b,$;if(b)_.editable=!0,_.metaSync({name:m.name,codeName:m.codeName,description:m.description},a);else{const j=Na.new(a);j.parent=h.toReference(),j.name=m.name,j.codeName=m.codeName,j.description=m.description,j.index=m.index,j.implements=[m.toJSON(),...m.implements.map(G=>G.toJSON())];const k=Ae(j,l);k.hydrateAncestors(),a.add(k,W.Added),k.addSelfToProject(a),k.initChildren(a),_=k}if(_.dataType)$=_.dataType,$.editable=!0,$.merge(_.dataType,a);else{const j=mr.new(a);j.parent=_.toReference();const k=Ae(j,l);k.hydrateAncestors(),a.add(k,W.Added),k.addSelfToProject(a),k.initChildren(a),$=k}g&&$.merge(m.getDataType(null),a),$.metaSync({editable:!1,deletable:!1},a),_.metaSync({editable:!1,deletable:!1},a)}),[...h.inputs].forEach(m=>{c.find(b=>{var _;if(b.name===m.name)return!0;const g=(_=b.knownVersions)==null?void 0:_.get(b.previousVersion);if(g&&g.name===m.name)return!0})||(m.editable=!0,m.remove({ignoreUpstream:!1},a),m.editable=!1)}),[...h.returnStatements].forEach(m=>{var b,g,_,$;if(!m.dataType||m.dataType&&l.diggestedBuiltInBaseEntitiesIds.has(m.dataType.id)){const L=mr.new(a);L.parent=m.toReference();const j=Ae(L,l);j.hydrateAncestors(),a.add(j,W.Added),j.addSelfToProject(a),j.initChildren(a)}let E=(b=m.dataType)==null?void 0:b.entity;(!E||(E==null?void 0:E.id)===re["built-in-base-entity"].BUILT_IN_PERSISTED_ENTITY_ENTITY.id)&&(z.Logger.log("Cloning old entity state into new project with data-ype as parent: ",(g=m.dataType)==null?void 0:g.id," from new project: ",((_=m.dataType)==null?void 0:_.project.version)===l.version&&(($=m.dataType)==null?void 0:$.project.entities.length)===3),E=r.clone(a,m.dataType)),m.dataType.setEntity(E,a),m.afterAllChildrenInitialized(a),m.outputs.forEach(L=>{const j=h.inputs.find(k=>se(L,l)===se(k,l));L.setValueWriter(j,a),j==null||j.addValueReader(L,a)})})}function Zke(l,p,i,r,a={}){var k;const c=l.getBuiltIn(Ie.SQL_ROW_TRANSFORMER),e=HR(se(p,l)+" row transformer",l.entities),f=c.implement(e,r),h=f.ownDeclaredProperties.find(G=>{var H;return(H=G.implements)==null?void 0:H.find(ie=>ie.id===re["built-in-base-entity"].BUILT_IN_SQL_ROW_TRANSFORMER_ENTITY.properties.definition.id)}),m=f.methods.find(G=>{var H;return((H=G.implements)==null?void 0:H.id)===re["built-in-base-entity"].BUILT_IN_SQL_ROW_TRANSFORMER_ENTITY.methods.up.id}),E=f.methods.find(G=>{var H;return((H=G.implements)==null?void 0:H.id)===re["built-in-base-entity"].BUILT_IN_SQL_ROW_TRANSFORMER_ENTITY.methods.down.id});if(!h||!m||!E)throw new Error("Cannot find definition property on the new row transformer entity");if(h.defaultValue)h.defaultValue.setValueAsTypeSingle(p,r);else{const G=Nr.new(r);G.name=ye.EntityTemplate,G.valueAsTypeSingle=p.toJSON(),G.parent=h.toReference();const H=Ae(G,l);H.hydrateAncestors(),r.add(H,W.Added),H.addSelfToProject(r),H.initChildren(r)}X$(l,f,p,i,r),z.Logger.log("BEFORE - changeSet.listAdded",r.listAdded.map(G=>{var ie,ee,ue,ae,de,ce,ne;const H=l.get(G.id);return H?se(H,l):G.type===d.InputMap?"(not found) "+G.type+" "+G.id+" - declaration: "+((ie=G.declaration)==null?void 0:ie.type)+" "+((ee=G.declaration)==null?void 0:ee.id)+' "'+((ue=G.declaration)==null?void 0:ue.name)+`"
479
+ `)),z.Logger.log("Persisting new additions"),h.visit(async(m,E)=>{if(r.added[m.id]){z.Logger.log("Adding: ",m.id);try{const b=Ae(m,this);if(b.hydrateAncestors(),b.addSelfToProject(a),a.add(b,W.Added),!this.get(m.id))throw new Error(`Entity ${m.id} was not added to the project`)}catch(b){z.Logger.error("Error: ",b),z.Logger.error("Errored entity: ",m)}}}),z.Logger.log("Persisting updates"),h.visit(async(m,E)=>{if(r.updated[m.id]){z.Logger.log("Updating: ",m.id);try{const b=this.get(m.id);b?(b.updateWithShallowTransfer(m,a),a.add(b,W.Updated)):z.Logger.warn(`Active version of ${m.id} not found when applying external changes`)}catch(b){z.Logger.error("Error: ",b),z.Logger.error("Errored entity: ",m)}}}),z.Logger.log("Persisting removals"),h.visit(async(m,E)=>{if(r.removed[m.id]){z.Logger.log("Removing: ",m.id);try{const b=this.get(m.id);b&&b.remove({ignoreUpstream:!1},a)}catch(b){z.Logger.error("Error: ",b),z.Logger.error("Errored entity: ",m)}}}),a.open=!1,a}toBuiltInShallowRecord(){const i={};return Object.values(this.builtInInstances).forEach(r=>{const a=r.toShallowJSON();i[r.id]=a}),i}toShallowRecord(){const i={};return Object.values(this.instances).forEach(r=>{const a=r.toShallowJSON();i[r.id]=a}),i}toFullProjectTransfer(i){const r={shallowErrors:!1,...i},a=new cn(void 0,{allBuiltInEntityIds:this.diggestedBuiltInBaseEntitiesIds});a.flatRecord={};for(const f of Object.values(this.instances))this.diggestedBuiltInBaseEntitiesIds.has(f.id)||(a.flatRecord[f.id]=f);a.order=Object.keys(a.flatRecord),a.orderEntities();const c={},e=[];return a.visit(f=>{try{const h=f.toShallowJSON();c[f.id]=h,e.push(f.id)}catch(h){if(z.Logger.error(`[toFullProjectTransfer] Error serializing ${f.type} ${f.id}`,h),!r.shallowErrors)throw h}}),{order:e,size:e.length,record:c}}async toFullProjectTransferAsync(i={}){const r={shallowErrors:!1,...i},a=z.YieldTracker.from(r),c=new cn(void 0,{allBuiltInEntityIds:this.diggestedBuiltInBaseEntitiesIds});c.flatRecord={};for(const h of Object.values(this.instances))await a.tick(),!this.diggestedBuiltInBaseEntitiesIds.has(h.id)&&(c.flatRecord[h.id]=h);c.order=Object.keys(c.flatRecord);const e=[];if(r.seenEntityMaps)for(const h of c.order){const m=r.seenEntityMaps.get(h)??h;this.diggestedBuiltInBaseEntitiesIds.has(m)}await c.orderEntitiesAsync({tracker:a});const f={};return await c.visitAsync(async h=>{try{if(this.diggestedBuiltInBaseEntitiesIds.has(h.id))return;const m=h.toShallowJSON({seenEntityMaps:r.seenEntityMaps});r.resetVersionOptions&&(m.version=Lt.UUID.uuid(),m.createdAt=r.resetVersionOptions.commonTimestamp||B().toISOString(),m.author=r.resetVersionOptions.author||Lt.sessionAuthor||"1",m.previousVersion=null),f[m.id]=m,e.push(m.id),r!=null&&r.onVisit&&await r.onVisit(m)}catch(m){if(z.Logger.error(`[toFullProjectTransferAsync] Error serializing ${h.type} ${h.id}`,m),!r.shallowErrors)throw m}},{tracker:a}),{order:e,size:e.length,record:f}}async toFullProjectGenerationTargetAsync(i={}){const r={shallowErrors:!1,...i},a=z.YieldTracker.from(r),c=new cn(void 0,{allBuiltInEntityIds:this.diggestedBuiltInBaseEntitiesIds});c.flatRecord={};for(const h of Object.values(this.instances))await a.tick(),!this.diggestedBuiltInBaseEntitiesIds.has(h.id)&&(c.flatRecord[h.id]=h);c.order=Object.keys(c.flatRecord);const e=[];if(r.seenEntityMaps)for(const h of c.order){const m=r.seenEntityMaps.get(h)??h;this.diggestedBuiltInBaseEntitiesIds.has(m)}await c.orderEntitiesAsync({tracker:a});const f={};return await c.visitAsync(async h=>{try{if(this.diggestedBuiltInBaseEntitiesIds.has(h.id))return;const m=h.toGenerationTarget({seenEntityMaps:r.seenEntityMaps});f[m.id]=m,e.push(m.id),r!=null&&r.onVisit&&await r.onVisit(m)}catch(m){if(z.Logger.error(`[toFullProjectTransferAsync] Error serializing ${h.type} ${h.id}`,m),!r.shallowErrors)throw m}},{tracker:a}),{order:e,size:e.length,record:f}}};R(Lt,"parentContext",J$),R(Lt,"sessionAuthor","1"),R(Lt,"repository",{APICreate:async(i,...r)=>i,APIUpdate:async(i,...r)=>i,APIDelete:async(i,...r)=>i,APIClone:async(i,...r)=>{},APILoad:async(i,...r)=>null,APILoadVersion:async(i,r,...a)=>null}),R(Lt,"type",d.Project),R(Lt,"USER_MANAGED_PARENT_TYPES",[]),R(Lt,"PARENT_TYPES",[...Lt.USER_MANAGED_PARENT_TYPES]),R(Lt,"MUTABLE_BASE_PROPERTIES",["name","description"]),R(Lt,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),R(Lt,"BASE_PROPERTIES",[...Lt.MUTABLE_BASE_PROPERTIES,...Lt.INMUTABLE_BASE_PROPERTIES]),R(Lt,"MUTABLE_META_PROPERTIES",[...Lt.MUTABLE_BASE_PROPERTIES,"x","y"]),R(Lt,"INMUTABLE_META_PROPERTIES",[...Lt.INMUTABLE_BASE_PROPERTIES]),R(Lt,"META_PROPERTIES",[...Lt.MUTABLE_META_PROPERTIES,...Lt.INMUTABLE_META_PROPERTIES]),R(Lt,"MUTABLE_UPSTREAM_PROPERTIES",[]),R(Lt,"INMUTABLE_UPSTREAM_PROPERTIES",["primitives","builtInBaseEntities","operationDeclarations","globalEventActionDescriptors","loopDeclarations","builtInInstances"]),R(Lt,"UPSTREAM_PROPERTIES",[...Lt.MUTABLE_UPSTREAM_PROPERTIES,...Lt.INMUTABLE_UPSTREAM_PROPERTIES]),R(Lt,"MUTABLE_DOWNSTREAM_PROPERTIES",["entities","projects","functions","events","variableDeclarations","variableInstances","conditions","operations","functionCalls","loops","searches"]),R(Lt,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),R(Lt,"DOWNSTREAM_PROPERTIES",[...Lt.MUTABLE_DOWNSTREAM_PROPERTIES,...Lt.INMUTABLE_DOWNSTREAM_PROPERTIES]),R(Lt,"PROPERTIES",[...Lt.META_PROPERTIES,...Lt.UPSTREAM_PROPERTIES,...Lt.DOWNSTREAM_PROPERTIES]);let N=Lt;class x_i extends ki{constructor(p){super(kv,p)}}class $_i extends ki{constructor(i){super(Kh,i);R(this,"autoexecutable",!0)}getEntityToMatchInputMap(i){return i.inputs.find(r=>{var a;return((a=r.declaration)==null?void 0:a.id)===re.operation[xe.Validate].inputs.entityToMatch.id})||null}getDataToValidateInputMap(i){return i.inputs.find(r=>{var a;return((a=r.declaration)==null?void 0:a.id)===re.operation[xe.Validate].inputs.dataToValidate.id})||null}getOutputDataOutputMap(i){return i.outputs.find(r=>{var a;return((a=r.declaration)==null?void 0:a.id)===re.operation[xe.Validate].dataType.entity.properties.outputEntity.id})||null}getEntityToMatch(i,r=this.project.addChangeSet(new q(this.project,N.sessionAuthor,B().toISOString(),this,!0,"get-entity-to-match-validate-data"))){var e;const a=((e=this.project.requestActiveDynamicValue(i))==null?void 0:e.value)||null,c=a==null?void 0:a.valueAsTypeSingle;return r==null||r.attemptAutoclose("get-entity-to-match-validate-data",this.id),c}syncOperationInstance(i,r=this.project.addChangeSet(new q(this.project,N.sessionAuthor,B().toISOString(),this,!0,"sync-operation-instance-validate-data"))){const a=[],c=[],e=[],f=[],h=this.getEntityToMatchInputMap(i);if(h){const{added:b,updated:g,removed:_,affected:$}=this.syncEntityToMatchInputMapDataType(h,r);a.push(...g),c.push(...b),e.push(..._),f.push(...$)}const m=this.getDataToValidateInputMap(i);if(m){const{added:b,updated:g,removed:_,affected:$}=this.syncDataToValidateInputMapDataType(m,r);a.push(...g),c.push(...b),e.push(..._),f.push(...$)}const E=this.getOutputDataOutputMap(i);if(E){const{added:b,updated:g,removed:_,affected:$}=this.syncOutputDataOutputMapDataType(E,r);a.push(...g),c.push(...b),e.push(..._),f.push(...$)}return r==null||r.attemptAutoclose("sync-operation-instance-validate-data",this.id),{updated:C(a),added:C(c),removed:C(e),affected:C(f),self:i}}syncEntityToMatchInputMapDataType(i,r=this.project.addChangeSet(new q(this.project,N.sessionAuthor,B().toISOString(),this,!0,"sync-entity-to-match-input-map-data-type"))){var E,b,g,_,$,L,j,k,G,H,ie,ee,ue,ae,de,ce,ne,le;const a=[],c=[],e=[],f=[];if(((E=i.declaration)==null?void 0:E.id)!==re.operation[xe.Validate].inputs.entityToMatch.id)return r==null||r.attemptAutoclose("sync-entity-to-match-input-map-data-type",this.id),{updated:[],added:[],removed:[],affected:[],self:null};const h=((b=this.project.requestActiveDynamicValue(i))==null?void 0:b.value)||null,m=h==null?void 0:h.valueAsTypeSingle;if(!i.dataType){const Q={id:N.UUID.uuid(),version:N.UUID.uuid(),createdAt:(r==null?void 0:r.timestamp)||new Date().toISOString(),author:(r==null?void 0:r.author)||N.sessionAuthor,previousVersion:null,deleted:!1,deletable:!0,editable:!0,type:d.DataType,parentRelationType:null,options:((g=i.declaration.dataType)==null?void 0:g.options)||null,implementationChooseOne:((_=i.declaration.dataType)==null?void 0:_.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:((k=i.declaration.dataType)==null?void 0:k.index)??null,isList:((G=i.declaration.dataType)==null?void 0:G.isList)||!1,foreignKeyAllowed:((H=i.declaration.dataType)==null?void 0:H.foreignKeyAllowed)??null,andChildrenGroup:null,orChildrenGroup:null,foreignKeyRef:null,asType:!0,entity:(m==null?void 0:m.toJSON())||null,like:!0,inferred:!0,parent:i.toReference()},oe=Ae(Q,i.project);oe.hydrateAncestors(),oe.setParent(i,r),oe.initChildren(r),oe.setEntity(m,r),r==null||r.add(oe,W.Added),a.push(oe),i.setDataType(oe,r)}return(ne=i.dataType)==null||ne.metaSync({inferred:!0,like:!1,asType:!0,options:((ie=i.declaration.dataType)==null?void 0:ie.options)||null,implementationChooseOne:((ee=i.declaration.dataType)==null?void 0:ee.implementationChooseOne)||!1,staticEntities:((ue=i.declaration.dataType)==null?void 0:ue.staticEntities)??null,interactiveEntities:((ae=i.declaration.dataType)==null?void 0:ae.interactiveEntities)??null,actionEntities:((de=i.declaration.dataType)==null?void 0:de.actionEntities)??null,isList:((ce=i.declaration.dataType)==null?void 0:ce.isList)||!1},r),(le=i.dataType)==null||le.setEntity(m,r),i.dataType&&c.push(i.dataType),r==null||r.attemptAutoclose("sync-entity-to-match-input-map-data-type",this.id),{updated:C(c),added:C(a),removed:C(e),affected:C(f),self:i.dataType}}syncDataToValidateInputMapDataType(i,r=this.project.addChangeSet(new q(this.project,N.sessionAuthor,B().toISOString(),this,!0,"sync-data-to-validate-input-map-data-type"))){var b,g,_;const a=[],c=[],e=[],f=[];if(((b=i.declaration)==null?void 0:b.id)!==re.operation[xe.Validate].inputs.dataToValidate.id)return r==null||r.attemptAutoclose("sync-data-to-validate-input-map-data-type",this.id),{updated:[],added:[],removed:[],affected:[],self:null};const h=this.getEntityToMatchInputMap(i.parent);if(!h)return r==null||r.attemptAutoclose("sync-data-to-validate-input-map-data-type",this.id),{updated:[],added:[],removed:[],affected:[],self:null};if(!this.getEntityToMatch(h,r))return r==null||r.attemptAutoclose("sync-data-to-validate-input-map-data-type",this.id),{updated:[],added:[],removed:[],affected:[],self:null};if(!i.dataType){const $={id:N.UUID.uuid(),version:N.UUID.uuid(),createdAt:(r==null?void 0:r.timestamp)||new Date().toISOString(),author:(r==null?void 0:r.author)||N.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=Ae($,i.project);L.setParent(i,r),L.initChildren(r),r==null||r.add(L,W.Added),a.push(L),i.setDataType(L,r)}(g=i.dataType)==null||g.metaSync({inferred:!0,like:!0,asType:!1},r);const E=this.getEntityToMatch(h,r);return(_=i.dataType)==null||_.setEntity(E,r),i.dataType&&c.push(i.dataType),r==null||r.attemptAutoclose("sync-data-to-validate-input-map-data-type",this.id),{updated:C(c),added:C(a),removed:C(e),affected:C(f),self:i.dataType}}syncOutputDataOutputMapDataType(i,r=this.project.addChangeSet(new q(this.project,N.sessionAuthor,B().toISOString(),this,!0,"sync-output-data-output-map-data-type"))){var g,_,$,L;const a=[],c=[],e=[],f=[];if(((g=i.declaration)==null?void 0:g.id)!==re.operation[xe.Validate].dataType.entity.properties.outputEntity.id)return r==null||r.attemptAutoclose("sync-output-data-output-map-data-type",this.id),{updated:[],added:[],removed:[],affected:[],self:null};const h=this.getEntityToMatchInputMap(i.parent);if(!h)return r==null||r.attemptAutoclose("sync-output-data-output-map-data-type",this.id),{updated:[],added:[],removed:[],affected:[],self:null};if(!this.getEntityToMatch(h,r))return r==null||r.attemptAutoclose("sync-output-data-output-map-data-type",this.id),{updated:[],added:[],removed:[],affected:[],self:null};const E=((_=this.project.requestActiveDynamicValue(h))==null?void 0:_.value)||null,b=(E==null?void 0:E.valueAsTypeSingle)||null;if(!i.dataType){const j={id:N.UUID.uuid(),version:N.UUID.uuid(),createdAt:(r==null?void 0:r.timestamp)||new Date().toISOString(),author:(r==null?void 0:r.author)||N.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()},k=Ae(j,i.project);k.hydrateAncestors(),k.setParent(i,r),k.initChildren(r),k.setEntity(b,r),r==null||r.add(k,W.Added),a.push(k),i.setDataType(k,r)}return($=i.dataType)==null||$.metaSync({inferred:!0,like:!0,asType:!1},r),(L=i.dataType)==null||L.setEntity(b,r),i.dataType&&c.push(i.dataType),r==null||r.attemptAutoclose("sync-output-data-output-map-data-type",this.id),{updated:C(c),added:C(a),removed:C(e),affected:C(f),self:i.dataType}}inferInputMapDataType(i,r=this.project.addChangeSet(new q(this.project,N.sessionAuthor,B().toISOString(),this,!0,"infer-input-map-data-type-validate-data"))){var c,e,f;if(((c=i.declaration)==null?void 0:c.id)===re.operation[xe.Validate].inputs.entityToMatch.id){const{added:h,updated:m,removed:E,affected:b}=r?this.syncEntityToMatchInputMapDataType(i,r):{added:[],updated:[],removed:[],affected:[]};return r==null||r.attemptAutoclose("infer-input-map-data-type",this.id),{updated:C(m),added:C(h),removed:C(E),affected:C(b),self:i.dataType}}if(((e=i.declaration)==null?void 0:e.id)===re.operation[xe.Validate].inputs.dataToValidate.id){const{added:h,updated:m,removed:E,affected:b}=this.syncDataToValidateInputMapDataType(i,r);return r==null||r.attemptAutoclose("infer-input-map-data-type",this.id),{updated:C(m),added:C(h),removed:C(E),affected:C(b),self:i.dataType}}const a=(f=i.declaration)==null?void 0:f.getDataType(r);if(a&&a.isResolved)return r==null||r.attemptAutoclose("infer-input-map-data-type-validate-data",this.id),{updated:[],added:[],removed:[],affected:[],self:a};if(i.readsValue){const h=jd(i.readsValue,r);return r==null||r.attemptAutoclose("infer-input-map-data-type-validate-data",this.id),{updated:[],added:[],removed:[],affected:[],self:h}}return r==null||r.attemptAutoclose("infer-input-map-data-type-validate-data",this.id),{updated:[],added:[],removed:[],affected:[],self:null}}inferOutputMapDataType(i,r=this.project.addChangeSet(new q(this.project,N.sessionAuthor,B().toISOString(),this,!0,"infer-output-map-data-type-validate-data"))){var a;if(((a=i.declaration)==null?void 0:a.id)===re.operation[xe.Validate].dataType.entity.properties.outputEntity.id){const{added:c,updated:e,removed:f,affected:h}=this.syncOutputDataOutputMapDataType(i,r);return r==null||r.attemptAutoclose("infer-output-map-data-type-validate-data",this.id),{updated:C(e),added:C(c),removed:C(f),affected:C(h),self:i.dataType}}return{updated:[],added:[],removed:[],affected:[],self:null}}}class L_i extends ki{constructor(p){super(SV,p)}}class B_i extends ki{constructor(p){super(qV,p)}}class M_i extends ki{constructor(p){super(ZV,p)}}class G_i extends ki{constructor(p){super(VI,p)}}class j_i extends ki{constructor(p){super(zg,p)}}class U_i extends ki{constructor(p){super(iv,p)}}function EUe(l){const p=[new j_e(l),new M_e(l),new G_e(l),new x_i(l),new $_i(l),new G_i(l),new L_i(l),new M_i(l),new B_i(l),new j_i(l),new U_i(l)];return TN.forEach(i=>{p.some(r=>r.id===i.id)||p.push(new ki(i,l))}),p.forEach(i=>{i.initChildren(null),l.subscribeBuiltInInstance(i)}),l.operationDeclarations=p,p}class k_i extends qd{constructor(i){super($n,i);R(this,"initialData");R(this,"id",Ie.PERSISTED_ENTITY);R(this,"version","1");R(this,"name",Ie.PERSISTED_ENTITY);R(this,"description",$n.description);R(this,"type",d.BuiltInBaseEntity);R(this,"abstract",$n.abstract);R(this,"static",$n.static);R(this,"properties",[]);R(this,"methods",[]);R(this,"abstractMethods",[]);R(this,"extends",null);R(this,"errors",[]);R(this,"project");this.initialData=$n,this.project=i,this.id=$n.id,this.version=$n.version,this.name=$n.name,this.static=$n.static,this.abstract=$n.abstract,this.properties=this.initialData.properties.map(a=>{const c=Ae(a,this.project);return c.setParent(this,null),c.initChildren(null),c}),this.methods=this.initialData.methods.map(a=>{const c=Ae(a,this.project);return c.parent=this,c}),this.abstractMethods=this.initialData.abstractMethods.map(a=>{const c=Ae(a,this.project);return c.parent=this,c}),this.initialData.extends&&(this.extends=Ae(this.initialData.extends,this.project));const r=this.properties.find(a=>a.id===re["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.identifier.id);if(!r)throw new Error("Path property not found in endpoint entity");r._codeNativeValueValidation=(a,c)=>$_e(a,c)}}const F_i=[];function bUe(l){const p=[new x_e(l),new B_e(l),new k_i(l)];return KN.forEach(i=>{!p.some(r=>r.id===i.id)&&!F_i.includes(i.id)&&p.push(new qd(i,l))}),p.forEach(i=>{l.subscribeBuiltInInstance(i)}),l.builtInBaseEntities=p,p}function AUe(l){const p=[new Ca(ve,l),new Ca(ut,l),new Ca(Pe,l),new Ca(ma,l),new Ca(It,l),new Ca(Pt,l),new Ca(dt,l),new Ca(ql,l),new Ca(er,l)];return p.forEach(i=>{l.subscribeBuiltInInstance(i)}),l.primitives=p,p}function gUe(l){const p=[new ki(ZR,l)];return p.forEach(i=>{i.initChildren(null),l.subscribeBuiltInInstance(i)}),l.globalEventActionDescriptors=p,p}function IUe(l){const p=[new ki(Xv,l),new ki(xf,l),new ki(Yv,l),new ki(cm,l),new ki(fm,l),new ki(wR,l)];p.forEach(r=>{r.initChildren(null),l.subscribeBuiltInInstance(r)}),l.loopDeclarations=p;const i=[new ki(BR,l),new ki(Jv,l),new ki(VR,l),new ki(IN,l),new ki(wN,l),new ki(CR,l)];return i.forEach(r=>{r.initChildren(null),l.subscribeBuiltInInstance(r)}),l.loopDeclarationsBodies=i,p}function RUe(l){const p=[new Hd(YN,l)];return p.forEach(i=>{i.initChildren(null),l.subscribeBuiltInInstance(i)}),l.valueDescriptors=p,p}function DUe(l){const p=[new ki(qN,l),new ki(SN,l),new ki(ZN,l),new ki(HN,l)];return WN.forEach(i=>{p.some(r=>r.id===i.id)||p.push(new ki(i,l))}),p.forEach(i=>{i.initChildren(null),l.subscribeBuiltInInstance(i)}),l.conditionDeclarations=p,p}function AT(l){return l&&typeof l.then=="function"}function K_i(l,p){const i=new cn(l[0],{allBuiltInEntityIds:p.allBuiltInEntityIds}),r=l.map(c=>c.id),a={};return l.forEach(c=>{a[c.id]=c}),i.order=r,i.flatRecord=a,i.orderEntities(),i.order.map(c=>i.flatRecord[c])}function S_i(l,p){const i=new cn(Object.values(l)[0],{allBuiltInEntityIds:p.allBuiltInEntityIds}),r=Object.keys(l);return i.order=r,i.flatRecord=l,i.orderEntities(),i.order}async function q_i(l,p){const i=z.YieldTracker.from(p),r=new cn(l[0],{allBuiltInEntityIds:p.allBuiltInEntityIds}),a=l.map(e=>e.id),c={};for(const e of l)c[e.id]=e,await i.tick();return r.order=a,r.flatRecord=c,await r.orderEntitiesAsync({tracker:i}),r.order.map(e=>r.flatRecord[e])}async function Z_i(l,p){const i=z.YieldTracker.from(p),r=new cn(Object.values(l)[0],{allBuiltInEntityIds:p.allBuiltInEntityIds}),a=Object.keys(l);return r.order=a,r.flatRecord=l,await r.orderEntitiesAsync({tracker:i}),r.order}class cn{constructor(p,i={}){R(this,"order",[]);R(this,"flatRecord",{});R(this,"allBuiltInEntityIds");R(this,"onGoingVisits",{});R(this,"cachedReferences",{});if(i.allBuiltInEntityIds&&(this.allBuiltInEntityIds=i.allBuiltInEntityIds),!p)return;const r={asyncInitialOrder:!1,...i};r.asyncInitialOrder?this.flattenAsync(p).then(()=>{this.orderEntitiesAsync({...r}).then(()=>{var a;(a=r.onOrdered)==null||a.call(r)})}):(this.flatten(p),this.orderEntities())}flatten(p){this.allBuiltInEntityIds||(this.allBuiltInEntityIds=new Set(j1()));const i=C(Ue(p,new Set(this.allBuiltInEntityIds),{ignoreBuiltInBaseEntities:!0,diggestedBuiltInBaseEntitiesIds:this.allBuiltInEntityIds})),r=new Set;for(const a of i)this.flatRecord[a.id]=a,r.add(a.id);this.order=Array.from(r)}async flattenAsync(p,i={}){const r=z.YieldTracker.from(i);this.allBuiltInEntityIds||(this.allBuiltInEntityIds=await U1({tracker:r}));const a=await kd(await je(p,new Set(this.allBuiltInEntityIds),{ignoreBuiltInBaseEntities:!0,diggestedBuiltInBaseEntitiesIds:this.allBuiltInEntityIds,tracker:r}),{tracker:r}),c=new Set;for(const e of a)this.flatRecord[e.id]=e,c.add(e.id),await r.tick();this.order=Array.from(c)}moveEntityAfterDependencies(p){const i=this.cachedReferences[p.id]||Ul(p,this.flatRecord,{ignoreBuiltInBaseEntities:!0,allBuiltInEntityIds:this.allBuiltInEntityIds});this.cachedReferences[p.id]=i;const{upstream:r}=i;for(const a of Object.keys(r)){const c=this.order.indexOf(a),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 r=this.order[i],a=this.flatRecord[r];if(a||z.Logger.warn(`Entity with id ${r} not found in flatRecord. Skipping...`),this.moveEntityAfterDependencies(a)){p=!0;break}}p&&this.orderEntities()}async orderEntitiesAsync(p={}){let i=!1;const r=z.YieldTracker.from(p);for(let a=0;a<this.order.length;a++){const c=this.order[a],e=this.flatRecord[c];if(e||z.Logger.warn(`Entity with id ${c} not found in flatRecord. Skipping...`),this.moveEntityAfterDependencies(e)){i=!0;break}await r.tick()}i&&await this.orderEntitiesAsync({tracker:r})}getUpstreamOngoingDependenciesVisits(p,i){const r=this.cachedReferences[p]||Ul(this.flatRecord[p],this.flatRecord,{ignoreBuiltInBaseEntities:!0,allBuiltInEntityIds:this.allBuiltInEntityIds});this.cachedReferences[p]=r;const{upstream:a}=r,c={};return Object.entries(this.onGoingVisits[i]||{}).forEach(([e,f])=>{Object.keys(a).includes(e)&&(c[e]=f)}),c}getDownstreamOngoingDependenciesVisits(p,i){const r=Object.keys(this.onGoingVisits[i]||{}),a=new Set(r.flatMap(e=>{const f=this.cachedReferences[e]||Ul(this.flatRecord[e],this.flatRecord,{ignoreBuiltInBaseEntities:!0,allBuiltInEntityIds:this.allBuiltInEntityIds});return this.cachedReferences[e]=f,Object.keys(f.downstream)})),c={};return Array.from(a).forEach(e=>{e===p&&(c[e]=this.onGoingVisits[i][e])}),c}async settlePromises(p,i){const r=Object.values(p);r.length&&await Promise.all(r),Object.keys(p).forEach(a=>{delete this.onGoingVisits[i][a]})}visit(p){const i=this.order;for(const r of i)p(this.flatRecord[r],this.flatRecord);return this}reverseVisit(p){const i=this.order.slice().reverse();for(const r of i)p(this.flatRecord[r],this.flatRecord);return this}async visitAsync(p,i={}){const{parallelise:r}={parallelise:!0,...i},a=z.YieldTracker.from(i),c=this.order;if(!r){for(const f of c){const h=p(this.flatRecord[f],this.flatRecord);AT(h)&&await h,await a.tick()}return this}const e=Math.random().toString(36).substring(7);this.onGoingVisits[e]={};for(const f of c){const h=this.getUpstreamOngoingDependenciesVisits(f,e);Object.keys(h).length&&await this.settlePromises(h,e);const m=p(this.flatRecord[f],this.flatRecord);AT(m)&&(this.onGoingVisits[e][f]=m),await a.tick()}return await this.settlePromises(this.onGoingVisits[e],e),this.onGoingVisits[e]={},this}async reverseVisitAsync(p,i={}){const{parallelise:r}={parallelise:!0,...i},a=z.YieldTracker.from(i),c=this.order.slice().reverse();if(!r){for(const f of c){const h=p(this.flatRecord[f],this.flatRecord);AT(h)&&await h,await a.tick()}return this}const e=Math.random().toString(36).substring(7);this.onGoingVisits[e]={};for(const f of c){const h=this.getDownstreamOngoingDependenciesVisits(f,e);Object.keys(h).length&&await this.settlePromises(h,e);const m=p(this.flatRecord[f],this.flatRecord);AT(m)&&(this.onGoingVisits[e][f]=m),await a.tick()}return await this.settlePromises(this.onGoingVisits[e],e),this.onGoingVisits[e]={},this}}const Qc={},BA={},HT={empty:!1,enrich:!0,mock:!1,ignoreCache:!1,onFetch:async()=>null,manuallyInit:!1};function wUe(l,p={enrich:!0,shallowErrors:!1},i){const r={enrich:!0,shallowErrors:!1,...p},{enrich:a,shallowErrors:c}=r,e=l.project,f=l.record,h=x1(l.project,{shallowErrors:c},i);h.instances[e.id]=h;const m=new cn(e,{allBuiltInEntityIds:h.diggestedBuiltInBaseEntitiesIds}),E=new Set;f[e.id]=e,E.add(e.id);const b=B().toISOString();Object.values(f).forEach(_=>{!_||m.allBuiltInEntityIds.has(_.id)||E.add(_.id)}),m.order=Array.from(E),m.flatRecord=f,m.orderEntities();const g=a?h.addChangeSet(new q(h,N.sessionAuthor,b,h,!0,"project-init-from-fetch-result")):null;return m.visit(_=>{if(_.id===h.id)return;const $=Ae(_,h);try{$.hydrateAncestors(),$.addSelfToProject(null);const L=Ul(_);Object.keys(L.downstream).forEach(j=>{const k=h.get(j);k&&k.hydrateAncestors()})}catch(L){if(c)z.Logger.error("Error hydrating ancestors: ",L);else throw L}}),a?(m.visit(_=>{if(_.id===h.id)return;const $=h.get(_.id);if($)try{$.afterAllChildrenInitialized(g)}catch(L){if(c)z.Logger.error("Error in afterAllChildrenInitialized: ",L);else throw L}}),h.afterAllChildrenInitialized(g)):Cu(h,b).forEach($=>{$.remove({ignoreUpstream:!0},null)}),h.instancesList.forEach(_=>{_.previousVersion=null}),h.initialized=!0,h.emit(ri.PROJECT_INITIALIZED,h,g),g==null||g.attemptAutoclose("project-init-from-fetch-result",h.id),h}async function H_i(l,p={enrich:!0,shallowErrors:!1,yieldEvery:100},i){const r={enrich:!0,shallowErrors:!1,yieldEvery:100,...p},{enrich:a,shallowErrors:c,yieldEvery:e}=r,f=l.project,h=l.record,m=await $1(l.project,{shallowErrors:c,yieldEvery:e},i);m.instances[f.id]=m;const E=new cn(void 0,{allBuiltInEntityIds:m.diggestedBuiltInBaseEntitiesIds});await E.flattenAsync(f,{yieldEvery:e}),await E.orderEntitiesAsync({yieldEvery:e});const b=new Set;h[f.id]=f,b.add(f.id);const g=B().toISOString();let _=0;for(const[j,k]of Object.entries(h))!k||E.allBuiltInEntityIds.has(k.id)||(b.add(k.id),++_%e===0&&await z.yieldToEventLoop());E.order=Array.from(b),E.flatRecord=h,await E.orderEntitiesAsync();const $=a?m.addChangeSet(new q(m,N.sessionAuthor,g,m,!0,"project-init-from-fetch-result")):null;if(await E.visitAsync(j=>{if(j.id===m.id)return;const k=Ae(j,m);try{k.hydrateAncestors(),k.addSelfToProject(null);const G=Ul(j);Object.keys(G.downstream).forEach(H=>{const ie=m.get(H);ie&&ie.hydrateAncestors()})}catch(G){if(c)z.Logger.error("Error hydrating ancestors: ",G);else throw console.log("Error hydrating ancestors: ",G),G}},{yieldEvery:e}),a){try{await E.visitAsync(j=>{if(j.id===m.id)return;const k=m.get(j.id);k&&k.afterAllChildrenInitialized($)},{yieldEvery:e})}catch(j){if(c)z.Logger.error("Error in afterAllChildrenInitialized: ",j);else throw console.log("Error in afterAllChildrenInitialized: ",j),j}m.afterAllChildrenInitialized($)}else Cu(m,g).forEach(k=>{k.remove({ignoreUpstream:!0},null)});let L=0;for(const j of m.instancesList)j.previousVersion=null,++L%e===0&&await z.yieldToEventLoop();return m.initialized=!0,m.emit(ri.PROJECT_INITIALIZED,m,$),$==null||$.attemptAutoclose("project-init-from-fetch-result",m.id),m}async function W_i(l,p=HT){const i={...HT,...p};if(i.empty)return{data:{project:{id:l.id,deletable:!0,editable:!0,type:d.Project,version:N.UUID.uuid(),createdAt:B().toISOString(),author:N.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 a={...YL};return a.id=l.id,{data:{project:a,record:{}}}}return z.Logger.log("Fetching project from external API"),new Promise(async a=>{try{if(i.onFetch){const c=await i.onFetch(l.id);if(c){a({data:c});return}}else a({data:null})}catch(c){z.Logger.error("Error fetching project: ",c),a({data:null})}})}function x1(l,p={shallowErrors:!1},i){const r=new N(l,i);AUe(r),bUe(r),EUe(r),gUe(r),IUe(r),RUe(r),DUe(r);const a=p.allBuiltInIds??new Set([...r.getAllBuiltInIds(),...j1()]);return r.diggestedBuiltInBaseEntitiesIds=a,a.forEach(c=>{if(!r.builtInInstances[c]&&r.instances[c])r.builtInInstances[c]=r.instances[c],delete r.instances[c];else if(!r.builtInInstances[c]&&!p.shallowErrors)throw new Error(`Built in entity was not properly initialized: ${c}`)}),r.instances[r.id]=r,r}async function $1(l,p={shallowErrors:!1},i){const r=z.YieldTracker.from(p),a=new N(l,i);AUe(a),bUe(a),await z.yieldToEventLoop(),EUe(a),await z.yieldToEventLoop(),gUe(a),IUe(a),RUe(a),DUe(a),await z.yieldToEventLoop();const c=p.allBuiltInIds??new Set([...a.getAllBuiltInIds(),...await U1()]);a.diggestedBuiltInBaseEntitiesIds=c;for(const e of c){if(!a.builtInInstances[e]&&a.instances[e])a.builtInInstances[e]=a.instances[e],delete a.instances[e];else if(!a.builtInInstances[e]&&!p.shallowErrors)throw new Error(`Built in entity was not properly initialized: ${e}`);a.instances[e]&&delete a.instances[e],await r.tick()}return a.instances[a.id]=a,a}function Cu(l,p){return l.instancesList.filter(r=>B(r.createdAt).isAfter(B(p)||!!r.previousVersion))}function z_i(l,{enrich:p,shallowErrors:i,...r}={enrich:!0,shallowErrors:!1},a){var _,$;const c=new Map,e=new Map;Object.keys(l.instances).forEach(L=>{if(l.diggestedBuiltInBaseEntitiesIds.has(L)){c.set(L,L),e.set(L,L);return}const j=l.get(L);if(!W1(j,{...l.instances,...l.builtInInstances}).every(ie=>!l.diggestedBuiltInBaseEntitiesIds.has(ie))){c.set(L,L),e.set(L,L);return}const H=N.UUID.uuid();c.set(L,H),e.set(H,L)});const f=((_=r.resetVersionOptions)==null?void 0:_.commonTimestamp)??B().toISOString(),h=l.toShallowJSON({seenEntityMaps:c});h.previousVersion=null,h.createdAt=f,h.version=N.UUID.uuid(),h.author=(($=r.resetVersionOptions)==null?void 0:$.author)??(N.sessionAuthor||"1");const m=x1(h,{shallowErrors:i,allBuiltInIds:l.diggestedBuiltInBaseEntitiesIds},a);m.instances[m.id]=m;const E=p?m.addChangeSet(new q(m,N.sessionAuthor,f,m,!0,"project-clone")):null,b=new cn(l,{allBuiltInEntityIds:l.diggestedBuiltInBaseEntitiesIds}),g=iL(b.flatRecord,c);return b.visit(L=>{var H;const j=L.toShallowJSON({seenEntityMaps:c});j.previousVersion=null,j.createdAt=f,j.version=N.UUID.uuid(),j.author=((H=r.resetVersionOptions)==null?void 0:H.author)??(N.sessionAuthor||"1");const k=Ul(j,g);if(Object.keys(k.upstream).length){let ie=!1;if(Object.keys(k.upstream).forEach(ee=>{if(!ie&&(!m.get(ee)||m.getDeleted(ee))){ie=!0;return}}),ie)return}const G=Ae(j,m);G.hydrateAncestors(),G.addSelfToProject(E),E==null||E.add(G,W.Added),r.onVisit&&r.onVisit(j)}),p?(b.visit(L=>{if(L.id===m.id)return;const j=m.get(c.get(L.id));j&&j.afterAllChildrenInitialized(E)}),m.afterAllChildrenInitialized(E)):Cu(m,f).forEach(j=>{j.remove({ignoreUpstream:!0},null)}),m.instancesList.forEach(L=>{L.previousVersion=null}),E==null||E.attemptAutoclose("project-clone",m.id),{project:m,maps:c}}async function Y_i(l,{shallowErrors:p,...i}={shallowErrors:!1,yieldEvery:100}){var m,E;const r=z.YieldTracker.from(i),a=new Map,c=new Map;Object.keys(l.instances).forEach(b=>{if(l.diggestedBuiltInBaseEntitiesIds.has(b)){a.set(b,b),c.set(b,b);return}const g=N.UUID.uuid();a.set(b,g),c.set(g,b)});const e=((m=i.resetVersionOptions)==null?void 0:m.commonTimestamp)??B().toISOString(),f=l.toShallowJSON({seenEntityMaps:a});f.previousVersion=null,f.createdAt=e,f.version=N.UUID.uuid(),f.author=((E=i.resetVersionOptions)==null?void 0:E.author)??(N.sessionAuthor||"1");const h=await l.toFullProjectTransferAsync({tracker:r,seenEntityMaps:a,resetVersionOptions:i.resetVersionOptions,onVisit:i.onVisit});return{project:f,record:h.record,order:h.order,maps:a}}async function J_i(l,{enrich:p,shallowErrors:i,...r}={enrich:!0,shallowErrors:!1,yieldEvery:100},a){var $,L;const c=z.YieldTracker.from(r),e=new Map,f=new Map;for(const j of Object.keys(l.instances)){if(l.diggestedBuiltInBaseEntitiesIds.has(j)){e.set(j,j),f.set(j,j),await c.tick();continue}const k=N.UUID.uuid();e.set(j,k),f.set(k,j),await c.tick()}const h=(($=r.resetVersionOptions)==null?void 0:$.commonTimestamp)??B().toISOString(),m=l.toShallowJSON({seenEntityMaps:e});m.previousVersion=null,m.createdAt=h,m.version=N.UUID.uuid(),m.author=((L=r.resetVersionOptions)==null?void 0:L.author)??(N.sessionAuthor||"1");const E=await $1(m,{shallowErrors:i,tracker:c},a);E.diggestedBuiltInBaseEntitiesIds=l.diggestedBuiltInBaseEntitiesIds,E.instances[E.id]=E;const b=p?E.addChangeSet(new q(E,N.sessionAuthor,h,E,!0,"project-clone")):null,g=new cn(void 0,{allBuiltInEntityIds:l.diggestedBuiltInBaseEntitiesIds}),_=await l.toFullProjectTransferAsync({tracker:c,seenEntityMaps:e,resetVersionOptions:r.resetVersionOptions,onVisit:r.onVisit});g.flatRecord=_.record,g.order=_.order,await g.visitAsync(j=>{var ie;if(l.diggestedBuiltInBaseEntitiesIds.has(j.id))return;const k=j;k.previousVersion=null,k.createdAt=h,k.version=N.UUID.uuid(),k.author=((ie=r.resetVersionOptions)==null?void 0:ie.author)??(N.sessionAuthor||"1");const G=Ul(k,g.flatRecord);if(Object.keys(G.upstream).length){let ee=!1;if(Object.keys(G.upstream).forEach(ue=>{if(!ee&&(!E.get(ue)||E.getDeleted(ue))){ee=!0;return}}),ee)return}const H=Ae(k,E);H.hydrateAncestors(),H.addSelfToProject(b),b==null||b.add(H,W.Added)},{tracker:c}),p?(await g.visitAsync(j=>{if(j.id===E.id||l.diggestedBuiltInBaseEntitiesIds.has(j.id))return;const k=E.get(e.get(j.id));k&&k.afterAllChildrenInitialized(b)},{tracker:c}),E.afterAllChildrenInitialized(b)):Cu(E,h).forEach(k=>{k.remove({ignoreUpstream:!0},null)});for(const j of E.instancesList)j.previousVersion=null,await c.tick();return b==null||b.attemptAutoclose("project-clone",E.id),{project:E,maps:e}}function X_i(l,p,i=p.addChangeSet(new q(p,N.sessionAuthor,B().toISOString(),p,!0,w.AfterAllChildrenInitialized)),{enrich:r,shallowErrors:a,...c}={shallowErrors:!1,enrich:!0}){var g,_;const e=new Map,f=new Map;Object.keys(l.instances).forEach($=>{if(l.diggestedBuiltInBaseEntitiesIds.has($)){e.set($,$),f.set($,$);return}if($===l.id){e.set($,p.id),f.set(p.id,$);return}const L=l.get($);if(!W1(L,{...l.instances,...l.builtInInstances}).every(H=>!l.diggestedBuiltInBaseEntitiesIds.has(H))){e.set($,$),f.set($,$);return}const G=N.UUID.uuid();e.set($,G),f.set(G,$)});const h=((g=c.resetVersionOptions)==null?void 0:g.commonTimestamp)??B().toISOString(),m=l.toShallowJSON({seenEntityMaps:e});m.previousVersion=null,m.createdAt=h,m.version=N.UUID.uuid(),m.author=((_=c.resetVersionOptions)==null?void 0:_.author)??(N.sessionAuthor||"1");const E=new cn(l,{allBuiltInEntityIds:l.diggestedBuiltInBaseEntitiesIds}),b=iL(E.flatRecord,e);return E.visit($=>{var k;if($.id===p.id)return;const L=$.toShallowJSON({seenEntityMaps:e});L.previousVersion=null,L.createdAt=h,L.version=N.UUID.uuid(),L.author=((k=c.resetVersionOptions)==null?void 0:k.author)??(N.sessionAuthor||"1");const j=Ul(L,b);if(Object.keys(j.upstream).length){let G=!1;if(Object.keys(j.upstream).forEach(H=>{if(!G&&(!p.get(H)||p.getDeleted(H))){G=!0;return}}),G)return}try{const G=Ae(L,p);G.hydrateAncestors(),G.addSelfToProject(i),i==null||i.add(G,W.Added),c.onVisit&&c.onVisit(L)}catch(G){if(a)z.Logger.error("Error cloning entity onto existing project: ",G);else throw console.log("Error cloning entity onto existing project: ",G),G}}),r?E.visit($=>{if($.id===p.id)return;const L=p.get(e.get($.id));L&&L.afterAllChildrenInitialized(i)}):Cu(p,h).forEach(L=>{L.remove({ignoreUpstream:!0},null)}),p.afterAllChildrenInitialized(i),p.instancesList.forEach($=>{$.previousVersion=null}),{project:p,maps:e,changeSet:i}}async function Q_i(l,p,i=p.addChangeSet(new q(p,N.sessionAuthor,B().toISOString(),p,!0,w.AfterAllChildrenInitialized)),{enrich:r,shallowErrors:a,...c}={enrich:!0,shallowErrors:!1,yieldEvery:100}){var _,$;const e=z.YieldTracker.from(c),f=new Map,h=new Map;for(const L of Object.keys(l.instances)){if(l.diggestedBuiltInBaseEntitiesIds.has(L)){f.set(L,L),h.set(L,L),await e.tick();continue}if(L===l.id){f.set(L,p.id),h.set(p.id,L),await e.tick();continue}const j=N.UUID.uuid();f.set(L,j),h.set(j,L),await e.tick()}const m=((_=c.resetVersionOptions)==null?void 0:_.commonTimestamp)??B().toISOString(),E=l.toShallowJSON({seenEntityMaps:f});E.previousVersion=null,E.createdAt=m,E.version=N.UUID.uuid(),E.author=(($=c.resetVersionOptions)==null?void 0:$.author)??(N.sessionAuthor||"1"),p.diggestedBuiltInBaseEntitiesIds=l.diggestedBuiltInBaseEntitiesIds;const b=new cn(void 0,{allBuiltInEntityIds:l.diggestedBuiltInBaseEntitiesIds}),g=await l.toFullProjectTransferAsync({tracker:e,seenEntityMaps:f,resetVersionOptions:c.resetVersionOptions,onVisit:c.onVisit,shallowErrors:a});b.flatRecord=g.record,b.order=g.order,await b.visitAsync(L=>{var G;if(l.diggestedBuiltInBaseEntitiesIds.has(L.id)||L.id===p.id)return;const j=L;j.previousVersion=null,j.createdAt=m,j.version=N.UUID.uuid(),j.author=((G=c.resetVersionOptions)==null?void 0:G.author)??(N.sessionAuthor||"1");const k=Ul(j,b.flatRecord);if(Object.keys(k.upstream).length){let H=!1;if(Object.keys(k.upstream).forEach(ie=>{if(!H&&(!p.get(ie)||p.getDeleted(ie))){H=!0;return}}),H)return}try{const H=Ae(j,p);H.hydrateAncestors(),H.addSelfToProject(i),i==null||i.add(H,W.Added)}catch(H){if(a)z.Logger.error("Error cloning entity onto existing project: ",H);else throw console.log("Error cloning entity onto existing project: ",H),H}},{tracker:e}),r?await b.visitAsync(L=>{if(L.id===p.id||l.diggestedBuiltInBaseEntitiesIds.has(L.id))return;const j=p.get(f.get(L.id));j&&j.afterAllChildrenInitialized(i)},{tracker:e}):Cu(p,m).forEach(j=>{j.remove({ignoreUpstream:!0},null)}),p.afterAllChildrenInitialized(i);for(const L of p.instancesList)L.previousVersion=null,await e.tick();return{project:p,maps:f,changeSet:i}}function CUe(l,{enrich:p,shallowErrors:i}={enrich:!0,shallowErrors:!1},r){const a=x1(l,{shallowErrors:i},r),c=B().toISOString(),e=p?a.addChangeSet(new q(a,N.sessionAuthor,c,a,!0,"project-init")):null;e&&(e.type=WR.Automatic);const f=new cn(l,{allBuiltInEntityIds:a.diggestedBuiltInBaseEntitiesIds});return f.visit(h=>{const m=Ae(h,a);m.hydrateAncestors(),m.addSelfToProject(e)}),p?(f.visit(h=>{if(h.id===a.id)return;const m=a.get(h.id);m&&m.afterAllChildrenInitialized(e)}),a.afterAllChildrenInitialized(e)):(Cu(a,c).forEach(E=>{E.remove({ignoreUpstream:!0},null)}),new cn(a,{allBuiltInEntityIds:a.diggestedBuiltInBaseEntitiesIds}).visit(E=>{E.initialized=!0,E.captureVersion()})),a.initialized=!0,a.emit(ri.PROJECT_INITIALIZED,a,e),e==null||e.attemptAutoclose("project-init",a.id),a}async function eVi(l,{enrich:p,shallowErrors:i,yieldEvery:r}={enrich:!0,shallowErrors:!1,yieldEvery:100},a){const c=await $1(l,{shallowErrors:i,yieldEvery:r},a),e=B().toISOString(),f=p?c.addChangeSet(new q(c,N.sessionAuthor,e,c,!0,"project-init")):null;f&&(f.type=WR.Automatic);const h=new cn(void 0,{allBuiltInEntityIds:c.diggestedBuiltInBaseEntitiesIds});if(await h.flattenAsync(l,{yieldEvery:r}),await h.orderEntitiesAsync({yieldEvery:r}),await h.visitAsync(m=>{const E=Ae(m,c);E.hydrateAncestors(),E.addSelfToProject(f)},{yieldEvery:r}),p)await h.visitAsync(m=>{if(m.id===c.id)return;const E=c.get(m.id);E&&E.afterAllChildrenInitialized(f)},{yieldEvery:r}),c.afterAllChildrenInitialized(f);else{Cu(c,e).forEach(b=>{b.remove({ignoreUpstream:!0},null)});const E=new cn(void 0,{allBuiltInEntityIds:c.diggestedBuiltInBaseEntitiesIds});await E.flattenAsync(c,{yieldEvery:r}),await E.orderEntitiesAsync({yieldEvery:r}),await E.visitAsync(b=>{b.initialized=!0,b.captureVersion()},{yieldEvery:r})}return c.initialized=!0,c.emit(ri.PROJECT_INITIALIZED,c,f),f==null||f.attemptAutoclose("project-init",c.id),c}async function tVi(l,p=HT,i){const r={...HT,...p};if(l.id&&Qc[l.id]&&!r.ignoreCache)return Qc[l.id];if(l.id&&BA[l.id]&&!r.ignoreCache)return await BA[l.id],Qc[l.id];const a=W_i(l,r);l.id&&(BA[l.id]=a);const c=await a;if(c.data){let e;return r.mock?e=CUe(YL,{enrich:!!r.enrich},i):c.data instanceof N?e=c.data:e=wUe(c.data,{enrich:!!r.enrich},i),Qc[l.id]=e,l.id&&delete BA[l.id],e}return null}function iVi(l){return Qc[l.id]&&delete Qc[l.id],null}const WT=mt([Ze(),ha(),pr(),Fd()]),OUe=Qv([Yr.CurrentDateAndTime,Yr.Random,Yr.Unique]),L1=at({type:OUe,rangeStart:WT.nullable(),rangeEnd:WT.nullable()}),PE=L1.extend({type:tt(Yr.Random),rangeStart:WT,rangeEnd:WT}),_Ue=L1.extend({type:tt(Yr.Unique),rangeStart:Xa(),rangeEnd:Xa()}),VUe=L1.extend({type:tt(Yr.CurrentDateAndTime),rangeStart:Xa(),rangeEnd:Xa()}),B1=PE.extend({rangeStart:ha().nullable(),rangeEnd:ha().nullable()}),PUe=B1.extend({rangeStart:ha(),rangeEnd:Xa()}),NUe=B1.extend({rangeStart:Xa(),rangeEnd:ha()}),xUe=B1.extend({rangeStart:ha(),rangeEnd:ha()}),M1=PE.extend({rangeStart:ha().nullable(),rangeEnd:ha().nullable()}),$Ue=M1.extend({rangeStart:ha(),rangeEnd:Xa()}),LUe=M1.extend({rangeStart:Xa(),rangeEnd:ha()}),BUe=M1.extend({rangeStart:ha(),rangeEnd:ha()}),G1=PE.extend({rangeStart:Fd().nullable(),rangeEnd:Fd().nullable()}),MUe=G1.extend({rangeStart:Fd(),rangeEnd:Xa()}),GUe=G1.extend({rangeStart:Xa(),rangeEnd:Fd()}),jUe=G1.extend({rangeStart:Fd(),rangeEnd:Fd()}),UUe=PE.extend({rangeStart:Xa(),rangeEnd:Xa()}),kUe=mt([$Ue,LUe,BUe]),FUe=mt([PUe,NUe,xUe]),KUe=mt([MUe,GUe,jUe,VUe]),rVi=mt([kUe,FUe,KUe,_Ue,UUe]);function j1(){const l=new Set;return new Set(JN.flatMap(i=>Ue(i,l)).map(i=>i.id))}function Ao(l){return[...l.calledByEntry||[],...l.calledByError||[],...l.calledBySuccess||[]].filter(p=>p.type!==d.GenericReference)}function SUe(l,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(l.id))return[];if(p.add(l.id),l.type!==d.ActionDescriptor)throw new Error("Entity must be an action descriptor to be flattened");return[l,...l.inputs.flatMap(r=>Ue(r,p,i)),...l.dataType?Ue(l.dataType,p,i):[],...l.error?Ue(l.error,p,i):[],...l.parent?Ue(l.parent,p,i):[]]}function qUe(l,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(l.id))return[];if(p.add(l.id),l.type!==d.ArgumentDeclaration)throw new Error("Entity must be an argument declaration to be flattened");return[l,...l.defaultValue?Ue(l.defaultValue,p):[],...l.writesValues.flatMap(r=>Ue(r,p,i)),...l.implements.flatMap(r=>Ue(r,p,i)),...l.dataType?Ue(l.dataType,p,i):[],...l.parent?Ue(l.parent,p,i):[]]}function ZUe(l,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(l.id))return[];if(p.add(l.id),l.type!==d.BreakStatement)throw new Error("Entity must be a break statement to be flattened");return[l,...l.outputs.flatMap(r=>Ue(r,p,i)),...l.throws?Ue(l.throws,p,i):[],...l.dataType?Ue(l.dataType,p,i):[],...l.readsValue?Ue(l.readsValue,p,i):[],...(Ao(l)||[]).flatMap(r=>Ue(r,p,i)),...l.parent?Ue(l.parent,p,i):[]]}function HUe(l,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(l.id))return[];if(p.add(l.id),l.type!==d.BuiltInBaseEntity)throw new Error("Entity must be a built-in base entity to be flattened");return[l,...(l.properties||[]).flatMap(r=>Ue(r,p,i)),...(l.methods||[]).flatMap(r=>Ue(r,p,i)),...(l.abstractMethods||[]).flatMap(r=>Ue(r,p,i)),...l.allPropertiesImplement?Ue(l.allPropertiesImplement,p,i):[],...l.additionalPropertiesDataType?Ue(l.additionalPropertiesDataType,p,i):[],...l.extends?Ue(l.extends,p,i):[]]}function WUe(l,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(l.id))return[];if(p.add(l.id),l.type!==d.Condition)throw new Error("Entity must be a condition to be flattened");return[l,...(l.andChildrenGroup||[]).flatMap(r=>Ue(r,p,i)),...(l.orChildrenGroup||[]).flatMap(r=>Ue(r,p,i)),...(l.inputs||[]).flatMap(r=>Ue(r,p,i)),...(l.successCalls||[]).flatMap(r=>Ue(r,p,i)),...(l.errorCalls||[]).flatMap(r=>Ue(r,p,i)),...(Ao(l)||[]).flatMap(r=>Ue(r,p,i)),...l.parent?Ue(l.parent,p,i):[]]}function zUe(l,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(l.id))return[];if(p.add(l.id),l.type!==d.ContinueStatement)throw new Error("Entity must be a continue statement to be flattened");return[l,...l.outputs.flatMap(r=>Ue(r,p,i)),...l.readsValue?Ue(l.readsValue,p,i):[],...l.throws?Ue(l.throws,p,i):[],...l.dataType?Ue(l.dataType,p,i):[],...(Ao(l)||[]).flatMap(r=>Ue(r,p,i)),...l.parent?Ue(l.parent,p,i):[]]}function YUe(l,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(l.id))return[];if(p.add(l.id),l.type!==d.DefinitionEntity)throw new Error("Entity must be a definition entity to be flattened");return[l,...l.extends?Ue(l.extends,p,i):[],...(l.implements||[]).flatMap(r=>Ue(r,p,i)),...(l.properties||[]).flatMap(r=>Ue(r,p,i)),...(l.methods||[]).flatMap(r=>Ue(r,p,i)),...(l.abstractMethods||[]).flatMap(r=>Ue(r,p,i)),...l.allPropertiesImplement?Ue(l.allPropertiesImplement,p,i):[],...l.additionalPropertiesDataType?Ue(l.additionalPropertiesDataType,p,i):[],...l.parent?Ue(l.parent,p,i):[]]}function JUe(l,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(l.id))return[];if(p.add(l.id),l.type!==d.DataType)throw new Error("Entity must be a data type to be flattened");return[l,...(l.andChildrenGroup||[]).flatMap(r=>Ue(r,p,i)),...(l.orChildrenGroup||[]).flatMap(r=>Ue(r,p,i)),...l.entity?Ue(l.entity,p,i):[],...l.foreignKeyRef?Ue(l.foreignKeyRef,p,i):[],...l.parent?Ue(l.parent,p,i):[]]}function XUe(l,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(l.id))return[];if(p.add(l.id),l.type!==d.FunctionCall)throw new Error("Entity must be a function call to be flattened");return[l,...(l.inputs||[]).flatMap(r=>Ue(r,p,i)),...(l.outputs||[]).flatMap(r=>Ue(r,p,i)),...l.error?Ue(l.error,p,i):[],...(Ao(l)||[]).flatMap(r=>Ue(r,p,i)),...(l.successCalls||[]).flatMap(r=>Ue(r,p,i)),...(l.errorCalls||[]).flatMap(r=>Ue(r,p,i)),...(l.writesValues||[]).flatMap(r=>Ue(r,p,i)),...l.parent?Ue(l.parent,p,i):[]]}function QUe(l,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(l.id))return[];if(p.add(l.id),l.type!==d.FunctionDeclaration)throw new Error("Entity must be a function declaration to be flattened");return[l,...(l.inputs||[]).flatMap(r=>Ue(r,p,i)),...(l.calls||[]).flatMap(r=>Ue(r,p,i)),...l.dataType?Ue(l.dataType,p,i):[],...l.implements?Ue(l.implements,p,i):[],...l.parent?Ue(l.parent,p,i):[]]}function eke(l,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(l.id))return[];if(p.add(l.id),l.type!==d.GlobalEvent)throw new Error("Entity must be a global event to be flattened");return[l,...(l.inputs||[]).flatMap(r=>Ue(r,p,i)),...(l.calls||[]).flatMap(r=>Ue(r,p,i)),...l.implements?Ue(l.implements,p,i):[],...l.parent?Ue(l.parent,p,i):[]]}function tke(l,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(l.id))return[];if(p.add(l.id),l.type!==d.InputMap)throw new Error("Entity must be an input map to be flattened");return[l,...l.readsValue?Ue(l.readsValue,p,i):[],...l.declaration?Ue(l.declaration,p,i):[],...l.defaultValue?Ue(l.defaultValue,p,i):[],...l.parent?Ue(l.parent,p,i):[]]}function ike(l,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(l.id))return[];if(p.add(l.id),l.type!==d.InstalledProject)throw new Error("Entity must be an installed project to be flattened");return[l,...(l.functions||[]).flatMap(r=>Ue(r,p,i)),...(l.events||[]).flatMap(r=>Ue(r,p,i)),...l.parent?Ue(l.parent,p,i):[]]}function rke(l,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(l.id))return[];if(p.add(l.id),l.type!==d.InternalCall)throw new Error("Entity must be an internal call to be flattened");return[l,...(l.successCalls||[]).flatMap(r=>Ue(r,p,i)),...(l.errorCalls||[]).flatMap(r=>Ue(r,p,i)),...(l.inputs||[]).flatMap(r=>Ue(r,p,i)),...(l.outputs||[]).flatMap(r=>Ue(r,p,i)),...(Ao(l)||[]).flatMap(r=>Ue(r,p,i)),...l.error?Ue(l.error,p,i):[],...(l.writesValues||[]).flatMap(r=>Ue(r,p,i)),...l.parent?Ue(l.parent,p,i):[]]}function nke(l,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(l.id))return[];if(p.add(l.id),l.type!==d.LiteralValue)throw new Error("Entity must be a literal value to be flattened");return[l,...l.valueAsTypeSingle?Ue(l.valueAsTypeSingle,p,i):[],...l.valueAsTypeList&&Array.isArray(l.valueAsTypeList)?l.valueAsTypeList.flatMap(r=>Ue(r,p,i)):[],...l.parent?Ue(l.parent,p,i):[]]}function ake(l,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(l.id))return[];if(p.add(l.id),l.type!==d.Loop)throw new Error("Entity must be a loop to be flattened");return[l,...(l.inputs||[]).flatMap(r=>Ue(r,p,i)),...(l.outputs||[]).flatMap(r=>Ue(r,p,i)),...(l.successCalls||[]).flatMap(r=>Ue(r,p,i)),...(l.errorCalls||[]).flatMap(r=>Ue(r,p,i)),...l.error?Ue(l.error,p,i):[],...l.dataType?Ue(l.dataType,p,i):[],...l.body?Ue(l.body,p,i):[],...(Ao(l)||[]).flatMap(r=>Ue(r,p,i)),...(l.writesValues||[]).flatMap(r=>Ue(r,p,i)),...l.parent?Ue(l.parent,p,i):[]]}function ske(l,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(l.id))return[];if(p.add(l.id),l.type!==d.Operation)throw new Error("Entity must be an operation to be flattened");return[l,...(l.successCalls||[]).flatMap(r=>Ue(r,p,i)),...(l.errorCalls||[]).flatMap(r=>Ue(r,p,i)),...(l.inputs||[]).flatMap(r=>Ue(r,p,i)),...(l.outputs||[]).flatMap(r=>Ue(r,p,i)),...(l.writesValues||[]).flatMap(r=>Ue(r,p,i)),...l.error?Ue(l.error,p,i):[],...(Ao(l)||[]).flatMap(r=>Ue(r,p,i)),...l.parent?Ue(l.parent,p,i):[]]}function lke(l,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(l.id))return[];if(p.add(l.id),l.type!==d.OutputMap)throw new Error("Entity must be an output map to be flattened");return[l,...(l.writesValues||[]).flatMap(r=>Ue(r,p,i)),...l.declaration?Ue(l.declaration,p,i):[],...l.parent?Ue(l.parent,p,i):[]]}function oke(l,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(l.id))return[];if(p.add(l.id),l.type!==d.PrimitiveEntity)throw new Error("Entity must be a primitive entity to be flattened");return[l,...(l.properties||[]).flatMap(r=>Ue(r,p,i)),...(l.methods||[]).flatMap(r=>Ue(r,p,i)),...(l.abstractMethods||[]).flatMap(r=>Ue(r,p,i))]}function dke(l,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(l.id))return[];if(p.add(l.id),l.type!==d.Project)throw new Error("Entity must be a project to be flattened");return[l,...(l.entities||[]).flatMap(r=>Ue(r,p,i)),...(l.functions||[]).flatMap(r=>Ue(r,p,i)),...(l.events||[]).flatMap(r=>Ue(r,p,i)),...(l.projects||[]).flatMap(r=>Ue(r,p,i)),...(l.variableDeclarations||[]).flatMap(r=>Ue(r,p,i)),...(l.variableInstances||[]).flatMap(r=>Ue(r,p,i)),...(l.operations||[]).flatMap(r=>Ue(r,p,i)),...(l.conditions||[]).flatMap(r=>Ue(r,p,i)),...(l.functionCalls||[]).flatMap(r=>Ue(r,p,i)),...(l.projects||[]).flatMap(r=>Ue(r,p,i)),...(l.loops||[]).flatMap(r=>Ue(r,p,i)),...(l.searches||[]).flatMap(r=>Ue(r,p,i))]}function uke(l,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(l.id))return[];if(p.add(l.id),l.type!==d.Property)throw new Error("Entity must be a property to be flattened");return[l,...l.defaultValue?Ue(l.defaultValue,p,i):[],...l.dataType?Ue(l.dataType,p,i):[],...l.parent?Ue(l.parent,p,i):[]]}function pke(l,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(l.id))return[];if(p.add(l.id),l.type!==d.ReturnStatement)throw new Error("Entity must be a return statement to be flattened");return[l,...(l.outputs||[]).flatMap(r=>Ue(r,p,i)),...l.throws?Ue(l.throws,p,i):[],...l.readsValue?Ue(l.readsValue,p,i):[],...l.dataType?Ue(l.dataType,p,i):[],...(Ao(l)||[]).flatMap(r=>Ue(r,p,i)),...l.parent?Ue(l.parent,p,i):[]]}function cke(l,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(l.id))return[];if(p.add(l.id),l.type!==d.Search)throw new Error("Entity must be a search to be flattened");return[l,...(l.successCalls||[]).flatMap(r=>Ue(r,p,i)),...(l.errorCalls||[]).flatMap(r=>Ue(r,p,i)),...(l.inputsDeclarations||[]).flatMap(r=>Ue(r,p,i)),...(l.inputs||[]).flatMap(r=>Ue(r,p,i)),...(l.writesValues||[]).flatMap(r=>Ue(r,p,i)),...(l.outputs||[]).flatMap(r=>Ue(r,p,i)),...l.error?Ue(l.error,p,i):[],...l.dataType?Ue(l.dataType,p,i):[],...(Ao(l)||[]).flatMap(r=>Ue(r,p,i)),...l.parent?Ue(l.parent,p,i):[]]}function fke(l,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(l.id))return[];if(p.add(l.id),l.type!==d.ValueDescriptor)throw new Error("Entity must be a value descriptor to be flattened");return[l,...l.defaultValue?Ue(l.defaultValue,p,i):[],...l.dataType?Ue(l.dataType,p,i):[],...l.parent?Ue(l.parent,p,i):[]]}function yke(l,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(l.id))return[];if(p.add(l.id),l.type!==d.VariableDeclaration)throw new Error("Entity must be a variable declaration to be flattened");return[l,...(l.successCalls||[]).flatMap(r=>Ue(r,p,i)),...(l.errorCalls||[]).flatMap(r=>Ue(r,p,i)),...(l.inputs||[]).flatMap(r=>Ue(r,p,i)),...(l.outputs||[]).flatMap(r=>Ue(r,p,i)),...(l.internalCalls||[]).flatMap(r=>Ue(r,p,i)),...(l.writesValues||[]).flatMap(r=>Ue(r,p,i)),...l.readsValue?Ue(l.readsValue,p,i):[],...l.defaultValue?Ue(l.defaultValue,p,i):[],...(Ao(l)||[]).flatMap(r=>Ue(r,p,i)),...l.dataType?Ue(l.dataType,p,i):[],...l.parent?Ue(l.parent,p,i):[]]}function hke(l,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(l.id))return[];if(p.add(l.id),l.type!==d.VariableInstance)throw new Error("Entity must be a variable instance to be flattened");return[l,...(l.successCalls||[]).flatMap(r=>Ue(r,p,i)),...(l.errorCalls||[]).flatMap(r=>Ue(r,p,i)),...(l.inputs||[]).flatMap(r=>Ue(r,p,i)),...(l.outputs||[]).flatMap(r=>Ue(r,p,i)),...(l.internalCalls||[]).flatMap(r=>Ue(r,p,i)),...(l.writesValues||[]).flatMap(r=>Ue(r,p,i)),...l.readsValue?Ue(l.readsValue,p,i):[],...l.defaultValue?Ue(l.defaultValue,p,i):[],...(Ao(l)||[]).flatMap(r=>Ue(r,p,i)),...l.declaration?Ue(l.declaration,p,i):[],...l.parent?Ue(l.parent,p,i):[]]}function Ue(l,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(!l)throw new Error("Entity must be defined to be flattened");if(l.type===d.GenericReference)return[];const r=i.ignoreBuiltInBaseEntities?i.diggestedBuiltInBaseEntitiesIds??new Set(j1()):new Set;if(i.diggestedBuiltInBaseEntitiesIds=r,i.ignoreBuiltInBaseEntities&&(ra.includes(l.type)||r.has(l.id)))return[];if(p.has(l.id))return[];switch(l.type){case d.FunctionCall:return XUe(l,p,i);case d.Operation:return ske(l,p,i);case d.Condition:return WUe(l,p,i);case d.Loop:return ake(l,p,i);case d.Search:return cke(l,p,i);case d.GlobalEvent:return eke(l,p,i);case d.ReturnStatement:return pke(l,p,i);case d.ContinueStatement:return zUe(l,p,i);case d.BreakStatement:return ZUe(l,p,i);case d.VariableDeclaration:return yke(l,p,i);case d.DefinitionEntity:return YUe(l,p,i);case d.FunctionDeclaration:return QUe(l,p,i);case d.Project:return dke(l,p,i);case d.ActionDescriptor:return SUe(l,p,i);case d.ArgumentDeclaration:return qUe(l,p,i);case d.ValueDescriptor:return fke(l,p,i);case d.InputMap:return tke(l,p,i);case d.OutputMap:return lke(l,p,i);case d.DataType:return JUe(l,p,i);case d.InstalledProject:return ike(l,p,i);case d.InternalCall:return rke(l,p,i);case d.LiteralValue:return nke(l,p,i);case d.Property:return uke(l,p,i);case d.VariableInstance:return hke(l,p,i);case d.BuiltInBaseEntity:return i.ignoreBuiltInBaseEntities?[]:HUe(l,p,i);case d.PrimitiveEntity:return i.ignoreBuiltInBaseEntities?[]:oke(l,p,i)}return[]}async function U1(l={}){const p=new Set,i=z.YieldTracker.from(l),r=new Set;for(const a of JN){const c=await je(a,p,{ignoreBuiltInBaseEntities:!1,tracker:i});for(const e of c)r.add(e.id),await i.tick()}return r}function go(l){return[...l.calledByEntry||[],...l.calledByError||[],...l.calledBySuccess||[]].filter(p=>p.type!==d.GenericReference)}async function mke(l,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(l.id))return[];if(p.add(l.id),l.type!==d.ActionDescriptor)throw new Error("Entity must be an action descriptor to be flattened");const r=z.YieldTracker.from(i),a=[l];await r.tick();const c={...i,tracker:r};delete c.yieldEvery;for(const e of l.inputs)a.push(...await je(e,p,c));return l.dataType&&a.push(...await je(l.dataType,p,c)),l.error&&a.push(...await je(l.error,p,c)),l.parent&&a.push(...await je(l.parent,p,c)),a}async function Tke(l,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(l.id))return[];if(p.add(l.id),l.type!==d.ArgumentDeclaration)throw new Error("Entity must be an argument declaration to be flattened");const r=z.YieldTracker.from(i),a=[l];await r.tick();const c={...i,tracker:r};delete c.yieldEvery,l.dataType&&a.push(...await je(l.dataType,p,c)),l.parent&&a.push(...await je(l.parent,p,c)),l.defaultValue&&a.push(...await je(l.defaultValue,p,c));for(const e of l.writesValues||[])a.push(...await je(e,p,c));for(const e of l.implements||[])a.push(...await je(e,p,c));return a}async function vke(l,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(l.id))return[];if(p.add(l.id),l.type!==d.BreakStatement)throw new Error("Entity must be a break statement to be flattened");const r=z.YieldTracker.from(i),a=[l];await r.tick();const c={...i,tracker:r};delete c.yieldEvery;for(const f of l.outputs)a.push(...await je(f,p,c));l.parent&&a.push(...await je(l.parent,p,c)),l.throws&&a.push(...await je(l.throws,p,c)),l.dataType&&a.push(...await je(l.dataType,p,c)),l.readsValue&&a.push(...await je(l.readsValue,p,c));const e=go(l);for(const f of e)a.push(...await je(f,p,c));return a}async function Eke(l,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(l.id))return[];if(p.add(l.id),l.type!==d.BuiltInBaseEntity)throw new Error("Entity must be a built-in base entity to be flattened");const r=z.YieldTracker.from(i),a=[l];await r.tick();const c={...i,tracker:r};delete c.yieldEvery;for(const e of l.properties||[])a.push(...await je(e,p,c));for(const e of l.methods||[])a.push(...await je(e,p,c));for(const e of l.abstractMethods||[])a.push(...await je(e,p,c));return l.allPropertiesImplement&&a.push(...await je(l.allPropertiesImplement,p,c)),l.additionalPropertiesDataType&&a.push(...await je(l.additionalPropertiesDataType,p,c)),l.extends&&a.push(...await je(l.extends,p,c)),a}async function bke(l,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(l.id))return[];if(p.add(l.id),l.type!==d.Condition)throw new Error("Entity must be a condition to be flattened");const r=z.YieldTracker.from(i),a=[l];await r.tick();const c={...i,tracker:r};if(delete c.yieldEvery,l.andChildrenGroup&&Array.isArray(l.andChildrenGroup))for(const f of l.andChildrenGroup)a.push(...await je(f,p,c));if(l.orChildrenGroup&&Array.isArray(l.orChildrenGroup))for(const f of l.orChildrenGroup)a.push(...await je(f,p,c));for(const f of l.inputs)a.push(...await je(f,p,c));for(const f of l.successCalls)a.push(...await je(f,p,c));for(const f of l.errorCalls)a.push(...await je(f,p,c));const e=go(l);for(const f of e)a.push(...await je(f,p,c));return l.parent&&a.push(...await je(l.parent,p,c)),a}async function Ake(l,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(l.id))return[];if(p.add(l.id),l.type!==d.ContinueStatement)throw new Error("Entity must be a continue statement to be flattened");const r=z.YieldTracker.from(i),a=[l];await r.tick();const c={...i,tracker:r};delete c.yieldEvery;for(const f of l.outputs)a.push(...await je(f,p,c));const e=go(l);for(const f of e)a.push(...await je(f,p,c));return l.parent&&a.push(...await je(l.parent,p,c)),l.throws&&a.push(...await je(l.throws,p,c)),l.dataType&&a.push(...await je(l.dataType,p,c)),l.readsValue&&a.push(...await je(l.readsValue,p,c)),a}async function gke(l,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(l.id))return[];if(p.add(l.id),l.type!==d.DefinitionEntity)throw new Error("Entity must be a definition entity to be flattened");const r=z.YieldTracker.from(i),a=[l];await r.tick();const c={...i,tracker:r};delete c.yieldEvery;for(const e of l.properties)a.push(...await je(e,p,c));for(const e of l.methods)a.push(...await je(e,p,c));for(const e of l.abstractMethods)a.push(...await je(e,p,c));for(const e of l.implements)a.push(...await je(e,p,c));return l.extends&&a.push(...await je(l.extends,p,c)),l.parent&&a.push(...await je(l.parent,p,c)),l.additionalPropertiesDataType&&a.push(...await je(l.additionalPropertiesDataType,p,c)),l.allPropertiesImplement&&a.push(...await je(l.allPropertiesImplement,p,c)),a}async function Ike(l,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(l.id))return[];if(p.add(l.id),l.type!==d.DataType)throw new Error("Entity must be a data type to be flattened");const r=z.YieldTracker.from(i),a=[l];await r.tick();const c={...i,tracker:r};if(delete c.yieldEvery,l.parent&&a.push(...await je(l.parent,p,c)),l.foreignKeyRef&&a.push(...await je(l.foreignKeyRef,p,c)),l.entity&&a.push(...await je(l.entity,p,c)),l.orChildrenGroup)for(const e of l.orChildrenGroup)a.push(...await je(e,p,c));if(l.andChildrenGroup)for(const e of l.andChildrenGroup)a.push(...await je(e,p,c));return a}async function Rke(l,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(l.id))return[];if(p.add(l.id),l.type!==d.FunctionCall)throw new Error("Entity must be a function call to be flattened");const r=z.YieldTracker.from(i),a=[l];await r.tick();const c={...i,tracker:r};delete c.yieldEvery;for(const f of l.inputs)a.push(...await je(f,p,c));for(const f of l.outputs)a.push(...await je(f,p,c));l.error&&a.push(...await je(l.error,p,c));const e=go(l);for(const f of e)a.push(...await je(f,p,c));for(const f of l.successCalls)a.push(...await je(f,p,c));for(const f of l.errorCalls)a.push(...await je(f,p,c));for(const f of l.writesValues)a.push(...await je(f,p,c));return l.parent&&a.push(...await je(l.parent,p,c)),a}async function Dke(l,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(l.id))return[];if(p.add(l.id),l.type!==d.FunctionDeclaration)throw new Error("Entity must be a function declaration to be flattened");const r=z.YieldTracker.from(i),a=[l];await r.tick();const c={...i,tracker:r};delete c.yieldEvery,l.parent&&a.push(...await je(l.parent,p,c)),l.implements&&a.push(...await je(l.implements,p,c)),l.dataType&&a.push(...await je(l.dataType,p,c));for(const e of l.inputs)a.push(...await je(e,p,c));for(const e of l.calls)a.push(...await je(e,p,c));return a}async function wke(l,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(l.id))return[];if(p.add(l.id),l.type!==d.GlobalEvent)throw new Error("Entity must be a global event to be flattened");const r=z.YieldTracker.from(i),a=[l];await r.tick();const c={...i,tracker:r};delete c.yieldEvery,l.parent&&a.push(...await je(l.parent,p,c)),l.implements&&a.push(...await je(l.implements,p,c));for(const e of l.inputs)a.push(...await je(e,p,c));for(const e of l.calls)a.push(...await je(e,p,c));return a}async function Cke(l,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(l.id))return[];if(p.add(l.id),l.type!==d.InputMap)throw new Error("Entity must be an input map to be flattened");const r=z.YieldTracker.from(i),a=[l];await r.tick();const c={...i,tracker:r};return delete c.yieldEvery,l.parent&&a.push(...await je(l.parent,p,c)),l.declaration&&a.push(...await je(l.declaration,p,c)),l.readsValue&&a.push(...await je(l.readsValue,p,c)),l.dataType&&a.push(...await je(l.dataType,p,c)),l.defaultValue&&a.push(...await je(l.defaultValue,p,c)),a}async function Oke(l,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(l.id))return[];if(p.add(l.id),l.type!==d.InstalledProject)throw new Error("Entity must be an installed project to be flattened");const r=z.YieldTracker.from(i),a=[l];await r.tick();const c={...i,tracker:r};delete c.yieldEvery;for(const e of l.functions)a.push(...await je(e,p,c));for(const e of l.events)a.push(...await je(e,p,c));return l.parent&&a.push(...await je(l.parent,p,c)),a}async function _ke(l,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(l.id))return[];if(p.add(l.id),l.type!==d.InternalCall)throw new Error("Entity must be an internal call to be flattened");const r=z.YieldTracker.from(i),a=[l];await r.tick();const c={...i,tracker:r};delete c.yieldEvery;for(const f of l.inputs)a.push(...await je(f,p,c));for(const f of l.outputs)a.push(...await je(f,p,c));l.error&&a.push(...await je(l.error,p,c));const e=go(l);for(const f of e)a.push(...await je(f,p,c));for(const f of l.successCalls)a.push(...await je(f,p,c));for(const f of l.errorCalls)a.push(...await je(f,p,c));for(const f of l.writesValues)a.push(...await je(f,p,c));return l.parent&&a.push(...await je(l.parent,p,c)),a}async function Vke(l,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(l.id))return[];if(p.add(l.id),l.type!==d.LiteralValue)throw new Error("Entity must be a literal value to be flattened");const r=z.YieldTracker.from(i),a=[l];await r.tick();const c={...i,tracker:r};if(delete c.yieldEvery,l.valueAsTypeSingle&&a.push(...await je(l.valueAsTypeSingle,p,c)),l.valueAsTypeList&&Array.isArray(l.valueAsTypeList))for(const e of l.valueAsTypeList)a.push(...await je(e,p,c));return l.parent&&a.push(...await je(l.parent,p,c)),a}async function Pke(l,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(l.id))return[];if(p.add(l.id),l.type!==d.Loop)throw new Error("Entity must be a loop to be flattened");const r=z.YieldTracker.from(i),a=[l];await r.tick();const c={...i,tracker:r};delete c.yieldEvery;for(const f of l.inputs)a.push(...await je(f,p,c));for(const f of l.outputs)a.push(...await je(f,p,c));l.error&&a.push(...await je(l.error,p,c));const e=go(l);for(const f of e)a.push(...await je(f,p,c));for(const f of l.successCalls)a.push(...await je(f,p,c));for(const f of l.errorCalls)a.push(...await je(f,p,c));for(const f of l.writesValues)a.push(...await je(f,p,c));return l.parent&&a.push(...await je(l.parent,p,c)),l.body&&a.push(...await je(l.body,p,c)),l.dataType&&a.push(...await je(l.dataType,p,c)),a}async function Nke(l,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(l.id))return[];if(p.add(l.id),l.type!==d.Operation)throw new Error("Entity must be an operation to be flattened");const r=z.YieldTracker.from(i),a=[l];await r.tick();const c={...i,tracker:r};delete c.yieldEvery;for(const f of l.inputs)a.push(...await je(f,p,c));for(const f of l.outputs)a.push(...await je(f,p,c));l.error&&a.push(...await je(l.error,p,c));const e=go(l);for(const f of e)a.push(...await je(f,p,c));for(const f of l.successCalls)a.push(...await je(f,p,c));for(const f of l.errorCalls)a.push(...await je(f,p,c));for(const f of l.writesValues)a.push(...await je(f,p,c));return l.parent&&a.push(...await je(l.parent,p,c)),a}async function xke(l,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(l.id))return[];if(p.add(l.id),l.type!==d.OutputMap)throw new Error("Entity must be an output map to be flattened");const r=z.YieldTracker.from(i),a=[l];await r.tick();const c={...i,tracker:r};delete c.yieldEvery;for(const e of l.writesValues)a.push(...await je(e,p,c));return l.declaration&&a.push(...await je(l.declaration,p,c)),l.dataType&&a.push(...await je(l.dataType,p,c)),l.parent&&a.push(...await je(l.parent,p,c)),a}async function $ke(l,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(l.id))return[];if(p.add(l.id),l.type!==d.PrimitiveEntity)throw new Error("Entity must be a primitive entity to be flattened");const r=z.YieldTracker.from(i),a=[l];await r.tick();const c={...i,tracker:r};delete c.yieldEvery;for(const e of l.properties)a.push(...await je(e,p,c));for(const e of l.methods)a.push(...await je(e,p,c));for(const e of l.abstractMethods)a.push(...await je(e,p,c));return a}async function Lke(l,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(l.id))return[];if(p.add(l.id),l.type!==d.Project)throw new Error("Entity must be a project to be flattened");const r=z.YieldTracker.from(i),a=[l];await r.tick();const c={...i,tracker:r};delete c.yieldEvery;for(const e of l.entities)a.push(...await je(e,p,c));for(const e of l.functions)a.push(...await je(e,p,c));for(const e of l.events)a.push(...await je(e,p,c));for(const e of l.projects)a.push(...await je(e,p,c));for(const e of l.variableDeclarations)a.push(...await je(e,p,c));for(const e of l.variableInstances)a.push(...await je(e,p,c));for(const e of l.operations)a.push(...await je(e,p,c));for(const e of l.conditions)a.push(...await je(e,p,c));for(const e of l.functionCalls)a.push(...await je(e,p,c));for(const e of l.projects)a.push(...await je(e,p,c));for(const e of l.loops)a.push(...await je(e,p,c));for(const e of l.searches)a.push(...await je(e,p,c));return a}async function Bke(l,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(l.id))return[];if(p.add(l.id),l.type!==d.Property)throw new Error("Entity must be a property to be flattened");const r=z.YieldTracker.from(i),a=[l];await r.tick();const c={...i,tracker:r};return delete c.yieldEvery,l.defaultValue&&a.push(...await je(l.defaultValue,p,c)),l.dataType&&a.push(...await je(l.dataType,p,c)),l.parent&&a.push(...await je(l.parent,p,c)),a}async function Mke(l,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(l.id))return[];if(p.add(l.id),l.type!==d.ReturnStatement)throw new Error("Entity must be a return statement to be flattened");const r=z.YieldTracker.from(i),a=[l];await r.tick();const c={...i,tracker:r};delete c.yieldEvery;for(const f of l.outputs)a.push(...await je(f,p,c));for(const f of l.outputs)a.push(...await je(f,p,c));l.throws&&a.push(...await je(l.throws,p,c)),l.readsValue&&a.push(...await je(l.readsValue,p,c)),l.dataType&&a.push(...await je(l.dataType,p,c));const e=go(l);for(const f of e)a.push(...await je(f,p,c));return l.parent&&a.push(...await je(l.parent,p,c)),a}async function Gke(l,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(l.id))return[];if(p.add(l.id),l.type!==d.Search)throw new Error("Entity must be a search to be flattened");const r=z.YieldTracker.from(i),a=[l];await r.tick();const c={...i,tracker:r};delete c.yieldEvery;for(const f of l.inputs)a.push(...await je(f,p,c));for(const f of l.outputs)a.push(...await je(f,p,c));l.error&&a.push(...await je(l.error,p,c)),l.dataType&&a.push(...await je(l.dataType,p,c));for(const f of l.inputsDeclarations)a.push(...await je(f,p,c));const e=go(l);for(const f of e)a.push(...await je(f,p,c));for(const f of l.successCalls)a.push(...await je(f,p,c));for(const f of l.errorCalls)a.push(...await je(f,p,c));for(const f of l.writesValues)a.push(...await je(f,p,c));return l.parent&&a.push(...await je(l.parent,p,c)),a}async function jke(l,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(l.id))return[];if(p.add(l.id),l.type!==d.ValueDescriptor)throw new Error("Entity must be a value descriptor to be flattened");const r=z.YieldTracker.from(i),a=[l];await r.tick();const c={...i,tracker:r};return delete c.yieldEvery,l.defaultValue&&a.push(...await je(l.defaultValue,p,c)),l.dataType&&a.push(...await je(l.dataType,p,c)),l.parent&&a.push(...await je(l.parent,p,c)),a}async function Uke(l,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(l.id))return[];if(p.add(l.id),l.type!==d.VariableDeclaration)throw new Error("Entity must be a variable declaration to be flattened");const r=z.YieldTracker.from(i),a=[l];await r.tick();const c={...i,tracker:r};delete c.yieldEvery;for(const f of l.inputs)a.push(...await je(f,p,c));for(const f of l.outputs)a.push(...await je(f,p,c));l.error&&a.push(...await je(l.error,p,c)),l.dataType&&a.push(...await je(l.dataType,p,c)),l.readsValue&&a.push(...await je(l.readsValue,p,c)),l.defaultValue&&a.push(...await je(l.defaultValue,p,c));const e=go(l);for(const f of e)a.push(...await je(f,p,c));for(const f of l.successCalls)a.push(...await je(f,p,c));for(const f of l.errorCalls)a.push(...await je(f,p,c));for(const f of l.writesValues)a.push(...await je(f,p,c));for(const f of l.internalCalls)a.push(...await je(f,p,c));return l.parent&&a.push(...await je(l.parent,p,c)),a}async function kke(l,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(l.id))return[];if(p.add(l.id),l.type!==d.VariableInstance)throw new Error("Entity must be a variable instance to be flattened");const r=z.YieldTracker.from(i),a=[l];await r.tick();const c={...i,tracker:r};delete c.yieldEvery;for(const f of l.inputs)a.push(...await je(f,p,c));for(const f of l.outputs)a.push(...await je(f,p,c));l.error&&a.push(...await je(l.error,p,c)),l.readsValue&&a.push(...await je(l.readsValue,p,c)),l.defaultValue&&a.push(...await je(l.defaultValue,p,c));const e=go(l);for(const f of e)a.push(...await je(f,p,c));for(const f of l.successCalls)a.push(...await je(f,p,c));for(const f of l.errorCalls)a.push(...await je(f,p,c));for(const f of l.writesValues)a.push(...await je(f,p,c));for(const f of l.internalCalls)a.push(...await je(f,p,c));return l.parent&&a.push(...await je(l.parent,p,c)),l.declaration&&a.push(...await je(l.declaration,p,c)),a}async function je(l,p=new Set,i={ignoreBuiltInBaseEntities:!1,yieldEvery:100}){const r={...i,ignoreBuiltInBaseEntities:i.ignoreBuiltInBaseEntities??!1};if(!l)throw new Error("Entity must be defined to be flattened");if(l.type===d.GenericReference)return[];const a=z.YieldTracker.from(r);r.tracker=a,r.yieldEvery!==void 0&&delete r.yieldEvery;const c=r.ignoreBuiltInBaseEntities?r.diggestedBuiltInBaseEntitiesIds??new Set(await U1(r)):new Set;if(r.diggestedBuiltInBaseEntitiesIds=c,r.ignoreBuiltInBaseEntities&&(ra.includes(l.type)||c.has(l.id)))return[];if(p.has(l.id))return[];switch(l.type){case d.FunctionCall:return Rke(l,p,r);case d.Operation:return Nke(l,p,r);case d.Condition:return bke(l,p,r);case d.Loop:return Pke(l,p,r);case d.Search:return Gke(l,p,r);case d.GlobalEvent:return wke(l,p,r);case d.ReturnStatement:return Mke(l,p,r);case d.ContinueStatement:return Ake(l,p,r);case d.BreakStatement:return vke(l,p,r);case d.VariableDeclaration:return Uke(l,p,r);case d.DefinitionEntity:return gke(l,p,r);case d.FunctionDeclaration:return Dke(l,p,r);case d.Project:return Lke(l,p,r);case d.ActionDescriptor:return mke(l,p,r);case d.ArgumentDeclaration:return Tke(l,p,r);case d.ValueDescriptor:return jke(l,p,r);case d.InputMap:return Cke(l,p,r);case d.OutputMap:return xke(l,p,r);case d.DataType:return Ike(l,p,r);case d.InstalledProject:return Oke(l,p,r);case d.InternalCall:return _ke(l,p,r);case d.LiteralValue:return Vke(l,p,r);case d.Property:return Bke(l,p,r);case d.VariableInstance:return kke(l,p,r);case d.BuiltInBaseEntity:return r.ignoreBuiltInBaseEntities?[]:Eke(l,p,r);case d.PrimitiveEntity:return r.ignoreBuiltInBaseEntities?[]:$ke(l,p,r)}return[]}function Fke(l){return l==null||l===""}function nVi(l){return l===null}function Pn(l){return l!=null&&l.valueAsType?!1:Fke(l==null?void 0:l.value)}function rd(l){return l?l.valueAsType===null&&l.value===null:!1}function Kke(l,p){if(l===p||!l&&!p)return!0;if(!l||!p||l.name===ye.EntityTemplate&&p.name!==ye.EntityTemplate||p.name===ye.EntityTemplate&&l.name!==ye.EntityTemplate)return!1;if(l.name===ye.ActionDescriptor&&p.name!==ye.ActionDescriptor||p.name===ye.ActionDescriptor&&l.name!==ye.ActionDescriptor)return!1;if(l.valueAsTypeSingle&&!p.valueAsTypeSingle||p.valueAsTypeSingle&&!l.valueAsTypeSingle)return!1;if(l.valueAsTypeList&&!p.valueAsTypeList||p.valueAsTypeList&&!l.valueAsTypeList)return!1;if(l.valueAsTypeSingle&&p.valueAsTypeSingle){if(l.valueAsTypeSingle.id!==p.valueAsTypeSingle.id)return!1}else if(l.valueAsTypeList&&p.valueAsTypeList){if(l.valueAsTypeList.length!==p.valueAsTypeList.length)return!1;for(let i=0;i<l.valueAsTypeList.length;i++)if(l.valueAsTypeList[i].id!==p.valueAsTypeList[i].id)return!1}else if(!l.valueAsType&&!p.valueAsType&&l.value!==p.value)return!1;return!0}function Ske(l,p,i){if(!i)throw new Error("[checkIsRowTransformerUpToDate] 'lastPublishedEntityVersion' argument is required");if(!p)throw new Error("[checkIsRowTransformerUpToDate] 'entity' argument is required");if(!l)throw new Error("[checkIsRowTransformerUpToDate] 'newestOpenRowTransformer' argument is required");let r=!0;const a=l.methods.find(c=>{var e;return((e=c.implements)==null?void 0:e.id)===re["built-in-base-entity"].BUILT_IN_SQL_ROW_TRANSFORMER_ENTITY.methods.up.id});if(a?(Vn(i).forEach(c=>{const e=a.inputs.find(f=>f.name===c.name);e&&si(e.getDataType(null),c.getDataType(null)).compatible||(r=!1)}),a.returnStatements.forEach(c=>{!c.dataType||!c.dataType.entity||c.dataType.entity.type!==d.DefinitionEntity?r=!1:LT(c.dataType.entity,p)||(r=!1)})):r=!1,r===null||r){const c=l.methods.find(e=>{var f;return((f=e.implements)==null?void 0:f.id)===re["built-in-base-entity"].BUILT_IN_SQL_ROW_TRANSFORMER_ENTITY.methods.down.id});c?(Vn(p).forEach(e=>{const f=c.inputs.find(h=>h.name===e.name);f&&si(f.getDataType(null),e.getDataType(null)).compatible||(r=!1)}),c.returnStatements.forEach(e=>{!e.dataType||!e.dataType.entity||e.dataType.entity.type!==d.DefinitionEntity?r=!1:LT(e.dataType.entity,i)||(r=!1)})):r=!1}return{isPreexistingRowTransformerUpToDate:r}}function qke(l,p,i){const r={changesSinceLastPublication:!1,rowTransformerNeeded:!1,newRowTransformerNeeded:!1,newestOpenRowTransformer:null,newRequiredProperties:[],newNonRequiredProperties:[],deletedProperties:[],lastPublishedEntityVersion:null,updatedEntityVersion:i,propChanges:new Map,isPreexistingRowTransformerUpToDate:null,extendedEntities:[]},c=l.entities.filter(k=>{var ie;if(k.id===i.id)return!1;let G=!1,H=k;for(;H;){if(((ie=H.extends)==null?void 0:ie.id)===i.id){G=!0;break}if(H.extends&&H.extends.type===d.DefinitionEntity)H=H.extends;else break}return G}).map(k=>qke(l,p,k));if(!p)return{...r,changesSinceLastPublication:!0,extendedEntities:c};const e=p.get(i.id);if(!e)return{...r,changesSinceLastPublication:!0,extendedEntities:c};const f=p.entities.filter(k=>Wi(k,Ie.SQL_ROW_TRANSFORMER)),m=l.entities.filter(k=>{var ee;if(!Wi(k,Ie.SQL_ROW_TRANSFORMER)||f.find(ue=>ue.id===k.id))return!1;const H=k.properties.find(ue=>!!ue.implements.find(ae=>re["built-in-base-entity"].BUILT_IN_SQL_ROW_TRANSFORMER_ENTITY.properties.definition.id===ae.id));if(!H)return!1;const ie=(ee=H.defaultValue)==null?void 0:ee.valueAsType;return ie?ie.id===i.id:!1}).sort((k,G)=>B(k.createdAt).isAfter(B(G.createdAt))?-1:1)[0]||null,E=new Map;let b=!1;const g=Vn(i).filter(k=>Vn(e).find(ie=>ie.id===k.id)?!1:!_a(k.getDataType(null))),_=Vn(i).filter(k=>Vn(e).find(ie=>ie.id===k.id)?!1:!!_a(k.getDataType(null))),$=Vn(e).filter(k=>!Vn(i).find(H=>H.id===k.id));Vn(i).filter(k=>{var ne,le,Q,oe,Ee,Te,Ve,Le,$e,ke,Ke;const G=Vn(e).find(Je=>Je.id===k.id);let H=!1;if(!G)return!1;const ie=el(k.dataType,!0,`[resolveSQLMigrationsDiffs] Unsupported data-type structure on current property '${k.name}' (${k.id}). 'andChildrenGroup' with more than one child is not supported for SQL column properties.`),ee=el(G.dataType,!0,`[resolveSQLMigrationsDiffs] Unsupported data-type structure on last published property '${k.name}' (${k.id}). 'andChildrenGroup' with more than one child is not supported for SQL column properties.`),ue=lg(ie,!0,`[resolveSQLMigrationsDiffs] Unsupported data-type structure on current property '${k.name}' (${k.id}). 'orChildrenGroup' with multiple non-null children is not supported for SQL column properties.`),ae=lg(ee,!0,`[resolveSQLMigrationsDiffs] Unsupported data-type structure on last published property '${k.name}' (${k.id}). 'orChildrenGroup' with multiple non-null children is not supported for SQL column properties.`);if(((ne=ue==null?void 0:ue.foreignKeyRef)==null?void 0:ne.id)!==((le=ae==null?void 0:ae.foreignKeyRef)==null?void 0:le.id)){const Je=ue==null?void 0:ue.foreignKeyRef,rt=ae==null?void 0:ae.foreignKeyRef;E.set(k.id,{...E.get(k.id)||{},newForeignKeyRef:Je||void 0,oldForeignKeyRef:rt||void 0,property:k,oldProperty:G}),H=!0,b=!0}else((Q=ue==null?void 0:ue.entity)==null?void 0:Q.id)!==((oe=ae==null?void 0:ae.entity)==null?void 0:oe.id)&&(((Ee=ue==null?void 0:ue.entity)==null?void 0:Ee.id)===re["primitive-entity"].string.id||((Te=ae==null?void 0:ae.entity)==null?void 0:Te.id)===re["primitive-entity"].date.id&&((Ve=ue==null?void 0:ue.entity)==null?void 0:Ve.id)===re["primitive-entity"].number.id?E.set(k.id,{...E.get(k.id)||{},castableDataTypeEntity:{fromId:((Le=ae==null?void 0:ae.entity)==null?void 0:Le.id)||"",toId:(($e=ue==null?void 0:ue.entity)==null?void 0:$e.id)||""},property:k,oldProperty:G}):(E.set(k.id,{...E.get(k.id)||{property:k},nonCastableDataTypeEntity:{fromId:((ke=ae==null?void 0:ae.entity)==null?void 0:ke.id)||"",toId:((Ke=ue==null?void 0:ue.entity)==null?void 0:Ke.id)||""},property:k,oldProperty:G}),b=!0),H=!0);k.name!==(G==null?void 0:G.name)&&(E.set(k.id,{...E.get(k.id)||{},nameChange:{from:(G==null?void 0:G.name)||"",to:k.name},property:k,oldProperty:G}),H=!0);const de=_a(G.getDataType(null)),ce=_a(k.getDataType(null));return ce!==de&&(E.set(k.id,{...E.get(k.id)||{},requiredChange:{from:!de,to:!ce},property:k,oldProperty:G}),ce||(b=!0),H=!0),H}),g.length>0&&(b=!0);let L=null;m&&b&&(L=Ske(m,i,e).isPreexistingRowTransformerUpToDate);const j=i.name!==e.name?{from:e.name,to:i.name}:void 0;return{...r,changesSinceLastPublication:E.size>0||!!$.length||!!g.length||!!_.length||b,rowTransformerNeeded:b,newestOpenRowTransformer:m,nameChange:j,newRequiredProperties:g,newNonRequiredProperties:_,deletedProperties:$,lastPublishedEntityVersion:e,propChanges:E,newRowTransformerNeeded:b&&!m,isPreexistingRowTransformerUpToDate:L,extendedEntities:c}}function X$(l,p,i,r,a){if(!l)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(!r)throw new Error("[addDifferencesToRowTransformer] 'oldEntityState' argument is required");const c=Vn(i),e=Vn(r);p.afterAllChildrenInitialized(a);const f=p.methods.find(m=>{var E;return((E=m.implements)==null?void 0:E.id)===re["built-in-base-entity"].BUILT_IN_SQL_ROW_TRANSFORMER_ENTITY.methods.up.id}),h=p.methods.find(m=>{var E;return((E=m.implements)==null?void 0:E.id)===re["built-in-base-entity"].BUILT_IN_SQL_ROW_TRANSFORMER_ENTITY.methods.down.id});if(!f)throw new Error("[addDifferencesToRowTransformer] The 'up' transformer trigger is missing from the parent");if(!h)throw new Error("[addDifferencesToRowTransformer] The 'down' transformer trigger is missing from the parent");e.forEach(m=>{const E=f.inputs.find($=>$.name===m.name),b=m.getDataType(null);let g=E,_;if(E)g.editable=!0;else{const $=Na.new(a);$.parent=f.toReference(),$.name=m.name,$.index=m.index,$.implements=[...m.implements.map(j=>j.toJSON())];const L=Ae($,l);L.hydrateAncestors(),a.add(L,W.Added),L.addSelfToProject(a),L.initChildren(a),g=L}if(!g.dataType||g.dataType&&l.diggestedBuiltInBaseEntitiesIds.has(g.dataType.id)){const $=mr.new(a);$.parent=g.toReference();const L=Ae($,l);L.hydrateAncestors(),a.add(L,W.Added),L.addSelfToProject(a),L.initChildren(a),_=L}else _=g.dataType,_.editable=!0;b&&_.merge(m.getDataType(null),a),_.metaSync({editable:!1,deletable:!1},a),g.metaSync({editable:!1,deletable:!1},a)}),[...f.inputs].forEach(m=>{e.find(b=>b.name===m.name)||(m.editable=!0,m.remove({ignoreUpstream:!1},a),m.editable=!1)}),[...f.returnStatements].forEach(m=>{var E,b;if(!m.dataType||m.dataType&&l.diggestedBuiltInBaseEntitiesIds.has(m.dataType.id)){const g=mr.new(a);g.entity=i.toReference(),g.parent=m.toReference();const _=Ae(g,l);_.hydrateAncestors(),a.add(_,W.Added),_.addSelfToProject(a),_.initChildren(a)}(!((E=m.dataType)!=null&&E.entity)||m.dataType.entity.type!==d.DefinitionEntity||m.dataType.entity.parent.id!==m.dataType.id)&&i.clone(a,m.dataType),ex((b=m.dataType)==null?void 0:b.entity,i,a),m.afterAllChildrenInitialized(a),m.outputs.forEach(g=>{const _=f.inputs.find($=>se(g,l)===se($,l));g.setValueWriter(_,a),_==null||_.addValueReader(g,a)})}),c.forEach(m=>{var L;const E=(L=m.knownVersions)==null?void 0:L.get(m.previousVersion),b=h.inputs.find(j=>j.name===m.name||!!E&&E.name===j.name),g=m.getDataType(null);let _=b,$;if(b)_.editable=!0,_.metaSync({name:m.name,codeName:m.codeName,description:m.description},a);else{const j=Na.new(a);j.parent=h.toReference(),j.name=m.name,j.codeName=m.codeName,j.description=m.description,j.index=m.index,j.implements=[m.toJSON(),...m.implements.map(G=>G.toJSON())];const k=Ae(j,l);k.hydrateAncestors(),a.add(k,W.Added),k.addSelfToProject(a),k.initChildren(a),_=k}if(_.dataType)$=_.dataType,$.editable=!0,$.merge(_.dataType,a);else{const j=mr.new(a);j.parent=_.toReference();const k=Ae(j,l);k.hydrateAncestors(),a.add(k,W.Added),k.addSelfToProject(a),k.initChildren(a),$=k}g&&$.merge(m.getDataType(null),a),$.metaSync({editable:!1,deletable:!1},a),_.metaSync({editable:!1,deletable:!1},a)}),[...h.inputs].forEach(m=>{c.find(b=>{var _;if(b.name===m.name)return!0;const g=(_=b.knownVersions)==null?void 0:_.get(b.previousVersion);if(g&&g.name===m.name)return!0})||(m.editable=!0,m.remove({ignoreUpstream:!1},a),m.editable=!1)}),[...h.returnStatements].forEach(m=>{var b,g,_,$;if(!m.dataType||m.dataType&&l.diggestedBuiltInBaseEntitiesIds.has(m.dataType.id)){const L=mr.new(a);L.parent=m.toReference();const j=Ae(L,l);j.hydrateAncestors(),a.add(j,W.Added),j.addSelfToProject(a),j.initChildren(a)}let E=(b=m.dataType)==null?void 0:b.entity;(!E||(E==null?void 0:E.id)===re["built-in-base-entity"].BUILT_IN_PERSISTED_ENTITY_ENTITY.id)&&(z.Logger.log("Cloning old entity state into new project with data-ype as parent: ",(g=m.dataType)==null?void 0:g.id," from new project: ",((_=m.dataType)==null?void 0:_.project.version)===l.version&&(($=m.dataType)==null?void 0:$.project.entities.length)===3),E=r.clone(a,m.dataType)),m.dataType.setEntity(E,a),m.afterAllChildrenInitialized(a),m.outputs.forEach(L=>{const j=h.inputs.find(k=>se(L,l)===se(k,l));L.setValueWriter(j,a),j==null||j.addValueReader(L,a)})})}function Zke(l,p,i,r,a={}){var k;const c=l.getBuiltIn(Ie.SQL_ROW_TRANSFORMER),e=HR(se(p,l)+" row transformer",l.entities),f=c.implement(e,r),h=f.ownDeclaredProperties.find(G=>{var H;return(H=G.implements)==null?void 0:H.find(ie=>ie.id===re["built-in-base-entity"].BUILT_IN_SQL_ROW_TRANSFORMER_ENTITY.properties.definition.id)}),m=f.methods.find(G=>{var H;return((H=G.implements)==null?void 0:H.id)===re["built-in-base-entity"].BUILT_IN_SQL_ROW_TRANSFORMER_ENTITY.methods.up.id}),E=f.methods.find(G=>{var H;return((H=G.implements)==null?void 0:H.id)===re["built-in-base-entity"].BUILT_IN_SQL_ROW_TRANSFORMER_ENTITY.methods.down.id});if(!h||!m||!E)throw new Error("Cannot find definition property on the new row transformer entity");if(h.defaultValue)h.defaultValue.setValueAsTypeSingle(p,r);else{const G=Nr.new(r);G.name=ye.EntityTemplate,G.valueAsTypeSingle=p.toJSON(),G.parent=h.toReference();const H=Ae(G,l);H.hydrateAncestors(),r.add(H,W.Added),H.addSelfToProject(r),H.initChildren(r)}X$(l,f,p,i,r),z.Logger.log("BEFORE - changeSet.listAdded",r.listAdded.map(G=>{var ie,ee,ue,ae,de,ce,ne;const H=l.get(G.id);return H?se(H,l):G.type===d.InputMap?"(not found) "+G.type+" "+G.id+" - declaration: "+((ie=G.declaration)==null?void 0:ie.type)+" "+((ee=G.declaration)==null?void 0:ee.id)+' "'+((ue=G.declaration)==null?void 0:ue.name)+`"
480
480
  parent: `+((de=(ae=G.parent)==null?void 0:ae.parent)==null?void 0:de.id)+" - "+((ne=(ce=G.parent)==null?void 0:ce.parent)==null?void 0:ne.name):"(not found) "+G.type+" "+G.id})),z.Logger.log("AFTER - changeSet.listAdded",r.listAdded.map(G=>{var ie,ee,ue,ae,de,ce,ne;const H=l.get(G.id);return H?H.type+' "'+se(H,l)+'" ('+H.id+")":G.type===d.InputMap?"(not found) "+G.type+" ("+G.id+") - declaration: "+((ie=G.declaration)==null?void 0:ie.type)+" ("+((ee=G.declaration)==null?void 0:ee.id)+') "'+((ue=G.declaration)==null?void 0:ue.name)+`"
481
481
  parent: "`+((de=(ae=G.parent)==null?void 0:ae.parent)==null?void 0:de.name)+'" ('+((ne=(ce=G.parent)==null?void 0:ce.parent)==null?void 0:ne.id)+")":"(not found) "+G.type+" "+G.id})),z.Logger.log("-----------------"),z.Logger.log("Old properties: ",Vn(i).map(G=>G.name+" ("+G.id+")")),z.Logger.log("New properties: ",Vn(p).map(G=>G.name+" ("+G.id+")"));const b=f.methods.find(G=>{var H;return((H=G.implements)==null?void 0:H.id)===re["built-in-base-entity"].BUILT_IN_SQL_ROW_TRANSFORMER_ENTITY.methods.up.id}),g=f.methods.find(G=>{var H;return((H=G.implements)==null?void 0:H.id)===re["built-in-base-entity"].BUILT_IN_SQL_ROW_TRANSFORMER_ENTITY.methods.down.id});z.Logger.log(`
482
482
  Up inputs: `,b==null?void 0:b.inputs.map(G=>G.name+" ("+G.id+")")),z.Logger.log("Up method return statements:",b==null?void 0:b.returnStatements[0].outputs.map(G=>se(G,l)+" ("+G.id+")")),z.Logger.log(`
package/dist/index.js CHANGED
@@ -185898,7 +185898,10 @@ const V6 = {
185898
185898
  }, a = new vn(void 0, {
185899
185899
  allBuiltInEntityIds: this.diggestedBuiltInBaseEntitiesIds
185900
185900
  });
185901
- a.flatRecord = this.instances, a.order = Object.keys(a.flatRecord), a.orderEntities();
185901
+ a.flatRecord = {};
185902
+ for (const f of Object.values(this.instances))
185903
+ this.diggestedBuiltInBaseEntitiesIds.has(f.id) || (a.flatRecord[f.id] = f);
185904
+ a.order = Object.keys(a.flatRecord), a.orderEntities();
185902
185905
  const c = {}, e = [];
185903
185906
  return a.visit((f) => {
185904
185907
  try {
@@ -185924,7 +185927,10 @@ const V6 = {
185924
185927
  }, a = Se.from(r), c = new vn(void 0, {
185925
185928
  allBuiltInEntityIds: this.diggestedBuiltInBaseEntitiesIds
185926
185929
  });
185927
- c.flatRecord = this.instances, c.order = Object.keys(c.flatRecord);
185930
+ c.flatRecord = {};
185931
+ for (const h of Object.values(this.instances))
185932
+ await a.tick(), !this.diggestedBuiltInBaseEntitiesIds.has(h.id) && (c.flatRecord[h.id] = h);
185933
+ c.order = Object.keys(c.flatRecord);
185928
185934
  const e = [];
185929
185935
  if (r.seenEntityMaps)
185930
185936
  for (const h of c.order) {
@@ -185966,7 +185972,10 @@ const V6 = {
185966
185972
  }, a = Se.from(r), c = new vn(void 0, {
185967
185973
  allBuiltInEntityIds: this.diggestedBuiltInBaseEntitiesIds
185968
185974
  });
185969
- c.flatRecord = this.instances, c.order = Object.keys(c.flatRecord);
185975
+ c.flatRecord = {};
185976
+ for (const h of Object.values(this.instances))
185977
+ await a.tick(), !this.diggestedBuiltInBaseEntitiesIds.has(h.id) && (c.flatRecord[h.id] = h);
185978
+ c.order = Object.keys(c.flatRecord);
185970
185979
  const e = [];
185971
185980
  if (r.seenEntityMaps)
185972
185981
  for (const h of c.order) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elyx-code/project-logic-tree",
3
- "version": "0.0.6843",
3
+ "version": "0.0.6844",
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",