@elyx-code/project-logic-tree 0.0.6220 → 0.0.6221

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.
@@ -42,7 +42,7 @@ Please provide a unique 'name' string.`,severity:D.Error,code:$.NameNotUniqueInS
42
42
  Please provide a unique 'name' string.`,severity:D.Error,code:$.NameNotUniqueInScope,issue:null}))}}return e}function mJ(r,a){switch(r.type){case n.DefinitionEntity:return Ec(r,a);case n.FunctionDeclaration:return Ac(r,a);case n.VariableDeclaration:return bc(r,a);case n.Property:return Rc(r,a);case n.ArgumentDeclaration:return Dc(r,a);case n.ReturnDeclaration:return Oc(r,a);default:return[]}}function QO(r,a,e){const i=`${Ul(r)}-${a}-id`;return e.instances[i]?m.UUID.uuid():i}function Pc(r,a){let e="",t=null;if(r.parent){const s=a.get(r.parent);s&&(t=s)}let i="";return t&&(i=`${Ul(x(t,a))}-`),e=`${i}${Ul(x(r,a))}-id`,a.instances[e]?m.UUID.uuid():e}function ht(r,a,e="uuid"){return e==="semantic"?QO(x(r,a),r.type,a):m.UUID.uuid()}function e1(r){var l;const a=S3(),e=r.toJSON();a.safeParse(e).success;const i=t1(r);(l=r.dataType)==null||l.validate();const s=[...i];if(r.id==="80c86e1b-caca-4ba5-9b1f-38f72d10e4a3"){const o=de({id:`${r.id}--${F.PropertyImplementsNonAbstact}`,message:`Property "${x(r,r.project)}" with id "${r.id}" implements a non-abstract property "${x(r,r.project)}" with id "${r.id}".`,issue:null,severity:D.Error,code:F.PropertyImplementsNonAbstact,entity:r});s.push(o.error)}return s}function t1(r){const a=[];if(!r.implements)return a;const e=r.implements;if(!e.abstract){const i=de({id:`${r.id}--${F.PropertyImplementsNonAbstact}`,message:`Property "${x(r,r.project)}" with id "${r.id}" implements a non-abstract property "${x(e,r.project)}" with id "${e.id}".`,issue:null,severity:D.Error,code:F.PropertyImplementsNonAbstact,entity:r});a.push(i.error)}if(r.static&&!e.static){const i=de({id:`${r.id}--${F.NonStaticPropertyImplementsStatic}`,message:`Static property "${x(r,r.project)}" with id "${r.id}" implements a non-static property "${x(e,r.project)}" with id "${e.id}".`,issue:null,severity:D.Error,code:F.NonStaticPropertyImplementsStatic,entity:r});a.push(i.error)}if(!r.static&&e.static){const i=de({id:`${r.id}--${F.StaticPropertyImplementsNonStatic}`,message:`Non-static property "${x(r,r.project)}" with id "${r.id}" implements a static property "${x(e,r.project)}" with id "${e.id}".`,issue:null,severity:D.Error,code:F.StaticPropertyImplementsNonStatic,entity:r});a.push(i.error)}if(!Ri(r.dataType,e.dataType)){const i=de({id:`${r.id}--${F.PropertyImplementsIncompatibleType}`,message:`Property "${x(r,r.project)}" with id "${r.id}" implements a property "${x(e,r.project)}" with id "${e.id}" that has an incompatible data type.`,issue:null,severity:D.Error,code:F.PropertyImplementsIncompatibleType,entity:r});a.push(i.error)}return He(r.errors,a)}const vJ=Object.freeze(Object.defineProperty({__proto__:null,validate:e1,validateImplementation:t1},Symbol.toStringTag,{value:"Module"}));function TJ(r,a){const e=[];if(r.parent){const i=a.get(r.parent);if(!i)e.push(new w({id:`${r.id}--${r.parent}--${R.ReferencedEntityNotFound}`,code:R.ReferencedEntityNotFound,severity:D.Error,message:`Entity of type "${r.type}" with id "${r.id}", is referencing an entity with id "${r.parent}" that isn't yet found in the project. Perhaps it should be created first. Or perhaps the ID is incorrect.`,issue:null}));else{const s=rn(i);if(s){const l=i!==s?`The entity of type '${r.type}' with id '${r.id}' have 'parent' with id '${r.parent}' because the entity belongs to a built-in '${s.type}' entity with id '${s.id}' (${x(s,i.project)}) higher up in the tree.`:`The entity of type '${r.type}' with id '${r.id}' have 'parent' with id '${r.parent}' because it is a built-in entity of type ${s.type}.`;e.push(new w({id:`${r.id}--${R.InvalidBuiltInEntityReference}`,code:R.InvalidBuiltInEntityReference,severity:D.Error,message:l,issue:null}))}else if(![n.DefinitionEntity].includes(i.type))e.push(new w({id:`${r.id}--${r.parent}--${R.InvalidParentReference}`,code:R.InvalidParentReference,severity:D.Error,message:`Entity of type "${r.type}" with id "${r.id}", has a parent reference that isn't pointing to an entity of type 'definition-entity'.`,issue:null}));else{const o=kt(i).filter(d=>!d.interactive);if(o.length){let d=o.length>1?`The entity of type '${r.type}' with id '${r.id}' can't be added to the 'parent' entity with id '${i.id}' because it extends or implements multiple '${n.BuiltInBaseEntity}' entities that are non-interactive ("${se(o.map(u=>x(u,u.project)),'", "','" and "')}").`:`The entity of type '${r.type}' with id '${r.id}' can't be added to the 'parent' entity with id '${i.id}' because it extends or implements a '${n.BuiltInBaseEntity}' entity that is non-interactive ("${x(o[0],o[0].project)}").`;d+=`
43
43
  ${Qr}`,e.push(new w({id:`${r.id}--${R.NonInteractiveEntityReferenced}`,code:R.NonInteractiveEntityReferenced,severity:D.Error,message:d,issue:null}))}else if(r.implements){const d=a.get(r.implements);if(r.id===r.implements)return e.push(new w({id:`${r.id}--${r.implements}--${R.SelfReference}`,code:R.SelfReference,severity:D.Error,message:`Entity of type "${r.type}" with id "${r.id}", has a reference to itself at 'implements'. This is not allowed. Change the reference string or the 'entityId' property of the reference object.`,issue:null})),e;if(!d)e.push(new w({id:`${r.id}--${r.implements}--${R.ReferencedEntityNotFound}`,code:R.ReferencedEntityNotFound,severity:D.Error,message:`Entity of type "${r.type}" with id "${r.id}", is referencing an entity with id "${r.implements}" that isn't yet found in the project. Perhaps it should be created first. Or perhaps the ID is incorrect.`,issue:null}));else{const u=i.properties.find(y=>{var c;return((c=y.implements)==null?void 0:c.id)===r.implements});u?e.push(new w({id:`${r.id}--${$.PropertyOverwritesOtherSiblingWithSameImplementation}`,code:$.PropertyOverwritesOtherSiblingWithSameImplementation,severity:D.Error,message:`The property with id "${r.id}" is trying to implement the property with id "${r.implements}", but the parent entity already has a property with id '${u.id}' that implements the same base property.`,issue:null})):[n.Property].includes(d.type)?d.abstract||e.push(new w({id:`${r.id}--${r.implements}--${R.InvalidImplementsReference}`,code:R.InvalidImplementsReference,severity:D.Error,message:`Entity of type "${r.type}" with id "${r.id}", has an 'implements' reference that isn't pointing to an abstract entity.`,issue:null})):e.push(new w({id:`${r.id}--${r.implements}--${R.InvalidImplementsReference}`,code:R.InvalidImplementsReference,severity:D.Error,message:`Entity of type "${r.type}" with id "${r.id}", has an 'implements' reference that isn't pointing to an entity of type 'property'.`,issue:null}))}}}}}const t=At(r,{},a);return e.push(...t.errors),e}class at{constructor(a){f(this,"version");f(this,"previousVersion",null);f(this,"createdAt");f(this,"deleted",!1);f(this,"author");this.version=a.version,this.previousVersion=a.previousVersion,this.createdAt=T(a.createdAt).toISOString(),this.deleted=a.deleted,this.author=a.author}metaSync(a){this.deleted=a.deleted!==void 0?a.deleted:this.deleted}}var wc=(r=>(r.Manual="manual",r.Automatic="automatic",r))(wc||{}),b=(r=>(r.Added="added",r.Updated="updated",r.Removed="removed",r.Affected="affected",r))(b||{});class A{constructor(a,e,t,i,s=!1,l=""){f(this,"id",m.UUID.uuid());f(this,"seenEntities",[]);f(this,"added",{});f(this,"updated",{});f(this,"removed",{});f(this,"affected",{});f(this,"self",null);f(this,"author");f(this,"timestamp");f(this,"open",!0);f(this,"dirty",!0);f(this,"type","manual");f(this,"autoclose",!1);f(this,"autoCloseActionName","");f(this,"project");if(this.project=a,this.author=e||m.sessionAuthor||"",this.timestamp=t,this.self=i,this.autoclose=s,this.autoCloseActionName=l,this.autoclose&&!this.autoCloseActionName)throw new Error("Auto-close change-set must have an auto-close action name.")}get isEmpty(){return Object.keys(this.added).length===0&&Object.keys(this.updated).length===0&&Object.keys(this.removed).length===0}get isValid(){var a;return!(this.isEmpty&&this.self&&!this.affected[(a=this.self)==null?void 0:a.id])}get list(){return[...Object.values(this.added),...Object.values(this.updated),...Object.values(this.removed)]}get listAdded(){return Object.values(this.added)}get listUpdated(){return Object.values(this.updated)}get listRemoved(){return Object.values(this.removed)}get listAffected(){return Object.values(this.affected)}get addedIds(){return Object.keys(this.added)}get updatedIds(){return Object.keys(this.updated)}get removedIds(){return Object.keys(this.removed)}get affectedIds(){return Object.keys(this.affected)}discardOrphans(){const a=[...this.addedIds,...this.updatedIds],e=this.project.toFlatIds(),t=_i(),i=e.filter(l=>!t.includes(l));a.filter(l=>!i.includes(l)).forEach(l=>{this.remove(l)})}captureAllChangesInVersionInstances(){[...this.addedIds,...this.updatedIds].forEach(e=>{const t=this.project.get(e);if(!t)throw new Error(`Entity with id "${e}" not found in the project state when capturing version for change-set.`);const i=this.get(e);t.version===i.version&&t.captureVersion()}),this.removedIds.forEach(e=>{const t=this.project.getDeleted(e);if(!t)throw new Error(`Entity with id "${e}" not found in the project state when capturing version for change-set.`);const i=this.get(e);t.version===i.version&&t.captureVersion()})}async attemptAutocloseAsync(a,e){var t;return this.autoclose&&this.autoCloseActionName&&this.autoCloseActionName===a&&(this.self&&e===((t=this.self)==null?void 0:t.id)||!this.self)&&await this.closeAsync(),this}async closeAsync(){return!this.isValid&&this.self&&!this.added[this.self.id]&&!this.updated[this.self.id]&&this.removed[this.self.id],this.discardOrphans(),this.sanitize(),this.recursiveCaptureUpstreamVersions(),this.captureAllChangesInVersionInstances(),this.recursiveCaptureUpstreamVersions(),this.open=!1,this.isEmpty?(console.warn(`Empty change-set (${this.id}) discarded upon closing.`),this.project.discardChangeSet(this),this.project.closePendingChangeSets(),this):(await this.project.closeChangeSet(this),this)}attemptAutoclose(a,e){var t;return this.autoclose&&this.autoCloseActionName&&this.autoCloseActionName===a&&(this.self&&e===((t=this.self)==null?void 0:t.id)||!this.self)&&this.close(),this}recursiveCaptureUpstreamVersions(){[...this.addedIds,...this.updatedIds,...this.removedIds].forEach(e=>{const t=this.get(e),{added:i,updated:s,removed:l,affected:o}=t.recursiveCaptureUpstreamVersions(this.timestamp);for(const d of i)this.add(d,"added");for(const d of s)this.add(d,"updated");for(const d of l)this.add(d,"removed");for(const d of o)this.add(d,"affected")})}sanitize(){this.listAdded.forEach(a=>{a.previousVersion=null})}close(){if(!this.isValid&&this.self&&!this.added[this.self.id]&&!this.updated[this.self.id]&&this.removed[this.self.id],this.discardOrphans(),this.sanitize(),this.captureAllChangesInVersionInstances(),this.recursiveCaptureUpstreamVersions(),this.captureAllChangesInVersionInstances(),this.open=!1,this.isEmpty)return console.warn(`Empty change-set (${this.id}) discarded upon closing.`),this.project.discardChangeSet(this),this.project.closePendingChangeSets(),this;if(this.added[this.project.id]&&this.updatedIds.length)throw new Error("No 'updated' entities should be present in the change-set when the project entity is in the 'added' list. New projects can only have newly added entities");if(this.added[this.project.id]&&this.removedIds.length)throw new Error("No 'removed' entities should be present in the change-set when the project entity is in the 'added' list. New projects can only have newly added entities");if(!this.updated[this.project.id]&&!this.added[this.project.id])throw new Error("Change-set must also have the project entity as 'updated' or 'added'. All changes must propagate upstream until the root project entity.");return this.project.closeChangeSet(this),this}get(a){return this.added[a]?this.added[a]:this.updated[a]?this.updated[a]:this.removed[a]?this.removed[a]:null}remove(a){return this.has(a)&&(delete this.added[a],delete this.updated[a],delete this.removed[a],delete this.affected[a],this.seenEntities=this.seenEntities.filter(e=>e!==a)),this}add(a,e){var l,o,d;if(!this.open||!this.dirty)return this;const t=Array.from(new Set([...this.project.getAllBuiltInIds(),..._i()]));if(t.includes(a.id))return this;if(!rd(a,{...this.project.instances,...this.project.builtInInstances}).every(u=>!t.includes(u)))return this;if(this.seenEntities.indexOf(a.id)===-1&&this.seenEntities.push(a.id),e==="removed"){if(this.added[a.id])return delete this.added[a.id],this.seenEntities=this.seenEntities.filter(y=>y!==a.id),delete this.project.deletedInstances[a.id],this;if(this.updated[a.id]&&delete this.updated[a.id],this.affected[a.id]&&delete this.affected[a.id],!this.hasRemoved(a.id)){a.increaseVersion(this.timestamp);const{added:y,updated:c,removed:I,affected:E}=a.recursiveCaptureUpstreamVersions(this.timestamp);for(const O of y)this.add(O,"added");for(const O of c)this.add(O,"updated");for(const O of I)this.add(O,"removed");for(const O of E)this.add(O,"affected")}a.captureVersion();const u=(l=a.knownVersions)==null?void 0:l.get(a.version);if(!u)throw Error(`Version ${a.version} should have a cached version instance but it wasn't found when adding entity to change-set`);return this.removed[a.id]=u,this}if(e==="added"){if(this.removed[a.id])return this;if(this.updated[a.id]&&delete this.updated[a.id],this.affected[a.id]&&delete this.affected[a.id],!this.hasAdded(a.id)){const{added:y,updated:c,removed:I,affected:E}=a.recursiveCaptureUpstreamVersions(this.timestamp);for(const O of y)this.add(O,"added");for(const O of c)this.add(O,"updated");for(const O of I)this.add(O,"removed");for(const O of E)this.add(O,"affected")}a.previousVersion=null,a.captureVersion();const u=(o=a.knownVersions)==null?void 0:o.get(a.version);if(!u)throw Error(`Version ${a.version} should have a cached version instance but it wasn't found when adding entity to change-set`);return this.added[a.id]=u,this}if(e==="updated"){if(this.removed[a.id])return this;if(this.added[a.id])return this;if(this.affected[a.id]&&delete this.affected[a.id],!this.hasUpdated(a.id)){a.increaseVersion(this.timestamp);const{added:y,updated:c,removed:I,affected:E}=a.recursiveCaptureUpstreamVersions(this.timestamp);for(const O of y)this.add(O,"added");for(const O of c)this.add(O,"updated");for(const O of I)this.add(O,"removed");for(const O of E)this.add(O,"affected")}a.captureVersion();const u=(d=a.knownVersions)==null?void 0:d.get(a.version);if(!u)throw Error(`Version ${a.version} should have a cached version instance but it wasn't found when adding entity to change-set`);return this.updated[a.id]=u,this}if(e==="affected"){if(this.removed[a.id])return this;if(this.added[a.id])return this;if(this.updated[a.id])return this;this.affected[a.id]=a}return this}toJSON(){const a={},e={},t={},i=new Set;for(const s of Object.values(this.added))a[s.id]=s.toShallowJSON();for(const s of Object.values(this.updated))e[s.id]=s.toShallowJSON();for(const s of Object.values(this.removed))t[s.id]=s.toShallowJSON();for(const s of Object.values(this.affected))i.add(s.id);return{added:a,updated:e,removed:t,affected:Array.from(i),self:this.self?this.self.toShallowJSON():null,seenEntities:this.seenEntities}}has(a){return!!this.added[a]||!!this.removed[a]||!!this.updated[a]||!!this.affected[a]}hasAdded(a){return!!this.added[a]}hasUpdated(a){return!!this.updated[a]}hasRemoved(a){return!!this.removed[a]}hasAffected(a){return!!this.affected[a]}}function IJ(r){return new Set([...Object.keys(r.added),...Object.keys(r.updated),...Object.keys(r.removed),...Array.from(r.affected)])}var i1=(r=>(r.Implements="implements",r.DataTypeEntity="data-type-entity",r))(i1||{});const Ae=class Ae extends at{constructor(e,t){super(e);f(this,"initialData");f(this,"id");f(this,"name");f(this,"description",null);f(this,"private");f(this,"abstract");f(this,"index");f(this,"static");f(this,"required");f(this,"constant",!1);f(this,"type",n.Property);f(this,"hidden",!1);f(this,"defaultValue",null);f(this,"dataType",null);f(this,"implements",null);f(this,"project");f(this,"errors",[]);f(this,"parent");f(this,"detachedDependents",{});f(this,"knownVersions",null);f(this,"activeVersion",!1);f(this,"initialized",!1);f(this,"startedInitialization",!1);f(this,"suggestion",!1);this.initialData=e,this.project=t,this.id=e.id,this.name=e.name,this.description=e.description,this.private=e.private,this.abstract=e.abstract,this.index=e.index,this.static=e.static,this.required=e.required||!1,this.hidden=e.hidden||!1,this.constant=e.constant||!1}static new(){return{id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.Property,name:"",description:"",dataType:null,implements:null,private:!1,abstract:!1,static:!1,constant:!1,hidden:!1,index:0,required:!1,defaultValue:null,parent:null}}static fromGenerationTarget(e,t){const i=_(e.parent),s=t.get(i);let l=null;if(e.implements){const u=_(e.implements);l=t.get(u)}const o={id:e.id,version:m.UUID.uuid(),createdAt:T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,name:e.name,type:n.Property,index:s.properties.length,private:e.private||!1,abstract:e.abstract||!1,static:e.static||!1,required:e.required||!1,constant:e.constant||!1,hidden:!1,description:e.description,defaultValue:null,implements:l,dataType:null,parent:s},d=V(o,t);return d.setParent(s,null),d.initChildren(null),d}static validateGenerationTarget(e,t){let i=JSON.parse(JSON.stringify(e));const s=[],l=TJ(i,t),o=Rc(i,t);return s.push(...l,...o,...ut(i)),{errors:s,modifiedData:i}}get isExtendedProperty(){const e=this.parent.allBasePropertiesFromExtendedAndImplementedEntities.find(t=>t.name===this.name);return!!e&&e.id!==this.id&&!e.abstract}validateGeneratedUpdate(e){const t=[];return e.parent&&t.push(new w({id:`${this.id}--${R.InvalidParentUpdate}`,code:R.InvalidParentUpdate,severity:D.Error,message:`Entity of type '${this.type}' with id '${this.id}' cannot have the 'parent' property updated, as it would mean moving the '${this.type}' entity to another parent entity.
44
44
  This is likely an incorrect strategy, either the '${this.type}' entity doesn't need to be updated or it should be deleted and a new one created in the desired parent.`,issue:null})),(e.readsValue||e.writesValue)&&t.push(new w({id:`${this.id}--${$.InvalidObjectStructure}`,code:$.InvalidObjectStructure,severity:D.Error,message:`Entity of type '${this.type}' with id '${this.id}' is not a value reading or writing entity.
45
- ${kl}`,issue:null})),{errors:t,modifiedData:e}}subscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]||(this.detachedDependents[t.entity.id]=t)}),this}syncDependents(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-dependents"))){const t=[],i=[],s=[],l=[];return Object.values(this.detachedDependents).forEach(o=>{const d=o.entity.afterAllChildrenInitialized(e);t.push(...d.updated),i.push(...d.added),s.push(...d.removed),l.push(...d.affected)}),e==null||e.attemptAutoclose("sync-dependents",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];return t==="implements"&&(this.setImplements(null,i),s.push(this)),{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}onDetachedDependencyRestored(e,t,i){const s=[],l=[],o=[],d=[];return t==="implements"&&(this.setImplements(e,i),s.push(this)),{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}subscribeToDependencies(){var e,t,i,s,l;return(t=(e=this.implements)==null?void 0:e.subscribeDependents)==null||t.call(e,[{entity:this,field:"implements"}]),(l=(s=(i=this.dataType)==null?void 0:i.entity)==null?void 0:s.subscribeDependents)==null||l.call(s,[{entity:this,field:"data-type-entity"}]),this}increaseVersion(e){if(e&&!T(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&T(e).isSame(T(this.createdAt))?this:(this.previousVersion=this.version,this.version=m.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new Ae(this,this.project);return e.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,e):new Map([[this.version,e]]),e.defaultValue=this.defaultValue,e.dataType=this.dataType,e.implements=this.implements,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],i=[],s=[],l=[];if(this.parent&&this.parent.type!==n.PrimitiveEntity&&this.parent.type!==n.BuiltInBaseEntity){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),i.push(...o.added),s.push(...o.removed)}return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}async restoreVersion(e){var d;const t=[],i=[],s=[],l=[];if(this.version===e)return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this};if(!this.knownVersions){const u=new Map;for(const[y,c]of this.knownVersions||new Map){if(u.set(y,c),c.activeVersion=!1,c.knownVersions)for(const[I,E]of c.knownVersions)u.set(I,E);c.knownVersions=null}}let o=(d=this.knownVersions)==null?void 0:d.get(e);if(!o){const u=await this.APILoadVersion({},e);if(!u)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new Ae(u,this.project)}return this.metaSync(o.toShallowJSON(),null),this.defaultValue=o.defaultValue,this.dataType=o.dataType,this.implements=o.implements,this.parent=o.parent,{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}hydrateAncestors(){const e=[],t=[],i=[],s=[];if(this.initialData.parent){const l=_(this.initialData.parent),o=this.project.get(l);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${xt(this.type)} with id '${this.id}' has a parent reference "${l}" which is missing in the project`)}else throw new Error(`${xt(this.type)} with id '${this.id}' is missing a parent reference`);if(this.initialData.implements){const l=_(this.initialData.implements),o=this.project.get(l);o&&(this.setImplements(o,null),e.push(o))}return{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],i=[],s=[],l=[];return this.initialized=!0,this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addSelfToProject(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-self-to-project"))){const t=[this],i=[],s=[],l=[];return this.parent.addProperty(this),t.push(this.parent),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}setParent(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"set-parent"))){var i;return((i=this.parent)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,b.Updated),t==null||t.attemptAutoclose("set-parent",this.id))),this}setImplements(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"set-implements"))){var i;return((i=this.implements)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.implements=e,t&&(t==null||t.add(this,b.Updated),t==null||t.attemptAutoclose("set-implements",this.id))),this}initChildren(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"init-children"))){if(this.initialized||this.startedInitialization)return this;if(this.startedInitialization=!0,this.initialData.defaultValue&&(this.defaultValue=V(this.initialData.defaultValue,this.project),this.defaultValue.setParent(this,null),this.defaultValue.initChildren(e)),this.initialData.dataType){const t=V(this.initialData.dataType,this.project);t.setParent(this,null),t.initChildren(e),this.dataType=t}if(this.initialData.implements){const t=V(this.initialData.implements,this.project);this.setImplements(t,null)}return this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"meta-sync"))){const i=pt(this,e),s=this.toMeta();return this.name=e.name!==void 0?e.name:s.name,this.description=e.description!==void 0?e.description:s.description,this.abstract=e.abstract!==void 0?e.abstract:s.abstract,this.private=e.private!==void 0?e.private:s.private,this.index=e.index||(e.index!==0?s.index:0),this.static=e.static!==void 0?e.static:s.static,this.hidden=e.hidden!==void 0?e.hidden:s.hidden,this.constant=e.constant!==void 0?e.constant:s.constant,this.required=e.required!==void 0?e.required:s.required,super.metaSync(e),e.deleted===!0&&!s.deleted?t==null||t.add(this,b.Removed):e.deleted===!1&&s.deleted?t==null||t.add(this,b.Added):i&&(t==null||t.add(this,b.Updated)),t==null||t.attemptAutoclose("meta-sync",this.id),this}async APILoad(e=j,...t){return await Ae.repository.APILoad(this.id,...t),this}async APICreate(e=j,...t){return await Ae.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=j,...t){return await Ae.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=j,...t){return await Ae.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=j,...t){return await Ae.repository.APIClone(this.id,...t),this}async APILoadVersion(e=j,t,...i){return await Ae.repository.APILoadVersion(this.id,t,...i)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-entity"))){const i=[],s=[],l=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(s.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(d=>{const{updated:u,removed:y,added:c}=d.entity.onDetachedDependencyRemoved(this,d.field,t);i.push(...u),s.push(...y),l.push(...c)}),this.defaultValue){const{updated:d,removed:u}=this.defaultValue.remove({ignoreUpstream:!0},t);i.push(...d),s.push(...u)}if(this.dataType){const{updated:d,removed:u}=this.dataType.remove({ignoreUpstream:!0},t);i.push(...d),s.push(...u)}return e||this.parent.type===n.DefinitionEntity&&(this.parent.removeProperty(this),i.push(this.parent)),t==null||t.attemptAutoclose("remove-entity",this.id),{added:p(l),updated:p(i),removed:p(s),affected:p(o),self:this}}restore({}={},e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"restore-entity"))){const t=[],i=[],s=[],l=[];if(e!=null&&e.hasAdded(this.id))return e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),this.defaultValue){const{updated:o}=this.defaultValue.restore({},e);i.push(...o)}if(this.dataType){const{updated:o}=this.dataType.restore({},e);i.push(...o)}return this.parent.type===n.DefinitionEntity&&(this.parent.addProperty(this),i.push(this.parent)),e==null||e.attemptAutoclose("restore-entity",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(l),self:this}}toFlat(e=new Set){var i,s;return e.has(this.id)?[]:(e.add(this.id),[this,...((i=this.defaultValue)==null?void 0:i.toFlat(e))||[],...((s=this.dataType)==null?void 0:s.toFlat(e))||[],...this.parent.toFlat(e)])}toFlatIds(e=new Set){var i,s;return e.has(this.id)?[]:(e.add(this.id),[this.id,...((i=this.defaultValue)==null?void 0:i.toFlatIds(e))||[],...((s=this.dataType)==null?void 0:s.toFlatIds(e))||[],...this.parent.toFlatIds(e)])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,description:this.description,index:this.index,hidden:this.hidden,private:this.private,abstract:this.abstract,required:this.required,constant:this.constant,static:this.static,type:this.type,name:this.name}}toJSON(e=new Set){var t,i,s;return e.has(this.id)?this.toReference():(e.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,index:this.index,private:this.private,required:this.required,static:this.static,constant:this.constant,abstract:this.abstract,hidden:this.hidden,defaultValue:((t=this.defaultValue)==null?void 0:t.toJSON(e))||null,dataType:((i=this.dataType)==null?void 0:i.toJSON(e))||null,implements:((s=this.implements)==null?void 0:s.toJSON(e))||null,parent:this.parent.toReference()})}toJSONClone(e=J){var i,s,l,o,d,u,y;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||ht(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(s=e.seenEntities)!=null&&s.has(t)||(l=e.seenEntities)!=null&&l.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(d=e.seenEntities)==null||d.add(this.id),{id:t,version:m.UUID.uuid(),createdAt:e.timestamp||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:this.type,name:this.name,description:this.description,index:this.index,private:this.private,required:this.required,static:this.static,constant:this.constant,abstract:this.abstract,hidden:this.hidden,defaultValue:((u=this.defaultValue)==null?void 0:u.toJSONClone({...e,newId:null}))||null,dataType:((y=this.dataType)==null?void 0:y.toJSONClone({...e,newId:null}))||null,implements:(()=>{var c;return this.implements&&this.project.getBuiltIn(this.implements.id)?this.implements.toJSON():((c=this.implements)==null?void 0:c.toJSONClone({...e,newId:null}))||null})(),parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps})})}toReference(e=J){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+m.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=J){var i,s,l,o;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,name:this.name,description:this.description,type:this.type,index:this.index,private:this.private,required:this.required,abstract:this.abstract,static:this.static,constant:this.constant,hidden:this.hidden,defaultValue:((s=this.defaultValue)==null?void 0:s.toReference(e))||null,dataType:((l=this.dataType)==null?void 0:l.toReference(e))||null,implements:((o=this.implements)==null?void 0:o.toReference(e))||null,parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){var i,s,l;return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...((i=this.defaultValue)==null?void 0:i.toFlatJSON(e))||[],...((s=this.dataType)==null?void 0:s.toFlatJSON(e))||[],...((l=this.implements)==null?void 0:l.toFlatJSON(e))||[],...this.parent.toFlatJSON(e)])}toGenerationTarget(){var e;return{id:this.id,name:this.name,description:this.description,type:this.type,private:this.private,required:this.required,abstract:this.abstract,static:this.static,implements:((e=this.implements)==null?void 0:e.id)||null,parent:this.parent.id}}toFlatGenerationTarget(e=new Set){var i,s;return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...((i=this.defaultValue)==null?void 0:i.toFlatGenerationTarget(e))||[],...((s=this.dataType)==null?void 0:s.toFlatGenerationTarget(e))||[]])}clearErrors(){var e,t;return this.errors=[],(e=this.defaultValue)==null||e.clearErrors(),(t=this.dataType)==null||t.clearErrors(),this}validate(){return this.errors=e1(this),this.errors.length,{success:!0,error:null,data:null}}getErrors(){var t,i;return[...this.errors,...((t=this.defaultValue)==null?void 0:t.getErrors())||[],...((i=this.dataType)==null?void 0:i.getErrors())||[]]}getShallowErrors(){return this.errors}clone(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"clone-entity")),t=null,i=null,s=!0){var E,O;let l=mt(t,this);const o=i||m.UUID.uuid();let d=t||this.parent;const u={hidden:!1,id:o,version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:(e==null?void 0:e.author)||"1",previousVersion:null,deleted:!1,type:this.type,name:this.name,description:this.description,index:this.index,private:this.private,constant:this.constant,required:this.required,abstract:this.abstract,static:this.static,defaultValue:null,dataType:null,implements:this.implements,parent:d},y=ct(u,l);s&&y.subscribe(),y.setParent(d,null),y.initChildren(e),e==null||e.add(y,b.Added);const c=((E=this.dataType)==null?void 0:E.clone(e,y,m.UUID.uuid(),s))||null;c&&y.setDataType(c);const I=(O=this.defaultValue)==null?void 0:O.clone(e,y,m.UUID.uuid(),s);return y.defaultValue=I||null,this.implements&&(y.implements=this.implements),y.addSelfToProject(null),e==null||e.attemptAutoclose("clone-entity",this.id),y}setDataType(e){return this.dataType=e,this}removeDataType(){return this.dataType=null,this}getDataType(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"get-data-type"))){return this.dataType}getDefaultValue(){return this.defaultValue}setDefaultValue(e){return this.defaultValue=e,this}};f(Ae,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>e,APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...i)=>null}),f(Ae,"type",n.Property),f(Ae,"USER_MANAGED_PARENT_TYPES",[n.DefinitionEntity]),f(Ae,"PARENT_TYPES",[...Ae.USER_MANAGED_PARENT_TYPES,n.PrimitiveEntity,n.BuiltInBaseEntity]),f(Ae,"MUTABLE_BASE_PROPERTIES",["name","description","private","abstract","static","required","constant"]),f(Ae,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),f(Ae,"BASE_PROPERTIES",[...Ae.MUTABLE_BASE_PROPERTIES,...Ae.INMUTABLE_BASE_PROPERTIES]),f(Ae,"MUTABLE_META_PROPERTIES",[...Ae.MUTABLE_BASE_PROPERTIES,"index"]),f(Ae,"INMUTABLE_META_PROPERTIES",[...Ae.INMUTABLE_BASE_PROPERTIES]),f(Ae,"META_PROPERTIES",[...Ae.MUTABLE_META_PROPERTIES,...Ae.INMUTABLE_META_PROPERTIES]),f(Ae,"MUTABLE_UPSTREAM_PROPERTIES",[]),f(Ae,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","implements"]),f(Ae,"UPSTREAM_PROPERTIES",[...Ae.MUTABLE_UPSTREAM_PROPERTIES,...Ae.INMUTABLE_UPSTREAM_PROPERTIES]),f(Ae,"MUTABLE_DOWNSTREAM_PROPERTIES",["dataType"]),f(Ae,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),f(Ae,"DOWNSTREAM_PROPERTIES",[...Ae.MUTABLE_DOWNSTREAM_PROPERTIES,...Ae.INMUTABLE_DOWNSTREAM_PROPERTIES]),f(Ae,"PROPERTIES",[...Ae.META_PROPERTIES,...Ae.UPSTREAM_PROPERTIES,...Ae.DOWNSTREAM_PROPERTIES]);let Ur=Ae;function r1(r){var s;const a=m5(),e=r.toJSON();a.safeParse(e).success,(s=r.dataType)==null||s.validate();const i=[];if(r.id==="iterate-over-employee-list-continue-statement-employee-dto-output-decl-id"){const l=de({id:`${r.id}--${F.PropertyImplementsNonAbstact}`,message:`Property "${x(r,r.project)}" with id "${r.id}" implements a non-abstract property "${x(r,r.project)}" with id "${r.id}".`,issue:null,severity:D.Error,code:F.PropertyImplementsNonAbstact,entity:r});i.push(l.error)}return He(r.errors,i)}const EJ=Object.freeze(Object.defineProperty({__proto__:null,validate:r1},Symbol.toStringTag,{value:"Module"}));var n1=(r=>(r.Implements="implements",r.DataTypeEntity="data-type-entity",r))(n1||{});const be=class be extends at{constructor(e,t){super(e);f(this,"initialData");f(this,"id");f(this,"name");f(this,"description",null);f(this,"index");f(this,"required");f(this,"constant",!0);f(this,"isError");f(this,"type",n.ReturnDeclaration);f(this,"defaultValue",null);f(this,"dataType",null);f(this,"readsValue",null);f(this,"implements",null);f(this,"project");f(this,"errors",[]);f(this,"parent");f(this,"detachedDependents",{});f(this,"knownVersions",null);f(this,"activeVersion",!1);f(this,"initialized",!1);f(this,"startedInitialization",!1);f(this,"suggestion",!1);this.initialData=e,this.project=t,this.id=e.id,this.index=e.index,this.name=e.name,this.description=e.description,this.required=e.required,this.constant=!0,this.isError=e.isError}static new(){return{id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.ReturnDeclaration,name:"",description:"",dataType:null,index:0,required:!1,constant:!0,isError:!1,implements:null,readsValue:null,defaultValue:null,parent:null}}static fromGenerationTarget(e,t){const i=_(e.parent),s=t.get(i);let l=null;if(e.readsValue){const u=_(e.readsValue);l=t.get(u)}const o={id:e.id,version:m.UUID.uuid(),createdAt:T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,name:e.name,type:n.ReturnDeclaration,index:s.outputs.length,isError:!1,description:e.description,defaultValue:null,implements:null,required:e.required,constant:!0,readsValue:l,dataType:null,parent:s},d=V(o,t);return d.setParent(s,null),d.initChildren(null),d}static validateGenerationTarget(e,t){var d,u;let i=JSON.parse(JSON.stringify(e));const s=[],l=At(i,{parent:{list:!1,types:[n.ReturnStatement,n.Search,n.BreakStatement,n.ContinueStatement]}},t),o=Oc(i,t);if(i=l.modifiedData,i.parent){const y=t.get(_(i.parent));if(y&&[n.BreakStatement,n.ContinueStatement].includes(y.type)){const c=y,I=c.parent,E=[...I.breakStatements.filter(P=>P.id!==y.id),...I.continueStatements.filter(P=>P.id!==y.id)];if(c.outputs.length)s.push(new w({id:`${i.id}--${$.NoOverlapWithImplementedSignature}`,code:$.NoOverlapWithImplementedSignature,severity:D.Error,message:`Entity of type '${n.ReturnDeclaration}' with id '${i.id}' cannot be added to the parent entity of type '${c.type}' with id '${c.id}'. This '${c.type}' already has return declarations.
45
+ ${kl}`,issue:null})),{errors:t,modifiedData:e}}subscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]||(this.detachedDependents[t.entity.id]=t)}),this}syncDependents(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-dependents"))){const t=[],i=[],s=[],l=[];return Object.values(this.detachedDependents).forEach(o=>{const d=o.entity.afterAllChildrenInitialized(e);t.push(...d.updated),i.push(...d.added),s.push(...d.removed),l.push(...d.affected)}),e==null||e.attemptAutoclose("sync-dependents",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];return t==="implements"&&(this.setImplements(null,i),s.push(this)),{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}onDetachedDependencyRestored(e,t,i){const s=[],l=[],o=[],d=[];return t==="implements"&&(this.setImplements(e,i),s.push(this)),{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}subscribeToDependencies(){var e,t,i,s,l;return(t=(e=this.implements)==null?void 0:e.subscribeDependents)==null||t.call(e,[{entity:this,field:"implements"}]),(l=(s=(i=this.dataType)==null?void 0:i.entity)==null?void 0:s.subscribeDependents)==null||l.call(s,[{entity:this,field:"data-type-entity"}]),this}increaseVersion(e){if(e&&!T(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&T(e).isSame(T(this.createdAt))?this:(this.previousVersion=this.version,this.version=m.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new Ae(this,this.project);return e.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,e):new Map([[this.version,e]]),e.defaultValue=this.defaultValue,e.dataType=this.dataType,e.implements=this.implements,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],i=[],s=[],l=[];if(this.parent&&this.parent.type!==n.PrimitiveEntity&&this.parent.type!==n.BuiltInBaseEntity){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),i.push(...o.added),s.push(...o.removed)}return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}async restoreVersion(e){var d;const t=[],i=[],s=[],l=[];if(this.version===e)return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this};if(!this.knownVersions){const u=new Map;for(const[y,c]of this.knownVersions||new Map){if(u.set(y,c),c.activeVersion=!1,c.knownVersions)for(const[I,E]of c.knownVersions)u.set(I,E);c.knownVersions=null}}let o=(d=this.knownVersions)==null?void 0:d.get(e);if(!o){const u=await this.APILoadVersion({},e);if(!u)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new Ae(u,this.project)}return this.metaSync(o.toShallowJSON(),null),this.defaultValue=o.defaultValue,this.dataType=o.dataType,this.implements=o.implements,this.parent=o.parent,{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}hydrateAncestors(){const e=[],t=[],i=[],s=[];if(this.initialData.parent){const l=_(this.initialData.parent),o=this.project.get(l);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${xt(this.type)} with id '${this.id}' has a parent reference "${l}" which is missing in the project`)}else throw new Error(`${xt(this.type)} with id '${this.id}' is missing a parent reference`);if(this.initialData.implements){const l=_(this.initialData.implements),o=this.project.get(l);o&&(this.setImplements(o,null),e.push(o))}return{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],i=[],s=[],l=[];return this.initialized=!0,this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addSelfToProject(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-self-to-project"))){const t=[this],i=[],s=[],l=[];return this.parent.addProperty(this),t.push(this.parent),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}setParent(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"set-parent"))){var i;return((i=this.parent)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,b.Updated),t==null||t.attemptAutoclose("set-parent",this.id))),this}setImplements(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"set-implements"))){var i;return((i=this.implements)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.implements=e,t&&(t==null||t.add(this,b.Updated),t==null||t.attemptAutoclose("set-implements",this.id))),this}initChildren(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"init-children"))){if(this.initialized||this.startedInitialization)return this;if(this.startedInitialization=!0,this.initialData.defaultValue&&(this.defaultValue=V(this.initialData.defaultValue,this.project),this.defaultValue.setParent(this,null),this.defaultValue.initChildren(e)),this.initialData.dataType){const t=V(this.initialData.dataType,this.project);t.setParent(this,null),t.initChildren(e),this.dataType=t}if(this.initialData.implements){const t=V(this.initialData.implements,this.project);this.setImplements(t,null)}return this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"meta-sync"))){const i=pt(this,e),s=this.toMeta();return this.name=e.name!==void 0?e.name:s.name,this.description=e.description!==void 0?e.description:s.description,this.abstract=e.abstract!==void 0?e.abstract:s.abstract,this.private=e.private!==void 0?e.private:s.private,this.index=e.index||(e.index!==0?s.index:0),this.static=e.static!==void 0?e.static:s.static,this.hidden=e.hidden!==void 0?e.hidden:s.hidden,this.constant=e.constant!==void 0?e.constant:s.constant,this.required=e.required!==void 0?e.required:s.required,super.metaSync(e),e.deleted===!0&&!s.deleted?t==null||t.add(this,b.Removed):e.deleted===!1&&s.deleted?t==null||t.add(this,b.Added):i&&(t==null||t.add(this,b.Updated)),t==null||t.attemptAutoclose("meta-sync",this.id),this}async APILoad(e=j,...t){return await Ae.repository.APILoad(this.id,...t),this}async APICreate(e=j,...t){return await Ae.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=j,...t){return await Ae.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=j,...t){return await Ae.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=j,...t){return await Ae.repository.APIClone(this.id,...t),this}async APILoadVersion(e=j,t,...i){return await Ae.repository.APILoadVersion(this.id,t,...i)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-entity"))){const i=[],s=[],l=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(s.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(d=>{const{updated:u,removed:y,added:c}=d.entity.onDetachedDependencyRemoved(this,d.field,t);i.push(...u),s.push(...y),l.push(...c)}),this.defaultValue){const{updated:d,removed:u}=this.defaultValue.remove({ignoreUpstream:!0},t);i.push(...d),s.push(...u)}if(this.dataType){const{updated:d,removed:u}=this.dataType.remove({ignoreUpstream:!0},t);i.push(...d),s.push(...u)}return e||this.parent.type===n.DefinitionEntity&&(this.parent.removeProperty(this),i.push(this.parent)),t==null||t.attemptAutoclose("remove-entity",this.id),{added:p(l),updated:p(i),removed:p(s),affected:p(o),self:this}}restore({}={},e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"restore-entity"))){const t=[],i=[],s=[],l=[];if(e!=null&&e.hasAdded(this.id))return e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),this.defaultValue){const{updated:o}=this.defaultValue.restore({},e);i.push(...o)}if(this.dataType){const{updated:o}=this.dataType.restore({},e);i.push(...o)}return this.parent.type===n.DefinitionEntity&&(this.parent.addProperty(this),i.push(this.parent)),e==null||e.attemptAutoclose("restore-entity",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(l),self:this}}toFlat(e=new Set){var i,s;return e.has(this.id)?[]:(e.add(this.id),[this,...((i=this.defaultValue)==null?void 0:i.toFlat(e))||[],...((s=this.dataType)==null?void 0:s.toFlat(e))||[],...this.parent.toFlat(e)])}toFlatIds(e=new Set){var i,s;return e.has(this.id)?[]:(e.add(this.id),[this.id,...((i=this.defaultValue)==null?void 0:i.toFlatIds(e))||[],...((s=this.dataType)==null?void 0:s.toFlatIds(e))||[],...this.parent.toFlatIds(e)])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,description:this.description,index:this.index,hidden:this.hidden,private:this.private,abstract:this.abstract,required:this.required,constant:this.constant,static:this.static,type:this.type,name:this.name}}toJSON(e=new Set){var t,i,s;return e.has(this.id)?this.toReference():(e.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,index:this.index,private:this.private,required:this.required,static:this.static,constant:this.constant,abstract:this.abstract,hidden:this.hidden,defaultValue:((t=this.defaultValue)==null?void 0:t.toJSON(e))||null,dataType:((i=this.dataType)==null?void 0:i.toJSON(e))||null,implements:((s=this.implements)==null?void 0:s.toJSON(e))||null,parent:this.parent.toReference()})}toJSONClone(e=J){var i,s,l,o,d,u,y;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||ht(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(s=e.seenEntities)!=null&&s.has(t)||(l=e.seenEntities)!=null&&l.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(d=e.seenEntities)==null||d.add(this.id),{id:t,version:m.UUID.uuid(),createdAt:e.timestamp||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:this.type,name:this.name,description:this.description,index:this.index,private:this.private,required:this.required,static:this.static,constant:this.constant,abstract:this.abstract,hidden:this.hidden,defaultValue:((u=this.defaultValue)==null?void 0:u.toJSONClone({...e,newId:null}))||null,dataType:((y=this.dataType)==null?void 0:y.toJSONClone({...e,newId:null}))||null,implements:(()=>{var c;return this.implements&&this.project.getBuiltIn(this.implements.id)?this.implements.toJSON():((c=this.implements)==null?void 0:c.toJSONClone({...e,newId:null}))||null})(),parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps})})}toReference(e=J){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+m.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=J){var i,s,l,o;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,name:this.name,description:this.description,type:this.type,index:this.index,private:this.private,required:this.required,abstract:this.abstract,static:this.static,constant:this.constant,hidden:this.hidden,defaultValue:((s=this.defaultValue)==null?void 0:s.toReference(e))||null,dataType:((l=this.dataType)==null?void 0:l.toReference(e))||null,implements:((o=this.implements)==null?void 0:o.toReference(e))||null,parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){var i,s,l;return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...((i=this.defaultValue)==null?void 0:i.toFlatJSON(e))||[],...((s=this.dataType)==null?void 0:s.toFlatJSON(e))||[],...((l=this.implements)==null?void 0:l.toFlatJSON(e))||[],...this.parent.toFlatJSON(e)])}toGenerationTarget(){var e;return{id:this.id,name:this.name,description:this.description,type:this.type,private:this.private,required:this.required,abstract:this.abstract,static:this.static,implements:((e=this.implements)==null?void 0:e.id)||null,parent:this.parent.id}}toFlatGenerationTarget(e=new Set){var i,s;return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...((i=this.defaultValue)==null?void 0:i.toFlatGenerationTarget(e))||[],...((s=this.dataType)==null?void 0:s.toFlatGenerationTarget(e))||[]])}clearErrors(){var e,t;return this.errors=[],(e=this.defaultValue)==null||e.clearErrors(),(t=this.dataType)==null||t.clearErrors(),this}validate(){return this.errors=e1(this),this.errors.length,{success:!0,error:null,data:null}}getErrors(){var t,i;return[...this.errors,...((t=this.defaultValue)==null?void 0:t.getErrors())||[],...((i=this.dataType)==null?void 0:i.getErrors())||[]]}getShallowErrors(){return this.errors}clone(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"clone-entity")),t=null,i=null,s=!0){var E,O;let l=mt(t,this);const o=i||m.UUID.uuid();let d=t||this.parent;const u={hidden:!1,id:o,version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:(e==null?void 0:e.author)||"1",previousVersion:null,deleted:!1,type:this.type,name:this.name,description:this.description,index:this.index,private:this.private,constant:this.constant,required:this.required,abstract:this.abstract,static:this.static,defaultValue:null,dataType:null,implements:this.implements,parent:d},y=ct(u,l);s&&y.subscribe(),y.setParent(d,null),y.initChildren(e),e==null||e.add(y,b.Added);const c=((E=this.dataType)==null?void 0:E.clone(e,y,m.UUID.uuid(),s))||null;c&&y.setDataType(c);const I=(O=this.defaultValue)==null?void 0:O.clone(e,y,m.UUID.uuid(),s);return y.defaultValue=I||null,this.implements&&(y.implements=this.implements),y.addSelfToProject(null),e==null||e.attemptAutoclose("clone-entity",this.id),y}setDataType(e){return this.dataType=e,this}removeDataType(){return this.dataType=null,this}getDataType(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"get-data-type"))){return e==null||e.attemptAutoclose("get-data-type",this.id),this.dataType}getDefaultValue(){return this.defaultValue}setDefaultValue(e){return this.defaultValue=e,this}};f(Ae,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>e,APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...i)=>null}),f(Ae,"type",n.Property),f(Ae,"USER_MANAGED_PARENT_TYPES",[n.DefinitionEntity]),f(Ae,"PARENT_TYPES",[...Ae.USER_MANAGED_PARENT_TYPES,n.PrimitiveEntity,n.BuiltInBaseEntity]),f(Ae,"MUTABLE_BASE_PROPERTIES",["name","description","private","abstract","static","required","constant"]),f(Ae,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),f(Ae,"BASE_PROPERTIES",[...Ae.MUTABLE_BASE_PROPERTIES,...Ae.INMUTABLE_BASE_PROPERTIES]),f(Ae,"MUTABLE_META_PROPERTIES",[...Ae.MUTABLE_BASE_PROPERTIES,"index"]),f(Ae,"INMUTABLE_META_PROPERTIES",[...Ae.INMUTABLE_BASE_PROPERTIES]),f(Ae,"META_PROPERTIES",[...Ae.MUTABLE_META_PROPERTIES,...Ae.INMUTABLE_META_PROPERTIES]),f(Ae,"MUTABLE_UPSTREAM_PROPERTIES",[]),f(Ae,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","implements"]),f(Ae,"UPSTREAM_PROPERTIES",[...Ae.MUTABLE_UPSTREAM_PROPERTIES,...Ae.INMUTABLE_UPSTREAM_PROPERTIES]),f(Ae,"MUTABLE_DOWNSTREAM_PROPERTIES",["dataType"]),f(Ae,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),f(Ae,"DOWNSTREAM_PROPERTIES",[...Ae.MUTABLE_DOWNSTREAM_PROPERTIES,...Ae.INMUTABLE_DOWNSTREAM_PROPERTIES]),f(Ae,"PROPERTIES",[...Ae.META_PROPERTIES,...Ae.UPSTREAM_PROPERTIES,...Ae.DOWNSTREAM_PROPERTIES]);let Ur=Ae;function r1(r){var s;const a=m5(),e=r.toJSON();a.safeParse(e).success,(s=r.dataType)==null||s.validate();const i=[];if(r.id==="iterate-over-employee-list-continue-statement-employee-dto-output-decl-id"){const l=de({id:`${r.id}--${F.PropertyImplementsNonAbstact}`,message:`Property "${x(r,r.project)}" with id "${r.id}" implements a non-abstract property "${x(r,r.project)}" with id "${r.id}".`,issue:null,severity:D.Error,code:F.PropertyImplementsNonAbstact,entity:r});i.push(l.error)}return He(r.errors,i)}const EJ=Object.freeze(Object.defineProperty({__proto__:null,validate:r1},Symbol.toStringTag,{value:"Module"}));var n1=(r=>(r.Implements="implements",r.DataTypeEntity="data-type-entity",r))(n1||{});const be=class be extends at{constructor(e,t){super(e);f(this,"initialData");f(this,"id");f(this,"name");f(this,"description",null);f(this,"index");f(this,"required");f(this,"constant",!0);f(this,"isError");f(this,"type",n.ReturnDeclaration);f(this,"defaultValue",null);f(this,"dataType",null);f(this,"readsValue",null);f(this,"implements",null);f(this,"project");f(this,"errors",[]);f(this,"parent");f(this,"detachedDependents",{});f(this,"knownVersions",null);f(this,"activeVersion",!1);f(this,"initialized",!1);f(this,"startedInitialization",!1);f(this,"suggestion",!1);this.initialData=e,this.project=t,this.id=e.id,this.index=e.index,this.name=e.name,this.description=e.description,this.required=e.required,this.constant=!0,this.isError=e.isError}static new(){return{id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.ReturnDeclaration,name:"",description:"",dataType:null,index:0,required:!1,constant:!0,isError:!1,implements:null,readsValue:null,defaultValue:null,parent:null}}static fromGenerationTarget(e,t){const i=_(e.parent),s=t.get(i);let l=null;if(e.readsValue){const u=_(e.readsValue);l=t.get(u)}const o={id:e.id,version:m.UUID.uuid(),createdAt:T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,name:e.name,type:n.ReturnDeclaration,index:s.outputs.length,isError:!1,description:e.description,defaultValue:null,implements:null,required:e.required,constant:!0,readsValue:l,dataType:null,parent:s},d=V(o,t);return d.setParent(s,null),d.initChildren(null),d}static validateGenerationTarget(e,t){var d,u;let i=JSON.parse(JSON.stringify(e));const s=[],l=At(i,{parent:{list:!1,types:[n.ReturnStatement,n.Search,n.BreakStatement,n.ContinueStatement]}},t),o=Oc(i,t);if(i=l.modifiedData,i.parent){const y=t.get(_(i.parent));if(y&&[n.BreakStatement,n.ContinueStatement].includes(y.type)){const c=y,I=c.parent,E=[...I.breakStatements.filter(P=>P.id!==y.id),...I.continueStatements.filter(P=>P.id!==y.id)];if(c.outputs.length)s.push(new w({id:`${i.id}--${$.NoOverlapWithImplementedSignature}`,code:$.NoOverlapWithImplementedSignature,severity:D.Error,message:`Entity of type '${n.ReturnDeclaration}' with id '${i.id}' cannot be added to the parent entity of type '${c.type}' with id '${c.id}'. This '${c.type}' already has return declarations.
46
46
  ${jc}`,issue:null}));else{const P=(u=(d=E[0])==null?void 0:d.outputs[0])==null?void 0:u.name;P!==i.name&&s.push(new w({id:`${i.id}--${$.NoOverlapWithImplementedSignature}`,code:$.NoOverlapWithImplementedSignature,severity:D.Error,message:`Entity of type '${n.ReturnDeclaration}' with id '${i.id}' cannot be added to the parent entity of type '${c.type}' with id '${c.id}'. This new 'return-declaration' doesn't have the same name "${P}" as the return declarations on the other statements in the same scope.
47
47
  ${jc}`,issue:null}))}}else if(y&&y.type===n.ReturnStatement){const c=y.parent;if(c&&lt.includes(c.type)){const I=c.implements;if(I){const E=I.outputs.find(B=>B.name===i.name),O=I.outputs.filter(B=>!y.outputs.find(q=>q.type===n.ReturnDeclaration&&q.name===B.name)),P=y.outputs.filter(B=>B.type===n.ReturnDeclaration),C=P.find(B=>B.name===i.name),M=P.length?`The parent entity already implements the following return declarations: ${se(P.map(B=>`'${B.id}' (${B.name})`),", "," and ")}.`:"The parent entity does not yet have any implemented return declarations.",G=O.length?`The parent entity is still missing the following returns in the implementation: ${se(O.map(B=>`'${B.id}' (${B.name})`),", "," and ")}.`:"The parent entity has all the returns it needs implemented.";E?C&&s.push(new w({id:`${i.id}--${$.NoOverlapWithImplementedSignature}`,code:$.NoOverlapWithImplementedSignature,severity:D.Error,message:`Entity of type '${n.ReturnDeclaration}' with id '${i.id}' should not exist in a parent entity of type '${y.type}' with id '${y.id}' that implements a ${n.ActionDescriptor} with fixed outputs.
48
48
  Adding a new return would make the implementation invalid. An return with the same name already exists in the parent entity.
@@ -204,7 +204,7 @@ You can't modify system entities that are built-in.`,issue:null})),o&&o.type===n
204
204
  An action descriptor can only have one error value descriptor child.
205
205
  Either remove the existing error value descriptor or update it with the 'update' action.
206
206
  You can use the 'describe_entity' action to get more information about the existing error value descriptor like so:
207
- ${Yi({describe_entity:o.error.id})}`,issue:null}))),{errors:s,modifiedData:i}}validateGeneratedUpdate(e){return{errors:[],modifiedData:e}}subscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]||(this.detachedDependents[t.entity.id]=t)}),this}syncDependents(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-dependents"))){const t=[],i=[],s=[],l=[];return Object.values(this.detachedDependents).forEach(o=>{const d=o.entity.afterAllChildrenInitialized(e);t.push(...d.updated),i.push(...d.added),s.push(...d.removed),l.push(...d.affected)}),e==null||e.attemptAutoclose("sync-dependents",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}onDetachedDependencyRestored(e,t,i){const s=[],l=[],o=[],d=[];return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}subscribeToDependencies(){var e,t,i;return(i=(t=(e=this.dataType)==null?void 0:e.entity)==null?void 0:t.subscribeDependents)==null||i.call(t,[{entity:this,field:"data-type-entity"}]),this}increaseVersion(e){if(e&&!T(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&T(e).isSame(T(this.createdAt))?this:(this.previousVersion=this.version,this.version=m.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new Ue(this,this.project);return e.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,e):new Map([[this.version,e]]),e.defaultValue=this.defaultValue,e.dataType=this.dataType,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],i=[],s=[],l=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),i.push(...o.added),s.push(...o.removed)}return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}async restoreVersion(e){var d;const t=[],i=[],s=[],l=[];if(this.version===e)return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this};if(!this.knownVersions){const u=new Map;for(const[y,c]of this.knownVersions||new Map){if(u.set(y,c),c.activeVersion=!1,c.knownVersions)for(const[I,E]of c.knownVersions)u.set(I,E);c.knownVersions=null}}let o=(d=this.knownVersions)==null?void 0:d.get(e);if(!o){const u=await this.APILoadVersion({},e);if(!u)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new Ue(u,this.project)}return this.metaSync(o.toShallowJSON(),null),this.defaultValue=o.defaultValue,this.dataType=o.dataType,this.parent=o.parent,{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}hydrateAncestors(){const e=[],t=[],i=[],s=[];if(this.initialData.parent){const l=_(this.initialData.parent),o=this.project.get(l);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw console.warn("No parent found for entity",this.initialData),new Error(`${this.type} with id '${this.id}' must have a 'parent'`);return{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],i=[],s=[],l=[];return this.initialized=!0,this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addSelfToProject(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-self-to-project"))){var o,d,u,y,c,I,E,O;const t=[this],i=[],s=[],l=[];return this.parentRelationType===N.FixedArguments||this.parentRelationType===N.DynamicArgument?((o=this.parent)==null?void 0:o.type)===n.Search||((d=this.parent)==null?void 0:d.type)===n.Loop?(this.parent.addInputDeclaration(this,e),t.push(this.parent)):((y=(u=this.parent)==null?void 0:u.addInput)==null||y.call(u,this),t.push(this.parent)):this.parentRelationType===N.FixedReturns||this.parentRelationType===N.DynamicReturn?((c=this.parent)==null?void 0:c.type)===n.Search||((I=this.parent)==null?void 0:I.type)===n.Loop?(this.parent.addOutputDeclaration(this,e),t.push(this.parent)):((O=(E=this.parent)==null?void 0:E.addOutput)==null||O.call(E,this),t.push(this.parent)):this.parentRelationType===N.ReturnedError&&this.parent&&(this.parent.error=this,t.push(this.parent)),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}setParent(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"set-parent"))){var i;return((i=this.parent)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,b.Updated),t==null||t.attemptAutoclose("set-parent",this.id))),this}initChildren(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.initialData.defaultValue&&(this.defaultValue=V(this.initialData.defaultValue,this.project),this.defaultValue.setParent(this,null),this.defaultValue.initChildren(e)),this.initialData.dataType&&(this.dataType=V(this.initialData.dataType,this.project),this.dataType.setParent(this,null),this.dataType.initChildren(e)),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this)}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"meta-sync"))){const i=pt(this,e),s=this.toMeta();return this.name=e.name!==void 0?e.name:s.name,this.description=e.description!==void 0?e.description:s.description,this.index=e.index||(e.index!==0?s.index:0),this.required=e.required!==void 0?e.required:this.required,this.parentRelationType=e.parentRelationType!==void 0?e.parentRelationType:this.parentRelationType,super.metaSync(e),e.deleted===!0&&!s.deleted?t==null||t.add(this,b.Removed):e.deleted===!1&&s.deleted?t==null||t.add(this,b.Added):i&&(t==null||t.add(this,b.Updated)),t==null||t.attemptAutoclose("meta-sync",this.id),this}async APILoad(e=j,...t){return await Ue.repository.APILoad(this.id,...t),this}async APICreate(e=j,...t){return await Ue.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=j,...t){return await Ue.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=j,...t){return await Ue.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=j,...t){return await Ue.repository.APIClone(this.id,...t),this}async APILoadVersion(e=j,t,...i){return await Ue.repository.APILoadVersion(this.id,t,...i)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-entity"))){var u,y,c,I,E,O,P;const i=[],s=[],l=[],o=[];if(Array.from(new Set([..._i(),...this.project.getAllBuiltInIds()])).includes(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),console.log("Built-in entity, cannot remove: ",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(s.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(C=>{const{updated:M,removed:G,added:B}=C.entity.onDetachedDependencyRemoved(this,C.field,t);i.push(...M),s.push(...G),l.push(...B)}),this.defaultValue){const{updated:C,removed:M}=this.defaultValue.remove({ignoreUpstream:!0},t);i.push(...C),s.push(...M)}if(this.dataType){const{updated:C,removed:M}=this.dataType.remove({ignoreUpstream:!0},t);i.push(...C),s.push(...M)}return e||(((u=this.parent)==null?void 0:u.type)===n.Search?this.parentRelationType===N.FixedReturns||this.parentRelationType===N.DynamicReturn?(y=this.parent)==null||y.removeOutputDeclaration(this,t):this.parentRelationType===N.FixedArguments||this.parentRelationType===N.DynamicArgument?(c=this.parent)==null||c.removeInputDeclaration(this,t):this.parentRelationType===N.ReturnedError&&(this.parent.error=null):((I=this.parent)==null?void 0:I.type)===n.Loop?this.parentRelationType===N.FixedReturns||this.parentRelationType===N.DynamicReturn?(E=this.parent)==null||E.removeOutputDeclaration(this,t):this.parentRelationType===N.ReturnedError&&(this.parent.error=null):this.parentRelationType===N.FixedReturns||this.parentRelationType===N.DynamicReturn?(O=this.parent)==null||O.removeOutput(this,t):(this.parentRelationType===N.FixedArguments||this.parentRelationType===N.DynamicArgument)&&((P=this.parent)==null||P.removeInput(this,t))),t==null||t.attemptAutoclose("remove-entity",this.id),{added:p(l),updated:p(i),removed:p(s),affected:p(o),self:this}}restore({}={},e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"restore-entity"))){var o,d,u,y,c,I,E;const t=[],i=[],s=[],l=[];if(e!=null&&e.hasAdded(this.id))return e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),this.defaultValue){const{updated:O}=this.defaultValue.restore({},e);i.push(...O)}if(this.dataType){const{updated:O}=this.dataType.restore({},e);i.push(...O)}return((o=this.parent)==null?void 0:o.type)===n.Search?this.parentRelationType===N.FixedReturns||this.parentRelationType===N.DynamicReturn?(d=this.parent)==null||d.addOutputDeclaration(this,e):(this.parentRelationType===N.FixedArguments||this.parentRelationType===N.DynamicArgument)&&((u=this.parent)==null||u.addInputDeclaration(this,e)):((y=this.parent)==null?void 0:y.type)===n.Loop?(this.parentRelationType===N.FixedReturns||this.parentRelationType===N.DynamicReturn)&&((c=this.parent)==null||c.addOutputDeclaration(this,e)):this.parentRelationType===N.FixedReturns||this.parentRelationType===N.DynamicReturn?(I=this.parent)==null||I.addOutput(this,e):(this.parentRelationType===N.FixedArguments||this.parentRelationType===N.DynamicArgument)&&((E=this.parent)==null||E.addInput(this,e)),e==null||e.attemptAutoclose("restore-entity",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(l),self:this}}toFlat(e=new Set){var i;return e.has(this.id)?[]:(e.add(this.id),[this,...((i=this.defaultValue)==null?void 0:i.toFlat(e))||[],...this.dataType?this.dataType.toFlat(e):[]])}toFlatIds(e=new Set){var i;return e.has(this.id)?[]:(e.add(this.id),[this.id,...((i=this.defaultValue)==null?void 0:i.toFlatIds(e))||[],...this.dataType?this.dataType.toFlatIds(e):[]])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,description:this.description,index:this.index,required:this.required,parentRelationType:this.parentRelationType,type:this.type,name:this.name}}toJSON(e=new Set){var t,i,s;return e.has(this.id)?this.toReference():(e.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,index:this.index,required:this.required,defaultValue:((t=this.defaultValue)==null?void 0:t.toJSON(e))||null,parentRelationType:this.parentRelationType,dataType:((i=this.dataType)==null?void 0:i.toJSON(e))||null,parent:((s=this.parent)==null?void 0:s.toReference())||null})}toJSONClone(e=J){var i,s,l,o,d,u,y,c;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||ht(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(s=e.seenEntities)!=null&&s.has(t)||(l=e.seenEntities)!=null&&l.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(d=e.seenEntities)==null||d.add(this.id),{id:t,version:m.UUID.uuid(),createdAt:e.timestamp||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:this.type,name:this.name,description:this.description,index:this.index,required:this.required,defaultValue:((u=this.defaultValue)==null?void 0:u.toJSONClone({...e,newId:null}))||null,parentRelationType:this.parentRelationType,dataType:((y=this.dataType)==null?void 0:y.toJSONClone({...e,newId:null}))||null,parent:((c=this.parent)==null?void 0:c.toReference({seenEntityMaps:e.seenEntityMaps}))||null})}toReference(e=J){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+m.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=J){var i,s,l,o;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,index:this.index,required:this.required,parentRelationType:this.parentRelationType,defaultValue:((s=this.defaultValue)==null?void 0:s.toReference(e))||null,dataType:((l=this.dataType)==null?void 0:l.toReference(e))||null,parent:((o=this.parent)==null?void 0:o.toReference(e))||null}}toFlatJSON(e=new Set){var i;return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...((i=this.defaultValue)==null?void 0:i.toFlatJSON(e))||[],...this.dataType?this.dataType.toFlatJSON(e):[]])}toGenerationTarget(){var e;return{id:this.id,name:this.name,description:this.description,type:this.type,required:this.required,parentRelationType:this.parentRelationType,parent:(e=this.parent)==null?void 0:e.id}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...this.defaultValue?this.defaultValue.toFlatGenerationTarget(e):[],...this.dataType?this.dataType.toFlatGenerationTarget(e):[]])}clearErrors(){var e,t;return this.errors=[],(e=this.defaultValue)==null||e.clearErrors(),(t=this.dataType)==null||t.clearErrors(),this}validate(){const e=j1(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){return[...this.errors,...this.dataType?this.dataType.getErrors():[]]}getShallowErrors(){return this.errors}clone(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"clone-entity")),t=null,i=null,s=!0){var E,O;if(Array.from(new Set([..._i(),...this.project.getAllBuiltInIds()])).includes(this.id))return this;let o=mt(t,this);const d=i||m.UUID.uuid(),u=this.toJSON();u.id=d,u.version=m.UUID.uuid(),u.createdAt=(e==null?void 0:e.timestamp)||T().toISOString(),u.author=(e==null?void 0:e.author)||"1",u.previousVersion=null,u.deleted=!1;const y=ct(u,o);t&&y.setParent(t,null),e==null||e.add(y,b.Added),s&&y.subscribe();const c=((E=this.dataType)==null?void 0:E.clone(e,y,m.UUID.uuid(),s))||null;c&&y.setDataType(c);const I=(O=this.defaultValue)==null?void 0:O.clone(e,y,m.UUID.uuid(),s);return y.defaultValue=I||null,e==null||e.attemptAutoclose("clone-entity",this.id),y}getDataType(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"get-data-type"))){return this.dataType||null}setDataType(e){return this.dataType=e,this}getDefaultValue(){return this.defaultValue||null}setDefaultValue(e){return this.defaultValue=e,this}removeDataType(){return this.dataType=null,this}};f(Ue,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>e,APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...i)=>null}),f(Ue,"type",n.ValueDescriptor),f(Ue,"USER_MANAGED_PARENT_TYPES",[n.ActionDescriptor,n.Loop,n.Search]),f(Ue,"PARENT_TYPES",[...Ue.USER_MANAGED_PARENT_TYPES]),f(Ue,"MUTABLE_BASE_PROPERTIES",["name","description","required"]),f(Ue,"INMUTABLE_BASE_PROPERTIES",["id","version","type","parentRelationType","createdAt","author","previousVersion"]),f(Ue,"BASE_PROPERTIES",[...Ue.MUTABLE_BASE_PROPERTIES,...Ue.INMUTABLE_BASE_PROPERTIES]),f(Ue,"MUTABLE_META_PROPERTIES",[...Ue.MUTABLE_BASE_PROPERTIES,"index"]),f(Ue,"INMUTABLE_META_PROPERTIES",[...Ue.INMUTABLE_BASE_PROPERTIES]),f(Ue,"META_PROPERTIES",[...Ue.MUTABLE_META_PROPERTIES,...Ue.INMUTABLE_META_PROPERTIES]),f(Ue,"MUTABLE_UPSTREAM_PROPERTIES",[]),f(Ue,"INMUTABLE_UPSTREAM_PROPERTIES",["parent"]),f(Ue,"UPSTREAM_PROPERTIES",[...Ue.MUTABLE_UPSTREAM_PROPERTIES,...Ue.INMUTABLE_UPSTREAM_PROPERTIES]),f(Ue,"MUTABLE_DOWNSTREAM_PROPERTIES",["dataType","defaultValue"]),f(Ue,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),f(Ue,"DOWNSTREAM_PROPERTIES",[...Ue.MUTABLE_DOWNSTREAM_PROPERTIES,...Ue.INMUTABLE_DOWNSTREAM_PROPERTIES]),f(Ue,"PROPERTIES",[...Ue.META_PROPERTIES,...Ue.UPSTREAM_PROPERTIES,...Ue.DOWNSTREAM_PROPERTIES]);let mr=Ue;function KJ(r,a){if(!r.type&&!r.id)return{errors:[new w({id:`last-generated-entity-payload--${R.MissingTypeProperty}`,message:"Last generated entity payload is missing a 'type' property.",severity:D.Error,code:R.MissingTypeProperty,issue:null}),new w({id:`last-generated-entity-payload--${R.MissingIdProperty}`,message:"Last generated entity payload is missing an 'id' property.",severity:D.Error,code:R.MissingIdProperty,issue:null})],modifiedData:null};if(r.type){if(!r.id)return{errors:[new w({id:`last-generated-entity-payload--${R.MissingIdProperty}`,message:`Last generated entity, with type "${r.type}" is missing an 'id' property.`,severity:D.Error,code:R.MissingIdProperty,issue:null})],modifiedData:null}}else return{errors:[new w({id:`${r.id}--${R.MissingTypeProperty}`,message:`Entity with id "${r.id}" is missing a 'type' property.`,severity:D.Error,code:R.MissingTypeProperty,issue:null})],modifiedData:null};if(r.type===n.GenericReference)return{errors:[new w({id:`${r.id}--${R.RootReference}`,message:`Generic reference entity with id "${r.id}". A generic reference cannot be generated as a standalone entity. Only in the body of another entity.`,severity:D.Error,code:R.RootReference,issue:null})],modifiedData:null};const e=r,t=a.instances[e.id],i=a.builtInInstances[e.id];if(t&&!i&&e.type!==n.GenericReference){let s=`A previously generated entity with id "${e.id}" already exists in the project state.
207
+ ${Yi({describe_entity:o.error.id})}`,issue:null}))),{errors:s,modifiedData:i}}validateGeneratedUpdate(e){return{errors:[],modifiedData:e}}subscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]||(this.detachedDependents[t.entity.id]=t)}),this}syncDependents(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-dependents"))){const t=[],i=[],s=[],l=[];return Object.values(this.detachedDependents).forEach(o=>{const d=o.entity.afterAllChildrenInitialized(e);t.push(...d.updated),i.push(...d.added),s.push(...d.removed),l.push(...d.affected)}),e==null||e.attemptAutoclose("sync-dependents",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}onDetachedDependencyRestored(e,t,i){const s=[],l=[],o=[],d=[];return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}subscribeToDependencies(){var e,t,i;return(i=(t=(e=this.dataType)==null?void 0:e.entity)==null?void 0:t.subscribeDependents)==null||i.call(t,[{entity:this,field:"data-type-entity"}]),this}increaseVersion(e){if(e&&!T(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&T(e).isSame(T(this.createdAt))?this:(this.previousVersion=this.version,this.version=m.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new Ue(this,this.project);return e.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,e):new Map([[this.version,e]]),e.defaultValue=this.defaultValue,e.dataType=this.dataType,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],i=[],s=[],l=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),i.push(...o.added),s.push(...o.removed)}return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}async restoreVersion(e){var d;const t=[],i=[],s=[],l=[];if(this.version===e)return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this};if(!this.knownVersions){const u=new Map;for(const[y,c]of this.knownVersions||new Map){if(u.set(y,c),c.activeVersion=!1,c.knownVersions)for(const[I,E]of c.knownVersions)u.set(I,E);c.knownVersions=null}}let o=(d=this.knownVersions)==null?void 0:d.get(e);if(!o){const u=await this.APILoadVersion({},e);if(!u)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new Ue(u,this.project)}return this.metaSync(o.toShallowJSON(),null),this.defaultValue=o.defaultValue,this.dataType=o.dataType,this.parent=o.parent,{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}hydrateAncestors(){const e=[],t=[],i=[],s=[];if(this.initialData.parent){const l=_(this.initialData.parent),o=this.project.get(l);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw console.warn("No parent found for entity",this.initialData),new Error(`${this.type} with id '${this.id}' must have a 'parent'`);return{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],i=[],s=[],l=[];return this.initialized=!0,this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addSelfToProject(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-self-to-project"))){var o,d,u,y,c,I,E,O;const t=[this],i=[],s=[],l=[];return this.parentRelationType===N.FixedArguments||this.parentRelationType===N.DynamicArgument?((o=this.parent)==null?void 0:o.type)===n.Search||((d=this.parent)==null?void 0:d.type)===n.Loop?(this.parent.addInputDeclaration(this,e),t.push(this.parent)):((y=(u=this.parent)==null?void 0:u.addInput)==null||y.call(u,this),t.push(this.parent)):this.parentRelationType===N.FixedReturns||this.parentRelationType===N.DynamicReturn?((c=this.parent)==null?void 0:c.type)===n.Search||((I=this.parent)==null?void 0:I.type)===n.Loop?(this.parent.addOutputDeclaration(this,e),t.push(this.parent)):((O=(E=this.parent)==null?void 0:E.addOutput)==null||O.call(E,this),t.push(this.parent)):this.parentRelationType===N.ReturnedError&&this.parent&&(this.parent.error=this,t.push(this.parent)),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}setParent(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"set-parent"))){var i;return((i=this.parent)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,b.Updated),t==null||t.attemptAutoclose("set-parent",this.id))),this}initChildren(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.initialData.defaultValue&&(this.defaultValue=V(this.initialData.defaultValue,this.project),this.defaultValue.setParent(this,null),this.defaultValue.initChildren(e)),this.initialData.dataType&&(this.dataType=V(this.initialData.dataType,this.project),this.dataType.setParent(this,null),this.dataType.initChildren(e)),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this)}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"meta-sync"))){const i=pt(this,e),s=this.toMeta();return this.name=e.name!==void 0?e.name:s.name,this.description=e.description!==void 0?e.description:s.description,this.index=e.index||(e.index!==0?s.index:0),this.required=e.required!==void 0?e.required:this.required,this.parentRelationType=e.parentRelationType!==void 0?e.parentRelationType:this.parentRelationType,super.metaSync(e),e.deleted===!0&&!s.deleted?t==null||t.add(this,b.Removed):e.deleted===!1&&s.deleted?t==null||t.add(this,b.Added):i&&(t==null||t.add(this,b.Updated)),t==null||t.attemptAutoclose("meta-sync",this.id),this}async APILoad(e=j,...t){return await Ue.repository.APILoad(this.id,...t),this}async APICreate(e=j,...t){return await Ue.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=j,...t){return await Ue.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=j,...t){return await Ue.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=j,...t){return await Ue.repository.APIClone(this.id,...t),this}async APILoadVersion(e=j,t,...i){return await Ue.repository.APILoadVersion(this.id,t,...i)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-entity"))){var u,y,c,I,E,O,P;const i=[],s=[],l=[],o=[];if(Array.from(new Set([..._i(),...this.project.getAllBuiltInIds()])).includes(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),console.log("Built-in entity, cannot remove: ",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(s.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(C=>{const{updated:M,removed:G,added:B}=C.entity.onDetachedDependencyRemoved(this,C.field,t);i.push(...M),s.push(...G),l.push(...B)}),this.defaultValue){const{updated:C,removed:M}=this.defaultValue.remove({ignoreUpstream:!0},t);i.push(...C),s.push(...M)}if(this.dataType){const{updated:C,removed:M}=this.dataType.remove({ignoreUpstream:!0},t);i.push(...C),s.push(...M)}return e||(((u=this.parent)==null?void 0:u.type)===n.Search?this.parentRelationType===N.FixedReturns||this.parentRelationType===N.DynamicReturn?(y=this.parent)==null||y.removeOutputDeclaration(this,t):this.parentRelationType===N.FixedArguments||this.parentRelationType===N.DynamicArgument?(c=this.parent)==null||c.removeInputDeclaration(this,t):this.parentRelationType===N.ReturnedError&&(this.parent.error=null):((I=this.parent)==null?void 0:I.type)===n.Loop?this.parentRelationType===N.FixedReturns||this.parentRelationType===N.DynamicReturn?(E=this.parent)==null||E.removeOutputDeclaration(this,t):this.parentRelationType===N.ReturnedError&&(this.parent.error=null):this.parentRelationType===N.FixedReturns||this.parentRelationType===N.DynamicReturn?(O=this.parent)==null||O.removeOutput(this,t):(this.parentRelationType===N.FixedArguments||this.parentRelationType===N.DynamicArgument)&&((P=this.parent)==null||P.removeInput(this,t))),t==null||t.attemptAutoclose("remove-entity",this.id),{added:p(l),updated:p(i),removed:p(s),affected:p(o),self:this}}restore({}={},e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"restore-entity"))){var o,d,u,y,c,I,E;const t=[],i=[],s=[],l=[];if(e!=null&&e.hasAdded(this.id))return e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),this.defaultValue){const{updated:O}=this.defaultValue.restore({},e);i.push(...O)}if(this.dataType){const{updated:O}=this.dataType.restore({},e);i.push(...O)}return((o=this.parent)==null?void 0:o.type)===n.Search?this.parentRelationType===N.FixedReturns||this.parentRelationType===N.DynamicReturn?(d=this.parent)==null||d.addOutputDeclaration(this,e):(this.parentRelationType===N.FixedArguments||this.parentRelationType===N.DynamicArgument)&&((u=this.parent)==null||u.addInputDeclaration(this,e)):((y=this.parent)==null?void 0:y.type)===n.Loop?(this.parentRelationType===N.FixedReturns||this.parentRelationType===N.DynamicReturn)&&((c=this.parent)==null||c.addOutputDeclaration(this,e)):this.parentRelationType===N.FixedReturns||this.parentRelationType===N.DynamicReturn?(I=this.parent)==null||I.addOutput(this,e):(this.parentRelationType===N.FixedArguments||this.parentRelationType===N.DynamicArgument)&&((E=this.parent)==null||E.addInput(this,e)),e==null||e.attemptAutoclose("restore-entity",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(l),self:this}}toFlat(e=new Set){var i;return e.has(this.id)?[]:(e.add(this.id),[this,...((i=this.defaultValue)==null?void 0:i.toFlat(e))||[],...this.dataType?this.dataType.toFlat(e):[]])}toFlatIds(e=new Set){var i;return e.has(this.id)?[]:(e.add(this.id),[this.id,...((i=this.defaultValue)==null?void 0:i.toFlatIds(e))||[],...this.dataType?this.dataType.toFlatIds(e):[]])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,description:this.description,index:this.index,required:this.required,parentRelationType:this.parentRelationType,type:this.type,name:this.name}}toJSON(e=new Set){var t,i,s;return e.has(this.id)?this.toReference():(e.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,index:this.index,required:this.required,defaultValue:((t=this.defaultValue)==null?void 0:t.toJSON(e))||null,parentRelationType:this.parentRelationType,dataType:((i=this.dataType)==null?void 0:i.toJSON(e))||null,parent:((s=this.parent)==null?void 0:s.toReference())||null})}toJSONClone(e=J){var i,s,l,o,d,u,y,c;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||ht(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(s=e.seenEntities)!=null&&s.has(t)||(l=e.seenEntities)!=null&&l.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(d=e.seenEntities)==null||d.add(this.id),{id:t,version:m.UUID.uuid(),createdAt:e.timestamp||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:this.type,name:this.name,description:this.description,index:this.index,required:this.required,defaultValue:((u=this.defaultValue)==null?void 0:u.toJSONClone({...e,newId:null}))||null,parentRelationType:this.parentRelationType,dataType:((y=this.dataType)==null?void 0:y.toJSONClone({...e,newId:null}))||null,parent:((c=this.parent)==null?void 0:c.toReference({seenEntityMaps:e.seenEntityMaps}))||null})}toReference(e=J){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+m.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=J){var i,s,l,o;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,index:this.index,required:this.required,parentRelationType:this.parentRelationType,defaultValue:((s=this.defaultValue)==null?void 0:s.toReference(e))||null,dataType:((l=this.dataType)==null?void 0:l.toReference(e))||null,parent:((o=this.parent)==null?void 0:o.toReference(e))||null}}toFlatJSON(e=new Set){var i;return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...((i=this.defaultValue)==null?void 0:i.toFlatJSON(e))||[],...this.dataType?this.dataType.toFlatJSON(e):[]])}toGenerationTarget(){var e;return{id:this.id,name:this.name,description:this.description,type:this.type,required:this.required,parentRelationType:this.parentRelationType,parent:(e=this.parent)==null?void 0:e.id}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...this.defaultValue?this.defaultValue.toFlatGenerationTarget(e):[],...this.dataType?this.dataType.toFlatGenerationTarget(e):[]])}clearErrors(){var e,t;return this.errors=[],(e=this.defaultValue)==null||e.clearErrors(),(t=this.dataType)==null||t.clearErrors(),this}validate(){const e=j1(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){return[...this.errors,...this.dataType?this.dataType.getErrors():[]]}getShallowErrors(){return this.errors}clone(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"clone-entity")),t=null,i=null,s=!0){var E,O;if(Array.from(new Set([..._i(),...this.project.getAllBuiltInIds()])).includes(this.id))return this;let o=mt(t,this);const d=i||m.UUID.uuid(),u=this.toJSON();u.id=d,u.version=m.UUID.uuid(),u.createdAt=(e==null?void 0:e.timestamp)||T().toISOString(),u.author=(e==null?void 0:e.author)||"1",u.previousVersion=null,u.deleted=!1;const y=ct(u,o);t&&y.setParent(t,null),e==null||e.add(y,b.Added),s&&y.subscribe();const c=((E=this.dataType)==null?void 0:E.clone(e,y,m.UUID.uuid(),s))||null;c&&y.setDataType(c);const I=(O=this.defaultValue)==null?void 0:O.clone(e,y,m.UUID.uuid(),s);return y.defaultValue=I||null,e==null||e.attemptAutoclose("clone-entity",this.id),y}getDataType(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"get-data-type"))){return e==null||e.attemptAutoclose("get-data-type",this.id),this.dataType||null}setDataType(e){return this.dataType=e,this}getDefaultValue(){return this.defaultValue||null}setDefaultValue(e){return this.defaultValue=e,this}removeDataType(){return this.dataType=null,this}};f(Ue,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>e,APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...i)=>null}),f(Ue,"type",n.ValueDescriptor),f(Ue,"USER_MANAGED_PARENT_TYPES",[n.ActionDescriptor,n.Loop,n.Search]),f(Ue,"PARENT_TYPES",[...Ue.USER_MANAGED_PARENT_TYPES]),f(Ue,"MUTABLE_BASE_PROPERTIES",["name","description","required"]),f(Ue,"INMUTABLE_BASE_PROPERTIES",["id","version","type","parentRelationType","createdAt","author","previousVersion"]),f(Ue,"BASE_PROPERTIES",[...Ue.MUTABLE_BASE_PROPERTIES,...Ue.INMUTABLE_BASE_PROPERTIES]),f(Ue,"MUTABLE_META_PROPERTIES",[...Ue.MUTABLE_BASE_PROPERTIES,"index"]),f(Ue,"INMUTABLE_META_PROPERTIES",[...Ue.INMUTABLE_BASE_PROPERTIES]),f(Ue,"META_PROPERTIES",[...Ue.MUTABLE_META_PROPERTIES,...Ue.INMUTABLE_META_PROPERTIES]),f(Ue,"MUTABLE_UPSTREAM_PROPERTIES",[]),f(Ue,"INMUTABLE_UPSTREAM_PROPERTIES",["parent"]),f(Ue,"UPSTREAM_PROPERTIES",[...Ue.MUTABLE_UPSTREAM_PROPERTIES,...Ue.INMUTABLE_UPSTREAM_PROPERTIES]),f(Ue,"MUTABLE_DOWNSTREAM_PROPERTIES",["dataType","defaultValue"]),f(Ue,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),f(Ue,"DOWNSTREAM_PROPERTIES",[...Ue.MUTABLE_DOWNSTREAM_PROPERTIES,...Ue.INMUTABLE_DOWNSTREAM_PROPERTIES]),f(Ue,"PROPERTIES",[...Ue.META_PROPERTIES,...Ue.UPSTREAM_PROPERTIES,...Ue.DOWNSTREAM_PROPERTIES]);let mr=Ue;function KJ(r,a){if(!r.type&&!r.id)return{errors:[new w({id:`last-generated-entity-payload--${R.MissingTypeProperty}`,message:"Last generated entity payload is missing a 'type' property.",severity:D.Error,code:R.MissingTypeProperty,issue:null}),new w({id:`last-generated-entity-payload--${R.MissingIdProperty}`,message:"Last generated entity payload is missing an 'id' property.",severity:D.Error,code:R.MissingIdProperty,issue:null})],modifiedData:null};if(r.type){if(!r.id)return{errors:[new w({id:`last-generated-entity-payload--${R.MissingIdProperty}`,message:`Last generated entity, with type "${r.type}" is missing an 'id' property.`,severity:D.Error,code:R.MissingIdProperty,issue:null})],modifiedData:null}}else return{errors:[new w({id:`${r.id}--${R.MissingTypeProperty}`,message:`Entity with id "${r.id}" is missing a 'type' property.`,severity:D.Error,code:R.MissingTypeProperty,issue:null})],modifiedData:null};if(r.type===n.GenericReference)return{errors:[new w({id:`${r.id}--${R.RootReference}`,message:`Generic reference entity with id "${r.id}". A generic reference cannot be generated as a standalone entity. Only in the body of another entity.`,severity:D.Error,code:R.RootReference,issue:null})],modifiedData:null};const e=r,t=a.instances[e.id],i=a.builtInInstances[e.id];if(t&&!i&&e.type!==n.GenericReference){let s=`A previously generated entity with id "${e.id}" already exists in the project state.
208
208
  Are you trying to update that entity?
209
209
  If so, you should use the 'update' action for core mutable metadata properties, or 'delete' and then 'post' again to replace it.
210
210
  If you are trying to create a new entity, please use a different id, for example: "${Pc(e,a)}".`;return{errors:[new w({id:`duplicate--${e.id}--${R.EntityIdNotUnique}`,message:s,severity:D.Error,code:R.EntityIdNotUnique,issue:null})],modifiedData:r}}else if(t&&e.type!==n.GenericReference)return{errors:[new w({id:`${e.id}--${R.EntityIdNotUnique}`,message:`A built in entity with id "${e.id}" already exists. You cannot modify built in entities. If you are trying to create a new entity, please use a different id, for example: "${Pc(e,a)}".`,severity:D.Error,code:R.EntityIdNotUnique,issue:null})],modifiedData:r};switch(e.type){case n.Project:return m.validateGenerationTarget(e,a);case n.DefinitionEntity:return nn.validateGenerationTarget(e,a);case n.Property:return Ur.validateGenerationTarget(e,a);case n.FunctionDeclaration:return gr.validateGenerationTarget(e,a);case n.DataType:return $r.validateGenerationTarget(e,a);case n.Operation:return Gr.validateGenerationTarget(e,a);case n.FunctionCall:return en.validateGenerationTarget(e,a);case n.VariableDeclaration:return Jr.validateGenerationTarget(e,a);case n.VariableInstance:return qr.validateGenerationTarget(e,a);case n.GlobalEvent:return Fr.validateGenerationTarget(e,a);case n.InputMap:return Wi.validateGenerationTarget(e,a);case n.OutputMap:return zi.validateGenerationTarget(e,a);case n.ArgumentDeclaration:return Yr.validateGenerationTarget(e,a);case n.ReturnDeclaration:return ai.validateGenerationTarget(e,a);case n.Loop:return kr.validateGenerationTarget(e,a);case n.Condition:return Zr.validateGenerationTarget(e,a);case n.Search:return Sr.validateGenerationTarget(e,a);case n.InstalledProject:return Wr.validateGenerationTarget(e,a);case n.InternalCall:return zr.validateGenerationTarget(e,a);case n.LiteralValue:return Hr.validateGenerationTarget(e,a);case n.ReturnStatement:return jr.validateGenerationTarget(e,a);case n.BreakStatement:return xr.validateGenerationTarget(e,a);case n.ContinueStatement:return Lt.validateGenerationTarget(e,a);case n.ActionDescriptor:return Se.validateGenerationTarget(e,a);case n.ValueDescriptor:return mr.validateGenerationTarget(e,a);case n.BuiltInBaseEntity:case n.PrimitiveEntity:{const s="Did you mean to generate a",o={[n.BuiltInBaseEntity]:`${s} '${n.DefinitionEntity}' instead?`,[n.PrimitiveEntity]:`${s} '${n.DefinitionEntity}' instead?`}[e.type]||"";return{errors:[new w({id:`${e.id}--${R.BuiltInEntityGenerated}`,message:`Entity with id "${e.id} is of "${e.type}" type and should not be generated. Built in entities can only be referenced by user created entities.
@@ -402,7 +402,7 @@ All global 'function-declaration' entity ids are:
402
402
  The project currently has no global 'function-declaration' entities that can be called as 'function-call' entities.`;s.push(new w({id:`${i.id}--${R.InvalidReference}`,code:R.InvalidReference,severity:D.Error,message:`Entity of type "${n.FunctionCall}" with id "${i.id}", has an invalid reference at the 'declaration' property. The 'declaration' property must be a valid reference to an 'function-declaration' entity.
403
403
  References can either be an ID string or an object with exacly four properties: 'id', 'entityId', 'entityType', 'type'.${d}`,issue:null}))}return{errors:s,modifiedData:i}}validateGeneratedUpdate(e){const t=[];return e.parent&&t.push(new w({id:`${this.id}--${R.InvalidParentUpdate}`,code:R.InvalidParentUpdate,severity:D.Error,message:`Entity of type '${this.type}' with id '${this.id}' cannot have the 'parent' property updated. The 'parent' on a callable entity, is its scope. It scope is auto-calculated implicitly by the its caller.
404
404
  If an entity is called by another, they must be in the same scope, which means they have the same parent.
405
- You shouldn't have to manually update a 'parent' property. The equivalent result is to change its callers, the value writters of its inputs, or the value readers of its outputs.`,issue:null})),{errors:t,modifiedData:e}}subscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]||(this.detachedDependents[t.entity.id]=t)}),this}syncDependents(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-dependents"))){const t=[],i=[],s=[],l=[];return Object.values(this.detachedDependents).forEach(o=>{const d=o.entity.afterAllChildrenInitialized(e);t.push(...d.updated),i.push(...d.added),s.push(...d.removed),l.push(...d.affected)}),e==null||e.attemptAutoclose("sync-dependents",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];if(t==="declaration"){const{updated:u,added:y,removed:c}=this.remove({ignoreUpstream:!1},i);s.push(...u),l.push(...y),o.push(...c)}if(t==="parent"){const{updated:u,added:y,removed:c}=this.remove({ignoreUpstream:!1},i);s.push(...u),l.push(...y),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}onDetachedDependencyRestored(e,t,i){const s=[],l=[],o=[],d=[];if(t==="declaration"){const{updated:u,added:y,removed:c}=this.restore({},i);s.push(...u),l.push(...y),o.push(...c)}if(t==="parent"){const{updated:u,added:y,removed:c}=this.restore({},i);s.push(...u),l.push(...y),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}subscribeToDependencies(){var e;return(e=this.parent)==null||e.subscribeDependents([{entity:this,field:"parent"}]),this.declaration.subscribeDependents([{entity:this,field:"declaration"}]),this}increaseVersion(e){if(e&&!T(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&T(e).isSame(T(this.createdAt))?this:(this.previousVersion=this.version,this.version=m.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new qe(this,this.project);return e.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,e):new Map([[this.version,e]]),e.inputs=this.inputs,e.outputs=this.outputs,e.error=this.error,e.successCalls=this.successCalls,e.errorCalls=this.errorCalls,e.process=this.process,e.declaration=this.declaration,e.calledBySuccess=this.calledBySuccess,e.calledByError=this.calledByError,e.calledByEntry=this.calledByEntry,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],i=[],s=[],l=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),i.push(...o.added),s.push(...o.removed)}return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}async restoreVersion(e){var d;const t=[],i=[],s=[],l=[];if(this.version===e)return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this};if(!this.knownVersions){const u=new Map;for(const[y,c]of this.knownVersions||new Map){if(u.set(y,c),c.activeVersion=!1,c.knownVersions)for(const[I,E]of c.knownVersions)u.set(I,E);c.knownVersions=null}}let o=(d=this.knownVersions)==null?void 0:d.get(e);if(!o){const u=await this.APILoadVersion({},e);if(!u)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new qe(u,this.project)}return this.metaSync(o.toShallowJSON(),null),this.inputs=o.inputs,this.outputs=o.outputs,this.error=o.error,this.successCalls=o.successCalls,this.errorCalls=o.errorCalls,this.process=o.process,this.declaration=o.declaration,this.calledBySuccess=o.calledBySuccess,this.calledByError=o.calledByError,this.calledByEntry=o.calledByEntry,this.parent=o.parent,{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}hydrateAncestors(){const e=[],t=[],i=[],s=[];if(this.initialData.parent){const l=_(this.initialData.parent),o=this.project.get(l);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(this.initialData.declaration){const l=_(this.initialData.declaration),o=this.project.get(l);o&&(this.setDeclaration(o),e.push(o))}return this.initialData.calledByEntry.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addEntryCaller(d,null),e.push(d))}),this.initialData.calledBySuccess.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addSuccessCaller(d,null),e.push(d))}),this.initialData.calledByError.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addErrorCaller(d,null),e.push(d))}),{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],i=[],s=[],l=[];this.initialized=!0,this.captureVersion();const{updated:o,added:d,removed:u}=this.syncMissingFixedInputs(e),{updated:y,added:c,removed:I}=this.syncMissingFixedOutputs(e);return t.push(...o,...y),i.push(...d,...c),s.push(...u,...I),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addSelfToProject(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-self-to-project"))){var o;const t=[this],i=[],s=[],l=[];return this.parent===this.project&&this.project.addFunctionCall(this),(o=this.process)==null||o.writesValues.forEach(d=>{d.setValueWriter(this.process,e),t.push(d)}),this.successCalls.forEach(d=>{d.addSuccessCaller(this,e),t.push(d)}),this.errorCalls.forEach(d=>{d.addErrorCaller(this,e),t.push(d)}),this.calledBySuccess.forEach(d=>{d.addSuccessCall(this,e),t.push(d)}),this.calledByError.forEach(d=>{d.addErrorCall(this,e),t.push(d)}),this.calledByEntry.forEach(d=>{d.addCall(this,e),t.push(d)}),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}removeInput(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-input"))){const i=this.inputs.findIndex(s=>s.id===e.id);return i>-1&&(this.inputs.splice(i,1),t&&(t==null||t.add(this,b.Affected))),t==null||t.attemptAutoclose("remove-input",this.id),this}addInput(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-input"))){return this.inputs.includes(e)?(t==null||t.attemptAutoclose("add-input",this.id),this):(this.inputs.push(e),t==null||t.add(this,b.Affected),t==null||t.attemptAutoclose("add-input",this.id),this)}addOutput(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-output"))){return this.outputs.includes(e)?(t==null||t.attemptAutoclose("add-output",this.id),this):(this.outputs.push(e),t==null||t.add(this,b.Affected),t==null||t.attemptAutoclose("add-output",this.id),this)}removeOutput(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-output"))){const i=this.outputs.findIndex(s=>s.id===e.id);return i>-1&&(this.outputs.splice(i,1),t&&(t==null||t.add(this,b.Affected))),t==null||t.attemptAutoclose("remove-output",this.id),this}addValueReader(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-value-reader"))){var i;return this.process&&!this.process.writesValues.includes(e)&&((i=this.process)==null||i.addValueReader(e,t),t==null||t.add(this,b.Affected)),t==null||t.attemptAutoclose("add-value-reader",this.id),this}removeValueReader(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-value-reader"))){var i;return this.process&&this.process.writesValues.includes(e)&&((i=this.process)==null||i.removeValueReader(e,t),t==null||t.add(this,b.Affected)),t==null||t.attemptAutoclose("remove-value-reader",this.id),this}addSuccessCaller(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-success-caller")),i=!1){return this.calledBySuccess.find(s=>s.id===e.id)||(this.calledBySuccess.push(e),t==null||t.add(this,b.Updated),i&&K(this,t)),t==null||t.attemptAutoclose("add-success-caller",this.id),this}addErrorCaller(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-error-caller")),i=!1){return this.calledByError.find(s=>s.id===e.id)||(this.calledByError.push(e),t==null||t.add(this,b.Updated),i&&K(this,t),t==null||t.attemptAutoclose("add-error-caller",this.id)),this}addEntryCaller(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-entry-caller")),i=!1){return this.calledByEntry.find(s=>s.id===e.id)||(this.calledByEntry.push(e),t==null||t.add(this,b.Updated),i&&K(this,t),t==null||t.attemptAutoclose("add-entry-caller",this.id)),this}addErrorCall(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-error-call")),i=!1){return this.errorCalls.find(s=>s.id===e.id)||(this.errorCalls.push(e),i&&K(this,t),t==null||t.add(this,b.Affected)),t==null||t.attemptAutoclose("add-error-call",this.id),this}addSuccessCall(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-success-call")),i=!1){return this.successCalls.find(s=>s.id===e.id)||(this.successCalls.push(e),i&&K(this,t),t==null||t.add(this,b.Affected)),t==null||t.attemptAutoclose("add-success-call",this.id),this}removeCall(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-call")),i=!1){const s=this.successCalls.findIndex(o=>o.id===e.id);s>-1&&(this.successCalls.splice(s,1),t==null||t.add(this,b.Affected));const l=this.errorCalls.findIndex(o=>o.id===e.id);return l>-1&&(this.errorCalls.splice(l,1),t==null||t.add(this,b.Affected)),i&&K(this,t),t==null||t.attemptAutoclose("remove-call",this.id),this}removeCaller(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-caller")),i=!1){return this.calledBySuccess=this.calledBySuccess.filter(s=>s.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(s,b.Affected)),!0):!1),this.calledByError=this.calledByError.filter(s=>s.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(s,b.Affected)),!0):!1),this.calledByEntry=this.calledByEntry.filter(s=>s.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(s,b.Affected)),!0):!1),i&&K(this,t),t==null||t.attemptAutoclose("remove-caller",this.id),this}setParent(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"set-parent"))){var i;return((i=this.parent)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,b.Updated),t==null||t.attemptAutoclose("set-parent",this.id))),this}setDeclaration(e){return this.declaration=e,this}initChildren(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"init-children"))){if(this.initialized||this.startedInitialization)return this;if(this.startedInitialization=!0,this.initialData.declaration.type===n.FunctionDeclaration){const t=V(this.initialData.declaration,this.project);this.declaration=t}else{const t=_(this.initialData.declaration),i=this.project.get(t);this.declaration=i}return this.successCalls=this.initialData.successCalls.map(t=>{const i=V(t,this.project);return i.addSuccessCaller(this),[n.BreakStatement,n.ContinueStatement].includes(i.type)?(i.setParent(this.parent.parent,null),i.initChildren(e)):i.type!==n.InternalCall&&(i.setParent(this.parent,null),i.initChildren(e)),i}),this.errorCalls=this.initialData.errorCalls.map(t=>{const i=V(t,this.project);return i.addErrorCaller(this),[n.BreakStatement,n.ContinueStatement].includes(i.type)?(i.setParent(this.parent.parent,null),i.initChildren(e)):i.type!==n.InternalCall&&(i.setParent(this.parent,null),i.initChildren(e)),i}),this.inputs=this.initialData.inputs.map(t=>{const i=V(t,this.project);return i.setParent(this,null),i.initChildren(e),i}),this.initialData.process&&(this.process=V(this.initialData.process,this.project),this.process.setParent(this,null),this.process.initChildren(e)),this.initialData.error&&(this.error=V(this.initialData.error,this.project),this.error.setParent(this,null),this.error.initChildren(e)),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"meta-sync"))){const i=pt(this,e),s=this.toMeta();return this.x=e.x||s.x,this.y=e.y||s.y,super.metaSync(e),e.deleted===!0&&!s.deleted?t==null||t.add(this,b.Removed):e.deleted===!1&&s.deleted?t==null||t.add(this,b.Added):i&&(t==null||t.add(this,b.Updated)),t==null||t.attemptAutoclose("meta-sync",this.id),this}async APILoad(e=j,...t){return await qe.repository.APILoad(this.id,...t),this}async APICreate(e=j,...t){return await qe.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=j,...t){return await qe.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=j,...t){return await qe.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=j,...t){return await qe.repository.APIClone(this.id,...t),this}async APILoadVersion(e=j,t,...i){return await qe.repository.APILoadVersion(this.id,t,...i)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-entity"))){var d;const i=[],s=[],l=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(s.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(u=>{const{updated:y,removed:c,added:I}=u.entity.onDetachedDependencyRemoved(this,u.field,t);i.push(...y),s.push(...c),l.push(...I)}),this.process){const{updated:u,removed:y}=(d=this.process)==null?void 0:d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...y)}if(this.inputs.forEach(u=>{const{updated:y,removed:c}=u.remove({ignoreUpstream:!0},t);i.push(...y),s.push(...c)}),this.outputs.forEach(u=>{const{updated:y,removed:c}=u.remove({ignoreUpstream:!0},t);i.push(...y),s.push(...c)}),this.error){const{updated:u,removed:y}=this.error.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...y)}return this.successCalls.forEach(u=>{i.push(u),u.removeCaller(this,t)}),this.errorCalls.forEach(u=>{i.push(u),u.removeCaller(this,t)}),e||this.calledBy.forEach(u=>{i.push(u),u.removeCall(this,t)}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:p(l),updated:p(i),removed:p(s),affected:p(o),self:this}}restore({}={},e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"restore-entity"))){const t=[],i=[],s=[],l=[];if(e!=null&&e.hasAdded(this.id))return e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),this.process){const{updated:o}=this.process.restore({},e);i.push(...o)}return this.inputs.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.outputs.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.successCalls.forEach(o=>{i.push(o),o.addSuccessCaller(this,e)}),this.errorCalls.forEach(o=>{i.push(o),o.addErrorCaller(this,e)}),this.calledBySuccess.forEach(o=>{i.push(o),o.addSuccessCall(this,e)}),this.calledByError.forEach(o=>{i.push(o),o.addErrorCall(this,e)}),this.calledByEntry.forEach(o=>{i.push(o),o.addCall(this,e)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(l),self:this}}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.successCalls.flatMap(i=>i.toFlat(e)),...this.errorCalls.flatMap(i=>i.toFlat(e)),...this.inputs.flatMap(i=>i.toFlat(e)),...this.outputs.flatMap(i=>i.toFlat(e)),...this.process?this.process.toFlat(e):[],...this.error?this.error.toFlat(e):[],...this.calledBy.flatMap(i=>i.toFlat(e))])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.successCalls.flatMap(i=>i.toFlatIds(e)),...this.errorCalls.flatMap(i=>i.toFlatIds(e)),...this.inputs.flatMap(i=>i.toFlatIds(e)),...this.outputs.flatMap(i=>i.toFlatIds(e))])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,x:this.x,y:this.y,type:this.type}}toJSON(e=new Set){var t,i;return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,successCalls:this.successCalls.map(s=>s.toJSON(e)),errorCalls:this.errorCalls.map(s=>s.toJSON(e)),calledBySuccess:this.calledBySuccess.map(s=>s.toReference()),calledByError:this.calledByError.map(s=>s.toReference()),calledByEntry:this.calledByEntry.map(s=>s.toReference()),process:(t=this.process)==null?void 0:t.toJSON(e),declaration:this.declaration.toJSON(e),inputs:this.inputs.map(s=>s.toJSON(e)),outputs:this.outputs.map(s=>s.toJSON(e)),parent:this.parent.toReference(),error:(i=this.error)==null?void 0:i.toJSON(e)})}toJSONClone(e=J){var i,s,l,o,d,u,y;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||ht(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(s=e.seenEntities)!=null&&s.has(t)||(l=e.seenEntities)!=null&&l.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(d=e.seenEntities)==null||d.add(this.id),{id:t,version:m.UUID.uuid(),createdAt:e.timestamp||T().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,successCalls:this.successCalls.map(c=>c.toJSONClone({...e,newId:null})),errorCalls:this.errorCalls.map(c=>c.toJSONClone({...e,newId:null})),calledBySuccess:this.calledBySuccess.map(c=>c.toReference({seenEntityMaps:e.seenEntityMaps})),calledByError:this.calledByError.map(c=>c.toReference({seenEntityMaps:e.seenEntityMaps})),calledByEntry:this.calledByEntry.map(c=>c.toReference({seenEntityMaps:e.seenEntityMaps})),process:(u=this.process)==null?void 0:u.toJSONClone({...e,newId:null}),declaration:this.declaration.toJSONClone({...e,newId:null}),inputs:this.inputs.map(c=>c.toJSONClone({...e,newId:null})),outputs:this.outputs.map(c=>c.toJSONClone({...e,newId:null})),error:(y=this.error)==null?void 0:y.toJSONClone({...e,newId:null}),parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps})})}toReference(e=J){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+m.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=J){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,process:this.process?this.process.toReference(e):null,inputs:this.inputs.map(s=>s.toReference(e)),outputs:this.outputs.map(s=>s.toReference(e)),declaration:this.declaration.toReference(e),successCalls:this.successCalls.map(s=>s.toReference(e)),errorCalls:this.errorCalls.map(s=>s.toReference(e)),calledBySuccess:this.calledBySuccess.map(s=>s.toReference(e)),calledByError:this.calledByError.map(s=>s.toReference(e)),calledByEntry:this.calledByEntry.map(s=>s.toReference(e)),error:this.error?this.error.toReference(e):null,parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.successCalls.flatMap(i=>i.toFlatJSON(e)),...this.errorCalls.flatMap(i=>i.toFlatJSON(e)),...this.inputs.flatMap(i=>i.toFlatJSON(e)),...this.outputs.flatMap(i=>i.toFlatJSON(e)),...this.process?this.process.toFlatJSON(e):[],...this.error?this.error.toFlatJSON(e):[]])}toGenerationTarget(){const e=this.parent.type===n.Project?void 0:this.parent.id;return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,calledByEntry:this.calledByEntry.map(t=>t.id),calledBySuccess:this.calledBySuccess.map(t=>t.id),calledByError:this.calledByError.map(t=>t.id),declaration:this.declaration.id,parent:e}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...this.successCalls.flatMap(i=>i.toFlatGenerationTarget(e)),...this.errorCalls.flatMap(i=>i.toFlatGenerationTarget(e)),...this.inputs.flatMap(i=>i.toFlatGenerationTarget(e)),...this.outputs.flatMap(i=>i.toFlatGenerationTarget(e)),...this.process?this.process.toFlatGenerationTarget(e):[],...this.error?this.error.toFlatGenerationTarget(e):[]])}clearErrors(){var e,t;return this.errors=[],this.inputs.forEach(i=>i.clearErrors()),this.outputs.forEach(i=>i.clearErrors()),this.successCalls.forEach(i=>i.clearErrors()),this.errorCalls.forEach(i=>i.clearErrors()),(e=this.process)==null||e.clearErrors(),(t=this.error)==null||t.clearErrors(),this}validate(){const e=H1(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){return[...this.errors,...this.inputs.flatMap(t=>t.getErrors()),...this.outputs.flatMap(t=>t.getErrors()),...this.error?this.error.getErrors():[],...this.process?this.process.getErrors():[]]}getShallowErrors(){return this.errors}clone(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"clone-entity")),t=null,i=null,s=!0){var O,P;let l=mt(t,this);const o=this.toJSON(),d=i||m.UUID.uuid();o.inputs=[];const u=d.split("-id"),y=u[u.length-1||0]||d;o.id=d,o.version=m.UUID.uuid(),o.createdAt=(e==null?void 0:e.timestamp)||T().toISOString(),o.author=(e==null?void 0:e.author)||"1",o.previousVersion=null,o.deleted=!1;const c=ct(o,l);t?c.setParent(t,null):c.setParent(this.parent,null),s&&c.subscribe(),c.initChildren(e),e==null||e.add(c,b.Added);const I=(O=this.inputs)==null?void 0:O.map((C,M)=>C.clone(e,c,y+"-input-map-"+M+"-id",s));c.inputs=I;const E=(P=this.outputs)==null?void 0:P.map((C,M)=>C.clone(e,c,y+"-output-map-"+M+"-id",s));return c.outputs=E,this.error&&(c.error=this.error.clone(e,c,y+"-error-map-id",s)),this.process&&(c.process=this.process.clone(e,c,y+"-process-id",s)),e==null||e.attemptAutoclose("clone-entity",this.id),c}removeUnrecognizedInputs(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-unrecognized-inputs"))){const t=[],i=[],s=[],l=[];return this.inputs.forEach(o=>{if(!this.declaration.inputs.find(u=>{var y;return u.id===((y=o.declaration)==null?void 0:y.id)})){const u=o.remove({ignoreUpstream:!1},e);s.push(...u.removed),t.push(...u.updated)}}),e==null||e.attemptAutoclose("remove-unrecognized-inputs",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}removeUnrecognizedOutputs(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-unrecognized-outputs"))){const t=[],i=[],s=[],l=[];return this.outputs.forEach(o=>{if(!this.declaration.getUniqueReturnDeclarations().find(u=>{var y;return u.id===((y=o.declaration)==null?void 0:y.id)})){const u=o.remove({ignoreUpstream:!1},e);s.push(...u.removed),t.push(...u.updated)}}),e==null||e.attemptAutoclose("remove-unrecognized-outputs",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}syncMissingFixedInputs(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-missing-fixed-inputs"))){const t=[],i=[],s=[],l=[],o=this.declaration.inputs.filter(c=>!this.inputs.find(I=>I.declaration.id===c.id));this.inputs.sort((c,I)=>c.index-I.index),o.forEach(c=>{this.inputs.forEach(O=>{O.index>=c.index&&O.metaSync({index:O.index+1},e)});const I={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.InputMap,declaration:c.toJSON(),readsValue:null,defaultValue:null,index:c.index,name:null,description:null,parent:this.toReference()},E=V(I,this.project);E.setParent(this,e),E.initChildren(e),e==null||e.add(E,b.Added),E.addSelfToProject(e),i.push(E)}),this.inputs.sort((c,I)=>c.index-I.index);const{updated:d,added:u,removed:y}=this.removeUnrecognizedInputs(e);return t.push(...d),i.push(...u),s.push(...y),e==null||e.attemptAutoclose("sync-missing-fixed-inputs",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}syncMissingFixedOutputs(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-missing-fixed-outputs"))){const t=[],i=[],s=[],l=[],o=[];this.outputs=this.initialData.outputs.map(I=>{const E=V(I,this.project);return o.push(E.index),E.setParent(this,null),E.initChildren(e),E});const d=this.declaration.getUniqueReturnDeclarations().filter(I=>!this.outputs.find(E=>E.declaration.id===I.id));this.outputs.sort((I,E)=>I.index-E.index),d.forEach((I,E)=>{this.outputs.forEach(M=>{M.index>=I.index&&M.index++});const O=o.includes(I.index)?this.outputs.length-1+E:I.index,P={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.OutputMap,declaration:I.toJSON(),defaultValue:null,writesValues:[],index:O,parent:this.toReference()},C=V(P,this.project);C.setParent(this,e),C.initChildren(e),e==null||e.add(C,b.Added),C.addSelfToProject(e)}),this.outputs.sort((I,E)=>I.index-E.index);const{updated:u,added:y,removed:c}=this.removeUnrecognizedOutputs(e);return t.push(...u),i.push(...y),s.push(...c),e==null||e.attemptAutoclose("sync-missing-fixed-outputs",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}};f(qe,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>e,APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...i)=>null}),f(qe,"type",n.FunctionCall),f(qe,"USER_MANAGED_PARENT_TYPES",[...dt,n.Project]),f(qe,"PARENT_TYPES",[...qe.USER_MANAGED_PARENT_TYPES]),f(qe,"MUTABLE_BASE_PROPERTIES",[]),f(qe,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),f(qe,"BASE_PROPERTIES",[...qe.MUTABLE_BASE_PROPERTIES,...qe.INMUTABLE_BASE_PROPERTIES]),f(qe,"MUTABLE_META_PROPERTIES",["x","y"]),f(qe,"INMUTABLE_META_PROPERTIES",[...qe.INMUTABLE_BASE_PROPERTIES]),f(qe,"META_PROPERTIES",[...qe.MUTABLE_META_PROPERTIES,...qe.INMUTABLE_META_PROPERTIES]),f(qe,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry"]),f(qe,"INMUTABLE_UPSTREAM_PROPERTIES",["declaration","parent"]),f(qe,"UPSTREAM_PROPERTIES",[...qe.MUTABLE_UPSTREAM_PROPERTIES,...qe.INMUTABLE_UPSTREAM_PROPERTIES]),f(qe,"MUTABLE_DOWNSTREAM_PROPERTIES",["successCalls","errorCalls","writesValues","inputs","outputs","error"]),f(qe,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),f(qe,"DOWNSTREAM_PROPERTIES",[...qe.MUTABLE_DOWNSTREAM_PROPERTIES,...qe.INMUTABLE_DOWNSTREAM_PROPERTIES]),f(qe,"PROPERTIES",[...qe.META_PROPERTIES,...qe.UPSTREAM_PROPERTIES,...qe.DOWNSTREAM_PROPERTIES]);let en=qe;function Zc(r){return r&&typeof r.then=="function"}class Wl{constructor(a){f(this,"order",[]);f(this,"flatRecord",{});f(this,"allBuiltInEntityIds",_i());f(this,"onGoingVisits",{});this.flatten(a),this.orderEntities()}flatten(a){const e=new Set(_i()),t=p(U(a,e,{ignoreBuiltInBaseEntities:!0})),i=new Set;for(const s of t)this.flatRecord[s.id]=s,i.add(s.id);this.order=Array.from(i)}moveEntityAfterDependencies(a){const{upstream:e}=Xl(a,this.flatRecord,{ignoreBuiltInBaseEntities:!0,allBuiltInEntityIds:this.allBuiltInEntityIds});for(const t of Object.keys(e)){const i=this.order.indexOf(t),s=this.order.indexOf(a.id);if(i>s)return this.order.splice(s,1),this.order.splice(i,0,a.id),!0}return!1}orderEntities(){let a=!1;for(let e=0;e<this.order.length;e++){const t=this.order[e],i=this.flatRecord[t];if(this.moveEntityAfterDependencies(i)){a=!0;break}}a&&this.orderEntities()}getUpstreamOngoingDependenciesVisits(a,e){const{upstream:t}=Xl(this.flatRecord[a],this.flatRecord,{ignoreBuiltInBaseEntities:!0,allBuiltInEntityIds:this.allBuiltInEntityIds}),i={};return Object.entries(this.onGoingVisits[e]||{}).forEach(([s,l])=>{Object.keys(t).includes(s)&&(i[s]=l)}),i}getDownstreamOngoingDependenciesVisits(a,e){const t=Object.keys(this.onGoingVisits[e]||{}),i=new Set(t.flatMap(l=>Object.keys(Xl(this.flatRecord[l],this.flatRecord,{ignoreBuiltInBaseEntities:!0,allBuiltInEntityIds:this.allBuiltInEntityIds}).downstream))),s={};return Array.from(i).forEach(l=>{l===a&&(s[l]=this.onGoingVisits[e][l])}),s}async settlePromises(a,e){const t=Object.values(a);t.length&&await Promise.all(t),Object.keys(a).forEach(i=>{delete this.onGoingVisits[e][i]})}visit(a){const e=this.order;for(const t of e)a(this.flatRecord[t],this.flatRecord);return this}reverseVisit(a){const e=this.order.slice().reverse();for(const t of e)a(this.flatRecord[t],this.flatRecord);return this}async visitAsync(a){const e=this.order,t=Math.random().toString(36).substring(7);this.onGoingVisits[t]={};for(const i of e){const s=this.getUpstreamOngoingDependenciesVisits(i,t);Object.keys(s).length&&await this.settlePromises(s,t);const l=a(this.flatRecord[i],this.flatRecord);Zc(l)&&(this.onGoingVisits[t][i]=l)}return await this.settlePromises(this.onGoingVisits[t],t),this.onGoingVisits[t]={},this}async reverseVisitAsync(a){const e=this.order.slice().reverse(),t=Math.random().toString(36).substring(7);this.onGoingVisits[t]={};for(const i of e){const s=this.getDownstreamOngoingDependenciesVisits(i,t);Object.keys(s).length&&await this.settlePromises(s,t);const l=a(this.flatRecord[i],this.flatRecord);Zc(l)&&(this.onGoingVisits[t][i]=l)}return await this.settlePromises(this.onGoingVisits[t],t),this.onGoingVisits[t]={},this}}function X1(r,a){switch(r.id){case k["built-in-base-entity"].BUILT_IN_PERSISTED_ENTITY_ENTITY.id:{const e=r.project.entities.filter(d=>!!d.implements.find(u=>u.id===k["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.id));if(e.find(d=>!!d.properties.find(u=>{var y;return u.implements&&u.implements.id===k["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.default.id&&((y=u.getDefaultValue())==null?void 0:y.value)===!0}))){const u=e[0].properties.find(c=>c.implements&&c.implements.id===k["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.default.id),y=u==null?void 0:u.defaultValue;if(y)y.value=!0;else if(u!=null&&u.dataType){const c={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(a==null?void 0:a.timestamp)||new Date().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.LiteralValue,name:L.EntityTemplate,autogeneration:null,value:!0,valueAsTypeSingle:null,valueAsTypeList:null,parent:u==null?void 0:u.dataType.toReference()},I=V(c,r.project);return I.setParent(u==null?void 0:u.dataType,a),I.initChildren(a),a==null||a.add(I,b.Added),I.addSelfToProject(a),{newEntities:[I]}}return{newEntities:[]}}const i=r.project.get(k["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.id),s=zl(i,"Main database",a);if(s.errors.length>0)return{newEntities:[]};const l=s.properties.find(d=>d.implements&&d.implements.id===k["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.default.id),o=l==null?void 0:l.defaultValue;if(o)o.value=!0;else if(l!=null&&l.dataType){const d={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(a==null?void 0:a.timestamp)||new Date().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.LiteralValue,name:L.EntityTemplate,autogeneration:null,value:!0,valueAsTypeSingle:null,valueAsTypeList:null,parent:l==null?void 0:l.dataType.toReference()},u=V(d,r.project);u.setParent(l==null?void 0:l.dataType,a),u.initChildren(a),a==null||a.add(u,b.Added),u.addSelfToProject(a)}return{newEntities:[s]}}}return{newEntities:[]}}function Q1(r,a){const e=[],t=[],i=[],s=[];return r.implements.filter(o=>o.type===n.BuiltInBaseEntity).forEach(o=>{var d;switch(o.id){case k["built-in-base-entity"].BUILT_IN_PERSISTED_ENTITY_ENTITY.id:{let y=r.project.entities.filter(E=>E.implements.find(O=>O.id===k["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.id)).find(E=>!!E.properties.find(O=>{var P;return O.implements&&O.implements.id===k["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.default.id&&((P=O.getDefaultValue())==null?void 0:P.value)===!0}));if(!y){y=r.project.getBuiltIn(k["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.id).implement("Relational database",a);const O=y.properties.find(P=>{var C;return((C=P.implements)==null?void 0:C.id)===k["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.default.id});(d=O==null?void 0:O.defaultValue)==null||d.metaSync({value:!0},a),t.push(y)}const c=r.properties.find(E=>E.implements&&E.implements.id===k["built-in-base-entity"].BUILT_IN_PERSISTED_ENTITY_ENTITY.properties.database.id),I=c==null?void 0:c.defaultValue;if(c&&!I){const E={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(a==null?void 0:a.timestamp)||new Date().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.LiteralValue,name:L.EntityTemplate,autogeneration:null,value:null,valueAsTypeSingle:y,valueAsTypeList:null,parent:c==null?void 0:c.toReference()},O=V(E,r.project);O.hydrateAncestors(),O.setParent(c,a),O.addSelfToProject(a),O.initChildren(a),a==null||a.add(O,b.Added),t.push(O);return}else I&&I.setValueAsTypeSingle(y,a);return}}}),{self:r,updated:p(e),added:p(t),removed:p(i),affected:p(s)}}function zl(r,a,e,t){const i=t||m.UUID.uuid(),s=m.UUID.uuid(),l={id:i,version:s,createdAt:(e==null?void 0:e.timestamp)||new Date().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,name:a,type:n.DefinitionEntity,description:null,static:r.static,abstract:!1,properties:[],methods:[],abstractMethods:[],extends:[],implements:[r],x:0,y:0,parent:r.project};X1(r,e);const o=V(l,r.project);return o.hydrateAncestors(),e==null||e.add(o,b.Added),o.addSelfToProject(e),o.addImplementation(r),o.setParent(r.project,e),o.initChildren(e),o.afterAllChildrenInitialized(e),Q1(o,e),o}function qc(r,a){return a.entities.find(i=>{const s=i.properties,l=s.map(c=>c.name),o=r.every(c=>l.includes(c)),d=l.filter(c=>!r.includes(c)),u=s.every(c=>!d.includes(c.name)||!c.required);return o&&u})||null}function eP(r,a,e,t=Dt.OrDataTypeGroup){const i=[],s=[],l=[],o=[],u={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||new Date().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.DataType,options:null,implementationChooseOne:!1,entity:r.toJSON(),isList:!1,asType:null,andChildrenGroup:null,orChildrenGroup:null,like:!0,inferred:!1,parentRelationType:t,parent:a.toReference()},y=V(u,r.project);return s.push(y),y.setParent(a,e),y.initChildren(e),e==null||e.add(y,b.Added),y.setEntity(r),y.addSelfToProject(e),{updated:p(i),added:p(s),removed:p(l),affected:p(o),self:y}}function Jc(r,a,e,t,i){var u,y,c,I,E,O,P,C;const s=[],l=[],o=[],d=[];switch(typeof r){case"string":let M=!1;const G=new Date(r);if(G instanceof Date&&!isNaN(G.valueOf())&&(M=!0),M){const B=a.project.getBuiltIn(k[n.PrimitiveEntity][L.Date].id);a.setEntity(B);break}else{const B=a.project.getBuiltIn(k[n.PrimitiveEntity][L.String].id);a.setEntity(B);break}case"number":a.setEntity(a.project.getBuiltIn(k[n.PrimitiveEntity][L.Number].id));break;case"boolean":a.setEntity(a.project.getBuiltIn(k[n.PrimitiveEntity][L.Boolean].id));break;case"object":if(r===null){a.setEntity(a.project.getBuiltIn(k[n.PrimitiveEntity][L.Null].id));break}else if(Array.isArray(r))if(a.metaSync({isList:!0},t),r.length>0){const B=r.slice(0,5).filter(q=>q!==void 0);if(B.every(q=>typeof q==typeof B[0])&&(typeof B[0]!="object"||B[0]===null))switch(typeof B[0]){case"string":a.setEntity(a.project.getBuiltIn(k[n.PrimitiveEntity][L.String].id));break;case"number":a.setEntity(a.project.getBuiltIn(k[n.PrimitiveEntity][L.Number].id));break;case"boolean":a.setEntity(a.project.getBuiltIn(k[n.PrimitiveEntity][L.Boolean].id));break;case"object":a.setEntity(a.project.getBuiltIn(k[n.PrimitiveEntity][L.Null].id));break}else{const q=[];let S=!1;B.forEach(pe=>{var Ie,Q,le,ei;if(Array.isArray(pe)&&(S=!0),typeof pe=="object"&&!Array.isArray(pe)&&pe!==null){const Xi=Yl(pe,a.project,{...e,id:m.UUID.uuid()},t,i);Xi.hasCreated&&q.push((Ie=Xi.changeSet)==null?void 0:Ie.self),s.push(...(Q=Xi.changeSet)==null?void 0:Q.updated),l.push(...(le=Xi.changeSet)==null?void 0:le.added),o.push(...(ei=Xi.changeSet)==null?void 0:ei.removed)}});const X=p(q);if(!X.length&&!S){B.forEach(pe=>{const Ie={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(t==null?void 0:t.timestamp)||new Date().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.DataType,options:null,implementationChooseOne:!1,entity:null,isList:!1,asType:null,andChildrenGroup:null,orChildrenGroup:null,like:!0,inferred:!1,parentRelationType:Dt.OrDataTypeGroup,parent:a.toReference()},Q=V(Ie,a.project);switch(Q.setParent(a,t),Q.initChildren(t),t==null||t.add(Q,b.Added),Q.addSelfToProject(t),typeof pe){case"string":Q.setEntity(Q.project.getBuiltIn(k[n.PrimitiveEntity][L.String].id));break;case"number":Q.setEntity(Q.project.getBuiltIn(k[n.PrimitiveEntity][L.Number].id));break;case"boolean":Q.setEntity(Q.project.getBuiltIn(k[n.PrimitiveEntity][L.Boolean].id));break;case"object":Q.setEntity(Q.project.getBuiltIn(k[n.PrimitiveEntity][L.Null].id));break}});break}else X.length===1&&!S?a.setEntity(X[0]):B.forEach(pe=>{if(typeof pe=="object"&&!Array.isArray(pe)&&pe!==null){const Ie=qc(Object.keys(pe),a.project);if(Ie){const Q=eP(Ie||X[0],a,t,Dt.OrDataTypeGroup);s.push(...Q.updated),l.push(...Q.added),o.push(...Q.removed)}}else{const Ie={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(t==null?void 0:t.timestamp)||new Date().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.DataType,options:null,implementationChooseOne:!1,entity:null,isList:Array.isArray(pe),asType:null,andChildrenGroup:null,orChildrenGroup:null,like:!0,inferred:!1,parentRelationType:Dt.OrDataTypeGroup,parent:a.toReference()},Q=V(Ie,a.project);Q.setParent(a,t),Q.initChildren(t),t==null||t.add(Q,b.Added),Q.addSelfToProject(t);const le=Jc(pe,Q,{...e,id:m.UUID.uuid()},t,i);s.push(...le.updated),l.push(...le.added),o.push(...le.removed)}})}}else{const B=Yl(r[0],a.project,{...e},t,i);a.setEntity((u=B.changeSet)==null?void 0:u.self),s.push(...(y=B.changeSet)==null?void 0:y.updated),l.push(...(c=B.changeSet)==null?void 0:c.added),o.push(...(I=B.changeSet)==null?void 0:I.removed);break}else{const B=Yl(r,a.project,{...e},t,i);a.setEntity((E=B.changeSet)==null?void 0:E.self),s.push(...(O=B.changeSet)==null?void 0:O.updated),l.push(...(P=B.changeSet)==null?void 0:P.added),o.push(...(C=B.changeSet)==null?void 0:C.removed);break}}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:a}}function Yl(r,a,e,t,i){const s=[],l=[],o=[],d=[],u=Object.keys(r),y=qc(u,a);if(y)return{hasCreated:!1,changeSet:{updated:[],added:[],removed:[],affected:[],self:y}};const c=i?e.name+" of "+i.name:e.name,E={id:e.id||m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(t==null?void 0:t.timestamp)||new Date().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,name:c,type:n.DefinitionEntity,description:e.description||null,static:e.static||!1,abstract:e.abstract||!1,properties:[],methods:[],abstractMethods:[],extends:[],implements:[],x:0,y:0,parent:a.toReference()},O=V(E,a);return O.setParent(a,t),O.initChildren(t),t==null||t.add(O,b.Added),O.addSelfToProject(t),l.push(O),u.forEach((P,C)=>{const G={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(t==null?void 0:t.timestamp)||new Date().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,name:P,type:n.Property,description:null,static:!1,abstract:!1,defaultValue:null,constant:!1,dataType:null,implements:null,index:C,hidden:!1,private:!1,required:!0,parent:O.toReference()},B=V(G,a);B.setParent(O,t),B.initChildren(t),t==null||t.add(B,b.Added),B.addSelfToProject(t),l.push(B);const g=r[P],S={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(t==null?void 0:t.timestamp)||new Date().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.DataType,parentRelationType:null,options:null,implementationChooseOne:!1,entity:null,isList:!1,asType:null,andChildrenGroup:null,orChildrenGroup:null,like:!0,inferred:!1,parent:B.toReference()},X=V(S,a);X.setParent(B,t),X.initChildren(t),t==null||t.add(X,b.Added),X.addSelfToProject(t),l.push(X);const pe=Jc(g,X,{...e,name:P,id:m.UUID.uuid()},t,i||O);s.push(...pe.updated),l.push(...pe.added),o.push(...pe.removed)}),{hasCreated:!0,changeSet:{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:O}}}function Tr(r,a,e,t){const i=[];return!r.length||!a.length?{errors:i,overlap:!1}:(r.length>a.length?r.forEach(s=>{const l=a.find(d=>d.name===s.name),o=a.find(d=>{var u,y;return!!s.implements&&((u=d.implements)==null?void 0:u.id)===((y=s.implements)==null?void 0:y.id)});if(l){const d=new it({id:s.id+"--"+l.id+"--"+t,message:`Entity of type ${s.type} named "${s.name}" with id "${s.id}" overrides a base ${l.type} ${l.name} with id "${l.id}" that has the same name`,issue:null,severity:D.Error,code:t,entity:s,firstRelationship:l});i.push(d)}if(o){const d=new it({id:s.id+"--"+o.id+"--"+e,message:`Entity of type ${s.type} named "${s.name}" with id "${s.id}" overrides a base ${o.type} ${o.name} with id "${o.id}" that implements the same base descriptor`,issue:null,severity:D.Error,code:e,entity:s,firstRelationship:o});i.push(d)}}):a.forEach(s=>{var d;const l=r.find(u=>u.name===s.name),o=r.find(u=>{var y,c;return!!u.implements&&((y=u.implements)==null?void 0:y.id)===((c=s.implements)==null?void 0:c.id)});if(l){const u=new it({id:l.id+"--"+s.id+"--"+t,message:`Entity of type ${l.type} named "${l.name}" with id "${l.id}" overrides a base entity ${s.name} with id "${s.id}" that has the same name`,issue:null,severity:D.Error,code:t,entity:l,firstRelationship:s});i.push(u)}if(o){const u=new it({id:o.id+"--"+s.id+"--"+e,message:`Entity of type ${o.type} named "${o.name}" with id "${o.id}" overrides a base entity ${s.name} with id "${s.id}" that implements the same base ${(d=o==null?void 0:o.implements)==null?void 0:d.type}`,issue:null,severity:D.Error,code:e,entity:o,firstRelationship:s});i.push(u)}}),{errors:i,overlap:!!i.length})}function uS(r,a){return r.abstract||(r.properties.forEach(t=>{t.abstract||t.metaSync({abstract:!0},a)}),Object.values(r.detachedDependents).forEach(t=>{t.field===Vc.Entity&&t.entity.remove({ignoreUpstream:!1},a)}),r.metaSync({abstract:!0},a)),r}function pS(r,a){return r.abstract&&(r.properties.forEach(t=>{t.abstract&&t.metaSync({abstract:!1},a)}),Object.values(r.detachedDependents).forEach(t=>{(t.field===nd.Implements||t.field===nd.Extends)&&t.entity.onDetachedDependencyRemoved(r,t.field,a)}),r.metaSync({abstract:!1},a)),r}function cS(r,a){return r.static||(r.properties.forEach(t=>{t.static||t.metaSync({static:!0},a)}),r.metaSync({static:!0},a)),r}function fS(r,a){return r.static&&(r.properties.forEach(t=>{t.static&&t.metaSync({static:!1},a)}),r.metaSync({static:!1},a)),r}function Ds(r,a){const e=Ln(r);if(e.length===0)return{list:[],last:null};let t=null;return{list:e.flatMap(s=>{if(s===a)return t=s,[s];const l=Ds(s,a);return l.last&&(t=l.last),[s,...l.list]}),last:t}}function Sc(r){const a=r.calledBy;if(a.length===0)return r.project;const e=a.reduce((t,i)=>{const s=Zt(i,r.project);return!s||s.type===n.Project?t:t.type===n.Project||Ds(s,t).last?s:(Ds(t,s).last,t)},r.project);return e.type===n.FunctionDeclaration&&e.parent.type===n.Loop?e.parent:e}function K(r,a){var i,s;let e=Sc(r);if(r.type===n.InternalCall)(i=r.parent)==null||i.setParent(e,a),(s=r.parent)==null||s.addSelfToProject(a);else if((r.type===n.ContinueStatement||r.type===n.BreakStatement)&&e.type!==n.Loop){r.remove({ignoreUpstream:!1},a);return}else if(r.type===n.ReturnStatement&&!dt.includes(e.type)){r.remove({ignoreUpstream:!1},a);return}else r.setParent(e,a),r.addSelfToProject(a);if(st.includes(r.type))return;Je(r).forEach(l=>{var d,u;const o=Sc(l);if(l.type===n.InternalCall)(d=l.parent)==null||d.setParent(o,a),(u=l.parent)==null||u.addSelfToProject(a);else if((l.type===n.ContinueStatement||l.type===n.BreakStatement)&&o.type!==n.Loop){l.remove({ignoreUpstream:!1},a);return}else if(l.type===n.ReturnStatement&&!dt.includes(o.type)){l.remove({ignoreUpstream:!1},a);return}else l.setParent(o,a),l.addSelfToProject(a)})}function tP(r,a,e=new Set){const t=tn(r),i=tn(a),s=t.filter(d=>!i.includes(d)),l=t.filter(d=>i.includes(d)),o=s.reduce((d,u)=>e.has(u.id)?d:(e.add(u.id),p([...d,...tP(u,a,e)])),[]);return p([...l,...o])}function _a(r,a){const e=Ds(r,a);return e.last===a&&e.list.length>0&&e.list[0]!==a}function yS(r,a){return!!Ds(r,a).last}function hS(r){if(lt.includes(r.type))return r;if([...Mi,n.VariableDeclaration].includes(r.type)){const a=r.parent;return lt.includes(a.type)?a:null}return null}function Wc(r,a){if(!r||!a)throw new Error("Both entities must be defined to find a common ancestor");if(r===a)return r;const e=r.parent;if(e){if(e===a)return a;if(e.type===n.Project)return null}else return null;const t=a.parent;if(t){if(t===r)return r;if(t.type===n.Project)return null}else return null;return Wc(e,t)}function wt(r){if(Sa.includes(r.type)){if(r.type===n.FunctionDeclaration){const a=r.parent;if(a.type===n.DefinitionEntity)return a;if(a.type===n.Loop)return a}return r}else{const a=r.parent;return a?wt(a):null}}function Hl(r,a){const e=Ma(r,a);if(!e)return null;if(Sa.includes(e.type)){if(e.type===n.FunctionDeclaration){const t=Ma(e.parent,a);if(t){if(t.type===n.DefinitionEntity)return t;if(t.type===n.Loop)return t}}return e}else{const t=e.parent?Ma(e.parent,a):null;return t?Hl(t,a):null}}function iP(r){if(!r)return null;if(Mi.includes(r.type))return r;const a=r.parent;return a?iP(a):null}function rP(r){if(!r)return null;if(ot.includes(r.type))return r;const a=r.parent;return a?rP(a):null}function nP(r){if(!r)return null;if(Ni.includes(r.type))return r;const a=r.parent;return a?nP(a):null}function mS(r){return r.type===n.VariableDeclaration?[r]:ot.includes(r.type)?[...r.inputs,...r.outputs||[]]:st.includes(r.type)?r.outputs:Gn.includes(r.type)||r.type===n.FunctionDeclaration?r.inputs:[]}function vS(r){const a=tn(r),e=[],t=[];lf.includes(r.type)&&e.push(...zc(r));const i=a.filter(s=>{const l=e.includes(s);return l?!1:Mi.includes(s.type)&&!l?(t.push(s),!1):!0});return e.sort((s,l)=>_a(l,s)?-1:0),t.sort((s,l)=>_a(l,s)?-1:0),[...e,...t,...i]}function sP(r){return[...r].sort((a,e)=>_a(e,a)?-1:0)}function TS(r){const a=sP(r),e=[];return a.forEach(t=>{const i=e[e.length-1];if(i){const s=i[i.length-1];_a(t,s)?e.push([t]):i.push(t)}else e.push([t])}),e}function Xt(r){const a=r.map(e=>wt(e));return p(a)}function zc(r){return ot.includes(r.type)?[...Xt(r.successCalls),...Xt(r.errorCalls)]:lt.includes(r.type)?Xt(r.calls):[]}function IS(r,a){return zc(r).includes(a)}function Yc(r){return r.writesValues||[]}function ES(r,a){return Yc(r).includes(a)}function aP(r){var a;return tt.includes((a=r==null?void 0:r.readsValue)==null?void 0:a.type)?r.readsValue:null}function AS(r){return r.writesValues}function oP(r=[]){return r.map(aP).filter(a=>!!a)}function Kl(r=[]){return r.map(a=>a.writesValues).flat().filter(a=>tt.includes(a.type))}function lP(r=[]){return r.map(a=>a.readsValue).filter(a=>!!a&&tt.includes(a.type))}function dP(r){return tt.includes(r.type)?r:null}function uP(r){return r.writesValues.map(dP).filter(a=>!!a)}function pP(r=[]){return r.reduce((a,e)=>e.type===n.OutputMap?[...a,...uP(e)]:a,[])}function Je(r){return ot.includes(r.type)?[...Hi(Xt(r.successCalls)),...Hi(Xt(r.errorCalls))]:lt.includes(r.type)?Hi(Xt(r.calls)):[]}function bS(r){return ot.includes(r.type)?[...Hi(Xt(r.successCalls)),...Hi(Xt(r.errorCalls))]:lt.includes(r.type)?Hi(Xt(r.calls)):[]}function cP(r,a=new Set){return r.writesValues.filter(t=>tt.includes(t.type)&&!a.has(t.id)).reduce((t,i)=>a.has(i.id)?t:[...t,...Ye(i,a)],[])}function fP(r,a=new Set){var t;return(((t=r.readsValue)==null?void 0:t.writesValues)||[]).filter(i=>tt.includes(i.type)&&!a.has(i.id)).reduce((i,s)=>a.has(s.id)?i:[...i,...Ye(s,a)],[])}function Ye(r,a=new Set){if(a.has(r.id))return[];if(r.type===n.ReturnStatement)return lP(r.outputs).reduce((t,i)=>[...t,...Ye(i,a)],[]);if(r.type===n.FunctionCall||r.type===n.Operation||r.type===n.Condition)return[...Je(r).reduce((s,l)=>{const o=wt(l);return[...s,...Ye(o||l,a)]},[]),...oP(r.inputs),...pP(r.outputs)].reduce((s,l)=>[...s,...Ye(l,a)],[]);if(Gn.includes(r.type)){const e=Kl(r.inputs),i=Je(r).reduce((s,l)=>{const o=wt(l);return[...s,...Ye(o||l,a)]},[]);return e.push(...i),e.reduce((s,l)=>[...s,...Ye(l,a)],[])}if(r.type===n.FunctionDeclaration){const e=[...Kl(r.inputs)],i=Je(r).reduce((s,l)=>{const o=wt(l);return[...s,...Ye(o||l,a)]},[]);return e.push(...i),e.reduce((s,l)=>[...s,...Ye(l)],[])}if(tt.includes(r.type)){a.add(r.id);const t=Je(r).reduce((i,s)=>{const l=wt(s);return[...i,...Ye(l||s,a)]},[]);return[r,...t,...fP(r,a),...cP(r,a)]}return[]}function oi(r,a=new Set){return a.has(r.id)?[]:(a.add(r.id),[...tn(r).reduce((i,s)=>[...i,s,...oi(s,a)],[])])}function Hi(r){return r.reduce((a,e)=>e.type===n.ReturnStatement||e.type===n.ContinueStatement||e.type===n.BreakStatement?[...a,e]:[...a,e,...Je(e)],[])}function yP(r){const a=r.entities||[],e=[...a,...r.functions||[],...r.events||[],...r.projects||[]],t=a.reduce((d,u)=>[...d,...u.properties],[]),i=a.reduce((d,u)=>[...d,...u.methods],[]),s=i.reduce((d,u)=>[...d,...Kl(u.inputs),...Hi(Xt(u.calls)),...u.returnStatements],[]),l=r.functions.reduce((d,u)=>[...d,...Hi(Xt(u.calls)),...u.returnStatements],[]),o=r.events.reduce((d,u)=>[...d,...Hi(Xt(u.calls)),...u.returnStatements],[]);return[...e,...t,...i,...s,...l,...o]}function hP(r,a){return a.filter(t=>{if(!t)return!1;switch(t.type){case n.FunctionCall:return t.inputs.find(i=>i.id===r.id)!==void 0||t.outputs.find(i=>i.id===r.id)!==void 0;case n.Condition:return t.successCalls.find(i=>i.id===r.id)!==void 0||t.errorCalls.find(i=>i.id===r.id)!==void 0||t.inputs.find(i=>i.id===r.id)!==void 0;case n.Operation:return t.outputs.find(i=>i.id===r.id)!==void 0;case n.VariableDeclaration:return ot.includes(r.type)?ZP(r).find(s=>{var l;return((l=s.readsValue)==null?void 0:l.id)===t.id})!==void 0:!1;case n.DefinitionEntity:return t.properties.find(i=>i.id===r.id)!==void 0||t.methods.find(i=>i.id===r.id)!==void 0;case n.FunctionDeclaration:return t.inputs.find(i=>i.id===r.id)!==void 0||(t.returnStatements.map(i=>i.outputs).flat()||[]).find(i=>i.id===r.id)!==void 0;default:return!1}})}function RS(r){const a=yP(r.project);return hP(r,a)}function Ma(r,a){return r?typeof r=="string"?a[r]:r.type===n.GenericReference?a[r.entityId]:a[r.id]?a[r.id]:null:null}function Xl(r,a={},e={ignoreBuiltInBaseEntities:!1,allBuiltInEntityIds:[]}){if(e.ignoreBuiltInBaseEntities&&(Ti.includes(r.type)||(e.allBuiltInEntityIds||[]).includes(r.id)))return{upstream:{},downstream:{}};const t=r,i=r,s=r,l=r,o=r,d=r,u=r,y=r,c=r,I=r,E=r,O=r,P=r,C=[...P.readsValue?[P.readsValue]:[],...P.declaration?[P.declaration]:[],...(O.calledByEntry||[]).flatMap(g=>g),...(O.calledBySuccess||[]).flatMap(g=>g),...(O.calledByError||[]).flatMap(g=>g),...(s.extends||[]).flatMap(g=>g),...I.parent?[I.parent]:[]];Array.isArray(s.implements)?C.push(...s.implements.flatMap(g=>g)):c.implements&&C.push(c.implements),o.valueAsTypeList&&Array.isArray(o.valueAsTypeList)&&C.push(...o.valueAsTypeList.flatMap(g=>g)),o.valueAsTypeSingle&&C.push(o.valueAsTypeSingle);const M=[...(t.inputs||[]).flatMap(g=>g),...(E.inputsDeclarations||[]).flatMap(g=>g),...(t.outputs||[]).flatMap(g=>g),...(E.outputsDeclarations||[]).flatMap(g=>g),...(P.internalCalls||[]).flatMap(g=>g),...P.writesValues||[],...O.dataType?[O.dataType]:[],...d.body?[d.body]:[],...O.defaultValue?[O.defaultValue]:[],...(O.successCalls||[]).flatMap(g=>g),...(O.errorCalls||[]).flatMap(g=>g),...(s.properties||[]).flatMap(g=>g),...(s.methods||[]).flatMap(g=>g),...(s.abstractMethods||[]).flatMap(g=>g),...u.error?[u.error]:[],...u.process?[u.process]:[],...I.throws?[I.throws]:[],...(i.andChildrenGroup||[]).flatMap(g=>g),...(i.orChildrenGroup||[]).flatMap(g=>g),...(y.entities||[]).flatMap(g=>g),...(y.functions||[]).flatMap(g=>g),...(y.functionCalls||[]).flatMap(g=>g),...(y.events||[]).flatMap(g=>g),...(y.conditions||[]).flatMap(g=>g),...(y.operations||[]).flatMap(g=>g),...(y.loops||[]).flatMap(g=>g),...(y.variableDeclarations||[]).flatMap(g=>g),...(y.variableInstances||[]).flatMap(g=>g),...(y.searches||[]).flatMap(g=>g),...(y.projects||[]).flatMap(g=>g),...(l.calls||[]).flatMap(g=>g)];r.type===n.DataType&&(i.entity&&a[_(i.entity)]&&a[_(i.entity)].parent&&_(a[_(i.entity)].parent)===r.id?M.push(i.entity):i.entity&&C.push(i.entity));const G={},B={};return C.forEach(g=>{const q=_(g);if(q&&e.ignoreBuiltInBaseEntities&&(Ti.includes(g.type)||(e.allBuiltInEntityIds||[]).includes(q)))return;const S=g.version;q&&(G[q]=S)}),M.forEach(g=>{const q=_(g);if(q&&e.ignoreBuiltInBaseEntities&&(Ti.includes(g.type)||(e.allBuiltInEntityIds||[]).includes(q)))return;const S=g.version;q&&(B[q]=S)}),{upstream:G,downstream:B}}function DS(r,a){const e=[];if(Mi.includes(r.type)){hi(r).forEach(s=>{const l=Hl(s,a);l&&e.push(l)});const i=[...r.inputs||[],...r.outputs||[]].map(s=>{const l=Ma(s,a);return l?JP(l,a):null}).filter(s=>s!==null);e.push(...p(i))}if(tt.includes(r.type)){const t=Ql(r);t&&e.push(t)}return p(e)}function Ln(r){const a=[];if(Mi.includes(r.type)){r.calledBy.forEach(i=>{const s=wt(i);s&&a.push(s)});const t=[...r.inputs||[],...r.outputs||[]].map(i=>Ql(i)).filter(i=>i!==null);a.push(...p(t))}if(tt.includes(r.type)){const e=Ql(r);e&&a.push(e)}return p(a)}function hi(r){return[...r.calledByEntry||[],...r.calledByError||[],...r.calledBySuccess||[]].filter(a=>a.type!==n.GenericReference)}function mP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.ActionDescriptor)throw new Error("Entity must be an action descriptor to be flattened");return[r,...r.inputs.flatMap(t=>U(t,a,e)),...r.outputs.flatMap(t=>U(t,a,e)),...r.error?U(r.error,a,e):[],...r.parent?U(r.parent,a,e):[]]}function vP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.ArgumentDeclaration)throw new Error("Entity must be an argument declaration to be flattened");return[r,...r.defaultValue?U(r.defaultValue,a):[],...r.writesValues.flatMap(t=>U(t,a,e)),...r.dataType?U(r.dataType,a,e):[],...r.parent?U(r.parent,a,e):[]]}function TP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.BreakStatement)throw new Error("Entity must be a break statement to be flattened");return[r,...r.outputs.flatMap(t=>U(t,a,e)),...r.throws?U(r.throws,a,e):[],...(hi(r)||[]).flatMap(t=>U(t,a,e)),...r.parent?U(r.parent,a,e):[]]}function IP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.BuiltInBaseEntity)throw new Error("Entity must be a built-in base entity to be flattened");return[r,...(r.properties||[]).flatMap(t=>U(t,a,e)),...(r.methods||[]).flatMap(t=>U(t,a,e)),...(r.abstractMethods||[]).flatMap(t=>U(t,a,e)),...(r.extends||[]).flatMap(t=>U(t,a,e))]}function EP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.Condition)throw new Error("Entity must be a condition to be flattened");return[r,...(r.inputs||[]).flatMap(t=>U(t,a,e)),...(r.successCalls||[]).flatMap(t=>U(t,a,e)),...(r.errorCalls||[]).flatMap(t=>U(t,a,e)),...(hi(r)||[]).flatMap(t=>U(t,a,e)),...r.parent?U(r.parent,a,e):[]]}function AP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.ContinueStatement)throw new Error("Entity must be a continue statement to be flattened");return[r,...r.outputs.flatMap(t=>U(t,a,e)),...r.throws?U(r.throws,a,e):[],...(hi(r)||[]).flatMap(t=>U(t,a,e)),...r.parent?U(r.parent,a,e):[]]}function bP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.DefinitionEntity)throw new Error("Entity must be a definition entity to be flattened");return[r,...(r.extends||[]).flatMap(t=>U(t,a,e)),...(r.implements||[]).flatMap(t=>U(t,a,e)),...(r.properties||[]).flatMap(t=>U(t,a,e)),...(r.methods||[]).flatMap(t=>U(t,a,e)),...(r.abstractMethods||[]).flatMap(t=>U(t,a,e)),...r.parent?U(r.parent,a,e):[]]}function RP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.DataType)throw new Error("Entity must be a data type to be flattened");return[r,...(r.andChildrenGroup||[]).flatMap(t=>U(t,a,e)),...(r.orChildrenGroup||[]).flatMap(t=>U(t,a,e)),...r.entity?U(r.entity,a,e):[],...r.parent?U(r.parent,a,e):[]]}function DP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.FunctionCall)throw new Error("Entity must be a function call to be flattened");return[r,...(r.inputs||[]).flatMap(t=>U(t,a,e)),...(r.outputs||[]).flatMap(t=>U(t,a,e)),...r.error?U(r.error,a,e):[],...r.process?U(r.process,a,e):[],...(hi(r)||[]).flatMap(t=>U(t,a,e)),...(r.successCalls||[]).flatMap(t=>U(t,a,e)),...(r.errorCalls||[]).flatMap(t=>U(t,a,e)),...r.parent?U(r.parent,a,e):[]]}function OP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.FunctionDeclaration)throw new Error("Entity must be a function declaration to be flattened");return[r,...(r.inputs||[]).flatMap(t=>U(t,a,e)),...(r.calls||[]).flatMap(t=>U(t,a,e)),...r.implements?U(r.implements,a,e):[],...r.parent?U(r.parent,a,e):[]]}function PP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.GlobalEvent)throw new Error("Entity must be a global event to be flattened");return[r,...(r.inputs||[]).flatMap(t=>U(t,a,e)),...(r.calls||[]).flatMap(t=>U(t,a,e)),...r.implements?U(r.implements,a,e):[],...r.parent?U(r.parent,a,e):[]]}function wP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.InputMap)throw new Error("Entity must be an input map to be flattened");return[r,...r.readsValue?U(r.readsValue,a,e):[],...r.declaration?U(r.declaration,a,e):[],...r.defaultValue?U(r.defaultValue,a,e):[],...r.parent?U(r.parent,a,e):[]]}function CP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.InstalledProject)throw new Error("Entity must be an installed project to be flattened");return[r,...(r.functions||[]).flatMap(t=>U(t,a,e)),...(r.events||[]).flatMap(t=>U(t,a,e)),...r.parent?U(r.parent,a,e):[]]}function VP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.InternalCall)throw new Error("Entity must be an internal call to be flattened");return[r,...(r.successCalls||[]).flatMap(t=>U(t,a,e)),...(r.errorCalls||[]).flatMap(t=>U(t,a,e)),...(r.inputs||[]).flatMap(t=>U(t,a,e)),...(r.outputs||[]).flatMap(t=>U(t,a,e)),...(hi(r)||[]).flatMap(t=>U(t,a,e)),...r.error?U(r.error,a,e):[],...r.process?U(r.process,a,e):[],...r.parent?U(r.parent,a,e):[]]}function BP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.LiteralValue)throw new Error("Entity must be a literal value to be flattened");return[r,...r.valueAsTypeSingle?U(r.valueAsTypeSingle,a,e):[],...r.valueAsTypeList&&Array.isArray(r.valueAsTypeList)?r.valueAsTypeList.flatMap(t=>U(t,a,e)):[],...r.parent?U(r.parent,a,e):[]]}function _P(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.Loop)throw new Error("Entity must be a loop to be flattened");return[r,...(r.inputs||[]).flatMap(t=>U(t,a,e)),...(r.outputs||[]).flatMap(t=>U(t,a,e)),...(r.successCalls||[]).flatMap(t=>U(t,a,e)),...(r.errorCalls||[]).flatMap(t=>U(t,a,e)),...r.error?U(r.error,a,e):[],...r.process?U(r.process,a,e):[],...r.body?U(r.body,a,e):[],...(hi(r)||[]).flatMap(t=>U(t,a,e)),...r.parent?U(r.parent,a,e):[]]}function MP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.Operation)throw new Error("Entity must be an operation to be flattened");return[r,...(r.successCalls||[]).flatMap(t=>U(t,a,e)),...(r.errorCalls||[]).flatMap(t=>U(t,a,e)),...(r.inputs||[]).flatMap(t=>U(t,a,e)),...(r.outputs||[]).flatMap(t=>U(t,a,e)),...r.error?U(r.error,a,e):[],...r.process?U(r.process,a,e):[],...(hi(r)||[]).flatMap(t=>U(t,a,e)),...r.parent?U(r.parent,a,e):[]]}function NP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.OutputMap)throw new Error("Entity must be an output map to be flattened");return[r,...(r.writesValues||[]).flatMap(t=>U(t,a,e)),...r.declaration?U(r.declaration,a,e):[],...r.defaultValue?U(r.defaultValue,a,e):[],...r.parent?U(r.parent,a,e):[]]}function LP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.PrimitiveEntity)throw new Error("Entity must be a primitive entity to be flattened");return[r,...(r.properties||[]).flatMap(t=>U(t,a,e)),...(r.methods||[]).flatMap(t=>U(t,a,e)),...(r.abstractMethods||[]).flatMap(t=>U(t,a,e))]}function UP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.Project)throw new Error("Entity must be a project to be flattened");return[r,...(r.entities||[]).flatMap(t=>U(t,a,e)),...(r.functions||[]).flatMap(t=>U(t,a,e)),...(r.events||[]).flatMap(t=>U(t,a,e)),...(r.projects||[]).flatMap(t=>U(t,a,e)),...(r.variableDeclarations||[]).flatMap(t=>U(t,a,e)),...(r.variableInstances||[]).flatMap(t=>U(t,a,e)),...(r.operations||[]).flatMap(t=>U(t,a,e)),...(r.conditions||[]).flatMap(t=>U(t,a,e)),...(r.functionCalls||[]).flatMap(t=>U(t,a,e)),...(r.projects||[]).flatMap(t=>U(t,a,e)),...(r.loops||[]).flatMap(t=>U(t,a,e)),...(r.searches||[]).flatMap(t=>U(t,a,e))]}function jP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.Property)throw new Error("Entity must be a property to be flattened");return[r,...r.defaultValue?U(r.defaultValue,a,e):[],...r.dataType?U(r.dataType,a,e):[],...r.parent?U(r.parent,a,e):[]]}function gP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.ReturnDeclaration)throw new Error("Entity must be a return declaration to be flattened");return[r,...r.readsValue?U(r.readsValue,a,e):[],...r.defaultValue?U(r.defaultValue,a,e):[],...r.dataType?U(r.dataType,a,e):[],...r.parent?U(r.parent,a,e):[]]}function $P(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.ReturnStatement)throw new Error("Entity must be a return statement to be flattened");return[r,...(r.outputs||[]).flatMap(t=>U(t,a,e)),...r.throws?U(r.throws,a,e):[],...(hi(r)||[]).flatMap(t=>U(t,a,e)),...r.parent?U(r.parent,a,e):[]]}function GP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.Search)throw new Error("Entity must be a search to be flattened");return[r,...(r.successCalls||[]).flatMap(t=>U(t,a,e)),...(r.errorCalls||[]).flatMap(t=>U(t,a,e)),...(r.inputsDeclarations||[]).flatMap(t=>U(t,a,e)),...(r.inputs||[]).flatMap(t=>U(t,a,e)),...(r.outputsDeclarations||[]).flatMap(t=>U(t,a,e)),...(r.outputs||[]).flatMap(t=>U(t,a,e)),...r.error?U(r.error,a,e):[],...(hi(r)||[]).flatMap(t=>U(t,a,e)),...r.parent?U(r.parent,a,e):[]]}function FP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.ValueDescriptor)throw new Error("Entity must be a value descriptor to be flattened");return[r,...r.defaultValue?U(r.defaultValue,a,e):[],...r.dataType?U(r.dataType,a,e):[],...r.parent?U(r.parent,a,e):[]]}function xP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.VariableDeclaration)throw new Error("Entity must be a variable declaration to be flattened");return[r,...(r.successCalls||[]).flatMap(t=>U(t,a,e)),...(r.errorCalls||[]).flatMap(t=>U(t,a,e)),...(r.inputs||[]).flatMap(t=>U(t,a,e)),...(r.outputs||[]).flatMap(t=>U(t,a,e)),...(r.internalCalls||[]).flatMap(t=>U(t,a,e)),...(r.writesValues||[]).flatMap(t=>U(t,a,e)),...r.readsValue?U(r.readsValue,a,e):[],...r.defaultValue?U(r.defaultValue,a,e):[],...(hi(r)||[]).flatMap(t=>U(t,a,e)),...r.dataType?U(r.dataType,a,e):[],...r.parent?U(r.parent,a,e):[]]}function kP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.VariableInstance)throw new Error("Entity must be a variable instance to be flattened");return[r,...(r.successCalls||[]).flatMap(t=>U(t,a,e)),...(r.errorCalls||[]).flatMap(t=>U(t,a,e)),...(r.inputs||[]).flatMap(t=>U(t,a,e)),...(r.outputs||[]).flatMap(t=>U(t,a,e)),...(r.internalCalls||[]).flatMap(t=>U(t,a,e)),...(r.writesValues||[]).flatMap(t=>U(t,a,e)),...r.readsValue?U(r.readsValue,a,e):[],...r.defaultValue?U(r.defaultValue,a,e):[],...(hi(r)||[]).flatMap(t=>U(t,a,e)),...r.declaration?U(r.declaration,a,e):[],...r.parent?U(r.parent,a,e):[]]}function _i(){const r=new Set,a=lE.flatMap(e=>U(e,r)).map(e=>e.id);if(!a.includes("http-request-error-return-delaration-id"))throw new Error("Built-in base entities must be included in the list");return a}function U(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(!r)throw new Error("Entity must be defined to be flattened");if(r.type===n.GenericReference)return[];if(e.ignoreBuiltInBaseEntities&&(Ti.includes(r.type)||_i().includes(r.id)))return[];if(a.has(r.id))return[];switch(r.type){case n.FunctionCall:return DP(r,a,e);case n.Operation:return MP(r,a,e);case n.Condition:return EP(r,a,e);case n.Loop:return _P(r,a,e);case n.Search:return GP(r,a,e);case n.GlobalEvent:return PP(r,a,e);case n.ReturnStatement:return $P(r,a,e);case n.ContinueStatement:return AP(r,a,e);case n.BreakStatement:return TP(r,a,e);case n.VariableDeclaration:return xP(r,a,e);case n.DefinitionEntity:return bP(r,a,e);case n.FunctionDeclaration:return OP(r,a,e);case n.Project:return UP(r,a,e);case n.ActionDescriptor:return mP(r,a,e);case n.ArgumentDeclaration:return vP(r,a,e);case n.ReturnDeclaration:return gP(r,a,e);case n.ValueDescriptor:return FP(r,a,e);case n.InputMap:return wP(r,a,e);case n.OutputMap:return NP(r,a,e);case n.DataType:return RP(r,a,e);case n.InstalledProject:return CP(r,a,e);case n.InternalCall:return VP(r,a,e);case n.LiteralValue:return BP(r,a,e);case n.Property:return jP(r,a,e);case n.VariableInstance:return kP(r,a,e);case n.BuiltInBaseEntity:return e.ignoreBuiltInBaseEntities?[]:IP(r,a,e);case n.PrimitiveEntity:return e.ignoreBuiltInBaseEntities?[]:LP(r,a,e)}return[]}function Hc(r){return r.type===n.FunctionCall||r.type===n.InternalCall||[n.Operation,n.Condition,n.Loop].includes(r.type)?r.declaration.inputs:r.type===n.FunctionDeclaration||Gn.includes(r.type)?r.inputs:r.type===n.Search?r.inputsDeclarations:[]}function OS(r,a){return a.type===n.Condition?a.inputs.find(e=>e.declaration.id===r.id):a.type===n.FunctionCall||a.type===n.Operation?a.inputs.find(e=>e.declaration.id===r.id):null}function ZP(r){return ot.includes(r.type)?r.inputs:[]}function qP(r){var a;return r.type===n.FunctionCall?((a=r.declaration.returnStatements[0])==null?void 0:a.outputs)||[]:[n.Operation,n.Condition,n.Loop].includes(r.type)?r.declaration.outputs:r.type===n.Search?r.outputsDeclarations:st.includes(r.type)?r.outputs:[]}function PS(r,a){return a.type===n.Condition?null:a.type===n.FunctionCall||a.type===n.Operation?a.outputs.find(e=>e.declaration.id===r.id):null}function wS(r){return r.type===n.Condition?[]:ot.includes(r.type)?r.outputs:[]}function Ql(r){const a=r.readsValue;return a?wt(a):null}function JP(r,a){const e=r.readsValue;return e?Hl(e,a):null}function SP(r){const a=r.internalCalls||[];return p(Xt(p(a.flatMap(e=>[...e.successCalls,...e.errorCalls]))))}function Os(r){const a=Yc(r),e=[];return a.forEach(t=>{if(tt.includes(t.type))e.push(t);else if(Er.includes(t.type)){const i=t.parent;e.push(i)}}),e}function p(r){const a=new Set;return r.filter(e=>!e||a.has(e.id)?!1:(a.add(e.id),!0))}function tn(r,a=!1){const e=[];if(r.type===n.Project&&e.push(...(r==null?void 0:r.entities)||[],...(r==null?void 0:r.functions)||[],...(r==null?void 0:r.variableDeclarations)||[],...(r==null?void 0:r.variableInstances)||[],...(r==null?void 0:r.searches)||[],...(r==null?void 0:r.loops)||[],...(r==null?void 0:r.operations)||[],...(r==null?void 0:r.conditions)||[],...(r==null?void 0:r.functionCalls)||[],...(r==null?void 0:r.events)||[],...(r==null?void 0:r.projects)||[]),dt.includes(r.type)&&e.push(...(r==null?void 0:r.detachedChildren)||[]),r.type===n.DefinitionEntity){const t=[...r.suggestedMethods,...r.methods].flatMap(i=>i.collapsed&&a?[]:tn(i));e.push(...t)}if(r.type===n.Condition){const t=r.successCalls.map(s=>wt(s)),i=r.errorCalls.map(s=>wt(s));e.push(...t,...i)}if(Gn.includes(r.type)){if(r.collapsed&&a)return[];const t=r.inputs.map(s=>Os(s)).flat(),i=r.calls.map(s=>wt(s));e.push(...p(t),...i)}if(ot.includes(r.type)&&r.type!==n.Condition&&r.type!==n.Loop){const t=r==null?void 0:r.outputs.map(l=>Os(l)).flat(),i=r.successCalls.map(l=>wt(l)),s=r.errorCalls.map(l=>wt(l));e.push(...p(t),...i,...s)}if(tt.includes(r.type)){const t=Os(r),i=SP(r);e.push(...t,...i)}if(r.type===n.Loop){const t=r.outputs.map(l=>Os(l)).flat();if(r.body){const l=tn(r.body,a);e.push(...l)}const i=r.errorCalls.map(l=>wt(l)),s=r.successCalls.map(l=>wt(l));e.push(...p(t),...s,...i)}if(r.type===n.FunctionDeclaration){if(r.collapsed&&a)return[];const t=r.inputs.map(s=>Os(s)).flat(),i=r.calls.map(s=>wt(s));e.push(...p(t),...i)}return p(e)}function WP(r,a=!1){const e=tn(r,a),t=[...e,...e.reduce((i,s)=>[...i,...WP(s,a)],[])];return p(t)}function zP(r){const a=Ln(r),e=[...a,...a.reduce((t,i)=>[...t,...zP(i)],[])];return p(e)}function Na(r){return r.implements.reduce((a,e)=>e.type===n.DefinitionEntity?[...a,n.DefinitionEntity,...Na(e),...La(e)]:[...a,e.name],[])}function La(r){return r.extends.reduce((a,e)=>e.type===n.DefinitionEntity?[...a,n.DefinitionEntity,...La(e),...Na(e)]:[...a,e.name],[])}function Kc(r){return r.extends.reduce((a,e)=>e.type===n.DefinitionEntity?[...a,e,...Kc(e),...Xc(e)]:[...a,e],[])}function Xc(r){return r.implements.reduce((a,e)=>e.type===n.DefinitionEntity?[...a,e,...Xc(e),...Kc(e)]:[...a,e],[])}function Qc(r){return[...La(r),...Na(r)].filter((e,t,i)=>i.indexOf(e)===t)}function YP(r){return r.implements.length===0&&r.extends.length===0?null:r.implements.find(t=>t.type===n.BuiltInBaseEntity&&t.name===z.PERSISTED_ENTITY)?r:[...r.implements,...r.extends].reduce((t,i)=>{if(i.type===n.DefinitionEntity){const s=YP(i);if(s)return s}return t},null)}function CS(r){const a=r.extends.find(e=>e.type===n.BuiltInBaseEntity);return a&&a.type===n.BuiltInBaseEntity?a:null}function VS(r){const a=r.implements.find(e=>e.type===n.BuiltInBaseEntity);return a&&a.type===n.BuiltInBaseEntity?a:null}function HP(r){const a=r.extends.find(e=>e.type===n.DefinitionEntity);return a&&a.type===n.DefinitionEntity?a:null}function kt(r){if(r.type===n.BuiltInBaseEntity)return[r];const a=[...r.implements,...r.extends].reduce((e,t)=>t.type===n.BuiltInBaseEntity?[...e,t]:t.type===n.DefinitionEntity?[...e,...kt(t)]:e,[]);return p(a)}function Ua(r){return r.type===n.PrimitiveEntity?!0:r.type===n.BuiltInBaseEntity?r.interactive:!kt(r).find(t=>!t.interactive)}function BS(r){return r.parent===r.project&&r.project.variableDeclarations.includes(r)}function ef(r){return r.parent!==r.project?!1:n.VariableDeclaration===r.type?r.project.variableDeclarations.includes(r):n.VariableInstance===r.type?r.project.variableInstances.includes(r):n.FunctionCall===r.type?r.project.functionCalls.includes(r):n.Condition===r.type?r.project.conditions.includes(r):n.Operation===r.type?r.project.operations.includes(r):n.Loop===r.type?r.project.loops.includes(r):n.Search===r.type?r.project.searches.includes(r):!1}function KP(r){if([...lt,n.DefinitionEntity,n.InstalledProject,n.Project].includes(r.type)||ef(r))return!1;const a=Ln(r);return a.length===0?!0:a.some(e=>KP(e))}function tf(r){return[...lt,n.DefinitionEntity,n.InstalledProject,n.Project].includes(r.type)||ef(r)?!1:Ln(r).length===0}function XP(r,a=0){if(tf(r)){const e=Ln(r);return e.length===0?r:e.map(i=>XP(i,a+1)).reduce((i,s)=>i?s&&s.x<i.x?s:i:s,null)}return null}function QP(r){const a=[];if(tf(r))a.push(r);else return[];return Ln(r).forEach(t=>{a.push(...QP(t))}),a}function ew(r){return r.type===n.FunctionDeclaration&&r.parent!==r.project&&!![n.DefinitionEntity,n.Loop,n.InstalledProject].includes(r.parent.type)}function _S(r,a){const e=new Map;return r.forEach(t=>{e.set(t.id,t)}),a.forEach(t=>{e.set(t.id,t)}),Array.from(e.values())}function ja(r){switch(r){case n.DefinitionEntity:return nn;case n.FunctionDeclaration:return gr;case n.VariableDeclaration:return Jr;case n.VariableInstance:return qr;case n.FunctionCall:return en;case n.Operation:return Gr;case n.Condition:return Zr;case n.ReturnStatement:return jr;case n.Loop:return kr;case n.Search:return Sr;case n.InputMap:return Wi;case n.OutputMap:return zi;case n.ArgumentDeclaration:return Yr;case n.ReturnDeclaration:return ai;case n.Property:return Ur;case n.InstalledProject:return Wr;case n.Project:return m;case n.DataType:return $r;case n.GlobalEvent:return Fr;case n.InternalCall:return zr;case n.ValueDescriptor:return mr;case n.BuiltInBaseEntity:return Ki;case n.PrimitiveEntity:return Qt;case n.ActionDescriptor:return Se;case n.LiteralValue:return Hr;case n.ContinueStatement:return Lt;case n.BreakStatement:return xr;default:return null}}function Zt(r,a){if(dt.includes(r.type))return r;if(Ti.includes(r.type))return null;const e=r.parent;if(!e)return null;if(e.type===n.GenericReference){const t=_(e);if(!t)return null;const i=a.get(t);return i?Zt(i,a):null}else return e===a?a:Zt(e,a)}function rf(r,a){if(Ti.includes(r.type)||a.getBuiltIn(r.id))return null;const e=mi(r.parent,a);return e?e===a?dt.includes(r.type)?r:null:e.type===n.DefinitionEntity?r:rf(e,a):null}function ed(r,a,e){if(r===a||a===e||r===e)return!1;const t=Zt(a.parent,e);return t===r?!0:ed(t,a,e)}var td=(r=>(r.SameBothLocal="same-both-local",r.AInB="a-in-b",r.BInA="b-in-a",r.ParallelInCommonParent="parallel-in-common-parent",r.ParallelInProject="parallel-in-project",r.AIsGlobalBIsNot="a-is-global-b-is-not",r.BIsGlobalAIsNot="b-is-global-a-is-not",r.SameBothGlobal="same-both-global",r))(td||{});function ga(r,a,e){const t=Zt(r,e),i=Zt(a,e);if(!t)throw new Error("Could not find scope owner for the entity: "+r.id);if(!i)throw new Error("Could not find scope owner for the entity: "+a.id);if(t===i&&t.type!==n.Project)return{compatible:!0,type:"same-both-local",commonAncestorScope:t};if(t===i&&t.type===n.Project)return{compatible:!0,type:"same-both-global",commonAncestorScope:t};if(t.type===n.Project&&i.type!==n.Project)return{compatible:!1,type:"a-is-global-b-is-not",commonAncestorScope:t};if(t.type!==n.Project&&i.type===n.Project)return{compatible:!1,type:"b-is-global-a-is-not",commonAncestorScope:i};if(ed(t,i,e))return{compatible:!0,type:"b-in-a",commonAncestorScope:t};if(ed(i,t,e))return{compatible:!0,type:"a-in-b",commonAncestorScope:i};const o=Wc(t,i);return o===e?{compatible:!1,type:"parallel-in-project",commonAncestorScope:o}:o?{compatible:!1,type:"parallel-in-common-parent",commonAncestorScope:Zt(o,e)}:{compatible:!1,type:"parallel-in-project",commonAncestorScope:e}}function tw(r,a,e){const t=ga(r,a,e);if(!t.compatible||t.type!=="same-both-local")return null;if(r===a)return r;let i=Zt(r.parent,e);if(i){if(i===a)return a;if(i.type===n.Project)return r}else return r;for(;i;){if(i){if(i===a)return a;if(i.type===n.Project)return r}else return r;i=Zt(i.parent,e)}let s=Zt(a.parent,e);if(s){if(s===r)return r;if(s.type===n.Project)return a}else return a;for(;s;){if(s){if(s===r)return r;if(s.type===n.Project)return a}else return a;s=Zt(s.parent,e)}return null}function iw(r){return r.length===0?null:r.length===1?r[0]:r.reduce((e,t)=>{const i=tw(e,t,t.project);return!i||i===t?e:t},r[0])}function mi(r,a){if(!r)return null;let e;return typeof r=="string"?e=r:r.type===n.GenericReference?e=_(r):e=r.id,e===a.id?a:a.get(e)}function rn(r){if(!r)return null;if(Ti.includes(r.type))return r;if(r.type===n.Project)return null;if(r.project.getBuiltIn(r.id))return r;const a=r.parent;return!a||a.type===n.Project?null:rn(a)}function $a(r){const a=[];function e(s,l){return a.some(o=>o.blockedByCaller===s&&o.blockedByCalling===l)}function t(s,l){e(s,l)||a.push({blockedByCaller:s,blockedByCalling:l})}const i=rf(r,r.project);return r.calledBySuccess.forEach(s=>{[...s.successCalls||[]].forEach(d=>{st.includes(d.type)&&d!==r&&(Je(r).find(c=>c===d)||t(s,d))});let o;if(ot.includes(s.type)&&(o=s),o){const d=$a(o);d.reachable||Je(r).find(c=>c===s)||d.blocks.forEach(c=>{t(s,c.blockedByCalling)})}}),r.calledByError.forEach(s=>{[...s.errorCalls||[]].forEach(d=>{st.includes(d.type)&&d!==r&&(Je(r).find(c=>c===d)||t(s,d))});let o;if(ot.includes(s.type)&&(o=s),o){const d=$a(o);d.reachable||Je(r).find(c=>c===s)||d.blocks.forEach(c=>{t(s,c.blockedByCalling)})}}),r.calledByEntry.forEach(s=>{if([...s.calls||[]].forEach(d=>{st.includes(d.type)&&d!==r&&(Je(r).find(c=>c===d)||t(s,d))}),s===i)return;let o;if(s.type===n.FunctionDeclaration){const d=wt(s);if(d.type===n.DefinitionEntity)return;d.type===n.Loop&&(o=d)}if(o){const d=$a(o);d.reachable||d.blocks.forEach(u=>{t(s,u.blockedByCalling)})}}),{reachable:a.length===0,entryPoint:i,blocks:a}}function MS(r){return Sa.includes(r.type)?r.type===n.FunctionDeclaration?!ew(r):!0:!1}function NS(r){if(n.ActionDescriptor===r.type){if(r.project.operationDeclarations.find(s=>s.id===r.id))return n.Operation;if(r.project.globalEventActionDescriptors.find(s=>s.id===r.id))return n.GlobalEvent;if(r.project.loopDeclarations.find(s=>s.id===r.id))return n.Loop;if(r.project.conditionDeclarations.find(s=>s.id===r.id))return n.Condition}return r.type}function id(r,a){return r.type===n.BuiltInBaseEntity?r.name===a:!!La(r).includes(a)}function LS(r,a){return r.type===n.BuiltInBaseEntity?r.name===a:!!Na(r).includes(a)}function Ga(r,a){return r.type===n.BuiltInBaseEntity?r.name===a:!!Qc(r).includes(a)}function US(r){const a=[];return r.entities.forEach(e=>{if(id(e,z.PERSISTED_ENTITY)){a.push(e);return}}),p(a)}function jS(r){const a=[];return r.entities.forEach(e=>{if(id(e,z.RELATIONAL_DATABASE)){a.push(e);return}}),p(a)}function gS(r){return r.type!==n.DefinitionEntity||r.abstract||!id(r,z.PERSISTED_ENTITY)?null:(r==null?void 0:r.properties.find(e=>{var t;return((t=e.implements)==null?void 0:t.id)===k[n.BuiltInBaseEntity][z.PERSISTED_ENTITY].properties.primaryKey.id&&!e.abstract}))||null}function $S(r){if(r.type!==n.DefinitionEntity)return[];if(r.abstract)return[];if(!Ga(r,z.PERSISTED_ENTITY))return r.id==="a2d0ec83-72ce-4f54-b059-a39e018fa86c"&&console.log("Entity does not have persisted base entity",r),[];const a=[],e=r.properties.filter(t=>{var i;return((i=t.implements)==null?void 0:i.id)!==k[n.BuiltInBaseEntity][z.PERSISTED_ENTITY].properties.database.id&&!t.abstract});return a.push(...e),a}function GS(r){var e;if(!r||r.type!==n.DefinitionEntity||!Ga(r,z.PERSISTED_ENTITY))return null;const a=r.properties.find(t=>{var i;return((i=t.implements)==null?void 0:i.id)===k[n.BuiltInBaseEntity][z.PERSISTED_ENTITY].properties.database.id});return(e=a==null?void 0:a.getDefaultValue())==null?void 0:e.valueAsTypeSingle}function mt(r,a){var t;if(!uf.includes(a.type)||!r)return a.project||null;let e=a.project;return r.type===n.Project?e=r:((t=a.project)==null?void 0:t.id)!==r.project.id&&(e=r.project),e}function FS(r){switch(r){case n.Project:return m;case n.InstalledProject:return Wr;case n.DefinitionEntity:return nn;case n.FunctionDeclaration:return gr;case n.GlobalEvent:return Fr;case n.VariableInstance:return qr;case n.VariableDeclaration:return Jr;case n.InputMap:return Wi;case n.OutputMap:return zi;case n.Condition:return Zr;case n.Operation:return Gr;case n.FunctionCall:return en;case n.ReturnDeclaration:return ai;case n.ArgumentDeclaration:return Yr;case n.PrimitiveEntity:return Qt;case n.DataType:return $r;case n.Property:return Ur;case n.ActionDescriptor:return Se;case n.ReturnStatement:return jr;case n.ContinueStatement:return Lt;case n.BreakStatement:return xr;case n.Loop:return kr;case n.Search:return Sr;case n.ValueDescriptor:return mr;case n.InternalCall:return zr;case n.LiteralValue:return Hr}return null}function xS(r){const a={added:{},updated:{},removed:{},affected:[],seenEntities:[],self:r==null?void 0:r.self};return r==null||r.added.forEach(e=>{a.added[e.id]=e}),r==null||r.updated.forEach(e=>{a.updated[e.id]=e}),r==null||r.removed.forEach(e=>{a.removed[e.id]=e}),a.affected=Array.from(new Set(r==null?void 0:r.affected.map(e=>e.id))),a}function pt(r,a){const e=ja(r.type);return e?!e.MUTABLE_META_PROPERTIES.every(i=>{const s=r[i],l=a[i];return l===void 0||s===l?!0:Array.isArray(s)&&Array.isArray(l)?s.length!==l.length?!1:s.every((o,d)=>o===l[d]):!1}):!1}function rd(r,a={}){if(r.type===n.Project)return[];if(!r.parent)return[];const e=_(r.parent);if(!e)return[];const t=a[e];return t?[t.id,...rd(t,a)]:[]}function kS(r){const a=[],e=new Set;return[...r.listAdded,...r.listUpdated,...r.listAffected].forEach(t=>{const i=wt(t);!i||e.has(i.id)||(e.add(i.id),a.push(i))}),p(a)}function rw(r){const a=Tq(),e=r.toJSON();a.safeParse(e).success;const i=r.implements.flatMap(y=>ZS(r,y)),s=r.extends.flatMap(y=>qS(r,y)),l=SS(r),o=JS(r);r.methods.flatMap(y=>y.validate());const d=[...i,...s,...l,...o];return He(r.errors,d)}function nw(r,a){const e=a.properties.filter(s=>s.abstract),t=[];let i=[...r.properties];return e.forEach(s=>{const l=i.find(o=>{var d;return((d=o.implements)==null?void 0:d.id)===s.id});l?i=i.filter(o=>o.id!==l.id):t.push(s)}),t}function sw(r,a){const e=a.abstractMethods,t=[];let i=[...r.methods];return e.forEach(s=>{const l=i.find(o=>{var d;return((d=o.implements)==null?void 0:d.id)===s.id});l?i=i.filter(o=>o.id!==l.id):t.push(s)}),t}function ZS(r,a){const e=[];if(!a.abstract){const y=de({id:r.id+"--"+F.ImplementingNonAbstractEntity,message:`Entity "${r.name}" with id "${r.id}" is implementing a non-abstract entity "${a.name}" with id "${a.id}"`,issue:null,severity:D.Error,code:F.ImplementingNonAbstractEntity,entity:r});return e.push(y.error),e}const t=a.properties.filter(y=>y.abstract),i=[];let s=[...r.properties];t.forEach(y=>{const c=s.find(I=>{var E;return((E=I.implements)==null?void 0:E.id)===y.id});c?s=s.filter(I=>I.id!==c.id):i.push(y)}),i.length&&i.forEach(y=>{const c=de({id:r.id+"--"+F.MissingPropertyImplementation+"--"+y.id,message:`Property "${y.name}" with id "${y.id}" of entity "${a.name}" with id "${a.id}" is not implemented when entity "${r.name}" with id "${r.id}" implements it`,issue:null,severity:D.Error,code:F.MissingPropertyImplementation,entity:r});e.push(c.error)});const l=[];let o=[...r.methods];a.abstractMethods.forEach(y=>{const c=o.find(I=>{var E;return((E=I.implements)==null?void 0:E.id)===y.id});c?o=o.filter(I=>I.id!==c.id):l.push(y)}),l.length&&l.forEach(y=>{const c=de({id:r.id+"--"+F.MissingMethodImplementation+"--"+y.id,message:`Method "${y.name}" with id "${y.id}" of entity "${a.name}" with id "${a.id}" is not implemented when entity "${r.name}" with id "${r.id}" implements it`,issue:null,severity:D.Error,code:F.MissingMethodImplementation,entity:r});e.push(c.error)});const d=[];a.properties.forEach(y=>{const c=s.find(I=>I.name===y.name);c&&d.push([c,y])}),d.length&&d.forEach(([y])=>{const c=de({id:r.id+"--"+$.PropertyOverwritesOtherSiblingWithSameName+"--"+y.id,message:`Property "${y.name}" with id "${y.id}" of entity "${r.name}" with id "${r.id}" overwrites the property with the same name from the base entity "${a.name}" with id "${a.id}"`,issue:null,severity:D.Error,code:$.PropertyOverwritesOtherSiblingWithSameName,entity:r});e.push(c.error)});const u=[];return a.methods.forEach(y=>{const c=o.find(I=>I.name===y.name);c&&u.push([c,y])}),u.length&&u.forEach(([y])=>{const c=de({id:r.id+"--"+$.MethodOverwritesOtherSiblingWithSameName+"--"+y.id,message:`Method "${y.name}" with id "${y.id}" of entity "${r.name}" with id "${r.id}" overwrites the method with the same name from the base entity "${a.name}" with id "${a.id}"`,issue:null,severity:D.Error,code:$.MethodOverwritesOtherSiblingWithSameName,entity:r});e.push(c.error)}),e}function qS(r,a){const e=[],t=[];if(!r.abstract&&a.abstract){const s=de({id:r.id+"--"+a.id+"--"+F.NonAbstractExtendingAbstractEntity,message:`Entity "${r.name}" with id "${r.id}" is not-abstract but is extending an abstract entity "${a.name}" with id "${a.id}"`,issue:null,severity:D.Error,code:F.NonAbstractExtendingAbstractEntity,entity:r,firstRelationship:a});return e.push(s.error),e}if(r.abstract&&!a.abstract){const s=de({id:r.id+"--"+a.id+"--"+F.AbstractExtendingNonAbstractEntity,message:`Entity "${r.name}" with id "${r.id}" is abstract but is extending an non-abstract entity "${a.name}" with id "${a.id}"`,issue:null,severity:D.Error,code:F.AbstractExtendingNonAbstractEntity,entity:r,firstRelationship:a});return e.push(s.error),e}r.properties.forEach(s=>{var o;const l=a.properties.find(d=>d.name===s.name);((o=s.implements)==null?void 0:o.id)!==(l==null?void 0:l.id)&&l&&t.push(s)}),t.length&&t.forEach(s=>{const l=de({id:r.id+"--"+$.PropertyOverwritesOtherSiblingWithSameName,message:`Property "${s.name}" with id "${s.id}" of entity "${r.name}" with id "${r.id}" overwrites the property with the same name from the extended entity "${a.name}" with id "${a.id}"`,issue:null,severity:D.Error,code:$.PropertyOverwritesOtherSiblingWithSameName,entity:r});e.push(l.error)});const i=[];return r.methods.forEach(s=>{var o;const l=a.methods.find(d=>d.name===s.name);((o=s.implements)==null?void 0:o.id)!==(l==null?void 0:l.id)&&l&&i.push(s)}),i.length&&i.forEach(s=>{const l=de({id:r.id+"--"+$.MethodOverwritesOtherSiblingWithSameName,message:`Method "${s.name}" with id "${s.id}" of entity "${r.name}" with id "${r.id}" overwrites the method with the same name from the extended entity "${a.name}" with id "${a.id}"`,issue:null,severity:D.Error,code:$.MethodOverwritesOtherSiblingWithSameName,entity:r});e.push(l.error)}),e}function JS(r){const a=[];if(!r.properties.length){const e=de({id:r.id+"--"+F.NoProperties,message:"No properties implemented",issue:null,severity:D.Warning,code:F.NoProperties,entity:r});a.push(e.error)}return r.properties.forEach(e=>{e.validate()}),a}function SS(r){const a=[];if(r.abstract){if(r.methods.length){const e=de({id:r.id+"--"+F.AbstractEntityWithNonAbstractMethods,message:`Entity "${r.name}" with id "${r.id}" is marked as abstract but has non-abstract methods`,issue:null,severity:D.Error,code:F.AbstractEntityWithNonAbstractMethods,entity:r});a.push(e.error)}if(r.properties.some(e=>!e.abstract)){const e=de({id:r.id+"--"+F.AbstractEntityWithNonAbstractProperties,message:`Entity "${r.name}" with id "${r.id}" is marked as abstract but has non-abstract properties`,issue:null,severity:D.Error,code:F.AbstractEntityWithNonAbstractProperties,entity:r});a.push(e.error),r.properties.forEach(t=>{if(!t.abstract){const i=de({id:r.id+"--"+F.StaticEntityWithNonStaticProperties+"--"+t.id,message:`Property "${t.name}" with id "${t.id}" of entity "${r.name}" with id "${r.id}" is not marked as abstract but the entity is marked as abstract`,issue:null,severity:D.Error,code:F.StaticEntityWithNonStaticProperties,entity:r});a.push(i.error)}})}}else{if(r.abstractMethods.length){const e=de({id:r.id+"--"+F.AbstractPropertyInNonAbstractEntity,message:`Entity "${r.name}" with id "${r.id}" is not marked as abstract but has abstract methods`,issue:null,severity:D.Error,code:F.AbstractPropertyInNonAbstractEntity,entity:r});a.push(e.error)}if(r.properties.some(e=>e.abstract)){const e=de({id:r.id+"--"+F.AbstractMethodInNonAbstractEntity,message:`Entity "${r.name}" with id "${r.id}" is not marked as abstract but has abstract properties`,issue:null,severity:D.Error,code:F.AbstractMethodInNonAbstractEntity,entity:r});a.push(e.error),r.properties.forEach(t=>{if(t.abstract){const i=de({id:r.id+"--"+F.AbstractMethodInNonAbstractEntity+"--"+t.id,message:`Property "${t.name}" with id "${t.id}" of entity "${r.name}" with id "${r.id}" is marked as abstract but the entity is not marked as abstract`,issue:null,severity:D.Error,code:F.AbstractMethodInNonAbstractEntity,entity:r});a.push(i.error)}})}}if(r.static&&r.properties.some(e=>!e.static)){const e=de({id:r.id+"--"+F.StaticEntityWithNonStaticProperties,message:`Entity "${r.name}" with id "${r.id}" is marked as static but has non-static properties`,issue:null,severity:D.Error,code:F.StaticEntityWithNonStaticProperties,entity:r});a.push(e.error),r.properties.forEach(t=>{if(!t.static){const i=de({id:r.id+"--"+F.NonStaticPropertyInStaticEntity+"--"+t.id,message:`Property "${t.name}" with id "${t.id}" of entity "${r.name}" with id "${r.id}" is not marked as static but the entity is marked as static`,issue:null,severity:D.Error,code:F.NonStaticPropertyInStaticEntity,entity:r});a.push(i.error)}})}return a}function WS(r,a){const e=[],t=kt(a);if(!a.abstract){const l=new it({id:r.id+"--"+a.id+"--"+F.ImplementingNonAbstractEntity,message:`Entity "${r.name}" with id "${r.id}" is implementing a non-abstract built-in entity "${a.name}" with id "${a.id}"`,issue:null,severity:D.Error,code:F.ImplementingNonAbstractEntity,entity:r,firstRelationship:a});e.push(l)}const i=r.implements.filter(l=>l.id!==a.id);if(r.abstract){const l=new it({id:r.id+"--"+a.id+"--"+F.AbstractEntityImplements,message:`Entity "${r.name}" with id "${r.id}" is marked as abstract and cannot implement built-in entity "${a.name}" with id "${a.id}"`,issue:null,severity:D.Error,code:F.AbstractEntityImplements,entity:r,firstRelationship:a});e.push(l)}if(r.static&&!a.static){const l=new it({id:r.id+"--"+a.id+"--"+F.StaticImplementingNonStaticEntity,message:`Entity "${r.name}" with id "${r.id}" is marked as static and cannot implement non-static built-in entity "${a.name}" with id "${a.id}"`,issue:null,severity:D.Error,code:F.StaticImplementingNonStaticEntity,entity:r,firstRelationship:a});e.push(l)}if(!r.static&&a.static){const l=new it({id:r.id+"--"+a.id+"--"+F.NonStaticImplementingStaticEntity,message:`Entity "${r.name}" with id "${r.id}" is not marked as static and cannot implement static built-in entity "${a.name}" with id "${a.id}"`,issue:null,severity:D.Error,code:F.NonStaticImplementingStaticEntity,entity:r,firstRelationship:a});e.push(l)}return i.length&&i.forEach(l=>{if(l.type===n.BuiltInBaseEntity){const o=t.filter(d=>d.id!==l.id);o.length&&o.forEach(d=>{if(d.id!==l.id){const u=new it({id:r.id+"--"+d.id+"--"+l.id+"--"+F.ImplementsIncompatibleEntities,message:`Entity "${r.name}" with id "${r.id}" is implementing built-in entity "${d.name}" with id "${d.id}" but also implements entity "${l.name}" with id "${l.id}" which is incompatible`,issue:null,severity:D.Error,code:F.ImplementsIncompatibleEntities,entity:r,firstRelationship:d,secondRelationship:l});e.push(u)}})}else{kt(l).forEach(y=>{const c=t.filter(I=>I.id!==y.id);c.length&&c.forEach(I=>{if(I.id!==y.id){const E=new it({id:r.id+"--"+I.id+"--"+y.id+"--"+F.ImplementsIncompatibleEntities,message:`Entity "${r.name}" with id "${r.id}" is implementing built-in entity "${I.name}" with id "${I.id}" but also implements entity "${y.name}" with id "${y.id}" which is incompatible`,issue:null,severity:D.Error,code:F.ImplementsIncompatibleEntities,entity:r,firstRelationship:I,secondRelationship:y});e.push(E)}})});const d=Tr(a.ownDeclaredProperties,l.ownDeclaredProperties,$.PropertyOverwritesOtherImplementedEntitysPropertyWithSameImplementation,$.PropertyOverwritesOtherImplementedEntitysPropertyWithSameName);e.push(...d.errors);const u=Tr(a.abstractMethods,[...l.abstractMethods,...l.methods],$.MethodOverwritesOtherImplementedEntitysMethodWithSameImplementation,$.MethodOverwritesOtherImplementedEntitysMethodWithSameName);e.push(...u.errors)}}),p(r.extends.flatMap(l=>kt(l))).forEach(l=>{if(!t.find(o=>o.id===l.id)){const o=new it({id:r.id+"--"+a.id+"--"+l.id+"--"+F.ExtendsIncompatibleEntities,message:`Entity "${r.name}" with id "${r.id}" is implementing built-in entity "${a.name}" with id "${a.id}" but also extends entity "${l.name}" with id "${l.id}" which is incompatible`,issue:null,severity:D.Error,code:F.ExtendsIncompatibleEntities,entity:r,firstRelationship:a,secondRelationship:l});e.push(o)}}),e}function zS(r,a,e=!1){const t=[],i=kt(a);if(!r.abstract&&a.abstract){const y=de({id:r.id+"--"+a.id+"--"+F.NonAbstractExtendingAbstractEntity,message:`Entity "${r.name}" with id "${r.id}" is not-abstract but is extending an abstract entity "${a.name}" with id "${a.id}"`,issue:null,severity:D.Error,code:F.NonAbstractExtendingAbstractEntity,entity:r,firstRelationship:a});t.push(y.error)}if(r.abstract&&!a.abstract){const y=de({id:r.id+"--"+a.id+"--"+F.AbstractExtendingNonAbstractEntity,message:`Entity "${r.name}" with id "${r.id}" is abstract but is extending an non-abstract entity "${a.name}" with id "${a.id}"`,issue:null,severity:D.Error,code:F.AbstractExtendingNonAbstractEntity,entity:r,firstRelationship:a});t.push(y.error)}if(!r.static&&a.static){const y=de({id:r.id+"--"+a.id+"--"+F.NonStaticExtendingStaticEntity,message:`Entity "${r.name}" with id "${r.id}" is not static but is extending a static entity "${a.name}" with id "${a.id}"`,issue:null,severity:D.Error,code:F.NonStaticExtendingStaticEntity,entity:r,firstRelationship:a});t.push(y.error)}if(r.static&&!a.static){const y=de({id:r.id+"--"+a.id+"--"+F.StaticExtendingNonStaticEntity,message:`Entity "${r.name}" with id "${r.id}" is static but is extending an non-static entity "${a.name}" with id "${a.id}"`,issue:null,severity:D.Error,code:F.StaticExtendingNonStaticEntity,entity:r,firstRelationship:a});t.push(y.error)}if(!Ua(a)){const y=de({id:r.id+"--"+a.id+"--"+F.ExtendingNonInteractiveEntity,message:`Entity "${r.name}" with id "${r.id}" is extending an non-interactive entity "${a.name}" with id "${a.id}"`,issue:null,severity:D.Error,code:F.ExtendingNonInteractiveEntity,entity:r,firstRelationship:a});t.push(y.error)}const l=r.extends.filter(y=>y.id!==a.id);l.length&&l.forEach(y=>{if(y.type===n.BuiltInBaseEntity){const c=i.filter(I=>I.id!==y.id);c.length&&c.forEach(I=>{if(I.id!==y.id){const E=de({id:r.id+"--"+I.id+"--"+y.id+"--"+F.ExtendsIncompatibleEntities,message:`Entity "${r.name}" with id "${r.id}" is extending built-in entity "${I.name}" with id "${I.id}" but also extends entity "${y.name}" with id "${y.id}" which is incompatible`,issue:null,severity:D.Error,code:F.ExtendsIncompatibleEntities,entity:r,firstRelationship:I,secondRelationship:y});t.push(E.error)}})}else{kt(y).forEach(M=>{const G=i.filter(B=>B.id!==M.id);G.length&&G.forEach(B=>{if(B.id!==M.id){const g=new it({id:r.id+"--"+B.id+"--"+M.id+"--"+F.ImplementsIncompatibleEntities,message:`Entity "${r.name}" with id "${r.id}" is extending built-in entity "${B.name}" with id "${B.id}" but also extends or implements entity "${M.name}" with id "${M.id}" which is incompatible`,issue:null,severity:D.Error,code:F.ImplementsIncompatibleEntities,entity:r,firstRelationship:B,secondRelationship:M});t.push(g)}})});const I=!!kt(y).find(M=>M.id===a.id);let E=[...y.properties];I&&(E=E.filter(M=>!a.properties.find(G=>{var B;return G.id===M.id||G.name===M.name||G.id===((B=M.implements)==null?void 0:B.id)})));let O=[...y.methods];I&&(O=O.filter(M=>!a.methods.find(G=>{var B;return G.id===M.id||G.name===M.name||G.id===((B=M.implements)==null?void 0:B.id)})));const P=Tr(a.ownDeclaredProperties,E,$.PropertyOverwritesOtherExtendedEntitysPropertyWithSameImplementation,$.PropertyOverwritesOtherExtendedEntitysPropertyWithSameName);t.push(...P.errors);const C=Tr(a.abstractMethods,O,$.MethodOverwritesOtherExtendedEntitysMethodWithSameImplementation,$.MethodOverwritesOtherExtendedEntitysMethodWithSameName);t.push(...C.errors)}}),e&&console.log("self.implements.length",r.implements.length),r.implements.length&&r.implements.forEach(y=>{if(y.type===n.BuiltInBaseEntity){const c=i.filter(I=>I.id!==y.id);c.length&&c.forEach(I=>{if(I.id!==y.id){const E=new it({id:r.id+"--"+I.id+"--"+y.id+"--"+F.ImplementsIncompatibleEntities,message:`Entity "${r.name}" with id "${r.id}" is implementing built-in entity "${I.name}" with id "${I.id}" but also implements entity "${y.name}" with id "${y.id}" which is incompatible`,issue:null,severity:D.Error,code:F.ImplementsIncompatibleEntities,entity:r,firstRelationship:I,secondRelationship:y});t.push(E)}})}else{kt(y).forEach(O=>{const P=i.filter(C=>C.id!==O.id);P.length&&P.forEach(C=>{if(C.id!==O.id){const M=new it({id:r.id+"--"+C.id+"--"+O.id+"--"+F.ImplementsIncompatibleEntities,message:`Entity "${r.name}" with id "${r.id}" is implementing built-in entity "${C.name}" with id "${C.id}" but also implements entity "${O.name}" with id "${O.id}" which is incompatible`,issue:null,severity:D.Error,code:F.ImplementsIncompatibleEntities,entity:r,firstRelationship:C,secondRelationship:O});t.push(M)}})});const I=Tr(a.ownDeclaredProperties,y.ownDeclaredProperties,$.PropertyOverwritesOtherImplementedEntitysPropertyWithSameImplementation,$.PropertyOverwritesOtherImplementedEntitysPropertyWithSameName);t.push(...I.errors);const E=Tr(a.abstractMethods,[...y.abstractMethods,...y.methods],$.MethodOverwritesOtherImplementedEntitysMethodWithSameImplementation,$.MethodOverwritesOtherImplementedEntitysMethodWithSameName);t.push(...E.errors)}});const o=Tr(r.ownDeclaredProperties,a.ownDeclaredProperties,$.PropertyOverwritesOtherSiblingWithSameImplementation,$.PropertyOverwritesOtherSiblingWithSameName);t.push(...o.errors);const d=Tr(a.methods,a.abstractMethods,$.MethodOverwritesOtherSiblingWithSameImplementation,$.MethodOverwritesOtherSiblingWithSameName);return t.push(...d.errors),p(r.extends.flatMap(y=>kt(y))).forEach(y=>{if(!i.find(c=>c.id===y.id)){const c=new it({id:r.id+"--"+a.id+"--"+y.id+"--"+F.ImplementsIncompatibleEntities,message:`Entity "${r.name}" with id "${r.id}" is extending built-in entity "${a.name}" with id "${a.id}" but also extends entity "${y.name}" with id "${y.id}" which is incompatible`,issue:null,severity:D.Error,code:F.ImplementsIncompatibleEntities,entity:r,firstRelationship:a,secondRelationship:y});t.push(c)}}),t}function YS(r){const a=[];return r.implements.forEach(e=>{if(!e.static){const t=new it({id:r.id+"--"+e.id+"--"+F.StaticImplementingNonStaticEntity,message:`Entity "${r.name}" with id "${r.id}" is static but implements entity "${e.name}" with id "${e.id}" which is non-static`,issue:null,severity:D.Error,code:F.StaticImplementingNonStaticEntity,entity:r,firstRelationship:e});a.push(t)}}),r.extends.forEach(e=>{if(!e.static){const t=new it({id:r.id+"--"+e.id+"--"+F.StaticExtendingNonStaticEntity,message:`Entity "${r.name}" with id "${r.id}" is static but extends entity "${e.name}" with id "${e.id}" which is non-static`,issue:null,severity:D.Error,code:F.StaticExtendingNonStaticEntity,entity:r,firstRelationship:e});a.push(t)}}),a}function HS(r){const a=[];if(r.implements.length){const e=new it({id:r.id+"--"+F.AbstractEntityImplements,message:`Entity "${r.name}" with id "${r.id}" cannot be marked as abstract because it implements other entities`,issue:null,severity:D.Error,code:F.AbstractEntityImplements,entity:r});a.push(e)}return r.extends.forEach(e=>{if(!e.abstract){const t=new it({id:r.id+"--"+e.id+"--"+F.AbstractExtendingNonAbstractEntity,message:`Entity "${r.name}" with id "${r.id}" is abstract but extends entity "${e.name}" with id "${e.id}" which is non-abstract`,issue:null,severity:D.Error,code:F.AbstractExtendingNonAbstractEntity,entity:r,firstRelationship:e});a.push(t)}}),a}function KS(r){const a=[];return r.extends.forEach(e=>{if(e.static){const t=new it({id:r.id+"--"+e.id+"--"+F.NonStaticExtendingStaticEntity,message:`Entity "${r.name}" with id "${r.id}" is non-static but extends entity "${e.name}" with id "${e.id}" which is static`,issue:null,severity:D.Error,code:F.NonStaticExtendingStaticEntity,entity:r,firstRelationship:e});a.push(t)}}),a}function XS(r){const a=[];return r.extends.forEach(e=>{if(e.abstract){const t=new it({id:r.id+"--"+e.id+"--"+F.NonAbstractExtendingAbstractEntity,message:`Entity "${r.name}" with id "${r.id}" is non-abstract but extends entity "${e.name}" with id "${e.id}" which is abstract`,issue:null,severity:D.Error,code:F.NonAbstractExtendingAbstractEntity,entity:r,firstRelationship:e});a.push(t)}}),a}const QS=Object.freeze(Object.defineProperty({__proto__:null,getBaseMethodsNotImplemented:sw,getBasePropertiesNotImplemented:nw,validate:rw,validateCanBecomeAbstract:HS,validateCanBecomeNonAbstract:XS,validateCanBecomeNonStatic:KS,validateCanBecomeStatic:YS,validateCanExtendEntity:zS,validateCanImplementEntity:WS},Symbol.toStringTag,{value:"Module"}));function eW(r,a){const e=[];if(r.parent)if(r.id===r.parent)e.push(new w({id:`${r.id}--${r.parent}--${R.SelfReference}`,code:R.SelfReference,severity:D.Error,message:`Entity of type "${r.type}" with id "${r.id}", has a reference to itself at 'parent'. This is not allowed. Change the reference string or the 'entityId' property of the reference object.`,issue:null}));else{const t=a.get(r.parent);t?[n.Project,n.DataType].includes(t.type)||e.push(new w({id:`${r.id}--${r.parent}--${R.InvalidParentReference}`,code:R.InvalidParentReference,severity:D.Error,message:`Entity of type "${r.type}" with id "${r.id}", has a parent reference that isn't pointing to an entity of type 'project' or 'data-type'.`,issue:null})):e.push(new w({id:`${r.id}--${r.parent}--${R.ReferencedEntityNotFound}`,code:R.ReferencedEntityNotFound,severity:D.Error,message:`Entity of type "${r.type}" with id "${r.id}", is referencing an entity with id "${r.parent}" that isn't yet found in the project. Perhaps it should be created first. Or perhaps the ID is incorrect.`,issue:null}))}return r.implements&&Array.isArray(r.implements)?r.implements.forEach(t=>{if(r.id===t){e.push(new w({id:`${r.id}--${t}--${R.SelfReference}`,code:R.SelfReference,severity:D.Error,message:`Entity of type "${r.type}" with id "${r.id}", has a reference to itself at one of the 'implements' references. This is not allowed. Change the reference string or the 'entityId' property of the reference object.`,issue:null}));return}const i=a.get(t);i?[n.DefinitionEntity,n.BuiltInBaseEntity].includes(i.type)?i.abstract||e.push(new w({id:`${r.id}--${t}--${R.InvalidImplementsReference}`,code:R.InvalidImplementsReference,severity:D.Error,message:`Entity of type "${r.type}" with id "${r.id}", has an 'implements' reference that isn't pointing to an abstract entity.`,issue:null})):e.push(new w({id:`${r.id}--${t}--${R.InvalidImplementsReference}`,code:R.InvalidImplementsReference,severity:D.Error,message:`Entity of type "${r.type}" with id "${r.id}", has an 'implements' reference that isn't pointing to an entity of type 'definition-entity' or 'built-in-base-entity'.`,issue:null})):e.push(new w({id:`${r.id}--${t}--${R.ReferencedEntityNotFound}`,code:R.ReferencedEntityNotFound,severity:D.Error,message:`Entity of type "${r.type}" with id "${r.id}", is referencing an entity with id "${t}" that isn't yet found in the project. Perhaps it should be created first. Or perhaps the ID is incorrect.`,issue:null}))}):e.push(new w({id:`${r.id}--${$.InvalidObjectStructure}`,code:$.InvalidObjectStructure,severity:D.Error,message:`Entity of type "${r.type}" with id "${r.id}", has an 'implements' property that isn't an array.`,issue:null})),r.extends&&Array.isArray(r.extends)&&r.extends.forEach(t=>{const i=a.get(t);i?[n.DefinitionEntity,n.BuiltInBaseEntity].includes(i.type)?i.abstract&&e.push(new w({id:`${r.id}--${t}--${R.InvalidExtendsReference}`,code:R.InvalidExtendsReference,severity:D.Error,message:`Entity of type "${r.type}" with id "${r.id}", has an 'extends' reference that isn't pointing to a non-abstract entity. Did you want to use the property 'implements', which holds a list of references to absract entities, instead?`,issue:null})):e.push(new w({id:`${r.id}--${t}--${R.InvalidExtendsReference}`,code:R.InvalidExtendsReference,severity:D.Error,message:`Entity of type "${r.type}" with id "${r.id}", has an 'extends' reference that isn't pointing to an entity of type 'definition-entity' or 'built-in-base-entity'.`,issue:null})):e.push(new w({id:`${r.id}--${t}--${R.ReferencedEntityNotFound}`,code:R.ReferencedEntityNotFound,severity:D.Error,message:`Entity of type "${r.type}" with id "${r.id}", is referencing an entity with id "${t}" that isn't yet found in the project. Perhaps it should be created first. Or perhaps the ID is incorrect.`,issue:null}))}),e}var nd=(r=>(r.Extends="extends",r.Implements="implements",r))(nd||{});const je=class je extends at{constructor(e,t){super(e);f(this,"initialData");f(this,"id");f(this,"name");f(this,"description",null);f(this,"x");f(this,"y");f(this,"static");f(this,"abstract");f(this,"type",n.DefinitionEntity);f(this,"properties",[]);f(this,"methods",[]);f(this,"abstractMethods",[]);f(this,"extends",[]);f(this,"implements",[]);f(this,"project");f(this,"errors",[]);f(this,"parent");f(this,"detachedDependents",{});f(this,"knownVersions",null);f(this,"activeVersion",!1);f(this,"initialized",!1);f(this,"startedInitialization",!1);f(this,"suggestedProperties",[]);f(this,"suggestedMethods",[]);this.initialData=e,this.project=t,this.id=e.id,this.name=e.name,this.description=e.description,this.x=e.x,this.y=e.y,this.static=e.static,this.abstract=e.abstract}static new(){return{id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.DefinitionEntity,name:"",description:"",static:!1,abstract:!1,properties:[],methods:[],abstractMethods:[],extends:[],implements:[],x:0,y:0,parent:null}}static fromGenerationTarget(e,t){let i=t;if(e.parent){const u=_(e.parent);i=t.get(u)}const s=[];e.implements&&e.implements.forEach(u=>{s.push(t.get(u)||t.getBuiltIn(u))});const l=[];e.extends&&e.extends.forEach(u=>{l.push(t.get(u)||t.getBuiltIn(u))});const o={id:e.id,version:m.UUID.uuid(),createdAt:T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,name:e.name,type:n.DefinitionEntity,description:e.description,static:e.static,abstract:e.abstract,properties:[],methods:[],abstractMethods:[],extends:l,implements:s,x:0,y:0,parent:i},d=V(o,t);return d.setParent(i,null),d.initChildren(null),d}static validateGenerationTarget(e,t){let i=JSON.parse(JSON.stringify(e));const s=[],l=eW(i,t),o=Ec(i,t);s.push(...l,...o,...ut(i));const d=i.parent?t.get(i.parent):null;if(d&&d.type===n.DataType){const u=d;u.entity&&s.push(new w({id:`${e.id}--${R.NewEntityWouldOverriteExisting}`,code:R.NewEntityWouldOverriteExisting,severity:D.Error,message:`The entity of type '${e.type}' with id '${e.id}' can't be added to the 'parent' entity with id '${u.id}' because it already has an 'entity' child. Data type entities can only have one 'entity' as children.
405
+ You shouldn't have to manually update a 'parent' property. The equivalent result is to change its callers, the value writters of its inputs, or the value readers of its outputs.`,issue:null})),{errors:t,modifiedData:e}}subscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]||(this.detachedDependents[t.entity.id]=t)}),this}syncDependents(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-dependents"))){const t=[],i=[],s=[],l=[];return Object.values(this.detachedDependents).forEach(o=>{const d=o.entity.afterAllChildrenInitialized(e);t.push(...d.updated),i.push(...d.added),s.push(...d.removed),l.push(...d.affected)}),e==null||e.attemptAutoclose("sync-dependents",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];if(t==="declaration"){const{updated:u,added:y,removed:c}=this.remove({ignoreUpstream:!1},i);s.push(...u),l.push(...y),o.push(...c)}if(t==="parent"){const{updated:u,added:y,removed:c}=this.remove({ignoreUpstream:!1},i);s.push(...u),l.push(...y),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}onDetachedDependencyRestored(e,t,i){const s=[],l=[],o=[],d=[];if(t==="declaration"){const{updated:u,added:y,removed:c}=this.restore({},i);s.push(...u),l.push(...y),o.push(...c)}if(t==="parent"){const{updated:u,added:y,removed:c}=this.restore({},i);s.push(...u),l.push(...y),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}subscribeToDependencies(){var e;return(e=this.parent)==null||e.subscribeDependents([{entity:this,field:"parent"}]),this.declaration.subscribeDependents([{entity:this,field:"declaration"}]),this}increaseVersion(e){if(e&&!T(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&T(e).isSame(T(this.createdAt))?this:(this.previousVersion=this.version,this.version=m.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new qe(this,this.project);return e.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,e):new Map([[this.version,e]]),e.inputs=this.inputs,e.outputs=this.outputs,e.error=this.error,e.successCalls=this.successCalls,e.errorCalls=this.errorCalls,e.process=this.process,e.declaration=this.declaration,e.calledBySuccess=this.calledBySuccess,e.calledByError=this.calledByError,e.calledByEntry=this.calledByEntry,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],i=[],s=[],l=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),i.push(...o.added),s.push(...o.removed)}return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}async restoreVersion(e){var d;const t=[],i=[],s=[],l=[];if(this.version===e)return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this};if(!this.knownVersions){const u=new Map;for(const[y,c]of this.knownVersions||new Map){if(u.set(y,c),c.activeVersion=!1,c.knownVersions)for(const[I,E]of c.knownVersions)u.set(I,E);c.knownVersions=null}}let o=(d=this.knownVersions)==null?void 0:d.get(e);if(!o){const u=await this.APILoadVersion({},e);if(!u)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new qe(u,this.project)}return this.metaSync(o.toShallowJSON(),null),this.inputs=o.inputs,this.outputs=o.outputs,this.error=o.error,this.successCalls=o.successCalls,this.errorCalls=o.errorCalls,this.process=o.process,this.declaration=o.declaration,this.calledBySuccess=o.calledBySuccess,this.calledByError=o.calledByError,this.calledByEntry=o.calledByEntry,this.parent=o.parent,{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}hydrateAncestors(){const e=[],t=[],i=[],s=[];if(this.initialData.parent){const l=_(this.initialData.parent),o=this.project.get(l);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(this.initialData.declaration){const l=_(this.initialData.declaration),o=this.project.get(l);o&&(this.setDeclaration(o),e.push(o))}return this.initialData.calledByEntry.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addEntryCaller(d,null),e.push(d))}),this.initialData.calledBySuccess.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addSuccessCaller(d,null),e.push(d))}),this.initialData.calledByError.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addErrorCaller(d,null),e.push(d))}),{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],i=[],s=[],l=[];this.initialized=!0,this.captureVersion();const{updated:o,added:d,removed:u}=this.syncMissingFixedInputs(e),{updated:y,added:c,removed:I}=this.syncMissingFixedOutputs(e);return t.push(...o,...y),i.push(...d,...c),s.push(...u,...I),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addSelfToProject(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-self-to-project"))){var o;const t=[this],i=[],s=[],l=[];return this.parent===this.project&&this.project.addFunctionCall(this),(o=this.process)==null||o.writesValues.forEach(d=>{d.setValueWriter(this.process,e),t.push(d)}),this.successCalls.forEach(d=>{d.addSuccessCaller(this,e),t.push(d)}),this.errorCalls.forEach(d=>{d.addErrorCaller(this,e),t.push(d)}),this.calledBySuccess.forEach(d=>{d.addSuccessCall(this,e),t.push(d)}),this.calledByError.forEach(d=>{d.addErrorCall(this,e),t.push(d)}),this.calledByEntry.forEach(d=>{d.addCall(this,e),t.push(d)}),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}removeInput(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-input"))){const i=this.inputs.findIndex(s=>s.id===e.id);return i>-1&&(this.inputs.splice(i,1),t&&(t==null||t.add(this,b.Affected))),t==null||t.attemptAutoclose("remove-input",this.id),this}addInput(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-input"))){return this.inputs.includes(e)?(t==null||t.attemptAutoclose("add-input",this.id),this):(this.inputs.push(e),t==null||t.add(this,b.Affected),t==null||t.attemptAutoclose("add-input",this.id),this)}addOutput(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-output"))){return this.outputs.includes(e)?(t==null||t.attemptAutoclose("add-output",this.id),this):(this.outputs.push(e),t==null||t.add(this,b.Affected),t==null||t.attemptAutoclose("add-output",this.id),this)}removeOutput(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-output"))){const i=this.outputs.findIndex(s=>s.id===e.id);return i>-1&&(this.outputs.splice(i,1),t&&(t==null||t.add(this,b.Affected))),t==null||t.attemptAutoclose("remove-output",this.id),this}addValueReader(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-value-reader"))){var i;return this.process&&!this.process.writesValues.includes(e)&&((i=this.process)==null||i.addValueReader(e,t),t==null||t.add(this,b.Affected)),t==null||t.attemptAutoclose("add-value-reader",this.id),this}removeValueReader(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-value-reader"))){var i;return this.process&&this.process.writesValues.includes(e)&&((i=this.process)==null||i.removeValueReader(e,t),t==null||t.add(this,b.Affected)),t==null||t.attemptAutoclose("remove-value-reader",this.id),this}addSuccessCaller(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-success-caller")),i=!1){return this.calledBySuccess.find(s=>s.id===e.id)||(this.calledBySuccess.push(e),t==null||t.add(this,b.Updated),i&&K(this,t)),t==null||t.attemptAutoclose("add-success-caller",this.id),this}addErrorCaller(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-error-caller")),i=!1){return this.calledByError.find(s=>s.id===e.id)||(this.calledByError.push(e),t==null||t.add(this,b.Updated),i&&K(this,t),t==null||t.attemptAutoclose("add-error-caller",this.id)),this}addEntryCaller(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-entry-caller")),i=!1){return this.calledByEntry.find(s=>s.id===e.id)||(this.calledByEntry.push(e),t==null||t.add(this,b.Updated),i&&K(this,t),t==null||t.attemptAutoclose("add-entry-caller",this.id)),this}addErrorCall(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-error-call")),i=!1){return this.errorCalls.find(s=>s.id===e.id)||(this.errorCalls.push(e),i&&K(this,t),t==null||t.add(this,b.Affected)),t==null||t.attemptAutoclose("add-error-call",this.id),this}addSuccessCall(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-success-call")),i=!1){return this.successCalls.find(s=>s.id===e.id)||(this.successCalls.push(e),i&&K(this,t),t==null||t.add(this,b.Affected)),t==null||t.attemptAutoclose("add-success-call",this.id),this}removeCall(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-call")),i=!1){const s=this.successCalls.findIndex(o=>o.id===e.id);s>-1&&(this.successCalls.splice(s,1),t==null||t.add(this,b.Affected));const l=this.errorCalls.findIndex(o=>o.id===e.id);return l>-1&&(this.errorCalls.splice(l,1),t==null||t.add(this,b.Affected)),i&&K(this,t),t==null||t.attemptAutoclose("remove-call",this.id),this}removeCaller(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-caller")),i=!1){return this.calledBySuccess=this.calledBySuccess.filter(s=>s.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(s,b.Affected)),!0):!1),this.calledByError=this.calledByError.filter(s=>s.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(s,b.Affected)),!0):!1),this.calledByEntry=this.calledByEntry.filter(s=>s.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(s,b.Affected)),!0):!1),i&&K(this,t),t==null||t.attemptAutoclose("remove-caller",this.id),this}setParent(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"set-parent"))){var i;return((i=this.parent)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,b.Updated),t==null||t.attemptAutoclose("set-parent",this.id))),this}setDeclaration(e){return this.declaration=e,this}initChildren(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"init-children"))){if(this.initialized||this.startedInitialization)return this;if(this.startedInitialization=!0,this.initialData.declaration.type===n.FunctionDeclaration){const t=V(this.initialData.declaration,this.project);this.declaration=t}else{const t=_(this.initialData.declaration),i=this.project.get(t);this.declaration=i}return this.successCalls=this.initialData.successCalls.map(t=>{const i=V(t,this.project);return i.addSuccessCaller(this),[n.BreakStatement,n.ContinueStatement].includes(i.type)?(i.setParent(this.parent.parent,null),i.initChildren(e)):i.type!==n.InternalCall&&(i.setParent(this.parent,null),i.initChildren(e)),i}),this.errorCalls=this.initialData.errorCalls.map(t=>{const i=V(t,this.project);return i.addErrorCaller(this),[n.BreakStatement,n.ContinueStatement].includes(i.type)?(i.setParent(this.parent.parent,null),i.initChildren(e)):i.type!==n.InternalCall&&(i.setParent(this.parent,null),i.initChildren(e)),i}),this.inputs=this.initialData.inputs.map(t=>{const i=V(t,this.project);return i.setParent(this,null),i.initChildren(e),i}),this.initialData.process&&(this.process=V(this.initialData.process,this.project),this.process.setParent(this,null),this.process.initChildren(e)),this.initialData.error&&(this.error=V(this.initialData.error,this.project),this.error.setParent(this,null),this.error.initChildren(e)),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"meta-sync"))){const i=pt(this,e),s=this.toMeta();return this.x=e.x||s.x,this.y=e.y||s.y,super.metaSync(e),e.deleted===!0&&!s.deleted?t==null||t.add(this,b.Removed):e.deleted===!1&&s.deleted?t==null||t.add(this,b.Added):i&&(t==null||t.add(this,b.Updated)),t==null||t.attemptAutoclose("meta-sync",this.id),this}async APILoad(e=j,...t){return await qe.repository.APILoad(this.id,...t),this}async APICreate(e=j,...t){return await qe.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=j,...t){return await qe.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=j,...t){return await qe.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=j,...t){return await qe.repository.APIClone(this.id,...t),this}async APILoadVersion(e=j,t,...i){return await qe.repository.APILoadVersion(this.id,t,...i)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-entity"))){var d;const i=[],s=[],l=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(s.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(u=>{const{updated:y,removed:c,added:I}=u.entity.onDetachedDependencyRemoved(this,u.field,t);i.push(...y),s.push(...c),l.push(...I)}),this.process){const{updated:u,removed:y}=(d=this.process)==null?void 0:d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...y)}if(this.inputs.forEach(u=>{const{updated:y,removed:c}=u.remove({ignoreUpstream:!0},t);i.push(...y),s.push(...c)}),this.outputs.forEach(u=>{const{updated:y,removed:c}=u.remove({ignoreUpstream:!0},t);i.push(...y),s.push(...c)}),this.error){const{updated:u,removed:y}=this.error.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...y)}return this.successCalls.forEach(u=>{i.push(u),u.removeCaller(this,t)}),this.errorCalls.forEach(u=>{i.push(u),u.removeCaller(this,t)}),e||this.calledBy.forEach(u=>{i.push(u),u.removeCall(this,t)}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:p(l),updated:p(i),removed:p(s),affected:p(o),self:this}}restore({}={},e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"restore-entity"))){const t=[],i=[],s=[],l=[];if(e!=null&&e.hasAdded(this.id))return e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),this.process){const{updated:o}=this.process.restore({},e);i.push(...o)}return this.inputs.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.outputs.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.successCalls.forEach(o=>{i.push(o),o.addSuccessCaller(this,e)}),this.errorCalls.forEach(o=>{i.push(o),o.addErrorCaller(this,e)}),this.calledBySuccess.forEach(o=>{i.push(o),o.addSuccessCall(this,e)}),this.calledByError.forEach(o=>{i.push(o),o.addErrorCall(this,e)}),this.calledByEntry.forEach(o=>{i.push(o),o.addCall(this,e)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(l),self:this}}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.successCalls.flatMap(i=>i.toFlat(e)),...this.errorCalls.flatMap(i=>i.toFlat(e)),...this.inputs.flatMap(i=>i.toFlat(e)),...this.outputs.flatMap(i=>i.toFlat(e)),...this.process?this.process.toFlat(e):[],...this.error?this.error.toFlat(e):[],...this.calledBy.flatMap(i=>i.toFlat(e))])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.successCalls.flatMap(i=>i.toFlatIds(e)),...this.errorCalls.flatMap(i=>i.toFlatIds(e)),...this.inputs.flatMap(i=>i.toFlatIds(e)),...this.outputs.flatMap(i=>i.toFlatIds(e))])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,x:this.x,y:this.y,type:this.type}}toJSON(e=new Set){var t,i;return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,successCalls:this.successCalls.map(s=>s.toJSON(e)),errorCalls:this.errorCalls.map(s=>s.toJSON(e)),calledBySuccess:this.calledBySuccess.map(s=>s.toReference()),calledByError:this.calledByError.map(s=>s.toReference()),calledByEntry:this.calledByEntry.map(s=>s.toReference()),process:(t=this.process)==null?void 0:t.toJSON(e),declaration:this.declaration.toJSON(e),inputs:this.inputs.map(s=>s.toJSON(e)),outputs:this.outputs.map(s=>s.toJSON(e)),parent:this.parent.toReference(),error:(i=this.error)==null?void 0:i.toJSON(e)})}toJSONClone(e=J){var i,s,l,o,d,u,y;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||ht(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(s=e.seenEntities)!=null&&s.has(t)||(l=e.seenEntities)!=null&&l.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(d=e.seenEntities)==null||d.add(this.id),{id:t,version:m.UUID.uuid(),createdAt:e.timestamp||T().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,successCalls:this.successCalls.map(c=>c.toJSONClone({...e,newId:null})),errorCalls:this.errorCalls.map(c=>c.toJSONClone({...e,newId:null})),calledBySuccess:this.calledBySuccess.map(c=>c.toReference({seenEntityMaps:e.seenEntityMaps})),calledByError:this.calledByError.map(c=>c.toReference({seenEntityMaps:e.seenEntityMaps})),calledByEntry:this.calledByEntry.map(c=>c.toReference({seenEntityMaps:e.seenEntityMaps})),process:(u=this.process)==null?void 0:u.toJSONClone({...e,newId:null}),declaration:this.declaration.toJSONClone({...e,newId:null}),inputs:this.inputs.map(c=>c.toJSONClone({...e,newId:null})),outputs:this.outputs.map(c=>c.toJSONClone({...e,newId:null})),error:(y=this.error)==null?void 0:y.toJSONClone({...e,newId:null}),parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps})})}toReference(e=J){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+m.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=J){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,process:this.process?this.process.toReference(e):null,inputs:this.inputs.map(s=>s.toReference(e)),outputs:this.outputs.map(s=>s.toReference(e)),declaration:this.declaration.toReference(e),successCalls:this.successCalls.map(s=>s.toReference(e)),errorCalls:this.errorCalls.map(s=>s.toReference(e)),calledBySuccess:this.calledBySuccess.map(s=>s.toReference(e)),calledByError:this.calledByError.map(s=>s.toReference(e)),calledByEntry:this.calledByEntry.map(s=>s.toReference(e)),error:this.error?this.error.toReference(e):null,parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.successCalls.flatMap(i=>i.toFlatJSON(e)),...this.errorCalls.flatMap(i=>i.toFlatJSON(e)),...this.inputs.flatMap(i=>i.toFlatJSON(e)),...this.outputs.flatMap(i=>i.toFlatJSON(e)),...this.process?this.process.toFlatJSON(e):[],...this.error?this.error.toFlatJSON(e):[]])}toGenerationTarget(){const e=this.parent.type===n.Project?void 0:this.parent.id;return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,calledByEntry:this.calledByEntry.map(t=>t.id),calledBySuccess:this.calledBySuccess.map(t=>t.id),calledByError:this.calledByError.map(t=>t.id),declaration:this.declaration.id,parent:e}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...this.successCalls.flatMap(i=>i.toFlatGenerationTarget(e)),...this.errorCalls.flatMap(i=>i.toFlatGenerationTarget(e)),...this.inputs.flatMap(i=>i.toFlatGenerationTarget(e)),...this.outputs.flatMap(i=>i.toFlatGenerationTarget(e)),...this.process?this.process.toFlatGenerationTarget(e):[],...this.error?this.error.toFlatGenerationTarget(e):[]])}clearErrors(){var e,t;return this.errors=[],this.inputs.forEach(i=>i.clearErrors()),this.outputs.forEach(i=>i.clearErrors()),this.successCalls.forEach(i=>i.clearErrors()),this.errorCalls.forEach(i=>i.clearErrors()),(e=this.process)==null||e.clearErrors(),(t=this.error)==null||t.clearErrors(),this}validate(){const e=H1(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){return[...this.errors,...this.inputs.flatMap(t=>t.getErrors()),...this.outputs.flatMap(t=>t.getErrors()),...this.error?this.error.getErrors():[],...this.process?this.process.getErrors():[]]}getShallowErrors(){return this.errors}clone(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"clone-entity")),t=null,i=null,s=!0){var O,P;let l=mt(t,this);const o=this.toJSON(),d=i||m.UUID.uuid();o.inputs=[];const u=d.split("-id"),y=u[u.length-1||0]||d;o.id=d,o.version=m.UUID.uuid(),o.createdAt=(e==null?void 0:e.timestamp)||T().toISOString(),o.author=(e==null?void 0:e.author)||"1",o.previousVersion=null,o.deleted=!1;const c=ct(o,l);t?c.setParent(t,null):c.setParent(this.parent,null),s&&c.subscribe(),c.initChildren(e),e==null||e.add(c,b.Added);const I=(O=this.inputs)==null?void 0:O.map((C,M)=>C.clone(e,c,y+"-input-map-"+M+"-id",s));c.inputs=I;const E=(P=this.outputs)==null?void 0:P.map((C,M)=>C.clone(e,c,y+"-output-map-"+M+"-id",s));return c.outputs=E,this.error&&(c.error=this.error.clone(e,c,y+"-error-map-id",s)),this.process&&(c.process=this.process.clone(e,c,y+"-process-id",s)),e==null||e.attemptAutoclose("clone-entity",this.id),c}removeUnrecognizedInputs(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-unrecognized-inputs"))){const t=[],i=[],s=[],l=[];return this.inputs.forEach(o=>{if(!this.declaration.inputs.find(u=>{var y;return u.id===((y=o.declaration)==null?void 0:y.id)})){const u=o.remove({ignoreUpstream:!1},e);s.push(...u.removed),t.push(...u.updated)}}),e==null||e.attemptAutoclose("remove-unrecognized-inputs",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}removeUnrecognizedOutputs(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-unrecognized-outputs"))){const t=[],i=[],s=[],l=[];return this.outputs.forEach(o=>{if(!this.declaration.getUniqueReturnDeclarations().find(u=>{var y;return u.id===((y=o.declaration)==null?void 0:y.id)})){const u=o.remove({ignoreUpstream:!1},e);s.push(...u.removed),t.push(...u.updated)}}),e==null||e.attemptAutoclose("remove-unrecognized-outputs",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}syncMissingFixedInputs(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-missing-fixed-inputs"))){const t=[],i=[],s=[],l=[],o=this.declaration.inputs.filter(c=>!this.inputs.find(I=>I.declaration.id===c.id));this.inputs.sort((c,I)=>c.index-I.index),o.forEach(c=>{this.inputs.forEach(O=>{O.index>=c.index&&O.metaSync({index:O.index+1},e)});const I={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.InputMap,declaration:c.toJSON(),readsValue:null,defaultValue:null,index:c.index,name:null,description:null,parent:this.toReference()},E=V(I,this.project);E.setParent(this,e),E.initChildren(e),e==null||e.add(E,b.Added),E.addSelfToProject(e),i.push(E)}),this.inputs.sort((c,I)=>c.index-I.index);const{updated:d,added:u,removed:y}=this.removeUnrecognizedInputs(e);return t.push(...d),i.push(...u),s.push(...y),e==null||e.attemptAutoclose("sync-missing-fixed-inputs",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}syncMissingFixedOutputs(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-missing-fixed-outputs"))){const t=[],i=[],s=[],l=[],o=[];this.outputs=this.initialData.outputs.map(I=>{const E=V(I,this.project);return o.push(E.index),E.setParent(this,null),E.initChildren(e),E});const d=this.declaration.getUniqueReturnDeclarations().filter(I=>!this.outputs.find(E=>E.declaration.id===I.id));this.outputs.sort((I,E)=>I.index-E.index),d.forEach((I,E)=>{this.outputs.forEach(M=>{M.index>=I.index&&M.index++});const O=o.includes(I.index)?this.outputs.length-1+E:I.index,P={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.OutputMap,declaration:I.toJSON(),defaultValue:null,writesValues:[],index:O,parent:this.toReference()},C=V(P,this.project);C.setParent(this,e),C.initChildren(e),e==null||e.add(C,b.Added),C.addSelfToProject(e)}),this.outputs.sort((I,E)=>I.index-E.index);const{updated:u,added:y,removed:c}=this.removeUnrecognizedOutputs(e);return t.push(...u),i.push(...y),s.push(...c),e==null||e.attemptAutoclose("sync-missing-fixed-outputs",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}};f(qe,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>e,APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...i)=>null}),f(qe,"type",n.FunctionCall),f(qe,"USER_MANAGED_PARENT_TYPES",[...dt,n.Project]),f(qe,"PARENT_TYPES",[...qe.USER_MANAGED_PARENT_TYPES]),f(qe,"MUTABLE_BASE_PROPERTIES",[]),f(qe,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),f(qe,"BASE_PROPERTIES",[...qe.MUTABLE_BASE_PROPERTIES,...qe.INMUTABLE_BASE_PROPERTIES]),f(qe,"MUTABLE_META_PROPERTIES",["x","y"]),f(qe,"INMUTABLE_META_PROPERTIES",[...qe.INMUTABLE_BASE_PROPERTIES]),f(qe,"META_PROPERTIES",[...qe.MUTABLE_META_PROPERTIES,...qe.INMUTABLE_META_PROPERTIES]),f(qe,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry"]),f(qe,"INMUTABLE_UPSTREAM_PROPERTIES",["declaration","parent"]),f(qe,"UPSTREAM_PROPERTIES",[...qe.MUTABLE_UPSTREAM_PROPERTIES,...qe.INMUTABLE_UPSTREAM_PROPERTIES]),f(qe,"MUTABLE_DOWNSTREAM_PROPERTIES",["successCalls","errorCalls","writesValues","inputs","outputs","error"]),f(qe,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),f(qe,"DOWNSTREAM_PROPERTIES",[...qe.MUTABLE_DOWNSTREAM_PROPERTIES,...qe.INMUTABLE_DOWNSTREAM_PROPERTIES]),f(qe,"PROPERTIES",[...qe.META_PROPERTIES,...qe.UPSTREAM_PROPERTIES,...qe.DOWNSTREAM_PROPERTIES]);let en=qe;function Zc(r){return r&&typeof r.then=="function"}class Wl{constructor(a){f(this,"order",[]);f(this,"flatRecord",{});f(this,"allBuiltInEntityIds",_i());f(this,"onGoingVisits",{});this.flatten(a),this.orderEntities()}flatten(a){const e=new Set(_i()),t=p(U(a,e,{ignoreBuiltInBaseEntities:!0})),i=new Set;for(const s of t)this.flatRecord[s.id]=s,i.add(s.id);this.order=Array.from(i)}moveEntityAfterDependencies(a){const{upstream:e}=Xl(a,this.flatRecord,{ignoreBuiltInBaseEntities:!0,allBuiltInEntityIds:this.allBuiltInEntityIds});for(const t of Object.keys(e)){const i=this.order.indexOf(t),s=this.order.indexOf(a.id);if(i>s)return this.order.splice(s,1),this.order.splice(i,0,a.id),!0}return!1}orderEntities(){let a=!1;for(let e=0;e<this.order.length;e++){const t=this.order[e],i=this.flatRecord[t];if(this.moveEntityAfterDependencies(i)){a=!0;break}}a&&this.orderEntities()}getUpstreamOngoingDependenciesVisits(a,e){const{upstream:t}=Xl(this.flatRecord[a],this.flatRecord,{ignoreBuiltInBaseEntities:!0,allBuiltInEntityIds:this.allBuiltInEntityIds}),i={};return Object.entries(this.onGoingVisits[e]||{}).forEach(([s,l])=>{Object.keys(t).includes(s)&&(i[s]=l)}),i}getDownstreamOngoingDependenciesVisits(a,e){const t=Object.keys(this.onGoingVisits[e]||{}),i=new Set(t.flatMap(l=>Object.keys(Xl(this.flatRecord[l],this.flatRecord,{ignoreBuiltInBaseEntities:!0,allBuiltInEntityIds:this.allBuiltInEntityIds}).downstream))),s={};return Array.from(i).forEach(l=>{l===a&&(s[l]=this.onGoingVisits[e][l])}),s}async settlePromises(a,e){const t=Object.values(a);t.length&&await Promise.all(t),Object.keys(a).forEach(i=>{delete this.onGoingVisits[e][i]})}visit(a){const e=this.order;for(const t of e)a(this.flatRecord[t],this.flatRecord);return this}reverseVisit(a){const e=this.order.slice().reverse();for(const t of e)a(this.flatRecord[t],this.flatRecord);return this}async visitAsync(a){const e=this.order,t=Math.random().toString(36).substring(7);this.onGoingVisits[t]={};for(const i of e){const s=this.getUpstreamOngoingDependenciesVisits(i,t);Object.keys(s).length&&await this.settlePromises(s,t);const l=a(this.flatRecord[i],this.flatRecord);Zc(l)&&(this.onGoingVisits[t][i]=l)}return await this.settlePromises(this.onGoingVisits[t],t),this.onGoingVisits[t]={},this}async reverseVisitAsync(a){const e=this.order.slice().reverse(),t=Math.random().toString(36).substring(7);this.onGoingVisits[t]={};for(const i of e){const s=this.getDownstreamOngoingDependenciesVisits(i,t);Object.keys(s).length&&await this.settlePromises(s,t);const l=a(this.flatRecord[i],this.flatRecord);Zc(l)&&(this.onGoingVisits[t][i]=l)}return await this.settlePromises(this.onGoingVisits[t],t),this.onGoingVisits[t]={},this}}function X1(r,a){switch(r.id){case k["built-in-base-entity"].BUILT_IN_PERSISTED_ENTITY_ENTITY.id:{const e=r.project.entities.filter(d=>!!d.implements.find(u=>u.id===k["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.id));if(e.find(d=>!!d.properties.find(u=>{var y;return u.implements&&u.implements.id===k["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.default.id&&((y=u.getDefaultValue())==null?void 0:y.value)===!0}))){const u=e[0].properties.find(c=>c.implements&&c.implements.id===k["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.default.id),y=u==null?void 0:u.defaultValue;if(y)y.value=!0;else if(u!=null&&u.dataType){const c={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(a==null?void 0:a.timestamp)||new Date().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.LiteralValue,name:L.EntityTemplate,autogeneration:null,value:!0,valueAsTypeSingle:null,valueAsTypeList:null,parent:u==null?void 0:u.dataType.toReference()},I=V(c,r.project);return I.setParent(u==null?void 0:u.dataType,a),I.initChildren(a),a==null||a.add(I,b.Added),I.addSelfToProject(a),{newEntities:[I]}}return{newEntities:[]}}const i=r.project.get(k["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.id),s=zl(i,"Main database",a);if(s.errors.length>0)return{newEntities:[]};const l=s.properties.find(d=>d.implements&&d.implements.id===k["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.default.id),o=l==null?void 0:l.defaultValue;if(o)o.value=!0;else if(l!=null&&l.dataType){const d={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(a==null?void 0:a.timestamp)||new Date().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.LiteralValue,name:L.EntityTemplate,autogeneration:null,value:!0,valueAsTypeSingle:null,valueAsTypeList:null,parent:l==null?void 0:l.dataType.toReference()},u=V(d,r.project);u.setParent(l==null?void 0:l.dataType,a),u.initChildren(a),a==null||a.add(u,b.Added),u.addSelfToProject(a)}return{newEntities:[s]}}}return{newEntities:[]}}function Q1(r,a){const e=[],t=[],i=[],s=[];return r.implements.filter(o=>o.type===n.BuiltInBaseEntity).forEach(o=>{var d;switch(o.id){case k["built-in-base-entity"].BUILT_IN_PERSISTED_ENTITY_ENTITY.id:{let y=r.project.entities.filter(E=>E.implements.find(O=>O.id===k["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.id)).find(E=>!!E.properties.find(O=>{var P;return O.implements&&O.implements.id===k["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.default.id&&((P=O.getDefaultValue())==null?void 0:P.value)===!0}));if(!y){y=r.project.getBuiltIn(k["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.id).implement("Relational database",a);const O=y.properties.find(P=>{var C;return((C=P.implements)==null?void 0:C.id)===k["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.default.id});(d=O==null?void 0:O.defaultValue)==null||d.metaSync({value:!0},a),t.push(y)}const c=r.properties.find(E=>E.implements&&E.implements.id===k["built-in-base-entity"].BUILT_IN_PERSISTED_ENTITY_ENTITY.properties.database.id),I=c==null?void 0:c.defaultValue;if(c&&!I){const E={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(a==null?void 0:a.timestamp)||new Date().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.LiteralValue,name:L.EntityTemplate,autogeneration:null,value:null,valueAsTypeSingle:y,valueAsTypeList:null,parent:c==null?void 0:c.toReference()},O=V(E,r.project);O.hydrateAncestors(),O.setParent(c,a),O.addSelfToProject(a),O.initChildren(a),a==null||a.add(O,b.Added),t.push(O);return}else I&&I.setValueAsTypeSingle(y,a);return}}}),{self:r,updated:p(e),added:p(t),removed:p(i),affected:p(s)}}function zl(r,a,e,t){const i=t||m.UUID.uuid(),s=m.UUID.uuid(),l={id:i,version:s,createdAt:(e==null?void 0:e.timestamp)||new Date().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,name:a,type:n.DefinitionEntity,description:null,static:r.static,abstract:!1,properties:[],methods:[],abstractMethods:[],extends:[],implements:[r],x:0,y:0,parent:r.project};X1(r,e);const o=V(l,r.project);return o.hydrateAncestors(),e==null||e.add(o,b.Added),o.addSelfToProject(e),o.addImplementation(r),o.setParent(r.project,e),o.initChildren(e),o.afterAllChildrenInitialized(e),Q1(o,e),o}function qc(r,a){return a.entities.find(i=>{const s=i.properties,l=s.map(c=>c.name),o=r.every(c=>l.includes(c)),d=l.filter(c=>!r.includes(c)),u=s.every(c=>!d.includes(c.name)||!c.required);return o&&u})||null}function eP(r,a,e,t=Dt.OrDataTypeGroup){const i=[],s=[],l=[],o=[],u={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||new Date().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.DataType,options:null,implementationChooseOne:!1,entity:r.toJSON(),isList:!1,asType:null,andChildrenGroup:null,orChildrenGroup:null,like:!0,inferred:!1,parentRelationType:t,parent:a.toReference()},y=V(u,r.project);return s.push(y),y.setParent(a,e),y.initChildren(e),e==null||e.add(y,b.Added),y.setEntity(r),y.addSelfToProject(e),{updated:p(i),added:p(s),removed:p(l),affected:p(o),self:y}}function Jc(r,a,e,t,i){var u,y,c,I,E,O,P,C;const s=[],l=[],o=[],d=[];switch(typeof r){case"string":let M=!1;const G=new Date(r);if(G instanceof Date&&!isNaN(G.valueOf())&&(M=!0),M){const B=a.project.getBuiltIn(k[n.PrimitiveEntity][L.Date].id);a.setEntity(B);break}else{const B=a.project.getBuiltIn(k[n.PrimitiveEntity][L.String].id);a.setEntity(B);break}case"number":a.setEntity(a.project.getBuiltIn(k[n.PrimitiveEntity][L.Number].id));break;case"boolean":a.setEntity(a.project.getBuiltIn(k[n.PrimitiveEntity][L.Boolean].id));break;case"object":if(r===null){a.setEntity(a.project.getBuiltIn(k[n.PrimitiveEntity][L.Null].id));break}else if(Array.isArray(r))if(a.metaSync({isList:!0},t),r.length>0){const B=r.slice(0,5).filter(q=>q!==void 0);if(B.every(q=>typeof q==typeof B[0])&&(typeof B[0]!="object"||B[0]===null))switch(typeof B[0]){case"string":a.setEntity(a.project.getBuiltIn(k[n.PrimitiveEntity][L.String].id));break;case"number":a.setEntity(a.project.getBuiltIn(k[n.PrimitiveEntity][L.Number].id));break;case"boolean":a.setEntity(a.project.getBuiltIn(k[n.PrimitiveEntity][L.Boolean].id));break;case"object":a.setEntity(a.project.getBuiltIn(k[n.PrimitiveEntity][L.Null].id));break}else{const q=[];let S=!1;B.forEach(pe=>{var Ie,Q,le,ei;if(Array.isArray(pe)&&(S=!0),typeof pe=="object"&&!Array.isArray(pe)&&pe!==null){const Xi=Yl(pe,a.project,{...e,id:m.UUID.uuid()},t,i);Xi.hasCreated&&q.push((Ie=Xi.changeSet)==null?void 0:Ie.self),s.push(...(Q=Xi.changeSet)==null?void 0:Q.updated),l.push(...(le=Xi.changeSet)==null?void 0:le.added),o.push(...(ei=Xi.changeSet)==null?void 0:ei.removed)}});const X=p(q);if(!X.length&&!S){B.forEach(pe=>{const Ie={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(t==null?void 0:t.timestamp)||new Date().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.DataType,options:null,implementationChooseOne:!1,entity:null,isList:!1,asType:null,andChildrenGroup:null,orChildrenGroup:null,like:!0,inferred:!1,parentRelationType:Dt.OrDataTypeGroup,parent:a.toReference()},Q=V(Ie,a.project);switch(Q.setParent(a,t),Q.initChildren(t),t==null||t.add(Q,b.Added),Q.addSelfToProject(t),typeof pe){case"string":Q.setEntity(Q.project.getBuiltIn(k[n.PrimitiveEntity][L.String].id));break;case"number":Q.setEntity(Q.project.getBuiltIn(k[n.PrimitiveEntity][L.Number].id));break;case"boolean":Q.setEntity(Q.project.getBuiltIn(k[n.PrimitiveEntity][L.Boolean].id));break;case"object":Q.setEntity(Q.project.getBuiltIn(k[n.PrimitiveEntity][L.Null].id));break}});break}else X.length===1&&!S?a.setEntity(X[0]):B.forEach(pe=>{if(typeof pe=="object"&&!Array.isArray(pe)&&pe!==null){const Ie=qc(Object.keys(pe),a.project);if(Ie){const Q=eP(Ie||X[0],a,t,Dt.OrDataTypeGroup);s.push(...Q.updated),l.push(...Q.added),o.push(...Q.removed)}}else{const Ie={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(t==null?void 0:t.timestamp)||new Date().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.DataType,options:null,implementationChooseOne:!1,entity:null,isList:Array.isArray(pe),asType:null,andChildrenGroup:null,orChildrenGroup:null,like:!0,inferred:!1,parentRelationType:Dt.OrDataTypeGroup,parent:a.toReference()},Q=V(Ie,a.project);Q.setParent(a,t),Q.initChildren(t),t==null||t.add(Q,b.Added),Q.addSelfToProject(t);const le=Jc(pe,Q,{...e,id:m.UUID.uuid()},t,i);s.push(...le.updated),l.push(...le.added),o.push(...le.removed)}})}}else{const B=Yl(r[0],a.project,{...e},t,i);a.setEntity((u=B.changeSet)==null?void 0:u.self),s.push(...(y=B.changeSet)==null?void 0:y.updated),l.push(...(c=B.changeSet)==null?void 0:c.added),o.push(...(I=B.changeSet)==null?void 0:I.removed);break}else{const B=Yl(r,a.project,{...e},t,i);a.setEntity((E=B.changeSet)==null?void 0:E.self),s.push(...(O=B.changeSet)==null?void 0:O.updated),l.push(...(P=B.changeSet)==null?void 0:P.added),o.push(...(C=B.changeSet)==null?void 0:C.removed);break}}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:a}}function Yl(r,a,e,t,i){const s=[],l=[],o=[],d=[],u=Object.keys(r),y=qc(u,a);if(y)return{hasCreated:!1,changeSet:{updated:[],added:[],removed:[],affected:[],self:y}};const c=i?e.name+" of "+i.name:e.name,E={id:e.id||m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(t==null?void 0:t.timestamp)||new Date().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,name:c,type:n.DefinitionEntity,description:e.description||null,static:e.static||!1,abstract:e.abstract||!1,properties:[],methods:[],abstractMethods:[],extends:[],implements:[],x:0,y:0,parent:a.toReference()},O=V(E,a);return O.setParent(a,t),O.initChildren(t),t==null||t.add(O,b.Added),O.addSelfToProject(t),l.push(O),u.forEach((P,C)=>{const G={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(t==null?void 0:t.timestamp)||new Date().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,name:P,type:n.Property,description:null,static:!1,abstract:!1,defaultValue:null,constant:!1,dataType:null,implements:null,index:C,hidden:!1,private:!1,required:!0,parent:O.toReference()},B=V(G,a);B.setParent(O,t),B.initChildren(t),t==null||t.add(B,b.Added),B.addSelfToProject(t),l.push(B);const g=r[P],S={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(t==null?void 0:t.timestamp)||new Date().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.DataType,parentRelationType:null,options:null,implementationChooseOne:!1,entity:null,isList:!1,asType:null,andChildrenGroup:null,orChildrenGroup:null,like:!0,inferred:!1,parent:B.toReference()},X=V(S,a);X.setParent(B,t),X.initChildren(t),t==null||t.add(X,b.Added),X.addSelfToProject(t),l.push(X);const pe=Jc(g,X,{...e,name:P,id:m.UUID.uuid()},t,i||O);s.push(...pe.updated),l.push(...pe.added),o.push(...pe.removed)}),{hasCreated:!0,changeSet:{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:O}}}function Tr(r,a,e,t){const i=[];return!r.length||!a.length?{errors:i,overlap:!1}:(r.length>a.length?r.forEach(s=>{const l=a.find(d=>d.name===s.name),o=a.find(d=>{var u,y;return!!s.implements&&((u=d.implements)==null?void 0:u.id)===((y=s.implements)==null?void 0:y.id)});if(l){const d=new it({id:s.id+"--"+l.id+"--"+t,message:`Entity of type ${s.type} named "${s.name}" with id "${s.id}" overrides a base ${l.type} ${l.name} with id "${l.id}" that has the same name`,issue:null,severity:D.Error,code:t,entity:s,firstRelationship:l});i.push(d)}if(o){const d=new it({id:s.id+"--"+o.id+"--"+e,message:`Entity of type ${s.type} named "${s.name}" with id "${s.id}" overrides a base ${o.type} ${o.name} with id "${o.id}" that implements the same base descriptor`,issue:null,severity:D.Error,code:e,entity:s,firstRelationship:o});i.push(d)}}):a.forEach(s=>{var d;const l=r.find(u=>u.name===s.name),o=r.find(u=>{var y,c;return!!u.implements&&((y=u.implements)==null?void 0:y.id)===((c=s.implements)==null?void 0:c.id)});if(l){const u=new it({id:l.id+"--"+s.id+"--"+t,message:`Entity of type ${l.type} named "${l.name}" with id "${l.id}" overrides a base entity ${s.name} with id "${s.id}" that has the same name`,issue:null,severity:D.Error,code:t,entity:l,firstRelationship:s});i.push(u)}if(o){const u=new it({id:o.id+"--"+s.id+"--"+e,message:`Entity of type ${o.type} named "${o.name}" with id "${o.id}" overrides a base entity ${s.name} with id "${s.id}" that implements the same base ${(d=o==null?void 0:o.implements)==null?void 0:d.type}`,issue:null,severity:D.Error,code:e,entity:o,firstRelationship:s});i.push(u)}}),{errors:i,overlap:!!i.length})}function uS(r,a){return r.abstract||(r.properties.forEach(t=>{t.abstract||t.metaSync({abstract:!0},a)}),Object.values(r.detachedDependents).forEach(t=>{t.field===Vc.Entity&&t.entity.remove({ignoreUpstream:!1},a)}),r.metaSync({abstract:!0},a)),r}function pS(r,a){return r.abstract&&(r.properties.forEach(t=>{t.abstract&&t.metaSync({abstract:!1},a)}),Object.values(r.detachedDependents).forEach(t=>{(t.field===nd.Implements||t.field===nd.Extends)&&t.entity.onDetachedDependencyRemoved(r,t.field,a)}),r.metaSync({abstract:!1},a)),r}function cS(r,a){return r.static||(r.properties.forEach(t=>{t.static||t.metaSync({static:!0},a)}),r.metaSync({static:!0},a)),r}function fS(r,a){return r.static&&(r.properties.forEach(t=>{t.static&&t.metaSync({static:!1},a)}),r.metaSync({static:!1},a)),r}function Ds(r,a){const e=Ln(r);if(e.length===0)return{list:[],last:null};let t=null;return{list:e.flatMap(s=>{if(s===a)return t=s,[s];const l=Ds(s,a);return l.last&&(t=l.last),[s,...l.list]}),last:t}}function Sc(r){const a=r.calledBy;if(a.length===0)return r.project;const e=a.reduce((t,i)=>{const s=Zt(i,r.project);return!s||s.type===n.Project?t:t.type===n.Project||Ds(s,t).last?s:(Ds(t,s).last,t)},r.project);return e.type===n.FunctionDeclaration&&e.parent.type===n.Loop?e.parent:e}function K(r,a){var i,s;let e=Sc(r);if(r.type===n.InternalCall)(i=r.parent)==null||i.setParent(e,a),(s=r.parent)==null||s.addSelfToProject(a);else if((r.type===n.ContinueStatement||r.type===n.BreakStatement)&&e.type!==n.Loop){r.remove({ignoreUpstream:!1},a);return}else if(r.type===n.ReturnStatement&&!dt.includes(e.type)){r.remove({ignoreUpstream:!1},a);return}else r.setParent(e,a),r.addSelfToProject(a);if(st.includes(r.type))return;Je(r).forEach(l=>{var d,u;const o=Sc(l);if(l.type===n.InternalCall)(d=l.parent)==null||d.setParent(o,a),(u=l.parent)==null||u.addSelfToProject(a);else if((l.type===n.ContinueStatement||l.type===n.BreakStatement)&&o.type!==n.Loop){l.remove({ignoreUpstream:!1},a);return}else if(l.type===n.ReturnStatement&&!dt.includes(o.type)){l.remove({ignoreUpstream:!1},a);return}else l.setParent(o,a),l.addSelfToProject(a)})}function tP(r,a,e=new Set){const t=tn(r),i=tn(a),s=t.filter(d=>!i.includes(d)),l=t.filter(d=>i.includes(d)),o=s.reduce((d,u)=>e.has(u.id)?d:(e.add(u.id),p([...d,...tP(u,a,e)])),[]);return p([...l,...o])}function _a(r,a){const e=Ds(r,a);return e.last===a&&e.list.length>0&&e.list[0]!==a}function yS(r,a){return!!Ds(r,a).last}function hS(r){if(lt.includes(r.type))return r;if([...Mi,n.VariableDeclaration].includes(r.type)){const a=r.parent;return lt.includes(a.type)?a:null}return null}function Wc(r,a){if(!r||!a)throw new Error("Both entities must be defined to find a common ancestor");if(r===a)return r;const e=r.parent;if(e){if(e===a)return a;if(e.type===n.Project)return null}else return null;const t=a.parent;if(t){if(t===r)return r;if(t.type===n.Project)return null}else return null;return Wc(e,t)}function wt(r){if(Sa.includes(r.type)){if(r.type===n.FunctionDeclaration){const a=r.parent;if(a.type===n.DefinitionEntity)return a;if(a.type===n.Loop)return a}return r}else{const a=r.parent;return a?wt(a):null}}function Hl(r,a){const e=Ma(r,a);if(!e)return null;if(Sa.includes(e.type)){if(e.type===n.FunctionDeclaration){const t=Ma(e.parent,a);if(t){if(t.type===n.DefinitionEntity)return t;if(t.type===n.Loop)return t}}return e}else{const t=e.parent?Ma(e.parent,a):null;return t?Hl(t,a):null}}function iP(r){if(!r)return null;if(Mi.includes(r.type))return r;const a=r.parent;return a?iP(a):null}function rP(r){if(!r)return null;if(ot.includes(r.type))return r;const a=r.parent;return a?rP(a):null}function nP(r){if(!r)return null;if(Ni.includes(r.type))return r;const a=r.parent;return a?nP(a):null}function mS(r){return r.type===n.VariableDeclaration?[r]:ot.includes(r.type)?[...r.inputs,...r.outputs||[]]:st.includes(r.type)?r.outputs:Gn.includes(r.type)||r.type===n.FunctionDeclaration?r.inputs:[]}function vS(r){const a=tn(r),e=[],t=[];lf.includes(r.type)&&e.push(...zc(r));const i=a.filter(s=>{const l=e.includes(s);return l?!1:Mi.includes(s.type)&&!l?(t.push(s),!1):!0});return e.sort((s,l)=>_a(l,s)?-1:0),t.sort((s,l)=>_a(l,s)?-1:0),[...e,...t,...i]}function sP(r){return[...r].sort((a,e)=>_a(e,a)?-1:0)}function TS(r){const a=sP(r),e=[];return a.forEach(t=>{const i=e[e.length-1];if(i){const s=i[i.length-1];_a(t,s)?e.push([t]):i.push(t)}else e.push([t])}),e}function Xt(r){const a=r.map(e=>wt(e));return p(a)}function zc(r){return ot.includes(r.type)?[...Xt(r.successCalls),...Xt(r.errorCalls)]:lt.includes(r.type)?Xt(r.calls):[]}function IS(r,a){return zc(r).includes(a)}function Yc(r){return r.writesValues||[]}function ES(r,a){return Yc(r).includes(a)}function aP(r){var a;return tt.includes((a=r==null?void 0:r.readsValue)==null?void 0:a.type)?r.readsValue:null}function AS(r){return r.writesValues}function oP(r=[]){return r.map(aP).filter(a=>!!a)}function Kl(r=[]){return r.map(a=>a.writesValues).flat().filter(a=>tt.includes(a.type))}function lP(r=[]){return r.map(a=>a.readsValue).filter(a=>!!a&&tt.includes(a.type))}function dP(r){return tt.includes(r.type)?r:null}function uP(r){return r.writesValues.map(dP).filter(a=>!!a)}function pP(r=[]){return r.reduce((a,e)=>e.type===n.OutputMap?[...a,...uP(e)]:a,[])}function Je(r){return ot.includes(r.type)?[...Hi(Xt(r.successCalls)),...Hi(Xt(r.errorCalls))]:lt.includes(r.type)?Hi(Xt(r.calls)):[]}function bS(r){return ot.includes(r.type)?[...Hi(Xt(r.successCalls)),...Hi(Xt(r.errorCalls))]:lt.includes(r.type)?Hi(Xt(r.calls)):[]}function cP(r,a=new Set){return r.writesValues.filter(t=>tt.includes(t.type)&&!a.has(t.id)).reduce((t,i)=>a.has(i.id)?t:[...t,...Ye(i,a)],[])}function fP(r,a=new Set){var t;return(((t=r.readsValue)==null?void 0:t.writesValues)||[]).filter(i=>tt.includes(i.type)&&!a.has(i.id)).reduce((i,s)=>a.has(s.id)?i:[...i,...Ye(s,a)],[])}function Ye(r,a=new Set){if(a.has(r.id))return[];if(r.type===n.ReturnStatement)return lP(r.outputs).reduce((t,i)=>[...t,...Ye(i,a)],[]);if(r.type===n.FunctionCall||r.type===n.Operation||r.type===n.Condition)return[...Je(r).reduce((s,l)=>{const o=wt(l);return[...s,...Ye(o||l,a)]},[]),...oP(r.inputs),...pP(r.outputs)].reduce((s,l)=>[...s,...Ye(l,a)],[]);if(Gn.includes(r.type)){const e=Kl(r.inputs),i=Je(r).reduce((s,l)=>{const o=wt(l);return[...s,...Ye(o||l,a)]},[]);return e.push(...i),e.reduce((s,l)=>[...s,...Ye(l,a)],[])}if(r.type===n.FunctionDeclaration){const e=[...Kl(r.inputs)],i=Je(r).reduce((s,l)=>{const o=wt(l);return[...s,...Ye(o||l,a)]},[]);return e.push(...i),e.reduce((s,l)=>[...s,...Ye(l)],[])}if(tt.includes(r.type)){a.add(r.id);const t=Je(r).reduce((i,s)=>{const l=wt(s);return[...i,...Ye(l||s,a)]},[]);return[r,...t,...fP(r,a),...cP(r,a)]}return[]}function oi(r,a=new Set){return a.has(r.id)?[]:(a.add(r.id),[...tn(r).reduce((i,s)=>[...i,s,...oi(s,a)],[])])}function Hi(r){return r.reduce((a,e)=>e.type===n.ReturnStatement||e.type===n.ContinueStatement||e.type===n.BreakStatement?[...a,e]:[...a,e,...Je(e)],[])}function yP(r){const a=r.entities||[],e=[...a,...r.functions||[],...r.events||[],...r.projects||[]],t=a.reduce((d,u)=>[...d,...u.properties],[]),i=a.reduce((d,u)=>[...d,...u.methods],[]),s=i.reduce((d,u)=>[...d,...Kl(u.inputs),...Hi(Xt(u.calls)),...u.returnStatements],[]),l=r.functions.reduce((d,u)=>[...d,...Hi(Xt(u.calls)),...u.returnStatements],[]),o=r.events.reduce((d,u)=>[...d,...Hi(Xt(u.calls)),...u.returnStatements],[]);return[...e,...t,...i,...s,...l,...o]}function hP(r,a){return a.filter(t=>{if(!t)return!1;switch(t.type){case n.FunctionCall:return t.inputs.find(i=>i.id===r.id)!==void 0||t.outputs.find(i=>i.id===r.id)!==void 0;case n.Condition:return t.successCalls.find(i=>i.id===r.id)!==void 0||t.errorCalls.find(i=>i.id===r.id)!==void 0||t.inputs.find(i=>i.id===r.id)!==void 0;case n.Operation:return t.outputs.find(i=>i.id===r.id)!==void 0;case n.VariableDeclaration:return ot.includes(r.type)?ZP(r).find(s=>{var l;return((l=s.readsValue)==null?void 0:l.id)===t.id})!==void 0:!1;case n.DefinitionEntity:return t.properties.find(i=>i.id===r.id)!==void 0||t.methods.find(i=>i.id===r.id)!==void 0;case n.FunctionDeclaration:return t.inputs.find(i=>i.id===r.id)!==void 0||(t.returnStatements.map(i=>i.outputs).flat()||[]).find(i=>i.id===r.id)!==void 0;default:return!1}})}function RS(r){const a=yP(r.project);return hP(r,a)}function Ma(r,a){return r?typeof r=="string"?a[r]:r.type===n.GenericReference?a[r.entityId]:a[r.id]?a[r.id]:null:null}function Xl(r,a={},e={ignoreBuiltInBaseEntities:!1,allBuiltInEntityIds:[]}){if(e.ignoreBuiltInBaseEntities&&(Ti.includes(r.type)||(e.allBuiltInEntityIds||[]).includes(r.id)))return{upstream:{},downstream:{}};const t=r,i=r,s=r,l=r,o=r,d=r,u=r,y=r,c=r,I=r,E=r,O=r,P=r,C=[...P.readsValue?[P.readsValue]:[],...P.declaration?[P.declaration]:[],...(O.calledByEntry||[]).flatMap(g=>g),...(O.calledBySuccess||[]).flatMap(g=>g),...(O.calledByError||[]).flatMap(g=>g),...(s.extends||[]).flatMap(g=>g),...I.parent?[I.parent]:[]];Array.isArray(s.implements)?C.push(...s.implements.flatMap(g=>g)):c.implements&&C.push(c.implements),o.valueAsTypeList&&Array.isArray(o.valueAsTypeList)&&C.push(...o.valueAsTypeList.flatMap(g=>g)),o.valueAsTypeSingle&&C.push(o.valueAsTypeSingle);const M=[...(t.inputs||[]).flatMap(g=>g),...(E.inputsDeclarations||[]).flatMap(g=>g),...(t.outputs||[]).flatMap(g=>g),...(E.outputsDeclarations||[]).flatMap(g=>g),...(P.internalCalls||[]).flatMap(g=>g),...P.writesValues||[],...O.dataType?[O.dataType]:[],...d.body?[d.body]:[],...O.defaultValue?[O.defaultValue]:[],...(O.successCalls||[]).flatMap(g=>g),...(O.errorCalls||[]).flatMap(g=>g),...(s.properties||[]).flatMap(g=>g),...(s.methods||[]).flatMap(g=>g),...(s.abstractMethods||[]).flatMap(g=>g),...u.error?[u.error]:[],...u.process?[u.process]:[],...I.throws?[I.throws]:[],...(i.andChildrenGroup||[]).flatMap(g=>g),...(i.orChildrenGroup||[]).flatMap(g=>g),...(y.entities||[]).flatMap(g=>g),...(y.functions||[]).flatMap(g=>g),...(y.functionCalls||[]).flatMap(g=>g),...(y.events||[]).flatMap(g=>g),...(y.conditions||[]).flatMap(g=>g),...(y.operations||[]).flatMap(g=>g),...(y.loops||[]).flatMap(g=>g),...(y.variableDeclarations||[]).flatMap(g=>g),...(y.variableInstances||[]).flatMap(g=>g),...(y.searches||[]).flatMap(g=>g),...(y.projects||[]).flatMap(g=>g),...(l.calls||[]).flatMap(g=>g)];r.type===n.DataType&&(i.entity&&a[_(i.entity)]&&a[_(i.entity)].parent&&_(a[_(i.entity)].parent)===r.id?M.push(i.entity):i.entity&&C.push(i.entity));const G={},B={};return C.forEach(g=>{const q=_(g);if(q&&e.ignoreBuiltInBaseEntities&&(Ti.includes(g.type)||(e.allBuiltInEntityIds||[]).includes(q)))return;const S=g.version;q&&(G[q]=S)}),M.forEach(g=>{const q=_(g);if(q&&e.ignoreBuiltInBaseEntities&&(Ti.includes(g.type)||(e.allBuiltInEntityIds||[]).includes(q)))return;const S=g.version;q&&(B[q]=S)}),{upstream:G,downstream:B}}function DS(r,a){const e=[];if(Mi.includes(r.type)){hi(r).forEach(s=>{const l=Hl(s,a);l&&e.push(l)});const i=[...r.inputs||[],...r.outputs||[]].map(s=>{const l=Ma(s,a);return l?JP(l,a):null}).filter(s=>s!==null);e.push(...p(i))}if(tt.includes(r.type)){const t=Ql(r);t&&e.push(t)}return p(e)}function Ln(r){const a=[];if(Mi.includes(r.type)){r.calledBy.forEach(i=>{const s=wt(i);s&&a.push(s)});const t=[...r.inputs||[],...r.outputs||[]].map(i=>Ql(i)).filter(i=>i!==null);a.push(...p(t))}if(tt.includes(r.type)){const e=Ql(r);e&&a.push(e)}return p(a)}function hi(r){return[...r.calledByEntry||[],...r.calledByError||[],...r.calledBySuccess||[]].filter(a=>a.type!==n.GenericReference)}function mP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.ActionDescriptor)throw new Error("Entity must be an action descriptor to be flattened");return[r,...r.inputs.flatMap(t=>U(t,a,e)),...r.outputs.flatMap(t=>U(t,a,e)),...r.error?U(r.error,a,e):[],...r.parent?U(r.parent,a,e):[]]}function vP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.ArgumentDeclaration)throw new Error("Entity must be an argument declaration to be flattened");return[r,...r.defaultValue?U(r.defaultValue,a):[],...r.writesValues.flatMap(t=>U(t,a,e)),...r.dataType?U(r.dataType,a,e):[],...r.parent?U(r.parent,a,e):[]]}function TP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.BreakStatement)throw new Error("Entity must be a break statement to be flattened");return[r,...r.outputs.flatMap(t=>U(t,a,e)),...r.throws?U(r.throws,a,e):[],...(hi(r)||[]).flatMap(t=>U(t,a,e)),...r.parent?U(r.parent,a,e):[]]}function IP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.BuiltInBaseEntity)throw new Error("Entity must be a built-in base entity to be flattened");return[r,...(r.properties||[]).flatMap(t=>U(t,a,e)),...(r.methods||[]).flatMap(t=>U(t,a,e)),...(r.abstractMethods||[]).flatMap(t=>U(t,a,e)),...(r.extends||[]).flatMap(t=>U(t,a,e))]}function EP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.Condition)throw new Error("Entity must be a condition to be flattened");return[r,...(r.inputs||[]).flatMap(t=>U(t,a,e)),...(r.successCalls||[]).flatMap(t=>U(t,a,e)),...(r.errorCalls||[]).flatMap(t=>U(t,a,e)),...(hi(r)||[]).flatMap(t=>U(t,a,e)),...r.parent?U(r.parent,a,e):[]]}function AP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.ContinueStatement)throw new Error("Entity must be a continue statement to be flattened");return[r,...r.outputs.flatMap(t=>U(t,a,e)),...r.throws?U(r.throws,a,e):[],...(hi(r)||[]).flatMap(t=>U(t,a,e)),...r.parent?U(r.parent,a,e):[]]}function bP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.DefinitionEntity)throw new Error("Entity must be a definition entity to be flattened");return[r,...(r.extends||[]).flatMap(t=>U(t,a,e)),...(r.implements||[]).flatMap(t=>U(t,a,e)),...(r.properties||[]).flatMap(t=>U(t,a,e)),...(r.methods||[]).flatMap(t=>U(t,a,e)),...(r.abstractMethods||[]).flatMap(t=>U(t,a,e)),...r.parent?U(r.parent,a,e):[]]}function RP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.DataType)throw new Error("Entity must be a data type to be flattened");return[r,...(r.andChildrenGroup||[]).flatMap(t=>U(t,a,e)),...(r.orChildrenGroup||[]).flatMap(t=>U(t,a,e)),...r.entity?U(r.entity,a,e):[],...r.parent?U(r.parent,a,e):[]]}function DP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.FunctionCall)throw new Error("Entity must be a function call to be flattened");return[r,...(r.inputs||[]).flatMap(t=>U(t,a,e)),...(r.outputs||[]).flatMap(t=>U(t,a,e)),...r.error?U(r.error,a,e):[],...r.process?U(r.process,a,e):[],...(hi(r)||[]).flatMap(t=>U(t,a,e)),...(r.successCalls||[]).flatMap(t=>U(t,a,e)),...(r.errorCalls||[]).flatMap(t=>U(t,a,e)),...r.parent?U(r.parent,a,e):[]]}function OP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.FunctionDeclaration)throw new Error("Entity must be a function declaration to be flattened");return[r,...(r.inputs||[]).flatMap(t=>U(t,a,e)),...(r.calls||[]).flatMap(t=>U(t,a,e)),...r.implements?U(r.implements,a,e):[],...r.parent?U(r.parent,a,e):[]]}function PP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.GlobalEvent)throw new Error("Entity must be a global event to be flattened");return[r,...(r.inputs||[]).flatMap(t=>U(t,a,e)),...(r.calls||[]).flatMap(t=>U(t,a,e)),...r.implements?U(r.implements,a,e):[],...r.parent?U(r.parent,a,e):[]]}function wP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.InputMap)throw new Error("Entity must be an input map to be flattened");return[r,...r.readsValue?U(r.readsValue,a,e):[],...r.declaration?U(r.declaration,a,e):[],...r.defaultValue?U(r.defaultValue,a,e):[],...r.parent?U(r.parent,a,e):[]]}function CP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.InstalledProject)throw new Error("Entity must be an installed project to be flattened");return[r,...(r.functions||[]).flatMap(t=>U(t,a,e)),...(r.events||[]).flatMap(t=>U(t,a,e)),...r.parent?U(r.parent,a,e):[]]}function VP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.InternalCall)throw new Error("Entity must be an internal call to be flattened");return[r,...(r.successCalls||[]).flatMap(t=>U(t,a,e)),...(r.errorCalls||[]).flatMap(t=>U(t,a,e)),...(r.inputs||[]).flatMap(t=>U(t,a,e)),...(r.outputs||[]).flatMap(t=>U(t,a,e)),...(hi(r)||[]).flatMap(t=>U(t,a,e)),...r.error?U(r.error,a,e):[],...r.process?U(r.process,a,e):[],...r.parent?U(r.parent,a,e):[]]}function BP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.LiteralValue)throw new Error("Entity must be a literal value to be flattened");return[r,...r.valueAsTypeSingle?U(r.valueAsTypeSingle,a,e):[],...r.valueAsTypeList&&Array.isArray(r.valueAsTypeList)?r.valueAsTypeList.flatMap(t=>U(t,a,e)):[],...r.parent?U(r.parent,a,e):[]]}function _P(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.Loop)throw new Error("Entity must be a loop to be flattened");return[r,...(r.inputs||[]).flatMap(t=>U(t,a,e)),...(r.outputs||[]).flatMap(t=>U(t,a,e)),...(r.successCalls||[]).flatMap(t=>U(t,a,e)),...(r.errorCalls||[]).flatMap(t=>U(t,a,e)),...r.error?U(r.error,a,e):[],...r.process?U(r.process,a,e):[],...r.body?U(r.body,a,e):[],...(hi(r)||[]).flatMap(t=>U(t,a,e)),...r.parent?U(r.parent,a,e):[]]}function MP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.Operation)throw new Error("Entity must be an operation to be flattened");return[r,...(r.successCalls||[]).flatMap(t=>U(t,a,e)),...(r.errorCalls||[]).flatMap(t=>U(t,a,e)),...(r.inputs||[]).flatMap(t=>U(t,a,e)),...(r.outputs||[]).flatMap(t=>U(t,a,e)),...r.error?U(r.error,a,e):[],...r.process?U(r.process,a,e):[],...(hi(r)||[]).flatMap(t=>U(t,a,e)),...r.parent?U(r.parent,a,e):[]]}function NP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.OutputMap)throw new Error("Entity must be an output map to be flattened");return[r,...(r.writesValues||[]).flatMap(t=>U(t,a,e)),...r.declaration?U(r.declaration,a,e):[],...r.defaultValue?U(r.defaultValue,a,e):[],...r.parent?U(r.parent,a,e):[]]}function LP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.PrimitiveEntity)throw new Error("Entity must be a primitive entity to be flattened");return[r,...(r.properties||[]).flatMap(t=>U(t,a,e)),...(r.methods||[]).flatMap(t=>U(t,a,e)),...(r.abstractMethods||[]).flatMap(t=>U(t,a,e))]}function UP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.Project)throw new Error("Entity must be a project to be flattened");return[r,...(r.entities||[]).flatMap(t=>U(t,a,e)),...(r.functions||[]).flatMap(t=>U(t,a,e)),...(r.events||[]).flatMap(t=>U(t,a,e)),...(r.projects||[]).flatMap(t=>U(t,a,e)),...(r.variableDeclarations||[]).flatMap(t=>U(t,a,e)),...(r.variableInstances||[]).flatMap(t=>U(t,a,e)),...(r.operations||[]).flatMap(t=>U(t,a,e)),...(r.conditions||[]).flatMap(t=>U(t,a,e)),...(r.functionCalls||[]).flatMap(t=>U(t,a,e)),...(r.projects||[]).flatMap(t=>U(t,a,e)),...(r.loops||[]).flatMap(t=>U(t,a,e)),...(r.searches||[]).flatMap(t=>U(t,a,e))]}function jP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.Property)throw new Error("Entity must be a property to be flattened");return[r,...r.defaultValue?U(r.defaultValue,a,e):[],...r.dataType?U(r.dataType,a,e):[],...r.parent?U(r.parent,a,e):[]]}function gP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.ReturnDeclaration)throw new Error("Entity must be a return declaration to be flattened");return[r,...r.readsValue?U(r.readsValue,a,e):[],...r.defaultValue?U(r.defaultValue,a,e):[],...r.dataType?U(r.dataType,a,e):[],...r.parent?U(r.parent,a,e):[]]}function $P(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.ReturnStatement)throw new Error("Entity must be a return statement to be flattened");return[r,...(r.outputs||[]).flatMap(t=>U(t,a,e)),...r.throws?U(r.throws,a,e):[],...(hi(r)||[]).flatMap(t=>U(t,a,e)),...r.parent?U(r.parent,a,e):[]]}function GP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.Search)throw new Error("Entity must be a search to be flattened");return[r,...(r.successCalls||[]).flatMap(t=>U(t,a,e)),...(r.errorCalls||[]).flatMap(t=>U(t,a,e)),...(r.inputsDeclarations||[]).flatMap(t=>U(t,a,e)),...(r.inputs||[]).flatMap(t=>U(t,a,e)),...(r.outputsDeclarations||[]).flatMap(t=>U(t,a,e)),...(r.outputs||[]).flatMap(t=>U(t,a,e)),...r.error?U(r.error,a,e):[],...(hi(r)||[]).flatMap(t=>U(t,a,e)),...r.parent?U(r.parent,a,e):[]]}function FP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.ValueDescriptor)throw new Error("Entity must be a value descriptor to be flattened");return[r,...r.defaultValue?U(r.defaultValue,a,e):[],...r.dataType?U(r.dataType,a,e):[],...r.parent?U(r.parent,a,e):[]]}function xP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.VariableDeclaration)throw new Error("Entity must be a variable declaration to be flattened");return[r,...(r.successCalls||[]).flatMap(t=>U(t,a,e)),...(r.errorCalls||[]).flatMap(t=>U(t,a,e)),...(r.inputs||[]).flatMap(t=>U(t,a,e)),...(r.outputs||[]).flatMap(t=>U(t,a,e)),...(r.internalCalls||[]).flatMap(t=>U(t,a,e)),...(r.writesValues||[]).flatMap(t=>U(t,a,e)),...r.readsValue?U(r.readsValue,a,e):[],...r.defaultValue?U(r.defaultValue,a,e):[],...(hi(r)||[]).flatMap(t=>U(t,a,e)),...r.dataType?U(r.dataType,a,e):[],...r.parent?U(r.parent,a,e):[]]}function kP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.VariableInstance)throw new Error("Entity must be a variable instance to be flattened");return[r,...(r.successCalls||[]).flatMap(t=>U(t,a,e)),...(r.errorCalls||[]).flatMap(t=>U(t,a,e)),...(r.inputs||[]).flatMap(t=>U(t,a,e)),...(r.outputs||[]).flatMap(t=>U(t,a,e)),...(r.internalCalls||[]).flatMap(t=>U(t,a,e)),...(r.writesValues||[]).flatMap(t=>U(t,a,e)),...r.readsValue?U(r.readsValue,a,e):[],...r.defaultValue?U(r.defaultValue,a,e):[],...(hi(r)||[]).flatMap(t=>U(t,a,e)),...r.declaration?U(r.declaration,a,e):[],...r.parent?U(r.parent,a,e):[]]}function _i(){const r=new Set,a=lE.flatMap(e=>U(e,r)).map(e=>e.id);if(!a.includes("http-request-error-return-delaration-id"))throw new Error("Built-in base entities must be included in the list");return a}function U(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(!r)throw new Error("Entity must be defined to be flattened");if(r.type===n.GenericReference)return[];if(e.ignoreBuiltInBaseEntities&&(Ti.includes(r.type)||_i().includes(r.id)))return[];if(a.has(r.id))return[];switch(r.type){case n.FunctionCall:return DP(r,a,e);case n.Operation:return MP(r,a,e);case n.Condition:return EP(r,a,e);case n.Loop:return _P(r,a,e);case n.Search:return GP(r,a,e);case n.GlobalEvent:return PP(r,a,e);case n.ReturnStatement:return $P(r,a,e);case n.ContinueStatement:return AP(r,a,e);case n.BreakStatement:return TP(r,a,e);case n.VariableDeclaration:return xP(r,a,e);case n.DefinitionEntity:return bP(r,a,e);case n.FunctionDeclaration:return OP(r,a,e);case n.Project:return UP(r,a,e);case n.ActionDescriptor:return mP(r,a,e);case n.ArgumentDeclaration:return vP(r,a,e);case n.ReturnDeclaration:return gP(r,a,e);case n.ValueDescriptor:return FP(r,a,e);case n.InputMap:return wP(r,a,e);case n.OutputMap:return NP(r,a,e);case n.DataType:return RP(r,a,e);case n.InstalledProject:return CP(r,a,e);case n.InternalCall:return VP(r,a,e);case n.LiteralValue:return BP(r,a,e);case n.Property:return jP(r,a,e);case n.VariableInstance:return kP(r,a,e);case n.BuiltInBaseEntity:return e.ignoreBuiltInBaseEntities?[]:IP(r,a,e);case n.PrimitiveEntity:return e.ignoreBuiltInBaseEntities?[]:LP(r,a,e)}return[]}function Hc(r){return r.type===n.FunctionCall||r.type===n.InternalCall||[n.Operation,n.Condition,n.Loop].includes(r.type)?r.declaration.inputs:r.type===n.FunctionDeclaration||Gn.includes(r.type)?r.inputs:r.type===n.Search?r.inputsDeclarations:[]}function OS(r,a){return a.type===n.Condition?a.inputs.find(e=>e.declaration.id===r.id):a.type===n.FunctionCall||a.type===n.Operation?a.inputs.find(e=>e.declaration.id===r.id):null}function ZP(r){return ot.includes(r.type)?r.inputs:[]}function qP(r){var a;return r.type===n.FunctionCall?((a=r.declaration.returnStatements[0])==null?void 0:a.outputs)||[]:[n.Operation,n.Condition,n.Loop].includes(r.type)?r.declaration.outputs:r.type===n.Search?r.outputsDeclarations:st.includes(r.type)?r.outputs:[]}function PS(r,a){return a.type===n.Condition?null:a.type===n.FunctionCall||a.type===n.Operation?a.outputs.find(e=>e.declaration.id===r.id):null}function wS(r){return r.type===n.Condition?[]:ot.includes(r.type)?r.outputs:[]}function Ql(r){const a=r.readsValue;return a?wt(a):null}function JP(r,a){const e=r.readsValue;return e?Hl(e,a):null}function SP(r){const a=r.internalCalls||[];return p(Xt(p(a.flatMap(e=>[...e.successCalls,...e.errorCalls]))))}function Os(r){const a=Yc(r),e=[];return a.forEach(t=>{if(tt.includes(t.type))e.push(t);else if(Er.includes(t.type)){const i=t.parent;e.push(i)}}),e}function p(r){const a=new Set;return r.filter(e=>!e||a.has(e.id)?!1:(a.add(e.id),!0))}function tn(r,a=!1){const e=[];if(r.type===n.Project&&e.push(...(r==null?void 0:r.entities)||[],...(r==null?void 0:r.functions)||[],...(r==null?void 0:r.variableDeclarations)||[],...(r==null?void 0:r.variableInstances)||[],...(r==null?void 0:r.searches)||[],...(r==null?void 0:r.loops)||[],...(r==null?void 0:r.operations)||[],...(r==null?void 0:r.conditions)||[],...(r==null?void 0:r.functionCalls)||[],...(r==null?void 0:r.events)||[],...(r==null?void 0:r.projects)||[]),dt.includes(r.type)&&e.push(...(r==null?void 0:r.detachedChildren)||[]),r.type===n.DefinitionEntity){const t=[...r.suggestedMethods,...r.methods].flatMap(i=>i.collapsed&&a?[]:tn(i));e.push(...t)}if(r.type===n.Condition){const t=r.successCalls.map(s=>wt(s)),i=r.errorCalls.map(s=>wt(s));e.push(...t,...i)}if(Gn.includes(r.type)){if(r.collapsed&&a)return[];const t=r.inputs.map(s=>Os(s)).flat(),i=r.calls.map(s=>wt(s));e.push(...p(t),...i)}if(ot.includes(r.type)&&r.type!==n.Condition&&r.type!==n.Loop){const t=r==null?void 0:r.outputs.map(l=>Os(l)).flat(),i=r.successCalls.map(l=>wt(l)),s=r.errorCalls.map(l=>wt(l));e.push(...p(t),...i,...s)}if(tt.includes(r.type)){const t=Os(r),i=SP(r);e.push(...t,...i)}if(r.type===n.Loop){const t=r.outputs.map(l=>Os(l)).flat();if(r.body){const l=tn(r.body,a);e.push(...l)}const i=r.errorCalls.map(l=>wt(l)),s=r.successCalls.map(l=>wt(l));e.push(...p(t),...s,...i)}if(r.type===n.FunctionDeclaration){if(r.collapsed&&a)return[];const t=r.inputs.map(s=>Os(s)).flat(),i=r.calls.map(s=>wt(s));e.push(...p(t),...i)}return p(e)}function WP(r,a=!1){const e=tn(r,a),t=[...e,...e.reduce((i,s)=>[...i,...WP(s,a)],[])];return p(t)}function zP(r){const a=Ln(r),e=[...a,...a.reduce((t,i)=>[...t,...zP(i)],[])];return p(e)}function Na(r){return r.implements.reduce((a,e)=>e.type===n.DefinitionEntity?[...a,n.DefinitionEntity,...Na(e),...La(e)]:[...a,e.name],[])}function La(r){return r.extends.reduce((a,e)=>e.type===n.DefinitionEntity?[...a,n.DefinitionEntity,...La(e),...Na(e)]:[...a,e.name],[])}function Kc(r){return r.extends.reduce((a,e)=>e.type===n.DefinitionEntity?[...a,e,...Kc(e),...Xc(e)]:[...a,e],[])}function Xc(r){return r.implements.reduce((a,e)=>e.type===n.DefinitionEntity?[...a,e,...Xc(e),...Kc(e)]:[...a,e],[])}function Qc(r){return[...La(r),...Na(r)].filter((e,t,i)=>i.indexOf(e)===t)}function YP(r){return r.implements.length===0&&r.extends.length===0?null:r.implements.find(t=>t.type===n.BuiltInBaseEntity&&t.name===z.PERSISTED_ENTITY)?r:[...r.implements,...r.extends].reduce((t,i)=>{if(i.type===n.DefinitionEntity){const s=YP(i);if(s)return s}return t},null)}function CS(r){const a=r.extends.find(e=>e.type===n.BuiltInBaseEntity);return a&&a.type===n.BuiltInBaseEntity?a:null}function VS(r){const a=r.implements.find(e=>e.type===n.BuiltInBaseEntity);return a&&a.type===n.BuiltInBaseEntity?a:null}function HP(r){const a=r.extends.find(e=>e.type===n.DefinitionEntity);return a&&a.type===n.DefinitionEntity?a:null}function kt(r){if(r.type===n.BuiltInBaseEntity)return[r];const a=[...r.implements,...r.extends].reduce((e,t)=>t.type===n.BuiltInBaseEntity?[...e,t]:t.type===n.DefinitionEntity?[...e,...kt(t)]:e,[]);return p(a)}function Ua(r){return r.type===n.PrimitiveEntity?!0:r.type===n.BuiltInBaseEntity?r.interactive:!kt(r).find(t=>!t.interactive)}function BS(r){return r.parent===r.project&&r.project.variableDeclarations.includes(r)}function ef(r){return r.parent!==r.project?!1:n.VariableDeclaration===r.type?r.project.variableDeclarations.includes(r):n.VariableInstance===r.type?r.project.variableInstances.includes(r):n.FunctionCall===r.type?r.project.functionCalls.includes(r):n.Condition===r.type?r.project.conditions.includes(r):n.Operation===r.type?r.project.operations.includes(r):n.Loop===r.type?r.project.loops.includes(r):n.Search===r.type?r.project.searches.includes(r):!1}function KP(r){if([...lt,n.DefinitionEntity,n.InstalledProject,n.Project].includes(r.type)||ef(r))return!1;const a=Ln(r);return a.length===0?!0:a.some(e=>KP(e))}function tf(r){return[...lt,n.DefinitionEntity,n.InstalledProject,n.Project].includes(r.type)||ef(r)?!1:Ln(r).length===0}function XP(r,a=0){if(tf(r)){const e=Ln(r);return e.length===0?r:e.map(i=>XP(i,a+1)).reduce((i,s)=>i?s&&s.x<i.x?s:i:s,null)}return null}function QP(r){const a=[];if(tf(r))a.push(r);else return[];return Ln(r).forEach(t=>{a.push(...QP(t))}),a}function ew(r){return r.type===n.FunctionDeclaration&&r.parent!==r.project&&!![n.DefinitionEntity,n.Loop,n.InstalledProject].includes(r.parent.type)}function _S(r,a){const e=new Map;return r.forEach(t=>{e.set(t.id,t)}),a.forEach(t=>{e.set(t.id,t)}),Array.from(e.values())}function ja(r){switch(r){case n.DefinitionEntity:return nn;case n.FunctionDeclaration:return gr;case n.VariableDeclaration:return Jr;case n.VariableInstance:return qr;case n.FunctionCall:return en;case n.Operation:return Gr;case n.Condition:return Zr;case n.ReturnStatement:return jr;case n.Loop:return kr;case n.Search:return Sr;case n.InputMap:return Wi;case n.OutputMap:return zi;case n.ArgumentDeclaration:return Yr;case n.ReturnDeclaration:return ai;case n.Property:return Ur;case n.InstalledProject:return Wr;case n.Project:return m;case n.DataType:return $r;case n.GlobalEvent:return Fr;case n.InternalCall:return zr;case n.ValueDescriptor:return mr;case n.BuiltInBaseEntity:return Ki;case n.PrimitiveEntity:return Qt;case n.ActionDescriptor:return Se;case n.LiteralValue:return Hr;case n.ContinueStatement:return Lt;case n.BreakStatement:return xr;default:return null}}function Zt(r,a){const e=r!=null&&r.parent?_(r==null?void 0:r.parent):null;let t=e?a.get(e):null;if(r.type===n.FunctionDeclaration&&(t==null?void 0:t.type)===n.Loop)return t;if(dt.includes(r.type))return r;if(Ti.includes(r.type))return null;const i=r.parent;if(!i)return null;if(i.type===n.GenericReference){const s=_(i);if(!s)return null;const l=a.get(s);return l?Zt(l,a):null}else return i===a?a:Zt(i,a)}function rf(r,a){if(Ti.includes(r.type)||a.getBuiltIn(r.id))return null;const e=mi(r.parent,a);return e?e===a?dt.includes(r.type)?r:null:e.type===n.DefinitionEntity?r:rf(e,a):null}function ed(r,a,e){if(r===a||a===e||r===e)return!1;const t=Zt(a.parent,e);return t===r?!0:ed(t,a,e)}var td=(r=>(r.SameBothLocal="same-both-local",r.AInB="a-in-b",r.BInA="b-in-a",r.ParallelInCommonParent="parallel-in-common-parent",r.ParallelInProject="parallel-in-project",r.AIsGlobalBIsNot="a-is-global-b-is-not",r.BIsGlobalAIsNot="b-is-global-a-is-not",r.SameBothGlobal="same-both-global",r))(td||{});function ga(r,a,e){const t=Zt(r,e),i=Zt(a,e);if(!t)throw new Error("Could not find scope owner for the entity: "+r.id);if(!i)throw new Error("Could not find scope owner for the entity: "+a.id);if(t===i&&t.type!==n.Project)return{compatible:!0,type:"same-both-local",commonAncestorScope:t};if(t===i&&t.type===n.Project)return{compatible:!0,type:"same-both-global",commonAncestorScope:t};if(t.type===n.Project&&i.type!==n.Project)return{compatible:!1,type:"a-is-global-b-is-not",commonAncestorScope:t};if(t.type!==n.Project&&i.type===n.Project)return{compatible:!1,type:"b-is-global-a-is-not",commonAncestorScope:i};if(ed(t,i,e))return{compatible:!0,type:"b-in-a",commonAncestorScope:t};if(ed(i,t,e))return{compatible:!0,type:"a-in-b",commonAncestorScope:i};const o=Wc(t,i);return o===e?{compatible:!1,type:"parallel-in-project",commonAncestorScope:o}:o?{compatible:!1,type:"parallel-in-common-parent",commonAncestorScope:Zt(o,e)}:{compatible:!1,type:"parallel-in-project",commonAncestorScope:e}}function tw(r,a,e){const t=ga(r,a,e);if(!t.compatible||t.type!=="same-both-local")return null;if(r===a)return r;let i=Zt(r.parent,e);if(i){if(i===a)return a;if(i.type===n.Project)return r}else return r;for(;i;){if(i){if(i===a)return a;if(i.type===n.Project)return r}else return r;i=Zt(i.parent,e)}let s=Zt(a.parent,e);if(s){if(s===r)return r;if(s.type===n.Project)return a}else return a;for(;s;){if(s){if(s===r)return r;if(s.type===n.Project)return a}else return a;s=Zt(s.parent,e)}return null}function iw(r){return r.length===0?null:r.length===1?r[0]:r.reduce((e,t)=>{const i=tw(e,t,t.project);return!i||i===t?e:t},r[0])}function mi(r,a){if(!r)return null;let e;return typeof r=="string"?e=r:r.type===n.GenericReference?e=_(r):e=r.id,e===a.id?a:a.get(e)}function rn(r){if(!r)return null;if(Ti.includes(r.type))return r;if(r.type===n.Project)return null;if(r.project.getBuiltIn(r.id))return r;const a=r.parent;return!a||a.type===n.Project?null:rn(a)}function $a(r){const a=[];function e(s,l){return a.some(o=>o.blockedByCaller===s&&o.blockedByCalling===l)}function t(s,l){e(s,l)||a.push({blockedByCaller:s,blockedByCalling:l})}const i=rf(r,r.project);return r.calledBySuccess.forEach(s=>{[...s.successCalls||[]].forEach(d=>{st.includes(d.type)&&d!==r&&(Je(r).find(c=>c===d)||t(s,d))});let o;if(ot.includes(s.type)&&(o=s),o){const d=$a(o);d.reachable||Je(r).find(c=>c===s)||d.blocks.forEach(c=>{t(s,c.blockedByCalling)})}}),r.calledByError.forEach(s=>{[...s.errorCalls||[]].forEach(d=>{st.includes(d.type)&&d!==r&&(Je(r).find(c=>c===d)||t(s,d))});let o;if(ot.includes(s.type)&&(o=s),o){const d=$a(o);d.reachable||Je(r).find(c=>c===s)||d.blocks.forEach(c=>{t(s,c.blockedByCalling)})}}),r.calledByEntry.forEach(s=>{if([...s.calls||[]].forEach(d=>{st.includes(d.type)&&d!==r&&(Je(r).find(c=>c===d)||t(s,d))}),s===i)return;let o;if(s.type===n.FunctionDeclaration){const d=wt(s);if(d.type===n.DefinitionEntity)return;d.type===n.Loop&&(o=d)}if(o){const d=$a(o);d.reachable||d.blocks.forEach(u=>{t(s,u.blockedByCalling)})}}),{reachable:a.length===0,entryPoint:i,blocks:a}}function MS(r){return Sa.includes(r.type)?r.type===n.FunctionDeclaration?!ew(r):!0:!1}function NS(r){if(n.ActionDescriptor===r.type){if(r.project.operationDeclarations.find(s=>s.id===r.id))return n.Operation;if(r.project.globalEventActionDescriptors.find(s=>s.id===r.id))return n.GlobalEvent;if(r.project.loopDeclarations.find(s=>s.id===r.id))return n.Loop;if(r.project.conditionDeclarations.find(s=>s.id===r.id))return n.Condition}return r.type}function id(r,a){return r.type===n.BuiltInBaseEntity?r.name===a:!!La(r).includes(a)}function LS(r,a){return r.type===n.BuiltInBaseEntity?r.name===a:!!Na(r).includes(a)}function Ga(r,a){return r.type===n.BuiltInBaseEntity?r.name===a:!!Qc(r).includes(a)}function US(r){const a=[];return r.entities.forEach(e=>{if(id(e,z.PERSISTED_ENTITY)){a.push(e);return}}),p(a)}function jS(r){const a=[];return r.entities.forEach(e=>{if(id(e,z.RELATIONAL_DATABASE)){a.push(e);return}}),p(a)}function gS(r){return r.type!==n.DefinitionEntity||r.abstract||!id(r,z.PERSISTED_ENTITY)?null:(r==null?void 0:r.properties.find(e=>{var t;return((t=e.implements)==null?void 0:t.id)===k[n.BuiltInBaseEntity][z.PERSISTED_ENTITY].properties.primaryKey.id&&!e.abstract}))||null}function $S(r){if(r.type!==n.DefinitionEntity)return[];if(r.abstract)return[];if(!Ga(r,z.PERSISTED_ENTITY))return r.id==="a2d0ec83-72ce-4f54-b059-a39e018fa86c"&&console.log("Entity does not have persisted base entity",r),[];const a=[],e=r.properties.filter(t=>{var i;return((i=t.implements)==null?void 0:i.id)!==k[n.BuiltInBaseEntity][z.PERSISTED_ENTITY].properties.database.id&&!t.abstract});return a.push(...e),a}function GS(r){var e;if(!r||r.type!==n.DefinitionEntity||!Ga(r,z.PERSISTED_ENTITY))return null;const a=r.properties.find(t=>{var i;return((i=t.implements)==null?void 0:i.id)===k[n.BuiltInBaseEntity][z.PERSISTED_ENTITY].properties.database.id});return(e=a==null?void 0:a.getDefaultValue())==null?void 0:e.valueAsTypeSingle}function mt(r,a){var t;if(!uf.includes(a.type)||!r)return a.project||null;let e=a.project;return r.type===n.Project?e=r:((t=a.project)==null?void 0:t.id)!==r.project.id&&(e=r.project),e}function FS(r){switch(r){case n.Project:return m;case n.InstalledProject:return Wr;case n.DefinitionEntity:return nn;case n.FunctionDeclaration:return gr;case n.GlobalEvent:return Fr;case n.VariableInstance:return qr;case n.VariableDeclaration:return Jr;case n.InputMap:return Wi;case n.OutputMap:return zi;case n.Condition:return Zr;case n.Operation:return Gr;case n.FunctionCall:return en;case n.ReturnDeclaration:return ai;case n.ArgumentDeclaration:return Yr;case n.PrimitiveEntity:return Qt;case n.DataType:return $r;case n.Property:return Ur;case n.ActionDescriptor:return Se;case n.ReturnStatement:return jr;case n.ContinueStatement:return Lt;case n.BreakStatement:return xr;case n.Loop:return kr;case n.Search:return Sr;case n.ValueDescriptor:return mr;case n.InternalCall:return zr;case n.LiteralValue:return Hr}return null}function xS(r){const a={added:{},updated:{},removed:{},affected:[],seenEntities:[],self:r==null?void 0:r.self};return r==null||r.added.forEach(e=>{a.added[e.id]=e}),r==null||r.updated.forEach(e=>{a.updated[e.id]=e}),r==null||r.removed.forEach(e=>{a.removed[e.id]=e}),a.affected=Array.from(new Set(r==null?void 0:r.affected.map(e=>e.id))),a}function pt(r,a){const e=ja(r.type);return e?!e.MUTABLE_META_PROPERTIES.every(i=>{const s=r[i],l=a[i];return l===void 0||s===l?!0:Array.isArray(s)&&Array.isArray(l)?s.length!==l.length?!1:s.every((o,d)=>o===l[d]):!1}):!1}function rd(r,a={}){if(r.type===n.Project)return[];if(!r.parent)return[];const e=_(r.parent);if(!e)return[];const t=a[e];return t?[t.id,...rd(t,a)]:[]}function kS(r){const a=[],e=new Set;return[...r.listAdded,...r.listUpdated,...r.listAffected].forEach(t=>{const i=wt(t);!i||e.has(i.id)||(e.add(i.id),a.push(i))}),p(a)}function rw(r){const a=Tq(),e=r.toJSON();a.safeParse(e).success;const i=r.implements.flatMap(y=>ZS(r,y)),s=r.extends.flatMap(y=>qS(r,y)),l=SS(r),o=JS(r);r.methods.flatMap(y=>y.validate());const d=[...i,...s,...l,...o];return He(r.errors,d)}function nw(r,a){const e=a.properties.filter(s=>s.abstract),t=[];let i=[...r.properties];return e.forEach(s=>{const l=i.find(o=>{var d;return((d=o.implements)==null?void 0:d.id)===s.id});l?i=i.filter(o=>o.id!==l.id):t.push(s)}),t}function sw(r,a){const e=a.abstractMethods,t=[];let i=[...r.methods];return e.forEach(s=>{const l=i.find(o=>{var d;return((d=o.implements)==null?void 0:d.id)===s.id});l?i=i.filter(o=>o.id!==l.id):t.push(s)}),t}function ZS(r,a){const e=[];if(!a.abstract){const y=de({id:r.id+"--"+F.ImplementingNonAbstractEntity,message:`Entity "${r.name}" with id "${r.id}" is implementing a non-abstract entity "${a.name}" with id "${a.id}"`,issue:null,severity:D.Error,code:F.ImplementingNonAbstractEntity,entity:r});return e.push(y.error),e}const t=a.properties.filter(y=>y.abstract),i=[];let s=[...r.properties];t.forEach(y=>{const c=s.find(I=>{var E;return((E=I.implements)==null?void 0:E.id)===y.id});c?s=s.filter(I=>I.id!==c.id):i.push(y)}),i.length&&i.forEach(y=>{const c=de({id:r.id+"--"+F.MissingPropertyImplementation+"--"+y.id,message:`Property "${y.name}" with id "${y.id}" of entity "${a.name}" with id "${a.id}" is not implemented when entity "${r.name}" with id "${r.id}" implements it`,issue:null,severity:D.Error,code:F.MissingPropertyImplementation,entity:r});e.push(c.error)});const l=[];let o=[...r.methods];a.abstractMethods.forEach(y=>{const c=o.find(I=>{var E;return((E=I.implements)==null?void 0:E.id)===y.id});c?o=o.filter(I=>I.id!==c.id):l.push(y)}),l.length&&l.forEach(y=>{const c=de({id:r.id+"--"+F.MissingMethodImplementation+"--"+y.id,message:`Method "${y.name}" with id "${y.id}" of entity "${a.name}" with id "${a.id}" is not implemented when entity "${r.name}" with id "${r.id}" implements it`,issue:null,severity:D.Error,code:F.MissingMethodImplementation,entity:r});e.push(c.error)});const d=[];a.properties.forEach(y=>{const c=s.find(I=>I.name===y.name);c&&d.push([c,y])}),d.length&&d.forEach(([y])=>{const c=de({id:r.id+"--"+$.PropertyOverwritesOtherSiblingWithSameName+"--"+y.id,message:`Property "${y.name}" with id "${y.id}" of entity "${r.name}" with id "${r.id}" overwrites the property with the same name from the base entity "${a.name}" with id "${a.id}"`,issue:null,severity:D.Error,code:$.PropertyOverwritesOtherSiblingWithSameName,entity:r});e.push(c.error)});const u=[];return a.methods.forEach(y=>{const c=o.find(I=>I.name===y.name);c&&u.push([c,y])}),u.length&&u.forEach(([y])=>{const c=de({id:r.id+"--"+$.MethodOverwritesOtherSiblingWithSameName+"--"+y.id,message:`Method "${y.name}" with id "${y.id}" of entity "${r.name}" with id "${r.id}" overwrites the method with the same name from the base entity "${a.name}" with id "${a.id}"`,issue:null,severity:D.Error,code:$.MethodOverwritesOtherSiblingWithSameName,entity:r});e.push(c.error)}),e}function qS(r,a){const e=[],t=[];if(!r.abstract&&a.abstract){const s=de({id:r.id+"--"+a.id+"--"+F.NonAbstractExtendingAbstractEntity,message:`Entity "${r.name}" with id "${r.id}" is not-abstract but is extending an abstract entity "${a.name}" with id "${a.id}"`,issue:null,severity:D.Error,code:F.NonAbstractExtendingAbstractEntity,entity:r,firstRelationship:a});return e.push(s.error),e}if(r.abstract&&!a.abstract){const s=de({id:r.id+"--"+a.id+"--"+F.AbstractExtendingNonAbstractEntity,message:`Entity "${r.name}" with id "${r.id}" is abstract but is extending an non-abstract entity "${a.name}" with id "${a.id}"`,issue:null,severity:D.Error,code:F.AbstractExtendingNonAbstractEntity,entity:r,firstRelationship:a});return e.push(s.error),e}r.properties.forEach(s=>{var o;const l=a.properties.find(d=>d.name===s.name);((o=s.implements)==null?void 0:o.id)!==(l==null?void 0:l.id)&&l&&t.push(s)}),t.length&&t.forEach(s=>{const l=de({id:r.id+"--"+$.PropertyOverwritesOtherSiblingWithSameName,message:`Property "${s.name}" with id "${s.id}" of entity "${r.name}" with id "${r.id}" overwrites the property with the same name from the extended entity "${a.name}" with id "${a.id}"`,issue:null,severity:D.Error,code:$.PropertyOverwritesOtherSiblingWithSameName,entity:r});e.push(l.error)});const i=[];return r.methods.forEach(s=>{var o;const l=a.methods.find(d=>d.name===s.name);((o=s.implements)==null?void 0:o.id)!==(l==null?void 0:l.id)&&l&&i.push(s)}),i.length&&i.forEach(s=>{const l=de({id:r.id+"--"+$.MethodOverwritesOtherSiblingWithSameName,message:`Method "${s.name}" with id "${s.id}" of entity "${r.name}" with id "${r.id}" overwrites the method with the same name from the extended entity "${a.name}" with id "${a.id}"`,issue:null,severity:D.Error,code:$.MethodOverwritesOtherSiblingWithSameName,entity:r});e.push(l.error)}),e}function JS(r){const a=[];if(!r.properties.length){const e=de({id:r.id+"--"+F.NoProperties,message:"No properties implemented",issue:null,severity:D.Warning,code:F.NoProperties,entity:r});a.push(e.error)}return r.properties.forEach(e=>{e.validate()}),a}function SS(r){const a=[];if(r.abstract){if(r.methods.length){const e=de({id:r.id+"--"+F.AbstractEntityWithNonAbstractMethods,message:`Entity "${r.name}" with id "${r.id}" is marked as abstract but has non-abstract methods`,issue:null,severity:D.Error,code:F.AbstractEntityWithNonAbstractMethods,entity:r});a.push(e.error)}if(r.properties.some(e=>!e.abstract)){const e=de({id:r.id+"--"+F.AbstractEntityWithNonAbstractProperties,message:`Entity "${r.name}" with id "${r.id}" is marked as abstract but has non-abstract properties`,issue:null,severity:D.Error,code:F.AbstractEntityWithNonAbstractProperties,entity:r});a.push(e.error),r.properties.forEach(t=>{if(!t.abstract){const i=de({id:r.id+"--"+F.StaticEntityWithNonStaticProperties+"--"+t.id,message:`Property "${t.name}" with id "${t.id}" of entity "${r.name}" with id "${r.id}" is not marked as abstract but the entity is marked as abstract`,issue:null,severity:D.Error,code:F.StaticEntityWithNonStaticProperties,entity:r});a.push(i.error)}})}}else{if(r.abstractMethods.length){const e=de({id:r.id+"--"+F.AbstractPropertyInNonAbstractEntity,message:`Entity "${r.name}" with id "${r.id}" is not marked as abstract but has abstract methods`,issue:null,severity:D.Error,code:F.AbstractPropertyInNonAbstractEntity,entity:r});a.push(e.error)}if(r.properties.some(e=>e.abstract)){const e=de({id:r.id+"--"+F.AbstractMethodInNonAbstractEntity,message:`Entity "${r.name}" with id "${r.id}" is not marked as abstract but has abstract properties`,issue:null,severity:D.Error,code:F.AbstractMethodInNonAbstractEntity,entity:r});a.push(e.error),r.properties.forEach(t=>{if(t.abstract){const i=de({id:r.id+"--"+F.AbstractMethodInNonAbstractEntity+"--"+t.id,message:`Property "${t.name}" with id "${t.id}" of entity "${r.name}" with id "${r.id}" is marked as abstract but the entity is not marked as abstract`,issue:null,severity:D.Error,code:F.AbstractMethodInNonAbstractEntity,entity:r});a.push(i.error)}})}}if(r.static&&r.properties.some(e=>!e.static)){const e=de({id:r.id+"--"+F.StaticEntityWithNonStaticProperties,message:`Entity "${r.name}" with id "${r.id}" is marked as static but has non-static properties`,issue:null,severity:D.Error,code:F.StaticEntityWithNonStaticProperties,entity:r});a.push(e.error),r.properties.forEach(t=>{if(!t.static){const i=de({id:r.id+"--"+F.NonStaticPropertyInStaticEntity+"--"+t.id,message:`Property "${t.name}" with id "${t.id}" of entity "${r.name}" with id "${r.id}" is not marked as static but the entity is marked as static`,issue:null,severity:D.Error,code:F.NonStaticPropertyInStaticEntity,entity:r});a.push(i.error)}})}return a}function WS(r,a){const e=[],t=kt(a);if(!a.abstract){const l=new it({id:r.id+"--"+a.id+"--"+F.ImplementingNonAbstractEntity,message:`Entity "${r.name}" with id "${r.id}" is implementing a non-abstract built-in entity "${a.name}" with id "${a.id}"`,issue:null,severity:D.Error,code:F.ImplementingNonAbstractEntity,entity:r,firstRelationship:a});e.push(l)}const i=r.implements.filter(l=>l.id!==a.id);if(r.abstract){const l=new it({id:r.id+"--"+a.id+"--"+F.AbstractEntityImplements,message:`Entity "${r.name}" with id "${r.id}" is marked as abstract and cannot implement built-in entity "${a.name}" with id "${a.id}"`,issue:null,severity:D.Error,code:F.AbstractEntityImplements,entity:r,firstRelationship:a});e.push(l)}if(r.static&&!a.static){const l=new it({id:r.id+"--"+a.id+"--"+F.StaticImplementingNonStaticEntity,message:`Entity "${r.name}" with id "${r.id}" is marked as static and cannot implement non-static built-in entity "${a.name}" with id "${a.id}"`,issue:null,severity:D.Error,code:F.StaticImplementingNonStaticEntity,entity:r,firstRelationship:a});e.push(l)}if(!r.static&&a.static){const l=new it({id:r.id+"--"+a.id+"--"+F.NonStaticImplementingStaticEntity,message:`Entity "${r.name}" with id "${r.id}" is not marked as static and cannot implement static built-in entity "${a.name}" with id "${a.id}"`,issue:null,severity:D.Error,code:F.NonStaticImplementingStaticEntity,entity:r,firstRelationship:a});e.push(l)}return i.length&&i.forEach(l=>{if(l.type===n.BuiltInBaseEntity){const o=t.filter(d=>d.id!==l.id);o.length&&o.forEach(d=>{if(d.id!==l.id){const u=new it({id:r.id+"--"+d.id+"--"+l.id+"--"+F.ImplementsIncompatibleEntities,message:`Entity "${r.name}" with id "${r.id}" is implementing built-in entity "${d.name}" with id "${d.id}" but also implements entity "${l.name}" with id "${l.id}" which is incompatible`,issue:null,severity:D.Error,code:F.ImplementsIncompatibleEntities,entity:r,firstRelationship:d,secondRelationship:l});e.push(u)}})}else{kt(l).forEach(y=>{const c=t.filter(I=>I.id!==y.id);c.length&&c.forEach(I=>{if(I.id!==y.id){const E=new it({id:r.id+"--"+I.id+"--"+y.id+"--"+F.ImplementsIncompatibleEntities,message:`Entity "${r.name}" with id "${r.id}" is implementing built-in entity "${I.name}" with id "${I.id}" but also implements entity "${y.name}" with id "${y.id}" which is incompatible`,issue:null,severity:D.Error,code:F.ImplementsIncompatibleEntities,entity:r,firstRelationship:I,secondRelationship:y});e.push(E)}})});const d=Tr(a.ownDeclaredProperties,l.ownDeclaredProperties,$.PropertyOverwritesOtherImplementedEntitysPropertyWithSameImplementation,$.PropertyOverwritesOtherImplementedEntitysPropertyWithSameName);e.push(...d.errors);const u=Tr(a.abstractMethods,[...l.abstractMethods,...l.methods],$.MethodOverwritesOtherImplementedEntitysMethodWithSameImplementation,$.MethodOverwritesOtherImplementedEntitysMethodWithSameName);e.push(...u.errors)}}),p(r.extends.flatMap(l=>kt(l))).forEach(l=>{if(!t.find(o=>o.id===l.id)){const o=new it({id:r.id+"--"+a.id+"--"+l.id+"--"+F.ExtendsIncompatibleEntities,message:`Entity "${r.name}" with id "${r.id}" is implementing built-in entity "${a.name}" with id "${a.id}" but also extends entity "${l.name}" with id "${l.id}" which is incompatible`,issue:null,severity:D.Error,code:F.ExtendsIncompatibleEntities,entity:r,firstRelationship:a,secondRelationship:l});e.push(o)}}),e}function zS(r,a,e=!1){const t=[],i=kt(a);if(!r.abstract&&a.abstract){const y=de({id:r.id+"--"+a.id+"--"+F.NonAbstractExtendingAbstractEntity,message:`Entity "${r.name}" with id "${r.id}" is not-abstract but is extending an abstract entity "${a.name}" with id "${a.id}"`,issue:null,severity:D.Error,code:F.NonAbstractExtendingAbstractEntity,entity:r,firstRelationship:a});t.push(y.error)}if(r.abstract&&!a.abstract){const y=de({id:r.id+"--"+a.id+"--"+F.AbstractExtendingNonAbstractEntity,message:`Entity "${r.name}" with id "${r.id}" is abstract but is extending an non-abstract entity "${a.name}" with id "${a.id}"`,issue:null,severity:D.Error,code:F.AbstractExtendingNonAbstractEntity,entity:r,firstRelationship:a});t.push(y.error)}if(!r.static&&a.static){const y=de({id:r.id+"--"+a.id+"--"+F.NonStaticExtendingStaticEntity,message:`Entity "${r.name}" with id "${r.id}" is not static but is extending a static entity "${a.name}" with id "${a.id}"`,issue:null,severity:D.Error,code:F.NonStaticExtendingStaticEntity,entity:r,firstRelationship:a});t.push(y.error)}if(r.static&&!a.static){const y=de({id:r.id+"--"+a.id+"--"+F.StaticExtendingNonStaticEntity,message:`Entity "${r.name}" with id "${r.id}" is static but is extending an non-static entity "${a.name}" with id "${a.id}"`,issue:null,severity:D.Error,code:F.StaticExtendingNonStaticEntity,entity:r,firstRelationship:a});t.push(y.error)}if(!Ua(a)){const y=de({id:r.id+"--"+a.id+"--"+F.ExtendingNonInteractiveEntity,message:`Entity "${r.name}" with id "${r.id}" is extending an non-interactive entity "${a.name}" with id "${a.id}"`,issue:null,severity:D.Error,code:F.ExtendingNonInteractiveEntity,entity:r,firstRelationship:a});t.push(y.error)}const l=r.extends.filter(y=>y.id!==a.id);l.length&&l.forEach(y=>{if(y.type===n.BuiltInBaseEntity){const c=i.filter(I=>I.id!==y.id);c.length&&c.forEach(I=>{if(I.id!==y.id){const E=de({id:r.id+"--"+I.id+"--"+y.id+"--"+F.ExtendsIncompatibleEntities,message:`Entity "${r.name}" with id "${r.id}" is extending built-in entity "${I.name}" with id "${I.id}" but also extends entity "${y.name}" with id "${y.id}" which is incompatible`,issue:null,severity:D.Error,code:F.ExtendsIncompatibleEntities,entity:r,firstRelationship:I,secondRelationship:y});t.push(E.error)}})}else{kt(y).forEach(M=>{const G=i.filter(B=>B.id!==M.id);G.length&&G.forEach(B=>{if(B.id!==M.id){const g=new it({id:r.id+"--"+B.id+"--"+M.id+"--"+F.ImplementsIncompatibleEntities,message:`Entity "${r.name}" with id "${r.id}" is extending built-in entity "${B.name}" with id "${B.id}" but also extends or implements entity "${M.name}" with id "${M.id}" which is incompatible`,issue:null,severity:D.Error,code:F.ImplementsIncompatibleEntities,entity:r,firstRelationship:B,secondRelationship:M});t.push(g)}})});const I=!!kt(y).find(M=>M.id===a.id);let E=[...y.properties];I&&(E=E.filter(M=>!a.properties.find(G=>{var B;return G.id===M.id||G.name===M.name||G.id===((B=M.implements)==null?void 0:B.id)})));let O=[...y.methods];I&&(O=O.filter(M=>!a.methods.find(G=>{var B;return G.id===M.id||G.name===M.name||G.id===((B=M.implements)==null?void 0:B.id)})));const P=Tr(a.ownDeclaredProperties,E,$.PropertyOverwritesOtherExtendedEntitysPropertyWithSameImplementation,$.PropertyOverwritesOtherExtendedEntitysPropertyWithSameName);t.push(...P.errors);const C=Tr(a.abstractMethods,O,$.MethodOverwritesOtherExtendedEntitysMethodWithSameImplementation,$.MethodOverwritesOtherExtendedEntitysMethodWithSameName);t.push(...C.errors)}}),e&&console.log("self.implements.length",r.implements.length),r.implements.length&&r.implements.forEach(y=>{if(y.type===n.BuiltInBaseEntity){const c=i.filter(I=>I.id!==y.id);c.length&&c.forEach(I=>{if(I.id!==y.id){const E=new it({id:r.id+"--"+I.id+"--"+y.id+"--"+F.ImplementsIncompatibleEntities,message:`Entity "${r.name}" with id "${r.id}" is implementing built-in entity "${I.name}" with id "${I.id}" but also implements entity "${y.name}" with id "${y.id}" which is incompatible`,issue:null,severity:D.Error,code:F.ImplementsIncompatibleEntities,entity:r,firstRelationship:I,secondRelationship:y});t.push(E)}})}else{kt(y).forEach(O=>{const P=i.filter(C=>C.id!==O.id);P.length&&P.forEach(C=>{if(C.id!==O.id){const M=new it({id:r.id+"--"+C.id+"--"+O.id+"--"+F.ImplementsIncompatibleEntities,message:`Entity "${r.name}" with id "${r.id}" is implementing built-in entity "${C.name}" with id "${C.id}" but also implements entity "${O.name}" with id "${O.id}" which is incompatible`,issue:null,severity:D.Error,code:F.ImplementsIncompatibleEntities,entity:r,firstRelationship:C,secondRelationship:O});t.push(M)}})});const I=Tr(a.ownDeclaredProperties,y.ownDeclaredProperties,$.PropertyOverwritesOtherImplementedEntitysPropertyWithSameImplementation,$.PropertyOverwritesOtherImplementedEntitysPropertyWithSameName);t.push(...I.errors);const E=Tr(a.abstractMethods,[...y.abstractMethods,...y.methods],$.MethodOverwritesOtherImplementedEntitysMethodWithSameImplementation,$.MethodOverwritesOtherImplementedEntitysMethodWithSameName);t.push(...E.errors)}});const o=Tr(r.ownDeclaredProperties,a.ownDeclaredProperties,$.PropertyOverwritesOtherSiblingWithSameImplementation,$.PropertyOverwritesOtherSiblingWithSameName);t.push(...o.errors);const d=Tr(a.methods,a.abstractMethods,$.MethodOverwritesOtherSiblingWithSameImplementation,$.MethodOverwritesOtherSiblingWithSameName);return t.push(...d.errors),p(r.extends.flatMap(y=>kt(y))).forEach(y=>{if(!i.find(c=>c.id===y.id)){const c=new it({id:r.id+"--"+a.id+"--"+y.id+"--"+F.ImplementsIncompatibleEntities,message:`Entity "${r.name}" with id "${r.id}" is extending built-in entity "${a.name}" with id "${a.id}" but also extends entity "${y.name}" with id "${y.id}" which is incompatible`,issue:null,severity:D.Error,code:F.ImplementsIncompatibleEntities,entity:r,firstRelationship:a,secondRelationship:y});t.push(c)}}),t}function YS(r){const a=[];return r.implements.forEach(e=>{if(!e.static){const t=new it({id:r.id+"--"+e.id+"--"+F.StaticImplementingNonStaticEntity,message:`Entity "${r.name}" with id "${r.id}" is static but implements entity "${e.name}" with id "${e.id}" which is non-static`,issue:null,severity:D.Error,code:F.StaticImplementingNonStaticEntity,entity:r,firstRelationship:e});a.push(t)}}),r.extends.forEach(e=>{if(!e.static){const t=new it({id:r.id+"--"+e.id+"--"+F.StaticExtendingNonStaticEntity,message:`Entity "${r.name}" with id "${r.id}" is static but extends entity "${e.name}" with id "${e.id}" which is non-static`,issue:null,severity:D.Error,code:F.StaticExtendingNonStaticEntity,entity:r,firstRelationship:e});a.push(t)}}),a}function HS(r){const a=[];if(r.implements.length){const e=new it({id:r.id+"--"+F.AbstractEntityImplements,message:`Entity "${r.name}" with id "${r.id}" cannot be marked as abstract because it implements other entities`,issue:null,severity:D.Error,code:F.AbstractEntityImplements,entity:r});a.push(e)}return r.extends.forEach(e=>{if(!e.abstract){const t=new it({id:r.id+"--"+e.id+"--"+F.AbstractExtendingNonAbstractEntity,message:`Entity "${r.name}" with id "${r.id}" is abstract but extends entity "${e.name}" with id "${e.id}" which is non-abstract`,issue:null,severity:D.Error,code:F.AbstractExtendingNonAbstractEntity,entity:r,firstRelationship:e});a.push(t)}}),a}function KS(r){const a=[];return r.extends.forEach(e=>{if(e.static){const t=new it({id:r.id+"--"+e.id+"--"+F.NonStaticExtendingStaticEntity,message:`Entity "${r.name}" with id "${r.id}" is non-static but extends entity "${e.name}" with id "${e.id}" which is static`,issue:null,severity:D.Error,code:F.NonStaticExtendingStaticEntity,entity:r,firstRelationship:e});a.push(t)}}),a}function XS(r){const a=[];return r.extends.forEach(e=>{if(e.abstract){const t=new it({id:r.id+"--"+e.id+"--"+F.NonAbstractExtendingAbstractEntity,message:`Entity "${r.name}" with id "${r.id}" is non-abstract but extends entity "${e.name}" with id "${e.id}" which is abstract`,issue:null,severity:D.Error,code:F.NonAbstractExtendingAbstractEntity,entity:r,firstRelationship:e});a.push(t)}}),a}const QS=Object.freeze(Object.defineProperty({__proto__:null,getBaseMethodsNotImplemented:sw,getBasePropertiesNotImplemented:nw,validate:rw,validateCanBecomeAbstract:HS,validateCanBecomeNonAbstract:XS,validateCanBecomeNonStatic:KS,validateCanBecomeStatic:YS,validateCanExtendEntity:zS,validateCanImplementEntity:WS},Symbol.toStringTag,{value:"Module"}));function eW(r,a){const e=[];if(r.parent)if(r.id===r.parent)e.push(new w({id:`${r.id}--${r.parent}--${R.SelfReference}`,code:R.SelfReference,severity:D.Error,message:`Entity of type "${r.type}" with id "${r.id}", has a reference to itself at 'parent'. This is not allowed. Change the reference string or the 'entityId' property of the reference object.`,issue:null}));else{const t=a.get(r.parent);t?[n.Project,n.DataType].includes(t.type)||e.push(new w({id:`${r.id}--${r.parent}--${R.InvalidParentReference}`,code:R.InvalidParentReference,severity:D.Error,message:`Entity of type "${r.type}" with id "${r.id}", has a parent reference that isn't pointing to an entity of type 'project' or 'data-type'.`,issue:null})):e.push(new w({id:`${r.id}--${r.parent}--${R.ReferencedEntityNotFound}`,code:R.ReferencedEntityNotFound,severity:D.Error,message:`Entity of type "${r.type}" with id "${r.id}", is referencing an entity with id "${r.parent}" that isn't yet found in the project. Perhaps it should be created first. Or perhaps the ID is incorrect.`,issue:null}))}return r.implements&&Array.isArray(r.implements)?r.implements.forEach(t=>{if(r.id===t){e.push(new w({id:`${r.id}--${t}--${R.SelfReference}`,code:R.SelfReference,severity:D.Error,message:`Entity of type "${r.type}" with id "${r.id}", has a reference to itself at one of the 'implements' references. This is not allowed. Change the reference string or the 'entityId' property of the reference object.`,issue:null}));return}const i=a.get(t);i?[n.DefinitionEntity,n.BuiltInBaseEntity].includes(i.type)?i.abstract||e.push(new w({id:`${r.id}--${t}--${R.InvalidImplementsReference}`,code:R.InvalidImplementsReference,severity:D.Error,message:`Entity of type "${r.type}" with id "${r.id}", has an 'implements' reference that isn't pointing to an abstract entity.`,issue:null})):e.push(new w({id:`${r.id}--${t}--${R.InvalidImplementsReference}`,code:R.InvalidImplementsReference,severity:D.Error,message:`Entity of type "${r.type}" with id "${r.id}", has an 'implements' reference that isn't pointing to an entity of type 'definition-entity' or 'built-in-base-entity'.`,issue:null})):e.push(new w({id:`${r.id}--${t}--${R.ReferencedEntityNotFound}`,code:R.ReferencedEntityNotFound,severity:D.Error,message:`Entity of type "${r.type}" with id "${r.id}", is referencing an entity with id "${t}" that isn't yet found in the project. Perhaps it should be created first. Or perhaps the ID is incorrect.`,issue:null}))}):e.push(new w({id:`${r.id}--${$.InvalidObjectStructure}`,code:$.InvalidObjectStructure,severity:D.Error,message:`Entity of type "${r.type}" with id "${r.id}", has an 'implements' property that isn't an array.`,issue:null})),r.extends&&Array.isArray(r.extends)&&r.extends.forEach(t=>{const i=a.get(t);i?[n.DefinitionEntity,n.BuiltInBaseEntity].includes(i.type)?i.abstract&&e.push(new w({id:`${r.id}--${t}--${R.InvalidExtendsReference}`,code:R.InvalidExtendsReference,severity:D.Error,message:`Entity of type "${r.type}" with id "${r.id}", has an 'extends' reference that isn't pointing to a non-abstract entity. Did you want to use the property 'implements', which holds a list of references to absract entities, instead?`,issue:null})):e.push(new w({id:`${r.id}--${t}--${R.InvalidExtendsReference}`,code:R.InvalidExtendsReference,severity:D.Error,message:`Entity of type "${r.type}" with id "${r.id}", has an 'extends' reference that isn't pointing to an entity of type 'definition-entity' or 'built-in-base-entity'.`,issue:null})):e.push(new w({id:`${r.id}--${t}--${R.ReferencedEntityNotFound}`,code:R.ReferencedEntityNotFound,severity:D.Error,message:`Entity of type "${r.type}" with id "${r.id}", is referencing an entity with id "${t}" that isn't yet found in the project. Perhaps it should be created first. Or perhaps the ID is incorrect.`,issue:null}))}),e}var nd=(r=>(r.Extends="extends",r.Implements="implements",r))(nd||{});const je=class je extends at{constructor(e,t){super(e);f(this,"initialData");f(this,"id");f(this,"name");f(this,"description",null);f(this,"x");f(this,"y");f(this,"static");f(this,"abstract");f(this,"type",n.DefinitionEntity);f(this,"properties",[]);f(this,"methods",[]);f(this,"abstractMethods",[]);f(this,"extends",[]);f(this,"implements",[]);f(this,"project");f(this,"errors",[]);f(this,"parent");f(this,"detachedDependents",{});f(this,"knownVersions",null);f(this,"activeVersion",!1);f(this,"initialized",!1);f(this,"startedInitialization",!1);f(this,"suggestedProperties",[]);f(this,"suggestedMethods",[]);this.initialData=e,this.project=t,this.id=e.id,this.name=e.name,this.description=e.description,this.x=e.x,this.y=e.y,this.static=e.static,this.abstract=e.abstract}static new(){return{id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.DefinitionEntity,name:"",description:"",static:!1,abstract:!1,properties:[],methods:[],abstractMethods:[],extends:[],implements:[],x:0,y:0,parent:null}}static fromGenerationTarget(e,t){let i=t;if(e.parent){const u=_(e.parent);i=t.get(u)}const s=[];e.implements&&e.implements.forEach(u=>{s.push(t.get(u)||t.getBuiltIn(u))});const l=[];e.extends&&e.extends.forEach(u=>{l.push(t.get(u)||t.getBuiltIn(u))});const o={id:e.id,version:m.UUID.uuid(),createdAt:T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,name:e.name,type:n.DefinitionEntity,description:e.description,static:e.static,abstract:e.abstract,properties:[],methods:[],abstractMethods:[],extends:l,implements:s,x:0,y:0,parent:i},d=V(o,t);return d.setParent(i,null),d.initChildren(null),d}static validateGenerationTarget(e,t){let i=JSON.parse(JSON.stringify(e));const s=[],l=eW(i,t),o=Ec(i,t);s.push(...l,...o,...ut(i));const d=i.parent?t.get(i.parent):null;if(d&&d.type===n.DataType){const u=d;u.entity&&s.push(new w({id:`${e.id}--${R.NewEntityWouldOverriteExisting}`,code:R.NewEntityWouldOverriteExisting,severity:D.Error,message:`The entity of type '${e.type}' with id '${e.id}' can't be added to the 'parent' entity with id '${u.id}' because it already has an 'entity' child. Data type entities can only have one 'entity' as children.
406
406
  You can inspect the existing 'entity' field with the 'describe_entity' action. Like so:
407
407
  ${Yi({describe_entity:u.entity.id})}
408
408
  Alternatively you can update the parent data-type entity with 'update' action to remove the existing value of the field.`,issue:null}))}return{errors:s,modifiedData:i}}get interactive(){return this.implements.length?this.implements.every(e=>e.interactive):!0}get allBasePropertiesFromExtendedAndImplementedEntities(){return p([...this.extends.reduce((e,t)=>[...[...t.ownDeclaredProperties,...t.allBasePropertiesFromExtendedAndImplementedEntities].filter(s=>!s.abstract),...e],[]),...this.implements.reduce((e,t)=>[...[...t.ownDeclaredProperties,...t.allBasePropertiesFromExtendedAndImplementedEntities].filter(s=>!s.abstract),...e],[])])}get allBaseMethodsFromExtendedAndImplementedEntities(){return p([...this.extends.reduce((e,t)=>t.type!==n.DefinitionEntity?[]:[...[...t.ownDeclaredMethods,...t.allBaseMethodsFromExtendedAndImplementedEntities].filter(s=>s.type!==n.ActionDescriptor),...e],[]),...this.implements.reduce((e,t)=>t.type!==n.DefinitionEntity?t.abstractMethods:[...[...t.ownDeclaredMethods,...t.allBaseMethodsFromExtendedAndImplementedEntities].filter(s=>s.type!==n.ActionDescriptor),...e],[])])}get extendedPropertiesFromOriginalParents(){return p(this.extends.reduce((e,t)=>{const i=[...t.ownDeclaredProperties,...t.extendedPropertiesFromOriginalParents].filter(s=>!s.abstract);return[...e,...i]},[]))}get implementedPropertiesFromOriginalParents(){return p([...this.extends.reduce((e,t)=>{const i=t.implementedPropertiesFromOriginalParents,s=[...t.ownDeclaredProperties].filter(l=>!!l.abstract&&!i.find(o=>o.name===l.name));return[...i,...s,...e]},[]),...this.implements.reduce((e,t)=>{const i=t.implementedPropertiesFromOriginalParents,s=[...t.ownDeclaredProperties].filter(l=>!!l.abstract&&!i.find(o=>o.name===l.name));return[...i,...s,...e]},[])].filter(e=>!!e.abstract))}get extendedMethodsFromOriginalParents(){return p(this.extends.reduce((e,t)=>{if(t.type!==n.DefinitionEntity)return[];const i=[...t.ownDeclaredMethods,...t.extendedMethodsFromOriginalParents].filter(s=>s.type!==n.ActionDescriptor);return[...e,...i]},[]))}get implementedMethodsFromOriginalParents(){return p([...this.extends.reduce((e,t)=>{const i=t.type===n.DefinitionEntity?t.methods:[],s=[...t.abstractMethods].filter(l=>!i.find(o=>o.name===l.name));return[...i,...s,...e]},[]),...this.implements.reduce((e,t)=>[...t.abstractMethods,...e],[])].filter(e=>e.type===n.ActionDescriptor))}get extendedProperties(){return this.properties.filter(e=>e.isExtendedProperty)}get ownDeclaredProperties(){return this.properties.filter(e=>!e.isExtendedProperty)}get extendedMethods(){return this.methods.filter(e=>e.isExtendedMethod)}get ownDeclaredMethods(){return this.methods.filter(e=>!e.isExtendedMethod)}validateGeneratedUpdate(e){const t=[];return e.parent&&t.push(new w({id:`${this.id}--${R.InvalidParentUpdate}`,code:R.InvalidParentUpdate,severity:D.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.`,issue:null})),{errors:t,modifiedData:e}}subscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]||(this.detachedDependents[t.entity.id]=t)}),this}syncDependents(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-dependents"))){const t=[],i=[],s=[],l=[];return Object.values(this.detachedDependents).forEach(o=>{const d=o.entity.afterAllChildrenInitialized(e);t.push(...d.updated),i.push(...d.added),s.push(...d.removed),l.push(...d.affected)}),e==null||e.attemptAutoclose("sync-dependents",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];return t==="implements"&&this.removeImplementation(e),t==="extends"&&this.removeExtension(e),{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}onDetachedDependencyRestored(e,t,i){const s=[],l=[],o=[],d=[];return t==="implements"&&this.addImplementation(e),t==="extends"&&this.addExtension(e),{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}subscribeToDependencies(){return this.implements.forEach(e=>{Ti.includes(e.type)||e.subscribeDependents([{entity:this,field:"implements"}])}),this.extends.forEach(e=>{Ti.includes(e.type)||e.subscribeDependents([{entity:this,field:"extends"}])}),this}increaseVersion(e){if(e&&!T(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&T(e).isSame(T(this.createdAt))?this:(this.previousVersion=this.version,this.version=m.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new je(this,this.project);return e.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,e):new Map([[this.version,e]]),e.properties=this.properties,e.methods=this.methods,e.abstractMethods=this.abstractMethods,e.extends=this.extends,e.implements=this.implements,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],i=[],s=[],l=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),i.push(...o.added),s.push(...o.removed)}return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}async restoreVersion(e){var d;const t=[],i=[],s=[],l=[];if(this.version===e)return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this};if(!this.knownVersions){const u=new Map;for(const[y,c]of this.knownVersions||new Map){if(u.set(y,c),c.activeVersion=!1,c.knownVersions)for(const[I,E]of c.knownVersions)u.set(I,E);c.knownVersions=null}}let o=(d=this.knownVersions)==null?void 0:d.get(e);if(!o){const u=await this.APILoadVersion({},e);if(!u)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new je(u,this.project)}return this.metaSync(o.toShallowJSON(),null),this.properties=o.properties,this.methods=o.methods,this.abstractMethods=o.abstractMethods,this.extends=o.extends,this.implements=o.implements,this.parent=o.parent,{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}hydrateAncestors(){const e=[],t=[],i=[],s=[];if(this.initialData.parent){const l=_(this.initialData.parent),o=this.project.get(l);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw new Error(`${this.type} with id '${this.id}' must have a 'parent'`);return this.initialData.extends.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addExtension(d),d.type!==n.BuiltInBaseEntity&&e.push(d))}),this.initialData.implements.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addImplementation(d),d.type!==n.BuiltInBaseEntity&&e.push(d))}),{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],i=[],s=[],l=[];this.initialized=!0,this.captureVersion();const{updated:o,added:d,removed:u,affected:y}=this.syncImplementationProperties(e);t.push(...o),i.push(...d),s.push(...u),l.push(...y);const{updated:c,added:I,removed:E,affected:O}=this.addExtendedProperties(e);t.push(...c),i.push(...I),s.push(...E),l.push(...O);const{updated:P,added:C,removed:M}=this.removeUnrecognizedProperties(e);t.push(...P),i.push(...C),s.push(...M);const{updated:G,added:B,removed:g,affected:q}=this.syncImplementationMethods(e);t.push(...G),i.push(...B),s.push(...g),l.push(...q);const{updated:S,added:X,removed:pe}=this.removeUnrecognizedMethods(e);return t.push(...S),i.push(...X),s.push(...pe),this.addSuggestions(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addSelfToProject(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-self-to-project"))){const t=[this],i=[],s=[],l=[];if(this.parent.type===n.DataType){const o=this.parent;o.entity=this,t.push(o)}else this.project.addDefinitionEntity(this);return this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}setParent(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"set-parent"))){var i;return((i=this.parent)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,b.Updated),t==null||t.attemptAutoclose("set-parent",this.id))),this}addExtension(e){return this.extends.includes(e)||this.extends.push(e),this}removeExtension(e){return this.extends=this.extends.filter(t=>t.id!==e.id),this}addImplementation(e){return this.implements.includes(e)||this.implements.push(e),this}removeImplementation(e){return this.implements=this.implements.filter(t=>t.id!==e.id),this}removeProperty(e){return this.properties=this.properties.filter(t=>t.id!==e.id),this}addMethod(e){return this.methods.includes(e)||(this.methods.push(e),this.suggestedMethods=this.suggestedMethods.filter(t=>t.name!==e.name)),this}removeMethod(e){return this.methods=this.methods.filter(t=>t.id!==e.id),this}addProperty(e){return this.properties.includes(e)||(this.properties.push(e),this.suggestedProperties=this.suggestedProperties.filter(t=>t.name!==e.name)),this}addSuggestedProperty(e){return this.suggestedProperties.includes(e)||this.suggestedProperties.push(e),this}addSuggestedMethod(e){return this.suggestedMethods.includes(e)||this.suggestedMethods.push(e),this}removeSuggestedProperty(e){return this.suggestedProperties=this.suggestedProperties.filter(t=>t.id!==e.id),this}removeSuggestedMethod(e){return this.suggestedMethods=this.suggestedMethods.filter(t=>t.id!==e.id),this}addAbstractMethod(e){return this.abstractMethods.includes(e)||this.abstractMethods.push(e),this}removeAbstractMethod(e){return this.abstractMethods=this.abstractMethods.filter(t=>t.id!==e.id),this}initChildren(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.properties=this.initialData.properties.map(t=>{const i=V(t,this.project);return i.setParent(this,null),i.initChildren(e),i}),this.methods=this.initialData.methods.map(t=>{const i=V(t,this.project);return i.setParent(this,null),i.initChildren(e),i}),this.abstractMethods=this.initialData.abstractMethods.map(t=>{const i=V(t,this.project);return i.setParent(this,null),i.initChildren(e),i}),this.extends=this.initialData.extends.map(t=>V(t,this.project)),this.implements=this.initialData.implements.map(t=>V(t,this.project)),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this)}removeUnrecognizedProperties(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-unrecognized-properties"))){const t=[],i=[],s=[],l=[];let o=[...this.properties];o=o.filter(u=>u.parent.id===this.id),o=o.filter(u=>!u.isExtendedProperty);const d=this.implementedPropertiesFromOriginalParents;return o=o.filter(u=>this.interactive&&!u.implements?!1:!d.find(y=>{var c;return y.id===((c=u.implements)==null?void 0:c.id)})),o.forEach(u=>{const y=u.remove({ignoreUpstream:!1},e);s.push(...y.removed),t.push(...y.updated)}),e==null||e.attemptAutoclose("remove-unrecognized-properties",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}removeUnrecognizedMethods(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-unrecognized-methods"))){const t=[],i=[],s=[],l=[];let o=[...this.methods];o=o.filter(u=>u.parent.id===this.id),o=o.filter(u=>!u.isExtendedMethod);const d=this.implementedMethodsFromOriginalParents;return o=o.filter(u=>this.interactive&&!u.implements?!1:!d.find(y=>{var c;return y.id===((c=u.implements)==null?void 0:c.id)})),o.forEach(u=>{const y=u.remove({ignoreUpstream:!1},e);s.push(...y.removed),t.push(...y.updated)}),e==null||e.attemptAutoclose("remove-unrecognized-methods",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}syncImplementationMethods(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-implementation-methods"))){const t=[],i=[],s=[],l=[],o=this.methods,d=this.implementedMethodsFromOriginalParents,u=[...this.allBaseMethodsFromExtendedAndImplementedEntities,...o];return d.filter(c=>!u.find(E=>{var O;return((O=E.implements)==null?void 0:O.id)===c.id})).forEach(c=>{if(this.methods.find(P=>{var C;return((C=P.implements)==null?void 0:C.id)===c.id}))return;const E=this.methods.find(P=>{var g,q;if(P.name===c.name&&!P.implements)return!0;const C=Ga(this,z.CRON_JOB),M=Ga(this,z.HTTP_ENDPOINT),G=((g=P.implements)==null?void 0:g.id)===k["built-in-base-entity"].BUILT_IN_HTTP_ENDPOINT_ENTITY.methods.handler.id,B=((q=P.implements)==null?void 0:q.id)===k["built-in-base-entity"].BUILT_IN_CRON_JOB_ENTITY.methods.handler.id;return!!(C&&!B&&!M&&G||M&&!G&&!C&&B)});if(E&&E.type===n.FunctionDeclaration){E.setImplements(c),E.metaSync({name:c.name},e),e==null||e.add(E,b.Updated),e==null||e.add(this,b.Updated);return}const O=c.implementAsFunctionDeclaration(e,this);i.push(O),e==null||e.add(O,b.Added),this.addMethod(O)}),e==null||e.attemptAutoclose("sync-implementation-methods",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}syncImplementationProperties(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-implementation-properties"))){const t=[],i=[],s=[],l=[],o=this.properties,d=this.implementedPropertiesFromOriginalParents,u=[...this.allBasePropertiesFromExtendedAndImplementedEntities,...o];return d.filter(c=>!u.find(E=>{var O;return((O=E.implements)==null?void 0:O.id)===c.id})).forEach(c=>{if(this.properties.find(P=>{var C;return((C=P.implements)==null?void 0:C.id)===c.id}))return;const E=this.properties.find(P=>P.name===c.name&&!!P.abstract&&!P.implements);if(E){E.implements=c,E.abstract=!1;return}const O=c.clone(e,this,m.UUID.uuid());O.initChildren(e),i.push(O),e==null||e.add(O,b.Added),O.setImplements(c,e),O.metaSync({abstract:!1},e),this.addProperty(O)}),e==null||e.attemptAutoclose("sync-implementation-properties",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addExtendedProperties(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-extended-properties"))){const t=[],i=[],s=[],l=[],o=this.properties,d=this.extendedPropertiesFromOriginalParents,u=d.filter(c=>d.find(E=>{var O;return((O=E.implements)==null?void 0:O.id)===c.id})?!1:!c.abstract),y=new Set(o.map(c=>c.name));return u.forEach(c=>{if(y.has(c.name))return;y.add(c.name);const I=c.clone(e,this,m.UUID.uuid());I.initChildren(e),i.push(I),e==null||e.add(I,b.Added),this.addProperty(I)}),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addSuggestions(){return this.implements.forEach(e=>{nw(this,e).forEach(s=>{const l=s.toJSON();l.id=`_suggestion--parent--${this.id}--${s.id}`;const o=V(l,this.project);o.suggestion=!0,o.setParent(this,null),o.initChildren(null),this.addSuggestedProperty(o)}),sw(this,e).forEach(s=>{const l=`_suggestion--parent--${this.id}--${s.id}`,o=s.implementAsFunctionDeclaration(null,this,l),d=V(o,this.project);if(d.suggestion=!0,d.setParent(this,null),d.initChildren(null),this.methods=this.methods.filter(u=>u.id!==l),d.inputs.forEach(u=>{u.suggestion=!0}),d.returnStatements.length){const u=d.returnStatements[0];u.suggestion=!0,u.outputs.forEach(y=>{y.suggestion=!0})}this.addSuggestedMethod(d)})}),this}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"meta-sync"))){const i=pt(this,e),s=this.toMeta();return this.name=e.name!==void 0?e.name:s.name,this.description=e.description!==void 0?e.description:s.description,this.x=e.x||s.x,this.y=e.y||s.y,this.static=e.static!==void 0?e.static:this.static,this.abstract=e.abstract!==void 0?e.abstract:this.abstract,super.metaSync(e),e.deleted===!0&&!s.deleted?t==null||t.add(this,b.Removed):e.deleted===!1&&s.deleted?t==null||t.add(this,b.Added):i&&(t==null||t.add(this,b.Updated)),t==null||t.attemptAutoclose("meta-sync",this.id),this}async APILoad(e=j,...t){return await je.repository.APILoad(this.id,...t),this}async APICreate(e=j,...t){return await je.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=j,...t){return await je.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=j,...t){return await je.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=j,...t){return await je.repository.APIClone(this.id,...t),this}async APILoadVersion(e=j,t,...i){return await je.repository.APILoadVersion(this.id,t,...i)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-entity"))){const i=[],s=[],l=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(s.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(d=>{const{updated:u,removed:y,added:c}=d.entity.onDetachedDependencyRemoved(this,d.field,t);i.push(...u),s.push(...y),l.push(...c)}),this.properties.forEach(d=>{const{updated:u,removed:y}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...y)}),this.methods.forEach(d=>{const{updated:u,removed:y}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...y)}),this.abstractMethods.forEach(d=>{const{updated:u,removed:y}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...y)}),this.suggestedProperties.forEach(d=>{const{updated:u,removed:y}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...y)}),this.suggestedMethods.forEach(d=>{const{updated:u,removed:y}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...y)}),!e){if(this.parent.type===n.Project)this.parent.removeDefinitionEntity(this);else if(this.parent.type===n.DataType){const d=this.parent.setEntity(null);i.push(d)}}return t==null||t.attemptAutoclose("remove-entity",this.id),{added:p(l),updated:p(i),removed:p(s),affected:p(o),self:this}}restore({}={},e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"restore-entity"))){const t=[],i=[],s=[],l=[];return e!=null&&e.hasAdded(this.id)?(e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),this.properties.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.methods.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.abstractMethods.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.suggestedProperties.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.suggestedMethods.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(l),self:this})}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.extends.flatMap(i=>i.toFlat(e)),...this.implements.flatMap(i=>i.toFlat(e)),...this.properties.flatMap(i=>i.toFlat(e)),...this.methods.flatMap(i=>i.toFlat(e)),...this.abstractMethods.flatMap(i=>i.toFlat(e)),...this.parent.toFlat(e)])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.extends.flatMap(i=>i.toFlatIds(e)),...this.implements.flatMap(i=>i.toFlatIds(e)),...this.properties.flatMap(i=>i.toFlatIds(e)),...this.methods.flatMap(i=>i.toFlatIds(e)),...this.abstractMethods.flatMap(i=>i.toFlatIds(e)),...this.parent.toFlatIds(e)])}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,x:this.x,y:this.y,type:this.type,name:this.name}}toJSON(e=new Set){return e.has(this.id)?this.toReference():(e.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,x:this.x,y:this.y,static:this.static,abstract:this.abstract,properties:this.properties.map(t=>t.toJSON(e)),methods:this.methods.map(t=>t.toJSON(e)),abstractMethods:this.abstractMethods.map(t=>t.toJSON(e)),implements:this.implements.map(t=>t.toJSON(e)),extends:this.extends.map(t=>t.toJSON(e)),parent:this.parent.toReference()})}toJSONClone(e=J){var i,s,l,o,d;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||ht(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(s=e.seenEntities)!=null&&s.has(t)||(l=e.seenEntities)!=null&&l.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(d=e.seenEntities)==null||d.add(this.id),{id:t,version:m.UUID.uuid(),createdAt:e.timestamp||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:this.type,name:this.name,description:this.description,x:this.x,y:this.y,static:this.static,abstract:this.abstract,properties:this.properties.map(u=>u.toJSONClone({...e,newId:null})),methods:this.methods.map(u=>u.toJSONClone({...e,newId:null})),abstractMethods:this.abstractMethods.map(u=>u.toJSONClone({...e,newId:null})),implements:this.implements.map(u=>u.type===n.BuiltInBaseEntity?u.toJSON():u.toJSONClone({...e,newId:null})),extends:this.extends.map(u=>u.type===n.BuiltInBaseEntity?u.toJSON():u.toJSONClone({...e,newId:null})),parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps})})}toReference(e=J){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+m.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=J){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,name:this.name,description:this.description,type:this.type,x:this.x,y:this.y,static:this.static,abstract:this.abstract,properties:this.properties.map(s=>s.toReference(e)),methods:this.methods.map(s=>s.toReference(e)),abstractMethods:this.abstractMethods.map(s=>s.toReference(e)),implements:this.implements.map(s=>s.toReference(e)),extends:this.extends.map(s=>s.toReference(e)),parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.properties.flatMap(i=>i.toFlatJSON(e)),...this.methods.flatMap(i=>i.toFlatJSON(e)),...this.abstractMethods.flatMap(i=>i.toFlatJSON(e)),...this.implements.flatMap(i=>i.toFlatJSON(e)),...this.extends.flatMap(i=>i.toFlatJSON(e)),...this.parent.toFlatJSON(e)])}toGenerationTarget(){const e=this.parent.type===n.Project?void 0:this.parent.id;return{id:this.id,name:this.name,description:this.description,type:this.type,static:this.static,abstract:this.abstract,extends:this.extends.map(t=>t.id),implements:this.implements.map(t=>t.id),parent:e}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...this.properties.flatMap(i=>i.toFlatGenerationTarget(e)),...this.methods.flatMap(i=>i.toFlatGenerationTarget(e)),...this.abstractMethods.flatMap(i=>i.toFlatGenerationTarget(e)),...this.implements.filter(i=>i.type===n.DefinitionEntity).flatMap(i=>i.toFlatGenerationTarget(e)),...this.implements.filter(i=>i.type===n.DefinitionEntity).flatMap(i=>i.toFlatGenerationTarget(e)),...this.parent.toFlatGenerationTarget(e)])}clearErrors(){return this.errors=[],this.properties.forEach(e=>e.clearErrors()),this.methods.forEach(e=>e.clearErrors()),this.abstractMethods.forEach(e=>e.clearErrors()),this}validate(){return this.errors=rw(this),{success:!0,error:null,data:null}}getErrors(){return[...this.errors,...this.properties.flatMap(t=>t.getErrors()),...this.methods.flatMap(t=>t.getErrors()),...this.abstractMethods.flatMap(t=>t.getErrors())]}getShallowErrors(){return this.errors}clone(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"clone-entity")),t=null,i=null,s=!0){var P,C,M;let l=mt(t,this);const o=this.toJSON(),d=i||m.UUID.uuid();o.properties=[],o.methods=[],o.abstractMethods=[];const u=d.split("-id"),y=u[u.length-1||0]||d;o.id=d,o.version=m.UUID.uuid(),o.createdAt=(e==null?void 0:e.timestamp)||T().toISOString(),o.author=(e==null?void 0:e.author)||"1",o.previousVersion=null,o.deleted=!1;const c=ct(o,l);t&&c.setParent(t,null),s&&c.subscribe(),c.initChildren(e),e==null||e.add(c,b.Added);const I=(P=this.properties)==null?void 0:P.map(G=>G.clone(e,c,m.UUID.uuid(),s));c.properties=I;const E=(C=this.methods)==null?void 0:C.map((G,B)=>G.clone(e,c,y+"-method-"+B+"-id",s));c.methods=E;const O=(M=this.abstractMethods)==null?void 0:M.map((G,B)=>G.clone(e,c,y+"-abstract-method-"+B+"-id",s));return c.abstractMethods=O,e==null||e.attemptAutoclose("clone-entity",this.id),c}getFunctionDeclaration(e){return this.methods.find(t=>t.id===e)}implement(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"implement-definition-entity")),i){const s=zl(this,e,t,i);return t==null||t.attemptAutoclose("implement-definition-entity",this.id),s}getAllInteractiveMethods(){const e=this.implements.filter(i=>i.type===n.DefinitionEntity||i.type===n.BuiltInBaseEntity&&i.interactive);return p([...this.methods,...this.extends.flatMap(i=>i.getAllInteractiveMethods()),...e.flatMap(i=>i.getAllInteractiveMethods())])}inferFromInputs(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"infer-definition-entity-from-inputs"))){const i=[],s=[],l=[],o=[];if(this.parent.type!==n.DataType||!this.parent.inferred)return t==null||t.attemptAutoclose("infer-definition-entity-from-inputs",this.id),{added:[],updated:[],removed:[],affected:[],self:this};const d=[];e.forEach(c=>{d.find(E=>x(E,this.project)===x(c,this.project))||d.push(c)});const u=this.properties.filter(c=>!c.dataType);d.forEach(c=>{var M,G;const I=u.find(B=>x(B,this.project)===x(c,this.project));if(!I)return;const O=Nn(c.parent).getMasterInputWithValueWritterFromAllInstances(c),P=Si(O,t),C=P==null?void 0:P.clone(t,I,m.UUID.uuid(),!0);if(C){const B=(M=I.dataType)==null?void 0:M.merge(C,t);I.dataType&&(B==null?void 0:B.self.id)!==I.dataType.id&&I.dataType.remove({ignoreUpstream:!1},t),C.id!==((G=B==null?void 0:B.self)==null?void 0:G.id)&&C.remove({ignoreUpstream:!1},t),B!=null&&B.self&&(B.self.metaSync({inferred:!0,like:!0},t),t==null||t.add(B.self,b.Added),I.setDataType(B.self),t==null||t.add(I,b.Updated))}c.setDeclaration(I),t==null||t.add(c,b.Updated)});const y=[];return d.forEach(c=>{if(!c.declaration){y.push(c);return}}),y.length===0?(t==null||t.attemptAutoclose("infer-definition-entity-from-inputs",this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(y.forEach(c=>{var B,g,q,S;const I=this.properties.find(X=>x(X,this.project)===x(c,this.project));if(I){if(c.setDeclaration(I),!I.getDataType(t)){const pe=Nn(c.parent).getMasterInputWithValueWritterFromAllInstances(c),Ie=Si(pe),Q=Ie==null?void 0:Ie.clone(t,I,m.UUID.uuid(),!0);if(Q){const le=(B=I.dataType)==null?void 0:B.merge(Q,t);I.dataType&&(le==null?void 0:le.self.id)!==I.dataType.id&&I.dataType.remove({ignoreUpstream:!1},t),Q.id!==((g=le==null?void 0:le.self)==null?void 0:g.id)&&Q.remove({ignoreUpstream:!1},t),le!=null&&le.self&&(le.self.metaSync({inferred:!0,like:!0},t),t==null||t.add(le.self,b.Added),I.setDataType(le.self),t==null||t.add(I,b.Updated))}}return}const E={id:m.UUID.uuid(),type:n.Property,version:m.UUID.uuid(),createdAt:(t==null?void 0:t.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,name:x(c,this.project),description:c.description,defaultValue:null,static:!0,abstract:!1,private:!1,hidden:!1,required:!1,constant:!0,index:c.index,implements:null,dataType:null,parent:this.toReference()},O=V(E,this.project);O.setParent(this,t),O.initChildren(t),t==null||t.add(O,b.Added);const C=Nn(c.parent).getMasterInputWithValueWritterFromAllInstances(c),M=Si(C),G=M==null?void 0:M.clone(t,O,m.UUID.uuid(),!0);if(G){const X=(q=O.dataType)==null?void 0:q.merge(G,t);O.dataType&&(X==null?void 0:X.self.id)!==O.dataType.id&&O.dataType.remove({ignoreUpstream:!1},t),G.id!==((S=X==null?void 0:X.self)==null?void 0:S.id)&&G.remove({ignoreUpstream:!1},t),X!=null&&X.self&&(X.self.metaSync({inferred:!0,like:!0},t),t==null||t.add(X.self,b.Added),O.setDataType(X.self),t==null||t.add(O,b.Updated))}return this.addProperty(O),c.setDeclaration(O),t==null||t.add(c,b.Updated),O}),t==null||t.attemptAutoclose("infer-definition-entity-from-inputs",this.id),{added:p(i),updated:p(s),removed:p(l),affected:p(o),self:this})}};f(je,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>e,APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...i)=>null}),f(je,"type",n.DefinitionEntity),f(je,"USER_MANAGED_PARENT_TYPES",[n.Project,n.DataType]),f(je,"PARENT_TYPES",[...je.USER_MANAGED_PARENT_TYPES]),f(je,"MUTABLE_BASE_PROPERTIES",["name","description","static","abstract"]),f(je,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),f(je,"BASE_PROPERTIES",[...je.MUTABLE_BASE_PROPERTIES,...je.INMUTABLE_BASE_PROPERTIES]),f(je,"MUTABLE_META_PROPERTIES",[...je.MUTABLE_BASE_PROPERTIES,"x","y"]),f(je,"INMUTABLE_META_PROPERTIES",[...je.INMUTABLE_BASE_PROPERTIES]),f(je,"META_PROPERTIES",[...je.MUTABLE_META_PROPERTIES,...je.INMUTABLE_META_PROPERTIES]),f(je,"MUTABLE_UPSTREAM_PROPERTIES",["extends","implements"]),f(je,"INMUTABLE_UPSTREAM_PROPERTIES",["parent"]),f(je,"UPSTREAM_PROPERTIES",[...je.MUTABLE_UPSTREAM_PROPERTIES,...je.INMUTABLE_UPSTREAM_PROPERTIES]),f(je,"MUTABLE_DOWNSTREAM_PROPERTIES",["properties","methods","abstractMethods"]),f(je,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),f(je,"DOWNSTREAM_PROPERTIES",[...je.MUTABLE_DOWNSTREAM_PROPERTIES,...je.INMUTABLE_DOWNSTREAM_PROPERTIES]),f(je,"PROPERTIES",[...je.META_PROPERTIES,...je.UPSTREAM_PROPERTIES,...je.DOWNSTREAM_PROPERTIES]);let nn=je;function tW(r){const a=K3(),e=r.toJSON();a.safeParse(e).success;const i=[];return He(r.errors,i)}const ka=class ka extends at{constructor(e,t){super(e);f(this,"initialData");f(this,"id");f(this,"version");f(this,"name");f(this,"description",null);f(this,"type",n.BuiltInBaseEntity);f(this,"abstract",!1);f(this,"static");f(this,"properties",[]);f(this,"methods",[]);f(this,"abstractMethods",[]);f(this,"extends",[]);f(this,"interactive",!1);f(this,"errors",[]);f(this,"project");this.initialData=this.initialData||e,this.project=this.project||t,this.id=this.id||e.id,this.version=this.version||e.version,this.name=this.name||e.name,this.static=this.static||e.static,this.interactive=this.interactive||e.interactive,this.abstract=e.abstract,this.properties=this.initialData.properties.map(i=>{const s=V(i,this.project);return s.setParent(this,null),s.initChildren(null),s}),this.methods=this.initialData.methods.map(i=>{const s=V(i,this.project);return s.setParent(this,null),s.initChildren(null),s}),this.abstractMethods=this.initialData.abstractMethods.map(i=>{const s=V(i,this.project);return s.setParent(this,null),s.initChildren(null),s}),this.extends=this.initialData.extends.map(i=>V(i,this.project))}get allBasePropertiesFromExtendedAndImplementedEntities(){return p(this.extends.reduce((e,t)=>{const i=[...t.ownDeclaredProperties,...t.allBasePropertiesFromExtendedAndImplementedEntities].filter(s=>!s.abstract);return[...e,...i]},[]))}get extendedPropertiesFromOriginalParents(){return p(this.extends.reduce((e,t)=>{const i=[...t.ownDeclaredProperties,...t.extendedPropertiesFromOriginalParents].filter(s=>!s.abstract);return[...e,...i]},[]))}get implementedPropertiesFromOriginalParents(){return p([...this.extends.reduce((e,t)=>{const i=t.implementedPropertiesFromOriginalParents,s=[...t.ownDeclaredProperties].filter(l=>!!l.abstract&&!i.find(o=>o.name===l.name));return[...i,...s,...e]},[])])}get extendedProperties(){return this.properties.filter(e=>e.isExtendedProperty)}get ownDeclaredProperties(){return this.properties.filter(e=>!e.isExtendedProperty)}subscribe(){return this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}async APILoad(e=j,...t){return await ka.repository.APILoad(this.id,...t),this}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.properties.flatMap(i=>i.toFlat(e)),...this.methods.flatMap(i=>i.toFlat(e)),...this.abstractMethods.flatMap(i=>i.toFlat(e)),...this.extends.flatMap(i=>i.toFlat(e))])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.properties.flatMap(i=>i.toFlatIds(e)),...this.methods.flatMap(i=>i.toFlatIds(e)),...this.abstractMethods.flatMap(i=>i.toFlatIds(e)),...this.extends.flatMap(i=>i.toFlatIds(e))])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,description:this.description,interactive:this.interactive,abstract:this.abstract,static:this.static,type:this.type,name:this.name}}toJSON(e=new Set){return e.has(this.id)?this.toReference():(e.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,abstract:this.abstract,static:this.static,interactive:this.interactive,properties:this.properties.map(t=>t.toJSON(e)),methods:this.methods.map(t=>t.toJSON(e)),abstractMethods:this.abstractMethods.map(t=>t.toJSON(e)),extends:this.extends.map(t=>t.toJSON(e))})}toReference(e=J){return{id:this.id+"--"+m.UUID.uuid()+"--ref",type:n.GenericReference,entityId:this.id,version:this.version,entityType:this.type}}toShallowJSON(e=J){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,interactive:this.interactive,properties:this.properties.map(t=>t.toReference()),methods:this.methods.map(t=>t.toReference()),abstractMethods:this.abstractMethods.map(t=>t.toReference()),extends:this.extends.map(t=>t.toReference())}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.properties.flatMap(i=>i.toFlatJSON(e)),...this.methods.flatMap(i=>i.toFlatJSON(e)),...this.abstractMethods.flatMap(i=>i.toFlatJSON(e))])}toGenerationTarget(){return{id:this.id,type:this.type,name:this.name,description:this.description,static:this.static,abstract:this.abstract,interactive:this.interactive,extends:this.extends.map(e=>e.id)}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...this.properties.flatMap(i=>i.toFlatGenerationTarget(e)),...this.methods.flatMap(i=>i.toFlatGenerationTarget(e)),...this.abstractMethods.flatMap(i=>i.toFlatGenerationTarget(e))])}clearErrors(){return this.errors=[],this.properties.forEach(e=>e.clearErrors()),this.methods.forEach(e=>e.clearErrors()),this.abstractMethods.forEach(e=>e.clearErrors()),this}validate(){const e=tW(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){return[...this.errors,...this.properties.flatMap(t=>t.getErrors()),...this.methods.flatMap(t=>t.getErrors()),...this.abstractMethods.flatMap(t=>t.getErrors())]}getShallowErrors(){return this.errors}implement(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),null,!0,"implement-built-in-base-entity")),i){const s=zl(this,e,t,i);return t==null||t.attemptAutoclose("implement-built-in-base-entity",this.id),s}getAllInteractiveMethods(){const e=[];return this.interactive&&(e.push(...this.methods),this.extends.filter(i=>i.type===n.BuiltInBaseEntity&&i.interactive||i.type===n.PrimitiveEntity).forEach(i=>{i instanceof ka&&e.push(...i.getAllInteractiveMethods())})),p(e)}};f(ka,"repository",{APILoad:async(e,...t)=>null});let Ki=ka;function iW(r){const a=k3(),e=r.toJSON();a.safeParse(e).success;const i=[];return He(r.errors,i)}const ld=class ld extends at{constructor(e,t){super(e);f(this,"initialData");f(this,"id");f(this,"name");f(this,"description",null);f(this,"type",n.PrimitiveEntity);f(this,"static");f(this,"abstract");f(this,"properties",[]);f(this,"methods",[]);f(this,"abstractMethods",[]);f(this,"extends",[]);f(this,"errors",[]);f(this,"project");this.initialData=e,this.project=t,this.id=e.id,this.name=e.name,this.static=e.static,this.abstract=e.abstract,this.properties=this.initialData.properties.map(i=>{const s=V(i,this.project);return s.setParent(this,null),s.initChildren(null),s}),this.methods=this.initialData.methods.map(i=>{const s=V(i,this.project);return s.parent=this,s}),this.abstractMethods=this.initialData.abstractMethods.map(i=>{const s=V(i,this.project);return s.parent=this,s})}get allBasePropertiesFromExtendedAndImplementedEntities(){return p(this.extends.reduce((e,t)=>{const i=[...t.ownDeclaredProperties,...t.allBasePropertiesFromExtendedAndImplementedEntities].filter(s=>!s.abstract);return[...e,...i]},[]))}get extendedPropertiesFromOriginalParents(){return p(this.extends.reduce((e,t)=>{const i=[...t.ownDeclaredProperties,...t.extendedPropertiesFromOriginalParents].filter(s=>!s.abstract);return[...e,...i]},[]))}get implementedPropertiesFromOriginalParents(){return p([...this.extends.reduce((e,t)=>{const i=t.implementedPropertiesFromOriginalParents,s=[...t.ownDeclaredProperties].filter(l=>!!l.abstract&&!i.find(o=>o.name===l.name));return[...i,...s,...e]},[])])}get extendedProperties(){return this.properties.filter(e=>e.isExtendedProperty)}get ownDeclaredProperties(){return this.properties.filter(e=>!e.isExtendedProperty)}subscribe(){return this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}async APILoad(e=j,...t){return await ld.repository.APILoad(this.id,...t),this}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.properties.flatMap(i=>i.toFlat(e)),...this.methods.flatMap(i=>i.toFlat(e)),...this.abstractMethods.flatMap(i=>i.toFlat(e))])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.properties.flatMap(i=>i.toFlatIds(e)),...this.methods.flatMap(i=>i.toFlatIds(e)),...this.abstractMethods.flatMap(i=>i.toFlatIds(e))])}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(e=new Set){return e.has(this.id)?this.toReference():(e.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(t=>t.toJSON(e)),methods:this.methods.map(t=>t.toJSON(e)),abstractMethods:this.abstractMethods.map(t=>t.toJSON(e)),extends:this.extends.map(t=>t.toJSON(e))})}toReference(e=J){return{id:this.id+"--"+m.UUID.uuid()+"--ref",type:n.GenericReference,entityId:this.id,version:this.version,entityType:this.type}}toShallowJSON(e=J){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(t=>t.toReference()),methods:this.methods.map(t=>t.toReference()),abstractMethods:this.abstractMethods.map(t=>t.toReference()),extends:this.extends.map(t=>t.toReference())}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.properties.flatMap(i=>i.toFlatJSON(e)),...this.methods.flatMap(i=>i.toFlatJSON(e)),...this.abstractMethods.flatMap(i=>i.toFlatJSON(e))])}toGenerationTarget(){return{id:this.id,type:this.type,name:this.name,description:this.description,static:this.static,abstract:this.abstract,extends:this.extends.map(e=>e.id)}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...this.properties.flatMap(i=>i.toFlatGenerationTarget(e)),...this.methods.flatMap(i=>i.toFlatGenerationTarget(e)),...this.abstractMethods.flatMap(i=>i.toFlatGenerationTarget(e))])}clearErrors(){return this.errors=[],this.properties.forEach(e=>e.clearErrors()),this.methods.forEach(e=>e.clearErrors()),this.abstractMethods.forEach(e=>e.clearErrors()),this}validate(){const e=iW(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){return[...this.errors,...this.properties.flatMap(t=>t.getErrors()),...this.methods.flatMap(t=>t.getErrors()),...this.abstractMethods.flatMap(t=>t.getErrors())]}getShallowErrors(){return this.errors}getAllInteractiveMethods(){const e=[];return e.push(...this.methods),this.extends.filter(i=>i.type===n.BuiltInBaseEntity&&i.interactive||i.type===n.PrimitiveEntity).forEach(i=>{i instanceof Ki&&e.push(...i.getAllInteractiveMethods())}),p(e)}};f(ld,"repository",{APILoad:async(e,...t)=>null});let Qt=ld;function ct(r,a){if(!r)throw new Error("Entity is null");const e=a.get(r.id);switch(r.type){case n.LiteralValue:return e||new Hr(r,a);case n.DefinitionEntity:return e||new nn(r,a);case n.PrimitiveEntity:return e||new Qt(r,a);case n.FunctionDeclaration:return e||new gr(r,a);case n.GlobalEvent:return e||new Fr(r,a);case n.DataType:return e||new $r(r,a);case n.Property:return e||new Ur(r,a);case n.FunctionCall:return e||new en(r,a);case n.Condition:return e||new Zr(r,a);case n.Operation:return e||new Gr(r,a);case n.VariableDeclaration:return e||new Jr(r,a);case n.VariableInstance:return e||new qr(r,a);case n.OutputMap:return e||new zi(r,a);case n.ReturnDeclaration:return e||new ai(r,a);case n.ArgumentDeclaration:return e||new Yr(r,a);case n.InputMap:return e||new Wi(r,a);case n.Project:return e||new m(r);case n.InstalledProject:return e||new Wr(r,a);case n.ActionDescriptor:return e||new Se(r,a);case n.ReturnStatement:return e||new jr(r,a);case n.Loop:return e||new kr(r,a);case n.Search:return e||new Sr(r,a);case n.ValueDescriptor:return e||new mr(r,a);case n.BuiltInBaseEntity:return e||new Ki(r,a);case n.InternalCall:return e||new zr(r,a);case n.ContinueStatement:return e||new Lt(r,a);case n.BreakStatement:return e||new xr(r,a);case n.GenericReference:return a.get(r.entityId);default:throw new Error("Invalid entity type: "+r.type)}}function V(r,a){if(!r)throw new Error("Entity is null");const e=ct(r,a);return e.subscribe(),e}function rW(r,a){if(!r)throw new Error("Entity is null");switch(r.type){case n.LiteralValue:return Hr.fromGenerationTarget(r,a);case n.DefinitionEntity:return nn.fromGenerationTarget(r,a);case n.FunctionDeclaration:return gr.fromGenerationTarget(r,a);case n.GlobalEvent:return Fr.fromGenerationTarget(r,a);case n.DataType:return $r.fromGenerationTarget(r,a);case n.Property:return Ur.fromGenerationTarget(r,a);case n.FunctionCall:return en.fromGenerationTarget(r,a);case n.Condition:return Zr.fromGenerationTarget(r,a);case n.Operation:return Gr.fromGenerationTarget(r,a);case n.VariableDeclaration:return Jr.fromGenerationTarget(r,a);case n.VariableInstance:return qr.fromGenerationTarget(r,a);case n.OutputMap:return zi.fromGenerationTarget(r,a);case n.ReturnDeclaration:return ai.fromGenerationTarget(r,a);case n.ArgumentDeclaration:return Yr.fromGenerationTarget(r,a);case n.InputMap:return Wi.fromGenerationTarget(r,a);case n.InstalledProject:return Wr.fromGenerationTarget(r,a);case n.ReturnStatement:return jr.fromGenerationTarget(r,a);case n.Loop:return kr.fromGenerationTarget(r,a);case n.Search:return Sr.fromGenerationTarget(r,a);case n.ActionDescriptor:return Se.fromGenerationTarget(r,a);case n.ValueDescriptor:return mr.fromGenerationTarget(r,a);case n.InternalCall:return zr.fromGenerationTarget(r,a);case n.ContinueStatement:return Lt.fromGenerationTarget(r,a);case n.BreakStatement:return xr.fromGenerationTarget(r,a);default:throw new Error("Invalid entity type: "+r.type)}}const J={seenEntityMaps:new Map,seenEntities:new Set,timestamp:T().toISOString()};class aw{constructor(){f(this,"initialData")}}const j={cascade:!1},ow={APILoad:async(r,...a)=>null},nW={APICreate:async(r,...a)=>r,APIUpdate:async(r,...a)=>r,APIDelete:async(r,...a)=>r,APIClone:async(r,...a)=>{},APILoadVersion:async(r,a,...e)=>null,...ow};class sW{}class aW extends aw{}class oW{}class lW{}class dW{}class nf{}class uW extends nf{}class pW extends nf{}class cW{}class Ir{static initReadsValue(a){if(a.initialData.readsValue&&a.initialData.readsValue.type!==n.GenericReference)a.readsValue=V(a.initialData.readsValue,a.project);else if(a.initialData.readsValue&&a.initialData.readsValue.type===n.GenericReference){const e=mi(a.initialData.readsValue,a.project);e&&(a.readsValue=e)}if(a.readsValue){if(tt.includes(a.readsValue.type)){let e=a.parent;dt.includes(e.type)||(e=e.parent);const t=a.type===n.InputMap&&a.parent.type===n.Loop;t&&(e=a.parent.parent),a.readsValue.setParent(e,null),a.readsValue.initChildren(null),!t&&e.detachedChildren.includes(a)?e.replaceDetachedChild(a,a.readsValue):t||e.subscribeDetachedChild(a.readsValue)}a.readsValue.addValueReader(a,null)}return a.readsValue}static hydrateReadsValue(a){if(a.initialData.readsValue&&a.initialData.readsValue.type!==n.GenericReference)a.readsValue=V(a.initialData.readsValue,a.project);else if(a.initialData.readsValue&&a.initialData.readsValue.type===n.GenericReference){const e=mi(a.initialData.readsValue,a.project);e&&(a.readsValue=e)}if(a.readsValue){if(tt.includes(a.readsValue.type)){let e=a.parent;dt.includes(e.type)||(e=e.parent);const t=a.type===n.InputMap&&a.parent.type===n.Loop;t&&(e=a.parent.parent),a.readsValue.setParent(e,null),!t&&e.detachedChildren.includes(a)?e.replaceDetachedChild(a,a.readsValue):t||e.subscribeDetachedChild(a.readsValue)}a.readsValue.addValueReader(a,null)}return a.readsValue}}class Fa{static initWritesValues(a,e){const t=a.initialData.writesValues.reduce((s,l)=>{if(l.type===n.GenericReference||a.writesValues.some(d=>d.id===l.id))return s;const o=V(l,a.project);return o.setValueWriter(a,null),tt.includes(o.type)&&(o.setParent(e,null),o.initChildren(null)),[...s,o]},[]),i=[...a.writesValues];return a.writesValues=p([...i,...t]),a.writesValues}}class fW{}const re=class re extends at{constructor(e){super(e);f(this,"initialData");f(this,"id");f(this,"type",n.Project);f(this,"name",null);f(this,"description",null);f(this,"x");f(this,"y");f(this,"entities",[]);f(this,"projects",[]);f(this,"functions",[]);f(this,"events",[]);f(this,"variableDeclarations",[]);f(this,"variableInstances",[]);f(this,"conditions",[]);f(this,"operations",[]);f(this,"functionCalls",[]);f(this,"loops",[]);f(this,"searches",[]);f(this,"primitives",[]);f(this,"builtInBaseEntities",[]);f(this,"operationDeclarations",[]);f(this,"globalEventActionDescriptors",[]);f(this,"loopDeclarations",[]);f(this,"loopDeclarationsBodies",[]);f(this,"conditionDeclarations",[]);f(this,"valueDescriptors",[]);f(this,"dataTypes",[]);f(this,"project");f(this,"instances",{});f(this,"builtInInstances",{});f(this,"deletedInstances",{});f(this,"errors",[]);f(this,"references",[]);f(this,"history",[]);f(this,"detachedDependents",{});f(this,"knownVersions",null);f(this,"activeVersion",!1);f(this,"initialized",!1);f(this,"startedInitialization",!1);f(this,"onCloseChangeSetCallback",null);this.initialData=e,this.id=e.id,this.name=e.name,this.description=e.description,this.x=0,this.y=0,this.instances[this.id]=this;try{(!re.UUID||re.UUID.isBackup)&&(re.UUID=Zo==null?void 0:Zo()),re.UUID||(re.UUID={isBackup:!0,uuid:()=>Math.random().toString(36).substring(2,15)+Math.random().toString(36).substring(2,15),fromUUID:t=>t})}catch(t){console.error("Error initializing UUID module",t),re.UUID={isBackup:!0,uuid:()=>Math.random().toString(36).substring(2,15)+Math.random().toString(36).substring(2,15),fromUUID:i=>i}}}static injectUUIDModule(e){re.UUID=e}static new(){return{id:re.UUID.uuid(),version:re.UUID.uuid(),createdAt:T().toISOString(),author:re.sessionAuthor,previousVersion:null,deleted:!1,type:n.Project,name:"",description:"",entities:[],functions:[],events:[],projects:[],variableDeclarations:[],variableInstances:[],conditions:[],operations:[],functionCalls:[],loops:[],searches:[]}}static validateGenerationTarget(e,t){let i=JSON.parse(JSON.stringify(e));const s=[];return s.push(...ut(i)),{errors:s,modifiedData:i}}async closePendingChangeSets(){const e=this.history.find(t=>t.dirty&&!t.open);e&&await this.closeChangeSet(e)}async onCloseChangeSet(e){this.onCloseChangeSetCallback=e,await this.closePendingChangeSets()}async closeChangeSet(e){const t=this.history.findIndex(l=>l.id===e.id),i=this.history.slice(0,t),s=i[i.length-1];if(!(s!=null&&s.dirty)&&this.onCloseChangeSetCallback){(await this.onCloseChangeSetCallback(e)).success&&(e.dirty=!1,this.closePendingChangeSets());return}}toLatestChangeSet(e,t,i,s=!1,l="here-this"){if(!this.history.length)return new A(this,e,t,i,s,l);const o=this.history[this.history.length-1];return o.open?o:this.addChangeSet(new A(this,e,t,i,s,l))}addChangeSet(e){if(!this.history.length)return this.history.push(e),e;const t=this.history.find(l=>l.id===(e==null?void 0:e.id));if(t)return t;const i=this.history.find(l=>l.open);if(i)throw console.warn("Previous still open: ",i),console.warn("New change set: ",e),new Error(`There is already an open change-set with id '${i.id}'.`);const s=this.history.findIndex(l=>T(e==null?void 0:e.timestamp).isBefore(T(l==null?void 0:l.timestamp)));return s===-1?this.history.push(e):this.history.splice(s,0,e),e}discardChangeSet(e){const t=this.history.findIndex(i=>i.id===(e==null?void 0:e.id));return t!==-1&&this.history.splice(t,1),this}undo(){const e=[],t=[],i=[],s=[];return{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}redo(){const e=[],t=[],i=[],s=[];return{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}async inject(...e){return await Promise.all(e.map(t=>new Promise(async i=>{await t.init(this),i(null)}))),this}validateGeneratedUpdate(e){return{errors:[],modifiedData:e}}subscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]||(this.detachedDependents[t.entity.id]=t)}),this}syncDependents(e=this.project.addChangeSet(new A(this.project,re.sessionAuthor,T().toISOString(),this,!0,"sync-dependents"))){const t=[],i=[],s=[],l=[];return Object.values(this.detachedDependents).forEach(o=>{const d=o.entity.afterAllChildrenInitialized(e);t.push(...d.updated),i.push(...d.added),s.push(...d.removed),l.push(...d.affected)}),e==null||e.attemptAutoclose("sync-dependents",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}onDetachedDependencyRestored(e,t,i){const s=[],l=[],o=[],d=[];return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}subscribeToDependencies(){return this}increaseVersion(e){if(e&&!T(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&T(e).isSame(T(this.createdAt))?this:(this.previousVersion=this.version,this.version=re.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new re(this);return e.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,e):new Map([[this.version,e]]),e.entities=this.entities,e.projects=this.projects,e.functions=this.functions,e.events=this.events,e.variableDeclarations=this.variableDeclarations,e.variableInstances=this.variableInstances,e.conditions=this.conditions,e.operations=this.operations,e.functionCalls=this.functionCalls,e.loops=this.loops,e.searches=this.searches,this}recursiveCaptureUpstreamVersions(e){const t=[],i=[],s=[],l=[];return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}async restoreVersion(e){var d;const t=[],i=[],s=[],l=[];if(this.version===e)return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this};if(!this.knownVersions){const u=new Map;for(const[y,c]of this.knownVersions||new Map){if(u.set(y,c),c.activeVersion=!1,c.knownVersions)for(const[I,E]of c.knownVersions)u.set(I,E);c.knownVersions=null}}let o=(d=this.knownVersions)==null?void 0:d.get(e);if(!o){const u=await this.APILoadVersion({},e);if(!u)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new re(u)}return this.metaSync(o.toShallowJSON(),null),this.entities=o.entities,this.projects=o.projects,this.functions=o.functions,this.events=o.events,this.variableDeclarations=o.variableDeclarations,this.variableInstances=o.variableInstances,this.conditions=o.conditions,this.operations=o.operations,this.functionCalls=o.functionCalls,this.loops=o.loops,this.searches=o.searches,{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}hydrateAncestors(){const e=[],t=[],i=[],s=[];return{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}afterAllChildrenInitialized(e=null){const t=[],i=[],s=[],l=[];return this.initialized=!0,this.captureVersion(),this.validate(),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addSelfToProject(e){const t=[],i=[],s=[],l=[];return this.subscribe(),this.subscribeToDependencies(),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}get instancesList(){return Object.values(this.instances)}isOperationDeclaration(e){return this.operationDeclarations.includes(e)}isGlobalEventActionDescriptor(e){return this.globalEventActionDescriptors.includes(e)}isLoopDeclaration(e){return this.loopDeclarations.includes(e)}isConditionDeclaration(e){return this.conditionDeclarations.includes(e)}initChildren(e=this.project.addChangeSet(new A(this.project,re.sessionAuthor,T().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.entities=this.initialData.entities.map(t=>{const i=V(t,this);return i.setParent(this,null),i.initChildren(e),i}),this.projects=this.initialData.projects.map(t=>{const i=V(t,this);return i.setParent(this,null),i.initChildren(e),i}),this.variableDeclarations=this.initialData.variableDeclarations.map(t=>{const i=V(t,this);return i.setParent(this,null),i.initChildren(e),i}),this.variableInstances=this.initialData.variableInstances.map(t=>{const i=V(t,this);return i.setParent(this,null),i.initChildren(e),i}),this.conditions=this.initialData.conditions.map(t=>{const i=V(t,this);return i.setParent(this,null),i.initChildren(e),i}),this.operations=this.initialData.operations.map(t=>{const i=V(t,this);return i.setParent(this,null),i.initChildren(e),i}),this.functions=this.initialData.functions.map(t=>{const i=V(t,this);return i.setParent(this,null),i.initChildren(e),i}),this.events=this.initialData.events.map(t=>{const i=V(t,this);return i.setParent(this,null),i.initChildren(e),i}),this.functionCalls=this.initialData.functionCalls.map(t=>{const i=V(t,this);return i.setParent(this,null),i.initChildren(e),i}),this.loops=this.initialData.loops.map(t=>{const i=V(t,this);return i.setParent(this,null),i.initChildren(e),i}),this.searches=this.initialData.searches.map(t=>{const i=V(t,this);return i.setParent(this,null),i.initChildren(e),i}),this.attachOrphanReferences(),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this)}subscribeInstance(e){return(!this.instances[e.id]||this.instances[e.id]!==e)&&(this.instances[e.id]=e),this}subscribeDeletedInstance(e){return(!this.deletedInstances[e.id]||this.deletedInstances[e.id]!==e)&&(this.deletedInstances[e.id]=e),this}subscribeBuiltInInstance(e){return(!this.builtInInstances[e.id]||this.builtInInstances[e.id]!==e)&&(this.builtInInstances[e.id]=e),this}subscribe(){return this}unsubscribe(){return this}unsubscribeInstance(e){return delete this.instances[e.id],this}unsubscribeDeletedInstance(e){return delete this.deletedInstances[e.id],this}findSubscribedBuiltInInstance(e){return this.builtInInstances[e.id]||null}get(e){return this.instances[e]||this.builtInInstances[e]||null}getDeleted(e){return this.deletedInstances[e]||null}getManaged(e){return this.getBuiltIn(e)?null:this.instances[e]||null}getBuiltIn(e){return this.builtInInstances[e]||null}findSubscribedInstanceFromReference(e){return this.instances[e.entityId]||null}findSubscribedBuiltInInstanceFromReference(e){return this.builtInInstances[e.entityId]||null}metaSync(e,t=this.project.addChangeSet(new A(this.project,re.sessionAuthor,T().toISOString(),this,!0,"meta-sync"))){const i=pt(this,e),s=this.toMeta();return this.name=e.name!==void 0?e.name:s.name,this.description=e.description!==void 0?e.description:s.description,this.x=e.x||s.x,this.y=e.y||s.y,super.metaSync(e),e.deleted===!0&&!s.deleted?t==null||t.add(this,b.Removed):e.deleted===!1&&s.deleted?t==null||t.add(this,b.Added):i&&(t==null||t.add(this,b.Updated)),t==null||t.attemptAutoclose("meta-sync",this.id),this}async APILoad(e=j,...t){return await re.repository.APILoad(this.id,...t),this}async APICreate(e=j,...t){return await re.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=j,...t){return await re.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=j,...t){return await re.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=j,...t){return await re.repository.APIClone(this.id,...t),this}async APILoadVersion(e=j,t,...i){return await re.repository.APILoadVersion(this.id,t,...i)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new A(this.project,re.sessionAuthor,T().toISOString(),this,!0,"remove-entity"))){return{added:[],updated:[],removed:[],affected:[],self:this}}restore({}={},e=this.project.addChangeSet(new A(this.project,re.sessionAuthor,T().toISOString(),this,!0,"restore-entity"))){return{added:[],updated:[],removed:[],affected:[],self:this}}getAllBuiltInIds(){const e=new Set;return[...this.primitives.flatMap(t=>t.toFlatIds(e)),...this.builtInBaseEntities.flatMap(t=>t.toFlatIds(e)),...this.operationDeclarations.flatMap(t=>t.toFlatIds(e)),...this.globalEventActionDescriptors.flatMap(t=>t.toFlatIds(e)),...this.loopDeclarations.flatMap(t=>t.toFlatIds(e)),...this.conditionDeclarations.flatMap(t=>t.toFlatIds(e)),...this.valueDescriptors.flatMap(t=>t.toFlatIds(e)),...this.dataTypes.flatMap(t=>t.toFlatIds(e))]}getAllBuiltIn(){const e=new Set;return[...this.primitives.flatMap(t=>t.toFlat(e)),...this.builtInBaseEntities.flatMap(t=>t.toFlat(e)),...this.operationDeclarations.flatMap(t=>t.toFlat(e)),...this.globalEventActionDescriptors.flatMap(t=>t.toFlat(e)),...this.loopDeclarations.flatMap(t=>t.toFlat(e)),...this.conditionDeclarations.flatMap(t=>t.toFlat(e)),...this.valueDescriptors.flatMap(t=>t.toFlat(e)),...this.dataTypes.flatMap(t=>t.toFlat(e))]}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.entities.flatMap(i=>i.toFlat(e)),...this.functions.flatMap(i=>i.toFlat(e)),...this.events.flatMap(i=>i.toFlat(e)),...this.projects.flatMap(i=>i.toFlat(e)),...this.variableDeclarations.flatMap(i=>i.toFlat(e)),...this.variableInstances.flatMap(i=>i.toFlat(e)),...this.conditions.flatMap(i=>i.toFlat(e)),...this.operations.flatMap(i=>i.toFlat(e)),...this.functionCalls.flatMap(i=>i.toFlat(e)),...this.loops.flatMap(i=>i.toFlat(e)),...this.searches.flatMap(i=>i.toFlat(e))])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.entities.flatMap(i=>i.toFlatIds(e)),...this.functions.flatMap(i=>i.toFlatIds(e)),...this.events.flatMap(i=>i.toFlatIds(e)),...this.projects.flatMap(i=>i.toFlatIds(e)),...this.variableDeclarations.flatMap(i=>i.toFlatIds(e)),...this.variableInstances.flatMap(i=>i.toFlatIds(e)),...this.conditions.flatMap(i=>i.toFlatIds(e)),...this.operations.flatMap(i=>i.toFlatIds(e)),...this.functionCalls.flatMap(i=>i.toFlatIds(e)),...this.loops.flatMap(i=>i.toFlatIds(e)),...this.searches.flatMap(i=>i.toFlatIds(e))])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,description:this.description,type:this.type,name:this.name}}toJSON(e=new Set){return e.has(this.id)?this.toReference():(e.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,entities:this.entities.map(t=>t.toJSON(e)),variableDeclarations:this.variableDeclarations.map(t=>t.toJSON(e)),variableInstances:this.variableInstances.map(t=>t.toJSON(e)),conditions:this.conditions.map(t=>t.toJSON(e)),operations:this.operations.map(t=>t.toJSON(e)),loops:this.loops.map(t=>t.toJSON(e)),searches:this.searches.map(t=>t.toJSON(e)),functions:this.functions.map(t=>t.toJSON(e)),events:this.events.map(t=>t.toJSON(e)),projects:this.projects.map(t=>t.toJSON(e)),functionCalls:this.functionCalls.map(t=>t.toJSON(e))})}toJSONClone(e={uuidStrategy:"uuid"}){const t=new Map,i=new Set,s=this.getAllBuiltInIds();return Object.keys(this.instances).forEach(l=>{if(s.includes(l)){t.set(l,l);return}t.set(l,re.UUID.uuid())}),i.add(this.id),{id:t.get(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,entities:this.entities.map(l=>l.toJSONClone({...e,seenEntityMaps:t,seenEntities:i,newId:null})),projects:this.projects.map(l=>l.toJSONClone({...e,seenEntityMaps:t,seenEntities:i,newId:null})),variableDeclarations:this.variableDeclarations.map(l=>l.toJSONClone({...e,seenEntityMaps:t,seenEntities:i,newId:null})),variableInstances:this.variableInstances.map(l=>l.toJSONClone({...e,seenEntityMaps:t,seenEntities:i,newId:null})),conditions:this.conditions.map(l=>l.toJSONClone({...e,seenEntityMaps:t,seenEntities:i,newId:null})),operations:this.operations.map(l=>l.toJSONClone({...e,seenEntityMaps:t,seenEntities:i,newId:null})),functions:this.functions.map(l=>l.toJSONClone({...e,seenEntityMaps:t,seenEntities:i,newId:null})),events:this.events.map(l=>l.toJSONClone({...e,seenEntityMaps:t,seenEntities:i,newId:null})),functionCalls:this.functionCalls.map(l=>l.toJSONClone({...e,seenEntityMaps:t,seenEntities:i,newId:null})),loops:this.loops.map(l=>l.toJSONClone({...e,seenEntityMaps:t,seenEntities:i,newId:null})),searches:this.searches.map(l=>l.toJSONClone({...e,seenEntityMaps:t,seenEntities:i,newId:null}))}}toReference(e=J){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+re.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=J){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,entities:this.entities.map(s=>s.toReference(e)),functions:this.functions.map(s=>s.toReference(e)),events:this.events.map(s=>s.toReference(e)),projects:this.projects.map(s=>s.toReference(e)),variableDeclarations:this.variableDeclarations.map(s=>s.toReference(e)),variableInstances:this.variableInstances.map(s=>s.toReference(e)),conditions:this.conditions.map(s=>s.toReference(e)),operations:this.operations.map(s=>s.toReference(e)),functionCalls:this.functionCalls.map(s=>s.toReference(e)),loops:this.loops.map(s=>s.toReference(e)),searches:this.searches.map(s=>s.toReference(e))}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.entities.flatMap(i=>i.toFlatJSON(e)),...this.functions.flatMap(i=>i.toFlatJSON(e)),...this.events.flatMap(i=>i.toFlatJSON(e)),...this.projects.flatMap(i=>i.toFlatJSON(e)),...this.variableDeclarations.flatMap(i=>i.toFlatJSON(e)),...this.variableInstances.flatMap(i=>i.toFlatJSON(e)),...this.conditions.flatMap(i=>i.toFlatJSON(e)),...this.operations.flatMap(i=>i.toFlatJSON(e)),...this.functionCalls.flatMap(i=>i.toFlatJSON(e)),...this.loops.flatMap(i=>i.toFlatJSON(e)),...this.searches.flatMap(i=>i.toFlatJSON(e))])}toGenerationTarget(){return{id:this.id,type:this.type,name:this.name,description:this.description}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[...this.entities.flatMap(i=>i.toFlatGenerationTarget(e)),...this.functions.flatMap(i=>i.toFlatGenerationTarget(e)),...this.events.flatMap(i=>i.toFlatGenerationTarget(e)),...this.projects.flatMap(i=>i.toFlatGenerationTarget(e)),...this.variableDeclarations.flatMap(i=>i.toFlatGenerationTarget(e)),...this.variableInstances.flatMap(i=>i.toFlatGenerationTarget(e)),...this.conditions.flatMap(i=>i.toFlatGenerationTarget(e)),...this.operations.flatMap(i=>i.toFlatGenerationTarget(e)),...this.functionCalls.flatMap(i=>i.toFlatGenerationTarget(e)),...this.loops.flatMap(i=>i.toFlatGenerationTarget(e)),...this.searches.flatMap(i=>i.toFlatGenerationTarget(e))])}clearErrors(){return this.errors=[],this.entities.forEach(e=>e.clearErrors()),this.projects.forEach(e=>e.clearErrors()),this.functions.forEach(e=>e.clearErrors()),this.events.forEach(e=>e.clearErrors()),this.variableDeclarations.forEach(e=>e.clearErrors()),this.variableInstances.forEach(e=>e.clearErrors()),this.conditions.forEach(e=>e.clearErrors()),this.operations.forEach(e=>e.clearErrors()),this.functionCalls.forEach(e=>e.clearErrors()),this.loops.forEach(e=>e.clearErrors()),this.searches.forEach(e=>e.clearErrors()),this}validate(){const e=fq(),t=this.toJSON();return e.safeParse(t),this.validateChildren(),{success:!0,error:null,data:t}}validateChildren(){this.entities.forEach(e=>e.validate()),this.projects.forEach(e=>e.validate()),this.functions.forEach(e=>e.validate()),this.events.forEach(e=>e.validate()),this.variableDeclarations.forEach(e=>e.validate()),this.variableInstances.forEach(e=>e.validate()),this.conditions.forEach(e=>e.validate()),this.operations.forEach(e=>e.validate()),this.functionCalls.forEach(e=>e.validate()),this.loops.forEach(e=>e.validate()),this.searches.forEach(e=>e.validate())}getErrors(){return[...this.errors,...this.entities.flatMap(t=>t.getErrors()),...this.projects.flatMap(t=>t.getErrors()),...this.functions.flatMap(t=>t.getErrors()),...this.events.flatMap(t=>t.getErrors()),...this.variableDeclarations.flatMap(t=>t.getErrors()),...this.variableInstances.flatMap(t=>t.getErrors()),...this.conditions.flatMap(t=>t.getErrors()),...this.operations.flatMap(t=>t.getErrors()),...this.functionCalls.flatMap(t=>t.getErrors()),...this.loops.flatMap(t=>t.getErrors()),...this.searches.flatMap(t=>t.getErrors())]}getShallowErrors(){return this.errors}clone(){return this}getDefinitionEntity(e){return this.entities.find(t=>t.id===e)||null}addDefinitionEntityFromTransfer(e){const t=V(e,this);return this.addDefinitionEntity(t),t}addDefinitionEntity(e){return this.entities.includes(e)||this.entities.push(e),e}addFunctionDeclarationFromTransfer(e){const t=V(e,this);return this.addFunctionDeclaration(t),t}addFunctionDeclaration(e){return this.functions.includes(e)||this.functions.push(e),e}addFunctionCallFromTransfer(e){const t=V(e,this);return this.addFunctionCall(t),t}addFunctionCall(e){return this.functionCalls.includes(e)||this.functionCalls.push(e),e}addVariableDeclarationFromTransfer(e){const t=V(e,this);return this.addVariableDeclaration(t),t}addVariableDeclaration(e){return this.variableDeclarations.includes(e)||this.variableDeclarations.push(e),e}addVariableInstanceFromTransfer(e){const t=V(e,this);return this.addVariableInstance(t),t}addVariableInstance(e){return this.variableInstances.includes(e)||this.variableInstances.push(e),e}addInstalledProjectFromTransfer(e){const t=V(e,this);return this.addInstalledProject(t),this}addInstalledProject(e){return this.projects.includes(e)||this.projects.push(e),this}addGlobalEventFromTransfer(e){const t=V(e,this);return this.addGlobalEvent(t),this}addGlobalEvent(e){return this.events.includes(e)||this.events.push(e),this}addConditionFromTransfer(e){const t=V(e,this);return this.addCondition(t),this}addCondition(e){return this.conditions.includes(e)||this.conditions.push(e),this}addOperationFromTransfer(e){const t=V(e,this);return this.addOperation(t),this}addOperation(e){return this.operations.includes(e)||this.operations.push(e),this}addLoopFromTransfer(e){const t=V(e,this);return this.addLoop(t),this}addLoop(e){return this.loops.includes(e)||this.loops.push(e),this}addSearchFromTransfer(e){const t=V(e,this);return this.addSearch(t),this}addSearch(e){return this.searches.includes(e)||this.searches.push(e),this}removeDefinitionEntity(e){const t=this.entities.findIndex(i=>i.id===e.id);if(t>-1){const i=this.entities[t];return this.entities.splice(t,1),i}return null}removeFunctionDeclaration(e){const t=this.functions.findIndex(i=>i.id===e.id);if(t>-1){const i=this.functions[t];return this.functions.splice(t,1),i}return null}removeExternalProject(e){const t=this.projects.findIndex(i=>i.id===e.id);if(t>-1){const i=this.projects[t];return this.projects.splice(t,1),i}return null}removeGlobalEvent(e){const t=this.events.findIndex(i=>i.id===e.id);if(t>-1){const i=this.events[t];return this.events.splice(t,1),i}return null}removeTopLevelVariableDeclaration(e){if(e.type!==n.VariableDeclaration)return null;const t=this.variableDeclarations.findIndex(i=>i.id===e.id);if(t>-1){const i=this.variableDeclarations[t];return this.variableDeclarations.splice(t,1),i}return null}getEntryPoints(){return[...this.functions,...this.events,...this.entities.flatMap(t=>t.methods)]}getTerminationStatements(){return[...this.getEntryPoints().reduce((t,i)=>{const s=Je(i);return[...t,...s.filter(l=>l.type===n.ReturnStatement||l.type===n.ContinueStatement||l.type===n.BreakStatement)]},[])]}getFunctionDeclaration(e){return this.functions.find(t=>t.id===e)||null}getConditions(){return[...this.conditions,...this.getEntryPoints().reduce((t,i)=>{const s=Je(i);return[...t,...s.filter(l=>l.type===n.Condition)]},[]),...this.functionCalls.reduce((t,i)=>{const s=Je(i);return[...t,...s.filter(l=>l.type===n.Condition)]},[]),...this.operations.reduce((t,i)=>{const s=Je(i);return[...t,...s.filter(l=>l.type===n.Condition)]},[]),...this.loops.reduce((t,i)=>{const s=Je(i);return[...t,...s.filter(l=>l.type===n.Condition)]},[]),...this.searches.reduce((t,i)=>{const s=Je(i);return[...t,...s.filter(l=>l.type===n.Condition)]},[])]}getOperations(){return[...this.operations,...this.getEntryPoints().reduce((t,i)=>{const s=Je(i);return[...t,...s.filter(l=>l.type===n.Operation)]},[]),...this.functionCalls.reduce((t,i)=>{const s=Je(i);return[...t,...s.filter(l=>l.type===n.Operation)]},[]),...this.conditions.reduce((t,i)=>{const s=Je(i);return[...t,...s.filter(l=>l.type===n.Operation)]},[]),...this.loops.reduce((t,i)=>{const s=Je(i);return[...t,...s.filter(l=>l.type===n.Operation)]},[]),...this.searches.reduce((t,i)=>{const s=Je(i);return[...t,...s.filter(l=>l.type===n.Operation)]},[])]}getFunctionCalls(){return[...this.functionCalls,...this.getEntryPoints().reduce((t,i)=>{const s=Je(i);return[...t,...s.filter(l=>l.type===n.FunctionCall)]},[]),...this.conditions.reduce((t,i)=>{const s=Je(i);return[...t,...s.filter(l=>l.type===n.FunctionCall)]},[]),...this.operations.reduce((t,i)=>{const s=Je(i);return[...t,...s.filter(l=>l.type===n.FunctionCall)]},[]),...this.loops.reduce((t,i)=>{const s=Je(i);return[...t,...s.filter(l=>l.type===n.FunctionCall)]},[]),...this.searches.reduce((t,i)=>{const s=Je(i);return[...t,...s.filter(l=>l.type===n.FunctionCall)]},[])]}getVariables(){return[...this.variableDeclarations,...this.getEntryPoints().reduce((t,i)=>{const s=Ye(i);return[...t,...s]},[]),...this.functionCalls.reduce((t,i)=>{const s=Ye(i);return[...t,...s]},[]),...this.conditions.reduce((t,i)=>{const s=Ye(i);return[...t,...s]},[]),...this.operations.reduce((t,i)=>{const s=Ye(i);return[...t,...s]},[]),...this.loops.reduce((t,i)=>{const s=Ye(i);return[...t,...s]},[]),...this.searches.reduce((t,i)=>{const s=Ye(i);return[...t,...s]},[])]}getVariableInstances(){return[...this.variableInstances,...this.getEntryPoints().reduce((t,i)=>{const l=Ye(i).filter(o=>o.type===n.VariableInstance);return[...t,...l]},[]),...this.functionCalls.reduce((t,i)=>{const l=Ye(i).filter(o=>o.type===n.VariableInstance);return[...t,...l]},[]),...this.conditions.reduce((t,i)=>{const l=Ye(i).filter(o=>o.type===n.VariableInstance);return[...t,...l]},[]),...this.operations.reduce((t,i)=>{const l=Ye(i).filter(o=>o.type===n.VariableInstance);return[...t,...l]},[]),...this.loops.reduce((t,i)=>{const l=Ye(i).filter(o=>o.type===n.VariableInstance);return[...t,...l]},[]),...this.searches.reduce((t,i)=>{const l=Ye(i).filter(o=>o.type===n.VariableInstance);return[...t,...l]},[])]}getVariableDeclarations(){return p([...this.variableDeclarations,...this.getEntryPoints().reduce((t,i)=>{const l=Ye(i).filter(o=>o.type===n.VariableDeclaration);return[...t,...l]},[]),...this.functionCalls.reduce((t,i)=>{const l=Ye(i).filter(o=>o.type===n.VariableDeclaration);return[...t,...l]},[]),...this.conditions.reduce((t,i)=>{const l=Ye(i).filter(o=>o.type===n.VariableDeclaration);return[...t,...l]},[]),...this.operations.reduce((t,i)=>{const l=Ye(i).filter(o=>o.type===n.VariableDeclaration);return[...t,...l]},[]),...this.loops.reduce((t,i)=>{const l=Ye(i).filter(o=>o.type===n.VariableDeclaration);return[...t,...l]},[]),...this.searches.reduce((t,i)=>{const l=Ye(i).filter(o=>o.type===n.VariableDeclaration);return[...t,...l]},[])])}getLoops(){return[...this.loops,...this.getEntryPoints().reduce((t,i)=>{const s=Je(i);return[...t,...s.filter(l=>l.type===n.Loop)]},[]),...this.functionCalls.reduce((t,i)=>{const s=Je(i);return[...t,...s.filter(l=>l.type===n.Loop)]},[]),...this.conditions.reduce((t,i)=>{const s=Je(i);return[...t,...s.filter(l=>l.type===n.Loop)]},[]),...this.operations.reduce((t,i)=>{const s=Je(i);return[...t,...s.filter(l=>l.type===n.Loop)]},[]),...this.searches.reduce((t,i)=>{const s=Je(i);return[...t,...s.filter(l=>l.type===n.Loop)]},[])]}getSearches(){return[...this.searches,...this.getEntryPoints().reduce((t,i)=>{const s=Je(i);return[...t,...s.filter(l=>l.type===n.Search)]},[]),...this.functionCalls.reduce((t,i)=>{const s=Je(i);return[...t,...s.filter(l=>l.type===n.Search)]},[]),...this.conditions.reduce((t,i)=>{const s=Je(i);return[...t,...s.filter(l=>l.type===n.Search)]},[]),...this.operations.reduce((t,i)=>{const s=Je(i);return[...t,...s.filter(l=>l.type===n.Search)]},[]),...this.loops.reduce((t,i)=>{const s=Je(i);return[...t,...s.filter(l=>l.type===n.Search)]},[])]}attachOrphanReferences(){const e=this.getVariableInstances(),t=this.getVariableDeclarations();return e.forEach(i=>{if(!i.declaration){const s=i.initialData,l=s.declaration.entityId||s.declaration.id,o=t.find(d=>d.id===l);o&&i.setDeclaration(o)}}),this}getBuiltInPersistedEntity(){return this.builtInBaseEntities.find(e=>e.name===z.PERSISTED_ENTITY)||null}};f(re,"sessionAuthor","1"),f(re,"UUID",{isBackup:!0,uuid:()=>Math.random().toString(36).substring(2,15)+Math.random().toString(36).substring(2,15),fromUUID:e=>e}),f(re,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>e,APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...i)=>null}),f(re,"type",n.Project),f(re,"USER_MANAGED_PARENT_TYPES",[]),f(re,"PARENT_TYPES",[...re.USER_MANAGED_PARENT_TYPES]),f(re,"MUTABLE_BASE_PROPERTIES",["name","description"]),f(re,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),f(re,"BASE_PROPERTIES",[...re.MUTABLE_BASE_PROPERTIES,...re.INMUTABLE_BASE_PROPERTIES]),f(re,"MUTABLE_META_PROPERTIES",[...re.MUTABLE_BASE_PROPERTIES,"x","y"]),f(re,"INMUTABLE_META_PROPERTIES",[...re.INMUTABLE_BASE_PROPERTIES]),f(re,"META_PROPERTIES",[...re.MUTABLE_META_PROPERTIES,...re.INMUTABLE_META_PROPERTIES]),f(re,"MUTABLE_UPSTREAM_PROPERTIES",[]),f(re,"INMUTABLE_UPSTREAM_PROPERTIES",["primitives","builtInBaseEntities","operationDeclarations","globalEventActionDescriptors","loopDeclarations","builtInInstances"]),f(re,"UPSTREAM_PROPERTIES",[...re.MUTABLE_UPSTREAM_PROPERTIES,...re.INMUTABLE_UPSTREAM_PROPERTIES]),f(re,"MUTABLE_DOWNSTREAM_PROPERTIES",["entities","projects","functions","events","variableDeclarations","variableInstances","conditions","operations","functionCalls","loops","searches"]),f(re,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),f(re,"DOWNSTREAM_PROPERTIES",[...re.MUTABLE_DOWNSTREAM_PROPERTIES,...re.INMUTABLE_DOWNSTREAM_PROPERTIES]),f(re,"PROPERTIES",[...re.META_PROPERTIES,...re.UPSTREAM_PROPERTIES,...re.DOWNSTREAM_PROPERTIES]);let m=re;var lw=(r=>(r.PersistChangeSet="persist-change-set",r.CreateSingle="create-single",r.CreateBulk="create-bulk",r.CreateSingleNested="create-single-nested",r.CreateBulkNested="create-bulk-nested",r.Update="update",r.Clone="clone",r.Delete="delete",r.Load="load",r.LoadNested="load-nested",r.LoadVersion="load-version",r))(lw||{});class dw extends Se{constructor(e){super(Oi,e);f(this,"id",Xe.Parallel);f(this,"name",Xe.Parallel);f(this,"description","Execute a list of actions one after the other");f(this,"version","1");f(this,"autoexecutable",!0);f(this,"initialData",Oi);f(this,"type",n.ActionDescriptor);f(this,"inputs",[]);f(this,"outputs",[]);f(this,"error",null);f(this,"project");this.project=e,this.inputs=Oi.inputs.map(t=>{const i=V(t,this.project);return i.setParent(this,null),i.initChildren(null),i}),this.outputs=Oi.outputs.map(t=>{const i=V(t,this.project);return i.setParent(this,null),i.initChildren(null),i}),this.error=Oi.error?V(Oi.error,this.project):null}}class uw extends Se{constructor(e){super(Jt,e);f(this,"id",Jt.id);f(this,"name",Jt.name);f(this,"description",Jt.description);f(this,"version",Jt.version);f(this,"autoexecutable",!1);f(this,"initialData",Jt);f(this,"type",n.ActionDescriptor);f(this,"inputs",[]);f(this,"outputs",[]);f(this,"error",null);f(this,"project");this.project=e,this.inputs=Jt.inputs.map(t=>{const i=V(t,this.project);return i.setParent(this,null),i.initChildren(null),i}),this.outputs=Jt.outputs.map(t=>{const i=V(t,this.project);return i.setParent(this,null),i.initChildren(null),i}),this.error=Jt.error?V(Jt.error,this.project):null}}class pw extends Se{constructor(e){super(nr,e);f(this,"id",Xe.Sequential);f(this,"name",Xe.Sequential);f(this,"description","Execute a list of actions one after the other");f(this,"version","1");f(this,"autoexecutable",!0);f(this,"initialData",nr);f(this,"type",n.ActionDescriptor);f(this,"inputs",[]);f(this,"outputs",[]);f(this,"error",null);f(this,"project");this.project=e,this.inputs=nr.inputs.map(t=>{const i=V(t,this.project);return i.setParent(this,null),i.initChildren(null),i}),this.outputs=nr.outputs.map(t=>{const i=V(t,this.project);return i.setParent(this,null),i.initChildren(null),i}),this.error=nr.error?V(nr.error,this.project):null}}class yW extends Se{constructor(a){super(Vs,a)}}class hW extends Se{constructor(a){super(on,a)}}class mW extends Se{constructor(e){super(ln,e);f(this,"autoexecutable",!0)}getEntityToMatchInputMap(e){return e.inputs.find(t=>{var i;return((i=t.declaration)==null?void 0:i.id)===k.operation[Qe.Validate].inputs.entityToMatch.id})||null}getDataToValidateInputMap(e){return e.inputs.find(t=>{var i;return((i=t.declaration)==null?void 0:i.id)===k.operation[Qe.Validate].inputs.dataToValidate.id})||null}getOutputDataOutputMap(e){return e.outputs.find(t=>{var i;return((i=t.declaration)==null?void 0:i.id)===k.operation[Qe.Validate].outputs.outputEntity.id})||null}getEntityToMatch(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"get-entity-to-match-validate-data"))){let i=null;if(e.readsValue){const l=e.readsValue.getDataType(t);l&&l.entity&&l.entity.type===n.DefinitionEntity&&(i=l.entity)}const s=e.getDefaultValue();return!i&&s&&s.valueAsTypeSingle&&!Array.isArray(s.valueAsTypeSingle)&&s.valueAsTypeSingle.type===n.DefinitionEntity&&(i=s.valueAsTypeSingle),i}syncOperationInstance(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-operation-instance-validate-data"))){const i=[],s=[],l=[],o=[],d=this.getEntityToMatchInputMap(e);if(d){const{added:c,updated:I,removed:E,affected:O}=this.syncEntityToMatchInputMapDataType(d,t);i.push(...I),s.push(...c),l.push(...E),o.push(...O)}const u=this.getDataToValidateInputMap(e);if(u){const{added:c,updated:I,removed:E,affected:O}=this.syncDataToValidateInputMapDataType(u,t);i.push(...I),s.push(...c),l.push(...E),o.push(...O)}const y=this.getOutputDataOutputMap(e);if(y){const{added:c,updated:I,removed:E,affected:O}=this.syncOutputDataOutputMapDataType(y,t);i.push(...I),s.push(...c),l.push(...E),o.push(...O)}return t==null||t.attemptAutoclose("sync-operation-instance-validate-data",this.id),{updated:p(i),added:p(s),removed:p(l),affected:p(o),self:e}}syncEntityToMatchInputMapDataType(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-entity-to-match-input-map-data-type"))){var u,y,c;const i=[],s=[],l=[],o=[];if(((u=e.declaration)==null?void 0:u.id)!==k.operation[Qe.Validate].inputs.entityToMatch.id)return t==null||t.attemptAutoclose("sync-entity-to-match-input-map-data-type",this.id),{updated:[],added:[],removed:[],affected:[],self:null};if(!e.dataType){const I={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(t==null?void 0:t.timestamp)||new Date().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.DataType,parentRelationType:null,options:null,implementationChooseOne:!1,isList:!1,andChildrenGroup:null,orChildrenGroup:null,asType:!0,entity:null,like:!0,inferred:!0,parent:e.toReference()},E=V(I,e.project);E.setParent(e,t),E.initChildren(t),t==null||t.add(E,b.Added),i.push(E),e.setDataType(E)}(y=e.dataType)==null||y.metaSync({inferred:!0,like:!1,asType:!0},t);const d=this.getEntityToMatch(e,t);return(c=e.dataType)==null||c.setEntity(d),e.dataType&&s.push(e.dataType),t==null||t.attemptAutoclose("sync-entity-to-match-input-map-data-type",this.id),{updated:p(s),added:p(i),removed:p(l),affected:p(o),self:e.dataType}}syncDataToValidateInputMapDataType(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-data-to-validate-input-map-data-type"))){var c,I,E;const i=[],s=[],l=[],o=[];if(((c=e.declaration)==null?void 0:c.id)!==k.operation[Qe.Validate].inputs.dataToValidate.id)return t==null||t.attemptAutoclose("sync-data-to-validate-input-map-data-type",this.id),{updated:[],added:[],removed:[],affected:[],self:null};const d=this.getEntityToMatchInputMap(e.parent);if(!d)return t==null||t.attemptAutoclose("sync-data-to-validate-input-map-data-type",this.id),{updated:[],added:[],removed:[],affected:[],self:null};if(!this.getEntityToMatch(d,t))return t==null||t.attemptAutoclose("sync-data-to-validate-input-map-data-type",this.id),{updated:[],added:[],removed:[],affected:[],self:null};if(!e.dataType){const O={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(t==null?void 0:t.timestamp)||new Date().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.DataType,parentRelationType:null,options:null,implementationChooseOne:!1,isList:!1,andChildrenGroup:null,orChildrenGroup:null,asType:!1,entity:null,like:!0,inferred:!0,parent:e.toReference()},P=V(O,e.project);P.setParent(e,t),P.initChildren(t),t==null||t.add(P,b.Added),i.push(P),e.setDataType(P)}(I=e.dataType)==null||I.metaSync({inferred:!0,like:!0,asType:!1},t);const y=this.getEntityToMatch(d,t);return(E=e.dataType)==null||E.setEntity(y),e.dataType&&s.push(e.dataType),t==null||t.attemptAutoclose("sync-data-to-validate-input-map-data-type",this.id),{updated:p(s),added:p(i),removed:p(l),affected:p(o),self:e.dataType}}syncOutputDataOutputMapDataType(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-output-data-output-map-data-type"))){var c,I,E;const i=[],s=[],l=[],o=[];if(((c=e.declaration)==null?void 0:c.id)!==k.operation[Qe.Validate].outputs.outputEntity.id)return t==null||t.attemptAutoclose("sync-output-data-output-map-data-type",this.id),{updated:[],added:[],removed:[],affected:[],self:null};const d=this.getEntityToMatchInputMap(e.parent);if(!d)return t==null||t.attemptAutoclose("sync-output-data-output-map-data-type",this.id),{updated:[],added:[],removed:[],affected:[],self:null};if(!this.getEntityToMatch(d,t))return t==null||t.attemptAutoclose("sync-output-data-output-map-data-type",this.id),{updated:[],added:[],removed:[],affected:[],self:null};if(!e.dataType){const O={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(t==null?void 0:t.timestamp)||new Date().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.DataType,parentRelationType:null,options:null,implementationChooseOne:!1,isList:!1,andChildrenGroup:null,orChildrenGroup:null,asType:!1,entity:null,like:!0,inferred:!0,parent:e.toReference()},P=V(O,e.project);P.setParent(e,t),P.initChildren(t),t==null||t.add(P,b.Added),i.push(P),e.setDataType(P)}(I=e.dataType)==null||I.metaSync({inferred:!0,like:!0,asType:!1},t);const y=this.getEntityToMatch(d,t);return(E=e.dataType)==null||E.setEntity(y),e.dataType&&s.push(e.dataType),t==null||t.attemptAutoclose("sync-output-data-output-map-data-type",this.id),{updated:p(s),added:p(i),removed:p(l),affected:p(o),self:e.dataType}}inferInputMapDataType(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"infer-input-map-data-type-validate-data"))){var i,s;if(((i=e.declaration)==null?void 0:i.id)===k.operation[Qe.Validate].inputs.entityToMatch.id){const{added:l,updated:o,removed:d,affected:u}=this.syncEntityToMatchInputMapDataType(e,t);return t==null||t.attemptAutoclose("infer-input-map-data-type-validate-data",this.id),{updated:p(o),added:p(l),removed:p(d),affected:p(u),self:e.dataType}}else if(((s=e.declaration)==null?void 0:s.id)===k.operation[Qe.Validate].inputs.dataToValidate.id){const{added:l,updated:o,removed:d,affected:u}=this.syncDataToValidateInputMapDataType(e,t);return t==null||t.attemptAutoclose("infer-input-map-data-type",this.id),{updated:p(o),added:p(l),removed:p(d),affected:p(u),self:e.dataType}}return{updated:[],added:[],removed:[],affected:[],self:null}}inferOutputMapDataType(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"infer-output-map-data-type-validate-data"))){var i;if(((i=e.declaration)==null?void 0:i.id)===k.operation[Qe.Validate].outputs.outputEntity.id){const{added:s,updated:l,removed:o,affected:d}=this.syncOutputDataOutputMapDataType(e,t);return t==null||t.attemptAutoclose("infer-output-map-data-type-validate-data",this.id),{updated:p(l),added:p(s),removed:p(o),affected:p(d),self:e.dataType}}return{updated:[],added:[],removed:[],affected:[],self:null}}}class vW extends Se{constructor(a){super(Ed,a)}}class TW extends Se{constructor(a){super(bd,a)}}class IW extends Se{constructor(a){super(Rd,a)}}class EW extends Se{constructor(a){super(Ka,a)}}class AW extends Se{constructor(a){super(za,a)}}class bW extends Se{constructor(a){super(Cs,a)}}function RW(r){const a=[new pw(r),new dw(r),new uw(r),new yW(r),new hW(r),new mW(r),new EW(r),new vW(r),new IW(r),new TW(r),new AW(r),new bW(r),new Se(Id,r),new Se(Td,r)];return a.forEach(e=>{e.initChildren(null),r.subscribeBuiltInInstance(e)}),r.operationDeclarations=a,a}class cw extends Ki{constructor(e){super(Vt,e);f(this,"initialData");f(this,"id",z.PERSISTED_ENTITY);f(this,"version","1");f(this,"name",z.PERSISTED_ENTITY);f(this,"description",Vt.description);f(this,"type",n.BuiltInBaseEntity);f(this,"abstract",Vt.abstract);f(this,"static",Vt.static);f(this,"properties",[]);f(this,"methods",[]);f(this,"abstractMethods",[]);f(this,"extends",[]);f(this,"errors",[]);f(this,"project");this.initialData=Vt,this.project=e,this.id=Vt.id,this.version=Vt.version,this.name=Vt.name,this.static=Vt.static,this.abstract=Vt.abstract,this.properties=this.initialData.properties.map(t=>{const i=V(t,this.project);return i.setParent(this,null),i.initChildren(null),i}),this.methods=this.initialData.methods.map(t=>{const i=V(t,this.project);return i.parent=this,i}),this.abstractMethods=this.initialData.abstractMethods.map(t=>{const i=V(t,this.project);return i.parent=this,i}),this.extends=this.initialData.extends.map(t=>V(t,this.project))}}function DW(r){const a=[new cw(r),new Ki(js,r),new Ki(gi,r),new Ki(ho,r)];return a.forEach(e=>{r.subscribeBuiltInInstance(e)}),r.builtInBaseEntities=a,a}function OW(r){const a=[new Qt(ae,r),new Qt(er,r),new Qt(ve,r),new Qt(cd,r),new Qt(Ot,r),new Qt(tr,r),new Qt(Li,r),new Qt(ir,r),new Qt(Fn,r)];return a.forEach(e=>{r.subscribeBuiltInInstance(e)}),r.primitives=a,a}function PW(r){const a=[new Se(vo,r)];return a.forEach(e=>{e.initChildren(null),r.subscribeBuiltInInstance(e)}),r.globalEventActionDescriptors=a,a}function wW(r){const a=[new Se(Ns,r),new Se(Ar,r),new Se(_s,r),new Se(Zn,r),new Se(qn,r),new Se(so,r)];a.forEach(t=>{t.initChildren(null),r.subscribeBuiltInInstance(t)}),r.loopDeclarations=a;const e=[new Se(uo,r),new Se(Ms,r),new Se(oo,r),new Se(jd,r),new Se($d,r),new Se(ao,r)];return e.forEach(t=>{t.initChildren(null),r.subscribeBuiltInInstance(t)}),r.loopDeclarationsBodies=e,a}function CW(r){const a=[new mr(To,r)];return a.forEach(e=>{e.initChildren(null),r.subscribeBuiltInInstance(e)}),r.valueDescriptors=a,a}function VW(r){const a=[new Se(fn,r),new Se(Yn,r)];return a.forEach(e=>{e.initChildren(null),r.subscribeBuiltInInstance(e)}),r.conditionDeclarations=a,a}const Un={},sd={},xa={empty:!1,enrich:!0,mock:!1,ignoreCache:!1,onFetch:async()=>null,manuallyInit:!1};function fw(r,{enrich:a}={enrich:!0}){const e=r.project,t=r.record,i=new Wl(e),s=new Set;t[e.id]=e,s.add(e.id);const l=T().toISOString();Object.values(t).forEach(u=>{!u||i.allBuiltInEntityIds.includes(u.id)||s.add(u.id)}),i.order=Array.from(s),i.flatRecord=t,i.orderEntities();const o=ad(r.project);o.instances[e.id]=o;const d=a?o.addChangeSet(new A(o,m.sessionAuthor,l,o,!0,"project-init-from-fetch-result")):null;return i.visit(u=>{if(u.id===o.id)return;const y=V(u,o);y.hydrateAncestors(),y.addSelfToProject(null)}),a?(i.visit(u=>{const y=o.get(u.id);y&&y.afterAllChildrenInitialized(d)}),o.afterAllChildrenInitialized(d)):od(o,l).forEach(y=>{y.remove({ignoreUpstream:!0},null)}),o.instancesList.forEach(u=>{u.previousVersion=null}),d==null||d.attemptAutoclose("project-init-from-fetch-result",o.id),o}async function BW(r,a=xa){const e={...xa,...a};if(e.empty)return{data:{project:{id:r.id,type:n.Project,version:m.UUID.uuid(),createdAt:T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,name:null,description:null,projects:[],entities:[],operations:[],functions:[],variableDeclarations:[],variableInstances:[],functionCalls:[],conditions:[],loops:[],searches:[],events:[]},record:{}}};if(e.mock){const i={...dp};return i.id=r.id,{data:{project:i,record:{}}}}return console.log("Fetching project from external API"),new Promise(async i=>{if(e.onFetch){const s=await e.onFetch(r.id);if(s){i({data:s});return}}else i({data:null})})}function ad(r){const a=new m(r);return OW(a),DW(a),RW(a),PW(a),wW(a),CW(a),VW(a),Array.from(new Set([...a.getAllBuiltInIds(),..._i()])).forEach(t=>{if(!a.builtInInstances[t]&&a.instances[t])a.builtInInstances[t]=a.instances[t],delete a.instances[t];else if(!a.builtInInstances[t])throw new Error(`Built in entity was not properly initialized: ${t}`)}),a}function od(r,a){return r.instancesList.filter(t=>T(t.createdAt).isAfter(T(a)||!!t.previousVersion))}function _W(r,{enrich:a}={enrich:!0}){const e=new Map,t=Array.from(new Set([...r.getAllBuiltInIds(),..._i()]));Object.keys(r.instances).forEach(u=>{if(t.includes(u)){e.set(u,u);return}const y=r.get(u);if(!rd(y,{...r.instances,...r.builtInInstances}).every(E=>!t.includes(E))){e.set(u,u);return}e.set(u,m.UUID.uuid())});const i=T().toISOString(),s=r.toShallowJSON({seenEntityMaps:e});s.previousVersion=null,s.createdAt=i,s.version=m.UUID.uuid();const l=ad(s),o=a?l.addChangeSet(new A(l,m.sessionAuthor,i,l,!0,"project-clone")):null,d=new Wl(r);return d.visit(u=>{const y=u.toShallowJSON({seenEntityMaps:e});u.type===n.ValueDescriptor&&u.name==="Iteration result"&&(console.log("Og entity shallow copy: ",y),console.log("Og entity full: ",u)),y.previousVersion=null,y.createdAt=i,y.version=m.UUID.uuid();const c=V(y,l);c.hydrateAncestors(),c.addSelfToProject(o),o==null||o.add(c,b.Added)}),a?(d.visit(u=>{const y=l.get(e.get(u.id));y&&y.afterAllChildrenInitialized(o)}),l.afterAllChildrenInitialized(o)):od(l,i).forEach(y=>{y.remove({ignoreUpstream:!0},null)}),l.instancesList.forEach(u=>{u.previousVersion=null}),o==null||o.attemptAutoclose("project-clone",l.id),l}function yw(r,{enrich:a}={enrich:!0}){const e=ad(r),t=T().toISOString(),i=a?e.addChangeSet(new A(e,m.sessionAuthor,t,e,!0,"project-init")):null;i&&(i.type=wc.Automatic);const s=new Wl(r);return s.visit(l=>{const o=V(l,e);o.hydrateAncestors(),o.addSelfToProject(i)}),a?(s.visit(l=>{const o=e.get(l.id);o&&o.afterAllChildrenInitialized(i)}),e.afterAllChildrenInitialized(i)):od(e,t).forEach(o=>{o.remove({ignoreUpstream:!0},null)}),i==null||i.attemptAutoclose("project-init",e.id),e}async function MW(r,a=xa){const e={...xa,...a};if(r.id&&Un[r.id]&&!e.ignoreCache)return Un[r.id];if(r.id&&sd[r.id]&&!e.ignoreCache)return await sd[r.id],Un[r.id];const t=BW(r,e);r.id&&(sd[r.id]=t);const i=await t;if(i.data){let s;return e.mock?s=yw(dp,{enrich:!!e.enrich}):i.data instanceof m?s=i.data:s=fw(i.data,{enrich:!!e.enrich}),Un[r.id]=s,r.id&&delete sd[r.id],s}return null}function NW(r){return Un[r.id]&&delete Un[r.id],null}const LW="test_primitive_entities_export";h.AI_VALUE_CONNECTION_GENERATION_ACTION_EXPLANATION=Fc,h.ALL_BUILT_IN_BASE_ENTITIES=kI,h.ALL_BUILT_IN_CONDITION_ENTITIES=iE,h.ALL_BUILT_IN_GLOBAL_EVENT_ENTITIES=nE,h.ALL_BUILT_IN_LOOP_BODY_ENTITIES=vT,h.ALL_BUILT_IN_LOOP_ENTITIES=mT,h.ALL_BUILT_IN_OPERATION_ENTITIES=C0,h.ALL_BUILT_IN_PRIMITIVE_ENTITIES=mf,h.ALL_BUILT_IN_TOP_LEVEL_ENTITIES=lE,h.ALL_BUILT_IN_VALUE_DESCRIPTORS=oE,h.ActionDescriptorState=Se,h.ActionInputMapState=ZJ,h.ActionOutputMapState=SJ,h.AppendToListOperationInputIds=Dh,h.AppendToListOperationOutputIds=Oh,h.ArgumentDeclarationDependencyField=N1,h.ArgumentDeclarationState=Yr,h.BREAK_AND_CONTINUE_STATEMENTS_RETURN_DECLARATIONS_EXPLANATION=jc,h.BUILT_IN_BASE_ENTITY_IDS=k,h.BUILT_IN_ENTITY_TYPES=Ti,h.BaseCanvasDraggableState=oW,h.BaseEntityNames=z,h.BaseState=aW,h.BaseValueDescriptorIds=Wa,h.BreakStatementDependencyField=Bc,h.BreakStatementState=xr,h.BuiltInBaseEntityState=Ki,h.CACHED_PROJECTS_BY_ID=Un,h.CALLABLE_ENTITIES_EXPLANATION=eS,h.CALLABLE_TYPES=Mi,h.CALLER_ENTITIES_EXPLANATION=F1,h.CALLER_TYPES=Ni,h.CALLS_UPDATE_EXPLANATION=Xr,h.COMPARISON_CONDITIONS=eE,h.CONDITIONS=tE,h.CUSTOM_ENTITY_OPERATIONS=Sm,h.CallableEntityClass=dW,h.CallerEntityClass=nf,h.ChangeSet=A,h.ChangeSetChangeCaptureType=wc,h.ChangeSetEntityChangeType=b,h.ChildEntityState=lW,h.ComparisonOperatorTypes=yt,h.ConditionDependencyField=T1,h.ConditionState=Zr,h.ContinueStatementDependencyField=Cc,h.ContinueStatementState=Lt,h.CreateNewInputIds=Em,h.CreateNewOutputIds=Am,h.DRAGGABLE_CALLABLE_TYPES=pd,h.DRAGGABLE_CALLER_TYPES=lf,h.DRAGGABLE_ELEMENT_TYPES=Sa,h.DRAGGABLE_EXECUTABLE_TYPES=Iw,h.DRAGGABLE_PASS_THROUGH_CALLABLE_TYPES=Ja,h.DRAGGABLE_PASS_THROUGH_CALLABLE_TYPES_WITH_OUTPUTS=ud,h.DataTypeCompatibilityTypes=bi,h.DataTypeDependencyField=Vc,h.DataTypeParentChildRelation=Dt,h.DataTypeState=$r,h.DefinitionEntityDependencyField=nd,h.DefinitionEntityState=nn,h.EDITABLE_PERSISTANCE_REPOSITORY_DEFAULTS=nW,h.ENTITIES_WITH_VALLUES_EXPLANATION=kl,h.ENTITY_PERSISTANCE_OPTIONS_DEFAULTS=j,h.ENTITY_RECUSION_OPTIONS_DEFAULTS=J,h.ENTITY_TYPES=Ew,h.ENTITY_WITH_DECLARATION_TYPES=vw,h.ENTITY_WITH_LOGIC_SCOPE_TYPES=dt,h.ENTITY_WITH_NAMES_TYPES=df,h.ENTITY_WITH_PARENT_TYPES=hw,h.ENTITY_WITH_USER_MANAGED_DECLARATION_TYPES=af,h.ENTITY_WITH_USER_MANAGED_SINGLE_IMPLEMENTS_TYPES=mw,h.ENTITY_WITH_VALUE_TYPES=sf,h.ENTRY_POINT_ENTITIES_EXPLANATION=Va,h.ENTRY_POINT_TYPES=lt,h.EVENT_TYPES=Gn,h.EXECUTABLE_TYPES=Tw,h.EXECUTION_OPERATIONS=Im,h.EntityAction=lw,h.EntityError=it,h.EntityErrorSeverity=D,h.EntityGenerationError=w,h.EntityGenerationErrorCode=R,h.EntityInstanceErrorCode=F,h.EntityOperations=Qe,h.EntityType=n,h.EntityWithLogicScopeClass=fW,h.EntityWithValueClass=cW,h.EntryPointEntityClass=uW,h.ExecutionOperations=Xe,h.ExecutionTerminationType=h1,h.FunctionCallDependencyField=K1,h.FunctionCallState=en,h.FunctionDeclarationDependencyField=l1,h.FunctionDeclarationState=gr,h.GET_PROJECT_OPTIONS_DEFAULTS=xa,h.GLOBAL_EVENT_DECLARATIONS=rE,h.GetLastInListOperationInputIds=ch,h.GetLastInListOperationOutputIds=fh,h.GlobalEventNames=Qi,h.GlobalEventState=Fr,h.HTTPOperations=Mt,h.HTTP_OPERATIONS=P0,h.InputMapDependencyField=V1,h.InputMapState=Wi,h.InstalledProjectState=Wr,h.InternalCallDependencyField=w1,h.InternalCallState=zr,h.JoinListOperationInputIds=My,h.JoinListOperationOutputIds=Ny,h.LIST_OPERATIONS=$h,h.ListOperations=he,h.LiteralValueDependencyField=U1,h.LiteralValueState=Hr,h.LoopDependencyField=m1,h.LoopState=kr,h.LoopTypes=ee,h.NON_INTERACTIVE_BASE_ENTITIES_EXPLANATION=Qr,h.NUMBER_OPERATIONS=Sf,h.NumberOperations=et,h.OPERATION_DECLARATIONS=w0,h.OperationDependencyField=p1,h.OperationState=Gr,h.OutputMapDependencyField=_1,h.OutputMapParentChildRelation=$n,h.OutputMapState=zi,h.PARENT_AUTO_CALCULATION_FROM_CALLER_EXPLANATION=Zl,h.PASS_THROUGH_CALLABLE_ENTITIES_EXPLANATION=Kr,h.PASS_THROUGH_CALLABLE_TYPES=ot,h.PASS_THROUGH_CALLABLE_TYPES_WITH_OUTPUTS=of,h.PROPERTY_NOT_VALUE_READER_WRITTER_EXPLANATION=Gc,h.ParallelExecutionOperation=dw,h.PassThroughCallableEntityClass=pW,h.PersistedEntity=cw,h.PersistedEntityMethods=di,h.PrimitiveEntityState=Qt,h.PrimitiveTypes=L,h.ProjectState=m,h.PropertyDependencyField=i1,h.PropertyState=Ur,h.READ_ONLY_ENTITY_PERSISTANCE_REPOSITORY=ow,h.RETURN_STATEMENT_RETURN_DECLARATIONS_EXPLANATION=tS,h.ReturnDeclarationDependencyField=n1,h.ReturnDeclarationState=ai,h.ReturnStatementDependencyField=$l,h.ReturnStatementState=jr,h.STANDALONE_CONDITIONS=JI,h.STRING_OPERATIONS=_y,h.ScopeCompatibilityType=td,h.SearchDependencyField=R1,h.SearchState=Sr,h.SequentialExecutionOperation=pw,h.SequentialExecutionOperationInputIds=am,h.SequentialExecutionOperationOutputIds=om,h.SharedEntityErrorCode=$,h.SharedStateFunctionality=aw,h.SplitListOperationInputIds=zy,h.SplitListOperationOutputIds=Yy,h.StandaloneOperatorTypes=vi,h.StringOperations=Ee,h.TERMINATION_TYPES=st,h.Traverser=Wl,h.USER_MANAGED_ENTITY_TYPES=uf,h.UserManagedEntityStateTemplate=sW,h.VALUE_READING_ENTITIES_EXPLANATION=$c,h.VALUE_READING_TYPES=Er,h.VALUE_WRITING_ENTITIES_EXPLANATION=x1,h.VALUE_WRITING_TYPES=Tt,h.VARIABLE_DATA_TYPE_INFERRANCE_EXPLANATION=gc,h.VARIABLE_TYPES=tt,h.ValueAutogenerationType=vt,h.ValueDescriptorDependencyField=g1,h.ValueDescriptorParentChildRelation=N,h.ValueDescriptorState=mr,h.ValueReadingEntityClass=Ir,h.ValueWritingEntityClass=Fa,h.VariableDeclarationDependencyField=A1,h.VariableDeclarationState=Jr,h.VariableInputMapState=kJ,h.VariableInstanceDependencyField=Mc,h.VariableInstanceState=qr,h.VariableOutputMapState=JJ,h.WaitOperation=uw,h.WaitOperationInputIds=Qh,h.WaitOperationOutputIds=em,h.actionDescriptorValidation=LJ,h.appendToListOperation=Ka,h.appendToListOperationElementToAppendArgument=Od,h.appendToListOperationElementToAppendArgumentParentRef=Nh,h.appendToListOperationElementToAppendArgumentRef=Ch,h.appendToListOperationError=gh,h.appendToListOperationErrorParentRef=jh,h.appendToListOperationListArgument=Dd,h.appendToListOperationListArgumentParentRef=Mh,h.appendToListOperationListArgumentRef=Ph,h.appendToListOperationListDataType=wh,h.appendToListOperationResultListDataType=_h,h.appendToListOperationResultListReturn=Uh,h.appendToListOperationResultListReturnParentRef=Lh,h.appendToListOperationResultListReturnRef=Bh,h.appendToListOperationSecondListDataType=Vh,h.applyNewScope=K,h.argumentDeclarationValidation=WJ,h.asGenerationActionExample=Yi,h.booleanPrototype=er,h.breakStatementValidation=_J,h.calculateNewParentBasedOnCallers=Sc,h.capitalizeFirstLetter=xt,h.changeSetJSONRecordToUniqueIds=IJ,h.checkAreDataTypesCompatible=Ri,h.checkAreDefinitionEntitiesCompatibleAsDataType=xO,h.checkArePropertiesCompatibleAsDataType=FO,h.checkExtendsBaseEntity=id,h.checkHasBaseEntity=Ga,h.checkHasMetadataChanged=pt,h.checkImplementationsOverlap=Tr,h.checkImplementsBaseEntity=LS,h.checkIsBranchDependentButNotDirectlyOnBranch=_a,h.checkIsBranchDependentOnBranch=yS,h.checkIsCallableEntityReachable=$a,h.checkIsCanvasEntity=MS,h.checkIsDetachedBranch=KP,h.checkIsDetachedBranchShallow=tf,h.checkIsGlobalVariable=BS,h.checkIsGloballyDeclared=ef,h.checkIsMethod=ew,h.checkIsNestedScope=ed,h.checkScopeCompatibility=ga,h.cloneProject=_W,h.conditionValidation=UJ,h.continueStatementValidation=bJ,h.convertToAbstract=uS,h.convertToNonAbstract=pS,h.convertToNonStatic=fS,h.convertToStatic=cS,h.countedLoopActionDescriptor=Ns,h.countedLoopActionDescriptorDynamicReturnDeclaration=lT,h.countedLoopActionDescriptorDynamicReturnDeclarationParentRef=oT,h.countedLoopActionDescriptorStringArgumentDeclaration=aT,h.countedLoopActionDescriptorStringArgumentDeclarationDataType=nT,h.countedLoopActionDescriptorStringArgumentDeclarationDataTypeDefaultValue=iT,h.countedLoopActionDescriptorStringArgumentDeclarationDataTypeDefaultValueParentRef=tT,h.countedLoopActionDescriptorStringArgumentDeclarationDataTypeParentRef=rT,h.countedLoopActionDescriptorStringArgumentDeclarationParentRef=sT,h.countedLoopBodyActionDescriptor=uo,h.countedLoopBodyActionDescriptorAnyDynamicArgument=fT,h.countedLoopBodyActionDescriptorAnyDynamicArgumentParentRef=cT,h.countedLoopBodyActionDescriptorAnyDynamicReturn=hT,h.countedLoopBodyActionDescriptorAnyDynamicReturnParentRef=yT,h.countedLoopBodyActionDescriptorIterationNumberArgumentDeclaration=Fd,h.countedLoopBodyActionDescriptorIterationNumberArgumentDeclarationDataType=uT,h.countedLoopBodyActionDescriptorIterationNumberArgumentDeclarationDataTypeParentRef=dT,h.countedLoopBodyActionDescriptorIterationNumberArgumentDeclarationParentRef=pT,h.createDefinitionEntityFromJSONObject=Yl,h.createEntityError=de,h.createNestedDataTypeForEntity=eP,h.createNewInstanceOperation=on,h.createNewInstanceOperationEntityToInstanciateArgument=Vm,h.createNewInstanceOperationEntityToInstanciateArgumentRef=Pm,h.createNewInstanceOperationEntityToInstanciateDataType=wm,h.createNewInstanceOperationError=Nm,h.createNewInstanceOperationErrorParentRef=Mm,h.createNewInstanceOperationNewEntityDataArgument=Om,h.createNewInstanceOperationNewEntityDataArgumentDataType=Dm,h.createNewInstanceOperationNewEntityDataArgumentDataTypeParentRef=Rm,h.createNewInstanceOperationNewEntityDataArgumentParentRef=bm,h.createNewInstanceOperationOutputEntityDeclaration=_m,h.createNewInstanceOperationOutputEntityDeclarationParentRef=Bm,h.createNewInstanceOperationRef=Cm,h.createSemanticId=QO,h.createStateFromGenerationTargetType=rW,h.createStateFromType=ct,h.createStateFromTypeAndSubscribe=V,h.cronJobBuiltInBaseEntity=ho,h.cronJobBuiltInBaseEntityExpressionProperty=FI,h.cronJobBuiltInBaseEntityExpressionPropertyDataTypeRef=Cw,h.cronJobBuiltInBaseEntityExpressionPropertyRef=$I,h.cronJobBuiltInBaseEntityRef=GI,h.cronJobTriggeredFunctionDeclarationBlueprint=eu,h.cronJobTriggeredFunctionDeclarationBlueprintParentRef=jI,h.dataTypeCompatibilityToErrorExplanation=Y1,h.dataTypeValidation=PJ,h.datePrototype=Li,h.dateValueAutogenerationSchema=yp,h.definitionEntityToZodSchema=DE,h.definitionEntityValidation=QS,h.deletePersistedEntityMethod=Qd,h.deletePersistedEntityMethodParentRef=AI,h.deleteRootProject=NW,h.endpointBuiltInBaseEntity=js,h.endpointBuiltInBaseEntityRef=AT,h.endpointBuiltInBaseEntityRefFour=iI,h.endpointBuiltInBaseEntityRefThree=BT,h.endpointBuiltInBaseEntityRefTwo=PT,h.endpointBuiltInCorsProperty=bT,h.endpointBuiltInCorsPropertyDataType=ET,h.endpointBuiltInCorsPropertyDataTypeRef=TT,h.endpointBuiltInCorsPropertyRef=IT,h.endpointBuiltInMethodProperty=kd,h.endpointBuiltInMethodPropertyDataType=VT,h.endpointBuiltInMethodPropertyDataTypeRef=wT,h.endpointBuiltInMethodPropertyRef=CT,h.endpointBuiltInPathProperty=xd,h.endpointBuiltInPathPropertyDataType=OT,h.endpointBuiltInPathPropertyDataTypeRef=RT,h.endpointBuiltInPathPropertyRef=DT,h.endpointPathParamsArgumentDeclaration=qd,h.endpointPathParamsArgumentDeclarationRef=FT,h.endpointPathParamsVariableDataType=xT,h.endpointPathParamsVariableDataTypeRef=GT,h.endpointReachedTriggerActionDescriptor=Hd,h.endpointReachedTriggerActionDescriptorRef=kT,h.endpointReachedTriggerActionDescriptorRefFour=JT,h.endpointReachedTriggerActionDescriptorRefThree=qT,h.endpointReachedTriggerActionDescriptorRefTwo=ZT,h.endpointRequestBodyArgumentDeclaration=Sd,h.endpointRequestBodyArgumentDeclarationRef=LT,h.endpointRequestBodyVariableDataType=UT,h.endpointRequestHeadersArgumentDeclaration=Zd,h.endpointRequestHeadersArgumentDeclarationRef=MT,h.endpointRequestHeadersVariableDataType=NT,h.endpointRequestHeadersVariableDataTypeRef=_T,h.endpointRequestQueryParamsArgumentDeclaration=Jd,h.endpointRequestQueryParamsArgumentDeclarationRef=gT,h.endpointRequestQueryParamsVariableDataType=$T,h.endpointRequestQueryParamsVariableDataTypeRef=jT,h.endpointResponseBodyDataType=eI,h.endpointResponseBodyReturnDeclaration=Yd,h.endpointResponseBodyReturnDeclarationRef=QT,h.endpointResponseCodeDataType=WT,h.endpointResponseCodeReturnDeclaration=Wd,h.endpointResponseCodeReturnDeclarationRef=ST,h.endpointResponseHeadersDataType=KT,h.endpointResponseHeadersDataTypeRef=YT,h.endpointResponseHeadersReturnDeclaration=zd,h.endpointResponseHeadersReturnDeclarationRef=HT,h.endpointReturnStatementRef=zT,h.endpointReturnStatementRefThree=tI,h.endpointReturnStatementRefTwo=XT,h.enrichFromKnownEntities=Ma,h.enumOptionsProperty=hf,h.enumOptionsPropertyDataType=ff,h.enumOptionsPropertyDataTypeRef=pf,h.enumOptionsPropertyRef=cf,h.enumPrototype=tr,h.enumPrototypeRef=yf,h.executionBuiltInBaseEntity=mo,h.executionBuiltInEntityAbortMethod=tu,h.executionBuiltInEntityAbortMethodParentRef=xI,h.filterOutDuplicateEntities=p,h.filterOutDuplicateErrors=N3,h.findEntityFromKeys=qc,h.findReferenceToSelfInList=hP,h.findReferencesToSelfInProject=RS,h.flattenActionDescriptor=mP,h.flattenArgumentDeclaration=vP,h.flattenBreakStatement=TP,h.flattenBuiltInBaseEntity=IP,h.flattenCalls=Hi,h.flattenCanvasAncestorsUntil=Ds,h.flattenCondition=EP,h.flattenContinueStatement=AP,h.flattenDataType=RP,h.flattenDefinitionEntity=bP,h.flattenDefinitionEntityExtensionAndImplementationTypes=Qc,h.flattenDefinitionEntityExtensionTypes=La,h.flattenDefinitionEntityExtensions=Kc,h.flattenDefinitionEntityImplementations=Xc,h.flattenDefinitionEntityImplementionTypes=Na,h.flattenDerivedCanvasEntities=oi,h.flattenDetachedBranch=QP,h.flattenElementCalls=Je,h.flattenElementCallsOnTheSameScope=bS,h.flattenEntity=U,h.flattenFunctionCall=DP,h.flattenFunctionDeclaration=OP,h.flattenGlobalEvent=PP,h.flattenInputMap=wP,h.flattenInstalledProject=CP,h.flattenInternalCall=VP,h.flattenLiteralValue=BP,h.flattenLoop=_P,h.flattenOperation=MP,h.flattenOutputMap=NP,h.flattenPrimitiveEntity=LP,h.flattenProject=UP,h.flattenProjectElements=yP,h.flattenProperty=jP,h.flattenRelatedCanvasElementsOnTheLeft=zP,h.flattenRelatedCanvasElementsOnTheRight=WP,h.flattenReturnDeclaration=gP,h.flattenReturnStatement=$P,h.flattenSearch=GP,h.flattenValueDescriptor=FP,h.flattenVariableDeclaration=xP,h.flattenVariableInstance=kP,h.flattenVariableReads=fP,h.flattenVariableWrites=cP,h.flattenVariables=Ye,h.fromChangeSetToRecordChangeSet=xS,h.fromZodParseToEntityGenerationErrors=Nc,h.functionCallValidation=dS,h.functionDeclarationValidation=OJ,h.generate=MV,h.generateActionExample=iS,h.generateExecutionDataType=uJ,h.generateIdFromStrategy=ht,h.generateMutablePropertiesExplanation=Gl,h.generateRandomBoolean=KE,h.generateRandomDate=CE,h.generateRandomDateAfter=OE,h.generateRandomDateBefore=PE,h.generateRandomDateBetweenRange=wE,h.generateRandomNumber=SE,h.generateRandomNumberAfter=ZE,h.generateRandomNumberBefore=qE,h.generateRandomNumberBetweenRange=JE,h.generateRandomText=HE,h.generateRandomTextAfter=WE,h.generateRandomTextBefore=zE,h.generateRandomTextBetweenRange=YE,h.generateUniqueUUID=kE,h.getAllActionDescriptorsForConditions=Sl,h.getAllActionDescriptorsForGlobalEvents=ql,h.getAllActionDescriptorsForLoops=Jl,h.getAllActionDescriptorsForOperations=aS,h.getAllBuiltInEntityIds=_i,h.getAllGloballyDeclaredFunctionDeclarationsExplanation=S1,h.getBaseBuiltInEntities=kt,h.getBaseSchemaBasedOnType=$1,h.getBuiltInEntityOwner=rn,h.getCallableEntityReferenceSchema=Pt,h.getCallableEntityTypeSchema=CD,h.getCalledBy=hi,h.getCallerEntityReferenceSchema=gZ,h.getCallerEntityTypeSchema=jZ,h.getCalls=zc,h.getCanvasEntitiesDerivedFromInternalCalls=SP,h.getCanvasEntitiesDerivedFromWrites=Os,h.getCanvasEntityDerivedFromValueReadingEntity=Ql,h.getCanvasEntityDerivedFromValueReadingEntityFromTransfer=JP,h.getCanvasEntityReferenceSchema=eq,h.getCanvasEntityTypeSchema=QZ,h.getChildrenEntityWithValues=mS,h.getColumnProperties=$S,h.getCommonAncestor=Wc,h.getCommonChildren=tP,h.getDatabaseEntities=jS,h.getDatabaseEntity=GS,h.getDeclaration=Nn,h.getDeepestScope=iw,h.getDraggableCallableEntityReferenceSchema=BD,h.getDraggableCallableEntityTypeSchema=VD,h.getDraggableCallerEntityReferenceSchema=GZ,h.getDraggableCallerEntityTypeSchema=$Z,h.getDraggableExecutableEntityReferenceSchema=ZZ,h.getDraggableExecutableEntityTypeSchema=kZ,h.getDraggablePassThroughCallableEntityReferenceSchema=Ol,h.getDraggablePassThroughCallableEntityTypeSchema=Dl,h.getDraggablePlayableEntityReferenceSchema=zZ,h.getDraggablePlayableEntityTypeSchema=WZ,h.getEntitiesCreatedSinceInitialization=od,h.getEntityArgumentDeclarations=Hc,h.getEntityInputMaps=ZP,h.getEntityOutputMaps=wS,h.getEntityReferenceSchema=XZ,h.getEntityReturnDeclarations=qP,h.getEntityTypeSchema=KZ,h.getEntityWithLogicScopeReferenceSchema=fr,h.getEntityWithLogicScopeTypeSchema=qZ,h.getEntityWithValueReferenceSchema=wD,h.getEntityWithValueTypeSchema=UZ,h.getEntryPointEntityReferenceSchema=Rt,h.getEntryPointEntityTypeSchema=Mr,h.getEventEntityReferenceSchema=bl,h.getEventEntityTypeSchema=Al,h.getExecutableEntityReferenceSchema=xZ,h.getExecutableEntityTypeSchema=FZ,h.getExtendedBuiltInEntity=CS,h.getExtendedDefinitionEntity=HP,h.getGenerationTargetSchemaBasedOnType=G1,h.getHeadIfPartOfDetachedBranch=XP,h.getHighestScope=tw,h.getImplementedBuiltInEntity=VS,h.getIsInteractive=Ua,h.getLastInListOperation=Rd,h.getLastInListOperationError=Rh,h.getLastInListOperationErrorParentRef=bh,h.getLastInListOperationInputListArgument=Ih,h.getLastInListOperationInputListArgumentParentRef=Th,h.getLastInListOperationInputListArgumentRef=yh,h.getLastInListOperationInputListDataType=hh,h.getLastInListOperationOutputElementDataType=vh,h.getLastInListOperationOutputElementReturn=Ah,h.getLastInListOperationOutputElementReturnParentRef=Eh,h.getLastInListOperationOutputElementReturnRef=mh,h.getLinkedEntitiesFromArgumentDeclaration=AS,h.getLowestPersistedEntityImplementation=YP,h.getParentCallableEntity=iP,h.getParentCallerEntity=nP,h.getParentCanvasEntities=Xt,h.getParentCanvasEntity=wt,h.getParentCanvasEntityFromTransfer=Hl,h.getParentEntryPoint=hS,h.getParentPassthroughCallableEntity=rP,h.getPassThroughCallableEntityReferenceSchema=rt,h.getPassThroughCallableEntityTypeSchema=Rl,h.getPeristedEntities=US,h.getPlayableEntityReferenceSchema=SZ,h.getPlayableEntityTypeSchema=JZ,h.getProject=MW,h.getPrototypeByType=ja,h.getRecusriveParentsIds=rd,h.getReferenceEntityId=_,h.getReferencedEntitiesStateOrErrors=xl,h.getReferencedEntityStateOrErrors=Lc,h.getReferencedIds=Xl,h.getRelatedCanvasElementsOnTheLeft=Ln,h.getRelatedCanvasElementsOnTheLeftFromTransfer=DS,h.getRelatedCanvasElementsOnTheRight=tn,h.getRootEntryPointScopeOwner=rf,h.getScopeOwner=Zt,h.getStateClassFromType=FS,h.getTerminationReferenceSchema=HZ,h.getTerminationTypeSchema=YZ,h.getTouchedCanvasEntitiesFromChangeSet=kS,h.getUsedArgFromDeclaration=OS,h.getUsedReturnFromDeclaration=PS,h.getValueReadingEntityReferenceSchema=PD,h.getValueReadingEntityTypeSchema=cr,h.getValueWritingEntityReferenceSchema=LZ,h.getValueWritingEntityTypeSchema=Ia,h.getVariableFromInputMapping=aP,h.getVariableFromReturnVariablePointer=dP,h.getVariableReferenceSchema=_r,h.getVariableTypeSchema=wn,h.getVariablesFromArgumentDeclarations=Kl,h.getVariablesFromInputMaps=oP,h.getVariablesFromOutputMapping=uP,h.getVariablesFromOutputMaps=pP,h.getVariablesFromReturnDeclarations=lP,h.getVariablesInSameOrHigherScope=Ic,h.getWrites=Yc,h.globalEventValidation=BJ,h.groupCallsBasedOnParallelizableExecution=TS,h.handleAfterEntityImplementationSideEffects=Q1,h.handleBeforeEntityImplementationSideEffects=X1,h.httpRequestBodyArgument=to,h.httpRequestBodyArgumentRef=s0,h.httpRequestBodyDataType=a0,h.httpRequestHeadersArgument=eo,h.httpRequestHeadersArgumentRef=r0,h.httpRequestHeadersDataType=n0,h.httpRequestMethodArgument=Xa,h.httpRequestMethodArgumentRef=t0,h.httpRequestMethodDataType=i0,h.httpRequestMethodDataTypeRef=Qm,h.httpRequestOperation=Vs,h.httpRequestOperationErrorValueDescriptor=_d,h.httpRequestOperationErrorValueDescriptorDatatype=O0,h.httpRequestOperationErrorValueDescriptorRef=D0,h.httpRequestOperationRef=E0,h.httpRequestOperationRefEight=b0,h.httpRequestOperationRefFive=T0,h.httpRequestOperationRefFour=v0,h.httpRequestOperationRefNine=R0,h.httpRequestOperationRefSeven=A0,h.httpRequestOperationRefSix=I0,h.httpRequestOperationRefThree=m0,h.httpRequestOperationRefTwo=h0,h.httpRequestQueryParamsArgument=Bd,h.httpRequestQueryParamsArgumentRef=Km,h.httpRequestQueryParamsDataType=Xm,h.httpRequestVariableURLArgument=Qa,h.httpRequestVariableURLArgumentRef=Ym,h.httpRequestVariableURLDataType=Hm,h.httpRequestVariableURLDataTypeRef=Wm,h.httpResponseBodyReturnDataType=y0,h.httpResponseBodyReturnDataTypeRef=c0,h.httpResponseBodyReturnReturn=no,h.httpResponseBodyReturnReturnRef=f0,h.httpResponseCodeDataType=l0,h.httpResponseCodeReturn=io,h.httpResponseCodeReturnRef=o0,h.httpResponseHeadersDataType=p0,h.httpResponseHeadersDataTypeRef=d0,h.httpResponseHeadersReturn=ro,h.httpResponseHeadersReturnRef=u0,h.implement=zl,h.inferArgumentDeclarationDataType=kO,h.inferDataType=Si,h.inferInputMapDataType=mc,h.inferOutputMapDataType=Tc,h.inferPropertyDataType=JO,h.inferReturnDeclarationDataType=vc,h.inferValueDescriptorDataType=SO,h.inferVariableDeclarationDataType=qO,h.inferVariableInstanceDataType=ZO,h.initBaseProjectEntity=ad,h.initProject=yw,h.initProjectFromFetchResult=fw,h.inputMapValidation=xJ,h.installedProjectValidation=GJ,h.internalCallValidation=FJ,h.isPromise=Zc,h.iterateOverListActionDescriptorListArgumentDeclaration=sv,h.iterateOverListActionDescriptorListArgumentDeclarationDataType=rv,h.iterateOverListActionDescriptorListArgumentDeclarationDataTypeParentRef=iv,h.iterateOverListActionDescriptorListArgumentDeclarationParentRef=nv,h.iterateOverListLoopActionDescriptor=Ar,h.iterateOverListLoopActionDescriptorDynamicReturnDeclaration=ov,h.iterateOverListLoopActionDescriptorDynamicReturnDeclarationParentRef=av,h.iterateOverListLoopBodyActionDescriptor=Ms,h.iterateOverListLoopBodyActionDescriptorAnyDynamicArgument=mv,h.iterateOverListLoopBodyActionDescriptorAnyDynamicArgumentParentRef=hv,h.iterateOverListLoopBodyActionDescriptorAnyDynamicReturn=Tv,h.iterateOverListLoopBodyActionDescriptorAnyDynamicReturnParentRef=vv,h.iterateOverListLoopBodyActionDescriptorCurrentValueArgumentDeclaration=lo,h.iterateOverListLoopBodyActionDescriptorCurrentValueArgumentDeclarationDataType=dv,h.iterateOverListLoopBodyActionDescriptorCurrentValueArgumentDeclarationDataTypeParentRef=lv,h.iterateOverListLoopBodyActionDescriptorCurrentValueArgumentDeclarationParentRef=uv,h.iterateOverListLoopBodyActionDescriptorIterationNumberArgumentDeclaration=yv,h.iterateOverListLoopBodyActionDescriptorIterationNumberArgumentDeclarationDataType=cv,h.iterateOverListLoopBodyActionDescriptorIterationNumberArgumentDeclarationDataTypeParentRef=pv,h.iterateOverListLoopBodyActionDescriptorIterationNumberArgumentDeclarationParentRef=fv,h.iterateOverObjectKeysActionDescriptorObjectArgumentDeclaration=Rv,h.iterateOverObjectKeysActionDescriptorObjectArgumentDeclarationDataType=Av,h.iterateOverObjectKeysActionDescriptorObjectArgumentDeclarationDataTypeParentRef=Ev,h.iterateOverObjectKeysActionDescriptorObjectArgumentDeclarationParentRef=bv,h.iterateOverObjectKeysLoopActionDescriptor=Zn,h.iterateOverObjectKeysLoopActionDescriptorDynamicReturnDeclaration=Ov,h.iterateOverObjectKeysLoopActionDescriptorDynamicReturnDeclarationParentRef=Dv,h.iterateOverObjectKeysLoopBodyActionDescriptor=jd,h.iterateOverObjectKeysLoopBodyActionDescriptorAnyDynamicArgument=Lv,h.iterateOverObjectKeysLoopBodyActionDescriptorAnyDynamicArgumentParentRef=Nv,h.iterateOverObjectKeysLoopBodyActionDescriptorAnyDynamicReturn=jv,h.iterateOverObjectKeysLoopBodyActionDescriptorAnyDynamicReturnParentRef=Uv,h.iterateOverObjectKeysLoopBodyActionDescriptorCurrentValueArgumentDeclaration=Ud,h.iterateOverObjectKeysLoopBodyActionDescriptorCurrentValueArgumentDeclarationDataType=wv,h.iterateOverObjectKeysLoopBodyActionDescriptorCurrentValueArgumentDeclarationDataTypeParentRef=Pv,h.iterateOverObjectKeysLoopBodyActionDescriptorCurrentValueArgumentDeclarationParentRef=Cv,h.iterateOverObjectKeysLoopBodyActionDescriptorIterationNumberArgumentDeclaration=Mv,h.iterateOverObjectKeysLoopBodyActionDescriptorIterationNumberArgumentDeclarationDataType=Bv,h.iterateOverObjectKeysLoopBodyActionDescriptorIterationNumberArgumentDeclarationDataTypeParentRef=Vv,h.iterateOverObjectKeysLoopBodyActionDescriptorIterationNumberArgumentDeclarationParentRef=_v,h.iterateOverObjectValuesActionDescriptorObjectArgumentDeclaration=xv,h.iterateOverObjectValuesActionDescriptorObjectArgumentDeclarationDataType=Gv,h.iterateOverObjectValuesActionDescriptorObjectArgumentDeclarationDataTypeParentRef=$v,h.iterateOverObjectValuesActionDescriptorObjectArgumentDeclarationParentRef=Fv,h.iterateOverObjectValuesLoopActionDescriptor=qn,h.iterateOverObjectValuesLoopActionDescriptorDynamicReturnDeclaration=Zv,h.iterateOverObjectValuesLoopActionDescriptorDynamicReturnDeclarationParentRef=kv,h.iterateOverObjectValuesLoopBodyActionDescriptor=$d,h.iterateOverObjectValuesLoopBodyActionDescriptorAnyDynamicArgument=Xv,h.iterateOverObjectValuesLoopBodyActionDescriptorAnyDynamicArgumentParentRef=Kv,h.iterateOverObjectValuesLoopBodyActionDescriptorAnyDynamicReturn=eT,h.iterateOverObjectValuesLoopBodyActionDescriptorAnyDynamicReturnParentRef=Qv,h.iterateOverObjectValuesLoopBodyActionDescriptorCurrentValueArgumentDeclaration=gd,h.iterateOverObjectValuesLoopBodyActionDescriptorCurrentValueArgumentDeclarationDataType=Jv,h.iterateOverObjectValuesLoopBodyActionDescriptorCurrentValueArgumentDeclarationDataTypeParentRef=qv,h.iterateOverObjectValuesLoopBodyActionDescriptorCurrentValueArgumentDeclarationParentRef=Sv,h.iterateOverObjectValuesLoopBodyActionDescriptorIterationNumberArgumentDeclaration=Hv,h.iterateOverObjectValuesLoopBodyActionDescriptorIterationNumberArgumentDeclarationDataType=zv,h.iterateOverObjectValuesLoopBodyActionDescriptorIterationNumberArgumentDeclarationDataTypeParentRef=Wv,h.iterateOverObjectValuesLoopBodyActionDescriptorIterationNumberArgumentDeclarationParentRef=Yv,h.iterateOverStringActionDescriptorDynamicReturnDeclaration=q0,h.iterateOverStringActionDescriptorDynamicReturnDeclarationParentRef=Z0,h.iterateOverStringActionDescriptorStringArgumentDeclaration=k0,h.iterateOverStringActionDescriptorStringArgumentDeclarationDataType=F0,h.iterateOverStringActionDescriptorStringArgumentDeclarationDataTypeParentRef=G0,h.iterateOverStringActionDescriptorStringArgumentDeclarationParentRef=x0,h.iterateOverStringLoopActionDescriptor=_s,h.iterateOverStringLoopBodyActionDescriptor=oo,h.iterateOverStringLoopBodyActionDescriptorAnyDynamicArgument=X0,h.iterateOverStringLoopBodyActionDescriptorAnyDynamicArgumentParentRef=K0,h.iterateOverStringLoopBodyActionDescriptorAnyDynamicReturn=ev,h.iterateOverStringLoopBodyActionDescriptorAnyDynamicReturnParentRef=Q0,h.iterateOverStringLoopBodyActionDescriptorCurrentValueArgumentDeclaration=Nd,h.iterateOverStringLoopBodyActionDescriptorCurrentValueArgumentDeclarationDataType=S0,h.iterateOverStringLoopBodyActionDescriptorCurrentValueArgumentDeclarationDataTypeParentRef=J0,h.iterateOverStringLoopBodyActionDescriptorCurrentValueArgumentDeclarationParentRef=W0,h.iterateOverStringLoopBodyActionDescriptorIterationNumberArgumentDeclaration=Ld,h.iterateOverStringLoopBodyActionDescriptorIterationNumberArgumentDeclarationDataType=Y0,h.iterateOverStringLoopBodyActionDescriptorIterationNumberArgumentDeclarationDataTypeParentRef=z0,h.iterateOverStringLoopBodyActionDescriptorIterationNumberArgumentDeclarationParentRef=H0,h.joinListOperation=Ed,h.joinListOperationError=Wy,h.joinListOperationErrorParentRef=Sy,h.joinListOperationFirstListArgument=xy,h.joinListOperationFirstListArgumentParentRef=Fy,h.joinListOperationFirstListArgumentRef=Ly,h.joinListOperationFirstListDataType=Uy,h.joinListOperationResultListDataType=Gy,h.joinListOperationResultListReturn=Jy,h.joinListOperationResultListReturnParentRef=qy,h.joinListOperationResultListReturnRef=$y,h.joinListOperationSecondListArgument=Zy,h.joinListOperationSecondListArgumentParentRef=ky,h.joinListOperationSecondListArgumentRef=jy,h.joinListOperationSecondListDataType=gy,h.joinListWithLastSeparator=se,h.joinStringsOperation=Cs,h.joinStringsOperationDynamicStringArgument=fy,h.joinStringsOperationDynamicStringArgumentParentRef=cy,h.joinStringsOperationDynamicStringArgumentRef=uy,h.joinStringsOperationDynamicStringDataType=py,h.joinStringsOperationError=dy,h.joinStringsOperationErrorParentRef=ly,h.joinStringsOperationFirstStringArgument=Ya,h.joinStringsOperationFirstStringArgumentParentRef=Qf,h.joinStringsOperationFirstStringArgumentRef=Wf,h.joinStringsOperationFirstStringDataType=zf,h.joinStringsOperationResultStringDataType=Xf,h.joinStringsOperationResultStringReturn=ws,h.joinStringsOperationResultStringReturnParentRef=oy,h.joinStringsOperationResultStringReturnRef=Kf,h.joinStringsOperationSecondStringArgument=Ha,h.joinStringsOperationSecondStringArgumentParentRef=ay,h.joinStringsOperationSecondStringArgumentRef=Yf,h.joinStringsOperationSecondStringDataType=Hf,h.joinStringsOperationSeparatorStringArgument=sy,h.joinStringsOperationSeparatorStringArgumentParentRef=ny,h.joinStringsOperationSeparatorStringArgumentRef=ey,h.joinStringsOperationSeparatorStringDataType=ry,h.joinStringsOperationSeparatorStringDataTypeDefaultValue=iy,h.joinStringsOperationSeparatorStringDataTypeDefaultValueParentRef=ty,h.keyValuePrototype=Fn,h.literalValudValidation=zJ,h.loopValidation=NJ,h.lowercaseFirstLetter=Nl,h.manualFlowActionDescriptorDeclarationArgumentDeclaration=Md,h.manualFlowActionDescriptorDeclarationArgumentDeclarationDataType=M0,h.manualFlowActionDescriptorDeclarationArgumentDeclarationDataTypeParentRef=_0,h.manualFlowActionDescriptorDeclarationArgumentDeclarationParentRef=N0,h.manualFlowLoopActionDescriptor=so,h.manualFlowLoopActionDescriptorDynamicReturnDeclaration=B0,h.manualFlowLoopActionDescriptorDynamicReturnDeclarationParentRef=V0,h.manualFlowLoopBodyActionDescriptor=ao,h.manualFlowLoopBodyActionDescriptorAnyDynamicArgument=U0,h.manualFlowLoopBodyActionDescriptorAnyDynamicArgumentParentRef=L0,h.manualFlowLoopBodyActionDescriptorAnyDynamicReturn=g0,h.manualFlowLoopBodyActionDescriptorAnyDynamicReturnParentRef=j0,h.mapActionDescriptorToTypeItRepresents=NS,h.mergeEntityErrorsList=L3,h.mergeListOfEntities=_S,h.methodDefaultValue=e0,h.mockClientProject=dp,h.moreThanOrEqualCondition=Yn,h.moreThanOrEqualConditionLeftHandArgument=YI,h.moreThanOrEqualConditionLeftHandArgumentDataType=WI,h.moreThanOrEqualConditionLeftHandArgumentDataTypeParentRef=SI,h.moreThanOrEqualConditionLeftHandArgumentParentRef=zI,h.moreThanOrEqualConditionRightHandArgument=QI,h.moreThanOrEqualConditionRightHandArgumentDataType=KI,h.moreThanOrEqualConditionRightHandArgumentDataTypeParentRef=HI,h.moreThanOrEqualConditionRightHandArgumentParentRef=XI,h.notEmptyCondition=fn,h.notEmptyConditionArgument=qI,h.notEmptyConditionRef=ZI,h.nullPrototype=cd,h.numberAdditionOperation=za,h.numberAdditionOperationDynamicSummandArgument=Vf,h.numberAdditionOperationDynamicSummandArgumentType=Cf,h.numberAdditionOperationDynamicSummandArgumentTypeParentRef=wf,h.numberAdditionOperationError=Pf,h.numberAdditionOperationErrorParentRef=Of,h.numberAdditionOperationFirstNumberArgument=fd,h.numberAdditionOperationFirstNumberArgumentRef=vf,h.numberAdditionOperationFirstNumberDataType=Tf,h.numberAdditionOperationRef=Rf,h.numberAdditionOperationRefThree=hd,h.numberAdditionOperationRefTwo=Df,h.numberAdditionOperationResultNumberDataType=bf,h.numberAdditionOperationResultNumberReturn=md,h.numberAdditionOperationResultNumberReturnRef=Af,h.numberAdditionOperationSecondNumberArgument=yd,h.numberAdditionOperationSecondNumberArgumentRef=If,h.numberAdditionOperationSecondNumberDataType=Ef,h.numberPrototype=ve,h.numberSubtractionOperation=Td,h.numberSubtractionOperationDynamicSubtrahendArgument=Jf,h.numberSubtractionOperationDynamicSubtrahendArgumentType=qf,h.numberSubtractionOperationDynamicSubtrahendArgumentTypeParentRef=Zf,h.numberSubtractionOperationError=kf,h.numberSubtractionOperationErrorParentRef=xf,h.numberSubtractionOperationFirstNumberArgument=jf,h.numberSubtractionOperationFirstNumberArgumentRef=Bf,h.numberSubtractionOperationFirstNumberDataType=_f,h.numberSubtractionOperationRef=vd,h.numberSubtractionOperationRefThree=Gf,h.numberSubtractionOperationRefTwo=gf,h.numberSubtractionOperationResultNumberDataType=Uf,h.numberSubtractionOperationResultNumberReturn=Ff,h.numberSubtractionOperationResultNumberReturnRef=Lf,h.numberSubtractionOperationSecondNumberArgument=$f,h.numberSubtractionOperationSecondNumberArgumentRef=Mf,h.numberSubtractionOperationSecondNumberDataType=Nf,h.numberValueAutogenerationSchema=fp,h.operationValidation=VJ,h.outputMapValidation=qJ,h.parallelExecutionOperation=Oi,h.parallelExecutionOperationError=Xh,h.parallelExecutionOperationErrorParentRef=Kh,h.parallelExecutionOperationListOfExecutionResultsDataType=zh,h.parallelExecutionOperationListOfExecutionResultsReturn=wd,h.parallelExecutionOperationListOfExecutionResultsReturnRef=Wh,h.parallelExecutionOperationListOfFunctionsArgument=Pd,h.parallelExecutionOperationListOfFunctionsArgumentDatatype=Sh,h.parallelExecutionOperationListOfFunctionsArgumentRef=Jh,h.parallelExecutionOperationListOfFunctionsBlueprint=qh,h.parallelExecutionOperationListOfFunctionsBlueprintDynamicInput=kh,h.parallelExecutionOperationListOfFunctionsBlueprintDynamicInputParentRef=xh,h.parallelExecutionOperationListOfFunctionsBlueprintDynamicOutput=Fh,h.parallelExecutionOperationListOfFunctionsBlueprintDynamicOutputParentRef=Gh,h.parallelExecutionOperationListOfFunctionsBlueprintParentRef=Zh,h.parallelExecutionOperationRef=Yh,h.parallelExecutionOperationRefThree=Hh,h.persistedBuiltInBaseEntity=Vt,h.persistedBuiltInBaseEntityDatabaseProperty=Sn,h.persistedBuiltInBaseEntityDatabasePropertyDataType=DI,h.persistedBuiltInBaseEntityDatabasePropertyDataTypeRef=Ow,h.persistedBuiltInBaseEntityDatabasePropertyParentRef=OI,h.persistedBuiltInBaseEntityDatabasePropertyRef=RI,h.persistedBuiltInBaseEntityPrimaryKeyProperty=Wn,h.persistedBuiltInBaseEntityPrimaryKeyPropertyDataType=NI,h.persistedBuiltInBaseEntityPrimaryKeyPropertyNumberDataTypeOption=wI,h.persistedBuiltInBaseEntityPrimaryKeyPropertyNumberDataTypeOptionParentRef=PI,h.persistedBuiltInBaseEntityPrimaryKeyPropertyParentRef=LI,h.persistedBuiltInBaseEntityPrimaryKeyPropertyRef=MI,h.persistedBuiltInBaseEntityPrimaryKeyPropertyStringDataTypeOption=VI,h.persistedBuiltInBaseEntityPrimaryKeyPropertyStringDataTypeOptionParentRef=CI,h.persistedBuiltInBaseEntityPrimaryKeyPropertyUUIDDataTypeOption=_I,h.persistedBuiltInBaseEntityPrimaryKeyPropertyUUIDDataTypeOptionParentRef=BI,h.processOutputGlobalValueDescriptorDataType=aE,h.processOutputGlobalValueDescriptorReturn=To,h.processOutputGlobalValueDescriptorReturnRef=sE,h.projectPublicationCompletedGlobalEvent=vo,h.propertyToZodSchema=RE,h.propertyValidation=vJ,h.relationalDatabaseBuiltInBaseEntity=gi,h.relationalDatabaseBuiltInBaseEntityAutoscalingProperty=Xd,h.relationalDatabaseBuiltInBaseEntityAutoscalingPropertyDataType=II,h.relationalDatabaseBuiltInBaseEntityAutoscalingPropertyDataTypeRef=TI,h.relationalDatabaseBuiltInBaseEntityAutoscalingPropertyParentRef=EI,h.relationalDatabaseBuiltInBaseEntityAutoscalingPropertyRef=vI,h.relationalDatabaseBuiltInBaseEntityDefaultProperty=Kd,h.relationalDatabaseBuiltInBaseEntityDefaultPropertyDataType=mI,h.relationalDatabaseBuiltInBaseEntityDefaultPropertyDataTypeRef=yI,h.relationalDatabaseBuiltInBaseEntityDefaultPropertyRef=hI,h.relationalDatabaseBuiltInBaseEntityIdentifierProperty=po,h.relationalDatabaseBuiltInBaseEntityIdentifierPropertyDataType=sI,h.relationalDatabaseBuiltInBaseEntityIdentifierPropertyDataTypeRef=rI,h.relationalDatabaseBuiltInBaseEntityIdentifierPropertyRef=nI,h.relationalDatabaseBuiltInBaseEntityMinSizeProperty=yo,h.relationalDatabaseBuiltInBaseEntityMinSizePropertyDataType=fI,h.relationalDatabaseBuiltInBaseEntityMinSizePropertyDataTypeRef=pI,h.relationalDatabaseBuiltInBaseEntityMinSizePropertyRef=cI,h.relationalDatabaseBuiltInBaseEntityPasswordProperty=fo,h.relationalDatabaseBuiltInBaseEntityPasswordPropertyDataType=dI,h.relationalDatabaseBuiltInBaseEntityPasswordPropertyDataTypeRef=Dw,h.relationalDatabaseBuiltInBaseEntityPasswordPropertyDefaultValueParentRef=uI,h.relationalDatabaseBuiltInBaseEntityPasswordPropertyRef=lI,h.relationalDatabaseBuiltInBaseEntityRef=Jn,h.relationalDatabaseBuiltInBaseEntityUsernameProperty=co,h.relationalDatabaseBuiltInBaseEntityUsernamePropertyDataType=oI,h.relationalDatabaseBuiltInBaseEntityUsernamePropertyDataTypeRef=Rw,h.relationalDatabaseBuiltInBaseEntityUsernamePropertyRef=aI,h.resolveActionDescriptorName=XO,h.resolveBaseEntityName=zO,h.resolveBuiltInBaseEntityDataTypeLabel=YO,h.resolveClonedEntityProject=mt,h.resolveConditionOperatorLabel=gl,h.resolveDataType=Ll,h.resolveDataTypeEntityOrNestedChildrenFromLiteralValue=Jc,h.resolveDataTypeLabel=jl,h.resolveDefinitionEntityDataTypeLabel=hJ,h.resolveEntityDataTypeLabel=yJ,h.resolveEntityName=x,h.resolveFirstCallsSecond=IS,h.resolveFirstWritesSecond=ES,h.resolvePrimaryKeyProperty=gS,h.resolvePrimitiveEntityName=KO,h.resolveSearchName=HO,h.resolveVariableScope=pJ,h.returnDeclarationValidation=EJ,h.returnStatementValidation=AJ,h.searchValidation=$J,h.sequentialExecutionOperation=nr,h.sequentialExecutionOperationError=Tm,h.sequentialExecutionOperationErrorParentRef=vm,h.sequentialExecutionOperationListOfExecutionResultsDataType=ym,h.sequentialExecutionOperationListOfExecutionResultsReturn=Vd,h.sequentialExecutionOperationListOfExecutionResultsReturnParentRef=mm,h.sequentialExecutionOperationListOfExecutionResultsReturnRef=fm,h.sequentialExecutionOperationListOfFunctionsArgument=Cd,h.sequentialExecutionOperationListOfFunctionsArgumentDatatype=cm,h.sequentialExecutionOperationListOfFunctionsArgumentParentRef=hm,h.sequentialExecutionOperationListOfFunctionsArgumentRef=pm,h.sequentialExecutionOperationListOfFunctionsBlueprint=um,h.sequentialExecutionOperationListOfFunctionsBlueprintDynamicInput=dm,h.sequentialExecutionOperationListOfFunctionsBlueprintDynamicOutput=lm,h.softDeletePersistedEntityMethod=Pw,h.softDeletePersistedEntityMethodParentRef=UI,h.sortCallsBasedOnExecutionDependencies=sP,h.sortChildrenEntitiesBasedOnExecutionDependencies=vS,h.splitListOperation=bd,h.splitListOperationError=ph,h.splitListOperationErrorParentRef=uh,h.splitListOperationFirstOutputListDataType=eh,h.splitListOperationFirstOutputListReturn=ah,h.splitListOperationFirstOutputListReturnParentRef=sh,h.splitListOperationFirstOutputListReturnRef=Ad,h.splitListOperationInputListArgument=ih,h.splitListOperationInputListArgumentParentRef=th,h.splitListOperationInputListArgumentRef=Hy,h.splitListOperationInputListDataType=Ky,h.splitListOperationSecondOutputListDataType=oh,h.splitListOperationSecondOutputListReturn=dh,h.splitListOperationSecondOutputListReturnParentRef=lh,h.splitListOperationSplitIndexArgument=nh,h.splitListOperationSplitIndexArgumentParentRef=rh,h.splitListOperationSplitIndexArgumentRef=Xy,h.splitListOperationSplitIndexDataType=Qy,h.splitStringOperation=Id,h.splitStringOperationError=By,h.splitStringOperationErrorParentRef=Vy,h.splitStringOperationFirstPartResultStringDataType=Iy,h.splitStringOperationFirstPartResultStringReturn=Cy,h.splitStringOperationFirstPartResultStringReturnParentRef=wy,h.splitStringOperationFirstPartResultStringReturnRef=Ty,h.splitStringOperationIndexArgument=Oy,h.splitStringOperationIndexArgumentParentRef=Dy,h.splitStringOperationIndexArgumentRef=my,h.splitStringOperationIndexDataType=vy,h.splitStringOperationSecondPartResultStringDataType=Ay,h.splitStringOperationSecondPartResultStringReturn=Aw,h.splitStringOperationSecondPartResultStringReturnParentRef=Py,h.splitStringOperationSecondPartResultStringReturnRef=Ey,h.splitStringOperationStringArgument=Ry,h.splitStringOperationStringArgumentParentRef=by,h.splitStringOperationStringArgumentRef=yy,h.splitStringOperationStringDataType=hy,h.stringPrototype=ae,h.stringValueAutogenerationSchema=cp,h.suggestNewIdForEntity=Pc,h.test_primitive_entities_export=LW,h.toCamelCase=cJ,h.toEntityState=mi,h.toKebabCase=WO,h.toLowerCaseKebabCase=Ul,h.toPascalCase=fJ,h.untypedDataPrototype=Ot,h.updateErrorsList=He,h.urlDefaultValue=zm,h.uuidPrototype=ir,h.validateArgumentDeclarationName=Dc,h.validateCalledByErrorIdInAction=nS,h.validateCalledByIdInAction=rS,h.validateCallers=J1,h.validateConditionEntityDeclaration=oS,h.validateDataOperation=ln,h.validateDataOperationDataToValidateArgument=gm,h.validateDataOperationDataToValidateArgumentParentRef=jm,h.validateDataOperationDataToValidateArgumentRef=Lm,h.validateDataOperationDataToValidateDataType=Um,h.validateDataOperationEntityToMatchTypeArgument=xm,h.validateDataOperationEntityToMatchTypeArgumentParentRef=Fm,h.validateDataOperationEntityToMatchTypeArgumentRef=$m,h.validateDataOperationEntityToMatchTypeDataType=Gm,h.validateDataOperationError=Jm,h.validateDataOperationErrorParentRef=qm,h.validateDataOperationOutputEntityDeclaration=Zm,h.validateDataOperationOutputEntityDeclarationParentRef=km,h.validateDefinitionEntityName=Ec,h.validateEntryCaller=q1,h.validateErrorCaller=Z1,h.validateFunctionCallDeclaration=W1,h.validateFunctionDeclarationName=Ac,h.validateGeneratedEntityParentIsNotBuiltInEntity=QJ,h.validateGeneration=KJ,h.validateGenerationTarget=ut,h.validateGenerationUpdate=XJ,h.validateLoopEntityDeclaration=lS,h.validateName=mJ,h.validateOperationEntityDeclaration=z1,h.validatePropertyName=Rc,h.validateReachability=vr,h.validateReadsValueInActionPayload=sS,h.validateReferenceObject=Fl,h.validateReferenceToOne=Uc,h.validateReferences=At,h.validateReturnDeclarationName=Oc,h.validateSuccessCaller=k1,h.validateValueReaderGenerationUpdate=Ba,h.validateValueWritter=xc,h.validateVariableDeclarationName=bc,h.validateVariableInternalCallUse=kc,h.valueAutogenerationCurrentDateAndTimeSchema=sD,h.valueAutogenerationGenericSchema=al,h.valueAutogenerationOptions=hp,h.valueAutogenerationOptionsSchema=nD,h.valueAutogenerationRandomBooleanSchema=pp,h.valueAutogenerationRandomDateBetweenSchema=yD,h.valueAutogenerationRandomDateFromSchema=cD,h.valueAutogenerationRandomDateSchema=dl,h.valueAutogenerationRandomDateUntilSchema=fD,h.valueAutogenerationRandomNumberBetweenSchema=lD,h.valueAutogenerationRandomNumberFromSchema=aD,h.valueAutogenerationRandomNumberSchema=ol,h.valueAutogenerationRandomNumberUntilSchema=oD,h.valueAutogenerationRandomSchema=ca,h.valueAutogenerationRandomTextBetweenSchema=pD,h.valueAutogenerationRandomTextFromSchema=dD,h.valueAutogenerationRandomTextSchema=ll,h.valueAutogenerationRandomTextUntilSchema=uD,h.valueAutogenerationRangeValueTypesSchema=pa,h.valueAutogenerationUniqueSchema=up,h.valueDescriptorValidation=HJ,h.variableDeclarationValidation=jJ,h.variableInstanceValidation=gJ,h.waitOperation=Jt,h.waitOperationMillisecondsNumberArgument=an,h.waitOperationMillisecondsNumberArgumentRef=tm,h.waitOperationMillisecondsNumberDataType=im,h.waitOperationOperationError=sm,h.waitOperationOperationErrorParentRef=nm,h.waitOperationRef=rm,Object.defineProperty(h,Symbol.toStringTag,{value:"Module"})});