@elyx-code/project-logic-tree 0.0.6729 → 0.0.6730

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -384,7 +384,7 @@ ${AA}`})),{errors:n,modifiedData:i}}onProjectInitialized(i,n=this.project.addCha
384
384
  You can inspect the existing 'entity' field with the 'describe_entity' action. Like so:
385
385
  ${Io({describe_entity:v.entity.id})}
386
386
  Alternatively you can update the parent data-type entity with 'update' action to remove the existing value of the field.`}))}return{errors:c,modifiedData:s}}get interactive(){return this.implements.length?this.implements.every(i=>i.interactive):!0}get allMethods(){return D([...this.ownDeclaredMethods,...this.allBaseMethodsFromOriginalParents])}get allProperties(){return D([...this.ownDeclaredProperties,...this.allBasePropertiesFromOriginalParents])}get allBaseMethodsFromOriginalParents(){var s;const i=((s=this.extends)==null?void 0:s.type)===d.DefinitionEntity?this.extends.allMethods:[],n=[...i].filter(c=>!i.some(e=>{var y,m;return e.id!==c.id&&(((y=e.implements)==null?void 0:y.id)===c.id||((m=e.extends)==null?void 0:m.id)===c.id)}));return D([...n,...this.implements.flatMap(c=>{const e=c.type===d.DefinitionEntity?[...c.allMethods]:[];return[...e].filter(m=>!e.some(v=>{var E,b;return v.id!==m.id&&(((E=v.implements)==null?void 0:E.id)===m.id||((b=v.extends)==null?void 0:b.id)===m.id)}))})])}get allBasePropertiesFromOriginalParents(){var c;const i=((c=this.extends)==null?void 0:c.allProperties)||[],n=[...i].filter(e=>!i.some(y=>{var m;return y.id!==e.id&&(!!y.implements.find(v=>v.id===e.id)||((m=y.extends)==null?void 0:m.id)===e.id)}));return D([...n,...this.implements.flatMap(e=>{const y=[...e.allProperties];return[...y].filter(v=>!y.some(E=>{var b;return E.id!==v.id&&(!!E.implements.find(w=>w.id===v.id)||((b=E.extends)==null?void 0:b.id)===v.id)}))})])}get allBasePropertiesFromExtendedAndImplementedEntities(){var c,e;const i=[...((c=this.extends)==null?void 0:c.ownDeclaredProperties)||[],...((e=this.extends)==null?void 0:e.allBasePropertiesFromExtendedAndImplementedEntities)||[]].filter(y=>!y.abstract),n=[...i].filter(y=>!i.some(m=>{var v;return m.id!==y.id&&(!!m.implements.find(E=>E.id===y.id)||((v=m.extends)==null?void 0:v.id)===y.id)})),s=this.implements.reduce((y,m)=>{const v=m.implementedPropertiesFromOriginalParents,E=[...m.ownDeclaredProperties].filter(P=>!P.abstract),b=[...v,...E,...y];return[...b].filter(P=>!!!b.find(L=>{var j;return!!L.implements.find(F=>F.id===P.id)||((j=L.extends)==null?void 0:j.id)===P.id}))},[]);return D([...n,...s])}get allBaseMethodsFromExtendedAndImplementedEntities(){return D([...(this.extends?[this.extends]:[]).reduce((i,n)=>n.type!==d.DefinitionEntity?[]:[...[...n.ownDeclaredMethods,...n.allBaseMethodsFromExtendedAndImplementedEntities].filter(c=>c.type!==d.ActionDescriptor),...i],[]),...this.implements.reduce((i,n)=>n.type!==d.DefinitionEntity?n.abstractMethods:[...[...n.ownDeclaredMethods,...n.allBaseMethodsFromExtendedAndImplementedEntities].filter(c=>c.type!==d.ActionDescriptor),...i],[])])}get extendedPropertiesFromOriginalParents(){var s,c;const i=[...((s=this.extends)==null?void 0:s.ownDeclaredProperties)||[],...((c=this.extends)==null?void 0:c.extendedPropertiesFromOriginalParents)||[]].filter(e=>!e.abstract),n=[...i].filter(e=>!i.some(y=>{var m;return y.id!==e.id&&(!!y.implements.find(v=>v.id===e.id)||((m=y.extends)==null?void 0:m.id)===e.id)}));return D(n)}get implementedPropertiesFromOriginalParents(){return D([...(this.extends?[this.extends]:[]).reduce((i,n)=>{const s=n.implementedPropertiesFromOriginalParents,c=[...n.ownDeclaredProperties].filter(m=>!!m.abstract),e=[...s,...c,...i];return[...e].filter(m=>!!!e.find(E=>{var b;return((b=E.extends)==null?void 0:b.id)===m.id||!!E.implements.find(w=>w.id===m.id)}))},[]),...this.implements.reduce((i,n)=>{const s=n.implementedPropertiesFromOriginalParents,c=[...n.ownDeclaredProperties].filter(m=>!!m.abstract),e=[...s,...c,...i];return[...e].filter(m=>!!!e.find(E=>{var b;return!!E.implements.find(w=>w.id===m.id)||((b=E.extends)==null?void 0:b.id)===m.id}))},[])].filter(i=>!!i.abstract))}get extendedMethodsFromOriginalParents(){return D((this.extends?[this.extends]:[]).reduce((i,n)=>{if(n.type!==d.DefinitionEntity)return[];const s=[...n.ownDeclaredMethods,...n.extendedMethodsFromOriginalParents].filter(c=>c.type!==d.ActionDescriptor);return[...i,...s]},[]))}get implementedMethodsFromOriginalParents(){return D([...(this.extends?[this.extends]:[]).reduce((i,n)=>{const s=n.type===d.DefinitionEntity?n.methods:[],c=[...n.abstractMethods].filter(e=>!s.find(y=>y.name===e.name));return[...s,...c,...i]},[]),...this.implements.reduce((i,n)=>[...n.abstractMethods,...i],[])].filter(i=>i.type===d.ActionDescriptor))}get extendedProperties(){return this.properties.filter(i=>i.isExtendedProperty)}get ownDeclaredProperties(){return this.properties.filter(n=>!n.isExtendedProperty)}get extendedMethods(){return this.methods.filter(i=>i.isExtendedMethod)}get ownDeclaredMethods(){return this.methods.filter(i=>!i.isExtendedMethod)}validateGeneratedUpdate(i){const n=[];return i.parent&&n.push(new De({id:`${this.id}--${ae.InvalidParentUpdate}`,code:ae.InvalidParentUpdate,severity:fe.Error,message:`Entity of type '${this.type}' with id '${this.id}' cannot have the 'parent' property updated. The 'parent' on an '${this.type}', must be the root project as it is a globally declared entity.`})),{errors:n,modifiedData:i}}subscribeDependents(i){return i.forEach(n=>{this.detachedDependents[n.entity.id]||(this.detachedDependents[n.entity.id]=n)}),this}unsubscribeDependents(i){return i.forEach(n=>{this.detachedDependents[n.entity.id]&&delete this.detachedDependents[n.entity.id]}),this}syncDependents(i=this.project.addChangeSet(new Z(this.project,x.sessionAuthor,M().toISOString(),this,!0,"sync-dependents"))){const n=[],s=[],c=[],e=[];return Object.values(this.detachedDependents).forEach(y=>{const m=y.entity.afterAllChildrenInitialized(i);n.push(...m.updated),s.push(...m.added),c.push(...m.removed),e.push(...m.affected)}),i==null||i.attemptAutoclose("sync-dependents",this.id),{updated:D(n),added:D(s),removed:D(c),affected:D(e),self:this}}onDetachedDependencyRemoved(i,n,s){const c=[],e=[],y=[],m=[];return n==="implements"&&(this.removeImplementation(i,s),c.push(this)),n==="extends"&&(this.setExtension(null,s),c.push(this)),{updated:D(c),added:D(e),removed:D(y),affected:D(m),self:this}}onDetachedDependencyRestored(i,n,s){const c=[],e=[],y=[],m=[];return n==="implements"&&(this.addImplementation(i,s),c.push(this)),n==="extends"&&(this.setExtension(i,s),c.push(this)),{updated:D(c),added:D(e),removed:D(y),affected:D(m),self:this}}unsubscribeFromDependencies(){return this.implements.forEach(i=>{Hn.includes(i.type)||i.unsubscribeDependents([{entity:this,field:"implements"}])}),this.extends&&(Hn.includes(this.extends.type)||this.extends.unsubscribeDependents([{entity:this,field:"extends"}])),this}subscribeToDependencies(){return this.implements.forEach(i=>{Hn.includes(i.type)||i.subscribeDependents([{entity:this,field:"implements"}])}),this.extends&&(Hn.includes(this.extends.type)||this.extends.subscribeDependents([{entity:this,field:"extends"}])),this}increaseVersion(i){if(i&&!M(i).isValid())throw new Error(`The shared timestamp '${i}' is not a valid ISO 8601 date string.`);return i&&M(i).isSame(M(this.createdAt))?this:(this.previousVersion=this.version,this.version=x.UUID.uuid(),this.createdAt=M(i).toISOString()||M().toISOString(),this)}captureVersion(){var n;const i=((n=this.knownVersions)==null?void 0:n.get(this.version))||new gi(this,this.project);return i.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,i):new Map([[this.version,i]]),i.properties=[...this.properties],i.methods=[...this.methods],i.abstractMethods=[...this.abstractMethods],i.extends=this.extends,i.implements=[...this.implements],i.allPropertiesImplement=this.allPropertiesImplement,i.additionalPropertiesDataType=this.additionalPropertiesDataType,i.parent=this.parent,this}recursiveCaptureUpstreamVersions(i){const n=[],s=[],c=[],e=[];if(this.parent){this.parent.increaseVersion(i);const y=this.parent.recursiveCaptureUpstreamVersions(i);n.push(this.parent,...y.updated),s.push(...y.added),c.push(...y.removed)}return{updated:D(n),added:D(s),removed:D(c),affected:D(e),self:this}}async restoreVersion(i){var m;const n=[],s=[],c=[],e=[];if(this.version===i)return{updated:D(n),added:D(s),removed:D(c),affected:D(e),self:this};if(!this.knownVersions){const v=new Map;for(const[E,b]of this.knownVersions||new Map){if(v.set(E,b),b.activeVersion=!1,b.knownVersions)for(const[w,P]of b.knownVersions)v.set(w,P);b.knownVersions=null}}let y=(m=this.knownVersions)==null?void 0:m.get(i);if(!y){const v=await this.APILoadVersion({},i);if(!v)throw new Error(`Version with id '${i}' for entity with id '${this.id}' not found.`);y=new gi(v,this.project)}return this.metaSync(y.toShallowJSON(),null),this.previousVersion=y.previousVersion,this.version=y.version,this.createdAt=y.createdAt,this.author=y.author,this.deleted=y.deleted,this.properties=[...y.properties],this.methods=[...y.methods],this.abstractMethods=[...y.abstractMethods],this.extends=y.extends,this.implements=[...y.implements],this.allPropertiesImplement=y.allPropertiesImplement,this.additionalPropertiesDataType=y.additionalPropertiesDataType,this.parent=y.parent,{updated:D(n),added:D(s),removed:D(c),affected:D(e),self:this}}updateWithShallowTransfer(i,n=this.project.addChangeSet(new Z(this.project,x.sessionAuthor,M().toISOString(),this,!0,_.UpdateWithShallowTransfer))){if(!this.checkCanEdit(this,n))return J.Logger.warn(`[updateWithShallowTransfer] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),n==null||n.attemptAutoclose(_.UpdateWithShallowTransfer,this.id),this;if(this.metaSync(i,n),this.version=i.version,this.createdAt=i.createdAt,this.author=i.author,this.deleted=i.deleted,this.previousVersion=i.previousVersion,this.unsubscribeFromDependencies(),i.parent){const y=re(i.parent),m=this.project.get(y),v=this.parent;if(v&&v.id!==(m==null?void 0:m.id)&&this.removeFromParent(n),m)this.setParent(m,n),this.addSelfToProject(n);else throw n==null||n.attemptAutoclose(_.UpdateWithShallowTransfer,this.id),new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${y}' that isn't found in the project`)}else throw n==null||n.attemptAutoclose(_.UpdateWithShallowTransfer,this.id),new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(i.extends){const y=re(i.extends),m=this.project.get(y);m&&this.setExtension(m,n)}else this.setExtension(null,n);if(i.implements.forEach(y=>{const m=re(y),v=this.project.get(m);if(v)this.addImplementation(v,n);else throw new Error(`${Sr(this.type)} with id '${this.id}' has a 'implements' reference "${m}" which is missing in the project`)}),this.implements.filter(y=>{const m=re(y);return!i.implements.find(v=>re(v)===m)}).forEach(y=>{this.removeImplementation(y,n)}),i.methods.forEach(y=>{const m=re(y),v=this.project.get(m);v&&this.addMethod(v,n)}),this.methods.filter(y=>{const m=re(y);return!i.methods.find(v=>re(v)===m)}).forEach(y=>{this.removeMethod(y,n)}),i.properties.forEach(y=>{const m=re(y),v=this.project.get(m);v&&this.addProperty(v,n)}),this.properties.filter(y=>{const m=re(y);return!i.properties.find(v=>re(v)===m)}).forEach(y=>{this.removeProperty(y,n)}),i.allPropertiesImplement){const y=re(i.allPropertiesImplement),m=this.project.get(y);m&&this.setAllPropertiesImplement(m,n)}else this.setAllPropertiesImplement(null,n);if(i.additionalPropertiesDataType){const y=re(i.additionalPropertiesDataType),m=this.project.get(y);m&&this.setAdditionalPropertiesDataType(m,n)}else this.setAdditionalPropertiesDataType(null,n);return this.captureVersion(),this.subscribeToDependencies(),n==null||n.attemptAutoclose(_.UpdateWithShallowTransfer,this.id),this}hydrateAncestors(){const i=[],n=[],s=[],c=[];if(this.initialData.parent){const e=re(this.initialData.parent),y=this.project.get(e);if(y)this.setParent(y,null),i.push(y);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${e}' that isn't found in the project`)}else throw new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(this.initialData.extends){const e=re(this.initialData.extends),y=this.project.get(e);y&&(this.setExtension(y,null),y.type!==d.BuiltInBaseEntity&&i.push(y))}return this.initialData.implements.forEach(e=>{const y=re(e),m=this.project.get(y);if(m)this.addImplementation(m,null),m.type!==d.BuiltInBaseEntity&&i.push(m);else throw new Error(`${Sr(this.type)} with id '${this.id}' has a 'implements' reference "${y}" which is missing in the project`)}),{updated:D(i),added:D(n),removed:D(s),affected:D(c),self:this}}afterAllChildrenInitialized(i=this.project.addChangeSet(new Z(this.project,x.sessionAuthor,M().toISOString(),this,!0,_.AfterAllChildrenInitialized))){if(!this.checkCanEdit(this,i))return J.Logger.warn(`[afterAllChildrenInitialized] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(_.AfterAllChildrenInitialized,this.id),{updated:[],added:[],removed:[],affected:[],self:this};const n=[],s=[],c=[],e=[];this.initialized=!0;const{updated:y,added:m,removed:v,affected:E}=this.syncImplementationProperties(i);n.push(...y),s.push(...m),c.push(...v),e.push(...E);const{updated:b,added:w,removed:P,affected:$}=this.addExtendedProperties(i);n.push(...b),s.push(...w),c.push(...P),e.push(...$);const{updated:L,added:j,removed:F}=this.removeUnrecognizedProperties(i);n.push(...L),s.push(...j),c.push(...F);const{updated:q,added:X,removed:ne,affected:ee}=this.syncImplementationMethods(i);n.push(...q),s.push(...X),c.push(...ne),e.push(...ee);const{updated:pe,added:oe,removed:ce,affected:Te}=this.addExtendedMethods(i);n.push(...pe),s.push(...oe),c.push(...ce),e.push(...Te);const{updated:de,added:ye,removed:_e}=this.removeUnrecognizedMethods(i);return n.push(...de),s.push(...ye),c.push(..._e),this.addSuggestions(),this.properties.sort((Pe,Ge)=>Pe.index-Ge.index),this.captureVersion(),i==null||i.attemptAutoclose(_.AfterAllChildrenInitialized,this.id),{updated:D(n),added:D(s),removed:D(c),affected:D(e),self:this}}addSelfToProject(i=this.project.addChangeSet(new Z(this.project,x.sessionAuthor,M().toISOString(),this,!0,"add-self-to-project"))){const n=[this],s=[],c=[],e=[];if(this.parent.type===d.DataType){const y=this.parent;y.entity=this,n.push(y)}else this.project.addDefinitionEntity(this);return this.subscribe(),this.subscribeToDependencies(),i==null||i.attemptAutoclose("add-self-to-project",this.id),{updated:D(n),added:D(s),removed:D(c),affected:D(e),self:this}}setParent(i,n=this.project.addChangeSet(new Z(this.project,x.sessionAuthor,M().toISOString(),this,!0,_.SetParent))){var s;return this.checkCanEditWithCounterpartAndSideEffects(this,i,_.SetParent,n)?(((s=this.parent)==null?void 0:s.id)!==(i==null?void 0:i.id)&&(this.parent=i,n&&(n==null||n.add(this,H.Updated))),n==null||n.attemptAutoclose(_.SetParent,this.id),this):this}setExtension(i,n=this.project.addChangeSet(new Z(this.project,x.sessionAuthor,M().toISOString(),this,!0,_.SetExtension))){var s;return this.checkCanEdit(this,n)?(((s=this.extends)==null?void 0:s.id)!==(i==null?void 0:i.id)&&(this.extends=i,this.subscribeToDependencies(),n&&(n==null||n.add(this,H.Updated))),n==null||n.attemptAutoclose(_.SetExtension,this.id),this):(J.Logger.warn(`[setExtension] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),n==null||n.attemptAutoclose(_.SetExtension,this.id),this)}addImplementation(i,n=this.project.addChangeSet(new Z(this.project,x.sessionAuthor,M().toISOString(),this,!0,_.AddImplementation))){return this.checkCanEdit(this,n)?(this.implements.includes(i)||(this.implements.push(i),this.subscribeToDependencies(),n==null||n.add(this,H.Updated)),n==null||n.attemptAutoclose(_.AddImplementation,this.id),this):(J.Logger.warn(`[addImplementation] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),n==null||n.attemptAutoclose(_.AddImplementation,this.id),this)}removeImplementation(i,n=this.project.addChangeSet(new Z(this.project,x.sessionAuthor,M().toISOString(),this,!0,_.RemoveImplementation))){return this.checkCanEdit(this,n)?(this.implements.includes(i)&&(this.implements=this.implements.filter(s=>s.id!==i.id),n==null||n.add(this,H.Updated)),n==null||n.attemptAutoclose(_.RemoveImplementation,this.id),this):(J.Logger.warn(`[removeImplementation] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),n==null||n.attemptAutoclose(_.RemoveImplementation,this.id),this)}removeProperty(i,n=this.project.addChangeSet(new Z(this.project,x.sessionAuthor,M().toISOString(),this,!0,_.RemoveProperty))){return this.checkCanEdit(this,n)?(this.properties.includes(i)&&(this.properties=this.properties.filter(s=>s.id!==i.id),n==null||n.add(this,H.Updated)),n==null||n.attemptAutoclose(_.RemoveProperty,this.id),this):(J.Logger.warn(`[removeProperty] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),n==null||n.attemptAutoclose(_.RemoveProperty,this.id),this)}addMethod(i,n=this.project.addChangeSet(new Z(this.project,x.sessionAuthor,M().toISOString(),this,!0,_.AddMethod))){return this.checkCanEdit(this,n)?(this.methods.includes(i)||(this.methods.push(i),this.suggestedMethods=this.suggestedMethods.filter(s=>s.name!==i.name),n==null||n.add(this,H.Updated)),n==null||n.attemptAutoclose(_.AddMethod,this.id),this):(J.Logger.warn(`[addMethod] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),n==null||n.attemptAutoclose(_.AddMethod,this.id),this)}removeMethod(i,n=this.project.addChangeSet(new Z(this.project,x.sessionAuthor,M().toISOString(),this,!0,_.RemoveMethod))){return this.checkCanEdit(this,n)?(this.methods.includes(i)&&(this.methods=this.methods.filter(s=>s.id!==i.id),n==null||n.add(this,H.Updated)),n==null||n.attemptAutoclose(_.RemoveMethod,this.id),this):(J.Logger.warn(`[removeMethod] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),n==null||n.attemptAutoclose(_.RemoveMethod,this.id),this)}addProperty(i,n=this.project.addChangeSet(new Z(this.project,x.sessionAuthor,M().toISOString(),this,!0,_.AddProperty))){return this.checkCanEdit(this,n)?(this.properties.includes(i)||(this.properties.push(i),this.suggestedProperties=this.suggestedProperties.filter(s=>s.name!==i.name),n==null||n.add(this,H.Updated)),n==null||n.attemptAutoclose(_.AddProperty,this.id),this):(J.Logger.warn(`[addProperty] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),n==null||n.attemptAutoclose(_.AddProperty,this.id),this)}addSuggestedProperty(i){return this.suggestedProperties.includes(i)||this.suggestedProperties.push(i),this}addSuggestedMethod(i){return this.suggestedMethods.includes(i)||this.suggestedMethods.push(i),this}removeSuggestedProperty(i){return this.suggestedProperties=this.suggestedProperties.filter(n=>n.id!==i.id),this}removeSuggestedMethod(i){return this.suggestedMethods=this.suggestedMethods.filter(n=>n.id!==i.id),this}addAbstractMethod(i,n=this.project.addChangeSet(new Z(this.project,x.sessionAuthor,M().toISOString(),this,!0,_.AddAbstractMethod))){return this.checkCanEdit(this,n)?(this.abstractMethods.includes(i)||(this.abstractMethods.push(i),n==null||n.add(this,H.Updated)),n==null||n.attemptAutoclose(_.AddAbstractMethod,this.id),this):(J.Logger.warn(`[addAbstractMethod] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),n==null||n.attemptAutoclose(_.AddAbstractMethod,this.id),this)}removeAbstractMethod(i,n=this.project.addChangeSet(new Z(this.project,x.sessionAuthor,M().toISOString(),this,!0,_.RemoveAbstractMethod))){return this.checkCanEdit(this,n)?(this.abstractMethods.includes(i)&&(this.abstractMethods=this.abstractMethods.filter(s=>s.id!==i.id),n==null||n.add(this,H.Updated)),n==null||n.attemptAutoclose(_.RemoveAbstractMethod,this.id),this):(J.Logger.warn(`[removeAbstractMethod] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),n==null||n.attemptAutoclose(_.RemoveAbstractMethod,this.id),this)}initChildren(i=this.project.addChangeSet(new Z(this.project,x.sessionAuthor,M().toISOString(),this,!0,"init-children"))){if(this.initialized||this.startedInitialization)return this;if(this.startedInitialization=!0,this.properties=this.initialData.properties.map(n=>{const s=he(n,this.project);return s.setParent(this,null),s.initChildren(i),s}),this.methods=this.initialData.methods.map(n=>{const s=he(n,this.project);return s.setParent(this,null),s.initChildren(i),s}),this.abstractMethods=this.initialData.abstractMethods.map(n=>{const s=he(n,this.project);return s.setParent(this,null),s.initChildren(i),s}),this.initialData.extends&&(this.extends=he(this.initialData.extends,this.project)),this.implements=this.initialData.implements.map(n=>he(n,this.project)),this.initialData.allPropertiesImplement){const n=he(this.initialData.allPropertiesImplement,this.project);n.setParent(this,null),n.initChildren(null),this.setAllPropertiesImplement(n,i)}if(this.initialData.additionalPropertiesDataType){const n=he(this.initialData.additionalPropertiesDataType,this.project);n.setParent(this,null),n.initChildren(null),this.setAdditionalPropertiesDataType(n,i)}return this.subscribeToDependencies(),this.afterAllChildrenInitialized(i),i==null||i.attemptAutoclose("init-children",this.id),this}removeUnrecognizedProperties(i=this.project.addChangeSet(new Z(this.project,x.sessionAuthor,M().toISOString(),this,!0,"remove-unrecognized-properties"))){const n=[],s=[],c=[],e=[];let y=[...this.properties];y=y.filter(b=>b.parent.id===this.id),y=y.filter(b=>!b.isExtendedProperty);const m=this.implementedPropertiesFromOriginalParents,v=this.getAllPropertiesImplements();return y.filter(b=>this.interactive&&!b.implements.length?!1:!b.implements.find(P=>!!m.find($=>$.id===P.id)||!!v.find($=>$.id===P.id))).forEach(b=>{const w=b.remove({ignoreUpstream:!1},i);c.push(...w.removed),n.push(...w.updated)}),i==null||i.attemptAutoclose("remove-unrecognized-properties",this.id),{updated:D(n),added:D(s),removed:D(c),affected:D(e),self:this}}removeUnrecognizedMethods(i=this.project.addChangeSet(new Z(this.project,x.sessionAuthor,M().toISOString(),this,!0,"remove-unrecognized-methods"))){const n=[],s=[],c=[],e=[];let y=[...this.methods];y=y.filter(v=>v.parent.id===this.id),y=y.filter(v=>!v.isExtendedMethod);const m=this.implementedMethodsFromOriginalParents;return y=y.filter(v=>this.interactive&&!v.implements?!1:!m.find(E=>{var b;return E.id===((b=v.implements)==null?void 0:b.id)})),y.forEach(v=>{const E=v.remove({ignoreUpstream:!1},i);c.push(...E.removed),n.push(...E.updated)}),i==null||i.attemptAutoclose("remove-unrecognized-methods",this.id),{updated:D(n),added:D(s),removed:D(c),affected:D(e),self:this}}syncImplementationMethods(i=this.project.addChangeSet(new Z(this.project,x.sessionAuthor,M().toISOString(),this,!0,"sync-implementation-methods"))){const n=[],s=[],c=[],e=[],y=this.methods,m=this.implementedMethodsFromOriginalParents,v=[...this.allBaseMethodsFromExtendedAndImplementedEntities,...y];return m.filter(b=>!v.find(P=>{var $;return(($=P.implements)==null?void 0:$.id)===b.id})).forEach(b=>{if(this.methods.find(L=>{var j;return((j=L.implements)==null?void 0:j.id)===b.id}))return;const P=this.methods.find(L=>{var ne,ee;if(L.name===b.name&&!L.implements)return!0;const j=Zi(this,Re.CRON_JOB),F=Zi(this,Re.HTTP_ENDPOINT),q=((ne=L.implements)==null?void 0:ne.id)===Q["built-in-base-entity"].BUILT_IN_HTTP_ENDPOINT_ENTITY.methods.handler.id,X=((ee=L.implements)==null?void 0:ee.id)===Q["built-in-base-entity"].BUILT_IN_CRON_JOB_ENTITY.methods.handler.id;return!!(j&&!X&&!F&&q||F&&!q&&!j&&X)});if(P&&P.type===d.FunctionDeclaration){P.setImplements(b,i),P.metaSync({name:b.name},i),i==null||i.add(P,H.Updated),i==null||i.add(this,H.Updated);return}const $=b.implementAsFunctionDeclaration(i,this);s.push($),i==null||i.add($,H.Added),this.addMethod($,i)}),this.methods.sort((b,w)=>b.index-w.index).forEach(b=>{b.afterAllChildrenInitialized(i)}),i==null||i.attemptAutoclose("sync-implementation-methods",this.id),{updated:D(n),added:D(s),removed:D(c),affected:D(e),self:this}}syncImplementationProperties(i=this.project.addChangeSet(new Z(this.project,x.sessionAuthor,M().toISOString(),this,!0,"sync-implementation-properties"))){const n=[],s=[],c=[],e=[],y=this.properties,m=this.implementedPropertiesFromOriginalParents.filter(E=>!this.allBasePropertiesFromExtendedAndImplementedEntities.find(w=>!!w.implements.find(P=>P.id===E.id))),v=[...this.allBasePropertiesFromExtendedAndImplementedEntities,...y];return m.forEach(E=>{const b=v.find(L=>!!L.implements.find(j=>j.id===E.id));if(b){const{updated:L,added:j,removed:F,affected:q}=b.syncWithImplementation(i);n.push(...L),s.push(...j),c.push(...F),e.push(...q);return}if(this.properties.find(L=>!!L.implements.find(j=>j.id===E.id)))return;const P=this.properties.find(L=>L.name===E.name&&!!L.abstract&&!L.implements);if(P){P.addImplementation(E,i),P.metaSync({abstract:!1},i),P.afterAllChildrenInitialized(i);return}const $=E.implement(this,i,x.UUID.uuid());s.push($),i==null||i.add($,H.Added)}),this.properties.find(E=>{var b;return E.id===((b=this.allPropertiesImplement)==null?void 0:b.id)})&&this.removeAllPropertiesImplement(i),i==null||i.attemptAutoclose("sync-implementation-properties",this.id),{updated:D(n),added:D(s),removed:D(c),affected:D(e),self:this}}addExtendedMethods(i=this.project.addChangeSet(new Z(this.project,x.sessionAuthor,M().toISOString(),this,!0,"add-extended-methods"))){const n=[],s=[],c=[],e=[],y=this.methods,v=this.extendedMethodsFromOriginalParents.filter(b=>b.type===d.FunctionDeclaration),E=new Set(y.filter(b=>{var w;return!!((w=b.extends)!=null&&w.id)}).map(b=>b.extends.id));return v.forEach(b=>{if(E.has(b.id))return;E.add(b.id);const w=b.clone(i,this,x.UUID.uuid());w.setExtends(b,i),w.initChildren(i),s.push(w),i==null||i.add(w,H.Added),this.addMethod(w,i)}),i==null||i.attemptAutoclose("add-extended-methods",this.id),{updated:D(n),added:D(s),removed:D(c),affected:D(e),self:this}}addExtendedProperties(i=this.project.addChangeSet(new Z(this.project,x.sessionAuthor,M().toISOString(),this,!0,"add-extended-properties"))){const n=[],s=[],c=[],e=[],y=this.properties,m=this.extendedPropertiesFromOriginalParents,v=m.filter(b=>m.find(P=>!!P.implements.find($=>$.id===b.id))?!1:!b.abstract),E=new Set(y.filter(b=>{var w;return!!((w=b.extends)!=null&&w.id)}).map(b=>b.extends.id));return v.forEach(b=>{if(E.has(b.id))return;E.add(b.id);const w=b.clone(i,this,x.UUID.uuid());w.setExtends(b,i),w.initChildren(i),s.push(w),i==null||i.add(w,H.Added),this.addProperty(w,i)}),[...this.properties].forEach(b=>{if(b.extends)return;if(v.find(P=>P.name===b.name&&P.implements.every($=>!!b.implements.find(L=>L.id===$.id)))){const P=b.remove({ignoreUpstream:!1},i);c.push(...P.removed),n.push(...P.updated)}}),this.properties.forEach(b=>{const w=b.afterAllChildrenInitialized(i);n.push(...w.updated),e.push(...w.affected),s.push(...w.added),c.push(...w.removed)}),i==null||i.attemptAutoclose("add-extended-properties",this.id),{updated:D(n),added:D(s),removed:D(c),affected:D(e),self:this}}addSuggestions(){return this.implements.forEach(i=>{HBe(this,i).forEach(c=>{const e=c.toJSON();e.id=`_suggestion--parent--${this.id}--${c.id}`;const y=he(e,this.project);y.suggestion=!0,y.setParent(this,null),y.initChildren(null),this.addSuggestedProperty(y)}),WBe(this,i).forEach(c=>{const e=`_suggestion--parent--${this.id}--${c.id}`,y=c.implementAsFunctionDeclaration(null,this,e),m=he(y,this.project);if(m.suggestion=!0,m.setParent(this,null),m.initChildren(null),this.methods=this.methods.filter(v=>v.id!==e),m.inputs.forEach(v=>{v.suggestion=!0}),m.returnStatements.length){const v=m.returnStatements[0];v.suggestion=!0,v.outputs.forEach(E=>{E.suggestion=!0})}this.addSuggestedMethod(m)})}),this}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(i,n=this.project.addChangeSet(new Z(this.project,x.sessionAuthor,M().toISOString(),this,!0,"meta-sync"))){const s=Mr(this,i,n),c=Lr(this,s),e=this.toMeta();return this.name=s.name!==void 0?s.name:e.name,this.codeName=s.codeName!==void 0?s.codeName:e.codeName,this.description=s.description!==void 0?s.description:e.description,this.x=s.x||e.x,this.y=s.y||e.y,this.static=s.static!==void 0?s.static:this.static,this.abstract=s.abstract!==void 0?s.abstract:this.abstract,this.additionalProperties=s.additionalProperties!==void 0?s.additionalProperties:e.additionalProperties,super.baseMetaSync(s,this,n),s.deleted===!0&&!e.deleted?n==null||n.add(this,H.Removed):s.deleted===!1&&e.deleted?n==null||n.add(this,H.Added):c&&(n==null||n.add(this,H.Updated)),n==null||n.attemptAutoclose("meta-sync",this.id),this}async APILoad(i=ke,...n){return await gi.repository.APILoad(this.id,...n),this}async APICreate(i=ke,...n){return await gi.repository.APICreate(this.toShallowJSON(),...n),this}async APIUpdate(i=ke,...n){return await gi.repository.APIUpdate(this.toShallowJSON(),...n),this}async APIDelete(i=ke,...n){return await gi.repository.APIDelete(this.toShallowJSON(),...n),this}async APIClone(i=ke,...n){return await gi.repository.APIClone(this.id,...n),this}async APILoadVersion(i=ke,n,...s){return await gi.repository.APILoadVersion(this.id,n,...s)}removeFromParent(i=this.project.addChangeSet(new Z(this.project,x.sessionAuthor,M().toISOString(),this,!0,_.RemoveFromParent))){if(!this.checkCanEdit(this,i))return J.Logger.warn(`[removeFromParent] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(_.RemoveFromParent,this.id),{added:[],updated:[],removed:[],affected:[],self:this};const n=[],s=[],c=[],e=[];if(this.parent.type===d.Project)this.parent.removeDefinitionEntity(this);else if(this.parent.type===d.DataType&&this.parent.entity&&this.parent.entity.id===this.id){const y=this.parent.setEntity(null,i);n.push(y)}return i==null||i.attemptAutoclose(_.RemoveFromParent,this.id),{added:D(c),updated:D(n),removed:D(s),affected:D(e),self:this}}remove({ignoreUpstream:i}={ignoreUpstream:!1},n=this.project.addChangeSet(new Z(this.project,x.sessionAuthor,M().toISOString(),this,!0,_.RemoveEntity))){var m;if(!this.checkCanDelete(this,n))return J.Logger.warn(`[remove] User is not allowed to delete or edit this ${this.type} entity with id: ${this.id}`),n==null||n.event({id:`${_.RemoveEntity}-${this.id}`,action:_.RemoveEntity,owner:this,errorReason:rr.ActionOwnerEntityNonDeletable,rootAction:((m=n==null?void 0:n.self)==null?void 0:m.id)===this.id&&(n==null?void 0:n.autoCloseActionName)===_.RemoveEntity}),n==null||n.attemptAutoclose(_.RemoveEntity,this.id),{added:[],updated:[],removed:[],affected:[],self:this};const s=[],c=[],e=[],y=[];if(n!=null&&n.hasRemoved(this.id))return n==null||n.attemptAutoclose(_.RemoveEntity,this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(c.push(this),this.unsubscribe(),this.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},n),Object.values(this.detachedDependents).forEach(v=>{const{updated:E,removed:b,added:w}=v.entity.onDetachedDependencyRemoved(this,v.field,n);s.push(...E),c.push(...b),e.push(...w)}),this.properties.forEach(v=>{const{updated:E,removed:b}=v.remove({ignoreUpstream:!0},n);s.push(...E),c.push(...b)}),this.methods.forEach(v=>{const{updated:E,removed:b}=v.remove({ignoreUpstream:!0},n);s.push(...E),c.push(...b)}),this.abstractMethods.forEach(v=>{const{updated:E,removed:b}=v.remove({ignoreUpstream:!0},n);s.push(...E),c.push(...b)}),this.suggestedProperties.forEach(v=>{const{updated:E,removed:b}=v.remove({ignoreUpstream:!0},n);s.push(...E),c.push(...b)}),this.suggestedMethods.forEach(v=>{const{updated:E,removed:b}=v.remove({ignoreUpstream:!0},n);s.push(...E),c.push(...b)}),!i){const v=this.removeFromParent(n);e.push(...v.added),s.push(...v.updated),c.push(...v.removed),y.push(...v.affected)}return n==null||n.attemptAutoclose(_.RemoveEntity,this.id),{added:D(e),updated:D(s),removed:D(c),affected:D(y),self:this}}restore({}={},i=this.project.addChangeSet(new Z(this.project,x.sessionAuthor,M().toISOString(),this,!0,_.RestoreEntity))){if(!this.checkCanEdit(this,i))return J.Logger.warn(`[restore] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(_.RestoreEntity,this.id),{added:[],updated:[],removed:[],affected:[],self:this};const n=[],s=[],c=[],e=[];return i!=null&&i.hasAdded(this.id)?(i==null||i.attemptAutoclose(_.RestoreEntity,this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},i),Object.values(this.detachedDependents).forEach(y=>{const{updated:m,removed:v,added:E}=y.entity.onDetachedDependencyRestored(this,y.field,i);s.push(...m),c.push(...v),n.push(...E)}),this.properties.forEach(y=>{const{updated:m}=y.restore({},i);s.push(...m)}),this.methods.forEach(y=>{const{updated:m}=y.restore({},i);s.push(...m)}),this.abstractMethods.forEach(y=>{const{updated:m}=y.restore({},i);s.push(...m)}),this.suggestedProperties.forEach(y=>{const{updated:m}=y.restore({},i);s.push(...m)}),this.suggestedMethods.forEach(y=>{const{updated:m}=y.restore({},i);s.push(...m)}),i==null||i.attemptAutoclose(_.RestoreEntity,this.id),{added:D(n),updated:D(s),removed:D(c),affected:D(e),self:this})}toFlat(i=new Set){var s;return i.has(this.id)?[]:(i.add(this.id),[this,...((s=this.extends)==null?void 0:s.toFlat(i))||[],...this.implements.flatMap(c=>c.toFlat(i)),...this.properties.flatMap(c=>c.toFlat(i)),...this.methods.flatMap(c=>c.toFlat(i)),...this.abstractMethods.flatMap(c=>c.toFlat(i)),...this.parent.toFlat(i)])}toFlatIds(i=new Set){var s;return i.has(this.id)?[]:(i.add(this.id),[this.id,...((s=this.extends)==null?void 0:s.toFlatIds(i))||[],...this.implements.flatMap(c=>c.toFlatIds(i)),...this.properties.flatMap(c=>c.toFlatIds(i)),...this.methods.flatMap(c=>c.toFlatIds(i)),...this.abstractMethods.flatMap(c=>c.toFlatIds(i)),...this.parent.toFlatIds(i)])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,codeName:this.codeName,description:this.description,static:this.static,abstract:this.abstract,x:this.x,y:this.y,type:this.type,editable:this.editable,deletable:this.deletable,additionalProperties:this.additionalProperties,name:this.name}}toJSON(i=new Set){var n,s,c;return i.has(this.id)?this.toReference():(i.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,editable:this.editable,deletable:this.deletable,name:this.name,codeName:this.codeName,description:this.description,x:this.x,y:this.y,static:this.static,abstract:this.abstract,additionalProperties:this.additionalProperties,allPropertiesImplement:((n=this.allPropertiesImplement)==null?void 0:n.toJSON(i))||null,additionalPropertiesDataType:((s=this.additionalPropertiesDataType)==null?void 0:s.toJSON(i))||null,properties:this.properties.map(e=>e.toJSON(i)),methods:this.methods.map(e=>e.toJSON(i)),abstractMethods:this.abstractMethods.map(e=>e.toJSON(i)),implements:this.implements.map(e=>e.toJSON(i)),extends:((c=this.extends)==null?void 0:c.toJSON(i))||null,parent:this.parent.toReference()})}toJSONClone(i=ct){var s,c,e,y,m,v,E,b,w,P;let n;return(s=i.seenEntityMaps)!=null&&s.has(this.id)?n=i.seenEntityMaps.get(this.id):(n=i.newId||jr(this,this.project,i.uuidStrategy),i.seenEntityMaps&&i.seenEntityMaps.set(this.id,n)),(c=i.seenEntities)!=null&&c.has(n)||(e=i.seenEntities)!=null&&e.has(this.id)?this.toReference({seenEntityMaps:i.seenEntityMaps}):((y=i.seenEntities)==null||y.add(n),(m=i.seenEntities)==null||m.add(this.id),{id:n,version:x.UUID.uuid(),createdAt:i.timestamp||M().toISOString(),author:x.sessionAuthor,previousVersion:null,deleted:!1,type:this.type,editable:this.editable,deletable:this.deletable,name:this.name,codeName:this.codeName,description:this.description,x:this.x,y:this.y,static:this.static,abstract:this.abstract,additionalProperties:this.additionalProperties,allPropertiesImplement:((v=this.allPropertiesImplement)==null?void 0:v.toJSONClone(i))||null,additionalPropertiesDataType:((E=this.additionalPropertiesDataType)==null?void 0:E.toJSONClone(i))||null,properties:this.properties.map($=>$.toJSONClone({...i,newId:null})),methods:this.methods.map($=>$.toJSONClone({...i,newId:null})),abstractMethods:this.abstractMethods.map($=>$.toJSONClone({...i,newId:null})),implements:this.implements.map($=>$.type===d.BuiltInBaseEntity?$.toJSON(i.seenEntities):$.toJSONClone({...i,newId:null})),extends:((b=this.extends)==null?void 0:b.type)===d.BuiltInBaseEntity?(w=this.extends)==null?void 0:w.toJSON(i.seenEntities):(P=this.extends)==null?void 0:P.toJSONClone({...i,newId:null}),parent:this.parent.toReference({seenEntityMaps:i.seenEntityMaps})})}toReference(i=ct){var s;let n=this.id;return(s=i.seenEntityMaps)!=null&&s.has(this.id)&&(n=i.seenEntityMaps.get(this.id)),{id:n+"--"+x.UUID.uuid()+"--ref",type:d.GenericReference,entityId:n,version:this.version,entityType:this.type}}toShallowJSON(i=ct){var s,c,e,y;let n=this.id;return(s=i.seenEntityMaps)!=null&&s.has(this.id)&&(n=i.seenEntityMaps.get(this.id)),{id:n,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,name:this.name,codeName:this.codeName,description:this.description,type:this.type,editable:this.editable,deletable:this.deletable,x:this.x,y:this.y,static:this.static,abstract:this.abstract,additionalProperties:this.additionalProperties,allPropertiesImplement:((c=this.allPropertiesImplement)==null?void 0:c.toReference(i))||null,additionalPropertiesDataType:((e=this.additionalPropertiesDataType)==null?void 0:e.toReference(i))||null,properties:this.properties.map(m=>m.toReference(i)),methods:this.methods.map(m=>m.toReference(i)),abstractMethods:this.abstractMethods.map(m=>m.toReference(i)),implements:this.implements.map(m=>m.toReference(i)),extends:((y=this.extends)==null?void 0:y.toReference(i))||null,parent:this.parent.toReference(i)}}toFlatJSON(i=new Set){var s,c,e;return i.has(this.id)?[]:(i.add(this.id),[this.toShallowJSON(),...this.properties.flatMap(y=>y.toFlatJSON(i)),...this.methods.flatMap(y=>y.toFlatJSON(i)),...this.abstractMethods.flatMap(y=>y.toFlatJSON(i)),...this.implements.flatMap(y=>y.toFlatJSON(i)),...((s=this.extends)==null?void 0:s.toFlatJSON(i))||[],...this.parent.toFlatJSON(i),...((c=this.additionalPropertiesDataType)==null?void 0:c.toFlatJSON(i))||[],...((e=this.allPropertiesImplement)==null?void 0:e.toFlatJSON(i))||[]])}toGenerationTarget(){var n;const i=this.parent.type===d.Project?void 0:this.parent.id;return{id:this.id,name:this.name,description:this.description,type:this.type,static:this.static,abstract:this.abstract,extends:(n=this.extends)==null?void 0:n.id,additionalProperties:this.additionalProperties,implements:this.implements.map(s=>s.id),parent:i}}toFlatGenerationTarget(i=new Set){var s,c,e;return i.has(this.id)?[]:(i.add(this.id),[this.toGenerationTarget(),...this.properties.flatMap(y=>y.toFlatGenerationTarget(i)),...this.methods.flatMap(y=>y.toFlatGenerationTarget(i)),...this.abstractMethods.flatMap(y=>y.toFlatGenerationTarget(i)),...this.implements.filter(y=>y.type===d.DefinitionEntity).flatMap(y=>y.toFlatGenerationTarget(i)),...((s=this.extends)==null?void 0:s.toFlatGenerationTarget(i))||[],...this.parent.toFlatGenerationTarget(i),...((c=this.additionalPropertiesDataType)==null?void 0:c.toFlatGenerationTarget(i))||[],...((e=this.allPropertiesImplement)==null?void 0:e.toFlatGenerationTarget(i))||[]])}clearErrors(){var i,n;return this.errors=[],this.properties.forEach(s=>s.clearErrors()),this.methods.forEach(s=>s.clearErrors()),this.abstractMethods.forEach(s=>s.clearErrors()),(i=this.additionalPropertiesDataType)==null||i.clearErrors(),(n=this.allPropertiesImplement)==null||n.clearErrors(),this}validate(){return this.errors=ZBe(this),{success:!0}}async validateAsync(i={}){const n=J.YieldTracker.from(i);return this.errors=await qBe(this,{tracker:n}),{success:!0}}getErrors(){var n,s;return[...this.errors,...this.properties.flatMap(c=>c.getErrors()),...this.methods.flatMap(c=>c.getErrors()),...this.abstractMethods.flatMap(c=>c.getErrors()),...((n=this.additionalPropertiesDataType)==null?void 0:n.getErrors())||[],...((s=this.allPropertiesImplement)==null?void 0:s.getErrors())||[]]}async getErrorsAsync(i={}){const n=J.YieldTracker.from(i),s=[...this.errors];await n.tick();for(const c of this.properties)s.push(...await c.getErrorsAsync({tracker:n}));for(const c of this.methods)s.push(...await c.getErrorsAsync({tracker:n}));for(const c of this.abstractMethods)s.push(...await c.getErrorsAsync({tracker:n}));return this.additionalPropertiesDataType&&s.push(...await this.additionalPropertiesDataType.getErrorsAsync({tracker:n})),this.allPropertiesImplement&&s.push(...await this.allPropertiesImplement.getErrorsAsync({tracker:n})),s}getShallowErrors(){return this.errors}clone(i=this.project.addChangeSet(new Z(this.project,x.sessionAuthor,M().toISOString(),this,!0,_.CloneEntity)),n=null,s=null,c=!0){var j,F,q;const e=Nr(n,this),y=this.toJSON(),m=s||x.UUID.uuid(),v=n||this.parent;y.properties=[],y.methods=[],y.abstractMethods=[];const E=m.split("-id"),b=E[E.length-1||0]||m;y.id=m,y.version=x.UUID.uuid(),y.createdAt=(i==null?void 0:i.timestamp)||M().toISOString(),y.author=(i==null?void 0:i.author)||"1",y.previousVersion=null,y.deleted=!1,y.editable=!0,y.deletable=!0,y.parent=v.toReference();const w=Ki(y,e);w.hydrateAncestors(),w.setParent(v,i),c&&(w.subscribe(),w.addSelfToProject(i)),w.initChildren(i),i==null||i.add(w,H.Added);const P=(j=this.properties)==null?void 0:j.map(X=>this.project.diggestedBuiltInBaseEntitiesIds.has(X.id)?e.getBuiltIn(X.id):X.clone(i,w,x.UUID.uuid(),c));w.properties=P;const $=(F=this.methods)==null?void 0:F.map((X,ne)=>this.project.diggestedBuiltInBaseEntitiesIds.has(X.id)?e.getBuiltIn(X.id):X.clone(i,w,b+"-method-"+ne+"-id",c));w.methods=$;const L=(q=this.abstractMethods)==null?void 0:q.map((X,ne)=>this.project.diggestedBuiltInBaseEntitiesIds.has(X.id)?e.getBuiltIn(X.id):X.clone(i,w,b+"-abstract-method-"+ne+"-id",c));if(w.abstractMethods=L,this.additionalPropertiesDataType)if(this.project.diggestedBuiltInBaseEntitiesIds.has(this.additionalPropertiesDataType.id))w.setAdditionalPropertiesDataType(this.project.getBuiltIn(this.additionalPropertiesDataType.id),i);else{const X=this.additionalPropertiesDataType.clone(i,w,x.UUID.uuid(),c);w.setAdditionalPropertiesDataType(X,i)}if(this.allPropertiesImplement)if(this.project.diggestedBuiltInBaseEntitiesIds.has(this.allPropertiesImplement.id))w.setAllPropertiesImplement(this.project.getBuiltIn(this.allPropertiesImplement.id),i);else{const X=this.allPropertiesImplement.clone(i,w,x.UUID.uuid(),c);w.setAllPropertiesImplement(X,i)}return i==null||i.attemptAutoclose(_.CloneEntity,this.id),w}getFunctionDeclaration(i){return this.methods.find(n=>n.id===i)}implement(i,n=this.project.addChangeSet(new Z(this.project,x.sessionAuthor,M().toISOString(),this,!0,"implement-definition-entity")),s){const c=UI(this,i,n,s);return n==null||n.attemptAutoclose("implement-definition-entity",this.id),c}getAllPropertiesImplements(){var n;const i=[];return this.allPropertiesImplement&&i.push(this.allPropertiesImplement),i.push(...((n=this.extends)==null?void 0:n.getAllPropertiesImplements())||[],...this.implements.flatMap(s=>s.getAllPropertiesImplements())),i}getAllInteractiveMethods(){var e;const i=this.implements.filter(y=>y.type===d.DefinitionEntity||y.type===d.BuiltInBaseEntity&&y.interactive),n=((e=this.extends)==null?void 0:e.getAllInteractiveMethods())||[],s=i.flatMap(y=>y.getAllInteractiveMethods());return D([...this.methods,...n,...s])}inferFromInputs(i,n=this.project.addChangeSet(new Z(this.project,x.sessionAuthor,M().toISOString(),this,!0,"infer-definition-entity-from-inputs"))){const s=[],c=[],e=[],y=[];if(this.parent.type!==d.DataType||!this.parent.inferred)return n==null||n.attemptAutoclose("infer-definition-entity-from-inputs",this.id),{added:[],updated:[],removed:[],affected:[],self:this};const m=[];i.forEach(b=>{m.find(P=>se(P,this.project)===se(b,this.project))||m.push(b)});const v=this.properties.filter(b=>!b.dataType);m.forEach(b=>{var q,X,ne;const w=v.find(ee=>se(ee,this.project)===se(b,this.project));if(!w)return;const $=Wn(b.parent).getMasterInputWithValueWritterFromAllInstances(b),L=hd($,n),j=L==null?void 0:L.clone(n,w,x.UUID.uuid(),!0);j&&((q=w.dataType)==null||q.merge(j,n),j.id!==((X=w.dataType)==null?void 0:X.id)&&j.remove({ignoreUpstream:!1},n),w.dataType&&(w.dataType.metaSync({inferred:!0,like:!0},n),w.setDataType(w.dataType,n),n==null||n.add(w,H.Affected)));let F=null;if(b.declaration&&w.id!==((ne=b.declaration)==null?void 0:ne.id)&&(F=b.declaration),b.setDeclaration(w,n),n==null||n.add(b,H.Updated),F){const{updated:ee,removed:pe}=F.remove({ignoreUpstream:!1},n);c.push(...ee),e.push(...pe)}});const E=[];return m.forEach(b=>{if(!b.declaration){E.push(b);return}}),E.length===0?(n==null||n.attemptAutoclose("infer-definition-entity-from-inputs",this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(E.forEach(b=>{var ne,ee,pe,oe;const w=this.properties.find(ce=>se(ce,this.project)===se(b,this.project));if(w){if(b.setDeclaration(w,n),!w.getDataType(n)){const Te=Wn(b.parent).getMasterInputWithValueWritterFromAllInstances(b),de=hd(Te),ye=de==null?void 0:de.clone(n,w,x.UUID.uuid(),!0);ye&&((ne=w.dataType)==null||ne.merge(ye,n),ye.id!==((ee=w.dataType)==null?void 0:ee.id)&&ye.remove({ignoreUpstream:!1},n),w.dataType&&(w.dataType.metaSync({inferred:!0,like:!0},n),w.setDataType(w.dataType,n),n==null||n.add(w,H.Affected)))}return}const P=se(b,this.project),$=b.codeName||Ac(b,this.project)||wo(qi(P)),L=ja.new(n);L.parent=this.toReference(),L.index=b.index,L.name=P,L.codeName=$,L.description=b.description;const j=he(L,this.project);j.hydrateAncestors(),n==null||n.add(j,H.Added),j.setParent(this,n),j.initChildren(n);const q=Wn(b.parent).getMasterInputWithValueWritterFromAllInstances(b),X=hd(q);if(X)if(this.project.diggestedBuiltInBaseEntitiesIds.has(X.id))j.setDataType(X,n),n==null||n.add(j,H.Affected);else{const ce=X==null?void 0:X.clone(n,j,x.UUID.uuid(),!0);ce&&((pe=j.dataType)==null||pe.merge(ce,n),ce.id!==((oe=j.dataType)==null?void 0:oe.id)&&ce.remove({ignoreUpstream:!1},n),j.dataType&&(j.dataType.metaSync({inferred:!0,like:!0},n),j.setDataType(j.dataType,n),n==null||n.add(j,H.Affected)))}return this.addProperty(j,n),b.setDeclaration(j,n),n==null||n.add(b,H.Updated),j}),n==null||n.attemptAutoclose("infer-definition-entity-from-inputs",this.id),{added:D(s),updated:D(c),removed:D(e),affected:D(y),self:this})}getRawDefaultValue(){const i={};return this.properties.forEach(n=>{var e;if(!VA(n))return;const s=se(n,this.project),c=n.codeName||Ac(n,this.project)||wo(qi(s));i[c]=((e=n.getDefaultValue())==null?void 0:e.value)||null}),i}getActiveRawDefaultValue(){const i={};return this.properties.forEach(n=>{var y;if(!VA(n))return;const s=se(n,this.project),c=n.codeName||Ac(n,this.project)||wo(qi(s)),e=(y=this.project.requestActiveDynamicValue(n,!0))==null?void 0:y.value;i[c]=(e==null?void 0:e.value)||null}),i}setAdditionalPropertiesDataType(i,n=this.project.addChangeSet(new Z(this.project,x.sessionAuthor,M().toISOString(),this,!0,_.SetAdditionalPropertiesDataType))){if(!this.checkCanEdit(this,n))return J.Logger.warn(`[setAdditionalPropertiesDataType] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),n==null||n.attemptAutoclose(_.SetAdditionalPropertiesDataType,this.id),this;const s=this.additionalPropertiesDataType;return(s==null?void 0:s.id)!==(i==null?void 0:i.id)&&(s==null||s.remove({ignoreUpstream:!0},n),this.additionalPropertiesDataType=i,this.subscribeToDependencies(),n==null||n.add(this,H.Affected)),n==null||n.attemptAutoclose(_.SetAdditionalPropertiesDataType,this.id),this}removeAdditionalPropertiesDataType(i=this.project.addChangeSet(new Z(this.project,x.sessionAuthor,M().toISOString(),this,!0,_.RemoveAllPropertiesImplement))){return this.checkCanEdit(this,i)?(this.additionalPropertiesDataType&&(this.additionalPropertiesDataType.remove({ignoreUpstream:!0},i),i==null||i.add(this,H.Affected),this.additionalPropertiesDataType=null),i==null||i.attemptAutoclose(_.RemoveAllPropertiesImplement,this.id),this):(J.Logger.warn(`[removeAdditionalPropertiesDataType] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(_.RemoveAllPropertiesImplement,this.id),this)}setAllPropertiesImplement(i,n=this.project.addChangeSet(new Z(this.project,x.sessionAuthor,M().toISOString(),this,!0,_.SetAllPropertiesImplement))){if(!this.checkCanEdit(this,n))return J.Logger.warn(`[setAllPropertiesImplement] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),n==null||n.attemptAutoclose(_.SetAllPropertiesImplement,this.id),this;const s=this.allPropertiesImplement;return(s==null?void 0:s.id)!==(i==null?void 0:i.id)&&(s==null||s.remove({ignoreUpstream:!0},n),this.allPropertiesImplement=i,this.subscribeToDependencies(),n==null||n.add(this,H.Affected)),n==null||n.attemptAutoclose(_.SetAllPropertiesImplement,this.id),this}removeAllPropertiesImplement(i=this.project.addChangeSet(new Z(this.project,x.sessionAuthor,M().toISOString(),this,!0,_.RemoveAllPropertiesImplement))){return this.checkCanEdit(this,i)?(this.allPropertiesImplement&&(this.properties.find(n=>{var s;return n.id===((s=this.allPropertiesImplement)==null?void 0:s.id)})||this.allPropertiesImplement.remove({ignoreUpstream:!0},i),i==null||i.add(this,H.Affected),this.allPropertiesImplement=null),i==null||i.attemptAutoclose(_.RemoveAllPropertiesImplement,this.id),this):(J.Logger.warn(`[removeAllPropertiesImplement] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(_.RemoveAllPropertiesImplement,this.id),this)}};I(gi,"repository",{APICreate:async(i,...n)=>i,APIUpdate:async(i,...n)=>i,APIDelete:async(i,...n)=>i,APIClone:async(i,...n)=>{},APILoad:async(i,...n)=>null,APILoadVersion:async(i,n,...s)=>null}),I(gi,"type",d.DefinitionEntity),I(gi,"USER_MANAGED_PARENT_TYPES",[d.Project,d.DataType]),I(gi,"PARENT_TYPES",[...gi.USER_MANAGED_PARENT_TYPES]),I(gi,"MUTABLE_BASE_PROPERTIES",["name","codeName","description","static","abstract","additionalProperties"]),I(gi,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),I(gi,"BASE_PROPERTIES",[...gi.MUTABLE_BASE_PROPERTIES,...gi.INMUTABLE_BASE_PROPERTIES]),I(gi,"MUTABLE_META_PROPERTIES",[...gi.MUTABLE_BASE_PROPERTIES,"x","y"]),I(gi,"INMUTABLE_META_PROPERTIES",[...gi.INMUTABLE_BASE_PROPERTIES]),I(gi,"META_PROPERTIES",[...gi.MUTABLE_META_PROPERTIES,...gi.INMUTABLE_META_PROPERTIES]),I(gi,"MUTABLE_UPSTREAM_PROPERTIES",["extends","implements"]),I(gi,"INMUTABLE_UPSTREAM_PROPERTIES",["parent"]),I(gi,"UPSTREAM_PROPERTIES",[...gi.MUTABLE_UPSTREAM_PROPERTIES,...gi.INMUTABLE_UPSTREAM_PROPERTIES]),I(gi,"MUTABLE_DOWNSTREAM_PROPERTIES",["properties","methods","abstractMethods","allPropertiesImplement","additionalPropertiesDataType"]),I(gi,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),I(gi,"DOWNSTREAM_PROPERTIES",[...gi.MUTABLE_DOWNSTREAM_PROPERTIES,...gi.INMUTABLE_DOWNSTREAM_PROPERTIES]),I(gi,"PROPERTIES",[...gi.META_PROPERTIES,...gi.UPSTREAM_PROPERTIES,...gi.DOWNSTREAM_PROPERTIES]);let us=gi;async function r1i(o,p={}){const i=J.YieldTracker.from(p),n=[],s=Mt(o.errors,n);return await i.tick(),s}function n1i(o){const p=[];return Mt(o.errors,p)}const LA=class LA extends _V{constructor(i,n){super(i);I(this,"initialData");I(this,"id");I(this,"name");I(this,"description",null);I(this,"type",d.PrimitiveEntity);I(this,"static");I(this,"abstract");I(this,"properties",[]);I(this,"methods",[]);I(this,"abstractMethods",[]);I(this,"extends",null);I(this,"errors",[]);I(this,"project");this.initialData=i,this.project=n,this.id=i.id,this.name=i.name,this.static=i.static,this.abstract=i.abstract,this.properties=this.initialData.properties.map(s=>{const c=he(s,this.project);return c.setParent(this,null),c.initChildren(null),c}),this.methods=this.initialData.methods.map(s=>{const c=he(s,this.project);return c.parent=this,c}),this.abstractMethods=this.initialData.abstractMethods.map(s=>{const c=he(s,this.project);return c.parent=this,c}),this.initialData.extends&&(this.extends=he(this.initialData.extends,this.project))}get allMethods(){return D([...this.ownDeclaredMethods,...this.allBaseMethodsFromOriginalParents])}get allProperties(){return D([...this.ownDeclaredProperties,...this.allBasePropertiesFromOriginalParents])}get allBaseMethodsFromOriginalParents(){var s;const i=((s=this.extends)==null?void 0:s.allMethods)||[],n=[...i].filter(c=>!i.some(e=>e.id!==c.id));return D(n)}get allBasePropertiesFromOriginalParents(){var s;const i=((s=this.extends)==null?void 0:s.allProperties)||[],n=[...i].filter(c=>!i.some(e=>{var y;return e.id!==c.id&&(e.implements.find(m=>m.id===c.id)||((y=e.extends)==null?void 0:y.id)===c.id)}));return D(n)}get allBasePropertiesFromExtendedAndImplementedEntities(){var s,c;const i=[...((s=this.extends)==null?void 0:s.ownDeclaredProperties)||[],...((c=this.extends)==null?void 0:c.allBasePropertiesFromExtendedAndImplementedEntities)||[]].filter(e=>!e.abstract),n=[...i].filter(e=>!i.some(y=>{var m;return y.id!==e.id&&(y.implements.find(v=>v.id===e.id)||((m=y.extends)==null?void 0:m.id)===e.id)}));return D(n)}get extendedPropertiesFromOriginalParents(){var s,c;const i=[...((s=this.extends)==null?void 0:s.ownDeclaredProperties)||[],...((c=this.extends)==null?void 0:c.extendedPropertiesFromOriginalParents)||[]].filter(e=>!e.abstract),n=[...i].filter(e=>!i.some(y=>{var m;return y.id!==e.id&&(y.implements.find(v=>v.id===e.id)||((m=y.extends)==null?void 0:m.id)===e.id)}));return D(n)}get implementedPropertiesFromOriginalParents(){return D([...(this.extends?[this.extends]:[]).reduce((i,n)=>{const s=n.implementedPropertiesFromOriginalParents,c=[...n.ownDeclaredProperties].filter(m=>!!m.abstract),e=[...s,...c,...i];return[...e].filter(m=>!!!e.find(E=>{var b;return((b=E.extends)==null?void 0:b.id)===m.id||E.implements.find(w=>w.id===m.id)}))},[])])}get extendedProperties(){return this.properties.filter(i=>i.isExtendedProperty)}get ownDeclaredMethods(){return[...this.methods]}get ownDeclaredProperties(){return this.properties.filter(i=>!i.isExtendedProperty)}subscribe(){return this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}async APILoad(i=ke,...n){return await LA.repository.APILoad(this.id,...n),this}toFlat(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this,...this.properties.flatMap(s=>s.toFlat(i)),...this.methods.flatMap(s=>s.toFlat(i)),...this.abstractMethods.flatMap(s=>s.toFlat(i))])}toFlatIds(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.id,...this.properties.flatMap(s=>s.toFlatIds(i)),...this.methods.flatMap(s=>s.toFlatIds(i)),...this.abstractMethods.flatMap(s=>s.toFlatIds(i))])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,description:this.description,static:this.static,abstract:this.abstract,type:this.type,name:this.name}}toJSON(i=new Set){var n;return i.has(this.id)?this.toReference():(i.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,static:this.static,abstract:this.abstract,properties:this.properties.map(s=>s.toJSON(i)),methods:this.methods.map(s=>s.toJSON(i)),abstractMethods:this.abstractMethods.map(s=>s.toJSON(i)),extends:((n=this.extends)==null?void 0:n.toJSON(i))||null})}toReference(i=ct){return{id:this.id+"--"+x.UUID.uuid()+"--ref",type:d.GenericReference,entityId:this.id,version:this.version,entityType:this.type}}toShallowJSON(i=ct){var n;return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,abstract:this.abstract,static:this.static,properties:this.properties.map(s=>s.toReference()),methods:this.methods.map(s=>s.toReference()),abstractMethods:this.abstractMethods.map(s=>s.toReference()),extends:((n=this.extends)==null?void 0:n.toReference())||null}}toFlatJSON(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.toShallowJSON(),...this.properties.flatMap(s=>s.toFlatJSON(i)),...this.methods.flatMap(s=>s.toFlatJSON(i)),...this.abstractMethods.flatMap(s=>s.toFlatJSON(i))])}toGenerationTarget(){var i;return{id:this.id,type:this.type,name:this.name,description:this.description,static:this.static,abstract:this.abstract,extends:(i=this.extends)==null?void 0:i.id}}toFlatGenerationTarget(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.toGenerationTarget(),...this.properties.flatMap(s=>s.toFlatGenerationTarget(i)),...this.methods.flatMap(s=>s.toFlatGenerationTarget(i)),...this.abstractMethods.flatMap(s=>s.toFlatGenerationTarget(i))])}clearErrors(){return this.errors=[],this.properties.forEach(i=>i.clearErrors()),this.methods.forEach(i=>i.clearErrors()),this.abstractMethods.forEach(i=>i.clearErrors()),this}validate(){return this.errors=n1i(this),{success:!0}}async validateAsync(i={}){const n=J.YieldTracker.from(i);return this.errors=await r1i(this,{tracker:n}),{success:!0}}getErrors(){return[...this.errors,...this.properties.flatMap(n=>n.getErrors()),...this.methods.flatMap(n=>n.getErrors()),...this.abstractMethods.flatMap(n=>n.getErrors())]}async getErrorsAsync(i={}){const n=J.YieldTracker.from(i),s=[...this.errors];await n.tick();for(const c of this.properties){const e=await c.getErrorsAsync({tracker:n});s.push(...e)}for(const c of this.methods){const e=await c.getErrorsAsync({tracker:n});s.push(...e)}for(const c of this.abstractMethods){const e=await c.getErrorsAsync({tracker:n});s.push(...e)}return s}getShallowErrors(){return this.errors}getAllInteractiveMethods(){const i=[];return i.push(...this.methods),!this.extends||this.extends.type===d.BuiltInBaseEntity&&this.extends.interactive||this.extends.type===d.PrimitiveEntity?i:(this.extends instanceof No&&i.push(...this.extends.getAllInteractiveMethods()),D(i))}};I(LA,"repository",{APILoad:async(i,...n)=>null});let ma=LA;function Ki(o,p){if(!o)throw new Error("Entity is null");const i=p.get(o.id);switch(o.type){case d.LiteralValue:return i||new Xr(o,p);case d.DefinitionEntity:return i||new us(o,p);case d.PrimitiveEntity:return i||new ma(o,p);case d.FunctionDeclaration:return i||new Vo(o,p);case d.GlobalEvent:return i||new Vu(o,p);case d.DataType:return i||new ir(o,p);case d.Property:return i||new ja(o,p);case d.FunctionCall:return i||new _u(o,p);case d.Condition:return i||new xu(o,p);case d.Operation:return i||new Pu(o,p);case d.VariableDeclaration:return i||new Mu(o,p);case d.VariableInstance:return i||new Lu(o,p);case d.OutputMap:return i||new Il(o,p);case d.ArgumentDeclaration:return i||new Ea(o,p);case d.InputMap:return i||new ds(o,p);case d.Project:return i||new x(o);case d.InstalledProject:return i||new Gu(o,p);case d.ActionDescriptor:return i||new Li(o,p);case d.ReturnStatement:return i||new Ed(o,p);case d.Loop:return i||new Nu(o,p);case d.Search:return i||new Bu(o,p);case d.ValueDescriptor:return i||new Ad(o,p);case d.BuiltInBaseEntity:return i||new No(o,p);case d.InternalCall:return i||new ku(o,p);case d.ContinueStatement:return i||new Uu(o,p);case d.BreakStatement:return i||new ju(o,p);case d.GenericReference:return p.get(o.entityId);default:throw new Error("Invalid entity type: "+o.type)}}function he(o,p){if(!o)throw new Error("Entity is null");const i=Ki(o,p);return i.subscribe(),i}function a1i(o,p){if(!o)throw new Error("Entity is null");switch(o.type){case d.LiteralValue:return Xr.fromGenerationTarget(o,p);case d.DefinitionEntity:return us.fromGenerationTarget(o,p);case d.FunctionDeclaration:return Vo.fromGenerationTarget(o,p);case d.GlobalEvent:return Vu.fromGenerationTarget(o,p);case d.DataType:return ir.fromGenerationTarget(o,p);case d.Property:return ja.fromGenerationTarget(o,p);case d.FunctionCall:return _u.fromGenerationTarget(o,p);case d.Condition:return xu.fromGenerationTarget(o,p);case d.Operation:return Pu.fromGenerationTarget(o,p);case d.VariableDeclaration:return Mu.fromGenerationTarget(o,p);case d.VariableInstance:return Lu.fromGenerationTarget(o,p);case d.OutputMap:return Il.fromGenerationTarget(o,p);case d.ArgumentDeclaration:return Ea.fromGenerationTarget(o,p);case d.InputMap:return ds.fromGenerationTarget(o,p);case d.InstalledProject:return Gu.fromGenerationTarget(o,p);case d.ReturnStatement:return Ed.fromGenerationTarget(o,p);case d.Loop:return Nu.fromGenerationTarget(o,p);case d.Search:return Bu.fromGenerationTarget(o,p);case d.ActionDescriptor:return Li.fromGenerationTarget(o,p);case d.ValueDescriptor:return Ad.fromGenerationTarget(o,p);case d.InternalCall:return ku.fromGenerationTarget(o,p);case d.ContinueStatement:return Uu.fromGenerationTarget(o,p);case d.BreakStatement:return ju.fromGenerationTarget(o,p);default:throw new Error("Invalid entity type: "+o.type)}}const ct={seenEntityMaps:new Map,seenEntities:new Set,timestamp:M().toISOString()};class QBe{constructor(){I(this,"initialData")}}const ke={cascade:!1},eGe={APILoad:async(o,...p)=>null},s1i={APICreate:async(o,...p)=>o,APIUpdate:async(o,...p)=>o,APIDelete:async(o,...p)=>o,APIClone:async(o,...p)=>{},APILoadVersion:async(o,p,...i)=>null,...eGe};class l1i{}class tGe extends QBe{}class o1i extends tGe{}class d1i{}class u1i{}class p1i{}class HN{}class c1i extends HN{}class f1i extends HN{}class y1i{}class af{static initReadsValue(p){if(p.initialData.readsValue&&p.initialData.readsValue.type!==d.GenericReference)p.readsValue=he(p.initialData.readsValue,p.project);else if(p.initialData.readsValue&&p.initialData.readsValue.type===d.GenericReference){const i=ra(p.initialData.readsValue,p.project);i&&(p.readsValue=i)}if(p.readsValue){if(Gt.includes(p.readsValue.type)){let i=p.parent;!nr.includes(i.type)&&i.type!==d.Project&&(i=i.parent);const n=p.type===d.InputMap&&p.parent.type===d.Loop;n&&(i=p.parent.parent),p.readsValue.setParent(i,null),p.readsValue.initChildren(null),i&&i.type!==d.Project&&!n&&i.detachedChildren.includes(p)?i.replaceDetachedChild(p,p.readsValue):i&&i.type!==d.Project&&!n&&i.subscribeDetachedChild(p.readsValue)}p.readsValue.addValueReader(p,null)}return p.readsValue}}class Pv{static initWritesValues(p,i){const n=p.initialData.writesValues.reduce((c,e)=>{if(e.type===d.GenericReference||p.writesValues.some(m=>m.id===e.id))return c;const y=he(e,p.project);return y.setValueWriter(p,null),Gt.includes(y.type)&&(y.setParent(i,null),y.initChildren(null)),[...c,y]},[]),s=[...p.writesValues];return p.writesValues=D([...s,...n]),p.writesValues}}class h1i{}var zt=(o=>(o.PROJECT_INITIALIZED="project-initialized",o.BEFORE_CHANGE_SET_CLOSE_BEFORE_SIDE_EFFECTS="before-change-set-close-before-side-effects",o.BEFORE_CHANGE_SET_CLOSE_AFTER_SIDE_EFFECTS="before-change-set-close-after-side-effects",o.CHANGE_SET_CLOSED_BEFORE_PERSIST="change-set-closed-before-persist",o.CHANGE_SET_PERSISTED="change-set-persisted",o.BEFORE_CHANGE_SET_PERSIST="before-change-set-persist",o.EXPLICIT_DEFINITION_ENTITY_ADDED="explicit-definition-entity-added",o.EXPLICIT_DEFINITION_ENTITY_REMOVED="explicit-definition-entity-removed",o.EXPLICIT_DEFINITION_ENTITY_UPDATED="explicit-definition-entity-updated",o.PERSISTED_DEFINITION_ENTITY_ADDED="persisted-definition-entity-added",o.PERSISTED_DEFINITION_ENTITY_REMOVED="persisted-definition-entity-removed",o.PERSISTED_DEFINITION_ENTITY_UPDATED="persisted-definition-entity-updated",o.RELATIONAL_DATABASE_DEFINITION_ENTITY_ADDED="relational-database-definition-entity-added",o.RELATIONAL_DATABASE_DEFINITION_ENTITY_REMOVED="relational-database-definition-entity-removed",o.RELATIONAL_DATABASE_DEFINITION_ENTITY_UPDATED="relational-database-definition-entity-updated",o))(zt||{});const WN={...sN,events:new J.Events("def-proj-static-p-ctx-events")},iGe={requestActiveDynamicValue:(o,p=!1)=>null,...WN},Ct=class Ct extends Ur{constructor(i,n={...iGe,events:new J.Events("def-proj-inst-p-ctx-events")}){super(i);I(this,"initialData");I(this,"id");I(this,"type",d.Project);I(this,"name",null);I(this,"description",null);I(this,"x");I(this,"y");I(this,"entities",[]);I(this,"projects",[]);I(this,"functions",[]);I(this,"events",[]);I(this,"variableDeclarations",[]);I(this,"variableInstances",[]);I(this,"conditions",[]);I(this,"operations",[]);I(this,"functionCalls",[]);I(this,"loops",[]);I(this,"searches",[]);I(this,"primitives",[]);I(this,"builtInBaseEntities",[]);I(this,"operationDeclarations",[]);I(this,"globalEventActionDescriptors",[]);I(this,"loopDeclarations",[]);I(this,"loopDeclarationsBodies",[]);I(this,"conditionDeclarations",[]);I(this,"valueDescriptors",[]);I(this,"dataTypes",[]);I(this,"project");I(this,"instances",{});I(this,"builtInInstances",{});I(this,"deletedInstances",{});I(this,"errors",[]);I(this,"references",[]);I(this,"history",[]);I(this,"undoableStackValueIndex",-1);I(this,"detachedDependents",{});I(this,"knownVersions",null);I(this,"activeVersion",!1);I(this,"initialized",!1);I(this,"startedInitialization",!1);I(this,"diggestedBuiltInBaseEntitiesIds",new Set);I(this,"rejectParallelCS",!1);I(this,"onPersistChangeSetSequentiallyCallback",null);I(this,"onPersistChangeSetInParallelCallback",null);I(this,"onAddChangeSetCallback",null);I(this,"onDiscardChangeSetCallback",null);if(this.parentContext=n,this.initialData=i,this.id=i.id,this.name=i.name,this.description=i.description,this.x=0,this.y=0,this.instances[this.id]=this,!Ct.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:Ct.UUID.uuid(),version:Ct.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||M().toISOString(),author:(i==null?void 0:i.author)||Ct.sessionAuthor,previousVersion:null,deleted:!1,deletable:!0,editable:!0,type:d.Project,name:"",description:"",entities:[],functions:[],events:[],projects:[],variableDeclarations:[],variableInstances:[],conditions:[],operations:[],functionCalls:[],loops:[],searches:[]}}static validateGenerationTarget(i,n){let s=JSON.parse(JSON.stringify(i));const c=[];return c.push(...$r(s)),{errors:c,modifiedData:s}}get off(){return this.parentContext.events.off}get on(){return this.parentContext.events.on}get emit(){return this.parentContext.events.emit}get emitAsync(){return this.parentContext.events.emitAsync}get emitAsyncAll(){return this.parentContext.events.emitAsyncAll}get emitAsyncAllSettled(){return this.parentContext.events.emitAsyncAllSettled}get emitAsyncSequentially(){return this.parentContext.events.emitAsyncSequentially}get emitAsyncSequentiallyAll(){return this.parentContext.events.emitAsyncSequentiallyAll}get emitAsyncSequentiallyAllSettled(){return this.parentContext.events.emitAsyncSequentiallyAllSettled}async closePersistChangeSetsSequentially(){J.Logger.log("[ProjectState.closePersistChangeSetsSequentially] called");const i=this.history.find(n=>n.dirty&&!n.open&&!n.submitting);i&&(J.Logger.log(`[ProjectState.closePersistChangeSetsSequentially] closing pending change-set ${i.id} - ${i.autoCloseActionName}`),await this.persistChangeSetSequentially(i))}async onPersistChangeSetSequentially(i){this.onPersistChangeSetSequentiallyCallback=i,J.Logger.log("[ProjectState.onPersistChangeSetSequentially] onPersistChangeSetSequentiallyCallback has been set. Checking for pending change-sets."),await this.closePersistChangeSetsSequentially()}offPersistChangeSetSequentially(){this.onPersistChangeSetSequentiallyCallback=null}async onPersistChangeSetInParallel(i){this.onPersistChangeSetInParallelCallback=i,J.Logger.log("[ProjectState.onPersistChangeSetInParallel] onPersistChangeSetInParallelCallback has been set. Checking for pending change-sets.");for(const n of this.history)this.persistChangeSetInParallel(n),await new Promise(s=>setTimeout(s,27))}offPersistChangeSetInParallel(){this.onPersistChangeSetInParallelCallback=null}onAddChangeSet(i){this.onAddChangeSetCallback=i}offAddChangeSet(){this.onAddChangeSetCallback=null}onDiscardChangeSet(i){this.onDiscardChangeSetCallback=i}offDiscardChangeSet(){this.onDiscardChangeSetCallback=null}async persistChangeSetSequentially(i){if(J.Logger.log(`[ProjectState.persistChangeSetSequentially] called for change-set ${i.id} - ${i.autoCloseActionName}`),!i.dirty||i.open||i.submitting){J.Logger.log(`[ProjectState.persistChangeSetSequentially] change-set ${i.id} - ${i.autoCloseActionName} is not dirty, or is open, or is already being submitted, skipping.`);return}const n=this.history.findIndex(e=>e.id===i.id),s=this.history.slice(0,n),c=s[s.length-1];if(c!=null&&c.dirty){J.Logger.log(`[ProjectState.persistChangeSetSequentially] lastBeforeSelf is dirty: ${c.id} - ${c.autoCloseActionName}, closing it first.`);return}this.onPersistChangeSetSequentiallyCallback&&(J.Logger.log(`[ProjectState.persistChangeSetSequentially] invoking onPersistChangeSetSequentiallyCallback for change-set ${i.id} - ${i.autoCloseActionName}`),this.emit("before-change-set-persist",i),i.submitting=!0,(await this.onPersistChangeSetSequentiallyCallback(i)).success&&(i.dirty=!1,this.emit("change-set-persisted",i),J.Logger.log(`[ProjectState.persistChangeSetSequentially] change-set ${i.id} - ${i.autoCloseActionName} closed successfully, checking for pending change-sets to close.`),this.closePersistChangeSetsSequentially()))}async persistChangeSetInParallel(i){if(J.Logger.log(`[ProjectState.persistChangeSetInParallel] called for change-set ${i.id} - ${i.autoCloseActionName}`),!i.dirty||i.open||i.submitting){J.Logger.log(`[ProjectState.persistChangeSetInParallel] change-set ${i.id} - ${i.autoCloseActionName} is not dirty, or is open, or is already being submitted, skipping.`);return}this.onPersistChangeSetInParallelCallback&&(J.Logger.log(`[ProjectState.persistChangeSetInParallel] invoking onPersistChangeSetInParallelCallback for change-set ${i.id} - ${i.autoCloseActionName}`),this.emit("before-change-set-persist",i),i.submitting=!0,(await this.onPersistChangeSetInParallelCallback(i)).success&&(i.dirty=!1,this.emit("change-set-persisted",i)))}toLatestChangeSet(i,n,s,c=!1,e="here-this"){if(!this.history.length)return new Z(this,i,n,s,c,e);const y=this.history[this.history.length-1];return y.open?y:this.addChangeSet(new Z(this,i,n,s,c,e))}addChangeSet(i){var s,c;if(!this.history.length)return this.undoableStackValueIndex=KO(this.undoableStackValueIndex,this.history,i),(s=this.onAddChangeSetCallback)==null||s.call(this,i,this.undoableStackValueIndex),i;const n=this.history.find(e=>e.id===(i==null?void 0:i.id));if(n)return n;if(this.rejectParallelCS){const e=this.history.find(y=>y.open);if(e)throw J.Logger.warn("Previous still open: ",e),J.Logger.warn("New change set: ",i),new Error(`There is already an open change-set with id '${e.id}'${e.autoCloseActionName?` auto-close: ${e.autoCloseActionName}`:""}${e.self?` root: ${e.self.type} ${se(e.self,this)}`:""}.`)}return this.undoableStackValueIndex=KO(this.undoableStackValueIndex,this.history,i),(c=this.onAddChangeSetCallback)==null||c.call(this,i,this.undoableStackValueIndex),i}discardChangeSet(i){var s;J.Logger.log(`[ProjectState.discardChangeSet] called for change-set ${i.id} - ${i.autoCloseActionName}`);const n=this.history.findIndex(c=>c.id===(i==null?void 0:i.id));return n!==-1&&(this.history.splice(n,1),J.Logger.log(`[ProjectState.discardChangeSet] Removed change-set ${i.id} - ${i.autoCloseActionName} from history.`),this.undoableStackValueIndex=this.undoableStackValueIndex-1,(s=this.onDiscardChangeSetCallback)==null||s.call(this,i),i==null||i.teardown()),this}validateGeneratedUpdate(i){return{errors:[],modifiedData:i}}subscribeDependents(i){return i.forEach(n=>{this.detachedDependents[n.entity.id]||(this.detachedDependents[n.entity.id]=n)}),this}unsubscribeDependents(i){return i.forEach(n=>{this.detachedDependents[n.entity.id]&&delete this.detachedDependents[n.entity.id]}),this}syncDependents(i=this.project.addChangeSet(new Z(this.project,Ct.sessionAuthor,M().toISOString(),this,!0,"sync-dependents"))){const n=[],s=[],c=[],e=[];return Object.values(this.detachedDependents).forEach(y=>{const m=y.entity.afterAllChildrenInitialized(i);n.push(...m.updated),s.push(...m.added),c.push(...m.removed),e.push(...m.affected)}),i==null||i.attemptAutoclose("sync-dependents",this.id),{updated:D(n),added:D(s),removed:D(c),affected:D(e),self:this}}onDetachedDependencyRemoved(i,n,s){const c=[],e=[],y=[],m=[];return{updated:D(c),added:D(e),removed:D(y),affected:D(m),self:this}}onDetachedDependencyRestored(i,n,s){const c=[],e=[],y=[],m=[];return{updated:D(c),added:D(e),removed:D(y),affected:D(m),self:this}}unsubscribeFromDependencies(){return this}subscribeToDependencies(){return this}increaseVersion(i){if(i&&!M(i).isValid())throw new Error(`The shared timestamp '${i}' is not a valid ISO 8601 date string.`);return i&&M(i).isSame(M(this.createdAt))?this:(this.previousVersion=this.version,this.version=Ct.UUID.uuid(),this.createdAt=M(i).toISOString()||M().toISOString(),this)}captureVersion(){var n;const i=((n=this.knownVersions)==null?void 0:n.get(this.version))||new Ct(this);return i.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,i):new Map([[this.version,i]]),i.entities=[...this.entities],i.projects=[...this.projects],i.functions=[...this.functions],i.events=[...this.events],i.variableDeclarations=[...this.variableDeclarations],i.variableInstances=[...this.variableInstances],i.conditions=[...this.conditions],i.operations=[...this.operations],i.functionCalls=[...this.functionCalls],i.loops=[...this.loops],i.searches=[...this.searches],this}recursiveCaptureUpstreamVersions(i){const n=[],s=[],c=[],e=[];return{updated:D(n),added:D(s),removed:D(c),affected:D(e),self:this}}async restoreVersion(i){var m;const n=[],s=[],c=[],e=[];if(this.version===i)return{updated:D(n),added:D(s),removed:D(c),affected:D(e),self:this};if(!this.knownVersions){const v=new Map;for(const[E,b]of this.knownVersions||new Map){if(v.set(E,b),b.activeVersion=!1,b.knownVersions)for(const[w,P]of b.knownVersions)v.set(w,P);b.knownVersions=null}}let y=(m=this.knownVersions)==null?void 0:m.get(i);if(!y){const v=await this.APILoadVersion({},i);if(!v)throw new Error(`Version with id '${i}' for entity with id '${this.id}' not found.`);y=new Ct(v)}return this.metaSync(y.toShallowJSON(),null),this.previousVersion=y.previousVersion,this.version=y.version,this.createdAt=y.createdAt,this.author=y.author,this.deleted=y.deleted,this.entities=y.entities,this.projects=y.projects,this.functions=y.functions,this.events=y.events,this.variableDeclarations=y.variableDeclarations,this.variableInstances=y.variableInstances,this.conditions=y.conditions,this.operations=y.operations,this.functionCalls=y.functionCalls,this.loops=y.loops,this.searches=y.searches,{updated:D(n),added:D(s),removed:D(c),affected:D(e),self:this}}updateWithShallowTransfer(i,n=this.project.addChangeSet(new Z(this.project,Ct.sessionAuthor,M().toISOString(),this,!0,_.UpdateWithShallowTransfer))){return this.checkCanEdit(this,n)?(this.metaSync(i,n),this.version=i.version,this.createdAt=i.createdAt,this.author=i.author,this.deleted=i.deleted,this.previousVersion=i.previousVersion,this.captureVersion(),this.subscribeToDependencies(),n==null||n.attemptAutoclose(_.UpdateWithShallowTransfer,this.id),this):(J.Logger.warn(`[updateWithShallowTransfer] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),n==null||n.attemptAutoclose(_.UpdateWithShallowTransfer,this.id),this)}hydrateAncestors(){const i=[],n=[],s=[],c=[];return{updated:D(i),added:D(n),removed:D(s),affected:D(c),self:this}}afterAllChildrenInitialized(i=null){const n=[],s=[],c=[],e=[];return this.initialized||(this.initialized=!0,this.emit("project-initialized",this,i)),this.validate(),this.captureVersion(),{updated:D(n),added:D(s),removed:D(c),affected:D(e),self:this}}addSelfToProject(i){const n=[],s=[],c=[],e=[];return this.subscribe(),this.subscribeToDependencies(),{updated:D(n),added:D(s),removed:D(c),affected:D(e),self:this}}get instancesList(){return Object.values(this.instances)}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 Z(this.project,Ct.sessionAuthor,M().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.entities=this.initialData.entities.map(n=>{const s=he(n,this);return s.setParent(this,null),s.initChildren(i),s}),this.projects=this.initialData.projects.map(n=>{const s=he(n,this);return s.setParent(this,null),s.initChildren(i),s}),this.variableDeclarations=this.initialData.variableDeclarations.map(n=>{const s=he(n,this);return s.setParent(this,null),s.initChildren(i),s}),this.variableInstances=this.initialData.variableInstances.map(n=>{const s=he(n,this);return s.setParent(this,null),s.initChildren(i),s}),this.conditions=this.initialData.conditions.map(n=>{const s=he(n,this);return s.setParent(this,null),s.initChildren(i),s}),this.operations=this.initialData.operations.map(n=>{const s=he(n,this);return s.setParent(this,null),s.initChildren(i),s}),this.functions=this.initialData.functions.map(n=>{const s=he(n,this);return s.setParent(this,null),s.initChildren(i),s}),this.events=this.initialData.events.map(n=>{const s=he(n,this);return s.setParent(this,null),s.initChildren(i),s}),this.functionCalls=this.initialData.functionCalls.map(n=>{const s=he(n,this);return s.setParent(this,null),s.initChildren(i),s}),this.loops=this.initialData.loops.map(n=>{const s=he(n,this);return s.setParent(this,null),s.initChildren(i),s}),this.searches=this.initialData.searches.map(n=>{const s=he(n,this);return s.setParent(this,null),s.initChildren(i),s}),this.attachOrphanReferences(),this.subscribeToDependencies(),this.afterAllChildrenInitialized(i),i==null||i.attemptAutoclose("init-children",this.id),this)}subscribeInstance(i){return(!this.instances[i.id]||this.instances[i.id]!==i)&&(this.instances[i.id]=i),this}subscribeDeletedInstance(i){return(!this.deletedInstances[i.id]||this.deletedInstances[i.id]!==i)&&(this.deletedInstances[i.id]=i),this}subscribeBuiltInInstance(i){return(!this.builtInInstances[i.id]||this.builtInInstances[i.id]!==i)&&(this.builtInInstances[i.id]=i),this}subscribe(){return this}unsubscribe(){return this}unsubscribeInstance(i){return delete this.instances[i.id],this}unsubscribeDeletedInstance(i){return delete this.deletedInstances[i.id],this}findSubscribedBuiltInInstance(i){return this.builtInInstances[i.id]||null}get(i){return this.instances[i]||this.builtInInstances[i]||null}getDeleted(i){return this.deletedInstances[i]||null}getManaged(i){return this.getBuiltIn(i)?null:this.instances[i]||null}getBuiltIn(i){return this.builtInInstances[i]||null}findSubscribedInstanceFromReference(i){return this.instances[i.entityId]||null}findSubscribedBuiltInInstanceFromReference(i){return this.builtInInstances[i.entityId]||null}metaSync(i,n=this.project.addChangeSet(new Z(this.project,Ct.sessionAuthor,M().toISOString(),this,!0,"meta-sync"))){const s=Mr(this,i,n),c=Lr(this,s),e=this.toMeta();return this.name=s.name!==void 0?s.name:e.name,this.description=s.description!==void 0?s.description:e.description,this.x=s.x||e.x,this.y=s.y||e.y,super.baseMetaSync(s,this,n),s.deleted===!0&&!e.deleted?n==null||n.add(this,H.Removed):s.deleted===!1&&e.deleted?n==null||n.add(this,H.Added):c&&(n==null||n.add(this,H.Updated)),n==null||n.attemptAutoclose("meta-sync",this.id),this}async APILoad(i=ke,...n){return await Ct.repository.APILoad(this.id,...n),this}async APICreate(i=ke,...n){return await Ct.repository.APICreate(this.toShallowJSON(),...n),this}async APIUpdate(i=ke,...n){return await Ct.repository.APIUpdate(this.toShallowJSON(),...n),this}async APIDelete(i=ke,...n){return await Ct.repository.APIDelete(this.toShallowJSON(),...n),this}async APIClone(i=ke,...n){return await Ct.repository.APIClone(this.id,...n),this}async APILoadVersion(i=ke,n,...s){return await Ct.repository.APILoadVersion(this.id,n,...s)}remove({ignoreUpstream:i}={ignoreUpstream:!1},n=this.project.addChangeSet(new Z(this.project,Ct.sessionAuthor,M().toISOString(),this,!0,_.RemoveEntity))){return{added:[],updated:[],removed:[],affected:[],self:this}}restore({}={},i=this.project.addChangeSet(new Z(this.project,Ct.sessionAuthor,M().toISOString(),this,!0,_.RestoreEntity))){return{added:[],updated:[],removed:[],affected:[],self:this}}getAllBuiltInIds(){const i=new Set;return[...this.primitives.flatMap(n=>n.toFlatIds(i)),...this.builtInBaseEntities.flatMap(n=>n.toFlatIds(i)),...this.operationDeclarations.flatMap(n=>n.toFlatIds(i)),...this.globalEventActionDescriptors.flatMap(n=>n.toFlatIds(i)),...this.loopDeclarations.flatMap(n=>n.toFlatIds(i)),...this.conditionDeclarations.flatMap(n=>n.toFlatIds(i)),...this.valueDescriptors.flatMap(n=>n.toFlatIds(i)),...this.dataTypes.flatMap(n=>n.toFlatIds(i))]}getAllBuiltIn(){const i=new Set;return[...this.primitives.flatMap(n=>n.toFlat(i)),...this.builtInBaseEntities.flatMap(n=>n.toFlat(i)),...this.operationDeclarations.flatMap(n=>n.toFlat(i)),...this.globalEventActionDescriptors.flatMap(n=>n.toFlat(i)),...this.loopDeclarations.flatMap(n=>n.toFlat(i)),...this.conditionDeclarations.flatMap(n=>n.toFlat(i)),...this.valueDescriptors.flatMap(n=>n.toFlat(i)),...this.dataTypes.flatMap(n=>n.toFlat(i))]}toFlat(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this,...this.entities.flatMap(s=>s.toFlat(i)),...this.functions.flatMap(s=>s.toFlat(i)),...this.events.flatMap(s=>s.toFlat(i)),...this.projects.flatMap(s=>s.toFlat(i)),...this.variableDeclarations.flatMap(s=>s.toFlat(i)),...this.variableInstances.flatMap(s=>s.toFlat(i)),...this.conditions.flatMap(s=>s.toFlat(i)),...this.operations.flatMap(s=>s.toFlat(i)),...this.functionCalls.flatMap(s=>s.toFlat(i)),...this.loops.flatMap(s=>s.toFlat(i)),...this.searches.flatMap(s=>s.toFlat(i))])}toFlatIds(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.id,...this.entities.flatMap(s=>s.toFlatIds(i)),...this.functions.flatMap(s=>s.toFlatIds(i)),...this.events.flatMap(s=>s.toFlatIds(i)),...this.projects.flatMap(s=>s.toFlatIds(i)),...this.variableDeclarations.flatMap(s=>s.toFlatIds(i)),...this.variableInstances.flatMap(s=>s.toFlatIds(i)),...this.conditions.flatMap(s=>s.toFlatIds(i)),...this.operations.flatMap(s=>s.toFlatIds(i)),...this.functionCalls.flatMap(s=>s.toFlatIds(i)),...this.loops.flatMap(s=>s.toFlatIds(i)),...this.searches.flatMap(s=>s.toFlatIds(i))])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,description:this.description,type:this.type,editable:this.editable,deletable:this.deletable,name:this.name}}toJSON(i=new Set){return i.has(this.id)?this.toReference():(i.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,editable:this.editable,deletable:this.deletable,name:this.name,description:this.description,entities:this.entities.map(n=>n.toJSON(i)),variableDeclarations:this.variableDeclarations.map(n=>n.toJSON(i)),variableInstances:this.variableInstances.map(n=>n.toJSON(i)),conditions:this.conditions.map(n=>n.toJSON(i)),operations:this.operations.map(n=>n.toJSON(i)),loops:this.loops.map(n=>n.toJSON(i)),searches:this.searches.map(n=>n.toJSON(i)),functions:this.functions.map(n=>n.toJSON(i)),events:this.events.map(n=>n.toJSON(i)),projects:this.projects.map(n=>n.toJSON(i)),functionCalls:this.functionCalls.map(n=>n.toJSON(i))})}toJSONClone(i={uuidStrategy:"uuid"}){const n=new Map,s=new Set,c=this.getAllBuiltInIds();return Object.keys(this.instances).forEach(e=>{if(c.includes(e)){n.set(e,e);return}n.set(e,Ct.UUID.uuid())}),s.add(this.id),{id:n.get(this.id),version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,editable:this.editable,deletable:this.deletable,name:this.name,description:this.description,entities:this.entities.map(e=>e.toJSONClone({...i,seenEntityMaps:n,seenEntities:s,newId:null})),projects:this.projects.map(e=>e.toJSONClone({...i,seenEntityMaps:n,seenEntities:s,newId:null})),variableDeclarations:this.variableDeclarations.map(e=>e.toJSONClone({...i,seenEntityMaps:n,seenEntities:s,newId:null})),variableInstances:this.variableInstances.map(e=>e.toJSONClone({...i,seenEntityMaps:n,seenEntities:s,newId:null})),conditions:this.conditions.map(e=>e.toJSONClone({...i,seenEntityMaps:n,seenEntities:s,newId:null})),operations:this.operations.map(e=>e.toJSONClone({...i,seenEntityMaps:n,seenEntities:s,newId:null})),functions:this.functions.map(e=>e.toJSONClone({...i,seenEntityMaps:n,seenEntities:s,newId:null})),events:this.events.map(e=>e.toJSONClone({...i,seenEntityMaps:n,seenEntities:s,newId:null})),functionCalls:this.functionCalls.map(e=>e.toJSONClone({...i,seenEntityMaps:n,seenEntities:s,newId:null})),loops:this.loops.map(e=>e.toJSONClone({...i,seenEntityMaps:n,seenEntities:s,newId:null})),searches:this.searches.map(e=>e.toJSONClone({...i,seenEntityMaps:n,seenEntities:s,newId:null}))}}toReference(i=ct){var s;let n=this.id;return(s=i.seenEntityMaps)!=null&&s.has(this.id)&&(n=i.seenEntityMaps.get(this.id)),{id:n+"--"+Ct.UUID.uuid()+"--ref",type:d.GenericReference,entityId:n,version:this.version,entityType:this.type}}toShallowJSON(i=ct){var s;let n=this.id;return(s=i.seenEntityMaps)!=null&&s.has(this.id)&&(n=i.seenEntityMaps.get(this.id)),{id:n,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,editable:this.editable,deletable:this.deletable,name:this.name,description:this.description,entities:this.entities.map(c=>c.toReference(i)),functions:this.functions.map(c=>c.toReference(i)),events:this.events.map(c=>c.toReference(i)),projects:this.projects.map(c=>c.toReference(i)),variableDeclarations:this.variableDeclarations.map(c=>c.toReference(i)),variableInstances:this.variableInstances.map(c=>c.toReference(i)),conditions:this.conditions.map(c=>c.toReference(i)),operations:this.operations.map(c=>c.toReference(i)),functionCalls:this.functionCalls.map(c=>c.toReference(i)),loops:this.loops.map(c=>c.toReference(i)),searches:this.searches.map(c=>c.toReference(i))}}toFlatJSON(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.toShallowJSON(),...this.entities.flatMap(s=>s.toFlatJSON(i)),...this.functions.flatMap(s=>s.toFlatJSON(i)),...this.events.flatMap(s=>s.toFlatJSON(i)),...this.projects.flatMap(s=>s.toFlatJSON(i)),...this.variableDeclarations.flatMap(s=>s.toFlatJSON(i)),...this.variableInstances.flatMap(s=>s.toFlatJSON(i)),...this.conditions.flatMap(s=>s.toFlatJSON(i)),...this.operations.flatMap(s=>s.toFlatJSON(i)),...this.functionCalls.flatMap(s=>s.toFlatJSON(i)),...this.loops.flatMap(s=>s.toFlatJSON(i)),...this.searches.flatMap(s=>s.toFlatJSON(i))])}toGenerationTarget(){return{id:this.id,type:this.type,name:this.name,description:this.description}}toFlatGenerationTarget(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[...this.entities.flatMap(s=>s.toFlatGenerationTarget(i)),...this.functions.flatMap(s=>s.toFlatGenerationTarget(i)),...this.events.flatMap(s=>s.toFlatGenerationTarget(i)),...this.projects.flatMap(s=>s.toFlatGenerationTarget(i)),...this.variableDeclarations.flatMap(s=>s.toFlatGenerationTarget(i)),...this.variableInstances.flatMap(s=>s.toFlatGenerationTarget(i)),...this.conditions.flatMap(s=>s.toFlatGenerationTarget(i)),...this.operations.flatMap(s=>s.toFlatGenerationTarget(i)),...this.functionCalls.flatMap(s=>s.toFlatGenerationTarget(i)),...this.loops.flatMap(s=>s.toFlatGenerationTarget(i)),...this.searches.flatMap(s=>s.toFlatGenerationTarget(i))])}clearErrors(){return this.errors=[],this.entities.forEach(i=>i.clearErrors()),this.projects.forEach(i=>i.clearErrors()),this.functions.forEach(i=>i.clearErrors()),this.events.forEach(i=>i.clearErrors()),this.variableDeclarations.forEach(i=>i.clearErrors()),this.variableInstances.forEach(i=>i.clearErrors()),this.conditions.forEach(i=>i.clearErrors()),this.operations.forEach(i=>i.clearErrors()),this.functionCalls.forEach(i=>i.clearErrors()),this.loops.forEach(i=>i.clearErrors()),this.searches.forEach(i=>i.clearErrors()),this}validate(){return this.validateChildren(),tv([...this.errors]),{success:!0}}async validateAsync(i={}){const n=J.YieldTracker.from(i);return await this.validateChildrenAsync({tracker:n}),await Awe([...this.errors]),{success:!0}}validateChildren(){this.entities.forEach(i=>i.validate()),this.projects.forEach(i=>i.validate()),this.functions.forEach(i=>i.validate()),this.events.forEach(i=>i.validate()),this.variableDeclarations.forEach(i=>i.validate()),this.variableInstances.forEach(i=>i.validate()),this.conditions.forEach(i=>i.validate()),this.operations.forEach(i=>i.validate()),this.functionCalls.forEach(i=>i.validate()),this.loops.forEach(i=>i.validate()),this.searches.forEach(i=>i.validate())}async validateChildrenAsync(i={}){const n=J.YieldTracker.from(i);for(let s=0;s<this.entities.length;s++)await this.entities[s].validateAsync({tracker:n});for(let s=0;s<this.projects.length;s++)await this.projects[s].validateAsync({tracker:n});for(let s=0;s<this.functions.length;s++)await this.functions[s].validateAsync({tracker:n});for(let s=0;s<this.events.length;s++)await this.events[s].validateAsync({tracker:n});for(let s=0;s<this.variableDeclarations.length;s++)await this.variableDeclarations[s].validateAsync({tracker:n});for(let s=0;s<this.variableInstances.length;s++)await this.variableInstances[s].validateAsync({tracker:n});for(let s=0;s<this.conditions.length;s++)await this.conditions[s].validateAsync({tracker:n});for(let s=0;s<this.operations.length;s++)await this.operations[s].validateAsync({tracker:n});for(let s=0;s<this.functionCalls.length;s++)await this.functionCalls[s].validateAsync({tracker:n});for(let s=0;s<this.loops.length;s++)await this.loops[s].validateAsync({tracker:n});for(let s=0;s<this.searches.length;s++)await this.searches[s].validateAsync({tracker:n})}getErrors(){return[...this.errors,...this.entities.flatMap(n=>n.getErrors()),...this.projects.flatMap(n=>n.getErrors()),...this.functions.flatMap(n=>n.getErrors()),...this.events.flatMap(n=>n.getErrors()),...this.variableDeclarations.flatMap(n=>n.getErrors()),...this.variableInstances.flatMap(n=>n.getErrors()),...this.conditions.flatMap(n=>n.getErrors()),...this.operations.flatMap(n=>n.getErrors()),...this.functionCalls.flatMap(n=>n.getErrors()),...this.loops.flatMap(n=>n.getErrors()),...this.searches.flatMap(n=>n.getErrors())]}async getErrorsAsync(i={}){const n=J.YieldTracker.from(i),s=[...this.errors];await n.tick();for(let c=0;c<this.entities.length;c++){const e=await this.entities[c].getErrorsAsync({tracker:n});s.push(...e)}for(let c=0;c<this.projects.length;c++){const e=await this.projects[c].getErrorsAsync({tracker:n});s.push(...e)}for(let c=0;c<this.functions.length;c++){const e=await this.functions[c].getErrorsAsync({tracker:n});s.push(...e)}for(let c=0;c<this.events.length;c++){const e=await this.events[c].getErrorsAsync({tracker:n});s.push(...e)}for(let c=0;c<this.variableDeclarations.length;c++){const e=await this.variableDeclarations[c].getErrorsAsync({tracker:n});s.push(...e)}for(let c=0;c<this.variableInstances.length;c++){const e=await this.variableInstances[c].getErrorsAsync({tracker:n});s.push(...e)}for(let c=0;c<this.conditions.length;c++){const e=await this.conditions[c].getErrorsAsync({tracker:n});s.push(...e)}for(let c=0;c<this.operations.length;c++){const e=await this.operations[c].getErrorsAsync({tracker:n});s.push(...e)}for(let c=0;c<this.functionCalls.length;c++){const e=await this.functionCalls[c].getErrorsAsync({tracker:n});s.push(...e)}for(let c=0;c<this.loops.length;c++){const e=await this.loops[c].getErrorsAsync({tracker:n});s.push(...e)}for(let c=0;c<this.searches.length;c++){const e=await this.searches[c].getErrorsAsync({tracker:n});s.push(...e)}return s}getShallowErrors(){return this.errors}clone(){return this}getDefinitionEntity(i){return this.entities.find(n=>n.id===i)||null}addDefinitionEntity(i){return this.entities.includes(i)||this.entities.push(i),i}addFunctionDeclaration(i){return this.functions.includes(i)||this.functions.push(i),i}addFunctionCall(i){return this.functionCalls.includes(i)||this.functionCalls.push(i),i}addVariableDeclaration(i){return this.variableDeclarations.includes(i)||this.variableDeclarations.push(i),i}addVariableInstance(i){return this.variableInstances.includes(i)||this.variableInstances.push(i),i}addInstalledProject(i){return this.projects.includes(i)||this.projects.push(i),this}addGlobalEvent(i){return this.events.includes(i)||this.events.push(i),this}addCondition(i){return this.conditions.includes(i)||this.conditions.push(i),this}addOperation(i){return this.operations.includes(i)||this.operations.push(i),this}addLoop(i){return this.loops.includes(i)||this.loops.push(i),this}addSearch(i){return this.searches.includes(i)||this.searches.push(i),this}removeDefinitionEntity(i){const n=this.entities.findIndex(s=>s.id===i.id);if(n>-1){const s=this.entities[n];return this.entities.splice(n,1),s}return null}removeCondition(i){const n=this.conditions.findIndex(s=>s.id===i.id);if(n>-1){const s=this.conditions[n];return this.conditions.splice(n,1),s}return null}removeOperation(i){const n=this.operations.findIndex(s=>s.id===i.id);if(n>-1){const s=this.operations[n];return this.operations.splice(n,1),s}return null}removeLoop(i){const n=this.loops.findIndex(s=>s.id===i.id);if(n>-1){const s=this.loops[n];return this.loops.splice(n,1),s}return null}removeSearch(i){const n=this.searches.findIndex(s=>s.id===i.id);if(n>-1){const s=this.searches[n];return this.searches.splice(n,1),s}return null}removeFunctionCall(i){const n=this.functionCalls.findIndex(s=>s.id===i.id);if(n>-1){const s=this.functionCalls[n];return this.functionCalls.splice(n,1),s}return null}removeVariableInstance(i){const n=this.variableInstances.findIndex(s=>s.id===i.id);if(n>-1){const s=this.variableInstances[n];return this.variableInstances.splice(n,1),s}return null}removeVariableDeclaration(i){const n=this.variableDeclarations.findIndex(s=>s.id===i.id);if(n>-1){const s=this.variableDeclarations[n];return this.variableDeclarations.splice(n,1),s}return null}removeFunctionDeclaration(i){const n=this.functions.findIndex(s=>s.id===i.id);if(n>-1){const s=this.functions[n];return this.functions.splice(n,1),s}return null}removeInstalledProject(i){const n=this.projects.findIndex(s=>s.id===i.id);if(n>-1){const s=this.projects[n];return this.projects.splice(n,1),s}return null}removeGlobalEvent(i){const n=this.events.findIndex(s=>s.id===i.id);if(n>-1){const s=this.events[n];return this.events.splice(n,1),s}return null}removeTopLevelVariableDeclaration(i){if(i.type!==d.VariableDeclaration)return null;const n=this.variableDeclarations.findIndex(s=>s.id===i.id);if(n>-1){const s=this.variableDeclarations[n];return this.variableDeclarations.splice(n,1),s}return null}getEntryPoints(){return[...this.functions,...this.events,...this.entities.flatMap(n=>n.methods)]}getTerminationStatements(){return[...this.getEntryPoints().reduce((n,s)=>{const c=wt(s);return[...n,...c.filter(e=>e.type===d.ReturnStatement||e.type===d.ContinueStatement||e.type===d.BreakStatement)]},[])]}getFunctionDeclaration(i){return this.functions.find(n=>n.id===i)||null}getConditions(){return[...this.conditions,...this.getEntryPoints().reduce((n,s)=>{const c=wt(s);return[...n,...c.filter(e=>e.type===d.Condition)]},[]),...this.functionCalls.reduce((n,s)=>{const c=wt(s);return[...n,...c.filter(e=>e.type===d.Condition)]},[]),...this.operations.reduce((n,s)=>{const c=wt(s);return[...n,...c.filter(e=>e.type===d.Condition)]},[]),...this.loops.reduce((n,s)=>{const c=wt(s);return[...n,...c.filter(e=>e.type===d.Condition)]},[]),...this.searches.reduce((n,s)=>{const c=wt(s);return[...n,...c.filter(e=>e.type===d.Condition)]},[])]}getOperations(){return[...this.operations,...this.getEntryPoints().reduce((n,s)=>{const c=wt(s);return[...n,...c.filter(e=>e.type===d.Operation)]},[]),...this.functionCalls.reduce((n,s)=>{const c=wt(s);return[...n,...c.filter(e=>e.type===d.Operation)]},[]),...this.conditions.reduce((n,s)=>{const c=wt(s);return[...n,...c.filter(e=>e.type===d.Operation)]},[]),...this.loops.reduce((n,s)=>{const c=wt(s);return[...n,...c.filter(e=>e.type===d.Operation)]},[]),...this.searches.reduce((n,s)=>{const c=wt(s);return[...n,...c.filter(e=>e.type===d.Operation)]},[])]}getFunctionCalls(){return[...this.functionCalls,...this.getEntryPoints().reduce((n,s)=>{const c=wt(s);return[...n,...c.filter(e=>e.type===d.FunctionCall)]},[]),...this.conditions.reduce((n,s)=>{const c=wt(s);return[...n,...c.filter(e=>e.type===d.FunctionCall)]},[]),...this.operations.reduce((n,s)=>{const c=wt(s);return[...n,...c.filter(e=>e.type===d.FunctionCall)]},[]),...this.loops.reduce((n,s)=>{const c=wt(s);return[...n,...c.filter(e=>e.type===d.FunctionCall)]},[]),...this.searches.reduce((n,s)=>{const c=wt(s);return[...n,...c.filter(e=>e.type===d.FunctionCall)]},[])]}getVariables(){return[...this.variableDeclarations,...this.getEntryPoints().reduce((n,s)=>{const c=Ji(s);return[...n,...c]},[]),...this.functionCalls.reduce((n,s)=>{const c=Ji(s);return[...n,...c]},[]),...this.conditions.reduce((n,s)=>{const c=Ji(s);return[...n,...c]},[]),...this.operations.reduce((n,s)=>{const c=Ji(s);return[...n,...c]},[]),...this.loops.reduce((n,s)=>{const c=Ji(s);return[...n,...c]},[]),...this.searches.reduce((n,s)=>{const c=Ji(s);return[...n,...c]},[])]}getVariableInstances(){return[...this.variableInstances,...this.entities.reduce((n,s)=>[...n,...s.methods.flatMap(c=>{const y=wt(c).filter(m=>m.type===d.VariableInstance);return[...n,...y]})],[]),...this.getEntryPoints().reduce((n,s)=>{const e=Ji(s).filter(y=>y.type===d.VariableInstance);return[...n,...e]},[]),...this.functionCalls.reduce((n,s)=>{const e=Ji(s).filter(y=>y.type===d.VariableInstance);return[...n,...e]},[]),...this.conditions.reduce((n,s)=>{const e=Ji(s).filter(y=>y.type===d.VariableInstance);return[...n,...e]},[]),...this.operations.reduce((n,s)=>{const e=Ji(s).filter(y=>y.type===d.VariableInstance);return[...n,...e]},[]),...this.loops.reduce((n,s)=>{const e=Ji(s).filter(y=>y.type===d.VariableInstance);return[...n,...e]},[]),...this.searches.reduce((n,s)=>{const e=Ji(s).filter(y=>y.type===d.VariableInstance);return[...n,...e]},[])]}getVariableDeclarations(){return D([...this.variableDeclarations,...this.entities.reduce((n,s)=>[...n,...s.methods.flatMap(c=>{const y=wt(c).filter(m=>m.type===d.VariableDeclaration);return[...n,...y]})],[]),...this.getEntryPoints().reduce((n,s)=>{const e=Ji(s).filter(y=>y.type===d.VariableDeclaration);return[...n,...e]},[]),...this.functionCalls.reduce((n,s)=>{const e=Ji(s).filter(y=>y.type===d.VariableDeclaration);return[...n,...e]},[]),...this.conditions.reduce((n,s)=>{const e=Ji(s).filter(y=>y.type===d.VariableDeclaration);return[...n,...e]},[]),...this.operations.reduce((n,s)=>{const e=Ji(s).filter(y=>y.type===d.VariableDeclaration);return[...n,...e]},[]),...this.loops.reduce((n,s)=>{const e=Ji(s).filter(y=>y.type===d.VariableDeclaration);return[...n,...e]},[]),...this.searches.reduce((n,s)=>{const e=Ji(s).filter(y=>y.type===d.VariableDeclaration);return[...n,...e]},[])])}getLoops(){return[...this.loops,...this.getEntryPoints().reduce((n,s)=>{const c=wt(s);return[...n,...c.filter(e=>e.type===d.Loop)]},[]),...this.functionCalls.reduce((n,s)=>{const c=wt(s);return[...n,...c.filter(e=>e.type===d.Loop)]},[]),...this.conditions.reduce((n,s)=>{const c=wt(s);return[...n,...c.filter(e=>e.type===d.Loop)]},[]),...this.operations.reduce((n,s)=>{const c=wt(s);return[...n,...c.filter(e=>e.type===d.Loop)]},[]),...this.searches.reduce((n,s)=>{const c=wt(s);return[...n,...c.filter(e=>e.type===d.Loop)]},[])]}getSearches(){return[...this.searches,...this.getEntryPoints().reduce((n,s)=>{const c=wt(s);return[...n,...c.filter(e=>e.type===d.Search)]},[]),...this.functionCalls.reduce((n,s)=>{const c=wt(s);return[...n,...c.filter(e=>e.type===d.Search)]},[]),...this.conditions.reduce((n,s)=>{const c=wt(s);return[...n,...c.filter(e=>e.type===d.Search)]},[]),...this.operations.reduce((n,s)=>{const c=wt(s);return[...n,...c.filter(e=>e.type===d.Search)]},[]),...this.loops.reduce((n,s)=>{const c=wt(s);return[...n,...c.filter(e=>e.type===d.Search)]},[])]}attachOrphanReferences(){const i=this.getVariableInstances(),n=this.getVariableDeclarations();return i.forEach(s=>{if(!s.declaration){const c=s.initialData,e=c.declaration.entityId||c.declaration.id,y=n.find(m=>m.id===e);y&&s.setDeclaration(y)}}),this}getBuiltInPersistedEntity(){return this.builtInBaseEntities.find(i=>i.name===Re.PERSISTED_ENTITY)||null}requestActiveDynamicValue(i,n=!1){var c,e;const s=(e=(c=this.parentContext).requestActiveDynamicValue)==null?void 0:e.call(c,i,n);if(!s&&BA.includes(i.type)){const y=i.getDefaultValue();return y?{value:y,type:Ve.DefaultValue,inheritanceLink:null,valueOwner:i}:null}return s||null}requestExtension(i){if(this.parentContext.requestExtension){const n=this.parentContext.requestExtension(i);if(n&&!n.module)throw new Error(`Module ${i} is not registered properly.`);return n.module||null}return null}undo(){J.Logger.log("Undoing, from: ",this.undoableStackValueIndex),this.undoableStackValueIndex=this.undoableStackValueIndex-1,J.Logger.log("To: ",this.undoableStackValueIndex);const i=this.history[this.undoableStackValueIndex+1],n=this.history[this.undoableStackValueIndex];return J.Logger.log("Current change set: ",i==null?void 0:i.toJSON()),J.Logger.log("Change set to restore: ",n==null?void 0:n.toJSON()),jO(i||"initial",n||"initial",this)}redo(){J.Logger.log("Undoing, from: ",this.undoableStackValueIndex),this.undoableStackValueIndex=this.undoableStackValueIndex+1,J.Logger.log("To: ",this.undoableStackValueIndex);const i=this.history[this.undoableStackValueIndex-1],n=this.history[this.undoableStackValueIndex];return J.Logger.log("Current change set: ",i==null?void 0:i.toJSON()),J.Logger.log("Change set to restore: ",n.toJSON()),jO(i||"initial",n||"initial",this)}applyExternalChangeSet(i){const n=i.payload,s=this.addChangeSet(new Z(this,i.userAuthor,i.emittedAt,this));s.ignoreNonEditable=!0,s.ignoreNonDeletable=!0;const c=n.updated[this.id];if(!c)throw new Error("Project root not found in change set transfer. Cannot apply changes.");const e={...n.added,...n.updated,...n.removed},y=[...Object.keys(n.added),...Object.keys(n.updated),...Object.keys(n.removed)];y.forEach(v=>{var E;if(!e[v]){J.Logger.warn(`Entity '${v}' not found in change set transfer. Cannot apply changes.`);const b=(E=this.get(v))==null?void 0:E.toShallowJSON();throw b?J.Logger.warn("Entity in project: ",b):J.Logger.warn("Entity not in project"),new Error(`Entity '${v}' not found in change set transfer. Cannot apply changes.`)}});const m=new Nn(c,{allBuiltInEntityIds:this.diggestedBuiltInBaseEntitiesIds});return m.flatRecord=e,m.order=y,m.orderEntities(),J.Logger.log("All entities: ",m.order.map((v,E)=>`${E+1}: ${e[v].type} - ${v}`).join(`,
387
- `)),J.Logger.log("Persisting new additions"),m.visit(async(v,E)=>{if(n.added[v.id]){J.Logger.log("Adding: ",v.id);try{const b=he(v,this);if(b.hydrateAncestors(),b.addSelfToProject(s),s.add(b,H.Added),!this.get(v.id))throw new Error(`Entity ${v.id} was not added to the project`)}catch(b){J.Logger.error("Error: ",b),J.Logger.error("Errored entity: ",v)}}}),J.Logger.log("Persisting updates"),m.visit(async(v,E)=>{if(n.updated[v.id]){J.Logger.log("Updating: ",v.id);try{const b=this.get(v.id);b?(b.updateWithShallowTransfer(v,s),s.add(b,H.Updated)):J.Logger.warn(`Active version of ${v.id} not found when applying external changes`)}catch(b){J.Logger.error("Error: ",b),J.Logger.error("Errored entity: ",v)}}}),J.Logger.log("Persisting removals"),m.visit(async(v,E)=>{if(n.removed[v.id]){J.Logger.log("Removing: ",v.id);try{const b=this.get(v.id);b&&b.remove({ignoreUpstream:!1},s)}catch(b){J.Logger.error("Error: ",b),J.Logger.error("Errored entity: ",v)}}}),s.open=!1,s}toBuiltInShallowRecord(){const i={};return Object.values(this.builtInInstances).forEach(n=>{const s=n.toShallowJSON();i[n.id]=s}),i}toShallowRecord(){const i={};return Object.values(this.instances).forEach(n=>{const s=n.toShallowJSON();i[n.id]=s}),i}toFullProjectTransfer(){const i=new Nn(void 0,{allBuiltInEntityIds:this.diggestedBuiltInBaseEntitiesIds});i.flatRecord=this.instances,i.order=Object.keys(i.flatRecord),i.orderEntities();const n={};return i.visit(s=>{const c=s.toShallowJSON();n[s.id]=c}),{order:i.order,size:i.order.length,record:n}}async toFullProjectTransferAsync(i={}){const n=J.YieldTracker.from(i),s=new Nn(void 0,{allBuiltInEntityIds:this.diggestedBuiltInBaseEntitiesIds});s.flatRecord=this.instances,s.order=Object.keys(s.flatRecord);let c=s.order;if(i.seenEntityMaps){c=[];for(const y of s.order){const m=i.seenEntityMaps.get(y)??y;this.diggestedBuiltInBaseEntitiesIds.has(m)||c.push(m)}}await s.orderEntitiesAsync({tracker:n});const e={};return await s.visitAsync(async y=>{if(this.diggestedBuiltInBaseEntitiesIds.has(y.id))return;const m=y.toShallowJSON({seenEntityMaps:i.seenEntityMaps});i.resetVersionOptions&&(m.version=Ct.UUID.uuid(),m.createdAt=i.resetVersionOptions.commonTimestamp||M().toISOString(),m.author=i.resetVersionOptions.author||Ct.sessionAuthor||"1",m.previousVersion=null),e[m.id]=m,i!=null&&i.onVisit&&await i.onVisit(m)},{tracker:n}),{order:c,size:s.order.length,record:e}}};I(Ct,"parentContext",WN),I(Ct,"sessionAuthor","1"),I(Ct,"repository",{APICreate:async(i,...n)=>i,APIUpdate:async(i,...n)=>i,APIDelete:async(i,...n)=>i,APIClone:async(i,...n)=>{},APILoad:async(i,...n)=>null,APILoadVersion:async(i,n,...s)=>null}),I(Ct,"type",d.Project),I(Ct,"USER_MANAGED_PARENT_TYPES",[]),I(Ct,"PARENT_TYPES",[...Ct.USER_MANAGED_PARENT_TYPES]),I(Ct,"MUTABLE_BASE_PROPERTIES",["name","description"]),I(Ct,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),I(Ct,"BASE_PROPERTIES",[...Ct.MUTABLE_BASE_PROPERTIES,...Ct.INMUTABLE_BASE_PROPERTIES]),I(Ct,"MUTABLE_META_PROPERTIES",[...Ct.MUTABLE_BASE_PROPERTIES,"x","y"]),I(Ct,"INMUTABLE_META_PROPERTIES",[...Ct.INMUTABLE_BASE_PROPERTIES]),I(Ct,"META_PROPERTIES",[...Ct.MUTABLE_META_PROPERTIES,...Ct.INMUTABLE_META_PROPERTIES]),I(Ct,"MUTABLE_UPSTREAM_PROPERTIES",[]),I(Ct,"INMUTABLE_UPSTREAM_PROPERTIES",["primitives","builtInBaseEntities","operationDeclarations","globalEventActionDescriptors","loopDeclarations","builtInInstances"]),I(Ct,"UPSTREAM_PROPERTIES",[...Ct.MUTABLE_UPSTREAM_PROPERTIES,...Ct.INMUTABLE_UPSTREAM_PROPERTIES]),I(Ct,"MUTABLE_DOWNSTREAM_PROPERTIES",["entities","projects","functions","events","variableDeclarations","variableInstances","conditions","operations","functionCalls","loops","searches"]),I(Ct,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),I(Ct,"DOWNSTREAM_PROPERTIES",[...Ct.MUTABLE_DOWNSTREAM_PROPERTIES,...Ct.INMUTABLE_DOWNSTREAM_PROPERTIES]),I(Ct,"PROPERTIES",[...Ct.META_PROPERTIES,...Ct.UPSTREAM_PROPERTIES,...Ct.DOWNSTREAM_PROPERTIES]);let x=Ct;class m1i extends Li{constructor(p){super(FT,p)}}class T1i extends Li{constructor(i){super(rh,i);I(this,"autoexecutable",!0)}getEntityToMatchInputMap(i){return i.inputs.find(n=>{var s;return((s=n.declaration)==null?void 0:s.id)===Q.operation[Ce.Validate].inputs.entityToMatch.id})||null}getDataToValidateInputMap(i){return i.inputs.find(n=>{var s;return((s=n.declaration)==null?void 0:s.id)===Q.operation[Ce.Validate].inputs.dataToValidate.id})||null}getOutputDataOutputMap(i){return i.outputs.find(n=>{var s;return((s=n.declaration)==null?void 0:s.id)===Q.operation[Ce.Validate].dataType.entity.properties.outputEntity.id})||null}getEntityToMatch(i,n=this.project.addChangeSet(new Z(this.project,x.sessionAuthor,M().toISOString(),this,!0,"get-entity-to-match-validate-data"))){var e;const s=((e=this.project.requestActiveDynamicValue(i))==null?void 0:e.value)||null,c=s==null?void 0:s.valueAsTypeSingle;return n==null||n.attemptAutoclose("get-entity-to-match-validate-data",this.id),c}syncOperationInstance(i,n=this.project.addChangeSet(new Z(this.project,x.sessionAuthor,M().toISOString(),this,!0,"sync-operation-instance-validate-data"))){const s=[],c=[],e=[],y=[],m=this.getEntityToMatchInputMap(i);if(m){const{added:b,updated:w,removed:P,affected:$}=this.syncEntityToMatchInputMapDataType(m,n);s.push(...w),c.push(...b),e.push(...P),y.push(...$)}const v=this.getDataToValidateInputMap(i);if(v){const{added:b,updated:w,removed:P,affected:$}=this.syncDataToValidateInputMapDataType(v,n);s.push(...w),c.push(...b),e.push(...P),y.push(...$)}const E=this.getOutputDataOutputMap(i);if(E){const{added:b,updated:w,removed:P,affected:$}=this.syncOutputDataOutputMapDataType(E,n);s.push(...w),c.push(...b),e.push(...P),y.push(...$)}return n==null||n.attemptAutoclose("sync-operation-instance-validate-data",this.id),{updated:D(s),added:D(c),removed:D(e),affected:D(y),self:i}}syncEntityToMatchInputMapDataType(i,n=this.project.addChangeSet(new Z(this.project,x.sessionAuthor,M().toISOString(),this,!0,"sync-entity-to-match-input-map-data-type"))){var E,b,w,P,$,L,j,F,q,X,ne,ee,pe,oe,ce,Te,de,ye;const s=[],c=[],e=[],y=[];if(((E=i.declaration)==null?void 0:E.id)!==Q.operation[Ce.Validate].inputs.entityToMatch.id)return n==null||n.attemptAutoclose("sync-entity-to-match-input-map-data-type",this.id),{updated:[],added:[],removed:[],affected:[],self:null};const m=((b=this.project.requestActiveDynamicValue(i))==null?void 0:b.value)||null,v=m==null?void 0:m.valueAsTypeSingle;if(!i.dataType){const _e={id:x.UUID.uuid(),version:x.UUID.uuid(),createdAt:(n==null?void 0:n.timestamp)||new Date().toISOString(),author:(n==null?void 0:n.author)||x.sessionAuthor,previousVersion:null,deleted:!1,deletable:!0,editable:!0,type:d.DataType,parentRelationType:null,options:((w=i.declaration.dataType)==null?void 0:w.options)||null,implementationChooseOne:((P=i.declaration.dataType)==null?void 0:P.implementationChooseOne)||!1,staticEntities:(($=i.declaration.dataType)==null?void 0:$.staticEntities)??null,interactiveEntities:((L=i.declaration.dataType)==null?void 0:L.interactiveEntities)??null,actionEntities:((j=i.declaration.dataType)==null?void 0:j.actionEntities)??null,index:((F=i.declaration.dataType)==null?void 0:F.index)??null,isList:((q=i.declaration.dataType)==null?void 0:q.isList)||!1,foreignKeyAllowed:((X=i.declaration.dataType)==null?void 0:X.foreignKeyAllowed)??null,andChildrenGroup:null,orChildrenGroup:null,foreignKeyRef:null,asType:!0,entity:(v==null?void 0:v.toJSON())||null,like:!0,inferred:!0,parent:i.toReference()},Pe=he(_e,i.project);Pe.hydrateAncestors(),Pe.setParent(i,n),Pe.initChildren(n),Pe.setEntity(v,n),n==null||n.add(Pe,H.Added),s.push(Pe),i.setDataType(Pe,n)}return(de=i.dataType)==null||de.metaSync({inferred:!0,like:!1,asType:!0,options:((ne=i.declaration.dataType)==null?void 0:ne.options)||null,implementationChooseOne:((ee=i.declaration.dataType)==null?void 0:ee.implementationChooseOne)||!1,staticEntities:((pe=i.declaration.dataType)==null?void 0:pe.staticEntities)??null,interactiveEntities:((oe=i.declaration.dataType)==null?void 0:oe.interactiveEntities)??null,actionEntities:((ce=i.declaration.dataType)==null?void 0:ce.actionEntities)??null,isList:((Te=i.declaration.dataType)==null?void 0:Te.isList)||!1},n),(ye=i.dataType)==null||ye.setEntity(v,n),i.dataType&&c.push(i.dataType),n==null||n.attemptAutoclose("sync-entity-to-match-input-map-data-type",this.id),{updated:D(c),added:D(s),removed:D(e),affected:D(y),self:i.dataType}}syncDataToValidateInputMapDataType(i,n=this.project.addChangeSet(new Z(this.project,x.sessionAuthor,M().toISOString(),this,!0,"sync-data-to-validate-input-map-data-type"))){var b,w,P;const s=[],c=[],e=[],y=[];if(((b=i.declaration)==null?void 0:b.id)!==Q.operation[Ce.Validate].inputs.dataToValidate.id)return n==null||n.attemptAutoclose("sync-data-to-validate-input-map-data-type",this.id),{updated:[],added:[],removed:[],affected:[],self:null};const m=this.getEntityToMatchInputMap(i.parent);if(!m)return n==null||n.attemptAutoclose("sync-data-to-validate-input-map-data-type",this.id),{updated:[],added:[],removed:[],affected:[],self:null};if(!this.getEntityToMatch(m,n))return n==null||n.attemptAutoclose("sync-data-to-validate-input-map-data-type",this.id),{updated:[],added:[],removed:[],affected:[],self:null};if(!i.dataType){const $={id:x.UUID.uuid(),version:x.UUID.uuid(),createdAt:(n==null?void 0:n.timestamp)||new Date().toISOString(),author:(n==null?void 0:n.author)||x.sessionAuthor,previousVersion:null,deleted:!1,deletable:!0,editable:!0,type:d.DataType,index:null,parentRelationType:null,options:null,implementationChooseOne:!1,foreignKeyAllowed:null,isList:!1,foreignKeyRef:null,andChildrenGroup:null,orChildrenGroup:null,staticEntities:null,interactiveEntities:null,actionEntities:null,asType:!1,entity:null,like:!0,inferred:!0,parent:i.toReference()},L=he($,i.project);L.setParent(i,n),L.initChildren(n),n==null||n.add(L,H.Added),s.push(L),i.setDataType(L,n)}(w=i.dataType)==null||w.metaSync({inferred:!0,like:!0,asType:!1},n);const E=this.getEntityToMatch(m,n);return(P=i.dataType)==null||P.setEntity(E,n),i.dataType&&c.push(i.dataType),n==null||n.attemptAutoclose("sync-data-to-validate-input-map-data-type",this.id),{updated:D(c),added:D(s),removed:D(e),affected:D(y),self:i.dataType}}syncOutputDataOutputMapDataType(i,n=this.project.addChangeSet(new Z(this.project,x.sessionAuthor,M().toISOString(),this,!0,"sync-output-data-output-map-data-type"))){var w,P,$,L;const s=[],c=[],e=[],y=[];if(((w=i.declaration)==null?void 0:w.id)!==Q.operation[Ce.Validate].dataType.entity.properties.outputEntity.id)return n==null||n.attemptAutoclose("sync-output-data-output-map-data-type",this.id),{updated:[],added:[],removed:[],affected:[],self:null};const m=this.getEntityToMatchInputMap(i.parent);if(!m)return n==null||n.attemptAutoclose("sync-output-data-output-map-data-type",this.id),{updated:[],added:[],removed:[],affected:[],self:null};if(!this.getEntityToMatch(m,n))return n==null||n.attemptAutoclose("sync-output-data-output-map-data-type",this.id),{updated:[],added:[],removed:[],affected:[],self:null};const E=((P=this.project.requestActiveDynamicValue(m))==null?void 0:P.value)||null,b=(E==null?void 0:E.valueAsTypeSingle)||null;if(!i.dataType){const j={id:x.UUID.uuid(),version:x.UUID.uuid(),createdAt:(n==null?void 0:n.timestamp)||new Date().toISOString(),author:(n==null?void 0:n.author)||x.sessionAuthor,previousVersion:null,deleted:!1,deletable:!0,editable:!0,type:d.DataType,parentRelationType:null,options:null,foreignKeyRef:null,implementationChooseOne:!1,foreignKeyAllowed:null,staticEntities:null,interactiveEntities:null,index:null,actionEntities:null,isList:!1,andChildrenGroup:null,orChildrenGroup:null,asType:!1,entity:(b==null?void 0:b.toJSON())||null,like:!0,inferred:!0,parent:i.toReference()},F=he(j,i.project);F.hydrateAncestors(),F.setParent(i,n),F.initChildren(n),F.setEntity(b,n),n==null||n.add(F,H.Added),s.push(F),i.setDataType(F,n)}return($=i.dataType)==null||$.metaSync({inferred:!0,like:!0,asType:!1},n),(L=i.dataType)==null||L.setEntity(b,n),i.dataType&&c.push(i.dataType),n==null||n.attemptAutoclose("sync-output-data-output-map-data-type",this.id),{updated:D(c),added:D(s),removed:D(e),affected:D(y),self:i.dataType}}inferInputMapDataType(i,n=this.project.addChangeSet(new Z(this.project,x.sessionAuthor,M().toISOString(),this,!0,"infer-input-map-data-type-validate-data"))){var c,e,y;if(((c=i.declaration)==null?void 0:c.id)===Q.operation[Ce.Validate].inputs.entityToMatch.id){const{added:m,updated:v,removed:E,affected:b}=this.syncEntityToMatchInputMapDataType(i,n);return n==null||n.attemptAutoclose("infer-input-map-data-type",this.id),{updated:D(v),added:D(m),removed:D(E),affected:D(b),self:i.dataType}}if(((e=i.declaration)==null?void 0:e.id)===Q.operation[Ce.Validate].inputs.dataToValidate.id){const{added:m,updated:v,removed:E,affected:b}=this.syncDataToValidateInputMapDataType(i,n);return n==null||n.attemptAutoclose("infer-input-map-data-type",this.id),{updated:D(v),added:D(m),removed:D(E),affected:D(b),self:i.dataType}}const s=(y=i.declaration)==null?void 0:y.getDataType(n);if(s&&s.isResolved)return n==null||n.attemptAutoclose("infer-input-map-data-type-validate-data",this.id),{updated:[],added:[],removed:[],affected:[],self:s};if(i.readsValue){const m=hd(i.readsValue,n);return n==null||n.attemptAutoclose("infer-input-map-data-type-validate-data",this.id),{updated:[],added:[],removed:[],affected:[],self:m}}return n==null||n.attemptAutoclose("infer-input-map-data-type-validate-data",this.id),{updated:[],added:[],removed:[],affected:[],self:null}}inferOutputMapDataType(i,n=this.project.addChangeSet(new Z(this.project,x.sessionAuthor,M().toISOString(),this,!0,"infer-output-map-data-type-validate-data"))){var s;if(((s=i.declaration)==null?void 0:s.id)===Q.operation[Ce.Validate].dataType.entity.properties.outputEntity.id){const{added:c,updated:e,removed:y,affected:m}=this.syncOutputDataOutputMapDataType(i,n);return n==null||n.attemptAutoclose("infer-output-map-data-type-validate-data",this.id),{updated:D(e),added:D(c),removed:D(y),affected:D(m),self:i.dataType}}return{updated:[],added:[],removed:[],affected:[],self:null}}}class v1i extends Li{constructor(p){super(o_,p)}}class E1i extends Li{constructor(p){super(d_,p)}}class b1i extends Li{constructor(p){super(u_,p)}}class A1i extends Li{constructor(p){super(Ag,p)}}class g1i extends Li{constructor(p){super(jA,p)}}class I1i extends Li{constructor(p){super(nT,p)}}function rGe(o){const p=[new IOe(o),new AOe(o),new gOe(o),new m1i(o),new T1i(o),new A1i(o),new v1i(o),new b1i(o),new E1i(o),new g1i(o),new I1i(o)];return LP.forEach(i=>{p.some(n=>n.id===i.id)||p.push(new Li(i,o))}),p.forEach(i=>{i.initChildren(null),o.subscribeBuiltInInstance(i)}),o.operationDeclarations=p,p}class R1i extends No{constructor(i){super(In,i);I(this,"initialData");I(this,"id",Re.PERSISTED_ENTITY);I(this,"version","1");I(this,"name",Re.PERSISTED_ENTITY);I(this,"description",In.description);I(this,"type",d.BuiltInBaseEntity);I(this,"abstract",In.abstract);I(this,"static",In.static);I(this,"properties",[]);I(this,"methods",[]);I(this,"abstractMethods",[]);I(this,"extends",null);I(this,"errors",[]);I(this,"project");this.initialData=In,this.project=i,this.id=In.id,this.version=In.version,this.name=In.name,this.static=In.static,this.abstract=In.abstract,this.properties=this.initialData.properties.map(s=>{const c=he(s,this.project);return c.setParent(this,null),c.initChildren(null),c}),this.methods=this.initialData.methods.map(s=>{const c=he(s,this.project);return c.parent=this,c}),this.abstractMethods=this.initialData.abstractMethods.map(s=>{const c=he(s,this.project);return c.parent=this,c}),this.initialData.extends&&(this.extends=he(this.initialData.extends,this.project));const n=this.properties.find(s=>s.id===Q["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.identifier.id);if(!n)throw new Error("Path property not found in endpoint entity");n._codeNativeValueValidation=(s,c)=>vOe(s,c)}}const D1i=[];function nGe(o){const p=[new TOe(o),new bOe(o),new R1i(o)];return lV.forEach(i=>{!p.some(n=>n.id===i.id)&&!D1i.includes(i.id)&&p.push(new No(i,o))}),p.forEach(i=>{o.subscribeBuiltInInstance(i)}),o.builtInBaseEntities=p,p}function aGe(o){const p=[new ma(ue,o),new ma(st,o),new ma(we,o),new ma(ba,o),new ma(ht,o),new ma(It,o),new ma(at,o),new ma(Rl,o),new ma(Hi,o)];return p.forEach(i=>{o.subscribeBuiltInInstance(i)}),o.primitives=p,p}function sGe(o){const p=[new Li(MI,o)];return p.forEach(i=>{i.initChildren(null),o.subscribeBuiltInInstance(i)}),o.globalEventActionDescriptors=p,p}function lGe(o){const p=[new Li(ev,o),new Li(Jc,o),new Li(XT,o),new Li(wh,o),new Li(Oh,o),new Li(TI,o)];p.forEach(n=>{n.initChildren(null),o.subscribeBuiltInInstance(n)}),o.loopDeclarations=p;const i=[new Li(OI,o),new Li(QT,o),new Li(AI,o),new Li(UP,o),new Li(SP,o),new Li(vI,o)];return i.forEach(n=>{n.initChildren(null),o.subscribeBuiltInInstance(n)}),o.loopDeclarationsBodies=i,p}function oGe(o){const p=[new Ad(yV,o)];return p.forEach(i=>{i.initChildren(null),o.subscribeBuiltInInstance(i)}),o.valueDescriptors=p,p}function dGe(o){const p=[new Li(dV,o),new Li(oV,o),new Li(uV,o),new Li(pV,o)];return cV.forEach(i=>{p.some(n=>n.id===i.id)||p.push(new Li(i,o))}),p.forEach(i=>{i.initChildren(null),o.subscribeBuiltInInstance(i)}),o.conditionDeclarations=p,p}function Nm(o){return o&&typeof o.then=="function"}function w1i(o,p){const i=new Nn(o[0],{allBuiltInEntityIds:p.allBuiltInEntityIds}),n=o.map(c=>c.id),s={};return o.forEach(c=>{s[c.id]=c}),i.order=n,i.flatRecord=s,i.orderEntities(),i.order.map(c=>i.flatRecord[c])}function O1i(o,p){const i=new Nn(Object.values(o)[0],{allBuiltInEntityIds:p.allBuiltInEntityIds}),n=Object.keys(o);return i.order=n,i.flatRecord=o,i.orderEntities(),i.order}async function C1i(o,p){const i=J.YieldTracker.from(p),n=new Nn(o[0],{allBuiltInEntityIds:p.allBuiltInEntityIds}),s=o.map(e=>e.id),c={};for(const e of o)c[e.id]=e,await i.tick();return n.order=s,n.flatRecord=c,await n.orderEntitiesAsync({tracker:i}),n.order.map(e=>n.flatRecord[e])}async function _1i(o,p){const i=J.YieldTracker.from(p),n=new Nn(Object.values(o)[0],{allBuiltInEntityIds:p.allBuiltInEntityIds}),s=Object.keys(o);return n.order=s,n.flatRecord=o,await n.orderEntitiesAsync({tracker:i}),n.order}class Nn{constructor(p,i={}){I(this,"order",[]);I(this,"flatRecord",{});I(this,"allBuiltInEntityIds");I(this,"onGoingVisits",{});I(this,"cachedReferences",{});if(i.allBuiltInEntityIds&&(this.allBuiltInEntityIds=i.allBuiltInEntityIds),!p)return;const n={asyncInitialOrder:!1,...i};n.asyncInitialOrder?this.flattenAsync(p).then(()=>{this.orderEntitiesAsync({...n}).then(()=>{var s;(s=n.onOrdered)==null||s.call(n)})}):(this.flatten(p),this.orderEntities())}flatten(p){this.allBuiltInEntityIds||(this.allBuiltInEntityIds=new Set(DR()));const i=D(Le(p,new Set(this.allBuiltInEntityIds),{ignoreBuiltInBaseEntities:!0,diggestedBuiltInBaseEntitiesIds:this.allBuiltInEntityIds})),n=new Set;for(const s of i)this.flatRecord[s.id]=s,n.add(s.id);this.order=Array.from(n)}async flattenAsync(p,i={}){const n=J.YieldTracker.from(i);this.allBuiltInEntityIds||(this.allBuiltInEntityIds=await wR({tracker:n}));const s=await wu(await $e(p,new Set(this.allBuiltInEntityIds),{ignoreBuiltInBaseEntities:!0,diggestedBuiltInBaseEntitiesIds:this.allBuiltInEntityIds,tracker:n}),{tracker:n}),c=new Set;for(const e of s)this.flatRecord[e.id]=e,c.add(e.id),await n.tick();this.order=Array.from(c)}moveEntityAfterDependencies(p){const i=this.cachedReferences[p.id]||md(p,this.flatRecord,{ignoreBuiltInBaseEntities:!0,allBuiltInEntityIds:this.allBuiltInEntityIds});this.cachedReferences[p.id]=i;const{upstream:n}=i;for(const s of Object.keys(n)){const c=this.order.indexOf(s),e=this.order.indexOf(p.id);if(c>e)return this.order.splice(e,1),this.order.splice(c,0,p.id),!0}return!1}orderEntities(){let p=!1;for(let i=0;i<this.order.length;i++){const n=this.order[i],s=this.flatRecord[n];if(s||J.Logger.warn(`Entity with id ${n} not found in flatRecord. Skipping...`),this.moveEntityAfterDependencies(s)){p=!0;break}}p&&this.orderEntities()}async orderEntitiesAsync(p={}){let i=!1;const n=J.YieldTracker.from(p);for(let s=0;s<this.order.length;s++){const c=this.order[s],e=this.flatRecord[c];if(e||J.Logger.warn(`Entity with id ${c} not found in flatRecord. Skipping...`),this.moveEntityAfterDependencies(e)){i=!0;break}await n.tick()}i&&await this.orderEntitiesAsync({tracker:n})}getUpstreamOngoingDependenciesVisits(p,i){const n=this.cachedReferences[p]||md(this.flatRecord[p],this.flatRecord,{ignoreBuiltInBaseEntities:!0,allBuiltInEntityIds:this.allBuiltInEntityIds});this.cachedReferences[p]=n;const{upstream:s}=n,c={};return Object.entries(this.onGoingVisits[i]||{}).forEach(([e,y])=>{Object.keys(s).includes(e)&&(c[e]=y)}),c}getDownstreamOngoingDependenciesVisits(p,i){const n=Object.keys(this.onGoingVisits[i]||{}),s=new Set(n.flatMap(e=>{const y=this.cachedReferences[e]||md(this.flatRecord[e],this.flatRecord,{ignoreBuiltInBaseEntities:!0,allBuiltInEntityIds:this.allBuiltInEntityIds});return this.cachedReferences[e]=y,Object.keys(y.downstream)})),c={};return Array.from(s).forEach(e=>{e===p&&(c[e]=this.onGoingVisits[i][e])}),c}async settlePromises(p,i){const n=Object.values(p);n.length&&await Promise.all(n),Object.keys(p).forEach(s=>{delete this.onGoingVisits[i][s]})}visit(p){const i=this.order;for(const n of i)p(this.flatRecord[n],this.flatRecord);return this}reverseVisit(p){const i=this.order.slice().reverse();for(const n of i)p(this.flatRecord[n],this.flatRecord);return this}async visitAsync(p,i={}){const{parallelise:n}={parallelise:!0,...i},s=J.YieldTracker.from(i),c=this.order;if(!n){for(const y of c){const m=p(this.flatRecord[y],this.flatRecord);Nm(m)&&await m,await s.tick()}return this}const e=Math.random().toString(36).substring(7);this.onGoingVisits[e]={};for(const y of c){const m=this.getUpstreamOngoingDependenciesVisits(y,e);Object.keys(m).length&&await this.settlePromises(m,e);const v=p(this.flatRecord[y],this.flatRecord);Nm(v)&&(this.onGoingVisits[e][y]=v),await s.tick()}return await this.settlePromises(this.onGoingVisits[e],e),this.onGoingVisits[e]={},this}async reverseVisitAsync(p,i={}){const{parallelise:n}={parallelise:!0,...i},s=J.YieldTracker.from(i),c=this.order.slice().reverse();if(!n){for(const y of c){const m=p(this.flatRecord[y],this.flatRecord);Nm(m)&&await m,await s.tick()}return this}const e=Math.random().toString(36).substring(7);this.onGoingVisits[e]={};for(const y of c){const m=this.getDownstreamOngoingDependenciesVisits(y,e);Object.keys(m).length&&await this.settlePromises(m,e);const v=p(this.flatRecord[y],this.flatRecord);Nm(v)&&(this.onGoingVisits[e][y]=v),await s.tick()}return await this.settlePromises(this.onGoingVisits[e],e),this.onGoingVisits[e]={},this}}const bc={},$b={},Jm={empty:!1,enrich:!0,mock:!1,ignoreCache:!1,onFetch:async()=>null,manuallyInit:!1};function uGe(o,p={enrich:!0,shallowErrors:!1},i){const n={enrich:!0,shallowErrors:!1,...p},{enrich:s,shallowErrors:c}=n,e=o.project,y=o.record,m=IR(o.project,{shallowErrors:c},i);m.instances[e.id]=m;const v=new Nn(e,{allBuiltInEntityIds:m.diggestedBuiltInBaseEntitiesIds}),E=new Set;y[e.id]=e,E.add(e.id);const b=M().toISOString();Object.values(y).forEach(P=>{!P||v.allBuiltInEntityIds.has(P.id)||E.add(P.id)}),v.order=Array.from(E),v.flatRecord=y,v.orderEntities();const w=s?m.addChangeSet(new Z(m,x.sessionAuthor,b,m,!0,"project-init-from-fetch-result")):null;return v.visit(P=>{if(P.id===m.id)return;const $=he(P,m);try{$.hydrateAncestors(),$.addSelfToProject(null);const L=md(P);Object.keys(L.downstream).forEach(j=>{const F=m.get(j);F&&F.hydrateAncestors()})}catch(L){if(c)J.Logger.error("Error hydrating ancestors: ",L);else throw L}}),s?(v.visit(P=>{if(P.id===m.id)return;const $=m.get(P.id);$&&$.afterAllChildrenInitialized(w)}),m.afterAllChildrenInitialized(w)):sf(m,b).forEach($=>{$.remove({ignoreUpstream:!0},null)}),m.instancesList.forEach(P=>{P.previousVersion=null}),m.initialized=!0,m.emit(zt.PROJECT_INITIALIZED,m,w),w==null||w.attemptAutoclose("project-init-from-fetch-result",m.id),m}async function P1i(o,p={enrich:!0,shallowErrors:!1,yieldEvery:100},i){const n={enrich:!0,shallowErrors:!1,yieldEvery:100,...p},{enrich:s,shallowErrors:c,yieldEvery:e}=n,y=o.project,m=o.record,v=await RR(o.project,{shallowErrors:c,yieldEvery:e},i);v.instances[y.id]=v;const E=new Nn(void 0,{allBuiltInEntityIds:v.diggestedBuiltInBaseEntitiesIds});await E.flattenAsync(y,{yieldEvery:e}),await E.orderEntitiesAsync({yieldEvery:e});const b=new Set;m[y.id]=y,b.add(y.id);const w=M().toISOString();let P=0;for(const[j,F]of Object.entries(m))!F||E.allBuiltInEntityIds.has(F.id)||(b.add(F.id),++P%e===0&&await J.yieldToEventLoop());E.order=Array.from(b),E.flatRecord=m,await E.orderEntitiesAsync();const $=s?v.addChangeSet(new Z(v,x.sessionAuthor,w,v,!0,"project-init-from-fetch-result")):null;await E.visitAsync(j=>{if(j.id===v.id)return;const F=he(j,v);try{F.hydrateAncestors(),F.addSelfToProject(null);const q=md(j);Object.keys(q.downstream).forEach(X=>{const ne=v.get(X);ne&&ne.hydrateAncestors()})}catch(q){if(c)J.Logger.error("Error hydrating ancestors: ",q);else throw console.log("Error hydrating ancestors: ",q),q}},{yieldEvery:e}),s?(await E.visitAsync(j=>{if(j.id===v.id)return;const F=v.get(j.id);F&&F.afterAllChildrenInitialized($)},{yieldEvery:e}),v.afterAllChildrenInitialized($)):sf(v,w).forEach(F=>{F.remove({ignoreUpstream:!0},null)});let L=0;for(const j of v.instancesList)j.previousVersion=null,++L%e===0&&await J.yieldToEventLoop();return v.initialized=!0,v.emit(zt.PROJECT_INITIALIZED,v,$),$==null||$.attemptAutoclose("project-init-from-fetch-result",v.id),v}async function V1i(o,p=Jm){const i={...Jm,...p};if(i.empty)return{data:{project:{id:o.id,deletable:!0,editable:!0,type:d.Project,version:x.UUID.uuid(),createdAt:M().toISOString(),author:x.sessionAuthor,previousVersion:null,deleted:!1,name:null,description:null,projects:[],entities:[],operations:[],functions:[],variableDeclarations:[],variableInstances:[],functionCalls:[],conditions:[],loops:[],searches:[],events:[]},record:{}}};if(i.mock){const s={...Zx};return s.id=o.id,{data:{project:s,record:{}}}}return J.Logger.log("Fetching project from external API"),new Promise(async s=>{try{if(i.onFetch){const c=await i.onFetch(o.id);if(c){s({data:c});return}}else s({data:null})}catch(c){J.Logger.error("Error fetching project: ",c),s({data:null})}})}function IR(o,p={shallowErrors:!1},i){const n=new x(o,i);aGe(n),nGe(n),rGe(n),sGe(n),lGe(n),oGe(n),dGe(n);const s=p.allBuiltInIds??new Set([...n.getAllBuiltInIds(),...DR()]);return n.diggestedBuiltInBaseEntitiesIds=s,s.forEach(c=>{if(!n.builtInInstances[c]&&n.instances[c])n.builtInInstances[c]=n.instances[c],delete n.instances[c];else if(!n.builtInInstances[c]&&!p.shallowErrors)throw new Error(`Built in entity was not properly initialized: ${c}`)}),n.instances[n.id]=n,n}async function RR(o,p={shallowErrors:!1},i){const n=J.YieldTracker.from(p),s=new x(o,i);aGe(s),nGe(s),await J.yieldToEventLoop(),rGe(s),await J.yieldToEventLoop(),sGe(s),lGe(s),oGe(s),dGe(s),await J.yieldToEventLoop();const c=p.allBuiltInIds??new Set([...s.getAllBuiltInIds(),...await wR()]);s.diggestedBuiltInBaseEntitiesIds=c;for(const e of c){if(!s.builtInInstances[e]&&s.instances[e])s.builtInInstances[e]=s.instances[e],delete s.instances[e];else if(!s.builtInInstances[e]&&!p.shallowErrors)throw new Error(`Built in entity was not properly initialized: ${e}`);s.instances[e]&&delete s.instances[e],await n.tick()}return s.instances[s.id]=s,s}function sf(o,p){return o.instancesList.filter(n=>M(n.createdAt).isAfter(M(p)||!!n.previousVersion))}function N1i(o,{enrich:p,shallowErrors:i,...n}={enrich:!0,shallowErrors:!1},s){var P,$;const c=new Map,e=new Map;Object.keys(o.instances).forEach(L=>{if(o.diggestedBuiltInBaseEntitiesIds.has(L)){c.set(L,L),e.set(L,L);return}const j=o.get(L);if(!ox(j,{...o.instances,...o.builtInInstances}).every(ne=>!o.diggestedBuiltInBaseEntitiesIds.has(ne))){c.set(L,L),e.set(L,L);return}const X=x.UUID.uuid();c.set(L,X),e.set(X,L)});const y=((P=n.resetVersionOptions)==null?void 0:P.commonTimestamp)??M().toISOString(),m=o.toShallowJSON({seenEntityMaps:c});m.previousVersion=null,m.createdAt=y,m.version=x.UUID.uuid(),m.author=(($=n.resetVersionOptions)==null?void 0:$.author)??(x.sessionAuthor||"1");const v=IR(m,{shallowErrors:i,allBuiltInIds:o.diggestedBuiltInBaseEntitiesIds},s);v.instances[v.id]=v;const E=p?v.addChangeSet(new Z(v,x.sessionAuthor,y,v,!0,"project-clone")):null,b=new Nn(o,{allBuiltInEntityIds:o.diggestedBuiltInBaseEntitiesIds}),w=L4e(b.flatRecord,c);return b.visit(L=>{var X;const j=L.toShallowJSON({seenEntityMaps:c});j.previousVersion=null,j.createdAt=y,j.version=x.UUID.uuid(),j.author=((X=n.resetVersionOptions)==null?void 0:X.author)??(x.sessionAuthor||"1");const F=md(j,w);if(Object.keys(F.upstream).length){let ne=!1;if(Object.keys(F.upstream).forEach(ee=>{if(!ne&&(!v.get(ee)||v.getDeleted(ee))){ne=!0;return}}),ne)return}const q=he(j,v);q.hydrateAncestors(),q.addSelfToProject(E),E==null||E.add(q,H.Added),n.onVisit&&n.onVisit(j)}),p?(b.visit(L=>{if(L.id===v.id)return;const j=v.get(c.get(L.id));j&&j.afterAllChildrenInitialized(E)}),v.afterAllChildrenInitialized(E)):sf(v,y).forEach(j=>{j.remove({ignoreUpstream:!0},null)}),v.instancesList.forEach(L=>{L.previousVersion=null}),E==null||E.attemptAutoclose("project-clone",v.id),{project:v,maps:c}}async function x1i(o,{shallowErrors:p,...i}={shallowErrors:!1,yieldEvery:100}){var v,E;const n=J.YieldTracker.from(i),s=new Map,c=new Map;Object.keys(o.instances).forEach(b=>{if(o.diggestedBuiltInBaseEntitiesIds.has(b)){s.set(b,b),c.set(b,b);return}const w=x.UUID.uuid();s.set(b,w),c.set(w,b)});const e=((v=i.resetVersionOptions)==null?void 0:v.commonTimestamp)??M().toISOString(),y=o.toShallowJSON({seenEntityMaps:s});y.previousVersion=null,y.createdAt=e,y.version=x.UUID.uuid(),y.author=((E=i.resetVersionOptions)==null?void 0:E.author)??(x.sessionAuthor||"1");const m=await o.toFullProjectTransferAsync({tracker:n,seenEntityMaps:s,resetVersionOptions:i.resetVersionOptions,onVisit:i.onVisit});return{project:y,record:m.record,order:m.order,maps:s}}async function $1i(o,{enrich:p,shallowErrors:i,...n}={enrich:!0,shallowErrors:!1,yieldEvery:100},s){var $,L;const c=J.YieldTracker.from(n),e=new Map,y=new Map;Object.keys(o.instances).forEach(j=>{if(o.diggestedBuiltInBaseEntitiesIds.has(j)){e.set(j,j),y.set(j,j);return}const F=x.UUID.uuid();e.set(j,F),y.set(F,j)});const m=(($=n.resetVersionOptions)==null?void 0:$.commonTimestamp)??M().toISOString(),v=o.toShallowJSON({seenEntityMaps:e});v.previousVersion=null,v.createdAt=m,v.version=x.UUID.uuid(),v.author=((L=n.resetVersionOptions)==null?void 0:L.author)??(x.sessionAuthor||"1");const E=await RR(v,{shallowErrors:i,tracker:c},s);E.diggestedBuiltInBaseEntitiesIds=o.diggestedBuiltInBaseEntitiesIds,E.instances[E.id]=E;const b=p?E.addChangeSet(new Z(E,x.sessionAuthor,m,E,!0,"project-clone")):null,w=new Nn(void 0,{allBuiltInEntityIds:o.diggestedBuiltInBaseEntitiesIds}),P=await o.toFullProjectTransferAsync({tracker:c,seenEntityMaps:e,resetVersionOptions:n.resetVersionOptions,onVisit:n.onVisit});w.flatRecord=P.record,w.order=P.order,await w.visitAsync(j=>{var ne;if(o.diggestedBuiltInBaseEntitiesIds.has(j.id))return;const F=j;F.previousVersion=null,F.createdAt=m,F.version=x.UUID.uuid(),F.author=((ne=n.resetVersionOptions)==null?void 0:ne.author)??(x.sessionAuthor||"1");const q=md(F,w.flatRecord);if(Object.keys(q.upstream).length){let ee=!1;if(Object.keys(q.upstream).forEach(pe=>{if(!ee&&(!E.get(pe)||E.getDeleted(pe))){ee=!0;return}}),ee)return}const X=he(F,E);X.hydrateAncestors(),X.addSelfToProject(b),b==null||b.add(X,H.Added)},{tracker:c}),p?(await w.visitAsync(j=>{if(j.id===E.id||o.diggestedBuiltInBaseEntitiesIds.has(j.id))return;const F=E.get(e.get(j.id));F&&F.afterAllChildrenInitialized(b)},{tracker:c}),E.afterAllChildrenInitialized(b)):sf(E,m).forEach(F=>{F.remove({ignoreUpstream:!0},null)});for(const j of E.instancesList)j.previousVersion=null,await c.tick();return b==null||b.attemptAutoclose("project-clone",E.id),{project:E,maps:e}}function pGe(o,{enrich:p,shallowErrors:i}={enrich:!0,shallowErrors:!1},n){const s=IR(o,{shallowErrors:i},n),c=M().toISOString(),e=p?s.addChangeSet(new Z(s,x.sessionAuthor,c,s,!0,"project-init")):null;e&&(e.type=kI.Automatic);const y=new Nn(o,{allBuiltInEntityIds:s.diggestedBuiltInBaseEntitiesIds});return y.visit(m=>{const v=he(m,s);v.hydrateAncestors(),v.addSelfToProject(e)}),p?(y.visit(m=>{if(m.id===s.id)return;const v=s.get(m.id);v&&v.afterAllChildrenInitialized(e)}),s.afterAllChildrenInitialized(e)):(sf(s,c).forEach(E=>{E.remove({ignoreUpstream:!0},null)}),new Nn(s,{allBuiltInEntityIds:s.diggestedBuiltInBaseEntitiesIds}).visit(E=>{E.initialized=!0,E.captureVersion()})),s.initialized=!0,s.emit(zt.PROJECT_INITIALIZED,s,e),e==null||e.attemptAutoclose("project-init",s.id),s}async function L1i(o,{enrich:p,shallowErrors:i,yieldEvery:n}={enrich:!0,shallowErrors:!1,yieldEvery:100},s){const c=await RR(o,{shallowErrors:i,yieldEvery:n},s),e=M().toISOString(),y=p?c.addChangeSet(new Z(c,x.sessionAuthor,e,c,!0,"project-init")):null;y&&(y.type=kI.Automatic);const m=new Nn(void 0,{allBuiltInEntityIds:c.diggestedBuiltInBaseEntitiesIds});if(await m.flattenAsync(o,{yieldEvery:n}),await m.orderEntitiesAsync({yieldEvery:n}),await m.visitAsync(v=>{const E=he(v,c);E.hydrateAncestors(),E.addSelfToProject(y)},{yieldEvery:n}),p)await m.visitAsync(v=>{if(v.id===c.id)return;const E=c.get(v.id);E&&E.afterAllChildrenInitialized(y)},{yieldEvery:n}),c.afterAllChildrenInitialized(y);else{sf(c,e).forEach(b=>{b.remove({ignoreUpstream:!0},null)});const E=new Nn(void 0,{allBuiltInEntityIds:c.diggestedBuiltInBaseEntitiesIds});await E.flattenAsync(c,{yieldEvery:n}),await E.orderEntitiesAsync({yieldEvery:n}),await E.visitAsync(b=>{b.initialized=!0,b.captureVersion()},{yieldEvery:n})}return c.initialized=!0,c.emit(zt.PROJECT_INITIALIZED,c,y),y==null||y.attemptAutoclose("project-init",c.id),c}async function M1i(o,p=Jm,i){const n={...Jm,...p};if(o.id&&bc[o.id]&&!n.ignoreCache)return bc[o.id];if(o.id&&$b[o.id]&&!n.ignoreCache)return await $b[o.id],bc[o.id];const s=V1i(o,n);o.id&&($b[o.id]=s);const c=await s;if(c.data){let e;return n.mock?e=pGe(Zx,{enrich:!!n.enrich},i):c.data instanceof x?e=c.data:e=uGe(c.data,{enrich:!!n.enrich},i),bc[o.id]=e,o.id&&delete $b[o.id],e}return null}function B1i(o){return bc[o.id]&&delete bc[o.id],null}function zN(o){return o==null||o===""}function Pr(o){return o?o.valueAsType?!1:zN(o.value):!0}function cGe(o,p){if(o===p||!o&&!p)return!0;if(!o||!p||o.name===le.EntityTemplate&&p.name!==le.EntityTemplate||p.name===le.EntityTemplate&&o.name!==le.EntityTemplate)return!1;if(o.name===le.ActionDescriptor&&p.name!==le.ActionDescriptor||p.name===le.ActionDescriptor&&o.name!==le.ActionDescriptor)return!1;if(o.valueAsTypeSingle&&!p.valueAsTypeSingle||p.valueAsTypeSingle&&!o.valueAsTypeSingle)return!1;if(o.valueAsTypeList&&!p.valueAsTypeList||p.valueAsTypeList&&!o.valueAsTypeList)return!1;if(o.valueAsTypeSingle&&p.valueAsTypeSingle){if(o.valueAsTypeSingle.id!==p.valueAsTypeSingle.id)return!1}else if(o.valueAsTypeList&&p.valueAsTypeList){if(o.valueAsTypeList.length!==p.valueAsTypeList.length)return!1;for(let i=0;i<o.valueAsTypeList.length;i++)if(o.valueAsTypeList[i].id!==p.valueAsTypeList[i].id)return!1}else if(!o.valueAsType&&!p.valueAsType&&o.value!==p.value)return!1;return!0}function DR(){const o=new Set;return new Set(hV.flatMap(i=>Le(i,o)).map(i=>i.id))}function eo(o){return[...o.calledByEntry||[],...o.calledByError||[],...o.calledBySuccess||[]].filter(p=>p.type!==d.GenericReference)}function fGe(o,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(o.id))return[];if(p.add(o.id),o.type!==d.ActionDescriptor)throw new Error("Entity must be an action descriptor to be flattened");return[o,...o.inputs.flatMap(n=>Le(n,p,i)),...o.dataType?Le(o.dataType,p,i):[],...o.error?Le(o.error,p,i):[],...o.parent?Le(o.parent,p,i):[]]}function yGe(o,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(o.id))return[];if(p.add(o.id),o.type!==d.ArgumentDeclaration)throw new Error("Entity must be an argument declaration to be flattened");return[o,...o.defaultValue?Le(o.defaultValue,p):[],...o.writesValues.flatMap(n=>Le(n,p,i)),...o.implements.flatMap(n=>Le(n,p,i)),...o.dataType?Le(o.dataType,p,i):[],...o.parent?Le(o.parent,p,i):[]]}function hGe(o,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(o.id))return[];if(p.add(o.id),o.type!==d.BreakStatement)throw new Error("Entity must be a break statement to be flattened");return[o,...o.outputs.flatMap(n=>Le(n,p,i)),...o.throws?Le(o.throws,p,i):[],...o.dataType?Le(o.dataType,p,i):[],...o.readsValue?Le(o.readsValue,p,i):[],...(eo(o)||[]).flatMap(n=>Le(n,p,i)),...o.parent?Le(o.parent,p,i):[]]}function mGe(o,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(o.id))return[];if(p.add(o.id),o.type!==d.BuiltInBaseEntity)throw new Error("Entity must be a built-in base entity to be flattened");return[o,...(o.properties||[]).flatMap(n=>Le(n,p,i)),...(o.methods||[]).flatMap(n=>Le(n,p,i)),...(o.abstractMethods||[]).flatMap(n=>Le(n,p,i)),...o.allPropertiesImplement?Le(o.allPropertiesImplement,p,i):[],...o.additionalPropertiesDataType?Le(o.additionalPropertiesDataType,p,i):[],...o.extends?Le(o.extends,p,i):[]]}function TGe(o,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(o.id))return[];if(p.add(o.id),o.type!==d.Condition)throw new Error("Entity must be a condition to be flattened");return[o,...(o.andChildrenGroup||[]).flatMap(n=>Le(n,p,i)),...(o.orChildrenGroup||[]).flatMap(n=>Le(n,p,i)),...(o.inputs||[]).flatMap(n=>Le(n,p,i)),...(o.successCalls||[]).flatMap(n=>Le(n,p,i)),...(o.errorCalls||[]).flatMap(n=>Le(n,p,i)),...(eo(o)||[]).flatMap(n=>Le(n,p,i)),...o.parent?Le(o.parent,p,i):[]]}function vGe(o,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(o.id))return[];if(p.add(o.id),o.type!==d.ContinueStatement)throw new Error("Entity must be a continue statement to be flattened");return[o,...o.outputs.flatMap(n=>Le(n,p,i)),...o.readsValue?Le(o.readsValue,p,i):[],...o.throws?Le(o.throws,p,i):[],...o.dataType?Le(o.dataType,p,i):[],...(eo(o)||[]).flatMap(n=>Le(n,p,i)),...o.parent?Le(o.parent,p,i):[]]}function EGe(o,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(o.id))return[];if(p.add(o.id),o.type!==d.DefinitionEntity)throw new Error("Entity must be a definition entity to be flattened");return[o,...o.extends?Le(o.extends,p,i):[],...(o.implements||[]).flatMap(n=>Le(n,p,i)),...(o.properties||[]).flatMap(n=>Le(n,p,i)),...(o.methods||[]).flatMap(n=>Le(n,p,i)),...(o.abstractMethods||[]).flatMap(n=>Le(n,p,i)),...o.allPropertiesImplement?Le(o.allPropertiesImplement,p,i):[],...o.additionalPropertiesDataType?Le(o.additionalPropertiesDataType,p,i):[],...o.parent?Le(o.parent,p,i):[]]}function bGe(o,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(o.id))return[];if(p.add(o.id),o.type!==d.DataType)throw new Error("Entity must be a data type to be flattened");return[o,...(o.andChildrenGroup||[]).flatMap(n=>Le(n,p,i)),...(o.orChildrenGroup||[]).flatMap(n=>Le(n,p,i)),...o.entity?Le(o.entity,p,i):[],...o.foreignKeyRef?Le(o.foreignKeyRef,p,i):[],...o.parent?Le(o.parent,p,i):[]]}function AGe(o,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(o.id))return[];if(p.add(o.id),o.type!==d.FunctionCall)throw new Error("Entity must be a function call to be flattened");return[o,...(o.inputs||[]).flatMap(n=>Le(n,p,i)),...(o.outputs||[]).flatMap(n=>Le(n,p,i)),...o.error?Le(o.error,p,i):[],...(eo(o)||[]).flatMap(n=>Le(n,p,i)),...(o.successCalls||[]).flatMap(n=>Le(n,p,i)),...(o.errorCalls||[]).flatMap(n=>Le(n,p,i)),...(o.writesValues||[]).flatMap(n=>Le(n,p,i)),...o.parent?Le(o.parent,p,i):[]]}function gGe(o,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(o.id))return[];if(p.add(o.id),o.type!==d.FunctionDeclaration)throw new Error("Entity must be a function declaration to be flattened");return[o,...(o.inputs||[]).flatMap(n=>Le(n,p,i)),...(o.calls||[]).flatMap(n=>Le(n,p,i)),...o.dataType?Le(o.dataType,p,i):[],...o.implements?Le(o.implements,p,i):[],...o.parent?Le(o.parent,p,i):[]]}function IGe(o,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(o.id))return[];if(p.add(o.id),o.type!==d.GlobalEvent)throw new Error("Entity must be a global event to be flattened");return[o,...(o.inputs||[]).flatMap(n=>Le(n,p,i)),...(o.calls||[]).flatMap(n=>Le(n,p,i)),...o.implements?Le(o.implements,p,i):[],...o.parent?Le(o.parent,p,i):[]]}function RGe(o,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(o.id))return[];if(p.add(o.id),o.type!==d.InputMap)throw new Error("Entity must be an input map to be flattened");return[o,...o.readsValue?Le(o.readsValue,p,i):[],...o.declaration?Le(o.declaration,p,i):[],...o.defaultValue?Le(o.defaultValue,p,i):[],...o.parent?Le(o.parent,p,i):[]]}function DGe(o,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(o.id))return[];if(p.add(o.id),o.type!==d.InstalledProject)throw new Error("Entity must be an installed project to be flattened");return[o,...(o.functions||[]).flatMap(n=>Le(n,p,i)),...(o.events||[]).flatMap(n=>Le(n,p,i)),...o.parent?Le(o.parent,p,i):[]]}function wGe(o,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(o.id))return[];if(p.add(o.id),o.type!==d.InternalCall)throw new Error("Entity must be an internal call to be flattened");return[o,...(o.successCalls||[]).flatMap(n=>Le(n,p,i)),...(o.errorCalls||[]).flatMap(n=>Le(n,p,i)),...(o.inputs||[]).flatMap(n=>Le(n,p,i)),...(o.outputs||[]).flatMap(n=>Le(n,p,i)),...(eo(o)||[]).flatMap(n=>Le(n,p,i)),...o.error?Le(o.error,p,i):[],...(o.writesValues||[]).flatMap(n=>Le(n,p,i)),...o.parent?Le(o.parent,p,i):[]]}function OGe(o,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(o.id))return[];if(p.add(o.id),o.type!==d.LiteralValue)throw new Error("Entity must be a literal value to be flattened");return[o,...o.valueAsTypeSingle?Le(o.valueAsTypeSingle,p,i):[],...o.valueAsTypeList&&Array.isArray(o.valueAsTypeList)?o.valueAsTypeList.flatMap(n=>Le(n,p,i)):[],...o.parent?Le(o.parent,p,i):[]]}function CGe(o,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(o.id))return[];if(p.add(o.id),o.type!==d.Loop)throw new Error("Entity must be a loop to be flattened");return[o,...(o.inputs||[]).flatMap(n=>Le(n,p,i)),...(o.outputs||[]).flatMap(n=>Le(n,p,i)),...(o.successCalls||[]).flatMap(n=>Le(n,p,i)),...(o.errorCalls||[]).flatMap(n=>Le(n,p,i)),...o.error?Le(o.error,p,i):[],...o.dataType?Le(o.dataType,p,i):[],...o.body?Le(o.body,p,i):[],...(eo(o)||[]).flatMap(n=>Le(n,p,i)),...(o.writesValues||[]).flatMap(n=>Le(n,p,i)),...o.parent?Le(o.parent,p,i):[]]}function _Ge(o,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(o.id))return[];if(p.add(o.id),o.type!==d.Operation)throw new Error("Entity must be an operation to be flattened");return[o,...(o.successCalls||[]).flatMap(n=>Le(n,p,i)),...(o.errorCalls||[]).flatMap(n=>Le(n,p,i)),...(o.inputs||[]).flatMap(n=>Le(n,p,i)),...(o.outputs||[]).flatMap(n=>Le(n,p,i)),...(o.writesValues||[]).flatMap(n=>Le(n,p,i)),...o.error?Le(o.error,p,i):[],...(eo(o)||[]).flatMap(n=>Le(n,p,i)),...o.parent?Le(o.parent,p,i):[]]}function PGe(o,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(o.id))return[];if(p.add(o.id),o.type!==d.OutputMap)throw new Error("Entity must be an output map to be flattened");return[o,...(o.writesValues||[]).flatMap(n=>Le(n,p,i)),...o.declaration?Le(o.declaration,p,i):[],...o.parent?Le(o.parent,p,i):[]]}function VGe(o,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(o.id))return[];if(p.add(o.id),o.type!==d.PrimitiveEntity)throw new Error("Entity must be a primitive entity to be flattened");return[o,...(o.properties||[]).flatMap(n=>Le(n,p,i)),...(o.methods||[]).flatMap(n=>Le(n,p,i)),...(o.abstractMethods||[]).flatMap(n=>Le(n,p,i))]}function NGe(o,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(o.id))return[];if(p.add(o.id),o.type!==d.Project)throw new Error("Entity must be a project to be flattened");return[o,...(o.entities||[]).flatMap(n=>Le(n,p,i)),...(o.functions||[]).flatMap(n=>Le(n,p,i)),...(o.events||[]).flatMap(n=>Le(n,p,i)),...(o.projects||[]).flatMap(n=>Le(n,p,i)),...(o.variableDeclarations||[]).flatMap(n=>Le(n,p,i)),...(o.variableInstances||[]).flatMap(n=>Le(n,p,i)),...(o.operations||[]).flatMap(n=>Le(n,p,i)),...(o.conditions||[]).flatMap(n=>Le(n,p,i)),...(o.functionCalls||[]).flatMap(n=>Le(n,p,i)),...(o.projects||[]).flatMap(n=>Le(n,p,i)),...(o.loops||[]).flatMap(n=>Le(n,p,i)),...(o.searches||[]).flatMap(n=>Le(n,p,i))]}function xGe(o,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(o.id))return[];if(p.add(o.id),o.type!==d.Property)throw new Error("Entity must be a property to be flattened");return[o,...o.defaultValue?Le(o.defaultValue,p,i):[],...o.dataType?Le(o.dataType,p,i):[],...o.parent?Le(o.parent,p,i):[]]}function $Ge(o,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(o.id))return[];if(p.add(o.id),o.type!==d.ReturnStatement)throw new Error("Entity must be a return statement to be flattened");return[o,...(o.outputs||[]).flatMap(n=>Le(n,p,i)),...o.throws?Le(o.throws,p,i):[],...o.readsValue?Le(o.readsValue,p,i):[],...o.dataType?Le(o.dataType,p,i):[],...(eo(o)||[]).flatMap(n=>Le(n,p,i)),...o.parent?Le(o.parent,p,i):[]]}function LGe(o,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(o.id))return[];if(p.add(o.id),o.type!==d.Search)throw new Error("Entity must be a search to be flattened");return[o,...(o.successCalls||[]).flatMap(n=>Le(n,p,i)),...(o.errorCalls||[]).flatMap(n=>Le(n,p,i)),...(o.inputsDeclarations||[]).flatMap(n=>Le(n,p,i)),...(o.inputs||[]).flatMap(n=>Le(n,p,i)),...(o.writesValues||[]).flatMap(n=>Le(n,p,i)),...(o.outputs||[]).flatMap(n=>Le(n,p,i)),...o.error?Le(o.error,p,i):[],...o.dataType?Le(o.dataType,p,i):[],...(eo(o)||[]).flatMap(n=>Le(n,p,i)),...o.parent?Le(o.parent,p,i):[]]}function MGe(o,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(o.id))return[];if(p.add(o.id),o.type!==d.ValueDescriptor)throw new Error("Entity must be a value descriptor to be flattened");return[o,...o.defaultValue?Le(o.defaultValue,p,i):[],...o.dataType?Le(o.dataType,p,i):[],...o.parent?Le(o.parent,p,i):[]]}function BGe(o,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(o.id))return[];if(p.add(o.id),o.type!==d.VariableDeclaration)throw new Error("Entity must be a variable declaration to be flattened");return[o,...(o.successCalls||[]).flatMap(n=>Le(n,p,i)),...(o.errorCalls||[]).flatMap(n=>Le(n,p,i)),...(o.inputs||[]).flatMap(n=>Le(n,p,i)),...(o.outputs||[]).flatMap(n=>Le(n,p,i)),...(o.internalCalls||[]).flatMap(n=>Le(n,p,i)),...(o.writesValues||[]).flatMap(n=>Le(n,p,i)),...o.readsValue?Le(o.readsValue,p,i):[],...o.defaultValue?Le(o.defaultValue,p,i):[],...(eo(o)||[]).flatMap(n=>Le(n,p,i)),...o.dataType?Le(o.dataType,p,i):[],...o.parent?Le(o.parent,p,i):[]]}function GGe(o,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(o.id))return[];if(p.add(o.id),o.type!==d.VariableInstance)throw new Error("Entity must be a variable instance to be flattened");return[o,...(o.successCalls||[]).flatMap(n=>Le(n,p,i)),...(o.errorCalls||[]).flatMap(n=>Le(n,p,i)),...(o.inputs||[]).flatMap(n=>Le(n,p,i)),...(o.outputs||[]).flatMap(n=>Le(n,p,i)),...(o.internalCalls||[]).flatMap(n=>Le(n,p,i)),...(o.writesValues||[]).flatMap(n=>Le(n,p,i)),...o.readsValue?Le(o.readsValue,p,i):[],...o.defaultValue?Le(o.defaultValue,p,i):[],...(eo(o)||[]).flatMap(n=>Le(n,p,i)),...o.declaration?Le(o.declaration,p,i):[],...o.parent?Le(o.parent,p,i):[]]}function Le(o,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(!o)throw new Error("Entity must be defined to be flattened");if(o.type===d.GenericReference)return[];const n=i.ignoreBuiltInBaseEntities?i.diggestedBuiltInBaseEntitiesIds??new Set(DR()):new Set;if(i.diggestedBuiltInBaseEntitiesIds=n,i.ignoreBuiltInBaseEntities&&(Hn.includes(o.type)||n.has(o.id)))return[];if(p.has(o.id))return[];switch(o.type){case d.FunctionCall:return AGe(o,p,i);case d.Operation:return _Ge(o,p,i);case d.Condition:return TGe(o,p,i);case d.Loop:return CGe(o,p,i);case d.Search:return LGe(o,p,i);case d.GlobalEvent:return IGe(o,p,i);case d.ReturnStatement:return $Ge(o,p,i);case d.ContinueStatement:return vGe(o,p,i);case d.BreakStatement:return hGe(o,p,i);case d.VariableDeclaration:return BGe(o,p,i);case d.DefinitionEntity:return EGe(o,p,i);case d.FunctionDeclaration:return gGe(o,p,i);case d.Project:return NGe(o,p,i);case d.ActionDescriptor:return fGe(o,p,i);case d.ArgumentDeclaration:return yGe(o,p,i);case d.ValueDescriptor:return MGe(o,p,i);case d.InputMap:return RGe(o,p,i);case d.OutputMap:return PGe(o,p,i);case d.DataType:return bGe(o,p,i);case d.InstalledProject:return DGe(o,p,i);case d.InternalCall:return wGe(o,p,i);case d.LiteralValue:return OGe(o,p,i);case d.Property:return xGe(o,p,i);case d.VariableInstance:return GGe(o,p,i);case d.BuiltInBaseEntity:return i.ignoreBuiltInBaseEntities?[]:mGe(o,p,i);case d.PrimitiveEntity:return i.ignoreBuiltInBaseEntities?[]:VGe(o,p,i)}return[]}async function wR(o={}){const p=new Set,i=J.YieldTracker.from(o),n=new Set;for(const s of hV){const c=await $e(s,p,{ignoreBuiltInBaseEntities:!1,tracker:i});for(const e of c)n.add(e.id),await i.tick()}return n}function to(o){return[...o.calledByEntry||[],...o.calledByError||[],...o.calledBySuccess||[]].filter(p=>p.type!==d.GenericReference)}async function kGe(o,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(o.id))return[];if(p.add(o.id),o.type!==d.ActionDescriptor)throw new Error("Entity must be an action descriptor to be flattened");const n=J.YieldTracker.from(i),s=[o];await n.tick();const c={...i,tracker:n};delete c.yieldEvery;for(const e of o.inputs)s.push(...await $e(e,p,c));return o.dataType&&s.push(...await $e(o.dataType,p,c)),o.error&&s.push(...await $e(o.error,p,c)),o.parent&&s.push(...await $e(o.parent,p,c)),s}async function jGe(o,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(o.id))return[];if(p.add(o.id),o.type!==d.ArgumentDeclaration)throw new Error("Entity must be an argument declaration to be flattened");const n=J.YieldTracker.from(i),s=[o];await n.tick();const c={...i,tracker:n};delete c.yieldEvery,o.dataType&&s.push(...await $e(o.dataType,p,c)),o.parent&&s.push(...await $e(o.parent,p,c)),o.defaultValue&&s.push(...await $e(o.defaultValue,p,c));for(const e of o.writesValues||[])s.push(...await $e(e,p,c));for(const e of o.implements||[])s.push(...await $e(e,p,c));return s}async function UGe(o,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(o.id))return[];if(p.add(o.id),o.type!==d.BreakStatement)throw new Error("Entity must be a break statement to be flattened");const n=J.YieldTracker.from(i),s=[o];await n.tick();const c={...i,tracker:n};delete c.yieldEvery;for(const y of o.outputs)s.push(...await $e(y,p,c));o.parent&&s.push(...await $e(o.parent,p,c)),o.throws&&s.push(...await $e(o.throws,p,c)),o.dataType&&s.push(...await $e(o.dataType,p,c)),o.readsValue&&s.push(...await $e(o.readsValue,p,c));const e=to(o);for(const y of e)s.push(...await $e(y,p,c));return s}async function KGe(o,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(o.id))return[];if(p.add(o.id),o.type!==d.BuiltInBaseEntity)throw new Error("Entity must be a built-in base entity to be flattened");const n=J.YieldTracker.from(i),s=[o];await n.tick();const c={...i,tracker:n};delete c.yieldEvery;for(const e of o.properties||[])s.push(...await $e(e,p,c));for(const e of o.methods||[])s.push(...await $e(e,p,c));for(const e of o.abstractMethods||[])s.push(...await $e(e,p,c));return o.allPropertiesImplement&&s.push(...await $e(o.allPropertiesImplement,p,c)),o.additionalPropertiesDataType&&s.push(...await $e(o.additionalPropertiesDataType,p,c)),o.extends&&s.push(...await $e(o.extends,p,c)),s}async function FGe(o,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(o.id))return[];if(p.add(o.id),o.type!==d.Condition)throw new Error("Entity must be a condition to be flattened");const n=J.YieldTracker.from(i),s=[o];await n.tick();const c={...i,tracker:n};if(delete c.yieldEvery,o.andChildrenGroup&&Array.isArray(o.andChildrenGroup))for(const y of o.andChildrenGroup)s.push(...await $e(y,p,c));if(o.orChildrenGroup&&Array.isArray(o.orChildrenGroup))for(const y of o.orChildrenGroup)s.push(...await $e(y,p,c));for(const y of o.inputs)s.push(...await $e(y,p,c));for(const y of o.successCalls)s.push(...await $e(y,p,c));for(const y of o.errorCalls)s.push(...await $e(y,p,c));const e=to(o);for(const y of e)s.push(...await $e(y,p,c));return o.parent&&s.push(...await $e(o.parent,p,c)),s}async function SGe(o,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(o.id))return[];if(p.add(o.id),o.type!==d.ContinueStatement)throw new Error("Entity must be a continue statement to be flattened");const n=J.YieldTracker.from(i),s=[o];await n.tick();const c={...i,tracker:n};delete c.yieldEvery;for(const y of o.outputs)s.push(...await $e(y,p,c));const e=to(o);for(const y of e)s.push(...await $e(y,p,c));return o.parent&&s.push(...await $e(o.parent,p,c)),o.throws&&s.push(...await $e(o.throws,p,c)),o.dataType&&s.push(...await $e(o.dataType,p,c)),o.readsValue&&s.push(...await $e(o.readsValue,p,c)),s}async function qGe(o,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(o.id))return[];if(p.add(o.id),o.type!==d.DefinitionEntity)throw new Error("Entity must be a definition entity to be flattened");const n=J.YieldTracker.from(i),s=[o];await n.tick();const c={...i,tracker:n};delete c.yieldEvery;for(const e of o.properties)s.push(...await $e(e,p,c));for(const e of o.methods)s.push(...await $e(e,p,c));for(const e of o.abstractMethods)s.push(...await $e(e,p,c));for(const e of o.implements)s.push(...await $e(e,p,c));return o.extends&&s.push(...await $e(o.extends,p,c)),o.parent&&s.push(...await $e(o.parent,p,c)),o.additionalPropertiesDataType&&s.push(...await $e(o.additionalPropertiesDataType,p,c)),o.allPropertiesImplement&&s.push(...await $e(o.allPropertiesImplement,p,c)),s}async function ZGe(o,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(o.id))return[];if(p.add(o.id),o.type!==d.DataType)throw new Error("Entity must be a data type to be flattened");const n=J.YieldTracker.from(i),s=[o];await n.tick();const c={...i,tracker:n};if(delete c.yieldEvery,o.parent&&s.push(...await $e(o.parent,p,c)),o.foreignKeyRef&&s.push(...await $e(o.foreignKeyRef,p,c)),o.entity&&s.push(...await $e(o.entity,p,c)),o.orChildrenGroup)for(const e of o.orChildrenGroup)s.push(...await $e(e,p,c));if(o.andChildrenGroup)for(const e of o.andChildrenGroup)s.push(...await $e(e,p,c));return s}async function HGe(o,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(o.id))return[];if(p.add(o.id),o.type!==d.FunctionCall)throw new Error("Entity must be a function call to be flattened");const n=J.YieldTracker.from(i),s=[o];await n.tick();const c={...i,tracker:n};delete c.yieldEvery;for(const y of o.inputs)s.push(...await $e(y,p,c));for(const y of o.outputs)s.push(...await $e(y,p,c));o.error&&s.push(...await $e(o.error,p,c));const e=to(o);for(const y of e)s.push(...await $e(y,p,c));for(const y of o.successCalls)s.push(...await $e(y,p,c));for(const y of o.errorCalls)s.push(...await $e(y,p,c));for(const y of o.writesValues)s.push(...await $e(y,p,c));return o.parent&&s.push(...await $e(o.parent,p,c)),s}async function WGe(o,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(o.id))return[];if(p.add(o.id),o.type!==d.FunctionDeclaration)throw new Error("Entity must be a function declaration to be flattened");const n=J.YieldTracker.from(i),s=[o];await n.tick();const c={...i,tracker:n};delete c.yieldEvery,o.parent&&s.push(...await $e(o.parent,p,c)),o.implements&&s.push(...await $e(o.implements,p,c)),o.dataType&&s.push(...await $e(o.dataType,p,c));for(const e of o.inputs)s.push(...await $e(e,p,c));for(const e of o.calls)s.push(...await $e(e,p,c));return s}async function zGe(o,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(o.id))return[];if(p.add(o.id),o.type!==d.GlobalEvent)throw new Error("Entity must be a global event to be flattened");const n=J.YieldTracker.from(i),s=[o];await n.tick();const c={...i,tracker:n};delete c.yieldEvery,o.parent&&s.push(...await $e(o.parent,p,c)),o.implements&&s.push(...await $e(o.implements,p,c));for(const e of o.inputs)s.push(...await $e(e,p,c));for(const e of o.calls)s.push(...await $e(e,p,c));return s}async function JGe(o,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(o.id))return[];if(p.add(o.id),o.type!==d.InputMap)throw new Error("Entity must be an input map to be flattened");const n=J.YieldTracker.from(i),s=[o];await n.tick();const c={...i,tracker:n};return delete c.yieldEvery,o.parent&&s.push(...await $e(o.parent,p,c)),o.declaration&&s.push(...await $e(o.declaration,p,c)),o.readsValue&&s.push(...await $e(o.readsValue,p,c)),o.dataType&&s.push(...await $e(o.dataType,p,c)),o.defaultValue&&s.push(...await $e(o.defaultValue,p,c)),s}async function YGe(o,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(o.id))return[];if(p.add(o.id),o.type!==d.InstalledProject)throw new Error("Entity must be an installed project to be flattened");const n=J.YieldTracker.from(i),s=[o];await n.tick();const c={...i,tracker:n};delete c.yieldEvery;for(const e of o.functions)s.push(...await $e(e,p,c));for(const e of o.events)s.push(...await $e(e,p,c));return o.parent&&s.push(...await $e(o.parent,p,c)),s}async function XGe(o,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(o.id))return[];if(p.add(o.id),o.type!==d.InternalCall)throw new Error("Entity must be an internal call to be flattened");const n=J.YieldTracker.from(i),s=[o];await n.tick();const c={...i,tracker:n};delete c.yieldEvery;for(const y of o.inputs)s.push(...await $e(y,p,c));for(const y of o.outputs)s.push(...await $e(y,p,c));o.error&&s.push(...await $e(o.error,p,c));const e=to(o);for(const y of e)s.push(...await $e(y,p,c));for(const y of o.successCalls)s.push(...await $e(y,p,c));for(const y of o.errorCalls)s.push(...await $e(y,p,c));for(const y of o.writesValues)s.push(...await $e(y,p,c));return o.parent&&s.push(...await $e(o.parent,p,c)),s}async function QGe(o,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(o.id))return[];if(p.add(o.id),o.type!==d.LiteralValue)throw new Error("Entity must be a literal value to be flattened");const n=J.YieldTracker.from(i),s=[o];await n.tick();const c={...i,tracker:n};if(delete c.yieldEvery,o.valueAsTypeSingle&&s.push(...await $e(o.valueAsTypeSingle,p,c)),o.valueAsTypeList&&Array.isArray(o.valueAsTypeList))for(const e of o.valueAsTypeList)s.push(...await $e(e,p,c));return o.parent&&s.push(...await $e(o.parent,p,c)),s}async function e4e(o,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(o.id))return[];if(p.add(o.id),o.type!==d.Loop)throw new Error("Entity must be a loop to be flattened");const n=J.YieldTracker.from(i),s=[o];await n.tick();const c={...i,tracker:n};delete c.yieldEvery;for(const y of o.inputs)s.push(...await $e(y,p,c));for(const y of o.outputs)s.push(...await $e(y,p,c));o.error&&s.push(...await $e(o.error,p,c));const e=to(o);for(const y of e)s.push(...await $e(y,p,c));for(const y of o.successCalls)s.push(...await $e(y,p,c));for(const y of o.errorCalls)s.push(...await $e(y,p,c));for(const y of o.writesValues)s.push(...await $e(y,p,c));return o.parent&&s.push(...await $e(o.parent,p,c)),o.body&&s.push(...await $e(o.body,p,c)),o.dataType&&s.push(...await $e(o.dataType,p,c)),s}async function t4e(o,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(o.id))return[];if(p.add(o.id),o.type!==d.Operation)throw new Error("Entity must be an operation to be flattened");const n=J.YieldTracker.from(i),s=[o];await n.tick();const c={...i,tracker:n};delete c.yieldEvery;for(const y of o.inputs)s.push(...await $e(y,p,c));for(const y of o.outputs)s.push(...await $e(y,p,c));o.error&&s.push(...await $e(o.error,p,c));const e=to(o);for(const y of e)s.push(...await $e(y,p,c));for(const y of o.successCalls)s.push(...await $e(y,p,c));for(const y of o.errorCalls)s.push(...await $e(y,p,c));for(const y of o.writesValues)s.push(...await $e(y,p,c));return o.parent&&s.push(...await $e(o.parent,p,c)),s}async function i4e(o,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(o.id))return[];if(p.add(o.id),o.type!==d.OutputMap)throw new Error("Entity must be an output map to be flattened");const n=J.YieldTracker.from(i),s=[o];await n.tick();const c={...i,tracker:n};delete c.yieldEvery;for(const e of o.writesValues)s.push(...await $e(e,p,c));return o.declaration&&s.push(...await $e(o.declaration,p,c)),o.dataType&&s.push(...await $e(o.dataType,p,c)),o.parent&&s.push(...await $e(o.parent,p,c)),s}async function r4e(o,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(o.id))return[];if(p.add(o.id),o.type!==d.PrimitiveEntity)throw new Error("Entity must be a primitive entity to be flattened");const n=J.YieldTracker.from(i),s=[o];await n.tick();const c={...i,tracker:n};delete c.yieldEvery;for(const e of o.properties)s.push(...await $e(e,p,c));for(const e of o.methods)s.push(...await $e(e,p,c));for(const e of o.abstractMethods)s.push(...await $e(e,p,c));return s}async function n4e(o,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(o.id))return[];if(p.add(o.id),o.type!==d.Project)throw new Error("Entity must be a project to be flattened");const n=J.YieldTracker.from(i),s=[o];await n.tick();const c={...i,tracker:n};delete c.yieldEvery;for(const e of o.entities)s.push(...await $e(e,p,c));for(const e of o.functions)s.push(...await $e(e,p,c));for(const e of o.events)s.push(...await $e(e,p,c));for(const e of o.projects)s.push(...await $e(e,p,c));for(const e of o.variableDeclarations)s.push(...await $e(e,p,c));for(const e of o.variableInstances)s.push(...await $e(e,p,c));for(const e of o.operations)s.push(...await $e(e,p,c));for(const e of o.conditions)s.push(...await $e(e,p,c));for(const e of o.functionCalls)s.push(...await $e(e,p,c));for(const e of o.projects)s.push(...await $e(e,p,c));for(const e of o.loops)s.push(...await $e(e,p,c));for(const e of o.searches)s.push(...await $e(e,p,c));return s}async function a4e(o,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(o.id))return[];if(p.add(o.id),o.type!==d.Property)throw new Error("Entity must be a property to be flattened");const n=J.YieldTracker.from(i),s=[o];await n.tick();const c={...i,tracker:n};return delete c.yieldEvery,o.defaultValue&&s.push(...await $e(o.defaultValue,p,c)),o.dataType&&s.push(...await $e(o.dataType,p,c)),o.parent&&s.push(...await $e(o.parent,p,c)),s}async function s4e(o,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(o.id))return[];if(p.add(o.id),o.type!==d.ReturnStatement)throw new Error("Entity must be a return statement to be flattened");const n=J.YieldTracker.from(i),s=[o];await n.tick();const c={...i,tracker:n};delete c.yieldEvery;for(const y of o.outputs)s.push(...await $e(y,p,c));for(const y of o.outputs)s.push(...await $e(y,p,c));o.throws&&s.push(...await $e(o.throws,p,c)),o.readsValue&&s.push(...await $e(o.readsValue,p,c)),o.dataType&&s.push(...await $e(o.dataType,p,c));const e=to(o);for(const y of e)s.push(...await $e(y,p,c));return o.parent&&s.push(...await $e(o.parent,p,c)),s}async function l4e(o,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(o.id))return[];if(p.add(o.id),o.type!==d.Search)throw new Error("Entity must be a search to be flattened");const n=J.YieldTracker.from(i),s=[o];await n.tick();const c={...i,tracker:n};delete c.yieldEvery;for(const y of o.inputs)s.push(...await $e(y,p,c));for(const y of o.outputs)s.push(...await $e(y,p,c));o.error&&s.push(...await $e(o.error,p,c)),o.dataType&&s.push(...await $e(o.dataType,p,c));for(const y of o.inputsDeclarations)s.push(...await $e(y,p,c));const e=to(o);for(const y of e)s.push(...await $e(y,p,c));for(const y of o.successCalls)s.push(...await $e(y,p,c));for(const y of o.errorCalls)s.push(...await $e(y,p,c));for(const y of o.writesValues)s.push(...await $e(y,p,c));return o.parent&&s.push(...await $e(o.parent,p,c)),s}async function o4e(o,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(o.id))return[];if(p.add(o.id),o.type!==d.ValueDescriptor)throw new Error("Entity must be a value descriptor to be flattened");const n=J.YieldTracker.from(i),s=[o];await n.tick();const c={...i,tracker:n};return delete c.yieldEvery,o.defaultValue&&s.push(...await $e(o.defaultValue,p,c)),o.dataType&&s.push(...await $e(o.dataType,p,c)),o.parent&&s.push(...await $e(o.parent,p,c)),s}async function d4e(o,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(o.id))return[];if(p.add(o.id),o.type!==d.VariableDeclaration)throw new Error("Entity must be a variable declaration to be flattened");const n=J.YieldTracker.from(i),s=[o];await n.tick();const c={...i,tracker:n};delete c.yieldEvery;for(const y of o.inputs)s.push(...await $e(y,p,c));for(const y of o.outputs)s.push(...await $e(y,p,c));o.error&&s.push(...await $e(o.error,p,c)),o.dataType&&s.push(...await $e(o.dataType,p,c)),o.readsValue&&s.push(...await $e(o.readsValue,p,c)),o.defaultValue&&s.push(...await $e(o.defaultValue,p,c));const e=to(o);for(const y of e)s.push(...await $e(y,p,c));for(const y of o.successCalls)s.push(...await $e(y,p,c));for(const y of o.errorCalls)s.push(...await $e(y,p,c));for(const y of o.writesValues)s.push(...await $e(y,p,c));for(const y of o.internalCalls)s.push(...await $e(y,p,c));return o.parent&&s.push(...await $e(o.parent,p,c)),s}async function u4e(o,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(o.id))return[];if(p.add(o.id),o.type!==d.VariableInstance)throw new Error("Entity must be a variable instance to be flattened");const n=J.YieldTracker.from(i),s=[o];await n.tick();const c={...i,tracker:n};delete c.yieldEvery;for(const y of o.inputs)s.push(...await $e(y,p,c));for(const y of o.outputs)s.push(...await $e(y,p,c));o.error&&s.push(...await $e(o.error,p,c)),o.readsValue&&s.push(...await $e(o.readsValue,p,c)),o.defaultValue&&s.push(...await $e(o.defaultValue,p,c));const e=to(o);for(const y of e)s.push(...await $e(y,p,c));for(const y of o.successCalls)s.push(...await $e(y,p,c));for(const y of o.errorCalls)s.push(...await $e(y,p,c));for(const y of o.writesValues)s.push(...await $e(y,p,c));for(const y of o.internalCalls)s.push(...await $e(y,p,c));return o.parent&&s.push(...await $e(o.parent,p,c)),o.declaration&&s.push(...await $e(o.declaration,p,c)),s}async function $e(o,p=new Set,i={ignoreBuiltInBaseEntities:!1,yieldEvery:100}){const n={...i,ignoreBuiltInBaseEntities:i.ignoreBuiltInBaseEntities??!1};if(!o)throw new Error("Entity must be defined to be flattened");if(o.type===d.GenericReference)return[];const s=J.YieldTracker.from(n);n.tracker=s,n.yieldEvery!==void 0&&delete n.yieldEvery;const c=n.ignoreBuiltInBaseEntities?n.diggestedBuiltInBaseEntitiesIds??new Set(await wR(n)):new Set;if(n.diggestedBuiltInBaseEntitiesIds=c,n.ignoreBuiltInBaseEntities&&(Hn.includes(o.type)||c.has(o.id)))return[];if(p.has(o.id))return[];switch(o.type){case d.FunctionCall:return HGe(o,p,n);case d.Operation:return t4e(o,p,n);case d.Condition:return FGe(o,p,n);case d.Loop:return e4e(o,p,n);case d.Search:return l4e(o,p,n);case d.GlobalEvent:return zGe(o,p,n);case d.ReturnStatement:return s4e(o,p,n);case d.ContinueStatement:return SGe(o,p,n);case d.BreakStatement:return UGe(o,p,n);case d.VariableDeclaration:return d4e(o,p,n);case d.DefinitionEntity:return qGe(o,p,n);case d.FunctionDeclaration:return WGe(o,p,n);case d.Project:return n4e(o,p,n);case d.ActionDescriptor:return kGe(o,p,n);case d.ArgumentDeclaration:return jGe(o,p,n);case d.ValueDescriptor:return o4e(o,p,n);case d.InputMap:return JGe(o,p,n);case d.OutputMap:return i4e(o,p,n);case d.DataType:return ZGe(o,p,n);case d.InstalledProject:return YGe(o,p,n);case d.InternalCall:return XGe(o,p,n);case d.LiteralValue:return QGe(o,p,n);case d.Property:return a4e(o,p,n);case d.VariableInstance:return u4e(o,p,n);case d.BuiltInBaseEntity:return n.ignoreBuiltInBaseEntities?[]:KGe(o,p,n);case d.PrimitiveEntity:return n.ignoreBuiltInBaseEntities?[]:r4e(o,p,n)}return[]}function p4e(o,p,i){if(!i)throw new Error("[checkIsRowTransformerUpToDate] 'lastPublishedEntityVersion' argument is required");if(!p)throw new Error("[checkIsRowTransformerUpToDate] 'entity' argument is required");if(!o)throw new Error("[checkIsRowTransformerUpToDate] 'newestOpenRowTransformer' argument is required");let n=!0;const s=o.methods.find(c=>{var e;return((e=c.implements)==null?void 0:e.id)===Q["built-in-base-entity"].BUILT_IN_SQL_ROW_TRANSFORMER_ENTITY.methods.up.id});if(s?(vn(i).forEach(c=>{const e=s.inputs.find(y=>y.name===c.name);e&&Yr(e.getDataType(null),c.getDataType(null)).compatible||(n=!1)}),s.returnStatements.forEach(c=>{!c.dataType||!c.dataType.entity||c.dataType.entity.type!==d.DefinitionEntity?n=!1:Um(c.dataType.entity,p)||(n=!1)})):n=!1,n===null||n){const c=o.methods.find(e=>{var y;return((y=e.implements)==null?void 0:y.id)===Q["built-in-base-entity"].BUILT_IN_SQL_ROW_TRANSFORMER_ENTITY.methods.down.id});c?(vn(p).forEach(e=>{const y=c.inputs.find(m=>m.name===e.name);y&&Yr(y.getDataType(null),e.getDataType(null)).compatible||(n=!1)}),c.returnStatements.forEach(e=>{!e.dataType||!e.dataType.entity||e.dataType.entity.type!==d.DefinitionEntity?n=!1:Um(e.dataType.entity,i)||(n=!1)})):n=!1}return{isPreexistingRowTransformerUpToDate:n}}function c4e(o,p,i){const n={changesSinceLastPublication:!1,rowTransformerNeeded:!1,newRowTransformerNeeded:!1,newestOpenRowTransformer:null,newRequiredProperties:[],newNonRequiredProperties:[],deletedProperties:[],lastPublishedEntityVersion:null,updatedEntityVersion:i,propChanges:new Map,isPreexistingRowTransformerUpToDate:null,extendedEntities:[]},c=o.entities.filter(F=>{var ne;if(F.id===i.id)return!1;let q=!1,X=F;for(;X;){if(((ne=X.extends)==null?void 0:ne.id)===i.id){q=!0;break}if(X.extends&&X.extends.type===d.DefinitionEntity)X=X.extends;else break}return q}).map(F=>c4e(o,p,F));if(!p)return{...n,changesSinceLastPublication:!0,extendedEntities:c};const e=p.get(i.id);if(!e)return{...n,changesSinceLastPublication:!0,extendedEntities:c};const y=p.entities.filter(F=>Zi(F,Re.SQL_ROW_TRANSFORMER)),v=o.entities.filter(F=>{var ee;if(!Zi(F,Re.SQL_ROW_TRANSFORMER)||y.find(pe=>pe.id===F.id))return!1;const X=F.properties.find(pe=>!!pe.implements.find(oe=>Q["built-in-base-entity"].BUILT_IN_SQL_ROW_TRANSFORMER_ENTITY.properties.definition.id===oe.id));if(!X)return!1;const ne=(ee=X.defaultValue)==null?void 0:ee.valueAsType;return ne?ne.id===i.id:!1}).sort((F,q)=>M(F.createdAt).isAfter(M(q.createdAt))?-1:1)[0]||null,E=new Map;let b=!1;const w=vn(i).filter(F=>vn(e).find(X=>X.id===F.id)?!1:!!F.required),P=vn(i).filter(F=>vn(e).find(X=>X.id===F.id)?!1:!F.required),$=vn(e).filter(F=>!vn(i).find(X=>X.id===F.id));vn(i).filter(F=>{var ne,ee,pe,oe,ce,Te,de,ye,_e,Pe,Ge,xe,Me,Se,je,Ze,Ye,lt,ot,Rt,Pt,Ri,sr,hr;const q=vn(e).find(_n=>_n.id===F.id);let X=!1;if(!q)return!1;if(((ee=(ne=F.dataType)==null?void 0:ne.entity)==null?void 0:ee.id)!==((oe=(pe=q==null?void 0:q.dataType)==null?void 0:pe.entity)==null?void 0:oe.id)&&(((Te=(ce=F.dataType)==null?void 0:ce.entity)==null?void 0:Te.id)===Q["primitive-entity"].string.id||((ye=(de=q==null?void 0:q.dataType)==null?void 0:de.entity)==null?void 0:ye.id)===Q["primitive-entity"].date.id&&((Pe=(_e=F.dataType)==null?void 0:_e.entity)==null?void 0:Pe.id)===Q["primitive-entity"].number.id?E.set(F.id,{...E.get(F.id)||{},castableDataTypeEntity:{fromId:((xe=(Ge=q==null?void 0:q.dataType)==null?void 0:Ge.entity)==null?void 0:xe.id)||"",toId:((Se=(Me=F.dataType)==null?void 0:Me.entity)==null?void 0:Se.id)||""},property:F,oldProperty:q}):(E.set(F.id,{...E.get(F.id)||{property:F},nonCastableDataTypeEntity:{fromId:((Ze=(je=q==null?void 0:q.dataType)==null?void 0:je.entity)==null?void 0:Ze.id)||"",toId:((lt=(Ye=F.dataType)==null?void 0:Ye.entity)==null?void 0:lt.id)||""},property:F,oldProperty:q}),b=!0),X=!0),((Rt=(ot=F.dataType)==null?void 0:ot.foreignKeyRef)==null?void 0:Rt.id)!==((Ri=(Pt=q==null?void 0:q.dataType)==null?void 0:Pt.foreignKeyRef)==null?void 0:Ri.id)){const _n=(sr=F.dataType)==null?void 0:sr.foreignKeyRef,an=(hr=q==null?void 0:q.dataType)==null?void 0:hr.foreignKeyRef;E.set(F.id,{...E.get(F.id)||{},newForeignKeyRef:_n||void 0,oldForeignKeyRef:an||void 0,property:F,oldProperty:q}),X=!0,b=!0}return F.name!==(q==null?void 0:q.name)&&(E.set(F.id,{...E.get(F.id)||{},nameChange:{from:(q==null?void 0:q.name)||"",to:F.name},property:F,oldProperty:q}),X=!0),F.required!==(q==null?void 0:q.required)&&(E.set(F.id,{...E.get(F.id)||{},requiredChange:{from:(q==null?void 0:q.required)||!1,to:F.required},property:F,oldProperty:q}),F.required&&(b=!0),X=!0),X}),w.length>0&&(b=!0);const L=!!v&&p4e(v,i,e).isPreexistingRowTransformerUpToDate||null,j=i.name!==e.name?{from:e.name,to:i.name}:void 0;return{...n,changesSinceLastPublication:E.size>0||!!$.length||!!w.length||!!P.length||b,rowTransformerNeeded:b,newestOpenRowTransformer:v,nameChange:j,newRequiredProperties:w,newNonRequiredProperties:P,deletedProperties:$,lastPublishedEntityVersion:e,propChanges:E,newRowTransformerNeeded:b&&!v,isPreexistingRowTransformerUpToDate:L,extendedEntities:c}}function JN(o,p,i,n,s){if(!o)throw new Error("[addDifferencesToRowTransformer] 'project' argument is required");if(!p)throw new Error("[addDifferencesToRowTransformer] 'transformer' argument is required");if(!i)throw new Error("[addDifferencesToRowTransformer] 'newEntityState' argument is required");if(!n)throw new Error("[addDifferencesToRowTransformer] 'oldEntityState' argument is required");const c=vn(i),e=vn(n);p.afterAllChildrenInitialized(s);const y=p.methods.find(v=>{var E;return((E=v.implements)==null?void 0:E.id)===Q["built-in-base-entity"].BUILT_IN_SQL_ROW_TRANSFORMER_ENTITY.methods.up.id}),m=p.methods.find(v=>{var E;return((E=v.implements)==null?void 0:E.id)===Q["built-in-base-entity"].BUILT_IN_SQL_ROW_TRANSFORMER_ENTITY.methods.down.id});if(!y)throw new Error("[addDifferencesToRowTransformer] The 'up' transformer trigger is missing from the parent");if(!m)throw new Error("[addDifferencesToRowTransformer] The 'down' transformer trigger is missing from the parent");e.forEach(v=>{const E=y.inputs.find($=>$.name===v.name),b=v.getDataType(null);let w=E,P;if(E)w.editable=!0;else{const $=Ea.new(s);$.parent=y.toReference(),$.name=v.name,$.index=v.index,$.implements=[...v.implements.map(j=>j.toJSON())];const L=he($,o);L.hydrateAncestors(),s.add(L,H.Added),L.addSelfToProject(s),L.initChildren(s),w=L}if(!w.dataType||w.dataType&&o.diggestedBuiltInBaseEntitiesIds.has(w.dataType.id)){const $=ir.new(s);$.parent=w.toReference();const L=he($,o);L.hydrateAncestors(),s.add(L,H.Added),L.addSelfToProject(s),L.initChildren(s),P=L}else P=w.dataType,P.editable=!0;b&&P.merge(v.getDataType(null),s),P.metaSync({editable:!1,deletable:!1},s),w.metaSync({editable:!1,deletable:!1},s)}),[...y.inputs].forEach(v=>{e.find(b=>b.name===v.name)||(v.editable=!0,v.remove({ignoreUpstream:!1},s),v.editable=!1)}),[...y.returnStatements].forEach(v=>{var E,b;if(!v.dataType||v.dataType&&o.diggestedBuiltInBaseEntitiesIds.has(v.dataType.id)){const w=ir.new(s);w.entity=i.toReference(),w.parent=v.toReference();const P=he(w,o);P.hydrateAncestors(),s.add(P,H.Added),P.addSelfToProject(s),P.initChildren(s)}(!((E=v.dataType)!=null&&E.entity)||v.dataType.entity.type!==d.DefinitionEntity||v.dataType.entity.parent.id!==v.dataType.id)&&i.clone(s,v.dataType),TV((b=v.dataType)==null?void 0:b.entity,i,s),v.afterAllChildrenInitialized(s),v.outputs.forEach(w=>{const P=y.inputs.find($=>se(w,o)===se($,o));w.setValueWriter(P,s),P==null||P.addValueReader(w,s)})}),c.forEach(v=>{var L;const E=(L=v.knownVersions)==null?void 0:L.get(v.previousVersion),b=m.inputs.find(j=>j.name===v.name||!!E&&E.name===j.name),w=v.getDataType(null);let P=b,$;if(b)P.editable=!0,P.metaSync({name:v.name,codeName:v.codeName,description:v.description},s);else{const j=Ea.new(s);j.parent=m.toReference(),j.name=v.name,j.codeName=v.codeName,j.description=v.description,j.index=v.index,j.implements=[v.toJSON(),...v.implements.map(q=>q.toJSON())];const F=he(j,o);F.hydrateAncestors(),s.add(F,H.Added),F.addSelfToProject(s),F.initChildren(s),P=F}if(P.dataType)$=P.dataType,$.editable=!0,$.merge(P.dataType,s);else{const j=ir.new(s);j.parent=P.toReference();const F=he(j,o);F.hydrateAncestors(),s.add(F,H.Added),F.addSelfToProject(s),F.initChildren(s),$=F}w&&$.merge(v.getDataType(null),s),$.metaSync({editable:!1,deletable:!1},s),P.metaSync({editable:!1,deletable:!1},s)}),[...m.inputs].forEach(v=>{c.find(b=>{var P;if(b.name===v.name)return!0;const w=(P=b.knownVersions)==null?void 0:P.get(b.previousVersion);if(w&&w.name===v.name)return!0})||(v.editable=!0,v.remove({ignoreUpstream:!1},s),v.editable=!1)}),[...m.returnStatements].forEach(v=>{var b,w,P,$;if(!v.dataType||v.dataType&&o.diggestedBuiltInBaseEntitiesIds.has(v.dataType.id)){const L=ir.new(s);L.parent=v.toReference();const j=he(L,o);j.hydrateAncestors(),s.add(j,H.Added),j.addSelfToProject(s),j.initChildren(s)}let E=(b=v.dataType)==null?void 0:b.entity;(!E||(E==null?void 0:E.id)===Q["built-in-base-entity"].BUILT_IN_PERSISTED_ENTITY_ENTITY.id)&&(J.Logger.log("Cloning old entity state into new project with data-ype as parent: ",(w=v.dataType)==null?void 0:w.id," from new project: ",((P=v.dataType)==null?void 0:P.project.version)===o.version&&(($=v.dataType)==null?void 0:$.project.entities.length)===3),E=n.clone(s,v.dataType)),v.dataType.setEntity(E,s),v.afterAllChildrenInitialized(s),v.outputs.forEach(L=>{const j=m.inputs.find(F=>se(L,o)===se(F,o));L.setValueWriter(j,s),j==null||j.addValueReader(L,s)})})}function f4e(o,p,i,n){var $;const s=o.getBuiltIn(Re.SQL_ROW_TRANSFORMER),c=OV(se(p,o)+" row transformer",o.entities),e=s.implement(c,n),y=e.ownDeclaredProperties.find(L=>{var j;return(j=L.implements)==null?void 0:j.find(F=>F.id===Q["built-in-base-entity"].BUILT_IN_SQL_ROW_TRANSFORMER_ENTITY.properties.definition.id)}),m=e.methods.find(L=>{var j;return((j=L.implements)==null?void 0:j.id)===Q["built-in-base-entity"].BUILT_IN_SQL_ROW_TRANSFORMER_ENTITY.methods.up.id}),v=e.methods.find(L=>{var j;return((j=L.implements)==null?void 0:j.id)===Q["built-in-base-entity"].BUILT_IN_SQL_ROW_TRANSFORMER_ENTITY.methods.down.id});if(!y||!m||!v)throw new Error("Cannot find definition property on the new row transformer entity");if(y.defaultValue)y.defaultValue.setValueAsTypeSingle(p,n);else{const L=Xr.new(n);L.name=le.EntityTemplate,L.valueAsTypeSingle=p.toJSON(),L.parent=y.toReference();const j=he(L,o);j.hydrateAncestors(),n.add(j,H.Added),j.addSelfToProject(n),j.initChildren(n)}JN(o,e,p,i,n),J.Logger.log("BEFORE - changeSet.listAdded",n.listAdded.map(L=>{var F,q,X,ne,ee,pe,oe;const j=o.get(L.id);return j?se(j,o):L.type===d.InputMap?"(not found) "+L.type+" "+L.id+" - declaration: "+((F=L.declaration)==null?void 0:F.type)+" "+((q=L.declaration)==null?void 0:q.id)+' "'+((X=L.declaration)==null?void 0:X.name)+`"
387
+ `)),J.Logger.log("Persisting new additions"),m.visit(async(v,E)=>{if(n.added[v.id]){J.Logger.log("Adding: ",v.id);try{const b=he(v,this);if(b.hydrateAncestors(),b.addSelfToProject(s),s.add(b,H.Added),!this.get(v.id))throw new Error(`Entity ${v.id} was not added to the project`)}catch(b){J.Logger.error("Error: ",b),J.Logger.error("Errored entity: ",v)}}}),J.Logger.log("Persisting updates"),m.visit(async(v,E)=>{if(n.updated[v.id]){J.Logger.log("Updating: ",v.id);try{const b=this.get(v.id);b?(b.updateWithShallowTransfer(v,s),s.add(b,H.Updated)):J.Logger.warn(`Active version of ${v.id} not found when applying external changes`)}catch(b){J.Logger.error("Error: ",b),J.Logger.error("Errored entity: ",v)}}}),J.Logger.log("Persisting removals"),m.visit(async(v,E)=>{if(n.removed[v.id]){J.Logger.log("Removing: ",v.id);try{const b=this.get(v.id);b&&b.remove({ignoreUpstream:!1},s)}catch(b){J.Logger.error("Error: ",b),J.Logger.error("Errored entity: ",v)}}}),s.open=!1,s}toBuiltInShallowRecord(){const i={};return Object.values(this.builtInInstances).forEach(n=>{const s=n.toShallowJSON();i[n.id]=s}),i}toShallowRecord(){const i={};return Object.values(this.instances).forEach(n=>{const s=n.toShallowJSON();i[n.id]=s}),i}toFullProjectTransfer(){const i=new Nn(void 0,{allBuiltInEntityIds:this.diggestedBuiltInBaseEntitiesIds});i.flatRecord=this.instances,i.order=Object.keys(i.flatRecord),i.orderEntities();const n={};return i.visit(s=>{const c=s.toShallowJSON();n[s.id]=c}),{order:i.order,size:i.order.length,record:n}}async toFullProjectTransferAsync(i={}){const n=J.YieldTracker.from(i),s=new Nn(void 0,{allBuiltInEntityIds:this.diggestedBuiltInBaseEntitiesIds});s.flatRecord=this.instances,s.order=Object.keys(s.flatRecord);let c=s.order;if(i.seenEntityMaps){c=[];for(const y of s.order){const m=i.seenEntityMaps.get(y)??y;this.diggestedBuiltInBaseEntitiesIds.has(m)||c.push(m)}}await s.orderEntitiesAsync({tracker:n});const e={};return await s.visitAsync(async y=>{if(this.diggestedBuiltInBaseEntitiesIds.has(y.id))return;const m=y.toShallowJSON({seenEntityMaps:i.seenEntityMaps});i.resetVersionOptions&&(m.version=Ct.UUID.uuid(),m.createdAt=i.resetVersionOptions.commonTimestamp||M().toISOString(),m.author=i.resetVersionOptions.author||Ct.sessionAuthor||"1",m.previousVersion=null),e[m.id]=m,i!=null&&i.onVisit&&await i.onVisit(m)},{tracker:n}),{order:c,size:s.order.length,record:e}}};I(Ct,"parentContext",WN),I(Ct,"sessionAuthor","1"),I(Ct,"repository",{APICreate:async(i,...n)=>i,APIUpdate:async(i,...n)=>i,APIDelete:async(i,...n)=>i,APIClone:async(i,...n)=>{},APILoad:async(i,...n)=>null,APILoadVersion:async(i,n,...s)=>null}),I(Ct,"type",d.Project),I(Ct,"USER_MANAGED_PARENT_TYPES",[]),I(Ct,"PARENT_TYPES",[...Ct.USER_MANAGED_PARENT_TYPES]),I(Ct,"MUTABLE_BASE_PROPERTIES",["name","description"]),I(Ct,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),I(Ct,"BASE_PROPERTIES",[...Ct.MUTABLE_BASE_PROPERTIES,...Ct.INMUTABLE_BASE_PROPERTIES]),I(Ct,"MUTABLE_META_PROPERTIES",[...Ct.MUTABLE_BASE_PROPERTIES,"x","y"]),I(Ct,"INMUTABLE_META_PROPERTIES",[...Ct.INMUTABLE_BASE_PROPERTIES]),I(Ct,"META_PROPERTIES",[...Ct.MUTABLE_META_PROPERTIES,...Ct.INMUTABLE_META_PROPERTIES]),I(Ct,"MUTABLE_UPSTREAM_PROPERTIES",[]),I(Ct,"INMUTABLE_UPSTREAM_PROPERTIES",["primitives","builtInBaseEntities","operationDeclarations","globalEventActionDescriptors","loopDeclarations","builtInInstances"]),I(Ct,"UPSTREAM_PROPERTIES",[...Ct.MUTABLE_UPSTREAM_PROPERTIES,...Ct.INMUTABLE_UPSTREAM_PROPERTIES]),I(Ct,"MUTABLE_DOWNSTREAM_PROPERTIES",["entities","projects","functions","events","variableDeclarations","variableInstances","conditions","operations","functionCalls","loops","searches"]),I(Ct,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),I(Ct,"DOWNSTREAM_PROPERTIES",[...Ct.MUTABLE_DOWNSTREAM_PROPERTIES,...Ct.INMUTABLE_DOWNSTREAM_PROPERTIES]),I(Ct,"PROPERTIES",[...Ct.META_PROPERTIES,...Ct.UPSTREAM_PROPERTIES,...Ct.DOWNSTREAM_PROPERTIES]);let x=Ct;class m1i extends Li{constructor(p){super(FT,p)}}class T1i extends Li{constructor(i){super(rh,i);I(this,"autoexecutable",!0)}getEntityToMatchInputMap(i){return i.inputs.find(n=>{var s;return((s=n.declaration)==null?void 0:s.id)===Q.operation[Ce.Validate].inputs.entityToMatch.id})||null}getDataToValidateInputMap(i){return i.inputs.find(n=>{var s;return((s=n.declaration)==null?void 0:s.id)===Q.operation[Ce.Validate].inputs.dataToValidate.id})||null}getOutputDataOutputMap(i){return i.outputs.find(n=>{var s;return((s=n.declaration)==null?void 0:s.id)===Q.operation[Ce.Validate].dataType.entity.properties.outputEntity.id})||null}getEntityToMatch(i,n=this.project.addChangeSet(new Z(this.project,x.sessionAuthor,M().toISOString(),this,!0,"get-entity-to-match-validate-data"))){var e;const s=((e=this.project.requestActiveDynamicValue(i))==null?void 0:e.value)||null,c=s==null?void 0:s.valueAsTypeSingle;return n==null||n.attemptAutoclose("get-entity-to-match-validate-data",this.id),c}syncOperationInstance(i,n=this.project.addChangeSet(new Z(this.project,x.sessionAuthor,M().toISOString(),this,!0,"sync-operation-instance-validate-data"))){const s=[],c=[],e=[],y=[],m=this.getEntityToMatchInputMap(i);if(m){const{added:b,updated:w,removed:P,affected:$}=this.syncEntityToMatchInputMapDataType(m,n);s.push(...w),c.push(...b),e.push(...P),y.push(...$)}const v=this.getDataToValidateInputMap(i);if(v){const{added:b,updated:w,removed:P,affected:$}=this.syncDataToValidateInputMapDataType(v,n);s.push(...w),c.push(...b),e.push(...P),y.push(...$)}const E=this.getOutputDataOutputMap(i);if(E){const{added:b,updated:w,removed:P,affected:$}=this.syncOutputDataOutputMapDataType(E,n);s.push(...w),c.push(...b),e.push(...P),y.push(...$)}return n==null||n.attemptAutoclose("sync-operation-instance-validate-data",this.id),{updated:D(s),added:D(c),removed:D(e),affected:D(y),self:i}}syncEntityToMatchInputMapDataType(i,n=this.project.addChangeSet(new Z(this.project,x.sessionAuthor,M().toISOString(),this,!0,"sync-entity-to-match-input-map-data-type"))){var E,b,w,P,$,L,j,F,q,X,ne,ee,pe,oe,ce,Te,de,ye;const s=[],c=[],e=[],y=[];if(((E=i.declaration)==null?void 0:E.id)!==Q.operation[Ce.Validate].inputs.entityToMatch.id)return n==null||n.attemptAutoclose("sync-entity-to-match-input-map-data-type",this.id),{updated:[],added:[],removed:[],affected:[],self:null};const m=((b=this.project.requestActiveDynamicValue(i))==null?void 0:b.value)||null,v=m==null?void 0:m.valueAsTypeSingle;if(!i.dataType){const _e={id:x.UUID.uuid(),version:x.UUID.uuid(),createdAt:(n==null?void 0:n.timestamp)||new Date().toISOString(),author:(n==null?void 0:n.author)||x.sessionAuthor,previousVersion:null,deleted:!1,deletable:!0,editable:!0,type:d.DataType,parentRelationType:null,options:((w=i.declaration.dataType)==null?void 0:w.options)||null,implementationChooseOne:((P=i.declaration.dataType)==null?void 0:P.implementationChooseOne)||!1,staticEntities:(($=i.declaration.dataType)==null?void 0:$.staticEntities)??null,interactiveEntities:((L=i.declaration.dataType)==null?void 0:L.interactiveEntities)??null,actionEntities:((j=i.declaration.dataType)==null?void 0:j.actionEntities)??null,index:((F=i.declaration.dataType)==null?void 0:F.index)??null,isList:((q=i.declaration.dataType)==null?void 0:q.isList)||!1,foreignKeyAllowed:((X=i.declaration.dataType)==null?void 0:X.foreignKeyAllowed)??null,andChildrenGroup:null,orChildrenGroup:null,foreignKeyRef:null,asType:!0,entity:(v==null?void 0:v.toJSON())||null,like:!0,inferred:!0,parent:i.toReference()},Pe=he(_e,i.project);Pe.hydrateAncestors(),Pe.setParent(i,n),Pe.initChildren(n),Pe.setEntity(v,n),n==null||n.add(Pe,H.Added),s.push(Pe),i.setDataType(Pe,n)}return(de=i.dataType)==null||de.metaSync({inferred:!0,like:!1,asType:!0,options:((ne=i.declaration.dataType)==null?void 0:ne.options)||null,implementationChooseOne:((ee=i.declaration.dataType)==null?void 0:ee.implementationChooseOne)||!1,staticEntities:((pe=i.declaration.dataType)==null?void 0:pe.staticEntities)??null,interactiveEntities:((oe=i.declaration.dataType)==null?void 0:oe.interactiveEntities)??null,actionEntities:((ce=i.declaration.dataType)==null?void 0:ce.actionEntities)??null,isList:((Te=i.declaration.dataType)==null?void 0:Te.isList)||!1},n),(ye=i.dataType)==null||ye.setEntity(v,n),i.dataType&&c.push(i.dataType),n==null||n.attemptAutoclose("sync-entity-to-match-input-map-data-type",this.id),{updated:D(c),added:D(s),removed:D(e),affected:D(y),self:i.dataType}}syncDataToValidateInputMapDataType(i,n=this.project.addChangeSet(new Z(this.project,x.sessionAuthor,M().toISOString(),this,!0,"sync-data-to-validate-input-map-data-type"))){var b,w,P;const s=[],c=[],e=[],y=[];if(((b=i.declaration)==null?void 0:b.id)!==Q.operation[Ce.Validate].inputs.dataToValidate.id)return n==null||n.attemptAutoclose("sync-data-to-validate-input-map-data-type",this.id),{updated:[],added:[],removed:[],affected:[],self:null};const m=this.getEntityToMatchInputMap(i.parent);if(!m)return n==null||n.attemptAutoclose("sync-data-to-validate-input-map-data-type",this.id),{updated:[],added:[],removed:[],affected:[],self:null};if(!this.getEntityToMatch(m,n))return n==null||n.attemptAutoclose("sync-data-to-validate-input-map-data-type",this.id),{updated:[],added:[],removed:[],affected:[],self:null};if(!i.dataType){const $={id:x.UUID.uuid(),version:x.UUID.uuid(),createdAt:(n==null?void 0:n.timestamp)||new Date().toISOString(),author:(n==null?void 0:n.author)||x.sessionAuthor,previousVersion:null,deleted:!1,deletable:!0,editable:!0,type:d.DataType,index:null,parentRelationType:null,options:null,implementationChooseOne:!1,foreignKeyAllowed:null,isList:!1,foreignKeyRef:null,andChildrenGroup:null,orChildrenGroup:null,staticEntities:null,interactiveEntities:null,actionEntities:null,asType:!1,entity:null,like:!0,inferred:!0,parent:i.toReference()},L=he($,i.project);L.setParent(i,n),L.initChildren(n),n==null||n.add(L,H.Added),s.push(L),i.setDataType(L,n)}(w=i.dataType)==null||w.metaSync({inferred:!0,like:!0,asType:!1},n);const E=this.getEntityToMatch(m,n);return(P=i.dataType)==null||P.setEntity(E,n),i.dataType&&c.push(i.dataType),n==null||n.attemptAutoclose("sync-data-to-validate-input-map-data-type",this.id),{updated:D(c),added:D(s),removed:D(e),affected:D(y),self:i.dataType}}syncOutputDataOutputMapDataType(i,n=this.project.addChangeSet(new Z(this.project,x.sessionAuthor,M().toISOString(),this,!0,"sync-output-data-output-map-data-type"))){var w,P,$,L;const s=[],c=[],e=[],y=[];if(((w=i.declaration)==null?void 0:w.id)!==Q.operation[Ce.Validate].dataType.entity.properties.outputEntity.id)return n==null||n.attemptAutoclose("sync-output-data-output-map-data-type",this.id),{updated:[],added:[],removed:[],affected:[],self:null};const m=this.getEntityToMatchInputMap(i.parent);if(!m)return n==null||n.attemptAutoclose("sync-output-data-output-map-data-type",this.id),{updated:[],added:[],removed:[],affected:[],self:null};if(!this.getEntityToMatch(m,n))return n==null||n.attemptAutoclose("sync-output-data-output-map-data-type",this.id),{updated:[],added:[],removed:[],affected:[],self:null};const E=((P=this.project.requestActiveDynamicValue(m))==null?void 0:P.value)||null,b=(E==null?void 0:E.valueAsTypeSingle)||null;if(!i.dataType){const j={id:x.UUID.uuid(),version:x.UUID.uuid(),createdAt:(n==null?void 0:n.timestamp)||new Date().toISOString(),author:(n==null?void 0:n.author)||x.sessionAuthor,previousVersion:null,deleted:!1,deletable:!0,editable:!0,type:d.DataType,parentRelationType:null,options:null,foreignKeyRef:null,implementationChooseOne:!1,foreignKeyAllowed:null,staticEntities:null,interactiveEntities:null,index:null,actionEntities:null,isList:!1,andChildrenGroup:null,orChildrenGroup:null,asType:!1,entity:(b==null?void 0:b.toJSON())||null,like:!0,inferred:!0,parent:i.toReference()},F=he(j,i.project);F.hydrateAncestors(),F.setParent(i,n),F.initChildren(n),F.setEntity(b,n),n==null||n.add(F,H.Added),s.push(F),i.setDataType(F,n)}return($=i.dataType)==null||$.metaSync({inferred:!0,like:!0,asType:!1},n),(L=i.dataType)==null||L.setEntity(b,n),i.dataType&&c.push(i.dataType),n==null||n.attemptAutoclose("sync-output-data-output-map-data-type",this.id),{updated:D(c),added:D(s),removed:D(e),affected:D(y),self:i.dataType}}inferInputMapDataType(i,n=this.project.addChangeSet(new Z(this.project,x.sessionAuthor,M().toISOString(),this,!0,"infer-input-map-data-type-validate-data"))){var c,e,y;if(((c=i.declaration)==null?void 0:c.id)===Q.operation[Ce.Validate].inputs.entityToMatch.id){const{added:m,updated:v,removed:E,affected:b}=this.syncEntityToMatchInputMapDataType(i,n);return n==null||n.attemptAutoclose("infer-input-map-data-type",this.id),{updated:D(v),added:D(m),removed:D(E),affected:D(b),self:i.dataType}}if(((e=i.declaration)==null?void 0:e.id)===Q.operation[Ce.Validate].inputs.dataToValidate.id){const{added:m,updated:v,removed:E,affected:b}=this.syncDataToValidateInputMapDataType(i,n);return n==null||n.attemptAutoclose("infer-input-map-data-type",this.id),{updated:D(v),added:D(m),removed:D(E),affected:D(b),self:i.dataType}}const s=(y=i.declaration)==null?void 0:y.getDataType(n);if(s&&s.isResolved)return n==null||n.attemptAutoclose("infer-input-map-data-type-validate-data",this.id),{updated:[],added:[],removed:[],affected:[],self:s};if(i.readsValue){const m=hd(i.readsValue,n);return n==null||n.attemptAutoclose("infer-input-map-data-type-validate-data",this.id),{updated:[],added:[],removed:[],affected:[],self:m}}return n==null||n.attemptAutoclose("infer-input-map-data-type-validate-data",this.id),{updated:[],added:[],removed:[],affected:[],self:null}}inferOutputMapDataType(i,n=this.project.addChangeSet(new Z(this.project,x.sessionAuthor,M().toISOString(),this,!0,"infer-output-map-data-type-validate-data"))){var s;if(((s=i.declaration)==null?void 0:s.id)===Q.operation[Ce.Validate].dataType.entity.properties.outputEntity.id){const{added:c,updated:e,removed:y,affected:m}=this.syncOutputDataOutputMapDataType(i,n);return n==null||n.attemptAutoclose("infer-output-map-data-type-validate-data",this.id),{updated:D(e),added:D(c),removed:D(y),affected:D(m),self:i.dataType}}return{updated:[],added:[],removed:[],affected:[],self:null}}}class v1i extends Li{constructor(p){super(o_,p)}}class E1i extends Li{constructor(p){super(d_,p)}}class b1i extends Li{constructor(p){super(u_,p)}}class A1i extends Li{constructor(p){super(Ag,p)}}class g1i extends Li{constructor(p){super(jA,p)}}class I1i extends Li{constructor(p){super(nT,p)}}function rGe(o){const p=[new IOe(o),new AOe(o),new gOe(o),new m1i(o),new T1i(o),new A1i(o),new v1i(o),new b1i(o),new E1i(o),new g1i(o),new I1i(o)];return LP.forEach(i=>{p.some(n=>n.id===i.id)||p.push(new Li(i,o))}),p.forEach(i=>{i.initChildren(null),o.subscribeBuiltInInstance(i)}),o.operationDeclarations=p,p}class R1i extends No{constructor(i){super(In,i);I(this,"initialData");I(this,"id",Re.PERSISTED_ENTITY);I(this,"version","1");I(this,"name",Re.PERSISTED_ENTITY);I(this,"description",In.description);I(this,"type",d.BuiltInBaseEntity);I(this,"abstract",In.abstract);I(this,"static",In.static);I(this,"properties",[]);I(this,"methods",[]);I(this,"abstractMethods",[]);I(this,"extends",null);I(this,"errors",[]);I(this,"project");this.initialData=In,this.project=i,this.id=In.id,this.version=In.version,this.name=In.name,this.static=In.static,this.abstract=In.abstract,this.properties=this.initialData.properties.map(s=>{const c=he(s,this.project);return c.setParent(this,null),c.initChildren(null),c}),this.methods=this.initialData.methods.map(s=>{const c=he(s,this.project);return c.parent=this,c}),this.abstractMethods=this.initialData.abstractMethods.map(s=>{const c=he(s,this.project);return c.parent=this,c}),this.initialData.extends&&(this.extends=he(this.initialData.extends,this.project));const n=this.properties.find(s=>s.id===Q["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.identifier.id);if(!n)throw new Error("Path property not found in endpoint entity");n._codeNativeValueValidation=(s,c)=>vOe(s,c)}}const D1i=[];function nGe(o){const p=[new TOe(o),new bOe(o),new R1i(o)];return lV.forEach(i=>{!p.some(n=>n.id===i.id)&&!D1i.includes(i.id)&&p.push(new No(i,o))}),p.forEach(i=>{o.subscribeBuiltInInstance(i)}),o.builtInBaseEntities=p,p}function aGe(o){const p=[new ma(ue,o),new ma(st,o),new ma(we,o),new ma(ba,o),new ma(ht,o),new ma(It,o),new ma(at,o),new ma(Rl,o),new ma(Hi,o)];return p.forEach(i=>{o.subscribeBuiltInInstance(i)}),o.primitives=p,p}function sGe(o){const p=[new Li(MI,o)];return p.forEach(i=>{i.initChildren(null),o.subscribeBuiltInInstance(i)}),o.globalEventActionDescriptors=p,p}function lGe(o){const p=[new Li(ev,o),new Li(Jc,o),new Li(XT,o),new Li(wh,o),new Li(Oh,o),new Li(TI,o)];p.forEach(n=>{n.initChildren(null),o.subscribeBuiltInInstance(n)}),o.loopDeclarations=p;const i=[new Li(OI,o),new Li(QT,o),new Li(AI,o),new Li(UP,o),new Li(SP,o),new Li(vI,o)];return i.forEach(n=>{n.initChildren(null),o.subscribeBuiltInInstance(n)}),o.loopDeclarationsBodies=i,p}function oGe(o){const p=[new Ad(yV,o)];return p.forEach(i=>{i.initChildren(null),o.subscribeBuiltInInstance(i)}),o.valueDescriptors=p,p}function dGe(o){const p=[new Li(dV,o),new Li(oV,o),new Li(uV,o),new Li(pV,o)];return cV.forEach(i=>{p.some(n=>n.id===i.id)||p.push(new Li(i,o))}),p.forEach(i=>{i.initChildren(null),o.subscribeBuiltInInstance(i)}),o.conditionDeclarations=p,p}function Nm(o){return o&&typeof o.then=="function"}function w1i(o,p){const i=new Nn(o[0],{allBuiltInEntityIds:p.allBuiltInEntityIds}),n=o.map(c=>c.id),s={};return o.forEach(c=>{s[c.id]=c}),i.order=n,i.flatRecord=s,i.orderEntities(),i.order.map(c=>i.flatRecord[c])}function O1i(o,p){const i=new Nn(Object.values(o)[0],{allBuiltInEntityIds:p.allBuiltInEntityIds}),n=Object.keys(o);return i.order=n,i.flatRecord=o,i.orderEntities(),i.order}async function C1i(o,p){const i=J.YieldTracker.from(p),n=new Nn(o[0],{allBuiltInEntityIds:p.allBuiltInEntityIds}),s=o.map(e=>e.id),c={};for(const e of o)c[e.id]=e,await i.tick();return n.order=s,n.flatRecord=c,await n.orderEntitiesAsync({tracker:i}),n.order.map(e=>n.flatRecord[e])}async function _1i(o,p){const i=J.YieldTracker.from(p),n=new Nn(Object.values(o)[0],{allBuiltInEntityIds:p.allBuiltInEntityIds}),s=Object.keys(o);return n.order=s,n.flatRecord=o,await n.orderEntitiesAsync({tracker:i}),n.order}class Nn{constructor(p,i={}){I(this,"order",[]);I(this,"flatRecord",{});I(this,"allBuiltInEntityIds");I(this,"onGoingVisits",{});I(this,"cachedReferences",{});if(i.allBuiltInEntityIds&&(this.allBuiltInEntityIds=i.allBuiltInEntityIds),!p)return;const n={asyncInitialOrder:!1,...i};n.asyncInitialOrder?this.flattenAsync(p).then(()=>{this.orderEntitiesAsync({...n}).then(()=>{var s;(s=n.onOrdered)==null||s.call(n)})}):(this.flatten(p),this.orderEntities())}flatten(p){this.allBuiltInEntityIds||(this.allBuiltInEntityIds=new Set(DR()));const i=D(Le(p,new Set(this.allBuiltInEntityIds),{ignoreBuiltInBaseEntities:!0,diggestedBuiltInBaseEntitiesIds:this.allBuiltInEntityIds})),n=new Set;for(const s of i)this.flatRecord[s.id]=s,n.add(s.id);this.order=Array.from(n)}async flattenAsync(p,i={}){const n=J.YieldTracker.from(i);this.allBuiltInEntityIds||(this.allBuiltInEntityIds=await wR({tracker:n}));const s=await wu(await $e(p,new Set(this.allBuiltInEntityIds),{ignoreBuiltInBaseEntities:!0,diggestedBuiltInBaseEntitiesIds:this.allBuiltInEntityIds,tracker:n}),{tracker:n}),c=new Set;for(const e of s)this.flatRecord[e.id]=e,c.add(e.id),await n.tick();this.order=Array.from(c)}moveEntityAfterDependencies(p){const i=this.cachedReferences[p.id]||md(p,this.flatRecord,{ignoreBuiltInBaseEntities:!0,allBuiltInEntityIds:this.allBuiltInEntityIds});this.cachedReferences[p.id]=i;const{upstream:n}=i;for(const s of Object.keys(n)){const c=this.order.indexOf(s),e=this.order.indexOf(p.id);if(c>e)return this.order.splice(e,1),this.order.splice(c,0,p.id),!0}return!1}orderEntities(){let p=!1;for(let i=0;i<this.order.length;i++){const n=this.order[i],s=this.flatRecord[n];if(s||J.Logger.warn(`Entity with id ${n} not found in flatRecord. Skipping...`),this.moveEntityAfterDependencies(s)){p=!0;break}}p&&this.orderEntities()}async orderEntitiesAsync(p={}){let i=!1;const n=J.YieldTracker.from(p);for(let s=0;s<this.order.length;s++){const c=this.order[s],e=this.flatRecord[c];if(e||J.Logger.warn(`Entity with id ${c} not found in flatRecord. Skipping...`),this.moveEntityAfterDependencies(e)){i=!0;break}await n.tick()}i&&await this.orderEntitiesAsync({tracker:n})}getUpstreamOngoingDependenciesVisits(p,i){const n=this.cachedReferences[p]||md(this.flatRecord[p],this.flatRecord,{ignoreBuiltInBaseEntities:!0,allBuiltInEntityIds:this.allBuiltInEntityIds});this.cachedReferences[p]=n;const{upstream:s}=n,c={};return Object.entries(this.onGoingVisits[i]||{}).forEach(([e,y])=>{Object.keys(s).includes(e)&&(c[e]=y)}),c}getDownstreamOngoingDependenciesVisits(p,i){const n=Object.keys(this.onGoingVisits[i]||{}),s=new Set(n.flatMap(e=>{const y=this.cachedReferences[e]||md(this.flatRecord[e],this.flatRecord,{ignoreBuiltInBaseEntities:!0,allBuiltInEntityIds:this.allBuiltInEntityIds});return this.cachedReferences[e]=y,Object.keys(y.downstream)})),c={};return Array.from(s).forEach(e=>{e===p&&(c[e]=this.onGoingVisits[i][e])}),c}async settlePromises(p,i){const n=Object.values(p);n.length&&await Promise.all(n),Object.keys(p).forEach(s=>{delete this.onGoingVisits[i][s]})}visit(p){const i=this.order;for(const n of i)p(this.flatRecord[n],this.flatRecord);return this}reverseVisit(p){const i=this.order.slice().reverse();for(const n of i)p(this.flatRecord[n],this.flatRecord);return this}async visitAsync(p,i={}){const{parallelise:n}={parallelise:!0,...i},s=J.YieldTracker.from(i),c=this.order;if(!n){for(const y of c){const m=p(this.flatRecord[y],this.flatRecord);Nm(m)&&await m,await s.tick()}return this}const e=Math.random().toString(36).substring(7);this.onGoingVisits[e]={};for(const y of c){const m=this.getUpstreamOngoingDependenciesVisits(y,e);Object.keys(m).length&&await this.settlePromises(m,e);const v=p(this.flatRecord[y],this.flatRecord);Nm(v)&&(this.onGoingVisits[e][y]=v),await s.tick()}return await this.settlePromises(this.onGoingVisits[e],e),this.onGoingVisits[e]={},this}async reverseVisitAsync(p,i={}){const{parallelise:n}={parallelise:!0,...i},s=J.YieldTracker.from(i),c=this.order.slice().reverse();if(!n){for(const y of c){const m=p(this.flatRecord[y],this.flatRecord);Nm(m)&&await m,await s.tick()}return this}const e=Math.random().toString(36).substring(7);this.onGoingVisits[e]={};for(const y of c){const m=this.getDownstreamOngoingDependenciesVisits(y,e);Object.keys(m).length&&await this.settlePromises(m,e);const v=p(this.flatRecord[y],this.flatRecord);Nm(v)&&(this.onGoingVisits[e][y]=v),await s.tick()}return await this.settlePromises(this.onGoingVisits[e],e),this.onGoingVisits[e]={},this}}const bc={},$b={},Jm={empty:!1,enrich:!0,mock:!1,ignoreCache:!1,onFetch:async()=>null,manuallyInit:!1};function uGe(o,p={enrich:!0,shallowErrors:!1},i){const n={enrich:!0,shallowErrors:!1,...p},{enrich:s,shallowErrors:c}=n,e=o.project,y=o.record,m=IR(o.project,{shallowErrors:c},i);m.instances[e.id]=m;const v=new Nn(e,{allBuiltInEntityIds:m.diggestedBuiltInBaseEntitiesIds}),E=new Set;y[e.id]=e,E.add(e.id);const b=M().toISOString();Object.values(y).forEach(P=>{!P||v.allBuiltInEntityIds.has(P.id)||E.add(P.id)}),v.order=Array.from(E),v.flatRecord=y,v.orderEntities();const w=s?m.addChangeSet(new Z(m,x.sessionAuthor,b,m,!0,"project-init-from-fetch-result")):null;return v.visit(P=>{if(P.id===m.id)return;const $=he(P,m);try{$.hydrateAncestors(),$.addSelfToProject(null);const L=md(P);Object.keys(L.downstream).forEach(j=>{const F=m.get(j);F&&F.hydrateAncestors()})}catch(L){if(c)J.Logger.error("Error hydrating ancestors: ",L);else throw L}}),s?(v.visit(P=>{if(P.id===m.id)return;const $=m.get(P.id);$&&$.afterAllChildrenInitialized(w)}),m.afterAllChildrenInitialized(w)):sf(m,b).forEach($=>{$.remove({ignoreUpstream:!0},null)}),m.instancesList.forEach(P=>{P.previousVersion=null}),m.initialized=!0,m.emit(zt.PROJECT_INITIALIZED,m,w),w==null||w.attemptAutoclose("project-init-from-fetch-result",m.id),m}async function P1i(o,p={enrich:!0,shallowErrors:!1,yieldEvery:100},i){const n={enrich:!0,shallowErrors:!1,yieldEvery:100,...p},{enrich:s,shallowErrors:c,yieldEvery:e}=n,y=o.project,m=o.record,v=await RR(o.project,{shallowErrors:c,yieldEvery:e},i);v.instances[y.id]=v;const E=new Nn(void 0,{allBuiltInEntityIds:v.diggestedBuiltInBaseEntitiesIds});await E.flattenAsync(y,{yieldEvery:e}),await E.orderEntitiesAsync({yieldEvery:e});const b=new Set;m[y.id]=y,b.add(y.id);const w=M().toISOString();let P=0;for(const[j,F]of Object.entries(m))!F||E.allBuiltInEntityIds.has(F.id)||(b.add(F.id),++P%e===0&&await J.yieldToEventLoop());E.order=Array.from(b),E.flatRecord=m,await E.orderEntitiesAsync();const $=s?v.addChangeSet(new Z(v,x.sessionAuthor,w,v,!0,"project-init-from-fetch-result")):null;await E.visitAsync(j=>{if(j.id===v.id)return;const F=he(j,v);try{F.hydrateAncestors(),F.addSelfToProject(null);const q=md(j);Object.keys(q.downstream).forEach(X=>{const ne=v.get(X);ne&&ne.hydrateAncestors()})}catch(q){if(c)J.Logger.error("Error hydrating ancestors: ",q);else throw console.log("Error hydrating ancestors: ",q),q}},{yieldEvery:e}),s?(await E.visitAsync(j=>{if(j.id===v.id)return;const F=v.get(j.id);F&&F.afterAllChildrenInitialized($)},{yieldEvery:e}),v.afterAllChildrenInitialized($)):sf(v,w).forEach(F=>{F.remove({ignoreUpstream:!0},null)});let L=0;for(const j of v.instancesList)j.previousVersion=null,++L%e===0&&await J.yieldToEventLoop();return v.initialized=!0,v.emit(zt.PROJECT_INITIALIZED,v,$),$==null||$.attemptAutoclose("project-init-from-fetch-result",v.id),v}async function V1i(o,p=Jm){const i={...Jm,...p};if(i.empty)return{data:{project:{id:o.id,deletable:!0,editable:!0,type:d.Project,version:x.UUID.uuid(),createdAt:M().toISOString(),author:x.sessionAuthor,previousVersion:null,deleted:!1,name:null,description:null,projects:[],entities:[],operations:[],functions:[],variableDeclarations:[],variableInstances:[],functionCalls:[],conditions:[],loops:[],searches:[],events:[]},record:{}}};if(i.mock){const s={...Zx};return s.id=o.id,{data:{project:s,record:{}}}}return J.Logger.log("Fetching project from external API"),new Promise(async s=>{try{if(i.onFetch){const c=await i.onFetch(o.id);if(c){s({data:c});return}}else s({data:null})}catch(c){J.Logger.error("Error fetching project: ",c),s({data:null})}})}function IR(o,p={shallowErrors:!1},i){const n=new x(o,i);aGe(n),nGe(n),rGe(n),sGe(n),lGe(n),oGe(n),dGe(n);const s=p.allBuiltInIds??new Set([...n.getAllBuiltInIds(),...DR()]);return n.diggestedBuiltInBaseEntitiesIds=s,s.forEach(c=>{if(!n.builtInInstances[c]&&n.instances[c])n.builtInInstances[c]=n.instances[c],delete n.instances[c];else if(!n.builtInInstances[c]&&!p.shallowErrors)throw new Error(`Built in entity was not properly initialized: ${c}`)}),n.instances[n.id]=n,n}async function RR(o,p={shallowErrors:!1},i){const n=J.YieldTracker.from(p),s=new x(o,i);aGe(s),nGe(s),await J.yieldToEventLoop(),rGe(s),await J.yieldToEventLoop(),sGe(s),lGe(s),oGe(s),dGe(s),await J.yieldToEventLoop();const c=p.allBuiltInIds??new Set([...s.getAllBuiltInIds(),...await wR()]);s.diggestedBuiltInBaseEntitiesIds=c;for(const e of c){if(!s.builtInInstances[e]&&s.instances[e])s.builtInInstances[e]=s.instances[e],delete s.instances[e];else if(!s.builtInInstances[e]&&!p.shallowErrors)throw new Error(`Built in entity was not properly initialized: ${e}`);s.instances[e]&&delete s.instances[e],await n.tick()}return s.instances[s.id]=s,s}function sf(o,p){return o.instancesList.filter(n=>M(n.createdAt).isAfter(M(p)||!!n.previousVersion))}function N1i(o,{enrich:p,shallowErrors:i,...n}={enrich:!0,shallowErrors:!1},s){var P,$;const c=new Map,e=new Map;Object.keys(o.instances).forEach(L=>{if(o.diggestedBuiltInBaseEntitiesIds.has(L)){c.set(L,L),e.set(L,L);return}const j=o.get(L);if(!ox(j,{...o.instances,...o.builtInInstances}).every(ne=>!o.diggestedBuiltInBaseEntitiesIds.has(ne))){c.set(L,L),e.set(L,L);return}const X=x.UUID.uuid();c.set(L,X),e.set(X,L)});const y=((P=n.resetVersionOptions)==null?void 0:P.commonTimestamp)??M().toISOString(),m=o.toShallowJSON({seenEntityMaps:c});m.previousVersion=null,m.createdAt=y,m.version=x.UUID.uuid(),m.author=(($=n.resetVersionOptions)==null?void 0:$.author)??(x.sessionAuthor||"1");const v=IR(m,{shallowErrors:i,allBuiltInIds:o.diggestedBuiltInBaseEntitiesIds},s);v.instances[v.id]=v;const E=p?v.addChangeSet(new Z(v,x.sessionAuthor,y,v,!0,"project-clone")):null,b=new Nn(o,{allBuiltInEntityIds:o.diggestedBuiltInBaseEntitiesIds}),w=L4e(b.flatRecord,c);return b.visit(L=>{var X;const j=L.toShallowJSON({seenEntityMaps:c});j.previousVersion=null,j.createdAt=y,j.version=x.UUID.uuid(),j.author=((X=n.resetVersionOptions)==null?void 0:X.author)??(x.sessionAuthor||"1");const F=md(j,w);if(Object.keys(F.upstream).length){let ne=!1;if(Object.keys(F.upstream).forEach(ee=>{if(!ne&&(!v.get(ee)||v.getDeleted(ee))){ne=!0;return}}),ne)return}const q=he(j,v);q.hydrateAncestors(),q.addSelfToProject(E),E==null||E.add(q,H.Added),n.onVisit&&n.onVisit(j)}),p?(b.visit(L=>{if(L.id===v.id)return;const j=v.get(c.get(L.id));j&&j.afterAllChildrenInitialized(E)}),v.afterAllChildrenInitialized(E)):sf(v,y).forEach(j=>{j.remove({ignoreUpstream:!0},null)}),v.instancesList.forEach(L=>{L.previousVersion=null}),E==null||E.attemptAutoclose("project-clone",v.id),{project:v,maps:c}}async function x1i(o,{shallowErrors:p,...i}={shallowErrors:!1,yieldEvery:100}){var v,E;const n=J.YieldTracker.from(i),s=new Map,c=new Map;Object.keys(o.instances).forEach(b=>{if(o.diggestedBuiltInBaseEntitiesIds.has(b)){s.set(b,b),c.set(b,b);return}const w=x.UUID.uuid();s.set(b,w),c.set(w,b)});const e=((v=i.resetVersionOptions)==null?void 0:v.commonTimestamp)??M().toISOString(),y=o.toShallowJSON({seenEntityMaps:s});y.previousVersion=null,y.createdAt=e,y.version=x.UUID.uuid(),y.author=((E=i.resetVersionOptions)==null?void 0:E.author)??(x.sessionAuthor||"1");const m=await o.toFullProjectTransferAsync({tracker:n,seenEntityMaps:s,resetVersionOptions:i.resetVersionOptions,onVisit:i.onVisit});return{project:y,record:m.record,order:m.order,maps:s}}async function $1i(o,{enrich:p,shallowErrors:i,...n}={enrich:!0,shallowErrors:!1,yieldEvery:100},s){var $,L;const c=J.YieldTracker.from(n),e=new Map,y=new Map;Object.keys(o.instances).forEach(j=>{if(o.diggestedBuiltInBaseEntitiesIds.has(j)){e.set(j,j),y.set(j,j);return}const F=x.UUID.uuid();e.set(j,F),y.set(F,j)});const m=(($=n.resetVersionOptions)==null?void 0:$.commonTimestamp)??M().toISOString(),v=o.toShallowJSON({seenEntityMaps:e});v.previousVersion=null,v.createdAt=m,v.version=x.UUID.uuid(),v.author=((L=n.resetVersionOptions)==null?void 0:L.author)??(x.sessionAuthor||"1");const E=await RR(v,{shallowErrors:i,tracker:c},s);E.diggestedBuiltInBaseEntitiesIds=o.diggestedBuiltInBaseEntitiesIds,E.instances[E.id]=E;const b=p?E.addChangeSet(new Z(E,x.sessionAuthor,m,E,!0,"project-clone")):null,w=new Nn(void 0,{allBuiltInEntityIds:o.diggestedBuiltInBaseEntitiesIds}),P=await o.toFullProjectTransferAsync({tracker:c,seenEntityMaps:e,resetVersionOptions:n.resetVersionOptions,onVisit:n.onVisit});w.flatRecord=P.record,w.order=P.order,await w.visitAsync(j=>{var ne;if(o.diggestedBuiltInBaseEntitiesIds.has(j.id))return;const F=j;F.previousVersion=null,F.createdAt=m,F.version=x.UUID.uuid(),F.author=((ne=n.resetVersionOptions)==null?void 0:ne.author)??(x.sessionAuthor||"1");const q=md(F,w.flatRecord);if(Object.keys(q.upstream).length){let ee=!1;if(Object.keys(q.upstream).forEach(pe=>{if(!ee&&(!E.get(pe)||E.getDeleted(pe))){ee=!0;return}}),ee)return}const X=he(F,E);X.hydrateAncestors(),X.addSelfToProject(b),b==null||b.add(X,H.Added)},{tracker:c}),p?(await w.visitAsync(j=>{if(j.id===E.id||o.diggestedBuiltInBaseEntitiesIds.has(j.id))return;const F=E.get(e.get(j.id));F&&F.afterAllChildrenInitialized(b)},{tracker:c}),E.afterAllChildrenInitialized(b)):sf(E,m).forEach(F=>{F.remove({ignoreUpstream:!0},null)});for(const j of E.instancesList)j.previousVersion=null,await c.tick();return b==null||b.attemptAutoclose("project-clone",E.id),{project:E,maps:e}}function pGe(o,{enrich:p,shallowErrors:i}={enrich:!0,shallowErrors:!1},n){const s=IR(o,{shallowErrors:i},n),c=M().toISOString(),e=p?s.addChangeSet(new Z(s,x.sessionAuthor,c,s,!0,"project-init")):null;e&&(e.type=kI.Automatic);const y=new Nn(o,{allBuiltInEntityIds:s.diggestedBuiltInBaseEntitiesIds});return y.visit(m=>{const v=he(m,s);v.hydrateAncestors(),v.addSelfToProject(e)}),p?(y.visit(m=>{if(m.id===s.id)return;const v=s.get(m.id);v&&v.afterAllChildrenInitialized(e)}),s.afterAllChildrenInitialized(e)):(sf(s,c).forEach(E=>{E.remove({ignoreUpstream:!0},null)}),new Nn(s,{allBuiltInEntityIds:s.diggestedBuiltInBaseEntitiesIds}).visit(E=>{E.initialized=!0,E.captureVersion()})),s.initialized=!0,s.emit(zt.PROJECT_INITIALIZED,s,e),e==null||e.attemptAutoclose("project-init",s.id),s}async function L1i(o,{enrich:p,shallowErrors:i,yieldEvery:n}={enrich:!0,shallowErrors:!1,yieldEvery:100},s){const c=await RR(o,{shallowErrors:i,yieldEvery:n},s),e=M().toISOString(),y=p?c.addChangeSet(new Z(c,x.sessionAuthor,e,c,!0,"project-init")):null;y&&(y.type=kI.Automatic);const m=new Nn(void 0,{allBuiltInEntityIds:c.diggestedBuiltInBaseEntitiesIds});if(await m.flattenAsync(o,{yieldEvery:n}),await m.orderEntitiesAsync({yieldEvery:n}),await m.visitAsync(v=>{const E=he(v,c);E.hydrateAncestors(),E.addSelfToProject(y)},{yieldEvery:n}),p)await m.visitAsync(v=>{if(v.id===c.id)return;const E=c.get(v.id);E&&E.afterAllChildrenInitialized(y)},{yieldEvery:n}),c.afterAllChildrenInitialized(y);else{sf(c,e).forEach(b=>{b.remove({ignoreUpstream:!0},null)});const E=new Nn(void 0,{allBuiltInEntityIds:c.diggestedBuiltInBaseEntitiesIds});await E.flattenAsync(c,{yieldEvery:n}),await E.orderEntitiesAsync({yieldEvery:n}),await E.visitAsync(b=>{b.initialized=!0,b.captureVersion()},{yieldEvery:n})}return c.initialized=!0,c.emit(zt.PROJECT_INITIALIZED,c,y),y==null||y.attemptAutoclose("project-init",c.id),c}async function M1i(o,p=Jm,i){const n={...Jm,...p};if(o.id&&bc[o.id]&&!n.ignoreCache)return bc[o.id];if(o.id&&$b[o.id]&&!n.ignoreCache)return await $b[o.id],bc[o.id];const s=V1i(o,n);o.id&&($b[o.id]=s);const c=await s;if(c.data){let e;return n.mock?e=pGe(Zx,{enrich:!!n.enrich},i):c.data instanceof x?e=c.data:e=uGe(c.data,{enrich:!!n.enrich},i),bc[o.id]=e,o.id&&delete $b[o.id],e}return null}function B1i(o){return bc[o.id]&&delete bc[o.id],null}function zN(o){return o==null||o===""}function Pr(o){return o!=null&&o.valueAsType?!1:zN(o==null?void 0:o.value)}function cGe(o,p){if(o===p||!o&&!p)return!0;if(!o||!p||o.name===le.EntityTemplate&&p.name!==le.EntityTemplate||p.name===le.EntityTemplate&&o.name!==le.EntityTemplate)return!1;if(o.name===le.ActionDescriptor&&p.name!==le.ActionDescriptor||p.name===le.ActionDescriptor&&o.name!==le.ActionDescriptor)return!1;if(o.valueAsTypeSingle&&!p.valueAsTypeSingle||p.valueAsTypeSingle&&!o.valueAsTypeSingle)return!1;if(o.valueAsTypeList&&!p.valueAsTypeList||p.valueAsTypeList&&!o.valueAsTypeList)return!1;if(o.valueAsTypeSingle&&p.valueAsTypeSingle){if(o.valueAsTypeSingle.id!==p.valueAsTypeSingle.id)return!1}else if(o.valueAsTypeList&&p.valueAsTypeList){if(o.valueAsTypeList.length!==p.valueAsTypeList.length)return!1;for(let i=0;i<o.valueAsTypeList.length;i++)if(o.valueAsTypeList[i].id!==p.valueAsTypeList[i].id)return!1}else if(!o.valueAsType&&!p.valueAsType&&o.value!==p.value)return!1;return!0}function DR(){const o=new Set;return new Set(hV.flatMap(i=>Le(i,o)).map(i=>i.id))}function eo(o){return[...o.calledByEntry||[],...o.calledByError||[],...o.calledBySuccess||[]].filter(p=>p.type!==d.GenericReference)}function fGe(o,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(o.id))return[];if(p.add(o.id),o.type!==d.ActionDescriptor)throw new Error("Entity must be an action descriptor to be flattened");return[o,...o.inputs.flatMap(n=>Le(n,p,i)),...o.dataType?Le(o.dataType,p,i):[],...o.error?Le(o.error,p,i):[],...o.parent?Le(o.parent,p,i):[]]}function yGe(o,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(o.id))return[];if(p.add(o.id),o.type!==d.ArgumentDeclaration)throw new Error("Entity must be an argument declaration to be flattened");return[o,...o.defaultValue?Le(o.defaultValue,p):[],...o.writesValues.flatMap(n=>Le(n,p,i)),...o.implements.flatMap(n=>Le(n,p,i)),...o.dataType?Le(o.dataType,p,i):[],...o.parent?Le(o.parent,p,i):[]]}function hGe(o,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(o.id))return[];if(p.add(o.id),o.type!==d.BreakStatement)throw new Error("Entity must be a break statement to be flattened");return[o,...o.outputs.flatMap(n=>Le(n,p,i)),...o.throws?Le(o.throws,p,i):[],...o.dataType?Le(o.dataType,p,i):[],...o.readsValue?Le(o.readsValue,p,i):[],...(eo(o)||[]).flatMap(n=>Le(n,p,i)),...o.parent?Le(o.parent,p,i):[]]}function mGe(o,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(o.id))return[];if(p.add(o.id),o.type!==d.BuiltInBaseEntity)throw new Error("Entity must be a built-in base entity to be flattened");return[o,...(o.properties||[]).flatMap(n=>Le(n,p,i)),...(o.methods||[]).flatMap(n=>Le(n,p,i)),...(o.abstractMethods||[]).flatMap(n=>Le(n,p,i)),...o.allPropertiesImplement?Le(o.allPropertiesImplement,p,i):[],...o.additionalPropertiesDataType?Le(o.additionalPropertiesDataType,p,i):[],...o.extends?Le(o.extends,p,i):[]]}function TGe(o,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(o.id))return[];if(p.add(o.id),o.type!==d.Condition)throw new Error("Entity must be a condition to be flattened");return[o,...(o.andChildrenGroup||[]).flatMap(n=>Le(n,p,i)),...(o.orChildrenGroup||[]).flatMap(n=>Le(n,p,i)),...(o.inputs||[]).flatMap(n=>Le(n,p,i)),...(o.successCalls||[]).flatMap(n=>Le(n,p,i)),...(o.errorCalls||[]).flatMap(n=>Le(n,p,i)),...(eo(o)||[]).flatMap(n=>Le(n,p,i)),...o.parent?Le(o.parent,p,i):[]]}function vGe(o,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(o.id))return[];if(p.add(o.id),o.type!==d.ContinueStatement)throw new Error("Entity must be a continue statement to be flattened");return[o,...o.outputs.flatMap(n=>Le(n,p,i)),...o.readsValue?Le(o.readsValue,p,i):[],...o.throws?Le(o.throws,p,i):[],...o.dataType?Le(o.dataType,p,i):[],...(eo(o)||[]).flatMap(n=>Le(n,p,i)),...o.parent?Le(o.parent,p,i):[]]}function EGe(o,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(o.id))return[];if(p.add(o.id),o.type!==d.DefinitionEntity)throw new Error("Entity must be a definition entity to be flattened");return[o,...o.extends?Le(o.extends,p,i):[],...(o.implements||[]).flatMap(n=>Le(n,p,i)),...(o.properties||[]).flatMap(n=>Le(n,p,i)),...(o.methods||[]).flatMap(n=>Le(n,p,i)),...(o.abstractMethods||[]).flatMap(n=>Le(n,p,i)),...o.allPropertiesImplement?Le(o.allPropertiesImplement,p,i):[],...o.additionalPropertiesDataType?Le(o.additionalPropertiesDataType,p,i):[],...o.parent?Le(o.parent,p,i):[]]}function bGe(o,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(o.id))return[];if(p.add(o.id),o.type!==d.DataType)throw new Error("Entity must be a data type to be flattened");return[o,...(o.andChildrenGroup||[]).flatMap(n=>Le(n,p,i)),...(o.orChildrenGroup||[]).flatMap(n=>Le(n,p,i)),...o.entity?Le(o.entity,p,i):[],...o.foreignKeyRef?Le(o.foreignKeyRef,p,i):[],...o.parent?Le(o.parent,p,i):[]]}function AGe(o,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(o.id))return[];if(p.add(o.id),o.type!==d.FunctionCall)throw new Error("Entity must be a function call to be flattened");return[o,...(o.inputs||[]).flatMap(n=>Le(n,p,i)),...(o.outputs||[]).flatMap(n=>Le(n,p,i)),...o.error?Le(o.error,p,i):[],...(eo(o)||[]).flatMap(n=>Le(n,p,i)),...(o.successCalls||[]).flatMap(n=>Le(n,p,i)),...(o.errorCalls||[]).flatMap(n=>Le(n,p,i)),...(o.writesValues||[]).flatMap(n=>Le(n,p,i)),...o.parent?Le(o.parent,p,i):[]]}function gGe(o,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(o.id))return[];if(p.add(o.id),o.type!==d.FunctionDeclaration)throw new Error("Entity must be a function declaration to be flattened");return[o,...(o.inputs||[]).flatMap(n=>Le(n,p,i)),...(o.calls||[]).flatMap(n=>Le(n,p,i)),...o.dataType?Le(o.dataType,p,i):[],...o.implements?Le(o.implements,p,i):[],...o.parent?Le(o.parent,p,i):[]]}function IGe(o,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(o.id))return[];if(p.add(o.id),o.type!==d.GlobalEvent)throw new Error("Entity must be a global event to be flattened");return[o,...(o.inputs||[]).flatMap(n=>Le(n,p,i)),...(o.calls||[]).flatMap(n=>Le(n,p,i)),...o.implements?Le(o.implements,p,i):[],...o.parent?Le(o.parent,p,i):[]]}function RGe(o,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(o.id))return[];if(p.add(o.id),o.type!==d.InputMap)throw new Error("Entity must be an input map to be flattened");return[o,...o.readsValue?Le(o.readsValue,p,i):[],...o.declaration?Le(o.declaration,p,i):[],...o.defaultValue?Le(o.defaultValue,p,i):[],...o.parent?Le(o.parent,p,i):[]]}function DGe(o,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(o.id))return[];if(p.add(o.id),o.type!==d.InstalledProject)throw new Error("Entity must be an installed project to be flattened");return[o,...(o.functions||[]).flatMap(n=>Le(n,p,i)),...(o.events||[]).flatMap(n=>Le(n,p,i)),...o.parent?Le(o.parent,p,i):[]]}function wGe(o,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(o.id))return[];if(p.add(o.id),o.type!==d.InternalCall)throw new Error("Entity must be an internal call to be flattened");return[o,...(o.successCalls||[]).flatMap(n=>Le(n,p,i)),...(o.errorCalls||[]).flatMap(n=>Le(n,p,i)),...(o.inputs||[]).flatMap(n=>Le(n,p,i)),...(o.outputs||[]).flatMap(n=>Le(n,p,i)),...(eo(o)||[]).flatMap(n=>Le(n,p,i)),...o.error?Le(o.error,p,i):[],...(o.writesValues||[]).flatMap(n=>Le(n,p,i)),...o.parent?Le(o.parent,p,i):[]]}function OGe(o,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(o.id))return[];if(p.add(o.id),o.type!==d.LiteralValue)throw new Error("Entity must be a literal value to be flattened");return[o,...o.valueAsTypeSingle?Le(o.valueAsTypeSingle,p,i):[],...o.valueAsTypeList&&Array.isArray(o.valueAsTypeList)?o.valueAsTypeList.flatMap(n=>Le(n,p,i)):[],...o.parent?Le(o.parent,p,i):[]]}function CGe(o,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(o.id))return[];if(p.add(o.id),o.type!==d.Loop)throw new Error("Entity must be a loop to be flattened");return[o,...(o.inputs||[]).flatMap(n=>Le(n,p,i)),...(o.outputs||[]).flatMap(n=>Le(n,p,i)),...(o.successCalls||[]).flatMap(n=>Le(n,p,i)),...(o.errorCalls||[]).flatMap(n=>Le(n,p,i)),...o.error?Le(o.error,p,i):[],...o.dataType?Le(o.dataType,p,i):[],...o.body?Le(o.body,p,i):[],...(eo(o)||[]).flatMap(n=>Le(n,p,i)),...(o.writesValues||[]).flatMap(n=>Le(n,p,i)),...o.parent?Le(o.parent,p,i):[]]}function _Ge(o,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(o.id))return[];if(p.add(o.id),o.type!==d.Operation)throw new Error("Entity must be an operation to be flattened");return[o,...(o.successCalls||[]).flatMap(n=>Le(n,p,i)),...(o.errorCalls||[]).flatMap(n=>Le(n,p,i)),...(o.inputs||[]).flatMap(n=>Le(n,p,i)),...(o.outputs||[]).flatMap(n=>Le(n,p,i)),...(o.writesValues||[]).flatMap(n=>Le(n,p,i)),...o.error?Le(o.error,p,i):[],...(eo(o)||[]).flatMap(n=>Le(n,p,i)),...o.parent?Le(o.parent,p,i):[]]}function PGe(o,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(o.id))return[];if(p.add(o.id),o.type!==d.OutputMap)throw new Error("Entity must be an output map to be flattened");return[o,...(o.writesValues||[]).flatMap(n=>Le(n,p,i)),...o.declaration?Le(o.declaration,p,i):[],...o.parent?Le(o.parent,p,i):[]]}function VGe(o,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(o.id))return[];if(p.add(o.id),o.type!==d.PrimitiveEntity)throw new Error("Entity must be a primitive entity to be flattened");return[o,...(o.properties||[]).flatMap(n=>Le(n,p,i)),...(o.methods||[]).flatMap(n=>Le(n,p,i)),...(o.abstractMethods||[]).flatMap(n=>Le(n,p,i))]}function NGe(o,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(o.id))return[];if(p.add(o.id),o.type!==d.Project)throw new Error("Entity must be a project to be flattened");return[o,...(o.entities||[]).flatMap(n=>Le(n,p,i)),...(o.functions||[]).flatMap(n=>Le(n,p,i)),...(o.events||[]).flatMap(n=>Le(n,p,i)),...(o.projects||[]).flatMap(n=>Le(n,p,i)),...(o.variableDeclarations||[]).flatMap(n=>Le(n,p,i)),...(o.variableInstances||[]).flatMap(n=>Le(n,p,i)),...(o.operations||[]).flatMap(n=>Le(n,p,i)),...(o.conditions||[]).flatMap(n=>Le(n,p,i)),...(o.functionCalls||[]).flatMap(n=>Le(n,p,i)),...(o.projects||[]).flatMap(n=>Le(n,p,i)),...(o.loops||[]).flatMap(n=>Le(n,p,i)),...(o.searches||[]).flatMap(n=>Le(n,p,i))]}function xGe(o,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(o.id))return[];if(p.add(o.id),o.type!==d.Property)throw new Error("Entity must be a property to be flattened");return[o,...o.defaultValue?Le(o.defaultValue,p,i):[],...o.dataType?Le(o.dataType,p,i):[],...o.parent?Le(o.parent,p,i):[]]}function $Ge(o,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(o.id))return[];if(p.add(o.id),o.type!==d.ReturnStatement)throw new Error("Entity must be a return statement to be flattened");return[o,...(o.outputs||[]).flatMap(n=>Le(n,p,i)),...o.throws?Le(o.throws,p,i):[],...o.readsValue?Le(o.readsValue,p,i):[],...o.dataType?Le(o.dataType,p,i):[],...(eo(o)||[]).flatMap(n=>Le(n,p,i)),...o.parent?Le(o.parent,p,i):[]]}function LGe(o,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(o.id))return[];if(p.add(o.id),o.type!==d.Search)throw new Error("Entity must be a search to be flattened");return[o,...(o.successCalls||[]).flatMap(n=>Le(n,p,i)),...(o.errorCalls||[]).flatMap(n=>Le(n,p,i)),...(o.inputsDeclarations||[]).flatMap(n=>Le(n,p,i)),...(o.inputs||[]).flatMap(n=>Le(n,p,i)),...(o.writesValues||[]).flatMap(n=>Le(n,p,i)),...(o.outputs||[]).flatMap(n=>Le(n,p,i)),...o.error?Le(o.error,p,i):[],...o.dataType?Le(o.dataType,p,i):[],...(eo(o)||[]).flatMap(n=>Le(n,p,i)),...o.parent?Le(o.parent,p,i):[]]}function MGe(o,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(o.id))return[];if(p.add(o.id),o.type!==d.ValueDescriptor)throw new Error("Entity must be a value descriptor to be flattened");return[o,...o.defaultValue?Le(o.defaultValue,p,i):[],...o.dataType?Le(o.dataType,p,i):[],...o.parent?Le(o.parent,p,i):[]]}function BGe(o,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(o.id))return[];if(p.add(o.id),o.type!==d.VariableDeclaration)throw new Error("Entity must be a variable declaration to be flattened");return[o,...(o.successCalls||[]).flatMap(n=>Le(n,p,i)),...(o.errorCalls||[]).flatMap(n=>Le(n,p,i)),...(o.inputs||[]).flatMap(n=>Le(n,p,i)),...(o.outputs||[]).flatMap(n=>Le(n,p,i)),...(o.internalCalls||[]).flatMap(n=>Le(n,p,i)),...(o.writesValues||[]).flatMap(n=>Le(n,p,i)),...o.readsValue?Le(o.readsValue,p,i):[],...o.defaultValue?Le(o.defaultValue,p,i):[],...(eo(o)||[]).flatMap(n=>Le(n,p,i)),...o.dataType?Le(o.dataType,p,i):[],...o.parent?Le(o.parent,p,i):[]]}function GGe(o,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(o.id))return[];if(p.add(o.id),o.type!==d.VariableInstance)throw new Error("Entity must be a variable instance to be flattened");return[o,...(o.successCalls||[]).flatMap(n=>Le(n,p,i)),...(o.errorCalls||[]).flatMap(n=>Le(n,p,i)),...(o.inputs||[]).flatMap(n=>Le(n,p,i)),...(o.outputs||[]).flatMap(n=>Le(n,p,i)),...(o.internalCalls||[]).flatMap(n=>Le(n,p,i)),...(o.writesValues||[]).flatMap(n=>Le(n,p,i)),...o.readsValue?Le(o.readsValue,p,i):[],...o.defaultValue?Le(o.defaultValue,p,i):[],...(eo(o)||[]).flatMap(n=>Le(n,p,i)),...o.declaration?Le(o.declaration,p,i):[],...o.parent?Le(o.parent,p,i):[]]}function Le(o,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(!o)throw new Error("Entity must be defined to be flattened");if(o.type===d.GenericReference)return[];const n=i.ignoreBuiltInBaseEntities?i.diggestedBuiltInBaseEntitiesIds??new Set(DR()):new Set;if(i.diggestedBuiltInBaseEntitiesIds=n,i.ignoreBuiltInBaseEntities&&(Hn.includes(o.type)||n.has(o.id)))return[];if(p.has(o.id))return[];switch(o.type){case d.FunctionCall:return AGe(o,p,i);case d.Operation:return _Ge(o,p,i);case d.Condition:return TGe(o,p,i);case d.Loop:return CGe(o,p,i);case d.Search:return LGe(o,p,i);case d.GlobalEvent:return IGe(o,p,i);case d.ReturnStatement:return $Ge(o,p,i);case d.ContinueStatement:return vGe(o,p,i);case d.BreakStatement:return hGe(o,p,i);case d.VariableDeclaration:return BGe(o,p,i);case d.DefinitionEntity:return EGe(o,p,i);case d.FunctionDeclaration:return gGe(o,p,i);case d.Project:return NGe(o,p,i);case d.ActionDescriptor:return fGe(o,p,i);case d.ArgumentDeclaration:return yGe(o,p,i);case d.ValueDescriptor:return MGe(o,p,i);case d.InputMap:return RGe(o,p,i);case d.OutputMap:return PGe(o,p,i);case d.DataType:return bGe(o,p,i);case d.InstalledProject:return DGe(o,p,i);case d.InternalCall:return wGe(o,p,i);case d.LiteralValue:return OGe(o,p,i);case d.Property:return xGe(o,p,i);case d.VariableInstance:return GGe(o,p,i);case d.BuiltInBaseEntity:return i.ignoreBuiltInBaseEntities?[]:mGe(o,p,i);case d.PrimitiveEntity:return i.ignoreBuiltInBaseEntities?[]:VGe(o,p,i)}return[]}async function wR(o={}){const p=new Set,i=J.YieldTracker.from(o),n=new Set;for(const s of hV){const c=await $e(s,p,{ignoreBuiltInBaseEntities:!1,tracker:i});for(const e of c)n.add(e.id),await i.tick()}return n}function to(o){return[...o.calledByEntry||[],...o.calledByError||[],...o.calledBySuccess||[]].filter(p=>p.type!==d.GenericReference)}async function kGe(o,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(o.id))return[];if(p.add(o.id),o.type!==d.ActionDescriptor)throw new Error("Entity must be an action descriptor to be flattened");const n=J.YieldTracker.from(i),s=[o];await n.tick();const c={...i,tracker:n};delete c.yieldEvery;for(const e of o.inputs)s.push(...await $e(e,p,c));return o.dataType&&s.push(...await $e(o.dataType,p,c)),o.error&&s.push(...await $e(o.error,p,c)),o.parent&&s.push(...await $e(o.parent,p,c)),s}async function jGe(o,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(o.id))return[];if(p.add(o.id),o.type!==d.ArgumentDeclaration)throw new Error("Entity must be an argument declaration to be flattened");const n=J.YieldTracker.from(i),s=[o];await n.tick();const c={...i,tracker:n};delete c.yieldEvery,o.dataType&&s.push(...await $e(o.dataType,p,c)),o.parent&&s.push(...await $e(o.parent,p,c)),o.defaultValue&&s.push(...await $e(o.defaultValue,p,c));for(const e of o.writesValues||[])s.push(...await $e(e,p,c));for(const e of o.implements||[])s.push(...await $e(e,p,c));return s}async function UGe(o,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(o.id))return[];if(p.add(o.id),o.type!==d.BreakStatement)throw new Error("Entity must be a break statement to be flattened");const n=J.YieldTracker.from(i),s=[o];await n.tick();const c={...i,tracker:n};delete c.yieldEvery;for(const y of o.outputs)s.push(...await $e(y,p,c));o.parent&&s.push(...await $e(o.parent,p,c)),o.throws&&s.push(...await $e(o.throws,p,c)),o.dataType&&s.push(...await $e(o.dataType,p,c)),o.readsValue&&s.push(...await $e(o.readsValue,p,c));const e=to(o);for(const y of e)s.push(...await $e(y,p,c));return s}async function KGe(o,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(o.id))return[];if(p.add(o.id),o.type!==d.BuiltInBaseEntity)throw new Error("Entity must be a built-in base entity to be flattened");const n=J.YieldTracker.from(i),s=[o];await n.tick();const c={...i,tracker:n};delete c.yieldEvery;for(const e of o.properties||[])s.push(...await $e(e,p,c));for(const e of o.methods||[])s.push(...await $e(e,p,c));for(const e of o.abstractMethods||[])s.push(...await $e(e,p,c));return o.allPropertiesImplement&&s.push(...await $e(o.allPropertiesImplement,p,c)),o.additionalPropertiesDataType&&s.push(...await $e(o.additionalPropertiesDataType,p,c)),o.extends&&s.push(...await $e(o.extends,p,c)),s}async function FGe(o,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(o.id))return[];if(p.add(o.id),o.type!==d.Condition)throw new Error("Entity must be a condition to be flattened");const n=J.YieldTracker.from(i),s=[o];await n.tick();const c={...i,tracker:n};if(delete c.yieldEvery,o.andChildrenGroup&&Array.isArray(o.andChildrenGroup))for(const y of o.andChildrenGroup)s.push(...await $e(y,p,c));if(o.orChildrenGroup&&Array.isArray(o.orChildrenGroup))for(const y of o.orChildrenGroup)s.push(...await $e(y,p,c));for(const y of o.inputs)s.push(...await $e(y,p,c));for(const y of o.successCalls)s.push(...await $e(y,p,c));for(const y of o.errorCalls)s.push(...await $e(y,p,c));const e=to(o);for(const y of e)s.push(...await $e(y,p,c));return o.parent&&s.push(...await $e(o.parent,p,c)),s}async function SGe(o,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(o.id))return[];if(p.add(o.id),o.type!==d.ContinueStatement)throw new Error("Entity must be a continue statement to be flattened");const n=J.YieldTracker.from(i),s=[o];await n.tick();const c={...i,tracker:n};delete c.yieldEvery;for(const y of o.outputs)s.push(...await $e(y,p,c));const e=to(o);for(const y of e)s.push(...await $e(y,p,c));return o.parent&&s.push(...await $e(o.parent,p,c)),o.throws&&s.push(...await $e(o.throws,p,c)),o.dataType&&s.push(...await $e(o.dataType,p,c)),o.readsValue&&s.push(...await $e(o.readsValue,p,c)),s}async function qGe(o,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(o.id))return[];if(p.add(o.id),o.type!==d.DefinitionEntity)throw new Error("Entity must be a definition entity to be flattened");const n=J.YieldTracker.from(i),s=[o];await n.tick();const c={...i,tracker:n};delete c.yieldEvery;for(const e of o.properties)s.push(...await $e(e,p,c));for(const e of o.methods)s.push(...await $e(e,p,c));for(const e of o.abstractMethods)s.push(...await $e(e,p,c));for(const e of o.implements)s.push(...await $e(e,p,c));return o.extends&&s.push(...await $e(o.extends,p,c)),o.parent&&s.push(...await $e(o.parent,p,c)),o.additionalPropertiesDataType&&s.push(...await $e(o.additionalPropertiesDataType,p,c)),o.allPropertiesImplement&&s.push(...await $e(o.allPropertiesImplement,p,c)),s}async function ZGe(o,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(o.id))return[];if(p.add(o.id),o.type!==d.DataType)throw new Error("Entity must be a data type to be flattened");const n=J.YieldTracker.from(i),s=[o];await n.tick();const c={...i,tracker:n};if(delete c.yieldEvery,o.parent&&s.push(...await $e(o.parent,p,c)),o.foreignKeyRef&&s.push(...await $e(o.foreignKeyRef,p,c)),o.entity&&s.push(...await $e(o.entity,p,c)),o.orChildrenGroup)for(const e of o.orChildrenGroup)s.push(...await $e(e,p,c));if(o.andChildrenGroup)for(const e of o.andChildrenGroup)s.push(...await $e(e,p,c));return s}async function HGe(o,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(o.id))return[];if(p.add(o.id),o.type!==d.FunctionCall)throw new Error("Entity must be a function call to be flattened");const n=J.YieldTracker.from(i),s=[o];await n.tick();const c={...i,tracker:n};delete c.yieldEvery;for(const y of o.inputs)s.push(...await $e(y,p,c));for(const y of o.outputs)s.push(...await $e(y,p,c));o.error&&s.push(...await $e(o.error,p,c));const e=to(o);for(const y of e)s.push(...await $e(y,p,c));for(const y of o.successCalls)s.push(...await $e(y,p,c));for(const y of o.errorCalls)s.push(...await $e(y,p,c));for(const y of o.writesValues)s.push(...await $e(y,p,c));return o.parent&&s.push(...await $e(o.parent,p,c)),s}async function WGe(o,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(o.id))return[];if(p.add(o.id),o.type!==d.FunctionDeclaration)throw new Error("Entity must be a function declaration to be flattened");const n=J.YieldTracker.from(i),s=[o];await n.tick();const c={...i,tracker:n};delete c.yieldEvery,o.parent&&s.push(...await $e(o.parent,p,c)),o.implements&&s.push(...await $e(o.implements,p,c)),o.dataType&&s.push(...await $e(o.dataType,p,c));for(const e of o.inputs)s.push(...await $e(e,p,c));for(const e of o.calls)s.push(...await $e(e,p,c));return s}async function zGe(o,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(o.id))return[];if(p.add(o.id),o.type!==d.GlobalEvent)throw new Error("Entity must be a global event to be flattened");const n=J.YieldTracker.from(i),s=[o];await n.tick();const c={...i,tracker:n};delete c.yieldEvery,o.parent&&s.push(...await $e(o.parent,p,c)),o.implements&&s.push(...await $e(o.implements,p,c));for(const e of o.inputs)s.push(...await $e(e,p,c));for(const e of o.calls)s.push(...await $e(e,p,c));return s}async function JGe(o,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(o.id))return[];if(p.add(o.id),o.type!==d.InputMap)throw new Error("Entity must be an input map to be flattened");const n=J.YieldTracker.from(i),s=[o];await n.tick();const c={...i,tracker:n};return delete c.yieldEvery,o.parent&&s.push(...await $e(o.parent,p,c)),o.declaration&&s.push(...await $e(o.declaration,p,c)),o.readsValue&&s.push(...await $e(o.readsValue,p,c)),o.dataType&&s.push(...await $e(o.dataType,p,c)),o.defaultValue&&s.push(...await $e(o.defaultValue,p,c)),s}async function YGe(o,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(o.id))return[];if(p.add(o.id),o.type!==d.InstalledProject)throw new Error("Entity must be an installed project to be flattened");const n=J.YieldTracker.from(i),s=[o];await n.tick();const c={...i,tracker:n};delete c.yieldEvery;for(const e of o.functions)s.push(...await $e(e,p,c));for(const e of o.events)s.push(...await $e(e,p,c));return o.parent&&s.push(...await $e(o.parent,p,c)),s}async function XGe(o,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(o.id))return[];if(p.add(o.id),o.type!==d.InternalCall)throw new Error("Entity must be an internal call to be flattened");const n=J.YieldTracker.from(i),s=[o];await n.tick();const c={...i,tracker:n};delete c.yieldEvery;for(const y of o.inputs)s.push(...await $e(y,p,c));for(const y of o.outputs)s.push(...await $e(y,p,c));o.error&&s.push(...await $e(o.error,p,c));const e=to(o);for(const y of e)s.push(...await $e(y,p,c));for(const y of o.successCalls)s.push(...await $e(y,p,c));for(const y of o.errorCalls)s.push(...await $e(y,p,c));for(const y of o.writesValues)s.push(...await $e(y,p,c));return o.parent&&s.push(...await $e(o.parent,p,c)),s}async function QGe(o,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(o.id))return[];if(p.add(o.id),o.type!==d.LiteralValue)throw new Error("Entity must be a literal value to be flattened");const n=J.YieldTracker.from(i),s=[o];await n.tick();const c={...i,tracker:n};if(delete c.yieldEvery,o.valueAsTypeSingle&&s.push(...await $e(o.valueAsTypeSingle,p,c)),o.valueAsTypeList&&Array.isArray(o.valueAsTypeList))for(const e of o.valueAsTypeList)s.push(...await $e(e,p,c));return o.parent&&s.push(...await $e(o.parent,p,c)),s}async function e4e(o,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(o.id))return[];if(p.add(o.id),o.type!==d.Loop)throw new Error("Entity must be a loop to be flattened");const n=J.YieldTracker.from(i),s=[o];await n.tick();const c={...i,tracker:n};delete c.yieldEvery;for(const y of o.inputs)s.push(...await $e(y,p,c));for(const y of o.outputs)s.push(...await $e(y,p,c));o.error&&s.push(...await $e(o.error,p,c));const e=to(o);for(const y of e)s.push(...await $e(y,p,c));for(const y of o.successCalls)s.push(...await $e(y,p,c));for(const y of o.errorCalls)s.push(...await $e(y,p,c));for(const y of o.writesValues)s.push(...await $e(y,p,c));return o.parent&&s.push(...await $e(o.parent,p,c)),o.body&&s.push(...await $e(o.body,p,c)),o.dataType&&s.push(...await $e(o.dataType,p,c)),s}async function t4e(o,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(o.id))return[];if(p.add(o.id),o.type!==d.Operation)throw new Error("Entity must be an operation to be flattened");const n=J.YieldTracker.from(i),s=[o];await n.tick();const c={...i,tracker:n};delete c.yieldEvery;for(const y of o.inputs)s.push(...await $e(y,p,c));for(const y of o.outputs)s.push(...await $e(y,p,c));o.error&&s.push(...await $e(o.error,p,c));const e=to(o);for(const y of e)s.push(...await $e(y,p,c));for(const y of o.successCalls)s.push(...await $e(y,p,c));for(const y of o.errorCalls)s.push(...await $e(y,p,c));for(const y of o.writesValues)s.push(...await $e(y,p,c));return o.parent&&s.push(...await $e(o.parent,p,c)),s}async function i4e(o,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(o.id))return[];if(p.add(o.id),o.type!==d.OutputMap)throw new Error("Entity must be an output map to be flattened");const n=J.YieldTracker.from(i),s=[o];await n.tick();const c={...i,tracker:n};delete c.yieldEvery;for(const e of o.writesValues)s.push(...await $e(e,p,c));return o.declaration&&s.push(...await $e(o.declaration,p,c)),o.dataType&&s.push(...await $e(o.dataType,p,c)),o.parent&&s.push(...await $e(o.parent,p,c)),s}async function r4e(o,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(o.id))return[];if(p.add(o.id),o.type!==d.PrimitiveEntity)throw new Error("Entity must be a primitive entity to be flattened");const n=J.YieldTracker.from(i),s=[o];await n.tick();const c={...i,tracker:n};delete c.yieldEvery;for(const e of o.properties)s.push(...await $e(e,p,c));for(const e of o.methods)s.push(...await $e(e,p,c));for(const e of o.abstractMethods)s.push(...await $e(e,p,c));return s}async function n4e(o,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(o.id))return[];if(p.add(o.id),o.type!==d.Project)throw new Error("Entity must be a project to be flattened");const n=J.YieldTracker.from(i),s=[o];await n.tick();const c={...i,tracker:n};delete c.yieldEvery;for(const e of o.entities)s.push(...await $e(e,p,c));for(const e of o.functions)s.push(...await $e(e,p,c));for(const e of o.events)s.push(...await $e(e,p,c));for(const e of o.projects)s.push(...await $e(e,p,c));for(const e of o.variableDeclarations)s.push(...await $e(e,p,c));for(const e of o.variableInstances)s.push(...await $e(e,p,c));for(const e of o.operations)s.push(...await $e(e,p,c));for(const e of o.conditions)s.push(...await $e(e,p,c));for(const e of o.functionCalls)s.push(...await $e(e,p,c));for(const e of o.projects)s.push(...await $e(e,p,c));for(const e of o.loops)s.push(...await $e(e,p,c));for(const e of o.searches)s.push(...await $e(e,p,c));return s}async function a4e(o,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(o.id))return[];if(p.add(o.id),o.type!==d.Property)throw new Error("Entity must be a property to be flattened");const n=J.YieldTracker.from(i),s=[o];await n.tick();const c={...i,tracker:n};return delete c.yieldEvery,o.defaultValue&&s.push(...await $e(o.defaultValue,p,c)),o.dataType&&s.push(...await $e(o.dataType,p,c)),o.parent&&s.push(...await $e(o.parent,p,c)),s}async function s4e(o,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(o.id))return[];if(p.add(o.id),o.type!==d.ReturnStatement)throw new Error("Entity must be a return statement to be flattened");const n=J.YieldTracker.from(i),s=[o];await n.tick();const c={...i,tracker:n};delete c.yieldEvery;for(const y of o.outputs)s.push(...await $e(y,p,c));for(const y of o.outputs)s.push(...await $e(y,p,c));o.throws&&s.push(...await $e(o.throws,p,c)),o.readsValue&&s.push(...await $e(o.readsValue,p,c)),o.dataType&&s.push(...await $e(o.dataType,p,c));const e=to(o);for(const y of e)s.push(...await $e(y,p,c));return o.parent&&s.push(...await $e(o.parent,p,c)),s}async function l4e(o,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(o.id))return[];if(p.add(o.id),o.type!==d.Search)throw new Error("Entity must be a search to be flattened");const n=J.YieldTracker.from(i),s=[o];await n.tick();const c={...i,tracker:n};delete c.yieldEvery;for(const y of o.inputs)s.push(...await $e(y,p,c));for(const y of o.outputs)s.push(...await $e(y,p,c));o.error&&s.push(...await $e(o.error,p,c)),o.dataType&&s.push(...await $e(o.dataType,p,c));for(const y of o.inputsDeclarations)s.push(...await $e(y,p,c));const e=to(o);for(const y of e)s.push(...await $e(y,p,c));for(const y of o.successCalls)s.push(...await $e(y,p,c));for(const y of o.errorCalls)s.push(...await $e(y,p,c));for(const y of o.writesValues)s.push(...await $e(y,p,c));return o.parent&&s.push(...await $e(o.parent,p,c)),s}async function o4e(o,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(o.id))return[];if(p.add(o.id),o.type!==d.ValueDescriptor)throw new Error("Entity must be a value descriptor to be flattened");const n=J.YieldTracker.from(i),s=[o];await n.tick();const c={...i,tracker:n};return delete c.yieldEvery,o.defaultValue&&s.push(...await $e(o.defaultValue,p,c)),o.dataType&&s.push(...await $e(o.dataType,p,c)),o.parent&&s.push(...await $e(o.parent,p,c)),s}async function d4e(o,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(o.id))return[];if(p.add(o.id),o.type!==d.VariableDeclaration)throw new Error("Entity must be a variable declaration to be flattened");const n=J.YieldTracker.from(i),s=[o];await n.tick();const c={...i,tracker:n};delete c.yieldEvery;for(const y of o.inputs)s.push(...await $e(y,p,c));for(const y of o.outputs)s.push(...await $e(y,p,c));o.error&&s.push(...await $e(o.error,p,c)),o.dataType&&s.push(...await $e(o.dataType,p,c)),o.readsValue&&s.push(...await $e(o.readsValue,p,c)),o.defaultValue&&s.push(...await $e(o.defaultValue,p,c));const e=to(o);for(const y of e)s.push(...await $e(y,p,c));for(const y of o.successCalls)s.push(...await $e(y,p,c));for(const y of o.errorCalls)s.push(...await $e(y,p,c));for(const y of o.writesValues)s.push(...await $e(y,p,c));for(const y of o.internalCalls)s.push(...await $e(y,p,c));return o.parent&&s.push(...await $e(o.parent,p,c)),s}async function u4e(o,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(o.id))return[];if(p.add(o.id),o.type!==d.VariableInstance)throw new Error("Entity must be a variable instance to be flattened");const n=J.YieldTracker.from(i),s=[o];await n.tick();const c={...i,tracker:n};delete c.yieldEvery;for(const y of o.inputs)s.push(...await $e(y,p,c));for(const y of o.outputs)s.push(...await $e(y,p,c));o.error&&s.push(...await $e(o.error,p,c)),o.readsValue&&s.push(...await $e(o.readsValue,p,c)),o.defaultValue&&s.push(...await $e(o.defaultValue,p,c));const e=to(o);for(const y of e)s.push(...await $e(y,p,c));for(const y of o.successCalls)s.push(...await $e(y,p,c));for(const y of o.errorCalls)s.push(...await $e(y,p,c));for(const y of o.writesValues)s.push(...await $e(y,p,c));for(const y of o.internalCalls)s.push(...await $e(y,p,c));return o.parent&&s.push(...await $e(o.parent,p,c)),o.declaration&&s.push(...await $e(o.declaration,p,c)),s}async function $e(o,p=new Set,i={ignoreBuiltInBaseEntities:!1,yieldEvery:100}){const n={...i,ignoreBuiltInBaseEntities:i.ignoreBuiltInBaseEntities??!1};if(!o)throw new Error("Entity must be defined to be flattened");if(o.type===d.GenericReference)return[];const s=J.YieldTracker.from(n);n.tracker=s,n.yieldEvery!==void 0&&delete n.yieldEvery;const c=n.ignoreBuiltInBaseEntities?n.diggestedBuiltInBaseEntitiesIds??new Set(await wR(n)):new Set;if(n.diggestedBuiltInBaseEntitiesIds=c,n.ignoreBuiltInBaseEntities&&(Hn.includes(o.type)||c.has(o.id)))return[];if(p.has(o.id))return[];switch(o.type){case d.FunctionCall:return HGe(o,p,n);case d.Operation:return t4e(o,p,n);case d.Condition:return FGe(o,p,n);case d.Loop:return e4e(o,p,n);case d.Search:return l4e(o,p,n);case d.GlobalEvent:return zGe(o,p,n);case d.ReturnStatement:return s4e(o,p,n);case d.ContinueStatement:return SGe(o,p,n);case d.BreakStatement:return UGe(o,p,n);case d.VariableDeclaration:return d4e(o,p,n);case d.DefinitionEntity:return qGe(o,p,n);case d.FunctionDeclaration:return WGe(o,p,n);case d.Project:return n4e(o,p,n);case d.ActionDescriptor:return kGe(o,p,n);case d.ArgumentDeclaration:return jGe(o,p,n);case d.ValueDescriptor:return o4e(o,p,n);case d.InputMap:return JGe(o,p,n);case d.OutputMap:return i4e(o,p,n);case d.DataType:return ZGe(o,p,n);case d.InstalledProject:return YGe(o,p,n);case d.InternalCall:return XGe(o,p,n);case d.LiteralValue:return QGe(o,p,n);case d.Property:return a4e(o,p,n);case d.VariableInstance:return u4e(o,p,n);case d.BuiltInBaseEntity:return n.ignoreBuiltInBaseEntities?[]:KGe(o,p,n);case d.PrimitiveEntity:return n.ignoreBuiltInBaseEntities?[]:r4e(o,p,n)}return[]}function p4e(o,p,i){if(!i)throw new Error("[checkIsRowTransformerUpToDate] 'lastPublishedEntityVersion' argument is required");if(!p)throw new Error("[checkIsRowTransformerUpToDate] 'entity' argument is required");if(!o)throw new Error("[checkIsRowTransformerUpToDate] 'newestOpenRowTransformer' argument is required");let n=!0;const s=o.methods.find(c=>{var e;return((e=c.implements)==null?void 0:e.id)===Q["built-in-base-entity"].BUILT_IN_SQL_ROW_TRANSFORMER_ENTITY.methods.up.id});if(s?(vn(i).forEach(c=>{const e=s.inputs.find(y=>y.name===c.name);e&&Yr(e.getDataType(null),c.getDataType(null)).compatible||(n=!1)}),s.returnStatements.forEach(c=>{!c.dataType||!c.dataType.entity||c.dataType.entity.type!==d.DefinitionEntity?n=!1:Um(c.dataType.entity,p)||(n=!1)})):n=!1,n===null||n){const c=o.methods.find(e=>{var y;return((y=e.implements)==null?void 0:y.id)===Q["built-in-base-entity"].BUILT_IN_SQL_ROW_TRANSFORMER_ENTITY.methods.down.id});c?(vn(p).forEach(e=>{const y=c.inputs.find(m=>m.name===e.name);y&&Yr(y.getDataType(null),e.getDataType(null)).compatible||(n=!1)}),c.returnStatements.forEach(e=>{!e.dataType||!e.dataType.entity||e.dataType.entity.type!==d.DefinitionEntity?n=!1:Um(e.dataType.entity,i)||(n=!1)})):n=!1}return{isPreexistingRowTransformerUpToDate:n}}function c4e(o,p,i){const n={changesSinceLastPublication:!1,rowTransformerNeeded:!1,newRowTransformerNeeded:!1,newestOpenRowTransformer:null,newRequiredProperties:[],newNonRequiredProperties:[],deletedProperties:[],lastPublishedEntityVersion:null,updatedEntityVersion:i,propChanges:new Map,isPreexistingRowTransformerUpToDate:null,extendedEntities:[]},c=o.entities.filter(F=>{var ne;if(F.id===i.id)return!1;let q=!1,X=F;for(;X;){if(((ne=X.extends)==null?void 0:ne.id)===i.id){q=!0;break}if(X.extends&&X.extends.type===d.DefinitionEntity)X=X.extends;else break}return q}).map(F=>c4e(o,p,F));if(!p)return{...n,changesSinceLastPublication:!0,extendedEntities:c};const e=p.get(i.id);if(!e)return{...n,changesSinceLastPublication:!0,extendedEntities:c};const y=p.entities.filter(F=>Zi(F,Re.SQL_ROW_TRANSFORMER)),v=o.entities.filter(F=>{var ee;if(!Zi(F,Re.SQL_ROW_TRANSFORMER)||y.find(pe=>pe.id===F.id))return!1;const X=F.properties.find(pe=>!!pe.implements.find(oe=>Q["built-in-base-entity"].BUILT_IN_SQL_ROW_TRANSFORMER_ENTITY.properties.definition.id===oe.id));if(!X)return!1;const ne=(ee=X.defaultValue)==null?void 0:ee.valueAsType;return ne?ne.id===i.id:!1}).sort((F,q)=>M(F.createdAt).isAfter(M(q.createdAt))?-1:1)[0]||null,E=new Map;let b=!1;const w=vn(i).filter(F=>vn(e).find(X=>X.id===F.id)?!1:!!F.required),P=vn(i).filter(F=>vn(e).find(X=>X.id===F.id)?!1:!F.required),$=vn(e).filter(F=>!vn(i).find(X=>X.id===F.id));vn(i).filter(F=>{var ne,ee,pe,oe,ce,Te,de,ye,_e,Pe,Ge,xe,Me,Se,je,Ze,Ye,lt,ot,Rt,Pt,Ri,sr,hr;const q=vn(e).find(_n=>_n.id===F.id);let X=!1;if(!q)return!1;if(((ee=(ne=F.dataType)==null?void 0:ne.entity)==null?void 0:ee.id)!==((oe=(pe=q==null?void 0:q.dataType)==null?void 0:pe.entity)==null?void 0:oe.id)&&(((Te=(ce=F.dataType)==null?void 0:ce.entity)==null?void 0:Te.id)===Q["primitive-entity"].string.id||((ye=(de=q==null?void 0:q.dataType)==null?void 0:de.entity)==null?void 0:ye.id)===Q["primitive-entity"].date.id&&((Pe=(_e=F.dataType)==null?void 0:_e.entity)==null?void 0:Pe.id)===Q["primitive-entity"].number.id?E.set(F.id,{...E.get(F.id)||{},castableDataTypeEntity:{fromId:((xe=(Ge=q==null?void 0:q.dataType)==null?void 0:Ge.entity)==null?void 0:xe.id)||"",toId:((Se=(Me=F.dataType)==null?void 0:Me.entity)==null?void 0:Se.id)||""},property:F,oldProperty:q}):(E.set(F.id,{...E.get(F.id)||{property:F},nonCastableDataTypeEntity:{fromId:((Ze=(je=q==null?void 0:q.dataType)==null?void 0:je.entity)==null?void 0:Ze.id)||"",toId:((lt=(Ye=F.dataType)==null?void 0:Ye.entity)==null?void 0:lt.id)||""},property:F,oldProperty:q}),b=!0),X=!0),((Rt=(ot=F.dataType)==null?void 0:ot.foreignKeyRef)==null?void 0:Rt.id)!==((Ri=(Pt=q==null?void 0:q.dataType)==null?void 0:Pt.foreignKeyRef)==null?void 0:Ri.id)){const _n=(sr=F.dataType)==null?void 0:sr.foreignKeyRef,an=(hr=q==null?void 0:q.dataType)==null?void 0:hr.foreignKeyRef;E.set(F.id,{...E.get(F.id)||{},newForeignKeyRef:_n||void 0,oldForeignKeyRef:an||void 0,property:F,oldProperty:q}),X=!0,b=!0}return F.name!==(q==null?void 0:q.name)&&(E.set(F.id,{...E.get(F.id)||{},nameChange:{from:(q==null?void 0:q.name)||"",to:F.name},property:F,oldProperty:q}),X=!0),F.required!==(q==null?void 0:q.required)&&(E.set(F.id,{...E.get(F.id)||{},requiredChange:{from:(q==null?void 0:q.required)||!1,to:F.required},property:F,oldProperty:q}),F.required&&(b=!0),X=!0),X}),w.length>0&&(b=!0);const L=!!v&&p4e(v,i,e).isPreexistingRowTransformerUpToDate||null,j=i.name!==e.name?{from:e.name,to:i.name}:void 0;return{...n,changesSinceLastPublication:E.size>0||!!$.length||!!w.length||!!P.length||b,rowTransformerNeeded:b,newestOpenRowTransformer:v,nameChange:j,newRequiredProperties:w,newNonRequiredProperties:P,deletedProperties:$,lastPublishedEntityVersion:e,propChanges:E,newRowTransformerNeeded:b&&!v,isPreexistingRowTransformerUpToDate:L,extendedEntities:c}}function JN(o,p,i,n,s){if(!o)throw new Error("[addDifferencesToRowTransformer] 'project' argument is required");if(!p)throw new Error("[addDifferencesToRowTransformer] 'transformer' argument is required");if(!i)throw new Error("[addDifferencesToRowTransformer] 'newEntityState' argument is required");if(!n)throw new Error("[addDifferencesToRowTransformer] 'oldEntityState' argument is required");const c=vn(i),e=vn(n);p.afterAllChildrenInitialized(s);const y=p.methods.find(v=>{var E;return((E=v.implements)==null?void 0:E.id)===Q["built-in-base-entity"].BUILT_IN_SQL_ROW_TRANSFORMER_ENTITY.methods.up.id}),m=p.methods.find(v=>{var E;return((E=v.implements)==null?void 0:E.id)===Q["built-in-base-entity"].BUILT_IN_SQL_ROW_TRANSFORMER_ENTITY.methods.down.id});if(!y)throw new Error("[addDifferencesToRowTransformer] The 'up' transformer trigger is missing from the parent");if(!m)throw new Error("[addDifferencesToRowTransformer] The 'down' transformer trigger is missing from the parent");e.forEach(v=>{const E=y.inputs.find($=>$.name===v.name),b=v.getDataType(null);let w=E,P;if(E)w.editable=!0;else{const $=Ea.new(s);$.parent=y.toReference(),$.name=v.name,$.index=v.index,$.implements=[...v.implements.map(j=>j.toJSON())];const L=he($,o);L.hydrateAncestors(),s.add(L,H.Added),L.addSelfToProject(s),L.initChildren(s),w=L}if(!w.dataType||w.dataType&&o.diggestedBuiltInBaseEntitiesIds.has(w.dataType.id)){const $=ir.new(s);$.parent=w.toReference();const L=he($,o);L.hydrateAncestors(),s.add(L,H.Added),L.addSelfToProject(s),L.initChildren(s),P=L}else P=w.dataType,P.editable=!0;b&&P.merge(v.getDataType(null),s),P.metaSync({editable:!1,deletable:!1},s),w.metaSync({editable:!1,deletable:!1},s)}),[...y.inputs].forEach(v=>{e.find(b=>b.name===v.name)||(v.editable=!0,v.remove({ignoreUpstream:!1},s),v.editable=!1)}),[...y.returnStatements].forEach(v=>{var E,b;if(!v.dataType||v.dataType&&o.diggestedBuiltInBaseEntitiesIds.has(v.dataType.id)){const w=ir.new(s);w.entity=i.toReference(),w.parent=v.toReference();const P=he(w,o);P.hydrateAncestors(),s.add(P,H.Added),P.addSelfToProject(s),P.initChildren(s)}(!((E=v.dataType)!=null&&E.entity)||v.dataType.entity.type!==d.DefinitionEntity||v.dataType.entity.parent.id!==v.dataType.id)&&i.clone(s,v.dataType),TV((b=v.dataType)==null?void 0:b.entity,i,s),v.afterAllChildrenInitialized(s),v.outputs.forEach(w=>{const P=y.inputs.find($=>se(w,o)===se($,o));w.setValueWriter(P,s),P==null||P.addValueReader(w,s)})}),c.forEach(v=>{var L;const E=(L=v.knownVersions)==null?void 0:L.get(v.previousVersion),b=m.inputs.find(j=>j.name===v.name||!!E&&E.name===j.name),w=v.getDataType(null);let P=b,$;if(b)P.editable=!0,P.metaSync({name:v.name,codeName:v.codeName,description:v.description},s);else{const j=Ea.new(s);j.parent=m.toReference(),j.name=v.name,j.codeName=v.codeName,j.description=v.description,j.index=v.index,j.implements=[v.toJSON(),...v.implements.map(q=>q.toJSON())];const F=he(j,o);F.hydrateAncestors(),s.add(F,H.Added),F.addSelfToProject(s),F.initChildren(s),P=F}if(P.dataType)$=P.dataType,$.editable=!0,$.merge(P.dataType,s);else{const j=ir.new(s);j.parent=P.toReference();const F=he(j,o);F.hydrateAncestors(),s.add(F,H.Added),F.addSelfToProject(s),F.initChildren(s),$=F}w&&$.merge(v.getDataType(null),s),$.metaSync({editable:!1,deletable:!1},s),P.metaSync({editable:!1,deletable:!1},s)}),[...m.inputs].forEach(v=>{c.find(b=>{var P;if(b.name===v.name)return!0;const w=(P=b.knownVersions)==null?void 0:P.get(b.previousVersion);if(w&&w.name===v.name)return!0})||(v.editable=!0,v.remove({ignoreUpstream:!1},s),v.editable=!1)}),[...m.returnStatements].forEach(v=>{var b,w,P,$;if(!v.dataType||v.dataType&&o.diggestedBuiltInBaseEntitiesIds.has(v.dataType.id)){const L=ir.new(s);L.parent=v.toReference();const j=he(L,o);j.hydrateAncestors(),s.add(j,H.Added),j.addSelfToProject(s),j.initChildren(s)}let E=(b=v.dataType)==null?void 0:b.entity;(!E||(E==null?void 0:E.id)===Q["built-in-base-entity"].BUILT_IN_PERSISTED_ENTITY_ENTITY.id)&&(J.Logger.log("Cloning old entity state into new project with data-ype as parent: ",(w=v.dataType)==null?void 0:w.id," from new project: ",((P=v.dataType)==null?void 0:P.project.version)===o.version&&(($=v.dataType)==null?void 0:$.project.entities.length)===3),E=n.clone(s,v.dataType)),v.dataType.setEntity(E,s),v.afterAllChildrenInitialized(s),v.outputs.forEach(L=>{const j=m.inputs.find(F=>se(L,o)===se(F,o));L.setValueWriter(j,s),j==null||j.addValueReader(L,s)})})}function f4e(o,p,i,n){var $;const s=o.getBuiltIn(Re.SQL_ROW_TRANSFORMER),c=OV(se(p,o)+" row transformer",o.entities),e=s.implement(c,n),y=e.ownDeclaredProperties.find(L=>{var j;return(j=L.implements)==null?void 0:j.find(F=>F.id===Q["built-in-base-entity"].BUILT_IN_SQL_ROW_TRANSFORMER_ENTITY.properties.definition.id)}),m=e.methods.find(L=>{var j;return((j=L.implements)==null?void 0:j.id)===Q["built-in-base-entity"].BUILT_IN_SQL_ROW_TRANSFORMER_ENTITY.methods.up.id}),v=e.methods.find(L=>{var j;return((j=L.implements)==null?void 0:j.id)===Q["built-in-base-entity"].BUILT_IN_SQL_ROW_TRANSFORMER_ENTITY.methods.down.id});if(!y||!m||!v)throw new Error("Cannot find definition property on the new row transformer entity");if(y.defaultValue)y.defaultValue.setValueAsTypeSingle(p,n);else{const L=Xr.new(n);L.name=le.EntityTemplate,L.valueAsTypeSingle=p.toJSON(),L.parent=y.toReference();const j=he(L,o);j.hydrateAncestors(),n.add(j,H.Added),j.addSelfToProject(n),j.initChildren(n)}JN(o,e,p,i,n),J.Logger.log("BEFORE - changeSet.listAdded",n.listAdded.map(L=>{var F,q,X,ne,ee,pe,oe;const j=o.get(L.id);return j?se(j,o):L.type===d.InputMap?"(not found) "+L.type+" "+L.id+" - declaration: "+((F=L.declaration)==null?void 0:F.type)+" "+((q=L.declaration)==null?void 0:q.id)+' "'+((X=L.declaration)==null?void 0:X.name)+`"
388
388
  parent: `+((ee=(ne=L.parent)==null?void 0:ne.parent)==null?void 0:ee.id)+" - "+((oe=(pe=L.parent)==null?void 0:pe.parent)==null?void 0:oe.name):"(not found) "+L.type+" "+L.id})),J.Logger.log("AFTER - changeSet.listAdded",n.listAdded.map(L=>{var F,q,X,ne,ee,pe,oe;const j=o.get(L.id);return j?j.type+' "'+se(j,o)+'" ('+j.id+")":L.type===d.InputMap?"(not found) "+L.type+" ("+L.id+") - declaration: "+((F=L.declaration)==null?void 0:F.type)+" ("+((q=L.declaration)==null?void 0:q.id)+') "'+((X=L.declaration)==null?void 0:X.name)+`"
389
389
  parent: "`+((ee=(ne=L.parent)==null?void 0:ne.parent)==null?void 0:ee.name)+'" ('+((oe=(pe=L.parent)==null?void 0:pe.parent)==null?void 0:oe.id)+")":"(not found) "+L.type+" "+L.id})),J.Logger.log("-----------------"),J.Logger.log("Old properties: ",vn(i).map(L=>L.name+" ("+L.id+")")),J.Logger.log("New properties: ",vn(p).map(L=>L.name+" ("+L.id+")"));const E=e.methods.find(L=>{var j;return((j=L.implements)==null?void 0:j.id)===Q["built-in-base-entity"].BUILT_IN_SQL_ROW_TRANSFORMER_ENTITY.methods.up.id}),b=e.methods.find(L=>{var j;return((j=L.implements)==null?void 0:j.id)===Q["built-in-base-entity"].BUILT_IN_SQL_ROW_TRANSFORMER_ENTITY.methods.down.id});J.Logger.log(`
390
390
  Up inputs: `,E==null?void 0:E.inputs.map(L=>L.name+" ("+L.id+")")),J.Logger.log("Up method return statements:",E==null?void 0:E.returnStatements[0].outputs.map(L=>se(L,o)+" ("+L.id+")")),J.Logger.log(`
package/dist/index.js CHANGED
@@ -179524,7 +179524,7 @@ function C3(o) {
179524
179524
  return o == null || o === "";
179525
179525
  }
179526
179526
  function $r(o) {
179527
- return o ? o.valueAsType ? !1 : C3(o.value) : !0;
179527
+ return o != null && o.valueAsType ? !1 : C3(o == null ? void 0 : o.value);
179528
179528
  }
179529
179529
  function nEi(o, p) {
179530
179530
  if (o === p || !o && !p)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elyx-code/project-logic-tree",
3
- "version": "0.0.6729",
3
+ "version": "0.0.6730",
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",