@elyx-code/project-logic-tree 0.0.7117 → 0.0.7118
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +1 -1
- package/dist/index.js +2 -0
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -623,7 +623,7 @@ This is likely an incorrect strategy, either the '${this.type}' entity doesn't n
|
|
|
623
623
|
You can inspect the existing 'entity' field with the 'describe_entity' action. Like so:
|
|
624
624
|
${ff({describe_entity:b.entity.id})}
|
|
625
625
|
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 _([...this.ownDeclaredMethods,...this.allBaseMethodsFromOriginalParents])}get allProperties(){return _([...this.ownDeclaredProperties,...this.allBasePropertiesFromOriginalParents])}get allBaseMethodsFromOriginalParents(){var a;const i=((a=this.extends)==null?void 0:a.type)===l.DefinitionEntity?this.extends.allMethods:[],n=[...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 _([...n,...this.implements.flatMap(c=>{const e=c.type===l.DefinitionEntity?[...c.allMethods]:[];return[...e].filter(h=>!e.some(m=>{var T,g;return m.id!==h.id&&(((T=m.implements)==null?void 0:T.id)===h.id||((g=m.extends)==null?void 0:g.id)===h.id)}))})])}get allBasePropertiesFromOriginalParents(){var c;const i=((c=this.extends)==null?void 0:c.allProperties)||[],n=[...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 _([...n,...this.implements.flatMap(e=>{const f=[...e.allProperties];return[...f].filter(m=>!f.some(T=>{var g;return T.id!==m.id&&(!!T.implements.find(b=>b.id===m.id)||((g=T.extends)==null?void 0:g.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),n=[...i].filter(f=>!i.some(h=>{var m;return h.id!==f.id&&(!!h.implements.find(T=>T.id===f.id)||((m=h.extends)==null?void 0:m.id)===f.id)})),a=this.implements.reduce((f,h)=>{const m=h.implementedPropertiesFromOriginalParents,T=[...h.ownDeclaredProperties].filter(R=>!R.abstract),g=[...m,...T,...f];return[...g].filter(R=>!!!g.find(C=>{var N;return!!C.implements.find($=>$.id===R.id)||((N=C.extends)==null?void 0:N.id)===R.id}))},[]);return _([...n,...a])}get allBaseMethodsFromExtendedAndImplementedEntities(){return _([...(this.extends?[this.extends]:[]).reduce((i,n)=>n.type!==l.DefinitionEntity?[]:[...[...n.ownDeclaredMethods,...n.allBaseMethodsFromExtendedAndImplementedEntities].filter(c=>c.type!==l.ActionDescriptor),...i],[]),...this.implements.reduce((i,n)=>n.type!==l.DefinitionEntity?n.abstractMethods:[...[...n.ownDeclaredMethods,...n.allBaseMethodsFromExtendedAndImplementedEntities].filter(c=>c.type!==l.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),n=[...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 _(n)}get implementedPropertiesFromOriginalParents(){return _([...(this.extends?[this.extends]:[]).reduce((i,n)=>{const a=n.implementedPropertiesFromOriginalParents,c=[...n.ownDeclaredProperties].filter(h=>!!h.abstract),e=[...a,...c,...i];return[...e].filter(h=>!!!e.find(T=>{var g;return((g=T.extends)==null?void 0:g.id)===h.id||!!T.implements.find(b=>b.id===h.id)}))},[]),...this.implements.reduce((i,n)=>{const a=n.implementedPropertiesFromOriginalParents,c=[...n.ownDeclaredProperties].filter(h=>!!h.abstract),e=[...a,...c,...i];return[...e].filter(h=>!!!e.find(T=>{var g;return!!T.implements.find(b=>b.id===h.id)||((g=T.extends)==null?void 0:g.id)===h.id}))},[])].filter(i=>!!i.abstract))}get extendedMethodsFromOriginalParents(){return _((this.extends?[this.extends]:[]).reduce((i,n)=>{if(n.type!==l.DefinitionEntity)return[];const a=[...n.ownDeclaredMethods,...n.extendedMethodsFromOriginalParents].filter(c=>c.type!==l.ActionDescriptor);return[...i,...a]},[]))}get implementedMethodsFromOriginalParents(){return _([...(this.extends?[this.extends]:[]).reduce((i,n)=>{const a=n.type===l.DefinitionEntity?n.methods:[],c=[...n.abstractMethods].filter(e=>!a.find(f=>f.name===e.name));return[...a,...c,...i]},[]),...this.implements.reduce((i,n)=>[...n.abstractMethods,...i],[])].filter(i=>i.type===l.ActionDescriptor))}get extendedProperties(){return this.properties.filter(i=>i.isExtendedProperty)}get ownDeclaredProperties(){return this.properties.filter(n=>!n.isExtendedProperty)}get extendedMethods(){return this.methods.filter(i=>i.isExtendedMethod)}get ownDeclaredMethods(){return this.methods.filter(i=>!i.isExtendedMethod)}validateGeneratedUpdate(i){const n=[],a=[];return i.parent&&n.push(new ke({id:`${this.id}--${be.InvalidParentUpdate}`,code:be.InvalidParentUpdate,severity:De.Error,message:`Entity of type '${this.type}' with id '${this.id}' cannot have the 'parent' property updated. The 'parent' on an '${this.type}', must be the root project as it is a globally declared entity.`})),{errors:n,explanations:a,modifiedData:i}}subscribeDependents(i){return i.forEach(n=>{this.detachedDependents[n.entity.id]||(this.detachedDependents[n.entity.id]=n)}),this}unsubscribeDependents(i){return i.forEach(n=>{this.detachedDependents[n.entity.id]&&delete this.detachedDependents[n.entity.id]}),this}syncDependents(i=this.project.addChangeSet(new ee(this.project,M.sessionAuthor,j().toISOString(),this,!0,"sync-dependents"))){const n=[],a=[],c=[],e=[];return Object.values(this.detachedDependents).forEach(f=>{const h=f.entity.afterAllChildrenInitialized(i);n.push(...h.updated),a.push(...h.added),c.push(...h.removed),e.push(...h.affected)}),i==null||i.attemptAutoclose("sync-dependents",this.id),{updated:_(n),added:_(a),removed:_(c),affected:_(e),self:this}}onDetachedDependencyRemoved(i,n,a){const c=[],e=[],f=[],h=[];return n==="implements"&&(this.removeImplementation(i,a),c.push(this)),n==="extends"&&(this.setExtension(null,a),c.push(this)),{updated:_(c),added:_(e),removed:_(f),affected:_(h),self:this}}onDetachedDependencyRestored(i,n,a){const c=[],e=[],f=[],h=[];return n==="implements"&&(this.addImplementation(i,a),c.push(this)),n==="extends"&&(this.setExtension(i,a),c.push(this)),{updated:_(c),added:_(e),removed:_(f),affected:_(h),self:this}}unsubscribeFromDependencies(){return this.implements.forEach(i=>{Ss.includes(i.type)||i.unsubscribeDependents([{entity:this,field:"implements"}])}),this.extends&&(Ss.includes(this.extends.type)||this.extends.unsubscribeDependents([{entity:this,field:"extends"}])),this}subscribeToDependencies(){return this.implements.forEach(i=>{Ss.includes(i.type)||i.subscribeDependents([{entity:this,field:"implements"}])}),this.extends&&(Ss.includes(this.extends.type)||this.extends.subscribeDependents([{entity:this,field:"extends"}])),this}increaseVersion(i){var n;if(this.project.diggestedBuiltInBaseEntitiesIds.has(this.id))return this;if(i&&!j(i).isValid())throw new Error(`The shared timestamp '${i}' is not a valid ISO 8601 date string.`);if(i&&j(i).isSame(j(this.createdAt)))return this;if(!((n=this.knownVersions)!=null&&n.has(this.version))&&this.project.initialized)throw new Error(`The current ${this.type} ${this.id} version '${this.version}' is not captured in the 'knownVersions' map. Capture the current version before increasing it to avoid losing data.`);if(!this.activeVersion)throw new Error(`Only active versions can be increased. Entity with id '${this.id}' and version '${this.version}' is not active.`);return this.previousVersion=this.version,this.version=M.UUID.uuid(),this.createdAt=j(i).toISOString()||j().toISOString(),this}captureVersion(){var n;const i=((n=this.knownVersions)==null?void 0:n.get(this.version))||new Cn(this,this.project);if(!this.activeVersion)throw new Error(`Only active versions can be captured. Entity of type ${this.type} with id '${this.id}' and version '${this.version}' is not active.`);if(this.version!==i.version)throw new Error(`Captured ${this.type} with id '${this.id}', version '${i.version}' does not match current entity version '${this.version}'.`);return this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,i):new Map().set(this.version,i),this.apply(i),this}snapshot(){const i=new Cn(this,this.project);return this.apply(i)}apply(i){const n=this.toMeta();return i.metaSync(n,null),i.properties=[...this.properties],i.methods=[...this.methods],i.abstractMethods=[...this.abstractMethods],i.extends=this.extends,i.implements=[...this.implements],i.allPropertiesImplement=this.allPropertiesImplement,i.additionalPropertiesDataType=this.additionalPropertiesDataType,i.parent=this.parent,i}recursiveCaptureUpstreamVersions(i){const n=[],a=[],c=[],e=[];if(this.parent){this.parent.increaseVersion(i);const f=this.parent.recursiveCaptureUpstreamVersions(i);n.push(this.parent,...f.updated),a.push(...f.added),c.push(...f.removed)}return{updated:_(n),added:_(a),removed:_(c),affected:_(e),self:this}}async restoreVersion(i,n){var m;const a=[],c=[],e=[],f=[];if(this.version===i&&(n!=null&&n.skipIfSameVersion))return{updated:_(a),added:_(c),removed:_(e),affected:_(f),self:this};if(!this.knownVersions){const T=new Map;for(const[g,b]of this.knownVersions||new Map){if(T.set(g,b),b.activeVersion=!1,b.knownVersions)for(const[R,I]of b.knownVersions)T.set(R,I);b.knownVersions=null}}let h=(m=this.knownVersions)==null?void 0:m.get(i);if(!h){const T=await this.APILoadVersion({},i);if(!T)throw new Error(`Version with id '${i}' for entity with id '${this.id}' not found.`);h=new Cn(T,this.project)}return this.metaSync(h.toShallowJSON(),null),this.previousVersion=h.previousVersion,this.version=h.version,this.createdAt=h.createdAt,this.author=h.author,this.deleted=h.deleted,this.properties=[...h.properties],this.methods=[...h.methods],this.abstractMethods=[...h.abstractMethods],this.extends=h.extends,this.implements=[...h.implements],this.allPropertiesImplement=h.allPropertiesImplement,this.additionalPropertiesDataType=h.additionalPropertiesDataType,this.parent=h.parent,{updated:_(a),added:_(c),removed:_(e),affected:_(f),self:this}}updateWithShallowTransfer(i,n=this.project.addChangeSet(new ee(this.project,M.sessionAuthor,j().toISOString(),this,!0,P.UpdateWithShallowTransfer))){if(!this.checkCanEdit(this,n))return se.Logger.warn(`[updateWithShallowTransfer] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),n==null||n.attemptAutoclose(P.UpdateWithShallowTransfer,this.id),this;if(this.metaSync(i,n),this.version=i.version,this.createdAt=i.createdAt,this.author=i.author,this.deleted=i.deleted,this.previousVersion=i.previousVersion,this.unsubscribeFromDependencies(),i.parent){const f=pe(i.parent),h=this.project.get(f),m=this.parent;if(m&&m.id!==(h==null?void 0:h.id)&&this.removeFromParent(n),h)this.setParent(h,n),this.addSelfToProject(n);else throw n==null||n.attemptAutoclose(P.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 n==null||n.attemptAutoclose(P.UpdateWithShallowTransfer,this.id),new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(i.extends){const f=pe(i.extends),h=this.project.get(f);h&&this.setExtension(h,n)}else this.setExtension(null,n);if(i.implements.forEach(f=>{const h=pe(f),m=this.project.get(h);if(m)this.addImplementation(m,n);else throw new Error(`${Rr(this.type)} with id '${this.id}' has a 'implements' reference "${h}" which is missing in the project`)}),this.implements.filter(f=>{const h=pe(f);return!i.implements.find(m=>pe(m)===h)}).forEach(f=>{this.removeImplementation(f,n)}),i.methods.forEach(f=>{const h=pe(f),m=this.project.get(h);m&&this.addMethod(m,n)}),this.methods.filter(f=>{const h=pe(f);return!i.methods.find(m=>pe(m)===h)}).forEach(f=>{this.removeMethod(f,n)}),i.properties.forEach(f=>{const h=pe(f),m=this.project.get(h);m&&this.addProperty(m,n)}),this.properties.filter(f=>{const h=pe(f);return!i.properties.find(m=>pe(m)===h)}).forEach(f=>{this.removeProperty(f,n)}),i.allPropertiesImplement){const f=pe(i.allPropertiesImplement),h=this.project.get(f);h&&this.setAllPropertiesImplement(h,n)}else this.setAllPropertiesImplement(null,n);if(i.additionalPropertiesDataType){const f=pe(i.additionalPropertiesDataType),h=this.project.get(f);h&&this.setAdditionalPropertiesDataType(h,n)}else this.setAdditionalPropertiesDataType(null,n);return this.captureVersion(),this.subscribeToDependencies(),n==null||n.attemptAutoclose(P.UpdateWithShallowTransfer,this.id),this}updateWithGenerationTarget(i,n=this.project.addChangeSet(new ee(this.project,M.sessionAuthor,j().toISOString(),this,!0,P.UpdateWithGenerationTarget))){var a;if(!this.checkCanEdit(this,n))return se.Logger.warn(`[updateWithGenerationTarget] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),n==null||n.attemptAutoclose(P.UpdateWithGenerationTarget,this.id),this;if(this.metaSync(i,n),i.parent){const c=pe(i.parent),e=this.project.get(c),f=this.parent;if(f&&f.id!==(e==null?void 0:e.id)&&this.removeFromParent(n),e)this.setParent(e,n),this.addSelfToProject(n);else throw n==null||n.attemptAutoclose(P.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=pe(i.extends),e=this.project.get(c);if(e)this.setExtension(e,n);else throw new Error(`${Rr(this.type)} with id '${this.id}' has an 'extends' reference "${c}" which is missing in the project`)}else i.extends===null&&this.setExtension(null,n);return(a=i.implements)==null||a.forEach(c=>{const e=pe(c),f=this.project.get(e);if(f)this.addImplementation(f,n);else throw new Error(`${Rr(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=pe(e);return!(i.implements||[]).find(h=>pe(h)===f)}).forEach(e=>{this.removeImplementation(e,n)}),this.captureVersion(),this.subscribeToDependencies(),n==null||n.attemptAutoclose(P.UpdateWithGenerationTarget,this.id),this}hydrateAncestors(){const i=[],n=[],a=[],c=[];if(this.initialData.parent){const e=pe(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=pe(this.initialData.extends),f=this.project.get(e);f&&(this.setExtension(f,null),f.type!==l.BuiltInBaseEntity&&i.push(f))}return this.initialData.implements.forEach(e=>{const f=pe(e),h=this.project.get(f);if(h)this.addImplementation(h,null),h.type!==l.BuiltInBaseEntity&&i.push(h);else throw new Error(`${Rr(this.type)} with id '${this.id}' has a 'implements' reference "${f}" which is missing in the project`)}),{updated:_(i),added:_(n),removed:_(a),affected:_(c),self:this}}afterAllChildrenInitialized(i=this.project.addChangeSet(new ee(this.project,M.sessionAuthor,j().toISOString(),this,!0,P.AfterAllChildrenInitialized))){if(!this.checkCanEdit(this,i))return se.Logger.warn(`[afterAllChildrenInitialized] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(P.AfterAllChildrenInitialized,this.id),{updated:[],added:[],removed:[],affected:[],self:this};const n=[],a=[],c=[],e=[];this.initialized=!0;const{updated:f,added:h,removed:m,affected:T}=this.syncImplementationProperties(i);n.push(...f),a.push(...h),c.push(...m),e.push(...T);const{updated:g,added:b,removed:R,affected:I}=this.addExtendedProperties(i);n.push(...g),a.push(...b),c.push(...R),e.push(...I);const{updated:C,added:N,removed:$}=this.removeUnrecognizedProperties(i);n.push(...C),a.push(...N),c.push(...$);const{updated:x,added:G,removed:K,affected:Z}=this.syncImplementationMethods(i);n.push(...x),a.push(...G),c.push(...K),e.push(...Z);const{updated:H,added:W,removed:Q,affected:ne}=this.addExtendedMethods(i);n.push(...H),a.push(...W),c.push(...Q),e.push(...ne);const{updated:Y,added:J,removed:te}=this.removeUnrecognizedMethods(i);n.push(...Y),a.push(...J),c.push(...te),this.addSuggestions(),this.properties.forEach(ce=>{this.static&&!ce.static&&ce.metaSync({static:!0},i),this.abstract&&!ce.abstract&&ce.metaSync({abstract:!0},i)}),this.properties.sort((ce,Te)=>ce.index-Te.index);let oe=this.project.getDefinitionEntities(new Set([this.id])).filter(ce=>ce.id!==this.id&&ce.name.toLowerCase()===this.name.toLowerCase());if(oe.length&&(this.parent.type===l.Project&&(oe.filter(Te=>Te.parent.type!==l.Project).forEach(Te=>{lHe(Te,i)}),oe=oe.filter(Te=>Te.name.toLowerCase()===this.name.toLowerCase())),oe.length)){const ce=lc(this.name,oe);this.metaSync({name:ce},i)}return i==null||i.attemptAutoclose(P.AfterAllChildrenInitialized,this.id),{updated:_(n),added:_(a),removed:_(c),affected:_(e),self:this}}addSelfToProject(i=this.project.addChangeSet(new ee(this.project,M.sessionAuthor,j().toISOString(),this,!0,"add-self-to-project"))){const n=[this],a=[],c=[],e=[];if(this.parent.type===l.DataType){const f=this.parent;f.entity=this,n.push(f)}else this.project.addDefinitionEntity(this);return this.subscribe(),this.subscribeToDependencies(),i==null||i.attemptAutoclose("add-self-to-project",this.id),{updated:_(n),added:_(a),removed:_(c),affected:_(e),self:this}}setParent(i,n=this.project.addChangeSet(new ee(this.project,M.sessionAuthor,j().toISOString(),this,!0,P.SetParent))){var a;return this.checkCanEditWithCounterpartAndSideEffects(this,i,P.SetParent,n)?(((a=this.parent)==null?void 0:a.id)!==(i==null?void 0:i.id)&&(this.parent=i,n&&(n==null||n.add(this,re.Updated))),n==null||n.attemptAutoclose(P.SetParent,this.id),this):this}setExtension(i,n=this.project.addChangeSet(new ee(this.project,M.sessionAuthor,j().toISOString(),this,!0,P.SetExtension))){var a;return this.checkCanEdit(this,n)?(((a=this.extends)==null?void 0:a.id)!==(i==null?void 0:i.id)&&(this.extends=i,this.subscribeToDependencies(),n&&(n==null||n.add(this,re.Updated))),n==null||n.attemptAutoclose(P.SetExtension,this.id),this):(se.Logger.warn(`[setExtension] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),n==null||n.attemptAutoclose(P.SetExtension,this.id),this)}addImplementation(i,n=this.project.addChangeSet(new ee(this.project,M.sessionAuthor,j().toISOString(),this,!0,P.AddImplementation))){return this.checkCanEdit(this,n)?(this.implements.includes(i)||(this.implements.push(i),this.subscribeToDependencies(),n==null||n.add(this,re.Updated)),n==null||n.attemptAutoclose(P.AddImplementation,this.id),this):(se.Logger.warn(`[addImplementation] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),n==null||n.attemptAutoclose(P.AddImplementation,this.id),this)}removeImplementation(i,n=this.project.addChangeSet(new ee(this.project,M.sessionAuthor,j().toISOString(),this,!0,P.RemoveImplementation))){return this.checkCanEdit(this,n)?(this.implements.includes(i)&&(this.implements=this.implements.filter(a=>a.id!==i.id),n==null||n.add(this,re.Updated)),n==null||n.attemptAutoclose(P.RemoveImplementation,this.id),this):(se.Logger.warn(`[removeImplementation] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),n==null||n.attemptAutoclose(P.RemoveImplementation,this.id),this)}removeProperty(i,n=this.project.addChangeSet(new ee(this.project,M.sessionAuthor,j().toISOString(),this,!0,P.RemoveProperty))){return this.checkCanEdit(this,n)?(this.properties.includes(i)&&(this.properties=this.properties.filter(a=>a.id!==i.id),n==null||n.add(this,re.Updated)),n==null||n.attemptAutoclose(P.RemoveProperty,this.id),this):(se.Logger.warn(`[removeProperty] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),n==null||n.attemptAutoclose(P.RemoveProperty,this.id),this)}addMethod(i,n=this.project.addChangeSet(new ee(this.project,M.sessionAuthor,j().toISOString(),this,!0,P.AddMethod))){return this.checkCanEdit(this,n)?(this.methods.includes(i)||(this.methods.push(i),this.suggestedMethods=this.suggestedMethods.filter(a=>a.name!==i.name),n==null||n.add(this,re.Updated)),n==null||n.attemptAutoclose(P.AddMethod,this.id),this):(se.Logger.warn(`[addMethod] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),n==null||n.attemptAutoclose(P.AddMethod,this.id),this)}removeMethod(i,n=this.project.addChangeSet(new ee(this.project,M.sessionAuthor,j().toISOString(),this,!0,P.RemoveMethod))){return this.checkCanEdit(this,n)?(this.methods.includes(i)&&(this.methods=this.methods.filter(a=>a.id!==i.id),n==null||n.add(this,re.Updated)),n==null||n.attemptAutoclose(P.RemoveMethod,this.id),this):(se.Logger.warn(`[removeMethod] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),n==null||n.attemptAutoclose(P.RemoveMethod,this.id),this)}addProperty(i,n=this.project.addChangeSet(new ee(this.project,M.sessionAuthor,j().toISOString(),this,!0,P.AddProperty))){return this.checkCanEdit(this,n)?(this.properties.includes(i)||(this.properties.push(i),this.suggestedProperties=this.suggestedProperties.filter(a=>a.name!==i.name),n==null||n.add(this,re.Updated)),n==null||n.attemptAutoclose(P.AddProperty,this.id),this):(se.Logger.warn(`[addProperty] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),n==null||n.attemptAutoclose(P.AddProperty,this.id),this)}addSuggestedProperty(i){return this.suggestedProperties.includes(i)||this.suggestedProperties.push(i),this}addSuggestedMethod(i){return this.suggestedMethods.includes(i)||this.suggestedMethods.push(i),this}removeSuggestedProperty(i){return this.suggestedProperties=this.suggestedProperties.filter(n=>n.id!==i.id),this}removeSuggestedMethod(i){return this.suggestedMethods=this.suggestedMethods.filter(n=>n.id!==i.id),this}addAbstractMethod(i,n=this.project.addChangeSet(new ee(this.project,M.sessionAuthor,j().toISOString(),this,!0,P.AddAbstractMethod))){return this.checkCanEdit(this,n)?(this.abstractMethods.includes(i)||(this.abstractMethods.push(i),n==null||n.add(this,re.Updated)),n==null||n.attemptAutoclose(P.AddAbstractMethod,this.id),this):(se.Logger.warn(`[addAbstractMethod] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),n==null||n.attemptAutoclose(P.AddAbstractMethod,this.id),this)}removeAbstractMethod(i,n=this.project.addChangeSet(new ee(this.project,M.sessionAuthor,j().toISOString(),this,!0,P.RemoveAbstractMethod))){return this.checkCanEdit(this,n)?(this.abstractMethods.includes(i)&&(this.abstractMethods=this.abstractMethods.filter(a=>a.id!==i.id),n==null||n.add(this,re.Updated)),n==null||n.attemptAutoclose(P.RemoveAbstractMethod,this.id),this):(se.Logger.warn(`[removeAbstractMethod] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),n==null||n.attemptAutoclose(P.RemoveAbstractMethod,this.id),this)}initChildren(i=this.project.addChangeSet(new ee(this.project,M.sessionAuthor,j().toISOString(),this,!0,"init-children"))){if(this.initialized||this.startedInitialization)return this;if(this.startedInitialization=!0,this.properties=this.initialData.properties.map(n=>{const a=Oe(n,this.project);return a.setParent(this,null),a.initChildren(i),a}),this.methods=this.initialData.methods.map(n=>{const a=Oe(n,this.project);return a.setParent(this,null),a.initChildren(i),a}),this.abstractMethods=this.initialData.abstractMethods.map(n=>{const a=Oe(n,this.project);return a.setParent(this,null),a.initChildren(i),a}),this.initialData.extends&&(this.extends=Oe(this.initialData.extends,this.project)),this.implements=this.initialData.implements.map(n=>Oe(n,this.project)),this.initialData.allPropertiesImplement){const n=Oe(this.initialData.allPropertiesImplement,this.project);n.setParent(this,null),n.initChildren(null),this.setAllPropertiesImplement(n,i)}if(this.initialData.additionalPropertiesDataType){const n=Oe(this.initialData.additionalPropertiesDataType,this.project);n.setParent(this,null),n.initChildren(null),this.setAdditionalPropertiesDataType(n,i)}return this.subscribeToDependencies(),this.afterAllChildrenInitialized(i),i==null||i.attemptAutoclose("init-children",this.id),this}removeUnrecognizedProperties(i=this.project.addChangeSet(new ee(this.project,M.sessionAuthor,j().toISOString(),this,!0,"remove-unrecognized-properties"))){const n=[],a=[],c=[],e=[];let f=[...this.properties];f=f.filter(g=>g.parent.id===this.id),f=f.filter(g=>!g.isExtendedProperty);const h=this.implementedPropertiesFromOriginalParents,m=this.getAllPropertiesImplements();return f.filter(g=>this.interactive&&!g.implements.length?!1:!g.implements.find(R=>!!h.find(I=>I.id===R.id)||!!m.find(I=>I.id===R.id))).forEach(g=>{const b=g.remove({ignoreUpstream:!1},i);c.push(...b.removed),n.push(...b.updated)}),i==null||i.attemptAutoclose("remove-unrecognized-properties",this.id),{updated:_(n),added:_(a),removed:_(c),affected:_(e),self:this}}removeUnrecognizedMethods(i=this.project.addChangeSet(new ee(this.project,M.sessionAuthor,j().toISOString(),this,!0,"remove-unrecognized-methods"))){const n=[],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(T=>{var g;return T.id===((g=m.implements)==null?void 0:g.id)})),f.forEach(m=>{const T=m.remove({ignoreUpstream:!1},i);c.push(...T.removed),n.push(...T.updated)}),i==null||i.attemptAutoclose("remove-unrecognized-methods",this.id),{updated:_(n),added:_(a),removed:_(c),affected:_(e),self:this}}syncImplementationMethods(i=this.project.addChangeSet(new ee(this.project,M.sessionAuthor,j().toISOString(),this,!0,"sync-implementation-methods"))){const n=[],a=[],c=[],e=[],f=this.methods,h=this.implementedMethodsFromOriginalParents,m=[...this.allBaseMethodsFromExtendedAndImplementedEntities,...f];return h.filter(g=>!m.find(R=>{var I;return((I=R.implements)==null?void 0:I.id)===g.id})).forEach(g=>{if(this.methods.find(C=>{var N;return((N=C.implements)==null?void 0:N.id)===g.id}))return;const R=this.methods.find(C=>{var K,Z;if(C.name===g.name&&!C.implements)return!0;const N=ki(this,Ie.CRON_JOB),$=ki(this,Ie.HTTP_ENDPOINT),x=((K=C.implements)==null?void 0:K.id)===B["built-in-base-entity"].BUILT_IN_HTTP_ENDPOINT_ENTITY.methods.handler.id,G=((Z=C.implements)==null?void 0:Z.id)===B["built-in-base-entity"].BUILT_IN_CRON_JOB_ENTITY.methods.handler.id;return!!(N&&!G&&!$&&x||$&&!x&&!N&&G)});if(R&&R.type===l.FunctionDeclaration){R.setImplements(g,i),R.metaSync({name:g.name},i),i==null||i.add(R,re.Updated),i==null||i.add(this,re.Updated);return}const I=g.implementAsFunctionDeclaration(i,this);a.push(I),i==null||i.add(I,re.Added),this.addMethod(I,i)}),this.methods.sort((g,b)=>g.index-b.index).forEach(g=>{g.afterAllChildrenInitialized(i)}),i==null||i.attemptAutoclose("sync-implementation-methods",this.id),{updated:_(n),added:_(a),removed:_(c),affected:_(e),self:this}}syncImplementationProperties(i=this.project.addChangeSet(new ee(this.project,M.sessionAuthor,j().toISOString(),this,!0,"sync-implementation-properties"))){const n=[],a=[],c=[],e=[],f=this.properties,h=this.implementedPropertiesFromOriginalParents.filter(T=>!this.allBasePropertiesFromExtendedAndImplementedEntities.find(b=>!!b.implements.find(R=>R.id===T.id))),m=[...this.allBasePropertiesFromExtendedAndImplementedEntities,...f];return h.forEach(T=>{const g=m.find(C=>!!C.implements.find(N=>N.id===T.id));if(g){const{updated:C,added:N,removed:$,affected:x}=g.syncWithImplementation(i);n.push(...C),a.push(...N),c.push(...$),e.push(...x);return}if(this.properties.find(C=>!!C.implements.find(N=>N.id===T.id)))return;const R=this.properties.find(C=>C.name===T.name&&!!C.abstract&&!C.implements);if(R){R.addImplementation(T,i),R.metaSync({abstract:!1},i),R.afterAllChildrenInitialized(i);return}const I=T.implement(this,i,M.UUID.uuid());a.push(I),i==null||i.add(I,re.Added)}),this.properties.find(T=>{var g;return T.id===((g=this.allPropertiesImplement)==null?void 0:g.id)})&&this.removeAllPropertiesImplement(i),i==null||i.attemptAutoclose("sync-implementation-properties",this.id),{updated:_(n),added:_(a),removed:_(c),affected:_(e),self:this}}addExtendedMethods(i=this.project.addChangeSet(new ee(this.project,M.sessionAuthor,j().toISOString(),this,!0,"add-extended-methods"))){const n=[],a=[],c=[],e=[],f=this.methods,m=this.extendedMethodsFromOriginalParents.filter(g=>g.type===l.FunctionDeclaration),T=new Set(f.filter(g=>{var b;return!!((b=g.extends)!=null&&b.id)}).map(g=>g.extends.id));return m.forEach(g=>{if(T.has(g.id))return;T.add(g.id);const b=g.clone(i,this,M.UUID.uuid());b.setExtends(g,i),b.initChildren(i),a.push(b),i==null||i.add(b,re.Added),this.addMethod(b,i)}),i==null||i.attemptAutoclose("add-extended-methods",this.id),{updated:_(n),added:_(a),removed:_(c),affected:_(e),self:this}}addExtendedProperties(i=this.project.addChangeSet(new ee(this.project,M.sessionAuthor,j().toISOString(),this,!0,"add-extended-properties"))){const n=[],a=[],c=[],e=[],f=this.properties,h=this.extendedPropertiesFromOriginalParents,m=h.filter(g=>h.find(R=>!!R.implements.find(I=>I.id===g.id))?!1:!g.abstract),T=new Set(f.filter(g=>{var b;return!!((b=g.extends)!=null&&b.id)}).map(g=>g.extends.id));return m.forEach(g=>{if(T.has(g.id))return;T.add(g.id);const b=g.clone(i,this,M.UUID.uuid());b.setExtends(g,i),b.initChildren(i),a.push(b),i==null||i.add(b,re.Added),this.addProperty(b,i)}),[...this.properties].forEach(g=>{if(g.extends)return;if(m.find(R=>R.name===g.name&&R.implements.every(I=>!!g.implements.find(C=>C.id===I.id)))){const R=g.remove({ignoreUpstream:!1},i);c.push(...R.removed),n.push(...R.updated)}}),this.properties.forEach(g=>{const b=g.afterAllChildrenInitialized(i);n.push(...b.updated),e.push(...b.affected),a.push(...b.added),c.push(...b.removed)}),i==null||i.attemptAutoclose("add-extended-properties",this.id),{updated:_(n),added:_(a),removed:_(c),affected:_(e),self:this}}addSuggestions(){return this.implements.forEach(i=>{Mrt(this,i).forEach(c=>{const e=c.toJSON();e.id=`_suggestion--parent--${this.id}--${c.id}`;const f=Oe(e,this.project);f.suggestion=!0,f.setParent(this,null),f.initChildren(null),this.addSuggestedProperty(f)}),Urt(this,i).forEach(c=>{const e=`_suggestion--parent--${this.id}--${c.id}`,f=c.implementAsFunctionDeclaration(null,this,e),h=Oe(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(T=>{T.suggestion=!0})}this.addSuggestedMethod(h)})}),this}subscribe(){var i;return this.activeVersion=!0,(i=this.knownVersions)==null||i.forEach(n=>{n.version!==this.version&&(n.activeVersion=!1)}),this.project.subscribeInstance(this),this.project.subscribedDefinitionEntities.add(this.id),this}unsubscribe(){return this.project.unsubscribeInstance(this),this.project.subscribedDefinitionEntities.delete(this.id),this}metaSync(i,n=this.project.addChangeSet(new ee(this.project,M.sessionAuthor,j().toISOString(),this,!0,"meta-sync"))){const a=ma(this,i,n),c=ha(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,n),a.deleted===!0&&!e.deleted?n==null||n.add(this,re.Removed):a.deleted===!1&&e.deleted?n==null||n.add(this,re.Added):c&&(n==null||n.add(this,re.Updated)),n==null||n.attemptAutoclose("meta-sync",this.id),this}async APILoad(i=it,...n){return await Cn.repository.APILoad(this.id,...n),this}async APICreate(i=it,...n){return await Cn.repository.APICreate(this.toShallowJSON(),...n),this}async APIUpdate(i=it,...n){return await Cn.repository.APIUpdate(this.toShallowJSON(),...n),this}async APIDelete(i=it,...n){return await Cn.repository.APIDelete(this.toShallowJSON(),...n),this}async APIClone(i=it,...n){return await Cn.repository.APIClone(this.id,...n),this}async APILoadVersion(i=it,n,...a){return await Cn.repository.APILoadVersion(this.id,n,...a)}removeFromParent(i=this.project.addChangeSet(new ee(this.project,M.sessionAuthor,j().toISOString(),this,!0,P.RemoveFromParent))){if(!this.checkCanEdit(this,i))return se.Logger.warn(`[removeFromParent] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(P.RemoveFromParent,this.id),{added:[],updated:[],removed:[],affected:[],self:this};const n=[],a=[],c=[],e=[];if(this.parent.type===l.Project)this.parent.removeDefinitionEntity(this);else if(this.parent.type===l.DataType&&this.parent.entity&&this.parent.entity.id===this.id){const f=this.parent.setEntity(null,i);n.push(f)}return i==null||i.attemptAutoclose(P.RemoveFromParent,this.id),{added:_(c),updated:_(n),removed:_(a),affected:_(e),self:this}}remove({ignoreUpstream:i}={ignoreUpstream:!1},n=this.project.addChangeSet(new ee(this.project,M.sessionAuthor,j().toISOString(),this,!0,P.RemoveEntity))){var h;if(!this.checkCanDelete(this,n))return se.Logger.warn(`[remove] User is not allowed to delete or edit this ${this.type} entity with id: ${this.id}`),n==null||n.event({id:`${P.RemoveEntity}-${this.id}--${Ze.ActionOwnerEntityNonDeletable}`,action:P.RemoveEntity,owner:this,errorReason:Ze.ActionOwnerEntityNonDeletable,rootAction:((h=n==null?void 0:n.self)==null?void 0:h.id)===this.id&&(n==null?void 0:n.actionName)===P.RemoveEntity}),n==null||n.attemptAutoclose(P.RemoveEntity,this.id),{added:[],updated:[],removed:[],affected:[],self:this};const a=[],c=[],e=[],f=[];if(n!=null&&n.hasRemoved(this.id))return n==null||n.attemptAutoclose(P.RemoveEntity,this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(c.push(this),this.unsubscribe(),this.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},n),Object.values(this.detachedDependents).forEach(m=>{const{updated:T,removed:g,added:b}=m.entity.onDetachedDependencyRemoved(this,m.field,n);a.push(...T),c.push(...g),e.push(...b)}),this.properties.forEach(m=>{const{updated:T,removed:g}=m.remove({ignoreUpstream:!0},n);a.push(...T),c.push(...g)}),this.methods.forEach(m=>{const{updated:T,removed:g}=m.remove({ignoreUpstream:!0},n);a.push(...T),c.push(...g)}),this.abstractMethods.forEach(m=>{const{updated:T,removed:g}=m.remove({ignoreUpstream:!0},n);a.push(...T),c.push(...g)}),this.suggestedProperties.forEach(m=>{const{updated:T,removed:g}=m.remove({ignoreUpstream:!0},n);a.push(...T),c.push(...g)}),this.suggestedMethods.forEach(m=>{const{updated:T,removed:g}=m.remove({ignoreUpstream:!0},n);a.push(...T),c.push(...g)}),!i){const m=this.removeFromParent(n);e.push(...m.added),a.push(...m.updated),c.push(...m.removed),f.push(...m.affected)}return n==null||n.attemptAutoclose(P.RemoveEntity,this.id),{added:_(e),updated:_(a),removed:_(c),affected:_(f),self:this}}restore({}={},i=this.project.addChangeSet(new ee(this.project,M.sessionAuthor,j().toISOString(),this,!0,P.RestoreEntity))){if(!this.checkCanEdit(this,i))return se.Logger.warn(`[restore] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(P.RestoreEntity,this.id),{added:[],updated:[],removed:[],affected:[],self:this};const n=[],a=[],c=[],e=[];return i!=null&&i.hasAdded(this.id)?(i==null||i.attemptAutoclose(P.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:T}=f.entity.onDetachedDependencyRestored(this,f.field,i);a.push(...h),c.push(...m),n.push(...T)}),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(P.RestoreEntity,this.id),{added:_(n),updated:_(a),removed:_(c),affected:_(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 n,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:((n=this.allPropertiesImplement)==null?void 0:n.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=Rt){var a,c,e,f,h,m,T,g,b,R;let n;return(a=i.seenEntityMaps)!=null&&a.has(this.id)?n=i.seenEntityMaps.get(this.id):(n=i.newId||Ra(this,this.project,i.uuidStrategy),i.seenEntityMaps&&i.seenEntityMaps.set(this.id,n)),(c=i.seenEntities)!=null&&c.has(n)||(e=i.seenEntities)!=null&&e.has(this.id)?this.toReference({seenEntityMaps:i.seenEntityMaps}):((f=i.seenEntities)==null||f.add(n),(h=i.seenEntities)==null||h.add(this.id),{id:n,version:M.UUID.uuid(),createdAt:i.timestamp||j().toISOString(),author:M.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:((T=this.additionalPropertiesDataType)==null?void 0:T.toJSONClone(i))||null,properties:this.properties.map(I=>I.toJSONClone({...i,newId:null})),methods:this.methods.map(I=>I.toJSONClone({...i,newId:null})),abstractMethods:this.abstractMethods.map(I=>I.toJSONClone({...i,newId:null})),implements:this.implements.map(I=>I.type===l.BuiltInBaseEntity?I.toJSON(i.seenEntities):I.toJSONClone({...i,newId:null})),extends:((g=this.extends)==null?void 0:g.type)===l.BuiltInBaseEntity?(b=this.extends)==null?void 0:b.toJSON(i.seenEntities):(R=this.extends)==null?void 0:R.toJSONClone({...i,newId:null}),parent:this.parent.toReference({seenEntityMaps:i.seenEntityMaps})})}toReference(i=Rt){var a;let n=this.id;return(a=i.seenEntityMaps)!=null&&a.has(this.id)&&(n=i.seenEntityMaps.get(this.id)),{id:n+"--"+M.UUID.uuid()+"--ref",type:l.GenericReference,entityId:n,version:this.version,entityType:this.type}}toShallowJSON(i=Rt){var a,c,e,f;let n=this.id;return(a=i.seenEntityMaps)!=null&&a.has(this.id)&&(n=i.seenEntityMaps.get(this.id)),{id:n,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,name:this.name,codeName:this.codeName,description:this.description,type:this.type,editable:this.editable,deletable:this.deletable,x:this.x,y:this.y,static:this.static,abstract:this.abstract,additionalProperties:this.additionalProperties,allPropertiesImplement:((c=this.allPropertiesImplement)==null?void 0:c.toReference(i))||null,additionalPropertiesDataType:((e=this.additionalPropertiesDataType)==null?void 0:e.toReference(i))||null,properties:this.properties.map(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=Rt){var c,e,f;const n=this.parent.type===l.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:n}}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===l.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,n;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(),(n=this.allPropertiesImplement)==null||n.clearErrors(),this}validate(){return this.errors=Brt(this),{success:!0}}async validateAsync(i={}){const n=se.YieldTracker.from(i);return this.errors=await Grt(this,{tracker:n}),{success:!0}}getErrors(){var n,a;return[...this.errors,...this.properties.flatMap(c=>c.getErrors()),...this.methods.flatMap(c=>c.getErrors()),...this.abstractMethods.flatMap(c=>c.getErrors()),...((n=this.additionalPropertiesDataType)==null?void 0:n.getErrors())||[],...((a=this.allPropertiesImplement)==null?void 0:a.getErrors())||[]]}async getErrorsAsync(i={}){const n=se.YieldTracker.from(i),a=[...this.errors];await n.tick();for(const c of this.properties)a.push(...await c.getErrorsAsync({tracker:n}));for(const c of this.methods)a.push(...await c.getErrorsAsync({tracker:n}));for(const c of this.abstractMethods)a.push(...await c.getErrorsAsync({tracker:n}));return this.additionalPropertiesDataType&&a.push(...await this.additionalPropertiesDataType.getErrorsAsync({tracker:n})),this.allPropertiesImplement&&a.push(...await this.allPropertiesImplement.getErrorsAsync({tracker:n})),a}getShallowErrors(){return this.errors}clone(i=this.project.addChangeSet(new ee(this.project,M.sessionAuthor,j().toISOString(),this,!0,P.CloneEntity)),n=null,a=null,c=!0){var N,$,x;const e=na(n,this),f=this.toJSON(),h=a||M.UUID.uuid(),m=n||this.parent;f.properties=[],f.methods=[],f.abstractMethods=[];const T=h.split("-id"),g=T[T.length-1||0]||h;f.id=h,f.version=M.UUID.uuid(),f.createdAt=(i==null?void 0:i.timestamp)||j().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 b=lr(f,e);b.hydrateAncestors(),b.setParent(m,i),c&&(b.subscribe(),b.addSelfToProject(i)),b.initChildren(i),i==null||i.add(b,re.Added);const R=(N=this.properties)==null?void 0:N.map(G=>this.project.diggestedBuiltInBaseEntitiesIds.has(G.id)?G:G.clone(i,b,M.UUID.uuid(),c));b.properties=R;const I=($=this.methods)==null?void 0:$.map((G,K)=>this.project.diggestedBuiltInBaseEntitiesIds.has(G.id)?G:G.clone(i,b,g+"-method-"+K+"-id",c));b.methods=I;const C=(x=this.abstractMethods)==null?void 0:x.map((G,K)=>this.project.diggestedBuiltInBaseEntitiesIds.has(G.id)?G:G.clone(i,b,g+"-abstract-method-"+K+"-id",c));if(b.abstractMethods=C,this.additionalPropertiesDataType)if(this.project.diggestedBuiltInBaseEntitiesIds.has(this.additionalPropertiesDataType.id))b.setAdditionalPropertiesDataType(this.additionalPropertiesDataType,i);else{const G=this.additionalPropertiesDataType.clone(i,b,M.UUID.uuid(),c);b.setAdditionalPropertiesDataType(G,i)}if(this.allPropertiesImplement)if(this.project.diggestedBuiltInBaseEntitiesIds.has(this.allPropertiesImplement.id))b.setAllPropertiesImplement(this.allPropertiesImplement,i);else{const G=this.allPropertiesImplement.clone(i,b,M.UUID.uuid(),c);b.setAllPropertiesImplement(G,i)}return i||b.captureVersion(),i==null||i.attemptAutoclose(P.CloneEntity,this.id),b}getFunctionDeclaration(i){return this.methods.find(n=>n.id===i)}implement(i,n=this.project.addChangeSet(new ee(this.project,M.sessionAuthor,j().toISOString(),this,!0,"implement-definition-entity")),a){const c=Zw(this,i,n,a);return n==null||n.attemptAutoclose("implement-definition-entity",this.id),c}getAllPropertiesImplements(){var n;const i=[];return this.allPropertiesImplement&&i.push(this.allPropertiesImplement),i.push(...((n=this.extends)==null?void 0:n.getAllPropertiesImplements())||[],...this.implements.flatMap(a=>a.getAllPropertiesImplements())),i}getAllInteractiveMethods(){var e;const i=this.implements.filter(f=>f.type===l.DefinitionEntity||f.type===l.BuiltInBaseEntity&&f.interactive),n=((e=this.extends)==null?void 0:e.getAllInteractiveMethods())||[],a=i.flatMap(f=>f.getAllInteractiveMethods());return _([...this.methods,...n,...a])}inferFromInputs(i,n=this.project.addChangeSet(new ee(this.project,M.sessionAuthor,j().toISOString(),this,!0,"infer-definition-entity-from-inputs"))){const a=[],c=[],e=[],f=[];if(this.parent.type!==l.DataType||!this.parent.inferred)return n==null||n.attemptAutoclose("infer-definition-entity-from-inputs",this.id),{added:[],updated:[],removed:[],affected:[],self:this};const h=[];i.forEach(g=>{h.find(R=>me(R,this.project)===me(g,this.project))||h.push(g)});const m=this.properties.filter(g=>!g.dataType);h.forEach(g=>{var x,G,K;const b=m.find(Z=>me(Z,this.project)===me(g,this.project));if(!b)return;const I=Vr(g.parent).getMasterInputWithValueWriterFromAllInstances(g),C=Xp(I,n),N=C==null?void 0:C.clone(n,b,M.UUID.uuid(),!0);N&&((x=b.dataType)==null||x.merge(N,n),N.id!==((G=b.dataType)==null?void 0:G.id)&&N.remove({ignoreUpstream:!1},n),b.dataType&&(b.dataType.metaSync({inferred:!0,like:!0},n),b.setDataType(b.dataType,n),n==null||n.add(b,re.Affected)));let $=null;if(g.declaration&&b.id!==((K=g.declaration)==null?void 0:K.id)&&($=g.declaration),g.setDeclaration(b,n),n==null||n.add(g,re.Updated),$){const{updated:Z,removed:H}=$.remove({ignoreUpstream:!1},n);c.push(...Z),e.push(...H)}});const T=[];return h.forEach(g=>{if(!g.declaration){T.push(g);return}}),T.length===0?(n==null||n.attemptAutoclose("infer-definition-entity-from-inputs",this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(T.forEach(g=>{var K,Z,H,W,Q;const b=this.properties.find(ne=>me(ne,this.project)===me(g,this.project));if(b){if(g.setDeclaration(b,n),!b.getDataType(n)){const Y=Vr(g.parent).getMasterInputWithValueWriterFromAllInstances(g),J=Xp(Y),te=J==null?void 0:J.clone(n,b,M.UUID.uuid(),!0);te&&((K=b.dataType)==null||K.merge(te,n),te.id!==((Z=b.dataType)==null?void 0:Z.id)&&te.remove({ignoreUpstream:!1},n),b.dataType&&(b.dataType.metaSync({inferred:!0,like:!0},n),b.setDataType(b.dataType,n),n==null||n.add(b,re.Affected)))}return}const R=me(g,this.project),I=g.codeName||ec(g,this.project)||to(sr(R)),C=xl.new(n);C.parent=this.toReference(),C.index=g.index,C.name=R,C.codeName=I,C.description=g.description;const N=Oe(C,this.project);N.hydrateAncestors(),N.addSelfToProject(n),n==null||n.add(N,re.Added),N.setParent(this,n),N.initChildren(n),n||N.captureVersion();const x=Vr(g.parent).getMasterInputWithValueWriterFromAllInstances(g),G=Xp(x);if(G&&G.id!==((H=N.dataType)==null?void 0:H.id)){const ne=G==null?void 0:G.clone(n,N,M.UUID.uuid(),!0);ne&&((W=N.dataType)==null||W.merge(ne,n),ne.id!==((Q=N.dataType)==null?void 0:Q.id)&&ne.remove({ignoreUpstream:!1},n),N.dataType&&(N.dataType.metaSync({inferred:!0,like:!0},n),N.setDataType(N.dataType,n),n==null||n.add(N,re.Affected)))}return this.addProperty(N,n),g.setDeclaration(N,n),n==null||n.add(g,re.Updated),N}),n==null||n.attemptAutoclose("infer-definition-entity-from-inputs",this.id),{added:_(a),updated:_(c),removed:_(e),affected:_(f),self:this})}getRawDefaultValue(){const i={};return this.properties.forEach(n=>{var e;if(!LE(n)||!n.defaultValue)return;const a=me(n,this.project),c=n.codeName||ec(n,this.project)||to(sr(a));i[c]=((e=n.getDefaultValue())==null?void 0:e.value)||null}),i}getActiveRawDefaultValue(){const i={};return this.properties.forEach(n=>{var f;if(!LE(n))return;const a=me(n,this.project),c=n.codeName||ec(n,this.project)||to(sr(a)),e=(f=this.project.requestActiveDynamicValue(n,!0))==null?void 0:f.value;e&&(i[c]=(e==null?void 0:e.value)||null)}),i}setAdditionalPropertiesDataType(i,n=this.project.addChangeSet(new ee(this.project,M.sessionAuthor,j().toISOString(),this,!0,P.SetAdditionalPropertiesDataType))){if(!this.checkCanEdit(this,n))return se.Logger.warn(`[setAdditionalPropertiesDataType] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),n==null||n.attemptAutoclose(P.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},n),this.additionalPropertiesDataType=i,this.subscribeToDependencies(),n==null||n.add(this,re.Affected)),n==null||n.attemptAutoclose(P.SetAdditionalPropertiesDataType,this.id),this}removeAdditionalPropertiesDataType(i=this.project.addChangeSet(new ee(this.project,M.sessionAuthor,j().toISOString(),this,!0,P.RemoveAllPropertiesImplement))){return this.checkCanEdit(this,i)?(this.additionalPropertiesDataType&&(this.additionalPropertiesDataType.remove({ignoreUpstream:!0},i),i==null||i.add(this,re.Affected),this.additionalPropertiesDataType=null),i==null||i.attemptAutoclose(P.RemoveAllPropertiesImplement,this.id),this):(se.Logger.warn(`[removeAdditionalPropertiesDataType] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(P.RemoveAllPropertiesImplement,this.id),this)}setAllPropertiesImplement(i,n=this.project.addChangeSet(new ee(this.project,M.sessionAuthor,j().toISOString(),this,!0,P.SetAllPropertiesImplement))){if(!this.checkCanEdit(this,n))return se.Logger.warn(`[setAllPropertiesImplement] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),n==null||n.attemptAutoclose(P.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},n),this.allPropertiesImplement=i,this.subscribeToDependencies(),n==null||n.add(this,re.Affected)),n==null||n.attemptAutoclose(P.SetAllPropertiesImplement,this.id),this}removeAllPropertiesImplement(i=this.project.addChangeSet(new ee(this.project,M.sessionAuthor,j().toISOString(),this,!0,P.RemoveAllPropertiesImplement))){return this.checkCanEdit(this,i)?(this.allPropertiesImplement&&(this.properties.find(n=>{var a;return n.id===((a=this.allPropertiesImplement)==null?void 0:a.id)})||this.allPropertiesImplement.remove({ignoreUpstream:!0},i),i==null||i.add(this,re.Affected),this.allPropertiesImplement=null),i==null||i.attemptAutoclose(P.RemoveAllPropertiesImplement,this.id),this):(se.Logger.warn(`[removeAllPropertiesImplement] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(P.RemoveAllPropertiesImplement,this.id),this)}};D(Cn,"repository",{APICreate:async(i,...n)=>i,APIUpdate:async(i,...n)=>i,APIDelete:async(i,...n)=>i,APIClone:async(i,...n)=>{},APILoad:async(i,...n)=>null,APILoadVersion:async(i,n,...a)=>null}),D(Cn,"type",l.DefinitionEntity),D(Cn,"USER_MANAGED_PARENT_TYPES",[l.Project,l.DataType]),D(Cn,"PARENT_TYPES",[...Cn.USER_MANAGED_PARENT_TYPES]),D(Cn,"MUTABLE_BASE_PROPERTIES",["name","codeName","description","static","abstract","additionalProperties"]),D(Cn,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),D(Cn,"BASE_PROPERTIES",[...Cn.MUTABLE_BASE_PROPERTIES,...Cn.INMUTABLE_BASE_PROPERTIES]),D(Cn,"MUTABLE_META_PROPERTIES",[...Cn.MUTABLE_BASE_PROPERTIES,"x","y"]),D(Cn,"INMUTABLE_META_PROPERTIES",[...Cn.INMUTABLE_BASE_PROPERTIES]),D(Cn,"META_PROPERTIES",[...Cn.MUTABLE_META_PROPERTIES,...Cn.INMUTABLE_META_PROPERTIES]),D(Cn,"MUTABLE_UPSTREAM_PROPERTIES",["extends","implements"]),D(Cn,"INMUTABLE_UPSTREAM_PROPERTIES",["parent"]),D(Cn,"UPSTREAM_PROPERTIES",[...Cn.MUTABLE_UPSTREAM_PROPERTIES,...Cn.INMUTABLE_UPSTREAM_PROPERTIES]),D(Cn,"MUTABLE_DOWNSTREAM_PROPERTIES",["properties","methods","abstractMethods","allPropertiesImplement","additionalPropertiesDataType"]),D(Cn,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),D(Cn,"DOWNSTREAM_PROPERTIES",[...Cn.MUTABLE_DOWNSTREAM_PROPERTIES,...Cn.INMUTABLE_DOWNSTREAM_PROPERTIES]),D(Cn,"PROPERTIES",[...Cn.META_PROPERTIES,...Cn.UPSTREAM_PROPERTIES,...Cn.DOWNSTREAM_PROPERTIES]);let on=Cn;async function L9i(s,u={}){const i=se.YieldTracker.from(u),n=[],a=Pi(s.errors,n);return await i.tick(),a}function G9i(s){const u=[];return Pi(s.errors,u)}const b1=class b1 extends NG{constructor(i,n){super(i);D(this,"initialData");D(this,"id");D(this,"name");D(this,"description",null);D(this,"type",l.PrimitiveEntity);D(this,"static");D(this,"abstract");D(this,"properties",[]);D(this,"methods",[]);D(this,"abstractMethods",[]);D(this,"extends",null);D(this,"errors",[]);D(this,"project");this.initialData=i,this.project=n,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=Oe(a,this.project);return c.setParent(this,null),c.initChildren(null),c}),this.methods=this.initialData.methods.map(a=>{const c=Oe(a,this.project);return c.parent=this,c}),this.abstractMethods=this.initialData.abstractMethods.map(a=>{const c=Oe(a,this.project);return c.parent=this,c}),this.initialData.extends&&(this.extends=Oe(this.initialData.extends,this.project))}get allMethods(){return _([...this.ownDeclaredMethods,...this.allBaseMethodsFromOriginalParents])}get allProperties(){return _([...this.ownDeclaredProperties,...this.allBasePropertiesFromOriginalParents])}get allBaseMethodsFromOriginalParents(){var a;const i=((a=this.extends)==null?void 0:a.allMethods)||[],n=[...i].filter(c=>!i.some(e=>e.id!==c.id));return _(n)}get allBasePropertiesFromOriginalParents(){var a;const i=((a=this.extends)==null?void 0:a.allProperties)||[],n=[...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 _(n)}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),n=[...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 _(n)}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),n=[...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 _(n)}get implementedPropertiesFromOriginalParents(){return _([...(this.extends?[this.extends]:[]).reduce((i,n)=>{const a=n.implementedPropertiesFromOriginalParents,c=[...n.ownDeclaredProperties].filter(h=>!!h.abstract),e=[...a,...c,...i];return[...e].filter(h=>!!!e.find(T=>{var g;return((g=T.extends)==null?void 0:g.id)===h.id||T.implements.find(b=>b.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=it,...n){return await b1.repository.APILoad(this.id,...n),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 n;return i.has(this.id)?this.toReference():(i.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,static:this.static,abstract:this.abstract,properties:this.properties.map(a=>a.toJSON(i)),methods:this.methods.map(a=>a.toJSON(i)),abstractMethods:this.abstractMethods.map(a=>a.toJSON(i)),extends:((n=this.extends)==null?void 0:n.toJSON(i))||null})}toReference(i=Rt){return{id:this.id+"--"+M.UUID.uuid()+"--ref",type:l.GenericReference,entityId:this.id,version:this.version,entityType:this.type}}toShallowJSON(i=Rt){var n;return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,abstract:this.abstract,static:this.static,properties:this.properties.map(a=>a.toReference()),methods:this.methods.map(a=>a.toReference()),abstractMethods:this.abstractMethods.map(a=>a.toReference()),extends:((n=this.extends)==null?void 0:n.toReference())||null}}toFlatJSON(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.toShallowJSON(),...this.properties.flatMap(a=>a.toFlatJSON(i)),...this.methods.flatMap(a=>a.toFlatJSON(i)),...this.abstractMethods.flatMap(a=>a.toFlatJSON(i))])}toGenerationTarget(i=Rt){var n;return{id:this.id,type:this.type,name:this.name,description:this.description,static:this.static,abstract:this.abstract,extends:(n=this.extends)==null?void 0:n.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=G9i(this),{success:!0}}async validateAsync(i={}){const n=se.YieldTracker.from(i);return this.errors=await L9i(this,{tracker:n}),{success:!0}}getErrors(){return[...this.errors,...this.properties.flatMap(n=>n.getErrors()),...this.methods.flatMap(n=>n.getErrors()),...this.abstractMethods.flatMap(n=>n.getErrors())]}async getErrorsAsync(i={}){const n=se.YieldTracker.from(i),a=[...this.errors];await n.tick();for(const c of this.properties){const e=await c.getErrorsAsync({tracker:n});a.push(...e)}for(const c of this.methods){const e=await c.getErrorsAsync({tracker:n});a.push(...e)}for(const c of this.abstractMethods){const e=await c.getErrorsAsync({tracker:n});a.push(...e)}return a}getShallowErrors(){return this.errors}getAllInteractiveMethods(){const i=[];return i.push(...this.methods),!this.extends||this.extends.type===l.PrimitiveEntity?i:_(i)}};D(b1,"repository",{APILoad:async(i,...n)=>null});let wh=b1;function lr(s,u){if(!s)throw new Error("Entity is null");const i=u.get(s.id);switch(s.type){case l.LiteralValue:return i||new Lr(s,u);case l.DefinitionEntity:return i||new on(s,u);case l.PrimitiveEntity:return i||new wh(s,u);case l.FunctionDeclaration:return i||new sp(s,u);case l.GlobalEvent:return i||new Cf(s,u);case l.DataType:return i||new wr(s,u);case l.Property:return i||new xl(s,u);case l.FunctionCall:return i||new Df(s,u);case l.Condition:return i||new Pf(s,u);case l.Operation:return i||new wf(s,u);case l.VariableDeclaration:return i||new xf(s,u);case l.VariableInstance:return i||new _f(s,u);case l.OutputMap:return i||new eu(s,u);case l.ArgumentDeclaration:return i||new $l(s,u);case l.InputMap:return i||new so(s,u);case l.Project:return i||new M(s);case l.InstalledProject:return i||new Nf(s,u);case l.ActionDescriptor:return i||new Hn(s,u);case l.ReturnStatement:return i||new oc(s,u);case l.Loop:return i||new Of(s,u);case l.Search:return i||new Vf(s,u);case l.ValueDescriptor:return i||new op(s,u);case l.BuiltInBaseEntity:return i||new ao(s,u);case l.InternalCall:return i||new $f(s,u);case l.ContinueStatement:return i||new Gf(s,u);case l.BreakStatement:return i||new Lf(s,u);case l.GenericReference:return u.get(s.entityId);default:throw new Error("Invalid entity type: "+s.type)}}function Oe(s,u){if(!s)throw new Error("Entity is null");const i=lr(s,u);return i.subscribe(),i}function B9i(s,u,i){if(!s)throw new Error("Entity is null");switch(s.type){case l.LiteralValue:return Lr.fromGenerationTarget(s,u,i);case l.DefinitionEntity:return on.fromGenerationTarget(s,u,i);case l.FunctionDeclaration:return sp.fromGenerationTarget(s,u,i);case l.GlobalEvent:return Cf.fromGenerationTarget(s,u,i);case l.DataType:return wr.fromGenerationTarget(s,u,i);case l.Property:return xl.fromGenerationTarget(s,u,i);case l.FunctionCall:return Df.fromGenerationTarget(s,u,i);case l.Condition:return Pf.fromGenerationTarget(s,u,i);case l.Operation:return wf.fromGenerationTarget(s,u,i);case l.VariableDeclaration:return xf.fromGenerationTarget(s,u,i);case l.VariableInstance:return _f.fromGenerationTarget(s,u,i);case l.OutputMap:return eu.fromGenerationTarget(s,u,i);case l.ArgumentDeclaration:return $l.fromGenerationTarget(s,u,i);case l.InputMap:return so.fromGenerationTarget(s,u,i);case l.InstalledProject:return Nf.fromGenerationTarget(s,u,i);case l.ReturnStatement:return oc.fromGenerationTarget(s,u,i);case l.Loop:return Of.fromGenerationTarget(s,u,i);case l.Search:return Vf.fromGenerationTarget(s,u,i);case l.ActionDescriptor:return Hn.fromGenerationTarget(s,u,i);case l.ValueDescriptor:return op.fromGenerationTarget(s,u,i);case l.InternalCall:return $f.fromGenerationTarget(s,u,i);case l.ContinueStatement:return Gf.fromGenerationTarget(s,u,i);case l.BreakStatement:return Lf.fromGenerationTarget(s,u,i);default:throw new Error("Invalid entity type: "+s.type)}}const Rt={seenEntityMaps:new Map,seenEntities:new Set,timestamp:j().toISOString()};class Krt{constructor(){D(this,"initialData")}}const it={cascade:!1},qrt={APILoad:async(s,...u)=>null},M9i={APICreate:async(s,...u)=>s,APIUpdate:async(s,...u)=>s,APIDelete:async(s,...u)=>s,APIClone:async(s,...u)=>{},APILoadVersion:async(s,u,...i)=>null,...qrt};class U9i{}class Zrt extends Krt{}class k9i extends Zrt{}class F9i{}class j9i{}class S9i{}class g2{}class K9i extends g2{}class q9i extends g2{}class Z9i{}class d0{static initReadsValue(u){if(u.initialData.readsValue&&u.initialData.readsValue.type!==l.GenericReference)u.readsValue=Oe(u.initialData.readsValue,u.project);else if(u.initialData.readsValue&&u.initialData.readsValue.type===l.GenericReference){const i=el(u.initialData.readsValue,u.project);i&&(u.readsValue=i)}if(u.readsValue){if(Di.includes(u.readsValue.type)){let i=u.parent;!Mr.includes(i.type)&&i.type!==l.Project&&(i=i.parent);const n=u.type===l.InputMap&&u.parent.type===l.Loop;n&&(i=u.parent.parent),u.readsValue.setParent(i,null),u.readsValue.initChildren(null),i&&i.type!==l.Project&&!n&&i.detachedChildren.includes(u)?i.replaceDetachedChild(u,u.readsValue):i&&i.type!==l.Project&&!n&&i.subscribeDetachedChild(u.readsValue)}u.readsValue.addValueReader(u,null)}return u.readsValue}}class hA{static initWritesValues(u,i){const n=u.initialData.writesValues.reduce((c,e)=>{if(e.type===l.GenericReference||u.writesValues.some(h=>h.id===e.id))return c;const f=Oe(e,u.project);return f.setValueWriter(u,null),Di.includes(f.type)&&(f.setParent(i,null),f.initChildren(null)),[...c,f]},[]),a=[...u.writesValues];return u.writesValues=_([...a,...n]),u.writesValues}}class H9i{}var nn=(s=>(s.PROJECT_INITIALIZED="project-initialized",s.BEFORE_CHANGE_SET_CLOSE_BEFORE_SIDE_EFFECTS="before-change-set-close-before-side-effects",s.BEFORE_CHANGE_SET_CLOSE_AFTER_SIDE_EFFECTS="before-change-set-close-after-side-effects",s.CHANGE_SET_CLOSED_BEFORE_PERSIST="change-set-closed-before-persist",s.CHANGE_SET_PERSISTED="change-set-persisted",s.BEFORE_CHANGE_SET_PERSIST="before-change-set-persist",s.EXPLICIT_DEFINITION_ENTITY_ADDED="explicit-definition-entity-added",s.EXPLICIT_DEFINITION_ENTITY_REMOVED="explicit-definition-entity-removed",s.EXPLICIT_DEFINITION_ENTITY_UPDATED="explicit-definition-entity-updated",s.PERSISTED_DEFINITION_ENTITY_ADDED="persisted-definition-entity-added",s.PERSISTED_DEFINITION_ENTITY_REMOVED="persisted-definition-entity-removed",s.PERSISTED_DEFINITION_ENTITY_UPDATED="persisted-definition-entity-updated",s.RELATIONAL_DATABASE_DEFINITION_ENTITY_ADDED="relational-database-definition-entity-added",s.RELATIONAL_DATABASE_DEFINITION_ENTITY_REMOVED="relational-database-definition-entity-removed",s.RELATIONAL_DATABASE_DEFINITION_ENTITY_UPDATED="relational-database-definition-entity-updated",s))(nn||{});const E2={...pB,events:new se.Events("def-proj-static-p-ctx-events")},Hrt={requestActiveDynamicValue:(s,u=!1)=>null,...E2},Ii=class Ii extends Da{constructor(i,n={...Hrt,events:new se.Events("def-proj-inst-p-ctx-events")}){super(i);D(this,"initialData");D(this,"id");D(this,"type",l.Project);D(this,"workspaceId");D(this,"name",null);D(this,"description",null);D(this,"x");D(this,"y");D(this,"entities",[]);D(this,"projects",[]);D(this,"functions",[]);D(this,"events",[]);D(this,"variableDeclarations",[]);D(this,"variableInstances",[]);D(this,"conditions",[]);D(this,"operations",[]);D(this,"functionCalls",[]);D(this,"loops",[]);D(this,"searches",[]);D(this,"primitives",[]);D(this,"builtInBaseEntities",[]);D(this,"operationDeclarations",[]);D(this,"globalEventActionDescriptors",[]);D(this,"loopDeclarations",[]);D(this,"loopDeclarationsBodies",[]);D(this,"conditionDeclarations",[]);D(this,"valueDescriptors",[]);D(this,"dataTypes",[]);D(this,"project");D(this,"instances",{});D(this,"builtInInstances",{});D(this,"deletedInstances",{});D(this,"subscribedDefinitionEntities",new Set);D(this,"errors",[]);D(this,"references",[]);D(this,"history",[]);D(this,"undoableStackValueIndex",-1);D(this,"detachedDependents",{});D(this,"knownVersions",null);D(this,"activeVersion",!1);D(this,"initialized",!1);D(this,"startedInitialization",!1);D(this,"diggestedBuiltInBaseEntitiesIds",new Set);D(this,"rejectParallelCS",!1);D(this,"onPersistChangeSetSequentiallyCallback",null);D(this,"onPersistChangeSetInParallelCallback",null);D(this,"onAddChangeSetCallback",null);D(this,"onDiscardChangeSetCallback",null);if(this.parentContext=n,this.initialData=i,this.id=i.id,this.workspaceId=i.workspaceId,this.name=i.name,this.description=i.description,this.x=0,this.y=0,this.instances[this.id]=this,!Ii.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:Ii.UUID.uuid(),version:Ii.UUID.uuid(),workspaceId:"",createdAt:(i==null?void 0:i.timestamp)||j().toISOString(),author:(i==null?void 0:i.author)||Ii.sessionAuthor,previousVersion:null,deleted:!1,deletable:!0,editable:!0,type:l.Project,name:"",description:"",entities:[],functions:[],events:[],projects:[],variableDeclarations:[],variableInstances:[],conditions:[],operations:[],functionCalls:[],loops:[],searches:[]}}static validateGenerationTarget(i,n){let a=JSON.parse(JSON.stringify(i));const c=[],e=[],f=ya(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(){se.Logger.log("[ProjectState.closePersistChangeSetsSequentially] called");const i=this.history.find(n=>n.dirty&&!n.open&&!n.submitting);i&&(se.Logger.log(`[ProjectState.closePersistChangeSetsSequentially] closing pending change-set ${i.id} - ${i.actionName}`),await this.persistChangeSetSequentially(i))}async onPersistChangeSetSequentially(i){this.onPersistChangeSetSequentiallyCallback=i,se.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,se.Logger.log("[ProjectState.onPersistChangeSetInParallel] onPersistChangeSetInParallelCallback has been set. Checking for pending change-sets.");for(const n of this.history)this.persistChangeSetInParallel(n),await new Promise(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(se.Logger.log(`[ProjectState.persistChangeSetSequentially] called for change-set ${i.id} - ${i.actionName}`),!i.dirty||i.open||i.submitting){se.Logger.log(`[ProjectState.persistChangeSetSequentially] change-set ${i.id} - ${i.actionName} is not dirty, or is open, or is already being submitted, skipping.`);return}const n=this.history.findIndex(e=>e.id===i.id),a=this.history.slice(0,n),c=a[a.length-1];if(c!=null&&c.dirty){se.Logger.log(`[ProjectState.persistChangeSetSequentially] lastBeforeSelf is dirty: ${c.id} - ${c.actionName}, closing it first.`);return}this.onPersistChangeSetSequentiallyCallback&&(se.Logger.log(`[ProjectState.persistChangeSetSequentially] invoking onPersistChangeSetSequentiallyCallback for change-set ${i.id} - ${i.actionName}`),this.emit("before-change-set-persist",i),i.submitting=!0,(await this.onPersistChangeSetSequentiallyCallback(i)).success&&(i.dirty=!1,this.emit("change-set-persisted",i),se.Logger.log(`[ProjectState.persistChangeSetSequentially] change-set ${i.id} - ${i.actionName} closed successfully, checking for pending change-sets to close.`),this.closePersistChangeSetsSequentially()))}async persistChangeSetInParallel(i){if(se.Logger.log(`[ProjectState.persistChangeSetInParallel] called for change-set ${i.id} - ${i.actionName}`),!i.dirty||i.open||i.submitting){se.Logger.log(`[ProjectState.persistChangeSetInParallel] change-set ${i.id} - ${i.actionName} is not dirty, or is open, or is already being submitted, skipping.`);return}this.onPersistChangeSetInParallelCallback&&(se.Logger.log(`[ProjectState.persistChangeSetInParallel] invoking onPersistChangeSetInParallelCallback for change-set ${i.id} - ${i.actionName}`),this.emit("before-change-set-persist",i),i.submitting=!0,(await this.onPersistChangeSetInParallelCallback(i)).success&&(i.dirty=!1,this.emit("change-set-persisted",i)))}toLatestChangeSet(i,n,a,c=!1,e="here-this"){if(!this.history.length)return new ee(this,i,n,a,c,e);const f=this.history[this.history.length-1];return f.open?f:this.addChangeSet(new ee(this,i,n,a,c,e))}addChangeSet(i){var a,c;if(!this.history.length)return this.undoableStackValueIndex=sV(this.undoableStackValueIndex,this.history,i),(a=this.onAddChangeSetCallback)==null||a.call(this,i,this.undoableStackValueIndex),i;const n=this.history.find(e=>e.id===(i==null?void 0:i.id));if(n)return n;if(this.rejectParallelCS){const e=this.history.find(f=>f.open);if(e)throw se.Logger.warn("Previous still open: ",e),se.Logger.warn("New change set: ",i),new Error(`There is already an open change-set with id '${e.id}'${e.actionName?` auto-close: ${e.actionName}`:""}${e.self?` root: ${e.self.type} ${me(e.self,this)}`:""}.`)}return this.undoableStackValueIndex=sV(this.undoableStackValueIndex,this.history,i),(c=this.onAddChangeSetCallback)==null||c.call(this,i,this.undoableStackValueIndex),i}discardChangeSet(i){var a;se.Logger.log(`[ProjectState.discardChangeSet] called for change-set ${i.id} - ${i.actionName}`);const n=this.history.findIndex(c=>c.id===(i==null?void 0:i.id));return n!==-1&&(this.history.splice(n,1),se.Logger.log(`[ProjectState.discardChangeSet] Removed change-set ${i.id} - ${i.actionName} 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(n=>{this.detachedDependents[n.entity.id]||(this.detachedDependents[n.entity.id]=n)}),this}unsubscribeDependents(i){return i.forEach(n=>{this.detachedDependents[n.entity.id]&&delete this.detachedDependents[n.entity.id]}),this}syncDependents(i=this.project.addChangeSet(new ee(this.project,Ii.sessionAuthor,j().toISOString(),this,!0,"sync-dependents"))){const n=[],a=[],c=[],e=[];return Object.values(this.detachedDependents).forEach(f=>{const h=f.entity.afterAllChildrenInitialized(i);n.push(...h.updated),a.push(...h.added),c.push(...h.removed),e.push(...h.affected)}),i==null||i.attemptAutoclose("sync-dependents",this.id),{updated:_(n),added:_(a),removed:_(c),affected:_(e),self:this}}onDetachedDependencyRemoved(i,n,a){const c=[],e=[],f=[],h=[];return{updated:_(c),added:_(e),removed:_(f),affected:_(h),self:this}}onDetachedDependencyRestored(i,n,a){const c=[],e=[],f=[],h=[];return{updated:_(c),added:_(e),removed:_(f),affected:_(h),self:this}}unsubscribeFromDependencies(){return this}subscribeToDependencies(){return this}increaseVersion(i){var n;if(i&&!j(i).isValid())throw new Error(`The shared timestamp '${i}' is not a valid ISO 8601 date string.`);if(i&&j(i).isSame(j(this.createdAt)))return this;if(!((n=this.knownVersions)!=null&&n.has(this.version))&&this.initialized)throw new Error(`The current ${this.type} ${this.id} version '${this.version}' is not captured in the 'knownVersions' map. Capture the current version before increasing it to avoid losing data.`);if(!this.activeVersion)throw new Error(`Only active versions can be increased. Entity with id '${this.id}' and version '${this.version}' is not active.`);return this.previousVersion=this.version,this.version=Ii.UUID.uuid(),this.createdAt=j(i).toISOString()||j().toISOString(),this}captureVersion(){var n;const i=((n=this.knownVersions)==null?void 0:n.get(this.version))||new Ii(this);if(!this.activeVersion)throw new Error(`Only active versions can be captured. Entity of type ${this.type} with id '${this.id}' and version '${this.version}' is not active.`);if(this.version!==i.version)throw new Error(`Captured ${this.type} with id '${this.id}', version '${i.version}' does not match current entity version '${this.version}'.`);return this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,i):new Map().set(this.version,i),this.apply(i),this}snapshot(){const i=new Ii(this);return this.apply(i)}apply(i){const n=this.toMeta();return i.metaSync(n,null),i.entities=[...this.entities],i.projects=[...this.projects],i.functions=[...this.functions],i.events=[...this.events],i.variableDeclarations=[...this.variableDeclarations],i.variableInstances=[...this.variableInstances],i.conditions=[...this.conditions],i.operations=[...this.operations],i.functionCalls=[...this.functionCalls],i.loops=[...this.loops],i.searches=[...this.searches],i}recursiveCaptureUpstreamVersions(i){const n=[],a=[],c=[],e=[];return{updated:_(n),added:_(a),removed:_(c),affected:_(e),self:this}}async restoreVersion(i,n){var m;const a=[],c=[],e=[],f=[];if(this.version===i&&(n!=null&&n.skipIfSameVersion))return{updated:_(a),added:_(c),removed:_(e),affected:_(f),self:this};if(!this.knownVersions){const T=new Map;for(const[g,b]of this.knownVersions||new Map){if(T.set(g,b),b.activeVersion=!1,b.knownVersions)for(const[R,I]of b.knownVersions)T.set(R,I);b.knownVersions=null}}let h=(m=this.knownVersions)==null?void 0:m.get(i);if(!h){const T=await this.APILoadVersion({},i);if(!T)throw new Error(`Version with id '${i}' for entity with id '${this.id}' not found.`);h=new Ii(T)}return this.metaSync(h.toShallowJSON(),null),this.previousVersion=h.previousVersion,this.version=h.version,this.createdAt=h.createdAt,this.author=h.author,this.deleted=h.deleted,this.entities=[...h.entities],this.projects=[...h.projects],this.functions=[...h.functions],this.events=[...h.events],this.variableDeclarations=[...h.variableDeclarations],this.variableInstances=[...h.variableInstances],this.conditions=[...h.conditions],this.operations=[...h.operations],this.functionCalls=[...h.functionCalls],this.loops=[...h.loops],this.searches=[...h.searches],{updated:_(a),added:_(c),removed:_(e),affected:_(f),self:this}}updateWithShallowTransfer(i,n=this.project.addChangeSet(new ee(this.project,Ii.sessionAuthor,j().toISOString(),this,!0,P.UpdateWithShallowTransfer))){return this.checkCanEdit(this,n)?(this.metaSync(i,n),this.version=i.version,this.createdAt=i.createdAt,this.author=i.author,this.deleted=i.deleted,this.previousVersion=i.previousVersion,this.captureVersion(),this.subscribeToDependencies(),n==null||n.attemptAutoclose(P.UpdateWithShallowTransfer,this.id),this):(se.Logger.warn(`[updateWithShallowTransfer] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),n==null||n.attemptAutoclose(P.UpdateWithShallowTransfer,this.id),this)}updateWithGenerationTarget(i,n=this.project.addChangeSet(new ee(this.project,Ii.sessionAuthor,j().toISOString(),this,!0,P.UpdateWithGenerationTarget))){return this.checkCanEdit(this,n)?(this.metaSync(i,n),this.captureVersion(),this.subscribeToDependencies(),n==null||n.attemptAutoclose(P.UpdateWithGenerationTarget,this.id),this):(se.Logger.warn(`[updateWithGenerationTarget] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),n==null||n.attemptAutoclose(P.UpdateWithGenerationTarget,this.id),this)}hydrateAncestors(){const i=[],n=[],a=[],c=[];return{updated:_(i),added:_(n),removed:_(a),affected:_(c),self:this}}afterAllChildrenInitialized(i=null){const n=[],a=[],c=[],e=[];return this.initialized||(this.initialized=!0,this.emit("project-initialized",this,i)),this.validate(),{updated:_(n),added:_(a),removed:_(c),affected:_(e),self:this}}addSelfToProject(i){const n=[],a=[],c=[],e=[];return this.subscribe(),this.subscribeToDependencies(),{updated:_(n),added:_(a),removed:_(c),affected:_(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 ee(this.project,Ii.sessionAuthor,j().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.entities=this.initialData.entities.map(n=>{const a=Oe(n,this);return a.setParent(this,null),a.initChildren(i),a}),this.projects=this.initialData.projects.map(n=>{const a=Oe(n,this);return a.setParent(this,null),a.initChildren(i),a}),this.variableDeclarations=this.initialData.variableDeclarations.map(n=>{const a=Oe(n,this);return a.setParent(this,null),a.initChildren(i),a}),this.variableInstances=this.initialData.variableInstances.map(n=>{const a=Oe(n,this);return a.setParent(this,null),a.initChildren(i),a}),this.conditions=this.initialData.conditions.map(n=>{const a=Oe(n,this);return a.setParent(this,null),a.initChildren(i),a}),this.operations=this.initialData.operations.map(n=>{const a=Oe(n,this);return a.setParent(this,null),a.initChildren(i),a}),this.functions=this.initialData.functions.map(n=>{const a=Oe(n,this);return a.setParent(this,null),a.initChildren(i),a}),this.events=this.initialData.events.map(n=>{const a=Oe(n,this);return a.setParent(this,null),a.initChildren(i),a}),this.functionCalls=this.initialData.functionCalls.map(n=>{const a=Oe(n,this);return a.setParent(this,null),a.initChildren(i),a}),this.loops=this.initialData.loops.map(n=>{const a=Oe(n,this);return a.setParent(this,null),a.initChildren(i),a}),this.searches=this.initialData.searches.map(n=>{const a=Oe(n,this);return a.setParent(this,null),a.initChildren(i),a}),this.attachOrphanReferences(),this.subscribeToDependencies(),this.afterAllChildrenInitialized(i),i==null||i.attemptAutoclose("init-children",this.id),this)}subscribeInstance(i){return(!this.instances[i.id]||this.instances[i.id]!==i)&&(this.instances[i.id]=i),this}subscribeDeletedInstance(i){return(!this.deletedInstances[i.id]||this.deletedInstances[i.id]!==i)&&(this.deletedInstances[i.id]=i),this}subscribeBuiltInInstance(i){return(!this.builtInInstances[i.id]||this.builtInInstances[i.id]!==i)&&(this.builtInInstances[i.id]=i),this}subscribe(){var i;return this.activeVersion=!0,(i=this.knownVersions)==null||i.forEach(n=>{n.version!==this.version&&(n.activeVersion=!1)}),this.subscribeInstance(this),this}unsubscribe(){return this}unsubscribeInstance(i){return delete this.instances[i.id],this}unsubscribeDeletedInstance(i){return delete this.deletedInstances[i.id],this}unsubscribeBuiltInInstance(i){return delete this.builtInInstances[i.id],this}findSubscribedBuiltInInstance(i){return this.builtInInstances[i.id]||null}get(i){return this.instances[i]||this.builtInInstances[i]||null}getDeleted(i){return this.deletedInstances[i]||null}getManaged(i){return this.getBuiltIn(i)?null:this.instances[i]||null}getBuiltIn(i){return this.builtInInstances[i]||null}findSubscribedInstanceFromReference(i){return this.instances[i.entityId]||null}findSubscribedBuiltInInstanceFromReference(i){return this.builtInInstances[i.entityId]||null}metaSync(i,n=this.project.addChangeSet(new ee(this.project,Ii.sessionAuthor,j().toISOString(),this,!0,"meta-sync"))){const a=ma(this,i,n),c=ha(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,n),a.deleted===!0&&!e.deleted?n==null||n.add(this,re.Removed):a.deleted===!1&&e.deleted?n==null||n.add(this,re.Added):c&&(n==null||n.add(this,re.Updated)),n==null||n.attemptAutoclose("meta-sync",this.id),this}async APILoad(i=it,...n){return await Ii.repository.APILoad(this.id,...n),this}async APICreate(i=it,...n){return await Ii.repository.APICreate(this.toShallowJSON(),...n),this}async APIUpdate(i=it,...n){return await Ii.repository.APIUpdate(this.toShallowJSON(),...n),this}async APIDelete(i=it,...n){return await Ii.repository.APIDelete(this.toShallowJSON(),...n),this}async APIClone(i=it,...n){return await Ii.repository.APIClone(this.id,...n),this}async APILoadVersion(i=it,n,...a){return await Ii.repository.APILoadVersion(this.id,n,...a)}remove({ignoreUpstream:i}={ignoreUpstream:!1},n=this.project.addChangeSet(new ee(this.project,Ii.sessionAuthor,j().toISOString(),this,!0,P.RemoveEntity))){return{added:[],updated:[],removed:[],affected:[],self:this}}restore({}={},i=this.project.addChangeSet(new ee(this.project,Ii.sessionAuthor,j().toISOString(),this,!0,P.RestoreEntity))){return{added:[],updated:[],removed:[],affected:[],self:this}}getAllBuiltInIds(){const i=new Set;return[...this.primitives.flatMap(n=>n.toFlatIds(i)),...this.builtInBaseEntities.flatMap(n=>n.toFlatIds(i)),...this.operationDeclarations.flatMap(n=>n.toFlatIds(i)),...this.globalEventActionDescriptors.flatMap(n=>n.toFlatIds(i)),...this.loopDeclarations.flatMap(n=>n.toFlatIds(i)),...this.conditionDeclarations.flatMap(n=>n.toFlatIds(i)),...this.valueDescriptors.flatMap(n=>n.toFlatIds(i)),...this.dataTypes.flatMap(n=>n.toFlatIds(i))]}getAllBuiltIn(){const i=new Set;return[...this.primitives.flatMap(n=>n.toFlat(i)),...this.builtInBaseEntities.flatMap(n=>n.toFlat(i)),...this.operationDeclarations.flatMap(n=>n.toFlat(i)),...this.globalEventActionDescriptors.flatMap(n=>n.toFlat(i)),...this.loopDeclarations.flatMap(n=>n.toFlat(i)),...this.conditionDeclarations.flatMap(n=>n.toFlat(i)),...this.valueDescriptors.flatMap(n=>n.toFlat(i)),...this.dataTypes.flatMap(n=>n.toFlat(i))]}toFlat(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this,...this.entities.flatMap(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,workspaceId:this.workspaceId,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,workspaceId:this.workspaceId,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,editable:this.editable,deletable:this.deletable,name:this.name,description:this.description,entities:this.entities.map(n=>n.toJSON(i)),variableDeclarations:this.variableDeclarations.map(n=>n.toJSON(i)),variableInstances:this.variableInstances.map(n=>n.toJSON(i)),conditions:this.conditions.map(n=>n.toJSON(i)),operations:this.operations.map(n=>n.toJSON(i)),loops:this.loops.map(n=>n.toJSON(i)),searches:this.searches.map(n=>n.toJSON(i)),functions:this.functions.map(n=>n.toJSON(i)),events:this.events.map(n=>n.toJSON(i)),projects:this.projects.map(n=>n.toJSON(i)),functionCalls:this.functionCalls.map(n=>n.toJSON(i))})}toJSONClone(i={uuidStrategy:"uuid"}){const n=new Map,a=new Set,c=this.getAllBuiltInIds();return Object.keys(this.instances).forEach(e=>{if(c.includes(e)){n.set(e,e);return}n.set(e,Ii.UUID.uuid())}),a.add(this.id),{id:n.get(this.id),version:this.version,workspaceId:this.workspaceId,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,editable:this.editable,deletable:this.deletable,name:this.name,description:this.description,entities:this.entities.map(e=>e.toJSONClone({...i,seenEntityMaps:n,seenEntities:a,newId:null})),projects:this.projects.map(e=>e.toJSONClone({...i,seenEntityMaps:n,seenEntities:a,newId:null})),variableDeclarations:this.variableDeclarations.map(e=>e.toJSONClone({...i,seenEntityMaps:n,seenEntities:a,newId:null})),variableInstances:this.variableInstances.map(e=>e.toJSONClone({...i,seenEntityMaps:n,seenEntities:a,newId:null})),conditions:this.conditions.map(e=>e.toJSONClone({...i,seenEntityMaps:n,seenEntities:a,newId:null})),operations:this.operations.map(e=>e.toJSONClone({...i,seenEntityMaps:n,seenEntities:a,newId:null})),functions:this.functions.map(e=>e.toJSONClone({...i,seenEntityMaps:n,seenEntities:a,newId:null})),events:this.events.map(e=>e.toJSONClone({...i,seenEntityMaps:n,seenEntities:a,newId:null})),functionCalls:this.functionCalls.map(e=>e.toJSONClone({...i,seenEntityMaps:n,seenEntities:a,newId:null})),loops:this.loops.map(e=>e.toJSONClone({...i,seenEntityMaps:n,seenEntities:a,newId:null})),searches:this.searches.map(e=>e.toJSONClone({...i,seenEntityMaps:n,seenEntities:a,newId:null}))}}toReference(i=Rt){var a;let n=this.id;return(a=i.seenEntityMaps)!=null&&a.has(this.id)&&(n=i.seenEntityMaps.get(this.id)),{id:n+"--"+Ii.UUID.uuid()+"--ref",type:l.GenericReference,entityId:n,version:this.version,entityType:this.type}}toShallowJSON(i=Rt){var a;let n=this.id;return(a=i.seenEntityMaps)!=null&&a.has(this.id)&&(n=i.seenEntityMaps.get(this.id)),{id:n,version:this.version,workspaceId:this.workspaceId,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=Rt){var a;let n=this.id;return(a=i.seenEntityMaps)!=null&&a.has(this.id)&&(n=i.seenEntityMaps.get(this.id)),{id:n,workspaceId:this.workspaceId,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(),GT([...this.errors]),{success:!0}}async validateAsync(i={}){const n=se.YieldTracker.from(i);return await this.validateChildrenAsync({tracker:n}),await eHe([...this.errors]),{success:!0}}validateChildren(){this.entities.forEach(i=>i.validate()),this.projects.forEach(i=>i.validate()),this.functions.forEach(i=>i.validate()),this.events.forEach(i=>i.validate()),this.variableDeclarations.forEach(i=>i.validate()),this.variableInstances.forEach(i=>i.validate()),this.conditions.forEach(i=>i.validate()),this.operations.forEach(i=>i.validate()),this.functionCalls.forEach(i=>i.validate()),this.loops.forEach(i=>i.validate()),this.searches.forEach(i=>i.validate())}async validateChildrenAsync(i={}){const n=se.YieldTracker.from(i);for(let a=0;a<this.entities.length;a++)await this.entities[a].validateAsync({tracker:n});for(let a=0;a<this.projects.length;a++)await this.projects[a].validateAsync({tracker:n});for(let a=0;a<this.functions.length;a++)await this.functions[a].validateAsync({tracker:n});for(let a=0;a<this.events.length;a++)await this.events[a].validateAsync({tracker:n});for(let a=0;a<this.variableDeclarations.length;a++)await this.variableDeclarations[a].validateAsync({tracker:n});for(let a=0;a<this.variableInstances.length;a++)await this.variableInstances[a].validateAsync({tracker:n});for(let a=0;a<this.conditions.length;a++)await this.conditions[a].validateAsync({tracker:n});for(let a=0;a<this.operations.length;a++)await this.operations[a].validateAsync({tracker:n});for(let a=0;a<this.functionCalls.length;a++)await this.functionCalls[a].validateAsync({tracker:n});for(let a=0;a<this.loops.length;a++)await this.loops[a].validateAsync({tracker:n});for(let a=0;a<this.searches.length;a++)await this.searches[a].validateAsync({tracker:n})}getErrors(){return[...this.errors,...this.entities.flatMap(n=>n.getErrors()),...this.projects.flatMap(n=>n.getErrors()),...this.functions.flatMap(n=>n.getErrors()),...this.events.flatMap(n=>n.getErrors()),...this.variableDeclarations.flatMap(n=>n.getErrors()),...this.variableInstances.flatMap(n=>n.getErrors()),...this.conditions.flatMap(n=>n.getErrors()),...this.operations.flatMap(n=>n.getErrors()),...this.functionCalls.flatMap(n=>n.getErrors()),...this.loops.flatMap(n=>n.getErrors()),...this.searches.flatMap(n=>n.getErrors())]}async getErrorsAsync(i={}){const n=se.YieldTracker.from(i),a=[...this.errors];await n.tick();for(let c=0;c<this.entities.length;c++){const e=await this.entities[c].getErrorsAsync({tracker:n});a.push(...e)}for(let c=0;c<this.projects.length;c++){const e=await this.projects[c].getErrorsAsync({tracker:n});a.push(...e)}for(let c=0;c<this.functions.length;c++){const e=await this.functions[c].getErrorsAsync({tracker:n});a.push(...e)}for(let c=0;c<this.events.length;c++){const e=await this.events[c].getErrorsAsync({tracker:n});a.push(...e)}for(let c=0;c<this.variableDeclarations.length;c++){const e=await this.variableDeclarations[c].getErrorsAsync({tracker:n});a.push(...e)}for(let c=0;c<this.variableInstances.length;c++){const e=await this.variableInstances[c].getErrorsAsync({tracker:n});a.push(...e)}for(let c=0;c<this.conditions.length;c++){const e=await this.conditions[c].getErrorsAsync({tracker:n});a.push(...e)}for(let c=0;c<this.operations.length;c++){const e=await this.operations[c].getErrorsAsync({tracker:n});a.push(...e)}for(let c=0;c<this.functionCalls.length;c++){const e=await this.functionCalls[c].getErrorsAsync({tracker:n});a.push(...e)}for(let c=0;c<this.loops.length;c++){const e=await this.loops[c].getErrorsAsync({tracker:n});a.push(...e)}for(let c=0;c<this.searches.length;c++){const e=await this.searches[c].getErrorsAsync({tracker:n});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 n=this.entities.findIndex(a=>a.id===i.id);if(n>-1){const a=this.entities[n];return this.entities.splice(n,1),a}return null}removeCondition(i){const n=this.conditions.findIndex(a=>a.id===i.id);if(n>-1){const a=this.conditions[n];return this.conditions.splice(n,1),a}return null}removeOperation(i){const n=this.operations.findIndex(a=>a.id===i.id);if(n>-1){const a=this.operations[n];return this.operations.splice(n,1),a}return null}removeLoop(i){const n=this.loops.findIndex(a=>a.id===i.id);if(n>-1){const a=this.loops[n];return this.loops.splice(n,1),a}return null}removeSearch(i){const n=this.searches.findIndex(a=>a.id===i.id);if(n>-1){const a=this.searches[n];return this.searches.splice(n,1),a}return null}removeFunctionCall(i){const n=this.functionCalls.findIndex(a=>a.id===i.id);if(n>-1){const a=this.functionCalls[n];return this.functionCalls.splice(n,1),a}return null}removeVariableInstance(i){const n=this.variableInstances.findIndex(a=>a.id===i.id);if(n>-1){const a=this.variableInstances[n];return this.variableInstances.splice(n,1),a}return null}removeVariableDeclaration(i){const n=this.variableDeclarations.findIndex(a=>a.id===i.id);if(n>-1){const a=this.variableDeclarations[n];return this.variableDeclarations.splice(n,1),a}return null}removeFunctionDeclaration(i){const n=this.functions.findIndex(a=>a.id===i.id);if(n>-1){const a=this.functions[n];return this.functions.splice(n,1),a}return null}removeInstalledProject(i){const n=this.projects.findIndex(a=>a.id===i.id);if(n>-1){const a=this.projects[n];return this.projects.splice(n,1),a}return null}removeGlobalEvent(i){const n=this.events.findIndex(a=>a.id===i.id);if(n>-1){const a=this.events[n];return this.events.splice(n,1),a}return null}removeTopLevelVariableDeclaration(i){if(i.type!==l.VariableDeclaration)return null;const n=this.variableDeclarations.findIndex(a=>a.id===i.id);if(n>-1){const a=this.variableDeclarations[n];return this.variableDeclarations.splice(n,1),a}return null}getEntryPoints(){return[...this.functions,...this.events,...this.entities.flatMap(n=>n.methods)]}getTerminationStatements(){return[...this.getEntryPoints().reduce((n,a)=>{const c=Lt(a);return[...n,...c.filter(e=>e.type===l.ReturnStatement||e.type===l.ContinueStatement||e.type===l.BreakStatement)]},[])]}getFunctionDeclaration(i){return this.functions.find(n=>n.id===i)||null}getConditions(){return[...this.conditions,...this.getEntryPoints().reduce((n,a)=>{const c=Lt(a);return[...n,...c.filter(e=>e.type===l.Condition)]},[]),...this.functionCalls.reduce((n,a)=>{const c=Lt(a);return[...n,...c.filter(e=>e.type===l.Condition)]},[]),...this.operations.reduce((n,a)=>{const c=Lt(a);return[...n,...c.filter(e=>e.type===l.Condition)]},[]),...this.loops.reduce((n,a)=>{const c=Lt(a);return[...n,...c.filter(e=>e.type===l.Condition)]},[]),...this.searches.reduce((n,a)=>{const c=Lt(a);return[...n,...c.filter(e=>e.type===l.Condition)]},[])]}getOperations(){return[...this.operations,...this.getEntryPoints().reduce((n,a)=>{const c=Lt(a);return[...n,...c.filter(e=>e.type===l.Operation)]},[]),...this.functionCalls.reduce((n,a)=>{const c=Lt(a);return[...n,...c.filter(e=>e.type===l.Operation)]},[]),...this.conditions.reduce((n,a)=>{const c=Lt(a);return[...n,...c.filter(e=>e.type===l.Operation)]},[]),...this.loops.reduce((n,a)=>{const c=Lt(a);return[...n,...c.filter(e=>e.type===l.Operation)]},[]),...this.searches.reduce((n,a)=>{const c=Lt(a);return[...n,...c.filter(e=>e.type===l.Operation)]},[])]}getFunctionCalls(){return[...this.functionCalls,...this.getEntryPoints().reduce((n,a)=>{const c=Lt(a);return[...n,...c.filter(e=>e.type===l.FunctionCall)]},[]),...this.conditions.reduce((n,a)=>{const c=Lt(a);return[...n,...c.filter(e=>e.type===l.FunctionCall)]},[]),...this.operations.reduce((n,a)=>{const c=Lt(a);return[...n,...c.filter(e=>e.type===l.FunctionCall)]},[]),...this.loops.reduce((n,a)=>{const c=Lt(a);return[...n,...c.filter(e=>e.type===l.FunctionCall)]},[]),...this.searches.reduce((n,a)=>{const c=Lt(a);return[...n,...c.filter(e=>e.type===l.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((n,a)=>{const c=Ir(a);return[...n,...c]},[]),...this.functionCalls.reduce((n,a)=>{const c=Ir(a);return[...n,...c]},[]),...this.conditions.reduce((n,a)=>{const c=Ir(a);return[...n,...c]},[]),...this.operations.reduce((n,a)=>{const c=Ir(a);return[...n,...c]},[]),...this.loops.reduce((n,a)=>{const c=Ir(a);return[...n,...c]},[]),...this.searches.reduce((n,a)=>{const c=Ir(a);return[...n,...c]},[])]}getVariableInstances(){return[...this.variableInstances,...this.entities.reduce((n,a)=>[...n,...a.methods.flatMap(c=>{const f=Lt(c).filter(h=>h.type===l.VariableInstance);return[...n,...f]})],[]),...this.getEntryPoints().reduce((n,a)=>{const e=Ir(a).filter(f=>f.type===l.VariableInstance);return[...n,...e]},[]),...this.functionCalls.reduce((n,a)=>{const e=Ir(a).filter(f=>f.type===l.VariableInstance);return[...n,...e]},[]),...this.conditions.reduce((n,a)=>{const e=Ir(a).filter(f=>f.type===l.VariableInstance);return[...n,...e]},[]),...this.operations.reduce((n,a)=>{const e=Ir(a).filter(f=>f.type===l.VariableInstance);return[...n,...e]},[]),...this.loops.reduce((n,a)=>{const e=Ir(a).filter(f=>f.type===l.VariableInstance);return[...n,...e]},[]),...this.searches.reduce((n,a)=>{const e=Ir(a).filter(f=>f.type===l.VariableInstance);return[...n,...e]},[])]}getVariableDeclarations(){return _([...this.variableDeclarations,...this.entities.reduce((n,a)=>[...n,...a.methods.flatMap(c=>{const f=Lt(c).filter(h=>h.type===l.VariableDeclaration);return[...n,...f]})],[]),...this.getEntryPoints().reduce((n,a)=>{const e=Ir(a).filter(f=>f.type===l.VariableDeclaration);return[...n,...e]},[]),...this.functionCalls.reduce((n,a)=>{const e=Ir(a).filter(f=>f.type===l.VariableDeclaration);return[...n,...e]},[]),...this.conditions.reduce((n,a)=>{const e=Ir(a).filter(f=>f.type===l.VariableDeclaration);return[...n,...e]},[]),...this.operations.reduce((n,a)=>{const e=Ir(a).filter(f=>f.type===l.VariableDeclaration);return[...n,...e]},[]),...this.loops.reduce((n,a)=>{const e=Ir(a).filter(f=>f.type===l.VariableDeclaration);return[...n,...e]},[]),...this.searches.reduce((n,a)=>{const e=Ir(a).filter(f=>f.type===l.VariableDeclaration);return[...n,...e]},[])])}getLoops(){return[...this.loops,...this.getEntryPoints().reduce((n,a)=>{const c=Lt(a);return[...n,...c.filter(e=>e.type===l.Loop)]},[]),...this.functionCalls.reduce((n,a)=>{const c=Lt(a);return[...n,...c.filter(e=>e.type===l.Loop)]},[]),...this.conditions.reduce((n,a)=>{const c=Lt(a);return[...n,...c.filter(e=>e.type===l.Loop)]},[]),...this.operations.reduce((n,a)=>{const c=Lt(a);return[...n,...c.filter(e=>e.type===l.Loop)]},[]),...this.searches.reduce((n,a)=>{const c=Lt(a);return[...n,...c.filter(e=>e.type===l.Loop)]},[])]}getSearches(){return[...this.searches,...this.getEntryPoints().reduce((n,a)=>{const c=Lt(a);return[...n,...c.filter(e=>e.type===l.Search)]},[]),...this.functionCalls.reduce((n,a)=>{const c=Lt(a);return[...n,...c.filter(e=>e.type===l.Search)]},[]),...this.conditions.reduce((n,a)=>{const c=Lt(a);return[...n,...c.filter(e=>e.type===l.Search)]},[]),...this.operations.reduce((n,a)=>{const c=Lt(a);return[...n,...c.filter(e=>e.type===l.Search)]},[]),...this.loops.reduce((n,a)=>{const c=Lt(a);return[...n,...c.filter(e=>e.type===l.Search)]},[])]}attachOrphanReferences(){const i=this.getVariableInstances(),n=this.getVariableDeclarations();return i.forEach(a=>{if(!a.declaration){const c=a.initialData,e=c.declaration.entityId||c.declaration.id,f=n.find(h=>h.id===e);f&&a.setDeclaration(f)}}),this}getBuiltInPersistedEntity(){return this.builtInBaseEntities.find(i=>i.name===Ie.PERSISTED_ENTITY)||null}requestActiveDynamicValue(i,n=!1){var c,e;const a=(e=(c=this.parentContext).requestActiveDynamicValue)==null?void 0:e.call(c,i,n);if(!a&&D1.includes(i.type)){const f=i.getDefaultValue();return f?{value:f,type:He.DefaultValue,inheritanceLink:null,valueOwner:i}:null}return a||null}requestExtension(i){if(this.parentContext.requestExtension){const n=this.parentContext.requestExtension(i);if(n&&!n.module)throw new Error(`Module ${i} is not registered properly.`);return n.module||null}return null}undo(){se.Logger.log("Undoing, from: ",this.undoableStackValueIndex),this.undoableStackValueIndex=this.undoableStackValueIndex-1,se.Logger.log("To: ",this.undoableStackValueIndex);const i=this.history[this.undoableStackValueIndex+1],n=this.history[this.undoableStackValueIndex];return se.Logger.log("Current change set: ",i==null?void 0:i.toJSON()),se.Logger.log("Change set to restore: ",n==null?void 0:n.toJSON()),rV(i||"initial",n||"initial",this)}redo(){se.Logger.log("Undoing, from: ",this.undoableStackValueIndex),this.undoableStackValueIndex=this.undoableStackValueIndex+1,se.Logger.log("To: ",this.undoableStackValueIndex);const i=this.history[this.undoableStackValueIndex-1],n=this.history[this.undoableStackValueIndex];return se.Logger.log("Current change set: ",i==null?void 0:i.toJSON()),se.Logger.log("Change set to restore: ",n.toJSON()),rV(i||"initial",n||"initial",this)}applyExternalChangeSet(i){const n=i.payload,a=this.addChangeSet(new ee(this,i.userAuthor,i.emittedAt,this));a.ignoreNonEditable=!0,a.ignoreNonDeletable=!0;const c=n.updated[this.id];if(!c)throw new Error("Project root not found in change set transfer. Cannot apply changes.");const e={...n.added,...n.updated,...n.removed},f=[...Object.keys(n.added),...Object.keys(n.updated),...Object.keys(n.removed)];f.forEach(m=>{var T;if(!e[m]){se.Logger.warn(`Entity '${m}' not found in change set transfer. Cannot apply changes.`);const g=(T=this.get(m))==null?void 0:T.toShallowJSON();throw g?se.Logger.warn("Entity in project: ",g):se.Logger.warn("Entity not in project"),new Error(`Entity '${m}' not found in change set transfer. Cannot apply changes.`)}});const h=new Ma(c,{allBuiltInEntityIds:this.diggestedBuiltInBaseEntitiesIds});return h.flatRecord=e,h.order=f,h.orderEntities(),se.Logger.log("All entities: ",h.order.map((m,T)=>`${T+1}: ${e[m].type} - ${m}`).join(`,
|
|
626
|
-
`)),se.Logger.log("Persisting new additions"),h.visit(async(m,T)=>{if(n.added[m.id]){se.Logger.log("Adding: ",m.id);try{const g=Oe(m,this);if(g.hydrateAncestors(),g.addSelfToProject(a),a.add(g,re.Added),a||g.captureVersion(),!this.get(m.id))throw new Error(`Entity ${m.id} was not added to the project`)}catch(g){se.Logger.error("Error: ",g),se.Logger.error("Errored entity: ",m)}}}),se.Logger.log("Persisting updates"),h.visit(async(m,T)=>{if(n.updated[m.id]){se.Logger.log("Updating: ",m.id);try{const g=this.get(m.id);g?(g.updateWithShallowTransfer(m,a),a.add(g,re.Updated),a||g.captureVersion()):se.Logger.warn(`Active version of ${m.id} not found when applying external changes`)}catch(g){se.Logger.error("Error: ",g),se.Logger.error("Errored entity: ",m)}}}),se.Logger.log("Persisting removals"),h.visit(async(m,T)=>{if(n.removed[m.id]){se.Logger.log("Removing: ",m.id);try{const g=this.get(m.id);g&&(g.remove({ignoreUpstream:!1},a),a.add(g,re.Removed),a||g.captureVersion())}catch(g){se.Logger.error("Error: ",g),se.Logger.error("Errored entity: ",m)}}}),a.open=!1,a}toBuiltInShallowRecord(){const i={};return Object.values(this.builtInInstances).forEach(n=>{const a=n.toShallowJSON();i[n.id]=a}),i}toShallowRecord(){const i={};return Object.values(this.instances).forEach(n=>{const a=n.toShallowJSON();i[n.id]=a}),i}toFullProjectTransfer(i){const n={shallowErrors:!1,...i},a=new Ma(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(se.Logger.error(`[toFullProjectTransfer] Error serializing ${f.type} ${f.id}`,h),!n.shallowErrors)throw h}}),{order:e,size:e.length,record:c}}async toFullProjectTransferAsync(i={}){const n={shallowErrors:!1,...i},a=se.YieldTracker.from(n),c=new Ma(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(n.seenEntityMaps)for(const h of c.order){const m=n.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:n.seenEntityMaps});n.resetVersionOptions&&(m.version=Ii.UUID.uuid(),m.createdAt=n.resetVersionOptions.commonTimestamp||j().toISOString(),m.author=n.resetVersionOptions.author||Ii.sessionAuthor||"1",m.previousVersion=null),f[m.id]=m,e.push(m.id),n!=null&&n.onVisit&&await n.onVisit(m)}catch(m){if(se.Logger.error(`[toFullProjectTransferAsync] Error serializing ${h.type} ${h.id}`,m),!n.shallowErrors)throw m}},{tracker:a}),{order:e,size:e.length,record:f}}async toFullProjectGenerationTargetAsync(i={}){const n={shallowErrors:!1,...i},a=se.YieldTracker.from(n),c=new Ma(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(n.seenEntityMaps)for(const h of c.order){const m=n.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:n.seenEntityMaps});f[m.id]=m,e.push(m.id),n!=null&&n.onVisit&&await n.onVisit(m)}catch(m){if(se.Logger.error(`[toFullProjectGenerationTargetAsync] Error serializing ${h.type} ${h.id}`,m),!n.shallowErrors)throw m}},{tracker:a}),{order:e,size:e.length,record:f}}};D(Ii,"parentContext",E2),D(Ii,"sessionAuthor","1"),D(Ii,"repository",{APICreate:async(i,...n)=>i,APIUpdate:async(i,...n)=>i,APIDelete:async(i,...n)=>i,APIClone:async(i,...n)=>{},APILoad:async(i,...n)=>null,APILoadVersion:async(i,n,...a)=>null}),D(Ii,"type",l.Project),D(Ii,"USER_MANAGED_PARENT_TYPES",[]),D(Ii,"PARENT_TYPES",[...Ii.USER_MANAGED_PARENT_TYPES]),D(Ii,"MUTABLE_BASE_PROPERTIES",["name","description"]),D(Ii,"INMUTABLE_BASE_PROPERTIES",["id","type","workspaceId","version","createdAt","author","previousVersion"]),D(Ii,"BASE_PROPERTIES",[...Ii.MUTABLE_BASE_PROPERTIES,...Ii.INMUTABLE_BASE_PROPERTIES]),D(Ii,"MUTABLE_META_PROPERTIES",[...Ii.MUTABLE_BASE_PROPERTIES,"x","y"]),D(Ii,"INMUTABLE_META_PROPERTIES",[...Ii.INMUTABLE_BASE_PROPERTIES]),D(Ii,"META_PROPERTIES",[...Ii.MUTABLE_META_PROPERTIES,...Ii.INMUTABLE_META_PROPERTIES]),D(Ii,"MUTABLE_UPSTREAM_PROPERTIES",[]),D(Ii,"INMUTABLE_UPSTREAM_PROPERTIES",["primitives","builtInBaseEntities","operationDeclarations","globalEventActionDescriptors","loopDeclarations","builtInInstances"]),D(Ii,"UPSTREAM_PROPERTIES",[...Ii.MUTABLE_UPSTREAM_PROPERTIES,...Ii.INMUTABLE_UPSTREAM_PROPERTIES]),D(Ii,"MUTABLE_DOWNSTREAM_PROPERTIES",["entities","projects","functions","events","variableDeclarations","variableInstances","conditions","operations","functionCalls","loops","searches"]),D(Ii,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),D(Ii,"DOWNSTREAM_PROPERTIES",[...Ii.MUTABLE_DOWNSTREAM_PROPERTIES,...Ii.INMUTABLE_DOWNSTREAM_PROPERTIES]),D(Ii,"PROPERTIES",[...Ii.META_PROPERTIES,...Ii.UPSTREAM_PROPERTIES,...Ii.DOWNSTREAM_PROPERTIES]);let M=Ii;class W9i extends Hn{constructor(u){super(Db,u)}}class z9i extends Hn{constructor(i){super(rT,i);D(this,"autoexecutable",!0)}getEntityToMatchInputMap(i){return i.inputs.find(n=>{var a;return((a=n.declaration)==null?void 0:a.id)===B.operation[Ge.Validate].inputs.entityToMatch.id})||null}getDataToValidateInputMap(i){return i.inputs.find(n=>{var a;return((a=n.declaration)==null?void 0:a.id)===B.operation[Ge.Validate].inputs.dataToValidate.id})||null}getOutputDataOutputMap(i){return i.outputs.find(n=>{var a;return((a=n.declaration)==null?void 0:a.id)===B.operation[Ge.Validate].dataType.entity.properties.outputEntity.id})||null}getEntityToMatch(i,n=this.project.addChangeSet(new ee(this.project,M.sessionAuthor,j().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 n==null||n.attemptAutoclose("get-entity-to-match-validate-data",this.id),c}syncOperationInstance(i,n=this.project.addChangeSet(new ee(this.project,M.sessionAuthor,j().toISOString(),this,!0,"sync-operation-instance-validate-data"))){const a=[],c=[],e=[],f=[],h=this.getEntityToMatchInputMap(i);if(h){const{added:g,updated:b,removed:R,affected:I}=this.syncEntityToMatchInputMapDataType(h,n);a.push(...b),c.push(...g),e.push(...R),f.push(...I)}const m=this.getDataToValidateInputMap(i);if(m){const{added:g,updated:b,removed:R,affected:I}=this.syncDataToValidateInputMapDataType(m,n);a.push(...b),c.push(...g),e.push(...R),f.push(...I)}const T=this.getOutputDataOutputMap(i);if(T){const{added:g,updated:b,removed:R,affected:I}=this.syncOutputDataOutputMapDataType(T,n);a.push(...b),c.push(...g),e.push(...R),f.push(...I)}return n==null||n.attemptAutoclose("sync-operation-instance-validate-data",this.id),{updated:_(a),added:_(c),removed:_(e),affected:_(f),self:i}}syncEntityToMatchInputMapDataType(i,n=this.project.addChangeSet(new ee(this.project,M.sessionAuthor,j().toISOString(),this,!0,"sync-entity-to-match-input-map-data-type"))){var T,g,b,R,I,C,N,$,x,G,K,Z,H,W,Q,ne,Y,J;const a=[],c=[],e=[],f=[];if(((T=i.declaration)==null?void 0:T.id)!==B.operation[Ge.Validate].inputs.entityToMatch.id)return n==null||n.attemptAutoclose("sync-entity-to-match-input-map-data-type",this.id),{updated:[],added:[],removed:[],affected:[],self:null};const h=((g=this.project.requestActiveDynamicValue(i))==null?void 0:g.value)||null,m=h==null?void 0:h.valueAsTypeSingle;if(!i.dataType){const te={id:M.UUID.uuid(),version:M.UUID.uuid(),createdAt:(n==null?void 0:n.timestamp)||new Date().toISOString(),author:(n==null?void 0:n.author)||M.sessionAuthor,previousVersion:null,deleted:!1,deletable:!0,editable:!0,type:l.DataType,parentRelationType:null,options:((b=i.declaration.dataType)==null?void 0:b.options)||null,implementationChooseOne:((R=i.declaration.dataType)==null?void 0:R.implementationChooseOne)||!1,staticEntities:((I=i.declaration.dataType)==null?void 0:I.staticEntities)??null,interactiveEntities:((C=i.declaration.dataType)==null?void 0:C.interactiveEntities)??null,actionEntities:((N=i.declaration.dataType)==null?void 0:N.actionEntities)??null,index:(($=i.declaration.dataType)==null?void 0:$.index)??null,isList:((x=i.declaration.dataType)==null?void 0:x.isList)||!1,foreignKeyAllowed:((G=i.declaration.dataType)==null?void 0:G.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()},le=Oe(te,i.project);le.hydrateAncestors(),le.addSelfToProject(n),n==null||n.add(le,re.Added),le.setParent(i,n),le.initChildren(n),le.setEntity(m,n),a.push(le),i.setDataType(le,n),n||le.captureVersion()}return(Y=i.dataType)==null||Y.metaSync({inferred:!0,like:!1,asType:!0,options:((K=i.declaration.dataType)==null?void 0:K.options)||null,implementationChooseOne:((Z=i.declaration.dataType)==null?void 0:Z.implementationChooseOne)||!1,staticEntities:((H=i.declaration.dataType)==null?void 0:H.staticEntities)??null,interactiveEntities:((W=i.declaration.dataType)==null?void 0:W.interactiveEntities)??null,actionEntities:((Q=i.declaration.dataType)==null?void 0:Q.actionEntities)??null,isList:((ne=i.declaration.dataType)==null?void 0:ne.isList)||!1},n),(J=i.dataType)==null||J.setEntity(m,n),i.dataType&&c.push(i.dataType),n==null||n.attemptAutoclose("sync-entity-to-match-input-map-data-type",this.id),{updated:_(c),added:_(a),removed:_(e),affected:_(f),self:i.dataType}}syncDataToValidateInputMapDataType(i,n=this.project.addChangeSet(new ee(this.project,M.sessionAuthor,j().toISOString(),this,!0,"sync-data-to-validate-input-map-data-type"))){var g,b,R;const a=[],c=[],e=[],f=[];if(((g=i.declaration)==null?void 0:g.id)!==B.operation[Ge.Validate].inputs.dataToValidate.id)return n==null||n.attemptAutoclose("sync-data-to-validate-input-map-data-type",this.id),{updated:[],added:[],removed:[],affected:[],self:null};const h=this.getEntityToMatchInputMap(i.parent);if(!h)return n==null||n.attemptAutoclose("sync-data-to-validate-input-map-data-type",this.id),{updated:[],added:[],removed:[],affected:[],self:null};if(!this.getEntityToMatch(h,n))return n==null||n.attemptAutoclose("sync-data-to-validate-input-map-data-type",this.id),{updated:[],added:[],removed:[],affected:[],self:null};if(!i.dataType){const I={id:M.UUID.uuid(),version:M.UUID.uuid(),createdAt:(n==null?void 0:n.timestamp)||new Date().toISOString(),author:(n==null?void 0:n.author)||M.sessionAuthor,previousVersion:null,deleted:!1,deletable:!0,editable:!0,type:l.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()},C=Oe(I,i.project);C.hydrateAncestors(),C.addSelfToProject(n),n==null||n.add(C,re.Added),C.setParent(i,n),C.initChildren(n),a.push(C),i.setDataType(C,n),n||C.captureVersion()}(b=i.dataType)==null||b.metaSync({inferred:!0,like:!0,asType:!1},n);const T=this.getEntityToMatch(h,n);return(R=i.dataType)==null||R.setEntity(T,n),i.dataType&&c.push(i.dataType),n==null||n.attemptAutoclose("sync-data-to-validate-input-map-data-type",this.id),{updated:_(c),added:_(a),removed:_(e),affected:_(f),self:i.dataType}}syncOutputDataOutputMapDataType(i,n=this.project.addChangeSet(new ee(this.project,M.sessionAuthor,j().toISOString(),this,!0,"sync-output-data-output-map-data-type"))){var b,R,I,C;const a=[],c=[],e=[],f=[];if(((b=i.declaration)==null?void 0:b.id)!==B.operation[Ge.Validate].dataType.entity.properties.outputEntity.id)return n==null||n.attemptAutoclose("sync-output-data-output-map-data-type",this.id),{updated:[],added:[],removed:[],affected:[],self:null};const h=this.getEntityToMatchInputMap(i.parent);if(!h)return n==null||n.attemptAutoclose("sync-output-data-output-map-data-type",this.id),{updated:[],added:[],removed:[],affected:[],self:null};if(!this.getEntityToMatch(h,n))return n==null||n.attemptAutoclose("sync-output-data-output-map-data-type",this.id),{updated:[],added:[],removed:[],affected:[],self:null};const T=((R=this.project.requestActiveDynamicValue(h))==null?void 0:R.value)||null,g=(T==null?void 0:T.valueAsTypeSingle)||null;if(!i.dataType){const N={id:M.UUID.uuid(),version:M.UUID.uuid(),createdAt:(n==null?void 0:n.timestamp)||new Date().toISOString(),author:(n==null?void 0:n.author)||M.sessionAuthor,previousVersion:null,deleted:!1,deletable:!0,editable:!0,type:l.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:(g==null?void 0:g.toJSON())||null,like:!0,inferred:!0,parent:i.toReference()},$=Oe(N,i.project);$.hydrateAncestors(),$.addSelfToProject(n),n==null||n.add($,re.Added),$.setParent(i,n),$.initChildren(n),$.setEntity(g,n),a.push($),i.setDataType($,n),n||$.captureVersion()}return(I=i.dataType)==null||I.metaSync({inferred:!0,like:!0,asType:!1},n),(C=i.dataType)==null||C.setEntity(g,n),i.dataType&&c.push(i.dataType),n==null||n.attemptAutoclose("sync-output-data-output-map-data-type",this.id),{updated:_(c),added:_(a),removed:_(e),affected:_(f),self:i.dataType}}inferInputMapDataType(i,n=this.project.addChangeSet(new ee(this.project,M.sessionAuthor,j().toISOString(),this,!0,"infer-input-map-data-type-validate-data"))){var c,e,f;if(((c=i.declaration)==null?void 0:c.id)===B.operation[Ge.Validate].inputs.entityToMatch.id){const{added:h,updated:m,removed:T,affected:g}=n?this.syncEntityToMatchInputMapDataType(i,n):{added:[],updated:[],removed:[],affected:[]};return n==null||n.attemptAutoclose("infer-input-map-data-type",this.id),{updated:_(m),added:_(h),removed:_(T),affected:_(g),self:i.dataType}}if(((e=i.declaration)==null?void 0:e.id)===B.operation[Ge.Validate].inputs.dataToValidate.id){const{added:h,updated:m,removed:T,affected:g}=this.syncDataToValidateInputMapDataType(i,n);return n==null||n.attemptAutoclose("infer-input-map-data-type",this.id),{updated:_(m),added:_(h),removed:_(T),affected:_(g),self:i.dataType}}const a=(f=i.declaration)==null?void 0:f.getDataType(n);if(a&&a.isResolved)return n==null||n.attemptAutoclose("infer-input-map-data-type-validate-data",this.id),{updated:[],added:[],removed:[],affected:[],self:a};if(i.readsValue){const h=Xp(i.readsValue,n);return n==null||n.attemptAutoclose("infer-input-map-data-type-validate-data",this.id),{updated:[],added:[],removed:[],affected:[],self:h}}return n==null||n.attemptAutoclose("infer-input-map-data-type-validate-data",this.id),{updated:[],added:[],removed:[],affected:[],self:null}}inferOutputMapDataType(i,n=this.project.addChangeSet(new ee(this.project,M.sessionAuthor,j().toISOString(),this,!0,"infer-output-map-data-type-validate-data"))){var a;if(((a=i.declaration)==null?void 0:a.id)===B.operation[Ge.Validate].dataType.entity.properties.outputEntity.id){const{added:c,updated:e,removed:f,affected:h}=this.syncOutputDataOutputMapDataType(i,n);return n==null||n.attemptAutoclose("infer-output-map-data-type-validate-data",this.id),{updated:_(e),added:_(c),removed:_(f),affected:_(h),self:i.dataType}}return{updated:[],added:[],removed:[],affected:[],self:null}}}class Y9i extends Hn{constructor(u){super(HN,u)}}class J9i extends Hn{constructor(u){super(WN,u)}}class Q9i extends Hn{constructor(u){super(zN,u)}}class X9i extends Hn{constructor(u){super(dD,u)}}class ezi extends Hn{constructor(u){super(O1,u)}}class tzi extends Hn{constructor(u){super(kE,u)}}const gq=B[l.Operation][Ee.GoogleSheetsAppendRows];class izi extends Hn{constructor(u){super(gL,u);const i=this.inputs.find(a=>a.id===gq.inputs.range.id);i&&(i._codeNativeValueValidation=(a,c)=>{const e={errors:[],override:c};if(typeof c=="string"&&c.length>0){const f=c.split("!"),h=f.length>1?f[1]:f[0];/^([A-Za-z]+[0-9]*|[0-9]+)(:[A-Za-z]+[0-9]*|:[0-9]+)?$/.test(h)||e.errors.push(new ui({id:a.id+"--invalid-range-format",message:`Range "${c}" is not a valid A1 notation. Examples of valid ranges: "Sheet1!A1:B2", "A1", "A:B", "1:2".`,severity:De.Error,code:"invalid-range-format",entity:a}))}return e});const n=this.inputs.find(a=>a.id===gq.inputs.values.id);n&&(n._codeNativeValueValidation=(a,c)=>{const e={errors:[],override:c};return c!=null&&(Array.isArray(c)?c.every(h=>Array.isArray(h))||e.errors.push(new ui({id:a.id+"--values-must-be-2d-array",message:'Every element inside the values list must also be a list (a 2D array). Example: [["Row 1", 123], ["Row 2", 456]]',severity:De.Error,code:"values-must-be-2d-array",entity:a})):e.errors.push(new ui({id:a.id+"--values-must-be-array",message:"The values input must be a list of lists (a 2D array). You provided a single non-list value.",severity:De.Error,code:"values-must-be-array",entity:a}))),e})}}function Wrt(s){const u=[new cWe(s),new W9i(s),new z9i(s),new X9i(s),new Y9i(s),new Q9i(s),new J9i(s),new ezi(s),new tzi(s),new izi(s)];return LL.forEach(i=>{u.some(n=>n.id===i.id)||u.push(new Hn(i,s))}),u.forEach(i=>{i.initChildren(null),s.subscribeBuiltInInstance(i)}),s.operationDeclarations=u,u}const nzi=[];function zrt(s){const u=[new YHe(s),new eWe(s),new iWe(s),new nWe(s),new aWe(s),new lWe(s),new dWe(s),new pWe(s)];return uG.forEach(i=>{!u.some(n=>n.id===i.id)&&!nzi.includes(i.id)&&u.push(new ao(i,s))}),u.forEach(i=>{s.subscribeBuiltInInstance(i)}),s.builtInBaseEntities=u,u}function Yrt(s){const u=[];return aN.forEach(i=>{u.some(n=>n.id===i.id)||u.push(new wh(i,s))}),u.forEach(i=>{s.subscribeBuiltInInstance(i)}),s.primitives=u,u}function Jrt(s){const u=[new Hn(Sw,s)];return u.forEach(i=>{i.initChildren(null),s.subscribeBuiltInInstance(i)}),s.globalEventActionDescriptors=u,u}function Qrt(s){const u=[new Hn(Mb,s),new Hn(e0,s),new Hn(Gb,s),new Hn(OT,s),new Hn(PT,s),new Hn(Iw,s)];u.forEach(n=>{n.initChildren(null),s.subscribeBuiltInInstance(n)}),s.loopDeclarations=u;const i=[new Hn(Nw,s),new Hn(Bb,s),new Hn(Cw,s),new Hn(FL,s),new Hn(KL,s),new Hn(Rw,s)];return i.forEach(n=>{n.initChildren(null),s.subscribeBuiltInInstance(n)}),s.loopDeclarationsBodies=i,u}function Xrt(s){const u=[new op(TG,s)];return u.forEach(i=>{i.initChildren(null),s.subscribeBuiltInInstance(i)}),s.valueDescriptors=u,u}function eat(s){const u=[new Hn(cG,s),new Hn(pG,s),new Hn(fG,s),new Hn(yG,s)];return hG.forEach(i=>{u.some(n=>n.id===i.id)||u.push(new Hn(i,s))}),u.forEach(i=>{i.initChildren(null),s.subscribeBuiltInInstance(i)}),s.conditionDeclarations=u,u}function Qg(s){return s&&typeof s.then=="function"}function rzi(s,u){const i=new Ma(s[0],{allBuiltInEntityIds:u.allBuiltInEntityIds}),n=s.map(c=>c.id),a={};return s.forEach(c=>{a[c.id]=c}),i.order=n,i.flatRecord=a,i.orderEntities(),i.order.map(c=>i.flatRecord[c])}function azi(s,u){const i=new Ma(Object.values(s)[0],{allBuiltInEntityIds:u.allBuiltInEntityIds}),n=Object.keys(s);return i.order=n,i.flatRecord=s,i.orderEntities(),i.order}async function szi(s,u){const i=se.YieldTracker.from(u),n=new Ma(s[0],{allBuiltInEntityIds:u.allBuiltInEntityIds}),a=s.map(e=>e.id),c={};for(const e of s)c[e.id]=e,await i.tick();return n.order=a,n.flatRecord=c,await n.orderEntitiesAsync({tracker:i}),n.order.map(e=>n.flatRecord[e])}async function lzi(s,u){const i=se.YieldTracker.from(u),n=new Ma(Object.values(s)[0],{allBuiltInEntityIds:u.allBuiltInEntityIds}),a=Object.keys(s);return n.order=a,n.flatRecord=s,await n.orderEntitiesAsync({tracker:i}),n.order}const fE=class fE{constructor(u,i={}){D(this,"order",[]);D(this,"cachedEntityDependencies",{});D(this,"flatRecord",{});D(this,"allBuiltInEntityIds");D(this,"onGoingVisits",{});D(this,"cachedReferences",{});if(i.allBuiltInEntityIds&&(this.allBuiltInEntityIds=i.allBuiltInEntityIds),!u)return;const n={asyncInitialOrder:!1,...i};n.asyncInitialOrder?this.flattenAsync(u).then(()=>{this.orderEntitiesAsync({...n}).then(()=>{var a;(a=n.onOrdered)==null||a.call(n)})}):(this.flatten(u),this.orderEntities())}flatten(u){this.allBuiltInEntityIds||(this.allBuiltInEntityIds=new Set(BC()));const i=_(Qe(u,new Set(this.allBuiltInEntityIds),{ignoreBuiltInBaseEntities:!0,diggestedBuiltInBaseEntitiesIds:this.allBuiltInEntityIds})),n=new Set;for(const a of i)this.flatRecord[a.id]=a,n.add(a.id);this.order=Array.from(n)}async flattenAsync(u,i={}){const n=se.YieldTracker.from(i);this.allBuiltInEntityIds||(this.allBuiltInEntityIds=await MC({tracker:n}));const a=await Af(await Je(u,new Set(this.allBuiltInEntityIds),{ignoreBuiltInBaseEntities:!0,diggestedBuiltInBaseEntitiesIds:this.allBuiltInEntityIds,tracker:n}),{tracker:n}),c=new Set;for(const e of a)this.flatRecord[e.id]=e,c.add(e.id),await n.tick();this.order=Array.from(c)}getEntityDependencies(u){if(this.cachedEntityDependencies[u])return this.cachedEntityDependencies[u];const i={},n={},a=new Set([u]),c=[u];for(;c.length>0;){const m=c.shift(),T=this.getDirectDependencies(m);for(const g of Object.keys(T.downstream)){const b=this.flatRecord[g];b&&b.parent&&(typeof b.parent=="string"?b.parent:b.parent.entityId||b.parent.id)===m&&(a.has(g)||(a.add(g),c.push(g)))}}const e=new Set;for(const m of a)e.add(m);const f=Array.from(a);for(;f.length>0;){const m=f.shift(),T=this.getDirectDependencies(m);for(const g of Object.keys(T.upstream))e.has(g)||(e.add(g),i[g]=!0,f.push(g))}const h={upstream:i,downstream:n};return this.cachedEntityDependencies[u]=h,h}getDirectDependencies(u){if(!this.cachedReferences[u]){const i=this.flatRecord[u];if(!i)return{upstream:{},downstream:{}};this.cachedReferences[u]=Qd(i,this.flatRecord,{ignoreBuiltInBaseEntities:!0,allBuiltInEntityIds:this.allBuiltInEntityIds})}return this.cachedReferences[u]}moveEntityAfterDependencies(u){const i=this.getEntityDependencies(u.id),{upstream:n}=i;for(const a of Object.keys(n)){const c=this.order.indexOf(a),e=this.order.indexOf(u.id);if(c>e){if(this.getEntityDependencies(a).upstream[u.id])continue;return this.order.splice(e,1),this.order.splice(c,0,u.id),!0}}return!1}orderEntities(u=0){for(const n of this.order)this.getDirectDependencies(n);for(const n of this.order){const a=this.flatRecord[n];if(a&&a.parent){const c=typeof a.parent=="string"?a.parent:a.parent.entityId||a.parent.id;c&&this.cachedReferences[c]&&(this.cachedReferences[c].downstream[n]=!0)}}let i=!1;for(let n=0;n<this.order.length;n++){const a=this.order[n],c=this.flatRecord[a];if(c||se.Logger.warn(`Entity with id ${a} not found in flatRecord. Skipping...`),this.moveEntityAfterDependencies(c)){i=!0;break}}if(i){if(u>fE.MAX_ORDERING_ITERATIONS){console.error("[Traverser] Infinite loop detected in orderEntities!");return}this.orderEntities(u+1)}}async orderEntitiesAsync(u={}){const i=u.iterations||0;for(const c of this.order)this.getDirectDependencies(c);for(const c of this.order){const e=this.flatRecord[c];if(e&&e.parent){const f=typeof e.parent=="string"?e.parent:e.parent.entityId||e.parent.id;f&&this.cachedReferences[f]&&(this.cachedReferences[f].downstream[c]=!0)}}let n=!1;const a=se.YieldTracker.from(u);for(let c=0;c<this.order.length;c++){const e=this.order[c],f=this.flatRecord[e];if(f||se.Logger.warn(`Entity with id ${e} not found in flatRecord. Skipping...`),this.moveEntityAfterDependencies(f)){n=!0;break}await a.tick()}if(n){if(i>fE.MAX_ORDERING_ITERATIONS){console.error("[Traverser] Infinite loop detected in orderEntitiesAsync!");return}await this.orderEntitiesAsync({tracker:a,iterations:i+1})}}getUpstreamOngoingDependenciesVisits(u,i){const n=this.cachedReferences[u]||Qd(this.flatRecord[u],this.flatRecord,{ignoreBuiltInBaseEntities:!0,allBuiltInEntityIds:this.allBuiltInEntityIds});this.cachedReferences[u]=n;const{upstream:a}=n,c={};return Object.entries(this.onGoingVisits[i]||{}).forEach(([e,f])=>{Object.keys(a).includes(e)&&(c[e]=f)}),c}getDownstreamOngoingDependenciesVisits(u,i){const n=Object.keys(this.onGoingVisits[i]||{}),a=new Set(n.flatMap(e=>{const f=this.cachedReferences[e]||Qd(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===u&&(c[e]=this.onGoingVisits[i][e])}),c}async settlePromises(u,i){const n=Object.values(u);n.length&&await Promise.all(n),Object.keys(u).forEach(a=>{delete this.onGoingVisits[i][a]})}visit(u){const i=this.order;for(const n of i)u(this.flatRecord[n],this.flatRecord);return this}reverseVisit(u){const i=this.order.slice().reverse();for(const n of i)u(this.flatRecord[n],this.flatRecord);return this}async visitAsync(u,i={}){const{parallelise:n}={parallelise:!0,...i},a=se.YieldTracker.from(i),c=this.order;if(!n){for(const f of c){const h=u(this.flatRecord[f],this.flatRecord);Qg(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=u(this.flatRecord[f],this.flatRecord);Qg(m)&&(this.onGoingVisits[e][f]=m),await a.tick()}return await this.settlePromises(this.onGoingVisits[e],e),this.onGoingVisits[e]={},this}async reverseVisitAsync(u,i={}){const{parallelise:n}={parallelise:!0,...i},a=se.YieldTracker.from(i),c=this.order.slice().reverse();if(!n){for(const f of c){const h=u(this.flatRecord[f],this.flatRecord);Qg(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=u(this.flatRecord[f],this.flatRecord);Qg(m)&&(this.onGoingVisits[e][f]=m),await a.tick()}return await this.settlePromises(this.onGoingVisits[e],e),this.onGoingVisits[e]={},this}};D(fE,"MAX_ORDERING_ITERATIONS",1e4);let Ma=fE;const vh={},gR={},PE={empty:!1,enrich:!0,mock:!1,ignoreCache:!1,onFetch:async()=>null,manuallyInit:!1};function tat(s,u={enrich:!0,shallowErrors:!1},i){const n={enrich:!0,shallowErrors:!1,...u},{enrich:a,shallowErrors:c}=n,e=s.project,f=s.record,h=xC(s.project,{shallowErrors:c},i);h.instances[e.id]=h;const m=new Ma(e,{allBuiltInEntityIds:h.diggestedBuiltInBaseEntitiesIds}),T=new Set;f[e.id]=e,T.add(e.id);const g=j().toISOString();Object.values(f).forEach(R=>{!R||m.allBuiltInEntityIds.has(R.id)||T.add(R.id)}),m.order=Array.from(T),m.flatRecord=f,m.orderEntities();const b=a?h.addChangeSet(new ee(h,M.sessionAuthor,g,h,!0,"project-init-from-fetch-result")):null;return m.visit(R=>{if(R.id===h.id)return;const I=Oe(R,h);try{I.hydrateAncestors(),I.addSelfToProject(null);const C=Qd(R);Object.keys(C.downstream).forEach(N=>{const $=h.get(N);$&&$.hydrateAncestors()})}catch(C){if(c)se.Logger.error("Error hydrating ancestors: ",C);else throw C}}),a?(m.visit(R=>{if(R.id===h.id)return;const I=h.get(R.id);if(I)try{I.afterAllChildrenInitialized(b),I.captureVersion()}catch(C){if(c)se.Logger.error("Error in afterAllChildrenInitialized: ",C);else throw C}}),h.afterAllChildrenInitialized(b),h.subscribe(),h.captureVersion()):(kc(h,g).forEach(I=>{I.remove({ignoreUpstream:!0},null)}),m.visit(I=>{if(I.id===h.id)return;const C=h.get(I.id);C&&(C.initialized=!0,C.captureVersion())}),h.initialized=!0,h.subscribe(),h.captureVersion()),h.initialized=!0,h.emit(nn.PROJECT_INITIALIZED,h,b),b==null||b.attemptAutoclose("project-init-from-fetch-result",h.id),h}async function ozi(s,u={enrich:!0,shallowErrors:!1,yieldEvery:100},i){const n={enrich:!0,shallowErrors:!1,yieldEvery:100,...u},{enrich:a,shallowErrors:c,yieldEvery:e}=n,f=se.YieldTracker.from({yieldEvery:e}),h=s.project,m=s.record,T=await VC(s.project,{shallowErrors:c,tracker:f},i);T.instances[h.id]=T;const g=new Ma(void 0,{allBuiltInEntityIds:T.diggestedBuiltInBaseEntitiesIds});await g.flattenAsync(h,{tracker:f}),await g.orderEntitiesAsync({tracker:f});const b=new Set;m[h.id]=h,b.add(h.id);const R=j().toISOString();for(const[C,N]of Object.entries(m))!N||g.allBuiltInEntityIds.has(N.id)||(b.add(N.id),await f.tick());g.order=Array.from(b),g.flatRecord=m,await g.orderEntitiesAsync({tracker:f});const I=a?T.addChangeSet(new ee(T,M.sessionAuthor,R,T,!0,"project-init-from-fetch-result")):null;if(await g.visitAsync(C=>{if(C.id===T.id)return;const N=Oe(C,T);try{N.hydrateAncestors(),N.addSelfToProject(null);const $=Qd(C);Object.keys($.downstream).forEach(x=>{const G=T.get(x);G&&G.hydrateAncestors()})}catch($){if(c)se.Logger.error("Error hydrating ancestors: ",$);else throw se.Logger.log("Error hydrating ancestors: ",$),$}},{tracker:f}),a){try{await g.visitAsync(C=>{if(C.id===T.id)return;const N=T.get(C.id);N&&(N.afterAllChildrenInitialized(I),N.captureVersion())},{tracker:f})}catch(C){if(c)se.Logger.error("Error in afterAllChildrenInitialized: ",C);else throw se.Logger.log("Error in afterAllChildrenInitialized: ",C),C}T.afterAllChildrenInitialized(I),T.subscribe(),T.captureVersion()}else kc(T,R).forEach(N=>{N.remove({ignoreUpstream:!0},null)}),await g.visitAsync(N=>{if(N.id===T.id)return;const $=T.get(N.id);$&&($.initialized=!0,$.captureVersion())},{tracker:f}),T.initialized=!0,T.subscribe(),T.captureVersion();return T.initialized=!0,T.emit(nn.PROJECT_INITIALIZED,T,I),I==null||I.attemptAutoclose("project-init-from-fetch-result",T.id),T}async function dzi(s,u=PE){const i={...PE,...u};if(i.empty)return{data:{project:{id:s.id,workspaceId:"",deletable:!0,editable:!0,type:l.Project,version:M.UUID.uuid(),createdAt:j().toISOString(),author:M.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={...TM};return a.id=s.id,{data:{project:a,record:{}}}}return se.Logger.log("Fetching project from external API"),new Promise(async a=>{try{if(i.onFetch){const c=await i.onFetch(s.id);if(c){a({data:c});return}}else a({data:null})}catch(c){se.Logger.error("Error fetching project: ",c),a({data:null})}})}function xC(s,u={shallowErrors:!1},i){const n=new M(s,i);Yrt(n),zrt(n),Wrt(n),Jrt(n),Qrt(n),Xrt(n),eat(n);const a=u.allBuiltInIds??new Set([...n.getAllBuiltInIds(),...BC()]);return n.diggestedBuiltInBaseEntitiesIds=a,a.forEach(c=>{if(!n.builtInInstances[c]&&n.instances[c])n.builtInInstances[c]=n.instances[c],delete n.instances[c];else if(!n.builtInInstances[c]&&!u.shallowErrors)throw new Error(`Built in entity was not properly initialized: ${c}`)}),n.instances[n.id]=n,n.activeVersion=!0,n}async function VC(s,u={shallowErrors:!1},i){const n=se.YieldTracker.from(u),a=new M(s,i);Yrt(a),zrt(a),await se.yieldToEventLoop(),Wrt(a),await se.yieldToEventLoop(),Jrt(a),Qrt(a),Xrt(a),eat(a),await se.yieldToEventLoop();const c=u.allBuiltInIds??new Set([...a.getAllBuiltInIds(),...await MC()]);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]&&!u.shallowErrors)throw new Error(`Built in entity was not properly initialized: ${e}`);a.instances[e]&&delete a.instances[e],await n.tick()}return a.instances[a.id]=a,a.activeVersion=!0,a}function kc(s,u){return s.instancesList.filter(n=>j(n.createdAt).isAfter(j(u)||!!n.previousVersion))}function uzi(s,{enrich:u,shallowErrors:i,...n}={enrich:!0,shallowErrors:!1},a){var R,I;const c=new Map,e=new Map;Object.keys(s.instances).forEach(C=>{if(s.diggestedBuiltInBaseEntitiesIds.has(C)){c.set(C,C),e.set(C,C);return}const N=s.get(C);if(!KC(N,{...s.instances,...s.builtInInstances}).every(G=>!s.diggestedBuiltInBaseEntitiesIds.has(G))){c.set(C,C),e.set(C,C);return}if(n.keepIds)c.set(C,C),e.set(C,C);else{const G=M.UUID.uuid();c.set(C,G),e.set(G,C)}});const f=((R=n.resetVersionOptions)==null?void 0:R.commonTimestamp)??j().toISOString(),h=s.toShallowJSON({seenEntityMaps:c});h.previousVersion=null,h.createdAt=f,h.version=M.UUID.uuid(),h.author=((I=n.resetVersionOptions)==null?void 0:I.author)??(M.sessionAuthor||"1");const m=xC(h,{shallowErrors:i,allBuiltInIds:s.diggestedBuiltInBaseEntitiesIds},a);m.instances[m.id]=m;const T=u?m.addChangeSet(new ee(m,M.sessionAuthor,f,m,!0,"project-clone")):null,g=new Ma(s,{allBuiltInEntityIds:s.diggestedBuiltInBaseEntitiesIds}),b=R2(g.flatRecord,c);return g.visit(C=>{var G;const N=C.toShallowJSON({seenEntityMaps:c});N.previousVersion=null,N.createdAt=f,N.version=M.UUID.uuid(),N.author=((G=n.resetVersionOptions)==null?void 0:G.author)??(M.sessionAuthor||"1");const $=Qd(N,b);if(Object.keys($.upstream).length){let K=!1;if(Object.keys($.upstream).forEach(Z=>{if(!K&&(!m.get(Z)||m.getDeleted(Z))){K=!0;return}}),K)return}const x=Oe(N,m);x.hydrateAncestors(),x.addSelfToProject(T),T==null||T.add(x,re.Added),n.onVisit&&n.onVisit(N)}),u?(g.visit(C=>{if(C.id===m.id)return;const N=m.get(c.get(C.id));N&&(N.afterAllChildrenInitialized(T),N.captureVersion())}),m.afterAllChildrenInitialized(T),m.subscribe(),m.captureVersion()):(kc(m,f).forEach(N=>{N.remove({ignoreUpstream:!0},null)}),g.visit(N=>{if(N.id===m.id)return;const $=m.get(N.id);$&&($.initialized=!0,$.captureVersion())}),m.initialized=!0,m.subscribe(),m.captureVersion()),m.instancesList.forEach(C=>{C.previousVersion=null}),T==null||T.attemptAutoclose("project-clone",m.id),{project:m,maps:c}}async function pzi(s,{shallowErrors:u,...i}={shallowErrors:!1,yieldEvery:100}){var m,T;const n=se.YieldTracker.from(i),a=new Map,c=new Map;Object.keys(s.instances).forEach(g=>{if(s.diggestedBuiltInBaseEntitiesIds.has(g)){a.set(g,g),c.set(g,g);return}const b=M.UUID.uuid();a.set(g,b),c.set(b,g)});const e=((m=i.resetVersionOptions)==null?void 0:m.commonTimestamp)??j().toISOString(),f=s.toShallowJSON({seenEntityMaps:a});f.previousVersion=null,f.createdAt=e,f.version=M.UUID.uuid(),f.author=((T=i.resetVersionOptions)==null?void 0:T.author)??(M.sessionAuthor||"1");const h=await s.toFullProjectTransferAsync({tracker:n,seenEntityMaps:a,resetVersionOptions:i.resetVersionOptions,onVisit:i.onVisit});return{project:f,record:h.record,order:h.order,maps:a}}async function czi(s,{enrich:u,shallowErrors:i,...n}={enrich:!0,shallowErrors:!1,yieldEvery:100},a){var I,C;const c=se.YieldTracker.from(n),e=new Map,f=new Map;for(const N of Object.keys(s.instances)){if(s.diggestedBuiltInBaseEntitiesIds.has(N)){e.set(N,N),f.set(N,N),await c.tick();continue}if(n.keepIds)e.set(N,N),f.set(N,N);else{const $=M.UUID.uuid();e.set(N,$),f.set($,N)}await c.tick()}const h=((I=n.resetVersionOptions)==null?void 0:I.commonTimestamp)??j().toISOString(),m=s.toShallowJSON({seenEntityMaps:e});m.previousVersion=null,m.createdAt=h,m.version=M.UUID.uuid(),m.author=((C=n.resetVersionOptions)==null?void 0:C.author)??(M.sessionAuthor||"1");const T=await VC(m,{shallowErrors:i,tracker:c},a);T.diggestedBuiltInBaseEntitiesIds=s.diggestedBuiltInBaseEntitiesIds,T.instances[T.id]=T;const g=u?T.addChangeSet(new ee(T,M.sessionAuthor,h,T,!0,"project-clone")):null,b=new Ma(void 0,{allBuiltInEntityIds:s.diggestedBuiltInBaseEntitiesIds}),R=await s.toFullProjectTransferAsync({tracker:c,seenEntityMaps:e,resetVersionOptions:n.resetVersionOptions,onVisit:n.onVisit,shallowErrors:i});b.flatRecord=R.record,b.order=R.order,await b.visitAsync(N=>{var K;if(s.diggestedBuiltInBaseEntitiesIds.has(N.id))return;const $=N;$.previousVersion=null,$.createdAt=h,$.version=M.UUID.uuid(),$.author=((K=n.resetVersionOptions)==null?void 0:K.author)??(M.sessionAuthor||"1");const x=Qd($,b.flatRecord);if(Object.keys(x.upstream).length){let Z=!1;if(Object.keys(x.upstream).forEach(H=>{if(!Z&&(!T.get(H)||T.getDeleted(H))){Z=!0;return}}),Z)return}const G=Oe($,T);G.hydrateAncestors(),G.addSelfToProject(g),g==null||g.add(G,re.Added)},{tracker:c}),u?(await b.visitAsync(N=>{if(N.id===T.id||s.diggestedBuiltInBaseEntitiesIds.has(N.id))return;const $=T.get(e.get(N.id));$&&($.afterAllChildrenInitialized(g),$.captureVersion())},{tracker:c}),T.afterAllChildrenInitialized(g),T.subscribe(),T.captureVersion()):(kc(T,h).forEach($=>{$.remove({ignoreUpstream:!0},null)}),await b.visitAsync($=>{if($.id===T.id)return;const x=T.get($.id);x&&(x.initialized=!0,x.captureVersion())},{tracker:c}),T.initialized=!0,T.subscribe(),T.captureVersion());for(const N of T.instancesList)N.previousVersion=null,await c.tick();return g==null||g.attemptAutoclose("project-clone",T.id),{project:T,maps:e}}function fzi(s,u,i=u.addChangeSet(new ee(u,M.sessionAuthor,j().toISOString(),u,!0,P.AfterAllChildrenInitialized)),{enrich:n,shallowErrors:a,...c}={shallowErrors:!1,enrich:!0}){var b,R;const e=new Map,f=new Map;Object.keys(s.instances).forEach(I=>{if(s.diggestedBuiltInBaseEntitiesIds.has(I)){e.set(I,I),f.set(I,I);return}if(I===s.id){e.set(I,u.id),f.set(u.id,I);return}const C=s.get(I);if(!KC(C,{...s.instances,...s.builtInInstances}).every(G=>!s.diggestedBuiltInBaseEntitiesIds.has(G))){e.set(I,I),f.set(I,I);return}const x=M.UUID.uuid();e.set(I,x),f.set(x,I)});const h=((b=c.resetVersionOptions)==null?void 0:b.commonTimestamp)??j().toISOString(),m=s.toShallowJSON({seenEntityMaps:e});m.previousVersion=null,m.createdAt=h,m.version=M.UUID.uuid(),m.author=((R=c.resetVersionOptions)==null?void 0:R.author)??(M.sessionAuthor||"1");const T=new Ma(s,{allBuiltInEntityIds:s.diggestedBuiltInBaseEntitiesIds}),g=R2(T.flatRecord,e);return T.visit(I=>{var $;if(I.id===u.id)return;const C=I.toShallowJSON({seenEntityMaps:e});C.previousVersion=null,C.createdAt=h,C.version=M.UUID.uuid(),C.author=(($=c.resetVersionOptions)==null?void 0:$.author)??(M.sessionAuthor||"1");const N=Qd(C,g);if(Object.keys(N.upstream).length){let x=!1;if(Object.keys(N.upstream).forEach(G=>{if(!x&&(!u.get(G)||u.getDeleted(G))){x=!0;return}}),x)return}try{const x=Oe(C,u);x.hydrateAncestors(),x.addSelfToProject(i),i==null||i.add(x,re.Added),c.onVisit&&c.onVisit(C)}catch(x){if(a)se.Logger.error("Error cloning entity onto existing project: ",x);else throw se.Logger.log("Error cloning entity onto existing project: ",x),x}}),n?(T.visit(I=>{if(I.id===u.id)return;const C=u.get(e.get(I.id));C&&(C.afterAllChildrenInitialized(i),C.previousVersion=null,C.captureVersion())}),u.afterAllChildrenInitialized(i),u.subscribe(),u.captureVersion()):(kc(u,h).forEach(C=>{C.remove({ignoreUpstream:!0},null)}),T.visit(C=>{if(C.id===u.id)return;const N=u.get(C.id);N&&(N.initialized=!0,N.previousVersion=null,N.captureVersion())}),u.initialized=!0,u.subscribe(),u.captureVersion()),u.afterAllChildrenInitialized(i),u.captureVersion(),{project:u,maps:e,changeSet:i}}async function yzi(s,u,i=u.addChangeSet(new ee(u,M.sessionAuthor,j().toISOString(),u,!0,P.AfterAllChildrenInitialized)),{enrich:n,shallowErrors:a,...c}={enrich:!0,shallowErrors:!1,yieldEvery:100}){var R,I;const e=se.YieldTracker.from(c),f=new Map,h=new Map;for(const C of Object.keys(s.instances)){if(s.diggestedBuiltInBaseEntitiesIds.has(C)){f.set(C,C),h.set(C,C),await e.tick();continue}if(C===s.id){f.set(C,u.id),h.set(u.id,C),await e.tick();continue}const N=M.UUID.uuid();f.set(C,N),h.set(N,C),await e.tick()}const m=((R=c.resetVersionOptions)==null?void 0:R.commonTimestamp)??j().toISOString(),T=s.toShallowJSON({seenEntityMaps:f});T.previousVersion=null,T.createdAt=m,T.version=M.UUID.uuid(),T.author=((I=c.resetVersionOptions)==null?void 0:I.author)??(M.sessionAuthor||"1"),u.diggestedBuiltInBaseEntitiesIds=s.diggestedBuiltInBaseEntitiesIds;const g=new Ma(void 0,{allBuiltInEntityIds:s.diggestedBuiltInBaseEntitiesIds}),b=await s.toFullProjectTransferAsync({tracker:e,seenEntityMaps:f,resetVersionOptions:c.resetVersionOptions,onVisit:c.onVisit,shallowErrors:a});return g.flatRecord=b.record,g.order=b.order,await g.visitAsync(C=>{var x;if(s.diggestedBuiltInBaseEntitiesIds.has(C.id)||C.id===u.id)return;const N=C;N.previousVersion=null,N.createdAt=m,N.version=M.UUID.uuid(),N.author=((x=c.resetVersionOptions)==null?void 0:x.author)??(M.sessionAuthor||"1");const $=Qd(N,g.flatRecord);if(Object.keys($.upstream).length){let G=!1;if(Object.keys($.upstream).forEach(K=>{if(!G&&(!u.get(K)||u.getDeleted(K))){G=!0;return}}),G)return}try{const G=Oe(N,u);G.hydrateAncestors(),G.addSelfToProject(i),i==null||i.add(G,re.Added)}catch(G){if(a)se.Logger.error("Error cloning entity onto existing project: ",G);else throw se.Logger.log("Error cloning entity onto existing project: ",G),G}},{tracker:e}),n?(await g.visitAsync(C=>{if(C.id===u.id||s.diggestedBuiltInBaseEntitiesIds.has(C.id))return;const N=u.get(f.get(C.id));N&&(N.afterAllChildrenInitialized(i),N.previousVersion=null,N.captureVersion())},{tracker:e}),u.afterAllChildrenInitialized(i),u.subscribe(),u.captureVersion()):(kc(u,m).forEach(N=>{N.remove({ignoreUpstream:!0},null)}),await g.visitAsync(N=>{if(N.id===u.id)return;const $=u.get(N.id);$&&($.initialized=!0,$.previousVersion=null,$.captureVersion())},{tracker:e}),u.initialized=!0,u.subscribe(),u.captureVersion()),u.afterAllChildrenInitialized(i),u.captureVersion(),{project:u,maps:f,changeSet:i}}function iat(s,{enrich:u,shallowErrors:i}={enrich:!0,shallowErrors:!1},n){const a=xC(s,{shallowErrors:i},n);a.activeVersion=!0;const c=j().toISOString(),e=u?a.addChangeSet(new ee(a,M.sessionAuthor,c,a,!0,"project-init")):null;e&&(e.type=Kw.Automatic);const f=new Ma(s,{allBuiltInEntityIds:a.diggestedBuiltInBaseEntitiesIds});return f.visit(h=>{const m=Oe(h,a);m.hydrateAncestors(),m.addSelfToProject(e)}),u?(f.visit(h=>{if(h.id===a.id)return;const m=a.get(h.id);m&&(m.afterAllChildrenInitialized(e),m.captureVersion())}),a.afterAllChildrenInitialized(e),a.subscribe(),a.captureVersion()):(kc(a,c).forEach(m=>{m.remove({ignoreUpstream:!0},null)}),f.visit(m=>{if(m.id===a.id)return;const T=a.get(m.id);T&&(T.initialized=!0,T.captureVersion())}),a.initialized=!0,a.subscribe(),a.captureVersion()),a.initialized=!0,a.emit(nn.PROJECT_INITIALIZED,a,e),e==null||e.attemptAutoclose("project-init",a.id),a}async function hzi(s,{enrich:u,shallowErrors:i,yieldEvery:n}={enrich:!0,shallowErrors:!1,yieldEvery:100},a){const c=se.YieldTracker.from({yieldEvery:n}),e=await VC(s,{shallowErrors:i,tracker:c},a),f=j().toISOString(),h=u?e.addChangeSet(new ee(e,M.sessionAuthor,f,e,!0,"project-init")):null;h&&(h.type=Kw.Automatic);const m=new Ma(void 0,{allBuiltInEntityIds:e.diggestedBuiltInBaseEntitiesIds});return await m.flattenAsync(s,{tracker:c}),await m.orderEntitiesAsync({tracker:c}),await m.visitAsync(T=>{const g=Oe(T,e);g.hydrateAncestors(),g.addSelfToProject(h)},{tracker:c}),u?(await m.visitAsync(T=>{if(T.id===e.id)return;const g=e.get(T.id);g&&(g.afterAllChildrenInitialized(h),g.captureVersion())},{tracker:c}),e.afterAllChildrenInitialized(h),e.subscribe(),e.captureVersion()):(kc(e,f).forEach(g=>{g.remove({ignoreUpstream:!0},null)}),await m.visitAsync(g=>{if(g.id===e.id)return;const b=e.get(g.id);b&&(b.initialized=!0,b.captureVersion())},{tracker:c}),e.initialized=!0,e.subscribe(),e.captureVersion()),e.initialized=!0,e.emit(nn.PROJECT_INITIALIZED,e,h),h==null||h.attemptAutoclose("project-init",e.id),e}async function mzi(s,u=PE,i){const n={...PE,...u};if(s.id&&vh[s.id]&&!n.ignoreCache)return vh[s.id];if(s.id&&gR[s.id]&&!n.ignoreCache)return await gR[s.id],vh[s.id];const a=dzi(s,n);s.id&&(gR[s.id]=a);const c=await a;if(c.data){let e;return n.mock?e=iat(TM,{enrich:!!n.enrich},i):c.data instanceof M?e=c.data:e=tat(c.data,{enrich:!!n.enrich},i),vh[s.id]=e,s.id&&delete gR[s.id],e}return null}function Tzi(s){return vh[s.id]&&delete vh[s.id],null}const _E=Yt([st(),rl(),Cr(),sc()]),nat=LT([ba.CurrentDateAndTime,ba.Random,ba.Unique]),NC=Dt({type:nat,rangeStart:_E.nullable(),rangeEnd:_E.nullable()}),mA=NC.extend({type:It(ba.Random),rangeStart:_E,rangeEnd:_E}),rat=NC.extend({type:It(ba.Unique),rangeStart:ro(),rangeEnd:ro()}),aat=NC.extend({type:It(ba.CurrentDateAndTime),rangeStart:ro(),rangeEnd:ro()}),$C=mA.extend({rangeStart:rl().nullable(),rangeEnd:rl().nullable()}),sat=$C.extend({rangeStart:rl(),rangeEnd:ro()}),lat=$C.extend({rangeStart:ro(),rangeEnd:rl()}),oat=$C.extend({rangeStart:rl(),rangeEnd:rl()}),LC=mA.extend({rangeStart:rl().nullable(),rangeEnd:rl().nullable()}),dat=LC.extend({rangeStart:rl(),rangeEnd:ro()}),uat=LC.extend({rangeStart:ro(),rangeEnd:rl()}),pat=LC.extend({rangeStart:rl(),rangeEnd:rl()}),GC=mA.extend({rangeStart:sc().nullable(),rangeEnd:sc().nullable()}),cat=GC.extend({rangeStart:sc(),rangeEnd:ro()}),fat=GC.extend({rangeStart:ro(),rangeEnd:sc()}),yat=GC.extend({rangeStart:sc(),rangeEnd:sc()}),hat=mA.extend({rangeStart:ro(),rangeEnd:ro()}),mat=Yt([dat,uat,pat]),Tat=Yt([sat,lat,oat]),vat=Yt([cat,fat,yat,aat]),vzi=Yt([mat,Tat,vat,rat,hat]);function BC(){const s=new Set;return new Set(vG.flatMap(i=>Qe(i,s)).map(i=>i.id))}function Pu(s){return[...s.calledByEntry||[],...s.calledByError||[],...s.calledBySuccess||[]].filter(u=>u.type!==l.GenericReference)}function gat(s,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(s.id))return[];if(u.add(s.id),s.type!==l.ActionDescriptor)throw new Error("Entity must be an action descriptor to be flattened");return[s,...s.inputs.flatMap(n=>Qe(n,u,i)),...s.dataType?Qe(s.dataType,u,i):[],...s.error?Qe(s.error,u,i):[],...s.parent?Qe(s.parent,u,i):[]]}function Eat(s,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(s.id))return[];if(u.add(s.id),s.type!==l.ArgumentDeclaration)throw new Error("Entity must be an argument declaration to be flattened");return[s,...s.defaultValue?Qe(s.defaultValue,u):[],...s.writesValues.flatMap(n=>Qe(n,u,i)),...s.implements.flatMap(n=>Qe(n,u,i)),...s.dataType?Qe(s.dataType,u,i):[],...s.parent?Qe(s.parent,u,i):[]]}function bat(s,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(s.id))return[];if(u.add(s.id),s.type!==l.BreakStatement)throw new Error("Entity must be a break statement to be flattened");return[s,...s.outputs.flatMap(n=>Qe(n,u,i)),...s.throws?Qe(s.throws,u,i):[],...s.dataType?Qe(s.dataType,u,i):[],...s.readsValue?Qe(s.readsValue,u,i):[],...(Pu(s)||[]).flatMap(n=>Qe(n,u,i)),...s.parent?Qe(s.parent,u,i):[]]}function Aat(s,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(s.id))return[];if(u.add(s.id),s.type!==l.BuiltInBaseEntity)throw new Error("Entity must be a built-in base entity to be flattened");return[s,...(s.properties||[]).flatMap(n=>Qe(n,u,i)),...(s.methods||[]).flatMap(n=>Qe(n,u,i)),...(s.abstractMethods||[]).flatMap(n=>Qe(n,u,i)),...s.allPropertiesImplement?Qe(s.allPropertiesImplement,u,i):[],...s.additionalPropertiesDataType?Qe(s.additionalPropertiesDataType,u,i):[],...s.extends?Qe(s.extends,u,i):[]]}function Iat(s,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(s.id))return[];if(u.add(s.id),s.type!==l.Condition)throw new Error("Entity must be a condition to be flattened");return[s,...(s.andChildrenGroup||[]).flatMap(n=>Qe(n,u,i)),...(s.orChildrenGroup||[]).flatMap(n=>Qe(n,u,i)),...(s.inputs||[]).flatMap(n=>Qe(n,u,i)),...(s.successCalls||[]).flatMap(n=>Qe(n,u,i)),...(s.errorCalls||[]).flatMap(n=>Qe(n,u,i)),...(Pu(s)||[]).flatMap(n=>Qe(n,u,i)),...s.parent?Qe(s.parent,u,i):[]]}function Rat(s,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(s.id))return[];if(u.add(s.id),s.type!==l.ContinueStatement)throw new Error("Entity must be a continue statement to be flattened");return[s,...s.outputs.flatMap(n=>Qe(n,u,i)),...s.readsValue?Qe(s.readsValue,u,i):[],...s.throws?Qe(s.throws,u,i):[],...s.dataType?Qe(s.dataType,u,i):[],...(Pu(s)||[]).flatMap(n=>Qe(n,u,i)),...s.parent?Qe(s.parent,u,i):[]]}function Dat(s,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(s.id))return[];if(u.add(s.id),s.type!==l.DefinitionEntity)throw new Error("Entity must be a definition entity to be flattened");return[s,...s.extends?Qe(s.extends,u,i):[],...(s.implements||[]).flatMap(n=>Qe(n,u,i)),...(s.properties||[]).flatMap(n=>Qe(n,u,i)),...(s.methods||[]).flatMap(n=>Qe(n,u,i)),...(s.abstractMethods||[]).flatMap(n=>Qe(n,u,i)),...s.allPropertiesImplement?Qe(s.allPropertiesImplement,u,i):[],...s.additionalPropertiesDataType?Qe(s.additionalPropertiesDataType,u,i):[],...s.parent?Qe(s.parent,u,i):[]]}function wat(s,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(s.id))return[];if(u.add(s.id),s.type!==l.DataType)throw new Error("Entity must be a data type to be flattened");return[s,...(s.andChildrenGroup||[]).flatMap(n=>Qe(n,u,i)),...(s.orChildrenGroup||[]).flatMap(n=>Qe(n,u,i)),...s.entity?Qe(s.entity,u,i):[],...s.foreignKeyRef?Qe(s.foreignKeyRef,u,i):[],...s.parent?Qe(s.parent,u,i):[]]}function Cat(s,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(s.id))return[];if(u.add(s.id),s.type!==l.FunctionCall)throw new Error("Entity must be a function call to be flattened");return[s,...(s.inputs||[]).flatMap(n=>Qe(n,u,i)),...(s.outputs||[]).flatMap(n=>Qe(n,u,i)),...s.error?Qe(s.error,u,i):[],...(Pu(s)||[]).flatMap(n=>Qe(n,u,i)),...(s.successCalls||[]).flatMap(n=>Qe(n,u,i)),...(s.errorCalls||[]).flatMap(n=>Qe(n,u,i)),...(s.writesValues||[]).flatMap(n=>Qe(n,u,i)),...s.parent?Qe(s.parent,u,i):[]]}function Oat(s,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(s.id))return[];if(u.add(s.id),s.type!==l.FunctionDeclaration)throw new Error("Entity must be a function declaration to be flattened");return[s,...(s.inputs||[]).flatMap(n=>Qe(n,u,i)),...(s.calls||[]).flatMap(n=>Qe(n,u,i)),...s.dataType?Qe(s.dataType,u,i):[],...s.implements?Qe(s.implements,u,i):[],...s.parent?Qe(s.parent,u,i):[]]}function Pat(s,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(s.id))return[];if(u.add(s.id),s.type!==l.GlobalEvent)throw new Error("Entity must be a global event to be flattened");return[s,...(s.inputs||[]).flatMap(n=>Qe(n,u,i)),...(s.calls||[]).flatMap(n=>Qe(n,u,i)),...s.implements?Qe(s.implements,u,i):[],...s.parent?Qe(s.parent,u,i):[]]}function _at(s,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(s.id))return[];if(u.add(s.id),s.type!==l.InputMap)throw new Error("Entity must be an input map to be flattened");return[s,...s.readsValue?Qe(s.readsValue,u,i):[],...s.declaration?Qe(s.declaration,u,i):[],...s.defaultValue?Qe(s.defaultValue,u,i):[],...s.parent?Qe(s.parent,u,i):[]]}function xat(s,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(s.id))return[];if(u.add(s.id),s.type!==l.InstalledProject)throw new Error("Entity must be an installed project to be flattened");return[s,...(s.functions||[]).flatMap(n=>Qe(n,u,i)),...(s.events||[]).flatMap(n=>Qe(n,u,i)),...s.parent?Qe(s.parent,u,i):[]]}function Vat(s,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(s.id))return[];if(u.add(s.id),s.type!==l.InternalCall)throw new Error("Entity must be an internal call to be flattened");return[s,...(s.successCalls||[]).flatMap(n=>Qe(n,u,i)),...(s.errorCalls||[]).flatMap(n=>Qe(n,u,i)),...(s.inputs||[]).flatMap(n=>Qe(n,u,i)),...(s.outputs||[]).flatMap(n=>Qe(n,u,i)),...(Pu(s)||[]).flatMap(n=>Qe(n,u,i)),...s.error?Qe(s.error,u,i):[],...(s.writesValues||[]).flatMap(n=>Qe(n,u,i)),...s.parent?Qe(s.parent,u,i):[]]}function Nat(s,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(s.id))return[];if(u.add(s.id),s.type!==l.LiteralValue)throw new Error("Entity must be a literal value to be flattened");return[s,...s.valueAsTypeSingle?Qe(s.valueAsTypeSingle,u,i):[],...s.valueAsTypeList&&Array.isArray(s.valueAsTypeList)?s.valueAsTypeList.flatMap(n=>Qe(n,u,i)):[],...s.parent?Qe(s.parent,u,i):[]]}function $at(s,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(s.id))return[];if(u.add(s.id),s.type!==l.Loop)throw new Error("Entity must be a loop to be flattened");return[s,...(s.inputs||[]).flatMap(n=>Qe(n,u,i)),...(s.outputs||[]).flatMap(n=>Qe(n,u,i)),...(s.successCalls||[]).flatMap(n=>Qe(n,u,i)),...(s.errorCalls||[]).flatMap(n=>Qe(n,u,i)),...s.error?Qe(s.error,u,i):[],...s.dataType?Qe(s.dataType,u,i):[],...s.body?Qe(s.body,u,i):[],...(Pu(s)||[]).flatMap(n=>Qe(n,u,i)),...(s.writesValues||[]).flatMap(n=>Qe(n,u,i)),...s.parent?Qe(s.parent,u,i):[]]}function Lat(s,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(s.id))return[];if(u.add(s.id),s.type!==l.Operation)throw new Error("Entity must be an operation to be flattened");return[s,...(s.successCalls||[]).flatMap(n=>Qe(n,u,i)),...(s.errorCalls||[]).flatMap(n=>Qe(n,u,i)),...(s.inputs||[]).flatMap(n=>Qe(n,u,i)),...(s.outputs||[]).flatMap(n=>Qe(n,u,i)),...(s.writesValues||[]).flatMap(n=>Qe(n,u,i)),...s.error?Qe(s.error,u,i):[],...(Pu(s)||[]).flatMap(n=>Qe(n,u,i)),...s.parent?Qe(s.parent,u,i):[]]}function Gat(s,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(s.id))return[];if(u.add(s.id),s.type!==l.OutputMap)throw new Error("Entity must be an output map to be flattened");return[s,...(s.writesValues||[]).flatMap(n=>Qe(n,u,i)),...s.declaration?Qe(s.declaration,u,i):[],...s.parent?Qe(s.parent,u,i):[]]}function Bat(s,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(s.id))return[];if(u.add(s.id),s.type!==l.PrimitiveEntity)throw new Error("Entity must be a primitive entity to be flattened");return[s,...(s.properties||[]).flatMap(n=>Qe(n,u,i)),...(s.methods||[]).flatMap(n=>Qe(n,u,i)),...(s.abstractMethods||[]).flatMap(n=>Qe(n,u,i))]}function Mat(s,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(s.id))return[];if(u.add(s.id),s.type!==l.Project)throw new Error("Entity must be a project to be flattened");return[s,...(s.entities||[]).flatMap(n=>Qe(n,u,i)),...(s.functions||[]).flatMap(n=>Qe(n,u,i)),...(s.events||[]).flatMap(n=>Qe(n,u,i)),...(s.projects||[]).flatMap(n=>Qe(n,u,i)),...(s.variableDeclarations||[]).flatMap(n=>Qe(n,u,i)),...(s.variableInstances||[]).flatMap(n=>Qe(n,u,i)),...(s.operations||[]).flatMap(n=>Qe(n,u,i)),...(s.conditions||[]).flatMap(n=>Qe(n,u,i)),...(s.functionCalls||[]).flatMap(n=>Qe(n,u,i)),...(s.projects||[]).flatMap(n=>Qe(n,u,i)),...(s.loops||[]).flatMap(n=>Qe(n,u,i)),...(s.searches||[]).flatMap(n=>Qe(n,u,i))]}function Uat(s,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(s.id))return[];if(u.add(s.id),s.type!==l.Property)throw new Error("Entity must be a property to be flattened");return[s,...s.defaultValue?Qe(s.defaultValue,u,i):[],...s.dataType?Qe(s.dataType,u,i):[],...s.parent?Qe(s.parent,u,i):[]]}function kat(s,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(s.id))return[];if(u.add(s.id),s.type!==l.ReturnStatement)throw new Error("Entity must be a return statement to be flattened");return[s,...(s.outputs||[]).flatMap(n=>Qe(n,u,i)),...s.throws?Qe(s.throws,u,i):[],...s.readsValue?Qe(s.readsValue,u,i):[],...s.dataType?Qe(s.dataType,u,i):[],...(Pu(s)||[]).flatMap(n=>Qe(n,u,i)),...s.parent?Qe(s.parent,u,i):[]]}function Fat(s,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(s.id))return[];if(u.add(s.id),s.type!==l.Search)throw new Error("Entity must be a search to be flattened");return[s,...(s.successCalls||[]).flatMap(n=>Qe(n,u,i)),...(s.errorCalls||[]).flatMap(n=>Qe(n,u,i)),...(s.inputsDeclarations||[]).flatMap(n=>Qe(n,u,i)),...(s.inputs||[]).flatMap(n=>Qe(n,u,i)),...(s.writesValues||[]).flatMap(n=>Qe(n,u,i)),...(s.outputs||[]).flatMap(n=>Qe(n,u,i)),...s.error?Qe(s.error,u,i):[],...s.dataType?Qe(s.dataType,u,i):[],...(Pu(s)||[]).flatMap(n=>Qe(n,u,i)),...s.parent?Qe(s.parent,u,i):[]]}function jat(s,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(s.id))return[];if(u.add(s.id),s.type!==l.ValueDescriptor)throw new Error("Entity must be a value descriptor to be flattened");return[s,...s.defaultValue?Qe(s.defaultValue,u,i):[],...s.dataType?Qe(s.dataType,u,i):[],...s.parent?Qe(s.parent,u,i):[]]}function Sat(s,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(s.id))return[];if(u.add(s.id),s.type!==l.VariableDeclaration)throw new Error("Entity must be a variable declaration to be flattened");return[s,...(s.successCalls||[]).flatMap(n=>Qe(n,u,i)),...(s.errorCalls||[]).flatMap(n=>Qe(n,u,i)),...(s.inputs||[]).flatMap(n=>Qe(n,u,i)),...(s.outputs||[]).flatMap(n=>Qe(n,u,i)),...(s.internalCalls||[]).flatMap(n=>Qe(n,u,i)),...(s.writesValues||[]).flatMap(n=>Qe(n,u,i)),...s.readsValue?Qe(s.readsValue,u,i):[],...s.defaultValue?Qe(s.defaultValue,u,i):[],...(Pu(s)||[]).flatMap(n=>Qe(n,u,i)),...s.dataType?Qe(s.dataType,u,i):[],...s.parent?Qe(s.parent,u,i):[]]}function Kat(s,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(s.id))return[];if(u.add(s.id),s.type!==l.VariableInstance)throw new Error("Entity must be a variable instance to be flattened");return[s,...(s.successCalls||[]).flatMap(n=>Qe(n,u,i)),...(s.errorCalls||[]).flatMap(n=>Qe(n,u,i)),...(s.inputs||[]).flatMap(n=>Qe(n,u,i)),...(s.outputs||[]).flatMap(n=>Qe(n,u,i)),...(s.internalCalls||[]).flatMap(n=>Qe(n,u,i)),...(s.writesValues||[]).flatMap(n=>Qe(n,u,i)),...s.readsValue?Qe(s.readsValue,u,i):[],...s.defaultValue?Qe(s.defaultValue,u,i):[],...(Pu(s)||[]).flatMap(n=>Qe(n,u,i)),...s.declaration?Qe(s.declaration,u,i):[],...s.parent?Qe(s.parent,u,i):[]]}function Qe(s,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(!s)throw new Error("Entity must be defined to be flattened");if(s.type===l.GenericReference)return[];const n=i.ignoreBuiltInBaseEntities?i.diggestedBuiltInBaseEntitiesIds??new Set(BC()):new Set;if(i.diggestedBuiltInBaseEntitiesIds=n,i.ignoreBuiltInBaseEntities&&(Ss.includes(s.type)||n.has(s.id)))return[];if(u.has(s.id))return[];switch(s.type){case l.FunctionCall:return Cat(s,u,i);case l.Operation:return Lat(s,u,i);case l.Condition:return Iat(s,u,i);case l.Loop:return $at(s,u,i);case l.Search:return Fat(s,u,i);case l.GlobalEvent:return Pat(s,u,i);case l.ReturnStatement:return kat(s,u,i);case l.ContinueStatement:return Rat(s,u,i);case l.BreakStatement:return bat(s,u,i);case l.VariableDeclaration:return Sat(s,u,i);case l.DefinitionEntity:return Dat(s,u,i);case l.FunctionDeclaration:return Oat(s,u,i);case l.Project:return Mat(s,u,i);case l.ActionDescriptor:return gat(s,u,i);case l.ArgumentDeclaration:return Eat(s,u,i);case l.ValueDescriptor:return jat(s,u,i);case l.InputMap:return _at(s,u,i);case l.OutputMap:return Gat(s,u,i);case l.DataType:return wat(s,u,i);case l.InstalledProject:return xat(s,u,i);case l.InternalCall:return Vat(s,u,i);case l.LiteralValue:return Nat(s,u,i);case l.Property:return Uat(s,u,i);case l.VariableInstance:return Kat(s,u,i);case l.BuiltInBaseEntity:return i.ignoreBuiltInBaseEntities?[]:Aat(s,u,i);case l.PrimitiveEntity:return i.ignoreBuiltInBaseEntities?[]:Bat(s,u,i)}return[]}async function MC(s={}){const u=new Set,i=se.YieldTracker.from(s),n=new Set;for(const a of vG){const c=await Je(a,u,{ignoreBuiltInBaseEntities:!1,tracker:i});for(const e of c)n.add(e.id),await i.tick()}return n}function _u(s){return[...s.calledByEntry||[],...s.calledByError||[],...s.calledBySuccess||[]].filter(u=>u.type!==l.GenericReference)}async function qat(s,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(s.id))return[];if(u.add(s.id),s.type!==l.ActionDescriptor)throw new Error("Entity must be an action descriptor to be flattened");const n=se.YieldTracker.from(i),a=[s];await n.tick();const c={...i,tracker:n};delete c.yieldEvery;for(const e of s.inputs)a.push(...await Je(e,u,c));return s.dataType&&a.push(...await Je(s.dataType,u,c)),s.error&&a.push(...await Je(s.error,u,c)),s.parent&&a.push(...await Je(s.parent,u,c)),a}async function Zat(s,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(s.id))return[];if(u.add(s.id),s.type!==l.ArgumentDeclaration)throw new Error("Entity must be an argument declaration to be flattened");const n=se.YieldTracker.from(i),a=[s];await n.tick();const c={...i,tracker:n};delete c.yieldEvery,s.dataType&&a.push(...await Je(s.dataType,u,c)),s.parent&&a.push(...await Je(s.parent,u,c)),s.defaultValue&&a.push(...await Je(s.defaultValue,u,c));for(const e of s.writesValues||[])a.push(...await Je(e,u,c));for(const e of s.implements||[])a.push(...await Je(e,u,c));return a}async function Hat(s,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(s.id))return[];if(u.add(s.id),s.type!==l.BreakStatement)throw new Error("Entity must be a break statement to be flattened");const n=se.YieldTracker.from(i),a=[s];await n.tick();const c={...i,tracker:n};delete c.yieldEvery;for(const f of s.outputs)a.push(...await Je(f,u,c));s.parent&&a.push(...await Je(s.parent,u,c)),s.throws&&a.push(...await Je(s.throws,u,c)),s.dataType&&a.push(...await Je(s.dataType,u,c)),s.readsValue&&a.push(...await Je(s.readsValue,u,c));const e=_u(s);for(const f of e)a.push(...await Je(f,u,c));return a}async function Wat(s,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(s.id))return[];if(u.add(s.id),s.type!==l.BuiltInBaseEntity)throw new Error("Entity must be a built-in base entity to be flattened");const n=se.YieldTracker.from(i),a=[s];await n.tick();const c={...i,tracker:n};delete c.yieldEvery;for(const e of s.properties||[])a.push(...await Je(e,u,c));for(const e of s.methods||[])a.push(...await Je(e,u,c));for(const e of s.abstractMethods||[])a.push(...await Je(e,u,c));return s.allPropertiesImplement&&a.push(...await Je(s.allPropertiesImplement,u,c)),s.additionalPropertiesDataType&&a.push(...await Je(s.additionalPropertiesDataType,u,c)),s.extends&&a.push(...await Je(s.extends,u,c)),a}async function zat(s,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(s.id))return[];if(u.add(s.id),s.type!==l.Condition)throw new Error("Entity must be a condition to be flattened");const n=se.YieldTracker.from(i),a=[s];await n.tick();const c={...i,tracker:n};if(delete c.yieldEvery,s.andChildrenGroup&&Array.isArray(s.andChildrenGroup))for(const f of s.andChildrenGroup)a.push(...await Je(f,u,c));if(s.orChildrenGroup&&Array.isArray(s.orChildrenGroup))for(const f of s.orChildrenGroup)a.push(...await Je(f,u,c));for(const f of s.inputs)a.push(...await Je(f,u,c));for(const f of s.successCalls)a.push(...await Je(f,u,c));for(const f of s.errorCalls)a.push(...await Je(f,u,c));const e=_u(s);for(const f of e)a.push(...await Je(f,u,c));return s.parent&&a.push(...await Je(s.parent,u,c)),a}async function Yat(s,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(s.id))return[];if(u.add(s.id),s.type!==l.ContinueStatement)throw new Error("Entity must be a continue statement to be flattened");const n=se.YieldTracker.from(i),a=[s];await n.tick();const c={...i,tracker:n};delete c.yieldEvery;for(const f of s.outputs)a.push(...await Je(f,u,c));const e=_u(s);for(const f of e)a.push(...await Je(f,u,c));return s.parent&&a.push(...await Je(s.parent,u,c)),s.throws&&a.push(...await Je(s.throws,u,c)),s.dataType&&a.push(...await Je(s.dataType,u,c)),s.readsValue&&a.push(...await Je(s.readsValue,u,c)),a}async function Jat(s,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(s.id))return[];if(u.add(s.id),s.type!==l.DefinitionEntity)throw new Error("Entity must be a definition entity to be flattened");const n=se.YieldTracker.from(i),a=[s];await n.tick();const c={...i,tracker:n};delete c.yieldEvery;for(const e of s.properties)a.push(...await Je(e,u,c));for(const e of s.methods)a.push(...await Je(e,u,c));for(const e of s.abstractMethods)a.push(...await Je(e,u,c));for(const e of s.implements)a.push(...await Je(e,u,c));return s.extends&&a.push(...await Je(s.extends,u,c)),s.parent&&a.push(...await Je(s.parent,u,c)),s.additionalPropertiesDataType&&a.push(...await Je(s.additionalPropertiesDataType,u,c)),s.allPropertiesImplement&&a.push(...await Je(s.allPropertiesImplement,u,c)),a}async function Qat(s,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(s.id))return[];if(u.add(s.id),s.type!==l.DataType)throw new Error("Entity must be a data type to be flattened");const n=se.YieldTracker.from(i),a=[s];await n.tick();const c={...i,tracker:n};if(delete c.yieldEvery,s.parent&&a.push(...await Je(s.parent,u,c)),s.foreignKeyRef&&a.push(...await Je(s.foreignKeyRef,u,c)),s.entity&&a.push(...await Je(s.entity,u,c)),s.orChildrenGroup)for(const e of s.orChildrenGroup)a.push(...await Je(e,u,c));if(s.andChildrenGroup)for(const e of s.andChildrenGroup)a.push(...await Je(e,u,c));return a}async function Xat(s,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(s.id))return[];if(u.add(s.id),s.type!==l.FunctionCall)throw new Error("Entity must be a function call to be flattened");const n=se.YieldTracker.from(i),a=[s];await n.tick();const c={...i,tracker:n};delete c.yieldEvery;for(const f of s.inputs)a.push(...await Je(f,u,c));for(const f of s.outputs)a.push(...await Je(f,u,c));s.error&&a.push(...await Je(s.error,u,c));const e=_u(s);for(const f of e)a.push(...await Je(f,u,c));for(const f of s.successCalls)a.push(...await Je(f,u,c));for(const f of s.errorCalls)a.push(...await Je(f,u,c));for(const f of s.writesValues)a.push(...await Je(f,u,c));return s.parent&&a.push(...await Je(s.parent,u,c)),a}async function est(s,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(s.id))return[];if(u.add(s.id),s.type!==l.FunctionDeclaration)throw new Error("Entity must be a function declaration to be flattened");const n=se.YieldTracker.from(i),a=[s];await n.tick();const c={...i,tracker:n};delete c.yieldEvery,s.parent&&a.push(...await Je(s.parent,u,c)),s.implements&&a.push(...await Je(s.implements,u,c)),s.dataType&&a.push(...await Je(s.dataType,u,c));for(const e of s.inputs)a.push(...await Je(e,u,c));for(const e of s.calls)a.push(...await Je(e,u,c));return a}async function tst(s,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(s.id))return[];if(u.add(s.id),s.type!==l.GlobalEvent)throw new Error("Entity must be a global event to be flattened");const n=se.YieldTracker.from(i),a=[s];await n.tick();const c={...i,tracker:n};delete c.yieldEvery,s.parent&&a.push(...await Je(s.parent,u,c)),s.implements&&a.push(...await Je(s.implements,u,c));for(const e of s.inputs)a.push(...await Je(e,u,c));for(const e of s.calls)a.push(...await Je(e,u,c));return a}async function ist(s,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(s.id))return[];if(u.add(s.id),s.type!==l.InputMap)throw new Error("Entity must be an input map to be flattened");const n=se.YieldTracker.from(i),a=[s];await n.tick();const c={...i,tracker:n};return delete c.yieldEvery,s.parent&&a.push(...await Je(s.parent,u,c)),s.declaration&&a.push(...await Je(s.declaration,u,c)),s.readsValue&&a.push(...await Je(s.readsValue,u,c)),s.dataType&&a.push(...await Je(s.dataType,u,c)),s.defaultValue&&a.push(...await Je(s.defaultValue,u,c)),a}async function nst(s,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(s.id))return[];if(u.add(s.id),s.type!==l.InstalledProject)throw new Error("Entity must be an installed project to be flattened");const n=se.YieldTracker.from(i),a=[s];await n.tick();const c={...i,tracker:n};delete c.yieldEvery;for(const e of s.functions)a.push(...await Je(e,u,c));for(const e of s.events)a.push(...await Je(e,u,c));return s.parent&&a.push(...await Je(s.parent,u,c)),a}async function rst(s,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(s.id))return[];if(u.add(s.id),s.type!==l.InternalCall)throw new Error("Entity must be an internal call to be flattened");const n=se.YieldTracker.from(i),a=[s];await n.tick();const c={...i,tracker:n};delete c.yieldEvery;for(const f of s.inputs)a.push(...await Je(f,u,c));for(const f of s.outputs)a.push(...await Je(f,u,c));s.error&&a.push(...await Je(s.error,u,c));const e=_u(s);for(const f of e)a.push(...await Je(f,u,c));for(const f of s.successCalls)a.push(...await Je(f,u,c));for(const f of s.errorCalls)a.push(...await Je(f,u,c));for(const f of s.writesValues)a.push(...await Je(f,u,c));return s.parent&&a.push(...await Je(s.parent,u,c)),a}async function ast(s,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(s.id))return[];if(u.add(s.id),s.type!==l.LiteralValue)throw new Error("Entity must be a literal value to be flattened");const n=se.YieldTracker.from(i),a=[s];await n.tick();const c={...i,tracker:n};if(delete c.yieldEvery,s.valueAsTypeSingle&&a.push(...await Je(s.valueAsTypeSingle,u,c)),s.valueAsTypeList&&Array.isArray(s.valueAsTypeList))for(const e of s.valueAsTypeList)a.push(...await Je(e,u,c));return s.parent&&a.push(...await Je(s.parent,u,c)),a}async function sst(s,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(s.id))return[];if(u.add(s.id),s.type!==l.Loop)throw new Error("Entity must be a loop to be flattened");const n=se.YieldTracker.from(i),a=[s];await n.tick();const c={...i,tracker:n};delete c.yieldEvery;for(const f of s.inputs)a.push(...await Je(f,u,c));for(const f of s.outputs)a.push(...await Je(f,u,c));s.error&&a.push(...await Je(s.error,u,c));const e=_u(s);for(const f of e)a.push(...await Je(f,u,c));for(const f of s.successCalls)a.push(...await Je(f,u,c));for(const f of s.errorCalls)a.push(...await Je(f,u,c));for(const f of s.writesValues)a.push(...await Je(f,u,c));return s.parent&&a.push(...await Je(s.parent,u,c)),s.body&&a.push(...await Je(s.body,u,c)),s.dataType&&a.push(...await Je(s.dataType,u,c)),a}async function lst(s,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(s.id))return[];if(u.add(s.id),s.type!==l.Operation)throw new Error("Entity must be an operation to be flattened");const n=se.YieldTracker.from(i),a=[s];await n.tick();const c={...i,tracker:n};delete c.yieldEvery;for(const f of s.inputs)a.push(...await Je(f,u,c));for(const f of s.outputs)a.push(...await Je(f,u,c));s.error&&a.push(...await Je(s.error,u,c));const e=_u(s);for(const f of e)a.push(...await Je(f,u,c));for(const f of s.successCalls)a.push(...await Je(f,u,c));for(const f of s.errorCalls)a.push(...await Je(f,u,c));for(const f of s.writesValues)a.push(...await Je(f,u,c));return s.parent&&a.push(...await Je(s.parent,u,c)),a}async function ost(s,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(s.id))return[];if(u.add(s.id),s.type!==l.OutputMap)throw new Error("Entity must be an output map to be flattened");const n=se.YieldTracker.from(i),a=[s];await n.tick();const c={...i,tracker:n};delete c.yieldEvery;for(const e of s.writesValues)a.push(...await Je(e,u,c));return s.declaration&&a.push(...await Je(s.declaration,u,c)),s.dataType&&a.push(...await Je(s.dataType,u,c)),s.parent&&a.push(...await Je(s.parent,u,c)),a}async function dst(s,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(s.id))return[];if(u.add(s.id),s.type!==l.PrimitiveEntity)throw new Error("Entity must be a primitive entity to be flattened");const n=se.YieldTracker.from(i),a=[s];await n.tick();const c={...i,tracker:n};delete c.yieldEvery;for(const e of s.properties)a.push(...await Je(e,u,c));for(const e of s.methods)a.push(...await Je(e,u,c));for(const e of s.abstractMethods)a.push(...await Je(e,u,c));return a}async function ust(s,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(s.id))return[];if(u.add(s.id),s.type!==l.Project)throw new Error("Entity must be a project to be flattened");const n=se.YieldTracker.from(i),a=[s];await n.tick();const c={...i,tracker:n};delete c.yieldEvery;for(const e of s.entities)a.push(...await Je(e,u,c));for(const e of s.functions)a.push(...await Je(e,u,c));for(const e of s.events)a.push(...await Je(e,u,c));for(const e of s.projects)a.push(...await Je(e,u,c));for(const e of s.variableDeclarations)a.push(...await Je(e,u,c));for(const e of s.variableInstances)a.push(...await Je(e,u,c));for(const e of s.operations)a.push(...await Je(e,u,c));for(const e of s.conditions)a.push(...await Je(e,u,c));for(const e of s.functionCalls)a.push(...await Je(e,u,c));for(const e of s.projects)a.push(...await Je(e,u,c));for(const e of s.loops)a.push(...await Je(e,u,c));for(const e of s.searches)a.push(...await Je(e,u,c));return a}async function pst(s,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(s.id))return[];if(u.add(s.id),s.type!==l.Property)throw new Error("Entity must be a property to be flattened");const n=se.YieldTracker.from(i),a=[s];await n.tick();const c={...i,tracker:n};return delete c.yieldEvery,s.defaultValue&&a.push(...await Je(s.defaultValue,u,c)),s.dataType&&a.push(...await Je(s.dataType,u,c)),s.parent&&a.push(...await Je(s.parent,u,c)),a}async function cst(s,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(s.id))return[];if(u.add(s.id),s.type!==l.ReturnStatement)throw new Error("Entity must be a return statement to be flattened");const n=se.YieldTracker.from(i),a=[s];await n.tick();const c={...i,tracker:n};delete c.yieldEvery;for(const f of s.outputs)a.push(...await Je(f,u,c));for(const f of s.outputs)a.push(...await Je(f,u,c));s.throws&&a.push(...await Je(s.throws,u,c)),s.readsValue&&a.push(...await Je(s.readsValue,u,c)),s.dataType&&a.push(...await Je(s.dataType,u,c));const e=_u(s);for(const f of e)a.push(...await Je(f,u,c));return s.parent&&a.push(...await Je(s.parent,u,c)),a}async function fst(s,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(s.id))return[];if(u.add(s.id),s.type!==l.Search)throw new Error("Entity must be a search to be flattened");const n=se.YieldTracker.from(i),a=[s];await n.tick();const c={...i,tracker:n};delete c.yieldEvery;for(const f of s.inputs)a.push(...await Je(f,u,c));for(const f of s.outputs)a.push(...await Je(f,u,c));s.error&&a.push(...await Je(s.error,u,c)),s.dataType&&a.push(...await Je(s.dataType,u,c));for(const f of s.inputsDeclarations)a.push(...await Je(f,u,c));const e=_u(s);for(const f of e)a.push(...await Je(f,u,c));for(const f of s.successCalls)a.push(...await Je(f,u,c));for(const f of s.errorCalls)a.push(...await Je(f,u,c));for(const f of s.writesValues)a.push(...await Je(f,u,c));return s.parent&&a.push(...await Je(s.parent,u,c)),a}async function yst(s,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(s.id))return[];if(u.add(s.id),s.type!==l.ValueDescriptor)throw new Error("Entity must be a value descriptor to be flattened");const n=se.YieldTracker.from(i),a=[s];await n.tick();const c={...i,tracker:n};return delete c.yieldEvery,s.defaultValue&&a.push(...await Je(s.defaultValue,u,c)),s.dataType&&a.push(...await Je(s.dataType,u,c)),s.parent&&a.push(...await Je(s.parent,u,c)),a}async function hst(s,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(s.id))return[];if(u.add(s.id),s.type!==l.VariableDeclaration)throw new Error("Entity must be a variable declaration to be flattened");const n=se.YieldTracker.from(i),a=[s];await n.tick();const c={...i,tracker:n};delete c.yieldEvery;for(const f of s.inputs)a.push(...await Je(f,u,c));for(const f of s.outputs)a.push(...await Je(f,u,c));s.error&&a.push(...await Je(s.error,u,c)),s.dataType&&a.push(...await Je(s.dataType,u,c)),s.readsValue&&a.push(...await Je(s.readsValue,u,c)),s.defaultValue&&a.push(...await Je(s.defaultValue,u,c));const e=_u(s);for(const f of e)a.push(...await Je(f,u,c));for(const f of s.successCalls)a.push(...await Je(f,u,c));for(const f of s.errorCalls)a.push(...await Je(f,u,c));for(const f of s.writesValues)a.push(...await Je(f,u,c));for(const f of s.internalCalls)a.push(...await Je(f,u,c));return s.parent&&a.push(...await Je(s.parent,u,c)),a}async function mst(s,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(s.id))return[];if(u.add(s.id),s.type!==l.VariableInstance)throw new Error("Entity must be a variable instance to be flattened");const n=se.YieldTracker.from(i),a=[s];await n.tick();const c={...i,tracker:n};delete c.yieldEvery;for(const f of s.inputs)a.push(...await Je(f,u,c));for(const f of s.outputs)a.push(...await Je(f,u,c));s.error&&a.push(...await Je(s.error,u,c)),s.readsValue&&a.push(...await Je(s.readsValue,u,c)),s.defaultValue&&a.push(...await Je(s.defaultValue,u,c));const e=_u(s);for(const f of e)a.push(...await Je(f,u,c));for(const f of s.successCalls)a.push(...await Je(f,u,c));for(const f of s.errorCalls)a.push(...await Je(f,u,c));for(const f of s.writesValues)a.push(...await Je(f,u,c));for(const f of s.internalCalls)a.push(...await Je(f,u,c));return s.parent&&a.push(...await Je(s.parent,u,c)),s.declaration&&a.push(...await Je(s.declaration,u,c)),a}async function Je(s,u=new Set,i={ignoreBuiltInBaseEntities:!1,yieldEvery:100}){const n={...i,ignoreBuiltInBaseEntities:i.ignoreBuiltInBaseEntities??!1};if(!s)throw new Error("Entity must be defined to be flattened");if(s.type===l.GenericReference)return[];const a=se.YieldTracker.from(n);n.tracker=a,n.yieldEvery!==void 0&&delete n.yieldEvery;const c=n.ignoreBuiltInBaseEntities?n.diggestedBuiltInBaseEntitiesIds??new Set(await MC(n)):new Set;if(n.diggestedBuiltInBaseEntitiesIds=c,n.ignoreBuiltInBaseEntities&&(Ss.includes(s.type)||c.has(s.id)))return[];if(u.has(s.id))return[];switch(s.type){case l.FunctionCall:return Xat(s,u,n);case l.Operation:return lst(s,u,n);case l.Condition:return zat(s,u,n);case l.Loop:return sst(s,u,n);case l.Search:return fst(s,u,n);case l.GlobalEvent:return tst(s,u,n);case l.ReturnStatement:return cst(s,u,n);case l.ContinueStatement:return Yat(s,u,n);case l.BreakStatement:return Hat(s,u,n);case l.VariableDeclaration:return hst(s,u,n);case l.DefinitionEntity:return Jat(s,u,n);case l.FunctionDeclaration:return est(s,u,n);case l.Project:return ust(s,u,n);case l.ActionDescriptor:return qat(s,u,n);case l.ArgumentDeclaration:return Zat(s,u,n);case l.ValueDescriptor:return yst(s,u,n);case l.InputMap:return ist(s,u,n);case l.OutputMap:return ost(s,u,n);case l.DataType:return Qat(s,u,n);case l.InstalledProject:return nst(s,u,n);case l.InternalCall:return rst(s,u,n);case l.LiteralValue:return ast(s,u,n);case l.Property:return pst(s,u,n);case l.VariableInstance:return mst(s,u,n);case l.BuiltInBaseEntity:return n.ignoreBuiltInBaseEntities?[]:Wat(s,u,n);case l.PrimitiveEntity:return n.ignoreBuiltInBaseEntities?[]:dst(s,u,n)}return[]}function Tst(s){return s==null||s===""}function gzi(s){return s===null}function Ya(s){return s!=null&&s.valueAsType?!1:Tst(s==null?void 0:s.value)}function ep(s){return s?s.valueAsType===null&&s.value===null:!1}function vst(s,u){if(s===u||!s&&!u)return!0;if(!s||!u||s.name===fe.EntityTemplate&&u.name!==fe.EntityTemplate||u.name===fe.EntityTemplate&&s.name!==fe.EntityTemplate)return!1;if(s.name===fe.ActionDescriptor&&u.name!==fe.ActionDescriptor||u.name===fe.ActionDescriptor&&s.name!==fe.ActionDescriptor)return!1;if(s.valueAsTypeSingle&&!u.valueAsTypeSingle||u.valueAsTypeSingle&&!s.valueAsTypeSingle)return!1;if(s.valueAsTypeList&&!u.valueAsTypeList||u.valueAsTypeList&&!s.valueAsTypeList)return!1;if(s.valueAsTypeSingle&&u.valueAsTypeSingle){if(s.valueAsTypeSingle.id!==u.valueAsTypeSingle.id)return!1}else if(s.valueAsTypeList&&u.valueAsTypeList){if(s.valueAsTypeList.length!==u.valueAsTypeList.length)return!1;for(let i=0;i<s.valueAsTypeList.length;i++)if(s.valueAsTypeList[i].id!==u.valueAsTypeList[i].id)return!1}else if(!s.valueAsType&&!u.valueAsType&&s.value!==u.value)return!1;return!0}function gst(s,u,i){if(!i)throw new Error("[checkIsRowTransformerUpToDate] 'lastPublishedEntityVersion' argument is required");if(!u)throw new Error("[checkIsRowTransformerUpToDate] 'entity' argument is required");if(!s)throw new Error("[checkIsRowTransformerUpToDate] 'newestOpenRowTransformer' argument is required");let n=!0;const a=s.methods.find(c=>{var e;return((e=c.implements)==null?void 0:e.id)===B["built-in-base-entity"].BUILT_IN_SQL_ROW_TRANSFORMER_ENTITY.methods.up.id});if(a?(ga(i).forEach(c=>{const e=a.inputs.find(f=>f.name===c.name);e&&Gi(e.getDataType(null),c.getDataType(null)).compatible||(n=!1)}),a.returnStatements.forEach(c=>{!c.dataType||!c.dataType.entity||c.dataType.entity.type!==l.DefinitionEntity?n=!1:hE(c.dataType.entity,u)||(n=!1)})):n=!1,n===null||n){const c=s.methods.find(e=>{var f;return((f=e.implements)==null?void 0:f.id)===B["built-in-base-entity"].BUILT_IN_SQL_ROW_TRANSFORMER_ENTITY.methods.down.id});c?(ga(u).forEach(e=>{const f=c.inputs.find(h=>h.name===e.name);f&&Gi(f.getDataType(null),e.getDataType(null)).compatible||(n=!1)}),c.returnStatements.forEach(e=>{!e.dataType||!e.dataType.entity||e.dataType.entity.type!==l.DefinitionEntity?n=!1:hE(e.dataType.entity,i)||(n=!1)})):n=!1}return{isPreexistingRowTransformerUpToDate:n}}function MR(s,u){var T,g;const i=B["primitive-entity"].enum.id;if(!s||!u||((T=s.entity)==null?void 0:T.id)!==i||((g=u.entity)==null?void 0:g.id)!==i)return{changed:null,newOptions:[],removedOptions:[],allFinalOptions:[]};const n=s.options||[],a=u.options||[],c=new Set(n),e=new Set(a),f=n.filter(b=>!e.has(b)),h=a.filter(b=>!c.has(b)),m=[...c].sort();return{changed:!!f.length||!!h.length,newOptions:f,removedOptions:h,allFinalOptions:m}}function ZV(s,u,i,n={skipBaseExtension:!1}){var Z;const a={...n||{},skipBaseExtension:(n==null?void 0:n.skipBaseExtension)||!1},c={changesSinceLastPublication:!1,rowTransformerNeeded:!1,newRowTransformerNeeded:!1,newestOpenRowTransformer:null,newRequiredProperties:[],newNonRequiredProperties:[],deletedProperties:[],lastPublishedEntityVersion:null,updatedEntityVersion:i,propChanges:new Map,isPreexistingRowTransformerUpToDate:null,extendedEntities:[]},f=s.entities.filter(H=>{var ne;if(H.id===i.id)return!1;let W=!1,Q=H;for(;Q;){if(((ne=Q.extends)==null?void 0:ne.id)===i.id){W=!0;break}if(Q.extends&&Q.extends.type===l.DefinitionEntity)Q=Q.extends;else break}return W}).map(H=>ZV(s,u,H,{...a,skipBaseExtension:!0}));if(!u)return{...c,changesSinceLastPublication:!0,extendedEntities:f};const h=u.get(i.id);if(!h)return{...c,changesSinceLastPublication:!0,extendedEntities:f};const m=u.entities.filter(H=>ki(H,Ie.SQL_ROW_TRANSFORMER)),g=s.entities.filter(H=>{var Y;if(!ki(H,Ie.SQL_ROW_TRANSFORMER)||m.find(J=>J.id===H.id))return!1;const Q=H.properties.find(J=>!!J.implements.find(te=>B["built-in-base-entity"].BUILT_IN_SQL_ROW_TRANSFORMER_ENTITY.properties.definition.id===te.id));if(!Q)return!1;const ne=(Y=Q.defaultValue)==null?void 0:Y.valueAsType;return ne?ne.id===i.id:!1}).sort((H,W)=>j(H.createdAt).isAfter(j(W.createdAt))?-1:1)[0]||null,b=new Map;let R=!1,I=null;!a.skipBaseExtension&&i.extends&&((Z=i.extends)==null?void 0:Z.type)===l.DefinitionEntity&&(I=ZV(i.project,u,i.extends));const C=ga(i).filter(H=>ga(h).find(ne=>ne.id===H.id)?!1:!Il(H.getDataType(null))),N=ga(i).filter(H=>ga(h).find(ne=>ne.id===H.id)?!1:!!Il(H.getDataType(null))),$=ga(h).filter(H=>!ga(i).find(Q=>Q.id===H.id));ga(i).filter(H=>{var ce,Te,ge,Re,Ce,Ne,Fe,Ae,$e,We,Ue,Ke,at,nt,Xe;const W=ga(h).find(ft=>ft.id===H.id);let Q=!1;if(!W)return!1;const ne=al(H.dataType,!0,`[resolveSQLMigrationsDiffs] Unsupported data-type structure on current property '${H.name}' (${H.id}). 'andChildrenGroup' with more than one child is not supported for SQL column properties.`),Y=al(W.dataType,!0,`[resolveSQLMigrationsDiffs] Unsupported data-type structure on last published property '${H.name}' (${H.id}). 'andChildrenGroup' with more than one child is not supported for SQL column properties.`),J=Am(ne,!0,`[resolveSQLMigrationsDiffs] Unsupported data-type structure on current property '${H.name}' (${H.id}). 'orChildrenGroup' with multiple non-null children is not supported for SQL column properties.`),te=Am(Y,!0,`[resolveSQLMigrationsDiffs] Unsupported data-type structure on last published property '${H.name}' (${H.id}). 'orChildrenGroup' with multiple non-null children is not supported for SQL column properties.`);if(((ce=J==null?void 0:J.foreignKeyRef)==null?void 0:ce.id)!==((Te=te==null?void 0:te.foreignKeyRef)==null?void 0:Te.id)){const ft=J==null?void 0:J.foreignKeyRef,Bi=te==null?void 0:te.foreignKeyRef;b.set(H.id,{...b.get(H.id)||{},newForeignKeyRef:ft||void 0,oldForeignKeyRef:Bi||void 0,property:H,oldProperty:W}),Q=!0,R=!0}else if(((ge=J==null?void 0:J.entity)==null?void 0:ge.id)!==((Re=te==null?void 0:te.entity)==null?void 0:Re.id)||MR(J,te).changed){const ft=B["primitive-entity"].enum.id;((Ce=J==null?void 0:J.entity)==null?void 0:Ce.id)===B["primitive-entity"].string.id||((Ne=te==null?void 0:te.entity)==null?void 0:Ne.id)===B["primitive-entity"].date.id&&((Fe=J==null?void 0:J.entity)==null?void 0:Fe.id)===B["primitive-entity"].number.id?b.set(H.id,{...b.get(H.id)||{},castableDataTypeEntity:{fromId:((Ae=te==null?void 0:te.entity)==null?void 0:Ae.id)||"",toId:(($e=J==null?void 0:J.entity)==null?void 0:$e.id)||""},property:H,oldProperty:W}):((We=J==null?void 0:J.entity)==null?void 0:We.id)===ft&&((Ue=te==null?void 0:te.entity)!=null&&Ue.id)&&MR(J,te).newOptions.length&&!MR(J,te).removedOptions.length?b.set(H.id,{...b.get(H.id)||{},castableDataTypeEntity:{fromId:((Ke=te==null?void 0:te.entity)==null?void 0:Ke.id)||"",toId:((at=J==null?void 0:J.entity)==null?void 0:at.id)||""},property:H,oldProperty:W}):(b.set(H.id,{...b.get(H.id)||{property:H},nonCastableDataTypeEntity:{fromId:((nt=te==null?void 0:te.entity)==null?void 0:nt.id)||"",toId:((Xe=J==null?void 0:J.entity)==null?void 0:Xe.id)||""},property:H,oldProperty:W}),R=!0),Q=!0}H.name!==(W==null?void 0:W.name)&&(b.set(H.id,{...b.get(H.id)||{},nameChange:{from:(W==null?void 0:W.name)||"",to:H.name},property:H,oldProperty:W}),Q=!0);const le=Il(W.getDataType(null)),oe=Il(H.getDataType(null));return oe!==le&&(b.set(H.id,{...b.get(H.id)||{},requiredChange:{from:!le,to:!oe},property:H,oldProperty:W}),oe||(R=!0),Q=!0),Q}),C.length>0&&(R=!0);let x=null;g&&R&&(x=gst(g,i,h).isPreexistingRowTransformerUpToDate);const G=i.name!==h.name?{from:h.name,to:i.name}:void 0;let K=I!=null&&I.rowTransformerNeeded?!0:R;return{...c,changesSinceLastPublication:b.size>0||!!$.length||!!C.length||!!N.length||K,rowTransformerNeeded:K,newestOpenRowTransformer:g,nameChange:G,newRequiredProperties:C,newNonRequiredProperties:N,deletedProperties:$,lastPublishedEntityVersion:h,propChanges:b,newRowTransformerNeeded:K&&!g,isPreexistingRowTransformerUpToDate:x,extendedEntities:f}}function b2(s,u,i,n,a){const c=a==null?void 0:a.ignoreNonEditable;a&&(a.ignoreNonEditable=!0);try{if(!s)throw new Error("[addDifferencesToRowTransformer] 'project' argument is required");if(!u)throw new Error("[addDifferencesToRowTransformer] 'transformer' argument is required");if(!i)throw new Error("[addDifferencesToRowTransformer] 'newEntityState' argument is required");if(!n)throw new Error("[addDifferencesToRowTransformer] 'oldEntityState' argument is required");const e=ga(i),f=ga(n);u.afterAllChildrenInitialized(a);const h=u.methods.find(T=>{var g;return((g=T.implements)==null?void 0:g.id)===B["built-in-base-entity"].BUILT_IN_SQL_ROW_TRANSFORMER_ENTITY.methods.up.id}),m=u.methods.find(T=>{var g;return((g=T.implements)==null?void 0:g.id)===B["built-in-base-entity"].BUILT_IN_SQL_ROW_TRANSFORMER_ENTITY.methods.down.id});if(!h)throw new Error("[addDifferencesToRowTransformer] The 'up' transformer trigger is missing from the parent");if(!m)throw new Error("[addDifferencesToRowTransformer] The 'down' transformer trigger is missing from the parent");f.forEach(T=>{const g=h.inputs.find(C=>C.name===T.name),b=Am(T.getDataType(null))||T.getDataType(null);let R=g,I;if(g)R.editable=!0;else{const C=$l.new(a);C.parent=h.toReference(),C.name=T.name,C.index=T.index,C.implements=[...T.implements.map($=>$.toJSON())];const N=Oe(C,s);N.hydrateAncestors(),a.add(N,re.Added),N.addSelfToProject(a),N.initChildren(a),R=N}if(!g||!R.dataType||R.dataType&&s.diggestedBuiltInBaseEntitiesIds.has(R.dataType.id)){const C=wr.new(a);C.parent=R.toReference();const N=Oe(C,s);N.hydrateAncestors(),a.add(N,re.Added),N.addSelfToProject(a),N.initChildren(a),I=N}else I=R.dataType,I.editable=!0;b&&I.merge(b,a),I.metaSync({editable:!1,deletable:!1},a),R.metaSync({editable:!1,deletable:!1},a)}),[...h.inputs].forEach(T=>{f.find(b=>b.name===T.name)||(T.editable=!0,T.remove({ignoreUpstream:!1},a),T.editable=!1)}),[...h.returnStatements].forEach(T=>{var N,$,x,G,K,Z,H,W,Q;if(!T.dataType||T.dataType&&s.diggestedBuiltInBaseEntitiesIds.has(T.dataType.id)){const ne=wr.new(a);ne.entity=i.toReference(),ne.parent=T.toReference();const Y=Oe(ne,s);Y.hydrateAncestors(),a.add(Y,re.Added),Y.addSelfToProject(a),Y.initChildren(a)}const g=(N=T.dataType)==null?void 0:N.entity,b=!g||g.type!==l.DefinitionEntity||g.type===l.DefinitionEntity&&(($=g.parent)==null?void 0:$.type)===l.Project||((x=g.parent)==null?void 0:x.id)!==((G=T.dataType)==null?void 0:G.id),R=!b&&g&&g.type===l.DefinitionEntity&&g.name&&s.getDefinitionEntities().some(ne=>ne.id!==g.id&&ne.name===g.name),I=g&&g.type===l.DefinitionEntity&&g.name&&!b&&!R?g.name:lc((i==null?void 0:i.name)+" new format",s.getDefinitionEntities());let C=(K=T.dataType)==null?void 0:K.entity;(!((Z=T.dataType)!=null&&Z.entity)||T.dataType.entity.type!==l.DefinitionEntity||T.dataType.entity.type==l.DefinitionEntity&&((H=T.dataType.entity.parent)==null?void 0:H.type)===l.Project||T.dataType.entity.parent.id!==T.dataType.id)&&(C=i.clone(a,T.dataType),C.metaSync({name:I},a)),qR(C,i,a,{exactDataType:!0}),C.setExtension(null,a),C.addImplementation(s.getBuiltIn(B["built-in-base-entity"].BUILT_IN_PERSISTED_ENTITY_ENTITY.id),a),C.properties.forEach(ne=>ne.setExtends(null,a)),T.dataType.setEntity(C,a),(Q=(W=T.dataType)==null?void 0:W.entity)==null||Q.metaSync({name:I},a),T.afterAllChildrenInitialized(a),T.outputs.forEach(ne=>{var oe,ce;if(ne.defaultValue||ne.readsValue)return;const Y=(oe=e.find(Te=>Te.name===me(ne,s)))==null?void 0:oe.id,J=(ce=f.find(Te=>(Te==null?void 0:Te.id)===Y))==null?void 0:ce.name,te=h.inputs.find(Te=>J===me(Te,s)),le=Gi((te==null?void 0:te.getDataType(null))||null,ne.getDataType(null)||null);le!=null&&le.compatible&&(ne.setValueWriter(te,a),te==null||te.addValueReader(ne,a))})}),e.forEach(T=>{var N;const g=(N=T.knownVersions)==null?void 0:N.get(T.previousVersion),b=m.inputs.find($=>$.name===T.name||!!g&&g.name===$.name),R=Am(T.getDataType(null))||T.getDataType(null);let I=b,C;if(b)I.editable=!0,I.metaSync({name:T.name,codeName:T.codeName,description:T.description},a);else{const $=$l.new(a);$.parent=m.toReference(),$.name=T.name,$.codeName=T.codeName,$.description=T.description,$.index=T.index,$.implements=[...T.implements.map(G=>G.toJSON())];const x=Oe($,s);x.hydrateAncestors(),a.add(x,re.Added),x.addSelfToProject(a),x.initChildren(a),I=x}if(!b||!I.dataType||I.dataType&&s.diggestedBuiltInBaseEntitiesIds.has(I.dataType.id)){const $=wr.new(a);$.parent=I.toReference();const x=Oe($,s);x.hydrateAncestors(),a.add(x,re.Added),x.addSelfToProject(a),x.initChildren(a),C=x}else C=I.dataType,C.editable=!0,C.merge(I.dataType,a);R&&C.merge(R,a),C.metaSync({editable:!1,deletable:!1},a),I.metaSync({editable:!1,deletable:!1},a)}),[...m.inputs].forEach(T=>{e.find(b=>{var I;if(b.name===T.name)return!0;const R=(I=b.knownVersions)==null?void 0:I.get(b.previousVersion);if(R&&R.name===T.name)return!0})||(T.editable=!0,T.remove({ignoreUpstream:!1},a),T.editable=!1)}),[...m.returnStatements].forEach(T=>{var N,$,x,G;if(!T.dataType||T.dataType&&s.diggestedBuiltInBaseEntitiesIds.has(T.dataType.id)){const K=wr.new(a);K.parent=T.toReference();const Z=Oe(K,s);Z.hydrateAncestors(),a.add(Z,re.Added),Z.addSelfToProject(a),Z.initChildren(a)}const g=(N=T.dataType)==null?void 0:N.entity,b=!g||g.id===B["built-in-base-entity"].BUILT_IN_PERSISTED_ENTITY_ENTITY.id,R=!b&&g&&g.type===l.DefinitionEntity&&g.name&&s.getDefinitionEntities().some(K=>K.id!==g.id&&K.name===g.name),I=g&&g.type===l.DefinitionEntity&&g.name&&!b&&!R?g.name:lc((n==null?void 0:n.name)+" old format",s.getDefinitionEntities());let C=($=T.dataType)==null?void 0:$.entity;(!C||(C==null?void 0:C.id)===B["built-in-base-entity"].BUILT_IN_PERSISTED_ENTITY_ENTITY.id)&&(C=n.clone(a,T.dataType),C.metaSync({name:I},a)),qR(C,n,a,{exactDataType:!0}),C.setExtension(null,a),C.addImplementation(s.getBuiltIn(B["built-in-base-entity"].BUILT_IN_PERSISTED_ENTITY_ENTITY.id),a),C.properties.forEach(K=>K.setExtends(null,a)),T.dataType.setEntity(C,a),(G=(x=T.dataType)==null?void 0:x.entity)==null||G.metaSync({name:I},a),T.afterAllChildrenInitialized(a),T.outputs.forEach(K=>{var Q,ne,Y;if(K.defaultValue||K.readsValue)return;const Z=(Q=f.find(J=>J.name===me(K,s)))==null?void 0:Q.id,H=(ne=e.find(J=>(J==null?void 0:J.id)===Z))==null?void 0:ne.name,W=m.inputs.find(J=>H===me(J,s));(Y=Gi((W==null?void 0:W.getDataType(null))||null,K.getDataType(null)||null))!=null&&Y.compatible&&(K.setValueWriter(W,a),W==null||W.addValueReader(K,a))})})}finally{a&&(a.ignoreNonEditable=!!c)}}function Est(s,u,i,n,a={}){var $;const c=s.getBuiltIn(Ie.SQL_ROW_TRANSFORMER),e=lc(me(u,s)+" row transformer",s.entities),f=c.implement(e,n),h=f.ownDeclaredProperties.find(x=>{var G;return(G=x.implements)==null?void 0:G.find(K=>K.id===B["built-in-base-entity"].BUILT_IN_SQL_ROW_TRANSFORMER_ENTITY.properties.definition.id)}),m=f.methods.find(x=>{var G;return((G=x.implements)==null?void 0:G.id)===B["built-in-base-entity"].BUILT_IN_SQL_ROW_TRANSFORMER_ENTITY.methods.up.id}),T=f.methods.find(x=>{var G;return((G=x.implements)==null?void 0:G.id)===B["built-in-base-entity"].BUILT_IN_SQL_ROW_TRANSFORMER_ENTITY.methods.down.id});if(!h||!m||!T)throw new Error("Cannot find definition property on the new row transformer entity");if(h.defaultValue)h.defaultValue.setValueAsTypeSingle(u,n);else{const x=Lr.new(n);x.name=fe.EntityTemplate,x.valueAsTypeSingle=u.toJSON(),x.parent=h.toReference();const G=Oe(x,s);G.hydrateAncestors(),n.add(G,re.Added),G.addSelfToProject(n),G.initChildren(n)}b2(s,f,u,i,n),se.Logger.log("BEFORE - changeSet.listAdded",n.listAdded.map(x=>{var K,Z,H,W,Q,ne,Y;const G=s.get(x.id);return G?me(G,s):x.type===l.InputMap?"(not found) "+x.type+" "+x.id+" - declaration: "+((K=x.declaration)==null?void 0:K.type)+" "+((Z=x.declaration)==null?void 0:Z.id)+' "'+((H=x.declaration)==null?void 0:H.name)+`"
|
|
626
|
+
`)),se.Logger.log("Persisting new additions"),h.visit(async(m,T)=>{if(n.added[m.id]){se.Logger.log("Adding: ",m.id);try{const g=Oe(m,this);if(g.hydrateAncestors(),g.addSelfToProject(a),a.add(g,re.Added),a||g.captureVersion(),!this.get(m.id))throw new Error(`Entity ${m.id} was not added to the project`)}catch(g){se.Logger.error("Error: ",g),se.Logger.error("Errored entity: ",m)}}}),se.Logger.log("Persisting updates"),h.visit(async(m,T)=>{if(n.updated[m.id]){se.Logger.log("Updating: ",m.id);try{const g=this.get(m.id);g?(g.updateWithShallowTransfer(m,a),a.add(g,re.Updated),a||g.captureVersion()):se.Logger.warn(`Active version of ${m.id} not found when applying external changes`)}catch(g){se.Logger.error("Error: ",g),se.Logger.error("Errored entity: ",m)}}}),se.Logger.log("Persisting removals"),h.visit(async(m,T)=>{if(n.removed[m.id]){se.Logger.log("Removing: ",m.id);try{const g=this.get(m.id);g&&(g.remove({ignoreUpstream:!1},a),a.add(g,re.Removed),a||g.captureVersion())}catch(g){se.Logger.error("Error: ",g),se.Logger.error("Errored entity: ",m)}}}),a.open=!1,a}toBuiltInShallowRecord(){const i={};return Object.values(this.builtInInstances).forEach(n=>{const a=n.toShallowJSON();i[n.id]=a}),i}toShallowRecord(){const i={};return Object.values(this.instances).forEach(n=>{const a=n.toShallowJSON();i[n.id]=a}),i}toFullProjectTransfer(i){const n={shallowErrors:!1,...i},a=new Ma(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(se.Logger.error(`[toFullProjectTransfer] Error serializing ${f.type} ${f.id}`,h),!n.shallowErrors)throw h}}),{order:e,size:e.length,record:c}}async toFullProjectTransferAsync(i={}){const n={shallowErrors:!1,...i},a=se.YieldTracker.from(n),c=new Ma(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(n.seenEntityMaps)for(const h of c.order){const m=n.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:n.seenEntityMaps});n.resetVersionOptions&&(m.version=Ii.UUID.uuid(),m.createdAt=n.resetVersionOptions.commonTimestamp||j().toISOString(),m.author=n.resetVersionOptions.author||Ii.sessionAuthor||"1",m.previousVersion=null),f[m.id]=m,e.push(m.id),n!=null&&n.onVisit&&await n.onVisit(m)}catch(m){if(se.Logger.error(`[toFullProjectTransferAsync] Error serializing ${h.type} ${h.id}`,m),!n.shallowErrors)throw m}},{tracker:a}),{order:e,size:e.length,record:f}}async toFullProjectGenerationTargetAsync(i={}){const n={shallowErrors:!1,...i},a=se.YieldTracker.from(n),c=new Ma(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(n.seenEntityMaps)for(const h of c.order){const m=n.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:n.seenEntityMaps});f[m.id]=m,e.push(m.id),n!=null&&n.onVisit&&await n.onVisit(m)}catch(m){if(se.Logger.error(`[toFullProjectGenerationTargetAsync] Error serializing ${h.type} ${h.id}`,m),!n.shallowErrors)throw m}},{tracker:a}),{order:e,size:e.length,record:f}}};D(Ii,"parentContext",E2),D(Ii,"sessionAuthor","1"),D(Ii,"repository",{APICreate:async(i,...n)=>i,APIUpdate:async(i,...n)=>i,APIDelete:async(i,...n)=>i,APIClone:async(i,...n)=>{},APILoad:async(i,...n)=>null,APILoadVersion:async(i,n,...a)=>null}),D(Ii,"type",l.Project),D(Ii,"USER_MANAGED_PARENT_TYPES",[]),D(Ii,"PARENT_TYPES",[...Ii.USER_MANAGED_PARENT_TYPES]),D(Ii,"MUTABLE_BASE_PROPERTIES",["name","description"]),D(Ii,"INMUTABLE_BASE_PROPERTIES",["id","type","workspaceId","version","createdAt","author","previousVersion"]),D(Ii,"BASE_PROPERTIES",[...Ii.MUTABLE_BASE_PROPERTIES,...Ii.INMUTABLE_BASE_PROPERTIES]),D(Ii,"MUTABLE_META_PROPERTIES",[...Ii.MUTABLE_BASE_PROPERTIES,"x","y"]),D(Ii,"INMUTABLE_META_PROPERTIES",[...Ii.INMUTABLE_BASE_PROPERTIES]),D(Ii,"META_PROPERTIES",[...Ii.MUTABLE_META_PROPERTIES,...Ii.INMUTABLE_META_PROPERTIES]),D(Ii,"MUTABLE_UPSTREAM_PROPERTIES",[]),D(Ii,"INMUTABLE_UPSTREAM_PROPERTIES",["primitives","builtInBaseEntities","operationDeclarations","globalEventActionDescriptors","loopDeclarations","builtInInstances"]),D(Ii,"UPSTREAM_PROPERTIES",[...Ii.MUTABLE_UPSTREAM_PROPERTIES,...Ii.INMUTABLE_UPSTREAM_PROPERTIES]),D(Ii,"MUTABLE_DOWNSTREAM_PROPERTIES",["entities","projects","functions","events","variableDeclarations","variableInstances","conditions","operations","functionCalls","loops","searches"]),D(Ii,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),D(Ii,"DOWNSTREAM_PROPERTIES",[...Ii.MUTABLE_DOWNSTREAM_PROPERTIES,...Ii.INMUTABLE_DOWNSTREAM_PROPERTIES]),D(Ii,"PROPERTIES",[...Ii.META_PROPERTIES,...Ii.UPSTREAM_PROPERTIES,...Ii.DOWNSTREAM_PROPERTIES]);let M=Ii;class W9i extends Hn{constructor(u){super(Db,u)}}class z9i extends Hn{constructor(i){super(rT,i);D(this,"autoexecutable",!0)}getEntityToMatchInputMap(i){return i.inputs.find(n=>{var a;return((a=n.declaration)==null?void 0:a.id)===B.operation[Ge.Validate].inputs.entityToMatch.id})||null}getDataToValidateInputMap(i){return i.inputs.find(n=>{var a;return((a=n.declaration)==null?void 0:a.id)===B.operation[Ge.Validate].inputs.dataToValidate.id})||null}getOutputDataOutputMap(i){return i.outputs.find(n=>{var a;return((a=n.declaration)==null?void 0:a.id)===B.operation[Ge.Validate].dataType.entity.properties.outputEntity.id})||null}getEntityToMatch(i,n=this.project.addChangeSet(new ee(this.project,M.sessionAuthor,j().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 n==null||n.attemptAutoclose("get-entity-to-match-validate-data",this.id),c}syncOperationInstance(i,n=this.project.addChangeSet(new ee(this.project,M.sessionAuthor,j().toISOString(),this,!0,"sync-operation-instance-validate-data"))){const a=[],c=[],e=[],f=[],h=this.getEntityToMatchInputMap(i);if(h){const{added:g,updated:b,removed:R,affected:I}=this.syncEntityToMatchInputMapDataType(h,n);a.push(...b),c.push(...g),e.push(...R),f.push(...I)}const m=this.getDataToValidateInputMap(i);if(m){const{added:g,updated:b,removed:R,affected:I}=this.syncDataToValidateInputMapDataType(m,n);a.push(...b),c.push(...g),e.push(...R),f.push(...I)}const T=this.getOutputDataOutputMap(i);if(T){const{added:g,updated:b,removed:R,affected:I}=this.syncOutputDataOutputMapDataType(T,n);a.push(...b),c.push(...g),e.push(...R),f.push(...I)}return n==null||n.attemptAutoclose("sync-operation-instance-validate-data",this.id),{updated:_(a),added:_(c),removed:_(e),affected:_(f),self:i}}syncEntityToMatchInputMapDataType(i,n=this.project.addChangeSet(new ee(this.project,M.sessionAuthor,j().toISOString(),this,!0,"sync-entity-to-match-input-map-data-type"))){var T,g,b,R,I,C,N,$,x,G,K,Z,H,W,Q,ne,Y,J;const a=[],c=[],e=[],f=[];if(((T=i.declaration)==null?void 0:T.id)!==B.operation[Ge.Validate].inputs.entityToMatch.id)return n==null||n.attemptAutoclose("sync-entity-to-match-input-map-data-type",this.id),{updated:[],added:[],removed:[],affected:[],self:null};const h=((g=this.project.requestActiveDynamicValue(i))==null?void 0:g.value)||null,m=h==null?void 0:h.valueAsTypeSingle;if(!i.dataType){const te={id:M.UUID.uuid(),version:M.UUID.uuid(),createdAt:(n==null?void 0:n.timestamp)||new Date().toISOString(),author:(n==null?void 0:n.author)||M.sessionAuthor,previousVersion:null,deleted:!1,deletable:!0,editable:!0,type:l.DataType,parentRelationType:null,options:((b=i.declaration.dataType)==null?void 0:b.options)||null,implementationChooseOne:((R=i.declaration.dataType)==null?void 0:R.implementationChooseOne)||!1,staticEntities:((I=i.declaration.dataType)==null?void 0:I.staticEntities)??null,interactiveEntities:((C=i.declaration.dataType)==null?void 0:C.interactiveEntities)??null,actionEntities:((N=i.declaration.dataType)==null?void 0:N.actionEntities)??null,index:(($=i.declaration.dataType)==null?void 0:$.index)??null,isList:((x=i.declaration.dataType)==null?void 0:x.isList)||!1,foreignKeyAllowed:((G=i.declaration.dataType)==null?void 0:G.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()},le=Oe(te,i.project);le.hydrateAncestors(),le.addSelfToProject(n),n==null||n.add(le,re.Added),le.setParent(i,n),le.initChildren(n),le.setEntity(m,n),a.push(le),i.setDataType(le,n),n||le.captureVersion()}return(Y=i.dataType)==null||Y.metaSync({inferred:!0,like:!1,asType:!0,options:((K=i.declaration.dataType)==null?void 0:K.options)||null,implementationChooseOne:((Z=i.declaration.dataType)==null?void 0:Z.implementationChooseOne)||!1,staticEntities:((H=i.declaration.dataType)==null?void 0:H.staticEntities)??null,interactiveEntities:((W=i.declaration.dataType)==null?void 0:W.interactiveEntities)??null,actionEntities:((Q=i.declaration.dataType)==null?void 0:Q.actionEntities)??null,isList:((ne=i.declaration.dataType)==null?void 0:ne.isList)||!1},n),(J=i.dataType)==null||J.setEntity(m,n),i.dataType&&c.push(i.dataType),n==null||n.attemptAutoclose("sync-entity-to-match-input-map-data-type",this.id),{updated:_(c),added:_(a),removed:_(e),affected:_(f),self:i.dataType}}syncDataToValidateInputMapDataType(i,n=this.project.addChangeSet(new ee(this.project,M.sessionAuthor,j().toISOString(),this,!0,"sync-data-to-validate-input-map-data-type"))){var g,b,R;const a=[],c=[],e=[],f=[];if(((g=i.declaration)==null?void 0:g.id)!==B.operation[Ge.Validate].inputs.dataToValidate.id)return n==null||n.attemptAutoclose("sync-data-to-validate-input-map-data-type",this.id),{updated:[],added:[],removed:[],affected:[],self:null};const h=this.getEntityToMatchInputMap(i.parent);if(!h)return n==null||n.attemptAutoclose("sync-data-to-validate-input-map-data-type",this.id),{updated:[],added:[],removed:[],affected:[],self:null};if(!this.getEntityToMatch(h,n))return n==null||n.attemptAutoclose("sync-data-to-validate-input-map-data-type",this.id),{updated:[],added:[],removed:[],affected:[],self:null};if(!i.dataType){const I={id:M.UUID.uuid(),version:M.UUID.uuid(),createdAt:(n==null?void 0:n.timestamp)||new Date().toISOString(),author:(n==null?void 0:n.author)||M.sessionAuthor,previousVersion:null,deleted:!1,deletable:!0,editable:!0,type:l.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()},C=Oe(I,i.project);C.hydrateAncestors(),C.addSelfToProject(n),n==null||n.add(C,re.Added),C.setParent(i,n),C.initChildren(n),a.push(C),i.setDataType(C,n),n||C.captureVersion()}(b=i.dataType)==null||b.metaSync({inferred:!0,like:!0,asType:!1},n);const T=this.getEntityToMatch(h,n);return(R=i.dataType)==null||R.setEntity(T,n),i.dataType&&c.push(i.dataType),n==null||n.attemptAutoclose("sync-data-to-validate-input-map-data-type",this.id),{updated:_(c),added:_(a),removed:_(e),affected:_(f),self:i.dataType}}syncOutputDataOutputMapDataType(i,n=this.project.addChangeSet(new ee(this.project,M.sessionAuthor,j().toISOString(),this,!0,"sync-output-data-output-map-data-type"))){var b,R,I,C;const a=[],c=[],e=[],f=[];if(((b=i.declaration)==null?void 0:b.id)!==B.operation[Ge.Validate].dataType.entity.properties.outputEntity.id)return n==null||n.attemptAutoclose("sync-output-data-output-map-data-type",this.id),{updated:[],added:[],removed:[],affected:[],self:null};const h=this.getEntityToMatchInputMap(i.parent);if(!h)return n==null||n.attemptAutoclose("sync-output-data-output-map-data-type",this.id),{updated:[],added:[],removed:[],affected:[],self:null};if(!this.getEntityToMatch(h,n))return n==null||n.attemptAutoclose("sync-output-data-output-map-data-type",this.id),{updated:[],added:[],removed:[],affected:[],self:null};const T=((R=this.project.requestActiveDynamicValue(h))==null?void 0:R.value)||null,g=(T==null?void 0:T.valueAsTypeSingle)||null;if(!i.dataType){const N={id:M.UUID.uuid(),version:M.UUID.uuid(),createdAt:(n==null?void 0:n.timestamp)||new Date().toISOString(),author:(n==null?void 0:n.author)||M.sessionAuthor,previousVersion:null,deleted:!1,deletable:!0,editable:!0,type:l.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:(g==null?void 0:g.toJSON())||null,like:!0,inferred:!0,parent:i.toReference()},$=Oe(N,i.project);$.hydrateAncestors(),$.addSelfToProject(n),n==null||n.add($,re.Added),$.setParent(i,n),$.initChildren(n),$.setEntity(g,n),a.push($),i.setDataType($,n),n||$.captureVersion()}return(I=i.dataType)==null||I.metaSync({inferred:!0,like:!0,asType:!1},n),(C=i.dataType)==null||C.setEntity(g,n),i.dataType&&c.push(i.dataType),n==null||n.attemptAutoclose("sync-output-data-output-map-data-type",this.id),{updated:_(c),added:_(a),removed:_(e),affected:_(f),self:i.dataType}}inferInputMapDataType(i,n=this.project.addChangeSet(new ee(this.project,M.sessionAuthor,j().toISOString(),this,!0,"infer-input-map-data-type-validate-data"))){var c,e,f;if(((c=i.declaration)==null?void 0:c.id)===B.operation[Ge.Validate].inputs.entityToMatch.id){const{added:h,updated:m,removed:T,affected:g}=n?this.syncEntityToMatchInputMapDataType(i,n):{added:[],updated:[],removed:[],affected:[]};return n==null||n.attemptAutoclose("infer-input-map-data-type",this.id),{updated:_(m),added:_(h),removed:_(T),affected:_(g),self:i.dataType}}if(((e=i.declaration)==null?void 0:e.id)===B.operation[Ge.Validate].inputs.dataToValidate.id){const{added:h,updated:m,removed:T,affected:g}=this.syncDataToValidateInputMapDataType(i,n);return n==null||n.attemptAutoclose("infer-input-map-data-type",this.id),{updated:_(m),added:_(h),removed:_(T),affected:_(g),self:i.dataType}}const a=(f=i.declaration)==null?void 0:f.getDataType(n);if(a&&a.isResolved)return n==null||n.attemptAutoclose("infer-input-map-data-type-validate-data",this.id),{updated:[],added:[],removed:[],affected:[],self:a};if(i.readsValue){const h=Xp(i.readsValue,n);return n==null||n.attemptAutoclose("infer-input-map-data-type-validate-data",this.id),{updated:[],added:[],removed:[],affected:[],self:h}}return n==null||n.attemptAutoclose("infer-input-map-data-type-validate-data",this.id),{updated:[],added:[],removed:[],affected:[],self:null}}inferOutputMapDataType(i,n=this.project.addChangeSet(new ee(this.project,M.sessionAuthor,j().toISOString(),this,!0,"infer-output-map-data-type-validate-data"))){var a;if(((a=i.declaration)==null?void 0:a.id)===B.operation[Ge.Validate].dataType.entity.properties.outputEntity.id){const{added:c,updated:e,removed:f,affected:h}=this.syncOutputDataOutputMapDataType(i,n);return n==null||n.attemptAutoclose("infer-output-map-data-type-validate-data",this.id),{updated:_(e),added:_(c),removed:_(f),affected:_(h),self:i.dataType}}return{updated:[],added:[],removed:[],affected:[],self:null}}}class Y9i extends Hn{constructor(u){super(HN,u)}}class J9i extends Hn{constructor(u){super(WN,u)}}class Q9i extends Hn{constructor(u){super(zN,u)}}class X9i extends Hn{constructor(u){super(dD,u)}}class ezi extends Hn{constructor(u){super(O1,u)}}class tzi extends Hn{constructor(u){super(kE,u)}}const gq=B[l.Operation][Ee.GoogleSheetsAppendRows];class izi extends Hn{constructor(u){super(gL,u);const i=this.inputs.find(a=>a.id===gq.inputs.range.id);i&&(i._codeNativeValueValidation=(a,c)=>{console.log("Range input custom validator");const e={errors:[],override:c};if(typeof c=="string"&&c.length>0){const f=c.split("!"),h=f.length>1?f[1]:f[0];/^([A-Za-z]+[0-9]*|[0-9]+)(:[A-Za-z]+[0-9]*|:[0-9]+)?$/.test(h)||e.errors.push(new ui({id:a.id+"--invalid-range-format",message:`Range "${c}" is not a valid A1 notation. Examples of valid ranges: "Sheet1!A1:B2", "A1", "A:B", "1:2".`,severity:De.Error,code:"invalid-range-format",entity:a}))}return e});const n=this.inputs.find(a=>a.id===gq.inputs.values.id);n&&(n._codeNativeValueValidation=(a,c)=>{console.log("Values input custom validator");const e={errors:[],override:c};return c!=null&&(Array.isArray(c)?c.every(h=>Array.isArray(h))||e.errors.push(new ui({id:a.id+"--values-must-be-2d-array",message:'Every element inside the values list must also be a list (a 2D array). Example: [["Row 1", 123], ["Row 2", 456]]',severity:De.Error,code:"values-must-be-2d-array",entity:a})):e.errors.push(new ui({id:a.id+"--values-must-be-array",message:"The values input must be a list of lists (a 2D array). You provided a single non-list value.",severity:De.Error,code:"values-must-be-array",entity:a}))),e})}}function Wrt(s){const u=[new cWe(s),new W9i(s),new z9i(s),new X9i(s),new Y9i(s),new Q9i(s),new J9i(s),new ezi(s),new tzi(s),new izi(s)];return LL.forEach(i=>{u.some(n=>n.id===i.id)||u.push(new Hn(i,s))}),u.forEach(i=>{i.initChildren(null),s.subscribeBuiltInInstance(i)}),s.operationDeclarations=u,u}const nzi=[];function zrt(s){const u=[new YHe(s),new eWe(s),new iWe(s),new nWe(s),new aWe(s),new lWe(s),new dWe(s),new pWe(s)];return uG.forEach(i=>{!u.some(n=>n.id===i.id)&&!nzi.includes(i.id)&&u.push(new ao(i,s))}),u.forEach(i=>{s.subscribeBuiltInInstance(i)}),s.builtInBaseEntities=u,u}function Yrt(s){const u=[];return aN.forEach(i=>{u.some(n=>n.id===i.id)||u.push(new wh(i,s))}),u.forEach(i=>{s.subscribeBuiltInInstance(i)}),s.primitives=u,u}function Jrt(s){const u=[new Hn(Sw,s)];return u.forEach(i=>{i.initChildren(null),s.subscribeBuiltInInstance(i)}),s.globalEventActionDescriptors=u,u}function Qrt(s){const u=[new Hn(Mb,s),new Hn(e0,s),new Hn(Gb,s),new Hn(OT,s),new Hn(PT,s),new Hn(Iw,s)];u.forEach(n=>{n.initChildren(null),s.subscribeBuiltInInstance(n)}),s.loopDeclarations=u;const i=[new Hn(Nw,s),new Hn(Bb,s),new Hn(Cw,s),new Hn(FL,s),new Hn(KL,s),new Hn(Rw,s)];return i.forEach(n=>{n.initChildren(null),s.subscribeBuiltInInstance(n)}),s.loopDeclarationsBodies=i,u}function Xrt(s){const u=[new op(TG,s)];return u.forEach(i=>{i.initChildren(null),s.subscribeBuiltInInstance(i)}),s.valueDescriptors=u,u}function eat(s){const u=[new Hn(cG,s),new Hn(pG,s),new Hn(fG,s),new Hn(yG,s)];return hG.forEach(i=>{u.some(n=>n.id===i.id)||u.push(new Hn(i,s))}),u.forEach(i=>{i.initChildren(null),s.subscribeBuiltInInstance(i)}),s.conditionDeclarations=u,u}function Qg(s){return s&&typeof s.then=="function"}function rzi(s,u){const i=new Ma(s[0],{allBuiltInEntityIds:u.allBuiltInEntityIds}),n=s.map(c=>c.id),a={};return s.forEach(c=>{a[c.id]=c}),i.order=n,i.flatRecord=a,i.orderEntities(),i.order.map(c=>i.flatRecord[c])}function azi(s,u){const i=new Ma(Object.values(s)[0],{allBuiltInEntityIds:u.allBuiltInEntityIds}),n=Object.keys(s);return i.order=n,i.flatRecord=s,i.orderEntities(),i.order}async function szi(s,u){const i=se.YieldTracker.from(u),n=new Ma(s[0],{allBuiltInEntityIds:u.allBuiltInEntityIds}),a=s.map(e=>e.id),c={};for(const e of s)c[e.id]=e,await i.tick();return n.order=a,n.flatRecord=c,await n.orderEntitiesAsync({tracker:i}),n.order.map(e=>n.flatRecord[e])}async function lzi(s,u){const i=se.YieldTracker.from(u),n=new Ma(Object.values(s)[0],{allBuiltInEntityIds:u.allBuiltInEntityIds}),a=Object.keys(s);return n.order=a,n.flatRecord=s,await n.orderEntitiesAsync({tracker:i}),n.order}const fE=class fE{constructor(u,i={}){D(this,"order",[]);D(this,"cachedEntityDependencies",{});D(this,"flatRecord",{});D(this,"allBuiltInEntityIds");D(this,"onGoingVisits",{});D(this,"cachedReferences",{});if(i.allBuiltInEntityIds&&(this.allBuiltInEntityIds=i.allBuiltInEntityIds),!u)return;const n={asyncInitialOrder:!1,...i};n.asyncInitialOrder?this.flattenAsync(u).then(()=>{this.orderEntitiesAsync({...n}).then(()=>{var a;(a=n.onOrdered)==null||a.call(n)})}):(this.flatten(u),this.orderEntities())}flatten(u){this.allBuiltInEntityIds||(this.allBuiltInEntityIds=new Set(BC()));const i=_(Qe(u,new Set(this.allBuiltInEntityIds),{ignoreBuiltInBaseEntities:!0,diggestedBuiltInBaseEntitiesIds:this.allBuiltInEntityIds})),n=new Set;for(const a of i)this.flatRecord[a.id]=a,n.add(a.id);this.order=Array.from(n)}async flattenAsync(u,i={}){const n=se.YieldTracker.from(i);this.allBuiltInEntityIds||(this.allBuiltInEntityIds=await MC({tracker:n}));const a=await Af(await Je(u,new Set(this.allBuiltInEntityIds),{ignoreBuiltInBaseEntities:!0,diggestedBuiltInBaseEntitiesIds:this.allBuiltInEntityIds,tracker:n}),{tracker:n}),c=new Set;for(const e of a)this.flatRecord[e.id]=e,c.add(e.id),await n.tick();this.order=Array.from(c)}getEntityDependencies(u){if(this.cachedEntityDependencies[u])return this.cachedEntityDependencies[u];const i={},n={},a=new Set([u]),c=[u];for(;c.length>0;){const m=c.shift(),T=this.getDirectDependencies(m);for(const g of Object.keys(T.downstream)){const b=this.flatRecord[g];b&&b.parent&&(typeof b.parent=="string"?b.parent:b.parent.entityId||b.parent.id)===m&&(a.has(g)||(a.add(g),c.push(g)))}}const e=new Set;for(const m of a)e.add(m);const f=Array.from(a);for(;f.length>0;){const m=f.shift(),T=this.getDirectDependencies(m);for(const g of Object.keys(T.upstream))e.has(g)||(e.add(g),i[g]=!0,f.push(g))}const h={upstream:i,downstream:n};return this.cachedEntityDependencies[u]=h,h}getDirectDependencies(u){if(!this.cachedReferences[u]){const i=this.flatRecord[u];if(!i)return{upstream:{},downstream:{}};this.cachedReferences[u]=Qd(i,this.flatRecord,{ignoreBuiltInBaseEntities:!0,allBuiltInEntityIds:this.allBuiltInEntityIds})}return this.cachedReferences[u]}moveEntityAfterDependencies(u){const i=this.getEntityDependencies(u.id),{upstream:n}=i;for(const a of Object.keys(n)){const c=this.order.indexOf(a),e=this.order.indexOf(u.id);if(c>e){if(this.getEntityDependencies(a).upstream[u.id])continue;return this.order.splice(e,1),this.order.splice(c,0,u.id),!0}}return!1}orderEntities(u=0){for(const n of this.order)this.getDirectDependencies(n);for(const n of this.order){const a=this.flatRecord[n];if(a&&a.parent){const c=typeof a.parent=="string"?a.parent:a.parent.entityId||a.parent.id;c&&this.cachedReferences[c]&&(this.cachedReferences[c].downstream[n]=!0)}}let i=!1;for(let n=0;n<this.order.length;n++){const a=this.order[n],c=this.flatRecord[a];if(c||se.Logger.warn(`Entity with id ${a} not found in flatRecord. Skipping...`),this.moveEntityAfterDependencies(c)){i=!0;break}}if(i){if(u>fE.MAX_ORDERING_ITERATIONS){console.error("[Traverser] Infinite loop detected in orderEntities!");return}this.orderEntities(u+1)}}async orderEntitiesAsync(u={}){const i=u.iterations||0;for(const c of this.order)this.getDirectDependencies(c);for(const c of this.order){const e=this.flatRecord[c];if(e&&e.parent){const f=typeof e.parent=="string"?e.parent:e.parent.entityId||e.parent.id;f&&this.cachedReferences[f]&&(this.cachedReferences[f].downstream[c]=!0)}}let n=!1;const a=se.YieldTracker.from(u);for(let c=0;c<this.order.length;c++){const e=this.order[c],f=this.flatRecord[e];if(f||se.Logger.warn(`Entity with id ${e} not found in flatRecord. Skipping...`),this.moveEntityAfterDependencies(f)){n=!0;break}await a.tick()}if(n){if(i>fE.MAX_ORDERING_ITERATIONS){console.error("[Traverser] Infinite loop detected in orderEntitiesAsync!");return}await this.orderEntitiesAsync({tracker:a,iterations:i+1})}}getUpstreamOngoingDependenciesVisits(u,i){const n=this.cachedReferences[u]||Qd(this.flatRecord[u],this.flatRecord,{ignoreBuiltInBaseEntities:!0,allBuiltInEntityIds:this.allBuiltInEntityIds});this.cachedReferences[u]=n;const{upstream:a}=n,c={};return Object.entries(this.onGoingVisits[i]||{}).forEach(([e,f])=>{Object.keys(a).includes(e)&&(c[e]=f)}),c}getDownstreamOngoingDependenciesVisits(u,i){const n=Object.keys(this.onGoingVisits[i]||{}),a=new Set(n.flatMap(e=>{const f=this.cachedReferences[e]||Qd(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===u&&(c[e]=this.onGoingVisits[i][e])}),c}async settlePromises(u,i){const n=Object.values(u);n.length&&await Promise.all(n),Object.keys(u).forEach(a=>{delete this.onGoingVisits[i][a]})}visit(u){const i=this.order;for(const n of i)u(this.flatRecord[n],this.flatRecord);return this}reverseVisit(u){const i=this.order.slice().reverse();for(const n of i)u(this.flatRecord[n],this.flatRecord);return this}async visitAsync(u,i={}){const{parallelise:n}={parallelise:!0,...i},a=se.YieldTracker.from(i),c=this.order;if(!n){for(const f of c){const h=u(this.flatRecord[f],this.flatRecord);Qg(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=u(this.flatRecord[f],this.flatRecord);Qg(m)&&(this.onGoingVisits[e][f]=m),await a.tick()}return await this.settlePromises(this.onGoingVisits[e],e),this.onGoingVisits[e]={},this}async reverseVisitAsync(u,i={}){const{parallelise:n}={parallelise:!0,...i},a=se.YieldTracker.from(i),c=this.order.slice().reverse();if(!n){for(const f of c){const h=u(this.flatRecord[f],this.flatRecord);Qg(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=u(this.flatRecord[f],this.flatRecord);Qg(m)&&(this.onGoingVisits[e][f]=m),await a.tick()}return await this.settlePromises(this.onGoingVisits[e],e),this.onGoingVisits[e]={},this}};D(fE,"MAX_ORDERING_ITERATIONS",1e4);let Ma=fE;const vh={},gR={},PE={empty:!1,enrich:!0,mock:!1,ignoreCache:!1,onFetch:async()=>null,manuallyInit:!1};function tat(s,u={enrich:!0,shallowErrors:!1},i){const n={enrich:!0,shallowErrors:!1,...u},{enrich:a,shallowErrors:c}=n,e=s.project,f=s.record,h=xC(s.project,{shallowErrors:c},i);h.instances[e.id]=h;const m=new Ma(e,{allBuiltInEntityIds:h.diggestedBuiltInBaseEntitiesIds}),T=new Set;f[e.id]=e,T.add(e.id);const g=j().toISOString();Object.values(f).forEach(R=>{!R||m.allBuiltInEntityIds.has(R.id)||T.add(R.id)}),m.order=Array.from(T),m.flatRecord=f,m.orderEntities();const b=a?h.addChangeSet(new ee(h,M.sessionAuthor,g,h,!0,"project-init-from-fetch-result")):null;return m.visit(R=>{if(R.id===h.id)return;const I=Oe(R,h);try{I.hydrateAncestors(),I.addSelfToProject(null);const C=Qd(R);Object.keys(C.downstream).forEach(N=>{const $=h.get(N);$&&$.hydrateAncestors()})}catch(C){if(c)se.Logger.error("Error hydrating ancestors: ",C);else throw C}}),a?(m.visit(R=>{if(R.id===h.id)return;const I=h.get(R.id);if(I)try{I.afterAllChildrenInitialized(b),I.captureVersion()}catch(C){if(c)se.Logger.error("Error in afterAllChildrenInitialized: ",C);else throw C}}),h.afterAllChildrenInitialized(b),h.subscribe(),h.captureVersion()):(kc(h,g).forEach(I=>{I.remove({ignoreUpstream:!0},null)}),m.visit(I=>{if(I.id===h.id)return;const C=h.get(I.id);C&&(C.initialized=!0,C.captureVersion())}),h.initialized=!0,h.subscribe(),h.captureVersion()),h.initialized=!0,h.emit(nn.PROJECT_INITIALIZED,h,b),b==null||b.attemptAutoclose("project-init-from-fetch-result",h.id),h}async function ozi(s,u={enrich:!0,shallowErrors:!1,yieldEvery:100},i){const n={enrich:!0,shallowErrors:!1,yieldEvery:100,...u},{enrich:a,shallowErrors:c,yieldEvery:e}=n,f=se.YieldTracker.from({yieldEvery:e}),h=s.project,m=s.record,T=await VC(s.project,{shallowErrors:c,tracker:f},i);T.instances[h.id]=T;const g=new Ma(void 0,{allBuiltInEntityIds:T.diggestedBuiltInBaseEntitiesIds});await g.flattenAsync(h,{tracker:f}),await g.orderEntitiesAsync({tracker:f});const b=new Set;m[h.id]=h,b.add(h.id);const R=j().toISOString();for(const[C,N]of Object.entries(m))!N||g.allBuiltInEntityIds.has(N.id)||(b.add(N.id),await f.tick());g.order=Array.from(b),g.flatRecord=m,await g.orderEntitiesAsync({tracker:f});const I=a?T.addChangeSet(new ee(T,M.sessionAuthor,R,T,!0,"project-init-from-fetch-result")):null;if(await g.visitAsync(C=>{if(C.id===T.id)return;const N=Oe(C,T);try{N.hydrateAncestors(),N.addSelfToProject(null);const $=Qd(C);Object.keys($.downstream).forEach(x=>{const G=T.get(x);G&&G.hydrateAncestors()})}catch($){if(c)se.Logger.error("Error hydrating ancestors: ",$);else throw se.Logger.log("Error hydrating ancestors: ",$),$}},{tracker:f}),a){try{await g.visitAsync(C=>{if(C.id===T.id)return;const N=T.get(C.id);N&&(N.afterAllChildrenInitialized(I),N.captureVersion())},{tracker:f})}catch(C){if(c)se.Logger.error("Error in afterAllChildrenInitialized: ",C);else throw se.Logger.log("Error in afterAllChildrenInitialized: ",C),C}T.afterAllChildrenInitialized(I),T.subscribe(),T.captureVersion()}else kc(T,R).forEach(N=>{N.remove({ignoreUpstream:!0},null)}),await g.visitAsync(N=>{if(N.id===T.id)return;const $=T.get(N.id);$&&($.initialized=!0,$.captureVersion())},{tracker:f}),T.initialized=!0,T.subscribe(),T.captureVersion();return T.initialized=!0,T.emit(nn.PROJECT_INITIALIZED,T,I),I==null||I.attemptAutoclose("project-init-from-fetch-result",T.id),T}async function dzi(s,u=PE){const i={...PE,...u};if(i.empty)return{data:{project:{id:s.id,workspaceId:"",deletable:!0,editable:!0,type:l.Project,version:M.UUID.uuid(),createdAt:j().toISOString(),author:M.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={...TM};return a.id=s.id,{data:{project:a,record:{}}}}return se.Logger.log("Fetching project from external API"),new Promise(async a=>{try{if(i.onFetch){const c=await i.onFetch(s.id);if(c){a({data:c});return}}else a({data:null})}catch(c){se.Logger.error("Error fetching project: ",c),a({data:null})}})}function xC(s,u={shallowErrors:!1},i){const n=new M(s,i);Yrt(n),zrt(n),Wrt(n),Jrt(n),Qrt(n),Xrt(n),eat(n);const a=u.allBuiltInIds??new Set([...n.getAllBuiltInIds(),...BC()]);return n.diggestedBuiltInBaseEntitiesIds=a,a.forEach(c=>{if(!n.builtInInstances[c]&&n.instances[c])n.builtInInstances[c]=n.instances[c],delete n.instances[c];else if(!n.builtInInstances[c]&&!u.shallowErrors)throw new Error(`Built in entity was not properly initialized: ${c}`)}),n.instances[n.id]=n,n.activeVersion=!0,n}async function VC(s,u={shallowErrors:!1},i){const n=se.YieldTracker.from(u),a=new M(s,i);Yrt(a),zrt(a),await se.yieldToEventLoop(),Wrt(a),await se.yieldToEventLoop(),Jrt(a),Qrt(a),Xrt(a),eat(a),await se.yieldToEventLoop();const c=u.allBuiltInIds??new Set([...a.getAllBuiltInIds(),...await MC()]);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]&&!u.shallowErrors)throw new Error(`Built in entity was not properly initialized: ${e}`);a.instances[e]&&delete a.instances[e],await n.tick()}return a.instances[a.id]=a,a.activeVersion=!0,a}function kc(s,u){return s.instancesList.filter(n=>j(n.createdAt).isAfter(j(u)||!!n.previousVersion))}function uzi(s,{enrich:u,shallowErrors:i,...n}={enrich:!0,shallowErrors:!1},a){var R,I;const c=new Map,e=new Map;Object.keys(s.instances).forEach(C=>{if(s.diggestedBuiltInBaseEntitiesIds.has(C)){c.set(C,C),e.set(C,C);return}const N=s.get(C);if(!KC(N,{...s.instances,...s.builtInInstances}).every(G=>!s.diggestedBuiltInBaseEntitiesIds.has(G))){c.set(C,C),e.set(C,C);return}if(n.keepIds)c.set(C,C),e.set(C,C);else{const G=M.UUID.uuid();c.set(C,G),e.set(G,C)}});const f=((R=n.resetVersionOptions)==null?void 0:R.commonTimestamp)??j().toISOString(),h=s.toShallowJSON({seenEntityMaps:c});h.previousVersion=null,h.createdAt=f,h.version=M.UUID.uuid(),h.author=((I=n.resetVersionOptions)==null?void 0:I.author)??(M.sessionAuthor||"1");const m=xC(h,{shallowErrors:i,allBuiltInIds:s.diggestedBuiltInBaseEntitiesIds},a);m.instances[m.id]=m;const T=u?m.addChangeSet(new ee(m,M.sessionAuthor,f,m,!0,"project-clone")):null,g=new Ma(s,{allBuiltInEntityIds:s.diggestedBuiltInBaseEntitiesIds}),b=R2(g.flatRecord,c);return g.visit(C=>{var G;const N=C.toShallowJSON({seenEntityMaps:c});N.previousVersion=null,N.createdAt=f,N.version=M.UUID.uuid(),N.author=((G=n.resetVersionOptions)==null?void 0:G.author)??(M.sessionAuthor||"1");const $=Qd(N,b);if(Object.keys($.upstream).length){let K=!1;if(Object.keys($.upstream).forEach(Z=>{if(!K&&(!m.get(Z)||m.getDeleted(Z))){K=!0;return}}),K)return}const x=Oe(N,m);x.hydrateAncestors(),x.addSelfToProject(T),T==null||T.add(x,re.Added),n.onVisit&&n.onVisit(N)}),u?(g.visit(C=>{if(C.id===m.id)return;const N=m.get(c.get(C.id));N&&(N.afterAllChildrenInitialized(T),N.captureVersion())}),m.afterAllChildrenInitialized(T),m.subscribe(),m.captureVersion()):(kc(m,f).forEach(N=>{N.remove({ignoreUpstream:!0},null)}),g.visit(N=>{if(N.id===m.id)return;const $=m.get(N.id);$&&($.initialized=!0,$.captureVersion())}),m.initialized=!0,m.subscribe(),m.captureVersion()),m.instancesList.forEach(C=>{C.previousVersion=null}),T==null||T.attemptAutoclose("project-clone",m.id),{project:m,maps:c}}async function pzi(s,{shallowErrors:u,...i}={shallowErrors:!1,yieldEvery:100}){var m,T;const n=se.YieldTracker.from(i),a=new Map,c=new Map;Object.keys(s.instances).forEach(g=>{if(s.diggestedBuiltInBaseEntitiesIds.has(g)){a.set(g,g),c.set(g,g);return}const b=M.UUID.uuid();a.set(g,b),c.set(b,g)});const e=((m=i.resetVersionOptions)==null?void 0:m.commonTimestamp)??j().toISOString(),f=s.toShallowJSON({seenEntityMaps:a});f.previousVersion=null,f.createdAt=e,f.version=M.UUID.uuid(),f.author=((T=i.resetVersionOptions)==null?void 0:T.author)??(M.sessionAuthor||"1");const h=await s.toFullProjectTransferAsync({tracker:n,seenEntityMaps:a,resetVersionOptions:i.resetVersionOptions,onVisit:i.onVisit});return{project:f,record:h.record,order:h.order,maps:a}}async function czi(s,{enrich:u,shallowErrors:i,...n}={enrich:!0,shallowErrors:!1,yieldEvery:100},a){var I,C;const c=se.YieldTracker.from(n),e=new Map,f=new Map;for(const N of Object.keys(s.instances)){if(s.diggestedBuiltInBaseEntitiesIds.has(N)){e.set(N,N),f.set(N,N),await c.tick();continue}if(n.keepIds)e.set(N,N),f.set(N,N);else{const $=M.UUID.uuid();e.set(N,$),f.set($,N)}await c.tick()}const h=((I=n.resetVersionOptions)==null?void 0:I.commonTimestamp)??j().toISOString(),m=s.toShallowJSON({seenEntityMaps:e});m.previousVersion=null,m.createdAt=h,m.version=M.UUID.uuid(),m.author=((C=n.resetVersionOptions)==null?void 0:C.author)??(M.sessionAuthor||"1");const T=await VC(m,{shallowErrors:i,tracker:c},a);T.diggestedBuiltInBaseEntitiesIds=s.diggestedBuiltInBaseEntitiesIds,T.instances[T.id]=T;const g=u?T.addChangeSet(new ee(T,M.sessionAuthor,h,T,!0,"project-clone")):null,b=new Ma(void 0,{allBuiltInEntityIds:s.diggestedBuiltInBaseEntitiesIds}),R=await s.toFullProjectTransferAsync({tracker:c,seenEntityMaps:e,resetVersionOptions:n.resetVersionOptions,onVisit:n.onVisit,shallowErrors:i});b.flatRecord=R.record,b.order=R.order,await b.visitAsync(N=>{var K;if(s.diggestedBuiltInBaseEntitiesIds.has(N.id))return;const $=N;$.previousVersion=null,$.createdAt=h,$.version=M.UUID.uuid(),$.author=((K=n.resetVersionOptions)==null?void 0:K.author)??(M.sessionAuthor||"1");const x=Qd($,b.flatRecord);if(Object.keys(x.upstream).length){let Z=!1;if(Object.keys(x.upstream).forEach(H=>{if(!Z&&(!T.get(H)||T.getDeleted(H))){Z=!0;return}}),Z)return}const G=Oe($,T);G.hydrateAncestors(),G.addSelfToProject(g),g==null||g.add(G,re.Added)},{tracker:c}),u?(await b.visitAsync(N=>{if(N.id===T.id||s.diggestedBuiltInBaseEntitiesIds.has(N.id))return;const $=T.get(e.get(N.id));$&&($.afterAllChildrenInitialized(g),$.captureVersion())},{tracker:c}),T.afterAllChildrenInitialized(g),T.subscribe(),T.captureVersion()):(kc(T,h).forEach($=>{$.remove({ignoreUpstream:!0},null)}),await b.visitAsync($=>{if($.id===T.id)return;const x=T.get($.id);x&&(x.initialized=!0,x.captureVersion())},{tracker:c}),T.initialized=!0,T.subscribe(),T.captureVersion());for(const N of T.instancesList)N.previousVersion=null,await c.tick();return g==null||g.attemptAutoclose("project-clone",T.id),{project:T,maps:e}}function fzi(s,u,i=u.addChangeSet(new ee(u,M.sessionAuthor,j().toISOString(),u,!0,P.AfterAllChildrenInitialized)),{enrich:n,shallowErrors:a,...c}={shallowErrors:!1,enrich:!0}){var b,R;const e=new Map,f=new Map;Object.keys(s.instances).forEach(I=>{if(s.diggestedBuiltInBaseEntitiesIds.has(I)){e.set(I,I),f.set(I,I);return}if(I===s.id){e.set(I,u.id),f.set(u.id,I);return}const C=s.get(I);if(!KC(C,{...s.instances,...s.builtInInstances}).every(G=>!s.diggestedBuiltInBaseEntitiesIds.has(G))){e.set(I,I),f.set(I,I);return}const x=M.UUID.uuid();e.set(I,x),f.set(x,I)});const h=((b=c.resetVersionOptions)==null?void 0:b.commonTimestamp)??j().toISOString(),m=s.toShallowJSON({seenEntityMaps:e});m.previousVersion=null,m.createdAt=h,m.version=M.UUID.uuid(),m.author=((R=c.resetVersionOptions)==null?void 0:R.author)??(M.sessionAuthor||"1");const T=new Ma(s,{allBuiltInEntityIds:s.diggestedBuiltInBaseEntitiesIds}),g=R2(T.flatRecord,e);return T.visit(I=>{var $;if(I.id===u.id)return;const C=I.toShallowJSON({seenEntityMaps:e});C.previousVersion=null,C.createdAt=h,C.version=M.UUID.uuid(),C.author=(($=c.resetVersionOptions)==null?void 0:$.author)??(M.sessionAuthor||"1");const N=Qd(C,g);if(Object.keys(N.upstream).length){let x=!1;if(Object.keys(N.upstream).forEach(G=>{if(!x&&(!u.get(G)||u.getDeleted(G))){x=!0;return}}),x)return}try{const x=Oe(C,u);x.hydrateAncestors(),x.addSelfToProject(i),i==null||i.add(x,re.Added),c.onVisit&&c.onVisit(C)}catch(x){if(a)se.Logger.error("Error cloning entity onto existing project: ",x);else throw se.Logger.log("Error cloning entity onto existing project: ",x),x}}),n?(T.visit(I=>{if(I.id===u.id)return;const C=u.get(e.get(I.id));C&&(C.afterAllChildrenInitialized(i),C.previousVersion=null,C.captureVersion())}),u.afterAllChildrenInitialized(i),u.subscribe(),u.captureVersion()):(kc(u,h).forEach(C=>{C.remove({ignoreUpstream:!0},null)}),T.visit(C=>{if(C.id===u.id)return;const N=u.get(C.id);N&&(N.initialized=!0,N.previousVersion=null,N.captureVersion())}),u.initialized=!0,u.subscribe(),u.captureVersion()),u.afterAllChildrenInitialized(i),u.captureVersion(),{project:u,maps:e,changeSet:i}}async function yzi(s,u,i=u.addChangeSet(new ee(u,M.sessionAuthor,j().toISOString(),u,!0,P.AfterAllChildrenInitialized)),{enrich:n,shallowErrors:a,...c}={enrich:!0,shallowErrors:!1,yieldEvery:100}){var R,I;const e=se.YieldTracker.from(c),f=new Map,h=new Map;for(const C of Object.keys(s.instances)){if(s.diggestedBuiltInBaseEntitiesIds.has(C)){f.set(C,C),h.set(C,C),await e.tick();continue}if(C===s.id){f.set(C,u.id),h.set(u.id,C),await e.tick();continue}const N=M.UUID.uuid();f.set(C,N),h.set(N,C),await e.tick()}const m=((R=c.resetVersionOptions)==null?void 0:R.commonTimestamp)??j().toISOString(),T=s.toShallowJSON({seenEntityMaps:f});T.previousVersion=null,T.createdAt=m,T.version=M.UUID.uuid(),T.author=((I=c.resetVersionOptions)==null?void 0:I.author)??(M.sessionAuthor||"1"),u.diggestedBuiltInBaseEntitiesIds=s.diggestedBuiltInBaseEntitiesIds;const g=new Ma(void 0,{allBuiltInEntityIds:s.diggestedBuiltInBaseEntitiesIds}),b=await s.toFullProjectTransferAsync({tracker:e,seenEntityMaps:f,resetVersionOptions:c.resetVersionOptions,onVisit:c.onVisit,shallowErrors:a});return g.flatRecord=b.record,g.order=b.order,await g.visitAsync(C=>{var x;if(s.diggestedBuiltInBaseEntitiesIds.has(C.id)||C.id===u.id)return;const N=C;N.previousVersion=null,N.createdAt=m,N.version=M.UUID.uuid(),N.author=((x=c.resetVersionOptions)==null?void 0:x.author)??(M.sessionAuthor||"1");const $=Qd(N,g.flatRecord);if(Object.keys($.upstream).length){let G=!1;if(Object.keys($.upstream).forEach(K=>{if(!G&&(!u.get(K)||u.getDeleted(K))){G=!0;return}}),G)return}try{const G=Oe(N,u);G.hydrateAncestors(),G.addSelfToProject(i),i==null||i.add(G,re.Added)}catch(G){if(a)se.Logger.error("Error cloning entity onto existing project: ",G);else throw se.Logger.log("Error cloning entity onto existing project: ",G),G}},{tracker:e}),n?(await g.visitAsync(C=>{if(C.id===u.id||s.diggestedBuiltInBaseEntitiesIds.has(C.id))return;const N=u.get(f.get(C.id));N&&(N.afterAllChildrenInitialized(i),N.previousVersion=null,N.captureVersion())},{tracker:e}),u.afterAllChildrenInitialized(i),u.subscribe(),u.captureVersion()):(kc(u,m).forEach(N=>{N.remove({ignoreUpstream:!0},null)}),await g.visitAsync(N=>{if(N.id===u.id)return;const $=u.get(N.id);$&&($.initialized=!0,$.previousVersion=null,$.captureVersion())},{tracker:e}),u.initialized=!0,u.subscribe(),u.captureVersion()),u.afterAllChildrenInitialized(i),u.captureVersion(),{project:u,maps:f,changeSet:i}}function iat(s,{enrich:u,shallowErrors:i}={enrich:!0,shallowErrors:!1},n){const a=xC(s,{shallowErrors:i},n);a.activeVersion=!0;const c=j().toISOString(),e=u?a.addChangeSet(new ee(a,M.sessionAuthor,c,a,!0,"project-init")):null;e&&(e.type=Kw.Automatic);const f=new Ma(s,{allBuiltInEntityIds:a.diggestedBuiltInBaseEntitiesIds});return f.visit(h=>{const m=Oe(h,a);m.hydrateAncestors(),m.addSelfToProject(e)}),u?(f.visit(h=>{if(h.id===a.id)return;const m=a.get(h.id);m&&(m.afterAllChildrenInitialized(e),m.captureVersion())}),a.afterAllChildrenInitialized(e),a.subscribe(),a.captureVersion()):(kc(a,c).forEach(m=>{m.remove({ignoreUpstream:!0},null)}),f.visit(m=>{if(m.id===a.id)return;const T=a.get(m.id);T&&(T.initialized=!0,T.captureVersion())}),a.initialized=!0,a.subscribe(),a.captureVersion()),a.initialized=!0,a.emit(nn.PROJECT_INITIALIZED,a,e),e==null||e.attemptAutoclose("project-init",a.id),a}async function hzi(s,{enrich:u,shallowErrors:i,yieldEvery:n}={enrich:!0,shallowErrors:!1,yieldEvery:100},a){const c=se.YieldTracker.from({yieldEvery:n}),e=await VC(s,{shallowErrors:i,tracker:c},a),f=j().toISOString(),h=u?e.addChangeSet(new ee(e,M.sessionAuthor,f,e,!0,"project-init")):null;h&&(h.type=Kw.Automatic);const m=new Ma(void 0,{allBuiltInEntityIds:e.diggestedBuiltInBaseEntitiesIds});return await m.flattenAsync(s,{tracker:c}),await m.orderEntitiesAsync({tracker:c}),await m.visitAsync(T=>{const g=Oe(T,e);g.hydrateAncestors(),g.addSelfToProject(h)},{tracker:c}),u?(await m.visitAsync(T=>{if(T.id===e.id)return;const g=e.get(T.id);g&&(g.afterAllChildrenInitialized(h),g.captureVersion())},{tracker:c}),e.afterAllChildrenInitialized(h),e.subscribe(),e.captureVersion()):(kc(e,f).forEach(g=>{g.remove({ignoreUpstream:!0},null)}),await m.visitAsync(g=>{if(g.id===e.id)return;const b=e.get(g.id);b&&(b.initialized=!0,b.captureVersion())},{tracker:c}),e.initialized=!0,e.subscribe(),e.captureVersion()),e.initialized=!0,e.emit(nn.PROJECT_INITIALIZED,e,h),h==null||h.attemptAutoclose("project-init",e.id),e}async function mzi(s,u=PE,i){const n={...PE,...u};if(s.id&&vh[s.id]&&!n.ignoreCache)return vh[s.id];if(s.id&&gR[s.id]&&!n.ignoreCache)return await gR[s.id],vh[s.id];const a=dzi(s,n);s.id&&(gR[s.id]=a);const c=await a;if(c.data){let e;return n.mock?e=iat(TM,{enrich:!!n.enrich},i):c.data instanceof M?e=c.data:e=tat(c.data,{enrich:!!n.enrich},i),vh[s.id]=e,s.id&&delete gR[s.id],e}return null}function Tzi(s){return vh[s.id]&&delete vh[s.id],null}const _E=Yt([st(),rl(),Cr(),sc()]),nat=LT([ba.CurrentDateAndTime,ba.Random,ba.Unique]),NC=Dt({type:nat,rangeStart:_E.nullable(),rangeEnd:_E.nullable()}),mA=NC.extend({type:It(ba.Random),rangeStart:_E,rangeEnd:_E}),rat=NC.extend({type:It(ba.Unique),rangeStart:ro(),rangeEnd:ro()}),aat=NC.extend({type:It(ba.CurrentDateAndTime),rangeStart:ro(),rangeEnd:ro()}),$C=mA.extend({rangeStart:rl().nullable(),rangeEnd:rl().nullable()}),sat=$C.extend({rangeStart:rl(),rangeEnd:ro()}),lat=$C.extend({rangeStart:ro(),rangeEnd:rl()}),oat=$C.extend({rangeStart:rl(),rangeEnd:rl()}),LC=mA.extend({rangeStart:rl().nullable(),rangeEnd:rl().nullable()}),dat=LC.extend({rangeStart:rl(),rangeEnd:ro()}),uat=LC.extend({rangeStart:ro(),rangeEnd:rl()}),pat=LC.extend({rangeStart:rl(),rangeEnd:rl()}),GC=mA.extend({rangeStart:sc().nullable(),rangeEnd:sc().nullable()}),cat=GC.extend({rangeStart:sc(),rangeEnd:ro()}),fat=GC.extend({rangeStart:ro(),rangeEnd:sc()}),yat=GC.extend({rangeStart:sc(),rangeEnd:sc()}),hat=mA.extend({rangeStart:ro(),rangeEnd:ro()}),mat=Yt([dat,uat,pat]),Tat=Yt([sat,lat,oat]),vat=Yt([cat,fat,yat,aat]),vzi=Yt([mat,Tat,vat,rat,hat]);function BC(){const s=new Set;return new Set(vG.flatMap(i=>Qe(i,s)).map(i=>i.id))}function Pu(s){return[...s.calledByEntry||[],...s.calledByError||[],...s.calledBySuccess||[]].filter(u=>u.type!==l.GenericReference)}function gat(s,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(s.id))return[];if(u.add(s.id),s.type!==l.ActionDescriptor)throw new Error("Entity must be an action descriptor to be flattened");return[s,...s.inputs.flatMap(n=>Qe(n,u,i)),...s.dataType?Qe(s.dataType,u,i):[],...s.error?Qe(s.error,u,i):[],...s.parent?Qe(s.parent,u,i):[]]}function Eat(s,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(s.id))return[];if(u.add(s.id),s.type!==l.ArgumentDeclaration)throw new Error("Entity must be an argument declaration to be flattened");return[s,...s.defaultValue?Qe(s.defaultValue,u):[],...s.writesValues.flatMap(n=>Qe(n,u,i)),...s.implements.flatMap(n=>Qe(n,u,i)),...s.dataType?Qe(s.dataType,u,i):[],...s.parent?Qe(s.parent,u,i):[]]}function bat(s,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(s.id))return[];if(u.add(s.id),s.type!==l.BreakStatement)throw new Error("Entity must be a break statement to be flattened");return[s,...s.outputs.flatMap(n=>Qe(n,u,i)),...s.throws?Qe(s.throws,u,i):[],...s.dataType?Qe(s.dataType,u,i):[],...s.readsValue?Qe(s.readsValue,u,i):[],...(Pu(s)||[]).flatMap(n=>Qe(n,u,i)),...s.parent?Qe(s.parent,u,i):[]]}function Aat(s,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(s.id))return[];if(u.add(s.id),s.type!==l.BuiltInBaseEntity)throw new Error("Entity must be a built-in base entity to be flattened");return[s,...(s.properties||[]).flatMap(n=>Qe(n,u,i)),...(s.methods||[]).flatMap(n=>Qe(n,u,i)),...(s.abstractMethods||[]).flatMap(n=>Qe(n,u,i)),...s.allPropertiesImplement?Qe(s.allPropertiesImplement,u,i):[],...s.additionalPropertiesDataType?Qe(s.additionalPropertiesDataType,u,i):[],...s.extends?Qe(s.extends,u,i):[]]}function Iat(s,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(s.id))return[];if(u.add(s.id),s.type!==l.Condition)throw new Error("Entity must be a condition to be flattened");return[s,...(s.andChildrenGroup||[]).flatMap(n=>Qe(n,u,i)),...(s.orChildrenGroup||[]).flatMap(n=>Qe(n,u,i)),...(s.inputs||[]).flatMap(n=>Qe(n,u,i)),...(s.successCalls||[]).flatMap(n=>Qe(n,u,i)),...(s.errorCalls||[]).flatMap(n=>Qe(n,u,i)),...(Pu(s)||[]).flatMap(n=>Qe(n,u,i)),...s.parent?Qe(s.parent,u,i):[]]}function Rat(s,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(s.id))return[];if(u.add(s.id),s.type!==l.ContinueStatement)throw new Error("Entity must be a continue statement to be flattened");return[s,...s.outputs.flatMap(n=>Qe(n,u,i)),...s.readsValue?Qe(s.readsValue,u,i):[],...s.throws?Qe(s.throws,u,i):[],...s.dataType?Qe(s.dataType,u,i):[],...(Pu(s)||[]).flatMap(n=>Qe(n,u,i)),...s.parent?Qe(s.parent,u,i):[]]}function Dat(s,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(s.id))return[];if(u.add(s.id),s.type!==l.DefinitionEntity)throw new Error("Entity must be a definition entity to be flattened");return[s,...s.extends?Qe(s.extends,u,i):[],...(s.implements||[]).flatMap(n=>Qe(n,u,i)),...(s.properties||[]).flatMap(n=>Qe(n,u,i)),...(s.methods||[]).flatMap(n=>Qe(n,u,i)),...(s.abstractMethods||[]).flatMap(n=>Qe(n,u,i)),...s.allPropertiesImplement?Qe(s.allPropertiesImplement,u,i):[],...s.additionalPropertiesDataType?Qe(s.additionalPropertiesDataType,u,i):[],...s.parent?Qe(s.parent,u,i):[]]}function wat(s,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(s.id))return[];if(u.add(s.id),s.type!==l.DataType)throw new Error("Entity must be a data type to be flattened");return[s,...(s.andChildrenGroup||[]).flatMap(n=>Qe(n,u,i)),...(s.orChildrenGroup||[]).flatMap(n=>Qe(n,u,i)),...s.entity?Qe(s.entity,u,i):[],...s.foreignKeyRef?Qe(s.foreignKeyRef,u,i):[],...s.parent?Qe(s.parent,u,i):[]]}function Cat(s,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(s.id))return[];if(u.add(s.id),s.type!==l.FunctionCall)throw new Error("Entity must be a function call to be flattened");return[s,...(s.inputs||[]).flatMap(n=>Qe(n,u,i)),...(s.outputs||[]).flatMap(n=>Qe(n,u,i)),...s.error?Qe(s.error,u,i):[],...(Pu(s)||[]).flatMap(n=>Qe(n,u,i)),...(s.successCalls||[]).flatMap(n=>Qe(n,u,i)),...(s.errorCalls||[]).flatMap(n=>Qe(n,u,i)),...(s.writesValues||[]).flatMap(n=>Qe(n,u,i)),...s.parent?Qe(s.parent,u,i):[]]}function Oat(s,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(s.id))return[];if(u.add(s.id),s.type!==l.FunctionDeclaration)throw new Error("Entity must be a function declaration to be flattened");return[s,...(s.inputs||[]).flatMap(n=>Qe(n,u,i)),...(s.calls||[]).flatMap(n=>Qe(n,u,i)),...s.dataType?Qe(s.dataType,u,i):[],...s.implements?Qe(s.implements,u,i):[],...s.parent?Qe(s.parent,u,i):[]]}function Pat(s,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(s.id))return[];if(u.add(s.id),s.type!==l.GlobalEvent)throw new Error("Entity must be a global event to be flattened");return[s,...(s.inputs||[]).flatMap(n=>Qe(n,u,i)),...(s.calls||[]).flatMap(n=>Qe(n,u,i)),...s.implements?Qe(s.implements,u,i):[],...s.parent?Qe(s.parent,u,i):[]]}function _at(s,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(s.id))return[];if(u.add(s.id),s.type!==l.InputMap)throw new Error("Entity must be an input map to be flattened");return[s,...s.readsValue?Qe(s.readsValue,u,i):[],...s.declaration?Qe(s.declaration,u,i):[],...s.defaultValue?Qe(s.defaultValue,u,i):[],...s.parent?Qe(s.parent,u,i):[]]}function xat(s,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(s.id))return[];if(u.add(s.id),s.type!==l.InstalledProject)throw new Error("Entity must be an installed project to be flattened");return[s,...(s.functions||[]).flatMap(n=>Qe(n,u,i)),...(s.events||[]).flatMap(n=>Qe(n,u,i)),...s.parent?Qe(s.parent,u,i):[]]}function Vat(s,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(s.id))return[];if(u.add(s.id),s.type!==l.InternalCall)throw new Error("Entity must be an internal call to be flattened");return[s,...(s.successCalls||[]).flatMap(n=>Qe(n,u,i)),...(s.errorCalls||[]).flatMap(n=>Qe(n,u,i)),...(s.inputs||[]).flatMap(n=>Qe(n,u,i)),...(s.outputs||[]).flatMap(n=>Qe(n,u,i)),...(Pu(s)||[]).flatMap(n=>Qe(n,u,i)),...s.error?Qe(s.error,u,i):[],...(s.writesValues||[]).flatMap(n=>Qe(n,u,i)),...s.parent?Qe(s.parent,u,i):[]]}function Nat(s,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(s.id))return[];if(u.add(s.id),s.type!==l.LiteralValue)throw new Error("Entity must be a literal value to be flattened");return[s,...s.valueAsTypeSingle?Qe(s.valueAsTypeSingle,u,i):[],...s.valueAsTypeList&&Array.isArray(s.valueAsTypeList)?s.valueAsTypeList.flatMap(n=>Qe(n,u,i)):[],...s.parent?Qe(s.parent,u,i):[]]}function $at(s,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(s.id))return[];if(u.add(s.id),s.type!==l.Loop)throw new Error("Entity must be a loop to be flattened");return[s,...(s.inputs||[]).flatMap(n=>Qe(n,u,i)),...(s.outputs||[]).flatMap(n=>Qe(n,u,i)),...(s.successCalls||[]).flatMap(n=>Qe(n,u,i)),...(s.errorCalls||[]).flatMap(n=>Qe(n,u,i)),...s.error?Qe(s.error,u,i):[],...s.dataType?Qe(s.dataType,u,i):[],...s.body?Qe(s.body,u,i):[],...(Pu(s)||[]).flatMap(n=>Qe(n,u,i)),...(s.writesValues||[]).flatMap(n=>Qe(n,u,i)),...s.parent?Qe(s.parent,u,i):[]]}function Lat(s,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(s.id))return[];if(u.add(s.id),s.type!==l.Operation)throw new Error("Entity must be an operation to be flattened");return[s,...(s.successCalls||[]).flatMap(n=>Qe(n,u,i)),...(s.errorCalls||[]).flatMap(n=>Qe(n,u,i)),...(s.inputs||[]).flatMap(n=>Qe(n,u,i)),...(s.outputs||[]).flatMap(n=>Qe(n,u,i)),...(s.writesValues||[]).flatMap(n=>Qe(n,u,i)),...s.error?Qe(s.error,u,i):[],...(Pu(s)||[]).flatMap(n=>Qe(n,u,i)),...s.parent?Qe(s.parent,u,i):[]]}function Gat(s,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(s.id))return[];if(u.add(s.id),s.type!==l.OutputMap)throw new Error("Entity must be an output map to be flattened");return[s,...(s.writesValues||[]).flatMap(n=>Qe(n,u,i)),...s.declaration?Qe(s.declaration,u,i):[],...s.parent?Qe(s.parent,u,i):[]]}function Bat(s,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(s.id))return[];if(u.add(s.id),s.type!==l.PrimitiveEntity)throw new Error("Entity must be a primitive entity to be flattened");return[s,...(s.properties||[]).flatMap(n=>Qe(n,u,i)),...(s.methods||[]).flatMap(n=>Qe(n,u,i)),...(s.abstractMethods||[]).flatMap(n=>Qe(n,u,i))]}function Mat(s,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(s.id))return[];if(u.add(s.id),s.type!==l.Project)throw new Error("Entity must be a project to be flattened");return[s,...(s.entities||[]).flatMap(n=>Qe(n,u,i)),...(s.functions||[]).flatMap(n=>Qe(n,u,i)),...(s.events||[]).flatMap(n=>Qe(n,u,i)),...(s.projects||[]).flatMap(n=>Qe(n,u,i)),...(s.variableDeclarations||[]).flatMap(n=>Qe(n,u,i)),...(s.variableInstances||[]).flatMap(n=>Qe(n,u,i)),...(s.operations||[]).flatMap(n=>Qe(n,u,i)),...(s.conditions||[]).flatMap(n=>Qe(n,u,i)),...(s.functionCalls||[]).flatMap(n=>Qe(n,u,i)),...(s.projects||[]).flatMap(n=>Qe(n,u,i)),...(s.loops||[]).flatMap(n=>Qe(n,u,i)),...(s.searches||[]).flatMap(n=>Qe(n,u,i))]}function Uat(s,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(s.id))return[];if(u.add(s.id),s.type!==l.Property)throw new Error("Entity must be a property to be flattened");return[s,...s.defaultValue?Qe(s.defaultValue,u,i):[],...s.dataType?Qe(s.dataType,u,i):[],...s.parent?Qe(s.parent,u,i):[]]}function kat(s,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(s.id))return[];if(u.add(s.id),s.type!==l.ReturnStatement)throw new Error("Entity must be a return statement to be flattened");return[s,...(s.outputs||[]).flatMap(n=>Qe(n,u,i)),...s.throws?Qe(s.throws,u,i):[],...s.readsValue?Qe(s.readsValue,u,i):[],...s.dataType?Qe(s.dataType,u,i):[],...(Pu(s)||[]).flatMap(n=>Qe(n,u,i)),...s.parent?Qe(s.parent,u,i):[]]}function Fat(s,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(s.id))return[];if(u.add(s.id),s.type!==l.Search)throw new Error("Entity must be a search to be flattened");return[s,...(s.successCalls||[]).flatMap(n=>Qe(n,u,i)),...(s.errorCalls||[]).flatMap(n=>Qe(n,u,i)),...(s.inputsDeclarations||[]).flatMap(n=>Qe(n,u,i)),...(s.inputs||[]).flatMap(n=>Qe(n,u,i)),...(s.writesValues||[]).flatMap(n=>Qe(n,u,i)),...(s.outputs||[]).flatMap(n=>Qe(n,u,i)),...s.error?Qe(s.error,u,i):[],...s.dataType?Qe(s.dataType,u,i):[],...(Pu(s)||[]).flatMap(n=>Qe(n,u,i)),...s.parent?Qe(s.parent,u,i):[]]}function jat(s,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(s.id))return[];if(u.add(s.id),s.type!==l.ValueDescriptor)throw new Error("Entity must be a value descriptor to be flattened");return[s,...s.defaultValue?Qe(s.defaultValue,u,i):[],...s.dataType?Qe(s.dataType,u,i):[],...s.parent?Qe(s.parent,u,i):[]]}function Sat(s,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(s.id))return[];if(u.add(s.id),s.type!==l.VariableDeclaration)throw new Error("Entity must be a variable declaration to be flattened");return[s,...(s.successCalls||[]).flatMap(n=>Qe(n,u,i)),...(s.errorCalls||[]).flatMap(n=>Qe(n,u,i)),...(s.inputs||[]).flatMap(n=>Qe(n,u,i)),...(s.outputs||[]).flatMap(n=>Qe(n,u,i)),...(s.internalCalls||[]).flatMap(n=>Qe(n,u,i)),...(s.writesValues||[]).flatMap(n=>Qe(n,u,i)),...s.readsValue?Qe(s.readsValue,u,i):[],...s.defaultValue?Qe(s.defaultValue,u,i):[],...(Pu(s)||[]).flatMap(n=>Qe(n,u,i)),...s.dataType?Qe(s.dataType,u,i):[],...s.parent?Qe(s.parent,u,i):[]]}function Kat(s,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(s.id))return[];if(u.add(s.id),s.type!==l.VariableInstance)throw new Error("Entity must be a variable instance to be flattened");return[s,...(s.successCalls||[]).flatMap(n=>Qe(n,u,i)),...(s.errorCalls||[]).flatMap(n=>Qe(n,u,i)),...(s.inputs||[]).flatMap(n=>Qe(n,u,i)),...(s.outputs||[]).flatMap(n=>Qe(n,u,i)),...(s.internalCalls||[]).flatMap(n=>Qe(n,u,i)),...(s.writesValues||[]).flatMap(n=>Qe(n,u,i)),...s.readsValue?Qe(s.readsValue,u,i):[],...s.defaultValue?Qe(s.defaultValue,u,i):[],...(Pu(s)||[]).flatMap(n=>Qe(n,u,i)),...s.declaration?Qe(s.declaration,u,i):[],...s.parent?Qe(s.parent,u,i):[]]}function Qe(s,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(!s)throw new Error("Entity must be defined to be flattened");if(s.type===l.GenericReference)return[];const n=i.ignoreBuiltInBaseEntities?i.diggestedBuiltInBaseEntitiesIds??new Set(BC()):new Set;if(i.diggestedBuiltInBaseEntitiesIds=n,i.ignoreBuiltInBaseEntities&&(Ss.includes(s.type)||n.has(s.id)))return[];if(u.has(s.id))return[];switch(s.type){case l.FunctionCall:return Cat(s,u,i);case l.Operation:return Lat(s,u,i);case l.Condition:return Iat(s,u,i);case l.Loop:return $at(s,u,i);case l.Search:return Fat(s,u,i);case l.GlobalEvent:return Pat(s,u,i);case l.ReturnStatement:return kat(s,u,i);case l.ContinueStatement:return Rat(s,u,i);case l.BreakStatement:return bat(s,u,i);case l.VariableDeclaration:return Sat(s,u,i);case l.DefinitionEntity:return Dat(s,u,i);case l.FunctionDeclaration:return Oat(s,u,i);case l.Project:return Mat(s,u,i);case l.ActionDescriptor:return gat(s,u,i);case l.ArgumentDeclaration:return Eat(s,u,i);case l.ValueDescriptor:return jat(s,u,i);case l.InputMap:return _at(s,u,i);case l.OutputMap:return Gat(s,u,i);case l.DataType:return wat(s,u,i);case l.InstalledProject:return xat(s,u,i);case l.InternalCall:return Vat(s,u,i);case l.LiteralValue:return Nat(s,u,i);case l.Property:return Uat(s,u,i);case l.VariableInstance:return Kat(s,u,i);case l.BuiltInBaseEntity:return i.ignoreBuiltInBaseEntities?[]:Aat(s,u,i);case l.PrimitiveEntity:return i.ignoreBuiltInBaseEntities?[]:Bat(s,u,i)}return[]}async function MC(s={}){const u=new Set,i=se.YieldTracker.from(s),n=new Set;for(const a of vG){const c=await Je(a,u,{ignoreBuiltInBaseEntities:!1,tracker:i});for(const e of c)n.add(e.id),await i.tick()}return n}function _u(s){return[...s.calledByEntry||[],...s.calledByError||[],...s.calledBySuccess||[]].filter(u=>u.type!==l.GenericReference)}async function qat(s,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(s.id))return[];if(u.add(s.id),s.type!==l.ActionDescriptor)throw new Error("Entity must be an action descriptor to be flattened");const n=se.YieldTracker.from(i),a=[s];await n.tick();const c={...i,tracker:n};delete c.yieldEvery;for(const e of s.inputs)a.push(...await Je(e,u,c));return s.dataType&&a.push(...await Je(s.dataType,u,c)),s.error&&a.push(...await Je(s.error,u,c)),s.parent&&a.push(...await Je(s.parent,u,c)),a}async function Zat(s,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(s.id))return[];if(u.add(s.id),s.type!==l.ArgumentDeclaration)throw new Error("Entity must be an argument declaration to be flattened");const n=se.YieldTracker.from(i),a=[s];await n.tick();const c={...i,tracker:n};delete c.yieldEvery,s.dataType&&a.push(...await Je(s.dataType,u,c)),s.parent&&a.push(...await Je(s.parent,u,c)),s.defaultValue&&a.push(...await Je(s.defaultValue,u,c));for(const e of s.writesValues||[])a.push(...await Je(e,u,c));for(const e of s.implements||[])a.push(...await Je(e,u,c));return a}async function Hat(s,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(s.id))return[];if(u.add(s.id),s.type!==l.BreakStatement)throw new Error("Entity must be a break statement to be flattened");const n=se.YieldTracker.from(i),a=[s];await n.tick();const c={...i,tracker:n};delete c.yieldEvery;for(const f of s.outputs)a.push(...await Je(f,u,c));s.parent&&a.push(...await Je(s.parent,u,c)),s.throws&&a.push(...await Je(s.throws,u,c)),s.dataType&&a.push(...await Je(s.dataType,u,c)),s.readsValue&&a.push(...await Je(s.readsValue,u,c));const e=_u(s);for(const f of e)a.push(...await Je(f,u,c));return a}async function Wat(s,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(s.id))return[];if(u.add(s.id),s.type!==l.BuiltInBaseEntity)throw new Error("Entity must be a built-in base entity to be flattened");const n=se.YieldTracker.from(i),a=[s];await n.tick();const c={...i,tracker:n};delete c.yieldEvery;for(const e of s.properties||[])a.push(...await Je(e,u,c));for(const e of s.methods||[])a.push(...await Je(e,u,c));for(const e of s.abstractMethods||[])a.push(...await Je(e,u,c));return s.allPropertiesImplement&&a.push(...await Je(s.allPropertiesImplement,u,c)),s.additionalPropertiesDataType&&a.push(...await Je(s.additionalPropertiesDataType,u,c)),s.extends&&a.push(...await Je(s.extends,u,c)),a}async function zat(s,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(s.id))return[];if(u.add(s.id),s.type!==l.Condition)throw new Error("Entity must be a condition to be flattened");const n=se.YieldTracker.from(i),a=[s];await n.tick();const c={...i,tracker:n};if(delete c.yieldEvery,s.andChildrenGroup&&Array.isArray(s.andChildrenGroup))for(const f of s.andChildrenGroup)a.push(...await Je(f,u,c));if(s.orChildrenGroup&&Array.isArray(s.orChildrenGroup))for(const f of s.orChildrenGroup)a.push(...await Je(f,u,c));for(const f of s.inputs)a.push(...await Je(f,u,c));for(const f of s.successCalls)a.push(...await Je(f,u,c));for(const f of s.errorCalls)a.push(...await Je(f,u,c));const e=_u(s);for(const f of e)a.push(...await Je(f,u,c));return s.parent&&a.push(...await Je(s.parent,u,c)),a}async function Yat(s,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(s.id))return[];if(u.add(s.id),s.type!==l.ContinueStatement)throw new Error("Entity must be a continue statement to be flattened");const n=se.YieldTracker.from(i),a=[s];await n.tick();const c={...i,tracker:n};delete c.yieldEvery;for(const f of s.outputs)a.push(...await Je(f,u,c));const e=_u(s);for(const f of e)a.push(...await Je(f,u,c));return s.parent&&a.push(...await Je(s.parent,u,c)),s.throws&&a.push(...await Je(s.throws,u,c)),s.dataType&&a.push(...await Je(s.dataType,u,c)),s.readsValue&&a.push(...await Je(s.readsValue,u,c)),a}async function Jat(s,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(s.id))return[];if(u.add(s.id),s.type!==l.DefinitionEntity)throw new Error("Entity must be a definition entity to be flattened");const n=se.YieldTracker.from(i),a=[s];await n.tick();const c={...i,tracker:n};delete c.yieldEvery;for(const e of s.properties)a.push(...await Je(e,u,c));for(const e of s.methods)a.push(...await Je(e,u,c));for(const e of s.abstractMethods)a.push(...await Je(e,u,c));for(const e of s.implements)a.push(...await Je(e,u,c));return s.extends&&a.push(...await Je(s.extends,u,c)),s.parent&&a.push(...await Je(s.parent,u,c)),s.additionalPropertiesDataType&&a.push(...await Je(s.additionalPropertiesDataType,u,c)),s.allPropertiesImplement&&a.push(...await Je(s.allPropertiesImplement,u,c)),a}async function Qat(s,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(s.id))return[];if(u.add(s.id),s.type!==l.DataType)throw new Error("Entity must be a data type to be flattened");const n=se.YieldTracker.from(i),a=[s];await n.tick();const c={...i,tracker:n};if(delete c.yieldEvery,s.parent&&a.push(...await Je(s.parent,u,c)),s.foreignKeyRef&&a.push(...await Je(s.foreignKeyRef,u,c)),s.entity&&a.push(...await Je(s.entity,u,c)),s.orChildrenGroup)for(const e of s.orChildrenGroup)a.push(...await Je(e,u,c));if(s.andChildrenGroup)for(const e of s.andChildrenGroup)a.push(...await Je(e,u,c));return a}async function Xat(s,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(s.id))return[];if(u.add(s.id),s.type!==l.FunctionCall)throw new Error("Entity must be a function call to be flattened");const n=se.YieldTracker.from(i),a=[s];await n.tick();const c={...i,tracker:n};delete c.yieldEvery;for(const f of s.inputs)a.push(...await Je(f,u,c));for(const f of s.outputs)a.push(...await Je(f,u,c));s.error&&a.push(...await Je(s.error,u,c));const e=_u(s);for(const f of e)a.push(...await Je(f,u,c));for(const f of s.successCalls)a.push(...await Je(f,u,c));for(const f of s.errorCalls)a.push(...await Je(f,u,c));for(const f of s.writesValues)a.push(...await Je(f,u,c));return s.parent&&a.push(...await Je(s.parent,u,c)),a}async function est(s,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(s.id))return[];if(u.add(s.id),s.type!==l.FunctionDeclaration)throw new Error("Entity must be a function declaration to be flattened");const n=se.YieldTracker.from(i),a=[s];await n.tick();const c={...i,tracker:n};delete c.yieldEvery,s.parent&&a.push(...await Je(s.parent,u,c)),s.implements&&a.push(...await Je(s.implements,u,c)),s.dataType&&a.push(...await Je(s.dataType,u,c));for(const e of s.inputs)a.push(...await Je(e,u,c));for(const e of s.calls)a.push(...await Je(e,u,c));return a}async function tst(s,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(s.id))return[];if(u.add(s.id),s.type!==l.GlobalEvent)throw new Error("Entity must be a global event to be flattened");const n=se.YieldTracker.from(i),a=[s];await n.tick();const c={...i,tracker:n};delete c.yieldEvery,s.parent&&a.push(...await Je(s.parent,u,c)),s.implements&&a.push(...await Je(s.implements,u,c));for(const e of s.inputs)a.push(...await Je(e,u,c));for(const e of s.calls)a.push(...await Je(e,u,c));return a}async function ist(s,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(s.id))return[];if(u.add(s.id),s.type!==l.InputMap)throw new Error("Entity must be an input map to be flattened");const n=se.YieldTracker.from(i),a=[s];await n.tick();const c={...i,tracker:n};return delete c.yieldEvery,s.parent&&a.push(...await Je(s.parent,u,c)),s.declaration&&a.push(...await Je(s.declaration,u,c)),s.readsValue&&a.push(...await Je(s.readsValue,u,c)),s.dataType&&a.push(...await Je(s.dataType,u,c)),s.defaultValue&&a.push(...await Je(s.defaultValue,u,c)),a}async function nst(s,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(s.id))return[];if(u.add(s.id),s.type!==l.InstalledProject)throw new Error("Entity must be an installed project to be flattened");const n=se.YieldTracker.from(i),a=[s];await n.tick();const c={...i,tracker:n};delete c.yieldEvery;for(const e of s.functions)a.push(...await Je(e,u,c));for(const e of s.events)a.push(...await Je(e,u,c));return s.parent&&a.push(...await Je(s.parent,u,c)),a}async function rst(s,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(s.id))return[];if(u.add(s.id),s.type!==l.InternalCall)throw new Error("Entity must be an internal call to be flattened");const n=se.YieldTracker.from(i),a=[s];await n.tick();const c={...i,tracker:n};delete c.yieldEvery;for(const f of s.inputs)a.push(...await Je(f,u,c));for(const f of s.outputs)a.push(...await Je(f,u,c));s.error&&a.push(...await Je(s.error,u,c));const e=_u(s);for(const f of e)a.push(...await Je(f,u,c));for(const f of s.successCalls)a.push(...await Je(f,u,c));for(const f of s.errorCalls)a.push(...await Je(f,u,c));for(const f of s.writesValues)a.push(...await Je(f,u,c));return s.parent&&a.push(...await Je(s.parent,u,c)),a}async function ast(s,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(s.id))return[];if(u.add(s.id),s.type!==l.LiteralValue)throw new Error("Entity must be a literal value to be flattened");const n=se.YieldTracker.from(i),a=[s];await n.tick();const c={...i,tracker:n};if(delete c.yieldEvery,s.valueAsTypeSingle&&a.push(...await Je(s.valueAsTypeSingle,u,c)),s.valueAsTypeList&&Array.isArray(s.valueAsTypeList))for(const e of s.valueAsTypeList)a.push(...await Je(e,u,c));return s.parent&&a.push(...await Je(s.parent,u,c)),a}async function sst(s,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(s.id))return[];if(u.add(s.id),s.type!==l.Loop)throw new Error("Entity must be a loop to be flattened");const n=se.YieldTracker.from(i),a=[s];await n.tick();const c={...i,tracker:n};delete c.yieldEvery;for(const f of s.inputs)a.push(...await Je(f,u,c));for(const f of s.outputs)a.push(...await Je(f,u,c));s.error&&a.push(...await Je(s.error,u,c));const e=_u(s);for(const f of e)a.push(...await Je(f,u,c));for(const f of s.successCalls)a.push(...await Je(f,u,c));for(const f of s.errorCalls)a.push(...await Je(f,u,c));for(const f of s.writesValues)a.push(...await Je(f,u,c));return s.parent&&a.push(...await Je(s.parent,u,c)),s.body&&a.push(...await Je(s.body,u,c)),s.dataType&&a.push(...await Je(s.dataType,u,c)),a}async function lst(s,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(s.id))return[];if(u.add(s.id),s.type!==l.Operation)throw new Error("Entity must be an operation to be flattened");const n=se.YieldTracker.from(i),a=[s];await n.tick();const c={...i,tracker:n};delete c.yieldEvery;for(const f of s.inputs)a.push(...await Je(f,u,c));for(const f of s.outputs)a.push(...await Je(f,u,c));s.error&&a.push(...await Je(s.error,u,c));const e=_u(s);for(const f of e)a.push(...await Je(f,u,c));for(const f of s.successCalls)a.push(...await Je(f,u,c));for(const f of s.errorCalls)a.push(...await Je(f,u,c));for(const f of s.writesValues)a.push(...await Je(f,u,c));return s.parent&&a.push(...await Je(s.parent,u,c)),a}async function ost(s,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(s.id))return[];if(u.add(s.id),s.type!==l.OutputMap)throw new Error("Entity must be an output map to be flattened");const n=se.YieldTracker.from(i),a=[s];await n.tick();const c={...i,tracker:n};delete c.yieldEvery;for(const e of s.writesValues)a.push(...await Je(e,u,c));return s.declaration&&a.push(...await Je(s.declaration,u,c)),s.dataType&&a.push(...await Je(s.dataType,u,c)),s.parent&&a.push(...await Je(s.parent,u,c)),a}async function dst(s,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(s.id))return[];if(u.add(s.id),s.type!==l.PrimitiveEntity)throw new Error("Entity must be a primitive entity to be flattened");const n=se.YieldTracker.from(i),a=[s];await n.tick();const c={...i,tracker:n};delete c.yieldEvery;for(const e of s.properties)a.push(...await Je(e,u,c));for(const e of s.methods)a.push(...await Je(e,u,c));for(const e of s.abstractMethods)a.push(...await Je(e,u,c));return a}async function ust(s,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(s.id))return[];if(u.add(s.id),s.type!==l.Project)throw new Error("Entity must be a project to be flattened");const n=se.YieldTracker.from(i),a=[s];await n.tick();const c={...i,tracker:n};delete c.yieldEvery;for(const e of s.entities)a.push(...await Je(e,u,c));for(const e of s.functions)a.push(...await Je(e,u,c));for(const e of s.events)a.push(...await Je(e,u,c));for(const e of s.projects)a.push(...await Je(e,u,c));for(const e of s.variableDeclarations)a.push(...await Je(e,u,c));for(const e of s.variableInstances)a.push(...await Je(e,u,c));for(const e of s.operations)a.push(...await Je(e,u,c));for(const e of s.conditions)a.push(...await Je(e,u,c));for(const e of s.functionCalls)a.push(...await Je(e,u,c));for(const e of s.projects)a.push(...await Je(e,u,c));for(const e of s.loops)a.push(...await Je(e,u,c));for(const e of s.searches)a.push(...await Je(e,u,c));return a}async function pst(s,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(s.id))return[];if(u.add(s.id),s.type!==l.Property)throw new Error("Entity must be a property to be flattened");const n=se.YieldTracker.from(i),a=[s];await n.tick();const c={...i,tracker:n};return delete c.yieldEvery,s.defaultValue&&a.push(...await Je(s.defaultValue,u,c)),s.dataType&&a.push(...await Je(s.dataType,u,c)),s.parent&&a.push(...await Je(s.parent,u,c)),a}async function cst(s,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(s.id))return[];if(u.add(s.id),s.type!==l.ReturnStatement)throw new Error("Entity must be a return statement to be flattened");const n=se.YieldTracker.from(i),a=[s];await n.tick();const c={...i,tracker:n};delete c.yieldEvery;for(const f of s.outputs)a.push(...await Je(f,u,c));for(const f of s.outputs)a.push(...await Je(f,u,c));s.throws&&a.push(...await Je(s.throws,u,c)),s.readsValue&&a.push(...await Je(s.readsValue,u,c)),s.dataType&&a.push(...await Je(s.dataType,u,c));const e=_u(s);for(const f of e)a.push(...await Je(f,u,c));return s.parent&&a.push(...await Je(s.parent,u,c)),a}async function fst(s,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(s.id))return[];if(u.add(s.id),s.type!==l.Search)throw new Error("Entity must be a search to be flattened");const n=se.YieldTracker.from(i),a=[s];await n.tick();const c={...i,tracker:n};delete c.yieldEvery;for(const f of s.inputs)a.push(...await Je(f,u,c));for(const f of s.outputs)a.push(...await Je(f,u,c));s.error&&a.push(...await Je(s.error,u,c)),s.dataType&&a.push(...await Je(s.dataType,u,c));for(const f of s.inputsDeclarations)a.push(...await Je(f,u,c));const e=_u(s);for(const f of e)a.push(...await Je(f,u,c));for(const f of s.successCalls)a.push(...await Je(f,u,c));for(const f of s.errorCalls)a.push(...await Je(f,u,c));for(const f of s.writesValues)a.push(...await Je(f,u,c));return s.parent&&a.push(...await Je(s.parent,u,c)),a}async function yst(s,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(s.id))return[];if(u.add(s.id),s.type!==l.ValueDescriptor)throw new Error("Entity must be a value descriptor to be flattened");const n=se.YieldTracker.from(i),a=[s];await n.tick();const c={...i,tracker:n};return delete c.yieldEvery,s.defaultValue&&a.push(...await Je(s.defaultValue,u,c)),s.dataType&&a.push(...await Je(s.dataType,u,c)),s.parent&&a.push(...await Je(s.parent,u,c)),a}async function hst(s,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(s.id))return[];if(u.add(s.id),s.type!==l.VariableDeclaration)throw new Error("Entity must be a variable declaration to be flattened");const n=se.YieldTracker.from(i),a=[s];await n.tick();const c={...i,tracker:n};delete c.yieldEvery;for(const f of s.inputs)a.push(...await Je(f,u,c));for(const f of s.outputs)a.push(...await Je(f,u,c));s.error&&a.push(...await Je(s.error,u,c)),s.dataType&&a.push(...await Je(s.dataType,u,c)),s.readsValue&&a.push(...await Je(s.readsValue,u,c)),s.defaultValue&&a.push(...await Je(s.defaultValue,u,c));const e=_u(s);for(const f of e)a.push(...await Je(f,u,c));for(const f of s.successCalls)a.push(...await Je(f,u,c));for(const f of s.errorCalls)a.push(...await Je(f,u,c));for(const f of s.writesValues)a.push(...await Je(f,u,c));for(const f of s.internalCalls)a.push(...await Je(f,u,c));return s.parent&&a.push(...await Je(s.parent,u,c)),a}async function mst(s,u=new Set,i={ignoreBuiltInBaseEntities:!1}){if(u.has(s.id))return[];if(u.add(s.id),s.type!==l.VariableInstance)throw new Error("Entity must be a variable instance to be flattened");const n=se.YieldTracker.from(i),a=[s];await n.tick();const c={...i,tracker:n};delete c.yieldEvery;for(const f of s.inputs)a.push(...await Je(f,u,c));for(const f of s.outputs)a.push(...await Je(f,u,c));s.error&&a.push(...await Je(s.error,u,c)),s.readsValue&&a.push(...await Je(s.readsValue,u,c)),s.defaultValue&&a.push(...await Je(s.defaultValue,u,c));const e=_u(s);for(const f of e)a.push(...await Je(f,u,c));for(const f of s.successCalls)a.push(...await Je(f,u,c));for(const f of s.errorCalls)a.push(...await Je(f,u,c));for(const f of s.writesValues)a.push(...await Je(f,u,c));for(const f of s.internalCalls)a.push(...await Je(f,u,c));return s.parent&&a.push(...await Je(s.parent,u,c)),s.declaration&&a.push(...await Je(s.declaration,u,c)),a}async function Je(s,u=new Set,i={ignoreBuiltInBaseEntities:!1,yieldEvery:100}){const n={...i,ignoreBuiltInBaseEntities:i.ignoreBuiltInBaseEntities??!1};if(!s)throw new Error("Entity must be defined to be flattened");if(s.type===l.GenericReference)return[];const a=se.YieldTracker.from(n);n.tracker=a,n.yieldEvery!==void 0&&delete n.yieldEvery;const c=n.ignoreBuiltInBaseEntities?n.diggestedBuiltInBaseEntitiesIds??new Set(await MC(n)):new Set;if(n.diggestedBuiltInBaseEntitiesIds=c,n.ignoreBuiltInBaseEntities&&(Ss.includes(s.type)||c.has(s.id)))return[];if(u.has(s.id))return[];switch(s.type){case l.FunctionCall:return Xat(s,u,n);case l.Operation:return lst(s,u,n);case l.Condition:return zat(s,u,n);case l.Loop:return sst(s,u,n);case l.Search:return fst(s,u,n);case l.GlobalEvent:return tst(s,u,n);case l.ReturnStatement:return cst(s,u,n);case l.ContinueStatement:return Yat(s,u,n);case l.BreakStatement:return Hat(s,u,n);case l.VariableDeclaration:return hst(s,u,n);case l.DefinitionEntity:return Jat(s,u,n);case l.FunctionDeclaration:return est(s,u,n);case l.Project:return ust(s,u,n);case l.ActionDescriptor:return qat(s,u,n);case l.ArgumentDeclaration:return Zat(s,u,n);case l.ValueDescriptor:return yst(s,u,n);case l.InputMap:return ist(s,u,n);case l.OutputMap:return ost(s,u,n);case l.DataType:return Qat(s,u,n);case l.InstalledProject:return nst(s,u,n);case l.InternalCall:return rst(s,u,n);case l.LiteralValue:return ast(s,u,n);case l.Property:return pst(s,u,n);case l.VariableInstance:return mst(s,u,n);case l.BuiltInBaseEntity:return n.ignoreBuiltInBaseEntities?[]:Wat(s,u,n);case l.PrimitiveEntity:return n.ignoreBuiltInBaseEntities?[]:dst(s,u,n)}return[]}function Tst(s){return s==null||s===""}function gzi(s){return s===null}function Ya(s){return s!=null&&s.valueAsType?!1:Tst(s==null?void 0:s.value)}function ep(s){return s?s.valueAsType===null&&s.value===null:!1}function vst(s,u){if(s===u||!s&&!u)return!0;if(!s||!u||s.name===fe.EntityTemplate&&u.name!==fe.EntityTemplate||u.name===fe.EntityTemplate&&s.name!==fe.EntityTemplate)return!1;if(s.name===fe.ActionDescriptor&&u.name!==fe.ActionDescriptor||u.name===fe.ActionDescriptor&&s.name!==fe.ActionDescriptor)return!1;if(s.valueAsTypeSingle&&!u.valueAsTypeSingle||u.valueAsTypeSingle&&!s.valueAsTypeSingle)return!1;if(s.valueAsTypeList&&!u.valueAsTypeList||u.valueAsTypeList&&!s.valueAsTypeList)return!1;if(s.valueAsTypeSingle&&u.valueAsTypeSingle){if(s.valueAsTypeSingle.id!==u.valueAsTypeSingle.id)return!1}else if(s.valueAsTypeList&&u.valueAsTypeList){if(s.valueAsTypeList.length!==u.valueAsTypeList.length)return!1;for(let i=0;i<s.valueAsTypeList.length;i++)if(s.valueAsTypeList[i].id!==u.valueAsTypeList[i].id)return!1}else if(!s.valueAsType&&!u.valueAsType&&s.value!==u.value)return!1;return!0}function gst(s,u,i){if(!i)throw new Error("[checkIsRowTransformerUpToDate] 'lastPublishedEntityVersion' argument is required");if(!u)throw new Error("[checkIsRowTransformerUpToDate] 'entity' argument is required");if(!s)throw new Error("[checkIsRowTransformerUpToDate] 'newestOpenRowTransformer' argument is required");let n=!0;const a=s.methods.find(c=>{var e;return((e=c.implements)==null?void 0:e.id)===B["built-in-base-entity"].BUILT_IN_SQL_ROW_TRANSFORMER_ENTITY.methods.up.id});if(a?(ga(i).forEach(c=>{const e=a.inputs.find(f=>f.name===c.name);e&&Gi(e.getDataType(null),c.getDataType(null)).compatible||(n=!1)}),a.returnStatements.forEach(c=>{!c.dataType||!c.dataType.entity||c.dataType.entity.type!==l.DefinitionEntity?n=!1:hE(c.dataType.entity,u)||(n=!1)})):n=!1,n===null||n){const c=s.methods.find(e=>{var f;return((f=e.implements)==null?void 0:f.id)===B["built-in-base-entity"].BUILT_IN_SQL_ROW_TRANSFORMER_ENTITY.methods.down.id});c?(ga(u).forEach(e=>{const f=c.inputs.find(h=>h.name===e.name);f&&Gi(f.getDataType(null),e.getDataType(null)).compatible||(n=!1)}),c.returnStatements.forEach(e=>{!e.dataType||!e.dataType.entity||e.dataType.entity.type!==l.DefinitionEntity?n=!1:hE(e.dataType.entity,i)||(n=!1)})):n=!1}return{isPreexistingRowTransformerUpToDate:n}}function MR(s,u){var T,g;const i=B["primitive-entity"].enum.id;if(!s||!u||((T=s.entity)==null?void 0:T.id)!==i||((g=u.entity)==null?void 0:g.id)!==i)return{changed:null,newOptions:[],removedOptions:[],allFinalOptions:[]};const n=s.options||[],a=u.options||[],c=new Set(n),e=new Set(a),f=n.filter(b=>!e.has(b)),h=a.filter(b=>!c.has(b)),m=[...c].sort();return{changed:!!f.length||!!h.length,newOptions:f,removedOptions:h,allFinalOptions:m}}function ZV(s,u,i,n={skipBaseExtension:!1}){var Z;const a={...n||{},skipBaseExtension:(n==null?void 0:n.skipBaseExtension)||!1},c={changesSinceLastPublication:!1,rowTransformerNeeded:!1,newRowTransformerNeeded:!1,newestOpenRowTransformer:null,newRequiredProperties:[],newNonRequiredProperties:[],deletedProperties:[],lastPublishedEntityVersion:null,updatedEntityVersion:i,propChanges:new Map,isPreexistingRowTransformerUpToDate:null,extendedEntities:[]},f=s.entities.filter(H=>{var ne;if(H.id===i.id)return!1;let W=!1,Q=H;for(;Q;){if(((ne=Q.extends)==null?void 0:ne.id)===i.id){W=!0;break}if(Q.extends&&Q.extends.type===l.DefinitionEntity)Q=Q.extends;else break}return W}).map(H=>ZV(s,u,H,{...a,skipBaseExtension:!0}));if(!u)return{...c,changesSinceLastPublication:!0,extendedEntities:f};const h=u.get(i.id);if(!h)return{...c,changesSinceLastPublication:!0,extendedEntities:f};const m=u.entities.filter(H=>ki(H,Ie.SQL_ROW_TRANSFORMER)),g=s.entities.filter(H=>{var Y;if(!ki(H,Ie.SQL_ROW_TRANSFORMER)||m.find(J=>J.id===H.id))return!1;const Q=H.properties.find(J=>!!J.implements.find(te=>B["built-in-base-entity"].BUILT_IN_SQL_ROW_TRANSFORMER_ENTITY.properties.definition.id===te.id));if(!Q)return!1;const ne=(Y=Q.defaultValue)==null?void 0:Y.valueAsType;return ne?ne.id===i.id:!1}).sort((H,W)=>j(H.createdAt).isAfter(j(W.createdAt))?-1:1)[0]||null,b=new Map;let R=!1,I=null;!a.skipBaseExtension&&i.extends&&((Z=i.extends)==null?void 0:Z.type)===l.DefinitionEntity&&(I=ZV(i.project,u,i.extends));const C=ga(i).filter(H=>ga(h).find(ne=>ne.id===H.id)?!1:!Il(H.getDataType(null))),N=ga(i).filter(H=>ga(h).find(ne=>ne.id===H.id)?!1:!!Il(H.getDataType(null))),$=ga(h).filter(H=>!ga(i).find(Q=>Q.id===H.id));ga(i).filter(H=>{var ce,Te,ge,Re,Ce,Ne,Fe,Ae,$e,We,Ue,Ke,at,nt,Xe;const W=ga(h).find(ft=>ft.id===H.id);let Q=!1;if(!W)return!1;const ne=al(H.dataType,!0,`[resolveSQLMigrationsDiffs] Unsupported data-type structure on current property '${H.name}' (${H.id}). 'andChildrenGroup' with more than one child is not supported for SQL column properties.`),Y=al(W.dataType,!0,`[resolveSQLMigrationsDiffs] Unsupported data-type structure on last published property '${H.name}' (${H.id}). 'andChildrenGroup' with more than one child is not supported for SQL column properties.`),J=Am(ne,!0,`[resolveSQLMigrationsDiffs] Unsupported data-type structure on current property '${H.name}' (${H.id}). 'orChildrenGroup' with multiple non-null children is not supported for SQL column properties.`),te=Am(Y,!0,`[resolveSQLMigrationsDiffs] Unsupported data-type structure on last published property '${H.name}' (${H.id}). 'orChildrenGroup' with multiple non-null children is not supported for SQL column properties.`);if(((ce=J==null?void 0:J.foreignKeyRef)==null?void 0:ce.id)!==((Te=te==null?void 0:te.foreignKeyRef)==null?void 0:Te.id)){const ft=J==null?void 0:J.foreignKeyRef,Bi=te==null?void 0:te.foreignKeyRef;b.set(H.id,{...b.get(H.id)||{},newForeignKeyRef:ft||void 0,oldForeignKeyRef:Bi||void 0,property:H,oldProperty:W}),Q=!0,R=!0}else if(((ge=J==null?void 0:J.entity)==null?void 0:ge.id)!==((Re=te==null?void 0:te.entity)==null?void 0:Re.id)||MR(J,te).changed){const ft=B["primitive-entity"].enum.id;((Ce=J==null?void 0:J.entity)==null?void 0:Ce.id)===B["primitive-entity"].string.id||((Ne=te==null?void 0:te.entity)==null?void 0:Ne.id)===B["primitive-entity"].date.id&&((Fe=J==null?void 0:J.entity)==null?void 0:Fe.id)===B["primitive-entity"].number.id?b.set(H.id,{...b.get(H.id)||{},castableDataTypeEntity:{fromId:((Ae=te==null?void 0:te.entity)==null?void 0:Ae.id)||"",toId:(($e=J==null?void 0:J.entity)==null?void 0:$e.id)||""},property:H,oldProperty:W}):((We=J==null?void 0:J.entity)==null?void 0:We.id)===ft&&((Ue=te==null?void 0:te.entity)!=null&&Ue.id)&&MR(J,te).newOptions.length&&!MR(J,te).removedOptions.length?b.set(H.id,{...b.get(H.id)||{},castableDataTypeEntity:{fromId:((Ke=te==null?void 0:te.entity)==null?void 0:Ke.id)||"",toId:((at=J==null?void 0:J.entity)==null?void 0:at.id)||""},property:H,oldProperty:W}):(b.set(H.id,{...b.get(H.id)||{property:H},nonCastableDataTypeEntity:{fromId:((nt=te==null?void 0:te.entity)==null?void 0:nt.id)||"",toId:((Xe=J==null?void 0:J.entity)==null?void 0:Xe.id)||""},property:H,oldProperty:W}),R=!0),Q=!0}H.name!==(W==null?void 0:W.name)&&(b.set(H.id,{...b.get(H.id)||{},nameChange:{from:(W==null?void 0:W.name)||"",to:H.name},property:H,oldProperty:W}),Q=!0);const le=Il(W.getDataType(null)),oe=Il(H.getDataType(null));return oe!==le&&(b.set(H.id,{...b.get(H.id)||{},requiredChange:{from:!le,to:!oe},property:H,oldProperty:W}),oe||(R=!0),Q=!0),Q}),C.length>0&&(R=!0);let x=null;g&&R&&(x=gst(g,i,h).isPreexistingRowTransformerUpToDate);const G=i.name!==h.name?{from:h.name,to:i.name}:void 0;let K=I!=null&&I.rowTransformerNeeded?!0:R;return{...c,changesSinceLastPublication:b.size>0||!!$.length||!!C.length||!!N.length||K,rowTransformerNeeded:K,newestOpenRowTransformer:g,nameChange:G,newRequiredProperties:C,newNonRequiredProperties:N,deletedProperties:$,lastPublishedEntityVersion:h,propChanges:b,newRowTransformerNeeded:K&&!g,isPreexistingRowTransformerUpToDate:x,extendedEntities:f}}function b2(s,u,i,n,a){const c=a==null?void 0:a.ignoreNonEditable;a&&(a.ignoreNonEditable=!0);try{if(!s)throw new Error("[addDifferencesToRowTransformer] 'project' argument is required");if(!u)throw new Error("[addDifferencesToRowTransformer] 'transformer' argument is required");if(!i)throw new Error("[addDifferencesToRowTransformer] 'newEntityState' argument is required");if(!n)throw new Error("[addDifferencesToRowTransformer] 'oldEntityState' argument is required");const e=ga(i),f=ga(n);u.afterAllChildrenInitialized(a);const h=u.methods.find(T=>{var g;return((g=T.implements)==null?void 0:g.id)===B["built-in-base-entity"].BUILT_IN_SQL_ROW_TRANSFORMER_ENTITY.methods.up.id}),m=u.methods.find(T=>{var g;return((g=T.implements)==null?void 0:g.id)===B["built-in-base-entity"].BUILT_IN_SQL_ROW_TRANSFORMER_ENTITY.methods.down.id});if(!h)throw new Error("[addDifferencesToRowTransformer] The 'up' transformer trigger is missing from the parent");if(!m)throw new Error("[addDifferencesToRowTransformer] The 'down' transformer trigger is missing from the parent");f.forEach(T=>{const g=h.inputs.find(C=>C.name===T.name),b=Am(T.getDataType(null))||T.getDataType(null);let R=g,I;if(g)R.editable=!0;else{const C=$l.new(a);C.parent=h.toReference(),C.name=T.name,C.index=T.index,C.implements=[...T.implements.map($=>$.toJSON())];const N=Oe(C,s);N.hydrateAncestors(),a.add(N,re.Added),N.addSelfToProject(a),N.initChildren(a),R=N}if(!g||!R.dataType||R.dataType&&s.diggestedBuiltInBaseEntitiesIds.has(R.dataType.id)){const C=wr.new(a);C.parent=R.toReference();const N=Oe(C,s);N.hydrateAncestors(),a.add(N,re.Added),N.addSelfToProject(a),N.initChildren(a),I=N}else I=R.dataType,I.editable=!0;b&&I.merge(b,a),I.metaSync({editable:!1,deletable:!1},a),R.metaSync({editable:!1,deletable:!1},a)}),[...h.inputs].forEach(T=>{f.find(b=>b.name===T.name)||(T.editable=!0,T.remove({ignoreUpstream:!1},a),T.editable=!1)}),[...h.returnStatements].forEach(T=>{var N,$,x,G,K,Z,H,W,Q;if(!T.dataType||T.dataType&&s.diggestedBuiltInBaseEntitiesIds.has(T.dataType.id)){const ne=wr.new(a);ne.entity=i.toReference(),ne.parent=T.toReference();const Y=Oe(ne,s);Y.hydrateAncestors(),a.add(Y,re.Added),Y.addSelfToProject(a),Y.initChildren(a)}const g=(N=T.dataType)==null?void 0:N.entity,b=!g||g.type!==l.DefinitionEntity||g.type===l.DefinitionEntity&&(($=g.parent)==null?void 0:$.type)===l.Project||((x=g.parent)==null?void 0:x.id)!==((G=T.dataType)==null?void 0:G.id),R=!b&&g&&g.type===l.DefinitionEntity&&g.name&&s.getDefinitionEntities().some(ne=>ne.id!==g.id&&ne.name===g.name),I=g&&g.type===l.DefinitionEntity&&g.name&&!b&&!R?g.name:lc((i==null?void 0:i.name)+" new format",s.getDefinitionEntities());let C=(K=T.dataType)==null?void 0:K.entity;(!((Z=T.dataType)!=null&&Z.entity)||T.dataType.entity.type!==l.DefinitionEntity||T.dataType.entity.type==l.DefinitionEntity&&((H=T.dataType.entity.parent)==null?void 0:H.type)===l.Project||T.dataType.entity.parent.id!==T.dataType.id)&&(C=i.clone(a,T.dataType),C.metaSync({name:I},a)),qR(C,i,a,{exactDataType:!0}),C.setExtension(null,a),C.addImplementation(s.getBuiltIn(B["built-in-base-entity"].BUILT_IN_PERSISTED_ENTITY_ENTITY.id),a),C.properties.forEach(ne=>ne.setExtends(null,a)),T.dataType.setEntity(C,a),(Q=(W=T.dataType)==null?void 0:W.entity)==null||Q.metaSync({name:I},a),T.afterAllChildrenInitialized(a),T.outputs.forEach(ne=>{var oe,ce;if(ne.defaultValue||ne.readsValue)return;const Y=(oe=e.find(Te=>Te.name===me(ne,s)))==null?void 0:oe.id,J=(ce=f.find(Te=>(Te==null?void 0:Te.id)===Y))==null?void 0:ce.name,te=h.inputs.find(Te=>J===me(Te,s)),le=Gi((te==null?void 0:te.getDataType(null))||null,ne.getDataType(null)||null);le!=null&&le.compatible&&(ne.setValueWriter(te,a),te==null||te.addValueReader(ne,a))})}),e.forEach(T=>{var N;const g=(N=T.knownVersions)==null?void 0:N.get(T.previousVersion),b=m.inputs.find($=>$.name===T.name||!!g&&g.name===$.name),R=Am(T.getDataType(null))||T.getDataType(null);let I=b,C;if(b)I.editable=!0,I.metaSync({name:T.name,codeName:T.codeName,description:T.description},a);else{const $=$l.new(a);$.parent=m.toReference(),$.name=T.name,$.codeName=T.codeName,$.description=T.description,$.index=T.index,$.implements=[...T.implements.map(G=>G.toJSON())];const x=Oe($,s);x.hydrateAncestors(),a.add(x,re.Added),x.addSelfToProject(a),x.initChildren(a),I=x}if(!b||!I.dataType||I.dataType&&s.diggestedBuiltInBaseEntitiesIds.has(I.dataType.id)){const $=wr.new(a);$.parent=I.toReference();const x=Oe($,s);x.hydrateAncestors(),a.add(x,re.Added),x.addSelfToProject(a),x.initChildren(a),C=x}else C=I.dataType,C.editable=!0,C.merge(I.dataType,a);R&&C.merge(R,a),C.metaSync({editable:!1,deletable:!1},a),I.metaSync({editable:!1,deletable:!1},a)}),[...m.inputs].forEach(T=>{e.find(b=>{var I;if(b.name===T.name)return!0;const R=(I=b.knownVersions)==null?void 0:I.get(b.previousVersion);if(R&&R.name===T.name)return!0})||(T.editable=!0,T.remove({ignoreUpstream:!1},a),T.editable=!1)}),[...m.returnStatements].forEach(T=>{var N,$,x,G;if(!T.dataType||T.dataType&&s.diggestedBuiltInBaseEntitiesIds.has(T.dataType.id)){const K=wr.new(a);K.parent=T.toReference();const Z=Oe(K,s);Z.hydrateAncestors(),a.add(Z,re.Added),Z.addSelfToProject(a),Z.initChildren(a)}const g=(N=T.dataType)==null?void 0:N.entity,b=!g||g.id===B["built-in-base-entity"].BUILT_IN_PERSISTED_ENTITY_ENTITY.id,R=!b&&g&&g.type===l.DefinitionEntity&&g.name&&s.getDefinitionEntities().some(K=>K.id!==g.id&&K.name===g.name),I=g&&g.type===l.DefinitionEntity&&g.name&&!b&&!R?g.name:lc((n==null?void 0:n.name)+" old format",s.getDefinitionEntities());let C=($=T.dataType)==null?void 0:$.entity;(!C||(C==null?void 0:C.id)===B["built-in-base-entity"].BUILT_IN_PERSISTED_ENTITY_ENTITY.id)&&(C=n.clone(a,T.dataType),C.metaSync({name:I},a)),qR(C,n,a,{exactDataType:!0}),C.setExtension(null,a),C.addImplementation(s.getBuiltIn(B["built-in-base-entity"].BUILT_IN_PERSISTED_ENTITY_ENTITY.id),a),C.properties.forEach(K=>K.setExtends(null,a)),T.dataType.setEntity(C,a),(G=(x=T.dataType)==null?void 0:x.entity)==null||G.metaSync({name:I},a),T.afterAllChildrenInitialized(a),T.outputs.forEach(K=>{var Q,ne,Y;if(K.defaultValue||K.readsValue)return;const Z=(Q=f.find(J=>J.name===me(K,s)))==null?void 0:Q.id,H=(ne=e.find(J=>(J==null?void 0:J.id)===Z))==null?void 0:ne.name,W=m.inputs.find(J=>H===me(J,s));(Y=Gi((W==null?void 0:W.getDataType(null))||null,K.getDataType(null)||null))!=null&&Y.compatible&&(K.setValueWriter(W,a),W==null||W.addValueReader(K,a))})})}finally{a&&(a.ignoreNonEditable=!!c)}}function Est(s,u,i,n,a={}){var $;const c=s.getBuiltIn(Ie.SQL_ROW_TRANSFORMER),e=lc(me(u,s)+" row transformer",s.entities),f=c.implement(e,n),h=f.ownDeclaredProperties.find(x=>{var G;return(G=x.implements)==null?void 0:G.find(K=>K.id===B["built-in-base-entity"].BUILT_IN_SQL_ROW_TRANSFORMER_ENTITY.properties.definition.id)}),m=f.methods.find(x=>{var G;return((G=x.implements)==null?void 0:G.id)===B["built-in-base-entity"].BUILT_IN_SQL_ROW_TRANSFORMER_ENTITY.methods.up.id}),T=f.methods.find(x=>{var G;return((G=x.implements)==null?void 0:G.id)===B["built-in-base-entity"].BUILT_IN_SQL_ROW_TRANSFORMER_ENTITY.methods.down.id});if(!h||!m||!T)throw new Error("Cannot find definition property on the new row transformer entity");if(h.defaultValue)h.defaultValue.setValueAsTypeSingle(u,n);else{const x=Lr.new(n);x.name=fe.EntityTemplate,x.valueAsTypeSingle=u.toJSON(),x.parent=h.toReference();const G=Oe(x,s);G.hydrateAncestors(),n.add(G,re.Added),G.addSelfToProject(n),G.initChildren(n)}b2(s,f,u,i,n),se.Logger.log("BEFORE - changeSet.listAdded",n.listAdded.map(x=>{var K,Z,H,W,Q,ne,Y;const G=s.get(x.id);return G?me(G,s):x.type===l.InputMap?"(not found) "+x.type+" "+x.id+" - declaration: "+((K=x.declaration)==null?void 0:K.type)+" "+((Z=x.declaration)==null?void 0:Z.id)+' "'+((H=x.declaration)==null?void 0:H.name)+`"
|
|
627
627
|
parent: `+((Q=(W=x.parent)==null?void 0:W.parent)==null?void 0:Q.id)+" - "+((Y=(ne=x.parent)==null?void 0:ne.parent)==null?void 0:Y.name):"(not found) "+x.type+" "+x.id})),se.Logger.log("AFTER - changeSet.listAdded",n.listAdded.map(x=>{var K,Z,H,W,Q,ne,Y;const G=s.get(x.id);return G?G.type+' "'+me(G,s)+'" ('+G.id+")":x.type===l.InputMap?"(not found) "+x.type+" ("+x.id+") - declaration: "+((K=x.declaration)==null?void 0:K.type)+" ("+((Z=x.declaration)==null?void 0:Z.id)+') "'+((H=x.declaration)==null?void 0:H.name)+`"
|
|
628
628
|
parent: "`+((Q=(W=x.parent)==null?void 0:W.parent)==null?void 0:Q.name)+'" ('+((Y=(ne=x.parent)==null?void 0:ne.parent)==null?void 0:Y.id)+")":"(not found) "+x.type+" "+x.id})),se.Logger.log("-----------------"),se.Logger.log("Old properties: ",ga(i).map(x=>x.name+" ("+x.id+")")),se.Logger.log("New properties: ",ga(u).map(x=>x.name+" ("+x.id+")"));const g=f.methods.find(x=>{var G;return((G=x.implements)==null?void 0:G.id)===B["built-in-base-entity"].BUILT_IN_SQL_ROW_TRANSFORMER_ENTITY.methods.up.id}),b=f.methods.find(x=>{var G;return((G=x.implements)==null?void 0:G.id)===B["built-in-base-entity"].BUILT_IN_SQL_ROW_TRANSFORMER_ENTITY.methods.down.id});se.Logger.log(`
|
|
629
629
|
Up inputs: `,g==null?void 0:g.inputs.map(x=>x.name+" ("+x.id+")")),se.Logger.log("Up method return statements:",g==null?void 0:g.returnStatements[0].outputs.map(x=>me(x,s)+" ("+x.id+")")),se.Logger.log(`
|
package/dist/index.js
CHANGED
|
@@ -230556,6 +230556,7 @@ class e6i extends Wn {
|
|
|
230556
230556
|
(a) => a.id === CF.inputs.range.id
|
|
230557
230557
|
);
|
|
230558
230558
|
i && (i._codeNativeValueValidation = (a, c) => {
|
|
230559
|
+
console.log("Range input custom validator");
|
|
230559
230560
|
const e = {
|
|
230560
230561
|
errors: [],
|
|
230561
230562
|
override: c
|
|
@@ -230580,6 +230581,7 @@ class e6i extends Wn {
|
|
|
230580
230581
|
(a) => a.id === CF.inputs.values.id
|
|
230581
230582
|
);
|
|
230582
230583
|
n && (n._codeNativeValueValidation = (a, c) => {
|
|
230584
|
+
console.log("Values input custom validator");
|
|
230583
230585
|
const e = {
|
|
230584
230586
|
errors: [],
|
|
230585
230587
|
override: c
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@elyx-code/project-logic-tree",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.7118",
|
|
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",
|