@elyx-code/project-logic-tree 0.0.6948 → 0.0.6950
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +1 -1
- package/dist/index.js +57 -30
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -603,7 +603,7 @@ This is likely an incorrect strategy, either the '${this.type}' entity doesn't n
|
|
|
603
603
|
You can inspect the existing 'entity' field with the 'describe_entity' action. Like so:
|
|
604
604
|
${fp({describe_entity:A.entity.id})}
|
|
605
605
|
Alternatively you can update the parent data-type entity with 'update' action to remove the existing value of the field.`}))}return{errors:e,explanations:c,modifiedData:a}}get interactive(){return this.implements.length?this.implements.every(i=>i.interactive):!0}get allMethods(){return C([...this.ownDeclaredMethods,...this.allBaseMethodsFromOriginalParents])}get allProperties(){return C([...this.ownDeclaredProperties,...this.allBasePropertiesFromOriginalParents])}get allBaseMethodsFromOriginalParents(){var a;const i=((a=this.extends)==null?void 0:a.type)===d.DefinitionEntity?this.extends.allMethods:[],r=[...i].filter(c=>!i.some(e=>{var f,h;return e.id!==c.id&&(((f=e.implements)==null?void 0:f.id)===c.id||((h=e.extends)==null?void 0:h.id)===c.id)}));return C([...r,...this.implements.flatMap(c=>{const e=c.type===d.DefinitionEntity?[...c.allMethods]:[];return[...e].filter(h=>!e.some(m=>{var E,b;return m.id!==h.id&&(((E=m.implements)==null?void 0:E.id)===h.id||((b=m.extends)==null?void 0:b.id)===h.id)}))})])}get allBasePropertiesFromOriginalParents(){var c;const i=((c=this.extends)==null?void 0:c.allProperties)||[],r=[...i].filter(e=>!i.some(f=>{var h;return f.id!==e.id&&(!!f.implements.find(m=>m.id===e.id)||((h=f.extends)==null?void 0:h.id)===e.id)}));return C([...r,...this.implements.flatMap(e=>{const f=[...e.allProperties];return[...f].filter(m=>!f.some(E=>{var b;return E.id!==m.id&&(!!E.implements.find(A=>A.id===m.id)||((b=E.extends)==null?void 0:b.id)===m.id)}))})])}get allBasePropertiesFromExtendedAndImplementedEntities(){var c,e;const i=[...((c=this.extends)==null?void 0:c.ownDeclaredProperties)||[],...((e=this.extends)==null?void 0:e.allBasePropertiesFromExtendedAndImplementedEntities)||[]].filter(f=>!f.abstract),r=[...i].filter(f=>!i.some(h=>{var m;return h.id!==f.id&&(!!h.implements.find(E=>E.id===f.id)||((m=h.extends)==null?void 0:m.id)===f.id)})),a=this.implements.reduce((f,h)=>{const m=h.implementedPropertiesFromOriginalParents,E=[...h.ownDeclaredProperties].filter(_=>!_.abstract),b=[...m,...E,...f];return[...b].filter(_=>!!!b.find(V=>{var M;return!!V.implements.find(G=>G.id===_.id)||((M=V.extends)==null?void 0:M.id)===_.id}))},[]);return C([...r,...a])}get allBaseMethodsFromExtendedAndImplementedEntities(){return C([...(this.extends?[this.extends]:[]).reduce((i,r)=>r.type!==d.DefinitionEntity?[]:[...[...r.ownDeclaredMethods,...r.allBaseMethodsFromExtendedAndImplementedEntities].filter(c=>c.type!==d.ActionDescriptor),...i],[]),...this.implements.reduce((i,r)=>r.type!==d.DefinitionEntity?r.abstractMethods:[...[...r.ownDeclaredMethods,...r.allBaseMethodsFromExtendedAndImplementedEntities].filter(c=>c.type!==d.ActionDescriptor),...i],[])])}get extendedPropertiesFromOriginalParents(){var a,c;const i=[...((a=this.extends)==null?void 0:a.ownDeclaredProperties)||[],...((c=this.extends)==null?void 0:c.extendedPropertiesFromOriginalParents)||[]].filter(e=>!e.abstract),r=[...i].filter(e=>!i.some(f=>{var h;return f.id!==e.id&&(!!f.implements.find(m=>m.id===e.id)||((h=f.extends)==null?void 0:h.id)===e.id)}));return C(r)}get implementedPropertiesFromOriginalParents(){return C([...(this.extends?[this.extends]:[]).reduce((i,r)=>{const a=r.implementedPropertiesFromOriginalParents,c=[...r.ownDeclaredProperties].filter(h=>!!h.abstract),e=[...a,...c,...i];return[...e].filter(h=>!!!e.find(E=>{var b;return((b=E.extends)==null?void 0:b.id)===h.id||!!E.implements.find(A=>A.id===h.id)}))},[]),...this.implements.reduce((i,r)=>{const a=r.implementedPropertiesFromOriginalParents,c=[...r.ownDeclaredProperties].filter(h=>!!h.abstract),e=[...a,...c,...i];return[...e].filter(h=>!!!e.find(E=>{var b;return!!E.implements.find(A=>A.id===h.id)||((b=E.extends)==null?void 0:b.id)===h.id}))},[])].filter(i=>!!i.abstract))}get extendedMethodsFromOriginalParents(){return C((this.extends?[this.extends]:[]).reduce((i,r)=>{if(r.type!==d.DefinitionEntity)return[];const a=[...r.ownDeclaredMethods,...r.extendedMethodsFromOriginalParents].filter(c=>c.type!==d.ActionDescriptor);return[...i,...a]},[]))}get implementedMethodsFromOriginalParents(){return C([...(this.extends?[this.extends]:[]).reduce((i,r)=>{const a=r.type===d.DefinitionEntity?r.methods:[],c=[...r.abstractMethods].filter(e=>!a.find(f=>f.name===e.name));return[...a,...c,...i]},[]),...this.implements.reduce((i,r)=>[...r.abstractMethods,...i],[])].filter(i=>i.type===d.ActionDescriptor))}get extendedProperties(){return this.properties.filter(i=>i.isExtendedProperty)}get ownDeclaredProperties(){return this.properties.filter(r=>!r.isExtendedProperty)}get extendedMethods(){return this.methods.filter(i=>i.isExtendedMethod)}get ownDeclaredMethods(){return this.methods.filter(i=>!i.isExtendedMethod)}validateGeneratedUpdate(i){const r=[],a=[];return i.parent&&r.push(new we({id:`${this.id}--${Te.InvalidParentUpdate}`,code:Te.InvalidParentUpdate,severity:ve.Error,message:`Entity of type '${this.type}' with id '${this.id}' cannot have the 'parent' property updated. The 'parent' on an '${this.type}', must be the root project as it is a globally declared entity.`})),{errors:r,explanations:a,modifiedData:i}}subscribeDependents(i){return i.forEach(r=>{this.detachedDependents[r.entity.id]||(this.detachedDependents[r.entity.id]=r)}),this}unsubscribeDependents(i){return i.forEach(r=>{this.detachedDependents[r.entity.id]&&delete this.detachedDependents[r.entity.id]}),this}syncDependents(i=this.project.addChangeSet(new S(this.project,x.sessionAuthor,B().toISOString(),this,!0,"sync-dependents"))){const r=[],a=[],c=[],e=[];return Object.values(this.detachedDependents).forEach(f=>{const h=f.entity.afterAllChildrenInitialized(i);r.push(...h.updated),a.push(...h.added),c.push(...h.removed),e.push(...h.affected)}),i==null||i.attemptAutoclose("sync-dependents",this.id),{updated:C(r),added:C(a),removed:C(c),affected:C(e),self:this}}onDetachedDependencyRemoved(i,r,a){const c=[],e=[],f=[],h=[];return r==="implements"&&(this.removeImplementation(i,a),c.push(this)),r==="extends"&&(this.setExtension(null,a),c.push(this)),{updated:C(c),added:C(e),removed:C(f),affected:C(h),self:this}}onDetachedDependencyRestored(i,r,a){const c=[],e=[],f=[],h=[];return r==="implements"&&(this.addImplementation(i,a),c.push(this)),r==="extends"&&(this.setExtension(i,a),c.push(this)),{updated:C(c),added:C(e),removed:C(f),affected:C(h),self:this}}unsubscribeFromDependencies(){return this.implements.forEach(i=>{ma.includes(i.type)||i.unsubscribeDependents([{entity:this,field:"implements"}])}),this.extends&&(ma.includes(this.extends.type)||this.extends.unsubscribeDependents([{entity:this,field:"extends"}])),this}subscribeToDependencies(){return this.implements.forEach(i=>{ma.includes(i.type)||i.subscribeDependents([{entity:this,field:"implements"}])}),this.extends&&(ma.includes(this.extends.type)||this.extends.subscribeDependents([{entity:this,field:"extends"}])),this}increaseVersion(i){var r;if(this.project.diggestedBuiltInBaseEntitiesIds.has(this.id))return this;if(i&&!B(i).isValid())throw new Error(`The shared timestamp '${i}' is not a valid ISO 8601 date string.`);if(i&&B(i).isSame(B(this.createdAt)))return this;if(!((r=this.knownVersions)!=null&&r.has(this.version))&&this.project.initialized)throw new Error(`The current ${this.type} ${this.id} version '${this.version}' is not captured in the 'knownVersions' map. Capture the current version before increasing it to avoid losing data.`);if(!this.activeVersion)throw new Error(`Only active versions can be increased. Entity with id '${this.id}' and version '${this.version}' is not active.`);return this.previousVersion=this.version,this.version=x.UUID.uuid(),this.createdAt=B(i).toISOString()||B().toISOString(),this}captureVersion(){var r;const i=((r=this.knownVersions)==null?void 0:r.get(this.version))||new Ni(this,this.project);if(!this.activeVersion)throw new Error(`Only active versions can be captured. Entity of type ${this.type} with id '${this.id}' and version '${this.version}' is not active.`);if(this.version!==i.version)throw new Error(`Captured ${this.type} with id '${this.id}', version '${i.version}' does not match current entity version '${this.version}'.`);return this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,i):new Map().set(this.version,i),this.apply(i),this}snapshot(){const i=new Ni(this,this.project);return this.apply(i)}apply(i){const r=this.toMeta();return i.metaSync(r,null),i.properties=[...this.properties],i.methods=[...this.methods],i.abstractMethods=[...this.abstractMethods],i.extends=this.extends,i.implements=[...this.implements],i.allPropertiesImplement=this.allPropertiesImplement,i.additionalPropertiesDataType=this.additionalPropertiesDataType,i.parent=this.parent,i}recursiveCaptureUpstreamVersions(i){const r=[],a=[],c=[],e=[];if(this.parent){this.parent.increaseVersion(i);const f=this.parent.recursiveCaptureUpstreamVersions(i);r.push(this.parent,...f.updated),a.push(...f.added),c.push(...f.removed)}return{updated:C(r),added:C(a),removed:C(c),affected:C(e),self:this}}async restoreVersion(i,r){var m;const a=[],c=[],e=[],f=[];if(this.version===i&&(r!=null&&r.skipIfSameVersion))return{updated:C(a),added:C(c),removed:C(e),affected:C(f),self:this};if(!this.knownVersions){const E=new Map;for(const[b,A]of this.knownVersions||new Map){if(E.set(b,A),A.activeVersion=!1,A.knownVersions)for(const[_,P]of A.knownVersions)E.set(_,P);A.knownVersions=null}}let h=(m=this.knownVersions)==null?void 0:m.get(i);if(!h){const E=await this.APILoadVersion({},i);if(!E)throw new Error(`Version with id '${i}' for entity with id '${this.id}' not found.`);h=new Ni(E,this.project)}return this.metaSync(h.toShallowJSON(),null),this.previousVersion=h.previousVersion,this.version=h.version,this.createdAt=h.createdAt,this.author=h.author,this.deleted=h.deleted,this.properties=[...h.properties],this.methods=[...h.methods],this.abstractMethods=[...h.abstractMethods],this.extends=h.extends,this.implements=[...h.implements],this.allPropertiesImplement=h.allPropertiesImplement,this.additionalPropertiesDataType=h.additionalPropertiesDataType,this.parent=h.parent,{updated:C(a),added:C(c),removed:C(e),affected:C(f),self:this}}updateWithShallowTransfer(i,r=this.project.addChangeSet(new S(this.project,x.sessionAuthor,B().toISOString(),this,!0,w.UpdateWithShallowTransfer))){if(!this.checkCanEdit(this,r))return Y.Logger.warn(`[updateWithShallowTransfer] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),r==null||r.attemptAutoclose(w.UpdateWithShallowTransfer,this.id),this;if(this.metaSync(i,r),this.version=i.version,this.createdAt=i.createdAt,this.author=i.author,this.deleted=i.deleted,this.previousVersion=i.previousVersion,this.unsubscribeFromDependencies(),i.parent){const f=ie(i.parent),h=this.project.get(f),m=this.parent;if(m&&m.id!==(h==null?void 0:h.id)&&this.removeFromParent(r),h)this.setParent(h,r),this.addSelfToProject(r);else throw r==null||r.attemptAutoclose(w.UpdateWithShallowTransfer,this.id),new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${f}' that isn't found in the project`)}else throw r==null||r.attemptAutoclose(w.UpdateWithShallowTransfer,this.id),new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(i.extends){const f=ie(i.extends),h=this.project.get(f);h&&this.setExtension(h,r)}else this.setExtension(null,r);if(i.implements.forEach(f=>{const h=ie(f),m=this.project.get(h);if(m)this.addImplementation(m,r);else throw new Error(`${fr(this.type)} with id '${this.id}' has a 'implements' reference "${h}" which is missing in the project`)}),this.implements.filter(f=>{const h=ie(f);return!i.implements.find(m=>ie(m)===h)}).forEach(f=>{this.removeImplementation(f,r)}),i.methods.forEach(f=>{const h=ie(f),m=this.project.get(h);m&&this.addMethod(m,r)}),this.methods.filter(f=>{const h=ie(f);return!i.methods.find(m=>ie(m)===h)}).forEach(f=>{this.removeMethod(f,r)}),i.properties.forEach(f=>{const h=ie(f),m=this.project.get(h);m&&this.addProperty(m,r)}),this.properties.filter(f=>{const h=ie(f);return!i.properties.find(m=>ie(m)===h)}).forEach(f=>{this.removeProperty(f,r)}),i.allPropertiesImplement){const f=ie(i.allPropertiesImplement),h=this.project.get(f);h&&this.setAllPropertiesImplement(h,r)}else this.setAllPropertiesImplement(null,r);if(i.additionalPropertiesDataType){const f=ie(i.additionalPropertiesDataType),h=this.project.get(f);h&&this.setAdditionalPropertiesDataType(h,r)}else this.setAdditionalPropertiesDataType(null,r);return this.captureVersion(),this.subscribeToDependencies(),r==null||r.attemptAutoclose(w.UpdateWithShallowTransfer,this.id),this}updateWithGenerationTarget(i,r=this.project.addChangeSet(new S(this.project,x.sessionAuthor,B().toISOString(),this,!0,w.UpdateWithGenerationTarget))){var a;if(!this.checkCanEdit(this,r))return Y.Logger.warn(`[updateWithGenerationTarget] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),r==null||r.attemptAutoclose(w.UpdateWithGenerationTarget,this.id),this;if(this.metaSync(i,r),i.parent){const c=ie(i.parent),e=this.project.get(c),f=this.parent;if(f&&f.id!==(e==null?void 0:e.id)&&this.removeFromParent(r),e)this.setParent(e,r),this.addSelfToProject(r);else throw r==null||r.attemptAutoclose(w.UpdateWithGenerationTarget,this.id),new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${c}' that isn't found in the project`)}if(i.extends){const c=ie(i.extends),e=this.project.get(c);if(e)this.setExtension(e,r);else throw new Error(`${fr(this.type)} with id '${this.id}' has an 'extends' reference "${c}" which is missing in the project`)}else i.extends===null&&this.setExtension(null,r);return(a=i.implements)==null||a.forEach(c=>{const e=ie(c),f=this.project.get(e);if(f)this.addImplementation(f,r);else throw new Error(`${fr(this.type)} with id '${this.id}' has a 'implements' reference "${e}" which is missing in the project`)}),i.implements&&this.implements.filter(e=>{const f=ie(e);return!(i.implements||[]).find(h=>ie(h)===f)}).forEach(e=>{this.removeImplementation(e,r)}),this.captureVersion(),this.subscribeToDependencies(),r==null||r.attemptAutoclose(w.UpdateWithGenerationTarget,this.id),this}hydrateAncestors(){const i=[],r=[],a=[],c=[];if(this.initialData.parent){const e=ie(this.initialData.parent),f=this.project.get(e);if(f)this.setParent(f,null),i.push(f);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${e}' that isn't found in the project`)}else throw new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(this.initialData.extends){const e=ie(this.initialData.extends),f=this.project.get(e);f&&(this.setExtension(f,null),f.type!==d.BuiltInBaseEntity&&i.push(f))}return this.initialData.implements.forEach(e=>{const f=ie(e),h=this.project.get(f);if(h)this.addImplementation(h,null),h.type!==d.BuiltInBaseEntity&&i.push(h);else throw new Error(`${fr(this.type)} with id '${this.id}' has a 'implements' reference "${f}" which is missing in the project`)}),{updated:C(i),added:C(r),removed:C(a),affected:C(c),self:this}}afterAllChildrenInitialized(i=this.project.addChangeSet(new S(this.project,x.sessionAuthor,B().toISOString(),this,!0,w.AfterAllChildrenInitialized))){if(!this.checkCanEdit(this,i))return Y.Logger.warn(`[afterAllChildrenInitialized] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(w.AfterAllChildrenInitialized,this.id),{updated:[],added:[],removed:[],affected:[],self:this};const r=[],a=[],c=[],e=[];this.initialized=!0;const{updated:f,added:h,removed:m,affected:E}=this.syncImplementationProperties(i);r.push(...f),a.push(...h),c.push(...m),e.push(...E);const{updated:b,added:A,removed:_,affected:P}=this.addExtendedProperties(i);r.push(...b),a.push(...A),c.push(..._),e.push(...P);const{updated:V,added:M,removed:G}=this.removeUnrecognizedProperties(i);r.push(...V),a.push(...M),c.push(...G);const{updated:k,added:q,removed:ne,affected:J}=this.syncImplementationMethods(i);r.push(...k),a.push(...q),c.push(...ne),e.push(...J);const{updated:se,added:te,removed:le,affected:ue}=this.addExtendedMethods(i);r.push(...se),a.push(...te),c.push(...le),e.push(...ue);const{updated:z,added:Q,removed:de}=this.removeUnrecognizedMethods(i);r.push(...z),a.push(...Q),c.push(...de),this.addSuggestions(),this.properties.sort((fe,be)=>fe.index-be.index);let he=this.project.getDefinitionEntities(new Set([this.id])).filter(fe=>fe.id!==this.id&&fe.name.toLowerCase()===this.name.toLowerCase());if(he.length&&(this.parent.type===d.Project&&(he.filter(be=>be.parent.type!==d.Project).forEach(be=>{N_e(be,i)}),he=he.filter(be=>be.name.toLowerCase()===this.name.toLowerCase())),he.length)){const fe=su(this.name,he);this.metaSync({name:fe},i)}return i==null||i.attemptAutoclose(w.AfterAllChildrenInitialized,this.id),{updated:C(r),added:C(a),removed:C(c),affected:C(e),self:this}}addSelfToProject(i=this.project.addChangeSet(new S(this.project,x.sessionAuthor,B().toISOString(),this,!0,"add-self-to-project"))){const r=[this],a=[],c=[],e=[];if(this.parent.type===d.DataType){const f=this.parent;f.entity=this,r.push(f)}else this.project.addDefinitionEntity(this);return this.subscribe(),this.subscribeToDependencies(),i==null||i.attemptAutoclose("add-self-to-project",this.id),{updated:C(r),added:C(a),removed:C(c),affected:C(e),self:this}}setParent(i,r=this.project.addChangeSet(new S(this.project,x.sessionAuthor,B().toISOString(),this,!0,w.SetParent))){var a;return this.checkCanEditWithCounterpartAndSideEffects(this,i,w.SetParent,r)?(((a=this.parent)==null?void 0:a.id)!==(i==null?void 0:i.id)&&(this.parent=i,r&&(r==null||r.add(this,W.Updated))),r==null||r.attemptAutoclose(w.SetParent,this.id),this):this}setExtension(i,r=this.project.addChangeSet(new S(this.project,x.sessionAuthor,B().toISOString(),this,!0,w.SetExtension))){var a;return this.checkCanEdit(this,r)?(((a=this.extends)==null?void 0:a.id)!==(i==null?void 0:i.id)&&(this.extends=i,this.subscribeToDependencies(),r&&(r==null||r.add(this,W.Updated))),r==null||r.attemptAutoclose(w.SetExtension,this.id),this):(Y.Logger.warn(`[setExtension] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),r==null||r.attemptAutoclose(w.SetExtension,this.id),this)}addImplementation(i,r=this.project.addChangeSet(new S(this.project,x.sessionAuthor,B().toISOString(),this,!0,w.AddImplementation))){return this.checkCanEdit(this,r)?(this.implements.includes(i)||(this.implements.push(i),this.subscribeToDependencies(),r==null||r.add(this,W.Updated)),r==null||r.attemptAutoclose(w.AddImplementation,this.id),this):(Y.Logger.warn(`[addImplementation] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),r==null||r.attemptAutoclose(w.AddImplementation,this.id),this)}removeImplementation(i,r=this.project.addChangeSet(new S(this.project,x.sessionAuthor,B().toISOString(),this,!0,w.RemoveImplementation))){return this.checkCanEdit(this,r)?(this.implements.includes(i)&&(this.implements=this.implements.filter(a=>a.id!==i.id),r==null||r.add(this,W.Updated)),r==null||r.attemptAutoclose(w.RemoveImplementation,this.id),this):(Y.Logger.warn(`[removeImplementation] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),r==null||r.attemptAutoclose(w.RemoveImplementation,this.id),this)}removeProperty(i,r=this.project.addChangeSet(new S(this.project,x.sessionAuthor,B().toISOString(),this,!0,w.RemoveProperty))){return this.checkCanEdit(this,r)?(this.properties.includes(i)&&(this.properties=this.properties.filter(a=>a.id!==i.id),r==null||r.add(this,W.Updated)),r==null||r.attemptAutoclose(w.RemoveProperty,this.id),this):(Y.Logger.warn(`[removeProperty] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),r==null||r.attemptAutoclose(w.RemoveProperty,this.id),this)}addMethod(i,r=this.project.addChangeSet(new S(this.project,x.sessionAuthor,B().toISOString(),this,!0,w.AddMethod))){return this.checkCanEdit(this,r)?(this.methods.includes(i)||(this.methods.push(i),this.suggestedMethods=this.suggestedMethods.filter(a=>a.name!==i.name),r==null||r.add(this,W.Updated)),r==null||r.attemptAutoclose(w.AddMethod,this.id),this):(Y.Logger.warn(`[addMethod] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),r==null||r.attemptAutoclose(w.AddMethod,this.id),this)}removeMethod(i,r=this.project.addChangeSet(new S(this.project,x.sessionAuthor,B().toISOString(),this,!0,w.RemoveMethod))){return this.checkCanEdit(this,r)?(this.methods.includes(i)&&(this.methods=this.methods.filter(a=>a.id!==i.id),r==null||r.add(this,W.Updated)),r==null||r.attemptAutoclose(w.RemoveMethod,this.id),this):(Y.Logger.warn(`[removeMethod] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),r==null||r.attemptAutoclose(w.RemoveMethod,this.id),this)}addProperty(i,r=this.project.addChangeSet(new S(this.project,x.sessionAuthor,B().toISOString(),this,!0,w.AddProperty))){return this.checkCanEdit(this,r)?(this.properties.includes(i)||(this.properties.push(i),this.suggestedProperties=this.suggestedProperties.filter(a=>a.name!==i.name),r==null||r.add(this,W.Updated)),r==null||r.attemptAutoclose(w.AddProperty,this.id),this):(Y.Logger.warn(`[addProperty] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),r==null||r.attemptAutoclose(w.AddProperty,this.id),this)}addSuggestedProperty(i){return this.suggestedProperties.includes(i)||this.suggestedProperties.push(i),this}addSuggestedMethod(i){return this.suggestedMethods.includes(i)||this.suggestedMethods.push(i),this}removeSuggestedProperty(i){return this.suggestedProperties=this.suggestedProperties.filter(r=>r.id!==i.id),this}removeSuggestedMethod(i){return this.suggestedMethods=this.suggestedMethods.filter(r=>r.id!==i.id),this}addAbstractMethod(i,r=this.project.addChangeSet(new S(this.project,x.sessionAuthor,B().toISOString(),this,!0,w.AddAbstractMethod))){return this.checkCanEdit(this,r)?(this.abstractMethods.includes(i)||(this.abstractMethods.push(i),r==null||r.add(this,W.Updated)),r==null||r.attemptAutoclose(w.AddAbstractMethod,this.id),this):(Y.Logger.warn(`[addAbstractMethod] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),r==null||r.attemptAutoclose(w.AddAbstractMethod,this.id),this)}removeAbstractMethod(i,r=this.project.addChangeSet(new S(this.project,x.sessionAuthor,B().toISOString(),this,!0,w.RemoveAbstractMethod))){return this.checkCanEdit(this,r)?(this.abstractMethods.includes(i)&&(this.abstractMethods=this.abstractMethods.filter(a=>a.id!==i.id),r==null||r.add(this,W.Updated)),r==null||r.attemptAutoclose(w.RemoveAbstractMethod,this.id),this):(Y.Logger.warn(`[removeAbstractMethod] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),r==null||r.attemptAutoclose(w.RemoveAbstractMethod,this.id),this)}initChildren(i=this.project.addChangeSet(new S(this.project,x.sessionAuthor,B().toISOString(),this,!0,"init-children"))){if(this.initialized||this.startedInitialization)return this;if(this.startedInitialization=!0,this.properties=this.initialData.properties.map(r=>{const a=Re(r,this.project);return a.setParent(this,null),a.initChildren(i),a}),this.methods=this.initialData.methods.map(r=>{const a=Re(r,this.project);return a.setParent(this,null),a.initChildren(i),a}),this.abstractMethods=this.initialData.abstractMethods.map(r=>{const a=Re(r,this.project);return a.setParent(this,null),a.initChildren(i),a}),this.initialData.extends&&(this.extends=Re(this.initialData.extends,this.project)),this.implements=this.initialData.implements.map(r=>Re(r,this.project)),this.initialData.allPropertiesImplement){const r=Re(this.initialData.allPropertiesImplement,this.project);r.setParent(this,null),r.initChildren(null),this.setAllPropertiesImplement(r,i)}if(this.initialData.additionalPropertiesDataType){const r=Re(this.initialData.additionalPropertiesDataType,this.project);r.setParent(this,null),r.initChildren(null),this.setAdditionalPropertiesDataType(r,i)}return this.subscribeToDependencies(),this.afterAllChildrenInitialized(i),i==null||i.attemptAutoclose("init-children",this.id),this}removeUnrecognizedProperties(i=this.project.addChangeSet(new S(this.project,x.sessionAuthor,B().toISOString(),this,!0,"remove-unrecognized-properties"))){const r=[],a=[],c=[],e=[];let f=[...this.properties];f=f.filter(b=>b.parent.id===this.id),f=f.filter(b=>!b.isExtendedProperty);const h=this.implementedPropertiesFromOriginalParents,m=this.getAllPropertiesImplements();return f.filter(b=>this.interactive&&!b.implements.length?!1:!b.implements.find(_=>!!h.find(P=>P.id===_.id)||!!m.find(P=>P.id===_.id))).forEach(b=>{const A=b.remove({ignoreUpstream:!1},i);c.push(...A.removed),r.push(...A.updated)}),i==null||i.attemptAutoclose("remove-unrecognized-properties",this.id),{updated:C(r),added:C(a),removed:C(c),affected:C(e),self:this}}removeUnrecognizedMethods(i=this.project.addChangeSet(new S(this.project,x.sessionAuthor,B().toISOString(),this,!0,"remove-unrecognized-methods"))){const r=[],a=[],c=[],e=[];let f=[...this.methods];f=f.filter(m=>m.parent.id===this.id),f=f.filter(m=>!m.isExtendedMethod);const h=this.implementedMethodsFromOriginalParents;return f=f.filter(m=>this.interactive&&!m.implements?!1:!h.find(E=>{var b;return E.id===((b=m.implements)==null?void 0:b.id)})),f.forEach(m=>{const E=m.remove({ignoreUpstream:!1},i);c.push(...E.removed),r.push(...E.updated)}),i==null||i.attemptAutoclose("remove-unrecognized-methods",this.id),{updated:C(r),added:C(a),removed:C(c),affected:C(e),self:this}}syncImplementationMethods(i=this.project.addChangeSet(new S(this.project,x.sessionAuthor,B().toISOString(),this,!0,"sync-implementation-methods"))){const r=[],a=[],c=[],e=[],f=this.methods,h=this.implementedMethodsFromOriginalParents,m=[...this.allBaseMethodsFromExtendedAndImplementedEntities,...f];return h.filter(b=>!m.find(_=>{var P;return((P=_.implements)==null?void 0:P.id)===b.id})).forEach(b=>{if(this.methods.find(V=>{var M;return((M=V.implements)==null?void 0:M.id)===b.id}))return;const _=this.methods.find(V=>{var ne,J;if(V.name===b.name&&!V.implements)return!0;const M=di(this,ge.CRON_JOB),G=di(this,ge.HTTP_ENDPOINT),k=((ne=V.implements)==null?void 0:ne.id)===re["built-in-base-entity"].BUILT_IN_HTTP_ENDPOINT_ENTITY.methods.handler.id,q=((J=V.implements)==null?void 0:J.id)===re["built-in-base-entity"].BUILT_IN_CRON_JOB_ENTITY.methods.handler.id;return!!(M&&!q&&!G&&k||G&&!k&&!M&&q)});if(_&&_.type===d.FunctionDeclaration){_.setImplements(b,i),_.metaSync({name:b.name},i),i==null||i.add(_,W.Updated),i==null||i.add(this,W.Updated);return}const P=b.implementAsFunctionDeclaration(i,this);a.push(P),i==null||i.add(P,W.Added),this.addMethod(P,i)}),this.methods.sort((b,A)=>b.index-A.index).forEach(b=>{b.afterAllChildrenInitialized(i)}),i==null||i.attemptAutoclose("sync-implementation-methods",this.id),{updated:C(r),added:C(a),removed:C(c),affected:C(e),self:this}}syncImplementationProperties(i=this.project.addChangeSet(new S(this.project,x.sessionAuthor,B().toISOString(),this,!0,"sync-implementation-properties"))){const r=[],a=[],c=[],e=[],f=this.properties,h=this.implementedPropertiesFromOriginalParents.filter(E=>!this.allBasePropertiesFromExtendedAndImplementedEntities.find(A=>!!A.implements.find(_=>_.id===E.id))),m=[...this.allBasePropertiesFromExtendedAndImplementedEntities,...f];return h.forEach(E=>{const b=m.find(V=>!!V.implements.find(M=>M.id===E.id));if(b){const{updated:V,added:M,removed:G,affected:k}=b.syncWithImplementation(i);r.push(...V),a.push(...M),c.push(...G),e.push(...k);return}if(this.properties.find(V=>!!V.implements.find(M=>M.id===E.id)))return;const _=this.properties.find(V=>V.name===E.name&&!!V.abstract&&!V.implements);if(_){_.addImplementation(E,i),_.metaSync({abstract:!1},i),_.afterAllChildrenInitialized(i);return}const P=E.implement(this,i,x.UUID.uuid());a.push(P),i==null||i.add(P,W.Added)}),this.properties.find(E=>{var b;return E.id===((b=this.allPropertiesImplement)==null?void 0:b.id)})&&this.removeAllPropertiesImplement(i),i==null||i.attemptAutoclose("sync-implementation-properties",this.id),{updated:C(r),added:C(a),removed:C(c),affected:C(e),self:this}}addExtendedMethods(i=this.project.addChangeSet(new S(this.project,x.sessionAuthor,B().toISOString(),this,!0,"add-extended-methods"))){const r=[],a=[],c=[],e=[],f=this.methods,m=this.extendedMethodsFromOriginalParents.filter(b=>b.type===d.FunctionDeclaration),E=new Set(f.filter(b=>{var A;return!!((A=b.extends)!=null&&A.id)}).map(b=>b.extends.id));return m.forEach(b=>{if(E.has(b.id))return;E.add(b.id);const A=b.clone(i,this,x.UUID.uuid());A.setExtends(b,i),A.initChildren(i),a.push(A),i==null||i.add(A,W.Added),this.addMethod(A,i)}),i==null||i.attemptAutoclose("add-extended-methods",this.id),{updated:C(r),added:C(a),removed:C(c),affected:C(e),self:this}}addExtendedProperties(i=this.project.addChangeSet(new S(this.project,x.sessionAuthor,B().toISOString(),this,!0,"add-extended-properties"))){const r=[],a=[],c=[],e=[],f=this.properties,h=this.extendedPropertiesFromOriginalParents,m=h.filter(b=>h.find(_=>!!_.implements.find(P=>P.id===b.id))?!1:!b.abstract),E=new Set(f.filter(b=>{var A;return!!((A=b.extends)!=null&&A.id)}).map(b=>b.extends.id));return m.forEach(b=>{if(E.has(b.id))return;E.add(b.id);const A=b.clone(i,this,x.UUID.uuid());A.setExtends(b,i),A.initChildren(i),a.push(A),i==null||i.add(A,W.Added),this.addProperty(A,i)}),[...this.properties].forEach(b=>{if(b.extends)return;if(m.find(_=>_.name===b.name&&_.implements.every(P=>!!b.implements.find(V=>V.id===P.id)))){const _=b.remove({ignoreUpstream:!1},i);c.push(..._.removed),r.push(..._.updated)}}),this.properties.forEach(b=>{const A=b.afterAllChildrenInitialized(i);r.push(...A.updated),e.push(...A.affected),a.push(...A.added),c.push(...A.removed)}),i==null||i.attemptAutoclose("add-extended-properties",this.id),{updated:C(r),added:C(a),removed:C(c),affected:C(e),self:this}}addSuggestions(){return this.implements.forEach(i=>{Jje(this,i).forEach(c=>{const e=c.toJSON();e.id=`_suggestion--parent--${this.id}--${c.id}`;const f=Re(e,this.project);f.suggestion=!0,f.setParent(this,null),f.initChildren(null),this.addSuggestedProperty(f)}),Qje(this,i).forEach(c=>{const e=`_suggestion--parent--${this.id}--${c.id}`,f=c.implementAsFunctionDeclaration(null,this,e),h=Re(f,this.project);if(h.suggestion=!0,h.setParent(this,null),h.initChildren(null),this.methods=this.methods.filter(m=>m.id!==e),h.inputs.forEach(m=>{m.suggestion=!0}),h.returnStatements.length){const m=h.returnStatements[0];m.suggestion=!0,m.outputs.forEach(E=>{E.suggestion=!0})}this.addSuggestedMethod(h)})}),this}subscribe(){var i;return this.activeVersion=!0,(i=this.knownVersions)==null||i.forEach(r=>{r.version!==this.version&&(r.activeVersion=!1)}),this.project.subscribeInstance(this),this.project.subscribedDefinitionEntities.add(this.id),this}unsubscribe(){return this.project.unsubscribeInstance(this),this.project.subscribedDefinitionEntities.delete(this.id),this}metaSync(i,r=this.project.addChangeSet(new S(this.project,x.sessionAuthor,B().toISOString(),this,!0,"meta-sync"))){const a=tn(this,i,r),c=en(this,a),e=this.toMeta();return this.name=a.name!==void 0?a.name:e.name,this.codeName=a.codeName!==void 0?a.codeName:e.codeName,this.description=a.description!==void 0?a.description:e.description,this.x=a.x||e.x,this.y=a.y||e.y,this.static=a.static!==void 0?a.static:this.static,this.abstract=a.abstract!==void 0?a.abstract:this.abstract,this.additionalProperties=a.additionalProperties!==void 0?a.additionalProperties:e.additionalProperties,super.baseMetaSync(a,this,r),a.deleted===!0&&!e.deleted?r==null||r.add(this,W.Removed):a.deleted===!1&&e.deleted?r==null||r.add(this,W.Added):c&&(r==null||r.add(this,W.Updated)),r==null||r.attemptAutoclose("meta-sync",this.id),this}async APILoad(i=Ke,...r){return await Ni.repository.APILoad(this.id,...r),this}async APICreate(i=Ke,...r){return await Ni.repository.APICreate(this.toShallowJSON(),...r),this}async APIUpdate(i=Ke,...r){return await Ni.repository.APIUpdate(this.toShallowJSON(),...r),this}async APIDelete(i=Ke,...r){return await Ni.repository.APIDelete(this.toShallowJSON(),...r),this}async APIClone(i=Ke,...r){return await Ni.repository.APIClone(this.id,...r),this}async APILoadVersion(i=Ke,r,...a){return await Ni.repository.APILoadVersion(this.id,r,...a)}removeFromParent(i=this.project.addChangeSet(new S(this.project,x.sessionAuthor,B().toISOString(),this,!0,w.RemoveFromParent))){if(!this.checkCanEdit(this,i))return Y.Logger.warn(`[removeFromParent] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(w.RemoveFromParent,this.id),{added:[],updated:[],removed:[],affected:[],self:this};const r=[],a=[],c=[],e=[];if(this.parent.type===d.Project)this.parent.removeDefinitionEntity(this);else if(this.parent.type===d.DataType&&this.parent.entity&&this.parent.entity.id===this.id){const f=this.parent.setEntity(null,i);r.push(f)}return i==null||i.attemptAutoclose(w.RemoveFromParent,this.id),{added:C(c),updated:C(r),removed:C(a),affected:C(e),self:this}}remove({ignoreUpstream:i}={ignoreUpstream:!1},r=this.project.addChangeSet(new S(this.project,x.sessionAuthor,B().toISOString(),this,!0,w.RemoveEntity))){var h;if(!this.checkCanDelete(this,r))return Y.Logger.warn(`[remove] User is not allowed to delete or edit this ${this.type} entity with id: ${this.id}`),r==null||r.event({id:`${w.RemoveEntity}-${this.id}--${Me.ActionOwnerEntityNonDeletable}`,action:w.RemoveEntity,owner:this,errorReason:Me.ActionOwnerEntityNonDeletable,rootAction:((h=r==null?void 0:r.self)==null?void 0:h.id)===this.id&&(r==null?void 0:r.actionName)===w.RemoveEntity}),r==null||r.attemptAutoclose(w.RemoveEntity,this.id),{added:[],updated:[],removed:[],affected:[],self:this};const a=[],c=[],e=[],f=[];if(r!=null&&r.hasRemoved(this.id))return r==null||r.attemptAutoclose(w.RemoveEntity,this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(c.push(this),this.unsubscribe(),this.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},r),Object.values(this.detachedDependents).forEach(m=>{const{updated:E,removed:b,added:A}=m.entity.onDetachedDependencyRemoved(this,m.field,r);a.push(...E),c.push(...b),e.push(...A)}),this.properties.forEach(m=>{const{updated:E,removed:b}=m.remove({ignoreUpstream:!0},r);a.push(...E),c.push(...b)}),this.methods.forEach(m=>{const{updated:E,removed:b}=m.remove({ignoreUpstream:!0},r);a.push(...E),c.push(...b)}),this.abstractMethods.forEach(m=>{const{updated:E,removed:b}=m.remove({ignoreUpstream:!0},r);a.push(...E),c.push(...b)}),this.suggestedProperties.forEach(m=>{const{updated:E,removed:b}=m.remove({ignoreUpstream:!0},r);a.push(...E),c.push(...b)}),this.suggestedMethods.forEach(m=>{const{updated:E,removed:b}=m.remove({ignoreUpstream:!0},r);a.push(...E),c.push(...b)}),!i){const m=this.removeFromParent(r);e.push(...m.added),a.push(...m.updated),c.push(...m.removed),f.push(...m.affected)}return r==null||r.attemptAutoclose(w.RemoveEntity,this.id),{added:C(e),updated:C(a),removed:C(c),affected:C(f),self:this}}restore({}={},i=this.project.addChangeSet(new S(this.project,x.sessionAuthor,B().toISOString(),this,!0,w.RestoreEntity))){if(!this.checkCanEdit(this,i))return Y.Logger.warn(`[restore] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(w.RestoreEntity,this.id),{added:[],updated:[],removed:[],affected:[],self:this};const r=[],a=[],c=[],e=[];return i!=null&&i.hasAdded(this.id)?(i==null||i.attemptAutoclose(w.RestoreEntity,this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},i),Object.values(this.detachedDependents).forEach(f=>{const{updated:h,removed:m,added:E}=f.entity.onDetachedDependencyRestored(this,f.field,i);a.push(...h),c.push(...m),r.push(...E)}),this.properties.forEach(f=>{const{updated:h}=f.restore({},i);a.push(...h)}),this.methods.forEach(f=>{const{updated:h}=f.restore({},i);a.push(...h)}),this.abstractMethods.forEach(f=>{const{updated:h}=f.restore({},i);a.push(...h)}),this.suggestedProperties.forEach(f=>{const{updated:h}=f.restore({},i);a.push(...h)}),this.suggestedMethods.forEach(f=>{const{updated:h}=f.restore({},i);a.push(...h)}),i==null||i.attemptAutoclose(w.RestoreEntity,this.id),{added:C(r),updated:C(a),removed:C(c),affected:C(e),self:this})}toFlat(i=new Set){var a;return i.has(this.id)?[]:(i.add(this.id),[this,...((a=this.extends)==null?void 0:a.toFlat(i))||[],...this.implements.flatMap(c=>c.toFlat(i)),...this.properties.flatMap(c=>c.toFlat(i)),...this.methods.flatMap(c=>c.toFlat(i)),...this.abstractMethods.flatMap(c=>c.toFlat(i)),...this.parent.toFlat(i)])}toFlatIds(i=new Set){var a;return i.has(this.id)?[]:(i.add(this.id),[this.id,...((a=this.extends)==null?void 0:a.toFlatIds(i))||[],...this.implements.flatMap(c=>c.toFlatIds(i)),...this.properties.flatMap(c=>c.toFlatIds(i)),...this.methods.flatMap(c=>c.toFlatIds(i)),...this.abstractMethods.flatMap(c=>c.toFlatIds(i)),...this.parent.toFlatIds(i)])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,codeName:this.codeName,description:this.description,static:this.static,abstract:this.abstract,x:this.x,y:this.y,type:this.type,editable:this.editable,deletable:this.deletable,additionalProperties:this.additionalProperties,name:this.name}}toJSON(i=new Set){var r,a,c;return i.has(this.id)?this.toReference():(i.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,editable:this.editable,deletable:this.deletable,name:this.name,codeName:this.codeName,description:this.description,x:this.x,y:this.y,static:this.static,abstract:this.abstract,additionalProperties:this.additionalProperties,allPropertiesImplement:((r=this.allPropertiesImplement)==null?void 0:r.toJSON(i))||null,additionalPropertiesDataType:((a=this.additionalPropertiesDataType)==null?void 0:a.toJSON(i))||null,properties:this.properties.map(e=>e.toJSON(i)),methods:this.methods.map(e=>e.toJSON(i)),abstractMethods:this.abstractMethods.map(e=>e.toJSON(i)),implements:this.implements.map(e=>e.toJSON(i)),extends:((c=this.extends)==null?void 0:c.toJSON(i))||null,parent:this.parent.toReference()})}toJSONClone(i=at){var a,c,e,f,h,m,E,b,A,_;let r;return(a=i.seenEntityMaps)!=null&&a.has(this.id)?r=i.seenEntityMaps.get(this.id):(r=i.newId||dn(this,this.project,i.uuidStrategy),i.seenEntityMaps&&i.seenEntityMaps.set(this.id,r)),(c=i.seenEntities)!=null&&c.has(r)||(e=i.seenEntities)!=null&&e.has(this.id)?this.toReference({seenEntityMaps:i.seenEntityMaps}):((f=i.seenEntities)==null||f.add(r),(h=i.seenEntities)==null||h.add(this.id),{id:r,version:x.UUID.uuid(),createdAt:i.timestamp||B().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:((m=this.allPropertiesImplement)==null?void 0:m.toJSONClone(i))||null,additionalPropertiesDataType:((E=this.additionalPropertiesDataType)==null?void 0:E.toJSONClone(i))||null,properties:this.properties.map(P=>P.toJSONClone({...i,newId:null})),methods:this.methods.map(P=>P.toJSONClone({...i,newId:null})),abstractMethods:this.abstractMethods.map(P=>P.toJSONClone({...i,newId:null})),implements:this.implements.map(P=>P.type===d.BuiltInBaseEntity?P.toJSON(i.seenEntities):P.toJSONClone({...i,newId:null})),extends:((b=this.extends)==null?void 0:b.type)===d.BuiltInBaseEntity?(A=this.extends)==null?void 0:A.toJSON(i.seenEntities):(_=this.extends)==null?void 0:_.toJSONClone({...i,newId:null}),parent:this.parent.toReference({seenEntityMaps:i.seenEntityMaps})})}toReference(i=at){var a;let r=this.id;return(a=i.seenEntityMaps)!=null&&a.has(this.id)&&(r=i.seenEntityMaps.get(this.id)),{id:r+"--"+x.UUID.uuid()+"--ref",type:d.GenericReference,entityId:r,version:this.version,entityType:this.type}}toShallowJSON(i=at){var a,c,e,f;let r=this.id;return(a=i.seenEntityMaps)!=null&&a.has(this.id)&&(r=i.seenEntityMaps.get(this.id)),{id:r,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,name:this.name,codeName:this.codeName,description:this.description,type:this.type,editable:this.editable,deletable:this.deletable,x:this.x,y:this.y,static:this.static,abstract:this.abstract,additionalProperties:this.additionalProperties,allPropertiesImplement:((c=this.allPropertiesImplement)==null?void 0:c.toReference(i))||null,additionalPropertiesDataType:((e=this.additionalPropertiesDataType)==null?void 0:e.toReference(i))||null,properties:this.properties.map(h=>h.toReference(i)),methods:this.methods.map(h=>h.toReference(i)),abstractMethods:this.abstractMethods.map(h=>h.toReference(i)),implements:this.implements.map(h=>h.toReference(i)),extends:((f=this.extends)==null?void 0:f.toReference(i))||null,parent:this.parent.toReference(i)}}toFlatJSON(i=new Set){var a,c,e;return i.has(this.id)?[]:(i.add(this.id),[this.toShallowJSON(),...this.properties.flatMap(f=>f.toFlatJSON(i)),...this.methods.flatMap(f=>f.toFlatJSON(i)),...this.abstractMethods.flatMap(f=>f.toFlatJSON(i)),...this.implements.flatMap(f=>f.toFlatJSON(i)),...((a=this.extends)==null?void 0:a.toFlatJSON(i))||[],...this.parent.toFlatJSON(i),...((c=this.additionalPropertiesDataType)==null?void 0:c.toFlatJSON(i))||[],...((e=this.allPropertiesImplement)==null?void 0:e.toFlatJSON(i))||[]])}toGenerationTarget(i=at){var c,e,f;const r=this.parent.type===d.Project?void 0:(c=i.seenEntityMaps)!=null&&c.has(this.parent.id)?i.seenEntityMaps.get(this.parent.id):this.parent.id;let a=this.id;return(e=i.seenEntityMaps)!=null&&e.has(this.id)&&(a=i.seenEntityMaps.get(this.id)),{id:a,name:this.name,description:this.description,type:this.type,static:this.static,abstract:this.abstract,extends:(f=this.extends)==null?void 0:f.id,additionalProperties:this.additionalProperties,implements:this.implements.map(h=>h.id),parent:r}}toFlatGenerationTarget(i=new Set){var a,c,e;return i.has(this.id)?[]:(i.add(this.id),[this.toGenerationTarget(),...this.properties.flatMap(f=>f.toFlatGenerationTarget(i)),...this.methods.flatMap(f=>f.toFlatGenerationTarget(i)),...this.abstractMethods.flatMap(f=>f.toFlatGenerationTarget(i)),...this.implements.filter(f=>f.type===d.DefinitionEntity).flatMap(f=>f.toFlatGenerationTarget(i)),...((a=this.extends)==null?void 0:a.toFlatGenerationTarget(i))||[],...this.parent.toFlatGenerationTarget(i),...((c=this.additionalPropertiesDataType)==null?void 0:c.toFlatGenerationTarget(i))||[],...((e=this.allPropertiesImplement)==null?void 0:e.toFlatGenerationTarget(i))||[]])}clearErrors(){var i,r;return this.errors=[],this.properties.forEach(a=>a.clearErrors()),this.methods.forEach(a=>a.clearErrors()),this.abstractMethods.forEach(a=>a.clearErrors()),(i=this.additionalPropertiesDataType)==null||i.clearErrors(),(r=this.allPropertiesImplement)==null||r.clearErrors(),this}validate(){return this.errors=Yje(this),{success:!0}}async validateAsync(i={}){const r=Y.YieldTracker.from(i);return this.errors=await zje(this,{tracker:r}),{success:!0}}getErrors(){var r,a;return[...this.errors,...this.properties.flatMap(c=>c.getErrors()),...this.methods.flatMap(c=>c.getErrors()),...this.abstractMethods.flatMap(c=>c.getErrors()),...((r=this.additionalPropertiesDataType)==null?void 0:r.getErrors())||[],...((a=this.allPropertiesImplement)==null?void 0:a.getErrors())||[]]}async getErrorsAsync(i={}){const r=Y.YieldTracker.from(i),a=[...this.errors];await r.tick();for(const c of this.properties)a.push(...await c.getErrorsAsync({tracker:r}));for(const c of this.methods)a.push(...await c.getErrorsAsync({tracker:r}));for(const c of this.abstractMethods)a.push(...await c.getErrorsAsync({tracker:r}));return this.additionalPropertiesDataType&&a.push(...await this.additionalPropertiesDataType.getErrorsAsync({tracker:r})),this.allPropertiesImplement&&a.push(...await this.allPropertiesImplement.getErrorsAsync({tracker:r})),a}getShallowErrors(){return this.errors}clone(i=this.project.addChangeSet(new S(this.project,x.sessionAuthor,B().toISOString(),this,!0,w.CloneEntity)),r=null,a=null,c=!0){var M,G,k;const e=Fr(r,this),f=this.toJSON(),h=a||x.UUID.uuid(),m=r||this.parent;f.properties=[],f.methods=[],f.abstractMethods=[];const E=h.split("-id"),b=E[E.length-1||0]||h;f.id=h,f.version=x.UUID.uuid(),f.createdAt=(i==null?void 0:i.timestamp)||B().toISOString(),f.author=(i==null?void 0:i.author)||"1",f.previousVersion=null,f.deleted=!1,f.editable=!0,f.deletable=!0,f.parent=m.toReference();const A=lr(f,e);A.hydrateAncestors(),A.setParent(m,i),c&&(A.subscribe(),A.addSelfToProject(i)),A.initChildren(i),i==null||i.add(A,W.Added);const _=(M=this.properties)==null?void 0:M.map(q=>this.project.diggestedBuiltInBaseEntitiesIds.has(q.id)?q:q.clone(i,A,x.UUID.uuid(),c));A.properties=_;const P=(G=this.methods)==null?void 0:G.map((q,ne)=>this.project.diggestedBuiltInBaseEntitiesIds.has(q.id)?q:q.clone(i,A,b+"-method-"+ne+"-id",c));A.methods=P;const V=(k=this.abstractMethods)==null?void 0:k.map((q,ne)=>this.project.diggestedBuiltInBaseEntitiesIds.has(q.id)?q:q.clone(i,A,b+"-abstract-method-"+ne+"-id",c));if(A.abstractMethods=V,this.additionalPropertiesDataType)if(this.project.diggestedBuiltInBaseEntitiesIds.has(this.additionalPropertiesDataType.id))A.setAdditionalPropertiesDataType(this.additionalPropertiesDataType,i);else{const q=this.additionalPropertiesDataType.clone(i,A,x.UUID.uuid(),c);A.setAdditionalPropertiesDataType(q,i)}if(this.allPropertiesImplement)if(this.project.diggestedBuiltInBaseEntitiesIds.has(this.allPropertiesImplement.id))A.setAllPropertiesImplement(this.allPropertiesImplement,i);else{const q=this.allPropertiesImplement.clone(i,A,x.UUID.uuid(),c);A.setAllPropertiesImplement(q,i)}return i||A.captureVersion(),i==null||i.attemptAutoclose(w.CloneEntity,this.id),A}getFunctionDeclaration(i){return this.methods.find(r=>r.id===i)}implement(i,r=this.project.addChangeSet(new S(this.project,x.sessionAuthor,B().toISOString(),this,!0,"implement-definition-entity")),a){const c=m1(this,i,r,a);return r==null||r.attemptAutoclose("implement-definition-entity",this.id),c}getAllPropertiesImplements(){var r;const i=[];return this.allPropertiesImplement&&i.push(this.allPropertiesImplement),i.push(...((r=this.extends)==null?void 0:r.getAllPropertiesImplements())||[],...this.implements.flatMap(a=>a.getAllPropertiesImplements())),i}getAllInteractiveMethods(){var e;const i=this.implements.filter(f=>f.type===d.DefinitionEntity||f.type===d.BuiltInBaseEntity&&f.interactive),r=((e=this.extends)==null?void 0:e.getAllInteractiveMethods())||[],a=i.flatMap(f=>f.getAllInteractiveMethods());return C([...this.methods,...r,...a])}inferFromInputs(i,r=this.project.addChangeSet(new S(this.project,x.sessionAuthor,B().toISOString(),this,!0,"infer-definition-entity-from-inputs"))){const a=[],c=[],e=[],f=[];if(this.parent.type!==d.DataType||!this.parent.inferred)return r==null||r.attemptAutoclose("infer-definition-entity-from-inputs",this.id),{added:[],updated:[],removed:[],affected:[],self:this};const h=[];i.forEach(b=>{h.find(_=>ce(_,this.project)===ce(b,this.project))||h.push(b)});const m=this.properties.filter(b=>!b.dataType);h.forEach(b=>{var k,q,ne;const A=m.find(J=>ce(J,this.project)===ce(b,this.project));if(!A)return;const P=gr(b.parent).getMasterInputWithValueWriterFromAllInstances(b),V=iu(P,r),M=V==null?void 0:V.clone(r,A,x.UUID.uuid(),!0);M&&((k=A.dataType)==null||k.merge(M,r),M.id!==((q=A.dataType)==null?void 0:q.id)&&M.remove({ignoreUpstream:!1},r),A.dataType&&(A.dataType.metaSync({inferred:!0,like:!0},r),A.setDataType(A.dataType,r),r==null||r.add(A,W.Affected)));let G=null;if(b.declaration&&A.id!==((ne=b.declaration)==null?void 0:ne.id)&&(G=b.declaration),b.setDeclaration(A,r),r==null||r.add(b,W.Updated),G){const{updated:J,removed:se}=G.remove({ignoreUpstream:!1},r);c.push(...J),e.push(...se)}});const E=[];return h.forEach(b=>{if(!b.declaration){E.push(b);return}}),E.length===0?(r==null||r.attemptAutoclose("infer-definition-entity-from-inputs",this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(E.forEach(b=>{var ne,J,se,te,le;const A=this.properties.find(ue=>ce(ue,this.project)===ce(b,this.project));if(A){if(b.setDeclaration(A,r),!A.getDataType(r)){const z=gr(b.parent).getMasterInputWithValueWriterFromAllInstances(b),Q=iu(z),de=Q==null?void 0:Q.clone(r,A,x.UUID.uuid(),!0);de&&((ne=A.dataType)==null||ne.merge(de,r),de.id!==((J=A.dataType)==null?void 0:J.id)&&de.remove({ignoreUpstream:!1},r),A.dataType&&(A.dataType.metaSync({inferred:!0,like:!0},r),A.setDataType(A.dataType,r),r==null||r.add(A,W.Affected)))}return}const _=ce(b,this.project),P=b.codeName||Ep(b,this.project)||cs(ir(_)),V=Es.new(r);V.parent=this.toReference(),V.index=b.index,V.name=_,V.codeName=P,V.description=b.description;const M=Re(V,this.project);M.hydrateAncestors(),M.addSelfToProject(r),r==null||r.add(M,W.Added),M.setParent(this,r),M.initChildren(r),r||M.captureVersion();const k=gr(b.parent).getMasterInputWithValueWriterFromAllInstances(b),q=iu(k);if(q&&q.id!==((se=M.dataType)==null?void 0:se.id)){const ue=q==null?void 0:q.clone(r,M,x.UUID.uuid(),!0);ue&&((te=M.dataType)==null||te.merge(ue,r),ue.id!==((le=M.dataType)==null?void 0:le.id)&&ue.remove({ignoreUpstream:!1},r),M.dataType&&(M.dataType.metaSync({inferred:!0,like:!0},r),M.setDataType(M.dataType,r),r==null||r.add(M,W.Affected)))}return this.addProperty(M,r),b.setDeclaration(M,r),r==null||r.add(b,W.Updated),M}),r==null||r.attemptAutoclose("infer-definition-entity-from-inputs",this.id),{added:C(a),updated:C(c),removed:C(e),affected:C(f),self:this})}getRawDefaultValue(){const i={};return this.properties.forEach(r=>{var e;if(!bv(r)||!r.defaultValue)return;const a=ce(r,this.project),c=r.codeName||Ep(r,this.project)||cs(ir(a));i[c]=((e=r.getDefaultValue())==null?void 0:e.value)||null}),i}getActiveRawDefaultValue(){const i={};return this.properties.forEach(r=>{var f;if(!bv(r))return;const a=ce(r,this.project),c=r.codeName||Ep(r,this.project)||cs(ir(a)),e=(f=this.project.requestActiveDynamicValue(r,!0))==null?void 0:f.value;e&&(i[c]=(e==null?void 0:e.value)||null)}),i}setAdditionalPropertiesDataType(i,r=this.project.addChangeSet(new S(this.project,x.sessionAuthor,B().toISOString(),this,!0,w.SetAdditionalPropertiesDataType))){if(!this.checkCanEdit(this,r))return Y.Logger.warn(`[setAdditionalPropertiesDataType] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),r==null||r.attemptAutoclose(w.SetAdditionalPropertiesDataType,this.id),this;const a=this.additionalPropertiesDataType;return(a==null?void 0:a.id)!==(i==null?void 0:i.id)&&(a==null||a.remove({ignoreUpstream:!0},r),this.additionalPropertiesDataType=i,this.subscribeToDependencies(),r==null||r.add(this,W.Affected)),r==null||r.attemptAutoclose(w.SetAdditionalPropertiesDataType,this.id),this}removeAdditionalPropertiesDataType(i=this.project.addChangeSet(new S(this.project,x.sessionAuthor,B().toISOString(),this,!0,w.RemoveAllPropertiesImplement))){return this.checkCanEdit(this,i)?(this.additionalPropertiesDataType&&(this.additionalPropertiesDataType.remove({ignoreUpstream:!0},i),i==null||i.add(this,W.Affected),this.additionalPropertiesDataType=null),i==null||i.attemptAutoclose(w.RemoveAllPropertiesImplement,this.id),this):(Y.Logger.warn(`[removeAdditionalPropertiesDataType] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(w.RemoveAllPropertiesImplement,this.id),this)}setAllPropertiesImplement(i,r=this.project.addChangeSet(new S(this.project,x.sessionAuthor,B().toISOString(),this,!0,w.SetAllPropertiesImplement))){if(!this.checkCanEdit(this,r))return Y.Logger.warn(`[setAllPropertiesImplement] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),r==null||r.attemptAutoclose(w.SetAllPropertiesImplement,this.id),this;const a=this.allPropertiesImplement;return(a==null?void 0:a.id)!==(i==null?void 0:i.id)&&(a==null||a.remove({ignoreUpstream:!0},r),this.allPropertiesImplement=i,this.subscribeToDependencies(),r==null||r.add(this,W.Affected)),r==null||r.attemptAutoclose(w.SetAllPropertiesImplement,this.id),this}removeAllPropertiesImplement(i=this.project.addChangeSet(new S(this.project,x.sessionAuthor,B().toISOString(),this,!0,w.RemoveAllPropertiesImplement))){return this.checkCanEdit(this,i)?(this.allPropertiesImplement&&(this.properties.find(r=>{var a;return r.id===((a=this.allPropertiesImplement)==null?void 0:a.id)})||this.allPropertiesImplement.remove({ignoreUpstream:!0},i),i==null||i.add(this,W.Affected),this.allPropertiesImplement=null),i==null||i.attemptAutoclose(w.RemoveAllPropertiesImplement,this.id),this):(Y.Logger.warn(`[removeAllPropertiesImplement] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(w.RemoveAllPropertiesImplement,this.id),this)}};R(Ni,"repository",{APICreate:async(i,...r)=>i,APIUpdate:async(i,...r)=>i,APIDelete:async(i,...r)=>i,APIClone:async(i,...r)=>{},APILoad:async(i,...r)=>null,APILoadVersion:async(i,r,...a)=>null}),R(Ni,"type",d.DefinitionEntity),R(Ni,"USER_MANAGED_PARENT_TYPES",[d.Project,d.DataType]),R(Ni,"PARENT_TYPES",[...Ni.USER_MANAGED_PARENT_TYPES]),R(Ni,"MUTABLE_BASE_PROPERTIES",["name","codeName","description","static","abstract","additionalProperties"]),R(Ni,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),R(Ni,"BASE_PROPERTIES",[...Ni.MUTABLE_BASE_PROPERTIES,...Ni.INMUTABLE_BASE_PROPERTIES]),R(Ni,"MUTABLE_META_PROPERTIES",[...Ni.MUTABLE_BASE_PROPERTIES,"x","y"]),R(Ni,"INMUTABLE_META_PROPERTIES",[...Ni.INMUTABLE_BASE_PROPERTIES]),R(Ni,"META_PROPERTIES",[...Ni.MUTABLE_META_PROPERTIES,...Ni.INMUTABLE_META_PROPERTIES]),R(Ni,"MUTABLE_UPSTREAM_PROPERTIES",["extends","implements"]),R(Ni,"INMUTABLE_UPSTREAM_PROPERTIES",["parent"]),R(Ni,"UPSTREAM_PROPERTIES",[...Ni.MUTABLE_UPSTREAM_PROPERTIES,...Ni.INMUTABLE_UPSTREAM_PROPERTIES]),R(Ni,"MUTABLE_DOWNSTREAM_PROPERTIES",["properties","methods","abstractMethods","allPropertiesImplement","additionalPropertiesDataType"]),R(Ni,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),R(Ni,"DOWNSTREAM_PROPERTIES",[...Ni.MUTABLE_DOWNSTREAM_PROPERTIES,...Ni.INMUTABLE_DOWNSTREAM_PROPERTIES]),R(Ni,"PROPERTIES",[...Ni.META_PROPERTIES,...Ni.UPSTREAM_PROPERTIES,...Ni.DOWNSTREAM_PROPERTIES]);let Ks=Ni;async function UVi(s,p={}){const i=Y.YieldTracker.from(p),r=[],a=qt(s.errors,r);return await i.tick(),a}function FVi(s){const p=[];return qt(s.errors,p)}const lI=class lI extends Gx{constructor(i,r){super(i);R(this,"initialData");R(this,"id");R(this,"name");R(this,"description",null);R(this,"type",d.PrimitiveEntity);R(this,"static");R(this,"abstract");R(this,"properties",[]);R(this,"methods",[]);R(this,"abstractMethods",[]);R(this,"extends",null);R(this,"errors",[]);R(this,"project");this.initialData=i,this.project=r,this.id=i.id,this.name=i.name,this.description=i.description,this.static=i.static,this.abstract=i.abstract,this.properties=this.initialData.properties.map(a=>{const c=Re(a,this.project);return c.setParent(this,null),c.initChildren(null),c}),this.methods=this.initialData.methods.map(a=>{const c=Re(a,this.project);return c.parent=this,c}),this.abstractMethods=this.initialData.abstractMethods.map(a=>{const c=Re(a,this.project);return c.parent=this,c}),this.initialData.extends&&(this.extends=Re(this.initialData.extends,this.project))}get allMethods(){return C([...this.ownDeclaredMethods,...this.allBaseMethodsFromOriginalParents])}get allProperties(){return C([...this.ownDeclaredProperties,...this.allBasePropertiesFromOriginalParents])}get allBaseMethodsFromOriginalParents(){var a;const i=((a=this.extends)==null?void 0:a.allMethods)||[],r=[...i].filter(c=>!i.some(e=>e.id!==c.id));return C(r)}get allBasePropertiesFromOriginalParents(){var a;const i=((a=this.extends)==null?void 0:a.allProperties)||[],r=[...i].filter(c=>!i.some(e=>{var f;return e.id!==c.id&&(e.implements.find(h=>h.id===c.id)||((f=e.extends)==null?void 0:f.id)===c.id)}));return C(r)}get allBasePropertiesFromExtendedAndImplementedEntities(){var a,c;const i=[...((a=this.extends)==null?void 0:a.ownDeclaredProperties)||[],...((c=this.extends)==null?void 0:c.allBasePropertiesFromExtendedAndImplementedEntities)||[]].filter(e=>!e.abstract),r=[...i].filter(e=>!i.some(f=>{var h;return f.id!==e.id&&(f.implements.find(m=>m.id===e.id)||((h=f.extends)==null?void 0:h.id)===e.id)}));return C(r)}get extendedPropertiesFromOriginalParents(){var a,c;const i=[...((a=this.extends)==null?void 0:a.ownDeclaredProperties)||[],...((c=this.extends)==null?void 0:c.extendedPropertiesFromOriginalParents)||[]].filter(e=>!e.abstract),r=[...i].filter(e=>!i.some(f=>{var h;return f.id!==e.id&&(f.implements.find(m=>m.id===e.id)||((h=f.extends)==null?void 0:h.id)===e.id)}));return C(r)}get implementedPropertiesFromOriginalParents(){return C([...(this.extends?[this.extends]:[]).reduce((i,r)=>{const a=r.implementedPropertiesFromOriginalParents,c=[...r.ownDeclaredProperties].filter(h=>!!h.abstract),e=[...a,...c,...i];return[...e].filter(h=>!!!e.find(E=>{var b;return((b=E.extends)==null?void 0:b.id)===h.id||E.implements.find(A=>A.id===h.id)}))},[])])}get extendedProperties(){return this.properties.filter(i=>i.isExtendedProperty)}get ownDeclaredMethods(){return[...this.methods]}get ownDeclaredProperties(){return this.properties.filter(i=>!i.isExtendedProperty)}subscribe(){return this.project.subscribeBuiltInInstance(this),this}unsubscribe(){return this.project.unsubscribeBuiltInInstance(this),this}async APILoad(i=Ke,...r){return await lI.repository.APILoad(this.id,...r),this}toFlat(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this,...this.properties.flatMap(a=>a.toFlat(i)),...this.methods.flatMap(a=>a.toFlat(i)),...this.abstractMethods.flatMap(a=>a.toFlat(i))])}toFlatIds(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.id,...this.properties.flatMap(a=>a.toFlatIds(i)),...this.methods.flatMap(a=>a.toFlatIds(i)),...this.abstractMethods.flatMap(a=>a.toFlatIds(i))])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,description:this.description,static:this.static,abstract:this.abstract,type:this.type,name:this.name}}toJSON(i=new Set){var r;return i.has(this.id)?this.toReference():(i.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,static:this.static,abstract:this.abstract,properties:this.properties.map(a=>a.toJSON(i)),methods:this.methods.map(a=>a.toJSON(i)),abstractMethods:this.abstractMethods.map(a=>a.toJSON(i)),extends:((r=this.extends)==null?void 0:r.toJSON(i))||null})}toReference(i=at){return{id:this.id+"--"+x.UUID.uuid()+"--ref",type:d.GenericReference,entityId:this.id,version:this.version,entityType:this.type}}toShallowJSON(i=at){var r;return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,abstract:this.abstract,static:this.static,properties:this.properties.map(a=>a.toReference()),methods:this.methods.map(a=>a.toReference()),abstractMethods:this.abstractMethods.map(a=>a.toReference()),extends:((r=this.extends)==null?void 0:r.toReference())||null}}toFlatJSON(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.toShallowJSON(),...this.properties.flatMap(a=>a.toFlatJSON(i)),...this.methods.flatMap(a=>a.toFlatJSON(i)),...this.abstractMethods.flatMap(a=>a.toFlatJSON(i))])}toGenerationTarget(i=at){var r;return{id:this.id,type:this.type,name:this.name,description:this.description,static:this.static,abstract:this.abstract,extends:(r=this.extends)==null?void 0:r.id}}toFlatGenerationTarget(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.toGenerationTarget(),...this.properties.flatMap(a=>a.toFlatGenerationTarget(i)),...this.methods.flatMap(a=>a.toFlatGenerationTarget(i)),...this.abstractMethods.flatMap(a=>a.toFlatGenerationTarget(i))])}clearErrors(){return this.errors=[],this.properties.forEach(i=>i.clearErrors()),this.methods.forEach(i=>i.clearErrors()),this.abstractMethods.forEach(i=>i.clearErrors()),this}validate(){return this.errors=FVi(this),{success:!0}}async validateAsync(i={}){const r=Y.YieldTracker.from(i);return this.errors=await UVi(this,{tracker:r}),{success:!0}}getErrors(){return[...this.errors,...this.properties.flatMap(r=>r.getErrors()),...this.methods.flatMap(r=>r.getErrors()),...this.abstractMethods.flatMap(r=>r.getErrors())]}async getErrorsAsync(i={}){const r=Y.YieldTracker.from(i),a=[...this.errors];await r.tick();for(const c of this.properties){const e=await c.getErrorsAsync({tracker:r});a.push(...e)}for(const c of this.methods){const e=await c.getErrorsAsync({tracker:r});a.push(...e)}for(const c of this.abstractMethods){const e=await c.getErrorsAsync({tracker:r});a.push(...e)}return a}getShallowErrors(){return this.errors}getAllInteractiveMethods(){const i=[];return i.push(...this.methods),!this.extends||this.extends.type===d.PrimitiveEntity?i:C(i)}};R(lI,"repository",{APILoad:async(i,...r)=>null});let Pf=lI;function lr(s,p){if(!s)throw new Error("Entity is null");const i=p.get(s.id);switch(s.type){case d.LiteralValue:return i||new Lr(s,p);case d.DefinitionEntity:return i||new Ks(s,p);case d.PrimitiveEntity:return i||new Pf(s,p);case d.FunctionDeclaration:return i||new md(s,p);case d.GlobalEvent:return i||new _p(s,p);case d.DataType:return i||new vr(s,p);case d.Property:return i||new Es(s,p);case d.FunctionCall:return i||new Cp(s,p);case d.Condition:return i||new Pp(s,p);case d.Operation:return i||new Op(s,p);case d.VariableDeclaration:return i||new $p(s,p);case d.VariableInstance:return i||new xp(s,p);case d.OutputMap:return i||new po(s,p);case d.ArgumentDeclaration:return i||new Za(s,p);case d.InputMap:return i||new Ts(s,p);case d.Project:return i||new x(s);case d.InstalledProject:return i||new Bp(s,p);case d.ActionDescriptor:return i||new er(s,p);case d.ReturnStatement:return i||new lu(s,p);case d.Loop:return i||new Vp(s,p);case d.Search:return i||new Lp(s,p);case d.ValueDescriptor:return i||new Ed(s,p);case d.BuiltInBaseEntity:return i||new Td(s,p);case d.InternalCall:return i||new Mp(s,p);case d.ContinueStatement:return i||new kp(s,p);case d.BreakStatement:return i||new Gp(s,p);case d.GenericReference:return p.get(s.entityId);default:throw new Error("Invalid entity type: "+s.type)}}function Re(s,p){if(!s)throw new Error("Entity is null");const i=lr(s,p);return i.subscribe(),i}function KVi(s,p,i){if(!s)throw new Error("Entity is null");switch(s.type){case d.LiteralValue:return Lr.fromGenerationTarget(s,p,i);case d.DefinitionEntity:return Ks.fromGenerationTarget(s,p,i);case d.FunctionDeclaration:return md.fromGenerationTarget(s,p,i);case d.GlobalEvent:return _p.fromGenerationTarget(s,p,i);case d.DataType:return vr.fromGenerationTarget(s,p,i);case d.Property:return Es.fromGenerationTarget(s,p,i);case d.FunctionCall:return Cp.fromGenerationTarget(s,p,i);case d.Condition:return Pp.fromGenerationTarget(s,p,i);case d.Operation:return Op.fromGenerationTarget(s,p,i);case d.VariableDeclaration:return $p.fromGenerationTarget(s,p,i);case d.VariableInstance:return xp.fromGenerationTarget(s,p,i);case d.OutputMap:return po.fromGenerationTarget(s,p,i);case d.ArgumentDeclaration:return Za.fromGenerationTarget(s,p,i);case d.InputMap:return Ts.fromGenerationTarget(s,p,i);case d.InstalledProject:return Bp.fromGenerationTarget(s,p,i);case d.ReturnStatement:return lu.fromGenerationTarget(s,p,i);case d.Loop:return Vp.fromGenerationTarget(s,p,i);case d.Search:return Lp.fromGenerationTarget(s,p,i);case d.ActionDescriptor:return er.fromGenerationTarget(s,p,i);case d.ValueDescriptor:return Ed.fromGenerationTarget(s,p,i);case d.InternalCall:return Mp.fromGenerationTarget(s,p,i);case d.ContinueStatement:return kp.fromGenerationTarget(s,p,i);case d.BreakStatement:return Gp.fromGenerationTarget(s,p,i);default:throw new Error("Invalid entity type: "+s.type)}}const at={seenEntityMaps:new Map,seenEntities:new Set,timestamp:B().toISOString()};class rUe{constructor(){R(this,"initialData")}}const Ke={cascade:!1},nUe={APILoad:async(s,...p)=>null},qVi={APICreate:async(s,...p)=>s,APIUpdate:async(s,...p)=>s,APIDelete:async(s,...p)=>s,APIClone:async(s,...p)=>{},APILoadVersion:async(s,p,...i)=>null,...nUe};class SVi{}class aUe extends rUe{}class ZVi extends aUe{}class HVi{}class WVi{}class zVi{}class RL{}class YVi extends RL{}class JVi extends RL{}class QVi{}class uy{static initReadsValue(p){if(p.initialData.readsValue&&p.initialData.readsValue.type!==d.GenericReference)p.readsValue=Re(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(Mt.includes(p.readsValue.type)){let i=p.parent;!Dr.includes(i.type)&&i.type!==d.Project&&(i=i.parent);const r=p.type===d.InputMap&&p.parent.type===d.Loop;r&&(i=p.parent.parent),p.readsValue.setParent(i,null),p.readsValue.initChildren(null),i&&i.type!==d.Project&&!r&&i.detachedChildren.includes(p)?i.replaceDetachedChild(p,p.readsValue):i&&i.type!==d.Project&&!r&&i.subscribeDetachedChild(p.readsValue)}p.readsValue.addValueReader(p,null)}return p.readsValue}}class QE{static initWritesValues(p,i){const r=p.initialData.writesValues.reduce((c,e)=>{if(e.type===d.GenericReference||p.writesValues.some(h=>h.id===e.id))return c;const f=Re(e,p.project);return f.setValueWriter(p,null),Mt.includes(f.type)&&(f.setParent(i,null),f.initChildren(null)),[...c,f]},[]),a=[...p.writesValues];return p.writesValues=C([...a,...r]),p.writesValues}}class XVi{}var pi=(s=>(s.PROJECT_INITIALIZED="project-initialized",s.BEFORE_CHANGE_SET_CLOSE_BEFORE_SIDE_EFFECTS="before-change-set-close-before-side-effects",s.BEFORE_CHANGE_SET_CLOSE_AFTER_SIDE_EFFECTS="before-change-set-close-after-side-effects",s.CHANGE_SET_CLOSED_BEFORE_PERSIST="change-set-closed-before-persist",s.CHANGE_SET_PERSISTED="change-set-persisted",s.BEFORE_CHANGE_SET_PERSIST="before-change-set-persist",s.EXPLICIT_DEFINITION_ENTITY_ADDED="explicit-definition-entity-added",s.EXPLICIT_DEFINITION_ENTITY_REMOVED="explicit-definition-entity-removed",s.EXPLICIT_DEFINITION_ENTITY_UPDATED="explicit-definition-entity-updated",s.PERSISTED_DEFINITION_ENTITY_ADDED="persisted-definition-entity-added",s.PERSISTED_DEFINITION_ENTITY_REMOVED="persisted-definition-entity-removed",s.PERSISTED_DEFINITION_ENTITY_UPDATED="persisted-definition-entity-updated",s.RELATIONAL_DATABASE_DEFINITION_ENTITY_ADDED="relational-database-definition-entity-added",s.RELATIONAL_DATABASE_DEFINITION_ENTITY_REMOVED="relational-database-definition-entity-removed",s.RELATIONAL_DATABASE_DEFINITION_ENTITY_UPDATED="relational-database-definition-entity-updated",s))(pi||{});const DL={...h$,events:new Y.Events("def-proj-static-p-ctx-events")},sUe={requestActiveDynamicValue:(s,p=!1)=>null,...DL},Gt=class Gt extends un{constructor(i,r={...sUe,events:new Y.Events("def-proj-inst-p-ctx-events")}){super(i);R(this,"initialData");R(this,"id");R(this,"type",d.Project);R(this,"workspaceId");R(this,"name",null);R(this,"description",null);R(this,"x");R(this,"y");R(this,"entities",[]);R(this,"projects",[]);R(this,"functions",[]);R(this,"events",[]);R(this,"variableDeclarations",[]);R(this,"variableInstances",[]);R(this,"conditions",[]);R(this,"operations",[]);R(this,"functionCalls",[]);R(this,"loops",[]);R(this,"searches",[]);R(this,"primitives",[]);R(this,"builtInBaseEntities",[]);R(this,"operationDeclarations",[]);R(this,"globalEventActionDescriptors",[]);R(this,"loopDeclarations",[]);R(this,"loopDeclarationsBodies",[]);R(this,"conditionDeclarations",[]);R(this,"valueDescriptors",[]);R(this,"dataTypes",[]);R(this,"project");R(this,"instances",{});R(this,"builtInInstances",{});R(this,"deletedInstances",{});R(this,"subscribedDefinitionEntities",new Set);R(this,"errors",[]);R(this,"references",[]);R(this,"history",[]);R(this,"undoableStackValueIndex",-1);R(this,"detachedDependents",{});R(this,"knownVersions",null);R(this,"activeVersion",!1);R(this,"initialized",!1);R(this,"startedInitialization",!1);R(this,"diggestedBuiltInBaseEntitiesIds",new Set);R(this,"rejectParallelCS",!1);R(this,"onPersistChangeSetSequentiallyCallback",null);R(this,"onPersistChangeSetInParallelCallback",null);R(this,"onAddChangeSetCallback",null);R(this,"onDiscardChangeSetCallback",null);if(this.parentContext=r,this.initialData=i,this.id=i.id,this.workspaceId=i.workspaceId,this.name=i.name,this.description=i.description,this.x=0,this.y=0,this.instances[this.id]=this,!Gt.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:Gt.UUID.uuid(),version:Gt.UUID.uuid(),workspaceId:"",createdAt:(i==null?void 0:i.timestamp)||B().toISOString(),author:(i==null?void 0:i.author)||Gt.sessionAuthor,previousVersion:null,deleted:!1,deletable:!0,editable:!0,type:d.Project,name:"",description:"",entities:[],functions:[],events:[],projects:[],variableDeclarations:[],variableInstances:[],conditions:[],operations:[],functionCalls:[],loops:[],searches:[]}}static validateGenerationTarget(i,r){let a=JSON.parse(JSON.stringify(i));const c=[],e=[],f=Xr(a);return e.push(...f.errors),c.push(...f.explanations),{errors:e,explanations:c,modifiedData:a}}get off(){return this.parentContext.events.off}get on(){return this.parentContext.events.on}get emit(){return this.parentContext.events.emit}get emitAsync(){return this.parentContext.events.emitAsync}get emitAsyncAll(){return this.parentContext.events.emitAsyncAll}get emitAsyncAllSettled(){return this.parentContext.events.emitAsyncAllSettled}get emitAsyncSequentially(){return this.parentContext.events.emitAsyncSequentially}get emitAsyncSequentiallyAll(){return this.parentContext.events.emitAsyncSequentiallyAll}get emitAsyncSequentiallyAllSettled(){return this.parentContext.events.emitAsyncSequentiallyAllSettled}async closePersistChangeSetsSequentially(){Y.Logger.log("[ProjectState.closePersistChangeSetsSequentially] called");const i=this.history.find(r=>r.dirty&&!r.open&&!r.submitting);i&&(Y.Logger.log(`[ProjectState.closePersistChangeSetsSequentially] closing pending change-set ${i.id} - ${i.actionName}`),await this.persistChangeSetSequentially(i))}async onPersistChangeSetSequentially(i){this.onPersistChangeSetSequentiallyCallback=i,Y.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,Y.Logger.log("[ProjectState.onPersistChangeSetInParallel] onPersistChangeSetInParallelCallback has been set. Checking for pending change-sets.");for(const r of this.history)this.persistChangeSetInParallel(r),await new Promise(a=>setTimeout(a,27))}offPersistChangeSetInParallel(){this.onPersistChangeSetInParallelCallback=null}onAddChangeSet(i){this.onAddChangeSetCallback=i}offAddChangeSet(){this.onAddChangeSetCallback=null}onDiscardChangeSet(i){this.onDiscardChangeSetCallback=i}offDiscardChangeSet(){this.onDiscardChangeSetCallback=null}async persistChangeSetSequentially(i){if(Y.Logger.log(`[ProjectState.persistChangeSetSequentially] called for change-set ${i.id} - ${i.actionName}`),!i.dirty||i.open||i.submitting){Y.Logger.log(`[ProjectState.persistChangeSetSequentially] change-set ${i.id} - ${i.actionName} is not dirty, or is open, or is already being submitted, skipping.`);return}const r=this.history.findIndex(e=>e.id===i.id),a=this.history.slice(0,r),c=a[a.length-1];if(c!=null&&c.dirty){Y.Logger.log(`[ProjectState.persistChangeSetSequentially] lastBeforeSelf is dirty: ${c.id} - ${c.actionName}, closing it first.`);return}this.onPersistChangeSetSequentiallyCallback&&(Y.Logger.log(`[ProjectState.persistChangeSetSequentially] invoking onPersistChangeSetSequentiallyCallback for change-set ${i.id} - ${i.actionName}`),this.emit("before-change-set-persist",i),i.submitting=!0,(await this.onPersistChangeSetSequentiallyCallback(i)).success&&(i.dirty=!1,this.emit("change-set-persisted",i),Y.Logger.log(`[ProjectState.persistChangeSetSequentially] change-set ${i.id} - ${i.actionName} closed successfully, checking for pending change-sets to close.`),this.closePersistChangeSetsSequentially()))}async persistChangeSetInParallel(i){if(Y.Logger.log(`[ProjectState.persistChangeSetInParallel] called for change-set ${i.id} - ${i.actionName}`),!i.dirty||i.open||i.submitting){Y.Logger.log(`[ProjectState.persistChangeSetInParallel] change-set ${i.id} - ${i.actionName} is not dirty, or is open, or is already being submitted, skipping.`);return}this.onPersistChangeSetInParallelCallback&&(Y.Logger.log(`[ProjectState.persistChangeSetInParallel] invoking onPersistChangeSetInParallelCallback for change-set ${i.id} - ${i.actionName}`),this.emit("before-change-set-persist",i),i.submitting=!0,(await this.onPersistChangeSetInParallelCallback(i)).success&&(i.dirty=!1,this.emit("change-set-persisted",i)))}toLatestChangeSet(i,r,a,c=!1,e="here-this"){if(!this.history.length)return new S(this,i,r,a,c,e);const f=this.history[this.history.length-1];return f.open?f:this.addChangeSet(new S(this,i,r,a,c,e))}addChangeSet(i){var a,c;if(!this.history.length)return this.undoableStackValueIndex=B_(this.undoableStackValueIndex,this.history,i),(a=this.onAddChangeSetCallback)==null||a.call(this,i,this.undoableStackValueIndex),i;const r=this.history.find(e=>e.id===(i==null?void 0:i.id));if(r)return r;if(this.rejectParallelCS){const e=this.history.find(f=>f.open);if(e)throw Y.Logger.warn("Previous still open: ",e),Y.Logger.warn("New change set: ",i),new Error(`There is already an open change-set with id '${e.id}'${e.actionName?` auto-close: ${e.actionName}`:""}${e.self?` root: ${e.self.type} ${ce(e.self,this)}`:""}.`)}return this.undoableStackValueIndex=B_(this.undoableStackValueIndex,this.history,i),(c=this.onAddChangeSetCallback)==null||c.call(this,i,this.undoableStackValueIndex),i}discardChangeSet(i){var a;Y.Logger.log(`[ProjectState.discardChangeSet] called for change-set ${i.id} - ${i.actionName}`);const r=this.history.findIndex(c=>c.id===(i==null?void 0:i.id));return r!==-1&&(this.history.splice(r,1),Y.Logger.log(`[ProjectState.discardChangeSet] Removed change-set ${i.id} - ${i.actionName} from history.`),this.undoableStackValueIndex=this.undoableStackValueIndex-1,(a=this.onDiscardChangeSetCallback)==null||a.call(this,i),i==null||i.teardown()),this}validateGeneratedUpdate(i){return{errors:[],explanations:[],modifiedData:i}}subscribeDependents(i){return i.forEach(r=>{this.detachedDependents[r.entity.id]||(this.detachedDependents[r.entity.id]=r)}),this}unsubscribeDependents(i){return i.forEach(r=>{this.detachedDependents[r.entity.id]&&delete this.detachedDependents[r.entity.id]}),this}syncDependents(i=this.project.addChangeSet(new S(this.project,Gt.sessionAuthor,B().toISOString(),this,!0,"sync-dependents"))){const r=[],a=[],c=[],e=[];return Object.values(this.detachedDependents).forEach(f=>{const h=f.entity.afterAllChildrenInitialized(i);r.push(...h.updated),a.push(...h.added),c.push(...h.removed),e.push(...h.affected)}),i==null||i.attemptAutoclose("sync-dependents",this.id),{updated:C(r),added:C(a),removed:C(c),affected:C(e),self:this}}onDetachedDependencyRemoved(i,r,a){const c=[],e=[],f=[],h=[];return{updated:C(c),added:C(e),removed:C(f),affected:C(h),self:this}}onDetachedDependencyRestored(i,r,a){const c=[],e=[],f=[],h=[];return{updated:C(c),added:C(e),removed:C(f),affected:C(h),self:this}}unsubscribeFromDependencies(){return this}subscribeToDependencies(){return this}increaseVersion(i){var r;if(i&&!B(i).isValid())throw new Error(`The shared timestamp '${i}' is not a valid ISO 8601 date string.`);if(i&&B(i).isSame(B(this.createdAt)))return this;if(!((r=this.knownVersions)!=null&&r.has(this.version))&&this.initialized)throw new Error(`The current ${this.type} ${this.id} version '${this.version}' is not captured in the 'knownVersions' map. Capture the current version before increasing it to avoid losing data.`);if(!this.activeVersion)throw new Error(`Only active versions can be increased. Entity with id '${this.id}' and version '${this.version}' is not active.`);return this.previousVersion=this.version,this.version=Gt.UUID.uuid(),this.createdAt=B(i).toISOString()||B().toISOString(),this}captureVersion(){var r;const i=((r=this.knownVersions)==null?void 0:r.get(this.version))||new Gt(this);if(!this.activeVersion)throw new Error(`Only active versions can be captured. Entity of type ${this.type} with id '${this.id}' and version '${this.version}' is not active.`);if(this.version!==i.version)throw new Error(`Captured ${this.type} with id '${this.id}', version '${i.version}' does not match current entity version '${this.version}'.`);return this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,i):new Map().set(this.version,i),this.apply(i),this}snapshot(){const i=new Gt(this);return this.apply(i)}apply(i){const r=this.toMeta();return i.metaSync(r,null),i.entities=[...this.entities],i.projects=[...this.projects],i.functions=[...this.functions],i.events=[...this.events],i.variableDeclarations=[...this.variableDeclarations],i.variableInstances=[...this.variableInstances],i.conditions=[...this.conditions],i.operations=[...this.operations],i.functionCalls=[...this.functionCalls],i.loops=[...this.loops],i.searches=[...this.searches],i}recursiveCaptureUpstreamVersions(i){const r=[],a=[],c=[],e=[];return{updated:C(r),added:C(a),removed:C(c),affected:C(e),self:this}}async restoreVersion(i,r){var m;const a=[],c=[],e=[],f=[];if(this.version===i&&(r!=null&&r.skipIfSameVersion))return{updated:C(a),added:C(c),removed:C(e),affected:C(f),self:this};if(!this.knownVersions){const E=new Map;for(const[b,A]of this.knownVersions||new Map){if(E.set(b,A),A.activeVersion=!1,A.knownVersions)for(const[_,P]of A.knownVersions)E.set(_,P);A.knownVersions=null}}let h=(m=this.knownVersions)==null?void 0:m.get(i);if(!h){const E=await this.APILoadVersion({},i);if(!E)throw new Error(`Version with id '${i}' for entity with id '${this.id}' not found.`);h=new Gt(E)}return this.metaSync(h.toShallowJSON(),null),this.previousVersion=h.previousVersion,this.version=h.version,this.createdAt=h.createdAt,this.author=h.author,this.deleted=h.deleted,this.entities=[...h.entities],this.projects=[...h.projects],this.functions=[...h.functions],this.events=[...h.events],this.variableDeclarations=[...h.variableDeclarations],this.variableInstances=[...h.variableInstances],this.conditions=[...h.conditions],this.operations=[...h.operations],this.functionCalls=[...h.functionCalls],this.loops=[...h.loops],this.searches=[...h.searches],{updated:C(a),added:C(c),removed:C(e),affected:C(f),self:this}}updateWithShallowTransfer(i,r=this.project.addChangeSet(new S(this.project,Gt.sessionAuthor,B().toISOString(),this,!0,w.UpdateWithShallowTransfer))){return this.checkCanEdit(this,r)?(this.metaSync(i,r),this.version=i.version,this.createdAt=i.createdAt,this.author=i.author,this.deleted=i.deleted,this.previousVersion=i.previousVersion,this.captureVersion(),this.subscribeToDependencies(),r==null||r.attemptAutoclose(w.UpdateWithShallowTransfer,this.id),this):(Y.Logger.warn(`[updateWithShallowTransfer] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),r==null||r.attemptAutoclose(w.UpdateWithShallowTransfer,this.id),this)}updateWithGenerationTarget(i,r=this.project.addChangeSet(new S(this.project,Gt.sessionAuthor,B().toISOString(),this,!0,w.UpdateWithGenerationTarget))){return this.checkCanEdit(this,r)?(this.metaSync(i,r),this.captureVersion(),this.subscribeToDependencies(),r==null||r.attemptAutoclose(w.UpdateWithGenerationTarget,this.id),this):(Y.Logger.warn(`[updateWithGenerationTarget] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),r==null||r.attemptAutoclose(w.UpdateWithGenerationTarget,this.id),this)}hydrateAncestors(){const i=[],r=[],a=[],c=[];return{updated:C(i),added:C(r),removed:C(a),affected:C(c),self:this}}afterAllChildrenInitialized(i=null){const r=[],a=[],c=[],e=[];return this.initialized||(this.initialized=!0,this.emit("project-initialized",this,i)),this.validate(),{updated:C(r),added:C(a),removed:C(c),affected:C(e),self:this}}addSelfToProject(i){const r=[],a=[],c=[],e=[];return this.subscribe(),this.subscribeToDependencies(),{updated:C(r),added:C(a),removed:C(c),affected:C(e),self:this}}get instancesList(){return Object.values(this.instances)}get builtInInstancesList(){return Object.values(this.builtInInstances)}isOperationDeclaration(i){return this.operationDeclarations.includes(i)}isGlobalEventActionDescriptor(i){return this.globalEventActionDescriptors.includes(i)}isLoopDeclaration(i){return this.loopDeclarations.includes(i)}isConditionDeclaration(i){return this.conditionDeclarations.includes(i)}initChildren(i=this.project.addChangeSet(new S(this.project,Gt.sessionAuthor,B().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.entities=this.initialData.entities.map(r=>{const a=Re(r,this);return a.setParent(this,null),a.initChildren(i),a}),this.projects=this.initialData.projects.map(r=>{const a=Re(r,this);return a.setParent(this,null),a.initChildren(i),a}),this.variableDeclarations=this.initialData.variableDeclarations.map(r=>{const a=Re(r,this);return a.setParent(this,null),a.initChildren(i),a}),this.variableInstances=this.initialData.variableInstances.map(r=>{const a=Re(r,this);return a.setParent(this,null),a.initChildren(i),a}),this.conditions=this.initialData.conditions.map(r=>{const a=Re(r,this);return a.setParent(this,null),a.initChildren(i),a}),this.operations=this.initialData.operations.map(r=>{const a=Re(r,this);return a.setParent(this,null),a.initChildren(i),a}),this.functions=this.initialData.functions.map(r=>{const a=Re(r,this);return a.setParent(this,null),a.initChildren(i),a}),this.events=this.initialData.events.map(r=>{const a=Re(r,this);return a.setParent(this,null),a.initChildren(i),a}),this.functionCalls=this.initialData.functionCalls.map(r=>{const a=Re(r,this);return a.setParent(this,null),a.initChildren(i),a}),this.loops=this.initialData.loops.map(r=>{const a=Re(r,this);return a.setParent(this,null),a.initChildren(i),a}),this.searches=this.initialData.searches.map(r=>{const a=Re(r,this);return a.setParent(this,null),a.initChildren(i),a}),this.attachOrphanReferences(),this.subscribeToDependencies(),this.afterAllChildrenInitialized(i),i==null||i.attemptAutoclose("init-children",this.id),this)}subscribeInstance(i){return(!this.instances[i.id]||this.instances[i.id]!==i)&&(this.instances[i.id]=i),this}subscribeDeletedInstance(i){return(!this.deletedInstances[i.id]||this.deletedInstances[i.id]!==i)&&(this.deletedInstances[i.id]=i),this}subscribeBuiltInInstance(i){return(!this.builtInInstances[i.id]||this.builtInInstances[i.id]!==i)&&(this.builtInInstances[i.id]=i),this}subscribe(){var i;return this.activeVersion=!0,(i=this.knownVersions)==null||i.forEach(r=>{r.version!==this.version&&(r.activeVersion=!1)}),this.subscribeInstance(this),this}unsubscribe(){return this}unsubscribeInstance(i){return delete this.instances[i.id],this}unsubscribeDeletedInstance(i){return delete this.deletedInstances[i.id],this}unsubscribeBuiltInInstance(i){return delete this.builtInInstances[i.id],this}findSubscribedBuiltInInstance(i){return this.builtInInstances[i.id]||null}get(i){return this.instances[i]||this.builtInInstances[i]||null}getDeleted(i){return this.deletedInstances[i]||null}getManaged(i){return this.getBuiltIn(i)?null:this.instances[i]||null}getBuiltIn(i){return this.builtInInstances[i]||null}findSubscribedInstanceFromReference(i){return this.instances[i.entityId]||null}findSubscribedBuiltInInstanceFromReference(i){return this.builtInInstances[i.entityId]||null}metaSync(i,r=this.project.addChangeSet(new S(this.project,Gt.sessionAuthor,B().toISOString(),this,!0,"meta-sync"))){const a=tn(this,i,r),c=en(this,a),e=this.toMeta();return this.name=a.name!==void 0?a.name:e.name,this.description=a.description!==void 0?a.description:e.description,this.x=a.x||e.x,this.y=a.y||e.y,super.baseMetaSync(a,this,r),a.deleted===!0&&!e.deleted?r==null||r.add(this,W.Removed):a.deleted===!1&&e.deleted?r==null||r.add(this,W.Added):c&&(r==null||r.add(this,W.Updated)),r==null||r.attemptAutoclose("meta-sync",this.id),this}async APILoad(i=Ke,...r){return await Gt.repository.APILoad(this.id,...r),this}async APICreate(i=Ke,...r){return await Gt.repository.APICreate(this.toShallowJSON(),...r),this}async APIUpdate(i=Ke,...r){return await Gt.repository.APIUpdate(this.toShallowJSON(),...r),this}async APIDelete(i=Ke,...r){return await Gt.repository.APIDelete(this.toShallowJSON(),...r),this}async APIClone(i=Ke,...r){return await Gt.repository.APIClone(this.id,...r),this}async APILoadVersion(i=Ke,r,...a){return await Gt.repository.APILoadVersion(this.id,r,...a)}remove({ignoreUpstream:i}={ignoreUpstream:!1},r=this.project.addChangeSet(new S(this.project,Gt.sessionAuthor,B().toISOString(),this,!0,w.RemoveEntity))){return{added:[],updated:[],removed:[],affected:[],self:this}}restore({}={},i=this.project.addChangeSet(new S(this.project,Gt.sessionAuthor,B().toISOString(),this,!0,w.RestoreEntity))){return{added:[],updated:[],removed:[],affected:[],self:this}}getAllBuiltInIds(){const i=new Set;return[...this.primitives.flatMap(r=>r.toFlatIds(i)),...this.builtInBaseEntities.flatMap(r=>r.toFlatIds(i)),...this.operationDeclarations.flatMap(r=>r.toFlatIds(i)),...this.globalEventActionDescriptors.flatMap(r=>r.toFlatIds(i)),...this.loopDeclarations.flatMap(r=>r.toFlatIds(i)),...this.conditionDeclarations.flatMap(r=>r.toFlatIds(i)),...this.valueDescriptors.flatMap(r=>r.toFlatIds(i)),...this.dataTypes.flatMap(r=>r.toFlatIds(i))]}getAllBuiltIn(){const i=new Set;return[...this.primitives.flatMap(r=>r.toFlat(i)),...this.builtInBaseEntities.flatMap(r=>r.toFlat(i)),...this.operationDeclarations.flatMap(r=>r.toFlat(i)),...this.globalEventActionDescriptors.flatMap(r=>r.toFlat(i)),...this.loopDeclarations.flatMap(r=>r.toFlat(i)),...this.conditionDeclarations.flatMap(r=>r.toFlat(i)),...this.valueDescriptors.flatMap(r=>r.toFlat(i)),...this.dataTypes.flatMap(r=>r.toFlat(i))]}toFlat(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this,...this.entities.flatMap(a=>a.toFlat(i)),...this.functions.flatMap(a=>a.toFlat(i)),...this.events.flatMap(a=>a.toFlat(i)),...this.projects.flatMap(a=>a.toFlat(i)),...this.variableDeclarations.flatMap(a=>a.toFlat(i)),...this.variableInstances.flatMap(a=>a.toFlat(i)),...this.conditions.flatMap(a=>a.toFlat(i)),...this.operations.flatMap(a=>a.toFlat(i)),...this.functionCalls.flatMap(a=>a.toFlat(i)),...this.loops.flatMap(a=>a.toFlat(i)),...this.searches.flatMap(a=>a.toFlat(i))])}toFlatIds(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.id,...this.entities.flatMap(a=>a.toFlatIds(i)),...this.functions.flatMap(a=>a.toFlatIds(i)),...this.events.flatMap(a=>a.toFlatIds(i)),...this.projects.flatMap(a=>a.toFlatIds(i)),...this.variableDeclarations.flatMap(a=>a.toFlatIds(i)),...this.variableInstances.flatMap(a=>a.toFlatIds(i)),...this.conditions.flatMap(a=>a.toFlatIds(i)),...this.operations.flatMap(a=>a.toFlatIds(i)),...this.functionCalls.flatMap(a=>a.toFlatIds(i)),...this.loops.flatMap(a=>a.toFlatIds(i)),...this.searches.flatMap(a=>a.toFlatIds(i))])}toMeta(){return{id:this.id,version:this.version,workspaceId:this.workspaceId,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,description:this.description,type:this.type,editable:this.editable,deletable:this.deletable,name:this.name}}toJSON(i=new Set){return i.has(this.id)?this.toReference():(i.add(this.id),{id:this.id,version:this.version,workspaceId:this.workspaceId,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,editable:this.editable,deletable:this.deletable,name:this.name,description:this.description,entities:this.entities.map(r=>r.toJSON(i)),variableDeclarations:this.variableDeclarations.map(r=>r.toJSON(i)),variableInstances:this.variableInstances.map(r=>r.toJSON(i)),conditions:this.conditions.map(r=>r.toJSON(i)),operations:this.operations.map(r=>r.toJSON(i)),loops:this.loops.map(r=>r.toJSON(i)),searches:this.searches.map(r=>r.toJSON(i)),functions:this.functions.map(r=>r.toJSON(i)),events:this.events.map(r=>r.toJSON(i)),projects:this.projects.map(r=>r.toJSON(i)),functionCalls:this.functionCalls.map(r=>r.toJSON(i))})}toJSONClone(i={uuidStrategy:"uuid"}){const r=new Map,a=new Set,c=this.getAllBuiltInIds();return Object.keys(this.instances).forEach(e=>{if(c.includes(e)){r.set(e,e);return}r.set(e,Gt.UUID.uuid())}),a.add(this.id),{id:r.get(this.id),version:this.version,workspaceId:this.workspaceId,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,editable:this.editable,deletable:this.deletable,name:this.name,description:this.description,entities:this.entities.map(e=>e.toJSONClone({...i,seenEntityMaps:r,seenEntities:a,newId:null})),projects:this.projects.map(e=>e.toJSONClone({...i,seenEntityMaps:r,seenEntities:a,newId:null})),variableDeclarations:this.variableDeclarations.map(e=>e.toJSONClone({...i,seenEntityMaps:r,seenEntities:a,newId:null})),variableInstances:this.variableInstances.map(e=>e.toJSONClone({...i,seenEntityMaps:r,seenEntities:a,newId:null})),conditions:this.conditions.map(e=>e.toJSONClone({...i,seenEntityMaps:r,seenEntities:a,newId:null})),operations:this.operations.map(e=>e.toJSONClone({...i,seenEntityMaps:r,seenEntities:a,newId:null})),functions:this.functions.map(e=>e.toJSONClone({...i,seenEntityMaps:r,seenEntities:a,newId:null})),events:this.events.map(e=>e.toJSONClone({...i,seenEntityMaps:r,seenEntities:a,newId:null})),functionCalls:this.functionCalls.map(e=>e.toJSONClone({...i,seenEntityMaps:r,seenEntities:a,newId:null})),loops:this.loops.map(e=>e.toJSONClone({...i,seenEntityMaps:r,seenEntities:a,newId:null})),searches:this.searches.map(e=>e.toJSONClone({...i,seenEntityMaps:r,seenEntities:a,newId:null}))}}toReference(i=at){var a;let r=this.id;return(a=i.seenEntityMaps)!=null&&a.has(this.id)&&(r=i.seenEntityMaps.get(this.id)),{id:r+"--"+Gt.UUID.uuid()+"--ref",type:d.GenericReference,entityId:r,version:this.version,entityType:this.type}}toShallowJSON(i=at){var a;let r=this.id;return(a=i.seenEntityMaps)!=null&&a.has(this.id)&&(r=i.seenEntityMaps.get(this.id)),{id:r,version:this.version,workspaceId:this.workspaceId,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,editable:this.editable,deletable:this.deletable,name:this.name,description:this.description,entities:this.entities.map(c=>c.toReference(i)),functions:this.functions.map(c=>c.toReference(i)),events:this.events.map(c=>c.toReference(i)),projects:this.projects.map(c=>c.toReference(i)),variableDeclarations:this.variableDeclarations.map(c=>c.toReference(i)),variableInstances:this.variableInstances.map(c=>c.toReference(i)),conditions:this.conditions.map(c=>c.toReference(i)),operations:this.operations.map(c=>c.toReference(i)),functionCalls:this.functionCalls.map(c=>c.toReference(i)),loops:this.loops.map(c=>c.toReference(i)),searches:this.searches.map(c=>c.toReference(i))}}toFlatJSON(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.toShallowJSON(),...this.entities.flatMap(a=>a.toFlatJSON(i)),...this.functions.flatMap(a=>a.toFlatJSON(i)),...this.events.flatMap(a=>a.toFlatJSON(i)),...this.projects.flatMap(a=>a.toFlatJSON(i)),...this.variableDeclarations.flatMap(a=>a.toFlatJSON(i)),...this.variableInstances.flatMap(a=>a.toFlatJSON(i)),...this.conditions.flatMap(a=>a.toFlatJSON(i)),...this.operations.flatMap(a=>a.toFlatJSON(i)),...this.functionCalls.flatMap(a=>a.toFlatJSON(i)),...this.loops.flatMap(a=>a.toFlatJSON(i)),...this.searches.flatMap(a=>a.toFlatJSON(i))])}toGenerationTarget(i=at){var a;let r=this.id;return(a=i.seenEntityMaps)!=null&&a.has(this.id)&&(r=i.seenEntityMaps.get(this.id)),{id:r,workspaceId:this.workspaceId,type:this.type,name:this.name,description:this.description}}toFlatGenerationTarget(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[...this.entities.flatMap(a=>a.toFlatGenerationTarget(i)),...this.functions.flatMap(a=>a.toFlatGenerationTarget(i)),...this.events.flatMap(a=>a.toFlatGenerationTarget(i)),...this.projects.flatMap(a=>a.toFlatGenerationTarget(i)),...this.variableDeclarations.flatMap(a=>a.toFlatGenerationTarget(i)),...this.variableInstances.flatMap(a=>a.toFlatGenerationTarget(i)),...this.conditions.flatMap(a=>a.toFlatGenerationTarget(i)),...this.operations.flatMap(a=>a.toFlatGenerationTarget(i)),...this.functionCalls.flatMap(a=>a.toFlatGenerationTarget(i)),...this.loops.flatMap(a=>a.toFlatGenerationTarget(i)),...this.searches.flatMap(a=>a.toFlatGenerationTarget(i))])}clearErrors(){return this.errors=[],this.entities.forEach(i=>i.clearErrors()),this.projects.forEach(i=>i.clearErrors()),this.functions.forEach(i=>i.clearErrors()),this.events.forEach(i=>i.clearErrors()),this.variableDeclarations.forEach(i=>i.clearErrors()),this.variableInstances.forEach(i=>i.clearErrors()),this.conditions.forEach(i=>i.clearErrors()),this.operations.forEach(i=>i.clearErrors()),this.functionCalls.forEach(i=>i.clearErrors()),this.loops.forEach(i=>i.clearErrors()),this.searches.forEach(i=>i.clearErrors()),this}validate(){return this.validateChildren(),AE([...this.errors]),{success:!0}}async validateAsync(i={}){const r=Y.YieldTracker.from(i);return await this.validateChildrenAsync({tracker:r}),await D_e([...this.errors]),{success:!0}}validateChildren(){this.entities.forEach(i=>i.validate()),this.projects.forEach(i=>i.validate()),this.functions.forEach(i=>i.validate()),this.events.forEach(i=>i.validate()),this.variableDeclarations.forEach(i=>i.validate()),this.variableInstances.forEach(i=>i.validate()),this.conditions.forEach(i=>i.validate()),this.operations.forEach(i=>i.validate()),this.functionCalls.forEach(i=>i.validate()),this.loops.forEach(i=>i.validate()),this.searches.forEach(i=>i.validate())}async validateChildrenAsync(i={}){const r=Y.YieldTracker.from(i);for(let a=0;a<this.entities.length;a++)await this.entities[a].validateAsync({tracker:r});for(let a=0;a<this.projects.length;a++)await this.projects[a].validateAsync({tracker:r});for(let a=0;a<this.functions.length;a++)await this.functions[a].validateAsync({tracker:r});for(let a=0;a<this.events.length;a++)await this.events[a].validateAsync({tracker:r});for(let a=0;a<this.variableDeclarations.length;a++)await this.variableDeclarations[a].validateAsync({tracker:r});for(let a=0;a<this.variableInstances.length;a++)await this.variableInstances[a].validateAsync({tracker:r});for(let a=0;a<this.conditions.length;a++)await this.conditions[a].validateAsync({tracker:r});for(let a=0;a<this.operations.length;a++)await this.operations[a].validateAsync({tracker:r});for(let a=0;a<this.functionCalls.length;a++)await this.functionCalls[a].validateAsync({tracker:r});for(let a=0;a<this.loops.length;a++)await this.loops[a].validateAsync({tracker:r});for(let a=0;a<this.searches.length;a++)await this.searches[a].validateAsync({tracker:r})}getErrors(){return[...this.errors,...this.entities.flatMap(r=>r.getErrors()),...this.projects.flatMap(r=>r.getErrors()),...this.functions.flatMap(r=>r.getErrors()),...this.events.flatMap(r=>r.getErrors()),...this.variableDeclarations.flatMap(r=>r.getErrors()),...this.variableInstances.flatMap(r=>r.getErrors()),...this.conditions.flatMap(r=>r.getErrors()),...this.operations.flatMap(r=>r.getErrors()),...this.functionCalls.flatMap(r=>r.getErrors()),...this.loops.flatMap(r=>r.getErrors()),...this.searches.flatMap(r=>r.getErrors())]}async getErrorsAsync(i={}){const r=Y.YieldTracker.from(i),a=[...this.errors];await r.tick();for(let c=0;c<this.entities.length;c++){const e=await this.entities[c].getErrorsAsync({tracker:r});a.push(...e)}for(let c=0;c<this.projects.length;c++){const e=await this.projects[c].getErrorsAsync({tracker:r});a.push(...e)}for(let c=0;c<this.functions.length;c++){const e=await this.functions[c].getErrorsAsync({tracker:r});a.push(...e)}for(let c=0;c<this.events.length;c++){const e=await this.events[c].getErrorsAsync({tracker:r});a.push(...e)}for(let c=0;c<this.variableDeclarations.length;c++){const e=await this.variableDeclarations[c].getErrorsAsync({tracker:r});a.push(...e)}for(let c=0;c<this.variableInstances.length;c++){const e=await this.variableInstances[c].getErrorsAsync({tracker:r});a.push(...e)}for(let c=0;c<this.conditions.length;c++){const e=await this.conditions[c].getErrorsAsync({tracker:r});a.push(...e)}for(let c=0;c<this.operations.length;c++){const e=await this.operations[c].getErrorsAsync({tracker:r});a.push(...e)}for(let c=0;c<this.functionCalls.length;c++){const e=await this.functionCalls[c].getErrorsAsync({tracker:r});a.push(...e)}for(let c=0;c<this.loops.length;c++){const e=await this.loops[c].getErrorsAsync({tracker:r});a.push(...e)}for(let c=0;c<this.searches.length;c++){const e=await this.searches[c].getErrorsAsync({tracker:r});a.push(...e)}return a}getShallowErrors(){return this.errors}clone(){return this}addDefinitionEntity(i){return this.entities.includes(i)||this.entities.push(i),i}addFunctionDeclaration(i){return this.functions.includes(i)||this.functions.push(i),i}addFunctionCall(i){return this.functionCalls.includes(i)||this.functionCalls.push(i),i}addVariableDeclaration(i){return this.variableDeclarations.includes(i)||this.variableDeclarations.push(i),i}addVariableInstance(i){return this.variableInstances.includes(i)||this.variableInstances.push(i),i}addInstalledProject(i){return this.projects.includes(i)||this.projects.push(i),this}addGlobalEvent(i){return this.events.includes(i)||this.events.push(i),this}addCondition(i){return this.conditions.includes(i)||this.conditions.push(i),this}addOperation(i){return this.operations.includes(i)||this.operations.push(i),this}addLoop(i){return this.loops.includes(i)||this.loops.push(i),this}addSearch(i){return this.searches.includes(i)||this.searches.push(i),this}removeDefinitionEntity(i){const r=this.entities.findIndex(a=>a.id===i.id);if(r>-1){const a=this.entities[r];return this.entities.splice(r,1),a}return null}removeCondition(i){const r=this.conditions.findIndex(a=>a.id===i.id);if(r>-1){const a=this.conditions[r];return this.conditions.splice(r,1),a}return null}removeOperation(i){const r=this.operations.findIndex(a=>a.id===i.id);if(r>-1){const a=this.operations[r];return this.operations.splice(r,1),a}return null}removeLoop(i){const r=this.loops.findIndex(a=>a.id===i.id);if(r>-1){const a=this.loops[r];return this.loops.splice(r,1),a}return null}removeSearch(i){const r=this.searches.findIndex(a=>a.id===i.id);if(r>-1){const a=this.searches[r];return this.searches.splice(r,1),a}return null}removeFunctionCall(i){const r=this.functionCalls.findIndex(a=>a.id===i.id);if(r>-1){const a=this.functionCalls[r];return this.functionCalls.splice(r,1),a}return null}removeVariableInstance(i){const r=this.variableInstances.findIndex(a=>a.id===i.id);if(r>-1){const a=this.variableInstances[r];return this.variableInstances.splice(r,1),a}return null}removeVariableDeclaration(i){const r=this.variableDeclarations.findIndex(a=>a.id===i.id);if(r>-1){const a=this.variableDeclarations[r];return this.variableDeclarations.splice(r,1),a}return null}removeFunctionDeclaration(i){const r=this.functions.findIndex(a=>a.id===i.id);if(r>-1){const a=this.functions[r];return this.functions.splice(r,1),a}return null}removeInstalledProject(i){const r=this.projects.findIndex(a=>a.id===i.id);if(r>-1){const a=this.projects[r];return this.projects.splice(r,1),a}return null}removeGlobalEvent(i){const r=this.events.findIndex(a=>a.id===i.id);if(r>-1){const a=this.events[r];return this.events.splice(r,1),a}return null}removeTopLevelVariableDeclaration(i){if(i.type!==d.VariableDeclaration)return null;const r=this.variableDeclarations.findIndex(a=>a.id===i.id);if(r>-1){const a=this.variableDeclarations[r];return this.variableDeclarations.splice(r,1),a}return null}getEntryPoints(){return[...this.functions,...this.events,...this.entities.flatMap(r=>r.methods)]}getTerminationStatements(){return[...this.getEntryPoints().reduce((r,a)=>{const c=ct(a);return[...r,...c.filter(e=>e.type===d.ReturnStatement||e.type===d.ContinueStatement||e.type===d.BreakStatement)]},[])]}getFunctionDeclaration(i){return this.functions.find(r=>r.id===i)||null}getConditions(){return[...this.conditions,...this.getEntryPoints().reduce((r,a)=>{const c=ct(a);return[...r,...c.filter(e=>e.type===d.Condition)]},[]),...this.functionCalls.reduce((r,a)=>{const c=ct(a);return[...r,...c.filter(e=>e.type===d.Condition)]},[]),...this.operations.reduce((r,a)=>{const c=ct(a);return[...r,...c.filter(e=>e.type===d.Condition)]},[]),...this.loops.reduce((r,a)=>{const c=ct(a);return[...r,...c.filter(e=>e.type===d.Condition)]},[]),...this.searches.reduce((r,a)=>{const c=ct(a);return[...r,...c.filter(e=>e.type===d.Condition)]},[])]}getOperations(){return[...this.operations,...this.getEntryPoints().reduce((r,a)=>{const c=ct(a);return[...r,...c.filter(e=>e.type===d.Operation)]},[]),...this.functionCalls.reduce((r,a)=>{const c=ct(a);return[...r,...c.filter(e=>e.type===d.Operation)]},[]),...this.conditions.reduce((r,a)=>{const c=ct(a);return[...r,...c.filter(e=>e.type===d.Operation)]},[]),...this.loops.reduce((r,a)=>{const c=ct(a);return[...r,...c.filter(e=>e.type===d.Operation)]},[]),...this.searches.reduce((r,a)=>{const c=ct(a);return[...r,...c.filter(e=>e.type===d.Operation)]},[])]}getFunctionCalls(){return[...this.functionCalls,...this.getEntryPoints().reduce((r,a)=>{const c=ct(a);return[...r,...c.filter(e=>e.type===d.FunctionCall)]},[]),...this.conditions.reduce((r,a)=>{const c=ct(a);return[...r,...c.filter(e=>e.type===d.FunctionCall)]},[]),...this.operations.reduce((r,a)=>{const c=ct(a);return[...r,...c.filter(e=>e.type===d.FunctionCall)]},[]),...this.loops.reduce((r,a)=>{const c=ct(a);return[...r,...c.filter(e=>e.type===d.FunctionCall)]},[]),...this.searches.reduce((r,a)=>{const c=ct(a);return[...r,...c.filter(e=>e.type===d.FunctionCall)]},[])]}getDefinitionEntities(i=new Set){return Array.from(this.subscribedDefinitionEntities).filter(a=>!i.has(a)).map(a=>this.get(a))}getVariables(){return[...this.variableDeclarations,...this.getEntryPoints().reduce((r,a)=>{const c=cr(a);return[...r,...c]},[]),...this.functionCalls.reduce((r,a)=>{const c=cr(a);return[...r,...c]},[]),...this.conditions.reduce((r,a)=>{const c=cr(a);return[...r,...c]},[]),...this.operations.reduce((r,a)=>{const c=cr(a);return[...r,...c]},[]),...this.loops.reduce((r,a)=>{const c=cr(a);return[...r,...c]},[]),...this.searches.reduce((r,a)=>{const c=cr(a);return[...r,...c]},[])]}getVariableInstances(){return[...this.variableInstances,...this.entities.reduce((r,a)=>[...r,...a.methods.flatMap(c=>{const f=ct(c).filter(h=>h.type===d.VariableInstance);return[...r,...f]})],[]),...this.getEntryPoints().reduce((r,a)=>{const e=cr(a).filter(f=>f.type===d.VariableInstance);return[...r,...e]},[]),...this.functionCalls.reduce((r,a)=>{const e=cr(a).filter(f=>f.type===d.VariableInstance);return[...r,...e]},[]),...this.conditions.reduce((r,a)=>{const e=cr(a).filter(f=>f.type===d.VariableInstance);return[...r,...e]},[]),...this.operations.reduce((r,a)=>{const e=cr(a).filter(f=>f.type===d.VariableInstance);return[...r,...e]},[]),...this.loops.reduce((r,a)=>{const e=cr(a).filter(f=>f.type===d.VariableInstance);return[...r,...e]},[]),...this.searches.reduce((r,a)=>{const e=cr(a).filter(f=>f.type===d.VariableInstance);return[...r,...e]},[])]}getVariableDeclarations(){return C([...this.variableDeclarations,...this.entities.reduce((r,a)=>[...r,...a.methods.flatMap(c=>{const f=ct(c).filter(h=>h.type===d.VariableDeclaration);return[...r,...f]})],[]),...this.getEntryPoints().reduce((r,a)=>{const e=cr(a).filter(f=>f.type===d.VariableDeclaration);return[...r,...e]},[]),...this.functionCalls.reduce((r,a)=>{const e=cr(a).filter(f=>f.type===d.VariableDeclaration);return[...r,...e]},[]),...this.conditions.reduce((r,a)=>{const e=cr(a).filter(f=>f.type===d.VariableDeclaration);return[...r,...e]},[]),...this.operations.reduce((r,a)=>{const e=cr(a).filter(f=>f.type===d.VariableDeclaration);return[...r,...e]},[]),...this.loops.reduce((r,a)=>{const e=cr(a).filter(f=>f.type===d.VariableDeclaration);return[...r,...e]},[]),...this.searches.reduce((r,a)=>{const e=cr(a).filter(f=>f.type===d.VariableDeclaration);return[...r,...e]},[])])}getLoops(){return[...this.loops,...this.getEntryPoints().reduce((r,a)=>{const c=ct(a);return[...r,...c.filter(e=>e.type===d.Loop)]},[]),...this.functionCalls.reduce((r,a)=>{const c=ct(a);return[...r,...c.filter(e=>e.type===d.Loop)]},[]),...this.conditions.reduce((r,a)=>{const c=ct(a);return[...r,...c.filter(e=>e.type===d.Loop)]},[]),...this.operations.reduce((r,a)=>{const c=ct(a);return[...r,...c.filter(e=>e.type===d.Loop)]},[]),...this.searches.reduce((r,a)=>{const c=ct(a);return[...r,...c.filter(e=>e.type===d.Loop)]},[])]}getSearches(){return[...this.searches,...this.getEntryPoints().reduce((r,a)=>{const c=ct(a);return[...r,...c.filter(e=>e.type===d.Search)]},[]),...this.functionCalls.reduce((r,a)=>{const c=ct(a);return[...r,...c.filter(e=>e.type===d.Search)]},[]),...this.conditions.reduce((r,a)=>{const c=ct(a);return[...r,...c.filter(e=>e.type===d.Search)]},[]),...this.operations.reduce((r,a)=>{const c=ct(a);return[...r,...c.filter(e=>e.type===d.Search)]},[]),...this.loops.reduce((r,a)=>{const c=ct(a);return[...r,...c.filter(e=>e.type===d.Search)]},[])]}attachOrphanReferences(){const i=this.getVariableInstances(),r=this.getVariableDeclarations();return i.forEach(a=>{if(!a.declaration){const c=a.initialData,e=c.declaration.entityId||c.declaration.id,f=r.find(h=>h.id===e);f&&a.setDeclaration(f)}}),this}getBuiltInPersistedEntity(){return this.builtInBaseEntities.find(i=>i.name===ge.PERSISTED_ENTITY)||null}requestActiveDynamicValue(i,r=!1){var c,e;const a=(e=(c=this.parentContext).requestActiveDynamicValue)==null?void 0:e.call(c,i,r);if(!a&&pI.includes(i.type)){const f=i.getDefaultValue();return f?{value:f,type:Be.DefaultValue,inheritanceLink:null,valueOwner:i}:null}return a||null}requestExtension(i){if(this.parentContext.requestExtension){const r=this.parentContext.requestExtension(i);if(r&&!r.module)throw new Error(`Module ${i} is not registered properly.`);return r.module||null}return null}undo(){Y.Logger.log("Undoing, from: ",this.undoableStackValueIndex),this.undoableStackValueIndex=this.undoableStackValueIndex-1,Y.Logger.log("To: ",this.undoableStackValueIndex);const i=this.history[this.undoableStackValueIndex+1],r=this.history[this.undoableStackValueIndex];return Y.Logger.log("Current change set: ",i==null?void 0:i.toJSON()),Y.Logger.log("Change set to restore: ",r==null?void 0:r.toJSON()),$_(i||"initial",r||"initial",this)}redo(){Y.Logger.log("Undoing, from: ",this.undoableStackValueIndex),this.undoableStackValueIndex=this.undoableStackValueIndex+1,Y.Logger.log("To: ",this.undoableStackValueIndex);const i=this.history[this.undoableStackValueIndex-1],r=this.history[this.undoableStackValueIndex];return Y.Logger.log("Current change set: ",i==null?void 0:i.toJSON()),Y.Logger.log("Change set to restore: ",r.toJSON()),$_(i||"initial",r||"initial",this)}applyExternalChangeSet(i){const r=i.payload,a=this.addChangeSet(new S(this,i.userAuthor,i.emittedAt,this));a.ignoreNonEditable=!0,a.ignoreNonDeletable=!0;const c=r.updated[this.id];if(!c)throw new Error("Project root not found in change set transfer. Cannot apply changes.");const e={...r.added,...r.updated,...r.removed},f=[...Object.keys(r.added),...Object.keys(r.updated),...Object.keys(r.removed)];f.forEach(m=>{var E;if(!e[m]){Y.Logger.warn(`Entity '${m}' not found in change set transfer. Cannot apply changes.`);const b=(E=this.get(m))==null?void 0:E.toShallowJSON();throw b?Y.Logger.warn("Entity in project: ",b):Y.Logger.warn("Entity not in project"),new Error(`Entity '${m}' not found in change set transfer. Cannot apply changes.`)}});const h=new Fn(c,{allBuiltInEntityIds:this.diggestedBuiltInBaseEntitiesIds});return h.flatRecord=e,h.order=f,h.orderEntities(),Y.Logger.log("All entities: ",h.order.map((m,E)=>`${E+1}: ${e[m].type} - ${m}`).join(`,
|
|
606
|
-
`)),Y.Logger.log("Persisting new additions"),h.visit(async(m,E)=>{if(r.added[m.id]){Y.Logger.log("Adding: ",m.id);try{const b=Re(m,this);if(b.hydrateAncestors(),b.addSelfToProject(a),a.add(b,W.Added),a||b.captureVersion(),!this.get(m.id))throw new Error(`Entity ${m.id} was not added to the project`)}catch(b){Y.Logger.error("Error: ",b),Y.Logger.error("Errored entity: ",m)}}}),Y.Logger.log("Persisting updates"),h.visit(async(m,E)=>{if(r.updated[m.id]){Y.Logger.log("Updating: ",m.id);try{const b=this.get(m.id);b?(b.updateWithShallowTransfer(m,a),a.add(b,W.Updated),a||b.captureVersion()):Y.Logger.warn(`Active version of ${m.id} not found when applying external changes`)}catch(b){Y.Logger.error("Error: ",b),Y.Logger.error("Errored entity: ",m)}}}),Y.Logger.log("Persisting removals"),h.visit(async(m,E)=>{if(r.removed[m.id]){Y.Logger.log("Removing: ",m.id);try{const b=this.get(m.id);b&&(b.remove({ignoreUpstream:!1},a),a.add(b,W.Removed),a||b.captureVersion())}catch(b){Y.Logger.error("Error: ",b),Y.Logger.error("Errored entity: ",m)}}}),a.open=!1,a}toBuiltInShallowRecord(){const i={};return Object.values(this.builtInInstances).forEach(r=>{const a=r.toShallowJSON();i[r.id]=a}),i}toShallowRecord(){const i={};return Object.values(this.instances).forEach(r=>{const a=r.toShallowJSON();i[r.id]=a}),i}toFullProjectTransfer(i){const r={shallowErrors:!1,...i},a=new Fn(void 0,{allBuiltInEntityIds:this.diggestedBuiltInBaseEntitiesIds});a.flatRecord={};for(const f of Object.values(this.instances))this.diggestedBuiltInBaseEntitiesIds.has(f.id)||(a.flatRecord[f.id]=f);a.order=Object.keys(a.flatRecord),a.orderEntities();const c={},e=[];return a.visit(f=>{try{const h=f.toShallowJSON();c[f.id]=h,e.push(f.id)}catch(h){if(Y.Logger.error(`[toFullProjectTransfer] Error serializing ${f.type} ${f.id}`,h),!r.shallowErrors)throw h}}),{order:e,size:e.length,record:c}}async toFullProjectTransferAsync(i={}){const r={shallowErrors:!1,...i},a=Y.YieldTracker.from(r),c=new Fn(void 0,{allBuiltInEntityIds:this.diggestedBuiltInBaseEntitiesIds});c.flatRecord={};for(const h of Object.values(this.instances))await a.tick(),!this.diggestedBuiltInBaseEntitiesIds.has(h.id)&&(c.flatRecord[h.id]=h);c.order=Object.keys(c.flatRecord);const e=[];if(r.seenEntityMaps)for(const h of c.order){const m=r.seenEntityMaps.get(h)??h;this.diggestedBuiltInBaseEntitiesIds.has(m)}await c.orderEntitiesAsync({tracker:a});const f={};return await c.visitAsync(async h=>{try{if(this.diggestedBuiltInBaseEntitiesIds.has(h.id))return;const m=h.toShallowJSON({seenEntityMaps:r.seenEntityMaps});r.resetVersionOptions&&(m.version=Gt.UUID.uuid(),m.createdAt=r.resetVersionOptions.commonTimestamp||B().toISOString(),m.author=r.resetVersionOptions.author||Gt.sessionAuthor||"1",m.previousVersion=null),f[m.id]=m,e.push(m.id),r!=null&&r.onVisit&&await r.onVisit(m)}catch(m){if(Y.Logger.error(`[toFullProjectTransferAsync] Error serializing ${h.type} ${h.id}`,m),!r.shallowErrors)throw m}},{tracker:a}),{order:e,size:e.length,record:f}}async toFullProjectGenerationTargetAsync(i={}){const r={shallowErrors:!1,...i},a=Y.YieldTracker.from(r),c=new Fn(void 0,{allBuiltInEntityIds:this.diggestedBuiltInBaseEntitiesIds});c.flatRecord={};for(const h of Object.values(this.instances))await a.tick(),!this.diggestedBuiltInBaseEntitiesIds.has(h.id)&&(c.flatRecord[h.id]=h);c.order=Object.keys(c.flatRecord);const e=[];if(r.seenEntityMaps)for(const h of c.order){const m=r.seenEntityMaps.get(h)??h;this.diggestedBuiltInBaseEntitiesIds.has(m)}await c.orderEntitiesAsync({tracker:a});const f={};return await c.visitAsync(async h=>{try{if(this.diggestedBuiltInBaseEntitiesIds.has(h.id))return;const m=h.toGenerationTarget({seenEntityMaps:r.seenEntityMaps});f[m.id]=m,e.push(m.id),r!=null&&r.onVisit&&await r.onVisit(m)}catch(m){if(Y.Logger.error(`[toFullProjectTransferAsync] Error serializing ${h.type} ${h.id}`,m),!r.shallowErrors)throw m}},{tracker:a}),{order:e,size:e.length,record:f}}};R(Gt,"parentContext",DL),R(Gt,"sessionAuthor","1"),R(Gt,"repository",{APICreate:async(i,...r)=>i,APIUpdate:async(i,...r)=>i,APIDelete:async(i,...r)=>i,APIClone:async(i,...r)=>{},APILoad:async(i,...r)=>null,APILoadVersion:async(i,r,...a)=>null}),R(Gt,"type",d.Project),R(Gt,"USER_MANAGED_PARENT_TYPES",[]),R(Gt,"PARENT_TYPES",[...Gt.USER_MANAGED_PARENT_TYPES]),R(Gt,"MUTABLE_BASE_PROPERTIES",["name","description"]),R(Gt,"INMUTABLE_BASE_PROPERTIES",["id","type","workspaceId","version","createdAt","author","previousVersion"]),R(Gt,"BASE_PROPERTIES",[...Gt.MUTABLE_BASE_PROPERTIES,...Gt.INMUTABLE_BASE_PROPERTIES]),R(Gt,"MUTABLE_META_PROPERTIES",[...Gt.MUTABLE_BASE_PROPERTIES,"x","y"]),R(Gt,"INMUTABLE_META_PROPERTIES",[...Gt.INMUTABLE_BASE_PROPERTIES]),R(Gt,"META_PROPERTIES",[...Gt.MUTABLE_META_PROPERTIES,...Gt.INMUTABLE_META_PROPERTIES]),R(Gt,"MUTABLE_UPSTREAM_PROPERTIES",[]),R(Gt,"INMUTABLE_UPSTREAM_PROPERTIES",["primitives","builtInBaseEntities","operationDeclarations","globalEventActionDescriptors","loopDeclarations","builtInInstances"]),R(Gt,"UPSTREAM_PROPERTIES",[...Gt.MUTABLE_UPSTREAM_PROPERTIES,...Gt.INMUTABLE_UPSTREAM_PROPERTIES]),R(Gt,"MUTABLE_DOWNSTREAM_PROPERTIES",["entities","projects","functions","events","variableDeclarations","variableInstances","conditions","operations","functionCalls","loops","searches"]),R(Gt,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),R(Gt,"DOWNSTREAM_PROPERTIES",[...Gt.MUTABLE_DOWNSTREAM_PROPERTIES,...Gt.INMUTABLE_DOWNSTREAM_PROPERTIES]),R(Gt,"PROPERTIES",[...Gt.META_PROPERTIES,...Gt.UPSTREAM_PROPERTIES,...Gt.DOWNSTREAM_PROPERTIES]);let x=Gt;class ePi extends er{constructor(p){super(dE,p)}}class tPi extends er{constructor(i){super(sm,i);R(this,"autoexecutable",!0)}getEntityToMatchInputMap(i){return i.inputs.find(r=>{var a;return((a=r.declaration)==null?void 0:a.id)===re.operation[xe.Validate].inputs.entityToMatch.id})||null}getDataToValidateInputMap(i){return i.inputs.find(r=>{var a;return((a=r.declaration)==null?void 0:a.id)===re.operation[xe.Validate].inputs.dataToValidate.id})||null}getOutputDataOutputMap(i){return i.outputs.find(r=>{var a;return((a=r.declaration)==null?void 0:a.id)===re.operation[xe.Validate].dataType.entity.properties.outputEntity.id})||null}getEntityToMatch(i,r=this.project.addChangeSet(new S(this.project,x.sessionAuthor,B().toISOString(),this,!0,"get-entity-to-match-validate-data"))){var e;const a=((e=this.project.requestActiveDynamicValue(i))==null?void 0:e.value)||null,c=a==null?void 0:a.valueAsTypeSingle;return r==null||r.attemptAutoclose("get-entity-to-match-validate-data",this.id),c}syncOperationInstance(i,r=this.project.addChangeSet(new S(this.project,x.sessionAuthor,B().toISOString(),this,!0,"sync-operation-instance-validate-data"))){const a=[],c=[],e=[],f=[],h=this.getEntityToMatchInputMap(i);if(h){const{added:b,updated:A,removed:_,affected:P}=this.syncEntityToMatchInputMapDataType(h,r);a.push(...A),c.push(...b),e.push(..._),f.push(...P)}const m=this.getDataToValidateInputMap(i);if(m){const{added:b,updated:A,removed:_,affected:P}=this.syncDataToValidateInputMapDataType(m,r);a.push(...A),c.push(...b),e.push(..._),f.push(...P)}const E=this.getOutputDataOutputMap(i);if(E){const{added:b,updated:A,removed:_,affected:P}=this.syncOutputDataOutputMapDataType(E,r);a.push(...A),c.push(...b),e.push(..._),f.push(...P)}return r==null||r.attemptAutoclose("sync-operation-instance-validate-data",this.id),{updated:C(a),added:C(c),removed:C(e),affected:C(f),self:i}}syncEntityToMatchInputMapDataType(i,r=this.project.addChangeSet(new S(this.project,x.sessionAuthor,B().toISOString(),this,!0,"sync-entity-to-match-input-map-data-type"))){var E,b,A,_,P,V,M,G,k,q,ne,J,se,te,le,ue,z,Q;const a=[],c=[],e=[],f=[];if(((E=i.declaration)==null?void 0:E.id)!==re.operation[xe.Validate].inputs.entityToMatch.id)return r==null||r.attemptAutoclose("sync-entity-to-match-input-map-data-type",this.id),{updated:[],added:[],removed:[],affected:[],self:null};const h=((b=this.project.requestActiveDynamicValue(i))==null?void 0:b.value)||null,m=h==null?void 0:h.valueAsTypeSingle;if(!i.dataType){const de={id:x.UUID.uuid(),version:x.UUID.uuid(),createdAt:(r==null?void 0:r.timestamp)||new Date().toISOString(),author:(r==null?void 0:r.author)||x.sessionAuthor,previousVersion:null,deleted:!1,deletable:!0,editable:!0,type:d.DataType,parentRelationType:null,options:((A=i.declaration.dataType)==null?void 0:A.options)||null,implementationChooseOne:((_=i.declaration.dataType)==null?void 0:_.implementationChooseOne)||!1,staticEntities:((P=i.declaration.dataType)==null?void 0:P.staticEntities)??null,interactiveEntities:((V=i.declaration.dataType)==null?void 0:V.interactiveEntities)??null,actionEntities:((M=i.declaration.dataType)==null?void 0:M.actionEntities)??null,index:((G=i.declaration.dataType)==null?void 0:G.index)??null,isList:((k=i.declaration.dataType)==null?void 0:k.isList)||!1,foreignKeyAllowed:((q=i.declaration.dataType)==null?void 0:q.foreignKeyAllowed)??null,andChildrenGroup:null,orChildrenGroup:null,foreignKeyRef:null,asType:!0,entity:(m==null?void 0:m.toJSON())||null,like:!0,inferred:!0,parent:i.toReference()},pe=Re(de,i.project);pe.hydrateAncestors(),pe.addSelfToProject(r),r==null||r.add(pe,W.Added),pe.setParent(i,r),pe.initChildren(r),pe.setEntity(m,r),a.push(pe),i.setDataType(pe,r),r||pe.captureVersion()}return(z=i.dataType)==null||z.metaSync({inferred:!0,like:!1,asType:!0,options:((ne=i.declaration.dataType)==null?void 0:ne.options)||null,implementationChooseOne:((J=i.declaration.dataType)==null?void 0:J.implementationChooseOne)||!1,staticEntities:((se=i.declaration.dataType)==null?void 0:se.staticEntities)??null,interactiveEntities:((te=i.declaration.dataType)==null?void 0:te.interactiveEntities)??null,actionEntities:((le=i.declaration.dataType)==null?void 0:le.actionEntities)??null,isList:((ue=i.declaration.dataType)==null?void 0:ue.isList)||!1},r),(Q=i.dataType)==null||Q.setEntity(m,r),i.dataType&&c.push(i.dataType),r==null||r.attemptAutoclose("sync-entity-to-match-input-map-data-type",this.id),{updated:C(c),added:C(a),removed:C(e),affected:C(f),self:i.dataType}}syncDataToValidateInputMapDataType(i,r=this.project.addChangeSet(new S(this.project,x.sessionAuthor,B().toISOString(),this,!0,"sync-data-to-validate-input-map-data-type"))){var b,A,_;const a=[],c=[],e=[],f=[];if(((b=i.declaration)==null?void 0:b.id)!==re.operation[xe.Validate].inputs.dataToValidate.id)return r==null||r.attemptAutoclose("sync-data-to-validate-input-map-data-type",this.id),{updated:[],added:[],removed:[],affected:[],self:null};const h=this.getEntityToMatchInputMap(i.parent);if(!h)return r==null||r.attemptAutoclose("sync-data-to-validate-input-map-data-type",this.id),{updated:[],added:[],removed:[],affected:[],self:null};if(!this.getEntityToMatch(h,r))return r==null||r.attemptAutoclose("sync-data-to-validate-input-map-data-type",this.id),{updated:[],added:[],removed:[],affected:[],self:null};if(!i.dataType){const P={id:x.UUID.uuid(),version:x.UUID.uuid(),createdAt:(r==null?void 0:r.timestamp)||new Date().toISOString(),author:(r==null?void 0:r.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()},V=Re(P,i.project);V.hydrateAncestors(),V.addSelfToProject(r),r==null||r.add(V,W.Added),V.setParent(i,r),V.initChildren(r),a.push(V),i.setDataType(V,r),r||V.captureVersion()}(A=i.dataType)==null||A.metaSync({inferred:!0,like:!0,asType:!1},r);const E=this.getEntityToMatch(h,r);return(_=i.dataType)==null||_.setEntity(E,r),i.dataType&&c.push(i.dataType),r==null||r.attemptAutoclose("sync-data-to-validate-input-map-data-type",this.id),{updated:C(c),added:C(a),removed:C(e),affected:C(f),self:i.dataType}}syncOutputDataOutputMapDataType(i,r=this.project.addChangeSet(new S(this.project,x.sessionAuthor,B().toISOString(),this,!0,"sync-output-data-output-map-data-type"))){var A,_,P,V;const a=[],c=[],e=[],f=[];if(((A=i.declaration)==null?void 0:A.id)!==re.operation[xe.Validate].dataType.entity.properties.outputEntity.id)return r==null||r.attemptAutoclose("sync-output-data-output-map-data-type",this.id),{updated:[],added:[],removed:[],affected:[],self:null};const h=this.getEntityToMatchInputMap(i.parent);if(!h)return r==null||r.attemptAutoclose("sync-output-data-output-map-data-type",this.id),{updated:[],added:[],removed:[],affected:[],self:null};if(!this.getEntityToMatch(h,r))return r==null||r.attemptAutoclose("sync-output-data-output-map-data-type",this.id),{updated:[],added:[],removed:[],affected:[],self:null};const E=((_=this.project.requestActiveDynamicValue(h))==null?void 0:_.value)||null,b=(E==null?void 0:E.valueAsTypeSingle)||null;if(!i.dataType){const M={id:x.UUID.uuid(),version:x.UUID.uuid(),createdAt:(r==null?void 0:r.timestamp)||new Date().toISOString(),author:(r==null?void 0:r.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()},G=Re(M,i.project);G.hydrateAncestors(),G.addSelfToProject(r),r==null||r.add(G,W.Added),G.setParent(i,r),G.initChildren(r),G.setEntity(b,r),a.push(G),i.setDataType(G,r),r||G.captureVersion()}return(P=i.dataType)==null||P.metaSync({inferred:!0,like:!0,asType:!1},r),(V=i.dataType)==null||V.setEntity(b,r),i.dataType&&c.push(i.dataType),r==null||r.attemptAutoclose("sync-output-data-output-map-data-type",this.id),{updated:C(c),added:C(a),removed:C(e),affected:C(f),self:i.dataType}}inferInputMapDataType(i,r=this.project.addChangeSet(new S(this.project,x.sessionAuthor,B().toISOString(),this,!0,"infer-input-map-data-type-validate-data"))){var c,e,f;if(((c=i.declaration)==null?void 0:c.id)===re.operation[xe.Validate].inputs.entityToMatch.id){const{added:h,updated:m,removed:E,affected:b}=r?this.syncEntityToMatchInputMapDataType(i,r):{added:[],updated:[],removed:[],affected:[]};return r==null||r.attemptAutoclose("infer-input-map-data-type",this.id),{updated:C(m),added:C(h),removed:C(E),affected:C(b),self:i.dataType}}if(((e=i.declaration)==null?void 0:e.id)===re.operation[xe.Validate].inputs.dataToValidate.id){const{added:h,updated:m,removed:E,affected:b}=this.syncDataToValidateInputMapDataType(i,r);return r==null||r.attemptAutoclose("infer-input-map-data-type",this.id),{updated:C(m),added:C(h),removed:C(E),affected:C(b),self:i.dataType}}const a=(f=i.declaration)==null?void 0:f.getDataType(r);if(a&&a.isResolved)return r==null||r.attemptAutoclose("infer-input-map-data-type-validate-data",this.id),{updated:[],added:[],removed:[],affected:[],self:a};if(i.readsValue){const h=iu(i.readsValue,r);return r==null||r.attemptAutoclose("infer-input-map-data-type-validate-data",this.id),{updated:[],added:[],removed:[],affected:[],self:h}}return r==null||r.attemptAutoclose("infer-input-map-data-type-validate-data",this.id),{updated:[],added:[],removed:[],affected:[],self:null}}inferOutputMapDataType(i,r=this.project.addChangeSet(new S(this.project,x.sessionAuthor,B().toISOString(),this,!0,"infer-output-map-data-type-validate-data"))){var a;if(((a=i.declaration)==null?void 0:a.id)===re.operation[xe.Validate].dataType.entity.properties.outputEntity.id){const{added:c,updated:e,removed:f,affected:h}=this.syncOutputDataOutputMapDataType(i,r);return r==null||r.attemptAutoclose("infer-output-map-data-type-validate-data",this.id),{updated:C(e),added:C(c),removed:C(f),affected:C(h),self:i.dataType}}return{updated:[],added:[],removed:[],affected:[],self:null}}}class iPi extends er{constructor(p){super(bP,p)}}class rPi extends er{constructor(p){super(AP,p)}}class nPi extends er{constructor(p){super(gP,p)}}class aPi extends er{constructor(p){super(zI,p)}}class sPi extends er{constructor(p){super(yI,p)}}class lPi extends er{constructor(p){super(Rv,p)}}function lUe(s){const p=[new OVe(s),new ePi(s),new tPi(s),new aPi(s),new iPi(s),new nPi(s),new rPi(s),new sPi(s),new lPi(s)];return SN.forEach(i=>{p.some(r=>r.id===i.id)||p.push(new er(i,s))}),p.forEach(i=>{i.initChildren(null),s.subscribeBuiltInInstance(i)}),s.operationDeclarations=p,p}const oPi=[];function oUe(s){const p=[new AVe(s),new RVe(s),new wVe(s),new CVe(s)];return mx.forEach(i=>{!p.some(r=>r.id===i.id)&&!oPi.includes(i.id)&&p.push(new Td(i,s))}),p.forEach(i=>{s.subscribeBuiltInInstance(i)}),s.builtInBaseEntities=p,p}function dUe(s){const p=[];return NV.forEach(i=>{p.some(r=>r.id===i.id)||p.push(new Pf(i,s))}),p.forEach(i=>{s.subscribeBuiltInInstance(i)}),s.primitives=p,p}function uUe(s){const p=[new er(f1,s)];return p.forEach(i=>{i.initChildren(null),s.subscribeBuiltInInstance(i)}),s.globalEventActionDescriptors=p,p}function pUe(s){const p=[new er(bE,s),new er(ey,s),new er(vE,s),new er(Vm,s),new er(Pm,s),new er(HR,s)];p.forEach(r=>{r.initChildren(null),s.subscribeBuiltInInstance(r)}),s.loopDeclarations=p;const i=[new er(r1,s),new er(EE,s),new er(JR,s),new er(JN,s),new er(ex,s),new er(WR,s)];return i.forEach(r=>{r.initChildren(null),s.subscribeBuiltInInstance(r)}),s.loopDeclarationsBodies=i,p}function cUe(s){const p=[new Ed(Ix,s)];return p.forEach(i=>{i.initChildren(null),s.subscribeBuiltInInstance(i)}),s.valueDescriptors=p,p}function fUe(s){const p=[new er(vx,s),new er(Tx,s),new er(Ex,s),new er(bx,s)];return Ax.forEach(i=>{p.some(r=>r.id===i.id)||p.push(new er(i,s))}),p.forEach(i=>{i.initChildren(null),s.subscribeBuiltInInstance(i)}),s.conditionDeclarations=p,p}function UT(s){return s&&typeof s.then=="function"}function dPi(s,p){const i=new Fn(s[0],{allBuiltInEntityIds:p.allBuiltInEntityIds}),r=s.map(c=>c.id),a={};return s.forEach(c=>{a[c.id]=c}),i.order=r,i.flatRecord=a,i.orderEntities(),i.order.map(c=>i.flatRecord[c])}function uPi(s,p){const i=new Fn(Object.values(s)[0],{allBuiltInEntityIds:p.allBuiltInEntityIds}),r=Object.keys(s);return i.order=r,i.flatRecord=s,i.orderEntities(),i.order}async function pPi(s,p){const i=Y.YieldTracker.from(p),r=new Fn(s[0],{allBuiltInEntityIds:p.allBuiltInEntityIds}),a=s.map(e=>e.id),c={};for(const e of s)c[e.id]=e,await i.tick();return r.order=a,r.flatRecord=c,await r.orderEntitiesAsync({tracker:i}),r.order.map(e=>r.flatRecord[e])}async function cPi(s,p){const i=Y.YieldTracker.from(p),r=new Fn(Object.values(s)[0],{allBuiltInEntityIds:p.allBuiltInEntityIds}),a=Object.keys(s);return r.order=a,r.flatRecord=s,await r.orderEntitiesAsync({tracker:i}),r.order}class Fn{constructor(p,i={}){R(this,"order",[]);R(this,"flatRecord",{});R(this,"allBuiltInEntityIds");R(this,"onGoingVisits",{});R(this,"cachedReferences",{});if(i.allBuiltInEntityIds&&(this.allBuiltInEntityIds=i.allBuiltInEntityIds),!p)return;const r={asyncInitialOrder:!1,...i};r.asyncInitialOrder?this.flattenAsync(p).then(()=>{this.orderEntitiesAsync({...r}).then(()=>{var a;(a=r.onOrdered)==null||a.call(r)})}):(this.flatten(p),this.orderEntities())}flatten(p){this.allBuiltInEntityIds||(this.allBuiltInEntityIds=new Set(oD()));const i=C(Ue(p,new Set(this.allBuiltInEntityIds),{ignoreBuiltInBaseEntities:!0,diggestedBuiltInBaseEntitiesIds:this.allBuiltInEntityIds})),r=new Set;for(const a of i)this.flatRecord[a.id]=a,r.add(a.id);this.order=Array.from(r)}async flattenAsync(p,i={}){const r=Y.YieldTracker.from(i);this.allBuiltInEntityIds||(this.allBuiltInEntityIds=await dD({tracker:r}));const a=await Ip(await je(p,new Set(this.allBuiltInEntityIds),{ignoreBuiltInBaseEntities:!0,diggestedBuiltInBaseEntitiesIds:this.allBuiltInEntityIds,tracker:r}),{tracker:r}),c=new Set;for(const e of a)this.flatRecord[e.id]=e,c.add(e.id),await r.tick();this.order=Array.from(c)}moveEntityAfterDependencies(p){const i=this.cachedReferences[p.id]||oo(p,this.flatRecord,{ignoreBuiltInBaseEntities:!0,allBuiltInEntityIds:this.allBuiltInEntityIds});this.cachedReferences[p.id]=i;const{upstream:r}=i;for(const a of Object.keys(r)){const c=this.order.indexOf(a),e=this.order.indexOf(p.id);if(c>e)return this.order.splice(e,1),this.order.splice(c,0,p.id),!0}return!1}orderEntities(){let p=!1;for(let i=0;i<this.order.length;i++){const r=this.order[i],a=this.flatRecord[r];if(a||Y.Logger.warn(`Entity with id ${r} not found in flatRecord. Skipping...`),this.moveEntityAfterDependencies(a)){p=!0;break}}p&&this.orderEntities()}async orderEntitiesAsync(p={}){let i=!1;const r=Y.YieldTracker.from(p);for(let a=0;a<this.order.length;a++){const c=this.order[a],e=this.flatRecord[c];if(e||Y.Logger.warn(`Entity with id ${c} not found in flatRecord. Skipping...`),this.moveEntityAfterDependencies(e)){i=!0;break}await r.tick()}i&&await this.orderEntitiesAsync({tracker:r})}getUpstreamOngoingDependenciesVisits(p,i){const r=this.cachedReferences[p]||oo(this.flatRecord[p],this.flatRecord,{ignoreBuiltInBaseEntities:!0,allBuiltInEntityIds:this.allBuiltInEntityIds});this.cachedReferences[p]=r;const{upstream:a}=r,c={};return Object.entries(this.onGoingVisits[i]||{}).forEach(([e,f])=>{Object.keys(a).includes(e)&&(c[e]=f)}),c}getDownstreamOngoingDependenciesVisits(p,i){const r=Object.keys(this.onGoingVisits[i]||{}),a=new Set(r.flatMap(e=>{const f=this.cachedReferences[e]||oo(this.flatRecord[e],this.flatRecord,{ignoreBuiltInBaseEntities:!0,allBuiltInEntityIds:this.allBuiltInEntityIds});return this.cachedReferences[e]=f,Object.keys(f.downstream)})),c={};return Array.from(a).forEach(e=>{e===p&&(c[e]=this.onGoingVisits[i][e])}),c}async settlePromises(p,i){const r=Object.values(p);r.length&&await Promise.all(r),Object.keys(p).forEach(a=>{delete this.onGoingVisits[i][a]})}visit(p){const i=this.order;for(const r of i)p(this.flatRecord[r],this.flatRecord);return this}reverseVisit(p){const i=this.order.slice().reverse();for(const r of i)p(this.flatRecord[r],this.flatRecord);return this}async visitAsync(p,i={}){const{parallelise:r}={parallelise:!0,...i},a=Y.YieldTracker.from(i),c=this.order;if(!r){for(const f of c){const h=p(this.flatRecord[f],this.flatRecord);UT(h)&&await h,await a.tick()}return this}const e=Math.random().toString(36).substring(7);this.onGoingVisits[e]={};for(const f of c){const h=this.getUpstreamOngoingDependenciesVisits(f,e);Object.keys(h).length&&await this.settlePromises(h,e);const m=p(this.flatRecord[f],this.flatRecord);UT(m)&&(this.onGoingVisits[e][f]=m),await a.tick()}return await this.settlePromises(this.onGoingVisits[e],e),this.onGoingVisits[e]={},this}async reverseVisitAsync(p,i={}){const{parallelise:r}={parallelise:!0,...i},a=Y.YieldTracker.from(i),c=this.order.slice().reverse();if(!r){for(const f of c){const h=p(this.flatRecord[f],this.flatRecord);UT(h)&&await h,await a.tick()}return this}const e=Math.random().toString(36).substring(7);this.onGoingVisits[e]={};for(const f of c){const h=this.getDownstreamOngoingDependenciesVisits(f,e);Object.keys(h).length&&await this.settlePromises(h,e);const m=p(this.flatRecord[f],this.flatRecord);UT(m)&&(this.onGoingVisits[e][f]=m),await a.tick()}return await this.settlePromises(this.onGoingVisits[e],e),this.onGoingVisits[e]={},this}}const gf={},sg={},yv={empty:!1,enrich:!0,mock:!1,ignoreCache:!1,onFetch:async()=>null,manuallyInit:!1};function yUe(s,p={enrich:!0,shallowErrors:!1},i){const r={enrich:!0,shallowErrors:!1,...p},{enrich:a,shallowErrors:c}=r,e=s.project,f=s.record,h=iD(s.project,{shallowErrors:c},i);h.instances[e.id]=h;const m=new Fn(e,{allBuiltInEntityIds:h.diggestedBuiltInBaseEntitiesIds}),E=new Set;f[e.id]=e,E.add(e.id);const b=B().toISOString();Object.values(f).forEach(_=>{!_||m.allBuiltInEntityIds.has(_.id)||E.add(_.id)}),m.order=Array.from(E),m.flatRecord=f,m.orderEntities();const A=a?h.addChangeSet(new S(h,x.sessionAuthor,b,h,!0,"project-init-from-fetch-result")):null;return m.visit(_=>{if(_.id===h.id)return;const P=Re(_,h);try{P.hydrateAncestors(),P.addSelfToProject(null);const V=oo(_);Object.keys(V.downstream).forEach(M=>{const G=h.get(M);G&&G.hydrateAncestors()})}catch(V){if(c)Y.Logger.error("Error hydrating ancestors: ",V);else throw V}}),a?(m.visit(_=>{if(_.id===h.id)return;const P=h.get(_.id);if(P)try{P.afterAllChildrenInitialized(A),P.captureVersion()}catch(V){if(c)Y.Logger.error("Error in afterAllChildrenInitialized: ",V);else throw V}}),h.afterAllChildrenInitialized(A),h.subscribe(),h.captureVersion()):(Uu(h,b).forEach(P=>{P.remove({ignoreUpstream:!0},null)}),m.visit(P=>{if(P.id===h.id)return;const V=h.get(P.id);V&&(V.initialized=!0,V.captureVersion())}),h.initialized=!0,h.subscribe(),h.captureVersion()),h.initialized=!0,h.emit(pi.PROJECT_INITIALIZED,h,A),A==null||A.attemptAutoclose("project-init-from-fetch-result",h.id),h}async function fPi(s,p={enrich:!0,shallowErrors:!1,yieldEvery:100},i){const r={enrich:!0,shallowErrors:!1,yieldEvery:100,...p},{enrich:a,shallowErrors:c,yieldEvery:e}=r,f=Y.YieldTracker.from({yieldEvery:e}),h=s.project,m=s.record,E=await rD(s.project,{shallowErrors:c,tracker:f},i);E.instances[h.id]=E;const b=new Fn(void 0,{allBuiltInEntityIds:E.diggestedBuiltInBaseEntitiesIds});await b.flattenAsync(h,{tracker:f}),await b.orderEntitiesAsync({tracker:f});const A=new Set;m[h.id]=h,A.add(h.id);const _=B().toISOString();for(const[V,M]of Object.entries(m))!M||b.allBuiltInEntityIds.has(M.id)||(A.add(M.id),await f.tick());b.order=Array.from(A),b.flatRecord=m,await b.orderEntitiesAsync({tracker:f});const P=a?E.addChangeSet(new S(E,x.sessionAuthor,_,E,!0,"project-init-from-fetch-result")):null;if(await b.visitAsync(V=>{if(V.id===E.id)return;const M=Re(V,E);try{M.hydrateAncestors(),M.addSelfToProject(null);const G=oo(V);Object.keys(G.downstream).forEach(k=>{const q=E.get(k);q&&q.hydrateAncestors()})}catch(G){if(c)Y.Logger.error("Error hydrating ancestors: ",G);else throw Y.Logger.log("Error hydrating ancestors: ",G),G}},{tracker:f}),a){try{await b.visitAsync(V=>{if(V.id===E.id)return;const M=E.get(V.id);M&&(M.afterAllChildrenInitialized(P),M.captureVersion())},{tracker:f})}catch(V){if(c)Y.Logger.error("Error in afterAllChildrenInitialized: ",V);else throw Y.Logger.log("Error in afterAllChildrenInitialized: ",V),V}E.afterAllChildrenInitialized(P),E.subscribe(),E.captureVersion()}else Uu(E,_).forEach(M=>{M.remove({ignoreUpstream:!0},null)}),await b.visitAsync(M=>{if(M.id===E.id)return;const G=E.get(M.id);G&&(G.initialized=!0,G.captureVersion())},{tracker:f}),E.initialized=!0,E.subscribe(),E.captureVersion();return E.initialized=!0,E.emit(pi.PROJECT_INITIALIZED,E,P),P==null||P.attemptAutoclose("project-init-from-fetch-result",E.id),E}async function yPi(s,p=yv){const i={...yv,...p};if(i.empty)return{data:{project:{id:s.id,workspaceId:"",deletable:!0,editable:!0,type:d.Project,version:x.UUID.uuid(),createdAt:B().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 a={...gB};return a.id=s.id,{data:{project:a,record:{}}}}return Y.Logger.log("Fetching project from external API"),new Promise(async a=>{try{if(i.onFetch){const c=await i.onFetch(s.id);if(c){a({data:c});return}}else a({data:null})}catch(c){Y.Logger.error("Error fetching project: ",c),a({data:null})}})}function iD(s,p={shallowErrors:!1},i){const r=new x(s,i);dUe(r),oUe(r),lUe(r),uUe(r),pUe(r),cUe(r),fUe(r);const a=p.allBuiltInIds??new Set([...r.getAllBuiltInIds(),...oD()]);return r.diggestedBuiltInBaseEntitiesIds=a,a.forEach(c=>{if(!r.builtInInstances[c]&&r.instances[c])r.builtInInstances[c]=r.instances[c],delete r.instances[c];else if(!r.builtInInstances[c]&&!p.shallowErrors)throw new Error(`Built in entity was not properly initialized: ${c}`)}),r.instances[r.id]=r,r.activeVersion=!0,r}async function rD(s,p={shallowErrors:!1},i){const r=Y.YieldTracker.from(p),a=new x(s,i);dUe(a),oUe(a),await Y.yieldToEventLoop(),lUe(a),await Y.yieldToEventLoop(),uUe(a),pUe(a),cUe(a),fUe(a),await Y.yieldToEventLoop();const c=p.allBuiltInIds??new Set([...a.getAllBuiltInIds(),...await dD()]);a.diggestedBuiltInBaseEntitiesIds=c;for(const e of c){if(!a.builtInInstances[e]&&a.instances[e])a.builtInInstances[e]=a.instances[e],delete a.instances[e];else if(!a.builtInInstances[e]&&!p.shallowErrors)throw new Error(`Built in entity was not properly initialized: ${e}`);a.instances[e]&&delete a.instances[e],await r.tick()}return a.instances[a.id]=a,a.activeVersion=!0,a}function Uu(s,p){return s.instancesList.filter(r=>B(r.createdAt).isAfter(B(p)||!!r.previousVersion))}function hPi(s,{enrich:p,shallowErrors:i,...r}={enrich:!0,shallowErrors:!1},a){var _,P;const c=new Map,e=new Map;Object.keys(s.instances).forEach(V=>{if(s.diggestedBuiltInBaseEntitiesIds.has(V)){c.set(V,V),e.set(V,V);return}const M=s.get(V);if(!mD(M,{...s.instances,...s.builtInInstances}).every(ne=>!s.diggestedBuiltInBaseEntitiesIds.has(ne))){c.set(V,V),e.set(V,V);return}const q=x.UUID.uuid();c.set(V,q),e.set(q,V)});const f=((_=r.resetVersionOptions)==null?void 0:_.commonTimestamp)??B().toISOString(),h=s.toShallowJSON({seenEntityMaps:c});h.previousVersion=null,h.createdAt=f,h.version=x.UUID.uuid(),h.author=((P=r.resetVersionOptions)==null?void 0:P.author)??(x.sessionAuthor||"1");const m=iD(h,{shallowErrors:i,allBuiltInIds:s.diggestedBuiltInBaseEntitiesIds},a);m.instances[m.id]=m;const E=p?m.addChangeSet(new S(m,x.sessionAuthor,f,m,!0,"project-clone")):null,b=new Fn(s,{allBuiltInEntityIds:s.diggestedBuiltInBaseEntitiesIds}),A=_L(b.flatRecord,c);return b.visit(V=>{var q;const M=V.toShallowJSON({seenEntityMaps:c});M.previousVersion=null,M.createdAt=f,M.version=x.UUID.uuid(),M.author=((q=r.resetVersionOptions)==null?void 0:q.author)??(x.sessionAuthor||"1");const G=oo(M,A);if(Object.keys(G.upstream).length){let ne=!1;if(Object.keys(G.upstream).forEach(J=>{if(!ne&&(!m.get(J)||m.getDeleted(J))){ne=!0;return}}),ne)return}const k=Re(M,m);k.hydrateAncestors(),k.addSelfToProject(E),E==null||E.add(k,W.Added),r.onVisit&&r.onVisit(M)}),p?(b.visit(V=>{if(V.id===m.id)return;const M=m.get(c.get(V.id));M&&(M.afterAllChildrenInitialized(E),M.captureVersion())}),m.afterAllChildrenInitialized(E),m.subscribe(),m.captureVersion()):(Uu(m,f).forEach(M=>{M.remove({ignoreUpstream:!0},null)}),b.visit(M=>{if(M.id===m.id)return;const G=m.get(M.id);G&&(G.initialized=!0,G.captureVersion())}),m.initialized=!0,m.subscribe(),m.captureVersion()),m.instancesList.forEach(V=>{V.previousVersion=null}),E==null||E.attemptAutoclose("project-clone",m.id),{project:m,maps:c}}async function mPi(s,{shallowErrors:p,...i}={shallowErrors:!1,yieldEvery:100}){var m,E;const r=Y.YieldTracker.from(i),a=new Map,c=new Map;Object.keys(s.instances).forEach(b=>{if(s.diggestedBuiltInBaseEntitiesIds.has(b)){a.set(b,b),c.set(b,b);return}const A=x.UUID.uuid();a.set(b,A),c.set(A,b)});const e=((m=i.resetVersionOptions)==null?void 0:m.commonTimestamp)??B().toISOString(),f=s.toShallowJSON({seenEntityMaps:a});f.previousVersion=null,f.createdAt=e,f.version=x.UUID.uuid(),f.author=((E=i.resetVersionOptions)==null?void 0:E.author)??(x.sessionAuthor||"1");const h=await s.toFullProjectTransferAsync({tracker:r,seenEntityMaps:a,resetVersionOptions:i.resetVersionOptions,onVisit:i.onVisit});return{project:f,record:h.record,order:h.order,maps:a}}async function TPi(s,{enrich:p,shallowErrors:i,...r}={enrich:!0,shallowErrors:!1,yieldEvery:100},a){var P,V;const c=Y.YieldTracker.from(r),e=new Map,f=new Map;for(const M of Object.keys(s.instances)){if(s.diggestedBuiltInBaseEntitiesIds.has(M)){e.set(M,M),f.set(M,M),await c.tick();continue}const G=x.UUID.uuid();e.set(M,G),f.set(G,M),await c.tick()}const h=((P=r.resetVersionOptions)==null?void 0:P.commonTimestamp)??B().toISOString(),m=s.toShallowJSON({seenEntityMaps:e});m.previousVersion=null,m.createdAt=h,m.version=x.UUID.uuid(),m.author=((V=r.resetVersionOptions)==null?void 0:V.author)??(x.sessionAuthor||"1");const E=await rD(m,{shallowErrors:i,tracker:c},a);E.diggestedBuiltInBaseEntitiesIds=s.diggestedBuiltInBaseEntitiesIds,E.instances[E.id]=E;const b=p?E.addChangeSet(new S(E,x.sessionAuthor,h,E,!0,"project-clone")):null,A=new Fn(void 0,{allBuiltInEntityIds:s.diggestedBuiltInBaseEntitiesIds}),_=await s.toFullProjectTransferAsync({tracker:c,seenEntityMaps:e,resetVersionOptions:r.resetVersionOptions,onVisit:r.onVisit,shallowErrors:i});A.flatRecord=_.record,A.order=_.order,await A.visitAsync(M=>{var ne;if(s.diggestedBuiltInBaseEntitiesIds.has(M.id))return;const G=M;G.previousVersion=null,G.createdAt=h,G.version=x.UUID.uuid(),G.author=((ne=r.resetVersionOptions)==null?void 0:ne.author)??(x.sessionAuthor||"1");const k=oo(G,A.flatRecord);if(Object.keys(k.upstream).length){let J=!1;if(Object.keys(k.upstream).forEach(se=>{if(!J&&(!E.get(se)||E.getDeleted(se))){J=!0;return}}),J)return}const q=Re(G,E);q.hydrateAncestors(),q.addSelfToProject(b),b==null||b.add(q,W.Added)},{tracker:c}),p?(await A.visitAsync(M=>{if(M.id===E.id||s.diggestedBuiltInBaseEntitiesIds.has(M.id))return;const G=E.get(e.get(M.id));G&&(G.afterAllChildrenInitialized(b),G.captureVersion())},{tracker:c}),E.afterAllChildrenInitialized(b),E.subscribe(),E.captureVersion()):(Uu(E,h).forEach(G=>{G.remove({ignoreUpstream:!0},null)}),await A.visitAsync(G=>{if(G.id===E.id)return;const k=E.get(G.id);k&&(k.initialized=!0,k.captureVersion())},{tracker:c}),E.initialized=!0,E.subscribe(),E.captureVersion());for(const M of E.instancesList)M.previousVersion=null,await c.tick();return b==null||b.attemptAutoclose("project-clone",E.id),{project:E,maps:e}}function vPi(s,p,i=p.addChangeSet(new S(p,x.sessionAuthor,B().toISOString(),p,!0,w.AfterAllChildrenInitialized)),{enrich:r,shallowErrors:a,...c}={shallowErrors:!1,enrich:!0}){var A,_;const e=new Map,f=new Map;Object.keys(s.instances).forEach(P=>{if(s.diggestedBuiltInBaseEntitiesIds.has(P)){e.set(P,P),f.set(P,P);return}if(P===s.id){e.set(P,p.id),f.set(p.id,P);return}const V=s.get(P);if(!mD(V,{...s.instances,...s.builtInInstances}).every(q=>!s.diggestedBuiltInBaseEntitiesIds.has(q))){e.set(P,P),f.set(P,P);return}const k=x.UUID.uuid();e.set(P,k),f.set(k,P)});const h=((A=c.resetVersionOptions)==null?void 0:A.commonTimestamp)??B().toISOString(),m=s.toShallowJSON({seenEntityMaps:e});m.previousVersion=null,m.createdAt=h,m.version=x.UUID.uuid(),m.author=((_=c.resetVersionOptions)==null?void 0:_.author)??(x.sessionAuthor||"1");const E=new Fn(s,{allBuiltInEntityIds:s.diggestedBuiltInBaseEntitiesIds}),b=_L(E.flatRecord,e);return E.visit(P=>{var G;if(P.id===p.id)return;const V=P.toShallowJSON({seenEntityMaps:e});V.previousVersion=null,V.createdAt=h,V.version=x.UUID.uuid(),V.author=((G=c.resetVersionOptions)==null?void 0:G.author)??(x.sessionAuthor||"1");const M=oo(V,b);if(Object.keys(M.upstream).length){let k=!1;if(Object.keys(M.upstream).forEach(q=>{if(!k&&(!p.get(q)||p.getDeleted(q))){k=!0;return}}),k)return}try{const k=Re(V,p);k.hydrateAncestors(),k.addSelfToProject(i),i==null||i.add(k,W.Added),c.onVisit&&c.onVisit(V)}catch(k){if(a)Y.Logger.error("Error cloning entity onto existing project: ",k);else throw Y.Logger.log("Error cloning entity onto existing project: ",k),k}}),r?(E.visit(P=>{if(P.id===p.id)return;const V=p.get(e.get(P.id));V&&(V.afterAllChildrenInitialized(i),V.previousVersion=null,V.captureVersion())}),p.afterAllChildrenInitialized(i),p.subscribe(),p.captureVersion()):(Uu(p,h).forEach(V=>{V.remove({ignoreUpstream:!0},null)}),E.visit(V=>{if(V.id===p.id)return;const M=p.get(V.id);M&&(M.initialized=!0,M.previousVersion=null,M.captureVersion())}),p.initialized=!0,p.subscribe(),p.captureVersion()),p.afterAllChildrenInitialized(i),p.captureVersion(),{project:p,maps:e,changeSet:i}}async function EPi(s,p,i=p.addChangeSet(new S(p,x.sessionAuthor,B().toISOString(),p,!0,w.AfterAllChildrenInitialized)),{enrich:r,shallowErrors:a,...c}={enrich:!0,shallowErrors:!1,yieldEvery:100}){var _,P;const e=Y.YieldTracker.from(c),f=new Map,h=new Map;for(const V of Object.keys(s.instances)){if(s.diggestedBuiltInBaseEntitiesIds.has(V)){f.set(V,V),h.set(V,V),await e.tick();continue}if(V===s.id){f.set(V,p.id),h.set(p.id,V),await e.tick();continue}const M=x.UUID.uuid();f.set(V,M),h.set(M,V),await e.tick()}const m=((_=c.resetVersionOptions)==null?void 0:_.commonTimestamp)??B().toISOString(),E=s.toShallowJSON({seenEntityMaps:f});E.previousVersion=null,E.createdAt=m,E.version=x.UUID.uuid(),E.author=((P=c.resetVersionOptions)==null?void 0:P.author)??(x.sessionAuthor||"1"),p.diggestedBuiltInBaseEntitiesIds=s.diggestedBuiltInBaseEntitiesIds;const b=new Fn(void 0,{allBuiltInEntityIds:s.diggestedBuiltInBaseEntitiesIds}),A=await s.toFullProjectTransferAsync({tracker:e,seenEntityMaps:f,resetVersionOptions:c.resetVersionOptions,onVisit:c.onVisit,shallowErrors:a});return b.flatRecord=A.record,b.order=A.order,await b.visitAsync(V=>{var k;if(s.diggestedBuiltInBaseEntitiesIds.has(V.id)||V.id===p.id)return;const M=V;M.previousVersion=null,M.createdAt=m,M.version=x.UUID.uuid(),M.author=((k=c.resetVersionOptions)==null?void 0:k.author)??(x.sessionAuthor||"1");const G=oo(M,b.flatRecord);if(Object.keys(G.upstream).length){let q=!1;if(Object.keys(G.upstream).forEach(ne=>{if(!q&&(!p.get(ne)||p.getDeleted(ne))){q=!0;return}}),q)return}try{const q=Re(M,p);q.hydrateAncestors(),q.addSelfToProject(i),i==null||i.add(q,W.Added)}catch(q){if(a)Y.Logger.error("Error cloning entity onto existing project: ",q);else throw Y.Logger.log("Error cloning entity onto existing project: ",q),q}},{tracker:e}),r?(await b.visitAsync(V=>{if(V.id===p.id||s.diggestedBuiltInBaseEntitiesIds.has(V.id))return;const M=p.get(f.get(V.id));M&&(M.afterAllChildrenInitialized(i),M.previousVersion=null,M.captureVersion())},{tracker:e}),p.afterAllChildrenInitialized(i),p.subscribe(),p.captureVersion()):(Uu(p,m).forEach(M=>{M.remove({ignoreUpstream:!0},null)}),await b.visitAsync(M=>{if(M.id===p.id)return;const G=p.get(M.id);G&&(G.initialized=!0,G.previousVersion=null,G.captureVersion())},{tracker:e}),p.initialized=!0,p.subscribe(),p.captureVersion()),p.afterAllChildrenInitialized(i),p.captureVersion(),{project:p,maps:f,changeSet:i}}function hUe(s,{enrich:p,shallowErrors:i}={enrich:!0,shallowErrors:!1},r){const a=iD(s,{shallowErrors:i},r);a.activeVersion=!0;const c=B().toISOString(),e=p?a.addChangeSet(new S(a,x.sessionAuthor,c,a,!0,"project-init")):null;e&&(e.type=y1.Automatic);const f=new Fn(s,{allBuiltInEntityIds:a.diggestedBuiltInBaseEntitiesIds});return f.visit(h=>{const m=Re(h,a);m.hydrateAncestors(),m.addSelfToProject(e)}),p?(f.visit(h=>{if(h.id===a.id)return;const m=a.get(h.id);m&&(m.afterAllChildrenInitialized(e),m.captureVersion())}),a.afterAllChildrenInitialized(e),a.subscribe(),a.captureVersion()):(Uu(a,c).forEach(m=>{m.remove({ignoreUpstream:!0},null)}),f.visit(m=>{if(m.id===a.id)return;const E=a.get(m.id);E&&(E.initialized=!0,E.captureVersion())}),a.initialized=!0,a.subscribe(),a.captureVersion()),a.initialized=!0,a.emit(pi.PROJECT_INITIALIZED,a,e),e==null||e.attemptAutoclose("project-init",a.id),a}async function bPi(s,{enrich:p,shallowErrors:i,yieldEvery:r}={enrich:!0,shallowErrors:!1,yieldEvery:100},a){const c=Y.YieldTracker.from({yieldEvery:r}),e=await rD(s,{shallowErrors:i,tracker:c},a),f=B().toISOString(),h=p?e.addChangeSet(new S(e,x.sessionAuthor,f,e,!0,"project-init")):null;h&&(h.type=y1.Automatic);const m=new Fn(void 0,{allBuiltInEntityIds:e.diggestedBuiltInBaseEntitiesIds});return await m.flattenAsync(s,{tracker:c}),await m.orderEntitiesAsync({tracker:c}),await m.visitAsync(E=>{const b=Re(E,e);b.hydrateAncestors(),b.addSelfToProject(h)},{tracker:c}),p?(await m.visitAsync(E=>{if(E.id===e.id)return;const b=e.get(E.id);b&&(b.afterAllChildrenInitialized(h),b.captureVersion())},{tracker:c}),e.afterAllChildrenInitialized(h),e.subscribe(),e.captureVersion()):(Uu(e,f).forEach(b=>{b.remove({ignoreUpstream:!0},null)}),await m.visitAsync(b=>{if(b.id===e.id)return;const A=e.get(b.id);A&&(A.initialized=!0,A.captureVersion())},{tracker:c}),e.initialized=!0,e.subscribe(),e.captureVersion()),e.initialized=!0,e.emit(pi.PROJECT_INITIALIZED,e,h),h==null||h.attemptAutoclose("project-init",e.id),e}async function APi(s,p=yv,i){const r={...yv,...p};if(s.id&&gf[s.id]&&!r.ignoreCache)return gf[s.id];if(s.id&&sg[s.id]&&!r.ignoreCache)return await sg[s.id],gf[s.id];const a=yPi(s,r);s.id&&(sg[s.id]=a);const c=await a;if(c.data){let e;return r.mock?e=hUe(gB,{enrich:!!r.enrich},i):c.data instanceof x?e=c.data:e=yUe(c.data,{enrich:!!r.enrich},i),gf[s.id]=e,s.id&&delete sg[s.id],e}return null}function gPi(s){return gf[s.id]&&delete gf[s.id],null}const hv=vt([He(),Va(),Tr(),au()]),mUe=Mm([ln.CurrentDateAndTime,ln.Random,ln.Unique]),nD=st({type:mUe,rangeStart:hv.nullable(),rangeEnd:hv.nullable()}),XE=nD.extend({type:nt(ln.Random),rangeStart:hv,rangeEnd:hv}),TUe=nD.extend({type:nt(ln.Unique),rangeStart:ms(),rangeEnd:ms()}),vUe=nD.extend({type:nt(ln.CurrentDateAndTime),rangeStart:ms(),rangeEnd:ms()}),aD=XE.extend({rangeStart:Va().nullable(),rangeEnd:Va().nullable()}),EUe=aD.extend({rangeStart:Va(),rangeEnd:ms()}),bUe=aD.extend({rangeStart:ms(),rangeEnd:Va()}),AUe=aD.extend({rangeStart:Va(),rangeEnd:Va()}),sD=XE.extend({rangeStart:Va().nullable(),rangeEnd:Va().nullable()}),gUe=sD.extend({rangeStart:Va(),rangeEnd:ms()}),IUe=sD.extend({rangeStart:ms(),rangeEnd:Va()}),RUe=sD.extend({rangeStart:Va(),rangeEnd:Va()}),lD=XE.extend({rangeStart:au().nullable(),rangeEnd:au().nullable()}),DUe=lD.extend({rangeStart:au(),rangeEnd:ms()}),wUe=lD.extend({rangeStart:ms(),rangeEnd:au()}),CUe=lD.extend({rangeStart:au(),rangeEnd:au()}),OUe=XE.extend({rangeStart:ms(),rangeEnd:ms()}),_Ue=vt([gUe,IUe,RUe]),VUe=vt([EUe,bUe,AUe]),PUe=vt([DUe,wUe,CUe,vUe]),IPi=vt([_Ue,VUe,PUe,TUe,OUe]);function oD(){const s=new Set;return new Set(Rx.flatMap(i=>Ue(i,s)).map(i=>i.id))}function Fo(s){return[...s.calledByEntry||[],...s.calledByError||[],...s.calledBySuccess||[]].filter(p=>p.type!==d.GenericReference)}function NUe(s,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(s.id))return[];if(p.add(s.id),s.type!==d.ActionDescriptor)throw new Error("Entity must be an action descriptor to be flattened");return[s,...s.inputs.flatMap(r=>Ue(r,p,i)),...s.dataType?Ue(s.dataType,p,i):[],...s.error?Ue(s.error,p,i):[],...s.parent?Ue(s.parent,p,i):[]]}function xUe(s,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(s.id))return[];if(p.add(s.id),s.type!==d.ArgumentDeclaration)throw new Error("Entity must be an argument declaration to be flattened");return[s,...s.defaultValue?Ue(s.defaultValue,p):[],...s.writesValues.flatMap(r=>Ue(r,p,i)),...s.implements.flatMap(r=>Ue(r,p,i)),...s.dataType?Ue(s.dataType,p,i):[],...s.parent?Ue(s.parent,p,i):[]]}function $Ue(s,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(s.id))return[];if(p.add(s.id),s.type!==d.BreakStatement)throw new Error("Entity must be a break statement to be flattened");return[s,...s.outputs.flatMap(r=>Ue(r,p,i)),...s.throws?Ue(s.throws,p,i):[],...s.dataType?Ue(s.dataType,p,i):[],...s.readsValue?Ue(s.readsValue,p,i):[],...(Fo(s)||[]).flatMap(r=>Ue(r,p,i)),...s.parent?Ue(s.parent,p,i):[]]}function LUe(s,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(s.id))return[];if(p.add(s.id),s.type!==d.BuiltInBaseEntity)throw new Error("Entity must be a built-in base entity to be flattened");return[s,...(s.properties||[]).flatMap(r=>Ue(r,p,i)),...(s.methods||[]).flatMap(r=>Ue(r,p,i)),...(s.abstractMethods||[]).flatMap(r=>Ue(r,p,i)),...s.allPropertiesImplement?Ue(s.allPropertiesImplement,p,i):[],...s.additionalPropertiesDataType?Ue(s.additionalPropertiesDataType,p,i):[],...s.extends?Ue(s.extends,p,i):[]]}function BUe(s,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(s.id))return[];if(p.add(s.id),s.type!==d.Condition)throw new Error("Entity must be a condition to be flattened");return[s,...(s.andChildrenGroup||[]).flatMap(r=>Ue(r,p,i)),...(s.orChildrenGroup||[]).flatMap(r=>Ue(r,p,i)),...(s.inputs||[]).flatMap(r=>Ue(r,p,i)),...(s.successCalls||[]).flatMap(r=>Ue(r,p,i)),...(s.errorCalls||[]).flatMap(r=>Ue(r,p,i)),...(Fo(s)||[]).flatMap(r=>Ue(r,p,i)),...s.parent?Ue(s.parent,p,i):[]]}function MUe(s,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(s.id))return[];if(p.add(s.id),s.type!==d.ContinueStatement)throw new Error("Entity must be a continue statement to be flattened");return[s,...s.outputs.flatMap(r=>Ue(r,p,i)),...s.readsValue?Ue(s.readsValue,p,i):[],...s.throws?Ue(s.throws,p,i):[],...s.dataType?Ue(s.dataType,p,i):[],...(Fo(s)||[]).flatMap(r=>Ue(r,p,i)),...s.parent?Ue(s.parent,p,i):[]]}function GUe(s,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(s.id))return[];if(p.add(s.id),s.type!==d.DefinitionEntity)throw new Error("Entity must be a definition entity to be flattened");return[s,...s.extends?Ue(s.extends,p,i):[],...(s.implements||[]).flatMap(r=>Ue(r,p,i)),...(s.properties||[]).flatMap(r=>Ue(r,p,i)),...(s.methods||[]).flatMap(r=>Ue(r,p,i)),...(s.abstractMethods||[]).flatMap(r=>Ue(r,p,i)),...s.allPropertiesImplement?Ue(s.allPropertiesImplement,p,i):[],...s.additionalPropertiesDataType?Ue(s.additionalPropertiesDataType,p,i):[],...s.parent?Ue(s.parent,p,i):[]]}function kUe(s,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(s.id))return[];if(p.add(s.id),s.type!==d.DataType)throw new Error("Entity must be a data type to be flattened");return[s,...(s.andChildrenGroup||[]).flatMap(r=>Ue(r,p,i)),...(s.orChildrenGroup||[]).flatMap(r=>Ue(r,p,i)),...s.entity?Ue(s.entity,p,i):[],...s.foreignKeyRef?Ue(s.foreignKeyRef,p,i):[],...s.parent?Ue(s.parent,p,i):[]]}function jUe(s,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(s.id))return[];if(p.add(s.id),s.type!==d.FunctionCall)throw new Error("Entity must be a function call to be flattened");return[s,...(s.inputs||[]).flatMap(r=>Ue(r,p,i)),...(s.outputs||[]).flatMap(r=>Ue(r,p,i)),...s.error?Ue(s.error,p,i):[],...(Fo(s)||[]).flatMap(r=>Ue(r,p,i)),...(s.successCalls||[]).flatMap(r=>Ue(r,p,i)),...(s.errorCalls||[]).flatMap(r=>Ue(r,p,i)),...(s.writesValues||[]).flatMap(r=>Ue(r,p,i)),...s.parent?Ue(s.parent,p,i):[]]}function UUe(s,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(s.id))return[];if(p.add(s.id),s.type!==d.FunctionDeclaration)throw new Error("Entity must be a function declaration to be flattened");return[s,...(s.inputs||[]).flatMap(r=>Ue(r,p,i)),...(s.calls||[]).flatMap(r=>Ue(r,p,i)),...s.dataType?Ue(s.dataType,p,i):[],...s.implements?Ue(s.implements,p,i):[],...s.parent?Ue(s.parent,p,i):[]]}function FUe(s,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(s.id))return[];if(p.add(s.id),s.type!==d.GlobalEvent)throw new Error("Entity must be a global event to be flattened");return[s,...(s.inputs||[]).flatMap(r=>Ue(r,p,i)),...(s.calls||[]).flatMap(r=>Ue(r,p,i)),...s.implements?Ue(s.implements,p,i):[],...s.parent?Ue(s.parent,p,i):[]]}function KUe(s,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(s.id))return[];if(p.add(s.id),s.type!==d.InputMap)throw new Error("Entity must be an input map to be flattened");return[s,...s.readsValue?Ue(s.readsValue,p,i):[],...s.declaration?Ue(s.declaration,p,i):[],...s.defaultValue?Ue(s.defaultValue,p,i):[],...s.parent?Ue(s.parent,p,i):[]]}function qUe(s,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(s.id))return[];if(p.add(s.id),s.type!==d.InstalledProject)throw new Error("Entity must be an installed project to be flattened");return[s,...(s.functions||[]).flatMap(r=>Ue(r,p,i)),...(s.events||[]).flatMap(r=>Ue(r,p,i)),...s.parent?Ue(s.parent,p,i):[]]}function SUe(s,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(s.id))return[];if(p.add(s.id),s.type!==d.InternalCall)throw new Error("Entity must be an internal call to be flattened");return[s,...(s.successCalls||[]).flatMap(r=>Ue(r,p,i)),...(s.errorCalls||[]).flatMap(r=>Ue(r,p,i)),...(s.inputs||[]).flatMap(r=>Ue(r,p,i)),...(s.outputs||[]).flatMap(r=>Ue(r,p,i)),...(Fo(s)||[]).flatMap(r=>Ue(r,p,i)),...s.error?Ue(s.error,p,i):[],...(s.writesValues||[]).flatMap(r=>Ue(r,p,i)),...s.parent?Ue(s.parent,p,i):[]]}function ZUe(s,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(s.id))return[];if(p.add(s.id),s.type!==d.LiteralValue)throw new Error("Entity must be a literal value to be flattened");return[s,...s.valueAsTypeSingle?Ue(s.valueAsTypeSingle,p,i):[],...s.valueAsTypeList&&Array.isArray(s.valueAsTypeList)?s.valueAsTypeList.flatMap(r=>Ue(r,p,i)):[],...s.parent?Ue(s.parent,p,i):[]]}function HUe(s,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(s.id))return[];if(p.add(s.id),s.type!==d.Loop)throw new Error("Entity must be a loop to be flattened");return[s,...(s.inputs||[]).flatMap(r=>Ue(r,p,i)),...(s.outputs||[]).flatMap(r=>Ue(r,p,i)),...(s.successCalls||[]).flatMap(r=>Ue(r,p,i)),...(s.errorCalls||[]).flatMap(r=>Ue(r,p,i)),...s.error?Ue(s.error,p,i):[],...s.dataType?Ue(s.dataType,p,i):[],...s.body?Ue(s.body,p,i):[],...(Fo(s)||[]).flatMap(r=>Ue(r,p,i)),...(s.writesValues||[]).flatMap(r=>Ue(r,p,i)),...s.parent?Ue(s.parent,p,i):[]]}function WUe(s,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(s.id))return[];if(p.add(s.id),s.type!==d.Operation)throw new Error("Entity must be an operation to be flattened");return[s,...(s.successCalls||[]).flatMap(r=>Ue(r,p,i)),...(s.errorCalls||[]).flatMap(r=>Ue(r,p,i)),...(s.inputs||[]).flatMap(r=>Ue(r,p,i)),...(s.outputs||[]).flatMap(r=>Ue(r,p,i)),...(s.writesValues||[]).flatMap(r=>Ue(r,p,i)),...s.error?Ue(s.error,p,i):[],...(Fo(s)||[]).flatMap(r=>Ue(r,p,i)),...s.parent?Ue(s.parent,p,i):[]]}function zUe(s,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(s.id))return[];if(p.add(s.id),s.type!==d.OutputMap)throw new Error("Entity must be an output map to be flattened");return[s,...(s.writesValues||[]).flatMap(r=>Ue(r,p,i)),...s.declaration?Ue(s.declaration,p,i):[],...s.parent?Ue(s.parent,p,i):[]]}function YUe(s,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(s.id))return[];if(p.add(s.id),s.type!==d.PrimitiveEntity)throw new Error("Entity must be a primitive entity to be flattened");return[s,...(s.properties||[]).flatMap(r=>Ue(r,p,i)),...(s.methods||[]).flatMap(r=>Ue(r,p,i)),...(s.abstractMethods||[]).flatMap(r=>Ue(r,p,i))]}function JUe(s,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(s.id))return[];if(p.add(s.id),s.type!==d.Project)throw new Error("Entity must be a project to be flattened");return[s,...(s.entities||[]).flatMap(r=>Ue(r,p,i)),...(s.functions||[]).flatMap(r=>Ue(r,p,i)),...(s.events||[]).flatMap(r=>Ue(r,p,i)),...(s.projects||[]).flatMap(r=>Ue(r,p,i)),...(s.variableDeclarations||[]).flatMap(r=>Ue(r,p,i)),...(s.variableInstances||[]).flatMap(r=>Ue(r,p,i)),...(s.operations||[]).flatMap(r=>Ue(r,p,i)),...(s.conditions||[]).flatMap(r=>Ue(r,p,i)),...(s.functionCalls||[]).flatMap(r=>Ue(r,p,i)),...(s.projects||[]).flatMap(r=>Ue(r,p,i)),...(s.loops||[]).flatMap(r=>Ue(r,p,i)),...(s.searches||[]).flatMap(r=>Ue(r,p,i))]}function QUe(s,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(s.id))return[];if(p.add(s.id),s.type!==d.Property)throw new Error("Entity must be a property to be flattened");return[s,...s.defaultValue?Ue(s.defaultValue,p,i):[],...s.dataType?Ue(s.dataType,p,i):[],...s.parent?Ue(s.parent,p,i):[]]}function XUe(s,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(s.id))return[];if(p.add(s.id),s.type!==d.ReturnStatement)throw new Error("Entity must be a return statement to be flattened");return[s,...(s.outputs||[]).flatMap(r=>Ue(r,p,i)),...s.throws?Ue(s.throws,p,i):[],...s.readsValue?Ue(s.readsValue,p,i):[],...s.dataType?Ue(s.dataType,p,i):[],...(Fo(s)||[]).flatMap(r=>Ue(r,p,i)),...s.parent?Ue(s.parent,p,i):[]]}function eFe(s,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(s.id))return[];if(p.add(s.id),s.type!==d.Search)throw new Error("Entity must be a search to be flattened");return[s,...(s.successCalls||[]).flatMap(r=>Ue(r,p,i)),...(s.errorCalls||[]).flatMap(r=>Ue(r,p,i)),...(s.inputsDeclarations||[]).flatMap(r=>Ue(r,p,i)),...(s.inputs||[]).flatMap(r=>Ue(r,p,i)),...(s.writesValues||[]).flatMap(r=>Ue(r,p,i)),...(s.outputs||[]).flatMap(r=>Ue(r,p,i)),...s.error?Ue(s.error,p,i):[],...s.dataType?Ue(s.dataType,p,i):[],...(Fo(s)||[]).flatMap(r=>Ue(r,p,i)),...s.parent?Ue(s.parent,p,i):[]]}function tFe(s,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(s.id))return[];if(p.add(s.id),s.type!==d.ValueDescriptor)throw new Error("Entity must be a value descriptor to be flattened");return[s,...s.defaultValue?Ue(s.defaultValue,p,i):[],...s.dataType?Ue(s.dataType,p,i):[],...s.parent?Ue(s.parent,p,i):[]]}function iFe(s,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(s.id))return[];if(p.add(s.id),s.type!==d.VariableDeclaration)throw new Error("Entity must be a variable declaration to be flattened");return[s,...(s.successCalls||[]).flatMap(r=>Ue(r,p,i)),...(s.errorCalls||[]).flatMap(r=>Ue(r,p,i)),...(s.inputs||[]).flatMap(r=>Ue(r,p,i)),...(s.outputs||[]).flatMap(r=>Ue(r,p,i)),...(s.internalCalls||[]).flatMap(r=>Ue(r,p,i)),...(s.writesValues||[]).flatMap(r=>Ue(r,p,i)),...s.readsValue?Ue(s.readsValue,p,i):[],...s.defaultValue?Ue(s.defaultValue,p,i):[],...(Fo(s)||[]).flatMap(r=>Ue(r,p,i)),...s.dataType?Ue(s.dataType,p,i):[],...s.parent?Ue(s.parent,p,i):[]]}function rFe(s,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(s.id))return[];if(p.add(s.id),s.type!==d.VariableInstance)throw new Error("Entity must be a variable instance to be flattened");return[s,...(s.successCalls||[]).flatMap(r=>Ue(r,p,i)),...(s.errorCalls||[]).flatMap(r=>Ue(r,p,i)),...(s.inputs||[]).flatMap(r=>Ue(r,p,i)),...(s.outputs||[]).flatMap(r=>Ue(r,p,i)),...(s.internalCalls||[]).flatMap(r=>Ue(r,p,i)),...(s.writesValues||[]).flatMap(r=>Ue(r,p,i)),...s.readsValue?Ue(s.readsValue,p,i):[],...s.defaultValue?Ue(s.defaultValue,p,i):[],...(Fo(s)||[]).flatMap(r=>Ue(r,p,i)),...s.declaration?Ue(s.declaration,p,i):[],...s.parent?Ue(s.parent,p,i):[]]}function Ue(s,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(!s)throw new Error("Entity must be defined to be flattened");if(s.type===d.GenericReference)return[];const r=i.ignoreBuiltInBaseEntities?i.diggestedBuiltInBaseEntitiesIds??new Set(oD()):new Set;if(i.diggestedBuiltInBaseEntitiesIds=r,i.ignoreBuiltInBaseEntities&&(ma.includes(s.type)||r.has(s.id)))return[];if(p.has(s.id))return[];switch(s.type){case d.FunctionCall:return jUe(s,p,i);case d.Operation:return WUe(s,p,i);case d.Condition:return BUe(s,p,i);case d.Loop:return HUe(s,p,i);case d.Search:return eFe(s,p,i);case d.GlobalEvent:return FUe(s,p,i);case d.ReturnStatement:return XUe(s,p,i);case d.ContinueStatement:return MUe(s,p,i);case d.BreakStatement:return $Ue(s,p,i);case d.VariableDeclaration:return iFe(s,p,i);case d.DefinitionEntity:return GUe(s,p,i);case d.FunctionDeclaration:return UUe(s,p,i);case d.Project:return JUe(s,p,i);case d.ActionDescriptor:return NUe(s,p,i);case d.ArgumentDeclaration:return xUe(s,p,i);case d.ValueDescriptor:return tFe(s,p,i);case d.InputMap:return KUe(s,p,i);case d.OutputMap:return zUe(s,p,i);case d.DataType:return kUe(s,p,i);case d.InstalledProject:return qUe(s,p,i);case d.InternalCall:return SUe(s,p,i);case d.LiteralValue:return ZUe(s,p,i);case d.Property:return QUe(s,p,i);case d.VariableInstance:return rFe(s,p,i);case d.BuiltInBaseEntity:return i.ignoreBuiltInBaseEntities?[]:LUe(s,p,i);case d.PrimitiveEntity:return i.ignoreBuiltInBaseEntities?[]:YUe(s,p,i)}return[]}async function dD(s={}){const p=new Set,i=Y.YieldTracker.from(s),r=new Set;for(const a of Rx){const c=await je(a,p,{ignoreBuiltInBaseEntities:!1,tracker:i});for(const e of c)r.add(e.id),await i.tick()}return r}function Ko(s){return[...s.calledByEntry||[],...s.calledByError||[],...s.calledBySuccess||[]].filter(p=>p.type!==d.GenericReference)}async function nFe(s,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(s.id))return[];if(p.add(s.id),s.type!==d.ActionDescriptor)throw new Error("Entity must be an action descriptor to be flattened");const r=Y.YieldTracker.from(i),a=[s];await r.tick();const c={...i,tracker:r};delete c.yieldEvery;for(const e of s.inputs)a.push(...await je(e,p,c));return s.dataType&&a.push(...await je(s.dataType,p,c)),s.error&&a.push(...await je(s.error,p,c)),s.parent&&a.push(...await je(s.parent,p,c)),a}async function aFe(s,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(s.id))return[];if(p.add(s.id),s.type!==d.ArgumentDeclaration)throw new Error("Entity must be an argument declaration to be flattened");const r=Y.YieldTracker.from(i),a=[s];await r.tick();const c={...i,tracker:r};delete c.yieldEvery,s.dataType&&a.push(...await je(s.dataType,p,c)),s.parent&&a.push(...await je(s.parent,p,c)),s.defaultValue&&a.push(...await je(s.defaultValue,p,c));for(const e of s.writesValues||[])a.push(...await je(e,p,c));for(const e of s.implements||[])a.push(...await je(e,p,c));return a}async function sFe(s,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(s.id))return[];if(p.add(s.id),s.type!==d.BreakStatement)throw new Error("Entity must be a break statement to be flattened");const r=Y.YieldTracker.from(i),a=[s];await r.tick();const c={...i,tracker:r};delete c.yieldEvery;for(const f of s.outputs)a.push(...await je(f,p,c));s.parent&&a.push(...await je(s.parent,p,c)),s.throws&&a.push(...await je(s.throws,p,c)),s.dataType&&a.push(...await je(s.dataType,p,c)),s.readsValue&&a.push(...await je(s.readsValue,p,c));const e=Ko(s);for(const f of e)a.push(...await je(f,p,c));return a}async function lFe(s,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(s.id))return[];if(p.add(s.id),s.type!==d.BuiltInBaseEntity)throw new Error("Entity must be a built-in base entity to be flattened");const r=Y.YieldTracker.from(i),a=[s];await r.tick();const c={...i,tracker:r};delete c.yieldEvery;for(const e of s.properties||[])a.push(...await je(e,p,c));for(const e of s.methods||[])a.push(...await je(e,p,c));for(const e of s.abstractMethods||[])a.push(...await je(e,p,c));return s.allPropertiesImplement&&a.push(...await je(s.allPropertiesImplement,p,c)),s.additionalPropertiesDataType&&a.push(...await je(s.additionalPropertiesDataType,p,c)),s.extends&&a.push(...await je(s.extends,p,c)),a}async function oFe(s,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(s.id))return[];if(p.add(s.id),s.type!==d.Condition)throw new Error("Entity must be a condition to be flattened");const r=Y.YieldTracker.from(i),a=[s];await r.tick();const c={...i,tracker:r};if(delete c.yieldEvery,s.andChildrenGroup&&Array.isArray(s.andChildrenGroup))for(const f of s.andChildrenGroup)a.push(...await je(f,p,c));if(s.orChildrenGroup&&Array.isArray(s.orChildrenGroup))for(const f of s.orChildrenGroup)a.push(...await je(f,p,c));for(const f of s.inputs)a.push(...await je(f,p,c));for(const f of s.successCalls)a.push(...await je(f,p,c));for(const f of s.errorCalls)a.push(...await je(f,p,c));const e=Ko(s);for(const f of e)a.push(...await je(f,p,c));return s.parent&&a.push(...await je(s.parent,p,c)),a}async function dFe(s,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(s.id))return[];if(p.add(s.id),s.type!==d.ContinueStatement)throw new Error("Entity must be a continue statement to be flattened");const r=Y.YieldTracker.from(i),a=[s];await r.tick();const c={...i,tracker:r};delete c.yieldEvery;for(const f of s.outputs)a.push(...await je(f,p,c));const e=Ko(s);for(const f of e)a.push(...await je(f,p,c));return s.parent&&a.push(...await je(s.parent,p,c)),s.throws&&a.push(...await je(s.throws,p,c)),s.dataType&&a.push(...await je(s.dataType,p,c)),s.readsValue&&a.push(...await je(s.readsValue,p,c)),a}async function uFe(s,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(s.id))return[];if(p.add(s.id),s.type!==d.DefinitionEntity)throw new Error("Entity must be a definition entity to be flattened");const r=Y.YieldTracker.from(i),a=[s];await r.tick();const c={...i,tracker:r};delete c.yieldEvery;for(const e of s.properties)a.push(...await je(e,p,c));for(const e of s.methods)a.push(...await je(e,p,c));for(const e of s.abstractMethods)a.push(...await je(e,p,c));for(const e of s.implements)a.push(...await je(e,p,c));return s.extends&&a.push(...await je(s.extends,p,c)),s.parent&&a.push(...await je(s.parent,p,c)),s.additionalPropertiesDataType&&a.push(...await je(s.additionalPropertiesDataType,p,c)),s.allPropertiesImplement&&a.push(...await je(s.allPropertiesImplement,p,c)),a}async function pFe(s,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(s.id))return[];if(p.add(s.id),s.type!==d.DataType)throw new Error("Entity must be a data type to be flattened");const r=Y.YieldTracker.from(i),a=[s];await r.tick();const c={...i,tracker:r};if(delete c.yieldEvery,s.parent&&a.push(...await je(s.parent,p,c)),s.foreignKeyRef&&a.push(...await je(s.foreignKeyRef,p,c)),s.entity&&a.push(...await je(s.entity,p,c)),s.orChildrenGroup)for(const e of s.orChildrenGroup)a.push(...await je(e,p,c));if(s.andChildrenGroup)for(const e of s.andChildrenGroup)a.push(...await je(e,p,c));return a}async function cFe(s,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(s.id))return[];if(p.add(s.id),s.type!==d.FunctionCall)throw new Error("Entity must be a function call to be flattened");const r=Y.YieldTracker.from(i),a=[s];await r.tick();const c={...i,tracker:r};delete c.yieldEvery;for(const f of s.inputs)a.push(...await je(f,p,c));for(const f of s.outputs)a.push(...await je(f,p,c));s.error&&a.push(...await je(s.error,p,c));const e=Ko(s);for(const f of e)a.push(...await je(f,p,c));for(const f of s.successCalls)a.push(...await je(f,p,c));for(const f of s.errorCalls)a.push(...await je(f,p,c));for(const f of s.writesValues)a.push(...await je(f,p,c));return s.parent&&a.push(...await je(s.parent,p,c)),a}async function fFe(s,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(s.id))return[];if(p.add(s.id),s.type!==d.FunctionDeclaration)throw new Error("Entity must be a function declaration to be flattened");const r=Y.YieldTracker.from(i),a=[s];await r.tick();const c={...i,tracker:r};delete c.yieldEvery,s.parent&&a.push(...await je(s.parent,p,c)),s.implements&&a.push(...await je(s.implements,p,c)),s.dataType&&a.push(...await je(s.dataType,p,c));for(const e of s.inputs)a.push(...await je(e,p,c));for(const e of s.calls)a.push(...await je(e,p,c));return a}async function yFe(s,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(s.id))return[];if(p.add(s.id),s.type!==d.GlobalEvent)throw new Error("Entity must be a global event to be flattened");const r=Y.YieldTracker.from(i),a=[s];await r.tick();const c={...i,tracker:r};delete c.yieldEvery,s.parent&&a.push(...await je(s.parent,p,c)),s.implements&&a.push(...await je(s.implements,p,c));for(const e of s.inputs)a.push(...await je(e,p,c));for(const e of s.calls)a.push(...await je(e,p,c));return a}async function hFe(s,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(s.id))return[];if(p.add(s.id),s.type!==d.InputMap)throw new Error("Entity must be an input map to be flattened");const r=Y.YieldTracker.from(i),a=[s];await r.tick();const c={...i,tracker:r};return delete c.yieldEvery,s.parent&&a.push(...await je(s.parent,p,c)),s.declaration&&a.push(...await je(s.declaration,p,c)),s.readsValue&&a.push(...await je(s.readsValue,p,c)),s.dataType&&a.push(...await je(s.dataType,p,c)),s.defaultValue&&a.push(...await je(s.defaultValue,p,c)),a}async function mFe(s,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(s.id))return[];if(p.add(s.id),s.type!==d.InstalledProject)throw new Error("Entity must be an installed project to be flattened");const r=Y.YieldTracker.from(i),a=[s];await r.tick();const c={...i,tracker:r};delete c.yieldEvery;for(const e of s.functions)a.push(...await je(e,p,c));for(const e of s.events)a.push(...await je(e,p,c));return s.parent&&a.push(...await je(s.parent,p,c)),a}async function TFe(s,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(s.id))return[];if(p.add(s.id),s.type!==d.InternalCall)throw new Error("Entity must be an internal call to be flattened");const r=Y.YieldTracker.from(i),a=[s];await r.tick();const c={...i,tracker:r};delete c.yieldEvery;for(const f of s.inputs)a.push(...await je(f,p,c));for(const f of s.outputs)a.push(...await je(f,p,c));s.error&&a.push(...await je(s.error,p,c));const e=Ko(s);for(const f of e)a.push(...await je(f,p,c));for(const f of s.successCalls)a.push(...await je(f,p,c));for(const f of s.errorCalls)a.push(...await je(f,p,c));for(const f of s.writesValues)a.push(...await je(f,p,c));return s.parent&&a.push(...await je(s.parent,p,c)),a}async function vFe(s,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(s.id))return[];if(p.add(s.id),s.type!==d.LiteralValue)throw new Error("Entity must be a literal value to be flattened");const r=Y.YieldTracker.from(i),a=[s];await r.tick();const c={...i,tracker:r};if(delete c.yieldEvery,s.valueAsTypeSingle&&a.push(...await je(s.valueAsTypeSingle,p,c)),s.valueAsTypeList&&Array.isArray(s.valueAsTypeList))for(const e of s.valueAsTypeList)a.push(...await je(e,p,c));return s.parent&&a.push(...await je(s.parent,p,c)),a}async function EFe(s,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(s.id))return[];if(p.add(s.id),s.type!==d.Loop)throw new Error("Entity must be a loop to be flattened");const r=Y.YieldTracker.from(i),a=[s];await r.tick();const c={...i,tracker:r};delete c.yieldEvery;for(const f of s.inputs)a.push(...await je(f,p,c));for(const f of s.outputs)a.push(...await je(f,p,c));s.error&&a.push(...await je(s.error,p,c));const e=Ko(s);for(const f of e)a.push(...await je(f,p,c));for(const f of s.successCalls)a.push(...await je(f,p,c));for(const f of s.errorCalls)a.push(...await je(f,p,c));for(const f of s.writesValues)a.push(...await je(f,p,c));return s.parent&&a.push(...await je(s.parent,p,c)),s.body&&a.push(...await je(s.body,p,c)),s.dataType&&a.push(...await je(s.dataType,p,c)),a}async function bFe(s,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(s.id))return[];if(p.add(s.id),s.type!==d.Operation)throw new Error("Entity must be an operation to be flattened");const r=Y.YieldTracker.from(i),a=[s];await r.tick();const c={...i,tracker:r};delete c.yieldEvery;for(const f of s.inputs)a.push(...await je(f,p,c));for(const f of s.outputs)a.push(...await je(f,p,c));s.error&&a.push(...await je(s.error,p,c));const e=Ko(s);for(const f of e)a.push(...await je(f,p,c));for(const f of s.successCalls)a.push(...await je(f,p,c));for(const f of s.errorCalls)a.push(...await je(f,p,c));for(const f of s.writesValues)a.push(...await je(f,p,c));return s.parent&&a.push(...await je(s.parent,p,c)),a}async function AFe(s,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(s.id))return[];if(p.add(s.id),s.type!==d.OutputMap)throw new Error("Entity must be an output map to be flattened");const r=Y.YieldTracker.from(i),a=[s];await r.tick();const c={...i,tracker:r};delete c.yieldEvery;for(const e of s.writesValues)a.push(...await je(e,p,c));return s.declaration&&a.push(...await je(s.declaration,p,c)),s.dataType&&a.push(...await je(s.dataType,p,c)),s.parent&&a.push(...await je(s.parent,p,c)),a}async function gFe(s,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(s.id))return[];if(p.add(s.id),s.type!==d.PrimitiveEntity)throw new Error("Entity must be a primitive entity to be flattened");const r=Y.YieldTracker.from(i),a=[s];await r.tick();const c={...i,tracker:r};delete c.yieldEvery;for(const e of s.properties)a.push(...await je(e,p,c));for(const e of s.methods)a.push(...await je(e,p,c));for(const e of s.abstractMethods)a.push(...await je(e,p,c));return a}async function IFe(s,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(s.id))return[];if(p.add(s.id),s.type!==d.Project)throw new Error("Entity must be a project to be flattened");const r=Y.YieldTracker.from(i),a=[s];await r.tick();const c={...i,tracker:r};delete c.yieldEvery;for(const e of s.entities)a.push(...await je(e,p,c));for(const e of s.functions)a.push(...await je(e,p,c));for(const e of s.events)a.push(...await je(e,p,c));for(const e of s.projects)a.push(...await je(e,p,c));for(const e of s.variableDeclarations)a.push(...await je(e,p,c));for(const e of s.variableInstances)a.push(...await je(e,p,c));for(const e of s.operations)a.push(...await je(e,p,c));for(const e of s.conditions)a.push(...await je(e,p,c));for(const e of s.functionCalls)a.push(...await je(e,p,c));for(const e of s.projects)a.push(...await je(e,p,c));for(const e of s.loops)a.push(...await je(e,p,c));for(const e of s.searches)a.push(...await je(e,p,c));return a}async function RFe(s,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(s.id))return[];if(p.add(s.id),s.type!==d.Property)throw new Error("Entity must be a property to be flattened");const r=Y.YieldTracker.from(i),a=[s];await r.tick();const c={...i,tracker:r};return delete c.yieldEvery,s.defaultValue&&a.push(...await je(s.defaultValue,p,c)),s.dataType&&a.push(...await je(s.dataType,p,c)),s.parent&&a.push(...await je(s.parent,p,c)),a}async function DFe(s,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(s.id))return[];if(p.add(s.id),s.type!==d.ReturnStatement)throw new Error("Entity must be a return statement to be flattened");const r=Y.YieldTracker.from(i),a=[s];await r.tick();const c={...i,tracker:r};delete c.yieldEvery;for(const f of s.outputs)a.push(...await je(f,p,c));for(const f of s.outputs)a.push(...await je(f,p,c));s.throws&&a.push(...await je(s.throws,p,c)),s.readsValue&&a.push(...await je(s.readsValue,p,c)),s.dataType&&a.push(...await je(s.dataType,p,c));const e=Ko(s);for(const f of e)a.push(...await je(f,p,c));return s.parent&&a.push(...await je(s.parent,p,c)),a}async function wFe(s,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(s.id))return[];if(p.add(s.id),s.type!==d.Search)throw new Error("Entity must be a search to be flattened");const r=Y.YieldTracker.from(i),a=[s];await r.tick();const c={...i,tracker:r};delete c.yieldEvery;for(const f of s.inputs)a.push(...await je(f,p,c));for(const f of s.outputs)a.push(...await je(f,p,c));s.error&&a.push(...await je(s.error,p,c)),s.dataType&&a.push(...await je(s.dataType,p,c));for(const f of s.inputsDeclarations)a.push(...await je(f,p,c));const e=Ko(s);for(const f of e)a.push(...await je(f,p,c));for(const f of s.successCalls)a.push(...await je(f,p,c));for(const f of s.errorCalls)a.push(...await je(f,p,c));for(const f of s.writesValues)a.push(...await je(f,p,c));return s.parent&&a.push(...await je(s.parent,p,c)),a}async function CFe(s,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(s.id))return[];if(p.add(s.id),s.type!==d.ValueDescriptor)throw new Error("Entity must be a value descriptor to be flattened");const r=Y.YieldTracker.from(i),a=[s];await r.tick();const c={...i,tracker:r};return delete c.yieldEvery,s.defaultValue&&a.push(...await je(s.defaultValue,p,c)),s.dataType&&a.push(...await je(s.dataType,p,c)),s.parent&&a.push(...await je(s.parent,p,c)),a}async function OFe(s,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(s.id))return[];if(p.add(s.id),s.type!==d.VariableDeclaration)throw new Error("Entity must be a variable declaration to be flattened");const r=Y.YieldTracker.from(i),a=[s];await r.tick();const c={...i,tracker:r};delete c.yieldEvery;for(const f of s.inputs)a.push(...await je(f,p,c));for(const f of s.outputs)a.push(...await je(f,p,c));s.error&&a.push(...await je(s.error,p,c)),s.dataType&&a.push(...await je(s.dataType,p,c)),s.readsValue&&a.push(...await je(s.readsValue,p,c)),s.defaultValue&&a.push(...await je(s.defaultValue,p,c));const e=Ko(s);for(const f of e)a.push(...await je(f,p,c));for(const f of s.successCalls)a.push(...await je(f,p,c));for(const f of s.errorCalls)a.push(...await je(f,p,c));for(const f of s.writesValues)a.push(...await je(f,p,c));for(const f of s.internalCalls)a.push(...await je(f,p,c));return s.parent&&a.push(...await je(s.parent,p,c)),a}async function _Fe(s,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(s.id))return[];if(p.add(s.id),s.type!==d.VariableInstance)throw new Error("Entity must be a variable instance to be flattened");const r=Y.YieldTracker.from(i),a=[s];await r.tick();const c={...i,tracker:r};delete c.yieldEvery;for(const f of s.inputs)a.push(...await je(f,p,c));for(const f of s.outputs)a.push(...await je(f,p,c));s.error&&a.push(...await je(s.error,p,c)),s.readsValue&&a.push(...await je(s.readsValue,p,c)),s.defaultValue&&a.push(...await je(s.defaultValue,p,c));const e=Ko(s);for(const f of e)a.push(...await je(f,p,c));for(const f of s.successCalls)a.push(...await je(f,p,c));for(const f of s.errorCalls)a.push(...await je(f,p,c));for(const f of s.writesValues)a.push(...await je(f,p,c));for(const f of s.internalCalls)a.push(...await je(f,p,c));return s.parent&&a.push(...await je(s.parent,p,c)),s.declaration&&a.push(...await je(s.declaration,p,c)),a}async function je(s,p=new Set,i={ignoreBuiltInBaseEntities:!1,yieldEvery:100}){const r={...i,ignoreBuiltInBaseEntities:i.ignoreBuiltInBaseEntities??!1};if(!s)throw new Error("Entity must be defined to be flattened");if(s.type===d.GenericReference)return[];const a=Y.YieldTracker.from(r);r.tracker=a,r.yieldEvery!==void 0&&delete r.yieldEvery;const c=r.ignoreBuiltInBaseEntities?r.diggestedBuiltInBaseEntitiesIds??new Set(await dD(r)):new Set;if(r.diggestedBuiltInBaseEntitiesIds=c,r.ignoreBuiltInBaseEntities&&(ma.includes(s.type)||c.has(s.id)))return[];if(p.has(s.id))return[];switch(s.type){case d.FunctionCall:return cFe(s,p,r);case d.Operation:return bFe(s,p,r);case d.Condition:return oFe(s,p,r);case d.Loop:return EFe(s,p,r);case d.Search:return wFe(s,p,r);case d.GlobalEvent:return yFe(s,p,r);case d.ReturnStatement:return DFe(s,p,r);case d.ContinueStatement:return dFe(s,p,r);case d.BreakStatement:return sFe(s,p,r);case d.VariableDeclaration:return OFe(s,p,r);case d.DefinitionEntity:return uFe(s,p,r);case d.FunctionDeclaration:return fFe(s,p,r);case d.Project:return IFe(s,p,r);case d.ActionDescriptor:return nFe(s,p,r);case d.ArgumentDeclaration:return aFe(s,p,r);case d.ValueDescriptor:return CFe(s,p,r);case d.InputMap:return hFe(s,p,r);case d.OutputMap:return AFe(s,p,r);case d.DataType:return pFe(s,p,r);case d.InstalledProject:return mFe(s,p,r);case d.InternalCall:return TFe(s,p,r);case d.LiteralValue:return vFe(s,p,r);case d.Property:return RFe(s,p,r);case d.VariableInstance:return _Fe(s,p,r);case d.BuiltInBaseEntity:return r.ignoreBuiltInBaseEntities?[]:lFe(s,p,r);case d.PrimitiveEntity:return r.ignoreBuiltInBaseEntities?[]:gFe(s,p,r)}return[]}function VFe(s){return s==null||s===""}function RPi(s){return s===null}function Vn(s){return s!=null&&s.valueAsType?!1:VFe(s==null?void 0:s.value)}function co(s){return s?s.valueAsType===null&&s.value===null:!1}function PFe(s,p){if(s===p||!s&&!p)return!0;if(!s||!p||s.name===ye.EntityTemplate&&p.name!==ye.EntityTemplate||p.name===ye.EntityTemplate&&s.name!==ye.EntityTemplate)return!1;if(s.name===ye.ActionDescriptor&&p.name!==ye.ActionDescriptor||p.name===ye.ActionDescriptor&&s.name!==ye.ActionDescriptor)return!1;if(s.valueAsTypeSingle&&!p.valueAsTypeSingle||p.valueAsTypeSingle&&!s.valueAsTypeSingle)return!1;if(s.valueAsTypeList&&!p.valueAsTypeList||p.valueAsTypeList&&!s.valueAsTypeList)return!1;if(s.valueAsTypeSingle&&p.valueAsTypeSingle){if(s.valueAsTypeSingle.id!==p.valueAsTypeSingle.id)return!1}else if(s.valueAsTypeList&&p.valueAsTypeList){if(s.valueAsTypeList.length!==p.valueAsTypeList.length)return!1;for(let i=0;i<s.valueAsTypeList.length;i++)if(s.valueAsTypeList[i].id!==p.valueAsTypeList[i].id)return!1}else if(!s.valueAsType&&!p.valueAsType&&s.value!==p.value)return!1;return!0}function NFe(s,p,i){if(!i)throw new Error("[checkIsRowTransformerUpToDate] 'lastPublishedEntityVersion' argument is required");if(!p)throw new Error("[checkIsRowTransformerUpToDate] 'entity' argument is required");if(!s)throw new Error("[checkIsRowTransformerUpToDate] 'newestOpenRowTransformer' argument is required");let r=!0;const a=s.methods.find(c=>{var e;return((e=c.implements)==null?void 0:e.id)===re["built-in-base-entity"].BUILT_IN_SQL_ROW_TRANSFORMER_ENTITY.methods.up.id});if(a?(fn(i).forEach(c=>{const e=a.inputs.find(f=>f.name===c.name);e&&ni(e.getDataType(null),c.getDataType(null)).compatible||(r=!1)}),a.returnStatements.forEach(c=>{!c.dataType||!c.dataType.entity||c.dataType.entity.type!==d.DefinitionEntity?r=!1:ev(c.dataType.entity,p)||(r=!1)})):r=!1,r===null||r){const c=s.methods.find(e=>{var f;return((f=e.implements)==null?void 0:f.id)===re["built-in-base-entity"].BUILT_IN_SQL_ROW_TRANSFORMER_ENTITY.methods.down.id});c?(fn(p).forEach(e=>{const f=c.inputs.find(h=>h.name===e.name);f&&ni(f.getDataType(null),e.getDataType(null)).compatible||(r=!1)}),c.returnStatements.forEach(e=>{!e.dataType||!e.dataType.entity||e.dataType.entity.type!==d.DefinitionEntity?r=!1:ev(e.dataType.entity,i)||(r=!1)})):r=!1}return{isPreexistingRowTransformerUpToDate:r}}function EV(s,p,i,r={skipBaseExtension:!1}){var J;const a={...r||{},skipBaseExtension:(r==null?void 0:r.skipBaseExtension)||!1},c={changesSinceLastPublication:!1,rowTransformerNeeded:!1,newRowTransformerNeeded:!1,newestOpenRowTransformer:null,newRequiredProperties:[],newNonRequiredProperties:[],deletedProperties:[],lastPublishedEntityVersion:null,updatedEntityVersion:i,propChanges:new Map,isPreexistingRowTransformerUpToDate:null,extendedEntities:[]},f=s.entities.filter(se=>{var ue;if(se.id===i.id)return!1;let te=!1,le=se;for(;le;){if(((ue=le.extends)==null?void 0:ue.id)===i.id){te=!0;break}if(le.extends&&le.extends.type===d.DefinitionEntity)le=le.extends;else break}return te}).map(se=>EV(s,p,se,{...a,skipBaseExtension:!0}));if(!p)return{...c,changesSinceLastPublication:!0,extendedEntities:f};const h=p.get(i.id);if(!h)return{...c,changesSinceLastPublication:!0,extendedEntities:f};const m=p.entities.filter(se=>di(se,ge.SQL_ROW_TRANSFORMER)),b=s.entities.filter(se=>{var z;if(!di(se,ge.SQL_ROW_TRANSFORMER)||m.find(Q=>Q.id===se.id))return!1;const le=se.properties.find(Q=>!!Q.implements.find(de=>re["built-in-base-entity"].BUILT_IN_SQL_ROW_TRANSFORMER_ENTITY.properties.definition.id===de.id));if(!le)return!1;const ue=(z=le.defaultValue)==null?void 0:z.valueAsType;return ue?ue.id===i.id:!1}).sort((se,te)=>B(se.createdAt).isAfter(B(te.createdAt))?-1:1)[0]||null,A=new Map;let _=!1,P=null;!a.skipBaseExtension&&i.extends&&((J=i.extends)==null?void 0:J.type)===d.DefinitionEntity&&(P=EV(i.project,p,i.extends));const V=fn(i).filter(se=>fn(h).find(ue=>ue.id===se.id)?!1:!Ka(se.getDataType(null))),M=fn(i).filter(se=>fn(h).find(ue=>ue.id===se.id)?!1:!!Ka(se.getDataType(null))),G=fn(h).filter(se=>!fn(i).find(le=>le.id===se.id));fn(i).filter(se=>{var fe,be,Ie,_e,Ge,Se,Ye,Ze,et,Et,yt;const te=fn(h).find(ai=>ai.id===se.id);let le=!1;if(!te)return!1;const ue=Sa(se.dataType,!0,`[resolveSQLMigrationsDiffs] Unsupported data-type structure on current property '${se.name}' (${se.id}). 'andChildrenGroup' with more than one child is not supported for SQL column properties.`),z=Sa(te.dataType,!0,`[resolveSQLMigrationsDiffs] Unsupported data-type structure on last published property '${se.name}' (${se.id}). 'andChildrenGroup' with more than one child is not supported for SQL column properties.`),Q=Dh(ue,!0,`[resolveSQLMigrationsDiffs] Unsupported data-type structure on current property '${se.name}' (${se.id}). 'orChildrenGroup' with multiple non-null children is not supported for SQL column properties.`),de=Dh(z,!0,`[resolveSQLMigrationsDiffs] Unsupported data-type structure on last published property '${se.name}' (${se.id}). 'orChildrenGroup' with multiple non-null children is not supported for SQL column properties.`);if(((fe=Q==null?void 0:Q.foreignKeyRef)==null?void 0:fe.id)!==((be=de==null?void 0:de.foreignKeyRef)==null?void 0:be.id)){const ai=Q==null?void 0:Q.foreignKeyRef,ui=de==null?void 0:de.foreignKeyRef;A.set(se.id,{...A.get(se.id)||{},newForeignKeyRef:ai||void 0,oldForeignKeyRef:ui||void 0,property:se,oldProperty:te}),le=!0,_=!0}else((Ie=Q==null?void 0:Q.entity)==null?void 0:Ie.id)!==((_e=de==null?void 0:de.entity)==null?void 0:_e.id)&&(((Ge=Q==null?void 0:Q.entity)==null?void 0:Ge.id)===re["primitive-entity"].string.id||((Se=de==null?void 0:de.entity)==null?void 0:Se.id)===re["primitive-entity"].date.id&&((Ye=Q==null?void 0:Q.entity)==null?void 0:Ye.id)===re["primitive-entity"].number.id?A.set(se.id,{...A.get(se.id)||{},castableDataTypeEntity:{fromId:((Ze=de==null?void 0:de.entity)==null?void 0:Ze.id)||"",toId:((et=Q==null?void 0:Q.entity)==null?void 0:et.id)||""},property:se,oldProperty:te}):(A.set(se.id,{...A.get(se.id)||{property:se},nonCastableDataTypeEntity:{fromId:((Et=de==null?void 0:de.entity)==null?void 0:Et.id)||"",toId:((yt=Q==null?void 0:Q.entity)==null?void 0:yt.id)||""},property:se,oldProperty:te}),_=!0),le=!0);se.name!==(te==null?void 0:te.name)&&(A.set(se.id,{...A.get(se.id)||{},nameChange:{from:(te==null?void 0:te.name)||"",to:se.name},property:se,oldProperty:te}),le=!0);const pe=Ka(te.getDataType(null)),he=Ka(se.getDataType(null));return he!==pe&&(A.set(se.id,{...A.get(se.id)||{},requiredChange:{from:!pe,to:!he},property:se,oldProperty:te}),he||(_=!0),le=!0),le}),V.length>0&&(_=!0);let k=null;b&&_&&(k=NFe(b,i,h).isPreexistingRowTransformerUpToDate);const q=i.name!==h.name?{from:h.name,to:i.name}:void 0;let ne=P!=null&&P.rowTransformerNeeded?!0:_;return{...c,changesSinceLastPublication:A.size>0||!!G.length||!!V.length||!!M.length||ne,rowTransformerNeeded:ne,newestOpenRowTransformer:b,nameChange:q,newRequiredProperties:V,newNonRequiredProperties:M,deletedProperties:G,lastPublishedEntityVersion:h,propChanges:A,newRowTransformerNeeded:ne&&!b,isPreexistingRowTransformerUpToDate:k,extendedEntities:f}}function wL(s,p,i,r,a){const c=a==null?void 0:a.ignoreNonEditable;a&&(a.ignoreNonEditable=!0);try{if(!s)throw new Error("[addDifferencesToRowTransformer] 'project' argument is required");if(!p)throw new Error("[addDifferencesToRowTransformer] 'transformer' argument is required");if(!i)throw new Error("[addDifferencesToRowTransformer] 'newEntityState' argument is required");if(!r)throw new Error("[addDifferencesToRowTransformer] 'oldEntityState' argument is required");const e=fn(i),f=fn(r);p.afterAllChildrenInitialized(a);const h=p.methods.find(E=>{var b;return((b=E.implements)==null?void 0:b.id)===re["built-in-base-entity"].BUILT_IN_SQL_ROW_TRANSFORMER_ENTITY.methods.up.id}),m=p.methods.find(E=>{var b;return((b=E.implements)==null?void 0:b.id)===re["built-in-base-entity"].BUILT_IN_SQL_ROW_TRANSFORMER_ENTITY.methods.down.id});if(!h)throw new Error("[addDifferencesToRowTransformer] The 'up' transformer trigger is missing from the parent");if(!m)throw new Error("[addDifferencesToRowTransformer] The 'down' transformer trigger is missing from the parent");f.forEach(E=>{const b=h.inputs.find(V=>V.name===E.name),A=Dh(E.getDataType(null))||E.getDataType(null);let _=b,P;if(b)_.editable=!0;else{const V=Za.new(a);V.parent=h.toReference(),V.name=E.name,V.index=E.index,V.implements=[...E.implements.map(G=>G.toJSON())];const M=Re(V,s);M.hydrateAncestors(),a.add(M,W.Added),M.addSelfToProject(a),M.initChildren(a),_=M}if(!b||!_.dataType||_.dataType&&s.diggestedBuiltInBaseEntitiesIds.has(_.dataType.id)){const V=vr.new(a);V.parent=_.toReference();const M=Re(V,s);M.hydrateAncestors(),a.add(M,W.Added),M.addSelfToProject(a),M.initChildren(a),P=M}else P=_.dataType,P.editable=!0;A&&P.merge(A,a),P.metaSync({editable:!1,deletable:!1},a),_.metaSync({editable:!1,deletable:!1},a)}),[...h.inputs].forEach(E=>{f.find(A=>A.name===E.name)||(E.editable=!0,E.remove({ignoreUpstream:!1},a),E.editable=!1)}),[...h.returnStatements].forEach(E=>{var M,G,k,q,ne,J,se,te,le;if(!E.dataType||E.dataType&&s.diggestedBuiltInBaseEntitiesIds.has(E.dataType.id)){const ue=vr.new(a);ue.entity=i.toReference(),ue.parent=E.toReference();const z=Re(ue,s);z.hydrateAncestors(),a.add(z,W.Added),z.addSelfToProject(a),z.initChildren(a)}const b=(M=E.dataType)==null?void 0:M.entity,A=!b||b.type!==d.DefinitionEntity||b.type===d.DefinitionEntity&&((G=b.parent)==null?void 0:G.type)===d.Project||((k=b.parent)==null?void 0:k.id)!==((q=E.dataType)==null?void 0:q.id),_=!A&&b&&b.type===d.DefinitionEntity&&b.name&&s.getDefinitionEntities().some(ue=>ue.id!==b.id&&ue.name===b.name),P=b&&b.type===d.DefinitionEntity&&b.name&&!A&&!_?b.name:su((i==null?void 0:i.name)+" new format",s.getDefinitionEntities());let V=(ne=E.dataType)==null?void 0:ne.entity;(!((J=E.dataType)!=null&&J.entity)||E.dataType.entity.type!==d.DefinitionEntity||E.dataType.entity.type==d.DefinitionEntity&&((se=E.dataType.entity.parent)==null?void 0:se.type)===d.Project||E.dataType.entity.parent.id!==E.dataType.id)&&(V=i.clone(a,E.dataType),V.metaSync({name:P},a)),Vg(V,i,a,{exactDataType:!0}),V.setExtension(null,a),V.addImplementation(s.getBuiltIn(re["built-in-base-entity"].BUILT_IN_PERSISTED_ENTITY_ENTITY.id),a),V.properties.forEach(ue=>ue.setExtends(null,a)),E.dataType.setEntity(V,a),(le=(te=E.dataType)==null?void 0:te.entity)==null||le.metaSync({name:P},a),E.afterAllChildrenInitialized(a),E.outputs.forEach(ue=>{var pe,he,fe;if(ue.defaultValue||ue.readsValue)return;const z=(pe=e.find(be=>be.name===ce(ue,s)))==null?void 0:pe.id,Q=(he=f.find(be=>(be==null?void 0:be.id)===z))==null?void 0:he.name,de=m.inputs.find(be=>Q===ce(be,s));(fe=ni((de==null?void 0:de.getDataType(null))||null,ue.getDataType(null)||null))!=null&&fe.compatible&&(ue.setValueWriter(de,a),de==null||de.addValueReader(ue,a))})}),e.forEach(E=>{var M;const b=(M=E.knownVersions)==null?void 0:M.get(E.previousVersion),A=m.inputs.find(G=>G.name===E.name||!!b&&b.name===G.name),_=Dh(E.getDataType(null))||E.getDataType(null);let P=A,V;if(A)P.editable=!0,P.metaSync({name:E.name,codeName:E.codeName,description:E.description},a);else{const G=Za.new(a);G.parent=m.toReference(),G.name=E.name,G.codeName=E.codeName,G.description=E.description,G.index=E.index,G.implements=[...E.implements.map(q=>q.toJSON())];const k=Re(G,s);k.hydrateAncestors(),a.add(k,W.Added),k.addSelfToProject(a),k.initChildren(a),P=k}if(!A||!P.dataType||P.dataType&&s.diggestedBuiltInBaseEntitiesIds.has(P.dataType.id)){const G=vr.new(a);G.parent=P.toReference();const k=Re(G,s);k.hydrateAncestors(),a.add(k,W.Added),k.addSelfToProject(a),k.initChildren(a),V=k}else V=P.dataType,V.editable=!0,V.merge(P.dataType,a);_&&V.merge(_,a),V.metaSync({editable:!1,deletable:!1},a),P.metaSync({editable:!1,deletable:!1},a)}),[...m.inputs].forEach(E=>{e.find(A=>{var P;if(A.name===E.name)return!0;const _=(P=A.knownVersions)==null?void 0:P.get(A.previousVersion);if(_&&_.name===E.name)return!0})||(E.editable=!0,E.remove({ignoreUpstream:!1},a),E.editable=!1)}),[...m.returnStatements].forEach(E=>{var M,G,k,q;if(!E.dataType||E.dataType&&s.diggestedBuiltInBaseEntitiesIds.has(E.dataType.id)){const ne=vr.new(a);ne.parent=E.toReference();const J=Re(ne,s);J.hydrateAncestors(),a.add(J,W.Added),J.addSelfToProject(a),J.initChildren(a)}const b=(M=E.dataType)==null?void 0:M.entity,A=!b||b.id===re["built-in-base-entity"].BUILT_IN_PERSISTED_ENTITY_ENTITY.id,_=!A&&b&&b.type===d.DefinitionEntity&&b.name&&s.getDefinitionEntities().some(ne=>ne.id!==b.id&&ne.name===b.name),P=b&&b.type===d.DefinitionEntity&&b.name&&!A&&!_?b.name:su((r==null?void 0:r.name)+" old format",s.getDefinitionEntities());let V=(G=E.dataType)==null?void 0:G.entity;(!V||(V==null?void 0:V.id)===re["built-in-base-entity"].BUILT_IN_PERSISTED_ENTITY_ENTITY.id)&&(V=r.clone(a,E.dataType),V.metaSync({name:P},a)),Vg(V,r,a,{exactDataType:!0}),V.setExtension(null,a),V.addImplementation(s.getBuiltIn(re["built-in-base-entity"].BUILT_IN_PERSISTED_ENTITY_ENTITY.id),a),V.properties.forEach(ne=>ne.setExtends(null,a)),E.dataType.setEntity(V,a),(q=(k=E.dataType)==null?void 0:k.entity)==null||q.metaSync({name:P},a),E.afterAllChildrenInitialized(a),E.outputs.forEach(ne=>{var le,ue,z;if(ne.defaultValue||ne.readsValue)return;const J=(le=f.find(Q=>Q.name===ce(ne,s)))==null?void 0:le.id,se=(ue=e.find(Q=>(Q==null?void 0:Q.id)===J))==null?void 0:ue.name,te=m.inputs.find(Q=>se===ce(Q,s));(z=ni((te==null?void 0:te.getDataType(null))||null,ne.getDataType(null)||null))!=null&&z.compatible&&(ne.setValueWriter(te,a),te==null||te.addValueReader(ne,a))})})}finally{a&&(a.ignoreNonEditable=!!c)}}function xFe(s,p,i,r,a={}){var G;const c=s.getBuiltIn(ge.SQL_ROW_TRANSFORMER),e=su(ce(p,s)+" row transformer",s.entities),f=c.implement(e,r),h=f.ownDeclaredProperties.find(k=>{var q;return(q=k.implements)==null?void 0:q.find(ne=>ne.id===re["built-in-base-entity"].BUILT_IN_SQL_ROW_TRANSFORMER_ENTITY.properties.definition.id)}),m=f.methods.find(k=>{var q;return((q=k.implements)==null?void 0:q.id)===re["built-in-base-entity"].BUILT_IN_SQL_ROW_TRANSFORMER_ENTITY.methods.up.id}),E=f.methods.find(k=>{var q;return((q=k.implements)==null?void 0:q.id)===re["built-in-base-entity"].BUILT_IN_SQL_ROW_TRANSFORMER_ENTITY.methods.down.id});if(!h||!m||!E)throw new Error("Cannot find definition property on the new row transformer entity");if(h.defaultValue)h.defaultValue.setValueAsTypeSingle(p,r);else{const k=Lr.new(r);k.name=ye.EntityTemplate,k.valueAsTypeSingle=p.toJSON(),k.parent=h.toReference();const q=Re(k,s);q.hydrateAncestors(),r.add(q,W.Added),q.addSelfToProject(r),q.initChildren(r)}wL(s,f,p,i,r),Y.Logger.log("BEFORE - changeSet.listAdded",r.listAdded.map(k=>{var ne,J,se,te,le,ue,z;const q=s.get(k.id);return q?ce(q,s):k.type===d.InputMap?"(not found) "+k.type+" "+k.id+" - declaration: "+((ne=k.declaration)==null?void 0:ne.type)+" "+((J=k.declaration)==null?void 0:J.id)+' "'+((se=k.declaration)==null?void 0:se.name)+`"
|
|
606
|
+
`)),Y.Logger.log("Persisting new additions"),h.visit(async(m,E)=>{if(r.added[m.id]){Y.Logger.log("Adding: ",m.id);try{const b=Re(m,this);if(b.hydrateAncestors(),b.addSelfToProject(a),a.add(b,W.Added),a||b.captureVersion(),!this.get(m.id))throw new Error(`Entity ${m.id} was not added to the project`)}catch(b){Y.Logger.error("Error: ",b),Y.Logger.error("Errored entity: ",m)}}}),Y.Logger.log("Persisting updates"),h.visit(async(m,E)=>{if(r.updated[m.id]){Y.Logger.log("Updating: ",m.id);try{const b=this.get(m.id);b?(b.updateWithShallowTransfer(m,a),a.add(b,W.Updated),a||b.captureVersion()):Y.Logger.warn(`Active version of ${m.id} not found when applying external changes`)}catch(b){Y.Logger.error("Error: ",b),Y.Logger.error("Errored entity: ",m)}}}),Y.Logger.log("Persisting removals"),h.visit(async(m,E)=>{if(r.removed[m.id]){Y.Logger.log("Removing: ",m.id);try{const b=this.get(m.id);b&&(b.remove({ignoreUpstream:!1},a),a.add(b,W.Removed),a||b.captureVersion())}catch(b){Y.Logger.error("Error: ",b),Y.Logger.error("Errored entity: ",m)}}}),a.open=!1,a}toBuiltInShallowRecord(){const i={};return Object.values(this.builtInInstances).forEach(r=>{const a=r.toShallowJSON();i[r.id]=a}),i}toShallowRecord(){const i={};return Object.values(this.instances).forEach(r=>{const a=r.toShallowJSON();i[r.id]=a}),i}toFullProjectTransfer(i){const r={shallowErrors:!1,...i},a=new Fn(void 0,{allBuiltInEntityIds:this.diggestedBuiltInBaseEntitiesIds});a.flatRecord={};for(const f of Object.values(this.instances))this.diggestedBuiltInBaseEntitiesIds.has(f.id)||(a.flatRecord[f.id]=f);a.order=Object.keys(a.flatRecord),a.orderEntities();const c={},e=[];return a.visit(f=>{try{const h=f.toShallowJSON();c[f.id]=h,e.push(f.id)}catch(h){if(Y.Logger.error(`[toFullProjectTransfer] Error serializing ${f.type} ${f.id}`,h),!r.shallowErrors)throw h}}),{order:e,size:e.length,record:c}}async toFullProjectTransferAsync(i={}){const r={shallowErrors:!1,...i},a=Y.YieldTracker.from(r),c=new Fn(void 0,{allBuiltInEntityIds:this.diggestedBuiltInBaseEntitiesIds});c.flatRecord={};for(const h of Object.values(this.instances))await a.tick(),!this.diggestedBuiltInBaseEntitiesIds.has(h.id)&&(c.flatRecord[h.id]=h);c.order=Object.keys(c.flatRecord);const e=[];if(r.seenEntityMaps)for(const h of c.order){const m=r.seenEntityMaps.get(h)??h;this.diggestedBuiltInBaseEntitiesIds.has(m)}await c.orderEntitiesAsync({tracker:a});const f={};return await c.visitAsync(async h=>{try{if(this.diggestedBuiltInBaseEntitiesIds.has(h.id))return;const m=h.toShallowJSON({seenEntityMaps:r.seenEntityMaps});r.resetVersionOptions&&(m.version=Gt.UUID.uuid(),m.createdAt=r.resetVersionOptions.commonTimestamp||B().toISOString(),m.author=r.resetVersionOptions.author||Gt.sessionAuthor||"1",m.previousVersion=null),f[m.id]=m,e.push(m.id),r!=null&&r.onVisit&&await r.onVisit(m)}catch(m){if(Y.Logger.error(`[toFullProjectTransferAsync] Error serializing ${h.type} ${h.id}`,m),!r.shallowErrors)throw m}},{tracker:a}),{order:e,size:e.length,record:f}}async toFullProjectGenerationTargetAsync(i={}){const r={shallowErrors:!1,...i},a=Y.YieldTracker.from(r),c=new Fn(void 0,{allBuiltInEntityIds:this.diggestedBuiltInBaseEntitiesIds});c.flatRecord={};for(const h of Object.values(this.instances))await a.tick(),!this.diggestedBuiltInBaseEntitiesIds.has(h.id)&&(c.flatRecord[h.id]=h);c.order=Object.keys(c.flatRecord);const e=[];if(r.seenEntityMaps)for(const h of c.order){const m=r.seenEntityMaps.get(h)??h;this.diggestedBuiltInBaseEntitiesIds.has(m)}await c.orderEntitiesAsync({tracker:a});const f={};return await c.visitAsync(async h=>{try{if(this.diggestedBuiltInBaseEntitiesIds.has(h.id))return;const m=h.toGenerationTarget({seenEntityMaps:r.seenEntityMaps});f[m.id]=m,e.push(m.id),r!=null&&r.onVisit&&await r.onVisit(m)}catch(m){if(Y.Logger.error(`[toFullProjectTransferAsync] Error serializing ${h.type} ${h.id}`,m),!r.shallowErrors)throw m}},{tracker:a}),{order:e,size:e.length,record:f}}};R(Gt,"parentContext",DL),R(Gt,"sessionAuthor","1"),R(Gt,"repository",{APICreate:async(i,...r)=>i,APIUpdate:async(i,...r)=>i,APIDelete:async(i,...r)=>i,APIClone:async(i,...r)=>{},APILoad:async(i,...r)=>null,APILoadVersion:async(i,r,...a)=>null}),R(Gt,"type",d.Project),R(Gt,"USER_MANAGED_PARENT_TYPES",[]),R(Gt,"PARENT_TYPES",[...Gt.USER_MANAGED_PARENT_TYPES]),R(Gt,"MUTABLE_BASE_PROPERTIES",["name","description"]),R(Gt,"INMUTABLE_BASE_PROPERTIES",["id","type","workspaceId","version","createdAt","author","previousVersion"]),R(Gt,"BASE_PROPERTIES",[...Gt.MUTABLE_BASE_PROPERTIES,...Gt.INMUTABLE_BASE_PROPERTIES]),R(Gt,"MUTABLE_META_PROPERTIES",[...Gt.MUTABLE_BASE_PROPERTIES,"x","y"]),R(Gt,"INMUTABLE_META_PROPERTIES",[...Gt.INMUTABLE_BASE_PROPERTIES]),R(Gt,"META_PROPERTIES",[...Gt.MUTABLE_META_PROPERTIES,...Gt.INMUTABLE_META_PROPERTIES]),R(Gt,"MUTABLE_UPSTREAM_PROPERTIES",[]),R(Gt,"INMUTABLE_UPSTREAM_PROPERTIES",["primitives","builtInBaseEntities","operationDeclarations","globalEventActionDescriptors","loopDeclarations","builtInInstances"]),R(Gt,"UPSTREAM_PROPERTIES",[...Gt.MUTABLE_UPSTREAM_PROPERTIES,...Gt.INMUTABLE_UPSTREAM_PROPERTIES]),R(Gt,"MUTABLE_DOWNSTREAM_PROPERTIES",["entities","projects","functions","events","variableDeclarations","variableInstances","conditions","operations","functionCalls","loops","searches"]),R(Gt,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),R(Gt,"DOWNSTREAM_PROPERTIES",[...Gt.MUTABLE_DOWNSTREAM_PROPERTIES,...Gt.INMUTABLE_DOWNSTREAM_PROPERTIES]),R(Gt,"PROPERTIES",[...Gt.META_PROPERTIES,...Gt.UPSTREAM_PROPERTIES,...Gt.DOWNSTREAM_PROPERTIES]);let x=Gt;class ePi extends er{constructor(p){super(dE,p)}}class tPi extends er{constructor(i){super(sm,i);R(this,"autoexecutable",!0)}getEntityToMatchInputMap(i){return i.inputs.find(r=>{var a;return((a=r.declaration)==null?void 0:a.id)===re.operation[xe.Validate].inputs.entityToMatch.id})||null}getDataToValidateInputMap(i){return i.inputs.find(r=>{var a;return((a=r.declaration)==null?void 0:a.id)===re.operation[xe.Validate].inputs.dataToValidate.id})||null}getOutputDataOutputMap(i){return i.outputs.find(r=>{var a;return((a=r.declaration)==null?void 0:a.id)===re.operation[xe.Validate].dataType.entity.properties.outputEntity.id})||null}getEntityToMatch(i,r=this.project.addChangeSet(new S(this.project,x.sessionAuthor,B().toISOString(),this,!0,"get-entity-to-match-validate-data"))){var e;const a=((e=this.project.requestActiveDynamicValue(i))==null?void 0:e.value)||null,c=a==null?void 0:a.valueAsTypeSingle;return r==null||r.attemptAutoclose("get-entity-to-match-validate-data",this.id),c}syncOperationInstance(i,r=this.project.addChangeSet(new S(this.project,x.sessionAuthor,B().toISOString(),this,!0,"sync-operation-instance-validate-data"))){const a=[],c=[],e=[],f=[],h=this.getEntityToMatchInputMap(i);if(h){const{added:b,updated:A,removed:_,affected:P}=this.syncEntityToMatchInputMapDataType(h,r);a.push(...A),c.push(...b),e.push(..._),f.push(...P)}const m=this.getDataToValidateInputMap(i);if(m){const{added:b,updated:A,removed:_,affected:P}=this.syncDataToValidateInputMapDataType(m,r);a.push(...A),c.push(...b),e.push(..._),f.push(...P)}const E=this.getOutputDataOutputMap(i);if(E){const{added:b,updated:A,removed:_,affected:P}=this.syncOutputDataOutputMapDataType(E,r);a.push(...A),c.push(...b),e.push(..._),f.push(...P)}return r==null||r.attemptAutoclose("sync-operation-instance-validate-data",this.id),{updated:C(a),added:C(c),removed:C(e),affected:C(f),self:i}}syncEntityToMatchInputMapDataType(i,r=this.project.addChangeSet(new S(this.project,x.sessionAuthor,B().toISOString(),this,!0,"sync-entity-to-match-input-map-data-type"))){var E,b,A,_,P,V,M,G,k,q,ne,J,se,te,le,ue,z,Q;const a=[],c=[],e=[],f=[];if(((E=i.declaration)==null?void 0:E.id)!==re.operation[xe.Validate].inputs.entityToMatch.id)return r==null||r.attemptAutoclose("sync-entity-to-match-input-map-data-type",this.id),{updated:[],added:[],removed:[],affected:[],self:null};const h=((b=this.project.requestActiveDynamicValue(i))==null?void 0:b.value)||null,m=h==null?void 0:h.valueAsTypeSingle;if(!i.dataType){const de={id:x.UUID.uuid(),version:x.UUID.uuid(),createdAt:(r==null?void 0:r.timestamp)||new Date().toISOString(),author:(r==null?void 0:r.author)||x.sessionAuthor,previousVersion:null,deleted:!1,deletable:!0,editable:!0,type:d.DataType,parentRelationType:null,options:((A=i.declaration.dataType)==null?void 0:A.options)||null,implementationChooseOne:((_=i.declaration.dataType)==null?void 0:_.implementationChooseOne)||!1,staticEntities:((P=i.declaration.dataType)==null?void 0:P.staticEntities)??null,interactiveEntities:((V=i.declaration.dataType)==null?void 0:V.interactiveEntities)??null,actionEntities:((M=i.declaration.dataType)==null?void 0:M.actionEntities)??null,index:((G=i.declaration.dataType)==null?void 0:G.index)??null,isList:((k=i.declaration.dataType)==null?void 0:k.isList)||!1,foreignKeyAllowed:((q=i.declaration.dataType)==null?void 0:q.foreignKeyAllowed)??null,andChildrenGroup:null,orChildrenGroup:null,foreignKeyRef:null,asType:!0,entity:(m==null?void 0:m.toJSON())||null,like:!0,inferred:!0,parent:i.toReference()},pe=Re(de,i.project);pe.hydrateAncestors(),pe.addSelfToProject(r),r==null||r.add(pe,W.Added),pe.setParent(i,r),pe.initChildren(r),pe.setEntity(m,r),a.push(pe),i.setDataType(pe,r),r||pe.captureVersion()}return(z=i.dataType)==null||z.metaSync({inferred:!0,like:!1,asType:!0,options:((ne=i.declaration.dataType)==null?void 0:ne.options)||null,implementationChooseOne:((J=i.declaration.dataType)==null?void 0:J.implementationChooseOne)||!1,staticEntities:((se=i.declaration.dataType)==null?void 0:se.staticEntities)??null,interactiveEntities:((te=i.declaration.dataType)==null?void 0:te.interactiveEntities)??null,actionEntities:((le=i.declaration.dataType)==null?void 0:le.actionEntities)??null,isList:((ue=i.declaration.dataType)==null?void 0:ue.isList)||!1},r),(Q=i.dataType)==null||Q.setEntity(m,r),i.dataType&&c.push(i.dataType),r==null||r.attemptAutoclose("sync-entity-to-match-input-map-data-type",this.id),{updated:C(c),added:C(a),removed:C(e),affected:C(f),self:i.dataType}}syncDataToValidateInputMapDataType(i,r=this.project.addChangeSet(new S(this.project,x.sessionAuthor,B().toISOString(),this,!0,"sync-data-to-validate-input-map-data-type"))){var b,A,_;const a=[],c=[],e=[],f=[];if(((b=i.declaration)==null?void 0:b.id)!==re.operation[xe.Validate].inputs.dataToValidate.id)return r==null||r.attemptAutoclose("sync-data-to-validate-input-map-data-type",this.id),{updated:[],added:[],removed:[],affected:[],self:null};const h=this.getEntityToMatchInputMap(i.parent);if(!h)return r==null||r.attemptAutoclose("sync-data-to-validate-input-map-data-type",this.id),{updated:[],added:[],removed:[],affected:[],self:null};if(!this.getEntityToMatch(h,r))return r==null||r.attemptAutoclose("sync-data-to-validate-input-map-data-type",this.id),{updated:[],added:[],removed:[],affected:[],self:null};if(!i.dataType){const P={id:x.UUID.uuid(),version:x.UUID.uuid(),createdAt:(r==null?void 0:r.timestamp)||new Date().toISOString(),author:(r==null?void 0:r.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()},V=Re(P,i.project);V.hydrateAncestors(),V.addSelfToProject(r),r==null||r.add(V,W.Added),V.setParent(i,r),V.initChildren(r),a.push(V),i.setDataType(V,r),r||V.captureVersion()}(A=i.dataType)==null||A.metaSync({inferred:!0,like:!0,asType:!1},r);const E=this.getEntityToMatch(h,r);return(_=i.dataType)==null||_.setEntity(E,r),i.dataType&&c.push(i.dataType),r==null||r.attemptAutoclose("sync-data-to-validate-input-map-data-type",this.id),{updated:C(c),added:C(a),removed:C(e),affected:C(f),self:i.dataType}}syncOutputDataOutputMapDataType(i,r=this.project.addChangeSet(new S(this.project,x.sessionAuthor,B().toISOString(),this,!0,"sync-output-data-output-map-data-type"))){var A,_,P,V;const a=[],c=[],e=[],f=[];if(((A=i.declaration)==null?void 0:A.id)!==re.operation[xe.Validate].dataType.entity.properties.outputEntity.id)return r==null||r.attemptAutoclose("sync-output-data-output-map-data-type",this.id),{updated:[],added:[],removed:[],affected:[],self:null};const h=this.getEntityToMatchInputMap(i.parent);if(!h)return r==null||r.attemptAutoclose("sync-output-data-output-map-data-type",this.id),{updated:[],added:[],removed:[],affected:[],self:null};if(!this.getEntityToMatch(h,r))return r==null||r.attemptAutoclose("sync-output-data-output-map-data-type",this.id),{updated:[],added:[],removed:[],affected:[],self:null};const E=((_=this.project.requestActiveDynamicValue(h))==null?void 0:_.value)||null,b=(E==null?void 0:E.valueAsTypeSingle)||null;if(!i.dataType){const M={id:x.UUID.uuid(),version:x.UUID.uuid(),createdAt:(r==null?void 0:r.timestamp)||new Date().toISOString(),author:(r==null?void 0:r.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()},G=Re(M,i.project);G.hydrateAncestors(),G.addSelfToProject(r),r==null||r.add(G,W.Added),G.setParent(i,r),G.initChildren(r),G.setEntity(b,r),a.push(G),i.setDataType(G,r),r||G.captureVersion()}return(P=i.dataType)==null||P.metaSync({inferred:!0,like:!0,asType:!1},r),(V=i.dataType)==null||V.setEntity(b,r),i.dataType&&c.push(i.dataType),r==null||r.attemptAutoclose("sync-output-data-output-map-data-type",this.id),{updated:C(c),added:C(a),removed:C(e),affected:C(f),self:i.dataType}}inferInputMapDataType(i,r=this.project.addChangeSet(new S(this.project,x.sessionAuthor,B().toISOString(),this,!0,"infer-input-map-data-type-validate-data"))){var c,e,f;if(((c=i.declaration)==null?void 0:c.id)===re.operation[xe.Validate].inputs.entityToMatch.id){const{added:h,updated:m,removed:E,affected:b}=r?this.syncEntityToMatchInputMapDataType(i,r):{added:[],updated:[],removed:[],affected:[]};return r==null||r.attemptAutoclose("infer-input-map-data-type",this.id),{updated:C(m),added:C(h),removed:C(E),affected:C(b),self:i.dataType}}if(((e=i.declaration)==null?void 0:e.id)===re.operation[xe.Validate].inputs.dataToValidate.id){const{added:h,updated:m,removed:E,affected:b}=this.syncDataToValidateInputMapDataType(i,r);return r==null||r.attemptAutoclose("infer-input-map-data-type",this.id),{updated:C(m),added:C(h),removed:C(E),affected:C(b),self:i.dataType}}const a=(f=i.declaration)==null?void 0:f.getDataType(r);if(a&&a.isResolved)return r==null||r.attemptAutoclose("infer-input-map-data-type-validate-data",this.id),{updated:[],added:[],removed:[],affected:[],self:a};if(i.readsValue){const h=iu(i.readsValue,r);return r==null||r.attemptAutoclose("infer-input-map-data-type-validate-data",this.id),{updated:[],added:[],removed:[],affected:[],self:h}}return r==null||r.attemptAutoclose("infer-input-map-data-type-validate-data",this.id),{updated:[],added:[],removed:[],affected:[],self:null}}inferOutputMapDataType(i,r=this.project.addChangeSet(new S(this.project,x.sessionAuthor,B().toISOString(),this,!0,"infer-output-map-data-type-validate-data"))){var a;if(((a=i.declaration)==null?void 0:a.id)===re.operation[xe.Validate].dataType.entity.properties.outputEntity.id){const{added:c,updated:e,removed:f,affected:h}=this.syncOutputDataOutputMapDataType(i,r);return r==null||r.attemptAutoclose("infer-output-map-data-type-validate-data",this.id),{updated:C(e),added:C(c),removed:C(f),affected:C(h),self:i.dataType}}return{updated:[],added:[],removed:[],affected:[],self:null}}}class iPi extends er{constructor(p){super(bP,p)}}class rPi extends er{constructor(p){super(AP,p)}}class nPi extends er{constructor(p){super(gP,p)}}class aPi extends er{constructor(p){super(zI,p)}}class sPi extends er{constructor(p){super(yI,p)}}class lPi extends er{constructor(p){super(Rv,p)}}function lUe(s){const p=[new OVe(s),new ePi(s),new tPi(s),new aPi(s),new iPi(s),new nPi(s),new rPi(s),new sPi(s),new lPi(s)];return SN.forEach(i=>{p.some(r=>r.id===i.id)||p.push(new er(i,s))}),p.forEach(i=>{i.initChildren(null),s.subscribeBuiltInInstance(i)}),s.operationDeclarations=p,p}const oPi=[];function oUe(s){const p=[new AVe(s),new RVe(s),new wVe(s),new CVe(s)];return mx.forEach(i=>{!p.some(r=>r.id===i.id)&&!oPi.includes(i.id)&&p.push(new Td(i,s))}),p.forEach(i=>{s.subscribeBuiltInInstance(i)}),s.builtInBaseEntities=p,p}function dUe(s){const p=[];return NV.forEach(i=>{p.some(r=>r.id===i.id)||p.push(new Pf(i,s))}),p.forEach(i=>{s.subscribeBuiltInInstance(i)}),s.primitives=p,p}function uUe(s){const p=[new er(f1,s)];return p.forEach(i=>{i.initChildren(null),s.subscribeBuiltInInstance(i)}),s.globalEventActionDescriptors=p,p}function pUe(s){const p=[new er(bE,s),new er(ey,s),new er(vE,s),new er(Vm,s),new er(Pm,s),new er(HR,s)];p.forEach(r=>{r.initChildren(null),s.subscribeBuiltInInstance(r)}),s.loopDeclarations=p;const i=[new er(r1,s),new er(EE,s),new er(JR,s),new er(JN,s),new er(ex,s),new er(WR,s)];return i.forEach(r=>{r.initChildren(null),s.subscribeBuiltInInstance(r)}),s.loopDeclarationsBodies=i,p}function cUe(s){const p=[new Ed(Ix,s)];return p.forEach(i=>{i.initChildren(null),s.subscribeBuiltInInstance(i)}),s.valueDescriptors=p,p}function fUe(s){const p=[new er(vx,s),new er(Tx,s),new er(Ex,s),new er(bx,s)];return Ax.forEach(i=>{p.some(r=>r.id===i.id)||p.push(new er(i,s))}),p.forEach(i=>{i.initChildren(null),s.subscribeBuiltInInstance(i)}),s.conditionDeclarations=p,p}function UT(s){return s&&typeof s.then=="function"}function dPi(s,p){const i=new Fn(s[0],{allBuiltInEntityIds:p.allBuiltInEntityIds}),r=s.map(c=>c.id),a={};return s.forEach(c=>{a[c.id]=c}),i.order=r,i.flatRecord=a,i.orderEntities(),i.order.map(c=>i.flatRecord[c])}function uPi(s,p){const i=new Fn(Object.values(s)[0],{allBuiltInEntityIds:p.allBuiltInEntityIds}),r=Object.keys(s);return i.order=r,i.flatRecord=s,i.orderEntities(),i.order}async function pPi(s,p){const i=Y.YieldTracker.from(p),r=new Fn(s[0],{allBuiltInEntityIds:p.allBuiltInEntityIds}),a=s.map(e=>e.id),c={};for(const e of s)c[e.id]=e,await i.tick();return r.order=a,r.flatRecord=c,await r.orderEntitiesAsync({tracker:i}),r.order.map(e=>r.flatRecord[e])}async function cPi(s,p){const i=Y.YieldTracker.from(p),r=new Fn(Object.values(s)[0],{allBuiltInEntityIds:p.allBuiltInEntityIds}),a=Object.keys(s);return r.order=a,r.flatRecord=s,await r.orderEntitiesAsync({tracker:i}),r.order}class Fn{constructor(p,i={}){R(this,"order",[]);R(this,"flatRecord",{});R(this,"allBuiltInEntityIds");R(this,"onGoingVisits",{});R(this,"cachedReferences",{});if(i.allBuiltInEntityIds&&(this.allBuiltInEntityIds=i.allBuiltInEntityIds),!p)return;const r={asyncInitialOrder:!1,...i};r.asyncInitialOrder?this.flattenAsync(p).then(()=>{this.orderEntitiesAsync({...r}).then(()=>{var a;(a=r.onOrdered)==null||a.call(r)})}):(this.flatten(p),this.orderEntities())}flatten(p){this.allBuiltInEntityIds||(this.allBuiltInEntityIds=new Set(oD()));const i=C(Ue(p,new Set(this.allBuiltInEntityIds),{ignoreBuiltInBaseEntities:!0,diggestedBuiltInBaseEntitiesIds:this.allBuiltInEntityIds})),r=new Set;for(const a of i)this.flatRecord[a.id]=a,r.add(a.id);this.order=Array.from(r)}async flattenAsync(p,i={}){const r=Y.YieldTracker.from(i);this.allBuiltInEntityIds||(this.allBuiltInEntityIds=await dD({tracker:r}));const a=await Ip(await je(p,new Set(this.allBuiltInEntityIds),{ignoreBuiltInBaseEntities:!0,diggestedBuiltInBaseEntitiesIds:this.allBuiltInEntityIds,tracker:r}),{tracker:r}),c=new Set;for(const e of a)this.flatRecord[e.id]=e,c.add(e.id),await r.tick();this.order=Array.from(c)}moveEntityAfterDependencies(p){const i=this.cachedReferences[p.id]||oo(p,this.flatRecord,{ignoreBuiltInBaseEntities:!0,allBuiltInEntityIds:this.allBuiltInEntityIds});this.cachedReferences[p.id]=i;const{upstream:r}=i;for(const a of Object.keys(r)){const c=this.order.indexOf(a),e=this.order.indexOf(p.id);if(c>e)return this.order.splice(e,1),this.order.splice(c,0,p.id),!0}return!1}orderEntities(){let p=!1;for(let i=0;i<this.order.length;i++){const r=this.order[i],a=this.flatRecord[r];if(a||Y.Logger.warn(`Entity with id ${r} not found in flatRecord. Skipping...`),this.moveEntityAfterDependencies(a)){p=!0;break}}p&&this.orderEntities()}async orderEntitiesAsync(p={}){let i=!1;const r=Y.YieldTracker.from(p);for(let a=0;a<this.order.length;a++){const c=this.order[a],e=this.flatRecord[c];if(e||Y.Logger.warn(`Entity with id ${c} not found in flatRecord. Skipping...`),this.moveEntityAfterDependencies(e)){i=!0;break}await r.tick()}i&&await this.orderEntitiesAsync({tracker:r})}getUpstreamOngoingDependenciesVisits(p,i){const r=this.cachedReferences[p]||oo(this.flatRecord[p],this.flatRecord,{ignoreBuiltInBaseEntities:!0,allBuiltInEntityIds:this.allBuiltInEntityIds});this.cachedReferences[p]=r;const{upstream:a}=r,c={};return Object.entries(this.onGoingVisits[i]||{}).forEach(([e,f])=>{Object.keys(a).includes(e)&&(c[e]=f)}),c}getDownstreamOngoingDependenciesVisits(p,i){const r=Object.keys(this.onGoingVisits[i]||{}),a=new Set(r.flatMap(e=>{const f=this.cachedReferences[e]||oo(this.flatRecord[e],this.flatRecord,{ignoreBuiltInBaseEntities:!0,allBuiltInEntityIds:this.allBuiltInEntityIds});return this.cachedReferences[e]=f,Object.keys(f.downstream)})),c={};return Array.from(a).forEach(e=>{e===p&&(c[e]=this.onGoingVisits[i][e])}),c}async settlePromises(p,i){const r=Object.values(p);r.length&&await Promise.all(r),Object.keys(p).forEach(a=>{delete this.onGoingVisits[i][a]})}visit(p){const i=this.order;for(const r of i)p(this.flatRecord[r],this.flatRecord);return this}reverseVisit(p){const i=this.order.slice().reverse();for(const r of i)p(this.flatRecord[r],this.flatRecord);return this}async visitAsync(p,i={}){const{parallelise:r}={parallelise:!0,...i},a=Y.YieldTracker.from(i),c=this.order;if(!r){for(const f of c){const h=p(this.flatRecord[f],this.flatRecord);UT(h)&&await h,await a.tick()}return this}const e=Math.random().toString(36).substring(7);this.onGoingVisits[e]={};for(const f of c){const h=this.getUpstreamOngoingDependenciesVisits(f,e);Object.keys(h).length&&await this.settlePromises(h,e);const m=p(this.flatRecord[f],this.flatRecord);UT(m)&&(this.onGoingVisits[e][f]=m),await a.tick()}return await this.settlePromises(this.onGoingVisits[e],e),this.onGoingVisits[e]={},this}async reverseVisitAsync(p,i={}){const{parallelise:r}={parallelise:!0,...i},a=Y.YieldTracker.from(i),c=this.order.slice().reverse();if(!r){for(const f of c){const h=p(this.flatRecord[f],this.flatRecord);UT(h)&&await h,await a.tick()}return this}const e=Math.random().toString(36).substring(7);this.onGoingVisits[e]={};for(const f of c){const h=this.getDownstreamOngoingDependenciesVisits(f,e);Object.keys(h).length&&await this.settlePromises(h,e);const m=p(this.flatRecord[f],this.flatRecord);UT(m)&&(this.onGoingVisits[e][f]=m),await a.tick()}return await this.settlePromises(this.onGoingVisits[e],e),this.onGoingVisits[e]={},this}}const gf={},sg={},yv={empty:!1,enrich:!0,mock:!1,ignoreCache:!1,onFetch:async()=>null,manuallyInit:!1};function yUe(s,p={enrich:!0,shallowErrors:!1},i){const r={enrich:!0,shallowErrors:!1,...p},{enrich:a,shallowErrors:c}=r,e=s.project,f=s.record,h=iD(s.project,{shallowErrors:c},i);h.instances[e.id]=h;const m=new Fn(e,{allBuiltInEntityIds:h.diggestedBuiltInBaseEntitiesIds}),E=new Set;f[e.id]=e,E.add(e.id);const b=B().toISOString();Object.values(f).forEach(_=>{!_||m.allBuiltInEntityIds.has(_.id)||E.add(_.id)}),m.order=Array.from(E),m.flatRecord=f,m.orderEntities();const A=a?h.addChangeSet(new S(h,x.sessionAuthor,b,h,!0,"project-init-from-fetch-result")):null;return m.visit(_=>{if(_.id===h.id)return;const P=Re(_,h);try{P.hydrateAncestors(),P.addSelfToProject(null);const V=oo(_);Object.keys(V.downstream).forEach(M=>{const G=h.get(M);G&&G.hydrateAncestors()})}catch(V){if(c)Y.Logger.error("Error hydrating ancestors: ",V);else throw V}}),a?(m.visit(_=>{if(_.id===h.id)return;const P=h.get(_.id);if(P)try{P.afterAllChildrenInitialized(A),P.captureVersion()}catch(V){if(c)Y.Logger.error("Error in afterAllChildrenInitialized: ",V);else throw V}}),h.afterAllChildrenInitialized(A),h.subscribe(),h.captureVersion()):(Uu(h,b).forEach(P=>{P.remove({ignoreUpstream:!0},null)}),m.visit(P=>{if(P.id===h.id)return;const V=h.get(P.id);V&&(V.initialized=!0,V.captureVersion())}),h.initialized=!0,h.subscribe(),h.captureVersion()),h.initialized=!0,h.emit(pi.PROJECT_INITIALIZED,h,A),A==null||A.attemptAutoclose("project-init-from-fetch-result",h.id),h}async function fPi(s,p={enrich:!0,shallowErrors:!1,yieldEvery:100},i){const r={enrich:!0,shallowErrors:!1,yieldEvery:100,...p},{enrich:a,shallowErrors:c,yieldEvery:e}=r,f=Y.YieldTracker.from({yieldEvery:e}),h=s.project,m=s.record,E=await rD(s.project,{shallowErrors:c,tracker:f},i);E.instances[h.id]=E;const b=new Fn(void 0,{allBuiltInEntityIds:E.diggestedBuiltInBaseEntitiesIds});await b.flattenAsync(h,{tracker:f}),await b.orderEntitiesAsync({tracker:f});const A=new Set;m[h.id]=h,A.add(h.id);const _=B().toISOString();for(const[V,M]of Object.entries(m))!M||b.allBuiltInEntityIds.has(M.id)||(A.add(M.id),await f.tick());b.order=Array.from(A),b.flatRecord=m,await b.orderEntitiesAsync({tracker:f});const P=a?E.addChangeSet(new S(E,x.sessionAuthor,_,E,!0,"project-init-from-fetch-result")):null;if(await b.visitAsync(V=>{if(V.id===E.id)return;const M=Re(V,E);try{M.hydrateAncestors(),M.addSelfToProject(null);const G=oo(V);Object.keys(G.downstream).forEach(k=>{const q=E.get(k);q&&q.hydrateAncestors()})}catch(G){if(c)Y.Logger.error("Error hydrating ancestors: ",G);else throw Y.Logger.log("Error hydrating ancestors: ",G),G}},{tracker:f}),a){try{await b.visitAsync(V=>{if(V.id===E.id)return;const M=E.get(V.id);M&&(M.afterAllChildrenInitialized(P),M.captureVersion())},{tracker:f})}catch(V){if(c)Y.Logger.error("Error in afterAllChildrenInitialized: ",V);else throw Y.Logger.log("Error in afterAllChildrenInitialized: ",V),V}E.afterAllChildrenInitialized(P),E.subscribe(),E.captureVersion()}else Uu(E,_).forEach(M=>{M.remove({ignoreUpstream:!0},null)}),await b.visitAsync(M=>{if(M.id===E.id)return;const G=E.get(M.id);G&&(G.initialized=!0,G.captureVersion())},{tracker:f}),E.initialized=!0,E.subscribe(),E.captureVersion();return E.initialized=!0,E.emit(pi.PROJECT_INITIALIZED,E,P),P==null||P.attemptAutoclose("project-init-from-fetch-result",E.id),E}async function yPi(s,p=yv){const i={...yv,...p};if(i.empty)return{data:{project:{id:s.id,workspaceId:"",deletable:!0,editable:!0,type:d.Project,version:x.UUID.uuid(),createdAt:B().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 a={...gB};return a.id=s.id,{data:{project:a,record:{}}}}return Y.Logger.log("Fetching project from external API"),new Promise(async a=>{try{if(i.onFetch){const c=await i.onFetch(s.id);if(c){a({data:c});return}}else a({data:null})}catch(c){Y.Logger.error("Error fetching project: ",c),a({data:null})}})}function iD(s,p={shallowErrors:!1},i){const r=new x(s,i);dUe(r),oUe(r),lUe(r),uUe(r),pUe(r),cUe(r),fUe(r);const a=p.allBuiltInIds??new Set([...r.getAllBuiltInIds(),...oD()]);return r.diggestedBuiltInBaseEntitiesIds=a,a.forEach(c=>{if(!r.builtInInstances[c]&&r.instances[c])r.builtInInstances[c]=r.instances[c],delete r.instances[c];else if(!r.builtInInstances[c]&&!p.shallowErrors)throw new Error(`Built in entity was not properly initialized: ${c}`)}),r.instances[r.id]=r,r.activeVersion=!0,r}async function rD(s,p={shallowErrors:!1},i){const r=Y.YieldTracker.from(p),a=new x(s,i);dUe(a),oUe(a),await Y.yieldToEventLoop(),lUe(a),await Y.yieldToEventLoop(),uUe(a),pUe(a),cUe(a),fUe(a),await Y.yieldToEventLoop();const c=p.allBuiltInIds??new Set([...a.getAllBuiltInIds(),...await dD()]);a.diggestedBuiltInBaseEntitiesIds=c;for(const e of c){if(!a.builtInInstances[e]&&a.instances[e])a.builtInInstances[e]=a.instances[e],delete a.instances[e];else if(!a.builtInInstances[e]&&!p.shallowErrors)throw new Error(`Built in entity was not properly initialized: ${e}`);a.instances[e]&&delete a.instances[e],await r.tick()}return a.instances[a.id]=a,a.activeVersion=!0,a}function Uu(s,p){return s.instancesList.filter(r=>B(r.createdAt).isAfter(B(p)||!!r.previousVersion))}function hPi(s,{enrich:p,shallowErrors:i,...r}={enrich:!0,shallowErrors:!1},a){var _,P;const c=new Map,e=new Map;Object.keys(s.instances).forEach(V=>{if(s.diggestedBuiltInBaseEntitiesIds.has(V)){c.set(V,V),e.set(V,V);return}const M=s.get(V);if(!mD(M,{...s.instances,...s.builtInInstances}).every(ne=>!s.diggestedBuiltInBaseEntitiesIds.has(ne))){c.set(V,V),e.set(V,V);return}const q=x.UUID.uuid();c.set(V,q),e.set(q,V)});const f=((_=r.resetVersionOptions)==null?void 0:_.commonTimestamp)??B().toISOString(),h=s.toShallowJSON({seenEntityMaps:c});h.previousVersion=null,h.createdAt=f,h.version=x.UUID.uuid(),h.author=((P=r.resetVersionOptions)==null?void 0:P.author)??(x.sessionAuthor||"1");const m=iD(h,{shallowErrors:i,allBuiltInIds:s.diggestedBuiltInBaseEntitiesIds},a);m.instances[m.id]=m;const E=p?m.addChangeSet(new S(m,x.sessionAuthor,f,m,!0,"project-clone")):null,b=new Fn(s,{allBuiltInEntityIds:s.diggestedBuiltInBaseEntitiesIds}),A=_L(b.flatRecord,c);return b.visit(V=>{var q;const M=V.toShallowJSON({seenEntityMaps:c});M.previousVersion=null,M.createdAt=f,M.version=x.UUID.uuid(),M.author=((q=r.resetVersionOptions)==null?void 0:q.author)??(x.sessionAuthor||"1");const G=oo(M,A);if(Object.keys(G.upstream).length){let ne=!1;if(Object.keys(G.upstream).forEach(J=>{if(!ne&&(!m.get(J)||m.getDeleted(J))){ne=!0;return}}),ne)return}const k=Re(M,m);k.hydrateAncestors(),k.addSelfToProject(E),E==null||E.add(k,W.Added),r.onVisit&&r.onVisit(M)}),p?(b.visit(V=>{if(V.id===m.id)return;const M=m.get(c.get(V.id));M&&(M.afterAllChildrenInitialized(E),M.captureVersion())}),m.afterAllChildrenInitialized(E),m.subscribe(),m.captureVersion()):(Uu(m,f).forEach(M=>{M.remove({ignoreUpstream:!0},null)}),b.visit(M=>{if(M.id===m.id)return;const G=m.get(M.id);G&&(G.initialized=!0,G.captureVersion())}),m.initialized=!0,m.subscribe(),m.captureVersion()),m.instancesList.forEach(V=>{V.previousVersion=null}),E==null||E.attemptAutoclose("project-clone",m.id),{project:m,maps:c}}async function mPi(s,{shallowErrors:p,...i}={shallowErrors:!1,yieldEvery:100}){var m,E;const r=Y.YieldTracker.from(i),a=new Map,c=new Map;Object.keys(s.instances).forEach(b=>{if(s.diggestedBuiltInBaseEntitiesIds.has(b)){a.set(b,b),c.set(b,b);return}const A=x.UUID.uuid();a.set(b,A),c.set(A,b)});const e=((m=i.resetVersionOptions)==null?void 0:m.commonTimestamp)??B().toISOString(),f=s.toShallowJSON({seenEntityMaps:a});f.previousVersion=null,f.createdAt=e,f.version=x.UUID.uuid(),f.author=((E=i.resetVersionOptions)==null?void 0:E.author)??(x.sessionAuthor||"1");const h=await s.toFullProjectTransferAsync({tracker:r,seenEntityMaps:a,resetVersionOptions:i.resetVersionOptions,onVisit:i.onVisit});return{project:f,record:h.record,order:h.order,maps:a}}async function TPi(s,{enrich:p,shallowErrors:i,...r}={enrich:!0,shallowErrors:!1,yieldEvery:100},a){var P,V;const c=Y.YieldTracker.from(r),e=new Map,f=new Map;for(const M of Object.keys(s.instances)){if(s.diggestedBuiltInBaseEntitiesIds.has(M)){e.set(M,M),f.set(M,M),await c.tick();continue}const G=x.UUID.uuid();e.set(M,G),f.set(G,M),await c.tick()}const h=((P=r.resetVersionOptions)==null?void 0:P.commonTimestamp)??B().toISOString(),m=s.toShallowJSON({seenEntityMaps:e});m.previousVersion=null,m.createdAt=h,m.version=x.UUID.uuid(),m.author=((V=r.resetVersionOptions)==null?void 0:V.author)??(x.sessionAuthor||"1");const E=await rD(m,{shallowErrors:i,tracker:c},a);E.diggestedBuiltInBaseEntitiesIds=s.diggestedBuiltInBaseEntitiesIds,E.instances[E.id]=E;const b=p?E.addChangeSet(new S(E,x.sessionAuthor,h,E,!0,"project-clone")):null,A=new Fn(void 0,{allBuiltInEntityIds:s.diggestedBuiltInBaseEntitiesIds}),_=await s.toFullProjectTransferAsync({tracker:c,seenEntityMaps:e,resetVersionOptions:r.resetVersionOptions,onVisit:r.onVisit,shallowErrors:i});A.flatRecord=_.record,A.order=_.order,await A.visitAsync(M=>{var ne;if(s.diggestedBuiltInBaseEntitiesIds.has(M.id))return;const G=M;G.previousVersion=null,G.createdAt=h,G.version=x.UUID.uuid(),G.author=((ne=r.resetVersionOptions)==null?void 0:ne.author)??(x.sessionAuthor||"1");const k=oo(G,A.flatRecord);if(Object.keys(k.upstream).length){let J=!1;if(Object.keys(k.upstream).forEach(se=>{if(!J&&(!E.get(se)||E.getDeleted(se))){J=!0;return}}),J)return}const q=Re(G,E);q.hydrateAncestors(),q.addSelfToProject(b),b==null||b.add(q,W.Added)},{tracker:c}),p?(await A.visitAsync(M=>{if(M.id===E.id||s.diggestedBuiltInBaseEntitiesIds.has(M.id))return;const G=E.get(e.get(M.id));G&&(G.afterAllChildrenInitialized(b),G.captureVersion())},{tracker:c}),E.afterAllChildrenInitialized(b),E.subscribe(),E.captureVersion()):(Uu(E,h).forEach(G=>{G.remove({ignoreUpstream:!0},null)}),await A.visitAsync(G=>{if(G.id===E.id)return;const k=E.get(G.id);k&&(k.initialized=!0,k.captureVersion())},{tracker:c}),E.initialized=!0,E.subscribe(),E.captureVersion());for(const M of E.instancesList)M.previousVersion=null,await c.tick();return b==null||b.attemptAutoclose("project-clone",E.id),{project:E,maps:e}}function vPi(s,p,i=p.addChangeSet(new S(p,x.sessionAuthor,B().toISOString(),p,!0,w.AfterAllChildrenInitialized)),{enrich:r,shallowErrors:a,...c}={shallowErrors:!1,enrich:!0}){var A,_;const e=new Map,f=new Map;Object.keys(s.instances).forEach(P=>{if(s.diggestedBuiltInBaseEntitiesIds.has(P)){e.set(P,P),f.set(P,P);return}if(P===s.id){e.set(P,p.id),f.set(p.id,P);return}const V=s.get(P);if(!mD(V,{...s.instances,...s.builtInInstances}).every(q=>!s.diggestedBuiltInBaseEntitiesIds.has(q))){e.set(P,P),f.set(P,P);return}const k=x.UUID.uuid();e.set(P,k),f.set(k,P)});const h=((A=c.resetVersionOptions)==null?void 0:A.commonTimestamp)??B().toISOString(),m=s.toShallowJSON({seenEntityMaps:e});m.previousVersion=null,m.createdAt=h,m.version=x.UUID.uuid(),m.author=((_=c.resetVersionOptions)==null?void 0:_.author)??(x.sessionAuthor||"1");const E=new Fn(s,{allBuiltInEntityIds:s.diggestedBuiltInBaseEntitiesIds}),b=_L(E.flatRecord,e);return E.visit(P=>{var G;if(P.id===p.id)return;const V=P.toShallowJSON({seenEntityMaps:e});V.previousVersion=null,V.createdAt=h,V.version=x.UUID.uuid(),V.author=((G=c.resetVersionOptions)==null?void 0:G.author)??(x.sessionAuthor||"1");const M=oo(V,b);if(Object.keys(M.upstream).length){let k=!1;if(Object.keys(M.upstream).forEach(q=>{if(!k&&(!p.get(q)||p.getDeleted(q))){k=!0;return}}),k)return}try{const k=Re(V,p);k.hydrateAncestors(),k.addSelfToProject(i),i==null||i.add(k,W.Added),c.onVisit&&c.onVisit(V)}catch(k){if(a)Y.Logger.error("Error cloning entity onto existing project: ",k);else throw Y.Logger.log("Error cloning entity onto existing project: ",k),k}}),r?(E.visit(P=>{if(P.id===p.id)return;const V=p.get(e.get(P.id));V&&(V.afterAllChildrenInitialized(i),V.previousVersion=null,V.captureVersion())}),p.afterAllChildrenInitialized(i),p.subscribe(),p.captureVersion()):(Uu(p,h).forEach(V=>{V.remove({ignoreUpstream:!0},null)}),E.visit(V=>{if(V.id===p.id)return;const M=p.get(V.id);M&&(M.initialized=!0,M.previousVersion=null,M.captureVersion())}),p.initialized=!0,p.subscribe(),p.captureVersion()),p.afterAllChildrenInitialized(i),p.captureVersion(),{project:p,maps:e,changeSet:i}}async function EPi(s,p,i=p.addChangeSet(new S(p,x.sessionAuthor,B().toISOString(),p,!0,w.AfterAllChildrenInitialized)),{enrich:r,shallowErrors:a,...c}={enrich:!0,shallowErrors:!1,yieldEvery:100}){var _,P;const e=Y.YieldTracker.from(c),f=new Map,h=new Map;for(const V of Object.keys(s.instances)){if(s.diggestedBuiltInBaseEntitiesIds.has(V)){f.set(V,V),h.set(V,V),await e.tick();continue}if(V===s.id){f.set(V,p.id),h.set(p.id,V),await e.tick();continue}const M=x.UUID.uuid();f.set(V,M),h.set(M,V),await e.tick()}const m=((_=c.resetVersionOptions)==null?void 0:_.commonTimestamp)??B().toISOString(),E=s.toShallowJSON({seenEntityMaps:f});E.previousVersion=null,E.createdAt=m,E.version=x.UUID.uuid(),E.author=((P=c.resetVersionOptions)==null?void 0:P.author)??(x.sessionAuthor||"1"),p.diggestedBuiltInBaseEntitiesIds=s.diggestedBuiltInBaseEntitiesIds;const b=new Fn(void 0,{allBuiltInEntityIds:s.diggestedBuiltInBaseEntitiesIds}),A=await s.toFullProjectTransferAsync({tracker:e,seenEntityMaps:f,resetVersionOptions:c.resetVersionOptions,onVisit:c.onVisit,shallowErrors:a});return b.flatRecord=A.record,b.order=A.order,await b.visitAsync(V=>{var k;if(s.diggestedBuiltInBaseEntitiesIds.has(V.id)||V.id===p.id)return;const M=V;M.previousVersion=null,M.createdAt=m,M.version=x.UUID.uuid(),M.author=((k=c.resetVersionOptions)==null?void 0:k.author)??(x.sessionAuthor||"1");const G=oo(M,b.flatRecord);if(Object.keys(G.upstream).length){let q=!1;if(Object.keys(G.upstream).forEach(ne=>{if(!q&&(!p.get(ne)||p.getDeleted(ne))){q=!0;return}}),q)return}try{const q=Re(M,p);q.hydrateAncestors(),q.addSelfToProject(i),i==null||i.add(q,W.Added)}catch(q){if(a)Y.Logger.error("Error cloning entity onto existing project: ",q);else throw Y.Logger.log("Error cloning entity onto existing project: ",q),q}},{tracker:e}),r?(await b.visitAsync(V=>{if(V.id===p.id||s.diggestedBuiltInBaseEntitiesIds.has(V.id))return;const M=p.get(f.get(V.id));M&&(M.afterAllChildrenInitialized(i),M.previousVersion=null,M.captureVersion())},{tracker:e}),p.afterAllChildrenInitialized(i),p.subscribe(),p.captureVersion()):(Uu(p,m).forEach(M=>{M.remove({ignoreUpstream:!0},null)}),await b.visitAsync(M=>{if(M.id===p.id)return;const G=p.get(M.id);G&&(G.initialized=!0,G.previousVersion=null,G.captureVersion())},{tracker:e}),p.initialized=!0,p.subscribe(),p.captureVersion()),p.afterAllChildrenInitialized(i),p.captureVersion(),{project:p,maps:f,changeSet:i}}function hUe(s,{enrich:p,shallowErrors:i}={enrich:!0,shallowErrors:!1},r){const a=iD(s,{shallowErrors:i},r);a.activeVersion=!0;const c=B().toISOString(),e=p?a.addChangeSet(new S(a,x.sessionAuthor,c,a,!0,"project-init")):null;e&&(e.type=y1.Automatic);const f=new Fn(s,{allBuiltInEntityIds:a.diggestedBuiltInBaseEntitiesIds});return f.visit(h=>{const m=Re(h,a);m.hydrateAncestors(),m.addSelfToProject(e)}),p?(f.visit(h=>{if(h.id===a.id)return;const m=a.get(h.id);m&&(m.afterAllChildrenInitialized(e),m.captureVersion())}),a.afterAllChildrenInitialized(e),a.subscribe(),a.captureVersion()):(Uu(a,c).forEach(m=>{m.remove({ignoreUpstream:!0},null)}),f.visit(m=>{if(m.id===a.id)return;const E=a.get(m.id);E&&(E.initialized=!0,E.captureVersion())}),a.initialized=!0,a.subscribe(),a.captureVersion()),a.initialized=!0,a.emit(pi.PROJECT_INITIALIZED,a,e),e==null||e.attemptAutoclose("project-init",a.id),a}async function bPi(s,{enrich:p,shallowErrors:i,yieldEvery:r}={enrich:!0,shallowErrors:!1,yieldEvery:100},a){const c=Y.YieldTracker.from({yieldEvery:r}),e=await rD(s,{shallowErrors:i,tracker:c},a),f=B().toISOString(),h=p?e.addChangeSet(new S(e,x.sessionAuthor,f,e,!0,"project-init")):null;h&&(h.type=y1.Automatic);const m=new Fn(void 0,{allBuiltInEntityIds:e.diggestedBuiltInBaseEntitiesIds});return await m.flattenAsync(s,{tracker:c}),await m.orderEntitiesAsync({tracker:c}),await m.visitAsync(E=>{const b=Re(E,e);b.hydrateAncestors(),b.addSelfToProject(h)},{tracker:c}),p?(await m.visitAsync(E=>{if(E.id===e.id)return;const b=e.get(E.id);b&&(b.afterAllChildrenInitialized(h),b.captureVersion())},{tracker:c}),e.afterAllChildrenInitialized(h),e.subscribe(),e.captureVersion()):(Uu(e,f).forEach(b=>{b.remove({ignoreUpstream:!0},null)}),await m.visitAsync(b=>{if(b.id===e.id)return;const A=e.get(b.id);A&&(A.initialized=!0,A.captureVersion())},{tracker:c}),e.initialized=!0,e.subscribe(),e.captureVersion()),e.initialized=!0,e.emit(pi.PROJECT_INITIALIZED,e,h),h==null||h.attemptAutoclose("project-init",e.id),e}async function APi(s,p=yv,i){const r={...yv,...p};if(s.id&&gf[s.id]&&!r.ignoreCache)return gf[s.id];if(s.id&&sg[s.id]&&!r.ignoreCache)return await sg[s.id],gf[s.id];const a=yPi(s,r);s.id&&(sg[s.id]=a);const c=await a;if(c.data){let e;return r.mock?e=hUe(gB,{enrich:!!r.enrich},i):c.data instanceof x?e=c.data:e=yUe(c.data,{enrich:!!r.enrich},i),gf[s.id]=e,s.id&&delete sg[s.id],e}return null}function gPi(s){return gf[s.id]&&delete gf[s.id],null}const hv=vt([He(),Va(),Tr(),au()]),mUe=Mm([ln.CurrentDateAndTime,ln.Random,ln.Unique]),nD=st({type:mUe,rangeStart:hv.nullable(),rangeEnd:hv.nullable()}),XE=nD.extend({type:nt(ln.Random),rangeStart:hv,rangeEnd:hv}),TUe=nD.extend({type:nt(ln.Unique),rangeStart:ms(),rangeEnd:ms()}),vUe=nD.extend({type:nt(ln.CurrentDateAndTime),rangeStart:ms(),rangeEnd:ms()}),aD=XE.extend({rangeStart:Va().nullable(),rangeEnd:Va().nullable()}),EUe=aD.extend({rangeStart:Va(),rangeEnd:ms()}),bUe=aD.extend({rangeStart:ms(),rangeEnd:Va()}),AUe=aD.extend({rangeStart:Va(),rangeEnd:Va()}),sD=XE.extend({rangeStart:Va().nullable(),rangeEnd:Va().nullable()}),gUe=sD.extend({rangeStart:Va(),rangeEnd:ms()}),IUe=sD.extend({rangeStart:ms(),rangeEnd:Va()}),RUe=sD.extend({rangeStart:Va(),rangeEnd:Va()}),lD=XE.extend({rangeStart:au().nullable(),rangeEnd:au().nullable()}),DUe=lD.extend({rangeStart:au(),rangeEnd:ms()}),wUe=lD.extend({rangeStart:ms(),rangeEnd:au()}),CUe=lD.extend({rangeStart:au(),rangeEnd:au()}),OUe=XE.extend({rangeStart:ms(),rangeEnd:ms()}),_Ue=vt([gUe,IUe,RUe]),VUe=vt([EUe,bUe,AUe]),PUe=vt([DUe,wUe,CUe,vUe]),IPi=vt([_Ue,VUe,PUe,TUe,OUe]);function oD(){const s=new Set;return new Set(Rx.flatMap(i=>Ue(i,s)).map(i=>i.id))}function Fo(s){return[...s.calledByEntry||[],...s.calledByError||[],...s.calledBySuccess||[]].filter(p=>p.type!==d.GenericReference)}function NUe(s,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(s.id))return[];if(p.add(s.id),s.type!==d.ActionDescriptor)throw new Error("Entity must be an action descriptor to be flattened");return[s,...s.inputs.flatMap(r=>Ue(r,p,i)),...s.dataType?Ue(s.dataType,p,i):[],...s.error?Ue(s.error,p,i):[],...s.parent?Ue(s.parent,p,i):[]]}function xUe(s,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(s.id))return[];if(p.add(s.id),s.type!==d.ArgumentDeclaration)throw new Error("Entity must be an argument declaration to be flattened");return[s,...s.defaultValue?Ue(s.defaultValue,p):[],...s.writesValues.flatMap(r=>Ue(r,p,i)),...s.implements.flatMap(r=>Ue(r,p,i)),...s.dataType?Ue(s.dataType,p,i):[],...s.parent?Ue(s.parent,p,i):[]]}function $Ue(s,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(s.id))return[];if(p.add(s.id),s.type!==d.BreakStatement)throw new Error("Entity must be a break statement to be flattened");return[s,...s.outputs.flatMap(r=>Ue(r,p,i)),...s.throws?Ue(s.throws,p,i):[],...s.dataType?Ue(s.dataType,p,i):[],...s.readsValue?Ue(s.readsValue,p,i):[],...(Fo(s)||[]).flatMap(r=>Ue(r,p,i)),...s.parent?Ue(s.parent,p,i):[]]}function LUe(s,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(s.id))return[];if(p.add(s.id),s.type!==d.BuiltInBaseEntity)throw new Error("Entity must be a built-in base entity to be flattened");return[s,...(s.properties||[]).flatMap(r=>Ue(r,p,i)),...(s.methods||[]).flatMap(r=>Ue(r,p,i)),...(s.abstractMethods||[]).flatMap(r=>Ue(r,p,i)),...s.allPropertiesImplement?Ue(s.allPropertiesImplement,p,i):[],...s.additionalPropertiesDataType?Ue(s.additionalPropertiesDataType,p,i):[],...s.extends?Ue(s.extends,p,i):[]]}function BUe(s,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(s.id))return[];if(p.add(s.id),s.type!==d.Condition)throw new Error("Entity must be a condition to be flattened");return[s,...(s.andChildrenGroup||[]).flatMap(r=>Ue(r,p,i)),...(s.orChildrenGroup||[]).flatMap(r=>Ue(r,p,i)),...(s.inputs||[]).flatMap(r=>Ue(r,p,i)),...(s.successCalls||[]).flatMap(r=>Ue(r,p,i)),...(s.errorCalls||[]).flatMap(r=>Ue(r,p,i)),...(Fo(s)||[]).flatMap(r=>Ue(r,p,i)),...s.parent?Ue(s.parent,p,i):[]]}function MUe(s,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(s.id))return[];if(p.add(s.id),s.type!==d.ContinueStatement)throw new Error("Entity must be a continue statement to be flattened");return[s,...s.outputs.flatMap(r=>Ue(r,p,i)),...s.readsValue?Ue(s.readsValue,p,i):[],...s.throws?Ue(s.throws,p,i):[],...s.dataType?Ue(s.dataType,p,i):[],...(Fo(s)||[]).flatMap(r=>Ue(r,p,i)),...s.parent?Ue(s.parent,p,i):[]]}function GUe(s,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(s.id))return[];if(p.add(s.id),s.type!==d.DefinitionEntity)throw new Error("Entity must be a definition entity to be flattened");return[s,...s.extends?Ue(s.extends,p,i):[],...(s.implements||[]).flatMap(r=>Ue(r,p,i)),...(s.properties||[]).flatMap(r=>Ue(r,p,i)),...(s.methods||[]).flatMap(r=>Ue(r,p,i)),...(s.abstractMethods||[]).flatMap(r=>Ue(r,p,i)),...s.allPropertiesImplement?Ue(s.allPropertiesImplement,p,i):[],...s.additionalPropertiesDataType?Ue(s.additionalPropertiesDataType,p,i):[],...s.parent?Ue(s.parent,p,i):[]]}function kUe(s,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(s.id))return[];if(p.add(s.id),s.type!==d.DataType)throw new Error("Entity must be a data type to be flattened");return[s,...(s.andChildrenGroup||[]).flatMap(r=>Ue(r,p,i)),...(s.orChildrenGroup||[]).flatMap(r=>Ue(r,p,i)),...s.entity?Ue(s.entity,p,i):[],...s.foreignKeyRef?Ue(s.foreignKeyRef,p,i):[],...s.parent?Ue(s.parent,p,i):[]]}function jUe(s,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(s.id))return[];if(p.add(s.id),s.type!==d.FunctionCall)throw new Error("Entity must be a function call to be flattened");return[s,...(s.inputs||[]).flatMap(r=>Ue(r,p,i)),...(s.outputs||[]).flatMap(r=>Ue(r,p,i)),...s.error?Ue(s.error,p,i):[],...(Fo(s)||[]).flatMap(r=>Ue(r,p,i)),...(s.successCalls||[]).flatMap(r=>Ue(r,p,i)),...(s.errorCalls||[]).flatMap(r=>Ue(r,p,i)),...(s.writesValues||[]).flatMap(r=>Ue(r,p,i)),...s.parent?Ue(s.parent,p,i):[]]}function UUe(s,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(s.id))return[];if(p.add(s.id),s.type!==d.FunctionDeclaration)throw new Error("Entity must be a function declaration to be flattened");return[s,...(s.inputs||[]).flatMap(r=>Ue(r,p,i)),...(s.calls||[]).flatMap(r=>Ue(r,p,i)),...s.dataType?Ue(s.dataType,p,i):[],...s.implements?Ue(s.implements,p,i):[],...s.parent?Ue(s.parent,p,i):[]]}function FUe(s,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(s.id))return[];if(p.add(s.id),s.type!==d.GlobalEvent)throw new Error("Entity must be a global event to be flattened");return[s,...(s.inputs||[]).flatMap(r=>Ue(r,p,i)),...(s.calls||[]).flatMap(r=>Ue(r,p,i)),...s.implements?Ue(s.implements,p,i):[],...s.parent?Ue(s.parent,p,i):[]]}function KUe(s,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(s.id))return[];if(p.add(s.id),s.type!==d.InputMap)throw new Error("Entity must be an input map to be flattened");return[s,...s.readsValue?Ue(s.readsValue,p,i):[],...s.declaration?Ue(s.declaration,p,i):[],...s.defaultValue?Ue(s.defaultValue,p,i):[],...s.parent?Ue(s.parent,p,i):[]]}function qUe(s,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(s.id))return[];if(p.add(s.id),s.type!==d.InstalledProject)throw new Error("Entity must be an installed project to be flattened");return[s,...(s.functions||[]).flatMap(r=>Ue(r,p,i)),...(s.events||[]).flatMap(r=>Ue(r,p,i)),...s.parent?Ue(s.parent,p,i):[]]}function SUe(s,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(s.id))return[];if(p.add(s.id),s.type!==d.InternalCall)throw new Error("Entity must be an internal call to be flattened");return[s,...(s.successCalls||[]).flatMap(r=>Ue(r,p,i)),...(s.errorCalls||[]).flatMap(r=>Ue(r,p,i)),...(s.inputs||[]).flatMap(r=>Ue(r,p,i)),...(s.outputs||[]).flatMap(r=>Ue(r,p,i)),...(Fo(s)||[]).flatMap(r=>Ue(r,p,i)),...s.error?Ue(s.error,p,i):[],...(s.writesValues||[]).flatMap(r=>Ue(r,p,i)),...s.parent?Ue(s.parent,p,i):[]]}function ZUe(s,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(s.id))return[];if(p.add(s.id),s.type!==d.LiteralValue)throw new Error("Entity must be a literal value to be flattened");return[s,...s.valueAsTypeSingle?Ue(s.valueAsTypeSingle,p,i):[],...s.valueAsTypeList&&Array.isArray(s.valueAsTypeList)?s.valueAsTypeList.flatMap(r=>Ue(r,p,i)):[],...s.parent?Ue(s.parent,p,i):[]]}function HUe(s,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(s.id))return[];if(p.add(s.id),s.type!==d.Loop)throw new Error("Entity must be a loop to be flattened");return[s,...(s.inputs||[]).flatMap(r=>Ue(r,p,i)),...(s.outputs||[]).flatMap(r=>Ue(r,p,i)),...(s.successCalls||[]).flatMap(r=>Ue(r,p,i)),...(s.errorCalls||[]).flatMap(r=>Ue(r,p,i)),...s.error?Ue(s.error,p,i):[],...s.dataType?Ue(s.dataType,p,i):[],...s.body?Ue(s.body,p,i):[],...(Fo(s)||[]).flatMap(r=>Ue(r,p,i)),...(s.writesValues||[]).flatMap(r=>Ue(r,p,i)),...s.parent?Ue(s.parent,p,i):[]]}function WUe(s,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(s.id))return[];if(p.add(s.id),s.type!==d.Operation)throw new Error("Entity must be an operation to be flattened");return[s,...(s.successCalls||[]).flatMap(r=>Ue(r,p,i)),...(s.errorCalls||[]).flatMap(r=>Ue(r,p,i)),...(s.inputs||[]).flatMap(r=>Ue(r,p,i)),...(s.outputs||[]).flatMap(r=>Ue(r,p,i)),...(s.writesValues||[]).flatMap(r=>Ue(r,p,i)),...s.error?Ue(s.error,p,i):[],...(Fo(s)||[]).flatMap(r=>Ue(r,p,i)),...s.parent?Ue(s.parent,p,i):[]]}function zUe(s,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(s.id))return[];if(p.add(s.id),s.type!==d.OutputMap)throw new Error("Entity must be an output map to be flattened");return[s,...(s.writesValues||[]).flatMap(r=>Ue(r,p,i)),...s.declaration?Ue(s.declaration,p,i):[],...s.parent?Ue(s.parent,p,i):[]]}function YUe(s,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(s.id))return[];if(p.add(s.id),s.type!==d.PrimitiveEntity)throw new Error("Entity must be a primitive entity to be flattened");return[s,...(s.properties||[]).flatMap(r=>Ue(r,p,i)),...(s.methods||[]).flatMap(r=>Ue(r,p,i)),...(s.abstractMethods||[]).flatMap(r=>Ue(r,p,i))]}function JUe(s,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(s.id))return[];if(p.add(s.id),s.type!==d.Project)throw new Error("Entity must be a project to be flattened");return[s,...(s.entities||[]).flatMap(r=>Ue(r,p,i)),...(s.functions||[]).flatMap(r=>Ue(r,p,i)),...(s.events||[]).flatMap(r=>Ue(r,p,i)),...(s.projects||[]).flatMap(r=>Ue(r,p,i)),...(s.variableDeclarations||[]).flatMap(r=>Ue(r,p,i)),...(s.variableInstances||[]).flatMap(r=>Ue(r,p,i)),...(s.operations||[]).flatMap(r=>Ue(r,p,i)),...(s.conditions||[]).flatMap(r=>Ue(r,p,i)),...(s.functionCalls||[]).flatMap(r=>Ue(r,p,i)),...(s.projects||[]).flatMap(r=>Ue(r,p,i)),...(s.loops||[]).flatMap(r=>Ue(r,p,i)),...(s.searches||[]).flatMap(r=>Ue(r,p,i))]}function QUe(s,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(s.id))return[];if(p.add(s.id),s.type!==d.Property)throw new Error("Entity must be a property to be flattened");return[s,...s.defaultValue?Ue(s.defaultValue,p,i):[],...s.dataType?Ue(s.dataType,p,i):[],...s.parent?Ue(s.parent,p,i):[]]}function XUe(s,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(s.id))return[];if(p.add(s.id),s.type!==d.ReturnStatement)throw new Error("Entity must be a return statement to be flattened");return[s,...(s.outputs||[]).flatMap(r=>Ue(r,p,i)),...s.throws?Ue(s.throws,p,i):[],...s.readsValue?Ue(s.readsValue,p,i):[],...s.dataType?Ue(s.dataType,p,i):[],...(Fo(s)||[]).flatMap(r=>Ue(r,p,i)),...s.parent?Ue(s.parent,p,i):[]]}function eFe(s,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(s.id))return[];if(p.add(s.id),s.type!==d.Search)throw new Error("Entity must be a search to be flattened");return[s,...(s.successCalls||[]).flatMap(r=>Ue(r,p,i)),...(s.errorCalls||[]).flatMap(r=>Ue(r,p,i)),...(s.inputsDeclarations||[]).flatMap(r=>Ue(r,p,i)),...(s.inputs||[]).flatMap(r=>Ue(r,p,i)),...(s.writesValues||[]).flatMap(r=>Ue(r,p,i)),...(s.outputs||[]).flatMap(r=>Ue(r,p,i)),...s.error?Ue(s.error,p,i):[],...s.dataType?Ue(s.dataType,p,i):[],...(Fo(s)||[]).flatMap(r=>Ue(r,p,i)),...s.parent?Ue(s.parent,p,i):[]]}function tFe(s,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(s.id))return[];if(p.add(s.id),s.type!==d.ValueDescriptor)throw new Error("Entity must be a value descriptor to be flattened");return[s,...s.defaultValue?Ue(s.defaultValue,p,i):[],...s.dataType?Ue(s.dataType,p,i):[],...s.parent?Ue(s.parent,p,i):[]]}function iFe(s,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(s.id))return[];if(p.add(s.id),s.type!==d.VariableDeclaration)throw new Error("Entity must be a variable declaration to be flattened");return[s,...(s.successCalls||[]).flatMap(r=>Ue(r,p,i)),...(s.errorCalls||[]).flatMap(r=>Ue(r,p,i)),...(s.inputs||[]).flatMap(r=>Ue(r,p,i)),...(s.outputs||[]).flatMap(r=>Ue(r,p,i)),...(s.internalCalls||[]).flatMap(r=>Ue(r,p,i)),...(s.writesValues||[]).flatMap(r=>Ue(r,p,i)),...s.readsValue?Ue(s.readsValue,p,i):[],...s.defaultValue?Ue(s.defaultValue,p,i):[],...(Fo(s)||[]).flatMap(r=>Ue(r,p,i)),...s.dataType?Ue(s.dataType,p,i):[],...s.parent?Ue(s.parent,p,i):[]]}function rFe(s,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(s.id))return[];if(p.add(s.id),s.type!==d.VariableInstance)throw new Error("Entity must be a variable instance to be flattened");return[s,...(s.successCalls||[]).flatMap(r=>Ue(r,p,i)),...(s.errorCalls||[]).flatMap(r=>Ue(r,p,i)),...(s.inputs||[]).flatMap(r=>Ue(r,p,i)),...(s.outputs||[]).flatMap(r=>Ue(r,p,i)),...(s.internalCalls||[]).flatMap(r=>Ue(r,p,i)),...(s.writesValues||[]).flatMap(r=>Ue(r,p,i)),...s.readsValue?Ue(s.readsValue,p,i):[],...s.defaultValue?Ue(s.defaultValue,p,i):[],...(Fo(s)||[]).flatMap(r=>Ue(r,p,i)),...s.declaration?Ue(s.declaration,p,i):[],...s.parent?Ue(s.parent,p,i):[]]}function Ue(s,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(!s)throw new Error("Entity must be defined to be flattened");if(s.type===d.GenericReference)return[];const r=i.ignoreBuiltInBaseEntities?i.diggestedBuiltInBaseEntitiesIds??new Set(oD()):new Set;if(i.diggestedBuiltInBaseEntitiesIds=r,i.ignoreBuiltInBaseEntities&&(ma.includes(s.type)||r.has(s.id)))return[];if(p.has(s.id))return[];switch(s.type){case d.FunctionCall:return jUe(s,p,i);case d.Operation:return WUe(s,p,i);case d.Condition:return BUe(s,p,i);case d.Loop:return HUe(s,p,i);case d.Search:return eFe(s,p,i);case d.GlobalEvent:return FUe(s,p,i);case d.ReturnStatement:return XUe(s,p,i);case d.ContinueStatement:return MUe(s,p,i);case d.BreakStatement:return $Ue(s,p,i);case d.VariableDeclaration:return iFe(s,p,i);case d.DefinitionEntity:return GUe(s,p,i);case d.FunctionDeclaration:return UUe(s,p,i);case d.Project:return JUe(s,p,i);case d.ActionDescriptor:return NUe(s,p,i);case d.ArgumentDeclaration:return xUe(s,p,i);case d.ValueDescriptor:return tFe(s,p,i);case d.InputMap:return KUe(s,p,i);case d.OutputMap:return zUe(s,p,i);case d.DataType:return kUe(s,p,i);case d.InstalledProject:return qUe(s,p,i);case d.InternalCall:return SUe(s,p,i);case d.LiteralValue:return ZUe(s,p,i);case d.Property:return QUe(s,p,i);case d.VariableInstance:return rFe(s,p,i);case d.BuiltInBaseEntity:return i.ignoreBuiltInBaseEntities?[]:LUe(s,p,i);case d.PrimitiveEntity:return i.ignoreBuiltInBaseEntities?[]:YUe(s,p,i)}return[]}async function dD(s={}){const p=new Set,i=Y.YieldTracker.from(s),r=new Set;for(const a of Rx){const c=await je(a,p,{ignoreBuiltInBaseEntities:!1,tracker:i});for(const e of c)r.add(e.id),await i.tick()}return r}function Ko(s){return[...s.calledByEntry||[],...s.calledByError||[],...s.calledBySuccess||[]].filter(p=>p.type!==d.GenericReference)}async function nFe(s,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(s.id))return[];if(p.add(s.id),s.type!==d.ActionDescriptor)throw new Error("Entity must be an action descriptor to be flattened");const r=Y.YieldTracker.from(i),a=[s];await r.tick();const c={...i,tracker:r};delete c.yieldEvery;for(const e of s.inputs)a.push(...await je(e,p,c));return s.dataType&&a.push(...await je(s.dataType,p,c)),s.error&&a.push(...await je(s.error,p,c)),s.parent&&a.push(...await je(s.parent,p,c)),a}async function aFe(s,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(s.id))return[];if(p.add(s.id),s.type!==d.ArgumentDeclaration)throw new Error("Entity must be an argument declaration to be flattened");const r=Y.YieldTracker.from(i),a=[s];await r.tick();const c={...i,tracker:r};delete c.yieldEvery,s.dataType&&a.push(...await je(s.dataType,p,c)),s.parent&&a.push(...await je(s.parent,p,c)),s.defaultValue&&a.push(...await je(s.defaultValue,p,c));for(const e of s.writesValues||[])a.push(...await je(e,p,c));for(const e of s.implements||[])a.push(...await je(e,p,c));return a}async function sFe(s,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(s.id))return[];if(p.add(s.id),s.type!==d.BreakStatement)throw new Error("Entity must be a break statement to be flattened");const r=Y.YieldTracker.from(i),a=[s];await r.tick();const c={...i,tracker:r};delete c.yieldEvery;for(const f of s.outputs)a.push(...await je(f,p,c));s.parent&&a.push(...await je(s.parent,p,c)),s.throws&&a.push(...await je(s.throws,p,c)),s.dataType&&a.push(...await je(s.dataType,p,c)),s.readsValue&&a.push(...await je(s.readsValue,p,c));const e=Ko(s);for(const f of e)a.push(...await je(f,p,c));return a}async function lFe(s,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(s.id))return[];if(p.add(s.id),s.type!==d.BuiltInBaseEntity)throw new Error("Entity must be a built-in base entity to be flattened");const r=Y.YieldTracker.from(i),a=[s];await r.tick();const c={...i,tracker:r};delete c.yieldEvery;for(const e of s.properties||[])a.push(...await je(e,p,c));for(const e of s.methods||[])a.push(...await je(e,p,c));for(const e of s.abstractMethods||[])a.push(...await je(e,p,c));return s.allPropertiesImplement&&a.push(...await je(s.allPropertiesImplement,p,c)),s.additionalPropertiesDataType&&a.push(...await je(s.additionalPropertiesDataType,p,c)),s.extends&&a.push(...await je(s.extends,p,c)),a}async function oFe(s,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(s.id))return[];if(p.add(s.id),s.type!==d.Condition)throw new Error("Entity must be a condition to be flattened");const r=Y.YieldTracker.from(i),a=[s];await r.tick();const c={...i,tracker:r};if(delete c.yieldEvery,s.andChildrenGroup&&Array.isArray(s.andChildrenGroup))for(const f of s.andChildrenGroup)a.push(...await je(f,p,c));if(s.orChildrenGroup&&Array.isArray(s.orChildrenGroup))for(const f of s.orChildrenGroup)a.push(...await je(f,p,c));for(const f of s.inputs)a.push(...await je(f,p,c));for(const f of s.successCalls)a.push(...await je(f,p,c));for(const f of s.errorCalls)a.push(...await je(f,p,c));const e=Ko(s);for(const f of e)a.push(...await je(f,p,c));return s.parent&&a.push(...await je(s.parent,p,c)),a}async function dFe(s,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(s.id))return[];if(p.add(s.id),s.type!==d.ContinueStatement)throw new Error("Entity must be a continue statement to be flattened");const r=Y.YieldTracker.from(i),a=[s];await r.tick();const c={...i,tracker:r};delete c.yieldEvery;for(const f of s.outputs)a.push(...await je(f,p,c));const e=Ko(s);for(const f of e)a.push(...await je(f,p,c));return s.parent&&a.push(...await je(s.parent,p,c)),s.throws&&a.push(...await je(s.throws,p,c)),s.dataType&&a.push(...await je(s.dataType,p,c)),s.readsValue&&a.push(...await je(s.readsValue,p,c)),a}async function uFe(s,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(s.id))return[];if(p.add(s.id),s.type!==d.DefinitionEntity)throw new Error("Entity must be a definition entity to be flattened");const r=Y.YieldTracker.from(i),a=[s];await r.tick();const c={...i,tracker:r};delete c.yieldEvery;for(const e of s.properties)a.push(...await je(e,p,c));for(const e of s.methods)a.push(...await je(e,p,c));for(const e of s.abstractMethods)a.push(...await je(e,p,c));for(const e of s.implements)a.push(...await je(e,p,c));return s.extends&&a.push(...await je(s.extends,p,c)),s.parent&&a.push(...await je(s.parent,p,c)),s.additionalPropertiesDataType&&a.push(...await je(s.additionalPropertiesDataType,p,c)),s.allPropertiesImplement&&a.push(...await je(s.allPropertiesImplement,p,c)),a}async function pFe(s,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(s.id))return[];if(p.add(s.id),s.type!==d.DataType)throw new Error("Entity must be a data type to be flattened");const r=Y.YieldTracker.from(i),a=[s];await r.tick();const c={...i,tracker:r};if(delete c.yieldEvery,s.parent&&a.push(...await je(s.parent,p,c)),s.foreignKeyRef&&a.push(...await je(s.foreignKeyRef,p,c)),s.entity&&a.push(...await je(s.entity,p,c)),s.orChildrenGroup)for(const e of s.orChildrenGroup)a.push(...await je(e,p,c));if(s.andChildrenGroup)for(const e of s.andChildrenGroup)a.push(...await je(e,p,c));return a}async function cFe(s,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(s.id))return[];if(p.add(s.id),s.type!==d.FunctionCall)throw new Error("Entity must be a function call to be flattened");const r=Y.YieldTracker.from(i),a=[s];await r.tick();const c={...i,tracker:r};delete c.yieldEvery;for(const f of s.inputs)a.push(...await je(f,p,c));for(const f of s.outputs)a.push(...await je(f,p,c));s.error&&a.push(...await je(s.error,p,c));const e=Ko(s);for(const f of e)a.push(...await je(f,p,c));for(const f of s.successCalls)a.push(...await je(f,p,c));for(const f of s.errorCalls)a.push(...await je(f,p,c));for(const f of s.writesValues)a.push(...await je(f,p,c));return s.parent&&a.push(...await je(s.parent,p,c)),a}async function fFe(s,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(s.id))return[];if(p.add(s.id),s.type!==d.FunctionDeclaration)throw new Error("Entity must be a function declaration to be flattened");const r=Y.YieldTracker.from(i),a=[s];await r.tick();const c={...i,tracker:r};delete c.yieldEvery,s.parent&&a.push(...await je(s.parent,p,c)),s.implements&&a.push(...await je(s.implements,p,c)),s.dataType&&a.push(...await je(s.dataType,p,c));for(const e of s.inputs)a.push(...await je(e,p,c));for(const e of s.calls)a.push(...await je(e,p,c));return a}async function yFe(s,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(s.id))return[];if(p.add(s.id),s.type!==d.GlobalEvent)throw new Error("Entity must be a global event to be flattened");const r=Y.YieldTracker.from(i),a=[s];await r.tick();const c={...i,tracker:r};delete c.yieldEvery,s.parent&&a.push(...await je(s.parent,p,c)),s.implements&&a.push(...await je(s.implements,p,c));for(const e of s.inputs)a.push(...await je(e,p,c));for(const e of s.calls)a.push(...await je(e,p,c));return a}async function hFe(s,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(s.id))return[];if(p.add(s.id),s.type!==d.InputMap)throw new Error("Entity must be an input map to be flattened");const r=Y.YieldTracker.from(i),a=[s];await r.tick();const c={...i,tracker:r};return delete c.yieldEvery,s.parent&&a.push(...await je(s.parent,p,c)),s.declaration&&a.push(...await je(s.declaration,p,c)),s.readsValue&&a.push(...await je(s.readsValue,p,c)),s.dataType&&a.push(...await je(s.dataType,p,c)),s.defaultValue&&a.push(...await je(s.defaultValue,p,c)),a}async function mFe(s,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(s.id))return[];if(p.add(s.id),s.type!==d.InstalledProject)throw new Error("Entity must be an installed project to be flattened");const r=Y.YieldTracker.from(i),a=[s];await r.tick();const c={...i,tracker:r};delete c.yieldEvery;for(const e of s.functions)a.push(...await je(e,p,c));for(const e of s.events)a.push(...await je(e,p,c));return s.parent&&a.push(...await je(s.parent,p,c)),a}async function TFe(s,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(s.id))return[];if(p.add(s.id),s.type!==d.InternalCall)throw new Error("Entity must be an internal call to be flattened");const r=Y.YieldTracker.from(i),a=[s];await r.tick();const c={...i,tracker:r};delete c.yieldEvery;for(const f of s.inputs)a.push(...await je(f,p,c));for(const f of s.outputs)a.push(...await je(f,p,c));s.error&&a.push(...await je(s.error,p,c));const e=Ko(s);for(const f of e)a.push(...await je(f,p,c));for(const f of s.successCalls)a.push(...await je(f,p,c));for(const f of s.errorCalls)a.push(...await je(f,p,c));for(const f of s.writesValues)a.push(...await je(f,p,c));return s.parent&&a.push(...await je(s.parent,p,c)),a}async function vFe(s,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(s.id))return[];if(p.add(s.id),s.type!==d.LiteralValue)throw new Error("Entity must be a literal value to be flattened");const r=Y.YieldTracker.from(i),a=[s];await r.tick();const c={...i,tracker:r};if(delete c.yieldEvery,s.valueAsTypeSingle&&a.push(...await je(s.valueAsTypeSingle,p,c)),s.valueAsTypeList&&Array.isArray(s.valueAsTypeList))for(const e of s.valueAsTypeList)a.push(...await je(e,p,c));return s.parent&&a.push(...await je(s.parent,p,c)),a}async function EFe(s,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(s.id))return[];if(p.add(s.id),s.type!==d.Loop)throw new Error("Entity must be a loop to be flattened");const r=Y.YieldTracker.from(i),a=[s];await r.tick();const c={...i,tracker:r};delete c.yieldEvery;for(const f of s.inputs)a.push(...await je(f,p,c));for(const f of s.outputs)a.push(...await je(f,p,c));s.error&&a.push(...await je(s.error,p,c));const e=Ko(s);for(const f of e)a.push(...await je(f,p,c));for(const f of s.successCalls)a.push(...await je(f,p,c));for(const f of s.errorCalls)a.push(...await je(f,p,c));for(const f of s.writesValues)a.push(...await je(f,p,c));return s.parent&&a.push(...await je(s.parent,p,c)),s.body&&a.push(...await je(s.body,p,c)),s.dataType&&a.push(...await je(s.dataType,p,c)),a}async function bFe(s,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(s.id))return[];if(p.add(s.id),s.type!==d.Operation)throw new Error("Entity must be an operation to be flattened");const r=Y.YieldTracker.from(i),a=[s];await r.tick();const c={...i,tracker:r};delete c.yieldEvery;for(const f of s.inputs)a.push(...await je(f,p,c));for(const f of s.outputs)a.push(...await je(f,p,c));s.error&&a.push(...await je(s.error,p,c));const e=Ko(s);for(const f of e)a.push(...await je(f,p,c));for(const f of s.successCalls)a.push(...await je(f,p,c));for(const f of s.errorCalls)a.push(...await je(f,p,c));for(const f of s.writesValues)a.push(...await je(f,p,c));return s.parent&&a.push(...await je(s.parent,p,c)),a}async function AFe(s,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(s.id))return[];if(p.add(s.id),s.type!==d.OutputMap)throw new Error("Entity must be an output map to be flattened");const r=Y.YieldTracker.from(i),a=[s];await r.tick();const c={...i,tracker:r};delete c.yieldEvery;for(const e of s.writesValues)a.push(...await je(e,p,c));return s.declaration&&a.push(...await je(s.declaration,p,c)),s.dataType&&a.push(...await je(s.dataType,p,c)),s.parent&&a.push(...await je(s.parent,p,c)),a}async function gFe(s,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(s.id))return[];if(p.add(s.id),s.type!==d.PrimitiveEntity)throw new Error("Entity must be a primitive entity to be flattened");const r=Y.YieldTracker.from(i),a=[s];await r.tick();const c={...i,tracker:r};delete c.yieldEvery;for(const e of s.properties)a.push(...await je(e,p,c));for(const e of s.methods)a.push(...await je(e,p,c));for(const e of s.abstractMethods)a.push(...await je(e,p,c));return a}async function IFe(s,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(s.id))return[];if(p.add(s.id),s.type!==d.Project)throw new Error("Entity must be a project to be flattened");const r=Y.YieldTracker.from(i),a=[s];await r.tick();const c={...i,tracker:r};delete c.yieldEvery;for(const e of s.entities)a.push(...await je(e,p,c));for(const e of s.functions)a.push(...await je(e,p,c));for(const e of s.events)a.push(...await je(e,p,c));for(const e of s.projects)a.push(...await je(e,p,c));for(const e of s.variableDeclarations)a.push(...await je(e,p,c));for(const e of s.variableInstances)a.push(...await je(e,p,c));for(const e of s.operations)a.push(...await je(e,p,c));for(const e of s.conditions)a.push(...await je(e,p,c));for(const e of s.functionCalls)a.push(...await je(e,p,c));for(const e of s.projects)a.push(...await je(e,p,c));for(const e of s.loops)a.push(...await je(e,p,c));for(const e of s.searches)a.push(...await je(e,p,c));return a}async function RFe(s,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(s.id))return[];if(p.add(s.id),s.type!==d.Property)throw new Error("Entity must be a property to be flattened");const r=Y.YieldTracker.from(i),a=[s];await r.tick();const c={...i,tracker:r};return delete c.yieldEvery,s.defaultValue&&a.push(...await je(s.defaultValue,p,c)),s.dataType&&a.push(...await je(s.dataType,p,c)),s.parent&&a.push(...await je(s.parent,p,c)),a}async function DFe(s,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(s.id))return[];if(p.add(s.id),s.type!==d.ReturnStatement)throw new Error("Entity must be a return statement to be flattened");const r=Y.YieldTracker.from(i),a=[s];await r.tick();const c={...i,tracker:r};delete c.yieldEvery;for(const f of s.outputs)a.push(...await je(f,p,c));for(const f of s.outputs)a.push(...await je(f,p,c));s.throws&&a.push(...await je(s.throws,p,c)),s.readsValue&&a.push(...await je(s.readsValue,p,c)),s.dataType&&a.push(...await je(s.dataType,p,c));const e=Ko(s);for(const f of e)a.push(...await je(f,p,c));return s.parent&&a.push(...await je(s.parent,p,c)),a}async function wFe(s,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(s.id))return[];if(p.add(s.id),s.type!==d.Search)throw new Error("Entity must be a search to be flattened");const r=Y.YieldTracker.from(i),a=[s];await r.tick();const c={...i,tracker:r};delete c.yieldEvery;for(const f of s.inputs)a.push(...await je(f,p,c));for(const f of s.outputs)a.push(...await je(f,p,c));s.error&&a.push(...await je(s.error,p,c)),s.dataType&&a.push(...await je(s.dataType,p,c));for(const f of s.inputsDeclarations)a.push(...await je(f,p,c));const e=Ko(s);for(const f of e)a.push(...await je(f,p,c));for(const f of s.successCalls)a.push(...await je(f,p,c));for(const f of s.errorCalls)a.push(...await je(f,p,c));for(const f of s.writesValues)a.push(...await je(f,p,c));return s.parent&&a.push(...await je(s.parent,p,c)),a}async function CFe(s,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(s.id))return[];if(p.add(s.id),s.type!==d.ValueDescriptor)throw new Error("Entity must be a value descriptor to be flattened");const r=Y.YieldTracker.from(i),a=[s];await r.tick();const c={...i,tracker:r};return delete c.yieldEvery,s.defaultValue&&a.push(...await je(s.defaultValue,p,c)),s.dataType&&a.push(...await je(s.dataType,p,c)),s.parent&&a.push(...await je(s.parent,p,c)),a}async function OFe(s,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(s.id))return[];if(p.add(s.id),s.type!==d.VariableDeclaration)throw new Error("Entity must be a variable declaration to be flattened");const r=Y.YieldTracker.from(i),a=[s];await r.tick();const c={...i,tracker:r};delete c.yieldEvery;for(const f of s.inputs)a.push(...await je(f,p,c));for(const f of s.outputs)a.push(...await je(f,p,c));s.error&&a.push(...await je(s.error,p,c)),s.dataType&&a.push(...await je(s.dataType,p,c)),s.readsValue&&a.push(...await je(s.readsValue,p,c)),s.defaultValue&&a.push(...await je(s.defaultValue,p,c));const e=Ko(s);for(const f of e)a.push(...await je(f,p,c));for(const f of s.successCalls)a.push(...await je(f,p,c));for(const f of s.errorCalls)a.push(...await je(f,p,c));for(const f of s.writesValues)a.push(...await je(f,p,c));for(const f of s.internalCalls)a.push(...await je(f,p,c));return s.parent&&a.push(...await je(s.parent,p,c)),a}async function _Fe(s,p=new Set,i={ignoreBuiltInBaseEntities:!1}){if(p.has(s.id))return[];if(p.add(s.id),s.type!==d.VariableInstance)throw new Error("Entity must be a variable instance to be flattened");const r=Y.YieldTracker.from(i),a=[s];await r.tick();const c={...i,tracker:r};delete c.yieldEvery;for(const f of s.inputs)a.push(...await je(f,p,c));for(const f of s.outputs)a.push(...await je(f,p,c));s.error&&a.push(...await je(s.error,p,c)),s.readsValue&&a.push(...await je(s.readsValue,p,c)),s.defaultValue&&a.push(...await je(s.defaultValue,p,c));const e=Ko(s);for(const f of e)a.push(...await je(f,p,c));for(const f of s.successCalls)a.push(...await je(f,p,c));for(const f of s.errorCalls)a.push(...await je(f,p,c));for(const f of s.writesValues)a.push(...await je(f,p,c));for(const f of s.internalCalls)a.push(...await je(f,p,c));return s.parent&&a.push(...await je(s.parent,p,c)),s.declaration&&a.push(...await je(s.declaration,p,c)),a}async function je(s,p=new Set,i={ignoreBuiltInBaseEntities:!1,yieldEvery:100}){const r={...i,ignoreBuiltInBaseEntities:i.ignoreBuiltInBaseEntities??!1};if(!s)throw new Error("Entity must be defined to be flattened");if(s.type===d.GenericReference)return[];const a=Y.YieldTracker.from(r);r.tracker=a,r.yieldEvery!==void 0&&delete r.yieldEvery;const c=r.ignoreBuiltInBaseEntities?r.diggestedBuiltInBaseEntitiesIds??new Set(await dD(r)):new Set;if(r.diggestedBuiltInBaseEntitiesIds=c,r.ignoreBuiltInBaseEntities&&(ma.includes(s.type)||c.has(s.id)))return[];if(p.has(s.id))return[];switch(s.type){case d.FunctionCall:return cFe(s,p,r);case d.Operation:return bFe(s,p,r);case d.Condition:return oFe(s,p,r);case d.Loop:return EFe(s,p,r);case d.Search:return wFe(s,p,r);case d.GlobalEvent:return yFe(s,p,r);case d.ReturnStatement:return DFe(s,p,r);case d.ContinueStatement:return dFe(s,p,r);case d.BreakStatement:return sFe(s,p,r);case d.VariableDeclaration:return OFe(s,p,r);case d.DefinitionEntity:return uFe(s,p,r);case d.FunctionDeclaration:return fFe(s,p,r);case d.Project:return IFe(s,p,r);case d.ActionDescriptor:return nFe(s,p,r);case d.ArgumentDeclaration:return aFe(s,p,r);case d.ValueDescriptor:return CFe(s,p,r);case d.InputMap:return hFe(s,p,r);case d.OutputMap:return AFe(s,p,r);case d.DataType:return pFe(s,p,r);case d.InstalledProject:return mFe(s,p,r);case d.InternalCall:return TFe(s,p,r);case d.LiteralValue:return vFe(s,p,r);case d.Property:return RFe(s,p,r);case d.VariableInstance:return _Fe(s,p,r);case d.BuiltInBaseEntity:return r.ignoreBuiltInBaseEntities?[]:lFe(s,p,r);case d.PrimitiveEntity:return r.ignoreBuiltInBaseEntities?[]:gFe(s,p,r)}return[]}function VFe(s){return s==null||s===""}function RPi(s){return s===null}function Vn(s){return s!=null&&s.valueAsType?!1:VFe(s==null?void 0:s.value)}function co(s){return s?s.valueAsType===null&&s.value===null:!1}function PFe(s,p){if(s===p||!s&&!p)return!0;if(!s||!p||s.name===ye.EntityTemplate&&p.name!==ye.EntityTemplate||p.name===ye.EntityTemplate&&s.name!==ye.EntityTemplate)return!1;if(s.name===ye.ActionDescriptor&&p.name!==ye.ActionDescriptor||p.name===ye.ActionDescriptor&&s.name!==ye.ActionDescriptor)return!1;if(s.valueAsTypeSingle&&!p.valueAsTypeSingle||p.valueAsTypeSingle&&!s.valueAsTypeSingle)return!1;if(s.valueAsTypeList&&!p.valueAsTypeList||p.valueAsTypeList&&!s.valueAsTypeList)return!1;if(s.valueAsTypeSingle&&p.valueAsTypeSingle){if(s.valueAsTypeSingle.id!==p.valueAsTypeSingle.id)return!1}else if(s.valueAsTypeList&&p.valueAsTypeList){if(s.valueAsTypeList.length!==p.valueAsTypeList.length)return!1;for(let i=0;i<s.valueAsTypeList.length;i++)if(s.valueAsTypeList[i].id!==p.valueAsTypeList[i].id)return!1}else if(!s.valueAsType&&!p.valueAsType&&s.value!==p.value)return!1;return!0}function NFe(s,p,i){if(!i)throw new Error("[checkIsRowTransformerUpToDate] 'lastPublishedEntityVersion' argument is required");if(!p)throw new Error("[checkIsRowTransformerUpToDate] 'entity' argument is required");if(!s)throw new Error("[checkIsRowTransformerUpToDate] 'newestOpenRowTransformer' argument is required");let r=!0;const a=s.methods.find(c=>{var e;return((e=c.implements)==null?void 0:e.id)===re["built-in-base-entity"].BUILT_IN_SQL_ROW_TRANSFORMER_ENTITY.methods.up.id});if(a?(fn(i).forEach(c=>{const e=a.inputs.find(f=>f.name===c.name);e&&ni(e.getDataType(null),c.getDataType(null)).compatible||(r=!1)}),a.returnStatements.forEach(c=>{!c.dataType||!c.dataType.entity||c.dataType.entity.type!==d.DefinitionEntity?r=!1:ev(c.dataType.entity,p)||(r=!1)})):r=!1,r===null||r){const c=s.methods.find(e=>{var f;return((f=e.implements)==null?void 0:f.id)===re["built-in-base-entity"].BUILT_IN_SQL_ROW_TRANSFORMER_ENTITY.methods.down.id});c?(fn(p).forEach(e=>{const f=c.inputs.find(h=>h.name===e.name);f&&ni(f.getDataType(null),e.getDataType(null)).compatible||(r=!1)}),c.returnStatements.forEach(e=>{!e.dataType||!e.dataType.entity||e.dataType.entity.type!==d.DefinitionEntity?r=!1:ev(e.dataType.entity,i)||(r=!1)})):r=!1}return{isPreexistingRowTransformerUpToDate:r}}function EV(s,p,i,r={skipBaseExtension:!1}){var J;const a={...r||{},skipBaseExtension:(r==null?void 0:r.skipBaseExtension)||!1},c={changesSinceLastPublication:!1,rowTransformerNeeded:!1,newRowTransformerNeeded:!1,newestOpenRowTransformer:null,newRequiredProperties:[],newNonRequiredProperties:[],deletedProperties:[],lastPublishedEntityVersion:null,updatedEntityVersion:i,propChanges:new Map,isPreexistingRowTransformerUpToDate:null,extendedEntities:[]},f=s.entities.filter(se=>{var ue;if(se.id===i.id)return!1;let te=!1,le=se;for(;le;){if(((ue=le.extends)==null?void 0:ue.id)===i.id){te=!0;break}if(le.extends&&le.extends.type===d.DefinitionEntity)le=le.extends;else break}return te}).map(se=>EV(s,p,se,{...a,skipBaseExtension:!0}));if(!p)return{...c,changesSinceLastPublication:!0,extendedEntities:f};const h=p.get(i.id);if(!h)return{...c,changesSinceLastPublication:!0,extendedEntities:f};const m=p.entities.filter(se=>di(se,ge.SQL_ROW_TRANSFORMER)),b=s.entities.filter(se=>{var z;if(!di(se,ge.SQL_ROW_TRANSFORMER)||m.find(Q=>Q.id===se.id))return!1;const le=se.properties.find(Q=>!!Q.implements.find(de=>re["built-in-base-entity"].BUILT_IN_SQL_ROW_TRANSFORMER_ENTITY.properties.definition.id===de.id));if(!le)return!1;const ue=(z=le.defaultValue)==null?void 0:z.valueAsType;return ue?ue.id===i.id:!1}).sort((se,te)=>B(se.createdAt).isAfter(B(te.createdAt))?-1:1)[0]||null,A=new Map;let _=!1,P=null;!a.skipBaseExtension&&i.extends&&((J=i.extends)==null?void 0:J.type)===d.DefinitionEntity&&(P=EV(i.project,p,i.extends));const V=fn(i).filter(se=>fn(h).find(ue=>ue.id===se.id)?!1:!Ka(se.getDataType(null))),M=fn(i).filter(se=>fn(h).find(ue=>ue.id===se.id)?!1:!!Ka(se.getDataType(null))),G=fn(h).filter(se=>!fn(i).find(le=>le.id===se.id));fn(i).filter(se=>{var fe,be,Ie,_e,Ge,Se,Ye,Ze,et,Et,yt;const te=fn(h).find(ai=>ai.id===se.id);let le=!1;if(!te)return!1;const ue=Sa(se.dataType,!0,`[resolveSQLMigrationsDiffs] Unsupported data-type structure on current property '${se.name}' (${se.id}). 'andChildrenGroup' with more than one child is not supported for SQL column properties.`),z=Sa(te.dataType,!0,`[resolveSQLMigrationsDiffs] Unsupported data-type structure on last published property '${se.name}' (${se.id}). 'andChildrenGroup' with more than one child is not supported for SQL column properties.`),Q=Dh(ue,!0,`[resolveSQLMigrationsDiffs] Unsupported data-type structure on current property '${se.name}' (${se.id}). 'orChildrenGroup' with multiple non-null children is not supported for SQL column properties.`),de=Dh(z,!0,`[resolveSQLMigrationsDiffs] Unsupported data-type structure on last published property '${se.name}' (${se.id}). 'orChildrenGroup' with multiple non-null children is not supported for SQL column properties.`);if(((fe=Q==null?void 0:Q.foreignKeyRef)==null?void 0:fe.id)!==((be=de==null?void 0:de.foreignKeyRef)==null?void 0:be.id)){const ai=Q==null?void 0:Q.foreignKeyRef,ui=de==null?void 0:de.foreignKeyRef;A.set(se.id,{...A.get(se.id)||{},newForeignKeyRef:ai||void 0,oldForeignKeyRef:ui||void 0,property:se,oldProperty:te}),le=!0,_=!0}else((Ie=Q==null?void 0:Q.entity)==null?void 0:Ie.id)!==((_e=de==null?void 0:de.entity)==null?void 0:_e.id)&&(((Ge=Q==null?void 0:Q.entity)==null?void 0:Ge.id)===re["primitive-entity"].string.id||((Se=de==null?void 0:de.entity)==null?void 0:Se.id)===re["primitive-entity"].date.id&&((Ye=Q==null?void 0:Q.entity)==null?void 0:Ye.id)===re["primitive-entity"].number.id?A.set(se.id,{...A.get(se.id)||{},castableDataTypeEntity:{fromId:((Ze=de==null?void 0:de.entity)==null?void 0:Ze.id)||"",toId:((et=Q==null?void 0:Q.entity)==null?void 0:et.id)||""},property:se,oldProperty:te}):(A.set(se.id,{...A.get(se.id)||{property:se},nonCastableDataTypeEntity:{fromId:((Et=de==null?void 0:de.entity)==null?void 0:Et.id)||"",toId:((yt=Q==null?void 0:Q.entity)==null?void 0:yt.id)||""},property:se,oldProperty:te}),_=!0),le=!0);se.name!==(te==null?void 0:te.name)&&(A.set(se.id,{...A.get(se.id)||{},nameChange:{from:(te==null?void 0:te.name)||"",to:se.name},property:se,oldProperty:te}),le=!0);const pe=Ka(te.getDataType(null)),he=Ka(se.getDataType(null));return he!==pe&&(A.set(se.id,{...A.get(se.id)||{},requiredChange:{from:!pe,to:!he},property:se,oldProperty:te}),he||(_=!0),le=!0),le}),V.length>0&&(_=!0);let k=null;b&&_&&(k=NFe(b,i,h).isPreexistingRowTransformerUpToDate);const q=i.name!==h.name?{from:h.name,to:i.name}:void 0;let ne=P!=null&&P.rowTransformerNeeded?!0:_;return{...c,changesSinceLastPublication:A.size>0||!!G.length||!!V.length||!!M.length||ne,rowTransformerNeeded:ne,newestOpenRowTransformer:b,nameChange:q,newRequiredProperties:V,newNonRequiredProperties:M,deletedProperties:G,lastPublishedEntityVersion:h,propChanges:A,newRowTransformerNeeded:ne&&!b,isPreexistingRowTransformerUpToDate:k,extendedEntities:f}}function wL(s,p,i,r,a){const c=a==null?void 0:a.ignoreNonEditable;a&&(a.ignoreNonEditable=!0);try{if(!s)throw new Error("[addDifferencesToRowTransformer] 'project' argument is required");if(!p)throw new Error("[addDifferencesToRowTransformer] 'transformer' argument is required");if(!i)throw new Error("[addDifferencesToRowTransformer] 'newEntityState' argument is required");if(!r)throw new Error("[addDifferencesToRowTransformer] 'oldEntityState' argument is required");const e=fn(i),f=fn(r);p.afterAllChildrenInitialized(a);const h=p.methods.find(E=>{var b;return((b=E.implements)==null?void 0:b.id)===re["built-in-base-entity"].BUILT_IN_SQL_ROW_TRANSFORMER_ENTITY.methods.up.id}),m=p.methods.find(E=>{var b;return((b=E.implements)==null?void 0:b.id)===re["built-in-base-entity"].BUILT_IN_SQL_ROW_TRANSFORMER_ENTITY.methods.down.id});if(!h)throw new Error("[addDifferencesToRowTransformer] The 'up' transformer trigger is missing from the parent");if(!m)throw new Error("[addDifferencesToRowTransformer] The 'down' transformer trigger is missing from the parent");f.forEach(E=>{const b=h.inputs.find(V=>V.name===E.name),A=Dh(E.getDataType(null))||E.getDataType(null);let _=b,P;if(b)_.editable=!0;else{const V=Za.new(a);V.parent=h.toReference(),V.name=E.name,V.index=E.index,V.implements=[...E.implements.map(G=>G.toJSON())];const M=Re(V,s);M.hydrateAncestors(),a.add(M,W.Added),M.addSelfToProject(a),M.initChildren(a),_=M}if(!b||!_.dataType||_.dataType&&s.diggestedBuiltInBaseEntitiesIds.has(_.dataType.id)){const V=vr.new(a);V.parent=_.toReference();const M=Re(V,s);M.hydrateAncestors(),a.add(M,W.Added),M.addSelfToProject(a),M.initChildren(a),P=M}else P=_.dataType,P.editable=!0;A&&P.merge(A,a),P.metaSync({editable:!1,deletable:!1},a),_.metaSync({editable:!1,deletable:!1},a)}),[...h.inputs].forEach(E=>{f.find(A=>A.name===E.name)||(E.editable=!0,E.remove({ignoreUpstream:!1},a),E.editable=!1)}),[...h.returnStatements].forEach(E=>{var M,G,k,q,ne,J,se,te,le;if(!E.dataType||E.dataType&&s.diggestedBuiltInBaseEntitiesIds.has(E.dataType.id)){const ue=vr.new(a);ue.entity=i.toReference(),ue.parent=E.toReference();const z=Re(ue,s);z.hydrateAncestors(),a.add(z,W.Added),z.addSelfToProject(a),z.initChildren(a)}const b=(M=E.dataType)==null?void 0:M.entity,A=!b||b.type!==d.DefinitionEntity||b.type===d.DefinitionEntity&&((G=b.parent)==null?void 0:G.type)===d.Project||((k=b.parent)==null?void 0:k.id)!==((q=E.dataType)==null?void 0:q.id),_=!A&&b&&b.type===d.DefinitionEntity&&b.name&&s.getDefinitionEntities().some(ue=>ue.id!==b.id&&ue.name===b.name),P=b&&b.type===d.DefinitionEntity&&b.name&&!A&&!_?b.name:su((i==null?void 0:i.name)+" new format",s.getDefinitionEntities());let V=(ne=E.dataType)==null?void 0:ne.entity;(!((J=E.dataType)!=null&&J.entity)||E.dataType.entity.type!==d.DefinitionEntity||E.dataType.entity.type==d.DefinitionEntity&&((se=E.dataType.entity.parent)==null?void 0:se.type)===d.Project||E.dataType.entity.parent.id!==E.dataType.id)&&(V=i.clone(a,E.dataType),V.metaSync({name:P},a)),Vg(V,i,a,{exactDataType:!0}),V.setExtension(null,a),V.addImplementation(s.getBuiltIn(re["built-in-base-entity"].BUILT_IN_PERSISTED_ENTITY_ENTITY.id),a),V.properties.forEach(ue=>ue.setExtends(null,a)),E.dataType.setEntity(V,a),(le=(te=E.dataType)==null?void 0:te.entity)==null||le.metaSync({name:P},a),E.afterAllChildrenInitialized(a),E.outputs.forEach(ue=>{var he,fe;if(ue.defaultValue||ue.readsValue)return;const z=(he=e.find(be=>be.name===ce(ue,s)))==null?void 0:he.id,Q=(fe=f.find(be=>(be==null?void 0:be.id)===z))==null?void 0:fe.name,de=h.inputs.find(be=>Q===ce(be,s)),pe=ni((de==null?void 0:de.getDataType(null))||null,ue.getDataType(null)||null);pe!=null&&pe.compatible&&(ue.setValueWriter(de,a),de==null||de.addValueReader(ue,a))})}),e.forEach(E=>{var M;const b=(M=E.knownVersions)==null?void 0:M.get(E.previousVersion),A=m.inputs.find(G=>G.name===E.name||!!b&&b.name===G.name),_=Dh(E.getDataType(null))||E.getDataType(null);let P=A,V;if(A)P.editable=!0,P.metaSync({name:E.name,codeName:E.codeName,description:E.description},a);else{const G=Za.new(a);G.parent=m.toReference(),G.name=E.name,G.codeName=E.codeName,G.description=E.description,G.index=E.index,G.implements=[...E.implements.map(q=>q.toJSON())];const k=Re(G,s);k.hydrateAncestors(),a.add(k,W.Added),k.addSelfToProject(a),k.initChildren(a),P=k}if(!A||!P.dataType||P.dataType&&s.diggestedBuiltInBaseEntitiesIds.has(P.dataType.id)){const G=vr.new(a);G.parent=P.toReference();const k=Re(G,s);k.hydrateAncestors(),a.add(k,W.Added),k.addSelfToProject(a),k.initChildren(a),V=k}else V=P.dataType,V.editable=!0,V.merge(P.dataType,a);_&&V.merge(_,a),V.metaSync({editable:!1,deletable:!1},a),P.metaSync({editable:!1,deletable:!1},a)}),[...m.inputs].forEach(E=>{e.find(A=>{var P;if(A.name===E.name)return!0;const _=(P=A.knownVersions)==null?void 0:P.get(A.previousVersion);if(_&&_.name===E.name)return!0})||(E.editable=!0,E.remove({ignoreUpstream:!1},a),E.editable=!1)}),[...m.returnStatements].forEach(E=>{var M,G,k,q;if(!E.dataType||E.dataType&&s.diggestedBuiltInBaseEntitiesIds.has(E.dataType.id)){const ne=vr.new(a);ne.parent=E.toReference();const J=Re(ne,s);J.hydrateAncestors(),a.add(J,W.Added),J.addSelfToProject(a),J.initChildren(a)}const b=(M=E.dataType)==null?void 0:M.entity,A=!b||b.id===re["built-in-base-entity"].BUILT_IN_PERSISTED_ENTITY_ENTITY.id,_=!A&&b&&b.type===d.DefinitionEntity&&b.name&&s.getDefinitionEntities().some(ne=>ne.id!==b.id&&ne.name===b.name),P=b&&b.type===d.DefinitionEntity&&b.name&&!A&&!_?b.name:su((r==null?void 0:r.name)+" old format",s.getDefinitionEntities());let V=(G=E.dataType)==null?void 0:G.entity;(!V||(V==null?void 0:V.id)===re["built-in-base-entity"].BUILT_IN_PERSISTED_ENTITY_ENTITY.id)&&(V=r.clone(a,E.dataType),V.metaSync({name:P},a)),Vg(V,r,a,{exactDataType:!0}),V.setExtension(null,a),V.addImplementation(s.getBuiltIn(re["built-in-base-entity"].BUILT_IN_PERSISTED_ENTITY_ENTITY.id),a),V.properties.forEach(ne=>ne.setExtends(null,a)),E.dataType.setEntity(V,a),(q=(k=E.dataType)==null?void 0:k.entity)==null||q.metaSync({name:P},a),E.afterAllChildrenInitialized(a),E.outputs.forEach(ne=>{var le,ue,z;if(ne.defaultValue||ne.readsValue)return;const J=(le=f.find(Q=>Q.name===ce(ne,s)))==null?void 0:le.id,se=(ue=e.find(Q=>(Q==null?void 0:Q.id)===J))==null?void 0:ue.name,te=m.inputs.find(Q=>se===ce(Q,s));(z=ni((te==null?void 0:te.getDataType(null))||null,ne.getDataType(null)||null))!=null&&z.compatible&&(ne.setValueWriter(te,a),te==null||te.addValueReader(ne,a))})})}finally{a&&(a.ignoreNonEditable=!!c)}}function xFe(s,p,i,r,a={}){var G;const c=s.getBuiltIn(ge.SQL_ROW_TRANSFORMER),e=su(ce(p,s)+" row transformer",s.entities),f=c.implement(e,r),h=f.ownDeclaredProperties.find(k=>{var q;return(q=k.implements)==null?void 0:q.find(ne=>ne.id===re["built-in-base-entity"].BUILT_IN_SQL_ROW_TRANSFORMER_ENTITY.properties.definition.id)}),m=f.methods.find(k=>{var q;return((q=k.implements)==null?void 0:q.id)===re["built-in-base-entity"].BUILT_IN_SQL_ROW_TRANSFORMER_ENTITY.methods.up.id}),E=f.methods.find(k=>{var q;return((q=k.implements)==null?void 0:q.id)===re["built-in-base-entity"].BUILT_IN_SQL_ROW_TRANSFORMER_ENTITY.methods.down.id});if(!h||!m||!E)throw new Error("Cannot find definition property on the new row transformer entity");if(h.defaultValue)h.defaultValue.setValueAsTypeSingle(p,r);else{const k=Lr.new(r);k.name=ye.EntityTemplate,k.valueAsTypeSingle=p.toJSON(),k.parent=h.toReference();const q=Re(k,s);q.hydrateAncestors(),r.add(q,W.Added),q.addSelfToProject(r),q.initChildren(r)}wL(s,f,p,i,r),Y.Logger.log("BEFORE - changeSet.listAdded",r.listAdded.map(k=>{var ne,J,se,te,le,ue,z;const q=s.get(k.id);return q?ce(q,s):k.type===d.InputMap?"(not found) "+k.type+" "+k.id+" - declaration: "+((ne=k.declaration)==null?void 0:ne.type)+" "+((J=k.declaration)==null?void 0:J.id)+' "'+((se=k.declaration)==null?void 0:se.name)+`"
|
|
607
607
|
parent: `+((le=(te=k.parent)==null?void 0:te.parent)==null?void 0:le.id)+" - "+((z=(ue=k.parent)==null?void 0:ue.parent)==null?void 0:z.name):"(not found) "+k.type+" "+k.id})),Y.Logger.log("AFTER - changeSet.listAdded",r.listAdded.map(k=>{var ne,J,se,te,le,ue,z;const q=s.get(k.id);return q?q.type+' "'+ce(q,s)+'" ('+q.id+")":k.type===d.InputMap?"(not found) "+k.type+" ("+k.id+") - declaration: "+((ne=k.declaration)==null?void 0:ne.type)+" ("+((J=k.declaration)==null?void 0:J.id)+') "'+((se=k.declaration)==null?void 0:se.name)+`"
|
|
608
608
|
parent: "`+((le=(te=k.parent)==null?void 0:te.parent)==null?void 0:le.name)+'" ('+((z=(ue=k.parent)==null?void 0:ue.parent)==null?void 0:z.id)+")":"(not found) "+k.type+" "+k.id})),Y.Logger.log("-----------------"),Y.Logger.log("Old properties: ",fn(i).map(k=>k.name+" ("+k.id+")")),Y.Logger.log("New properties: ",fn(p).map(k=>k.name+" ("+k.id+")"));const b=f.methods.find(k=>{var q;return((q=k.implements)==null?void 0:q.id)===re["built-in-base-entity"].BUILT_IN_SQL_ROW_TRANSFORMER_ENTITY.methods.up.id}),A=f.methods.find(k=>{var q;return((q=k.implements)==null?void 0:q.id)===re["built-in-base-entity"].BUILT_IN_SQL_ROW_TRANSFORMER_ENTITY.methods.down.id});Y.Logger.log(`
|
|
609
609
|
Up inputs: `,b==null?void 0:b.inputs.map(k=>k.name+" ("+k.id+")")),Y.Logger.log("Up method return statements:",b==null?void 0:b.returnStatements[0].outputs.map(k=>ce(k,s)+" ("+k.id+")")),Y.Logger.log(`
|
package/dist/index.js
CHANGED
|
@@ -194840,10 +194840,15 @@ function x4(s, p, i, r = {
|
|
|
194840
194840
|
}
|
|
194841
194841
|
return ee;
|
|
194842
194842
|
}).map(
|
|
194843
|
-
(ae) => x4(
|
|
194844
|
-
|
|
194845
|
-
|
|
194846
|
-
|
|
194843
|
+
(ae) => x4(
|
|
194844
|
+
s,
|
|
194845
|
+
p,
|
|
194846
|
+
ae,
|
|
194847
|
+
{
|
|
194848
|
+
...a,
|
|
194849
|
+
skipBaseExtension: !0
|
|
194850
|
+
}
|
|
194851
|
+
)
|
|
194847
194852
|
);
|
|
194848
194853
|
if (!p)
|
|
194849
194854
|
return {
|
|
@@ -195079,7 +195084,9 @@ function b5(s, p, i, r, a) {
|
|
|
195079
195084
|
// data-type later in this loop becomes a no-op and the arg keeps
|
|
195080
195085
|
// the entire union. Starting from a fresh empty data-type avoids
|
|
195081
195086
|
// the problem.
|
|
195082
|
-
!E || !_.dataType || _.dataType && s.diggestedBuiltInBaseEntitiesIds.has(
|
|
195087
|
+
!E || !_.dataType || _.dataType && s.diggestedBuiltInBaseEntitiesIds.has(
|
|
195088
|
+
_.dataType.id
|
|
195089
|
+
)
|
|
195083
195090
|
) {
|
|
195084
195091
|
const V = gr.new(a);
|
|
195085
195092
|
V.parent = _.toReference();
|
|
@@ -195121,7 +195128,10 @@ function b5(s, p, i, r, a) {
|
|
|
195121
195128
|
de,
|
|
195122
195129
|
s
|
|
195123
195130
|
);
|
|
195124
|
-
z.hydrateAncestors(), a.add(
|
|
195131
|
+
z.hydrateAncestors(), a.add(
|
|
195132
|
+
z,
|
|
195133
|
+
H.Added
|
|
195134
|
+
), z.addSelfToProject(a), z.initChildren(a);
|
|
195125
195135
|
}
|
|
195126
195136
|
const E = (B = b.dataType) == null ? void 0 : B.entity, A = !E || E.type !== d.DefinitionEntity || E.type === d.DefinitionEntity && ((M = E.parent) == null ? void 0 : M.type) === d.Project || ((k = E.parent) == null ? void 0 : k.id) !== ((q = b.dataType) == null ? void 0 : q.id), _ = !A && E && E.type === d.DefinitionEntity && E.name && s.getDefinitionEntities().some(
|
|
195127
195137
|
(de) => de.id !== E.id && de.name === E.name
|
|
@@ -195133,9 +195143,17 @@ function b5(s, p, i, r, a) {
|
|
|
195133
195143
|
(!((J = b.dataType) != null && J.entity) || b.dataType.entity.type !== d.DefinitionEntity || b.dataType.entity.type == d.DefinitionEntity && ((ae = b.dataType.entity.parent) == null ? void 0 : ae.type) === d.Project || b.dataType.entity.parent.id !== b.dataType.id) && (V = i.clone(
|
|
195134
195144
|
a,
|
|
195135
195145
|
b.dataType
|
|
195136
|
-
), V.metaSync(
|
|
195137
|
-
|
|
195138
|
-
|
|
195146
|
+
), V.metaSync(
|
|
195147
|
+
{ name: N },
|
|
195148
|
+
a
|
|
195149
|
+
)), eC(
|
|
195150
|
+
V,
|
|
195151
|
+
i,
|
|
195152
|
+
a,
|
|
195153
|
+
{
|
|
195154
|
+
exactDataType: !0
|
|
195155
|
+
}
|
|
195156
|
+
), V.setExtension(null, a), V.addImplementation(
|
|
195139
195157
|
s.getBuiltIn(
|
|
195140
195158
|
ie["built-in-base-entity"].BUILT_IN_PERSISTED_ENTITY_ENTITY.id
|
|
195141
195159
|
),
|
|
@@ -195145,24 +195163,21 @@ function b5(s, p, i, r, a) {
|
|
|
195145
195163
|
), b.dataType.setEntity(
|
|
195146
195164
|
V,
|
|
195147
195165
|
a
|
|
195148
|
-
), (se = (ee = b.dataType) == null ? void 0 : ee.entity) == null || se.metaSync(
|
|
195149
|
-
|
|
195150
|
-
a
|
|
195151
|
-
), b.afterAllChildrenInitialized(a), b.outputs.forEach((de) => {
|
|
195152
|
-
var ue, he, fe;
|
|
195166
|
+
), (se = (ee = b.dataType) == null ? void 0 : ee.entity) == null || se.metaSync({ name: N }, a), b.afterAllChildrenInitialized(a), b.outputs.forEach((de) => {
|
|
195167
|
+
var he, fe;
|
|
195153
195168
|
if (de.defaultValue || de.readsValue)
|
|
195154
195169
|
return;
|
|
195155
|
-
const z = (
|
|
195170
|
+
const z = (he = e.find(
|
|
195156
195171
|
(Ee) => Ee.name === pe(de, s)
|
|
195157
|
-
)) == null ? void 0 :
|
|
195172
|
+
)) == null ? void 0 : he.id, Y = (fe = f.find(
|
|
195158
195173
|
(Ee) => (Ee == null ? void 0 : Ee.id) === z
|
|
195159
|
-
)) == null ? void 0 :
|
|
195174
|
+
)) == null ? void 0 : fe.name, oe = h.inputs.find(
|
|
195160
195175
|
(Ee) => Y === pe(Ee, s)
|
|
195161
|
-
)
|
|
195162
|
-
(fe = si(
|
|
195176
|
+
), ue = si(
|
|
195163
195177
|
(oe == null ? void 0 : oe.getDataType(null)) || null,
|
|
195164
195178
|
de.getDataType(null) || null
|
|
195165
|
-
)
|
|
195179
|
+
);
|
|
195180
|
+
ue != null && ue.compatible && (de.setValueWriter(oe, a), oe == null || oe.addValueReader(de, a));
|
|
195166
195181
|
});
|
|
195167
195182
|
}), e.forEach((b) => {
|
|
195168
195183
|
var B;
|
|
@@ -195207,7 +195222,9 @@ function b5(s, p, i, r, a) {
|
|
|
195207
195222
|
// can't mutate or remove). Start from a fresh data-type so the
|
|
195208
195223
|
// merge with the column property's actual data-type below produces
|
|
195209
195224
|
// the right shape.
|
|
195210
|
-
!A || !N.dataType || N.dataType && s.diggestedBuiltInBaseEntitiesIds.has(
|
|
195225
|
+
!A || !N.dataType || N.dataType && s.diggestedBuiltInBaseEntitiesIds.has(
|
|
195226
|
+
N.dataType.id
|
|
195227
|
+
)
|
|
195211
195228
|
) {
|
|
195212
195229
|
const M = gr.new(a);
|
|
195213
195230
|
M.parent = N.toReference();
|
|
@@ -195256,7 +195273,10 @@ function b5(s, p, i, r, a) {
|
|
|
195256
195273
|
re,
|
|
195257
195274
|
s
|
|
195258
195275
|
);
|
|
195259
|
-
J.hydrateAncestors(), a.add(
|
|
195276
|
+
J.hydrateAncestors(), a.add(
|
|
195277
|
+
J,
|
|
195278
|
+
H.Added
|
|
195279
|
+
), J.addSelfToProject(a), J.initChildren(a);
|
|
195260
195280
|
}
|
|
195261
195281
|
const E = (B = b.dataType) == null ? void 0 : B.entity, A = !E || E.id === ie["built-in-base-entity"].BUILT_IN_PERSISTED_ENTITY_ENTITY.id, _ = !A && E && E.type === d.DefinitionEntity && E.name && s.getDefinitionEntities().some(
|
|
195262
195282
|
(re) => re.id !== E.id && re.name === E.name
|
|
@@ -195268,9 +195288,17 @@ function b5(s, p, i, r, a) {
|
|
|
195268
195288
|
(!V || (V == null ? void 0 : V.id) === ie["built-in-base-entity"].BUILT_IN_PERSISTED_ENTITY_ENTITY.id) && (V = r.clone(
|
|
195269
195289
|
a,
|
|
195270
195290
|
b.dataType
|
|
195271
|
-
), V.metaSync(
|
|
195272
|
-
|
|
195273
|
-
|
|
195291
|
+
), V.metaSync(
|
|
195292
|
+
{ name: N },
|
|
195293
|
+
a
|
|
195294
|
+
)), eC(
|
|
195295
|
+
V,
|
|
195296
|
+
r,
|
|
195297
|
+
a,
|
|
195298
|
+
{
|
|
195299
|
+
exactDataType: !0
|
|
195300
|
+
}
|
|
195301
|
+
), V.setExtension(null, a), V.addImplementation(
|
|
195274
195302
|
s.getBuiltIn(
|
|
195275
195303
|
ie["built-in-base-entity"].BUILT_IN_PERSISTED_ENTITY_ENTITY.id
|
|
195276
195304
|
),
|
|
@@ -195280,10 +195308,7 @@ function b5(s, p, i, r, a) {
|
|
|
195280
195308
|
), b.dataType.setEntity(
|
|
195281
195309
|
V,
|
|
195282
195310
|
a
|
|
195283
|
-
), (q = (k = b.dataType) == null ? void 0 : k.entity) == null || q.metaSync(
|
|
195284
|
-
{ name: N },
|
|
195285
|
-
a
|
|
195286
|
-
), b.afterAllChildrenInitialized(a), b.outputs.forEach((re) => {
|
|
195311
|
+
), (q = (k = b.dataType) == null ? void 0 : k.entity) == null || q.metaSync({ name: N }, a), b.afterAllChildrenInitialized(a), b.outputs.forEach((re) => {
|
|
195287
195312
|
var se, de, z;
|
|
195288
195313
|
if (re.defaultValue || re.readsValue)
|
|
195289
195314
|
return;
|
|
@@ -195376,7 +195401,9 @@ parent: "` + ((se = (ee = k.parent) == null ? void 0 : ee.parent) == null ? void
|
|
|
195376
195401
|
)
|
|
195377
195402
|
), ce.log(
|
|
195378
195403
|
"New properties: ",
|
|
195379
|
-
Tn(p).map(
|
|
195404
|
+
Tn(p).map(
|
|
195405
|
+
(k) => k.name + " (" + k.id + ")"
|
|
195406
|
+
)
|
|
195380
195407
|
);
|
|
195381
195408
|
const E = f.methods.find(
|
|
195382
195409
|
(k) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@elyx-code/project-logic-tree",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.6950",
|
|
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",
|